Added new GDAL plugin and osgbluemarble example to demonstrate how to create

PagedLOD'd databases using GDAL.
This commit is contained in:
Robert Osfield
2003-10-08 13:09:23 +00:00
parent 48fc18fe8b
commit e7c0d70747
15 changed files with 713 additions and 2 deletions

View File

@@ -53,7 +53,7 @@ PLUGIN_DIRS = \
ive\
# comment in if you have gdal installed
# PLUGIN_DIRS += gdal
PLUGIN_DIRS += gdal
# comment in if you have japser (JPEG2000 library) installed.
# PLUGIN_DIRS += jp2
@@ -127,6 +127,7 @@ EXAMPLE_DIRS = \
osganimate\
osgautotransform\
osgbillboard\
osgbluemarble\
osgcallback\
osgcameragroup\
osgclip\

View File

@@ -252,6 +252,33 @@ Package=<4>
###############################################################################
Project: "Example osgbluemarble"=.\examples\osgbluemarble\osgbluemarble.dsp - Package Owner=<4>
Package=<5>
{{{
}}}
Package=<4>
{{{
Begin Project Dependency
Project_Dep_Name Core osg
End Project Dependency
Begin Project Dependency
Project_Dep_Name Core osgDB
End Project Dependency
Begin Project Dependency
Project_Dep_Name Core osgGA
End Project Dependency
Begin Project Dependency
Project_Dep_Name Core osgProducer
End Project Dependency
Begin Project Dependency
Project_Dep_Name Core osgUtil
End Project Dependency
}}}
###############################################################################
Project: "Example osgcallback"=.\examples\osgcallback\osgcallback.dsp - Package Owner=<4>
Package=<5>
@@ -1914,6 +1941,27 @@ Package=<4>
###############################################################################
Project: "osgPlugin gdal"=.\osgPlugins\gdal\gdal.dsp - Package Owner=<4>
Package=<5>
{{{
}}}
Package=<4>
{{{
Begin Project Dependency
Project_Dep_Name Core osg
End Project Dependency
Begin Project Dependency
Project_Dep_Name Core osgDB
End Project Dependency
Begin Project Dependency
Project_Dep_Name Core osgUtil
End Project Dependency
}}}
###############################################################################
Project: "osgPlugin osg"=.\osgPlugins\osg\dot_osg.dsp - Package Owner=<4>
Package=<5>

View File

