1 // Copyright (C) 2007-2015 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, or (at your option) any later version.
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>
42 #include <vtkCellData.h>
44 #include <Utils_SALOME_Exception.hxx>
46 vtkStandardNewMacro(SMESH_SVTKActor);
51 SMESH_SVTKActor::SMESH_SVTKActor():
52 my0DGrid(vtkUnstructuredGrid::New()),
53 myBallGrid(vtkUnstructuredGrid::New())
55 my0DActor = SVTK_DeviceActor::New();
56 myBallActor = SVTK_DeviceActor::New();
57 myBallActor->SetBallEnabled(true);
59 myBallActor->SetResolveCoincidentTopology(false);
60 myBallActor->SetCoincident3DAllowed(true);
61 myBallActor->PickableOff();
62 my0DActor->SetResolveCoincidentTopology(false);
63 my0DActor->SetCoincident3DAllowed(true);
64 my0DActor->PickableOff();
67 myBallGrid->Allocate();
73 SMESH_SVTKActor::~SMESH_SVTKActor() {
75 myBallActor->Delete();
81 Publishes the actor in all its internal devices
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);
97 Removes the actor from all its internal devices
101 ::RemoveFromRender(vtkRenderer* theRenderer)
103 Superclass::RemoveFromRender(theRenderer);
104 theRenderer->RemoveActor( myBallActor );
105 theRenderer->RemoveActor( my0DActor );
110 ::MapCells(SALOME_Actor* theMapActor,
111 const TColStd_IndexedMapOfInteger& theMapIndex)
113 myUnstructuredGrid->Initialize();
114 myUnstructuredGrid->Allocate();
116 my0DGrid->Initialize();
117 my0DGrid->Allocate();
119 myBallGrid->Initialize();
120 myBallGrid->Allocate();
122 vtkDataSet *aSourceDataSet = theMapActor->GetInput();
123 SVTK::CopyPoints( GetSource(), aSourceDataSet );
124 SVTK::CopyPoints( myBallGrid, aSourceDataSet );
125 SVTK::CopyPoints( my0DGrid, aSourceDataSet );
128 int aNbOfParts = theMapIndex.Extent();
131 vtkCellData* outputCD = 0;
132 //Copy deamaters of the balls
134 outputCD = myBallGrid->GetCellData();
135 cd = aSourceDataSet->GetCellData();
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))
142 if (aCell->GetCellType() != VTK_POLYHEDRON)
144 if(aCell->GetCellType() == VTK_VERTEX ) {
145 my0DGrid->InsertNextCell(aCell->GetCellType(),aCell->GetPointIds());
147 else if(aCell->GetCellType() == VTK_POLY_VERTEX ) {
148 vtkIdType newCellId = myBallGrid->InsertNextCell(aCell->GetCellType(),aCell->GetPointIds());
150 outputCD->CopyData(cd, myVisualObj->GetElemVTKId(aPartId), newCellId);
154 myUnstructuredGrid->InsertNextCell(aCell->GetCellType(),aCell->GetPointIds());
159 vtkPolyhedron *polyhedron = dynamic_cast<vtkPolyhedron*>(aCell);
161 throw SALOME_Exception(LOCALIZED ("not a polyhedron"));
162 vtkIdType *pts = polyhedron->GetFaces();
163 myUnstructuredGrid->InsertNextCell(aCell->GetCellType(),pts[0], pts+1);
169 if(theMapActor->IsShrunk()){
170 SetShrinkFactor(theMapActor->GetShrinkFactor());
174 myMapIndex = theMapIndex;
181 Superclass::Initialize();
182 my0DActor->SetInputData(my0DGrid);
183 myBallActor->SetInputData(myBallGrid);
187 void SMESH_SVTKActor::SetVisibility( int theVisibility ) {
188 Superclass::SetVisibility( theVisibility );
189 my0DActor->SetVisibility( theVisibility );
190 myBallActor->SetVisibility( theVisibility );
194 void SMESH_SVTKActor::Set0DSize(float theSize) {
195 my0DActor->GetProperty()->SetPointSize(theSize);
198 void SMESH_SVTKActor::SetBallSize(float theSize) {
199 myBallActor->GetProperty()->SetPointSize(theSize);
202 void SMESH_SVTKActor::SetBallScale(double theScale) {
203 myBallActor->SetBallScale(theScale);
206 void SMESH_SVTKActor::SetVisualObject(TVisualObjPtr theVisualObj) {
207 myVisualObj = theVisualObj;