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:
Robert Osfield 2007-03-29 19:42:07 +00:00
parent 5ba0e5b930
commit a2ecb93c2b
6 changed files with 299 additions and 113 deletions

View File

@ -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;
};

View File

@ -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

View File

@ -19,6 +19,31 @@ Shape::~Shape()
{
}
HeightField::HeightField():
_columns(0),
_rows(0),
_origin(0.0f,0.0f,0.0f),
_dx(1.0f),
_dy(1.0f),
_skirtHeight(0.0f),
_borderWidth(0)
{
_heights = new osg::FloatArray;
}
HeightField::HeightField(const HeightField& mesh,const CopyOp& copyop):
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(new osg::FloatArray(*mesh._heights))
{
}
HeightField::~HeightField()
{
}
@ -28,7 +53,7 @@ void HeightField::allocate(unsigned int numColumns,unsigned int numRows)
{
if (_columns!=numColumns || _rows!=numRows)
{
_heights.resize(numColumns*numRows);
_heights->resize(numColumns*numRows);
}
_columns=numColumns;
_rows=numRows;

View File

@ -12,6 +12,7 @@
*/
#include <osgTerrain/Layer>
#include <osg/Notify>
using namespace osgTerrain;
@ -78,6 +79,30 @@ void ImageLayer::setImage(osg::Image* image)
}
bool ImageLayer::getValue(unsigned int i, unsigned int j, float& value) const
{
osg::notify(osg::NOTICE)<<"Not implemented yet"<<std::endl;
return false;
}
bool ImageLayer::getValue(unsigned int i, unsigned int j, osg::Vec2& value) const
{
osg::notify(osg::NOTICE)<<"Not implemented yet"<<std::endl;
return false;
}
bool ImageLayer::getValue(unsigned int i, unsigned int j, osg::Vec3& value) const
{
osg::notify(osg::NOTICE)<<"Not implemented yet"<<std::endl;
return false;
}
bool ImageLayer::getValue(unsigned int i, unsigned int j, osg::Vec4& value) const
{
osg::notify(osg::NOTICE)<<"Not implemented yet"<<std::endl;
return false;
}
/////////////////////////////////////////////////////////////////////////////
//
// HieghtFieldLayer
@ -98,21 +123,27 @@ void HeightFieldLayer::setHeightField(osg::HeightField* hf)
_heightField = hf;
}
/////////////////////////////////////////////////////////////////////////////
//
// ImageLayer
//
ArrayLayer::ArrayLayer()
bool HeightFieldLayer::getValue(unsigned int i, unsigned int j, float& value) const
{
osg::notify(osg::NOTICE)<<"Not implemented yet"<<std::endl;
return false;
}
ArrayLayer::ArrayLayer(const ArrayLayer& arrayLayer,const osg::CopyOp& copyop):
Layer(arrayLayer,copyop),
_array(arrayLayer._array)
bool HeightFieldLayer::getValue(unsigned int i, unsigned int j, osg::Vec2& value) const
{
osg::notify(osg::NOTICE)<<"Not implemented yet"<<std::endl;
return false;
}
void ArrayLayer::setArray(osg::Array* array)
bool HeightFieldLayer::getValue(unsigned int i, unsigned int j, osg::Vec3& value) const
{
_array = array;
osg::notify(osg::NOTICE)<<"Not implemented yet"<<std::endl;
return false;
}
bool HeightFieldLayer::getValue(unsigned int i, unsigned int j, osg::Vec4& value) const
{
osg::notify(osg::NOTICE)<<"Not implemented yet"<<std::endl;
return false;
}

View File

