1 // Created on: 1995-03-06
2 // Created by: Laurent PAINNOT
3 // Copyright (c) 1995-1999 Matra Datavision
4 // Copyright (c) 1999-2014 OPEN CASCADE SAS
6 // This file is part of Open CASCADE Technology software library.
8 // This library is free software; you can redistribute it and/or modify it under
9 // the terms of the GNU Lesser General Public License version 2.1 as published
10 // by the Free Software Foundation, with special exception defined in the file
11 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
12 // distribution for complete text of the license and disclaimer of any warranty.
14 // Alternatively, this file may be used under the terms of Open CASCADE
15 // commercial license or contractual agreement.
17 #ifndef _Poly_Triangulation_HeaderFile
18 #define _Poly_Triangulation_HeaderFile
20 #include <Standard.hxx>
21 #include <Standard_Type.hxx>
23 #include <Standard_Real.hxx>
24 #include <Standard_Integer.hxx>
25 #include <TColgp_Array1OfPnt.hxx>
26 #include <TColgp_HArray1OfPnt2d.hxx>
27 #include <Poly_Array1OfTriangle.hxx>
28 #include <TShort_HArray1OfShortReal.hxx>
29 #include <MMgt_TShared.hxx>
30 #include <Standard_Boolean.hxx>
31 #include <TColgp_Array1OfPnt2d.hxx>
32 #include <TShort_Array1OfShortReal.hxx>
33 class Standard_DomainError;
34 class Standard_NullObject;
37 class Poly_Triangulation;
38 DEFINE_STANDARD_HANDLE(Poly_Triangulation, MMgt_TShared)
40 //! Provides a triangulation for a surface, a set of surfaces, or
41 //! more generally a shape.
42 //! A triangulation consists of an approximate representation
43 //! of the actual shape, using a collection of points and
44 //! triangles. The points are located on the surface. The
45 //! edges of the triangles connect adjacent points with a
46 //! straight line that approximates the true curve on the surface.
47 //! A triangulation comprises:
48 //! - A table of 3D nodes (3D points on the surface).
49 //! - A table of triangles. Each triangle (Poly_Triangle
50 //! object) comprises a triplet of indices in the table of 3D
51 //! nodes specific to the triangulation.
52 //! - A table of 2D nodes (2D points), parallel to the table of
53 //! 3D nodes. This table is optional. If it exists, the
54 //! coordinates of a 2D point are the (u, v) parameters
55 //! of the corresponding 3D point on the surface
56 //! approximated by the triangulation.
57 //! - A deflection (optional), which maximizes the distance
58 //! from a point on the surface to the corresponding point
59 //! on its approximate triangulation.
60 //! In many cases, algorithms do not need to work with the
61 //! exact representation of a surface. A triangular
62 //! representation induces simpler and more robust adjusting,
63 //! faster performances, and the results are as good.
64 //! This is a Transient class.
65 class Poly_Triangulation : public MMgt_TShared
71 //! Constructs a triangulation from a set of triangles. The
72 //! triangulation is initialized without a triangle or a node, but capable of
73 //! containing nbNodes nodes, and nbTriangles
74 //! triangles. Here the UVNodes flag indicates whether
75 //! 2D nodes will be associated with 3D ones, (i.e. to
76 //! enable a 2D representation).
77 Standard_EXPORT Poly_Triangulation(const Standard_Integer nbNodes, const Standard_Integer nbTriangles, const Standard_Boolean UVNodes);
79 //! Constructs a triangulation from a set of triangles. The
80 //! triangulation is initialized with 3D points from Nodes and triangles
82 Standard_EXPORT Poly_Triangulation(const TColgp_Array1OfPnt& Nodes, const Poly_Array1OfTriangle& Triangles);
84 //! Constructs a triangulation from a set of triangles. The
85 //! triangulation is initialized with 3D points from Nodes, 2D points from
86 //! UVNodes and triangles from Triangles, where
87 //! coordinates of a 2D point from UVNodes are the
88 //! (u, v) parameters of the corresponding 3D point
89 //! from Nodes on the surface approximated by the
90 //! constructed triangulation.
91 Standard_EXPORT Poly_Triangulation(const TColgp_Array1OfPnt& Nodes, const TColgp_Array1OfPnt2d& UVNodes, const Poly_Array1OfTriangle& Triangles);
93 //! Returns the deflection of this triangulation.
94 Standard_EXPORT Standard_Real Deflection() const;
96 //! Sets the deflection of this triangulation to D.
97 //! See more on deflection in Polygon2D
98 Standard_EXPORT void Deflection (const Standard_Real D);
100 //! Deallocates the UV nodes.
101 Standard_EXPORT void RemoveUVNodes();
103 //! Returns the number of nodes for this triangulation.
104 //! Null if the nodes are not yet defined.
105 Standard_Integer NbNodes() const;
107 //! Returns the number of triangles for this triangulation.
108 //! Null if the Triangles are not yet defined.
109 Standard_Integer NbTriangles() const;
111 //! Returns true if 2D nodes are associated with 3D nodes for
112 //! this triangulation.
113 Standard_Boolean HasUVNodes() const;
115 //! Returns the table of 3D nodes (3D points) for this triangulation.
116 Standard_EXPORT const TColgp_Array1OfPnt& Nodes() const;
118 //! Returns the table of 3D nodes (3D points) for this triangulation.
119 //! The returned array is
120 //! shared. Therefore if the table is selected by reference, you
121 //! can, by simply modifying it, directly modify the data
122 //! structure of this triangulation.
123 Standard_EXPORT TColgp_Array1OfPnt& ChangeNodes();
125 //! Returns the table of 2D nodes (2D points) associated with
126 //! each 3D node of this triangulation.
127 //! The function HasUVNodes checks if 2D nodes
128 //! are associated with the 3D nodes of this triangulation.
129 //! Const reference on the 2d nodes values.
130 Standard_EXPORT const TColgp_Array1OfPnt2d& UVNodes() const;
132 //! Returns the table of 2D nodes (2D points) associated with
133 //! each 3D node of this triangulation.
134 //! Function ChangeUVNodes shares the returned array.
135 //! Therefore if the table is selected by reference,
136 //! you can, by simply modifying it, directly modify the data
137 //! structure of this triangulation.
138 Standard_EXPORT TColgp_Array1OfPnt2d& ChangeUVNodes();
140 //! Returns the table of triangles for this triangulation.
141 Standard_EXPORT const Poly_Array1OfTriangle& Triangles() const;
143 //! Returns the table of triangles for this triangulation.
144 //! Function ChangeUVNodes shares the returned array.
145 //! Therefore if the table is selected by reference,
146 //! you can, by simply modifying it, directly modify the data
147 //! structure of this triangulation.
148 Standard_EXPORT Poly_Array1OfTriangle& ChangeTriangles();
150 //! Sets the table of node normals.
151 //! raises exception if length of theNormals != 3*NbNodes
152 Standard_EXPORT void SetNormals (const Handle(TShort_HArray1OfShortReal)& theNormals);
154 Standard_EXPORT const TShort_Array1OfShortReal& Normals() const;
156 Standard_EXPORT TShort_Array1OfShortReal& ChangeNormals();
158 Standard_EXPORT Standard_Boolean HasNormals() const;
163 DEFINE_STANDARD_RTTI(Poly_Triangulation,MMgt_TShared)
173 Standard_Real myDeflection;
174 Standard_Integer myNbNodes;
175 Standard_Integer myNbTriangles;
176 TColgp_Array1OfPnt myNodes;
177 Handle(TColgp_HArray1OfPnt2d) myUVNodes;
178 Poly_Array1OfTriangle myTriangles;
179 Handle(TShort_HArray1OfShortReal) myNormals;
185 #include <Poly_Triangulation.lxx>
191 #endif // _Poly_Triangulation_HeaderFile