Beispiel #1
0
    void extract_mesh(const C3t3& c3t3,
            MatrixFr& vertices, MatrixIr& faces, MatrixIr& voxels) {
        const Tr& tr = c3t3.triangulation();
        size_t num_vertices = tr.number_of_vertices();
        size_t num_faces = c3t3.number_of_facets_in_complex();
        size_t num_voxels = c3t3.number_of_cells_in_complex();

        vertices.resize(num_vertices, 3);
        faces.resize(num_faces, 3);
        voxels.resize(num_voxels, 4);

        std::map<Tr::Vertex_handle, int> V;
        size_t inum = 0;
        for(auto vit = tr.finite_vertices_begin();
                vit != tr.finite_vertices_end(); ++vit) {
            V[vit] = inum;
            const auto& p = vit->point();
            vertices.row(inum) = Vector3F(p.x(), p.y(), p.z()).transpose();
            assert(inum < num_vertices);
            inum++;
        }
        assert(inum == num_vertices);

        size_t face_count = 0;
        for(auto fit = c3t3.facets_in_complex_begin();
                fit != c3t3.facets_in_complex_end(); ++fit) {
            assert(face_count < num_faces);
            for (int i=0; i<3; i++) {
                if (i != fit->second) {
                    const auto& vh = (*fit).first->vertex(i);
                    assert(V.find(vh) != V.end());
                    const int vid = V[vh];
                    faces(face_count, i) = vid;
                }
            }
            face_count++;
        }
        assert(face_count == num_faces);

        size_t voxel_count = 0;
        for(auto cit = c3t3.cells_in_complex_begin() ;
                cit != c3t3.cells_in_complex_end(); ++cit ) {
            assert(voxel_count < num_voxels);
            for (int i=0; i<4; i++) {
                assert(V.find(cit->vertex(i)) != V.end());
                const size_t vid = V[cit->vertex(i)];
                voxels(voxel_count, i) = vid;
            }
            voxel_count++;
        }
        assert(voxel_count == num_voxels);
    }
Beispiel #2
0
 void create_box(const VectorF& bbox_min, const VectorF& bbox_max,
         MatrixFr& box_vertices, MatrixIr& box_faces) {
     box_vertices.resize(8, 3);
     box_faces.resize(12, 3);
     box_vertices << bbox_min[0], bbox_min[1], bbox_min[2],
                     bbox_max[0], bbox_min[1], bbox_min[2],
                     bbox_max[0], bbox_max[1], bbox_min[2],
                     bbox_min[0], bbox_max[1], bbox_min[2],
                     bbox_min[0], bbox_min[1], bbox_max[2],
                     bbox_max[0], bbox_min[1], bbox_max[2],
                     bbox_max[0], bbox_max[1], bbox_max[2],
                     bbox_min[0], bbox_max[1], bbox_max[2];
     box_faces << 1, 2, 5,
                  5, 2, 6,
                  3, 4, 7,
                  3, 0, 4,
                  2, 3, 6,
                  3, 7, 6,
                  0, 1, 5,
                  0, 5, 4,
                  4, 5, 6,
                  4, 6, 7,
                  0, 3, 2,
                  0, 2, 1;
 }
Beispiel #3
0
    void extract_data(CarveMeshPtr mesh, MatrixFr& vertices, MatrixIr& faces) {
        typedef CarveMesh::vertex_t CarveVertex;
        const size_t num_vertices = mesh->vertex_storage.size();
        vertices.resize(num_vertices, 3);
        for (size_t i=0; i<num_vertices; i++) {
            const auto& v = mesh->vertex_storage[i];
            vertices(i,0) = v.v.x;
            vertices(i,1) = v.v.y;
            vertices(i,2) = v.v.z;
        }

        const size_t num_faces = mesh->faceEnd() - mesh->faceBegin();
        faces.resize(num_faces, 3);
        for (auto itr=mesh->faceBegin(); itr != mesh->faceEnd(); itr++) {
            std::vector<CarveVertex* > vts;
            (*itr)->getVertices(vts);
            assert(vts.size() == 3);

            // WARNING:
            // Here is my guess on how to extract vertex index.
            // Carve's documentation is not clear on how to do this.  
            const size_t fid = itr - mesh->faceBegin();
            faces(fid, 0) = vts[0] - &mesh->vertex_storage[0];
            faces(fid, 1) = vts[1] - &mesh->vertex_storage[0];
            faces(fid, 2) = vts[2] - &mesh->vertex_storage[0];
        }
    }