Commit 33484921 authored by Thomas Feuvrier's avatar Thomas Feuvrier

ENH: Add new KML library 0.4.0 version. Add 13 tests.

parent 8ee0c31c
......@@ -81,6 +81,35 @@ OPTION(OTB_USE_JPEG2000 "Use to support jpeg2000 image file format." ON)
# FIND EXTERNAL LIBRAIRIES USE
#-------------------------------
# EXPAT Library
#-------------------------------
SET(OTB_USE_EXTERNAL_EXPAT 1)
SET(EXPAT_FIND_REQUIRED 0) # To suppress cmake error message if not find
FIND_PACKAGE(EXPAT)
IF(EXPAT_FOUND)
# Control expat compatibility
INCLUDE_DIRECTORIES(BEFORE ${EXPAT_INCLUDE_DIR})
MESSAGE(${EXPAT_INCLUDE_DIR})
LINK_DIRECTORIES( ${EXPAT_LIBRARY} )
TRY_COMPILE(OTB_TYPE_COMPILE_EXPAT
${OTB_BINARY_DIR}/CMakeTmp
${OTB_SOURCE_DIR}/CMake/otbTestCompileExpat.cxx )
IF(OTB_TYPE_COMPILE_EXPAT)
SET(OTB_USE_EXTERNAL_EXPAT 1)
ELSE(OTB_TYPE_COMPILE_EXPAT)
SET(OTB_USE_EXTERNAL_EXPAT 0)
ENDIF( OTB_TYPE_COMPILE_EXPAT)
ELSE(EXPAT_FOUND)
SET(OTB_USE_EXTERNAL_EXPAT 0)
ENDIF(EXPAT_FOUND)
IF(NOT OTB_USE_EXTERNAL_EXPAT)
ADD_DEFINITIONS(-DOTB_USE_INTERNAL_EXPAT)
INCLUDE_DIRECTORIES(BEFORE "${OTB_SOURCE_DIR}/Utilities/otbexpat")
INCLUDE_DIRECTORIES(BEFORE "${OTB_BINARY_DIR}/Utilities/otbexpat")
ENDIF(NOT OTB_USE_EXTERNAL_EXPAT)
#-------------------------------
# ITK Library
#-------------------------------
......@@ -89,6 +118,15 @@ OPTION(OTB_USE_EXTERNAL_ITK "Use an outside build of ITK." OFF)
IF(OTB_USE_EXTERNAL_ITK)
FIND_PACKAGE(ITK)
IF(ITK_FOUND)
# Builf ITK_INCLUDE_DIRS list wihout expat path
SET(new_list "")
FOREACH(files_h ${ITK_INCLUDE_DIRS})
IF(NOT "${files_h}" MATCHES "expat")
SET(new_list "${new_list};${files_h}")
ENDIF(NOT "${files_h}" MATCHES "expat")
ENDFOREACH(files_h ${ITK_INCLUDE_DIRS})
SET(ITK_INCLUDE_DIRS "${new_list}")
INCLUDE(${ITK_USE_FILE})
ELSE(ITK_FOUND)
MESSAGE(FATAL_ERROR
......@@ -287,34 +325,6 @@ ENDIF (NOT GDAL_INCLUDE_DIRS)
INCLUDE_DIRECTORIES(${GDAL_INCLUDE_DIRS})
LINK_DIRECTORIES( ${GDAL_LIBRARY_DIRS} )
#-------------------------------
# EXPAT Library
#-------------------------------
SET(OTB_USE_EXTERNAL_EXPAT 1)
SET(EXPAT_FIND_REQUIRED 0) # To suppress cmake error message if not find
FIND_PACKAGE(EXPAT)
IF(EXPAT_FOUND)
# Control expat compatibility
INCLUDE_DIRECTORIES(${EXPAT_INCLUDE_DIR})
MESSAGE(${EXPAT_INCLUDE_DIR})
LINK_DIRECTORIES( ${EXPAT_LIBRARY} )
TRY_COMPILE(OTB_TYPE_COMPILE_EXPAT
${OTB_BINARY_DIR}/CMakeTmp
${OTB_SOURCE_DIR}/CMake/otbTestCompileExpat.cxx )
IF(OTB_TYPE_COMPILE_EXPAT)
SET(OTB_USE_EXTERNAL_EXPAT 1)
ELSE(OTB_TYPE_COMPILE_EXPAT)
SET(OTB_USE_EXTERNAL_EXPAT 0)
ENDIF( OTB_TYPE_COMPILE_EXPAT)
ELSE(EXPAT_FOUND)
SET(OTB_USE_EXTERNAL_EXPAT 0)
ENDIF(EXPAT_FOUND)
IF(NOT OTB_USE_EXTERNAL_EXPAT)
ADD_DEFINITIONS(-DOTB_USE_INTERNAL_EXPAT)
INCLUDE_DIRECTORIES("${OTB_SOURCE_DIR}/Utilities/otbexpat")
INCLUDE_DIRECTORIES("${OTB_BINARY_DIR}/Utilities/otbexpat")
ENDIF(NOT OTB_USE_EXTERNAL_EXPAT)
#-------------------------------
# End connections whith external libraries
......
......@@ -382,42 +382,45 @@ ADD_TEST(ut2DSiftImageSceneSyntheticRotate10 ${UTILITIES_TESTS}
1 10 0.5 0 )
# ------- lib Kml ------------------------------
#FOREACH(id_test createkml helloattrs helloenum hellofolder hellogeometry helloregion helloserializer helloworld parsekml )
# ADD_TEST( utKml${id_test} ${CXX_TEST_PATH}/otbKmlTests${id_test}
# kml${id_test}
# ${TEMP}/utkml${id_test}.txt
# )
#ENDFOREACH(id_test)
FOREACH(id_test createkml helloattrs helloenum hellofolder hellogeometry helloregion helloworld parsekml )
ADD_TEST( utKml${id_test} ${UTILITIES_TESTS}
kml${id_test}
${TEMP}/utkml${id_test}.txt
)
ENDFOREACH(id_test)
#ADD_TEST( utKmlhellofeatures ${CXX_TEST_PATH}/otbKmlTestshellofeatures
# kmlhellofeatures
# ${INPUTDATA}/abstractview.kml
ADD_TEST( utKmlhellofeatures ${UTILITIES_TESTS}
kmlhellofeatures
${INPUTDATA}/abstractview.kml
# ${TEMP}/utkmlhellofeatures.txt
# )
)
#ADD_TEST( utKmlhellohref ${CXX_TEST_PATH}/otbKmlTestshellohref
# kmlhellohref
# ${INPUTDATA}/abstractview.kml
ADD_TEST( utKmlhellohref ${UTILITIES_TESTS}
kmlhellohref
${INPUTDATA}/abstractview.kml
# ${TEMP}/utkmlhellohref.txt
# )
#ADD_TEST( utKmlhellokmz ${CXX_TEST_PATH}/otbKmlTestshellokmz
# kmlhellokmz
# ${INPUTDATA}/multikml-doc.kmz
)
ADD_TEST( utKmlhellokmz ${UTILITIES_TESTS}
kmlhellokmz
${INPUTDATA}/multikml-doc.kmz
# ${TEMP}/utkmlhellokmz.txt
# )
#ADD_TEST( utKmlprettykml ${CXX_TEST_PATH}/otbKmlTestsprettykml
# kmlprettykml
# ${INPUTDATA}/polygons2d.kml
# ${TEMP}/utkmlprettykml.txt
# )
#ADD_TEST( utKmlprintgeometry ${CXX_TEST_PATH}/otbKmlTestsprintgeometry
# kmlprintgeometry
# ${INPUTDATA}/polygons2d.kml
)
ADD_TEST( utKmlprettykml ${UTILITIES_TESTS}
--compare-ascii ${TOL}
${BASELINE_FILES}/utkmlprettykml.txt
${TEMP}/utkmlprettykml.txt
kmlprettykml
${INPUTDATA}/polygons2d.kml
${TEMP}/utkmlprettykml.txt
)
ADD_TEST( utKmlprintgeometry ${UTILITIES_TESTS}
kmlprintgeometry
${INPUTDATA}/polygons2d.kml
# ${TEMP}/utkmlprintgeometry.txt
# )
)
# ------- Fichiers sources CXX -----------------------------------
......@@ -435,6 +438,20 @@ svmGenericKernelBasicOperationsTest.cxx
otbSVMComposedKernelFunctorTest.cxx
ossimRadarSatSupport.cxx
itkScaleInvariantFeatureImageFilterTest.cxx
kmlcreatekml.cc
kmlhelloattrs.cc
kmlhelloenum.cc
kmlhellofolder.cc
kmlhellogeometry.cc
kmlhellohref.cc
kmlhellokmz.cc
kmlhelloregion.cc
kmlhelloworld.cc
kmlparsekml.cc
kmlprettykml.cc
kmlprintgeometry.cc
kmlhellofeatures.cc
kmlprint.cc
)
IF(OTB_COMPILE_JPEG2000)
......@@ -470,7 +487,7 @@ IF(NOT BUILD_SHARED_LIBS)
ENDIF(NOT BUILD_SHARED_LIBS)
ADD_EXECUTABLE(otbUtilitiesTests otbUtilitiesTests.cxx ${UtilitiesTests_SRCS})
TARGET_LINK_LIBRARIES(otbUtilitiesTests OTBIO OTBCommon gdal ITKIO ITKAlgorithms ITKStatistics ITKCommon otbossim otbsvm otb6S tinyXML )
TARGET_LINK_LIBRARIES(otbUtilitiesTests OTBIO OTBCommon gdal ITKIO ITKAlgorithms ITKStatistics ITKCommon otbossim otbsvm otb6S tinyXML otbkml)
IF(OTB_COMPILE_JPEG2000)
TARGET_LINK_LIBRARIES(otbUtilitiesTests otbopenjpeg)
......@@ -499,25 +516,6 @@ ENDIF(UNIX)
#ENDFOREACH(loop_var)
# ROMAIN
# ------- CXX and EXECUTABLES files for KML Tests -----------------------------------
# hellofeatures
#FOREACH(filename createkml helloattrs helloenum hellofolder
# hellogeometry hellohref hellokmz helloregion helloserializer
# helloworld parsekml prettykml printgeometry
# )
# ADD_EXECUTABLE(otbKmlTests${filename} kml${filename}.cc )
# TARGET_LINK_LIBRARIES(otbKmlTests${filename} otbkml OTBIO OTBCommon)
# IF( OTB_USE_EXTERNAL_EXPAT )
# TARGET_LINK_LIBRARIES(otbKmlTests${filename} expat)
# ELSE( OTB_USE_EXTERNAL_EXPAT )
# TARGET_LINK_LIBRARIES(otbKmlTests${filename} otbexpat)
# ENDIF( OTB_USE_EXTERNAL_EXPAT )
# IF(UNIX)
# TARGET_LINK_LIBRARIES (otbKmlTests${filename} m)
# ENDIF(UNIX)
#ENDFOREACH(filename)
# Original 6S main executable in C
# ADD_EXECUTABLE(otb6SMain 6SMainTest.cxx )
......
......@@ -18,66 +18,72 @@
=========================================================================*/
// this file defines the otbMultiScaleTest for the test driver
// and all it expects is that you have a function called RegisterTests
#if defined(_MSC_VER)
#pragma warning ( disable : 4786 )
#endif
#include <iostream>
#include "otbTestMain.h"
void RegisterTests()
{
REGISTER_TEST(kmlcreatekml);
}
// Copyright 2008, Google Inc. All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are met:
//
// 1. Redistributions of source code must retain the above copyright notice,
// this list of conditions and the following disclaimer.
// 2. Redistributions in binary form must reproduce the above copyright notice,
// this list of conditions and the following disclaimer in the documentation
// and/or other materials provided with the distribution.
// 3. Neither the name of Google Inc. nor the names of its contributors may be
// used to endorse or promote products derived from this software without
// specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
// WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
// MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
// EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
// OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
// WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
// OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
// ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
// createkml.cc
// This program uses the KmlFactory to create a Point Placemark and
// prints the resultant KML on standard output.
#include <iostream>
#include <string>
#include "kml/dom.h"
#include "kml/util/kmlprint.h"
// libkml types are in the kmldom namespace
using kmldom::Coordinates;
using kmldom::Kml;
using kmldom::CoordinatesPtr;
using kmldom::KmlPtr;
using kmldom::KmlFactory;
using kmldom::Placemark;
using kmldom::Point;
using kmldom::PlacemarkPtr;
using kmldom::PointPtr;
int kmlcreatekml(int argc, char * argv[]) {
int kmlcreatekml(int argc, char* argv[]) {
// Get the factory singleton to create KML elements.
KmlFactory* factory = KmlFactory::GetFactory();
// Create <coordinates>.
Coordinates* coordinates = factory->CreateCoordinates();
CoordinatesPtr coordinates = factory->CreateCoordinates();
// Create <coordinates>-122.0816695,37.42052549<coordinates>
coordinates->add_point2(-122.0816695,37.42052549);
coordinates->add_latlng(37.42052549,-122.0816695);
// Create <Point> and give it <coordinates>.
Point* point = factory->CreatePoint();
PointPtr point = factory->CreatePoint();
point->set_coordinates(coordinates); // point takes ownership
// Create <Placemark> and give it a <name> and the <Point>.
Placemark* placemark = factory->CreatePlacemark();
PlacemarkPtr placemark = factory->CreatePlacemark();
placemark->set_name("Cool Statue");
placemark->set_geometry(point); // placemark takes ownership
// Create <kml> and give it <Placemark>.
Kml* kml = factory->CreateKml();
KmlPtr kml = factory->CreateKml();
kml->set_feature(placemark); // kml takes ownership.
// Serialize to XML
std::string xml = kmldom::SerializePretty(*kml);
std::string xml = kmldom::SerializePretty(kml);
// Print to stdout
G_kmlprint.flux.open(argv[1]);
G_kmlprint.flux << xml;
G_kmlprint.flux.close();
// Release memory
delete kml; // Frees all child elements
return EXIT_SUCCESS;
std::cout << xml;
return EXIT_SUCCESS;
}
......@@ -18,92 +18,93 @@
=========================================================================*/
// this file defines the otbMultiScaleTest for the test driver
// and all it expects is that you have a function called RegisterTests
#if defined(_MSC_VER)
#pragma warning ( disable : 4786 )
#endif
#include <iostream>
#include "otbTestMain.h"
void RegisterTests()
{
REGISTER_TEST(kmlhelloattrs);
}
// Sample of parse and dom access of attributes.
//#include <assert.h>
// Copyright 2008, Google Inc. All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are met:
//
// 1. Redistributions of source code must retain the above copyright notice,
// this list of conditions and the following disclaimer.
// 2. Redistributions in binary form must reproduce the above copyright notice,
// this list of conditions and the following disclaimer in the documentation
// and/or other materials provided with the distribution.
// 3. Neither the name of Google Inc. nor the names of its contributors may be
// used to endorse or promote products derived from this software without
// specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
// WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
// MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
// EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
// OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
// WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
// OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
// ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
// Sample of parse and DOM access of attributes.
#include <assert.h>
#include <iostream>
#include <string>
#include "kml/dom.h"
using kmldom::Element;
using kmldom::HotSpot;
using kmldom::IconStyle;
using kmldom::Placemark;
#include "kml/util/kmlprint.h"
using kmldom::ElementPtr;
using kmldom::HotSpotPtr;
using kmldom::IconStylePtr;
using kmldom::PlacemarkPtr;
using std::cout;
using std::endl;
void CheckHotSpot() {
const std::string kml(
"<IconStyle id=\"is42\">"
"<hotSpot x=\"0.5\" y=\"123\" xunits=\"fraction\" yunits=\"pixels\"/>"
"</IconStyle>");
Element* root = kmldom::Parse(kml, NULL);
ElementPtr root = kmldom::Parse(kml, NULL);
// Verify the parse went fine.
assert(root); // The kml is perfect.
const IconStyle* iconstyle = kmldom::AsIconStyle(root);
const IconStylePtr iconstyle = kmldom::AsIconStyle(root);
assert(true == iconstyle->has_hotspot());
const HotSpot* hotspot = iconstyle->hotspot();
const HotSpotPtr hotspot = iconstyle->get_hotspot();
assert(true == hotspot->has_x());
assert(0.5 == hotspot->x());
assert(0.5 == hotspot->get_x());
assert(true == hotspot->has_y());
assert(123 == hotspot->y());
assert(123 == hotspot->get_y());
assert(true == hotspot->has_xunits());
assert(kmldom::UNITS_FRACTION == hotspot->xunits());
assert(kmldom::UNITS_FRACTION == hotspot->get_xunits());
assert(true == hotspot->has_yunits());
assert(kmldom::UNITS_PIXELS == hotspot->yunits());
assert(kmldom::UNITS_PIXELS == hotspot->get_yunits());
// Serialize the sample.
std::string parsed_kml = kmldom::SerializePretty(*hotspot);
G_kmlprint.flux <<"parsed_kml: " <<parsed_kml<<std::endl;
// std::cout << parsed_kml << std::endl;
// Free all resources allocated by the parser.
delete root;
std::string parsed_kml = kmldom::SerializePretty(hotspot);
cout << parsed_kml << endl;
}