Commit b62fce49 authored by Julien Malik's avatar Julien Malik

COMP: fix namespace issues in MassOfBelief::PrintSelf. overloading operator...

COMP: fix namespace issues in MassOfBelief::PrintSelf. overloading operator for STL types is to be avoided
parent 3d69feab
......@@ -26,8 +26,10 @@
#include <map>
#include <ostream>
namespace otb
{
/** \class MassOfBelief
* \brief This class represent a mass of belief function
*
......@@ -156,6 +158,18 @@ public:
/** Return true if the support set is null */
bool IsEmpty() const;
/** Define a Print static method for label sets
* Do not overload << for std::set since it causes
* namespace issues. */
static std::ostream & PrintLabelSet(std::ostream & out,
const LabelSetType & labelSet);
/** Define a Print static method for label sets
* Do not overload << for std::set since it causes
* namespace issues. */
static std::ostream & PrintLabelSetOfSet(std::ostream & out,
const LabelSetOfSetType & labelSet);
protected:
/** Constructor */
MassOfBelief() {}
......@@ -176,11 +190,6 @@ private:
} // end namespace otb
/** Define the << operator for label sets */
template <class TLabel>
std::ostream &
operator<<(std::ostream & out,
const std::set<TLabel> & labelSet);
#ifndef OTB_MANUAL_INSTANTIATION
#include "otbMassOfBelief.txx"
......
......@@ -373,29 +373,33 @@ MassOfBelief<TLabel, TMass>
Superclass::PrintSelf(os, indent);
// Display mass of belief universe
os<<indent<<"Mass of belief universe: "<<this->GetUniverse()<<std::endl;
os << indent << "Mass of belief universe: "
<< PrintLabelSet(os, this->GetUniverse())
<< std::endl;
// Display mass of belief support
os<<indent<<"Mass of belief support: "<<this->GetSupport()<<std::endl;
os<<indent<<"Mass of belief support: "
<<PrintLabelSetOfSet(os, this->GetSupport())
<<std::endl;
// Display individual masses
for(typename MassMapType::const_iterator it = m_MassesMap.begin();
it!=m_MassesMap.end(); ++it)
{
os<<indent<<(it->first)<< " has mass "<<(it->second)<<std::endl;
os<< indent
<< PrintLabelSet(os, it->first)
<< " has mass "<<(it->second)<<std::endl;
}
os<<indent<<"Other masses are null"<<std::endl;
}
} // end namespace otb
/** Define the << operator for label sets */
template <class TLabel>
template <class TLabel, class TMass>
std::ostream &
operator<<(std::ostream & out,
const std::set<TLabel> & labelSet)
MassOfBelief<TLabel, TMass>
::PrintLabelSet(std::ostream & out,
const LabelSetType & labelSet)
{
// Define an iterator on the label set
typedef std::set<TLabel> LabelSetType;
typename LabelSetType::const_iterator it = labelSet.begin();
// Open the set
......@@ -409,7 +413,36 @@ operator<<(std::ostream & out,
if(it != labelSet.end())
out<<", ";
}
// close the set
out<<"}";
// Return
return out;
}
template <class TLabel, class TMass>
std::ostream &
MassOfBelief<TLabel, TMass>
::PrintLabelSetOfSet(std::ostream & out,
const LabelSetOfSetType & labelSet)
{
// Define an iterator on the label set
typedef std::set<TLabel> LabelSetType;
typename LabelSetOfSetType::const_iterator it = labelSet.begin();
// Open the set
out<<"{";
// Append the set elements
while(it != labelSet.end())
{
PrintLabelSet(out, *it);
++it;
if(it != labelSet.end())
out<<", ";
}
// close the set
out<<"}";
......@@ -417,4 +450,16 @@ operator<<(std::ostream & out,
return out;
}
} // end namespace otb
/** Define the << operator for label sets */
/*
template <class TLabel>
std::ostream &
operator<<(std::ostream & out,
const std::set<TLabel> & labelSet)*/
#endif
......@@ -120,7 +120,7 @@ otbJointMassOfBeliefFilter.cxx
SET(BasicFuzzy_SRCS2
otbFuzzyVariableDSApplied.cxx
otbMassOfBeliefDSApplied.cxx
#otbVectorDataToDSValidatedVectorDataFilter.cxx
otbVectorDataToDSValidatedVectorDataFilter.cxx
otbVectorDataToSpecificDescriptionFilterBase.cxx
otbVectorDataToRoadDescriptionFilter.cxx
)
......
......@@ -29,8 +29,8 @@ void RegisterTests()
{
REGISTER_TEST(otbFuzzyVariableDSApplied);
REGISTER_TEST(otbMassOfBeliefDSApplied);
//REGISTER_TEST(otbVectorDataToDSValidatedVectorDataFilterNew);
//REGISTER_TEST(otbVectorDataToDSValidatedVectorDataFilter);
REGISTER_TEST(otbVectorDataToDSValidatedVectorDataFilterNew);
REGISTER_TEST(otbVectorDataToDSValidatedVectorDataFilter);
REGISTER_TEST(otbVectorDataToSpecificDescriptionFilterBaseNew);
REGISTER_TEST(otbVectorDataToRoadDescriptionFilterNew);
REGISTER_TEST(otbVectorDataToRoadDescriptionFilter);
......
......@@ -21,10 +21,16 @@
#include "otbMassOfBelief.h"
int otbMassOfBelief(int argc, char* argv[])
typedef otb::MassOfBelief<std::string> MassOfBeliefFunctionType;
std::ostream& operator <<(std::ostream& os, const MassOfBeliefFunctionType::LabelSetType& l )
{
typedef otb::MassOfBelief<std::string> MassOfBeliefFunctionType;
MassOfBeliefFunctionType::PrintLabelSet(os, l);
return os;
}
int otbMassOfBelief(int argc, char* argv[])
{
// Instantiate function
MassOfBeliefFunctionType::Pointer massFunction = MassOfBeliefFunctionType::New();
......
......@@ -24,6 +24,20 @@
#include "otbFuzzyVariable.h"
#include "otbJointMassOfBeliefFilter.h"
typedef float PrecisionType;
typedef otb::FuzzyVariable<std::string, PrecisionType>
FuzzyVarType;
typedef otb::MassOfBelief<std::string> MassOfBeliefFunctionType;
typedef otb::JointMassOfBeliefFilter<MassOfBeliefFunctionType>
JointMassOfBeliefFilterType;
std::ostream& operator <<(std::ostream& os, const MassOfBeliefFunctionType::LabelSetType& l )
{
MassOfBeliefFunctionType::PrintLabelSet(os, l);
return os;
}
int otbMassOfBeliefDSApplied(int argc, char* argv[])
{
const char * hyp_1 = argv[1];
......@@ -31,12 +45,6 @@ int otbMassOfBeliefDSApplied(int argc, char* argv[])
double desc1Val = atof(argv[3]);
double desc2Val = atof(argv[4]);
typedef float PrecisionType;
typedef otb::FuzzyVariable<std::string, PrecisionType>
FuzzyVarType;
typedef otb::MassOfBelief<std::string> MassOfBeliefFunctionType;
typedef otb::JointMassOfBeliefFilter<MassOfBeliefFunctionType>
JointMassOfBeliefFilterType;
// Descriptors and associated fuzzy variables
FuzzyVarType::Pointer desc1 = FuzzyVarType::New();
......
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