1 /*=========================================================================
2 
3   Program:   Visualization Toolkit
4   Module:    vtkMarchingSquares.h
5 
6   Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
7   All rights reserved.
8   See Copyright.txt or http://www.kitware.com/Copyright.htm for details.
9 
10      This software is distributed WITHOUT ANY WARRANTY; without even
11      the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
12      PURPOSE.  See the above copyright notice for more information.
13 
14 =========================================================================*/
15 /**
16  * @class   vtkMarchingSquares
17  * @brief   generate isoline(s) from structured points set
18  *
19  * vtkMarchingSquares is a filter that takes as input a structured points set
20  * and generates on output one or more isolines.  One or more contour values
21  * must be specified to generate the isolines.  Alternatively, you can specify
22  * a min/max scalar range and the number of contours to generate a series of
23  * evenly spaced contour values.
24  *
25  * To generate contour lines the input data must be of topological dimension 2
26  * (i.e., an image). If not, you can use the ImageRange ivar to select an
27  * image plane from an input volume. This avoids having to extract a plane first
28  * (using vtkExtractSubVolume).  The filter deals with this by first
29  * trying to use the input data directly, and if not a 2D image, then uses the
30  * ImageRange ivar to reduce it to an image.
31  *
32  * @warning
33  * This filter is specialized to images. If you are interested in
34  * contouring other types of data, use the general vtkContourFilter.
35  * @sa
36  * vtkContourFilter vtkMarchingCubes vtkSliceCubes vtkDividingCubes
37 */
38 
39 #ifndef vtkMarchingSquares_h
40 #define vtkMarchingSquares_h
41 
42 #include "vtkFiltersCoreModule.h" // For export macro
43 #include "vtkPolyDataAlgorithm.h"
44 
45 #include "vtkContourValues.h" // Passes calls to vtkContourValues
46 
47 class vtkImageData;
48 class vtkIncrementalPointLocator;
49 
50 class VTKFILTERSCORE_EXPORT vtkMarchingSquares : public vtkPolyDataAlgorithm
51 {
52 public:
53   static vtkMarchingSquares *New();
54   vtkTypeMacro(vtkMarchingSquares,vtkPolyDataAlgorithm);
55   void PrintSelf(ostream& os, vtkIndent indent) override;
56 
57   //@{
58   /**
59    * Set/Get the i-j-k index range which define a plane on which to generate
60    * contour lines. Using this ivar it is possible to input a 3D volume
61    * directly and then generate contour lines on one of the i-j-k planes, or
62    * a portion of a plane.
63    */
64   vtkSetVectorMacro(ImageRange,int,6);
65   vtkGetVectorMacro(ImageRange,int,6);
66   void SetImageRange(int imin, int imax, int jmin, int jmax,
67                      int kmin, int kmax);
68   //@}
69 
70   //@{
71   /**
72    * Methods to set contour values
73    */
74   void SetValue(int i, double value);
75   double GetValue(int i);
76   double *GetValues();
77   void GetValues(double *contourValues);
78   void SetNumberOfContours(int number);
79   int GetNumberOfContours();
80   void GenerateValues(int numContours, double range[2]);
81   void GenerateValues(int numContours, double rangeStart, double rangeEnd);
82   //@}
83 
84   /**
85    * Because we delegate to vtkContourValues
86    */
87   vtkMTimeType GetMTime() override;
88 
89   void SetLocator(vtkIncrementalPointLocator *locator);
90   vtkGetObjectMacro(Locator,vtkIncrementalPointLocator);
91 
92   /**
93    * Create default locator. Used to create one when none is specified.
94    * The locator is used to merge coincident points.
95    */
96   void CreateDefaultLocator();
97 
98 protected:
99   vtkMarchingSquares();
100   ~vtkMarchingSquares() override;
101 
102   int RequestData(vtkInformation *, vtkInformationVector **, vtkInformationVector *) override;
103   int FillInputPortInformation(int port, vtkInformation *info) override;
104 
105   vtkContourValues *ContourValues;
106   int ImageRange[6];
107   vtkIncrementalPointLocator *Locator;
108 
109 private:
110   vtkMarchingSquares(const vtkMarchingSquares&) = delete;
111   void operator=(const vtkMarchingSquares&) = delete;
112 };
113 
114 /**
115  * Set a particular contour value at contour number i. The index i ranges
116  * between 0<=i<NumberOfContours.
117  */
SetValue(int i,double value)118 inline void vtkMarchingSquares::SetValue(int i, double value)
119 {this->ContourValues->SetValue(i,value);}
120 
121 /**
122  * Get the ith contour value.
123  */
GetValue(int i)124 inline double vtkMarchingSquares::GetValue(int i)
125 {return this->ContourValues->GetValue(i);}
126 
127 /**
128  * Get a pointer to an array of contour values. There will be
129  * GetNumberOfContours() values in the list.
130  */
GetValues()131 inline double *vtkMarchingSquares::GetValues()
132 {return this->ContourValues->GetValues();}
133 
134 /**
135  * Fill a supplied list with contour values. There will be
136  * GetNumberOfContours() values in the list. Make sure you allocate
137  * enough memory to hold the list.
138  */
GetValues(double * contourValues)139 inline void vtkMarchingSquares::GetValues(double *contourValues)
140 {this->ContourValues->GetValues(contourValues);}
141 
142 /**
143  * Set the number of contours to place into the list. You only really
144  * need to use this method to reduce list size. The method SetValue()
145  * will automatically increase list size as needed.
146  */
SetNumberOfContours(int number)147 inline void vtkMarchingSquares::SetNumberOfContours(int number)
148 {this->ContourValues->SetNumberOfContours(number);}
149 
150 /**
151  * Get the number of contours in the list of contour values.
152  */
GetNumberOfContours()153 inline int vtkMarchingSquares::GetNumberOfContours()
154 {return this->ContourValues->GetNumberOfContours();}
155 
156 /**
157  * Generate numContours equally spaced contour values between specified
158  * range. Contour values will include min/max range values.
159  */
GenerateValues(int numContours,double range[2])160 inline void vtkMarchingSquares::GenerateValues(int numContours, double range[2])
161 {this->ContourValues->GenerateValues(numContours, range);}
162 
163 /**
164  * Generate numContours equally spaced contour values between specified
165  * range. Contour values will include min/max range values.
166  */
GenerateValues(int numContours,double rangeStart,double rangeEnd)167 inline void vtkMarchingSquares::GenerateValues(int numContours, double
168                                              rangeStart, double rangeEnd)
169 {this->ContourValues->GenerateValues(numContours, rangeStart, rangeEnd);}
170 
171 #endif
172