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), mPatientModelService(patientModel), mViewService(visualization)
55 mManualTool = mTrackingService->getManualTool();
56 mSpline = vtkParametricSplinePtr::New();
57 mLastStoredViewVector.Identity();
66 std::cout <<
"cameraRawPointsSlot is empty !" << std::endl;
70 this->generateSplineCurve(mesh);
74 void CXVBcameraPath::generateSplineCurve(
MeshPtr mesh)
76 vtkPolyDataPtr polyDataInput = mesh->getTransformedPolyData(mesh->get_rMd());
77 vtkPoints *vtkpoints = polyDataInput->GetPoints();
79 mNumberOfInputPoints = polyDataInput->GetNumberOfPoints();
81 mNumberOfControlPoints = mNumberOfInputPoints;
85 mSpline->GetXSpline()->RemoveAllPoints();
86 mSpline->GetYSpline()->RemoveAllPoints();
87 mSpline->GetZSpline()->RemoveAllPoints();
89 mSpline->SetPoints(vtkpoints);
98 double splineParameter = pos / 100.0;
103 double pos_r[3], focus_r[3], d_r[3];
104 double splineParameterArray[3];
105 splineParameterArray[0] = splineParameter;
106 splineParameterArray[1] = splineParameter;
107 splineParameterArray[2] = splineParameter;
109 mSpline->Evaluate(splineParameterArray, pos_r, d_r);
110 splineParameterArray[0] = splineParameter+0.1;
111 splineParameterArray[1] = splineParameter+0.1;
112 splineParameterArray[2] = splineParameter+0.1;
113 mSpline->Evaluate(splineParameterArray, focus_r, d_r);
115 mLastCameraPos_r =
Vector3D(pos_r[0], pos_r[1], pos_r[2]);
116 mLastCameraFocus_r =
Vector3D(focus_r[0], focus_r[1], focus_r[2]);
117 this->updateManualToolPosition();
121 void CXVBcameraPath::updateManualToolPosition()
125 if(
similar(mLastCameraFocus_r, mLastCameraPos_r, 0.01)) {
126 viewDirection_r = mLastStoredViewVector;
128 viewDirection_r = (mLastCameraFocus_r - mLastCameraPos_r).normalized();
129 mLastStoredViewVector = viewDirection_r;
134 Vector3D yVector =
cross(viewDirection_r, xVector).normalized();
138 rMt.matrix().col(0).head(3) = xVector;
139 rMt.matrix().col(1).head(3) = yVector;
140 rMt.matrix().col(2).head(3) = viewDirection_r;
141 rMt.matrix().col(3).head(3) = mLastCameraPos_r;
146 Transform3D rMpr = mPatientModelService->get_rMpr();
147 Transform3D prMt = rMpr.inv() * rMt * rotateZ * rotateX;
149 mManualTool->set_prMt(prMt);
156 mLastCameraViewAngle =
static_cast<double>(angle) * (
M_PI / 180.0);
157 this->updateManualToolPosition();
162 mLastCameraRotAngle =
static_cast<double>(angle) * (
M_PI / 180.0);
163 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)
bool similar(const DoubleBoundingBox3D &a, const DoubleBoundingBox3D &b, double tol)
Vector3D cross(const Vector3D &a, const Vector3D &b)
compute cross product of a and b.
vtkSmartPointer< class vtkPolyData > vtkPolyDataPtr
boost::shared_ptr< class PatientModelService > PatientModelServicePtr
void cameraViewAngleSlot(int angle)
Eigen::Vector3d Vector3D
Vector3D is a representation of a point or vector in 3D.
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)