|
||||
File indexing completed on 2025-01-18 10:04:38
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_ListOfTriangulation.hxx> 0024 #include <Standard_OStream.hxx> 0025 #include <Standard_Boolean.hxx> 0026 #include <Standard_IStream.hxx> 0027 #include <Standard_Real.hxx> 0028 #include <TColgp_SequenceOfPnt2d.hxx> 0029 0030 class Poly_Triangulation; 0031 class Poly_Polygon3D; 0032 class Poly_Polygon2D; 0033 class Poly_Triangle; 0034 0035 0036 //! This package provides classes and services to 0037 //! handle : 0038 //! 0039 //! * 3D triangular polyhedrons. 0040 //! 0041 //! * 3D polygons. 0042 //! 0043 //! * 2D polygon. 0044 //! 0045 //! * Tools to dump, save and restore those objects. 0046 class Poly 0047 { 0048 public: 0049 0050 DEFINE_STANDARD_ALLOC 0051 0052 0053 //! Computes and stores the link from nodes to 0054 //! triangles and from triangles to neighbouring 0055 //! triangles. 0056 //! This tool is obsolete, replaced by Poly_CoherentTriangulation 0057 //! Algorithm to make minimal loops in a graph 0058 //! Join several triangulations to one new triangulation object. 0059 //! The new triangulation is just a mechanical sum of input 0060 //! triangulations, without node sharing. UV coordinates are 0061 //! dropped in the result. 0062 Standard_EXPORT static Handle(Poly_Triangulation) Catenate (const Poly_ListOfTriangulation& lstTri); 0063 0064 //! Writes the content of the triangulation <T> on the 0065 //! stream <OS>. If <Compact> is true this is a "save" 0066 //! format intended to be read back with the Read 0067 //! method. If compact is False it is a "Dump" format 0068 //! intended to be informative. 0069 Standard_EXPORT static void Write (const Handle(Poly_Triangulation)& T, Standard_OStream& OS, const Standard_Boolean Compact = Standard_True); 0070 0071 //! Writes the content of the 3D polygon <P> on the 0072 //! stream <OS>. If <Compact> is true this is a "save" 0073 //! format intended to be read back with the Read 0074 //! method. If compact is False it is a "Dump" format 0075 //! intended to be informative. 0076 Standard_EXPORT static void Write (const Handle(Poly_Polygon3D)& P, Standard_OStream& OS, const Standard_Boolean Compact = Standard_True); 0077 0078 //! Writes the content of the 2D polygon <P> on the 0079 //! stream <OS>. If <Compact> is true this is a "save" 0080 //! format intended to be read back with the Read 0081 //! method. If compact is False it is a "Dump" format 0082 //! intended to be informative. 0083 Standard_EXPORT static void Write (const Handle(Poly_Polygon2D)& P, Standard_OStream& OS, const Standard_Boolean Compact = Standard_True); 0084 0085 //! Dumps the triangulation. This is a call to the 0086 //! previous method with Comapct set to False. 0087 Standard_EXPORT static void Dump (const Handle(Poly_Triangulation)& T, Standard_OStream& OS); 0088 0089 //! Dumps the 3D polygon. This is a call to the 0090 //! previous method with Comapct set to False. 0091 Standard_EXPORT static void Dump (const Handle(Poly_Polygon3D)& P, Standard_OStream& OS); 0092 0093 //! Dumps the 2D polygon. This is a call to the 0094 //! previous method with Comapct set to False. 0095 Standard_EXPORT static void Dump (const Handle(Poly_Polygon2D)& P, Standard_OStream& OS); 0096 0097 //! Reads a triangulation from the stream <IS>. 0098 Standard_EXPORT static Handle(Poly_Triangulation) ReadTriangulation (Standard_IStream& IS); 0099 0100 //! Reads a 3d polygon from the stream <IS>. 0101 Standard_EXPORT static Handle(Poly_Polygon3D) ReadPolygon3D (Standard_IStream& IS); 0102 0103 //! Reads a 2D polygon from the stream <IS>. 0104 Standard_EXPORT static Handle(Poly_Polygon2D) ReadPolygon2D (Standard_IStream& IS); 0105 0106 //! Compute node normals for face triangulation 0107 //! as mean normal of surrounding triangles 0108 Standard_EXPORT static void ComputeNormals (const Handle(Poly_Triangulation)& Tri); 0109 0110 //! Computes parameters of the point P on triangle 0111 //! defined by points P1, P2, and P3, in 2d. 0112 //! The parameters U and V are defined so that 0113 //! P = P1 + U * (P2 - P1) + V * (P3 - P1), 0114 //! with U >= 0, V >= 0, U + V <= 1. 0115 //! If P is located outside of triangle, or triangle 0116 //! is degenerated, the returned parameters correspond 0117 //! to closest point, and returned value is square of 0118 //! the distance from original point to triangle (0 if 0119 //! point is inside). 0120 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); 0121 0122 //! Computes the intersection between axis and triangulation. 0123 //! @param theTri [in] input triangulation 0124 //! @param theAxis [in] intersecting ray 0125 //! @param theIsClosest [in] finds the closest intersection when TRUE, finds the farthest otherwise 0126 //! @param theTriangle [out] intersected triangle 0127 //! @param theDistance [out] distance along ray to intersection point 0128 //! @return TRUE if intersection takes place, FALSE otherwise. 0129 Standard_EXPORT static Standard_Boolean Intersect (const Handle(Poly_Triangulation)& theTri, 0130 const gp_Ax1& theAxis, 0131 const Standard_Boolean theIsClosest, 0132 Poly_Triangle& theTriangle, 0133 Standard_Real& theDistance); 0134 0135 //! Computes the intersection between a triangle defined by three vertexes and a line. 0136 //! @param theStart [in] picking ray origin 0137 //! @param theDir [in] picking ray direction 0138 //! @param theV0 [in] first triangle node 0139 //! @param theV1 [in] second triangle node 0140 //! @param theV2 [in] third triangle node 0141 //! @param theParam [out] param on line of the intersection point 0142 //! @return 1 if intersection was found, 0 otherwise. 0143 Standard_EXPORT static Standard_Integer IntersectTriLine (const gp_XYZ& theStart, 0144 const gp_Dir& theDir, 0145 const gp_XYZ& theV0, 0146 const gp_XYZ& theV1, 0147 const gp_XYZ& theV2, 0148 Standard_Real& theParam); 0149 0150 //! Returns area and perimeter of 2D-polygon given by its vertices. 0151 //! theArea will be negative if the polygon is bypassed clockwise 0152 //! and will be positive, otherwise. thePerimeter will always be positive. 0153 //! 0154 //! ATTENTION!!! 0155 //! The container theSeqPnts of 2D-points gp_Pnt2d must have definition 0156 //! for following methods: Length(), Lower(), Upper() and Value(Standard_Integer) 0157 //! (e.g. it can be either NCollection_Sequence<gp_Pnt2d> or 0158 //! NCollection_Array1<gp_Pnt2d>). 0159 template <class TypeSequencePnts> 0160 Standard_EXPORT static 0161 Standard_Boolean PolygonProperties(const TypeSequencePnts& theSeqPnts, 0162 Standard_Real& theArea, 0163 Standard_Real& thePerimeter) 0164 { 0165 if (theSeqPnts.Length() < 2) 0166 { 0167 theArea = thePerimeter = 0.0; 0168 return Standard_True; 0169 } 0170 0171 Standard_Integer aStartIndex = theSeqPnts.Lower(); 0172 const gp_XY &aRefPnt = theSeqPnts.Value(aStartIndex++).XY(); 0173 gp_XY aPrevPt = theSeqPnts.Value(aStartIndex++).XY() - aRefPnt, aCurrPt; 0174 0175 theArea = 0.0; 0176 thePerimeter = aPrevPt.Modulus(); 0177 0178 for (Standard_Integer i = aStartIndex; i <= theSeqPnts.Upper(); i++) 0179 { 0180 aCurrPt = theSeqPnts.Value(i).XY() - aRefPnt; 0181 const Standard_Real aDelta = aPrevPt.Crossed(aCurrPt); 0182 0183 theArea += aDelta; 0184 thePerimeter += (aPrevPt - aCurrPt).Modulus(); 0185 aPrevPt = aCurrPt; 0186 } 0187 0188 thePerimeter += aPrevPt.Modulus(); 0189 theArea *= 0.5; 0190 return Standard_True; 0191 } 0192 0193 }; 0194 0195 #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 |