1
0
mirror of https://git.dev.opencascade.org/repos/occt.git synced 2025-08-04 13:13:25 +03:00

Integration of OCCT 6.5.0 from SVN

This commit is contained in:
bugmaster
2011-03-16 07:30:28 +00:00
committed by bugmaster
parent 4903637061
commit 7fd59977df
16375 changed files with 3882564 additions and 0 deletions

113
src/MAT2d/MAT2d.cdl Executable file
View File

@@ -0,0 +1,113 @@
-- File: MAT2d.cdl
-- Created: Tue Jul 6 12:14:54 1993
-- Author: Yves FRICAUD
-- <yfr@phylox>
---Copyright: Matra Datavision 1993
package MAT2d
---Purpose : Package of computation of Bisector locus on a
-- Set of geometrys from Geom2d.
uses
MMgt,
gp,
Geom2d,
TColStd,
TCollection,
TColgp,
TColGeom2d,
MAT,
Bisector
is
deferred class SketchExplorer;
---Purpose: SletchExplorer contains an iterator on a set of geometrys
-- from Geom2d. It's use by BisectingLocus.
generic class BisectingLocus;
---Purpose: Constuction of the map of the bisector locus on a
-- set of geometrys from Geom2d.
class Tool2d;
---Purpose: Tool2d contains the geometrys of the map. Tool2d
-- contains the set of the geometric's methode used for
-- the map's computation.
class Mat2d instantiates Mat from MAT (Tool2d);
class Connexion;
---Purpose: a Connexion links two lines.
class MiniPath;
---Purpose: MiniPath computes one minimum path to link all the
-- lines of a set.
class Circuit;
---Purpose: EquiCircuit gives a Circuit passing by all the lines
-- in a set and all the connexions of the minipath associated.
class CutCurve;
---Purpose: Cuts a curve at the extremas of curvature
-- and at the inflections. Constructs a trimmed
-- Curve for each interval.
class SequenceOfConnexion instantiates Sequence from TCollection
(Connexion from MAT2d);
class DataMapOfIntegerSequenceOfConnexion instantiates DataMap
from TCollection (Integer from Standard,
SequenceOfConnexion from MAT2d,
MapIntegerHasher from TColStd);
class Array2OfConnexion instantiates Array2 from TCollection
(Connexion from MAT2d);
class DataMapOfIntegerBisec instantiates DataMap from TCollection
(Integer from Standard,
Bisec from Bisector,
MapIntegerHasher from TColStd);
class DataMapOfIntegerPnt2d instantiates DataMap from TCollection
(Integer from Standard,
Pnt2d from gp,
MapIntegerHasher from TColStd);
class DataMapOfIntegerVec2d instantiates DataMap from TCollection
(Integer from Standard,
Vec2d from gp,
MapIntegerHasher from TColStd);
class SequenceOfSequenceOfCurve instantiates Sequence from TCollection
(SequenceOfCurve from TColGeom2d);
class SequenceOfSequenceOfGeometry instantiates Sequence from TCollection
(SequenceOfGeometry from TColGeom2d);
class DataMapOfIntegerConnexion instantiates DataMap from TCollection
(Integer from Standard,
Connexion from MAT2d,
MapIntegerHasher from TColStd);
class BiInt;
class MapBiIntHasher;
class DataMapOfBiIntSequenceOfInteger instantiates DataMap
from TCollection (BiInt from MAT2d,
SequenceOfInteger from TColStd,
MapBiIntHasher from MAT2d);
class DataMapOfBiIntInteger instantiates DataMap
from TCollection (BiInt from MAT2d,
Integer from Standard,
MapBiIntHasher from MAT2d);
end MAT2d;

36
src/MAT2d/MAT2d_BiInt.cdl Executable file
View File

@@ -0,0 +1,36 @@
-- File: MAT2d_BiInt.cdl
-- Created: Fri Nov 19 11:56:44 1993
-- Author: Yves FRICAUD
-- <yfr@phylox>
---Copyright: Matra Datavision 1993
class BiInt from MAT2d
---Purpose: BiInt is a set of two integers.
is
Create ( I1,I2 : Integer) returns BiInt from MAT2d;
FirstIndex(me) returns Integer
is static;
SecondIndex(me) returns Integer
is static;
FirstIndex(me : in out ; I1 : Integer)
is static;
SecondIndex(me : in out ; I2 : Integer)
is static;
IsEqual (me ;B : BiInt from MAT2d) returns Boolean
---C++: alias operator ==
is static;
fields
i1 : Integer;
i2 : Integer;
end BiInt;

41
src/MAT2d/MAT2d_BiInt.cxx Executable file
View File

@@ -0,0 +1,41 @@
// File: MAT2d_BiInt.cxx
// Created: Fri Nov 19 15:23:43 1993
// Author: Yves FRICAUD
// <yfr@phylox>
# include <MAT2d_BiInt.ixx>
MAT2d_BiInt::MAT2d_BiInt(const Standard_Integer I1,
const Standard_Integer I2)
:i1(I1),i2(I2)
{
}
Standard_Integer MAT2d_BiInt::FirstIndex()const
{
return i1;
}
Standard_Integer MAT2d_BiInt::SecondIndex()const
{
return i2;
}
void MAT2d_BiInt::FirstIndex(const Standard_Integer I1)
{
i1 = I1;
}
void MAT2d_BiInt::SecondIndex(const Standard_Integer I2)
{
i2 = I2;
}
Standard_Boolean MAT2d_BiInt::IsEqual(const MAT2d_BiInt& B)
const
{
return (i1 == B.FirstIndex() && i2 == B.SecondIndex());
}

View File

@@ -0,0 +1,160 @@
-- File: MAT2d_BisectingLocus.cdl
-- Created: Tue Jul 6 12:24:44 1993
-- Author: Yves FRICAUD
-- <yfr@phylox>
---Copyright: Matra Datavision 1993
generic class BisectingLocus from MAT2d (Explorer as any)
-- as SketchExplorer from MAT2d
---Purpose : BisectingLocus generates and contains the Bisecting_Locus
-- of a set of lines from Geom2d, defined by <ExploSet>.
--
-- If the set of lines contains closed lines:
-- ------------------------------------------
-- These lines cut the plane in areas.
-- One map can be computed for each area.
--
-- Bisecting locus computes a map in an area.
-- The area is defined by a side (MAT_Left,MAT_Right)
-- on one of the closed lines.
--
-- If the set of lines contains only open lines:
-- --------------------------------------------
-- the map recovers all the plane.
--
-- Warning: Assume the orientation of the closed lines are
-- compatible.
--
-- Assume the explo contains only lines located in the
-- area where the bisecting locus will be computed.
--
-- Assume a line don't cross itself or an other line.
--
-- Remark:
-- the curves coming from the explorer can be
-- decomposed in different parts. It the case for the
-- curves other than circles or lines.
--
-- The map of bisecting locus is described by a graph.
-- - The BasicsElements correspond to elements on
-- the figure described by the Explorer.
-- - The Arcs correspond to the bisectors.
-- - The Nodes are the extremities of the arcs.
uses
Graph from MAT,
Arc from MAT,
BasicElt from MAT,
Node from MAT,
Side from MAT,
DataMapOfIntegerBasicElt from MAT,
DataMapOfBiIntInteger from MAT2d,
Bisec from Bisector,
Geometry from Geom2d,
Pnt2d from gp,
Tool2d from MAT2d
is
Create returns BisectingLocus from MAT2d;
---Category: Construction.
Compute (me : in out ;
anExplo : in out Explorer;
LineIndex : Integer = 1;
aSide : Side from MAT = MAT_Left )
--- Purpose : Computation of the Bisector_Locus in a set of Lines
-- defined in <anExplo>.
-- The bisecting locus are computed on the side <aSide>
-- from the line <LineIndex> in <anExplo>.
is static;
---Category: Querying.
IsDone (me) returns Boolean from Standard
---Purpose: Returns True if Compute has succeeded.
is static;
Graph(me) returns Graph from MAT
--- Purpose : Returns <theGraph> of <me>.
is static;
NumberOfContours (me)
---Purpose: Returns the number of contours.
returns Integer from Standard
is static;
NumberOfElts( me ; IndLine : Integer)
---Purpose: Returns the number of BasicElts on the line
-- <IndLine>.
returns Integer from Standard
is static;
NumberOfSections (me; IndLine : Integer; Index : Integer)
---Purpose: Returns the number of sections of a curve.
-- this curve is the Indexth curve in the IndLineth contour
-- given by anExplo.
--
returns Integer from Standard
is static;
BasicElt ( me ; IndLine : Integer ; Index : Integer)
---Purpose: Returns the BasicElts located at the position
-- <Index> on the contour designed by <IndLine>.
-- Remark: the BasicElts on a contour are sorted.
--
returns BasicElt from MAT
is static;
GeomElt(me ; aBasicElt : BasicElt from MAT)
--- Purpose : Returns the geometry linked to the <BasicElt>.
returns Geometry from Geom2d
is static;
GeomElt(me ; aNode : Node from MAT)
--- Purpose : Returns the geometry of type <gp> linked to
-- the <Node>.
returns Pnt2d from gp
is static;
GeomBis(me ; anArc : Arc from MAT ; Reverse :in out Boolean from Standard)
--- Purpose : Returns the geometry of type <Bissec>
-- linked to the arc <ARC>.
-- <Reverse> is False when the FirstNode of <anArc>
-- correspond to the first point of geometry.
--
returns Bisec from Bisector
is static;
---Category: private methods.
Fusion(me : in out)
is static private;
RenumerationAndFusion
(me : in out;
IndexLine : Integer;
LengthLine : Integer;
IndexLast : in out Integer;
NewMap : in out DataMapOfIntegerBasicElt from MAT)
is static private;
fields
theGraph : Graph from MAT;
theTool : Tool2d from MAT2d;
isDone : Boolean from Standard;
nbSect : DataMapOfBiIntInteger from MAT2d;
nbContours : Integer from Standard;
end BisectingLocus;

View File

