Ejemplo n.º 1
0
GeometryTransitPtr createPathGeometry(const std::vector<Pnt3f>& Path)
{

    //*******************Create the Geometry for the box
    GeoUInt8PropertyRecPtr type = GeoUInt8Property::create();
    //Volume bound box
    type->push_back(GL_LINE_STRIP);

    GeoUInt32PropertyRefPtr lens = GeoUInt32Property::create();
    //Volume bound box
    lens->push_back(Path.size());

    Color3f CoolColor(0.0f,0.0f,1.0f),
            HotColor(1.0f,0.0f,0.0f);

    GeoUInt32PropertyRefPtr index = GeoUInt32Property::create();
    GeoPnt3fPropertyRefPtr points = GeoPnt3fProperty::create();
    GeoVec3fPropertyRefPtr colors = GeoVec3fProperty::create();

    //Volume bound box
    Color3f Color;
    Real32 t;
    for(UInt32 i(0) ; i<Path.size() ; ++i)
    {
        t = static_cast<Real32>(i)/static_cast<Real32>(Path.size());
        Color = (t*CoolColor) + ((1.0f-t)*HotColor);
        index->push_back(i);
        points->push_back(Path[i]);
        colors->push_back(Color);
    }

    GeometryRecPtr PathGeo = Geometry::create();
    PathGeo->setTypes     (type);
    PathGeo->setLengths   (lens);
    PathGeo->setIndices   (index);
    PathGeo->setPositions (points);
    PathGeo->setColors    (colors);

    //Create the material for the line
    LineChunkRecPtr DefaultLineChunk = LineChunk::create();
    DefaultLineChunk->setWidth(2.0f);

    MaterialChunkRecPtr DefaultMaterialChunk = MaterialChunk::create();
    DefaultMaterialChunk->setLit(false);

    ChunkMaterialRecPtr DefaultChunkMaterial = ChunkMaterial::create();
    DefaultChunkMaterial->addChunk(DefaultMaterialChunk);
    DefaultChunkMaterial->addChunk(DefaultLineChunk);

    PathGeo->setMaterial(DefaultChunkMaterial);

    return GeometryTransitPtr(PathGeo);
}
Ejemplo n.º 2
0
OSG_BEGIN_NAMESPACE

