Esempio n. 1
0
void ElementTreeModel::setMesh(MeshLib::Mesh const& mesh)
{
    this->clearView();

    QList<QVariant> mesh_name;
    mesh_name << "Name:" << QString::fromStdString(mesh.getName()) << "" << "" << "";
    TreeItem* name_item = new TreeItem(mesh_name, _rootItem);
    _rootItem->appendChild(name_item);

    QList<QVariant> nodes_number;
    nodes_number << "#Nodes: " << QString::number(mesh.getNumberOfNodes()) << "" << "";
    TreeItem* nodes_item = new TreeItem(nodes_number, _rootItem);
    _rootItem->appendChild(nodes_item);

    QList<QVariant> elements_number;
    elements_number << "#Elements: " << QString::number(mesh.getNumberOfElements()) << "" << "";
    TreeItem* elements_item = new TreeItem(elements_number, _rootItem);
    _rootItem->appendChild(elements_item);

    const std::array<QString, 7> n_element_names = {{ "Lines:", "Triangles:", "Quads:", "Tetrahedra:", "Hexahedra:", "Pyramids:", "Prisms:" }};
    const std::array<unsigned, 7>& n_element_types (MeshLib::MeshInformation::getNumberOfElementTypes(mesh));
    for (std::size_t i=0; i<n_element_types.size(); ++i)
    {
        if (n_element_types[i])
        {
            QList<QVariant> elements_number;
            elements_number << n_element_names[i] << QString::number(n_element_types[i]) << "" << "";
            TreeItem* type_item = new TreeItem(elements_number, elements_item);
            elements_item->appendChild(type_item);
        }
    }

    QList<QVariant> bounding_box;
    bounding_box << "Bounding Box" << "" << "" << "";
    TreeItem* aabb_item = new TreeItem(bounding_box, _rootItem);
    _rootItem->appendChild(aabb_item);

    const GeoLib::AABB aabb (MeshLib::MeshInformation::getBoundingBox(mesh));
    auto const& min = aabb.getMinPoint();
    auto const& max = aabb.getMaxPoint();

    QList<QVariant> min_aabb;
    min_aabb << "Min:" << QString::number(min[0], 'f') << QString::number(min[1], 'f') << QString::number(min[2], 'f');
    TreeItem* min_item = new TreeItem(min_aabb, aabb_item);
    aabb_item->appendChild(min_item);

    QList<QVariant> max_aabb;
    max_aabb << "Max:" << QString::number(max[0], 'f') << QString::number(max[1], 'f') << QString::number(max[2], 'f');
    TreeItem* max_item = new TreeItem(max_aabb, aabb_item);
    aabb_item->appendChild(max_item);

    QList<QVariant> edges;
    edges << "Edge Length: " << "[" + QString::number(mesh.getMinEdgeLength(), 'f') + "," << QString::number(mesh.getMaxEdgeLength(), 'f') + "]" << "";
    TreeItem* edge_item = new TreeItem(edges, _rootItem);
    _rootItem->appendChild(edge_item);

    std::vector<std::string> const& vec_names (mesh.getProperties().getPropertyVectorNames());
    for (std::size_t i=0; i<vec_names.size(); ++i)
    {
        QList<QVariant> array_info;
        array_info << QString::fromStdString(vec_names[i]) + ": ";
        auto vec_bounds (MeshLib::MeshInformation::getValueBounds<int>(mesh, vec_names[i]));
        if (vec_bounds.second != std::numeric_limits<int>::max())
            array_info << "[" + QString::number(vec_bounds.first) + "," << QString::number(vec_bounds.second) + "]" << "";
        else
        {
            auto vec_bounds (MeshLib::MeshInformation::getValueBounds<double>(mesh, vec_names[i]));
            if (vec_bounds.second != std::numeric_limits<double>::max())
                array_info  << "[" + QString::number(vec_bounds.first) + "," << QString::number(vec_bounds.second) + "]" << "";
        }
        if (array_info.size() == 1)
            array_info << "[ ?" << "? ]" << "";
        TreeItem* vec_item = new TreeItem(array_info, _rootItem);
        _rootItem->appendChild(vec_item);
    }

    reset();

}
Esempio n. 2
0
std::unique_ptr<MeshLib::Mesh> appendLinesAlongPolylines(
    const MeshLib::Mesh& mesh, const GeoLib::PolylineVec& ply_vec)
{
    // copy existing nodes and elements
    std::vector<MeshLib::Node*> vec_new_nodes = MeshLib::copyNodeVector(mesh.getNodes());
    std::vector<MeshLib::Element*> vec_new_eles = MeshLib::copyElementVector(mesh.getElements(), vec_new_nodes);

    auto const material_ids = materialIDs(mesh);
    int const max_matID =
        material_ids
            ? *(std::max_element(begin(*material_ids), end(*material_ids)))
            : 0;

    std::vector<int> new_mat_ids;
    const std::size_t n_ply (ply_vec.size());
    // for each polyline
    for (std::size_t k(0); k < n_ply; k++)
    {
        const GeoLib::Polyline* ply = (*ply_vec.getVector())[k];

        // search nodes on the polyline
        MeshGeoToolsLib::MeshNodesAlongPolyline mshNodesAlongPoly(
            mesh, *ply, mesh.getMinEdgeLength() * 0.5,
            MeshGeoToolsLib::SearchAllNodes::Yes);
        auto &vec_nodes_on_ply = mshNodesAlongPoly.getNodeIDs();
        if (vec_nodes_on_ply.empty()) {
            std::string ply_name;
            ply_vec.getNameOfElementByID(k, ply_name);
            INFO("No nodes found on polyline %s", ply_name.c_str());
            continue;
        }

        // add line elements
        for (std::size_t i=0; i<vec_nodes_on_ply.size()-1; i++) {
            std::array<MeshLib::Node*, 2> element_nodes;
            element_nodes[0] = vec_new_nodes[vec_nodes_on_ply[i]];
            element_nodes[1] = vec_new_nodes[vec_nodes_on_ply[i+1]];
            vec_new_eles.push_back(
                new MeshLib::Line(element_nodes, vec_new_eles.size()));
            new_mat_ids.push_back(max_matID+k+1);
        }
    }

    // generate a mesh
    const std::string name = mesh.getName() + "_with_lines";
    auto new_mesh =
        std::make_unique<MeshLib::Mesh>(name, vec_new_nodes, vec_new_eles);
    auto new_material_ids =
        new_mesh->getProperties().createNewPropertyVector<int>(
            "MaterialIDs", MeshLib::MeshItemType::Cell);
    if (!new_material_ids)
    {
        OGS_FATAL("Could not create MaterialIDs cell vector in new mesh.");
    }
    new_material_ids->reserve(new_mesh->getNumberOfElements());
    if (material_ids != nullptr)
    {
        std::copy(begin(*material_ids), end(*material_ids),
                  std::back_inserter(*new_material_ids));
    }
    else
    {
        new_material_ids->resize(mesh.getNumberOfElements());
    }
    std::copy(begin(new_mat_ids), end(new_mat_ids),
              std::back_inserter(*new_material_ids));
    return new_mesh;
}
std::unique_ptr<MeshLib::Mesh> appendLinesAlongPolylines(
    const MeshLib::Mesh& mesh, const GeoLib::PolylineVec& ply_vec)
{
    // copy existing nodes and elements
    std::vector<MeshLib::Node*> vec_new_nodes = MeshLib::copyNodeVector(mesh.getNodes());
    std::vector<MeshLib::Element*> vec_new_eles = MeshLib::copyElementVector(mesh.getElements(), vec_new_nodes);

    std::vector<int> new_mat_ids;
    {
        if (mesh.getProperties().existsPropertyVector<int>("MaterialIDs")) {
            auto ids =
                mesh.getProperties().getPropertyVector<int>("MaterialIDs");
            new_mat_ids.reserve(ids->size());
            std::copy(ids->cbegin(), ids->cend(),
                      std::back_inserter(new_mat_ids));
        }
    }
    int max_matID(0);
    if (!new_mat_ids.empty())
        max_matID = *(std::max_element(new_mat_ids.cbegin(), new_mat_ids.cend()));

    const std::size_t n_ply (ply_vec.size());
    // for each polyline
    for (std::size_t k(0); k < n_ply; k++)
    {
        const GeoLib::Polyline* ply = (*ply_vec.getVector())[k];

        // search nodes on the polyline
        MeshGeoToolsLib::MeshNodesAlongPolyline mshNodesAlongPoly(
            mesh, *ply, mesh.getMinEdgeLength() * 0.5,
            MeshGeoToolsLib::SearchAllNodes::Yes);
        auto &vec_nodes_on_ply = mshNodesAlongPoly.getNodeIDs();
        if (vec_nodes_on_ply.empty()) {
            std::string ply_name;
            ply_vec.getNameOfElementByID(k, ply_name);
            INFO("No nodes found on polyline %s", ply_name.c_str());
            continue;
        }

        // add line elements
        for (std::size_t i=0; i<vec_nodes_on_ply.size()-1; i++) {
            std::array<MeshLib::Node*, 2> element_nodes;
            element_nodes[0] = vec_new_nodes[vec_nodes_on_ply[i]];
            element_nodes[1] = vec_new_nodes[vec_nodes_on_ply[i+1]];
            vec_new_eles.push_back(
                new MeshLib::Line(element_nodes, vec_new_eles.size()));
            new_mat_ids.push_back(max_matID+k+1);
        }
    }

    // generate a mesh
    const std::string name = mesh.getName() + "_with_lines";
    auto new_mesh =
        std::make_unique<MeshLib::Mesh>(name, vec_new_nodes, vec_new_eles);
    auto opt_mat_pv = new_mesh->getProperties().createNewPropertyVector<int>(
        "MaterialIDs", MeshLib::MeshItemType::Cell);
    if (opt_mat_pv) {
        auto & mat_pv = *opt_mat_pv;
        mat_pv.reserve(new_mat_ids.size());
        std::copy(new_mat_ids.cbegin(), new_mat_ids.cend(),
            std::back_inserter(mat_pv));
    }
    return new_mesh;
}