@@ -0,0 +1,190 @@
# Microsoft Developer Studio Project File - Name="Example osgbluemarble" - Package Owner=<4>
# Microsoft Developer Studio Generated Build File, Format Version 6.00
# ** DO NOT EDIT **
# TARGTYPE "Win32 (x86) Console Application" 0x0103
CFG=Example osgbluemarble - Win32 Release
!MESSAGE This is not a valid makefile. To build this project using NMAKE,
!MESSAGE use the Export Makefile command and run
!MESSAGE
!MESSAGE NMAKE /f "osgbluemarble.mak".
!MESSAGE
!MESSAGE You can specify a configuration when running NMAKE
!MESSAGE by defining the macro CFG on the command line. For example:
!MESSAGE
!MESSAGE NMAKE /f "osgbluemarble.mak" CFG="Example osgbluemarble - Win32 Release"
!MESSAGE
!MESSAGE Possible choices for configuration are:
!MESSAGE
!MESSAGE "Example osgbluemarble - Win32 Release" (based on "Win32 (x86) Console Application")
!MESSAGE "Example osgbluemarble - Win32 Debug" (based on "Win32 (x86) Console Application")
!MESSAGE
# Begin Project
# PROP AllowPerConfigDependencies 0
# PROP Scc_ProjName ""
# PROP Scc_LocalPath ""
CPP=cl.exe
RSC=rc.exe
!IF "$(CFG)" == "Example osgbluemarble - Win32 Release"
# PROP BASE Use_MFC 0
# PROP BASE Use_Debug_Libraries 0
# PROP BASE Output_Dir "Release"
# PROP BASE Intermediate_Dir "Release"
# PROP BASE Target_Dir ""
# PROP Use_MFC 0
# PROP Use_Debug_Libraries 0
# PROP Output_Dir "Release"
# PROP Intermediate_Dir "Release"
# PROP Ignore_Export_Lib 0
# PROP Target_Dir ""
# ADD BASE CPP /nologo /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /c
# ADD CPP /nologo /MD /W3 /GR /GX /O2 /I "../../../include" /D "WIN32" /D "NDEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /c
# ADD BASE RSC /l 0x809 /d "NDEBUG"
# ADD RSC /l 0x809 /d "NDEBUG"
BSC32=bscmake.exe
# ADD BASE BSC32 /nologo
# ADD BSC32 /nologo
LINK32=link.exe
# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /machine:I386
# ADD LINK32 opengl32.lib /nologo /subsystem:console /pdb:none /machine:I386 /out:"../../../bin/osgbluemarble.exe" /libpath:"../../../lib"
!ELSEIF "$(CFG)" == "Example osgbluemarble - Win32 Debug"
# PROP BASE Use_MFC 0
# PROP BASE Use_Debug_Libraries 1
# PROP BASE Output_Dir "Debug"
# PROP BASE Intermediate_Dir "Debug"
# PROP BASE Target_Dir ""
# PROP Use_MFC 0
# PROP Use_Debug_Libraries 1
# PROP Output_Dir "Debug"
# PROP Intermediate_Dir "Debug"
# PROP Ignore_Export_Lib 0
# PROP Target_Dir ""
# ADD BASE CPP /nologo /W3 /Gm /GX /Zi /Od /D "WIN32" /D "_DEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /c
# ADD CPP /nologo /MDd /W3 /Gm /vd0 /GR /GX /Zi /Od /I "../../../include" /D "_CONSOLE" /D "_MBCS" /D "FL_DLL" /D "WIN32" /D "_DEBUG" /FR /YX /FD /c
# ADD BASE RSC /l 0x809 /d "_DEBUG"
# ADD RSC /l 0x809 /d "_DEBUG"
BSC32=bscmake.exe
# ADD BASE BSC32 /nologo
# ADD BSC32 /nologo
LINK32=link.exe
# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept
# ADD LINK32 opengl32.lib /nologo /subsystem:console /debug /machine:I386 /nodefaultlib:"libcmt" /out:"../../../bin/osgbluemarbled.exe" /pdbtype:sept /libpath:"../../../lib"
# SUBTRACT LINK32 /incremental:no
!ENDIF
# Begin Target
# Name "Example osgbluemarble - Win32 Release"
# Name "Example osgbluemarble - Win32 Debug"
# Begin Source File
SOURCE=..\..\..\examples\osgbluemarble\osgbluemarble.cpp
# End Source File
# End Target
# Begin Group "Resource Files"
# PROP Default_Filter "ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe"
# End Group
# End Project

View File

