osgEarth 2.1.1
Public Member Functions | Public Attributes | Protected Member Functions | Private Types | Private Member Functions | Private Attributes

AMRGeometry Class Reference

List of all members.

Public Member Functions

 AMRGeometry ()
 AMRGeometry (const AMRGeometry &rhs, const osg::CopyOp &op=osg::CopyOp::DEEP_COPY_ALL)
 META_Object (osgEarth, AMRGeometry)
virtual osg::BoundingBox computeBound () const
void clearDrawList ()
void setDrawList (const AMRDrawableList &drawList)

Public Attributes

osg::ref_ptr< osg::Program > _program

Protected Member Functions

virtual void drawImplementation (osg::RenderInfo &renderInfo) const

Private Types

typedef std::vector
< osg::ref_ptr
< osg::DrawElements > > 
Pattern

Private Member Functions

void initShaders ()
void initPatterns ()

Private Attributes

AMRDrawableList _drawList
Pattern _pattern
int _numPatternVerts
int _numPatternElements
int _numPatternStrips
int _numPatternTriangles
osg::ref_ptr< osg::Vec3Array > _verts
osg::ref_ptr< osg::Vec2Array > _texCoords
osg::ref_ptr
< osg::VertexBufferObject > 
_patternVBO
osg::ref_ptr
< osg::ElementBufferObject > 
_patternEBO

Detailed Description

Adaptive Mesh Refining Geometry.

This class extends OSG's geometry object to perform adaptive mesh refinement using a virtual vertex manifold and a globally shared VBO that contains the refinement patches.

Definition at line 78 of file AMRGeometry.


Member Typedef Documentation

typedef std::vector< osg::ref_ptr<osg::DrawElements> > AMRGeometry::Pattern [private]

Definition at line 104 of file AMRGeometry.


Constructor & Destructor Documentation

AMRGeometry::AMRGeometry ( )

Definition at line 92 of file AMRGeometry.cpp.

{
    initShaders();
    initPatterns();

    //this->setBound( osg::BoundingBox(-1e10, -1e10, -1e10, 1e10, 1e10, 1e10) );
}

Here is the call graph for this function:

AMRGeometry::AMRGeometry ( const AMRGeometry rhs,
const osg::CopyOp &  op = osg::CopyOp::DEEP_COPY_ALL 
)

Definition at line 100 of file AMRGeometry.cpp.

                                                                      :
osg::Drawable( rhs, op ) //osg::Geometry( rhs, op )
{
    //todo
    setInitialBound( osg::BoundingBox(-1e10, -1e10, -1e10, 1e10, 1e10, 1e10) );
}

Member Function Documentation

void AMRGeometry::clearDrawList ( )

Empties the draw list of manifold triangles.

Definition at line 123 of file AMRGeometry.cpp.

{
    if ( _drawList.size() > 0 )
    {
        _drawList.clear();
        dirtyBound();
    }
}
osg::BoundingBox AMRGeometry::computeBound ( ) const [virtual]

Definition at line 108 of file AMRGeometry.cpp.

{
    osg::BoundingBox box;
    for( AMRDrawableList::const_iterator i = _drawList.begin(); i != _drawList.end(); ++i )
    {
        const AMRTriangleList& prims = i->get()->_triangles;
        for( AMRTriangleList::const_iterator j = prims.begin(); j != prims.end(); ++j )
        {
            j->get()->expand( box );
        }
    } 
    return box;
}
void AMRGeometry::drawImplementation ( osg::RenderInfo &  renderInfo) const [protected, virtual]

renders the draw list.

Definition at line 277 of file AMRGeometry.cpp.

{   
    osg::State& state = *renderInfo.getState();
    
    // bind the VBO:
    state.setVertexPointer( _verts.get() );

    // bind the texture coordinate arrrays:
    state.setTexCoordPointer( 0, _texCoords.get() );

    // this will enable the amr geometry's stateset (and activate the Program)
    state.pushStateSet( this->getStateSet() );
    //state.pushStateSet(0L);
    //_program->apply( state );

    int numTemplates = 0;

    for( AMRDrawableList::const_iterator i = _drawList.begin(); i != _drawList.end(); ++i )
    {
        const AMRDrawable* drawable = i->get();

        // apply the drawable's state changes:
        state.pushStateSet( drawable->_stateSet.get() );

        for( AMRTriangleList::const_iterator j = drawable->_triangles.begin(); j != drawable->_triangles.end(); ++j )
        {
            const AMRTriangle* dtemplate = j->get();

            // apply the primitive's state changes:
            state.apply( dtemplate->_stateSet.get() );

            // render the pattern (a collection of primitive sets)
            for( Pattern::const_iterator p = _pattern.begin(); p != _pattern.end(); ++p )
            {
                p->get()->draw( state, true );
            }

            numTemplates++;
        }

        state.popStateSet();
    }

    if ( s_numTemplates != numTemplates )
    {
        s_numTemplates = numTemplates;
        OE_INFO << LC << std::dec 
            << "templates="  << numTemplates
            << ", verts="    << numTemplates*_numPatternVerts
            << ", strips="   << numTemplates*_numPatternStrips
            << ", tris="     << numTemplates*_numPatternTriangles
            << ", elements=" << numTemplates*_numPatternElements
            << std::endl;
    }

    // unbind the buffer objects.
    state.unbindVertexBufferObject();
    state.unbindElementBufferObject();

    // undo the program.
    state.popStateSet();
}
void AMRGeometry::initPatterns ( ) [private]

