diff --git a/Code/BasicFilters/otbStreamingShrinkImageFilter.txx b/Code/BasicFilters/otbStreamingShrinkImageFilter.txx index ddad24e17663ee2c74dcc02f3a1c723643c6cc27..b8dd29dbced267e974b1f2a5fdd8ec4f1b8dbab7 100644 --- a/Code/BasicFilters/otbStreamingShrinkImageFilter.txx +++ b/Code/BasicFilters/otbStreamingShrinkImageFilter.txx @@ -183,7 +183,7 @@ StreamingShrinkImageFilter<TInputImage, TOutputImage> { inputPtr->UpdateOutputData(); } - catch (itk::ExceptionObject & err) + catch (itk::ExceptionObject & ) { this->InvokeEvent(itk::EndEvent()); throw; diff --git a/Code/IO/otbCoordinateToName.cxx b/Code/IO/otbCoordinateToName.cxx index cd06b6f3dda905afdce87034b9ecd000830a9e60..094191c106d8276d50eb0feeb3bd63c2c62313d2 100644 --- a/Code/IO/otbCoordinateToName.cxx +++ b/Code/IO/otbCoordinateToName.cxx @@ -38,6 +38,7 @@ CoordinateToName::CoordinateToName() : m_Lon(-1000.0), m_Lat(-1000.0), m_Multithread(false), m_IsValid(false), m_PlaceName(""), m_CountryName("") { + /* //Avoid collision between different instance of the class typedef itk::Statistics::MersenneTwisterRandomVariateGenerator RandomGenType; RandomGenType::Pointer randomGen = RandomGenType::GetInstance(); @@ -49,6 +50,7 @@ CoordinateToName::CoordinateToName() : filename << randomNum; filename << ".xml"; m_TempFileName = filename.str(); + */ m_Curl = CurlHelper::New(); @@ -103,7 +105,9 @@ void CoordinateToName::DoEvaluate() urlStream << "&lng="; urlStream << m_Lon; otbMsgDevMacro("CoordinateToName: retrieve url " << urlStream.str()); - RetrieveXML(urlStream); + + m_Curl->RetrieveUrlInMemory(urlStream.str(), m_CurlOutput); + std::string placeName = ""; std::string countryName = ""; ParseXMLGeonames(placeName, countryName); @@ -119,15 +123,12 @@ void CoordinateToName::DoEvaluate() } } -void CoordinateToName::RetrieveXML(const std::ostringstream& urlStream) const -{ - m_Curl->RetrieveFile(urlStream, m_TempFileName); -} - void CoordinateToName::ParseXMLGeonames(std::string& placeName, std::string& countryName) const { - TiXmlDocument doc(m_TempFileName.c_str()); - if (doc.LoadFile()) + TiXmlDocument doc; + doc.Parse(m_CurlOutput.c_str()); + + if (!doc.Error()) { TiXmlHandle docHandle(&doc); @@ -144,7 +145,6 @@ void CoordinateToName::ParseXMLGeonames(std::string& placeName, std::string& cou countryName = childCountryName->GetText(); } otbMsgDevMacro(<< "Near " << placeName << " in " << countryName); - remove(m_TempFileName.c_str()); } } diff --git a/Code/IO/otbCoordinateToName.h b/Code/IO/otbCoordinateToName.h index f6fb7f9ba0e0b95a6b463422f63d9f9f1a720dd8..a7fe8948b3e1c80251e25e944412cc79527f98c0 100644 --- a/Code/IO/otbCoordinateToName.h +++ b/Code/IO/otbCoordinateToName.h @@ -116,7 +116,6 @@ protected: CoordinateToName(); virtual ~CoordinateToName() {} void PrintSelf(std::ostream& os, itk::Indent indent) const; - void RetrieveXML(const std::ostringstream& urlStream) const; void ParseXMLGeonames(std::string& placeName, std::string& countryName) const; virtual void DoEvaluate(); @@ -139,7 +138,7 @@ private: std::string m_PlaceName; std::string m_CountryName; - std::string m_TempFileName; + std::string m_CurlOutput; CurlHelperInterface::Pointer m_Curl; diff --git a/Code/IO/otbCurlHelper.cxx b/Code/IO/otbCurlHelper.cxx index 5f83b9b9a36cb889c85a2267e041ecce22381563..8fc76b25ca1eed62c9aa01f6463f08e31d1581b5 100644 --- a/Code/IO/otbCurlHelper.cxx +++ b/Code/IO/otbCurlHelper.cxx @@ -42,12 +42,58 @@ int CurlHelper::TestUrlAvailability(const std::string& url) const curl_easy_setopt(curl, CURLOPT_USERAGENT, m_Browser.data()); curl_easy_setopt(curl, CURLOPT_URL, url.data()); // Set the dummy write function - curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, &Self::curlDummyWriteFunction); + curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, &Self::CallbackWriteDataDummy); curl_easy_setopt(curl, CURLOPT_MAXFILESIZE, 1); // Perform requet res = curl_easy_perform(curl); + + /* always cleanup */ + curl_easy_cleanup(curl); + + } + return res; +#else + otbMsgDevMacro(<< "Curl is not available, compile with OTB_USE_CURL to ON"); + return -1; +#endif +} + +int CurlHelper::RetrieveUrlInMemory(const std::string& url, std::string& output) const +{ +#ifdef OTB_USE_CURL + otbMsgDevMacro(<< "Retrieving: " << url); + CURL * curl; + CURLcode res = CURL_LAST; + + curl = curl_easy_init(); + if (curl) + { + curl_easy_setopt(curl, CURLOPT_URL, url.c_str()); + + // Set 5s timeout + curl_easy_setopt(curl, CURLOPT_TIMEOUT, 5); + + // Use our writing static function to avoid file descriptor + // pointer crash on windows + curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, &Self::CallbackWriteDataToStringStream); + + // Say the file where to write the received data + std::ostringstream* outputStream = new std::ostringstream; + curl_easy_setopt(curl, CURLOPT_WRITEDATA, (void*) outputStream); + + // Perform request + res = curl_easy_perform(curl); + + // Save output + output = outputStream->str(); + otbMsgDevMacro("curl output : " << output) + + // Clean up + delete outputStream; + curl_easy_cleanup(curl); } + otbMsgDevMacro(<< " -> " << res); return res; #else otbMsgDevMacro(<< "Curl is not available, compile with OTB_USE_CURL to ON"); @@ -83,7 +129,7 @@ int CurlHelper::RetrieveFile(const std::string& urlString, std::string filename) // Use our writing static function to avoid file descriptor // pointer crash on windows - curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, &Self::write_data); + curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, &Self::CallbackWriteDataToFile); // Say the file where to write the received data curl_easy_setopt(curl, CURLOPT_WRITEDATA, (void*) output_file); @@ -160,7 +206,7 @@ int CurlHelper::RetrieveFileMulti(const std::vector<std::string>& listURLs, // Param easy handle curl_easy_setopt(lEasyHandle, CURLOPT_USERAGENT, m_Browser.data()); curl_easy_setopt(lEasyHandle, CURLOPT_URL, (*url).data()); - curl_easy_setopt(lEasyHandle, CURLOPT_WRITEFUNCTION, &Self::write_data); + curl_easy_setopt(lEasyHandle, CURLOPT_WRITEFUNCTION, &Self::CallbackWriteDataToFile); curl_easy_setopt(lEasyHandle, CURLOPT_WRITEDATA, (void*) (*file)); // Add easy handle to multi handle @@ -279,7 +325,7 @@ int CurlHelper::RetrieveFileMulti(const std::vector<std::string>& listURLs, #endif } -size_t CurlHelper::write_data(void* ptr, size_t size, size_t nmemb, void* data) +size_t CurlHelper::CallbackWriteDataToFile(void* ptr, size_t size, size_t nmemb, void* data) { size_t written; @@ -290,4 +336,31 @@ size_t CurlHelper::write_data(void* ptr, size_t size, size_t nmemb, void* data) return written; } +/* +size_t CurlHelper::CallbackWriteDataToCharVector(void *ptr, size_t size, size_t nmemb, void *data) +{ + register int realsize = (int)(size * nmemb); + + std::vector<char> *vec + = static_cast<std::vector<char>*>(data); + const char* chPtr = static_cast<char*>(ptr); + vec->insert(vec->end(), chPtr, chPtr + realsize); + + return realsize; +} +*/ + +size_t CurlHelper::CallbackWriteDataToStringStream(void *ptr, size_t size, size_t nmemb, void *data) +{ + std::ostringstream& stream = *reinterpret_cast<std::ostringstream*>(data); + stream << reinterpret_cast<char*>(ptr); + return size * nmemb; +} + + +size_t CurlHelper::CallbackWriteDataDummy(void *ptr, size_t size, size_t nmemb, void *data) +{ + return size * nmemb; +} + } diff --git a/Code/IO/otbCurlHelper.h b/Code/IO/otbCurlHelper.h index 692fe459df03ebd9842c0778995d3d9670fc6073..b880529d008a699c8341d7aeeca2ff459e8963e6 100644 --- a/Code/IO/otbCurlHelper.h +++ b/Code/IO/otbCurlHelper.h @@ -47,6 +47,8 @@ public: int RetrieveFile(const std::ostringstream& urlStream, std::string filename) const; int RetrieveFile(const std::string& urlString, std::string filename) const; + int RetrieveUrlInMemory(const std::string& urlString, std::string& output) const; + int RetrieveFileMulti(const std::vector<std::string>& listURLs, const std::vector<std::string>& listFiles, int maxConnect) const; @@ -60,15 +62,14 @@ private: CurlHelper(const Self &); //purposely not implemented void operator =(const Self&); //purposely not implemented - size_t curlDummyWriteFunction(void*, size_t, size_t nmemb, void*) - { - return nmemb; - } - // Need to use our writing function to handle windows segfaults // Need to be static cause the CURL_OPT is expecting a pure C // function or a static c++ method. - static size_t write_data(void* ptr, size_t size, size_t nmemb, void* data); + static size_t CallbackWriteDataToFile(void* ptr, size_t size, size_t nmemb, void* data); + + static size_t CallbackWriteDataToStringStream(void* ptr, size_t size, size_t nmemb, void* data); + + static size_t CallbackWriteDataDummy(void* ptr, size_t size, size_t nmemb, void* data); // Browser Agent used std::string m_Browser; diff --git a/Code/IO/otbCurlHelperInterface.h b/Code/IO/otbCurlHelperInterface.h index 8d2d0a116bc707c516cbf86519b501759f8e0a3f..f0d4dd0df94f5ebc7dd9f29c17207ed648907aa4 100644 --- a/Code/IO/otbCurlHelperInterface.h +++ b/Code/IO/otbCurlHelperInterface.h @@ -44,12 +44,16 @@ public: itkTypeMacro(CurlHelperInterface, itk::Object); virtual int TestUrlAvailability(const std::string& url) const = 0; + virtual int RetrieveFile(const std::ostringstream& urlStream, std::string filename) const = 0; + virtual int RetrieveFile(const std::string& urlString, std::string filename) const = 0; + virtual int RetrieveUrlInMemory(const std::string& urlString, std::string& output) const = 0; + virtual int RetrieveFileMulti(const std::vector<std::string>& listURLs, - const std::vector<std::string>& listFiles, - int maxConnect) const = 0; + const std::vector<std::string>& listFiles, + int maxConnect) const = 0; protected: CurlHelperInterface() {} virtual ~CurlHelperInterface() {} diff --git a/Code/IO/otbOGRIOHelper.txx b/Code/IO/otbOGRIOHelper.txx index 894e4f4a2e9405ee98191e7ef4d45fa4f55fbd45..b676c70e1ea2db825dba84bf84532076fa1957ad 100644 --- a/Code/IO/otbOGRIOHelper.txx +++ b/Code/IO/otbOGRIOHelper.txx @@ -613,7 +613,7 @@ unsigned int OGRIOHelper<TVectorData> for (typename ChildrenListType::iterator it = children.begin(); it != children.end(); ++it) { DataNodePointerType dataNode = (*it)->Get(); - otbMsgDevMacro(<< "Type of node " << dataNode->GetNodeType() << " id" << dataNode->GetNodeId()); + //otbMsgDevMacro(<< "Type of node " << dataNode->GetNodeType() << " id " << dataNode->GetNodeId()); ++m_Kept; // Get the kwl @@ -621,6 +621,7 @@ unsigned int OGRIOHelper<TVectorData> itk::ExposeMetaData<VectorDataKeywordlist>(dataNode->GetMetaDataDictionary(), MetaDataKey::VectorDataKeywordlistKey, kwl); + // Create the field once if (ogrCurrentLayer != NULL && ogrCurrentLayer->GetFeatureCount() == 0) { @@ -628,11 +629,19 @@ unsigned int OGRIOHelper<TVectorData> // vectordatakeywordlist for (unsigned int fieldIdx = 0; fieldIdx < kwl.GetNumberOfFields(); fieldIdx++) { - if (ogrCurrentLayer->CreateField(kwl.GetNthField(fieldIdx).first) != OGRERR_NONE ) - { - itkExceptionMacro(<< "Failed to create Field "<<kwl.GetNthField(fieldIdx).first->GetNameRef()); - } - } + if ( std::string(kwl.GetNthField(fieldIdx).first->GetNameRef()) != "FID" ) + { + otbMsgDevMacro(<< " CreateField '" << kwl.GetNthField(fieldIdx).first->GetNameRef() << "'"); + if (ogrCurrentLayer->CreateField(kwl.GetNthField(fieldIdx).first) != OGRERR_NONE ) + { + itkExceptionMacro(<< "Failed to create Field "<<kwl.GetNthField(fieldIdx).first->GetNameRef()); + } + } + else + { + otbMsgDevMacro(<< "WARNING: Skipping OGR field 'FID'"); + } + } } switch (dataNode->GetNodeType()) @@ -680,11 +689,15 @@ unsigned int OGRIOHelper<TVectorData> { // Get the key of the Nth OGRFieldRefn const char * key = kwl.GetNthField(i).first->GetNameRef(); - // Edit the value of the field and add it to the current feature - ogrFeature->SetField(ogrFeature->GetFieldIndex(key) , kwl.GetFieldAsString(key).c_str()); + + if (std::string(key) != "FID") + { + // Edit the value of the field and add it to the current feature + ogrFeature->SetField(ogrFeature->GetFieldIndex(key) , kwl.GetFieldAsString(key).c_str()); + } } - ogrFeature->SetField("Name", dataNode->GetNodeId()); +// ogrFeature->SetField("Name", dataNode->GetNodeId()); ogrFeature->SetGeometry(&ogrPoint); if (ogrCurrentLayer->CreateFeature(ogrFeature) != OGRERR_NONE) @@ -738,7 +751,7 @@ unsigned int OGRIOHelper<TVectorData> ogrFeature->SetField(ogrFeature->GetFieldIndex(key) , kwl.GetFieldAsString(key).c_str()); } - ogrFeature->SetField("Name", dataNode->GetNodeId()); +// ogrFeature->SetField("Name", dataNode->GetNodeId()); ogrFeature->SetGeometry(&ogrLine); if (ogrCurrentLayer->CreateFeature(ogrFeature) != OGRERR_NONE) @@ -851,7 +864,7 @@ unsigned int OGRIOHelper<TVectorData> OGRFeature * ogrFeature; ogrFeature = OGRFeature::CreateFeature(ogrCurrentLayer->GetLayerDefn()); - ogrFeature->SetField("Name", dataNode->GetNodeId()); +// ogrFeature->SetField("Name", dataNode->GetNodeId()); ogrFeature->GetDefnRef()->SetGeomType(wkbMultiPoint); ogrFeature->SetGeometry(ogrMultiPoint); @@ -877,7 +890,7 @@ unsigned int OGRIOHelper<TVectorData> OGRFeature *ogrFeature; ogrFeature = OGRFeature::CreateFeature(ogrCurrentLayer->GetLayerDefn()); - ogrFeature->SetField("Name", dataNode->GetNodeId()); +// ogrFeature->SetField("Name", dataNode->GetNodeId()); ogrFeature->GetDefnRef()->SetGeomType(wkbMultiLineString); ogrFeature->SetGeometry(ogrMultiLineString); @@ -900,7 +913,7 @@ unsigned int OGRIOHelper<TVectorData> OGRFeature * ogrFeature; ogrFeature = OGRFeature::CreateFeature(ogrCurrentLayer->GetLayerDefn()); - ogrFeature->SetField("Name", dataNode->GetNodeId()); +// ogrFeature->SetField("Name", dataNode->GetNodeId()); ogrFeature->GetDefnRef()->SetGeomType(wkbMultiPolygon); ogrFeature->SetGeometry(ogrMultiPolygon); @@ -924,7 +937,7 @@ unsigned int OGRIOHelper<TVectorData> OGRFeature *ogrFeature; ogrFeature = OGRFeature::CreateFeature(ogrCurrentLayer->GetLayerDefn()); - ogrFeature->SetField("Name", dataNode->GetNodeId()); +// ogrFeature->SetField("Name", dataNode->GetNodeId()); ogrFeature->GetDefnRef()->SetGeomType(wkbGeometryCollection); ogrFeature->SetGeometry(ogrCollectionGeometry); diff --git a/Code/IO/otbOGRVectorDataIO.txx b/Code/IO/otbOGRVectorDataIO.txx index 53ad3faddcd383ffec1f5d6c06c47641d3eee1dc..5a9e50d8971fa1aa8871cebe01be76fd864b234b 100644 --- a/Code/IO/otbOGRVectorDataIO.txx +++ b/Code/IO/otbOGRVectorDataIO.txx @@ -282,8 +282,8 @@ void OGRVectorDataIO<TData>::Write(const VectorDataConstPointerType data, char * } chrono.Stop(); - std::cout << "OGRVectorDataIO: file saved in " << chrono.GetMeanTime() << " seconds. (" << layerKept << - " elements)" << std::endl; + otbMsgDevMacro( << "OGRVectorDataIO: file saved in " << chrono.GetMeanTime() << " seconds. (" << layerKept << + " elements)" ); otbMsgDevMacro(<< " OGRVectorDataIO::Write() "); } diff --git a/Code/IO/otbScalarBufferToImageFileWriter.h b/Code/IO/otbScalarBufferToImageFileWriter.h new file mode 100644 index 0000000000000000000000000000000000000000..4a0871fd4e8eeaaf3df49f503fbb01a2d44da730 --- /dev/null +++ b/Code/IO/otbScalarBufferToImageFileWriter.h @@ -0,0 +1,133 @@ +/*========================================================================= + + Program: ORFEO Toolbox + Language: C++ + Date: $Date$ + Version: $Revision$ + + + Copyright (c) Centre National d'Etudes Spatiales. All rights reserved. + See OTBCopyright.txt for details. + + + This software is distributed WITHOUT ANY WARRANTY; without even + the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + PURPOSE. See the above copyright notices for more information. + +=========================================================================*/ +#ifndef __otbScalarBufferToImageFileWriter_h +#define __otbScalarBufferToImageFileWriter_h + +#if defined(_MSC_VER) +#pragma warning ( disable : 4786 ) +#endif + +#include "itkProcessObject.h" +#include "otbVectorImage.h" +#include "otbImageFileWriter.h" + +namespace otb +{ +/** \class ScalarBufferToImageFileWriter + * + * \brief Record an image stored in a buffer. + * + * TBufferType is the scalar buffer type, TOutputPixelType is the type in which the image will be recorded. + * User have to precise the image size, the number of channel will be computed automatically. + * The SetFilename method precises the image name. + */ + +template <class TBufferType, class TOutputPixelType=TBufferType> +class ITK_EXPORT ScalarBufferToImageFileWriter : public itk::ProcessObject +{ +public: + + typedef ScalarBufferToImageFileWriter Self; + typedef itk::ProcessObject Superclass; + typedef itk::SmartPointer<Self> Pointer; + typedef itk::SmartPointer<const Self> ConstPointer; + + /** Method for creation through the object factory. */ + itkNewMacro(Self); + + /** Run-time type information (and related methods). */ + itkTypeMacro(ScalarBufferToImageFileWriter, itk::ProcessObject); + + /** INput typedefs */ + typedef TBufferType BufferType; + typedef TOutputPixelType OutputPixelType; + + /** Output image type */ + typedef otb::VectorImage<OutputPixelType, 2> ImageType; + typedef typename ImageType::PixelType PixelType; + typedef typename ImageType::RegionType RegionType; + typedef typename ImageType::SizeType SizeType; + typedef typename ImageType::IndexType IndexType; + + /** Writer Type*/ + typedef otb::ImageFileWriter<ImageType> WriterType; + typedef typename WriterType::Pointer WriterPointer; + + /** Filename accessor */ + otbGetObjectMemberMacro(Writer, FileName, std::string); + otbSetObjectMemberMacro(Writer, FileName, std::string); + + /** Size accessors */ + itkGetMacro(ImageSize, SizeType); + itkSetMacro(ImageSize, SizeType); + + /** Number of channels */ + itkGetMacro(NumberOfChannels, unsigned int); + itkSetMacro(NumberOfChannels, unsigned int); + + /** Inverse X spacing accessors. */ + itkGetMacro(InverseXSpacing, bool); + itkSetMacro(InverseXSpacing, bool); + + /** Buffer accessors */ + void SetBuffer( BufferType * pBuff ) + { + m_Buffer = pBuff; + } + + virtual void GenerateData(); + + virtual void Update() + { + this->GenerateData(); + } + +protected: + ScalarBufferToImageFileWriter(); + virtual ~ScalarBufferToImageFileWriter() { /* don't call ClearBuffer, user's care */} + void PrintSelf(std::ostream& os, itk::Indent indent) const; + +private: + + ScalarBufferToImageFileWriter(const Self &); //purposely not implemented + void operator =(const Self&); //purposely not implemented + + + /** Writer */ + WriterPointer m_Writer; + + /** Scalar tab buffer to writer */ + BufferType * m_Buffer; + + /**Output image number of channels */ + unsigned int m_NumberOfChannels; + + /** Output image size */ + SizeType m_ImageSize; + + /** Inverse biffer among X */ + bool m_InverseXSpacing; +}; + +} // end namespace otb + +#ifndef OTB_MANUAL_INSTANTIATION +#include "otbScalarBufferToImageFileWriter.txx" +#endif + +#endif diff --git a/Code/IO/otbScalarBufferToImageFileWriter.txx b/Code/IO/otbScalarBufferToImageFileWriter.txx new file mode 100644 index 0000000000000000000000000000000000000000..283271e0e96475871f914fda718da832827d5c21 --- /dev/null +++ b/Code/IO/otbScalarBufferToImageFileWriter.txx @@ -0,0 +1,128 @@ +/*========================================================================= + + Program: ORFEO Toolbox + Language: C++ + Date: $Date$ + Version: $Revision$ + + + Copyright (c) Centre National d'Etudes Spatiales. All rights reserved. + See OTBCopyright.txt for details. + + + This software is distributed WITHOUT ANY WARRANTY; without even + the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + PURPOSE. See the above copyright notices for more information. + +=========================================================================*/ + +#ifdef _MSC_VER +#pragma warning ( disable : 4786 ) +#endif + +#include "otbMacro.h" + +#include "otbScalarBufferToImageFileWriter.h" +#include "itkImageRegionIterator.h" +#include "itkImageRegionIteratorWithIndex.h" + +namespace otb +{ +template<class TBufferType, class TOutputPixelType> +ScalarBufferToImageFileWriter<TBufferType, TOutputPixelType> +::ScalarBufferToImageFileWriter() : m_Buffer(NULL), m_NumberOfChannels(0), m_InverseXSpacing(false) +{ + m_Writer = WriterType::New(); + m_ImageSize.Fill(0); +} + + +template<class TBufferType, class TOutputPixelType> +void +ScalarBufferToImageFileWriter<TBufferType, TOutputPixelType>::GenerateData() +{ + // Check image parameters + if( (m_ImageSize[0]==0) || (m_ImageSize[0]==0) ) + { + itkExceptionMacro("Invalid output image size, Size can't be null."); + } + + if( m_NumberOfChannels==0 ) + { + itkExceptionMacro("Invalid output image number of channels."); + } + + RegionType l_Region; + IndexType l_Id; + l_Id.Fill(0); + l_Region.SetIndex(l_Id); + l_Region.SetSize(m_ImageSize); + + typename ImageType::Pointer l_Image = ImageType::New(); + l_Image->SetRegions( l_Region ); + l_Image->SetNumberOfComponentsPerPixel(m_NumberOfChannels); + l_Image->Allocate(); + PixelType l_Pix; + + l_Pix.SetSize(m_NumberOfChannels); + l_Pix.Fill( itk::NumericTraits<OutputPixelType>::Zero ); + l_Image->FillBuffer(l_Pix); + + // 1 specific loop for each case to save time processing + if(m_InverseXSpacing == false) + { + itk::ImageRegionIterator<ImageType> it(l_Image, l_Region); + it.GoToBegin(); + + unsigned int cpt(0); + while( it.IsAtEnd()==false ) + { + for(unsigned int i=0; i<m_NumberOfChannels; i++) + { + l_Pix[i] = static_cast<OutputPixelType>(m_Buffer[cpt]); + cpt++; + } + + it.Set( l_Pix ); + ++it; + } + } + else + { + itk::ImageRegionIteratorWithIndex<ImageType> it(l_Image, l_Region); + it.GoToBegin(); + // cpt is the first component of the last pixel + unsigned int cpt(0); + while( it.IsAtEnd()==false ) + { + IndexType index = it.GetIndex(); + cpt = (m_ImageSize[1] - 1 - index[1]) * m_NumberOfChannels * m_ImageSize[0] + m_NumberOfChannels * index[0]; + + for(unsigned int i=0; i<m_NumberOfChannels; i++) + { + l_Pix[i] = static_cast<OutputPixelType>(m_Buffer[cpt+i]); + } + + it.Set( l_Pix ); + ++it; + } + } + + m_Writer->WriteGeomFileOff(); + m_Writer->SetInput( l_Image ); + m_Writer->Update(); +} + +template<class TBufferType, class TOutputPixelType> +void +ScalarBufferToImageFileWriter<TBufferType, TOutputPixelType> +::PrintSelf(std::ostream& os, itk::Indent indent) const +{ + Superclass::PrintSelf(os, indent); + os << indent << "FileName" << m_Writer->GetFileName() << std::endl; + os << indent << "Size" << m_ImageSize << std::endl; + os << indent << "NumberOfChannels" << m_NumberOfChannels << std::endl; +} + +} // end namespace otb + diff --git a/Code/ObjectDetection/otbLabeledSampleLocalizationGenerator.h b/Code/ObjectDetection/otbLabeledSampleLocalizationGenerator.h index b3ee15c9ddd0b13dc45743974cda6c1e0af485eb..2027d111d9a22ff1e150ee61c5fd0eeaf89a413a 100644 --- a/Code/ObjectDetection/otbLabeledSampleLocalizationGenerator.h +++ b/Code/ObjectDetection/otbLabeledSampleLocalizationGenerator.h @@ -78,8 +78,6 @@ public: void PushBackInput(const VectorDataType *); const VectorDataType * GetInput(unsigned int idx) const; - virtual void Update(); - /** Field name containing the class identifier */ itkGetConstMacro(ClassKey, std::string); itkSetMacro(ClassKey, std::string); @@ -124,6 +122,13 @@ private: LabeledSampleLocalizationGenerator(const Self &); //purposely not implemented void operator =(const Self&); //purposely not implemented + std::string GetNextID() + { + std::ostringstream oss; + oss << m_CurrentID++; + return oss.str(); + } + RandomGeneratorType::Pointer m_RandomGenerator; std::string m_ClassKey; @@ -132,6 +137,7 @@ private: double m_InhibitionRadius; unsigned long int m_NbMaxIteration; unsigned int m_NumberOfPositiveSamplesPerPoint; + unsigned int m_CurrentID; }; } // end namespace otb diff --git a/Code/ObjectDetection/otbLabeledSampleLocalizationGenerator.txx b/Code/ObjectDetection/otbLabeledSampleLocalizationGenerator.txx index 17273cff619f5b71bc0d008bcd289c4f8a080614..29b6cbc6f2f5fd94834cc2262c58855b95333cda 100644 --- a/Code/ObjectDetection/otbLabeledSampleLocalizationGenerator.txx +++ b/Code/ObjectDetection/otbLabeledSampleLocalizationGenerator.txx @@ -32,7 +32,8 @@ LabeledSampleLocalizationGenerator<TVectorData> m_RandomLocalizationDensity(.005), m_InhibitionRadius(5.0), m_NbMaxIteration(10000), - m_NumberOfPositiveSamplesPerPoint(50) + m_NumberOfPositiveSamplesPerPoint(50), + m_CurrentID(0) { this->SetNumberOfRequiredInputs(1); this->SetNumberOfRequiredOutputs(1); @@ -115,19 +116,8 @@ LabeledSampleLocalizationGenerator<TVectorData> ++itVector; } - //std::cout << "insiders: " << insiders.size() << std::endl; - - // Search parametrization - //unsigned int nbMaxIter = (unsigned int)(node->GetPolygonExteriorRing()->GetArea()); - // - insiders.size() * CONST_PI * vcl_pow(this->GetInhibitionRadius(), 2)) - // / (CONST_PI * vcl_pow(this->GetInhibitionRadius(), 2))); - - unsigned int nbMaxPosition = (unsigned int)(node->GetPolygonExteriorRing()->GetArea() * this->GetRandomLocalizationDensity()); - - //std::cout << "nbMaxIter: " << this->GetNbMaxIteration() << std::endl; - //std::cout << "nbMaxPosition: " << nbMaxPosition << std::endl; - // Generation + unsigned int nbMaxPosition = (unsigned int)(node->GetPolygonExteriorRing()->GetArea() * this->GetRandomLocalizationDensity()); unsigned long int nbIter = this->GetNbMaxIteration(); unsigned int nbPosition = nbMaxPosition; @@ -146,6 +136,7 @@ LabeledSampleLocalizationGenerator<TVectorData> { candidate[dim] = this->m_RandomGenerator->GetUniformVariate(rangeMin[dim], rangeMax[dim]); } + if(node->GetPolygonExteriorRing()->IsInside(candidate)) { typename PointVectorType::const_iterator pit = insiders.begin(); @@ -173,7 +164,6 @@ LabeledSampleLocalizationGenerator<TVectorData> } // Densifying positive points - for(typename PointVectorType::const_iterator iIt = insiders.begin(); iIt != insiders.end(); ++iIt) { for(unsigned int i = 0; i < m_NumberOfPositiveSamplesPerPoint; ++i) @@ -193,14 +183,6 @@ LabeledSampleLocalizationGenerator<TVectorData> return result; } -template <class TVectorData> -void -LabeledSampleLocalizationGenerator<TVectorData> -::Update() -{ - this->GenerateData(); -} - template <class TVectorData> void LabeledSampleLocalizationGenerator<TVectorData> @@ -229,7 +211,19 @@ LabeledSampleLocalizationGenerator<TVectorData> { if (itVector.Get()->IsPointFeature()) { - this->GetOutput(0)->GetDataTree()->Add(itVector.Get(), document); + // Duplicate input feature + typename DataNodeType::Pointer currentGeometry = DataNodeType::New(); + currentGeometry->SetNodeId(this->GetNextID()); + currentGeometry->SetNodeType(otb::FEATURE_POINT); + currentGeometry->SetPoint(itVector.Get()->GetPoint()); + + std::vector<std::string> fields = itVector.Get()->GetFieldList(); + for (std::vector<std::string>::const_iterator it = fields.begin(); it != fields.end(); ++it) + { + currentGeometry->SetFieldAsString( *it, itVector.Get()->GetFieldAsString(*it) ); + } + + this->GetOutput(0)->GetDataTree()->Add(currentGeometry, document); } ++itVector; } @@ -253,21 +247,21 @@ LabeledSampleLocalizationGenerator<TVectorData> for (typename PointVectorType::const_iterator it = vPoint.begin(); it != vPoint.end(); ++it) { - typename DataNodeType::Pointer CurrentGeometry = DataNodeType::New(); - CurrentGeometry->SetNodeId("FEATURE_POINT"); - CurrentGeometry->SetNodeType(otb::FEATURE_POINT); - CurrentGeometry->SetPoint(*it); - CurrentGeometry->SetFieldAsInt(this->GetClassKey(), this->GetNoClassIdentifier()); - this->GetOutput(0)->GetDataTree()->Add(CurrentGeometry, document); + typename DataNodeType::Pointer currentGeometry = DataNodeType::New(); + currentGeometry->SetNodeId(this->GetNextID()); + currentGeometry->SetNodeType(otb::FEATURE_POINT); + currentGeometry->SetPoint(*it); + currentGeometry->SetFieldAsInt(this->GetClassKey(), this->GetNoClassIdentifier()); + this->GetOutput(0)->GetDataTree()->Add(currentGeometry, document); } for (typename PointVectorType::const_iterator it = pPoint.begin(); it != pPoint.end(); ++it) { - typename DataNodeType::Pointer CurrentGeometry = DataNodeType::New(); - CurrentGeometry->SetNodeId("FEATURE_POINT"); - CurrentGeometry->SetNodeType(otb::FEATURE_POINT); - CurrentGeometry->SetPoint(*it); - CurrentGeometry->SetFieldAsInt(this->GetClassKey(), 1); - this->GetOutput(0)->GetDataTree()->Add(CurrentGeometry, document); + typename DataNodeType::Pointer currentGeometry = DataNodeType::New(); + currentGeometry->SetNodeId(this->GetNextID()); + currentGeometry->SetNodeType(otb::FEATURE_POINT); + currentGeometry->SetPoint(*it); + currentGeometry->SetFieldAsInt(this->GetClassKey(), 1); + this->GetOutput(0)->GetDataTree()->Add(currentGeometry, document); } } ++itVector; diff --git a/Code/Projections/otbGenericRSTransform.txx b/Code/Projections/otbGenericRSTransform.txx index ae5fa7a45f707e9d13826ffd3e786d1d74ea40d3..3e07a9fde1c2f891a21e75969f69fce51b3b7e07 100644 --- a/Code/Projections/otbGenericRSTransform.txx +++ b/Code/Projections/otbGenericRSTransform.txx @@ -130,18 +130,32 @@ GenericRSTransform<TScalarType, NInputDimensions, NOutputDimensions> { typedef otb::ForwardSensorModel<double, InputSpaceDimension, InputSpaceDimension> ForwardSensorModelType; typename ForwardSensorModelType::Pointer sensorModel = ForwardSensorModelType::New(); - sensorModel->SetImageGeometry(m_InputKeywordList); - if (!m_DEMDirectory.empty()) + + bool imageGeometrySet = false; + try + { + sensorModel->SetImageGeometry(m_InputKeywordList); + imageGeometrySet = true; + } + catch( itk::ExceptionObject& e) { - sensorModel->SetDEMDirectory(m_DEMDirectory); + otbMsgDevMacro(<< "Unable to instanciate a sensor model with the provided keyword list. Exception caught : " << e) } - else if (m_AverageElevation != -32768.0) + + if (imageGeometrySet) { - sensorModel->SetAverageElevation(m_AverageElevation); + if (!m_DEMDirectory.empty()) + { + sensorModel->SetDEMDirectory(m_DEMDirectory); + } + else if (m_AverageElevation != -32768.0) + { + sensorModel->SetAverageElevation(m_AverageElevation); + } + m_InputTransform = sensorModel.GetPointer(); + inputTransformIsSensor = true; + otbMsgDevMacro(<< "Input projection set to sensor model."); } - m_InputTransform = sensorModel.GetPointer(); - inputTransformIsSensor = true; - otbMsgDevMacro(<< "Input projection set to sensor model."); } if (m_InputTransform.IsNull()) //default if we didn't manage to instantiate it before @@ -194,18 +208,33 @@ GenericRSTransform<TScalarType, NInputDimensions, NOutputDimensions> { typedef otb::InverseSensorModel<double, InputSpaceDimension, OutputSpaceDimension> InverseSensorModelType; typename InverseSensorModelType::Pointer sensorModel = InverseSensorModelType::New(); - sensorModel->SetImageGeometry(m_OutputKeywordList); - if (!m_DEMDirectory.empty()) + + bool imageGeometrySet = false; + try { - sensorModel->SetDEMDirectory(m_DEMDirectory); + sensorModel->SetImageGeometry(m_OutputKeywordList); + imageGeometrySet = true; } - else if (m_AverageElevation != -32768.0) + catch( itk::ExceptionObject& e) + { + otbMsgDevMacro(<< "Unable to instanciate a sensor model with the provided output keyword list. Exception caught : " << e) + } + + + if (imageGeometrySet) { - sensorModel->SetAverageElevation(m_AverageElevation); + if (!m_DEMDirectory.empty()) + { + sensorModel->SetDEMDirectory(m_DEMDirectory); + } + else if (m_AverageElevation != -32768.0) + { + sensorModel->SetAverageElevation(m_AverageElevation); + } + m_OutputTransform = sensorModel.GetPointer(); + outputTransformIsSensor = true; + otbMsgDevMacro(<< "Output projection set to sensor model"); } - m_OutputTransform = sensorModel.GetPointer(); - outputTransformIsSensor = true; - otbMsgDevMacro(<< "Output projection set to sensor model"); } diff --git a/Code/Projections/otbPlaceNameToLonLat.cxx b/Code/Projections/otbPlaceNameToLonLat.cxx index 392a5d45b46fcaa1f66f8779f21fbc02bc38a043..eb50ff3083d9359673ac40ef477ca9cc972b4b0c 100644 --- a/Code/Projections/otbPlaceNameToLonLat.cxx +++ b/Code/Projections/otbPlaceNameToLonLat.cxx @@ -23,10 +23,6 @@ namespace otb { -/** - * Constructor - */ - PlaceNameToLonLat::PlaceNameToLonLat() : m_Lon(-1000.0), m_Lat(-1000.0), m_PlaceName("Where everything started") @@ -34,10 +30,6 @@ PlaceNameToLonLat::PlaceNameToLonLat() : m_Curl = CurlHelper::New(); } -/** - * - */ - void PlaceNameToLonLat ::PrintSelf(std::ostream& os, itk::Indent indent) const @@ -86,36 +78,17 @@ bool PlaceNameToLonLat::Evaluate() return true; } -/* -//This method will be necessary to process the file directly in memory -//without writing it to the disk. Waiting for the xml lib to handle that -//also -static size_t -curlHandlerWriteMemoryCallback(void *ptr, size_t size, size_t nmemb, - void *data) -{ - register int realsize = (int)(size * nmemb); - - std::vector<char> *vec - = static_cast<std::vector<char>*>(data); - const char* chPtr = static_cast<char*>(ptr); - vec->insert(vec->end(), chPtr, chPtr + realsize); - - return realsize; -} -*/ - void PlaceNameToLonLat::RetrieveXML(const std::ostringstream& urlStream) { - m_Curl->RetrieveFile(urlStream, "out.xml"); + m_Curl->RetrieveUrlInMemory(urlStream.str(), m_CurlOutput); } void PlaceNameToLonLat::ParseXMLYahoo() { - TiXmlDocument doc("out.xml"); - doc.LoadFile(); - TiXmlHandle docHandle(&doc); + TiXmlDocument doc; + doc.Parse(m_CurlOutput.c_str()); + TiXmlHandle docHandle(&doc); TiXmlElement* childLat = docHandle.FirstChild("ResultSet").FirstChild("Result").FirstChild("Latitude").Element(); if (childLat) { @@ -126,15 +99,14 @@ void PlaceNameToLonLat::ParseXMLYahoo() { m_Lon = atof(childLon->GetText()); } - } void PlaceNameToLonLat::ParseXMLGoogle() { - TiXmlDocument doc("out.xml"); - doc.LoadFile(); - TiXmlHandle docHandle(&doc); + TiXmlDocument doc; + doc.Parse(m_CurlOutput.c_str()); + TiXmlHandle docHandle(&doc); TiXmlElement* childLat = docHandle.FirstChild("kml").FirstChild("Placemark").FirstChild("LookAt").FirstChild( "latitude").Element(); if (childLat) @@ -147,8 +119,8 @@ void PlaceNameToLonLat::ParseXMLGoogle() { m_Lon = atof(childLon->GetText()); } - } + void PlaceNameToLonLat::ParseXMLGeonames() { diff --git a/Code/Projections/otbPlaceNameToLonLat.h b/Code/Projections/otbPlaceNameToLonLat.h index e92c1dbb420b040055379baf66c89a33c03d6e1a..79087f44735f5b8b166d0f7a9a99335bf829a564 100644 --- a/Code/Projections/otbPlaceNameToLonLat.h +++ b/Code/Projections/otbPlaceNameToLonLat.h @@ -74,6 +74,7 @@ private: SearchMethodEnum m_SearchMethod; //Not implemented yet TODO CurlHelperInterface::Pointer m_Curl; + std::string m_CurlOutput; }; diff --git a/Code/Projections/otbRationalTransform.h b/Code/Projections/otbRationalTransform.h new file mode 100644 index 0000000000000000000000000000000000000000..ad587978b25c36b9df865c95c9ccd937c89fa7d1 --- /dev/null +++ b/Code/Projections/otbRationalTransform.h @@ -0,0 +1,180 @@ +/*========================================================================= + + Program: ORFEO Toolbox + Language: C++ + Date: $Date$ + Version: $Revision$ + + + Copyright (c) Centre National d'Etudes Spatiales. All rights reserved. + See OTBCopyright.txt for details. + + + This software is distributed WITHOUT ANY WARRANTY; without even + the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + PURPOSE. See the above copyright notices for more information. + +=========================================================================*/ +#ifndef __otbRationalTransform_h +#define __otbRationalTransform_h + +#include "itkTransform.h" +#include "itkExceptionObject.h" +#include "itkMacro.h" + +namespace otb +{ +/** \class RationalTransform + * \brief This class implements a rational transfom + * + * A rational transform is a quotient of two polynomial functions. + * + * The degree of the numerator and denominator polynomial functions + * can be set using the appropriate setters. + * + * The number of parameters is then the number of dimensions times + * the numerator degree plus one times the denominator degree plus + * one. + * + * Parameters in the parameters vector are in the following order: + * dim0num0 dim0num1 ... dim0numN dim0denom0 dim0denom1 + * ... dim0denomM ... dim1num0 ... dimDdenomM. + * + * \ingroup Transform + **/ + +template <class TScalarType = double, + unsigned int Dimension = 2> +class ITK_EXPORT RationalTransform : public itk::Transform<TScalarType, Dimension, Dimension> +{ +public: + /** Standard class typedefs. */ + typedef itk::Transform<TScalarType, Dimension, + Dimension> Superclass; + typedef RationalTransform Self; + typedef itk::SmartPointer<Self> Pointer; + typedef itk::SmartPointer<const Self> ConstPointer; + + typedef typename Superclass::ScalarType ScalarType; + typedef itk::Point<ScalarType, Dimension> InputPointType; + typedef itk::Point<ScalarType, Dimension> OutputPointType; + + typedef typename Superclass::InverseTransformBasePointer InverseTransformBasePointer; + + /** Method for creation through the object factory. */ + itkNewMacro(Self); + + /** Run-time type information (and related methods). */ + itkTypeMacro(RationalTransform, itk::Transform); + + itkStaticConstMacro(SpaceDimension, unsigned int, Dimension); + + /** Set the numerator degree */ + itkSetMacro(NumeratorDegree, unsigned int); + + /** Get the numerator degree */ + itkGetMacro(NumeratorDegree, unsigned int); + + /** Set the numerator degree */ + itkSetMacro(DenominatorDegree, unsigned int); + + /** Get the denominator degree */ + itkGetMacro(DenominatorDegree, unsigned int); + + + /** The transform point method */ + virtual OutputPointType TransformPoint(const InputPointType& point) const + { + // Check for consistency + if(this->GetNumberOfParameters() != this->m_Parameters.size()) + { + { + itkExceptionMacro(<<"Wrong number of parameters: found "<<this->m_Parameters.Size()<<", expected "<<this->GetNumberOfParameters()); + } + } + + // Build output + OutputPointType outputPoint; + + unsigned int dimensionStride = (m_DenominatorDegree+1)+(m_NumeratorDegree+1); + + // Compute RPC transform + for(unsigned int dim = 0; dim < SpaceDimension; ++dim) + { + // Initialize numerator and denominator + TScalarType num = itk::NumericTraits<TScalarType>::Zero; + TScalarType denom = itk::NumericTraits<TScalarType>::Zero; + TScalarType currentPower = 1.; + + // Compute numerator + for(unsigned int numDegree = 0; numDegree <= m_NumeratorDegree; ++numDegree) + { + num+=this->m_Parameters[dim*dimensionStride+numDegree]*currentPower; + currentPower*=point[dim]; + } + + // Compute denominator + currentPower = 1.; + for(unsigned int denomDegree = 0; denomDegree <= m_DenominatorDegree; ++denomDegree) + { + denom+=this->m_Parameters[dim*dimensionStride+m_NumeratorDegree+denomDegree+1]*currentPower; + currentPower*=point[dim]; + } + + // Finally, fill the output + outputPoint[dim]=num/denom; + } + + // Return the output point + return outputPoint; + } + + // Get the number of parameters + virtual unsigned int GetNumberOfParameters() const + { + return (m_NumeratorDegree +1 + m_DenominatorDegree+1)*SpaceDimension; + } + + // Set parameter method + virtual void SetParameters(const typename Superclass::ParametersType & params) + { + // Check for the appropriate size + if(params.Size() != this->GetNumberOfParameters()) + { + itkExceptionMacro(<<"Wrong number of parameters: found "<<params.Size()<<", expected "<<this->GetNumberOfParameters()); + } + + // Set parameters + this->m_Parameters = params; + } + +protected: + RationalTransform() : Superclass(SpaceDimension, 16), m_NumeratorDegree(3), m_DenominatorDegree(3) + { + this->m_Parameters.SetSize(this->GetNumberOfParameters()); + this->m_Parameters.Fill(0); + this->m_Parameters[1] = 1.; + this->m_Parameters[4] = 1.; + } + + virtual ~RationalTransform() {} + + void PrintSelf(std::ostream& os, itk::Indent indent) const + { + Superclass::PrintSelf(os, indent); + } + +private: + RationalTransform(const Self &); //purposely not implemented + void operator =(const Self&); //purposely not implemented + + // Degree of numerator + unsigned int m_NumeratorDegree; + + // Degree of denominator + unsigned int m_DenominatorDegree; +}; + +} // namespace otb + +#endif diff --git a/Code/SARPolarimetry/otbHermitianEigenAnalysis.h b/Code/SARPolarimetry/otbHermitianEigenAnalysis.h index fdc417d5bbe0f55f962eafa59f96e95393486f2b..16001824ae9bba73af0305911c6044885f74d341 100644 --- a/Code/SARPolarimetry/otbHermitianEigenAnalysis.h +++ b/Code/SARPolarimetry/otbHermitianEigenAnalysis.h @@ -1,13 +1,14 @@ /*========================================================================= - Program: Insight Segmentation & Registration Toolkit - Module: $RCSfile: otbHermitianEigenAnalysis.h, v $ + Program: ORFEO Toolbox Language: C++ - Date: $Date: 2005/07/09 22:43:35 $ - Version: $Revision: 1.5 $ + Date: $Date$ + Version: $Revision$ + + + Copyright (c) Centre National d'Etudes Spatiales. All rights reserved. + See OTBCopyright.txt for details. - Copyright (c) Insight Software Consortium. All rights reserved. - See ITKCopyright.txt or http://www.itk.org/HTML/Copyright.htm for details. This software is distributed WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR @@ -56,6 +57,8 @@ namespace otb * num. math. 11, 293-306(1968) by bowdler, martin, reinsch, and * wilkinson. * handbook for auto. comp., vol.ii-linear algebra, 227-240(1971). + * + * \ingroup SARPolarimetry */ template < typename TMatrix, typename TVector, typename TEigenMatrix=TMatrix > @@ -85,7 +88,7 @@ public: m_OrderEigenValues(OrderByValue) {}; - ~HermitianEigenAnalysis() {}; + virtual ~HermitianEigenAnalysis() {}; typedef TMatrix MatrixType; typedef TEigenMatrix EigenMatrixType; diff --git a/Code/SARPolarimetry/otbMLCToCircularCoherencyDegreeImageFilter.h b/Code/SARPolarimetry/otbMLCToCircularCoherencyDegreeImageFilter.h index 61ca413afb4b8c682e70a6d353b20665cc01938e..937b08dc15adf38fdd40e000abd3a89e4e895be4 100644 --- a/Code/SARPolarimetry/otbMLCToCircularCoherencyDegreeImageFilter.h +++ b/Code/SARPolarimetry/otbMLCToCircularCoherencyDegreeImageFilter.h @@ -45,6 +45,12 @@ namespace Functor { * \f$ S_{ll} = S_{ll}^{*} = 1/2 * ( -S_{xx} - j*2*S_{xy} + S_{yy}) \f$ * \f$ S_{lr} = S_{rl} = 1/2 * ( -S_{xx} - S_{yy}) \f$ * + * \infgroup Functor + * \ingroup SARPolarimetry + * + * \sa MLCToCoherencyDegreeImageFilter + * \sa MLCToCoherencyImageFilter + * */ template< class TInput, class TOutput> class MLCToCircularCoherencyDegreeFunctor @@ -60,24 +66,24 @@ public: result.SetSize(m_NumberOfComponentsPerPixel); result.Fill(0.0); - RealType C1 = static_cast<RealType>(Covariance[0].real()); // C1 <hh.hh*> - RealType C2 = static_cast<RealType>(Covariance[3].real()); // C2 <hv.hv*> - RealType C3 = static_cast<RealType>(Covariance[5].real()); // C3 <vv.vv*> - RealType C4 = static_cast<RealType>(Covariance[1].real()); // C4 Re<hh.hv*> - RealType C5 = static_cast<RealType>(Covariance[1].imag()); // C5 Im<hh.hv*> - RealType C6 = static_cast<RealType>(Covariance[2].real()); // C6 Re<hh.vv*> - RealType C7 = static_cast<RealType>(Covariance[2].imag()); // C7 Im<hh.vv*> - RealType C8 = static_cast<RealType>(Covariance[4].real()); // C8 Re<hv.vv*> - RealType C9 = static_cast<RealType>(Covariance[4].imag()); // C9 Im<hv.vv*> + const RealType C1 = static_cast<RealType>(Covariance[0].real()); // C1 <hh.hh*> + const RealType C2 = static_cast<RealType>(Covariance[3].real()); // C2 <hv.hv*> + const RealType C3 = static_cast<RealType>(Covariance[5].real()); // C3 <vv.vv*> + const RealType C4 = static_cast<RealType>(Covariance[1].real()); // C4 Re<hh.hv*> + const RealType C5 = static_cast<RealType>(Covariance[1].imag()); // C5 Im<hh.hv*> + const RealType C6 = static_cast<RealType>(Covariance[2].real()); // C6 Re<hh.vv*> + const RealType C7 = static_cast<RealType>(Covariance[2].imag()); // C7 Im<hh.vv*> + const RealType C8 = static_cast<RealType>(Covariance[4].real()); // C8 Re<hv.vv*> + const RealType C9 = static_cast<RealType>(Covariance[4].imag()); // C9 Im<hv.vv*> - RealType llrrReal = 0.25 * ( C1 + C3 -4*C2 -2*C6); - RealType llrrImag = -(C4 + C8); + const RealType llrrReal = 0.25 * ( C1 + C3 -4*C2 -2*C6); + const RealType llrrImag = -(C4 + C8); - RealType lllrReal = 0.25 * ( C1 - C3 - 2*C5 + 2*C9); - RealType lllrImag = -0.5*(C7+C4+C8); + const RealType lllrReal = 0.25 * ( C1 - C3 - 2*C5 + 2*C9); + const RealType lllrImag = -0.5*(C7+C4+C8); - RealType rrlrReal = 0.25 * ( C1 -C3 + 2*C5 - 2*C9); - RealType rrlrImag = 0.5 * (C4+C8-C7); + const RealType rrlrReal = 0.25 * ( C1 -C3 + 2*C5 - 2*C9); + const RealType rrlrImag = 0.5 * (C4+C8-C7); RealType ll2 = 0.25 * ( C1 + C3 + 4*C2 - 2*C6 - 4*C5 - 4*C9); RealType rr2 = 0.25 * ( C1 + C3 + 4*C2 - 2*C6 + 4*C5 + 4*C9); @@ -114,7 +120,7 @@ public: MLCToCircularCoherencyDegreeFunctor() : m_NumberOfComponentsPerPixel(3) {} /** Destructor */ - ~MLCToCircularCoherencyDegreeFunctor() {} + virtual ~MLCToCircularCoherencyDegreeFunctor() {} private: unsigned int m_NumberOfComponentsPerPixel; diff --git a/Code/SARPolarimetry/otbMLCToCoherencyDegreeImageFilter.h b/Code/SARPolarimetry/otbMLCToCoherencyDegreeImageFilter.h index fa19f292e4850f724a9dbb5740af0b0eec91475d..a9edf7d9fb1ad3fcb6dfde60791d67e89bb039e2 100644 --- a/Code/SARPolarimetry/otbMLCToCoherencyDegreeImageFilter.h +++ b/Code/SARPolarimetry/otbMLCToCoherencyDegreeImageFilter.h @@ -29,11 +29,16 @@ namespace Functor { /** \class otbMLCToCoherencyDegreeFunctor * \brief Evaluate the Coherency Degree coefficient from from the MLC image * - * * Output value are: + * Output value are: * channel #0 : \f$ abs(S_{hh}*S_{vv}}^{*}) / sqrt(S_{hh}*S_{hh}}^{*}) / sqrt(S_{vv}*S_{vv}}^{*})\f$ * channel #1 : \f$ abs(S_{hv}*S_{vv}}^{*}) / sqrt(S_{hv}*S_{hv}}^{*}) / sqrt(S_{vv}*S_{vv}}^{*}) \f$ * channel #2 : \f$ abs(S_{hh}*S_{hv}}^{*}) / sqrt(S_{hh}*S_{hh}}^{*}) / sqrt(S_{hv}*S_{hv}}^{*}) \f$ * + * \infgroup Functor + * \ingroup SARPolarimetry + * + * \sa MLCToCircularCoherencyDegreeImageFilter + * \sa MLCToCoherencyImageFilter */ template< class TInput, class TOutput> class MLCToCoherencyDegreeFunctor @@ -49,12 +54,12 @@ public: result.SetSize(m_NumberOfComponentsPerPixel); result.Fill(0.0); - RealType C11 = static_cast<RealType>(Covariance[0].real()); - ComplexType C12 = static_cast<ComplexType>(Covariance[1]); - ComplexType C13 = static_cast<ComplexType>(Covariance[2]); - RealType C22 = static_cast<RealType>(Covariance[3].real()); - ComplexType C23 = static_cast<ComplexType>(Covariance[4]); - RealType C33 = static_cast<RealType>(Covariance[5].real()); + const RealType C11 = static_cast<RealType>(Covariance[0].real()); + const ComplexType C12 = static_cast<ComplexType>(Covariance[1]); + const ComplexType C13 = static_cast<ComplexType>(Covariance[2]); + const RealType C22 = static_cast<RealType>(Covariance[3].real()); + const ComplexType C23 = static_cast<ComplexType>(Covariance[4]); + const RealType C33 = static_cast<RealType>(Covariance[5].real()); if ((C11 >0.00001) && (C33 > 0.0001)) { @@ -83,7 +88,7 @@ public: MLCToCoherencyDegreeFunctor() : m_NumberOfComponentsPerPixel(3) {} /** Destructor */ - ~MLCToCoherencyDegreeFunctor() {} + virtual ~MLCToCoherencyDegreeFunctor() {} private: unsigned int m_NumberOfComponentsPerPixel; diff --git a/Code/SARPolarimetry/otbMLCToCoherencyImageFilter.h b/Code/SARPolarimetry/otbMLCToCoherencyImageFilter.h index a8b2511b423fac6c377fcbd9fe36996f371610cd..0dbc3a47281c38444279727b141a5a548a86197a 100644 --- a/Code/SARPolarimetry/otbMLCToCoherencyImageFilter.h +++ b/Code/SARPolarimetry/otbMLCToCoherencyImageFilter.h @@ -29,7 +29,7 @@ namespace Functor { /** \class otbMLCToCoherencyFunctor * \brief Evaluate the Coherency matrix from from the MLC image * - * * Output value are: + * Output value are: * channel #0 : \f$ 0.5 * (S_{hh}+S_{vv}.(S_{hh}+S_{vv})^{*} \f$ * channel #1 : \f$ 0.5 * (S_{hh}+S_{vv}.(S_{hh}-S_{vv})^{*} \f$ * channel #2 : \f$ (S_{hh}+S_{vv}.(S_{hv})^{*} \f$ @@ -37,6 +37,11 @@ namespace Functor { * channel #4 : \f$ (S_{hh}-S_{vv}.(S_{hv})^{*} \f$ * channel #5 : \f$ 2.0*S_{hv}.S_{hv}^{*} \f$ * + * \infgroup Functor + * \ingroup SARPolarimetry + * + * \sa MLCToCircularCoherencyDegreeImageFilter + * \sa MLCToCoherencyDegreeImageFilter */ template< class TInput, class TOutput> class MLCToCoherencyFunctor @@ -50,16 +55,16 @@ public: TOutput result; result.SetSize(m_NumberOfComponentsPerPixel); - ComplexType C11 = static_cast<ComplexType>(Covariance[0]); - ComplexType C12 = static_cast<ComplexType>(Covariance[1]); - ComplexType C13 = static_cast<ComplexType>(Covariance[2]); - ComplexType C22 = static_cast<ComplexType>(Covariance[3]); - ComplexType C23 = static_cast<ComplexType>(Covariance[4]); - ComplexType C33 = static_cast<ComplexType>(Covariance[5]); + const ComplexType C11 = static_cast<ComplexType>(Covariance[0]); + const ComplexType C12 = static_cast<ComplexType>(Covariance[1]); + const ComplexType C13 = static_cast<ComplexType>(Covariance[2]); + const ComplexType C22 = static_cast<ComplexType>(Covariance[3]); + const ComplexType C23 = static_cast<ComplexType>(Covariance[4]); + const ComplexType C33 = static_cast<ComplexType>(Covariance[5]); - ComplexType C21 = vcl_conj(C12); - ComplexType C31 = vcl_conj(C13); - ComplexType C32 = vcl_conj(C23); + const ComplexType C21 = vcl_conj(C12); + const ComplexType C31 = vcl_conj(C13); + const ComplexType C32 = vcl_conj(C23); result[0] = static_cast<OutputValueType>( 0.5*(C11 + C13 + C31 + C33) ); result[1] = static_cast<OutputValueType>( 0.5*(C11 - C13 + C31 - C33) ); @@ -80,7 +85,7 @@ public: MLCToCoherencyFunctor() : m_NumberOfComponentsPerPixel(6) {} /** Destructor */ - ~MLCToCoherencyFunctor() {} + virtual ~MLCToCoherencyFunctor() {} private: unsigned int m_NumberOfComponentsPerPixel; diff --git a/Code/SARPolarimetry/otbMuellerToCircularPolarisationImageFilter.h b/Code/SARPolarimetry/otbMuellerToCircularPolarisationImageFilter.h index f64c0663638029cf431d5fd287c78e07ec2fdb17..89ae7bdcb18a0270d6588d9c5cd1bc1d3aa24779 100644 --- a/Code/SARPolarimetry/otbMuellerToCircularPolarisationImageFilter.h +++ b/Code/SARPolarimetry/otbMuellerToCircularPolarisationImageFilter.h @@ -30,6 +30,11 @@ namespace Functor { * \brief Evaluate the Circular Polarisation image * (3 channels : LL, RR and LR) from the Mueller image * + * \ingroup Functor + * \ingroup SARPolarimetry + * + * \sa MuellerToMLCImageFilter + * \sa MuellerToPolarisationDegreeAndPowerImageFilter * */ template< class TInput, class TOutput> @@ -44,10 +49,10 @@ public: TOutput result; result.SetSize(m_NumberOfComponentsPerPixel); - RealType M11 = static_cast<RealType>(Mueller[0]); - RealType M14 = static_cast<RealType>(Mueller[3]); - RealType M41 = static_cast<RealType>(Mueller[12]); - RealType M44 = static_cast<RealType>(Mueller[15]); + const RealType M11 = static_cast<RealType>(Mueller[0]); + const RealType M14 = static_cast<RealType>(Mueller[3]); + const RealType M41 = static_cast<RealType>(Mueller[12]); + const RealType M44 = static_cast<RealType>(Mueller[15]); result[0] = static_cast<OutputValueType>( M11 + M14 + M41 + M44 ); // LL result[1] = static_cast<OutputValueType>( M11 - M14 - M41 + M44 ); // RR @@ -65,7 +70,7 @@ public: MuellerToCircularPolarisationFunctor() : m_NumberOfComponentsPerPixel(3) {} /** Destructor */ - ~MuellerToCircularPolarisationFunctor() {} + virtual ~MuellerToCircularPolarisationFunctor() {} private: unsigned int m_NumberOfComponentsPerPixel; diff --git a/Code/SARPolarimetry/otbMuellerToMLCImageFilter.h b/Code/SARPolarimetry/otbMuellerToMLCImageFilter.h index 90c0563e8f092be158949149fedbe99d8e0ac74c..97a45886f0388f87a9101ff63dbcce25dc2bcfc4 100644 --- a/Code/SARPolarimetry/otbMuellerToMLCImageFilter.h +++ b/Code/SARPolarimetry/otbMuellerToMLCImageFilter.h @@ -29,6 +29,12 @@ namespace Functor { /** \class otbMuellerToMLCFunctor * \brief Evaluate the MLC image from the Mueller image * + * \ingroup Functor + * \ingroup SARPolarimetry + * + * \sa MuellerToCircularPolarisationImageFilter + * \sa MuellerToPolarisationDegreeAndPowerImageFilter + * */ template< class TInput, class TOutput> class MuellerToMLCFunctor @@ -44,29 +50,29 @@ public: TOutput result; result.SetSize(m_NumberOfComponentsPerPixel); - RealType M11 = static_cast<RealType>(Mueller[0]); - RealType M12 = static_cast<RealType>(Mueller[1]); - RealType M13 = static_cast<RealType>(Mueller[2]); - RealType M14 = static_cast<RealType>(Mueller[3]); - RealType M21 = static_cast<RealType>(Mueller[4]); - RealType M22 = static_cast<RealType>(Mueller[5]); - RealType M23 = static_cast<RealType>(Mueller[6]); - RealType M24 = static_cast<RealType>(Mueller[7]); - RealType M31 = static_cast<RealType>(Mueller[8]); - RealType M32 = static_cast<RealType>(Mueller[9]); - RealType M33 = static_cast<RealType>(Mueller[10]); - RealType M34 = static_cast<RealType>(Mueller[11]); - RealType M41 = static_cast<RealType>(Mueller[12]); - RealType M42 = static_cast<RealType>(Mueller[13]); - RealType M43 = static_cast<RealType>(Mueller[14]); - RealType M44 = static_cast<RealType>(Mueller[15]); - - ComplexType hhhh(M11+M22+2.*M12, 0.0); - ComplexType hvhv(M11-M22, 0.0); - ComplexType vvvv(M11+M22-2.*M12, 0.0); - ComplexType hhhv(M13+M23, -1.*(M14+M24)); - ComplexType hhvv(M33-M44, -2.*M34); - ComplexType hvvv(M13-M23, -1.*(M14-M24)); + const RealType M11 = static_cast<RealType>(Mueller[0]); + const RealType M12 = static_cast<RealType>(Mueller[1]); + const RealType M13 = static_cast<RealType>(Mueller[2]); + const RealType M14 = static_cast<RealType>(Mueller[3]); + const RealType M21 = static_cast<RealType>(Mueller[4]); + const RealType M22 = static_cast<RealType>(Mueller[5]); + const RealType M23 = static_cast<RealType>(Mueller[6]); + const RealType M24 = static_cast<RealType>(Mueller[7]); + const RealType M31 = static_cast<RealType>(Mueller[8]); + const RealType M32 = static_cast<RealType>(Mueller[9]); + const RealType M33 = static_cast<RealType>(Mueller[10]); + const RealType M34 = static_cast<RealType>(Mueller[11]); + const RealType M41 = static_cast<RealType>(Mueller[12]); + const RealType M42 = static_cast<RealType>(Mueller[13]); + const RealType M43 = static_cast<RealType>(Mueller[14]); + const RealType M44 = static_cast<RealType>(Mueller[15]); + + const ComplexType hhhh(M11+M22+2.*M12, 0.0); + const ComplexType hvhv(M11-M22, 0.0); + const ComplexType vvvv(M11+M22-2.*M12, 0.0); + const ComplexType hhhv(M13+M23, -1.*(M14+M24)); + const ComplexType hhvv(M33-M44, -2.*M34); + const ComplexType hvvv(M13-M23, -1.*(M14-M24)); result[0] = static_cast<OutputValueType>( hhhh ); result[1] = static_cast<OutputValueType>( 2.* hhhv ); @@ -87,7 +93,7 @@ public: MuellerToMLCFunctor() : m_NumberOfComponentsPerPixel(6) {} /** Destructor */ - ~MuellerToMLCFunctor() {} + virtual ~MuellerToMLCFunctor() {} private: unsigned int m_NumberOfComponentsPerPixel; diff --git a/Code/SARPolarimetry/otbMuellerToPolarisationDegreeAndPowerImageFilter.h b/Code/SARPolarimetry/otbMuellerToPolarisationDegreeAndPowerImageFilter.h index 6182990e217ccaf736614bb2f7162e439ee1ce26..d4d955bb690af4143c5010a25255ecd30b294adf 100644 --- a/Code/SARPolarimetry/otbMuellerToPolarisationDegreeAndPowerImageFilter.h +++ b/Code/SARPolarimetry/otbMuellerToPolarisationDegreeAndPowerImageFilter.h @@ -34,6 +34,12 @@ namespace Functor { * \brief Evaluate the min and max polarisation degree and min and max power * from the Mueller image * + * \ingroup Functor + * \ingroup SARPolarimetry + * + * \sa MuellerToCircularPolarisationImageFilter + * \sa MuellerToMLCImageFilter + * */ template< class TInput, class TOutput> class MuellerToPolarisationDegreeAndPowerFunctor @@ -151,7 +157,7 @@ public: MuellerToPolarisationDegreeAndPowerFunctor() : m_NumberOfComponentsPerPixel(4) {} /** Destructor */ - ~MuellerToPolarisationDegreeAndPowerFunctor() {} + virtual ~MuellerToPolarisationDegreeAndPowerFunctor() {} private: unsigned int m_NumberOfComponentsPerPixel; diff --git a/Code/SARPolarimetry/otbPolarimetricData.h b/Code/SARPolarimetry/otbPolarimetricData.h index 6a230fbc143dd1696c9d3f54b5e05f0383767846..938ba50fb5dacc99b06e2ae26b672e3eb22efdf7 100644 --- a/Code/SARPolarimetry/otbPolarimetricData.h +++ b/Code/SARPolarimetry/otbPolarimetricData.h @@ -41,8 +41,9 @@ typedef enum /** \class PolarimetricData * \brief This class allows to determine the type of architecture we get. * +* HH_HV_VH_VV (0), HH_HV_VV (1), HH_VH_VV (2), HH_HV(3), VH_VV (4), HH_VV (5). * -* \sa +* \ingroup SARPolarimetry */ class ITK_EXPORT PolarimetricData : public itk::DataObject @@ -73,7 +74,7 @@ protected: /** Constructor */ PolarimetricData(); /** Destructor */ - ~PolarimetricData() {} + virtual ~PolarimetricData() {} /**PrintSelf method */ void PrintSelf(std::ostream& os, itk::Indent indent) const; diff --git a/Code/SARPolarimetry/otbPolarimetricSynthesisFilter.h b/Code/SARPolarimetry/otbPolarimetricSynthesisFilter.h index b6c6255632e579a27d3b21589a8a1bc231428e87..53551f4eefe9689dc13305c32b4f0b7de5653117 100644 --- a/Code/SARPolarimetry/otbPolarimetricSynthesisFilter.h +++ b/Code/SARPolarimetry/otbPolarimetricSynthesisFilter.h @@ -54,6 +54,10 @@ namespace otb * the type of the output image. It is also parameterized by the * operation to be applied, using a Functor style. * + * + * \ingroup SARPolarimetry + * \sa PolarimetricSynthesisFunctor + * */ template <class TInputImageHH, class TInputImageHV, class TInputImageVH, class TInputImageVV, class TOutputImage, diff --git a/Code/SARPolarimetry/otbPolarimetricSynthesisFunctor.h b/Code/SARPolarimetry/otbPolarimetricSynthesisFunctor.h index 8f6cd87b03895f631ad93fc89deabd4a4aea7ce2..0f23625cfba3b59b7c7d5c9b78d8ea1ce04558ae 100644 --- a/Code/SARPolarimetry/otbPolarimetricSynthesisFunctor.h +++ b/Code/SARPolarimetry/otbPolarimetricSynthesisFunctor.h @@ -32,6 +32,7 @@ namespace Functor \vec(E_{r})\cdot\left[ S \right] \vec(E_{i}) \f$ * * \ingroup Functor + * \ingroup SARPolarimetry */ template <class TInput1, class TInput2, class TInput3, class TInput4, class TOutput> class PolarimetricSynthesisFunctor @@ -69,7 +70,7 @@ public: tmp = vcl_conj(m_Er[0]) * (m_Ei[0] * static_cast<ComplexType>(Shh) + m_Ei[1] * static_cast<ComplexType>(Shv)) + vcl_conj(m_Er[1]) * (m_Ei[0] * static_cast<ComplexType>(Svh) + m_Ei[1] * static_cast<ComplexType>(Svv)); - scalar = (double) (vcl_pow(vcl_abs(tmp), 2)); + scalar = static_cast<double>(vcl_abs(tmp)) * static_cast<double>(vcl_abs(tmp)); return (static_cast<TOutput>(scalar)); } diff --git a/Code/SARPolarimetry/otbReciprocalCoherencyToMuellerImageFilter.h b/Code/SARPolarimetry/otbReciprocalCoherencyToMuellerImageFilter.h index 38cbede26a18e9a230a0a5ee9fdd7cc75bfb093f..c7412fd8b283cbb02ad3eed023f731ecccfe6914 100644 --- a/Code/SARPolarimetry/otbReciprocalCoherencyToMuellerImageFilter.h +++ b/Code/SARPolarimetry/otbReciprocalCoherencyToMuellerImageFilter.h @@ -29,6 +29,7 @@ namespace Functor { /** \class otbCoherencyToMuellerFunctor * \brief Evaluate the Mueller matrix from the reciprocal coherency matrix image * + * \ingroup SARPolarimetry */ template< class TInput, class TOutput> class ReciprocalCoherencyToMuellerFunctor @@ -76,7 +77,7 @@ public: ReciprocalCoherencyToMuellerFunctor() {} /** Destructor */ - ~ReciprocalCoherencyToMuellerFunctor() {} + virtual ~ReciprocalCoherencyToMuellerFunctor() {} private: itkStaticConstMacro(NumberOfComponentsPerPixel, unsigned int, 10); diff --git a/Code/SARPolarimetry/otbReciprocalHAlphaImageFilter.h b/Code/SARPolarimetry/otbReciprocalHAlphaImageFilter.h index 760a203ca91ec4eb5aa8d193b313ed8b599e969a..0cdb0ff672e3a56730c3a14790db7bd0c7e18990 100644 --- a/Code/SARPolarimetry/otbReciprocalHAlphaImageFilter.h +++ b/Code/SARPolarimetry/otbReciprocalHAlphaImageFilter.h @@ -32,11 +32,13 @@ namespace Functor { /** \class otbHAlphaFunctor * \brief Evaluate the H-Alpha parameters from the reciprocal coherency matrix image * - * * Output value are: + * Output value are: * channel #0 : entropy * channel #1 : \f$ \alpha \f$ parameter * channel #2 : anisotropy * + * \ingroup SARPolarimetry + * */ template< class TInput, class TOutput> class ReciprocalHAlphaFunctor @@ -71,7 +73,7 @@ public: inline TOutput operator()( const TInput & Coherency ) const { TOutput result; - result.SetSize(NumberOfComponentsPerPixel); + result.SetSize(m_NumberOfComponentsPerPixel); CoherencyMatrixType T; EigenvalueType eigenValues; @@ -95,7 +97,7 @@ public: RealType entropy; RealType alpha; RealType anisotropy; - const RealType epsilon = 1.0E-4; + //const RealType epsilon = 1.0E-4; totalEigenValues = static_cast<RealType>( eigenValues[0] + eigenValues[1] + eigenValues[2]); @@ -110,7 +112,7 @@ public: p[k] = static_cast<RealType>(eigenValues[k]) / totalEigenValues; } - if ( (p[0] < epsilon) || (p[1] < epsilon) || (p[2] < epsilon) ) + if ( (p[0] < m_Epsilon) || (p[1] < m_Epsilon) || (p[2] < m_Epsilon) ) { entropy =0.0; } @@ -131,14 +133,14 @@ public: if (p[k] > 1.) p[k] = 1.; } - val0=sqrt(eigenVectors[0][0]*eigenVectors[0][0] + eigenVectors[0][1]*eigenVectors[0][1]); - a0=acos(abs(val0)) * CONST_180_PI; + val0=sqrt(static_cast<double>(eigenVectors[0][0]*eigenVectors[0][0]) + static_cast<double>(eigenVectors[0][1]*eigenVectors[0][1])); + a0=acos(vcl_abs(val0)) * CONST_180_PI; - val1=sqrt(eigenVectors[0][2]*eigenVectors[0][2] + eigenVectors[0][3]*eigenVectors[0][3]); - a1=acos(abs(val1)) * CONST_180_PI; + val1=sqrt(static_cast<double>(eigenVectors[0][2]*eigenVectors[0][2]) + static_cast<double>(eigenVectors[0][3]*eigenVectors[0][3])); + a1=acos(vcl_abs(val1)) * CONST_180_PI; - val2=sqrt(eigenVectors[0][4]*eigenVectors[0][4] + eigenVectors[0][5]*eigenVectors[0][5]); - a2=acos(abs(val2)) * CONST_180_PI; + val2=sqrt(static_cast<double>(eigenVectors[0][4]*eigenVectors[0][4]) + static_cast<double>(eigenVectors[0][5]*eigenVectors[0][5])); + a2=acos(vcl_abs(val2)) * CONST_180_PI; alpha=p[0]*a0 + p[1]*a1 + p[2]*a2; @@ -156,17 +158,18 @@ public: unsigned int GetOutputSize() { - return NumberOfComponentsPerPixel; + return m_NumberOfComponentsPerPixel; } /** Constructor */ - ReciprocalHAlphaFunctor() {} + ReciprocalHAlphaFunctor() : m_Epsilon(1e-4) {} /** Destructor */ - ~ReciprocalHAlphaFunctor() {} + virtual ~ReciprocalHAlphaFunctor() {} private: - itkStaticConstMacro(NumberOfComponentsPerPixel, unsigned int, 3); + itkStaticConstMacro(m_NumberOfComponentsPerPixel, unsigned int, 3); + const double m_Epsilon; }; } diff --git a/Code/SARPolarimetry/otbSinclairImageFilter.h b/Code/SARPolarimetry/otbSinclairImageFilter.h index 707f0184bf4960450e7fd3f7f3f1308cf2cc0227..6e10c46a379b86c210046cb28fd79f802634c24e 100644 --- a/Code/SARPolarimetry/otbSinclairImageFilter.h +++ b/Code/SARPolarimetry/otbSinclairImageFilter.h @@ -33,6 +33,16 @@ namespace otb * the type of the output image. It is also parameterized by the * operation to be applied, using a Functor style. * + * \ingroup SARPolarimetry + * + * \sa SinclairImageFilter + * \sa SinclairToCircularCovarianceMatrixFunctor + * \sa SinclairToCoherencyFunctor + * \sa SinclairToCovarianceFunctor + * \sa SinclairToMuellerFunctor + * \sa SinclairToReciprocalCircularCovarianceMatrixFunctor + * \sa SinclairToReciprocalCoherencyFunctor + * \sa SinclairToReciprocalCovarianceFunctor */ template <class TInputImageHH, class TInputImageHV, diff --git a/Code/SARPolarimetry/otbSinclairToCircularCovarianceMatrixFunctor.h b/Code/SARPolarimetry/otbSinclairToCircularCovarianceMatrixFunctor.h index 194f74e1459595e206b3101cec76f7227074da6a..5640fc6bff9aef6436124bb41f4d6a3118cbdf70 100644 --- a/Code/SARPolarimetry/otbSinclairToCircularCovarianceMatrixFunctor.h +++ b/Code/SARPolarimetry/otbSinclairToCircularCovarianceMatrixFunctor.h @@ -41,6 +41,15 @@ namespace Functor * channel #9 : \f$ S_{rr}.S_{rr}^{*} \f$ * * \ingroup Functor + * \ingroup SARPolarimetry + * + * \sa SinclairImageFilter + * \sa SinclairToCoherencyFunctor + * \sa SinclairToCovarianceFunctor + * \sa SinclairToMuellerFunctor + * \sa SinclairToReciprocalCircularCovarianceMatrixFunctor + * \sa SinclairToReciprocalCoherencyFunctor + * \sa SinclairToReciprocalCovarianceFunctor */ template <class TInput1, class TInput2, class TInput3, class TInput4, class TOutput> @@ -57,18 +66,18 @@ public: TOutput result; result.SetSize(m_NumberOfComponentsPerPixel); - ComplexType jShv = static_cast<ComplexType>(Shv) * vcl_complex<RealType>(0.0, 1.0); - ComplexType jSvh = static_cast<ComplexType>(Svh) * vcl_complex<RealType>(0.0, 1.0); - - ComplexType Sll = static_cast<ComplexType>( 0.5 * (-Shh-jShv-jSvh+Svv) ); - ComplexType Slr = static_cast<ComplexType>( 0.5 * (-Shh+jShv-jSvh+Svv) ); - ComplexType Srl = static_cast<ComplexType>( 0.5 * (-Shh-jShv+jSvh-Svv) ); - ComplexType Srr = static_cast<ComplexType>( 0.5 * (-Shh+jShv+jSvh+Svv) ); - - ComplexType conjSll = vcl_conj(Sll); - ComplexType conjSlr = vcl_conj(Slr); - ComplexType conjSrl = vcl_conj(Srl); - ComplexType conjSrr = vcl_conj(Srr); + const ComplexType jShv = static_cast<ComplexType>(Shv) * vcl_complex<RealType>(0.0, 1.0); + const ComplexType jSvh = static_cast<ComplexType>(Svh) * vcl_complex<RealType>(0.0, 1.0); + + const ComplexType Sll = static_cast<ComplexType>( 0.5 * (-Shh-jShv-jSvh+Svv) ); + const ComplexType Slr = static_cast<ComplexType>( 0.5 * (-Shh+jShv-jSvh+Svv) ); + const ComplexType Srl = static_cast<ComplexType>( 0.5 * (-Shh-jShv+jSvh-Svv) ); + const ComplexType Srr = static_cast<ComplexType>( 0.5 * (-Shh+jShv+jSvh+Svv) ); + + const ComplexType conjSll = vcl_conj(Sll); + const ComplexType conjSlr = vcl_conj(Slr); + const ComplexType conjSrl = vcl_conj(Srl); + const ComplexType conjSrr = vcl_conj(Srr); result[0] = static_cast<OutputValueType>( Sll * conjSll ); result[1] = static_cast<OutputValueType>( Sll * conjSlr ); diff --git a/Code/SARPolarimetry/otbSinclairToCoherencyFunctor.h b/Code/SARPolarimetry/otbSinclairToCoherencyFunctor.h index ea35f8717eb17c328b2b9a2cb515a43dde457cfe..cfbd6ca5b45404f1c47e6eba7c392215e638f815 100644 --- a/Code/SARPolarimetry/otbSinclairToCoherencyFunctor.h +++ b/Code/SARPolarimetry/otbSinclairToCoherencyFunctor.h @@ -41,6 +41,15 @@ namespace Functor * channel #9 : \f$ j(S_{hv}-S_{vh}).(j(S_{hv}-S_{vh}))^{*} \f$ * * \ingroup Functor + * \ingroup SARPolarimetry + * + * \sa SinclairImageFilter + * \sa SinclairToCircularCovarianceMatrixFunctor + * \sa SinclairToCovarianceFunctor + * \sa SinclairToMuellerFunctor + * \sa SinclairToReciprocalCircularCovarianceMatrixFunctor + * \sa SinclairToReciprocalCoherencyFunctor + * \sa SinclairToReciprocalCovarianceFunctor */ template <class TInput1, class TInput2, class TInput3, class TInput4, class TOutput> @@ -58,10 +67,10 @@ public: result.SetSize(NumberOfComponentsPerPixel); - ComplexType HHPlusVV = static_cast<ComplexType>(Shh + Svv); - ComplexType VVMinusVV = static_cast<ComplexType>(Shh - Svv); - ComplexType HVPlusHV = static_cast<ComplexType>( Shv + Svh); - ComplexType jHVMinusHV = static_cast<ComplexType>( Shv - Svh) * vcl_complex<RealType>(0.0, 1.0); + const ComplexType HHPlusVV = static_cast<ComplexType>(Shh + Svv); + const ComplexType VVMinusVV = static_cast<ComplexType>(Shh - Svv); + const ComplexType HVPlusHV = static_cast<ComplexType>( Shv + Svh); + const ComplexType jHVMinusHV = static_cast<ComplexType>( Shv - Svh) * vcl_complex<RealType>(0.0, 1.0); result[0] = static_cast<OutputValueType>( HHPlusVV * vcl_conj(HHPlusVV) ); result[1] = static_cast<OutputValueType>( HHPlusVV * vcl_conj(VVMinusVV) ); diff --git a/Code/SARPolarimetry/otbSinclairToCovarianceFunctor.h b/Code/SARPolarimetry/otbSinclairToCovarianceFunctor.h index ed1229bb6fadfdf3a22e2a0e4e13943196a0fe0a..46034a4ffc1ea87a4b6e8efb120c82c6c7fd4547 100644 --- a/Code/SARPolarimetry/otbSinclairToCovarianceFunctor.h +++ b/Code/SARPolarimetry/otbSinclairToCovarianceFunctor.h @@ -41,6 +41,15 @@ namespace Functor * channel #9 : \f$ S_{vv}.S_{vv}^{*} \f$ * * \ingroup Functor + * \ingroup SARPolarimetry + * + * \sa SinclairImageFilter + * \sa SinclairToCircularCovarianceMatrixFunctor + * \sa SinclairToCoherencyFunctor + * \sa SinclairToMuellerFunctor + * \sa SinclairToReciprocalCircularCovarianceMatrixFunctor + * \sa SinclairToReciprocalCoherencyFunctor + * \sa SinclairToReciprocalCovarianceFunctor */ template <class TInput1, class TInput2, class TInput3, class TInput4, class TOutput> @@ -55,7 +64,7 @@ public: { TOutput result; - result.SetSize(NumberOfComponentsPerPixel); + result.SetSize(m_NumberOfComponentsPerPixel); result[0] = static_cast<OutputValueType>( static_cast<ComplexType>(Shh)*vcl_conj(static_cast<ComplexType>(Shh)) ); result[1] = static_cast<OutputValueType>( static_cast<ComplexType>(Shh)*vcl_conj(static_cast<ComplexType>(Shv)) ); @@ -73,7 +82,7 @@ public: unsigned int GetNumberOfComponentsPerPixel() { - return NumberOfComponentsPerPixel; + return m_NumberOfComponentsPerPixel; } /** Constructor */ @@ -86,7 +95,7 @@ protected: private: - itkStaticConstMacro(NumberOfComponentsPerPixel, unsigned int, 10); + itkStaticConstMacro(m_NumberOfComponentsPerPixel, unsigned int, 10); }; diff --git a/Code/SARPolarimetry/otbSinclairToMuellerFunctor.h b/Code/SARPolarimetry/otbSinclairToMuellerFunctor.h index 9bba7f5ac13607c85abeacfe23ad34f5d8ff16c5..86d6998c7d12b2a7fd40b83c75f791cae1cff240 100644 --- a/Code/SARPolarimetry/otbSinclairToMuellerFunctor.h +++ b/Code/SARPolarimetry/otbSinclairToMuellerFunctor.h @@ -29,7 +29,40 @@ namespace Functor * Elements of the Mueller matrix are extract from Antennas for radar and communications * Harold Mott p 503 * + * Output value are: + * channel #0 : \f$ 0.5 * \mathcal{Re}( T_{xx}.T_{xx}^{*} + T_{xy}.T_{xy}^{*} + T_{yx}.T_{yx}^{*} + T_{yy}.T_{yy}^{*} ) \f$ + * channel #1 : \f$ 0.5 * \mathcal{Re}( T_{xx}.T_{xx}^{*} - T_{xy}.T_{xy}^{*} + T_{yx}.T_{yx}^{*} - T_{yy}.T_{yy}^{*} ) \f$ + * channel #2 : \f$ \mathcal{Re}( T_{xx}.T_{xy}^{*} + T_{yx}.T_{yy}^{*} ) \f$ + * channel #3 : \f$ \mathcal{Im}( T_{xx}.T_{xy}^{*} + T_{yx}.T_{yy}^{*} ) \f$ + * channel #4 : \f$ 0.5 * \mathcal{Re}( T_{xx}.T_{xx}^{*} + T_{xy}.T_{xy}^{*} - T_{yx}.T_{yx}^{*} - T_{yy}.T_{yy}^{*} ) \f$ + * channel #5 : \f$ 0.5 * \mathcal{Re}( T_{xx}.T_{xx}^{*} - T_{xy}.T_{xy}^{*} - T_{yx}.T_{yx}^{*} + T_{yy}.T_{yy}^{*} ) \f$ + * channel #6 : \f$ \mathcal{Re}( T_{xx}.T_{xy}^{*} - T_{yx}.T_{yy}^{*} ) \f$ + * channel #7 : \f$ \mathcal{Im}( T_{xx}.T_{xy}^{*} - T_{yx}.T_{yy}^{*} ) \f$ + * channel #8 : \f$ \mathcal{Re}( T_{xx}.T_{yx}^{*} + T_{xy}.T_{yy}^{*} ) \f$ + * channel #9 : \f$ \mathcal{Im}( T_{xx}.T_{yx}^{*} - T_{xy}.T_{yy}^{*} ) \f$ + * channel #10 : \f$ \mathcal{Re}( T_{xx}.T_{yy}^{*} + T_{xy}.T_{yx}^{*} ) \f$ + * channel #11 : \f$ \mathcal{Im}( T_{xx}.T_{yy}^{*} - T_{xy}.T_{yx}^{*} ) \f$ + * channel #12 : \f$ \mathcal{Re}( T_{xx}.T_{yx}^{*} + T_{xy}.T_{yy}^{*} ) \f$ + * channel #13 : \f$ \mathcal{Im}( T_{xx}.T_{yx}^{*} - T_{xy}.T_{yy}^{*} ) \f$ + * channel #14 : \f$ \mathcal{Re}( T_{xx}.T_{yy}^{*} + T_{xy}.T_{yx}^{*} ) \f$ + * channel #15 : \f$ \mathcal{Im}( T_{xx}.T_{yy}^{*} - T_{xy}.T_{yx}^{*} ) \f$ + * + * With : + * \f$ T_{xx} = -S_{hh} \f$ + * \f$ T_{xy} = -S_{hv} \f$ + * \f$ T_{yx} = -S_{vh} \f$ + * \f$ T_{yy} = -S_{vv} \f$ + * * \ingroup Functor + * \ingroup SARPolarimetry + * + * \sa SinclairImageFilter + * \sa SinclairToCircularCovarianceMatrixFunctor + * \sa SinclairToCoherencyFunctor + * \sa SinclairToCovarianceFunctor + * \sa SinclairToReciprocalCircularCovarianceMatrixFunctor + * \sa SinclairToReciprocalCoherencyFunctor + * \sa SinclairToReciprocalCovarianceFunctor */ template <class TInput1, class TInput2, class TInput3, class TInput4, class TOutput> @@ -48,15 +81,15 @@ public: result.SetSize(m_NumberOfComponentsPerPixel); - ComplexType Txx = static_cast<ComplexType>(-Shh); - ComplexType Txy = static_cast<ComplexType>(-Shv); - ComplexType Tyx = static_cast<ComplexType>(Svh); - ComplexType Tyy = static_cast<ComplexType>(Svv); + const ComplexType Txx = static_cast<ComplexType>(-Shh); + const ComplexType Txy = static_cast<ComplexType>(-Shv); + const ComplexType Tyx = static_cast<ComplexType>(Svh); + const ComplexType Tyy = static_cast<ComplexType>(Svv); - ComplexType conjTxx = vcl_conj(static_cast<ComplexType>(-Shh)); - ComplexType conjTxy = vcl_conj(static_cast<ComplexType>(-Shv)); - ComplexType conjTyx = vcl_conj(static_cast<ComplexType>(Svh)); - ComplexType conjTyy = vcl_conj(static_cast<ComplexType>(Svv)); + const ComplexType conjTxx = vcl_conj(static_cast<ComplexType>(-Shh)); + const ComplexType conjTxy = vcl_conj(static_cast<ComplexType>(-Shv)); + const ComplexType conjTyx = vcl_conj(static_cast<ComplexType>(Svh)); + const ComplexType conjTyy = vcl_conj(static_cast<ComplexType>(Svv)); result[0] = static_cast<OutputValueType>( 0.5 * (Txx*conjTxx + Txy*conjTxy + Tyx*conjTyx + Tyy*conjTyy).real() ); result[1] = static_cast<OutputValueType>( 0.5 * (Txx*conjTxx - Txy*conjTxy + Tyx*conjTyx - Tyy*conjTyy).real() ); @@ -70,8 +103,10 @@ public: result[9] = static_cast<OutputValueType>( (Txx*conjTyx - Txy*conjTyy).real() ); result[10] = static_cast<OutputValueType>( (Txx*conjTyy + Txy*conjTyx).real() ); result[11] = static_cast<OutputValueType>( (Txx*conjTyy - Txy*conjTyx).imag() ); + result[12] = static_cast<OutputValueType>( (conjTxx*Tyx + conjTxy*Tyy).imag() ); result[13] = static_cast<OutputValueType>( (conjTxx*Tyx - conjTxy*Tyy).imag() ); + result[14] = static_cast<OutputValueType>( (conjTxx*Tyy + conjTxy*Tyx).imag() ); result[15] = static_cast<OutputValueType>( (Txx*conjTyy - Txy*conjTyx).real() ); diff --git a/Code/SARPolarimetry/otbSinclairToReciprocalCircularCovarianceMatrixFunctor.h b/Code/SARPolarimetry/otbSinclairToReciprocalCircularCovarianceMatrixFunctor.h index 6221350539eb6ae88a40fa70df390be7427c9139..8e55716a9685a66287bfd293818e8ccc0e306527 100644 --- a/Code/SARPolarimetry/otbSinclairToReciprocalCircularCovarianceMatrixFunctor.h +++ b/Code/SARPolarimetry/otbSinclairToReciprocalCircularCovarianceMatrixFunctor.h @@ -37,6 +37,15 @@ namespace Functor * channel #5 : \f$ S_{rr}.S_{rr}^{*} \f$ * * \ingroup Functor + * \ingroup SARPolarimetry + * + * \sa SinclairImageFilter + * \sa SinclairToCoherencyFunctor + * \sa SinclairToCovarianceFunctor + * \sa SinclairToMuellerFunctor + * \sa SinclairToReciprocalCircularCovarianceMatrixFunctor + * \sa SinclairToReciprocalCoherencyFunctor + * \sa SinclairToReciprocalCovarianceFunctor */ template <class TInput1, class TInput2, class TInput3, class TInput4, class TOutput> @@ -53,15 +62,15 @@ public: TOutput result; result.SetSize(m_NumberOfComponentsPerPixel); - ComplexType j2Shv = static_cast<ComplexType>(Shv) * vcl_complex<RealType>(0.0, 2.0); + const ComplexType j2Shv = static_cast<ComplexType>(Shv) * vcl_complex<RealType>(0.0, 2.0); - ComplexType Sll = static_cast<ComplexType>( 0.5 * (-Shh-j2Shv+Svv) ); - ComplexType Slr = static_cast<ComplexType>( 0.5 * (-Shh+Svv) ); - ComplexType Srr = vcl_conj(Sll); + const ComplexType Sll = static_cast<ComplexType>( 0.5 * (-Shh-j2Shv+Svv) ); + const ComplexType Slr = static_cast<ComplexType>( 0.5 * (-Shh+Svv) ); + const ComplexType Srr = vcl_conj(Sll); - ComplexType conjSll = vcl_conj(Sll); - ComplexType conjSlr = vcl_conj(Slr); - ComplexType conjSrr = vcl_conj(Srr); + const ComplexType conjSll = vcl_conj(Sll); + const ComplexType conjSlr = vcl_conj(Slr); + const ComplexType conjSrr = vcl_conj(Srr); result[0] = static_cast<OutputValueType>( Sll * conjSll ); result[1] = static_cast<OutputValueType>( Sll * conjSlr ); diff --git a/Code/SARPolarimetry/otbSinclairToReciprocalCoherencyFunctor.h b/Code/SARPolarimetry/otbSinclairToReciprocalCoherencyFunctor.h index c668031a1536481038d78bd582eed38fa9369fdb..2f66651a436c62f0c322c7b00c277c430b4bbcd5 100644 --- a/Code/SARPolarimetry/otbSinclairToReciprocalCoherencyFunctor.h +++ b/Code/SARPolarimetry/otbSinclairToReciprocalCoherencyFunctor.h @@ -37,6 +37,17 @@ namespace Functor * channel #5 : \f$ (2*S_{hv}).(2*S_{hv})^{*} \f$ * * \ingroup Functor + * \ingroup SARPolarimetry + * + * \sa SinclairImageFilter + * \sa SinclairToCircularCovarianceMatrixFunctor + * \sa SinclairToCoherencyFunctor + * \sa SinclairToCovarianceFunctor + * \sa SinclairToMuellerFunctor + * \sa SinclairToReciprocalCircularCovarianceMatrixFunctor + * \sa SinclairToReciprocalCovarianceFunctor + + * \sa SinclairToReciprocalCovarianceFunctor */ template <class TInput1, class TInput2, class TInput3, class TInput4, class TOutput> @@ -53,9 +64,9 @@ public: result.SetSize(NumberOfComponentsPerPixel); - ComplexType HHPlusVV = static_cast<ComplexType>(Shh + Svv); - ComplexType VVMinusVV = static_cast<ComplexType>(Shh - Svv); - ComplexType twoHV = static_cast<ComplexType>( 2.0 * Shv); + const ComplexType HHPlusVV = static_cast<ComplexType>(Shh + Svv); + const ComplexType VVMinusVV = static_cast<ComplexType>(Shh - Svv); + const ComplexType twoHV = static_cast<ComplexType>( 2.0 * Shv); result[0] = static_cast<OutputValueType>( HHPlusVV * vcl_conj(HHPlusVV) ); result[1] = static_cast<OutputValueType>( HHPlusVV * vcl_conj(VVMinusVV) ); diff --git a/Code/SARPolarimetry/otbSinclairToReciprocalCovarianceFunctor.h b/Code/SARPolarimetry/otbSinclairToReciprocalCovarianceFunctor.h index 5b8d8ebd7aee3d1fc049b0da18ee07aa1f6c2db4..3e9a1e9db6fee058fcc8354d65eaa3fab4cd9884 100644 --- a/Code/SARPolarimetry/otbSinclairToReciprocalCovarianceFunctor.h +++ b/Code/SARPolarimetry/otbSinclairToReciprocalCovarianceFunctor.h @@ -37,6 +37,15 @@ namespace Functor * channel #5 : \f$ S_{vv}.S_{vv}^{*} \f$ * * \ingroup Functor + * \ingroup SARPolarimetry + * + * \sa SinclairImageFilter + * \sa SinclairToCircularCovarianceMatrixFunctor + * \sa SinclairToCoherencyFunctor + * \sa SinclairToCovarianceFunctor + * \sa SinclairToMuellerFunctor + * \sa SinclairToReciprocalCircularCovarianceMatrixFunctor + * \sa SinclairToReciprocalCoherencyFunctor */ template <class TInput1, class TInput2, class TInput3, class TInput4, class TOutput> diff --git a/Code/Testing/otbCurlHelperStub.cxx b/Code/Testing/otbCurlHelperStub.cxx index e4325fe5906130c2c08b5579efa80abd53c489d8..5dc7b20411b4c4424401608725235ded452b1124 100644 --- a/Code/Testing/otbCurlHelperStub.cxx +++ b/Code/Testing/otbCurlHelperStub.cxx @@ -31,6 +31,31 @@ int CurlHelperStub::TestUrlAvailability(const std::string& url) const return -1; } +int CurlHelperStub::RetrieveUrlInMemory(const std::string& url, std::string& output) const +{ + if (url.compare("http://ws.geonames.org/findNearbyPlaceName?lat=1.29&lng=103.78") == 0) + { + output = "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"no\"?>\n" + "<geonames>\n" + "<geoname>\n" + "<toponymName>Kent Ridge</toponymName>\n" + "<name>Kent Ridge</name>\n" + "<lat>1.29306</lat>\n" + "<lng>103.78444</lng>\n" + "<geonameId>1880515</geonameId>\n" + "<countryCode>SG</countryCode>\n" + "<countryName>Singapore</countryName>\n" + "<fcl>P</fcl>\n" + "<fcode>PPLX</fcode>\n" + "<distance>0.59959</distance>\n" + "</geoname>\n" + "</geonames>\n"; + return 0; + } + itkExceptionMacro(<< "otbCurlHelperStub: value not recognized by stub"); + return -1; +} + int CurlHelperStub::RetrieveFile(const std::ostringstream& urlStream, std::string filename) const { if (urlStream.str().compare("http://ws.geonames.org/findNearbyPlaceName?lat=1.29&lng=103.78") == 0) diff --git a/Code/Testing/otbCurlHelperStub.h b/Code/Testing/otbCurlHelperStub.h index 682e3f87ede6c8b15817d2bca16624d5ecf1f58c..c58e875fecd6d894e801276ea80698ad6ee9038c 100644 --- a/Code/Testing/otbCurlHelperStub.h +++ b/Code/Testing/otbCurlHelperStub.h @@ -42,6 +42,7 @@ public: itkNewMacro(Self); int TestUrlAvailability(const std::string& url) const; + int RetrieveUrlInMemory(const std::string& urlString, std::string& output) const; int RetrieveFile(const std::ostringstream& urlStream, std::string filename) const; int RetrieveFile(const std::string& urlString, std::string filename) const; diff --git a/Code/Visualization/otbArrowKeyMoveActionHandler.h b/Code/Visualization/otbArrowKeyMoveActionHandler.h index 00b180803a8067a357da9c422b74604d8ab2903c..ef9cdbb321ff754416fd689c954cae0d0e33b089 100644 --- a/Code/Visualization/otbArrowKeyMoveActionHandler.h +++ b/Code/Visualization/otbArrowKeyMoveActionHandler.h @@ -81,150 +81,167 @@ public: sourceWidget = m_View->GetZoomWidget(); handle = true; } + if(handle && event == FL_FOCUS) + { + return true; + } if ((handle) && ((event == FL_KEYBOARD) || (event == FL_SHORTCUT))) { - switch (Fl::event_key()) + // handle compose mode + if(m_Composed && Fl::event_state() != (int)m_ComposeKey) + { + return false; + } + + unsigned int eventKey = Fl::event_key(); + + if(eventKey == m_UpKey) + { + typename ViewType::SizeType size; + size = m_View->GetFullWidget()->GetExtent().GetSize(); + + // Get the current position + typename ViewType::ImageWidgetType::PointType screenPoint, imagePoint; + screenPoint[0] = size[0] / 2; + screenPoint[1] = size[1] / 2; + + // Transform to image point + imagePoint = m_View->GetFullWidget()->GetScreenToImageTransform()->TransformPoint(screenPoint); + + // Transform to index + typename ViewType::IndexType index; + index[0] = static_cast<int>(imagePoint[0]); + index[1] = static_cast<int>(imagePoint[1]); + + // Move + index[1] -= size[1]/4; + + // Change scaled extract region center + m_Model->SetExtractRegionCenter(index); + // Update model + m_Model->Update(); + return true; + } + else if(eventKey == m_DownKey) { - case FL_Up: - { - typename ViewType::SizeType size; - size = m_View->GetFullWidget()->GetExtent().GetSize(); - - // Get the current position - typename ViewType::ImageWidgetType::PointType screenPoint, imagePoint; - screenPoint[0] = size[0] / 2; - screenPoint[1] = size[1] / 2; - - // Transform to image point - imagePoint = m_View->GetFullWidget()->GetScreenToImageTransform()->TransformPoint(screenPoint); - - // Transform to index - typename ViewType::IndexType index; - index[0] = static_cast<int>(imagePoint[0]); - index[1] = static_cast<int>(imagePoint[1]); - - // Move - index[1] -= size[1]/4; - - // Change scaled extract region center - m_Model->SetExtractRegionCenter(index); - // Update model - m_Model->Update(); - return true; - break; - } - case FL_Down: - { - typename ViewType::SizeType size; - size = m_View->GetFullWidget()->GetExtent().GetSize(); - - // Get the current position - typename ViewType::ImageWidgetType::PointType screenPoint, imagePoint; - screenPoint[0] = size[0] / 2; - screenPoint[1] = size[1] / 2; - - // Transform to image point - imagePoint = m_View->GetFullWidget()->GetScreenToImageTransform()->TransformPoint(screenPoint); - - // Transform to index - typename ViewType::IndexType index; - index[0] = static_cast<int>(imagePoint[0]); - index[1] = static_cast<int>(imagePoint[1]); - - // Move - index[1] += size[1]/4; - - // Change scaled extract region center - m_Model->SetExtractRegionCenter(index); - // Update model - m_Model->Update(); - return true; - break; - } - case FL_Left: - { - typename ViewType::SizeType size; - size = m_View->GetFullWidget()->GetExtent().GetSize(); - - // Get the current position - typename ViewType::ImageWidgetType::PointType screenPoint, imagePoint; - screenPoint[0] = size[0] / 2; - screenPoint[1] = size[1] / 2; - - // Transform to image point - imagePoint = m_View->GetFullWidget()->GetScreenToImageTransform()->TransformPoint(screenPoint); - - // Transform to index - typename ViewType::IndexType index; - index[0] = static_cast<int>(imagePoint[0]); - index[1] = static_cast<int>(imagePoint[1]); - - // Move - index[0] -= size[0]/4; - - // Change scaled extract region center - m_Model->SetExtractRegionCenter(index); - // Update model - m_Model->Update(); - return true; - break; - } - case FL_Right: - { - typename ViewType::SizeType size; - size = m_View->GetFullWidget()->GetExtent().GetSize(); - - // Get the current position - typename ViewType::ImageWidgetType::PointType screenPoint, imagePoint; - screenPoint[0] = size[0] / 2; - screenPoint[1] = size[1] / 2; - - // Transform to image point - imagePoint = m_View->GetFullWidget()->GetScreenToImageTransform()->TransformPoint(screenPoint); - - // Transform to index - typename ViewType::IndexType index; - index[0] = static_cast<int>(imagePoint[0]); - index[1] = static_cast<int>(imagePoint[1]); - - // Move - index[0] += size[0]/4; - - // Change scaled extract region center - m_Model->SetExtractRegionCenter(index); - // Update model - m_Model->Update(); - return true; - break; - } - default: - { - return false; - break; - } + typename ViewType::SizeType size; + size = m_View->GetFullWidget()->GetExtent().GetSize(); + + // Get the current position + typename ViewType::ImageWidgetType::PointType screenPoint, imagePoint; + screenPoint[0] = size[0] / 2; + screenPoint[1] = size[1] / 2; + + // Transform to image point + imagePoint = m_View->GetFullWidget()->GetScreenToImageTransform()->TransformPoint(screenPoint); + + // Transform to index + typename ViewType::IndexType index; + index[0] = static_cast<int>(imagePoint[0]); + index[1] = static_cast<int>(imagePoint[1]); + + // Move + index[1] += size[1]/4; + + // Change scaled extract region center + m_Model->SetExtractRegionCenter(index); + // Update model + m_Model->Update(); + return true; + } + else if(eventKey == m_LeftKey) + { + typename ViewType::SizeType size; + size = m_View->GetFullWidget()->GetExtent().GetSize(); + + // Get the current position + typename ViewType::ImageWidgetType::PointType screenPoint, imagePoint; + screenPoint[0] = size[0] / 2; + screenPoint[1] = size[1] / 2; + + // Transform to image point + imagePoint = m_View->GetFullWidget()->GetScreenToImageTransform()->TransformPoint(screenPoint); + + // Transform to index + typename ViewType::IndexType index; + index[0] = static_cast<int>(imagePoint[0]); + index[1] = static_cast<int>(imagePoint[1]); + + // Move + index[0] -= size[0]/4; + + // Change scaled extract region center + m_Model->SetExtractRegionCenter(index); + // Update model + m_Model->Update(); + return true; + } + else if(eventKey == m_RightKey) + { + typename ViewType::SizeType size; + size = m_View->GetFullWidget()->GetExtent().GetSize(); + + // Get the current position + typename ViewType::ImageWidgetType::PointType screenPoint, imagePoint; + screenPoint[0] = size[0] / 2; + screenPoint[1] = size[1] / 2; + + // Transform to image point + imagePoint = m_View->GetFullWidget()->GetScreenToImageTransform()->TransformPoint(screenPoint); + + // Transform to index + typename ViewType::IndexType index; + index[0] = static_cast<int>(imagePoint[0]); + index[1] = static_cast<int>(imagePoint[1]); + + // Move + index[0] += size[0]/4; + + // Change scaled extract region center + m_Model->SetExtractRegionCenter(index); + // Update model + m_Model->Update(); + return true; } } } return false; } - /** Set/Get the pointer to the model */ +/** Set/Get the pointer to the model */ itkSetObjectMacro(Model, ModelType); itkGetObjectMacro(Model, ModelType); - /** Set/Get the pointer to the view */ +/** Set/Get the pointer to the view */ itkSetObjectMacro(View, ViewType); itkGetObjectMacro(View, ViewType); +/** Set key mapping */ + itkSetMacro(UpKey, unsigned int); + itkGetMacro(UpKey, unsigned int); + itkSetMacro(DownKey, unsigned int); + itkGetMacro(DownKey, unsigned int); + itkSetMacro(LeftKey, unsigned int); + itkGetMacro(LeftKey, unsigned int); + itkSetMacro(RightKey, unsigned int); + itkGetMacro(RightKey, unsigned int); + itkSetMacro(Composed, bool); + itkGetMacro(Composed, bool); + itkSetMacro(ComposeKey, unsigned int); + itkGetMacro(ComposeKey, unsigned int); + protected: - /** Constructor */ - ArrowKeyMoveActionHandler() : m_View(), m_Model() +/** Constructor */ + ArrowKeyMoveActionHandler() : m_View(), m_Model(), + m_UpKey(FL_Up), m_DownKey(FL_Down), + m_LeftKey(FL_Left), m_RightKey(FL_Right), + m_Composed(false), m_ComposeKey(FL_SHIFT) {} - /** Destructor */ +/** Destructor */ virtual ~ArrowKeyMoveActionHandler(){} - /** Printself method */ +/** Printself method */ void PrintSelf(std::ostream& os, itk::Indent indent) const { Superclass::PrintSelf(os, indent); @@ -234,12 +251,24 @@ private: ArrowKeyMoveActionHandler(const Self&); // purposely not implemented void operator =(const Self&); // purposely not implemented - // Pointer to the view +// Pointer to the view ViewPointerType m_View; - // Pointer to the model +// Pointer to the model ModelPointerType m_Model; +// Key mapping for up, down, left and right + unsigned int m_UpKey; + unsigned int m_DownKey; + unsigned int m_LeftKey; + unsigned int m_RightKey; + + // Use composed shortcuts + bool m_Composed; + +// Key state (for Ctrl - shortcuts) + unsigned int m_ComposeKey; + }; // end class } // end namespace otb #endif diff --git a/Code/Visualization/otbChangeExtractRegionActionHandler.h b/Code/Visualization/otbChangeExtractRegionActionHandler.h index e3c6b42d8da2c12f73d3af8551eec0558d52937d..4ffca79a548c2262b176c79f7997c55827c6e0c2 100644 --- a/Code/Visualization/otbChangeExtractRegionActionHandler.h +++ b/Code/Visualization/otbChangeExtractRegionActionHandler.h @@ -76,6 +76,9 @@ public: typename ViewType::ImageWidgetType::PointType screenPoint, imagePoint; screenPoint = m_View->GetScrollWidget()->GetMousePosition(); + // Give focus to the widget + m_View->GetScrollWidget()->take_focus(); + // Transform to image point imagePoint = m_View->GetScrollWidget()->GetScreenToImageTransform()->TransformPoint(screenPoint); diff --git a/Code/Visualization/otbImageLayerGenerator.txx b/Code/Visualization/otbImageLayerGenerator.txx index dd40d15172b7a0f3e1da5c509c18b8a68c19bfd2..b5d87c8151b1fb77d8cb2389f3f4ba29ab3cced1 100644 --- a/Code/Visualization/otbImageLayerGenerator.txx +++ b/Code/Visualization/otbImageLayerGenerator.txx @@ -151,7 +151,7 @@ ImageLayerGenerator<TImageLayer> { m_Resampler->Update(); } - catch(itk::ExceptionObject & err) + catch(itk::ExceptionObject &) { // Disconnect pipeline and prepare a new resampler m_Resampler = ResampleFilterType::New(); diff --git a/Code/Visualization/otbImageWidget.h b/Code/Visualization/otbImageWidget.h index 92b942533834d511e05fbb1b7a85383777cb82c6..e11718d7709123729f5829cba3122da81ca03f24 100644 --- a/Code/Visualization/otbImageWidget.h +++ b/Code/Visualization/otbImageWidget.h @@ -113,6 +113,9 @@ public: itkGetObjectMacro(ImageToScreenTransform, AffineTransformType); itkGetObjectMacro(ScreenToImageTransform, AffineTransformType); + /** GetopenGL buffer */ + itkGetConstMacro(OpenGlBuffer, unsigned char *); + /** Get The GlBuffered Region*/ itkGetMacro(OpenGlBufferedRegion, RegionType); diff --git a/Testing/Code/IO/CMakeLists.txt b/Testing/Code/IO/CMakeLists.txt index aee6220453e2477c6403948703624e280017c638..da6ef772325b306fbf6a1f5911752bfc0966fd14 100644 --- a/Testing/Code/IO/CMakeLists.txt +++ b/Testing/Code/IO/CMakeLists.txt @@ -1793,7 +1793,10 @@ ENDIF(OTB_DATA_USE_LARGEINPUT) # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ otbIOTESTS15 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - +ADD_TEST(ioTuVectorDataIOFactory ${IO_TESTS15} + otbVectorDataIOFactory + ${INPUTDATA}/ToulouseRoad-examples.shp ) + ADD_TEST(ioTuOGRVectorDataIO ${IO_TESTS15} otbOGRVectorDataIONew ) @@ -2682,6 +2685,20 @@ ADD_TEST(ioTuSarDefaultImageMetadataInterfaceNew ${IO_TESTS20} ADD_TEST(ioTuSarDefaultImageMetadataInterface ${IO_TESTS20} otbSarDefaultImageMetadataInterface ) +ADD_TEST(ioTuScalarBufferToImageFileWriter ${IO_TESTS20} + otbScalarBufferToImageFileWriterNew ) + +ADD_TEST(ioTvScalarBufferToImageFileWriterTest ${IO_TESTS20} + --compare-image ${NOTOL} + ${BASELINE}/ioTvScalarBufferToImageFileWriterTest.tif + ${TEMP}/ioTvScalarBufferToImageFileWriterTest.tif + otbScalarBufferToImageFileWriterTest + 4 + 50 + 75 + ${TEMP}/ioTvScalarBufferToImageFileWriterTest.tif +) + # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ otbIOTESTS21 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ @@ -2875,6 +2892,8 @@ ADD_TEST(ioTvGDALReadPxlComplex${INPUTFILE_PIXELTYPE} ${IO_TESTS21} ENDFOREACH(INPUTFILE_PIXELTYPE ${INPUTFILE_PIXELTYPES_LIST}) + + # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ otbIOTESTS22 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ @@ -2950,6 +2969,7 @@ ADD_TEST(ioTvMultiChannelROI_HDF5_2_TIF ${COMMON_TESTS2} ENDIF(CHECK_GDAL_BUILDED_WITH_HDF) + #---------------------------------------------------------------------------------- SET(BasicIO_SRCS1 otbIOTests1.cxx @@ -3074,6 +3094,7 @@ otbWritingComplexDataWithComplexImageTest.cxx SET(BasicIO_SRCS15 otbIOTests15.cxx +otbVectorDataIOFactory.cxx otbVectorDataSourceNew.cxx otbVectorDataFileReaderNew.cxx otbVectorDataFileReader.cxx @@ -3150,6 +3171,8 @@ otbOpticalDefaultImageMetadataInterface.cxx otbSarDefaultImageMetadataInterfaceFactoryNew.cxx otbSarDefaultImageMetadataInterfaceNew.cxx otbSarDefaultImageMetadataInterface.cxx +otbScalarBufferToImageFileWriterNew.cxx +otbScalarBufferToImageFileWriterTest.cxx ) SET(BasicIO_SRCS21 @@ -3217,4 +3240,4 @@ OTB_ADD_EXECUTABLE(otbIOTests21 "${BasicIO_SRCS21}" "OTBIO;OTBTesting") IF(CHECK_GDAL_BUILDED_WITH_HDF) OTB_ADD_EXECUTABLE(otbIOTests22 "${BasicIO_SRCS22}" "OTBIO;OTBTesting") -ENDIF(CHECK_GDAL_BUILDED_WITH_HDF) \ No newline at end of file +ENDIF(CHECK_GDAL_BUILDED_WITH_HDF) diff --git a/Testing/Code/IO/otbGDALReadPxlComplex.cxx b/Testing/Code/IO/otbGDALReadPxlComplex.cxx index 452041b7411bacf1be56005186469ac9ab688bb0..c6065d53b04d4a258dc91fcbe6b72c2acb65b736 100644 --- a/Testing/Code/IO/otbGDALReadPxlComplex.cxx +++ b/Testing/Code/IO/otbGDALReadPxlComplex.cxx @@ -74,7 +74,7 @@ int otbGDALReadPxlComplexGeneric(int argc, char * argv[]) std::cout << "nbBytes of the buffer = " << nbBytes << " = " \ << nbBand << " x " << nbPixelToRead << " x " << bytePerPixel<< std::endl; - char * loadBuffer = new char[nbBytes]; + char * loadBuffer = new char[static_cast<unsigned int>(nbBytes)]; int pixelOffset = bytePerPixel * nbBand; int lineOffset = bytePerPixel * nbBand * sizeX; diff --git a/Testing/Code/IO/otbIOTests15.cxx b/Testing/Code/IO/otbIOTests15.cxx index 7264b9ded12cbb97f37d84a304685e4f14617328..333cc1c69681a15907f8547d045f280acb761a48 100644 --- a/Testing/Code/IO/otbIOTests15.cxx +++ b/Testing/Code/IO/otbIOTests15.cxx @@ -26,6 +26,7 @@ void RegisterTests() { + REGISTER_TEST(otbVectorDataIOFactory); REGISTER_TEST(otbVectorDataSourceNew); REGISTER_TEST(otbVectorDataFileReaderNew); REGISTER_TEST(otbVectorDataFileReader); diff --git a/Testing/Code/IO/otbIOTests20.cxx b/Testing/Code/IO/otbIOTests20.cxx index 2ecd94929ce388b0de2e77c68009ef14374d7d4d..485452d99123839cf8a328f52cf7cf244d30f275 100644 --- a/Testing/Code/IO/otbIOTests20.cxx +++ b/Testing/Code/IO/otbIOTests20.cxx @@ -35,4 +35,6 @@ void RegisterTests() REGISTER_TEST(otbSarDefaultImageMetadataInterfaceFactoryNew); REGISTER_TEST(otbSarDefaultImageMetadataInterfaceNew); REGISTER_TEST(otbSarDefaultImageMetadataInterface); + REGISTER_TEST(otbScalarBufferToImageFileWriterNew); + REGISTER_TEST(otbScalarBufferToImageFileWriterTest); } diff --git a/Testing/Code/IO/otbScalarBufferToImageFileWriterNew.cxx b/Testing/Code/IO/otbScalarBufferToImageFileWriterNew.cxx new file mode 100644 index 0000000000000000000000000000000000000000..1d1aa9d9c29b0c5766603782499ab12a7689a499 --- /dev/null +++ b/Testing/Code/IO/otbScalarBufferToImageFileWriterNew.cxx @@ -0,0 +1,32 @@ +/*========================================================================= + + Program: ORFEO Toolbox + Language: C++ + Date: $Date$ + Version: $Revision$ + + + Copyright (c) Centre National d'Etudes Spatiales. All rights reserved. + See OTBCopyright.txt for details. + + + This software is distributed WITHOUT ANY WARRANTY; without even + the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + PURPOSE. See the above copyright notices for more information. + +=========================================================================*/ + +#if defined(_MSC_VER) +#pragma warning ( disable : 4786 ) +#endif + +#include "otbScalarBufferToImageFileWriter.h" + + +int otbScalarBufferToImageFileWriterNew(int argc, char* argv[]) +{ + typedef otb::ScalarBufferToImageFileWriter<int, double> FilterType; + FilterType::Pointer filter = FilterType::New(); + + return EXIT_SUCCESS; +} diff --git a/Testing/Code/IO/otbScalarBufferToImageFileWriterTest.cxx b/Testing/Code/IO/otbScalarBufferToImageFileWriterTest.cxx new file mode 100644 index 0000000000000000000000000000000000000000..e418b37598f4e3e89c791986782e5052352d57ac --- /dev/null +++ b/Testing/Code/IO/otbScalarBufferToImageFileWriterTest.cxx @@ -0,0 +1,65 @@ +/*========================================================================= + + Program: ORFEO Toolbox + Language: C++ + Date: $Date$ + Version: $Revision$ + + + Copyright (c) Centre National d'Etudes Spatiales. All rights reserved. + See OTBCopyright.txt for details. + + + This software is distributed WITHOUT ANY WARRANTY; without even + the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + PURPOSE. See the above copyright notices for more information. + +=========================================================================*/ + +#if defined(_MSC_VER) +#pragma warning ( disable : 4786 ) +#endif + +#include "otbScalarBufferToImageFileWriter.h" + + +int otbScalarBufferToImageFileWriterTest(int argc, char* argv[]) +{ + unsigned int nbCh = atoi(argv[1]); + unsigned int sizeX = atoi(argv[2]); + unsigned int sizeY = atoi(argv[3]); + + typedef otb::ScalarBufferToImageFileWriter<float, unsigned int> FilterType; + FilterType::Pointer filter = FilterType::New(); + + float * tab = new float[nbCh*sizeX*sizeY]; + + int cpt=0; + double val = 0.; + for(unsigned int sx=0; sx<sizeX; sx++) + { + for(unsigned int sy=0; sy<sizeY; sy++) + { + for(unsigned int i=0; i<nbCh; i++) + { + tab[cpt++] = val; + val++; + } + } + } + + FilterType::SizeType size; + size[0] = sizeX; + size[1] = sizeY; + filter->SetImageSize(size); + filter->SetNumberOfChannels(nbCh); + filter->SetBuffer(tab); + filter->SetFileName(argv[4]); + filter->SetInverseXSpacing(true); + filter->Update(); + + delete[] tab; + tab = NULL; + + return EXIT_SUCCESS; +} diff --git a/Testing/Code/IO/otbVectorDataIOFactory.cxx b/Testing/Code/IO/otbVectorDataIOFactory.cxx new file mode 100644 index 0000000000000000000000000000000000000000..5c7d20183d0e696ef85667a1cceb6e6f901da4f0 --- /dev/null +++ b/Testing/Code/IO/otbVectorDataIOFactory.cxx @@ -0,0 +1,44 @@ +/*========================================================================= + + Program: ORFEO Toolbox + Language: C++ + Date: $Date$ + Version: $Revision$ + + + Copyright (c) Centre National d'Etudes Spatiales. All rights reserved. + See OTBCopyright.txt for details. + + + This software is distributed WITHOUT ANY WARRANTY; without even + the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + PURPOSE. See the above copyright notices for more information. + +=========================================================================*/ + +#include "otbVectorDataIOFactory.h" +#include "otbVectorData.h" + +typedef short Type1; +typedef double Type2; + +typedef otb::VectorData<Type1> VectorData1Type; +typedef otb::VectorData<Type2> VectorData2Type; + +typedef otb::VectorDataIOFactory<VectorData1Type> VectorData1IOFactoryType; +typedef otb::VectorDataIOFactory<VectorData2Type> VectorData2IOFactoryType; + +typedef VectorData1IOFactoryType::VectorDataIOBasePointerType VectorData1IOBasePointerType; +typedef VectorData2IOFactoryType::VectorDataIOBasePointerType VectorData2IOBasePointerType; + +int otbVectorDataIOFactory(int argc, char * argv[]) +{ + VectorData1IOBasePointerType io1 = VectorData1IOFactoryType::CreateVectorDataIO(argv[1], VectorData1IOFactoryType::ReadMode); + std::cout << io1 << std::endl; + + VectorData2IOBasePointerType io2 = VectorData2IOFactoryType::CreateVectorDataIO(argv[1], VectorData2IOFactoryType::ReadMode); + std::cout << io2 << std::endl; + + return EXIT_SUCCESS; +} + diff --git a/Testing/Code/Projections/CMakeLists.txt b/Testing/Code/Projections/CMakeLists.txt index cfb331627b9096c3c48c7c908bedcb774dfe62b3..7483bd67dbc7b2f1dc2b2b98889666895b6b4691 100644 --- a/Testing/Code/Projections/CMakeLists.txt +++ b/Testing/Code/Projections/CMakeLists.txt @@ -475,7 +475,7 @@ ADD_TEST(prTvOrthoRectificationUTM_RADARSAT2_VV ${PROJECTIONS_TESTS2} ADD_TEST(prTvOrthoRectificationUTM_ENVISAT ${PROJECTIONS_TESTS2} --compare-image ${EPSILON_4} ${BASELINE}/prTvOrthoRectificationUTM_ENVISAT.tif ${TEMP}/prTvOrthoRectificationUTM_ENVISAT.tif - otbOrthoRectificationFilter + otbOrthoRectificationComplexFilter ${LARGEINPUT}/ENVISAT_ASAR_SCENE01/ASA_APS_1PNDPA20030821_7713.N1 ${TEMP}/prTvOrthoRectificationUTM_ENVISAT.tif 655696.679130 4906584.046495 @@ -485,7 +485,7 @@ ADD_TEST(prTvOrthoRectificationUTM_ENVISAT ${PROJECTIONS_TESTS2} ADD_TEST(prTvOrthoRectificationUTM_PALSAR ${PROJECTIONS_TESTS2} --compare-image ${EPSILON_4} ${BASELINE}/prTvOrthoRectificationUTM_PALSAR.tif ${TEMP}/prTvOrthoRectificationUTM_PALSAR.tif - otbOrthoRectificationFilter + otbOrthoRectificationComplexFilter ${LARGEINPUT}/PALSAR/200801280007/l1data/VOL-ALPSRP037120700-H1.1__A ${TEMP}/prTvOrthoRectificationUTM_PALSAR.tif 309298.731439 3909055.130746 @@ -495,7 +495,7 @@ ADD_TEST(prTvOrthoRectificationUTM_PALSAR ${PROJECTIONS_TESTS2} ADD_TEST(prTvOrthoRectificationUTM_TERRASARX_HH ${PROJECTIONS_TESTS2} --compare-image ${EPSILON_4} ${BASELINE}/prTvOrthoRectificationUTM_TERRASARX_HH.tif ${TEMP}/prTvOrthoRectificationUTM_TERRASARX_HH.tif - otbOrthoRectificationFilter + otbOrthoRectificationComplexFilter ${LARGEINPUT}/TERRASARX/PANGKALANBUUN/IMAGEDATA/IMAGE_HH_SRA_stripFar_008.cos ${TEMP}/prTvOrthoRectificationUTM_TERRASARX_HH.tif 591992.001073 9699689.825866 @@ -505,7 +505,7 @@ ADD_TEST(prTvOrthoRectificationUTM_TERRASARX_HH ${PROJECTIONS_TESTS2} ADD_TEST(prTvOrthoRectificationUTM_TERRASARX_VV ${PROJECTIONS_TESTS2} --compare-image ${EPSILON_4} ${BASELINE}/prTvOrthoRectificationUTM_TERRASARX_VV.tif ${TEMP}/prTvOrthoRectificationUTM_TERRASARX_VV.tif - otbOrthoRectificationFilter + otbOrthoRectificationComplexFilter ${LARGEINPUT}/TERRASARX/PANGKALANBUUN/IMAGEDATA/IMAGE_VV_SRA_stripFar_008.cos ${TEMP}/prTvOrthoRectificationUTM_TERRASARX_VV.tif 591992.001073 9699689.825866 @@ -819,6 +819,10 @@ ADD_TEST(prTvGenericRSTransformWithSRID ${PROJECTIONS_TESTS3} ) +ADD_TEST(prTvGenericRSTransformFromImage ${PROJECTIONS_TESTS3} + otbGenericRSTransformFromImage + ${INPUTDATA}/WithoutProjRefWithKeywordlist.tif) + ADD_TEST(prTuVectorDataProjectionFilterNew ${PROJECTIONS_TESTS3} otbVectorDataProjectionFilterNew ) #test points @@ -1006,7 +1010,21 @@ ADD_TEST(prTvImageToGenericRSOutputParameters ${PROJECTIONS_TESTS4} ) ENDIF(OTB_DATA_USE_LARGEINPUT) +#----- otb::RationalTransform ------------------------ +ADD_TEST(prTuRationalTransformNew ${PROJECTIONS_TESTS4} +otbRationalTransformNew) +ADD_TEST(prTvRationalTransform ${PROJECTIONS_TESTS4} + --compare-ascii ${NOTOL} + ${BASELINE_FILES}/otbRationalTransformOutput.txt + ${TEMP}/otbRationalTransformOutput.txt +otbRationalTransform +${TEMP}/otbRationalTransformOutput.txt +0 0 +1 1 +10 10 +-10 -10 +) #======================================================================================= @@ -1048,6 +1066,7 @@ otbGenericMapProjection.cxx otbGenericRSTransformNew.cxx otbGenericRSTransform.cxx otbGenericRSTransformWithSRID.cxx +otbGenericRSTransformFromImage.cxx otbVectorDataProjectionFilterNew.cxx otbVectorDataProjectionFilter.cxx otbVectorDataProjectionFilterFromMapToSensor.cxx @@ -1067,6 +1086,7 @@ otbGenericRSResampleImageFilter.cxx otbElevDatabaseHeightAboveMSLFunction.cxx otbImageToEnvelopeVectorDataFilter.cxx otbImageToGenericRSOutputParameters.cxx +otbRationalTransform.cxx ) OTB_ADD_EXECUTABLE(otbProjectionsTests1 "${Projections_SRCS1}" "OTBProjections;OTBIO;OTBTesting") diff --git a/Testing/Code/Projections/otbGenericRSTransformFromImage.cxx b/Testing/Code/Projections/otbGenericRSTransformFromImage.cxx new file mode 100644 index 0000000000000000000000000000000000000000..415d40aefd1fec2b73dfabd8e497cdbacd9c4ba5 --- /dev/null +++ b/Testing/Code/Projections/otbGenericRSTransformFromImage.cxx @@ -0,0 +1,66 @@ +/*========================================================================= + + Program: ORFEO Toolbox + Language: C++ + Date: $Date$ + Version: $Revision$ + + + Copyright (c) Centre National d'Etudes Spatiales. All rights reserved. + See OTBCopyright.txt for details. + + + This software is distributed WITHOUT ANY WARRANTY; without even + the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + PURPOSE. See the above copyright notices for more information. + +=========================================================================*/ +#if defined(_MSC_VER) +#pragma warning ( disable : 4786 ) +#endif + +#include "otbVectorImage.h" +#include "otbImageFileReader.h" +#include "otbGenericRSTransform.h" +#include <ogr_spatialref.h> +#include <fstream> + +typedef otb::VectorImage<double, 2> ImageType; +typedef otb::ImageFileReader<ImageType> ReaderType; +typedef otb::GenericRSTransform<> TransformType; +typedef TransformType::InputPointType PointType; + +int otbGenericRSTransformFromImage(int argc, char* argv[]) +{ + /* + * This test checks if we can instanciate a GenericRSTransform from the image information + * without throwing an exception + */ + + // Reader + ReaderType::Pointer reader = ReaderType::New(); + reader->SetFileName(argv[1]); + reader->UpdateOutputInformation(); + + // Build wgs ref + OGRSpatialReference oSRS; + oSRS.SetWellKnownGeogCS("WGS84"); + char * wgsRef = NULL; + oSRS.exportToWkt(&wgsRef); + + // Instanciate WGS->Image transform + TransformType::Pointer wgs2img = TransformType::New(); + wgs2img->SetInputProjectionRef(wgsRef); + wgs2img->SetOutputProjectionRef(reader->GetOutput()->GetProjectionRef()); + wgs2img->SetOutputKeywordList(reader->GetOutput()->GetImageKeywordlist()); + wgs2img->InstanciateTransform(); + + // Instanciate Image->WGS transform + TransformType::Pointer img2wgs = TransformType::New(); + img2wgs->SetInputProjectionRef(reader->GetOutput()->GetProjectionRef()); + img2wgs->SetInputKeywordList(reader->GetOutput()->GetImageKeywordlist()); + img2wgs->SetOutputProjectionRef(wgsRef); + img2wgs->InstanciateTransform(); + + return EXIT_SUCCESS; +} diff --git a/Testing/Code/Projections/otbImageToGenericRSOutputParameters.cxx b/Testing/Code/Projections/otbImageToGenericRSOutputParameters.cxx index 89b9a19d6c3a72c331146cb15bbe2be7a14be6a3..19e39ba69ffd4728ebe1361ce04fc9f0a70254cc 100644 --- a/Testing/Code/Projections/otbImageToGenericRSOutputParameters.cxx +++ b/Testing/Code/Projections/otbImageToGenericRSOutputParameters.cxx @@ -59,13 +59,13 @@ int otbImageToGenericRSOutputParameters (int argc, char * argv[]) spacing[0] = 0.000006; spacing[1] = -0.000006; - // Filter : Taget SRS : WGS84 + // Filter : Target SRS : WGS84 FilterType::Pointer filter = FilterType::New(); filter->SetInput(reader->GetOutput()); filter->SetOutputProjectionRef(otb::GeoInformationConversion::ToWKT(4326)); //WGS84 filter->Compute(); - // Otuput file + // Output file std::ofstream outfile(outfname); outfile<<"Output Parameters for SRID : 4326 (WGS84)"<<std::endl; @@ -74,7 +74,7 @@ int otbImageToGenericRSOutputParameters (int argc, char * argv[]) outfile<<"Output Size : "<<filter->GetOutputSize()<<std::endl; outfile<< std::endl; - // target SRS : 32631 UTM 31 N + // Target SRS : 32631 UTM 31 N filter->SetOutputProjectionRef(otb::GeoInformationConversion::ToWKT(32631)); //WGS84 filter->Compute(); @@ -84,7 +84,7 @@ int otbImageToGenericRSOutputParameters (int argc, char * argv[]) outfile<<"Output Size : "<<filter->GetOutputSize()<<std::endl; outfile<< std::endl; - // target SRS : lambertII + // Target SRS : lambertII typedef otb::Lambert2EtenduForwardProjection Lambert2Type; Lambert2Type::Pointer lambert2Projection = Lambert2Type::New(); std::string lambertRef = lambert2Projection->GetWkt(); diff --git a/Testing/Code/Projections/otbOrthoRectificationFilter.cxx b/Testing/Code/Projections/otbOrthoRectificationFilter.cxx index d524e44526747d18dc3f21975a8d19dffc27d580..4a9f9ac4320cde44e27be780b6e35e52b2eebd82 100644 --- a/Testing/Code/Projections/otbOrthoRectificationFilter.cxx +++ b/Testing/Code/Projections/otbOrthoRectificationFilter.cxx @@ -28,7 +28,8 @@ #include "otbImageFileReader.h" #include "otbStreamingImageFileWriter.h" #include "otbMapProjections.h" - +#include "itkComplexToModulusImageFilter.h" +#include "otbUnaryImageFunctorWithVectorImageFilter.h" #include "otbOrthoRectificationFilter.h" #include "otbMapProjections.h" @@ -46,11 +47,11 @@ int otbOrthoRectificationFilter(int argc, char* argv[]) return EXIT_FAILURE; } - typedef otb::VectorImage<double, 2> ImageType; - typedef otb::ImageFileReader<ImageType> ReaderType; - typedef otb::StreamingImageFileWriter<ImageType> WriterType; + typedef otb::VectorImage<double, 2> VectorImageType; + typedef otb::ImageFileReader<VectorImageType> ReaderType; + typedef otb::StreamingImageFileWriter<VectorImageType> WriterType; typedef otb::UtmInverseProjection UtmMapProjectionType; - typedef otb::OrthoRectificationFilter<ImageType, ImageType, UtmMapProjectionType> OrthoRectifFilterType; + typedef otb::OrthoRectificationFilter<VectorImageType, VectorImageType, UtmMapProjectionType> OrthoRectifFilterType; //Allocate pointer ReaderType::Pointer reader = ReaderType::New(); @@ -68,22 +69,22 @@ int otbOrthoRectificationFilter(int argc, char* argv[]) orthoRectifFilter->SetInput(reader->GetOutput()); - ImageType::IndexType start; + VectorImageType::IndexType start; start[0] = 0; start[1] = 0; orthoRectifFilter->SetOutputStartIndex(start); - ImageType::SizeType size; + VectorImageType::SizeType size; size[0] = atoi(argv[5]); // X size size[1] = atoi(argv[6]); //Y size orthoRectifFilter->SetOutputSize(size); - ImageType::SpacingType spacing; + VectorImageType::SpacingType spacing; spacing[0] = atof(argv[7]); spacing[1] = atof(argv[8]); orthoRectifFilter->SetOutputSpacing(spacing); - ImageType::PointType origin; + VectorImageType::PointType origin; origin[0] = strtod(argv[3], NULL); //Origin easting origin[1] = strtod(argv[4], NULL); //Origin northing orthoRectifFilter->SetOutputOrigin(origin); @@ -93,7 +94,7 @@ int otbOrthoRectificationFilter(int argc, char* argv[]) orthoRectifFilter->SetMapProjection(utmMapProjection); // Deformation Field spacing - ImageType::SpacingType gridSpacing; + VectorImageType::SpacingType gridSpacing; gridSpacing[0] = atof(argv[11]); gridSpacing[1] = -atof(argv[11]); orthoRectifFilter->SetDeformationFieldSpacing(gridSpacing); @@ -104,3 +105,85 @@ int otbOrthoRectificationFilter(int argc, char* argv[]) return EXIT_SUCCESS; } + + +int otbOrthoRectificationComplexFilter(int argc, char* argv[]) +{ + ossimInit::instance()->initialize(argc, argv); + if (argc != 12) + { + std::cout << argv[0] << + " <input filename> <output filename> <origin easting> <origin northing> <x size> <y size> <x spacing> <y spacing> <UTM zone> <UTM hemisphere>" + << std::endl; + + return EXIT_FAILURE; + } + + typedef otb::VectorImage<std::complex<double>, 2> ComplexVectorImageType; + typedef otb::VectorImage<double, 2> ModulusVectorImageType; + typedef otb::UnaryImageFunctorWithVectorImageFilter< + ComplexVectorImageType, + ModulusVectorImageType, + itk::Function::ComplexToModulus< + ComplexVectorImageType::InternalPixelType, + ModulusVectorImageType::InternalPixelType + > + > ComplexToModulusFilterType; + typedef otb::ImageFileReader<ComplexVectorImageType> ReaderType; + typedef otb::StreamingImageFileWriter<ModulusVectorImageType> WriterType; + typedef otb::UtmInverseProjection UtmMapProjectionType; + typedef otb::OrthoRectificationFilter<ModulusVectorImageType, ModulusVectorImageType, UtmMapProjectionType> OrthoRectifFilterType; + + //Allocate pointer + ReaderType::Pointer reader = ReaderType::New(); + reader->SetFileName(argv[1]); + reader->GenerateOutputInformation(); + std::cout << reader->GetOutput() << std::endl; + + ComplexToModulusFilterType::Pointer complexToModulus = ComplexToModulusFilterType::New(); + complexToModulus->SetInput(reader->GetOutput()); + + UtmMapProjectionType::Pointer utmMapProjection = UtmMapProjectionType::New(); + OrthoRectifFilterType::Pointer orthoRectifFilter = OrthoRectifFilterType::New(); + + orthoRectifFilter->SetInput(complexToModulus->GetOutput()); + + ComplexVectorImageType::IndexType start; + start[0] = 0; + start[1] = 0; + orthoRectifFilter->SetOutputStartIndex(start); + + ComplexVectorImageType::SizeType size; + size[0] = atoi(argv[5]); // X size + size[1] = atoi(argv[6]); //Y size + orthoRectifFilter->SetOutputSize(size); + + ComplexVectorImageType::SpacingType spacing; + spacing[0] = atof(argv[7]); + spacing[1] = atof(argv[8]); + orthoRectifFilter->SetOutputSpacing(spacing); + + ComplexVectorImageType::PointType origin; + origin[0] = strtod(argv[3], NULL); //Origin easting + origin[1] = strtod(argv[4], NULL); //Origin northing + orthoRectifFilter->SetOutputOrigin(origin); + + utmMapProjection->SetZone(atoi(argv[9])); + utmMapProjection->SetHemisphere(argv[10][0]); + orthoRectifFilter->SetMapProjection(utmMapProjection); + + // Deformation Field spacing + ComplexVectorImageType::SpacingType gridSpacing; + gridSpacing[0] = atof(argv[11]); + gridSpacing[1] = -atof(argv[11]); + orthoRectifFilter->SetDeformationFieldSpacing(gridSpacing); + + + WriterType::Pointer writer = WriterType::New(); + writer->SetFileName(argv[2]); + writer->SetInput(orthoRectifFilter->GetOutput()); + writer->SetTilingStreamDivisions(4); + writer->Update(); + + return EXIT_SUCCESS; +} diff --git a/Testing/Code/Projections/otbProjectionsTests2.cxx b/Testing/Code/Projections/otbProjectionsTests2.cxx index 24254d0927356c39e8e5f6f712f79fc8b3588d4c..c8e5b0a1594dbebec8165e25a7f55ade4ac938d6 100644 --- a/Testing/Code/Projections/otbProjectionsTests2.cxx +++ b/Testing/Code/Projections/otbProjectionsTests2.cxx @@ -28,6 +28,7 @@ void RegisterTests() { REGISTER_TEST(otbOrthoRectificationFilterNew); REGISTER_TEST(otbOrthoRectificationFilter); + REGISTER_TEST(otbOrthoRectificationComplexFilter); REGISTER_TEST(otbOrthoRectificationFilterWithDEM); REGISTER_TEST(otbOrthoRectificationMonoThreadFilter); REGISTER_TEST(otbGCPsToRPCSensorModelImageFilterNew); diff --git a/Testing/Code/Projections/otbProjectionsTests3.cxx b/Testing/Code/Projections/otbProjectionsTests3.cxx index 8a7823dc6406ef2c170149fff9014e6dc0efcb8c..cfac112ba3e9ca38fab26036109da7b343ddca08 100644 --- a/Testing/Code/Projections/otbProjectionsTests3.cxx +++ b/Testing/Code/Projections/otbProjectionsTests3.cxx @@ -33,6 +33,7 @@ void RegisterTests() REGISTER_TEST(otbGenericRSTransformNew); REGISTER_TEST(otbGenericRSTransform); REGISTER_TEST(otbGenericRSTransformWithSRID); + REGISTER_TEST(otbGenericRSTransformFromImage); REGISTER_TEST(otbVectorDataProjectionFilterNew); REGISTER_TEST(otbVectorDataProjectionFilter); REGISTER_TEST(otbVectorDataProjectionFilterFromMapToSensor); diff --git a/Testing/Code/Projections/otbProjectionsTests4.cxx b/Testing/Code/Projections/otbProjectionsTests4.cxx index 54d72c19f153b428f000d11687d3b477244dc2e8..de3ea5481bd1c572266fc24df1f7c15242b23531 100644 --- a/Testing/Code/Projections/otbProjectionsTests4.cxx +++ b/Testing/Code/Projections/otbProjectionsTests4.cxx @@ -35,4 +35,6 @@ void RegisterTests() REGISTER_TEST(otbImageToEnvelopeVectorDataFilter); REGISTER_TEST(otbImageToGenericRSOutputParametersNew); REGISTER_TEST(otbImageToGenericRSOutputParameters); + REGISTER_TEST(otbRationalTransformNew); + REGISTER_TEST(otbRationalTransform); } diff --git a/Testing/Code/Projections/otbRationalTransform.cxx b/Testing/Code/Projections/otbRationalTransform.cxx new file mode 100644 index 0000000000000000000000000000000000000000..4b0e1ba826b4552c5e6276995e53039f72b50eb5 --- /dev/null +++ b/Testing/Code/Projections/otbRationalTransform.cxx @@ -0,0 +1,101 @@ +/*========================================================================= + + Program: ORFEO Toolbox + Language: C++ + Date: $Date$ + Version: $Revision$ + + + Copyright (c) Centre National d'Etudes Spatiales. All rights reserved. + See OTBCopyright.txt for details. + + + This software is distributed WITHOUT ANY WARRANTY; without even + the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + PURPOSE. See the above copyright notices for more information. + +=========================================================================*/ +#if defined(_MSC_VER) +#pragma warning ( disable : 4786 ) +#endif + +#include "otbRationalTransform.h" +#include <fstream> + +int otbRationalTransformNew(int argc, char* argv[]) +{ + typedef otb::RationalTransform<> RationalTransformType; + + // Instantiation + RationalTransformType::Pointer rt = RationalTransformType::New(); + + return EXIT_SUCCESS; +} + +int otbRationalTransform(int argc, char* argv[]) +{ + typedef otb::RationalTransform<> RationalTransformType; + + // Instantiation + RationalTransformType::Pointer rt = RationalTransformType::New(); + rt->SetNumeratorDegree(4); + rt->SetDenominatorDegree(4); + + RationalTransformType::ParametersType params(rt->GetNumberOfParameters()); + params.Fill(1.); + + // Rational is + // fx(x, y) = (1+2*x+3*x^2+4*x^3+5*x^4)/(6+7*x+8*x^2+9*x^3+10*x^4) + // fy(x, y) = (11+12*y+13*y^2+14*y^3+15*y^4)/(16+17*y+18*y^2+19*y^3+20*y^4) + params[0]=1; + params[1]=2; + params[2]=3; + params[3]=4; + params[4]=5; + params[5]=6; + params[6]=7; + params[7]=8; + params[8]=9; + params[9]=10; + params[10]=11; + params[11]=12; + params[12]=13; + params[13]=14; + params[14]=15; + params[15]=16; + params[16]=17; + params[17]=18; + params[18]=19; + params[19]=20; + + rt->SetParameters(params); + + RationalTransformType::InputPointType inputPoint; + RationalTransformType::OutputPointType outputPoint; + + std::ofstream ofs; + ofs.open(argv[1]); + + // Set floatfield to format writing properly + ofs.setf(std::ios::fixed, std::ios::floatfield); + ofs.precision(10); + + unsigned int idx = 2; + + ofs<<"Rational function is: "<<std::endl; + ofs<<"fx(x, y) = (1+2*x+3*x^2+4*x^3+5*x^4)/(6+7*x+8*x^2+9*x^3+10*x^4)"<<std::endl; + ofs<<"fy(x, y) = (11+12*y+13*y^2+14*y^3+15*y^4)/(16+17*y+18*y^2+19*y^3+20*y^4)"<<std::endl; + while(idx+1<(unsigned int)argc) + { + inputPoint[0] = atof(argv[idx]); + inputPoint[1] = atof(argv[idx+1]); + outputPoint = rt->TransformPoint(inputPoint); + ofs<<inputPoint<<" -> "<<outputPoint<<std::endl; + idx+=2; + } + + ofs.close(); + + return EXIT_SUCCESS; +} + diff --git a/Testing/Code/SARPolarimetry/CMakeLists.txt b/Testing/Code/SARPolarimetry/CMakeLists.txt index 80ac1101c4af3d95c36fed866662a3dfeb2a08a6..152de721dacaf9709033c8e880ebbaf840982ed7 100644 --- a/Testing/Code/SARPolarimetry/CMakeLists.txt +++ b/Testing/Code/SARPolarimetry/CMakeLists.txt @@ -266,7 +266,7 @@ ADD_TEST(saTuReciprocalHAlphaImageFilterNew ${SARPOLARIMETRY_TESTS1} ADD_TEST(saTvReciprocalHAlphaImageFilter ${SARPOLARIMETRY_TESTS1} --compare-image ${EPSILON_12} ${BASELINE}/saTvReciprocalHAlphaImageFilter.tif ${TEMP}/saTvReciprocalHAlphaImageFilter.tif - otbHAlphaImageFilter + otbReciprocalHAlphaImageFilter ${INPUTDATA}/RSAT_imagery_HH.tif ${INPUTDATA}/RSAT_imagery_HV.tif ${INPUTDATA}/RSAT_imagery_HV.tif @@ -337,6 +337,10 @@ ADD_TEST(saTvMuellerToMLCImageFilter ${SARPOLARIMETRY_TESTS1} ${INPUTDATA}/RSAT_imagery_VV.tif ${TEMP}/saTvMuellerToMLCImageFilter.tif ) +# Hermitian eigen analysis class +ADD_TEST(saTvHermitianEigenAnalysisTest ${SARPOLARIMETRY_TESTS1} + otbHermitianEigenAnalysisTest +) # A enrichir SET(SARPOLARIMETRY_SRCS1 @@ -350,6 +354,7 @@ otbMultiChannelsPolarimetricSynthesisFilterNew.cxx otbMultiChannelsPolarimetricSynthesisFilter.cxx otbVectorMultiChannelsPolarimetricSynthesisFilter.cxx otbSinclairToCovarianceFunctor.cxx +otbSinclairToReciprocalCovarianceFunctor.cxx otbSinclairImageFilter.cxx otbMLCToCoherencyImageFilterNew.cxx otbMLCToCoherencyImageFilter.cxx @@ -367,6 +372,7 @@ otbMuellerToPolarisationDegreeAndPowerImageFilterNew.cxx otbMuellerToPolarisationDegreeAndPowerImageFilter.cxx otbMuellerToMLCImageFilterNew.cxx otbMuellerToMLCImageFilter.cxx +otbHermitianEigenAnalysisTest.cxx ) OTB_ADD_EXECUTABLE(otbSARPolarimetryTests1 "${SARPOLARIMETRY_SRCS1}" "OTBSARPolarimetry;OTBIO;OTBTesting") diff --git a/Testing/Code/SARPolarimetry/otbHermitianEigenAnalysisTest.cxx b/Testing/Code/SARPolarimetry/otbHermitianEigenAnalysisTest.cxx new file mode 100644 index 0000000000000000000000000000000000000000..3a111558ca201e4391e6083a31b70928eb9d63c1 --- /dev/null +++ b/Testing/Code/SARPolarimetry/otbHermitianEigenAnalysisTest.cxx @@ -0,0 +1,40 @@ +/*========================================================================= + + Program: ORFEO Toolbox + Language: C++ + Date: $Date$ + Version: $Revision$ + + + Copyright (c) Centre National d'Etudes Spatiales. All rights reserved. + See OTBCopyright.txt for details. + + + This software is distributed WITHOUT ANY WARRANTY; without even + the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + PURPOSE. See the above copyright notices for more information. + +=========================================================================*/ +#if defined(_MSC_VER) +#pragma warning ( disable : 4786 ) +#endif + +#include "itkExceptionObject.h" +#include <iostream> + +#include "otbImage.h" +#include "otbVectorImage.h" +#include "otbHermitianEigenAnalysis.h" + +int otbHermitianEigenAnalysisTest(int argc, char * argv[]) +{ + typedef vnl_matrix<double> MatrixType; + typedef std::vector<double> VectorType; + + + typedef otb::HermitianEigenAnalysis<MatrixType, VectorType> FilterType; + + FilterType filter; + + return EXIT_SUCCESS; +} diff --git a/Testing/Code/SARPolarimetry/otbMLCToCircularCoherencyDegreeImageFilterNew.cxx b/Testing/Code/SARPolarimetry/otbMLCToCircularCoherencyDegreeImageFilterNew.cxx index c79e3ddd94d5ed353f394f9c2a5cafe05a0f9c5f..78669a68b07b24da7542b685fa6c1b170126a67a 100644 --- a/Testing/Code/SARPolarimetry/otbMLCToCircularCoherencyDegreeImageFilterNew.cxx +++ b/Testing/Code/SARPolarimetry/otbMLCToCircularCoherencyDegreeImageFilterNew.cxx @@ -37,7 +37,5 @@ int otbMLCToCircularCoherencyDegreeImageFilterNew(int argc, char * argv[]) FilterType::Pointer filter = FilterType::New(); - std::cout << filter << std::endl; - return EXIT_SUCCESS; } diff --git a/Testing/Code/SARPolarimetry/otbMLCToCoherencyDegreeImageFilterNew.cxx b/Testing/Code/SARPolarimetry/otbMLCToCoherencyDegreeImageFilterNew.cxx index 496e6b23599b7716da99a2eb1b030750eec1fc9f..70cd40313abda21f349016ea9c29938c5eb053c9 100644 --- a/Testing/Code/SARPolarimetry/otbMLCToCoherencyDegreeImageFilterNew.cxx +++ b/Testing/Code/SARPolarimetry/otbMLCToCoherencyDegreeImageFilterNew.cxx @@ -37,7 +37,5 @@ int otbMLCToCoherencyDegreeImageFilterNew(int argc, char * argv[]) FilterType::Pointer filter = FilterType::New(); - std::cout << filter << std::endl; - return EXIT_SUCCESS; } diff --git a/Testing/Code/SARPolarimetry/otbMLCToCoherencyImageFilterNew.cxx b/Testing/Code/SARPolarimetry/otbMLCToCoherencyImageFilterNew.cxx index 96212610514e14f43d320dc27f7348b261e2f8fe..d07c6da4a8f1349d98549a6b623d8ea8d3971cb8 100644 --- a/Testing/Code/SARPolarimetry/otbMLCToCoherencyImageFilterNew.cxx +++ b/Testing/Code/SARPolarimetry/otbMLCToCoherencyImageFilterNew.cxx @@ -37,7 +37,5 @@ int otbMLCToCoherencyImageFilterNew(int argc, char * argv[]) FilterType::Pointer filter = FilterType::New(); - std::cout << filter << std::endl; - return EXIT_SUCCESS; } diff --git a/Testing/Code/SARPolarimetry/otbMuellerToCircularPolarisationImageFilterNew.cxx b/Testing/Code/SARPolarimetry/otbMuellerToCircularPolarisationImageFilterNew.cxx index fa5c002d25bbd6bc1f36d666c4a0c096501c34d3..1b482a6bdf72f4331007ef17a5b80e902d772778 100644 --- a/Testing/Code/SARPolarimetry/otbMuellerToCircularPolarisationImageFilterNew.cxx +++ b/Testing/Code/SARPolarimetry/otbMuellerToCircularPolarisationImageFilterNew.cxx @@ -36,7 +36,5 @@ int otbMuellerToCircularPolarisationImageFilterNew(int argc, char * argv[]) FilterType::Pointer filter = FilterType::New(); - std::cout << filter << std::endl; - return EXIT_SUCCESS; } diff --git a/Testing/Code/SARPolarimetry/otbMuellerToMLCImageFilterNew.cxx b/Testing/Code/SARPolarimetry/otbMuellerToMLCImageFilterNew.cxx index da3ca7f311f4d2bb1453cbb83d142d0d5d4f1601..d533f1ed540bae4cca6f6c6ccebc281d6a615047 100644 --- a/Testing/Code/SARPolarimetry/otbMuellerToMLCImageFilterNew.cxx +++ b/Testing/Code/SARPolarimetry/otbMuellerToMLCImageFilterNew.cxx @@ -38,7 +38,5 @@ int otbMuellerToMLCImageFilterNew(int argc, char * argv[]) FilterType::Pointer filter = FilterType::New(); - std::cout << filter << std::endl; - return EXIT_SUCCESS; } diff --git a/Testing/Code/SARPolarimetry/otbMuellerToPolarisationDegreeAndPowerImageFilterNew.cxx b/Testing/Code/SARPolarimetry/otbMuellerToPolarisationDegreeAndPowerImageFilterNew.cxx index 18d94e90287a5a7b61c9e7c917a3e1cd6a405f66..f084149bd80a9674ae851e228645d1cedf4c17c7 100644 --- a/Testing/Code/SARPolarimetry/otbMuellerToPolarisationDegreeAndPowerImageFilterNew.cxx +++ b/Testing/Code/SARPolarimetry/otbMuellerToPolarisationDegreeAndPowerImageFilterNew.cxx @@ -36,7 +36,5 @@ int otbMuellerToPolarisationDegreeAndPowerImageFilterNew(int argc, char * argv[] FilterType::Pointer filter = FilterType::New(); - std::cout << filter << std::endl; - return EXIT_SUCCESS; } diff --git a/Testing/Code/SARPolarimetry/otbMultiChannelsPolarimetricSynthesisFilterNew.cxx b/Testing/Code/SARPolarimetry/otbMultiChannelsPolarimetricSynthesisFilterNew.cxx index 95e195e45dc54bab87d072a9dbfa6c31837b7932..16ee6ce6077fc8ae897c2b18ecbb17f24467dd27 100644 --- a/Testing/Code/SARPolarimetry/otbMultiChannelsPolarimetricSynthesisFilterNew.cxx +++ b/Testing/Code/SARPolarimetry/otbMultiChannelsPolarimetricSynthesisFilterNew.cxx @@ -39,7 +39,5 @@ int otbMultiChannelsPolarimetricSynthesisFilterNew(int argc, char * argv[]) FilterType::Pointer filter = FilterType::New(); - std::cout << filter << std::endl; - return EXIT_SUCCESS; } diff --git a/Testing/Code/SARPolarimetry/otbPolarimetricSynthesisFilterNew.cxx b/Testing/Code/SARPolarimetry/otbPolarimetricSynthesisFilterNew.cxx index 8db9eb8bc049c2dcdabdcbcf01152a7a72c1e0d4..718e186083e9dc248b050fedae5eb0d5e0857936 100644 --- a/Testing/Code/SARPolarimetry/otbPolarimetricSynthesisFilterNew.cxx +++ b/Testing/Code/SARPolarimetry/otbPolarimetricSynthesisFilterNew.cxx @@ -40,7 +40,5 @@ int otbPolarimetricSynthesisFilterNew(int argc, char * argv[]) FilterType::Pointer filter = FilterType::New(); - std::cout << filter << std::endl; - return EXIT_SUCCESS; } diff --git a/Testing/Code/SARPolarimetry/otbReciprocalCoherencyToMuellerImageFilterNew.cxx b/Testing/Code/SARPolarimetry/otbReciprocalCoherencyToMuellerImageFilterNew.cxx index 7dbcfcc1a8e98ec9306d1985f1bdbb9352f67d64..47bef8d8d91b9e1a641ecd0ef4ec86b5617c6a80 100644 --- a/Testing/Code/SARPolarimetry/otbReciprocalCoherencyToMuellerImageFilterNew.cxx +++ b/Testing/Code/SARPolarimetry/otbReciprocalCoherencyToMuellerImageFilterNew.cxx @@ -36,7 +36,5 @@ int otbReciprocalCoherencyToMuellerImageFilterNew(int argc, char * argv[]) FilterType::Pointer filter = FilterType::New(); - std::cout << filter << std::endl; - return EXIT_SUCCESS; } diff --git a/Testing/Code/SARPolarimetry/otbReciprocalHAlphaImageFilterNew.cxx b/Testing/Code/SARPolarimetry/otbReciprocalHAlphaImageFilterNew.cxx index 4cb17b6f32b6c4234267e4664c6a309b38697dd8..4f1e94be9a82f5e23dbb6a779a3034085cb5c16c 100644 --- a/Testing/Code/SARPolarimetry/otbReciprocalHAlphaImageFilterNew.cxx +++ b/Testing/Code/SARPolarimetry/otbReciprocalHAlphaImageFilterNew.cxx @@ -36,7 +36,5 @@ int otbReciprocalHAlphaImageFilterNew(int argc, char * argv[]) FilterType::Pointer filter = FilterType::New(); - std::cout << filter << std::endl; - return EXIT_SUCCESS; } diff --git a/Testing/Code/SARPolarimetry/otbSARPolarimetryTests1.cxx b/Testing/Code/SARPolarimetry/otbSARPolarimetryTests1.cxx index 7dde2e00eea997d2b9b69a36251266d33a712384..95724e8111ca37c1f5c0a4a3114371186c663c90 100644 --- a/Testing/Code/SARPolarimetry/otbSARPolarimetryTests1.cxx +++ b/Testing/Code/SARPolarimetry/otbSARPolarimetryTests1.cxx @@ -35,6 +35,7 @@ void RegisterTests() REGISTER_TEST(otbMultiChannelsPolarimetricSynthesisFilter); REGISTER_TEST(otbVectorMultiChannelsPolarimetricSynthesisFilter); REGISTER_TEST(otbSinclairToReciprocalCovarianceFunctor); + REGISTER_TEST(otbSinclairToCovarianceFunctor); REGISTER_TEST(otbSinclairImageFilter); REGISTER_TEST(otbMLCToCoherencyImageFilterNew); REGISTER_TEST(otbMLCToCoherencyImageFilter); @@ -52,4 +53,5 @@ void RegisterTests() REGISTER_TEST(otbMuellerToPolarisationDegreeAndPowerImageFilter); REGISTER_TEST(otbMuellerToMLCImageFilterNew); REGISTER_TEST(otbMuellerToMLCImageFilter); + REGISTER_TEST(otbHermitianEigenAnalysisTest); } diff --git a/Testing/Code/SARPolarimetry/otbSinclairToCovarianceFunctor.cxx b/Testing/Code/SARPolarimetry/otbSinclairToCovarianceFunctor.cxx index 830fc9aecc1dcb4012ca7a4523492ccadcff7d51..db4b78440364180e540fb6c78f6f4a787246e6c3 100644 --- a/Testing/Code/SARPolarimetry/otbSinclairToCovarianceFunctor.cxx +++ b/Testing/Code/SARPolarimetry/otbSinclairToCovarianceFunctor.cxx @@ -17,27 +17,31 @@ =========================================================================*/ #include "itkExceptionObject.h" -#include "otbSinclairToReciprocalCovarianceFunctor.h" +#include "otbSinclairToCovarianceFunctor.h" #include "itkVariableLengthVector.h" -int otbSinclairToReciprocalCovarianceFunctor(int argc, char * argv[]) +int otbSinclairToCovarianceFunctor(int argc, char * argv[]) { typedef std::complex<double> ScalarType; typedef itk::VariableLengthVector<ScalarType> OutputType; - typedef otb::Functor::SinclairToReciprocalCovarianceFunctor<ScalarType, ScalarType, + typedef otb::Functor::SinclairToCovarianceFunctor<ScalarType, ScalarType, ScalarType, ScalarType, OutputType > FunctorType; - OutputType result(6); + OutputType result(10); FunctorType funct; OutputType outputFunct; result[0] = 1.0; result[1] = 0.0; - result[2] = 1.0; - result[3] = 0.0; + result[2] = 0.0; + result[3] = 1.0; result[4] = 0.0; - result[5] = 1.0; + result[5] = 0.0; + result[6] = 0.0; + result[7] = 0.0; + result[8] = 0.0; + result[9] = 1.0; outputFunct = funct.operator ()( 1.0, 0.0, 0.0, 1.0); @@ -46,7 +50,11 @@ int otbSinclairToReciprocalCovarianceFunctor(int argc, char * argv[]) vcl_abs(result[2]-outputFunct[2]) > 1e-10 || vcl_abs(result[3]-outputFunct[3]) > 1e-10 || vcl_abs(result[4]-outputFunct[4]) > 1e-10 || - vcl_abs(result[5]-outputFunct[5]) > 1e-10) + vcl_abs(result[5]-outputFunct[5]) > 1e-10 || + vcl_abs(result[6]-outputFunct[6]) > 1e-10 || + vcl_abs(result[7]-outputFunct[7]) > 1e-10 || + vcl_abs(result[8]-outputFunct[8]) > 1e-10 || + vcl_abs(result[9]-outputFunct[9]) > 1e-10) { return EXIT_FAILURE; } diff --git a/Testing/Code/SARPolarimetry/otbSinclairToReciprocalCovarianceFunctor.cxx b/Testing/Code/SARPolarimetry/otbSinclairToReciprocalCovarianceFunctor.cxx new file mode 100644 index 0000000000000000000000000000000000000000..830fc9aecc1dcb4012ca7a4523492ccadcff7d51 --- /dev/null +++ b/Testing/Code/SARPolarimetry/otbSinclairToReciprocalCovarianceFunctor.cxx @@ -0,0 +1,55 @@ +/*========================================================================= + + Program: ORFEO Toolbox + Language: C++ + Date: $Date$ + Version: $Revision$ + + + Copyright (c) Centre National d'Etudes Spatiales. All rights reserved. + See OTBCopyright.txt for details. + + + This software is distributed WITHOUT ANY WARRANTY; without even + the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + PURPOSE. See the above copyright notices for more information. + +=========================================================================*/ +#include "itkExceptionObject.h" + +#include "otbSinclairToReciprocalCovarianceFunctor.h" +#include "itkVariableLengthVector.h" + +int otbSinclairToReciprocalCovarianceFunctor(int argc, char * argv[]) +{ + typedef std::complex<double> ScalarType; + typedef itk::VariableLengthVector<ScalarType> OutputType; + + typedef otb::Functor::SinclairToReciprocalCovarianceFunctor<ScalarType, ScalarType, + ScalarType, ScalarType, OutputType > FunctorType; + + OutputType result(6); + FunctorType funct; + OutputType outputFunct; + + result[0] = 1.0; + result[1] = 0.0; + result[2] = 1.0; + result[3] = 0.0; + result[4] = 0.0; + result[5] = 1.0; + + outputFunct = funct.operator ()( 1.0, 0.0, 0.0, 1.0); + + if( vcl_abs(result[0]-outputFunct[0]) > 1e-10 || + vcl_abs(result[1]-outputFunct[1]) > 1e-10 || + vcl_abs(result[2]-outputFunct[2]) > 1e-10 || + vcl_abs(result[3]-outputFunct[3]) > 1e-10 || + vcl_abs(result[4]-outputFunct[4]) > 1e-10 || + vcl_abs(result[5]-outputFunct[5]) > 1e-10) + { + return EXIT_FAILURE; + } + + return EXIT_SUCCESS; +} diff --git a/Testing/Code/TestSystem/CMakeLists.txt b/Testing/Code/TestSystem/CMakeLists.txt index 91883a3cae25bf723e7ab1b5f7ead2674bc9a7ac..5c35cf0121fa846348f4bf034f170b49aba84480 100644 --- a/Testing/Code/TestSystem/CMakeLists.txt +++ b/Testing/Code/TestSystem/CMakeLists.txt @@ -20,6 +20,12 @@ SET(EPSILON_3 0.001) SET(TESTSYSTEM_TESTS ${CXX_TEST_PATH}/otbTestSystemTests) +#Test if the current working copy corresponds to the nightly revision number +ADD_TEST(tsTuIsNightlyRevision ${TESTSYSTEM_TESTS} + otbIsNightlyRevision + ${OTB_WC_REVISION} + http://www.orfeo-toolbox.org/nightly/libNightlyNumber ) + #Test a basic ascii comparison ADD_TEST(tsTvCompareAscii ${TESTSYSTEM_TESTS} --compare-ascii ${NOTOL} @@ -124,6 +130,7 @@ ADD_TEST(tsTvCompareAscii5epsilon2 ${TESTSYSTEM_TESTS} # ------- CXX source files ----------------------------------- SET(TESTSYSTEM_SRCS otbTestSystemTests.cxx +otbIsNightlyRevision.cxx otbCompareAsciiTests.cxx otbCompareAsciiTests2.cxx otbCompareAsciiTests3.cxx diff --git a/Testing/Code/TestSystem/otbIsNightlyRevision.cxx b/Testing/Code/TestSystem/otbIsNightlyRevision.cxx new file mode 100644 index 0000000000000000000000000000000000000000..1a3aa2edbf4e9832cd7f2850ae698cdf4737e98c --- /dev/null +++ b/Testing/Code/TestSystem/otbIsNightlyRevision.cxx @@ -0,0 +1,48 @@ +/*========================================================================= + + Program: ORFEO Toolbox + Language: C++ + Date: $Date$ + Version: $Revision$ + + + Copyright (c) Centre National d'Etudes Spatiales. All rights reserved. + See OTBCopyright.txt for details. + + + This software is distributed WITHOUT ANY WARRANTY; without even + the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + PURPOSE. See the above copyright notices for more information. + +=========================================================================*/ +#include <iostream> +#include <fstream> + +#include "otbCurlHelper.h" + +int otbIsNightlyRevision(int argc, char * argv[]) +{ + if (argc != 3) + { + return EXIT_FAILURE; + } + + std::string wcRevision = argv[1]; + std::string nightlyRevisionUrl = argv[2]; + + otb::CurlHelper::Pointer curl = otb::CurlHelper::New(); + + std::string nightlyRevision; + curl->RetrieveUrlInMemory(nightlyRevisionUrl, nightlyRevision); + + if (nightlyRevision == wcRevision) + { + return EXIT_SUCCESS; + } + else + { + std::cerr << "Nightly revision is " << nightlyRevision << " but working copy revision is " << wcRevision << std::endl; + return EXIT_FAILURE; + } + +} diff --git a/Testing/Code/TestSystem/otbTestSystemTests.cxx b/Testing/Code/TestSystem/otbTestSystemTests.cxx index a3c3c06d022f8e8d7517a857c69a9edd5a190553..af852e91c7aba1fdf8ef52617ea07fa2f5b7702d 100644 --- a/Testing/Code/TestSystem/otbTestSystemTests.cxx +++ b/Testing/Code/TestSystem/otbTestSystemTests.cxx @@ -26,6 +26,7 @@ void RegisterTests() { + REGISTER_TEST(otbIsNightlyRevision); REGISTER_TEST(otbCompareAsciiTests); REGISTER_TEST(otbCompareAsciiTests2); REGISTER_TEST(otbCompareAsciiTests3); diff --git a/Utilities/ITK/Code/IO/itkConvertPixelBuffer.txx b/Utilities/ITK/Code/IO/itkConvertPixelBuffer.txx index baeaa0fa540b6aa1cf366e01af394c687ecc8716..76e61893434a786cd5d047a5f4ee05a8729aefb0 100644 --- a/Utilities/ITK/Code/IO/itkConvertPixelBuffer.txx +++ b/Utilities/ITK/Code/IO/itkConvertPixelBuffer.txx @@ -744,7 +744,6 @@ ConvertPixelBuffer<InputPixelType, OutputPixelType, OutputConvertTraits> OutputPixelType* outputData , size_t size) { size_t length = size* (size_t)inputNumberOfComponents; - OutputPixelType dummy; for( size_t i=0; i< length/2; i++ ) { OutputConvertTraits::SetNthComponent( 0, *outputData, (*inputData).real());