1 // Copyright (C) 2007-2012 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_DataSetMapperHolder.cxx
25 // Author: Alexey PETROV
28 #include "VISU_DataSetMapperHolder.hxx"
29 #include "SALOME_ExtractGeometry.h"
30 #include "VISU_ElnoDisassembleFilter.hxx"
31 #include "VISU_LookupTable.hxx"
33 #include "VISU_PipeLineUtils.hxx"
35 #include <vtkDataSetMapper.h>
36 #include <vtkUnstructuredGrid.h>
39 #include <vtkImplicitBoolean.h>
40 #include <vtkImplicitFunction.h>
41 #include <vtkImplicitFunctionCollection.h>
47 static int MYDEBUG = 0;
49 static int MYDEBUG = 0;
53 //----------------------------------------------------------------------------
54 vtkStandardNewMacro(VISU_DataSetMapperHolder);
57 //----------------------------------------------------------------------------
58 VISU_DataSetMapperHolder
59 ::VISU_DataSetMapperHolder():
60 myElnoDisassembleFilter( VISU_ElnoDisassembleFilter::New() ),
61 myExtractGeometry( SALOME_ExtractGeometry::New() )
63 if(MYDEBUG) MESSAGE("VISU_DataSetMapperHolder::VISU_DataSetMapperHolder - "<<this);
65 myElnoDisassembleFilter->Delete();
67 // Clipping functionality
68 myExtractGeometry->Delete();
69 myExtractGeometry->SetStoreMapping(true);
71 vtkImplicitBoolean* anImplicitBoolean = vtkImplicitBoolean::New();
72 myExtractGeometry->SetImplicitFunction(anImplicitBoolean);
73 anImplicitBoolean->SetOperationTypeToIntersection();
74 anImplicitBoolean->Delete();
78 //----------------------------------------------------------------------------
79 VISU_DataSetMapperHolder
80 ::~VISU_DataSetMapperHolder()
83 MESSAGE("VISU_DataSetMapperHolder::~VISU_DataSetMapperHolder - "<<this);
87 //----------------------------------------------------------------------------
89 VISU_DataSetMapperHolder
90 ::ShallowCopy(VISU_MapperHolder *theMapperHolder,
93 if(VISU_DataSetMapperHolder* aMapperHolder = dynamic_cast<VISU_DataSetMapperHolder*>(theMapperHolder)){
95 SetUnstructuredGridIDMapper(aMapperHolder->GetUnstructuredGridIDMapper());
97 VISU::CopyDataSetMapper(GetDataSetMapper(),
98 aMapperHolder->GetDataSetMapper(),
100 myExtractGeometry->SetImplicitFunction(aMapperHolder->GetImplicitFunction());
105 //----------------------------------------------------------------------------
107 VISU_DataSetMapperHolder
108 ::SetElnoDisassembleState( bool theIsShrunk )
110 vtkFloatingPointType aShrinkFactor = std::abs( myElnoDisassembleFilter->GetShrinkFactor() );
112 myElnoDisassembleFilter->SetShrinkFactor( aShrinkFactor );
114 myElnoDisassembleFilter->SetShrinkFactor( -aShrinkFactor );
118 //----------------------------------------------------------------------------
120 VISU_DataSetMapperHolder
123 unsigned long int aSize = Superclass::GetMemorySize();
125 if(myExtractGeometry->GetInput())
126 if(vtkDataSet* aDataSet = myExtractGeometry->GetOutput())
127 aSize = aDataSet->GetActualMemorySize() * 1024;
133 //----------------------------------------------------------------------------
135 VISU_DataSetMapperHolder
136 ::SetUnstructuredGridIDMapper(const VISU::PUnstructuredGridIDMapper& theIDMapper)
138 myElnoDisassembleFilter->SetInput( theIDMapper->GetUnstructuredGridOutput() );
139 myExtractGeometry->SetInput( myElnoDisassembleFilter->GetOutput() );
140 myUnstructuredGridIDMapper = theIDMapper;
141 SetIDMapper( theIDMapper );
145 //----------------------------------------------------------------------------
146 const VISU::PUnstructuredGridIDMapper&
147 VISU_DataSetMapperHolder
148 ::GetUnstructuredGridIDMapper()
150 return myUnstructuredGridIDMapper;
154 //----------------------------------------------------------------------------
156 VISU_DataSetMapperHolder
157 ::GetUnstructuredGridInput()
159 if(myUnstructuredGridIDMapper)
160 return myUnstructuredGridIDMapper->GetUnstructuredGridOutput();
166 //----------------------------------------------------------------------------
168 VISU_DataSetMapperHolder
171 if(myExtractGeometry->GetInput())
172 myExtractGeometry->Update();
173 return myExtractGeometry->GetOutput();
177 //----------------------------------------------------------------------------
179 VISU_DataSetMapperHolder
182 myDataSetMapper = vtkDataSetMapper::New();
183 myDataSetMapper->Delete();
184 SetMapper(myDataSetMapper.GetPointer());
188 //----------------------------------------------------------------------------
190 VISU_DataSetMapperHolder
191 ::SetDataSetMapper(vtkDataSetMapper* theMapper)
193 myDataSetMapper = theMapper;
194 SetMapper(myDataSetMapper.GetPointer());
198 //----------------------------------------------------------------------------
200 VISU_DataSetMapperHolder
204 return myDataSetMapper.GetPointer();
208 //----------------------------------------------------------------------------
210 VISU_DataSetMapperHolder
211 ::SetLookupTable(VISU_LookupTable* theLookupTable)
213 myDataSetMapper->SetLookupTable(theLookupTable);
217 //----------------------------------------------------------------------------
219 VISU_DataSetMapperHolder
220 ::GetNodeObjID(vtkIdType theID)
222 vtkIdType anID = myExtractGeometry->GetNodeObjId(theID);
223 return Superclass::GetNodeObjID(anID);
226 //----------------------------------------------------------------------------
228 VISU_DataSetMapperHolder
229 ::GetNodeVTKID(vtkIdType theID)
231 vtkIdType anID = Superclass::GetNodeVTKID(theID);
232 return myExtractGeometry->GetNodeVTKId(anID);
235 //----------------------------------------------------------------------------
236 vtkFloatingPointType*
237 VISU_DataSetMapperHolder
238 ::GetNodeCoord(vtkIdType theObjID)
240 return Superclass::GetNodeCoord(theObjID);
244 //----------------------------------------------------------------------------
246 VISU_DataSetMapperHolder
247 ::GetElemObjID(vtkIdType theID)
249 vtkIdType anID = myExtractGeometry->GetElemObjId(theID);
250 return Superclass::GetElemObjID(anID);
253 //----------------------------------------------------------------------------
255 VISU_DataSetMapperHolder
256 ::GetElemVTKID(vtkIdType theID)
258 vtkIdType anID = Superclass::GetElemVTKID(theID);
259 return myExtractGeometry->GetElemVTKId(anID);
262 //----------------------------------------------------------------------------
264 VISU_DataSetMapperHolder
265 ::GetElemCell(vtkIdType theObjID)
267 return Superclass::GetElemCell(theObjID);
271 //----------------------------------------------------------------------------
273 VISU_DataSetMapperHolder
274 ::SetImplicitFunction(vtkImplicitFunction *theFunction)
276 myExtractGeometry->SetImplicitFunction(theFunction);
279 //----------------------------------------------------------------------------
280 vtkImplicitFunction *
281 VISU_DataSetMapperHolder
282 ::GetImplicitFunction()
284 return myExtractGeometry->GetImplicitFunction();
287 //----------------------------------------------------------------------------
289 VISU_DataSetMapperHolder
290 ::RemoveAllClippingPlanes()
292 if(vtkImplicitBoolean* aBoolean = myExtractGeometry->GetImplicitBoolean()){
293 vtkImplicitFunctionCollection* aFunction = aBoolean->GetFunction();
294 aFunction->RemoveAllItems();
295 aBoolean->Modified(); // VTK bug
299 //----------------------------------------------------------------------------
301 VISU_DataSetMapperHolder
302 ::GetNumberOfClippingPlanes()
304 if(vtkImplicitBoolean* aBoolean = myExtractGeometry->GetImplicitBoolean()){
305 vtkImplicitFunctionCollection* aFunction = aBoolean->GetFunction();
306 return aFunction->GetNumberOfItems();
311 //----------------------------------------------------------------------------
313 VISU_DataSetMapperHolder
314 ::AddClippingPlane(vtkPlane* thePlane)
317 if (vtkImplicitBoolean* aBoolean = myExtractGeometry->GetImplicitBoolean()) {
318 vtkImplicitFunctionCollection* aFunction = aBoolean->GetFunction();
319 aFunction->AddItem(thePlane);
320 aBoolean->Modified();
321 // Check, that at least one cell present after clipping.
322 // This check was introduced because of bug IPAL8849.
323 vtkDataSet* aClippedDataSet = GetClippedInput();
324 if(aClippedDataSet->GetNumberOfCells() < 1)
331 //----------------------------------------------------------------------------
333 VISU_DataSetMapperHolder
334 ::GetClippingPlane(vtkIdType theID)
336 vtkPlane* aPlane = NULL;
337 if(theID >= 0 && theID < GetNumberOfClippingPlanes()){
338 if(vtkImplicitBoolean* aBoolean = myExtractGeometry->GetImplicitBoolean()){
339 vtkImplicitFunctionCollection* aFunction = aBoolean->GetFunction();
340 vtkImplicitFunction* aFun = NULL;
341 aFunction->InitTraversal();
342 for(vtkIdType anID = 0; anID <= theID; anID++)
343 aFun = aFunction->GetNextItem();
344 aPlane = dynamic_cast<vtkPlane*>(aFun);
350 //----------------------------------------------------------------------------
351 void VISU_DataSetMapperHolder::RemoveClippingPlane(vtkIdType theID)
353 if(theID >= 0 && theID < GetNumberOfClippingPlanes()){
354 if(vtkImplicitBoolean* aBoolean = myExtractGeometry->GetImplicitBoolean()){
355 vtkImplicitFunctionCollection* aFunctions = aBoolean->GetFunction();
356 aFunctions->RemoveItem(theID);
357 aBoolean->Modified();
363 //----------------------------------------------------------------------------
365 VISU_DataSetMapperHolder
366 ::SetExtractInside(bool theMode)
368 myExtractGeometry->SetExtractInside(theMode);
371 //----------------------------------------------------------------------------
373 VISU_DataSetMapperHolder
374 ::SetExtractBoundaryCells(bool theMode)
376 myExtractGeometry->SetExtractBoundaryCells(theMode);
380 //----------------------------------------------------------------------------