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_DataSetMapperHolder.cxx
25 // Author: Alexey PETROV
29 #include "VISU_DataSetMapperHolder.hxx"
30 #include "SALOME_ExtractGeometry.h"
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>
45 static int MYDEBUG = 0;
47 static int MYDEBUG = 0;
51 //----------------------------------------------------------------------------
52 vtkStandardNewMacro(VISU_DataSetMapperHolder);
55 //----------------------------------------------------------------------------
56 VISU_DataSetMapperHolder
57 ::VISU_DataSetMapperHolder():
58 myExtractGeometry(SALOME_ExtractGeometry::New())
60 if(MYDEBUG) MESSAGE("VISU_DataSetMapperHolder::VISU_DataSetMapperHolder - "<<this);
62 // Clipping functionality
63 myExtractGeometry->Delete();
64 myExtractGeometry->SetStoreMapping(true);
66 vtkImplicitBoolean* anImplicitBoolean = vtkImplicitBoolean::New();
67 myExtractGeometry->SetImplicitFunction(anImplicitBoolean);
68 anImplicitBoolean->SetOperationTypeToIntersection();
69 anImplicitBoolean->Delete();
73 //----------------------------------------------------------------------------
74 VISU_DataSetMapperHolder
75 ::~VISU_DataSetMapperHolder()
78 MESSAGE("VISU_DataSetMapperHolder::~VISU_DataSetMapperHolder - "<<this);
82 //----------------------------------------------------------------------------
84 VISU_DataSetMapperHolder
85 ::ShallowCopy(VISU_MapperHolder *theMapperHolder,
88 if(VISU_DataSetMapperHolder* aMapperHolder = dynamic_cast<VISU_DataSetMapperHolder*>(theMapperHolder)){
90 SetUnstructuredGridIDMapper(aMapperHolder->GetUnstructuredGridIDMapper());
92 VISU::CopyDataSetMapper(GetDataSetMapper(),
93 aMapperHolder->GetDataSetMapper(),
99 //----------------------------------------------------------------------------
101 VISU_DataSetMapperHolder
104 unsigned long int aSize = Superclass::GetMemorySize();
106 if(myExtractGeometry->GetInput())
107 if(vtkDataSet* aDataSet = myExtractGeometry->GetOutput())
108 aSize = aDataSet->GetActualMemorySize() * 1024;
114 //----------------------------------------------------------------------------
116 VISU_DataSetMapperHolder
117 ::SetUnstructuredGridIDMapper(const VISU::PUnstructuredGridIDMapper& theIDMapper)
119 myExtractGeometry->SetInput(theIDMapper->GetUnstructuredGridOutput());
120 myUnstructuredGridIDMapper = theIDMapper;
121 SetIDMapper(theIDMapper);
125 //----------------------------------------------------------------------------
126 const VISU::PUnstructuredGridIDMapper&
127 VISU_DataSetMapperHolder
128 ::GetUnstructuredGridIDMapper()
130 return myUnstructuredGridIDMapper;
134 //----------------------------------------------------------------------------
136 VISU_DataSetMapperHolder
137 ::GetUnstructuredGridInput()
139 if(myUnstructuredGridIDMapper)
140 return myUnstructuredGridIDMapper->GetUnstructuredGridOutput();
146 //----------------------------------------------------------------------------
148 VISU_DataSetMapperHolder
151 if(myExtractGeometry->GetInput())
152 myExtractGeometry->Update();
153 return myExtractGeometry->GetOutput();
157 //----------------------------------------------------------------------------
159 VISU_DataSetMapperHolder
162 myDataSetMapper = vtkDataSetMapper::New();
163 myDataSetMapper->Delete();
164 SetMapper(myDataSetMapper.GetPointer());
168 //----------------------------------------------------------------------------
170 VISU_DataSetMapperHolder
171 ::SetDataSetMapper(vtkDataSetMapper* theMapper)
173 myDataSetMapper = theMapper;
174 SetMapper(myDataSetMapper.GetPointer());
178 //----------------------------------------------------------------------------
180 VISU_DataSetMapperHolder
184 return myDataSetMapper.GetPointer();
188 //----------------------------------------------------------------------------
190 VISU_DataSetMapperHolder
191 ::SetLookupTable(VISU_LookupTable* theLookupTable)
193 myDataSetMapper->SetLookupTable(theLookupTable);
197 //----------------------------------------------------------------------------
199 VISU_DataSetMapperHolder
200 ::GetNodeObjID(vtkIdType theID)
202 vtkIdType anID = myExtractGeometry->GetNodeObjId(theID);
203 return Superclass::GetNodeObjID(anID);
206 //----------------------------------------------------------------------------
208 VISU_DataSetMapperHolder
209 ::GetNodeVTKID(vtkIdType theID)
211 vtkIdType anID = Superclass::GetNodeVTKID(theID);
212 return myExtractGeometry->GetNodeVTKId(anID);
215 //----------------------------------------------------------------------------
216 vtkFloatingPointType*
217 VISU_DataSetMapperHolder
218 ::GetNodeCoord(int theObjID)
220 return Superclass::GetNodeCoord(theObjID);
224 //----------------------------------------------------------------------------
226 VISU_DataSetMapperHolder
227 ::GetElemObjID(vtkIdType theID)
229 vtkIdType anID = myExtractGeometry->GetElemObjId(theID);
230 return Superclass::GetElemObjID(anID);
233 //----------------------------------------------------------------------------
235 VISU_DataSetMapperHolder
236 ::GetElemVTKID(vtkIdType theID)
238 vtkIdType anID = Superclass::GetElemVTKID(theID);
239 return myExtractGeometry->GetElemVTKId(anID);
242 //----------------------------------------------------------------------------
244 VISU_DataSetMapperHolder
245 ::GetElemCell(vtkIdType theObjID)
247 return Superclass::GetElemCell(theObjID);
251 //----------------------------------------------------------------------------
253 VISU_DataSetMapperHolder
254 ::SetImplicitFunction(vtkImplicitFunction *theFunction)
256 myExtractGeometry->SetImplicitFunction(theFunction);
259 //----------------------------------------------------------------------------
260 vtkImplicitFunction *
261 VISU_DataSetMapperHolder
262 ::GetImplicitFunction()
264 return myExtractGeometry->GetImplicitFunction();
267 //----------------------------------------------------------------------------
269 VISU_DataSetMapperHolder
270 ::RemoveAllClippingPlanes()
272 if(vtkImplicitBoolean* aBoolean = myExtractGeometry->GetImplicitBoolean()){
273 vtkImplicitFunctionCollection* aFunction = aBoolean->GetFunction();
274 aFunction->RemoveAllItems();
275 aBoolean->Modified(); // VTK bug
279 //----------------------------------------------------------------------------
281 VISU_DataSetMapperHolder
282 ::GetNumberOfClippingPlanes()
284 if(vtkImplicitBoolean* aBoolean = myExtractGeometry->GetImplicitBoolean()){
285 vtkImplicitFunctionCollection* aFunction = aBoolean->GetFunction();
286 return aFunction->GetNumberOfItems();
291 //----------------------------------------------------------------------------
293 VISU_DataSetMapperHolder
294 ::AddClippingPlane(vtkPlane* thePlane)
297 if (vtkImplicitBoolean* aBoolean = myExtractGeometry->GetImplicitBoolean()) {
298 vtkImplicitFunctionCollection* aFunction = aBoolean->GetFunction();
299 aFunction->AddItem(thePlane);
300 // Check, that at least one cell present after clipping.
301 // This check was introduced because of bug IPAL8849.
302 vtkDataSet* aClippedDataSet = GetClippedInput();
303 if(aClippedDataSet->GetNumberOfCells() < 1)
310 //----------------------------------------------------------------------------
312 VISU_DataSetMapperHolder
313 ::GetClippingPlane(vtkIdType theID)
315 vtkPlane* aPlane = NULL;
316 if(theID >= 0 && theID < GetNumberOfClippingPlanes()){
317 if(vtkImplicitBoolean* aBoolean = myExtractGeometry->GetImplicitBoolean()){
318 vtkImplicitFunctionCollection* aFunction = aBoolean->GetFunction();
319 vtkImplicitFunction* aFun = NULL;
320 aFunction->InitTraversal();
321 for(vtkIdType anID = 0; anID <= theID; anID++)
322 aFun = aFunction->GetNextItem();
323 aPlane = dynamic_cast<vtkPlane*>(aFun);
329 //----------------------------------------------------------------------------
331 VISU_DataSetMapperHolder
332 ::SetExtractInside(bool theMode)
334 myExtractGeometry->SetExtractInside(theMode);
337 //----------------------------------------------------------------------------
339 VISU_DataSetMapperHolder
340 ::SetExtractBoundaryCells(bool theMode)
342 myExtractGeometry->SetExtractBoundaryCells(theMode);
346 //----------------------------------------------------------------------------