OpenWalnut  1.3.1
WGEGeodeUtils_test.h
1 //---------------------------------------------------------------------------
2 //
3 // Project: OpenWalnut ( http://www.openwalnut.org )
4 //
5 // Copyright 2009 OpenWalnut Community, BSV@Uni-Leipzig and CNCF@MPI-CBS
6 // For more information see http://www.openwalnut.org/copying
7 //
8 // This file is part of OpenWalnut.
9 //
10 // OpenWalnut is free software: you can redistribute it and/or modify
11 // it under the terms of the GNU Lesser General Public License as published by
12 // the Free Software Foundation, either version 3 of the License, or
13 // (at your option) any later version.
14 //
15 // OpenWalnut is distributed in the hope that it will be useful,
16 // but WITHOUT ANY WARRANTY; without even the implied warranty of
17 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 // GNU Lesser General Public License for more details.
19 //
20 // You should have received a copy of the GNU Lesser General Public License
21 // along with OpenWalnut. If not, see <http://www.gnu.org/licenses/>.
22 //
23 //---------------------------------------------------------------------------
24 
25 #ifndef WGEGEODEUTILS_TEST_H
26 #define WGEGEODEUTILS_TEST_H
27 
28 #include <cxxtest/ValueTraits.h>
29 #include <cxxtest/TestSuite.h>
30 
31 #include <osg/io_utils>
32 
33 #include "../../common/WStringUtils.h"
34 #include "WVec3Traits.h"
35 #include "../WGEGeodeUtils.h"
36 
37 /**
38  * Testsuite for the WGEGeode utils.
39  */
40 class WGEGeodeUtilsTest : public CxxTest::TestSuite
41 {
42 public:
43  /**
44  * A unit subdivided plane with resolution width_x_height has width*height many quads.
45  */
47  {
48  double spacing = 0.0;
49  osg::ref_ptr< WGESubdividedPlane > g = wge::genUnitSubdividedPlane( 2, 2, spacing );
50  osg::Geometry *geo = dynamic_cast< osg::Geometry* >( g->getDrawable( 0 ) );
51  if( !geo )
52  {
53  TS_FAIL( "The drawable inside the WGESubdividedPlane geode is not a geometry" );
54  }
55  TS_ASSERT( geo );
56  osg::Vec3Array* verts = dynamic_cast< osg::Vec3Array* >( geo->getVertexArray() );
57  if( !verts )
58  {
59  TS_FAIL( "The vertex array inside is not a osg::Vec3Array" );
60  }
61  osg::ref_ptr< osg::Vec3Array > expected = osg::ref_ptr< osg::Vec3Array >( new osg::Vec3Array );
62  expected->push_back( osg::Vec3( 0.0, 0.0, 0.0 ) );
63  expected->push_back( osg::Vec3( 1.0, 0.0, 0.0 ) );
64  expected->push_back( osg::Vec3( 1.0, 1.0, 0.0 ) );
65  expected->push_back( osg::Vec3( 0.0, 1.0, 0.0 ) );
66  expected->push_back( osg::Vec3( 1.0, 0.0, 0.0 ) );
67  expected->push_back( osg::Vec3( 2.0, 0.0, 0.0 ) );
68  expected->push_back( osg::Vec3( 2.0, 1.0, 0.0 ) );
69  expected->push_back( osg::Vec3( 1.0, 1.0, 0.0 ) );
70  expected->push_back( osg::Vec3( 0.0, 1.0, 0.0 ) );
71  expected->push_back( osg::Vec3( 1.0, 1.0, 0.0 ) );
72  expected->push_back( osg::Vec3( 1.0, 2.0, 0.0 ) );
73  expected->push_back( osg::Vec3( 0.0, 2.0, 0.0 ) );
74  expected->push_back( osg::Vec3( 1.0, 1.0, 0.0 ) );
75  expected->push_back( osg::Vec3( 2.0, 1.0, 0.0 ) );
76  expected->push_back( osg::Vec3( 2.0, 2.0, 0.0 ) );
77  expected->push_back( osg::Vec3( 1.0, 2.0, 0.0 ) );
78  TS_ASSERT_EQUALS( verts->asVector(), expected->asVector() );
79  }
80 
81  /**
82  * For each quad there is a center point defined in the center point array.
83  */
84  void testCenterPoints( void )
85  {
86  osg::ref_ptr< WGESubdividedPlane > g = wge::genUnitSubdividedPlane( 2, 2 );
87  osg::ref_ptr< osg::Vec3Array > expected = osg::ref_ptr< osg::Vec3Array >( new osg::Vec3Array );
88  expected->push_back( osg::Vec3( 0.5, 0.5, 0.0 ) );
89  expected->push_back( osg::Vec3( 1.5, 0.5, 0.0 ) );
90  expected->push_back( osg::Vec3( 0.5, 1.5, 0.0 ) );
91  expected->push_back( osg::Vec3( 1.5, 1.5, 0.0 ) );
92  TS_ASSERT_EQUALS( g->getCenterArray()->asVector(), expected->asVector() );
93  }
94 };
95 
96 #endif // WGEGEODEUTILS_TEST_H