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 #include "SVTK_Actor.h"
24 #include "SALOME_Actor.h"
25 #include "SVTK_Utils.h"
27 #include "SALOME_InteractiveObject.hxx"
30 #include <vtkObjectFactory.h>
31 #include <vtkUnstructuredGrid.h>
32 #include <vtkDataSetMapper.h>
33 #include <vtkRenderer.h>
36 #define VTK_XVERSION (VTK_MAJOR_VERSION*10000+VTK_MINOR_VERSION*100+VTK_BUILD_VERSION)
37 #if VTK_XVERSION > 50700
38 #include <vtkPolyhedron.h>
40 #include <vtkPolyData.h>
42 #include "Utils_SALOME_Exception.hxx"
43 #include "utilities.h"
46 vtkStandardNewMacro(SVTK_Actor);
53 myUnstructuredGrid(vtkUnstructuredGrid::New())
56 myIsResolveCoincidentTopology = false;
58 Visibility = Pickable = false;
60 myUnstructuredGrid->Delete();
61 myUnstructuredGrid->Allocate();
68 SetInputData(GetSource());
73 ::SetSource(vtkUnstructuredGrid* theUnstructuredGrid)
75 if(GetSource() == theUnstructuredGrid)
78 myUnstructuredGrid = theUnstructuredGrid;
80 SetInputData(theUnstructuredGrid);
87 return myUnstructuredGrid.GetPointer();
98 const TColStd_IndexedMapOfInteger&
100 ::GetMapIndex() const
107 ::MapCells(SALOME_Actor* theMapActor,
108 const TColStd_IndexedMapOfInteger& theMapIndex)
110 myUnstructuredGrid->Initialize();
111 myUnstructuredGrid->Allocate();
113 vtkDataSet *aSourceDataSet = theMapActor->GetInput();
114 SVTK::CopyPoints(GetSource(),aSourceDataSet);
116 int aNbOfParts = theMapIndex.Extent();
117 for(int ind = 1; ind <= aNbOfParts; ind++){
118 int aPartId = theMapIndex( ind );
119 if(vtkCell* aCell = theMapActor->GetElemCell(aPartId))
121 #if VTK_XVERSION > 50700
122 if (aCell->GetCellType() != VTK_POLYHEDRON)
124 myUnstructuredGrid->InsertNextCell(aCell->GetCellType(),aCell->GetPointIds());
125 #if VTK_XVERSION > 50700
128 vtkPolyhedron *polyhedron = dynamic_cast<vtkPolyhedron*>(aCell);
130 throw SALOME_Exception(LOCALIZED ("not a polyhedron"));
131 vtkIdType *pts = polyhedron->GetFaces();
132 myUnstructuredGrid->InsertNextCell(aCell->GetCellType(),pts[0], pts+1);
139 if(theMapActor->IsShrunk()){
140 SetShrinkFactor(theMapActor->GetShrinkFactor());
144 myMapIndex = theMapIndex;
149 ::MapPoints(SALOME_Actor* theMapActor,
150 const TColStd_IndexedMapOfInteger& theMapIndex)
152 myUnstructuredGrid->Initialize();
153 myUnstructuredGrid->Allocate();
155 if(int aNbOfParts = theMapIndex.Extent()){
156 vtkPoints *aPoints = vtkPoints::New();
157 aPoints->SetNumberOfPoints(aNbOfParts);
158 for(vtkIdType i = 0; i < aNbOfParts; i++){
159 int aPartId = theMapIndex( i+1 );
160 if(double* aCoord = theMapActor->GetNodeCoord(aPartId)){
161 aPoints->SetPoint(i,aCoord);
162 // Change the type from int to vtkIdType in order to avoid compilation errors while using VTK
163 // from ParaView-3.4.0 compiled on 64-bit Debian platform with VTK_USE_64BIT_IDS = ON
164 myUnstructuredGrid->InsertNextCell(VTK_VERTEX,(vtkIdType) 1,&i);
167 myUnstructuredGrid->SetPoints(aPoints);
173 myMapIndex = theMapIndex;
178 ::MapEdge(SALOME_Actor* theMapActor,
179 const TColStd_IndexedMapOfInteger& theMapIndex)
181 myUnstructuredGrid->Initialize();
182 myUnstructuredGrid->Allocate();
184 vtkDataSet *aSourceDataSet = theMapActor->GetInput();
185 SVTK::CopyPoints(GetSource(),aSourceDataSet);
188 if(theMapIndex.Extent() == 2){
189 int anEdgeId = theMapIndex(1) < 0 ? theMapIndex(1) : theMapIndex(2);
190 int aCellId = theMapIndex(1) < 0 ? theMapIndex(2) : theMapIndex(1);
193 if(vtkCell* aCell = theMapActor->GetElemCell(aCellId)){
195 anEdgeId = -anEdgeId - 1;
196 int aNbOfEdges = aCell->GetNumberOfEdges();
197 if(0 <= anEdgeId || anEdgeId < aNbOfEdges){
198 if(vtkCell* anEdge = aCell->GetEdge(anEdgeId))
199 myUnstructuredGrid->InsertNextCell(VTK_LINE,anEdge->GetPointIds());
207 if(theMapActor->IsShrunk()){
208 SetShrinkFactor(theMapActor->GetShrinkFactor());
212 myMapIndex = theMapIndex;
216 To publish the actor an all its internal devices
220 ::AddToRender(vtkRenderer* theRenderer)
222 theRenderer->AddActor(this);
227 ::RemoveFromRender(vtkRenderer* theRenderer)
229 theRenderer->RemoveActor(this);