xtk

Given a point P and slice normals, How do I get the slice index value to place the slice on the point P?


I want to place the "custom slice" showed on lesson 17 on a specific position. To do that, it is necessary modify the normals (that's done) and translate the slice to a given point P(x,y,z).

I notice that the slice index values varies a lot depending on the current normals, but i dont know what is cause. This can help me to solve my question.

Im sure that, may be the slice will no pass exactly for the point P, but the closest slice on a specific index will be ok.

What do I need to do?

The image explains my question:

https://www.dropbox.com/s/48nhwg01dwhee0n/newindexvalue.png

Thanks in advance!!


Solution

  • I found a solution...I think that can be improved. To do that you must use the following Function:

    GetSliceIndex_givenNormalAndPoint = function(sliceNormal,volumeCenter,sliceSpacing,indexSliceOnCenter,point){
      //Plane ecuation of the slice on the volume center point
      //Plane Ecuation given plane normal and point---Ax+By+Cz+D=0
      A = sliceNormal[0];
      B = sliceNormal[1];
      C = sliceNormal[2];
      D = -(sliceNormal[0]*volumeCenter[0]+sliceNormal[1]*volumeCenter[1]+sliceNormal[2]*volumeCenter[2]);
      //Distance between a plane and a Point
      distance = Math.abs(A*point[0]+B*point[1]+C*point[2] + D);
      distance = distance/Math.sqrt(A*A+B*B+C*C);
      //get the number of Slices on the Distance
      nSlicesOnDistance = distance/sliceSpacing;
      //get the indexSlice nearest to the point
      indexSliceOnPoint = indexSliceOnCenter + nSlicesOnDistance;
      return indexSliceOnPoint;
    }
    

    a Caller Example is:

    var sliceIndex = _this.GetSliceIndex_givenNormalAndPoint(_this.volume._childrenInfo[0]._sliceNormal,
                                            _this.centerVolume,
                                            _this.volume._childrenInfo[0]._sliceSpacing,
                                            Math.floor(_this.volume._childrenInfo[0]._nb/2),
                                            _this.pointToPositioningTheSlice
                                            );
    _this.volume.indexX = sliceIndex;
    

    The _this.centerVolume is obtained using the volume Bounding Box; the _this.pointToPositioningTheSlice is the point to set the slice; the Math.floor(_this.volume._childrenInfo[0]._nb/2) is the current indexX.

    Screen Shot of the result:

    https://dl.dropboxusercontent.com/u/269301/SliceOnPoint.png

    Regards!


    EDIT1...A fix on the previous code to adjust the index position:

    xslicegui.prototype.GetSliceIndex_givenNormalAndPoint = function(sliceNormal,volumeCenter,sliceSpacing,indexSliceOnCenter,point){
      //Plane ecuation of the slice on the volume center point
      //Plane Ecuation given plane normal and point---Ax+By+Cz+D=0
      A = sliceNormal[0];
      B = sliceNormal[1];
      C = sliceNormal[2];
      D = -(sliceNormal[0]*volumeCenter[0]+sliceNormal[1]*volumeCenter[1]+sliceNormal[2]*volumeCenter[2]);
      //Distance between a plane and a Point
      distanceSigned = A*point[0]+B*point[1]+C*point[2] + D;
      distance = Math.abs(distanceSigned);
      distance = distance/Math.sqrt(A*A+B*B+C*C);
      //get the number of Slices on the Distance
      nSlicesOnDistance = distance/sliceSpacing;
    
      //http://stackoverflow.com/questions/15688232/check-which-side-of-a-plane-points-are-on
      sign = typeof distanceSigned === 'number' ? distanceSigned ? distanceSigned < 0 ? -1 : 1 : distanceSigned === distanceSigned ? 0 : NaN : NaN;
      //get the indexSlice nearest to the point
      indexSliceOnPoint = indexSliceOnCenter + (sign * nSlicesOnDistance);
      return indexSliceOnPoint;
    }