00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025 #ifndef WGEGEODEUTILS_TEST_H
00026 #define WGEGEODEUTILS_TEST_H
00027
00028 #include <cxxtest/ValueTraits.h>
00029 #include <cxxtest/TestSuite.h>
00030
00031 #include <osg/io_utils>
00032
00033 #include "../../common/WStringUtils.h"
00034 #include "WVec3Traits.h"
00035 #include "../WGEGeodeUtils.h"
00036
00037
00038
00039
00040 class WGEGeodeUtilsTest : public CxxTest::TestSuite
00041 {
00042 public:
00043
00044
00045
00046 void testNumQuadsAndTheirVerticesWithoutSpacing( void )
00047 {
00048 double spacing = 0.0;
00049 osg::ref_ptr< WGESubdividedPlane > g = wge::genUnitSubdividedPlane( 2, 2, spacing );
00050 osg::Geometry *geo = dynamic_cast< osg::Geometry* >( g->getDrawable( 0 ) );
00051 if( !geo )
00052 {
00053 TS_FAIL( "The drawable inside the WGESubdividedPlane geode is not a geometry" );
00054 }
00055 TS_ASSERT( geo );
00056 osg::Vec3Array* verts = dynamic_cast< osg::Vec3Array* >( geo->getVertexArray() );
00057 if( !verts )
00058 {
00059 TS_FAIL( "The vertex array inside is not a osg::Vec3Array" );
00060 }
00061 osg::ref_ptr< osg::Vec3Array > expected = osg::ref_ptr< osg::Vec3Array >( new osg::Vec3Array );
00062 expected->push_back( osg::Vec3( 0.0, 0.0, 0.0 ) );
00063 expected->push_back( osg::Vec3( 1.0, 0.0, 0.0 ) );
00064 expected->push_back( osg::Vec3( 1.0, 1.0, 0.0 ) );
00065 expected->push_back( osg::Vec3( 0.0, 1.0, 0.0 ) );
00066 expected->push_back( osg::Vec3( 1.0, 0.0, 0.0 ) );
00067 expected->push_back( osg::Vec3( 2.0, 0.0, 0.0 ) );
00068 expected->push_back( osg::Vec3( 2.0, 1.0, 0.0 ) );
00069 expected->push_back( osg::Vec3( 1.0, 1.0, 0.0 ) );
00070 expected->push_back( osg::Vec3( 0.0, 1.0, 0.0 ) );
00071 expected->push_back( osg::Vec3( 1.0, 1.0, 0.0 ) );
00072 expected->push_back( osg::Vec3( 1.0, 2.0, 0.0 ) );
00073 expected->push_back( osg::Vec3( 0.0, 2.0, 0.0 ) );
00074 expected->push_back( osg::Vec3( 1.0, 1.0, 0.0 ) );
00075 expected->push_back( osg::Vec3( 2.0, 1.0, 0.0 ) );
00076 expected->push_back( osg::Vec3( 2.0, 2.0, 0.0 ) );
00077 expected->push_back( osg::Vec3( 1.0, 2.0, 0.0 ) );
00078 TS_ASSERT_EQUALS( verts->asVector(), expected->asVector() );
00079 }
00080
00081
00082
00083
00084 void testCenterPoints( void )
00085 {
00086 osg::ref_ptr< WGESubdividedPlane > g = wge::genUnitSubdividedPlane( 2, 2 );
00087 osg::ref_ptr< osg::Vec3Array > expected = osg::ref_ptr< osg::Vec3Array >( new osg::Vec3Array );
00088 expected->push_back( osg::Vec3( 0.5, 0.5, 0.0 ) );
00089 expected->push_back( osg::Vec3( 1.5, 0.5, 0.0 ) );
00090 expected->push_back( osg::Vec3( 0.5, 1.5, 0.0 ) );
00091 expected->push_back( osg::Vec3( 1.5, 1.5, 0.0 ) );
00092 TS_ASSERT_EQUALS( g->getCenterArray()->asVector(), expected->asVector() );
00093 }
00094 };
00095
00096 #endif // WGEGEODEUTILS_TEST_H