]> SALOME platform Git repositories - modules/smesh.git/blob - src/OBJECT/SMESH_SVTKActor.cxx
Salome HOME
0022100: EDF 2413 SMESH: Take into account TRIA7
[modules/smesh.git] / src / OBJECT / SMESH_SVTKActor.cxx
1 // Copyright (C) 2007-2013  CEA/DEN, EDF R&D, OPEN CASCADE
2 //
3 // Copyright (C) 2003-2007  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.salome-platform.org/ or email : webmaster.salome@opencascade.com
21 //
22
23 //  SMESH OBJECT : interactive object for SMESH visualization
24 //  File   : SMESH_SVTKActor.cxx
25 //  Author : Roman NIKOLAEV
26 //  Module : SMESH
27 //
28
29 #include "SMESH_SVTKActor.h"
30
31 #include <SVTK_Utils.h>
32 #include <SALOME_Actor.h>
33
34
35 #include <SVTK_DeviceActor.h>
36 #include <vtkPoints.h>
37 #include <vtkRenderer.h>
38 #include <vtkObjectFactory.h>
39 #include <vtkUnstructuredGrid.h>
40 #include <vtkCell.h>
41 #include <vtkDataSetMapper.h>
42
43 vtkStandardNewMacro(SMESH_SVTKActor);
44
45 /*!
46   Constructor
47 */
48 SMESH_SVTKActor::SMESH_SVTKActor():
49   my0DGrid(vtkUnstructuredGrid::New()),
50   myBallGrid(vtkUnstructuredGrid::New())
51 {
52   my0DActor = SVTK_DeviceActor::New();
53   myBallActor = SVTK_DeviceActor::New();
54
55   myBallActor->SetResolveCoincidentTopology(false);
56   myBallActor->SetCoincident3DAllowed(true);
57   myBallActor->PickableOff();
58   my0DActor->SetResolveCoincidentTopology(false);
59   my0DActor->SetCoincident3DAllowed(true);
60   my0DActor->PickableOff();
61
62   my0DGrid->Allocate();
63   myBallGrid->Allocate();
64 }
65
66 /*!
67   Constructor
68 */
69 SMESH_SVTKActor::~SMESH_SVTKActor() {
70   my0DActor->Delete();
71   myBallActor->Delete();
72   my0DGrid->Delete();
73   myBallGrid->Delete();
74 }
75
76 /*!
77   Publishes the actor in all its internal devices
78 */
79 void SMESH_SVTKActor::AddToRender(vtkRenderer* theRenderer) {
80   Superclass::AddToRender(theRenderer);
81   float a0D = my0DActor->GetProperty()->GetPointSize();
82   float aBall = myBallActor->GetProperty()->GetPointSize();
83   my0DActor->GetProperty()->DeepCopy(GetProperty());
84   myBallActor->GetProperty()->DeepCopy(GetProperty());
85   my0DActor->GetProperty()->SetPointSize(a0D);
86   myBallActor->GetProperty()->SetPointSize(aBall);
87   theRenderer->AddActor(my0DActor);
88   theRenderer->AddActor(myBallActor);
89   
90 }
91
92 /*!
93   Removes the actor from all its internal devices
94 */
95 void 
96 SMESH_SVTKActor
97 ::RemoveFromRender(vtkRenderer* theRenderer)
98 {
99   Superclass::RemoveFromRender(theRenderer);
100   theRenderer->RemoveActor( myBallActor );
101   theRenderer->RemoveActor( my0DActor );
102 }
103
104 void
105 SMESH_SVTKActor
106 ::MapCells(SALOME_Actor* theMapActor,
107            const TColStd_IndexedMapOfInteger& theMapIndex)
108 {
109   myUnstructuredGrid->Initialize();
110   myUnstructuredGrid->Allocate();
111
112   my0DGrid->Initialize();
113   my0DGrid->Allocate();
114
115   myBallGrid->Initialize();
116   myBallGrid->Allocate();
117
118   vtkDataSet *aSourceDataSet = theMapActor->GetInput();
119   SVTK::CopyPoints( GetSource(), aSourceDataSet );
120   SVTK::CopyPoints( myBallGrid, aSourceDataSet );
121   SVTK::CopyPoints( my0DGrid,    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     {
128 #if VTK_XVERSION > 50700
129       if (aCell->GetCellType() != VTK_POLYHEDRON)
130 #endif
131       {
132         if(aCell->GetCellType() == VTK_VERTEX ) {
133           my0DGrid->InsertNextCell(aCell->GetCellType(),aCell->GetPointIds());
134         } else if(aCell->GetCellType() == VTK_POLY_VERTEX ) {
135           myBallGrid->InsertNextCell(aCell->GetCellType(),aCell->GetPointIds());
136         } else {
137           myUnstructuredGrid->InsertNextCell(aCell->GetCellType(),aCell->GetPointIds());
138         }
139       }
140 #if VTK_XVERSION > 50700
141       else
142       {
143         vtkPolyhedron *polyhedron = dynamic_cast<vtkPolyhedron*>(aCell);
144         if (!polyhedron)
145           throw SALOME_Exception(LOCALIZED ("not a polyhedron"));
146         vtkIdType *pts = polyhedron->GetFaces();
147         myUnstructuredGrid->InsertNextCell(aCell->GetCellType(),pts[0], pts+1);
148       }
149 #endif
150     }
151   }
152
153   UnShrink();
154   if(theMapActor->IsShrunk()){
155     SetShrinkFactor(theMapActor->GetShrinkFactor());
156     SetShrink();
157   }
158
159   myMapIndex = theMapIndex;
160 }
161
162 void
163 SMESH_SVTKActor
164 ::Initialize()
165 {
166   Superclass::Initialize();
167   my0DActor->SetInputData(my0DGrid);
168   myBallActor->SetInputData(myBallGrid);
169 }
170
171
172 void SMESH_SVTKActor::SetVisibility( int theVisibility ) {
173   Superclass::SetVisibility( theVisibility );  
174   my0DActor->SetVisibility( theVisibility );
175   myBallActor->SetVisibility( theVisibility );
176 }
177
178
179 void SMESH_SVTKActor::Set0DSize(float theSize) {
180   my0DActor->GetProperty()->SetPointSize(theSize);  
181 }
182
183 void SMESH_SVTKActor::SetBallSize(float theSize) {
184   myBallActor->GetProperty()->SetPointSize(theSize);
185 }
186