PROJECT(Examples C)

# Macro defs

# This macro states that the executable "EXECUTABLE" upon execution will generate
# output image "OUTPUT_IMG". The executable will depend on "SOURCE_FILE" (since
# it is assumed that it was generated by compiling SOURCE_FILE), the perl script
# used to generate this macro, and any figures that may have been generated by
# other examples that the executable may use as inputs to produce the OUTPUT_IMG.
#
# TODO: Create a smarter macro. For an example that generates 3 outputs, 3 macros
# are created. This results in the example running 3 times, instead of once.
MACRO(RUN_EXAMPLE EXECUTABLE OUTPUT_IMG SOURCE_FILE)
  ADD_CUSTOM_COMMAND(
      OUTPUT      "${SoftwareGuide_BINARY_DIR}/Art/Generated/${OUTPUT_IMG}"
      COMMAND     "${OTB_PREFIX}/bin/${EXECUTABLE}"
      ARGS        ${ARGN}
      DEPENDS     ${RUN_EXAMPLES_SCRIPT} ${SOURCE_FILE} ${GENERATED_FIGURE_DEPS}
  )
ENDMACRO(RUN_EXAMPLE)

# If we made the assumption that the input file needed for this example
# was generated by running some other example, let us explicitly
# state that dependency so that makefile rules fire in the right
# order.
MACRO(ADD_GENERATED_FIG_DEPS OUTPUT_IMG GENERATED_FIG)
  SET( GENERATED_FIGURE_DEPS ${GENERATED_FIGURE_DEPS} "${SoftwareGuide_BINARY_DIR}/Art/Generated/${GENERATED_FIG}" )
ENDMACRO( ADD_GENERATED_FIG_DEPS )


# Some images need normalization for proper display in the book.
# Create a convenience macro that normalizes SOME_IMG and produces
# a rescaled EPS_IMG using ImageMagick tools.
MACRO(CONVERT_AND_NORMALIZE_IMG SOME_IMG EPS_IMG PATH)
  ADD_CUSTOM_COMMAND(
      SOURCE      "${PATH}/${SOME_IMG}"
      COMMAND     ${IMAGEMAGICK_CONVERT_EXECUTABLE}
      ARGS        "-normalize" "${PATH}/${SOME_IMG}" "${SoftwareGuide_BINARY_DIR}/Art/${EPS_IMG}"
      DEPENDS     ${RUN_EXAMPLES_SCRIPT} "${SoftwareGuide_BINARY_DIR}/Art/Generated/${SOME_IMG}"
      OUTPUT      "${SoftwareGuide_BINARY_DIR}/Art/${EPS_IMG}"
  )
ENDMACRO(CONVERT_AND_NORMALIZE_IMG)

# Same as before.. also flip the image in the process.
MACRO(CONVERT_AND_FLIP_AND_NORMALIZE_IMG SOME_IMG EPS_IMG PATH)
  ADD_CUSTOM_COMMAND(
      SOURCE      "${PATH}/${SOME_IMG}"
      COMMAND     ${IMAGEMAGICK_CONVERT_EXECUTABLE}
      ARGS        "-flip" "-normalize" "${PATH}/${SOME_IMG}" "${SoftwareGuide_BINARY_DIR}/Art/${EPS_IMG}"
      DEPENDS     ${RUN_EXAMPLES_SCRIPT} "${SoftwareGuide_BINARY_DIR}/Art/Generated/${SOME_IMG}"
      OUTPUT      "${SoftwareGuide_BINARY_DIR}/Art/${EPS_IMG}"
  )
ENDMACRO(CONVERT_AND_FLIP_AND_NORMALIZE_IMG)

# Convert an image from some file format to EPS for inclusion in Latex using
# ImageMagick or bmeps

IF(OTB_USE_BMEPS)
  MACRO(CONVERT_IMG SOME_IMG EPS_IMG PATH)
    ADD_CUSTOM_COMMAND(
        SOURCE      "${PATH}/${SOME_IMG}"
        COMMAND     ${BMEPS_EXECUTABLE}
        ARGS        "${PATH}/${SOME_IMG}" "${SoftwareGuide_BINARY_DIR}/Art/${EPS_IMG}"
        DEPENDS     ${RUN_EXAMPLES_SCRIPT} "${SoftwareGuide_BINARY_DIR}/Art/Generated/${SOME_IMG}"
        OUTPUT      "${SoftwareGuide_BINARY_DIR}/Art/${EPS_IMG}"
    )
  ENDMACRO(CONVERT_IMG)
ELSE(OTB_USE_BMEPS)
  MACRO(CONVERT_IMG SOME_IMG EPS_IMG PATH)
    ADD_CUSTOM_COMMAND(
        SOURCE      "${PATH}/${SOME_IMG}"
        COMMAND     ${IMAGEMAGICK_CONVERT_EXECUTABLE}
        ARGS        "${PATH}/${SOME_IMG}" "${SoftwareGuide_BINARY_DIR}/Art/${EPS_IMG}"
        DEPENDS     ${RUN_EXAMPLES_SCRIPT} "${SoftwareGuide_BINARY_DIR}/Art/Generated/${SOME_IMG}"
        OUTPUT      "${SoftwareGuide_BINARY_DIR}/Art/${EPS_IMG}"
    )
  ENDMACRO(CONVERT_IMG)
ENDIF(OTB_USE_BMEPS)

