MITK-IGT
IGT Extension of MITK
Loading...
Searching...
No Matches
mitkEndoDebug.h
Go to the documentation of this file.
1/*============================================================================
2
3The Medical Imaging Interaction Toolkit (MITK)
4
5Copyright (c) German Cancer Research Center (DKFZ)
6All rights reserved.
7
8Use of this source code is governed by a 3-clause BSD license that can be
9found in the LICENSE file.
10
11============================================================================*/
12#ifndef mitkEndoDebug_h
13#define mitkEndoDebug_h
14
15#include <set>
16#include <string>
17#include <iostream>
18#include <sstream>
19#include <MitkCameraCalibrationExports.h>
20
21namespace mitk
22{
26 struct EndoDebugData;
27
32 struct MITKCAMERACALIBRATION_EXPORT EndoDebug
33 {
37 static EndoDebug& GetInstance();
38
42 static std::string GetUniqueFileName(const std::string& dir, const std::string& ext="jpg" , const std::string &prefix="");
43
47 void SetDebugEnabled(bool _DebugEnabled);
48
52 bool GetDebugEnabled();
53
57 void SetShowImagesInDebug(bool _ShowImagesInDebug);
58
62 bool GetShowImagesInDebug();
63
67 void SetShowImagesTimeOut(size_t _ShowImagesTimeOut);
68
72 size_t GetShowImagesTimeOut();
73
78 void SetDebugImagesOutputDirectory(const std::string& _DebugImagesOutputDirectory);
79
83 std::string GetDebugImagesOutputDirectory() const;
84
88 std::string GetFilenameWithoutExtension(const std::string& s);
89
97 bool AddFileToDebug(const std::string& fileToDebug);
98
102 void SetFilesToDebug(const std::set<std::string>& filesToDebug);
103
107 std::set<std::string> GetFilesToDebug();
108
114 bool AddSymbolToDebug(const std::string& symbolToDebug);
115
119 void SetSymbolsToDebug(const std::set<std::string>& symbolsToDebug);
120
124 std::set<std::string> GetSymbolsToDebug();
125
129 bool DebugFile( const std::string& fileToDebug );
130
134 bool DebugSymbol( const std::string& symbolToDebug );
139 bool Debug( const std::string& fileToDebug, const std::string& symbol="" );
143 void SetLogFile( const std::string& file );
147 void ShowMessage( const std::string& message );
151 EndoDebug();
155 virtual ~EndoDebug();
156
157 private:
161 EndoDebugData* d;
162 };
163}
164
165// DISABLE DEBUGGING FOR RELEASE MODE ON WINDOWS
166#if (defined(WIN32) && !defined(_DEBUG)) || defined(NDEBUG)
167 #define endodebugmarker
168 #define endodebug(msg)
169 #define endodebugvar(var)
170 #define endodebugsymbol(var, mSymbol)
171 #define endodebugimg(imgVariableName)
172 #define endodebugbegin if( false ) {
173 #define endodebugend }
174 #define endoAssert(a) \
175 if(!(a)) { \
176 throw std::invalid_argument("FAILED: " #a); \
177 }
178
179 #define endoAssertMsg(a, msg) \
180 if(!(a)) { \
181 throw std::invalid_argument( "FAILED: " #a ); \
182 }
183
184 #define endodebugcode(code)
185 #define endoAssertCode(assertCode)
186#else
190 #define endodebugmarker\
191 if( mitk::EndoDebug::GetInstance().Debug(__FILE__) ) \
192 { \
193 std::ostringstream ___ostringstream; \
194 ___ostringstream << mitk::EndoDebug::GetInstance().GetFilenameWithoutExtension(__FILE__) << ", " << __LINE__\
195 << ": " << __FUNCTION__ << std::endl;\
196 mitk::EndoDebug::GetInstance().ShowMessage( ___ostringstream.str() ); \
197 }
198
202 #define endodebug(msg)\
203 if( mitk::EndoDebug::GetInstance().Debug(__FILE__) ) \
204 { \
205 std::ostringstream ___ostringstream; \
206 ___ostringstream << mitk::EndoDebug::GetInstance().GetFilenameWithoutExtension(__FILE__) << ", " << __LINE__\
207 << ": " << msg << std::endl;\
208 mitk::EndoDebug::GetInstance().ShowMessage( ___ostringstream.str() ); \
209 }
210
214 #define endodebugvar(var)\
215 if( mitk::EndoDebug::GetInstance().Debug(__FILE__) ) \
216 { \
217 std::ostringstream ___ostringstream; \
218 ___ostringstream << mitk::EndoDebug::GetInstance().GetFilenameWithoutExtension(__FILE__) << ", " << __LINE__\
219 << ": " #var " = " << var << std::endl;\
220 mitk::EndoDebug::GetInstance().ShowMessage( ___ostringstream.str() ); \
221 }
222
226 #define endodebugsymbol(var, mSymbol)\
227 if( mitk::EndoDebug::GetInstance().Debug(__FILE__, mSymbol) ) \
228 { \
229 std::ostringstream ___ostringstream; \
230 ___ostringstream << mitk::EndoDebug::GetInstance().GetFilenameWithoutExtension(__FILE__) << ", " << __LINE__\
231 << ": " #var " = " << var << std::endl;\
232 mitk::EndoDebug::GetInstance().ShowMessage( ___ostringstream.str() ); \
233 }
234
239 #define endodebugimg(imgVariableName)\
240 if( mitk::EndoDebug::GetInstance().Debug(__FILE__) \
241 && mitk::EndoDebug::GetInstance().GetShowImagesInDebug() \
242 && (imgVariableName).cols > 0 && (imgVariableName).rows > 0 && (imgVariableName).data) \
243 { \
244 std::ostringstream ___ostringstream; \
245 ___ostringstream << mitk::EndoDebug::GetInstance().GetFilenameWithoutExtension(__FILE__) << ", " << __LINE__\
246 << ": Showing " #imgVariableName << std::endl; \
247 mitk::EndoDebug::GetInstance().ShowMessage( ___ostringstream.str() ); \
248 std::string outputFile = mitk::EndoDebug::GetInstance().GetDebugImagesOutputDirectory(); \
249 if( !outputFile.empty() ) \
250 {\
251 outputFile = mitk::EndoDebug::GetInstance().GetUniqueFileName(outputFile, "jpg", std::string(#imgVariableName) );\
252 cv::imwrite(outputFile, imgVariableName);\
253 }\
254 else\
255 {\
256 cv::imshow( "Debug", imgVariableName ); \
257 cv::waitKey( mitk::EndoDebug::GetInstance().GetShowImagesTimeOut() ); \
258 }\
259 }
260
264 #define endodebugbegin \
265 if( mitk::EndoDebug::GetInstance().Debug(__FILE__) ) \
266 {
267
271 #define endodebugend \
272 }
273
274 #define endodebugcode(code) \
275 endodebugbegin \
276 code \
277 endodebugend
278
282#define endoAssert(a) \
283if(!(a)) { \
284std::ostringstream s; \
285s << mitk::EndoDebug::GetInstance().GetFilenameWithoutExtension(__FILE__) << ", " \
286 << __LINE__ << ", failed: " << #a; \
287throw std::invalid_argument(s.str()); }
288
293#define endoAssertMsg(a, msg) \
294if(!(a)) { \
295 std::ostringstream s; \
296 s << mitk::EndoDebug::GetInstance().GetFilenameWithoutExtension(__FILE__) << ", " \
297 << __LINE__ << ": " << msg; \
298 throw std::invalid_argument(s.str()); \
299 }
300
301#define endoAssertCode(assertCode) \
302 assertCode
303
304#endif
305
306#endif
IGT Exceptions.