-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathPoints.cpp
More file actions
72 lines (61 loc) · 2.45 KB
/
Copy pathPoints.cpp
File metadata and controls
72 lines (61 loc) · 2.45 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
/////////////////////////////////////////////////////////////////
/// @file Points.cpp
/// @author Chris L Baker (clb) <chris@chimail.net>
/// @date 2014.05.20
/// @brief Provide a simple interface to draw a point
///
/// @attention Copyright (C) 2014
/// @attention All rights reserved
/////////////////////////////////////////////////////////////////
#include "Colors.h"
#include "Points.h"
#include <osg/Geometry>
#include <osg/Point>
#include <osg/Geode>
#include <osg/Version>
namespace d3
{
/////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////
osg::ref_ptr<osg::Node> get(const PointVec_t& points,
const float size)
{
// the color array
osg::ref_ptr<osg::Vec4Array> osgColors( new osg::Vec4Array() );
osgColors->reserve(points.size());
// the vertex array
osg::ref_ptr<osg::Vec3Array> verts( new osg::Vec3Array() );
verts->reserve(points.size());
// the actual cloud indices
osg::ref_ptr<osg::DrawElementsUInt>
theCloud( new osg::DrawElementsUInt(osg::PrimitiveSet::POINTS, 0) );
theCloud->reserveElements(points.size());
// add the points and colors - only iterate the list once so we know we have
// the right number of points and colors
unsigned int index(0);
for ( const Point& pt : points )
{
verts->push_back(pt.location);
osgColors->push_back(pt.color);
theCloud->push_back(index++);
}
// now add all this stuff to the geometry object
osg::ref_ptr<osg::Geometry> cloudGeometry( new osg::Geometry() );
cloudGeometry->setVertexArray(verts);
#if OSG_MIN_VERSION_REQUIRED(3,2,0)
cloudGeometry->setColorArray(osgColors, osg::Array::Binding::BIND_PER_VERTEX);
#else // OSG_MIN_VERSION_REQUIRED(3,2,0)
cloudGeometry->setColorArray(osgColors);
cloudGeometry->setColorBinding(osg::Geometry::BIND_PER_VERTEX);
#endif // OSG_MIN_VERSION_REQUIRED(3,2,0)
cloudGeometry->addPrimitiveSet(theCloud);
// set the state - point size and lighting
osg::ref_ptr<osg::StateSet> cloudStateSet( cloudGeometry->getOrCreateStateSet() );
cloudStateSet->setAttribute(new osg::Point(size), osg::StateAttribute::ON);
cloudStateSet->setMode(GL_LIGHTING, osg::StateAttribute::OFF);
// build the geode to return
osg::ref_ptr<osg::Geode> geode(new osg::Geode());
geode->addDrawable(cloudGeometry);
return geode;
};
} // namespace d3