]> SALOME platform Git repositories - modules/visu.git/blob - src/PIPELINE/VISU_DataSetMapperHolder.cxx
Salome HOME
Join modifications from BR_Dev_For_4_0 tag V4_1_1.
[modules/visu.git] / src / PIPELINE / VISU_DataSetMapperHolder.cxx
1 //  VISU OBJECT : interactive object for VISU entities implementation
2 //
3 //  Copyright (C) 2003  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 //
23 //
24 // File:    VISU_DataSetMapperHolder.cxx
25 // Author:  Alexey PETROV
26 // Module : VISU
27
28
29 #include "VISU_DataSetMapperHolder.hxx"
30 #include "SALOME_ExtractGeometry.h"
31 #include "VISU_LookupTable.hxx"
32
33 #include "VISU_PipeLineUtils.hxx"
34
35 #include <vtkDataSetMapper.h>
36 #include <vtkUnstructuredGrid.h>
37
38 #include <vtkPlane.h>
39 #include <vtkImplicitBoolean.h>
40 #include <vtkImplicitFunction.h>
41 #include <vtkImplicitFunctionCollection.h>
42 #include <vtkMath.h>
43
44 #ifdef _DEBUG_
45 static int MYDEBUG = 0;
46 #else
47 static int MYDEBUG = 0;
48 #endif
49
50
51 //----------------------------------------------------------------------------
52 vtkStandardNewMacro(VISU_DataSetMapperHolder);
53
54
55 //----------------------------------------------------------------------------
56 VISU_DataSetMapperHolder
57 ::VISU_DataSetMapperHolder():
58   myExtractGeometry(SALOME_ExtractGeometry::New())
59 {
60   if(MYDEBUG) MESSAGE("VISU_DataSetMapperHolder::VISU_DataSetMapperHolder - "<<this);
61
62   // Clipping functionality
63   myExtractGeometry->Delete();
64   myExtractGeometry->SetStoreMapping(true);
65
66   vtkImplicitBoolean* anImplicitBoolean = vtkImplicitBoolean::New();
67   myExtractGeometry->SetImplicitFunction(anImplicitBoolean);
68   anImplicitBoolean->SetOperationTypeToIntersection();
69   anImplicitBoolean->Delete();
70 }
71
72
73 //----------------------------------------------------------------------------
74 VISU_DataSetMapperHolder
75 ::~VISU_DataSetMapperHolder()
76 {
77   if(MYDEBUG)
78     MESSAGE("VISU_DataSetMapperHolder::~VISU_DataSetMapperHolder - "<<this);
79 }
80
81
82 //----------------------------------------------------------------------------
83 void 
84 VISU_DataSetMapperHolder
85 ::ShallowCopy(VISU_MapperHolder *theMapperHolder,
86               bool theIsCopyInput)
87 {
88   if(VISU_DataSetMapperHolder* aMapperHolder = dynamic_cast<VISU_DataSetMapperHolder*>(theMapperHolder)){
89     if(theIsCopyInput)
90       SetUnstructuredGridIDMapper(aMapperHolder->GetUnstructuredGridIDMapper());
91     
92     VISU::CopyDataSetMapper(GetDataSetMapper(), 
93                             aMapperHolder->GetDataSetMapper(), 
94                             theIsCopyInput);
95   }
96 }
97
98
99 //----------------------------------------------------------------------------
100 unsigned long int
101 VISU_DataSetMapperHolder
102 ::GetMemorySize()
103 {
104   unsigned long int aSize = Superclass::GetMemorySize();
105
106   if(myExtractGeometry->GetInput())
107     if(vtkDataSet* aDataSet = myExtractGeometry->GetOutput())
108       aSize = aDataSet->GetActualMemorySize() * 1024;
109   
110   return aSize;
111 }
112
113
114 //----------------------------------------------------------------------------
115 void
116 VISU_DataSetMapperHolder
117 ::SetUnstructuredGridIDMapper(const VISU::PUnstructuredGridIDMapper& theIDMapper)
118 {
119   myExtractGeometry->SetInput(theIDMapper->GetUnstructuredGridOutput());
120   myUnstructuredGridIDMapper = theIDMapper;
121   SetIDMapper(theIDMapper);
122 }
123
124
125 //----------------------------------------------------------------------------
126 const VISU::PUnstructuredGridIDMapper&  
127 VISU_DataSetMapperHolder
128 ::GetUnstructuredGridIDMapper()
129 {
130   return myUnstructuredGridIDMapper;
131 }
132
133
134 //----------------------------------------------------------------------------
135 vtkUnstructuredGrid* 
136 VISU_DataSetMapperHolder
137 ::GetUnstructuredGridInput()
138 {
139   if(myUnstructuredGridIDMapper)
140     return myUnstructuredGridIDMapper->GetUnstructuredGridOutput();
141
142   return NULL;
143 }
144
145
146 //----------------------------------------------------------------------------
147 vtkPointSet* 
148 VISU_DataSetMapperHolder
149 ::GetClippedInput()
150 {
151   if(myExtractGeometry->GetInput())
152     myExtractGeometry->Update();
153   return myExtractGeometry->GetOutput();
154 }
155
156
157 //----------------------------------------------------------------------------
158 void
159 VISU_DataSetMapperHolder
160 ::OnCreateMapper()
161 {
162   myDataSetMapper = vtkDataSetMapper::New();
163   myDataSetMapper->Delete();
164   SetMapper(myDataSetMapper.GetPointer());
165 }
166
167
168 //----------------------------------------------------------------------------
169 void
170 VISU_DataSetMapperHolder
171 ::SetDataSetMapper(vtkDataSetMapper* theMapper)
172 {
173   myDataSetMapper = theMapper;
174   SetMapper(myDataSetMapper.GetPointer());
175 }
176
177
178 //----------------------------------------------------------------------------
179 vtkDataSetMapper* 
180 VISU_DataSetMapperHolder
181 ::GetDataSetMapper()
182 {
183   GetMapper();
184   return myDataSetMapper.GetPointer();
185 }
186
187
188 //----------------------------------------------------------------------------
189 void
190 VISU_DataSetMapperHolder
191 ::SetLookupTable(VISU_LookupTable* theLookupTable)
192 {
193   myDataSetMapper->SetLookupTable(theLookupTable);
194 }
195
196
197 //----------------------------------------------------------------------------
198 vtkIdType 
199 VISU_DataSetMapperHolder
200 ::GetNodeObjID(vtkIdType theID)
201 {
202   vtkIdType anID = myExtractGeometry->GetNodeObjId(theID);
203   return Superclass::GetNodeObjID(anID);
204 }
205
206 //----------------------------------------------------------------------------
207 vtkIdType 
208 VISU_DataSetMapperHolder
209 ::GetNodeVTKID(vtkIdType theID)
210 {
211   vtkIdType anID = Superclass::GetNodeVTKID(theID);
212   return myExtractGeometry->GetNodeVTKId(anID);
213 }
214
215 //----------------------------------------------------------------------------
216 vtkFloatingPointType* 
217 VISU_DataSetMapperHolder
218 ::GetNodeCoord(int theObjID)
219 {
220   return Superclass::GetNodeCoord(theObjID);
221 }
222
223
224 //----------------------------------------------------------------------------
225 vtkIdType 
226 VISU_DataSetMapperHolder
227 ::GetElemObjID(vtkIdType theID)
228 {
229   vtkIdType anID = myExtractGeometry->GetElemObjId(theID);
230   return Superclass::GetElemObjID(anID);
231 }
232
233 //----------------------------------------------------------------------------
234 vtkIdType
235 VISU_DataSetMapperHolder
236 ::GetElemVTKID(vtkIdType theID)
237 {
238   vtkIdType anID = Superclass::GetElemVTKID(theID);
239   return myExtractGeometry->GetElemVTKId(anID);
240 }
241
242 //----------------------------------------------------------------------------
243 vtkCell* 
244 VISU_DataSetMapperHolder
245 ::GetElemCell(vtkIdType  theObjID)
246 {
247   return Superclass::GetElemCell(theObjID);
248 }
249
250
251 //----------------------------------------------------------------------------
252 void
253 VISU_DataSetMapperHolder
254 ::SetImplicitFunction(vtkImplicitFunction *theFunction)
255 {
256   myExtractGeometry->SetImplicitFunction(theFunction);
257
258
259 //----------------------------------------------------------------------------
260 vtkImplicitFunction * 
261 VISU_DataSetMapperHolder
262 ::GetImplicitFunction()
263 {
264   return myExtractGeometry->GetImplicitFunction();
265 }
266
267 //----------------------------------------------------------------------------
268 void
269 VISU_DataSetMapperHolder
270 ::RemoveAllClippingPlanes()
271 {
272   if(vtkImplicitBoolean* aBoolean = myExtractGeometry->GetImplicitBoolean()){
273     vtkImplicitFunctionCollection* aFunction = aBoolean->GetFunction();
274     aFunction->RemoveAllItems();
275     aBoolean->Modified(); // VTK bug
276   }
277 }
278
279 //----------------------------------------------------------------------------
280 vtkIdType
281 VISU_DataSetMapperHolder
282 ::GetNumberOfClippingPlanes()
283 {
284   if(vtkImplicitBoolean* aBoolean = myExtractGeometry->GetImplicitBoolean()){
285     vtkImplicitFunctionCollection* aFunction = aBoolean->GetFunction();
286     return aFunction->GetNumberOfItems();
287   }
288   return 0;
289 }
290
291 //----------------------------------------------------------------------------
292 bool 
293 VISU_DataSetMapperHolder
294 ::AddClippingPlane(vtkPlane* thePlane)
295 {
296   if (thePlane) {
297     if (vtkImplicitBoolean* aBoolean = myExtractGeometry->GetImplicitBoolean()) {
298       vtkImplicitFunctionCollection* aFunction = aBoolean->GetFunction();
299       aFunction->AddItem(thePlane);
300       // Check, that at least one cell present after clipping.
301       // This check was introduced because of bug IPAL8849.
302       vtkDataSet* aClippedDataSet = GetClippedInput();
303       if(aClippedDataSet->GetNumberOfCells() < 1)
304         return false;
305     }
306   }
307   return true;
308 }
309
310 //----------------------------------------------------------------------------
311 vtkPlane* 
312 VISU_DataSetMapperHolder
313 ::GetClippingPlane(vtkIdType theID)
314 {
315   vtkPlane* aPlane = NULL;
316   if(theID >= 0 && theID < GetNumberOfClippingPlanes()){
317     if(vtkImplicitBoolean* aBoolean = myExtractGeometry->GetImplicitBoolean()){
318       vtkImplicitFunctionCollection* aFunction = aBoolean->GetFunction();
319       vtkImplicitFunction* aFun = NULL;
320       aFunction->InitTraversal();
321       for(vtkIdType anID = 0; anID <= theID; anID++)
322         aFun = aFunction->GetNextItem();
323       aPlane = dynamic_cast<vtkPlane*>(aFun);
324     }
325   }
326   return aPlane;
327 }
328
329 //----------------------------------------------------------------------------
330 void
331 VISU_DataSetMapperHolder
332 ::SetExtractInside(bool theMode)
333 {
334   myExtractGeometry->SetExtractInside(theMode);
335 }
336
337 //----------------------------------------------------------------------------
338 void
339 VISU_DataSetMapperHolder
340 ::SetExtractBoundaryCells(bool theMode)
341 {
342   myExtractGeometry->SetExtractBoundaryCells(theMode);
343 }
344
345
346 //----------------------------------------------------------------------------