1
0
mirror of https://git.dev.opencascade.org/repos/occt.git synced 2025-08-09 13:22:24 +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

4
src/Select3D/FILES Executable file
View File

@@ -0,0 +1,4 @@
Select3D_Pnt.hxx
Select3D_Pnt2d.hxx
Select3D_Box2d.hxx
Select3D_Macro.hxx

84
src/Select3D/Select3D.cdl Executable file
View File

@@ -0,0 +1,84 @@
-- File: Select3D.cdl
-- Created: Wed Feb 22 11:15:53 1995
-- Author: Mister rmi
-- <rmi@photon>
--Modified by Rob Jan 13 th 98 : Compute Depth on EyeLine for
-- Each Kind of SensitiveEntity.
-- (Deferred Method to be implemented)
--
---Copyright: Matra Datavision 1995
package Select3D
---Purpose: The Select3D package provides the following services
-- - definition of standard 3D sensitive primitives such as points, curves and faces.
-- - recovery of the bounding boxes in the 2D graphic selection space, if required.
-- - a 3D-2D projector.
uses
Standard,
TCollection,
TColStd,
TColgp,
gp,
Bnd,
Poly,
TopLoc,
Geom,
SelectBasics,
V3d
is
---Category: sensitive entities
enumeration TypeOfSensitivity is TOS_INTERIOR,TOS_BOUNDARY,TOS_EXTERIOR
end TypeOfSensitivity;
---Purpose: Provides values for type of sensitivity in 3D.
-- These are used to specify whether it is the interior,
-- the boundary, or the exterior of a 3D sensitive entity which is sensitive.
deferred class SensitiveEntity;
deferred class SensitivePoly;
class SensitivePoint;
class SensitiveSegment;
class SensitiveCircle;
class SensitiveCurve;
class SensitiveTriangle;
class SensitiveTriangulation;
class SensitiveFace;
class SensitiveBox;
class SensitiveWire;
class SensitiveGroup;
class SensitiveEntitySequence instantiates Sequence from TCollection
(SensitiveEntity from Select3D);
---Category: selectors/projectors
class Projector;
class ListOfSensitiveTriangle instantiates List from TCollection
(SensitiveTriangle from Select3D);
class ListOfSensitive instantiates List from TCollection
(SensitiveEntity from Select3D);
imported Pnt;
imported Pnt2d;
imported Box2d;
end Select3D;

79
src/Select3D/Select3D_Box2d.hxx Executable file
View File

@@ -0,0 +1,79 @@
#ifndef _Select3D_Box2d_HeaderFile
#define _Select3D_Box2d_HeaderFile
#include<Bnd_Box2d.hxx>
#include<Standard_ShortReal.hxx>
#include<Select3D_Macro.hxx>
struct Select3D_Box2d
{
Standard_ShortReal xmin, ymin, xmax, ymax;
Select3D_Box2d()
{
SetVoid();
}
Select3D_Box2d(const Bnd_Box2d& theBox)
{
SetField(theBox);
}
inline operator Bnd_Box2d() const
{
Bnd_Box2d aBox;
aBox.SetVoid();
if( !IsVoid() )
aBox.Update(xmin, ymin, xmax, ymax);
return aBox;
}
inline Select3D_Box2d operator = ( const Bnd_Box2d& theBox)
{
SetField(theBox);
return *this;
}
inline void Update(const gp_Pnt2d& thePnt)
{
Bnd_Box2d aBox;
aBox.Set(thePnt);
if( !IsVoid() )
aBox.Update(xmin, ymin, xmax, ymax);
SetField(aBox);
}
inline void SetVoid()
{
xmin = ymin = ShortRealLast();
xmax = ymax = ShortRealFirst();
}
inline Standard_Boolean IsVoid() const
{
return ( xmin == ShortRealLast() && ymin == ShortRealLast() && xmax == ShortRealFirst() && ymax == ShortRealFirst() );
}
private:
inline void SetField(const Bnd_Box2d& theBox)
{
if( theBox.IsVoid() )
SetVoid();
else {
Standard_Real x, y, x1, y1;
theBox.Get(x, y, x1, y1);
xmin = DToF(x);
ymin = DToF(y);
xmax = DToF(x1);
ymax = DToF(y1);
}
}
};
#endif

13
src/Select3D/Select3D_Macro.hxx Executable file
View File

@@ -0,0 +1,13 @@
#ifndef _Select3D_Macro_HeaderFile
#define _Select3D_Macro_HeaderFile
#include <Standard_ShortReal.hxx>
// Safe conversion of Standard_ShortReal(float) to Standard_Real(double)
inline Standard_ShortReal DToF (Standard_Real a)
{
return a > ShortRealLast() ? ShortRealLast() :
a < ShortRealFirst() ? ShortRealFirst() : (Standard_ShortReal)a;
}
#endif

33
src/Select3D/Select3D_Pnt.hxx Executable file
View File

@@ -0,0 +1,33 @@
#ifndef _Select3D_Pnt_HeaderFile
#define _Select3D_Pnt_HeaderFile
#include<gp_Pnt.hxx>
#include<Standard_ShortReal.hxx>
#include<Select3D_Macro.hxx>
struct Select3D_Pnt{
Standard_ShortReal x, y, z;
inline operator gp_Pnt() const
{
return gp_Pnt(x, y, z);
}
inline operator gp_XYZ() const
{
return gp_XYZ(x, y, z);
}
inline gp_Pnt operator = (const gp_Pnt& thePnt)
{
x = DToF(thePnt.X());
y = DToF(thePnt.Y());
z = DToF(thePnt.Z());
return *this;
}
};
#endif

33
src/Select3D/Select3D_Pnt2d.hxx Executable file
View File

@@ -0,0 +1,33 @@
#ifndef _Select3D_Pnt2d_HeaderFile
#define _Select3D_Pnt2d_HeaderFile
#include<gp_Pnt2d.hxx>
#include<Standard_ShortReal.hxx>
#include<Select3D_Macro.hxx>
struct Select3D_Pnt2d{
Standard_ShortReal x, y;
inline operator gp_Pnt2d() const
{
return gp_Pnt2d(x, y);
}
inline operator gp_XY() const
{
return gp_XY(x, y);
}
inline gp_Pnt2d operator = (const gp_Pnt2d& thePnt)
{
x = DToF(thePnt.X());
y = DToF(thePnt.Y());
return *this;
}
};
#endif

View File

@@ -0,0 +1,183 @@
-- File: Select3D_Projector.cdl
-- Created: Thu Mar 12 13:32:28 1992
-- Author: Christophe MARION
-- <cma@sdsun2> copie quasi exacte de HLRAlgo_Projector
---Copyright: Matra Datavision 1992
class Projector from Select3D
---Purpose: A framework to define 3D projectors.
uses
Real from Standard,
Boolean from Standard,
Trsf from gp,
GTrsf from gp,
Lin from gp,
Pnt from gp,
Vec from gp,
Ax2 from gp,
Vec2d from gp,
Pnt2d from gp,
Box from Bnd,
View from V3d
raises
NoSuchObject from Standard
is
Create(aView:View from V3d) returns Projector from Select3D;
--- Purpose: Constructs the 3D projector object defined by the 3D view aView.
Create returns Projector from Select3D;
Create(CS : Ax2 from gp)
---Purpose: Creates an axonometric projector. <CS> is the
-- viewing coordinate system.
returns Projector from Select3D;
Create(CS : Ax2 from gp;
Focus : Real from Standard)
---Purpose: Creates a perspective projector. <CS> is the
-- viewing coordinate system.
returns Projector from Select3D;
Create(T : Trsf from gp;
Persp : Boolean from Standard;
Focus : Real from Standard)
---Purpose: build a Projector with automatic minmax directions.
returns Projector from Select3D;
Create(T : Trsf from gp;
Persp : Boolean from Standard;
Focus : Real from Standard;
v1,v2,v3 : Vec2d from gp)
---Purpose: build a Projector with given minmax directions.
returns Projector from Select3D;
Create(GT : GTrsf from gp;
Persp : Boolean from Standard;
Focus : Real from Standard)
---Purpose: build a Projector with automatic minmax directions.
returns Projector from Select3D;
Delete(me:out) is virtual;
---C++: alias "Standard_EXPORT virtual ~Select3D_Projector(){Delete() ; }"
Set (me: in out ;
T : Trsf from gp;
Persp : Boolean from Standard;
Focus : Real from Standard)
is static;
SetView(me:in out ; V : View from V3d);
---Purpose: Sets the 3D view V used at the time of construction.
View(me) returns any View from V3d;
---Purpose: Returns the 3D view used at the time of construction.
---C++: return const&
---C++: inline
Directions(me; D1 , D2 , D3 : out Vec2d from gp)
---C++: inline
is virtual;
Scaled(me : in out; On : Boolean from Standard = Standard_False)
---Purpose: to compute with the given scale and translation.
is virtual;
Perspective(me) returns Boolean
---Purpose: Returns True if there is a perspective transformation.
---C++: inline
is virtual;
Transformation(me) returns GTrsf from gp
---Purpose: Returns the active transformation.
---C++: inline
---C++: return const &
is virtual;
InvertedTransformation(me) returns GTrsf from gp
---Purpose: Returns the active inverted transformation.
---C++: inline
---C++: return const &
is virtual;
FullTransformation(me) returns Trsf from gp
---Purpose: Returns the original transformation.
---C++: inline
---C++: return const &
is virtual;
Focus(me) returns Real from Standard
---Purpose: Returns the focal length.
---C++: inline
raises
NoSuchObject from Standard -- if there is no perspective
is virtual;
Transform(me; D : in out Vec from gp)
---C++: inline
is virtual;
Transform(me; Pnt : in out Pnt from gp)
---C++: inline
is virtual;
Project(me; P : Pnt from gp;
Pout : out Pnt2d from gp)
---Purpose: Transform and apply perspective if needed.
is virtual;
Project(me; P : Pnt from gp;
X,Y,Z : out Real from Standard)
---Purpose: Transform and apply perspective if needed.
is static;
Project(me; P : Pnt from gp;
D1 : Vec from gp;
Pout : out Pnt2d from gp;
D1out : out Vec2d from gp)
---Purpose: Transform and apply perspective if needed.
is virtual;
BoxAdd(me; P : Pnt2d from gp;
B : out Box from Bnd)
---Purpose: Adds to the box <B> the min-max of the point <P>.
is virtual;
Shoot(me; X , Y : Real from Standard)
returns Lin from gp
---Purpose: return a line going through the eye towards the
-- 2d point <X,Y>.
is virtual;
SetDirection(me: in out)
is static private;
Transform(me; P : in out Pnt from gp;
T : GTrsf from gp)
---C++: inline
is virtual;
Transform(me; D : in out Lin from gp;
T : GTrsf from gp)
---C++: inline
is virtual;
fields
myType : Integer from Standard;
myPersp : Boolean from Standard is protected;
myFocus : Real from Standard is protected;
myScaledTrsf : Trsf from gp is protected;
myGTrsf : GTrsf from gp is protected;
myInvTrsf : GTrsf from gp is protected;
myD1 : Vec2d from gp is protected;
myD2 : Vec2d from gp is protected;
myD3 : Vec2d from gp is protected;
myView : View from V3d;
end Projector;

View File

@@ -0,0 +1,506 @@
// File: Select3D_Projector.cxx
// Created: Fri Mar 13 11:08:32 1992
// Author: Christophe MARION
// <cma@sdsun2>
#define IMP240100 //GG
// Change RefToPix()/Convert() to Project() method.
#include <Select3D_Projector.ixx>
#include <Precision.hxx>
#include <gp_Ax3.hxx>
#include <gp_Vec.hxx>
#include <gp_Vec2d.hxx>
// formula for derivating a perspective, from Mathematica
// X'[t] X[t] Z'[t]
// D1 = -------- + -------------
// Z[t] Z[t] 2
// 1 - ---- f (1 - ----)
// f f
//=======================================================================
//function : Select3D_Projector
//purpose :
//=======================================================================
Select3D_Projector::Select3D_Projector(const Handle(V3d_View)& aViou):
myPersp(aViou->Type()==V3d_PERSPECTIVE),
myFocus(aViou->Focale()),
myD1(1,0),
myD2(0,1),
myD3(1,1),
myView(aViou)
{
Standard_Real Xat,Yat,Zat,XUp,YUp,ZUp,DX,DY,DZ;
//Standard_Boolean Pers=Standard_False;
aViou->At(Xat,Yat,Zat);
aViou->Up(XUp,YUp,ZUp);
aViou->Proj(DX,DY,DZ);
gp_Pnt At (Xat,Yat,Zat);
gp_Dir Zpers (DX,DY,DZ);
gp_Dir Ypers (XUp,YUp,ZUp);
gp_Dir Xpers = Ypers.Crossed(Zpers);
gp_Ax3 Axe (At, Zpers, Xpers);
myScaledTrsf.SetTransformation(Axe);
myGTrsf.SetTrsf(myScaledTrsf);
Scaled();
}
Select3D_Projector::Select3D_Projector () :
myPersp(Standard_False),myFocus(0),myD1(1,0),myD2(0,1),myD3(1,1)
{
Scaled();
SetDirection();
}
//=======================================================================
//function : Select3D_Projector
//purpose :
//=======================================================================
Select3D_Projector::Select3D_Projector
(const gp_Ax2& CS) :
myPersp(Standard_False), myFocus(0)
{
myScaledTrsf.SetTransformation(CS);
myGTrsf.SetTrsf(myScaledTrsf);
Scaled();
SetDirection();
}
//=======================================================================
//function : Select3D_Projector
//purpose :
//=======================================================================
Select3D_Projector::Select3D_Projector
(const gp_Ax2& CS,
const Standard_Real Focus) :
myPersp(Standard_True), myFocus(Focus)
{
myScaledTrsf.SetTransformation(CS);
myGTrsf.SetTrsf(myScaledTrsf);
Scaled();
SetDirection();
}
//=======================================================================
//function : Select3D_Projector
//purpose :
//=======================================================================
Select3D_Projector::Select3D_Projector
(const gp_Trsf& T,
const Standard_Boolean Persp,
const Standard_Real Focus) :
myPersp(Persp),
myFocus(Focus),
myScaledTrsf(T)
{
myGTrsf.SetTrsf(myScaledTrsf);
Scaled();
SetDirection();
}
//=======================================================================
//function : Select3D_Projector
//purpose :
//=======================================================================
Select3D_Projector::Select3D_Projector
(const gp_Trsf& T,
const Standard_Boolean Persp,
const Standard_Real Focus,
const gp_Vec2d& v1,
const gp_Vec2d& v2,
const gp_Vec2d& v3) :
myPersp(Persp),
myFocus(Focus),
myScaledTrsf(T),
myD1(v1),
myD2(v2),
myD3(v3)
{
myGTrsf.SetTrsf(myScaledTrsf);
Scaled();
}
//=======================================================================
//function : Select3D_Projector
//purpose :
//=======================================================================
Select3D_Projector::Select3D_Projector
(const gp_GTrsf& GT,
const Standard_Boolean Persp,
const Standard_Real Focus) :
myPersp(Persp),
myFocus(Focus),
myGTrsf(GT)
{
Scaled();
SetDirection();
}
void Select3D_Projector::Delete()
{}
//=======================================================================
//function : Set
//purpose :
//=======================================================================
void Select3D_Projector::Set
(const gp_Trsf& T,
const Standard_Boolean Persp,
const Standard_Real Focus)
{
myPersp = Persp;
myFocus = Focus;
myScaledTrsf = T;
Scaled();
SetDirection();
}
//=======================================================================
//function : Scaled
//purpose :
//=======================================================================
#include <gp_Mat.hxx>
static Standard_Integer TrsfType(const gp_GTrsf& Trsf) {
const gp_Mat& Mat = Trsf.VectorialPart();
if( (Abs(Mat.Value(1,1)-1.0) < 1e-15)
&& (Abs(Mat.Value(2,2)-1.0) < 1e-15)
&& (Abs(Mat.Value(3,3)-1.0) < 1e-15)) {
return(1); //-- top
}
else if( (Abs(Mat.Value(1,1)-0.7071067811865476) < 1e-15)
&& (Abs(Mat.Value(1,2)+0.5) < 1e-15)
&& (Abs(Mat.Value(1,3)-0.5) < 1e-15)
&& (Abs(Mat.Value(2,1)-0.7071067811865476) < 1e-15)
&& (Abs(Mat.Value(2,2)-0.5) < 1e-15)
&& (Abs(Mat.Value(2,3)+0.5) < 1e-15)
&& (Abs(Mat.Value(3,1)) < 1e-15)
&& (Abs(Mat.Value(3,2)-0.7071067811865476) < 1e-15)
&& (Abs(Mat.Value(3,3)-0.7071067811865476) < 1e-15)) {
return(0); //--
}
else if( (Abs(Mat.Value(1,1)-1.0) < 1e-15)
&& (Abs(Mat.Value(2,3)-1.0) < 1e-15)
&& (Abs(Mat.Value(3,2)+1.0) < 1e-15)) {
return(2); //-- front
}
else if( (Abs(Mat.Value(1,1)-0.7071067811865476) < 1e-15)
&& (Abs(Mat.Value(1,2)-0.7071067811865476) < 1e-15)
&& (Abs(Mat.Value(1,3)) < 1e-15)
&& (Abs(Mat.Value(2,1)+0.5) < 1e-15)
&& (Abs(Mat.Value(2,2)-0.5) < 1e-15)
&& (Abs(Mat.Value(2,3)-0.7071067811865476) < 1e-15)
&& (Abs(Mat.Value(3,1)-0.5) < 1e-15)
&& (Abs(Mat.Value(3,2)+0.5) < 1e-15)
&& (Abs(Mat.Value(3,3)-0.7071067811865476) < 1e-15)) {
return(3); //-- axo
}
return(-1);
}
void Select3D_Projector::Scaled (const Standard_Boolean On)
{
myType=-1;
if (!On) {
if (!myPersp) {
//myGTrsf.SetTranslationPart(gp_XYZ(0.,0.,0.));
myType=TrsfType(myGTrsf);
}
}
myInvTrsf = myGTrsf;
myInvTrsf.Invert();
}
//=======================================================================
//function : Project
//purpose :
//=======================================================================
void Select3D_Projector::Project (const gp_Pnt& P, gp_Pnt2d& Pout) const
{
if(!myView.IsNull()){
Standard_Real Xout,Yout;
// V3d_View
#ifdef IMP240100
myView->Project(P.X(),P.Y(),P.Z(),Xout,Yout);
#else
Standard_Integer Xp,Yp;
myView->RefToPix(P.X(),P.Y(),P.Z(),Xp,Yp);
myView->Convert(Xp,Yp,Xout,Yout);
#endif
Pout.SetCoord(Xout,Yout);
}
else{
if(myType!=-1) {
Standard_Real X,Y;
switch (myType) {
case 0: { //-- axono standard
Standard_Real x07 = P.X()*0.7071067811865475;
Standard_Real y05 = P.Y()*0.5;
Standard_Real z05 = P.Z()*0.5;
X=x07-y05+z05;
Y=x07+y05-z05;
//-- Z=0.7071067811865475*(P.Y()+P.Z());
break;
}
case 1: { //-- top
X=P.X(); Y=P.Y(); //-- Z=P.Z();
Pout.SetCoord(X,Y);
break;
}
case 2: {
X=P.X(); Y=P.Z(); //-- Z=-P.Y();
Pout.SetCoord(X,Y);
break;
}
case 3: {
Standard_Real xmy05 = (P.X()-P.Y())*0.5;
Standard_Real z07 = P.Z()*0.7071067811865476;
X=0.7071067811865476*(P.X()+P.Y());
Y=-xmy05+z07;
Pout.SetCoord(X,Y);
//-- Z= xmy05+z07;
break;
}
default: {
gp_Pnt P2 = P;
Transform(P2);
if (myPersp) {
Standard_Real R = 1.-P2.Z()/myFocus;
Pout.SetCoord(P2.X()/R,P2.Y()/R);
}
else
Pout.SetCoord(P2.X(),P2.Y());
break;
}
}
}
else {
gp_Pnt P2 = P;
Transform(P2);
if (myPersp) {
Standard_Real R = 1.-P2.Z()/myFocus;
Pout.SetCoord(P2.X()/R,P2.Y()/R);
}
else
Pout.SetCoord(P2.X(),P2.Y());
}
}
}
//=======================================================================
//function : Project
//purpose :
//=======================================================================
/* ====== TYPE 0 (??)
(0.7071067811865476, -0.5 , 0.4999999999999999)
(0.7071067811865475, 0.5000000000000001, -0.5 )
(0.0, 0.7071067811865475, 0.7071067811865476)
====== TYPE 1 (top)
(1.0, 0.0, 0.0)
(0.0, 1.0, 0.0)
(0.0, 0.0, 1.0)
======= TYPE 2 (front)
(1.0, 0.0 , 0.0)
(0.0, 1.110223024625157e-16 , 1.0)
(0.0, -1.0 , 1.110223024625157e-16)
======= TYPE 3
( 0.7071067811865476, 0.7071067811865475, 0.0)
(-0.5 , 0.5000000000000001, 0.7071067811865475)
( 0.4999999999999999, -0.5 , 0.7071067811865476)
*/
void Select3D_Projector::Project (const gp_Pnt& P,
Standard_Real& X,
Standard_Real& Y,
Standard_Real& Z) const
{
if(!myView.IsNull()){
// Standard_Real Xout,Yout;
// V3d_View
#ifdef IMP240100
myView->Project(P.X(),P.Y(),P.Z(),X,Y);
#else
Standard_Integer Xp,Yp;
myView->RefToPix(P.X(),P.Y(),P.Z(),Xp,Yp);
myView->Convert(Xp,Yp,X,Y);
#endif
}
else{
if(myType!=-1) {
switch (myType) {
case 0: { //-- axono standard
Standard_Real x07 = P.X()*0.7071067811865475;
Standard_Real y05 = P.Y()*0.5;
Standard_Real z05 = P.Z()*0.5;
X=x07-y05+z05;
Y=x07+y05-z05;
Z=0.7071067811865475*(P.Y()+P.Z());
break;
}
case 1: { //-- top
X=P.X(); Y=P.Y(); Z=P.Z();
break;
}
case 2: {
X=P.X(); Y=P.Z(); Z=-P.Y();
break;
}
case 3: {
Standard_Real xmy05 = (P.X()-P.Y())*0.5;
Standard_Real z07 = P.Z()*0.7071067811865476;
X=0.7071067811865476*(P.X()+P.Y());
Y=-xmy05+z07;
Z= xmy05+z07;
break;
}
default: {
gp_Pnt P2 = P;
Transform(P2);
P2.Coord(X,Y,Z);
break;
}
}
}
else {
gp_Pnt P2 = P;
Transform(P2);
P2.Coord(X,Y,Z);
if (myPersp) {
Standard_Real R = 1 - Z / myFocus;
X = X / R;
Y = Y / R;
}
}
}
}
//=======================================================================
//function : Project
//purpose :
//=======================================================================
void Select3D_Projector::Project (const gp_Pnt& P,
const gp_Vec& D1,
gp_Pnt2d& Pout,
gp_Vec2d& D1out) const
{
gp_Pnt PP = P;
Transform(PP);
gp_Vec DD1 = D1;
Transform(DD1);
if (myPersp) {
Standard_Real R = 1. - PP.Z() / myFocus;
Pout .SetCoord(PP .X()/R , PP.Y()/R);
D1out.SetCoord(DD1.X()/R + PP.X()*DD1.Z()/(myFocus * R*R),
DD1.Y()/R + PP.Y()*DD1.Z()/(myFocus * R*R));
}
else {
Pout .SetCoord(PP .X(),PP .Y());
D1out.SetCoord(DD1.X(),DD1.Y());
}
}
//=======================================================================
//function : BoxAdd
//purpose :
//=======================================================================
void Select3D_Projector::BoxAdd
(const gp_Pnt2d& P,
Bnd_Box& B) const
{
gp_Vec2d V(P.X(),P.Y());
gp_Pnt PP(myD1 * V, myD2 * V, myD3 * V);
B.Add(PP);
}
//=======================================================================
//function : Shoot
//purpose :
//=======================================================================
gp_Lin Select3D_Projector::Shoot
(const Standard_Real X,
const Standard_Real Y) const
{
gp_Lin L;
if (myPersp) {
L = gp_Lin(gp_Pnt(0,0, myFocus),
gp_Dir(X,Y,-myFocus));
}
else {
L = gp_Lin(gp_Pnt(X,Y,0),
gp_Dir(0,0,-1));
}
Transform(L, myInvTrsf);
return L;
}
//=======================================================================
//function : SetDirection
//purpose :
//=======================================================================
void Select3D_Projector::SetDirection ()
{
gp_Vec V1(1,0,0);
Transform(V1);
if ((Abs(V1.X()) + Abs(V1.Y())) < Precision::Angular()) V1.SetCoord(1,1,0);
gp_Vec2d D1(V1.X(),V1.Y());
myD1.SetCoord(-D1.Y(),D1.X());
gp_Vec V2(0,1,0);
Transform(V2);
if ((Abs(V2.X()) + Abs(V2.Y())) < Precision::Angular()) V2.SetCoord(1,1,0);
gp_Vec2d D2(V2.X(),V2.Y());
myD2.SetCoord(-D2.Y(),D2.X());
gp_Vec V3(0,0,1);
Transform(V3);
if ((Abs(V3.X()) + Abs(V3.Y())) < Precision::Angular()) V3.SetCoord(1,1,0);
gp_Vec2d D3(V3.X(),V3.Y());
myD3.SetCoord(-D3.Y(),D3.X());
}
void Select3D_Projector::SetView(const Handle(V3d_View)& aViou)
{
myView = aViou;
myPersp = aViou->Type()==V3d_PERSPECTIVE;
myFocus= aViou->Focale();
Standard_Real Xat,Yat,Zat,XUp,YUp,ZUp,DX,DY,DZ;
//Standard_Boolean Pers=Standard_False;
aViou->At(Xat,Yat,Zat);
aViou->Up(XUp,YUp,ZUp);
aViou->Proj(DX,DY,DZ);
gp_Pnt At (Xat,Yat,Zat);
gp_Dir Zpers (DX,DY,DZ);
gp_Dir Ypers (XUp,YUp,ZUp);
gp_Dir Xpers = Ypers.Crossed(Zpers);
gp_Ax3 Axe (At, Zpers, Xpers);
myScaledTrsf.SetTransformation(Axe);
Scaled();
}

View File

@@ -0,0 +1,127 @@
// File: Select3D_Projector.lxx
// Created: Thu Jul 9 12:50:25 1992
// Author: Christophe MARION
// <cma@sdsun1>
#include <Standard_NoSuchObject.hxx>
#include <gp_Vec.hxx>
#include <gp_Pnt.hxx>
#include <gp_Lin.hxx>
#include <V3d_View.hxx>
#include <V3d.hxx>
//=======================================================================
//function : Directions
//purpose :
//=======================================================================
inline void Select3D_Projector::Directions
(gp_Vec2d& D1, gp_Vec2d& D2, gp_Vec2d& D3) const
{
D1 = myD1;
D2 = myD2;
D3 = myD3;
}
//=======================================================================
//function : Perspective
//purpose :
//=======================================================================
inline Standard_Boolean Select3D_Projector::Perspective() const
{ return myPersp; }
//=======================================================================
//function : Transformation
//purpose :
//=======================================================================
inline const gp_GTrsf& Select3D_Projector::Transformation() const
{ return myGTrsf; }
//=======================================================================
//function : InvertedTransformation
//purpose :
//=======================================================================
inline const gp_GTrsf& Select3D_Projector::InvertedTransformation() const
{ return myInvTrsf; }
//=======================================================================
//function : FullTransformation
//purpose :
//=======================================================================
inline const gp_Trsf& Select3D_Projector::FullTransformation() const
{ return myScaledTrsf; }
//=======================================================================
//function : Focus
//purpose :
//=======================================================================
inline Standard_Real Select3D_Projector::Focus() const
{
Standard_NoSuchObject_Raise_if(!myPersp,
"Select3D_Projector::Not a Perpective");
return myFocus;
}
//=======================================================================
//function : Transform
//purpose :
//=======================================================================
inline void Select3D_Projector::Transform (gp_Vec& D) const
{
gp_XYZ coord = D.XYZ();
if (myGTrsf.Form() == gp_Identity || myGTrsf.Form() == gp_Translation) { }
else if (myGTrsf.Form() == gp_PntMirror) { coord.Reverse(); }
else { coord.Multiply (myGTrsf.VectorialPart()); }
D.SetXYZ(coord);
}
//=======================================================================
//function : Transform
//purpose :
//=======================================================================
inline void Select3D_Projector::Transform (gp_Pnt& Pnt) const
{
gp_XYZ xyz = Pnt.XYZ();
myGTrsf.Transforms(xyz);
Pnt = gp_Pnt(xyz);
}
inline const Handle(V3d_View)& Select3D_Projector::View() const
{return myView;}
inline void Select3D_Projector::Transform (gp_Lin& Lin, const gp_GTrsf& T) const
{
gp_Ax1 ax1 = Lin.Position();
gp_XYZ xyz = ax1.Location().XYZ();
T.Transforms(xyz);
ax1.SetLocation(gp_Pnt(xyz));
gp_Dir dir = ax1.Direction();
gp_XYZ coord = dir.XYZ();
if (T.Form() == gp_Identity || T.Form() == gp_Translation) { }
else if (T.Form() == gp_PntMirror) { coord.Reverse(); }
else {
coord.Multiply (T.VectorialPart());
Standard_Real D = coord.Modulus();
coord.Divide(D);
}
dir.SetXYZ(coord);
ax1.SetDirection(dir);
Lin.SetPosition(ax1);
}
inline void Select3D_Projector::Transform (gp_Pnt& Pnt, const gp_GTrsf& T) const
{
gp_XYZ xyz = Pnt.XYZ();
T.Transforms(xyz);
Pnt = gp_Pnt(xyz);
}

View File

@@ -0,0 +1,113 @@
-- File: Select3D_SensitiveBox.cdl
-- Created: Thu Apr 13 10:16:20 1995
-- Author: Robert COUBLANC
-- <rob@photon>
---Copyright: Matra Datavision 1995
class SensitiveBox from Select3D
inherits SensitiveEntity from Select3D
---Purpose: A framework to define selection by a sensitive box.
uses
Pnt from gp,
Pnt2d from gp,
Box from Bnd,
Box2d from Bnd,
Projector from Select3D,
Lin from gp,
EntityOwner from SelectBasics,
ListOfBox2d from SelectBasics,
Array1OfPnt2d from TColgp,
Location from TopLoc
is
Create (OwnerId : EntityOwner from SelectBasics;
BoundingBox : Box from Bnd)
returns mutable SensitiveBox;
---Purpose: Constructs a sensitive box object defined by the
-- owner OwnerId, and the bounding box BoundingBox.
Create (OwnerId : EntityOwner from SelectBasics;
XMin,YMin,ZMin,
XMax,YMax,ZMax : Real)
returns mutable SensitiveBox;
--- Purpose: Constructs a sensitive box object defined by the
-- owner OwnerId, and the coordinates Xmin, YMin, ZMin, XMax, YMax, ZMax.
-- Xmin, YMin and ZMin define the minimum point in
-- the front lower left hand corner of the box,
-- and XMax, YMax and ZMax define the maximum
-- point in the back upper right hand corner of the box.
Project (me:mutable;aProjector : Projector from Select3D)
is redefined static;
---Level: Public
---Purpose: projection of the sensitive primitive in order to
-- get 2D boxes for the Sort Algorithm
Areas (me:mutable ; boxes : in out ListOfBox2d from SelectBasics)
is redefined static;
---Level: Public
---Purpose: gives the 2D boxes which represent the Box in the
-- selection process...
GetConnected(me:mutable;aLocation: Location from TopLoc)
returns SensitiveEntity from Select3D is redefined static;
Matches(me :mutable;
X,Y : Real from Standard;
aTol: Real from Standard;
DMin: out Real from Standard)
returns Boolean
is static;
---Level: Public
---Purpose:
--
Matches (me :mutable;
XMin,YMin,XMax,YMax : Real from Standard;
aTol: Real from Standard)
returns Boolean is redefined static;
Matches (me :mutable;
Polyline:Array1OfPnt2d from TColgp;
aBox:Box2d from Bnd;
aTol: Real from Standard)
returns Boolean
is redefined virtual;
---Level: Public
ComputeDepth(me;EyeLine: Lin from gp)
returns Real from Standard is redefined static;
Dump(me; S: in out OStream;FullDump : Boolean from Standard = Standard_True) is redefined virtual;
Box(me) returns Box from Bnd;
---Purpose: Returns the sensitive 3D box used at the time of construction.
---C++: inline
---C++: return const &
ProjectBox(me:mutable;aPrj: Projector from Select3D;aBox:Box from Bnd)
is static private;
fields
mybox3d : Box from Bnd;
mybox2d : Box2d from Bnd;
end SensitiveBox;

View File

@@ -0,0 +1,204 @@
// Copyright: Matra-Datavision 1995
// File: Select3D_SensitiveBox.cxx
// Created: Thu Apr 13 10:28:17 1995
// Author: Robert COUBLANC
// <rob>
#include <Select3D_SensitiveBox.ixx>
#include <gp_Pnt2d.hxx>
#include <gp_Pnt.hxx>
#include <Bnd_Box.hxx>
#include <ElCLib.hxx>
//==================================================
// Function: Constructor
// Purpose :
//==================================================
Select3D_SensitiveBox::Select3D_SensitiveBox(const Handle(SelectBasics_EntityOwner)& OwnerId,
const Bnd_Box& BBox):
Select3D_SensitiveEntity(OwnerId),
mybox3d(BBox){}
//==================================================
// Function: Constructor
// Purpose :
//==================================================
Select3D_SensitiveBox::
Select3D_SensitiveBox(const Handle(SelectBasics_EntityOwner)& OwnerId,
const Standard_Real XMin,
const Standard_Real YMin,
const Standard_Real ZMin,
const Standard_Real XMax,
const Standard_Real YMax,
const Standard_Real ZMax):
Select3D_SensitiveEntity(OwnerId)
{
mybox3d.Update(XMin,YMin,ZMin,XMax,YMax,ZMax);
}
//==================================================
// Function: Project
// Purpose :
//==================================================
void Select3D_SensitiveBox::
Project(const Select3D_Projector& aProj)
{
Select3D_SensitiveEntity::Project(aProj); // to set the field last proj...
if(HasLocation()){
Bnd_Box B = mybox3d.Transformed(Location().Transformation());
ProjectBox(aProj,B);
}
else
ProjectBox(aProj,mybox3d);
}
//==================================================
// Function:
// Purpose :
//==================================================
void Select3D_SensitiveBox::
Areas(SelectBasics_ListOfBox2d& aSeq)
{ aSeq.Append(mybox2d);}
//=======================================================================
//function : GetConnected
//purpose :
//=======================================================================
Handle(Select3D_SensitiveEntity) Select3D_SensitiveBox::GetConnected(const TopLoc_Location& aLoc)
{
Handle(Select3D_SensitiveBox) NiouEnt = new Select3D_SensitiveBox(myOwnerId,mybox3d);
if(HasLocation()) NiouEnt->SetLocation(Location());
NiouEnt->UpdateLocation(aLoc);
return NiouEnt;
}
//==================================================
// Function:
// Purpose :
//==================================================
Standard_Boolean Select3D_SensitiveBox::
Matches(const Standard_Real X,
const Standard_Real Y,
const Standard_Real aTol,
Standard_Real& DMin)
{
Select3D_SensitiveEntity::Matches(X,Y,aTol,DMin);
DMin=0.;
return Standard_True;
}
//==================================================
// Function:
// Purpose :
//==================================================
Standard_Boolean Select3D_SensitiveBox::
Matches (const Standard_Real XMin,
const Standard_Real YMin,
const Standard_Real XMax,
const Standard_Real YMax,
const Standard_Real aTol)
{
Bnd_Box2d BoundBox;
BoundBox.Update(XMin-aTol,YMin-aTol,XMax+aTol,YMax+aTol);
return(!BoundBox.IsOut(mybox2d));
}
//=======================================================================
//function : Matches
//purpose :
//=======================================================================
Standard_Boolean Select3D_SensitiveBox::
Matches (const TColgp_Array1OfPnt2d& aPoly,
const Bnd_Box2d& aBox,
const Standard_Real aTol)
{
return(!aBox.IsOut(mybox2d));
}
//=======================================================================
//function : Dump
//purpose :
//=======================================================================
void Select3D_SensitiveBox::Dump(Standard_OStream& S,const Standard_Boolean FullDump) const
{
S<<"\tSensitiveBox 3D :\n";
if(HasLocation())
S<<"\t\tExisting Location"<<endl;
Standard_Real XMin,YMin,ZMin,XMax,YMax,ZMax;
mybox3d.Get(XMin,YMin,ZMin,XMax,YMax,ZMax);
S<<"\t\t PMin [ "<<XMin<<" , "<<YMin<<" , "<<ZMin<<" ]";
S<<"\t\t PMax [ "<<XMax<<" , "<<YMax<<" , "<<ZMax<<" ]"<<endl;
if(FullDump){
// S<<"\t\t\tOwner:"<<myOwnerId<<endl;
Select3D_SensitiveEntity::DumpBox(S,mybox2d);}
}
//=======================================================================
//function : ProjectBox
//purpose :
//=======================================================================
void Select3D_SensitiveBox::ProjectBox(const Select3D_Projector& aPrj,
const Bnd_Box& aBox)
{
mybox2d.SetVoid();
gp_Pnt2d curp2d;
Standard_Real XMin,YMin,ZMin,XMax,YMax,ZMax;
aBox.Get(XMin,YMin,ZMin,XMax,YMax,ZMax);
aPrj.Project(gp_Pnt(XMin,YMin,ZMin),curp2d);
mybox2d.Update(curp2d.X(),curp2d.Y());
aPrj.Project(gp_Pnt(XMax,YMin,ZMin),curp2d);
mybox2d.Update(curp2d.X(),curp2d.Y());
aPrj.Project(gp_Pnt(XMax,YMax,ZMin),curp2d);
mybox2d.Update(curp2d.X(),curp2d.Y());
aPrj.Project(gp_Pnt(XMin,YMax,ZMin),curp2d);
mybox2d.Update(curp2d.X(),curp2d.Y());
aPrj.Project(gp_Pnt(XMin,YMin,ZMax),curp2d);
mybox2d.Update(curp2d.X(),curp2d.Y());
aPrj.Project(gp_Pnt(XMax,YMin,ZMax),curp2d);
mybox2d.Update(curp2d.X(),curp2d.Y());
aPrj.Project(gp_Pnt(XMax,YMax,ZMax),curp2d);
mybox2d.Update(curp2d.X(),curp2d.Y());
aPrj.Project(gp_Pnt(XMin,YMax,ZMax),curp2d);
mybox2d.Update(curp2d.X(),curp2d.Y());
}
//=======================================================================
//function : ComputeDepth
//purpose :
//=======================================================================
Standard_Real Select3D_SensitiveBox::ComputeDepth(const gp_Lin& EyeLine) const
{
Standard_Real XMin,YMin,ZMin,XMax,YMax,ZMax;
mybox3d.Get(XMin,YMin,ZMin,XMax,YMax,ZMax);
gp_Pnt PMid((XMin+XMax)/2.,(YMin+YMax)/2.,(ZMin+ZMax)/2.);
return ElCLib::Parameter(EyeLine,PMid);
}

View File

@@ -0,0 +1,6 @@
// File: Select3D_SensitiveBox.lxx
// Created: Wed Jul 16 18:04:10 1997
// Author: Robert COUBLANC
// <rob@robox.paris1.matra-dtv.fr>
inline const Bnd_Box& Select3D_SensitiveBox::Box() const
{return mybox3d;}

View File

@@ -0,0 +1,107 @@
-- File: Select3D_SensitiveCircle.cdl
-- Created: Tue Feb 6 11:35:02 1996
-- Author: Robert COUBLANC
-- <rob@fidox>
---Copyright: Matra Datavision 1996
class SensitiveCircle from Select3D
inherits SensitivePoly from Select3D
---Purpose: A framework to define sensitive 3D arcs and circles.
uses
Pnt from gp,
Pnt2d from gp,
Projector from Select3D,
Lin from gp,
EntityOwner from SelectBasics,
ListOfBox2d from SelectBasics,
Circle from Geom,
Array1OfPnt from TColgp,
HArray1OfPnt from TColgp,
Array1OfPnt2d from TColgp,
Box2d from Bnd,
Location from TopLoc
is
Create (OwnerId : EntityOwner from SelectBasics;
TheCircle : Circle from Geom;
FilledCircle : Boolean = Standard_False;
NbOfPoints : Integer = 6)
returns mutable SensitiveCircle;
---Level: Public
---Purpose: Constructs the sensitive circle object defined by the
-- owner OwnerId, the circle Circle, the Boolean
-- FilledCircle and the number of points NbOfPoints.
Create (OwnerId : EntityOwner from SelectBasics;
TheCircle : Circle from Geom;
u1 : Real ;
u2 : Real;
FilledCircle : Boolean = Standard_False;
NbOfPoints : Integer = 6)
returns mutable SensitiveCircle;
---Level: Public
---Purpose: Constructs the sensitive arc object defined by the
-- owner OwnerId, the circle Circle, the parameters u1
-- and u2, the Boolean FilledCircle and the number of points NbOfPoints.
-- u1 and u2 define the first and last points of the arc on Circle.
Create(OwnerId : EntityOwner from SelectBasics;
apolyg3d : HArray1OfPnt from TColgp;
FilledCircle : Boolean from Standard = Standard_False)
returns mutable SensitiveCircle;
---Level: Internal
---Purpose: Constructs the sensitive circle object defined by the
-- owner OwnerId, the array of triangles apolyg3d, and the Boolean FilledCircle.
-- apolyg3d is an array of consecutive triangles on the
-- circle. The triangle i+1 lies on the intersection of the
-- tangents to the circle of i and i+2.
Create(OwnerId : EntityOwner from SelectBasics;
apolyg3d : Array1OfPnt from TColgp;
FilledCircle : Boolean from Standard = Standard_False)
returns mutable SensitiveCircle;
---Purpose: Constructs the sensitive circle object defined by the
-- owner OwnerId, the array of points apolyg3d, and the Boolean FilledCircle.
Matches(me :mutable;
X,Y : Real from Standard;
aTol: Real from Standard;
DMin: out Real from Standard)
returns Boolean
is static;
Matches (me :mutable;
XMin,YMin,XMax,YMax : Real from Standard;
aTol: Real from Standard)
returns Boolean
is redefined static;
Matches (me :mutable;
Polyline:Array1OfPnt2d from TColgp;
aBox:Box2d from Bnd;
aTol: Real from Standard)
returns Boolean
is redefined virtual;
---Level: Public
ComputeDepth(me;EyeLine: Lin from gp)
returns Real from Standard is redefined static;
ArrayBounds(me;Low,Up:in out Integer);
GetPoint3d(me;rank:Integer) returns Pnt from gp;
---Level: Internal
Dump(me; S: in out OStream;FullDump : Boolean from Standard = Standard_True) is redefined virtual;
fields
myFillStatus : Boolean;
myDetectedIndex : Integer from Standard; -- used for depth...
end SensitiveCircle;

View File

