osgEarth 2.1.1
Public Member Functions | Protected Member Functions | Protected Attributes | Friends

seamless::PatchSet Class Reference

Inheritance diagram for seamless::PatchSet:
Collaboration diagram for seamless::PatchSet:

List of all members.

Public Member Functions

 PatchSet ()
 PatchSet (const osgEarth::Drivers::SeamlessOptions &options, PatchOptions *poptionsPrototype=0)
 PatchSet (const PatchSet &rhs, const osg::CopyOp &copyop=osg::CopyOp::SHALLOW_COPY)
 META_Object (seamless, PatchSet)
int getResolution () const
void setPrecisionFactor (double factor)
double getPrecisionFactor () const
double calcPrecisionFactor (int pixelError, double horiz_fov_deg=60.0, int screenRes=1280, int dpi=90)
void setPrecisionFactor (int pixelError, double horiz_fov_deg=60.0, int screenRes=1280, int dpi=90)
void setPatchOptionsPrototype (PatchOptions *proto)
PatchOptionsgetPatchOptionsPrototype () const
void setMaxLevel (int maxLevel)
int getMaxLevel () const
void setVerticalScale (float scale)
float getVerticalScale () const
void setMap (const osgEarth::Map *map)
const osgEarth::MapgetMap () const
osgEarth::MapFramegetMapFrame () const
virtual osg::Node * createPatchGroup (const std::string &filename, PatchOptions *poptions)
virtual osg::Transform * createPatch (const std::string &filename, PatchOptions *poptions)
virtual osg::Node * createPatchSetGraph (const std::string &filename)
virtual osg::Node * createChild (const PatchOptions *parentOptions, int childNum)
unsigned short makeIndex (int x, int y)
unsigned short rotateIndex (unsigned short index)

Protected Member Functions

virtual ~PatchSet ()
void initPrimitiveSets ()
osg::ref_ptr
< osg::DrawElementsUShort > 
makeBasicTrile (int delta)
osg::ref_ptr
< osg::DrawElementsUShort > 
makeSingleStrip (int delta)
osg::ref_ptr
< osg::DrawElementsUShort > 
makeDualStrip ()

Protected Attributes

double _precisionFactor
int _resolution
int _maxLevel
float _verticalScale
osg::ref_ptr< PatchOptions_patchOptionsPrototype
osg::ref_ptr
< osg::DrawElementsUShort > 
trilePset [2][4]
osg::ref_ptr
< osg::DrawElementsUShort > 
stripPset [4][4]
osg::ref_ptr< const osgEarth::Map_map
osgEarth::MapFrame_mapf
osgEarth::Drivers::SeamlessOptions _options

Friends

class Patch

Detailed Description

Definition at line 38 of file PatchSet.


Constructor & Destructor Documentation

seamless::PatchSet::PatchSet ( )

Definition at line 34 of file PatchSet.cpp.

Here is the call graph for this function:

seamless::PatchSet::PatchSet ( const osgEarth::Drivers::SeamlessOptions options,
PatchOptions poptionsPrototype = 0 
)

Definition at line 43 of file PatchSet.cpp.

    :  _maxLevel(16),
       _patchOptionsPrototype(poptionsPrototype ? poptionsPrototype
                              : new PatchOptions),
       _mapf(0), _options(options)
{
    _resolution = options.resolution().value();
    _verticalScale = options.verticalScale().value();
    setPrecisionFactor(4);
    initPrimitiveSets();
}

Here is the call graph for this function:

seamless::PatchSet::PatchSet ( const PatchSet rhs,
const osg::CopyOp &  copyop = osg::CopyOp::SHALLOW_COPY 
)
seamless::PatchSet::~PatchSet ( ) [protected, virtual]

Definition at line 76 of file PatchSet.cpp.

{
    delete _mapf;
}

Member Function Documentation

double seamless::PatchSet::calcPrecisionFactor ( int  pixelError,
double  horiz_fov_deg = 60.0,
int  screenRes = 1280,
int  dpi = 90 
)

Definition at line 155 of file PatchSet.cpp.

{
    // Find near plane distance in meters
    const double pixelsPerMeter = dpi / .0254;
    const double halfScreen = .5 * screenRes / pixelsPerMeter;
    const double dNear = halfScreen / tan(DegreesToRadians(horiz_fov_deg / 2));
    return dNear * pixelsPerMeter / (pixelError * _resolution);
}

Here is the caller graph for this function:

osg::Node * seamless::PatchSet::createChild ( const PatchOptions parentOptions,
int  childNum 
) [virtual]

Reimplemented in seamless::Geographic.

Definition at line 328 of file PatchSet.cpp.

