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_H
00026 #define WGEGEODEUTILS_H
00027
00028 #include <string>
00029 #include <vector>
00030
00031 #include <osg/Array>
00032 #include <osg/Geode>
00033 #include <osg/Geometry>
00034 #include <osg/MatrixTransform>
00035 #include <osg/PositionAttitudeTransform>
00036 #include <osg/Vec3>
00037 #include <osgText/Text>
00038
00039 #include "../common/math/WLine.h"
00040 #include "../common/math/WPlane.h"
00041 #include "../common/math/linearAlgebra/WLinearAlgebra.h"
00042 #include "../common/WColor.h"
00043 #include "../common/datastructures/WColoredVertices.h"
00044 #include "WExportWGE.h"
00045 #include "WGEGeometryUtils.h"
00046 #include "WGESubdividedPlane.h"
00047 #include "WGEUtils.h"
00048 #include "WTriangleMesh.h"
00049
00050 namespace wge
00051 {
00052
00053
00054
00055
00056
00057
00058
00059
00060 osg::ref_ptr< osg::Geode > WGE_EXPORT generateBoundingBoxGeode( const WBoundingBox& bb, const WColor& color );
00061
00062
00063
00064
00065
00066
00067
00068
00069
00070
00071
00072 osg::ref_ptr< osg::Node > WGE_EXPORT generateSolidBoundingBoxNode( const WBoundingBox& bb, const WColor& color, bool threeDTexCoords = true );
00073
00074
00075
00076
00077
00078
00079
00080
00081 osg::ref_ptr< osg::Geometry > WGE_EXPORT createUnitCube( const WColor& color );
00082
00083
00084
00085
00086
00087
00088
00089
00090 osg::ref_ptr< osg::Geometry > WGE_EXPORT createUnitCubeAsLines( const WColor& color );
00091
00092
00093
00094
00095
00096
00097
00098
00099
00100
00101
00102
00103
00104
00105 osg::ref_ptr< osg::Geometry > convertToOsgGeometry( WTriangleMesh::SPtr mesh,
00106 const WColor& defaultColor = WColor( 1.0, 1.0, 1.0, 1.0 ),
00107 bool includeNormals = false,
00108 bool lighting = false,
00109 bool useMeshColor = true );
00110
00111
00112
00113
00114
00115
00116
00117
00118
00119
00120
00121
00122
00123
00124
00125 osg::ref_ptr< osg::Geometry > WGE_EXPORT convertToOsgGeometry( WTriangleMesh::SPtr mesh, const WColoredVertices& colorMap,
00126 const WColor& defaultColor = WColor( 1.0, 1.0, 1.0, 1.0 ),
00127 bool includeNormals = false,
00128 bool lighting = false
00129 );
00130
00131
00132
00133
00134
00135
00136
00137
00138
00139
00140 osg::ref_ptr< osg::Geode > WGE_EXPORT generateLineStripGeode( const WLine& line,
00141 const float thickness = 3.0f,
00142 const WColor& color = WColor( 0, 0, 0, 0 ) );
00143
00144
00145
00146
00147
00148
00149
00150
00151 osg::ref_ptr< osg::PositionAttitudeTransform > WGE_EXPORT addLabel( osg::Vec3 position, std::string text );
00152
00153
00154
00155
00156
00157
00158
00159 osg::ref_ptr< osg::PositionAttitudeTransform > WGE_EXPORT vector2label( osg::Vec3 position );
00160
00161
00162
00163
00164
00165
00166
00167
00168
00169
00170
00171
00172 osg::ref_ptr< osg::Geode > WGE_EXPORT genFinitePlane( double xSize,
00173 double ySize,
00174 const WPlane& p,
00175 const WColor& color = WColor( 0.0, 0.7, 0.7, 1.0 ),
00176 bool border = false );
00177
00178
00179
00180
00181
00182
00183
00184
00185
00186
00187
00188
00189 osg::ref_ptr< osg::Group > creatCoordinateSystem(
00190 osg::Vec3 middle,
00191 double sizeX,
00192 double sizeY,
00193 double sizeZ
00194 );
00195
00196
00197
00198
00199
00200
00201
00202
00203
00204
00205 osg::ref_ptr< osg::Geode > WGE_EXPORT genFinitePlane( osg::Vec3 const& base, osg::Vec3 const& a, osg::Vec3 const& b );
00206
00207
00208
00209
00210
00211
00212
00213
00214
00215
00216 osg::ref_ptr< WGESubdividedPlane > WGE_EXPORT genUnitSubdividedPlane( size_t resX, size_t resY, double spacing = 0.01 );
00217
00218
00219
00220
00221
00222
00223
00224
00225
00226
00227
00228 template< class Container > osg::ref_ptr< osg::Geode > genPointBlobs( boost::shared_ptr< Container > points,
00229 double size,
00230 const WColor& color = WColor( 1.0, 0.0, 0.0, 1.0 ) );
00231 }
00232
00233 template< class Container > inline osg::ref_ptr< osg::Geode > wge::genPointBlobs( boost::shared_ptr< Container > points,
00234 double size,
00235 const WColor& color )
00236 {
00237 osg::ref_ptr< osg::Vec3Array > vertices = osg::ref_ptr< osg::Vec3Array >( new osg::Vec3Array );
00238 osg::ref_ptr< osg::Vec4Array > colors = osg::ref_ptr< osg::Vec4Array >( new osg::Vec4Array );
00239 osg::ref_ptr< osg::Geometry > geometry = osg::ref_ptr< osg::Geometry >( new osg::Geometry );
00240 osg::ref_ptr< osg::Vec3Array > normals = osg::ref_ptr< osg::Vec3Array >( new osg::Vec3Array );
00241
00242 for( typename Container::const_iterator point = points->begin(); point != points->end(); ++point )
00243 {
00244 const WPosition& pos = *point;
00245 std::vector< WPosition > corners;
00246 corners.reserve( 8 );
00247 double halfSize = size / 2.0;
00248 corners.push_back( WPosition( pos[0] - halfSize, pos[1] - halfSize, pos[2] - halfSize ) );
00249 corners.push_back( WPosition( pos[0] + halfSize, pos[1] - halfSize, pos[2] - halfSize ) );
00250 corners.push_back( WPosition( pos[0] + halfSize, pos[1] - halfSize, pos[2] + halfSize ) );
00251 corners.push_back( WPosition( pos[0] - halfSize, pos[1] - halfSize, pos[2] + halfSize ) );
00252 corners.push_back( WPosition( pos[0] - halfSize, pos[1] + halfSize, pos[2] - halfSize ) );
00253 corners.push_back( WPosition( pos[0] + halfSize, pos[1] + halfSize, pos[2] - halfSize ) );
00254 corners.push_back( WPosition( pos[0] + halfSize, pos[1] + halfSize, pos[2] + halfSize ) );
00255 corners.push_back( WPosition( pos[0] - halfSize, pos[1] + halfSize, pos[2] + halfSize ) );
00256
00257 osg::ref_ptr< osg::Vec3Array > ver = generateCuboidQuads( corners );
00258 vertices->insert( vertices->end(), ver->begin(), ver->end() );
00259 osg::ref_ptr< osg::Vec3Array > nor = generateCuboidQuadNormals( corners );
00260 normals->insert( normals->end(), nor->begin(), nor->end() );
00261 geometry->addPrimitiveSet( new osg::DrawArrays( osg::PrimitiveSet::QUADS, vertices->size() - ver->size(), ver->size() ) );
00262 }
00263
00264 geometry->setVertexArray( vertices );
00265 colors->push_back( color );
00266 geometry->setColorArray( colors );
00267 geometry->setColorBinding( osg::Geometry::BIND_OVERALL );
00268 geometry->setNormalArray( normals );
00269 geometry->setNormalBinding( osg::Geometry::BIND_PER_PRIMITIVE );
00270 osg::ref_ptr< osg::Geode > geode = osg::ref_ptr< osg::Geode >( new osg::Geode );
00271 geode->addDrawable( geometry );
00272 return geode;
00273 }
00274 #endif // WGEGEODEUTILS_H