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>
37 static int MYDEBUG = 0;
39 static int MYDEBUG = 0;
43 static void CopyPoints(vtkUnstructuredGrid* theGrid, vtkDataSet *theSourceDataSet){
44 vtkPoints *aPoints = vtkPoints::New();
45 vtkIdType iEnd = theSourceDataSet->GetNumberOfPoints();
46 aPoints->SetNumberOfPoints(iEnd);
47 for(vtkIdType i = 0; i < iEnd; i++){
48 aPoints->SetPoint(i,theSourceDataSet->GetPoint(i));
50 theGrid->SetPoints(aPoints);
54 //=======================================================================
56 vtkStandardNewMacro(SVTK_Actor);
58 SVTK_Actor::SVTK_Actor()
63 Visibility = Pickable = false;
65 myUnstructuredGrid = vtkUnstructuredGrid::New();
66 myUnstructuredGrid->Allocate();
69 myIsShrinkable = true;
70 myShrinkFilter = vtkShrinkFilter::New();
72 myMapper = vtkDataSetMapper::New();
74 myMapper->SetInput(myUnstructuredGrid);
75 Superclass::InitPipeLine(myMapper);
77 SetResolveCoincidentTopology(false);
80 void SVTK_Actor::SetShrinkFactor(float theValue){
81 myShrinkFilter->SetShrinkFactor(theValue);
85 void SVTK_Actor::SetShrink()
87 if ( !myIsShrinkable ) return;
88 if ( vtkDataSet* aDataSet = myPassFilter[0]->GetOutput() )
90 myShrinkFilter->SetInput( aDataSet );
91 myPassFilter[1]->SetInput( myShrinkFilter->GetOutput() );
96 void SVTK_Actor::UnShrink()
98 if ( !myIsShrunk ) return;
99 if ( vtkDataSet* aDataSet = myPassFilter[0]->GetOutput() )
101 myPassFilter[1]->SetInput( aDataSet );
102 myPassFilter[1]->Modified();
109 //----------------------------------------------------------------------------
110 SVTK_Actor::~SVTK_Actor()
112 //if(MYDEBUG) INFOS("VTKViewer_Actor::~VTKViewer_Actor()");
114 myMapper->RemoveAllInputs();
117 myShrinkFilter->UnRegisterAllOutputs();
118 myShrinkFilter->Delete();
120 myUnstructuredGrid->Delete();
124 //----------------------------------------------------------------------------
125 void SVTK_Actor::MapCells(SALOME_Actor* theMapActor,
126 const TColStd_IndexedMapOfInteger& theMapIndex)
128 myUnstructuredGrid->Reset();
130 vtkDataSet *aSourceDataSet = theMapActor->GetInput();
131 CopyPoints(myUnstructuredGrid,aSourceDataSet);
133 int aNbOfParts = theMapIndex.Extent();
134 for(int ind = 1; ind <= aNbOfParts; ind++){
135 int aPartId = theMapIndex( ind );
136 vtkCell* aCell = theMapActor->GetElemCell(aPartId);
137 myUnstructuredGrid->InsertNextCell(aCell->GetCellType(),aCell->GetPointIds());
138 //for (int i = 0, iEnd = aCell->GetNumberOfEdges(); i < iEnd; i++){
139 // vtkCell* anEdgeCell = aCell->GetEdge(i);
140 // myUnstructuredGrid->InsertNextCell(VTK_LINE,anEdgeCell->GetPointIds());
145 if(theMapActor->IsShrunk()){
146 SetShrinkFactor(theMapActor->GetShrinkFactor());
152 //----------------------------------------------------------------------------
153 void SVTK_Actor::MapPoints(SALOME_Actor* theMapActor,
154 const TColStd_IndexedMapOfInteger& theMapIndex)
156 myUnstructuredGrid->Reset();
157 if(int aNbOfParts = theMapIndex.Extent()){
158 vtkPoints *aPoints = vtkPoints::New();
159 aPoints->SetNumberOfPoints(aNbOfParts);
160 for(int i = 0; i < aNbOfParts; i++){
161 int aPartId = theMapIndex( i+1 );
162 float* aCoord = theMapActor->GetNodeCoord(aPartId);
163 aPoints->SetPoint(i,aCoord);
164 myUnstructuredGrid->InsertNextCell(VTK_VERTEX,1,&i);
166 myUnstructuredGrid->SetPoints(aPoints);
174 //----------------------------------------------------------------------------
175 void SVTK_Actor::MapEdge(SALOME_Actor* theMapActor,
176 const TColStd_IndexedMapOfInteger& theMapIndex)
178 myUnstructuredGrid->Reset();
180 vtkDataSet *aSourceDataSet = theMapActor->GetInput();
181 CopyPoints(myUnstructuredGrid,aSourceDataSet);
183 int iEnd = theMapIndex.Extent();
184 int aCellId = -1, aCellCounter = 0;
185 for(int i = 1; i <= iEnd; i++){
186 int anId = theMapIndex( i );
193 if(aCellCounter == 1){
194 vtkCell* aCell = theMapActor->GetElemCell(aCellId);
195 if(aCell->GetCellType() <= VTK_LINE){
196 myUnstructuredGrid->InsertNextCell(aCell->GetCellType(),aCell->GetPointIds());
198 int aNbOfParts = aCell->GetNumberOfEdges();
199 for(int i = 1; i <= iEnd; i++){
200 int aPartId = theMapIndex(i);
202 aPartId = -aPartId-1;
203 if(0 > aPartId || aPartId >= aNbOfParts) break;
204 vtkCell* anEdgeCell = aCell->GetEdge(aPartId);
205 myUnstructuredGrid->InsertNextCell(VTK_LINE,anEdgeCell->GetPointIds());
210 int aNbOfParts = aSourceDataSet->GetNumberOfCells();
211 for(int i = 1; i <= iEnd; i++){
212 int aPartId = theMapIndex( i );
214 if(aPartId >= aNbOfParts) break;
215 vtkCell* aCell = aSourceDataSet->GetCell(aPartId);
216 myUnstructuredGrid->InsertNextCell(aCell->GetCellType(),aCell->GetPointIds());
222 if(theMapActor->IsShrunk()){
223 SetShrinkFactor(theMapActor->GetShrinkFactor());
228 //----------------------------------------------------------------------------