OpenWalnut  1.5.0dev
WGEGeodeUtils.cpp
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 #include <map>
26 #include <string>
27 #include <vector>
28 
29 #include <osg/Array>
30 #include <osg/Geode>
31 #include <osg/Geometry>
32 #include <osg/LightModel>
33 #include <osg/LineWidth>
34 #include <osg/Material>
35 #include <osg/MatrixTransform>
36 #include <osg/ShapeDrawable>
37 #include <osg/Vec3>
38 
39 #include "../common/math/WMath.h"
40 #include "../common/WPathHelper.h"
41 #include "../common/WStringUtils.h"
42 
43 #include "shaders/WGEShader.h"
44 #include "WGEGeodeUtils.h"
45 #include "WGEGeometryUtils.h"
46 #include "WGEGroupNode.h"
47 #include "WGESubdividedPlane.h"
48 #include "WGEUtils.h"
49 #include "widgets/labeling/WGELabel.h"
50 
51 osg::ref_ptr< osg::Geode > wge::generateBoundingBoxGeode( const WBoundingBox& bb, const WColor& color )
52 {
53  const WBoundingBox::vec_type& pos1 = bb.getMin();
54  const WBoundingBox::vec_type& pos2 = bb.getMax();
55 
56  WAssert( pos1[0] <= pos2[0] && pos1[1] <= pos2[1] && pos1[2] <= pos2[2], "pos1 does not seem to be the frontLowerLeft corner of the BB!" );
57  using osg::ref_ptr;
58  ref_ptr< osg::Vec3Array > vertices = ref_ptr< osg::Vec3Array >( new osg::Vec3Array );
59  ref_ptr< osg::Vec4Array > colors = ref_ptr< osg::Vec4Array >( new osg::Vec4Array );
60  ref_ptr< osg::Geometry > geometry = ref_ptr< osg::Geometry >( new osg::Geometry );
61 
62  vertices->push_back( osg::Vec3( pos1[0], pos1[1], pos1[2] ) );
63  vertices->push_back( osg::Vec3( pos2[0], pos1[1], pos1[2] ) );
64  vertices->push_back( osg::Vec3( pos2[0], pos2[1], pos1[2] ) );
65  vertices->push_back( osg::Vec3( pos1[0], pos2[1], pos1[2] ) );
66  vertices->push_back( osg::Vec3( pos1[0], pos1[1], pos1[2] ) );
67  vertices->push_back( osg::Vec3( pos1[0], pos1[1], pos2[2] ) );
68  vertices->push_back( osg::Vec3( pos2[0], pos1[1], pos2[2] ) );
69  vertices->push_back( osg::Vec3( pos2[0], pos2[1], pos2[2] ) );
70  vertices->push_back( osg::Vec3( pos1[0], pos2[1], pos2[2] ) );
71  vertices->push_back( osg::Vec3( pos1[0], pos1[1], pos2[2] ) );
72 
73  geometry->addPrimitiveSet( new osg::DrawArrays( osg::PrimitiveSet::LINE_STRIP, 0, vertices->size() ) );
74 
75  vertices->push_back( osg::Vec3( pos1[0], pos2[1], pos1[2] ) );
76  vertices->push_back( osg::Vec3( pos1[0], pos2[1], pos2[2] ) );
77  vertices->push_back( osg::Vec3( pos2[0], pos2[1], pos1[2] ) );
78  vertices->push_back( osg::Vec3( pos2[0], pos2[1], pos2[2] ) );
79  vertices->push_back( osg::Vec3( pos2[0], pos1[1], pos1[2] ) );
80  vertices->push_back( osg::Vec3( pos2[0], pos1[1], pos2[2] ) );
81 
82  geometry->addPrimitiveSet( new osg::DrawArrays( osg::PrimitiveSet::LINES, vertices->size() - 6, 6 ) );
83 
84  geometry->setVertexArray( vertices );
85  colors->push_back( color );
86  geometry->setColorArray( colors );
87  geometry->setColorBinding( osg::Geometry::BIND_OVERALL );
88  osg::ref_ptr< osg::Geode > geode = osg::ref_ptr< osg::Geode >( new osg::Geode );
89  geode->setName( "Bounding Box Geode" );
90  geode->addDrawable( geometry );
91 
92  // disable light for this geode as lines can't be lit properly
93  osg::StateSet* state = geode->getOrCreateStateSet();
94  state->setMode( GL_LIGHTING, osg::StateAttribute::OFF | osg::StateAttribute::PROTECTED );
95 
96  return geode;
97 }
98 
99 void wge::createCube( osg::ref_ptr< osg::Geometry > geometry, const WPosition& position, const WPosition& size, const WColor& color )
100 {
101  // the geometry might be empty: ensure we have arrays properly set. If they cannot be casted, they get overwritten later. Users own fault if
102  // he does not read the doc
103  osg::ref_ptr< osg::Vec3Array > vertices = dynamic_cast< osg::Vec3Array* >( geometry->getVertexArray() );
104  osg::ref_ptr< osg::Vec3Array > tex = dynamic_cast< osg::Vec3Array* >( geometry->getTexCoordArray( 0 ) );
105  osg::ref_ptr< osg::Vec3Array > normals = dynamic_cast< osg::Vec3Array* >( geometry->getNormalArray() );
106  osg::ref_ptr< osg::Vec4Array > colors = dynamic_cast< osg::Vec4Array* >( geometry->getColorArray() );
107 
108  // get some mem if not already done
109  if( !vertices )
110  {
111  vertices = osg::ref_ptr< osg::Vec3Array >( new osg::Vec3Array );
112  }
113  if( !tex )
114  {
115  tex = osg::ref_ptr< osg::Vec3Array >( new osg::Vec3Array );
116  }
117  if( !normals )
118  {
119  normals = osg::ref_ptr< osg::Vec3Array >( new osg::Vec3Array );
120  }
121  if( !colors )
122  {
123  colors = osg::ref_ptr< osg::Vec4Array >( new osg::Vec4Array );
124  }
125 
126  size_t first = vertices->getNumElements();
127 
128  // NOTE: as the OSG 3.2 does not allow binding normals/colors and other arrays on a per-primitive basis, we bind the normals per vertex
129  // This means we add four normals per face
130 
131  // front face
132  vertices->push_back( position + WPosition( 0.0, 0.0, 0.0 ) );
133  vertices->push_back( position + WPosition( size.x(), 0.0, 0.0 ) );
134  vertices->push_back( position + WPosition( size.x(), size.y(), 0.0 ) );
135  vertices->push_back( position + WPosition( 0.0, size.y(), 0.0 ) );
136  tex->push_back( osg::Vec3( 0.0, 0.0, 0.0 ) );
137  tex->push_back( osg::Vec3( 1.0, 0.0, 0.0 ) );
138  tex->push_back( osg::Vec3( 1.0, 1.0, 0.0 ) );
139  tex->push_back( osg::Vec3( 0.0, 1.0, 0.0 ) );
140  normals->push_back( osg::Vec3( 0.0, 0.0, -1.0 ) );
141  normals->push_back( osg::Vec3( 0.0, 0.0, -1.0 ) );
142  normals->push_back( osg::Vec3( 0.0, 0.0, -1.0 ) );
143  normals->push_back( osg::Vec3( 0.0, 0.0, -1.0 ) );
144 
145  // back face
146  vertices->push_back( position + WPosition( 0.0, 0.0, size.z() ) );
147  vertices->push_back( position + WPosition( size.x(), 0.0, size.z() ) );
148  vertices->push_back( position + WPosition( size.x(), size.y(), size.z() ) );
149  vertices->push_back( position + WPosition( 0.0, size.y(), size.z() ) );
150  tex->push_back( osg::Vec3( 0.0, 0.0, 1.0 ) );
151  tex->push_back( osg::Vec3( 1.0, 0.0, 1.0 ) );
152  tex->push_back( osg::Vec3( 1.0, 1.0, 1.0 ) );
153  tex->push_back( osg::Vec3( 0.0, 1.0, 1.0 ) );
154  normals->push_back( osg::Vec3( 0.0, 0.0, 1.0 ) );
155  normals->push_back( osg::Vec3( 0.0, 0.0, 1.0 ) );
156  normals->push_back( osg::Vec3( 0.0, 0.0, 1.0 ) );
157  normals->push_back( osg::Vec3( 0.0, 0.0, 1.0 ) );
158 
159  // left
160  vertices->push_back( position + WPosition( 0.0, 0.0, 0.0 ) );
161  vertices->push_back( position + WPosition( 0.0, size.y(), 0.0 ) );
162  vertices->push_back( position + WPosition( 0.0, size.y(), size.z() ) );
163  vertices->push_back( position + WPosition( 0.0, 0.0, size.z() ) );
164  tex->push_back( osg::Vec3( 0.0, 0.0, 0.0 ) );
165  tex->push_back( osg::Vec3( 0.0, 1.0, 0.0 ) );
166  tex->push_back( osg::Vec3( 0.0, 1.0, 1.0 ) );
167  tex->push_back( osg::Vec3( 0.0, 0.0, 1.0 ) );
168  normals->push_back( osg::Vec3( -1.0, 0.0, 0.0 ) );
169  normals->push_back( osg::Vec3( -1.0, 0.0, 0.0 ) );
170  normals->push_back( osg::Vec3( -1.0, 0.0, 0.0 ) );
171  normals->push_back( osg::Vec3( -1.0, 0.0, 0.0 ) );
172 
173  // right
174  vertices->push_back( position + WPosition( size.x(), 0.0, 0.0 ) );
175  vertices->push_back( position + WPosition( size.x(), size.y(), 0.0 ) );
176  vertices->push_back( position + WPosition( size.x(), size.y(), size.z() ) );
177  vertices->push_back( position + WPosition( size.x(), 0.0, size.z() ) );
178  tex->push_back( osg::Vec3( 1.0, 0.0, 0.0 ) );
179  tex->push_back( osg::Vec3( 1.0, 1.0, 0.0 ) );
180  tex->push_back( osg::Vec3( 1.0, 1.0, 1.0 ) );
181  tex->push_back( osg::Vec3( 1.0, 0.0, 1.0 ) );
182  normals->push_back( osg::Vec3( 1.0, 0.0, 0.0 ) );
183  normals->push_back( osg::Vec3( 1.0, 0.0, 0.0 ) );
184  normals->push_back( osg::Vec3( 1.0, 0.0, 0.0 ) );
185  normals->push_back( osg::Vec3( 1.0, 0.0, 0.0 ) );
186 
187  // bottom
188  vertices->push_back( position + WPosition( 0.0, 0.0, 0.0 ) );
189  vertices->push_back( position + WPosition( size.x(), 0.0, 0.0 ) );
190  vertices->push_back( position + WPosition( size.x(), 0.0, size.z() ) );
191  vertices->push_back( position + WPosition( 0.0, 0.0, size.z() ) );
192  tex->push_back( osg::Vec3( 0.0, 0.0, 0.0 ) );
193  tex->push_back( osg::Vec3( 1.0, 0.0, 0.0 ) );
194  tex->push_back( osg::Vec3( 1.0, 0.0, 1.0 ) );
195  tex->push_back( osg::Vec3( 0.0, 0.0, 1.0 ) );
196  normals->push_back( osg::Vec3( 0.0, -1.0, 0.0 ) );
197  normals->push_back( osg::Vec3( 0.0, -1.0, 0.0 ) );
198  normals->push_back( osg::Vec3( 0.0, -1.0, 0.0 ) );
199  normals->push_back( osg::Vec3( 0.0, -1.0, 0.0 ) );
200 
201  // top
202  vertices->push_back( position + WPosition( 0.0, size.y(), 0.0 ) );
203  vertices->push_back( position + WPosition( size.x(), size.y(), 0.0 ) );
204  vertices->push_back( position + WPosition( size.x(), size.y(), size.z() ) );
205  vertices->push_back( position + WPosition( 0.0, size.y(), size.z() ) );
206  tex->push_back( osg::Vec3( 0.0, 1.0, 0.0 ) );
207  tex->push_back( osg::Vec3( 1.0, 1.0, 0.0 ) );
208  tex->push_back( osg::Vec3( 1.0, 1.0, 1.0 ) );
209  tex->push_back( osg::Vec3( 0.0, 1.0, 1.0 ) );
210  normals->push_back( osg::Vec3( 0.0, 1.0, 0.0 ) );
211  normals->push_back( osg::Vec3( 0.0, 1.0, 0.0 ) );
212  normals->push_back( osg::Vec3( 0.0, 1.0, 0.0 ) );
213  normals->push_back( osg::Vec3( 0.0, 1.0, 0.0 ) );
214 
215  // set it up and set arrays
216  geometry->addPrimitiveSet( new osg::DrawArrays( osg::PrimitiveSet::QUADS, first, 6 * 4 ) ); // 6 faces, 4 vertices per face
217  geometry->setVertexArray( vertices );
218 
219  // set 3D texture coordinates here.
220  geometry->setTexCoordArray( 0, tex );
221 
222  // set normals
223  geometry->setNormalArray( normals );
224  geometry->setNormalBinding( osg::Geometry::BIND_PER_VERTEX );
225 
226  // finally, the colors
227  colors->push_back( color );
228  geometry->setColorArray( colors );
229  geometry->setColorBinding( osg::Geometry::BIND_PER_PRIMITIVE_SET );
230 }
231 
232 osg::ref_ptr< osg::Geometry > wge::createCube( const WPosition& position, const WPosition& size, const WColor& color )
233 {
234  // create the unit cube manually as the ShapeDrawable and osg::Box does not provide 3D texture coordinates
235  osg::ref_ptr< osg::Geometry > cube = new osg::Geometry();
236  createCube( cube, position, size, color );
237  return cube;
238 }
239 
240 osg::ref_ptr< osg::Geometry > wge::createUnitCube( const WColor& color )
241 {
242  // create the unit cube manually as the ShapeDrawable and osg::Box does not provide 3D texture coordinates
243  return createCube( WPosition( 0.0, 0.0, 0.0 ), WPosition( 1.0, 1.0, 1.0 ), color );
244 }
245 
246 osg::ref_ptr< osg::Geometry > wge::createUnitCubeAsLines( const WColor& color, bool asLines )
247 {
248  // create the unit cube manually as the ShapeDrawable and osg::Box does not provide 3D texture coordinates
249  osg::ref_ptr< osg::Geometry > cube = new osg::Geometry();
250  osg::ref_ptr< osg::Vec3Array > vertices = osg::ref_ptr< osg::Vec3Array >( new osg::Vec3Array );
251  osg::ref_ptr< osg::Vec4Array > colors = osg::ref_ptr< osg::Vec4Array >( new osg::Vec4Array );
252 
253  if( !asLines )
254  {
255  vertices->push_back( osg::Vec3( 0.0, 0.0, 0.0 ) );
256  vertices->push_back( osg::Vec3( 1.0, 0.0, 0.0 ) );
257  vertices->push_back( osg::Vec3( 1.0, 1.0, 0.0 ) );
258  vertices->push_back( osg::Vec3( 0.0, 1.0, 0.0 ) );
259  vertices->push_back( osg::Vec3( 0.0, 0.0, 0.0 ) );
260  vertices->push_back( osg::Vec3( 0.0, 0.0, 1.0 ) );
261  vertices->push_back( osg::Vec3( 1.0, 0.0, 1.0 ) );
262  vertices->push_back( osg::Vec3( 1.0, 1.0, 1.0 ) );
263  vertices->push_back( osg::Vec3( 0.0, 1.0, 1.0 ) );
264  vertices->push_back( osg::Vec3( 0.0, 0.0, 1.0 ) );
265 
266  cube->addPrimitiveSet( new osg::DrawArrays( osg::PrimitiveSet::LINE_STRIP, 0, vertices->size() ) );
267 
268  vertices->push_back( osg::Vec3( 0.0, 1.0, 0.0 ) );
269  vertices->push_back( osg::Vec3( 0.0, 1.0, 1.0 ) );
270  vertices->push_back( osg::Vec3( 1.0, 0.0, 0.0 ) );
271  vertices->push_back( osg::Vec3( 1.0, 0.0, 1.0 ) );
272  vertices->push_back( osg::Vec3( 1.0, 1.0, 0.0 ) );
273  vertices->push_back( osg::Vec3( 1.0, 1.0, 1.0 ) );
274 
275  cube->addPrimitiveSet( new osg::DrawArrays( osg::PrimitiveSet::LINES, vertices->size() - 6, 6 ) );
276  }
277  else
278  {
279  vertices->push_back( osg::Vec3( 0.0, 0.0, 0.0 ) );
280  vertices->push_back( osg::Vec3( 1.0, 0.0, 0.0 ) );
281 
282  vertices->push_back( osg::Vec3( 1.0, 0.0, 0.0 ) );
283  vertices->push_back( osg::Vec3( 1.0, 1.0, 0.0 ) );
284 
285  vertices->push_back( osg::Vec3( 1.0, 1.0, 0.0 ) );
286  vertices->push_back( osg::Vec3( 0.0, 1.0, 0.0 ) );
287 
288  vertices->push_back( osg::Vec3( 0.0, 1.0, 0.0 ) );
289  vertices->push_back( osg::Vec3( 0.0, 0.0, 0.0 ) );
290 
291  vertices->push_back( osg::Vec3( 0.0, 0.0, 0.0 ) );
292  vertices->push_back( osg::Vec3( 0.0, 0.0, 1.0 ) );
293 
294  vertices->push_back( osg::Vec3( 0.0, 0.0, 1.0 ) );
295  vertices->push_back( osg::Vec3( 1.0, 0.0, 1.0 ) );
296 
297  vertices->push_back( osg::Vec3( 1.0, 0.0, 1.0 ) );
298  vertices->push_back( osg::Vec3( 1.0, 1.0, 1.0 ) );
299 
300  vertices->push_back( osg::Vec3( 1.0, 1.0, 1.0 ) );
301  vertices->push_back( osg::Vec3( 0.0, 1.0, 1.0 ) );
302 
303  vertices->push_back( osg::Vec3( 0.0, 1.0, 1.0 ) );
304  vertices->push_back( osg::Vec3( 0.0, 0.0, 1.0 ) );
305 
306  vertices->push_back( osg::Vec3( 0.0, 1.0, 0.0 ) );
307  vertices->push_back( osg::Vec3( 0.0, 1.0, 1.0 ) );
308 
309  vertices->push_back( osg::Vec3( 1.0, 0.0, 0.0 ) );
310  vertices->push_back( osg::Vec3( 1.0, 0.0, 1.0 ) );
311 
312  vertices->push_back( osg::Vec3( 1.0, 1.0, 0.0 ) );
313  vertices->push_back( osg::Vec3( 1.0, 1.0, 1.0 ) );
314 
315  cube->addPrimitiveSet( new osg::DrawArrays( osg::PrimitiveSet::LINES, 0, vertices->size() ) );
316  }
317 
318  // set it up and set arrays
319  cube->setVertexArray( vertices );
320 
321  // set 3D texture coordinates here.
322  cube->setTexCoordArray( 0, vertices );
323 
324  // finally, the colors
325  colors->push_back( color );
326  cube->setColorArray( colors );
327  cube->setColorBinding( osg::Geometry::BIND_OVERALL );
328 
329  return cube;
330 }
331 
332 osg::ref_ptr< osg::Node > wge::generateSolidBoundingBoxNode( const WBoundingBox& bb, const WColor& color, bool threeDTexCoords )
333 {
334  WAssert( bb.valid(), "Invalid bounding box!" );
335 
336  // create a uni cube
337  osg::ref_ptr< osg::Geode > cube = new osg::Geode();
338  cube->setName( "Solid Bounding Box" );
339  if( threeDTexCoords )
340  {
341  cube->addDrawable( createUnitCube( color ) );
342  }
343  else
344  {
345  osg::ref_ptr< osg::ShapeDrawable > cubeDrawable = new osg::ShapeDrawable( new osg::Box( osg::Vec3( 0.5, 0.5, 0.5 ), 1.0 ) );
346  cubeDrawable->setColor( color );
347  cube->addDrawable( cubeDrawable );
348  }
349 
350  // transform the cube to match the bbox
351  osg::Matrixd transformM;
352  osg::Matrixd scaleM;
353  transformM.makeTranslate( bb.getMin() );
354  scaleM.makeScale( bb.getMax() - bb.getMin() );
355 
356  // apply transformation to bbox
357  osg::ref_ptr< osg::MatrixTransform > transform = new osg::MatrixTransform();
358  transform->setMatrix( scaleM * transformM );
359  transform->addChild( cube );
360 
361  // we do not need light
362  osg::StateSet* state = cube->getOrCreateStateSet();
363  state->setMode( GL_LIGHTING, osg::StateAttribute::OFF | osg::StateAttribute::PROTECTED );
364 
365  return transform;
366 }
367 
368 osg::ref_ptr< osg::Geometry > wge::convertToOsgGeometry( WTriangleMesh::SPtr mesh,
369  const WColor& defaultColor,
370  bool includeNormals,
371  bool lighting,
372  bool useMeshColor )
373 {
374  osg::ref_ptr< osg::Geometry> geometry( new osg::Geometry );
375  geometry->setVertexArray( mesh->getVertexArray() );
376 
377  osg::DrawElementsUInt* surfaceElement;
378 
379  surfaceElement = new osg::DrawElementsUInt( osg::PrimitiveSet::TRIANGLES, 0 );
380 
381  std::vector< size_t > tris = mesh->getTriangles();
382  surfaceElement->reserve( tris.size() );
383 
384  for( unsigned int vertId = 0; vertId < tris.size(); ++vertId )
385  {
386  surfaceElement->push_back( tris[vertId] );
387  }
388  geometry->addPrimitiveSet( surfaceElement );
389 
390  // add the mesh colors
391  if( mesh->getVertexColorArray() && useMeshColor )
392  {
393  geometry->setColorArray( mesh->getVertexColorArray() );
394  geometry->setColorBinding( osg::Geometry::BIND_PER_VERTEX );
395  }
396  else
397  {
398  osg::ref_ptr< osg::Vec4Array > colors = osg::ref_ptr< osg::Vec4Array >( new osg::Vec4Array );
399  colors->push_back( defaultColor );
400  geometry->setColorArray( colors );
401  geometry->setColorBinding( osg::Geometry::BIND_OVERALL );
402  }
403 
404  // ------------------------------------------------
405  // normals
406  if( includeNormals )
407  {
408  geometry->setNormalArray( mesh->getVertexNormalArray() );
409  geometry->setNormalBinding( osg::Geometry::BIND_PER_VERTEX );
410 
411  if( lighting )
412  {
413  // if normals are specified, we also setup a default lighting.
414  osg::StateSet* state = geometry->getOrCreateStateSet();
415  osg::ref_ptr<osg::LightModel> lightModel = new osg::LightModel();
416  lightModel->setTwoSided( true );
417  state->setAttributeAndModes( lightModel.get(), osg::StateAttribute::ON );
418  state->setMode( GL_BLEND, osg::StateAttribute::ON );
419  {
420  osg::ref_ptr< osg::Material > material = new osg::Material();
421  material->setDiffuse( osg::Material::FRONT, osg::Vec4( 1.0, 1.0, 1.0, 1.0 ) );
422  material->setSpecular( osg::Material::FRONT, osg::Vec4( 0.0, 0.0, 0.0, 1.0 ) );
423  material->setAmbient( osg::Material::FRONT, osg::Vec4( 0.1, 0.1, 0.1, 1.0 ) );
424  material->setEmission( osg::Material::FRONT, osg::Vec4( 0.0, 0.0, 0.0, 1.0 ) );
425  material->setShininess( osg::Material::FRONT, 25.0 );
426  state->setAttribute( material );
427  }
428  }
429  }
430 
431  // enable VBO
432  geometry->setUseDisplayList( false );
433  geometry->setUseVertexBufferObjects( true );
434 
435  return geometry;
436 }
437 
438 osg::ref_ptr< osg::Geometry > wge::convertToOsgGeometryFlatShaded( WTriangleMesh::SPtr mesh,
439  const WColor& defaultColor,
440  bool includeNormals,
441  bool lighting,
442  bool useMeshColor )
443 {
444  osg::DrawElementsUInt* surfaceElement;
445  surfaceElement = new osg::DrawElementsUInt( osg::PrimitiveSet::TRIANGLES, 0 );
446  std::vector< size_t > tris = mesh->getTriangles();
447 
448  osg::ref_ptr< osg::Geometry> geometry( new osg::Geometry );
449  osg::ref_ptr< osg::Vec3Array > oldVertexArray( mesh->getVertexArray() );
450  osg::ref_ptr< osg::Vec3Array > newVertexArray( new osg::Vec3Array );
451  osg::ref_ptr< osg::Vec4Array > oldVertexColorArray( mesh->getVertexColorArray() );
452  osg::ref_ptr< osg::Vec4Array > newVertexColorArray( new osg::Vec4Array );
453 
454  // Make separate vertices for all triangle corners
455  for( size_t index = 0; index < tris.size(); ++index )
456  {
457  newVertexArray->push_back( (*oldVertexArray)[tris[index]] );
458  surfaceElement->push_back( index );
459  newVertexColorArray->push_back( (*oldVertexColorArray)[tris[index]] );
460  }
461  geometry->setVertexArray( newVertexArray );
462  geometry->addPrimitiveSet( surfaceElement );
463 
464  // add the mesh colors
465  if( mesh->getVertexColorArray() && useMeshColor )
466  {
467  geometry->setColorArray( newVertexColorArray );
468  geometry->setColorBinding( osg::Geometry::BIND_PER_VERTEX );
469  }
470  else
471  {
472  osg::ref_ptr< osg::Vec4Array > colors = osg::ref_ptr< osg::Vec4Array >( new osg::Vec4Array );
473  colors->push_back( defaultColor );
474  geometry->setColorArray( colors );
475  geometry->setColorBinding( osg::Geometry::BIND_OVERALL );
476  }
477 
478  // ------------------------------------------------
479  // normals
480  if( includeNormals )
481  {
482  // Set all vertex normals to the normals of the corresponding
483  // triangles causing uniform shading in a triangle
484  osg::ref_ptr< osg::Vec3Array > oldTriNormals = mesh->getTriangleNormalArray( true );
485  osg::ref_ptr< osg::Vec3Array > newVertNormals( new osg::Vec3Array );
486  for( size_t index = 0; index < tris.size(); ++index )
487  {
488  newVertNormals->push_back( (*oldTriNormals)[index/3] );
489  }
490  geometry->setNormalArray( newVertNormals );
491  geometry->setNormalBinding( osg::Geometry::BIND_PER_VERTEX );
492 
493  if( lighting )
494  {
495  // if normals are specified, we also setup a default lighting.
496  osg::StateSet* state = geometry->getOrCreateStateSet();
497  osg::ref_ptr<osg::LightModel> lightModel = new osg::LightModel();
498  lightModel->setTwoSided( true );
499  state->setAttributeAndModes( lightModel.get(), osg::StateAttribute::ON );
500  state->setMode( GL_BLEND, osg::StateAttribute::ON );
501  {
502  osg::ref_ptr< osg::Material > material = new osg::Material();
503  material->setDiffuse( osg::Material::FRONT, osg::Vec4( 1.0, 1.0, 1.0, 1.0 ) );
504  material->setSpecular( osg::Material::FRONT, osg::Vec4( 0.0, 0.0, 0.0, 1.0 ) );
505  material->setAmbient( osg::Material::FRONT, osg::Vec4( 0.1, 0.1, 0.1, 1.0 ) );
506  material->setEmission( osg::Material::FRONT, osg::Vec4( 0.0, 0.0, 0.0, 1.0 ) );
507  material->setShininess( osg::Material::FRONT, 25.0 );
508  state->setAttribute( material );
509  }
510  }
511  }
512 
513  // enable VBO
514  geometry->setUseDisplayList( false );
515  geometry->setUseVertexBufferObjects( true );
516 
517  return geometry;
518 }
519 
520 osg::ref_ptr< osg::Geometry > wge::convertToOsgGeometry( WTriangleMesh::SPtr mesh,
521  const WColoredVertices& colorMap,
522  const WColor& defaultColor,
523  bool includeNormals, bool lighting )
524 {
525  osg::ref_ptr< osg::Geometry > geometry = convertToOsgGeometry( mesh, defaultColor, includeNormals, lighting, false );
526 
527  // ------------------------------------------------
528  // colors
529  osg::ref_ptr< osg::Vec4Array > colors = osg::ref_ptr< osg::Vec4Array >( new osg::Vec4Array );
530  for( size_t i = 0; i < mesh->vertSize(); ++i )
531  {
532  colors->push_back( defaultColor );
533  }
534  for( std::map< size_t, WColor >::const_iterator vc = colorMap.getData().begin(); vc != colorMap.getData().end(); ++vc )
535  {
536  // ATTENTION: the colormap might not be available and hence an old one, but the new mesh might have triggered the update
537  if( vc->first < colors->size() )
538  {
539  colors->at( vc->first ) = vc->second;
540  }
541  }
542 
543  geometry->setColorArray( colors );
544  geometry->setColorBinding( osg::Geometry::BIND_PER_VERTEX );
545 
546  return geometry;
547 }
548 
549 osg::ref_ptr< osg::Geometry > wge::convertToOsgGeometryLines( WTriangleMesh::SPtr mesh,
550  const WColor& defaultColor,
551  bool useMeshColor )
552 {
553  osg::ref_ptr< osg::Geometry > geometry( new osg::Geometry );
554  geometry->setVertexArray( mesh->getVertexArray() );
555 
556  osg::DrawElementsUInt* meshElement;
557 
558  meshElement = new osg::DrawElementsUInt( osg::PrimitiveSet::LINES, 0 );
559 
560  std::vector< size_t > tris = mesh->getTriangles();
561  meshElement->reserve( tris.size() * 3 );
562 
563  for( unsigned int triId = 0; triId < tris.size() / 3.; ++triId )
564  {
565  for( size_t edgeId = 0; edgeId < 3; ++edgeId )
566  {
567  meshElement->push_back( tris[triId*3 + edgeId] );
568  meshElement->push_back( tris[triId*3 + ( edgeId + 1 ) % 3] );
569  }
570  }
571  geometry->addPrimitiveSet( meshElement );
572 
573  // add the mesh colors
574  if( mesh->getVertexColorArray() && useMeshColor )
575  {
576  geometry->setColorArray( mesh->getVertexColorArray() );
577  geometry->setColorBinding( osg::Geometry::BIND_PER_VERTEX );
578  }
579  else
580  {
581  osg::ref_ptr< osg::Vec4Array > colors = osg::ref_ptr< osg::Vec4Array >( new osg::Vec4Array );
582  colors->push_back( defaultColor );
583  geometry->setColorArray( colors );
584  geometry->setColorBinding( osg::Geometry::BIND_OVERALL );
585  }
586 
587  osg::StateSet* stateset = geometry->getOrCreateStateSet();
588  stateset->setAttributeAndModes( new osg::LineWidth( 1 ), osg::StateAttribute::ON );
589  stateset->setMode( GL_LIGHTING, osg::StateAttribute::OFF );
590  stateset->setMode( GL_BLEND, osg::StateAttribute::ON );
591 
592  return geometry;
593 }
594 
595 osg::ref_ptr< osg::PositionAttitudeTransform > wge::addLabel( osg::Vec3 position, std::string text )
596 {
597  osg::ref_ptr< osgText::Text > label = osg::ref_ptr< osgText::Text >( new osgText::Text() );
598  osg::ref_ptr< osg::Geode > labelGeode = osg::ref_ptr< osg::Geode >( new osg::Geode() );
599 
600  labelGeode->addDrawable( label );
601 
602  // setup font
603  label->setFont( WPathHelper::getAllFonts().Default.string() );
604  label->setBackdropType( osgText::Text::OUTLINE );
605  label->setCharacterSize( 6 );
606 
607  label->setText( text );
608  label->setAxisAlignment( osgText::Text::SCREEN );
609  label->setDrawMode( osgText::Text::TEXT );
610  label->setAlignment( osgText::Text::CENTER_TOP );
611  label->setPosition( osg::Vec3( 0.0, 0.0, 0.0 ) );
612  label->setColor( osg::Vec4( 1.0f, 1.0f, 1.0f, 1.0f ) );
613 
614  osg::ref_ptr< osg::PositionAttitudeTransform > labelXform =
615  osg::ref_ptr< osg::PositionAttitudeTransform >( new osg::PositionAttitudeTransform() );
616  labelXform->setPosition( position );
617 
618  labelXform->addChild( labelGeode );
619 
620  return labelXform;
621 }
622 
623 osg::ref_ptr< osg::PositionAttitudeTransform > wge::vector2label( osg::Vec3 position )
624 {
625  std::string label = "(" + string_utils::toString( position[0] ) + "," +
626  string_utils::toString( position[1] ) + "," + string_utils::toString( position[2] ) + ")";
627  return ( addLabel( position, label ) );
628 }
629 
630 osg::ref_ptr< osg::Geode > wge::genFinitePlane( double xSize, double ySize, const WPlane& p, const WColor& color, bool border )
631 {
632  using osg::ref_ptr;
633  ref_ptr< osg::Vec3Array > vertices = ref_ptr< osg::Vec3Array >( new osg::Vec3Array );
634  ref_ptr< osg::Vec4Array > colors = ref_ptr< osg::Vec4Array >( new osg::Vec4Array );
635  ref_ptr< osg::Geometry > geometry = ref_ptr< osg::Geometry >( new osg::Geometry );
636 
637  colors->push_back( color );
638 
639  vertices->push_back( p.getPointInPlane( xSize, ySize ) );
640  vertices->push_back( p.getPointInPlane( -xSize, ySize ) );
641  vertices->push_back( p.getPointInPlane( -xSize, -ySize ) );
642  vertices->push_back( p.getPointInPlane( xSize, -ySize ) );
643 
644  geometry->addPrimitiveSet( new osg::DrawArrays( osg::PrimitiveSet::QUADS, 0, 4 ) );
645  geometry->setVertexArray( vertices );
646  geometry->setColorArray( colors );
647  geometry->setColorBinding( osg::Geometry::BIND_OVERALL );
648 
649  osg::StateSet* stateset = new osg::StateSet;
650  stateset->setMode( GL_LIGHTING, osg::StateAttribute::OFF );
651  geometry->setStateSet( stateset );
652 
653  osg::ref_ptr< osg::Geode > geode = osg::ref_ptr< osg::Geode >( new osg::Geode );
654  geode->setName( "Finite Plane Geode" );
655  geode->addDrawable( geometry );
656 
657  if( border )
658  {
659  vertices->push_back( vertices->front() );
660  ref_ptr< osg::Geometry > borderGeom = ref_ptr< osg::Geometry >( new osg::Geometry );
661  borderGeom->addPrimitiveSet( new osg::DrawArrays( osg::PrimitiveSet::LINE_STRIP, 0, 4 ) );
662  borderGeom->addPrimitiveSet( new osg::DrawArrays( osg::PrimitiveSet::LINE_STRIP, 3, 2 ) );
663  ref_ptr< osg::Vec4Array > colors = ref_ptr< osg::Vec4Array >( new osg::Vec4Array );
664  colors->push_back( inverseColor( color ) );
665  borderGeom->setColorArray( colors );
666  borderGeom->setColorBinding( osg::Geometry::BIND_OVERALL );
667  borderGeom->setVertexArray( vertices );
668  geode->addDrawable( borderGeom );
669  }
670  return geode;
671 }
672 
673 osg::ref_ptr< osg::Geode > wge::genFinitePlane( osg::Vec3 const& base, osg::Vec3 const& a, osg::Vec3 const& b, const WColor& color )
674 {
675  // the stuff needed by the OSG to create a geometry instance
676  osg::ref_ptr< osg::Vec3Array > vertices = new osg::Vec3Array;
677  osg::ref_ptr< osg::Vec3Array > texcoords0 = new osg::Vec3Array;
678  osg::ref_ptr< osg::Vec3Array > normals = new osg::Vec3Array;
679  osg::ref_ptr< osg::Vec4Array > colors = new osg::Vec4Array;
680 
681  osg::Vec3 aPlusB = a + b;
682 
683  vertices->push_back( base );
684  vertices->push_back( base + a );
685  vertices->push_back( base + aPlusB );
686  vertices->push_back( base + b );
687 
688  osg::Vec3 aCrossB = a ^ b;
689  aCrossB.normalize();
690  osg::Vec3 aNorm = a;
691  aNorm.normalize();
692  osg::Vec3 bNorm = b;
693  bNorm.normalize();
694 
695  normals->push_back( aCrossB );
696  normals->push_back( aCrossB );
697  normals->push_back( aCrossB );
698  normals->push_back( aCrossB );
699  colors->push_back( color );
700  colors->push_back( color );
701  colors->push_back( color );
702  colors->push_back( color );
703  texcoords0->push_back( osg::Vec3( 0.0, 0.0, 0.0 ) );
704  texcoords0->push_back( aNorm );
705  texcoords0->push_back( aNorm + bNorm );
706  texcoords0->push_back( bNorm );
707 
708  // put it all together
709  osg::ref_ptr< osg::Geometry > geometry = new osg::Geometry();
710  geometry->setVertexArray( vertices );
711  geometry->setTexCoordArray( 0, texcoords0 );
712  geometry->setNormalArray( normals );
713  geometry->setColorArray( colors );
714  geometry->addPrimitiveSet( new osg::DrawArrays( osg::PrimitiveSet::QUADS, 0, 4 ) );
715 
716  osg::ref_ptr< osg::Geode > geode = new osg::Geode();
717  geode->setName( "Finite Plane" );
718  geode->addDrawable( geometry );
719  return geode;
720 }
721 
722 osg::ref_ptr< osg::Group > wge::creatCoordinateSystem(
723  osg::Vec3 middle,
724  double sizeX,
725  double sizeY,
726  double sizeZ
727 )
728 {
729  osg::ref_ptr< WGEGroupNode >groupNode = new WGEGroupNode();
730  osg::ref_ptr< WGEShader > shaderCoordinateSystem( new WGEShader( "WGECoordinateSystem" ) );
731 
732  osg::ref_ptr< osg::Geode > graphX( new osg::Geode );
733  osg::ref_ptr< osg::Geode > graphY( new osg::Geode );
734  osg::ref_ptr< osg::Geode > graphZ( new osg::Geode );
735 
736  osg::ref_ptr< osg::Geode > graphXCylinder( new osg::Geode );
737  osg::ref_ptr< osg::Geode > graphYCylinder( new osg::Geode );
738  osg::ref_ptr< osg::Geode > graphZCylinder( new osg::Geode );
739 
740  // X
741  osg::ref_ptr< osg::ShapeDrawable > cylinderX = new osg::ShapeDrawable( new osg::Cylinder(
742  middle, 1, sizeX + ( sizeX * 0.5 )
743  ) );
744  osg::ref_ptr< osg::ShapeDrawable > cylinderXEnd = new osg::ShapeDrawable( new osg::Cylinder(
745  osg::Vec3( middle.x(), middle.y(), middle.z() - ( sizeX + ( sizeX * 0.5 ) ) / 2.0 ), 1.0, 1.0
746  ) );
747  osg::ref_ptr< osg::ShapeDrawable > coneX = new osg::ShapeDrawable( new osg::Cone(
748  osg::Vec3( middle.x(), middle.y(), middle.z() + ( sizeX + ( sizeX * 0.5 ) ) / 2.0 ), 2.0, 5.0
749  ) );
750  cylinderXEnd->getOrCreateStateSet()->setMode( GL_LIGHTING, osg::StateAttribute::OFF );
751  graphXCylinder->addDrawable( cylinderX );
752  graphX->addDrawable( coneX );
753  graphX->addDrawable( cylinderXEnd );
754 
755  osg::ref_ptr< osg::Material > matX = new osg::Material();
756  matX->setDiffuse( osg::Material::FRONT, WColor( 1.0, 0.0, 0.0, 1.0 ) );
757  cylinderX->getOrCreateStateSet()->setAttribute( matX, osg::StateAttribute::ON );
758  coneX->getOrCreateStateSet()->setAttribute( matX, osg::StateAttribute::ON );
759 
760  // Y
761  osg::ref_ptr< osg::ShapeDrawable > cylinderY = new osg::ShapeDrawable( new osg::Cylinder(
762  middle, 1, sizeY + ( sizeY * 0.5 )
763  ) );
764  osg::ref_ptr< osg::ShapeDrawable > cylinderYEnd = new osg::ShapeDrawable( new osg::Cylinder(
765  osg::Vec3( middle.x(), middle.y(), middle.z() - ( sizeY + ( sizeY * 0.5 ) ) / 2.0 ), 1.0, 1.0
766  ) );
767  osg::ref_ptr< osg::ShapeDrawable > coneY = new osg::ShapeDrawable( new osg::Cone(
768  osg::Vec3( middle.x(), middle.y(), middle.z() + ( sizeY + ( sizeY * 0.5 ) ) / 2.0 ), 2.0, 5.0
769  ) );
770  cylinderYEnd->getOrCreateStateSet()->setMode( GL_LIGHTING, osg::StateAttribute::OFF );
771 
772  graphYCylinder->addDrawable( cylinderY );
773  graphY->addDrawable( coneY );
774  graphY->addDrawable( cylinderYEnd );
775 
776  osg::ref_ptr< osg::Material > matY = new osg::Material();
777  matY->setDiffuse( osg::Material::FRONT, WColor( 0.0, 1.0, 0.0, 1.0 ) );
778  cylinderY->getOrCreateStateSet()->setAttribute( matY, osg::StateAttribute::ON );
779  coneY->getOrCreateStateSet()->setAttribute( matY, osg::StateAttribute::ON );
780 
781 
782  // Z
783  osg::ref_ptr< osg::ShapeDrawable > cylinderZ = new osg::ShapeDrawable( new osg::Cylinder(
784  middle, 1, sizeZ + ( sizeZ * 0.5 )
785  ) );
786  osg::ref_ptr< osg::ShapeDrawable > cylinderZEnd = new osg::ShapeDrawable( new osg::Cylinder(
787  osg::Vec3( middle.x(), middle.y(), middle.z() - ( sizeZ + ( sizeZ * 0.5 ) ) / 2.0 ), 1.0, 1.0
788  ) );
789  osg::ref_ptr< osg::ShapeDrawable > coneZ = new osg::ShapeDrawable( new osg::Cone(
790  osg::Vec3( middle.x(), middle.y(), middle.z() + ( sizeZ + ( sizeZ * 0.5 ) ) / 2.0 ), 2.0, 5.0
791  ) );
792  cylinderZEnd->getOrCreateStateSet()->setMode( GL_LIGHTING, osg::StateAttribute::OFF );
793 
794  graphZCylinder->addDrawable( cylinderZ );
795  graphZ->addDrawable( coneZ );
796  graphZ->addDrawable( cylinderZEnd );
797 
798  osg::ref_ptr< osg::Material > matZ = new osg::Material();
799  matZ->setDiffuse( osg::Material::FRONT, WColor( 0.0, 0.0, 1.0, 1.0 ) );
800  cylinderZ->getOrCreateStateSet()->setAttribute( matZ, osg::StateAttribute::ON );
801  coneZ->getOrCreateStateSet()->setAttribute( matZ, osg::StateAttribute::ON );
802 
803  shaderCoordinateSystem->apply( graphXCylinder );
804  shaderCoordinateSystem->apply( graphYCylinder );
805  shaderCoordinateSystem->apply( graphZCylinder );
806 
807  osg::ref_ptr< WGELabel > graphXLabel = new WGELabel();
808  graphXLabel->setText( "X" );
809  graphXLabel->setCharacterSize( 10 );
810  graphXLabel->setPosition( osg::Vec3( middle.x(), middle.y(), middle.z() + ( sizeX + ( sizeX * 0.5 ) ) / 2.0 + 5.0 ) );
811  graphXLabel->getOrCreateStateSet()->setMode( GL_LIGHTING, osg::StateAttribute::OFF );
812  graphX->addDrawable( graphXLabel );
813 
814  osg::ref_ptr< WGELabel > graphYLabel = new WGELabel();
815  graphYLabel->setText( "Y" );
816  graphYLabel->setCharacterSize( 10 );
817  graphYLabel->setPosition( osg::Vec3( middle.x(), middle.y(), middle.z() + ( sizeY + ( sizeY * 0.5 ) ) / 2.0 + 5.0 ) );
818  graphYLabel->getOrCreateStateSet()->setMode( GL_LIGHTING, osg::StateAttribute::OFF );
819  graphY->addDrawable( graphYLabel );
820 
821  osg::ref_ptr< WGELabel > graphZLabel = new WGELabel();
822  graphZLabel->setText( "Z" );
823  graphZLabel->setCharacterSize( 10 );
824  graphZLabel->setPosition( osg::Vec3( middle.x(), middle.y(), middle.z() + ( sizeZ + ( sizeZ * 0.5 ) ) / 2.0 + 5.0 ) );
825  graphZLabel->getOrCreateStateSet()->setMode( GL_LIGHTING, osg::StateAttribute::OFF );
826  graphZ->addDrawable( graphZLabel );
827 
828 
829  osg::ref_ptr< osg::MatrixTransform > graphXTransform = new osg::MatrixTransform();
830  graphXTransform->addChild( graphX );
831  graphXTransform->addChild( graphXCylinder );
832  osg::ref_ptr< osg::MatrixTransform > graphYTransform = new osg::MatrixTransform();
833  graphYTransform->addChild( graphY );
834  graphYTransform->addChild( graphYCylinder );
835  osg::ref_ptr< osg::MatrixTransform > graphZTransform = new osg::MatrixTransform();
836  graphZTransform->addChild( graphZ );
837  graphZTransform->addChild( graphZCylinder );
838 
839  osg::Matrixd matrixTranslateTo0 = osg::Matrixd::translate( -middle.x(), -middle.y(), -middle.z() );
840  osg::Matrixd matrixTranslateFrom0 = osg::Matrixd::translate( middle.x(), middle.y(), middle.z() );
841 
842  graphXTransform->setMatrix( matrixTranslateTo0 * osg::Matrixd::rotate(
843  90.0 * pi() / 180.0,
844  osg::Vec3f( 0.0, 1.0, 0.0 ) ) * matrixTranslateFrom0
845  );
846  graphYTransform->setMatrix( matrixTranslateTo0 * osg::Matrixd::rotate(
847  -90.0 * pi() / 180.0,
848  osg::Vec3f( 1.0, 0.0, 0.0 ) ) * matrixTranslateFrom0
849  );
850 
851  groupNode->insert( graphXTransform );
852  groupNode->insert( graphYTransform );
853  groupNode->insert( graphZTransform );
854 
855  return groupNode;
856 }
const vec_type & getMax() const
Gives the back upper right aka maximum corner.
Definition: WBoundingBox.h:308
const vec_type & getMin() const
Gives the front lower left aka minimum corner.
Definition: WBoundingBox.h:302
osg::BoundingBoxImpl< osg::Vec3 >::vec_type vec_type
Vertex type for min and max positions of this box.
Definition: WBoundingBox.h:53
Represents a std::map where for each vertex ID a color is stored.
const std::map< size_t, WColor > & getData() const
Reference to the data.
Class to wrap around the osg Group node and providing a thread safe add/removal mechanism.
Definition: WGEGroupNode.h:48
Label layout-item.
Definition: WGELabel.h:39
Class encapsulating the OSG Program class for a more convenient way of adding and modifying shader.
Definition: WGEShader.h:48
static Fonts getAllFonts()
The paths to all fonts supported.
Represents a plane with a normal vector and a position in space.
Definition: WPlane.h:39
WPosition getPointInPlane(double x, double y) const
Computes with relative coordinates a point in this plane.
Definition: WPlane.cpp:94
This only is a 3d double vector.
std::shared_ptr< WTriangleMesh > SPtr
Shared pointer.
Definition: WTriangleMesh.h:55
Some default colors.
Definition: WColor.cpp:36
std::string toString(const T &value)
Convert a given value to a string.
Definition: WStringUtils.h:120
osg::ref_ptr< osg::Geometry > convertToOsgGeometryLines(WTriangleMesh::SPtr mesh, const WColor &defaultColor=WColor(1.0, 1.0, 1.0, 1.0), bool useMeshColor=true)
Convert triangle mesh to lines representing it.
osg::ref_ptr< osg::Geode > generateBoundingBoxGeode(const WBoundingBox &bb, const WColor &color)
Generates an OSG geode for the bounding box.
osg::ref_ptr< osg::PositionAttitudeTransform > vector2label(osg::Vec3 position)
helper function to add a label with it's position vector
osg::ref_ptr< osg::Geometry > convertToOsgGeometry(WTriangleMesh::SPtr mesh, const WColor &defaultColor=WColor(1.0, 1.0, 1.0, 1.0), bool includeNormals=false, bool lighting=false, bool useMeshColor=true)
Extract the vertices and triangles from a WTriangleMesh and save them into an osg::Geometry.
osg::ref_ptr< osg::Geometry > createUnitCube(const WColor &color)
Creates a osg::Geometry containing an unit cube, having 3D texture coordinates.
osg::ref_ptr< osg::PositionAttitudeTransform > addLabel(osg::Vec3 position, std::string text)
helper function to add a label somewhere
osg::ref_ptr< osg::Group > creatCoordinateSystem(osg::Vec3 middle, double sizeX, double sizeY, double sizeZ)
Create a coordinate system.
osg::ref_ptr< osg::Geometry > convertToOsgGeometryFlatShaded(WTriangleMesh::SPtr mesh, const WColor &defaultColor=WColor(1.0, 1.0, 1.0, 1.0), bool includeNormals=false, bool lighting=false, bool useMeshColor=true)
Extract the vertices and triangles from a WTriangleMesh and save them into an osg::Geometry in order ...
osg::ref_ptr< osg::Node > generateSolidBoundingBoxNode(const WBoundingBox &bb, const WColor &color, bool threeDTexCoords=true)
Generates an OSG node for the specified bounding box.
osg::ref_ptr< osg::Geode > genFinitePlane(double xSize, double ySize, const WPlane &p, const WColor &color=WColor(0.0, 0.7, 0.7, 1.0), bool border=false)
Generates a geode out of a Plane with a fixed size in direction of the vectors which span that plane.
void createCube(osg::ref_ptr< osg::Geometry > geometry, const WPosition &position, const WPosition &size, const WColor &color)
Create an arbitrary cube and insert it into the given geometry.
osg::ref_ptr< osg::Geometry > createUnitCubeAsLines(const WColor &color, bool asLines=false)
Creates a osg::Geometry containing an unit cube as line-strips, having 3D texture coordinates.