Medical Imaging Interaction Toolkit  2016.11.0
Medical Imaging Interaction Toolkit
mitkEndoDebug.h
Go to the documentation of this file.
1 /*===================================================================
2 
3 The Medical Imaging Interaction Toolkit (MITK)
4 
5 Copyright (c) German Cancer Research Center,
6 Division of Medical and Biological Informatics.
7 All rights reserved.
8 
9 This software is distributed WITHOUT ANY WARRANTY; without
10 even the implied warranty of MERCHANTABILITY or FITNESS FOR
11 A PARTICULAR PURPOSE.
12 
13 See LICENSE.txt or http://www.mitk.org for details.
14 
15 ===================================================================*/
16 #ifndef mitkEndoDebug_h
17 #define mitkEndoDebug_h
18 
19 #include <set>
20 #include <string>
21 #include <iostream>
22 #include <sstream>
23 #include <MitkCameraCalibrationExports.h>
24 
25 namespace mitk
26 {
30  struct EndoDebugData;
31 
36  struct MITKCAMERACALIBRATION_EXPORT EndoDebug
37  {
41  static EndoDebug& GetInstance();
42 
46  static std::string GetUniqueFileName(const std::string& dir, const std::string& ext="jpg" , const std::string &prefix="");
47 
51  void SetDebugEnabled(bool _DebugEnabled);
52 
56  bool GetDebugEnabled();
57 
61  void SetShowImagesInDebug(bool _ShowImagesInDebug);
62 
66  bool GetShowImagesInDebug();
67 
71  void SetShowImagesTimeOut(size_t _ShowImagesTimeOut);
72 
76  size_t GetShowImagesTimeOut();
77 
82  void SetDebugImagesOutputDirectory(const std::string& _DebugImagesOutputDirectory);
83 
87  std::string GetDebugImagesOutputDirectory() const;
88 
92  std::string GetFilenameWithoutExtension(const std::string& s);
93 
101  bool AddFileToDebug(const std::string& fileToDebug);
102 
106  void SetFilesToDebug(const std::set<std::string>& filesToDebug);
107 
111  std::set<std::string> GetFilesToDebug();
112 
118  bool AddSymbolToDebug(const std::string& symbolToDebug);
119 
123  void SetSymbolsToDebug(const std::set<std::string>& symbolsToDebug);
124 
128  std::set<std::string> GetSymbolsToDebug();
129 
133  bool DebugFile( const std::string& fileToDebug );
134 
138  bool DebugSymbol( const std::string& symbolToDebug );
143  bool Debug( const std::string& fileToDebug, const std::string& symbol="" );
147  void SetLogFile( const std::string& file );
151  void ShowMessage( const std::string& message );
155  EndoDebug();
159  virtual ~EndoDebug();
160 
161  private:
165  EndoDebugData* d;
166  };
167 }
168 
169 // DISABLE DEBUGGING FOR RELEASE MODE ON WINDOWS
170 #if (defined(WIN32) && !defined(_DEBUG)) || defined(NDEBUG)
171  #define endodebugmarker
172  #define endodebug(msg)
173  #define endodebugvar(var)
174  #define endodebugsymbol(var, mSymbol)
175  #define endodebugimg(imgVariableName)
176  #define endodebugbegin if( false ) {
177  #define endodebugend }
178  #define endoAssert(a) \
179  if(!(a)) { \
180  throw std::invalid_argument("FAILED: " #a); \
181  }
182 
183  #define endoAssertMsg(a, msg) \
184  if(!(a)) { \
185  throw std::invalid_argument( "FAILED: " #a ); \
186  }
187 
188  #define endodebugcode(code)
189  #define endoAssertCode(assertCode)
190 #else
191  #define endodebugmarker\
195  if( mitk::EndoDebug::GetInstance().Debug(__FILE__) ) \
196  { \
197  std::ostringstream ___ostringstream; \
198  ___ostringstream << mitk::EndoDebug::GetInstance().GetFilenameWithoutExtension(__FILE__) << ", " << __LINE__\
199  << ": " << __FUNCTION__ << std::endl;\
200  mitk::EndoDebug::GetInstance().ShowMessage( ___ostringstream.str() ); \
201  }
202 
206  #define endodebug(msg)\
207  if( mitk::EndoDebug::GetInstance().Debug(__FILE__) ) \
208  { \
209  std::ostringstream ___ostringstream; \
210  ___ostringstream << mitk::EndoDebug::GetInstance().GetFilenameWithoutExtension(__FILE__) << ", " << __LINE__\
211  << ": " << msg << std::endl;\
212  mitk::EndoDebug::GetInstance().ShowMessage( ___ostringstream.str() ); \
213  }
214 
218  #define endodebugvar(var)\
219  if( mitk::EndoDebug::GetInstance().Debug(__FILE__) ) \
220  { \
221  std::ostringstream ___ostringstream; \
222  ___ostringstream << mitk::EndoDebug::GetInstance().GetFilenameWithoutExtension(__FILE__) << ", " << __LINE__\
223  << ": " #var " = " << var << std::endl;\
224  mitk::EndoDebug::GetInstance().ShowMessage( ___ostringstream.str() ); \
225  }
226 
230  #define endodebugsymbol(var, mSymbol)\
231  if( mitk::EndoDebug::GetInstance().Debug(__FILE__, mSymbol) ) \
232  { \
233  std::ostringstream ___ostringstream; \
234  ___ostringstream << mitk::EndoDebug::GetInstance().GetFilenameWithoutExtension(__FILE__) << ", " << __LINE__\
235  << ": " #var " = " << var << std::endl;\
236  mitk::EndoDebug::GetInstance().ShowMessage( ___ostringstream.str() ); \
237  }
238 
243  #define endodebugimg(imgVariableName)\
244  if( mitk::EndoDebug::GetInstance().Debug(__FILE__) \
245  && mitk::EndoDebug::GetInstance().GetShowImagesInDebug() \
246  && (imgVariableName).cols > 0 && (imgVariableName).rows > 0 && (imgVariableName).data) \
247  { \
248  std::ostringstream ___ostringstream; \
249  ___ostringstream << mitk::EndoDebug::GetInstance().GetFilenameWithoutExtension(__FILE__) << ", " << __LINE__\
250  << ": Showing " #imgVariableName << std::endl; \
251  mitk::EndoDebug::GetInstance().ShowMessage( ___ostringstream.str() ); \
252  std::string outputFile = mitk::EndoDebug::GetInstance().GetDebugImagesOutputDirectory(); \
253  if( !outputFile.empty() ) \
254  {\
255  outputFile = mitk::EndoDebug::GetInstance().GetUniqueFileName(outputFile, "jpg", std::string(#imgVariableName) );\
256  cv::imwrite(outputFile, imgVariableName);\
257  }\
258  else\
259  {\
260  cv::imshow( "Debug", imgVariableName ); \
261  cv::waitKey( mitk::EndoDebug::GetInstance().GetShowImagesTimeOut() ); \
262  }\
263  }
264 
268  #define endodebugbegin \
269  if( mitk::EndoDebug::GetInstance().Debug(__FILE__) ) \
270  {
271 
275  #define endodebugend \
276  }
277 
278  #define endodebugcode(code) \
279  endodebugbegin \
280  code \
281  endodebugend
282 
286 #define endoAssert(a) \
287 if(!(a)) { \
288 std::ostringstream s; \
289 s << mitk::EndoDebug::GetInstance().GetFilenameWithoutExtension(__FILE__) << ", " \
290  << __LINE__ << ", failed: " << #a; \
291 throw std::invalid_argument(s.str()); }
292 
297 #define endoAssertMsg(a, msg) \
298 if(!(a)) { \
299  std::ostringstream s; \
300  s << mitk::EndoDebug::GetInstance().GetFilenameWithoutExtension(__FILE__) << ", " \
301  << __LINE__ << ": " << msg; \
302  throw std::invalid_argument(s.str()); \
303  }
304 
305 #define endoAssertCode(assertCode) \
306  assertCode
307 
308 #endif
309 
310 #endif // mitkEndoDebug_h
311 
312 
DataCollection - Class to facilitate loading/accessing structured data.