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 double 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->SetInputConnection( theIDMapper->GetOutputPort() );
139 myExtractGeometry->SetInputConnection( myElnoDisassembleFilter->GetOutputPort() );
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();
176 //----------------------------------------------------------------------------
178 VISU_DataSetMapperHolder
179 ::GetClippedInputPort()
181 return myExtractGeometry->GetOutputPort();
185 //----------------------------------------------------------------------------
187 VISU_DataSetMapperHolder
190 myDataSetMapper = vtkDataSetMapper::New();
191 myDataSetMapper->Delete();
192 SetMapper(myDataSetMapper.GetPointer());
196 //----------------------------------------------------------------------------
198 VISU_DataSetMapperHolder
199 ::SetDataSetMapper(vtkDataSetMapper* theMapper)
201 myDataSetMapper = theMapper;
202 SetMapper(myDataSetMapper.GetPointer());
206 //----------------------------------------------------------------------------
208 VISU_DataSetMapperHolder
212 return myDataSetMapper.GetPointer();
216 //----------------------------------------------------------------------------
218 VISU_DataSetMapperHolder
219 ::SetLookupTable(VISU_LookupTable* theLookupTable)
221 myDataSetMapper->SetLookupTable(theLookupTable);
225 //----------------------------------------------------------------------------
227 VISU_DataSetMapperHolder
228 ::GetNodeObjID(vtkIdType theID)
230 vtkIdType anID = myExtractGeometry->GetNodeObjId(theID);
231 return Superclass::GetNodeObjID(anID);
234 //----------------------------------------------------------------------------
236 VISU_DataSetMapperHolder
237 ::GetNodeVTKID(vtkIdType theID)
239 vtkIdType anID = Superclass::GetNodeVTKID(theID);
240 return myExtractGeometry->GetNodeVTKId(anID);
243 //----------------------------------------------------------------------------
245 VISU_DataSetMapperHolder
246 ::GetNodeCoord(vtkIdType theObjID)
248 return Superclass::GetNodeCoord(theObjID);
252 //----------------------------------------------------------------------------
254 VISU_DataSetMapperHolder
255 ::GetElemObjID(vtkIdType theID)
257 vtkIdType anID = myExtractGeometry->GetElemObjId(theID);
258 return Superclass::GetElemObjID(anID);
261 //----------------------------------------------------------------------------
263 VISU_DataSetMapperHolder
264 ::GetElemVTKID(vtkIdType theID)
266 vtkIdType anID = Superclass::GetElemVTKID(theID);
267 return myExtractGeometry->GetElemVTKId(anID);
270 //----------------------------------------------------------------------------
272 VISU_DataSetMapperHolder
273 ::GetElemCell(vtkIdType theObjID)
275 return Superclass::GetElemCell(theObjID);
279 //----------------------------------------------------------------------------
281 VISU_DataSetMapperHolder
282 ::SetImplicitFunction(vtkImplicitFunction *theFunction)
284 myExtractGeometry->SetImplicitFunction(theFunction);
287 //----------------------------------------------------------------------------
288 vtkImplicitFunction *
289 VISU_DataSetMapperHolder
290 ::GetImplicitFunction()
292 return myExtractGeometry->GetImplicitFunction();
295 //----------------------------------------------------------------------------
297 VISU_DataSetMapperHolder
298 ::RemoveAllClippingPlanes()
300 if(vtkImplicitBoolean* aBoolean = myExtractGeometry->GetImplicitBoolean()){
301 vtkImplicitFunctionCollection* aFunction = aBoolean->GetFunction();
302 aFunction->RemoveAllItems();
303 aBoolean->Modified(); // VTK bug
307 //----------------------------------------------------------------------------
309 VISU_DataSetMapperHolder
310 ::GetNumberOfClippingPlanes()
312 if(vtkImplicitBoolean* aBoolean = myExtractGeometry->GetImplicitBoolean()){
313 vtkImplicitFunctionCollection* aFunction = aBoolean->GetFunction();
314 return aFunction->GetNumberOfItems();
319 //----------------------------------------------------------------------------
321 VISU_DataSetMapperHolder
322 ::AddClippingPlane(vtkPlane* thePlane)
325 if (vtkImplicitBoolean* aBoolean = myExtractGeometry->GetImplicitBoolean()) {
326 vtkImplicitFunctionCollection* aFunction = aBoolean->GetFunction();
327 aFunction->AddItem(thePlane);
328 aBoolean->Modified();
329 // Check, that at least one cell present after clipping.
330 // This check was introduced because of bug IPAL8849.
331 vtkDataSet* aClippedDataSet = GetClippedInput();
332 if(aClippedDataSet->GetNumberOfCells() < 1)
339 //----------------------------------------------------------------------------
341 VISU_DataSetMapperHolder
342 ::GetClippingPlane(vtkIdType theID)
344 vtkPlane* aPlane = NULL;
345 if(theID >= 0 && theID < GetNumberOfClippingPlanes()){
346 if(vtkImplicitBoolean* aBoolean = myExtractGeometry->GetImplicitBoolean()){
347 vtkImplicitFunctionCollection* aFunction = aBoolean->GetFunction();
348 vtkImplicitFunction* aFun = NULL;
349 aFunction->InitTraversal();
350 for(vtkIdType anID = 0; anID <= theID; anID++)
351 aFun = aFunction->GetNextItem();
352 aPlane = dynamic_cast<vtkPlane*>(aFun);
358 //----------------------------------------------------------------------------
359 void VISU_DataSetMapperHolder::RemoveClippingPlane(vtkIdType theID)
361 if(theID >= 0 && theID < GetNumberOfClippingPlanes()){
362 if(vtkImplicitBoolean* aBoolean = myExtractGeometry->GetImplicitBoolean()){
363 vtkImplicitFunctionCollection* aFunctions = aBoolean->GetFunction();
364 aFunctions->RemoveItem(theID);
365 aBoolean->Modified();
371 //----------------------------------------------------------------------------
373 VISU_DataSetMapperHolder
374 ::SetExtractInside(bool theMode)
376 myExtractGeometry->SetExtractInside(theMode);
379 //----------------------------------------------------------------------------
381 VISU_DataSetMapperHolder
382 ::SetExtractBoundaryCells(bool theMode)
384 myExtractGeometry->SetExtractBoundaryCells(theMode);
388 //----------------------------------------------------------------------------