void SWWReaderTest::testBedslopeNormalArray() { CPPUNIT_ASSERT( _sww->isValid() ); osg::ref_ptr<osg::Vec3Array> actual = _sww->getBedslopeNormalArray(); CPPUNIT_ASSERT( actual ); // expected number of bedslope normals const size_t nvertices = 24; CPPUNIT_ASSERT_EQUAL( actual->size(), nvertices ); // hard-coded values (bedslope is flat plane) using osg::Vec3; using osg::Vec3Array; Vec3Array *expected = new Vec3Array; expected->assign(24, Vec3( 0.301511, -0.301511, 0.904534 ) ); for (size_t i=0; i<nvertices; i++) CPPUNIT_ASSERT_VEC3_EQUAL( actual->at(i), expected->at(i) ); }
void SWWReaderTest::testBedslopeVertexArray() { osg::ref_ptr<osg::Vec3Array> actual = _sww->getBedslopeVertexArray(); CPPUNIT_ASSERT( _sww->isValid() ); CPPUNIT_ASSERT( actual ); // expected number of bedslope vertices const size_t nvertices = 20; CPPUNIT_ASSERT_EQUAL( actual->size(), nvertices ); // hard-coded values extracted from sww file - note that these values are normalised by the reader using osg::Vec3; using osg::Vec3Array; Vec3Array *expected = new Vec3Array(20); (*expected)[ 0] = Vec3(-0.5, -0.5, 0.333333); (*expected)[ 1] = Vec3(-0.5, -0.166667, 0.444444); (*expected)[ 2] = Vec3(-0.5, 0.166667, 0.555556); (*expected)[ 3] = Vec3(-0.5, 0.5, 0.666667); (*expected)[ 4] = Vec3(-0.25, -0.5, 0.25); (*expected)[ 5] = Vec3(-0.25, -0.166667, 0.361111); (*expected)[ 6] = Vec3(-0.25, 0.166667, 0.472222); (*expected)[ 7] = Vec3(-0.25, 0.5, 0.583333); (*expected)[ 8] = Vec3(0, -0.5, 0.166667); (*expected)[ 9] = Vec3(0, -0.166667, 0.277778); (*expected)[10] = Vec3(0, 0.166667, 0.388889); (*expected)[11] = Vec3(0, 0.5, 0.5); (*expected)[12] = Vec3(0.25, -0.5, 0.0833333); (*expected)[13] = Vec3(0.25, -0.166667, 0.194444); (*expected)[14] = Vec3(0.25, 0.166667, 0.305556); (*expected)[15] = Vec3(0.25, 0.5, 0.416667); (*expected)[16] = Vec3(0.5, -0.5, 0); (*expected)[17] = Vec3(0.5, -0.166667, 0.111111); (*expected)[18] = Vec3(0.5, 0.166667, 0.222222); (*expected)[19] = Vec3(0.5, 0.5, 0.333333); for (size_t i=0; i<nvertices; i++) { CPPUNIT_ASSERT_VEC3_EQUAL( expected->at(i), actual->at(i) ); } }
osg::Node* Shape::createOSGAxes(const base::Dimension3& dim) { const Real s = 1.5; Real d = Math::minimum(0.06,Math::minimum(dim.x,dim.y,dim.z)/16.0); Group* g = NewObj Group; g->setName("debug"); // color the axes X:red, Y:green and Z:blue, with white end cones StateSet* red = NewObj StateSet(); osg::Material* rmat = NewObj osg::Material(); Vec4 cred(1,0,0,1); // mat->setEmission( osg::Material::FRONT_AND_BACK, Vec4(0,0,0,0) ); //mat->setAmbient( osg::Material::FRONT_AND_BACK, col ); rmat->setDiffuse( osg::Material::FRONT_AND_BACK, cred ); rmat->setSpecular( osg::Material::FRONT_AND_BACK, Vec4(1,1,1,0) ); rmat->setShininess( osg::Material::FRONT_AND_BACK, 1.0); red->setAttribute( rmat ); StateSet* green = NewObj StateSet(); osg::Material* gmat = NewObj osg::Material(); Vec4 cgreen(0,1,0,1); // mat->setEmission( osg::Material::FRONT_AND_BACK, Vec4(0,0,0,0) ); //mat->setAmbient( osg::Material::FRONT_AND_BACK, col ); gmat->setDiffuse( osg::Material::FRONT_AND_BACK, cgreen ); gmat->setSpecular( osg::Material::FRONT_AND_BACK, Vec4(1,1,1,0) ); gmat->setShininess( osg::Material::FRONT_AND_BACK, 1.0); green->setAttribute( gmat ); StateSet* blue = NewObj StateSet(); osg::Material* bmat = NewObj osg::Material(); Vec4 cblue(0,0,1,1); // mat->setEmission( osg::Material::FRONT_AND_BACK, Vec4(0,0,0,0) ); //mat->setAmbient( osg::Material::FRONT_AND_BACK, col ); bmat->setDiffuse( osg::Material::FRONT_AND_BACK, cblue ); bmat->setSpecular( osg::Material::FRONT_AND_BACK, Vec4(1,1,1,0) ); bmat->setShininess( osg::Material::FRONT_AND_BACK, 1.0); blue->setAttribute( bmat ); StateSet* white = NewObj StateSet(); osg::Material* wmat = NewObj osg::Material(); Vec4 cwhite(1,1,1,1); // mat->setEmission( osg::Material::FRONT_AND_BACK, Vec4(0,0,0,0) ); //mat->setAmbient( osg::Material::FRONT_AND_BACK, col ); wmat->setDiffuse( osg::Material::FRONT_AND_BACK, cwhite ); wmat->setSpecular( osg::Material::FRONT_AND_BACK, Vec4(1,1,1,0) ); wmat->setShininess( osg::Material::FRONT_AND_BACK, 1.0); white->setAttribute( wmat ); // a long Clyinder for the axis and a cone-like cylinder // for the arrow head of each X,Y and Z. MatrixTransform* xrot = NewObj MatrixTransform(); xrot->setMatrix(osg::Matrix::rotate(consts::Pi/2.0,Vec3(0,1,0))); xrot->postMult(osg::Matrix::translate(s*dim.x/4.0,0,0)); g->addChild(xrot); MatrixTransform* yrot = NewObj MatrixTransform(); yrot->setMatrix(osg::Matrix::rotate(consts::Pi/2.0,Vec3(-1,0,0))); yrot->postMult(osg::Matrix::translate(0,s*dim.y/4.0,0)); g->addChild(yrot); MatrixTransform* zrot = NewObj MatrixTransform(); zrot->setMatrix(osg::Matrix::translate(0,0,s*dim.z/4.0)); g->addChild(zrot); // the cylinder axes ref<Cylinder> xc(NewObj Cylinder(s*dim.x/2.0,d)); xrot->addChild(xc->createOSGVisual()); xrot->setStateSet(red); ref<Cylinder> yc(NewObj Cylinder(s*dim.y/2.0,d)); yrot->addChild(yc->createOSGVisual()); yrot->setStateSet(green); ref<Cylinder> zc(NewObj Cylinder(s*dim.z/2.0,d)); zrot->addChild(zc->createOSGVisual()); zrot->setStateSet(blue); // Translate each axis cone to the end MatrixTransform* xtrans = NewObj MatrixTransform(); xtrans->setMatrix(osg::Matrix::translate(0,0,s*dim.x/4.0+d)); xrot->addChild(xtrans); MatrixTransform* ytrans = NewObj MatrixTransform(); ytrans->setMatrix(osg::Matrix::translate(0,0,s*dim.y/4.0+d)); yrot->addChild(ytrans); MatrixTransform* ztrans = NewObj MatrixTransform(); ztrans->setMatrix(osg::Matrix::translate(0,0,s*dim.z/4.0+d)); zrot->addChild(ztrans); // the end cones ref<Cone> cone(NewObj Cone(4*d,2*d)); osg::Node* coneNode = cone->createOSGVisual(); coneNode->setStateSet(white); xtrans->addChild(coneNode); ytrans->addChild(coneNode); ztrans->addChild(coneNode); return g; }