how to get correct shape location

hello , I met a problem when trying to get the Z locaion of a plane by selection. I am using OCCT 7.7 on ubuntu 22.04. I made a window to show the step file, and selected a face on the body. I want to get the Z location of the face but got two different result which really makes me confused. 

// this code is a part of function setShapes in class Algo    

    occtviewer->Context()->InitSelected();  // occtviewer->Context() gets the context, occtviewer is an instance of class OcctQtViewer
    Handle(StdSelect_BRepOwner) owner = Handle(StdSelect_BRepOwner)::DownCast (occtviewer->Context()->SelectedOwner());
    TopoDS_Shape shape = owner->Shape();

    up_plane = TopoDS::Face(shape);  // up_plane is a member of class Algo

    Handle(Geom_Surface) surface = BRep_Tool::Surface(TopoDS::Face(up_plane));
    Handle(Geom_Plane) plane = Handle(Geom_Plane)::DownCast(surface);
    gp_Pnt origin = plane->Location();
    std::cout << "zup = " << origin.Z() << std::endl;

// output: zup = -243.36
// Here the output is correct.
// this code is a part of function showRes in class Algo

    Handle(Geom_Surface) surface = BRep_Tool::Surface(TopoDS::Face(up_plane));
    Handle(Geom_Plane) plane = Handle(Geom_Plane)::DownCast(surface);
    gp_Pnt origin = plane->Location();
    double up_z =  origin.Z();
    std::cout << "up_z= " << up_z << std::endl;

// output: up_z= -314.455
// Here the output is wrong.

Function setShapes is executed before function showRes.

I really want to know what's wrong with my code  and solve this problem.

Dmitrii Pasukhin's picture

Hello.

Does your face have some hierarchy? Or it is only face without parents? Do you apply any transformation on top of geometry?

I would recommend to transform result location by all cascade transformations(TopLoc_Locations)

Best regards, Dmitrii.

vio liu's picture

Thank you for your replay! I forgot a transformation is applied between the two functions. What a stupid mistake. Thank you again!