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;
}