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 "SVTK_Actor.h"
22 #include "VTKViewer_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);
56 //=======================================================================
58 vtkStandardNewMacro(SVTK_Actor);
60 SVTK_Actor::SVTK_Actor()
65 Visibility = Pickable = false;
67 myUnstructuredGrid = vtkUnstructuredGrid::New();
68 myUnstructuredGrid->Allocate();
71 myIsShrinkable = true;
72 myShrinkFilter = vtkShrinkFilter::New();
74 myMapper = vtkDataSetMapper::New();
76 myMapper->SetInput(myUnstructuredGrid);
77 Superclass::InitPipeLine(myMapper);
79 SetResolveCoincidentTopology(false);
82 void SVTK_Actor::SetShrinkFactor(float theValue){
83 myShrinkFilter->SetShrinkFactor(theValue);
87 void SVTK_Actor::SetShrink()
89 if ( !myIsShrinkable ) return;
90 if ( vtkDataSet* aDataSet = myPassFilter[0]->GetOutput() )
92 myShrinkFilter->SetInput( aDataSet );
93 myPassFilter[1]->SetInput( myShrinkFilter->GetOutput() );
98 void SVTK_Actor::UnShrink()
100 if ( !myIsShrunk ) return;
101 if ( vtkDataSet* aDataSet = myPassFilter[0]->GetOutput() )
103 myPassFilter[1]->SetInput( aDataSet );
104 myPassFilter[1]->Modified();
111 //----------------------------------------------------------------------------
112 SVTK_Actor::~SVTK_Actor()
114 //if(MYDEBUG) INFOS("VTKViewer_Actor::~VTKViewer_Actor()");
116 myMapper->RemoveAllInputs();
119 myShrinkFilter->UnRegisterAllOutputs();
120 myShrinkFilter->Delete();
122 myUnstructuredGrid->Delete();
126 //----------------------------------------------------------------------------
127 void SVTK_Actor::MapCells(SALOME_Actor* theMapActor,
128 const TColStd_IndexedMapOfInteger& theMapIndex)
130 myUnstructuredGrid->Reset();
132 vtkDataSet *aSourceDataSet = theMapActor->GetInput();
133 CopyPoints(myUnstructuredGrid,aSourceDataSet);
135 int aNbOfParts = theMapIndex.Extent();
136 for(int ind = 1; ind <= aNbOfParts; ind++){
137 int aPartId = theMapIndex( ind );
138 vtkCell* aCell = theMapActor->GetElemCell(aPartId);
139 myUnstructuredGrid->InsertNextCell(aCell->GetCellType(),aCell->GetPointIds());
140 //for (int i = 0, iEnd = aCell->GetNumberOfEdges(); i < iEnd; i++){
141 // vtkCell* anEdgeCell = aCell->GetEdge(i);
142 // myUnstructuredGrid->InsertNextCell(VTK_LINE,anEdgeCell->GetPointIds());
147 if(theMapActor->IsShrunk()){
148 SetShrinkFactor(theMapActor->GetShrinkFactor());
154 //----------------------------------------------------------------------------
155 void SVTK_Actor::MapPoints(SALOME_Actor* theMapActor,
156 const TColStd_IndexedMapOfInteger& theMapIndex)
158 myUnstructuredGrid->Reset();
159 if(int aNbOfParts = theMapIndex.Extent()){
160 vtkPoints *aPoints = vtkPoints::New();
161 aPoints->SetNumberOfPoints(aNbOfParts);
162 for(int i = 0; i < aNbOfParts; i++){
163 int aPartId = theMapIndex( i+1 );
164 float* aCoord = theMapActor->GetNodeCoord(aPartId);
165 aPoints->SetPoint(i,aCoord);
166 myUnstructuredGrid->InsertNextCell(VTK_VERTEX,1,&i);
168 myUnstructuredGrid->SetPoints(aPoints);
176 //----------------------------------------------------------------------------
177 void SVTK_Actor::MapEdge(SALOME_Actor* theMapActor,
178 const TColStd_IndexedMapOfInteger& theMapIndex)
180 myUnstructuredGrid->Reset();
182 vtkDataSet *aSourceDataSet = theMapActor->GetInput();
183 CopyPoints(myUnstructuredGrid,aSourceDataSet);
185 int iEnd = theMapIndex.Extent();
186 int aCellId = -1, aCellCounter = 0;
187 for(int i = 1; i <= iEnd; i++){
188 int anId = theMapIndex( i );
195 if(aCellCounter == 1){
196 vtkCell* aCell = theMapActor->GetElemCell(aCellId);
197 if(aCell->GetCellType() <= VTK_LINE){
198 myUnstructuredGrid->InsertNextCell(aCell->GetCellType(),aCell->GetPointIds());
200 int aNbOfParts = aCell->GetNumberOfEdges();
201 for(int i = 1; i <= iEnd; i++){
202 int aPartId = theMapIndex(i);
204 aPartId = -aPartId-1;
205 if(0 > aPartId || aPartId >= aNbOfParts) break;
206 vtkCell* anEdgeCell = aCell->GetEdge(aPartId);
207 myUnstructuredGrid->InsertNextCell(VTK_LINE,anEdgeCell->GetPointIds());
212 int aNbOfParts = aSourceDataSet->GetNumberOfCells();
213 for(int i = 1; i <= iEnd; i++){
214 int aPartId = theMapIndex( i );
216 if(aPartId >= aNbOfParts) break;
217 vtkCell* aCell = aSourceDataSet->GetCell(aPartId);
218 myUnstructuredGrid->InsertNextCell(aCell->GetCellType(),aCell->GetPointIds());
224 if(theMapActor->IsShrunk()){
225 SetShrinkFactor(theMapActor->GetShrinkFactor());
230 //----------------------------------------------------------------------------