vtkDataSetSurfaceFilter.h 9.6 KB
Newer Older
1 2 3 4 5
/*=========================================================================

  Program:   Visualization Toolkit
  Module:    vtkDataSetSurfaceFilter.h

6
  Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
7 8
  All rights reserved.
  See Copyright.txt or http://www.kitware.com/Copyright.htm for details.
9

10 11
     This software is distributed WITHOUT ANY WARRANTY; without even
     the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
12
     PURPOSE.  See the above copyright notice for more information.
13 14

=========================================================================*/
15 16 17 18 19 20 21 22 23 24 25 26
/**
 * @class   vtkDataSetSurfaceFilter
 * @brief   Extracts outer (polygonal) surface.
 *
 * vtkDataSetSurfaceFilter is a faster version of vtkGeometry filter, but it
 * does not have an option to select bounds.  It may use more memory than
 * vtkGeometryFilter.  It only has one option: whether to use triangle strips
 * when the input type is structured.
 *
 * @sa
 * vtkGeometryFilter vtkStructuredGridGeometryFilter.
*/
27

28 29
#ifndef vtkDataSetSurfaceFilter_h
#define vtkDataSetSurfaceFilter_h
30

31
#include "vtkFiltersGeometryModule.h" // For export macro
32
#include "vtkPolyDataAlgorithm.h"
33

34 35
class vtkPointData;
class vtkPoints;
36
class vtkIdTypeArray;
37
class vtkStructuredGrid;
38

39 40 41 42 43 44
// Helper structure for hashing faces.
struct vtkFastGeomQuadStruct
{
  struct vtkFastGeomQuadStruct *Next;
  vtkIdType SourceId;
  int numPts;
45
  vtkIdType* ptArray;
46
};
47
typedef struct vtkFastGeomQuadStruct vtkFastGeomQuad;
48

49
class VTKFILTERSGEOMETRY_EXPORT vtkDataSetSurfaceFilter : public vtkPolyDataAlgorithm
50 51 52
{
public:
  static vtkDataSetSurfaceFilter *New();
53
  vtkTypeMacro(vtkDataSetSurfaceFilter,vtkPolyDataAlgorithm);
54
  void PrintSelf(ostream& os, vtkIndent indent) override;
55

56 57 58 59 60 61
  //@{
  /**
   * When input is structured data, this flag will generate faces with
   * triangle strips.  This should render faster and use less memory, but no
   * cell data is copied.  By default, UseStrips is Off.
   */
62 63 64
  vtkSetMacro(UseStrips, vtkTypeBool);
  vtkGetMacro(UseStrips, vtkTypeBool);
  vtkBooleanMacro(UseStrips, vtkTypeBool);
65 66 67 68 69 70 71 72
  //@}

  //@{
  /**
   * If PieceInvariant is true, vtkDataSetSurfaceFilter requests
   * 1 ghost level from input in order to remove internal surface
   * that are between processes. False by default.
   */
73 74
  vtkSetMacro(PieceInvariant, int);
  vtkGetMacro(PieceInvariant, int);
75 76 77 78 79 80 81 82 83 84 85
  //@}

  //@{
  /**
   * If on, the output polygonal dataset will have a celldata array that
   * holds the cell index of the original 3D cell that produced each output
   * cell. This is useful for cell picking. The default is off to conserve
   * memory. Note that PassThroughCellIds will be ignored if UseStrips is on,
   * since in that case each tringle strip can represent more than on of the
   * input cells.
   */
86 87 88 89 90 91
  vtkSetMacro(PassThroughCellIds,vtkTypeBool);
  vtkGetMacro(PassThroughCellIds,vtkTypeBool);
  vtkBooleanMacro(PassThroughCellIds,vtkTypeBool);
  vtkSetMacro(PassThroughPointIds,vtkTypeBool);
  vtkGetMacro(PassThroughPointIds,vtkTypeBool);
  vtkBooleanMacro(PassThroughPointIds,vtkTypeBool);
92 93 94 95 96 97
  //@}

  //@{
  /**
   * If PassThroughCellIds or PassThroughPointIds is on, then these ivars
   * control the name given to the field in which the ids are written into.  If
98
   * set to nullptr, then vtkOriginalCellIds or vtkOriginalPointIds (the default)
99 100
   * is used, respectively.
   */
101
  vtkSetStringMacro(OriginalCellIdsName);
102 103
  virtual const char *GetOriginalCellIdsName()
  {
104
    return (  this->OriginalCellIdsName
105
              ? this->OriginalCellIdsName : "vtkOriginalCellIds");
106 107
  }
  vtkSetStringMacro(OriginalPointIdsName);
108 109
  virtual const char *GetOriginalPointIdsName()
  {
110 111 112
    return (  this->OriginalPointIdsName
            ? this->OriginalPointIdsName : "vtkOriginalPointIds");
  }
113 114 115 116 117 118
  //@}

  //@{
  /**
   * If the input is an unstructured grid with nonlinear faces, this parameter
   * determines how many times the face is subdivided into linear faces.  If 0,
luz.paz's avatar
luz.paz committed
119
   * the output is the equivalent of its linear counterpart (and the midpoints
120 121 122 123 124 125 126
   * determining the nonlinear interpolation are discarded).  If 1 (the
   * default), the nonlinear face is triangulated based on the midpoints.  If
   * greater than 1, the triangulated pieces are recursively subdivided to reach
   * the desired subdivision.  Setting the value to greater than 1 may cause
   * some point data to not be passed even if no nonlinear faces exist.  This
   * option has no effect if the input is not an unstructured grid.
   */
127 128
  vtkSetMacro(NonlinearSubdivisionLevel, int);
  vtkGetMacro(NonlinearSubdivisionLevel, int);
129
  //@}
130

131 132 133 134 135
  //@{
  /**
   * Direct access methods that can be used to use the this class as an
   * algorithm without using it as a filter.
   */
136 137
  virtual int StructuredExecute(vtkDataSet *input,
    vtkPolyData *output, vtkIdType *ext, vtkIdType *wholeExt);
138
#ifdef VTK_USE_64BIT_IDS
139 140
  virtual int StructuredExecute(vtkDataSet *input,
    vtkPolyData *output, int *ext32, int *wholeExt32)
141
  {
142 143
    vtkIdType ext[6]; vtkIdType wholeExt[6];
    for (int cc=0; cc < 6; cc++)
144
    {
145 146 147
      ext[cc] = ext32[cc];
      wholeExt[cc] = wholeExt32[cc];
    }
148 149
    return this->StructuredExecute(input, output, ext, wholeExt);
  }
150
#endif
151
  virtual int UnstructuredGridExecute(vtkDataSet *input,
152
                                      vtkPolyData *output);
153
  virtual int DataSetExecute(vtkDataSet *input, vtkPolyData *output);
154
  virtual int StructuredWithBlankingExecute(vtkStructuredGrid *input, vtkPolyData *output);
155 156
  virtual int UniformGridExecute(
      vtkDataSet *input, vtkPolyData *output,
157
      vtkIdType *ext, vtkIdType *wholeExt, bool extractface[6] );
158 159
#ifdef VTK_USE_64BIT_IDS
  virtual int UniformGridExecute(vtkDataSet *input,
160
    vtkPolyData *output, int *ext32, int *wholeExt32, bool extractface[6] )
161
  {
162 163
    vtkIdType ext[6]; vtkIdType wholeExt[6];
    for (int cc=0; cc < 6; cc++)
164
    {
165 166 167
      ext[cc] = ext32[cc];
      wholeExt[cc] = wholeExt32[cc];
    }
168 169
    return this->UniformGridExecute(input, output, ext, wholeExt, extractface);
  }
170
#endif
171
  //@}
172

173 174
protected:
  vtkDataSetSurfaceFilter();
175
  ~vtkDataSetSurfaceFilter() override;
176

177
  vtkTypeBool UseStrips;
178

179
  int RequestUpdateExtent(vtkInformation *, vtkInformationVector **, vtkInformationVector *) override;
180

181 182
  int RequestData(vtkInformation *, vtkInformationVector **, vtkInformationVector *) override;
  int FillInputPortInformation(int port, vtkInformation *info) override;
183

184 185

  // Helper methods.
186

187 188 189 190 191 192 193
  /**
   * Estimates the total number of points & cells on the surface to render
   * ext -- the extent of the structured data in question (in)
   * wholeExt -- the global extent of the structured data (in)
   * numPoints -- the estimated number of points (out)
   * numCells -- the estimated number of cells (out)
   */
194 195 196 197
  void EstimateStructuredDataArraySizes(
      vtkIdType *ext, vtkIdType *wholeExt,
      vtkIdType &numPoints, vtkIdType &numCells );

198
  void ExecuteFaceStrips(vtkDataSet *input, vtkPolyData *output,
199
                         int maxFlag, vtkIdType *ext,
200
                         int aAxis, int bAxis, int cAxis,
201
                         vtkIdType *wholeExt);
202 203 204 205 206

  void ExecuteFaceQuads(vtkDataSet *input, vtkPolyData *output,
      int maxFlag, vtkIdType *ext, int aAxis, int bAxis, int cAxis,
      vtkIdType *wholeExt, bool checkVisibility );

207
  void ExecuteFaceQuads(vtkDataSet *input, vtkPolyData *output,
208
                        int maxFlag, vtkIdType *ext,
209
                        int aAxis, int bAxis, int cAxis,
210
                        vtkIdType *wholeExt);
211

Amy Squillacote's avatar
Amy Squillacote committed
212
  void InitializeQuadHash(vtkIdType numPoints);
213
  void DeleteQuadHash();
214
  virtual void InsertQuadInHash(vtkIdType a, vtkIdType b, vtkIdType c, vtkIdType d,
Amy Squillacote's avatar
Amy Squillacote committed
215
                        vtkIdType sourceId);
216
  virtual void InsertTriInHash(vtkIdType a, vtkIdType b, vtkIdType c,
217
                       vtkIdType sourceId, vtkIdType faceId = -1);
218
  virtual void InsertPolygonInHash(vtkIdType* ids, int numpts,
219
                           vtkIdType sourceId);
220 221 222 223
  void InitQuadHashTraversal();
  vtkFastGeomQuad *GetNextVisibleQuadFromHash();

  vtkFastGeomQuad **QuadHash;
Amy Squillacote's avatar
Amy Squillacote committed
224
  vtkIdType QuadHashLength;
225
  vtkFastGeomQuad *QuadHashTraversal;
Amy Squillacote's avatar
Amy Squillacote committed
226
  vtkIdType QuadHashTraversalIndex;
227

Amy Squillacote's avatar
Amy Squillacote committed
228
  vtkIdType *PointMap;
229
  vtkIdType GetOutputPointId(vtkIdType inPtId, vtkDataSet *input,
Amy Squillacote's avatar
Amy Squillacote committed
230
                             vtkPoints *outPts, vtkPointData *outPD);
231

232
  class vtkEdgeInterpolationMap;
233

234 235 236 237 238
  vtkEdgeInterpolationMap *EdgeMap;
  vtkIdType GetInterpolatedPointId(vtkIdType edgePtA, vtkIdType edgePtB,
                                   vtkDataSet *input, vtkCell *cell,
                                   double pcoords[3], vtkPoints *outPts,
                                   vtkPointData *outPD);
239

240
  vtkIdType NumberOfNewCells;
241

242
  // Better memory allocation for faces (hash)
243
  void InitFastGeomQuadAllocation(vtkIdType numberOfCells);
Clinton Stimpson's avatar
Clinton Stimpson committed
244
  vtkFastGeomQuad* NewFastGeomQuad(int numPts);
245 246
  void DeleteAllFastGeomQuads();
  // -----
247 248
  vtkIdType FastGeomQuadArrayLength;
  vtkIdType NumberOfFastGeomQuadArrays;
249
  unsigned char** FastGeomQuadArrays;  // store this data as an array of bytes
250
  // These indexes allow us to find the next available face.
251 252
  vtkIdType NextArrayIndex;
  vtkIdType NextQuadIndex;
253

254 255
  int PieceInvariant;

256
  vtkTypeBool PassThroughCellIds;
257
  void RecordOrigCellId(vtkIdType newIndex, vtkIdType origId);
258
  virtual void RecordOrigCellId(vtkIdType newIndex, vtkFastGeomQuad *quad);
259
  vtkIdTypeArray *OriginalCellIds;
260
  char *OriginalCellIdsName;
261

262
  vtkTypeBool PassThroughPointIds;
263 264
  void RecordOrigPointId(vtkIdType newIndex, vtkIdType origId);
  vtkIdTypeArray *OriginalPointIds;
265 266 267
  char *OriginalPointIdsName;

  int NonlinearSubdivisionLevel;
268

269
private:
270 271
  vtkDataSetSurfaceFilter(const vtkDataSetSurfaceFilter&) = delete;
  void operator=(const vtkDataSetSurfaceFilter&) = delete;
272 273 274
};

#endif