Refactoring of the Geometry Classes

From mitk.org
Jump to navigation Jump to search

Migration Guide for TimeSlicedGeometry to TimeGeometry

Our geometry-concept has been changed to simplify the use of the geometry. As a first step the TimeSlicedGeometry has been removed. By now, all time information will be stored in a new class named TimeGeometry.

The old structure is displayed in the image below. The geometry of each BaseData-object, for example an image, has been represented by a Geometry3D-Class. Usually this was not an Geometry3D but an derivated class mostly an TimeSlicedGeometry. The TimeSlicedGeometry was responsible for managing the geometry for different time points but also provided functions like transformation etc.


width="750"


The geometry-concept has been redesigned. The new structure is shown in a simplified class diagram below. Now BaseData holds a TimeGeometry which is basically a container for different Geometry3D-Objects for each time point. Since TimeGeometry is just an abstract class the data management is mainly done in a subclass. This is done to be able to support different scenarios. The biggest change introduced by this new concept is that TimeGeometry does not inherit from Geometry3D. Therefore a cast to Geometry3D is no longer possible. Also TimeGeometry itself does not provide any transformation information. To get the transformation for a BaseData-Object a time point must be specified and the corresponding Geometry3D will contain the transformation.


width="750"


Most changes introduced by this redesign of the geometry affect the handling of the BaseData and any class that is derived by it. The next sections will explain how the most important functions which changed can be replaced.


Code replacements

This section describes how old code can be migrated to the new TimeGeometry-concept.


GetTimeSlicedGeometry

This function returned the TimeSlicedGeometry which represent an object. The equivalent function is now GetTimeGeometry which returns the TimeGeometry that represent an object. :

Old:

<syntaxhighlight lang="cpp"> data->GetTimeSlicedGeometry(); </syntaxhighlight>

New:

<syntaxhighlight lang="cpp"> data->GetTimeGeometry(); </syntaxhighlight>


SetGeometry

Since TimeSlicedGeometry has been derived SetGeometry could be used to set the TimeSlicedGeometry for a given object. Since TimeGeometry does not inheriting from Geometry3D, the new method SetTimeGeometry(..) must be used now.

Old:

<syntaxhighlight lang="cpp"> data->SetGeometry(TimeSlicedGeometryObject); </syntaxhighlight>

New:

<syntaxhighlight lang="cpp"> data->SetTimeGeometry(TimeGeometryObject); </syntaxhighlight>


Calculate corresponding time steps for two BaseData-objects

MITK does not use an absolute time definition but define time relative to a zero time point. This zero time point might be different for each object! To calculate the corresponding time steps of two BaseData-objects assumptions about the relation of the zero time points of each objects must be made which is usually to assume that both zero time points represent the same real time point. This is not necessarily the case and a programmer should be aware of this assumption if it is made. Therefore, the method TimeStepToTimeStep has been removed. To get the same functionality a conversion between two time points must be made.

'Therefore, the method TimeStepToTimeStep has been removed. To get the same functionality a conversion between two time points must be made. '

Old:

<syntaxhighlight lang="cpp"> data->GetTimeSlicedGeometry()->TimeStepToTimeStep( data2TimeGeometry, time ); </syntaxhighlight>

New (one possible solution):

<syntaxhighlight lang="cpp"> TimeStepType tS = ... // Will contain the result. TimePointType tP = data1->GetTimeGeometry()->TimePointToTimeStep(tS); tS = data2->GetTimeGeometry()->TimeStepToTimePoint(tP); </syntaxhighlight>

Copy Time Geometry from one object to another

Since TimeGeometry does not inherit from Geometry3D the setting/getting has been simplified

Old:

<syntaxhighlight lang="cpp"> data->SetGeometry(dynamic_cast<Geometry3D*>(input->GetTimeSlicedGeometry()->Clone().GetPointer())); </syntaxhighlight>

New:

