//----------------------------------------------------------------------void vtkResliceCursorLineRepresentation::WidgetInteraction(double e[2]){
vtkResliceCursor *rc =this->GetResliceCursor();if(this->ManipulationMode == WindowLevelling){this->WindowLevel(e[0], e[1]);this->LastEventPosition[0]= e[0];this->LastEventPosition[1]= e[1];return;}// Depending on the state, different motions are allowed.if(this->InteractionState == Outside ||!this->Renderer ||!rc ){this->LastEventPosition[0]= e[0];this->LastEventPosition[1]= e[1];return;}if(rc->GetThickMode()&&this->ManipulationMode ==
vtkResliceCursorRepresentation::ResizeThickness){double sf =1.0;// Compute the scale factorint*size =this->Renderer->GetSize();double dPos = e[1]-this->LastEventPosition[1];
sf *=(1.0+2.0*(dPos / size[1]));//scale factor of 2.0 is arbitrarydouble thickness[3];
rc->GetThickness(thickness);
rc->SetThickness( thickness[0]* sf,
thickness[1]* sf,
thickness[2]* sf );this->LastEventPosition[0]= e[0];this->LastEventPosition[1]= e[1];return;}// depending on the state, perform different operations//// 1. Translationif(this->InteractionState == OnCenter &&!this->Modifier ){// Intersect with the viewing vector. We will use this point and the// start event point to compute an offset vector to translate the// center by.double intersectionPos[3], newCenter[3];this->Picker->Pick( e, intersectionPos,this->Renderer );// Offset the center by this vector.for(int i =0; i <3; i++){
newCenter[i]=this->StartCenterPosition[i]+
intersectionPos[i]-this->StartPickPosition[i];}
rc->SetCenter(newCenter);}// 2. Rotation of axis 1if(this->InteractionState == OnAxis1 &&!this->Modifier ){this->RotateAxis( e,this->ResliceCursorActor->GetCursorAlgorithm()->GetPlaneAxis1());}// 3. Rotation of axis 2if(this->InteractionState == OnAxis2 &&!this->Modifier ){this->RotateAxis( e,this->ResliceCursorActor->GetCursorAlgorithm()->GetPlaneAxis2());}// 4. Rotation of both axesif((this->InteractionState == OnAxis2 ||this->InteractionState == OnAxis1)&&this->Modifier ){// Rotate both by the same angleconstdouble angle =this->RotateAxis( e,this->ResliceCursorActor->GetCursorAlgorithm()->GetPlaneAxis1());this->RotateAxis(this->ResliceCursorActor->GetCursorAlgorithm()->GetPlaneAxis2(), angle );}this->LastEventPosition[0]= e[0];this->LastEventPosition[1]= e[1];}-----------------------------------
这部分代码可修改为单轴旋转,双轴同时旋转
二,更改十字线的形状(比如加圆,三角形,箭头)的核心代码
//----------------------------------------------------------------------------void myvtkResliceCursor::BuildCursorGeometryWithHole(){this->ComputeAxes();double bounds[6];this->Image->GetBounds(bounds);// Length of the principal diagonal.constdouble pdLength =20*0.5*sqrt((bounds[1]- bounds[0])*(bounds[1]- bounds[0])+(bounds[3]- bounds[2])*(bounds[3]- bounds[2])+(bounds[5]- bounds[4])*(bounds[5]- bounds[4]));// Precompute prior to use within the loop.constdouble holeHalfWidth =this->HoleWidth /2.0;double pts[12][3];for(int i =0; i <3; i++){
pts[0][i]=this->Center[i]- pdLength *this->XAxis[i];
pts[1][i]=this->Center[i]+ pdLength *this->XAxis[i];
pts[2][i]=this->Center[i]- pdLength *this->YAxis[i];
pts[3][i]=this->Center[i]+ pdLength *this->YAxis[i];
pts[4][i]=this->Center[i]- pdLength *this->ZAxis[i];
pts[5][i]=this->Center[i]+ pdLength *this->ZAxis[i];// Break in the polydata to satisfy the hole
pts[6][i]=this->Center[i]- holeHalfWidth *this->XAxis[i];
pts[7][i]=this->Center[i]+ holeHalfWidth *this->XAxis[i];
pts[8][i]=this->Center[i]- holeHalfWidth *this->YAxis[i];
pts[9][i]=this->Center[i]+ holeHalfWidth *this->YAxis[i];
pts[10][i]=this->Center[i]- holeHalfWidth *this->ZAxis[i];
pts[11][i]=this->Center[i]+ holeHalfWidth *this->ZAxis[i];}for(int j =0; j <3; j++){
vtkPoints *centerlinePoints =this->CenterlineAxis[j]->GetPoints();
centerlinePoints->SetPoint(0, pts[2*j]);
centerlinePoints->SetPoint(1, pts[6+2*j]);
centerlinePoints->SetPoint(2, pts[6+2*j+1]);
centerlinePoints->SetPoint(3, pts[2*j+1]);this->CenterlineAxis[j]->Modified();}this->PolyDataBuildTime.Modified();}
其中,constdouble pdLength表示的就是十字线的长度,centerlinePoints就是用来存储两条十字线的起止点坐标,若要修改线的形状或加比如三角形,箭头等标志时就修改该变量,但要注意修改它的Size大小这里用到的主要就是几何数据和拓扑结构之间的一些知识,需要仔细的阅读源码,其余看的还不是很仔细有不足之处望指正!