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