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>
35 #include <SVTK_DeviceActor.h>
36 #include <vtkPoints.h>
37 #include <vtkRenderer.h>
38 #include <vtkObjectFactory.h>
39 #include <vtkUnstructuredGrid.h>
41 #include <vtkDataSetMapper.h>
43 vtkStandardNewMacro(SMESH_SVTKActor);
48 SMESH_SVTKActor::SMESH_SVTKActor():
49 my0DGrid(vtkUnstructuredGrid::New()),
50 myBallGrid(vtkUnstructuredGrid::New())
52 my0DActor = SVTK_DeviceActor::New();
53 myBallActor = SVTK_DeviceActor::New();
55 myBallActor->SetResolveCoincidentTopology(false);
56 myBallActor->SetCoincident3DAllowed(true);
57 myBallActor->PickableOff();
58 my0DActor->SetResolveCoincidentTopology(false);
59 my0DActor->SetCoincident3DAllowed(true);
60 my0DActor->PickableOff();
63 myBallGrid->Allocate();
69 SMESH_SVTKActor::~SMESH_SVTKActor() {
71 myBallActor->Delete();
77 Publishes the actor in all its internal devices
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);
93 Removes the actor from all its internal devices
97 ::RemoveFromRender(vtkRenderer* theRenderer)
99 Superclass::RemoveFromRender(theRenderer);
100 theRenderer->RemoveActor( myBallActor );
101 theRenderer->RemoveActor( my0DActor );
106 ::MapCells(SALOME_Actor* theMapActor,
107 const TColStd_IndexedMapOfInteger& theMapIndex)
109 myUnstructuredGrid->Initialize();
110 myUnstructuredGrid->Allocate();
112 my0DGrid->Initialize();
113 my0DGrid->Allocate();
115 myBallGrid->Initialize();
116 myBallGrid->Allocate();
118 vtkDataSet *aSourceDataSet = theMapActor->GetInput();
119 SVTK::CopyPoints( GetSource(), aSourceDataSet );
120 SVTK::CopyPoints( myBallGrid, aSourceDataSet );
121 SVTK::CopyPoints( my0DGrid, aSourceDataSet );
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))
128 #if VTK_XVERSION > 50700
129 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());
140 #if VTK_XVERSION > 50700
143 vtkPolyhedron *polyhedron = dynamic_cast<vtkPolyhedron*>(aCell);
145 throw SALOME_Exception(LOCALIZED ("not a polyhedron"));
146 vtkIdType *pts = polyhedron->GetFaces();
147 myUnstructuredGrid->InsertNextCell(aCell->GetCellType(),pts[0], pts+1);
154 if(theMapActor->IsShrunk()){
155 SetShrinkFactor(theMapActor->GetShrinkFactor());
159 myMapIndex = theMapIndex;
166 Superclass::Initialize();
167 my0DActor->SetInputData(my0DGrid);
168 myBallActor->SetInputData(myBallGrid);
172 void SMESH_SVTKActor::SetVisibility( int theVisibility ) {
173 Superclass::SetVisibility( theVisibility );
174 my0DActor->SetVisibility( theVisibility );
175 myBallActor->SetVisibility( theVisibility );
179 void SMESH_SVTKActor::Set0DSize(float theSize) {
180 my0DActor->GetProperty()->SetPointSize(theSize);
183 void SMESH_SVTKActor::SetBallSize(float theSize) {
184 myBallActor->GetProperty()->SetPointSize(theSize);