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.salome-platform.org/ or email : webmaster.salome@opencascade.com
20 #include "SVTK_Actor.h"
21 #include "SALOME_Actor.h"
24 #include <vtkObjectFactory.h>
25 #include <vtkUnstructuredGrid.h>
26 #include <vtkDataSetMapper.h>
27 #include <vtkRenderer.h>
30 #include <vtkPolyData.h>
37 CopyPoints(vtkUnstructuredGrid* theGrid, vtkDataSet *theSourceDataSet)
39 vtkPoints *aPoints = vtkPoints::New();
40 vtkIdType iEnd = theSourceDataSet->GetNumberOfPoints();
41 aPoints->SetNumberOfPoints(iEnd);
42 for(vtkIdType i = 0; i < iEnd; i++){
43 aPoints->SetPoint(i,theSourceDataSet->GetPoint(i));
45 theGrid->SetPoints(aPoints);
49 vtkStandardNewMacro(SVTK_Actor);
56 myUnstructuredGrid(vtkUnstructuredGrid::New())
59 myIsResolveCoincidentTopology = false;
61 Visibility = Pickable = false;
63 myUnstructuredGrid->Delete();
64 myUnstructuredGrid->Allocate();
71 SetInput(GetSource());
76 ::SetSource(vtkUnstructuredGrid* theUnstructuredGrid)
78 if(GetSource() == theUnstructuredGrid)
81 myUnstructuredGrid = theUnstructuredGrid;
83 SetInput(theUnstructuredGrid);
90 return myUnstructuredGrid.GetPointer();
101 const TColStd_IndexedMapOfInteger&
103 ::GetMapIndex() const
110 ::MapCells(SALOME_Actor* theMapActor,
111 const TColStd_IndexedMapOfInteger& theMapIndex)
113 myUnstructuredGrid->Initialize();
114 myUnstructuredGrid->Allocate();
116 vtkDataSet *aSourceDataSet = theMapActor->GetInput();
117 CopyPoints(GetSource(),aSourceDataSet);
119 int aNbOfParts = theMapIndex.Extent();
120 for(int ind = 1; ind <= aNbOfParts; ind++){
121 int aPartId = theMapIndex( ind );
122 if(vtkCell* aCell = theMapActor->GetElemCell(aPartId))
123 myUnstructuredGrid->InsertNextCell(aCell->GetCellType(),aCell->GetPointIds());
127 if(theMapActor->IsShrunk()){
128 SetShrinkFactor(theMapActor->GetShrinkFactor());
132 myMapIndex = theMapIndex;
137 ::MapPoints(SALOME_Actor* theMapActor,
138 const TColStd_IndexedMapOfInteger& theMapIndex)
140 myUnstructuredGrid->Initialize();
141 myUnstructuredGrid->Allocate();
143 if(int aNbOfParts = theMapIndex.Extent()){
144 vtkPoints *aPoints = vtkPoints::New();
145 aPoints->SetNumberOfPoints(aNbOfParts);
146 for(int i = 0; i < aNbOfParts; i++){
147 int aPartId = theMapIndex( i+1 );
148 if(vtkFloatingPointType* aCoord = theMapActor->GetNodeCoord(aPartId)){
149 aPoints->SetPoint(i,aCoord);
150 myUnstructuredGrid->InsertNextCell(VTK_VERTEX,1,&i);
153 myUnstructuredGrid->SetPoints(aPoints);
159 myMapIndex = theMapIndex;
164 ::MapEdge(SALOME_Actor* theMapActor,
165 const TColStd_IndexedMapOfInteger& theMapIndex)
167 myUnstructuredGrid->Initialize();
168 myUnstructuredGrid->Allocate();
170 vtkDataSet *aSourceDataSet = theMapActor->GetInput();
171 CopyPoints(GetSource(),aSourceDataSet);
174 if(theMapIndex.Extent() == 2){
175 int anEdgeId = theMapIndex(1) < 0 ? theMapIndex(1) : theMapIndex(2);
176 int aCellId = theMapIndex(1) < 0 ? theMapIndex(2) : theMapIndex(1);
179 if(vtkCell* aCell = theMapActor->GetElemCell(aCellId)){
181 anEdgeId = -anEdgeId - 1;
182 int aNbOfEdges = aCell->GetNumberOfEdges();
183 if(0 <= anEdgeId || anEdgeId < aNbOfEdges){
184 if(vtkCell* anEdge = aCell->GetEdge(anEdgeId))
185 myUnstructuredGrid->InsertNextCell(VTK_LINE,anEdge->GetPointIds());
193 if(theMapActor->IsShrunk()){
194 SetShrinkFactor(theMapActor->GetShrinkFactor());
198 myMapIndex = theMapIndex;