@@ -0,0 +1,330 @@
// File: MAT2d_BisectingLocus.gxx
// Created: Tue Jul 13 15:10:17 1993
// Author: Yves FRICAUD
// <yfr@phylox>
# include <MAT2d_Mat2d.hxx>
# include <MAT2d_Tool2d.hxx>
# include <MAT2d_Circuit.hxx>
# include <MAT2d_CutCurve.hxx>
# include <MAT2d_BiInt.hxx>
# include <MAT2d_SequenceOfSequenceOfGeometry.hxx>
# include <MAT_Graph.hxx>
# include <MAT_Arc.hxx>
# include <MAT_BasicElt.hxx>
# include <MAT_Node.hxx>
# include <MAT_Bisector.hxx>
# include <MAT_ListOfBisector.hxx>
# include <MAT_DataMapOfIntegerBasicElt.hxx>
# include <MAT_DataMapIteratorOfDataMapOfIntegerBasicElt.hxx>
# include <Geom2d_Curve.hxx>
# include <gp_Pnt2d.hxx>
# include <TColGeom2d_SequenceOfGeometry.hxx>
# include <Precision.hxx>
#include <Standard_OutOfRange.hxx>
static void CutSketch (MAT2d_SequenceOfSequenceOfGeometry& Figure,
MAT2d_DataMapOfBiIntInteger& NbSect);
//=============================================================================
//function : MAT2d_BisectingLocus
//purpose : Constructeur vide.
//=============================================================================
MAT2d_BisectingLocus::MAT2d_BisectingLocus()
{
}
//=============================================================================
//function : Compute
//purpose : Calcul de la carte des lieux bisecteurs sur le contour defini par
// <anExplo>.
//=============================================================================
void MAT2d_BisectingLocus::Compute( Explorer& anExplo,
const Standard_Integer IndexLine,
const MAT_Side aSide )
{
MAT2d_Mat2d TheMAT;
Handle(MAT_ListOfBisector) TheRoots = new MAT_ListOfBisector();
MAT2d_SequenceOfSequenceOfGeometry Figure;
Standard_Integer i;
nbSect.Clear();
nbContours = anExplo.NumberOfContours();
//---------------------------------
// Lecture des donnees de anExplo.
//---------------------------------
for (i = 1; i <= anExplo.NumberOfContours(); i++) {
TColGeom2d_SequenceOfGeometry Line;
Figure.Append(Line);
for (anExplo.Init(i); anExplo.More(); anExplo.Next()) {
Figure.ChangeValue(i).Append(anExplo.Value());
}
}
//-----------------------
// Decoupage des courbes.
//-----------------------
CutSketch(Figure,nbSect);
//----------------------------------------------------------
// Construction du circuit sur lequel est calcule la carte.
//----------------------------------------------------------
Handle(MAT2d_Circuit) ACircuit = new MAT2d_Circuit();
// Modified by Sergey KHROMOV - Wed Mar 6 17:43:47 2002 Begin
// ACircuit->Perform(Figure,IndexLine,(aSide == MAT_Left));
ACircuit->Perform(Figure,anExplo.GetIsClosed(), IndexLine,(aSide == MAT_Left));
// Modified by Sergey KHROMOV - Wed Mar 6 17:43:48 2002 End
// -----------------------
// Initialistion du Tool.
// -----------------------
theTool.Sense(aSide);
theTool.InitItems(ACircuit);
// --------------------------------------------
// Initialisation et execution de l algorithme.
// --------------------------------------------
TheMAT.CreateMat(theTool);
isDone = TheMAT.IsDone(); if (!isDone) return;
// ----------------------------------------------------------------
// Recuperation du resultat de l algorithme et creation du graphe.
// ----------------------------------------------------------------
for (TheMAT.Init(); TheMAT.More(); TheMAT.Next()) {
TheRoots->BackAdd(TheMAT.Bisector());
}
theGraph = new MAT_Graph();
theGraph->Perform(TheMAT.SemiInfinite(),
TheRoots,
theTool.NumberOfItems(),
TheMAT.NumberOfBisectors());
//-----------------------------------------------------------------------
// Fusion des elements de base doubles si plusieurs lignes dans Exploset.
//-----------------------------------------------------------------------
if (anExplo.NumberOfContours() > 1) {
MAT_DataMapOfIntegerBasicElt NewMap;
Standard_Integer IndexLast = 1;
//-----------------------------------------------------------------------
// Construction de NewMap dont les elements sont ordonnes suivant les
// lignes du contour et qui ne contient pas d element dupliques.
// em meme temps fusion des arcs dupliques et mise a jour des noeuds.
//-----------------------------------------------------------------------
for ( i = 1; i <= anExplo.NumberOfContours(); i++) {
RenumerationAndFusion(i,
theTool.Circuit()->LineLength(i),
IndexLast,
NewMap);
}
//-----------------------------------------------------------------------
// Chargement dans le graph de la nouvelle map.
// et compactage de la map des Arcs (ie Elimination des trous du a la
// fusion d arcs ).et de celle des Nodes.
//-----------------------------------------------------------------------
theGraph->ChangeBasicElts(NewMap);
theGraph->CompactArcs();
theGraph->CompactNodes();
}
}
//=============================================================================
//function : RenumerationAndFusion
//purpose :
//=============================================================================
void MAT2d_BisectingLocus::RenumerationAndFusion
(const Standard_Integer ILine,
const Standard_Integer LengthLine,
Standard_Integer& IndexLast,
MAT_DataMapOfIntegerBasicElt& NewMap)
{
Standard_Integer IndFirst;
Standard_Integer i,j;
Standard_Integer GeomIndexArc1,GeomIndexArc2,GeomIndexArc3,GeomIndexArc4;
Standard_Boolean MergeArc1,MergeArc2;
for ( i = 1; i <= LengthLine; i++) {
const TColStd_SequenceOfInteger& S = theTool.Circuit()->RefToEqui(ILine,i);
IndFirst = S.Value(1);
NewMap.Bind(IndexLast,theGraph->ChangeBasicElt(IndFirst));
IndexLast++;
for(j = 2; j <= S.Length(); j++){
theGraph->FusionOfBasicElts(IndFirst,
S.Value(j),
MergeArc1,
GeomIndexArc1,
GeomIndexArc2,
MergeArc2,
GeomIndexArc3,
GeomIndexArc4);
if(MergeArc1) {
theTool.BisecFusion(GeomIndexArc1,GeomIndexArc2);
}
if(MergeArc2) {
theTool.BisecFusion(GeomIndexArc3,GeomIndexArc4);
}
}
}
}
//=============================================================================
//function : IsDone
//Purpose :
//=============================================================================
Standard_Boolean MAT2d_BisectingLocus::IsDone() const
{
return isDone;
}
//=============================================================================
//function : Graph
//
//=============================================================================
Handle(MAT_Graph) MAT2d_BisectingLocus::Graph() const
{
return theGraph;
}
//=============================================================================
//function : NumberOfContours
//
//=============================================================================
Standard_Integer MAT2d_BisectingLocus::NumberOfContours () const
{
return nbContours;
}
//=============================================================================
//function : NumberOfElts
//
//=============================================================================
Standard_Integer MAT2d_BisectingLocus::NumberOfElts
(const Standard_Integer IndLine) const
{
return theTool.Circuit()->LineLength(IndLine);
}
//=============================================================================
//function : NumberOfSect
//
//=============================================================================
Standard_Integer MAT2d_BisectingLocus::NumberOfSections
(const Standard_Integer IndLine,
const Standard_Integer Index )
const
{
MAT2d_BiInt B(IndLine,Index);
return nbSect(B);
}
//=============================================================================
//function : BasicElt
//
//=============================================================================
Handle(MAT_BasicElt) MAT2d_BisectingLocus::BasicElt
(const Standard_Integer IndLine,
const Standard_Integer Index )
const
{
Standard_Integer i;
Standard_Integer Ind = Index;
for (i = 1 ; i < IndLine ; i++){
Ind = Ind + theTool.Circuit()->LineLength(i);
}
return theGraph->BasicElt(Ind);
}
//=============================================================================
//function : GeomBis
//
//=============================================================================
Bisector_Bisec MAT2d_BisectingLocus::GeomBis (const Handle(MAT_Arc)& anArc,
Standard_Boolean& Reverse)
const
{
Reverse = Standard_False;
Handle(Geom2d_Curve) Bis = theTool.GeomBis(anArc->GeomIndex()).Value();
if (Bis->FirstParameter() <= -Precision::Infinite()) {
Reverse = Standard_True;
}
else if (Bis->LastParameter() < Precision::Infinite()) {
gp_Pnt2d PF = Bis->Value(Bis->FirstParameter());
gp_Pnt2d PL = Bis->Value(Bis->LastParameter());
gp_Pnt2d PNode = GeomElt(anArc->FirstNode());
if (PNode.SquareDistance(PF) > PNode.SquareDistance(PL))
Reverse = Standard_True;
}
return theTool.GeomBis(anArc->GeomIndex());
}
//=============================================================================
//function : GeomElt
//
//=============================================================================
Handle(Geom2d_Geometry) MAT2d_BisectingLocus::GeomElt
(const Handle(MAT_BasicElt)& aBasicElt) const
{
return theTool.GeomElt(aBasicElt->GeomIndex());
}
//=============================================================================
//function : GeomElt
//
//=============================================================================
gp_Pnt2d MAT2d_BisectingLocus::GeomElt(const Handle(MAT_Node)& aNode) const
{
return theTool.GeomPnt(aNode->GeomIndex());
}
//=============================================================================
//function : CutSketch
//
//=============================================================================
static void CutSketch (MAT2d_SequenceOfSequenceOfGeometry& Figure,
MAT2d_DataMapOfBiIntInteger& NbSect)
{
MAT2d_CutCurve Cuter;
Standard_Integer i,j,k,ico;
Standard_Integer ICurveInit;
Standard_Integer NbSection;
for ( i = 1; i <= Figure.Length(); i++) {
TColGeom2d_SequenceOfGeometry& Contour = Figure.ChangeValue(i);
ICurveInit = 0;
for ( j = 1; j <= Contour.Length(); j++) {
ICurveInit++;
Cuter.Perform(Handle(Geom2d_Curve)::DownCast(Contour.ChangeValue(j)));
NbSection = 1;
if (!Cuter.UnModified()) {
ico = j;
NbSection = Cuter.NbCurves();
for ( k = 1; k <= NbSection; k++) {
Contour.InsertAfter(j,Cuter.Value(k));
j++;
}
Contour.Remove(ico);
j--;
}
MAT2d_BiInt B(i,ICurveInit);
NbSect.Bind(B,NbSection);
}
}
}

126
src/MAT2d/MAT2d_Circuit.cdl Executable file
View File

@@ -0,0 +1,126 @@
-- File: MAT2d_Circuit.cdl
-- Created: Thu Nov 18 16:01:02 1993
-- Author: Yves FRICAUD
-- <yfr@phylox>
---Copyright: Matra Datavision 1993
class Circuit from MAT2d
inherits
TShared from MMgt
---Purpose: Constructs a circuit on a set of lines.
--
--
uses
SequenceOfInteger from TColStd,
Geometry from Geom2d,
SequenceOfGeometry from TColGeom2d,
SequenceOfBoolean from TColStd,
SequenceOfConnexion from MAT2d,
BiInt from MAT2d,
Connexion from MAT2d,
SequenceOfSequenceOfGeometry from MAT2d,
DataMapOfIntegerConnexion from MAT2d,
MiniPath from MAT2d,
DataMapOfBiIntSequenceOfInteger from MAT2d
is
Create returns mutable Circuit from MAT2d;
---Category: Computation
Perform(me : mutable ;
aFigure : in out SequenceOfSequenceOfGeometry;
IsClosed : SequenceOfBoolean from TColStd;
IndRefLine : Integer;
Trigo : Boolean)
is static;
PassByLast(me ; C1,C2 : Connexion from MAT2d)
returns Boolean
is static private;
Side (me ; C : Connexion from MAT2d; Line : SequenceOfGeometry)
returns Real
is static private;
UpDateLink(me : mutable ;
IFirst,ILine,ICurveFirst,ICurveLast: Integer)
is static private;
SortRefToEqui(me : mutable ; aBiInt : BiInt from MAT2d)
is static private;
InitOpen(me ; Line : in out SequenceOfGeometry)
is static private;
InsertCorner(me ; Line : in out SequenceOfGeometry)
is static private;
DoubleLine(me ;
Line : in out SequenceOfGeometry;
Connexions : in out SequenceOfConnexion from MAT2d;
Father : mutable Connexion from MAT2d;
Side : Real)
is static private;
ConstructCircuit(me : mutable ;
aFigure : SequenceOfSequenceOfGeometry;
IndRefLine : Integer;
aPath : MiniPath from MAT2d)
is static private;
---Category: Querying
NumberOfItems(me)
---Purpose: Returns the Number of Items .
returns Integer is static;
Value(me ; Index : Integer)
---Purpose: Returns the item at position <Index> in <me>.
returns Geometry from Geom2d
is static;
LineLength(me ; IndexLine : Integer)
---Purpose: Returns the number of items on the line <IndexLine>.
returns Integer from Standard
is static;
RefToEqui(me ; IndLine : Integer; IndCurve : Integer)
---Purpose: Returns the set of index of the items in <me>corresponding
-- to the curve <IndCurve> on the line <IndLine> from the
-- initial figure.
--
---C++: return const&
returns SequenceOfInteger from TColStd
is static;
Connexion(me ; Index : Integer)
---Purpose: Returns the Connexion on the item <Index> in me.
returns Connexion from MAT2d
is static;
ConnexionOn(me ; Index : Integer)
---Purpose: Returns <True> is there is a connexion on the item <Index>
-- in <me>.
returns Boolean from Standard
is static;
fields
direction : Real;
geomElements : SequenceOfGeometry from TColGeom2d;
connexionMap : DataMapOfIntegerConnexion from MAT2d;
linkRefEqui : DataMapOfBiIntSequenceOfInteger from MAT2d;
linesLength : SequenceOfInteger from TColStd;
end Circuit;

902
src/MAT2d/MAT2d_Circuit.cxx Executable file
View File

