Automate Installation of Multiple Binary packages 2

In a previous post we saw how to automate installation of different versions of ParaView and give each one its own icon and menu entry.

What if we want to add a new version without re-downloading all the previous ones ?

We need to:

  1. Find which versions we already have
  2. Store this information
  3. Skip steps for the ones we have

Although, these sound obvious it took quite some time to find the proper way to do it in ansible, hence this note.

[Read More]

Automate Installation of Multiple Binary packages

As a ParaView developer it is useful to keep multiple versions of ParaView installed so that testing for regressions becomes quick and easy. I used to just drop the binaries from https://www.paraview.org/download/ right into an ~/opt directory, and add custom launchers with menulibre. To differentiate between versions I would edit the icon with Gimp so that it includes the corresponding ParaView version.

Since I started using ansible to set up different VMs and machines it became natural to look for an opportunity to use it everywhere. In this case the goal is:

[Read More]

Organizing build commands in cmake with profiles

When dealing with a C/C++ project that utilizes cmake one will sooner or later need to organize the available build options into profiles than enable multiple features in a convenient manners. Two of the ways to achieve that is the use of cmake cache files and cmake presets.

Let’s start with setting a common ground for this test using the vtk repository:

git clone https://gitlab.kitware.com/vtk/vtk
cd vtk/
git switch -d v9.1.0
git submodule init
git submodule update --recursive

VTK has already a number of documented build options on top of the ones that cmake provides for every project.

[Read More]

Generating compile commands with cmake

cmake offers the option to generate a compilation database in json format using the option CMAKE_EXPORT_COMPILE_COMMANDS=YES. The database holds essentially the command, paths and compilers flags used to compile each file of a project. The generated file (usually called compile_commands.json) can be used in conjunction with various code completion tools like YouCompleteMe and Visual Studio’s IntelliSense in order to offer more complete information, completion and errors about the code.

The official cmake tutorial

There are many resources, posts and articles about using cmake and writing modern cmake code. Unfortunately for a new user it is sometimes difficult to locate the proper resource that contains no deprecated options or any other non-recommended practices. One of the quickest and simplest resource I became aware recently is the official tutorial that lives in the documentation of cmake.

Using ccache to speedup compilation of C/C++

ccache is a utility that caches intermediate files during compilation offering significant speedups. It is especially useful if you are switching between two branches of the same project see below.

To use it, prepend it before the compiler i.e. Use ccache gcc instead of gcc ... . If you are using cmake with a version greater that 3.4 you can use the option -DCMAKE_CXX_COMPILER_LAUNCHER=ccache for older version you can modify the compiler settings or use the variable RULE_LAUNCH_COMPILE for more see here.

[Read More]

Change pixels in 2D/3D images

Similar to an older post. One can modify 2D/3D images in order to change specific pixels /voxels. This became useful recently while trying to remove a tissue from a segmented image. For something more complicated you may want to use Slicer, but for simple cases like this a python script enough. Appended you can also find the corresponding C++ code. Keep in mind that python handles all supported PixelTypes automatically while for the C++ one needs to update the PixelType typedef and the dimension variable.

[Read More]
itk 

Thousands separator in C++

As you print more and more numbers in the screen it may become cumbersome to count digits just to see is if you are in the range of millions or 100’s of millions. Visually grouping digits can simmplify things. There is a pleathora of ways to do this in C++ but the one I find the best is the one provided by the standand C++ library through the std::numpunct object. Here is a small example that uses groups digits using commas.

[Read More]

#ifdef in Latex documents

Consider the case where you want to generate slightly different versions of a document out of single latex file. This could be needed when using different document templates or if you want to switch on/off commentary in your document. You may want different introduction or order of chapters based on each particular case. A way to do it is using conditionals that exists available in plain TeX. For example

\documentclass{article}
\newif\ifanswers
%\answerstrue 
\begin{document}

question : what is the expected complexity of quicksort for an array of integers ?
\vspace{1cm}

\ifanswers
answer $o(n\log n)$ where $n$ is the numer of integers.
\fi
\vspace{1cm}

question : give the definition of an abelian group .
\vspace{1cm}

\ifanswers
answer : an abelian group is a set, $a$, together with an operation $\cdot$ that ...
\vspace{1cm}
\fi
\end{document}

Enabling conditionals can be achieved by commenting/uncommenting the 3rd line either by hand or using a makefile:

[Read More]

Keep running until crash with gdb

Many times when trying to catch a bug , or to validate that your parallel code runs correctly you wish to run your code again and again and again until break on an assertion or even better until you persuade yourself that your code is good enough. Once more, stakoverflow has the answer for us:

set $n = 100
while $n-- > 0
  printf "starting program\n"
  run
  if $_siginfo
    printf "Received signal %d, stopping\n", $_siginfo.si_signo
    loop_break
  else
    printf "program exited\n"
  end
end

If you use it often save it in a file and launch it using

[Read More]