35 #include "vtkPolyData.h" 36 #include "vtkCardinalSpline.h" 37 #include "vtkPoints.h" 38 #include "vtkCellArray.h" 39 #include "vtkCamera.h" 40 #include "vtkParametricSpline.h" 41 #include "vtkSpline.h" 53 : mTrackingService(tracker)
54 , mPatientModelService(patientModel)
55 , mViewService(visualization)
56 , mLastCameraViewAngle(0)
57 , mLastCameraRotAngle(0)
59 mManualTool = mTrackingService->getManualTool();
60 mSpline = vtkParametricSplinePtr::New();
61 mLastStoredViewVector.Identity();
70 std::cout <<
"cameraRawPointsSlot is empty !" << std::endl;
74 this->generateSplineCurve(mesh);
78 void CXVBcameraPath::generateSplineCurve(
MeshPtr mesh)
80 vtkPolyDataPtr polyDataInput = mesh->getTransformedPolyDataCopy(mesh->get_rMd());
81 vtkPoints *vtkpoints = polyDataInput->GetPoints();
83 mNumberOfInputPoints = polyDataInput->GetNumberOfPoints();
85 mNumberOfControlPoints = mNumberOfInputPoints;
89 mSpline->GetXSpline()->RemoveAllPoints();
90 mSpline->GetYSpline()->RemoveAllPoints();
91 mSpline->GetZSpline()->RemoveAllPoints();
93 mSpline->SetPoints(vtkpoints);
102 double splineParameter = pos / 100.0;
107 double pos_r[3], focus_r[3], d_r[3];
108 double splineParameterArray[3];
109 splineParameterArray[0] = splineParameter;
110 splineParameterArray[1] = splineParameter;
111 splineParameterArray[2] = splineParameter;
113 mSpline->Evaluate(splineParameterArray, pos_r, d_r);
114 splineParameterArray[0] = splineParameter+0.05;
115 splineParameterArray[1] = splineParameter+0.05;
116 splineParameterArray[2] = splineParameter+0.05;
117 mSpline->Evaluate(splineParameterArray, focus_r, d_r);
119 mLastCameraPos_r =
Vector3D(pos_r[0], pos_r[1], pos_r[2]);
120 mLastCameraFocus_r =
Vector3D(focus_r[0], focus_r[1], focus_r[2]);
121 this->updateManualToolPosition();
125 void CXVBcameraPath::updateManualToolPosition()
129 if(
similar(mLastCameraFocus_r, mLastCameraPos_r, 0.01)) {
130 viewDirection_r = mLastStoredViewVector;
132 viewDirection_r = (mLastCameraFocus_r - mLastCameraPos_r).normalized();
133 mLastStoredViewVector = viewDirection_r;
138 Vector3D yVector =
cross(viewDirection_r, xVector).normalized();
142 rMt.matrix().col(0).head(3) = xVector;
143 rMt.matrix().col(1).head(3) = yVector;
144 rMt.matrix().col(2).head(3) = viewDirection_r;
145 rMt.matrix().col(3).head(3) = mLastCameraPos_r;
150 Transform3D rMpr = mPatientModelService->get_rMpr();
151 Transform3D prMt = rMpr.inv() * rMt * rotateZ * rotateX;
153 mManualTool->set_prMt(prMt);
160 mLastCameraViewAngle =
static_cast<double>(angle) * (
M_PI / 180.0);
161 this->updateManualToolPosition();
166 mLastCameraRotAngle =
static_cast<double>(angle) * (
M_PI / 180.0);
167 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.