@@ -0,0 +1,902 @@
// File: MAT2d_Circuit.cxx
// Created: Fri Nov 19 15:30:11 1993
// Author: Yves FRICAUD
// <yfr@phylox>
#ifdef DRAW
#include <Draw_Appli.hxx>
#include <DrawTrSurf_Curve2d.hxx>
#include <Draw_Marker2D.hxx>
#endif
#ifdef DEB
#include <GCE2d_MakeSegment.hxx>
#include <Geom2d_Curve.hxx>
#include <Geom2d_Parabola.hxx>
#include <Geom2d_Hyperbola.hxx>
#include <Geom2d_TrimmedCurve.hxx>
#include <Geom2d_CartesianPoint.hxx>
#include <Geom2d_Line.hxx>
#include <Geom2d_Circle.hxx>
#endif
#include <MAT2d_Circuit.ixx>
#include <Geom2d_TrimmedCurve.hxx>
#include <Geom2d_CartesianPoint.hxx>
#include <Geom2d_Geometry.hxx>
#include <TColStd_SequenceOfInteger.hxx>
#include <TColStd_Array1OfBoolean.hxx>
#include <TColStd_Array1OfInteger.hxx>
#include <MAT2d_BiInt.hxx>
#include <MAT2d_MiniPath.hxx>
#include <MAT2d_Connexion.hxx>
#include <MAT2d_SequenceOfConnexion.hxx>
#include <MAT2d_DataMapOfIntegerConnexion.hxx>
#include <MAT2d_SequenceOfSequenceOfGeometry.hxx>
#include <MAT2d_DataMapOfBiIntSequenceOfInteger.hxx>
#include <MAT2d_DataMapIteratorOfDataMapOfBiIntSequenceOfInteger.hxx>
#include <Precision.hxx>
#include <Adaptor3d_OffsetCurve.hxx>
#include <Geom2dInt_GInter.hxx>
#include <Geom2dAdaptor_HCurve.hxx>
#include <IntRes2d_IntersectionPoint.hxx>
#ifdef DRAW
static Handle(DrawTrSurf_Curve2d) draw;
Standard_EXPORT Draw_Viewer dout;
#endif
#ifdef DEB
static void MAT2d_DrawCurve(const Handle(Geom2d_Curve)& aCurve,
const Standard_Integer Indice);
static Standard_Boolean AffichCircuit = 0;
#endif
// static functions:
static Standard_Real CrossProd(const Handle(Geom2d_Geometry)& Geom1,
const Handle(Geom2d_Geometry)& Geom2,
Standard_Real& DotProd);
static Standard_Boolean IsSharpCorner (const Handle(Geom2d_Geometry)& Geom1,
const Handle(Geom2d_Geometry)& Geom2,
const Standard_Real& Direction);
//=============================================================================
//function : Constructor
//purpose :
//=============================================================================
MAT2d_Circuit::MAT2d_Circuit()
{
}
//=============================================================================
//function : Perform
//purpose :
//=============================================================================
void MAT2d_Circuit::Perform
( MAT2d_SequenceOfSequenceOfGeometry& FigItem,
const TColStd_SequenceOfBoolean & IsClosed,
const Standard_Integer IndRefLine,
const Standard_Boolean Trigo)
{
Standard_Integer NbLines = FigItem.Length();
Standard_Integer i;
TColStd_Array1OfBoolean Open(1,NbLines);
MAT2d_SequenceOfConnexion SVide;
Handle(MAT2d_Connexion) ConnexionNul;
if (Trigo) direction = 1.; else direction = -1.;
//---------------------
// Reinitialisation SD.
//---------------------
geomElements.Clear();
connexionMap.Clear();
linkRefEqui.Clear();
linesLength.Clear();
//----------------------------
// Detection Lignes ouvertes.
//----------------------------
for ( i = 1; i <= NbLines; i++) {
Handle_Geom2d_TrimmedCurve Curve;
Curve = Handle(Geom2d_TrimmedCurve)::DownCast(FigItem.Value(i).First());
gp_Pnt2d P1 = Curve->StartPoint();
Curve = Handle(Geom2d_TrimmedCurve)::DownCast(FigItem.Value(i).Last());
gp_Pnt2d P2 = Curve->EndPoint();
// Modified by Sergey KHROMOV - Wed Mar 6 16:59:01 2002 Begin
// if ( P1.IsEqual(P2,Precision::Confusion())) Open(i) = Standard_False;
// else Open(i) = Standard_True;
if (IsClosed(i)) Open(i) = Standard_False;
else if (P1.IsEqual(P2,Precision::Confusion())) Open(i) = Standard_False;
else Open(i) = Standard_True;
// Modified by Sergey KHROMOV - Wed Mar 6 16:59:04 2002 End
}
//---------------------------------------------------------------
// Insertion des cassures saillantes ou
// ajout des extremites de chaque courbe si la ligne est ouverte.
//---------------------------------------------------------------
for ( i = 1; i <= NbLines; i++) {
if (Open(i)) {
InitOpen(FigItem.ChangeValue(i));
linesLength.Append(FigItem.Value(i).Length());
}
else {
InsertCorner(FigItem.ChangeValue(i));
linesLength.Append(FigItem.Value(i).Length());
}
}
//---------------------------------
// Une seule ligne => Rien a faire.
//---------------------------------
if (NbLines == 1) {
if (Open(1)) {
DoubleLine(FigItem.ChangeValue(1),SVide,ConnexionNul,direction);
linesLength.SetValue(1,FigItem.Value(1).Length());
}
geomElements = FigItem.Value(1);
UpDateLink(1,1,1,geomElements.Length());
linesLength.Append(FigItem.Value(1).Length());
return;
}
//------------------
// Plusieurs lignes.
//------------------
//---------------------------------------------------------
// Calcul de l ensemble des connexions realisant le chemin.
//---------------------------------------------------------
MAT2d_MiniPath Road;
Road.Perform(FigItem,IndRefLine,Trigo);
//------------------------
// Fermeture ligne ouverte.
//-------------------------
for ( i = 1; i <= NbLines; i++) {
if (Open(i)) {
Handle(MAT2d_Connexion) CF;
if (Road.IsRoot(i)) CF = ConnexionNul; else CF = Road.Father(i);
if (Road.IsConnexionsFrom(i)) {
DoubleLine(FigItem.ChangeValue(i),Road.ConnexionsFrom(i),
CF,direction);
}
else {
DoubleLine(FigItem.ChangeValue(i),SVide,CF,direction);
}
linesLength.SetValue(i,FigItem.Value(i).Length());
}
}
//------------------------
// Construction du chemin.
//------------------------
Road.RunOnConnexions();
#ifdef DEB
if (AffichCircuit) {
Standard_Integer NbConnexions = Road.Path().Length();
for (i = 1; i <= NbConnexions; i++) {
Handle(Geom2d_TrimmedCurve) edge;
edge = GCE2d_MakeSegment(Road.Path().Value(i)->PointOnFirst(),
Road.Path().Value(i)->PointOnSecond());
MAT2d_DrawCurve(edge,2);
}
}
#endif
//-------------------------
// Construction du Circuit.
//-------------------------
ConstructCircuit(FigItem,IndRefLine,Road);
}
//=======================================================================
//function : SubSequence
//purpose :
//=======================================================================
static void SubSequence(const TColGeom2d_SequenceOfGeometry& S1,
Standard_Integer IF,
Standard_Integer IL,
TColGeom2d_SequenceOfGeometry& S2)
{
S2.Clear();
for (Standard_Integer i = IF; i<= IL; i++){
S2.Append(S1.Value(i));
}
}
//=============================================================================
//function : ConstructCircuit
//purpose :
//=============================================================================
void MAT2d_Circuit::ConstructCircuit
(const MAT2d_SequenceOfSequenceOfGeometry& FigItem,
const Standard_Integer IndRefLine,
const MAT2d_MiniPath& Road)
{
Handle(MAT2d_Connexion) PrevC,CurC;
TColGeom2d_SequenceOfGeometry SetOfItem;
Standard_Integer NbConnexions;
Standard_Integer ILastItem;
Standard_Integer IndLast;
Standard_Integer i;
NbConnexions = Road.Path().Length();
//-----------------------------------------------------
// Depart du premier element de la ligne de reference.
//-----------------------------------------------------
PrevC = Road.Path().Value(1);
SubSequence(FigItem.Value(IndRefLine),
1,
PrevC->IndexItemOnFirst(),
geomElements);
UpDateLink(1,IndRefLine,1,PrevC->IndexItemOnFirst());
connexionMap.Bind(geomElements.Length()+1,PrevC);
ILastItem = geomElements.Length();
//-----------------------------------------------------------------------
// Ajout des portion de lignes delimites par deux connexions successives.
//-----------------------------------------------------------------------
for ( i = 2; i <= NbConnexions; i++) {
CurC = Road.Path().Value(i);
if (PassByLast(PrevC,CurC)) {
//------------------------------------------------------
// La portion passe par le dernier element de la ligne.
// - ajout de la portion de PrevC au dernier element
// de la ligne.
// - Si la ligne contient plus d'un element ajout de la
// portion du premier element de la ligne a CurC.
//------------------------------------------------------
IndLast = FigItem.Value(CurC->IndexFirstLine()).Length();
SubSequence (FigItem.Value(CurC->IndexFirstLine()),
PrevC->IndexItemOnSecond(),
IndLast,
SetOfItem);
UpDateLink(ILastItem+1,CurC->IndexFirstLine(),
PrevC->IndexItemOnSecond(),IndLast);
geomElements.Append(SetOfItem);
ILastItem = geomElements.Length();
if (FigItem.Value(CurC->IndexFirstLine()).Length() > 1) {
SubSequence(FigItem.Value(CurC->IndexFirstLine()),
1,
CurC->IndexItemOnFirst(),
SetOfItem);
UpDateLink(ILastItem+1,CurC->IndexFirstLine(),
1,CurC->IndexItemOnFirst());
geomElements.Append(SetOfItem);
ILastItem = geomElements.Length();
}
connexionMap.Bind(ILastItem+1,CurC);
}
else{
//------------------------------------------------------
// La portion ne passe par le dernier element de la ligne.
//------------------------------------------------------
SubSequence(FigItem.Value(CurC->IndexFirstLine()),
PrevC->IndexItemOnSecond(),
CurC ->IndexItemOnFirst(),
SetOfItem);
UpDateLink(ILastItem+1,CurC->IndexFirstLine(),
PrevC->IndexItemOnSecond(),CurC->IndexItemOnFirst());
geomElements.Append(SetOfItem);
ILastItem = geomElements.Length();
connexionMap.Bind(ILastItem+1,CurC);
}
PrevC = CurC;
}
//-------------------------------------------------------------
// Fermeture : de la derniere connexion au dernier element de la
// ligne de reference.
//-------------------------------------------------------------
IndLast = FigItem.Value(IndRefLine).Length();
if (IndLast == 1) {
connexionMap.Bind(1,CurC);
connexionMap.UnBind(ILastItem+1);
}
else {
SubSequence(FigItem.Value(IndRefLine),
PrevC->IndexItemOnSecond(),
IndLast,
SetOfItem);
UpDateLink(ILastItem+1,IndRefLine,PrevC->IndexItemOnSecond(),IndLast);
geomElements.Append(SetOfItem);
ILastItem = geomElements.Length();
}
//--------------------------------------
// Tri des RefToEqui pour chaque element.
//--------------------------------------
MAT2d_DataMapIteratorOfDataMapOfBiIntSequenceOfInteger Ite;
for ( Ite.Initialize(linkRefEqui); Ite.More(); Ite.Next()) {
if (Ite.Value().Length() > 1) {
SortRefToEqui(Ite.Key());
}
}
#ifdef DEB
if (AffichCircuit) {
ILastItem = geomElements.Length();
for (i = 1; i <= ILastItem; i++) {
if (geomElements.Value(i)->DynamicType() != STANDARD_TYPE(Geom2d_CartesianPoint) ){
MAT2d_DrawCurve
(Handle(Geom2d_Curve)::DownCast(geomElements.Value(i)),2);
}
}
}
#endif
}
//=============================================================================
//function : InitOpen
//purpose :
//=============================================================================
void MAT2d_Circuit::InitOpen (TColGeom2d_SequenceOfGeometry& Line) const
{
Handle(Geom2d_TrimmedCurve) Curve;
Standard_Real DotProd;
Curve = Handle(Geom2d_TrimmedCurve)::DownCast(Line.First());
Line.InsertBefore(1,new Geom2d_CartesianPoint(Curve->StartPoint()));
Curve = Handle(Geom2d_TrimmedCurve)::DownCast(Line.Last());
Line.Append(new Geom2d_CartesianPoint(Curve->EndPoint()));
for ( Standard_Integer i = 2; i <= Line.Length() - 2; i++) {
if ( Abs(CrossProd(Line.Value(i),Line.Value(i+1),DotProd)) > 1.E-8 ||
DotProd < 0. ) {
Curve = Handle(Geom2d_TrimmedCurve)::DownCast(Line.Value(i));
Line.InsertAfter(i,new Geom2d_CartesianPoint(Curve->EndPoint()));
i++;
}
}
}
//=============================================================================
//function : DoubleLine
//purpose :
//=============================================================================
void MAT2d_Circuit::DoubleLine
( TColGeom2d_SequenceOfGeometry& Line,
MAT2d_SequenceOfConnexion& ConnexionFrom,
const Handle(MAT2d_Connexion)& ConnexionFather,
const Standard_Real SideRef)
const
{
Handle(Standard_Type) Type;
Handle(Geom2d_TrimmedCurve) Curve;
Standard_Integer NbItems = Line.Length();
Standard_Integer i;
Standard_Real ProVec,DotProd;
Handle(MAT2d_Connexion) CC;
//--------------------------
// Completion de la ligne.
//--------------------------
for ( i = NbItems - 1; i > 1; i--){
Type = Line.Value(i)->DynamicType();
if ( Type == STANDARD_TYPE(Geom2d_CartesianPoint) ){
Line.Append(Line.Value(i));
}
else {
Curve = Handle(Geom2d_TrimmedCurve)::DownCast(Line.Value(i)->Copy());
Curve->Reverse();
Line.Append(Curve);
}
}
//------------------------------------------
// Repartition des connexions sur la ligne
//------------------------------------------
Standard_Integer IAfter = ConnexionFrom.Length();
Standard_Integer NbConnexions = IAfter;
Standard_Integer IndCOF;
for (i = 1; i <= IAfter; i++) {
CC = ConnexionFrom.Value(i);
IndCOF = CC->IndexItemOnFirst();
Type = Line.Value(IndCOF)->DynamicType();
if ( Type == STANDARD_TYPE(Geom2d_CartesianPoint) ){
if (IndCOF!= NbItems && IndCOF!= 1) {
ProVec = CrossProd(Line.Value(IndCOF - 1),Line.Value(IndCOF + 1),DotProd);
if ((ProVec)*SideRef > 0){
CC->IndexItemOnFirst(2*NbItems - IndCOF);
ConnexionFrom.InsertAfter(IAfter,CC);
ConnexionFrom.Remove(i);
IAfter--;
i--;
}
}
}
else if (Side(CC,Line) != SideRef){
Curve = Handle(Geom2d_TrimmedCurve)::DownCast(Line.Value(IndCOF));
CC->IndexItemOnFirst(2*NbItems - IndCOF);
CC->ParameterOnFirst(Curve->ReversedParameter(CC->ParameterOnFirst()));
ConnexionFrom.InsertAfter(IAfter,CC);
ConnexionFrom.Remove(i);
IAfter--;
i--;
}
}
//---------------------------
// Mise a jour connexion pere.
//---------------------------
if (!ConnexionFather.IsNull()) {
CC = ConnexionFather->Reverse();
IndCOF = CC->IndexItemOnFirst();
Type = Line.Value(IndCOF)->DynamicType();
if ( Type == STANDARD_TYPE(Geom2d_CartesianPoint) ){
if (IndCOF != NbItems && IndCOF != 1) {
ProVec = CrossProd(Line.Value(IndCOF - 1),Line.Value(IndCOF + 1),DotProd);
if ((ProVec)*SideRef > 0){
ConnexionFather->IndexItemOnSecond(2*NbItems - IndCOF);
}
}
}
else if (Side(CC,Line) != SideRef){
Curve = Handle(Geom2d_TrimmedCurve)::DownCast(Line.Value(IndCOF));
ConnexionFather->IndexItemOnSecond(2*NbItems - IndCOF);
ConnexionFather->ParameterOnSecond
(Curve->ReversedParameter(ConnexionFather->ParameterOnSecond()));
}
}
//-------------------------------------
// Suppression des cassures rentrantes.
//-------------------------------------
Standard_Integer IndLine = 1;
Standard_Integer ICorres = 1;
TColStd_Array1OfInteger Corres(1,Line.Length());
while (Line.Value(IndLine) != Line.Last()){
Corres(ICorres) = IndLine;
Type = Line.Value(IndLine)->DynamicType();
if (Type == STANDARD_TYPE(Geom2d_CartesianPoint) &&
ICorres != 1 && ICorres != NbItems) {
if (!IsSharpCorner(Line.Value(IndLine - 1),
Line.Value(IndLine + 1),SideRef)){
Line.Remove(IndLine);
IndLine--;
Corres(ICorres) =0;
}
}
IndLine++;
ICorres++;
}
Corres(ICorres) = IndLine;
for (i = 1; i < 2*NbItems - 2; i++) {
if (Corres(i) == 0) Corres(i) = Corres(2*NbItems - i);
}
#ifdef DEB
if (AffichCircuit) {
for (i = 1; i <= 2*NbItems - 2; i++) {
cout<< "Correspondance "<< i<<" -> "<<Corres(i)<<endl;
}
}
#endif
//----------------------------
// Mise a jour des Connexions.
//----------------------------
for ( i = 1; i <= NbConnexions; i++){
CC = ConnexionFrom.ChangeValue(i);
CC->IndexItemOnFirst(Corres(CC->IndexItemOnFirst()));
}
if (!ConnexionFather.IsNull()) {
ConnexionFather
->IndexItemOnSecond(Corres(ConnexionFather->IndexItemOnSecond()));
}
}
//=============================================================================
//function : InsertCorner
//purpose :
//=============================================================================
void MAT2d_Circuit::InsertCorner (TColGeom2d_SequenceOfGeometry& Line) const
{
Standard_Integer i,isuiv;
Handle(Geom2d_TrimmedCurve) Curve;
Standard_Boolean Insert;
for ( i = 1; i <= Line.Length(); i++) {
isuiv = (i == Line.Length()) ? 1 : i + 1;
Insert = IsSharpCorner(Line.Value(i),Line.Value(isuiv),direction);
#ifdef DEB
if (AffichCircuit) {
if (Insert) {
Curve = Handle(Geom2d_TrimmedCurve)::DownCast(Line.Value(isuiv));
gp_Pnt2d P = Curve->StartPoint();
#ifdef DRAW
Handle(Draw_Marker2D) dr = new Draw_Marker2D(P,Draw_Plus,Draw_vert);
dout << dr;
dout.Flush();
#endif
}
}
#endif
if (Insert) {
Curve = Handle(Geom2d_TrimmedCurve)::DownCast(Line.Value(isuiv));
Line.InsertAfter(i,new Geom2d_CartesianPoint(Curve->StartPoint()));
i++;
}
}
}
//=============================================================================
//function : NumberOfItem
//purpose :
//=============================================================================
Standard_Integer MAT2d_Circuit::NumberOfItems()const
{
return geomElements.Length();
}
//=============================================================================
//function : LineLength
//purpose :
//=============================================================================
Standard_Integer MAT2d_Circuit::LineLength(const Standard_Integer I) const
{
return linesLength(I);
}
//=============================================================================
//function : Value
//purpose :
//=============================================================================
Handle(Geom2d_Geometry) MAT2d_Circuit::Value
(const Standard_Integer Index)const
{
return geomElements.Value(Index);
}
//=============================================================================
//function : RefToEqui
//purpose :
//=============================================================================
const TColStd_SequenceOfInteger& MAT2d_Circuit::RefToEqui
(const Standard_Integer IndLine,
const Standard_Integer IndCurve) const
{
MAT2d_BiInt Key(IndLine,IndCurve);
return linkRefEqui(Key);
}
//=============================================================================
//function : SortRefToEqui
//purpose :
//=============================================================================
void MAT2d_Circuit::SortRefToEqui (const MAT2d_BiInt& BiRef)
{
Standard_Integer i;
TColStd_SequenceOfInteger& S = linkRefEqui.ChangeFind(BiRef);
TColStd_SequenceOfInteger SFin;
for( i = 1; i <= S.Length(); i++){
if (!ConnexionOn(S.Value(i))) break;
}
if ( i > 1 && i <= S.Length()) {
SFin = S;
SFin.Split(i,S);
S.Append(SFin);
}
}
//=============================================================================
//function : Connexion
//purpose :
//=============================================================================
Handle(MAT2d_Connexion) MAT2d_Circuit::Connexion(const Standard_Integer I)const
{
return connexionMap(I);
}
//=============================================================================
//function : ConnexionOn
//purpose :
//=============================================================================
Standard_Boolean MAT2d_Circuit::ConnexionOn(const Standard_Integer I)const
{
return connexionMap.IsBound(I);
}
//=============================================================================
//function : Side
//purpose :
//=============================================================================
Standard_Real MAT2d_Circuit::Side
(const Handle(MAT2d_Connexion)& C1,
const TColGeom2d_SequenceOfGeometry& Line)
const
{
Handle(Geom2d_TrimmedCurve) Curve;
gp_Vec2d Vect1(C1->PointOnSecond().X() - C1->PointOnFirst().X(),
C1->PointOnSecond().Y() - C1->PointOnFirst().Y());
Curve = Handle(Geom2d_TrimmedCurve)::DownCast
(Line.Value(C1->IndexItemOnFirst()));
gp_Vec2d Vect2 = Curve->DN(C1->ParameterOnFirst(),1);
if ( (Vect1^Vect2) > 0.) return - 1.; else return 1.;
}
//=============================================================================
//function : PassByLast
//purpose :
//=============================================================================
Standard_Boolean MAT2d_Circuit::PassByLast
(const Handle(MAT2d_Connexion)& C1,
const Handle(MAT2d_Connexion)& C2) const
{
if (C2->IndexFirstLine() == C1->IndexSecondLine()){
if (C2->IndexItemOnFirst() < C1->IndexItemOnSecond()) {
return Standard_True;
}
else if (C2->IndexItemOnFirst() == C1->IndexItemOnSecond()) {
if (C1->IndexFirstLine() == C2->IndexSecondLine()) {
return Standard_True;
}
if (C2->ParameterOnFirst() == C1->ParameterOnSecond()) {
gp_Vec2d Vect1(C1->PointOnSecond(),C1->PointOnFirst());
gp_Vec2d Vect2(C2->PointOnFirst(),C2->PointOnSecond());
if ((Vect1^Vect2)*direction > 0) {
return Standard_True;
}
}
else if (C2->ParameterOnFirst() < C1->ParameterOnSecond()) {
return Standard_True;
}
}
}
return Standard_False;
}
//=============================================================================
//function : UpDateLink
//purpose :
//=============================================================================
void MAT2d_Circuit::UpDateLink(const Standard_Integer IFirst,
const Standard_Integer ILine,
const Standard_Integer ICurveFirst,
const Standard_Integer ICurveLast)
{
Standard_Integer IEqui = IFirst;
Standard_Integer i;
for (i = ICurveFirst; i <= ICurveLast; i++) {
MAT2d_BiInt Key(ILine,i);
if (linkRefEqui.IsBound(Key)) {
linkRefEqui(Key).Append(IEqui);
}
else {
TColStd_SequenceOfInteger L;
linkRefEqui.Bind(Key,L);
linkRefEqui(Key).Append(IEqui);
}
IEqui++;
}
}
//==========================================================================
//function : CrossProd
//purpose : Calcul le produit vectoriel et scalaire entre les directions des
// tangentes a la fin de Geom1 et au debut de Geom2.
// Geom1 et Geom2 doivent etre des courbes.
//==========================================================================
static Standard_Real CrossProd(const Handle(Geom2d_Geometry)& Geom1,
const Handle(Geom2d_Geometry)& Geom2,
Standard_Real& DotProd)
{
Handle(Geom2d_TrimmedCurve) Curve;
Curve = Handle(Geom2d_TrimmedCurve)::DownCast(Geom1);
gp_Dir2d Dir1(Curve->DN(Curve->LastParameter(),1));
Curve = Handle(Geom2d_TrimmedCurve)::DownCast(Geom2);
gp_Dir2d Dir2(Curve->DN(Curve->FirstParameter(),1));
DotProd = Dir1.Dot(Dir2);
return Dir1^Dir2;
}
//=======================================================================
//function : IsSharpCorner
//purpose : Return True Si le point commun entre <Geom1> et <Geom2> est
// une cassure saillante par rapport <Direction>
//=======================================================================
static Standard_Boolean IsSharpCorner (const Handle(Geom2d_Geometry)& Geom1,
const Handle(Geom2d_Geometry)& Geom2,
const Standard_Real& Direction)
{
Standard_Real DotProd;
Standard_Real ProVec = CrossProd (Geom1,Geom2,DotProd);
Standard_Integer NbTest = 1;
Standard_Real DU = Precision::Confusion();
Handle(Geom2d_TrimmedCurve) C1,C2;
C1= Handle(Geom2d_TrimmedCurve)::DownCast(Geom1);
C2= Handle(Geom2d_TrimmedCurve)::DownCast(Geom2);
// Modified by Sergey KHROMOV - Thu Oct 24 19:02:46 2002 Begin
// Add the same criterion as it is in MAT2d_Circuit::InitOpen(..)
// Standard_Real TolAng = 1.E-5;
Standard_Real TolAng = 1.E-8;
// Modified by Sergey KHROMOV - Thu Oct 24 19:02:47 2002 End
while (NbTest <= 10) {
if ((ProVec)*Direction < -TolAng)
return Standard_True; // Saillant.
if ((ProVec)*Direction > TolAng)
return Standard_False; // Rentrant.
else {
if (DotProd > 0) {
return Standard_False; // Plat.
}
TolAng = 1.E-8;
Standard_Real U1 = C1->LastParameter() - NbTest*DU;
Standard_Real U2 = C2->FirstParameter() + NbTest*DU;
gp_Dir2d Dir1(C1->DN(U1,1));
gp_Dir2d Dir2(C2->DN(U2,1));
DotProd = Dir1.Dot(Dir2);
ProVec = Dir1^Dir2;
NbTest++;
}
}
// Rebroussement.
// on calculde des paralleles aux deux courbes du cote du domaine
// de calcul
// Si pas dintersection => saillant.
// Sinon => rentrant.
Standard_Real D ;
Standard_Real Tol = Precision::Confusion();
Standard_Real MilC1 = (C1->LastParameter() + C1->FirstParameter())*0.5;
Standard_Real MilC2 = (C2->LastParameter() + C2->FirstParameter())*0.5;
gp_Pnt2d P = C1->Value(C1->LastParameter());
gp_Pnt2d P1 = C1->Value(MilC1);
gp_Pnt2d P2 = C2->Value(MilC2);
D = Min(P1.Distance(P),P2.Distance(P));
D /= 10;
if (Direction > 0.) D = -D;
Handle(Geom2dAdaptor_HCurve) HC1 = new Geom2dAdaptor_HCurve(C1);
Handle(Geom2dAdaptor_HCurve) HC2 = new Geom2dAdaptor_HCurve(C2);
Adaptor3d_OffsetCurve OC1(HC1,D,MilC1,C1->LastParameter());
Adaptor3d_OffsetCurve OC2(HC2,D,C2->FirstParameter(),MilC2);
Geom2dInt_GInter Intersect;
Intersect.Perform(OC1,OC2,Tol,Tol);
#ifdef DEB
static Standard_Boolean Affich = 0;
if (Affich) {
Standard_Real DU1 = (OC1.LastParameter() - OC1.FirstParameter())/9.;
Standard_Real DU2 = (OC2.LastParameter() - OC2.FirstParameter())/9.;
for (Standard_Integer ki = 0; ki <= 9; ki++) {
gp_Pnt2d P1 = OC1.Value(OC1.FirstParameter()+ki*DU1);
gp_Pnt2d P2 = OC2.Value(OC2.FirstParameter()+ki*DU2);
#ifdef DRAW
Handle(Draw_Marker2D) dr1 = new Draw_Marker2D(P1,Draw_Plus,Draw_vert);
Handle(Draw_Marker2D) dr2 = new Draw_Marker2D(P2,Draw_Plus,Draw_rouge);
dout << dr1;
dout << dr2;
}
dout.Flush();
#else
}
#endif
}
#endif
if (Intersect.IsDone() && !Intersect.IsEmpty()) {
return Standard_False;
}
else {
return Standard_True;
}
return Standard_False;
}
#ifdef DEB
//==========================================================================
//function : MAT2d_DrawCurve
//purpose : Affichage d une courbe <aCurve> de Geom2d. dans une couleur
// definie par <Indice>.
// Indice = 1 jaune,
// Indice = 2 bleu,
// Indice = 3 rouge,
// Indice = 4 vert.
//==========================================================================
void MAT2d_DrawCurve(const Handle(Geom2d_Curve)& aCurve,
const Standard_Integer Indice)
{
Handle(Standard_Type) type = aCurve->DynamicType();
Handle(Geom2d_Curve) curve,CurveDraw;
#ifdef DRAW
Handle(DrawTrSurf_Curve2d) dr;
Draw_Color Couleur;
#endif
if (type == STANDARD_TYPE(Geom2d_TrimmedCurve)) {
curve = Handle(Geom2d_TrimmedCurve)::DownCast(aCurve)->BasisCurve();
type = curve->DynamicType();
// PB de representation des courbes semi_infinies.
gp_Parab2d gpParabola;
gp_Hypr2d gpHyperbola;
Standard_Real Focus;
Standard_Real Limit = 50000.;
Standard_Real delta = 400;
// PB de representation des courbes semi_infinies.
if (aCurve->LastParameter() == Precision::Infinite()) {
if (type == STANDARD_TYPE(Geom2d_Parabola)) {
gpParabola = Handle(Geom2d_Parabola)::DownCast(curve)->Parab2d();
Focus = gpParabola.Focal();
Standard_Real Val1 = Sqrt(Limit*Focus);
Standard_Real Val2 = Sqrt(Limit*Limit);
delta= (Val1 <= Val2 ? Val1:Val2);
}
else if (type == STANDARD_TYPE(Geom2d_Hyperbola)) {
gpHyperbola = Handle(Geom2d_Hyperbola)::DownCast(curve)->Hypr2d();
Standard_Real Majr = gpHyperbola.MajorRadius();
Standard_Real Minr = gpHyperbola.MinorRadius();
Standard_Real Valu1 = Limit/Majr;
Standard_Real Valu2 = Limit/Minr;
Standard_Real Val1 = Log(Valu1+Sqrt(Valu1*Valu1-1));
Standard_Real Val2 = Log(Valu2+Sqrt(Valu2*Valu2+1));
delta = (Val1 <= Val2 ? Val1:Val2);
}
CurveDraw = new Geom2d_TrimmedCurve(aCurve,
aCurve->FirstParameter(),
aCurve->FirstParameter() + delta);
}
else {
CurveDraw = aCurve;
}
// fin PB.
}
else {
CurveDraw = aCurve;
}
#ifdef DRAW
if (Indice == 1) Couleur = Draw_jaune;
else if (Indice == 2) Couleur = Draw_bleu;
else if (Indice == 3) Couleur = Draw_rouge;
else if (Indice == 4) Couleur = Draw_vert;
if (type == STANDARD_TYPE(Geom2d_Circle))
dr = new DrawTrSurf_Curve2d(CurveDraw,Couleur,30);
else if (type == STANDARD_TYPE(Geom2d_Line))
dr = new DrawTrSurf_Curve2d(CurveDraw,Couleur,2);
else
dr = new DrawTrSurf_Curve2d(CurveDraw,Couleur,500);
dout << dr;
dout.Flush();
#endif
}
#endif