{
    Vec2d lowerLeft(0.0, 1.0);
    Vec2d upperRight(1.0, 1.0);

    parentOptions->getPatchExtents(lowerLeft, upperRight);
    Vec2d range = upperRight - lowerLeft;
    Vec2d newRange = range * .5;
    double x = (childNum % 2) * .5;
    double y = (childNum / 2) * .5;
    PatchOptions* pgroupOptions = osg::clone(parentOptions);
    Vec2d ll = lowerLeft + componentMultiply(Vec2d(x, y), range);
    pgroupOptions->setPatchExtents(ll, ll + newRange);
    pgroupOptions->setPatchLevel(parentOptions->getPatchLevel() + 1);
    Node* pgroup = createPatchGroup("foobies.osgearth_engine_seamless_patch",
                                    pgroupOptions);
    return pgroup;
}

Here is the call graph for this function:

Here is the caller graph for this function:

Transform * seamless::PatchSet::createPatch ( const std::string &  filename,
PatchOptions poptions 
) [virtual]

Reimplemented in seamless::Geographic, and seamless::Projected.

Definition at line 114 of file PatchSet.cpp.

{
    Patch* patch = new Patch;
    patch->setPatchSet(this);
    Vec2d ll, ur;
    poptions->getPatchExtents(ll, ur);
    Vec2d range = (ur - ll);
    ref_ptr<Patch::Data> data = new Patch::Data;
    int patchDim = _resolution + 1;
    Vec3Array* verts = new Vec3Array(patchDim * patchDim);
    for (int j = 0; j < patchDim; ++j)
        for (int i = 0; i < patchDim; ++i)
            (*verts)[patchDim * j + i]
                = Vec3((ll.x() + i * range.x()
                        / static_cast<float>(_resolution)) * 81920.0,
                       (ll.y() + j * range.y()
                        / static_cast<float>(_resolution)) * 81920.0,
                       0.0);
    data->vertexData.array = verts;
    data->vertexData.binding = Geometry::BIND_PER_VERTEX;
    Vec3Array* norms = new Vec3Array(1);
    (*norms)[0] = Vec3d(0.0, 0.0, 1.0);
    data->normalData.array = norms;
    data->normalData.binding = Geometry::BIND_OVERALL;
    Vec4Array* colors = new Vec4Array(1);
    (*colors)[0] = Vec4(1.0, 1.0, 1.0, 1.0);
    data->colorData.array = colors;
    data->colorData.binding = Geometry::BIND_OVERALL;
    patch->setData(data);
    MatrixTransform* transform = new MatrixTransform;
    transform->addChild(patch);
    return transform;
}

Here is the call graph for this function:

Node * seamless::PatchSet::createPatchGroup ( const std::string &  filename,
PatchOptions poptions 
) [virtual]

Reimplemented in seamless::Geographic.

Definition at line 532 of file Geographic.cpp.

