0031668: Visualization - WebGL sample doesn't work on Emscripten 1.39
[occt.git] / src / Poly / Poly.hxx
CommitLineData
42cf5bc1 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
5//
6// This file is part of Open CASCADE Technology software library.
7//
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.
13//
14// Alternatively, this file may be used under the terms of Open CASCADE
15// commercial license or contractual agreement.
16
17#ifndef _Poly_HeaderFile
18#define _Poly_HeaderFile
19
20#include <Standard.hxx>
21#include <Standard_DefineAlloc.hxx>
22#include <Standard_Handle.hxx>
42cf5bc1 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>
5fe14d0f 28#include <TColgp_SequenceOfPnt2d.hxx>
29
42cf5bc1 30class Poly_Triangulation;
31class Poly_Polygon3D;
32class Poly_Polygon2D;
33class gp_XY;
34class Poly_Triangle;
35class Poly_Triangulation;
36class Poly_Polygon3D;
37class Poly_Polygon2D;
38class Poly_PolygonOnTriangulation;
39class Poly_Connect;
40
41
42//! This package provides classes and services to
43//! handle :
44//!
45//! * 3D triangular polyhedrons.
46//!
47//! * 3D polygons.
48//!
49//! * 2D polygon.
50//!
51//! * Tools to dump, save and restore those objects.
52class Poly
53{
54public:
55
56 DEFINE_STANDARD_ALLOC
57
58
59 //! Computes and stores the link from nodes to
60 //! triangles and from triangles to neighbouring
61 //! triangles.
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);
69
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);
76
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);
83
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);
90
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);
94
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);
98
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);
102
103 //! Reads a triangulation from the stream <IS>.
104 Standard_EXPORT static Handle(Poly_Triangulation) ReadTriangulation (Standard_IStream& IS);
105
106 //! Reads a 3d polygon from the stream <IS>.
107 Standard_EXPORT static Handle(Poly_Polygon3D) ReadPolygon3D (Standard_IStream& IS);
108
109 //! Reads a 2D polygon from the stream <IS>.
110 Standard_EXPORT static Handle(Poly_Polygon2D) ReadPolygon2D (Standard_IStream& IS);
111
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);
115
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);
127
128
5fe14d0f 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.
132 //!
133 //! ATTENTION!!!
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)
143 {
144 if (theSeqPnts.Length() < 2)
145 {
146 theArea = thePerimeter = 0.0;
147 return Standard_True;
148 }
149
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;
153
154 theArea = 0.0;
155 thePerimeter = aPrevPt.Modulus();
156
157 for (Standard_Integer i = aStartIndex; i <= theSeqPnts.Upper(); i++)
158 {
159 aCurrPt = theSeqPnts.Value(i).XY() - aRefPnt;
160 const Standard_Real aDelta = aPrevPt.Crossed(aCurrPt);
161
162 theArea += aDelta;
163 thePerimeter += (aPrevPt - aCurrPt).Modulus();
164 aPrevPt = aCurrPt;
165 }
166
167 thePerimeter += aPrevPt.Modulus();
168 theArea *= 0.5;
169 return Standard_True;
170 }
42cf5bc1 171
172
173protected:
174
175
176
177
178
179private:
180
181
182
183
184friend class Poly_Triangle;
185friend class Poly_Triangulation;
186friend class Poly_Polygon3D;
187friend class Poly_Polygon2D;
188friend class Poly_PolygonOnTriangulation;
189friend class Poly_Connect;
190
191};
192
193
194
195
196
197
198
199#endif // _Poly_HeaderFile