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 #include "SVTK_Actor.h"
23 #include "SALOME_Actor.h"
25 #include "SALOME_InteractiveObject.hxx"
28 #include <vtkObjectFactory.h>
29 #include <vtkUnstructuredGrid.h>
30 #include <vtkDataSetMapper.h>
31 #include <vtkRenderer.h>
34 #include <vtkPolyData.h>
41 CopyPoints(vtkUnstructuredGrid* theGrid, vtkDataSet *theSourceDataSet)
43 vtkPoints *aPoints = vtkPoints::New();
44 vtkIdType iEnd = theSourceDataSet->GetNumberOfPoints();
45 aPoints->SetNumberOfPoints(iEnd);
46 for(vtkIdType i = 0; i < iEnd; i++){
47 aPoints->SetPoint(i,theSourceDataSet->GetPoint(i));
49 theGrid->SetPoints(aPoints);
53 vtkStandardNewMacro(SVTK_Actor);
60 myUnstructuredGrid(vtkUnstructuredGrid::New())
63 myIsResolveCoincidentTopology = false;
65 Visibility = Pickable = false;
67 myUnstructuredGrid->Delete();
68 myUnstructuredGrid->Allocate();
75 SetInput(GetSource());
80 ::SetSource(vtkUnstructuredGrid* theUnstructuredGrid)
82 if(GetSource() == theUnstructuredGrid)
85 myUnstructuredGrid = theUnstructuredGrid;
87 SetInput(theUnstructuredGrid);
94 return myUnstructuredGrid.GetPointer();
105 const TColStd_IndexedMapOfInteger&
107 ::GetMapIndex() const
114 ::MapCells(SALOME_Actor* theMapActor,
115 const TColStd_IndexedMapOfInteger& theMapIndex)
117 myUnstructuredGrid->Initialize();
118 myUnstructuredGrid->Allocate();
120 vtkDataSet *aSourceDataSet = theMapActor->GetInput();
121 CopyPoints(GetSource(),aSourceDataSet);
123 int aNbOfParts = theMapIndex.Extent();
124 for(int ind = 1; ind <= aNbOfParts; ind++){
125 int aPartId = theMapIndex( ind );
126 if(vtkCell* aCell = theMapActor->GetElemCell(aPartId))
127 myUnstructuredGrid->InsertNextCell(aCell->GetCellType(),aCell->GetPointIds());
131 if(theMapActor->IsShrunk()){
132 SetShrinkFactor(theMapActor->GetShrinkFactor());
136 myMapIndex = theMapIndex;
141 ::MapPoints(SALOME_Actor* theMapActor,
142 const TColStd_IndexedMapOfInteger& theMapIndex)
144 myUnstructuredGrid->Initialize();
145 myUnstructuredGrid->Allocate();
147 if(int aNbOfParts = theMapIndex.Extent()){
148 vtkPoints *aPoints = vtkPoints::New();
149 aPoints->SetNumberOfPoints(aNbOfParts);
150 for(vtkIdType i = 0; i < aNbOfParts; i++){
151 int aPartId = theMapIndex( i+1 );
152 if(vtkFloatingPointType* aCoord = theMapActor->GetNodeCoord(aPartId)){
153 aPoints->SetPoint(i,aCoord);
154 // Change the type from int to vtkIdType in order to avoid compilation errors while using VTK
155 // from ParaView-3.4.0 compiled on 64-bit Debian platform with VTK_USE_64BIT_IDS = ON
156 myUnstructuredGrid->InsertNextCell(VTK_VERTEX,(vtkIdType) 1,&i);
159 myUnstructuredGrid->SetPoints(aPoints);
165 myMapIndex = theMapIndex;
170 ::MapEdge(SALOME_Actor* theMapActor,
171 const TColStd_IndexedMapOfInteger& theMapIndex)
173 myUnstructuredGrid->Initialize();
174 myUnstructuredGrid->Allocate();
176 vtkDataSet *aSourceDataSet = theMapActor->GetInput();
177 CopyPoints(GetSource(),aSourceDataSet);
180 if(theMapIndex.Extent() == 2){
181 int anEdgeId = theMapIndex(1) < 0 ? theMapIndex(1) : theMapIndex(2);
182 int aCellId = theMapIndex(1) < 0 ? theMapIndex(2) : theMapIndex(1);
185 if(vtkCell* aCell = theMapActor->GetElemCell(aCellId)){
187 anEdgeId = -anEdgeId - 1;
188 int aNbOfEdges = aCell->GetNumberOfEdges();
189 if(0 <= anEdgeId || anEdgeId < aNbOfEdges){
190 if(vtkCell* anEdge = aCell->GetEdge(anEdgeId))
191 myUnstructuredGrid->InsertNextCell(VTK_LINE,anEdge->GetPointIds());
199 if(theMapActor->IsShrunk()){
200 SetShrinkFactor(theMapActor->GetShrinkFactor());
204 myMapIndex = theMapIndex;