1 // Copyright (C) 2007-2008 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
22 // VISU OBJECT : interactive object for VISU entities implementation
27 #include "VISU_DataSetActor.h"
28 #include "VISU_UnstructuredGridPL.hxx"
29 #include "VISU_PipeLineUtils.hxx"
31 #include <vtkDataSetMapper.h>
32 #include <vtkObjectFactory.h>
33 #include <vtkImplicitBoolean.h>
34 #include <SALOME_ExtractGeometry.h>
35 #include <SALOME_ExtractPolyDataGeometry.h>
36 #include <vtkImplicitFunctionCollection.h>
39 #include <boost/bind.hpp>
44 static int MYDEBUG = 0;
46 static int MYDEBUG = 0;
49 //----------------------------------------------------------------------------
50 vtkStandardNewMacro(VISU_DataSetActor);
52 //----------------------------------------------------------------------------
54 ::VISU_DataSetActor():
55 myMapper(vtkDataSetMapper::New()),
56 myExtractor(SALOME_ExtractGeometry::New()),
57 myPolyDataExtractor(SALOME_ExtractPolyDataGeometry::New()),
58 myFunction(vtkImplicitBoolean::New())
60 if(MYDEBUG) MESSAGE("VISU_DataSetActor::VISU_DataSetActor - this = "<<this);
62 myExtractor->SetImplicitFunction(myFunction);
63 myPolyDataExtractor->SetImplicitFunction(myFunction);
64 //myExtractor->ExtractBoundaryCellsOn();
65 //myPolyDataExtractor->ExtractBoundaryCellsOn();
67 myFunction->SetOperationTypeToIntersection();
70 myExtractor->Delete();
71 myPolyDataExtractor->Delete();
75 //----------------------------------------------------------------------------
77 ::~VISU_DataSetActor()
79 if(MYDEBUG) MESSAGE("~VISU_DataSetActor() - this = "<<this);
82 //----------------------------------------------------------------------------
85 ::ShallowCopyPL(VISU_PipeLine* thePipeLine)
87 Superclass::ShallowCopyPL(thePipeLine);
89 if(VISU_UnstructuredGridPL* aPipeLine = dynamic_cast<VISU_UnstructuredGridPL*>(thePipeLine)){
90 vtkDataSetMapper* aTarget = GetDataSetMapper();
91 vtkDataSetMapper* aSource = aPipeLine->GetDataSetMapper();
92 VISU::CopyDataSetMapper(aTarget, aSource, true);
96 //----------------------------------------------------------------------------
99 ::SetMapperInput(vtkDataSet* theDataSet)
101 if (theDataSet->IsA("vtkPolyData")) {
102 myPolyDataExtractor->SetInput(theDataSet);
103 myMapper->SetInput(myPolyDataExtractor->GetOutput());
105 myExtractor->SetInput(theDataSet);
106 myMapper->SetInput(myExtractor->GetOutput());
108 // myMapper->SetInput(theDataSet);
109 SetMapper(myMapper.GetPointer());
112 //----------------------------------------------------------------------------
113 vtkDataSetMapper* VISU_DataSetActor::GetDataSetMapper()
115 return myMapper.GetPointer();
118 //----------------------------------------------------------------------------
119 void VISU_DataSetActor::RemoveAllClippingPlanes()
121 myFunction->GetFunction()->RemoveAllItems();
122 myFunction->Modified();
125 //----------------------------------------------------------------------------
126 vtkIdType VISU_DataSetActor::GetNumberOfClippingPlanes()
128 return myFunction->GetFunction()->GetNumberOfItems();
131 //----------------------------------------------------------------------------
132 bool VISU_DataSetActor::AddClippingPlane(vtkPlane* thePlane)
134 vtkImplicitFunctionCollection* aFunctions = GetClippingPlanes();
135 aFunctions->InitTraversal();
136 vtkImplicitFunction* aItem;
137 while ((aItem = aFunctions->GetNextItem())) {
138 if (thePlane == aItem)
141 myFunction->AddFunction(thePlane);
145 //----------------------------------------------------------------------------
146 vtkPlane* VISU_DataSetActor::GetClippingPlane(vtkIdType theID)
148 vtkPlane* aPlane = NULL;
149 if ((theID >= 0) && (theID < GetNumberOfClippingPlanes())) {
150 vtkImplicitFunctionCollection* aFunction = myFunction->GetFunction();
151 vtkImplicitFunction* aFun = NULL;
152 aFunction->InitTraversal();
153 for (vtkIdType i = 0; i <= theID; i++)
154 aFun = aFunction->GetNextItem();
155 aPlane = dynamic_cast<vtkPlane*>(aFun);
160 //----------------------------------------------------------------------------
161 vtkImplicitFunctionCollection* VISU_DataSetActor::GetClippingPlanes()
163 return myFunction->GetFunction();