@@ -0,0 +1,345 @@
// File: Select3D_SensitiveCircle.cxx
// Created: Tue Feb 6 14:15:06 1996
// Author: Robert COUBLANC
// <rob@fidox>
// Modified Tue Apr 14 1998 by rob : fix Bug : Case of Null Radius Circle...
#include <Select3D_SensitiveCircle.ixx>
#include <Precision.hxx>
#include <gp_Lin2d.hxx>
#include <CSLib_Class2d.hxx>
#include <Select3D_SensitiveTriangle.hxx>
#include <ElCLib.hxx>
#include <Select3D_Pnt.hxx>
#include <Select3D_Pnt2d.hxx>
//=======================================================================
//function : Select3D_SensitiveCircle (constructeur)
//purpose : Definition d'un cercle sensible
//=======================================================================
static Standard_Integer S3D_GetCircleNBPoints(const Handle(Geom_Circle)& C,
const Standard_Integer anInputNumber)
{
if(C->Radius()>Precision::Confusion())
return 2*anInputNumber+1;
return 1;
}
static Standard_Integer S3D_GetArcNBPoints(const Handle(Geom_Circle)& C,
const Standard_Integer anInputNumber)
{
if(C->Radius()>Precision::Confusion())
return 2*anInputNumber-1;
return 1;
}
Select3D_SensitiveCircle::
Select3D_SensitiveCircle(const Handle(SelectBasics_EntityOwner)& OwnerId,
const Handle(Geom_Circle)& TheCircle,
const Standard_Boolean FilledCircle,
const Standard_Integer NbPoints):
Select3D_SensitivePoly(OwnerId, S3D_GetCircleNBPoints(TheCircle,NbPoints)),
myFillStatus(FilledCircle),
myDetectedIndex(-1)
{
if(mynbpoints!=1){
gp_Pnt p1,p2;//,pmid;
gp_Vec v1;//,v2;
Standard_Real ustart = TheCircle->FirstParameter(),uend = TheCircle->LastParameter();
Standard_Real du = (uend-ustart)/NbPoints;
Standard_Real R = TheCircle->Radius();
Standard_Integer rank = 1;
Standard_Real curu =ustart;
for(Standard_Integer i=1;i<=NbPoints;i++)
{
TheCircle->D1(curu,p1,v1);
v1.Normalize();
((Select3D_Pnt*)mypolyg3d)[rank-1] = p1;
rank++;
p2 = gp_Pnt(p1.X()+v1.X()*tan(du/2.)*R,
p1.Y()+v1.Y()*tan(du/2.)*R,
p1.Z()+v1.Z()*tan(du/2.)*R);
((Select3D_Pnt*)mypolyg3d)[rank-1] = p2;
rank++;
curu+=du;
}
((Select3D_Pnt*)mypolyg3d)[NbPoints*2] = ((Select3D_Pnt*)mypolyg3d)[0];
}
// Radius = 0.0
else
((Select3D_Pnt*)mypolyg3d)[0] = TheCircle->Location();
}
//=======================================================================
//function : Select3D_SensitiveCircle (constructeur)
//purpose : Definition d'un arc sensible
//=======================================================================
Select3D_SensitiveCircle::
Select3D_SensitiveCircle(const Handle(SelectBasics_EntityOwner)& OwnerId,
const Handle(Geom_Circle)& TheCircle,
const Standard_Real u1,
const Standard_Real u2,
const Standard_Boolean FilledCircle,
const Standard_Integer NbPoints):
Select3D_SensitivePoly(OwnerId, S3D_GetArcNBPoints(TheCircle,NbPoints)),
myFillStatus(FilledCircle),
myDetectedIndex(-1)
{
if(mynbpoints > 1){
gp_Pnt p1,p2;//,pmid;
gp_Vec v1;//,v2;
Standard_Real ustart = u1;
Standard_Real uend = u2;
if (u1 > u2) {ustart=u1;uend=u2;}
Standard_Real du = (uend-ustart)/(NbPoints-1);
Standard_Real R = TheCircle->Radius();
Standard_Integer rank = 1;
Standard_Real curu =ustart;
for(Standard_Integer i=1;i<=NbPoints-1;i++)
{
TheCircle->D1(curu,p1,v1);
v1.Normalize();
((Select3D_Pnt*)mypolyg3d)[rank-1] = p1;
rank++;
p2 = gp_Pnt(p1.X()+v1.X()*tan(du/2.)*R,
p1.Y()+v1.Y()*tan(du/2.)*R,
p1.Z()+v1.Z()*tan(du/2.)*R);
((Select3D_Pnt*)mypolyg3d)[rank-1] = p2;
rank++;
curu+=du;
}
TheCircle->D0(uend,p1);
((Select3D_Pnt*)mypolyg3d)[NbPoints*2-2] = p1;
}
else
((Select3D_Pnt*)mypolyg3d)[0] = TheCircle->Location();
}
//=======================================================================
//function : Select3D_SensitiveCircle
//purpose :
//=======================================================================
Select3D_SensitiveCircle::Select3D_SensitiveCircle(const Handle(SelectBasics_EntityOwner)& OwnerId,
const Handle(TColgp_HArray1OfPnt)& Thepolyg3d,
const Standard_Boolean FilledCircle):
Select3D_SensitivePoly(OwnerId, Thepolyg3d),
myFillStatus(FilledCircle),
myDetectedIndex(-1)
{
}
Select3D_SensitiveCircle::Select3D_SensitiveCircle(const Handle(SelectBasics_EntityOwner)& OwnerId,
const TColgp_Array1OfPnt& Thepolyg3d,
const Standard_Boolean FilledCircle):
Select3D_SensitivePoly(OwnerId, Thepolyg3d),
myFillStatus(FilledCircle),
myDetectedIndex(-1)
{
}
Standard_Boolean Select3D_SensitiveCircle::
Matches(const Standard_Real X,
const Standard_Real Y,
const Standard_Real aTol,
Standard_Real& DMin)
{
// dans le cas Edge (pourtour de la face seulement
//on regarde si le point souris X,Y se trouve a l'interieur du triangle
// pi,pi+1,pi+2 a la tolerance pres... si oui on a fini...
if(mynbpoints>1){
Standard_Boolean Found =Standard_False;
Standard_Integer i = 0;
//gp_Pnt2d p1,p2,p3,pg;
if(!myFillStatus){
while(i < mynbpoints-2 && !Found) {
Standard_Integer TheStat =
Select3D_SensitiveTriangle::Status(((Select3D_Pnt2d*)mypolyg2d)[i],
((Select3D_Pnt2d*)mypolyg2d)[i+1],
((Select3D_Pnt2d*)mypolyg2d)[i+2],
gp_XY(X,Y),aTol,DMin);
Found = (TheStat!=2);
if(Found) myDetectedIndex=i;
i+=2;
}
}
else {
myDetectedIndex =-1;
#ifndef DEB
Standard_Real DMin2 = 0.;
#else
Standard_Real DMin2;
#endif
Standard_Real Xmin,Ymin,Xmax,Ymax;
Bnd_Box2d(mybox2d).Get(Xmin,Ymin,Xmax,Ymax);
if(!Bnd_Box2d(mybox2d).IsVoid())
DMin2 = gp_XY(Xmax-Xmin,Ymax-Ymin).SquareModulus();
TColgp_Array1OfPnt2d aArrayOf2dPnt(1, mynbpoints);
Points2D(aArrayOf2dPnt);
CSLib_Class2d TheInOutTool(aArrayOf2dPnt,aTol,aTol,Xmin,Ymin,Xmax,Ymax);
Standard_Integer TheStat = TheInOutTool.SiDans(gp_Pnt2d(X,Y));
Standard_Real aTol2 = aTol*aTol;
if(TheStat!=1) {
for(Standard_Integer I=0;i<mynbpoints-1;i+=2){
gp_XY V1(((Select3D_Pnt2d*)mypolyg2d)[I+1]),V(X,Y);
V1-=((Select3D_Pnt2d*)mypolyg2d)[I];
V-=((Select3D_Pnt2d*)mypolyg2d)[I];
Standard_Real Vector = V1^V;
Standard_Real V1V1 = V1.SquareModulus();
DMin2 =
(V1V1 <=aTol2) ?
Min(DMin2,V.SquareModulus()): // si le segment est trop petit...
Min(DMin2,Vector*Vector/V1V1);
}
Select3D_SensitiveEntity::Matches(X,Y,aTol,DMin);
return Standard_True;
}
return Standard_False;
}
if(!Found)
myDetectedIndex=-1;
else
Select3D_SensitiveEntity::Matches(X,Y,aTol,DMin);
return Found;
}
return Standard_True;
}
Standard_Boolean Select3D_SensitiveCircle::
Matches(const Standard_Real XMin,
const Standard_Real YMin,
const Standard_Real XMax,
const Standard_Real YMax,
const Standard_Real aTol)
{
myDetectedIndex =-1;
Bnd_Box2d abox;
abox.Update(Min(XMin,XMax),Min(YMin,YMax),Max(XMin,XMax),Max(YMin,YMax));
abox.Enlarge(aTol);
for(Standard_Integer i=0;i<mynbpoints;i++)
if(abox.IsOut(((Select3D_Pnt2d*)mypolyg2d)[i])) return Standard_False;
return Standard_True;
}
//=======================================================================
//function : Matches
//purpose :
//=======================================================================
Standard_Boolean Select3D_SensitiveCircle::
Matches (const TColgp_Array1OfPnt2d& aPoly,
const Bnd_Box2d& aBox,
const Standard_Real aTol)
{
Standard_Real Umin,Vmin,Umax,Vmax;
aBox.Get(Umin,Vmin,Umax,Vmax);
Standard_Real Tolu,Tolv;
Tolu = 1e-7;
Tolv = 1e-7;
CSLib_Class2d aClassifier2d(aPoly,aTol,aTol,Umin,Vmin,Umax,Vmax);
for(Standard_Integer j=1;j<=mynbpoints;j++){
Standard_Integer RES = aClassifier2d.SiDans(((Select3D_Pnt2d*)mypolyg2d)[j-1]);
if(RES!=1) return Standard_False;
}
return Standard_True;
}
void Select3D_SensitiveCircle::
ArrayBounds(Standard_Integer & Low,
Standard_Integer & Up) const
{
Low = 0;
Up = mynbpoints-1;
}
gp_Pnt Select3D_SensitiveCircle::
GetPoint3d(const Standard_Integer Rank) const
{
if(Rank>=0&& Rank<mynbpoints)
return ((Select3D_Pnt*)mypolyg3d)[Rank];
return ((Select3D_Pnt*)mypolyg3d)[0];
}
//=======================================================================
//function : Dump
//purpose :
//=======================================================================
void Select3D_SensitiveCircle::Dump(Standard_OStream& S,const Standard_Boolean FullDump) const
{
// Standard_Integer rank(1);
gp_XYZ CDG(0.,0.,0.);
S<<"\tSensitiveCircle 3D :";
Standard_Boolean isclosed = 1== mynbpoints;
if(isclosed)
S<<"(Closed Circle)"<<endl;
else
S<<"(Arc Of Circle)"<<endl;
if(HasLocation())
S<<"\t\tExisting Location"<<endl;
if(FullDump){
Standard_Integer EndIndex = isclosed? mynbpoints-2 : mynbpoints-1, nbpt(0);
for(Standard_Integer i=0;i<EndIndex;i+=2){
CDG +=((Select3D_Pnt*)mypolyg3d)[i];
nbpt++;
}
CDG/=nbpt;
Standard_Real R = (CDG-((Select3D_Pnt*)mypolyg3d)[0]).Modulus();
S<<"\t\t Center : ("<<CDG.X()<<" , "<<CDG.Y()<<" , "<<CDG.Z()<<" )"<<endl;
S<<"\t\t Radius :"<<R<<endl;
}
}
Standard_Real Select3D_SensitiveCircle::ComputeDepth(const gp_Lin& EyeLine) const
{
gp_Pnt CDG;
if(myDetectedIndex==-1){
gp_XYZ CurCoord(((Select3D_Pnt*)mypolyg3d)[0]);
Standard_Boolean isclosed = 1==mynbpoints;
Standard_Integer EndIndex = isclosed ? mynbpoints-2 : mynbpoints-1, nbpt(0);
for(Standard_Integer i=1;i<EndIndex;i+=2){
CurCoord +=((Select3D_Pnt*)mypolyg3d)[i];
nbpt++;
}
CDG.SetXYZ(CurCoord);
}
else{
gp_XYZ CurCoord(((Select3D_Pnt*)mypolyg3d)[myDetectedIndex]);
CurCoord+=((Select3D_Pnt*)mypolyg3d)[myDetectedIndex+1];
CurCoord+=((Select3D_Pnt*)mypolyg3d)[myDetectedIndex+2];
CDG.SetXYZ(CurCoord);
}
return ElCLib::Parameter(EyeLine,CDG);
}

View File

@@ -0,0 +1,93 @@
-- File: Select3D_SensitiveCurve.cdl
-- Created: Fri Mar 10 16:13:39 1995
-- Author: Mister rmi
-- <rmi@photon>
-- Modified on july 97 by ROB : Field HArray instead Of ArrayOfPnt3D
-- (connected entities)
---Copyright: Matra Datavision 1995
class SensitiveCurve from Select3D
inherits SensitivePoly from Select3D
---Purpose: A framework to define a sensitive 3D curve.
uses
Pnt from gp,
Pnt2d from gp,
Projector from Select3D,
Lin from gp,
EntityOwner from SelectBasics,
ListOfBox2d from SelectBasics,
Curve from Geom,
Array1OfPnt from TColgp,
Array1OfPnt2d from TColgp,
HArray1OfPnt from TColgp,
Box2d from Bnd,
Location from TopLoc
is
Create (OwnerId : EntityOwner from SelectBasics;
TheCurve : Curve from Geom;
MaxPoints : Integer = 17)
returns mutable SensitiveCurve;
---Level: Public
---Purpose: Constructs a sensitive curve object defined by the
-- owner OwnerId, the curve TheCurve, and the
-- maximum number of points on the curve: MaxPoints.
Create (OwnerId : EntityOwner from SelectBasics;
ThePoints : HArray1OfPnt from TColgp)
returns mutable SensitiveCurve;
---Level: Public
---Purpose: Constructs a sensitive curve object defined by the
-- owner OwnerId and the set of points ThePoints.
Create (OwnerId : EntityOwner from SelectBasics;
ThePoints : Array1OfPnt from TColgp)
returns mutable SensitiveCurve;
---Level: Public
---Purpose: Creation of Sensitive Curve from Points.
-- Warning : This Method should disappear in the next version...
Matches(me :mutable;
X,Y : Real from Standard;
aTol: Real from Standard;
DMin: out Real from Standard)
returns Boolean
is redefined static;
Matches (me :mutable;
XMin,YMin,XMax,YMax : Real from Standard;
aTol: Real from Standard)
returns Boolean
is static;
Matches (me :mutable;
Polyline:Array1OfPnt2d from TColgp;
aBox:Box2d from Bnd;
aTol: Real from Standard)
returns Boolean
is redefined virtual;
---Level: Public
ComputeDepth(me;EyeLine: Lin from gp)
returns Real from Standard is redefined static;
GetLastDetected(me) returns Integer from Standard;
---Purpose: Gets index of last detected segment
---C++: inline
---Category: Internal Methods
Dump(me; S: in out OStream;FullDump : Boolean from Standard = Standard_True) is redefined virtual;
LoadPoints(me:mutable;aCurve:Curve from Geom;NbPoints: Integer) is static private;
fields
mylastseg : Integer from Standard;
end SensitiveCurve;

View File

@@ -0,0 +1,179 @@
// Copyright: Matra-Datavision 1995
// File: Select3D_SensitiveCurve.cxx
// Created: Mon Mar 13 09:57:58 1995
// Author: Robert COUBLANC
// <rob>
#include <Select3D_SensitiveCurve.ixx>
#include <SelectBasics_BasicTool.hxx>
#include <gp_Lin2d.hxx>
#include <Precision.hxx>
#include <ElCLib.hxx>
#include <CSLib_Class2d.hxx>
//==================================================
// Function:
// Purpose :
//==================================================
Select3D_SensitiveCurve
::Select3D_SensitiveCurve(const Handle(SelectBasics_EntityOwner)& OwnerId,
const Handle(Geom_Curve)& C,
const Standard_Integer NbPoints):
Select3D_SensitivePoly(OwnerId, NbPoints),
mylastseg(0)
{
LoadPoints(C,NbPoints);
}
//==================================================
// Function: Creation
// Purpose :
//==================================================
Select3D_SensitiveCurve
::Select3D_SensitiveCurve(const Handle(SelectBasics_EntityOwner)& OwnerId,
const Handle(TColgp_HArray1OfPnt)& ThePoints):
Select3D_SensitivePoly(OwnerId, ThePoints),
mylastseg(0)
{
}
//==================================================
// Function: Creation
// Purpose :
//==================================================
Select3D_SensitiveCurve
::Select3D_SensitiveCurve(const Handle(SelectBasics_EntityOwner)& OwnerId,
const TColgp_Array1OfPnt& ThePoints):
Select3D_SensitivePoly(OwnerId, ThePoints),
mylastseg(0)
{
}
//==================================================
// Function: Matches
// Purpose :
//==================================================
Standard_Boolean Select3D_SensitiveCurve
::Matches(const Standard_Real X,
const Standard_Real Y,
const Standard_Real aTol,
Standard_Real& DMin)
{
Standard_Integer Rank;
TColgp_Array1OfPnt2d aArrayOf2dPnt(1, mynbpoints);
Points2D(aArrayOf2dPnt);
Standard_Boolean KK = SelectBasics_BasicTool::MatchPolyg2d(aArrayOf2dPnt,
X,Y,
aTol,
DMin,
Rank);
if(KK){
Select3D_SensitiveEntity::Matches(X,Y,aTol,DMin);
mylastseg = Rank;
}
return KK;
}
//==================================================
// Function: Matches
// Purpose : know if a box touches the projected polygon
// of the Curve.
//==================================================
Standard_Boolean Select3D_SensitiveCurve::
Matches (const Standard_Real XMin,
const Standard_Real YMin,
const Standard_Real XMax,
const Standard_Real YMax,
const Standard_Real aTol)
{
Bnd_Box2d BoundBox;
BoundBox.Update(XMin-aTol,YMin-aTol,XMax+aTol,YMax+aTol);
for(Standard_Integer j=0; j<mynbpoints-1; j++)
{
if(BoundBox.IsOut(((Select3D_Pnt2d*)mypolyg2d)[j])) return Standard_False;
}
return Standard_True;
}
//=======================================================================
//function : Matches
//purpose :
//=======================================================================
Standard_Boolean Select3D_SensitiveCurve::
Matches (const TColgp_Array1OfPnt2d& aPoly,
const Bnd_Box2d& aBox,
const Standard_Real aTol)
{
Standard_Real Umin,Vmin,Umax,Vmax;
aBox.Get(Umin,Vmin,Umax,Vmax);
Standard_Real Tolu,Tolv;
Tolu = 1e-7;
Tolv = 1e-7;
CSLib_Class2d aClassifier2d(aPoly,aTol,aTol,Umin,Vmin,Umax,Vmax);
for(Standard_Integer j=0;j<mynbpoints;j++){
Standard_Integer RES = aClassifier2d.SiDans(((Select3D_Pnt2d*)mypolyg2d)[j]);
if(RES!=1) return Standard_False;
}
return Standard_True;
}
//==================================================
// Function:
// Purpose :
//==================================================
void Select3D_SensitiveCurve
::LoadPoints (const Handle(Geom_Curve)& aCurve,const Standard_Integer NbP)
{
/*this method is private and it used only inside of constructor.
That's why check !NbP==mypolyg3d->Length() was removed*/
Standard_Real Step = (aCurve->LastParameter()- aCurve->FirstParameter())/(NbP-1);
Standard_Real Curparam = aCurve->FirstParameter();
for(Standard_Integer i=0;i<mynbpoints;i++)
{
((Select3D_Pnt*)mypolyg3d)[i] = aCurve->Value(Curparam);
Curparam+=Step;
}
}
//=======================================================================
//function : Dump
//purpose :
//=======================================================================
void Select3D_SensitiveCurve::Dump(Standard_OStream& S,const Standard_Boolean FullDump) const
{
S<<"\tSensitiveCurve 3D :"<<endl;
if(HasLocation())
S<<"\t\tExisting Location"<<endl;
S<<"\t\tNumber Of Points :"<<mynbpoints<<endl;
if(FullDump){
// S<<"\t\t\tOwner:"<<myOwnerId<<endl;
Select3D_SensitiveEntity::DumpBox(S,mybox2d);
}
}
//=======================================================================
//function : ComputeDepth
//purpose :
//=======================================================================
Standard_Real Select3D_SensitiveCurve::ComputeDepth(const gp_Lin& EyeLine) const
{
if(mylastseg==0) return Precision::Infinite(); // non implemente actuellement...
gp_XYZ TheCDG(((Select3D_Pnt*)mypolyg3d)[mylastseg]);
TheCDG+=((Select3D_Pnt*)mypolyg3d)[mylastseg+1];
TheCDG/=2.;
return ElCLib::Parameter(EyeLine,gp_Pnt(TheCDG));
}

View File

@@ -0,0 +1,3 @@
inline Standard_Integer Select3D_SensitiveCurve::GetLastDetected() const
{return mylastseg;}

View File

@@ -0,0 +1,157 @@
-- File: Select3D_SensitiveEntity.cdl
-- Created: Tue Jan 24 09:30:34 1995
-- Author: Rob
-- modified by rob jul/ 21/ 97 : inserting locations ...
-- modified by rob jan/ 29/ 98 : Sort by deph-> add a field to be able
-- to compute a depth
-- -> Virtual methods rather than
-- Deferred for Project
-- WARNING : Must be redefined for
-- each kind of sensitive entity
--
---Copyright: Matra Datavision 1995
deferred class SensitiveEntity from Select3D inherits
SensitiveEntity from SelectBasics
---Purpose: Abstract framework to define 3D sensitive entities.
-- As the selection process uses the principle of a
-- projection of 3D shapes onto a 2D view where
-- nearness to a rectangle determines whether a shape
-- is picked or not, all 3D shapes need to be converted
-- into 2D ones in order to be selected.
uses
Projector from Select3D,
EntityOwner from SelectBasics,
Location from TopLoc,
Lin from gp,
Box2d from Bnd,
Array1OfPnt2d from TColgp
is
Initialize(OwnerId : EntityOwner from SelectBasics);
NeedsConversion(me) returns Boolean is redefined static;
---Level: Public
---Purpose: Returns true if this framework needs conversion.
---C++: inline
Is3D(me) returns Boolean from Standard is redefined static;
---Purpose: Returns true if this framework provides 3D information.
Project (me:mutable;aProjector : Projector from Select3D) is virtual;
---Level: Public
---Purpose:Returns the projector aProjector.
-- In classes inheriting this framework, you must
-- redefine this function in order to get a sensitive 2D
-- rectangle from a 3D entity. This rectangle is the
-- sensitive zone which makes the 3D entity selectable.
MaxBoxes(me) returns Integer is redefined virtual;
---Level: Public
---Purpose: Returns the max number of sensitive areas returned
-- by this class is 1 by default.
-- Else on must redefine this method.
GetConnected(me:mutable;aLocation: Location from TopLoc)
returns SensitiveEntity from Select3D is virtual;
---Purpose: Returns the sensitive entity found at the location aLocation.
-- You must redefine this function for any type of
-- sensitive entity which can accept another connected
-- sensitive entity.//can be connected to another sensitive entity.
Matches(me :mutable;
X,Y : Real from Standard;
aTol: Real from Standard;
DMin: out Real from Standard)
returns Boolean is redefined virtual;
---Purpose: Matches the coordinates X, Y with the entity found at
-- that point within the tolerance aTol and the minimum depth DMin.
-- You must redefine this function for every inheriting entity.
-- You will have to call this framework inside the redefined function.
Matches (me :mutable;
XMin,YMin,XMax,YMax : Real from Standard;
aTol: Real from Standard)
returns Boolean from Standard is redefined virtual;
---Purpose: Matches the box defined by the coordinates Xmin,
-- Ymin, Xmax, Ymax with the entity found at that point
-- within the tolerance aTol.
-- Xmin, YMin define the minimum point in the lower left
-- hand corner of the box, and XMax, YMax define the
-- maximum point in the upper right hand corner of the box.
-- You must redefine this function for every inheriting entity.
-- You will have to call this framework inside the redefined function.
Matches (me :mutable;
Polyline:Array1OfPnt2d from TColgp;
aBox:Box2d from Bnd;
aTol: Real from Standard)
returns Boolean from Standard is redefined virtual;
---Purpose: prevents from hiding virtual methods...
GetEyeLine(me; X,Y : Real from Standard) returns Lin from gp;
---Purpose: Returns the eye line for the point defined by the coordinates X,Y.
ComputeDepth(me;EyeLine : Lin from gp) returns Real from Standard
is deferred;
---Purpose: Returns the depth of this object on the line EyeLine.
-- EyeLine goes through the eye towards a point
-- defined by the coordinates X,Y in the function GetEyeLine.
---Purpose: gives an abcissa on <aLin> .
-- <aLin> represents the line going through
-- the eye towards an X,Y point on the screen. This Method
-- must return a mean Depth on this line.
Depth(me) returns Real from Standard is redefined;
---Category: Location of sensitive entities...
-- Default implementations of HasLocation() and Location() rely on
-- location obtained from the entity owner, to minimize memory usage.
-- SetLocation() and ResetLocation() do nothing by default.
HasLocation(me) returns Boolean from Standard is virtual;
---Purpose: Returns true if this framework has a location defined.
Location(me) returns Location from TopLoc is virtual;
---C++: return const&
ResetLocation(me:mutable) is virtual;
---Purpose: sets the location to Identity
SetLocation(me:mutable;aLoc :Location from TopLoc) is virtual;
Dump(me; S: in out OStream;FullDump : Boolean from Standard = Standard_True) is virtual;
---Purpose: 2 options :
-- <FullDump> = False -> general information
-- <FullDump> = True -> whole informtion 3D +2d ...
DumpBox(myclass; S: in out OStream;abox:Box2d from Bnd) ;
UpdateLocation(me:mutable;aLoc:Location from TopLoc);
SetLastPrj(me:mutable;aPrj:Projector from Select3D) is virtual;
SetLastDepth(me:mutable; aDepth: Real from Standard) is protected;
fields
mylastprj : Address from Standard is protected;
mylastdepth : ShortReal from Standard;
end SensitiveEntity;

View File

