Commit 39d4a6d8 authored by Julien Malik's avatar Julien Malik

MRG

parents 6767df02 1a73b07c
......@@ -2,6 +2,7 @@ syntax: glob
*~
.*.swp
*.orig
*.pyc
.\#*
\#*\#
include(WrapperMacros)
#OTB_CREATE_APPLICATION(NAME VectorImageFactory SOURCES VectorImageFactory.cxx)
OTB_CREATE_APPLICATION(NAME Addition SOURCES otbAddition.cxx)
OTB_CREATE_APPLICATION(NAME Smoothing SOURCES otbSmoothing.cxx LINK_LIBRARIES OTBIO;OTBCommon;OTBBasicFilters)
OTB_CREATE_APPLICATION(NAME Rescale SOURCES otbRescale.cxx LINK_LIBRARIES OTBIO;OTBCommon;OTBBasicFilters)
OTB_CREATE_APPLICATION(NAME AllocateOutput SOURCES otbAllocateOutput.cxx LINK_LIBRARIES OTBIO;OTBCommon;OTBBasicFilters)
OTB_CREATE_APPLICATION(NAME CopyInput SOURCES otbCopyInput.cxx LINK_LIBRARIES OTBIO;OTBCommon;OTBBasicFilters)
OTB_CREATE_APPLICATION(NAME InternalReader SOURCES otbInternalReader.cxx LINK_LIBRARIES OTBIO;OTBCommon;OTBBasicFilters)
OTB_CREATE_APPLICATION(NAME TestApplication SOURCES otbTestApplication.cxx LINK_LIBRARIES OTBIO;OTBCommon;OTBBasicFilters)
OTB_CREATE_APPLICATION(NAME HyperspectralUnmixing SOURCES otbHyperspectralUnmixing.cxx LINK_LIBRARIES OTBIO;OTBCommon;OTBBasicFilters)
OTB_CREATE_APPLICATION(NAME ExtractROI SOURCES otbExtractROI.cxx LINK_LIBRARIES OTBIO;OTBCommon;OTBBasicFilters)
/*=========================================================================
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 "itkObjectFactory.h"
#include "itkVersion.h"
#include "otbWrapperTypes.h"
//template <class TPixel, unsigned int VImageDimension = 2>
class ITK_EXPORT MyVectorImage : public otb::VectorImage<float, 2>
{
public:
/** Standard class typedefs. */
typedef MyVectorImage Self;
// typedef otb::VectorImage<TPixel, VImageDimension> Superclass;
typedef otb::VectorImage<float, 2> Superclass;
typedef itk::SmartPointer<Self> Pointer;
typedef itk::SmartPointer<const Self> ConstPointer;
typedef itk::WeakPointer<const Self> ConstWeakPointer;
/** Method for creation through the object factory. */
itkNewMacro(Self);
/** Run-time type information (and related methods). */
itkTypeMacro(MyVectorImage, otb::VectorImage);
};
namespace otb
{
namespace Wrapper
{
class ImageFactory : public itk::ObjectFactoryBase
{
public:
/** Standard class typedefs. */
typedef ImageFactory Self;
typedef itk::ObjectFactoryBase Superclass;
typedef itk::SmartPointer<Self> Pointer;
typedef itk::SmartPointer<const Self> ConstPointer;
/** Class methods used to interface with the registered factories. */
virtual const char* GetITKSourceVersion(void) const
{
return ITK_SOURCE_VERSION;
}
virtual const char* GetDescription(void) const
{
return "ImageFactory";
}
/** Method for class instantiation. */
itkFactorylessNewMacro(Self);
/** Run-time type information (and related methods). */
itkTypeMacro(ApplicationFactory, itk::ObjectFactoryBase);
protected:
ImageFactory()
{
}
virtual ~ImageFactory()
{
}
/** This method is provided by sub-classes of ObjectFactoryBase.
* It should create the named itk object or return 0 if that object
* is not supported by the factory implementation. */
virtual LightObject::Pointer CreateObject(const char* itkclassname )
{
std::cout << "CreateObject Testing " << itkclassname << std::endl;
VectorImageType::Pointer image;
if ( std::string( typeid(VectorImageType).name() ) == itkclassname )
{
std::cout << "HIT" << std::endl;
image = MyVectorImage::New().GetPointer();
}
return image.GetPointer();
}
/** This method creates all the objects with the class overide of
* itkclass name, which are provide by this object
*/
virtual std::list<LightObject::Pointer>
CreateAllObject(const char* itkclassname)
{
std::list<LightObject::Pointer> list;
std::cout << "CreateAllObject Testing " << itkclassname << std::endl;
return list;
}
private:
ImageFactory(const Self &); //purposely not implemented
void operator =(const Self&); //purposely not implemented
};
} // end namespace Wrapper
} //end namespace otb
#if (defined(WIN32) || defined(_WIN32))
# define OTB_APP_EXPORT __declspec(dllexport)
#else
# define OTB_APP_EXPORT
#endif
typedef otb::Wrapper::ImageFactory ImageFactoryType;
static ImageFactoryType::Pointer staticFactory;
extern "C"
{
OTB_APP_EXPORT itk::ObjectFactoryBase* itkLoad()
{
staticFactory = ImageFactoryType::New();
return staticFactory;
}
}
/*=========================================================================
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 "otbWrapperApplication.h"
#include "otbWrapperApplicationFactory.h"
namespace otb
{
namespace Wrapper
{
class Addition : public Application
{
public:
/** Standard class typedefs. */
typedef Addition Self;
typedef Application Superclass;
typedef itk::SmartPointer<Self> Pointer;
typedef itk::SmartPointer<const Self> ConstPointer;
/** Standard macro */
itkNewMacro(Self);
itkTypeMacro(Addition, otb::Application);
private:
Addition()
{
SetName("Addition");
SetDescription("This is a simple application which adds two numbers and print the sum on standard output");
}
virtual ~Addition()
{
}
void DoCreateParameters()
{
std::cout << "Addition::DoCreateParameters" << std::endl;
AddParameter(ParameterType_Float, "a", "First number");
AddParameter(ParameterType_Float, "b", "Second number");
}
void DoUpdateParameters()
{
std::cout << "Addition::DoUpdateParameters" << std::endl;
}
void DoExecute()
{
std::cout << "Addition::DoExecute" << std::endl;
GetLogger()->Debug("debug message");
GetLogger()->Error("error message");
std::cout << GetParameterFloat("a") + GetParameterFloat("b") << std::endl;
}
};
}
}
OTB_APPLICATION_EXPORT(otb::Wrapper::Addition)
/*=========================================================================
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 "otbWrapperApplication.h"
#include "otbWrapperApplicationFactory.h"
namespace otb
{
namespace Wrapper
{
class AllocateOutput : public Application
{
public:
/** Standard class typedefs. */
typedef AllocateOutput Self;
typedef Application Superclass;
typedef itk::SmartPointer<Self> Pointer;
typedef itk::SmartPointer<const Self> ConstPointer;
/** Standard macro */
itkNewMacro(Self);
itkTypeMacro(AllocateOutput, otb::Application);
private:
AllocateOutput()
{
SetName("AllocateOutput");
m_Image = VectorImageType::New();
SetDescription("Allocate output image inside the process.");
}
virtual ~AllocateOutput()
{
}
void DoCreateParameters()
{
AddParameter(ParameterType_OutputImage, "out", "Output Image");
}
void DoUpdateParameters()
{
// Nothing to do here : all parameters are independent
}
void DoExecute()
{
VectorImageType::Pointer inImage = VectorImageType::New();
VectorImageType::IndexType start;
start[0] = 0; // first index on X
start[1] = 0; // first index on Y
VectorImageType::SizeType size;
size[0] = 10; // size along X
size[1] = 10;
VectorImageType::RegionType region;
region.SetSize(size);
region.SetIndex(start);
m_Image->SetRegions(region);
m_Image->SetNumberOfComponentsPerPixel( 3 );
m_Image->Allocate();
VectorImageType::PixelType initialValue;
initialValue.SetSize(3);
initialValue.Fill(0);
m_Image->FillBuffer(initialValue);
SetParameterOutputImage("out", m_Image);
}
VectorImageType::Pointer m_Image;
};
}
}
OTB_APPLICATION_EXPORT(otb::Wrapper::AllocateOutput)
/*=========================================================================
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 "otbWrapperApplication.h"
#include "otbWrapperApplicationFactory.h"
#include "itkCastImageFilter.h"
namespace otb
{
namespace Wrapper
{
class CopyInput : public Application
{
public:
/** Standard class typedefs. */
typedef CopyInput Self;
typedef Application Superclass;
typedef itk::SmartPointer<Self> Pointer;
typedef itk::SmartPointer<const Self> ConstPointer;
/** Standard macro */
itkNewMacro(Self);
itkTypeMacro(CopyInput, otb::Application);
private:
CopyInput()
{
SetName("CopyInput");
SetDescription("Copy the input image into output.");
}
virtual ~CopyInput()
{
}
void DoCreateParameters()
{
AddParameter(ParameterType_InputImage, "in", "Input Image");
AddParameter(ParameterType_OutputImage, "out", "Output Image");
}
void DoUpdateParameters()
{
// Nothing to do here : all parameters are independent
}
void DoExecute()
{
std::cout << "CopyInput 1" << std::endl;
VectorImageType::Pointer inImage = GetParameterImage("in");
typedef itk::CastImageFilter<VectorImageType, VectorImageType> CastImageFilterType;
CastImageFilterType::Pointer caster = CastImageFilterType::New();
m_FilterRef = caster;
std::cout << "CopyInput 2" << std::endl;
caster->SetInPlace(true);
caster->SetInput(inImage);
std::cout << "CopyInput 3" << std::endl;
caster->UpdateOutputInformation();
std::cout << "CopyInput 4" << std::endl;
SetParameterOutputImage("out", caster->GetOutput());
std::cout << "CopyInput 5" << std::endl;
}
itk::LightObject::Pointer m_FilterRef;
};
}
}
OTB_APPLICATION_EXPORT(otb::Wrapper::CopyInput)
/*=========================================================================
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 "otbWrapperApplication.h"
#include "otbWrapperApplicationFactory.h"
#include "otbMultiChannelExtractROI.h"
#include "otbStandardFilterWatcher.h"
#include "otbWrapperNumericalParameter.h"
#include "otbWrapperTypes.h"
namespace otb
{
namespace Wrapper
{
class ExtractROI : public Application
{
public:
/** Standard class typedefs. */
typedef ExtractROI Self;
typedef Application Superclass;
typedef itk::SmartPointer<Self> Pointer;
typedef itk::SmartPointer<const Self> ConstPointer;
/** Standard macro */
itkNewMacro(Self);
itkTypeMacro(ExtractROI, otb::Application);
/** Filters typedef */
typedef otb::MultiChannelExtractROI<VectorImageType::InternalPixelType,
VectorImageType::InternalPixelType> ExtractROIFilterType;
private:
ExtractROI()
{
SetName("ExtractROI");
SetDescription("Extract a ROI defined by the user.");
m_ExtractROIFilter = ExtractROIFilterType::New();
}
virtual ~ExtractROI()
{
}
void DoCreateParameters()
{
AddParameter(ParameterType_InputImage, "in", "Input Image");
AddParameter(ParameterType_OutputImage, "out", "Output Image");
AddParameter(ParameterType_Int, "startx", "Start X");
AddParameter(ParameterType_Int, "starty", "Start Y");
AddParameter(ParameterType_Int, "sizex", "Size X");
AddParameter(ParameterType_Int, "sizey", "Size Y");
// Default values
SetParameterInt("startx", 0);
SetParameterInt("starty", 0);
SetParameterInt("sizex", 0);
SetParameterInt("sizey", 0);
// Output pixel type choices
AddParameter(ParameterType_Choice, "t", "Output Pixel Type");
AddChoice("t.double", "double");
AddChoice("t.uchar", "unsigned Char");
AddChoice("t.shortint", "short int");
AddChoice("t.int", "int");
AddChoice("t.float", "float");
AddChoice("t.uishort", "unsigned short int");
AddChoice("t.uint", "unsigned int");
// Channelist Parameters
}
void DoUpdateParameters()
{
// Update the sizes only if the user does not defined a size
if ( HasValue("in") )
{
ExtractROIFilterType::InputImageType* inImage = GetParameterImage("in");
ExtractROIFilterType::InputImageType::RegionType largestRegion = inImage->GetLargestPossibleRegion();
if (!HasUserValue("sizex") && !HasUserValue("sizey") )
{
SetParameterInt("sizex", largestRegion.GetSize()[0]);
SetParameterInt("sizey", largestRegion.GetSize()[1]);
}
// Put the limit of the index and the size relative the image
dynamic_cast< NumericalParameter<int> * >(GetParameterByKey("sizex"))->SetMinimumValue(0);
dynamic_cast< NumericalParameter<int> * >(GetParameterByKey("sizex"))->SetMaximumValue(largestRegion.GetSize(0));
dynamic_cast< NumericalParameter<int> * >(GetParameterByKey("sizey"))->SetMinimumValue(0);
dynamic_cast< NumericalParameter<int> * >(GetParameterByKey("sizey"))->SetMaximumValue(largestRegion.GetSize(1));
dynamic_cast< NumericalParameter<int> * >(GetParameterByKey("startx"))->SetMinimumValue(0);
dynamic_cast< NumericalParameter<int> * >(GetParameterByKey("startx"))->SetMaximumValue(largestRegion.GetSize(0));
dynamic_cast< NumericalParameter<int> * >(GetParameterByKey("starty"))->SetMinimumValue(0);
dynamic_cast< NumericalParameter<int> * >(GetParameterByKey("starty"))->SetMaximumValue(largestRegion.GetSize(1));
// Update the channel list
}
// Crop the roi region to be included in the largest possible
// region
if(!this->CropRegionOfInterest())
{
// Put the index of the ROI to origin and try to crop again
SetParameterInt("startx", 0);
SetParameterInt("starty", 0);
this->CropRegionOfInterest();
}
}
bool CropRegionOfInterest()
{
VectorImageType::RegionType region;
region.SetSize(0, GetParameterInt("sizex"));
region.SetSize(1, GetParameterInt("sizey"));
region.SetIndex(0, GetParameterInt("startx"));
region.SetIndex(1, GetParameterInt("starty"));
if (region.Crop(GetParameterImage("in")->GetLargestPossibleRegion()))
{
SetParameterInt("sizex", region.GetSize(0));
SetParameterInt("sizey", region.GetSize(1));
SetParameterInt("startx", region.GetIndex(0));
SetParameterInt("starty", region.GetIndex(1));
return true;
}
return false;
}
void DoExecute()
{
typename ExtractROIFilterType::InputImageType* inImage = GetParameterImage("in");
m_ExtractROIFilter->SetInput(inImage);
m_ExtractROIFilter->SetStartX(GetParameterInt("startx"));
m_ExtractROIFilter->SetStartY(GetParameterInt("starty"));
m_ExtractROIFilter->SetSizeX(GetParameterInt("sizey"));
m_ExtractROIFilter->SetSizeY(GetParameterInt("sizey"));
m_ExtractROIFilter->UpdateOutputInformation();
SetParameterOutputImage("out", m_ExtractROIFilter->GetOutput());
}
ExtractROIFilterType::Pointer m_ExtractROIFilter;
};
}
}
OTB_APPLICATION_EXPORT(otb::Wrapper::ExtractROI)
This diff is collapsed.
/*=========================================================================
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 "otbWrapperApplication.h"
#include "otbWrapperApplicationFactory.h"
#include "otbImageFileReader.h"
namespace otb
{
namespace Wrapper
{
class InternalReader : public Application
{
public:
/** Standard class typedefs. */
typedef InternalReader Self;
typedef Application Superclass;
typedef itk::SmartPointer<Self> Pointer;
typedef itk::SmartPointer<const Self> ConstPointer;
/** Standard macro */
itkNewMacro(Self);
itkTypeMacro(InternalReader, otb::Application);
/** Filters typedef */
typedef otb::ImageFileReader<VectorImageType> ReaderFilterType;