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