From e7c0d7074744bf966ce26fd67da9203ae9a47a0d Mon Sep 17 00:00:00 2001 From: Robert Osfield Date: Wed, 8 Oct 2003 13:09:23 +0000 Subject: [PATCH] Added new GDAL plugin and osgbluemarble example to demonstrate how to create PagedLOD'd databases using GDAL. --- Make/makedirdefs | 3 +- VisualStudio/VisualStudio.dsw | 48 +++ .../examples/osgbluemarble/osgbluemarble.dsp | 190 +++++++++++ VisualStudio/osgPlugins/gdal/gdal.dsp | 109 ++++++ VisualStudio/osgPlugins/ive/ive.dsp | 8 + src/osgDB/GNUmakefile | 1 + src/osgPlugins/gdal/GNUmakefile | 14 + src/osgPlugins/gdal/ReaderWriterGDAL.cpp | 310 ++++++++++++++++++ src/osgPlugins/ive/DataInputStream.cpp | 12 + src/osgPlugins/ive/DataInputStream.h | 1 + src/osgPlugins/ive/DataOutputStream.cpp | 6 + src/osgPlugins/ive/DataOutputStream.h | 1 + src/osgPlugins/ive/GNUmakefile | 1 + src/osgPlugins/ive/Geometry.cpp | 8 + src/osgPlugins/ive/ReadWrite.h | 3 +- 15 files changed, 713 insertions(+), 2 deletions(-) create mode 100644 VisualStudio/examples/osgbluemarble/osgbluemarble.dsp create mode 100755 VisualStudio/osgPlugins/gdal/gdal.dsp create mode 100644 src/osgPlugins/gdal/GNUmakefile create mode 100644 src/osgPlugins/gdal/ReaderWriterGDAL.cpp diff --git a/Make/makedirdefs b/Make/makedirdefs index 6c7182133..6c601810c 100644 --- a/Make/makedirdefs +++ b/Make/makedirdefs @@ -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\ diff --git a/VisualStudio/VisualStudio.dsw b/VisualStudio/VisualStudio.dsw index 5e0be7b56..e4570241d 100644 --- a/VisualStudio/VisualStudio.dsw +++ b/VisualStudio/VisualStudio.dsw @@ -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> diff --git a/VisualStudio/examples/osgbluemarble/osgbluemarble.dsp b/VisualStudio/examples/osgbluemarble/osgbluemarble.dsp new file mode 100644 index 000000000..db9835311 --- /dev/null +++ b/VisualStudio/examples/osgbluemarble/osgbluemarble.dsp @@ -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 + diff --git a/VisualStudio/osgPlugins/gdal/gdal.dsp b/VisualStudio/osgPlugins/gdal/gdal.dsp new file mode 100755 index 000000000..7bfbcd98b --- /dev/null +++ b/VisualStudio/osgPlugins/gdal/gdal.dsp @@ -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 diff --git a/VisualStudio/osgPlugins/ive/ive.dsp b/VisualStudio/osgPlugins/ive/ive.dsp index f9e93836b..f98d9a2e0 100755 --- a/VisualStudio/osgPlugins/ive/ive.dsp +++ b/VisualStudio/osgPlugins/ive/ive.dsp @@ -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 diff --git a/src/osgDB/GNUmakefile b/src/osgDB/GNUmakefile index 96ae788b6..fc59326e2 100644 --- a/src/osgDB/GNUmakefile +++ b/src/osgDB/GNUmakefile @@ -10,6 +10,7 @@ CXXFILES =\ Registry.cpp\ Version.cpp\ WriteFile.cpp\ + ImageOptions.cpp\ Input.cpp\ Output.cpp\ Field.cpp\ diff --git a/src/osgPlugins/gdal/GNUmakefile b/src/osgPlugins/gdal/GNUmakefile new file mode 100644 index 000000000..356570cdc --- /dev/null +++ b/src/osgPlugins/gdal/GNUmakefile @@ -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 diff --git a/src/osgPlugins/gdal/ReaderWriterGDAL.cpp b/src/osgPlugins/gdal/ReaderWriterGDAL.cpp new file mode 100644 index 000000000..414428e46 --- /dev/null +++ b/src/osgPlugins/gdal/ReaderWriterGDAL.cpp @@ -0,0 +1,310 @@ +#include +#include +#include +#include + +#include +#include +#include + +#include + +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 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(options); + if (imageOptions) + { + std::cout<<"Got 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 = "<GetRasterCount()<GetProjectionRef()<GetGeoTransform(geoTransform)!=CE_None) + { + std::cout << " GetGeoTransform "<< std::endl; + std::cout << " Origin = "<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 "<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"<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"<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"<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"<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."<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 g_readerWriter_GDAL_Proxy; diff --git a/src/osgPlugins/ive/DataInputStream.cpp b/src/osgPlugins/ive/DataInputStream.cpp index a75dcbcb5..71878f03c 100644 --- a/src/osgPlugins/ive/DataInputStream.cpp +++ b/src/osgPlugins/ive/DataInputStream.cpp @@ -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<<"]"<read((char*)&s, SHORTSIZE); diff --git a/src/osgPlugins/ive/DataInputStream.h b/src/osgPlugins/ive/DataInputStream.h index 07dd4cbde..59334eefc 100644 --- a/src/osgPlugins/ive/DataInputStream.h +++ b/src/osgPlugins/ive/DataInputStream.h @@ -31,6 +31,7 @@ public: ~DataInputStream(); bool readBool(); char readChar(); + unsigned char readUChar(); unsigned short readUShort(); unsigned int readUInt(); int readInt(); diff --git a/src/osgPlugins/ive/DataOutputStream.cpp b/src/osgPlugins/ive/DataOutputStream.cpp index 9d2977e4f..6d1c95753 100644 --- a/src/osgPlugins/ive/DataOutputStream.cpp +++ b/src/osgPlugins/ive/DataOutputStream.cpp @@ -74,6 +74,12 @@ void DataOutputStream::writeChar(char c){ if (_verboseOutput) std::cout<<"read/writeChar() ["<<(int)c<<"]"<write((char*)&c, CHARSIZE); + + if (_verboseOutput) std::cout<<"read/writeUChar() ["<<(int)c<<"]"<write((char*)&s, SHORTSIZE); diff --git a/src/osgPlugins/ive/DataOutputStream.h b/src/osgPlugins/ive/DataOutputStream.h index 818a2219c..6556b8356 100644 --- a/src/osgPlugins/ive/DataOutputStream.h +++ b/src/osgPlugins/ive/DataOutputStream.h @@ -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); diff --git a/src/osgPlugins/ive/GNUmakefile b/src/osgPlugins/ive/GNUmakefile index 89ab3b513..7d9228ffe 100644 --- a/src/osgPlugins/ive/GNUmakefile +++ b/src/osgPlugins/ive/GNUmakefile @@ -13,6 +13,7 @@ CXXFILES =\ DataOutputStream.cpp\ DrawArrayLengths.cpp\ DrawArrays.cpp\ + DrawElementsUByte.cpp\ DrawElementsUShort.cpp\ DrawElementsUInt.cpp\ Drawable.cpp\ diff --git a/src/osgPlugins/ive/Geometry.cpp b/src/osgPlugins/ive/Geometry.cpp index c199f8944..f99df3d08 100644 --- a/src/osgPlugins/ive/Geometry.cpp +++ b/src/osgPlugins/ive/Geometry.cpp @@ -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(getPrimitiveSet(i))) ((ive::DrawArrayLengths*)(getPrimitiveSet(i)))->write(out); + else if(dynamic_cast(getPrimitiveSet(i))) + ((ive::DrawElementsUByte*)(getPrimitiveSet(i)))->write(out); else if(dynamic_cast(getPrimitiveSet(i))) ((ive::DrawElementsUShort*)(getPrimitiveSet(i)))->write(out); else if(dynamic_cast(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); diff --git a/src/osgPlugins/ive/ReadWrite.h b/src/osgPlugins/ive/ReadWrite.h index 1c04f44f5..e95420bb5 100644 --- a/src/osgPlugins/ive/ReadWrite.h +++ b/src/osgPlugins/ive/ReadWrite.h @@ -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