[vtkusers] How to get the updated value of a vtkAssembly's position?

Aroosha Laghaee a.laghaee at sms.ed.ac.uk
Fri Aug 26 11:21:49 EDT 2005


Dear Users,

I am using VTK to simulate a robot arm (fixed at the top). My arm (a
vtkAssembly) is a collection of four joints (each also an assembly of a box and
sphere). Please look at the attached diagram for a picture of this hierarchy of
assemblies. Here is how the arm is put together:

//draws LARA
vtkAssembly** drawLARA()
{
// set up the actors here

//assemble each joint
  vtkAssembly *joint4 = vtkAssembly::New();
  joint4->AddPart(sphereActor4);

  vtkAssembly *joint3 = vtkAssembly::New();
  joint3->AddPart(sphereActor3);
  joint3->AddPart(cubeActor4);
  joint3->AddPart(joint4);

  vtkAssembly *joint2 = vtkAssembly::New();
  joint2->AddPart(sphereActor2);
  joint2->AddPart(cubeActor3);
  joint2->AddPart(joint3);

  vtkAssembly *joint1 = vtkAssembly::New();
  joint1->AddPart(sphereActor1);
  joint1->AddPart(cubeActor2);
  joint1->AddPart(joint2);

  vtkAssembly *joint0 = vtkAssembly::New();
  joint0->AddPart(cubeActor1);
  joint0->AddPart(joint1);

  //set rotation and tilt origins for each joint
  joint4->SetOrigin(sphereActor4->GetCenter());
  joint3->SetOrigin(sphereActor3->GetCenter());
  joint2->SetOrigin(sphereActor2->GetCenter());
  joint1->SetOrigin(sphereActor1->GetCenter());

  //assemble the arm
  vtkAssembly** arm = new vtkAssembly *[5];
  joint[0] = joint0;
  joint[1] = joint1;
  joint[2] = joint2;
  joint[3] = joint3;
  joint[4] = joint4;

  return arm;
  //clean up here
  }

Each joint can make two types of movement(rotate and tilt). I use:
joint->AddOrientation(0,0,float) for tilting &
joint->AddOrientation(0,float,0) for rotation.

This function allows me to keep track of each joints orientation. But I also
need to have the latest position of the last joint. But since my robot is fixed
at the top the change in position of the last joint is the result of the upper
joints tilting/rotating rather than a direct change of position on the last
joint itself.

However, I am finding this very difficult to do. I either keep getting a value
of (0,0,0). Or a value of (5,1,0) which is the original position I specified
when drawing the last actor (a sphere) in the last joint
(sphereActor4->SetPosition(5,1,0);).

This is where I am having problems. Lines starting with a '->' denote lines
where I have tried different solutions:

//ROTATION IS THE SAME AS BELOW BUT USES AddOrientation(0,n,0);
// tilts Joint joint by t degrees
Joint& Joint::tilt(vtkAssembly *joint, float t)
{
        float n = check_tilt_range(t);      //check we are not hiting extremes
        joint->AddOrientation(0,0,n);       //do the tilting
        //joint->RotateZ(n);                //CHANGED TO AddOrientation INSTEAD

        m_renWin->Render();                 //render the new position
->//      joint->GetPosition(m_position);   //THIS WOULD GIVE (0,0,0)

->      vtkProp3DCollection* pc = vtkProp3DCollection::New();
->      pc = joint->GetParts();
->      pc->InitTraversal();
->      vtkProp3D* endProp = (vtkProp3D* )pc->GetLastProp3D();
->      endProp->GetPosition(m_position);       //THIS GIVES THE INITIAL SETUP
                                                //POSITION OF endProp

         //THE FOLLOWING GIVES (0,0,0)
->//        m_transform = vtkTransform::New();
->//        m_matrix = vtkMatrix4x4::New();
->//        joint->GetMatrix(m_matrix);
->//        m_transform->SetMatrix(m_matrix);
->//        m_transform->GetPosition(m_position);
->//        m_transform->Update();
        printf("\nCurrent position = %f,%f,%f.",
                 m_position[0],m_position[1],m_position[2]);
        return *this;
}

Whenever I get zero I also get garbage in the elements of the transform. I would
be most grate ful for any help and hints as to where I am going wrong.

Many thanks,
        Aroosha


-------------- next part --------------
A non-text attachment was scrubbed...
Name: LaraJointHierarchy.JPG
Type: image/jpeg
Size: 10240 bytes
Desc: not available
URL: <http://www.vtk.org/pipermail/vtkusers/attachments/20050826/77cc9c9f/attachment.jpeg>


More information about the vtkusers mailing list