Commit b774e579 authored by Rashad Kanavath's avatar Rashad Kanavath

Merge remote-tracking branch 'origin/develop' into update_pkg

parents e1bddcb2 81cb2d8b
......@@ -41,9 +41,11 @@ if(Shark_DIR)
endif() #if(Shark_DIR)
find_path( SHARK_INCLUDE_DIR shark/Core/Shark.h
find_path( SHARK_INCLUDE_DIR
NAMES shark/Core/Shark.h
PATHS "${SHARK_SEARCH_PATH}"
PATH_SUFFIXES include include/shark shark)
PATH_SUFFIXES include include/shark shark
)
find_library( SHARK_LIBRARY
NAMES shark shark_debug
......@@ -51,22 +53,37 @@ find_library( SHARK_LIBRARY
PATH_SUFFIXES lib
)
mark_as_advanced( SHARK_INCLUDE_DIR
SHARK_LIBRARY )
find_package(
Boost 1.48.0 REQUIRED QUIET COMPONENTS
mark_as_advanced( SHARK_INCLUDE_DIR SHARK_LIBRARY )
find_package( Boost 1.48.0 REQUIRED QUIET COMPONENTS
system date_time filesystem
program_options serialization thread
unit_test_framework
)
)
if(NOT Boost_FOUND)
message(FATAL_ERROR "Please make sure Boost 1.48.0 is installed on your system")
endif()
if(NOT SHARK_LIBRARY)
message(FATAL_ERROR "Cannot find SHARK_LIBRARY. set it with cmake -DSHARK_LIBRARY=")
return()
endif()
if(NOT SHARK_INCLUDE_DIR)
message(FATAL_ERROR "Cannot find SHARK_INCLUDE_DIR. Set it with cmake -DSHARK_INCLUDE_DIR=")
return()
endif()
get_filename_component(SHARK_INSTALLDIR ${SHARK_LIBRARY} PATH)
get_filename_component(SHARK_INSTALLDIR ${SHARK_INSTALLDIR} PATH)
if(NOT SHARK_CONFIG_FILE)
find_file(SHARK_CONFIG_FILE SharkConfig.cmake PATH_SUFFIXES lib/cmake/Shark share/Shark)
find_file(SHARK_CONFIG_FILE SharkConfig.cmake
PATHS ${SHARK_INSTALLDIR}
PATH_SUFFIXES lib/cmake/Shark share/Shark cmake/Shark)
endif()
if(SHARK_CONFIG_FILE)
file(STRINGS "${SHARK_CONFIG_FILE}" SHARK_CONFIG_FILE_CONTENTS)
string(REGEX REPLACE
......@@ -81,13 +98,42 @@ if(SHARK_CONFIG_FILE)
set(SHARK_VERSION_STRING
"${SHARK_VERSION_MAJOR}.${SHARK_VERSION_MINOR}.${SHARK_VERSION_PATCH}")
endif()
set(SHARK_USE_OPENMP_matched)
#define SHARK_USE_OPENMP
file(STRINGS "${SHARK_INCLUDE_DIR}/shark/Core/Shark.h" SHARK_H_CONTENTS)
string(REGEX MATCH
"#define.SHARK_USE_OPENMP"
SHARK_USE_OPENMP_matched "${SHARK_H_CONTENTS}")
#this variable is added in cache but not used now
# you can use it to see if shark installation has openMP
# later if needed in other places..
set(SHARK_USE_OPENMP FALSE CACHE BOOL "shark is built with OpenMP")
if(SHARK_USE_OPENMP_matched)
set(SHARK_USE_OPENMP TRUE CACHE BOOL "shark is built with OpenMP" FORCE)
endif()
if(SHARK_USE_OPENMP)
message(STATUS "Shark is built with OpenMP: SHARK_USE_OPENMP = TRUE")
find_package(OpenMP REQUIRED QUIET)
if(OPENMP_FOUND)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${OpenMP_C_FLAGS}")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${OpenMP_CXX_FLAGS}")
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} ${OpenMP_EXE_LINKER_FLAGS}")
else()
message(FATAL_ERROR "Your shark libraries are compiled with it OpenMP")
set(SHARK_FOUND FALSE)
endif()
else()
message(STATUS "Shark is built without OpenMP: SHARK_USE_OPENMP = FALSE")
endif()
INCLUDE(${CMAKE_ROOT}/Modules/FindPackageHandleStandardArgs.cmake)
FIND_PACKAGE_HANDLE_STANDARD_ARGS(Shark
REQUIRED_VARS SHARK_LIBRARY SHARK_INCLUDE_DIR
VERSION_VAR SHARK_VERSION_STRING)
REQUIRED_VARS SHARK_LIBRARY SHARK_INCLUDE_DIR
VERSION_VAR SHARK_VERSION_STRING)
if(SHARK_FOUND)
set(SHARK_INCLUDE_DIRS ${SHARK_INCLUDE_DIR} ${Boost_INCLUDE_DIR} )
set(SHARK_LIBRARIES ${SHARK_LIBRARY} ${Boost_LIBRARIES} )
......
......@@ -37,9 +37,23 @@ namespace Wrapper
SetParameterDescription("classifier.libsvm", "This group of parameters allows setting SVM classifier parameters.");
AddParameter(ParameterType_Choice, "classifier.libsvm.k", "SVM Kernel Type");
AddChoice("classifier.libsvm.k.linear", "Linear");
SetParameterDescription("classifier.libsvm.k.linear",
"Linear Kernel, no mapping is done, this is the fastest option.");
AddChoice("classifier.libsvm.k.rbf", "Gaussian radial basis function");
SetParameterDescription("classifier.libsvm.k.rbf",
"This kernel is a good choice in most of the case. It is "
"an exponential function of the euclidian distance between "
"the vectors.");
AddChoice("classifier.libsvm.k.poly", "Polynomial");
SetParameterDescription("classifier.libsvm.k.poly",
"Polynomial Kernel, the mapping is a polynomial function.");
AddChoice("classifier.libsvm.k.sigmoid", "Sigmoid");
SetParameterDescription("classifier.libsvm.k.sigmoid",
"The kernel is a hyperbolic tangente function of the vectors.");
SetParameterString("classifier.libsvm.k", "linear", false);
SetParameterDescription("classifier.libsvm.k", "SVM Kernel Type.");
AddParameter(ParameterType_Choice, "classifier.libsvm.m", "SVM Model Type");
......@@ -47,21 +61,50 @@ namespace Wrapper
if (this->m_RegressionFlag)
{
AddChoice("classifier.libsvm.m.epssvr", "Epsilon Support Vector Regression");
SetParameterDescription("classifier.libsvm.m.epssvr",
"The distance between feature vectors from the training set and the "
"fitting hyper-plane must be less than Epsilon. For outliers the penalty "
"multiplier C is used ");
AddChoice("classifier.libsvm.m.nusvr", "Nu Support Vector Regression");
SetParameterString("classifier.libsvm.m", "epssvr", false);
SetParameterDescription("classifier.libsvm.m.nusvr",
"Same as the epsilon regression except that this time the bounded "
"parameter nu is used instead of epsilon");
}
else
{
AddChoice("classifier.libsvm.m.csvc", "C support vector classification");
SetParameterDescription("classifier.libsvm.m.csvc",
"This formulation allows imperfect separation of classes. The penalty "
"is set through the cost parameter C.");
AddChoice("classifier.libsvm.m.nusvc", "Nu support vector classification");
SetParameterDescription("classifier.libsvm.m.nusvc",
"This formulation allows imperfect separation of classes. The penalty "
"is set through the cost parameter Nu. As compared to C, Nu is harder "
"to optimize, and may not be as fast.");
AddChoice("classifier.libsvm.m.oneclass", "Distribution estimation (One Class SVM)");
SetParameterDescription("classifier.libsvm.m.oneclass",
"All the training data are from the same class, SVM builds a boundary "
"that separates the class from the rest of the feature space.");
SetParameterString("classifier.libsvm.m", "csvc", false);
}
AddParameter(ParameterType_Float, "classifier.libsvm.c", "Cost parameter C");
SetParameterFloat("classifier.libsvm.c",1.0, false);
SetParameterDescription(
"classifier.libsvm.c",
"SVM models have a cost parameter C (1 by default) to control the trade-off between training errors and forcing rigid margins.");
SetParameterDescription("classifier.libsvm.c",
"SVM models have a cost parameter C (1 by default) to control the "
"trade-off between training errors and forcing rigid margins.");
AddParameter(ParameterType_Float, "classifier.libsvm.nu", "Cost parameter Nu");
SetParameterFloat("classifier.libsvm.nu",0.5, false);
SetParameterDescription("classifier.libsvm.nu",
"Cost parameter Nu, in the range 0..1, the larger the value, "
"the smoother the decision.");
// It seems that it miss a nu parameter for the nu-SVM use.
AddParameter(ParameterType_Empty, "classifier.libsvm.opt", "Parameters optimization");
MandatoryOff("classifier.libsvm.opt");
SetParameterDescription("classifier.libsvm.opt", "SVM parameters optimization flag.");
......@@ -73,8 +116,15 @@ namespace Wrapper
{
AddParameter(ParameterType_Float, "classifier.libsvm.eps", "Epsilon");
SetParameterFloat("classifier.libsvm.eps",1e-3, false);
AddParameter(ParameterType_Float, "classifier.libsvm.nu", "Nu");
SetParameterFloat("classifier.libsvm.nu",0.5, false);
SetParameterDescription("classifier.libsvm.eps",
"The distance between feature vectors from the training set and "
"the fitting hyper-plane must be less than Epsilon. For outliers"
"the penalty mutliplier is set by C.");
// AddParameter(ParameterType_Float, "classifier.libsvm.nu", "Nu");
// SetParameterFloat("classifier.libsvm.nu",0.5, false);
// SetParameterDescription("classifier.libsvm.nu",
// "Cost parameter Nu, in the range 0..1, the larger the value, "
// "the smoother the decision.");
}
}
......@@ -100,6 +150,7 @@ namespace Wrapper
{
libSVMClassifier->SetDoProbabilityEstimates(true);
}
libSVMClassifier->SetNu(GetParameterFloat("classifier.libsvm.nu"));
libSVMClassifier->SetC(GetParameterFloat("classifier.libsvm.c"));
switch (GetParameterInt("classifier.libsvm.k"))
......@@ -135,7 +186,6 @@ namespace Wrapper
break;
}
libSVMClassifier->SetEpsilon(GetParameterFloat("classifier.libsvm.eps"));
libSVMClassifier->SetNu(GetParameterFloat("classifier.libsvm.nu"));
}
else
{
......@@ -155,6 +205,7 @@ namespace Wrapper
break;
}
}
libSVMClassifier->Train();
libSVMClassifier->Save(modelPath);
......@@ -163,4 +214,4 @@ namespace Wrapper
} //end namespace wrapper
} //end namespace otb
#endif
#endif
\ No newline at end of file
......@@ -64,6 +64,8 @@ public:
typedef std::vector<LinePointType> PointListType;
typedef itk::VectorContainer<unsigned long, PointType> PointContainerType;
typedef itk::SmartPointer<PointContainerType> PointContainerPointer;
typedef itk::SizeValueType SizeValueType;
typedef itk::IdentifierType IdentifierType;
/** Returns a reference to the list of the Line points.*/
PointListType& GetPoints(void);
......@@ -72,19 +74,19 @@ public:
void SetPoints(PointListType& newPoints);
/** Return a point in the list given the index */
const SpatialObjectPointType* GetPoint(unsigned long id) const ITK_OVERRIDE
const SpatialObjectPointType* GetPoint(IdentifierType id) const ITK_OVERRIDE
{
return &(m_Points[id]);
}
/** Return a point in the list given the index */
SpatialObjectPointType* GetPoint(unsigned long id) ITK_OVERRIDE
SpatialObjectPointType* GetPoint(IdentifierType id) ITK_OVERRIDE
{
return &(m_Points[id]);
}
/** Return the number of points in the list */
itk::SizeValueType GetNumberOfPoints(void) const ITK_OVERRIDE
SizeValueType GetNumberOfPoints(void) const ITK_OVERRIDE
{
return m_Points.size();
}
......
......@@ -1578,7 +1578,7 @@ void GDALImageIO::InternalWriteImageInformation(const void* buffer)
if (driverShortName == "NOT-FOUND")
{
itkExceptionMacro(
<< "GDAL Writing failed : the image file name '" << m_FileName.c_str() << "' is not recognized by GDAL.");
<< "GDAL Writing failed: the image file name '" << m_FileName.c_str() << "' is not recognized by GDAL.");
}
if (m_CanStreamWrite)
......@@ -1664,9 +1664,7 @@ void GDALImageIO::InternalWriteImageInformation(const void* buffer)
if (m_Dataset.IsNull())
{
itkExceptionMacro(
<< "GDAL Writing failed : Impossible to create the image file name '"
<< m_FileName << "' : " << CPLGetLastErrorMsg() );
itkExceptionMacro(<< CPLGetLastErrorMsg());
}
/*----------------------------------------------------------------------*/
......
......@@ -54,19 +54,14 @@ public:
/** Constructor. */
ImageFileReaderException(const char *file, unsigned int line,
const char* message = "Error in IO",
const char* loc = "Unknown") :
ExceptionObject(file, line, message, loc)
const std::string& desc = "",
const std::string& filename = "") :
ExceptionObject(file, line, desc),
m_Filename(filename)
{
}
/** Constructor. */
ImageFileReaderException(const std::string &file, unsigned int line,
const char* message = "Error in IO",
const char* loc = "Unknown") :
ExceptionObject(file, line, message, loc)
{
}
std::string m_Filename;
};
/** \class ImageFileReader
......@@ -170,12 +165,10 @@ protected:
void DoConvertBuffer(void* buffer, size_t numberOfPixels);
private:
/** Test whether the given filename exist and it is readable,
this is intended to be called before attempting to use
ImageIO classes for actually reading the file. If the file
doesn't exist or it is not readable, and exception with an
appropriate message will be thrown. */
void TestFileExistenceAndReadability();
/** Test whether m_ImageIO is valid (not NULL). This is intended to be called
* after trying to create it via an ImageIOFactory. Throws an exception with
* an appropriate message otherwise. */
void TestValidImageIO();
/** Generate the filename (for GDALImageI for example). If filename is a directory, look if is a
* CEOS product (file "DAT...") In this case, the GdalFileName contain the open image file.
......@@ -196,8 +189,6 @@ private:
bool m_UseStreaming;
std::string m_ExceptionMessage;
// The region that the ImageIO class will return when we ask to
// produce the requested region.
itk::ImageIORegion m_ActualIORegion;
......
......@@ -65,7 +65,6 @@ ImageFileReader<TOutputImage, ConvertPixelTraits>
m_UserSpecifiedImageIO(false),
m_FileName(""),
m_UseStreaming(true),
m_ExceptionMessage(""),
m_ActualIORegion(),
m_FilenameHelper(FNameHelperType::New()),
m_AdditionalNumber(0),
......@@ -129,9 +128,9 @@ ImageFileReader<TOutputImage, ConvertPixelTraits>
output->SetBufferedRegion(output->GetRequestedRegion());
output->Allocate();
// Test if the file exist and if it can be open.
// An exception will be thrown otherwise.
this->TestFileExistenceAndReadability();
// Raise an exception if the file could not be opened
// i.e. if this->m_ImageIO is Null
this->TestValidImageIO();
// Tell the ImageIO to read the file
OutputImagePixelType *buffer =
......@@ -242,8 +241,7 @@ ImageFileReader<TOutputImage, ConvertPixelTraits>
}
else
{
throw otb::ImageFileReaderException(__FILE__, __LINE__,
"Invalid output object type");
throw otb::ImageFileReaderException(__FILE__, __LINE__, "Invalid output object type");
}
}
}
......@@ -253,74 +251,32 @@ void
ImageFileReader<TOutputImage, ConvertPixelTraits>
::GenerateOutputInformation(void)
{
typename TOutputImage::Pointer output = this->GetOutput();
itkDebugMacro(<< "Reading file for GenerateOutputInformation()" << this->m_FileName);
// Check to see if we can read the file given the name or prefix
//
if (this->m_FileName == "")
{
throw otb::ImageFileReaderException(__FILE__, __LINE__, "FileName must be specified");
}
{
throw otb::ImageFileReaderException(__FILE__, __LINE__, "Filename must be specified.");
}
// Find real image file name
// !!!! Update FileName
std::string lFileName;
bool found = GetGdalReadImageFileName(this->m_FileName, lFileName);
if (found == false)
{
otbMsgDebugMacro(<< "Filename was NOT unknown. May be recognized by a Image factory ! ");
}
// Update FileName
this->m_FileName = lFileName;
// Test if the file exists and if it can be opened.
// An exception will be thrown otherwise.
// We catch the exception because some ImageIO's may not actually
// open a file. Still reports file error if no ImageIO is loaded.
try
{
m_ExceptionMessage = "";
this->TestFileExistenceAndReadability();
}
catch (itk::ExceptionObject & err)
{
m_ExceptionMessage = err.GetDescription();
}
bool found = GetGdalReadImageFileName(this->m_FileName, lFileName);
if (found)
{
// Update FileName
this->m_FileName = lFileName;
}
if (this->m_UserSpecifiedImageIO == false) //try creating via factory
{
{
this->m_ImageIO = ImageIOFactory::CreateImageIO(this->m_FileName.c_str(), otb::ImageIOFactory::ReadMode);
}
if (this->m_ImageIO.IsNull())
{
//this->Print(std::cerr);
otb::ImageFileReaderException e(__FILE__, __LINE__);
std::ostringstream msg;
msg << " Could not create IO object for file "
<< this->m_FileName.c_str() << std::endl;
msg << " Tried to create one of the following:" << std::endl;
std::list<itk::LightObject::Pointer> allobjects =
itk::ObjectFactoryBase::CreateAllInstance("otbImageIOBase");
for (std::list<itk::LightObject::Pointer>::iterator i = allobjects.begin();
i != allobjects.end(); ++i)
{
otb::ImageIOBase* io = dynamic_cast<otb::ImageIOBase*>(i->GetPointer());
// IO should never be null, but we would better check for it
if(io)
msg << " " << io->GetNameOfClass() << std::endl;
}
msg << " You probably failed to set a file suffix, or" << std::endl;
msg << " set the suffix to an unsupported type." << std::endl;
e.SetDescription(msg.str().c_str());
throw e;
return;
}
}
// Raise an exception if the file could not be opened
// i.e. if this->m_ImageIO is Null
this->TestValidImageIO();
// Get the ImageIO MetaData Dictionary
itk::MetaDataDictionary& dict = this->m_ImageIO->GetMetaDataDictionary();
......@@ -331,7 +287,7 @@ ImageFileReader<TOutputImage, ConvertPixelTraits>
bool lVectorImage = false;
if (strcmp(output->GetNameOfClass(), "VectorImage") == 0)
lVectorImage= true;
this->m_ImageIO->SetOutputImagePixelType(PixelIsComplex(dummy),lVectorImage);
// Pass the dataset number (used for hdf files for example)
......@@ -435,9 +391,9 @@ ImageFileReader<TOutputImage, ConvertPixelTraits>
if(!m_KeywordListUpToDate && !m_FilenameHelper->GetSkipGeom())
{
std::string lFileNameOssimKeywordlist = GetDerivedDatasetSourceFileName(m_FileName);
// Update otb Keywordlist
ImageKeywordlist otb_kwl;
if (!m_FilenameHelper->ExtGEOMFileNameIsSet())
......@@ -450,7 +406,7 @@ ImageFileReader<TOutputImage, ConvertPixelTraits>
otb_kwl = ReadGeometryFromGEOMFile(m_FilenameHelper->GetExtGEOMFileName());
otbMsgDevMacro(<< "Loading external kwl");
}
// Don't add an empty ossim keyword list
if(!otb_kwl.Empty())
{
......@@ -511,7 +467,7 @@ ImageFileReader<TOutputImage, ConvertPixelTraits>
}
// If Skip ProjectionRef is activated, remove ProjRef from dict
if (m_FilenameHelper->GetSkipCarto())
{
......@@ -576,9 +532,9 @@ std::string
ImageFileReader<TOutputImage, ConvertPixelTraits>
::GetDerivedDatasetSourceFileName(const std::string & filename) const
{
const size_t dsds_pos = filename.find(DerivedSubdatasetPrefix);
if(dsds_pos != std::string::npos)
{
// Derived subdataset from gdal
......@@ -595,50 +551,22 @@ ImageFileReader<TOutputImage, ConvertPixelTraits>
template <class TOutputImage, class ConvertPixelTraits>
void
ImageFileReader<TOutputImage, ConvertPixelTraits>
::TestFileExistenceAndReadability()
::TestValidImageIO()
{
// Test if the file a server name : if so the test is skipped
if (this->m_FileName.find(std::string("http://")) == 0 ||
this->m_FileName.find(std::string("https://")) == 0)
{
return;
}
if (this->m_ImageIO.IsNull())
{
std::string fileToCheck = GetDerivedDatasetSourceFileName(m_FileName);
std::string fileToCheck = GetDerivedDatasetSourceFileName(m_FileName);
// Test if the file exists.
if (!itksys::SystemTools::FileExists(fileToCheck.c_str()))
// Test if the file exists.
if (!itksys::SystemTools::FileExists(fileToCheck.c_str()))
{
otb::ImageFileReaderException e(__FILE__, __LINE__);
std::ostringstream msg;
msg << "The file doesn't exist. "
<< std::endl << "Filename = " << fileToCheck
<< std::endl;
e.SetDescription(msg.str().c_str());
throw e;
return;
throw otb::ImageFileReaderException (__FILE__, __LINE__, "The file does not exist.", fileToCheck);
}
// Test if the file can be open for reading access.
//Only if m_FileName specify a filename (not a dirname)
if (itksys::SystemTools::FileExists(fileToCheck.c_str(), true))
else
{
std::ifstream readTester;
readTester.open(fileToCheck.c_str());
if (readTester.fail())
{
readTester.close();
std::ostringstream msg;
msg << "The file couldn't be opened for reading. "
<< std::endl << "Filename: " << fileToCheck
<< std::endl;
otb::ImageFileReaderException e(__FILE__, __LINE__, msg.str().c_str(), ITK_LOCATION);
throw e;
return;
}
readTester.close();
throw otb::ImageFileReaderException(__FILE__, __LINE__, "Probably unsupported format or incorrect filename extension.", this->m_FileName);
}
}
}
template <class TOutputImage, class ConvertPixelTraits>
......@@ -695,7 +623,7 @@ ImageFileReader<TOutputImage, ConvertPixelTraits>
}
fic_trouve = true;
}
otbMsgDevMacro(<< "lFileNameGdal : " << GdalFileName.c_str());
otbMsgDevMacro(<< "fic_trouve : " << fic_trouve);
return (fic_trouve);
......@@ -716,12 +644,12 @@ ImageFileReader<TOutputImage, ConvertPixelTraits>
{
const std::string skip_geom_key = "skipgeom";
const std::string geom_key = "geom";
if (in)
{
// First, see if the simple filename has changed
typename FNameHelperType::Pointer helper = FNameHelperType::New();
helper->SetExtendedFileName(in);
std::string simpleFileName = helper->GetSimpleFileName();
......@@ -735,7 +663,7 @@ ImageFileReader<TOutputImage, ConvertPixelTraits>
if(oldMap.size() != newMap.size() || !std::equal(oldMap.begin(),oldMap.end(),newMap.begin()))
{
this->Modified();
// Now check if keywordlist needs to be generated again
// Condition is: one of the old or new map has the skip_geom
// key and the other does not
......@@ -759,7 +687,7 @@ ImageFileReader<TOutputImage, ConvertPixelTraits>
m_KeywordListUpToDate = false;
this->Modified();
}
m_FilenameHelper = helper;
}
}
......@@ -781,15 +709,15 @@ ImageFileReader<TOutputImage, ConvertPixelTraits>
return this->m_ImageIO->GetOverviewsCount();
}
template <class TOutputImage, class ConvertPixelTraits>
std::vector<std::string>
ImageFileReader<TOutputImage, ConvertPixelTraits>
::GetOverviewsInfo()
{
this->UpdateOutputInformation();
return this->m_ImageIO->GetOverviewsInfo();
}
......
......@@ -448,20 +448,7 @@ ImageFileWriter<TInputImage>
{
itk::ImageFileWriterException e(__FILE__, __LINE__);
std::ostringstream msg;
msg << " Could not create IO object for file "
<< m_FileName.c_str() << std::endl;
msg << " Tried to create one of the following:" << std::endl;
std::list<itk::LightObject::Pointer> allobjects =
itk::ObjectFactoryBase::CreateAllInstance("otbImageIOBase");
for (std::list<itk::LightObject::Pointer>::iterator i = allobjects.begin();
i != allobjects.end(); ++i)
{
otb::ImageIOBase* io = dynamic_cast<otb::ImageIOBase*>(i->GetPointer());
if(io)
msg << " " << io->GetNameOfClass() << std::endl;
}
msg << " You probably failed to set a file suffix, or" << std::endl;
msg << " set the suffix to an unsupported type." << std::endl;
msg << "Cannot write image " << m_FileName.c_str() << ". Probably unsupported format or incorrect filename extension.";
e.SetDescription(msg.str().c_str());
e.SetLocation(ITK_LOCATION);
throw e;
......
......@@ -48,38 +48,35 @@ ImageIOFactory::CreateImageIO(const char* path, FileModeType mode)
itk::ObjectFactoryBase::CreateAllInstance("otbImageIOBase");
for(std::list<itk::LightObject::Pointer>::iterator i = allobjects.begin();
i != allobjects.end(); ++i)
{
{
otb::ImageIOBase* io = dynamic_cast<otb::ImageIOBase*>(i->GetPointer());
if(io)
{
{
possibleImageIO.push_back(io);
}
else
{
std::cerr << "Error ImageIO factory did not return an ImageIOBase: "
<< (*i)->GetNameOfClass()
<< std::endl;
}
}
for(std::list<otb::ImageIOBase::Pointer>::iterator k = possibleImageIO.begin();
k != possibleImageIO.end(); ++k)
else
{
itkGenericExceptionMacro(<< "ImageIO factory did not return an ImageIOBase but a " << (*i)->GetNameOfClass());
}
}
for(std::list<otb::ImageIOBase::Pointer>::iterator k = possibleImageIO.begin(); k != possibleImageIO.end(); ++k)
{
if( mode == ReadMode )
{
{
if((*k)->CanReadFile(path))
{
{
return *k;
}
}
}
else if( mode == WriteMode )
{
{
if((*k)->CanWriteFile(path))
{
{
return *k;
}
}
}
}
return ITK_NULLPTR;
}
......
......@@ -22,8 +22,8 @@
#define otbMachineLearningModel_h
#include "itkObject.h"
#include "itkVariableLengthVector.h"
#include "itkListSample.h"
#include "otbMachineLearningModelTraits.h"
namespace otb
{
......@@ -66,6 +66,7 @@ namespace otb
*
* \ingroup OTBLearningBase
*/
template <class TInputValue, class TTargetValue, class TConfidenceValue = double >
class ITK_EXPORT MachineLearningModel
: public itk::Object
......@@ -81,22 +82,22 @@ public:
/**\name Input related typedefs */
//@{
typedef TInputValue InputValueType;
typedef itk::VariableLengthVector<InputValueType> InputSampleType;
typedef itk::Statistics::ListSample<InputSampleType> InputListSampleType;
typedef typename MLMSampleTraits<TInputValue>::ValueType InputValueType;
typedef typename MLMSampleTraits<TInputValue>::SampleType InputSampleType;
typedef itk::Statistics::ListSample<InputSampleType> InputListSampleType;
//@}
/**\name Target related typedefs */
//@{
typedef TTargetValue TargetValueType;
typedef itk::