00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019 #include "PointCloud.h"
00020
00021 namespace uvsim
00022 {
00023
00024 void PointCloudCallback::operator()(osg::Node *node, osg::NodeVisitor *nv)
00025 {
00026 osg::ref_ptr<PointCloud> pointCloud = dynamic_cast<PointCloud*>
00027 (node->getUserData());
00028 if (pointCloud.get())
00029 {
00030
00031 (pointCloud.get())->updateSize();
00032 }
00033
00034 }
00035
00036 PointCloud::PointCloud()
00037 {
00038 }
00039
00040 PointCloud::PointCloud(int pointSize, osg::Vec3Array * points, osg::Vec4Array * colors) :
00041 points(points), root(new osg::PositionAttitudeTransform), geom(new osg::Geometry),
00042 geode(new osg::Geode), colors(colors),
00043 drawArrays(new osg::DrawArrays(osg::PrimitiveSet::POINTS, 0, points->size()))
00044 {
00045 root->setUpdateCallback(new PointCloudCallback);
00046 root->addChild(geode.get());
00047 geode->setStateSet(makeStateSet(pointSize));
00048 geode->addDrawable(geom.get());
00049 geom->setVertexArray(points);
00050 geom->setColorArray(colors);
00051 geom->setColorBinding(osg::Geometry::BIND_PER_VERTEX);
00052 geom->addPrimitiveSet(drawArrays.get());
00053 }
00054
00055 PointCloud::~PointCloud()
00056 {
00057 }
00058
00059 void PointCloud::updateSize()
00060 {
00061 (drawArrays.get())->setCount(points->size());
00062 (geom.get())->dirtyDisplayList();
00063 }
00064
00065 osg::StateSet* PointCloud::makeStateSet(float size)
00066 {
00067 osg::StateSet *set = new osg::StateSet();
00068
00070
00071
00072
00073
00074
00076 osg::PointSprite *sprite = new osg::PointSprite();
00077 set->setTextureAttributeAndModes(0, sprite, osg::StateAttribute::ON);
00078
00080 osg::Point *point = new osg::Point();
00081 point->setSize(size);
00082 set->setAttribute(point);
00083
00085 set->setMode(GL_DEPTH_TEST, osg::StateAttribute::OFF);
00086 set->setMode(GL_LIGHTING, osg::StateAttribute::OFF);
00087
00089 osg::Texture2D *tex = new osg::Texture2D();
00090 tex->setImage(osgDB::readImageFile(std::string(DATADIR)+="/textures/particle.rgb"));
00091 set->setTextureAttributeAndModes(0, tex, osg::StateAttribute::ON);
00092
00093 return set;
00094 }
00095
00096 }
00097
00098
00099