]> SALOME platform Git repositories - modules/smesh.git/blob - src/OBJECT/SMESH_SVTKActor.cxx
Salome HOME
Merge branch 'master' into V7_5_BR
[modules/smesh.git] / src / OBJECT / SMESH_SVTKActor.cxx
1 // Copyright (C) 2007-2014  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, or (at your option) any later version.
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 #include <SVTK_DeviceActor.h>
35 #include <vtkPoints.h>
36 #include <vtkRenderer.h>
37 #include <vtkObjectFactory.h>
38 #include <vtkUnstructuredGrid.h>
39 #include <vtkCell.h>
40 #include <vtkDataSetMapper.h>
41 #include <vtkPolyhedron.h>
42 #include <vtkCellData.h>
43
44 #include <Utils_SALOME_Exception.hxx>
45
46 vtkStandardNewMacro(SMESH_SVTKActor);
47
48 /*!
49   Constructor
50 */
51 SMESH_SVTKActor::SMESH_SVTKActor():
52   my0DGrid(vtkUnstructuredGrid::New()),
53   myBallGrid(vtkUnstructuredGrid::New())
54 {
55   my0DActor = SVTK_DeviceActor::New();
56   myBallActor = SVTK_DeviceActor::New();
57   myBallActor->SetBallEnabled(true);
58
59   myBallActor->SetResolveCoincidentTopology(false);
60   myBallActor->SetCoincident3DAllowed(true);
61   myBallActor->PickableOff();
62   my0DActor->SetResolveCoincidentTopology(false);
63   my0DActor->SetCoincident3DAllowed(true);
64   my0DActor->PickableOff();
65
66   my0DGrid->Allocate();
67   myBallGrid->Allocate();
68 }
69
70 /*!
71   Constructor
72 */
73 SMESH_SVTKActor::~SMESH_SVTKActor() {
74   my0DActor->Delete();
75   myBallActor->Delete();
76   my0DGrid->Delete();
77   myBallGrid->Delete();
78 }
79
80 /*!
81   Publishes the actor in all its internal devices
82 */
83 void SMESH_SVTKActor::AddToRender(vtkRenderer* theRenderer) {
84   Superclass::AddToRender(theRenderer);
85   float a0D = my0DActor->GetProperty()->GetPointSize();
86   float aBall = myBallActor->GetProperty()->GetPointSize();
87   my0DActor->GetProperty()->DeepCopy(GetProperty());
88   myBallActor->GetProperty()->DeepCopy(GetProperty());
89   my0DActor->GetProperty()->SetPointSize(a0D);
90   myBallActor->GetProperty()->SetPointSize(aBall);
91   theRenderer->AddActor(my0DActor);
92   theRenderer->AddActor(myBallActor);
93   
94 }
95
96 /*!
97   Removes the actor from all its internal devices
98 */
99 void 
100 SMESH_SVTKActor
101 ::RemoveFromRender(vtkRenderer* theRenderer)
102 {
103   Superclass::RemoveFromRender(theRenderer);
104   theRenderer->RemoveActor( myBallActor );
105   theRenderer->RemoveActor( my0DActor );
106 }
107
108 void
109 SMESH_SVTKActor
110 ::MapCells(SALOME_Actor* theMapActor,
111            const TColStd_IndexedMapOfInteger& theMapIndex)
112 {
113   myUnstructuredGrid->Initialize();
114   myUnstructuredGrid->Allocate();
115
116   my0DGrid->Initialize();
117   my0DGrid->Allocate();
118
119   myBallGrid->Initialize();
120   myBallGrid->Allocate();
121
122   vtkDataSet *aSourceDataSet = theMapActor->GetInput();
123   SVTK::CopyPoints( GetSource(), aSourceDataSet );
124   SVTK::CopyPoints( myBallGrid, aSourceDataSet );
125   SVTK::CopyPoints( my0DGrid,    aSourceDataSet );
126   
127
128   int aNbOfParts = theMapIndex.Extent();
129
130   vtkCellData* cd = 0;
131   vtkCellData* outputCD = 0;
132   //Copy deamaters of the balls
133   if(myVisualObj) {
134     outputCD = myBallGrid->GetCellData();
135     cd = aSourceDataSet->GetCellData();
136   }
137   outputCD->CopyAllocate(cd,aNbOfParts,aNbOfParts/2);
138   for(int ind = 1; ind <= aNbOfParts; ind++){
139     int aPartId = theMapIndex( ind );
140     if(vtkCell* aCell = theMapActor->GetElemCell(aPartId))
141     {
142       if (aCell->GetCellType() != VTK_POLYHEDRON)
143       {
144         if(aCell->GetCellType() == VTK_VERTEX ) {
145           my0DGrid->InsertNextCell(aCell->GetCellType(),aCell->GetPointIds());
146         } else if(aCell->GetCellType() == VTK_POLY_VERTEX ) {
147           vtkIdType newCellId = myBallGrid->InsertNextCell(aCell->GetCellType(),aCell->GetPointIds());
148           if(myVisualObj) {
149             outputCD->CopyData(cd, myVisualObj->GetElemVTKId(aPartId), newCellId);
150           }
151         } else {
152           myUnstructuredGrid->InsertNextCell(aCell->GetCellType(),aCell->GetPointIds());
153         }
154       }
155       else
156       {
157         vtkPolyhedron *polyhedron = dynamic_cast<vtkPolyhedron*>(aCell);
158         if (!polyhedron)
159           throw SALOME_Exception(LOCALIZED ("not a polyhedron"));
160         vtkIdType *pts = polyhedron->GetFaces();
161         myUnstructuredGrid->InsertNextCell(aCell->GetCellType(),pts[0], pts+1);
162       }
163     }
164   }
165
166   UnShrink();
167   if(theMapActor->IsShrunk()){
168     SetShrinkFactor(theMapActor->GetShrinkFactor());
169     SetShrink();
170   }
171
172   myMapIndex = theMapIndex;
173 }
174
175 void
176 SMESH_SVTKActor
177 ::Initialize()
178 {
179   Superclass::Initialize();
180   my0DActor->SetInputData(my0DGrid);
181   myBallActor->SetInputData(myBallGrid);
182 }
183
184
185 void SMESH_SVTKActor::SetVisibility( int theVisibility ) {
186   Superclass::SetVisibility( theVisibility );  
187   my0DActor->SetVisibility( theVisibility );
188   myBallActor->SetVisibility( theVisibility );
189 }
190
191
192 void SMESH_SVTKActor::Set0DSize(float theSize) {
193   my0DActor->GetProperty()->SetPointSize(theSize);  
194 }
195
196 void SMESH_SVTKActor::SetBallSize(float theSize) {
197   myBallActor->GetProperty()->SetPointSize(theSize);
198 }
199
200 void SMESH_SVTKActor::SetVisualObject(TVisualObjPtr theVisualObj) {
201   myVisualObj = theVisualObj;
202 }
203