Page MenuHomePhabricator

Extend mitk::GenericLookupTable
Closed, ResolvedPublic

Description

The template class mitk::GenericLookupTable allows for simple declaration of lookup-tables for arbitrary types. It is used together with the template class mitk::GenericLookupTableProperty which encapsulates GenericLookupTables of the same type.

These simple template classes should be extended with the following:

  • Add initialization method to generate a lookup-tables with an initial size and default value
  • Wrap other relevant methods from the encapsulated STL hash map
  • Add reader/writer classes for scene serialization
  • Write a unit test

Event Timeline

While working on the EnhancedPointsetMapper, I made the following changes to GenericLoopkupTable (See T1692):

I added a mitkSpecializeGenericLookupTable macro to mitkGenericLookupTable.h to
be able to create specific lookup tables (analogous to the macro in
mitkGenericProperty.h).

Then I added the files mitkLookupTables.h and mitkLookupTables.cpp to define
and instantiate the following lookup tables: BoolLookupTable, FloatLookupTable,
IntLookupTable and StringLookupTable.

I fixed some compilation errors in mitkGenericLookupTable.h - mostly const
correctness problems.

I believe, mitk::GenericLookupTableProperty is unnecessary, if we use the
existing mitk::GenericProperty with MyLookupTable::Pointer as template
parameter (the two classes are basically identical save of the member
definition: ValueType m_Value versus ValueType::Pointer m_Value)

Therefore, I changed the LookupTableProperty definitions in mitkProperties.h
&.cpp from
mitkSpecializeGenericLookupTableProperty(FloatLookupTableProperty,
FloatLookupTable);
to
mitkSpecializeGenericProperty(FloatLookupTableProperty,
FloatLookupTable::Pointer , FloatLookupTable::New());

(In reply to comment #1)

I believe, mitk::GenericLookupTableProperty is unnecessary, if we use the
existing mitk::GenericProperty with MyLookupTable::Pointer as template
parameter (the two classes are basically identical save of the member
definition: ValueType m_Value versus ValueType::Pointer m_Value)

Therefore, I changed the LookupTableProperty definitions in mitkProperties.h
&.cpp from
mitkSpecializeGenericLookupTableProperty(FloatLookupTableProperty,
FloatLookupTable);
to
mitkSpecializeGenericProperty(FloatLookupTableProperty,
FloatLookupTable::Pointer , FloatLookupTable::New());

This solution proved to be a problem. The == operator of GenericProperty uses the == operator of its template type.
In this case:

mitkSpecializeGenericProperty(FloatLookupTableProperty,
FloatLookupTable::Pointer , FloatLookupTable::New());

it was calling == of the smartpointer class, which only checks if the pointer are equal, not if the objects that the pointers point at are equal.

Therefore another solution is needed: We can not use a (smart)pointer to a lookup table as template paramter, we have to use the lookup table itself:

mitkSpecializeGenericProperty(FloatLookupTableProperty,
FloatLookupTable , FloatLookupTable());

To allow this, mitk::GenericLookupTable may not derive from itk::Object. It must define =, ==, != operators and must define a global ostream& << operator.
Because the ostream& << operator has to be a global function, it must be defined in a cpp file. Therefore the mitkSpecializeGenericLookupTable must be splitted into one that declares the new lookup table and is called in a header file (mitkLookupTables.h), and a second macro mitkSpecializeGenericLookupTableOperator that is called for each specialized lookup table in a cpp file (mitkLookupTables.cpp) and defines the << operator function

[SVN revision 19558]
FIX (#2278): rewrite mitk::GenericLookupTable in order to be used correctly with GenericProperty. See T2278 for details.

The GenericLookupTables seem to be quite usable now, closing this bug. If new features need to be added, it can be reopened.

Reopening because we need to add template instantiations for mitk::PropertyList::GetPropertyValue<> for the new lookuptable properties.

[SVN revision 21028]
FIX (#2278): add template instantiations for mitk::PropertyList::GetPropertyValue<> for FloatLookupTable, BoolLookupTable, IntLookupTable, StringLookupTable.

[SVN revision 21030]
FIX (#2278): add testcase for mitk::PropertyList::GetPropertyValue<> instantiation for BoolLookupTable

New features and testcases are committed, dartclients are green, closing now.