NifTK  16.4.1 - 0798f20
CMIC's Translational Medical Imaging Platform
niftkContourTool.h
Go to the documentation of this file.
1 /*=============================================================================
2 
3  NifTK: A software platform for medical image computing.
4 
5  Copyright (c) University College London (UCL). All rights reserved.
6 
7  This software is distributed WITHOUT ANY WARRANTY; without even
8  the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
9  PURPOSE.
10 
11  See LICENSE.txt in the top level directory for details.
12 
13 =============================================================================*/
14 
15 #ifndef niftkContourTool_h
16 #define niftkContourTool_h
17 
18 #include "niftkMIDASExports.h"
19 
20 #include <mitkContourModel.h>
21 #include <mitkContourModelSet.h>
22 #include <mitkMessage.h>
23 #include <mitkOperation.h>
24 #include <mitkOperationActor.h>
25 
26 #include <niftkPointUtils.h>
27 
29 #include "niftkTool.h"
30 
31 namespace niftk
32 {
33 
51 class NIFTKMIDAS_EXPORT ContourTool : public Tool {
52 
53 public:
54 
55  mitkClassMacro(ContourTool, Tool)
56 
57 
58  static const std::string EDITING_PROPERTY_NAME;
59 
61  static const std::string MIDAS_CONTOUR_TOOL_BACKGROUND_CONTOUR;
62 
64  virtual void ExecuteOperation(mitk::Operation* operation);
65 
67  virtual void ClearData();
68 
70  virtual mitk::ContourModel* GetContour();
71 
73  virtual void SetFeedbackContourVisible(bool);
74 
76  static void CopyContour(mitk::ContourModel &a, mitk::ContourModel &b);
77 
79  static void CopyContourSet(mitk::ContourModelSet &a, mitk::ContourModelSet &b, bool initialise=true);
80 
82  static void InitialiseContour(mitk::ContourModel &a, mitk::ContourModel &b);
83 
85  mitk::Message<> ContoursHaveChanged;
86 
87 protected:
88 
89  ContourTool(); // purposely hidden
90  virtual ~ContourTool(); // purposely hidden
91 
93  virtual bool OnMousePressed(mitk::StateMachineAction* action, mitk::InteractionEvent* event);
94 
96  void Disable3dRenderingOfNode(mitk::DataNode* node);
97 
99  void AccumulateContourInWorkingData(mitk::ContourModel& contour, int contourIndex);
100 
101  // Utility methods for helping draw lines that require m_Geometry to be set.
102  void ConvertPointInMmToVx(const mitk::Point3D& pointInMm, mitk::Point3D& pointInVx);
103  void ConvertPointToNearestVoxelCentreInVx(const mitk::Point3D& pointInMm, mitk::Point3D& nearestVoxelCentreInVx);
104  void ConvertPointToNearestVoxelCentreInMm(const mitk::Point3D& pointInMm, mitk::Point3D& nearestVoxelCentreInMm);
105  void GetClosestCornerPoint2D(const mitk::Point3D& pointInMm, int* whichTwoAxesInVx, mitk::Point3D& cornerPointInMm);
106 
111  int GetEqualCoordinateAxes(const mitk::Point3D& cornerPoint1InMm, const mitk::Point3D& cornerPoint2InMm, int* whichTwoAxesInVx);
112 
113  void GetAdditionalCornerPoint(const mitk::Point3D& cornerPoint1InMm, const mitk::Point3D& point2InMm, const mitk::Point3D& cornerPoint2InMm, int* whichTwoAxesInVx, mitk::Point3D& newCornerPointInMm);
114 
115  // Main method for drawing a line:
116  // 1.) from previousPoint to currentPoint working around voxel corners, output in contourAroundCorners
117  // 2.) from previousPoint to currentPoint working in a straight line, output in contourAlongLine
118  // Returns true if new points added to contourAroundCorners or the last point updated, otherwise false.
119  bool DrawLineAroundVoxelEdges(
120  const mitk::Image* image, // input
121  const mitk::BaseGeometry* geometry, // input
122  const mitk::PlaneGeometry* planeGeometry, // input
123  const mitk::Point3D& currentPoint, // input
124  const mitk::Point3D& previousPoint, // input
125  mitk::ContourModel& contourAroundCorners, // output
126  mitk::ContourModel& contourAlongLine // output
127  );
128 
129  // Methods for manipulating the "BackgroundContour", which typically doesn't get drawn, but is useful for converting to image coordinates, e.g. for rendering into images for boundaries.
130  mitk::ContourModel* GetBackgroundContour();
131  void SetBackgroundContour(mitk::ContourModel&);
132  void Disable3dRenderingOfBackgroundContour();
133  void SetBackgroundContourVisible(bool);
134  void SetBackgroundContourColor( float r, float g, float b );
135  void SetBackgroundContourColorDefault();
136 
137  // We default this to 1, and use throughout.
138  int m_ContourWidth;
139 
140  // We default this to false, and use throughout.
141  bool m_ContourClosed;
142 
143  // We default this to 0.01, and use throughout when comparing point positions.
144  float m_Tolerance;
145 
146  // This is the 3D geometry associated with the m_WorkingImage
147  mitk::BaseGeometry* m_SegmentationImageGeometry;
148 
149  // This is the current 3D working image (the image that is the segmentation, i.e. a binary image)
150  mitk::Image* m_SegmentationImage;
151 
152  // This is the current 3D reference image (the image that is being segmented, i.e. a grey scale image)
153  mitk::Image* m_ReferenceImage;
154 
155  // Like the base class mitkFeedbackContourTool, we keep a contour that is the straight line, exaclty as we iterate, not working around voxel corners.
156  mitk::ContourModel::Pointer m_BackgroundContour;
157  mitk::DataNode::Pointer m_BackgroundContourNode;
158  bool m_BackgroundContourVisible;
159 
160 private:
161 
162  // Operation constant, used in Undo/Redo framework.
163  static const mitk::OperationType MIDAS_CONTOUR_TOOL_OP_ACCUMULATE_CONTOUR;
164 
166  ContourToolEventInterface::Pointer m_Interface;
167 
168 };
169 
170 }
171 
172 #endif
Base class for segmentor tools that need access to the list of seeds for the current reference data v...
Definition: niftkTool.h:61
GLenum GLsizei GLenum GLenum const GLvoid * image
Definition: glew.h:4052
Definition: niftkMeshSmoother.cxx:19
Definition: ReceptorMemberCommandTest.cxx:25
GLboolean GLboolean g
Definition: glew.h:8272
Provides common functionality for DrawTool and PolyTool where these two tools enable drawing lines an...
Definition: niftkContourTool.h:51
GLdouble GLdouble GLdouble b
Definition: glew.h:7885
GLboolean GLboolean GLboolean GLboolean a
Definition: glew.h:8272
GLdouble GLdouble GLdouble r
Definition: glew.h:1390
Simultaneous itk::Image and itk::Array (and hence vnl_vector) class.
cl_event event
Definition: glew.h:3231
Interface class, simply to callback onto ContourTool for Undo/Redo purposes.
Definition: niftkContourToolEventInterface.h:33
A list of utility methods for working with MIT points and stuff.
Definition: niftkExceptionObject.h:21