Piero V.

Heterogeneous comparisons in C++ containers

Occasionally, I still work with my Intel RealSense, on my RGBD toolbox, and affine topics.

Recently, I decided to allow multiple formats for the color images (initially, I had hardcoded them to JPEG only).

Therefore, I had to modify my data structures to work with pairs of paths instead of their common stems.

The UI to add new frames to the scene lists all the valid frames once and puts them into an ordered std::set, now keyed on the path pair.

With my previous assumption on fixed formats, I could do lookups on the set to quickly check if a provided stem was valid.

After the changes, this involved a heterogeneous comparison, i.e., a comparison of different types.

The trivial way to do this is a linear search, e.g., with std::find and a lambda or a range-based for.

However, this seemed a frequent case to me, and I was curious to see if there was a way to still take advantage of the optimized algorithms provided by the containers.

Indeed, there is! But it was added only since C++14.

After implementing bool operator<(const Other &, const Key &), you can pass std::less<> as a comparator to your container instead of the default std::less<Key>.

That is a particular template specialization that was developed for this purpose. It contains an is_transparent type that enables the templated version of some methods in STL containers.

This stack overflow answer contains many details. A TL; DR is that this implementation avoids unwanted conversions that could have undesired effects (e.g., the continuous creation of temporary objects from literals).

Komplete Audio 6 and DPC_WATCHDOG_VIOLATION

TL; DR

Connect your sound card to a USB hub with an external power supply.

The long story

A few months ago I changed my computer. The new one is high-end: it has a Ryzen 9 7950X processor and an Nvidia RTX 3080 GPU. Finding a motherboard was not easy: all the models compatible with that processor have a lot of compromises (or prohibitive costs). Eventually, I took an ASRock B650 PG Lightning with its pros and cons.

Everything is powered by a BitFenix Whisper 850W PSU, which has good reviews on many specialized sites.

The system is very stable with Linux: it can sustain several Firefox builds consecutively for hours without batting an eye.

Sadly, I cannot say the same for Windows, which I use almost exclusively for playing games. I often had blue screens of death with the DPC_WATCHDOG_VIOLATION error.

When I analyzed the dumps with WinDBG, I noticed the Komplete Audio 6 driver was always in the stack trace when this happened.

I tried to contact Native Instruments for help, but they were super unhelpful. I even asked them to make the driver open source since it is an old product they do not care about anymore. … [Leggi il resto]

Some tricks with range-diff

The workflows we use for Tor Browser are kinda peculiar.

When you manage a fork, you need a strategy to stay updated with upstream. We create a new branch for every new Firefox release and cherry-pick our previous commits on top of it.

The advantage over merging is that our patches always stay in a single and compact block of commits. So, it is trivial to tell our commits from upstream, and users can easily verify we do not modify Firefox outside those commits (we keep the commit hashes of gecko-dev, the official GitHub mirror of Mozilla's mercurial repositories).

There are also disadvantages: keeping fewer commits helps with this workflow. Therefore, our commits have a meaning of “feature”, not of “change”. Thus, we constantly update them, and the history of a patch becomes hard to follow.

And most importantly, this workflow requires frequent rebases, with the risk of losing some changes. To mitigate it, every new branch goes through a review process before we switch to it.

The main tools we use are git range-diff to check single commits and “diff-of-diffs” to check the patch set as a whole. … [Leggi il resto]

Customize NSIS MUI2's welcome page

Recently, I had to customize NSIS installers for work.

It was my first time, and I had to get to know this tool first. While this system already offers many functionalities, if you want to change anything in its built-in pages, you must rely on Win32 APIs.

The welcome and finish pages are an exception, up to a certain sense, because they are made with nsDialogs, NSIS’s plugin for creating completely custom pages.

As a result, it is possible to pass to add new widgets using the same API in a function passed MUI_PAGE_CUSTOMFUNCTION_SHOW. However, I encountered a major problem: the default widgets fill the available space. Therefore, any new widgets will be hidden, and it will not be possible to interact with them with the mouse. I looked for a solution online - NSIS is more than 20 years old, so you can find a lot of documentation - but I did not find an answer that worked for me.

Eventually, I found that you can resize widgets on Win32 with MoveWindow. … [Leggi il resto]

RealSense D400 and infrared streams

A while ago, I started working on a dataset I captured a few years ago with a Microsoft Kinect One.

I immediately realized the data looked much cleaner than the newer datasets I created with my Intel RealSense D435.

I had already noticed that, above a certain distance, the depth data was full of craters. I already knew the error is proportional to the squared distance, but for me, it was much bigger than expected. Therefore, I calibrated the sensors and now I stay closer to my targets during the acquisitions.

But for the last dataset I captured, I tried another strategy: I decided to save also the raw IR footage to process it offline.

Stereo vision

RealSense cameras are RGBD sensors: they provide simultaneously a color (RGB) and depth (D) stream.

There are several types of techniques to measure depth. For example, the original Kinect for the Xbox 360 uses “structured light”, and the Kinect One included a time-of-flight camera.

The RealSense D400 series is based on stereo vision, which works by matching the same point in frames captured by two different cameras. There is a relation between the displacement of this point (disparity), the relative position of the two cameras, and the depth. … [Leggi il resto]