Commit 6fe0beb1 authored by Emmanuel Christophe's avatar Emmanuel Christophe
Browse files

ENH: adding origin and spacing for VectorData (link with Visualization)

parent c0dc33a4
......@@ -36,9 +36,15 @@ namespace otb
* The internal tree can be walked with itk::TreeIteratorBase subclasses.
*
* The three templates indicate
* - the precision of the points coordinates (default double)
* - the number of dimensions of the space (default 2)
* - the precision of the value associated with objects such as line or polygons (default double)
* - the precision of the points coordinates (by default: double)
* - the number of dimensions of the space (by default: 2)
* - the precision of the value associated with objects such as line or
* polygons (by default: double)
*
* The elements in the VectorData have their coordinates in the projection
* specified by the Wkt string. This class also offer the possibility to store
* the coordinates directly into an image coordinate system, using the origin and
* spacing in a similar way as the corresponding image.
*
* \sa DataNode
* \sa VectorDataFileReader
......@@ -70,6 +76,10 @@ public:
typedef typename DataNodeType::Pointer DataNodePointerType;
typedef itk::TreeContainer<DataNodePointerType> DataTreeType;
typedef typename DataTreeType::Pointer DataTreePointerType;
typedef typename DataNodeType::PointType PointType;
typedef itk::Vector<double, 2> SpacingType;
typedef itk::Point<double, 2> OriginType;
itkGetObjectMacro(DataTree,DataTreeType);
itkGetConstObjectMacro(DataTree,DataTreeType);
......@@ -77,12 +87,38 @@ public:
virtual void SetProjectionRef(std::string projectionRef);
virtual std::string GetProjectionRef() const;
/** Set the origin of the vector data to put it in the corresponding
* image coordinates
* \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 of the vector data to put it in the corresponding
* image coordinates
* \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);
/** Clear the vector data */
virtual bool Clear();
/** Return the number of element in the tree */
virtual int Size() const;
void TransformPointToPhysicalPoint(const PointType& point, PointType& physicalPoint) const
{
physicalPoint[0] = point[0] * m_Spacing[0] + m_Origin[0];
physicalPoint[1] = point[1] * m_Spacing[1] + m_Origin[1];
}
protected:
/** Constructor */
VectorData();
......@@ -95,10 +131,12 @@ private:
VectorData(const Self&); //purposely not implemented
void operator=(const Self&); //purposely not implemented
/** Data tree */
DataTreePointerType m_DataTree;
SpacingType m_Spacing;
OriginType m_Origin;
};
}// end namespace otb
......
......@@ -33,6 +33,8 @@ VectorData<TPrecision,VDimension,TValuePrecision>
DataNodePointerType root = DataNodeType::New();
root->SetNodeId("Root");
m_DataTree->SetRoot(root);
m_Origin.Fill(0);
m_Spacing.Fill(1);
}
template<class TPrecision, unsigned int VDimension, class TValuePrecision>
......@@ -59,6 +61,66 @@ VectorData<TPrecision,VDimension,TValuePrecision>
return projectionRef;
}
template<class TPrecision, unsigned int VDimension, class TValuePrecision>
void
VectorData<TPrecision,VDimension,TValuePrecision>
::SetSpacing(const SpacingType & spacing )
{
itkDebugMacro("setting Spacing to " << spacing);
if ( this->m_Spacing != spacing )
{
this->m_Spacing = spacing;
this->Modified();
}
}
template<class TPrecision, unsigned int VDimension, class TValuePrecision>
void
VectorData<TPrecision,VDimension,TValuePrecision>
::SetSpacing(const double spacing[2] )
{
SpacingType s(spacing);
this->SetSpacing(s);
}
template<class TPrecision, unsigned int VDimension, class TValuePrecision>
void
VectorData<TPrecision,VDimension,TValuePrecision>
::SetSpacing(const float spacing[2] )
{
itk::Vector<float, 2> sf(spacing);
SpacingType s;
s.CastFrom( sf );
this->SetSpacing(s);
}
template<class TPrecision, unsigned int VDimension, class TValuePrecision>
void
VectorData<TPrecision,VDimension,TValuePrecision>
::SetOrigin(const double origin[2] )
{
OriginType p(origin);
this->SetOrigin( p );
}
template<class TPrecision, unsigned int VDimension, class TValuePrecision>
void
VectorData<TPrecision,VDimension,TValuePrecision>
::SetOrigin(const float origin[2] )
{
itk::Point<float, 2> of(origin);
OriginType p;
p.CastFrom( of );
this->SetOrigin( p );
}
template <class TPrecision, unsigned int VDimension, class TValuePrecision>
bool
VectorData<TPrecision,VDimension,TValuePrecision>
......
......@@ -359,7 +359,8 @@ VectorDataProjectionFilter<TInputVectorData,TOutputVectorData>
{
itk::EncapsulateMetaData<std::string>(outputDict, MetaDataKey::ProjectionRefKey, m_OutputProjectionRef );
}
output->SetSpacing(m_OutputSpacing);
output->SetOrigin(m_OutputOrigin);
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment