Skip to content
Snippets Groups Projects
Commit 637cc1de authored by Cyrille Valladeau's avatar Cyrille Valladeau
Browse files

MRG

parents 2627e27f 33b4e6af
No related branches found
No related tags found
No related merge requests found
Showing
with 712 additions and 557 deletions
......@@ -116,8 +116,8 @@ ConvolutionImageFilter< TInputImage, TOutputImage, TBoundaryCondition>
// support progress methods/callbacks
itk::ProgressReporter progress(this, threadId, outputRegionForThread.GetNumberOfPixels());
InputRealType sum;
InputRealType norm;
InputRealType sum = itk::NumericTraits<InputRealType>::Zero;
InputRealType norm = itk::NumericTraits<InputRealType>::Zero;
// Process each of the boundary faces. These are N-d regions which border
// the edge of the buffer.
......
......@@ -9,11 +9,11 @@
Copyright (c) Centre National d'Etudes Spatiales. All rights reserved.
See OTBCopyright.txt for details.
Copyright (c) Institut Telecom / Telecom Bretagne. All rights reserved.
Copyright (c) Institut Telecom / Telecom Bretagne. All rights reserved.
See ITCopyright.txt for details.
This software is distributed WITHOUT ANY WARRANTY; without even
the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
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.
=========================================================================*/
......@@ -30,17 +30,17 @@ namespace Statistics {
/** \class FlexibleDistanceWithMissingValue
* \brief Non-Euclidean distance function facing missing value.
*
* This class is derived from EuclideanDistanceWithMissingValuePow2 class to
* deal with missing data. In addition, the initial Evaluate method performs
* This class is derived from EuclideanDistanceWithMissingValuePow2 class to
* deal with missing data. In addition, the initial Evaluate method performs
* a flexible calculation of distance when a component does contain data.
*
* The general formlation is defined as:
* The general formulation is defined as:
* \f$
d(x,y) = \sum_i | x_i^a - y_i^a |^b.
d(x,y) = \sum_i | x_i^a - y_i^a |^b.
\f$
*
*
* The class can be templated over any container that holds data elements, as
* for template of EuclideanDistance.
* for template of EuclideanDistance.
*
* The only restriction is that elements have to support '\code{NaN}'.
*
......@@ -54,7 +54,7 @@ class ITK_EXPORT FlexibleDistanceWithMissingValue :
/** Standard "Self" typedef. */
typedef FlexibleDistanceWithMissingValue Self;
typedef otb::Statistics::EuclideanDistanceWithMissingValuePow2< TVector > Superclass;
typedef itk::SmartPointer< Self > Pointer ;
typedef itk::SmartPointer< Self > Pointer ;
typedef itk::SmartPointer<const Self> ConstPointer;
typedef typename Superclass::MeasurementVectorSizeType MeasurementVectorSizeType;
......@@ -75,7 +75,7 @@ class ITK_EXPORT FlexibleDistanceWithMissingValue :
double Evaluate(const TVector &x1, const TVector &x2) const ;
/** Gets the cooridnate distance between a and b. NOTE: a and b
* should be type of component */
* should be type of component */
double Evaluate(const ValueType &a, const ValueType &b) const ;
/** Returns true if the distance between x and the origin is less
......@@ -84,10 +84,10 @@ class ITK_EXPORT FlexibleDistanceWithMissingValue :
return Superclass::IsWithinRange( x, radius ); }
/** Set the value of the parameter a and b.
* Those parameters are defined as static component in order to call it far
* Those parameters are defined as static component in order to call it far
* away from the instanciation of the class (through the SOM training for instance) */
static double Alpha;
static double Beta;
static double Beta;
static void SetAlphaBeta( double a, double b);
/** test if it is ordinary Euclidean distance */
......@@ -95,7 +95,7 @@ class ITK_EXPORT FlexibleDistanceWithMissingValue :
protected:
FlexibleDistanceWithMissingValue() {}
virtual ~FlexibleDistanceWithMissingValue() {}
virtual ~FlexibleDistanceWithMissingValue() {}
}; // end of class
/** Static variable instanciation */
......
......@@ -9,11 +9,11 @@
Copyright (c) Centre National d'Etudes Spatiales. All rights reserved.
See OTBCopyright.txt for details.
Copyright (c) Institut Telecom / Telecom Bretagne. All rights reserved.
Copyright (c) Institut Telecom / Telecom Bretagne. All rights reserved.
See ITCopyright.txt for details.
This software is distributed WITHOUT ANY WARRANTY; without even
the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
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.
=========================================================================*/
......@@ -37,7 +37,7 @@ FlexibleDistanceWithMissingValue< TVector >
if (IsEuclidean())
return Superclass::Evaluate(x1,x2);
if( itk::MeasurementVectorTraits::GetLength( x1 ) !=
if( itk::MeasurementVectorTraits::GetLength( x1 ) !=
itk::MeasurementVectorTraits::GetLength( x2 ) )
{
itkExceptionMacro( << "Vector lengths must be equal." );
......@@ -49,7 +49,7 @@ FlexibleDistanceWithMissingValue< TVector >
{
if ( !IsMissingValue( x1[i] ) && !IsMissingValue( x2[i] ) )
{
temp = pow( fabs( pow(x1[i],this->Alpha) - pow(x2[i],this->Alpha) ), this->Beta );
temp = vcl_pow( vcl_abs( vcl_pow(x1[i],this->Alpha) - vcl_pow(x2[i],this->Alpha) ), this->Beta );
distance += temp ;
}
}
......@@ -65,15 +65,15 @@ FlexibleDistanceWithMissingValue< TVector >
if ( IsEuclidean() )
return Superclass::Evaluate(x);
MeasurementVectorSizeType
MeasurementVectorSizeType
measurementVectorSize = this->GetMeasurementVectorSize();
if(measurementVectorSize == 0)
if(measurementVectorSize == 0)
{
itkExceptionMacro( << "Please set the MeasurementVectorSize first" );
}
itk::MeasurementVectorTraits::Assert( this->m_Origin, measurementVectorSize,
itk::MeasurementVectorTraits::Assert( this->m_Origin, measurementVectorSize,
"EuclideanDistance::Evaluate Origin and input vector have different lengths");
double temp, distance = itk::NumericTraits< double >::Zero ;
......@@ -82,7 +82,7 @@ FlexibleDistanceWithMissingValue< TVector >
{
if ( !IsMissingValue( this->GetOrigin()[i] ) && !IsMissingValue( x[i] ) )
{
temp = pow( fabs( pow(this->GetOrigin()[i],this->Alpha) - pow(x[i],this->Alpha) ), this->Beta) ;
temp = vcl_pow( vcl_abs( vcl_pow(this->GetOrigin()[i],this->Alpha) - vcl_pow(x[i],this->Alpha) ), this->Beta) ;
distance += temp ;
}
}
......@@ -97,12 +97,12 @@ FlexibleDistanceWithMissingValue< TVector >
{
if (IsEuclidean())
return Superclass::Evaluate(a,b);
// FIXME throw NaN exception or not ??
if ( IsMissingValue( a ) || IsMissingValue( b ) )
return 0.0;
double temp = pow(fabs(pow(a,this->Alpha) - pow(b,this->Alpha)), this->Beta) ;
double temp = vcl_pow(vcl_abs(vcl_pow(a,this->Alpha) - vcl_pow(b,this->Alpha)), this->Beta) ;
return temp ;
}
template< class TVector >
......@@ -124,7 +124,7 @@ FlexibleDistanceWithMissingValue< TVector >
return true;
}
else
{
{
return false;
}
}
......
......@@ -100,6 +100,7 @@ protected:
SubsampleImageFilter ()
{
m_SubsampleFactor.Fill( 1 );
//this->SetNumberOfThreads(1);
}
virtual ~SubsampleImageFilter() {}
......
......@@ -140,7 +140,6 @@ void
SubsampleImageFilter< TInputImage, TOutputImage, TDirectionOfTransformation >
::BeforeThreadedGenerateData ()
{
// Fill output image with zeros !
OutputImagePointerType output = this->GetOutput();
output->FillBuffer(0);
}
......@@ -174,9 +173,9 @@ SubsampleImageFilter< TInputImage, TOutputImage, TDirectionOfTransformation >
while ( !inputIter.IsAtEnd() )
{
outputIter.SetLocation(
outputIter.SetOffset(
static_cast< typename SubsampledImageRegionIterator< OutputImageType >::OffsetType >
( inputIter.GetLocationOffset() ) );
( inputIter.GetOffset() ) );
outputIter.Set( static_cast< OutputPixelType >( inputIter.Get() ) );
++inputIter;
}
......@@ -190,13 +189,13 @@ SubsampleImageFilter< TInputImage, TOutputImage, TDirectionOfTransformation >
while ( !inputIter.IsAtEnd() )
{
InputImageIndexType inputIndex = inputIter.GetLocationIndex();
InputImageIndexType inputIndex = inputIter.GetIndex();
OutputImageIndexType outputIndex;
for ( unsigned int i = 0; i < OutputImageDimension; i++ )
{
outputIndex[i] = inputIndex[i] * m_SubsampleFactor[i];
}
outputIter.SetLocation( outputIndex );
outputIter.SetIndex( outputIndex );
outputIter.Set( static_cast< OutputPixelType >( inputIter.Get() ) );
++inputIter;
}
......
......@@ -97,37 +97,11 @@ public:
typedef typename Superclass::IndexValueType IndexValueType;
/** Default constructor. Needed since we provide a cast constructor. */
SubsampledImageRegionConstIterator() : itk::ImageRegionConstIterator<TImage> ()
{
m_SubsampleFactor.Fill(1);
m_SubSampledEndOffset = this->m_EndOffset;
const IndexType& startIndex = this->m_Region.GetIndex();
const SizeType& size = this->m_Region.GetSize();
for ( unsigned int i = 0; i < ImageIteratorDimension; ++i )
{
m_LastUsableIndex[i] = startIndex[i] + static_cast<IndexValueType>( size[i]-1 );
}
}
SubsampledImageRegionConstIterator() ;
/** Constructor establishes an iterator to walk a particular image and a
* particular region of that image. */
SubsampledImageRegionConstIterator ( const ImageType *ptr,
const RegionType &region)
: itk::ImageRegionConstIterator< TImage > ( ptr, region )
{
m_SubsampleFactor.Fill( 1 );
m_SubSampledEndOffset = this->m_EndOffset;
const IndexType& startIndex = this->m_Region.GetIndex();
const SizeType& size = this->m_Region.GetSize();
for ( unsigned int i = 0; i < ImageIteratorDimension; ++i )
{
m_LastUsableIndex[i] = startIndex[i] + static_cast<IndexValueType>( size[i]-1 );
}
}
SubsampledImageRegionConstIterator ( const ImageType *ptr, const RegionType &region);
/** Constructor that can be used to cast from an ImageIterator to an
* SubsampledImageRegionConstIterator. Many routines return an ImageIterator
......@@ -135,20 +109,7 @@ public:
* Rather than provide overloaded APIs that return different types of Iterators, itk
* returns ImageIterators and uses constructors to cast from an
* ImageIterator to a SubsampledImageRegionConstIterator. */
SubsampledImageRegionConstIterator( const itk::ImageIterator<TImage> &it )
: itk::ImageRegionConstIterator< TImage >( it )
{
m_SubsampleFactor.Fill( 1 );
m_SubSampledEndOffset = this->m_EndOffset;
const IndexType& startIndex = this->m_Region.GetIndex();
const SizeType& size = this->m_Region.GetSize();
for ( unsigned int i = 0; i < ImageIteratorDimension; ++i )
{
m_LastUsableIndex[i] = startIndex[i] + static_cast<IndexValueType>( size[i]-1 );
}
}
SubsampledImageRegionConstIterator( const itk::ImageIterator<TImage> &it );
/** Constructor that can be used to cast from an ImageConstIterator to an
* SubsampledImageRegionConstIterator. Many routines return an ImageIterator
......@@ -156,47 +117,13 @@ public:
* Rather than provide overloaded APIs that return different types of Iterators, itk
* returns ImageIterators and uses constructors to cast from an
* ImageIterator to a SubsampledImageRegionConstIterator. */
SubsampledImageRegionConstIterator( const itk::ImageConstIterator<TImage> &it)
: itk::ImageRegionConstIterator< TImage >( it )
{
m_SubsampleFactor.Fill( 1 );
const IndexType& startIndex = this->m_Region.GetIndex();
const SizeType& size = this->m_Region.GetSize();
for ( unsigned int i = 0; i < ImageIteratorDimension; ++i )
{
m_LastUsableIndex[i] = startIndex[i] + static_cast<IndexValueType>( size[i]-1 );
}
m_SubSampledEndOffset = this->m_Image->ComputeOffset( m_LastUsableIndex ) + 1;
}
SubsampledImageRegionConstIterator( const itk::ImageConstIterator<TImage> &it );
/** Set an isotropic subsampling factor */
void SetSubsampleFactor ( typename IndexType::IndexValueType factor )
{
IndexType index;
index.Fill( factor );
SetSubsampleFactor( index );
}
void SetSubsampleFactor ( typename IndexType::IndexValueType factor );
/** Set / Get the subsample factor */
void SetSubsampleFactor ( const IndexType & factor )
{
this->m_SubsampleFactor = factor;
// Evaluate the last possible pixel.
const IndexType& startIndex = this->m_Region.GetIndex();
const SizeType& size = this->m_Region.GetSize();
for ( unsigned int i = 0; i < ImageIteratorDimension; ++i )
{
m_LastUsableIndex[i] = startIndex[i]
+ static_cast<IndexValueType>( m_SubsampleFactor[i] * ( (size[i]-1) / m_SubsampleFactor[i] ) );
}
m_SubSampledEndOffset = this->m_Image->ComputeOffset( m_LastUsableIndex ) + 1;
}
void SetSubsampleFactor ( const IndexType & factor );
const IndexType & GetSubsampleFactor () const
{
......@@ -205,27 +132,11 @@ public:
/** Move an iterator to the beginning of the region. "Begin" is
* defined as the first pixel in the region. */
void GoToBegin()
{
Superclass::GoToBegin();
const SizeType& size = this->m_Region.GetSize();
this->m_SpanBeginOffset = this->m_Offset;
this->m_SpanEndOffset = this->m_Offset
+ static_cast<IndexValueType>( m_SubsampleFactor[0] * ((size[0]-1) / m_SubsampleFactor[0]) )
+ 1;
}
void GoToBegin();
/** Move an iterator to the end of the region. "End" is defined as
* one pixel past the last pixel of the region. */
void GoToEnd()
{
Superclass::GoToEnd();
this->m_Offset = m_SubSampledEndOffset - 1;
this->m_SpanEndOffset = this->m_Offset + 1;
this->m_SpanBeginOffset = this->m_Offset - m_LastUsableIndex[0];
}
void GoToEnd();
/** Is the iterator at the beginning of the region?
* "Begin" is defined here as before the first pixel
......@@ -235,7 +146,7 @@ public:
*/
bool IsAtBegin(void) const
{
return ( this->m_Offset <= this->m_BeginOffset );
return ( this->m_Offset <= m_SubSampledBeginOffset );
}
/** Is the iterator at the end of the region?
......@@ -250,14 +161,18 @@ public:
return ( this->m_Offset >= m_SubSampledEndOffset );
}
/** Set the index. No bounds checking is performed. This is overridden
* from the parent because we have an extra ivar.
/** Set the index.
* It is moved to the next available (usable) index.
* \sa GetIndex */
void SetIndex(const IndexType &ind)
void SetIndex(const IndexType &ind) ;
/** Get the Index. */
IndexType GetIndex() const
{
Superclass::SetIndex( ind );
return Superclass::GetIndex();
}
/** Increment (prefix) the fastest moving dimension of the iterator's index.
* This operator will constrain the iterator within the region (i.e. the
* iterator will automatically wrap from the end of the row of the region
......@@ -307,70 +222,23 @@ public:
/** This iterator give the possibility to Set/Get the current location if scanning.
* No Bound checking is performed when setting the position.
*/
void SetLocation ( const OffsetType & location )
{
this->m_Offset = location;
const SizeType& size = this->m_Region.GetSize();
this->m_SpanEndOffset = this->m_Offset
+ static_cast<IndexValueType>( m_SubsampleFactor[0] * ((size[0]-1) / m_SubsampleFactor[0]) )
+ 1;
this->m_SpanBeginOffset = this->m_Offset;
}
void SetLocation ( const IndexType & location )
{
this->m_Offset = this->m_Image->ComputeOffset( location );
const SizeType& size = this->m_Region.GetSize();
this->m_SpanEndOffset = this->m_Offset
+ static_cast<IndexValueType>( m_SubsampleFactor[0] * ((size[0]-1) / m_SubsampleFactor[0]) )
+ 1;
this->m_SpanBeginOffset = this->m_Offset;
}
const OffsetType & GetLocationOffset() const
void SetOffset ( const OffsetType & offset );
const OffsetType & GetOffset() const
{
return this->m_Offset;
}
IndexType GetLocationIndex() const
{
IndexType ind = this->m_Image->ComputeIndex( static_cast<IndexValueType>(this->m_Offset) );
return ind;
}
/** In order to help copy into a new Image, give the new region parameters
/** GenerateOutputInformation.
* In order to help copy into a new Image, give the new region parameters
*/
RegionType GetNewRegion () const
{
IndexType startIndex = this->m_Region.GetIndex();
SizeType size = this->m_Region.GetSize();
for ( unsigned int i = 0; i < ImageIteratorDimension; ++i )
{
startIndex[i] /= m_SubsampleFactor[i];
--size[i];
size[i] /= m_SubsampleFactor[i];
++size[i];
}
RegionType newRegion;
newRegion.SetIndex( startIndex );
newRegion.SetSize( size );
for ( unsigned int i = 0; i < ImageIteratorDimension; ++i )
{
otbGenericMsgDebugMacro(<<"NewRegionIndex[" << i << "] = " << startIndex[i]);
otbGenericMsgDebugMacro(<<"NewRegionSize [" << i << "] = " << size[i]);
}
return newRegion;
}
RegionType GenerateOutputInformation () const;
protected:
IndexType m_SubsampleFactor;
unsigned long m_SubSampledBeginOffset;
//unsigned long m_SubSampledReverseEndOffset;
unsigned long m_SubSampledEndOffset;
IndexType m_FirstUsableIndex;
IndexType m_LastUsableIndex;
private:
......
......@@ -26,13 +26,255 @@
namespace otb {
template < class TImage >
SubsampledImageRegionConstIterator< TImage >
::SubsampledImageRegionConstIterator()
: itk::ImageRegionConstIterator<TImage> ()
{
m_SubsampleFactor.Fill(1);
m_SubSampledEndOffset = this->m_EndOffset;
const IndexType& startIndex = this->m_Region.GetIndex();
const SizeType& size = this->m_Region.GetSize();
for ( unsigned int i = 0; i < ImageIteratorDimension; ++i )
{
m_FirstUsableIndex[i] = startIndex[i];
m_LastUsableIndex[i] = startIndex[i] + static_cast<IndexValueType>( size[i]-1 );
}
}
template < class TImage >
SubsampledImageRegionConstIterator< TImage >
::SubsampledImageRegionConstIterator ( const ImageType *ptr, const RegionType &region)
: itk::ImageRegionConstIterator< TImage > ( ptr, region )
{
m_SubsampleFactor.Fill( 1 );
m_SubSampledEndOffset = this->m_EndOffset;
const IndexType& startIndex = this->m_Region.GetIndex();
const SizeType& size = this->m_Region.GetSize();
for ( unsigned int i = 0; i < ImageIteratorDimension; ++i )
{
m_FirstUsableIndex[i] = startIndex[i];
m_LastUsableIndex[i] = startIndex[i] + static_cast<IndexValueType>( size[i]-1 );
}
}
template < class TImage >
SubsampledImageRegionConstIterator< TImage >
::SubsampledImageRegionConstIterator( const itk::ImageIterator<TImage> &it )
: itk::ImageRegionConstIterator< TImage >( it )
{
m_SubsampleFactor.Fill( 1 );
m_SubSampledEndOffset = this->m_EndOffset;
const IndexType& startIndex = this->m_Region.GetIndex();
const SizeType& size = this->m_Region.GetSize();
for ( unsigned int i = 0; i < ImageIteratorDimension; ++i )
{
m_FirstUsableIndex[i] = startIndex[i];
m_LastUsableIndex[i] = startIndex[i] + static_cast<IndexValueType>( size[i]-1 );
}
}
template < class TImage >
SubsampledImageRegionConstIterator< TImage >
::SubsampledImageRegionConstIterator( const itk::ImageConstIterator<TImage> &it )
: itk::ImageRegionConstIterator< TImage >( it )
{
m_SubsampleFactor.Fill( 1 );
const IndexType& startIndex = this->m_Region.GetIndex();
const SizeType& size = this->m_Region.GetSize();
for ( unsigned int i = 0; i < ImageIteratorDimension; ++i )
{
m_FirstUsableIndex[i] = startIndex[i];
m_LastUsableIndex[i] = startIndex[i] + static_cast<IndexValueType>( size[i]-1 );
}
m_SubSampledEndOffset = this->m_Image->ComputeOffset( m_LastUsableIndex ) + 1;
}
template < class TImage >
void
SubsampledImageRegionConstIterator< TImage >
::SetSubsampleFactor ( typename IndexType::IndexValueType factor )
{
IndexType index;
index.Fill( factor );
SetSubsampleFactor( index );
}
template < class TImage >
void
SubsampledImageRegionConstIterator< TImage >
::SetSubsampleFactor ( const IndexType & factor )
{
this->m_SubsampleFactor = factor;
// Evaluate the last possible pixel.
const IndexType& startIndex = this->m_Region.GetIndex();
const SizeType& size = this->m_Region.GetSize();
for ( unsigned int i = 0; i < ImageIteratorDimension; ++i )
{
m_FirstUsableIndex[i] = startIndex[i];
while ( m_FirstUsableIndex[i]
!= ( m_SubsampleFactor[i] * ( m_FirstUsableIndex[i] / m_SubsampleFactor[i] ) ) )
{
++m_FirstUsableIndex[i];
}
m_LastUsableIndex[i] = startIndex[i]
+ static_cast<IndexValueType>( m_SubsampleFactor[i] * ( (size[i]-1) / m_SubsampleFactor[i] ) );
}
m_SubSampledBeginOffset = this->m_Image->ComputeOffset( m_FirstUsableIndex );
//m_SubSampledReverseEndOffset = m_SubSampledBeginOffset - 1;
m_SubSampledEndOffset = this->m_Image->ComputeOffset( m_LastUsableIndex ) + 1;
}
template < class TImage >
void
SubsampledImageRegionConstIterator< TImage >
::GoToBegin()
{
this->m_Offset = m_SubSampledBeginOffset;
const SizeType& size = this->m_Region.GetSize();
this->m_SpanBeginOffset = this->m_Offset;
this->m_SpanEndOffset = this->m_Offset
+ static_cast<IndexValueType>( m_SubsampleFactor[0] * ((size[0]-1) / m_SubsampleFactor[0]) )
+ 1;
}
template < class TImage >
void
SubsampledImageRegionConstIterator< TImage >
::GoToEnd()
{
this->m_Offset = m_SubSampledEndOffset - 1;
this->m_SpanEndOffset = this->m_Offset + 1;
this->m_SpanBeginOffset = this->m_Offset - m_LastUsableIndex[0];
}
template < class TImage >
void
SubsampledImageRegionConstIterator< TImage >
::SetIndex ( const IndexType & ind )
{
IndexType theIndex = ind;
for ( unsigned int i = 0; i < ImageIteratorDimension; ++i )
{
while ( theIndex[i]
!= ( m_SubsampleFactor[i] * ( theIndex[i] / m_SubsampleFactor[i] ) ) )
{
++theIndex[i];
}
if ( theIndex[i] > static_cast<IndexValueType>( this->m_Region.GetIndex()[i] + this->m_Region.GetSize()[i] ) )
{
theIndex[i] = ind[i];
while ( theIndex[i]
!= ( m_SubsampleFactor[i] * ( theIndex[i] / m_SubsampleFactor[i] ) ) )
{
--theIndex[i];
}
if ( theIndex[i] < this->m_Region.GetIndex()[i] )
theIndex[i] = ind[i];
}
}
//Superclass::SetIndex( theIndex );
OffsetType theOffset = this->m_Image->ComputeOffset( theIndex );
SetOffset( theOffset );
}
template < class TImage >
void
SubsampledImageRegionConstIterator< TImage >
::SetOffset( const OffsetType & offset )
{
this->m_Offset = offset;
const SizeType& size = this->m_Region.GetSize();
this->m_SpanBeginOffset = this->m_Offset;
this->m_SpanEndOffset = this->m_Offset
+ static_cast<IndexValueType>( m_SubsampleFactor[0] * ((size[0]-1) / m_SubsampleFactor[0]) )
+ 1;
}
template < class TImage >
typename SubsampledImageRegionConstIterator< TImage >::RegionType
SubsampledImageRegionConstIterator< TImage >
::GenerateOutputInformation () const
{
IndexType startIndex = this->m_Region.GetIndex();
SizeType size = this->m_Region.GetSize();
for ( unsigned int i = 0; i < ImageIteratorDimension; ++i )
{
startIndex[i] /= m_SubsampleFactor[i];
--size[i];
size[i] /= m_SubsampleFactor[i];
++size[i];
}
RegionType newRegion;
newRegion.SetIndex( startIndex );
newRegion.SetSize( size );
#if 0
// #ifndef NDEBUG
std::cerr << "InitialImageSize (";
for ( unsigned int i = 0; i < ImageIteratorDimension-1; i++ )
std::cerr << this->m_Region.GetSize()[i] << ", ";
std::cerr << this->m_Region.GetSize()[ImageIteratorDimension-1] << ") with index (";
for ( unsigned int i = 0; i < ImageIteratorDimension-1; i++ )
std::cerr << this->m_Region.GetIndex()[i] << ", ";
std::cerr << this->m_Region.GetIndex()[ImageIteratorDimension-1] << ")\n";
std::cerr << "NewRegionSize (";
for ( unsigned int i = 0; i < ImageIteratorDimension-1; i++ )
std::cerr << size[i] << ", ";
std::cerr << size[ImageIteratorDimension-1] << ") with index (";
for ( unsigned int i = 0; i < ImageIteratorDimension-1; i++ )
std::cerr << startIndex[i] << ", ";
std::cerr << startIndex[ImageIteratorDimension-1] << ")\n";
std::cerr << "FirstIndex (";
for ( unsigned int i = 0; i < ImageIteratorDimension-1; i++ )
std::cerr << m_FirstUsableIndex[i] << ", ";
std::cerr << m_FirstUsableIndex[ImageIteratorDimension-1] << ") offset=";
std::cerr << m_SubSampledBeginOffset << "\n";
std::cerr << "LastIndex (";
for ( unsigned int i = 0; i < ImageIteratorDimension-1; i++ )
std::cerr << m_LastUsableIndex[i] << ", ";
std::cerr << m_LastUsableIndex[ImageIteratorDimension-1] << ") offset=";
std::cerr << m_SubSampledEndOffset << "\n";
#endif
return newRegion;
}
template < class TImage >
void
SubsampledImageRegionConstIterator< TImage >
::Increment ()
{
// Get the index of the last pixel on the span (row)
IndexType ind = this->m_Image->ComputeIndex( static_cast<typename Superclass::OffsetValueType>(this->m_Offset) );
IndexType ind = this->m_Image->ComputeIndex(
static_cast<typename Superclass::OffsetValueType>(this->m_Offset) );
const IndexType& startIndex = this->m_Region.GetIndex();
const SizeType& size = this->m_Region.GetSize();
......
......@@ -89,6 +89,18 @@ public:
itkExceptionMacro("GetYear not implemented in DefaultImageMetadataInterface, no captor type found");
};
/** Get the sat elevation from the ossim metadata */
double GetSatElevation( const MetaDataDictionaryType & dict ) const
{
itkExceptionMacro("GetSatElevation not implemented in DefaultImageMetadataInterface, no captor type found");
};
/** Get the sat azimuth from the ossim metadata */
double GetSatAzimuth( const MetaDataDictionaryType & dict ) const
{
itkExceptionMacro("GetSatElevation not implemented in DefaultImageMetadataInterface, no captor type found");
};
bool CanRead( const MetaDataDictionaryType & dict ) const
{
// This clas is the default one, it has to be able to call every metadata
......
......@@ -318,4 +318,51 @@ IkonosImageMetadataInterface
return outputValuesVariableLengthVector;
}
double
IkonosImageMetadataInterface::GetSatElevation( const MetaDataDictionaryType & dict ) const
{
if( !this->CanRead( dict ) )
{
itkExceptionMacro(<<"Invalid Metadata, no Ikonos Image");
}
ImageKeywordlistType imageKeywordlist;
if (dict.HasKey(MetaDataKey::OSSIMKeywordlistKey))
{
itk::ExposeMetaData<ImageKeywordlistType>(dict, MetaDataKey::OSSIMKeywordlistKey, imageKeywordlist);
}
ossimKeywordlist kwl;
imageKeywordlist.convertToOSSIMKeywordlist(kwl);
std::string key= "support_data.nominal_collection_elevation_angle";
ossimString keywordString = kwl.find(key.c_str());
return keywordString.toDouble();
}
double
IkonosImageMetadataInterface::GetSatAzimuth( const MetaDataDictionaryType & dict ) const
{
if( !this->CanRead( dict ) )
{
itkExceptionMacro(<<"Invalid Metadata, no Ikonos Image");
}
ImageKeywordlistType imageKeywordlist;
if (dict.HasKey(MetaDataKey::OSSIMKeywordlistKey))
{
itk::ExposeMetaData<ImageKeywordlistType>(dict, MetaDataKey::OSSIMKeywordlistKey, imageKeywordlist);
}
ossimKeywordlist kwl;
imageKeywordlist.convertToOSSIMKeywordlist(kwl);
std::string key= "support_data.nominal_collection_azimuth_angle";
ossimString keywordString = kwl.find(key.c_str());
return keywordString.toDouble();
}
} // end namespace otb
......@@ -72,6 +72,12 @@ public:
/** Get the imaging month from the ossim metadata */
int GetYear( const MetaDataDictionaryType & dict ) const;
/** Get the sat elevation from the ossim metadata */
double GetSatElevation( const MetaDataDictionaryType & dict ) const;
/** Get the sat azimuth from the ossim metadata */
double GetSatAzimuth( const MetaDataDictionaryType & dict ) const;
bool CanRead( const MetaDataDictionaryType & dict) const;
......
/*=========================================================================
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 "otbImageMetadataInterface.h"
#include "otbDefaultImageMetadataInterface.h"
// Optical sensors
#include "otbIkonosImageMetadataInterfaceFactory.h"
#include "otbSpotImageMetadataInterfaceFactory.h"
#include "otbQuickBirdImageMetadataInterfaceFactory.h"
// SAR Sensors
#include "itkObjectFactoryBase.h"
#include "itkMutexLock.h"
#include "itkMutexLockHolder.h"
namespace otb
{
ImageMetadataInterface::ImageMetadataInterfaceBasePointerType
ImageMetadataInterface
::CreateIMI( const MetaDataDictionaryType & dict )
{
RegisterBuiltInFactories();
std::list<ImageMetadataInterfaceBasePointerType> possibleIMI;
std::list<itk::LightObject::Pointer> allobjects =
itk::ObjectFactoryBase::CreateAllInstance("ImageMetadataInterfaceBase");
for (std::list<itk::LightObject::Pointer>::iterator i = allobjects.begin();
i != allobjects.end(); ++i)
{
ImageMetadataInterfaceBase * io = dynamic_cast<ImageMetadataInterfaceBase*>(i->GetPointer());
if (io)
{
possibleIMI.push_back(io);
}
else
{
itkGenericExceptionMacro(<< "Error ImageMetadataInterface factory did not return an ImageMetadataInterfaceBase: "
<< (*i)->GetNameOfClass());
}
}
for (std::list<ImageMetadataInterfaceBasePointerType>::iterator k = possibleIMI.begin();
k != possibleIMI.end(); ++k)
{
if ((*k)->CanRead(dict))
{
return *k;
}
}
DefaultImageMetadataInterface::Pointer defaultIMI = DefaultImageMetadataInterface::New();
return dynamic_cast<ImageMetadataInterfaceBase*>(static_cast<DefaultImageMetadataInterface*>(defaultIMI));
}
void
ImageMetadataInterface
::RegisterBuiltInFactories()
{
static bool firstTime = true;
static itk::SimpleMutexLock mutex;
{
// This helper class makes sure the Mutex is unlocked
// in the event an exception is thrown.
itk::MutexLockHolder<itk::SimpleMutexLock> mutexHolder( mutex );
if ( firstTime )
{
itk::ObjectFactoryBase::RegisterFactory( IkonosImageMetadataInterfaceFactory::New() );
itk::ObjectFactoryBase::RegisterFactory( SpotImageMetadataInterfaceFactory::New() );
itk::ObjectFactoryBase::RegisterFactory( QuickBirdImageMetadataInterfaceFactory::New() );
//itk::ObjectFactoryBase::RegisterFactory( QuickBirdImageMetadataInterfaceFactory::New() );
firstTime = false;
}
}
}
} // end namespace otb
/*=========================================================================
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 __otbImageMetadataInterface_h
#define __otbImageMetadataInterface_h
#include "itkObject.h"
#include "otbImageMetadataInterfaceBase.h"
namespace otb
{
/** \class ImageMetadataInterface
* \brief Create instances of ImageMetadataInterface objects using an object factory.
*/
class ITK_EXPORT ImageMetadataInterface : public itk::Object
{
public:
/** Standard class typedefs. */
typedef ImageMetadataInterface Self;
typedef itk::Object Superclass;
typedef itk::SmartPointer<Self> Pointer;
typedef itk::SmartPointer<const Self> ConstPointer;
/** Class Methods used to interface with the registered factories */
/** Run-time type information (and related methods). */
itkTypeMacro(ImageMetadataInterface, Object);
/** Convenient typedefs. */
typedef ImageMetadataInterfaceBase::ImageType ImageType;
typedef ImageMetadataInterfaceBase::MetaDataDictionaryType MetaDataDictionaryType;
typedef ImageMetadataInterfaceBase::VectorType VectorType;
typedef ImageMetadataInterfaceBase::VariableLengthVectorType VariableLengthVectorType;
typedef ImageMetadataInterfaceBase::ImageKeywordlistType ImageKeywordlistType;
typedef ImageMetadataInterfaceBase::Pointer ImageMetadataInterfaceBasePointerType;
/** Create the appropriate ImageMetadataInterface depending on the particulars of the file. */
static ImageMetadataInterfaceBasePointerType CreateIMI( const MetaDataDictionaryType & dict );
/** Register Built-in factories */
static void RegisterBuiltInFactories();
protected:
ImageMetadataInterface();
~ImageMetadataInterface();
private:
ImageMetadataInterface(const Self&); //purposely not implemented
void operator=(const Self&); //purposely not implemented
};
} // end namespace otb
#endif
......@@ -166,6 +166,14 @@ public:
virtual int GetYear( const MetaDataDictionaryType & dict ) const =0;
otbMetadataGetMacro(Year, int);
/** Get the sat elevation from the ossim metadata */
virtual double GetSatElevation( const MetaDataDictionaryType & dict ) const =0;
otbMetadataGetMacro(SatElevation, double);
/** Get the sat azimuth from the ossim metadata */
virtual double GetSatAzimuth( const MetaDataDictionaryType & dict ) const =0;
otbMetadataGetMacro(SatAzimuth, double);
virtual bool CanRead( const MetaDataDictionaryType & dict ) const =0;
virtual void PrintSelf(std::ostream& os, itk::Indent indent, const MetaDataDictionaryType & dict) const;
......
......@@ -65,7 +65,7 @@ ImageMetadataInterfaceFactory
return *k;
}
}
std::cout<<"bothing found -> use default"<<std::endl;
DefaultImageMetadataInterface::Pointer defaultIMI = DefaultImageMetadataInterface::New();
return dynamic_cast<ImageMetadataInterfaceBase*>(static_cast<DefaultImageMetadataInterface*>(defaultIMI));
}
......
......@@ -409,4 +409,52 @@ QuickBirdImageMetadataInterface
return outputValuesVariableLengthVector;
}
double
QuickBirdImageMetadataInterface::GetSatElevation( const MetaDataDictionaryType & dict ) const
{
if( !this->CanRead( dict ) )
{
itkExceptionMacro(<<"Invalid Metadata, no QuickBird Image");
}
ImageKeywordlistType imageKeywordlist;
if (dict.HasKey(MetaDataKey::OSSIMKeywordlistKey))
{
itk::ExposeMetaData<ImageKeywordlistType>(dict, MetaDataKey::OSSIMKeywordlistKey, imageKeywordlist);
}
ossimKeywordlist kwl;
imageKeywordlist.convertToOSSIMKeywordlist(kwl);
std::string key= "support_data.sat_elevation_angle";
ossimString keywordString = kwl.find(key.c_str());
return keywordString.toDouble();
}
double
QuickBirdImageMetadataInterface::GetSatAzimuth( const MetaDataDictionaryType & dict ) const
{
if( !this->CanRead( dict ) )
{
itkExceptionMacro(<<"Invalid Metadata, no QuickBird Image");
}
ImageKeywordlistType imageKeywordlist;
if (dict.HasKey(MetaDataKey::OSSIMKeywordlistKey))
{
itk::ExposeMetaData<ImageKeywordlistType>(dict, MetaDataKey::OSSIMKeywordlistKey, imageKeywordlist);
}
ossimKeywordlist kwl;
imageKeywordlist.convertToOSSIMKeywordlist(kwl);
std::string key= "support_data.sat_azimuth_angle";
ossimString keywordString = kwl.find(key.c_str());
return keywordString.toDouble();
}
} // end namespace otb
......@@ -71,6 +71,12 @@ public:
/** Get the imaging month from the ossim metadata */
int GetYear( const MetaDataDictionaryType & dict ) const;
/** Get the sat elevation from the ossim metadata */
double GetSatElevation( const MetaDataDictionaryType & dict ) const;
/** Get the sat azimuth from the ossim metadata */
double GetSatAzimuth( const MetaDataDictionaryType & dict ) const;
bool CanRead( const MetaDataDictionaryType & dict) const;
......
......@@ -303,5 +303,63 @@ SpotImageMetadataInterface
return outputValuesVariableLengthVector;
}
double
SpotImageMetadataInterface::GetSatElevation( const MetaDataDictionaryType & dict ) const
{
if( !this->CanRead( dict ) )
{
itkExceptionMacro(<<"Invalid Metadata, no Spot Image");
}
ImageKeywordlistType imageKeywordlist;
if (dict.HasKey(MetaDataKey::OSSIMKeywordlistKey))
{
itk::ExposeMetaData<ImageKeywordlistType>(dict, MetaDataKey::OSSIMKeywordlistKey, imageKeywordlist);
}
ossimKeywordlist kwl;
imageKeywordlist.convertToOSSIMKeywordlist(kwl);
std::string key= "support_data.incident_angle";
ossimString keywordString = kwl.find(key.c_str());
return ( 90.-keywordString.toDouble() );
}
double
SpotImageMetadataInterface::GetSatAzimuth( const MetaDataDictionaryType & dict ) const
{
if( !this->CanRead( dict ) )
{
itkExceptionMacro(<<"Invalid Metadata, no Spot Image");
}
ImageKeywordlistType imageKeywordlist;
if (dict.HasKey(MetaDataKey::OSSIMKeywordlistKey))
{
itk::ExposeMetaData<ImageKeywordlistType>(dict, MetaDataKey::OSSIMKeywordlistKey, imageKeywordlist);
}
ossimKeywordlist kwl;
imageKeywordlist.convertToOSSIMKeywordlist(kwl);
std::string key= "support_data.step_count";
ossimString keywordString = kwl.find(key.c_str());
int step = keywordString.toInt();
key= "support_data.scene_orientation";
keywordString = kwl.find(key.c_str());
double satAz = keywordString.toDouble();
if( (step-48)<0 )
{
satAz += 90.;
}
else
satAz = satAz - 90.;
return satAz;
}
} // end namespace otb
......@@ -71,6 +71,12 @@ public:
/** Get the imaging month from the ossim metadata */
int GetYear( const MetaDataDictionaryType & dict ) const;
/** Get the sat elevation from the ossim metadata */
double GetSatElevation( const MetaDataDictionaryType & dict ) const;
/** Get the sat azimuth from the ossim metadata */
double GetSatAzimuth( const MetaDataDictionaryType & dict ) const;
bool CanRead( const MetaDataDictionaryType & dict) const;
......
This diff is collapsed.
......@@ -99,38 +99,38 @@ public:
typedef typename ExtractFilterType::Pointer ExtractFilterPointerType;
/** Set/Get the image */
void SetImage(ImageType * img)
virtual void SetImage(ImageType * img)
{
if(m_Image != img)
if(this->m_Image != img)
{
m_Image = img;
m_ExtractFilter->SetInput(m_Image);
m_ScaledExtractFilter->SetInput(m_Image);
this-> m_Image = img;
this->m_ExtractFilter->SetInput(m_Image);
this->m_ScaledExtractFilter->SetInput(m_Image);
}
}
itkGetObjectMacro(Image,ImageType);
/** Set/Get the quicklook */
void SetQuicklook(ImageType * ql)
virtual void SetQuicklook(ImageType * ql)
{
if(m_Quicklook != ql)
if(this->m_Quicklook != ql)
{
m_Quicklook = ql;
m_QuicklookRenderingFilter->SetInput(m_Quicklook);
this->m_Quicklook = ql;
this->m_QuicklookRenderingFilter->SetInput(m_Quicklook);
}
}
itkGetObjectMacro(Quicklook,ImageType);
/** Get the histogram list */
HistogramListPointerType GetHistogramList()
virtual HistogramListPointerType GetHistogramList()
{
//FIXME Update condition?
return m_RenderingFunction->GetHistogramList();
}
/** Set/Get the rendering function */
void SetRenderingFunction(RenderingFunctionType * function)
virtual void SetRenderingFunction(RenderingFunctionType * function)
{
m_RenderingFunction = function;
m_RenderingFunction->SetListSample(this->GetListSample());
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment