37 #include <visp3/core/vpException.h>
38 #include <visp3/core/vpRotationMatrix.h>
39 #include <visp3/ustk_gui/us3DSceneWidget.h>
41 #ifdef USTK_HAVE_VTK_QT
43 #include <visp3/ustk_gui/usVTKConverter.h>
46 #include <vtkArrowSource.h>
47 #include <vtkCellArray.h>
48 #include <vtkCylinderSource.h>
49 #include <vtkDistanceWidget.h>
50 #include <vtkImagePlaneWidget.h>
51 #include <vtkImageResliceMapper.h>
52 #include <vtkInteractorStyleTrackballCamera.h>
53 #include <vtkMatrix4x4.h>
54 #include <vtkPointData.h>
55 #include <vtkPolyLine.h>
56 #include <vtkProperty.h>
57 #include <vtkRenderWindowInteractor.h>
58 #include <vtkResliceImageViewer.h>
59 #include <vtkResliceImageViewerMeasurements.h>
60 #include <vtkSTLReader.h>
61 #include <vtkSTLWriter.h>
62 #include <vtkSmartPointer.h>
63 #include <vtkSphereSource.h>
65 #include <QPaintEngine>
73 imageResliceMapper1 = vtkImageResliceMapper::New();
74 imageResliceMapper2 = vtkImageResliceMapper::New();
75 imageResliceMapper3 = vtkImageResliceMapper::New();
81 imageSlice1 = vtkImageSlice::New();
82 imageSlice2 = vtkImageSlice::New();
83 imageSlice3 = vtkImageSlice::New();
85 renderer = vtkRenderer::New();
105 if (this->imageData == NULL)
106 throw(vpException(vpException::fatalError,
"no vtk image provided"));
109 imageResliceMapper1->SetInputData(this->imageData);
110 imageResliceMapper2->SetInputData(this->imageData);
111 imageResliceMapper3->SetInputData(this->imageData);
113 this->imageData->SetOrigin(0, 0, 0);
115 if (plane1 == NULL || plane2 == NULL || plane3 == NULL)
116 throw(vpException(vpException::fatalError,
"no vtk planes provided"));
119 imageResliceMapper1->SetSlicePlane(plane1);
120 imageResliceMapper2->SetSlicePlane(plane2);
121 imageResliceMapper3->SetSlicePlane(plane3);
123 imageSlice1->SetMapper(imageResliceMapper1);
124 imageSlice2->SetMapper(imageResliceMapper2);
125 imageSlice3->SetMapper(imageResliceMapper3);
129 imageData->GetBounds(bounds);
131 imageBoundsCube = vtkSmartPointer<vtkCubeSource>::New();
132 imageBoundsCube->SetBounds(bounds);
136 cutter1 = vtkSmartPointer<vtkCutter>::New();
137 cutter1->SetCutFunction(plane1);
138 cutter1->SetInputConnection(imageBoundsCube->GetOutputPort());
140 vtkSmartPointer<vtkPolyDataMapper> cutterMapper1 = vtkSmartPointer<vtkPolyDataMapper>::New();
141 cutterMapper1->SetInputConnection(cutter1->GetOutputPort());
142 vtkSmartPointer<vtkActor> planeBorder1 = vtkSmartPointer<vtkActor>::New();
143 planeBorder1->GetProperty()->SetColor(1.0, 0, 0);
144 planeBorder1->GetProperty()->SetOpacity(1.0);
145 planeBorder1->GetProperty()->SetLighting(0);
146 planeBorder1->GetProperty()->SetLineWidth(1);
147 planeBorder1->SetMapper(cutterMapper1);
150 cutter2 = vtkSmartPointer<vtkCutter>::New();
151 cutter2->SetCutFunction(plane2);
152 cutter2->SetInputConnection(imageBoundsCube->GetOutputPort());
154 vtkSmartPointer<vtkPolyDataMapper> cutterMapper2 = vtkSmartPointer<vtkPolyDataMapper>::New();
155 cutterMapper2->SetInputConnection(cutter2->GetOutputPort());
156 vtkSmartPointer<vtkActor> planeBorder2 = vtkSmartPointer<vtkActor>::New();
157 planeBorder2->GetProperty()->SetColor(0, 1.0, 0);
158 planeBorder2->GetProperty()->SetOpacity(1.0);
159 planeBorder2->GetProperty()->SetLighting(0);
160 planeBorder2->GetProperty()->SetLineWidth(1);
161 planeBorder2->SetMapper(cutterMapper2);
164 cutter3 = vtkSmartPointer<vtkCutter>::New();
165 cutter3->SetCutFunction(plane3);
166 cutter3->SetInputConnection(imageBoundsCube->GetOutputPort());
168 vtkSmartPointer<vtkPolyDataMapper> cutterMapper3 = vtkSmartPointer<vtkPolyDataMapper>::New();
169 cutterMapper3->SetInputConnection(cutter3->GetOutputPort());
170 vtkSmartPointer<vtkActor> planeBorder3 = vtkSmartPointer<vtkActor>::New();
171 planeBorder3->GetProperty()->SetColor(0, 0, 1.0);
172 planeBorder3->GetProperty()->SetOpacity(1.0);
173 planeBorder3->GetProperty()->SetLighting(0);
174 planeBorder3->GetProperty()->SetLineWidth(1);
175 planeBorder3->SetMapper(cutterMapper3);
178 m_axesActor = vtkSmartPointer<vtkAxesActor>::New();
181 m_axesActor->SetXAxisLabelText(
"U");
182 m_axesActor->SetYAxisLabelText(
"V");
183 m_axesActor->SetZAxisLabelText(
"W");
184 m_axesActor->SetTotalLength(0.01, 0.01, 0.01);
187 vtkSmartPointer<vtkCylinderSource> cylinderSource = vtkSmartPointer<vtkCylinderSource>::New();
188 cylinderSource->SetCenter(plane1->GetOrigin());
189 cylinderSource->SetRadius(0.005);
190 cylinderSource->SetHeight(0.01);
191 cylinderSource->SetResolution(100);
192 cylinderSource->Update();
193 meshPolyData = cylinderSource->GetOutput();
196 vtkSmartPointer<vtkPolyDataMapper> meshMapper = vtkSmartPointer<vtkPolyDataMapper>::New();
197 meshMapper->SetInputConnection(cylinderSource->GetOutputPort());
198 meshMapper->Update();
199 vtkSmartPointer<vtkActor> meshActor = vtkSmartPointer<vtkActor>::New();
200 meshActor->GetProperty()->SetColor(1.0, 1.0, 0);
201 meshActor->SetMapper(meshMapper);
204 cutterPolyDataPlane1 = vtkSmartPointer<vtkCutter>::New();
205 cutterPolyDataPlane1->SetCutFunction(plane1);
206 cutterPolyDataPlane1->SetInputConnection(cylinderSource->GetOutputPort());
207 cutterPolyDataPlane1->Update();
209 vtkSmartPointer<vtkPolyDataMapper> cutterMeshMapper1 = vtkSmartPointer<vtkPolyDataMapper>::New();
210 cutterMeshMapper1->SetInputConnection(cutterPolyDataPlane1->GetOutputPort());
211 vtkSmartPointer<vtkActor> meshBorder1 = vtkSmartPointer<vtkActor>::New();
212 meshBorder1->GetProperty()->SetColor(1.0, 1.0, 0);
213 meshBorder1->GetProperty()->SetOpacity(1.0);
214 meshBorder1->GetProperty()->SetLighting(0);
215 meshBorder1->GetProperty()->SetLineWidth(1);
216 meshBorder1->SetMapper(cutterMeshMapper1);
218 cutterPolyDataPlane2 = vtkSmartPointer<vtkCutter>::New();
219 cutterPolyDataPlane2->SetCutFunction(plane2);
220 cutterPolyDataPlane2->SetInputConnection(cylinderSource->GetOutputPort());
221 cutterPolyDataPlane2->Update();
223 vtkSmartPointer<vtkPolyDataMapper> cutterMeshMapper2 = vtkSmartPointer<vtkPolyDataMapper>::New();
224 cutterMeshMapper2->SetInputConnection(cutterPolyDataPlane2->GetOutputPort());
225 vtkSmartPointer<vtkActor> meshBorder2 = vtkSmartPointer<vtkActor>::New();
226 meshBorder2->GetProperty()->SetColor(1.0, 1.0, 0);
227 meshBorder2->GetProperty()->SetOpacity(1.0);
228 meshBorder2->GetProperty()->SetLighting(0);
229 meshBorder2->GetProperty()->SetLineWidth(1);
230 meshBorder2->SetMapper(cutterMeshMapper2);
232 cutterPolyDataPlane3 = vtkSmartPointer<vtkCutter>::New();
233 cutterPolyDataPlane3->SetCutFunction(plane3);
234 cutterPolyDataPlane3->SetInputConnection(cylinderSource->GetOutputPort());
235 cutterPolyDataPlane3->Update();
237 vtkSmartPointer<vtkPolyDataMapper> cutterMeshMapper3 = vtkSmartPointer<vtkPolyDataMapper>::New();
238 cutterMeshMapper3->SetInputConnection(cutterPolyDataPlane3->GetOutputPort());
239 vtkSmartPointer<vtkActor> meshBorder3 = vtkSmartPointer<vtkActor>::New();
240 meshBorder3->GetProperty()->SetColor(1.0, 1.0, 0);
241 meshBorder3->GetProperty()->SetOpacity(1.0);
242 meshBorder3->GetProperty()->SetLighting(0);
243 meshBorder3->GetProperty()->SetLineWidth(1);
244 meshBorder3->SetMapper(cutterMeshMapper3);
247 renderer = vtkRenderer::New();
248 renderer->AddActor(m_axesActor);
249 renderer->AddActor(imageSlice1);
250 renderer->AddActor(imageSlice2);
251 renderer->AddActor(imageSlice3);
252 renderer->AddActor(planeBorder1);
253 renderer->AddActor(planeBorder2);
254 renderer->AddActor(planeBorder3);
255 renderer->AddActor(meshActor);
256 renderer->AddActor(meshBorder1);
257 renderer->AddActor(meshBorder2);
258 renderer->AddActor(meshBorder3);
259 renderer->SetBackground(0.5, 0.5, 0.5);
260 renderer->ResetCamera();
263 #if USTK_HAVE_VTK_VERSION < 0x090000
264 vtkRenderWindow *renderWindow = this->GetRenderWindow();
266 vtkRenderWindow *renderWindow = this->renderWindow();
268 renderWindow->AddRenderer(renderer);
271 vtkInteractorStyleTrackballCamera *style = vtkInteractorStyleTrackballCamera::New();
273 renderWindow->GetInteractor()->SetInteractorStyle(style);
282 this->imageData = imageData;
284 this->imageData->Modified();
286 imageResliceMapper1->SetInputData(imageData);
287 imageResliceMapper2->SetInputData(imageData);
288 imageResliceMapper3->SetInputData(imageData);
291 #if USTK_HAVE_VTK_VERSION < 0x090000
292 this->GetRenderWindow()->Render();
294 this->renderWindow()->Render();
377 this->plane1 = plane1;
378 this->plane2 = plane2;
379 this->plane3 = plane3;
389 renderer->RemoveActor(imageSlice1);
390 renderer->RemoveActor(imageSlice2);
391 renderer->RemoveActor(imageSlice3);
394 imageBoundsCube->SetBounds(imageData->GetBounds());
397 this->imageData = imageData;
398 imageResliceMapper1->SetInputData(imageData);
399 imageResliceMapper2->SetInputData(imageData);
400 imageResliceMapper3->SetInputData(imageData);
403 renderer->AddActor(imageSlice1);
404 renderer->AddActor(imageSlice2);
405 renderer->AddActor(imageSlice3);
407 #if USTK_HAVE_VTK_VERSION < 0x090000
408 GetRenderWindow()->Render();
410 renderWindow()->Render();
421 if (plane1 == NULL) {
422 plane1 = vtkPlane::New();
424 plane1->SetNormal(1, 0, 0);
428 origin[0] = matrix->Element[0][3];
429 origin[1] = matrix->Element[1][3];
430 origin[2] = matrix->Element[2][3];
431 plane1->SetOrigin(origin);
434 vpRotationMatrix rMat;
435 vpHomogeneousMatrix hMat;
439 vpColVector normal(3);
444 normal = rMat * normal;
446 plane1->SetNormal(normal.data[0], normal.data[1], normal.data[2]);
459 if (plane2 == NULL) {
460 plane2 = vtkPlane::New();
462 plane2->SetNormal(0, 1, 0);
466 origin[0] = matrix->Element[0][3];
467 origin[1] = matrix->Element[1][3];
468 origin[2] = matrix->Element[2][3];
469 plane2->SetOrigin(origin);
472 vpRotationMatrix rMat;
473 vpHomogeneousMatrix hMat;
477 vpColVector normal(3);
482 normal = rMat * normal;
484 plane2->SetNormal(normal.data[0], normal.data[1], normal.data[2]);
497 if (plane3 == NULL) {
498 plane3 = vtkPlane::New();
500 plane3->SetNormal(0, 0, 1);
505 origin[0] = matrix->Element[0][3];
506 origin[1] = matrix->Element[1][3];
507 origin[2] = matrix->Element[2][3];
508 plane3->SetOrigin(origin);
511 vpRotationMatrix rMat;
512 vpHomogeneousMatrix hMat;
516 vpColVector normal(3);
521 normal = rMat * normal;
523 plane3->SetNormal(normal.data[0], normal.data[1], normal.data[2]);
static void convert(const usImagePostScan3D< unsigned char > &postScanImage, vtkSmartPointer< vtkImageData > &vtkPostScanImage, vtkSmartPointer< vtkImageImport > importer=NULL)