132
src/MAT2d/MAT2d_Connexion.cdl Executable file
View File

@@ -0,0 +1,132 @@
-- File: MAT2d_Connexion.cdl
-- Created: Thu Oct 7 15:40:54 1993
-- Author: Yves FRICAUD
-- <yfr@phylox>
---Copyright: Matra Datavision 1993
class Connexion from MAT2d
inherits
TShared from MMgt
---Purpose: A Connexion links two lines of items in a set
-- of lines. It s contains two points and their paramatric
-- definitions on the lines.
-- The items can be points or curves.
uses
Pnt2d from gp
is
Create returns mutable Connexion from MAT2d;
Create(LineA : Integer;
LineB : Integer;
ItemA : Integer;
ItemB : Integer;
Distance : Real;
ParameterOnA : Real;
ParameterOnB : Real;
PointA : Pnt2d from gp;
PointB : Pnt2d from gp)
returns mutable Connexion from MAT2d;
IndexFirstLine(me) returns Integer
---Purpose: Returns the Index on the first line.
is static;
IndexSecondLine(me) returns Integer
---Purpose: Returns the Index on the Second line.
is static;
IndexItemOnFirst(me) returns Integer
---Purpose: Returns the Index of the item on the first line.
is static;
IndexItemOnSecond(me) returns Integer
---Purpose: Returns the Index of the item on the second line.
is static;
ParameterOnFirst(me) returns Real
---Purpose: Returns the parameter of the point on the firstline.
is static;
ParameterOnSecond(me) returns Real
---Purpose: Returns the parameter of the point on the secondline.
is static;
PointOnFirst(me) returns Pnt2d from gp
---Purpose: Returns the point on the firstline.
is static;
PointOnSecond(me) returns Pnt2d from gp
---Purpose: Returns the point on the secondline.
is static;
Distance (me) returns Real
---Purpose: Returns the distance between the two points.
is static;
IndexFirstLine(me : mutable ; anIndex : Integer)
is static;
IndexSecondLine(me : mutable ; anIndex : Integer)
is static;
IndexItemOnFirst(me : mutable ; anIndex : Integer)
is static;
IndexItemOnSecond(me : mutable ; anIndex : Integer)
is static;
ParameterOnFirst(me : mutable ; aParameter : Real)
is static;
ParameterOnSecond(me : mutable ; aParameter : Real)
is static;
PointOnFirst(me : mutable ; aPoint : Pnt2d from gp)
is static;
PointOnSecond(me : mutable ; aPoint : Pnt2d from gp)
is static;
Distance (me : mutable ; aDistance : Real)
is static;
Reverse(me)
---Purpose: Returns the reverse connexion of <me>.
-- the firstpoint is the secondpoint.
-- the secondpoint is the firstpoint.
returns mutable Connexion from MAT2d
is static;
IsAfter(me ; aConnexion : Connexion from MAT2d ; aSense : Real)
---Purpose: Returns <True> if my firstPoint is on the same line
-- than the firstpoint of <aConnexion> and my firstpoint
-- is after the firstpoint of <aConnexion> on the line.
-- <aSense> = 1 if <aConnexion> is on the Left of its
-- firstline, else <aSense> = -1.
returns Boolean from Standard
is static;
Dump (me; Deep : Integer = 0; Offset : Integer = 0)
---Purpose: Print <me>.
is static;
fields
lineA : Integer;
lineB : Integer;
itemA : Integer;
itemB : Integer;
distance : Real;
parameterOnA : Real;
parameterOnB : Real;
pointA : Pnt2d from gp;
pointB : Pnt2d from gp;
end Connexion;

