예제 #1
0
std::size_t ElementSearch::searchByBoundingBox(
    GeoLib::AABB const& aabb)
{
    auto matchedIDs = filter(_mesh.getElements(),
        [&aabb](MeshLib::Element* e) {
            std::size_t const nElemNodes (e->getNumberOfBaseNodes());
            for (std::size_t n=0; n < nElemNodes; ++n)
                if (aabb.containsPoint(*e->getNode(n), 0))
                    return true;    // any node of element is in aabb.
            return false;    // no nodes of element are in aabb.
        });

    this->updateUnion(matchedIDs);
    return matchedIDs.size();
}
void Mesh2MeshPropertyInterpolation::interpolatePropertiesForMesh(Mesh *dest_mesh, std::vector<double>& dest_properties) const
{
    // carry over property information from source elements to source nodes
    std::vector<double> interpolated_src_node_properties(_src_mesh->getNumberOfNodes());
    interpolateElementPropertiesToNodeProperties(interpolated_src_node_properties);

    // looping over the destination elements and calculate properties
    // from interpolated_src_node_properties
    std::vector<MeshLib::Node*> const& src_nodes(_src_mesh->getNodes());

    GeoLib::Grid<MeshLib::Node> src_grid(src_nodes.begin(), src_nodes.end(), 64);

    auto materialIds = dest_mesh->getProperties().getPropertyVector<int>("MaterialIDs");
    if (!materialIds)
        materialIds = dest_mesh->getProperties().createNewPropertyVector<int>(
            "MaterialIDs", MeshLib::MeshItemType::Cell, 1);
    if (!materialIds)
    {
        ERR("Could not create PropertyVector for MaterialIDs in Mesh.");
        return;
    }

    std::vector<MeshLib::Element*> const& dest_elements(dest_mesh->getElements());
    const std::size_t n_dest_elements(dest_elements.size());
    for (std::size_t k(0); k<n_dest_elements; k++)
    {
        // compute axis aligned bounding box around the current element
        const GeoLib::AABB elem_aabb(dest_elements[k]->getNodes(), dest_elements[k]->getNodes()+dest_elements[k]->getNumberOfBaseNodes());

        // request "interesting" nodes from grid
        std::vector<std::vector<MeshLib::Node*> const*> nodes;
        src_grid.getPntVecsOfGridCellsIntersectingCuboid(elem_aabb.getMinPoint(), elem_aabb.getMaxPoint(), nodes);

        std::size_t cnt(0);
        dest_properties[k] = 0.0;

        for (std::size_t i(0); i<nodes.size(); ++i) {
            std::vector<MeshLib::Node*> const* i_th_vec(nodes[i]);
            const std::size_t n_nodes_in_vec(i_th_vec->size());
            for (std::size_t j(0); j<n_nodes_in_vec; j++) {
                MeshLib::Node const*const j_th_node((*i_th_vec)[j]);
                if (elem_aabb.containsPoint(*j_th_node)) {
                    if (dest_elements[k]->isPntInElement(*j_th_node, 30)) {
                        dest_properties[k] += interpolated_src_node_properties[(*i_th_vec)[j]->getID()];
                        cnt++;
                    }
                }
            }
        }

        dest_properties[k] /= cnt;
        materialIds->push_back(k);

        if (cnt == 0) {
            std::string base_name("DebugData/Element-");
            base_name += std::to_string(k);

            std::string aabb_fname(base_name + "-aabb.gli");
            std::ofstream out_aabb(aabb_fname.c_str());
            out_aabb << "#POINTS" << "\n";
            out_aabb << "0 " << elem_aabb.getMinPoint() << "\n";
            out_aabb << "1 " << elem_aabb.getMaxPoint() << "\n";
            out_aabb << "#STOP" << "\n";
            out_aabb.close();


            std::string source_fname(base_name + "-SourceNodes.gli");
            std::ofstream out_src(source_fname.c_str());
            out_src << "#POINTS" << "\n";
            std::size_t nodes_cnt(0);
            for (std::size_t i(0); i<nodes.size(); ++i) {
                std::vector<MeshLib::Node*> const* i_th_vec(nodes[i]);
                const std::size_t n_nodes_in_vec(i_th_vec->size());
                for (std::size_t j(0); j<n_nodes_in_vec; j++) {
                    MeshLib::Node const*const j_th_node((*i_th_vec)[j]);
                    out_src << nodes_cnt << " " << *(dynamic_cast<GeoLib::Point const*>(j_th_node)) << "\n";
                    nodes_cnt++;
                }
            }
            out_src << "#STOP" << "\n";
            out_src.close();
            ERR("no source nodes in dest element %d", k);
        }
    }
}