24 #include <vtkSmartPointer.h> 25 #include <itkCommand.h> 26 #include <vtkImageData.h> 27 #include <vtkMatrix4x4.h> 28 #include <vtkImageAppend.h> 29 #include <vtkImagePermute.h> 30 #include <vtkImageAccumulate.h> 31 #include <vtkImageMapToWindowLevelColors.h> 32 #if(VTK_MAJOR_VERSION > 5) 33 #include <vtkResliceCursor.h> 34 #include <vtkResliceCursorActor.h> 37 #include <itkRGBPixel.h> 39 #include <itkVectorImage.h> 41 #include <vnl/vnl_matrix.h> 43 #include "milxQtRenderWindow.h" 44 #include "vtkImageViewer3.h" 45 #include "milxImage.h" 48 typedef unsigned char charPixelType;
49 typedef itk::Image<charPixelType, milx::imgDimension> charImageType;
50 typedef int intPixelType;
51 typedef itk::Image<intPixelType, milx::imgDimension> intImageType;
52 typedef itk::RGBPixel<unsigned char> rgbPixelType;
53 typedef itk::Image<rgbPixelType, milx::imgDimension> rgbImageType;
54 typedef float floatPixelType;
55 typedef itk::Image<floatPixelType, milx::imgDimension> floatImageType;
56 typedef itk::VectorImage<floatPixelType, milx::imgDimension> vectorImageType;
61 vtkSmartPointer<vtkActor> modelActor;
62 vtkSmartPointer<vtkActor> parentActor;
78 void Execute(itk::Object *caller,
const itk::EventObject & event)
80 Execute( (
const itk::Object *)caller, event);
83 void Execute(
const itk::Object *
object,
const itk::EventObject & event)
85 qApp->processEvents();
127 milxQtImage(QWidget *theParent = 0,
bool contextSystem =
true);
139 return "milxQtImage";
149 return prefix + QFileInfo(name).fileName();
156 inline void SetInput(vtkSmartPointer<vtkImageData> newImg)
167 inline void SetInput(charImageType::Pointer newImg,
const bool flipY =
true)
169 setData(newImg, flipY);
178 inline void SetInput(intImageType::Pointer newImg,
const bool flipY =
true)
180 setData(newImg, flipY);
189 inline void SetInput(rgbImageType::Pointer newImg,
const bool flipY =
true)
191 setData(newImg, flipY);
200 inline void SetInput(floatImageType::Pointer newImg,
const bool flipY =
true)
202 setData(newImg, flipY);
211 inline void SetInput(vectorImageType::Pointer newImg,
const bool flipY =
true)
213 setData(newImg, flipY);
221 void SetTransform(vtkSmartPointer<vtkTransform> transform);
229 void setData(QPointer<milxQtImage> newImg,
const bool forceDeepCopy =
false);
234 void setData(vtkSmartPointer<vtkImageData> newImg);
242 void setData(charImageType::Pointer newImg,
const bool flipY =
true);
250 void setData(intImageType::Pointer newImg,
const bool flipY =
true);
258 void setData(rgbImageType::Pointer newImg,
const bool flipY =
true);
266 void setData(floatImageType::Pointer newImg,
const bool flipY =
true);
275 void setData(vectorImageType::Pointer newImg,
const bool flipY =
true,
const bool deepCopy =
false);
280 void setData(vnl_matrix<double> &newData);
285 void setData(
const unsigned slice, vnl_matrix<double> &newData);
292 void setDisplayData(QPointer<milxQtImage> newImg);
298 { setDisplayData(newImg); }
308 void setDisplayData(charImageType::Pointer newImg,
const bool flipY =
true);
313 inline void setSharedData(charImageType::Pointer newImg,
const bool flipY =
true)
314 { setDisplayData(newImg, flipY); }
324 void setDisplayData(intImageType::Pointer newImg,
const bool flipY =
true);
329 inline void setSharedData(intImageType::Pointer newImg,
const bool flipY =
true)
330 { setDisplayData(newImg, flipY); }
340 void setDisplayData(rgbImageType::Pointer newImg,
const bool flipY =
true);
345 inline void setSharedData(rgbImageType::Pointer newImg,
const bool flipY =
true)
346 { setDisplayData(newImg, flipY); }
356 void setDisplayData(floatImageType::Pointer newImg,
const bool flipY =
true);
361 inline void setSharedData(floatImageType::Pointer newImg,
const bool flipY =
true)
362 { setDisplayData(newImg, flipY); }
372 void setDisplayData(vectorImageType::Pointer newImg,
const bool flipY =
true);
377 inline void setSharedData(vectorImageType::Pointer newImg,
const bool flipY =
true)
378 { setDisplayData(newImg, flipY); }
430 #if VTK_MAJOR_VERSION <= 5 436 {
return imageData->GetProducerPort(); }
444 return viewer->GetImageActor();
450 #if(VTK_MAJOR_VERSION > 5) 451 inline void SetCursor(vtkResliceCursor *newCursor)
453 viewer->SetCursor(newCursor);
456 inline void SetCursor(vtkCursor3D *newCursor)
458 viewer->SetCursor(newCursor);
465 #if(VTK_MAJOR_VERSION > 5) 466 inline vtkResliceCursor* GetCursor()
468 return viewer->GetCursor();
471 inline vtkCursor3D* GetCursor()
473 return viewer->GetCursor();
480 #if(VTK_MAJOR_VERSION > 5) 481 inline void SetCursorActor(vtkResliceCursorActor *newCursorActor)
483 viewer->SetCursorActor(newCursorActor);
488 viewer->SetCursorActor(newCursorActor);
497 return viewer->GetCursorActor();
505 return GetImageActor()->GetDisplayExtent();
519 return viewer->GetRenderWindow()->GetInteractor();
594 return (!eightbit && !rgb && !vectorised);
620 return usingVTKImage;
639 if(viewer->GetImageActor()->GetInterpolate())
650 return orientAct->isChecked();
658 return cursorAct->isChecked();
669 actualNumberOfDimensions = dims;
671 inline size_t getActualNumberOfDimensions()
673 return actualNumberOfDimensions;
683 void trackView(
milxQtImage *windowToTrack, ViewType viewTo);
686 vtkSmartPointer<vtkImageData> butterWorthHighPass(vtkSmartPointer<vtkImageData> img);
689 void userEvent(QMouseEvent *event = NULL);
690 void userEvent(QKeyEvent *event);
691 void userEvent(QWheelEvent *event);
696 virtual void updateCoords(vtkObject *obj);
701 void updateSlice(vtkObject *obj);
706 void updateTrackedView(vtkObject *obj);
711 virtual void contour();
717 void autoLevel(
float percentile=0.99);
722 void setLevel(
int level);
729 return viewer->GetWindowLevel();
735 double GetIntensityWindow();
740 void SetIntensityWindow(
double window);
745 double GetIntensityLevel();
750 void SetIntensityLevel(
double level);
751 #if (ITK_REVIEW || ITK_VERSION_MAJOR > 3) 756 void overlay(QString filename =
"");
761 void overlayContour(QString filename =
"");
766 void computeContour();
767 #endif // (ITK_REVIEW || ITK_VERSION_MAJOR > 3) 772 void blend(QString filename =
"",
float opacity = -1.0);
777 void blend(
milxQtImage *imageToMatch,
float opacity = -1.0);
782 void volumeRendering();
787 void imageInformation();
802 void histogramEqualisation();
807 void gradientMagnitude();
832 void invertIntensity();
842 void matchInfo(QString filename =
"");
852 void matchHistogram(QString filename =
"");
857 void resample(QString filename =
"");
864 void mask(QString filename =
"");
869 void subsample(
size_t xSampleFactor = 0,
size_t ySampleFactor = 0,
size_t zSampleFactor = 0);
876 void crop(QString filename =
"");
881 void resampleLabel(QString filename =
"");
888 void transform(QString filename =
"", QString refImgFilename =
"",
bool inverse =
false);
893 void checkerBoard(QString filename =
"",
int numberOfSquares = 0);
900 void checkerBoard(
milxQtImage *img,
int numberOfSquares = 0);
907 void distanceMap(
bool signedDistance =
true,
bool inside =
false);
912 void thresholdAbove(
float value = 0,
float level = 0);
917 void thresholdBelow(
float value = 0,
float level = 0);
922 void threshold(
float value = 0,
float blevel = 0,
float alevel = 0);
927 void binaryThreshold(
float value = 0,
float blevel = 0,
float alevel = 0);
932 void otsu(
int bins = 0);
937 void otsuMultiple(
int bins = 0,
int labels = 0);
942 void flip(
bool xAxis =
false,
bool yAxis =
false,
bool zAxis =
false,
bool aboutOrigin =
true);
949 void surface(
const float value = numeric_limits<float>::max());
966 void component(
int index = -1);
980 void vectorField(
int subsampleFactor = 0,
float scaling = 0.0);
992 void anisotropicDiffusion();
997 void gaussianSmooth();
1012 void zeros(
const unsigned long xSize,
const unsigned long ySize,
const unsigned long zSize,
milxQtImage *refImage = NULL);
1017 void resize(
double outputSpacing = 0.0);
1022 void resize(
const unsigned long xSize,
const unsigned long ySize,
const unsigned long zSize,
milxQtImage *refImage = NULL);
1032 void add(QString filename =
"");
1042 void subtract(QString filename =
"");
1052 void multiply(QString filename =
"");
1057 void scale(
float scaling);
1080 void interpolateDisplay(
const bool quietly =
false);
1081 inline void disableInterpolateDisplay()
1082 { viewer->GetImageActor()->InterpolateOn(); interpolateDisplay(); }
1083 inline void enableInterpolateDisplay()
1084 { viewer->GetImageActor()->InterpolateOff(); interpolateDisplay(); }
1092 void applyOrientDisplay(
const bool quietly =
false);
1093 inline void disableApplyOrientDisplay()
1094 { orientAct->setChecked(
false); applyOrientDisplay(); }
1095 inline void enableApplyOrientDisplay()
1096 { orientAct->setChecked(
true); applyOrientDisplay(); }
1104 void setDefaultOrientation(
int orientMode);
1111 virtual void enableScale(QString title =
"",
const bool quiet =
false,
double minRange = 0.0,
double maxRange = 0.0,
int noOfLabels = 3);
1118 virtual void scaleDisplay(
const bool forceDisplay =
false);
1123 virtual void showCrosshair(
const bool quietly =
false);
1132 viewer->EnableCursor();
1133 cursorAct->setChecked(
true);
1142 viewer->DisableCursor();
1143 cursorAct->setChecked(
false);
1153 viewer->GetRenderWindow()->SetCurrentCursor(VTK_CURSOR_CROSSHAIR);
1154 crosshairAct->setChecked(
true);
1163 viewer->GetRenderWindow()->SetCurrentCursor(0);
1164 crosshairAct->setChecked(
false);
1166 #if VTK_MAJOR_VERSION > 5 1171 virtual void resliceMode(
const bool quietly =
false);
1176 virtual inline void enableResliceMode()
1178 printDebug(
"Oblique slicing enabled. Use Shift + Left Mouse.");
1179 viewer->GetInteractorStyle()-> SetInteractionModeToImage3D();
1180 resliceAct->setChecked(
true);
1186 virtual inline void disableResliceMode()
1188 viewer->GetInteractorStyle()->SetInteractionModeToImageSlicing();
1189 resliceAct->setChecked(
false);
1197 void setView(
int viewMode);
1202 virtual void viewToXYPlane();
1207 virtual void viewToZXPlane();
1212 virtual void viewToZYPlane();
1219 viewer->SetCursorFocalPoint(position);
1220 viewer->UpdateCursor();
1227 {
return viewer->GetCursorFocalPoint(); }
1232 virtual void updateLookupTable();
1237 void histogram(
int bins = 256,
float belowValue = 0,
float aboveValue = 255,
bool plotHistogram =
true);
1249 void setSlice(
int slice);
1256 return viewer->GetSlice();
1264 return viewer->GetWindowLevel()->GetWindow();
1272 return viewer->GetWindowLevel()->GetLevel();
1280 viewer->GetWindowLevel()->SetWindow(window);
1288 viewer->GetWindowLevel()->SetLevel(level);
1305 virtual void createMenu(QMenu *menu);
1313 void generateImage(
const bool quietly =
false);
1318 void generateVoxelisedSurface(vtkSmartPointer<vtkPolyData> surfaceToVoxelise,
double *bounds = NULL,
double *spacing = NULL);
1327 virtual void customOperation();
1328 void updateModelActor(vtkObject * obj,
unsigned long,
void * client_data,
void *, vtkCommand * command);
1329 void updateDisplay(QPointer<milxQtImage> img);
1336 void imageToSurface(vtkSmartPointer<vtkImageData>,
const float );
1341 void imageToPolyData(vtkSmartPointer<vtkImageData> );
1346 void imageToPseudoImage(vectorImageType::Pointer );
1351 void imageToVectorField(vectorImageType::Pointer, floatImageType::Pointer,
int,
float);
1356 void imageToTensorField(vectorImageType::Pointer, floatImageType::Pointer,
int,
float );
1361 void imageToStreamLines(vectorImageType::Pointer, floatImageType::Pointer );
1366 void imageToVolume(vtkSmartPointer<vtkImageData> ,
bool);
1371 void imageToPlot(vtkSmartPointer<vtkImageData>,
int);
1376 void modified(QPointer<milxQtImage> );
1381 void coordinateChanged(
int,
int,
int);
1413 vtkSmartPointer<vtkImageAccumulate>
hist;
1492 void updateData(
const bool orient =
true);
1505 void createActions();
1510 void createConnections();
1515 void contextMenuEvent(QContextMenuEvent *event);
1520 QMenu* basicContextMenu();
1525 QMenu* operationsMenu();
1530 QMenu* thresholdsMenu();
1535 QMenu* transformsMenu();
1540 QMenu* vectorsMenu();
1545 void dropEvent(QDropEvent *event);
1551 virtual void SetupWidgets(vtkRenderWindowInteractor *interactor);
1556 inline void updateViewer(vtkObject * obj,
unsigned long,
void * client_data,
void *, vtkCommand * command)
1558 #if VTK_MAJOR_VERSION <= 5 1559 viewer->SetInput(imageData);
1561 viewer->SetInputData(imageData);
1568 QString getOpenFilename(
const QString labelForDialog =
"Select Image", QString exts =
"");
1574 #endif // MILXQTIMAGE_H void setSharedData(rgbImageType::Pointer newImg, const bool flipY=true)
Shares the ITK image data to image (same as setDisplayData()). You will need to call generate image a...
QAction * blendAct
Action for blending images.
QAction * matchAct
Action for matching info of image to another image.
vtkSmartPointer< vtkImageData > imageData
Points to the current VTK Image Data, Smart Pointer.
bool isFloatingPointImage()
Returns true if image is a floating point (float) image.
QAction * overlayAct
Action for overlaying labelled image.
QAction * orientAct
Orient image?
void setCrosshairPosition(double *position)
Set the position of the Crosshair.
QAction * histogramAct
Action for displaying histogram.
bool eightbit
Using eightbit data?
QAction * cropAct
Action for auto cropping image.
void setIntensityWindow(double window)
Get or set the window/level for the image intensity tranfert function.
itkEventQtObserver::Pointer observeProgress
Observer for the Qt event loop.
void SetInput(floatImageType::Pointer newImg, const bool flipY=true)
ITK interface function: Assigns the image data internally. Same as setData() function.
virtual vtkRenderWindowInteractor * GetVTKInteractor()
Get the interactor associated with the view rendering.
void setSharedData(vectorImageType::Pointer newImg, const bool flipY=true)
Shares the ITK image data to image (same as setDisplayData()). You will need to call generate image a...
QAction * relabelAct
Action for relabelling image.
This class represents the MILX Qt Render Window Display object using QVTK.
QAction * cannyAct
Action for canny edges of image.
void SetInput(charImageType::Pointer newImg, const bool flipY=true)
ITK interface function: Assigns the image data internally. Same as setData() function.
vtkSmartPointer< vtkImageViewer3 > viewer
VTK Viewer handler, Smart Pointer.
vtkSmartPointer< vtkImagePermute > permute
Permute axis class, Smart Pointer.
QAction * otsuMultipleAct
Otsu Threshold.
void setSharedData(floatImageType::Pointer newImg, const bool flipY=true)
Shares the ITK image data to image (same as setDisplayData()). You will need to call generate image a...
This class represents the MILX Qt Image Display object using VTK.
vtkProp3D * GetCursorActor()
Set the internal cursor used for display.
QAction * pseudoImageAct
Action for displaying vector/tensor fields as a pseudo image.
QAction * vectorMagnitudeAct
Action for displaying magnitude of vector images.
floatImageType::Pointer imageFloat
Up to date floating point image data.
virtual void disableCrosshair()
removes the cursor/crosshair.
QAction * cursorAct
Show cursor?
void updateViewer(vtkObject *obj, unsigned long, void *client_data, void *, vtkCommand *command)
Update the viewer image data to reflect changes.
void setSharedData(charImageType::Pointer newImg, const bool flipY=true)
Shares the ITK image data to image (same as setDisplayData()). You will need to call generate image a...
QAction * flipAct
Action for flipping image.
QAction * distMapAct
Action for distance map of image.
vtkSmartPointer< vtkImageAccumulate > hist
Histogram filter, allocated on histogram() call.
QAction * surfacePlotAct
Action for displaying surface plot.
QAction * resliceAct
Reslice mode?
QAction * laplacianAct
Action for Laplacian of image.
bool isVTKImage()
Returns true if image is a VTK-type image.
vtkImageActor * GetImageActor()
Returns the internal image actor used for display.
double stddevValue
Std deviation data value currently held.
void setFloatingPointImage()
Sets image is a floating point (float) image. Relevant only for when creating images, otherwise automatically set.
void setActualNumberOfDimensions(const size_t dims)
Sets the actual number of dimensions of the image.
QAction * belowAct
Threshold from below.
QAction * bandAct
Threshold inbetween band.
QAction * streamLinesAct
Action for displaying stream lines.
QAction * otsuAct
Otsu Threshold.
bool track
track the coordinates during user interaction
QAction * volRenderAct
Action for volume rendering.
vectorImageType::Pointer GetVectorImage()
Returns the internal vector image data. Unlike the other Get*Image() members, the return value can be...
QAction * matchHistAct
Action for matching histogram of image.
bool is32BitImage()
Returns true if image is an 32-bit (int) image.
bool appendedData
Appended image data?
void SetCursorActor(vtkActor *newCursorActor)
Set the internal cursor actor used for display.
QAction * infoAct
Action for displaying information about the image.
QMenu * vectorMenu
Vector Menu.
QAction * checkerAct
Action for checkerboard of image.
QMenu * transformMenu
Transform Menu.
bool imported
Imported before?
virtual vtkDataSet * GetDataSet()
Get the data, return the vtkImageData object downcast to vtkDataSet, useful for getting scalar range ...
QAction * aboveAct
Threshold from above.
rgbImageType::Pointer GetRGBImage()
Returns the internal RGB image data.
vtkImageMapToWindowLevelColors * GetWindowLevel()
Returns the internal image window levels data used for display.
QMenu * thresholdMenu
Threshold Menu.
int getSlice()
Gets the current slice of the volume.
virtual void enableCrosshair()
Enables the cursor/crosshair for marking. Image must be generated before calling. ...
#define MILXQT_EXPORT
Define Windows DLL importing.
QAction * transformAct
Action for transforming image.
QAction * levelAct
Action for auto-levelling gamma for display.
QAction * normAct
Action for normalization of image.
bool isOriented()
Returns true if orientation is applied to the display of the image.
QAction * binaryAct
Binary Threshold.
void SetInput(intImageType::Pointer newImg, const bool flipY=true)
ITK interface function: Assigns the image data internally. Same as setData() function.
bool viewerSetup
has the viewer/window been setup (only done initial so is to not disturb users settings) ...
bool isCrosshair()
Returns true if cursor shown to the display of the image.
QAction * equaliseAct
Action for contouring image.
QAction * sobelAct
Action for sobel edges of image.
double meanValue
Other Variables.
bool integer
Using integer data?
QAction * overlayContourAct
Action for overlaying labelled image as contour.
QAction * interpolateAct
Interpolate image?
QAction * resampleAct
Action for resampling image.
QAction * highPassAct
Action for high pass filtering of image.
double minValue
min value in image
QAction * gradMagAct
Action for gradient magnitude of image.
double getIntensityLevel()
Get or set the window/level for the image intensity tranfert function.
QList< ModelActorItem > modelActors
Model actors being displayed in image view.
vtkAlgorithmOutput * GetOutputPort()
Returns the image data object (ImageData) producer port used internally VTK style.
void set8BitImage()
Sets image as an 8-bit (unsigned char) image. Relevant only for when creating images, otherwise automatically set.
charImageType::Pointer imageChar
Up to date 8-bit greyscale image data.
void SetInput(vtkSmartPointer< vtkImageData > newImg)
VTK interface function: Assigns the image data internally. Same as setData() function.
QAction * gaussianAct
Action for Gaussian smoothing of image.
bool isVectorImage()
Returns true if image is a vector image.
QAction * subsampleAct
Action for downsampling image.
QAction * rescaleAct
Action for contouring image.
bool usingVTKImage
using VTK image data?
double * getCrosshairPosition()
Get the position of the Crosshair.
bool isDisplayFlipped()
Returns true if image was flipped internally for display purposes only.
void set32BitImage()
Sets image as an 32-bit (int) image. Relevant only for when creating images, otherwise automatically ...
double maxValue
max value in image
bool vectorised
Using Vector image data?
QAction * vectorFieldAct
Action for displaying vector/tensor fields.
QAction * resampleSpacingAct
Action for resampling image based on spacing.
void setSharedData(intImageType::Pointer newImg, const bool flipY=true)
Shares the ITK image data to image (same as setDisplayData()). You will need to call generate image a...
vtkSmartPointer< vtkImageData > GetOutput()
Returns the image data object (ImageData) used internally VTK style.
QString strippedNamePrefix()
Returns the stripped (path removed) name of the data with "Image" prefix.
QAction * invertAct
Action for invert intensity of image.
vtkSmartPointer< vtkImageAppend > imageDataAppended
Appended Data.
virtual const char * GetNameOfClass() const
ITK interfacing member for exceptions.
This class can be attached as an observer to trigger Qt to update the event loop. ...
void setSharedData(QPointer< milxQtImage > newImg)
Shares the ITK image data to image (same as setDisplayData()). You will need to call generate image a...
bool flipped
Flip for display?
charImageType::Pointer GetCharImage()
Returns the internal unsigned char image data.
void SetInput(rgbImageType::Pointer newImg, const bool flipY=true)
ITK interface function: Assigns the image data internally. Same as setData() function.
double getIntensityWindow()
Get or set the window/level for the image intensity tranfert function.
QAction * medianAct
Action for median smoothing of image.
size_t actualNumberOfDimensions
All images loaded as 3D images or 3D vector images, this shows actual dimension.
virtual void enableCrosshairPointer()
Enables the mouse pointer as a crosshair instead. Scene must be rendered before calling.
floatImageType::Pointer GetFloatImage()
Returns the internal float image data.
QAction * computeContourAct
Action for contouring image.
void SetInput(vectorImageType::Pointer newImg, const bool flipY=true)
ITK interface function: Assigns the image data internally. Same as setData() function.
QAction * maskAct
Action for resampling image.
bool isRGBImage()
Returns true if image is an RGB (3-vector unsigned char image) image.
QAction * polyDataAct
Action for image to poly data.
void setRGBImage()
Sets image as an RGB (3-vector unsigned char image) image. Relevant only for when creating images...
int * GetDisplayExtent()
Returns the current display extent of the image data, i.e the current slice dimensions/extents.
vectorImageType::Pointer imageVector
Up to date vector image data.
intImageType::Pointer imageInt
Up to date 32-bit greyscale image data.
bool is8BitImage()
Returns true if image is an 8-bit (unsigned char) image.
virtual void disableCrosshairPointer()
Restores the mouse pointer to default.
QAction * smoothAct
Action for smoothing of image.
void setVectorImage()
Sets image as a vector image. Relevant only for when creating images, otherwise automatically set...
bool volume
is the image a volume?
QAction * resampleLabelAct
Action for resampling image.
intImageType::Pointer GetIntImage()
Returns the internal unsigned char image data.
QAction * surfaceAct
Action for image to surface.
QAction * vectorComponentAct
Action for displaying components of vector images.
ViewType viewToTrack
In tracking mode, what slice to show.
QAction * bilateralAct
Action for bilateral smoothing of image.
QMenu * operateMenu
Operate Menu.
void setIntensityLevel(double level)
Get or set the window/level for the image intensity tranfert function.
bool isInterpolated()
Returns true if image display is interpolated.
rgbImageType::Pointer imageRGB
Up to date 32-bit image data (used only internally atm)