1 // Copyright (C) 2007-2014 CEA/DEN, EDF R&D, OPEN CASCADE
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either
6 // version 2.1 of the License, or (at your option) any later version.
8 // This library is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 // Lesser General Public License for more details.
13 // You should have received a copy of the GNU Lesser General Public
14 // License along with this library; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
20 #include "GEOM_ShadingFace.h"
21 #include "OCC2VTK_internal.h"
23 #include <vtkObjectFactory.h>
25 #include <vtkPoints.h>
26 #include <vtkCellArray.h>
28 #include <vtkPolyDataMapper.h>
29 #include <vtkPolyData.h>
30 #include <vtkInformation.h>
31 #include <vtkInformationVector.h>
33 #include <BRep_Tool.hxx>
34 #include <Poly_Triangulation.hxx>
37 vtkStandardNewMacro(GEOM_ShadingFace);
39 GEOM_ShadingFace::GEOM_ShadingFace()
41 this->SetNumberOfInputPorts(0);
44 GEOM_ShadingFace::~GEOM_ShadingFace()
48 int GEOM_ShadingFace::RequestData(vtkInformation *vtkNotUsed(request),
49 vtkInformationVector **vtkNotUsed(inputVector),
50 vtkInformationVector *outputVector)
52 vtkInformation *outInfo = outputVector->GetInformationObject(0);
53 vtkPolyData *aPolyData = vtkPolyData::SafeDownCast(
54 outInfo->Get(vtkDataObject::DATA_OBJECT()));
56 aPolyData->Allocate();
57 vtkPoints* aPts = vtkPoints::New();
58 aPolyData->SetPoints(aPts);
61 TFaceSet::Iterator anIter(myData->myFaceSet);
62 for(; anIter.More(); anIter.Next()){
63 const TopoDS_Face& aFace = anIter.Value();
64 OCC2VTK(aFace,aPolyData,aPts);
71 OCC2VTK(const TopoDS_Face& theFace,
72 vtkPolyData* thePolyData,
76 Handle(Poly_Triangulation) aPoly = BRep_Tool::Triangulation(theFace,aLoc);
81 Standard_Boolean identity = true;
82 if(!aLoc.IsIdentity()){
84 myTransf = aLoc.Transformation();
88 int aNbOfNodes = thePts->GetNumberOfPoints();
89 const TColgp_Array1OfPnt& Nodes = aPoly->Nodes();
90 Standard_Integer nbNodesInFace = aPoly->NbNodes();
91 for(i = 1; i <= nbNodesInFace; i++) {
94 P.Transform(myTransf);
95 thePts->InsertNextPoint(P.X(),P.Y(),P.Z());
98 const Poly_Array1OfTriangle& Triangles = aPoly->Triangles();
99 Standard_Integer nbTriInFace = aPoly->NbTriangles();
100 for(i = 1; i <= nbTriInFace; i++){
102 Standard_Integer N1,N2,N3;
103 Triangles(i).Get(N1,N2,N3);
104 N1 += aNbOfNodes - 1;
105 N2 += aNbOfNodes - 1;
106 N3 += aNbOfNodes - 1;
107 vtkIdType anIds[3] = {N1, N2, N3};
108 thePolyData->InsertNextCell(VTK_TRIANGLE,3,anIds);