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.
This commit is contained in:
Robert Osfield 2001-10-06 20:29:42 +00:00
parent c56a1b8c31
commit 3da57d6d22
10 changed files with 55 additions and 39 deletions

View File

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

View File

@ -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 <osg/GeoSet>
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;
}

View File

@ -6,7 +6,7 @@
#define OSGUTIL_RENDERBIN 1
#include <osgUtil/RenderGraph>
#include <osgUtil/Statistics>
#include <osg/Statistics>
#include <map>
#include <vector>
@ -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:

View File

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

View File

@ -104,6 +104,7 @@ TARGET_INCLUDE_FILES = \
osg/State\
osg/StateAttribute\
osg/StateSet\
osg/Statistics\
osg/Stencil\
osg/Switch\
osg/TexEnv\

View File

@ -568,7 +568,7 @@ void displaytext(int x, int y, char *s)
// GWM July 2001 - add Statistics structure, and related RenderBin
#include <osgUtil/RenderBin>
#include <osgUtil/Statistics>
#include <osg/Statistics>
void Viewer::showStats()
{

View File

@ -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: "<<filename << endl;
osg::notify(osg::NOTICE)<<"sizes: "<< inf.width << " " << inf.height <<endl;
imbuff = (unsigned char *)malloc( inf.ImageSize); // read from disk
buffer = (unsigned char *)malloc( ncomp*inf.width*inf.height*sizeof(unsigned char)); //
if (ncomp==BW) {
osg::notify(osg::NOTICE)<<"BMP file: "<<filename << " sz " << inf.ImageSize <<endl;
osg::notify(osg::NOTICE)<<"sizes: "<< inf.width << " " << inf.height << " = " << ncomp*inf.width*inf.height << endl;
}
unsigned long off=0;
unsigned long doff=(ncomp*sizeof(unsigned char)*inf.width)/4;
unsigned long rowbytes=ncomp*sizeof(unsigned char)*inf.width;
unsigned long doff=(rowbytes)/4;
if ((rowbytes%4)) doff++; // round up if needed
doff*=4; // to find dword alignment
doff=fread((char *)buffer, sizeof(unsigned char),ncomp*inf.width*inf.height, fp);
if (ncomp>2) { // yes bill, colours are usually BGR aren't they
for(int j=0; j<inf.height; j++) {
if (j<5) osg::notify(osg::NOTICE)<<"row: "<< j << " offset " << off <<endl;
off+=doff;
fread((char *)imbuff, sizeof(unsigned char),inf.ImageSize, fp);
for(int j=0; j<inf.height; j++) {
memcpy(buffer+j*rowbytes, imbuff+off, rowbytes); // pack bytes closely
off+=doff;
if (ncomp>2) { // yes bill, colours are usually BGR aren't they
for(int i=0; i<inf.width; i++) {
unsigned char blu=buffer[3*(i*inf.height+j)+0];
buffer[3*(i*inf.height+j)+0]=buffer[3*(i*inf.height+j)+2]; // swap order of colours
buffer[3*(i*inf.height+j)+2]=blu;
int ijw=i+j*inf.width;
unsigned char blu=buffer[3*ijw+0];
buffer[3*ijw+0]=buffer[3*ijw+2]; // swap order of colours
buffer[3*ijw+2]=blu;
}
}
}
delete [] imbuff; // free the on-disk storage
} // else error in header
fclose(fp);
@ -234,6 +242,7 @@ class ReaderWriterBMP : public osgDB::ReaderWriter
int r = 1;
int internalFormat = numComponents_ret;
unsigned int pixelFormat =
numComponents_ret == 1 ? GL_LUMINANCE :
@ -241,6 +250,9 @@ class ReaderWriterBMP : public osgDB::ReaderWriter
numComponents_ret == 3 ? GL_RGB :
numComponents_ret == 4 ? GL_RGBA : (GLenum)-1;
cout << "internalFormat="<<internalFormat<<endl;
cout << "pixelFormat="<<pixelFormat<<endl;
unsigned int dataType = GL_UNSIGNED_BYTE;
osg::Image* pOsgImage = new osg::Image;

View File

@ -66,7 +66,6 @@ TARGET_INCLUDE_FILES = \
osgUtil/SceneViewManipulator\
osgUtil/SmoothingVisitor\
osgUtil/StateSetManipulator\
osgUtil/Statistics\
osgUtil/Tesselator\
osgUtil/TrackballManipulator\
osgUtil/TriStripVisitor\

View File

@ -162,7 +162,7 @@ void RenderBin::draw_local(osg::State& state,RenderLeaf*& previous)
}
// stats
#include <osg/GeoSet>
void RenderBin::getPrims(Statistics *primStats)
void RenderBin::getPrims(osg::Statistics *primStats)
{
for(RenderBinList::iterator itr = _bins.begin();
itr!=_bins.end();

View File

@ -140,7 +140,7 @@ void RenderStage::draw(osg::State& state,RenderLeaf*& previous)
}
// Statistics features
void RenderStage::getPrims(Statistics *primStats)
void RenderStage::getPrims(osg::Statistics *primStats)
{
if (_renderStageLighting.valid()) primStats->nlights+=_renderStageLighting->_lightList.size();
RenderBin::getPrims(primStats);