Added support for float or double osg::Plane, and the default osg::Plane to double.

Performance tests on big models did not indicate any performance penalty in using doubles over floats,
so the move to doubles should mainly impact precision improvements for whole earth databases.

Also made improvements to osgUtil::PlaneIntersector and osgSim::ElevationSlice classes
This commit is contained in:
Robert Osfield
2006-11-28 16:00:52 +00:00
parent 5e1c5cd556
commit 345810ef22
14 changed files with 262 additions and 135 deletions

View File

@@ -78,25 +78,24 @@ void TexGen::setPlanesFromMatrix(const Matrixd& matrix)
void TexGen::apply(State&) const
{
if (_mode == OBJECT_LINEAR)
if (_mode == OBJECT_LINEAR || _mode == EYE_LINEAR)
{
glTexGenfv(GL_S, GL_OBJECT_PLANE, _plane_s.ptr());
glTexGenfv(GL_T, GL_OBJECT_PLANE, _plane_t.ptr());
glTexGenfv(GL_R, GL_OBJECT_PLANE, _plane_r.ptr());
glTexGenfv(GL_Q, GL_OBJECT_PLANE, _plane_q.ptr());
glTexGeni( GL_S, GL_TEXTURE_GEN_MODE, _mode );
glTexGeni( GL_T, GL_TEXTURE_GEN_MODE, _mode );
glTexGeni( GL_R, GL_TEXTURE_GEN_MODE, _mode );
glTexGeni( GL_Q, GL_TEXTURE_GEN_MODE, _mode );
}
else if (_mode == EYE_LINEAR)
{
glTexGenfv(GL_S, GL_EYE_PLANE, _plane_s.ptr());
glTexGenfv(GL_T, GL_EYE_PLANE, _plane_t.ptr());
glTexGenfv(GL_R, GL_EYE_PLANE, _plane_r.ptr());
glTexGenfv(GL_Q, GL_EYE_PLANE, _plane_q.ptr());
GLenum glmode = _mode == OBJECT_LINEAR ? GL_OBJECT_PLANE : GL_EYE_PLANE;
if (sizeof(_plane_s[0])==sizeof(GLfloat))
{
glTexGenfv(GL_S, glmode, (const GLfloat*)_plane_s.ptr());
glTexGenfv(GL_T, glmode, (const GLfloat*)_plane_t.ptr());
glTexGenfv(GL_R, glmode, (const GLfloat*)_plane_r.ptr());
glTexGenfv(GL_Q, glmode, (const GLfloat*)_plane_q.ptr());
}
else
{
glTexGendv(GL_S, glmode, (const GLdouble*)_plane_s.ptr());
glTexGendv(GL_T, glmode, (const GLdouble*)_plane_t.ptr());
glTexGendv(GL_R, glmode, (const GLdouble*)_plane_r.ptr());
glTexGendv(GL_Q, glmode, (const GLdouble*)_plane_q.ptr());
}
glTexGeni( GL_S, GL_TEXTURE_GEN_MODE, _mode );
glTexGeni( GL_T, GL_TEXTURE_GEN_MODE, _mode );
@@ -120,8 +119,6 @@ void TexGen::apply(State&) const
}
else // SPHERE_MAP
{
// We ignore the planes if we are not in OBJECT_ or EYE_LINEAR mode.
// Also don't set the mode of GL_R & GL_Q as these will generate
// GL_INVALID_ENUM (See OpenGL Refrence Guide, glTexGEn.)

View File

@@ -157,11 +157,6 @@ bool DataInputStream::readBool(){
return c!=0;
}
unsigned int DataInputStream::getVersion()
{
return( _version );
}
char DataInputStream::readChar(){
char c;
_istream->read(&c, CHARSIZE);
@@ -387,11 +382,24 @@ osg::Vec4d DataInputStream::readVec4d(){
osg::Plane DataInputStream::readPlane(){
osg::Plane v;
v[0]=readFloat();
v[1]=readFloat();
v[2]=readFloat();
v[3]=readFloat();
if (getVersion() <= VERSION_0018)
{
v[0]=readFloat();
v[1]=readFloat();
v[2]=readFloat();
v[3]=readFloat();
}
else
{
// assume double for planes even if Plane::value_type is float
// to ensure that the .ive format does vary.
v[0]=readDouble();
v[1]=readDouble();
v[2]=readDouble();
v[3]=readDouble();
}
if (_verboseOutput) std::cout<<"read/writePlane() ["<<v<<"]"<<std::endl;
return v;

View File

@@ -40,7 +40,7 @@ public:
void setOptions(const osgDB::ReaderWriter::Options* options);
const osgDB::ReaderWriter::Options* getOptions() const { return _options.get(); }
unsigned int getVersion();
inline unsigned int getVersion() const { return _version; }
bool readBool();
char readChar();
unsigned char readUChar();

View File

@@ -272,10 +272,10 @@ void DataOutputStream::writeVec4d(const osg::Vec4d& v){
void DataOutputStream::writePlane(const osg::Plane& v)
{
writeFloat(v[0]);
writeFloat(v[1]);
writeFloat(v[2]);
writeFloat(v[3]);
writeDouble(v[0]);
writeDouble(v[1]);
writeDouble(v[2]);
writeDouble(v[3]);
if (_verboseOutput) std::cout<<"read/writePlane() ["<<v<<"]"<<std::endl;
}

View File

@@ -27,8 +27,9 @@
#define VERSION_0016 16
#define VERSION_0017 17
#define VERSION_0018 18
#define VERSION_0019 19
#define VERSION VERSION_0018
#define VERSION VERSION_0019
/* The BYTE_SEX tag is used to check the endian
of the IVE file being read in. The IVE format

View File

@@ -44,7 +44,7 @@ bool TexGen_readLocalData(Object& obj, Input& fr)
iteratorAdvanced = true;
}
Vec4 plane;
osg::Plane plane;
if (fr[0].matchWord("plane_s"))
{
if (fr[1].getFloat(plane[0]) && fr[2].getFloat(plane[1]) &&

View File

@@ -35,18 +35,54 @@ void ElevationSlice::computeIntersections(osg::Node* scene)
if (em)
{
osg::Vec3d upVector = em->computeLocalUpVector(_startPoint.x(), _startPoint.y(), _startPoint.z());
osg::Vec3d start_upVector = em->computeLocalUpVector(_startPoint.x(), _startPoint.y(), _startPoint.z());
osg::Vec3d end_upVector = em->computeLocalUpVector(_endPoint.x(), _endPoint.y(), _endPoint.z());
double latitude, longitude, height;
em->convertXYZToLatLongHeight(_startPoint.x(), _startPoint.y(), _startPoint.z(), latitude, longitude, height);
double start_latitude, start_longitude, start_height;
em->convertXYZToLatLongHeight(_startPoint.x(), _startPoint.y(), _startPoint.z(),
start_latitude, start_longitude, start_height);
osg::notify(osg::NOTICE)<<"lat = "<<latitude<<" longitude = "<<longitude<<" height = "<<height<<std::endl;
osg::notify(osg::NOTICE)<<"start_lat = "<<start_latitude<<" start_longitude = "<<start_longitude<<" start_height = "<<start_height<<std::endl;
double end_latitude, end_longitude, end_height;
em->convertXYZToLatLongHeight(_endPoint.x(), _endPoint.y(), _endPoint.z(),
end_latitude, end_longitude, end_height);
osg::notify(osg::NOTICE)<<"end_lat = "<<end_latitude<<" end_longitude = "<<end_longitude<<" end_height = "<<end_height<<std::endl;
// set up the main intersection plane
osg::Vec3d planeNormal = (_endPoint - _startPoint) ^ start_upVector;
planeNormal.normalize();
plane.set( planeNormal, _startPoint );
// set up the start cut off plane
osg::Vec3d startPlaneNormal = start_upVector ^ planeNormal;
startPlaneNormal.normalize();
boundingPolytope.add( osg::Plane(startPlaneNormal, _startPoint) );
// set up the end cut off plane
osg::Vec3d endPlaneNormal = planeNormal ^ end_upVector;
endPlaneNormal.normalize();
boundingPolytope.add( osg::Plane(endPlaneNormal, _endPoint) );
}
else
{
osg::Vec3d upVector (0.0, 0.0, 1.0);
// set up the main intersection plane
osg::Vec3d planeNormal = (_endPoint - _startPoint) ^ upVector;
planeNormal.normalize();
plane.set( planeNormal, _startPoint );
// set up the start cut off plane
osg::Vec3d startPlaneNormal = upVector ^ planeNormal;
startPlaneNormal.normalize();
boundingPolytope.add( osg::Plane(startPlaneNormal, _startPoint) );
// set up the end cut off plane
osg::Vec3d endPlaneNormal = planeNormal ^ upVector;
endPlaneNormal.normalize();
boundingPolytope.add( osg::Plane(endPlaneNormal, _endPoint) );
}
osg::ref_ptr<osgUtil::PlaneIntersector> intersector = new osgUtil::PlaneIntersector(plane, boundingPolytope);

View File

@@ -69,21 +69,21 @@ struct FadeTextPolytopeData : public FadeTextData, public osg::Polytope
void buildPolytope()
{
osg::Vec3 edge01 = _vertices[1] - _vertices[0];
osg::Vec3 edge12 = _vertices[2] - _vertices[1];
osg::Vec3 edge23 = _vertices[3] - _vertices[2];
osg::Vec3 edge30 = _vertices[0] - _vertices[3];
osg::Vec3d edge01 = _vertices[1] - _vertices[0];
osg::Vec3d edge12 = _vertices[2] - _vertices[1];
osg::Vec3d edge23 = _vertices[3] - _vertices[2];
osg::Vec3d edge30 = _vertices[0] - _vertices[3];
osg::Vec3 normalFrontFace = edge01 ^ edge12;
osg::Vec3d normalFrontFace = edge01 ^ edge12;
bool needToFlip = normalFrontFace.z()>0.0f;
normalFrontFace.normalize();
add(osg::Plane(normalFrontFace, _vertices[0]));
add(osg::Plane( osg::Vec3(0.0f,0.0f,0.0f), _vertices[0], _vertices[1]));
add(osg::Plane( osg::Vec3(0.0f,0.0f,0.0f), _vertices[1], _vertices[2]));
add(osg::Plane( osg::Vec3(0.0f,0.0f,0.0f), _vertices[2], _vertices[3]));
add(osg::Plane( osg::Vec3(0.0f,0.0f,0.0f), _vertices[3], _vertices[0]));
add(osg::Plane( osg::Vec3d(0.0f,0.0f,0.0f), _vertices[0], _vertices[1]));
add(osg::Plane( osg::Vec3d(0.0f,0.0f,0.0f), _vertices[1], _vertices[2]));
add(osg::Plane( osg::Vec3d(0.0f,0.0f,0.0f), _vertices[2], _vertices[3]));
add(osg::Plane( osg::Vec3d(0.0f,0.0f,0.0f), _vertices[3], _vertices[0]));
#if 0
osg::notify(osg::NOTICE)<<" normalFrontFace = "<<normalFrontFace<<std::endl;

View File

@@ -696,7 +696,7 @@ Intersector* PlaneIntersector::clone(osgUtil::IntersectionVisitor& iv)
bool PlaneIntersector::enter(const osg::Node& node)
{
return !node.isCullingActive() ||
( _plane.intersect(node.getBound()) && _polytope.contains(node.getBound()) );
( _plane.intersect(node.getBound())==0 && _polytope.contains(node.getBound()) );
}
@@ -708,9 +708,13 @@ void PlaneIntersector::leave()
void PlaneIntersector::intersect(osgUtil::IntersectionVisitor& iv, osg::Drawable* drawable)
{
osg::notify(osg::NOTICE)<<"PlaneIntersector::intersect(osgUtil::IntersectionVisitor& iv, osg::Drawable* drawable)"<<std::endl;
if ( !_plane.intersect( drawable->getBound() ) ) return;
if ( !_polytope.contains( drawable->getBound() ) ) return;
osg::notify(osg::NOTICE)<<"Succed PlaneIntersector::intersect(osgUtil::IntersectionVisitor& iv, osg::Drawable* drawable)"<<std::endl;
Intersection hit;
hit.nodePath = iv.getNodePath();
hit.drawable = drawable;