@@ -0,0 +1,227 @@
// Copyright: Matra-Datavision 1995
// File: Select3D_SensitiveEntity.cxx
// Created: Mon Mar 13 17:55:29 1995
// Author: Robert COUBLANC
// <rob>
#include <Select3D_SensitiveEntity.ixx>
#include <Precision.hxx>
#include <SelectBasics_EntityOwner.hxx>
#include <Select3D_Macro.hxx>
//=======================================================================
//function : Select3D_SensitiveEntity
//purpose :
//=======================================================================
Select3D_SensitiveEntity::Select3D_SensitiveEntity(const Handle(SelectBasics_EntityOwner)& OwnerId):
SelectBasics_SensitiveEntity(OwnerId),
mylastprj(NULL),
mylastdepth(0.0)
{}
//=======================================================================
//function : Project
//purpose :
//=======================================================================
void Select3D_SensitiveEntity::Project(const Select3D_Projector& aPrj)
{
mylastprj = (Standard_Address*)&aPrj;
}
//=======================================================================
//function : Matches
//purpose :
//=======================================================================
Standard_Boolean Select3D_SensitiveEntity::Matches(const Standard_Real X,
const Standard_Real Y,
const Standard_Real aTol,
Standard_Real& DMin)
{
gp_Lin L;
if(mylastprj!=NULL)
L = (* ((Select3D_Projector*) mylastprj)).Shoot(X,Y);
SetLastDepth( ComputeDepth(L) );
return (Abs(mylastdepth)>Precision::Confusion());
}
//=======================================================================
//function : Matches
//purpose :
//=======================================================================
Standard_Boolean Select3D_SensitiveEntity::Matches(const Standard_Real XMin,
const Standard_Real YMin,
const Standard_Real XMax,
const Standard_Real YMax,
const Standard_Real aTol)
{
return Standard_False;
}
//=======================================================================
//function : Matches
//purpose :
//=======================================================================
Standard_Boolean Select3D_SensitiveEntity::Matches(const TColgp_Array1OfPnt2d& aPoly,
const Bnd_Box2d& aBox,
const Standard_Real aTol)
{
return Standard_False;
}
//=======================================================================
//function : Dump
//purpose :
//=======================================================================
void Select3D_SensitiveEntity::Dump(Standard_OStream& S,const Standard_Boolean FullDump) const
{
S<<"\tSensitive Entity 3D"<<endl;
}
//=======================================================================
//function : DumpBox
//purpose :
//=======================================================================
void Select3D_SensitiveEntity::DumpBox(Standard_OStream& S,const Bnd_Box2d& b2d)
{
if(!b2d.IsVoid()){
Standard_Real xmin,ymin,xmax,ymax;
b2d.Get(xmin,ymin,xmax,ymax);
S<<"\t\t\tBox2d: PMIN ["<<xmin<<" , "<<ymin<<"]"<<endl;
S<<"\t\t\t PMAX ["<<xmax<<" , "<<ymax<<"]"<<endl;
}
}
//=======================================================================
//function : ResetLocation
//purpose :
//=======================================================================
void Select3D_SensitiveEntity::ResetLocation()
{
}
//=======================================================================
//function : SetLocation
//purpose :
//=======================================================================
void Select3D_SensitiveEntity::SetLocation(const TopLoc_Location&)
{
}
//=======================================================================
//function : UpdateLocation
//purpose :
//=======================================================================
void Select3D_SensitiveEntity::UpdateLocation(const TopLoc_Location& aLoc)
{
if(aLoc.IsIdentity() || aLoc == Location()) return;
if(!HasLocation())
SetLocation(aLoc);
else {
TopLoc_Location compLoc = aLoc * Location();
SetLocation(compLoc);}
}
//=======================================================================
//function : Location
//purpose :
//=======================================================================
const TopLoc_Location& Select3D_SensitiveEntity::Location() const
{
static TopLoc_Location anIdentity;
Handle(SelectBasics_EntityOwner) anOwner = OwnerId();
return anOwner.IsNull() ? anIdentity : anOwner->Location();
}
//=======================================================================
//function : HasLocation
//purpose :
//=======================================================================
Standard_Boolean Select3D_SensitiveEntity::HasLocation() const
{
Handle(SelectBasics_EntityOwner) anOwner = OwnerId();
return (!anOwner.IsNull() && anOwner->HasLocation());
}
//=======================================================================
//function : Is3D
//purpose :
//=======================================================================
Standard_Boolean Select3D_SensitiveEntity::Is3D() const
{return Standard_True;}
//=======================================================================
//function : Depth
//purpose :
//=======================================================================
Standard_Real Select3D_SensitiveEntity::Depth() const
{return mylastdepth;}
//=======================================================================
//function : GetEyeLine
//purpose :
//=======================================================================
gp_Lin Select3D_SensitiveEntity::GetEyeLine(const Standard_Real X,
const Standard_Real Y) const
{
gp_Lin L;
if(mylastprj!=NULL)
L = (* ((Select3D_Projector*) mylastprj)).Shoot(X,Y);
return L;
}
//=======================================================================
//function : MaxBoxes
//purpose :
//=======================================================================
Standard_Integer Select3D_SensitiveEntity::MaxBoxes() const
{return 1;}
//=======================================================================
//function : SetLastPrj
//purpose :
//=======================================================================
void Select3D_SensitiveEntity::SetLastPrj(const Select3D_Projector& aprj)
{ mylastprj = (Standard_Address*)& aprj;}
//=======================================================================
//function : GetConnected
//purpose :
//=======================================================================
Handle(Select3D_SensitiveEntity) Select3D_SensitiveEntity::GetConnected(const TopLoc_Location&)
{
Handle(Select3D_SensitiveEntity) NiouEnt;
return NiouEnt;
}
//=======================================================================
//function : GetConnected
//purpose :
//=======================================================================
void Select3D_SensitiveEntity::SetLastDepth(const Standard_Real aDepth)
{
mylastdepth = DToF(aDepth);
}

View File

@@ -0,0 +1,5 @@
inline Standard_Boolean Select3D_SensitiveEntity::NeedsConversion() const
{return Standard_True;}

View File

@@ -0,0 +1,87 @@
-- File: Select3D_SensitiveFace.cdl
-- Created: Fri Mar 24 16:01:23 1995
-- Author: Robert COUBLANC
-- <rob@fidox>
---Copyright: Matra Datavision 1995
class SensitiveFace from Select3D
inherits SensitivePoly from Select3D
---Purpose: Sensitive Entity to make a face selectable.
uses
EntityOwner from SelectBasics,
Projector from Select3D,
Lin from gp,
ListOfBox2d from SelectBasics,
Array1OfPnt from TColgp,
HArray1OfPnt from TColgp,
Array1OfPnt2d from TColgp,
Box2d from Bnd,
TypeOfSensitivity from Select3D,
Location from TopLoc
is
Create (OwnerId : EntityOwner from SelectBasics;
ThePoints : Array1OfPnt from TColgp;
Sensitivity : TypeOfSensitivity = Select3D_TOS_INTERIOR)
returns mutable SensitiveFace;
---Level: Public
---Purpose: Constructs a sensitive face object defined by the
-- owner OwnerId, the array of points ThePoints, and
-- the sensitivity type Sensitivity.
-- The array of points is the outer polygon of the geometric face.
Create (OwnerId : EntityOwner from SelectBasics;
ThePoints : HArray1OfPnt from TColgp;
Sensitivity : TypeOfSensitivity = Select3D_TOS_INTERIOR)
returns mutable SensitiveFace;
---Level: Public
---Purpose: Constructs a sensitive face object defined by the
-- owner OwnerId, the array of points ThePoints, and
-- the sensitivity type Sensitivity.
-- The array of points is the outer polygon of the geometric face.
Matches(me :mutable;
X,Y : Real from Standard;
aTol: Real from Standard;
DMin: out Real from Standard)
returns Boolean
is redefined virtual;
Matches (me :mutable;
XMin,YMin,XMax,YMax : Real from Standard;
aTol: Real from Standard)
returns Boolean
is redefined virtual;
---Level: Public
Matches (me :mutable;
Polyline:Array1OfPnt2d from TColgp;
aBox:Box2d from Bnd;
aTol: Real from Standard)
returns Boolean
is redefined virtual;
---Level: Public
ComputeDepth(me;EyeLine: Lin from gp)
returns Real from Standard is redefined virtual;
---Level: Public
---Purpose: Computes the depth values for all 3D points defining this face and returns
-- the minimal value among them.
-- If the "minimal depth" approach is not suitable and gives wrong detection results
-- in some particular case, a custom sensitive face class can be implemented at application level
-- that overrides default ComputeDepth() behavior.
Dump(me; S: in out OStream;FullDump : Boolean from Standard = Standard_True) is redefined virtual;
fields
mytype : TypeOfSensitivity;
myautointer : Boolean;
myDetectedIndex : Integer from Standard;
end SensitiveFace;

View File

@@ -0,0 +1,237 @@
// Copyright: Matra-Datavision 1995
// File: Select3D_SensitiveFace.cxx
// Created: Mon Mar 27 10:15:15 1995
// Author: Robert COUBLANC
// <rob>
//Modif on jun-24-97 : introduction de CSLib_Class2d de LBR
// pour teste si on est dedans ou dehors...
//Modif on jul-21-97 : changement en harray1 pour eventuelles connexions ...
#include <Select3D_SensitiveFace.ixx>
#include <SelectBasics_BasicTool.hxx>
#include <gp_Pnt2d.hxx>
#include <gp_Pnt.hxx>
#include <Precision.hxx>
#include <ElCLib.hxx>
#include <CSLib_Class2d.hxx>
#define AutoInterMask 0x01
#define AutoComputeMask 0x02
// Standard_True if the flag is one
#define AutoInterFlag(aflag) ( aflag & AutoInterMask )
#define AutoComputeFlag(aflag) ( aflag & AutoComputeMask )
// set the flag to one
#define SetAutoInterFlag(aflag) ( aflag = aflag & AutoInterMask)
#define SetAutoComputeFlag(aflag) ( aflag = aflag & AutoComputeMask)
// Initialize flags
#define AutoInitFlags(aflag) (aflag = 0)
//==================================================
// Function: faire disparaitre ce constructeur a la prochaine version...
// Purpose : simplement garde pour ne pas perturber la version update
//==================================================
Select3D_SensitiveFace::
Select3D_SensitiveFace(const Handle(SelectBasics_EntityOwner)& OwnerId,
const TColgp_Array1OfPnt& ThePoints,
const Select3D_TypeOfSensitivity aType):
Select3D_SensitivePoly(OwnerId, ThePoints),
mytype (aType),
myDetectedIndex(-1)
{
AutoInitFlags(myautointer);
}
//==================================================
// Function:
// Purpose :
//==================================================
Select3D_SensitiveFace::
Select3D_SensitiveFace(const Handle(SelectBasics_EntityOwner)& OwnerId,
const Handle(TColgp_HArray1OfPnt)& ThePoints,
const Select3D_TypeOfSensitivity aType):
Select3D_SensitivePoly(OwnerId, ThePoints),
mytype (aType),
myDetectedIndex(-1)
{
AutoInitFlags(myautointer);
}
//==================================================
// Function:
// Purpose :
//==================================================
Standard_Boolean Select3D_SensitiveFace::
Matches(const Standard_Real X,
const Standard_Real Y,
const Standard_Real aTol,
Standard_Real& DMin)
{
#ifndef DEB
Standard_Real DMin2 = 0.;
#else
Standard_Real DMin2;
#endif
Standard_Real Xmin,Ymin,Xmax,Ymax;
if(!Bnd_Box2d(mybox2d).IsVoid()){
Bnd_Box2d(mybox2d).Get(Xmin,Ymin,Xmax,Ymax);
DMin2 = gp_XY(Xmax-Xmin,Ymax-Ymin).SquareModulus();
}
// calcul d'un critere de distance mini...
// au depart Dmin = taille de la boite englobante 2D,
// ensuite distance mini du polyedre ou du cdg...
Standard_Real aTol2 = aTol*aTol;
gp_XY CDG(0.,0.);
// for(Standard_Integer I=1;I<=Nbp-1;I++){
Standard_Integer I;
for(I=1;I<mynbpoints-1;I++){
CDG+=((Select3D_Pnt2d*)mypolyg2d)[I-1];
}
if(mynbpoints>1){
CDG/= (mynbpoints-1);
}
DMin2=Min(DMin2,gp_XY(CDG.X()-X,CDG.Y()-Y).SquareModulus());
DMin = Sqrt(DMin2);
Standard_Boolean isplane2d(Standard_True);
for( I=1;I<mynbpoints-1;I++){
gp_XY V1(((Select3D_Pnt2d*)mypolyg2d)[I]),V(X,Y);
V1-=((Select3D_Pnt2d*)mypolyg2d)[I-1];
V-=((Select3D_Pnt2d*)mypolyg2d)[I-1];
Standard_Real Vector = V1^V;
Standard_Real V1V1 = V1.SquareModulus();
DMin2 =
(V1V1 <=aTol2) ?
Min(DMin2,V.SquareModulus()): // si le segment est trop petit...
Min(DMin2,Vector*Vector/V1V1);
//cdg ...
gp_XY PlaneTest(CDG);PlaneTest-=((Select3D_Pnt2d*)mypolyg2d)[I-1];
Standard_Real valtst = PlaneTest^V1;
if(isplane2d && Abs(valtst)>aTol) isplane2d=Standard_False;
}
if(isplane2d) {
Select3D_SensitiveEntity::Matches(X,Y,aTol,DMin);
return Standard_True;
}
//detection d'une auto - intersection dans le polygon 2D; si oui on sort
// if (!AutoComputeFlag(myautointer)) {
// if(mypolyg2d.Length()>4) {
// if (SelectBasics_BasicTool::AutoInter(mypolyg2d)) {
// SetAutoInterFlag(myautointer);
// }
// }
// SetAutoComputeFlag(myautointer);
// }
// if (AutoInterFlag(myautointer)) return Standard_True;
// //
//sinon on regarde si le point est dans la face...
TColgp_Array1OfPnt2d aArrayOf2dPnt(1, mynbpoints);
Points2D(aArrayOf2dPnt);
CSLib_Class2d TheInOutTool(aArrayOf2dPnt,aTol,aTol,Xmin,Ymin,Xmax,Ymax);
Standard_Integer TheStat = TheInOutTool.SiDans(gp_Pnt2d(X,Y));
Standard_Boolean res(Standard_False);
switch(TheStat){
case 0:
res = Standard_True;
case 1:
{
if(mytype!=Select3D_TOS_BOUNDARY)
res = Standard_True;
}
}
if(res)
Select3D_SensitiveEntity::Matches(X,Y,aTol,DMin);
return res;
}
//=======================================================================
//function : Matches
//purpose :
//=======================================================================
Standard_Boolean Select3D_SensitiveFace::
Matches (const Standard_Real XMin,
const Standard_Real YMin,
const Standard_Real XMax,
const Standard_Real YMax,
const Standard_Real aTol)
{
Bnd_Box2d BoundBox;
BoundBox.Update(XMin-aTol,YMin-aTol,XMax+aTol,YMax+aTol);
for(Standard_Integer j=1;j<=mynbpoints-1;j++){
if(BoundBox.IsOut(((Select3D_Pnt2d*)mypolyg2d)[j-1])) return Standard_False;
}
return Standard_True;
}
//=======================================================================
//function : Matches
//purpose :
//=======================================================================
Standard_Boolean Select3D_SensitiveFace::
Matches (const TColgp_Array1OfPnt2d& aPoly,
const Bnd_Box2d& aBox,
const Standard_Real aTol)
{
Standard_Real Umin,Vmin,Umax,Vmax;
aBox.Get(Umin,Vmin,Umax,Vmax);
Standard_Real Tolu,Tolv;
Tolu = 1e-7;
Tolv = 1e-7;
CSLib_Class2d aClassifier2d(aPoly,aTol,aTol,Umin,Vmin,Umax,Vmax);
for(Standard_Integer j=1;j<=mynbpoints;j++){
Standard_Integer RES = aClassifier2d.SiDans(((Select3D_Pnt2d*)mypolyg2d)[j-1]);
if(RES!=1) return Standard_False;
}
return Standard_True;
}
//=======================================================================
//function : Dump
//purpose :
//=======================================================================
void Select3D_SensitiveFace::Dump(Standard_OStream& S,const Standard_Boolean FullDump) const
{
S<<"\tSensitiveFace 3D :"<<endl;;
if(HasLocation())
S<<"\t\tExisting Location"<<endl;
if(mytype==Select3D_TOS_BOUNDARY)
S<<"\t\tSelection Of Bounding Polyline Only"<<endl;
if(FullDump){
S<<"\t\tNumber Of Points :"<<mynbpoints<<endl;
// S<<"\t\t\tOwner:"<<myOwnerId<<endl;
Select3D_SensitiveEntity::DumpBox(S,mybox2d);
}
}
//=======================================================================
//function : ComputeDepth
//purpose :
//=======================================================================
Standard_Real Select3D_SensitiveFace::ComputeDepth(const gp_Lin& EyeLine) const
{
Standard_Real val(Precision::Infinite());
for(Standard_Integer i=0;i<mynbpoints-1;i++)
val = Min(val,ElCLib::Parameter(EyeLine,((Select3D_Pnt*)mypolyg3d)[i]));
return val;
}

View File

@@ -0,0 +1,149 @@
-- File: Select3D_SensitiveGroup.cdl
-- Created: Thu Apr 16 14:57:09 1998
-- Author: Robert COUBLANC
-- <rob@robox.paris1.matra-dtv.fr>
---Copyright: Matra Datavision 1998
class SensitiveGroup from Select3D inherits SensitiveEntity from Select3D
---Purpose: A framework to define selection of a sensitive group
-- by a sensitive entity which is a set of 3D sensitive entities.
-- Remark: 2 modes are possible for rectangle selection
-- the group is considered selected
-- 1) when all the entities inside are selected in the rectangle
-- 2) only one entity inside is selected by the rectangle
-- By default the "Match All entities" mode is set.
uses
Pnt from gp,
Projector from Select3D,
Lin from gp,
EntityOwner from SelectBasics,
SensitiveEntity from Select3D,
ListOfSensitive from Select3D,
ListOfBox2d from SelectBasics,
Array1OfPnt2d from TColgp,
Box2d from Bnd,
Location from TopLoc
is
Create (OwnerId : EntityOwner from SelectBasics;
MatchAll : Boolean from Standard = Standard_True)
returns mutable SensitiveGroup from Select3D;
---Purpose: Constructs an empty sensitive group object.
-- This is a set of sensitive 3D entities. The sensitive
-- entities will be defined using the function Add to fill
-- the entity owner OwnerId. If MatchAll is false, nothing can be added.
Create(OwnerId : EntityOwner from SelectBasics;
TheList : in out ListOfSensitive from Select3D;
MatchAll : Boolean from Standard = Standard_True)
returns mutable SensitiveGroup from Select3D;
---Purpose: Constructs a sensitive group object defined by the list
-- TheList and the entity owner OwnerId. If MatchAll is false, nothing is done.
Add (me :mutable; LL: in out ListOfSensitive from Select3D);
---Purpose: Adds the list of sensitive entities LL to the empty
-- sensitive group object created at construction time.
Add (me :mutable;aSensitive : SensitiveEntity from Select3D);
---Purpose: Adds the sensitive entity aSensitive to the non-empty
-- sensitive group object created at construction time.
Remove(me:mutable; aSensitive :SensitiveEntity from Select3D);
Clear(me:mutable) ;
---Purpose: Removes all sensitive entities from the list used at the
-- time of construction, or added using the function Add.
IsIn(me;aSensitive: SensitiveEntity from Select3D)
returns Boolean from Standard;
---Purpose: Returns true if the sensitive entity aSensitive is in
-- the list used at the time of construction, or added using the function Add.
Set(me:mutable; MustMatchAllEntities: Boolean from Standard);
---Purpose: Sets the requirement that all sensitive entities in the
-- list used at the time of construction, or added using
-- the function Add must be matched.
---C++: inline
MustMatchAll(me) returns Boolean from Standard;
---Purpose: Returns true if all sensitive entities in the list used
-- at the time of construction, or added using the function Add must be matched.
---C++: inline
Project (me:mutable;aProjector : Projector from Select3D)
is redefined static;
---Level: Public
---Purpose: projection of the sensitive primitive in order to
-- get 2D boxes for the Sort Algorithm
Areas (me:mutable ; boxes : in out ListOfBox2d from SelectBasics)
is redefined static;
---Level: Public
---Purpose: gives the 2D boxes which represent the segment in the
-- selection process...
MaxBoxes(me) returns Integer from Standard is redefined static;
GetConnected(me:mutable;aLocation: Location from TopLoc)
returns SensitiveEntity from Select3D is redefined static;
SetLocation(me:mutable;aLoc:Location from TopLoc) is redefined static;
---Purpose: propagation of location on all the sensitive inside...
ResetLocation(me:mutable) is redefined static;
---Purpose: propagation of location on all the sensitive inside...
Matches(me :mutable;
X,Y : Real from Standard;
aTol: Real from Standard;
DMin: out Real from Standard)
returns Boolean
is redefined static;
---Level: Public
---Purpose: projection of the sensitive primitive in order to
-- get 2D boxes for the Sort Algorithm
Matches (me :mutable;
XMin,YMin,XMax,YMax : Real from Standard;
aTol: Real from Standard)
returns Boolean
is static;
Matches (me :mutable;
Polyline:Array1OfPnt2d from TColgp;
aBox:Box2d from Bnd;
aTol: Real from Standard)
returns Boolean
is redefined virtual;
---Level: Public
ComputeDepth(me;EyeLine: Lin from gp)
returns Real from Standard is redefined static;
---Purpose: returns the depth of the touched entity
SetLastPrj(me:mutable;aPrj:Projector from Select3D) is redefined virtual;
GetEntities(me)
returns ListOfSensitive from Select3D;
---Purpose: Gets group content
---C++: inline
---C++: return const&
fields
myList : ListOfSensitive from Select3D;
myMustMatchAll : Boolean from Standard;
myLastRank : Integer from Standard;
myLastTol : ShortReal from Standard;
myX,myY : ShortReal from Standard;
end SensitiveGroup;

View File

