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_DefineHandle.hxx>
22 #include <Standard_Real.hxx>
23 #include <Standard_Integer.hxx>
24 #include <TColgp_Array1OfPnt.hxx>
25 #include <TColgp_HArray1OfPnt2d.hxx>
26 #include <Poly_Array1OfTriangle.hxx>
27 #include <TShort_HArray1OfShortReal.hxx>
28 #include <MMgt_TShared.hxx>
29 #include <Standard_Boolean.hxx>
30 #include <TColgp_Array1OfPnt2d.hxx>
31 #include <TShort_Array1OfShortReal.hxx>
32 class Standard_DomainError;
33 class Standard_NullObject;
36 class Poly_Triangulation;
37 DEFINE_STANDARD_HANDLE(Poly_Triangulation, MMgt_TShared)
39 //! Provides a triangulation for a surface, a set of surfaces, or
40 //! more generally a shape.
41 //! A triangulation consists of an approximate representation
42 //! of the actual shape, using a collection of points and
43 //! triangles. The points are located on the surface. The
44 //! edges of the triangles connect adjacent points with a
45 //! straight line that approximates the true curve on the surface.
46 //! A triangulation comprises:
47 //! - A table of 3D nodes (3D points on the surface).
48 //! - A table of triangles. Each triangle (Poly_Triangle
49 //! object) comprises a triplet of indices in the table of 3D
50 //! nodes specific to the triangulation.
51 //! - A table of 2D nodes (2D points), parallel to the table of
52 //! 3D nodes. This table is optional. If it exists, the
53 //! coordinates of a 2D point are the (u, v) parameters
54 //! of the corresponding 3D point on the surface
55 //! approximated by the triangulation.
56 //! - A deflection (optional), which maximizes the distance
57 //! from a point on the surface to the corresponding point
58 //! on its approximate triangulation.
59 //! In many cases, algorithms do not need to work with the
60 //! exact representation of a surface. A triangular
61 //! representation induces simpler and more robust adjusting,
62 //! faster performances, and the results are as good.
63 //! This is a Transient class.
64 class Poly_Triangulation : public MMgt_TShared
69 DEFINE_STANDARD_RTTIEXT(Poly_Triangulation, 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 //! Copy constructor for triangulation.
97 Standard_EXPORT Poly_Triangulation (const Handle(Poly_Triangulation)& theTriangulation);
99 //! Returns the deflection of this triangulation.
100 Standard_Real Deflection() const { return myDeflection; }
102 //! Sets the deflection of this triangulation to theDeflection.
103 //! See more on deflection in Polygon2D
104 Standard_EXPORT void Deflection (const Standard_Real theDeflection);
106 //! Deallocates the UV nodes.
107 Standard_EXPORT void RemoveUVNodes();
109 //! Returns the number of nodes for this triangulation.
110 Standard_Integer NbNodes() const { return myNodes.Length(); }
112 //! Returns the number of triangles for this triangulation.
113 Standard_Integer NbTriangles() const { return myTriangles.Length(); }
115 //! Returns Standard_True if 2D nodes are associated with 3D nodes for this triangulation.
116 Standard_Boolean HasUVNodes() const { return !myUVNodes.IsNull(); }
118 //! Returns the table of 3D nodes (3D points) for this triangulation.
119 const TColgp_Array1OfPnt& Nodes() const { return myNodes; }
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 TColgp_Array1OfPnt& ChangeNodes() { return myNodes; }
128 //! Returns node at the given index.
129 //! Raises Standard_OutOfRange exception if theIndex is less than 1 or greater than NbNodes.
130 Standard_EXPORT const gp_Pnt& Node (const Standard_Integer theIndex) const;
132 //! Give access to the node at the given index.
133 //! Raises Standard_OutOfRange exception if theIndex is less than 1 or greater than NbNodes.
134 Standard_EXPORT gp_Pnt& ChangeNode (const Standard_Integer theIndex);
136 //! Returns the table of 2D nodes (2D points) associated with
137 //! each 3D node of this triangulation.
138 //! The function HasUVNodes checks if 2D nodes
139 //! are associated with the 3D nodes of this triangulation.
140 //! Const reference on the 2d nodes values.
141 const TColgp_Array1OfPnt2d& UVNodes() const { return myUVNodes->Array1(); }
143 //! Returns the table of 2D nodes (2D points) associated with
144 //! each 3D node of this triangulation.
145 //! Function ChangeUVNodes shares the returned array.
146 //! Therefore if the table is selected by reference,
147 //! you can, by simply modifying it, directly modify the data
148 //! structure of this triangulation.
149 TColgp_Array1OfPnt2d& ChangeUVNodes() { return myUVNodes->ChangeArray1(); }
151 //! Returns UVNode at the given index.
152 //! Raises Standard_OutOfRange exception if theIndex is less than 1 or greater than NbNodes.
153 Standard_EXPORT const gp_Pnt2d& UVNode (const Standard_Integer theIndex) const;
155 //! Give access to the UVNode at the given index.
156 //! Raises Standard_OutOfRange exception if theIndex is less than 1 or greater than NbNodes.
157 Standard_EXPORT gp_Pnt2d& ChangeUVNode (const Standard_Integer theIndex);
159 //! Returns the table of triangles for this triangulation.
160 const Poly_Array1OfTriangle& Triangles() const { return myTriangles; }
162 //! Returns the table of triangles for this triangulation.
163 //! Function ChangeUVNodes shares the returned array.
164 //! Therefore if the table is selected by reference,
165 //! you can, by simply modifying it, directly modify the data
166 //! structure of this triangulation.
167 Poly_Array1OfTriangle& ChangeTriangles() { return myTriangles; }
169 //! Returns triangle at the given index.
170 //! Raises Standard_OutOfRange exception if theIndex is less than 1 or greater than NbTriangles.
171 Standard_EXPORT const Poly_Triangle& Triangle (const Standard_Integer theIndex) const;
173 //! Give access to the triangle at the given index.
174 //! Raises Standard_OutOfRange exception if theIndex is less than 1 or greater than NbTriangles.
175 Standard_EXPORT Poly_Triangle& ChangeTriangle (const Standard_Integer theIndex);
177 //! Sets the table of node normals.
178 //! raises exception if length of theNormals != 3*NbNodes
179 Standard_EXPORT void SetNormals (const Handle(TShort_HArray1OfShortReal)& theNormals);
181 //! Returns the table of node normals.
182 Standard_EXPORT const TShort_Array1OfShortReal& Normals() const;
184 //! Gives access to the table of node normals.
185 Standard_EXPORT TShort_Array1OfShortReal& ChangeNormals();
187 //! Returns Standard_True if nodal normals are defined.
188 Standard_EXPORT Standard_Boolean HasNormals() const;
190 //! @return normal at the given index.
191 //! Raises Standard_OutOfRange exception.
192 Standard_EXPORT const gp_Dir Normal (const Standard_Integer theIndex) const;
194 //! Changes normal at the given index.
195 //! Raises Standard_OutOfRange exception.
196 Standard_EXPORT void SetNormal (const Standard_Integer theIndex,
197 const gp_Dir& theNormal);
201 Standard_Real myDeflection;
202 TColgp_Array1OfPnt myNodes;
203 Handle(TColgp_HArray1OfPnt2d) myUVNodes;
204 Poly_Array1OfTriangle myTriangles;
205 Handle(TShort_HArray1OfShortReal) myNormals;
209 #endif // _Poly_Triangulation_HeaderFile