Slicer  4.13
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 
187 
196  void SetNthMeasurement(int id, vtkMRMLMeasurement* measurement);
197  void SetNthMeasurement(int id, const std::string& name, double value, const std::string &units,
198  std::string printFormat = "", const std::string description = "",
199  vtkCodedEntry* quantityCode = nullptr, vtkCodedEntry* derivationCode = nullptr,
200  vtkCodedEntry* unitsCode = nullptr, vtkCodedEntry* methodCode = nullptr);
201  void RemoveAllMeasurements();
203 
219  enum
220  {
221  LockModifiedEvent = 19000,
225  PointPositionDefinedEvent, // point was not defined (undefined, preview position status, or non-existent point) before but now it is defined
226  PointPositionUndefinedEvent, // point position was defined and now it is not defined anymore (point deleted or position is not defined)
231  };
232 
237  enum
238  {
242  PositionStatus_Last
243  };
244 
245  static const char* GetPositionStatusAsString(int id);
246  static int GetPositionStatusFromString(const char* name);
247 
249  virtual void RemoveAllControlPoints();
250 
252  void RemoveAllMarkups() { this->RemoveAllControlPoints(); };
253 
255  vtkGetMacro(Locked, int);
263  void SetLocked(int locked);
266  vtkBooleanMacro(Locked, int);
267 
269  vtkMRMLMarkupsDisplayNode *GetMarkupsDisplayNode();
270 
272  bool ControlPointExists(int n);
273 
275  bool MarkupExists(int n) { return this->ControlPointExists(n); }
277  int GetNumberOfControlPoints();
279  int GetNumberOfDefinedControlPoints(bool includePreview=false);
281  int GetNumberOfMarkups() { return this->GetNumberOfControlPoints(); };
283  int GetNumberOfPointsInNthMarkup(int) { return this->GetNumberOfControlPoints(); };
285  ControlPoint* GetNthControlPoint(int n);
287  std::vector<ControlPoint*>* GetControlPoints();
294  int AddNControlPoints(int n, std::string label = std::string(), vtkVector3d* point = nullptr);
297  int AddControlPointWorld(vtkVector3d point, std::string label = std::string());
299  int AddControlPoint(vtkVector3d point, std::string label = std::string());
305  int AddControlPoint(ControlPoint *controlPoint, bool autoLabel=true);
306 
309  vtkVector3d GetNthControlPointPositionVector(int pointIndex);
310 
312  vtkVector3d GetMarkupPointVector(int markupIndex, int) { return this->GetNthControlPointPositionVector(markupIndex); };
313 
315  void GetMarkupPoint(int markupIndex, int pointIndex, double point[3]);
316 
319  void GetNthControlPointPosition(int pointIndex, double point[3]);
320  double* GetNthControlPointPosition(int pointIndex);
323  int GetNthControlPointPositionWorld(int pointIndex, double worldxyz[3]);
324 
326  int GetNthControlPointPositionStatus(int pointIndex);
327 
332  int GetNthControlPointIndexByPositionStatus(int pointIndex, int positionStatus);
333 
335  void UnsetNthControlPointPosition(int pointIndex);
336 
338  void RemoveNthControlPoint(int pointIndex);
339 
341  void RemoveMarkup(int pointIndex) { this->RemoveNthControlPoint(pointIndex); };
342 
349  bool InsertControlPoint(ControlPoint* controlPoint, int targetIndex);
350 
351  //Add and insert control point at index, defined in the world coordinate system.
352  //\sa InsertControlPoint
353  bool InsertControlPointWorld(int n, vtkVector3d pointWorld, std::string label = std::string());
354 
355  //Add and insert control point at index
356  //\sa InsertControlPoint
357  bool InsertControlPoint(int n, vtkVector3d point, std::string label = std::string());
358 
360  void SwapControlPoints(int m1, int m2);
361 
364  void SetNthControlPointPositionFromPointer(const int pointIndex, const double *pos);
367  void SetNthControlPointPositionFromArray(const int pointIndex, const double pos[3], int positionStatus = PositionDefined);
370  void SetNthControlPointPosition(const int pointIndex, const double x, const double y, const double z, int positionStatus = PositionDefined);
374  void SetNthControlPointPositionWorld(const int pointIndex, const double x, const double y, const double z);
377  void SetNthControlPointPositionWorldFromArray(const int pointIndex, const double pos[3], int positionStatus = PositionDefined);
380  void SetNthControlPointPositionOrientationWorldFromArray(const int pointIndex,
381  const double pos[3], const double orientationMatrix[9], const char* associatedNodeID, int positionStatus = PositionDefined);
382 
385  vtkVector3d GetCenterPositionVector();
388  void GetCenterPosition(double point[3]);
391  int GetCenterPositionWorld(double worldxyz[3]);
394  void SetCenterPositionFromPointer(const double *pos);
397  void SetCenterPositionFromArray(const double pos[3]);
400  void SetCenterPosition(const double x, const double y, const double z);
404  void SetCenterPositionWorld(const double x, const double y, const double z);
405 
407  void SetNthControlPointOrientationFromPointer(int n, const double *orientationWXYZ);
409  void SetNthControlPointOrientationFromArray(int n, const double orientationWXYZ[4]);
411  void SetNthControlPointOrientation(int n, double w, double x, double y, double z);
413  void GetNthControlPointOrientation(int n, double orientationWXYZ[4]);
415  double* GetNthControlPointOrientationMatrix(int n);
417  void SetNthControlPointOrientationMatrix(int n, double orientationMatrix[9]);
421  void SetNthControlPointOrientationMatrixWorld(int n, double orientationMatrix[9]);
423  double* GetNthControlPointNormal(int n);
425  void GetNthControlPointNormalWorld(int n, double normalWorld[3]);
430  vtkVector4d GetNthControlPointOrientationVector(int pointIndex);
431 
433  std::string GetNthControlPointAssociatedNodeID(int n = 0);
434  void SetNthControlPointAssociatedNodeID(int n, std::string id);
435 
437  std::string GetNthMarkupAssociatedNodeID(int n = 0) { return this->GetNthControlPointAssociatedNodeID(n); }
439  void SetNthMarkupAssociatedNodeID(int n, std::string id) { this->SetNthControlPointAssociatedNodeID(n,id); }
440 
442  std::string GetNthControlPointID(int n);
443 
445  std::string GetNthMarkupID(int n = 0) { return this->GetNthControlPointID(n); }
446 
448  int GetNthControlPointIndexByID(const char* controlPointID);
450  ControlPoint* GetNthControlPointByID(const char* controlPointID);
451 
454  bool GetNthControlPointSelected(int n = 0);
457  void SetNthControlPointSelected(int n, bool flag);
458 
461  bool GetNthControlPointLocked(int n = 0);
468  void SetNthControlPointLocked(int n, bool flag);
469 
471  bool GetNthMarkupLocked(int n = 0) { return this->GetNthControlPointLocked(n); };
473  void SetNthMarkupLocked(int n, bool flag) { this->SetNthControlPointLocked(n, flag); }
474 
477  bool GetNthControlPointVisibility(int n = 0);
485  void SetNthControlPointVisibility(int n, bool flag);
486 
489  std::string GetNthControlPointLabel(int n = 0);
491  void SetNthControlPointLabel(int n, std::string label);
492 
494  std::string GetNthMarkupLabel(int n = 0) { return this->GetNthControlPointLabel(n); }
496  void SetNthMarkupLabel(int n, std::string label) { this->SetNthControlPointLabel(n, label); }
497 
500  std::string GetNthControlPointDescription(int n = 0);
502  void SetNthControlPointDescription(int n, std::string description);
503 
506  bool CanApplyNonLinearTransforms()const override;
509  void ApplyTransform(vtkAbstractTransform* transform) override;
510 
513  std::string GetMarkupLabelFormat();
523  void SetMarkupLabelFormat(std::string format);
524 
529  std::string ReplaceListNameInMarkupLabelFormat();
530 
538  bool GetModifiedSinceRead() override;
539 
543  bool ResetNthControlPointID(int n);
544 
548  vtkGetMacro(RequiredNumberOfControlPoints, int);
549 
558  vtkGetMacro(MaximumNumberOfControlPoints, int);
559 
560  // WXYZ: W rotation angle in degrees, XYZ is rotation axis.
561  static void ConvertOrientationMatrixToWXYZ(const double orientationMatrix[9], double orientationWXYZ[4]);
562  static void ConvertOrientationWXYZToMatrix(double orientationWXYZ[4], double orientationMatrix[9]);
563 
564  void GetControlPointLabels(vtkStringArray* labels);
565 
566  vtkPoints* GetCurvePoints();
567  vtkPoints* GetCurvePointsWorld();
568 
569  vtkPolyData* GetCurve();
570  vtkPolyData* GetCurveWorld();
571 
572  vtkAlgorithmOutput* GetCurveWorldConnection();
573 
574  vtkGetMacro(CurveClosed, bool);
575 
576  int GetControlPointIndexFromInterpolatedPointIndex(vtkIdType interpolatedPointIndex);
577 
581  vtkCurveGenerator* GetCurveGenerator() { return this->CurveGenerator.GetPointer(); };
582 
583  void GetRASBounds(double bounds[6]) override;
584  void GetBounds(double bounds[6]) override;
585 
587  int GetClosestControlPointIndexToPositionWorld(double pos[3]);
588 
594  void SetControlPointPositionsWorld(vtkPoints* points);
595 
597  void GetControlPointPositionsWorld(vtkPoints* points);
598 
600  virtual vtkMatrix4x4* GetInteractionHandleToWorldMatrix();
601 
602  virtual std::string GetPropertiesLabelText();
603 
605  vtkMRMLUnitNode* GetUnitNode(const char* quantity);
606 
609  virtual void UpdateAssignedAttribute() {};
610 
611 protected:
613  ~vtkMRMLMarkupsNode() override;
615  void operator=(const vtkMRMLMarkupsNode&);
616 
617  vtkSmartPointer<vtkStringArray> TextList;
618 
624  bool SetControlPointLabelsWorld(vtkStringArray* labels, vtkPoints* points, std::string separator = "");
625 
629  ControlPoint* GetNthControlPointCustomLog(int n, const char* failedMethodName);
630 
634  void SetNthControlPointID(int n, std::string id);
635 
639  std::string GenerateUniqueControlPointID();
640 
641  std::string GenerateControlPointLabel(int controlPointIndex);
642 
643  virtual void UpdateCurvePolyFromControlPoints();
644 
645  void OnTransformNodeReferenceChanged(vtkMRMLTransformNode* transformNode) override;
646 
648  void UpdateMeasurements();
649 
652  virtual void UpdateMeasurementsInternal();
653 
656  virtual void WriteMeasurementsToDescription();
657 
659  virtual void UpdateInteractionHandleToWorldMatrix();
660 
663  int RequiredNumberOfControlPoints{0};
666  int MaximumNumberOfControlPoints{0};
667 
668  bool CurveClosed{false};
669 
672 
674  vtkSmartPointer<vtkCurveGenerator> CurveGenerator;
675 
680  vtkSmartPointer<vtkFrenetSerretFrame> CurveCoordinateSystemGeneratorWorld;
681 
684  vtkSmartPointer<vtkPolyData> CurveInputPoly;
685 
686  vtkSmartPointer<vtkTransformPolyDataFilter> CurvePolyToWorldTransformer;
687  vtkSmartPointer<vtkGeneralTransform> CurvePolyToWorldTransform;
688 
691  vtkSmartPointer<vtkPointLocator> TransformedCurvePolyLocator;
692 
694  int Locked{0};
695 
696  std::string MarkupLabelFormat{"%N-%d"};
697 
701  int LastUsedControlPointNumber{0};
702 
705  vtkVector3d CenterPos;
706 
708  vtkCollection* Measurements;
709 
710  std::string PropertiesLabelText;
711 
713  vtkSmartPointer<vtkMatrix4x4> InteractionHandleToWorldMatrix;
714 
716  bool IsUpdatingPoints{false};
717 
718  friend class qSlicerMarkupsModuleWidget; // To directly access measurements
719 };
720 
721 #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])