1 // Copyright (C) 2003 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
2 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
4 // This library is free software; you can redistribute it and/or
5 // modify it under the terms of the GNU Lesser General Public
6 // License as published by the Free Software Foundation; either
7 // version 2.1 of the License.
9 // This library is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 // Lesser General Public License for more details.
14 // You should have received a copy of the GNU Lesser General Public
15 // License along with this library; if not, write to the Free Software
16 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 // See http://www.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org
20 #include "SVTK_Actor.h"
21 #include "SALOME_Actor.h"
24 #include <vtkObjectFactory.h>
25 #include <vtkUnstructuredGrid.h>
26 #include <vtkDataSetMapper.h>
27 #include <vtkRenderer.h>
30 #include <vtkPolyData.h>
37 CopyPoints(vtkUnstructuredGrid* theGrid, vtkDataSet *theSourceDataSet)
39 vtkPoints *aPoints = vtkPoints::New();
40 vtkIdType iEnd = theSourceDataSet->GetNumberOfPoints();
41 aPoints->SetNumberOfPoints(iEnd);
42 for(vtkIdType i = 0; i < iEnd; i++){
43 aPoints->SetPoint(i,theSourceDataSet->GetPoint(i));
45 theGrid->SetPoints(aPoints);
49 vtkStandardNewMacro(SVTK_Actor);
56 myUnstructuredGrid(vtkUnstructuredGrid::New())
60 Visibility = Pickable = false;
62 myUnstructuredGrid->Delete();
63 myUnstructuredGrid->Allocate();
70 SetInput(GetSource());
75 ::SetSource(vtkUnstructuredGrid* theUnstructuredGrid)
77 if(GetSource() == theUnstructuredGrid)
80 myUnstructuredGrid = theUnstructuredGrid;
82 SetInput(theUnstructuredGrid);
89 return myUnstructuredGrid.GetPointer();
100 const TColStd_IndexedMapOfInteger&
102 ::GetMapIndex() const
109 ::MapCells(SALOME_Actor* theMapActor,
110 const TColStd_IndexedMapOfInteger& theMapIndex)
112 myUnstructuredGrid->Initialize();
113 myUnstructuredGrid->Allocate();
115 vtkDataSet *aSourceDataSet = theMapActor->GetInput();
116 CopyPoints(GetSource(),aSourceDataSet);
118 int aNbOfParts = theMapIndex.Extent();
119 for(int ind = 1; ind <= aNbOfParts; ind++){
120 int aPartId = theMapIndex( ind );
121 if(vtkCell* aCell = theMapActor->GetElemCell(aPartId))
122 myUnstructuredGrid->InsertNextCell(aCell->GetCellType(),aCell->GetPointIds());
126 if(theMapActor->IsShrunk()){
127 SetShrinkFactor(theMapActor->GetShrinkFactor());
131 myMapIndex = theMapIndex;
136 ::MapPoints(SALOME_Actor* theMapActor,
137 const TColStd_IndexedMapOfInteger& theMapIndex)
139 myUnstructuredGrid->Initialize();
140 myUnstructuredGrid->Allocate();
142 if(int aNbOfParts = theMapIndex.Extent()){
143 vtkPoints *aPoints = vtkPoints::New();
144 aPoints->SetNumberOfPoints(aNbOfParts);
145 for(int i = 0; i < aNbOfParts; i++){
146 int aPartId = theMapIndex( i+1 );
147 if(vtkFloatingPointType* aCoord = theMapActor->GetNodeCoord(aPartId)){
148 aPoints->SetPoint(i,aCoord);
149 myUnstructuredGrid->InsertNextCell(VTK_VERTEX,1,&i);
152 myUnstructuredGrid->SetPoints(aPoints);
158 myMapIndex = theMapIndex;
163 ::MapEdge(SALOME_Actor* theMapActor,
164 const TColStd_IndexedMapOfInteger& theMapIndex)
166 myUnstructuredGrid->Initialize();
167 myUnstructuredGrid->Allocate();
169 vtkDataSet *aSourceDataSet = theMapActor->GetInput();
170 CopyPoints(GetSource(),aSourceDataSet);
173 if(theMapIndex.Extent() == 2){
174 int anEdgeId = theMapIndex(1) < 0 ? theMapIndex(1) : theMapIndex(2);
175 int aCellId = theMapIndex(1) < 0 ? theMapIndex(2) : theMapIndex(1);
178 if(vtkCell* aCell = theMapActor->GetElemCell(aCellId)){
180 anEdgeId = -anEdgeId - 1;
181 int aNbOfEdges = aCell->GetNumberOfEdges();
182 if(0 <= anEdgeId || anEdgeId < aNbOfEdges){
183 if(vtkCell* anEdge = aCell->GetEdge(anEdgeId))
184 myUnstructuredGrid->InsertNextCell(VTK_LINE,anEdge->GetPointIds());
192 if(theMapActor->IsShrunk()){
193 SetShrinkFactor(theMapActor->GetShrinkFactor());
197 myMapIndex = theMapIndex;