1 // Copyright (C) 2007-2024 CEA, EDF, 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 SVTK_TIndexedMapOfVtkId&
101 ::GetMapIndex() const
107 const SVTK_IndexedMapOfVtkIds&
109 ::GetMapCompositeIndex() const
111 return myMapCompositeIndex;
116 ::MapCells(SALOME_Actor* theMapActor,
117 const SVTK_TIndexedMapOfVtkId& theMapIndex)
119 myUnstructuredGrid->Initialize();
120 myUnstructuredGrid->Allocate();
122 vtkUnstructuredGrid * aSourceGrid = (vtkUnstructuredGrid *)theMapActor->GetInput();
123 GetSource()->SetPoints( aSourceGrid->GetPoints() );
125 int aNbOfParts = theMapIndex.Extent();
126 for(int ind = 1; ind <= aNbOfParts; ind++){
127 int aPartId = theMapIndex( ind );
128 if(vtkCell* aCell = theMapActor->GetElemCell(aPartId))
130 #if VTK_XVERSION > 50700
131 if (aCell->GetCellType() != VTK_POLYHEDRON)
133 myUnstructuredGrid->InsertNextCell(aCell->GetCellType(),aCell->GetPointIds());
134 #if VTK_XVERSION > 50700
137 vtkPolyhedron *polyhedron = dynamic_cast<vtkPolyhedron*>(aCell);
139 throw SALOME_Exception(LOCALIZED ("not a polyhedron"));
140 vtkIdType *pts = polyhedron->GetFaces();
141 myUnstructuredGrid->InsertNextCell(aCell->GetCellType(),pts[0], pts+1);
148 if(theMapActor->IsShrunk()){
149 SetShrinkFactor(theMapActor->GetShrinkFactor());
153 myMapIndex = theMapIndex;
158 ::MapPoints(SALOME_Actor* theMapActor,
159 const SVTK_TIndexedMapOfVtkId& theMapIndex)
161 myUnstructuredGrid->Initialize();
162 myUnstructuredGrid->Allocate();
164 if(int aNbOfParts = theMapIndex.Extent()){
165 vtkPoints *aPoints = vtkPoints::New();
166 aPoints->SetNumberOfPoints(aNbOfParts);
167 for(vtkIdType i = 0; i < aNbOfParts; i++){
168 vtkIdType aPartId = theMapIndex( i+1 );
169 if(double* aCoord = theMapActor->GetNodeCoord(aPartId)){
170 aPoints->SetPoint(i,aCoord);
171 // Change the type from int to vtkIdType in order to avoid compilation errors while using VTK
172 // from ParaView-3.4.0 compiled on 64-bit Debian platform with VTK_USE_64BIT_IDS = ON
173 myUnstructuredGrid->InsertNextCell(VTK_VERTEX,(vtkIdType) 1,&i);
176 myUnstructuredGrid->SetPoints(aPoints);
182 myMapIndex = theMapIndex;
187 ::MapEdge(SALOME_Actor* theMapActor,
188 const SVTK_TIndexedMapOfVtkId& theMapIndex)
190 myUnstructuredGrid->Initialize();
191 myUnstructuredGrid->Allocate();
193 vtkUnstructuredGrid * aSourceGrid = (vtkUnstructuredGrid *)theMapActor->GetInput();
194 GetSource()->SetPoints( aSourceGrid->GetPoints() );
197 if(theMapIndex.Extent() == 2){
198 int anEdgeId = theMapIndex(1) < 0 ? theMapIndex(1) : theMapIndex(2);
199 int aCellId = theMapIndex(1) < 0 ? theMapIndex(2) : theMapIndex(1);
202 if(vtkCell* aCell = theMapActor->GetElemCell(aCellId)){
204 anEdgeId = -anEdgeId - 1;
205 int aNbOfEdges = aCell->GetNumberOfEdges();
206 if(0 <= anEdgeId || anEdgeId < aNbOfEdges){
207 if(vtkCell* anEdge = aCell->GetEdge(anEdgeId))
208 myUnstructuredGrid->InsertNextCell(VTK_LINE,anEdge->GetPointIds());
216 if(theMapActor->IsShrunk()){
217 SetShrinkFactor(theMapActor->GetShrinkFactor());
221 myMapIndex = theMapIndex;
226 ::MapEdge( SALOME_Actor* theMapActor,
227 const SVTK_IndexedMapOfVtkIds& theMapCompositeIndex) {
228 myUnstructuredGrid->Initialize();
229 myUnstructuredGrid->Allocate();
231 vtkUnstructuredGrid * aSourceGrid = ( vtkUnstructuredGrid * )theMapActor->GetInput();
232 GetSource()->SetPoints( aSourceGrid->GetPoints() );
234 vtkIdType aNbOfParts = theMapCompositeIndex.Extent();
235 for(vtkIdType ind = 1; ind <= aNbOfParts; ind++){
236 std::vector<vtkIdType> aNodesIds = theMapCompositeIndex( ind );
237 vtkSmartPointer<vtkIdList> ids = vtkSmartPointer<vtkIdList>::New();
238 ids->InsertNextId(theMapActor->GetNodeVtkId( aNodesIds[0] ) );
239 ids->InsertNextId(theMapActor->GetNodeVtkId( aNodesIds[1] ) );
240 myUnstructuredGrid->InsertNextCell(VTK_LINE,ids);
244 if(theMapActor->IsShrunk()){
245 SetShrinkFactor(theMapActor->GetShrinkFactor());
249 myMapCompositeIndex = theMapCompositeIndex;
253 To publish the actor an all its internal devices
257 ::AddToRender(vtkRenderer* theRenderer)
259 theRenderer->AddActor(this);
264 ::RemoveFromRender(vtkRenderer* theRenderer)
266 theRenderer->RemoveActor(this);