From 7aab621405b3041268a434752c52ba85dff2f74d Mon Sep 17 00:00:00 2001 From: Robert Osfield Date: Wed, 2 Apr 2003 10:50:15 +0000 Subject: [PATCH] Added support for min pixel size, max pixel size and max visable distance to osgSim::LightPointNode, the max pixel size from was originally in osg::LightPoint. Added additional get/set methods to osg::LightPointNode. Increased the compute pixel size by a ratio 1.41 (sqrtf(2)) to correlate the computed size with the actual size seen on screen. --- examples/osglightpoint/osglightpoint.cpp | 11 ++----- include/osgSim/LightPoint | 2 -- include/osgSim/LightPointNode | 32 ++++++++++++++++--- src/osg/CullStack.cpp | 8 ++--- src/osgPlugins/geo/ReaderWriterGEO.cpp | 2 +- src/osgSim/LightPoint.cpp | 6 ---- src/osgSim/LightPointNode.cpp | 40 ++++++++++++++++-------- 7 files changed, 62 insertions(+), 39 deletions(-) diff --git a/examples/osglightpoint/osglightpoint.cpp b/examples/osglightpoint/osglightpoint.cpp index 847ce3cf9..48762a544 100644 --- a/examples/osglightpoint/osglightpoint.cpp +++ b/examples/osglightpoint/osglightpoint.cpp @@ -5,6 +5,7 @@ #include #include #include +#include #include #include @@ -32,7 +33,7 @@ void addToLightPointNode(osgSim::LightPointNode& lpn,osgSim::LightPoint& start,o float rend = 0.0f; float rdelta = 1.0f/((float)noSteps-1.0f); - lpn._lightPointList.reserve(noSteps); + lpn.getLightPointList().reserve(noSteps); for(unsigned int i=0;iaddChild(osgDB::readNodeFiles(arguments)); rootnode->addChild(createLightPointsDatabase()); - if (!rootnode) - { - return 1; - } + // run optimization over the scene graph osgUtil::Optimizer optimzer; diff --git a/include/osgSim/LightPoint b/include/osgSim/LightPoint index 962fffb69..346c57ec3 100644 --- a/include/osgSim/LightPoint +++ b/include/osgSim/LightPoint @@ -45,7 +45,6 @@ class OSGSIM_EXPORT LightPoint const osg::Vec4& color, float intensity=1.0f, float radius=1.0f, - float maxPixelSize=30, Sector* sector=0, BlinkSequence* blinkSequence=0, BlendingMode blendingMode=BLENDED); @@ -61,7 +60,6 @@ class OSGSIM_EXPORT LightPoint osg::Vec4 _color; float _intensity; float _radius; - float _maxPixelSize; osg::ref_ptr _sector; osg::ref_ptr _blinkSequence; diff --git a/include/osgSim/LightPointNode b/include/osgSim/LightPointNode index 032a7c8f2..7b110c330 100644 --- a/include/osgSim/LightPointNode +++ b/include/osgSim/LightPointNode @@ -44,18 +44,35 @@ class OSGSIM_EXPORT LightPointNode : public osg::Node virtual void traverse(osg::NodeVisitor& nv); - + unsigned int addLightPoint(const LightPoint& lp); + void removeLightPoint(unsigned int pos); + + LightPoint& getLightPoint(unsigned int pos) { return _lightPointList[pos]; } const LightPoint& getLightPoint(unsigned int pos) const { return _lightPointList[pos]; } - void removeLightPoint(unsigned int pos); - - void removeLightPoints(LightPointList::iterator start,LightPointList::iterator end); - LightPointList _lightPointList; + void setLightPointList(const LightPointList& lpl) { _lightPointList=lpl; } + + LightPointList& getLightPointList() { return _lightPointList; } + + const LightPointList& getLightPointList() const { return _lightPointList; } + + + void setMinPixelSize(float minPixelSize) { _minPixelSize = minPixelSize; } + + float getMinPixelSize() const { return _minPixelSize; } + + void setMaxPixelSize(float maxPixelSize) { _maxPixelSize = maxPixelSize; } + + float getMaxPixelSize() const { return _maxPixelSize; } + + void setMaxVisableDistance2(float maxVisableDistance2) { _maxVisableDistance2 = maxVisableDistance2; } + + float setMaxVisableDistance2() const { return _maxVisableDistance2; } protected: @@ -67,6 +84,11 @@ class OSGSIM_EXPORT LightPointNode : public osg::Node virtual bool computeBound() const; + LightPointList _lightPointList; + + float _minPixelSize; + float _maxPixelSize; + float _maxVisableDistance2; }; diff --git a/src/osg/CullStack.cpp b/src/osg/CullStack.cpp index 07003fc5f..053e523d2 100644 --- a/src/osg/CullStack.cpp +++ b/src/osg/CullStack.cpp @@ -96,11 +96,11 @@ void CullStack::pushCullingSet() float P23 = P(2,3); float P33 = P(3,3); osg::Vec4 pixelSizeVector(M(0,2)*P23, - M(1,2)*P23, - M(2,2)*P23, - M(3,2)*P23 + M(3,3)*P33); + M(1,2)*P23, + M(2,2)*P23, + M(3,2)*P23 + M(3,3)*P33); - float scaleRatio = 1.0f/sqrtf(scale_00.length2()+scale_10.length2()); + float scaleRatio = 0.701f/sqrtf(scale_00.length2()+scale_10.length2()); pixelSizeVector *= scaleRatio; diff --git a/src/osgPlugins/geo/ReaderWriterGEO.cpp b/src/osgPlugins/geo/ReaderWriterGEO.cpp index fd3f8421e..ff3404ae9 100644 --- a/src/osgPlugins/geo/ReaderWriterGEO.cpp +++ b/src/osgPlugins/geo/ReaderWriterGEO.cpp @@ -826,7 +826,7 @@ class ReaderWriterGEO : public ReaderWriter float blue=cls[2]/255.0f; //float alpha=1.0f; // cls[3]*frac/255.0f; osg::Vec4 colour(red,green,blue,1.0f); - lpn->addLightPoint(osgSim::LightPoint(true,coord_pool[idx],colour,1.0f,1.0f,30,0,0,osgSim::LightPoint::BLENDED)); + lpn->addLightPoint(osgSim::LightPoint(true,coord_pool[idx],colour,1.0f,1.0f,0,0,osgSim::LightPoint::BLENDED)); } else { // get colour from palette gfd=(*itr)->getField(GEO_DB_VRTX_COLOR_INDEX); // use color pool... int icp= gfd ? gfd->getInt() : 0; diff --git a/src/osgSim/LightPoint.cpp b/src/osgSim/LightPoint.cpp index 2cd40a42e..6f47240e6 100644 --- a/src/osgSim/LightPoint.cpp +++ b/src/osgSim/LightPoint.cpp @@ -21,7 +21,6 @@ LightPoint::LightPoint(): _color(1.0f,1.0f,1.0f,1.0f), _intensity(1.0f), _radius(1.0f), - _maxPixelSize(30), _sector(0), _blinkSequence(0), _blendingMode(BLENDED) @@ -34,7 +33,6 @@ LightPoint::LightPoint(const osg::Vec3& position,const osg::Vec4& color): _color(color), _intensity(1.0f), _radius(1.0f), - _maxPixelSize(30), _sector(0), _blinkSequence(0), _blendingMode(BLENDED) @@ -46,7 +44,6 @@ LightPoint::LightPoint(bool on, const osg::Vec4& color, float intensity, float radius, - float maxPixelSize, Sector* sector, BlinkSequence* blinkSequence, BlendingMode blendingMode): @@ -55,7 +52,6 @@ LightPoint::LightPoint(bool on, _color(color), _intensity(intensity), _radius(radius), - _maxPixelSize(maxPixelSize), _sector(sector), _blinkSequence(blinkSequence), _blendingMode(blendingMode) @@ -68,7 +64,6 @@ LightPoint::LightPoint(const LightPoint& lp): _color(lp._color), _intensity(lp._intensity), _radius(lp._radius), - _maxPixelSize(lp._maxPixelSize), _sector(lp._sector), _blinkSequence(lp._blinkSequence), _blendingMode(lp._blendingMode) @@ -82,7 +77,6 @@ LightPoint& LightPoint::operator = (const LightPoint& lp) _color = lp._color; _intensity = lp._intensity; _radius = lp._radius; - _maxPixelSize = lp._maxPixelSize; _sector = lp._sector; _blinkSequence = lp._blinkSequence; _blendingMode = lp._blendingMode; diff --git a/src/osgSim/LightPointNode.cpp b/src/osgSim/LightPointNode.cpp index 06989a200..38e15d5dd 100644 --- a/src/osgSim/LightPointNode.cpp +++ b/src/osgSim/LightPointNode.cpp @@ -26,14 +26,20 @@ using namespace osgSim; -LightPointNode::LightPointNode() +LightPointNode::LightPointNode(): + _minPixelSize(0.0f), + _maxPixelSize(30.0f), + _maxVisableDistance2(FLT_MAX) { } /** Copy constructor using CopyOp to manage deep vs shallow copy.*/ LightPointNode::LightPointNode(const LightPointNode& lpn,const osg::CopyOp& copyop): osg::Node(lpn,copyop), - _lightPointList(lpn._lightPointList) + _lightPointList(lpn._lightPointList), + _minPixelSize(lpn._minPixelSize), + _maxPixelSize(lpn._maxPixelSize), + _maxVisableDistance2(lpn._maxVisableDistance2) { } @@ -55,11 +61,6 @@ void LightPointNode::removeLightPoint(unsigned int pos) dirtyBound(); } -void LightPointNode::removeLightPoints(LightPointList::iterator start,LightPointList::iterator end) -{ - _lightPointList.erase(start,end); -} - bool LightPointNode::computeBound() const { _bsphere.init(); @@ -81,9 +82,13 @@ bool LightPointNode::computeBound() const itr!=_lightPointList.end(); ++itr) { - _bsphere.expandRadiusBy(itr->_position); + osg::Vec3 dv(itr->_position-_bsphere.center()); + float radius = dv.length()+itr->_radius; + if (_bsphere.radius()_maxVisableDistance2) continue; + } + + osg::Vec4 color = lp._color; // check the sector. @@ -265,7 +277,9 @@ void LightPointNode::traverse(osg::NodeVisitor& nv) // adjust pixel size to account for intensity. if (intensity!=1.0) pixelSize *= sqrt(intensity); - + + // round up to the minimum pixel size if required. + if (pixelSize<_minPixelSize) pixelSize = _minPixelSize; osg::Vec3 xpos(position*matrix); @@ -281,7 +295,7 @@ void LightPointNode::traverse(osg::NodeVisitor& nv) drawable->addBlendedLightPoint(0, xpos,color); } - else if (pixelSizeaddBlendedLightPoint((unsigned int)(lp._maxPixelSize-1.0), xpos,color); + drawable->addBlendedLightPoint((unsigned int)(_maxPixelSize-1.0), xpos,color); } } else // ADDITIVE blending. @@ -310,7 +324,7 @@ void LightPointNode::traverse(osg::NodeVisitor& nv) drawable->addAdditiveLightPoint(0, xpos,color); } - else if (pixelSizeaddAdditiveLightPoint((unsigned int)(lp._maxPixelSize-1.0), xpos,color); + drawable->addAdditiveLightPoint((unsigned int)(_maxPixelSize-1.0), xpos,color); } } }