|
|
|||
File indexing completed on 2026-09-15 09:16:48
0001 // Created on: 1995-03-06 0002 // Created by: Laurent PAINNOT 0003 // Copyright (c) 1995-1999 Matra Datavision 0004 // Copyright (c) 1999-2014 OPEN CASCADE SAS 0005 // 0006 // This file is part of Open CASCADE Technology software library. 0007 // 0008 // This library is free software; you can redistribute it and/or modify it under 0009 // the terms of the GNU Lesser General Public License version 2.1 as published 0010 // by the Free Software Foundation, with special exception defined in the file 0011 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT 0012 // distribution for complete text of the license and disclaimer of any warranty. 0013 // 0014 // Alternatively, this file may be used under the terms of Open CASCADE 0015 // commercial license or contractual agreement. 0016 0017 #ifndef _Poly_HeaderFile 0018 #define _Poly_HeaderFile 0019 0020 #include <Standard.hxx> 0021 #include <Standard_DefineAlloc.hxx> 0022 #include <Standard_Handle.hxx> 0023 #include <Poly_Triangulation.hxx> 0024 #include <Standard_OStream.hxx> 0025 #include <Standard_Boolean.hxx> 0026 #include <Standard_IStream.hxx> 0027 #include <Standard_Real.hxx> 0028 #include <gp_Pnt2d.hxx> 0029 #include <NCollection_Sequence.hxx> 0030 0031 class Poly_Triangulation; 0032 class Poly_Polygon3D; 0033 class Poly_Polygon2D; 0034 class Poly_Triangle; 0035 0036 //! This package provides classes and services to 0037 //! handle: 0038 //! * 3D triangular polyhedrons. 0039 //! * 3D polygons. 0040 //! * 2D polygon. 0041 //! * Tools to dump, save and restore those objects. 0042 class Poly 0043 { 0044 public: 0045 DEFINE_STANDARD_ALLOC 0046 0047 //! Computes and stores the link from nodes to 0048 //! triangles and from triangles to neighbouring 0049 //! triangles. 0050 //! This tool is obsolete, replaced by Poly_CoherentTriangulation 0051 //! Algorithm to make minimal loops in a graph 0052 //! Join several triangulations to one new triangulation object. 0053 //! The new triangulation is just a mechanical sum of input 0054 //! triangulations, without node sharing. UV coordinates are 0055 //! dropped in the result. 0056 Standard_EXPORT static occ::handle<Poly_Triangulation> Catenate( 0057 const NCollection_List<occ::handle<Poly_Triangulation>>& lstTri); 0058 0059 //! Writes the content of the triangulation <T> on the 0060 //! stream <OS>. If <Compact> is true this is a "save" 0061 //! format intended to be read back with the Read 0062 //! method. If compact is False it is a "Dump" format 0063 //! intended to be informative. 0064 Standard_EXPORT static void Write(const occ::handle<Poly_Triangulation>& T, 0065 Standard_OStream& OS, 0066 const bool Compact = true); 0067 0068 //! Writes the content of the 3D polygon <P> on the 0069 //! stream <OS>. If <Compact> is true this is a "save" 0070 //! format intended to be read back with the Read 0071 //! method. If compact is False it is a "Dump" format 0072 //! intended to be informative. 0073 Standard_EXPORT static void Write(const occ::handle<Poly_Polygon3D>& P, 0074 Standard_OStream& OS, 0075 const bool Compact = true); 0076 0077 //! Writes the content of the 2D polygon <P> on the 0078 //! stream <OS>. If <Compact> is true this is a "save" 0079 //! format intended to be read back with the Read 0080 //! method. If compact is False it is a "Dump" format 0081 //! intended to be informative. 0082 Standard_EXPORT static void Write(const occ::handle<Poly_Polygon2D>& P, 0083 Standard_OStream& OS, 0084 const bool Compact = true); 0085 0086 //! Dumps the triangulation. This is a call to the 0087 //! previous method with Comapct set to False. 0088 Standard_EXPORT static void Dump(const occ::handle<Poly_Triangulation>& T, Standard_OStream& OS); 0089 0090 //! Dumps the 3D polygon. This is a call to the 0091 //! previous method with Comapct set to False. 0092 Standard_EXPORT static void Dump(const occ::handle<Poly_Polygon3D>& P, Standard_OStream& OS); 0093 0094 //! Dumps the 2D polygon. This is a call to the 0095 //! previous method with Comapct set to False. 0096 Standard_EXPORT static void Dump(const occ::handle<Poly_Polygon2D>& P, Standard_OStream& OS); 0097 0098 //! Reads a triangulation from the stream <IS>. 0099 Standard_EXPORT static occ::handle<Poly_Triangulation> ReadTriangulation(Standard_IStream& IS); 0100 0101 //! Reads a 3d polygon from the stream <IS>. 0102 Standard_EXPORT static occ::handle<Poly_Polygon3D> ReadPolygon3D(Standard_IStream& IS); 0103 0104 //! Reads a 2D polygon from the stream <IS>. 0105 Standard_EXPORT static occ::handle<Poly_Polygon2D> ReadPolygon2D(Standard_IStream& IS); 0106 0107 //! Compute node normals for face triangulation 0108 //! as mean normal of surrounding triangles 0109 Standard_EXPORT static void ComputeNormals(const occ::handle<Poly_Triangulation>& Tri); 0110 0111 //! Computes parameters of the point P on triangle 0112 //! defined by points P1, P2, and P3, in 2d. 0113 //! The parameters U and V are defined so that 0114 //! P = P1 + U * (P2 - P1) + V * (P3 - P1), 0115 //! with U >= 0, V >= 0, U + V <= 1. 0116 //! If P is located outside of triangle, or triangle 0117 //! is degenerated, the returned parameters correspond 0118 //! to closest point, and returned value is square of 0119 //! the distance from original point to triangle (0 if 0120 //! point is inside). 0121 Standard_EXPORT static double PointOnTriangle(const gp_XY& P1, 0122 const gp_XY& P2, 0123 const gp_XY& P3, 0124 const gp_XY& P, 0125 gp_XY& UV); 0126 0127 //! Computes the intersection between axis and triangulation. 0128 //! @param[in] theTri input triangulation 0129 //! @param[in] theAxis intersecting ray 0130 //! @param[in] theIsClosest finds the closest intersection when TRUE, finds the farthest 0131 //! otherwise 0132 //! @param[out] theTriangle intersected triangle 0133 //! @param[out] theDistance distance along ray to intersection point 0134 //! @return TRUE if intersection takes place, FALSE otherwise. 0135 Standard_EXPORT static bool Intersect(const occ::handle<Poly_Triangulation>& theTri, 0136 const gp_Ax1& theAxis, 0137 const bool theIsClosest, 0138 Poly_Triangle& theTriangle, 0139 double& theDistance); 0140 0141 //! Computes the intersection between a triangle defined by three vertexes and a line. 0142 //! @param[in] theStart picking ray origin 0143 //! @param[in] theDir picking ray direction 0144 //! @param[in] theV0 first triangle node 0145 //! @param[in] theV1 second triangle node 0146 //! @param[in] theV2 third triangle node 0147 //! @param[out] theParam param on line of the intersection point 0148 //! @return 1 if intersection was found, 0 otherwise. 0149 Standard_EXPORT static int IntersectTriLine(const gp_XYZ& theStart, 0150 const gp_Dir& theDir, 0151 const gp_XYZ& theV0, 0152 const gp_XYZ& theV1, 0153 const gp_XYZ& theV2, 0154 double& theParam); 0155 0156 //! Returns area and perimeter of 2D-polygon given by its vertices. 0157 //! theArea will be negative if the polygon is bypassed clockwise 0158 //! and will be positive, otherwise. thePerimeter will always be positive. 0159 //! 0160 //! ATTENTION!!! 0161 //! The container theSeqPnts of 2D-points gp_Pnt2d must have definition 0162 //! for following methods: Length(), Lower(), Upper() and Value(int) 0163 //! (e.g. it can be either NCollection_Sequence<gp_Pnt2d> or 0164 //! NCollection_Array1<gp_Pnt2d>). 0165 template <class TypeSequencePnts> 0166 Standard_EXPORT static bool PolygonProperties(const TypeSequencePnts& theSeqPnts, 0167 double& theArea, 0168 double& thePerimeter) 0169 { 0170 if (theSeqPnts.Length() < 2) 0171 { 0172 theArea = thePerimeter = 0.0; 0173 return true; 0174 } 0175 0176 int aStartIndex = theSeqPnts.Lower(); 0177 const gp_XY& aRefPnt = theSeqPnts.Value(aStartIndex++).XY(); 0178 gp_XY aPrevPt = theSeqPnts.Value(aStartIndex++).XY() - aRefPnt, aCurrPt; 0179 0180 theArea = 0.0; 0181 thePerimeter = aPrevPt.Modulus(); 0182 0183 for (int i = aStartIndex; i <= theSeqPnts.Upper(); i++) 0184 { 0185 aCurrPt = theSeqPnts.Value(i).XY() - aRefPnt; 0186 const double aDelta = aPrevPt.Crossed(aCurrPt); 0187 0188 theArea += aDelta; 0189 thePerimeter += (aPrevPt - aCurrPt).Modulus(); 0190 aPrevPt = aCurrPt; 0191 } 0192 0193 thePerimeter += aPrevPt.Modulus(); 0194 theArea *= 0.5; 0195 return true; 0196 } 0197 }; 0198 0199 #endif // _Poly_HeaderFile
| [ Source navigation ] | [ Diff markup ] | [ Identifier search ] | [ general search ] |
|
This page was automatically generated by the 2.3.7 LXR engine. The LXR team |
|