# Convert an image from some file format to EPS for inclusion in Latex using
# ImageMagick.. also flip in the process.
MACRO(CONVERT_AND_FLIP_IMG SOME_IMG EPS_IMG PATH)
  ADD_CUSTOM_COMMAND(
      SOURCE      "${PATH}/${SOME_IMG}"
      COMMAND     ${IMAGEMAGICK_CONVERT_EXECUTABLE}
      ARGS        "-flip" "${PATH}/${SOME_IMG}" "${SoftwareGuide_BINARY_DIR}/Art/${EPS_IMG}"
      DEPENDS     ${RUN_EXAMPLES_SCRIPT} "${SoftwareGuide_BINARY_DIR}/Art/Generated/${SOME_IMG}"
      OUTPUT      "${SoftwareGuide_BINARY_DIR}/Art/${EPS_IMG}"
  )
ENDMACRO(CONVERT_AND_FLIP_IMG)

# Convert an image from some file format to EPS for inclusion in Latex using
# ImageMagick or bmeps.. This image is an input image. A seperate macro is necessary
# cause input images do not have any dependecies
IF(OTB_USE_BMEPS)
  MACRO(CONVERT_INPUT_IMG SOME_IMG EPS_IMG PATH)
    ADD_CUSTOM_COMMAND(
        SOURCE      "${PATH}/${SOME_IMG}"
        COMMAND     ${BMEPS_EXECUTABLE}
        ARGS        "${PATH}/${SOME_IMG}" "${SoftwareGuide_BINARY_DIR}/Art/${EPS_IMG}"
        DEPENDS     ${RUN_EXAMPLES_SCRIPT}
        OUTPUT      "${SoftwareGuide_BINARY_DIR}/Art/${EPS_IMG}"
    )
  ENDMACRO(CONVERT_INPUT_IMG)
ELSE(OTB_USE_BMEPS)
  MACRO(CONVERT_INPUT_IMG SOME_IMG EPS_IMG PATH)
    ADD_CUSTOM_COMMAND(
        SOURCE      "${PATH}/${SOME_IMG}"
        COMMAND     ${IMAGEMAGICK_CONVERT_EXECUTABLE}
        ARGS        "${PATH}/${SOME_IMG}" "${SoftwareGuide_BINARY_DIR}/Art/${EPS_IMG}"
        DEPENDS     ${RUN_EXAMPLES_SCRIPT}
        OUTPUT      "${SoftwareGuide_BINARY_DIR}/Art/${EPS_IMG}"
    )
  ENDMACRO(CONVERT_INPUT_IMG)
ENDIF(OTB_USE_BMEPS)


#
#
#  Error checking for the components we need
#
#



# # Convert an image from some file format to EPS for inclusion in Latex using
# # jpg2ps.. This image is an input image. A seperate macro is necessary
# # cause input images do not have any dependecies
# #in case of input image is in jpeg
# MACRO(CONVERT_INPUT_COMPRESSED_IMG BASIC_OPTION SOME_IMG EPS_IMG PATH)
#   ADD_CUSTOM_COMMAND(
#       SOURCE      "${PATH}/${SOME_IMG}"
#       COMMAND     ${JPG2PS_EXECUTABLE}
#       ARGS        "${BASIC_OPTION}" "${PATH}/${SOME_IMG}" "${SoftwareGuide_BINARY_DIR}/Art/${EPS_IMG}"
#       DEPENDS     ${RUN_EXAMPLES_SCRIPT}
#       OUTPUT      "${SoftwareGuide_BINARY_DIR}/Art/${EPS_IMG}"
#   )
# ENDMACRO(CONVERT_INPUT_COMPRESSED_IMG)
#
# MACRO(CONVERT_COMPRESSED_IMG BASIC_OPTION SOME_IMG EPS_IMG PATH)
#   ADD_CUSTOM_COMMAND(
#       SOURCE      "${PATH}/${SOME_IMG}"
#       COMMAND     ${JPG2PS_EXECUTABLE}
#       ARGS        "${BASIC_OPTION}" "${PATH}/${SOME_IMG}" "${SoftwareGuide_BINARY_DIR}/Art/${EPS_IMG}"
#       DEPENDS     ${RUN_EXAMPLES_SCRIPT} "${SoftwareGuide_BINARY_DIR}/Art/Generated/${SOME_IMG}"
#       OUTPUT      "${SoftwareGuide_BINARY_DIR}/Art/${EPS_IMG}"
#   )
# ENDMACRO(CONVERT_COMPRESSED_IMG)


# Convert an image from some file format to EPS for inclusion in Latex using
# ImageMagick.. This image is an input image. A seperate macro is necessary
# cause input images do not have any dependecies. Also flip
MACRO(CONVERT_AND_FLIP_INPUT_IMG SOME_IMG EPS_IMG PATH)
  ADD_CUSTOM_COMMAND(
      SOURCE      "${PATH}/${SOME_IMG}"
      COMMAND     ${IMAGEMAGICK_CONVERT_EXECUTABLE}
      ARGS        "-flip" "${PATH}/${SOME_IMG}" "${SoftwareGuide_BINARY_DIR}/Art/${EPS_IMG}"
      DEPENDS     ${RUN_EXAMPLES_SCRIPT}
      OUTPUT      "${SoftwareGuide_BINARY_DIR}/Art/${EPS_IMG}"
  )
