0033661: Data Exchange, Step Import - Tessellated GDTs are not imported
[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;
42cf5bc1 33class Poly_Triangle;
42cf5bc1 34
35
36//! This package provides classes and services to
37//! handle :
38//!
39//! * 3D triangular polyhedrons.
40//!
41//! * 3D polygons.
42//!
43//! * 2D polygon.
44//!
45//! * Tools to dump, save and restore those objects.
46class Poly
47{
48public:
49
50 DEFINE_STANDARD_ALLOC
51
52
53 //! Computes and stores the link from nodes to
54 //! triangles and from triangles to neighbouring
55 //! triangles.
56 //! This tool is obsolete, replaced by Poly_CoherentTriangulation
57 //! Algorithm to make minimal loops in a graph
58 //! Join several triangulations to one new triangulation object.
59 //! The new triangulation is just a mechanical sum of input
60 //! triangulations, without node sharing. UV coordinates are
61 //! dropped in the result.
62 Standard_EXPORT static Handle(Poly_Triangulation) Catenate (const Poly_ListOfTriangulation& lstTri);
63
64 //! Writes the content of the triangulation <T> on the
65 //! stream <OS>. If <Compact> is true this is a "save"
66 //! format intended to be read back with the Read
67 //! method. If compact is False it is a "Dump" format
68 //! intended to be informative.
69 Standard_EXPORT static void Write (const Handle(Poly_Triangulation)& T, Standard_OStream& OS, const Standard_Boolean Compact = Standard_True);
70
71 //! Writes the content of the 3D polygon <P> on the
72 //! stream <OS>. If <Compact> is true this is a "save"
73 //! format intended to be read back with the Read
74 //! method. If compact is False it is a "Dump" format
75 //! intended to be informative.
76 Standard_EXPORT static void Write (const Handle(Poly_Polygon3D)& P, Standard_OStream& OS, const Standard_Boolean Compact = Standard_True);
77
78 //! Writes the content of the 2D polygon <P> on the
79 //! stream <OS>. If <Compact> is true this is a "save"
80 //! format intended to be read back with the Read
81 //! method. If compact is False it is a "Dump" format
82 //! intended to be informative.
83 Standard_EXPORT static void Write (const Handle(Poly_Polygon2D)& P, Standard_OStream& OS, const Standard_Boolean Compact = Standard_True);
84
85 //! Dumps the triangulation. This is a call to the
86 //! previous method with Comapct set to False.
87 Standard_EXPORT static void Dump (const Handle(Poly_Triangulation)& T, Standard_OStream& OS);
88
89 //! Dumps the 3D polygon. This is a call to the
90 //! previous method with Comapct set to False.
91 Standard_EXPORT static void Dump (const Handle(Poly_Polygon3D)& P, Standard_OStream& OS);
92
93 //! Dumps the 2D polygon. This is a call to the
94 //! previous method with Comapct set to False.
95 Standard_EXPORT static void Dump (const Handle(Poly_Polygon2D)& P, Standard_OStream& OS);
96
97 //! Reads a triangulation from the stream <IS>.
98 Standard_EXPORT static Handle(Poly_Triangulation) ReadTriangulation (Standard_IStream& IS);
99
100 //! Reads a 3d polygon from the stream <IS>.
101 Standard_EXPORT static Handle(Poly_Polygon3D) ReadPolygon3D (Standard_IStream& IS);
102
103 //! Reads a 2D polygon from the stream <IS>.
104 Standard_EXPORT static Handle(Poly_Polygon2D) ReadPolygon2D (Standard_IStream& IS);
105
106 //! Compute node normals for face triangulation
107 //! as mean normal of surrounding triangles
108 Standard_EXPORT static void ComputeNormals (const Handle(Poly_Triangulation)& Tri);
109
110 //! Computes parameters of the point P on triangle
111 //! defined by points P1, P2, and P3, in 2d.
112 //! The parameters U and V are defined so that
113 //! P = P1 + U * (P2 - P1) + V * (P3 - P1),
114 //! with U >= 0, V >= 0, U + V <= 1.
115 //! If P is located outside of triangle, or triangle
116 //! is degenerated, the returned parameters correspond
117 //! to closest point, and returned value is square of
118 //! the distance from original point to triangle (0 if
119 //! point is inside).
120 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);
121
f7ad1e7e 122 //! Computes the intersection between axis and triangulation.
123 //! @param theTri [in] input triangulation
124 //! @param theAxis [in] intersecting ray
125 //! @param theIsClosest [in] finds the closest intersection when TRUE, finds the farthest otherwise
126 //! @param theTriangle [out] intersected triangle
127 //! @param theDistance [out] distance along ray to intersection point
128 //! @return TRUE if intersection takes place, FALSE otherwise.
129 Standard_EXPORT static Standard_Boolean Intersect (const Handle(Poly_Triangulation)& theTri,
130 const gp_Ax1& theAxis,
131 const Standard_Boolean theIsClosest,
132 Poly_Triangle& theTriangle,
133 Standard_Real& theDistance);
134
135 //! Computes the intersection between a triangle defined by three vertexes and a line.
136 //! @param theStart [in] picking ray origin
137 //! @param theDir [in] picking ray direction
138 //! @param theV0 [in] first triangle node
139 //! @param theV1 [in] second triangle node
140 //! @param theV2 [in] third triangle node
141 //! @param theParam [out] param on line of the intersection point
142 //! @return 1 if intersection was found, 0 otherwise.
143 Standard_EXPORT static Standard_Integer IntersectTriLine (const gp_XYZ& theStart,
144 const gp_Dir& theDir,
145 const gp_XYZ& theV0,
146 const gp_XYZ& theV1,
147 const gp_XYZ& theV2,
148 Standard_Real& theParam);
42cf5bc1 149
5fe14d0f 150 //! Returns area and perimeter of 2D-polygon given by its vertices.
151 //! theArea will be negative if the polygon is bypassed clockwise
152 //! and will be positive, otherwise. thePerimeter will always be positive.
153 //!
154 //! ATTENTION!!!
155 //! The container theSeqPnts of 2D-points gp_Pnt2d must have definition
156 //! for following methods: Length(), Lower(), Upper() and Value(Standard_Integer)
157 //! (e.g. it can be either NCollection_Sequence<gp_Pnt2d> or
158 //! NCollection_Array1<gp_Pnt2d>).
159 template <class TypeSequencePnts>
160 Standard_EXPORT static
161 Standard_Boolean PolygonProperties(const TypeSequencePnts& theSeqPnts,
162 Standard_Real& theArea,
163 Standard_Real& thePerimeter)
164 {
165 if (theSeqPnts.Length() < 2)
166 {
167 theArea = thePerimeter = 0.0;
168 return Standard_True;
169 }
170
171 Standard_Integer aStartIndex = theSeqPnts.Lower();
172 const gp_XY &aRefPnt = theSeqPnts.Value(aStartIndex++).XY();
173 gp_XY aPrevPt = theSeqPnts.Value(aStartIndex++).XY() - aRefPnt, aCurrPt;
174
175 theArea = 0.0;
176 thePerimeter = aPrevPt.Modulus();
177
178 for (Standard_Integer i = aStartIndex; i <= theSeqPnts.Upper(); i++)
179 {
180 aCurrPt = theSeqPnts.Value(i).XY() - aRefPnt;
181 const Standard_Real aDelta = aPrevPt.Crossed(aCurrPt);
182
183 theArea += aDelta;
184 thePerimeter += (aPrevPt - aCurrPt).Modulus();
185 aPrevPt = aCurrPt;
186 }
187
188 thePerimeter += aPrevPt.Modulus();
189 theArea *= 0.5;
190 return Standard_True;
191 }
42cf5bc1 192
42cf5bc1 193};
194
42cf5bc1 195#endif // _Poly_HeaderFile