From 0ba2d26b1a7e6e5f86929fbad37ef3f1cedcba6a Mon Sep 17 00:00:00 2001 From: Robert Osfield Date: Thu, 29 Apr 2004 22:22:22 +0000 Subject: [PATCH] Added Support for cluster culling. Removed osgTerrain::CoordinateSystem which is now replaced by osg::CoordinateSystemNode. --- include/osgTerrain/CoordinateSystem | 210 ---------------------------- include/osgTerrain/DataSet | 51 ++++--- include/osgTerrain/Terrain | 13 +- src/osgTerrain/CoordinateSystem.cpp | 53 ------- src/osgTerrain/DataSet.cpp | 144 +++++++++++++------ src/osgTerrain/GNUmakefile | 1 - 6 files changed, 129 insertions(+), 343 deletions(-) delete mode 100644 include/osgTerrain/CoordinateSystem delete mode 100644 src/osgTerrain/CoordinateSystem.cpp diff --git a/include/osgTerrain/CoordinateSystem b/include/osgTerrain/CoordinateSystem deleted file mode 100644 index 03aa0a7d1..000000000 --- a/include/osgTerrain/CoordinateSystem +++ /dev/null @@ -1,210 +0,0 @@ -/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2003 Robert Osfield - * - * This library is open source and may be redistributed and/or modified under - * the terms of the OpenSceneGraph Public License (OSGPL) version 0.0 or - * (at your option) any later version. The full license is in LICENSE file - * included with this distribution, and on the openscenegraph.org website. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * OpenSceneGraph Public License for more details. -*/ - -#ifndef OSGTERRAIN_COORDINATESYSTEM -#define OSGTERRAIN_COORDINATESYSTEM 1 - -#include -#include -#include -#include - -#include - -namespace osgTerrain -{ - -const double WGS_84_RADIUS_EQUATOR = 6378137.0; -const double WGS_84_RADIUS_POLAR = 6356752.3142; - -class EllipsodeTransform -{ - public: - - EllipsodeTransform(double radiusEquator = WGS_84_RADIUS_EQUATOR, - double radiusPolar = WGS_84_RADIUS_POLAR): - _radiusEquator(radiusEquator), - _radiusPolar(radiusPolar) { computeCoefficients(); } - - EllipsodeTransform(const EllipsodeTransform& et): - _radiusEquator(et._radiusEquator), - _radiusPolar(et._radiusPolar) { computeCoefficients(); } - - void setRadiusEquator(double radius) { _radiusEquator = radius; computeCoefficients(); } - double getRadiusEquator() const { return _radiusEquator; } - - void setRadiusPolar(double radius) { _radiusPolar = radius; computeCoefficients(); } - double getRadiusPolar() const { return _radiusPolar; } - - inline void convertLatLongHeightToXYZ(double latitude, double longitude, double height, - double& X, double& Y, double& Z) const - { - // for details on maths see http://www.colorado.edu/geography/gcraft/notes/datum/gif/llhxyz.gif - double sin_latitude = sin(latitude); - double cos_latitude = cos(latitude); - double N = _radiusEquator / sqrt( 1.0 - _eccentricitySquared*sin_latitude*sin_latitude); - X = (N+height)*cos_latitude*cos(longitude); - Y = (N+height)*cos_latitude*sin(longitude); - Z = (N*(1-_eccentricitySquared)+height)*sin(latitude); - } - - inline void convertXYZToLatLongHeight(double X, double Y, double Z, - double& latitude, double& longitude, double& height) const - { - // http://www.colorado.edu/geography/gcraft/notes/datum/gif/xyzllh.gif - double p = sqrt(X*X + Y*Y); - double theta = atan(Z*_radiusEquator/ (p*_radiusPolar)); - double eDashSquared = (_radiusEquator*_radiusEquator - _radiusPolar*_radiusPolar)/ - (_radiusPolar*_radiusPolar); - - double sin_theta = sin(theta); - double cos_theta = cos(theta); - - latitude = atan( (Z + eDashSquared*_radiusPolar*sin_theta*sin_theta*sin_theta) / - (p - _eccentricitySquared*_radiusEquator*cos_theta*cos_theta*cos_theta) ); - longitude = atan2(Y,X); - - double sin_latitude = sin(latitude); - double N = _radiusEquator / sqrt( 1.0 - _eccentricitySquared*sin_latitude*sin_latitude); - - height = p/cos(latitude) - N; - } - - inline void computeLocalToWorldTransform(double latitude, double longitude, double height, osg::Matrixd& localToWorld) const - { - double X, Y, Z; - convertLatLongHeightToXYZ(latitude,longitude,height,X,Y,Z); - - localToWorld.makeTranslate(X,Y,Z); - - // normalize X,Y,Z - double inverse_length = 1.0/sqrt(X*X + Y*Y + Z*Z); - X *= inverse_length; - Y *= inverse_length; - Z *= inverse_length; - - double length_XY = sqrt(X*X + Y*Y); - double inverse_length_XY = 1.0/length_XY; - - // Vx = |(-Y,X,0)| - localToWorld(0,0) = -Y*inverse_length_XY; - localToWorld(0,1) = X*inverse_length_XY; - localToWorld(0,2) = 0.0; - - // Vy = /(-Z*X/(sqrt(X*X+Y*Y), -Z*Y/(sqrt(X*X+Y*Y),sqrt(X*X+Y*Y))| - double Vy_x = -Z*X*inverse_length_XY; - double Vy_y = -Z*Y*inverse_length_XY; - double Vy_z = length_XY; - inverse_length = 1.0/sqrt(Vy_x*Vy_x + Vy_y*Vy_y + Vy_z*Vy_z); - localToWorld(1,0) = Vy_x*inverse_length; - localToWorld(1,1) = Vy_y*inverse_length; - localToWorld(1,2) = Vy_z*inverse_length; - - // Vz = (X,Y,Z) - localToWorld(2,0) = X; - localToWorld(2,1) = Y; - localToWorld(2,2) = Z; - } - - osg::Vec3 computeGavitationVector(double X, double Y, double Z) const - { - osg::Vec3 normal(-X,-Y,-Z); - normal.normalize(); - return normal; - } - - - protected: - - void computeCoefficients() - { - double flattening = (_radiusEquator-_radiusPolar)/_radiusEquator; - _eccentricitySquared = 2*flattening - flattening*flattening; - } - - double _radiusEquator; - double _radiusPolar; - double _eccentricitySquared; - -}; - -/** CoordinateSystem encapsulate the coordinate system that associated with objects in a scene.*/ -class CoordinateSystem : public osg::Object -{ - public: - - CoordinateSystem(); - - CoordinateSystem(const std::string& WTK); - - /** Copy constructor using CopyOp to manage deep vs shallow copy.*/ - CoordinateSystem(const CoordinateSystem&,const osg::CopyOp& copyop=osg::CopyOp::SHALLOW_COPY); - - META_Object(osgTerrain,CoordinateSystem); - - inline bool operator == (const CoordinateSystem& cs) const - { - if (this == &cs) return true; - if (_WKT != cs._WKT) return false; - return true; - } - - inline bool operator != (const CoordinateSystem& cs) const - { - return !(*this==cs); - } - - /** Set the CoordinateSystem reference string, should be stored in OpenGIS Well Know Text form.*/ - void setWKT(const std::string& WKT) { _WKT = WKT; } - - /** Get the CoordinateSystem reference string.*/ - const std::string& getWKT() const { return _WKT; } - - - /** CoordinateTransformation is a helper class for transforming between two different CoodinateSystems. - * To use, simply constructor a CoordinateSystem::CoordinateTransformation convertor(sourceCS,destinateCS) - * and then convert indiviual points via v_destination = convert(v_source), or the - * CoordinateTransformation.convert(ptr,num) method when handling arrays of Vec2/Vec3's.*/ - class CoordinateTransformation : public osg::Referenced - { - public: - - static CoordinateTransformation* createCoordinateTransformation(const CoordinateSystem& source, const CoordinateSystem& destination); - - static void setCoordinateTransformationPrototpe(CoordinateTransformation* ct); - - virtual osg::Vec2 operator () (const osg::Vec2& source) const = 0; - virtual osg::Vec3 operator () (const osg::Vec3& source) const = 0; - - virtual bool transform(unsigned int numPoints, osg::Vec2* vec2ptr) const = 0; - virtual bool transform(unsigned int numPoints, osg::Vec3* vec3ptr) const = 0; - - protected: - - CoordinateTransformation() {} - virtual ~CoordinateTransformation() {} - - virtual CoordinateTransformation* cloneCoordinateTransformation(const CoordinateSystem& source, const CoordinateSystem& destination) const = 0; - - }; - - protected: - - virtual ~CoordinateSystem() {} - - std::string _WKT; - -}; - -} -#endif diff --git a/include/osgTerrain/DataSet b/include/osgTerrain/DataSet index cde76c020..a5477c9b6 100644 --- a/include/osgTerrain/DataSet +++ b/include/osgTerrain/DataSet @@ -19,8 +19,7 @@ #include #include #include - -#include +#include #include @@ -53,7 +52,7 @@ class OSGTERRAIN_EXPORT DataSet : public osg::Referenced _numValuesY(sp._numValuesY), _numValuesZ(sp._numValuesZ) {} - SpatialProperties(osgTerrain::CoordinateSystem* cs, const osg::BoundingBox& extents): + SpatialProperties(osg::CoordinateSystemNode* cs, const osg::BoundingBox& extents): _cs(cs), _extents(extents), _numValuesX(0), @@ -81,7 +80,7 @@ class OSGTERRAIN_EXPORT DataSet : public osg::Referenced _extents.expandBy( osg::Vec3(_numValuesX,_numValuesY,0.0)*_geoTransform); } - osg::ref_ptr _cs; + osg::ref_ptr _cs; osg::Matrixd _geoTransform; osg::BoundingBox _extents; unsigned int _numValuesX; @@ -123,9 +122,9 @@ class OSGTERRAIN_EXPORT DataSet : public osg::Referenced static SourceData* readData(Source* source); - osg::BoundingBox getExtents(const osgTerrain::CoordinateSystem* cs) const; + osg::BoundingBox getExtents(const osg::CoordinateSystemNode* cs) const; - const SpatialProperties& computeSpatialProperties(const osgTerrain::CoordinateSystem* cs) const; + const SpatialProperties& computeSpatialProperties(const osg::CoordinateSystemNode* cs) const; bool intersects(const SpatialProperties& sp) const; @@ -142,7 +141,7 @@ class OSGTERRAIN_EXPORT DataSet : public osg::Referenced osg::ref_ptr _model; GDALDataset* _gdalDataSet; - typedef std::map SpatialPropertiesMap; + typedef std::map SpatialPropertiesMap; mutable SpatialPropertiesMap _spatialPropertiesMap; @@ -201,9 +200,9 @@ class OSGTERRAIN_EXPORT DataSet : public osg::Referenced void setCoordinateSystemPolicy(ParameterPolicy policy) { _coordinateSystemPolicy = policy; } ParameterPolicy getCoordinateSystemPolicy() const { return _coordinateSystemPolicy; } - void setCoordinateSystem(const std::string& wellKnownText) { _cs = new osgTerrain::CoordinateSystem(wellKnownText); } - void setCoordinateSystem(osgTerrain::CoordinateSystem* cs) { _cs = cs; } - osgTerrain::CoordinateSystem* getCoordinateSystem() { return _cs.get(); } + void setCoordinateSystem(const std::string& wellKnownText) { _cs = new osg::CoordinateSystemNode(wellKnownText); } + void setCoordinateSystem(osg::CoordinateSystemNode* cs) { _cs = cs; } + osg::CoordinateSystemNode* getCoordinateSystem() { return _cs.get(); } void setGeoTransformPolicy(ParameterPolicy policy) { _geoTransformPolicy = policy; } @@ -225,11 +224,11 @@ class OSGTERRAIN_EXPORT DataSet : public osg::Referenced void loadSourceData(); - bool needReproject(const osgTerrain::CoordinateSystem* cs) const; + bool needReproject(const osg::CoordinateSystemNode* cs) const; - bool needReproject(const osgTerrain::CoordinateSystem* cs, double minResolution, double maxResolution) const; + bool needReproject(const osg::CoordinateSystemNode* cs, double minResolution, double maxResolution) const; - Source* doReproject(const std::string& filename, osgTerrain::CoordinateSystem* cs, double targetResolution=0.0) const; + Source* doReproject(const std::string& filename, osg::CoordinateSystemNode* cs, double targetResolution=0.0) const; void buildOverviews(); @@ -745,7 +744,7 @@ class OSGTERRAIN_EXPORT DataSet : public osg::Referenced _maxVisibleDistance(FLT_MAX), _subTileGenerated(false) {} - CompositeDestination(osgTerrain::CoordinateSystem* cs, const osg::BoundingBox& extents): + CompositeDestination(osg::CoordinateSystemNode* cs, const osg::BoundingBox& extents): SpatialProperties(cs,extents), _dataSet(0), _parent(0), @@ -851,19 +850,19 @@ class OSGTERRAIN_EXPORT DataSet : public osg::Referenced void setDefaultColor(const osg::Vec4& defaultColor) { _defaultColor = defaultColor; } const osg::Vec4& getDefaultColor() const { return _defaultColor; } - void setDestinationCoordinateSystem(const std::string& wellKnownText) { setDestinationCoordinateSystem(new osgTerrain::CoordinateSystem(wellKnownText)); } - void setDestinationCoordinateSystem(osgTerrain::CoordinateSystem* cs) { _destinationCoordinateSystem = cs; } - osgTerrain::CoordinateSystem* getDestinationCoordinateSystem() { return _destinationCoordinateSystem .get(); } + void setDestinationCoordinateSystem(const std::string& wellKnownText) { setDestinationCoordinateSystem(new osg::CoordinateSystemNode(wellKnownText)); } + void setDestinationCoordinateSystem(osg::CoordinateSystemNode* cs) { _destinationCoordinateSystem = cs; } + osg::CoordinateSystemNode* getDestinationCoordinateSystem() { return _destinationCoordinateSystem .get(); } - void setIntermediateCoordinateSystem(const std::string& wellKnownText) { setIntermediateCoordinateSystem(new osgTerrain::CoordinateSystem(wellKnownText)); } - void setIntermediateCoordinateSystem(osgTerrain::CoordinateSystem* cs) { _intermediateCoordinateSystem = cs; } - osgTerrain::CoordinateSystem* getIntermediateCoordinateSystem() { return _intermediateCoordinateSystem.get(); } + void setIntermediateCoordinateSystem(const std::string& wellKnownText) { setIntermediateCoordinateSystem(new osg::CoordinateSystemNode(wellKnownText)); } + void setIntermediateCoordinateSystem(osg::CoordinateSystemNode* cs) { _intermediateCoordinateSystem = cs; } + osg::CoordinateSystemNode* getIntermediateCoordinateSystem() { return _intermediateCoordinateSystem.get(); } void setConvertFromGeographicToGeocentric(bool flag) { _convertFromGeographicToGeocentric = flag; } bool getConvertFromGeographicToGeocentric() const { return _convertFromGeographicToGeocentric; } - void setEllipsodeTransform(const osgTerrain::EllipsodeTransform& et) { _ellipsodeTransform = et; } - osgTerrain::EllipsodeTransform& getEllipsodeTransform() { return _ellipsodeTransform; } + void setEllipsoidModel(osg::EllipsoidModel* et) { _ellipsoidModel = et; } + osg::EllipsoidModel* getEllipsoidModel() { return _ellipsoidModel.get(); } void setDestinationExtents(const osg::BoundingBox& extents) { _extents = extents; } @@ -907,7 +906,7 @@ class OSGTERRAIN_EXPORT DataSet : public osg::Referenced CompositeDestination* createDestinationGraph(CompositeDestination* parent, - osgTerrain::CoordinateSystem* cs, + osg::CoordinateSystemNode* cs, const osg::BoundingBox& extents, unsigned int maxImageSize, unsigned int maxTerrainSize, @@ -950,11 +949,11 @@ class OSGTERRAIN_EXPORT DataSet : public osg::Referenced float _radiusToMaxVisibleDistanceRatio; float _verticalScale; - osg::ref_ptr _destinationCoordinateSystem; - osg::ref_ptr _intermediateCoordinateSystem; + osg::ref_ptr _destinationCoordinateSystem; + osg::ref_ptr _intermediateCoordinateSystem; bool _convertFromGeographicToGeocentric; - osgTerrain::EllipsodeTransform _ellipsodeTransform; + osg::ref_ptr _ellipsoidModel; osg::Matrixd _geoTransform; osg::BoundingBox _extents; diff --git a/include/osgTerrain/Terrain b/include/osgTerrain/Terrain index 3ac8f6906..b8d1f2e83 100644 --- a/include/osgTerrain/Terrain +++ b/include/osgTerrain/Terrain @@ -18,7 +18,7 @@ #include #include -#include +#include namespace osgTerrain { @@ -38,16 +38,6 @@ class OSGTERRAIN_EXPORT Terrain : public osg::Group virtual void traverse(osg::NodeVisitor& nv); - /** Set the coordinates system associated with this Terrain*/ - void setCoordinateSystem(CoordinateSystem* cs) { _coordinateSystem = cs; } - - /** Get the coordinates system associated with this Terrain*/ - CoordinateSystem* getCoordinateSystem() { return _coordinateSystem.get(); } - - /** Get the const coordinates system associated with this Terrain*/ - const CoordinateSystem* getCoordinateSystem() const { return _coordinateSystem.get(); } - - /** Set the HeightField for this Terrain. * If a Renderer is attached then this will be notified.*/ void setHeightField(osg::HeightField* heightField); @@ -96,7 +86,6 @@ class OSGTERRAIN_EXPORT Terrain : public osg::Group virtual ~Terrain(); - osg::ref_ptr _coordinateSystem; osg::ref_ptr _heightField; osg::ref_ptr _renderer; diff --git a/src/osgTerrain/CoordinateSystem.cpp b/src/osgTerrain/CoordinateSystem.cpp deleted file mode 100644 index 6fff2f73c..000000000 --- a/src/osgTerrain/CoordinateSystem.cpp +++ /dev/null @@ -1,53 +0,0 @@ -/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2003 Robert Osfield - * - * This library is open source and may be redistributed and/or modified under - * the terms of the OpenSceneGraph Public License (OSGPL) version 0.0 or - * (at your option) any later version. The full license is in LICENSE file - * included with this distribution, and on the openscenegraph.org website. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * OpenSceneGraph Public License for more details. -*/ - -#include - -using namespace osgTerrain; - -CoordinateSystem::CoordinateSystem() -{ -} - -CoordinateSystem::CoordinateSystem(const std::string& WKT): - _WKT(WKT) -{ -} - -CoordinateSystem::CoordinateSystem(const CoordinateSystem& cs,const osg::CopyOp& copyop): - Object(cs,copyop), - _WKT(cs._WKT) -{ -} - - -osg::ref_ptr& getCoordinateTransformationPrototypePtr() -{ - static osg::ref_ptr s_coordinateSystemPrototype; - return s_coordinateSystemPrototype; -} - - -CoordinateSystem::CoordinateTransformation* CoordinateSystem::CoordinateTransformation::createCoordinateTransformation(const CoordinateSystem& source, const CoordinateSystem& destination) -{ - if (getCoordinateTransformationPrototypePtr().valid()) - { - getCoordinateTransformationPrototypePtr()->cloneCoordinateTransformation(source, destination); - } - return 0L; -} - -void CoordinateSystem::CoordinateTransformation::setCoordinateTransformationPrototpe(CoordinateTransformation* ct) -{ - getCoordinateTransformationPrototypePtr() = ct; -} diff --git a/src/osgTerrain/DataSet.cpp b/src/osgTerrain/DataSet.cpp index e496afe81..d49ac5026 100644 --- a/src/osgTerrain/DataSet.cpp +++ b/src/osgTerrain/DataSet.cpp @@ -51,10 +51,10 @@ enum CoordinateSystemType LOCAL }; -CoordinateSystemType getCoordinateSystemType(const osgTerrain::CoordinateSystem* lhs) +CoordinateSystemType getCoordinateSystemType(const osg::CoordinateSystemNode* lhs) { // set up LHS SpatialReference - char* projection_string = strdup(lhs->getWKT().c_str()); + char* projection_string = strdup(lhs->getCoordinateSystem().c_str()); char* importString = projection_string; OGRSpatialReference lhsSR; @@ -79,10 +79,10 @@ CoordinateSystemType getCoordinateSystemType(const osgTerrain::CoordinateSystem* return PROJECTED; } -double getAngularUnits(const osgTerrain::CoordinateSystem* lhs) +double getAngularUnits(const osg::CoordinateSystemNode* lhs) { // set up LHS SpatialReference - char* projection_string = strdup(lhs->getWKT().c_str()); + char* projection_string = strdup(lhs->getCoordinateSystem().c_str()); char* importString = projection_string; OGRSpatialReference lhsSR; @@ -97,10 +97,10 @@ double getAngularUnits(const osgTerrain::CoordinateSystem* lhs) return result; } -double getLinearUnits(const osgTerrain::CoordinateSystem* lhs) +double getLinearUnits(const osg::CoordinateSystemNode* lhs) { // set up LHS SpatialReference - char* projection_string = strdup(lhs->getWKT().c_str()); + char* projection_string = strdup(lhs->getCoordinateSystem().c_str()); char* importString = projection_string; OGRSpatialReference lhsSR; @@ -119,7 +119,7 @@ double getLinearUnits(const osgTerrain::CoordinateSystem* lhs) return result; } -bool areCoordinateSystemEquivilant(const osgTerrain::CoordinateSystem* lhs,const osgTerrain::CoordinateSystem* rhs) +bool areCoordinateSystemEquivilant(const osg::CoordinateSystemNode* lhs,const osg::CoordinateSystemNode* rhs) { // if ptr's equal the return true if (lhs == rhs) return true; @@ -132,10 +132,10 @@ bool areCoordinateSystemEquivilant(const osgTerrain::CoordinateSystem* lhs,const } // use compare on ProjectionRef strings. - if (*lhs == *rhs) return true; + if (lhs->getCoordinateSystem() == rhs->getCoordinateSystem()) return true; // set up LHS SpatialReference - char* projection_string = strdup(lhs->getWKT().c_str()); + char* projection_string = strdup(lhs->getCoordinateSystem().c_str()); char* importString = projection_string; OGRSpatialReference lhsSR; @@ -144,7 +144,7 @@ bool areCoordinateSystemEquivilant(const osgTerrain::CoordinateSystem* lhs,const free(projection_string); // set up RHS SpatialReference - projection_string = strdup(rhs->getWKT().c_str()); + projection_string = strdup(rhs->getCoordinateSystem().c_str()); importString = projection_string; OGRSpatialReference rhsSR; @@ -158,8 +158,8 @@ bool areCoordinateSystemEquivilant(const osgTerrain::CoordinateSystem* lhs,const int result2 = lhsSR.IsSameGeogCS(&rhsSR); std::cout<<"areCoordinateSystemEquivilant "<getWKT()<getCoordinateSystem()<getEllipsodeTransform(); - bool mapLatLongsToXYZ = _dataSet->getConvertFromGeographicToGeocentric(); + const osg::EllipsoidModel* et = _dataSet->getEllipsoidModel(); + bool mapLatLongsToXYZ = _dataSet->getConvertFromGeographicToGeocentric() && et; bool useLocalToTileTransform = _dataSet->getUseLocalTileTransform(); + osg::Vec3 center_position(0.0f,0.0f,0.0f); + osg::Vec3 center_normal(0.0f,0.0f,1.0f); + osg::Vec3 transformed_center_normal(0.0f,0.0f,1.0f); + if (useLocalToTileTransform) { if (mapLatLongsToXYZ) @@ -1980,20 +1991,30 @@ osg::Node* DataSet::DestinationTile::createPolygonal() double midLong = grid->getOrigin().x()+grid->getXInterval()*((double)(numColumns-1))*0.5; double midLat = grid->getOrigin().y()+grid->getYInterval()*((double)(numRows-1))*0.5; double midZ = grid->getOrigin().z(); - et.computeLocalToWorldTransform(osg::DegreesToRadians(midLat),osg::DegreesToRadians(midLong),midZ,localToWorld); + et->computeLocalToWorldTransformFromLatLongHeight(osg::DegreesToRadians(midLat),osg::DegreesToRadians(midLong),midZ,localToWorld); double minLong = grid->getOrigin().x(); double minLat = grid->getOrigin().y(); double minX,minY,minZ; - et.convertLatLongHeightToXYZ(osg::DegreesToRadians(minLat),osg::DegreesToRadians(minLong),midZ,minX,minY,minZ); + et->convertLatLongHeightToXYZ(osg::DegreesToRadians(minLat),osg::DegreesToRadians(minLong),midZ,minX,minY,minZ); double midX,midY; - et.convertLatLongHeightToXYZ(osg::DegreesToRadians(midLat),osg::DegreesToRadians(midLong),midZ,midX,midY,midZ); + et->convertLatLongHeightToXYZ(osg::DegreesToRadians(midLat),osg::DegreesToRadians(midLong),midZ,midX,midY,midZ); double length = sqrt((midX-minX)*(midX-minX) + (midY-minY)*(midY-minY)); skirtVector.set(0.0f,0.0f,-length*skirtRatio); + + center_normal.set(midX,midY,midZ); + center_normal.normalize(); + + worldToLocal.invert(localToWorld); + + //center_position = computeLocalPosition(localToWorld,midX,midY,midZ); + center_position = computeLocalPosition2(worldToLocal,midX,midY,midZ); + transformed_center_normal = osg::Matrixd::transform3x3(localToWorld,center_normal); + } else { @@ -2001,8 +2022,11 @@ osg::Node* DataSet::DestinationTile::createPolygonal() double midY = grid->getOrigin().y()+grid->getYInterval()*((double)(numRows-1))*0.5; double midZ = grid->getOrigin().z(); localToWorld.makeTranslate(midX,midY,midZ); + worldToLocal.invert(localToWorld); + skirtVector.set(0.0f,0.0f,-_extents.radius()*skirtRatio); - } + } + } else if (mapLatLongsToXYZ) { @@ -2012,8 +2036,8 @@ osg::Node* DataSet::DestinationTile::createPolygonal() double midLat = grid->getOrigin().y()+grid->getYInterval()*((double)(numRows-1))*0.5; double midZ = grid->getOrigin().z(); double X,Y,Z; - et.convertLatLongHeightToXYZ(osg::DegreesToRadians(midLat),osg::DegreesToRadians(midLong),midZ,X,Y,Z); - osg::Vec3 gravitationVector = et.computeGavitationVector(X,Y,Z); + et->convertLatLongHeightToXYZ(osg::DegreesToRadians(midLat),osg::DegreesToRadians(midLong),midZ,X,Y,Z); + osg::Vec3 gravitationVector = et->computeLocalUpVector(X,Y,Z); gravitationVector.normalize(); skirtVector = gravitationVector * _extents.radius()* skirtRatio; } @@ -2033,6 +2057,9 @@ osg::Node* DataSet::DestinationTile::createPolygonal() double delta_Y = grid->getYInterval(); double orig_Z = grid->getOrigin().z(); + + float min_dot_product = 1.0f; + for(r=0;rconvertLatLongHeightToXYZ(osg::DegreesToRadians(Y),osg::DegreesToRadians(X),Z, X,Y,Z); } -#if 1 + + // upadate the cluster culling data. + osg::Vec3 local_normal(X,Y,Z); + local_normal.normalize(); + float local_dot_product = center_normal * local_normal; + min_dot_product = osg::minimum(min_dot_product, local_dot_product); + if (useLocalToTileTransform) { - v[vi] = computeLocalPosition(localToWorld,X,Y,Z); + //v[vi] = computeLocalPosition(localToWorld,X,Y,Z); + v[vi] = computeLocalPosition2(worldToLocal,X,Y,Z); } else -#endif { v[vi].set(X,Y,Z); } @@ -2064,9 +2097,12 @@ osg::Node* DataSet::DestinationTile::createPolygonal() t[vi].y() = (r==numRows-1)? 1.0f : (float)(r)/(float)(numRows-1); ++vi; + } } + + //geometry->setUseDisplayList(false); geometry->setVertexArray(&v); @@ -2128,6 +2164,28 @@ osg::Node* DataSet::DestinationTile::createPolygonal() if (n.valid() && n->size()!=numVertices) n->resize(numVertices); #endif + + bool useClusterCullingCallback = mapLatLongsToXYZ; + if (useClusterCullingCallback) + { + // set up cluster cullling, + osg::ClusterCullingCallback* ccc = new osg::ClusterCullingCallback; + + float angle = acosf(min_dot_product)+osg::PI*0.5f; + float deviation = (anglegetControlPoint()==\t"<getControlPoint()<<"\t"<getNormal()<<"\t"<getDeviation()<computeFrom(geometry); + std::cout<<"computeFrom ccc->getControlPoint()==\t"<getControlPoint()<<"\t"<getNormal()<<"\t"<getDeviation()<0) @@ -2236,9 +2294,11 @@ osg::Node* DataSet::DestinationTile::createPolygonal() simplifier.simplify(*geometry, pointsToProtectDuringSimplification); // this will replace the normal vector with a new one + osgUtil::TriStripVisitor tsv; tsv.stripify(*geometry); + osg::Geode* geode = new osg::Geode; geode->addDrawable(geometry); @@ -2682,6 +2742,8 @@ DataSet::DataSet() _geometryType = POLYGONAL; _textureType = COMPRESSED_TEXTURE; _useLocalTileTransform = true; + + setEllipsoidModel(new osg::EllipsoidModel()); } void DataSet::init() @@ -2721,7 +2783,7 @@ void DataSet::loadSources() } DataSet::CompositeDestination* DataSet::createDestinationGraph(CompositeDestination* parent, - osgTerrain::CoordinateSystem* cs, + osg::CoordinateSystemNode* cs, const osg::BoundingBox& extents, unsigned int maxImageSize, unsigned int maxTerrainSize, @@ -2973,7 +3035,7 @@ void DataSet::computeDestinationGraphFromSources(unsigned int numLevels) if (sd->_cs.valid()) { _destinationCoordinateSystem = sd->_cs; - std::cout<<"Setting coordinate system to "<<_destinationCoordinateSystem->getWKT()<getCoordinateSystem()<