{

Here is the caller graph for this function:

Node * seamless::PatchSet::createPatchSetGraph ( const std::string &  filename) [virtual]

Reimplemented in seamless::Geographic.

Definition at line 148 of file PatchSet.cpp.

{
    PatchOptions* poptions = osg::clone(_patchOptionsPrototype.get());
    poptions->setPatchSet(this);
    return createPatchGroup(filename, poptions);
}

Here is the call graph for this function:

const osgEarth::Map* seamless::PatchSet::getMap ( ) const [inline]

Definition at line 71 of file PatchSet.

{ return _map.get(); }

Here is the caller graph for this function:

osgEarth::MapFrame& seamless::PatchSet::getMapFrame ( ) const [inline]

Definition at line 72 of file PatchSet.

{ return *_mapf; }
int seamless::PatchSet::getMaxLevel ( ) const [inline]

Definition at line 67 of file PatchSet.

{ return _maxLevel; }
PatchOptions* seamless::PatchSet::getPatchOptionsPrototype ( ) const [inline]

Definition at line 62 of file PatchSet.

double seamless::PatchSet::getPrecisionFactor ( ) const [inline]

Definition at line 49 of file PatchSet.

{ return _precisionFactor; }
int seamless::PatchSet::getResolution ( ) const [inline]

Definition at line 47 of file PatchSet.

{ return _resolution; }

Here is the caller graph for this function:

float seamless::PatchSet::getVerticalScale ( ) const [inline]

Definition at line 69 of file PatchSet.

{ return _verticalScale; }

Here is the caller graph for this function:

void seamless::PatchSet::initPrimitiveSets ( ) [protected]

Definition at line 273 of file PatchSet.cpp.

{
    for (int res = 0; res < 2; res++)
    {
        // Bottom trile
        trilePset[res][0] = makeBasicTrile(2 - res);
        // The other triles are rotations of the first on the grid of
        // coordinate indices.
        for (int i = 1; i < 4; ++i)
        {
            trilePset[res][i] = new DrawElementsUShort(GL_TRIANGLES);
            for (DrawElementsUShort::iterator itr = trilePset[res][i - 1]->begin(),
                     end = trilePset[res][i - 1]->end();
                 itr != end;
                ++itr)
                trilePset[res][i]->push_back(rotateIndex(*itr));
        }
    }
    // First, the strips for the edge from lower left to middle
    stripPset[0][0] = makeSingleStrip(2); // low res
    stripPset[1][0] = makeDualStrip();
    // The other dual strip is the reflection across y = x
    stripPset[2][0] = new DrawElementsUShort(GL_TRIANGLES);
    for (DrawElementsUShort::iterator itr = stripPset[1][0]->begin(),
             end = stripPset[1][0]->end();
         itr != end;
        ++itr)
    {
        int x, y;
        getGridCoords(_resolution, *itr, x, y);
        stripPset[2][0]->push_back(makeIndex(y, x));
    }
    // Now switch the order on the triangles on the reflected strip
    for (size_t i = 1; i < stripPset[2][0]->size(); i += 3)
    {
        std::swap((*stripPset[2][0].get())[i],
                  (*stripPset[2][0].get())[i + 1]);
    }

    stripPset[3][0] = makeSingleStrip(1); // hi res
    // Now rotate the strips for the other diagonals.
    for (int j = 1; j < 4; ++j)
    {
        for (int i = 0; i < 4; ++i)
        {
            stripPset[i][j] = new DrawElementsUShort(GL_TRIANGLES);
            for (DrawElementsUShort::iterator itr = stripPset[i][j - 1]->begin(),
                     end = stripPset[i][j - 1]->end();
                 itr != end;
                ++itr)
                stripPset[i][j]->push_back(rotateIndex(*itr));
        }
    }
}

Here is the call graph for this function:

Here is the caller graph for this function:

ref_ptr< DrawElementsUShort > seamless::PatchSet::makeBasicTrile ( int  delta) [protected]

Definition at line 174 of file PatchSet.cpp.

{
    ref_ptr<DrawElementsUShort> pset = new DrawElementsUShort(GL_TRIANGLES);
    // y axis
    int xBegin = delta;
    int xEnd = _resolution - delta;
    for (int j = 0; j < _resolution / 2 - delta; j += delta)
    {
        for (int i = xBegin; i < xEnd; i += 2 * delta)
        {
            pset->push_back(makeIndex(i, j));
            pset->push_back(makeIndex(i + delta, j));
            pset->push_back(makeIndex(i + delta, j + delta));
            pset->push_back(makeIndex(i + delta, j + delta));
            pset->push_back(makeIndex(i + delta, j));
            pset->push_back(makeIndex(i + 2 * delta, j));
            if (i + 2 * delta == xEnd)
                break;
            pset->push_back(makeIndex(i + delta, j + delta));
            pset->push_back(makeIndex(i + 2 * delta, j));
            pset->push_back(makeIndex(i + 2 * delta, j + delta));
            pset->push_back(makeIndex(i + 2 * delta, j + delta));
            pset->push_back(makeIndex(i + 2 * delta, j));
            pset->push_back(makeIndex(i + 3 * delta, j + delta));
        }
        xBegin += delta;
        xEnd -= delta;
    }
    return pset;
}

Here is the call graph for this function:

Here is the caller graph for this function:

ref_ptr< DrawElementsUShort > seamless::PatchSet::makeDualStrip ( ) [protected]

Definition at line 251 of file PatchSet.cpp.

{
    ref_ptr<DrawElementsUShort> pset = new DrawElementsUShort(GL_TRIANGLES);
    for (int i = 0, j = 2; j <= _resolution / 2; i += 2, j += 2)
    {
        pset->push_back(makeIndex(i, j));
        if (i == 0)
            pset->push_back(makeIndex(0, 0));
        else
            pset->push_back(makeIndex(i - 2, j -2));
        pset->push_back(makeIndex(i + 1, j - 2));
        pset->push_back(makeIndex(i, j));
        pset->push_back(makeIndex(i + 1, j - 2));
        pset->push_back(makeIndex(i + 2, j - 1));

        pset->push_back(makeIndex(i, j));
        pset->push_back(makeIndex(i + 2, j - 1));
        pset->push_back(makeIndex(i + 3, j));
    }
    return pset;
}

Here is the call graph for this function:

Here is the caller graph for this function:

unsigned short seamless::PatchSet::makeIndex ( int  x,
int  y 
) [inline]

Get the index (into attribute array) for vertex.

Parameters:
xx grid coordinate
yy grid coordinate

Definition at line 84 of file PatchSet.

    {
        return static_cast<unsigned short>(y * (_resolution + 1) + x);
    }

Here is the caller graph for this function:

ref_ptr< DrawElementsUShort > seamless::PatchSet::makeSingleStrip ( int  delta) [protected]

Definition at line 222 of file PatchSet.cpp.

{
    ref_ptr<DrawElementsUShort> pset = new DrawElementsUShort(GL_TRIANGLES);
    for (int i = 0; i < _resolution / 2; i += delta)
    {
        if (i > 0)
        {
            pset->push_back(makeIndex(i - delta, i));
            pset->push_back(makeIndex(i, i));
            pset->push_back(makeIndex(i, i + delta));
        }
        pset->push_back(makeIndex(i, i));
        pset->push_back(makeIndex(i + delta, i + delta));
        pset->push_back(makeIndex(i, i + delta));
        pset->push_back(makeIndex(i, i));
        pset->push_back(makeIndex(i + delta, i));
        pset->push_back(makeIndex(i + delta, i + delta));
        if (i < _resolution / 2 - delta)
        {
            pset->push_back(makeIndex(i + delta, i + delta));
            pset->push_back(makeIndex(i + delta, i));
            pset->push_back(makeIndex(i + 2 * delta, i + delta));
        }
    }
    return pset;
}

Here is the call graph for this function:

Here is the caller graph for this function:

seamless::PatchSet::META_Object ( seamless  ,
PatchSet   
)

Reimplemented in seamless::Geographic.

unsigned short seamless::PatchSet::rotateIndex ( unsigned short  index)

Rotate grid indices 90 deg counter-clockwise.

Definition at line 206 of file PatchSet.cpp.

{
    int x, y;
    int psRes = _resolution;
    getGridCoords(psRes, index, x, y);
    x -= psRes / 2;
    y -= psRes / 2;
    int newx = -y;
    int newy = x;
    newx += psRes / 2;
    newy += psRes / 2;
    return makeIndex(newx, newy);
}

Here is the call graph for this function:

Here is the caller graph for this function:

void seamless::PatchSet::setMap ( const osgEarth::Map map)

Definition at line 81 of file PatchSet.cpp.

{
    _map = map;
    if (map)
    {
        delete _mapf;
        _mapf = new MapFrame(map, Map::TERRAIN_LAYERS, "seamless");
    }
}

Here is the caller graph for this function:

void seamless::PatchSet::setMaxLevel ( int  maxLevel) [inline]

Definition at line 66 of file PatchSet.

{ _maxLevel = maxLevel; }

Here is the caller graph for this function:

void seamless::PatchSet::setPatchOptionsPrototype ( PatchOptions proto) [inline]

Definition at line 58 of file PatchSet.

    {
        _patchOptionsPrototype = proto;
    }
void seamless::PatchSet::setPrecisionFactor ( int  pixelError,
double  horiz_fov_deg = 60.0,
int  screenRes = 1280,
int  dpi = 90 
) [inline]

Definition at line 52 of file PatchSet.

    {
        setPrecisionFactor(calcPrecisionFactor(pixelError, horiz_fov_deg,
                                               screenRes, dpi));
    }

Here is the call graph for this function:

void seamless::PatchSet::setPrecisionFactor ( double  factor) [inline]

Definition at line 48 of file PatchSet.

{ _precisionFactor = factor; }

Here is the caller graph for this function:

void seamless::PatchSet::setVerticalScale ( float  scale) [inline]

Definition at line 68 of file PatchSet.

{ _verticalScale = scale; }

Friends And Related Function Documentation

friend class Patch [friend]

Definition at line 79 of file PatchSet.


Member Data Documentation

osg::ref_ptr<const osgEarth::Map> seamless::PatchSet::_map [protected]

Definition at line 105 of file PatchSet.

Definition at line 106 of file PatchSet.

Definition at line 95 of file PatchSet.

Definition at line 107 of file PatchSet.

Definition at line 97 of file PatchSet.

Definition at line 93 of file PatchSet.

Definition at line 94 of file PatchSet.

Definition at line 96 of file PatchSet.

osg::ref_ptr<osg::DrawElementsUShort> seamless::PatchSet::stripPset[4][4] [protected]

Definition at line 104 of file PatchSet.

osg::ref_ptr<osg::DrawElementsUShort> seamless::PatchSet::trilePset[2][4] [protected]

Definition at line 103 of file PatchSet.


The documentation for this class was generated from the following files:
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines