RTAB-Map 0.23.10
Real-Time Appearance-Based Mapping
Loading...
Searching...
No Matches
UtiLite

Introduction

UtiLite is a simple library to create small cross-platform applications using threads, events-based communication and a powerful logger. The first three sections show the core classes of the library, then last sections show some useful functions added through time.

UtiLite provides a utility application called uResourceGenerator to generate resources to include in an executable. For example:

$ rtabmap-res_tool DatabaseSchema.sql

This will generate a HEX file "DatabaseSchema_sql.h" which can be included in source files. Data of the file is global and can be accessed by the generated const char * DATABASESCHEMA_SQL.

#include "DatabaseSchema_sql.h"
...
std::string hex = DATABASESCHEMA_SQL;
// Assuming there are only ASCII characters, we can directly convert to a string:
std::string schema = uHex2Str(hex);
// For binary data:
std::vector<char> bytes = uHex2Bytes(hex);
std::string UTILITE_EXPORT uHex2Str(const std::string &hex)
std::vector< char > UTILITE_EXPORT uHex2Bytes(const std::string &hex)

ULogger

The ULogger can be used anywhere in the application to log messages (formated like a printf). The logger can be set (ULogger::setType()) to print in a file or in the console (with colors depending on the severity). Convenient macros are given, working like a printf(), as UDEBUG(), UINFO(), UWARN(), UERROR(), UFATAL(), UASSERT(). Small example:

...
UINFO("A simple message with number %d", 42);
UDEBUG("A debug message");
...
#define UDEBUG(...)
Definition ULogger.h:59

This will print: [Severity] (Time) File:Line:Function() "The message"

[ INFO] (2010-09-25 18:08:20) main.cpp:18::main() A simple message with number 42
[DEBUG] (2010-09-25 18:08:20) main.cpp:18::main() A debug message

UEventsManager, UEventsHandler, UEvent

The events-based communication framework helps to communicate between objects/threads. The UEventsManager is a singleton with which we can post events anywhere in the application by calling UEventsManager::post(). All UEventsHandler will then receive the event with their protected function UEventsHandler::handleEvent(). Handlers are added to UEventsManager by calling UEventsManager::addHandler(). The UEvent provides an abstract class to implement any event implementations. The only requirement is that the event must implements UEvent::getClassName() to know the event's type.

...
MyHandler handler; // MyHandler is an implementation of UEventsHandler
UEventsManager::post(new MyEvent()); // MyEvent is an implementation of UEvent
// The UEventsHandler::handleEvent() of "handler" will then be called by the UEventsManager's events dispatching thread.
...
static void addHandler(UEventsHandler *handler)
static void post(UEvent *event, bool async=true, const UEventsSender *sender=0)

Look at the full example in page of UEventsHandler on how communication works with threads (UThread).

UThread, UMutex, USemaphore

The multi-threading framework use a UThread as an abstract class to implement a thread in object-style. Reimplement UThread::mainLoop() then call UThread::start() to start the main loop of the thread. Threads can be joined by calling UThread::join() and killed by calling UThread::kill(). Classes UMutex and USemaphore provide blocking mechanisms to protect data between threads.

...
MyThread t; // MyThread is an implementation of UThread
t.start();
t.join(); // Wait the thread to finish
...

UTimer

A useful class to compute processing time:

UDirectory, UFile

For files and directories manipulations :

Convenient use of STL

The library provides some simple wrappers of the STL like:

Basic mathematic operations

A library of basic array manipulations:

Conversion

A library of convenient functions to convert some data into another like:

UProcessInfo

This class can be used to get the process memory usage: UProcessInfo::getMemoryUsage().