]> SALOME platform Git repositories - modules/gui.git/blob - src/SVTK/SVTK_Actor.cxx
Salome HOME
Merge from OCC_development_generic_2006
[modules/gui.git] / src / SVTK / SVTK_Actor.cxx
1 //  Copyright (C) 2003  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
2 //  CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
3 //
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.
8 //
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.
13 //
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
17 //
18 //  See http://www.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org
19
20 #include "SVTK_Actor.h"
21 #include "SALOME_Actor.h"
22
23 // VTK Includes
24 #include <vtkObjectFactory.h>
25 #include <vtkUnstructuredGrid.h>
26 #include <vtkDataSetMapper.h>
27 #include <vtkRenderer.h>
28
29 #include <vtkCell.h>
30 #include <vtkPolyData.h>
31
32 using namespace std;
33
34
35 static 
36 void
37 CopyPoints(vtkUnstructuredGrid* theGrid, vtkDataSet *theSourceDataSet)
38 {
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));
44   }
45   theGrid->SetPoints(aPoints);
46   aPoints->Delete();
47 }
48
49 //=======================================================================
50
51 vtkStandardNewMacro(SVTK_Actor);
52
53 SVTK_Actor
54 ::SVTK_Actor():
55   myUnstructuredGrid(vtkUnstructuredGrid::New())
56 {
57   myIsShaded = true;
58
59   Visibility = Pickable = false;
60
61   myUnstructuredGrid->Delete();
62   myUnstructuredGrid->Allocate();
63 }
64
65 //----------------------------------------------------------------------------
66 void
67 SVTK_Actor
68 ::Initialize()
69 {
70   SetInput(GetSource());
71 }
72
73
74 //----------------------------------------------------------------------------
75 void
76 SVTK_Actor
77 ::SetSource(vtkUnstructuredGrid* theUnstructuredGrid)
78 {
79   if(GetSource() == theUnstructuredGrid)
80     return;
81
82   myUnstructuredGrid = theUnstructuredGrid;
83
84   SetInput(theUnstructuredGrid);
85 }
86
87 vtkUnstructuredGrid*
88 SVTK_Actor
89 ::GetSource()
90 {
91   return myUnstructuredGrid.GetPointer();
92 }
93
94
95 //----------------------------------------------------------------------------
96 SVTK_Actor
97 ::~SVTK_Actor()
98 {
99 }
100
101
102 //----------------------------------------------------------------------------
103 const TColStd_IndexedMapOfInteger&
104 SVTK_Actor
105 ::GetMapIndex() const
106 {
107   return myMapIndex;
108 }
109
110
111 //----------------------------------------------------------------------------
112 void
113 SVTK_Actor
114 ::MapCells(SALOME_Actor* theMapActor,
115            const TColStd_IndexedMapOfInteger& theMapIndex)
116 {
117   myUnstructuredGrid->Initialize();
118   myUnstructuredGrid->Allocate();
119
120   vtkDataSet *aSourceDataSet = theMapActor->GetInput();
121   CopyPoints(GetSource(),aSourceDataSet);
122
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());
128   }
129
130   UnShrink();
131   if(theMapActor->IsShrunk()){
132     SetShrinkFactor(theMapActor->GetShrinkFactor());
133     SetShrink();
134   }
135
136   myMapIndex = theMapIndex;
137 }
138
139
140 //----------------------------------------------------------------------------
141 void 
142 SVTK_Actor
143 ::MapPoints(SALOME_Actor* theMapActor,
144             const TColStd_IndexedMapOfInteger& theMapIndex)
145 {
146   myUnstructuredGrid->Initialize();
147   myUnstructuredGrid->Allocate();
148
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);
157       }
158     }
159     myUnstructuredGrid->SetPoints(aPoints);
160     aPoints->Delete();
161   }
162
163   UnShrink();
164
165   myMapIndex = theMapIndex;
166 }
167
168
169 //----------------------------------------------------------------------------
170 void
171 SVTK_Actor
172 ::MapEdge(SALOME_Actor* theMapActor,
173           const TColStd_IndexedMapOfInteger& theMapIndex)
174 {
175   myUnstructuredGrid->Initialize();
176   myUnstructuredGrid->Allocate();
177
178   vtkDataSet *aSourceDataSet = theMapActor->GetInput();
179   CopyPoints(GetSource(),aSourceDataSet);
180
181
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);
185
186     if(aCellId > 0){
187       if(vtkCell* aCell = theMapActor->GetElemCell(aCellId)){
188         if(anEdgeId < 0){
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());
194           }
195         }
196       }
197     }
198   }
199
200   UnShrink();
201   if(theMapActor->IsShrunk()){
202     SetShrinkFactor(theMapActor->GetShrinkFactor());
203     SetShrink();
204   }
205
206   myMapIndex = theMapIndex;
207 }
208
209 //----------------------------------------------------------------------------