1 // Copyright (C) 2007-2012 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"
26 #include "SALOME_InteractiveObject.hxx"
29 #include <vtkObjectFactory.h>
30 #include <vtkUnstructuredGrid.h>
31 #include <vtkDataSetMapper.h>
32 #include <vtkRenderer.h>
35 #define VTK_XVERSION (VTK_MAJOR_VERSION*10000+VTK_MINOR_VERSION*100+VTK_BUILD_VERSION)
36 #if VTK_XVERSION > 50700
37 #include <vtkPolyhedron.h>
39 #include <vtkPolyData.h>
41 #include "Utils_SALOME_Exception.hxx"
42 #include "utilities.h"
46 CopyPoints(vtkUnstructuredGrid* theGrid, vtkDataSet *theSourceDataSet)
48 vtkPoints *aPoints = vtkPoints::New();
49 vtkIdType iEnd = theSourceDataSet->GetNumberOfPoints();
50 aPoints->SetNumberOfPoints(iEnd);
51 for(vtkIdType i = 0; i < iEnd; i++){
52 aPoints->SetPoint(i,theSourceDataSet->GetPoint(i));
54 theGrid->SetPoints(aPoints);
58 vtkStandardNewMacro(SVTK_Actor);
65 myUnstructuredGrid(vtkUnstructuredGrid::New())
68 myIsResolveCoincidentTopology = false;
70 Visibility = Pickable = false;
72 myUnstructuredGrid->Delete();
73 myUnstructuredGrid->Allocate();
80 SetInput(GetSource());
85 ::SetSource(vtkUnstructuredGrid* theUnstructuredGrid)
87 if(GetSource() == theUnstructuredGrid)
90 myUnstructuredGrid = theUnstructuredGrid;
92 SetInput(theUnstructuredGrid);
99 return myUnstructuredGrid.GetPointer();
110 const TColStd_IndexedMapOfInteger&
112 ::GetMapIndex() const
119 ::MapCells(SALOME_Actor* theMapActor,
120 const TColStd_IndexedMapOfInteger& theMapIndex)
122 myUnstructuredGrid->Initialize();
123 myUnstructuredGrid->Allocate();
125 vtkDataSet *aSourceDataSet = theMapActor->GetInput();
126 CopyPoints(GetSource(),aSourceDataSet);
128 int aNbOfParts = theMapIndex.Extent();
129 for(int ind = 1; ind <= aNbOfParts; ind++){
130 int aPartId = theMapIndex( ind );
131 if(vtkCell* aCell = theMapActor->GetElemCell(aPartId))
133 #if VTK_XVERSION > 50700
134 if (aCell->GetCellType() != VTK_POLYHEDRON)
136 myUnstructuredGrid->InsertNextCell(aCell->GetCellType(),aCell->GetPointIds());
137 #if VTK_XVERSION > 50700
140 vtkPolyhedron *polyhedron = dynamic_cast<vtkPolyhedron*>(aCell);
142 throw SALOME_Exception(LOCALIZED ("not a polyhedron"));
143 vtkIdType *pts = polyhedron->GetFaces();
144 myUnstructuredGrid->InsertNextCell(aCell->GetCellType(),pts[0], pts+1);
151 if(theMapActor->IsShrunk()){
152 SetShrinkFactor(theMapActor->GetShrinkFactor());
156 myMapIndex = theMapIndex;
161 ::MapPoints(SALOME_Actor* theMapActor,
162 const TColStd_IndexedMapOfInteger& theMapIndex)
164 myUnstructuredGrid->Initialize();
165 myUnstructuredGrid->Allocate();
167 if(int aNbOfParts = theMapIndex.Extent()){
168 vtkPoints *aPoints = vtkPoints::New();
169 aPoints->SetNumberOfPoints(aNbOfParts);
170 for(vtkIdType i = 0; i < aNbOfParts; i++){
171 int aPartId = theMapIndex( i+1 );
172 if(vtkFloatingPointType* aCoord = theMapActor->GetNodeCoord(aPartId)){
173 aPoints->SetPoint(i,aCoord);
174 // Change the type from int to vtkIdType in order to avoid compilation errors while using VTK
175 // from ParaView-3.4.0 compiled on 64-bit Debian platform with VTK_USE_64BIT_IDS = ON
176 myUnstructuredGrid->InsertNextCell(VTK_VERTEX,(vtkIdType) 1,&i);
179 myUnstructuredGrid->SetPoints(aPoints);
185 myMapIndex = theMapIndex;
190 ::MapEdge(SALOME_Actor* theMapActor,
191 const TColStd_IndexedMapOfInteger& theMapIndex)
193 myUnstructuredGrid->Initialize();
194 myUnstructuredGrid->Allocate();
196 vtkDataSet *aSourceDataSet = theMapActor->GetInput();
197 CopyPoints(GetSource(),aSourceDataSet);
200 if(theMapIndex.Extent() == 2){
201 int anEdgeId = theMapIndex(1) < 0 ? theMapIndex(1) : theMapIndex(2);
202 int aCellId = theMapIndex(1) < 0 ? theMapIndex(2) : theMapIndex(1);
205 if(vtkCell* aCell = theMapActor->GetElemCell(aCellId)){
207 anEdgeId = -anEdgeId - 1;
208 int aNbOfEdges = aCell->GetNumberOfEdges();
209 if(0 <= anEdgeId || anEdgeId < aNbOfEdges){
210 if(vtkCell* anEdge = aCell->GetEdge(anEdgeId))
211 myUnstructuredGrid->InsertNextCell(VTK_LINE,anEdge->GetPointIds());
219 if(theMapActor->IsShrunk()){
220 SetShrinkFactor(theMapActor->GetShrinkFactor());
224 myMapIndex = theMapIndex;