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 //=======================================================================
51 vtkStandardNewMacro(SVTK_Actor);
55 myUnstructuredGrid(vtkUnstructuredGrid::New())
59 Visibility = Pickable = false;
61 myUnstructuredGrid->Delete();
62 myUnstructuredGrid->Allocate();
65 //----------------------------------------------------------------------------
70 SetInput(GetSource());
74 //----------------------------------------------------------------------------
77 ::SetSource(vtkUnstructuredGrid* theUnstructuredGrid)
79 if(GetSource() == theUnstructuredGrid)
82 myUnstructuredGrid = theUnstructuredGrid;
84 SetInput(theUnstructuredGrid);
91 return myUnstructuredGrid.GetPointer();
95 //----------------------------------------------------------------------------
102 //----------------------------------------------------------------------------
103 const TColStd_IndexedMapOfInteger&
105 ::GetMapIndex() const
111 //----------------------------------------------------------------------------
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;
140 //----------------------------------------------------------------------------
143 ::MapPoints(SALOME_Actor* theMapActor,
144 const TColStd_IndexedMapOfInteger& theMapIndex)
146 myUnstructuredGrid->Initialize();
147 myUnstructuredGrid->Allocate();
149 if(int aNbOfParts = theMapIndex.Extent()){
150 vtkPoints *aPoints = vtkPoints::New();
151 aPoints->SetNumberOfPoints(aNbOfParts);
152 for(int i = 0; i < aNbOfParts; i++){
153 int aPartId = theMapIndex( i+1 );
154 if(float* aCoord = theMapActor->GetNodeCoord(aPartId)){
155 aPoints->SetPoint(i,aCoord);
156 myUnstructuredGrid->InsertNextCell(VTK_VERTEX,1,&i);
159 myUnstructuredGrid->SetPoints(aPoints);
165 myMapIndex = theMapIndex;
169 //----------------------------------------------------------------------------
172 ::MapEdge(SALOME_Actor* theMapActor,
173 const TColStd_IndexedMapOfInteger& theMapIndex)
175 myUnstructuredGrid->Initialize();
176 myUnstructuredGrid->Allocate();
178 vtkDataSet *aSourceDataSet = theMapActor->GetInput();
179 CopyPoints(GetSource(),aSourceDataSet);
182 if(theMapIndex.Extent() == 2){
183 int anEdgeId = theMapIndex(1) < 0 ? theMapIndex(1) : theMapIndex(2);
184 int aCellId = theMapIndex(1) < 0 ? theMapIndex(2) : theMapIndex(1);
187 if(vtkCell* aCell = theMapActor->GetElemCell(aCellId)){
189 anEdgeId = -anEdgeId - 1;
190 int aNbOfEdges = aCell->GetNumberOfEdges();
191 if(0 <= anEdgeId || anEdgeId < aNbOfEdges){
192 if(vtkCell* anEdge = aCell->GetEdge(anEdgeId))
193 myUnstructuredGrid->InsertNextCell(VTK_LINE,anEdge->GetPointIds());
201 if(theMapActor->IsShrunk()){
202 SetShrinkFactor(theMapActor->GetShrinkFactor());
206 myMapIndex = theMapIndex;
209 //----------------------------------------------------------------------------