Пример #1
0
const std::vector< std::pair<std::size_t,double> >& DirectConditionGenerator::directToSurfaceNodes(const MeshLib::Mesh &mesh, const std::string &filename)
{
    if (_direct_values.empty())
    {
        GeoLib::Raster* raster (GeoLib::IO::AsciiRasterInterface::readRaster(filename));
        if (! raster) {
            ERR("Error in DirectConditionGenerator::directToSurfaceNodes() - could not load raster file.");
            return _direct_values;
        }

        const MathLib::Vector3 dir(0,0,-1);
        const std::vector<GeoLib::Point*> surface_nodes(MeshLib::MeshSurfaceExtraction::getSurfaceNodes(mesh, dir, 90) );
        const std::size_t nNodes(surface_nodes.size());
        const double no_data (raster->getHeader().no_data);
        _direct_values.reserve(nNodes);
        for (std::size_t i=0; i<nNodes; i++)
        {
            double val (raster->getValueAtPoint(*surface_nodes[i]));
            val = (val == no_data) ? 0 : val;
            _direct_values.push_back (std::pair<std::size_t, double>(surface_nodes[i]->getID(), val));
        }
        delete raster;
    }
    else
        ERR("Error in DirectConditionGenerator::directToSurfaceNodes() - Data vector contains outdated values.");

    return _direct_values;
}
Пример #2
0
const std::vector< std::pair<size_t,double> >& DirectConditionGenerator::directWithSurfaceIntegration(MeshLib::Mesh &mesh, const std::string &filename, double scaling)
{
	if (_direct_values.empty())
	{
		GeoLib::Raster* raster (GeoLib::Raster::readRaster(filename));
		if (!raster) {
			ERR("Error in DirectConditionGenerator::directWithSurfaceIntegration() - could not load raster file.");
			return _direct_values;
		}

		const MathLib::Vector3 dir(0,0,-1);
		MeshLib::Mesh* sfc_mesh (MeshLib::MeshSurfaceExtraction::getMeshSurface(mesh, dir, true));
		std::vector<double> node_area_vec;
		MeshLib::MeshSurfaceExtraction::getSurfaceAreaForNodes(*sfc_mesh, node_area_vec);
		const std::vector<MeshLib::Node*> &surface_nodes (sfc_mesh->getNodes());
		const size_t nNodes(sfc_mesh->getNNodes());
		const double no_data (raster->getNoDataValue());
		_direct_values.reserve(nNodes);
		for (size_t i=0; i<nNodes; ++i)
		{
			double val (raster->getValueAtPoint(*surface_nodes[i]));
			val = (val == no_data) ? 0 : ((val*node_area_vec[i])/scaling);
			_direct_values.push_back (std::pair<size_t, double>(surface_nodes[i]->getID(), val));
		}

		delete raster;
	}
	else
		std::cout << "Error in DirectConditionGenerator::directWithSurfaceIntegration() - Data vector contains outdated values..." << std::endl;

	return _direct_values;
}
Пример #3
0
bool MeshLayerMapper::layerMapping(MeshLib::Mesh &new_mesh, GeoLib::Raster const& raster, double noDataReplacementValue = 0.0)
{
    if (new_mesh.getDimension() != 2)
    {
        ERR("MshLayerMapper::layerMapping() - requires 2D mesh");
        return false;
    }

    GeoLib::RasterHeader const& header (raster.getHeader());
    const double x0(header.origin[0]);
    const double y0(header.origin[1]);
    const double delta(header.cell_size);

    const std::pair<double, double> xDim(x0, x0 + header.n_cols * delta); // extension in x-dimension
    const std::pair<double, double> yDim(y0, y0 + header.n_rows * delta); // extension in y-dimension

    const std::size_t nNodes (new_mesh.getNumberOfNodes());
    const std::vector<MeshLib::Node*> &nodes = new_mesh.getNodes();
    for (unsigned i = 0; i < nNodes; ++i)
    {
        if (!raster.isPntOnRaster(*nodes[i]))
        {
            // use either default value or elevation from layer above
            nodes[i]->updateCoordinates((*nodes[i])[0], (*nodes[i])[1], noDataReplacementValue);
            continue;
        }

        double elevation (raster.interpolateValueAtPoint(*nodes[i]));
        if (std::abs(elevation - header.no_data) < std::numeric_limits<double>::epsilon())
            elevation = noDataReplacementValue;
        nodes[i]->updateCoordinates((*nodes[i])[0], (*nodes[i])[1], elevation);
    }

    return true;
}
Пример #4
0
double LayeredMeshGenerator::calcEpsilon(GeoLib::Raster const& low, GeoLib::Raster const& high)
{
    const double max (*std::max_element(high.begin(), high.end()));
    const double min (*std::min_element( low.begin(),  low.end()));
    return ((max-min)*1e-07);
}