280
src/MAT2d/MAT2d_Connexion.cxx Executable file
View File

@@ -0,0 +1,280 @@
// File: MAT2d_Connexion.cxx
// Created: Mon Oct 11 10:42:18 1993
// Author: Yves FRICAUD
// <yfr@phylox>
#include <MAT2d_Connexion.ixx>
#include <gp_Pnt2d.hxx>
#include <gp_Vec2d.hxx>
//=============================================================================
//function :
//purpose :
//=============================================================================
MAT2d_Connexion::MAT2d_Connexion()
{
}
//=============================================================================
//function :
//purpose :
//=============================================================================
MAT2d_Connexion::MAT2d_Connexion(const Standard_Integer LineA,
const Standard_Integer LineB,
const Standard_Integer ItemA,
const Standard_Integer ItemB,
const Standard_Real Distance,
const Standard_Real ParameterOnA,
const Standard_Real ParameterOnB,
const gp_Pnt2d& PointA,
const gp_Pnt2d& PointB):
lineA(LineA), lineB(LineB),itemA(ItemA),itemB(ItemB),
distance(Distance),
parameterOnA(ParameterOnA),parameterOnB(ParameterOnB),
pointA(PointA),pointB(PointB)
{
}
//=============================================================================
//function : IndexFirstLine
//purpose :
//=============================================================================
Standard_Integer MAT2d_Connexion::IndexFirstLine() const
{
return lineA;
}
//=============================================================================
//function : IndexSecondLine
//purpose :
//=============================================================================
Standard_Integer MAT2d_Connexion::IndexSecondLine() const
{
return lineB;
}
//=============================================================================
//function : IndexItemOnFirst
//purpose :
//=============================================================================
Standard_Integer MAT2d_Connexion::IndexItemOnFirst()const
{
return itemA;
}
//=============================================================================
//function : IndexItemOnSecond
// purpose :
//=============================================================================
Standard_Integer MAT2d_Connexion::IndexItemOnSecond() const
{
return itemB;
}
//=============================================================================
//function : ParameterOnFirst
//purpose :
//=============================================================================
Standard_Real MAT2d_Connexion::ParameterOnFirst() const
{
return parameterOnA;
}
//=============================================================================
//function : ParameterOnSecond
// purpose :
//=============================================================================
Standard_Real MAT2d_Connexion::ParameterOnSecond() const
{
return parameterOnB;
}
//=============================================================================
//function : PointOnFirst
//purpose :
//=============================================================================
gp_Pnt2d MAT2d_Connexion::PointOnFirst() const
{
return pointA;
}
//=============================================================================
//function : PointOnSecond
//purpose :
//=============================================================================
gp_Pnt2d MAT2d_Connexion::PointOnSecond() const
{
return pointB;
}
//=============================================================================
//function : Distance
//purpose :
//=============================================================================
Standard_Real MAT2d_Connexion::Distance() const
{
return distance;
}
//=============================================================================
//function : IndexFirstLine
//purpose :
//=============================================================================
void MAT2d_Connexion::IndexFirstLine(const Standard_Integer anIndex)
{
lineA = anIndex;
}
//=============================================================================
//function : IndexSecondLine
//purpose :
//=============================================================================
void MAT2d_Connexion::IndexSecondLine(const Standard_Integer anIndex)
{
lineB = anIndex;
}
//=============================================================================
//function : IndexItemOnFirst
//purpose :
//=============================================================================
void MAT2d_Connexion::IndexItemOnFirst(const Standard_Integer anIndex)
{
itemA = anIndex;
}
//=============================================================================
//function : IndexItemOnSecond
//purpose :
//=============================================================================
void MAT2d_Connexion::IndexItemOnSecond(const Standard_Integer anIndex)
{
itemB = anIndex;
}
//=============================================================================
//function : ParameterOnFirst
//purpose :
//=============================================================================
void MAT2d_Connexion::ParameterOnFirst(const Standard_Real aParameter)
{
parameterOnA = aParameter;
}
//=============================================================================
//function : ParameterOnSecond
//purpose :
//=============================================================================
void MAT2d_Connexion::ParameterOnSecond(const Standard_Real aParameter)
{
parameterOnB = aParameter;
}
//=============================================================================
//function : PointOnFirst
//purpose :
//=============================================================================
void MAT2d_Connexion::PointOnFirst(const gp_Pnt2d& aPoint)
{
pointA = aPoint;
}
//=============================================================================
//function : PointOnSecond
//purpose :
//=============================================================================
void MAT2d_Connexion::PointOnSecond(const gp_Pnt2d& aPoint)
{
pointB = aPoint;
}
//=============================================================================
//function : Distance
//purpose :
//=============================================================================
void MAT2d_Connexion::Distance(const Standard_Real d)
{
distance = d;
}
//=============================================================================
//function : Reverse
//purpose :
//=============================================================================
Handle(MAT2d_Connexion) MAT2d_Connexion::Reverse() const
{
return new MAT2d_Connexion(lineB,lineA,itemB,itemA,distance,
parameterOnB,parameterOnA,pointB,pointA);
}
//=============================================================================
//function : IsAfter
//purpose :
//=============================================================================
Standard_Boolean MAT2d_Connexion::IsAfter(const Handle(MAT2d_Connexion)& C2,
const Standard_Real Sense) const
{
if (lineA != C2->IndexFirstLine()) {
return Standard_False;
}
if (itemA > C2->IndexItemOnFirst()) {
return Standard_True;
}
else if (itemA == C2->IndexItemOnFirst()){
if ( parameterOnA > C2->ParameterOnFirst()) {
return Standard_True;
}
else if ( parameterOnA == C2->ParameterOnFirst()) {
gp_Vec2d Vect1(C2->PointOnFirst(),C2->PointOnSecond());
gp_Vec2d Vect2(pointA,pointB);
if ((Vect1^Vect2)*Sense > 0) {
return Standard_True;
}
}
}
return Standard_False;
}
static void Indent(const Standard_Integer Offset) {
if (Offset > 0) {
for (Standard_Integer i = 0; i <Offset; i++) {cout <<" ";}
}
}
//=============================================================================
//function : Dump
//purpose :
//=============================================================================
void MAT2d_Connexion::Dump (const Standard_Integer ,
const Standard_Integer Offset) const
{
Standard_Integer MyOffset = Offset;
Indent (Offset);
cout<<"MAT2d_Connexion :"<<endl;
MyOffset++;
Indent (MyOffset);
cout <<"IndexFirstLine :"<<lineA<<endl;
Indent (MyOffset);
cout <<"IndexSecondLine :"<<lineB<<endl;
Indent (MyOffset);
cout <<"IndexItemOnFirst :"<<itemA<<endl;
Indent (MyOffset);
cout <<"IndexItemOnSecond :"<<itemB<<endl;
Indent (MyOffset);
cout <<"ParameterOnFirst :"<<parameterOnA<<endl;
Indent (MyOffset);
cout <<"ParameterOnSecond :"<<parameterOnB<<endl;
Indent (MyOffset);
cout <<"PointOnFirst :"<<endl;
cout <<" X = "<<pointA.X()<<endl;
cout <<" Y = "<<pointA.Y()<<endl;
Indent (MyOffset);
cout <<"PointOnSecond :"<<endl;
cout <<" X = "<<pointB.X()<<endl;
cout <<" Y = "<<pointB.Y()<<endl;
Indent (MyOffset);
cout <<"Distance :"<<distance<<endl;
}

