itk中的花式数据切割(三)

来源:互联网 发布:阿里云服务器换系统 编辑:程序博客网 时间:2024/06/06 00:15
前两篇基本上都是中规中矩的沿着XYZ切割,本文呢,我们开始斜着切。

斜着切需要有两个输入:已知点,方向向量(垂直于切面)。
void complateplane(double* planeOrigin,double* planeNormal){std::auto_ptr<itkPlane> plane ( new itkPlane);plane->SetOrigin(planeOrigin);plane->SetNormal(planeNormal);ImageType::RegionType inputRegion = this_data->GetLargestPossibleRegion();ImageType::SizeType size = inputRegion.GetSize();for (int x=0;x<size[0];x++){for (int y=0;y<size[1];y++){for(int z=0;z<size[2];z++){ImageType::IndexType  point_temp;point_temp[0] = x;point_temp[1] = y;point_temp[2] = z;double pworld[3];pworld[0]=point_temp[0];pworld[1]=point_temp[1];pworld[2]=point_temp[2];double val=plane->EvaluateFunction(pworld);if (val < 1 && val > -1){this_data->SetPixel(point_temp,1);}}}}}

斜着切的思路完全依赖一个数学公式:
double something = normal[0]*(seed[0]-origin[0]) + normal[1]*(seed[1]-origin[1]) + normal[2]*(seed[2]-origin[2])
其中:
normal:法向量
seed:已知点
origin:图像原点
通过判断something的值来选择对应的数据。
1.something = 0
此时得到的结果是一个面,即通过seed点并且垂直于normal方向向量的空间平面
2.something > 0
1中得到的空间平面会将图像数据分成两部分,依赖右手定则,左侧的部分就是大于0
3.something < 0
相对于2中描述的空间,另外一边的空间小于0
(汗,好拗口,凑合看,简直不会说中文)
优点:这种切割方法不只可以用来提取某一部分,而且可以在原始数据中划分区域。
缺点:虽然比起前两篇的切割方法要灵活,但记得一定要把法向量算对。

参考文献:http://www.vtk.org/doc/nightly/html/classvtkPlane.html