Commit 290e3108 authored by Guillaume Pasero's avatar Guillaume Pasero

ENH: resume implementation of OGRDataToClassStatisticsFilter, synthetise accumulators

parent e61381ed
......@@ -55,8 +55,8 @@ public:
typedef otb::ogr::DataSource OGRDataType;
typedef otb::ogr::DataSource::Pointer OGRDataPointer;
typedef std::map<std::string, unsigned long> ClassCountMapType;
typedef std::map<unsigned long, unsigned long> PolygonSizeMapType;
typedef otb::PolygonClassStatisticsAccumulator::ClassCountMapType ClassCountMapType;
typedef otb::PolygonClassStatisticsAccumulator::PolygonSizeMapType PolygonSizeMapType;
/** Wrap output type as DataObject */
typedef itk::SimpleDataObjectDecorator<ClassCountMapType> ClassCountObjectType;
......@@ -154,9 +154,11 @@ public:
typedef TMaskImage MaskImageType;
typedef otb::ogr::DataSource OGRDataType;
typedef typename Superclass::FilterType FilterType;
typedef typename FilterType::ClassCountObjectType ClassCountObjectType;
typedef typename FilterType::PolygonSizeObjectType PolygonSizeObjectType;
typedef typename Superclass::FilterType FilterType;
typedef typename FilterType::ClassCountMapType ClassCountMapType;
typedef typename FilterType::PolygonSizeMapType PolygonSizeMapType;
typedef typename FilterType::ClassCountObjectType ClassCountObjectType;
typedef typename FilterType::PolygonSizeObjectType PolygonSizeObjectType;
/** Type macro */
itkNewMacro(Self);
......
......@@ -22,7 +22,7 @@
namespace otb
{
// Members from otb::PersistentOGRDataToClassStatisticsFilter
// --------- otb::PersistentOGRDataToClassStatisticsFilter ---------------------
template<class TInputImage, class TMaskImage>
PersistentOGRDataToClassStatisticsFilter<TInputImage,TMaskImage>
......@@ -79,7 +79,40 @@ PersistentOGRDataToClassStatisticsFilter<TInputImage,TMaskImage>
otb::ogr::DataSource* vectors = const_cast<otb::ogr::DataSource*>(this->GetOGRData());
vectors->GetLayer(m_layerIndex).SetSpatialFilter(NULL);
ClassCountMapType &classCount = this->GetClassCountOutput()->Get();
PolygonSizeMapType &polygonSize = this->GetPolygonSizeOutput()->Get();
// Reset outputs
classCount.clear();
polygonSize.clear();
std::vector<PolygonClassStatisticsAccumulator::Pointer>::iterator it = m_TemporaryStats.begin();
for (; it != m_TemporaryStats.end(); it++)
{
const ClassCountMapType &tempClassCount = (*it)->GetClassCountMap();
const PolygonSizeMapType &tempPolygonSize = (*it)->GetPolygonSizeMap();
ClassCountMapType::const_iterator itClass = tempClassCount.begin();
for (; itClass != tempClassCount.end(); itClass++)
{
if (classCount.count(itClass->first) == 0)
{
classCount[itClass->first] = 0UL;
}
classCount[itClass->first] += itClass->second;
}
PolygonSizeMapType::const_iterator itPoly = tempPolygonSize.begin();
for (; itPoly != tempPolygonSize.end() ; itPoly++)
{
if (polygonSize.count(itPoly->first) == 0)
{
polygonSize[itPoly->first] = 0UL;
}
polygonSize[itPoly->first] += itPoly->second;
}
}
// TODO : gather stats
}
......@@ -336,7 +369,7 @@ PersistentOGRDataToClassStatisticsFilter<TInputImage,TMaskImage>
return region;
}
// Members from otb::OGRDataToClassStatisticsFilter
// -------------- otb::OGRDataToClassStatisticsFilter --------------------------
template<class TInputImage, class TMaskImage>
void
......
......@@ -36,6 +36,9 @@ public:
typedef itk::SmartPointer<Self> Pointer;
itkNewMacro(Self);
typedef std::map<std::string, unsigned long> ClassCountMapType;
typedef std::map<unsigned long, unsigned long> PolygonSizeMapType;
/** Runtime information support. */
itkTypeMacro(PolygonClassStatisticsAccumulator, itk::Object);
......@@ -45,6 +48,12 @@ public:
/** Reset the accumulator */
void Reset();
const ClassCountMapType& GetClassCountMap();
const PolygonSizeMapType& GetPolygonSizeMap();
unsigned long GetNumberOfPixels();
itkSetMacro(FieldIndex, int);
itkGetMacro(FieldIndex, int);
......@@ -59,9 +68,9 @@ private:
//Number of pixels in all the polygons
unsigned long m_NbPixelsGlobal;
//Number of pixels in each classes
std::map<std::string, unsigned long> m_ElmtsInClass;
ClassCountMapType m_ElmtsInClass;
//Number of pixels in each polygons
std::map<unsigned long, unsigned long> m_Polygon; // check the feature id
PolygonSizeMapType m_Polygon; // check the feature id
int m_FieldIndex;
......
......@@ -165,5 +165,26 @@ PolygonClassStatisticsAccumulator
m_Polygon.clear();
}
const PolygonClassStatisticsAccumulator::ClassCountMapType&
PolygonClassStatisticsAccumulator
::GetClassCountMap()
{
return m_ElmtsInClass;
}
const PolygonClassStatisticsAccumulator::PolygonSizeMapType&
PolygonClassStatisticsAccumulator
::GetPolygonSizeMap()
{
return m_Polygon;
}
unsigned long
PolygonClassStatisticsAccumulator
::GetNumberOfPixels()
{
return m_NbPixelsGlobal;
}
} // end of namespace otb
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