
Fri, 12/03/2010 - 16:44
Forums:
Hello,
I need some informations (Material,Position,Radius,Height) of the object (cylinder) which is displayed in my context.
It's no problem to get the material:
myAISContext->DisplayedObjects(objList);
objList.First()->Material();
But I dont know how to get the Position, Radius and Height of my cylinder. Is it possible to derive these information from an AIS_InteractiveObject (objList.First())???
Thanks.
Fri, 12/03/2010 - 18:51
The difficult part is that OCC does not think of your object as a cylinder. Instead, it thinks of it as a group of topology ( 3 faces, two edges ) with underlying geometry ( two planar surfaces, one cylindrical surface, two circular curves. There are multiple ways to get the values you want, but I think the easiest is to get it from the curves. Try this:
Cast the AIS_InteractiveObject to an AIS_Shape
Get the TopoDS_Shape from the AIS_Shape
Use TopExp_Explorer to iterate through the curves
If the curve type is a circle, convert it to a circle
Get the radius and center of the circles
Note: I have not tried this code, but I think the general idea is correct.
double dRadius; // Variables to hold our results
gp_pnt ptEnds[2];
int numEndsFound = 0;
Handle(AIS_Shape) aShape = Handle(AIS_Shape)::DownCast(objList.First());
if (!aShape.IsNull ())
{
TopoDS_Shape topo = aShape->Shape()
TopExp_Explorer Ex;
// Get the circles at the top and bottom of the cylinder
for (Ex.Init(mWireframeShape,TopAbs_EDGE); Ex.More(); Ex.Next())
{
Handle(Geom_Curve) curve;
double dParamStart;
double dParamEnd;
curve = BRep_Tool::Curve(TopoDS::Edge(Ex.Current()), dParamStart, dParamEnd );
if (curve->IsKind(STANDARD_TYPE(Geom_Circle)))
{
Handle(Geom_Circle) aCircle = Handle(Geom_Circle)::DownCast(curve);
if (!aCircle .IsNull ())
{
gp_Circ circle = aCircle->Circ();
dRadius = circle.Radius();
ptEnds[numEndsFound] = circle.Location();
numEndsFound++;
if( numEndsFound == 2 )
{
break;
}
}
}
}
}
if( numEndsFound != 2 )
{
// Something didn't work right!!
}
// I'll leave it to you to calculate the position and height from the two end points.
Fri, 12/03/2010 - 20:28
Just to add to Eric's reply, another way more or less similar for cones, cylinder and spheres is :
http://www.opencascade.org/org/forum/thread_18562/
But I don't know how to get the geometrical properties for primitives like for example cubes. The way I am doing is storing the geometry in say in an object and inquiring the info when I need it back.
Thanks,
Venu
Sat, 12/04/2010 - 16:42
The answer very simple: Use OCAF!
Or use some framework like SALOME_GEOM module (Win32 port: http://sourceforge.net/projects/salomegeometry/ )