WGEGeodeUtils_test.h

00001 //---------------------------------------------------------------------------
00002 //
00003 // Project: OpenWalnut ( http://www.openwalnut.org )
00004 //
00005 // Copyright 2009 OpenWalnut Community, BSV@Uni-Leipzig and CNCF@MPI-CBS
00006 // For more information see http://www.openwalnut.org/copying
00007 //
00008 // This file is part of OpenWalnut.
00009 //
00010 // OpenWalnut is free software: you can redistribute it and/or modify
00011 // it under the terms of the GNU Lesser General Public License as published by
00012 // the Free Software Foundation, either version 3 of the License, or
00013 // (at your option) any later version.
00014 //
00015 // OpenWalnut is distributed in the hope that it will be useful,
00016 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00017 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00018 // GNU Lesser General Public License for more details.
00019 //
00020 // You should have received a copy of the GNU Lesser General Public License
00021 // along with OpenWalnut. If not, see <http://www.gnu.org/licenses/>.
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  * Testsuite for the WGEGeode utils.
00039  */
00040 class WGEGeodeUtilsTest : public CxxTest::TestSuite
00041 {
00042 public:
00043     /**
00044      * A unit subdivided plane with resolution width_x_height has width*height many quads.
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      * For each quad there is a center point defined in the center point array.
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
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends