1 /*=========================================================================
2 
3 Program:   Visualization Toolkit
4 Module:    vtkTessellatorFilter.h
5 Language:  C++
6 Date:      $Date$
7 Version:   $Revision$
8 
9 Copyright 2003 Sandia Corporation.
10 Under the terms of Contract DE-AC04-94AL85000, there is a non-exclusive
11 license for use of this work by or on behalf of the
12 U.S. Government. Redistribution and use in source and binary forms, with
13 or without modification, are permitted provided that this Notice and any
14 statement of authorship are reproduced on all copies.
15 
16 =========================================================================*/
17 #ifndef vtkTessellatorFilter_h
18 #define vtkTessellatorFilter_h
19 
20 // .NAME vtkTessellatorFilter - approximate nonlinear FEM elements with simplices
21 // .SECTION Description
22 // This class approximates nonlinear FEM elements with linear simplices.
23 //
24 // <b>Warning</b>: This class is temporary and will go away at some point
25 // after ParaView 1.4.0.
26 //
27 // This filter rifles through all the cells in an input vtkDataSet. It
28 // tesselates each cell and uses the vtkStreamingTessellator and
29 // vtkDataSetEdgeSubdivisionCriterion classes to generate simplices that
30 // approximate the nonlinear mesh using some approximation metric (encoded
31 // in the particular vtkDataSetEdgeSubdivisionCriterion::EvaluateEdge
32 // implementation). The simplices are placed into the filter's output
33 // vtkDataSet object by the callback routines AddATetrahedron,
34 // AddATriangle, and AddALine, which are registered with the triangulator.
35 //
36 // The output mesh will have geometry and any fields specified as
37 // attributes in the input mesh's point data.  The attribute's copy flags
38 // are honored, except for normals.
39 //
40 // .SECTION Internals
41 //
42 // The filter's main member function is RequestData(). This function first
43 // calls SetupOutput() which allocates arrays and some temporary variables
44 // for the primitive callbacks (OutputTriangle and OutputLine which are
45 // called by AddATriangle and AddALine, respectively).  Each cell is given
46 // an initial tesselation, which results in one or more calls to
47 // OutputTetrahedron, OutputTriangle or OutputLine to add elements to the
48 // OutputMesh. Finally, Teardown() is called to free the filter's working
49 // space.
50 //
51 // .SECTION See Also
52 // vtkDataSetToUnstructuredGridFilter vtkDataSet vtkStreamingTessellator
53 // vtkDataSetEdgeSubdivisionCriterion
54 
55 #include "vtkFiltersGeneralModule.h" // For export macro
56 #include "vtkUnstructuredGridAlgorithm.h"
57 
58 class vtkDataArray;
59 class vtkDataSet;
60 class vtkDataSetEdgeSubdivisionCriterion;
61 class vtkPointLocator;
62 class vtkPoints;
63 class vtkStreamingTessellator;
64 class vtkEdgeSubdivisionCriterion;
65 class vtkUnstructuredGrid;
66 
67 class VTKFILTERSGENERAL_EXPORT vtkTessellatorFilter : public vtkUnstructuredGridAlgorithm
68 {
69 public:
70   vtkTypeMacro(vtkTessellatorFilter,vtkUnstructuredGridAlgorithm);
71   void PrintSelf( ostream& os, vtkIndent indent );
72 
73   static vtkTessellatorFilter* New();
74 
75   virtual void SetTessellator( vtkStreamingTessellator* );
76   vtkGetObjectMacro(Tessellator, vtkStreamingTessellator);
77 
78   virtual void SetSubdivider( vtkDataSetEdgeSubdivisionCriterion* );
79   vtkGetObjectMacro(Subdivider, vtkDataSetEdgeSubdivisionCriterion);
80 
81   virtual unsigned long GetMTime();
82 
83   // Description:
84   // Set the dimension of the output tessellation.
85   // Cells in dimensions higher than the given value will have
86   // their boundaries of dimension \a OutputDimension tessellated.
87   // For example, if \a OutputDimension is 2, a hexahedron's
88   // quadrilateral faces would be tessellated rather than its
89   // interior.
90   vtkSetClampMacro(OutputDimension,int,1,3);
91   vtkGetMacro(OutputDimension,int);
92   //BTX
93   int GetOutputDimension() const;
94   //ETX
95 
96   // Description:
97   // These are convenience routines for setting properties maintained by the
98   // tessellator and subdivider. They are implemented here for ParaView's
99   // sake.
100   virtual void SetMaximumNumberOfSubdivisions( int num_subdiv_in );
101   int GetMaximumNumberOfSubdivisions();
102   virtual void SetChordError( double ce );
103   double GetChordError();
104 
105   // Description:
106   // These methods are for the ParaView client.
107   virtual void ResetFieldCriteria();
108   virtual void SetFieldCriterion( int field, double chord );
109 
110   // Description:
111   // The adaptive tessellation will output vertices that are not shared
112   // among cells, even where they should be. This can be corrected to
113   // some extents with a vtkMergeFilter.
114   // By default, the filter is off and vertices will not be shared.
115   vtkGetMacro(MergePoints,int);
116   vtkSetMacro(MergePoints,int);
117   vtkBooleanMacro(MergePoints,int);
118 
119 protected:
120   vtkTessellatorFilter();
121   ~vtkTessellatorFilter();
122 
123   virtual int FillInputPortInformation(int port, vtkInformation* info);
124 
125   // Description:
126   // Called by RequestData to set up a multitude of member variables used by
127   // the per-primitive output functions (OutputLine, OutputTriangle, and
128   // maybe one day... OutputTetrahedron).
129   void SetupOutput( vtkDataSet* input, vtkUnstructuredGrid* output );
130 
131   // Description:
132   // Called by RequestData to merge output points.
133   void MergeOutputPoints( vtkUnstructuredGrid* input, vtkUnstructuredGrid* output );
134 
135   // Description:
136   // Reset the temporary variables used during the filter's RequestData() method.
137   void Teardown();
138 
139   // Description:
140   // Run the filter; produce a polygonal approximation to the grid.
141   virtual int RequestData(vtkInformation* request,
142                           vtkInformationVector** inputVector,
143                           vtkInformationVector* outputVector);
144 
145   //BTX
146   vtkStreamingTessellator* Tessellator;
147   vtkDataSetEdgeSubdivisionCriterion* Subdivider;
148   int OutputDimension;
149   int MergePoints;
150   vtkPointLocator* Locator;
151 
152   // Description:
153   // These member variables are set by SetupOutput for use inside the
154   // callback members OutputLine and OutputTriangle.
155   vtkUnstructuredGrid* OutputMesh;
156   vtkPoints* OutputPoints;
157   vtkDataArray** OutputAttributes;
158   int* OutputAttributeIndices;
159 
160   static void AddAPoint( const double*,
161                          vtkEdgeSubdivisionCriterion*,
162                          void*,
163                          const void* );
164   static void AddALine( const double*,
165                         const double*,
166                         vtkEdgeSubdivisionCriterion*,
167                         void*,
168                         const void* );
169   static void AddATriangle( const double*,
170                             const double*,
171                             const double*,
172                             vtkEdgeSubdivisionCriterion*,
173                             void*,
174                             const void* );
175   static void AddATetrahedron( const double*,
176                                const double*,
177                                const double*,
178                                const double*,
179                                vtkEdgeSubdivisionCriterion*,
180                                void*,
181                                const void* );
182   void OutputPoint( const double* );
183   void OutputLine( const double*, const double* );
184   void OutputTriangle( const double*, const double*, const double* );
185   void OutputTetrahedron( const double*,
186                           const double*,
187                           const double*,
188                           const double* );
189   //ETX
190 
191 private:
192   vtkTessellatorFilter( const vtkTessellatorFilter& ); // Not implemented.
193   void operator = ( const vtkTessellatorFilter& ); // Not implemented.
194 };
195 
196 //BTX
GetOutputDimension()197 inline int vtkTessellatorFilter::GetOutputDimension() const
198 {
199   return this->OutputDimension;
200 }
201 //ETX
202 
203 #endif // vtkTessellatorFilter_h
204