Slicer  4.13
Slicer is a multi-platform, free and open source software package for visualization and medical image computing
vtkCurveGenerator.h
Go to the documentation of this file.
1 /*==============================================================================
2 
3  Program: 3D Slicer
4 
5  Copyright (c) Kitware Inc.
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  This file was originally developed by Thomas Vaughan, PerkLab, Queen's University.
17 
18 ==============================================================================*/
19 
20 #ifndef __vtkCurveGenerator_h
21 #define __vtkCurveGenerator_h
22 
23 // vtk includes
24 #include <vtkParametricFunction.h>
25 #include <vtkPointLocator.h>
26 #include <vtkPolyData.h>
27 #include <vtkPolyDataAlgorithm.h>
28 #include <vtkSetGet.h>
29 #include <vtkSmartPointer.h>
30 
32 class vtkDoubleArray;
33 class vtkPoints;
34 class vtkSpline;
35 
36 // export
37 #include "vtkSlicerMarkupsModuleMRMLExport.h"
38 
40 class VTK_SLICER_MARKUPS_MODULE_MRML_EXPORT vtkCurveGenerator : public vtkPolyDataAlgorithm
41 {
42 public:
43  vtkTypeMacro(vtkCurveGenerator, vtkPolyDataAlgorithm);
44  static vtkCurveGenerator* New();
45 
46  void PrintSelf(ostream& os, vtkIndent indent) override;
47 
50  vtkSetMacro(CurveIsClosed, bool);
51  vtkGetMacro(CurveIsClosed, bool);
52  vtkBooleanMacro(CurveIsClosed, bool);
53 
55  void SetCurveIsLoop(bool loop) { this->SetCurveIsClosed(loop); }
58  void CurveIsLoopOn() { this->SetCurveIsClosed(true); }
59  void CurveIsLoopOff() { this->SetCurveIsClosed(false); }
60  bool GetCurveIsLoop() { return this->GetCurveIsClosed(); }
62 
64  enum
65  {
66  CURVE_TYPE_LINEAR_SPLINE = 0, // Curve interpolates between input points with straight lines
67  CURVE_TYPE_CARDINAL_SPLINE, // Curve interpolates between input points smoothly
68  CURVE_TYPE_KOCHANEK_SPLINE, // Curve interpolates between input points smoothly, generalized
69  CURVE_TYPE_POLYNOMIAL, // Curve approximates the input points with a polynomial fit
70  CURVE_TYPE_SHORTEST_DISTANCE_ON_SURFACE, // Curve finds the closest path along a the edges of a surface mesh
71  CURVE_TYPE_LAST // Valid types go above this line
72  };
73  vtkGetMacro(CurveType, int);
74  vtkSetMacro(CurveType, int);
75  static const char* GetCurveTypeAsString(int id);
76  static int GetCurveTypeFromString(const char* name);
77  void SetCurveTypeToLinearSpline() { this->SetCurveType(CURVE_TYPE_LINEAR_SPLINE); }
78  void SetCurveTypeToCardinalSpline() { this->SetCurveType(CURVE_TYPE_CARDINAL_SPLINE); }
79  void SetCurveTypeToKochanekSpline() { this->SetCurveType(CURVE_TYPE_KOCHANEK_SPLINE); }
80  void SetCurveTypeToPolynomial() { this->SetCurveType(CURVE_TYPE_POLYNOMIAL); }
81  void SetCurveTypeToShortestDistanceOnSurface() { this->SetCurveType(CURVE_TYPE_SHORTEST_DISTANCE_ON_SURFACE); }
82 
83  virtual bool IsInterpolatingCurve();
84 
86  vtkSetMacro(NumberOfPointsPerInterpolatingSegment, int);
87  vtkGetMacro(NumberOfPointsPerInterpolatingSegment, int);
88 
90  vtkGetMacro(KochanekBias, double);
91  vtkSetMacro(KochanekBias, double);
92 
94  vtkGetMacro(KochanekContinuity, double);
95  vtkSetMacro(KochanekContinuity, double);
96 
98  vtkGetMacro(KochanekTension, double);
99  vtkSetMacro(KochanekTension, double);
100 
102  vtkGetMacro(KochanekEndsCopyNearestDerivatives, bool);
103  vtkSetMacro(KochanekEndsCopyNearestDerivatives, bool);
104 
106  vtkGetMacro(PolynomialOrder, int);
107  vtkSetMacro(PolynomialOrder, int);
108 
109  // Wednesday May 9, 2018 TODO
110  // InputParameters is currently computed by this class depending on the
111  // value of PolynomialPointSortingMethod, and is only supported for polynomials.
112  // In the future this could be expanded to support splines, and to allow
113  // the user to specify their own parameters (make a SetInputParameters function)
114  // e.g. through functions below
115  // Set the parameter values (e.g. point distances) that the curve should be based on
116  //virtual void SetInputParameters( vtkDoubleArray* );
117  //virtual vtkDoubleArray* GetInputParameters();
118 
120  enum
121  {
122  SORTING_METHOD_INDEX = 0,
124  SORTING_METHOD_LAST // valid types should be written above this line
125  };
126  vtkGetMacro(PolynomialPointSortingMethod, int);
127  vtkSetMacro(PolynomialPointSortingMethod, int);
128  static const char* GetPolynomialPointSortingMethodAsString(int id);
129  static int GetPolynomialPointSortingMethodFromString(const char* name);
130  void SetPolynomialPointSortingMethodToIndex() { this->SetPolynomialPointSortingMethod(vtkCurveGenerator::SORTING_METHOD_INDEX); }
132  {
133  this->SetPolynomialPointSortingMethod(vtkCurveGenerator::SORTING_METHOD_MINIMUM_SPANNING_TREE_POSITION);
134  }
135 
138  enum
139  {
140  POLYNOMIAL_FIT_METHOD_GLOBAL_LEAST_SQUARES = 0,
142  POLYNOMIAL_FIT_METHOD_LAST // Valid types go above this line
143  };
144  vtkGetMacro(PolynomialFitMethod, double);
145  vtkSetMacro(PolynomialFitMethod, double);
146  static const char* GetPolynomialFitMethodAsString(int id);
147  static int GetPolynomialFitMethodFromString(const char* name);
150 
152  vtkGetMacro(PolynomialSampleWidth, double);
153  vtkSetMacro(PolynomialSampleWidth, double);
154 
157  enum
158  {
159  POLYNOMIAL_WEIGHT_FUNCTION_RECTANGULAR = 0,
163  POLYNOMIAL_WEIGHT_FUNCTION_LAST // Valid types go above this line
164  };
165  vtkGetMacro(PolynomialWeightFunction, double);
166  vtkSetMacro(PolynomialWeightFunction, double);
167  static const char* GetPolynomialWeightFunctionAsString(int id);
168  static int GetPolynomialWeightFunctionFromString(const char* name);
173 
175  int GetSurfaceCostFunctionType();
176  void SetSurfaceCostFunctionType(int surfaceCostFunctionType);
177 
180  vtkIdType GetControlPointIdFromInterpolatedPointId(vtkIdType interpolatedPointId);
181 
183  vtkIdList* GetSurfacePointIds();
184 
186  double GetOutputCurveLength();
187 
189  vtkParametricFunction* GetParametricFunction() { return this->ParametricFunction.GetPointer(); };
190 
192  void SetInputPoints(vtkPoints* points);
193 
195  vtkPoints* GetOutputPoints();
196 
202  static void SortByIndex(vtkPoints* inputPoints, vtkDoubleArray* outputParameters);
203 
214  static void SortByMinimumSpanningTreePosition(vtkPoints* inputPoints, vtkDoubleArray* outputParameters);
215 
216 protected:
217  // input parameters
221  double KochanekBias;
230  std::vector<vtkIdType> InterpolatedPointIdsForControlPoints;
231 
232  // internal storage
233  vtkSmartPointer<vtkPointLocator> SurfacePointLocator;
234  vtkSmartPointer<vtkSlicerDijkstraGraphGeodesicPath> SurfacePathFilter;
235  vtkSmartPointer<vtkDoubleArray> InputParameters;
236  vtkSmartPointer<vtkParametricFunction> ParametricFunction;
237 
238  // output
240 
241  // logic
242  void SetParametricFunctionToSpline(vtkPoints* inputPoints, vtkSpline* xSpline, vtkSpline* ySpline, vtkSpline* zSpline);
243  void SetParametricFunctionToLinearSpline(vtkPoints* inputPoints);
244  void SetParametricFunctionToCardinalSpline(vtkPoints* inputPoints);
245  void SetParametricFunctionToKochanekSpline(vtkPoints* inputPoints);
246  void SetParametricFunctionToPolynomial(vtkPoints* inputPoints);
247  int GeneratePoints(vtkPoints* inputPoints, vtkPolyData* inputSurface, vtkPolyData* outputPolyData);
248  int GeneratePointsFromFunction(vtkPoints* inputPoints, vtkPoints* outputPoints, vtkDoubleArray* outputPedigreeIdArray);
249  int GeneratePointsFromSurface(vtkPoints* inputPoints, vtkPolyData* inputSurface, vtkPoints* outputPoints, vtkDoubleArray* outputPedigreeIdArray);
250  int GenerateLines(vtkPolyData* polyData);
251 
252  int FillInputPortInformation(int port, vtkInformation* info) override;
253  int RequestData(vtkInformation* request, vtkInformationVector** inputVector, vtkInformationVector* outputVector) override;
254 
255 protected:
257  ~vtkCurveGenerator() override;
258  vtkCurveGenerator(const vtkCurveGenerator&) = delete;
259  void operator=(const vtkCurveGenerator&) = delete;
260 };
261 
262 #endif
void SetPolynomialWeightFunctionToCosine()
Filter that generates curves between points of an input polydata.
Filter that generates curves between points of an input polydata.
void SetPolynomialWeightFunctionToGaussian()
void SetCurveTypeToShortestDistanceOnSurface()
int NumberOfPointsPerInterpolatingSegment
void SetPolynomialPointSortingMethodToIndex()
std::vector< vtkIdType > InterpolatedPointIdsForControlPoints
vtkSmartPointer< vtkPointLocator > SurfacePointLocator
void SetPolynomialFitMethodToMovingLeastSquares()
void SetPolynomialWeightFunctionToTriangular()
void SetPolynomialFitMethodToGlobalLeastSquares()
vtkSmartPointer< vtkDoubleArray > InputParameters
bool KochanekEndsCopyNearestDerivatives
void SetCurveTypeToKochanekSpline()
vtkSmartPointer< vtkParametricFunction > ParametricFunction
void SetPolynomialPointSortingMethodToMinimumSpanningTreePosition()
void SetPolynomialWeightFunctionToRectangular()
void SetCurveTypeToCardinalSpline()
vtkParametricFunction * GetParametricFunction()
The internal instance of the current parametric function use of the curve for other computations...
void SetCurveTypeToLinearSpline()
vtkSmartPointer< vtkSlicerDijkstraGraphGeodesicPath > SurfacePathFilter