Esempio n. 1
0
	void createPoints()
	{
		test_pnts.emplace_back(1,1,0,0);
		test_pnts.emplace_back(1,2,0,1);
		test_pnts.emplace_back(1,3,0,2);
		test_pnts.emplace_back(2,1,0,3);
		test_pnts.emplace_back(2,2,0,4);
		test_pnts.emplace_back(2,3,0,5);
		test_pnts.emplace_back(3,1,0,6);
		test_pnts.emplace_back(3,2,0,7);
		test_pnts.emplace_back(3,3,0,8);
		auto points = std::unique_ptr<std::vector<GeoLib::Point*>>(
			new std::vector<GeoLib::Point*>(9));

		auto cpy_name_id_map = new std::map<std::string, std::size_t>;
		std::size_t pos(0);
		for (auto p : test_pnts) {
			(*points)[pos] = new GeoLib::Point(p);
			pnt_name_id_map["p"+std::to_string(pos)] = pos;
			(*cpy_name_id_map)["p"+std::to_string(pos)] = pos;
			pos++;
		}

		geo_objects.addPointVec(std::move(points), geo_name, cpy_name_id_map);
	}
Esempio n. 2
0
bool convertMeshToGeo(const MeshLib::Mesh &mesh, GeoLib::GEOObjects &geo_objects, double eps)
{
    if (mesh.getDimension() != 2)
    {
        ERR ("Mesh to geometry conversion is only working for 2D meshes.");
        return false;
    }

    // nodes to points conversion
    std::string mesh_name(mesh.getName());
    {
        auto points = std::make_unique<std::vector<GeoLib::Point*>>();
        points->reserve(mesh.getNumberOfNodes());

        for (auto node_ptr : mesh.getNodes())
            points->push_back(new GeoLib::Point(*node_ptr, node_ptr->getID()));

        geo_objects.addPointVec(std::move(points), mesh_name, nullptr, eps);
    }
    const std::vector<std::size_t> id_map (geo_objects.getPointVecObj(mesh_name)->getIDMap());

    // elements to surface triangles conversion
    std::string const mat_name ("MaterialIDs");
    auto bounds (MeshInformation::getValueBounds<int>(mesh, mat_name));
    const unsigned nMatGroups(bounds.second-bounds.first+1);
    auto sfcs = std::make_unique<std::vector<GeoLib::Surface*>>();
    sfcs->reserve(nMatGroups);
    auto const& points = *geo_objects.getPointVec(mesh_name);
    for (unsigned i=0; i<nMatGroups; ++i)
        sfcs->push_back(new GeoLib::Surface(points));

    const std::vector<MeshLib::Element*> &elements = mesh.getElements();
    const std::size_t nElems (mesh.getNumberOfElements());

    MeshLib::PropertyVector<int> const*const materialIds =
        mesh.getProperties().existsPropertyVector<int>("MaterialIDs")
            ? mesh.getProperties().getPropertyVector<int>("MaterialIDs")
            : nullptr;

    for (unsigned i=0; i<nElems; ++i)
    {
        auto surfaceId = !materialIds ? 0 : ((*materialIds)[i] - bounds.first);
        MeshLib::Element* e (elements[i]);
        if (e->getGeomType() == MeshElemType::TRIANGLE)
            (*sfcs)[surfaceId]->addTriangle(id_map[e->getNodeIndex(0)], id_map[e->getNodeIndex(1)], id_map[e->getNodeIndex(2)]);
        if (e->getGeomType() == MeshElemType::QUAD)
        {
            (*sfcs)[surfaceId]->addTriangle(id_map[e->getNodeIndex(0)], id_map[e->getNodeIndex(1)], id_map[e->getNodeIndex(2)]);
            (*sfcs)[surfaceId]->addTriangle(id_map[e->getNodeIndex(0)], id_map[e->getNodeIndex(2)], id_map[e->getNodeIndex(3)]);
        }
        // all other element types are ignored (i.e. lines)
    }

    std::for_each(sfcs->begin(), sfcs->end(), [](GeoLib::Surface* sfc){ if (sfc->getNumberOfTriangles()==0) delete sfc; sfc = nullptr;});
    auto sfcs_end = std::remove(sfcs->begin(), sfcs->end(), nullptr);
    sfcs->erase(sfcs_end, sfcs->end());

    geo_objects.addSurfaceVec(std::move(sfcs), mesh_name);
    return true;
}
void convertMeshNodesToGeometry(std::vector<MeshLib::Node*> const& nodes,
	std::vector<std::size_t> const& node_ids,
	std::string & geo_name,
	GeoLib::GEOObjects & geometry_sets)
{
	// copy data
	auto pnts = std::unique_ptr<std::vector<GeoLib::Point*>>(
	    new std::vector<GeoLib::Point*>);
	std::map<std::string, std::size_t>* pnt_names(
		new std::map<std::string, std::size_t>);
	std::size_t cnt(0);
	for (std::size_t id: node_ids) {
		pnts->push_back(new GeoLib::Point(*(nodes[id]), cnt));
		pnt_names->insert(std::pair<std::string, std::size_t>(
			geo_name+"-PNT-"+std::to_string(cnt), cnt));
		cnt++;
	}

	// create data structures for geometry
	geometry_sets.addPointVec(std::move(pnts), geo_name, pnt_names);
}
void createSetOfTestPointsAndAssociatedNames(GeoLib::GEOObjects & geo_objs, std::string &name, GeoLib::Point const& shift)
{
	std::vector<GeoLib::Point*> *pnts(new std::vector<GeoLib::Point*>);
	std::map<std::string, std::size_t>* pnt_name_map(new std::map< std::string, std::size_t>);

	const std::size_t pnts_per_edge(8);
	for (std::size_t k(0); k < pnts_per_edge; k++) {
		const std::size_t k_offset(k * pnts_per_edge * pnts_per_edge);
		for (std::size_t j(0); j < pnts_per_edge; j++) {
			const std::size_t offset(j * pnts_per_edge + k_offset);
			for (std::size_t i(0); i < pnts_per_edge; i++) {
				pnts->push_back(new GeoLib::Point(i+shift[0], j+shift[1], k+shift[2]));
				std::string pnt_name(
						name + "-" + BaseLib::number2str(i) + "-" + BaseLib::number2str(j) + "-"
								+ BaseLib::number2str(k));
				pnt_name_map->insert(std::pair< std::string, std::size_t>(pnt_name, i + offset));
			}
		}
	}

	geo_objs.addPointVec(pnts, name, pnt_name_map);
}