Skip to content
Snippets Groups Projects
Commit c3e14e66 authored by Julien Michel's avatar Julien Michel
Browse files

MRG

parents 35dc849e b7d9d26c
Branches
Tags
No related merge requests found
......@@ -23,6 +23,10 @@
//TODO change this include have to define from what inherate this class
#include "otbPolyLineParametricPathWithValue.h" //for vcl_abs
#include "itkVector.h"
#include "itkPoint.h"
#include "itkIndex.h"
namespace otb
{
......@@ -61,6 +65,10 @@ public:
typedef typename LineType::IndexType IndexType;
typedef TPolygon PolygonType;
typedef typename PolygonType::Pointer PolygonPointerType;
typedef typename PolygonType::VertexType VertexType;
typedef itk::Point<double,2> PointType;
typedef itk::Vector<double,2> SpacingType;
typedef itk::Index<2> RegionIndexType;
/**
* \param labelObject the label object to vectorize
......@@ -68,6 +76,55 @@ public:
*/
inline PolygonType * operator()(const LabelObjectType * labelObject);
/** Set the start index of the underlying image */
void SetStartIndex(const RegionIndexType & index)
{
m_StartIndex = index;
}
/** Get the start index */
const RegionIndexType & GetStartIndex() const
{
return m_StartIndex;
}
/** Set the origin of the underlying image */
void SetOrigin(const PointType & origin)
{
m_Origin = origin;
}
/** Get the origin */
const PointType & GetOrigin() const
{
return m_Origin;
}
/** Set the spacing of the underlying image */
void SetSpacing(const SpacingType & spacing)
{
m_Spacing = spacing;
}
/** Get the spacing */
const SpacingType & GetSpacing() const
{
return m_Spacing;
}
/** Constructor */
LabelObjectToPolygonFunctor() : m_Polygon(NULL),
m_CurrentState(UP_LEFT),
m_PositionFlag(LEFT_END),
m_StartingPoint(),
m_CurrentPoint(),
m_CurrentRun(),
m_CurrentLine(0),
m_Solution(),
m_LineOffset(0),
m_StartIndex(),
m_Origin(),
m_Spacing(1.)
{}
/** Destructor */
virtual ~LabelObjectToPolygonFunctor(){}
private:
/// Internal structures
typedef std::vector<LineType> RunsPerLineType;
......@@ -109,6 +166,9 @@ private:
/// Walk right to update the finite states machine.
inline void WalkRight(unsigned int line,const IndexType & startPoint, const IndexType & endPoint, PolygonType * polygon, const StateType state);
// Apply origin and spacing
VertexType IndexToPoint(const VertexType& index) const;
PolygonPointerType m_Polygon;
// Internal structure to store runs
......@@ -137,6 +197,13 @@ private:
/// The line offset from start of the region
unsigned int m_LineOffset;
// The following will be used for coordinate transform
RegionIndexType m_StartIndex;
PointType m_Origin;
SpacingType m_Spacing;
}; // end class LabelObjectToPolygonFunctor
} // end namespace Functor
......
......@@ -511,7 +511,7 @@ LabelObjectToPolygonFunctor<TLabelObject,TPolygon>
m_CurrentPoint[1]=line+m_LineOffset;
newPoint = m_CurrentPoint;
newPoint+=offset;
polygon->AddVertex(newPoint);
polygon->AddVertex(IndexToPoint(newPoint));
}
// if the end point is not on line n, add an intermediate point
......@@ -520,7 +520,7 @@ LabelObjectToPolygonFunctor<TLabelObject,TPolygon>
m_CurrentPoint[0] = endPoint[0]+1;
newPoint = m_CurrentPoint;
newPoint+=offset;
polygon->AddVertex(newPoint);
polygon->AddVertex(IndexToPoint(newPoint));
}
if(m_CurrentPoint != endPoint)
......@@ -528,7 +528,7 @@ LabelObjectToPolygonFunctor<TLabelObject,TPolygon>
m_CurrentPoint = endPoint;
newPoint = m_CurrentPoint;
newPoint+=offset;
polygon->AddVertex(newPoint);
polygon->AddVertex(IndexToPoint(newPoint));
}
}
......@@ -572,7 +572,7 @@ LabelObjectToPolygonFunctor<TLabelObject,TPolygon>
m_CurrentPoint[1]=line+m_LineOffset;
newPoint = m_CurrentPoint;
newPoint+=offset;
polygon->AddVertex(newPoint);
polygon->AddVertex(IndexToPoint(newPoint));
}
// if the end point is not on line n, add an intermediate point
......@@ -581,7 +581,7 @@ LabelObjectToPolygonFunctor<TLabelObject,TPolygon>
m_CurrentPoint[0] = endPoint[0]-1;
newPoint = m_CurrentPoint;
newPoint+=offset;
polygon->AddVertex(newPoint);
polygon->AddVertex(IndexToPoint(newPoint));
}
if(m_CurrentPoint!=endPoint)
......@@ -589,10 +589,27 @@ LabelObjectToPolygonFunctor<TLabelObject,TPolygon>
m_CurrentPoint = endPoint;
newPoint = m_CurrentPoint;
newPoint+=offset;
polygon->AddVertex(newPoint);
polygon->AddVertex(IndexToPoint(newPoint));
}
}
// Apply origin and spacing
template<class TLabelObject, class TPolygon>
typename LabelObjectToPolygonFunctor<TLabelObject,TPolygon>
::VertexType
LabelObjectToPolygonFunctor<TLabelObject,TPolygon>
::IndexToPoint(const VertexType& index) const
{
VertexType resp;
// Apply origin and spacing
resp[0] = (index[0]-m_StartIndex[0])*m_Spacing[0]+m_Origin[0];
resp[1] = (index[1]-m_StartIndex[1])*m_Spacing[1]+m_Origin[1];
return resp;
}
} // end namespace Functor
} // end namespace otb
......
......@@ -444,6 +444,9 @@ ShapeAttributesLabelObjectFunctor<TLabelObject,TLabelImage>
// Flusser moments
PolygonFunctorType polygonFunctor;
polygonFunctor.SetStartIndex(m_LabelImage->GetLargestPossibleRegion().GetIndex());
polygonFunctor.SetOrigin(m_LabelImage->GetOrigin());
polygonFunctor.SetSpacing(m_LabelImage->GetSpacing());
typename PolygonType::Pointer polygon = polygonFunctor(lo);
lo->SetPolygon(polygon);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment