1 // Copyright (C) 2007-2013 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->SetInputData(theDataSet);
105 myMapper->SetInputConnection(myPolyDataExtractor->GetOutputPort());
107 myExtractor->SetInputData(theDataSet);
108 myMapper->SetInputConnection(myExtractor->GetOutputPort());
110 // myMapper->SetInputData(theDataSet);
112 SetMapper(myMapper.GetPointer());
115 //----------------------------------------------------------------------------
116 vtkDataSetMapper* VISU_DataSetActor::GetDataSetMapper()
118 return myMapper.GetPointer();
121 //----------------------------------------------------------------------------
122 void VISU_DataSetActor::RemoveAllClippingPlanes()
124 myFunction->GetFunction()->RemoveAllItems();
125 myFunction->Modified();
128 //----------------------------------------------------------------------------
129 vtkIdType VISU_DataSetActor::GetNumberOfClippingPlanes()
131 return myFunction->GetFunction()->GetNumberOfItems();
134 //----------------------------------------------------------------------------
135 bool VISU_DataSetActor::AddClippingPlane(vtkPlane* thePlane)
137 vtkImplicitFunctionCollection* aFunctions = GetClippingPlanes();
138 aFunctions->InitTraversal();
139 vtkImplicitFunction* aItem;
140 while ((aItem = aFunctions->GetNextItem())) {
141 if (thePlane == aItem)
144 myFunction->AddFunction(thePlane);
148 //----------------------------------------------------------------------------
149 vtkPlane* VISU_DataSetActor::GetClippingPlane(vtkIdType theID)
151 vtkPlane* aPlane = NULL;
152 if ((theID >= 0) && (theID < GetNumberOfClippingPlanes())) {
153 vtkImplicitFunctionCollection* aFunction = myFunction->GetFunction();
154 vtkImplicitFunction* aFun = NULL;
155 aFunction->InitTraversal();
156 for (vtkIdType i = 0; i <= theID; i++)
157 aFun = aFunction->GetNextItem();
158 aPlane = dynamic_cast<vtkPlane*>(aFun);
163 //----------------------------------------------------------------------------
164 vtkImplicitFunctionCollection* VISU_DataSetActor::GetClippingPlanes()
166 return myFunction->GetFunction();