1 // Copyright (C) 2007-2010 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
28 #include "VISU_DataSetActor.h"
29 #include "VISU_UnstructuredGridPL.hxx"
30 #include "VISU_PipeLineUtils.hxx"
32 #include <VTKViewer_DataSetMapper.h>
34 #include <vtkObjectFactory.h>
35 #include <vtkImplicitBoolean.h>
36 #include <SALOME_ExtractGeometry.h>
37 #include <SALOME_ExtractPolyDataGeometry.h>
38 #include <vtkImplicitFunctionCollection.h>
41 #include <boost/bind.hpp>
46 static int MYDEBUG = 0;
48 static int MYDEBUG = 0;
51 //----------------------------------------------------------------------------
52 vtkStandardNewMacro(VISU_DataSetActor);
54 //----------------------------------------------------------------------------
56 ::VISU_DataSetActor():
57 myMapper(VTKViewer_DataSetMapper::New()),
58 myExtractor(SALOME_ExtractGeometry::New()),
59 myPolyDataExtractor(SALOME_ExtractPolyDataGeometry::New()),
60 myFunction(vtkImplicitBoolean::New())
62 if(MYDEBUG) MESSAGE("VISU_DataSetActor::VISU_DataSetActor - this = "<<this);
64 myExtractor->SetImplicitFunction(myFunction);
65 myPolyDataExtractor->SetImplicitFunction(myFunction);
66 //myExtractor->ExtractBoundaryCellsOn();
67 //myPolyDataExtractor->ExtractBoundaryCellsOn();
69 myFunction->SetOperationTypeToIntersection();
72 myExtractor->Delete();
73 myPolyDataExtractor->Delete();
77 //----------------------------------------------------------------------------
79 ::~VISU_DataSetActor()
81 if(MYDEBUG) MESSAGE("~VISU_DataSetActor() - this = "<<this);
84 //----------------------------------------------------------------------------
87 ::ShallowCopyPL(VISU_PipeLine* thePipeLine)
89 Superclass::ShallowCopyPL(thePipeLine);
91 if(VISU_UnstructuredGridPL* aPipeLine = dynamic_cast<VISU_UnstructuredGridPL*>(thePipeLine)){
92 vtkDataSetMapper* aTarget = GetDataSetMapper();
93 vtkDataSetMapper* aSource = aPipeLine->GetDataSetMapper();
94 VISU::CopyDataSetMapper(aTarget, aSource, true);
98 //----------------------------------------------------------------------------
101 ::SetMapperInput(vtkDataSet* theDataSet)
103 if (theDataSet->IsA("vtkPolyData")) {
104 myPolyDataExtractor->SetInput(theDataSet);
105 myMapper->SetInput(myPolyDataExtractor->GetOutput());
107 myExtractor->SetInput(theDataSet);
108 myMapper->SetInput(myExtractor->GetOutput());
110 // myMapper->SetInput(theDataSet);
111 SetMapper(myMapper.GetPointer());
114 //----------------------------------------------------------------------------
115 vtkDataSetMapper* VISU_DataSetActor::GetDataSetMapper()
117 return myMapper.GetPointer();
120 //----------------------------------------------------------------------------
121 void VISU_DataSetActor::RemoveAllClippingPlanes()
123 myFunction->GetFunction()->RemoveAllItems();
124 myFunction->Modified();
127 //----------------------------------------------------------------------------
128 vtkIdType VISU_DataSetActor::GetNumberOfClippingPlanes()
130 return myFunction->GetFunction()->GetNumberOfItems();
133 //----------------------------------------------------------------------------
134 bool VISU_DataSetActor::AddClippingPlane(vtkPlane* thePlane)
136 vtkImplicitFunctionCollection* aFunctions = GetClippingPlanes();
137 aFunctions->InitTraversal();
138 vtkImplicitFunction* aItem;
139 while ((aItem = aFunctions->GetNextItem())) {
140 if (thePlane == aItem)
143 myFunction->AddFunction(thePlane);
147 //----------------------------------------------------------------------------
148 vtkPlane* VISU_DataSetActor::GetClippingPlane(vtkIdType theID)
150 vtkPlane* aPlane = NULL;
151 if ((theID >= 0) && (theID < GetNumberOfClippingPlanes())) {
152 vtkImplicitFunctionCollection* aFunction = myFunction->GetFunction();
153 vtkImplicitFunction* aFun = NULL;
154 aFunction->InitTraversal();
155 for (vtkIdType i = 0; i <= theID; i++)
156 aFun = aFunction->GetNextItem();
157 aPlane = dynamic_cast<vtkPlane*>(aFun);
162 //----------------------------------------------------------------------------
163 vtkImplicitFunctionCollection* VISU_DataSetActor::GetClippingPlanes()
165 return myFunction->GetFunction();