20 #include "milxQtUnifiedWindow.h" 23 #include <itkLinearInterpolateImageFunction.h> 25 #include <vtkSmartPointer.h> 27 #include <vtkCellLocator.h> 28 #include <vtkGenericCell.h> 29 #include <vtkLineSource.h> 30 #include <vtkDoubleArray.h> 32 #include <vtkImageMapToWindowLevelColors.h> 33 #include <vtkCheckerboardRepresentation.h> 52 bool alreadyPresent =
false;
57 setCommonProperties(model);
70 bool alreadyPresent =
false;
75 setCommonProperties(image);
131 qApp->processEvents();
138 vtkSmartPointer<vtkMatrix4x4> transformModel = vtkSmartPointer<vtkMatrix4x4>::New();
140 transformModel->Invert();
146 connect(img, SIGNAL(
modified(vtkSmartPointer<vtkImageActor> )),
this, SLOT(
updateImageActor(vtkSmartPointer<vtkImageActor>)));
151 qApp->processEvents();
164 unifyModels.first()->GetOutput()->GetBounds(bounds);
165 printInfo(
"Original Bounds: " + QString::number(bounds[0]) +
", " + QString::number(bounds[1]) +
", " + QString::number(bounds[2]) +
", " + QString::number(bounds[3]) +
", " + QString::number(bounds[4]) +
", " + QString::number(bounds[5]));
175 mdl->GetOutput()->GetBounds(mdlBounds);
176 printInfo(
"Bounds: " + QString::number(mdlBounds[0]) +
", " + QString::number(mdlBounds[1]) +
", " + QString::number(mdlBounds[2]) +
", " + QString::number(mdlBounds[3]) +
", " + QString::number(mdlBounds[4]) +
", " + QString::number(mdlBounds[5]));
179 bigBounds[0] = milx::Minimum<double>(mdlBounds[0], bounds[0]);
180 bigBounds[1] = milx::Maximum<double>(mdlBounds[1], bounds[1]);
181 bigBounds[2] = milx::Minimum<double>(mdlBounds[2], bounds[2]);
182 bigBounds[3] = milx::Maximum<double>(mdlBounds[3], bounds[3]);
183 bigBounds[4] = milx::Minimum<double>(mdlBounds[4], bounds[4]);
184 bigBounds[5] = milx::Maximum<double>(mdlBounds[5], bounds[5]);
194 printInfo(
"Overall Bounds: " + QString::number(bigBounds[0]) +
", " + QString::number(bigBounds[1]) +
", " + QString::number(bigBounds[2]) +
", " + QString::number(bigBounds[3]) +
", " + QString::number(bigBounds[4]) +
", " + QString::number(bigBounds[5]));
196 printInfo(
"Computing Distance map of first model ...");
198 image->
setName(
"Voxelisation Source");
199 image->generateVoxelisedSurface(
unifyModels.first()->GetOutput(), bigBounds);
200 image->distanceMap();
201 image->generateImage();
202 emit imageAvailable(image);
226 const bool absValues =
true;
227 floatImageType::Pointer distanceImage = image->GetFloatImage();
230 printInfo(
"Computing Distance map for other models ...");
236 printInfo(mdl->strippedBaseName() +
" info:");
240 image2->generateImage();
241 image2->distanceMap();
242 emit imageAvailable(image2);
244 floatImageType::Pointer distanceImage2 = image2->GetFloatImage();
245 printInfo(
"Computing Forward Distances ...");
247 printInfo(
"Computing Backward Distances ...");
251 scalars1->GetRange(range1);
253 scalars2->GetRange(range2);
254 double hausdorff = milx::Maximum<double>(range1[1], range2[1]);
255 printInfo(
"Hausdorff Distance: " + QString::number(hausdorff));
257 mdl->GetOutput()->GetPointData()->SetScalars(scalars1);
258 mdl->GetOutput()->Modified();
259 #if VTK_MAJOR_VERSION <=5 260 mdl->GetOutput()->Update();
261 #endif // VTK_MAJOR_VERSION 262 mdl->colourMapToHOT();
263 unifyModels.first()->GetOutput()->GetPointData()->SetScalars(scalars2);
265 #if VTK_MAJOR_VERSION <=5 267 #endif // VTK_MAJOR_VERSION 285 printError(
"Not enough images being compared. Add more.");
289 printInfo(
"Generating Checkboard to View Images");
292 checker = vtkSmartPointer<vtkImageCheckerboard>::New();
293 checker->SetNumberOfDivisions(5,5,1);
299 cerr <<
"Slice: " << displayExtents[0] <<
", " << displayExtents[1] <<
", " << displayExtents[2]
300 <<
", " << displayExtents[3] <<
", " << displayExtents[4] <<
", " << displayExtents[5] << endl;
301 vtkSmartPointer<vtkImageReslice> slice = vtkSmartPointer<vtkImageReslice>::New();
302 #if VTK_MAJOR_VERSION <=5 306 #endif // VTK_MAJOR_VERSION 308 slice->SetOutputExtent(displayExtents);
310 #if VTK_MAJOR_VERSION <=5 311 checker->SetInput(count, slice->GetOutput());
313 checker->SetInputData(count, slice->GetOutput());
314 #endif // VTK_MAJOR_VERSION 322 vtkSmartPointer<vtkImageMapToWindowLevelColors> windowLevel = vtkSmartPointer<vtkImageMapToWindowLevelColors>::New();
323 #if VTK_MAJOR_VERSION <=5 324 windowLevel->SetInput(checker->GetOutput());
326 windowLevel->SetInputData(checker->GetOutput());
329 vtkSmartPointer<vtkImageActor> checkerActor = vtkSmartPointer<vtkImageActor>::New();
331 #if VTK_MAJOR_VERSION <=5 332 checkerActor->SetInput(windowLevel->GetOutput());
334 checkerActor->SetInputData(windowLevel->GetOutput());
342 checkerWidget = vtkSmartPointer<vtkCheckerboardWidget>::New();
343 checkerWidget->SetInteractor(milxQtRenderWindow::GetRenderWindow()->GetInteractor());
345 vtkCheckerboardRepresentation *checkerWidgetRep =
static_cast<vtkCheckerboardRepresentation *
>(
checkerWidget->GetRepresentation());
346 checkerWidgetRep->SetImageActor(checkerActor);
347 checkerWidgetRep->SetCheckerboard(checker);
359 const int numberOfPoints = surface->GetNumberOfPoints();
361 typedef itk::Point<double, 3> InputImagePointType;
362 typedef itk::ContinuousIndex<double, 3 > ContinuousIndexType;
364 typedef itk::LinearInterpolateImageFunction<floatImageType, double> InterpolatorType;
366 InterpolatorType::Pointer interpolator = InterpolatorType::New();
367 interpolator->SetInputImage(img);
369 vtkSmartPointer<vtkFloatArray> scalars = vtkSmartPointer<vtkFloatArray>::New();
370 scalars->SetName(
"Distance");
371 scalars->SetNumberOfTuples(numberOfPoints);
372 scalars->SetNumberOfComponents(1);
374 InputImagePointType point;
375 ContinuousIndexType index;
376 for(
int i = 0; i < numberOfPoints; i++)
379 surface->GetPoint(i, position);
381 point[0] = position[0];
382 point[1] = position[1];
383 point[2] = position[2];
385 img->TransformPhysicalPointToContinuousIndex(point, index);
388 if(interpolator->IsInsideBuffer(index))
391 double valueFound = 0.0;
393 valueFound = fabs(interpolator->EvaluateAtContinuousIndex(index));
395 valueFound = interpolator->EvaluateAtContinuousIndex(index);
396 scalars->SetTuple1(i, valueFound);
407 unionAct->setText(QApplication::translate(
"Unified",
"&Union of Data", 0, QApplication::UnicodeUTF8));
412 geoDifferenceAct->setText(QApplication::translate(
"Unified",
"&Surface (Hausdoff) Distance", 0, QApplication::UnicodeUTF8));
416 scalarDifferenceAct->setText(QApplication::translate(
"Unified",
"&Scalar Difference", 0, QApplication::UnicodeUTF8));
421 checkerBoardAct->setText(QApplication::translate(
"Unified",
"&Checkerboard", 0, QApplication::UnicodeUTF8));
487 void milxQtUnifiedWindow::setCommonProperties(QWidget *passedWindow)
void printWarning(QString msg)
Warning message wrapper for console.
void printError(QString msg)
Error message wrapper for console.
void createConnections()
Create the connections for context menu etc.
void generateScalarDifference()
Generate a difference of the scalar data to display, i.e. show the net displacement vectors of the da...
QAction * checkerBoardAct
Checkerboard of image data.
void RemoveActor(vtkSmartPointer< vtkProp > actor)
Remove the VTK actor from this window.
void generateVoxelisedSurface(vtkSmartPointer< vtkPolyData > surfaceToVoxelise, double *bounds=NULL, double *spacing=NULL)
Converts or Voxelises a surface (vtkPolyData) to an image.
void refresh()
Refresh the display of the window.
QMenu * viewMenu
Context Menu.
void createActions()
Create the actions for context menu etc.
void setName(const QString filename)
Set the name of the data.
QActionGroup * modeGroup
Grouping for check boxes.
void generateUnion()
Generate a union of the data to display, i.e. show all data at once unaltered.
void AddActor(vtkSmartPointer< vtkProp > actor)
Add a VTK actor to this window.
This class represents the MILX Qt Render Window Display object using QVTK.
QAction * viewZY
Change view to zy-plane (Coronal)
This class represents the MILX Qt Image Display object using VTK.
vtkSmartPointer< vtkFloatArray > surfaceScalarsFromImage(vtkSmartPointer< vtkPolyData > surface, itk::SmartPointer< floatImageType > img, const bool absoluteValues)
Function for extracting pixel values from image given surface points.
QMenu * contextMenu
Context Menu.
void contextMenuEvent(QContextMenuEvent *event)
The context menu setup member.
QList< milxQtModel *> unifyModels
Model to maintain and operate on.
QAction * axesAct
Action for axes of the display.
void modified(vtkSmartPointer< vtkImageActor >)
Emit signal to allow updating of image actors if present.
QAction * scalarDifferenceAct
Scalar Difference of data.
vtkImageActor * GetImageActor()
Returns the internal image actor used for display.
QAction * unionAct
Union of data.
QString prefix
Prefix of the data.
void printDebug(QString msg)
Debug message wrapper for console.
QAction * geoDifferenceAct
Geometric Difference of data.
void addModelActor(vtkSmartPointer< vtkActor > mdlActor)
Directly add model actor to generic view.
This class represents the MILX Qt Model/Mesh Display object using VTK.
void closing(QWidget *win)
Send signal that the window is closing.
QList< milxQtImage *> unifyImages
Images to maintain and operate on.
void addImageActor(vtkSmartPointer< vtkImageActor > imgActor, vtkMatrix4x4 *transformMatrix=NULL)
Directly add image actor to generic view.
QAction * refreshAct
Action for refreshing the display.
QList< vtkSmartPointer< vtkImageReslice > > slices
Images to maintain and operate on.
milxQtUnifiedWindow(QWidget *theParent=0)
Default constructor.
void addToWindow(milxQtModel *model)
Add this model window to the unified display.
vtkSmartPointer< vtkCheckerboardWidget > checkerWidget
Checker board widget for comparing images.
QMenu * colourMapMenu
Colour map menu.
void generateRender()
Generate the render so it is ready for display. Should be called before showing the window...
QAction * saveViewAct
Save camera view.
QAction * viewXY
Change view to xy-plane (Axial)
vtkSmartPointer< vtkImageData > GetOutput()
Returns the image data object (ImageData) used internally VTK style.
void removeFromWindow(QWidget *passedWindow)
Remove this window from the unified display.
QString getName()
Returns the name of the data.
void removeImageActor(vtkSmartPointer< vtkImageActor > imgActor)
Directly remove image actor from generic view.
void RemoveAllActors()
Remove all VTK actors from this window.
void generateDifference(double pseudoInfinityFactor=-1.0)
Generate a difference of the geometric data to display, i.e. show the net displacement vectors of the...
QAction * viewZX
Change view to zx-plane (Sagittal)
void generateCheckerBoard()
Generate a checker board widget to compare images, i.e. show checkboards with the compared images...
void done(int value)
Send signal that computation is done. Value carries the progress,.
vtkSmartPointer< vtkMatrix4x4 > getTransformMatrix()
Internal transform matrix used to transform actors appropriately for direction and coordinate systems...
int * GetDisplayExtent()
Returns the current display extent of the image data, i.e the current slice dimensions/extents.
virtual ~milxQtUnifiedWindow()
Default destructor.
void refresh()
Refresh the display of the model including widgets. Camera remains as is.
vtkSmartPointer< vtkLODActor > GetActor()
Returns the VTK actor used.
void printInfo(QString msg)
Info message wrapper for console.
void working(int value)
Send signal that computation is in progress. Value carries the progress,.
virtual void updateImageActor(vtkObject *obj, unsigned long, void *client_data, void *, vtkCommand *command)
Update any image actors in display to current slice when slice number changes.
QAction * loadViewAct
Load camera view.
void removeModelActor(vtkSmartPointer< vtkActor > mdlActor)
Directly remove model actor from generic view.