https://gitlab.opengeosys.org/ogs/ogs.git
Raw File
Tip revision: daaddc08b6ad363c20ae9c29c11eeea8113c7d14 authored by Lars Bilke on 06 August 2015, 13:27:41 UTC
Merge pull request #798 from rinkk/GmlReaderMemoryFix
Tip revision: daaddc0
BoundaryElementsSearcher.cpp
/**
 * @copyright
 * Copyright (c) 2012-2015, OpenGeoSys Community (http://www.opengeosys.org)
 *            Distributed under a Modified BSD License.
 *              See accompanying file LICENSE.txt or
 *              http://www.opengeosys.org/LICENSE.txt
 */

#include "BoundaryElementsSearcher.h"

#include "GeoLib/GeoObject.h"
#include "GeoLib/Polyline.h"
#include "GeoLib/Surface.h"

#include "MeshLib/Mesh.h"
#include "MeshLib/Elements/Element.h"

#include "MeshGeoToolsLib/MeshNodeSearcher.h"
#include "MeshGeoToolsLib/BoundaryElementsAlongPolyline.h"
#include "MeshGeoToolsLib/BoundaryElementsOnSurface.h"


namespace MeshGeoToolsLib
{

BoundaryElementsSearcher::BoundaryElementsSearcher(MeshLib::Mesh const& mesh, MeshNodeSearcher &mshNodeSearcher) : _mesh(mesh), _mshNodeSearcher(mshNodeSearcher)
{}

BoundaryElementsSearcher::~BoundaryElementsSearcher()
{
	for (auto p : _boundary_elements_along_polylines)
		delete p;
	for (auto p : _boundary_elements_along_surfaces)
		delete p;
}

std::vector<MeshLib::Element*> const& BoundaryElementsSearcher::getBoundaryElements(GeoLib::GeoObject const& geoObj)
{
	switch (geoObj.getGeoType()) {
	case GeoLib::GEOTYPE::POLYLINE:
		return this->getBoundaryElementsAlongPolyline(*dynamic_cast<const GeoLib::Polyline*>(&geoObj));
		break;
	case GeoLib::GEOTYPE::SURFACE:
		return this->getBoundaryElementsOnSurface(*dynamic_cast<const GeoLib::Surface*>(&geoObj));
		break;
	default:
		const static std::vector<MeshLib::Element*> dummy(0);
		return dummy;
	}
}

std::vector<MeshLib::Element*> const& BoundaryElementsSearcher::getBoundaryElementsAlongPolyline(GeoLib::Polyline const& ply)
{
	std::vector<BoundaryElementsAlongPolyline*>::const_iterator it(_boundary_elements_along_polylines.begin());
	for (; it != _boundary_elements_along_polylines.end(); ++it) {
		if (&(*it)->getPolyline() == &ply) {
			// we calculated mesh nodes for this polyline already
			return (*it)->getBoundaryElements();
		}
	}

	_boundary_elements_along_polylines.push_back(
			new BoundaryElementsAlongPolyline(_mesh, _mshNodeSearcher, ply));
	return _boundary_elements_along_polylines.back()->getBoundaryElements();
}

std::vector<MeshLib::Element*> const& BoundaryElementsSearcher::getBoundaryElementsOnSurface(GeoLib::Surface const& sfc)
{
	std::vector<BoundaryElementsOnSurface*>::const_iterator it(_boundary_elements_along_surfaces.begin());
	for (; it != _boundary_elements_along_surfaces.end(); ++it) {
		if (&(*it)->getSurface() == &sfc) {
			// we calculated mesh nodes for this surface already
			return (*it)->getBoundaryElements();
		}
	}

	_boundary_elements_along_surfaces.push_back(
			new BoundaryElementsOnSurface(_mesh, _mshNodeSearcher, sfc));
	return _boundary_elements_along_surfaces.back()->getBoundaryElements();
}

} // end namespace MeshGeoToolsLib

back to top