Changeset 347


Ignore:
Timestamp:
03/12/10 09:55:04 (2 years ago)
Author:
ddangelo
Message:

Python function to calculate the bounding box of a av::osg::Node added.
The LoadFile? node now outputs the filename of the loaded object in the field "FilenameLoaded?", as soon as the file is actually loaded. This is useful to trigger actions which depend on the presence of the loaded object (e.g. the calculation of the bounding box).

Location:
trunk/avango-osg
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/avango-osg/include/avango/osg/LoadFile.h

    r1 r347  
    7171      SFString Filename; 
    7272 
     73      /** 
     74       * Outputs the file name of the geometry as soon as it is actually loaded. 
     75       * You can connect to this field to get a notification when the loading of the file was done. 
     76       */ 
     77      SFString FilenameLoaded; 
     78 
    7379      /* virtual */ void fieldHasChangedLocalSideEffect(const av::Field& field); 
    7480      /* virtual */ void evaluateLocalSideEffect(); 
  • trunk/avango-osg/python/avango/osg/OSGNode.cpp

    r1 r347  
    2929#include "OSGNode.h" 
    3030 
     31#include <osg/NodeVisitor> 
     32#include <osg/BoundingBox> 
     33#include <osg/BoundingSphere> 
     34#include <osg/MatrixTransform> 
     35#include <osg/Billboard> 
     36 
     37 
    3138using namespace boost::python; 
    3239using namespace av::python; 
     
    4350 } 
    4451 
     52 
     53namespace { 
     54  class CalculateBoundingBox : public ::osg::NodeVisitor 
     55  { 
     56  public: 
     57    CalculateBoundingBox() : 
     58      NodeVisitor(NodeVisitor::TRAVERSE_ALL_CHILDREN) 
     59    { 
     60      m_transformMatrix.makeIdentity(); 
     61    } 
     62 
     63    virtual ~CalculateBoundingBox() 
     64    { 
     65    } 
     66 
     67    virtual 
     68    void apply(::osg::Geode &geode) 
     69    { 
     70      ::osg::BoundingBox bbox; 
     71      for (unsigned int i = 0; i < geode.getNumDrawables(); ++i) 
     72      { 
     73        bbox.expandBy(geode.getDrawable(i)->getBound()); 
     74      } 
     75      ::osg::BoundingBox bboxTrans; 
     76      for (unsigned int i = 0; i < 8; ++i) 
     77      { 
     78        ::osg::Vec3 xvec = bbox.corner(i) * m_transformMatrix; 
     79        bboxTrans.expandBy(xvec); 
     80      } 
     81      m_boundingBox.expandBy(bboxTrans); 
     82      traverse(geode); 
     83    } 
     84 
     85    virtual 
     86    void apply(::osg::MatrixTransform &node) 
     87    { 
     88      m_transformMatrix *= node.getMatrix(); 
     89      traverse(node); 
     90    } 
     91 
     92    virtual 
     93    void apply(::osg::Billboard &node) 
     94    { 
     95      traverse(node); 
     96    } 
     97 
     98    ::osg::BoundingBox &getBoundBox() 
     99    { 
     100      return m_boundingBox; 
     101    } 
     102 
     103  protected: 
     104    ::osg::BoundingBox m_boundingBox; // the overall resultant bounding box 
     105    ::osg::Matrix m_transformMatrix; // the current transform matrix 
     106  }; 
     107 
     108 
     109  osg::BoundingBox CalcBoundingBox(av::osg::Node* node) 
     110  { 
     111    CalculateBoundingBox bbox; 
     112    node->getOsgNode()->accept( bbox ); 
     113    return bbox.getBoundBox(); 
     114  } 
     115 
     116} 
     117 
     118 
     119 
     120 
    45121void init_OSGNode(void) 
    46122 { 
     
    52128    .def("get_absolute_transform", &av::osg::Node::getAbsoluteTransform) 
    53129    ; 
     130 
     131  def("calc_bounding_box", CalcBoundingBox); 
    54132 } 
  • trunk/avango-osg/src/avango/osg/LoadFile.cpp

    r154 r347  
    4747{ 
    4848  AV_FC_ADD_FIELD(Filename, mFilename); 
     49  AV_FC_ADD_FIELD(FilenameLoaded, ""); 
    4950} 
    5051 
     
    119120      // add new geometry 
    120121      getOsgMatrixTransform()->addChild(mLoadedNode.get()); 
     122      FilenameLoaded.setValue(mFilename); 
    121123    } 
    122124 
Note: See TracChangeset for help on using the changeset viewer.