1 // Copyright (C) 2007-2016 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, or (at your option) any later version.
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 #include <vtkVersion.h>
37 #define VTK_XVERSION (VTK_MAJOR_VERSION*10000+VTK_MINOR_VERSION*100+VTK_BUILD_VERSION)
38 #if VTK_XVERSION > 50700
39 #include <vtkPolyhedron.h>
41 #include <vtkPolyData.h>
43 #include "Utils_SALOME_Exception.hxx"
44 #include "utilities.h"
47 vtkStandardNewMacro(SVTK_Actor);
54 myUnstructuredGrid(vtkUnstructuredGrid::New())
57 myIsResolveCoincidentTopology = false;
59 Visibility = Pickable = false;
61 myUnstructuredGrid->Delete();
62 myUnstructuredGrid->Allocate();
69 SetInputData(GetSource());
74 ::SetSource(vtkUnstructuredGrid* theUnstructuredGrid)
76 if(GetSource() == theUnstructuredGrid)
79 myUnstructuredGrid = theUnstructuredGrid;
81 SetInputData(theUnstructuredGrid);
88 return myUnstructuredGrid.GetPointer();
99 const TColStd_IndexedMapOfInteger&
101 ::GetMapIndex() const
108 ::MapCells(SALOME_Actor* theMapActor,
109 const TColStd_IndexedMapOfInteger& theMapIndex)
111 myUnstructuredGrid->Initialize();
112 myUnstructuredGrid->Allocate();
114 vtkUnstructuredGrid * aSourceGrid = (vtkUnstructuredGrid *)theMapActor->GetInput();
115 GetSource()->SetPoints( aSourceGrid->GetPoints() );
117 int aNbOfParts = theMapIndex.Extent();
118 for(int ind = 1; ind <= aNbOfParts; ind++){
119 int aPartId = theMapIndex( ind );
120 if(vtkCell* aCell = theMapActor->GetElemCell(aPartId))
122 #if VTK_XVERSION > 50700
123 if (aCell->GetCellType() != VTK_POLYHEDRON)
125 myUnstructuredGrid->InsertNextCell(aCell->GetCellType(),aCell->GetPointIds());
126 #if VTK_XVERSION > 50700
129 vtkPolyhedron *polyhedron = dynamic_cast<vtkPolyhedron*>(aCell);
131 throw SALOME_Exception(LOCALIZED ("not a polyhedron"));
132 vtkIdType *pts = polyhedron->GetFaces();
133 myUnstructuredGrid->InsertNextCell(aCell->GetCellType(),pts[0], pts+1);
140 if(theMapActor->IsShrunk()){
141 SetShrinkFactor(theMapActor->GetShrinkFactor());
145 myMapIndex = theMapIndex;
150 ::MapPoints(SALOME_Actor* theMapActor,
151 const TColStd_IndexedMapOfInteger& theMapIndex)
153 myUnstructuredGrid->Initialize();
154 myUnstructuredGrid->Allocate();
156 if(int aNbOfParts = theMapIndex.Extent()){
157 vtkPoints *aPoints = vtkPoints::New();
158 aPoints->SetNumberOfPoints(aNbOfParts);
159 for(vtkIdType i = 0; i < aNbOfParts; i++){
160 int aPartId = theMapIndex( i+1 );
161 if(double* aCoord = theMapActor->GetNodeCoord(aPartId)){
162 aPoints->SetPoint(i,aCoord);
163 // Change the type from int to vtkIdType in order to avoid compilation errors while using VTK
164 // from ParaView-3.4.0 compiled on 64-bit Debian platform with VTK_USE_64BIT_IDS = ON
165 myUnstructuredGrid->InsertNextCell(VTK_VERTEX,(vtkIdType) 1,&i);
168 myUnstructuredGrid->SetPoints(aPoints);
174 myMapIndex = theMapIndex;
179 ::MapEdge(SALOME_Actor* theMapActor,
180 const TColStd_IndexedMapOfInteger& theMapIndex)
182 myUnstructuredGrid->Initialize();
183 myUnstructuredGrid->Allocate();
185 vtkUnstructuredGrid * aSourceGrid = (vtkUnstructuredGrid *)theMapActor->GetInput();
186 GetSource()->SetPoints( aSourceGrid->GetPoints() );
189 if(theMapIndex.Extent() == 2){
190 int anEdgeId = theMapIndex(1) < 0 ? theMapIndex(1) : theMapIndex(2);
191 int aCellId = theMapIndex(1) < 0 ? theMapIndex(2) : theMapIndex(1);
194 if(vtkCell* aCell = theMapActor->GetElemCell(aCellId)){
196 anEdgeId = -anEdgeId - 1;
197 int aNbOfEdges = aCell->GetNumberOfEdges();
198 if(0 <= anEdgeId || anEdgeId < aNbOfEdges){
199 if(vtkCell* anEdge = aCell->GetEdge(anEdgeId))
200 myUnstructuredGrid->InsertNextCell(VTK_LINE,anEdge->GetPointIds());
208 if(theMapActor->IsShrunk()){
209 SetShrinkFactor(theMapActor->GetShrinkFactor());
213 myMapIndex = theMapIndex;
217 To publish the actor an all its internal devices
221 ::AddToRender(vtkRenderer* theRenderer)
223 theRenderer->AddActor(this);
228 ::RemoveFromRender(vtkRenderer* theRenderer)
230 theRenderer->RemoveActor(this);