ENDMACRO(CONVERT_AND_FLIP_INPUT_IMG)


# Set/Get macros to set/get dependencies on file foo.tex
MACRO(SET_DEP_FOR_TEXFILE NAME VAL)
  SET(${NAME} ${${NAME}} "${VAL}")
  #MESSAGE("set: ${NAME}: ${${NAME}}")
ENDMACRO(SET_DEP_FOR_TEXFILE)
MACRO(GET_DEP_FOR_TEXFILE NAME VAR)
  SET(${VAR} ${${NAME}})
  #MESSAGE("get: ${NAME}: ${${NAME}}")
ENDMACRO(GET_DEP_FOR_TEXFILE)

# Macro to indicate that foo.tex depends on bar.eps
MACRO(ADD_DEP_TEX_ON_EPS_FIGS TEXFILE EPSIMG)
  GET_FILENAME_COMPONENT(name "${TEXFILE}" NAME_WE)
  SET_DEP_FOR_TEXFILE("${name}-DEPS" "${SoftwareGuide_BINARY_DIR}/Art/${EPSIMG}")
  #MESSAGE("Add dependency to ${TEXFILE} to ${EPSIMG}")
  GET_DEP_TEX_ON_EPS_FIGS("${TEXFILE}" deps)
  #MESSAGE("Stored as ${deps}")
ENDMACRO(ADD_DEP_TEX_ON_EPS_FIGS)

# Get macro to get the list of eps figures that are dependencies of foo.tex
MACRO(GET_DEP_TEX_ON_EPS_FIGS TEXFILE VAR)
  GET_FILENAME_COMPONENT(name "${TEXFILE}" NAME_WE)
  #MESSAGE("-- name: ${name} --")
  GET_DEP_FOR_TEXFILE("${name}-DEPS" ${VAR})
ENDMACRO(GET_DEP_TEX_ON_EPS_FIGS)

#
# Find Perl executable

INCLUDE (${CMAKE_ROOT}/Modules/FindPerl.cmake)
IF( NOT PERL_FOUND )
  MESSAGE("Perl executable was not found")
ENDIF( NOT PERL_FOUND )
FIND_PROGRAM(PERLCXXPARSER
  NAMES ${SoftwareGuide_SOURCE_DIR}/ParseCxxExamples.pl
)


ADD_CUSTOM_TARGET(SoftwareGuideExamples  ALL echo)


#
# At some point we should replace the manual OTB_EXAMPLES_SRCS with
# this FILE GLOB_RECURSE expression.
#
#FILE( GLOB_RECURSE OTB_EXAMPLES_SRCS  ${OTB_SOURCE_DIR}/Examples/*.cxx)


