21 #ifndef mvdAlgorithm_h 22 #define mvdAlgorithm_h 27 #include "ConfigureMonteverdi.h" 29 #include "OTBMonteverdiCoreExport.h" 45 #include "itkFixedArray.h" 46 #include "itkExceptionObject.h" 47 #include "itkVariableLengthVector.h" 91 template <
typename T2,
unsigned int N,
typename T1>
92 inline itk::FixedArray<T2, N>
ToFixedArray(
const itk::VariableLengthVector<T1>& v);
106 template <
typename T2,
unsigned int N,
typename T1>
107 inline itk::FixedArray<T2, N>&
ToFixedArray(itk::FixedArray<T2, N>& a,
const itk::VariableLengthVector<T1>& v);
118 template <
typename T2,
typename T1,
unsigned int N>
130 template <
typename T2,
typename T1,
unsigned int N>
131 inline itk::VariableLengthVector<T2>&
ToVariableLengthVector(itk::FixedArray<T1, N>& a,
const itk::VariableLengthVector<T1>& v);
146 template <
typename T>
147 inline QTextStream& operator<<(QTextStream& stream, const itk::VariableLengthVector<T>& vector);
157 template <
typename T>
158 inline QTextStream&
operator>>(QTextStream& stream, itk::VariableLengthVector<T>& vector);
168 template <
typename T>
169 inline QDataStream& operator<<(QDataStream& stream, const itk::VariableLengthVector<T>& vector);
179 template <
typename T>
180 inline QDataStream&
operator>>(QDataStream& stream, itk::VariableLengthVector<T>& vector);
230 inline std::string
ToStdString(
const QString& str);
234 inline const char*
ToString(
const QString& str);
248 template <
typename T>
249 std::string
ToStdString(
const std::vector<T>& vec);
253 template <
typename T>
286 template <
typename TInputIterator,
typename TUnaryPredicate>
287 inline bool AllOf(TInputIterator first, TInputIterator last, TUnaryPredicate pred);
299 template <
typename TInputIterator,
typename TUnaryPredicate>
300 inline bool AnyOf(TInputIterator first, TInputIterator last, TUnaryPredicate pred);
311 template <
typename TInputIterator,
typename TUnaryPredicate>
312 inline bool NoneOf(TInputIterator first, TInputIterator last, TUnaryPredicate pred);
322 template <
typename T2,
unsigned int N,
typename T1>
323 inline itk::FixedArray<T2, N>
ToFixedArray(
const itk::VariableLengthVector<T1>& v)
325 assert(v.Size() == N);
327 throw itk::RangeError(__FILE__, __LINE__);
329 itk::FixedArray<T2, N> a;
331 for (
unsigned int i = 0; i < N; ++i)
332 a[i] = static_cast<T2>(v[i]);
338 template <
typename T2,
unsigned int N,
typename T1>
339 inline itk::FixedArray<T2, N>&
ToFixedArray(itk::FixedArray<T2, N>& a,
const itk::VariableLengthVector<T1>& v)
341 assert(v.Size() == N && v.Size() == a.Size());
343 throw itk::RangeError(__FILE__, __LINE__);
345 for (
unsigned int i = 0; i < N; ++i)
346 a[i] = static_cast<T2>(v[i]);
352 template <
typename T2,
typename T1,
unsigned int N>
355 assert(a.Size() == N);
357 throw itk::RangeError(__FILE__, __LINE__);
359 itk::VariableLengthVector<T2> v;
363 for (
unsigned int i = 0; i < N; ++i)
364 v[i] = static_cast<T2>(a[i]);
370 template <
typename T2,
typename T1,
unsigned int N>
371 inline itk::VariableLengthVector<T2>&
ToVariableLengthVector(itk::VariableLengthVector<T2>& v,
const itk::FixedArray<T1, N>& a)
373 assert(a.Size() == N);
375 throw itk::RangeError(__FILE__, __LINE__);
379 for (
unsigned int i = 0; i < N; ++i)
380 v[i] = static_cast<T2>(a[i]);
401 for (StringVector::const_iterator it(sv.begin()); it != sv.end(); ++it)
403 qsl.append(QString(it->c_str()));
413 return std::string(str.toLocal8Bit().constData());
419 return str.toLocal8Bit().constData();
425 return QString(str.c_str());
431 return std::string(str.toLatin1().constData());
437 return str.toLatin1().constData();
443 std::ostringstream oss;
452 std::ostringstream oss;
453 oss << spacing[0] <<
" , " << spacing[1];
461 std::ostringstream oss;
462 oss << size[0] <<
" , " << size[1];
470 std::ostringstream oss;
471 oss << point[0] <<
" , " << point[1];
477 template <
typename T>
480 std::ostringstream oss;
481 typename std::vector<T>::const_iterator it = vec.begin();
482 while (it != vec.end())
493 template <
typename T>
496 return QString(
"%1").arg(val);
503 assert(!std::isnan(val));
508 QString valf = QString(
"%1").arg(val, 0,
'g', 9);
512 <<
"ToString< float >(" << val <<
"): " 519 if (valf.toFloat() != val)
520 throw std::runtime_error(
521 ToStdString(QCoreApplication::translate(
"mvd::DatasetDescritor",
"Accuracy loss when converting float (%1) to string.").arg(valf)));
530 assert(!std::isnan(val));
535 QString vald = QString(
"%1").arg(val, 0,
'g', 17);
540 <<
"ToString< double >(" << val <<
"): " 547 if (vald.toDouble() != val)
548 throw std::runtime_error(
549 ToStdString(QCoreApplication::translate(
"mvd::DatasetDescriptor",
"Accuracy loss when converting double (%1) to string.").arg(vald)));
560 template <
typename TInputIterator,
typename TUnaryPredicate>
561 inline bool AllOf(TInputIterator first, TInputIterator last, TUnaryPredicate pred)
563 while (first != last)
575 template <
typename TInputIterator,
typename TUnaryPredicate>
576 inline bool AnyOf(TInputIterator first, TInputIterator last, TUnaryPredicate pred)
578 while (first != last)
590 template <
typename TInputIterator,
typename TUnaryPredicate>
591 inline bool NoneOf(TInputIterator first, TInputIterator last, TUnaryPredicate pred)
593 while (first != last)
607 double thousand = isInBits ? 1024.0 : 1000.0;
609 double remainder =
static_cast<double>(size);
612 return QString::number(size);
614 remainder /= thousand;
616 if (remainder < thousand)
617 return QString(
"%1 KiB").arg(QString::number(remainder,
'g', 3));
619 remainder /= thousand;
621 if (remainder < thousand)
622 return QString(
"%1 MiB").arg(QString::number(remainder,
'g', 3));
624 remainder /= thousand;
626 if (remainder < thousand)
627 return QString(
"%1 GiB").arg(QString::number(remainder,
'g', 3));
629 remainder /= thousand;
631 return QString(
"%1 TiB").arg(QString::number(remainder,
'g', 3));
637 #endif // mvdAlgorithm_h itk::Size< Monteverdi_DIMENSION > SizeType
itk::FixedArray< T2, N > & ToFixedArray(itk::FixedArray< T2, N > &a, const itk::VariableLengthVector< T1 > &v)
itk::VariableLengthVector< T2 > & ToVariableLengthVector(itk::VariableLengthVector< T2 > &v, const itk::FixedArray< T1, N > &a)
std::vector< std::string > StringVector
QStringList ToQStringList(const StringVector &sv)
Convert a StringVector object to a QStringList object.
std::string ToStdString(const QString &str)
Convert and copy a QString to a STL std::string.
QStringList & AppendToQStringList(QStringList &qsl, const StringVector &sv)
Append the content of a StringVector object to the content of a QStringList object.
const char * ToLocalString(const QString &)
Append the content of a StringVector object to the content of a QStringList object.
bool NoneOf(TInputIterator first, TInputIterator last, TUnaryPredicate pred)
Test if no element in range fulfills condition.
std::string ToLocalStdString(const QString &)
Append the content of a StringVector object to the content of a QStringList object.
QTextStream & operator>>(QTextStream &stream, itk::VariableLengthVector< T > &vector)
Write an itk::VariableLengthVector< T > into a QTextStream.
bool AnyOf(TInputIterator first, TInputIterator last, TUnaryPredicate pred)
Test if any of element in range fulfills condition.
const char * ToString(const QString &str)
Append the content of a StringVector object to the content of a QStringList object.
The "otb" namespace contains all Orfeo Toolbox (OTB) classes.
QString FromStdString(const std::string &str)
Convert and copy an STL std::string to a QString.
QString ToQString< double >(const double &)
QString ToQString< float >(const float &)
QString ToQString(const T &val)
bool AllOf(TInputIterator first, TInputIterator last, TUnaryPredicate pred)
Test condition on all elements in range.
QString ToHumanReadableSize(qint64 fize, bool isInBits=true)
VectorImageType::SpacingType SpacingType
VectorImageType::PointType PointType