1 // VISU OBJECT : interactive object for VISU entities implementation
3 // Copyright (C) 2003 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
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.
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.
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
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
24 // File: VISU_PolyDataMapperHolder.cxx
25 // Author: Alexey PETROV
29 #include "VISU_PolyDataMapperHolder.hxx"
30 #include "SALOME_ExtractPolyDataGeometry.h"
31 #include "VISU_LookupTable.hxx"
33 #include "VISU_PipeLineUtils.hxx"
35 #include <vtkPolyDataMapper.h>
36 #include <vtkPolyData.h>
39 #include <vtkImplicitBoolean.h>
40 #include <vtkImplicitFunction.h>
41 #include <vtkImplicitFunctionCollection.h>
45 static int MYDEBUG = 0;
47 static int MYDEBUG = 0;
51 //----------------------------------------------------------------------------
52 vtkStandardNewMacro(VISU_PolyDataMapperHolder);
55 //----------------------------------------------------------------------------
56 VISU_PolyDataMapperHolder
57 ::VISU_PolyDataMapperHolder():
58 myExtractPolyDataGeometry(SALOME_ExtractPolyDataGeometry::New())
60 if(MYDEBUG) MESSAGE("VISU_PolyDataMapperHolder::VISU_PolyDataMapperHolder - "<<this);
62 // Clipping functionality
63 myExtractPolyDataGeometry->Delete();
64 myExtractPolyDataGeometry->SetStoreMapping(true);
66 vtkImplicitBoolean* anImplicitBoolean = vtkImplicitBoolean::New();
67 myExtractPolyDataGeometry->SetImplicitFunction(anImplicitBoolean);
68 anImplicitBoolean->SetOperationTypeToIntersection();
69 anImplicitBoolean->Delete();
73 //----------------------------------------------------------------------------
74 VISU_PolyDataMapperHolder
75 ::~VISU_PolyDataMapperHolder()
78 MESSAGE("VISU_PolyDataMapperHolder::~VISU_PolyDataMapperHolder - "<<this);
82 //----------------------------------------------------------------------------
84 VISU_PolyDataMapperHolder
85 ::ShallowCopy(VISU_MapperHolder *theMapperHolder,
88 if(VISU_PolyDataMapperHolder* aMapperHolder = dynamic_cast<VISU_PolyDataMapperHolder*>(theMapperHolder)){
90 SetPolyDataIDMapper(aMapperHolder->GetPolyDataIDMapper());
92 VISU::CopyPolyDataMapper(GetPolyDataMapper(),
93 aMapperHolder->GetPolyDataMapper(),
99 //----------------------------------------------------------------------------
101 VISU_PolyDataMapperHolder
104 unsigned long int aSize = Superclass::GetMemorySize();
106 if(myExtractPolyDataGeometry->GetInput())
107 if(vtkDataSet* aDataSet = myExtractPolyDataGeometry->GetOutput())
108 aSize = aDataSet->GetActualMemorySize() * 1024;
114 //----------------------------------------------------------------------------
116 VISU_PolyDataMapperHolder
117 ::SetPolyDataIDMapper(const VISU::PPolyDataIDMapper& theIDMapper)
119 myExtractPolyDataGeometry->SetInput(theIDMapper->GetPolyDataOutput());
120 myPolyDataIDMapper = theIDMapper;
121 SetIDMapper(theIDMapper);
125 //----------------------------------------------------------------------------
126 const VISU::PPolyDataIDMapper&
127 VISU_PolyDataMapperHolder
128 ::GetPolyDataIDMapper()
130 return myPolyDataIDMapper;
134 //----------------------------------------------------------------------------
136 VISU_PolyDataMapperHolder
139 if(myPolyDataIDMapper)
140 return myPolyDataIDMapper->GetPolyDataOutput();
146 //----------------------------------------------------------------------------
148 VISU_PolyDataMapperHolder
151 if(myExtractPolyDataGeometry->GetInput())
152 myExtractPolyDataGeometry->Update();
153 return myExtractPolyDataGeometry->GetOutput();
157 //----------------------------------------------------------------------------
159 VISU_PolyDataMapperHolder
162 myPolyDataMapper = vtkPolyDataMapper::New();
163 myPolyDataMapper->Delete();
164 SetMapper(myPolyDataMapper.GetPointer());
168 //----------------------------------------------------------------------------
170 VISU_PolyDataMapperHolder
171 ::SetPolyDataMapper(vtkPolyDataMapper* theMapper)
173 myPolyDataMapper = theMapper;
174 SetMapper(myPolyDataMapper.GetPointer());
178 //----------------------------------------------------------------------------
180 VISU_PolyDataMapperHolder
181 ::GetPolyDataMapper()
184 return myPolyDataMapper.GetPointer();
188 //----------------------------------------------------------------------------
190 VISU_PolyDataMapperHolder
191 ::SetLookupTable(VISU_LookupTable* theLookupTable)
193 myPolyDataMapper->SetLookupTable(theLookupTable);
197 //----------------------------------------------------------------------------
199 VISU_PolyDataMapperHolder
200 ::GetNodeObjID(vtkIdType theID)
202 vtkIdType anID = myExtractPolyDataGeometry->GetNodeObjId(theID);
203 return Superclass::GetNodeObjID(anID);
206 //----------------------------------------------------------------------------
208 VISU_PolyDataMapperHolder
209 ::GetNodeVTKID(vtkIdType theID)
211 vtkIdType anID = Superclass::GetNodeVTKID(theID);
212 return myExtractPolyDataGeometry->GetNodeVTKId(anID);
215 //----------------------------------------------------------------------------
216 vtkFloatingPointType*
217 VISU_PolyDataMapperHolder
218 ::GetNodeCoord(vtkIdType theObjID)
220 return Superclass::GetNodeCoord(theObjID);
224 //----------------------------------------------------------------------------
226 VISU_PolyDataMapperHolder
227 ::GetElemObjID(vtkIdType theID)
229 vtkIdType anID = myExtractPolyDataGeometry->GetElemObjId(theID);
230 return Superclass::GetElemObjID(anID);
233 //----------------------------------------------------------------------------
235 VISU_PolyDataMapperHolder
236 ::GetElemVTKID(vtkIdType theID)
238 vtkIdType anID = Superclass::GetElemVTKID(theID);
239 return myExtractPolyDataGeometry->GetElemVTKId(anID);
242 //----------------------------------------------------------------------------
244 VISU_PolyDataMapperHolder
245 ::GetElemCell(vtkIdType theObjID)
247 return Superclass::GetElemCell(theObjID);
251 //------------------------ Clipping planes -----------------------------------
253 VISU_PolyDataMapperHolder
254 ::AddClippingPlane(vtkPlane* thePlane)
257 if (vtkImplicitBoolean* aBoolean = myExtractPolyDataGeometry->GetImplicitBoolean()) {
258 vtkImplicitFunctionCollection* aFunction = aBoolean->GetFunction();
259 aFunction->AddItem(thePlane);
260 // Check, that at least one cell present after clipping.
261 // This check was introduced because of bug IPAL8849.
262 vtkDataSet* aClippedDataSet = GetClippedInput();
263 if(aClippedDataSet->GetNumberOfCells() < 1)
270 //----------------------------------------------------------------------------
272 VISU_PolyDataMapperHolder
273 ::GetClippingPlane(vtkIdType theID)
275 vtkPlane* aPlane = NULL;
276 if(theID >= 0 && theID < GetNumberOfClippingPlanes()){
277 if(vtkImplicitBoolean* aBoolean = myExtractPolyDataGeometry->GetImplicitBoolean()){
278 vtkImplicitFunctionCollection* aFunction = aBoolean->GetFunction();
279 vtkImplicitFunction* aFun = NULL;
280 aFunction->InitTraversal();
281 for(vtkIdType anID = 0; anID <= theID; anID++)
282 aFun = aFunction->GetNextItem();
283 aPlane = dynamic_cast<vtkPlane*>(aFun);
289 //----------------------------------------------------------------------------
291 VISU_PolyDataMapperHolder
292 ::RemoveAllClippingPlanes()
294 if(vtkImplicitBoolean* aBoolean = myExtractPolyDataGeometry->GetImplicitBoolean()){
295 vtkImplicitFunctionCollection* aFunction = aBoolean->GetFunction();
296 aFunction->RemoveAllItems();
297 aBoolean->Modified(); // VTK bug
301 //----------------------------------------------------------------------------
303 VISU_PolyDataMapperHolder
304 ::GetNumberOfClippingPlanes()
306 if(vtkImplicitBoolean* aBoolean = myExtractPolyDataGeometry->GetImplicitBoolean()){
307 vtkImplicitFunctionCollection* aFunction = aBoolean->GetFunction();
308 return aFunction->GetNumberOfItems();
313 //----------------------------------------------------------------------------
315 VISU_PolyDataMapperHolder
316 ::SetImplicitFunction(vtkImplicitFunction *theFunction)
318 myExtractPolyDataGeometry->SetImplicitFunction(theFunction);
321 //----------------------------------------------------------------------------
323 VISU_PolyDataMapperHolder
324 ::GetImplicitFunction()
326 return myExtractPolyDataGeometry->GetImplicitFunction();
329 //----------------------------------------------------------------------------
331 VISU_PolyDataMapperHolder
332 ::SetExtractInside(bool theMode)
334 myExtractPolyDataGeometry->SetExtractInside(theMode);
337 //----------------------------------------------------------------------------
339 VISU_PolyDataMapperHolder
340 ::SetExtractBoundaryCells(bool theMode)
342 myExtractPolyDataGeometry->SetExtractBoundaryCells(theMode);
346 //----------------------------------------------------------------------------