VTK/CanvasAPI

From KitwarePublic
Jump to navigationJump to search

After recent discussions I have been prototyping a simple canvas style API for VTK. The diagram below shows a rough equivalence to the QGraphicsView framework present in Qt, but with a much more basic API at this stage.

Chart Classes


Using Function Pointers

It seems that there is a wish to be able to declare functions that override certain aspects of rendering. In a traditional C++ API this would normally be accomplished by inheritance and overriding of a virtual function. The same thing can be accomplished by supplying function pointers without needing to derive a class.

The QtConcurrent API uses function pointers, and boost_bind optionally. Check out the relevant sections of their API documentation here for more details. So a specific signature is required for the function pointer, but this could optionally be created by boost::bind (or possibly boost lambda functions).

As an example the equivalent code would be.

<source lang="cpp">#include <mymark.h>

double scalarFunction(int index);

int main() {

 MyMark *mark = new MyMark;
 mark->SetScalarFunctor(scalarFunction);

}

double scalarFunction(int index) {

 return index * 3.0 / (index - 1.0);

}</source>

Compared with a more traditional inherited class API.

<source lang="cpp">#include <mymark.h>

class InheritedMark : public MyMark { protected:

 virtual double scalarFunction(int index);

};

int main() {

 InheritedMark *mark = new InheritedMark;

}

double InheritedMark::scalarFunction(int index) {

 return index * 3.0 / (index - 1.0);

}</source>