]> SALOME platform Git repositories - modules/visu.git/blob - src/OBJECT/VISU_MeshAct.cxx
Salome HOME
b6b812d9f569abfbc9a91fcdce4cde1dedfb733c
[modules/visu.git] / src / OBJECT / VISU_MeshAct.cxx
1 //  VISU OBJECT : interactive object for VISU entities implementation
2 //
3 //  Copyright (C) 2003  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 //  CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
5 //
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.
10 //
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.
15 //
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
19 //
20 //  See http://www.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org
21 //
22 //
23 //
24 //  File   : VISU_MeshAct.cxx
25 //  Author : 
26 //  Module : VISU
27 //  $Header$
28
29 #include "VISU_MeshAct.h"
30 #include "SVTK_DeviceActor.h"
31
32 #include <vtkObjectFactory.h>
33 #include <vtkRenderer.h>
34 #include <vtkTexture.h>
35
36 #include <vtkFeatureEdges.h>
37 #include <vtkDataSetMapper.h>
38 #include <vtkDataSet.h>
39 #include <vtkMatrix4x4.h>
40 #include <vtkMapperCollection.h>
41
42
43 //----------------------------------------------------------------------------
44 vtkStandardNewMacro(VISU_MeshAct);
45
46
47 //----------------------------------------------------------------------------
48 VISU_MeshAct
49 ::VISU_MeshAct()
50 {
51   vtkMatrix4x4 *m;
52   m = vtkMatrix4x4::New();
53
54   mySurfaceActor = SVTK_DeviceActor::New();
55   mySurfaceActor->SetRepresentation(SVTK::Representation::Surface);
56   mySurfaceActor->SetUserMatrix(m);
57
58   myEdgeActor = SVTK_DeviceActor::New();
59   myEdgeActor->SetRepresentation(SVTK::Representation::Wireframe);
60   myEdgeActor->SetUserMatrix(m);
61
62   myNodeActor = SVTK_DeviceActor::New();
63   myNodeActor->SetRepresentation(SVTK::Representation::Points);
64   myNodeActor->SetUserMatrix(m);
65
66   m->Delete();
67   SetRepresentation(SVTK::Representation::Surface);
68 }
69
70 VISU_MeshAct
71 ::~VISU_MeshAct()
72 {
73   mySurfaceActor->Delete();
74   myEdgeActor->Delete();
75   myNodeActor->Delete();
76 }
77
78
79 //----------------------------------------------------------------------------
80 void
81 VISU_MeshAct
82 ::SetMapperInput(vtkDataSet* theDataSet)
83 {
84   Superclass::SetMapperInput(theDataSet);
85
86   mySurfaceActor->SetInput(theDataSet);
87   myEdgeActor->SetInput(theDataSet);
88   myNodeActor->SetInput(theDataSet);
89 }
90
91
92 //----------------------------------------------------------------------------
93 void
94 VISU_MeshAct
95 ::SetTransform(VTKViewer_Transform* theTransform)
96 {
97   Superclass::SetTransform(theTransform);
98
99   mySurfaceActor->SetTransform(theTransform);
100   myEdgeActor->SetTransform(theTransform);
101   myNodeActor->SetTransform(theTransform);
102 }
103
104
105 //----------------------------------------------------------------------------
106 void
107 VISU_MeshAct
108 ::SetShrinkable(bool theIsShrinkable)
109 {
110   Superclass::SetShrinkable(theIsShrinkable);
111
112   mySurfaceActor->SetShrinkable(theIsShrinkable);
113   myEdgeActor->SetShrinkable(theIsShrinkable);
114 }
115
116 void
117 VISU_MeshAct
118 ::SetShrinkFactor(float theValue)
119 {
120   Superclass::SetShrinkFactor(theValue);
121
122   mySurfaceActor->SetShrinkFactor(theValue);
123   myEdgeActor->SetShrinkFactor(theValue);
124 }
125
126
127 //----------------------------------------------------------------------------
128 vtkProperty* 
129 VISU_MeshAct
130 ::GetSurfaceProperty()
131 {
132   return mySurfaceActor->GetProperty();
133 }
134
135 vtkProperty* 
136 VISU_MeshAct
137 ::GetEdgeProperty()
138 {
139   return myEdgeActor->GetProperty();
140 }
141
142 vtkProperty* 
143 VISU_MeshAct
144 ::GetNodeProperty()
145 {
146   return myNodeActor->GetProperty();
147 }
148
149 //----------------------------------------------------------------------------
150 void
151 VISU_MeshAct
152 ::SetOpacity(float theValue)
153 {
154   GetSurfaceProperty()->SetOpacity(theValue);
155 }
156
157 float
158 VISU_MeshAct
159 ::GetOpacity()
160 {
161   return GetSurfaceProperty()->GetOpacity();
162 }
163
164 //----------------------------------------------------------------------------
165 void
166 VISU_MeshAct
167 ::SetLineWidth(float theLineWidth)
168 {
169   GetEdgeProperty()->SetLineWidth(theLineWidth);
170 }
171
172 float
173 VISU_MeshAct::GetLineWidth()
174 {
175   return GetEdgeProperty()->GetLineWidth();
176 }
177
178 //----------------------------------------------------------------------------
179 void
180 VISU_MeshAct
181 ::SetShrink()
182 {
183   if(myRepresentation == VTK_POINTS)
184     return;
185
186   Superclass::SetShrink();
187
188   mySurfaceActor->SetShrink();
189   myEdgeActor->SetShrink();
190 }
191
192 void
193 VISU_MeshAct
194 ::UnShrink()
195 {
196   Superclass::UnShrink();
197
198   mySurfaceActor->UnShrink();
199   myEdgeActor->UnShrink();
200 }
201
202
203 //----------------------------------------------------------------------------
204 void 
205 VISU_MeshAct
206 ::SetRepresentation(int theMode)
207 {
208   Superclass::SetRepresentation(theMode);
209
210   if(theMode == SVTK::Representation::Insideframe)
211     myEdgeActor->SetRepresentation(SVTK::Representation::Insideframe);
212   else
213     myEdgeActor->SetRepresentation(SVTK::Representation::Wireframe);
214 }
215
216 //----------------------------------------------------------------------------
217 int
218 VISU_MeshAct
219 ::RenderOpaqueGeometry(vtkViewport *ren)
220 {
221   GetMatrix(myNodeActor->GetUserMatrix());
222   GetMatrix(myEdgeActor->GetUserMatrix());
223   GetMatrix(mySurfaceActor->GetUserMatrix());
224
225   using namespace SVTK::Representation;
226   switch(GetRepresentation()){
227   case Points : 
228     myNodeActor->RenderOpaqueGeometry(ren);
229     break;
230   case Wireframe : 
231   case Insideframe : 
232     myEdgeActor->RenderOpaqueGeometry(ren);
233     break;
234   case Surface : 
235     mySurfaceActor->RenderOpaqueGeometry(ren);
236     break;
237   case Surfaceframe : 
238     mySurfaceActor->RenderOpaqueGeometry(ren);
239     myEdgeActor->RenderOpaqueGeometry(ren);
240     break;
241   }
242   return 1;
243 }
244
245 int
246 VISU_MeshAct
247 ::RenderTranslucentGeometry(vtkViewport *ren)
248 {
249   GetMatrix(myNodeActor->GetUserMatrix());
250   GetMatrix(myEdgeActor->GetUserMatrix());
251   GetMatrix(mySurfaceActor->GetUserMatrix());
252
253   using namespace SVTK::Representation;
254   switch(GetRepresentation()){
255   case Points : 
256     myNodeActor->RenderTranslucentGeometry(ren);
257     break;
258   case Wireframe : 
259   case Insideframe : 
260     myEdgeActor->RenderTranslucentGeometry(ren);
261     break;
262   case Surface : 
263     mySurfaceActor->RenderTranslucentGeometry(ren);
264     break;
265   case Surfaceframe : 
266     mySurfaceActor->RenderTranslucentGeometry(ren);
267     myEdgeActor->RenderTranslucentGeometry(ren);
268     break;
269   }
270   return 1;
271 }