Slicer  5.2
Slicer is a multi-platform, free and open source software package for visualization and medical image computing
vtkSlicerMarkupsLogic.h
Go to the documentation of this file.
1 /*==============================================================================
2 
3  Program: 3D Slicer
4 
5  Portions (c) Copyright Brigham and Women's Hospital (BWH) All Rights Reserved.
6 
7  See COPYRIGHT.txt
8  or http://www.slicer.org/copyright/copyright.txt for details.
9 
10  Unless required by applicable law or agreed to in writing, software
11  distributed under the License is distributed on an "AS IS" BASIS,
12  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  See the License for the specific language governing permissions and
14  limitations under the License.
15 
16 ==============================================================================*/
17 
18 // .NAME vtkSlicerMarkupsLogic - slicer logic class for volumes manipulation
19 // .SECTION Description
20 // This class manages the logic associated with reading, saving,
21 // and changing propertied of the volumes
22 
23 
24 #ifndef __vtkSlicerMarkupsLogic_h
25 #define __vtkSlicerMarkupsLogic_h
26 
27 // Slicer includes
28 #include "vtkSlicerModuleLogic.h"
29 
30 // MRML includes
31 #include "vtkMRMLStorageNode.h"
32 
33 // VTK includes
34 #include "vtkVector.h"
35 
36 // STD includes
37 #include <cstdlib>
38 #include <string>
39 
40 #include "vtkSlicerMarkupsModuleLogicExport.h"
41 
42 class vtkIdList;
43 class vtkMatrix4x4;
44 class vtkMRMLMarkupsNode;
50 class vtkMRMLTableNode;
51 class vtkPlane;
52 class vtkPoints;
53 class vtkPolyData;
55 
57 class VTK_SLICER_MARKUPS_MODULE_LOGIC_EXPORT vtkSlicerMarkupsLogic :
59 {
60 public:
61 
62  enum Events{
63  MarkupRegistered = vtkCommand::UserEvent + 1,
64  MarkupUnregistered
65  };
66 
67  static vtkSlicerMarkupsLogic *New();
69  void PrintSelf(ostream& os, vtkIndent indent) override;
70 
71  void ProcessMRMLNodesEvents(vtkObject *caller,
72  unsigned long event,
73  void *callData ) override;
74 
79  std::string GetSelectionNodeID();
80 
84  std::string GetActiveListID();
85 
88  void SetActiveListID(vtkMRMLMarkupsNode *markupsNode);
89 
95  void SetActiveList(vtkMRMLMarkupsNode* markupsNode);
96 
101  std::string AddNewDisplayNodeForMarkupsNode(vtkMRMLNode *mrmlNode);
102 
108  std::string AddNewFiducialNode(const char *name = "F", vtkMRMLScene *scene = nullptr);
109 
112  vtkMRMLMarkupsNode* AddNewMarkupsNode(std::string className, std::string nodeName=std::string(), vtkMRMLScene* scene = nullptr);
113 
118  int AddControlPoint(double r=0.0, double a=0.0, double s=0.0);
119 
123  void JumpSlicesToLocation(double x, double y, double z, bool centered, int viewGroup = -1, vtkMRMLSliceNode* exclude = nullptr);
126  void JumpSlicesToNthPointInMarkup(const char *id, int n, bool centered = false, int viewGroup = -1, vtkMRMLSliceNode* exclude = nullptr);
129  void FocusCamerasOnNthPointInMarkup(const char *id, int n);
133  void FocusCameraOnNthPointInMarkup(const char *cameraNodeID, const char *markupNodeID, int n);
134 
138  char* LoadMarkups(const char* fileName, const char* fidsName=nullptr, vtkMRMLMessageCollection* userMessages=nullptr);
139 
141  char* LoadMarkupsFiducials(const char* fileName, const char* fidsName=nullptr, vtkMRMLMessageCollection* userMessages=nullptr);
142 
143  char* LoadMarkupsFromFcsv(const char* fileName, const char* nodeName=nullptr, vtkMRMLMessageCollection* userMessages=nullptr);
144  char* LoadMarkupsFromJson(const char* fileName, const char* nodeName=nullptr, vtkMRMLMessageCollection* userMessages=nullptr);
145 
148  void SetAllControlPointsVisibility(vtkMRMLMarkupsNode *node, bool flag);
149  void ToggleAllControlPointsVisibility(vtkMRMLMarkupsNode *node);
150  void SetAllControlPointsLocked(vtkMRMLMarkupsNode *node, bool flag);
151  void ToggleAllControlPointsLocked(vtkMRMLMarkupsNode *node);
152  void SetAllControlPointsSelected(vtkMRMLMarkupsNode *node, bool flag);
153  void ToggleAllControlPointsSelected(vtkMRMLMarkupsNode *node);
155 
160  void SetDisplayNodeToDefaults(vtkMRMLMarkupsDisplayNode *displayNode);
161 
163  void SetDisplayDefaultsFromNode(vtkMRMLMarkupsDisplayNode *displayNode);
164 
169  bool CopyNthControlPointToNewList(int n, vtkMRMLMarkupsNode *markupsNode,
170  vtkMRMLMarkupsNode *newMarkupsNode);
171 
179  bool MoveNthControlPointToNewListAtIndex(int n, vtkMRMLMarkupsNode *markupsNode,
180  vtkMRMLMarkupsNode *newMarkupsNode, int newIndex);
181 
187  void ConvertAnnotationFiducialsToMarkups();
188 
193  void RenameAllControlPointsFromCurrentFormat(vtkMRMLMarkupsNode *markupsNode);
194 
200  bool StartPlaceMode(bool persistent, vtkMRMLInteractionNode* interactionNode = nullptr);
201 
202  vtkSetMacro(AutoCreateDisplayNodes, bool);
203  vtkGetMacro(AutoCreateDisplayNodes, bool);
204  vtkBooleanMacro(AutoCreateDisplayNodes, bool);
205 
206  vtkMRMLMarkupsDisplayNode* GetDefaultMarkupsDisplayNode();
207 
210  void CopyBasicDisplayProperties(vtkMRMLMarkupsDisplayNode *sourceDisplayNode, vtkMRMLMarkupsDisplayNode *targetDisplayNode);
211 
219  static double GetClosedCurveSurfaceArea(vtkMRMLMarkupsClosedCurveNode* curveNode, vtkPolyData* surface = nullptr, bool projectWarp = true);
220 
233  static bool FitSurfaceProjectWarp(vtkPoints* curvePoints, vtkPolyData* surface, double radiusScalingFactor = 1.0, vtkIdType numberOfInternalGridPoints=225);
234 
244  static bool FitSurfaceDiskWarp(vtkPoints* curvePoints, vtkPolyData* surface, double radiusScalingFactor = 1.0);
245 
248  static bool IsPolygonClockwise(vtkPoints* points, vtkIdList* pointIds=nullptr);
249 
251  static bool GetBestFitPlane(vtkMRMLMarkupsNode* curveNode, vtkPlane* plane);
252 
253  std::string GetJsonStorageNodeClassNameForMarkupsType(std::string markupsType);
254  void RegisterJsonStorageNodeForMarkupsType(std::string markupsType, std::string storageNodeClassName);
255  vtkMRMLMarkupsJsonStorageNode* AddNewJsonStorageNodeForMarkupsType(std::string markupsType);
256 
263  void RegisterMarkupsNode(vtkMRMLMarkupsNode* markupsNode,
264  vtkSlicerMarkupsWidget* markupsWidget,
265  bool createPushButton=true);
266 
270  void UnregisterMarkupsNode(vtkMRMLMarkupsNode* markupsNode);
271 
274  bool IsMarkupsNodeRegistered(const char* nodeType) const;
275 
281  vtkSlicerMarkupsWidget* GetWidgetByMarkupsType(const char* markupsType) const;
282 
288  vtkMRMLMarkupsNode* GetNodeByMarkupsType(const char* markupsType) const;
289 
291  const std::list<std::string>& GetRegisteredMarkupsTypes() const;
292 
294  bool GetCreateMarkupsPushButton(const char* markupName) const;
295 
298  static bool ImportControlPointsFromTable(vtkMRMLMarkupsNode* markupsNode, vtkMRMLTableNode* tableNode,
299  int startRow = 0, int numberOfRows = -1);
300 
301  static bool ExportControlPointsToTable(vtkMRMLMarkupsNode* markupsNode, vtkMRMLTableNode* tableNode,
302  int coordinateSystem = vtkMRMLStorageNode::CoordinateSystemRAS);
303 
308  static bool ExportControlPointsToCSV(vtkMRMLMarkupsNode* markupsNode, const std::string filename, bool lps = true);
309 
313  static bool ImportControlPointsFromCSV(vtkMRMLMarkupsNode* markupsNode, const std::string filename);
314 
315  //-----------------------------------------------------------
316  // All public methods below are deprecated
317  //
318  // These methods are deprecated because they use old terms (markup instead of control point),
319 
322  vtkMRMLMarkupsNode *newMarkupsNode)
323  {
324  vtkWarningMacro("vtkSlicerMarkupsLogic::CopyNthMarkupToNewList method is deprecated, please use CopyNthControlPointToNewList instead");
325  return this->CopyNthControlPointToNewList(n, markupsNode, newMarkupsNode);
326  }
329  vtkMRMLMarkupsNode *newMarkupsNode, int newIndex)
330  {
331  vtkWarningMacro("vtkSlicerMarkupsLogic::MoveNthMarkupToNewList method is deprecated, please use MoveNthControlPointToNewListAtIndex instead");
332  return this->MoveNthControlPointToNewListAtIndex(n, markupsNode, newMarkupsNode, newIndex);
333  }
335  int AddFiducial(double r=0.0, double a=0.0, double s=0.0)
336  {
337  vtkWarningMacro("vtkSlicerMarkupsLogic::AddFiducial method is deprecated, please use AddControlPoint instead");
338  return this->AddControlPoint(r, a, s);
339  };
342  {
343  vtkWarningMacro("vtkSlicerMarkupsLogic::SetAllMarkupsVisibility method is deprecated, please use SetAllControlPointsVisibility instead");
344  this->SetAllControlPointsVisibility(node, flag);
345  };
348  {
349  vtkWarningMacro("vtkSlicerMarkupsLogic::ToggleAllMarkupsVisibility method is deprecated, please use ToggleAllControlPointsVisibility instead");
350  this->ToggleAllControlPointsVisibility(node);
351  };
354  {
355  vtkWarningMacro("vtkSlicerMarkupsLogic::SetAllMarkupsLocked method is deprecated, please use SetAllControlPointsLocked instead");
356  this->SetAllControlPointsLocked(node, flag);
357  };
360  {
361  vtkWarningMacro("vtkSlicerMarkupsLogic::ToggleAllMarkupsLocked method is deprecated, please use ToggleAllControlPointsLocked instead");
362  this->ToggleAllControlPointsLocked(node);
363  };
366  {
367  vtkWarningMacro("vtkSlicerMarkupsLogic::SetAllMarkupsSelected method is deprecated, please use SetAllControlPointsSelected instead");
368  this->SetAllControlPointsSelected(node, flag);
369  };
372  {
373  vtkWarningMacro("vtkSlicerMarkupsLogic::ToggleAllMarkupsSelected method is deprecated, please use ToggleAllControlPointsSelected instead");
374  this->ToggleAllControlPointsSelected(node);
375  };
378  {
379  vtkWarningMacro("vtkSlicerMarkupsLogic::RenameAllMarkupsFromCurrentFormat method is deprecated, please use RenameAllControlPointsFromCurrentFormat instead");
380  this->RenameAllControlPointsFromCurrentFormat(markupsNode);
381  };
382 
384  vtkVector3d GenerateUniqueColor();
388  void GenerateUniqueColor(double color[3]);
390 
391 protected:
392 
394  ~vtkSlicerMarkupsLogic() override;
395 
397  void SetMRMLSceneInternal(vtkMRMLScene * newScene) override;
398  void ObserveMRMLScene() override;
399  void SetAndObserveSelectionNode(vtkMRMLSelectionNode* selectionNode);
400 
402  void UpdatePlaceNodeClassNamesInSelectionNode();
403 
405  void RegisterNodes() override;
406  void UpdateFromMRMLScene() override;
407  void OnMRMLSceneNodeAdded(vtkMRMLNode* node) override;
408  void OnMRMLSceneNodeRemoved(vtkMRMLNode* node) override;
409 
410 private:
411 
413  void operator=(const vtkSlicerMarkupsLogic&) = delete;
414 
415  bool AutoCreateDisplayNodes;
416 
417  class vtkInternal;
418  vtkInternal* Internal;
419 };
420 
421 #endif
void PrintSelf(ostream &os, vtkIndent indent) override
static vtkSlicerModuleLogic * New()
The Usual vtk class functions.
void ToggleAllMarkupsLocked(vtkMRMLMarkupsNode *node)
void SetAllMarkupsVisibility(vtkMRMLMarkupsNode *node, bool flag)
MRML node for storing a slice through RAS space.
void SetAllMarkupsSelected(vtkMRMLMarkupsNode *node, bool flag)
virtual void ProcessMRMLNodesEvents(vtkObject *caller, unsigned long event, void *callData)
A set of MRML Nodes that supports serialization and undo/redo.
Definition: vtkMRMLScene.h:57
virtual void OnMRMLSceneNodeAdded(vtkMRMLNode *)
virtual void OnMRMLSceneNodeRemoved(vtkMRMLNode *)
virtual void ObserveMRMLScene()
int AddFiducial(double r=0.0, double a=0.0, double s=0.0)
virtual void SetMRMLSceneInternal(vtkMRMLScene *newScene)
Process interaction events to update state of markup widget nodes.
void ToggleAllMarkupsSelected(vtkMRMLMarkupsNode *node)
void SetAllMarkupsLocked(vtkMRMLMarkupsNode *node, bool flag)
bool MoveNthMarkupToNewList(int n, vtkMRMLMarkupsNode *markupsNode, vtkMRMLMarkupsNode *newMarkupsNode, int newIndex)
MRML node to represent a table object.
virtual void UpdateFromMRMLScene()
Abstract Superclass for all specific types of MRML nodes.
Definition: vtkMRMLNode.h:167
void ToggleAllMarkupsVisibility(vtkMRMLMarkupsNode *node)
MRML node for storing information about the active nodes in the scene.
MRML node to represent a closed curve markup Closed Curve Markups nodes contain N control points...
bool CopyNthMarkupToNewList(int n, vtkMRMLMarkupsNode *markupsNode, vtkMRMLMarkupsNode *newMarkupsNode)
void RenameAllMarkupsFromCurrentFormat(vtkMRMLMarkupsNode *markupsNode)