@ -818,6 +818,26 @@ BEGIN_OBJECT_REFLECTOR(osg::HeightField)
__float__getYInterval,
"",
"");
I_Method0(osg::FloatArray *, getFloatArray,
Properties::NON_VIRTUAL,
__osg_FloatArray_P1__getFloatArray,
"Get the FloatArray height data. ",
"");
I_Method0(const osg::FloatArray *, getFloatArray,
Properties::NON_VIRTUAL,
__C5_osg_FloatArray_P1__getFloatArray,
"Get the const sFloatArray height data. ",
"");
I_Method0(osg::HeightField::HeightList &, getHeightList,
Properties::NON_VIRTUAL,
__HeightList_R1__getHeightList,
"",
"");
I_Method0(const osg::HeightField::HeightList &, getHeightList,
Properties::NON_VIRTUAL,
__C5_HeightList_R1__getHeightList,
"",
"");
I_Method1(void, setSkirtHeight, IN, float, skirtHeight,
Properties::NON_VIRTUAL,
__void__setSkirtHeight__float,
@ -873,16 +893,6 @@ BEGIN_OBJECT_REFLECTOR(osg::HeightField)
__float__getHeight__unsigned_int__unsigned_int,
"",
"");
I_Method0(osg::HeightField::HeightList &, getHeightList,
Properties::NON_VIRTUAL,
__HeightList_R1__getHeightList,
"",
"");
I_Method0(const osg::HeightField::HeightList &, getHeightList,
Properties::NON_VIRTUAL,
__C5_HeightList_R1__getHeightList,
"",
"");
I_Method2(osg::Vec3, getVertex, IN, unsigned int, c, IN, unsigned int, r,
Properties::NON_VIRTUAL,
__Vec3__getVertex__unsigned_int__unsigned_int,
@ -901,6 +911,9 @@ BEGIN_OBJECT_REFLECTOR(osg::HeightField)
I_SimpleProperty(unsigned int, BorderWidth,
__unsigned_int__getBorderWidth,
__void__setBorderWidth__unsigned_int);
I_SimpleProperty(osg::FloatArray *, FloatArray,
__osg_FloatArray_P1__getFloatArray,
0);
I_IndexedProperty(float, Height,
__float__getHeight__unsigned_int__unsigned_int,
__void__setHeight__unsigned_int__unsigned_int__float,

View File

@ -10,12 +10,14 @@
#include <osgIntrospection/StaticMethodInfo>
#include <osgIntrospection/Attributes>
#include <osg/Array>
#include <osg/BoundingSphere>
#include <osg/CopyOp>
#include <osg/Image>
#include <osg/Object>
#include <osg/Shape>
#include <osg/Vec2>
#include <osg/Vec3>
#include <osg/Vec4>
#include <osgTerrain/Layer>
#include <osgTerrain/Locator>
@ -27,35 +29,6 @@
#undef OUT
#endif
BEGIN_OBJECT_REFLECTOR(osgTerrain::ArrayLayer)
I_BaseType(osgTerrain::Layer);
I_Constructor0(____ArrayLayer,
"",
"");
I_ConstructorWithDefaults2(IN, const osgTerrain::ArrayLayer &, x, , IN, const osg::CopyOp &, copyop, osg::CopyOp::SHALLOW_COPY,
____ArrayLayer__C5_ArrayLayer_R1__C5_osg_CopyOp_R1,
"Copy constructor using CopyOp to manage deep vs shallow copy. ",
"");
I_Method1(void, setArray, IN, osg::Array *, array,
Properties::NON_VIRTUAL,
__void__setArray__osg_Array_P1,
"",
"");
I_Method0(osg::Array *, getArray,
Properties::NON_VIRTUAL,
__osg_Array_P1__getArray,
"",
"");
I_Method0(const osg::Array *, getArray,
Properties::NON_VIRTUAL,
__C5_osg_Array_P1__getArray,
"",
"");
I_SimpleProperty(osg::Array *, Array,
__osg_Array_P1__getArray,
__void__setArray__osg_Array_P1);
END_REFLECTOR
BEGIN_OBJECT_REFLECTOR(osgTerrain::HeightFieldLayer)
I_BaseType(osgTerrain::Layer);
I_Constructor0(____HeightFieldLayer,
@ -80,6 +53,36 @@ BEGIN_OBJECT_REFLECTOR(osgTerrain::HeightFieldLayer)
__C5_osg_HeightField_P1__getHeightField,
"",
"");
I_Method0(unsigned int, getNumColumns,
Properties::VIRTUAL,
__unsigned_int__getNumColumns,
"",
"");
I_Method0(unsigned int, getNumRows,
Properties::VIRTUAL,
__unsigned_int__getNumRows,
"",
"");
I_Method3(bool, getValue, IN, unsigned int, i, IN, unsigned int, j, IN, float &, value,
Properties::VIRTUAL,
__bool__getValue__unsigned_int__unsigned_int__float_R1,
"",
"");
I_Method3(bool, getValue, IN, unsigned int, i, IN, unsigned int, j, IN, osg::Vec2 &, value,
Properties::VIRTUAL,
__bool__getValue__unsigned_int__unsigned_int__osg_Vec2_R1,
"",
"");
I_Method3(bool, getValue, IN, unsigned int, i, IN, unsigned int, j, IN, osg::Vec3 &, value,
Properties::VIRTUAL,
__bool__getValue__unsigned_int__unsigned_int__osg_Vec3_R1,
"",
"");
I_Method3(bool, getValue, IN, unsigned int, i, IN, unsigned int, j, IN, osg::Vec4 &, value,
Properties::VIRTUAL,
__bool__getValue__unsigned_int__unsigned_int__osg_Vec4_R1,
"",
"");
I_SimpleProperty(osg::HeightField *, HeightField,
__osg_HeightField_P1__getHeightField,
__void__setHeightField__osg_HeightField_P1);
@ -109,6 +112,36 @@ BEGIN_OBJECT_REFLECTOR(osgTerrain::ImageLayer)
__C5_osg_Image_P1__getImage,
"",
"");
I_Method0(unsigned int, getNumColumns,
Properties::VIRTUAL,
__unsigned_int__getNumColumns,
"",
"");
I_Method0(unsigned int, getNumRows,
Properties::VIRTUAL,
__unsigned_int__getNumRows,
"",
"");
I_Method3(bool, getValue, IN, unsigned int, i, IN, unsigned int, j, IN, float &, value,
Properties::VIRTUAL,
__bool__getValue__unsigned_int__unsigned_int__float_R1,
"",
"");
I_Method3(bool, getValue, IN, unsigned int, i, IN, unsigned int, j, IN, osg::Vec2 &, value,
Properties::VIRTUAL,
__bool__getValue__unsigned_int__unsigned_int__osg_Vec2_R1,
"",
"");
I_Method3(bool, getValue, IN, unsigned int, i, IN, unsigned int, j, IN, osg::Vec3 &, value,
Properties::VIRTUAL,
__bool__getValue__unsigned_int__unsigned_int__osg_Vec3_R1,
"",
"");
I_Method3(bool, getValue, IN, unsigned int, i, IN, unsigned int, j, IN, osg::Vec4 &, value,
Properties::VIRTUAL,
__bool__getValue__unsigned_int__unsigned_int__osg_Vec4_R1,
"",
"");
I_SimpleProperty(osg::Image *, Image,
__osg_Image_P1__getImage,
__void__setImage__osg_Image_P1);
@ -163,6 +196,46 @@ BEGIN_OBJECT_REFLECTOR(osgTerrain::Layer)
__C5_Locator_P1__getLocator,
"",
"");
I_Method0(unsigned int, getNumColumns,
Properties::VIRTUAL,
__unsigned_int__getNumColumns,
"",
"");
I_Method0(unsigned int, getNumRows,
Properties::VIRTUAL,
__unsigned_int__getNumRows,
"",
"");
I_Method3(bool, getValue, IN, unsigned, int, IN, unsigned, int, IN, float &, x,
Properties::VIRTUAL,
__bool__getValue__unsigned__unsigned__float_R1,
"",
"");
I_Method3(bool, getValue, IN, unsigned, int, IN, unsigned, int, IN, osg::Vec2 &, x,
Properties::VIRTUAL,
__bool__getValue__unsigned__unsigned__osg_Vec2_R1,
"",
"");
I_Method3(bool, getValue, IN, unsigned, int, IN, unsigned, int, IN, osg::Vec3 &, x,
Properties::VIRTUAL,
__bool__getValue__unsigned__unsigned__osg_Vec3_R1,
"",
"");
I_Method3(bool, getValue, IN, unsigned, int, IN, unsigned, int, IN, osg::Vec4 &, x,
Properties::VIRTUAL,
__bool__getValue__unsigned__unsigned__osg_Vec4_R1,
"",
"");
I_Method6(void, computeIndices, IN, double, ndc_x, IN, double, ndc_y, IN, unsigned int &, i, IN, unsigned int &, j, IN, double &, ir, IN, double &, jr,
Properties::NON_VIRTUAL,
__void__computeIndices__double__double__unsigned_int_R1__unsigned_int_R1__double_R1__double_R1,
"",
"");
I_Method3(bool, getInterpolatedValue, IN, double, ndc_x, IN, double, ndc_y, IN, float &, value,
Properties::NON_VIRTUAL,
__bool__getInterpolatedValue__double__double__float_R1,
"",
"");
I_Method0(osg::BoundingSphere, computeBound,
Properties::VIRTUAL,
__osg_BoundingSphere__computeBound,