给定点P和切片法线,如何获得切片索引值以将切片放置在点P上?

时间:2014-02-05 05:08:24

标签: xtk

我希望将第17课中显示的“自定义切片”放在特定位置。要做到这一点,有必要修改法线(已完成)并将切片转换为给定点P(x,y,z)。

我注意到切片索引值根据当前法线变化很大,但我不知道是什么原因。这可以帮助我解决我的问题。

我确定,切片可能不会完全传递给P点,但是特定索引上最近的切片就可以了。

我需要做什么?

图片解释了我的问题:

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

提前致谢!!

1 个答案:

答案 0 :(得分:0)

我找到了一个解决方案......我认为可以改进。为此,您必须使用以下功能:

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

来电示例是:

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;

使用体积边界框获得_this.centerVolume; _this.pointToPositioningTheSlice是设置切片的点; Math.floor(_this.volume._childrenInfo[0]._nb/2)是当前的indexX。

结果的屏幕截图:

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

问候!


EDIT1 ...修改上一个代码以调整索引位置:

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