NodeTransitPtr OctreeVisualization::createOctreeVisualization(OctreePtr tree,
                                                              Int32 MaxDepth,
                                                              bool filledGeometry,
                                                              bool onlyLeaf)
{
    OTNodeGeometryCreateFunc GeoCreateFunc;
    OTNodeMaterialCreateFunc MatCreateFunc;    
    OTNodeIsVisibleFunc IsVisibleFunc;

    IsVisibleFunc = boost::bind(&OctreeVisualization::isNodeLeaf,_1, _2,
                                false);

    NodeRecPtr VisRootNode = makeCoredNode<Group>();

    if(filledGeometry)
    {
        NodeRecPtr BaseBox = makeBox(1.0f,1.0f,1.0f,
                                     1,   1,   1);

        GeoCreateFunc = boost::bind(&OctreeVisualization::createNodeDistanceLOD,_1, _2, _3, BaseBox.get(), 10.0f);

        BlendChunkRecPtr DefaultBlendChunk = BlendChunk::create();
        DefaultBlendChunk->setSrcFactor(GL_SRC_ALPHA);
        DefaultBlendChunk->setDestFactor(GL_ONE_MINUS_SRC_ALPHA);

        PolygonChunkRecPtr    DefaultPolygonChunk = PolygonChunk::create();
        DefaultPolygonChunk->setCullFace(GL_BACK);
        
        MatCreateFunc = boost::bind(&OctreeVisualization::createMatFilled,_1, _2,
                                    Color3f(0.0f,1.0f,0.0f),
                                    Color3f(1.0f,0.0f,0.0f),
                                    0.15f,
                                    DefaultBlendChunk.get(),
                                    DefaultPolygonChunk.get());

        createOctreeVisualizationRec(tree,
                                     tree->getRoot(),
                                     VisRootNode,
                                     osgMin<UInt32>(tree->getDepth(),MaxDepth),
                                     GeoCreateFunc,
                                     MatCreateFunc,
                                     IsVisibleFunc);
    }
    else
    {
        //*******************Create the Geometry for the box
        GeoUInt8PropertyRecPtr type = GeoUInt8Property::create();
        //Volume bound box
        type->push_back(GL_LINE_STRIP);
        type->push_back(GL_LINES);

        GeoUInt32PropertyRefPtr lens = GeoUInt32Property::create();
        //Volume bound box
        lens->push_back(10);
        lens->push_back(6);

        GeoUInt32PropertyRefPtr index = GeoUInt32Property::create();

        //Volume bound box
        index->push_back(0);
        index->push_back(1);
        index->push_back(3);
        index->push_back(2);
        index->push_back(0);
        index->push_back(4);
        index->push_back(5);
        index->push_back(7);
        index->push_back(6);
        index->push_back(4);

        index->push_back(1);
        index->push_back(5);
        index->push_back(2);
        index->push_back(6);
        index->push_back(3);
        index->push_back(7);

        GeoPnt3fPropertyRefPtr highlightPoints = GeoPnt3fProperty::create();
        //Volume bound box
        highlightPoints->push_back(Pnt3f(-1, -1, -1));
        highlightPoints->push_back(Pnt3f( 1, -1, -1));
        highlightPoints->push_back(Pnt3f(-1,  1, -1));
        highlightPoints->push_back(Pnt3f( 1,  1, -1));
        highlightPoints->push_back(Pnt3f(-1, -1,  1));
        highlightPoints->push_back(Pnt3f( 1, -1,  1));
        highlightPoints->push_back(Pnt3f(-1,  1,  1));
        highlightPoints->push_back(Pnt3f( 1,  1,  1));

        //Colors
        Color4f BoundBoxColor(1.0f,1.0f,1.0,1.00f);

        GeoVec4fPropertyRefPtr highlightColors = GeoVec4fProperty::create();
        //Volume bound box
        highlightColors->push_back(BoundBoxColor);
        highlightColors->push_back(BoundBoxColor);
        highlightColors->push_back(BoundBoxColor);
        highlightColors->push_back(BoundBoxColor);
        highlightColors->push_back(BoundBoxColor);
        highlightColors->push_back(BoundBoxColor);
        highlightColors->push_back(BoundBoxColor);
        highlightColors->push_back(BoundBoxColor);

        GeometryRecPtr BoxGeo =Geometry::create();
        BoxGeo->setTypes     (type);
        BoxGeo->setLengths   (lens);
        BoxGeo->setIndices   (index);
        BoxGeo->setPositions (highlightPoints);
        BoxGeo->setColors    (highlightColors);

        //Highlight Bound Box Node
        NodeRecPtr BaseBox = makeNodeFor(BoxGeo);
        GeoCreateFunc =
            boost::bind(&OctreeVisualization::createNodeDistanceLOD,_1, _2, _3,
                        BaseBox.get(), 10.0f);

        //*******************Create the Geometry for the highlight


        BlendChunkRecPtr DefaultBlendChunk = BlendChunk::create();
        DefaultBlendChunk->setSrcFactor(GL_SRC_ALPHA);
        DefaultBlendChunk->setDestFactor(GL_ONE_MINUS_SRC_ALPHA);

        LineChunkRecPtr    DefaultLineChunk = LineChunk::create();
        DefaultLineChunk->setSmooth(true);

        MatCreateFunc = boost::bind(&OctreeVisualization::createMatLine,_1, _2,
                                    Color3f(1.0f,0.0f,0.0f),
                                    Color3f(0.0f,0.0f,1.0f),
                                    0.55f,
                                    DefaultBlendChunk.get(),
                                    DefaultLineChunk.get());

        createOctreeVisualizationRec(tree,
                                     tree->getRoot(),
                                     VisRootNode,
                                     osgMin<UInt32>(tree->getDepth(),MaxDepth),
                                     GeoCreateFunc,
                                     MatCreateFunc,
                                     IsVisibleFunc);
    }


    return NodeTransitPtr(VisRootNode);
}