osgEarth 2.1.1

/home/cube/sources/osgearth/src/osgEarthDrivers/engine_seamless/Patch

Go to the documentation of this file.
00001 /* -*-c++-*- */
00002 /* osgEarth - Dynamic map generation toolkit for OpenSceneGraph
00003  * Copyright 2010 Pelican Ventures, Inc.
00004  * http://osgearth.org
00005  *
00006  * osgEarth is free software; you can redistribute it and/or modify
00007  * it under the terms of the GNU Lesser General Public License as published by
00008  * the Free Software Foundation; either version 2 of the License, or
00009  * (at your option) any later version.
00010  *
00011  * This program is distributed in the hope that it will be useful,
00012  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00013  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00014  * GNU Lesser General Public License for more details.
00015  *
00016  * You should have received a copy of the GNU Lesser General Public License
00017  * along with this program.  If not, see <http://www.gnu.org/licenses/>
00018  */
00019 
00020 #ifndef SEAMLESS_PATCH
00021 #define SEAMLESS_PATCH 1
00022 
00023 #include <osg/Geode>
00024 #include <osg/Geometry>
00025 #include <osg/Node>
00026 #include <osg/PrimitiveSet>
00027 
00028 namespace seamless
00029 {
00030 class PatchSet;
00031 
00032 class Patch : public osg::Node
00033 {
00034 public:
00035     Patch();
00036     Patch(const Patch& rhs,
00037           const osg::CopyOp& copyop = osg::CopyOp::SHALLOW_COPY);
00038 
00039     META_Node(seamless, Patch);
00040 
00041     virtual void traverse(osg::NodeVisitor& nv);
00042     virtual osg::BoundingSphere computeBound() const;
00043     virtual void resizeGLObjectBuffers(unsigned int maxSize);
00044     virtual void releaseGLObjects(osg::State* = 0) const;
00045 
00046     virtual void init();
00047 
00048     // Wrapper around all the data for a patch at the different
00049     // LODs. The Geometry objects associated with triles point to the
00050     // arrays stored here.
00051     struct Data : public osg::Object
00052     {
00053         Data();
00054         Data(const Data&,
00055              const osg::CopyOp& copyop = osg::CopyOp::SHALLOW_COPY);
00056         ~Data() {}
00057         META_Object(seamless, Patch::Data);
00058         void getGeometryAttributes(const osg::Geometry* geom);
00059         void setGeometryAttributes(osg::Geometry* geom);
00060         osg::Geometry::ArrayData vertexData;
00061         osg::Geometry::ArrayData normalData;
00062         osg::Geometry::ArrayData colorData;
00063         osg::Geometry::ArrayData secondaryColorData;
00064         osg::Geometry::ArrayData fogCoordData;
00065         osg::Geometry::ArrayDataList texCoordList;
00066         osg::Geometry::ArrayDataList vertexAttribList;
00067     };
00068 
00069     Data* getData() { return _data.get(); }
00070     const Data* getData() const { return _data.get(); }
00071     void setData(Data* data)
00072     {
00073         _data = data;
00074         init();
00075     }
00078     void dirtyVertexData();
00082     float getPatchError(const osg::Vec3& eye);
00083     virtual float getEdgeError(const osg::Vec3& eye, int edge);
00084     void setPatchSet(PatchSet* patchSet);
00085     PatchSet* getPatchSet() const;
00090     void setErrorThreshold(float threshold) { _errorThreshold = threshold; }
00091     float getErrorThreshold() const { return _errorThreshold; }
00092 protected:
00093     ~Patch();
00094     // Triles at two resolutions, counterclockwise from bottom. 0 is
00095     // low, 1 is high.
00096     osg::ref_ptr<osg::Geode> _trile[2][4];
00097     // connecting strips at each diagonal, counterclockwise from lower
00098     // left. There are 4 possibilities for each strip:
00099     // 0 both neighbors low
00100     // 1 clockwise neighbor low, counterclockwise neighbor high
00101     // 2 clockwise neighbor high, counterclockwise neighbor low
00102     // 3 both neighbors high
00103     osg::ref_ptr<osg::Geode> _strip[4][4];
00104     osg::ref_ptr<Data> _data;
00105     osg::ref_ptr<PatchSet> _patchSet;
00106     float _errorThreshold;
00107 };
00108 
00109 // Utilities useful in Patch subclasses
00110 // Find the point closest to P3 on the line segment from P1 to P2
00111 extern osg::Vec3 closestPointOnSegment(
00112     const osg::Vec3& p1, const osg::Vec3& p2, const osg::Vec3& p3);
00113 extern float distanceToSegment(
00114     const osg::Vec3& p1, const osg::Vec3& p2, const osg::Vec3& p3);
00115 }
00116 #endif
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines