Beispiel #1
0
GeoMeshPtr GeogramMeshUtils::mesh_to_geomesh(const Mesh::Ptr mesh) {
    const size_t dim = mesh->get_dim();
    const size_t vertex_per_face = mesh->get_vertex_per_face();
    const size_t num_vertices = mesh->get_num_vertices();
    const size_t num_faces = mesh->get_num_faces();
    const auto& vertices = mesh->get_vertices();
    const auto& faces = mesh->get_faces();

    if (vertex_per_face != 3) {
        throw NotImplementedError("Converting non-triangle mesh to "
                "Geogram mesh is not yet implemented");
    }

    auto geo_mesh = std::make_shared<GeoMesh>(dim, false);
    geo_mesh->vertices.clear();
    geo_mesh->vertices.create_vertices(num_vertices);
    geo_mesh->facets.clear();
    geo_mesh->facets.create_triangles(num_faces);

    for (size_t i=0; i<num_vertices; i++) {
        auto& p = geo_mesh->vertices.point(i);
        for (size_t j=0; j<dim; j++) {
            p[j] = vertices[i*dim+j];
        }
    }

    for (size_t i=0; i<num_faces; i++) {
        geo_mesh->facets.set_vertex(i, 0, faces[i*3]);
        geo_mesh->facets.set_vertex(i, 1, faces[i*3+1]);
        geo_mesh->facets.set_vertex(i, 2, faces[i*3+2]);
    }

    return geo_mesh;
}
Beispiel #2
0
CellPartition::Ptr CellPartition::create(const Mesh::Ptr& mesh) {
    const MatrixFr vertices = MatrixUtils::reshape<MatrixFr>(
            mesh->get_vertices(), mesh->get_num_vertices(), mesh->get_dim());
    const MatrixIr faces = MatrixUtils::reshape<MatrixIr>(
            mesh->get_faces(), mesh->get_num_faces(),
            mesh->get_vertex_per_face());
    return CellPartition::Ptr(new CellPartition(vertices, faces));
}
void copy_vertices(Mesh::Ptr mesh, std::unique_ptr<DracoMesh>& draco_mesh) {
    const auto dim = mesh->get_dim();
    const auto num_vertices = mesh->get_num_vertices();
    draco_mesh->set_num_points(num_vertices);
    draco::GeometryAttribute positions;
    positions.Init(draco::GeometryAttribute::POSITION, // Attribute type
            nullptr,                                   // data buffer
            dim,                                       // number of components
            draco::DT_FLOAT64,                         // data type
            false,                                     // normalized
            sizeof(Float) * dim,                       // byte stride
            0);                                        // byte offset
    auto pos_att_id = draco_mesh->AddAttribute(
            positions,      // attribute object
            true,           // identity mapping
            num_vertices);  // num attribute values

    for (int i = 0; i < num_vertices; ++i) {
        draco_mesh->attribute(pos_att_id)->SetAttributeValue(
                draco::AttributeValueIndex(i), mesh->get_vertex(i).data());
    }
}