1.1 --- a/Code/BasicFilters/otbPrintableImageFilter.h Thu Jul 02 15:06:19 2009 +0200
1.2 +++ b/Code/BasicFilters/otbPrintableImageFilter.h Thu Jul 02 15:07:20 2009 +0200
1.3 @@ -48,12 +48,12 @@
1.4 m_ObjectColor.Fill(255);
1.5 };
1.6 ~MaskFunctor(){};
1.7 -
1.8 +
1.9 typedef TInputPixel InputPixelType;
1.10 typedef TMaskPixel MaskPixelType;
1.11 typedef TOutputPixel OutputPixelType;
1.12 typedef typename OutputPixelType::ValueType OutputInternalPixelType;
1.13 -
1.14 +
1.15 MaskPixelType GetBackgroundValue()
1.16 {
1.17 return m_BackgroundValue;
1.18 @@ -62,7 +62,7 @@
1.19 {
1.20 m_BackgroundValue = val;
1.21 }
1.22 -
1.23 +
1.24 OutputPixelType GetObjectColor()
1.25 {
1.26 return m_ObjectColor;
1.27 @@ -71,7 +71,7 @@
1.28 {
1.29 m_ObjectColor = val;
1.30 }
1.31 -
1.32 +
1.33 inline OutputPixelType operator()(InputPixelType inPix, MaskPixelType maskPix) const
1.34 {
1.35 OutputPixelType outPix;
1.36 @@ -87,10 +87,10 @@
1.37 {
1.38 outPix = m_ObjectColor;
1.39 }
1.40 -
1.41 +
1.42 return outPix;
1.43 }
1.44 -
1.45 +
1.46 protected:
1.47 MaskPixelType m_BackgroundValue;
1.48 OutputPixelType m_ObjectColor;
1.49 @@ -101,18 +101,18 @@
1.50 /**
1.51 * \class PrintableImageFilter
1.52 * \brief This class is a helper class to turn a vector image to a generic 8 bytes RGB image.
1.53 - * A mask can be used to highlight some object represebted by the same value.
1.54 - * The mask is a binary image. Background MaskValue is used to precise which
1.55 - * value of the mask are objects (default 0).
1.56 + * A mask can be used to highlight some objects represented by the same value.
1.57 + * The mask is a binary image. Background MaskValue is used to precise which
1.58 + * value of the mask are objects (default 0).
1.59 * Output object color can be set using m_ObjectColor (default white).
1.60 - * The output is a 3 channels image, each channel is a channel of the input image.
1.61 - * They can be selected usin m_ChannelList or SetChannel(int ch ) method.
1.62 + * The output is a 3 channel image, each channel is a channel of the input image.
1.63 + * They can be selected using m_ChannelList or SetChannel(int ch ) method.
1.64 *
1.65 * It is useful for publications for instance.
1.66 - *
1.67 + *
1.68 * \sa itkImageToImageFilter
1.69 **/
1.70 -
1.71 +
1.72 template <class TInputImage , class TMaskImage = otb::Image<unsigned char, 2> >
1.73 class ITK_EXPORT PrintableImageFilter :
1.74 public itk::ImageToImageFilter<TInputImage, otb::VectorImage<unsigned char, 2> >
1.75 @@ -123,56 +123,60 @@
1.76 <TInputImage, otb::VectorImage<unsigned char,2> > Superclass;
1.77 typedef itk::SmartPointer<Self> Pointer;
1.78 typedef itk::SmartPointer<const Self> ConstPointer;
1.79 -
1.80 +
1.81 typedef TInputImage InputImageType;
1.82 typedef typename InputImageType::PixelType InputPixelType;
1.83 typedef typename InputImageType::InternalPixelType InputInternalPixelType;
1.84 +// typedef typename itk::NumericTraits<InputPixelType>::ValueType InputInternalPixelType;
1.85 typedef unsigned char OutputInternalPixelType;
1.86 typedef VectorImage<OutputInternalPixelType,2> OutputImageType;
1.87 typedef OutputImageType::PixelType OutputPixelType;
1.88 -
1.89 +
1.90 typedef TMaskImage MaskImageType;
1.91 typedef typename MaskImageType::Pointer MaskImagePointerType;
1.92 - typedef typename MaskImageType::PixelType MaskPixelType;
1.93 + typedef typename MaskImageType::PixelType MaskPixelType;
1.94
1.95 - typedef VectorRescaleIntensityImageFilter<InputImageType,OutputImageType> VectorRescalerType;
1.96 -
1.97 +
1.98 +
1.99 typedef otb::MultiChannelExtractROI<InputInternalPixelType,
1.100 InputInternalPixelType> ChannelExtractorType;
1.101 typedef typename ChannelExtractorType::ChannelsType ChannelsType;
1.102
1.103 + typedef VectorRescaleIntensityImageFilter
1.104 + <typename ChannelExtractorType::OutputImageType,OutputImageType> VectorRescalerType;
1.105 +
1.106 typedef Functor::MaskFunctor<InputPixelType,MaskPixelType,OutputPixelType> FunctorType;
1.107 - typedef itk::BinaryFunctorImageFilter<OutputImageType, MaskImageType,
1.108 + typedef itk::BinaryFunctorImageFilter<OutputImageType, MaskImageType,
1.109 OutputImageType, FunctorType > FunctorFilterType;
1.110 typedef typename FunctorFilterType::Pointer FunctorFilterPointerType;
1.111
1.112 /** Method for creation through object factory */
1.113 itkNewMacro(Self);
1.114 -
1.115 +
1.116 /** Run-time type information */
1.117 itkTypeMacro(PrintableImageFilter,
1.118 itk::ImageToImageFilter);
1.119 -
1.120 +
1.121 /** Display */
1.122 void PrintSelf( std::ostream& os, itk::Indent indent ) const;
1.123 -
1.124 +
1.125 void SetChannel( unsigned int channel);
1.126 const ChannelsType GetChannels(void) const;
1.127 -
1.128 +
1.129 otbSetObjectMemberMacro(Rescaler,AutomaticInputMinMaxComputation,bool);
1.130 otbGetObjectMemberMacro(Rescaler,AutomaticInputMinMaxComputation,bool);
1.131 otbSetObjectMemberMacro(Rescaler,InputMinimum,InputPixelType);
1.132 otbGetObjectMemberMacro(Rescaler,InputMinimum,InputPixelType);
1.133 otbSetObjectMemberMacro(Rescaler,InputMaximum,InputPixelType);
1.134 otbGetObjectMemberMacro(Rescaler,InputMaximum,InputPixelType);
1.135 -
1.136 -
1.137 +
1.138 +
1.139 /**
1.140 * If set, only pixels within the mask will be classified.
1.141 * \param mask The input mask.
1.142 */
1.143 void SetInputMask(const MaskImageType * mask);
1.144 -
1.145 +
1.146 /**
1.147 * Get the input mask.
1.148 * \return The mask.
1.149 @@ -181,7 +185,7 @@
1.150
1.151 itkSetMacro(UseMask, bool);
1.152 itkGetMacro(UseMask, bool);
1.153 -
1.154 +
1.155 ChannelsType const GetChannelList()
1.156 {
1.157 return m_ChannelList;
1.158 @@ -196,7 +200,7 @@
1.159 m_ChannelList = chList;
1.160 this->Modified();
1.161 }
1.162 -
1.163 +
1.164 /** Output Mask Object color. */
1.165 void SetObjectColor( OutputPixelType val )
1.166 {
1.167 @@ -209,14 +213,14 @@
1.168 this->Modified();
1.169 }
1.170 itkGetMacro(ObjectColor, OutputPixelType);
1.171 -
1.172 +
1.173 void SetBackgroundMaskValue( MaskPixelType val )
1.174 {
1.175 m_BackgroundMaskValue = val;
1.176 m_MaskFilter->GetFunctor().SetBackgroundValue( val );
1.177 this->Modified();
1.178 }
1.179 - itkGetMacro(BackgroundMaskValue, MaskPixelType);
1.180 + itkGetMacro(BackgroundMaskValue, MaskPixelType);
1.181
1.182 protected:
1.183
1.184 @@ -224,12 +228,12 @@
1.185
1.186 void BeforeGenerateData();
1.187 void GenerateData();
1.188 -
1.189 +
1.190 private:
1.191 -
1.192 +
1.193 PrintableImageFilter(Self&); // intentionally not implemented
1.194 void operator=(const Self&); // intentionally not implemented
1.195 -
1.196 +
1.197 typename VectorRescalerType::Pointer m_Rescaler;
1.198 typename ChannelExtractorType::Pointer m_Extractor;
1.199 // Foreground mask value
1.200 @@ -244,9 +248,9 @@
1.201 //MaskPixelType m_ForegroundMaskValue;
1.202 // Background mask value
1.203 MaskPixelType m_BackgroundMaskValue;
1.204 -
1.205 +
1.206 };
1.207 -
1.208 +
1.209 } // end namespace otb
1.210
1.211 #ifndef OTB_MANUAL_INSTANTIATION
2.1 --- a/Code/Projections/CMakeLists.txt Thu Jul 02 15:06:19 2009 +0200
2.2 +++ b/Code/Projections/CMakeLists.txt Thu Jul 02 15:07:20 2009 +0200
2.3 @@ -1,10 +1,15 @@
2.4 FILE(GLOB OTBProjections_SRCS "*.cxx" )
2.5
2.6 +IF( NOT OTB_USE_CURL )
2.7 + LIST(REMOVE_ITEM OTBProjections_SRCS "${CMAKE_CURRENT_SOURCE_DIR}/otbPlaceNameToLonLat.cxx" )
2.8 + LIST(REMOVE_ITEM OTBProjections_SRCS "${CMAKE_CURRENT_SOURCE_DIR}/otbCoordinateToName.cxx" )
2.9 +ENDIF( NOT OTB_USE_CURL )
2.10 +
2.11 ADD_LIBRARY(OTBProjections ${OTBProjections_SRCS})
2.12 # TARGET_LINK_LIBRARIES(OTBProjections OTBIO otbossimplugins)
2.13 TARGET_LINK_LIBRARIES(OTBProjections OTBIO)
2.14 IF( OTB_USE_CURL )
2.15 - TARGET_LINK_LIBRARIES (OTBProjections ${CURL_LIBRARY})
2.16 + TARGET_LINK_LIBRARIES (OTBProjections ${CURL_LIBRARY} tinyXML)
2.17 ENDIF( OTB_USE_CURL )
2.18 IF(OTB_LIBRARY_PROPERTIES)
2.19 SET_TARGET_PROPERTIES(OTBProjections PROPERTIES ${OTB_LIBRARY_PROPERTIES})
2.20 @@ -22,7 +27,7 @@
2.21 FILE(GLOB __files2 "${CMAKE_CURRENT_SOURCE_DIR}/*.txx")
2.22 IF( NOT OTB_USE_CURL )
2.23 LIST(REMOVE_ITEM __files1 "${CMAKE_CURRENT_SOURCE_DIR}/otbPlaceNameToLonLat.h" )
2.24 - LIST(REMOVE_ITEM __files2 "${CMAKE_CURRENT_SOURCE_DIR}/otbPlaceNameToLonLat.txx" )
2.25 + LIST(REMOVE_ITEM __files2 "${CMAKE_CURRENT_SOURCE_DIR}/otbCoordinateToName.h" )
2.26 ENDIF( NOT OTB_USE_CURL )
2.27 INSTALL(FILES ${__files1} ${__files2}
2.28 DESTINATION ${OTB_INSTALL_INCLUDE_DIR_CM24}/Projections
3.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
3.2 +++ b/Code/Projections/otbCoordinateToName.cxx Thu Jul 02 15:07:20 2009 +0200
3.3 @@ -0,0 +1,143 @@
3.4 +/*=========================================================================
3.5 +
3.6 + Program: ORFEO Toolbox
3.7 + Language: C++
3.8 + Date: $Date$
3.9 + Version: $Revision$
3.10 +
3.11 +
3.12 + Copyright (c) Centre National d'Etudes Spatiales. All rights reserved.
3.13 + See OTBCopyright.txt for details.
3.14 +
3.15 +
3.16 + This software is distributed WITHOUT ANY WARRANTY; without even
3.17 + the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
3.18 + PURPOSE. See the above copyright notices for more information.
3.19 +
3.20 +=========================================================================*/
3.21 +
3.22 +#include "otbCoordinateToName.h"
3.23 +#include "tinyxml.h"
3.24 +#include <curl/curl.h>
3.25 +#include "otbMacro.h"
3.26 +
3.27 +namespace otb
3.28 +{
3.29 +
3.30 +/**
3.31 + * Constructor
3.32 + */
3.33 +
3.34 +CoordinateToName::CoordinateToName()
3.35 +{
3.36 + m_Lon = -1000.0;
3.37 + m_Lat = -1000.0;
3.38 + m_PlaceName = "";
3.39 + m_CountryName = "";
3.40 +}
3.41 +
3.42 +/**
3.43 + *
3.44 + */
3.45 +
3.46 +void
3.47 +CoordinateToName
3.48 +::PrintSelf(std::ostream& os, itk::Indent indent) const
3.49 +{
3.50 + this->Superclass::PrintSelf(os,indent);
3.51 + os << indent << " m_Lon " << m_Lon << std::endl;
3.52 + os << indent << " m_Lat " << m_Lat << std::endl;
3.53 + os << indent << " m_PlaceName " << m_PlaceName << std::endl;
3.54 +}
3.55 +
3.56 +
3.57 +bool CoordinateToName::Evaluate()
3.58 +{
3.59 +
3.60 + std::ostringstream urlStream;
3.61 + urlStream << "http://ws.geonames.org/findNearbyPlaceName?lat=";
3.62 + urlStream << m_Lat;
3.63 + urlStream << "&lng=";
3.64 + urlStream << m_Lon;
3.65 + otbMsgDevMacro("CoordinateToName: retrieve url " << urlStream.str());
3.66 + RetrieveXML(urlStream);
3.67 + ParseXMLGeonames();
3.68 +
3.69 + return true;
3.70 +}
3.71 +
3.72 +/*
3.73 +//This method will be necessary to process the file directly in memory
3.74 +//without writing it to the disk. Waiting for the xml lib to handle that
3.75 +//also
3.76 +static size_t
3.77 +curlHandlerWriteMemoryCallback(void *ptr, size_t size, size_t nmemb,
3.78 + void *data)
3.79 +{
3.80 + register int realsize = (int)(size * nmemb);
3.81 +
3.82 + std::vector<char> *vec
3.83 + = static_cast<std::vector<char>*>(data);
3.84 + const char* chPtr = static_cast<char*>(ptr);
3.85 + vec->insert(vec->end(), chPtr, chPtr + realsize);
3.86 +
3.87 + return realsize;
3.88 +}
3.89 +*/
3.90 +
3.91 +void CoordinateToName::RetrieveXML(std::ostringstream& urlStream)
3.92 +{
3.93 +
3.94 + CURL *curl;
3.95 + CURLcode res;
3.96 +
3.97 + FILE* output_file = fopen("out.xml","w");
3.98 + curl = curl_easy_init();
3.99 +
3.100 +// std::cout << "URL data " << urlStream.str().data() << std::endl;
3.101 +
3.102 +
3.103 + char url[256];
3.104 + strcpy(url,urlStream.str().data());
3.105 +
3.106 +// std::cout << url << std::endl;
3.107 + if (curl)
3.108 + {
3.109 + std::vector<char> chunk;
3.110 + curl_easy_setopt(curl, CURLOPT_URL, url);
3.111 + /*
3.112 + //Step needed to handle curl without temporary file
3.113 + curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION,this->curlHandlerWriteMemoryCallback);
3.114 + curl_easy_setopt(curl, CURLOPT_FILE, (void *)&chunk);
3.115 + */
3.116 + curl_easy_setopt(curl, CURLOPT_WRITEDATA, output_file);
3.117 + res = curl_easy_perform(curl);
3.118 +
3.119 + fclose(output_file);
3.120 + /* always cleanup */
3.121 + curl_easy_cleanup(curl);
3.122 + }
3.123 +
3.124 +}
3.125 +
3.126 +
3.127 +void CoordinateToName::ParseXMLGeonames()
3.128 +{
3.129 + TiXmlDocument doc( "out.xml" );
3.130 + doc.LoadFile();
3.131 + TiXmlHandle docHandle( &doc );
3.132 +
3.133 + TiXmlElement* childName = docHandle.FirstChild( "geonames" ).FirstChild( "geoname" ).FirstChild( "name" ).Element();
3.134 + if ( childName )
3.135 + {
3.136 + m_PlaceName=childName->GetText();
3.137 + }
3.138 + TiXmlElement* childCountryName = docHandle.FirstChild( "geonames" ).FirstChild( "geoname" ).FirstChild( "countryName" ).Element();
3.139 + if ( childCountryName )
3.140 + {
3.141 + m_CountryName=childCountryName->GetText();
3.142 + }
3.143 +}
3.144 +
3.145 +} // namespace otb
3.146 +
4.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
4.2 +++ b/Code/Projections/otbCoordinateToName.h Thu Jul 02 15:07:20 2009 +0200
4.3 @@ -0,0 +1,80 @@
4.4 +/*=========================================================================
4.5 +
4.6 + Program: ORFEO Toolbox
4.7 + Language: C++
4.8 + Date: $Date$
4.9 + Version: $Revision$
4.10 +
4.11 +
4.12 + Copyright (c) Centre National d'Etudes Spatiales. All rights reserved.
4.13 + See OTBCopyright.txt for details.
4.14 +
4.15 +
4.16 + This software is distributed WITHOUT ANY WARRANTY; without even
4.17 + the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
4.18 + PURPOSE. See the above copyright notices for more information.
4.19 +
4.20 +=========================================================================*/
4.21 +#ifndef __otbCoordinateToName_h
4.22 +#define __otbCoordinateToName_h
4.23 +
4.24 +#include "itkObject.h"
4.25 +#include "itkObjectFactory.h"
4.26 +
4.27 +namespace otb
4.28 +{
4.29 +
4.30 +/**
4.31 + * \class CoordinateToName
4.32 + * \brief Retrieve Geographical information for Longitude and Latitude coordinates
4.33 + *
4.34 +
4.35 + */
4.36 +
4.37 +
4.38 +class ITK_EXPORT CoordinateToName : public itk::Object
4.39 +{
4.40 +public:
4.41 + /** Standard class typedefs. */
4.42 + typedef CoordinateToName Self;
4.43 + typedef itk::SmartPointer<Self> Pointer;
4.44 + typedef itk::SmartPointer<const Self> ConstPointer;
4.45 +
4.46 +
4.47 + typedef itk::Object Superclass;
4.48 +
4.49 + itkTypeMacro(CoordinateToName, Object);
4.50 + /** Method for creation through the object factory. */
4.51 + itkNewMacro(Self);
4.52 +
4.53 + itkGetMacro( Lon, double );
4.54 + itkGetMacro( Lat, double );
4.55 + itkGetMacro( PlaceName, std::string );
4.56 + itkGetMacro( CountryName, std::string );
4.57 +
4.58 + itkSetMacro( Lon, double );
4.59 + itkSetMacro( Lat, double );
4.60 +
4.61 + virtual bool Evaluate();
4.62 +
4.63 +protected:
4.64 + CoordinateToName();
4.65 + ~CoordinateToName() {};
4.66 + void PrintSelf(std::ostream& os, itk::Indent indent) const;
4.67 + void RetrieveXML(std::ostringstream& urlStream);
4.68 + void ParseXMLGeonames();
4.69 +
4.70 +private:
4.71 + CoordinateToName( const Self& ); //purposely not implemented
4.72 + void operator=( const Self& ); //purposely not implemented
4.73 +
4.74 + double m_Lon;
4.75 + double m_Lat;
4.76 + std::string m_PlaceName;
4.77 + std::string m_CountryName;
4.78 +};
4.79 +
4.80 +} // namespace otb
4.81 +
4.82 +
4.83 +#endif
5.1 --- a/Code/Projections/otbGenericRSTransform.h Thu Jul 02 15:06:19 2009 +0200
5.2 +++ b/Code/Projections/otbGenericRSTransform.h Thu Jul 02 15:07:20 2009 +0200
5.3 @@ -25,18 +25,13 @@
5.4 #include "itkTransform.h"
5.5 #include "itkExceptionObject.h"
5.6 #include "itkMacro.h"
5.7 -// #include "base/ossimGpt.h"
5.8 -// #include "base/ossimDpt.h"
5.9 -// #include "projection/ossimProjection.h"
5.10 -// #include "base/ossimEllipsoid.h"
5.11 -// #include "base/ossimEllipsoidFactory.h"
5.12 -// #include "base/ossimString.h"
5.13 -// #include "ossimOgcWktTranslator.h"
5.14 #include "otbCompositeTransform.h"
5.15
5.16 namespace otb
5.17 {
5.18
5.19 + enum TransformAccuracy {UNKNOWN, ESTIMATE, PRECISE};
5.20 +
5.21 /** \class GenericRSTransform
5.22 * \brief This is the class to handle generic remote sensing transform
5.23 *
5.24 @@ -183,6 +178,15 @@
5.25
5.26 itkGetConstReferenceMacro(OutputSpacing, SpacingType);
5.27
5.28 + /** Check if the transform is up to date */
5.29 + virtual bool IsUpToDate()
5.30 + {
5.31 + return m_TransformUpToDate;
5.32 + }
5.33 +
5.34 + /** Get Transform accuracy */
5.35 + itkGetMacro(TransformAccuracy, TransformAccuracy);
5.36 +
5.37 /** Methods prototypes */
5.38 virtual const TransformType * GetTransform() const;
5.39
5.40 @@ -234,6 +238,8 @@
5.41 GenericTransformPointerType m_InputTransform;
5.42 GenericTransformPointerType m_OutputTransform;
5.43 bool m_TransformUpToDate;
5.44 + TransformAccuracy m_TransformAccuracy;
5.45 +
5.46 };
5.47
5.48
6.1 --- a/Code/Projections/otbGenericRSTransform.txx Thu Jul 02 15:06:19 2009 +0200
6.2 +++ b/Code/Projections/otbGenericRSTransform.txx Thu Jul 02 15:07:20 2009 +0200
6.3 @@ -47,6 +47,7 @@
6.4 m_InputTransform = NULL;
6.5 m_OutputTransform = NULL;
6.6 m_TransformUpToDate = false;
6.7 + m_TransformAccuracy = UNKNOWN;
6.8 }
6.9
6.10
6.11 @@ -176,22 +177,6 @@
6.12 }
6.13
6.14
6.15 -
6.16 -// template<class TScalarType, unsigned int NInputDimensions, unsigned int NOutputDimensions>
6.17 -// const typename GenericRSTransform<TScalarType, NInputDimensions, NOutputDimensions>::TransformType*
6.18 -// GenericRSTransform<TScalarType, NInputDimensions, NOutputDimensions>
6.19 -// ::GetTransform ()
6.20 -// {
6.21 -// itkDebugMacro("returning MapProjection address " << this->m_Transform );
6.22 -// if ((reinstanciateTransform) || (m_Transform == NULL))
6.23 -// {
6.24 -// this->InstanciateProjection();
6.25 -// }
6.26 -//
6.27 -// return this->m_Transform;
6.28 -// }
6.29 -
6.30 -
6.31 template<class TScalarType, unsigned int NInputDimensions, unsigned int NOutputDimensions>
6.32 const typename GenericRSTransform<TScalarType, NInputDimensions, NOutputDimensions>::TransformType*
6.33 GenericRSTransform<TScalarType, NInputDimensions, NOutputDimensions>
6.34 @@ -220,24 +205,15 @@
6.35 {
6.36 m_Transform = TransformType::New();
6.37
6.38 - //If the information was not specified by the user, it is filled from the metadata
6.39 - // InputVectorDataPointer input = this->GetInput();
6.40 - // const itk::MetaDataDictionary & m_InputDictionary = input->GetMetaDataDictionary();
6.41 -
6.42 if (m_InputKeywordList.GetSize() == 0)
6.43 {
6.44 - ossimKeywordlist kwl;
6.45 - itk::ExposeMetaData<ossimKeywordlist>(m_InputDictionary, MetaDataKey::OSSIMKeywordlistKey, kwl );
6.46 - m_InputKeywordList.SetKeywordlist(kwl);
6.47 + itk::ExposeMetaData<ImageKeywordlist>(m_InputDictionary, MetaDataKey::OSSIMKeywordlistKey, m_InputKeywordList );
6.48 }
6.49 if (m_InputProjectionRef.empty())
6.50 {
6.51 itk::ExposeMetaData<std::string>(m_InputDictionary, MetaDataKey::ProjectionRefKey, m_InputProjectionRef );
6.52 }
6.53
6.54 -
6.55 -
6.56 -
6.57 otbMsgDevMacro(<< "Information to instanciate transform: ");
6.58 otbMsgDevMacro(<< " * Input Origin: " << m_InputOrigin);
6.59 otbMsgDevMacro(<< " * Input Spacing: " << m_InputSpacing);
6.60 @@ -250,12 +226,19 @@
6.61 otbMsgDevMacro(<< " * Output Origin: " << m_OutputOrigin);
6.62 otbMsgDevMacro(<< " * Output Spacing: " << m_OutputSpacing);
6.63
6.64 + //Make sure that the state is clean:
6.65 + m_InputTransform = NULL;
6.66 + m_OutputTransform = NULL;
6.67 +
6.68 bool firstTransformGiveGeo = true;
6.69 + bool inputTransformIsSensor = false;
6.70 + bool inputTransformIsMap = false;
6.71 + bool outputTransformIsSensor = false;
6.72 + bool outputTransformIsMap = false;
6.73
6.74 //*****************************
6.75 //Set the input transformation
6.76 //*****************************
6.77 -
6.78 try
6.79 {
6.80 if (m_InputKeywordList.GetSize() > 0)
6.81 @@ -268,6 +251,7 @@
6.82 sensorModel->SetDEMDirectory(m_DEMDirectory);
6.83 }
6.84 m_InputTransform = sensorModel.GetPointer();
6.85 + inputTransformIsSensor = true;
6.86 otbMsgDevMacro(<< "Input projection set to sensor model.");
6.87 }
6.88 }
6.89 @@ -285,6 +269,7 @@
6.90 if (mapTransform->GetMapProjection() != NULL)
6.91 {
6.92 m_InputTransform = mapTransform.GetPointer();
6.93 + inputTransformIsMap = true;
6.94 otbMsgDevMacro(<< "Input projection set to map transform: " << m_InputTransform);
6.95 }
6.96
6.97 @@ -333,6 +318,7 @@
6.98 sensorModel->SetDEMDirectory(m_DEMDirectory);
6.99 }
6.100 m_OutputTransform = sensorModel.GetPointer();
6.101 + outputTransformIsSensor = true;
6.102 otbMsgDevMacro(<< "Output projection set to sensor model");
6.103 }
6.104 }
6.105 @@ -350,6 +336,7 @@
6.106 if (mapTransform->GetMapProjection() != NULL)
6.107 {
6.108 m_OutputTransform = mapTransform.GetPointer();
6.109 + outputTransformIsMap = true;
6.110 otbMsgDevMacro(<< "Output projection set to map transform: " << m_OutputTransform);
6.111 }
6.112
6.113 @@ -366,27 +353,25 @@
6.114 }
6.115
6.116
6.117 - //If the projection information for the output is provided, propagate it
6.118 -// OutputVectorDataPointer output = this->GetOutput();
6.119 -// itk::MetaDataDictionary & m_OutputDictionary = output->GetMetaDataDictionary();
6.120 -
6.121 - //FIXME: this part will need to be propagated independantly in the VectorDataProjectionFilter
6.122 -// if (m_OutputKeywordList.GetSize() != 0)
6.123 -// {
6.124 -// ossimKeywordlist kwl;
6.125 -// m_OutputKeywordList.convertToOSSIMKeywordlist (kwl);
6.126 -// itk::EncapsulateMetaData<ossimKeywordlist>(m_OutputDictionary, MetaDataKey::OSSIMKeywordlistKey, kwl );
6.127 -// }
6.128 -// if ( !m_OutputProjectionRef.empty())
6.129 -// {
6.130 -// itk::EncapsulateMetaData<std::string>(m_OutputDictionary, MetaDataKey::ProjectionRefKey, m_OutputProjectionRef );
6.131 -// }
6.132 -
6.133 -
6.134 m_Transform->SetFirstTransform(m_InputTransform);
6.135 m_Transform->SetSecondTransform(m_OutputTransform);
6.136 + m_TransformUpToDate = true;
6.137 + //The acurracy information is a simplistic model for now and should be refined
6.138 + if ((inputTransformIsSensor || outputTransformIsSensor) && (m_DEMDirectory.empty()))
6.139 + {
6.140 + //Sensor model without DEM
6.141 + m_TransformAccuracy = ESTIMATE;
6.142 + }
6.143 + else if (!inputTransformIsSensor && !outputTransformIsSensor && !inputTransformIsMap && !outputTransformIsMap)
6.144 + {
6.145 + //no transform
6.146 + m_TransformAccuracy = UNKNOWN;
6.147 + }
6.148 + else
6.149 + {
6.150
6.151 - m_TransformUpToDate = true;
6.152 + m_TransformAccuracy = PRECISE;
6.153 + }
6.154
6.155 }
6.156
7.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
7.2 +++ b/Code/Projections/otbPlaceNameToLonLat.cxx Thu Jul 02 15:07:20 2009 +0200
7.3 @@ -0,0 +1,188 @@
7.4 +/*=========================================================================
7.5 +
7.6 + Program: ORFEO Toolbox
7.7 + Language: C++
7.8 + Date: $Date$
7.9 + Version: $Revision$
7.10 +
7.11 +
7.12 + Copyright (c) Centre National d'Etudes Spatiales. All rights reserved.
7.13 + See OTBCopyright.txt for details.
7.14 +
7.15 +
7.16 + This software is distributed WITHOUT ANY WARRANTY; without even
7.17 + the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
7.18 + PURPOSE. See the above copyright notices for more information.
7.19 +
7.20 +=========================================================================*/
7.21 +
7.22 +#include "otbPlaceNameToLonLat.h"
7.23 +#include "tinyxml.h"
7.24 +#include <curl/curl.h>
7.25 +
7.26 +
7.27 +namespace otb
7.28 +{
7.29 +
7.30 +/**
7.31 + * Constructor
7.32 + */
7.33 +
7.34 +PlaceNameToLonLat::PlaceNameToLonLat()
7.35 +{
7.36 + m_Lon = -1000.0;
7.37 + m_Lat = -1000.0;
7.38 + m_PlaceName = "Where everything started";
7.39 +}
7.40 +
7.41 +/**
7.42 + *
7.43 + */
7.44 +
7.45 +void
7.46 +PlaceNameToLonLat
7.47 +::PrintSelf(std::ostream& os, itk::Indent indent) const
7.48 +{
7.49 + this->Superclass::PrintSelf(os,indent);
7.50 + os << indent << " m_Lon " << m_Lon << std::endl;
7.51 + os << indent << " m_Lat " << m_Lat << std::endl;
7.52 + os << indent << " m_PlaceName " << m_PlaceName << std::endl;
7.53 +}
7.54 +
7.55 +
7.56 +bool PlaceNameToLonLat::Evaluate()
7.57 +{
7.58 + std::string::size_type loc = m_PlaceName.find(" ", 0 );
7.59 + while (loc != std::string::npos)
7.60 + {
7.61 + m_PlaceName.replace(loc, 1, "+");
7.62 + loc = m_PlaceName.find(" ", loc);
7.63 + }
7.64 +
7.65 + if ((m_Lat == -1000.0) && (m_Lon == -1000.0))
7.66 + {
7.67 + std::ostringstream urlStream;
7.68 + urlStream << "http://maps.google.com/maps?q=";
7.69 + urlStream << m_PlaceName;
7.70 + urlStream << "&sll=38.9594,-95.2655&sspn=119.526,360&output=kml&ie=utf-8&v=2.2&cv=4.2.0180.1134&hl=en";
7.71 + RetrieveXML(urlStream);
7.72 + ParseXMLGoogle();
7.73 + }
7.74 +
7.75 + if ((m_Lat == -1000.0) && (m_Lon == -1000.0))
7.76 + {
7.77 + std::ostringstream urlStream;
7.78 + urlStream << "http://api.local.yahoo.com/MapsService/V1/geocode?appid=com.sun.blueprints.ui.geocoder&location=";
7.79 + urlStream << m_PlaceName;
7.80 + RetrieveXML(urlStream);
7.81 + ParseXMLYahoo();
7.82 + }
7.83 +
7.84 + if ((m_Lat == -1000.0) && (m_Lon == -1000.0))
7.85 + {
7.86 + std::cout << "Search Error: fallback on the origin" << std::endl;
7.87 + m_Lat = 43.560204;
7.88 + m_Lon = 1.480736;
7.89 + return false;
7.90 + }
7.91 + return true;
7.92 +}
7.93 +
7.94 +/*
7.95 +//This method will be necessary to process the file directly in memory
7.96 +//without writing it to the disk. Waiting for the xml lib to handle that
7.97 +//also
7.98 +static size_t
7.99 +curlHandlerWriteMemoryCallback(void *ptr, size_t size, size_t nmemb,
7.100 + void *data)
7.101 +{
7.102 + register int realsize = (int)(size * nmemb);
7.103 +
7.104 + std::vector<char> *vec
7.105 + = static_cast<std::vector<char>*>(data);
7.106 + const char* chPtr = static_cast<char*>(ptr);
7.107 + vec->insert(vec->end(), chPtr, chPtr + realsize);
7.108 +
7.109 + return realsize;
7.110 +}
7.111 +*/
7.112 +
7.113 +void PlaceNameToLonLat::RetrieveXML(std::ostringstream& urlStream)
7.114 +{
7.115 +
7.116 + CURL *curl;
7.117 + CURLcode res;
7.118 +
7.119 + FILE* output_file = fopen("out.xml","w");
7.120 + curl = curl_easy_init();
7.121 +
7.122 +// std::cout << "URL data " << urlStream.str().data() << std::endl;
7.123 +
7.124 +
7.125 + char url[256];
7.126 + strcpy(url,urlStream.str().data());
7.127 +
7.128 +// std::cout << url << std::endl;
7.129 + if (curl)
7.130 + {
7.131 + std::vector<char> chunk;
7.132 + curl_easy_setopt(curl, CURLOPT_URL, url);
7.133 + /*
7.134 + //Step needed to handle curl without temporary file
7.135 + curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION,this->curlHandlerWriteMemoryCallback);
7.136 + curl_easy_setopt(curl, CURLOPT_FILE, (void *)&chunk);
7.137 + */
7.138 + curl_easy_setopt(curl, CURLOPT_WRITEDATA, output_file);
7.139 + res = curl_easy_perform(curl);
7.140 +
7.141 + fclose(output_file);
7.142 + /* always cleanup */
7.143 + curl_easy_cleanup(curl);
7.144 + }
7.145 +
7.146 +}
7.147 +
7.148 +
7.149 +void PlaceNameToLonLat::ParseXMLYahoo()
7.150 +{
7.151 + TiXmlDocument doc( "out.xml" );
7.152 + doc.LoadFile();
7.153 + TiXmlHandle docHandle( &doc );
7.154 +
7.155 + TiXmlElement* childLat = docHandle.FirstChild( "ResultSet" ).FirstChild( "Result" ).FirstChild( "Latitude" ).Element();
7.156 + if ( childLat )
7.157 + {
7.158 + m_Lat=atof(childLat->GetText());
7.159 + }
7.160 + TiXmlElement* childLon = docHandle.FirstChild( "ResultSet" ).FirstChild( "Result" ).FirstChild( "Longitude" ).Element();
7.161 + if ( childLon )
7.162 + {
7.163 + m_Lon=atof(childLon->GetText());
7.164 + }
7.165 +
7.166 +}
7.167 +
7.168 +void PlaceNameToLonLat::ParseXMLGoogle()
7.169 +{
7.170 + TiXmlDocument doc( "out.xml" );
7.171 + doc.LoadFile();
7.172 + TiXmlHandle docHandle( &doc );
7.173 +
7.174 + TiXmlElement* childLat = docHandle.FirstChild( "kml" ).FirstChild( "Placemark" ).FirstChild( "LookAt" ).FirstChild( "latitude" ).Element();
7.175 + if ( childLat )
7.176 + {
7.177 + m_Lat=atof(childLat->GetText());
7.178 + }
7.179 + TiXmlElement* childLon = docHandle.FirstChild( "kml" ).FirstChild( "Placemark" ).FirstChild( "LookAt" ).FirstChild( "longitude" ).Element();
7.180 + if ( childLon )
7.181 + {
7.182 + m_Lon=atof(childLon->GetText());
7.183 + }
7.184 +
7.185 +}
7.186 +void PlaceNameToLonLat::ParseXMLGeonames()
7.187 +{
7.188 +
7.189 +}
7.190 +
7.191 +} // namespace otb
8.1 --- a/Code/Projections/otbPlaceNameToLonLat.h Thu Jul 02 15:06:19 2009 +0200
8.2 +++ b/Code/Projections/otbPlaceNameToLonLat.h Thu Jul 02 15:07:20 2009 +0200
8.3 @@ -80,8 +80,5 @@
8.4
8.5 } // namespace otb
8.6
8.7 -#ifndef OTB_MANUAL_INSTANTIATION
8.8 -#include "otbPlaceNameToLonLat.txx"
8.9 -#endif
8.10
8.11 #endif
9.1 --- a/Code/Projections/otbPlaceNameToLonLat.txx Thu Jul 02 15:06:19 2009 +0200
9.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000
9.3 @@ -1,192 +0,0 @@
9.4 -/*=========================================================================
9.5 -
9.6 - Program: ORFEO Toolbox
9.7 - Language: C++
9.8 - Date: $Date$
9.9 - Version: $Revision$
9.10 -
9.11 -
9.12 - Copyright (c) Centre National d'Etudes Spatiales. All rights reserved.
9.13 - See OTBCopyright.txt for details.
9.14 -
9.15 -
9.16 - This software is distributed WITHOUT ANY WARRANTY; without even
9.17 - the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
9.18 - PURPOSE. See the above copyright notices for more information.
9.19 -
9.20 -=========================================================================*/
9.21 -#ifndef __otbPlaceNameToLonLat_txx
9.22 -#define __otbPlaceNameToLonLat_txx
9.23 -
9.24 -#include "otbPlaceNameToLonLat.h"
9.25 -#include "tinyxml.h"
9.26 -#include <curl/curl.h>
9.27 -
9.28 -
9.29 -namespace otb
9.30 -{
9.31 -
9.32 -/**
9.33 - * Constructor
9.34 - */
9.35 -
9.36 -PlaceNameToLonLat::PlaceNameToLonLat()
9.37 -{
9.38 - m_Lon = -1000.0;
9.39 - m_Lat = -1000.0;
9.40 - m_PlaceName = "Where everything started";
9.41 -}
9.42 -
9.43 -/**
9.44 - *
9.45 - */
9.46 -
9.47 -void
9.48 -PlaceNameToLonLat
9.49 -::PrintSelf(std::ostream& os, itk::Indent indent) const
9.50 -{
9.51 - this->Superclass::PrintSelf(os,indent);
9.52 - os << indent << " m_Lon " << m_Lon << std::endl;
9.53 - os << indent << " m_Lat " << m_Lat << std::endl;
9.54 - os << indent << " m_PlaceName " << m_PlaceName << std::endl;
9.55 -}
9.56 -
9.57 -
9.58 -bool PlaceNameToLonLat::Evaluate()
9.59 -{
9.60 - std::string::size_type loc = m_PlaceName.find(" ", 0 );
9.61 - while (loc != std::string::npos)
9.62 - {
9.63 - m_PlaceName.replace(loc, 1, "+");
9.64 - loc = m_PlaceName.find(" ", loc);
9.65 - }
9.66 -
9.67 - if ((m_Lat == -1000.0) && (m_Lon == -1000.0))
9.68 - {
9.69 - std::ostringstream urlStream;
9.70 - urlStream << "http://maps.google.com/maps?q=";
9.71 - urlStream << m_PlaceName;
9.72 - urlStream << "&sll=38.9594,-95.2655&sspn=119.526,360&output=kml&ie=utf-8&v=2.2&cv=4.2.0180.1134&hl=en";
9.73 - RetrieveXML(urlStream);
9.74 - ParseXMLGoogle();
9.75 - }
9.76 -
9.77 - if ((m_Lat == -1000.0) && (m_Lon == -1000.0))
9.78 - {
9.79 - std::ostringstream urlStream;
9.80 - urlStream << "http://api.local.yahoo.com/MapsService/V1/geocode?appid=com.sun.blueprints.ui.geocoder&location=";
9.81 - urlStream << m_PlaceName;
9.82 - RetrieveXML(urlStream);
9.83 - ParseXMLYahoo();
9.84 - }
9.85 -
9.86 - if ((m_Lat == -1000.0) && (m_Lon == -1000.0))
9.87 - {
9.88 - std::cout << "Search Error: fallback on the origin" << std::endl;
9.89 - m_Lat = 43.560204;
9.90 - m_Lon = 1.480736;
9.91 - return false;
9.92 - }
9.93 - return true;
9.94 -}
9.95 -
9.96 -/*
9.97 -//This method will be necessary to process the file directly in memory
9.98 -//without writing it to the disk. Waiting for the xml lib to handle that
9.99 -//also
9.100 -static size_t
9.101 -curlHandlerWriteMemoryCallback(void *ptr, size_t size, size_t nmemb,
9.102 - void *data)
9.103 -{
9.104 - register int realsize = (int)(size * nmemb);
9.105 -
9.106 - std::vector<char> *vec
9.107 - = static_cast<std::vector<char>*>(data);
9.108 - const char* chPtr = static_cast<char*>(ptr);
9.109 - vec->insert(vec->end(), chPtr, chPtr + realsize);
9.110 -
9.111 - return realsize;
9.112 -}
9.113 -*/
9.114 -
9.115 -void PlaceNameToLonLat::RetrieveXML(std::ostringstream& urlStream)
9.116 -{
9.117 -
9.118 - CURL *curl;
9.119 - CURLcode res;
9.120 -
9.121 - FILE* output_file = fopen("out.xml","w");
9.122 - curl = curl_easy_init();
9.123 -
9.124 -// std::cout << "URL data " << urlStream.str().data() << std::endl;
9.125 -
9.126 -
9.127 - char url[256];
9.128 - strcpy(url,urlStream.str().data());
9.129 -
9.130 -// std::cout << url << std::endl;
9.131 - if (curl)
9.132 - {
9.133 - std::vector<char> chunk;
9.134 - curl_easy_setopt(curl, CURLOPT_URL, url);
9.135 - /*
9.136 - //Step needed to handle curl without temporary file
9.137 - curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION,this->curlHandlerWriteMemoryCallback);
9.138 - curl_easy_setopt(curl, CURLOPT_FILE, (void *)&chunk);
9.139 - */
9.140 - curl_easy_setopt(curl, CURLOPT_WRITEDATA, output_file);
9.141 - res = curl_easy_perform(curl);
9.142 -
9.143 - fclose(output_file);
9.144 - /* always cleanup */
9.145 - curl_easy_cleanup(curl);
9.146 - }
9.147 -
9.148 -}
9.149 -
9.150 -
9.151 -void PlaceNameToLonLat::ParseXMLYahoo()
9.152 -{
9.153 - TiXmlDocument doc( "out.xml" );
9.154 - doc.LoadFile();
9.155 - TiXmlHandle docHandle( &doc );
9.156 -
9.157 - TiXmlElement* childLat = docHandle.FirstChild( "ResultSet" ).FirstChild( "Result" ).FirstChild( "Latitude" ).Element();
9.158 - if ( childLat )
9.159 - {
9.160 - m_Lat=atof(childLat->GetText());
9.161 - }
9.162 - TiXmlElement* childLon = docHandle.FirstChild( "ResultSet" ).FirstChild( "Result" ).FirstChild( "Longitude" ).Element();
9.163 - if ( childLon )
9.164 - {
9.165 - m_Lon=atof(childLon->GetText());
9.166 - }
9.167 -
9.168 -}
9.169 -
9.170 -void PlaceNameToLonLat::ParseXMLGoogle()
9.171 -{
9.172 - TiXmlDocument doc( "out.xml" );
9.173 - doc.LoadFile();
9.174 - TiXmlHandle docHandle( &doc );
9.175 -
9.176 - TiXmlElement* childLat = docHandle.FirstChild( "kml" ).FirstChild( "Placemark" ).FirstChild( "LookAt" ).FirstChild( "latitude" ).Element();
9.177 - if ( childLat )
9.178 - {
9.179 - m_Lat=atof(childLat->GetText());
9.180 - }
9.181 - TiXmlElement* childLon = docHandle.FirstChild( "kml" ).FirstChild( "Placemark" ).FirstChild( "LookAt" ).FirstChild( "longitude" ).Element();
9.182 - if ( childLon )
9.183 - {
9.184 - m_Lon=atof(childLon->GetText());
9.185 - }
9.186 -
9.187 -}
9.188 -void PlaceNameToLonLat::ParseXMLGeonames()
9.189 -{
9.190 -
9.191 -}
9.192 -
9.193 -} // namespace otb
9.194 -
9.195 -#endif
10.1 --- a/Code/Visualization/otbImageLayer.h Thu Jul 02 15:06:19 2009 +0200
10.2 +++ b/Code/Visualization/otbImageLayer.h Thu Jul 02 15:07:20 2009 +0200
10.3 @@ -27,6 +27,7 @@
10.4 #include "otbListSampleToHistogramListGenerator.h"
10.5
10.6 #include "otbRenderingImageFilter.h"
10.7 +#include "otbGenericRSTransform.h"
10.8
10.9 namespace otb
10.10 {
10.11 @@ -67,6 +68,9 @@
10.12 typedef typename ImageType::RegionType RegionType;
10.13 typedef typename ImageType::IndexType IndexType;
10.14
10.15 + typedef itk::Point<double,2> PointType;
10.16 + typedef otb::GenericRSTransform<double> TransformType;
10.17 +
10.18 /** Output image typedef */
10.19 typedef TOutputImage OutputImageType;
10.20 typedef typename OutputImageType::PixelType OutputPixelType;
10.21 @@ -172,6 +176,9 @@
10.22 /** Get the pixel description */
10.23 virtual std::string GetPixelDescription(const IndexType & index);
10.24
10.25 + /** Get the pixel location */
10.26 + virtual PointType GetPixelLocation(const IndexType & index);
10.27 +
10.28 protected:
10.29 /** Constructor */
10.30 ImageLayer();
10.31 @@ -192,13 +199,14 @@
10.32 /** Update the images */
10.33 virtual void RenderImages();
10.34
10.35 + virtual void InitTransform();
10.36 +
10.37 /** Find out the histogram size from the pixel */
10.38 unsigned int PixelSize(ImagePointerType image, ScalarType* v) const;
10.39 unsigned int PixelSize(ImagePointerType image, VectorPixelType* v) const;
10.40 unsigned int PixelSize(ImagePointerType image, RGBPixelType* v) const;
10.41 unsigned int PixelSize(ImagePointerType image, RGBAPixelType* v) const;
10.42
10.43 -
10.44 private:
10.45 ImageLayer(const Self&); // purposely not implemented
10.46 void operator=(const Self&); // purposely not implemented
10.47 @@ -224,6 +232,13 @@
10.48 ExtractFilterPointerType m_ExtractFilter;
10.49 ExtractFilterPointerType m_ScaledExtractFilter;
10.50
10.51 + /** Coordinate transform */
10.52 + TransformType::Pointer m_Transform;
10.53 +
10.54 + /** General info about the image*/
10.55 + std::string m_PlaceName;//FIXME the call should be done by a more general method outside of the layer
10.56 + std::string m_CountryName;//which would also handle the dependance to curl
10.57 +
10.58 }; // end class
10.59 } // end namespace otb
10.60
11.1 --- a/Code/Visualization/otbImageLayer.txx Thu Jul 02 15:06:19 2009 +0200
11.2 +++ b/Code/Visualization/otbImageLayer.txx Thu Jul 02 15:07:20 2009 +0200
11.3 @@ -23,6 +23,9 @@
11.4 #include "itkTimeProbe.h"
11.5 #include "otbStandardRenderingFunction.h"
11.6
11.7 +#include "otbImageKeywordlist.h"
11.8 +// #include "otbCoordinateToName.h"
11.9 +
11.10 namespace otb
11.11 {
11.12
11.13 @@ -54,6 +57,11 @@
11.14 // Wiring
11.15 m_ExtractRenderingFilter->SetInput(m_ExtractFilter->GetOutput());
11.16 m_ScaledExtractRenderingFilter->SetInput(m_ScaledExtractFilter->GetOutput());
11.17 +
11.18 + m_Transform = TransformType::New();
11.19 +
11.20 + m_PlaceName = "";
11.21 + m_CountryName = "";
11.22 }
11.23
11.24 template <class TImage, class TOutputImage>
11.25 @@ -80,6 +88,9 @@
11.26
11.27 // Render images
11.28 this->RenderImages();
11.29 +
11.30 + // Initialize the geotransform
11.31 + this->InitTransform();
11.32 }
11.33
11.34 template <class TImage, class TOutputImage>
11.35 @@ -226,9 +237,63 @@
11.36 oss<<" (ql)"<<std::endl<<m_RenderingFunction->Describe(m_Quicklook->GetPixel(ssindex));
11.37 }
11.38 }
11.39 + //here, we consider that if the transform is not ready (call to InitTransform)
11.40 + //the user of the class don't want to use it
11.41 + if (m_Transform->IsUpToDate())
11.42 + {
11.43 + if (m_Transform->GetTransformAccuracy() != UNKNOWN)
11.44 + {
11.45 + PointType point = this->GetPixelLocation(index);
11.46 + oss<< setiosflags(ios::fixed) << setprecision(6) << "Lon: " << point[0] << " Lat: "<< point[1] << std::endl;
11.47 + if (m_Transform->GetTransformAccuracy() == PRECISE) oss<< "(precise location)" << std::endl;
11.48 + if (m_Transform->GetTransformAccuracy() == ESTIMATE) oss<< "(estimated location)" << std::endl;
11.49 +
11.50 +// if ((m_PlaceName == "") && (m_CountryName == ""))
11.51 +// {
11.52 +// CoordinateToName::Pointer conv = CoordinateToName::New();
11.53 +// conv->SetLon(point[0]);
11.54 +// conv->SetLat(point[1]);
11.55 +// conv->Evaluate();
11.56 +//
11.57 +// m_PlaceName = conv->GetPlaceName();
11.58 +// m_CountryName = conv->GetCountryName();
11.59 +// }
11.60 +// if (m_PlaceName != "") oss << "Near " << m_PlaceName;
11.61 +// if (m_CountryName != "") oss << " in " << m_CountryName;
11.62 + }
11.63 + else
11.64 + {
11.65 + oss << "Location unknown" << std::endl;
11.66 + }
11.67 + }
11.68 return oss.str();
11.69 }
11.70
11.71 +template <class TImage, class TOutputImage>
11.72 +typename ImageLayer<TImage,TOutputImage>::PointType
11.73 +ImageLayer<TImage,TOutputImage>
11.74 +::GetPixelLocation(const IndexType & index)
11.75 +{
11.76 + PointType inputPoint;
11.77 + inputPoint[0] = index[0];
11.78 + inputPoint[1] = index[1];
11.79 + return m_Transform->TransformPoint(inputPoint);
11.80 +}
11.81 +
11.82 +
11.83 +template <class TImage, class TOutputImage>
11.84 +void
11.85 +ImageLayer<TImage,TOutputImage>
11.86 +::InitTransform()
11.87 +{
11.88 + const itk::MetaDataDictionary & inputDict = m_Image->GetMetaDataDictionary();
11.89 + m_Transform->SetInputDictionary(inputDict);
11.90 + m_Transform->SetInputOrigin(m_Image->GetOrigin());
11.91 + m_Transform->SetInputSpacing(m_Image->GetSpacing());
11.92 + // m_Transform->SetDEMDirectory(m_DEMDirectory);
11.93 + m_Transform->InstanciateTransform();
11.94 +}
11.95 +
11.96 }
11.97
11.98 #endif
12.1 --- a/Examples/Projections/CMakeLists.txt Thu Jul 02 15:06:19 2009 +0200
12.2 +++ b/Examples/Projections/CMakeLists.txt Thu Jul 02 15:07:20 2009 +0200
12.3 @@ -22,6 +22,10 @@
12.4 IF( OTB_USE_CURL )
12.5 ADD_EXECUTABLE(PlaceNameToLonLatExample PlaceNameToLonLatExample.cxx )
12.6 TARGET_LINK_LIBRARIES(PlaceNameToLonLatExample OTBProjections OTBCommon OTBIO ${CURL_LIBRARY} tinyXML)
12.7 +
12.8 +ADD_EXECUTABLE(CoordinateToNameExample CoordinateToNameExample.cxx )
12.9 +TARGET_LINK_LIBRARIES(CoordinateToNameExample OTBProjections OTBCommon OTBIO ${CURL_LIBRARY} tinyXML)
12.10 +
12.11 ENDIF( OTB_USE_CURL )
12.12
12.13 ADD_EXECUTABLE(VectorDataProjectionExample VectorDataProjectionExample.cxx )
12.14 @@ -111,6 +115,10 @@
12.15 PlaceNameToLonLatExampleTest
12.16 Toulouse
12.17 )
12.18 +ADD_TEST(prTeCoordinateToNameExampleTest ${EXE_TESTS2}
12.19 + CoordinateToNameExampleTest
12.20 + 103.78 1.29
12.21 +)
12.22 ENDIF( OTB_USE_CURL )
12.23
12.24 INCLUDE_DIRECTORIES(${OTB_SOURCE_DIR}/Testing/Code)
13.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
13.2 +++ b/Examples/Projections/CoordinateToNameExample.cxx Thu Jul 02 15:07:20 2009 +0200
13.3 @@ -0,0 +1,52 @@
13.4 +/*=========================================================================
13.5 +
13.6 + Program: ORFEO Toolbox
13.7 + Language: C++
13.8 + Date: $Date$
13.9 + Version: $Revision$
13.10 +
13.11 +
13.12 + Copyright (c) Centre National d'Etudes Spatiales. All rights reserved.
13.13 + See OTBCopyright.txt for details.
13.14 +
13.15 +
13.16 + This software is distributed WITHOUT ANY WARRANTY; without even
13.17 + the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
13.18 + PURPOSE. See the above copyright notices for more information.
13.19 +
13.20 +=========================================================================*/
13.21 +#if defined(_MSC_VER)
13.22 +#pragma warning ( disable : 4786 )
13.23 +#endif
13.24 +
13.25 +
13.26 +#include "otbCoordinateToName.h"
13.27 +
13.28 +
13.29 +int main( int argc, char* argv[] )
13.30 +{
13.31 +
13.32 + if (argc!=3)
13.33 + {
13.34 + std::cout << argv[0] <<" <lon> <lat>"
13.35 + << std::endl;
13.36 +
13.37 + return EXIT_FAILURE;
13.38 + }
13.39 +
13.40 +
13.41 + otb::CoordinateToName::Pointer conv = otb::CoordinateToName::New();
13.42 + conv->SetLon(atof(argv[1]));
13.43 + conv->SetLat(atof(argv[2]));
13.44 + conv->Evaluate();
13.45 +
13.46 + std::string name = conv->GetPlaceName();
13.47 + std::string country = conv->GetCountryName();
13.48 +
13.49 + std::cout << "Nearby place: " << name << std::endl;
13.50 + std::cout << "Country: " << country << std::endl;
13.51 +
13.52 +
13.53 + return EXIT_SUCCESS;
13.54 +
13.55 +}
14.1 --- a/Examples/Projections/otbProjectionsExamplesTests2.cxx Thu Jul 02 15:06:19 2009 +0200
14.2 +++ b/Examples/Projections/otbProjectionsExamplesTests2.cxx Thu Jul 02 15:07:20 2009 +0200
14.3 @@ -27,9 +27,12 @@
14.4 void RegisterTests()
14.5 {
14.6 REGISTER_TEST(PlaceNameToLonLatExampleTest);
14.7 + REGISTER_TEST(CoordinateToNameExampleTest);
14.8 }
14.9
14.10
14.11 #undef main
14.12 #define main PlaceNameToLonLatExampleTest
14.13 #include "PlaceNameToLonLatExample.cxx"
14.14 +#define main CoordinateToNameExampleTest
14.15 +#include "CoordinateToNameExample.cxx"
14.16 \ No newline at end of file
15.1 --- a/Testing/Utilities/CMakeLists.txt Thu Jul 02 15:06:19 2009 +0200
15.2 +++ b/Testing/Utilities/CMakeLists.txt Thu Jul 02 15:07:20 2009 +0200
15.3 @@ -51,16 +51,6 @@
15.4 ossimElevManagerTest
15.5 )
15.6
15.7 -
15.8 -ADD_TEST(utTvIjBSplineScatteredDataPointSetToImageFilterTest ${UTILITIES_TESTS}
15.9 ---compare-image ${EPSILON}
15.10 - ${BASELINE}/ijBSplineScatteredDataPointSetToImageFilterTestOutput.hdr
15.11 - ${TEMP}/ijBSplineScatteredDataPointSetToImageFilterTestOutput.hdr
15.12 - ijBSplineScatteredDataPointSetToImageFilterTest
15.13 - ${INPUTDATA}/brain.png
15.14 - ${TEMP}/ijBSplineScatteredDataPointSetToImageFilterTestOutput.hdr
15.15 -)
15.16 -
15.17 # ------- lib otbsvm ------------------------------
15.18
15.19 ADD_TEST(utTuSvmKernelFunctorTest ${UTILITIES_TESTS}
15.20 @@ -442,7 +432,6 @@
15.21 ossimIntegrationTest.cxx
15.22 ossimKeywordlistTest.cxx
15.23 ossimElevManagerTest.cxx
15.24 -ijBSplineScatteredDataPointSetToImageFilterTest.cxx
15.25 svmGenericKernelFunctor.cxx
15.26 svmTest.cxx
15.27 svmGenericKernelTest.cxx
15.28 @@ -492,7 +481,6 @@
15.29
15.30 # ------- Select sources files suppress warning -----------------------------------
15.31 SET(UtilitiesTests_DisableWarning_SRCS
15.32 - ijBSplineScatteredDataPointSetToImageFilterTest.cxx
15.33 siftfast.cpp
15.34 openthreadsWorkCrew.cpp
15.35 expatchardata.cxx
16.1 --- a/Testing/Utilities/ijBSplineScatteredDataPointSetToImageFilterTest.cxx Thu Jul 02 15:06:19 2009 +0200
16.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000
16.3 @@ -1,122 +0,0 @@
16.4 -#include "otbImage.h"
16.5 -#include "otbImageFileReader.h"
16.6 -#include "otbImageFileWriter.h"
16.7 -#include "itkImageRegionIteratorWithIndex.h"
16.8 -#include "itkPointSet.h"
16.9 -#include "ijBSplineScatteredDataPointSetToImageFilter.h"
16.10 -
16.11 -/**
16.12 - * In this test, we approximate a 2-D scalar field.
16.13 - * The scattered data is derived from a segmented
16.14 - * image. We write the output to an image for
16.15 - * comparison.
16.16 - */
16.17 -int ijBSplineScatteredDataPointSetToImageFilterTest( int argc, char *argv[] )
16.18 -{
16.19 - const unsigned int ParametricDimension = 2;
16.20 - const unsigned int DataDimension = 1;
16.21 -
16.22 - typedef int PixelType;
16.23 - typedef otb::Image<PixelType, ParametricDimension> InputImageType;
16.24 - typedef double RealType;
16.25 - typedef itk::Vector<RealType, DataDimension> VectorType;
16.26 - typedef otb::Image<VectorType, ParametricDimension> VectorImageType;
16.27 - typedef itk::PointSet
16.28 - <VectorImageType::PixelType, ParametricDimension> PointSetType;
16.29 - PointSetType::Pointer pointSet = PointSetType::New();
16.30 -
16.31 - typedef otb::ImageFileReader<InputImageType> ReaderType;
16.32 - ReaderType::Pointer reader = ReaderType::New();
16.33 - reader->SetFileName( argv[1] );
16.34 - reader->Update();
16.35 -
16.36 - itk::ImageRegionIteratorWithIndex<InputImageType>
16.37 - It( reader->GetOutput(), reader->GetOutput()->GetLargestPossibleRegion() );
16.38 -
16.39 - // Iterate through the input image which consists of multivalued
16.40 - // foreground pixels (=nonzero) and background values (=zero).
16.41 - // The foreground pixels comprise the input point set.
16.42 -
16.43 - for ( It.GoToBegin(); !It.IsAtEnd(); ++It )
16.44 - {
16.45 - if ( It.Get() != itk::NumericTraits<PixelType>::Zero )
16.46 - {
16.47 - // We extract both the 2-D location of the point
16.48 - // and the pixel value of that point.
16.49 -
16.50 - PointSetType::PointType point;
16.51 - reader->GetOutput()->TransformIndexToPhysicalPoint( It.GetIndex(), point );
16.52 -
16.53 - unsigned long i = pointSet->GetNumberOfPoints();
16.54 - pointSet->SetPoint( i, point );
16.55 -
16.56 - PointSetType::PixelType V( DataDimension );
16.57 - V[0] = static_cast<RealType>( It.Get() );
16.58 - pointSet->SetPointData( i, V );
16.59 - }
16.60 - }
16.61 -
16.62 - // Instantiate the B-spline filter and set the desired parameters.
16.63 - typedef ij::BSplineScatteredDataPointSetToImageFilter
16.64 - <PointSetType, VectorImageType> FilterType;
16.65 - FilterType::Pointer filter = FilterType::New();
16.66 - filter->SetSplineOrder( 3 );
16.67 - FilterType::ArrayType ncps;
16.68 - ncps.Fill( 4 );
16.69 - filter->SetNumberOfControlPoints( ncps );
16.70 - filter->SetNumberOfLevels( 10 );
16.71 -
16.72 - // Define the parametric domain.
16.73 - filter->SetOrigin( reader->GetOutput()->GetOrigin() );
16.74 - filter->SetSpacing( reader->GetOutput()->GetSpacing() );
16.75 - filter->SetSize( reader->GetOutput()->GetLargestPossibleRegion().GetSize() );
16.76 -
16.77 - filter->SetInput( pointSet );
16.78 -
16.79 - try
16.80 - {
16.81 - filter->Update();
16.82 - }
16.83 - catch (...)
16.84 - {
16.85 - std::cerr << "Test 1: itkBSplineScatteredDataImageFilter exception thrown"
16.86 - << std::endl;
16.87 - return EXIT_FAILURE;
16.88 - }
16.89 -
16.90 - // Write the output to an image.
16.91 - typedef otb::Image<RealType, ParametricDimension> RealImageType;
16.92 - RealImageType::Pointer image = RealImageType::New();
16.93 - image->SetRegions( reader->GetOutput()->GetLargestPossibleRegion() );
16.94 - image->Allocate();
16.95 - itk::ImageRegionIteratorWithIndex<RealImageType>
16.96 - Itt( image, image->GetLargestPossibleRegion() );
16.97 -
16.98 - for ( Itt.GoToBegin(); !Itt.IsAtEnd(); ++Itt )
16.99 - {
16.100 - Itt.Set( filter->GetOutput()->GetPixel( Itt.GetIndex() )[0] );
16.101 - }
16.102 -
16.103 - typedef otb::ImageFileWriter<RealImageType> WriterType;
16.104 - WriterType::Pointer writer = WriterType::New();
16.105 - writer->SetInput( image );
16.106 - writer->SetFileName( argv[2] );
16.107 - writer->Update();
16.108 -
16.109 - return EXIT_SUCCESS;
16.110 -};
16.111 -
16.112 -
16.113 -
16.114 -
16.115 -
16.116 -
16.117 -
16.118 -
16.119 -
16.120 -
16.121 -
16.122 -
16.123 -
16.124 -
16.125 -
17.1 --- a/Testing/Utilities/otbUtilitiesTests.cxx Thu Jul 02 15:06:19 2009 +0200
17.2 +++ b/Testing/Utilities/otbUtilitiesTests.cxx Thu Jul 02 15:07:20 2009 +0200
17.3 @@ -29,7 +29,6 @@
17.4 REGISTER_TEST(ossimIntegrationTest);
17.5 REGISTER_TEST(ossimKeywordlistTest);
17.6 REGISTER_TEST(ossimElevManagerTest);
17.7 -REGISTER_TEST(ijBSplineScatteredDataPointSetToImageFilterTest);
17.8 REGISTER_TEST(svmGenericKernelFunctor);
17.9 REGISTER_TEST(svmTest);
17.10 REGISTER_TEST(svmGenericKernelTest);
18.1 --- a/Utilities/ITK/Code/Review/itkBSplineScatteredDataPointSetToImageFilter.txx Thu Jul 02 15:06:19 2009 +0200
18.2 +++ b/Utilities/ITK/Code/Review/itkBSplineScatteredDataPointSetToImageFilter.txx Thu Jul 02 15:07:20 2009 +0200
18.3 @@ -919,7 +919,9 @@
18.4 idx[dimension] %=
18.5 lattice->GetLargestPossibleRegion().GetSize()[dimension];
18.6 }
18.7 - data += ( lattice->GetPixel( idx ) * B );
18.8 +
18.9 + if(idx[dimension]>=0 && idx[dimension]<lattice->GetLargestPossibleRegion().GetSize()[dimension])
18.10 + data += ( lattice->GetPixel( idx ) * B );
18.11 }
18.12 It.Set( data );
18.13 }
19.1 --- a/Utilities/otbsvm/svm.cxx Thu Jul 02 15:06:19 2009 +0200
19.2 +++ b/Utilities/otbsvm/svm.cxx Thu Jul 02 15:07:20 2009 +0200
19.3 @@ -44,10 +44,10 @@
19.4 #if 1
19.5 void info(char *fmt,...)
19.6 {
19.7 -// va_list ap;
19.8 -// va_start(ap,fmt);
19.9 -// vprintf(fmt,ap);
19.10 -// va_end(ap);
19.11 + va_list ap;
19.12 + va_start(ap,fmt);
19.13 + vprintf(fmt,ap);
19.14 + va_end(ap);
19.15 }
19.16 void info_flush()
19.17 {