mirror of
https://git.dev.opencascade.org/repos/occt.git
synced 2025-09-03 14:10:33 +03:00
OCC22357 Hidden face selection
This commit is contained in:
@@ -1,5 +1,4 @@
|
||||
|
||||
-- -- File: Poly.cdl
|
||||
-- File: Poly.cdl
|
||||
-- Created: Mon Mar 6 09:38:50 1995
|
||||
-- Author: Laurent PAINNOT
|
||||
-- <lpa@metrox>
|
||||
@@ -7,17 +6,17 @@
|
||||
|
||||
|
||||
|
||||
package Poly
|
||||
package Poly
|
||||
|
||||
---Purpose: This package provides classes and services to
|
||||
-- handle :
|
||||
--
|
||||
--
|
||||
-- * 3D triangular polyhedrons.
|
||||
--
|
||||
--
|
||||
-- * 3D polygons.
|
||||
--
|
||||
--
|
||||
-- * 2D polygon.
|
||||
--
|
||||
--
|
||||
-- * Tools to dump, save and restore those objects.
|
||||
|
||||
uses
|
||||
@@ -26,7 +25,7 @@ uses
|
||||
TCollection,
|
||||
TColStd,
|
||||
gp,
|
||||
TColgp,
|
||||
TColgp,
|
||||
TShort
|
||||
|
||||
is
|
||||
@@ -37,7 +36,7 @@ is
|
||||
|
||||
class Array1OfTriangle
|
||||
instantiates Array1 from TCollection(Triangle from Poly);
|
||||
|
||||
|
||||
class HArray1OfTriangle
|
||||
instantiates HArray1 from TCollection(Triangle from Poly,
|
||||
Array1OfTriangle from Poly);
|
||||
@@ -47,7 +46,7 @@ is
|
||||
-- triangles. It is made of a nodes which are
|
||||
-- indexed. Nodes have a 3d value and a 2d value.
|
||||
-- Triangles are triplet of node indices.
|
||||
--
|
||||
--
|
||||
-- This is a Transient class.
|
||||
|
||||
|
||||
@@ -64,10 +63,10 @@ is
|
||||
-- referencing a triangulation.
|
||||
|
||||
|
||||
--
|
||||
--
|
||||
-- Tools to use triangulations
|
||||
--
|
||||
|
||||
--
|
||||
|
||||
class Connect;
|
||||
---Purpose: Computes and stores the link from nodes to
|
||||
-- triangles and from triangles to neighbouring
|
||||
@@ -89,8 +88,8 @@ is
|
||||
|
||||
--
|
||||
-- Package methods
|
||||
--
|
||||
|
||||
--
|
||||
|
||||
Catenate (lstTri: ListOfTriangulation from Poly)
|
||||
returns Triangulation from Poly;
|
||||
---Purpose: Join several triangulations to one new triangulation object.
|
||||
@@ -101,7 +100,7 @@ is
|
||||
Write(T : Triangulation from Poly;
|
||||
OS : in out OStream;
|
||||
Compact : Boolean = Standard_True);
|
||||
|
||||
|
||||
---Purpose: Writes the content of the triangulation <T> on the
|
||||
-- stream <OS>. If <Compact> is true this is a "save"
|
||||
-- format intended to be read back with the Read
|
||||
@@ -111,7 +110,7 @@ is
|
||||
Write(P : Polygon3D from Poly;
|
||||
OS : in out OStream;
|
||||
Compact : Boolean = Standard_True);
|
||||
|
||||
|
||||
---Purpose: Writes the content of the 3D polygon <P> on the
|
||||
-- stream <OS>. If <Compact> is true this is a "save"
|
||||
-- format intended to be read back with the Read
|
||||
@@ -121,7 +120,7 @@ is
|
||||
Write(P : Polygon2D from Poly;
|
||||
OS : in out OStream;
|
||||
Compact : Boolean = Standard_True);
|
||||
|
||||
|
||||
---Purpose: Writes the content of the 2D polygon <P> on the
|
||||
-- stream <OS>. If <Compact> is true this is a "save"
|
||||
-- format intended to be read back with the Read
|
||||
@@ -133,32 +132,45 @@ is
|
||||
OS : in out OStream);
|
||||
---Purpose: Dumps the triangulation. This is a call to the
|
||||
-- previous method with Comapct set to False.
|
||||
|
||||
|
||||
Dump(P : Polygon3D from Poly;
|
||||
OS : in out OStream);
|
||||
---Purpose: Dumps the 3D polygon. This is a call to the
|
||||
-- previous method with Comapct set to False.
|
||||
|
||||
|
||||
Dump(P : Polygon2D from Poly;
|
||||
OS : in out OStream);
|
||||
---Purpose: Dumps the 2D polygon. This is a call to the
|
||||
-- previous method with Comapct set to False.
|
||||
|
||||
|
||||
|
||||
ReadTriangulation(IS : in out IStream)
|
||||
returns Triangulation from Poly;
|
||||
---Purpose: Reads a triangulation from the stream <IS>.
|
||||
|
||||
|
||||
ReadPolygon3D(IS : in out IStream)
|
||||
returns Polygon3D from Poly;
|
||||
---Purpose: Reads a 3d polygon from the stream <IS>.
|
||||
|
||||
|
||||
ReadPolygon2D(IS : in out IStream)
|
||||
returns Polygon2D from Poly;
|
||||
---Purpose: Reads a 2D polygon from the stream <IS>.
|
||||
|
||||
ComputeNormals(Tri : Triangulation from Poly);
|
||||
---Purpose: Compute node normals for face triangulation
|
||||
---Purpose: Compute node normals for face triangulation
|
||||
-- as mean normal of surrounding triangles
|
||||
|
||||
|
||||
PointOnTriangle(P1, P2, P3, P: XY from gp; UV: out XY from gp)
|
||||
returns Real;
|
||||
---Purpose: Computes parameters of the point P on triangle
|
||||
-- defined by points P1, P2, and P3, in 2d.
|
||||
-- The parameters U and V are defined so that
|
||||
-- P = P1 + U * (P2 - P1) + V * (P3 - P1),
|
||||
-- with U >= 0, V >= 0, U + V <= 1.
|
||||
-- If P is located outside of triangle, or triangle
|
||||
-- is degenerated, the returned parameters correspond
|
||||
-- to closest point, and returned value is square of
|
||||
-- the distance from original point to triangle (0 if
|
||||
-- point is inside).
|
||||
|
||||
end Poly;
|
||||
|
@@ -25,8 +25,7 @@
|
||||
//purpose : Join several triangulations to one new triangulation object
|
||||
//=======================================================================
|
||||
|
||||
Handle(Poly_Triangulation) Poly::Catenate
|
||||
(const Poly_ListOfTriangulation& lstTri)
|
||||
Handle(Poly_Triangulation) Poly::Catenate (const Poly_ListOfTriangulation& lstTri)
|
||||
{
|
||||
Standard_Integer nNodes(0);
|
||||
Standard_Integer nTrian(0);
|
||||
@@ -75,11 +74,11 @@ Handle(Poly_Triangulation) Poly::Catenate
|
||||
|
||||
//=======================================================================
|
||||
//function : Write
|
||||
//purpose :
|
||||
//purpose :
|
||||
//=======================================================================
|
||||
|
||||
void Poly::Write(const Handle(Poly_Triangulation)& T,
|
||||
Standard_OStream& OS,
|
||||
void Poly::Write(const Handle(Poly_Triangulation)& T,
|
||||
Standard_OStream& OS,
|
||||
const Standard_Boolean Compact)
|
||||
{
|
||||
OS << "Poly_Triangulation\n";
|
||||
@@ -125,7 +124,7 @@ void Poly::Write(const Handle(Poly_Triangulation)& T,
|
||||
OS << UVNodes(i).Y() << "\n";
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (!Compact) OS << "\nTriangles :\n";
|
||||
Standard_Integer nbTriangles = T->NbTriangles();
|
||||
Standard_Integer n1, n2, n3;
|
||||
@@ -145,11 +144,11 @@ void Poly::Write(const Handle(Poly_Triangulation)& T,
|
||||
|
||||
//=======================================================================
|
||||
//function : Write
|
||||
//purpose :
|
||||
//purpose :
|
||||
//=======================================================================
|
||||
|
||||
void Poly::Write(const Handle(Poly_Polygon3D)& P,
|
||||
Standard_OStream& OS,
|
||||
void Poly::Write(const Handle(Poly_Polygon3D)& P,
|
||||
Standard_OStream& OS,
|
||||
const Standard_Boolean Compact)
|
||||
{
|
||||
OS << "Poly_Polygon3D\n";
|
||||
@@ -198,11 +197,11 @@ void Poly::Write(const Handle(Poly_Polygon3D)& P,
|
||||
|
||||
//=======================================================================
|
||||
//function : Write
|
||||
//purpose :
|
||||
//purpose :
|
||||
//=======================================================================
|
||||
|
||||
void Poly::Write(const Handle(Poly_Polygon2D)& P,
|
||||
Standard_OStream& OS,
|
||||
void Poly::Write(const Handle(Poly_Polygon2D)& P,
|
||||
Standard_OStream& OS,
|
||||
const Standard_Boolean Compact)
|
||||
{
|
||||
OS << "Poly_Polygon2D\n";
|
||||
@@ -237,7 +236,7 @@ void Poly::Write(const Handle(Poly_Polygon2D)& P,
|
||||
|
||||
//=======================================================================
|
||||
//function : Dump
|
||||
//purpose :
|
||||
//purpose :
|
||||
//=======================================================================
|
||||
|
||||
void Poly::Dump(const Handle(Poly_Triangulation)& T, Standard_OStream& OS)
|
||||
@@ -248,7 +247,7 @@ void Poly::Dump(const Handle(Poly_Triangulation)& T, Standard_OStream& OS)
|
||||
|
||||
//=======================================================================
|
||||
//function : Dump
|
||||
//purpose :
|
||||
//purpose :
|
||||
//=======================================================================
|
||||
|
||||
void Poly::Dump(const Handle(Poly_Polygon3D)& P, Standard_OStream& OS)
|
||||
@@ -259,7 +258,7 @@ void Poly::Dump(const Handle(Poly_Polygon3D)& P, Standard_OStream& OS)
|
||||
|
||||
//=======================================================================
|
||||
//function : Dump
|
||||
//purpose :
|
||||
//purpose :
|
||||
//=======================================================================
|
||||
|
||||
void Poly::Dump(const Handle(Poly_Polygon2D)& P, Standard_OStream& OS)
|
||||
@@ -270,13 +269,13 @@ void Poly::Dump(const Handle(Poly_Polygon2D)& P, Standard_OStream& OS)
|
||||
|
||||
//=======================================================================
|
||||
//function : ReadTriangulation
|
||||
//purpose :
|
||||
//purpose :
|
||||
//=======================================================================
|
||||
|
||||
Handle(Poly_Triangulation) Poly::ReadTriangulation(Standard_IStream& IS)
|
||||
{
|
||||
// Read a triangulation
|
||||
|
||||
|
||||
char line[100];
|
||||
IS >> line;
|
||||
if (strcmp(line,"Poly_Triangulation")) {
|
||||
@@ -320,7 +319,7 @@ Handle(Poly_Triangulation) Poly::ReadTriangulation(Standard_IStream& IS)
|
||||
Triangles(i).Set(n1,n2,n3);
|
||||
}
|
||||
|
||||
|
||||
|
||||
Handle(Poly_Triangulation) T;
|
||||
|
||||
if (hasUV) T = new Poly_Triangulation(Nodes,UVNodes,Triangles);
|
||||
@@ -334,13 +333,13 @@ Handle(Poly_Triangulation) Poly::ReadTriangulation(Standard_IStream& IS)
|
||||
|
||||
//=======================================================================
|
||||
//function : ReadPolygon3D
|
||||
//purpose :
|
||||
//purpose :
|
||||
//=======================================================================
|
||||
|
||||
Handle(Poly_Polygon3D) Poly::ReadPolygon3D(Standard_IStream& IS)
|
||||
{
|
||||
// Read a 3d polygon
|
||||
|
||||
|
||||
char line[100];
|
||||
IS >> line;
|
||||
if (strcmp(line,"Poly_Polygon3D")) {
|
||||
@@ -377,7 +376,7 @@ Handle(Poly_Polygon3D) Poly::ReadPolygon3D(Standard_IStream& IS)
|
||||
Handle(Poly_Polygon3D) P;
|
||||
if (!hasparameters)
|
||||
P = new Poly_Polygon3D(Nodes);
|
||||
else
|
||||
else
|
||||
P = new Poly_Polygon3D(Nodes, Param);
|
||||
|
||||
P->Deflection(d);
|
||||
@@ -387,13 +386,13 @@ Handle(Poly_Polygon3D) Poly::ReadPolygon3D(Standard_IStream& IS)
|
||||
|
||||
//=======================================================================
|
||||
//function : ReadPolygon3D
|
||||
//purpose :
|
||||
//purpose :
|
||||
//=======================================================================
|
||||
|
||||
Handle(Poly_Polygon2D) Poly::ReadPolygon2D(Standard_IStream& IS)
|
||||
{
|
||||
// Read a 2d polygon
|
||||
|
||||
|
||||
char line[100];
|
||||
IS >> line;
|
||||
if (strcmp(line,"Poly_Polygon2D")) {
|
||||
@@ -417,9 +416,9 @@ Handle(Poly_Polygon2D) Poly::ReadPolygon2D(Standard_IStream& IS)
|
||||
Nodes(i).SetCoord(x,y);
|
||||
}
|
||||
|
||||
Handle(Poly_Polygon2D) P =
|
||||
Handle(Poly_Polygon2D) P =
|
||||
new Poly_Polygon2D(Nodes);
|
||||
|
||||
|
||||
P->Deflection(d);
|
||||
|
||||
return P;
|
||||
@@ -427,14 +426,14 @@ Handle(Poly_Polygon2D) Poly::ReadPolygon2D(Standard_IStream& IS)
|
||||
|
||||
//=======================================================================
|
||||
//function : ComputeNormals
|
||||
//purpose :
|
||||
//purpose :
|
||||
//=======================================================================
|
||||
|
||||
void Poly::ComputeNormals(const Handle(Poly_Triangulation)& Tri)
|
||||
{
|
||||
const TColgp_Array1OfPnt& arrNodes = Tri->Nodes();
|
||||
const Poly_Array1OfTriangle & arrTri = Tri->Triangles();
|
||||
Standard_Integer nbNormVal = Tri->NbNodes() * 3;
|
||||
Standard_Integer nbNormVal = Tri->NbNodes() * 3;
|
||||
const Handle(TShort_HArray1OfShortReal) Normals =
|
||||
new TShort_HArray1OfShortReal(1, nbNormVal);
|
||||
Normals->Init(0.F);
|
||||
@@ -493,3 +492,107 @@ void Poly::ComputeNormals(const Handle(Poly_Triangulation)& Tri)
|
||||
|
||||
Tri->SetNormals(Normals);
|
||||
}
|
||||
|
||||
//=======================================================================
|
||||
//function : PointOnTriangle
|
||||
//purpose :
|
||||
//=======================================================================
|
||||
|
||||
Standard_Real Poly::PointOnTriangle (const gp_XY& theP1, const gp_XY& theP2, const gp_XY& theP3,
|
||||
const gp_XY& theP, gp_XY& theUV)
|
||||
{
|
||||
gp_XY aDP = theP - theP1;
|
||||
gp_XY aDU = theP2 - theP1;
|
||||
gp_XY aDV = theP3 - theP1;
|
||||
Standard_Real aDet = aDU ^ aDV;
|
||||
|
||||
// case of non-degenerated triangle
|
||||
if ( Abs (aDet) > gp::Resolution() )
|
||||
{
|
||||
Standard_Real aU = (aDP ^ aDV) / aDet;
|
||||
Standard_Real aV = -(aDP ^ aDU) / aDet;
|
||||
|
||||
// if point is inside triangle, just return parameters
|
||||
if ( aU > -gp::Resolution() &&
|
||||
aV > -gp::Resolution() &&
|
||||
1. - aU - aV > -gp::Resolution() )
|
||||
{
|
||||
theUV.SetCoord (aU, aV);
|
||||
return 0.;
|
||||
}
|
||||
|
||||
// else find closest point on triangle sides; note that in general case
|
||||
// triangle can be very distorted and it is necessary to check
|
||||
// projection on all sides regardless of values of computed parameters
|
||||
|
||||
// project on side U=0
|
||||
aU = 0.;
|
||||
aV = Min (1., Max (0., (aDP * aDV) / aDV.SquareModulus()));
|
||||
Standard_Real aD = (aV * aDV - aDP).SquareModulus();
|
||||
|
||||
// project on side V=0
|
||||
Standard_Real u = Min (1., Max (0., (aDP * aDU) / aDU.SquareModulus()));
|
||||
Standard_Real d = (u * aDU - aDP).SquareModulus();
|
||||
if ( d < aD )
|
||||
{
|
||||
aU = u;
|
||||
aV = 0.;
|
||||
aD = d;
|
||||
}
|
||||
|
||||
// project on side U+V=1
|
||||
gp_XY aDUV = aDV - aDU;
|
||||
Standard_Real v = Min (1., Max (0., ((aDP - aDU) * aDUV) / aDUV.SquareModulus()));
|
||||
d = (theP2 + v * aDUV - theP).SquareModulus();
|
||||
if ( d < aD )
|
||||
{
|
||||
aU = 1. - v;
|
||||
aV = v;
|
||||
aD = d;
|
||||
}
|
||||
|
||||
theUV.SetCoord (aU, aV);
|
||||
return aD;
|
||||
}
|
||||
|
||||
// degenerated triangle
|
||||
Standard_Real aL2U = aDU.SquareModulus();
|
||||
Standard_Real aL2V = aDV.SquareModulus();
|
||||
if ( aL2U < gp::Resolution() ) // side 1-2 is degenerated
|
||||
{
|
||||
if ( aL2V < gp::Resolution() ) // whole triangle is degenerated to point
|
||||
{
|
||||
theUV.SetCoord (0., 0.);
|
||||
return (theP - theP1).SquareModulus();
|
||||
}
|
||||
else
|
||||
{
|
||||
theUV.SetCoord (0., (aDP * aDV) / aL2V);
|
||||
return (theP - (theP1 + theUV.Y() * aDV)).SquareModulus();
|
||||
}
|
||||
}
|
||||
else if ( aL2V < gp::Resolution() ) // side 1-3 is degenerated
|
||||
{
|
||||
theUV.SetCoord ((aDP * aDU) / aL2U, 0.);
|
||||
return (theP - (theP1 + theUV.X() * aDU)).SquareModulus();
|
||||
}
|
||||
else // sides 1-2 and 1-3 are collinear
|
||||
{
|
||||
// select parameter on one of sides so as to have points closer to picked
|
||||
Standard_Real aU = Min (1., Max (0., (aDP * aDU) / aL2U));
|
||||
Standard_Real aV = Min (1., Max (0., (aDP * aDV) / aL2V));
|
||||
Standard_Real aD1 = (aDP - aU * aDU).SquareModulus();
|
||||
Standard_Real aD2 = (aDP - aV * aDV).SquareModulus();
|
||||
if ( aD1 < aD2 )
|
||||
{
|
||||
theUV.SetCoord ((aDP * aDU) / aL2U, 0.);
|
||||
return aD1;
|
||||
}
|
||||
else
|
||||
{
|
||||
theUV.SetCoord (0., (aDP * aDV) / aL2V);
|
||||
return aD2;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user