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:
parent
c56a1b8c31
commit
3da57d6d22
@ -64,13 +64,16 @@
|
|||||||
namespace osg {
|
namespace osg {
|
||||||
|
|
||||||
#ifdef USE_DEGREES_INTERNALLY
|
#ifdef USE_DEGREES_INTERNALLY
|
||||||
inline double inDegrees(float angle) { return angle; }
|
inline double inDegrees(double angle) { return angle; }
|
||||||
inline double inRadians(float angle) { return angle*180.0/M_PI; }
|
inline double inRadians(double angle) { return angle*180.0/M_PI; }
|
||||||
#else
|
#else
|
||||||
inline double inDegrees(float angle) { return angle*M_PI/180.0; }
|
inline double inDegrees(double angle) { return angle*M_PI/180.0; }
|
||||||
inline double inRadians(float angle) { return angle; }
|
inline double inRadians(double angle) { return angle; }
|
||||||
#endif
|
#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
|
#endif // __OSG_MATH
|
||||||
|
@ -2,19 +2,18 @@
|
|||||||
//Distributed under the terms of the GNU Library General Public License (LGPL)
|
//Distributed under the terms of the GNU Library General Public License (LGPL)
|
||||||
//as published by the Free Software Foundation.
|
//as published by the Free Software Foundation.
|
||||||
|
|
||||||
#ifndef OSGUTIL_STATISTICS
|
#ifndef OSG_STATISTICS
|
||||||
#define OSGUTIL_STATISTICS 1
|
#define OSG_STATISTICS 1
|
||||||
|
|
||||||
#include <osg/GeoSet>
|
#include <osg/GeoSet>
|
||||||
|
|
||||||
namespace osgUtil {
|
namespace osg {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Statistics base class. Used to extract primitive information from
|
* Statistics base class. Used to extract primitive information from
|
||||||
* the renderBin(s).
|
* the renderBin(s).
|
||||||
*/
|
*/
|
||||||
|
class SG_EXPORT Statistics : public Object
|
||||||
class OSGUTIL_EXPORT Statistics : public osg::Object
|
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
|
||||||
@ -23,7 +22,9 @@ class OSGUTIL_EXPORT Statistics : public osg::Object
|
|||||||
nprims=0, nlights=0; nbins=0;
|
nprims=0, nlights=0; nbins=0;
|
||||||
reset();
|
reset();
|
||||||
};
|
};
|
||||||
|
|
||||||
~Statistics() {}; // no dynamic allocations, so no need to free
|
~Statistics() {}; // no dynamic allocations, so no need to free
|
||||||
|
|
||||||
void reset() {
|
void reset() {
|
||||||
for (int i=0; i<20; i++) primverts[i]=numprimtypes[i]=primlens[i]=primtypes[i]=0;
|
for (int i=0; i<20; i++) primverts[i]=numprimtypes[i]=primlens[i]=primtypes[i]=0;
|
||||||
}
|
}
|
@ -6,7 +6,7 @@
|
|||||||
#define OSGUTIL_RENDERBIN 1
|
#define OSGUTIL_RENDERBIN 1
|
||||||
|
|
||||||
#include <osgUtil/RenderGraph>
|
#include <osgUtil/RenderGraph>
|
||||||
#include <osgUtil/Statistics>
|
#include <osg/Statistics>
|
||||||
|
|
||||||
#include <map>
|
#include <map>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
@ -58,7 +58,7 @@ class OSGUTIL_EXPORT RenderBin : public osg::Object
|
|||||||
virtual void draw_local(osg::State& state,RenderLeaf*& previous);
|
virtual void draw_local(osg::State& state,RenderLeaf*& previous);
|
||||||
|
|
||||||
/** extract stats for current draw list. */
|
/** extract stats for current draw list. */
|
||||||
void getPrims(Statistics *primStats);
|
void getPrims(osg::Statistics *primStats);
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
|
@ -116,7 +116,7 @@ class OSGUTIL_EXPORT RenderStage : public RenderBin
|
|||||||
void addToDependencyList(RenderStage* rs);
|
void addToDependencyList(RenderStage* rs);
|
||||||
|
|
||||||
/** extract stats for current draw list. */
|
/** extract stats for current draw list. */
|
||||||
void getPrims(Statistics *primStats);
|
void getPrims(osg::Statistics *primStats);
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
|
@ -104,6 +104,7 @@ TARGET_INCLUDE_FILES = \
|
|||||||
osg/State\
|
osg/State\
|
||||||
osg/StateAttribute\
|
osg/StateAttribute\
|
||||||
osg/StateSet\
|
osg/StateSet\
|
||||||
|
osg/Statistics\
|
||||||
osg/Stencil\
|
osg/Stencil\
|
||||||
osg/Switch\
|
osg/Switch\
|
||||||
osg/TexEnv\
|
osg/TexEnv\
|
||||||
|
@ -568,7 +568,7 @@ void displaytext(int x, int y, char *s)
|
|||||||
|
|
||||||
// GWM July 2001 - add Statistics structure, and related RenderBin
|
// GWM July 2001 - add Statistics structure, and related RenderBin
|
||||||
#include <osgUtil/RenderBin>
|
#include <osgUtil/RenderBin>
|
||||||
#include <osgUtil/Statistics>
|
#include <osg/Statistics>
|
||||||
|
|
||||||
void Viewer::showStats()
|
void Viewer::showStats()
|
||||||
{
|
{
|
||||||
|
@ -75,7 +75,7 @@ bmp_error(char *buffer, int bufferlen)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* byte order workarounds *sigh* */
|
/* byte order workarounds *sigh* */
|
||||||
void swapbyte(long *i)
|
void swapbyte(long &i)
|
||||||
{
|
{
|
||||||
char *vv=(char *)i;
|
char *vv=(char *)i;
|
||||||
char tmp=vv[0];
|
char tmp=vv[0];
|
||||||
@ -85,7 +85,7 @@ void swapbyte(long *i)
|
|||||||
vv[1]=vv[2];
|
vv[1]=vv[2];
|
||||||
vv[2]=tmp;
|
vv[2]=tmp;
|
||||||
}
|
}
|
||||||
void swapbyte(unsigned long *i)
|
void swapbyte(unsigned long &i)
|
||||||
{
|
{
|
||||||
char *vv=(char *)i;
|
char *vv=(char *)i;
|
||||||
char tmp=vv[0];
|
char tmp=vv[0];
|
||||||
@ -105,14 +105,14 @@ void swapbyte(float *i)
|
|||||||
vv[1]=vv[2];
|
vv[1]=vv[2];
|
||||||
vv[2]=tmp;
|
vv[2]=tmp;
|
||||||
}
|
}
|
||||||
void swapbyte(unsigned short *i)
|
void swapbyte(unsigned short &i)
|
||||||
{
|
{
|
||||||
char *vv=(char *)i;
|
char *vv=(char *)i;
|
||||||
char tmp=vv[0];
|
char tmp=vv[0];
|
||||||
vv[0]=vv[1];
|
vv[0]=vv[1];
|
||||||
vv[1]=tmp;
|
vv[1]=tmp;
|
||||||
}
|
}
|
||||||
void swapbyte(short *i)
|
void swapbyte(short &i)
|
||||||
{
|
{
|
||||||
char *vv=(char *)i;
|
char *vv=(char *)i;
|
||||||
char tmp=vv[0];
|
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!
|
// It is extremely expensive on disk space - every RGB pixel uses 3 bytes plus a header!
|
||||||
// BMP - sponsored by Seagate.
|
// BMP - sponsored by Seagate.
|
||||||
// unsigned char palette[256][3];
|
// unsigned char palette[256][3];
|
||||||
unsigned char * buffer;
|
unsigned char *buffer, *imbuff; // returned to sender & as read from the disk
|
||||||
|
|
||||||
bmperror = ERROR_NO_FILE;
|
bmperror = ERROR_NO_FILE;
|
||||||
|
|
||||||
@ -149,7 +149,7 @@ int *numComponents_ret)
|
|||||||
fread((char *)&hd, sizeof(bmpheader), 1, fp);
|
fread((char *)&hd, sizeof(bmpheader), 1, fp);
|
||||||
fread((char *)&inf, sizeof(BMPInfo), 1, fp);
|
fread((char *)&inf, sizeof(BMPInfo), 1, fp);
|
||||||
if (hd.FileType != MB) {
|
if (hd.FileType != MB) {
|
||||||
swapbyte(&(hd.FileType));
|
swapbyte((hd.FileType));
|
||||||
swap=true;
|
swap=true;
|
||||||
if (hd.FileType != MB) {
|
if (hd.FileType != MB) {
|
||||||
bmperror=ERROR_READING_HEADER;
|
bmperror=ERROR_READING_HEADER;
|
||||||
@ -158,11 +158,12 @@ int *numComponents_ret)
|
|||||||
}
|
}
|
||||||
if (hd.FileType == MB) {
|
if (hd.FileType == MB) {
|
||||||
if (swap) { // inverse the field of the header which need swapping
|
if (swap) { // inverse the field of the header which need swapping
|
||||||
swapbyte(&hd.siz[0]);
|
swapbyte(hd.siz[0]);
|
||||||
swapbyte(&hd.siz[1]);
|
swapbyte(hd.siz[1]);
|
||||||
swapbyte(&inf.Colorbits);
|
swapbyte(inf.Colorbits);
|
||||||
swapbyte(&inf.width);
|
swapbyte(inf.width);
|
||||||
swapbyte(&inf.height);
|
swapbyte(inf.height);
|
||||||
|
swapbyte(inf.ImageSize);
|
||||||
}
|
}
|
||||||
long size = hd.siz[1]*65536+hd.siz[0];
|
long size = hd.siz[1]*65536+hd.siz[0];
|
||||||
size -= sizeof(bmpheader)+sizeof(BMPInfo);
|
size -= sizeof(bmpheader)+sizeof(BMPInfo);
|
||||||
@ -181,25 +182,32 @@ int *numComponents_ret)
|
|||||||
ncomp = RGBA;
|
ncomp = RGBA;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
buffer = (unsigned char *)malloc( ncomp*inf.width*inf.height);
|
imbuff = (unsigned char *)malloc( inf.ImageSize); // read from disk
|
||||||
osg::notify(osg::NOTICE)<<"BMP file: "<<filename << endl;
|
buffer = (unsigned char *)malloc( ncomp*inf.width*inf.height*sizeof(unsigned char)); //
|
||||||
osg::notify(osg::NOTICE)<<"sizes: "<< inf.width << " " << inf.height <<endl;
|
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 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*=4; // to find dword alignment
|
||||||
doff=fread((char *)buffer, sizeof(unsigned char),ncomp*inf.width*inf.height, fp);
|
fread((char *)imbuff, sizeof(unsigned char),inf.ImageSize, fp);
|
||||||
if (ncomp>2) { // yes bill, colours are usually BGR aren't they
|
for(int j=0; j<inf.height; j++) {
|
||||||
for(int j=0; j<inf.height; j++) {
|
memcpy(buffer+j*rowbytes, imbuff+off, rowbytes); // pack bytes closely
|
||||||
if (j<5) osg::notify(osg::NOTICE)<<"row: "<< j << " offset " << off <<endl;
|
off+=doff;
|
||||||
off+=doff;
|
if (ncomp>2) { // yes bill, colours are usually BGR aren't they
|
||||||
for(int i=0; i<inf.width; i++) {
|
for(int i=0; i<inf.width; i++) {
|
||||||
unsigned char blu=buffer[3*(i*inf.height+j)+0];
|
int ijw=i+j*inf.width;
|
||||||
buffer[3*(i*inf.height+j)+0]=buffer[3*(i*inf.height+j)+2]; // swap order of colours
|
unsigned char blu=buffer[3*ijw+0];
|
||||||
buffer[3*(i*inf.height+j)+2]=blu;
|
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
|
} // else error in header
|
||||||
fclose(fp);
|
fclose(fp);
|
||||||
@ -234,6 +242,7 @@ class ReaderWriterBMP : public osgDB::ReaderWriter
|
|||||||
int r = 1;
|
int r = 1;
|
||||||
|
|
||||||
int internalFormat = numComponents_ret;
|
int internalFormat = numComponents_ret;
|
||||||
|
|
||||||
|
|
||||||
unsigned int pixelFormat =
|
unsigned int pixelFormat =
|
||||||
numComponents_ret == 1 ? GL_LUMINANCE :
|
numComponents_ret == 1 ? GL_LUMINANCE :
|
||||||
@ -241,6 +250,9 @@ class ReaderWriterBMP : public osgDB::ReaderWriter
|
|||||||
numComponents_ret == 3 ? GL_RGB :
|
numComponents_ret == 3 ? GL_RGB :
|
||||||
numComponents_ret == 4 ? GL_RGBA : (GLenum)-1;
|
numComponents_ret == 4 ? GL_RGBA : (GLenum)-1;
|
||||||
|
|
||||||
|
cout << "internalFormat="<<internalFormat<<endl;
|
||||||
|
cout << "pixelFormat="<<pixelFormat<<endl;
|
||||||
|
|
||||||
unsigned int dataType = GL_UNSIGNED_BYTE;
|
unsigned int dataType = GL_UNSIGNED_BYTE;
|
||||||
|
|
||||||
osg::Image* pOsgImage = new osg::Image;
|
osg::Image* pOsgImage = new osg::Image;
|
||||||
|
@ -66,7 +66,6 @@ TARGET_INCLUDE_FILES = \
|
|||||||
osgUtil/SceneViewManipulator\
|
osgUtil/SceneViewManipulator\
|
||||||
osgUtil/SmoothingVisitor\
|
osgUtil/SmoothingVisitor\
|
||||||
osgUtil/StateSetManipulator\
|
osgUtil/StateSetManipulator\
|
||||||
osgUtil/Statistics\
|
|
||||||
osgUtil/Tesselator\
|
osgUtil/Tesselator\
|
||||||
osgUtil/TrackballManipulator\
|
osgUtil/TrackballManipulator\
|
||||||
osgUtil/TriStripVisitor\
|
osgUtil/TriStripVisitor\
|
||||||
|
@ -162,7 +162,7 @@ void RenderBin::draw_local(osg::State& state,RenderLeaf*& previous)
|
|||||||
}
|
}
|
||||||
// stats
|
// stats
|
||||||
#include <osg/GeoSet>
|
#include <osg/GeoSet>
|
||||||
void RenderBin::getPrims(Statistics *primStats)
|
void RenderBin::getPrims(osg::Statistics *primStats)
|
||||||
{
|
{
|
||||||
for(RenderBinList::iterator itr = _bins.begin();
|
for(RenderBinList::iterator itr = _bins.begin();
|
||||||
itr!=_bins.end();
|
itr!=_bins.end();
|
||||||
|
@ -140,7 +140,7 @@ void RenderStage::draw(osg::State& state,RenderLeaf*& previous)
|
|||||||
|
|
||||||
}
|
}
|
||||||
// Statistics features
|
// Statistics features
|
||||||
void RenderStage::getPrims(Statistics *primStats)
|
void RenderStage::getPrims(osg::Statistics *primStats)
|
||||||
{
|
{
|
||||||
if (_renderStageLighting.valid()) primStats->nlights+=_renderStageLighting->_lightList.size();
|
if (_renderStageLighting.valid()) primStats->nlights+=_renderStageLighting->_lightList.size();
|
||||||
RenderBin::getPrims(primStats);
|
RenderBin::getPrims(primStats);
|
||||||
|
Loading…
Reference in New Issue
Block a user