69
src/MAT2d/MAT2d_CutCurve.cdl Executable file
View File

@@ -0,0 +1,69 @@
-- File: MAT2d_CutCurve.cdl
-- Created: Fri Sep 23 14:10:53 1994
-- Author: Yves FRICAUD
-- <yfr@nonox>
---Copyright: Matra Datavision 1994
class CutCurve from MAT2d
---Purpose: Cuts a curve at the extremas of curvature
-- and at the inflections. Constructs a trimmed
-- Curve for each interval.
uses
Curve from Geom2d,
TrimmedCurve from Geom2d,
SequenceOfCurve from TColGeom2d,
Side from MAT
raises
OutOfRange from Standard
is
Create;
Create (C : Curve from Geom2d) returns CutCurve from MAT2d;
Perform (me : in out; C : Curve from Geom2d)
---Purpose: Cuts a curve at the extremas of curvature
-- and at the inflections.
is static;
Perform (me : in out; C : Curve from Geom2d; aSide : Side from MAT)
---Purpose: Cuts a curve at the inflections, and at the extremas
-- of curvature where the concavity is on <aSide>.
is static;
PerformInf (me : in out; C : Curve from Geom2d)
---Purpose: Cuts a curve at the inflections.
is static;
UnModified (me) returns Boolean from Standard
---Purpose: Returns True if the curve is not cut.
is static;
NbCurves (me) returns Integer from Standard
---Purpose: Returns the number of curves.
-- it's allways greatest than 2.
--
raises
OutOfRange from Standard
---Purpose: raises if the Curve is UnModified;
is static;
Value (me ; Index : Integer from Standard) returns TrimmedCurve from Geom2d
---Purpose: Returns the Indexth curve.
raises
OutOfRange from Standard
---Purpose: raises if Index not in the range [1,NbCurves()]
is static;
fields
theCurves : SequenceOfCurve from TColGeom2d;
end CutCurve;

121
src/MAT2d/MAT2d_CutCurve.cxx Executable file
View File

@@ -0,0 +1,121 @@
// File: MAT2d_CutCurve.cxx
// Created: Fri Sep 23 16:25:59 1994
// Author: Yves FRICAUD
// <yfr@nonox>
#include <MAT2d_CutCurve.ixx>
#include <Geom2dLProp_CurAndInf2d.hxx>
#include <Precision.hxx>
#include <gp_Pnt2d.hxx>
#include <Geom2d_TrimmedCurve.hxx>
#include <TColGeom2d_SequenceOfCurve.hxx>
//=======================================================================
//function : MAT2d_CutCurve
//purpose :
//=======================================================================
MAT2d_CutCurve::MAT2d_CutCurve()
{
}
//=======================================================================
//function : MAT2d_CutCurve
//purpose :
//=======================================================================
MAT2d_CutCurve::MAT2d_CutCurve(const Handle(Geom2d_Curve)& C)
{
Perform (C);
}
//=======================================================================
//function : Perform
//purpose :
//=======================================================================
void MAT2d_CutCurve::Perform(const Handle(Geom2d_Curve)& C)
{
theCurves.Clear();
Geom2dLProp_CurAndInf2d Sommets;
Handle(Geom2d_TrimmedCurve) TrimC;
Standard_Real UF,UL,UC;
gp_Pnt2d PF,PL,PC;
Standard_Real PTol = Precision::PConfusion()*10;
Standard_Real Tol = Precision::Confusion()*10;
Standard_Boolean YaCut = Standard_False;
Sommets.Perform (C);
if (Sommets.IsDone() && !Sommets.IsEmpty()) {
UF = C->FirstParameter();
UL = C->LastParameter ();
PF = C->Value(UF);
PL = C->Value(UL);
for (Standard_Integer i = 1; i <= Sommets.NbPoints(); i++) {
UC = Sommets.Parameter(i);
PC = C->Value(UC);
if (UC - UF > PTol && PC.Distance(PF) > Tol) {
if ( UL - UC < PTol || PL.Distance(PC) < Tol) {
break;
}
TrimC = new Geom2d_TrimmedCurve(C,UF,UC);
theCurves.Append(TrimC);
UF = UC;
PF = PC;
YaCut = Standard_True;
}
}
if (YaCut) {
TrimC = new Geom2d_TrimmedCurve(C,UF,UL);
theCurves.Append(TrimC);
}
}
}
//=======================================================================
//function : UnModified
//purpose :
//=======================================================================
Standard_Boolean MAT2d_CutCurve::UnModified() const
{
return theCurves.IsEmpty();
}
//=======================================================================
//function : NbCurves
//purpose :
//=======================================================================
Standard_Integer MAT2d_CutCurve::NbCurves() const
{
if (UnModified()) {Standard_OutOfRange::Raise();}
return theCurves.Length();
}
//=======================================================================
//function : Value
//purpose :
//=======================================================================
Handle(Geom2d_TrimmedCurve) MAT2d_CutCurve::Value (
const Standard_Integer Index)
const
{
if (UnModified()) {Standard_OutOfRange::Raise();}
if ( Index < 1 || Index > theCurves.Length()) {
Standard_OutOfRange::Raise();
}
return Handle(Geom2d_TrimmedCurve)::DownCast(theCurves.Value(Index));
}

View File

@@ -0,0 +1,26 @@
-- File: MAT2d_MapBiIntHasher.cdl
-- Created: Fri Nov 19 12:14:13 1993
-- Author: Yves FRICAUD
-- <yfr@phylox>
---Copyright: Matra Datavision 1993
class MapBiIntHasher from MAT2d
---Purpose:
uses
BiInt from MAT2d
is
HashCode(myclass;
Key1 : BiInt from MAT2d;
Upper : Integer )
---C++: inline
returns Integer;
IsEqual(myclass; Key1, Key2 : BiInt from MAT2d)
---C++: inline
returns Boolean;
end MapBiIntHasher;

View File

@@ -0,0 +1,6 @@
// File: MAT2d_MapBiIntHasher.cxx
// Created: Fri Nov 19 15:23:05 1993
// Author: Yves FRICAUD
// <yfr@phylox>
#include <MAT2d_MapBiIntHasher.ixx>

View File

@@ -0,0 +1,45 @@
// File: MAT2d_MapBiIntHasher.lxx
// Created: Fri Nov 19 12:26:47 1993
// Author: Yves FRICAUD
// <yfr@phylox>
#include <MAT2d_BiInt.hxx>
#include <TColStd_MapIntegerHasher.hxx>
//=======================================================================
//function : HashCode
//purpose :
//=======================================================================
//#ifndef WNT
//inline static Standard_Integer MAT2d_MapBiIntHasher::HashCode
//(const MAT2d_BiInt& Key1, const Standard_Integer upper)
//{
// return TColStd_MapIntegerHasher::HashCode(Key1.FirstIndex(),upper);
//}
//#else
inline Standard_Integer MAT2d_MapBiIntHasher::HashCode
(const MAT2d_BiInt& Key1, const Standard_Integer upper)
{
return TColStd_MapIntegerHasher::HashCode(Key1.FirstIndex(),upper);
}
//#endif
//=======================================================================
//function : IsEqual
//purpose :
//=======================================================================
//#ifndef WNT
//inline static Standard_Boolean MAT2d_MapBiIntHasher::IsEqual
// (const MAT2d_BiInt& Key1,
// const MAT2d_BiInt& Key2)
//{
// return (Key1 == Key2);
//}
//#else
inline Standard_Boolean MAT2d_MapBiIntHasher::IsEqual
(const MAT2d_BiInt& Key1,
const MAT2d_BiInt& Key2)
{
return (Key1 == Key2);
}
//#endif

123
src/MAT2d/MAT2d_MiniPath.cdl Executable file
View File

