For all issues regarding the Forums use, please, refer to the Forum Rules.

Our Solutions

Need professional assistance?
Consider our:

Support Offerings

 

Need to speed up your development?
Have a look at our:

Samples & Tools

 

Need some functionality extending standard OCCT capabilities?
Check out our:

Adv. Components

Related pages

3d Point with attached text

MAIRE's picture
Forums: 

Hello everybody,

I have 2 problems to resolve with Cascade :
- how can I display a 3d point and attach a text to it.
- when I'm picking with mouse in the viewer, how can I get the coordinates of picking point (in world coordinates).

best regards.
thm

David Jorge's picture

Hi,
Have a look at the example/class CASCADE\samples\standard\mfc\01_Geometry\src\ISession2D\ISession_Text.cpp.

Second question:
world coordinates !!! Don't know!!

---Open a local context on VERTEX's---
//expecting a click on a vertice
pDoc->GetAISContext()->Select();
pDoc->GetAISContext()->InitSelected();
TopoDS_Shape aShape = pDoc->GetAISContext()->SelectedShape();
pDoc->GetAISContext()->CloseLocalContext();
TopoDS_Vertex aVertex = TopoDS::Vertex(aShape);

//print the coordinates on screen
TopoDS_Vertex v;
gp_Pnt pt;
v= TopoDS::Vertex(aVertex);
pt = BRep_Tool::Pnt(v);

char aText[10];
sprintf(aText,"(%g,%g,%g)",pt.X(),pt.Y(),pt.Z());

Handle(ISession_Text) aGraphicText = new ISession_Text(aText,pt);
aGraphicText->SetScale(0.1);
pDoc->GetAISContext()->Display(aGraphicText,TRUE);

//close local context
pDoc->GetAISContext()->ClearCurrents();

Regards,
David

Stephane Routelous's picture

to get the 3d coodinates of a picked point , use :
gp_Pnt ConvertClickToPoint(Standard_Real x, Standard_Real y, Handle(V3d_View) aView)
{
V3d_Coordinate XEye,YEye,ZEye,XAt,YAt,ZAt;
aView->Eye(XEye,YEye,ZEye);
aView->At(XAt,YAt,ZAt);
gp_Pnt EyePoint(XEye,YEye,ZEye);
gp_Pnt AtPoint(XAt,YAt,ZAt);

gp_Vec EyeVector(EyePoint,AtPoint);
gp_Dir EyeDir(EyeVector);

gp_Pln PlaneOfTheView = gp_Pln(AtPoint,EyeDir);
Standard_Real X,Y,Z;
aView->Convert((int)x,(int)y,X,Y,Z);
gp_Pnt ConvertedPoint(X,Y,Z);
gp_Pnt2d ConvertedPointOnPlane = ProjLib::Project(PlaneOfTheView,ConvertedPoint);

gp_Pnt ResultPoint = ElSLib::Value(ConvertedPointOnPlane.X(),
ConvertedPointOnPlane.Y(),
PlaneOfTheView);
return ResultPoint;
}

HTH