Personal tools
User menu

Refactoring of the Geometry Classes

From mitk.org

Jump to: navigation, 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:

data->GetTimeSlicedGeometry();

New:

data->GetTimeGeometry();


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:

data->SetGeometry(TimeSlicedGeometryObject);

New:

data->SetTimeGeometry(TimeGeometryObject);


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:

data->GetTimeSlicedGeometry()->TimeStepToTimeStep( data2TimeGeometry, time );

New (one possible solution):

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

Copy Time Geometry from one object to another

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

Old:

data->SetGeometry(dynamic_cast<Geometry3D*>(input->GetTimeSlicedGeometry()->Clone().GetPointer()));

New:

data->SetTimeGeometry(input->GetTimeGeometry()->Clone().GetPointer());


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:

data->Initialize(input->GetPixelType(), *input->GetTimeSlicedGeometry ());

New:

data->Initialize(input->GetPixelType(), *input->GetTimeGeometry());


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:

data->SetGeometry(dynamic_cast<Geometry3D*>(input->GetTimeSlicedGeometry()->Clone().GetPointer()));

New:

data->SetTimeGeometry(input->GetTimeGeometry()->Clone().GetPointer());


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:

data->GetTimeSlicedGeometry()->GetBounds())

New:

data->GetTimeGeometry()->GetBoundsInWorld())


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

Old:

data->GetTimeSlicedGeometry()->MSToTimeStep( GetTime() );

New:

data->GetTimeGeometry()->TimePointToTimeStep( GetTime() );


Get Number of availible Time Steps

Old:

data->GetTimeSlicedGeometry()->GetTimeSteps();

New:

data->GetTimeGeometry()->CountTimeSteps();


Get Geometry for a specific time step

Old:

data->GetTimeSlicedGeometry()->GetGeometry3D(timeStep);

New:

data->GetTimeGeometry()->GetGeometryForTimeStep(timeStep);


Check if a time step is covered by the Object

Old:

data->GetTimeSlicedGeometry()->IsValidTime( m_TimeStep )

New:

data-> GetTimeGeometry()->IsValidTimeStep( m_TimeStep )


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:

data->InitializeEvenlyTimed(slicedGeometry, m_Dimensions[3]);

New with unknown previous TimeGeometry:

ProportionalTimeGeometry::Pointer timeGeometry = ProportionalTimeGeometry::New();
timeGeometry->Initialize(slicedGeometry, m_Dimensions[3]);
data->SetTimeGeometry(timeGeometry);

New with known previous TimeGeometry:

dynamic_cast<ProportionalTimeGeometry *>(data->GetTimeGeometry())->Initialize(slicedGeometry, m_Dimensions[3]);


Update Time geometry

Old:

data->GetTimeSlicedGeometry()->UpdateInformation();

New:

data-> GetTimeGeometry()->Update();


Test if evenly sliced time geometry

Old:

data->GetTimeSlicedGeometry()->GetEvenlyTimed()

New:

ProportionalTimeGeometry::Pointer timeGeometry = dynamic_cast<ProportionalTimeGeometry>(GetTimeGeometry());
timeGeometry != NULL;


Set Image Geometry on/off

Old:

data->GetTimeSlicedGeometry()->ImageGeometryOn();

New:

for (TimeStepType step = 0; step < data->GetTimeGeometry()->GetNumberOfTimeSteps(); ++step)
    data->GetTimeGeometry()->GetGeometryForTimeStep(step)->ImageGeometryOn();


Transform Coordinate with Time Geometry

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

Old:

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


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:

data->GetTimeSlicedGeometry()->SetIndexToWorldTransform( affineTransform );

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:

data->GetTimeSlicedGeometry()->GetOrigin();

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:

data->GetTimeSlicedGeometry()->GetSpacing();

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:

data->GetTimeSlicedGeometry()->Set(geo3, 1);

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

  • This page was last modified on 29 November 2014, at 12:50.
  • This page has been accessed 13,905 times.