@@ -0,0 +1,123 @@
-- File: MAT2d_MiniPath.cdl
-- Created: Thu Oct 7 15:41:28 1993
-- Author: Yves FRICAUD
-- <yfr@phylox>
---Copyright: Matra Datavision 1993
class MiniPath from MAT2d
---Purpose: MiniPath computes a path to link all the lines in
-- a set of lines. The path is described as a set of
-- connexions.
--
-- The set of connexions can be seen as an arbitrary Tree.
-- The node of the tree are the lines. The arcs of the
-- tree are the connexions. The ancestror of a line is
-- the connexion which ends on it. The children of a line
-- are the connexions which start on it.
--
-- The children of a line are ordered by the relation
-- <IsAfter> defined on the connexions.
-- (See MAT2s_Connexion.cdl).
uses
Connexion from MAT2d,
SequenceOfConnexion from MAT2d,
DataMapOfIntegerConnexion from MAT2d,
DataMapOfIntegerSequenceOfConnexion from MAT2d,
SequenceOfSequenceOfGeometry from MAT2d
is
Create returns MiniPath from MAT2d;
Perform(me : in out;
Figure : SequenceOfSequenceOfGeometry from MAT2d;
IndStart: Integer;
Sense : Boolean)
---Purpose: Computes the path to link the lines in <Figure>.
-- the path starts on the line of index <IndStart>
-- <Sense> = True if the Circuit turns in the
-- trigonometric sense.
is static;
RunOnConnexions(me : in out)
---Purpose: Run on the set of connexions to compute the path.
-- the path is an exploration of the tree which contains
-- the connexions and their reverses.
-- if the tree of connexions is
-- A
-- / \
-- B E
-- / \ \
-- C D F
--
-- the path is A->B, B->C, C->B, B->D, D->B, B->A, A->E,
-- E->F, F->E, E->A.
is static;
Path(me)
---Purpose: Returns the sequence of connexions corresponding to
-- the path.
---C++: return const&
returns SequenceOfConnexion from MAT2d
is static;
IsConnexionsFrom(me ; Index : Integer)
---Purpose: Returns <True> if there is one Connexion which starts
-- on line designed by <Index>.
returns Boolean from Standard
is static;
ConnexionsFrom(me : in out ; Index : Integer)
---Purpose: Returns the connexions which start on line
-- designed by <Index>.
--
---C++: return&
returns SequenceOfConnexion from MAT2d
is static;
IsRoot(me ; Index : Integer)
---Purpose: Returns <True> if the line designed by <Index> is
-- the root.
returns Boolean from Standard
is static;
Father(me : in out ; Index : Integer)
---Purpose: Returns the connexion which ends on line
-- designed by <Index>.
returns mutable Connexion from MAT2d
is static;
Append (me : in out;
Connexion : Connexion from MAT2d)
---Purpose: Add a connexion to the path.
is static private;
ExploSons(me : in out ;
aPath : in out SequenceOfConnexion from MAT2d ;
aConnexion : Connexion from MAT2d )
is static private;
MinimumL1L2(me;
Figure : SequenceOfSequenceOfGeometry from MAT2d;
L1 : Integer ;
L2 : Integer )
---Purpose: Returns the connexion which realises the minimum of
-- distance between the lines of index <L1> and <L2> in
-- <aFigure>. The connexion is oriented from <L1> to <L2>.
returns mutable Connexion from MAT2d
is static private;
fields
theConnexions : DataMapOfIntegerSequenceOfConnexion from MAT2d;
theFather : DataMapOfIntegerConnexion from MAT2d;
thePath : SequenceOfConnexion from MAT2d;
theDirection : Real from Standard;
indStart : Integer from Standard;
end MiniPath;

422
src/MAT2d/MAT2d_MiniPath.cxx Executable file
View File

@@ -0,0 +1,422 @@
// File: MAT2d_MiniPath.cxx
// Created: Thu Oct 7 19:04:22 1993
// Author: Yves FRICAUD
// <yfr@phylox>
#include <MAT2d_MiniPath.ixx>
#include <MAT2d_Connexion.hxx>
#include <MAT2d_Array2OfConnexion.hxx>
#include <Extrema_POnCurv2d.hxx>
#include <Extrema_ExtCC2d.hxx>
#include <Extrema_ExtPC2d.hxx>
#include <Geom2dAdaptor_Curve.hxx>
#include <Geom2d_Point.hxx>
#include <Geom2d_CartesianPoint.hxx>
#include <TColStd_SequenceOfInteger.hxx>
#include <TColGeom2d_SequenceOfGeometry.hxx>
#include <Standard_NotImplemented.hxx>
//============================================================================
//function : MAT2d_MiniPath()
//purpose :
//============================================================================
MAT2d_MiniPath::MAT2d_MiniPath()
{
}
//============================================================================
//function : Perform
//purpose : Calcul du chemin reliant les differents elements de <aFigure>.
// le chemin part de la ligne <IndStart>.
// <Sense> = True les lignes sont orientes dans le sens trigo.
//============================================================================
void MAT2d_MiniPath::Perform
(const MAT2d_SequenceOfSequenceOfGeometry& Figure,
const Standard_Integer IndStart,
const Standard_Boolean Sense)
{
Standard_Integer i,j;
Standard_Integer NbLines = Figure.Length();
MAT2d_Array2OfConnexion Connexion (1,NbLines,1,NbLines);
indStart = IndStart;
theDirection = 1.;
if (Sense) theDirection = -1.;
//----------------------------------------------------------------------
// Calcul des connexions qui realisent le minimum de distance entre les
// differents elements de la figure.
//----------------------------------------------------------------------
for (i = 1; i < NbLines; i++) {
for (j =i+1; j <= NbLines; j++){
Connexion(i,j) = MinimumL1L2(Figure,i,j);
Connexion(j,i) = Connexion(i,j)->Reverse();
}
}
TColStd_SequenceOfInteger Set1;
TColStd_SequenceOfInteger Set2;
Standard_Real DistS1S2;
Standard_Integer IndiceLine1,IndiceLine2;
#ifndef DEB
Standard_Integer ISuiv =0,MinOnSet1 =0,MinOnSet2 =0;
#else
Standard_Integer ISuiv,MinOnSet1,MinOnSet2;
#endif
//---------------------------------------------------------------------------
// - 0 Set1 est initialise avec la ligne de depart.
// Set2 contient toutes les autres.
//---------------------------------------------------------------------------
Set1.Append(IndStart);
for (i=1 ; i<=NbLines ; i++){
if (i != IndStart){
Set2.Append(i);
}
}
//---------------------------------------------------------------------------
// - 1 Recherche de la connexion C la plus courte entre Set1 et Set2.
// - 2 La ligne de Set2 realisant le minimum de distance est inseree dans
// Set1 et supprime dans Set2.
// - 3 Insertion de la connexion dans l ensemble des connexions.
// - 4 Si Set2 est non vide retour en 1.
//---------------------------------------------------------------------------
while (!Set2.IsEmpty()){
DistS1S2 = RealLast();
for (i = 1; i <= Set1.Length(); i++) {
IndiceLine1 = Set1.Value(i);
for (j = 1 ; j<= Set2.Length() ;j++) {
IndiceLine2 = Set2.Value(j);
if(Connexion(IndiceLine1,IndiceLine2)->Distance() < DistS1S2) {
ISuiv = j;
DistS1S2 = Connexion(IndiceLine1,IndiceLine2)->Distance();
MinOnSet1 = IndiceLine1;
MinOnSet2 = IndiceLine2;
}
}
}
Set1.Append(Set2.Value(ISuiv));
Set2.Remove(ISuiv);
Append(Connexion(MinOnSet1,MinOnSet2));
}
//----------------------------------------------------------------
// Construction du chemin en parcourant l ensemble des connexions.
//----------------------------------------------------------------
RunOnConnexions() ;
}
//============================================================================
//function : Append
//purpose : Insertion d une nouvelle connexion dans le chemin.
//
// Les connexions et les lignes constituent un arbre dont
// - les noeuds sont les lignes.
// - les connexions sont les branches.
//
//============================================================================
void MAT2d_MiniPath::Append(const Handle(MAT2d_Connexion)& C)
{
Handle(MAT2d_Connexion) CC;
if (!theConnexions.IsBound(C->IndexFirstLine())) {
MAT2d_SequenceOfConnexion Seq;
theConnexions.Bind(C->IndexFirstLine(),Seq);
theConnexions(C->IndexFirstLine()).Append(C);
theFather.Bind(C->IndexSecondLine(),C);
return;
}
MAT2d_SequenceOfConnexion& Seq = theConnexions(C->IndexFirstLine());
Standard_Integer IndexAfter = 0;
Standard_Integer NbConnexions = Seq.Length();
for (Standard_Integer i = 1; i <= NbConnexions; i++) {
CC = Seq.Value(i);
if (CC->IsAfter(C,theDirection)){
IndexAfter = i;
break;
}
}
//----------------------------------------------------------------------
// Insertion de <C> avant <IAfter>.
// Si <IAfter> = 0 => Pas de connexions apres <C> => <C> est la
// derniere.
//----------------------------------------------------------------------
if (IndexAfter == 0) {
Seq.Append(C);
}
else {
Seq.InsertBefore(IndexAfter,C);
}
theFather.Bind(C->IndexSecondLine(),C);
return;
}
//============================================================================
//function : Path
//purpose : Retour de la sequence de connexions definissant le chemin.
//============================================================================
const MAT2d_SequenceOfConnexion& MAT2d_MiniPath::Path() const
{
return thePath;
}
//============================================================================
//function : IsConnexionsFrom
//purpose :
//============================================================================
Standard_Boolean MAT2d_MiniPath::IsConnexionsFrom
(const Standard_Integer i) const
{
return (theConnexions.IsBound(i));
}
//============================================================================
//function : Connexions
//purpose : Retour de la sequence de connexions issue de la ligne <i>.
//============================================================================
MAT2d_SequenceOfConnexion& MAT2d_MiniPath::ConnexionsFrom
(const Standard_Integer i)
{
return theConnexions.ChangeFind(i);
}
//============================================================================
//function : IsRoot
//purpose :
//============================================================================
Standard_Boolean MAT2d_MiniPath::IsRoot(const Standard_Integer ILine) const
{
return (ILine == indStart);
}
//============================================================================
//function : Father
//purpose : Retour de la premiere connexion qui arrive sur la ligne i
//============================================================================
Handle(MAT2d_Connexion) MAT2d_MiniPath::Father(const Standard_Integer ILine)
{
return theFather.ChangeFind(ILine);
}
//============================================================================
//function : RunOnConnexions
//purpose : Construction de <thePath> en parcourant <theConnexions>.
//============================================================================
void MAT2d_MiniPath::RunOnConnexions()
{
Standard_Integer i;
Handle(MAT2d_Connexion) C;
const MAT2d_SequenceOfConnexion& SC = theConnexions(indStart);
thePath.Clear();
for ( i = 1; i <= SC.Length(); i++) {
C = SC.Value(i);
thePath.Append(C);
ExploSons(thePath,C);
thePath.Append(C->Reverse());
}
}
//============================================================================
//function : ExploSons
//purpose :
//============================================================================
void MAT2d_MiniPath::ExploSons( MAT2d_SequenceOfConnexion& CResult,
const Handle(MAT2d_Connexion)& CRef )
{
Standard_Integer i;
Standard_Integer Index = CRef->IndexSecondLine();
if (!theConnexions.IsBound(Index)) return;
const MAT2d_SequenceOfConnexion& SC = theConnexions(Index);
Handle(MAT2d_Connexion) CRR = CRef->Reverse();
Handle(MAT2d_Connexion) C;
for ( i = 1; i <= SC.Length(); i++) {
C = SC.Value(i);
if (C->IsAfter(CRR,theDirection)) {
CResult.Append(C);
ExploSons(CResult,C);
CResult.Append(C->Reverse());
}
}
for ( i = 1; i <= SC.Length(); i++) {
C = SC.Value(i);
if (!C->IsAfter(CRR,theDirection)) {
CResult.Append(C);
ExploSons(CResult,C);
CResult.Append(C->Reverse());
}
else {
break;
}
}
}
//============================================================================
//function : MinimumL1L2
//purpose : Calcul de la connexion realisant le minimum de distance entre les
// lignes d indice <IL1> et <IL2> dans <Figure>.
//============================================================================
Handle(MAT2d_Connexion) MAT2d_MiniPath::MinimumL1L2
(const MAT2d_SequenceOfSequenceOfGeometry& Figure,
const Standard_Integer IL1,
const Standard_Integer IL2) const
{
Extrema_POnCurv2d PointOnCurv1,PointOnCurv2;
#ifndef DEB
Standard_Integer IC1,IC2,IMinC1 =0,IMinC2 =0,i;
#else
Standard_Integer IC1,IC2,IMinC1,IMinC2,i;
#endif
Standard_Real DistL1L2_2,DistP1P2_2;
#ifndef DEB
Standard_Real ParameterOnC1 =0.,ParameterOnC2 =0.;
#else
Standard_Real ParameterOnC1,ParameterOnC2;
#endif
TColGeom2d_SequenceOfGeometry L1,L2;
gp_Pnt2d Point1,Point2,P1,P2;
Handle(Geom2d_Curve) Item1;
Handle(Geom2d_Curve) Item2;
L1 = Figure.Value(IL1);
L2 = Figure.Value(IL2);
DistL1L2_2 = RealLast();
//---------------------------------------------------------------------------
// Calcul des extremas de distances entre les composants de L1 et de L2.
//---------------------------------------------------------------------------
for (IC1 = 1; IC1 <= L1.Length(); IC1++) {
Handle(Standard_Type) Type1 = L1.Value(IC1)->DynamicType();
if (Type1 != STANDARD_TYPE(Geom2d_CartesianPoint)) {
Item1 = Handle(Geom2d_Curve)::DownCast(L1.Value(IC1));
}
else {
P1 = Handle(Geom2d_Point)::DownCast(L1.Value(IC1))->Pnt2d();
}
for (IC2 = 1; IC2 <= L2.Length(); IC2++) {
Handle(Standard_Type) Type2 = L2.Value(IC2)->DynamicType();
if (Type2 != STANDARD_TYPE(Geom2d_CartesianPoint)) {
Item2 = Handle(Geom2d_Curve)::DownCast(L2.Value(IC2));
}
else {
P2 = Handle(Geom2d_Point)::DownCast(L2.Value(IC2))->Pnt2d();
}
if (Type1 == STANDARD_TYPE(Geom2d_CartesianPoint) &&
Type2 == STANDARD_TYPE(Geom2d_CartesianPoint) ) {
DistP1P2_2 = P1.SquareDistance(P2);
if (DistP1P2_2 <= DistL1L2_2) {
DistL1L2_2 = DistP1P2_2;
IMinC1 = IC1;
IMinC2 = IC2;
Point1 = P1;
Point2 = P2;
ParameterOnC1 = 0.;
ParameterOnC2 = 0.;
}
}
else if (Type1 == STANDARD_TYPE(Geom2d_CartesianPoint)) {
Geom2dAdaptor_Curve C2(Item2);
Extrema_ExtPC2d Extremas(P1,C2);
if (Extremas.IsDone()){
for (i = 1; i <= Extremas.NbExt(); i++) {
if (Extremas.SquareDistance(i) < DistL1L2_2) {
DistL1L2_2 = Extremas.SquareDistance(i);
IMinC1 = IC1;
IMinC2 = IC2;
PointOnCurv2 = Extremas.Point(i);
ParameterOnC1 = 0.;
ParameterOnC2 = PointOnCurv2.Parameter();
Point1 = P1;
Point2 = PointOnCurv2.Value();
}
}
}
}
else if (Type2 == STANDARD_TYPE(Geom2d_CartesianPoint)) {
Geom2dAdaptor_Curve C1(Item1);
Extrema_ExtPC2d Extremas(P2,C1);
if (Extremas.IsDone()){
for (i=1;i<=Extremas.NbExt();i++) {
if (Extremas.SquareDistance(i) < DistL1L2_2) {
DistL1L2_2 = Extremas.SquareDistance(i);
IMinC1 = IC1;
IMinC2 = IC2;
PointOnCurv1 = Extremas.Point(i);
ParameterOnC2 = 0.;
ParameterOnC1 = PointOnCurv1.Parameter();
Point1 = PointOnCurv1.Value();
Point2 = P2;
}
}
}
}
else {
Geom2dAdaptor_Curve C1(Item1);
Geom2dAdaptor_Curve C2(Item2);
Extrema_ExtCC2d Extremas(C1,C2);
if (!Extremas.IsParallel() && Extremas.IsDone()){
for ( i=1; i <= Extremas.NbExt(); i++) {
if (Extremas.SquareDistance(i) < DistL1L2_2) {
DistL1L2_2 = Extremas.SquareDistance(i);
IMinC1 = IC1;
IMinC2 = IC2;
Extremas.Points(i,PointOnCurv1,PointOnCurv2);
ParameterOnC1 = PointOnCurv1.Parameter();
ParameterOnC2 = PointOnCurv2.Parameter();
Point1 = PointOnCurv1.Value();
Point2 = PointOnCurv2.Value();
}
}
}
}
}
}
Handle(MAT2d_Connexion) ConnexionL1L2;
ConnexionL1L2 = new MAT2d_Connexion(IL1,IL2,IMinC1,IMinC2,sqrt (DistL1L2_2),
ParameterOnC1,ParameterOnC2,
Point1,Point2);
return ConnexionL1L2;
}

