Announcement

Collapse
No announcement yet.

How to get bounding box center from SoVRMLShape

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • How to get bounding box center from SoVRMLShape

    Hi, I am new to Open Inventor. I have a SoVRMLShape object, how can I get center of that object ? Here some code that I have tried:

    Code:
    SbVec3f GetBBoxCenter(SoVRMLShape* shape)
    {
    SoVRMLGeometry* geometry = static_cast<::SoVRMLGeometry*>(shape->geometry.getValue());
    SoGetBoundingBoxAction* action;
    geometry->getBoundingBox(action);
    SbBox3f bb = action->getBoundingBox();
    return bb.getCenter();
    }
    Here I thought that SoGetBoundingBoxAction object will be set after
    Code:
    geometry->getBoundingBox(action);
    but it throws an exception (Access violation reading location). How to do it in proper way or is it another method to get center of the SoVRMLShape ?
    Best regards,
    Oleksa.

  • #2
    Askelo,
    I suggest you to refer to the documentation of SoGetBoundingBoxAction. You need to first instantiate the Action with the Viewport of the viewer in which the shape is being rendered. Then, you can apply the action to the root of the scene graph you wish to know the BoundingBox of:
    Code:
    SoGetBoundingBoxAction gba( viewer->getViewportRegion() );
    gba.apply( root );
    Finally, you get the resulting BoundingBox by calling:
    Code:
    SbBox3f bbox = gba.getBoundingBox();

    Comment


    • #3
      Hi,
      Just a small clarification to Benjamin's reply: It is possible to apply SoGetBoundingBoxAction to a single node. So you could write:
      Code:
      SbVec3f GetBBoxCenter(SoVRMLShape* shape)
      {
      SoVRMLGeometry* geometry = static_cast<::SoVRMLGeometry*>(shape->geometry.getValue());
      SoGetBoundingBoxAction action(SbViewportRegion(500,500)); // Estimated viewport usually close enough
      action.apply(geometry);
      SbBox3f bb = action->getBoundingBox();
      return bb.getCenter();
      }
      You can apply the action to the SoVRMLShape node or to the SoVRMLGeometry node. Just be careful that the node is "ref'd" somewhere. The SoVRMLGeometry is ref'd by belonging to the 'geometry' field, so that should always be safe.
      Regards,
      Mike

      Comment


      • #4
        mikeheck thanks a lot for example and Benjamin for suggestion, that helps.

        Comment

        Working...
        X