SET( OTB_EXAMPLES_SRCS
  ${OTB_SOURCE_DIR}/Examples/Application/ApplicationExample.cxx
  ${OTB_SOURCE_DIR}/Examples/Installation/HelloWorld.cxx
  ${OTB_SOURCE_DIR}/Examples/DataRepresentation/Image/Image1.cxx
  ${OTB_SOURCE_DIR}/Examples/DataRepresentation/Image/Image2.cxx
  ${OTB_SOURCE_DIR}/Examples/DataRepresentation/Image/Image3.cxx
  ${OTB_SOURCE_DIR}/Examples/DataRepresentation/Image/Image4.cxx
  ${OTB_SOURCE_DIR}/Examples/DataRepresentation/Image/ImageAdaptor1.cxx
  ${OTB_SOURCE_DIR}/Examples/DataRepresentation/Image/ImageAdaptor2.cxx
  ${OTB_SOURCE_DIR}/Examples/DataRepresentation/Image/ImageAdaptor3.cxx
  ${OTB_SOURCE_DIR}/Examples/DataRepresentation/Image/ImageAdaptor4.cxx
  ${OTB_SOURCE_DIR}/Examples/DataRepresentation/Image/RGBImage.cxx
  ${OTB_SOURCE_DIR}/Examples/DataRepresentation/Image/VectorImage.cxx
  ${OTB_SOURCE_DIR}/Examples/DataRepresentation/Image/Image5.cxx
  ${OTB_SOURCE_DIR}/Examples/DataRepresentation/Image/ImageListExample.cxx
  ${OTB_SOURCE_DIR}/Examples/DataRepresentation/Mesh/PointSet1.cxx
  ${OTB_SOURCE_DIR}/Examples/DataRepresentation/Mesh/PointSet2.cxx
  ${OTB_SOURCE_DIR}/Examples/DataRepresentation/Mesh/PointSet3.cxx
  ${OTB_SOURCE_DIR}/Examples/DataRepresentation/Mesh/Mesh1.cxx
  ${OTB_SOURCE_DIR}/Examples/DataRepresentation/Mesh/Mesh2.cxx
  ${OTB_SOURCE_DIR}/Examples/DataRepresentation/Mesh/Mesh3.cxx
  ${OTB_SOURCE_DIR}/Examples/DataRepresentation/Mesh/PointSetWithVectors.cxx
  ${OTB_SOURCE_DIR}/Examples/DataRepresentation/Path/PolyLineParametricPath1.cxx
  ${OTB_SOURCE_DIR}/Examples/IO/ImageReadWrite.cxx
  ${OTB_SOURCE_DIR}/Examples/IO/StreamingImageReadWrite.cxx
  ${OTB_SOURCE_DIR}/Examples/IO/ExplicitStreamingExample.cxx
  ${OTB_SOURCE_DIR}/Examples/IO/RGBImageReadWrite.cxx
  ${OTB_SOURCE_DIR}/Examples/IO/ImageReadCastWrite.cxx
  ${OTB_SOURCE_DIR}/Examples/IO/ImageReadRegionOfInterestWrite.cxx
  ${OTB_SOURCE_DIR}/Examples/IO/ComplexImageReadWrite.cxx
  ${OTB_SOURCE_DIR}/Examples/IO/MultibandImageReadWrite.cxx
  ${OTB_SOURCE_DIR}/Examples/IO/ExtractROI.cxx
  ${OTB_SOURCE_DIR}/Examples/IO/ImageSeriesIOExample.cxx
  ${OTB_SOURCE_DIR}/Examples/IO/MetadataExample.cxx
  #${OTB_SOURCE_DIR}/Examples/IO/DXFReaderExample.cxx
  ${OTB_SOURCE_DIR}/Examples/IO/VectorDataIOExample.cxx
  ${OTB_SOURCE_DIR}/Examples/IO/OGRWrappersExample.cxx
  ${OTB_SOURCE_DIR}/Examples/IO/DEMToImageGenerator.cxx
  ${OTB_SOURCE_DIR}/Examples/IO/DEMHandlerExample.cxx
  ${OTB_SOURCE_DIR}/Examples/IO/TileMapImageIOExample.cxx
  ${OTB_SOURCE_DIR}/Examples/Filtering/BinaryThresholdImageFilter.cxx
  ${OTB_SOURCE_DIR}/Examples/Filtering/ThresholdImageFilter.cxx
  ${OTB_SOURCE_DIR}/Examples/Filtering/CannyEdgeDetectionImageFilter.cxx
  ${OTB_SOURCE_DIR}/Examples/Filtering/CompositeFilterExample.cxx
  ${OTB_SOURCE_DIR}/Examples/Filtering/GradientMagnitudeImageFilter.cxx
  ${OTB_SOURCE_DIR}/Examples/Filtering/GradientMagnitudeRecursiveGaussianImageFilter.cxx
  ${OTB_SOURCE_DIR}/Examples/Filtering/DerivativeImageFilter.cxx
  ${OTB_SOURCE_DIR}/Examples/Filtering/SecondDerivativeRecursiveGaussianImageFilter.cxx
  ${OTB_SOURCE_DIR}/Examples/Filtering/LaplacianRecursiveGaussianImageFilter1.cxx
  ${OTB_SOURCE_DIR}/Examples/Filtering/LaplacianRecursiveGaussianImageFilter2.cxx
  ${OTB_SOURCE_DIR}/Examples/Filtering/MeanImageFilter.cxx
  ${OTB_SOURCE_DIR}/Examples/Filtering/MedianImageFilter.cxx
  ${OTB_SOURCE_DIR}/Examples/Filtering/DiscreteGaussianImageFilter.cxx
  ${OTB_SOURCE_DIR}/Examples/Filtering/GradientAnisotropicDiffusionImageFilter.cxx
  ${OTB_SOURCE_DIR}/Examples/Filtering/DanielssonDistanceMapImageFilter.cxx
  ${OTB_SOURCE_DIR}/Examples/Filtering/MathematicalMorphologyBinaryFilters.cxx
  ${OTB_SOURCE_DIR}/Examples/Filtering/MathematicalMorphologyGrayscaleFilters.cxx
  #${OTB_SOURCE_DIR}/Examples/Filtering/RasterizationExample.cxx
  ${OTB_SOURCE_DIR}/Examples/BasicFilters/LeeImageFilter.cxx
  ${OTB_SOURCE_DIR}/Examples/BasicFilters/FrostImageFilter.cxx
  ${OTB_SOURCE_DIR}/Examples/BasicFilters/ScalingFilterExample.cxx
  ${OTB_SOURCE_DIR}/Examples/BasicFilters/PrintableImageFilterExample.cxx
  ${OTB_SOURCE_DIR}/Examples/BasicFilters/IndexedToRGBExample.cxx
  ${OTB_SOURCE_DIR}/Examples/BasicFilters/DEMToRainbowExample.cxx
  ${OTB_SOURCE_DIR}/Examples/BasicFilters/MeanShiftSegmentationFilterExample.cxx
  ${OTB_SOURCE_DIR}/Examples/BasicFilters/HillShadingExample.cxx
  ${OTB_SOURCE_DIR}/Examples/BasicFilters/BandMathFilterExample.cxx
  ${OTB_SOURCE_DIR}/Examples/BasicFilters/BandMathXImageFilterExample.cxx
  ${OTB_SOURCE_DIR}/Examples/Registration/ImageRegistration1.cxx
  ${OTB_SOURCE_DIR}/Examples/Registration/ImageRegistration2.cxx
  ${OTB_SOURCE_DIR}/Examples/Registration/ImageRegistration5.cxx
  ${OTB_SOURCE_DIR}/Examples/Registration/ImageRegistration9.cxx
  ${OTB_SOURCE_DIR}/Examples/Projections/SensorModelExample.cxx
  ${OTB_SOURCE_DIR}/Examples/Projections/MapProjectionExample.cxx
  ${OTB_SOURCE_DIR}/Examples/Projections/OrthoRectificationExample.cxx
  ${OTB_SOURCE_DIR}/Examples/Projections/VectorDataProjectionExample.cxx
  ${OTB_SOURCE_DIR}/Examples/Projections/GeometriesProjectionExample.cxx
  ${OTB_SOURCE_DIR}/Examples/Projections/VectorDataExtractROIExample.cxx
  ${OTB_SOURCE_DIR}/Examples/Projections/PlaceNameToLonLatExample.cxx
  ${OTB_SOURCE_DIR}/Examples/Projections/EstimateRPCSensorModelExample.cxx
  ${OTB_SOURCE_DIR}/Examples/DisparityMap/SimpleDisparityMapEstimationExample.cxx
  #${OTB_SOURCE_DIR}/Examples/DisparityMap/NCCRegistrationFilterExample.cxx
  ${OTB_SOURCE_DIR}/Examples/DisparityMap/FineRegistrationImageFilterExample.cxx
  ${OTB_SOURCE_DIR}/Examples/DisparityMap/StereoReconstructionExample.cxx
  ${OTB_SOURCE_DIR}/Examples/FeatureExtraction/TextureExample.cxx
  ${OTB_SOURCE_DIR}/Examples/FeatureExtraction/PanTexExample.cxx
  ${OTB_SOURCE_DIR}/Examples/FeatureExtraction/SFSExample.cxx
  ${OTB_SOURCE_DIR}/Examples/FeatureExtraction/AlignmentsExample.cxx
  ${OTB_SOURCE_DIR}/Examples/FeatureExtraction/RatioLineDetectorExample.cxx
  ${OTB_SOURCE_DIR}/Examples/FeatureExtraction/CorrelationLineDetectorExample.cxx
  ${OTB_SOURCE_DIR}/Examples/FeatureExtraction/AssymmetricFusionOfLineDetectorExample.cxx
  ${OTB_SOURCE_DIR}/Examples/FeatureExtraction/LocalHoughExample.cxx
  #${OTB_SOURCE_DIR}/Examples/FeatureExtraction/LineSegmentDetectorExample.cxx
  #${OTB_SOURCE_DIR}/Examples/FeatureExtraction/RightAngleDetectionExample.cxx
  ${OTB_SOURCE_DIR}/Examples/FeatureExtraction/ExtractSegmentsByStepsExample.cxx
  ${OTB_SOURCE_DIR}/Examples/FeatureExtraction/ExtractSegmentsExample.cxx
  ${OTB_SOURCE_DIR}/Examples/FeatureExtraction/ParallelLineDetectionExample.cxx
  ${OTB_SOURCE_DIR}/Examples/FeatureExtraction/TouziEdgeDetectorExample.cxx
  ${OTB_SOURCE_DIR}/Examples/FeatureExtraction/HarrisExample.cxx
  ${OTB_SOURCE_DIR}/Examples/FeatureExtraction/SURFExample.cxx
  ${OTB_SOURCE_DIR}/Examples/FeatureExtraction/ComplexMomentsImageFunctionExample.cxx
  ${OTB_SOURCE_DIR}/Examples/FeatureExtraction/ComplexMomentPathExample.cxx
  ${OTB_SOURCE_DIR}/Examples/FeatureExtraction/HuMomentsImageFunctionExample.cxx
  ${OTB_SOURCE_DIR}/Examples/FeatureExtraction/FlusserMomentsImageFunctionExample.cxx
  ${OTB_SOURCE_DIR}/Examples/FeatureExtraction/ExtractRoadByStepsExample.cxx
  ${OTB_SOURCE_DIR}/Examples/FeatureExtraction/ExtractRoadExample.cxx
  ${OTB_SOURCE_DIR}/Examples/FeatureExtraction/SeamCarvingExample.cxx
  ${OTB_SOURCE_DIR}/Examples/FeatureExtraction/SeamCarvingOtherExample.cxx
  ${OTB_SOURCE_DIR}/Examples/FeatureExtraction/ThresholdToPointSetExample.cxx
  ${OTB_SOURCE_DIR}/Examples/FeatureExtraction/CloudDetectionExample.cxx
  ${OTB_SOURCE_DIR}/Examples/FeatureExtraction/EdgeDensityExample.cxx
  ${OTB_SOURCE_DIR}/Examples/DimensionReduction/MaximumAutocorrelationFactor.cxx
  ${OTB_SOURCE_DIR}/Examples/DimensionReduction/PCAExample.cxx
  ${OTB_SOURCE_DIR}/Examples/DimensionReduction/NAPCAExample.cxx
  ${OTB_SOURCE_DIR}/Examples/DimensionReduction/MNFExample.cxx
  ${OTB_SOURCE_DIR}/Examples/DimensionReduction/ICAExample.cxx
  ${OTB_SOURCE_DIR}/Examples/Segmentation/ConnectedThresholdImageFilter.cxx
  ${OTB_SOURCE_DIR}/Examples/Segmentation/OtsuThresholdImageFilter.cxx
  ${OTB_SOURCE_DIR}/Examples/Segmentation/OtsuMultipleThresholdImageFilter.cxx
  ${OTB_SOURCE_DIR}/Examples/Segmentation/NeighborhoodConnectedImageFilter.cxx
  ${OTB_SOURCE_DIR}/Examples/Segmentation/ConfidenceConnected.cxx
  ${OTB_SOURCE_DIR}/Examples/Segmentation/IsolatedConnectedImageFilter.cxx
  ${OTB_SOURCE_DIR}/Examples/Segmentation/WatershedSegmentation.cxx
  ${OTB_SOURCE_DIR}/Examples/Segmentation/FastMarchingImageFilter.cxx
  #${OTB_SOURCE_DIR}/Examples/Patented/HybridSegmentationFuzzyVoronoi.cxx
  #${OTB_SOURCE_DIR}/Examples/Patented/FuzzyConnectednessImageFilter.cxx
  ${OTB_SOURCE_DIR}/Examples/MultiScale/MorphologicalPyramidAnalysisFilterExample.cxx
  ${OTB_SOURCE_DIR}/Examples/MultiScale/MorphologicalPyramidSynthesisFilterExample.cxx
  ${OTB_SOURCE_DIR}/Examples/MultiScale/MorphologicalPyramidSegmenterExample.cxx
  ${OTB_SOURCE_DIR}/Examples/MultiScale/MorphologicalPyramidSegmentationExample.cxx
  ${OTB_SOURCE_DIR}/Examples/ChangeDetection/ChangeDetectionFrameworkExample.cxx
  ${OTB_SOURCE_DIR}/Examples/ChangeDetection/DiffChDet.cxx
  ${OTB_SOURCE_DIR}/Examples/ChangeDetection/RatioChDet.cxx
  ${OTB_SOURCE_DIR}/Examples/ChangeDetection/CorrelChDet.cxx
  ${OTB_SOURCE_DIR}/Examples/ChangeDetection/KullbackLeiblerDistanceChDet.cxx
  ${OTB_SOURCE_DIR}/Examples/ChangeDetection/KullbackLeiblerProfileChDet.cxx
  ${OTB_SOURCE_DIR}/Examples/ChangeDetection/MultivariateAlterationDetector.cxx
  ${OTB_SOURCE_DIR}/Examples/Classification/KdTreeBasedKMeansClustering.cxx
  ${OTB_SOURCE_DIR}/Examples/Classification/KMeansImageClassificationExample.cxx
  ${OTB_SOURCE_DIR}/Examples/Classification/ScalarImageKmeansModelEstimator.cxx
  ${OTB_SOURCE_DIR}/Examples/Classification/ScalarImageKmeansClassifier.cxx
  ${OTB_SOURCE_DIR}/Examples/Classification/BayesianPluginClassifier.cxx
  ${OTB_SOURCE_DIR}/Examples/Classification/ExpectationMaximizationMixtureModelEstimator.cxx
  ${OTB_SOURCE_DIR}/Examples/Classification/ScalarImageMarkovRandomField1.cxx
  ${OTB_SOURCE_DIR}/Examples/Markov/MarkovClassification1Example.cxx
  ${OTB_SOURCE_DIR}/Examples/Markov/MarkovClassification2Example.cxx
  ${OTB_SOURCE_DIR}/Examples/Markov/MarkovClassification3Example.cxx
  ${OTB_SOURCE_DIR}/Examples/Markov/MarkovRestaurationExample.cxx
  ${OTB_SOURCE_DIR}/Examples/Markov/MarkovRegularizationExample.cxx
  ${OTB_SOURCE_DIR}/Examples/Learning/SVMPointSetModelEstimatorExample.cxx
  ${OTB_SOURCE_DIR}/Examples/Learning/SVMPointSetClassificationExample.cxx
  ${OTB_SOURCE_DIR}/Examples/Learning/SVMImageModelEstimatorExample.cxx
  ${OTB_SOURCE_DIR}/Examples/Learning/SVMImageClassificationExample.cxx
  ${OTB_SOURCE_DIR}/Examples/Learning/SVMImageEstimatorClassificationMultiExample.cxx
  ${OTB_SOURCE_DIR}/Examples/Classification/SupervisedImageClassificationExample.cxx
  ${OTB_SOURCE_DIR}/Examples/Classification/MajorityVotingFusionOfClassificationMapsExample.cxx
  ${OTB_SOURCE_DIR}/Examples/Classification/DempsterShaferFusionOfClassificationMapsExample.cxx
  ${OTB_SOURCE_DIR}/Examples/Classification/ClassificationMapRegularizationExample.cxx
  ${OTB_SOURCE_DIR}/Examples/Learning/SOMExample.cxx
  ${OTB_SOURCE_DIR}/Examples/Learning/SOMClassifierExample.cxx
  ${OTB_SOURCE_DIR}/Examples/Classification/SOMImageClassificationExample.cxx
  ${OTB_SOURCE_DIR}/Examples/Learning/SEMModelEstimatorExample.cxx
  ${OTB_SOURCE_DIR}/Examples/Learning/SVMGenericKernelImageClassificationExample.cxx
  ${OTB_SOURCE_DIR}/Examples/Learning/SVMGenericKernelImageModelEstimatorExample.cxx
  ${OTB_SOURCE_DIR}/Examples/Learning/TrainMachineLearningModelFromSamplesExample.cxx
  ${OTB_SOURCE_DIR}/Examples/Learning/TrainMachineLearningModelFromImagesExample.cxx
  ${OTB_SOURCE_DIR}/Examples/OBIA/ImageToLabelToImage.cxx
  ${OTB_SOURCE_DIR}/Examples/OBIA/ShapeAttributeComputation.cxx
#   ${OTB_SOURCE_DIR}/Examples/OBIA/KeepNObjects.cxx
  ${OTB_SOURCE_DIR}/Examples/OBIA/RadiometricAttributesLabelMapFilterExample.cxx
  ${OTB_SOURCE_DIR}/Examples/OBIA/HooverMetricsEstimation.cxx
  ${OTB_SOURCE_DIR}/Examples/Iterators/ImageLinearIteratorWithIndex.cxx
  ${OTB_SOURCE_DIR}/Examples/Iterators/NeighborhoodIterators2.cxx
  ${OTB_SOURCE_DIR}/Examples/Iterators/NeighborhoodIterators5.cxx
  ${OTB_SOURCE_DIR}/Examples/Iterators/ImageRandomConstIteratorWithIndex.cxx
  ${OTB_SOURCE_DIR}/Examples/Iterators/ShapedNeighborhoodIterators1.cxx
  ${OTB_SOURCE_DIR}/Examples/Iterators/ShapedNeighborhoodIterators2.cxx
  ${OTB_SOURCE_DIR}/Examples/Iterators/NeighborhoodIterators3.cxx
  ${OTB_SOURCE_DIR}/Examples/Iterators/IteratorsExamples.cxx
  ${OTB_SOURCE_DIR}/Examples/Iterators/ImageLinearIteratorWithIndex2.cxx
  ${OTB_SOURCE_DIR}/Examples/Iterators/ImageRegionIterator.cxx
  ${OTB_SOURCE_DIR}/Examples/Iterators/ImageSliceIteratorWithIndex.cxx
  ${OTB_SOURCE_DIR}/Examples/Iterators/NeighborhoodIterators6.cxx
  ${OTB_SOURCE_DIR}/Examples/Iterators/NeighborhoodIterators1.cxx
  ${OTB_SOURCE_DIR}/Examples/Iterators/NeighborhoodIterators4.cxx
  ${OTB_SOURCE_DIR}/Examples/Iterators/ImageRegionIteratorWithIndex.cxx
  ${OTB_SOURCE_DIR}/Examples/Radiometry/ARVIMultiChannelRAndBAndNIRVegetationIndexImageFilter.cxx
  ${OTB_SOURCE_DIR}/Examples/Radiometry/AVIMultiChannelRAndGAndNIRVegetationIndexImageFilter.cxx
  ${OTB_SOURCE_DIR}/Examples/Radiometry/NDVIRAndNIRVegetationIndexImageFilter.cxx
  ${OTB_SOURCE_DIR}/Examples/Radiometry/AtmosphericCorrectionSequencement.cxx
  ${OTB_SOURCE_DIR}/Examples/Fusion/BayesianFusionImageFilter.cxx
  ${OTB_SOURCE_DIR}/Examples/Fusion/PanSharpeningExample.cxx
  ${OTB_SOURCE_DIR}/Examples/Tutorials/HelloWorldOTB.cxx
  ${OTB_SOURCE_DIR}/Examples/Tutorials/Pipeline.cxx
  ${OTB_SOURCE_DIR}/Examples/Tutorials/FilteringPipeline.cxx
  ${OTB_SOURCE_DIR}/Examples/Tutorials/ScalingPipeline.cxx
  ${OTB_SOURCE_DIR}/Examples/Tutorials/SmarterFilteringPipeline.cxx
  ${OTB_SOURCE_DIR}/Examples/Tutorials/OrthoFusion.cxx
  ${OTB_SOURCE_DIR}/Examples/Tutorials/Multispectral.cxx
  ${OTB_SOURCE_DIR}/Examples/Simulation/ProsailModel.cxx
  ${OTB_SOURCE_DIR}/Examples/Simulation/LAIFromNDVIImageTransform.cxx
  ${OTB_SOURCE_DIR}/Examples/Simulation/LAIAndPROSAILToSensorResponse.cxx
  ${OTB_SOURCE_DIR}/Examples/Hyperspectral/HyperspectralUnmixingExample.cxx
)

