Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
What's new
10
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Open sidebar
Main Repositories
otb
Commits
0adc3c81
Commit
0adc3c81
authored
Mar 07, 2016
by
Guillaume Pasero
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
ENH: support map in StatisticsXMLFileWriter
parent
1fd3fa1a
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
77 additions
and
4 deletions
+77
-4
Modules/IO/IOXML/include/otbStatisticsXMLFileWriter.h
Modules/IO/IOXML/include/otbStatisticsXMLFileWriter.h
+8
-0
Modules/IO/IOXML/include/otbStatisticsXMLFileWriter.txx
Modules/IO/IOXML/include/otbStatisticsXMLFileWriter.txx
+69
-4
No files found.
Modules/IO/IOXML/include/otbStatisticsXMLFileWriter.h
View file @
0adc3c81
...
...
@@ -60,9 +60,15 @@ public:
/** Convenient typedef */
typedef
std
::
pair
<
std
::
string
,
MeasurementVectorType
>
InputDataType
;
typedef
std
::
vector
<
InputDataType
>
MeasurementVectorContainer
;
typedef
std
::
map
<
std
::
string
,
std
::
string
>
GenericMapType
;
typedef
std
::
map
<
std
::
string
,
GenericMapType
>
GenericMapContainer
;
/** Method to set/get the input list sample */
void
AddInput
(
const
char
*
name
,
const
MeasurementVectorType
&
inputVector
);
template
<
typename
MapType
>
void
AddInputMap
(
const
char
*
name
,
const
MapType
&
map
);
/** Trigger the processing */
void
Update
()
...
...
@@ -88,6 +94,8 @@ private:
std
::
string
m_FileName
;
MeasurementVectorContainer
m_MeasurementVectorContainer
;
GenericMapContainer
m_GenericMapContainer
;
};
// end of class StatisticsXMLFileWriter
...
...
Modules/IO/IOXML/include/otbStatisticsXMLFileWriter.txx
View file @
0adc3c81
...
...
@@ -60,8 +60,8 @@ StatisticsXMLFileWriter<TMeasurementVector>
::GenerateData()
{
// Check if the input are not null
if(m_MeasurementVectorContainer.size() == 0)
itkExceptionMacro(<<"At
L
east one input is required, please set input using the method AddInput");
if(m_MeasurementVectorContainer.size() ==
0 && m_GenericMapContainer.size() ==
0)
itkExceptionMacro(<<"At
l
east one input is required, please set input using the method
s
AddInput
or AddInputMap
");
// Check if the filename is not empty
if(m_FileName.empty())
...
...
@@ -80,8 +80,12 @@ StatisticsXMLFileWriter<TMeasurementVector>
TiXmlDeclaration* decl = new TiXmlDeclaration( "1.0", "", "" );
doc.LinkEndChild( decl );
TiXmlElement * root = new TiXmlElement( "FeatureStatistics");
doc.LinkEndChild( root );
TiXmlElement * root = NULL;
if (m_MeasurementVectorContainer.size())
{
root = new TiXmlElement( "FeatureStatistics");
doc.LinkEndChild( root );
}
// Iterate through the input
for (unsigned int i = 0; i < m_MeasurementVectorContainer.size(); ++i)
...
...
@@ -103,6 +107,39 @@ StatisticsXMLFileWriter<TMeasurementVector>
feature->LinkEndChild(curStatisticVector);
}
}
// Iterate on map containers
TiXmlElement * mapRoot = NULL;
if (m_GenericMapContainer.size())
{
mapRoot = new TiXmlElement( "GeneralStatistics");
doc.LinkEndChild( mapRoot );
}
std::string keyAttr("key");
std::string valAttr("value");
GenericMapContainer::const_iterator containerIt;
for ( containerIt = m_GenericMapContainer.begin() ; containerIt != m_GenericMapContainer.end() ; ++containerIt)
{
std::string mapName = containerIt->first;
GenericMapType::const_iterator mapIter;
// The current statistic
TiXmlElement * feature = new TiXmlElement("Statistic");
feature->SetAttribute("name", mapName.c_str());
mapRoot->LinkEndChild( feature );
// Store the value for this statistic
for( mapIter = containerIt->second.begin() ; mapIter != containerIt->second.end() ; ++mapIter )
{
// For each value in Measurementvector
TiXmlElement * curStatisticMap = new TiXmlElement("StatisticMap");
curStatisticMap->SetAttribute(keyAttr , mapIter->first);
curStatisticMap->SetAttribute(valAttr, mapIter->second);
feature->LinkEndChild(curStatisticMap);
}
}
// Finally, write the file
if (! doc.SaveFile( m_FileName.c_str() ) )
...
...
@@ -114,6 +151,34 @@ StatisticsXMLFileWriter<TMeasurementVector>
}
template < class TMeasurementVector >
template <typename MapType>
void
StatisticsXMLFileWriter<TMeasurementVector>
::AddInputMap(const char * name, const MapType& map )
{
std::string token(name);
if(m_GenericMapContainer.count(token) > 0)
{
itkExceptionMacro(<<"Token selected ("
<<name<<") is already added to the XML file");
}
typename MapType::const_iterator it;
GenericMapType insideMap;
std::ostringstream oss;
std::ostringstream ossKey;
for ( it = map.begin() ; it != map.end() ; ++it)
{
oss.str(std::string(""));
oss << it->second;
ossKey.str(std::string(""));
ossKey << it->first;
insideMap[ossKey.str()] = oss.str();
}
m_GenericMapContainer[token] = insideMap;
}
template < class TMeasurementVector >
void
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment