Udates to Drawable + IVE plugin with support for new ClusterCullingCallack.

Improvement to osgbluemarble.
This commit is contained in:
Robert Osfield
2003-10-10 12:54:21 +00:00
parent 83b04bd04b
commit 5d35daa970
7 changed files with 240 additions and 169 deletions

View File

@@ -899,6 +899,7 @@ void Drawable::Extensions::glGetOcclusionQueryuiv( GLuint id, GLenum pname, GLui
//
ClusterCullingCallback::ClusterCullingCallback():
_radius(-1.0f),
_deviation(-1.0f)
{
}
@@ -919,20 +920,24 @@ ClusterCullingCallback::ClusterCullingCallback(const osg::Drawable* drawable)
computeFrom(drawable);
}
struct CollectNormalsFunctor
struct ComputeAveragesFunctor
{
CollectNormalsFunctor():
_x(0.0),_y(0.0),_z(0) {}
ComputeAveragesFunctor():
_num(0),
_x(0.0),_y(0.0),_z(0),
_nx(0.0),_ny(0.0),_nz(0) {}
inline void operator() ( const osg::Vec3 &v1, const osg::Vec3 &v2, const osg::Vec3 &v3, bool)
{
// calc orientation of triangle.
osg::Vec3 normal = (v2-v1)^(v3-v1);
normal.normalize();
_normals.push_back(normal);
if (normal.normalize()!=0.0f)
{
_nx += normal.x();
_ny += normal.y();
_nz += normal.z();
}
_x += v1.x();
_y += v1.y();
_z += v1.z();
@@ -944,20 +949,74 @@ struct CollectNormalsFunctor
_x += v3.x();
_y += v3.y();
_z += v3.z();
++_num;
}
typedef std::vector<osg::Vec3> NormalList;
NormalList _normals;
osg::Vec3 center() const { return osg::Vec3(_x/(double)(3*_num),_y/(double)(3*_num),_z/(double)(3*_num)); }
osg::Vec3 normal() const { Vec3 normal(_nx/(double)_num,_ny/(double)_num,_nz/(double)_num); normal.normalize(); return normal; }
unsigned int _num;
double _x,_y,_z;
double _nx,_ny,_nz;
};
struct ComputeDeviationFunctor
{
ComputeDeviationFunctor():
_deviation(1.0),
_radius2(0.0) {}
void set(const osg::Vec3& center,const osg::Vec3& normal)
{
_center = center;
_normal = normal;
}
inline void operator() ( const osg::Vec3 &v1, const osg::Vec3 &v2, const osg::Vec3 &v3, bool)
{
// calc orientation of triangle.
osg::Vec3 normal = (v2-v1)^(v3-v1);
if (normal.normalize()!=0.0f)
{
_deviation = osg::minimum(_normal*normal,_deviation);
}
_radius2 = osg::maximum((v1-_center).length2(),_radius2);
_radius2 = osg::maximum((v2-_center).length2(),_radius2);
_radius2 = osg::maximum((v3-_center).length2(),_radius2);
}
osg::Vec3 _center;
osg::Vec3 _normal;
float _deviation;
float _radius2;
};
void ClusterCullingCallback::computeFrom(const osg::Drawable* drawable)
{
TriangleFunctor<CollectNormalsFunctor> stf;
drawable->accept(stf);
TriangleFunctor<ComputeAveragesFunctor> caf;
drawable->accept(caf);
_controlPoint = caf.center();
_normal = caf.normal();
TriangleFunctor<ComputeDeviationFunctor> cdf;
cdf.set(_controlPoint,_normal);
drawable->accept(cdf);
if (_normal.length2()==0.0) _deviation = -1.0f;
else
{
float angle = acosf(cdf._deviation)+osg::PI*0.5f;
if (angle<osg::PI) _deviation = cosf(angle);
else _deviation = -1.0f;
}
_radius = sqrtf(cdf._radius2);
}
void ClusterCullingCallback::set(const osg::Vec3& controlPoint, const osg::Vec3& normal, float deviation)
@@ -968,7 +1027,13 @@ void ClusterCullingCallback::set(const osg::Vec3& controlPoint, const osg::Vec3&
}
bool ClusterCullingCallback::cull(osg::NodeVisitor*, osg::Drawable*, osg::State*) const
bool ClusterCullingCallback::cull(osg::NodeVisitor* nv, osg::Drawable* , osg::State*) const
{
return false;
if (_deviation<=-1.0f) return false;
osg::Vec3 eye_cp = nv->getEyePoint() - _controlPoint;
float deviation = (eye_cp * _normal)/eye_cp.length();
return deviation < _deviation;
}

View File

@@ -50,10 +50,10 @@ class ReaderWriterGDAL : public osgDB::ReaderWriter
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;
windowX = osg::maximum((int)(floor((double)dataWidth * imageOptions->_sourceRatioWindow.windowX)),0);
windowY = osg::maximum((int)(floor((double)dataHeight * imageOptions->_sourceRatioWindow.windowY)),0);
windowWidth = osg::minimum((int)(ceil((double)dataWidth * (imageOptions->_sourceRatioWindow.windowX + imageOptions->_sourceRatioWindow.windowWidth))),dataWidth)-windowX;
windowHeight = osg::minimum((int)(ceil((double)dataHeight * (imageOptions->_sourceRatioWindow.windowY + imageOptions->_sourceRatioWindow.windowHeight))),dataHeight)-windowY;
break;
case(osgDB::ImageOptions::PIXEL_WINDOW):
windowX = imageOptions->_sourcePixelWindow.windowX;

View File

