Salome HOME
Fix for the "0020314: EDF 993 SMESH : Display bug with Volumes created by GHS3D"...
[modules/visu.git] / src / CONVERTOR / VISU_MergeFilterUtilities.hxx
1 // Copyright (C) 2007-2011  CEA/DEN, EDF R&D, OPEN CASCADE
2 //
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either
6 // version 2.1 of the License.
7 //
8 // This library is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
11 // Lesser General Public License for more details.
12 //
13 // You should have received a copy of the GNU Lesser General Public
14 // License along with this library; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
16 //
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
18 //
19
20 //  SALOME VTKViewer : build VTK viewer into Salome desktop
21 //  File   : 
22 //  Author : 
23 //  Module : SALOME
24 //  $Header$
25 //
26 #ifndef VISU_MergeFilterUtilities_H
27 #define VISU_MergeFilterUtilities_H
28
29 #include <string>
30 #include <vtkDataSet.h>
31
32 class vtkDataSet;
33 class vtkPolyData;
34 class vtkUnstructuredGrid;
35 class vtkIntArray;
36
37 using namespace std;
38 #include <set>
39 #include <vector>
40 #include <map>
41
42 namespace VISU
43 {
44   class TFieldList;
45
46   typedef int TCellId;
47   typedef int TEntityId;
48   typedef std::pair<TCellId, TEntityId> TObjectId;
49
50   typedef std::set<TObjectId> TObjectIdSet;
51   typedef std::vector<TObjectId> TObjectIdArray;
52
53   typedef int TTupleId;
54   typedef std::map<TObjectId, TTupleId> TObjectId2TupleIdMap;
55
56   typedef int TTupleCellID;
57   typedef int GeometryCellID;
58   typedef std::vector<TTupleCellID> TCellIdArray;
59   typedef std::map<GeometryCellID, TCellIdArray> TObjectId2TupleGaussIdMap;
60   
61   //---------------------------------------------------------------
62   typedef vtkFieldData* (vtkDataSet::* TGetFieldData)();
63
64   //---------------------------------------------------------------
65   struct TGetCellData
66   {
67     vtkFieldData*
68     operator()(vtkDataSet* theDataSet)
69     {
70       return (vtkFieldData*)(theDataSet->GetCellData());
71     }
72   };
73
74
75   //---------------------------------------------------------------
76   struct TGetPointData
77   {
78     vtkFieldData*
79     operator()(vtkDataSet* theDataSet)
80     {
81       return (vtkFieldData*)(theDataSet->GetPointData());
82     }
83   };
84
85   void
86   GetObjectId2TupleIdMap(vtkIntArray *theArray, 
87                          TObjectId2TupleIdMap& theObjectId2TupleIdMap);
88
89   void
90   GetObjectId2TupleGaussIdArray(vtkIntArray *theArray,
91                                 TObjectId2TupleGaussIdMap& theObjectId2TupleGaussIdMap);
92   
93   template<class TGetFieldData>
94   vtkIntArray*
95   GetIDMapper(VISU::TFieldList* theFieldList,
96               TGetFieldData theGetFieldData,
97               const char* theFieldName);
98
99   template<class TGetFieldData>
100   vtkIntArray*
101   GetIDMapper(vtkDataSet* theIDMapperDataSet,
102               TGetFieldData theGetFieldData,
103               const char* theFieldName);
104
105   bool
106   IsDifferent(vtkIntArray *theFirstIDMapper,
107               vtkIntArray *theSecondIDMapper);
108
109   void
110   GetIntersection(vtkIntArray *theFirstIDMapper,
111                   vtkIntArray *theSecondIDMapper,
112                   TObjectIdArray& theResult);
113
114   //---------------------------------------------------------------
115   bool
116   Execute(vtkUnstructuredGrid *theInput,
117           vtkUnstructuredGrid *theOutput,
118           vtkDataSet* theScalarsDataSet,
119           vtkDataSet* theVectorsDataSet,
120           vtkDataSet* theNormalsDataSet,
121           vtkDataSet* theTCoordsDataSet,
122           vtkDataSet* theTensorsDataSet,
123           TFieldList* theFieldList,
124           bool theIsMergingInputs);
125
126
127   //---------------------------------------------------------------
128   bool
129   Execute(vtkPolyData *theInput,
130           vtkPolyData *theOutput,
131           vtkDataSet* theScalarsDataSet,
132           vtkDataSet* theVectorsDataSet,
133           vtkDataSet* theNormalsDataSet,
134           vtkDataSet* theTCoordsDataSet,
135           vtkDataSet* theTensorsDataSet,
136           TFieldList* theFieldList,
137           bool theIsMergingInputs);
138
139   //---------------------------------------------------------------
140   class TFieldNode
141   {
142   public:
143     TFieldNode(const char* name, vtkDataSet* ptr=0)
144     {
145       int length = static_cast<int>(strlen(name));
146       if (length > 0) {
147         this->Name = new char[length+1];
148         strcpy(this->Name, name);
149       } else {
150         this->Name = 0;
151       }
152       this->Ptr = ptr;
153       this->Next = 0;
154     }
155     ~TFieldNode()
156     {
157       delete[] this->Name;
158     }
159
160     const char* GetName()
161     {
162       return Name;
163     }
164     vtkDataSet* Ptr;
165     TFieldNode* Next;
166   private:
167     TFieldNode(const TFieldNode&) {}
168     void operator=(const TFieldNode&) {}
169     char* Name;
170   };
171
172
173   //---------------------------------------------------------------
174   class TFieldList
175   {
176   public:
177     TFieldList()
178     {
179       this->First = 0;
180       this->Last = 0;
181     }
182     ~TFieldList()
183     {
184       TFieldNode* node = this->First;
185       TFieldNode* next;
186       while(node){
187         next = node->Next;
188         delete node;
189         node = next;
190       }
191     }
192
193
194     void Add(const char* name, vtkDataSet* ptr)
195     {
196       TFieldNode* newNode = new TFieldNode(name, ptr);
197       if (!this->First) {
198         this->First = newNode;
199         this->Last = newNode;
200       } else {
201         this->Last->Next = newNode;
202         this->Last = newNode;
203       }
204     }
205
206     friend class TFieldListIterator;
207     
208   private:
209     TFieldNode* First;
210     TFieldNode* Last;
211   };
212   
213
214   //---------------------------------------------------------------
215   class TFieldListIterator
216   {
217   public:
218     TFieldListIterator(TFieldList* list)
219     {
220       this->List = list;
221       this->Position = 0;
222     }
223     void Begin()
224     {
225       this->Position = this->List->First;
226     }
227     void Next()
228     {
229       if (this->Position) {
230         this->Position = this->Position->Next;
231       }
232     }
233     int End()
234     {
235       return this->Position ? 0 : 1;
236     }
237     TFieldNode* Get()
238     {
239       return this->Position;
240     }
241     
242   private:
243     TFieldNode* Position;
244     TFieldList* List;
245   };
246   
247
248   //---------------------------------------------------------------
249 }
250
251 #endif
252
253