I have recently worked with the PcapPlusPlus library to analyze timestamps from PCAP ethernet captures. And I have fucked up majorly the Unix timestamp to string conversion. This post is meant to 1. remind me of my failure… 2. remember how to do it right the next time
Unix timestamps represent time elapsed since 00:00:00 UTC on Thursday, 1 January 1970, mostly in seconds, in case of .pcap(ng) files with an additional fractional nanoseconds part. The following timestamp represents Mon Jul 15 2024 17:48:40 GMT+0000 and almost a second full of nanoseconds (the fractional part):
1721065720.968918119
In my C++ program I wanted to export stuff as CSV including a row of Unix timestamps. PcapPlusPlus allows getting the timestamp from a parsed packet read from a pcap(ng) file like this:
Converting this to string seems to be straight forward using a std::stringstream. The crucial part is that the nanoseconds part can start with one or more zeros such as this:
1721065721.008918119
The fractional part represents 0.008918119 seconds. This must be 9 digits long!
Parsing the fractional part of this with a std::stringstream will strip the leading zeros which reduces the length of the nanoseconds fractional part: The fractional part must preserve the 9 digits because 0.8918119 s is much bigger than 0.008918119 s.
To properly parse the fractional part (e.g. to plot it) it must be ensured that the leading zeros also go into the string written into the CSV:
OpenCV’s TextureFlow example screenshot (C++ variant)
Since version 2.4.3 OpenCV has a nice example for generating a texture flow image from an input image. This generates a grid-like distributed edge-gradient image from the input. Unfortunately this example is in Python with no C++ translation available. A while ago I have made an attempt to translate this to C++. The result is not 100% identical to the Python variant, but close enough:
This is a Qt-based program for Windows and Linux to generate tetrahedral meshes for finite element simulation from various surface mesh formats. It also offers a fast and easy-to-use mesh viewer based on QGLViewer and allows basic mesh manipulations (currently only scaling is possible). Two different methods for tetrahedralization are possible: Delaunay Triangulation and Johnathan Shewchuk’s Isosurface Stuffing algorithm.