38 #include <visp3/ustk_gui/usResliceMatrixViewer.h>
40 #ifdef USTK_HAVE_VTK_QT
42 #include <visp3/ustk_core/usImagePostScan3D.h>
43 #include <visp3/ustk_gui/usVTKConverter.h>
45 #include <vtkAbstractTransform.h>
47 #include <vtkActor2D.h>
48 #include <vtkBoundedPlanePointPlacer.h>
49 #include <vtkCamera.h>
50 #include <vtkCellPicker.h>
51 #include <vtkCommand.h>
52 #include <vtkDistanceRepresentation.h>
53 #include <vtkDistanceRepresentation2D.h>
54 #include <vtkDistanceWidget.h>
55 #include <vtkHandleRepresentation.h>
56 #include <vtkImageActor.h>
57 #include <vtkImageData.h>
58 #include <vtkImageMapToWindowLevelColors.h>
59 #include <vtkImageSlabReslice.h>
60 #include <vtkInteractorStyleImage.h>
61 #include <vtkLookupTable.h>
62 #include <vtkMapper.h>
63 #include <vtkMatrix4x4.h>
64 #include <vtkMetaImageReader.h>
66 #include <vtkPlaneSource.h>
67 #include <vtkProperty.h>
68 #include <vtkRenderWindow.h>
69 #include <vtkRenderer.h>
70 #include <vtkRendererCollection.h>
71 #include <vtkResliceImageViewer.h>
72 #include <vtkResliceImageViewerMeasurements.h>
74 #include <vtkHomogeneousTransform.h>
76 #include <QDesktopWidget>
77 #include <QFileDialog>
78 #include <QResizeEvent>
92 vtkImage->GetDimensions(imageDims);
93 vtkImage->GetSpacing(spacing);
96 vpHomogeneousMatrix matrix3;
98 matrix3[0][3] = imageDims[0] * spacing[0] / 2;
99 matrix3[1][3] = imageDims[1] * spacing[1] / 2;
100 matrix3[2][3] = imageDims[2] * spacing[2] / 2;
104 vtkMatrix3 = vtkMatrix4x4::New();
108 vpHomogeneousMatrix matrix2;
110 matrix2[0][3] = imageDims[0] * spacing[0] / 2;
111 matrix2[1][3] = imageDims[1] * spacing[1] / 2;
112 matrix2[2][3] = imageDims[2] * spacing[2] / 2;
119 vtkMatrix2 = vtkMatrix4x4::New();
123 vpHomogeneousMatrix matrix1;
125 matrix1[0][3] = imageDims[0] * spacing[0] / 2;
126 matrix1[1][3] = imageDims[1] * spacing[1] / 2;
127 matrix1[2][3] = imageDims[2] * spacing[2] / 2;
133 vtkMatrix1 = vtkMatrix4x4::New();
164 connect(this->resetButton, SIGNAL(pressed()),
this, SLOT(
ResetViews()));
166 connect(this->openImageButton, SIGNAL(pressed()),
this, SLOT(
openPostScan3D()));
167 connect(this->saveView1Button, SIGNAL(pressed()),
this, SLOT(
getView1Slice()));
168 connect(this->saveView4Button, SIGNAL(pressed()), view4, SLOT(saveViewSlot()));
169 connect(this->saveView3Button, SIGNAL(pressed()), view3, SLOT(saveViewSlot()));
172 connect(view1, SIGNAL(matrixChanged(vtkMatrix4x4 *)), view2, SLOT(updateMatrix1(vtkMatrix4x4 *)));
173 connect(view4, SIGNAL(matrixChanged(vtkMatrix4x4 *)), view2, SLOT(updateMatrix2(vtkMatrix4x4 *)));
174 connect(view3, SIGNAL(matrixChanged(vtkMatrix4x4 *)), view2, SLOT(updateMatrix3(vtkMatrix4x4 *)));
176 connect(view2, SIGNAL(plane2Changed()), view1, SLOT(updateView()));
177 connect(view2, SIGNAL(plane2Changed()), view4, SLOT(updateView()));
178 connect(view2, SIGNAL(plane2Changed()), view3, SLOT(updateView()));
195 vtkImage->GetDimensions(imageDims);
196 vtkImage->GetSpacing(spacing);
199 vpHomogeneousMatrix matrix3;
201 matrix3[0][3] = imageDims[0] * spacing[0] / 2;
202 matrix3[1][3] = imageDims[1] * spacing[1] / 2;
203 matrix3[2][3] = imageDims[2] * spacing[2] / 2;
210 vpHomogeneousMatrix matrix2;
212 matrix2[0][3] = imageDims[0] * spacing[0] / 2;
213 matrix2[1][3] = imageDims[1] * spacing[1] / 2;
214 matrix2[2][3] = imageDims[2] * spacing[2] / 2;
223 vpHomogeneousMatrix matrix1;
225 matrix1[0][3] = imageDims[0] * spacing[0] / 2;
226 matrix1[1][3] = imageDims[1] * spacing[1] / 2;
227 matrix1[2][3] = imageDims[2] * spacing[2] / 2;
251 this->view1->GetRenderWindow()->Render();
252 this->view2->GetRenderWindow()->Render();
253 this->view3->GetRenderWindow()->Render();
254 this->view4->GetRenderWindow()->Render();
260 void usResliceMatrixViewer::setupUi()
262 this->setMinimumSize(640, 480);
263 QRect screenRect = QApplication::desktop()->screenGeometry();
264 this->resize(screenRect.size());
266 gridLayoutWidget =
new QWidget(
this);
267 gridLayoutWidget->setObjectName(QString::fromUtf8(
"gridLayoutWidget"));
268 gridLayoutWidget->setGeometry(QRect(10, 10, screenRect.width() - 200, screenRect.height() - 40));
269 gridLayout_2 =
new QGridLayout(gridLayoutWidget);
270 gridLayout_2->setObjectName(QString::fromUtf8(
"gridLayout_2"));
271 gridLayout_2->setContentsMargins(0, 0, 0, 0);
273 view1->setObjectName(QString::fromUtf8(
"view1"));
275 gridLayout_2->addWidget(view1, 0, 0, 1, 1);
278 view2->setObjectName(QString::fromUtf8(
"view1"));
280 gridLayout_2->addWidget(view2, 1, 0, 1, 1);
283 view3->setObjectName(QString::fromUtf8(
"view1"));
285 gridLayout_2->addWidget(view3, 0, 1, 1, 1);
288 view4->setObjectName(QString::fromUtf8(
"view2"));
290 gridLayout_2->addWidget(view4, 1, 1, 1, 1);
292 resetButton =
new QPushButton(
this);
293 resetButton->setObjectName(QString::fromUtf8(
"resetButton"));
294 resetButton->setText(QString::fromUtf8(
"Reset views"));
295 resetButton->setGeometry(QRect(screenRect.width() - 180, 30, 160, 31));
297 openImageButton =
new QPushButton(
this);
298 openImageButton->setObjectName(QString::fromUtf8(
"openImageButton"));
299 openImageButton->setText(QString::fromUtf8(
"Open new image"));
300 openImageButton->setGeometry(QRect(screenRect.width() - 180, 80, 160, 31));
302 saveView1Button =
new QPushButton(
this);
303 saveView1Button->setObjectName(QString::fromUtf8(
"saveView1Button"));
304 saveView1Button->setText(QString::fromUtf8(
"Save view 1"));
305 saveView1Button->setGeometry(QRect(screenRect.width() - 180, 130, 160, 31));
307 saveView4Button =
new QPushButton(
this);
308 saveView4Button->setObjectName(QString::fromUtf8(
"saveView4Button"));
309 saveView4Button->setText(QString::fromUtf8(
"Save view 4"));
310 saveView4Button->setGeometry(QRect(screenRect.width() - 180, 180, 160, 31));
312 saveView3Button =
new QPushButton(
this);
313 saveView3Button->setObjectName(QString::fromUtf8(
"saveView3Button"));
314 saveView3Button->setText(QString::fromUtf8(
"Save view 3"));
315 saveView3Button->setGeometry(QRect(screenRect.width() - 180, 230, 160, 31));
324 if (event->size().width() >= 640 && event->size().height() >= 480) {
325 QMainWindow::resizeEvent(event);
326 gridLayoutWidget->setGeometry(QRect(10, 10, event->size().width() - 220, event->size().height() - 20));
327 resetButton->setGeometry(QRect(event->size().width() - 180, 30, 160, 31));
328 openImageButton->setGeometry(QRect(event->size().width() - 180, 80, 160, 31));
329 saveView1Button->setGeometry(QRect(event->size().width() - 180, 130, 160, 31));
330 saveView4Button->setGeometry(QRect(event->size().width() - 180, 180, 160, 31));
331 saveView3Button->setGeometry(QRect(event->size().width() - 180, 230, 160, 31));
351 QString fileName = QFileDialog::getOpenFileName(
this, tr(
"Open Image"),
us::getDataSetPath().c_str(),
352 tr(
"Meta header files (*.mhd)"));
354 if (fileName.size() == 0)
357 double t0 = vpTime::measureTimeMs();
361 double t1 = vpTime::measureTimeMs();
362 std::cout <<
"read image time (ms) = " << t1 - t0 << std::endl;
371 std::cout <<
"convert/update image time (ms) = " << vpTime::measureTimeMs() - t1 << std::endl;
static void read(usImageRF2D< short int > &imageRf2D, const std::string &headerFileName)
static void write(const usImageRF2D< short > &rfImage, const std::string &headerFileName, const std::string &imageExtension2D)
virtual void ResetViews()
usResliceMatrixViewer(std::string imageFileName)
void resizeEvent(QResizeEvent *event)
static void convert(const usImagePostScan3D< unsigned char > &postScanImage, vtkSmartPointer< vtkImageData > &vtkPostScanImage, vtkSmartPointer< vtkImageImport > importer=NULL)
VISP_EXPORT std::string getDataSetPath()