@@ -0,0 +1,109 @@
# Microsoft Developer Studio Project File - Name="osgPlugin gdal" - Package Owner=<4>
# Microsoft Developer Studio Generated Build File, Format Version 6.00
# ** DO NOT EDIT **
# TARGTYPE "Win32 (x86) Dynamic-Link Library" 0x0102
CFG=osgPlugin gdal - Win32 Release
!MESSAGE This is not a valid makefile. To build this project using NMAKE,
!MESSAGE use the Export Makefile command and run
!MESSAGE
!MESSAGE NMAKE /f "gdal.mak".
!MESSAGE
!MESSAGE You can specify a configuration when running NMAKE
!MESSAGE by defining the macro CFG on the command line. For example:
!MESSAGE
!MESSAGE NMAKE /f "gdal.mak" CFG="osgPlugin gdal - Win32 Release"
!MESSAGE
!MESSAGE Possible choices for configuration are:
!MESSAGE
!MESSAGE "osgPlugin gdal - Win32 Release" (based on "Win32 (x86) Dynamic-Link Library")
!MESSAGE "osgPlugin gdal - Win32 Debug" (based on "Win32 (x86) Dynamic-Link Library")
!MESSAGE
# Begin Project
# PROP AllowPerConfigDependencies 0
# PROP Scc_ProjName ""
# PROP Scc_LocalPath ""
CPP=cl.exe
MTL=midl.exe
RSC=rc.exe
!IF "$(CFG)" == "osgPlugin gdal - Win32 Release"
# PROP BASE Use_MFC 0
# PROP BASE Use_Debug_Libraries 0
# PROP BASE Output_Dir "Release"
# PROP BASE Intermediate_Dir "Release"
# PROP BASE Target_Dir ""
# PROP Use_MFC 0
# PROP Use_Debug_Libraries 0
# PROP Output_Dir "../../../lib"
# PROP Intermediate_Dir "Release"
# PROP Ignore_Export_Lib 0
# PROP Target_Dir ""
# ADD BASE CPP /nologo /MT /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_WINDOWS" /D "_MBCS" /D "_USRDLL" /YX /FD /c
# ADD CPP /nologo /MD /W3 /GR /GX /O2 /I "../../../include" /D "WIN32" /D "NDEBUG" /D "_WINDOWS" /D "_MBCS" /D "_USRDLL" /YX /FD /c
# ADD BASE MTL /nologo /D "NDEBUG" /mktyplib203 /win32
# ADD MTL /nologo /D "NDEBUG" /mktyplib203 /win32
# ADD BASE RSC /l 0x809 /d "NDEBUG"
# ADD RSC /l 0x809 /d "NDEBUG"
BSC32=bscmake.exe
# ADD BASE BSC32 /nologo
# ADD BSC32 /nologo
LINK32=link.exe
# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /dll /machine:I386
# ADD LINK32 libgdal.lib /nologo /dll /pdb:none /machine:I386 /nodefaultlib:"LIBC" /out:"../../../bin/osgdb_gdal.dll" /libpath:"../../../lib"
# SUBTRACT LINK32 /nodefaultlib
!ELSEIF "$(CFG)" == "osgPlugin gdal - Win32 Debug"
# PROP BASE Use_MFC 0
# PROP BASE Use_Debug_Libraries 1
# PROP BASE Output_Dir "Debug"
# PROP BASE Intermediate_Dir "Debug"
# PROP BASE Target_Dir ""
# PROP Use_MFC 0
# PROP Use_Debug_Libraries 1
# PROP Output_Dir "../../../lib"
# PROP Intermediate_Dir "Debug"
# PROP Ignore_Export_Lib 0
# PROP Target_Dir ""
# ADD BASE CPP /nologo /MTd /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_WINDOWS" /D "_MBCS" /D "_USRDLL" /YX /FD /GZ /c
# ADD CPP /nologo /MDd /W3 /Gm /vmg /vd0 /GR /GX /Zi /Od /I "../../../include" /D "_WINDOWS" /D "_MBCS" /D "_USRDLL" /D "WIN32" /D "_DEBUG" /YX /FD /GZ /c
# ADD BASE MTL /nologo /D "_DEBUG" /mktyplib203 /win32
# ADD MTL /nologo /D "_DEBUG" /mktyplib203 /win32
# ADD BASE RSC /l 0x809 /d "_DEBUG"
# ADD RSC /l 0x809 /d "_DEBUG"
BSC32=bscmake.exe
# ADD BASE BSC32 /nologo
# ADD BSC32 /nologo
LINK32=link.exe
# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /dll /debug /machine:I386 /pdbtype:sept
# ADD LINK32 libgdal.lib /nologo /dll /debug /machine:I386 /nodefaultlib:"LIBC" /out:"../../../bin/osgdb_gdald.dll" /pdbtype:sept /libpath:"../../../lib"
# SUBTRACT LINK32 /nodefaultlib
!ENDIF
# Begin Target
# Name "osgPlugin gdal - Win32 Release"
# Name "osgPlugin gdal - Win32 Debug"
# Begin Group "Source Files"
# PROP Default_Filter "cpp;c;cxx;rc;def;r;odl;idl;hpj;bat"
# Begin Source File
SOURCE=..\..\..\src\osgPlugins\gdal\ReaderWriterGDAL.cpp
# End Source File
# End Group
# Begin Group "Header Files"
# PROP Default_Filter "h;hpp;hxx;hm;inl"
# End Group
# Begin Group "Resource Files"
# PROP Default_Filter "ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;gdal;jpe"
# End Group
# End Target
# End Project

View File

@@ -142,6 +142,10 @@ SOURCE=..\..\..\src\osgPlugins\ive\DrawArrays.cpp
# End Source File
# Begin Source File
SOURCE=..\..\..\src\osgPlugins\ive\DrawElementsUByte.cpp
# End Source File
# Begin Source File
SOURCE=..\..\..\src\osgPlugins\ive\DrawElementsUInt.cpp
# End Source File
# Begin Source File
@@ -358,6 +362,10 @@ SOURCE=..\..\..\src\osgPlugins\ive\DrawArrays.h
# End Source File
# Begin Source File
SOURCE=..\..\..\src\osgPlugins\ive\DrawElementsUByte.h
# End Source File
# Begin Source File
SOURCE=..\..\..\src\osgPlugins\ive\DrawElementsUInt.h
# End Source File
# Begin Source File