Definition at line 202 of file AMRGeometry.cpp.

{
    _numPatternVerts = 0;
    _numPatternElements = 0;
    _numPatternStrips = 0;
    _numPatternTriangles = 0;

    this->setUseVertexBufferObjects( true );
    this->setUseDisplayList( false );

    _patternVBO = new osg::VertexBufferObject();

    _verts = new osg::Vec3Array();
    _verts->setVertexBufferObject( _patternVBO.get() );

    _texCoords = new osg::Vec2Array();
    _texCoords->setVertexBufferObject( _patternVBO.get() );
 
    // build a right-triangle pattern. (0,0) is the lower-left (90d),
    // (0,1) is the lower right (45d) and (1,0) is the upper-left (45d)
    osg::Vec3f p1(0,0,0), p2(0,1,0), p3(1,0,0);

    for( int r=AMR_PATCH_ROWS-1; r >=0; --r )
    {
        int cols = AMR_PATCH_ROWS-r;
        //OE_INFO << "ROW " << r << std::endl;
        for( int c=0; c<cols; ++c )
        {
            osg::Vec3 point( (float)c/(float)(AMR_PATCH_ROWS-1), (float)r/(float)(AMR_PATCH_ROWS-1), 0 );
            osg::Vec3 baryVert;
            osg::Vec2 baryTex;
            toBarycentric( p1, p2, p3, point, baryVert, baryTex );
            _verts->push_back( baryVert );
            _texCoords->push_back( baryTex );
        }
    }
    _numPatternVerts = _verts->size();

    unsigned short off = 0;
    unsigned short rowptr = off;

    _patternEBO = new osg::ElementBufferObject();

    for( int r=1; r<AMR_PATCH_ROWS; ++r )
    {
        rowptr += r;
        osg::DrawElementsUShort* e = new osg::DrawElementsUShort( GL_TRIANGLE_STRIP );
        e->setElementBufferObject( _patternEBO.get() );            

        for( int c=0; c<=r; ++c )
        {
            e->push_back( rowptr + c );               
            if ( c < r )
                e->push_back( rowptr + c - r );
        }
        OE_INFO << std::endl;
        _pattern.push_back( e );

        _numPatternStrips++;
        _numPatternElements += e->size();
        _numPatternTriangles += (e->size()-1)/2;     
    }

    OE_INFO << LC
        << "Pattern: "   << std::dec
        << "verts="      << _numPatternVerts
        << ", strips="   << _numPatternStrips
        << ", tris="     << _numPatternTriangles
        << ", elements=" << _numPatternElements
        << std::endl;
}

Here is the call graph for this function:

Here is the caller graph for this function:

void AMRGeometry::initShaders ( ) [private]

Definition at line 140 of file AMRGeometry.cpp.

{
    // initialize the shader program.
    _program = new osg::Program();
    _program->setName( "AMRGeometry" );

    osg::Shader* vertexShader = new osg::Shader( osg::Shader::VERTEX,
        //std::string( source_vertShaderMain_flatMethod )
        std::string( source_vertShaderMain_geocentricMethod ) +
        std::string( source_geodeticToXYZ ) +
        std::string( source_rotVecToGeodetic )
        //std::string( source_vertShaderMain_latLonMethod )
        //std::string( source_vertShaderMain_slerpMethod )
        );

    vertexShader->setName( "AMR Vert Shader" );
    _program->addShader( vertexShader );

    osg::Shader* fragmentShader = new osg::Shader( osg::Shader::FRAGMENT,
        std::string( source_fragShaderMain )
        );

    fragmentShader->setName( "AMR Frag Shader" );
    _program->addShader( fragmentShader );

    // the shader program:
    this->getOrCreateStateSet()->setAttribute( _program.get(), osg::StateAttribute::ON );
}

Here is the caller graph for this function:

AMRGeometry::META_Object ( osgEarth  ,
AMRGeometry   
)
void AMRGeometry::setDrawList ( const AMRDrawableList drawList)

Sets an entire new triangle list.

Definition at line 133 of file AMRGeometry.cpp.

{
    _drawList = drawList;
    dirtyBound();
}

Member Data Documentation

Definition at line 100 of file AMRGeometry.

Definition at line 107 of file AMRGeometry.

Definition at line 108 of file AMRGeometry.

Definition at line 109 of file AMRGeometry.

Definition at line 106 of file AMRGeometry.

Definition at line 105 of file AMRGeometry.

osg::ref_ptr<osg::ElementBufferObject> AMRGeometry::_patternEBO [private]

Definition at line 114 of file AMRGeometry.

osg::ref_ptr<osg::VertexBufferObject> AMRGeometry::_patternVBO [private]

Definition at line 113 of file AMRGeometry.

osg::ref_ptr<osg::Program> AMRGeometry::_program

Definition at line 118 of file AMRGeometry.

osg::ref_ptr<osg::Vec2Array> AMRGeometry::_texCoords [private]

Definition at line 112 of file AMRGeometry.

osg::ref_ptr<osg::Vec3Array> AMRGeometry::_verts [private]

Definition at line 111 of file AMRGeometry.


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