1 // Copyright (C) 2007-2010 CEA/DEN, EDF R&D, OPEN CASCADE
3 // Copyright (C) 2003-2007 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
23 // VISU OBJECT : interactive object for VISU entities implementation
24 // File: VISU_PolyDataMapperHolder.cxx
25 // Author: Alexey PETROV
28 #include "VISU_PolyDataMapperHolder.hxx"
29 #include "SALOME_ExtractPolyDataGeometry.h"
30 #include "VISU_LookupTable.hxx"
32 #include "VISU_PipeLineUtils.hxx"
34 #include <vtkPolyDataMapper.h>
35 #include <vtkPolyData.h>
38 #include <vtkImplicitBoolean.h>
39 #include <vtkImplicitFunction.h>
40 #include <vtkImplicitFunctionCollection.h>
42 //#include <vtkExtractPolyDataGeometry.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();
70 //myExtractPolyDataGeometry->ExtractInsideOn();
74 //----------------------------------------------------------------------------
75 VISU_PolyDataMapperHolder
76 ::~VISU_PolyDataMapperHolder()
79 MESSAGE("VISU_PolyDataMapperHolder::~VISU_PolyDataMapperHolder - "<<this);
83 //----------------------------------------------------------------------------
85 VISU_PolyDataMapperHolder
86 ::ShallowCopy(VISU_MapperHolder *theMapperHolder,
89 if(VISU_PolyDataMapperHolder* aMapperHolder = dynamic_cast<VISU_PolyDataMapperHolder*>(theMapperHolder)){
91 SetPolyDataIDMapper(aMapperHolder->GetPolyDataIDMapper());
93 VISU::CopyPolyDataMapper(GetPolyDataMapper(),
94 aMapperHolder->GetPolyDataMapper(),
96 myExtractPolyDataGeometry->SetImplicitFunction(aMapperHolder->GetImplicitFunction());
101 //----------------------------------------------------------------------------
103 VISU_PolyDataMapperHolder
106 unsigned long int aSize = Superclass::GetMemorySize();
108 if(myExtractPolyDataGeometry->GetInput())
109 if(vtkDataSet* aDataSet = myExtractPolyDataGeometry->GetOutput())
110 aSize = aDataSet->GetActualMemorySize() * 1024;
116 //----------------------------------------------------------------------------
118 VISU_PolyDataMapperHolder
119 ::SetPolyDataIDMapper(const VISU::PPolyDataIDMapper& theIDMapper)
121 myExtractPolyDataGeometry->SetInput(theIDMapper->GetPolyDataOutput());
122 myPolyDataIDMapper = theIDMapper;
123 SetIDMapper(theIDMapper);
127 //----------------------------------------------------------------------------
128 const VISU::PPolyDataIDMapper&
129 VISU_PolyDataMapperHolder
130 ::GetPolyDataIDMapper()
132 return myPolyDataIDMapper;
136 //----------------------------------------------------------------------------
138 VISU_PolyDataMapperHolder
141 if(myPolyDataIDMapper)
142 return myPolyDataIDMapper->GetPolyDataOutput();
148 //----------------------------------------------------------------------------
150 VISU_PolyDataMapperHolder
153 if(myExtractPolyDataGeometry->GetInput())
154 myExtractPolyDataGeometry->Update();
155 return myExtractPolyDataGeometry->GetOutput();
159 //----------------------------------------------------------------------------
161 VISU_PolyDataMapperHolder
164 myPolyDataMapper = vtkPolyDataMapper::New();
165 myPolyDataMapper->Delete();
166 SetMapper(myPolyDataMapper.GetPointer());
170 //----------------------------------------------------------------------------
172 VISU_PolyDataMapperHolder
173 ::SetPolyDataMapper(vtkPolyDataMapper* theMapper)
175 myPolyDataMapper = theMapper;
176 SetMapper(myPolyDataMapper.GetPointer());
180 //----------------------------------------------------------------------------
182 VISU_PolyDataMapperHolder
183 ::GetPolyDataMapper()
186 return myPolyDataMapper.GetPointer();
190 //----------------------------------------------------------------------------
192 VISU_PolyDataMapperHolder
193 ::SetLookupTable(VISU_LookupTable* theLookupTable)
195 myPolyDataMapper->SetLookupTable(theLookupTable);
199 //----------------------------------------------------------------------------
201 VISU_PolyDataMapperHolder
202 ::GetNodeObjID(vtkIdType theID)
204 vtkIdType anID = myExtractPolyDataGeometry->GetNodeObjId(theID);
205 return Superclass::GetNodeObjID(anID);
208 //----------------------------------------------------------------------------
210 VISU_PolyDataMapperHolder
211 ::GetNodeVTKID(vtkIdType theID)
213 vtkIdType anID = Superclass::GetNodeVTKID(theID);
214 return myExtractPolyDataGeometry->GetNodeVTKId(anID);
217 //----------------------------------------------------------------------------
218 vtkFloatingPointType*
219 VISU_PolyDataMapperHolder
220 ::GetNodeCoord(vtkIdType theObjID)
222 return Superclass::GetNodeCoord(theObjID);
226 //----------------------------------------------------------------------------
228 VISU_PolyDataMapperHolder
229 ::GetElemObjID(vtkIdType theID)
231 vtkIdType anID = myExtractPolyDataGeometry->GetElemObjId(theID);
232 return Superclass::GetElemObjID(anID);
235 //----------------------------------------------------------------------------
237 VISU_PolyDataMapperHolder
238 ::GetElemVTKID(vtkIdType theID)
240 vtkIdType anID = Superclass::GetElemVTKID(theID);
241 return myExtractPolyDataGeometry->GetElemVTKId(anID);
244 //----------------------------------------------------------------------------
246 VISU_PolyDataMapperHolder
247 ::GetElemCell(vtkIdType theObjID)
249 return Superclass::GetElemCell(theObjID);
253 //------------------------ Clipping planes -----------------------------------
255 VISU_PolyDataMapperHolder
256 ::AddClippingPlane(vtkPlane* thePlane)
259 if (vtkImplicitBoolean* aBoolean = myExtractPolyDataGeometry->GetImplicitBoolean()) {
260 vtkImplicitFunctionCollection* aFunction = aBoolean->GetFunction();
261 aFunction->AddItem(thePlane);
262 aBoolean->Modified();
263 // Check, that at least one cell present after clipping.
264 // This check was introduced because of bug IPAL8849.
265 vtkDataSet* aClippedDataSet = GetClippedInput();
266 if(aClippedDataSet->GetNumberOfCells() < 1)
273 //----------------------------------------------------------------------------
275 VISU_PolyDataMapperHolder
276 ::GetClippingPlane(vtkIdType theID)
278 vtkPlane* aPlane = NULL;
279 if(theID >= 0 && theID < GetNumberOfClippingPlanes()){
280 if(vtkImplicitBoolean* aBoolean = myExtractPolyDataGeometry->GetImplicitBoolean()){
281 vtkImplicitFunctionCollection* aFunction = aBoolean->GetFunction();
282 vtkImplicitFunction* aFun = NULL;
283 aFunction->InitTraversal();
284 for(vtkIdType anID = 0; anID <= theID; anID++)
285 aFun = aFunction->GetNextItem();
286 aPlane = dynamic_cast<vtkPlane*>(aFun);
292 //----------------------------------------------------------------------------
293 void VISU_PolyDataMapperHolder::RemoveClippingPlane(vtkIdType theID)
295 if(theID >= 0 && theID < GetNumberOfClippingPlanes()){
296 if(vtkImplicitBoolean* aBoolean = myExtractPolyDataGeometry->GetImplicitBoolean()){
297 vtkImplicitFunctionCollection* aFunctions = aBoolean->GetFunction();
298 aFunctions->RemoveItem(theID);
299 aBoolean->Modified();
304 //----------------------------------------------------------------------------
306 VISU_PolyDataMapperHolder
307 ::RemoveAllClippingPlanes()
309 if(vtkImplicitBoolean* aBoolean = myExtractPolyDataGeometry->GetImplicitBoolean()){
310 vtkImplicitFunctionCollection* aFunction = aBoolean->GetFunction();
311 aFunction->RemoveAllItems();
312 aBoolean->Modified(); // VTK bug
316 //----------------------------------------------------------------------------
318 VISU_PolyDataMapperHolder
319 ::GetNumberOfClippingPlanes()
321 if(vtkImplicitBoolean* aBoolean = myExtractPolyDataGeometry->GetImplicitBoolean()){
322 vtkImplicitFunctionCollection* aFunction = aBoolean->GetFunction();
323 return aFunction->GetNumberOfItems();
328 //----------------------------------------------------------------------------
330 VISU_PolyDataMapperHolder
331 ::SetImplicitFunction(vtkImplicitFunction *theFunction)
333 myExtractPolyDataGeometry->SetImplicitFunction(theFunction);
336 //----------------------------------------------------------------------------
338 VISU_PolyDataMapperHolder
339 ::GetImplicitFunction()
341 return myExtractPolyDataGeometry->GetImplicitFunction();
344 //----------------------------------------------------------------------------
346 VISU_PolyDataMapperHolder
347 ::SetExtractInside(bool theMode)
349 myExtractPolyDataGeometry->SetExtractInside(theMode);
352 //----------------------------------------------------------------------------
354 VISU_PolyDataMapperHolder
355 ::SetExtractBoundaryCells(bool theMode)
357 myExtractPolyDataGeometry->SetExtractBoundaryCells(theMode);
361 //----------------------------------------------------------------------------