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