IF(OTB_USE_PATENTED)
SET(OTB_EXAMPLES_SRCS ${OTB_EXAMPLES_SRCS}
  ${OTB_SOURCE_DIR}/Examples/Patented/SIFTDisparityMapEstimation.cxx
  ${OTB_SOURCE_DIR}/Examples/Patented/SIFTFastExample.cxx
  ${OTB_SOURCE_DIR}/Examples/Patented/EstimateAffineTransformationExample.cxx
  ${OTB_SOURCE_DIR}/Examples/Patented/SIFTDensityExample.cxx
   )
ENDIF(OTB_USE_PATENTED)

# It is recommended that the user build the figures from the OTB executables
# to generate the guide to ensure consistency.
IF( BUILD_FIGURES )
  #
  # Generate .cmake files containing those macros defined above.
  #
  # First make a directory to store generated images
  MAKE_DIRECTORY( "${SoftwareGuide_BINARY_DIR}/Art/Generated" )
  SET ( GeneratedFolder "${SoftwareGuide_BINARY_DIR}/Art/Generated" )

  # Earlier versions of the book had all the images flipped upside down, legacy
  # issue.. So if this flag is set to ON, they will be flipped prior to inclusion
  # in the SW guide.
  IF(OTB_FLIP_INPUTS_AND_THEIR_OUTPUTS)
    SET(FILENAME "${SoftwareGuide_BINARY_DIR}/Art/Generated/Flipped_files.txt")
    FILE(WRITE ${FILENAME} "")
    FOREACH(FLIPIMG ${OTB_FLIP_IMG})
      FILE(APPEND ${FILENAME} "${FLIPIMG} ")
    ENDFOREACH(FLIPIMG)
  ENDIF(OTB_FLIP_INPUTS_AND_THEIR_OUTPUTS)

  SET(FILENAME2 "${SoftwareGuide_BINARY_DIR}/Art/Generated/GeneratedFiles.txt")
  FILE(WRITE ${FILENAME2} "")


  FOREACH (example ${OTB_EXAMPLES_SRCS})
    #
    # Configure .. copy needed source files
    #
    GET_FILENAME_COMPONENT(EXAMPLE_FILE ${example} NAME)
    #CONFIGURE_FILE(${example} ${Examples_BINARY_DIR}/${EXAMPLE_FILE}
    #  COPYONLY IMMEDIATE)

    #Clear Figure dependencies for this examples
    #A figure may be generated by another example
    SET( GENERATED_FIGURE_DEPS "")

    # Run Perl script on each example to generate .cmake files
    GET_FILENAME_COMPONENT(EXAMPLE_FILE_BASE ${example} NAME_WE)

    MESSAGE(STATUS "Processing example ${example}")

    # Parse the source file, foo.cxx to generate a foo.cmake containing above macros.
    IF(PERL_FOUND AND RUN_EXAMPLES_SCRIPT)
      SET( ExampleCmakeFile "${Examples_BINARY_DIR}/${EXAMPLE_FILE_BASE}.cmake")
      GET_FILENAME_COMPONENT(TEX_FILE ${example} NAME_WE)
      SET(TEX_FILE ${SoftwareGuide_BINARY_DIR}/Examples/${TEX_FILE}.tex)

      EXECUTE_PROCESS(COMMAND ${PERL_EXECUTABLE}
                      ${RUN_EXAMPLES_SCRIPT} ${example} ${OTB_PREFIX}/bin ${OTB_DATA_PATHS} ${ExampleCmakeFile} ${TEX_FILE} ${GeneratedFolder} )
      # MESSAGE( ARGS ${RUN_EXAMPLES_SCRIPT} ${example} ${OTB_EXECUTABLES_DIR} ${OTB_DATA_PATHS} ${ExampleCmakeFile} ${TEX_FILE} ${GeneratedFolder})
      # Include each of the generated .cmake files in dependencies list
      # only if the file is generated (if it has command line tags)
      INCLUDE(${ExampleCmakeFile} OPTIONAL)

    ENDIF(PERL_FOUND AND RUN_EXAMPLES_SCRIPT)
  ENDFOREACH(example)

  #
  # Parse Latex file for latex includes
  #
  IF( PERL_FOUND AND PERLCXXPARSER )
    FOREACH(example ${OTB_EXAMPLES_SRCS})
    GET_FILENAME_COMPONENT(TEX_FILE ${example} NAME_WE)
    SET(TEX_FILE ${SoftwareGuide_BINARY_DIR}/Examples/${TEX_FILE}.tex)
    GET_DEP_TEX_ON_EPS_FIGS("${TEX_FILE}" deps)
    #MESSAGE("Deps gotten from GET_DEP_TEX_ON_EPS_FIG are ${deps}")
    #GET_FILENAME_COMPONENT(depsNAME ${deps} NAME)
    #MESSAGE("File ${TEX_FILE} depends on: ${deps}")
    ADD_CUSTOM_COMMAND(
      SOURCE    ${example}
      COMMAND   ${PERL_EXECUTABLE}
      ARGS      ${PERLCXXPARSER} ${example} ${TEX_FILE}
      TARGET    SoftwareGuideExamples
      DEPENDS   ${PERLCXXPARSER} ${example} ${deps}
      OUTPUTS   ${TEX_FILE}
    )
    SET(TEX_DEPENDENCIES ${TEX_DEPENDENCIES} ${TEX_FILE})
    ENDFOREACH(example)

  ENDIF( PERL_FOUND AND PERLCXXPARSER )

