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_DataSetMapperHolder.cxx
24 // Author: Alexey PETROV
27 #include "VISU_DataSetMapperHolder.hxx"
28 #include "SALOME_ExtractGeometry.h"
29 #include "VISU_ElnoDisassembleFilter.hxx"
30 #include "VISU_LookupTable.hxx"
32 #include "VISU_PipeLineUtils.hxx"
34 #include <vtkDataSetMapper.h>
35 #include <vtkUnstructuredGrid.h>
38 #include <vtkImplicitBoolean.h>
39 #include <vtkImplicitFunction.h>
40 #include <vtkImplicitFunctionCollection.h>
46 static int MYDEBUG = 0;
48 static int MYDEBUG = 0;
52 //----------------------------------------------------------------------------
53 vtkStandardNewMacro(VISU_DataSetMapperHolder);
56 //----------------------------------------------------------------------------
57 VISU_DataSetMapperHolder
58 ::VISU_DataSetMapperHolder():
59 myElnoDisassembleFilter( VISU_ElnoDisassembleFilter::New() ),
60 myExtractGeometry( SALOME_ExtractGeometry::New() )
62 if(MYDEBUG) MESSAGE("VISU_DataSetMapperHolder::VISU_DataSetMapperHolder - "<<this);
64 myElnoDisassembleFilter->Delete();
66 // Clipping functionality
67 myExtractGeometry->Delete();
68 myExtractGeometry->SetStoreMapping(true);
70 vtkImplicitBoolean* anImplicitBoolean = vtkImplicitBoolean::New();
71 myExtractGeometry->SetImplicitFunction(anImplicitBoolean);
72 anImplicitBoolean->SetOperationTypeToIntersection();
73 anImplicitBoolean->Delete();
77 //----------------------------------------------------------------------------
78 VISU_DataSetMapperHolder
79 ::~VISU_DataSetMapperHolder()
82 MESSAGE("VISU_DataSetMapperHolder::~VISU_DataSetMapperHolder - "<<this);
86 //----------------------------------------------------------------------------
88 VISU_DataSetMapperHolder
89 ::ShallowCopy(VISU_MapperHolder *theMapperHolder,
92 if(VISU_DataSetMapperHolder* aMapperHolder = dynamic_cast<VISU_DataSetMapperHolder*>(theMapperHolder)){
94 SetUnstructuredGridIDMapper(aMapperHolder->GetUnstructuredGridIDMapper());
96 VISU::CopyDataSetMapper(GetDataSetMapper(),
97 aMapperHolder->GetDataSetMapper(),
99 myExtractGeometry->SetImplicitFunction(aMapperHolder->GetImplicitFunction());
104 //----------------------------------------------------------------------------
106 VISU_DataSetMapperHolder
107 ::SetElnoDisassembleState( bool theIsShrunk )
109 vtkFloatingPointType aShrinkFactor = std::abs( myElnoDisassembleFilter->GetShrinkFactor() );
111 myElnoDisassembleFilter->SetShrinkFactor( aShrinkFactor );
113 myElnoDisassembleFilter->SetShrinkFactor( -aShrinkFactor );
117 //----------------------------------------------------------------------------
119 VISU_DataSetMapperHolder
122 unsigned long int aSize = Superclass::GetMemorySize();
124 if(myExtractGeometry->GetInput())
125 if(vtkDataSet* aDataSet = myExtractGeometry->GetOutput())
126 aSize = aDataSet->GetActualMemorySize() * 1024;
132 //----------------------------------------------------------------------------
134 VISU_DataSetMapperHolder
135 ::SetUnstructuredGridIDMapper(const VISU::PUnstructuredGridIDMapper& theIDMapper)
137 myElnoDisassembleFilter->SetInput( theIDMapper->GetUnstructuredGridOutput() );
138 myExtractGeometry->SetInput( myElnoDisassembleFilter->GetOutput() );
139 myUnstructuredGridIDMapper = theIDMapper;
140 SetIDMapper( theIDMapper );
144 //----------------------------------------------------------------------------
145 const VISU::PUnstructuredGridIDMapper&
146 VISU_DataSetMapperHolder
147 ::GetUnstructuredGridIDMapper()
149 return myUnstructuredGridIDMapper;
153 //----------------------------------------------------------------------------
155 VISU_DataSetMapperHolder
156 ::GetUnstructuredGridInput()
158 if(myUnstructuredGridIDMapper)
159 return myUnstructuredGridIDMapper->GetUnstructuredGridOutput();
165 //----------------------------------------------------------------------------
167 VISU_DataSetMapperHolder
170 if(myExtractGeometry->GetInput())
171 myExtractGeometry->Update();
172 return myExtractGeometry->GetOutput();
176 //----------------------------------------------------------------------------
178 VISU_DataSetMapperHolder
181 myDataSetMapper = vtkDataSetMapper::New();
182 myDataSetMapper->Delete();
183 SetMapper(myDataSetMapper.GetPointer());
187 //----------------------------------------------------------------------------
189 VISU_DataSetMapperHolder
190 ::SetDataSetMapper(vtkDataSetMapper* theMapper)
192 myDataSetMapper = theMapper;
193 SetMapper(myDataSetMapper.GetPointer());
197 //----------------------------------------------------------------------------
199 VISU_DataSetMapperHolder
203 return myDataSetMapper.GetPointer();
207 //----------------------------------------------------------------------------
209 VISU_DataSetMapperHolder
210 ::SetLookupTable(VISU_LookupTable* theLookupTable)
212 myDataSetMapper->SetLookupTable(theLookupTable);
216 //----------------------------------------------------------------------------
218 VISU_DataSetMapperHolder
219 ::GetNodeObjID(vtkIdType theID)
221 vtkIdType anID = myExtractGeometry->GetNodeObjId(theID);
222 return Superclass::GetNodeObjID(anID);
225 //----------------------------------------------------------------------------
227 VISU_DataSetMapperHolder
228 ::GetNodeVTKID(vtkIdType theID)
230 vtkIdType anID = Superclass::GetNodeVTKID(theID);
231 return myExtractGeometry->GetNodeVTKId(anID);
234 //----------------------------------------------------------------------------
235 vtkFloatingPointType*
236 VISU_DataSetMapperHolder
237 ::GetNodeCoord(vtkIdType theObjID)
239 return Superclass::GetNodeCoord(theObjID);
243 //----------------------------------------------------------------------------
245 VISU_DataSetMapperHolder
246 ::GetElemObjID(vtkIdType theID)
248 vtkIdType anID = myExtractGeometry->GetElemObjId(theID);
249 return Superclass::GetElemObjID(anID);
252 //----------------------------------------------------------------------------
254 VISU_DataSetMapperHolder
255 ::GetElemVTKID(vtkIdType theID)
257 vtkIdType anID = Superclass::GetElemVTKID(theID);
258 return myExtractGeometry->GetElemVTKId(anID);
261 //----------------------------------------------------------------------------
263 VISU_DataSetMapperHolder
264 ::GetElemCell(vtkIdType theObjID)
266 return Superclass::GetElemCell(theObjID);
270 //----------------------------------------------------------------------------
272 VISU_DataSetMapperHolder
273 ::SetImplicitFunction(vtkImplicitFunction *theFunction)
275 myExtractGeometry->SetImplicitFunction(theFunction);
278 //----------------------------------------------------------------------------
279 vtkImplicitFunction *
280 VISU_DataSetMapperHolder
281 ::GetImplicitFunction()
283 return myExtractGeometry->GetImplicitFunction();
286 //----------------------------------------------------------------------------
288 VISU_DataSetMapperHolder
289 ::RemoveAllClippingPlanes()
291 if(vtkImplicitBoolean* aBoolean = myExtractGeometry->GetImplicitBoolean()){
292 vtkImplicitFunctionCollection* aFunction = aBoolean->GetFunction();
293 aFunction->RemoveAllItems();
294 aBoolean->Modified(); // VTK bug
298 //----------------------------------------------------------------------------
300 VISU_DataSetMapperHolder
301 ::GetNumberOfClippingPlanes()
303 if(vtkImplicitBoolean* aBoolean = myExtractGeometry->GetImplicitBoolean()){
304 vtkImplicitFunctionCollection* aFunction = aBoolean->GetFunction();
305 return aFunction->GetNumberOfItems();
310 //----------------------------------------------------------------------------
312 VISU_DataSetMapperHolder
313 ::AddClippingPlane(vtkPlane* thePlane)
316 if (vtkImplicitBoolean* aBoolean = myExtractGeometry->GetImplicitBoolean()) {
317 vtkImplicitFunctionCollection* aFunction = aBoolean->GetFunction();
318 aFunction->AddItem(thePlane);
319 aBoolean->Modified();
320 // Check, that at least one cell present after clipping.
321 // This check was introduced because of bug IPAL8849.
322 vtkDataSet* aClippedDataSet = GetClippedInput();
323 if(aClippedDataSet->GetNumberOfCells() < 1)
330 //----------------------------------------------------------------------------
332 VISU_DataSetMapperHolder
333 ::GetClippingPlane(vtkIdType theID)
335 vtkPlane* aPlane = NULL;
336 if(theID >= 0 && theID < GetNumberOfClippingPlanes()){
337 if(vtkImplicitBoolean* aBoolean = myExtractGeometry->GetImplicitBoolean()){
338 vtkImplicitFunctionCollection* aFunction = aBoolean->GetFunction();
339 vtkImplicitFunction* aFun = NULL;
340 aFunction->InitTraversal();
341 for(vtkIdType anID = 0; anID <= theID; anID++)
342 aFun = aFunction->GetNextItem();
343 aPlane = dynamic_cast<vtkPlane*>(aFun);
349 //----------------------------------------------------------------------------
350 void VISU_DataSetMapperHolder::RemoveClippingPlane(vtkIdType theID)
352 if(theID >= 0 && theID < GetNumberOfClippingPlanes()){
353 if(vtkImplicitBoolean* aBoolean = myExtractGeometry->GetImplicitBoolean()){
354 vtkImplicitFunctionCollection* aFunctions = aBoolean->GetFunction();
355 aFunctions->RemoveItem(theID);
356 aBoolean->Modified();
362 //----------------------------------------------------------------------------
364 VISU_DataSetMapperHolder
365 ::SetExtractInside(bool theMode)
367 myExtractGeometry->SetExtractInside(theMode);
370 //----------------------------------------------------------------------------
372 VISU_DataSetMapperHolder
373 ::SetExtractBoundaryCells(bool theMode)
375 myExtractGeometry->SetExtractBoundaryCells(theMode);
379 //----------------------------------------------------------------------------