*** empty log message ***
This commit is contained in:
@@ -15,6 +15,16 @@
|
||||
|
||||
using namespace osg;
|
||||
|
||||
void HeightField::allocateGrid(unsigned int numColumns,unsigned int numRows)
|
||||
{
|
||||
if (_columns!=numColumns || _rows!=numRows)
|
||||
{
|
||||
_heights.resize(numColumns*numRows);
|
||||
}
|
||||
_columns=numColumns;
|
||||
_rows=numRows;
|
||||
}
|
||||
|
||||
Vec3 HeightField::getNormal(unsigned int c,unsigned int r) const
|
||||
{
|
||||
// four point normal generation.
|
||||
@@ -53,27 +63,4 @@ Vec3 HeightField::getNormal(unsigned int c,unsigned int r) const
|
||||
return normal;
|
||||
}
|
||||
|
||||
Grid::Grid()
|
||||
{
|
||||
}
|
||||
|
||||
Grid::Grid(const Grid& mesh,const CopyOp& copyop):
|
||||
HeightField(mesh,copyop)
|
||||
{
|
||||
_heights = mesh._heights;
|
||||
}
|
||||
|
||||
Grid::~Grid()
|
||||
{
|
||||
}
|
||||
|
||||
void Grid::allocateGrid(unsigned int numColumns,unsigned int numRows)
|
||||
{
|
||||
if (_columns!=numColumns || _rows!=numRows)
|
||||
{
|
||||
_heights.resize(numColumns*numRows);
|
||||
}
|
||||
_columns=numColumns;
|
||||
_rows=numRows;
|
||||
}
|
||||
|
||||
|
||||
@@ -42,18 +42,35 @@ class ReaderWriterGDAL : public osgDB::ReaderWriter
|
||||
int destHeight = osg::minimum(dataHeight,1024);
|
||||
|
||||
|
||||
osgDB::ImageOptions::TexCoordRange* texCoordRange = 0;
|
||||
|
||||
const osgDB::ImageOptions* imageOptions = dynamic_cast<const osgDB::ImageOptions*>(options);
|
||||
if (imageOptions)
|
||||
{
|
||||
std::cout<<"Got ImageOptions"<<std::endl;
|
||||
|
||||
int margin = 0;
|
||||
switch(imageOptions->_sourceImageWindowMode)
|
||||
{
|
||||
case(osgDB::ImageOptions::RATIO_WINDOW):
|
||||
windowX = osg::maximum((int)(floor((double)dataWidth * imageOptions->_sourceRatioWindow.windowX)),0);
|
||||
windowY = osg::maximum((int)(floor((double)dataHeight * imageOptions->_sourceRatioWindow.windowY)),0);
|
||||
windowWidth = osg::minimum((int)(ceil((double)dataWidth * (imageOptions->_sourceRatioWindow.windowX + imageOptions->_sourceRatioWindow.windowWidth))),dataWidth)-windowX;
|
||||
windowHeight = osg::minimum((int)(ceil((double)dataHeight * (imageOptions->_sourceRatioWindow.windowY + imageOptions->_sourceRatioWindow.windowHeight))),dataHeight)-windowY;
|
||||
{
|
||||
double desiredX = (double)dataWidth * imageOptions->_sourceRatioWindow.windowX;
|
||||
double desiredY = (double)dataHeight * imageOptions->_sourceRatioWindow.windowY;
|
||||
double desiredWidth = (double)dataWidth * imageOptions->_sourceRatioWindow.windowWidth;
|
||||
double desiredHeight = (double)dataHeight * imageOptions->_sourceRatioWindow.windowHeight;
|
||||
|
||||
windowX = osg::maximum((int)(floor(desiredX))-margin,0);
|
||||
windowY = osg::maximum((int)(floor(desiredY))-margin,0);
|
||||
windowWidth = osg::minimum((int)(ceil(desiredX + desiredWidth))+margin,dataWidth)-windowX;
|
||||
windowHeight = osg::minimum((int)(ceil(desiredY + desiredHeight))+margin,dataHeight)-windowY;
|
||||
|
||||
texCoordRange = new osgDB::ImageOptions::TexCoordRange;
|
||||
texCoordRange->set((desiredX-(double)windowX)/(double)windowWidth,
|
||||
((double)(windowY+windowHeight) -(desiredY+desiredHeight))/(double)windowHeight,
|
||||
(desiredWidth)/(double)windowWidth,
|
||||
(desiredHeight)/(double)windowHeight);
|
||||
std::cout<<"tex coord range "<<texCoordRange->_x<<" "<<texCoordRange->_y<<" "<<texCoordRange->_w<<" "<<texCoordRange->_h<<std::endl;
|
||||
}
|
||||
break;
|
||||
case(osgDB::ImageOptions::PIXEL_WINDOW):
|
||||
windowX = imageOptions->_sourcePixelWindow.windowX;
|
||||
@@ -145,6 +162,7 @@ class ReaderWriterGDAL : public osgDB::ReaderWriter
|
||||
else if (band->GetColorInterpretation()==GCI_GreenBand) bandGreen = band;
|
||||
else if (band->GetColorInterpretation()==GCI_BlueBand) bandBlue = band;
|
||||
else if (band->GetColorInterpretation()==GCI_AlphaBand) bandAlpha = band;
|
||||
else bandGray = band;
|
||||
|
||||
// int gotMin,gotMax;
|
||||
// double minmax[2];
|
||||
@@ -281,7 +299,9 @@ class ReaderWriterGDAL : public osgDB::ReaderWriter
|
||||
dataType,
|
||||
(unsigned char *)imageData,
|
||||
osg::Image::USE_NEW_DELETE);
|
||||
|
||||
|
||||
if (texCoordRange) image->setUserData(texCoordRange);
|
||||
|
||||
image->flipVertical();
|
||||
|
||||
return image;
|
||||
|
||||
@@ -73,6 +73,21 @@ bool Drawable_readLocalData(Object& obj, Input& fr)
|
||||
}
|
||||
}
|
||||
|
||||
if (fr[0].matchWord("useVertexBufferObjects"))
|
||||
{
|
||||
if (fr[1].matchWord("TRUE"))
|
||||
{
|
||||
drawable.setUseVertexBufferObjects(true);
|
||||
fr+=2;
|
||||
iteratorAdvanced = true;
|
||||
}
|
||||
else if (fr[1].matchWord("FALSE"))
|
||||
{
|
||||
drawable.setUseVertexBufferObjects(false);
|
||||
fr+=2;
|
||||
iteratorAdvanced = true;
|
||||
}
|
||||
}
|
||||
|
||||
return iteratorAdvanced;
|
||||
}
|
||||
@@ -103,6 +118,9 @@ bool Drawable_writeLocalData(const Object& obj, Output& fw)
|
||||
if (drawable.getUseDisplayList()) fw << "TRUE" << std::endl;
|
||||
else fw << "FALSE" << std::endl;
|
||||
|
||||
fw.indent()<<"useVertexBufferObjects ";
|
||||
if (drawable.getUseVertexBufferObjects()) fw << "TRUE" << std::endl;
|
||||
else fw << "FALSE" << std::endl;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -305,14 +305,25 @@ bool HeightField_writeLocalData(const Object& obj, Output& fw);
|
||||
//register the read and write functions with the osgDB::Registry.
|
||||
RegisterDotOsgWrapperProxy g_HeightFieldFuncProxy
|
||||
(
|
||||
0,
|
||||
new osg::HeightField,
|
||||
"HeightField",
|
||||
"Object HieghtField",
|
||||
"Object HeightField",
|
||||
&HeightField_readLocalData,
|
||||
&HeightField_writeLocalData,
|
||||
DotOsgWrapper::READ_AND_WRITE
|
||||
);
|
||||
|
||||
//register the read and write functions with the osgDB::Registry.
|
||||
RegisterDotOsgWrapperProxy g_GridFuncProxy
|
||||
(
|
||||
new osg::HeightField,
|
||||
"Grid",
|
||||
"Object HeightField",
|
||||
0,
|
||||
0,
|
||||
DotOsgWrapper::READ_AND_WRITE
|
||||
);
|
||||
|
||||
bool HeightField_readLocalData(Object& obj, Input& fr)
|
||||
{
|
||||
bool iteratorAdvanced = false;
|
||||
@@ -359,49 +370,12 @@ bool HeightField_readLocalData(Object& obj, Input& fr)
|
||||
iteratorAdvanced = true;
|
||||
}
|
||||
|
||||
return iteratorAdvanced;
|
||||
}
|
||||
|
||||
bool HeightField_writeLocalData(const Object& obj, Output& fw)
|
||||
{
|
||||
const HeightField& heightfield = static_cast<const HeightField&>(obj);
|
||||
|
||||
fw.indent()<<"Origin "<<heightfield.getOrigin()<<std::endl;
|
||||
fw.indent()<<"XInterval "<<heightfield.getXInterval()<<std::endl;
|
||||
fw.indent()<<"YInterval "<<heightfield.getYInterval()<<std::endl;
|
||||
fw.indent()<<"Rotation "<<heightfield.getRotation()<<std::endl;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
// forward declare functions to use later.
|
||||
bool Grid_readLocalData(Object& obj, Input& fr);
|
||||
bool Grid_writeLocalData(const Object& obj, Output& fw);
|
||||
|
||||
//register the read and write functions with the osgDB::Registry.
|
||||
RegisterDotOsgWrapperProxy g_GridFuncProxy
|
||||
(
|
||||
new osg::Grid,
|
||||
"Grid",
|
||||
"Object HeightField Grid",
|
||||
&Grid_readLocalData,
|
||||
&Grid_writeLocalData,
|
||||
DotOsgWrapper::READ_AND_WRITE
|
||||
);
|
||||
|
||||
bool Grid_readLocalData(Object& obj, Input& fr)
|
||||
{
|
||||
bool iteratorAdvanced = false;
|
||||
|
||||
Grid& grid = static_cast<Grid&>(obj);
|
||||
|
||||
if (fr.matchSequence("NumColumnsAndRows %i %i"))
|
||||
{
|
||||
int numcolumns,numrows;
|
||||
fr[1].getInt(numcolumns);
|
||||
fr[2].getInt(numrows);
|
||||
grid.allocateGrid(numcolumns,numrows);
|
||||
heightfield.allocateGrid(numcolumns,numrows);
|
||||
fr+=3;
|
||||
iteratorAdvanced = true;
|
||||
}
|
||||
@@ -421,9 +395,9 @@ bool Grid_readLocalData(Object& obj, Input& fr)
|
||||
{
|
||||
if (fr.readSequence(height))
|
||||
{
|
||||
grid.setHeight(column,row,height);
|
||||
heightfield.setHeight(column,row,height);
|
||||
++column;
|
||||
if (column>=grid.getNumColumns())
|
||||
if (column>=heightfield.getNumColumns())
|
||||
{
|
||||
column = 0;
|
||||
++row;
|
||||
@@ -440,25 +414,29 @@ bool Grid_readLocalData(Object& obj, Input& fr)
|
||||
|
||||
}
|
||||
|
||||
|
||||
return iteratorAdvanced;
|
||||
}
|
||||
|
||||
bool Grid_writeLocalData(const Object& obj, Output& fw)
|
||||
bool HeightField_writeLocalData(const Object& obj, Output& fw)
|
||||
{
|
||||
const Grid& grid = static_cast<const Grid&>(obj);
|
||||
const HeightField& heightfield = static_cast<const HeightField&>(obj);
|
||||
|
||||
fw.indent()<<"NumColumnsAndRows "<<grid.getNumColumns()<<" "<<grid.getNumRows()<<std::endl;
|
||||
fw.indent()<<"Origin "<<heightfield.getOrigin()<<std::endl;
|
||||
fw.indent()<<"XInterval "<<heightfield.getXInterval()<<std::endl;
|
||||
fw.indent()<<"YInterval "<<heightfield.getYInterval()<<std::endl;
|
||||
fw.indent()<<"Rotation "<<heightfield.getRotation()<<std::endl;
|
||||
|
||||
fw.indent()<<"NumColumnsAndRows "<<heightfield.getNumColumns()<<" "<<heightfield.getNumRows()<<std::endl;
|
||||
|
||||
fw.indent()<<"Heights"<<std::endl;
|
||||
|
||||
ParameterOutput po(fw);
|
||||
po.begin();
|
||||
for(unsigned int row=0;row<grid.getNumRows();++row)
|
||||
for(unsigned int row=0;row<heightfield.getNumRows();++row)
|
||||
{
|
||||
for(unsigned int column=0;column<grid.getNumColumns();++column)
|
||||
for(unsigned int column=0;column<heightfield.getNumColumns();++column)
|
||||
{
|
||||
po.write(grid.getHeight(column,row));
|
||||
po.write(heightfield.getHeight(column,row));
|
||||
}
|
||||
po.newLine();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user