<syntaxhighlight lang="cpp"> data->SetTimeGeometry(input->GetTimeGeometry()->Clone().GetPointer()); </syntaxhighlight>


Initialize the geometry of a BaseData-object from another object

Since the basic class of the TimeGeometry is known, the cast is no longer needed.

Old:

<syntaxhighlight lang="cpp"> data->Initialize(input->GetPixelType(), *input->GetTimeSlicedGeometry ()); </syntaxhighlight>

New:

<syntaxhighlight lang="cpp"> data->Initialize(input->GetPixelType(), *input->GetTimeGeometry()); </syntaxhighlight>


Copy the Geometry of one BaseData-object to another one.

Instead of copy the TimeSlicedGeometry copy the TimeGeometry. No cast is needed since the Clone-method will return the right type.

Old:

<syntaxhighlight lang="cpp"> data->SetGeometry(dynamic_cast<Geometry3D*>(input->GetTimeSlicedGeometry()->Clone().GetPointer())); </syntaxhighlight>

New:

<syntaxhighlight lang="cpp"> data->SetTimeGeometry(input->GetTimeGeometry()->Clone().GetPointer()); </syntaxhighlight>


Get the bounds of a data-object

Previous it has not been defined if the bounds of a TimeSlicedGeometry contains only the bounds of a specific time point or contain the bounds of all time points. 'The bounds of the new geometry are defined to include the data of all time steps,' e.g. it is guaranteed that the bounds of the TimeGeometry contains the bound of all time steps. 'Since the TimeGeometry does not provide a transformation between world and index coordinates, the bounds can be accessed only as bounds in world coordinates.' If bounds in index coordinates are necessary then they must either be taken from the time step geometry or the world coordinates must be transformed using a TimeStep geometry.

Old:

<syntaxhighlight lang="cpp"> data->GetTimeSlicedGeometry()->GetBounds()) </syntaxhighlight>

New:

<syntaxhighlight lang="cpp"> data->GetTimeGeometry()->GetBoundsInWorld()) </syntaxhighlight>


Convert a Time Point (Time in ms) into a Time Step

Old:

<syntaxhighlight lang="cpp"> data->GetTimeSlicedGeometry()->MSToTimeStep( GetTime() ); </syntaxhighlight>

New:

<syntaxhighlight lang="cpp"> data->GetTimeGeometry()->TimePointToTimeStep( GetTime() ); </syntaxhighlight>


Get Number of availible Time Steps

Old:

<syntaxhighlight lang="cpp"> data->GetTimeSlicedGeometry()->GetTimeSteps(); </syntaxhighlight>

New:

<syntaxhighlight lang="cpp"> data->GetTimeGeometry()->CountTimeSteps(); </syntaxhighlight>


Get Geometry for a specific time step

Old:

<syntaxhighlight lang="cpp"> data->GetTimeSlicedGeometry()->GetGeometry3D(timeStep); </syntaxhighlight>

New:

<syntaxhighlight lang="cpp"> data->GetTimeGeometry()->GetGeometryForTimeStep(timeStep); </syntaxhighlight>


Check if a time step is covered by the Object

Old:

<syntaxhighlight lang="cpp"> data->GetTimeSlicedGeometry()->IsValidTime( m_TimeStep ) </syntaxhighlight>

New:

<syntaxhighlight lang="cpp"> data-> GetTimeGeometry()->IsValidTimeStep( m_TimeStep ) </syntaxhighlight>


Initialize Evenly Timed TimeGeometry

To initialize a TimeGeometry the type of the TimeGeometry must be known. If this Type is not known a new TimeGeometry must be created and used. This is a new behavior since there had been only one type of TimeSlicedGeometry.

Old:

<syntaxhighlight lang="cpp"> data->InitializeEvenlyTimed(slicedGeometry, m_Dimensions[3]); </syntaxhighlight>

New with unknown previous TimeGeometry:

