LTI-Lib 2 Changes from 1.9.x to 2

lti::object

In the LTI-Lib 1.9.x the lti::object only defined the virtual method getTypeName(). The interface for lti::object in the LTI-Lib 2 is much more stronger and specifies the "clonable" interface. Two methods have to be defined in all classes inherited from lti::object: clone() and newInstance(). The former creates an instance with a replicated internal state while the latter creates a new instance with the default constructor. The main reason for this change is that now, all lti::objects can potentially exist in factories, and for this fact the clone() methods are required

A relatively new feature of C++ is used for clone() and newInstance(), which is not supported by GCC 2.95.x or VC++ 6.0: the return type of clone() is a pointer to the current class, and not a pointer to the parent class, as previously expected. This saves some unnecessary casting when working at the same level in the class hierarchy.

The old method getTypeName() has then be replaced by name().

Since there are many objects for which is does not make sense to clone, then many old lti::objects are now independent from the hierarchy (e.g. lti::mutex, lti::factory, etc.)

lti::className, getTypeName() and name()

The LTI-Lib 1.9.x produced simple const char* with the method getTypeName(), which was not necessarily unique (especially for template classes).

The LTI-Lib 2 has replaced the method getTypeName() with name(), which returns a fully qualified class name (generated with lti::className). This way, the name() method can be directly used with factories.

To simplify the manual generation of class names that are independent of the used C++ compiler or OS platform, all spaces are eliminated from the names.

Names of template classes

The names of many template classes in the LTI-Lib 1.9.x began with a 't', so for example there were types lti::tpoint<T>, lti::tpointList<T>, lti::trectangle<T> among others. To be consistent with the lti::vector and lti::matrix types, all those types has been renamed to lti::point<T>, lti::pointList<T>, lti::rectangle<T>. Similarly to the shortcuts of vectors and matrices, there are now several shortcuts like lti::ipoint for lti::point<int>, or lti::fpoint for lti::point<float>.

Underscores in protected and private attributes

The use of underscore is now not only allowed, but mandatory in the LTI-Lib 2 for protected or private attributes. This is necessary to simplify the identification of local variables from class attributes. The attribute name has to have a trailing underscore (e.g. vectorSize_)

lti::point

Member Functions

  • The function distanceTo() no longer exists. Use sqrt(p.distanceSqr()) is p is your point

lti::rgbaPixel and lti::rgbPixel<T>

In the older LTI-Lib the common pixel type was called rgbPixel; now the equivalent type in the LTI-Lib-2 is lti::rgbaPixel. The older trgbPixel is now called lti::rgbPixel<T>.

lti::genericVector

The generic vectors and matrices and all inherited classes have changed the initialization interface to a more intuitive, efficient one, even though it can be a little bit more dangerous.

Construction and Initialization

Old LTI-Lib 1.9.x

Previously, if you wrote:

vector<T> oldVct(5);

a vector with 5 elements initialized with T() was created. There are many cases in which you know you don't want to initialize anything to save some time. Therefore an alternative constructor was created:

vector<T> oldVct(false,5);

to avoid the initialization. This is however not so intuitive while reading.

New LTI-Lib 2

In C++ you know that if you write something like:

int i;

then the content of i is not defined. Therefore in the LTI-Lib 2 this approach has been followed and the container objects are only then initialized if you explicitely indicate that:

vector<T> aVct(5); // uninitialized vector with 5 elements, i.e. only
                   // memory allocation

vector<T> aVct(5,T()); // vector initialized with default value of T

Resize and Initialization

The same applies to the resize method:

Old LTI-Lib 1.9.x

vector<T> vct;

vct.resize(10); // 10 new elements initialized with T()
vct.resize(15); // 5 new elements initialized with T(), keeping the first 10
vct.resize(18,T(6)); // 3 new elements initialized with "6", keeping the first
                     // 15 elements

New LTI-Lib 2

vector<T> vct;

vct.resize(10); // 10 new uninitialized elements
vct.resize(15); // 5 new uninitialized elements, keeping the first 10,
                // whatsoever they were.
vct.resize(18,T(6)); // 3 new elements initialized with "6", keeping the first
                     // 15 elements

One very important change is that in the LTI-Lib-2 the use of explicit method names is prefered over overloaded methods or the use of flags. In the particular case of the older "resize", the new prefered way is summarized in the following table:

LTI-Lib 2 LTI-Lib 2 LTI-Lib 1
Prefered Still possible Deprecated
vct.allocate(15) vct.resize(15,T(),AllocateOnly) vct.resize(15,T(),false,false)
vct.assign(15,T()) vct.resize(15,T(),Init) vct.resize(15,T(),false,true)
vct.resize(15) vct.resize(15,T(),Copy) vct.resize(15,T(),true,false)
vct.resize(15,T()) vct.resize(15,T(),CopyAndInit) vct.resize(15,T(),true,true)

lti::genericMatrix

Access as vector

In the LTI-Lib 2 it was possible to access a connected matrix as vector, using an at() method which expected just an integer. Since with this method it is quite dangerous to make a non intended access to a matrix as vector, the method has been renamed to elem(). This way there is no possible misunderstanding that you want to do what you're saying (the problem caused several hours debugging in some functors!).

lti::location, lti::rectLocation

Member Functions

  • getArea() renamed to calculateArea() since there is a multiplication involved. (Being a bit picky maybe)