21 #ifndef otbContingencyTable_h
22 #define otbContingencyTable_h
26 #include <itkObject.h>
27 #include <itkObjectFactory.h>
28 #include <itkVariableSizeMatrix.h>
33 template <
class TClassLabel>
49 typedef itk::VariableSizeMatrix<unsigned long>
MatrixType;
58 unsigned int rows =
static_cast<unsigned int>(
m_RefLabels.size());
59 unsigned int cols =
static_cast<unsigned int>(
m_ProdLabels.size());
60 matrix.SetSize(rows, cols);
72 for (
unsigned int i = 0; i < contingencyTable.
matrix.Rows(); ++i)
74 for (
unsigned int j = 0; j < contingencyTable.
matrix.Cols(); ++j)
76 std::ostringstream oss;
77 oss << contingencyTable.
matrix(i, j);
78 size_t length = oss.str().length();
79 if (length > maxWidth)
84 int width =
static_cast<int>(maxWidth) + 1;
87 o << std::setfill(
' ') << std::setw(width) <<
"labels";
88 for (
size_t i = 0; i < contingencyTable.
m_ProdLabels.size(); ++i)
90 o << std::setfill(
' ') << std::setw(width) << contingencyTable.
m_ProdLabels[i];
95 for (
unsigned int i = 0; i < contingencyTable.
matrix.Rows(); ++i)
97 o << std::setfill(
' ') << std::setw(width) << contingencyTable.
m_RefLabels[i];
98 for (
unsigned int j = 0; j < contingencyTable.
matrix.Cols(); ++j)
100 o << std::setfill(
' ') << std::setw(width) << contingencyTable.
matrix(i, j);
110 const char separator =
',';
112 std::ostringstream oss;
121 for (
unsigned int i = 0; i <
matrix.Rows(); ++i)
124 for (
unsigned int j = 0; j <
matrix.Cols(); ++j)
126 oss << separator <<
matrix(i, j);
143 void PrintSelf(std::ostream& os, itk::Indent itkNotUsed(indent))
const override
154 size_t tmpMaxWidth = maxWidth;
155 for (
size_t i = 0; i < labels.size(); ++i)
157 std::ostringstream oss;
159 size_t length = oss.str().length();
160 if (length > tmpMaxWidth)
161 tmpMaxWidth = length;
171 #endif // otbContingencyTable_h