Slicer  4.11
Slicer is a multi-platform, free and open source software package for visualization and medical image computing
vtkParametricPolynomialApproximation.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 
30 #ifndef vtkParametricPolynomialApproximation_h
31 #define vtkParametricPolynomialApproximation_h
32 
33 class vtkPoints;
34 class vtkDoubleArray;
35 class vtkTimeStamp;
36 
37 #include "vtkSlicerMarkupsModuleMRMLExport.h" // For export macro
38 
39 #include <vtkParametricFunction.h>
40 #include <vtkSmartPointer.h>
41 
42 class VTK_SLICER_MARKUPS_MODULE_MRML_EXPORT vtkParametricPolynomialApproximation : public vtkParametricFunction
43 {
44 public:
45  vtkTypeMacro(vtkParametricPolynomialApproximation, vtkParametricFunction);
46  void PrintSelf(ostream& os, vtkIndent indent) override;
47 
49 
53  int GetDimension() override { return 1; }
54 
59  void Evaluate(double u[3], double Pt[3], double Du[9]) override;
60 
65  double EvaluateScalar(double u[3], double Pt[3], double Du[9]) override;
66 
68 
71  vtkGetMacro(PolynomialOrder, int);
72  vtkSetMacro(PolynomialOrder, int);
74 
76 
80  void SetPoints(vtkPoints*);
82 
84 
88  void SetParameters(vtkDoubleArray*);
90 
92 
95  enum {
96  FIT_METHOD_GLOBAL_LEAST_SQUARES = 0, // global fit
98  FIT_METHOD_LAST // valid types go above this line
99  };
101 
103 
106  vtkGetMacro(FitMethod, int);
107  vtkSetMacro(FitMethod, int);
111 
113 
116  enum {
117  WEIGHT_FUNCTION_RECTANGULAR = 0, // All points within the sampling width (see above) are treated with equal importance
118  WEIGHT_FUNCTION_TRIANGULAR, // Points closer are treated as more important, falloff is linear
119  WEIGHT_FUNCTION_COSINE, // Points closer are treated as more important, falloff curve follows a smooth cosine
120  WEIGHT_FUNCTION_GAUSSIAN, // Points closer are treated as more important, falloff curve follows a smooth gaussian with 5% cutoff
121  WEIGHT_FUNCTION_LAST // valid types go above this line
122  };
124 
126 
129  vtkGetMacro(WeightFunction, int);
130  vtkSetMacro(WeightFunction, int);
136 
138 
145  vtkGetMacro(SampleWidth, double);
146  vtkSetMacro(SampleWidth, double);
148 
149 protected:
152 
153 private:
154  // What kind of fit (global/local)
155  int FitMethod;
156 
157  // These apply to all types of polynomials
158  int PolynomialOrder;
159  vtkSmartPointer< vtkDoubleArray > Parameters;
160  vtkSmartPointer< vtkPoints > Points;
161  double SamplePosition; // Internally store the sample position queried by the user
162 
163  // These apply only to moving least squares (for now)
164  vtkSmartPointer< vtkDoubleArray > Weights; // Internally compute and store weights
165  vtkSmartPointer< vtkDoubleArray > SortedParameters; // Internally computed, same values as Parameters but sorted
166  int WeightFunction;
167  double SampleWidth;
168  double SafeSampleWidth; // internally computed, ensures that moving least squares polynomials are always computed in parameters 0..1
169  vtkTimeStamp SafeHalfSampleWidthComputedTime;
170 
171  // This is directly used to evaluate points in 3D (in a sense this is the "output")
172  vtkSmartPointer< vtkDoubleArray > Coefficients;
173 
174  // Logic functions
175  void ComputeCoefficients();
176  bool ComputeCoefficientsNeeded();
177  void ComputeWeights();
178  void ComputeWeightsGlobalLeastSquares();
179  void ComputeWeightsMovingLeastSquares();
180  bool ComputeWeightsNeeded();
181  void ComputeSortedParameters();
182  bool ComputeSortedParametersNeeded();
183  void ComputeSafeSampleWidth();
184  bool ComputeSafeSampleWidthNeeded();
185  static void FitLeastSquaresPolynomials(vtkDoubleArray* parameters, vtkPoints* points,
186  vtkDoubleArray* weights, int polynomialOrder, vtkDoubleArray* coefficients);
187 
189  void operator=(const vtkParametricPolynomialApproximation&) = delete;
190 };
191 
192 #endif