[vtkusers] trouble rotating from new Origin vtkProp3D
Sergio Aguirre
sergio.aguirre at gmail.com
Wed Sep 7 14:16:00 EDT 2011
Hi everyone
I am trying to set the origin (the point about which all rotations take
place)
of a vtkActor through a vtkProp3D pointer.
My actor is generated from a series of images containing binary segmentation
masks
that I use to construct a surface through the pipeline below.
As I understand, because the vtkActor surface comes from ImageData whose
origin
are a corner of an image (x,y) and a image slice (z); when I rotate or
translate
the vtkActor it always rotates/translates from that point.
However, I would rather apply rotations/translations from a center of the
vtkActor
surface determined from its bounding box - which I use to calculate a center
and set
that point as a new origin for the actor. However, it has no effect and the
rotations
still apply from the original vtkImageData origin.
Is there a way to set the origin of the vtkActor surface? or do I need to
construct
a new copy surface actor independent of the vtkImageData to be able to set
an
origin at the center of its bounding box?
Any suggestions are appreciated.
Sergio
//// building the vtkActor from images
vtiReader = vtkXMLImageDataReader::New();
vtiReader->SetFileName("C:/code/epxZCTC_Demo/Debug/demo_103.vti");
vtiReader->WholeSlicesOff();
vtiReader->Update();
Image = vtkImageData::New();
Image->DeepCopy(vtiReader->GetOutput());
sgauss = vtkImageGaussianSmooth::New();
sgauss->SetInput(Image);
sgauss->SetDimensionality(3);
sgauss->SetStandardDeviation(0.25, 0.25, 0.25);
sgauss->SetRadiusFactor(1);
Cubes = vtkMarchingCubes::New();
Cubes->SetInputConnection(sgauss->GetOutputPort());
Cubes->SetNumberOfContours(1);
Cubes->ComputeScalarsOff();
Cubes->ComputeGradientsOff();
Cubes->ComputeNormalsOff();
Cubes->SetValue(0,255);
smoother = vtkSmoothPolyDataFilter::New();
smoother->SetInputConnection(Cubes->GetOutputPort());
smoother->SetNumberOfIterations(300);
smoother->SetRelaxationFactor(0.01);
smoother->SetFeatureAngle(60);
smoother->FeatureEdgeSmoothingOff();
smoother->BoundarySmoothingOff();
smoother->SetConvergence(0);
normals = vtkPolyDataNormals::New();
normals->SetInputConnection(Cubes->GetOutputPort());
normals->FlipNormalsOn();
strips = vtkStripper::New();
strips->SetInputConnection(smoother->GetOutputPort());
Mapper = vtkPolyDataMapper::New();
Mapper->SetInputConnection(strips->GetOutputPort());
Mapper->ScalarVisibilityOff();
Actor = vtkActor::New();
Actor->SetMapper(colonMapper);
Actor->GetProperty()->SetDiffuseColor(1.0, 0.65, 0.65);
Actor->GetProperty()->SetDiffuse(0.70);
Actor->GetProperty()->SetSpecular(0.3);
Actor->GetProperty()->SetSpecularPower(10);
// setting a new origin for rotations
vtkProp3D* picked_object = (vtkProp3D*) propList->GetItemAsObject(object);
double tip[3], bounds[6], icenter[3], center[3], trans[3];
UpdateLaser(styPoseE, tip); // get Tip - new position for translation
picked_object->GetBounds(bounds); // picked_object get bounds
icenter[0] = (bounds[1]-bounds[0])/2; // initial center
icenter[1] = (bounds[3]-bounds[2])/2;
icenter[2] = (bounds[5]-bounds[4])/2;
picked_object->SetOrigin(icenter); // set origin to initial center
picked_object->SetPosition(icenter);
center[0] = tip[0]-icenter[0];
center[1] = tip[1]-icenter[1];
center[2] = tip[2]-icenter[2];
trans[0] = center[0]+icenter[0]; // translation delta
trans[1] = center[1]+icenter[1];
trans[2] = center[2]+icenter[2];
objMtx = vtkMatrix4x4::New();
picked_object->GetMatrix(objMtx); // store picked_object current position +
rotation
objMtx->SetElement(0,3, 0.0);
objMtx->SetElement(1,3, 0.0);
objMtx->SetElement(2,3, 0.0);
objMtx->SetElement(3,3, 1.0);
rotMtx = vtkMatrix4x4::New();
rotMtx->Identity();
rotMtx->SetElement(0,0, 0.9961); // rotation matrix to apply
rotMtx->SetElement(0,2, 0.0871);
rotMtx->SetElement(2,0, -0.0871);
rotMtx->SetElement(2,2, 0.9961);
t = vtkTransform::New();
t->Identity();
t->Translate(trans[0], trans[1], trans[2]);
t->Concatenate(objMtx); // concatenate current obj transformation matrix
t->Concatenate(rotMtx); // concatenate rotation delta
t->Translate(-icenter[0], -icenter[1], -icenter[2]);
nMtx = vtkMatrix4x4::New();
nMtx->DeepCopy(t->GetMatrix());
picked_object->PokeMatrix(nMtx);
this->RenWin->Render();
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.vtk.org/pipermail/vtkusers/attachments/20110907/2042eec2/attachment.htm>
More information about the vtkusers
mailing list