forked from Derek-yfqiu/OCCReader
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathGEOM_ShadingFace.cxx
109 lines (94 loc) · 3.09 KB
/
GEOM_ShadingFace.cxx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
// Copyright (C) 2014-2015 KIT-INR/NK
//
// This library is free software; you can redistribute it and/or
// modify it under the terms of the GNU Lesser General Public
// License as published by the Free Software Foundation; either
// version 2.1 of the License.
//
// This library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
// Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public
// License along with this library; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
//
//
#include "GEOM_ShadingFace.h"
#include <vtkObjectFactory.h>
#include <vtkPoints.h>
#include <vtkCellArray.h>
#include <vtkPolyDataMapper.h>
#include <vtkPolyData.h>
#include <vtkInformation.h>
#include <vtkInformationVector.h>
#include <BRep_Tool.hxx>
#include <Poly_Triangulation.hxx>
vtkStandardNewMacro(GEOM_ShadingFace);
GEOM_ShadingFace::GEOM_ShadingFace()
{
this->SetNumberOfInputPorts(0);
}
GEOM_ShadingFace::~GEOM_ShadingFace()
{
}
int GEOM_ShadingFace::RequestData(vtkInformation *vtkNotUsed(request),
vtkInformationVector **vtkNotUsed(inputVector),
vtkInformationVector *outputVector)
{
vtkInformation *outInfo = outputVector->GetInformationObject(0);
vtkPolyData *aPolyData = vtkPolyData::SafeDownCast(
outInfo->Get(vtkDataObject::DATA_OBJECT()));
aPolyData->Allocate();
vtkPoints* aPts = vtkPoints::New();
aPolyData->SetPoints(aPts);
aPts->Delete();
TFaceSet::Iterator anIter(myFaceSet);
for(; anIter.More(); anIter.Next()){
const TopoDS_Face& aFace = anIter.Value();
OCC2VTK(aFace,aPolyData,aPts);
}
return 1;
}
void
GEOM_ShadingFace::
OCC2VTK(const TopoDS_Face& theFace,
vtkPolyData* thePolyData,
vtkPoints* thePts)
{
TopLoc_Location aLoc;
Handle(Poly_Triangulation) aPoly = BRep_Tool::Triangulation(theFace,aLoc);
if(aPoly.IsNull())
return;
else{
gp_Trsf myTransf;
Standard_Boolean identity = true;
if(!aLoc.IsIdentity()){
identity = false;
myTransf = aLoc.Transformation();
}
Standard_Integer i;
int aNbOfNodes = thePts->GetNumberOfPoints();
const TColgp_Array1OfPnt& Nodes = aPoly->Nodes();
Standard_Integer nbNodesInFace = aPoly->NbNodes();
for(i = 1; i <= nbNodesInFace; i++) {
gp_Pnt P = Nodes(i);
if(!identity)
P.Transform(myTransf);
thePts->InsertNextPoint(P.X(),P.Y(),P.Z());
}
const Poly_Array1OfTriangle& Triangles = aPoly->Triangles();
Standard_Integer nbTriInFace = aPoly->NbTriangles();
for(i = 1; i <= nbTriInFace; i++){
// Get the triangle
Standard_Integer N1,N2,N3;
Triangles(i).Get(N1,N2,N3);
N1 += aNbOfNodes - 1;
N2 += aNbOfNodes - 1;
N3 += aNbOfNodes - 1;
vtkIdType anIds[3] = {N1, N2, N3};
thePolyData->InsertNextCell(VTK_TRIANGLE,3,anIds);
}
}
}