[vtkusers] Rotating 1D data in 3D space

KK krishna at lucidindia.net
Wed May 7 11:19:52 EDT 2003


Hi
I have  problem  with rotating 1D data in 3D  space using vtkTransform and
vtkImageReslice.Here i'm placing the code and the output produced.Can
anybody explain the mistake which i'm making because of which i'm getting
wrong results.

****** Code used for rotation 1D data in 3D space using vtkImageReslice ****

 int x,y,z;
 x = 4; y =1; z = 1;
 int ox = 8, oy = 8,oz = 1;
 vtkStructuredPoints *sp = vtkStructuredPoints::New();
 sp->SetDimensions(x,y,z);
 sp->SetOrigin(0, 0, 0);
 sp->SetSpacing(1.0,1.0,1.0);

 vtkStructuredPoints *osp = vtkStructuredPoints::New();
 osp->SetDimensions(ox,oy,oz);
 osp->SetOrigin(0, 0, 0);
 osp->SetSpacing(0.5,0.5,1.0);
 vtkUnsignedShortArray *oscalars = vtkUnsignedShortArray::New();



 vtkUnsignedShortArray *scalars = vtkUnsignedShortArray::New();
 int i = 0;
 unsigned char Data[125];
 for( i = 0; i < 125; i++)
  Data[i] = (unsigned char)i;

 scalars->SetNumberOfTuples(1);
 scalars->SetNumberOfValues(x*y*z);

 i = 0;
 for(int iz = 0; iz < z; iz++)
 {
  int zoffset = iz * x * y;
  for(int ix = 0; ix < x; ix++)
  {
   for(int iy = 0;iy < y ; iy++)
   {
    int offset = zoffset+iy*x+ix;
    unsigned short val = static_cast<unsigned short>(offset);
    scalars->SetValue(offset,val);
   }
  }
 }
 sp->SetNumberOfScalarComponents(1);
 sp->GetPointData()->SetScalars(scalars);

 vtkTransform* t = vtkTransform::New();
 t->PostMultiply();
 t->Identity();
 t->RotateWXYZ(45,0,0,1);


 vtkImageReslice* ir = vtkImageReslice::New();

 ir->SetInterpolationModeToLinear();
 ir->SetOutputOrigin(0.0, 0.0, 0.0);
 ir->SetInput(sp);
 ir->SetResliceTransform(t);
 ir->AutoCropOutputOn();
 ir->Update();
 vtkImageData* id = ir->GetOutput();
 vtkUnsignedShortArray *newdata =
(vtkUnsignedShortArray*)id->GetPointData()->GetScalars();

 printf("\n");
 float oldCOs[3];
 float newCOs[3];
 for( i = 0; i < id->GetNumberOfPoints(); i++)
 {
  id->GetPoint(i, newCOs);
  printf("\n(%f, %f, %f\t%d)", newCOs[0], newCOs[1], newCOs[2],
newdata->GetValue(i));
 }
 printf("\n");
 for( i = 0; i < sp->GetNumberOfPoints(); i++)
 {
  sp->GetPoint(i, oldCOs);
  printf("\n(%f, %f, %f\t%d)", oldCOs[0], oldCOs[1],
oldCOs[2],scalars->GetValue(i));
 }
 printf("\n");

************ End of code *********************

************ Output produced ******
///This is after Transformation(rotate by 45 degrees)
(0.000000, 0.000000, 0.000000   0)
(1.000000, 0.000000, 0.000000   1)
(2.000000, 0.000000, 0.000000   0)
(0.000000, 1.000000, 0.000000   0)
(1.000000, 1.000000, 0.000000   0)
(2.000000, 1.000000, 0.000000   0)
(0.000000, 2.000000, 0.000000   0)
(1.000000, 2.000000, 0.000000   0)
(2.000000, 2.000000, 0.000000   0)

///This is the input data
(0.000000, 0.000000, 0.000000   0)
(1.000000, 0.000000, 0.000000   1)
(2.000000, 0.000000, 0.000000   2)
(3.000000, 0.000000, 0.000000   3)
************End of output




More information about the vtkusers mailing list