@@ -0,0 +1,295 @@
// File: Select3D_SensitiveGroup.cxx
// Created: Thu Apr 16 16:17:00 1998
// Author: Robert COUBLANC
// <rob@robox.paris1.matra-dtv.fr>
#include <Select3D_SensitiveGroup.ixx>
#include <Select3D_ListIteratorOfListOfSensitive.hxx>
#include <Precision.hxx>
Select3D_SensitiveGroup::Select3D_SensitiveGroup(const Handle(SelectBasics_EntityOwner)& OwnerId,
const Standard_Boolean MatchAll):
Select3D_SensitiveEntity(OwnerId),
myMustMatchAll(MatchAll),
myLastRank(0),
myX(0.),
myY(0.)
{
}
Select3D_SensitiveGroup::Select3D_SensitiveGroup(const Handle(SelectBasics_EntityOwner)& OwnerId,
Select3D_ListOfSensitive& TheList,
const Standard_Boolean MatchAll):
Select3D_SensitiveEntity(OwnerId),
myMustMatchAll(MatchAll),
myLastRank(0),
myX(0.),
myY(0.)
{
myList.Append(TheList);
}
//=======================================================================
//function : Add
//purpose : No control of entities inside
//=======================================================================
void Select3D_SensitiveGroup::Add(Select3D_ListOfSensitive& LL)
{myList.Append(LL);}
//=======================================================================
//function : Add
//purpose :
//=======================================================================
void Select3D_SensitiveGroup::Add(const Handle(Select3D_SensitiveEntity)& aSensitive)
{
for(Select3D_ListIteratorOfListOfSensitive It(myList);It.More();It.Next()){
if(It.Value()==aSensitive) return;
}
myList.Append(aSensitive);
}
//=======================================================================
//function : Remove
//purpose :
//=======================================================================
void Select3D_SensitiveGroup::Remove(const Handle(Select3D_SensitiveEntity)& aSensitive)
{
for(Select3D_ListIteratorOfListOfSensitive It(myList);It.More();It.Next()){
if(It.Value()==aSensitive){
myList.Remove(It);
return;
}
}
}
//=======================================================================
//function : IsIn
//purpose :
//=======================================================================
Standard_Boolean Select3D_SensitiveGroup::IsIn(const Handle(Select3D_SensitiveEntity)& aSensitive) const
{
for(Select3D_ListIteratorOfListOfSensitive It(myList);It.More();It.Next()){
if(It.Value()==aSensitive)
return Standard_True;
}
return Standard_False;
}
//=======================================================================
//function : Clear
//purpose :
//=======================================================================
void Select3D_SensitiveGroup::Clear()
{myList.Clear();}
//=======================================================================
//function : Project
//purpose :
//=======================================================================
void Select3D_SensitiveGroup::Project(const Select3D_Projector& aProjector)
{
Select3D_SensitiveEntity::Project(aProjector); // to set the field last proj...
for(Select3D_ListIteratorOfListOfSensitive It(myList);It.More();It.Next()){
It.Value()->Project(aProjector);
}
}
//=======================================================================
//function : Areas
//purpose :
//=======================================================================
void Select3D_SensitiveGroup::Areas(SelectBasics_ListOfBox2d& boxes)
{
for(Select3D_ListIteratorOfListOfSensitive It(myList);It.More();It.Next()){
It.Value()->Areas(boxes);
}
}
//=======================================================================
//function : GetConnected
//purpose :
//=======================================================================
Handle(Select3D_SensitiveEntity) Select3D_SensitiveGroup::GetConnected(const TopLoc_Location& aLocation)
{
Handle(Select3D_SensitiveGroup) newgroup = new Select3D_SensitiveGroup(myOwnerId,myMustMatchAll);
Select3D_ListOfSensitive LL;
for(Select3D_ListIteratorOfListOfSensitive It(myList);It.More();It.Next()){
LL.Append(It.Value()->GetConnected(aLocation));
}
newgroup->Add(LL);
return newgroup;
}
//=======================================================================
//function : SetLocation
//purpose :
//=======================================================================
void Select3D_SensitiveGroup::SetLocation(const TopLoc_Location& aLoc)
{
if(aLoc.IsIdentity()) return;
if(HasLocation())
if(aLoc == Location()) return;
Select3D_SensitiveEntity::SetLocation(aLoc);
for(Select3D_ListIteratorOfListOfSensitive It(myList);It.More();It.Next()){
if(It.Value()->HasLocation()){
if(It.Value()->Location()!=aLoc)
It.Value()->SetLocation(It.Value()->Location()*aLoc);
}
else
It.Value()->SetLocation(aLoc);
}
}
//=======================================================================
//function : ResetLocation
//purpose :
//=======================================================================
void Select3D_SensitiveGroup::ResetLocation()
{
if(!HasLocation()) return;
for(Select3D_ListIteratorOfListOfSensitive It(myList);It.More();It.Next()){
if(It.Value()->HasLocation() && It.Value()->Location()!=Location())
It.Value()->SetLocation(It.Value()->Location()*Location().Inverted());
else
It.Value()->ResetLocation();
}
Select3D_SensitiveEntity::ResetLocation();
}
//=======================================================================
//function : Matches
//purpose :
//=======================================================================
Standard_Boolean Select3D_SensitiveGroup::Matches(const Standard_Real X,
const Standard_Real Y,
const Standard_Real aTol,
Standard_Real& DMin)
{
myLastRank = 0;
myLastTol = aTol;
for(Select3D_ListIteratorOfListOfSensitive It(myList);It.More();It.Next()){
myLastRank++;
if(It.Value()->Matches(X,Y,aTol,DMin)){
myX = X;myY = Y;myLastTol = aTol;
SetLastDepth( Precision::Infinite() );
Select3D_SensitiveEntity::Matches(X,Y,aTol,DMin);
return Standard_True;
}
}
myLastRank =0;
SetLastDepth(0.0);
return Standard_False;
}
//=======================================================================
//function : Matches
//purpose : si on doit tout matcher, on ne repond oui que si toutes
// les primitives repondent oui
//=======================================================================
Standard_Boolean Select3D_SensitiveGroup::Matches(const Standard_Real XMin,
const Standard_Real YMin,
const Standard_Real XMax,
const Standard_Real YMax,
const Standard_Real aTol)
{
Standard_Boolean result(Standard_True);
for(Select3D_ListIteratorOfListOfSensitive It(myList);It.More();It.Next()){
if(It.Value()->Matches(XMin,YMin,XMax,YMax,aTol)){
if(!myMustMatchAll)
return Standard_True;
}
// ca ne matches pas..
else {
if(myMustMatchAll)
return Standard_False;
else
result = Standard_False;
}
}
return result;
}
//=======================================================================
//function : Matches
//purpose :
//=======================================================================
Standard_Boolean Select3D_SensitiveGroup::
Matches (const TColgp_Array1OfPnt2d& aPoly,
const Bnd_Box2d& aBox,
const Standard_Real aTol)
{
Standard_Boolean result(Standard_True);
for(Select3D_ListIteratorOfListOfSensitive It(myList);It.More();It.Next()){
if(It.Value()->Matches(aPoly, aBox, aTol)){
if(!myMustMatchAll)
return Standard_True;
}
else {
if(myMustMatchAll)
return Standard_False;
else
result = Standard_False;
}
}
return result;
}
//=======================================================================
//function : ComputeDepth
//purpose : pour optimiser, on prend le min des profondeurs pour
// les entites qui repondent OUI a Matches(X,Y,...)
// on commence le test a partir de mylastRank...
//=======================================================================
Standard_Real Select3D_SensitiveGroup::ComputeDepth(const gp_Lin& EyeLine) const
{
Standard_Integer currank(0);
Standard_Real DMin,thedepth(Precision::Infinite());
for(Select3D_ListIteratorOfListOfSensitive It(myList);It.More();It.Next()){
currank++;
if(currank>=myLastRank){
if(It.Value()->Matches(myX,myY,myLastTol,DMin)){
It.Value()->ComputeDepth(EyeLine);
thedepth = Min(Depth(),
It.Value()->Depth());
}
}
}
return thedepth;
}
//=======================================================================
//function : MaxBoxes
//purpose :
//=======================================================================
Standard_Integer Select3D_SensitiveGroup::MaxBoxes() const
{
Standard_Integer nbboxes(0);
for(Select3D_ListIteratorOfListOfSensitive It(myList);It.More();It.Next()){
nbboxes+=It.Value()->MaxBoxes();
}
return nbboxes;
}
void Select3D_SensitiveGroup::SetLastPrj(const Select3D_Projector& Prj)
{
Select3D_SensitiveEntity::SetLastPrj(Prj);
for(Select3D_ListIteratorOfListOfSensitive It(myList);It.More();It.Next())
It.Value()->SetLastPrj(Prj);
}

View File

@@ -0,0 +1,15 @@
// File: Select3D_SensitiveGroup.lxx
// Created: Thu Apr 16 16:17:20 1998
// Author: Robert COUBLANC
// <rob@robox.paris1.matra-dtv.fr>
inline void Select3D_SensitiveGroup::Set(const Standard_Boolean MustMatchAllEntities)
{myMustMatchAll = MustMatchAllEntities;}
inline Standard_Boolean Select3D_SensitiveGroup::MustMatchAll() const
{return myMustMatchAll;}
inline const Select3D_ListOfSensitive& Select3D_SensitiveGroup::GetEntities() const
{return myList;}

View File

@@ -0,0 +1,95 @@
-- File: Select3D_SensitivePoint.cdl
-- Created: Thu Feb 23 09:46:31 1995
-- Author: Mister rmi
-- <rmi@photon>
---Copyright: Matra Datavision 1995
class SensitivePoint from Select3D
inherits SensitiveEntity from Select3D
---Purpose: A framework to define sensitive 3D points.
uses
Pnt from gp,
Pnt2d from gp,
Projector from Select3D,
Lin from gp,
EntityOwner from SelectBasics,
ListOfBox2d from SelectBasics,
Location from TopLoc,
Box2d from Bnd,
Array1OfPnt2d from TColgp,
Pnt from Select3D,
Pnt2d from Select3D
is
Create (OwnerId : EntityOwner from SelectBasics;
Point : Pnt from gp)
returns mutable SensitivePoint;
---Purpose: Constructs a sensitive point object defined by the
-- owner OwnerId and the point Point.
Project (me:mutable;aProjector : Projector from Select3D)
is redefined static;
---Level: Public
---Purpose:Converts the stored 3D point into a 2D point according
-- to <aProjector> ; this method is called by the selection Manager.
Areas(me:mutable; aresult : in out ListOfBox2d from SelectBasics)
is redefined static;
---Level: Public
---Purpose: stores in <aresult> the 2D sensitive box which represents
-- the point area in the selection process.
GetConnected(me:mutable;aLocation: Location from TopLoc)
returns SensitiveEntity from Select3D is redefined static;
Matches(me :mutable;
X,Y : Real from Standard;
aTol: Real from Standard;
DMin: out Real from Standard)
returns Boolean
is redefined static;
---Level: Public
---Purpose: returns true if the X,Y position matches the point
-- else gives the distance between them.
Matches (me :mutable;
XMin,YMin,XMax,YMax : Real from Standard;
aTol: Real from Standard)
returns Boolean
is static;
Matches (me :mutable;
Polyline:Array1OfPnt2d from TColgp;
aBox:Box2d from Bnd;
aTol: Real from Standard)
returns Boolean
is redefined virtual;
---Level: Public
ComputeDepth(me;EyeLine: Lin from gp)
returns Real from Standard is redefined static;
Point(me) returns Pnt from gp;
---Purpose: Returns the point used at the time of construction.
Dump(me; S: in out OStream;FullDump : Boolean from Standard = Standard_True) is redefined virtual;
fields
mypoint : Pnt from Select3D;
myprojpt : Pnt2d from Select3D;
end SensitivePoint;

View File

@@ -0,0 +1,164 @@
// Copyright: Matra-Datavision 1995
// File: Select3D_SensitivePoint.cxx
// Created: Fri Mar 10 13:41:23 1995
// Author: Mister rmi
// <rmi>
#include <Select3D_SensitivePoint.ixx>
#include <Select3D_Projector.hxx>
#include <Bnd_Box2d.hxx>
#include <ElCLib.hxx>
#include <CSLib_Class2d.hxx>
//==================================================
// Function:
// Purpose :
//==================================================
Select3D_SensitivePoint
::Select3D_SensitivePoint(const Handle(SelectBasics_EntityOwner)& anOwner,
const gp_Pnt& aPoint):
Select3D_SensitiveEntity(anOwner)
{
SetSensitivityFactor(4.);
mypoint = aPoint;
}
//==================================================
// Function:
// Purpose :
//==================================================
void Select3D_SensitivePoint
::Project (const Select3D_Projector& aProj)
{
Select3D_SensitiveEntity::Project(aProj); // to set the field last proj...
gp_Pnt2d aPoint2d;
if(!HasLocation())
aProj.Project(mypoint, aPoint2d);
else{
gp_Pnt aP(mypoint.x, mypoint.y, mypoint.z);
aProj.Project(aP.Transformed(Location().Transformation()), aPoint2d);
}
myprojpt = aPoint2d;
}
//==================================================
// Function:
// Purpose :
//==================================================
void Select3D_SensitivePoint
::Areas(SelectBasics_ListOfBox2d& boxes)
{
Bnd_Box2d abox;
abox.Set(myprojpt);
boxes.Append(abox);
}
//==================================================
// Function:
// Purpose :
//==================================================
Standard_Boolean Select3D_SensitivePoint
::Matches(const Standard_Real X,
const Standard_Real Y,
const Standard_Real aTol,
Standard_Real& DMin)
{
DMin = gp_Pnt2d(X,Y).Distance(myprojpt);
if(DMin<=aTol*SensitivityFactor()) {
Select3D_SensitiveEntity::Matches(X,Y,aTol,DMin);
return Standard_True;
}
return Standard_False;
}
Standard_Boolean Select3D_SensitivePoint::
Matches (const Standard_Real XMin,
const Standard_Real YMin,
const Standard_Real XMax,
const Standard_Real YMax,
const Standard_Real aTol)
{
Bnd_Box2d B;
B.Update(Min(XMin,XMax),Min(YMin,YMax),Max(XMin,XMax),Max(YMin,YMax));
B.Enlarge(aTol);
return !B.IsOut(myprojpt);
}
//=======================================================================
//function : Matches
//purpose :
//=======================================================================
Standard_Boolean Select3D_SensitivePoint::
Matches (const TColgp_Array1OfPnt2d& aPoly,
const Bnd_Box2d& aBox,
const Standard_Real aTol)
{
Standard_Real Umin,Vmin,Umax,Vmax;
aBox.Get(Umin,Vmin,Umax,Vmax);
Standard_Real Tolu,Tolv;
Tolu = 1e-7;
Tolv = 1e-7;
CSLib_Class2d aClassifier2d(aPoly,aTol,aTol,Umin,Vmin,Umax,Vmax);
Standard_Integer RES = aClassifier2d.SiDans(myprojpt);
if(RES==1) return Standard_True;
return Standard_False;
}
//=======================================================================
//function : Point
//purpose :
//=======================================================================
gp_Pnt Select3D_SensitivePoint::Point() const
{return mypoint;}
//=======================================================================
//function : GetConnected
//purpose :
//=======================================================================
Handle(Select3D_SensitiveEntity) Select3D_SensitivePoint::GetConnected(const TopLoc_Location& aLoc)
{
Handle(Select3D_SensitivePoint) NiouEnt = new Select3D_SensitivePoint(myOwnerId,mypoint);
if(HasLocation()) NiouEnt->SetLocation(Location());
NiouEnt->UpdateLocation(aLoc);
return NiouEnt;
}
//=======================================================================
//function : Dump
//purpose :
//=======================================================================
void Select3D_SensitivePoint::Dump(Standard_OStream& S,const Standard_Boolean FullDump) const
{
S<<"\tSensitivePoint 3D :";
if(HasLocation())
S<<"\t\tExisting Location"<<endl;
S<<"\t\t P3d [ "<<mypoint.x<<" , "<<mypoint.y<<" , "<<mypoint.z<<" ]"<<endl;
S<<"\t\t P2d [ "<<myprojpt.x<<" , "<<myprojpt.y<<" ]"<<endl;
}
//=======================================================================
//function : ComputeDepth
//purpose :
//=======================================================================
Standard_Real Select3D_SensitivePoint::ComputeDepth(const gp_Lin& EyeLine) const
{
return ElCLib::Parameter(EyeLine,mypoint);
}

View File

@@ -0,0 +1,72 @@
deferred class SensitivePoly from Select3D
inherits SensitiveEntity from Select3D
---Purpose: Sensitive Entity to make a face selectable.
uses
EntityOwner from SelectBasics,
Projector from Select3D,
ListOfBox2d from SelectBasics,
Array1OfPnt from TColgp,
HArray1OfPnt from TColgp,
Array1OfPnt2d from TColgp,
Box2d from Select3D
is
Initialize (OwnerId : EntityOwner from SelectBasics;
ThePoints : Array1OfPnt from TColgp)
returns mutable SensitivePoly;
---Level: Public
---Purpose: Constructs a sensitive face object defined by the
-- owner OwnerId, the array of points ThePoints, and
-- the sensitivity type Sensitivity.
-- The array of points is the outer polygon of the geometric face.
Initialize (OwnerId : EntityOwner from SelectBasics;
ThePoints : HArray1OfPnt from TColgp)
returns mutable SensitivePoly;
---Level: Public
---Purpose: Constructs a sensitive face object defined by the
-- owner OwnerId, the array of points ThePoints, and
-- the sensitivity type Sensitivity.
-- The array of points is the outer polygon of the geometric face.
Initialize(OwnerId : EntityOwner from SelectBasics;
NbOfPoints : Integer = 6)
returns mutable SensitivePoly;
---Level: Public
---Purpose: Constructs the sensitive circle object defined by the
-- owner OwnerId, the circle Circle, the Boolean
-- FilledCircle and the number of points NbOfPoints.
Project (me:mutable;aProjector : Projector from Select3D) is redefined virtual;
---Level: Public
---Purpose: projection of the sensitive primitive in order to
-- get 2D boxes for the Sort Algorithm
Areas (me:mutable ; boxes : in out ListOfBox2d from SelectBasics) is redefined static;
---Level: Public
---Purpose: stores in <boxes> the 2D Boxes which represent the sensitive face
-- in the selection algorithm.
Points3D(me:mutable; theHArrayOfPnt : in out HArray1OfPnt from TColgp);
---Purpose: Returns the 3D points of the array used at construction time.
---C++: inline
Points2D(me:mutable; theArrayOfPnt2d : in out Array1OfPnt2d from TColgp);
---Purpose: Returns the 2D points of the array used at construction time.
---C++: inline
Destroy(me: mutable);
---C++: alias ~
fields
mypolyg3d : Address from Standard is protected;
mypolyg2d : Address from Standard is protected;
mybox2d : Box2d from Select3D is protected;
mynbpoints : Integer from Standard is protected;
end SensitiveFace;

View File

@@ -0,0 +1,103 @@
#include <Select3D_SensitivePoly.ixx>
#include <gp_Pnt2d.hxx>
#include <gp_Pnt.hxx>
#include <Select3D_Pnt.hxx>
#include <Select3D_Pnt2d.hxx>
#include <Select3D_Box2d.hxx>
#include <TopLoc_Location.hxx>
//==================================================
// Function: faire disparaitre ce constructeur a la prochaine version...
// Purpose : simplement garde pour ne pas perturber la version update
//==================================================
Select3D_SensitivePoly::
Select3D_SensitivePoly(const Handle(SelectBasics_EntityOwner)& OwnerId,
const TColgp_Array1OfPnt& ThePoints):
Select3D_SensitiveEntity(OwnerId)
{
mynbpoints = ThePoints.Upper()-ThePoints.Lower()+1;
mypolyg3d = new Select3D_Pnt[mynbpoints];
mypolyg2d = new Select3D_Pnt2d[mynbpoints];
for(Standard_Integer i=0;i<mynbpoints;i++)
((Select3D_Pnt*)mypolyg3d)[i] = ThePoints.Value(ThePoints.Lower()+i);
}
//==================================================
// Function:
// Purpose :
//==================================================
Select3D_SensitivePoly::
Select3D_SensitivePoly(const Handle(SelectBasics_EntityOwner)& OwnerId,
const Handle(TColgp_HArray1OfPnt)& ThePoints):
Select3D_SensitiveEntity(OwnerId)
{
mynbpoints = ThePoints->Upper()-ThePoints->Lower()+1;
mypolyg3d = new Select3D_Pnt[mynbpoints];
mypolyg2d = new Select3D_Pnt2d[mynbpoints];
for(Standard_Integer i=0;i<mynbpoints;i++)
((Select3D_Pnt*)mypolyg3d)[i] = ThePoints->Value(ThePoints->Lower()+i);
}
//==================================================
// Function:
// Purpose :
//==================================================
Select3D_SensitivePoly::
Select3D_SensitivePoly(const Handle(SelectBasics_EntityOwner)& OwnerId,
const Standard_Integer NbPoints):
Select3D_SensitiveEntity(OwnerId)
{
mynbpoints = NbPoints;
mypolyg3d = new Select3D_Pnt[mynbpoints];
mypolyg2d = new Select3D_Pnt2d[mynbpoints];
}
//==================================================
// Function:
// Purpose :
//==================================================
void Select3D_SensitivePoly::Project(const Select3D_Projector& aProj)
{
Select3D_SensitiveEntity::Project(aProj); // to set the field last proj...
mybox2d.SetVoid();
Standard_Boolean hasloc = HasLocation();
gp_Pnt2d aPnt2d;
for(Standard_Integer i=0;i<mynbpoints;i++)
{
gp_Pnt aPnt(((Select3D_Pnt*)mypolyg3d)[i].x, ((Select3D_Pnt*)mypolyg3d)[i].y, ((Select3D_Pnt*)mypolyg3d)[i].z);
if(hasloc){
aProj.Project(aPnt.Transformed(Location().Transformation()),aPnt2d);
}
else
aProj.Project(aPnt,aPnt2d);
mybox2d.Update(aPnt2d);
((Select3D_Pnt2d*)mypolyg2d)[i] = aPnt2d;
}
}
//==================================================
// Function:
// Purpose :
//==================================================
void Select3D_SensitivePoly
::Areas(SelectBasics_ListOfBox2d& aSeq)
{
aSeq.Append(mybox2d);
}
//==================================================
// Function:
// Purpose :
//==================================================
void Select3D_SensitivePoly::Destroy()
{
delete[] (Select3D_Pnt*)mypolyg3d;
delete[] (Select3D_Pnt2d*)mypolyg2d;
}

View File

@@ -0,0 +1,27 @@
#include<Select3D_Pnt.hxx>
#include<Select3D_Pnt2d.hxx>
#include<TColgp_HArray1OfPnt.hxx>
#include<TColgp_Array1OfPnt2d.hxx>
inline void Select3D_SensitivePoly
::Points3D( Handle(TColgp_HArray1OfPnt)& theHArrayOfPnt )
{
theHArrayOfPnt = new TColgp_HArray1OfPnt(1,mynbpoints);
for(Standard_Integer i = 1; i <= mynbpoints; i++)
{
gp_Pnt aPnt(((Select3D_Pnt*)mypolyg3d)[i-1].x, ((Select3D_Pnt*)mypolyg3d)[i-1].y, ((Select3D_Pnt*)mypolyg3d)[i-1].z);
theHArrayOfPnt->SetValue(i, aPnt);
}
}
inline void Select3D_SensitivePoly
::Points2D( TColgp_Array1OfPnt2d& aArrayOf2dPnt)
{
for(Standard_Integer i = 1; i <= mynbpoints; i++)
{
gp_Pnt2d aPnt2d(((Select3D_Pnt2d*)mypolyg2d)[i-1].x, ((Select3D_Pnt2d*)mypolyg2d)[i-1].y);
aArrayOf2dPnt.SetValue(i,aPnt2d);
}
}

View File

