Slicer  5.1
Slicer is a multi-platform, free and open source software package for visualization and medical image computing
vtkMRMLMarkupsCurveNode.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 __vtkMRMLMarkupsCurveNode_h
19 #define __vtkMRMLMarkupsCurveNode_h
20 
21 // MRML includes
22 #include "vtkMRMLDisplayableNode.h"
23 #include "vtkMRMLModelNode.h"
24 
25 // Markups includes
26 #include "vtkSlicerMarkupsModuleMRMLExport.h"
28 #include "vtkMRMLMarkupsNode.h"
29 
30 // VTK includes
31 #include <vtkStringArray.h>
32 
33 // std includes
34 #include <vector>
35 
36 class vtkArrayCalculator;
37 class vtkAssignAttribute;
38 class vtkCallbackCommand;
39 class vtkCleanPolyData;
41 class vtkPassThroughFilter;
42 class vtkPlane;
44 class vtkTransformPolyDataFilter;
45 class vtkTriangleFilter;
46 
89 class VTK_SLICER_MARKUPS_MODULE_MRML_EXPORT vtkMRMLMarkupsCurveNode : public vtkMRMLMarkupsNode
90 {
91 public:
92  static vtkMRMLMarkupsCurveNode *New();
95  void PrintSelf(ostream& os, vtkIndent indent) override;
96 
97  const char* GetIcon() override {return ":/Icons/MarkupsOpenCurve.png";}
98  const char* GetAddIcon() override {return ":/Icons/MarkupsCurveMouseModePlace.png";}
99  const char* GetPlaceAddIcon() override {return ":/Icons/MarkupsCurveMouseModePlaceAdd.png";}
100 
101  //--------------------------------------------------------------------------
102  // MRMLNode methods
103  //--------------------------------------------------------------------------
104 
105  vtkMRMLNode* CreateNodeInstance() override;
107  const char* GetNodeTagName() override {return "MarkupsCurve";}
108 
110  const char* GetMarkupType() override {return "Curve";};
111 
112  // Get markup type GUI display name
113  const char* GetTypeDisplayName() override {return "Curve";};
114 
116  const char* GetDefaultNodeNamePrefix() override {return "OC";};
117 
119  void ReadXMLAttributes( const char** atts) override;
120 
122  void WriteXML(ostream& of, int indent) override;
123 
127 
130  vtkPoints* GetCurvePointsWorld() override;
131  vtkPolyData* GetCurveWorld() override;
132  vtkAlgorithmOutput* GetCurveWorldConnection() override;
134 
140  double GetCurveLengthWorld(vtkIdType startCurvePointIndex=0, vtkIdType numberOfCurvePoints=-1);
141 
144  static double GetCurveLength(vtkPoints* curvePoints, bool closedCurve, vtkIdType startCurvePointIndex=0, vtkIdType numberOfCurvePoints=-1);
145 
151  double GetCurveLengthBetweenStartEndPointsWorld(vtkIdType startCurvePointIndex, vtkIdType endCurvePointIndex);
152 
154  bool SetControlPointLabels(vtkStringArray* labels, vtkPoints* points);
155 
163  static bool ConstrainPointsToSurface(vtkPoints* originalPoints, vtkPoints* normalVectors, vtkPolyData* surfacePolydata,
164  vtkPoints* surfacePoints, double maximumSearchRadius=.25);
165 
167  void ResampleCurveWorld(double controlPointDistance);
168 
170  // If pedigreeIdsArray is specified then the method returns the fractional point index of the original point for each new point.
171  // Fractional point index is a value between the point indices of the two original points it was between, the fractional part
172  // specifies the distance from those two points. It can be used for interpolating point data.
173  static bool ResamplePoints(vtkPoints* originalPoints, vtkPoints* interpolatedPoints,
174  double samplingDistance, bool closedCurve, vtkDoubleArray* pedigreeIdsArray=nullptr);
175 
177  static bool ResampleStaticControlPointMeasurements(vtkCollection* measurements, vtkDoubleArray* curvePointsPedigreeIdsArray, int curvePointsPerControlPoint);
178 
181  bool GetSampledCurvePointsBetweenStartEndPointsWorld(vtkPoints* sampledPoints,
182  double samplingDistance, vtkIdType startCurvePointIndex, vtkIdType endCurvePointIndex);
183 
185  vtkIdType GetClosestCurvePointIndexToPositionWorld(const double posWorld[3]);
186 
192  vtkIdType GetClosestPointPositionAlongCurveWorld(const double posWorld[3], double closestPosWorld[3]);
193 
198  vtkIdType GetFarthestCurvePointIndexToPositionWorld(const double posWorld[3]);
199 
202  vtkIdType GetCurvePointIndexFromControlPointIndex(int controlPointIndex);
203 
205  static bool GetPositionAndClosestPointIndexAlongCurve(double foundCurvePosition[3], vtkIdType& foundClosestPointIndex,
206  vtkIdType startCurvePointId, double distanceFromStartPoint, vtkPoints* curvePoints, bool closedCurve);
207 
212  vtkIdType GetCurvePointIndexAlongCurveWorld(vtkIdType startCurvePointId, double distanceFromStartPoint);
213 
219  bool GetPositionAlongCurveWorld(double foundCurvePosition[3], vtkIdType startCurvePointId, double distanceFromStartPoint);
220 
223  bool GetCurveDirectionAtPointIndexWorld(vtkIdType curvePointIndex, double directionVectorWorld[3]);
224 
232  bool GetCurvePointToWorldTransformAtPointIndex(vtkIdType curvePointIndex, vtkMatrix4x4* curvePointToWorld);
233 
234  bool GetPointsOnPlaneWorld(vtkPlane* plane, vtkPoints* intersectionPoints);
235 
237  int GetCurveType();
238  void SetCurveType(int type);
239  const char* GetCurveTypeAsString(int id);
240  int GetCurveTypeFromString(const char* name);
241  void SetCurveTypeToLinear();
242  void SetCurveTypeToCardinalSpline();
243  void SetCurveTypeToKochanekSpline();
244  void SetCurveTypeToPolynomial();
245  void SetCurveTypeToShortestDistanceOnSurface(vtkMRMLModelNode* modelNode=nullptr);
246 
249  const char* GetShortestDistanceSurfaceNodeReferenceRole() { return this->GetSurfaceConstraintNodeReferenceRole(); }
252  const char* GetShortestDistanceSurfaceNodeReferenceMRMLAttributeName() { return this->GetSurfaceConstraintNodeReferenceMRMLAttributeName(); }
253 
255  const char* GetSurfaceConstraintNodeReferenceRole() { return "shortestDistanceSurface"; }
256  const char* GetSurfaceConstraintNodeReferenceMRMLAttributeName() { return "shortestDistanceSurfaceRef"; };
257 
262  void SetAndObserveShortestDistanceSurfaceNode(vtkMRMLModelNode* modelNode) { this->SetAndObserveSurfaceConstraintNode(modelNode); }
265  vtkMRMLModelNode* GetShortestDistanceSurfaceNode() { return this->GetSurfaceConstraintNode(); }
266 
269  void SetAndObserveSurfaceConstraintNode(vtkMRMLModelNode* modelNode);
270  vtkMRMLModelNode* GetSurfaceConstraintNode();
272 
278  void SetSurfaceConstraintMaximumSearchRadiusTolerance(double tolerance);
279  double GetSurfaceConstraintMaximumSearchRadiusTolerance() const;
281 
284  int GetSurfaceCostFunctionType();
285  void SetSurfaceCostFunctionType(int surfaceCostFunctionType);
286  static const char* GetSurfaceCostFunctionTypeAsString(int surfaceCostFunctionType);
287  static int GetSurfaceCostFunctionTypeFromString(const char* name);
288 
291  const char* GetSurfaceDistanceWeightingFunction();
292  void SetSurfaceDistanceWeightingFunction(const char* function);
293 
295  int GetNumberOfPointsPerInterpolatingSegment();
298  void SetNumberOfPointsPerInterpolatingSegment(int pointsPerSegment);
300 
302  virtual void UpdateAssignedAttribute() override;
303 
304 protected:
305  vtkSmartPointer<vtkCleanPolyData> CleanFilter;
306  vtkSmartPointer<vtkTriangleFilter> TriangleFilter;
307  vtkSmartPointer<vtkTransformPolyDataFilter> SurfaceToLocalTransformer;
308  vtkSmartPointer<vtkArrayCalculator> SurfaceScalarCalculator;
309  vtkSmartPointer<vtkPassThroughFilter> SurfaceScalarPassThroughFilter;
310  vtkSmartPointer<vtkCurveMeasurementsCalculator> CurveMeasurementsCalculator;
311  vtkSmartPointer<vtkPassThroughFilter> WorldOutput;
313 
317  vtkSmartPointer<vtkAssignAttribute> ScalarDisplayAssignAttribute;
318 
321 
322 protected:
323  void ProcessMRMLEvents(vtkObject* caller, unsigned long event, void* callData) override;
324  void OnNodeReferenceAdded(vtkMRMLNodeReference* reference) override;
325  void OnNodeReferenceModified(vtkMRMLNodeReference* reference) override;
326  void OnNodeReferenceRemoved(vtkMRMLNodeReference* reference) override;
327 
328  virtual void UpdateSurfaceScalarVariables();
329  virtual void OnSurfaceModelNodeChanged();
330  virtual void OnSurfaceModelTransformChanged();
331 
333  ~vtkMRMLMarkupsCurveNode() override;
335  void operator=(const vtkMRMLMarkupsCurveNode&);
336 
337  void UpdateMeasurementsInternal() override;
338 
340  static void OnCurvatureMeasurementModified(vtkObject* caller, unsigned long eid, void* clientData, void* callData);
341 
342 private:
343  vtkSmartPointer<vtkProjectMarkupsCurvePointsFilter> ProjectPointsFilter;
344 };
345 
346 #endif
MRML node to represent a curve markup Curve Markups nodes contain N control points. Visualization parameters are set in the vtkMRMLMarkupsDisplayNode class.
void OnNodeReferenceRemoved(vtkMRMLNodeReference *reference) override
Called after a node reference ID is removed (list size decreased).
vtkSmartPointer< vtkPassThroughFilter > SurfaceScalarPassThroughFilter
Projects curve points from a vtkMRMLMarkupsCurveNode to the surface of a model.
const char * GetMarkupType() override
Get markup type internal name.
MRML node to represent a 3D surface model.
virtual vtkPoints * GetCurvePointsWorld()
void operator=(const vtkMRMLMarkupsNode &)
const char * GetShortestDistanceSurfaceNodeReferenceMRMLAttributeName()
vtkSmartPointer< vtkArrayCalculator > SurfaceScalarCalculator
Filter that generates curves between points of an input polydata.
vtkSmartPointer< vtkCleanPolyData > CleanFilter
void OnNodeReferenceAdded(vtkMRMLNodeReference *reference) override
Called when a node reference ID is added (list size increased).
const char * GetPlaceAddIcon() override
virtual vtkAlgorithmOutput * GetCurveWorldConnection()
const char * GetNodeTagName() override
Get node XML tag name (like Volume, Model)
virtual vtkPolyData * GetCurveWorld()
const char * GetDefaultNodeNamePrefix() override
Get markup short name.
vtkSmartPointer< vtkTriangleFilter > TriangleFilter
vtkSmartPointer< vtkAssignAttribute > ScalarDisplayAssignAttribute
const char * GetIcon() override
virtual void UpdateMeasurementsInternal()
const char * GetTypeDisplayName() override
void SetAndObserveShortestDistanceSurfaceNode(vtkMRMLModelNode *modelNode)
vtkMRMLCopyContentMacro(vtkMRMLMarkupsNode)
vtkMRMLModelNode * GetShortestDistanceSurfaceNode()
vtkSmartPointer< vtkTransformPolyDataFilter > SurfaceToLocalTransformer
const char * GetSurfaceConstraintNodeReferenceMRMLAttributeName()
vtkMRMLNode * CreateNodeInstance() override=0
MRMLNode methods.
const char * ShortestDistanceSurfaceActiveScalar
vtkCallbackCommand * CurvatureMeasurementModifiedCallbackCommand
Command handling curvature measurement modified events to propagate enabled state.
void ReadXMLAttributes(const char **atts) override
Read node attributes from XML file.
const char * GetSurfaceConstraintNodeReferenceRole()
Node reference role for the surface that is used to project the curve onto.
const char * GetShortestDistanceSurfaceNodeReferenceRole()
Abstract Superclass for all specific types of MRML nodes.
Definition: vtkMRMLNode.h:167
Class to hold information about a node reference.
Definition: vtkMRMLNode.h:801
vtkSmartPointer< vtkPassThroughFilter > WorldOutput
void OnNodeReferenceModified(vtkMRMLNodeReference *reference) override
Called when a node reference ID is modified.
virtual void UpdateAssignedAttribute()
const char * GetAddIcon() override
vtkSmartPointer< vtkCurveMeasurementsCalculator > CurveMeasurementsCalculator
void WriteXML(ostream &of, int indent) override
Write this node&#39;s information to a MRML file in XML format.
void ProcessMRMLEvents(vtkObject *, unsigned long, void *) override
Alternative method to propagate events generated in Display nodes.
void PrintSelf(ostream &os, vtkIndent indent) override