View File

@@ -0,0 +1,42 @@
-- File: MAT2d_SketchExplorer.cdl
-- Created: Mon Jul 12 12:07:58 1993
-- Author: Yves FRICAUD
-- <yfr@phylox>
---Copyright: Matra Datavision 1993
deferred class SketchExplorer from MAT2d
---Purpose: SketchExplorer is an iterator on a sketch. A
-- sketch is a set of contours, each contour is a set
-- of curves from Geom2d.
uses
Curve from Geom2d
is
NumberOfContours(me)
--- Purpose : Returns the number of contours in the figure.
returns Integer;
Init(me : in out ; ContourIndex : Integer );
--- Purpose : Initializes the curves explorer on the contour
-- of range <ContourIndex>.
More(me) returns Boolean from Standard;
--- Purpose: Returns False if there is no more curves on the
-- current contour.
Next(me : in out);
--- Purpose : Moves to the next curve of the current contour.
Value(me) returns Curve from Geom2d;
--- Purpose : Returns the current curve on the current contour.
end SketchExplorer;

View File

@@ -0,0 +1,5 @@
// File: MAT2d_SketchExplorer.cxx
// Created: Tue Jul 13 15:09:31 1993
// Author: Yves FRICAUD
// <yfr@phylox>

227
src/MAT2d/MAT2d_Tool2d.cdl Executable file
View File

@@ -0,0 +1,227 @@
-- File: MAT2d_Tool2d.cdl
-- Created: Mon Jul 12 16:54:50 1993
-- Author: Yves FRICAUD
-- <yfr@phylox>
---Copyright: Matra Datavision 1993
class Tool2d from MAT2d
---Purpose: Set of the methods useful for the MAT's computation.
-- Tool2d contains the geometry of the bisecting locus.
uses
Bisec from Bisector,
Side from MAT,
Bisector from MAT,
Connexion from MAT2d,
Circuit from MAT2d,
DataMapOfIntegerBisec from MAT2d,
DataMapOfIntegerPnt2d from MAT2d,
DataMapOfIntegerVec2d from MAT2d,
SequenceOfInteger from TColStd,
Pnt2d from gp,
Vec2d from gp,
TrimmedCurve from Geom2d,
Curve from Geom2d,
Geometry from Geom2d
is
Create returns Tool2d from MAT2d;
--- Purpose : Empty Constructor.
--- Category : Initialisation.
Sense(me : in out ; aside : Side from MAT)
--- Purpose :<aSide> defines the side of the computation of the map.
is static;
InitItems(me : in out ;
aCircuit : Circuit from MAT2d )
--- Purpose : InitItems cuts the line in Items.
-- this Items are the geometrics representations of
-- the BasicElts from MAT.
is static;
--- Category : Set of the methods used by the algorithm MAT from MAT.
NumberOfItems(me)
--- Purpose : Returns the Number of Items .
returns Integer is static;
ToleranceOfConfusion(me) returns Real
---Purpose: Returns tolerance to test the confusion of two points.
is static;
FirstPoint(me : in out ; anitem : Integer;
dist : out Real )
--- Purpose : Creates the point at the origin of the bisector between
-- anitem and the previous item.
-- dist is the distance from the FirstPoint to <anitem>.
-- Returns the index of this point in <theGeomPnts>.
returns Integer is static;
TangentBefore(me : in out ; anitem : Integer)
--- Purpose : Creates the Tangent at the end of the Item defined
-- by <anitem>. Returns the index of this vector in
-- <theGeomVecs>
returns Integer is static;
TangentAfter(me : in out ; anitem : Integer)
--- Purpose : Creates the Reversed Tangent at the origin of the Item
-- defined by <anitem>. Returns the index of this vector in
-- <theGeomVecs>
returns Integer is static;
Tangent(me : in out ; bisector : Integer)
--- Purpose : Creates the Tangent at the end of the bisector defined
-- by <bisector>. Returns the index of this vector in
-- <theGeomVecs>
returns Integer is static;
CreateBisector(me : in out ; abisector : mutable Bisector from MAT)
--- Purpose : Creates the geometric bisector defined by <abisector>.
is static;
TrimBisector(me : in out ; abisector : mutable Bisector from MAT)
--- Purpose : Trims the geometric bisector by the <firstparameter>
-- of <abisector>.
-- If the parameter is out of the bisector, Return FALSE.
-- else Return True.
returns Boolean is static;
TrimBisector(me : in out ;
abisector : mutable Bisector from MAT ;
apoint : Integer)
--- Purpose : Trims the geometric bisector by the point of index
-- <apoint> in <theGeomPnts>.
-- If the point is out of the bisector, Return FALSE.
-- else Return True.
returns Boolean is static;
IntersectBisector(me : in out ;
bisectorone : mutable Bisector from MAT ;
bisectortwo : mutable Bisector from MAT ;
intpnt : in out Integer)
--- Purpose : Computes the point of intersection between the
-- bisectors defined by <bisectorone> and
-- <bisectortwo> .
-- If this point exists, <intpnt> is its index
-- in <theGeomPnts> and Return the distance of the point
-- from the bisector else Return <RealLast>.
returns Real is static;
Distance(me;
abisector : Bisector from MAT;
param1 : Real;
param2 : Real)
---Purpose: Returns the distance between the two points designed
-- by their parameters on <abisector>.
returns Real is static;
Dump(me ; bisector , erease : Integer) is static;
--- Purpose : displays informations about the bisector defined by
-- <bisector>.
--- Category : Querying.
GeomBis(me ; Index: Integer)
--- Purpose : Returns the <Bisec> of index <Index> in
-- <theGeomBisectors>.
--
---C++: return const &
returns Bisec from Bisector
is static;
GeomElt(me ; Index: Integer)
--- Purpose : Returns the Geometry of index <Index> in <theGeomElts>.
returns Geometry from Geom2d
is static;
GeomPnt(me ; Index: Integer)
--- Purpose : Returns the point of index <Index> in the <theGeomPnts>.
--
---C++: return const &
returns Pnt2d from gp
is static;
GeomVec(me ; Index: Integer)
--- Purpose : Returns the vector of index <Index> in the
-- <theGeomVecs>.
--
---C++: return const &
returns Vec2d from gp
is static;
Circuit(me)
---Purpose:
--
returns Circuit from MAT2d
is static;
---Category: Modification
BisecFusion(me : in out;
Index1 : Integer;
Index2 : Integer)
is static;
ChangeGeomBis(me : in out ; Index: Integer)
--- Purpose : Returns the <Bisec> of index <Index> in
-- <theGeomBisectors>.
--
---C++: return &
returns Bisec from Bisector
is static;
---Category: Private
IsSameDistance(me ;
bisectorone , bisectortwo : any Bisector from MAT ;
apoint : Pnt2d from gp;
adistance : out Real)
--- Purpose : Returns True if the point <apoint> is equidistant to
-- the elements separated by bisectors <bisectorone> and
-- <bisectortwo>.
-- In this case <adistance> is the distance of the point
-- from the bisectors.
returns Boolean
is static private;
Projection (me ;
IndexElt : Integer from Standard;
Point : Pnt2d from gp ;
Distance : out Real from Standard)
---Purpose: Return <True> if the Point can be projected
-- on the element designed by <IndexElt>.
-- In this case <Distance> is the minimum of distance
-- between Point and its projections.
returns Boolean
is static private;
TrimBisec (me ;
Bis : in out Bisec from Bisector ;
IndexEdge : Integer from Standard ;
OnLine : Boolean from Standard ;
StartOrEnd : Integer from Standard )
is static private;
fields
theDirection : Real;
theNumberOfBisectors : Integer;
theNumberOfPnts : Integer;
theNumberOfVecs : Integer;
theCircuit : Circuit from MAT2d;
theGeomBisectors : DataMapOfIntegerBisec from MAT2d;
theGeomPnts : DataMapOfIntegerPnt2d from MAT2d;
theGeomVecs : DataMapOfIntegerVec2d from MAT2d;
theLinesLength : SequenceOfInteger from TColStd;
end Tool2d;

1276
src/MAT2d/MAT2d_Tool2d.cxx Executable file

File diff suppressed because it is too large Load Diff