Exemplo n.º 1
0
/// run mc on one Octnode
/// this generates one or more triangles which are pushed to the GLData
void MarchingCubes::mc_node( Octnode* node) {
    assert( node->childcount == 0 ); // don't call this on non-leafs!
    assert( node->is_undecided() );
    unsigned int edgeTableIndex = mc_edgeTableIndex(node);
    unsigned int edges = edgeTable[edgeTableIndex];
    std::vector< GLVertex > vertices = interpolated_vertices(node, edges);
    for (unsigned int i=0; triTable[edgeTableIndex][i] != -1 ; i+=3 ) {
        std::vector< unsigned int > triangle;
        GLVertex p1 = vertices[ triTable[edgeTableIndex][i    ] ];
        GLVertex p2 = vertices[ triTable[edgeTableIndex][i+1  ] ];
        GLVertex p3 = vertices[ triTable[edgeTableIndex][i+2  ] ];
        GLVertex::set_normal_and_color( p1, p2, p3, node->color );
        triangle.push_back( g->addVertex(  p1, node ) );
        triangle.push_back( g->addVertex(  p2, node ) );
        triangle.push_back( g->addVertex(  p3, node ) );
        g->addPolygon(triangle);
        node->addIndex( triangle[0] );
        node->addIndex( triangle[1] );
        node->addIndex( triangle[2] );
    }
}
Exemplo n.º 2
0
// run mc on one Octnode
std::vector<Triangle> MarchingCubes::mc_node(const Octnode* node) {
    assert( node->childcount == 0 ); // don't call this on non-leafs!
    std::vector<Triangle> tris;
    unsigned int edgeTableIndex = mc_edgeTableIndex(node);
    // the index into this table now tells us which edges have the vertices
    // for the new triangles
    // the lookup returns a 12-bit number, where each bit indicates wether 
    // the edge is cut by the isosurface
    unsigned int edges = edgeTable[edgeTableIndex];
    // calculate intersection points by linear interpolation
    // there are now 12 different cases:
    std::vector<Point> vertices = interpolated_vertices(node, edges);
    assert(vertices.size()==12);
    // form triangles by lookup in triTable
    for (unsigned int i=0; triTable[edgeTableIndex][i] != -1 ; i+=3 ) {
        tris.push_back( Triangle( vertices[ triTable[edgeTableIndex][i  ] ],
                                  vertices[ triTable[edgeTableIndex][i+1] ], 
                                  vertices[ triTable[edgeTableIndex][i+2] ]  )
                                  );
    }
    return tris;
}