[vtkusers] How to apply Transformations to STL objects
MIRG UTM
mirgvtk at gmail.com
Mon Mar 19 00:43:12 EDT 2007
Hi VTK gurus
I am working on medical data, I have two pieces of bone in STL format and I
have to align second with the first one and then merge both to form a single
object. I am new to VTK and donot know exactly how to do. I tried to move
the second bone by using vtkActor methods (RotateX, RotateY, AddPosition
etc) but these only move the rendered pipeline and actual object data does
not change. Then I tried to change the data manually by using
"vtkMatrix4x4", I could get the point data from STL object and change it by
applying transformation, but I donot know how to set this changed point data
back to the STL object. If any one can please help me how to do this. Is
there any other easy way to do the same?
Here is code snippit;
stlReader = vtkSTLReader::New();
stlReader->SetFileName("stlFile.stl");
// here goes other rendering stuff
//get PolyData from the STL object
vtkPolyData *pd = vtkPolyData::New();
pd = stlReader->GetOutput();
int n1 = pd->GetNumberOfPoints();
// get points data from PolyData object
vtkPoints *a = pd->GetPoints();
vtkMatrix4x4 *t = vtkMatrix4x4::New();
t->Identity();
t->SetElement(0, 3, 5.0);
t->SetElement(1, 3, 0.0);
t->SetElement(2, 3, 0.0);
double *p, pin[4], pout[4];
for (int i=0; i<n1;i++)
{
p = a->GetPoint(i);
pin[0] = p[0]; pin[1] = p[1]; pin[2] = p[2]; pin[3] = 1;
t->MultiplyPoint(pin, pout);
p[0]=pout[0]; p[1]=pout[1]; p[2]=pout[2];
a->SetPoint(i, p);
}
// return updated points to PolyData object
pd->SetPoints(a);
// upto here the code is OK, but after this I donot know how to return
// this changed PolyData object back to the 'stlReader'
// I have tried to use the following
this->vtkReaderSoft->SetInputConnection(reinterpret_cast<vtkAlgorithmOutput*>(pd));
// but it gives the following runtime error
ERROR: In D:\Softwares\VTK5.0\Source\Filtering\vtkAlgorithm.cxx, line 567
vtkSTLReader (0x0288BDA8): Attempt to connect input port index 0 for an
algorithm with 0 input ports.
Please help me to solve this and then how to merge two STL objects into a
single object using operations like UNION, INTERSECTION, DIFFERENCE etc.
Thanks in advance.
MIRG
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.vtk.org/pipermail/vtkusers/attachments/20070319/e13ba66d/attachment.htm>
More information about the vtkusers
mailing list