<syntaxhighlight lang="cpp"> ProportionalTimeGeometry::Pointer timeGeometry = ProportionalTimeGeometry::New(); timeGeometry->Initialize(slicedGeometry, m_Dimensions[3]); data->SetTimeGeometry(timeGeometry); </syntaxhighlight>

New with known previous TimeGeometry:

<syntaxhighlight lang="cpp"> dynamic_cast<ProportionalTimeGeometry *>(data->GetTimeGeometry())->Initialize(slicedGeometry, m_Dimensions[3]); </syntaxhighlight>


Update Time geometry

Old:

<syntaxhighlight lang="cpp"> data->GetTimeSlicedGeometry()->UpdateInformation(); </syntaxhighlight>

New:

<syntaxhighlight lang="cpp"> data-> GetTimeGeometry()->Update(); </syntaxhighlight>


Test if evenly sliced time geometry

Old:

<syntaxhighlight lang="cpp"> data->GetTimeSlicedGeometry()->GetEvenlyTimed() </syntaxhighlight>

New:

<syntaxhighlight lang="cpp"> ProportionalTimeGeometry::Pointer timeGeometry = dynamic_cast<ProportionalTimeGeometry>(GetTimeGeometry()); timeGeometry != NULL; </syntaxhighlight>


Set Image Geometry on/off

Old:

<syntaxhighlight lang="cpp"> data->GetTimeSlicedGeometry()->ImageGeometryOn(); </syntaxhighlight>

New:

<syntaxhighlight lang="cpp"> for (TimeStepType step = 0; step < data->GetTimeGeometry()->GetNumberOfTimeSteps(); ++step)

   data->GetTimeGeometry()->GetGeometryForTimeStep(step)->ImageGeometryOn();

</syntaxhighlight>


Transform Coordinate with Time Geometry

'NOT LONGER SUPPORTED, needs to get specific time point'

Old:

<syntaxhighlight lang="cpp"> data->GetTimeSlicedGeometry()->WorldToIndex(worldPoint, point); </nowiki>

New:

<syntaxhighlight lang="cpp"> data->GetTimeGeometry()->GetGeometryForTimeStep(timeStep)->WorldToIndex(worldPoint, point); </syntaxhighlight>


Set Transform for Time Geometry

TimeGeometries does no longer have any coordinate transformations. Therefore it is not possible to get these transformations. Instead define a specific time step for getting the transformation.

Old:

<syntaxhighlight lang="cpp"> data->GetTimeSlicedGeometry()->SetIndexToWorldTransform( affineTransform ); </syntaxhighlight>

New: NO LONGER SUPPORTED, TimeGeometries has no Spacing. Use Geometries instead


Get Origin for Time Geometry

TimeGeometries does no longer have any coordinate transformations. Therefore it is not possible to get these transformations. Instead define a specific time step for getting the transformation.

Old:

<syntaxhighlight lang="cpp"> data->GetTimeSlicedGeometry()->GetOrigin(); </syntaxhighlight>

New: NO LONGER SUPPORTED, TimeGeometries has no Origin. Use Geometries instead


Get Spacing for Time Geometry

TimeGeometries does no longer have any coordinate transformations. Therefore it is not possible to get these transformations. Instead define a specific time step for getting the transformation.

Old:

<syntaxhighlight lang="cpp"> data->GetTimeSlicedGeometry()->GetSpacing(); </syntaxhighlight>

New: NO LONGER SUPPORTED, TimeGeometries has no Spacing. Use Geometries instead


Set a Geometrie for a specific time Step

TimeGeometries does no longer have any coordinate transformations. Therefore it is not possible to get these transformations. Instead define a specific time step for getting the transformation.

Old:

<syntaxhighlight lang="cpp"> data->GetTimeSlicedGeometry()->Set(geo3, 1); </syntaxhighlight>

New: Time geometry needs to be casted to child class which supports this function