Salome HOME
Join modifications from BR_Dev_For_4_0 tag V4_1_1.
[modules/geom.git] / src / OBJECT / GEOM_ShadingFace.cxx
1 #include "GEOM_ShadingFace.h" 
2  
3 #include <vtkObjectFactory.h> 
4  
5 #include <vtkPoints.h> 
6 #include <vtkCellArray.h> 
7
8 #include <vtkPolyDataMapper.h>  
9 #include <vtkPolyData.h>  
10
11 #include <BRep_Tool.hxx>
12 #include <Poly_Triangulation.hxx>
13  
14
15 vtkStandardNewMacro(GEOM_ShadingFace);
16  
17 GEOM_ShadingFace::GEOM_ShadingFace() 
18
19
20  
21 GEOM_ShadingFace::~GEOM_ShadingFace() 
22
23
24  
25 void
26 GEOM_ShadingFace:: 
27 Execute()
28 {
29   vtkPolyData* aPolyData = GetOutput();
30   aPolyData->Allocate();
31   vtkPoints* aPts = vtkPoints::New();
32   aPolyData->SetPoints(aPts);
33   aPts->Delete();
34
35   TFaceSet::Iterator anIter(myFaceSet);
36   for(; anIter.More(); anIter.Next()){
37     const TopoDS_Face& aFace = anIter.Value();
38     OCC2VTK(aFace,aPolyData,aPts);
39   }
40 }
41
42 void  
43 GEOM_ShadingFace:: 
44 OCC2VTK(const TopoDS_Face& theFace,  
45         vtkPolyData* thePolyData, 
46         vtkPoints* thePts) 
47 {
48   TopLoc_Location aLoc;
49   Handle(Poly_Triangulation) aPoly = BRep_Tool::Triangulation(theFace,aLoc);
50   if(aPoly.IsNull()) 
51     return;
52   else{
53     gp_Trsf myTransf;
54     Standard_Boolean identity = true;
55     if(!aLoc.IsIdentity()){
56       identity = false;
57       myTransf = aLoc.Transformation();
58     }           
59       
60     Standard_Integer i; 
61     int aNbOfNodes = thePts->GetNumberOfPoints();
62     const TColgp_Array1OfPnt& Nodes = aPoly->Nodes();
63     Standard_Integer nbNodesInFace = aPoly->NbNodes(); 
64     for(i = 1; i <= nbNodesInFace; i++) {
65       gp_Pnt P = Nodes(i);
66       if(!identity) 
67         P.Transform(myTransf);
68       thePts->InsertNextPoint(P.X(),P.Y(),P.Z());
69     }
70
71     const Poly_Array1OfTriangle& Triangles = aPoly->Triangles();
72     Standard_Integer nbTriInFace = aPoly->NbTriangles();
73     for(i = 1; i <= nbTriInFace; i++){
74       // Get the triangle
75       Standard_Integer N1,N2,N3;
76       Triangles(i).Get(N1,N2,N3);
77       N1 += aNbOfNodes - 1;
78       N2 += aNbOfNodes - 1;
79       N3 += aNbOfNodes - 1;
80       vtkIdType anIds[3] = {N1, N2, N3};
81       thePolyData->InsertNextCell(VTK_TRIANGLE,3,anIds);
82     }
83   } 
84 }