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 //! Creates full copy of current triangulation
94 Standard_EXPORT virtual Handle(Poly_Triangulation) Copy() const;
96 //! Returns the deflection of this triangulation.
97 Standard_EXPORT Standard_Real Deflection() const;
99 //! Sets the deflection of this triangulation to D.
100 //! See more on deflection in Polygon2D
101 Standard_EXPORT void Deflection (const Standard_Real D);
103 //! Deallocates the UV nodes.
104 Standard_EXPORT void RemoveUVNodes();
106 //! Returns the number of nodes for this triangulation.
107 //! Null if the nodes are not yet defined.
108 Standard_Integer NbNodes() const;
110 //! Returns the number of triangles for this triangulation.
111 //! Null if the Triangles are not yet defined.
112 Standard_Integer NbTriangles() const;
114 //! Returns true if 2D nodes are associated with 3D nodes for
115 //! this triangulation.
116 Standard_Boolean HasUVNodes() const;
118 //! Returns the table of 3D nodes (3D points) for this triangulation.
119 Standard_EXPORT const TColgp_Array1OfPnt& Nodes() const;
121 //! Returns the table of 3D nodes (3D points) for this triangulation.
122 //! The returned array is
123 //! shared. Therefore if the table is selected by reference, you
124 //! can, by simply modifying it, directly modify the data
125 //! structure of this triangulation.
126 Standard_EXPORT TColgp_Array1OfPnt& ChangeNodes();
128 //! Returns the table of 2D nodes (2D points) associated with
129 //! each 3D node of this triangulation.
130 //! The function HasUVNodes checks if 2D nodes
131 //! are associated with the 3D nodes of this triangulation.
132 //! Const reference on the 2d nodes values.
133 Standard_EXPORT const TColgp_Array1OfPnt2d& UVNodes() const;
135 //! Returns the table of 2D nodes (2D points) associated with
136 //! each 3D node of this triangulation.
137 //! Function ChangeUVNodes shares the returned array.
138 //! Therefore if the table is selected by reference,
139 //! you can, by simply modifying it, directly modify the data
140 //! structure of this triangulation.
141 Standard_EXPORT TColgp_Array1OfPnt2d& ChangeUVNodes();
143 //! Returns the table of triangles for this triangulation.
144 Standard_EXPORT const Poly_Array1OfTriangle& Triangles() const;
146 //! Returns the table of triangles for this triangulation.
147 //! Function ChangeUVNodes shares the returned array.
148 //! Therefore if the table is selected by reference,
149 //! you can, by simply modifying it, directly modify the data
150 //! structure of this triangulation.
151 Standard_EXPORT Poly_Array1OfTriangle& ChangeTriangles();
153 //! Sets the table of node normals.
154 //! raises exception if length of theNormals != 3*NbNodes
155 Standard_EXPORT void SetNormals (const Handle(TShort_HArray1OfShortReal)& theNormals);
157 Standard_EXPORT const TShort_Array1OfShortReal& Normals() const;
159 Standard_EXPORT TShort_Array1OfShortReal& ChangeNormals();
161 Standard_EXPORT Standard_Boolean HasNormals() const;
166 DEFINE_STANDARD_RTTI(Poly_Triangulation,MMgt_TShared)
176 Standard_Real myDeflection;
177 Standard_Integer myNbNodes;
178 Standard_Integer myNbTriangles;
179 TColgp_Array1OfPnt myNodes;
180 Handle(TColgp_HArray1OfPnt2d) myUVNodes;
181 Poly_Array1OfTriangle myTriangles;
182 Handle(TShort_HArray1OfShortReal) myNormals;
188 #include <Poly_Triangulation.lxx>
194 #endif // _Poly_Triangulation_HeaderFile