From 15aecc1ab049c91545861dd73e549dbae64df121 Mon Sep 17 00:00:00 2001
From: Victor Poughon <victor.poughon@cnes.fr>
Date: Wed, 24 Apr 2019 14:17:22 +0200
Subject: [PATCH] DOC: review BandMathFilterExample

---
 Data/Input/qb_ExtractRoad_pretty.png          |  3 ++
 Data/Output/qb_BandMath-pretty.jpg            |  3 ++
 .../BasicFilters/BandMathFilterExample.cxx    | 50 ++++---------------
 .../BasicFilters/BandMathFilterExample.rst    | 27 ++++++++++
 4 files changed, 42 insertions(+), 41 deletions(-)
 create mode 100644 Data/Input/qb_ExtractRoad_pretty.png
 create mode 100644 Data/Output/qb_BandMath-pretty.jpg
 create mode 100644 Examples/BasicFilters/BandMathFilterExample.rst

diff --git a/Data/Input/qb_ExtractRoad_pretty.png b/Data/Input/qb_ExtractRoad_pretty.png
new file mode 100644
index 0000000000..d4307ec6f7
--- /dev/null
+++ b/Data/Input/qb_ExtractRoad_pretty.png
@@ -0,0 +1,3 @@
+version https://git-lfs.github.com/spec/v1
+oid sha256:7a01fe4d41a060407d2613ba9595fde7321aa77c6e44f6552bb83d77d0dcef34
+size 1334929
diff --git a/Data/Output/qb_BandMath-pretty.jpg b/Data/Output/qb_BandMath-pretty.jpg
new file mode 100644
index 0000000000..bd7702f79d
--- /dev/null
+++ b/Data/Output/qb_BandMath-pretty.jpg
@@ -0,0 +1,3 @@
+version https://git-lfs.github.com/spec/v1
+oid sha256:280cbf6de4cfc271371df94f79bdef1b6fb5089225e0d5105a6ad494ae7be89e
+size 67381
diff --git a/Examples/BasicFilters/BandMathFilterExample.cxx b/Examples/BasicFilters/BandMathFilterExample.cxx
index 7404742ba2..98d13618c6 100644
--- a/Examples/BasicFilters/BandMathFilterExample.cxx
+++ b/Examples/BasicFilters/BandMathFilterExample.cxx
@@ -22,22 +22,6 @@
 ./BandMathFilterExample Input/qb_RoadExtract.tif Output/RoadExtractBandMath.tif Output/qb_BandMath-pretty.jpg
 */
 
-
-// This filter is based on the mathematical parser library muParser.
-// The built in functions and operators list is available at:
-// http://muparser.sourceforge.net/mup_features.html.
-//
-// In order to use this filter, at least one input image should be
-// set. An associated variable name can be specified or not by using
-// the corresponding SetNthInput method. For the nth input image, if
-// no associated variable name has been specified, a default variable
-// name is given by concatenating the letter "b" (for band) and the
-// corresponding input index.
-//
-// The next step is to set the expression according to the variable
-// names. For example, in the default case with three input images the
-// following expression is valid: ``(b1+b2)*b3``.
-
 #include "itkMacro.h"
 #include <iostream>
 
@@ -65,11 +49,10 @@ int main(int argc, char* argv[])
     return EXIT_FAILURE;
   }
 
-  // We start by the typedef needed for reading and
+  // We start by the typedefs needed for reading and
   // writing the images. The BandMathImageFilter class
   // works with Image as input, so we need to define additional
   // filters to extract each layer of the multispectral image.
-
   typedef double                                                           PixelType;
   typedef otb::VectorImage<PixelType, 2>                                   InputImageType;
   typedef otb::Image<PixelType, 2>                                         OutputImageType;
@@ -78,13 +61,12 @@ int main(int argc, char* argv[])
   typedef otb::ImageFileReader<InputImageType>                             ReaderType;
   typedef otb::ImageFileWriter<OutputImageType>                            WriterType;
 
-  // We can now define the type for the filter:
+  // We can now define the type for the filter
   typedef otb::BandMathImageFilter<OutputImageType> FilterType;
 
-  // We instantiate the filter, the reader, and the writer:
+  // We instantiate the filter, the reader, and the writer
   ReaderType::Pointer reader = ReaderType::New();
   WriterType::Pointer writer = WriterType::New();
-
   FilterType::Pointer filter = FilterType::New();
 
   writer->SetInput(filter->GetOutput());