@@ -0,0 +1,153 @@
-- File: Select3D_SensitiveSegment.cdl
-- Created: Tue Jan 24 13:49:15 1995
-- Author: Mister rmi
-- <rmi@photon>
---Copyright: Matra Datavision 1995
class SensitiveSegment from Select3D
inherits SensitiveEntity from Select3D
---Purpose: A framework to define sensitive zones along a segment
-- One gives the 3D start and end point;
-- the maximum number of 2D boxes given
-- by this entity may be set by the user
-- if the projected segment is
-- vertical or horizontal, one needs only 1 box.
-- for a pi/4 angle -> MaxNumber 2D boxes
uses
Pnt from gp,
Pnt2d from gp,
Projector from Select3D,
Lin from gp,
EntityOwner from SelectBasics,
ListOfBox2d from SelectBasics,
Array1OfPnt2d from TColgp,
Box2d from Bnd,
Location from TopLoc,
Pnt from Select3D,
Pnt2d from Select3D
is
Create (OwnerId : EntityOwner from SelectBasics;
FirstP,LastP : Pnt from gp;
MaxRect : Integer = 1)
returns mutable SensitiveSegment;
---Purpose: Constructs the sensitive segment object defined by
-- the owner OwnerId, the points FirstP, LastP and the
-- maximum number of sensitive bounding boxes MaxRect.
Set (me:mutable; MaxRect : Integer) is static;
---Purpose: Sets the maximum number of sensitive rectangles MaxRect.
---C++: inline
StartPoint (me : mutable ; aPt : Pnt from gp) is static;
---Level: Public
---Purpose: changes the start Point of the Segment;
---C++: inline
EndPoint (me : mutable ; aPt : Pnt from gp) is static;
---Level: Public
---Purpose: changes the end point of the segment
---C++: inline
StartPoint (me) returns Pnt from gp is static;
---Level: Public
---Purpose: gives the 3D start Point of the Segment
---C++: inline
EndPoint(me) returns Pnt from gp is static;
---Level: Public
---Purpose: gives the 3D End Point of the Segment
---C++: inline
StartPoint2d (me) returns Pnt2d from gp is static;
---Level: Public
---Purpose: gives the 3D start Point of the Segment
---C++: inline
EndPoint2d(me) returns Pnt2d from gp is static;
---Level: Public
---Purpose: gives the 3D End Point of the Segment
---C++: inline
Project (me:mutable;aProjector : Projector from Select3D)
is redefined virtual;
---Level: Public
---Purpose: projection of the sensitive primitive in order to
-- get 2D boxes for the Sort Algorithm
Areas (me:mutable ; boxes : in out ListOfBox2d from SelectBasics)
is redefined static;
---Level: Public
---Purpose: gives the 2D boxes which represent the segment in the
-- selection process...
GetConnected(me:mutable;aLocation: Location from TopLoc)
returns SensitiveEntity from Select3D is redefined static;
Matches(me :mutable;
X,Y : Real from Standard;
aTol: Real from Standard;
DMin: out Real from Standard)
returns Boolean
is redefined static;
---Level: Public
---Purpose: projection of the sensitive primitive in order to
-- get 2D boxes for the Sort Algorithm
Matches (me :mutable;
XMin,YMin,XMax,YMax : Real from Standard;
aTol: Real from Standard)
returns Boolean
is static;
Matches (me :mutable;
Polyline:Array1OfPnt2d from TColgp;
aBox:Box2d from Bnd;
aTol: Real from Standard)
returns Boolean
is redefined virtual;
---Level: Public
ComputeDepth(me;EyeLine: Lin from gp)
returns Real from Standard is redefined static;
MaxBoxes(me) returns Integer is redefined static;
---Level: Public
---Purpose:returns <mymaxrect>
---C++: inline
Dump(me; S: in out OStream;FullDump : Boolean from Standard = Standard_True) is redefined virtual;
fields
mymaxrect : Integer;
mystart : Pnt from Select3D;
myend : Pnt from Select3D;
myprojstart : Pnt2d from Select3D; -- computed at convert time
myprojend : Pnt2d from Select3D; -- computed at convert time
end SensitiveSegment;

View File

@@ -0,0 +1,234 @@
// Copyright: Matra-Datavision 1995
// File: Select3D_SensitiveSegment.cxx
// Created: Wed Jan 25 11:27:54 1995
// Author: Mister rmi
// <rmi>
#include <Select3D_SensitiveSegment.ixx>
#include <SelectBasics_BasicTool.hxx>
#include <gp_Vec.hxx>
#include <gp_Vec2d.hxx>
#include <Bnd_Box2d.hxx>
#include <gp_Pnt2d.hxx>
#include <gp_Dir2d.hxx>
#include <gp_Lin2d.hxx>
#include <ElCLib.hxx>
#include <Extrema_ExtElC.hxx>
#include <Extrema_POnCurv.hxx>
#include <TColgp_Array1OfPnt2d.hxx>
#include <Precision.hxx>
#include <SelectBasics_ListIteratorOfListOfBox2d.hxx>
#include <CSLib_Class2d.hxx>
//=====================================================
// Function : Create
// Purpose :Constructor
//=====================================================
Select3D_SensitiveSegment::
Select3D_SensitiveSegment(const Handle(SelectBasics_EntityOwner)& OwnerId,
const gp_Pnt& FirstP,
const gp_Pnt& LastP,
const Standard_Integer MaxRect):
Select3D_SensitiveEntity(OwnerId),
mymaxrect(MaxRect)
{
mystart = FirstP;
myend = LastP;
}
//=====================================================
// Function :
// Purpose :
//=====================================================
void Select3D_SensitiveSegment
::Project(const Select3D_Projector& aProj)
{
Select3D_SensitiveEntity::Project(aProj); // to set the field last proj...
gp_Pnt2d aPoint2dStart;
gp_Pnt2d aPoint2dEnd;
if(HasLocation()){
gp_Pnt aStart(mystart.x, mystart.y, mystart.z);
gp_Pnt aEnd(myend.x, myend.y, myend.z);
aProj.Project(aStart.Transformed(Location().Transformation()),aPoint2dStart);
aProj.Project(aEnd.Transformed(Location().Transformation()),aPoint2dEnd);
}
else{
aProj.Project(mystart,aPoint2dStart);
aProj.Project(myend,aPoint2dEnd);
}
myprojstart = aPoint2dStart;
myprojend = aPoint2dEnd;
}
//=====================================================
// Function : Areas
// Purpose :
//=====================================================
void Select3D_SensitiveSegment
::Areas(SelectBasics_ListOfBox2d& theareas)
{
// gp_Dir2d dy (0.,1.);
gp_Pnt2d aPStart(myprojstart.x,myprojstart.y);
if(aPStart.Distance(myprojend)<=Precision::Confusion()){
Bnd_Box2d curbox;
curbox.Set(myprojstart);
theareas.Append(curbox);
}
else {
gp_Vec2d MyVec(myprojstart,myprojend);//,VAxx(gp_Dir2d(0.,1.));
Standard_Real theangle = Abs(gp_Dir2d(0.,1.).Angle(gp_Vec2d(myprojstart,myprojend)));
if(theangle>=PI/2.) theangle-=PI/2;
if(theangle>=PI/12. && theangle <=5*PI/12.)
{
TColgp_Array1OfPnt2d BoxPoint (1,mymaxrect+1);
BoxPoint (1) = myprojstart;
BoxPoint(mymaxrect+1)=myprojend;
gp_Vec2d Vtr = MyVec/mymaxrect;
// for (Standard_Integer i=2;i<=mymaxrect;i++)
Standard_Integer i;
for ( i=2;i<=mymaxrect;i++)
{BoxPoint (i) = BoxPoint (i-1).Translated(Vtr);}
for (i=2;i<=mymaxrect+1;i++)
{ Bnd_Box2d curbox;
curbox.Set(BoxPoint(i-1));
curbox.Add(BoxPoint(i));
theareas.Append(curbox);
}
}
else
{
Bnd_Box2d curbox;
curbox.Set(myprojstart);
curbox.Add(myprojend);
theareas.Append(curbox);
}
}
}
//=====================================================
// Function : Matches
// Purpose :
//=====================================================
Standard_Boolean Select3D_SensitiveSegment
::Matches(const Standard_Real X,
const Standard_Real Y,
const Standard_Real aTol,
Standard_Real& DMin)
{
gp_Pnt2d aPStart(myprojstart.x,myprojstart.y);
gp_Pnt2d aPEnd(myprojend.x,myprojend.y);
if ( ! SelectBasics_BasicTool::MatchSegment (aPStart, aPEnd, X, Y, aTol, DMin) )
return Standard_False;
Select3D_SensitiveEntity::Matches (X, Y, aTol, DMin); // to compute depth
return Standard_True;
}
Standard_Boolean Select3D_SensitiveSegment::
Matches (const Standard_Real XMin,
const Standard_Real YMin,
const Standard_Real XMax,
const Standard_Real YMax,
const Standard_Real aTol)
{
Bnd_Box2d BoundBox;
BoundBox.Update(XMin-aTol,YMin-aTol,XMax+aTol,YMax+aTol);
if(BoundBox.IsOut(myprojstart)) return Standard_False;
if( BoundBox.IsOut(myprojend)) return Standard_False;
return Standard_True;
}
//=======================================================================
//function : Matches
//purpose :
//=======================================================================
Standard_Boolean Select3D_SensitiveSegment::
Matches (const TColgp_Array1OfPnt2d& aPoly,
const Bnd_Box2d& aBox,
const Standard_Real aTol)
{
Standard_Real Umin,Vmin,Umax,Vmax;
aBox.Get(Umin,Vmin,Umax,Vmax);
Standard_Real Tolu,Tolv;
Tolu = 1e-7;
Tolv = 1e-7;
CSLib_Class2d aClassifier2d(aPoly,aTol,aTol,Umin,Vmin,Umax,Vmax);
Standard_Integer RES = aClassifier2d.SiDans(myprojstart);
if (RES!=1) return Standard_False;
RES = aClassifier2d.SiDans(myprojend);
if (RES!=1) return Standard_False;
return Standard_True;
}
//=======================================================================
//function : GetConnected
//purpose :
//=======================================================================
Handle(Select3D_SensitiveEntity) Select3D_SensitiveSegment::GetConnected(const TopLoc_Location& aLoc)
{
Handle(Select3D_SensitiveSegment) NiouEnt = new Select3D_SensitiveSegment(myOwnerId,mystart,myend,mymaxrect);
if(HasLocation()) NiouEnt->SetLocation(Location());
NiouEnt->UpdateLocation(aLoc);
return NiouEnt;
}
//=======================================================================
//function : Dump
//purpose :
//=======================================================================
void Select3D_SensitiveSegment::Dump(Standard_OStream& S,const Standard_Boolean FullDump) const
{
S<<"\tSensitivePoint 3D :"<<endl;
if(HasLocation())
S<<"\t\tExisting Location"<<endl;
S<<"\t\t P1 [ "<<mystart.x<<" , "<<mystart.y <<" , "<<mystart.z <<" ]"<<endl;
S<<"\t\t P2 [ "<<myend.x<<" , "<<myend.y <<" , "<<myend.z <<" ]"<<endl;
S<<"\t\t maxrect ="<<mymaxrect<<endl;
}
//=======================================================================
//function : ComputeDepth
//purpose :
//=======================================================================
Standard_Real Select3D_SensitiveSegment::ComputeDepth(const gp_Lin& EyeLine) const
{
gp_Pnt aP0 = mystart;
gp_Pnt aP1 = myend;
// if segment is degenerated (zero length), just use depth of the end
gp_XYZ aV = aP1.XYZ() - aP0.XYZ();
Standard_Real aNorm = aV.Modulus();
if ( aNorm <= gp::Resolution() )
return ElCLib::Parameter (EyeLine, aP0);
// else compute point on segment closest to the line
gp_Lin aLine (aP0, aV);
Extrema_ExtElC aTool (aLine, EyeLine, Precision::Angular());
if ( aTool.IsDone() && ! aTool.IsParallel() )
{
for (Standard_Integer i=1; i <= aTool.NbExt(); i++)
{
Extrema_POnCurv POL1, POL2;
aTool.Points (i, POL1, POL2);
// use point found by extrema only if it is inside segment
if ( POL1.Parameter() > 0. && POL1.Parameter() < aNorm )
return ElCLib::Parameter (EyeLine, POL1.Value());
}
}
// if extrema failed or lines are parallel, return closest of the segment ends
return Min (ElCLib::Parameter (EyeLine, aP0),
ElCLib::Parameter (EyeLine, aP1));
}

View File

@@ -0,0 +1,35 @@
// Copyright: Matra-Datavision 1995
// File: Select3D_SensitiveSegment.lxx
// Created: Thu Feb 23 09:07:24 1995
// Author: Mister rmi
// <rmi>
inline void Select3D_SensitiveSegment::Set(const Standard_Integer MaxRect)
{mymaxrect = MaxRect;}
inline void Select3D_SensitiveSegment::StartPoint (const gp_Pnt& start)
{
mystart = start;
}
inline void Select3D_SensitiveSegment::EndPoint (const gp_Pnt& end)
{
myend = end;
}
inline gp_Pnt Select3D_SensitiveSegment::StartPoint () const
{return mystart;}
inline gp_Pnt Select3D_SensitiveSegment::EndPoint () const
{return myend;}
inline gp_Pnt2d Select3D_SensitiveSegment::StartPoint2d () const
{return myprojstart;}
inline gp_Pnt2d Select3D_SensitiveSegment::EndPoint2d () const
{return myprojend;}
inline Standard_Integer Select3D_SensitiveSegment::MaxBoxes()
const {return mymaxrect;}

View File

