C++ Java Mappings

Some concepts used in ShapeLogic do not map well from Java to C++. This page list those, and their mapping or the possible different mappings.

Color models

Color models in Java / ImageJ

ImageJ has strategically chosen only to work with a very simple color model:

  • int representing RGB or RGBA
  • byte representing gray 8 bit
  • short representing gray 16 bit
  • float representing gray float

An image's pixels can always be stored as an array of a primitive number type.

Color models in C++ / GIL

GIL has a very diverse color model with both interleaved or planar images, with any number of channels, any word type and color space.

The only abstraction that can be made on this would be a pixel coordinate.

There could be an interface for whether a pixel satisfies a given predicate. In Java this gives an extra layer of indirection.

Another option is to constrain the color models that can be handled.

Java Interface

The simple mapping would be to create abstract C++ classes and use multiple inheritance.

For some algorithms the new C++ concepts might work well.

Iterator

The C++ STL iterator has a start point and a determined end point.

The Java iterator has a next() and hasNext() method.

The lazy data streams used in ShapeLogic do not have a determined end point, so an STL iterator does not seem to be an option. It is trivial to define and implement a Java iterator in C++.