Changeset 1206

Show
Ignore:
Timestamp:
05/07/08 18:41:36 (2 weeks ago)
Author:
cneumann
Message:

fixed: bounding volume calculation (was incorrect for non-leaf geo)

make existing unit test compile/run (on linux)

added: unit test for the above bvol problem

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/Source/System/NodeCores/Drawables/Geometry/Base/WS/OSGGeometry.cpp

    r1198 r1206  
    175175void Geometry::adjustVolume(Volume & volume) 
    176176{ 
    177     volume.setValid(); 
    178     volume.setEmpty(); 
    179  
    180177    GeoVectorProperty *pos = getPositions(); 
    181178 
     
    183180        return;                  // Node has no points, no volume 
    184181 
    185     Pnt3f p; 
    186  
    187     PrimitiveIterator it,end = this->endPrimitives(); 
    188  
    189     for(it = this->beginPrimitives(); it != end; ++it) 
    190     { 
    191         for(UInt32 v=0; v < it.getLength(); ++v) 
     182    volume.setValid(); 
     183         
     184    PrimitiveIterator it  = this->beginPrimitives(); 
     185    PrimitiveIterator end = this->endPrimitives  (); 
     186 
     187    for(; it != end; ++it) 
     188    { 
     189        for(UInt32 v = 0; v < it.getLength(); ++v) 
    192190        { 
    193191            volume.extendBy(it.getPosition(v)); 
  • trunk/Source/System/NodeCores/Drawables/Geometry/Base/WS/OSGGeometryTest.cpp

    r815 r1206  
    4444#include <OpenSG/OSGFieldContainerFactory.h> 
    4545#include <OpenSG/OSGTypedGeoVectorProperty.h> 
     46#include <OpenSG/OSGSimpleGeometry.h> 
     47#include <OpenSG/OSGTransform.h> 
    4648 
    4749SUITE(GeometryTests) 
     
    5052TEST(CreateGeometry) 
    5153{ 
    52     OSG::GeometryPtr g = OSG::Geometry::create(); 
    53     CHECK(g != OSGNullFC); 
     54    OSG::GeometryUnrecPtr g = OSG::Geometry::create(); 
     55    CHECK(g != NULL); 
    5456} 
    5557 
    5658TEST(TestInitialValues) 
    5759{ 
    58     OSG::GeometryPtr g = OSG::Geometry::create(); 
    59     CHECK(g != OSGNullFC); 
     60    OSG::GeometryUnrecPtr g = OSG::Geometry::create(); 
     61    CHECK(g != NULL); 
    6062 
    6163    for(unsigned i=0;i<OSG::Geometry::MaxAttribs;i++) 
    6264    { 
    63         CHECK(g->getProperty(i) == OSGNullFC); 
    64         CHECK(g->getIndex(i) == OSGNullFC); 
     65        CHECK(g->getProperty(i) == NULL); 
     66        CHECK(g->getIndex(i) == NULL); 
    6567    } 
    6668 
    67     CHECK(g->getMaterial() == OSGNullFC); 
     69    CHECK(g->getMaterial() == NULL); 
    6870} 
    6971 
     
    7173TEST(TestGenericInterfaces) 
    7274{ 
    73     OSG::GeometryPtr g = OSG::Geometry::create(); 
    74     CHECK(g != OSGNullFC); 
    75  
    76     OSG::GeoPnt3fPropertyPtr  pnts  = OSG::GeoPnt3fProperty ::create(); 
     75    OSG::GeometryUnrecPtr g = OSG::Geometry::create(); 
     76    CHECK(g != NULL); 
     77 
     78    OSG::GeoPnt3fPropertyUnrecPtr  pnts  = OSG::GeoPnt3fProperty ::create(); 
    7779    pnts->addValue(OSG::Pnt3f(0,0,0)); 
    7880 
    7981    g->setPositions(pnts); 
    8082 
    81     OSG::GeoVectorPropertyPtr pnts_g = g->getPositions(); 
     83    OSG::GeoVectorPropertyUnrecPtr pnts_g = g->getPositions(); 
    8284    pnts_g->setValue(OSG::Pnt3f(1,1,1), 0); 
    8385    pnts_g->setValue(OSG::Pnt3s(1,1,1), 0); 
     
    9496{ 
    9597    // Test setting attributes to all possible value types 
    96     OSG::GeometryPtr g = OSG::Geometry::create(); 
    97     CHECK(g != OSGNullFC); 
     98    OSG::GeometryUnrecPtr g = OSG::Geometry::create(); 
     99    CHECK(g != NULL); 
    98100 
    99101    // Copied-and-macroed from OSGTypedGeoVectorPropertyFields 
     
    228230    }; 
    229231 
    230     OSG::GeoVectorPropertyPtr att; 
     232    OSG::GeoVectorPropertyUnrecPtr att; 
    231233 
    232234    unsigned num_vec_props = sizeof(allowed_vec_prop_types) / sizeof(char*); 
     
    234236    for(unsigned i = 0; i < num_vec_props;++i) 
    235237    { 
    236         att = dynamic_cast<OSG::GeoVectorPropertyPtr>( 
     238        att = OSG::dynamic_pointer_cast<OSG::GeoVectorProperty>( 
    237239                    OSG::FieldContainerFactory::the()->createContainer( 
    238240                        allowed_vec_prop_types[i])); 
     
    244246} 
    245247 
     248TEST(GeometryAsInnerNodesBoundingVolume) 
     249{ 
     250    // pNGeo0:[Geometry] 
     251    //   | 
     252    //   +-------------------------------------+ 
     253    //   |                                     | 
     254    // pNTrans1:pTrans1[Transform]           pNTran2:pTrans2[Transform] 
     255    //   |                                     | 
     256    // pNGeo1:[Geometry]                     pNGeo2:[Geometry] 
     257     
     258    OSG::NodeUnrecPtr pNGeo0 = OSG::makeBox(2.0, 2.0, 4.0, 1, 1, 1); 
     259    OSG::NodeUnrecPtr pNGeo1 = OSG::makeBox(2.0, 2.0, 2.0, 1, 1, 1); 
     260    OSG::NodeUnrecPtr pNGeo2 = OSG::makeBox(2.0, 2.0, 2.0, 1, 1, 1); 
     261     
     262    OSG::NodeUnrecPtr      pNTrans1 = OSG::Node::create(); 
     263    OSG::TransformUnrecPtr pTrans1  = OSG::Transform::create(); 
     264    OSG::NodeUnrecPtr      pNTrans2 = OSG::Node::create(); 
     265    OSG::TransformUnrecPtr pTrans2  = OSG::Transform::create(); 
     266     
     267    pNTrans1->setCore (pTrans1); 
     268    pNTrans1->addChild(pNGeo1 ); 
     269    pNTrans2->setCore (pTrans2); 
     270    pNTrans2->addChild(pNGeo2 ); 
     271     
     272    pNGeo0->addChild(pNTrans1); 
     273    pNGeo0->addChild(pNTrans2); 
     274     
     275    OSG::Matrix mat1; 
     276    OSG::Matrix mat2; 
     277     
     278    mat1.setTranslate(OSG::Vec3f(  3.0, 0.0, 0.0)); 
     279    mat2.setTranslate(OSG::Vec3f(- 3.0, 0.0, 0.0)); 
     280     
     281    pTrans1->editSFMatrix()->setValue(mat1); 
     282    pTrans2->editSFMatrix()->setValue(mat2); 
     283     
     284    OSG::commitChanges(); 
     285     
     286    OSG::DynamicVolume bbox; 
     287    OSG::Pnt3f         min; 
     288    OSG::Pnt3f         max; 
     289     
     290    pNGeo1->getWorldVolume(bbox); 
     291    bbox.getBounds(min, max); 
     292        
     293    CHECK_CLOSE( 2.0, min[0], 1e-6); 
     294    CHECK_CLOSE(-1.0, min[1], 1e-6); 
     295    CHECK_CLOSE(-1.0, min[2], 1e-6); 
     296     
     297    CHECK_CLOSE( 4.0, max[0], 1e-6); 
     298    CHECK_CLOSE( 1.0, max[1], 1e-6); 
     299    CHECK_CLOSE( 1.0, max[2], 1e-6); 
     300     
     301    pNGeo2->getWorldVolume(bbox); 
     302    bbox.getBounds(min, max); 
     303         
     304    CHECK_CLOSE(-4.0, min[0], 1e-6); 
     305    CHECK_CLOSE(-1.0, min[1], 1e-6); 
     306    CHECK_CLOSE(-1.0, min[2], 1e-6); 
     307     
     308    CHECK_CLOSE(-2.0, max[0], 1e-6); 
     309    CHECK_CLOSE( 1.0, max[1], 1e-6); 
     310    CHECK_CLOSE( 1.0, max[2], 1e-6); 
     311     
     312    pNGeo0->getWorldVolume(bbox); 
     313    bbox.getBounds(min, max); 
     314     
     315    CHECK_CLOSE(-4.0, min[0], 1e-6); 
     316    CHECK_CLOSE(-1.0, min[1], 1e-6); 
     317    CHECK_CLOSE(-2.0, min[2], 1e-6); 
     318     
     319    CHECK_CLOSE( 4.0, max[0], 1e-6); 
     320    CHECK_CLOSE( 1.0, max[1], 1e-6); 
     321    CHECK_CLOSE( 2.0, max[2], 1e-6); 
     322} 
     323 
    246324} // SUITE 
    247325