ELSE( BUILD_FIGURES )
  #
  # Parse Latex file for latex includes
  #
  IF( PERL_FOUND AND PERLCXXPARSER )
    FOREACH(example ${OTB_EXAMPLES_SRCS})
    GET_FILENAME_COMPONENT(TEX_FILE ${example} NAME_WE)
    SET(TEX_FILE ${SoftwareGuide_BINARY_DIR}/Examples/${TEX_FILE}.tex)
    ADD_CUSTOM_COMMAND(
      SOURCE    ${example}
      COMMAND   ${PERL_EXECUTABLE}
      ARGS      ${PERLCXXPARSER} ${example} ${TEX_FILE}
      TARGET    SoftwareGuideExamples
      DEPENDS   ${PERLCXXPARSER} ${example}
      OUTPUTS   ${TEX_FILE}
    )
    SET(TEX_DEPENDENCIES ${TEX_DEPENDENCIES} ${TEX_FILE})
    ENDFOREACH(example)

  ENDIF( PERL_FOUND AND PERLCXXPARSER )

ENDIF( BUILD_FIGURES )

ADD_CUSTOM_TARGET(BuildTexFiles ALL DEPENDS ${TEX_DEPENDENCIES})
SET(EXAMPLES_TEX_FILES ${TEX_DEPENDENCIES} CACHE INTERNAL "Internal EXAMPLES_TEX_FILES file list.")
