diff --git a/dumux/io/grid/gridmanager_sub.hh b/dumux/io/grid/gridmanager_sub.hh index cf18c0bb848ffe93732876667b8a01fe69435ed7..fadeff1335996969a8b93ade27db946d086d0f39 100644 --- a/dumux/io/grid/gridmanager_sub.hh +++ b/dumux/io/grid/gridmanager_sub.hh @@ -25,6 +25,7 @@ #define DUMUX_IO_GRID_MANAGER_SUB_HH #include <memory> +#include <utility> #include <dune/common/shared_ptr.hh> #include <dune/common/concept.hh> @@ -241,14 +242,26 @@ private: template<class Img> void createGridFromImage_(const Img& img, const std::string& paramGroup) { - // get the corner coordinates - using GlobalPosition = typename ParentType::Grid::template Codim<0>::Geometry::GlobalCoordinate; - const auto upperRight = getParamFromGroup<GlobalPosition>(paramGroup, "Grid.UpperRight"); - const auto lowerLeft = getParamFromGroup<GlobalPosition>(paramGroup, "Grid.LowerLeft", GlobalPosition(0.0)); - // get the number of cells const std::array<int, dim> cells{static_cast<int>(img.header().nCols), static_cast<int>(img.header().nRows)}; + // get the corner coordinates + const auto [lowerLeft, upperRight] = [&]() + { + using GlobalPosition = typename ParentType::Grid::template Codim<0>::Geometry::GlobalCoordinate; + const auto lowerLeft = getParamFromGroup<GlobalPosition>(paramGroup, "Grid.LowerLeft", GlobalPosition(0.0)); + if (hasParamInGroup(paramGroup, "Grid.PixelDimensions")) + { + auto upperRight = getParamFromGroup<GlobalPosition>(paramGroup, "Grid.PixelDimensions"); + for (int i = 0; i < upperRight.size(); ++i) + upperRight[i] *= cells[i]; + upperRight += lowerLeft; + return std::make_pair(lowerLeft, upperRight); + } + else + return std::make_pair(lowerLeft, getParamFromGroup<GlobalPosition>(paramGroup, "Grid.UpperRight")); + }(); + // construct the host grid this->initHostGrid_(lowerLeft, upperRight, cells, paramGroup); diff --git a/dumux/io/rasterimagereader.hh b/dumux/io/rasterimagereader.hh index 4ead3192f7a2ebbed232fee6396bdcced365605b..0e5304f9d633b45fb0325b0102b4bda89f172c31 100644 --- a/dumux/io/rasterimagereader.hh +++ b/dumux/io/rasterimagereader.hh @@ -328,7 +328,7 @@ public: std::size_t rowIdx = 0; std::size_t colIdx = 0; - for (const auto& val : result) + for (const auto val : result) { image[rowIdx][colIdx] = val; @@ -354,7 +354,7 @@ public: std::vector<OutputValueType> data; data.reserve(image.size()*image[0].size()); for (const auto& row: image) - for (const auto& col : row) + for (const auto col : row) data.push_back(col); return data; diff --git a/test/io/rasterimagereader/test_rasterimagereader.cc b/test/io/rasterimagereader/test_rasterimagereader.cc index 491a4fab09ea6e18cfe7ea19315121b5f60fbba3..3853f420e7e4e84b62dd0bc2de02e680973cb668 100644 --- a/test/io/rasterimagereader/test_rasterimagereader.cc +++ b/test/io/rasterimagereader/test_rasterimagereader.cc @@ -49,7 +49,7 @@ int main(int argc, char** argv) // print the image for (const auto& row: printableBlackAndWhiteImage) { - for (const auto& col : row) + for (bool col : row) std::cout << col << " "; std::cout << std::endl; } @@ -131,7 +131,7 @@ int main(int argc, char** argv) // print the image for (const auto& row: printableGrayScaleImage) { - for (const auto& col : row) + for (bool col : row) std::cout << std::setw(3) << +col << " "; std::cout << std::endl; }