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

Ajout du support des itérateur d'arrêtes incidentes et sortantes, tests...

Ajout du support des itérateur d'arrêtes incidentes et sortantes, tests associés ajoutés au test RCC8Graph.
parent 37886972
No related branches found
No related tags found
No related merge requests found
......@@ -24,7 +24,7 @@ namespace otb
{
/**
* \class EdgeIterator
* \brief Iterates on the graph vertices
* \brief Iterates on the graph edges.
*/
template <class TGraph>
class RCC8EdgeIterator
......
......@@ -48,7 +48,10 @@ namespace otb
m_Graph=graph;
tie(m_Iter,m_End)=edges(*m_Graph->GetGraph());
}
/**
* Get the current edge value.
* \return The value of the current edge pointed by the iterator.
*/
template <class TGraph>
typename RCC8EdgeIterator<TGraph>
::RCC8ValueType
......
/*=========================================================================
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 _otbRCC8InEdgeIterator_h
#define _otbRCC8InEdgeIterator_h
#include "otbRCC8Graph.h"
namespace otb
{
/**
* \class EdgeIterator
* \brief Iterates on the graph in edges from a vertex.
*/
template <class TGraph>
class RCC8InEdgeIterator
{
public:
/** self typedef */
typedef RCC8InEdgeIterator Self;
/** Graph typedef */
typedef TGraph GraphType;
typedef typename GraphType::InternalGraphType InternalGraphType;
typedef typename GraphType::Pointer GraphPointerType;
typedef typename GraphType::EdgePointerType EdgePointerType;
typedef typename GraphType::VertexPointerType VertexPointerType;
typedef typename GraphType::VertexDescriptorType VertexDescriptorType;
typedef typename GraphType::RCC8ValueType RCC8ValueType;
/** typedef of the internal iterator */
typedef typename boost::graph_traits<InternalGraphType>::in_edge_iterator InternalIteratorType;
/** Typedef of the index map */
typedef typename boost::property_map<InternalGraphType, boost::vertex_index_t>::type IndexMapType;
/** Constructor */
RCC8InEdgeIterator();
/** Copy constructor */
RCC8InEdgeIterator(const Self& iter);
/** Constructor with input graph */
RCC8InEdgeIterator(VertexDescriptorType vertex,GraphType * graph);
/**
* Get the current edge value.
* \return The value of the current edge pointed by the iterator.
*/
RCC8ValueType GetValue(void);
/**
* Return the source vertex of the current edge.
* \return The source edge.
*/
VertexPointerType GetSourceVertex(void);
/**
* Return the source vertex index of the current edge.
* \return The souce vertex index.
*/
VertexDescriptorType GetSourceIndex(void);
/**
* Return true if the iterator is at the end.
* \return True if the iterator is at the end.
*/
bool IsAtEnd(void);
/**
* Go to the beginning.
*/
void GoToBegin(void);
/**
* Increment.
*/
Self& operator++();
/**
* Decrement.
*/
Self& operator--();
/**
* Add
*/
Self& operator+(int i);
/**
* Remove
*/
Self& operator-(int i);
/**
* Difference comparison operator.
*/
bool operator!=(const Self& it);
/**
* Equality comparison operator.
*/
bool operator==(const Self& it);
/**
* Instantiation operator.
*/
Self& operator=(const Self& it);
private:
// End
InternalIteratorType m_End;
// Internal iterator.
InternalIteratorType m_Iter;
// Input graph pointer
GraphPointerType m_Graph;
// Target vertex index
VertexDescriptorType m_VertexIndex;
};
} // End namespace otb
#ifndef OTB_MANUAL_INSTANTIATION
#include "otbRCC8InEdgeIterator.txx"
#endif
#endif
/*=========================================================================
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 _otbRCC8InEdgeIterator_txx
#define _otbRCC8InEdgeIterator_txx
#include "otbRCC8InEdgeIterator.h"
namespace otb
{
/** Constructor */
template <class TGraph>
RCC8InEdgeIterator<TGraph>
::RCC8InEdgeIterator()
{}
/**
* Copy operator.
*/
template <class TGraph>
RCC8InEdgeIterator<TGraph>
::RCC8InEdgeIterator(const Self& iter)
{
m_Iter=iter.m_Iter;
m_Graph=iter.m_Graph;
m_VertexIndex = iter.m_VertexIndex;
m_End=iter.m_End;
}
/**
*Constructor with input graph
*/
template <class TGraph>
RCC8InEdgeIterator<TGraph>
::RCC8InEdgeIterator(VertexDescriptorType vertex,TGraph * graph)
{
m_Graph=graph;
m_VertexIndex=vertex;
tie(m_Iter,m_End)=in_edges(vertex,*m_Graph->GetGraph());
}
/**
* Get the current edge value.
* \return The value of the current edge pointed by the iterator.
*/
template <class TGraph>
typename RCC8InEdgeIterator<TGraph>
::RCC8ValueType
RCC8InEdgeIterator<TGraph>
::GetValue(void)
{
return (*m_Graph->GetGraph())[*m_Iter]->GetValue();
}
/**
* Return the source vertex of the current edge.
* \return The source edge.
*/
template <class TGraph>
typename RCC8InEdgeIterator<TGraph>
::VertexPointerType
RCC8InEdgeIterator<TGraph>
::GetSourceVertex(void)
{
return (*m_Graph->GetGraph())[source(*m_Iter,(*m_Graph->GetGraph()))];
}
/**
* Return the source vertex index of the current edge.
* \return The souce vertex index.
*/
template <class TGraph>
typename RCC8InEdgeIterator<TGraph>
::VertexDescriptorType
RCC8InEdgeIterator<TGraph>
::GetSourceIndex(void)
{
IndexMapType index = get(boost::vertex_index, (*m_Graph->GetGraph()));
return index[source(*m_Iter,(*m_Graph->GetGraph()))];
}
/**
* Return true if the iterator is at the end.
* \return True if the iterator is at the end.
*/
template <class TGraph>
bool
RCC8InEdgeIterator<TGraph>
::IsAtEnd(void)
{
return (m_Iter==m_End);
}
/**
* Go to the beginning.
*/
template <class TGraph>
void
RCC8InEdgeIterator<TGraph>
::GoToBegin(void)
{
tie(m_Iter,m_End)=in_edges(m_VertexIndex,*m_Graph->GetGraph());
}
/**
* Increment.
*/
template <class TGraph>
typename RCC8InEdgeIterator<TGraph>
::Self&
RCC8InEdgeIterator<TGraph>
::operator++()
{
++m_Iter;
return *this;
}
/**
* Decrement.
*/
template <class TGraph>
typename RCC8InEdgeIterator<TGraph>
::Self&
RCC8InEdgeIterator<TGraph>
::operator--()
{
--m_Iter;
return *this;
}
/**
* Add
*/
template <class TGraph>
typename RCC8InEdgeIterator<TGraph>
::Self&
RCC8InEdgeIterator<TGraph>
::operator+(int i)
{
m_Iter=m_Iter+i;
return *this;
}
/**
* Remove
*/
template <class TGraph>
typename RCC8InEdgeIterator<TGraph>
::Self&
RCC8InEdgeIterator<TGraph>
::operator-(int i)
{
m_Iter=m_Iter-i;
return *this;
}
/**
* Difference comparison operator.
*/
template <class TGraph>
bool
RCC8InEdgeIterator<TGraph>
::operator!=(const Self& iter)
{
return (m_Iter != iter.m_Iter);
}
/**
* Equality comparison operator.
*/
template <class TGraph>
bool
RCC8InEdgeIterator<TGraph>
::operator==(const Self& iter)
{
return (m_Iter == iter.m_Iter);
}
/**
* Instantiation operator.
*/
template <class TGraph>
typename RCC8InEdgeIterator<TGraph>
::Self&
RCC8InEdgeIterator<TGraph>
::operator=(const Self& iter)
{
m_Iter = iter.m_Iter;
return *this;
}
} // End namespace otb
#endif
/*=========================================================================
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 _otbRCC8OutEdgeIterator_h
#define _otbRCC8OutEdgeIterator_h
#include "otbRCC8Graph.h"
namespace otb
{
/**
* \class EdgeIterator
* \brief Iterates on the graph out edges from a vertex.
*/
template <class TGraph>
class RCC8OutEdgeIterator
{
public:
/** self typedef */
typedef RCC8OutEdgeIterator Self;
/** Graph typedef */
typedef TGraph GraphType;
typedef typename GraphType::InternalGraphType InternalGraphType;
typedef typename GraphType::Pointer GraphPointerType;
typedef typename GraphType::EdgePointerType EdgePointerType;
typedef typename GraphType::VertexPointerType VertexPointerType;
typedef typename GraphType::VertexDescriptorType VertexDescriptorType;
typedef typename GraphType::RCC8ValueType RCC8ValueType;
/** typedef of the internal iterator */
typedef typename boost::graph_traits<InternalGraphType>::out_edge_iterator InternalIteratorType;
/** Typedef of the index map */
typedef typename boost::property_map<InternalGraphType, boost::vertex_index_t>::type IndexMapType;
/** Constructor */
RCC8OutEdgeIterator();
/** Copy constructor */
RCC8OutEdgeIterator(const Self& iter);
/** Constructor with input graph */
RCC8OutEdgeIterator(VertexDescriptorType vertex,TGraph * graph);
/**
* Get the current edge value.
* \return The value of the current edge pointed by the iterator.
*/
RCC8ValueType GetValue(void);
/**
* Return the target vertex of the current edge.
* \return The target vertex.
*/
VertexPointerType GetTargetVertex(void);
/**
* Return the target vertex index of the current edge.
* \return The target vertex index.
*/
VertexDescriptorType GetTargetIndex(void);
/**
* Return true if the iterator is at the end.
* \return True if the iterator is at the end.
*/
bool IsAtEnd(void);
/**
* Go to the beginning.
*/
void GoToBegin(void);
/**
* Increment.
*/
Self& operator++();
/**
* Decrement.
*/
Self& operator--();
/**
* Add
*/
Self& operator+(int i);
/**
* Remove
*/
Self& operator-(int i);
/**
* Difference comparison operator.
*/
bool operator!=(const Self& it);
/**
* Equality comparison operator.
*/
bool operator==(const Self& it);
/**
* Instantiation operator.
*/
Self& operator=(const Self& it);
private:
// End
InternalIteratorType m_End;
// Internal iterator.
InternalIteratorType m_Iter;
// Input graph pointer
GraphPointerType m_Graph;
// source vertex descriptor
VertexDescriptorType m_VertexIndex;
};
} // End namespace otb
#ifndef OTB_MANUAL_INSTANTIATION
#include "otbRCC8OutEdgeIterator.txx"
#endif
#endif
/*=========================================================================
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 _otbRCC8OutEdgeIterator_txx
#define _otbRCC8OutEdgeIterator_txx
#include "otbRCC8OutEdgeIterator.h"
namespace otb
{
/** Constructor */
template <class TGraph>
RCC8OutEdgeIterator<TGraph>
::RCC8OutEdgeIterator()
{}
/**
* Copy operator.
*/
template <class TGraph>
RCC8OutEdgeIterator<TGraph>
::RCC8OutEdgeIterator(const Self& iter)
{
m_Iter=iter.m_Iter;
m_Graph=iter.m_Graph;
m_VertexIndex = iter.m_VertexIndex;
m_End=iter.m_End;
}
/**
*Constructor with input graph
*/
template <class TGraph>
RCC8OutEdgeIterator<TGraph>
::RCC8OutEdgeIterator(VertexDescriptorType vertex,TGraph * graph)
{
m_Graph=graph;
m_VertexIndex = vertex;
tie(m_Iter,m_End)=out_edges(vertex,*m_Graph->GetGraph());
}
/**
* Get the current edge value.
* \return The value of the current edge pointed by the iterator.
*/
template <class TGraph>
typename RCC8OutEdgeIterator<TGraph>
::RCC8ValueType
RCC8OutEdgeIterator<TGraph>
::GetValue(void)
{
return (*m_Graph->GetGraph())[*m_Iter]->GetValue();
}
/**
* Return the target vertex of the current edge.
* \return The target vertex.
*/
template <class TGraph>
typename RCC8OutEdgeIterator<TGraph>
::VertexPointerType
RCC8OutEdgeIterator<TGraph>
::GetTargetVertex(void)
{
return (*m_Graph->GetGraph())[target(*m_Iter,(*m_Graph->GetGraph()))];
}
/**
* Return the target vertex index of the current edge.
* \return The target vertex index.
*/
template <class TGraph>
typename RCC8OutEdgeIterator<TGraph>
::VertexDescriptorType
RCC8OutEdgeIterator<TGraph>
::GetTargetIndex(void)
{
IndexMapType index = get(boost::vertex_index,(*m_Graph->GetGraph()));
return index[target(*m_Iter,(*m_Graph->GetGraph()))];
}
/**
* Return true if the iterator is at the end.
* \return True if the iterator is at the end.
*/
template <class TGraph>
bool
RCC8OutEdgeIterator<TGraph>
::IsAtEnd(void)
{
return (m_Iter==m_End);
}
/**
* Go to the beginning.
*/
template <class TGraph>
void
RCC8OutEdgeIterator<TGraph>
::GoToBegin(void)
{
tie(m_Iter,m_End)=out_edges(m_VertexIndex,*m_Graph->GetGraph());
}
/**
* Increment.
*/
template <class TGraph>
typename RCC8OutEdgeIterator<TGraph>
::Self&
RCC8OutEdgeIterator<TGraph>
::operator++()
{
++m_Iter;
return *this;
}
/**
* Decrement.
*/
template <class TGraph>
typename RCC8OutEdgeIterator<TGraph>
::Self&
RCC8OutEdgeIterator<TGraph>
::operator--()
{
--m_Iter;
return *this;
}
/**
* Add
*/
template <class TGraph>
typename RCC8OutEdgeIterator<TGraph>
::Self&
RCC8OutEdgeIterator<TGraph>
::operator+(int i)
{
m_Iter=m_Iter+i;
return *this;
}
/**
* Remove
*/
template <class TGraph>
typename RCC8OutEdgeIterator<TGraph>
::Self&
RCC8OutEdgeIterator<TGraph>
::operator-(int i)
{
m_Iter=m_Iter-i;
return *this;
}
/**
* Difference comparison operator.
*/
template <class TGraph>
bool
RCC8OutEdgeIterator<TGraph>
::operator!=(const Self& iter)
{
return (m_Iter != iter.m_Iter);
}
/**
* Equality comparison operator.
*/
template <class TGraph>
bool
RCC8OutEdgeIterator<TGraph>
::operator==(const Self& iter)
{
return (m_Iter == iter.m_Iter);
}
/**
* Instantiation operator.
*/
template <class TGraph>
typename RCC8OutEdgeIterator<TGraph>
::Self&
RCC8OutEdgeIterator<TGraph>
::operator=(const Self& iter)
{
m_Iter = iter.m_Iter;
return *this;
}
} // End namespace otb
#endif
......@@ -20,6 +20,8 @@ PURPOSE. See the above copyright notices for more information.
#include "otbRCC8VertexBase.h"
#include "otbRCC8VertexIterator.h"
#include "otbRCC8EdgeIterator.h"
#include "otbRCC8InEdgeIterator.h"
#include "otbRCC8OutEdgeIterator.h"
void fail(bool test, char * reason)
{
......@@ -41,6 +43,8 @@ int otbRCC8Graph(int argc, char* argv[])
typedef RCC8GraphType::EdgeType EdgeType;
typedef otb::RCC8VertexIterator<RCC8GraphType> VertexIteratorType;
typedef otb::RCC8EdgeIterator<RCC8GraphType> EdgeIteratorType;
typedef otb::RCC8InEdgeIterator<RCC8GraphType> InEdgeIteratorType;
typedef otb::RCC8OutEdgeIterator<RCC8GraphType> OutEdgeIteratorType;
// Instantiation
RCC8GraphType::Pointer rcc8Graph = RCC8GraphType::New();
......@@ -125,6 +129,34 @@ int otbRCC8Graph(int argc, char* argv[])
fail(true,"Edge iterator out of bound.");
}
}
// Adding vertices and edges to test the in and out iterators
VertexType::Pointer vertex4 = VertexType::New();
VertexType::Pointer vertex5 = VertexType::New();
vertex4->SetSegmentationImageIndex(3);
vertex4->SetObjectLabelInImage(3);
vertex5->SetSegmentationImageIndex(4);
vertex5->SetObjectLabelInImage(4);
rcc8Graph->SetVertex(3,vertex4);
rcc8Graph->SetVertex(4,vertex5);
rcc8Graph->AddEdge(3,1,otb::OTB_RCC8_NTPP);
rcc8Graph->AddEdge(1,4,otb::OTB_RCC8_PO);
// Testing the in edge iterator
int vertexIndex=1;
InEdgeIteratorType inEdgeIt(vertexIndex,rcc8Graph);
for(inEdgeIt.GoToBegin();!inEdgeIt.IsAtEnd();++inEdgeIt)
{
fail(!((inEdgeIt.GetSourceIndex()==0)||(inEdgeIt.GetSourceIndex()==3)),
"!((inEdgeIt.GetSourceIndex()==0)||(inEdgeIt.GetSourceIndex()==3))");
}
// Testing the out edge iterator
OutEdgeIteratorType outEdgeIt(vertexIndex,rcc8Graph);
for(outEdgeIt.GoToBegin();!outEdgeIt.IsAtEnd();++outEdgeIt)
{
fail(!((inEdgeIt.GetSourceIndex()==0)||(inEdgeIt.GetSourceIndex()==3)),
"!((inEdgeIt.GetSourceIndex()==2)||(inEdgeIt.GetSourceIndex()==4))");
}
}
catch( itk::ExceptionObject & err )
{
......
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