@@ -1,100 +1,107 @@
/**********************************************************************
*
* FILE: Drawable.cpp
* FILE: Drawable.cpp
*
* DESCRIPTION: Read/Write osg::Drawable in binary format to disk.
* DESCRIPTION: Read/Write osg::Drawable in binary format to disk.
*
* CREATED BY: Auto generated by iveGenerated
* and later modified by Rune Schmidt Jensen.
* CREATED BY: Auto generated by iveGenerated
* and later modified by Rune Schmidt Jensen.
*
* HISTORY: Created 18.3.2003
* HISTORY: Created 18.3.2003
*
* Copyright 2003 VR-C
* Copyright 2003 VR-C
**********************************************************************/
#include "Exception.h"
#include "Drawable.h"
#include "ClusterCullingCallback.h"
#include "Object.h"
#include "StateSet.h"
using namespace ive;
void Drawable::write(DataOutputStream* out){
// Write Drawable's identification.
out->writeInt(IVEDRAWABLE);
// If the osg class is inherited by any other class we should also write this to file.
osg::Object* obj = dynamic_cast<osg::Object*>(this);
if(obj){
((ive::Object*)(obj))->write(out);
}
else
throw Exception("Drawable::write(): Could not cast this osg::Drawable to an osg::Object.");
void Drawable::write(DataOutputStream* out)
{
// Write Drawable's identification.
out->writeInt(IVEDRAWABLE);
// If the osg class is inherited by any other class we should also write this to file.
osg::Object* obj = dynamic_cast<osg::Object*>(this);
if(obj){
((ive::Object*)(obj))->write(out);
}
else
throw Exception("Drawable::write(): Could not cast this osg::Drawable to an osg::Object.");
// Write Drawable's properties.
// Write stateset if any
if (getStateSet())
{
out->writeInt(1); //true we have a stateset
out->writeStateSet(getStateSet());
}
else
out->writeInt(0); //false we don't have a stateset
// Write Drawable's properties.
// Write shape
if (getShape())
{
out->writeInt(1); //true we have a shape
//static_cast<Shape*>(getShape())->write(out);
}
else
out->writeInt(0); //false we don't have a shape
// Write stateset if any
out->writeBool(getStateSet()!=0);
if (getStateSet())
{
out->writeStateSet(getStateSet());
}
osg::ClusterCullingCallback* ccc = dynamic_cast<osg::ClusterCullingCallback*>(getCullCallback());
out->writeBool(ccc!=0);
if(ccc)
{
((ive::ClusterCullingCallback*)(ccc))->write(out);
}
// Write support display list.
out->writeBool(getSupportsDisplayList());
// Write support display list.
out->writeBool(getSupportsDisplayList());
// Write use display list.
out->writeBool(getUseDisplayList());
// Write use display list.
out->writeBool(getUseDisplayList());
// Write use display list.
out->writeBool(getUseVertexBufferObjects());
}
void Drawable::read(DataInputStream* in){
// Read Drawable's identification.
int id = in->peekInt();
if(id == IVEDRAWABLE){
// Code to read Drawable's properties.
id = in->readInt();
// If the osg class is inherited by any other class we should also read this from file.
osg::Object* obj = dynamic_cast<osg::Object*>(this);
if(obj){
((ive::Object*)(obj))->read(in);
}
else
throw Exception("Drawable::read(): Could not cast this osg::Drawable to an osg::Object.");
void Drawable::read(DataInputStream* in)
{
// Read Drawable's identification.
int id = in->peekInt();
if(id == IVEDRAWABLE)
{
// Code to read Drawable's properties.
id = in->readInt();
// If the osg class is inherited by any other class we should also read this from file.
osg::Object* obj = dynamic_cast<osg::Object*>(this);
if(obj){
((ive::Object*)(obj))->read(in);
}
else
throw Exception("Drawable::read(): Could not cast this osg::Drawable to an osg::Object.");
// Read in drawable's properties
// Read in drawable's properties
// Read stateset if any
if(in->readInt()){
setStateSet(in->readStateSet());
}
// Read stateset if any
if(in->readBool())
{
setStateSet(in->readStateSet());
}
// Read shape if any
if(in->readInt()){
//osg::Shape* shape = new osg::Shape();
//static_cast<Shape*>(shape)->read(in);
//setShape(shape);
}
if(in->readBool())
{
osg::ClusterCullingCallback* ccc = new osg::ClusterCullingCallback();
((ive::ClusterCullingCallback*)(ccc))->read(in);
setCullCallback(ccc);
}
// Read support display list
setSupportsDisplayList(in->readBool());
// Read support display list
setSupportsDisplayList(in->readBool());
// Read use display list
setUseDisplayList(in->readBool());
// Read use display list
setUseDisplayList(in->readBool());
}
else{
throw Exception("Drawable::read(): Expected Drawable identification.");
}
// Read use display list
setUseVertexBufferObjects(in->readBool());
}
else{
throw Exception("Drawable::read(): Expected Drawable identification.");
}
}

View File

@@ -8,6 +8,7 @@ CXXFILES =\
BlendFunc.cpp\
ConvexPlanarOccluder.cpp\
ConvexPlanarPolygon.cpp\
ClusterCullingCallback.cpp\
CullFace.cpp\
DataInputStream.cpp\
DataOutputStream.cpp\

View File

@@ -32,6 +32,7 @@ namespace ive {
// Node callbacks
#define IVENODECALLBACK 0x00000050
#define IVEANIMATIONPATHCALLBACK 0x00000051
#define IVECLUSTERCULLINGCALLBACK 0x00000052
// State attributes.
#define IVESTATEATTRIBUTE 0x00000100