14 #include "vtkPolyData.h" 15 #include "vtkCardinalSpline.h" 16 #include "vtkPoints.h" 17 #include "vtkCellArray.h" 18 #include "vtkCamera.h" 19 #include "vtkParametricSpline.h" 20 #include "vtkSpline.h" 32 : mTrackingService(tracker)
33 , mPatientModelService(patientModel)
34 , mViewService(visualization)
35 , mLastCameraViewAngle(0)
36 , mLastCameraRotAngle(0)
38 mManualTool = mTrackingService->getManualTool();
39 mSpline = vtkParametricSplinePtr::New();
40 mLastStoredViewVector.Identity();
49 std::cout <<
"cameraRawPointsSlot is empty !" << std::endl;
53 this->generateSplineCurve(mesh);
57 void CXVBcameraPath::generateSplineCurve(
MeshPtr mesh)
59 vtkPolyDataPtr polyDataInput = mesh->getTransformedPolyDataCopy(mesh->get_rMd());
60 vtkPoints *vtkpoints = polyDataInput->GetPoints();
62 mNumberOfInputPoints = polyDataInput->GetNumberOfPoints();
64 mNumberOfControlPoints = mNumberOfInputPoints;
68 mSpline->GetXSpline()->RemoveAllPoints();
69 mSpline->GetYSpline()->RemoveAllPoints();
70 mSpline->GetZSpline()->RemoveAllPoints();
72 mSpline->SetPoints(vtkpoints);
81 double splineParameter = pos / 100.0;
86 double pos_r[3], focus_r[3], d_r[3];
87 double splineParameterArray[3];
88 splineParameterArray[0] = splineParameter;
89 splineParameterArray[1] = splineParameter;
90 splineParameterArray[2] = splineParameter;
92 mSpline->Evaluate(splineParameterArray, pos_r, d_r);
93 splineParameterArray[0] = splineParameter+0.05;
94 splineParameterArray[1] = splineParameter+0.05;
95 splineParameterArray[2] = splineParameter+0.05;
96 mSpline->Evaluate(splineParameterArray, focus_r, d_r);
98 mLastCameraPos_r =
Vector3D(pos_r[0], pos_r[1], pos_r[2]);
99 mLastCameraFocus_r =
Vector3D(focus_r[0], focus_r[1], focus_r[2]);
100 this->updateManualToolPosition();
104 void CXVBcameraPath::updateManualToolPosition()
108 if(
similar(mLastCameraFocus_r, mLastCameraPos_r, 0.01)) {
109 viewDirection_r = mLastStoredViewVector;
111 viewDirection_r = (mLastCameraFocus_r - mLastCameraPos_r).normalized();
112 mLastStoredViewVector = viewDirection_r;
117 Vector3D yVector =
cross(viewDirection_r, xVector).normalized();
121 rMt.matrix().col(0).head(3) = xVector;
122 rMt.matrix().col(1).head(3) = yVector;
123 rMt.matrix().col(2).head(3) = viewDirection_r;
124 rMt.matrix().col(3).head(3) = mLastCameraPos_r;
129 Transform3D rMpr = mPatientModelService->get_rMpr();
130 Transform3D prMt = rMpr.inv() * rMt * rotateZ * rotateX;
132 mManualTool->set_prMt(prMt);
139 mLastCameraViewAngle =
static_cast<double>(angle) * (
M_PI / 180.0);
140 this->updateManualToolPosition();
145 mLastCameraRotAngle =
static_cast<double>(angle) * (
M_PI / 180.0);
146 this->updateManualToolPosition();
void cameraRawPointsSlot(MeshPtr mesh)
Transform3D Transform3D
Transform3D is a representation of an affine 3D transform.
boost::shared_ptr< class TrackingService > TrackingServicePtr
void cameraRotateAngleSlot(int angle)
Vector3D cross(const Vector3D &a, const Vector3D &b)
compute cross product of a and b.
boost::shared_ptr< class PatientModelService > PatientModelServicePtr
void cameraViewAngleSlot(int angle)
vtkSmartPointer< vtkPolyData > vtkPolyDataPtr
Eigen::Vector3d Vector3D
Vector3D is a representation of a point or vector in 3D.
bool similar(const CameraInfo &lhs, const CameraInfo &rhs, double tol)
Transform3D createTransformRotateZ(const double angle)
void cameraPathPositionSlot(int pos)
Transform3D createTransformRotateX(const double angle)
boost::shared_ptr< class Mesh > MeshPtr
CXVBcameraPath(TrackingServicePtr tracker, PatientModelServicePtr patientModel, ViewServicePtr visualization)
Namespace for all CustusX production code.