View File

@@ -10,6 +10,7 @@ CXXFILES =\
Registry.cpp\
Version.cpp\
WriteFile.cpp\
ImageOptions.cpp\
Input.cpp\
Output.cpp\
Field.cpp\

View File

@@ -0,0 +1,14 @@
TOPDIR = ../../..
include $(TOPDIR)/Make/makedefs
CXXFILES =\
ReaderWriterGDAL.cpp\
LIBS += $(OSG_LIBS) -lgdal.1.1 $(OTHER_LIBS)
TARGET_BASENAME = gdal
include $(TOPDIR)/Make/cygwin_plugin_def
PLUGIN = $(PLUGIN_PREFIX)$(TARGET_BASENAME).$(PLUGIN_EXT)
include $(TOPDIR)/Make/makerules

View File

@@ -0,0 +1,310 @@
#include <osg/Image>
#include <osg/Notify>
#include <osg/Geode>
#include <osg/GL>
#include <osgDB/Registry>
#include <osgDB/FileNameUtils>
#include <osgDB/ImageOptions>
#include <gdal_priv.h>
class ReaderWriterGDAL : public osgDB::ReaderWriter
{
public:
virtual const char* className() { return "GDAL Image Reader"; }
virtual bool acceptsExtension(const std::string& extension)
{
return osgDB::equalCaseInsensitive(extension,"gdal") || osgDB::equalCaseInsensitive(extension,"gdal");
}
virtual ReadResult readImage(const std::string& fileName, const osgDB::ReaderWriter::Options* options)
{
//std::string ext = osgDB::getFileExtension(fileName);
//if (!acceptsExtension(ext)) return ReadResult::FILE_NOT_HANDLED;
initGDAL();
std::auto_ptr<GDALDataset> dataset((GDALDataset*)GDALOpen(fileName.c_str(),GA_ReadOnly));
if (!dataset.get()) return ReadResult::FILE_NOT_HANDLED;
int dataWidth = dataset->GetRasterXSize();
int dataHeight = dataset->GetRasterYSize();
int windowX = 0;
int windowY = 0;
int windowWidth = dataWidth;
int windowHeight = dataHeight;
int destX = 0;
int destY = 0;
int destWidth = osg::minimum(dataWidth,1024);
int destHeight = osg::minimum(dataHeight,1024);
const osgDB::ImageOptions* imageOptions = dynamic_cast<const osgDB::ImageOptions*>(options);
if (imageOptions)
{
std::cout<<"Got ImageOptions"<<std::endl;
switch(imageOptions->_sourceImageWindowMode)
{
case(osgDB::ImageOptions::RATIO_WINDOW):
windowX = (unsigned int)(floor((double)dataWidth * imageOptions->_sourceRatioWindow.windowX));
windowY = (unsigned int)(floor((double)dataHeight * imageOptions->_sourceRatioWindow.windowY));
windowWidth = (unsigned int)(ceil((double)dataWidth * (imageOptions->_sourceRatioWindow.windowX + imageOptions->_sourceRatioWindow.windowWidth)))-windowX;
windowHeight = (unsigned int)(ceil((double)dataHeight * (imageOptions->_sourceRatioWindow.windowY + imageOptions->_sourceRatioWindow.windowHeight)))-windowY;
break;
case(osgDB::ImageOptions::PIXEL_WINDOW):
windowX = imageOptions->_sourcePixelWindow.windowX;
windowY = imageOptions->_sourcePixelWindow.windowY;
windowWidth = imageOptions->_sourcePixelWindow.windowWidth;
windowHeight = imageOptions->_sourcePixelWindow.windowHeight;
break;
default:
// leave source window dimensions as whole image.
break;
}
switch(imageOptions->_destinationImageWindowMode)
{
case(osgDB::ImageOptions::RATIO_WINDOW):
destX = (unsigned int)(floor((double)dataWidth * imageOptions->_destinationRatioWindow.windowX));
destY = (unsigned int)(floor((double)dataHeight * imageOptions->_destinationRatioWindow.windowY));
destWidth = (unsigned int)(ceil((double)dataWidth * (imageOptions->_destinationRatioWindow.windowX + imageOptions->_destinationRatioWindow.windowWidth)))-windowX;
destHeight = (unsigned int)(ceil((double)dataHeight * (imageOptions->_destinationRatioWindow.windowY + imageOptions->_destinationRatioWindow.windowHeight)))-windowY;
break;
case(osgDB::ImageOptions::PIXEL_WINDOW):
destX = imageOptions->_destinationPixelWindow.windowX;
destY = imageOptions->_destinationPixelWindow.windowY;
destWidth = imageOptions->_destinationPixelWindow.windowWidth;
destHeight = imageOptions->_destinationPixelWindow.windowHeight;
break;
default:
// leave source window dimensions as whole image.
break;
}
}
// windowX = 0;
// windowY = 0;
// windowWidth = destWidth;
// windowHeight = destHeight;
std::cout << " windowX = "<<windowX<<std::endl;
std::cout << " windowY = "<<windowY<<std::endl;
std::cout << " windowWidth = "<<windowWidth<<std::endl;
std::cout << " windowHeight = "<<windowHeight<<std::endl;
std::cout << std::endl;
std::cout << " destX = "<<destX<<std::endl;
std::cout << " destY = "<<destY<<std::endl;
std::cout << " destWidth = "<<destWidth<<std::endl;
std::cout << " destHeight = "<<destHeight<<std::endl;
std::cout << std::endl;
std::cout << " GetRaterCount() "<< dataset->GetRasterCount()<<std::endl;
std::cout << " GetProjectionRef() "<< dataset->GetProjectionRef()<<std::endl;
double geoTransform[6];
if (dataset->GetGeoTransform(geoTransform)!=CE_None)
{
std::cout << " GetGeoTransform "<< std::endl;
std::cout << " Origin = "<<geoTransform[0]<<" "<<geoTransform[3]<<std::endl;
std::cout << " Pixel X = "<<geoTransform[1]<<" "<<geoTransform[4]<<std::endl;
std::cout << " Pixel Y = "<<geoTransform[2]<<" "<<geoTransform[5]<<std::endl;
}
int numBands = dataset->GetRasterCount();
GDALRasterBand* bandGray = 0;
GDALRasterBand* bandRed = 0;
GDALRasterBand* bandGreen = 0;
GDALRasterBand* bandBlue = 0;
GDALRasterBand* bandAlpha = 0;
for(int b=1;b<=numBands;++b)
{
GDALRasterBand* band = dataset->GetRasterBand(b);
std::cout << " Band "<<b<<std::endl;
std::cout << " GetOverviewCount() = "<< band->GetOverviewCount()<<std::endl;
std::cout << " GetColorTable() = "<< band->GetColorTable()<<std::endl;
std::cout << " DataTypeName() = "<< GDALGetDataTypeName(band->GetRasterDataType())<<std::endl;
std::cout << " ColorIntepretationName() = "<< GDALGetColorInterpretationName(band->GetColorInterpretation())<<std::endl;
if (band->GetColorInterpretation()==GCI_GrayIndex) bandGray = band;
else if (band->GetColorInterpretation()==GCI_RedBand) bandRed = band;
else if (band->GetColorInterpretation()==GCI_GreenBand) bandGreen = band;
else if (band->GetColorInterpretation()==GCI_BlueBand) bandBlue = band;
else if (band->GetColorInterpretation()==GCI_AlphaBand) bandAlpha = band;
// int gotMin,gotMax;
// double minmax[2];
//
// minmax[0] = band->GetMinimum(&gotMin);
// minmax[1] = band->GetMaximum(&gotMax);
// if (!(gotMin && gotMax))
// {
// std::cout<<" computing min max"<<std::endl;
// GDALComputeRasterMinMax(band,TRUE,minmax);
// }
//
// std::cout << " min "<<minmax[0]<<std::endl;
// std::cout << " max "<<minmax[1]<<std::endl;
}
int s = destWidth;
int t = destHeight;
int r = 1;
int internalFormat = GL_LUMINANCE;
unsigned int pixelFormat = GL_LUMINANCE;
unsigned int dataType = GL_FLOAT;
unsigned char* imageData = 0;
if (bandRed && bandGreen && bandBlue)
{
if (bandAlpha)
{
// RGBA
int pixelSpace=4;
int lineSpace=destWidth * pixelSpace;
imageData = new unsigned char[destWidth * destHeight * pixelSpace];
pixelFormat = GL_RGBA;
internalFormat = GL_RGBA;
dataType = GL_UNSIGNED_BYTE;
std::cout << "reading RGBA"<<std::endl;
bandRed->RasterIO(GF_Read,windowX,windowY,windowWidth,windowHeight,(void*)(imageData+0),destWidth,destHeight,GDT_Byte,pixelSpace,lineSpace);
bandGreen->RasterIO(GF_Read,windowX,windowY,windowWidth,windowHeight,(void*)(imageData+1),destWidth,destHeight,GDT_Byte,pixelSpace,lineSpace);
bandBlue->RasterIO(GF_Read,windowX,windowY,windowWidth,windowHeight,(void*)(imageData+2),destWidth,destHeight,GDT_Byte,pixelSpace,lineSpace);
bandAlpha->RasterIO(GF_Read,windowX,windowY,windowWidth,windowHeight,(void*)(imageData+3),destWidth,destHeight,GDT_Byte,pixelSpace,lineSpace);
}
else
{
// RGB
int pixelSpace=3;
int lineSpace=destWidth * pixelSpace;
imageData = new unsigned char[destWidth * destHeight * pixelSpace];
pixelFormat = GL_RGB;
internalFormat = GL_RGB;
dataType = GL_UNSIGNED_BYTE;
std::cout << "reading RGB"<<std::endl;
bandRed->RasterIO(GF_Read,windowX,windowY,windowWidth,windowHeight,(void*)(imageData+0),destWidth,destHeight,GDT_Byte,pixelSpace,lineSpace);
bandGreen->RasterIO(GF_Read,windowX,windowY,windowWidth,windowHeight,(void*)(imageData+1),destWidth,destHeight,GDT_Byte,pixelSpace,lineSpace);
bandBlue->RasterIO(GF_Read,windowX,windowY,windowWidth,windowHeight,(void*)(imageData+2),destWidth,destHeight,GDT_Byte,pixelSpace,lineSpace);
}
} else if (bandGray)
{
if (bandAlpha)
{
// Luminance alpha
int pixelSpace=2;
int lineSpace=destWidth * pixelSpace;
imageData = new unsigned char[destWidth * destHeight * pixelSpace];
pixelFormat = GL_LUMINANCE_ALPHA;
internalFormat = GL_LUMINANCE_ALPHA;
dataType = GL_UNSIGNED_BYTE;
std::cout << "reading grey + alpha"<<std::endl;
bandGray->RasterIO(GF_Read,windowX,windowY,windowWidth,windowHeight,(void*)(imageData+0),destWidth,destHeight,GDT_Byte,pixelSpace,lineSpace);
bandAlpha->RasterIO(GF_Read,windowX,windowY,windowWidth,windowHeight,(void*)(imageData+1),destWidth,destHeight,GDT_Byte,pixelSpace,lineSpace);
}
else
{
// Luminance map
int pixelSpace=1;
int lineSpace=destWidth * pixelSpace;
imageData = new unsigned char[destWidth * destHeight * pixelSpace];
pixelFormat = GL_LUMINANCE;
internalFormat = GL_LUMINANCE;
dataType = GL_UNSIGNED_BYTE;
std::cout << "reading grey"<<std::endl;
bandGray->RasterIO(GF_Read,windowX,windowY,windowWidth,windowHeight,(void*)(imageData+0),destWidth,destHeight,GDT_Byte,pixelSpace,lineSpace);
}
} else if (bandAlpha)
{
// alpha map (treat as a Luminance map)
int pixelSpace=1;
int lineSpace=destWidth * pixelSpace;
imageData = new unsigned char[destWidth * destHeight * pixelSpace];
pixelFormat = GL_LUMINANCE;
internalFormat = GL_LUMINANCE;
dataType = GL_UNSIGNED_BYTE;
std::cout << "reading alpha"<<std::endl;
bandAlpha->RasterIO(GF_Read,windowX,windowY,windowWidth,windowHeight,(void*)(imageData+0),destWidth,destHeight,GDT_Byte,pixelSpace,lineSpace);
}
else
{
std::cout << "not found any usable bands in file."<<std::endl;
}
//GDALOpen(dataset);
if (imageData)
{
osg::Image* image = new osg::Image;
image->setFileName(fileName.c_str());
image->setImage(s,t,r,
internalFormat,
pixelFormat,
dataType,
(unsigned char *)imageData,
osg::Image::USE_NEW_DELETE);
image->flipVertical();
return image;
}
return 0;
}
void initGDAL()
{
static bool s_initialized = false;
if (!s_initialized)
{
s_initialized = true;
GDALAllRegister();
}
}
};
// now register with Registry to instantiate the above
// reader/writer.
osgDB::RegisterReaderWriterProxy<ReaderWriterGDAL> g_readerWriter_GDAL_Proxy;

