From 3da57d6d22b061b42308ef725d0ca4c4f1190c3e Mon Sep 17 00:00:00 2001 From: Robert Osfield Date: Sat, 6 Oct 2001 20:29:42 +0000 Subject: [PATCH] Added a osg::DegreesToRadians() and osg::RadiansToDegrees() method to osg/Math, updated the ReaderWriterBMP.cpp (mods sent in my Geoff Michel) and moved the osgUtil::Statistics to osg::Statistics in preperation to adding it to the the Drawable base class. --- include/osg/Math | 11 +++-- include/{osgUtil => osg}/Statistics | 11 ++--- include/osgUtil/RenderBin | 4 +- include/osgUtil/RenderStage | 2 +- src/osg/Makefile | 1 + src/osgGLUT/Viewer.cpp | 2 +- src/osgPlugins/bmp/ReaderWriterBMP.cpp | 58 ++++++++++++++++---------- src/osgUtil/Makefile | 1 - src/osgUtil/RenderBin.cpp | 2 +- src/osgUtil/RenderStage.cpp | 2 +- 10 files changed, 55 insertions(+), 39 deletions(-) rename include/{osgUtil => osg}/Statistics (97%) diff --git a/include/osg/Math b/include/osg/Math index ad1b94850..c568148a8 100644 --- a/include/osg/Math +++ b/include/osg/Math @@ -64,13 +64,16 @@ namespace osg { #ifdef USE_DEGREES_INTERNALLY -inline double inDegrees(float angle) { return angle; } -inline double inRadians(float angle) { return angle*180.0/M_PI; } +inline double inDegrees(double angle) { return angle; } +inline double inRadians(double angle) { return angle*180.0/M_PI; } #else -inline double inDegrees(float angle) { return angle*M_PI/180.0; } -inline double inRadians(float angle) { return angle; } +inline double inDegrees(double angle) { return angle*M_PI/180.0; } +inline double inRadians(double angle) { return angle; } #endif +inline double DegreesToRadians(double angle) { return angle*M_PI/180.0; } +inline double RadiansToDegrees(double angle) { return angle*180.0/M_PI; } + }; #endif // __OSG_MATH diff --git a/include/osgUtil/Statistics b/include/osg/Statistics similarity index 97% rename from include/osgUtil/Statistics rename to include/osg/Statistics index 40d28cbc6..2799c716a 100644 --- a/include/osgUtil/Statistics +++ b/include/osg/Statistics @@ -2,19 +2,18 @@ //Distributed under the terms of the GNU Library General Public License (LGPL) //as published by the Free Software Foundation. -#ifndef OSGUTIL_STATISTICS -#define OSGUTIL_STATISTICS 1 +#ifndef OSG_STATISTICS +#define OSG_STATISTICS 1 #include -namespace osgUtil { +namespace osg { /** * Statistics base class. Used to extract primitive information from * the renderBin(s). */ - -class OSGUTIL_EXPORT Statistics : public osg::Object +class SG_EXPORT Statistics : public Object { public: @@ -23,7 +22,9 @@ class OSGUTIL_EXPORT Statistics : public osg::Object nprims=0, nlights=0; nbins=0; reset(); }; + ~Statistics() {}; // no dynamic allocations, so no need to free + void reset() { for (int i=0; i<20; i++) primverts[i]=numprimtypes[i]=primlens[i]=primtypes[i]=0; } diff --git a/include/osgUtil/RenderBin b/include/osgUtil/RenderBin index 9fd9d52e3..7db6da20b 100644 --- a/include/osgUtil/RenderBin +++ b/include/osgUtil/RenderBin @@ -6,7 +6,7 @@ #define OSGUTIL_RENDERBIN 1 #include -#include +#include #include #include @@ -58,7 +58,7 @@ class OSGUTIL_EXPORT RenderBin : public osg::Object virtual void draw_local(osg::State& state,RenderLeaf*& previous); /** extract stats for current draw list. */ - void getPrims(Statistics *primStats); + void getPrims(osg::Statistics *primStats); public: diff --git a/include/osgUtil/RenderStage b/include/osgUtil/RenderStage index 7e6d2855a..c5134dd38 100644 --- a/include/osgUtil/RenderStage +++ b/include/osgUtil/RenderStage @@ -116,7 +116,7 @@ class OSGUTIL_EXPORT RenderStage : public RenderBin void addToDependencyList(RenderStage* rs); /** extract stats for current draw list. */ - void getPrims(Statistics *primStats); + void getPrims(osg::Statistics *primStats); public: diff --git a/src/osg/Makefile b/src/osg/Makefile index 0aeb4c65c..250a369ab 100644 --- a/src/osg/Makefile +++ b/src/osg/Makefile @@ -104,6 +104,7 @@ TARGET_INCLUDE_FILES = \ osg/State\ osg/StateAttribute\ osg/StateSet\ + osg/Statistics\ osg/Stencil\ osg/Switch\ osg/TexEnv\ diff --git a/src/osgGLUT/Viewer.cpp b/src/osgGLUT/Viewer.cpp index 8510b958d..13c061733 100644 --- a/src/osgGLUT/Viewer.cpp +++ b/src/osgGLUT/Viewer.cpp @@ -568,7 +568,7 @@ void displaytext(int x, int y, char *s) // GWM July 2001 - add Statistics structure, and related RenderBin #include -#include +#include void Viewer::showStats() { diff --git a/src/osgPlugins/bmp/ReaderWriterBMP.cpp b/src/osgPlugins/bmp/ReaderWriterBMP.cpp index 9cd5f6550..19b06834f 100644 --- a/src/osgPlugins/bmp/ReaderWriterBMP.cpp +++ b/src/osgPlugins/bmp/ReaderWriterBMP.cpp @@ -75,7 +75,7 @@ bmp_error(char *buffer, int bufferlen) } /* byte order workarounds *sigh* */ -void swapbyte(long *i) +void swapbyte(long &i) { char *vv=(char *)i; char tmp=vv[0]; @@ -85,7 +85,7 @@ void swapbyte(long *i) vv[1]=vv[2]; vv[2]=tmp; } -void swapbyte(unsigned long *i) +void swapbyte(unsigned long &i) { char *vv=(char *)i; char tmp=vv[0]; @@ -105,14 +105,14 @@ void swapbyte(float *i) vv[1]=vv[2]; vv[2]=tmp; } -void swapbyte(unsigned short *i) +void swapbyte(unsigned short &i) { char *vv=(char *)i; char tmp=vv[0]; vv[0]=vv[1]; vv[1]=tmp; } -void swapbyte(short *i) +void swapbyte(short &i) { char *vv=(char *)i; char tmp=vv[0]; @@ -132,7 +132,7 @@ int *numComponents_ret) // It is extremely expensive on disk space - every RGB pixel uses 3 bytes plus a header! // BMP - sponsored by Seagate. // unsigned char palette[256][3]; - unsigned char * buffer; + unsigned char *buffer, *imbuff; // returned to sender & as read from the disk bmperror = ERROR_NO_FILE; @@ -149,7 +149,7 @@ int *numComponents_ret) fread((char *)&hd, sizeof(bmpheader), 1, fp); fread((char *)&inf, sizeof(BMPInfo), 1, fp); if (hd.FileType != MB) { - swapbyte(&(hd.FileType)); + swapbyte((hd.FileType)); swap=true; if (hd.FileType != MB) { bmperror=ERROR_READING_HEADER; @@ -158,11 +158,12 @@ int *numComponents_ret) } if (hd.FileType == MB) { if (swap) { // inverse the field of the header which need swapping - swapbyte(&hd.siz[0]); - swapbyte(&hd.siz[1]); - swapbyte(&inf.Colorbits); - swapbyte(&inf.width); - swapbyte(&inf.height); + swapbyte(hd.siz[0]); + swapbyte(hd.siz[1]); + swapbyte(inf.Colorbits); + swapbyte(inf.width); + swapbyte(inf.height); + swapbyte(inf.ImageSize); } long size = hd.siz[1]*65536+hd.siz[0]; size -= sizeof(bmpheader)+sizeof(BMPInfo); @@ -181,25 +182,32 @@ int *numComponents_ret) ncomp = RGBA; break; } - buffer = (unsigned char *)malloc( ncomp*inf.width*inf.height); - osg::notify(osg::NOTICE)<<"BMP file: "<2) { // yes bill, colours are usually BGR aren't they for(int i=0; i