1 // Copyright (C) 2003 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
2 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
4 // This library is free software; you can redistribute it and/or
5 // modify it under the terms of the GNU Lesser General Public
6 // License as published by the Free Software Foundation; either
7 // version 2.1 of the License.
9 // This library is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 // Lesser General Public License for more details.
14 // You should have received a copy of the GNU Lesser General Public
15 // License along with this library; if not, write to the Free Software
16 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 // See http://www.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org
20 #include "VTKViewer_Actor.h"
22 #include "SALOME_PassThroughFilter.h"
25 #include <vtkObjectFactory.h>
26 #include <vtkUnstructuredGrid.h>
27 #include <vtkDataSetMapper.h>
28 #include <vtkRenderer.h>
31 #include <vtkPolyData.h>
32 #include <vtkShrinkFilter.h>
34 #include "utilities.h"
39 static int MYDEBUG = 0;
41 static int MYDEBUG = 0;
45 static void CopyPoints(vtkUnstructuredGrid* theGrid, vtkDataSet *theSourceDataSet){
46 vtkPoints *aPoints = vtkPoints::New();
47 vtkIdType iEnd = theSourceDataSet->GetNumberOfPoints();
48 aPoints->SetNumberOfPoints(iEnd);
49 for(vtkIdType i = 0; i < iEnd; i++){
50 aPoints->SetPoint(i,theSourceDataSet->GetPoint(i));
52 theGrid->SetPoints(aPoints);
57 //=======================================================================
59 vtkStandardNewMacro(VTKViewer_Actor);
61 VTKViewer_Actor::VTKViewer_Actor()
66 Visibility = Pickable = false;
68 myUnstructuredGrid = vtkUnstructuredGrid::New();
69 myUnstructuredGrid->Allocate();
72 myIsShrinkable = true;
73 myShrinkFilter = vtkShrinkFilter::New();
75 myMapper = vtkDataSetMapper::New();
77 myMapper->SetInput(myUnstructuredGrid);
78 Superclass::InitPipeLine(myMapper);
80 SetResolveCoincidentTopology(false);
84 void VTKViewer_Actor::SetShrinkFactor(float theValue){
85 myShrinkFilter->SetShrinkFactor(theValue);
90 void VTKViewer_Actor::SetShrink()
92 if ( !myIsShrinkable ) return;
93 if ( vtkDataSet* aDataSet = myPassFilter[0]->GetOutput() )
95 myShrinkFilter->SetInput( aDataSet );
96 myPassFilter[1]->SetInput( myShrinkFilter->GetOutput() );
101 void VTKViewer_Actor::UnShrink()
103 if ( !myIsShrunk ) return;
104 if ( vtkDataSet* aDataSet = myPassFilter[0]->GetOutput() )
106 myPassFilter[1]->SetInput( aDataSet );
107 myPassFilter[1]->Modified();
114 //----------------------------------------------------------------------------
115 VTKViewer_Actor::~VTKViewer_Actor()
117 if(MYDEBUG) INFOS("VTKViewer_Actor::~VTKViewer_Actor()");
119 myMapper->RemoveAllInputs();
122 myShrinkFilter->UnRegisterAllOutputs();
123 myShrinkFilter->Delete();
125 myUnstructuredGrid->Delete();
129 //----------------------------------------------------------------------------
130 void VTKViewer_Actor::MapCells(SALOME_Actor* theMapActor,
131 const TColStd_IndexedMapOfInteger& theMapIndex)
133 myUnstructuredGrid->Reset();
135 vtkDataSet *aSourceDataSet = theMapActor->GetInput();
136 CopyPoints(myUnstructuredGrid,aSourceDataSet);
138 int aNbOfParts = theMapIndex.Extent();
139 for(int ind = 1; ind <= aNbOfParts; ind++){
140 int aPartId = theMapIndex( ind );
141 vtkCell* aCell = theMapActor->GetElemCell(aPartId);
142 myUnstructuredGrid->InsertNextCell(aCell->GetCellType(),aCell->GetPointIds());
143 //for (int i = 0, iEnd = aCell->GetNumberOfEdges(); i < iEnd; i++){
144 // vtkCell* anEdgeCell = aCell->GetEdge(i);
145 // myUnstructuredGrid->InsertNextCell(VTK_LINE,anEdgeCell->GetPointIds());
150 if(theMapActor->IsShrunk()){
151 SetShrinkFactor(theMapActor->GetShrinkFactor());
157 //----------------------------------------------------------------------------
158 void VTKViewer_Actor::MapPoints(SALOME_Actor* theMapActor,
159 const TColStd_IndexedMapOfInteger& theMapIndex)
161 myUnstructuredGrid->Reset();
162 if(int aNbOfParts = theMapIndex.Extent()){
163 vtkPoints *aPoints = vtkPoints::New();
164 aPoints->SetNumberOfPoints(aNbOfParts);
165 for(int i = 0; i < aNbOfParts; i++){
166 int aPartId = theMapIndex( i+1 );
167 float* aCoord = theMapActor->GetNodeCoord(aPartId);
168 aPoints->SetPoint(i,aCoord);
169 myUnstructuredGrid->InsertNextCell(VTK_VERTEX,1,&i);
171 myUnstructuredGrid->SetPoints(aPoints);
179 //----------------------------------------------------------------------------
180 void VTKViewer_Actor::MapEdge(SALOME_Actor* theMapActor,
181 const TColStd_IndexedMapOfInteger& theMapIndex)
183 myUnstructuredGrid->Reset();
185 vtkDataSet *aSourceDataSet = theMapActor->GetInput();
186 CopyPoints(myUnstructuredGrid,aSourceDataSet);
188 int iEnd = theMapIndex.Extent();
189 int aCellId = -1, aCellCounter = 0;
190 for(int i = 1; i <= iEnd; i++){
191 int anId = theMapIndex( i );
198 if(aCellCounter == 1){
199 vtkCell* aCell = theMapActor->GetElemCell(aCellId);
200 if(aCell->GetCellType() <= VTK_LINE){
201 myUnstructuredGrid->InsertNextCell(aCell->GetCellType(),aCell->GetPointIds());
203 int aNbOfParts = aCell->GetNumberOfEdges();
204 for(int i = 1; i <= iEnd; i++){
205 int aPartId = theMapIndex(i);
207 aPartId = -aPartId-1;
208 if(0 > aPartId || aPartId >= aNbOfParts) break;
209 vtkCell* anEdgeCell = aCell->GetEdge(aPartId);
210 myUnstructuredGrid->InsertNextCell(VTK_LINE,anEdgeCell->GetPointIds());
215 int aNbOfParts = aSourceDataSet->GetNumberOfCells();
216 for(int i = 1; i <= iEnd; i++){
217 int aPartId = theMapIndex( i );
219 if(aPartId >= aNbOfParts) break;
220 vtkCell* aCell = aSourceDataSet->GetCell(aPartId);
221 myUnstructuredGrid->InsertNextCell(aCell->GetCellType(),aCell->GetPointIds());
227 if(theMapActor->IsShrunk()){
228 SetShrinkFactor(theMapActor->GetShrinkFactor());
233 //----------------------------------------------------------------------------