diff --git a/Gui/DataView/GeoMapper.cpp b/Gui/DataView/GeoMapper.cpp index b6f9ed989b577d7e2cfe7a1e9fe17f5524e6c829..3495da96dc6e8b108e1b82d518285983d3b14021 100644 --- a/Gui/DataView/GeoMapper.cpp +++ b/Gui/DataView/GeoMapper.cpp @@ -9,31 +9,36 @@ * Created on 2012-09-25 by Karsten Rink */ +// ThirdParty/logog +#include "logog/include/logog.hpp" + #include "GeoMapper.h" #include "Mesh.h" #include "Node.h" #include "MshEditor.h" #include "PointWithID.h" -#include "VtkRaster.h" +#include "Raster.h" #include "readMeshFromFile.h" GeoMapper::GeoMapper(GeoLib::GEOObjects &geo_objects, const std::string &geo_name) - : _geo_objects(geo_objects), _geo_name(geo_name), _grid(NULL), - _origin_x(0), _origin_y(0), _cellsize(0), _width(0), _height(0), _img_data(NULL) + : _geo_objects(geo_objects), _geo_name(geo_name), _grid(NULL), _raster(nullptr) { } GeoMapper::~GeoMapper() { - delete _img_data; + delete _raster; } void GeoMapper::mapOnDEM(const std::string &file_name) { - double no_data(-9999); - _img_data = VtkRaster::loadDataFromASC(file_name, _origin_x, _origin_y, _width, _height, _cellsize, no_data); + GeoLib::Raster *raster(GeoLib::Raster::getRasterFromASCFile(file_name)); + if (! raster) { + ERR("GeoMapper::mapOnDEM(): failed to load %s", file_name.c_str()); + return; + } this->mapData(); } @@ -101,13 +106,19 @@ void GeoMapper::mapData(MeshLib::Mesh const*const mesh) float GeoMapper::getDemElevation(double x, double y) const { - if ((x<_origin_x) || (x>_origin_x+(_width*_cellsize)) || (y<_origin_y) || (y>_origin_y+(_height*_cellsize))) + const double origin_x(_raster->getOrigin()[0]); + const double origin_y(_raster->getOrigin()[1]); + const double cellsize(_raster->getRasterPixelDistance()); + const std::size_t width(_raster->getNCols()); + const std::size_t height(_raster->getNRows()); + + if ((x<origin_x) || (x>origin_x+(width*cellsize)) || (y<origin_y) || (y>origin_y+(height*cellsize))) return 0; - unsigned x_index = static_cast<unsigned>((x-_origin_x)/_cellsize); - unsigned y_index = static_cast<unsigned>((y-_origin_y)/_cellsize); + const unsigned x_index = static_cast<unsigned>((x-origin_x)/cellsize); + const unsigned y_index = static_cast<unsigned>((y-origin_y)/cellsize); - return static_cast<float>(_img_data[y_index*_width+x_index]); + return static_cast<float>(*(_raster->begin() + (y_index*width+x_index))); } double GeoMapper::getMeshElevation(double x, double y, MeshLib::Mesh const*const mesh) const diff --git a/Gui/DataView/GeoMapper.h b/Gui/DataView/GeoMapper.h index c0181dd2823e6a177207a4afa6616543939b59a8..24f9a48c132eaa63b732cbe8cf4bae8fc6f5c4d2 100644 --- a/Gui/DataView/GeoMapper.h +++ b/Gui/DataView/GeoMapper.h @@ -25,6 +25,7 @@ namespace MeshLib { namespace GeoLib { class PointWithID; + class Raster; } /** @@ -53,12 +54,7 @@ private: GeoLib::Grid<GeoLib::PointWithID>* _grid; // only necessary for mapping on DEM - double _origin_x; - double _origin_y; - double _cellsize; - unsigned _width; - unsigned _height; - double* _img_data; + GeoLib::Raster *_raster; }; #endif //GEOMAPPER_H