8 #include <opencv2/opencv.hpp>
11 #include "complexmat.cuh"
13 #include "complexmat.hpp"
20 std::ios::fmtflags flags;
21 std::streamsize precision;
24 IOSave( std::ios& userStream )
25 : stream( userStream )
26 , flags( userStream.flags() )
27 , precision( userStream.precision() )
28 , fill( userStream.fill() )
33 stream.flags( flags );
34 stream.precision( precision );
45 std::string indent() { return std::string(indentLvl * 4, ' '); }
52 FTrace(DbgTracer &dt, const char *fn, const char *format, ...) : t(dt), funcName(fn)
58 if (-1 == vasprintf(&arg, format, vl))
59 throw std::runtime_error("vasprintf error");
62 std::cerr << t.indent() << funcName << "(" << arg << ") {" << std::endl;
69 std::cerr << t.indent() << "}" << std::endl;
74 void traceVal(const char *name, const T& obj, int line, bool always = false)
78 std::cerr << indent() << name /*<< " @" << line */ << " " << print(obj) << std::endl;
81 template <typename T> struct Printer {
83 Printer(const T &_obj) : obj(_obj) {}
86 template <typename T> Printer<T> print(const T& obj) { return Printer<T>(obj); }
87 Printer<cv::Mat> print(const MatScales& obj) { return Printer<cv::Mat>(obj); }
88 Printer<cv::Mat> print(const MatFeats& obj) { return Printer<cv::Mat>(obj); }
89 Printer<cv::Mat> print(const MatScaleFeats& obj) { return Printer<cv::Mat>(obj); }
93 std::ostream &operator<<(std::ostream &os, const DbgTracer::Printer<T> &p)
99 #if CV_MAJOR_VERSION == 3 && CV_MINOR_VERSION < 3
100 static inline std::ostream &operator<<(std::ostream &out, const cv::MatSize &msize)
102 int i, dims = msize.p[-1];
103 for (i = 0; i < dims; i++) {
112 std::ostream &operator<<(std::ostream &os, const DbgTracer::Printer<cv::Mat> &p);
115 static inline std::ostream &operator<<(std::ostream &os, const cufftComplex &p)
122 std::ostream &operator<<(std::ostream &os, const DbgTracer::Printer<ComplexMat> &p);
124 extern DbgTracer __dbgTracer;
126 #define TRACE(...) const DbgTracer::FTrace __tracer(__dbgTracer, __PRETTY_FUNCTION__, ##__VA_ARGS__)
128 #define DEBUG_PRINT(obj) __dbgTracer.traceVal(#obj, (obj), __LINE__)
129 #define DEBUG_PRINTM(obj) DEBUG_PRINT(obj)
130 #define PRINT(obj) __dbgTracer.traceVal(#obj, (obj), __LINE__, true)