Slicer  4.11
Slicer is a multi-platform, free and open source software package for visualization and medical image computing
vtkMRMLMarkupsNode.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 #ifndef __vtkMRMLMarkupsNode_h
19 #define __vtkMRMLMarkupsNode_h
20 
21 // MRML includes
22 #include "vtkMRMLDisplayableNode.h"
23 #include "vtkCurveGenerator.h"
24 #include "vtkMRMLMeasurement.h"
25 
26 // Markups includes
27 #include "vtkSlicerMarkupsModuleMRMLExport.h"
28 
29 // VTK includes
30 #include <vtkPointLocator.h>
31 #include <vtkSmartPointer.h>
32 #include <vtkVector.h>
33 
34 class vtkFrenetSerretFrame;
35 class vtkMRMLUnitNode;
36 
60 
61 class vtkAlgorithmOutput;
62 class vtkCollection;
63 class vtkDataArray;
64 class vtkGeneralTransform;
65 class vtkMatrix4x4;
67 class vtkPolyData;
68 class vtkStringArray;
69 class vtkTransformPolyDataFilter;
70 
71 class VTK_SLICER_MARKUPS_MODULE_MRML_EXPORT vtkMRMLMarkupsNode : public vtkMRMLDisplayableNode
72 {
77 
78 public:
79 
80  struct ControlPoint
81  {
83  {
84  // position is 0
85  this->Position[0] = 0.0;
86  this->Position[1] = 0.0;
87  this->Position[2] = 0.0;
88 
89  this->OrientationMatrix[0] = 1.0;
90  this->OrientationMatrix[1] = 0.0;
91  this->OrientationMatrix[2] = 0.0;
92 
93  this->OrientationMatrix[3] = 0.0;
94  this->OrientationMatrix[4] = 1.0;
95  this->OrientationMatrix[5] = 0.0;
96 
97  this->OrientationMatrix[6] = 0.0;
98  this->OrientationMatrix[7] = 0.0;
99  this->OrientationMatrix[8] = 1.0;
100 
101  Selected = true;
102  Locked = false;
103  Visibility = true;
104  PositionStatus = PositionUndefined;
105  }
106 
107  // Positions and orientation in local coordinates.
108  // If transform is applied to the markup node then world
109  // coordinates may be obtained by applying "to world" transform.
110  double Position[3];
111  // Orientation of x axis (0, 1, 2), y axis (3, 4, 5), and z axis (6, 7, 8).
112  // This memory layout is chosen so that the normal (z axis) can be retrieved quickly.
113  double OrientationMatrix[9];
114 
115  std::string ID;
116  std::string Label;
117  std::string Description;
118  std::string AssociatedNodeID;
119 
120  bool Selected;
121  bool Locked;
124  };
125 
126  typedef std::vector<ControlPoint*> ControlPointsListType;
127 
128  static vtkMRMLMarkupsNode *New();
130 
131  void PrintSelf(ostream& os, vtkIndent indent) override;
132 
133  virtual const char* GetIcon() {return "";};
134 
135  //--------------------------------------------------------------------------
136  // MRMLNode methods
137  //--------------------------------------------------------------------------
138 
139  vtkMRMLNode* CreateNodeInstance() override;
141  const char* GetNodeTagName() override {return "Markups";};
142 
144  void ReadXMLAttributes( const char** atts) override;
145 
147  void WriteXML(ostream& of, int indent) override;
148 
153  void WriteCLI(std::vector<std::string>& commandLine,
154  std::string prefix, int coordinateSystem = 0,
155  int multipleFlag = 1) override;
156 
160 
162  void ProcessMRMLEvents ( vtkObject * /*caller*/,
163  unsigned long /*event*/,
164  void * /*callData*/ ) override;
165 
166 
169 
171  void CreateDefaultDisplayNodes() override;
172 
174 
178  int GetNumberOfMeasurements();
179  int GetNumberOfEnabledMeasurements();
180  vtkMRMLMeasurement* GetNthMeasurement(int id);
181  vtkMRMLMeasurement* GetMeasurement(const char* name);
182  void AddMeasurement(vtkMRMLMeasurement* measurement);
183  void RemoveNthMeasurement(int id);
184  void ClearValueForAllMeasurements();
186 
189  void UpdateAllMeasurements();
190 
192 
201  void SetNthMeasurement(int id, vtkMRMLMeasurement* measurement);
202  void SetNthMeasurement(int id, const std::string& name, double value, const std::string &units,
203  std::string printFormat = "", const std::string description = "",
204  vtkCodedEntry* quantityCode = nullptr, vtkCodedEntry* derivationCode = nullptr,
205  vtkCodedEntry* unitsCode = nullptr, vtkCodedEntry* methodCode = nullptr);
206  void RemoveAllMeasurements();
208 
224  enum
225  {
226  LockModifiedEvent = 19000,
230  PointPositionDefinedEvent, // point was not defined (undefined, preview position status, or non-existent point) before but now it is defined
231  PointPositionUndefinedEvent, // point position was defined and now it is not defined anymore (point deleted or position is not defined)
236  };
237 
242  enum
243  {
247  PositionStatus_Last
248  };
249 
250  static const char* GetPositionStatusAsString(int id);
251  static int GetPositionStatusFromString(const char* name);
252 
254  virtual void RemoveAllControlPoints();
255 
257  void RemoveAllMarkups() { this->RemoveAllControlPoints(); };
258 
260  vtkGetMacro(Locked, int);
268  void SetLocked(int locked);
271  vtkBooleanMacro(Locked, int);
272 
274  vtkMRMLMarkupsDisplayNode *GetMarkupsDisplayNode();
275 
277  bool ControlPointExists(int n);
278 
280  bool MarkupExists(int n) { return this->ControlPointExists(n); }
282  int GetNumberOfControlPoints();
284  int GetNumberOfDefinedControlPoints(bool includePreview=false);
286  int GetNumberOfMarkups() { return this->GetNumberOfControlPoints(); };
288  int GetNumberOfPointsInNthMarkup(int) { return this->GetNumberOfControlPoints(); };
290  ControlPoint* GetNthControlPoint(int n);
292  std::vector<ControlPoint*>* GetControlPoints();
299  int AddNControlPoints(int n, std::string label = std::string(), vtkVector3d* point = nullptr);
302  int AddControlPointWorld(vtkVector3d point, std::string label = std::string());
304  int AddControlPoint(vtkVector3d point, std::string label = std::string());
310  int AddControlPoint(ControlPoint *controlPoint, bool autoLabel=true);
311 
314  vtkVector3d GetNthControlPointPositionVector(int pointIndex);
315 
317  vtkVector3d GetMarkupPointVector(int markupIndex, int) { return this->GetNthControlPointPositionVector(markupIndex); };
318 
320  void GetMarkupPoint(int markupIndex, int pointIndex, double point[3]);
321 
324  void GetNthControlPointPosition(int pointIndex, double point[3]);
325  double* GetNthControlPointPosition(int pointIndex);
328  int GetNthControlPointPositionWorld(int pointIndex, double worldxyz[3]);
329 
331  int GetNthControlPointPositionStatus(int pointIndex);
332 
337  int GetNthControlPointIndexByPositionStatus(int pointIndex, int positionStatus);
338 
340  void UnsetNthControlPointPosition(int pointIndex);
341 
343  void RemoveNthControlPoint(int pointIndex);
344 
346  void RemoveMarkup(int pointIndex) { this->RemoveNthControlPoint(pointIndex); };
347 
354  bool InsertControlPoint(ControlPoint* controlPoint, int targetIndex);
355 
356  //Add and insert control point at index, defined in the world coordinate system.
357  //\sa InsertControlPoint
358  bool InsertControlPointWorld(int n, vtkVector3d pointWorld, std::string label = std::string());
359 
360  //Add and insert control point at index
361  //\sa InsertControlPoint
362  bool InsertControlPoint(int n, vtkVector3d point, std::string label = std::string());
363 
365  void SwapControlPoints(int m1, int m2);
366 
369  void SetNthControlPointPositionFromPointer(const int pointIndex, const double *pos);
372  void SetNthControlPointPositionFromArray(const int pointIndex, const double pos[3], int positionStatus = PositionDefined);
375  void SetNthControlPointPosition(const int pointIndex, const double x, const double y, const double z, int positionStatus = PositionDefined);
379  void SetNthControlPointPositionWorld(const int pointIndex, const double x, const double y, const double z);
382  void SetNthControlPointPositionWorldFromArray(const int pointIndex, const double pos[3], int positionStatus = PositionDefined);
385  void SetNthControlPointPositionOrientationWorldFromArray(const int pointIndex,
386  const double pos[3], const double orientationMatrix[9], const char* associatedNodeID, int positionStatus = PositionDefined);
387 
390  vtkVector3d GetCenterPositionVector();
393  void GetCenterPosition(double point[3]);
396  int GetCenterPositionWorld(double worldxyz[3]);
399  void SetCenterPositionFromPointer(const double *pos);
402  void SetCenterPositionFromArray(const double pos[3]);
405  void SetCenterPosition(const double x, const double y, const double z);
409  void SetCenterPositionWorld(const double x, const double y, const double z);
410 
412  void SetNthControlPointOrientationFromPointer(int n, const double *orientationWXYZ);
414  void SetNthControlPointOrientationFromArray(int n, const double orientationWXYZ[4]);
416  void SetNthControlPointOrientation(int n, double w, double x, double y, double z);
418  void GetNthControlPointOrientation(int n, double orientationWXYZ[4]);
420  double* GetNthControlPointOrientationMatrix(int n);
422  void SetNthControlPointOrientationMatrix(int n, double orientationMatrix[9]);
426  void SetNthControlPointOrientationMatrixWorld(int n, double orientationMatrix[9]);
428  double* GetNthControlPointNormal(int n);
430  void GetNthControlPointNormalWorld(int n, double normalWorld[3]);
435  vtkVector4d GetNthControlPointOrientationVector(int pointIndex);
436 
438  std::string GetNthControlPointAssociatedNodeID(int n = 0);
439  void SetNthControlPointAssociatedNodeID(int n, std::string id);
440 
442  std::string GetNthMarkupAssociatedNodeID(int n = 0) { return this->GetNthControlPointAssociatedNodeID(n); }
444  void SetNthMarkupAssociatedNodeID(int n, std::string id) { this->SetNthControlPointAssociatedNodeID(n,id); }
445 
447  std::string GetNthControlPointID(int n);
448 
450  std::string GetNthMarkupID(int n = 0) { return this->GetNthControlPointID(n); }
451 
453  int GetNthControlPointIndexByID(const char* controlPointID);
455  ControlPoint* GetNthControlPointByID(const char* controlPointID);
456 
459  bool GetNthControlPointSelected(int n = 0);
462  void SetNthControlPointSelected(int n, bool flag);
463 
466  bool GetNthControlPointLocked(int n = 0);
473  void SetNthControlPointLocked(int n, bool flag);
474 
476  bool GetNthMarkupLocked(int n = 0) { return this->GetNthControlPointLocked(n); };
478  void SetNthMarkupLocked(int n, bool flag) { this->SetNthControlPointLocked(n, flag); }
479 
482  bool GetNthControlPointVisibility(int n = 0);
490  void SetNthControlPointVisibility(int n, bool flag);
491 
494  std::string GetNthControlPointLabel(int n = 0);
496  void SetNthControlPointLabel(int n, std::string label);
497 
499  std::string GetNthMarkupLabel(int n = 0) { return this->GetNthControlPointLabel(n); }
501  void SetNthMarkupLabel(int n, std::string label) { this->SetNthControlPointLabel(n, label); }
502 
505  std::string GetNthControlPointDescription(int n = 0);
507  void SetNthControlPointDescription(int n, std::string description);
508 
511  bool CanApplyNonLinearTransforms()const override;
514  void ApplyTransform(vtkAbstractTransform* transform) override;
515 
518  std::string GetMarkupLabelFormat();
528  void SetMarkupLabelFormat(std::string format);
529 
534  std::string ReplaceListNameInMarkupLabelFormat();
535 
543  bool GetModifiedSinceRead() override;
544 
548  bool ResetNthControlPointID(int n);
549 
553  vtkGetMacro(RequiredNumberOfControlPoints, int);
554 
563  vtkGetMacro(MaximumNumberOfControlPoints, int);
564 
565  // WXYZ: W rotation angle in degrees, XYZ is rotation axis.
566  static void ConvertOrientationMatrixToWXYZ(const double orientationMatrix[9], double orientationWXYZ[4]);
567  static void ConvertOrientationWXYZToMatrix(double orientationWXYZ[4], double orientationMatrix[9]);
568 
569  void GetControlPointLabels(vtkStringArray* labels);
570 
571  vtkPoints* GetCurvePoints();
572  vtkPoints* GetCurvePointsWorld();
573 
574  vtkPolyData* GetCurve();
575  vtkPolyData* GetCurveWorld();
576 
577  vtkAlgorithmOutput* GetCurveWorldConnection();
578 
579  vtkGetMacro(CurveClosed, bool);
580 
581  int GetControlPointIndexFromInterpolatedPointIndex(vtkIdType interpolatedPointIndex);
582 
586  vtkCurveGenerator* GetCurveGenerator() { return this->CurveGenerator.GetPointer(); };
587 
588  void GetRASBounds(double bounds[6]) override;
589  void GetBounds(double bounds[6]) override;
590 
592  int GetClosestControlPointIndexToPositionWorld(double pos[3]);
593 
599  void SetControlPointPositionsWorld(vtkPoints* points);
600 
602  void GetControlPointPositionsWorld(vtkPoints* points);
603 
605  virtual vtkMatrix4x4* GetInteractionHandleToWorldMatrix();
606 
607  virtual std::string GetPropertiesLabelText();
608 
610  vtkMRMLUnitNode* GetUnitNode(const char* quantity);
611 
614  virtual void UpdateAssignedAttribute() {};
615 
616 protected:
618  ~vtkMRMLMarkupsNode() override;
620  void operator=(const vtkMRMLMarkupsNode&);
621 
622  vtkSmartPointer<vtkStringArray> TextList;
623 
629  bool SetControlPointLabelsWorld(vtkStringArray* labels, vtkPoints* points, std::string separator = "");
630 
634  ControlPoint* GetNthControlPointCustomLog(int n, const char* failedMethodName);
635 
639  void SetNthControlPointID(int n, std::string id);
640 
644  std::string GenerateUniqueControlPointID();
645 
646  std::string GenerateControlPointLabel(int controlPointIndex);
647 
648  virtual void UpdateCurvePolyFromControlPoints();
649 
650  void OnTransformNodeReferenceChanged(vtkMRMLTransformNode* transformNode) override;
651 
654  virtual void UpdateMeasurementsInternal();
655 
658  virtual void WriteMeasurementsToDescription();
659 
661  virtual void UpdateInteractionHandleToWorldMatrix();
662 
665  int RequiredNumberOfControlPoints{0};
668  int MaximumNumberOfControlPoints{0};
669 
670  bool CurveClosed{false};
671 
674 
676  vtkSmartPointer<vtkCurveGenerator> CurveGenerator;
677 
682  vtkSmartPointer<vtkFrenetSerretFrame> CurveCoordinateSystemGeneratorWorld;
683 
686  vtkSmartPointer<vtkPolyData> CurveInputPoly;
687 
688  vtkSmartPointer<vtkTransformPolyDataFilter> CurvePolyToWorldTransformer;
689  vtkSmartPointer<vtkGeneralTransform> CurvePolyToWorldTransform;
690 
693  vtkSmartPointer<vtkPointLocator> TransformedCurvePolyLocator;
694 
696  int Locked{0};
697 
698  std::string MarkupLabelFormat{"%N-%d"};
699 
703  int LastUsedControlPointNumber{0};
704 
707  vtkVector3d CenterPos;
708 
710  vtkCollection* Measurements;
711 
712  std::string PropertiesLabelText;
713 
715  vtkSmartPointer<vtkMatrix4x4> InteractionHandleToWorldMatrix;
716 
718  bool IsUpdatingPoints{false};
719 
720  friend class qSlicerMarkupsModuleWidget; // To directly access measurements
721 };
722 
723 #endif
void SetNthMarkupAssociatedNodeID(int n, std::string id)
void ProcessMRMLEvents(vtkObject *, unsigned long, void *) override
alternative method to propagate events generated in Display nodes
ControlPointsListType ControlPoints
Vector of control points.
void ReadXMLAttributes(const char **atts) override
Read node attributes from XML file
Filter that generates curves between points of an input polydata.
MRML node for representing a transformation between this node space and a parent node space...
virtual vtkMRMLStorageNode * CreateDefaultStorageNode()
virtual void GetBounds(double bounds[6])
int GetNumberOfPointsInNthMarkup(int)
bool MarkupExists(int n)
Deprecated. Use ControlPointExists instead.
std::vector< ControlPoint * > ControlPointsListType
const char * GetNodeTagName() override
Get node XML tag name (like Volume, Model)
bool GetNthMarkupLocked(int n=0)
vtkSmartPointer< vtkCurveGenerator > CurveGenerator
Converts curve control points to curve points.
virtual void WriteCLI(std::vector< std::string > &vtkNotUsed(commandLine), std::string vtkNotUsed(prefix), int vtkNotUsed(coordinateSystemFlag)=0, int vtkNotUsed(multipleFlag)=1)
virtual bool GetModifiedSinceRead()
virtual void ApplyTransform(vtkAbstractTransform *transform)
Class for storing well-defined measurement results, using coded entries.
vtkSmartPointer< vtkStringArray > TextList
void SetNthMarkupLocked(int n, bool flag)
void WriteXML(ostream &of, int indent) override
Write this node&#39;s information to a MRML file in XML format.
vtkSmartPointer< vtkPolyData > CurveInputPoly
vtkVector3d GetMarkupPointVector(int markupIndex, int)
std::string GetNthMarkupLabel(int n=0)
void operator=(const vtkMRMLDisplayableNode &)
std::string GetNthMarkupAssociatedNodeID(int n=0)
void SetNthMarkupLabel(int n, std::string label)
vtkSmartPointer< vtkTransformPolyDataFilter > CurvePolyToWorldTransformer
Simple class for storing standard coded entries (coding scheme, value, meaning triplets) ...
Definition: vtkCodedEntry.h:26
void PrintSelf(ostream &os, vtkIndent indent) override
virtual void CreateDefaultDisplayNodes()
virtual const char * GetIcon()
void RemoveMarkup(int pointIndex)
vtkSmartPointer< vtkFrenetSerretFrame > CurveCoordinateSystemGeneratorWorld
vtkSmartPointer< vtkGeneralTransform > CurvePolyToWorldTransform
A superclass for other storage nodes.
std::string PropertiesLabelText
vtkMRMLNode * CreateNodeInstance() override=0
MRMLNode methods.
vtkCollection * Measurements
List of measurements stored for the markup.
vtkMRMLCopyContentMacro(vtkMRMLStorableNode)
vtkCurveGenerator * GetCurveGenerator()
virtual bool CanApplyNonLinearTransforms() const
std::string GetNthMarkupID(int n=0)
Abstract Superclass for all specific types of MRML nodes.
Definition: vtkMRMLNode.h:167
vtkSmartPointer< vtkPointLocator > TransformedCurvePolyLocator
virtual void UpdateAssignedAttribute()
Node that holds the information about a unit.
virtual void OnTransformNodeReferenceChanged(vtkMRMLTransformNode *transformNode)
Called when transform node reference added/modified/removed.
vtkSmartPointer< vtkMatrix4x4 > InteractionHandleToWorldMatrix
Transform that moves the xyz unit vectors and origin of the interaction handles to local coordinates...
virtual void GetRASBounds(double bounds[6])