1 // Copyright (C) 2007-2024 CEA, EDF, 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"
22 #include <vtkObjectFactory.h>
24 #include <vtkPoints.h>
25 #include <vtkCellArray.h>
27 #include <vtkPolyDataMapper.h>
28 #include <vtkPolyData.h>
29 #include <vtkInformation.h>
30 #include <vtkInformationVector.h>
32 #include <BRep_Tool.hxx>
33 #include <Poly_Triangulation.hxx>
36 vtkStandardNewMacro(GEOM_ShadingFace)
38 GEOM_ShadingFace::GEOM_ShadingFace()
40 this->SetNumberOfInputPorts(0);
43 GEOM_ShadingFace::~GEOM_ShadingFace()
47 int GEOM_ShadingFace::RequestData(vtkInformation *vtkNotUsed(request),
48 vtkInformationVector **vtkNotUsed(inputVector),
49 vtkInformationVector *outputVector)
51 vtkInformation *outInfo = outputVector->GetInformationObject(0);
52 vtkPolyData *aPolyData = vtkPolyData::SafeDownCast(
53 outInfo->Get(vtkDataObject::DATA_OBJECT()));
55 aPolyData->Allocate();
56 vtkPoints* aPts = vtkPoints::New();
57 aPolyData->SetPoints(aPts);
60 TFaceSet::Iterator anIter(myFaceSet);
61 for(; anIter.More(); anIter.Next()){
62 const TopoDS_Face& aFace = anIter.Value();
63 OCC2VTK(aFace,aPolyData,aPts);
70 OCC2VTK(const TopoDS_Face& theFace,
71 vtkPolyData* thePolyData,
75 Handle(Poly_Triangulation) aPoly = BRep_Tool::Triangulation(theFace,aLoc);
80 Standard_Boolean identity = true;
81 if(!aLoc.IsIdentity()){
83 myTransf = aLoc.Transformation();
87 int aNbOfNodes = thePts->GetNumberOfPoints();
88 Standard_Integer nbNodesInFace = aPoly->NbNodes();
89 for(i = 1; i <= nbNodesInFace; i++) {
90 gp_Pnt P = aPoly->Node(i);
92 P.Transform(myTransf);
93 thePts->InsertNextPoint(P.X(),P.Y(),P.Z());
96 Standard_Integer nbTriInFace = aPoly->NbTriangles();
97 for(i = 1; i <= nbTriInFace; i++){
99 Standard_Integer N1,N2,N3;
100 aPoly->Triangle(i).Get(N1,N2,N3);
101 N1 += aNbOfNodes - 1;
102 N2 += aNbOfNodes - 1;
103 N3 += aNbOfNodes - 1;
104 vtkIdType anIds[3] = {N1, N2, N3};
105 thePolyData->InsertNextCell(VTK_TRIANGLE,3,anIds);