[Insight-users] Bug in void SpatialObject< TDimension >::ComputeObjectToParentTransform()
Bloch Christoph
christoph.bloch at meduniwien.ac.at
Wed Apr 22 05:58:59 EDT 2009
Hi all,
there is a bug in the current implementation of the method. The code
attached below indicates, that calling
ComputeObjectToParentTransform() after ComputeObjectToWorldTransform()
changes the ParentToWorldTransform which it should not - at least to my
understanding.
#include "itkSpatialObject.h"
#include "itkGroupSpatialObject.h"
using namespace std;
int main( int , char *[] )
{
typedef itk::SpatialObject<2> SpatialObjectType;
typedef SpatialObjectType::TransformType TransformType;
SpatialObjectType::Pointer object1 = SpatialObjectType ::New();
object1->GetProperty()->SetName("First Object");
SpatialObjectType::Pointer object2 = SpatialObjectType ::New();
object2->GetProperty()->SetName("Second Object");
object1->AddSpatialObject(object2);
SpatialObjectType::Pointer object3 = SpatialObjectType ::New();
object3->GetProperty()->SetName("Third Object");
object2->AddSpatialObject(object3);
TransformType::OffsetType ObjectToWorldOffset;
ObjectToWorldOffset[0] = 5;
ObjectToWorldOffset[1] = 5;
object1->GetObjectToWorldTransform()->SetOffset(ObjectToWorldOffset);
object1->ComputeObjectToParentTransform();
object1->ComputeObjectToWorldTransform(); //update all children
cout << object1->GetObjectToParentTransform()->GetOffset() << endl;
cout << object2->GetObjectToParentTransform()->GetOffset() << endl;
cout << object3->GetObjectToParentTransform()->GetOffset() << endl;
cout <<"\nCalling object3->ComputeObjectToParentTransform()\n" << endl;
object3->ComputeObjectToParentTransform();
cout << object1->GetObjectToParentTransform()->GetOffset() << endl;
cout << object2->GetObjectToParentTransform()->GetOffset() << endl;
cout << object3->GetObjectToParentTransform()->GetOffset() << endl;
return 0;
}
This gives the following output:
[5, 5]
[0, 0]
[0, 0]
Calling object3->ComputeObjectToParentTransform()
[5, 5]
[0, 0]
[5, 5]
I think I tracked the problem down to the following code:
void
SpatialObject< TDimension >
::ComputeObjectToParentTransform()
{
m_ObjectToParentTransform->SetScale(m_ObjectToWorldTransform->GetScale());
m_ObjectToParentTransform->SetCenter(m_ObjectToWorldTransform->GetCenter());
m_ObjectToParentTransform->SetMatrix(m_ObjectToWorldTransform->GetMatrix());
m_ObjectToParentTransform->SetOffset(m_ObjectToWorldTransform->GetOffset());
if(m_TreeNode->HasParent())
{
typename TransformType::Pointer inverse = TransformType::New();
if(static_cast<TreeNodeType*>(m_TreeNode->GetParent())
449: ->GetNodeToParentNodeTransform()->GetInverse(inverse))
{
551: m_ObjectToParentTransform->Compose(inverse,true);
}
}
......
Here line 449 should be changed to
->GetNodeToWorldTransform()->GetInverse(inverse))
and line line 451 to
m_ObjectToParentTransform->Compose(inverse,false);
I hope this saves some headache,
Christoph
More information about the Insight-users
mailing list