Skip to content
Snippets Groups Projects
Commit 7bac4c50 authored by Emmanuel Christophe's avatar Emmanuel Christophe
Browse files

ENH: definition of GenerateOutputInformation

parent d45cab79
Branches
Tags
No related merge requests found
......@@ -9,6 +9,8 @@
#include "otbImage.h"
#include "otbVectorDataToImageFilter.h"
// ./mapnikOTBClasses /home/christop/OTB/trunk/OTB-Data/Input/waterways.shp output.png
int main(int argc, char * argv[])
{
......@@ -32,6 +34,7 @@ int main(int argc, char * argv[])
VectorDataToImageFilterType::Pointer vectorDataRendering = VectorDataToImageFilterType::New();
vectorDataRendering->SetInput(projection->GetOutput());
//Save the image in a file
typedef otb::ImageFileWriter<ImageType> WriterType;
WriterType::Pointer writer = WriterType::New();
......
......@@ -48,11 +48,43 @@ template <class TVectorData, class TImage>
/** Some typedefs. */
typedef TVectorData VectorDataType;
typedef TImage ImageType;
typedef typename ImageType::Pointer ImagePointer;
/** Number of dimensions. */
itkStaticConstMacro(ImageDimension, unsigned int,
TImage::ImageDimension);
/** Image size typedef. */
typedef itk::Size<itkGetStaticConstMacro(ImageDimension)> SizeType;
/** Image index typedef. */
typedef typename TImage::IndexType IndexType;
/** Image spacing,origin and direction typedef */
typedef typename TImage::SpacingType SpacingType;
typedef typename TImage::PointType OriginType;
typedef typename TImage::DirectionType DirectionType;
virtual void SetInput( const VectorDataType *input);
const VectorDataType * GetInput(void);
/** Set the origin of the vector data.
* \sa GetOrigin() */
itkSetMacro(Origin, OriginType);
virtual void SetOrigin( const double origin[2] );
virtual void SetOrigin( const float origin[2] );
itkGetConstReferenceMacro(Origin, OriginType);
/** Set the spacing (size of a pixel) of the vector data.
* \sa GetSpacing() */
virtual void SetSpacing (const SpacingType & spacing);
virtual void SetSpacing (const double spacing[2]);
virtual void SetSpacing (const float spacing[2]);
itkGetConstReferenceMacro(Spacing, SpacingType);
protected:
/** Constructor */
......@@ -62,13 +94,22 @@ template <class TVectorData, class TImage>
/**PrintSelf method */
virtual void PrintSelf(std::ostream& os, itk::Indent indent) const;
virtual void GenerateOutputInformation();
virtual void GenerateData(void);
virtual void BeforeThreadedGenerateData();
private:
VectorDataToImageFilter(const Self&); //purposely not implemented
void operator=(const Self&); //purposely not implemented
SpacingType m_Spacing;
OriginType m_Origin;
SizeType m_Size;
IndexType m_StartIndex;
DirectionType m_Direction;
}; // end class
} // end namespace otb
......
......@@ -61,6 +61,99 @@ namespace otb
//----------------------------------------------------------------------------
template <class TVectorData, class TImage>
void
VectorDataToImageFilter<TVectorData, TImage>
::SetSpacing(const SpacingType & spacing )
{
itkDebugMacro("setting Spacing to " << spacing);
if ( this->m_Spacing != spacing )
{
this->m_Spacing = spacing;
this->Modified();
}
}
//----------------------------------------------------------------------------
template <class TVectorData, class TImage>
void
VectorDataToImageFilter<TVectorData, TImage>
::SetSpacing(const double spacing[2] )
{
SpacingType s(spacing);
this->SetSpacing(s);
}
//----------------------------------------------------------------------------
template <class TVectorData, class TImage>
void
VectorDataToImageFilter<TVectorData, TImage>
::SetSpacing(const float spacing[2] )
{
itk::Vector<float, 2> sf(spacing);
SpacingType s;
s.CastFrom( sf );
this->SetSpacing(s);
}
//----------------------------------------------------------------------------
template <class TVectorData, class TImage>
void
VectorDataToImageFilter<TVectorData, TImage>
::SetOrigin(const double origin[2] )
{
OriginType p(origin);
this->SetOrigin( p );
}
//----------------------------------------------------------------------------
template <class TVectorData, class TImage>
void
VectorDataToImageFilter<TVectorData, TImage>
::SetOrigin(const float origin[2] )
{
itk::Point<float, 2> of(origin);
OriginType p;
p.CastFrom( of );
this->SetOrigin( p );
}
/**
* Inform pipeline of required output region
*/
template <class TVectorData, class TImage>
void
VectorDataToImageFilter<TVectorData, TImage>
::GenerateOutputInformation()
{
// call the superclass' implementation of this method
Superclass::GenerateOutputInformation();
// get pointers to the input and output
ImagePointer outputPtr = this->GetOutput();
if ( !outputPtr )
{
return;
}
// Set the size of the output region
typename TImage::RegionType outputLargestPossibleRegion;
outputLargestPossibleRegion.SetSize( m_Size );
outputLargestPossibleRegion.SetIndex( m_StartIndex );
outputPtr->SetLargestPossibleRegion( outputLargestPossibleRegion );
// Set spacing and origin
outputPtr->SetSpacing( m_Spacing );
outputPtr->SetOrigin( m_Origin );
outputPtr->SetDirection( m_Direction );
return;
}
/**
* Generate Data
*/
......@@ -69,10 +162,23 @@ namespace otb
VectorDataToImageFilter<TVectorData, TImage>
::GenerateData(void)
{
this->AllocateOutputs();
this->BeforeThreadedGenerateData();
this->AfterThreadedGenerateData();
}
template <class TVectorData, class TImage>
void
VectorDataToImageFilter<TVectorData, TImage>
::BeforeThreadedGenerateData(void)
{
Superclass::BeforeThreadedGenerateData();
}
/**
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment