Ejemplo n.º 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;
}
Ejemplo n.º 2
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;
}