@@ -0,0 +1,93 @@
-- File: Select3D_SensitiveTriangle.cdl
-- Created: Wed May 14 16:37:59 1997
-- Author: Robert COUBLANC
-- <rob@robox.paris1.matra-dtv.fr>
---Copyright: Matra Datavision 1997
class SensitiveTriangle from Select3D
inherits SensitivePoly from Select3D
---Purpose: A framework to define selection of triangles in a view.
-- This comes into play in the detection of meshing and triangulation in surfaces.
uses
EntityOwner from SelectBasics,
Projector from Select3D,
Lin from gp,
ListOfBox2d from SelectBasics,
Array1OfPnt2d from TColgp,
Box2d from Bnd,
XY from gp,
Pnt from gp,
TypeOfSensitivity from Select3D,
Location from TopLoc
is
Create (OwnerId : EntityOwner from SelectBasics;
P1,P2,P3 : Pnt from gp;
Sensitivity : TypeOfSensitivity = Select3D_TOS_INTERIOR)
returns mutable SensitiveTriangle;
---Level: Public
---Purpose: Constructs a sensitive triangle object defined by the
-- owner OwnerId, the points P1, P2, P3, and the type of sensitivity Sensitivity.
Matches(me :mutable;
X,Y : Real from Standard;
aTol: Real from Standard;
DMin: out Real from Standard)
returns Boolean
is redefined virtual;
Matches (me :mutable;
XMin,YMin,XMax,YMax : Real from Standard;
aTol: Real from Standard)
returns Boolean
is redefined virtual;
---Level: Public
Matches (me :mutable;
Polyline:Array1OfPnt2d from TColgp;
aBox:Box2d from Bnd;
aTol: Real from Standard)
returns Boolean
is redefined virtual;
---Level: Public
ComputeDepth(me;EyeLine: Lin from gp)
returns Real from Standard is redefined static;
Points3D(me; P1,P2,P3 : out Pnt from gp) ;
---Purpose: Returns the 3D points P1, P2, P3 used at the time of construction.
Center3D (me) returns Pnt from gp;
---Purpose: Returns the center point of the sensitive triangle created at construction time.
Center2D (me) returns XY from gp;
---Purpose: WARNING : the returned Values are the original values
-- without the stored location (if there's one).
-- To get the genuine value, One must apply this location
-- (Method Location() )
Status(me;
X,Y : Real from Standard;
aTol : Real from Standard ;
Dmin : out Real from Standard)
returns Integer from Standard;
Status (myclass;
p0,p1,p2: XY from gp ;
aPoint : XY from gp ;
aTol : Real from Standard;
Dmin : out Real from Standard) returns Integer from Standard;
---Purpose: Dmin gives the distance between the cdg and aPoint return
Dump(me; S: in out OStream;FullDump : Boolean from Standard = Standard_True) is redefined virtual;
fields
mytype : TypeOfSensitivity from Select3D;
end SensitiveTriangle;

View File

@@ -0,0 +1,355 @@
// File: Select3D_SensitiveTriangle.cxx
// Created: Wed May 14 16:56:06 1997
// Author: Robert COUBLANC
// <rob@robox.paris1.matra-dtv.fr>
#include <Select3D_SensitiveTriangle.ixx>
#include <SelectBasics_BasicTool.hxx>
#include <gp_Pnt2d.hxx>
#include <gp_Pnt.hxx>
#include <gp_Dir2d.hxx>
#include <Precision.hxx>
#include <Bnd_Box.hxx>
#include <ElCLib.hxx>
#include <TopLoc_Location.hxx>
#include <CSLib_Class2d.hxx>
#define COORD(a,b) ((Select3D_Pnt*)mypolyg3d)[(a)].b
#define COORD2d(a,b) ((Select3D_Pnt2d*)mypolyg2d)[(a)].b
static Standard_Boolean S3D_Str_NearSegment (const gp_XY& p0, const gp_XY& p1, const gp_XY& TheP,
const Standard_Real aTol, Standard_Real& aDMin)
{
gp_XY V01(p1);
V01 -= p0;
gp_XY Vec(TheP);
Vec -= p0;
Standard_Real u = Vec*V01.Normalized();
if(u<-aTol) return Standard_False;
Standard_Real u1 = u-aTol;
Standard_Real modmod = V01.SquareModulus();
if(u1*u1> modmod) return Standard_False;
gp_XY N01 (-V01.Y(),V01.X());
N01.Normalize();
aDMin = Abs (Vec * N01);
return aDMin <= aTol;
}
//==================================================
// Function:
// Purpose :
//==================================================
Select3D_SensitiveTriangle::
Select3D_SensitiveTriangle(const Handle(SelectBasics_EntityOwner)& OwnerId,
const gp_Pnt& P0,
const gp_Pnt& P1,
const gp_Pnt& P2,
const Select3D_TypeOfSensitivity aType):
Select3D_SensitivePoly(OwnerId,3),
mytype (aType)
{
((Select3D_Pnt*)mypolyg3d)[0] = P0;
((Select3D_Pnt*)mypolyg3d)[1] = P1;
((Select3D_Pnt*)mypolyg3d)[2] = P2;
}
//==================================================
// Function:
// Purpose :
//==================================================
Standard_Boolean Select3D_SensitiveTriangle::
Matches(const Standard_Real X,
const Standard_Real Y,
const Standard_Real aTol,
Standard_Real& DMin)
{
Select3D_SensitiveEntity::Matches(X,Y,aTol,DMin);
if(Bnd_Box2d(mybox2d).IsOut(gp_Pnt2d(X,Y))) return Standard_False;
Standard_Integer Res;
switch (mytype){
case Select3D_TOS_BOUNDARY:
Res = Status(X,Y,aTol,DMin);
return Res== 1;
break;
case Select3D_TOS_INTERIOR:
Res = Status(X,Y,aTol,DMin);
return (Res==0 || Res == 1);
#ifndef DEB
default:
break;
#endif
}
return Standard_True;
}
Standard_Boolean Select3D_SensitiveTriangle::
Matches (const Standard_Real XMin,
const Standard_Real YMin,
const Standard_Real XMax,
const Standard_Real YMax,
const Standard_Real aTol)
{
Bnd_Box2d B;
B.Update(Min(XMin,XMax)-aTol,
Min(YMin,YMax)-aTol,
Max(XMin,XMax)+aTol,
Max(YMin,YMax)+aTol);
for(Standard_Integer i=0;i<=2;i++){
if(B.IsOut(((Select3D_Pnt2d*)mypolyg2d)[i]))
return Standard_False;}
return Standard_True;
}
//=======================================================================
//function : Matches
//purpose :
//=======================================================================
Standard_Boolean Select3D_SensitiveTriangle::
Matches (const TColgp_Array1OfPnt2d& aPoly,
const Bnd_Box2d& aBox,
const Standard_Real aTol)
{
Standard_Real Umin,Vmin,Umax,Vmax;
aBox.Get(Umin,Vmin,Umax,Vmax);
Standard_Real Tolu,Tolv;
Tolu = 1e-7;
Tolv = 1e-7;
CSLib_Class2d aClassifier2d(aPoly,aTol,aTol,Umin,Vmin,Umax,Vmax);
for(Standard_Integer i=0;i<=2;i++){
Standard_Integer RES = aClassifier2d.SiDans(((Select3D_Pnt2d*)mypolyg2d)[i]);
if(RES!=1) return Standard_False;
}
return Standard_True;
}
void Select3D_SensitiveTriangle::Points3D(gp_Pnt& P0,gp_Pnt& P1,gp_Pnt& P2) const
{
P0 = ((Select3D_Pnt*)mypolyg3d)[0]; P1 = ((Select3D_Pnt*)mypolyg3d)[1]; P2 = ((Select3D_Pnt*)mypolyg3d)[2];
}
gp_Pnt Select3D_SensitiveTriangle::Center3D() const
{
gp_XYZ CDG(((Select3D_Pnt*)mypolyg3d)[0]);
CDG += ((Select3D_Pnt*)mypolyg3d)[1];
CDG += ((Select3D_Pnt*)mypolyg3d)[2];
CDG /=3.;
return gp_Pnt(CDG);;
}
gp_XY Select3D_SensitiveTriangle::Center2D() const
{
return (gp_XY(((Select3D_Pnt2d*)mypolyg2d)[0])+gp_XY(((Select3D_Pnt2d*)mypolyg2d)[1])
+gp_XY(((Select3D_Pnt2d*)mypolyg2d)[2]))/3.;
}
//=======================================================================
//function : Status
//purpose : 0 = inside /1 = Boundary/ 2 = outside
//=======================================================================
Standard_Integer Select3D_SensitiveTriangle::Status(const Standard_Real X,
const Standard_Real Y,
const Standard_Real aTol,
Standard_Real& DMin) const
{
return Status(((Select3D_Pnt2d*)mypolyg2d)[0],((Select3D_Pnt2d*)mypolyg2d)[1],
((Select3D_Pnt2d*)mypolyg2d)[2],gp_XY(X,Y),aTol,DMin);
}
//=======================================================================
//function : Status
//purpose :
//=======================================================================
Standard_Integer Select3D_SensitiveTriangle::Status(const gp_XY& p0,
const gp_XY& p1,
const gp_XY& p2,
const gp_XY& TheP,
const Standard_Real aTol,
Standard_Real& DMin)
{
Bnd_Box2d B;
B.Update(p0.X(),p0.Y());B.Update(p1.X(),p1.Y());B.Update(p2.X(),p2.Y());
B.Enlarge(aTol);
if(B.IsOut(TheP)) return 2;
// on classifie le point par rapport aux demi -espaces delimites
// par chaque cote du triangle (a la tolerance pres)
gp_XY V01(p1);V01-=p0;
gp_XY V02(p2);V02-=p0;
gp_XY V12(p2);V12-=p1;
Standard_Real TolTol = aTol*aTol;
// regardons les cas particuliers...
//si l'un des vecteurs est quasi nul (2 points sont confondus),
// on sort tout de suite (on est deja dans la boite d'encombrement, c'est bon...)
DMin = aTol;
if ( V01.SquareModulus() <= gp::Resolution() )
{
Standard_Real LV = V02.SquareModulus();
if ( LV <= gp::Resolution())
return 0; // les 3 points sont confondus, et TheP est dans la boite englobante B...
if ( S3D_Str_NearSegment (p0, p2, TheP, aTol, DMin) )
return 0;
return 2;
}
if ( V02.SquareModulus() <= gp::Resolution() )
{
if ( S3D_Str_NearSegment (p0, p1, TheP, aTol, DMin) )
return 0;
return 2;
}
if ( V12.SquareModulus() <= gp::Resolution() )
{
if ( S3D_Str_NearSegment (p0, p1, TheP, aTol, DMin) )
return 0;
return 2;
}
if ( V01.CrossMagnitude(V02) <= gp::Resolution() )
{
if ( S3D_Str_NearSegment (p0, p1, TheP, aTol, DMin) )
return 0;
return 2;
}
// normale a p0p1 orientee...
gp_Dir2d N (-V01.Y(), V01.X());
Standard_Boolean Neg = (N * V02 < 0.);
if ( Neg )
N.Reverse();
gp_XY Vec(TheP);
Vec -= p0;
Standard_Real aD1 = Vec * N.XY();
if ( aD1 < -aTol )
return 2;
// normale a p1p2 orientee...
if(Neg)
N.SetCoord(p2.Y()-p1.Y(),p1.X()-p2.X());
else
N.SetCoord(p1.Y()-p2.Y(),p2.X()-p1.X());
Vec.SetCoord(TheP.X()-p1.X(),TheP.Y()-p1.Y());
Standard_Real aD2 = Vec * N.XY();
if ( aD2 < -aTol )
return 2; // dehors
// normale a p2p0 orientee...
// attention v20 (x0-x2) => N y2-y0 => -N y0-y2
// (y0-y2) x0-x2 x2-x0
if(Neg)
N.SetCoord(p0.Y()-p2.Y(),p2.X()-p0.X());
else
N.SetCoord(p2.Y()-p0.Y(),p0.X()-p2.X());
Vec.SetCoord(TheP.X()-p2.X(),TheP.Y()-p2.Y());
Standard_Real aD3 = Vec * N.XY();
if ( aD3 < -aTol )
return 2; // dehors
// compute 2d distance to triangle
Standard_Real aD = Min (aD1, Min (aD2, aD3));
DMin = ( aD < 0 ? -aD : 0. );
return 0;
}
//=======================================================================
//function : Dump
//purpose :
//=======================================================================
void Select3D_SensitiveTriangle::Dump(Standard_OStream& S,const Standard_Boolean FullDump) const
{
// les generalites....
S<<"\tSensitiveTriangle 3D :\n";
if(HasLocation())
S<<"\t\tExisting Location"<<endl;
S<<"\t\t P0 [ "<<COORD(0,x)<<" , "<<COORD(0,y) <<" , "<<COORD(0,z)<<" ]"<<endl;
S<<"\t\t P1 [ "<<COORD(1,x)<<" , "<<COORD(1,y) <<" , "<<COORD(1,z)<<" ]"<<endl;
S<<"\t\t P2 [ "<<COORD(2,x)<<" , "<<COORD(2,y) <<" , "<<COORD(2,z)<<" ]"<<endl;
if(FullDump){
S<<"\t\tProjected Points"<<endl;
S<<"\t\t 0.[ "<<COORD2d(0,x)<<" , "<<COORD2d(0,y)<<" ]"<<endl;
S<<"\t\t 1.[ "<<COORD2d(1,x)<<" , "<<COORD2d(1,y)<<" ]"<<endl;
S<<"\t\t 2.[ "<<COORD2d(2,x)<<" , "<<COORD2d(2,y)<<" ]"<<endl;
// S<<"\t\t\tOwner:"<<myOwnerId<<endl;
Select3D_SensitiveEntity::DumpBox(S,mybox2d);
}
}
//=======================================================================
//function : ComputeDepth
//purpose :
//=======================================================================
Standard_Real Select3D_SensitiveTriangle::ComputeDepth(const gp_Lin& EyeLine) const
{
gp_Pnt P1(((Select3D_Pnt*)mypolyg3d)[0].x, ((Select3D_Pnt*)mypolyg3d)[0].y, ((Select3D_Pnt*)mypolyg3d)[0].z);
gp_Pnt P2(((Select3D_Pnt*)mypolyg3d)[1].x, ((Select3D_Pnt*)mypolyg3d)[1].y, ((Select3D_Pnt*)mypolyg3d)[1].z);
gp_Pnt P3(((Select3D_Pnt*)mypolyg3d)[2].x, ((Select3D_Pnt*)mypolyg3d)[2].y, ((Select3D_Pnt*)mypolyg3d)[2].z);
gp_Trsf TheTrsf ;
if(HasLocation())
TheTrsf = Location().Transformation();
if(TheTrsf.Form()!=gp_Identity){
P1.Transform(TheTrsf);
P2.Transform(TheTrsf);
P3.Transform(TheTrsf);
}
Standard_Real prof(Precision::Infinite());
// formule calcul du parametre du point sur l'intersection
// t = (P1P2 ^P1P3)* OP1 / ((P1P2^P1P3)*Dir)
gp_Pnt Oye = EyeLine.Location(); // origine de la ligne oeil/point vise...
gp_Dir Dir = EyeLine.Direction();
gp_Vec P1P2 (P1,P2), P1P3(P1,P3);
P1P2.Normalize();
P1P3.Normalize();
gp_Vec oP1(Oye,P1);
Standard_Real val1 = oP1.DotCross(P1P2,P1P3);
Standard_Real val2 = Dir.DotCross(P1P2,P1P3);
if(Abs(val2)>Precision::Confusion())
prof =val1/val2;
if (prof==Precision::Infinite()){
prof= ElCLib::Parameter(EyeLine,P1);
prof = Min (prof, ElCLib::Parameter(EyeLine,P2));
prof = Min (prof, ElCLib::Parameter(EyeLine,P3));
}
return prof;
}

View File

@@ -0,0 +1,184 @@
-- File: Select3D_SensitiveTriangulation.cdl
-- Created: Thu May 15 15:05:37 1997
-- Author: Robert COUBLANC
-- <rob@robox.paris1.matra-dtv.fr>
---Copyright: Matra Datavision 1997
class SensitiveTriangulation from Select3D
inherits SensitiveEntity from Select3D
---Purpose: A framework to define selection of a sensitive entity made of a set of triangles.
uses
EntityOwner from SelectBasics,
Projector from Select3D,
Lin from gp,
Trsf from gp,
ListOfBox2d from SelectBasics,
Array1OfPnt from TColgp,
Array1OfPnt2d from TColgp,
HArray1OfInteger from TColStd,
Box2d from Bnd,
SensitiveTriangle from Select3D,
ListOfSensitiveTriangle from Select3D,
XYZ from gp,
XY from gp,
Pnt from gp,
Pnt2d from gp,
Triangulation from Poly,
Location from TopLoc
is
Create(OwnerId : EntityOwner from SelectBasics;
aTriangulation: Triangulation from Poly;
aLoc : Location from TopLoc;
InteriorFlag : Boolean from Standard = Standard_True)
returns mutable SensitiveTriangulation from Select3D;
---Purpose: Constructs a sensitive triangulation object defined by
-- the owner OwnerId, the triangulation aTriangulation,
-- the location aLoc, and the flag InteriorFlag.
Create(OwnerId : EntityOwner from SelectBasics;
aTriangulation: Triangulation from Poly;
aLoc : Location from TopLoc;
thefreeedges : HArray1OfInteger from TColStd;
theCDG : Pnt from gp;
InteriorFlag : Boolean from Standard)
returns mutable SensitiveTriangulation from Select3D;
---Purpose: Constructs a sensitive triangulation object defined by
-- the owner OwnerId, the triangulation aTriangulation,
-- the location aLoc, the array of free edges
-- thefreeedges, the center of gravity theCDG, and the flag InteriorFlag.
-- As free edges and the center of gravity do not have
-- to be computed later, this syntax reduces computation time.
Project (me:mutable;aProjector : Projector from Select3D) is redefined static;
---Level: Public
---Purpose: projection of the sensitive primitive in order to
-- get 2D boxes for the Sort Algorithm
Areas (me:mutable ; boxes : in out ListOfBox2d from SelectBasics) is redefined static;
---Level: Public
---Purpose: stores in <boxes> the 2D Boxes which represent the sensitive face
-- in the selection algorithm.
GetConnected(me:mutable;aLocation: Location from TopLoc)
returns SensitiveEntity from Select3D is redefined static;
Matches(me :mutable;
X,Y : Real from Standard;
aTol: Real from Standard;
DMin: out Real from Standard)
returns Boolean
is redefined virtual;
Matches (me :mutable;
XMin,YMin,XMax,YMax : Real from Standard;
aTol: Real from Standard)
returns Boolean
is redefined virtual;
---Level: Public
Matches (me :mutable;
Polyline:Array1OfPnt2d from TColgp;
aBox:Box2d from Bnd;
aTol: Real from Standard)
returns Boolean
is redefined virtual;
---Level: Public
ComputeDepth(me;EyeLine: Lin from gp)
returns Real from Standard is redefined static;
---Purpose: give the depht of the last detected triangle
-- (center of gravity)
DetectedTriangle(me) returns Integer from Standard;
---Purpose: Returns the detected three nodes P1, P2, P3 constituting a triangle.
-- This triangle is a component of the overall sensitive
-- triangulation created at construction time.
---C++: inline
Triangulation(me) returns any Triangulation from Poly;
---Purpose: Returns the triangulation used at the time of construction.
---C++: inline
---C++: return const &
CDG3D(me) returns Pnt from gp;
---Purpose: Returns the 3D center of gravity used at the time of construction.
---C++: inline
---C++: return const &
CDG2D(me) returns Pnt2d from gp;
---Purpose: Returns the 2D center of gravity used at the time of construction.
---C++: inline
---C++: return const &
IsFree(me;
IndexOfTriangle : Integer from Standard;
IndexinFree : out Integer from Standard)
returns Boolean is static private;
Status (me;
p0,p1,p2: XY from gp ;
aPoint : XY from gp ;
aTol : Real from Standard;
Dmin : out Real from Standard) returns Integer from Standard;
---Purpose: Dmin gives the distance between the cdg and aPoint
---Category: TheLocations....
HasInitLocation(me) returns Boolean from Standard;
---C++: inline
GetInitLocation(me) returns Location from TopLoc;
---C++: inline
---C++: return const &
ResetLocation(me:mutable) is redefined virtual;
SetLocation(me:mutable;aLoc :Location from TopLoc) is redefined virtual;
Dump(me; S: in out OStream;FullDump : Boolean from Standard = Standard_True) is redefined virtual;
DetectedTriangle(me;P1,P2,P3 : out Pnt from gp)
returns Boolean from Standard;
---Purpose: gives the vertices of detected triangle...
DetectedTriangle2d(me;P1,P2,P3 : out Pnt2d from gp)
returns Boolean from Standard;
---Purpose: Gets 2D nodes computed by entity using 3D nodes and viewer
-- parameters (see Project() method)
ComputeTotalTrsf(me:mutable) is static private;
fields
myTriangul : Triangulation from Poly;
myiniloc : Location from TopLoc;
myTrsf : Trsf from gp;
myCDG3D : Pnt from gp;
myFreeEdges: HArray1OfInteger from TColStd;
myIntFlag : Boolean from Standard;
myNodes2d : Array1OfPnt2d from TColgp;
myCDG2D : Pnt2d from gp;
mybox2d : Box2d from Bnd;
myDetectedTr: Integer from Standard;
end SensitiveTriangulation;

View File

@@ -0,0 +1,676 @@
// File: Select3D_SensitiveTriangulation.cxx
// Created: Thu May 15 17:47:05 1997
// Author: Robert COUBLANC
// <rob@robox.paris1.matra-dtv.fr>
//Modified Thur Apr 09 98 by rob : No more computation of free edges.
// fix bug on Compute Depth (don't forget
// Location...)
#define BUC60858 //GG 27/03/01 Avoid to crash when selecting
// a triangle containing confused or aligned points.
#include <Select3D_SensitiveTriangulation.ixx>
#include <gp_Pnt2d.hxx>
#include <Poly_Connect.hxx>
#include <CSLib_Class2d.hxx>
#include <TColStd_Array1OfInteger.hxx>
#include <Select3D_SensitiveTriangle.hxx>
#include <Precision.hxx>
#include <ElCLib.hxx>
#include <CSLib_Class2d.hxx>
static Standard_Integer S3D_NumberOfFreeEdges(const Handle(Poly_Triangulation)& Trg)
{
Standard_Integer nFree = 0;
Poly_Connect pc(Trg);
Standard_Integer t[3];
Standard_Integer i,j;
for (i = 1; i <= Trg->NbTriangles(); i++) {
pc.Triangles(i,t[0],t[1],t[2]);
for (j = 0; j < 3; j++)
if (t[j] == 0) nFree++;
}
return nFree;
}
static Standard_Boolean S3D_STriangul_NearSegment (const gp_XY& p0, const gp_XY& p1, const gp_XY& TheP,
const Standard_Real aTol, Standard_Real& aDMin)
{
Bnd_Box2d B;
B.SetVoid();
B.Set(p0);
B.Update(p1.X(),p1.Y());
B.Enlarge(aTol*3);
if(B.IsOut(TheP)) return Standard_False;
gp_XY V01(p1);V01-=p0;
gp_XY Vec(TheP);Vec -= p0;
Standard_Real u = Vec*V01.Normalized();
if(u<-aTol) return Standard_False;
Standard_Real u1 = u-aTol;
Standard_Real modmod = V01.SquareModulus();
if(u1*u1> modmod) return Standard_False;
gp_XY N01 (-V01.Y(),V01.X());
N01.Normalize();
aDMin = Abs (Vec * N01);
return aDMin <= aTol;
}
// static Standard_Real S3D_SquareDistanceFromEdge(gp_Pnt2d PCur,
// gp_Pnt2d PEdg1,
// gp_Pnt2d PEdg2,
// const Standard_Real TolTol)
// {
// gp_XY VEdg (PEdg1.XY());
// gp_XY VCur (PEdg1.XY());
// VEdg-= PEdg2.XY();
// VCur-=PCur.XY();
// Standard_Real long1 = VEdg.SquareModulus();
// if(long1<=TolTol)
// return VCur.SquareModulus();
// Standard_Real Val = VEdg^VCur;
// return Val*Val/long1;
// }
static Standard_Boolean S3D_IsEdgeIn(const Standard_Integer e1,
const Standard_Integer e2,
const Standard_Integer N1,
const Standard_Integer N2,
const Standard_Integer N3)
{
Standard_Integer bid1 = (e1 == N1) ? N1 : ((e1 == N2) ? N2 : ( e1==N3 ? N3 : 0));
if(bid1==0) return Standard_False;
Standard_Integer bid2 = (e2 == N1) ? N1 : ((e2 == N2) ? N2 : ( e2==N3 ? N3 : 0));
if(bid2==0 || bid2 ==bid1) return Standard_False;
return Standard_True;
}
//=======================================================================
//function : Select3D_SensitiveTriangulation
//purpose :
//=======================================================================
Select3D_SensitiveTriangulation::
Select3D_SensitiveTriangulation(const Handle(SelectBasics_EntityOwner)& OwnerId,
const Handle(Poly_Triangulation)& Trg,
const TopLoc_Location& Loc,
const Standard_Boolean InteriorFlag):
Select3D_SensitiveEntity(OwnerId),
myTriangul(Trg),
myiniloc(Loc),
myIntFlag(InteriorFlag),
myNodes2d(1,Trg->NbNodes()),
myDetectedTr(-1)
{
// Code honteusement vole a DBRep_DrawableShape::Display...
// calcul des edges libres et du cdg 3d de la triangulation:
// Ce code devrait, pour plus de facilites etre integre dans la poly_triangulation...
Standard_Integer fr = 1;
const Poly_Array1OfTriangle& triangles = myTriangul->Triangles();
const TColgp_Array1OfPnt& Nodes = myTriangul->Nodes();
Standard_Integer nbTriangles (myTriangul->NbTriangles());
gp_XYZ cdg(0,0,0);
Standard_Integer n[3];
// pour rechercher les connexions dans le cas ou on ne s'occupe de la frontiere...
if(!myIntFlag){
myFreeEdges = new TColStd_HArray1OfInteger(1,2*S3D_NumberOfFreeEdges(Trg));
TColStd_Array1OfInteger& FreeE = myFreeEdges->ChangeArray1();
Poly_Connect pc(myTriangul);
Standard_Integer t[3];
Standard_Integer i,j;
for ( i = 1; i <= nbTriangles; i++) {
pc.Triangles(i,t[0],t[1],t[2]);
triangles(i).Get(n[0],n[1],n[2]);
cdg += (Nodes(n[0]).XYZ() + Nodes(n[1]).XYZ()+ Nodes(n[2]).XYZ())/3.;
for (j = 0; j < 3; j++) {
Standard_Integer k = (j+1) % 3;
if (t[j] == 0) {
FreeE(fr) = n[j];
FreeE(fr+1)= n[k];
fr += 2;
}
}
}
}
else{
for (Standard_Integer i = 1; i <= nbTriangles; i++) {
triangles(i).Get(n[0],n[1],n[2]);
cdg += (Nodes(n[0]).XYZ() + Nodes(n[1]).XYZ()+ Nodes(n[2]).XYZ())/3.;
}
}
if(nbTriangles!=0) cdg /= nbTriangles;
myCDG3D = gp_Pnt(cdg);
ComputeTotalTrsf();
if(myTrsf.Form()!=gp_Identity)
myCDG3D.Transform(myTrsf);
}
//=======================================================================
//function : Select3D_SensitiveTriangulation
//purpose :
//=======================================================================
Select3D_SensitiveTriangulation::
Select3D_SensitiveTriangulation(const Handle(SelectBasics_EntityOwner)& OwnerId,
const Handle(Poly_Triangulation)& Trg,
const TopLoc_Location& Loc,
const Handle(TColStd_HArray1OfInteger)& FreeEdges,
const gp_Pnt& TheCDG,
const Standard_Boolean InteriorFlag):
Select3D_SensitiveEntity(OwnerId),
myTriangul(Trg),
myiniloc(Loc),
myCDG3D(TheCDG),
myFreeEdges(FreeEdges),
myIntFlag(InteriorFlag),
myNodes2d(1,Trg->NbNodes()),
myDetectedTr(-1)
{
}
//=======================================================================
//function : Project
//purpose :
//=======================================================================
void Select3D_SensitiveTriangulation::Project(const Select3D_Projector& aPrj)
{
Select3D_SensitiveEntity::Project(aPrj); // to set the field last proj...
mybox2d.SetVoid();
const TColgp_Array1OfPnt& Nodes = myTriangul->Nodes();
gp_Pnt2d ProjPT;
for(Standard_Integer I=1;I<=myTriangul->NbNodes();I++){
if(myTrsf.Form()!=gp_Identity)
aPrj.Project(Nodes(I).Transformed(myTrsf),ProjPT);
else
aPrj.Project(Nodes(I),ProjPT);
myNodes2d.SetValue(I,ProjPT);
mybox2d.Add(ProjPT);
}
aPrj.Project(myCDG3D,myCDG2D);
}
//=======================================================================
//function : Areas
//purpose :
//=======================================================================
void Select3D_SensitiveTriangulation::Areas(SelectBasics_ListOfBox2d& boxes)
{
boxes.Append(mybox2d);
}
//=======================================================================
//function : getUV
//purpose : compute parameters of the picked point on triangle in 2d
// Note: parameters of point P on triangle (P1, P2, P3) are defined
// as U and V such that P = P1 + U * (P2 - P1) + V * (P3 - P1);
// Range: U >= 0, V >= 0, U + V <= 1
//=======================================================================
static gp_XY getUV (const gp_XY& aP2d1, const gp_XY& aP2d2, const gp_XY& aP2d3,
const gp_XY& aPick)
{
gp_XY aDU = aP2d2 - aP2d1;
gp_XY aDV = aP2d3 - aP2d1;
Standard_Real aDet = aDU ^ aDV;
// case of non-degenerated triangle
gp_XY aDP = aPick - aP2d1;
if ( Abs (aDet) > gp::Resolution() )
{
Standard_Real aU = (aDP ^ aDV) / aDet;
Standard_Real aV = -(aDP ^ aDU) / aDet;
if ( aU < 0. ) aU = 0.;
if ( aV < 0. ) aV = 0.;
if ( aU + aV > 1. ) { Standard_Real aD = aU + aV; aU /= aD; aV /= aD; }
return gp_XY (aU, aV);
}
// degenerated case (in 2d projection)
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
return gp_XY (0., 0.);
else
return gp_XY (0., (aDP * aDV) / aL2V);
}
else if ( aL2V < gp::Resolution() ) // side 1-3 is degenerated
return gp_XY ((aDP * aDU) / aL2U, 0.);
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));
gp_XY aP2dU = aP2d1 + aU * aDU;
gp_XY aP2dV = aP2d1 + aV * aDV;
if ( (aPick - aP2dU).SquareModulus() < (aPick - aP2dV).SquareModulus() )
return gp_XY ((aDP * aDU) / aL2U, 0.);
else
return gp_XY (0., (aDP * aDV) / aL2V);
}
}
//=======================================================================
//function : Matches
//purpose :
//=======================================================================
Standard_Boolean Select3D_SensitiveTriangulation::Matches(const Standard_Real X,
const Standard_Real Y,
const Standard_Real aTol,
Standard_Real& DMin)
{
// get view direction (necessary for calculation of depth) from field mylastprj of the base class
if ( ! mylastprj )
return Standard_False;
DMin = Precision::Infinite();
gp_XY BidPoint(X,Y);
myDetectedTr = -1;
const Poly_Array1OfTriangle& triangles = myTriangul->Triangles();
// on regarde si on est a l'interieur d'1 triangle 2d.
if(myIntFlag)
{
gp_Lin EyeLine = (*((Select3D_Projector*)mylastprj)).Shoot(X,Y);
if ( myTrsf.Form()!=gp_Identity )
EyeLine.Transform (myTrsf.Inverted());
Standard_Real aMinDepth = Precision::Infinite();
const TColgp_Array1OfPnt& Nodes = myTriangul->Nodes();
for (Standard_Integer itr=1; itr<=myTriangul->NbTriangles(); itr++)
{
Standard_Integer n1,n2,n3;
triangles(itr).Get(n1,n2,n3);
const gp_XY& aPnt2d1 = myNodes2d(n1).XY();
const gp_XY& aPnt2d2 = myNodes2d(n2).XY();
const gp_XY& aPnt2d3 = myNodes2d(n3).XY();
Standard_Real DD = 0.;
if (Status (BidPoint, aPnt2d1, aPnt2d2, aPnt2d3, aTol, DD) == 2)
continue;
// compute depth on this triangle
gp_XY aUV = getUV (aPnt2d1, aPnt2d2, aPnt2d3, BidPoint);
Standard_Real aDepth1 = ElCLib::Parameter (EyeLine, Nodes(n1));
Standard_Real aDepth2 = ElCLib::Parameter (EyeLine, Nodes(n2));
Standard_Real aDepth3 = ElCLib::Parameter (EyeLine, Nodes(n3));
Standard_Real aDepth = aDepth1 + aUV.X() * (aDepth2 - aDepth1) +
aUV.Y() * (aDepth3 - aDepth1);
// take triangle with lowest depth
if ( aDepth < aMinDepth )
{
aMinDepth = aDepth;
myDetectedTr = itr;
DMin = DD;
}
}
}
// Cas Uniquement Test sur Frontiere de la triangulation...
//
else
{
//Standard_Integer ifirst;
TColStd_Array1OfInteger& FreeE = myFreeEdges->ChangeArray1();
Standard_Integer nn = FreeE.Length(), Node1,Node2;
//Standard_Real LEdg;
//Standard_Real DMinDMin,TolTol = aTol*aTol;
for (Standard_Integer ifri =1; ifri <= nn && myDetectedTr < 0; ifri+=2)
{
Node1 = FreeE(ifri);
Node2 = FreeE(ifri+1);
if (S3D_STriangul_NearSegment (myNodes2d(Node1).XY(),
myNodes2d(Node2).XY(),
BidPoint, aTol, DMin) )
{
for(Standard_Integer itr=1; itr <= myTriangul->NbTriangles(); itr++)
{
Standard_Integer n1,n2,n3;
triangles(itr).Get(n1,n2,n3);
if(S3D_IsEdgeIn(Node1,Node2,n1,n2,n3))
{
myDetectedTr = itr;
break; // return first found; selection of closest is not implemented yet
}
}
}
}
}
if ( myDetectedTr <= 0 )
return Standard_False;
Select3D_SensitiveEntity::Matches(X,Y,aTol,DMin);
return Standard_True;
}
//=======================================================================
//function : Matches
//purpose :
//=======================================================================
Standard_Boolean Select3D_SensitiveTriangulation::Matches(const Standard_Real XMin,
const Standard_Real YMin,
const Standard_Real XMax,
const Standard_Real YMax,
const Standard_Real aTol)
{
Bnd_Box2d B;
B.Update(Min(XMin,XMax)-aTol,
Min(YMin,YMax)-aTol,
Max(XMin,XMax)+aTol,
Max(YMin,YMax)+aTol);
for(Standard_Integer i=myNodes2d.Lower();i<=myNodes2d.Upper();i++){
if(B.IsOut(myNodes2d(i)))
return Standard_False;
}
return Standard_True;
}
//=======================================================================
//function : Matches
//purpose :
//=======================================================================
Standard_Boolean Select3D_SensitiveTriangulation::
Matches (const TColgp_Array1OfPnt2d& aPoly,
const Bnd_Box2d& aBox,
const Standard_Real aTol)
{
Standard_Real Umin,Vmin,Umax,Vmax;
aBox.Get(Umin,Vmin,Umax,Vmax);
Standard_Real Tolu,Tolv;
Tolu = 1e-7;
Tolv = 1e-7;
CSLib_Class2d aClassifier2d(aPoly,aTol,aTol,Umin,Vmin,Umax,Vmax);
for(Standard_Integer j=1;j<=myNodes2d.Length();j++){
Standard_Integer RES = aClassifier2d.SiDans(myNodes2d(j));
if(RES!=1) return Standard_False;
}
return Standard_True;
}
Standard_Integer Select3D_SensitiveTriangulation::Status (const gp_XY& TheP,
const gp_XY& Proj0,
const gp_XY& Proj1,
const gp_XY& Proj2,
const Standard_Real aTol,
Standard_Real& DD) const
{
return Select3D_SensitiveTriangle::Status(Proj0,Proj1,Proj2,TheP,aTol,DD);
}
//=======================================================================
//function : IsFree
//purpose :
//=======================================================================
Standard_Boolean Select3D_SensitiveTriangulation::IsFree(const Standard_Integer IndexOfTriangle,
Standard_Integer& FoundIndex) const
{
FoundIndex=-1;
Standard_Integer n[3];
const Poly_Array1OfTriangle& triangles = myTriangul->Triangles();
triangles(IndexOfTriangle).Get(n[0],n[1],n[2]);
TColStd_Array1OfInteger& FreeE = myFreeEdges->ChangeArray1();
for(Standard_Integer I=1;I<=FreeE.Length() && FoundIndex==-1;I+=2){
if(FreeE(I) == n[0]){
if(FreeE(I+1)== n[1] || FreeE(I+1)== n[2]) FoundIndex=I;}
else if(FreeE(I) == n[1]){
if(FreeE(I+1)== n[0] || FreeE(I+1)== n[2]) FoundIndex=I;}
else if(FreeE(I) == n[2]){
if(FreeE(I+1)== n[0] || FreeE(I+1)== n[1]) FoundIndex=I;}
}
return FoundIndex!=-1;
}
//=======================================================================
//function : GetConnected
//purpose :
//=======================================================================
Handle(Select3D_SensitiveEntity) Select3D_SensitiveTriangulation::
GetConnected(const TopLoc_Location& aLoc)
{
Handle(Select3D_SensitiveTriangulation) NiouEnt =
new Select3D_SensitiveTriangulation(myOwnerId,myTriangul,myiniloc,myFreeEdges,myCDG3D,myIntFlag);
if(HasLocation()) NiouEnt->SetLocation(Location());
// TopLoc_Location TheLocToApply = HasLocation() ? Location()*aLoc : aLoc;
// if(!TheLocToApply.IsIdentity())
NiouEnt->UpdateLocation(aLoc);
return NiouEnt;
}
//=======================================================================
//function : ResetLocation
//purpose :
//=======================================================================
void Select3D_SensitiveTriangulation::ResetLocation()
{
Select3D_SensitiveEntity::ResetLocation();
ComputeTotalTrsf();
}
void Select3D_SensitiveTriangulation::SetLocation(const TopLoc_Location& aLoc)
{
Select3D_SensitiveEntity::SetLocation(aLoc);
ComputeTotalTrsf();
}
//=======================================================================
//function : Dump
//purpose :
//=======================================================================
void Select3D_SensitiveTriangulation::Dump(Standard_OStream& S,const Standard_Boolean FullDump) const
{
S<<"\tSensitiveTriangulation 3D :"<<endl;
if(myiniloc.IsIdentity())
S<<"\t\tNo Initial Location"<<endl;
else
S<<"\t\tExisting Initial Location"<<endl;
if(HasLocation())
S<<"\t\tExisting Location"<<endl;
S<<"\t\tNb Triangles : "<<myTriangul->NbTriangles()<<endl;
S<<"\t\tNb Nodes : "<<myTriangul->NbNodes()<<endl;
S<<"\t\tNb Free Edges: "<<myFreeEdges->Length()/2<<endl;
if(FullDump){
// S<<"\t\t\tOwner:"<<myOwnerId<<endl;
Select3D_SensitiveEntity::DumpBox(S,mybox2d);
}
}
//=======================================================================
//function : ComputeDepth
//purpose :
//=======================================================================
Standard_Real Select3D_SensitiveTriangulation::ComputeDepth(const gp_Lin& EyeLine) const
{
if(myDetectedTr==-1) return Precision::Infinite(); // non implemente actuellement...
const Poly_Array1OfTriangle& triangles = myTriangul->Triangles();
const TColgp_Array1OfPnt& Nodes = myTriangul->Nodes();
Standard_Integer n1,n2,n3;
triangles(myDetectedTr).Get(n1,n2,n3);
gp_Pnt P[3]={Nodes(n1),Nodes(n2),Nodes(n3)};
if(myTrsf.Form()!=gp_Identity){
for(Standard_Integer i =0;i<=2;i++){
P[i].Transform(myTrsf);
}
}
// formule calcul du parametre du point sur l'intersection
// t = (P1P2 ^P1P3)* OP1 / ((P1P2^P1P3)*Dir)
Standard_Real prof(Precision::Infinite());
gp_Pnt Oye = EyeLine.Location(); // origine de la ligne oeil/point vise...
gp_Dir Dir = EyeLine.Direction();
gp_Vec Vtr[3];
for(Standard_Integer i=0;i<=2;i++)
Vtr[i] = gp_Vec(P[i%3],P[(i+1)%3]);
Vtr[2] = -Vtr[2];
// eliminons tout de suite les cas singuliers...
Standard_Integer SingularCase(-1);
if(Vtr[0].SquareMagnitude()<= Precision::Confusion())
SingularCase = 0;
if(Vtr[1].SquareMagnitude()<= Precision::Confusion())
SingularCase = (SingularCase == -1) ? 1 : 2;
#ifdef BUC60858
if(Vtr[2].SquareMagnitude()<= Precision::Confusion())
if( SingularCase < 0 ) SingularCase = 1;
#endif
// 3 pts confondus...
if(SingularCase ==2){
prof= ElCLib::Parameter(EyeLine,P[0]);
return prof;
}
if(SingularCase!=0)
Vtr[0].Normalize();
if(SingularCase!=1 &&
SingularCase!=2)
Vtr[2].Normalize();
gp_Vec OPo(Oye,P[0]);
// 2 points confondus... on recherche l'intersection entre le segment et la ligne oeil/point vise.
//
if(SingularCase!=-1){
gp_Vec V = SingularCase==0 ? Vtr[2] : Vtr[0];
gp_Vec Det = Dir^V;
gp_Vec VSM = OPo^V;
if(Det.X()> Precision::Confusion())
prof = VSM.X()/Det.X();
else if (Det.Y()> Precision::Confusion())
prof = VSM.Y()/Det.Y();
else if(Det.Z()> Precision::Confusion())
prof = VSM.Z()/Det.Z();
}
else{
Standard_Real val1 = OPo.DotCross(Vtr[0],Vtr[2]);
Standard_Real val2 = Dir.DotCross(Vtr[0],Vtr[2]);
if(Abs(val2)>Precision::Confusion())
prof =val1/val2;
}
if (prof==Precision::Infinite()){
prof= ElCLib::Parameter(EyeLine,P[0]);
prof = Min (prof, ElCLib::Parameter(EyeLine,P[1]));
prof = Min (prof, ElCLib::Parameter(EyeLine,P[2]));
}
return prof;
}
//=======================================================================
//function : DetectedTriangle
//purpose :
//=======================================================================
Standard_Boolean Select3D_SensitiveTriangulation::DetectedTriangle(gp_Pnt& P1,
gp_Pnt& P2,
gp_Pnt& P3) const
{
if(myDetectedTr==-1) return Standard_False; // non implemente actuellement...
const Poly_Array1OfTriangle& triangles = myTriangul->Triangles();
const TColgp_Array1OfPnt& Nodes = myTriangul->Nodes();
Standard_Integer n1,n2,n3;
triangles(myDetectedTr).Get(n1,n2,n3);
P1 = Nodes(n1);
P2 = Nodes(n2);
P3 = Nodes(n3);
if(myTrsf.Form()!=gp_Identity){
P1.Transform(myTrsf);
P2.Transform(myTrsf);
P3.Transform(myTrsf);
}
return Standard_True;
}
//=============================================================================
// Function : DetectedTriangle2d
// Purpose :
//=============================================================================
Standard_Boolean Select3D_SensitiveTriangulation::DetectedTriangle2d(
gp_Pnt2d& P1, gp_Pnt2d& P2, gp_Pnt2d& P3) const
{
if(myDetectedTr==-1)
return Standard_False; // non implemente actuellement...
const Poly_Array1OfTriangle& triangles = myTriangul->Triangles();
const TColgp_Array1OfPnt& Nodes = myTriangul->Nodes();
Standard_Integer n1,n2,n3;
triangles( myDetectedTr ).Get(n1,n2,n3);
int aLower = myNodes2d.Lower();
int anUpper = myNodes2d.Upper();
if ( n1 >= aLower && n1 <= anUpper &&
n2 >= aLower && n2 <= anUpper &&
n3 >= aLower && n3 <= anUpper )
{
P1 = myNodes2d.Value( n1 );
P2 = myNodes2d.Value( n2 );
P3 = myNodes2d.Value( n3 );
return Standard_True;
}
else
return Standard_False;
}
void Select3D_SensitiveTriangulation::ComputeTotalTrsf()
{
Standard_Boolean hasloc = (HasLocation() || !myiniloc.IsIdentity());
if(hasloc){
if(myiniloc.IsIdentity())
myTrsf = Location().Transformation();
else if(HasLocation()){
myTrsf = (Location()*myiniloc).Transformation();
}
else
myTrsf = myiniloc.Transformation();
}
else{
gp_Trsf TheId;
myTrsf = TheId;
}
}

