1 // Copyright (C) 2007-2008 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
22 // VISU OBJECT : interactive object for VISU entities implementation
23 // File: VISU_PolyDataMapperHolder.cxx
24 // Author: Alexey PETROV
27 #include "VISU_PolyDataMapperHolder.hxx"
28 #include "SALOME_ExtractPolyDataGeometry.h"
29 #include "VISU_LookupTable.hxx"
31 #include "VISU_PipeLineUtils.hxx"
33 #include <vtkPolyDataMapper.h>
34 #include <vtkPolyData.h>
37 #include <vtkImplicitBoolean.h>
38 #include <vtkImplicitFunction.h>
39 #include <vtkImplicitFunctionCollection.h>
41 //#include <vtkExtractPolyDataGeometry.h>
44 static int MYDEBUG = 0;
46 static int MYDEBUG = 0;
50 //----------------------------------------------------------------------------
51 vtkStandardNewMacro(VISU_PolyDataMapperHolder);
54 //----------------------------------------------------------------------------
55 VISU_PolyDataMapperHolder
56 ::VISU_PolyDataMapperHolder():
57 myExtractPolyDataGeometry(SALOME_ExtractPolyDataGeometry::New())
59 if(MYDEBUG) MESSAGE("VISU_PolyDataMapperHolder::VISU_PolyDataMapperHolder - "<<this);
61 // Clipping functionality
62 myExtractPolyDataGeometry->Delete();
63 myExtractPolyDataGeometry->SetStoreMapping(true);
65 vtkImplicitBoolean* anImplicitBoolean = vtkImplicitBoolean::New();
66 myExtractPolyDataGeometry->SetImplicitFunction(anImplicitBoolean);
67 anImplicitBoolean->SetOperationTypeToIntersection();
68 anImplicitBoolean->Delete();
69 //myExtractPolyDataGeometry->ExtractInsideOn();
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(),
95 myExtractPolyDataGeometry->SetImplicitFunction(aMapperHolder->GetImplicitFunction());
100 //----------------------------------------------------------------------------
102 VISU_PolyDataMapperHolder
105 unsigned long int aSize = Superclass::GetMemorySize();
107 if(myExtractPolyDataGeometry->GetInput())
108 if(vtkDataSet* aDataSet = myExtractPolyDataGeometry->GetOutput())
109 aSize = aDataSet->GetActualMemorySize() * 1024;
115 //----------------------------------------------------------------------------
117 VISU_PolyDataMapperHolder
118 ::SetPolyDataIDMapper(const VISU::PPolyDataIDMapper& theIDMapper)
120 myExtractPolyDataGeometry->SetInput(theIDMapper->GetPolyDataOutput());
121 myPolyDataIDMapper = theIDMapper;
122 SetIDMapper(theIDMapper);
126 //----------------------------------------------------------------------------
127 const VISU::PPolyDataIDMapper&
128 VISU_PolyDataMapperHolder
129 ::GetPolyDataIDMapper()
131 return myPolyDataIDMapper;
135 //----------------------------------------------------------------------------
137 VISU_PolyDataMapperHolder
140 if(myPolyDataIDMapper)
141 return myPolyDataIDMapper->GetPolyDataOutput();
147 //----------------------------------------------------------------------------
149 VISU_PolyDataMapperHolder
152 if(myExtractPolyDataGeometry->GetInput())
153 myExtractPolyDataGeometry->Update();
154 return myExtractPolyDataGeometry->GetOutput();
158 //----------------------------------------------------------------------------
160 VISU_PolyDataMapperHolder
163 myPolyDataMapper = vtkPolyDataMapper::New();
164 myPolyDataMapper->Delete();
165 SetMapper(myPolyDataMapper.GetPointer());
169 //----------------------------------------------------------------------------
171 VISU_PolyDataMapperHolder
172 ::SetPolyDataMapper(vtkPolyDataMapper* theMapper)
174 myPolyDataMapper = theMapper;
175 SetMapper(myPolyDataMapper.GetPointer());
179 //----------------------------------------------------------------------------
181 VISU_PolyDataMapperHolder
182 ::GetPolyDataMapper()
185 return myPolyDataMapper.GetPointer();
189 //----------------------------------------------------------------------------
191 VISU_PolyDataMapperHolder
192 ::SetLookupTable(VISU_LookupTable* theLookupTable)
194 myPolyDataMapper->SetLookupTable(theLookupTable);
198 //----------------------------------------------------------------------------
200 VISU_PolyDataMapperHolder
201 ::GetNodeObjID(vtkIdType theID)
203 vtkIdType anID = myExtractPolyDataGeometry->GetNodeObjId(theID);
204 return Superclass::GetNodeObjID(anID);
207 //----------------------------------------------------------------------------
209 VISU_PolyDataMapperHolder
210 ::GetNodeVTKID(vtkIdType theID)
212 vtkIdType anID = Superclass::GetNodeVTKID(theID);
213 return myExtractPolyDataGeometry->GetNodeVTKId(anID);
216 //----------------------------------------------------------------------------
217 vtkFloatingPointType*
218 VISU_PolyDataMapperHolder
219 ::GetNodeCoord(vtkIdType theObjID)
221 return Superclass::GetNodeCoord(theObjID);
225 //----------------------------------------------------------------------------
227 VISU_PolyDataMapperHolder
228 ::GetElemObjID(vtkIdType theID)
230 vtkIdType anID = myExtractPolyDataGeometry->GetElemObjId(theID);
231 return Superclass::GetElemObjID(anID);
234 //----------------------------------------------------------------------------
236 VISU_PolyDataMapperHolder
237 ::GetElemVTKID(vtkIdType theID)
239 vtkIdType anID = Superclass::GetElemVTKID(theID);
240 return myExtractPolyDataGeometry->GetElemVTKId(anID);
243 //----------------------------------------------------------------------------
245 VISU_PolyDataMapperHolder
246 ::GetElemCell(vtkIdType theObjID)
248 return Superclass::GetElemCell(theObjID);
252 //------------------------ Clipping planes -----------------------------------
254 VISU_PolyDataMapperHolder
255 ::AddClippingPlane(vtkPlane* 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)
272 //----------------------------------------------------------------------------
274 VISU_PolyDataMapperHolder
275 ::GetClippingPlane(vtkIdType theID)
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);
291 //----------------------------------------------------------------------------
292 void VISU_PolyDataMapperHolder::RemoveClippingPlane(vtkIdType theID)
294 if(theID >= 0 && theID < GetNumberOfClippingPlanes()){
295 if(vtkImplicitBoolean* aBoolean = myExtractPolyDataGeometry->GetImplicitBoolean()){
296 vtkImplicitFunctionCollection* aFunctions = aBoolean->GetFunction();
297 aFunctions->RemoveItem(theID);
298 aBoolean->Modified();
303 //----------------------------------------------------------------------------
305 VISU_PolyDataMapperHolder
306 ::RemoveAllClippingPlanes()
308 if(vtkImplicitBoolean* aBoolean = myExtractPolyDataGeometry->GetImplicitBoolean()){
309 vtkImplicitFunctionCollection* aFunction = aBoolean->GetFunction();
310 aFunction->RemoveAllItems();
311 aBoolean->Modified(); // VTK bug
315 //----------------------------------------------------------------------------
317 VISU_PolyDataMapperHolder
318 ::GetNumberOfClippingPlanes()
320 if(vtkImplicitBoolean* aBoolean = myExtractPolyDataGeometry->GetImplicitBoolean()){
321 vtkImplicitFunctionCollection* aFunction = aBoolean->GetFunction();
322 return aFunction->GetNumberOfItems();
327 //----------------------------------------------------------------------------
329 VISU_PolyDataMapperHolder
330 ::SetImplicitFunction(vtkImplicitFunction *theFunction)
332 myExtractPolyDataGeometry->SetImplicitFunction(theFunction);
335 //----------------------------------------------------------------------------
337 VISU_PolyDataMapperHolder
338 ::GetImplicitFunction()
340 return myExtractPolyDataGeometry->GetImplicitFunction();
343 //----------------------------------------------------------------------------
345 VISU_PolyDataMapperHolder
346 ::SetExtractInside(bool theMode)
348 myExtractPolyDataGeometry->SetExtractInside(theMode);
351 //----------------------------------------------------------------------------
353 VISU_PolyDataMapperHolder
354 ::SetExtractBoundaryCells(bool theMode)
356 myExtractPolyDataGeometry->SetExtractBoundaryCells(theMode);
360 //----------------------------------------------------------------------------