1 // Copyright (C) 2007-2013 CEA/DEN, EDF R&D, OPEN CASCADE
3 // Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
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.
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.
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
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
23 // SMESH OBJECT : interactive object for SMESH visualization
24 // File : SMESH_SVTKActor.cxx
25 // Author : Roman NIKOLAEV
29 #include "SMESH_SVTKActor.h"
31 #include <SVTK_Utils.h>
32 #include <SALOME_Actor.h>
34 #include <SVTK_DeviceActor.h>
35 #include <vtkPoints.h>
36 #include <vtkRenderer.h>
37 #include <vtkObjectFactory.h>
38 #include <vtkUnstructuredGrid.h>
40 #include <vtkDataSetMapper.h>
41 #include <vtkPolyhedron.h>
43 #include <Utils_SALOME_Exception.hxx>
45 vtkStandardNewMacro(SMESH_SVTKActor);
50 SMESH_SVTKActor::SMESH_SVTKActor():
51 my0DGrid(vtkUnstructuredGrid::New()),
52 myBallGrid(vtkUnstructuredGrid::New())
54 my0DActor = SVTK_DeviceActor::New();
55 myBallActor = SVTK_DeviceActor::New();
57 myBallActor->SetResolveCoincidentTopology(false);
58 myBallActor->SetCoincident3DAllowed(true);
59 myBallActor->PickableOff();
60 my0DActor->SetResolveCoincidentTopology(false);
61 my0DActor->SetCoincident3DAllowed(true);
62 my0DActor->PickableOff();
65 myBallGrid->Allocate();
71 SMESH_SVTKActor::~SMESH_SVTKActor() {
73 myBallActor->Delete();
79 Publishes the actor in all its internal devices
81 void SMESH_SVTKActor::AddToRender(vtkRenderer* theRenderer) {
82 Superclass::AddToRender(theRenderer);
83 float a0D = my0DActor->GetProperty()->GetPointSize();
84 float aBall = myBallActor->GetProperty()->GetPointSize();
85 my0DActor->GetProperty()->DeepCopy(GetProperty());
86 myBallActor->GetProperty()->DeepCopy(GetProperty());
87 my0DActor->GetProperty()->SetPointSize(a0D);
88 myBallActor->GetProperty()->SetPointSize(aBall);
89 theRenderer->AddActor(my0DActor);
90 theRenderer->AddActor(myBallActor);
95 Removes the actor from all its internal devices
99 ::RemoveFromRender(vtkRenderer* theRenderer)
101 Superclass::RemoveFromRender(theRenderer);
102 theRenderer->RemoveActor( myBallActor );
103 theRenderer->RemoveActor( my0DActor );
108 ::MapCells(SALOME_Actor* theMapActor,
109 const TColStd_IndexedMapOfInteger& theMapIndex)
111 myUnstructuredGrid->Initialize();
112 myUnstructuredGrid->Allocate();
114 my0DGrid->Initialize();
115 my0DGrid->Allocate();
117 myBallGrid->Initialize();
118 myBallGrid->Allocate();
120 vtkDataSet *aSourceDataSet = theMapActor->GetInput();
121 SVTK::CopyPoints( GetSource(), aSourceDataSet );
122 SVTK::CopyPoints( myBallGrid, aSourceDataSet );
123 SVTK::CopyPoints( my0DGrid, aSourceDataSet );
125 int aNbOfParts = theMapIndex.Extent();
126 for(int ind = 1; ind <= aNbOfParts; ind++){
127 int aPartId = theMapIndex( ind );
128 if(vtkCell* aCell = theMapActor->GetElemCell(aPartId))
130 if (aCell->GetCellType() != VTK_POLYHEDRON)
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());
137 myUnstructuredGrid->InsertNextCell(aCell->GetCellType(),aCell->GetPointIds());
142 vtkPolyhedron *polyhedron = dynamic_cast<vtkPolyhedron*>(aCell);
144 throw SALOME_Exception(LOCALIZED ("not a polyhedron"));
145 vtkIdType *pts = polyhedron->GetFaces();
146 myUnstructuredGrid->InsertNextCell(aCell->GetCellType(),pts[0], pts+1);
152 if(theMapActor->IsShrunk()){
153 SetShrinkFactor(theMapActor->GetShrinkFactor());
157 myMapIndex = theMapIndex;
164 Superclass::Initialize();
165 my0DActor->SetInputData(my0DGrid);
166 myBallActor->SetInputData(myBallGrid);
170 void SMESH_SVTKActor::SetVisibility( int theVisibility ) {
171 Superclass::SetVisibility( theVisibility );
172 my0DActor->SetVisibility( theVisibility );
173 myBallActor->SetVisibility( theVisibility );
177 void SMESH_SVTKActor::Set0DSize(float theSize) {
178 my0DActor->GetProperty()->SetPointSize(theSize);
181 void SMESH_SVTKActor::SetBallSize(float theSize) {
182 myBallActor->GetProperty()->SetPointSize(theSize);