NifTK  16.4.1 - 0798f20
CMIC's Translational Medical Imaging Platform
niftkPaintbrushTool.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 niftkPaintbrushTool_h
16 #define niftkPaintbrushTool_h
17 
18 #include "niftkMIDASExports.h"
19 
20 #include <itkImage.h>
21 
22 #include <mitkGeometry3D.h>
23 #include <mitkImage.h>
24 #include <mitkOperation.h>
25 #include <mitkOperationActor.h>
26 #include <mitkSegTool2D.h>
27 
28 #include <usServiceReference.h>
29 
31 
35 
36 namespace niftk
37 {
38 
66 class NIFTKMIDAS_EXPORT PaintbrushTool : public mitk::SegTool2D, public FilteringStateMachine
67 {
68 
69 public:
70 
73  enum
74  {
78  DILATIONS_SUBTRACTIONS
79  };
80 
83 
86 
89 
92 
93 
94  mitkClassMacro(PaintbrushTool, mitk::SegTool2D)
95  itkNewMacro(PaintbrushTool)
96 
97  typedef itk::Image<mitk::Tool::DefaultSegmentationDataType, 3> ImageType;
98  typedef itk::MIDASImageUpdatePixelWiseSingleValueProcessor<mitk::Tool::DefaultSegmentationDataType, 3> ProcessorType;
99 
100  virtual void InitializeStateMachine();
101 
103  virtual const char* GetName() const;
104  virtual const char** GetXPM() const;
105 
107  static const std::string REGION_PROPERTY_NAME;
108 
111  int GetCursorSize() const;
112 
114  void SetCursorSize(int cursorSize);
115 
118  bool GetErosionMode() const;
119 
122  void SetErosionMode(bool erosionMode);
123 
125  mitk::Message1<int> CursorSizeChanged;
126 
128  virtual void ExecuteOperation(mitk::Operation* operation);
129 
131  virtual bool StartAddingAddition(mitk::StateMachineAction* action, mitk::InteractionEvent* event);
132  virtual bool KeepAddingAddition(mitk::StateMachineAction* action, mitk::InteractionEvent* event);
133  virtual bool StopAddingAddition(mitk::StateMachineAction* action, mitk::InteractionEvent* event);
134  virtual bool StartAddingSubtraction(mitk::StateMachineAction* action, mitk::InteractionEvent* event);
135  virtual bool KeepAddingSubtraction(mitk::StateMachineAction* action, mitk::InteractionEvent* event);
136  virtual bool StopAddingSubtraction(mitk::StateMachineAction* action, mitk::InteractionEvent* event);
137  virtual bool StartRemovingSubtraction(mitk::StateMachineAction* action, mitk::InteractionEvent* event);
138  virtual bool KeepRemovingSubtraction(mitk::StateMachineAction* action, mitk::InteractionEvent* event);
139  virtual bool StopRemovingSubtraction(mitk::StateMachineAction* action, mitk::InteractionEvent* event);
140 
142  mitk::Message1<int> SegmentationEdited;
143 
144 protected:
145 
146  PaintbrushTool(); // purposely hidden
147  virtual ~PaintbrushTool(); // purposely hidden
148 
150  virtual void ConnectActionsAndFunctions();
151 
160  bool FilterEvents(mitk::InteractionEvent* event, mitk::DataNode* dataNode);
161 
167  virtual void Activated();
168 
174  virtual void Deactivated();
175 
176 private:
177 
178  // Operation constant, used in Undo/Redo framework.
179  static const mitk::OperationType MIDAS_PAINTBRUSH_TOOL_OP_EDIT_IMAGE;
180 
187  void GetListOfAffectedVoxels(
188  const mitk::PlaneGeometry& planeGeometry,
189  mitk::Point3D& currentPoint,
190  mitk::Point3D& previousPoint,
191  ProcessorType &processor);
192 
194  bool MarkInitialPosition(unsigned int dataIndex, mitk::StateMachineAction* action, mitk::InteractionEvent* event);
195 
197  void SetInvalidRegion(unsigned int dataIndex);
198 
200  void SetValidRegion(unsigned int dataIndex, const std::vector<int>& boundingBox);
201 
203  void SetRegion(unsigned int dataIndex, bool valid, const std::vector<int>& boundingBox = std::vector<int>());
204 
206  bool DoMouseMoved(mitk::StateMachineAction* action, mitk::InteractionEvent* event,
207  int dataIndex,
208  unsigned char valueForRedo,
209  unsigned char valueForUndo
210  );
211 
213  template<typename TPixel, unsigned int VImageDimension>
214  void RunITKProcessor(
215  itk::Image<TPixel, VImageDimension>* itkImage,
216  ProcessorType::Pointer processor,
217  bool redo,
218  unsigned char valueToWrite
219  );
220 
221  // Pointer to interface object, used as callback in Undo/Redo framework
222  PaintbrushToolEventInterface::Pointer m_Interface;
223 
225  int GetDataIndex(bool isLeftMouseButton);
226 
227  // Cursor size for editing, and cursor type is currently always a cross.
228  int m_CursorSize;
229 
230  // This is the 3D geometry associated with the m_WorkingImage, where we assume both working images have same size and geometry.
231  mitk::BaseGeometry* m_WorkingImageGeometry;
232 
233  // This points to the current working image, assuming that we are only ever processing, left, middle or right mouse button at any one time.
234  mitk::Image* m_WorkingImage;
235 
236  // Used between MouseDown and MouseMoved events to track movement.
237  mitk::Point3D m_MostRecentPointInMillimetres;
238 
239  // If m_ErosionMode is true, we update WorkingData 0 and 1, if m_ErosionMode is false, we update WorkingData 2 and 3.
240  bool m_ErosionMode;
241 
242  // Stores the current display interactor configurations when this tool is activated.
243  // The configurations are restored when the tool is deactivated.
244  std::map<us::ServiceReferenceU, mitk::EventConfig> m_DisplayInteractorConfigs;
245 
246 };
247 
248 }
249 
250 #endif
Interface class, simply to callback operations onto the PaintbrushTool.
Definition: niftkPaintbrushToolEventInterface.h:33
Definition: niftkPaintbrushTool.h:75
Paint brush tool used during editing on the morphological editor screen (a.k.a connection breaker)...
Definition: niftkPaintbrushTool.h:66
static const std::string DILATIONS_SUBTRACTIONS_NAME
Stores the name of the MIDAS connection breaker image, used in Morphological Editor.
Definition: niftkPaintbrushTool.h:91
Definition: niftkPaintbrushTool.h:76
Base class for segmentor tools that need access to the list of seeds for the current reference data v...
Definition: niftkTool.h:61
Definition: niftkMeshSmoother.cxx:19
Definition: ReceptorMemberCommandTest.cxx:25
Definition: niftkITKAffineResampleImage.cxx:74
static const std::string DILATIONS_ADDITIONS_NAME
Stores the name of the MIDAS additions image, used in Morphological Editor.
Definition: niftkPaintbrushTool.h:88
itk::Image< mitk::Tool::DefaultSegmentationDataType, 3 > ImageType
Definition: niftkPaintbrushTool.h:97
static const std::string EROSIONS_SUBTRACTIONS_NAME
Stores the name of the MIDAS connection breaker image, used in Morphological Editor.
Definition: niftkPaintbrushTool.h:85
Simultaneous itk::Image and itk::Array (and hence vnl_vector) class.
cl_event event
Definition: glew.h:3231
static const std::string EROSIONS_ADDITIONS_NAME
Stores the name of the MIDAS additions image, used in Morphological Editor.
Definition: niftkPaintbrushTool.h:82
Class to support undo/redo of an operation that takes a list of pixels, and sets them all to a given ...
Definition: itkMIDASImageUpdatePixelWiseSingleValueProcessor.h:32
Definition: niftkExceptionObject.h:21
GLsizei const GLcharARB ** string
Definition: glew.h:5194
Definition: niftkPaintbrushTool.h:77
Common base class for segmentor tools and interactors.
Definition: niftkFilteringStateMachine.h:49