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_HeaderFile
18 #define _Poly_HeaderFile
20 #include <Standard.hxx>
21 #include <Standard_DefineAlloc.hxx>
22 #include <Standard_Handle.hxx>
23 #include <Poly_ListOfTriangulation.hxx>
24 #include <Standard_OStream.hxx>
25 #include <Standard_Boolean.hxx>
26 #include <Standard_IStream.hxx>
27 #include <Standard_Real.hxx>
28 #include <TColgp_SequenceOfPnt2d.hxx>
30 class Poly_Triangulation;
35 class Poly_Triangulation;
38 class Poly_PolygonOnTriangulation;
42 //! This package provides classes and services to
45 //! * 3D triangular polyhedrons.
51 //! * Tools to dump, save and restore those objects.
59 //! Computes and stores the link from nodes to
60 //! triangles and from triangles to neighbouring
62 //! This tool is obsolete, replaced by Poly_CoherentTriangulation
63 //! Algorithm to make minimal loops in a graph
64 //! Join several triangulations to one new triangulation object.
65 //! The new triangulation is just a mechanical sum of input
66 //! triangulations, without node sharing. UV coordinates are
67 //! dropped in the result.
68 Standard_EXPORT static Handle(Poly_Triangulation) Catenate (const Poly_ListOfTriangulation& lstTri);
70 //! Writes the content of the triangulation <T> on the
71 //! stream <OS>. If <Compact> is true this is a "save"
72 //! format intended to be read back with the Read
73 //! method. If compact is False it is a "Dump" format
74 //! intended to be informative.
75 Standard_EXPORT static void Write (const Handle(Poly_Triangulation)& T, Standard_OStream& OS, const Standard_Boolean Compact = Standard_True);
77 //! Writes the content of the 3D polygon <P> on the
78 //! stream <OS>. If <Compact> is true this is a "save"
79 //! format intended to be read back with the Read
80 //! method. If compact is False it is a "Dump" format
81 //! intended to be informative.
82 Standard_EXPORT static void Write (const Handle(Poly_Polygon3D)& P, Standard_OStream& OS, const Standard_Boolean Compact = Standard_True);
84 //! Writes the content of the 2D polygon <P> on the
85 //! stream <OS>. If <Compact> is true this is a "save"
86 //! format intended to be read back with the Read
87 //! method. If compact is False it is a "Dump" format
88 //! intended to be informative.
89 Standard_EXPORT static void Write (const Handle(Poly_Polygon2D)& P, Standard_OStream& OS, const Standard_Boolean Compact = Standard_True);
91 //! Dumps the triangulation. This is a call to the
92 //! previous method with Comapct set to False.
93 Standard_EXPORT static void Dump (const Handle(Poly_Triangulation)& T, Standard_OStream& OS);
95 //! Dumps the 3D polygon. This is a call to the
96 //! previous method with Comapct set to False.
97 Standard_EXPORT static void Dump (const Handle(Poly_Polygon3D)& P, Standard_OStream& OS);
99 //! Dumps the 2D polygon. This is a call to the
100 //! previous method with Comapct set to False.
101 Standard_EXPORT static void Dump (const Handle(Poly_Polygon2D)& P, Standard_OStream& OS);
103 //! Reads a triangulation from the stream <IS>.
104 Standard_EXPORT static Handle(Poly_Triangulation) ReadTriangulation (Standard_IStream& IS);
106 //! Reads a 3d polygon from the stream <IS>.
107 Standard_EXPORT static Handle(Poly_Polygon3D) ReadPolygon3D (Standard_IStream& IS);
109 //! Reads a 2D polygon from the stream <IS>.
110 Standard_EXPORT static Handle(Poly_Polygon2D) ReadPolygon2D (Standard_IStream& IS);
112 //! Compute node normals for face triangulation
113 //! as mean normal of surrounding triangles
114 Standard_EXPORT static void ComputeNormals (const Handle(Poly_Triangulation)& Tri);
116 //! Computes parameters of the point P on triangle
117 //! defined by points P1, P2, and P3, in 2d.
118 //! The parameters U and V are defined so that
119 //! P = P1 + U * (P2 - P1) + V * (P3 - P1),
120 //! with U >= 0, V >= 0, U + V <= 1.
121 //! If P is located outside of triangle, or triangle
122 //! is degenerated, the returned parameters correspond
123 //! to closest point, and returned value is square of
124 //! the distance from original point to triangle (0 if
125 //! point is inside).
126 Standard_EXPORT static Standard_Real PointOnTriangle (const gp_XY& P1, const gp_XY& P2, const gp_XY& P3, const gp_XY& P, gp_XY& UV);
129 //! Returns area and perimeter of 2D-polygon given by its vertices.
130 //! theArea will be negative if the polygon is bypassed clockwise
131 //! and will be positive, otherwise. thePerimeter will always be positive.
134 //! The container theSeqPnts of 2D-points gp_Pnt2d must have definition
135 //! for following methods: Length(), Lower(), Upper() and Value(Standard_Integer)
136 //! (e.g. it can be either NCollection_Sequence<gp_Pnt2d> or
137 //! NCollection_Array1<gp_Pnt2d>).
138 template <class TypeSequencePnts>
139 Standard_EXPORT static
140 Standard_Boolean PolygonProperties(const TypeSequencePnts& theSeqPnts,
141 Standard_Real& theArea,
142 Standard_Real& thePerimeter)
144 if (theSeqPnts.Length() < 2)
146 theArea = thePerimeter = 0.0;
147 return Standard_True;
150 Standard_Integer aStartIndex = theSeqPnts.Lower();
151 const gp_XY &aRefPnt = theSeqPnts.Value(aStartIndex++).XY();
152 gp_XY aPrevPt = theSeqPnts.Value(aStartIndex++).XY() - aRefPnt, aCurrPt;
155 thePerimeter = aPrevPt.Modulus();
157 for (Standard_Integer i = aStartIndex; i <= theSeqPnts.Upper(); i++)
159 aCurrPt = theSeqPnts.Value(i).XY() - aRefPnt;
160 const Standard_Real aDelta = aPrevPt.Crossed(aCurrPt);
163 thePerimeter += (aPrevPt - aCurrPt).Modulus();
167 thePerimeter += aPrevPt.Modulus();
169 return Standard_True;
184 friend class Poly_Triangle;
185 friend class Poly_Triangulation;
186 friend class Poly_Polygon3D;
187 friend class Poly_Polygon2D;
188 friend class Poly_PolygonOnTriangulation;
189 friend class Poly_Connect;
199 #endif // _Poly_HeaderFile