C++ 1-Liner: round() your numbers

C++, Programming No Comments »

You know what really hurts? A missing round() function if you really need it. Here is a code snippet for all of those with the same problem.

  1. template <class T>
  2. inline T round(float num)
  3. {
  4.    return static_cast<T>((num>0.0f) ? num+0.5f : num-0.5f);
  5. }

Multiline Macro Compilation Errors

C++, Programming No Comments »

Sometimes you just need to write macros in your C/C++ code. And sometimes, they get long and you want to split them on multiple lines for reasons of readibility.

I admit, that I only seldomly use multiline macros. But today something new came to my mind. I created a simple multiline macro, e.g. something similar to this:

  1. #define MYMACRO(a, b) {  
  2.                      a = a+b;  
  3.                      b = b+a; }

Nothing difficult or wrong on the first sight! Right? Okay but I got hundreds of compilation errors!
After trying around some time I noticed that it is not allowed to put a space behind the slash, i.e. ” is okay and ‘ ‘ is not.

So if you encounter the same error - welcome to the club …. tststs one never stops learning :-)

Matlab / C++ Communication

C++, Libraries, Matlab No Comments »

Often one is required to write medical image processing code in C++ for reasons of speed and programming libraries. However, what is missing during the development are nice and interactive calculation, plotting and visualization tools. However, on the contrary these are provided by Matlab. So all we need is an easy link for communicating between Matlab and your C++ program.

An overview of the available methods is provided in the Matlab external interfaces guide. Today I want to provide you with a link to my favorite method for windows C++ programs. It is called MatlabEngine and can be downloaded at CodeProject.

Design by j david macor.com.Original WP Theme & Icons by N.Design Studio
Entries RSS Comments RSS Log in