39 #include <visp3/ustk_core/usConfig.h>
40 #ifdef USTK_HAVE_VTK_QT
41 #include <visp3/ustk_gui/usViewerWidget.h>
44 #include <visp3/ustk_core/usImagePostScan2D.h>
45 #include <visp3/ustk_gui/us2DSceneWidget.h>
56 m_resliceMatrix = NULL;
58 m_reslice = vtkImageReslice::New();
60 m_renderer = vtkRenderer::New();
62 m_table = vtkLookupTable::New();
64 m_color = vtkImageMapToColors::New();
66 m_actor = vtkImageActor::New();
68 m_polydataPlaneContour = vtkPolyData::New();
69 m_polyDataPlaneContourMapper = vtkPolyDataMapper::New();
70 m_polydataPlaneContourActor = vtkActor::New();
72 m_polydataMeshContour = vtkPolyData::New();
73 m_polyDataMeshContourMapper = vtkPolyDataMapper::New();
74 m_polydataMeshContourActor = vtkActor::New();
77 m_propPicker = vtkPropPicker::New();
81 m_mousePressed =
false;
84 setMouseTracking(
false);
86 m_pickingState =
false;
114 if (m_imageData == NULL)
115 throw(vpException(vpException::fatalError,
"No imageData provided in us2DSceneWidget"));
117 if (m_resliceMatrix == NULL)
118 throw(vpException(vpException::fatalError,
"No reslice matrix provided in us2DSceneWidget"));
120 m_reslice->SetInputData(m_imageData);
121 m_reslice->SetOutputDimensionality(2);
122 m_reslice->SetResliceAxes(m_resliceMatrix);
123 m_reslice->SetInterpolationModeToLinear();
126 m_reslice->AutoCropOutputOn();
129 m_table->SetRange(0, 255);
130 m_table->SetValueRange(0.0, 1.0);
131 m_table->SetSaturationRange(0.0, 0.0);
132 m_table->SetRampToLinear();
136 m_color->SetLookupTable(m_table);
137 m_color->SetInputConnection(m_reslice->GetOutputPort());
140 m_actor->GetMapper()->SetInputConnection(m_color->GetOutputPort());
141 m_actor->SetOpacity(0.7);
143 m_renderer->AddActor(m_actor);
146 #if USTK_HAVE_VTK_VERSION < 0x090000
147 vtkRenderWindow *renderWindow = this->GetRenderWindow();
149 vtkRenderWindow *renderWindow = this->renderWindow();
151 renderWindow->AddRenderer(m_renderer);
154 vtkSmartPointer<vtkInteractorStyleImage> imageStyle = vtkSmartPointer<vtkInteractorStyleImage>::New();
155 imageStyle->SetInteractionModeToImageSlicing();
156 renderWindow->GetInteractor()->SetInteractorStyle(imageStyle);
160 m_propPicker->PickFromListOn();
163 m_propPicker->AddPickList(m_actor);
184 m_polydataPlaneContour = polyData;
188 m_polyDataPlaneContourMapper->SetInputData(m_polydataPlaneContour);
189 m_polyDataPlaneContourMapper->SetScalarRange(m_polydataPlaneContour->GetScalarRange());
191 m_polydataPlaneContourActor->GetProperty()->SetOpacity(1.0);
192 m_polydataPlaneContourActor->GetProperty()->SetLighting(0);
193 m_polydataPlaneContourActor->GetProperty()->SetLineWidth(1);
194 m_polydataPlaneContourActor->GetProperty()->SetOpacity(1.0);
196 vpHomogeneousMatrix mat;
198 vtkMatrix4x4 *matrix = vtkMatrix4x4::New();
200 m_polydataPlaneContourActor->SetUserMatrix(matrix);
202 m_polydataPlaneContourActor->SetMapper(m_polyDataPlaneContourMapper);
204 m_renderer->AddActor(m_polydataPlaneContourActor);
213 m_polydataMeshContour = polyData;
216 m_polyDataMeshContourMapper->SetInputData(m_polydataMeshContour);
217 m_polyDataMeshContourMapper->SetScalarRange(m_polydataMeshContour->GetScalarRange());
219 m_polydataMeshContourActor->GetProperty()->SetOpacity(1.0);
220 m_polydataMeshContourActor->GetProperty()->SetLighting(0);
221 m_polydataMeshContourActor->GetProperty()->SetLineWidth(1);
222 m_polydataMeshContourActor->GetProperty()->SetColor(1.0, 1.0, 0.0);
223 m_polydataMeshContourActor->GetProperty()->SetOpacity(1.0);
225 vpHomogeneousMatrix mat;
227 vtkMatrix4x4 *matrix = vtkMatrix4x4::New();
229 m_polydataMeshContourActor->SetUserMatrix(matrix);
231 m_polydataMeshContourActor->SetMapper(m_polyDataMeshContourMapper);
233 m_renderer->AddActor(m_polydataMeshContourActor);
244 m_renderer->RemoveActor(m_actor);
247 m_imageData = imageData;
249 m_reslice->SetInputData(imageData);
252 m_renderer->AddActor(m_actor);
255 #if USTK_HAVE_VTK_VERSION < 0x090000
256 GetRenderWindow()->Render();
258 renderWindow()->Render();
278 #if USTK_HAVE_VTK_VERSION < 0x090000
279 int increment =
event->delta() / 120;
281 int increment =
event->angleDelta().y() / 120;
285 double sliceSpacing = m_imageData->GetSpacing()[2];
287 vpTranslationVector tVec;
290 tVec.data[2] = sliceSpacing * increment;
292 vpHomogeneousMatrix MTrans;
293 MTrans.buildFrom(tVec, vpThetaUVector(0, 0, 0));
295 vpHomogeneousMatrix MCurrrent;
298 vpHomogeneousMatrix Mnew = MCurrrent * MTrans;
303 vtkMatrix4x4 *vtkMat = vtkMatrix4x4::New();
305 m_polydataPlaneContourActor->SetUserMatrix(vtkMat);
306 m_polydataMeshContourActor->SetUserMatrix(vtkMat);
309 m_renderer->Render();
322 if (event->key() == Qt::Key_H) {
324 }
else if (event->key() == Qt::Key_P) {
335 if (event->key() == Qt::Key_H) {
337 }
else if (event->key() == Qt::Key_P) {
349 int dx = m_lastmouserPosX -
event->pos().x();
350 int dy = m_lastmouserPosY -
event->pos().y();
352 vpHomogeneousMatrix currentMat;
355 vpThetaUVector tuVec;
359 tuVec.data[1] = vpMath::rad(dx * .1);
363 tuVec.data[0] = vpMath::rad(dy * .1);
366 vpHomogeneousMatrix MRot;
367 MRot.buildFrom(vpTranslationVector(0, 0, 0), tuVec);
369 vpHomogeneousMatrix finalMat = currentMat * MRot;
374 vtkMatrix4x4 *vtkMat = vtkMatrix4x4::New();
376 m_polydataPlaneContourActor->SetUserMatrix(vtkMat);
377 m_polydataMeshContourActor->SetUserMatrix(vtkMat);
381 m_renderer->Render();
383 m_lastmouserPosX =
event->pos().x();
384 m_lastmouserPosY =
event->pos().y();
388 usViewerWidget::mouseMoveEvent(event);
397 vtkSmartPointer<vtkPNGWriter> writer = vtkSmartPointer<vtkPNGWriter>::New();
399 std::cout <<
"saving slice in file : " << absFileName << std::endl;
400 writer->SetFileName(absFileName.c_str());
401 writer->SetInputConnection(m_reslice->GetOutputPort());
412 #if USTK_HAVE_VTK_VERSION < 0x090000
413 this->GetRenderWindow()->Render();
415 renderWindow()->Render();
419 vtkSmartPointer<vtkImageData> vtkImage2D;
420 vtkImage2D = m_reslice->GetOutput();
429 if (m_pPressed || m_pickingState) {
430 int x =
event->pos().x();
431 int y = this->height() -
event->pos().y();
433 m_propPicker->Pick(x, y, 0.0, m_renderer);
435 if (m_propPicker->GetPath()) {
437 m_propPicker->GetPickPosition(p);
440 vpHomogeneousMatrix MCurrrent;
443 vpColVector vector(4);
444 vector.data[0] = p[0];
445 vector.data[1] = p[1];
446 vector.data[2] = p[2];
449 vector = MCurrrent * vector;
450 std::cout <<
"Picked value = " << vector.data[0] <<
" " << vector.data[1] <<
" " << vector.data[2] << std::endl;
451 m_pickedVoxel = vector;
454 std::cout <<
"Pick out of image" << std::endl;
456 usViewerWidget::mousePressEvent(event);
462 m_polydataPlaneContourActor->GetProperty()->SetColor(r, g, b);
471 vtkSmartPointer<vtkPoints> points = vtkSmartPointer<vtkPoints>::New();
472 points->InsertNextPoint(u1, v1, w1);
473 points->InsertNextPoint(u2, v2, w2);
476 vtkSmartPointer<vtkLine> line0 = vtkSmartPointer<vtkLine>::New();
477 line0->GetPointIds()->SetId(0, 0);
478 line0->GetPointIds()->SetId(1, 1);
481 vtkSmartPointer<vtkCellArray> lines = vtkSmartPointer<vtkCellArray>::New();
482 lines->InsertNextCell(line0);
485 vtkSmartPointer<vtkPolyData> polydata = vtkSmartPointer<vtkPolyData>::New();
488 polydata->SetPoints(points);
489 polydata->SetLines(lines);
492 vtkSmartPointer<vtkPolyDataMapper> lineMapper = vtkSmartPointer<vtkPolyDataMapper>::New();
493 lineMapper->SetInputData(polydata);
494 lineMapper->SetScalarRange(polydata->GetScalarRange());
496 vtkSmartPointer<vtkActor> lineActor = vtkSmartPointer<vtkActor>::New();
497 lineActor->GetProperty()->SetOpacity(1.0);
498 lineActor->GetProperty()->SetLighting(0);
499 lineActor->GetProperty()->SetLineWidth(1);
500 lineActor->GetProperty()->SetColor(1.0, 0.0, 0.0);
501 lineActor->GetProperty()->SetOpacity(1.0);
502 lineActor->SetMapper(lineMapper);
504 vpHomogeneousMatrix mat;
506 vtkMatrix4x4 *matrix = vtkMatrix4x4::New();
508 lineActor->SetUserMatrix(matrix);
510 m_renderer->AddActor(lineActor);
511 #if USTK_HAVE_VTK_VERSION < 0x090000
512 GetRenderWindow()->Render();
514 renderWindow()->Render();
521 #if USTK_HAVE_VTK_VERSION < 0x090000
533 m_pickingState =
true;
535 connect(
this, SIGNAL(
voxelPicked(vpColVector)), &loop, SLOT(quit()));
539 m_pickingState =
false;
static void convert(const usImagePostScan3D< unsigned char > &postScanImage, vtkSmartPointer< vtkImageData > &vtkPostScanImage, vtkSmartPointer< vtkImageImport > importer=NULL)
VISP_EXPORT std::string getDataSetPath()