View File

@@ -0,0 +1,25 @@
// File: Select3D_SensitiveTriangulation.lxx
// Created: Thu May 15 17:48:58 1997
// Author: Robert COUBLANC
// <rob@robox.paris1.matra-dtv.fr>
inline const Handle(Poly_Triangulation)& Select3D_SensitiveTriangulation::Triangulation() const
{
return myTriangul;
}
inline const gp_Pnt& Select3D_SensitiveTriangulation::CDG3D() const
{
return myCDG3D;
}
inline const gp_Pnt2d& Select3D_SensitiveTriangulation::CDG2D() const
{
return myCDG2D;
}
inline Standard_Boolean Select3D_SensitiveTriangulation::HasInitLocation() const
{return !myiniloc.IsIdentity();}
inline const TopLoc_Location& Select3D_SensitiveTriangulation::GetInitLocation() const
{return myiniloc;}

View File

@@ -0,0 +1,118 @@
-- File: Select3D_SensitiveWire.cdl
-- Created: Thu Oct 17 10:19:25 1996
-- Author: Odile OLIVIER
-- <odl@sacadox.paris1.matra-dtv.fr>
---Copyright: Matra Datavision 1996
class SensitiveWire from Select3D
inherits SensitiveEntity from Select3D
---Purpose: A framework to define selection of a wire owner by an
-- elastic wire band.
uses
Pnt from gp,
Projector from Select3D,
Lin from gp,
EntityOwner from SelectBasics,
SensitiveEntity from Select3D,
SensitiveEntitySequence from Select3D,
ListOfBox2d from SelectBasics,
Array1OfPnt2d from TColgp,
Box2d from Bnd,
Location from TopLoc
is
Create (OwnerId : EntityOwner from SelectBasics;
MaxRect : Integer = 1)
returns mutable SensitiveWire;
---Purpose: Constructs a sensitive wire object defined by the
-- owner OwnerId, and the maximum number of
-- sensitive rectangles MaxRect.
Add (me :mutable;aSensitive : SensitiveEntity from Select3D)
is static;
---Purpose: Adds the sensitive entity aSensitive to this framework.
Project (me:mutable;aProjector : Projector from Select3D)
is redefined static;
---Level: Public
---Purpose: projection of the sensitive primitive in order to
-- get 2D boxes for the Sort Algorithm
Areas (me:mutable ; boxes : in out ListOfBox2d from SelectBasics)
is redefined static;
---Level: Public
---Purpose: gives the 2D boxes which represent the segment in the
-- selection process...
GetConnected(me:mutable;aLocation: Location from TopLoc)
returns SensitiveEntity from Select3D is redefined static;
GetEdges(me : mutable;
theEdges : in out SensitiveEntitySequence from Select3D);
---Level: Public
---Purpose: returns the sensitive edges stored in this wire
SetLocation(me:mutable;aLoc:Location from TopLoc) is redefined static;
---Purpose: propagation of location on all the sensitive inside...
ResetLocation(me:mutable) is redefined static;
---Purpose: propagation of location on all the sensitive inside...
Matches(me :mutable;
X,Y : Real from Standard;
aTol: Real from Standard;
DMin: out Real from Standard)
returns Boolean
is redefined static;
---Level: Public
---Purpose: projection of the sensitive primitive in order to
-- get 2D boxes for the Sort Algorithm
Matches (me :mutable;
XMin,YMin,XMax,YMax : Real from Standard;
aTol: Real from Standard)
returns Boolean
is static;
Matches (me :mutable;
Polyline:Array1OfPnt2d from TColgp;
aBox:Box2d from Bnd;
aTol: Real from Standard)
returns Boolean
is redefined virtual;
---Level: Public
ComputeDepth(me;EyeLine: Lin from gp)
returns Real from Standard is redefined static;
---Purpose: returns the depth of the touched entity
MaxBoxes(me) returns Integer is redefined static;
---Level: Public
---Purpose:returns <mymaxrect>
Dump(me; S: in out OStream;FullDump : Boolean from Standard = Standard_True) is redefined virtual;
SetLastPrj(me:mutable;aPrj: Projector from Select3D) is redefined virtual;
GetLastDetected(me)
returns SensitiveEntity from Select3D is static;
---Purpose:returns <mymaxrect>
fields
mymaxrect : Integer;
mysensitive : SensitiveEntitySequence from Select3D;
myDetectedIndex : Integer from Standard;
end SensitiveWire;

View File

@@ -0,0 +1,286 @@
// File: Select3D_SensitiveWire.cxx
// Created: Thu Oct 17 10:19:25 1996
// Author: Odile OLIVIER
// <odl@sacadox.paris1.matra-dtv.fr>
//Copyright: Matra Datavision 1996
#include <Select3D_SensitiveWire.ixx>
#include <SelectBasics_BasicTool.hxx>
#include <Select3D_SensitiveEntity.hxx>
#include <Select3D_SensitiveEntitySequence.hxx>
#include <SelectBasics_ListIteratorOfListOfBox2d.hxx>
#include <SelectBasics_ListOfBox2d.hxx>
#include <Precision.hxx>
#include <Bnd_Box2d.hxx>
#include <ElCLib.hxx>
//static Standard_Boolean debugmode=Standard_False;
//=====================================================
// Function : Create
// Purpose :Constructor
//=====================================================
Select3D_SensitiveWire::
Select3D_SensitiveWire(const Handle(SelectBasics_EntityOwner)& OwnerId,
const Standard_Integer MaxRect):
Select3D_SensitiveEntity(OwnerId),
mymaxrect(MaxRect),
myDetectedIndex(-1)
{}
//=====================================================
// Function : Add
// Purpose :
//=====================================================
void Select3D_SensitiveWire
::Add(const Handle(Select3D_SensitiveEntity)& aSensitive)
{
if ( !aSensitive .IsNull()) {
if(!HasLocation())
mysensitive.Append(aSensitive);
else
mysensitive.Append(aSensitive->GetConnected(Location()));
}
}
//=======================================================================
//function : SetLocation
//purpose :
//=======================================================================
void Select3D_SensitiveWire::SetLocation(const TopLoc_Location& aLoc)
{
// evitons les problemes...
if(aLoc.IsIdentity()) return;
if(HasLocation())
if(aLoc == Location()) return;
Select3D_SensitiveEntity::SetLocation(aLoc);
for(Standard_Integer i=1;i<=mysensitive.Length();i++){
if(mysensitive(i)->HasLocation()){
if(mysensitive(i)->Location()!=aLoc)
mysensitive(i)->SetLocation(mysensitive(i)->Location()*aLoc);
}
else
mysensitive(i)->SetLocation(aLoc);
}
}
//=======================================================================
//function : ResetLocation
//purpose :
//=======================================================================
void Select3D_SensitiveWire::ResetLocation()
{
if(!HasLocation()) return;
for(Standard_Integer i=1;i<=mysensitive.Length();i++){
if(mysensitive(i)->HasLocation() && mysensitive(i)->Location()!=Location())
mysensitive(i)->SetLocation(mysensitive(i)->Location()*Location().Inverted());
else
mysensitive(i)->ResetLocation();
}
Select3D_SensitiveEntity::ResetLocation();
}
//=====================================================
// Function : Project
// Purpose :
//=====================================================
void Select3D_SensitiveWire
::Project(const Select3D_Projector& aProj)
{
for ( Standard_Integer i=1; i<=mysensitive.Length(); i++)
mysensitive(i)->Project(aProj);
Select3D_SensitiveEntity::Project(aProj);
}
//=====================================================
// Function : Areas
// Purpose :
//=====================================================
void Select3D_SensitiveWire
::Areas(SelectBasics_ListOfBox2d& theareas)
{
Bnd_Box2d BB; // en attendant un nouveau champ rob-18-jun-97
SelectBasics_ListOfBox2d BidL;
Standard_Integer i;
for (i=1; i<=mysensitive.Length(); i++)
mysensitive.Value(i)->Areas(BidL);
for(SelectBasics_ListIteratorOfListOfBox2d it(BidL);it.More();it.Next())
BB.Add(it.Value());
theareas.Append(BB);
}
//=====================================================
// Function : Matches
// Purpose :
//=====================================================
Standard_Boolean Select3D_SensitiveWire
::Matches(const Standard_Real X,
const Standard_Real Y,
const Standard_Real aTol,
Standard_Real& DMin)
{
Standard_Integer i;
Standard_Real Dcur;
DMin = Precision::Infinite();
Standard_Boolean IsTouched = Standard_False;
for (i=1; i<=mysensitive.Length(); i++) {
if (mysensitive.Value(i)->Matches(X,Y,aTol,Dcur)) {
IsTouched = Standard_True;
if(Dcur<=DMin){
myDetectedIndex = i;
DMin = Dcur;
}
}
}
// Select3D_SensitiveEntity::Matches(X,Y,aTol,DMin);
return IsTouched;
}
//=====================================================
// Function : Matches
// Purpose :
//=====================================================
Standard_Boolean Select3D_SensitiveWire::
Matches (const Standard_Real XMin,
const Standard_Real YMin,
const Standard_Real XMax,
const Standard_Real YMax,
const Standard_Real aTol)
{
Standard_Integer i;
for (i=1; i<=mysensitive.Length(); i++) {
if (!(mysensitive.Value(i)->Matches(XMin,YMin,XMax,YMax,aTol)))
return Standard_False;
}
return Standard_True;
}
//=======================================================================
//function : Matches
//purpose :
//=======================================================================
Standard_Boolean Select3D_SensitiveWire::
Matches (const TColgp_Array1OfPnt2d& aPoly,
const Bnd_Box2d& aBox,
const Standard_Real aTol)
{
Standard_Integer i;
for (i=1; i<=mysensitive.Length(); i++) {
if (!(mysensitive.Value(i)->Matches(aPoly, aBox, aTol)))
return Standard_False;
}
return Standard_True;
}
//=====================================================
// Function : MaxBoxes
// Purpose :
//=====================================================
Standard_Integer Select3D_SensitiveWire::
MaxBoxes () const
{
return 1;
}
//=======================================================================
//function : GetConnected
//purpose :
//=======================================================================
Handle(Select3D_SensitiveEntity) Select3D_SensitiveWire::GetConnected(const TopLoc_Location& aLoc)
{
Handle(Select3D_SensitiveWire) SWIR = new Select3D_SensitiveWire(myOwnerId);
for(Standard_Integer i=1;i<=mysensitive.Length();i++)
SWIR->Add(mysensitive(i));
if(HasLocation())
SWIR->SetLocation(Location()*aLoc);
else
SWIR->SetLocation(aLoc);
return SWIR;
}
//=======================================================================
//function : Dump
//purpose :
//=======================================================================
void Select3D_SensitiveWire::Dump(Standard_OStream& S,const Standard_Boolean FullDump) const
{
S<<"\tSensitiveWire 3D :"<<endl;;
if(HasLocation())
S<<"\t\tExisting Location"<<endl;
S<<"\t\tComposed Of "<<mysensitive.Length()<<" Sensitive Entities"<<endl;
for(Standard_Integer i=1;i<= mysensitive.Length();i++){
S<<"Sensitive #"<<i<<" : "<<endl;
mysensitive(i)->Dump(S,FullDump);}
S<<"\tEnd Of Sensitive Wire"<<endl;
}
//=======================================================================
//function : ComputeDepth
//purpose :
//=======================================================================
Standard_Real Select3D_SensitiveWire::ComputeDepth(const gp_Lin& EyeLine) const
{
if(myDetectedIndex==-1)
// should be never called...
return Precision::Infinite();
return mysensitive(myDetectedIndex)->ComputeDepth(EyeLine);
}
//=======================================================================
//function : SetLastPrj
//purpose :
//=======================================================================
void Select3D_SensitiveWire::SetLastPrj(const Select3D_Projector& Prj)
{
Select3D_SensitiveEntity::SetLastPrj(Prj);
for(Standard_Integer i=1;i<=mysensitive.Length();i++)
mysensitive(i)->SetLastPrj(Prj);
}
//=======================================================================
//function : GetEdges
//purpose : returns the sensitive edges stored in this wire
//=======================================================================
void Select3D_SensitiveWire::GetEdges( Select3D_SensitiveEntitySequence& theEdges )
{
theEdges.Clear();
theEdges.Append(mysensitive);
}
//=============================================================================
// Function : GetLastDetected
// Purpose :
//=============================================================================
Handle(Select3D_SensitiveEntity) Select3D_SensitiveWire::GetLastDetected() const
{
Handle(Select3D_SensitiveEntity) aRes;
if ( myDetectedIndex >= 1 && myDetectedIndex <= mysensitive.Length() )
aRes = mysensitive.Value( myDetectedIndex );
return aRes;
}