38 #include <visp3/ustk_core/usImagePostScan3D.h>
39 #include <visp3/ustk_gui/usMedicalImageViewer.h>
40 #include <visp3/ustk_gui/usVTKConverter.h>
42 #ifdef USTK_HAVE_VTK_QT
44 #include <vtkAbstractTransform.h>
46 #include <vtkActor2D.h>
47 #include <vtkBoundedPlanePointPlacer.h>
48 #include <vtkCamera.h>
49 #include <vtkCellPicker.h>
50 #include <vtkCommand.h>
51 #include <vtkDistanceRepresentation.h>
52 #include <vtkDistanceRepresentation2D.h>
53 #include <vtkDistanceWidget.h>
54 #include <vtkHandleRepresentation.h>
55 #include <vtkImageActor.h>
56 #include <vtkImageData.h>
57 #include <vtkImageMapToWindowLevelColors.h>
58 #include <vtkImageSlabReslice.h>
59 #include <vtkInteractorStyleImage.h>
60 #include <vtkLookupTable.h>
61 #include <vtkMapper.h>
62 #include <vtkMatrix4x4.h>
63 #include <vtkMetaImageReader.h>
65 #include <vtkPlaneSource.h>
66 #include <vtkPointHandleRepresentation2D.h>
67 #include <vtkPointHandleRepresentation3D.h>
68 #include <vtkProperty.h>
69 #include <vtkRenderWindow.h>
70 #include <vtkRenderer.h>
71 #include <vtkRendererCollection.h>
72 #include <vtkResliceCursor.h>
73 #include <vtkResliceCursorActor.h>
74 #include <vtkResliceCursorLineRepresentation.h>
75 #include <vtkResliceCursorPolyDataAlgorithm.h>
76 #include <vtkResliceCursorThickLineRepresentation.h>
77 #include <vtkResliceCursorWidget.h>
78 #include <vtkResliceImageViewer.h>
79 #include <vtkResliceImageViewerMeasurements.h>
81 #include <QDesktopWidget>
82 #include <QResizeEvent>
84 #if !(USTK_HAVE_VTK_VERSION < 0x090000)
88 #ifndef DOXYGEN_SHOULD_SKIP_THIS
90 class vtkResliceCursorCallback :
public vtkCommand
93 static vtkResliceCursorCallback *New() {
return new vtkResliceCursorCallback; }
97 void Execute(vtkObject *,
unsigned long,
void *)
100 for (
int i = 0; i < 3; i++) {
101 this->RIW[i]->Render();
106 vtkResliceCursorCallback() : widget3D(), RIW() {}
108 vtkResliceImageViewer *RIW[3];
124 vtkImage->GetDimensions(imageDims);
125 vtkImage->GetSpacing(spacing);
127 for (
int i = 0; i < 3; i++) {
128 riw[i] = vtkSmartPointer<vtkResliceImageViewer>::New();
131 #if USTK_HAVE_VTK_VERSION < 0x090000
132 this->view1->SetRenderWindow(
riw[0]->GetRenderWindow());
133 riw[0]->SetupInteractor(this->view1->GetRenderWindow()->GetInteractor());
135 this->view2->SetRenderWindow(
riw[1]->GetRenderWindow());
136 riw[1]->SetupInteractor(this->view2->GetRenderWindow()->GetInteractor());
138 this->view3->SetRenderWindow(
riw[2]->GetRenderWindow());
139 riw[2]->SetupInteractor(this->view3->GetRenderWindow()->GetInteractor());
141 this->view1->setRenderWindow(
riw[0]->GetRenderWindow());
142 riw[0]->SetupInteractor(this->view1->renderWindow()->GetInteractor());
144 this->view2->setRenderWindow(
riw[1]->GetRenderWindow());
145 riw[1]->SetupInteractor(this->view2->renderWindow()->GetInteractor());
147 this->view3->setRenderWindow(
riw[2]->GetRenderWindow());
148 riw[2]->SetupInteractor(this->view3->renderWindow()->GetInteractor());
151 for (
int i = 0; i < 3; i++) {
153 vtkResliceCursorLineRepresentation *rep =
154 vtkResliceCursorLineRepresentation::SafeDownCast(
riw[i]->GetResliceCursorWidget()->GetRepresentation());
155 riw[i]->SetResliceCursor(
riw[0]->GetResliceCursor());
157 rep->GetResliceCursorActor()->GetCursorAlgorithm()->SetReslicePlaneNormal(i);
159 riw[i]->SetInputData(vtkImage);
160 riw[i]->SetSliceOrientation(i);
161 riw[i]->SetSlice(imageDims[i] / 2);
162 riw[i]->SetResliceModeToOblique();
163 riw[i]->SliceScrollOnMouseWheelOff();
167 this->view4->
setPlanes(
riw[0]->GetResliceCursor()->GetPlane(0),
riw[1]->GetResliceCursor()->GetPlane(1),
168 riw[2]->GetResliceCursor()->GetPlane(2));
172 vtkSmartPointer<vtkResliceCursorCallback> cbk = vtkSmartPointer<vtkResliceCursorCallback>::New();
174 cbk->widget3D = this->view4;
176 for (
int i = 0; i < 3; i++) {
177 cbk->RIW[i] =
riw[i];
178 riw[i]->GetResliceCursorWidget()->AddObserver(vtkResliceCursorWidget::ResliceAxesChangedEvent, cbk);
179 riw[i]->GetResliceCursorWidget()->AddObserver(vtkResliceCursorWidget::WindowLevelEvent, cbk);
180 riw[i]->GetResliceCursorWidget()->AddObserver(vtkResliceCursorWidget::ResetCursorEvent, cbk);
183 for (
int i = 0; i < 3; i++) {
184 riw[i]->SetResliceMode(1);
185 riw[i]->GetRenderer()->ResetCamera();
187 riw[i]->GetRenderer()->GetActiveCamera()->SetRoll(180);
191 #if USTK_HAVE_VTK_VERSION < 0x090000
192 this->view4->GetRenderWindow()->GetRenderers()->GetFirstRenderer()->GetActiveCamera()->SetRoll(180);
194 this->view4->renderWindow()->GetRenderers()->GetFirstRenderer()->GetActiveCamera()->SetRoll(180);
198 connect(this->resetButton, SIGNAL(pressed()),
this, SLOT(
ResetViews()));
218 for (
int i = 0; i < 3; i++) {
219 riw[i]->GetLookupTable()->SetRange(0, 255);
220 riw[i]->GetResliceCursorWidget()->Render();
229 #if USTK_HAVE_VTK_VERSION < 0x090000
230 this->view1->GetRenderWindow()->Render();
231 this->view2->GetRenderWindow()->Render();
232 this->view3->GetRenderWindow()->Render();
234 this->view1->renderWindow()->Render();
235 this->view2->renderWindow()->Render();
236 this->view3->renderWindow()->Render();
239 this->view1->update();
240 this->view2->update();
241 this->view3->update();
242 this->view4->update();
263 this->
DistanceWidget[i] = vtkSmartPointer<vtkDistanceWidget>::New();
264 this->
DistanceWidget[i]->SetInteractor(this->
riw[i]->GetResliceCursorWidget()->GetInteractor());
267 this->
DistanceWidget[i]->SetPriority(this->
riw[i]->GetResliceCursorWidget()->GetPriority() + 0.01);
269 vtkSmartPointer<vtkPointHandleRepresentation2D> handleRep = vtkSmartPointer<vtkPointHandleRepresentation2D>::New();
270 vtkSmartPointer<vtkDistanceRepresentation2D> distanceRep = vtkSmartPointer<vtkDistanceRepresentation2D>::New();
271 distanceRep->SetHandleRepresentation(handleRep);
273 distanceRep->InstantiateHandleRepresentation();
274 distanceRep->GetPoint1Representation()->SetPointPlacer(
riw[i]->GetPointPlacer());
275 distanceRep->GetPoint2Representation()->SetPointPlacer(
riw[i]->GetPointPlacer());
288 void usMedicalImageViewer::setupUi()
290 this->setMinimumSize(640, 480);
291 #if USTK_HAVE_VTK_VERSION < 0x090000
292 QRect screenRect = QApplication::desktop()->screenGeometry();
294 QRect screenRect = QApplication::screens()[0]->geometry();
296 this->resize(screenRect.size());
298 gridLayoutWidget =
new QWidget(
this);
299 gridLayoutWidget->setObjectName(QString::fromUtf8(
"gridLayoutWidget"));
300 gridLayoutWidget->setGeometry(QRect(10, 10, screenRect.width() - 200, screenRect.height() - 40));
301 gridLayout_2 =
new QGridLayout(gridLayoutWidget);
302 gridLayout_2->setObjectName(QString::fromUtf8(
"gridLayout_2"));
303 gridLayout_2->setContentsMargins(0, 0, 0, 0);
305 view2->setObjectName(QString::fromUtf8(
"view2"));
307 gridLayout_2->addWidget(view2, 1, 0, 1, 1);
310 view4->setObjectName(QString::fromUtf8(
"view4"));
312 gridLayout_2->addWidget(view4, 0, 1, 1, 1);
315 view3->setObjectName(QString::fromUtf8(
"view3"));
317 gridLayout_2->addWidget(view3, 1, 1, 1, 1);
320 view1->setObjectName(QString::fromUtf8(
"view1"));
322 gridLayout_2->addWidget(view1, 0, 0, 1, 1);
324 resetButton =
new QPushButton(
this);
325 resetButton->setObjectName(QString::fromUtf8(
"resetButton"));
326 resetButton->setText(QString::fromUtf8(
"Reset views"));
327 resetButton->setGeometry(QRect(screenRect.width() - 180, 30, 160, 31));
329 resetColorsButton =
new QPushButton(
this);
330 resetColorsButton->setObjectName(QString::fromUtf8(
"resetColorsButton"));
331 resetColorsButton->setText(QString::fromUtf8(
"Reset colormap"));
332 resetColorsButton->setGeometry(QRect(screenRect.width() - 180, 80, 160, 31));
334 AddDistance1Button =
new QPushButton(
this);
335 AddDistance1Button->setObjectName(QString::fromUtf8(
"AddDistance1Button"));
336 AddDistance1Button->setText(QString::fromUtf8(
"Add distance 1"));
337 AddDistance1Button->setGeometry(QRect(screenRect.width() - 180, 130, 160, 31));
346 if (event->size().width() >= 640 && event->size().height() >= 480) {
347 QMainWindow::resizeEvent(event);
348 gridLayoutWidget->setGeometry(QRect(10, 10, event->size().width() - 220, event->size().height() - 20));
349 resetButton->setGeometry(QRect(event->size().width() - 180, 30, 160, 31));
350 resetColorsButton->setGeometry(QRect(event->size().width() - 180, 80, 160, 31));
351 AddDistance1Button->setGeometry(QRect(event->size().width() - 180, 130, 160, 31));
static void read(usImageRF2D< short int > &imageRf2D, const std::string &headerFileName)
virtual void ResetColorMap()
virtual void AddDistanceMeasurementToView1()
vtkSmartPointer< vtkResliceImageViewer > riw[3]
usMedicalImageViewer(std::string imageFileName)
virtual void AddDistanceMeasurementToView(int)
void resizeEvent(QResizeEvent *event)
vtkSmartPointer< vtkDistanceWidget > DistanceWidget[3]
virtual void ResetViews()
static void convert(const usImagePostScan3D< unsigned char > &postScanImage, vtkSmartPointer< vtkImageData > &vtkPostScanImage, vtkSmartPointer< vtkImageImport > importer=NULL)