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