Salome HOME
Mantis issues 0020573 and 0020603: Partition problems. A fix by Peter KURNEV.
[modules/geom.git] / src / OBJECT / GEOM_ShadingFace.cxx
1 //  Copyright (C) 2007-2008  CEA/DEN, EDF R&D, OPEN CASCADE
2 //
3 //  Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 //  CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
5 //
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.
10 //
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.
15 //
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
19 //
20 //  See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
21 //
22 #include "GEOM_ShadingFace.h" 
23  
24 #include <vtkObjectFactory.h> 
25  
26 #include <vtkPoints.h> 
27 #include <vtkCellArray.h> 
28
29 #include <vtkPolyDataMapper.h>  
30 #include <vtkPolyData.h>  
31
32 #include <BRep_Tool.hxx>
33 #include <Poly_Triangulation.hxx>
34  
35
36 vtkStandardNewMacro(GEOM_ShadingFace);
37  
38 GEOM_ShadingFace::GEOM_ShadingFace() 
39
40
41  
42 GEOM_ShadingFace::~GEOM_ShadingFace() 
43
44
45  
46 void
47 GEOM_ShadingFace:: 
48 Execute()
49 {
50   vtkPolyData* aPolyData = GetOutput();
51   aPolyData->Allocate();
52   vtkPoints* aPts = vtkPoints::New();
53   aPolyData->SetPoints(aPts);
54   aPts->Delete();
55
56   TFaceSet::Iterator anIter(myFaceSet);
57   for(; anIter.More(); anIter.Next()){
58     const TopoDS_Face& aFace = anIter.Value();
59     OCC2VTK(aFace,aPolyData,aPts);
60   }
61 }
62
63 void  
64 GEOM_ShadingFace:: 
65 OCC2VTK(const TopoDS_Face& theFace,  
66         vtkPolyData* thePolyData, 
67         vtkPoints* thePts) 
68 {
69   TopLoc_Location aLoc;
70   Handle(Poly_Triangulation) aPoly = BRep_Tool::Triangulation(theFace,aLoc);
71   if(aPoly.IsNull()) 
72     return;
73   else{
74     gp_Trsf myTransf;
75     Standard_Boolean identity = true;
76     if(!aLoc.IsIdentity()){
77       identity = false;
78       myTransf = aLoc.Transformation();
79     }           
80       
81     Standard_Integer i; 
82     int aNbOfNodes = thePts->GetNumberOfPoints();
83     const TColgp_Array1OfPnt& Nodes = aPoly->Nodes();
84     Standard_Integer nbNodesInFace = aPoly->NbNodes(); 
85     for(i = 1; i <= nbNodesInFace; i++) {
86       gp_Pnt P = Nodes(i);
87       if(!identity) 
88         P.Transform(myTransf);
89       thePts->InsertNextPoint(P.X(),P.Y(),P.Z());
90     }
91
92     const Poly_Array1OfTriangle& Triangles = aPoly->Triangles();
93     Standard_Integer nbTriInFace = aPoly->NbTriangles();
94     for(i = 1; i <= nbTriInFace; i++){
95       // Get the triangle
96       Standard_Integer N1,N2,N3;
97       Triangles(i).Get(N1,N2,N3);
98       N1 += aNbOfNodes - 1;
99       N2 += aNbOfNodes - 1;
100       N3 += aNbOfNodes - 1;
101       vtkIdType anIds[3] = {N1, N2, N3};
102       thePolyData->InsertNextCell(VTK_TRIANGLE,3,anIds);
103     }
104   } 
105 }