@@ -93,9 +75,9 @@ int main(int argc, char* argv[])
 
   reader->UpdateOutputInformation();
 
-  // We now need to extract each band from the input \doxygen{otb}{VectorImage},
-  // it illustrates the use of the \doxygen{otb}{VectorImageToImageList}.
-  // Each extracted layer is an input to the \doxygen{otb}{BandMathImageFilter}:
+  // We now need to extract each band from the input VectorImage,
+  // it illustrates the use of the VectorImageToImageList.
+  // Each extracted layer is an input to the BandMathImageFilter
   VectorImageToImageListType::Pointer imageList = VectorImageToImageListType::New();
   imageList->SetInput(reader->GetOutput());
 
@@ -111,8 +93,8 @@ int main(int argc, char* argv[])
   // Now we can define the mathematical expression to perform on the layers (b1, b2, b3, b4).
   // The filter takes advantage of the parsing capabilities of the muParser library and
   // allows setting the expression as on a digital calculator.
-  //
-  // The expression below returns 255 if the ratio $(NIR-RED)/(NIR+RED)$ is greater than 0.4 and 0 if not.
+
+  // The expression below returns 255 if the ratio (NIR-RED)/(NIR+RED) is greater than 0.4 and 0 if not.
   filter->SetExpression("if((b4-b3)/(b4+b3) > 0.4, 255, 0)");
 
 #ifdef OTB_MUPARSER_HAS_CXX_LOGICAL_OPERATORS
@@ -125,19 +107,7 @@ int main(int argc, char* argv[])
   writer->Update();
 
   // The muParser library also provides the possibility to extend existing built-in functions. For example,
-  // you can use the OTB expression "ndvi(b3, b4)" with the filter. In this instance, the mathematical expression would be
-  // \textit{if($ndvi(b3, b4)>0.4$, 255, 0)}, which would return the same result.
-
-  // Figure~\ref{fig:BandMathImageFilter} shows the result of the threshold applied to the NDVI index
-  // of a Quickbird image.
-  // \begin{figure}
-  // \center
-  // \includegraphics[width=0.45\textwidth]{qb_ExtractRoad_pretty.eps}
-  // \includegraphics[width=0.45\textwidth]{qb_BandMath-pretty.eps}
-  // \itkcaption[Band Math]{From left to right:
-  // Original image, thresholded NDVI index.}
-  // \label{fig:BandMathImageFilter}
-  // \end{figure}
+  // you can use the OTB expression "ndvi(b3, b4)" with the filter. In this instance, the mathematical expression would be "if(ndvi(b3, b4)>0.4, 255, 0)", which would return the same result.
 
   typedef otb::Image<unsigned char, 2>                                 OutputPrettyImageType;
   typedef otb::ImageFileWriter<OutputPrettyImageType>                  PrettyImageFileWriterType;
@@ -151,6 +121,4 @@ int main(int argc, char* argv[])
   prettyWriter->SetFileName(argv[3]);
 
   prettyWriter->Update();
-
-  return EXIT_SUCCESS;
 }
diff --git a/Examples/BasicFilters/BandMathFilterExample.rst b/Examples/BasicFilters/BandMathFilterExample.rst
new file mode 100644
index 0000000000..47da3da898
--- /dev/null
+++ b/Examples/BasicFilters/BandMathFilterExample.rst
@@ -0,0 +1,27 @@
+The :doxygen:`BandMathImageFilter` is based on the mathematical parser library muParser.
+The built in functions and operators list is available at:
+http://muparser.sourceforge.net/mup_features.html.
+
+In order to use this filter, at least one input image should be
+set. An associated variable name can be specified or not by using
+the corresponding ``SetNthInput`` method. For the nth input image, if
+no associated variable name has been specified, a default variable
+name is given by concatenating the letter "b" (for band) and the
+corresponding input index.
+
+The next step is to set the expression according to the variable
+names. For example, in the default case with three input images the
+following expression is valid: ``(b1+b2)*b3``.
+
+.. |image1| image:: /Input/qb_ExtractRoad_pretty.png
+
+.. |image2| image:: /Output/qb_BandMath-pretty.jpg
+
+.. _Figure1:
+
++--------------------------+-------------------------+
+|        |image1|          |         |image2|        |
++--------------------------+-------------------------+
+
+    NDVI of a Quickbird image computed with BandMathImageFilter
+
-- 
GitLab