From 0995a736ca1c4871e4359781aa4458c573742e68 Mon Sep 17 00:00:00 2001 From: VincentMiras Date: Mon, 22 Sep 2025 09:36:35 +0200 Subject: [PATCH 01/16] =?UTF-8?q?Cr=C3=A9ation=20du=20style=20terrain=20rg?= =?UTF-8?q?b?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- include/rok4/style/Terrainrgb.h | 80 +++++++++++++++++++++++++++++++++ src/style/Terrainrgb.cpp | 70 +++++++++++++++++++++++++++++ 2 files changed, 150 insertions(+) create mode 100644 include/rok4/style/Terrainrgb.h create mode 100644 src/style/Terrainrgb.cpp diff --git a/include/rok4/style/Terrainrgb.h b/include/rok4/style/Terrainrgb.h new file mode 100644 index 0000000..65bb53c --- /dev/null +++ b/include/rok4/style/Terrainrgb.h @@ -0,0 +1,80 @@ +/* + * Copyright © (2011) Institut national de l'information + * géographique et forestière + * + * Géoportail SAV + * + * This software is a computer program whose purpose is to publish geographic + * data using OGC WMS and WMTS protocol. + * + * This software is governed by the CeCILL-C license under French law and + * abiding by the rules of distribution of free software. You can use, + * modify and/ or redistribute the software under the terms of the CeCILL-C + * license as circulated by CEA, CNRS and INRIA at the following URL + * "http://www.cecill.info". + * + * As a counterpart to the access to the source code and rights to copy, + * modify and redistribute granted by the license, users are provided only + * with a limited warranty and the software's author, the holder of the + * economic rights, and the successive licensors have only limited + * liability. + * + * In this respect, the user's attention is drawn to the risks associated + * with loading, using, modifying and/or developing or reproducing the + * software by the user in light of its specific status of free software, + * that may mean that it is complicated to manipulate, and that also + * therefore means that it is reserved for developers and experienced + * professionals having in-depth computer knowledge. Users are therefore + * encouraged to load and test the software's suitability as regards their + * requirements in conditions enabling the security of their systems and/or + * data to be ensured and, more generally, to use and operate it in the + * same conditions as regards security. + * + * The fact that you are presently reading this means that you have had + * + * knowledge of the CeCILL-C license and that you accept its terms. + */ + +#pragma once + +#include "rok4/utils/Configuration.h" + +#include +#include +#include +#include + +class Terrainrgb : public Configuration +{ +private: + /** \~french + * \brief min_elevation : élévation minimale à partir de laquelle est calculée la couleur + ** \~english + * \brief min_elevation : minimum elevation from which the color is calculated + */ + int min_elevation; + + /** \~french + * \brief step : écart d'altitude entre deux couleurs différentes + ** \~english + * \brief step : altitude difference between two different colors + */ + float step; + +public: + /** + * \~french + * \brief Constructeurs avec des arguments + * \~english + * \brief Constructor with arguments + */ + Terrainrgb(json11::Json doc); + + /** + * \~french + * \brief Destructeur + * \~english + * \brief Destructor + */ + virtual ~Terrainrgb(); +}; diff --git a/src/style/Terrainrgb.cpp b/src/style/Terrainrgb.cpp new file mode 100644 index 0000000..17aea32 --- /dev/null +++ b/src/style/Terrainrgb.cpp @@ -0,0 +1,70 @@ +/* + * Copyright © (2011) Institut national de l'information + * géographique et forestière + * + * Géoportail SAV + * + * This software is a computer program whose purpose is to publish geographic + * data using OGC WMS and WMTS protocol. + * + * This software is governed by the CeCILL-C license under French law and + * abiding by the rules of distribution of free software. You can use, + * modify and/ or redistribute the software under the terms of the CeCILL-C + * license as circulated by CEA, CNRS and INRIA at the following URL + * "http://www.cecill.info". + * + * As a counterpart to the access to the source code and rights to copy, + * modify and redistribute granted by the license, users are provided only + * with a limited warranty and the software's author, the holder of the + * economic rights, and the successive licensors have only limited + * liability. + * + * In this respect, the user's attention is drawn to the risks associated + * with loading, using, modifying and/or developing or reproducing the + * software by the user in light of its specific status of free software, + * that may mean that it is complicated to manipulate, and that also + * therefore means that it is reserved for developers and experienced + * professionals having in-depth computer knowledge. Users are therefore + * encouraged to load and test the software's suitability as regards their + * requirements in conditions enabling the security of their systems and/or + * data to be ensured and, more generally, to use and operate it in the + * same conditions as regards security. + * + * The fact that you are presently reading this means that you have had + * + * knowledge of the CeCILL-C license and that you accept its terms. + */ + +#include "style/Terrainrgb.h" +#include +#include "zlib.h" +#include +#include "byteswap.h" +#include + +Terrainrgb::Terrainrgb(json11::Json doc) : Configuration() +{ + + if (doc["min_elevation"].is_number()) + { + min_elevation = doc["min_elevation"].number_value(); + } + else + { + BOOST_LOG_TRIVIAL(warning) << "Wrong format for terrainrgb, terrainrgb ignored"; + return; + } + if (doc["step"].is_number()) + { + min_elevation = doc["step"].number_value(); + } + else + { + BOOST_LOG_TRIVIAL(warning) << "Wrong format for terrainrgb, terrainrgb ignored"; + return; + } +} + +Terrainrgb::~Terrainrgb() +{ +} From eb4a6467f472f8c7a0f9729762d2609e58a4aa5c Mon Sep 17 00:00:00 2001 From: VincentMiras Date: Tue, 23 Sep 2025 10:31:34 +0200 Subject: [PATCH 02/16] =?UTF-8?q?impl=C3=A9mentation=20de=20TerrainrgbImag?= =?UTF-8?q?e.h/cpp?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- include/rok4/image/TerrainrgbImage.h | 58 +++++++++++++ src/image/TerrainrgbImage.cpp | 123 +++++++++++++++++++++++++++ 2 files changed, 181 insertions(+) create mode 100644 include/rok4/image/TerrainrgbImage.h create mode 100644 src/image/TerrainrgbImage.cpp diff --git a/include/rok4/image/TerrainrgbImage.h b/include/rok4/image/TerrainrgbImage.h new file mode 100644 index 0000000..2a3bab7 --- /dev/null +++ b/include/rok4/image/TerrainrgbImage.h @@ -0,0 +1,58 @@ +/* + * Copyright © (2011) Institut national de l'information + * géographique et forestière + * + * Géoportail SAV + * + * This software is a computer program whose purpose is to publish geographic + * data using OGC WMS and WMTS protocol. + * + * This software is governed by the CeCILL-C license under French law and + * abiding by the rules of distribution of free software. You can use, + * modify and/ or redistribute the software under the terms of the CeCILL-C + * license as circulated by CEA, CNRS and INRIA at the following URL + * "http://www.cecill.info". + * + * As a counterpart to the access to the source code and rights to copy, + * modify and redistribute granted by the license, users are provided only + * with a limited warranty and the software's author, the holder of the + * economic rights, and the successive licensors have only limited + * liability. + * + * In this respect, the user's attention is drawn to the risks associated + * with loading, using, modifying and/or developing or reproducing the + * software by the user in light of its specific status of free software, + * that may mean that it is complicated to manipulate, and that also + * therefore means that it is reserved for developers and experienced + * professionals having in-depth computer knowledge. Users are therefore + * encouraged to load and test the software's suitability as regards their + * requirements in conditions enabling the security of their systems and/or + * data to be ensured and, more generally, to use and operate it in the + * same conditions as regards security. + * + * The fact that you are presently reading this means that you have had + * + * knowledge of the CeCILL-C license and that you accept its terms. + */ + +#pragma once + +#include "rok4/image/Image.h" +#include "rok4/style/Terrainrgb.h" + +class TerrainrgbImage : public Image +{ +private: + Image *source_image; + Terrainrgb *terrainrgb; + + template + int _getline(T *buffer, int line); + +public: + virtual int get_line(float *buffer, int line); + virtual int get_line(uint16_t *buffer, int line); + virtual int get_line(uint8_t *buffer, int line); + TerrainrgbImage(Image *image, Terrainrgb *terrainrgb); + virtual ~TerrainrgbImage(); +}; diff --git a/src/image/TerrainrgbImage.cpp b/src/image/TerrainrgbImage.cpp new file mode 100644 index 0000000..3475a7b --- /dev/null +++ b/src/image/TerrainrgbImage.cpp @@ -0,0 +1,123 @@ +/* + * Copyright © (2011) Institut national de l'information + * géographique et forestière + * + * Géoportail SAV + * + * This software is a computer program whose purpose is to publish geographic + * data using OGC WMS and WMTS protocol. + * + * This software is governed by the CeCILL-C license under French law and + * abiding by the rules of distribution of free software. You can use, + * modify and/ or redistribute the software under the terms of the CeCILL-C + * license as circulated by CEA, CNRS and INRIA at the following URL + * "http://www.cecill.info". + * + * As a counterpart to the access to the source code and rights to copy, + * modify and redistribute granted by the license, users are provided only + * with a limited warranty and the software's author, the holder of the + * economic rights, and the successive licensors have only limited + * liability. + * + * In this respect, the user's attention is drawn to the risks associated + * with loading, using, modifying and/or developing or reproducing the + * software by the user in light of its specific status of free software, + * that may mean that it is complicated to manipulate, and that also + * therefore means that it is reserved for developers and experienced + * professionals having in-depth computer knowledge. Users are therefore + * encouraged to load and test the software's suitability as regards their + * requirements in conditions enabling the security of their systems and/or + * data to be ensured and, more generally, to use and operate it in the + * same conditions as regards security. + * + * The fact that you are presently reading this means that you have had + * + * knowledge of the CeCILL-C license and that you accept its terms. + */ + +#include "image/TerrainrgbImage.h" + +#include +#include "TerrainrgbImage.h" + +int TerrainrgbImage::get_line(float *buffer, int line) +{ + if (source_image->get_channels() == 1) + { + return _getline(buffer, line); + } + else + { + return source_image->get_line(buffer, line); + } +} + +int TerrainrgbImage::get_line(uint16_t *buffer, int line) +{ + if (source_image->get_channels() == 1) + { + return _getline(buffer, line); + } + else + { + return source_image->get_line(buffer, line); + } +} + +int TerrainrgbImage::get_line(uint8_t *buffer, int line) +{ + if (source_image->get_channels() == 1) + { + return _getline(buffer, line); + } + else + { + return source_image->get_line(buffer, line); + } +} + +TerrainrgbImage::TerrainrgbImage(Image *image, Terrainrgb *Terrainrgb) : Image(image->get_width(), image->get_height(), 1, image->get_bbox()), source_image(image) +{ + // Il n'y aura application de la palette et modification des canaux que si + // - la palette n'est pas nulle et pas vide + // - l'image source est sur un canal + if (source_image->get_channels() == 1) + { + channels = 3; + } + else + { + channels = image->get_channels(); + } +} + +TerrainrgbImage::~TerrainrgbImage() +{ + delete source_image; +} + +template +int TerrainrgbImage::_getline(T *buffer, int line) +{ + float *source = new float[source_image->get_width() * source_image->get_channels()]; + source_image->get_line(source, line); + switch (channels) + { + + case 3: + for (int i = 0; i < source_image->get_width(); i++) + { + int base = *buffer + terrainrgb->min_elevation / terrainrgb->step; + int red = abs(base / (256 * 256)) % 256; + int green = abs((base - red * 256 * 256) / 256) % 256; + int blue = abs(base - red * 256 * 256 - green * 256); + *(buffer + i * 3) = red; + *(buffer + i * 3 + 1) = green; + *(buffer + i * 3 + 2) = blue; + } + break; + } + + delete[] source; + return width * sizeof(T) * channels; +} From f62c3688779d8964dbc91a4b06fd736e021b8a93 Mon Sep 17 00:00:00 2001 From: VincentMiras Date: Tue, 23 Sep 2025 11:05:36 +0200 Subject: [PATCH 03/16] =?UTF-8?q?D=C3=A9bug=20probl=C3=A8me=20=C3=A0=20la?= =?UTF-8?q?=20compilation?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- include/rok4/style/Terrainrgb.h | 3 +-- src/image/TerrainrgbImage.cpp | 1 - 2 files changed, 1 insertion(+), 3 deletions(-) diff --git a/include/rok4/style/Terrainrgb.h b/include/rok4/style/Terrainrgb.h index 65bb53c..fbb8761 100644 --- a/include/rok4/style/Terrainrgb.h +++ b/include/rok4/style/Terrainrgb.h @@ -46,7 +46,7 @@ class Terrainrgb : public Configuration { -private: +public: /** \~french * \brief min_elevation : élévation minimale à partir de laquelle est calculée la couleur ** \~english @@ -61,7 +61,6 @@ class Terrainrgb : public Configuration */ float step; -public: /** * \~french * \brief Constructeurs avec des arguments diff --git a/src/image/TerrainrgbImage.cpp b/src/image/TerrainrgbImage.cpp index 3475a7b..948ad13 100644 --- a/src/image/TerrainrgbImage.cpp +++ b/src/image/TerrainrgbImage.cpp @@ -38,7 +38,6 @@ #include "image/TerrainrgbImage.h" #include -#include "TerrainrgbImage.h" int TerrainrgbImage::get_line(float *buffer, int line) { From bebe28dbda3923b4206c6c466d9efaa1a18d47e0 Mon Sep 17 00:00:00 2001 From: VincentMiras Date: Tue, 23 Sep 2025 11:11:43 +0200 Subject: [PATCH 04/16] =?UTF-8?q?mise=20=C3=A0=20jour=20changelog?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- CHANGELOG.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 6953392..6e9362e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,10 @@ Le format est basé sur [Keep a Changelog](https://keepachangelog.com/) et ce pr ## [Unreleased] ### Added + +- `Terrainrgb` : Ajout d'un style terrainrgb pour transformer les MNT en format Terrain RGB. +- `TerrainrgbImage` : Ajout du processus de traitement du style Terrainrgb. + ### Changed ### Deprecated ### Removed From 28dc457fab02d9388c39c10d18a89c9f6d74e87c Mon Sep 17 00:00:00 2001 From: VincentMiras Date: Tue, 23 Sep 2025 14:37:25 +0200 Subject: [PATCH 05/16] Adapt style.h/cpp to admit terrainrgb --- include/rok4/style/Style.h | 6 ++++++ src/image/TerrainrgbImage.cpp | 3 --- src/style/Style.cpp | 18 +++++++++++++++--- 3 files changed, 21 insertions(+), 6 deletions(-) diff --git a/include/rok4/style/Style.h b/include/rok4/style/Style.h index 766a22d..07e5fe2 100644 --- a/include/rok4/style/Style.h +++ b/include/rok4/style/Style.h @@ -55,6 +55,7 @@ class Style; #include "rok4/style/Pente.h" #include "rok4/style/Estompage.h" #include "rok4/style/Aspect.h" +#include "rok4/style/Terrainrgb.h" #include "rok4/enums/Interpolation.h" #include "rok4/utils/Configuration.h" #include "rok4/enums/Format.h" @@ -162,6 +163,11 @@ private : * \~english \brief Define wether the server must compute a relief shadow */ Estompage* estompage; + /** + * \~french \brief Définit si un terrainrgb doit être appliqué + * \~english \brief Define wether the server must compute a RGB terrain + */ + Terrainrgb* terrainrgb; /** * \~french \brief Valeur de nodata attendue dans les données en entrée diff --git a/src/image/TerrainrgbImage.cpp b/src/image/TerrainrgbImage.cpp index 948ad13..db73f02 100644 --- a/src/image/TerrainrgbImage.cpp +++ b/src/image/TerrainrgbImage.cpp @@ -77,9 +77,6 @@ int TerrainrgbImage::get_line(uint8_t *buffer, int line) TerrainrgbImage::TerrainrgbImage(Image *image, Terrainrgb *Terrainrgb) : Image(image->get_width(), image->get_height(), 1, image->get_bbox()), source_image(image) { - // Il n'y aura application de la palette et modification des canaux que si - // - la palette n'est pas nulle et pas vide - // - l'image source est sur un canal if (source_image->get_channels() == 1) { channels = 3; diff --git a/src/style/Style.cpp b/src/style/Style.cpp index fd2c65c..9266bed 100644 --- a/src/style/Style.cpp +++ b/src/style/Style.cpp @@ -62,6 +62,7 @@ bool Style::parse(json11::Json& doc) { aspect = 0; estompage = 0; palette = 0; + terrainrgb = 0; input_nodata_value = NULL; output_nodata_value = NULL; @@ -106,10 +107,13 @@ bool Style::parse(json11::Json& doc) { legends.push_back(leg); } - palette = new Palette(doc["palette"].object_items()); - if (! palette->is_ok()) { - error_message = "Palette issue for style " + id + ": " + palette->get_error_message(); + if (doc["palette"].is_object()){ + palette = new Palette(doc["palette"].object_items()); + if (! palette->is_ok()) { + BOOST_LOG_TRIVIAL(warning) << "Palette"; + error_message = "Palette issue for style " + id + ": " + palette->get_error_message(); return false; + } } if (doc["estompage"].is_object()) { @@ -144,6 +148,14 @@ bool Style::parse(json11::Json& doc) { } } + if (doc["terrainrgb"].is_object()) { + terrainrgb = new Terrainrgb(doc["terrainrgb"].object_items()); + if (! terrainrgb->is_ok() || palette->is_ok()) { + error_message = "Terrainrgb issue for style " + id + ": " + terrainrgb->get_error_message(); + return false; + } + } + return true; } From ff85f0f62412b68940772c066625d346dcb61d6e Mon Sep 17 00:00:00 2001 From: VincentMiras Date: Tue, 23 Sep 2025 17:37:26 +0200 Subject: [PATCH 06/16] ajout d'une valuer en cas de nodata --- include/rok4/style/Terrainrgb.h | 7 +++++++ src/style/Terrainrgb.cpp | 2 +- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/include/rok4/style/Terrainrgb.h b/include/rok4/style/Terrainrgb.h index fbb8761..e4cb7b2 100644 --- a/include/rok4/style/Terrainrgb.h +++ b/include/rok4/style/Terrainrgb.h @@ -61,6 +61,13 @@ class Terrainrgb : public Configuration */ float step; + /** \~french + * \brief noData : valeur de nodata pour l'image source + ** \~english + * \brief noData : value of nodata for the source image + */ + float input_nodata_value; + /** * \~french * \brief Constructeurs avec des arguments diff --git a/src/style/Terrainrgb.cpp b/src/style/Terrainrgb.cpp index 17aea32..8f14d36 100644 --- a/src/style/Terrainrgb.cpp +++ b/src/style/Terrainrgb.cpp @@ -42,7 +42,7 @@ #include "byteswap.h" #include -Terrainrgb::Terrainrgb(json11::Json doc) : Configuration() +Terrainrgb::Terrainrgb(json11::Json doc) : Configuration(), input_nodata_value (-99999) { if (doc["min_elevation"].is_number()) From 84797eeb7d52102a16bbe150b15079cc6fa45478 Mon Sep 17 00:00:00 2001 From: VincentMiras Date: Wed, 24 Sep 2025 15:13:33 +0200 Subject: [PATCH 07/16] =?UTF-8?q?Ajout=20gestion=20de=20nodata=20qui=20cr?= =?UTF-8?q?=C3=A9ait=20une=20erreur=20de=20segmentation=20et=20nettoyage?= =?UTF-8?q?=20du=20code?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- include/rok4/style/Style.h | 23 ++++++++++++++++++++++- include/rok4/style/Terrainrgb.h | 7 +++++++ src/style/Style.cpp | 19 +++++++++++++++---- src/style/Terrainrgb.cpp | 2 +- 4 files changed, 45 insertions(+), 6 deletions(-) diff --git a/include/rok4/style/Style.h b/include/rok4/style/Style.h index 07e5fe2..387d954 100644 --- a/include/rok4/style/Style.h +++ b/include/rok4/style/Style.h @@ -298,7 +298,7 @@ private : return false; } - if (estompage_defined() || pente_defined() || aspect_defined()) { + if (estompage_defined() || pente_defined() || aspect_defined() || terrainrgb_defined()) { return false; } else { return true; @@ -427,6 +427,27 @@ private : inline Aspect* get_aspect() { return aspect; } + + /** + * \~french + * \brief Return vrai si le style est un terrainrgb + * \return bool + * \~english + * \brief Return true if the style is an rgb terrain + * \return bool + */ + inline bool terrainrgb_defined() { + return (terrainrgb != 0); + } + /** + * \~french + * \brief Retourne le terrainrgb + * \~english + * \brief Return rgb terrain + */ + inline Terrainrgb* get_terrainrgb() { + return terrainrgb; + } /** diff --git a/include/rok4/style/Terrainrgb.h b/include/rok4/style/Terrainrgb.h index e4cb7b2..cd6bcd5 100644 --- a/include/rok4/style/Terrainrgb.h +++ b/include/rok4/style/Terrainrgb.h @@ -68,6 +68,13 @@ class Terrainrgb : public Configuration */ float input_nodata_value; + /** \~french + * \brief noData : valeur de nodata pour l'image source + ** \~english + * \brief noData : value of nodata for the source image + */ + float terrainrgb_nodata_value; + /** * \~french * \brief Constructeurs avec des arguments diff --git a/src/style/Style.cpp b/src/style/Style.cpp index 9266bed..2b84428 100644 --- a/src/style/Style.cpp +++ b/src/style/Style.cpp @@ -110,7 +110,6 @@ bool Style::parse(json11::Json& doc) { if (doc["palette"].is_object()){ palette = new Palette(doc["palette"].object_items()); if (! palette->is_ok()) { - BOOST_LOG_TRIVIAL(warning) << "Palette"; error_message = "Palette issue for style " + id + ": " + palette->get_error_message(); return false; } @@ -150,12 +149,11 @@ bool Style::parse(json11::Json& doc) { if (doc["terrainrgb"].is_object()) { terrainrgb = new Terrainrgb(doc["terrainrgb"].object_items()); - if (! terrainrgb->is_ok() || palette->is_ok()) { + if (! terrainrgb->is_ok()) { error_message = "Terrainrgb issue for style " + id + ": " + terrainrgb->get_error_message(); return false; } } - return true; } @@ -165,6 +163,7 @@ Style::Style ( std::string path ) : Configuration(path) { estompage = 0; palette = 0; aspect = 0; + terrainrgb = 0; input_nodata_value = NULL; output_nodata_value = NULL; @@ -231,7 +230,12 @@ Style::Style ( std::string path ) : Configuration(path) { else if (pente_defined()) { input_nodata_value = new int[1]; input_nodata_value[0] = (int) pente->input_nodata_value; - } + } + else if (terrainrgb_defined()) { + input_nodata_value = new int[1]; + input_nodata_value[0] = (int) terrainrgb->input_nodata_value; + return; + } else if (palette && ! palette->is_empty()) { input_nodata_value = new int[1]; input_nodata_value[0] = (int) palette->get_colours_map()->begin()->first; @@ -265,6 +269,10 @@ Style::Style ( std::string path ) : Configuration(path) { output_nodata_value = new int[1]; output_nodata_value[0] = (int) pente->slope_nodata_value; } + else if (terrainrgb_defined()) { + output_nodata_value = new int[1]; + output_nodata_value[0] = (int) terrainrgb->terrainrgb_nodata_value; + } } Style::~Style() { @@ -280,6 +288,9 @@ Style::~Style() { if (aspect != 0) { delete aspect; } + if (terrainrgb != 0) { + delete terrainrgb; + } if (input_nodata_value != NULL) { delete[] input_nodata_value; } diff --git a/src/style/Terrainrgb.cpp b/src/style/Terrainrgb.cpp index 8f14d36..25e4e33 100644 --- a/src/style/Terrainrgb.cpp +++ b/src/style/Terrainrgb.cpp @@ -42,7 +42,7 @@ #include "byteswap.h" #include -Terrainrgb::Terrainrgb(json11::Json doc) : Configuration(), input_nodata_value (-99999) +Terrainrgb::Terrainrgb(json11::Json doc) : Configuration(), input_nodata_value (-99999), terrainrgb_nodata_value(-10000) { if (doc["min_elevation"].is_number()) From 472b30875e68aea20c58b0ebe64a45ad926437b0 Mon Sep 17 00:00:00 2001 From: VincentMiras Date: Wed, 24 Sep 2025 17:41:40 +0200 Subject: [PATCH 08/16] =?UTF-8?q?Suppression=20d'un=20return=20qui=20cassa?= =?UTF-8?q?it=20le=20processus=20au=20milieu=20en=20cas=20de=20terrainrgb?= =?UTF-8?q?=20et=20retour=20en=20arri=C3=A8re=20sur=20un=20test=20inutile?= =?UTF-8?q?=20pour=20palette?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/style/Style.cpp | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/src/style/Style.cpp b/src/style/Style.cpp index 2b84428..5446fa8 100644 --- a/src/style/Style.cpp +++ b/src/style/Style.cpp @@ -107,12 +107,10 @@ bool Style::parse(json11::Json& doc) { legends.push_back(leg); } - if (doc["palette"].is_object()){ - palette = new Palette(doc["palette"].object_items()); - if (! palette->is_ok()) { - error_message = "Palette issue for style " + id + ": " + palette->get_error_message(); - return false; - } + palette = new Palette(doc["palette"].object_items()); + if (! palette->is_ok()) { + error_message = "Palette issue for style " + id + ": " + palette->get_error_message(); + return false; } if (doc["estompage"].is_object()) { @@ -234,7 +232,6 @@ Style::Style ( std::string path ) : Configuration(path) { else if (terrainrgb_defined()) { input_nodata_value = new int[1]; input_nodata_value[0] = (int) terrainrgb->input_nodata_value; - return; } else if (palette && ! palette->is_empty()) { input_nodata_value = new int[1]; From fb2a9d4bfc696abae673fb3c12b16f9b37140b0c Mon Sep 17 00:00:00 2001 From: VincentMiras Date: Tue, 30 Sep 2025 10:45:47 +0200 Subject: [PATCH 09/16] traitement de l'image correct --- include/rok4/style/Style.h | 11 +++++++--- src/image/TerrainrgbImage.cpp | 39 +++++++++++++++++------------------ src/style/Style.cpp | 6 ++++-- src/style/Terrainrgb.cpp | 11 +++++----- 4 files changed, 36 insertions(+), 31 deletions(-) diff --git a/include/rok4/style/Style.h b/include/rok4/style/Style.h index 387d954..0e560dd 100644 --- a/include/rok4/style/Style.h +++ b/include/rok4/style/Style.h @@ -225,7 +225,7 @@ private : * \~english \brief Style is allowed ? */ bool handle (int spp) { - if (estompage_defined() || pente_defined() || aspect_defined()) { + if (estompage_defined() || pente_defined() || aspect_defined() || terrainrgb_defined()) { return (spp == 1); } else { return true; @@ -243,7 +243,11 @@ private : } else { return 4; } - } else { + } + else if (terrainrgb_defined()){ + return 3; + } + else { if (estompage_defined() || pente_defined() || aspect_defined()) { return 1; } else { @@ -251,6 +255,7 @@ private : return orig_channels; } } + } /** @@ -258,7 +263,7 @@ private : * \~english \brief Which sample format after style */ SampleFormat::eSampleFormat get_sample_format (SampleFormat::eSampleFormat sf) { - if (palette && ! palette->is_empty()) { + if ((palette && ! palette->is_empty()) || terrainrgb_defined()) { return SampleFormat::UINT8; } else { return sf; diff --git a/src/image/TerrainrgbImage.cpp b/src/image/TerrainrgbImage.cpp index db73f02..1d2d3a8 100644 --- a/src/image/TerrainrgbImage.cpp +++ b/src/image/TerrainrgbImage.cpp @@ -75,7 +75,7 @@ int TerrainrgbImage::get_line(uint8_t *buffer, int line) } } -TerrainrgbImage::TerrainrgbImage(Image *image, Terrainrgb *Terrainrgb) : Image(image->get_width(), image->get_height(), 1, image->get_bbox()), source_image(image) +TerrainrgbImage::TerrainrgbImage(Image *image, Terrainrgb *terrainrgb) : Image(image->get_width(), image->get_height(), 1, image->get_bbox()), source_image(image), terrainrgb(terrainrgb) { if (source_image->get_channels() == 1) { @@ -85,35 +85,34 @@ TerrainrgbImage::TerrainrgbImage(Image *image, Terrainrgb *Terrainrgb) : Image(i { channels = image->get_channels(); } -} +} TerrainrgbImage::~TerrainrgbImage() { delete source_image; } -template -int TerrainrgbImage::_getline(T *buffer, int line) -{ - float *source = new float[source_image->get_width() * source_image->get_channels()]; - source_image->get_line(source, line); - switch (channels) - { - +template +int TerrainrgbImage::_getline ( T* buffer, int line ) { + float* source = new float[source_image->get_width() * source_image->get_channels()]; + source_image->get_line ( source, line ); + switch ( channels ) { case 3: - for (int i = 0; i < source_image->get_width(); i++) - { - int base = *buffer + terrainrgb->min_elevation / terrainrgb->step; - int red = abs(base / (256 * 256)) % 256; - int green = abs((base - red * 256 * 256) / 256) % 256; - int blue = abs(base - red * 256 * 256 - green * 256); - *(buffer + i * 3) = red; - *(buffer + i * 3 + 1) = green; - *(buffer + i * 3 + 2) = blue; + for (int i = 0; i < source_image->get_width() ; i++ ) { + + int base = (std::max((T) *(source+i), (T) terrainrgb->min_elevation) - terrainrgb->min_elevation) / terrainrgb->step; + int red = (base / (256 * 256) % 256); + int green = ((base - red * 256 * 256) / 256 % 256); + int blue = (base - red * 256 * 256 - green * 256); + * ( buffer+i*3 ) = (T) red; + * ( buffer+i*3+1 ) = (T) green; + * ( buffer+i*3+2 ) = (T) blue; } break; } + + delete[] source; - return width * sizeof(T) * channels; + return width * sizeof ( T ) * channels; } diff --git a/src/style/Style.cpp b/src/style/Style.cpp index 5446fa8..2b4535a 100644 --- a/src/style/Style.cpp +++ b/src/style/Style.cpp @@ -267,8 +267,10 @@ Style::Style ( std::string path ) : Configuration(path) { output_nodata_value[0] = (int) pente->slope_nodata_value; } else if (terrainrgb_defined()) { - output_nodata_value = new int[1]; - output_nodata_value[0] = (int) terrainrgb->terrainrgb_nodata_value; + output_nodata_value = new int[3]; + output_nodata_value[0] = 0; + output_nodata_value[1] = 0; + output_nodata_value[2] = 0; } } diff --git a/src/style/Terrainrgb.cpp b/src/style/Terrainrgb.cpp index 25e4e33..1fdbff3 100644 --- a/src/style/Terrainrgb.cpp +++ b/src/style/Terrainrgb.cpp @@ -42,7 +42,7 @@ #include "byteswap.h" #include -Terrainrgb::Terrainrgb(json11::Json doc) : Configuration(), input_nodata_value (-99999), terrainrgb_nodata_value(-10000) +Terrainrgb::Terrainrgb(json11::Json doc) : Configuration() { if (doc["min_elevation"].is_number()) @@ -51,18 +51,17 @@ Terrainrgb::Terrainrgb(json11::Json doc) : Configuration(), input_nodata_value ( } else { - BOOST_LOG_TRIVIAL(warning) << "Wrong format for terrainrgb, terrainrgb ignored"; - return; + min_elevation = -10000; } if (doc["step"].is_number()) { - min_elevation = doc["step"].number_value(); + step = doc["step"].number_value(); } else { - BOOST_LOG_TRIVIAL(warning) << "Wrong format for terrainrgb, terrainrgb ignored"; - return; + step = 0.1; } + input_nodata_value=min_elevation; } Terrainrgb::~Terrainrgb() From 70a31342d5ca0efb2b1ea5cc667645eec74c1ee0 Mon Sep 17 00:00:00 2001 From: VincentMiras Date: Tue, 30 Sep 2025 13:53:45 +0200 Subject: [PATCH 10/16] =?UTF-8?q?Ajout=20de=20contrainte=20sur=20les=20con?= =?UTF-8?q?ditions=20d'un=20style=20terrainrgb=20et=20ajout=20d'un=20test?= =?UTF-8?q?=20avant=20la=20cr=C3=A9ation=20d'une=20palette?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/style/Style.cpp | 24 +++++++++++++++--------- 1 file changed, 15 insertions(+), 9 deletions(-) diff --git a/src/style/Style.cpp b/src/style/Style.cpp index 2b4535a..7b6e7f5 100644 --- a/src/style/Style.cpp +++ b/src/style/Style.cpp @@ -107,10 +107,12 @@ bool Style::parse(json11::Json& doc) { legends.push_back(leg); } - palette = new Palette(doc["palette"].object_items()); - if (! palette->is_ok()) { - error_message = "Palette issue for style " + id + ": " + palette->get_error_message(); - return false; + if (doc["palette"].is_object()) { + palette = new Palette(doc["palette"].object_items()); + if (! palette->is_ok()) { + error_message = "Palette issue for style " + id + ": " + palette->get_error_message(); + return false; + } } if (doc["estompage"].is_object()) { @@ -146,6 +148,10 @@ bool Style::parse(json11::Json& doc) { } if (doc["terrainrgb"].is_object()) { + if (estompage != 0 || pente != 0 || aspect !=0 || palette !=0) { + error_message = "Style " + id + " define exposition, estompage, pente or palette rules"; + return false; + } terrainrgb = new Terrainrgb(doc["terrainrgb"].object_items()); if (! terrainrgb->is_ok()) { error_message = "Terrainrgb issue for style " + id + ": " + terrainrgb->get_error_message(); @@ -255,8 +261,8 @@ Style::Style ( std::string path ) : Configuration(path) { } } else if (estompage_defined()) { - output_nodata_value = new int[1]; - output_nodata_value[0] = (int) estompage->estompage_nodata_value; + output_nodata_value = new int[1]; + output_nodata_value[0] = (int) estompage->estompage_nodata_value; } else if (aspect_defined()) { output_nodata_value = new int[1]; @@ -268,9 +274,9 @@ Style::Style ( std::string path ) : Configuration(path) { } else if (terrainrgb_defined()) { output_nodata_value = new int[3]; - output_nodata_value[0] = 0; - output_nodata_value[1] = 0; - output_nodata_value[2] = 0; + output_nodata_value[0] = 0; + output_nodata_value[1] = 0; + output_nodata_value[2] = 0; } } From 095e1f93e7d1a8e4c0ebc99d2ee2018054d4515c Mon Sep 17 00:00:00 2001 From: VincentMiras Date: Tue, 30 Sep 2025 13:54:05 +0200 Subject: [PATCH 11/16] Ajout fonction palette_defined() --- include/rok4/style/Style.h | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/include/rok4/style/Style.h b/include/rok4/style/Style.h index 0e560dd..2a118f2 100644 --- a/include/rok4/style/Style.h +++ b/include/rok4/style/Style.h @@ -358,6 +358,17 @@ private : return &legends; } + /** + * \~french + * \brief Détermine si le style décrit une table de correspondance + * \return true si oui + * \~english + * \brief Determine if the style describe a lookup table + * \return true if it does + */ + inline bool palette_defined() { + return (palette != 0); + } /** * \~french * \brief Retourne la table de correspondance From 5d8509f4f2bd8bf8ac91eeb513acafde1d010482 Mon Sep 17 00:00:00 2001 From: VincentMiras Date: Tue, 30 Sep 2025 14:41:30 +0200 Subject: [PATCH 12/16] Ajout de commentaire et format du code --- include/rok4/style/Style.h | 2 +- include/rok4/style/Terrainrgb.h | 8 +++--- src/image/TerrainrgbImage.cpp | 47 +++++++++++---------------------- src/style/Terrainrgb.cpp | 17 ++++-------- 4 files changed, 25 insertions(+), 49 deletions(-) diff --git a/include/rok4/style/Style.h b/include/rok4/style/Style.h index 2a118f2..f41a2a5 100644 --- a/include/rok4/style/Style.h +++ b/include/rok4/style/Style.h @@ -164,7 +164,7 @@ private : */ Estompage* estompage; /** - * \~french \brief Définit si un terrainrgb doit être appliqué + * \~french \brief Définit si un calcul de terrainrgb doit être appliqué * \~english \brief Define wether the server must compute a RGB terrain */ Terrainrgb* terrainrgb; diff --git a/include/rok4/style/Terrainrgb.h b/include/rok4/style/Terrainrgb.h index cd6bcd5..42abeba 100644 --- a/include/rok4/style/Terrainrgb.h +++ b/include/rok4/style/Terrainrgb.h @@ -55,9 +55,9 @@ class Terrainrgb : public Configuration int min_elevation; /** \~french - * \brief step : écart d'altitude entre deux couleurs différentes + * \brief step : résolution verticale ** \~english - * \brief step : altitude difference between two different colors + * \brief step : vertical resolution */ float step; @@ -69,9 +69,9 @@ class Terrainrgb : public Configuration float input_nodata_value; /** \~french - * \brief noData : valeur de nodata pour l'image source + * \brief noData : valeur de nodata pour le terrainrgb ** \~english - * \brief noData : value of nodata for the source image + * \brief noData : value of nodata for the RGB terrain */ float terrainrgb_nodata_value; diff --git a/src/image/TerrainrgbImage.cpp b/src/image/TerrainrgbImage.cpp index 1d2d3a8..fb688c7 100644 --- a/src/image/TerrainrgbImage.cpp +++ b/src/image/TerrainrgbImage.cpp @@ -39,56 +39,39 @@ #include -int TerrainrgbImage::get_line(float *buffer, int line) -{ - if (source_image->get_channels() == 1) - { +int TerrainrgbImage::get_line(float *buffer, int line) { + if (source_image->get_channels() == 1) { return _getline(buffer, line); - } - else - { + } else { return source_image->get_line(buffer, line); } } -int TerrainrgbImage::get_line(uint16_t *buffer, int line) -{ - if (source_image->get_channels() == 1) - { +int TerrainrgbImage::get_line(uint16_t *buffer, int line) { + if (source_image->get_channels() == 1) { return _getline(buffer, line); - } - else - { + } else { return source_image->get_line(buffer, line); } } -int TerrainrgbImage::get_line(uint8_t *buffer, int line) -{ - if (source_image->get_channels() == 1) - { +int TerrainrgbImage::get_line(uint8_t *buffer, int line) { + if (source_image->get_channels() == 1) { return _getline(buffer, line); - } - else - { + } else { return source_image->get_line(buffer, line); } } -TerrainrgbImage::TerrainrgbImage(Image *image, Terrainrgb *terrainrgb) : Image(image->get_width(), image->get_height(), 1, image->get_bbox()), source_image(image), terrainrgb(terrainrgb) -{ - if (source_image->get_channels() == 1) - { +TerrainrgbImage::TerrainrgbImage(Image *image, Terrainrgb *terrainrgb) : Image(image->get_width(), image->get_height(), 1, image->get_bbox()), source_image(image), terrainrgb(terrainrgb) { + if (source_image->get_channels() == 1) { channels = 3; - } - else - { + } else { channels = image->get_channels(); } } -TerrainrgbImage::~TerrainrgbImage() -{ +TerrainrgbImage::~TerrainrgbImage() { delete source_image; } @@ -100,10 +83,12 @@ int TerrainrgbImage::_getline ( T* buffer, int line ) { case 3: for (int i = 0; i < source_image->get_width() ; i++ ) { + // découpage de l'altitude en RGB suivant la formule suivante : height = min_elevation + ((Red * 256 * 256 + Green * 256 + Blue) * step) int base = (std::max((T) *(source+i), (T) terrainrgb->min_elevation) - terrainrgb->min_elevation) / terrainrgb->step; int red = (base / (256 * 256) % 256); int green = ((base - red * 256 * 256) / 256 % 256); int blue = (base - red * 256 * 256 - green * 256); + * ( buffer+i*3 ) = (T) red; * ( buffer+i*3+1 ) = (T) green; * ( buffer+i*3+2 ) = (T) blue; @@ -111,8 +96,6 @@ int TerrainrgbImage::_getline ( T* buffer, int line ) { break; } - - delete[] source; return width * sizeof ( T ) * channels; } diff --git a/src/style/Terrainrgb.cpp b/src/style/Terrainrgb.cpp index 1fdbff3..ee64347 100644 --- a/src/style/Terrainrgb.cpp +++ b/src/style/Terrainrgb.cpp @@ -45,25 +45,18 @@ Terrainrgb::Terrainrgb(json11::Json doc) : Configuration() { - if (doc["min_elevation"].is_number()) - { + if (doc["min_elevation"].is_number()) { min_elevation = doc["min_elevation"].number_value(); - } - else - { + } else { min_elevation = -10000; } - if (doc["step"].is_number()) - { + if (doc["step"].is_number()) { step = doc["step"].number_value(); - } - else - { + } else { step = 0.1; } input_nodata_value=min_elevation; } -Terrainrgb::~Terrainrgb() -{ +Terrainrgb::~Terrainrgb() { } From 8bac916924b3a83bec143bbe5765b75edb616005 Mon Sep 17 00:00:00 2001 From: VincentMiras Date: Tue, 30 Sep 2025 14:55:49 +0200 Subject: [PATCH 13/16] =?UTF-8?q?Mise=20=C3=A0=20jour=20changelog?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- CHANGELOG.md | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 6e9362e..d2d02f7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,8 +10,13 @@ Le format est basé sur [Keep a Changelog](https://keepachangelog.com/) et ce pr - `Terrainrgb` : Ajout d'un style terrainrgb pour transformer les MNT en format Terrain RGB. - `TerrainrgbImage` : Ajout du processus de traitement du style Terrainrgb. +- `Style` : Ajout d'une fonction permettant de savoir si une palette existe ou non. +- Ajout du traitement en cas de style terrainrgb. Il doit être l'unique style déclaré pour fonctionner. ### Changed + +- `Style` : Vérification de l'existance d'un bloc palette dans le json de style avant la création d'un objet palette. Ce changement nécessite la vérification de l'existance d'une palette qui n'était pas vérifié avant. + ### Deprecated ### Removed ### Fixed From 2eaf5b41e947fb6aa94eb1c3250801056b9f3fa3 Mon Sep 17 00:00:00 2001 From: VincentMiras Date: Tue, 30 Sep 2025 15:27:25 +0200 Subject: [PATCH 14/16] Documentation global des fichiers --- include/rok4/image/TerrainrgbImage.h | 8 ++++++++ include/rok4/style/Terrainrgb.h | 9 +++++++++ src/image/TerrainrgbImage.cpp | 7 +++++++ src/style/Terrainrgb.cpp | 8 ++++++++ 4 files changed, 32 insertions(+) diff --git a/include/rok4/image/TerrainrgbImage.h b/include/rok4/image/TerrainrgbImage.h index 2a3bab7..dcd333a 100644 --- a/include/rok4/image/TerrainrgbImage.h +++ b/include/rok4/image/TerrainrgbImage.h @@ -35,6 +35,14 @@ * knowledge of the CeCILL-C license and that you accept its terms. */ +/** + * \file TerrainrgbImage.h + ** \~french + * \brief D�finition de la classe TerrainrgbImage + ** \~english + * \brief Define class TerrainrgbImage + */ + #pragma once #include "rok4/image/Image.h" diff --git a/include/rok4/style/Terrainrgb.h b/include/rok4/style/Terrainrgb.h index 42abeba..e809229 100644 --- a/include/rok4/style/Terrainrgb.h +++ b/include/rok4/style/Terrainrgb.h @@ -35,6 +35,15 @@ * knowledge of the CeCILL-C license and that you accept its terms. */ + /** + * \file Terrainrgb.h + ** \~french + * \brief D�finition de la classe Terrainrgb + ** \~english + * \brief Define class Terrainrgb + */ + + #pragma once #include "rok4/utils/Configuration.h" diff --git a/src/image/TerrainrgbImage.cpp b/src/image/TerrainrgbImage.cpp index fb688c7..b1178e6 100644 --- a/src/image/TerrainrgbImage.cpp +++ b/src/image/TerrainrgbImage.cpp @@ -35,6 +35,13 @@ * knowledge of the CeCILL-C license and that you accept its terms. */ + /** + * \file TerrainrgbImage.cpp + * \~french + * \brief Implémentation de la classe TerrainrgbImage permettant l'application du terrainrgb à une image. + * \~english + * \brief Implement the TerrainrgbImage Class handling computing of Terrainrgb style to an image. + */ #include "image/TerrainrgbImage.h" #include diff --git a/src/style/Terrainrgb.cpp b/src/style/Terrainrgb.cpp index ee64347..e81eb8a 100644 --- a/src/style/Terrainrgb.cpp +++ b/src/style/Terrainrgb.cpp @@ -35,6 +35,14 @@ * knowledge of the CeCILL-C license and that you accept its terms. */ + /** + * \file Terrainrgb.cpp + * \~french + * \brief Implémentation de la classe Terrainrgb modélisant un terrainrgb. + * \~english + * \brief Implement the Terrainrgb Class handling terrainrgb definition. + */ + #include "style/Terrainrgb.h" #include #include "zlib.h" From 7558d2daee73fca94d309062e5d4e73597eda306 Mon Sep 17 00:00:00 2001 From: VincentMiras Date: Tue, 30 Sep 2025 15:34:33 +0200 Subject: [PATCH 15/16] Correction faute documentation --- src/style/Terrainrgb.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/style/Terrainrgb.cpp b/src/style/Terrainrgb.cpp index e81eb8a..c0992d8 100644 --- a/src/style/Terrainrgb.cpp +++ b/src/style/Terrainrgb.cpp @@ -40,7 +40,7 @@ * \~french * \brief Implémentation de la classe Terrainrgb modélisant un terrainrgb. * \~english - * \brief Implement the Terrainrgb Class handling terrainrgb definition. + * \brief Implement the Terrainrgb Class handling RGB terrain definition. */ #include "style/Terrainrgb.h" From 90a50b5774ec2d73849f5099c67aa25d6905645c Mon Sep 17 00:00:00 2001 From: VincentMiras Date: Tue, 30 Sep 2025 15:43:46 +0200 Subject: [PATCH 16/16] =?UTF-8?q?Mise=20=C3=A0=20jour=20du=20changelog?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- CHANGELOG.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index d2d02f7..031f648 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -14,12 +14,12 @@ Le format est basé sur [Keep a Changelog](https://keepachangelog.com/) et ce pr - Ajout du traitement en cas de style terrainrgb. Il doit être l'unique style déclaré pour fonctionner. ### Changed - -- `Style` : Vérification de l'existance d'un bloc palette dans le json de style avant la création d'un objet palette. Ce changement nécessite la vérification de l'existance d'une palette qui n'était pas vérifié avant. - ### Deprecated ### Removed ### Fixed + +- `Style` : Vérification de l'existance d'un bloc palette dans le json de style avant la création d'un objet palette. Ce changement nécessite la vérification de l'existance d'une palette qui n'était pas vérifié avant. + ### Security ## [2.0.6] - 2025-09-11