View File

@@ -94,6 +94,18 @@ char DataInputStream::readChar(){
return c;
}
unsigned char DataInputStream::readUChar(){
unsigned char c;
_istream->read((char*)&c, CHARSIZE);
if (_istream->rdstate() & _istream->failbit)
throw Exception("DataInputStream::readUChar(): Failed to read unsigned char value.");
if (_verboseOutput) std::cout<<"read/writeUChar() ["<<(int)c<<"]"<<std::endl;
return c;
}
unsigned short DataInputStream::readUShort(){
unsigned short s;
_istream->read((char*)&s, SHORTSIZE);

View File

@@ -31,6 +31,7 @@ public:
~DataInputStream();
bool readBool();
char readChar();
unsigned char readUChar();
unsigned short readUShort();
unsigned int readUInt();
int readInt();

View File

@@ -74,6 +74,12 @@ void DataOutputStream::writeChar(char c){
if (_verboseOutput) std::cout<<"read/writeChar() ["<<(int)c<<"]"<<std::endl;
}
void DataOutputStream::writeUChar(unsigned char c){
_ostream->write((char*)&c, CHARSIZE);
if (_verboseOutput) std::cout<<"read/writeUChar() ["<<(int)c<<"]"<<std::endl;
}
void DataOutputStream::writeUShort(unsigned short s){
_ostream->write((char*)&s, SHORTSIZE);

View File

@@ -28,6 +28,7 @@ public:
~DataOutputStream();
void writeBool(bool b);
void writeChar(char c);
void writeUChar(unsigned char c);
void writeUShort(unsigned short s);
void writeUInt(unsigned int s);
void writeInt(int i);

View File

@@ -13,6 +13,7 @@ CXXFILES =\
DataOutputStream.cpp\
DrawArrayLengths.cpp\
DrawArrays.cpp\
DrawElementsUByte.cpp\
DrawElementsUShort.cpp\
DrawElementsUInt.cpp\
Drawable.cpp\

View File

@@ -17,6 +17,7 @@
#include "Drawable.h"
#include "DrawArrays.h"
#include "DrawArrayLengths.h"
#include "DrawElementsUByte.h"
#include "DrawElementsUShort.h"
#include "DrawElementsUInt.h"
@@ -45,6 +46,8 @@ void Geometry::write(DataOutputStream* out){
((ive::DrawArrays*)(getPrimitiveSet(i)))->write(out);
else if(dynamic_cast<osg::DrawArrayLengths*>(getPrimitiveSet(i)))
((ive::DrawArrayLengths*)(getPrimitiveSet(i)))->write(out);
else if(dynamic_cast<osg::DrawElementsUByte*>(getPrimitiveSet(i)))
((ive::DrawElementsUByte*)(getPrimitiveSet(i)))->write(out);
else if(dynamic_cast<osg::DrawElementsUShort*>(getPrimitiveSet(i)))
((ive::DrawElementsUShort*)(getPrimitiveSet(i)))->write(out);
else if(dynamic_cast<osg::DrawElementsUInt*>(getPrimitiveSet(i)))
@@ -180,6 +183,11 @@ void Geometry::read(DataInputStream* in){
((ive::DrawArrayLengths*)(prim))->read(in);
addPrimitiveSet(prim);
}
else if(primID==IVEDRAWELEMENTSUBYTE){
prim = new osg::DrawElementsUByte();
((ive::DrawElementsUByte*)(prim))->read(in);
addPrimitiveSet(prim);
}
else if(primID==IVEDRAWELEMENTSUSHORT){
prim = new osg::DrawElementsUShort();
((ive::DrawElementsUShort*)(prim))->read(in);

View File

@@ -59,8 +59,9 @@ namespace ive {
#define IVEPRIMITIVESET 0x00010000
#define IVEDRAWARRAYS 0x00010001
#define IVEDRAWARRAYLENGTHS 0x00010002
#define IVEDRAWELEMENTSUSHORT 0x00010003
#define IVEDRAWELEMENTSUSHORT 0x00010003
#define IVEDRAWELEMENTSUINT 0x00010004
#define IVEDRAWELEMENTSUBYTE 0x00010005
// osgSim classes
#define IVEBLINKSEQUENCE 0x00100001