Converted osg::HeightField across to using a osg::FloatArray internally to enable
it to be assigned as a vertex attribute array to an osg::Geometry. Removed the osgTerrain::ArrayLayer as its no longer required thanks to the above change which makes the osgTerrain::HeightFieldLayer more flexible. Updated wrappers
This commit is contained in:
@@ -478,25 +478,9 @@ class OSG_EXPORT HeightField : public Shape
|
||||
{
|
||||
public:
|
||||
|
||||
HeightField():
|
||||
_columns(0),
|
||||
_rows(0),
|
||||
_origin(0.0f,0.0f,0.0f),
|
||||
_dx(1.0f),
|
||||
_dy(1.0f),
|
||||
_skirtHeight(0.0f),
|
||||
_borderWidth(0) {}
|
||||
HeightField();
|
||||
|
||||
HeightField(const HeightField& mesh,const CopyOp& copyop=CopyOp::SHALLOW_COPY):
|
||||
Shape(mesh,copyop),
|
||||
_columns(mesh._columns),
|
||||
_rows(mesh._rows),
|
||||
_origin(mesh._origin),
|
||||
_dx(mesh._dx),
|
||||
_dy(mesh._dy),
|
||||
_skirtHeight(mesh._skirtHeight),
|
||||
_borderWidth(mesh._borderWidth),
|
||||
_heights(mesh._heights) {}
|
||||
HeightField(const HeightField& mesh,const CopyOp& copyop=CopyOp::SHALLOW_COPY);
|
||||
|
||||
META_Shape(osg, HeightField);
|
||||
|
||||
@@ -515,6 +499,16 @@ class OSG_EXPORT HeightField : public Shape
|
||||
|
||||
inline void setYInterval(float dy) { _dy = dy; }
|
||||
inline float getYInterval() const { return _dy; }
|
||||
|
||||
/** Get the FloatArray height data.*/
|
||||
osg::FloatArray* getFloatArray() { return _heights.get(); }
|
||||
|
||||
/** Get the const sFloatArray height data.*/
|
||||
const osg::FloatArray* getFloatArray() const { return _heights.get(); }
|
||||
|
||||
HeightList& getHeightList() { return *_heights; }
|
||||
|
||||
const HeightList& getHeightList() const { return *_heights; }
|
||||
|
||||
/** Set the height of the skirt to render around the edge of HeightField.
|
||||
* The skirt is used as a means of disguising edge boundaries between adjacent HeightField,
|
||||
@@ -540,29 +534,26 @@ class OSG_EXPORT HeightField : public Shape
|
||||
/* set a single height point in the height field */
|
||||
inline void setHeight(unsigned int c,unsigned int r,float value)
|
||||
{
|
||||
_heights[c+r*_columns] = value;
|
||||
(*_heights)[c+r*_columns] = value;
|
||||
}
|
||||
|
||||
/* Get address of single height point in the height field, allows user to change. */
|
||||
inline float& getHeight(unsigned int c,unsigned int r)
|
||||
{
|
||||
return _heights[c+r*_columns];
|
||||
return (*_heights)[c+r*_columns];
|
||||
}
|
||||
|
||||
/* Get value of single height point in the height field, not editable. */
|
||||
inline float getHeight(unsigned int c,unsigned int r) const
|
||||
{
|
||||
return _heights[c+r*_columns];
|
||||
return (*_heights)[c+r*_columns];
|
||||
}
|
||||
|
||||
HeightList& getHeightList() { return _heights; }
|
||||
const HeightList& getHeightList() const { return _heights; }
|
||||
|
||||
inline Vec3 getVertex(unsigned int c,unsigned int r) const
|
||||
{
|
||||
return Vec3(_origin.x()+getXInterval()*(float)c,
|
||||
_origin.y()+getYInterval()*(float)r,
|
||||
_origin.z()+_heights[c+r*_columns]);
|
||||
_origin.z()+(*_heights)[c+r*_columns]);
|
||||
}
|
||||
|
||||
Vec3 getNormal(unsigned int c,unsigned int r) const;
|
||||
@@ -573,17 +564,17 @@ class OSG_EXPORT HeightField : public Shape
|
||||
|
||||
virtual ~HeightField();
|
||||
|
||||
unsigned int _columns,_rows;
|
||||
unsigned int _columns,_rows;
|
||||
|
||||
osg::Vec3 _origin;
|
||||
float _dx;
|
||||
float _dy;
|
||||
osg::Vec3 _origin;
|
||||
float _dx;
|
||||
float _dy;
|
||||
|
||||
float _skirtHeight;
|
||||
unsigned int _borderWidth;
|
||||
float _skirtHeight;
|
||||
unsigned int _borderWidth;
|
||||
|
||||
Quat _rotation;
|
||||
HeightList _heights;
|
||||
Quat _rotation;
|
||||
osg::ref_ptr<osg::FloatArray> _heights;
|
||||
|
||||
};
|
||||
|
||||
|
||||
@@ -40,6 +40,72 @@ class OSGTERRAIN_EXPORT Layer : public osg::Object
|
||||
|
||||
const Locator* getLocator() const { return _locator.get(); }
|
||||
|
||||
virtual unsigned int getNumColumns() const { return 0; }
|
||||
virtual unsigned int getNumRows() const { return 0; }
|
||||
|
||||
virtual bool getValue(unsigned int /*i*/, unsigned int /*j*/, float& /*value*/) const { return false; }
|
||||
virtual bool getValue(unsigned int /*i*/, unsigned int /*j*/, osg::Vec2& /*value*/) const { return false; }
|
||||
virtual bool getValue(unsigned int /*i*/, unsigned int /*j*/, osg::Vec3& /*value*/) const { return false; }
|
||||
virtual bool getValue(unsigned int /*i*/, unsigned int /*j*/, osg::Vec4& /*value*/) const { return false; }
|
||||
|
||||
inline void computeIndices(double ndc_x, double ndc_y, unsigned int& i, unsigned int& j, double& ir, double& jr)
|
||||
{
|
||||
ndc_x *= double(getNumColumns()-1);
|
||||
ndc_y *= double(getNumRows()-1);
|
||||
i = (unsigned int)(ndc_x);
|
||||
j = (unsigned int)(ndc_y);
|
||||
ir = ndc_x - double(i);
|
||||
jr = ndc_y - double(j);
|
||||
}
|
||||
|
||||
|
||||
inline bool getInterpolatedValue(double ndc_x, double ndc_y, float& value)
|
||||
{
|
||||
unsigned int i,j;
|
||||
double ir, jr;
|
||||
computeIndices(ndc_x, ndc_y, i, j, ir, jr);
|
||||
value = 0.0f;
|
||||
double div = 0.0f;
|
||||
float v,r;
|
||||
|
||||
r = (1.0f-ir)*(1.0f-jr);
|
||||
if (r>0.0 && getValue(i,j,v))
|
||||
{
|
||||
value += v*r;
|
||||
div += r;
|
||||
}
|
||||
|
||||
r = (ir)*(1.0f-jr);
|
||||
if (r>0.0 && getValue(i+1,j,v))
|
||||
{
|
||||
value += v*r;
|
||||
div += r;
|
||||
}
|
||||
|
||||
r = (ir)*(jr);
|
||||
if (r>0.0 && getValue(i+1,j+1,v))
|
||||
{
|
||||
value += v*r;
|
||||
div += r;
|
||||
}
|
||||
|
||||
r = (1.0f-ir)*(jr);
|
||||
if (r>0.0 && getValue(i,j+1,v))
|
||||
{
|
||||
value += v*r;
|
||||
div += r;
|
||||
}
|
||||
|
||||
if (div != 0.0)
|
||||
{
|
||||
value /= div;
|
||||
return true;
|
||||
}
|
||||
|
||||
value = 0.0;
|
||||
return false;
|
||||
}
|
||||
|
||||
virtual osg::BoundingSphere computeBound() const;
|
||||
|
||||
protected:
|
||||
@@ -61,11 +127,17 @@ class OSGTERRAIN_EXPORT ImageLayer : public Layer
|
||||
|
||||
|
||||
void setImage(osg::Image* image);
|
||||
|
||||
osg::Image* getImage() { return _image.get(); }
|
||||
|
||||
const osg::Image* getImage() const { return _image.get(); }
|
||||
|
||||
virtual unsigned int getNumColumns() const { return _image.valid() ? _image->s() : 0; }
|
||||
virtual unsigned int getNumRows() const { return _image.valid() ? _image->t() : 0; }
|
||||
|
||||
virtual bool getValue(unsigned int i, unsigned int j, float& value) const;
|
||||
virtual bool getValue(unsigned int i, unsigned int j, osg::Vec2& value) const;
|
||||
virtual bool getValue(unsigned int i, unsigned int j, osg::Vec3& value) const;
|
||||
virtual bool getValue(unsigned int i, unsigned int j, osg::Vec4& value) const;
|
||||
|
||||
protected:
|
||||
|
||||
virtual ~ImageLayer() {}
|
||||
@@ -85,11 +157,17 @@ class OSGTERRAIN_EXPORT HeightFieldLayer : public Layer
|
||||
|
||||
|
||||
void setHeightField(osg::HeightField* hf);
|
||||
|
||||
osg::HeightField* getHeightField() { return _heightField.get(); }
|
||||
|
||||
const osg::HeightField* getHeightField() const { return _heightField.get(); }
|
||||
|
||||
virtual unsigned int getNumColumns() const { return _heightField.valid() ? _heightField->getNumColumns() : 0; }
|
||||
virtual unsigned int getNumRows() const { return _heightField.valid() ? _heightField->getNumRows() : 0; }
|
||||
|
||||
virtual bool getValue(unsigned int i, unsigned int j, float& value) const;
|
||||
virtual bool getValue(unsigned int i, unsigned int j, osg::Vec2& value) const;
|
||||
virtual bool getValue(unsigned int i, unsigned int j, osg::Vec3& value) const;
|
||||
virtual bool getValue(unsigned int i, unsigned int j, osg::Vec4& value) const;
|
||||
|
||||
protected:
|
||||
|
||||
virtual ~HeightFieldLayer() {}
|
||||
@@ -98,31 +176,6 @@ class OSGTERRAIN_EXPORT HeightFieldLayer : public Layer
|
||||
|
||||
};
|
||||
|
||||
|
||||
class OSGTERRAIN_EXPORT ArrayLayer : public Layer
|
||||
{
|
||||
public:
|
||||
|
||||
ArrayLayer();
|
||||
|
||||
/** Copy constructor using CopyOp to manage deep vs shallow copy.*/
|
||||
ArrayLayer(const ArrayLayer&,const osg::CopyOp& copyop=osg::CopyOp::SHALLOW_COPY);
|
||||
|
||||
|
||||
void setArray(osg::Array* array);
|
||||
|
||||
osg::Array* getArray() { return _array.get(); }
|
||||
|
||||
const osg::Array* getArray() const { return _array.get(); }
|
||||
|
||||
protected:
|
||||
|
||||
virtual ~ArrayLayer() {}
|
||||
|
||||
osg::ref_ptr<osg::Array> _array;
|
||||
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user