[vtkusers] Volume origin,bounds, extent question

Eric E. Monson emonson at cs.duke.edu
Mon Jan 19 17:22:04 EST 2009


Hey Bruce,

It really doesn't sound like this should be a problem if you're really  
talking about rotating the whole volume, even by these small amounts.  
Since this transformation, as you saw before, doesn't fit the  
definition of a permutation, I think you just need to apply a  
vtkTransformFilter to your data after the reader pulls it in.

xform = vtkTransform()::New();
xform->RotateZ(0.6467807);
xform->RotateX(-0.18608);
xform->RotateY(-0.49602);

xformFilter = vtkTransformFilter()::New();
xformFilter->SetInputConnection(original_volume_reader- 
 >GetOutputPort());
xformFilter->SetTransform(xform);

Talk to you later,
-Eric


On Jan 19, 2009, at 5:04 PM, Kall, Bruce A. wrote:

> Eric,
>
> Thanks.  Unfortunately my rotations are quite small (in one  
> particular volume,
> rotating about the center of the volume):
>
> Rotate around Z by: 0.6467807 degrees
> Rotate around X by: -0.18608 degrees
> Rotate around Y by: -0.49602 degrees
>
> It's enough though that if not done, coordinates of voxels on the  
> other
> side of the volume are incorrect (using an origin of lower left in  
> vtk). Seems
> like vtk just increments each voxel by the spacing to get from
> the lower left to the upper right coordinate. But even with these  
> small angular
> rotations, over a 256x256x86 volume with a voxel size of 0.977 it puts
> me off by about 3mm on the other size from what coordinates are  
> supposed to be.
>
> Any other suggestions?
>
> Bruce
>
>
>
> Eric E. Monson wrote:
>> Hey Bruce,
>>
>> (try to keep the discussion on-list)
>>
>> So what is your original align_matrix[][] -- is the issue that it's  
>> being changed after you assign the values to "matrix"?
>>
>> My suggestion was to use vtkTransform itself to calculate the  
>> transformation matrix. If you only do rotations in 90 degree  
>> increments and scalings of +/- 1, then the matrix will still be a  
>> permutation matrix. As I understand it, there is nothing that  
>> forces the transformation matrix in vtkTransform to be a  
>> permutation matrix, though, since it can do "a full range of linear  
>> (also known as affine) coordinate transformations in three  
>> dimesions". SetTransform() requires a permutation matrix, though,  
>> and I'm not sure how that is enforced.
>>
>> e.g. If you do:
>>
>> xform = vtk.vtkTransform()::New();
>> xform->RotateX(90);
>> xform->Scale(1, 1, -1);
>>
>> the matrix will be:
>>
>>        1 0 0 0
>>        0 -1.99673e-16 1 0
>>        0 1 1.99673e-16 0
>>        0 0 0 1
>>
>> Which would hopefully still qualify for the SetTransform() input.
>>
>> -Eric
>>
>>
>> On Jan 19, 2009, at 1:23 PM, Kall, Bruce A. wrote:
>>
>>> Eric,
>>>
>>> Thanks.  I think this is what I tried, but what I am getting back  
>>> after the SetTransform is the same xform
>>> which is not a permutation matrix (e.g., sum in all rows is 1.0).   
>>> Is there some step I am missing? I'm sending
>>> in my matrix (I called it align_matrix which is  double  
>>> align_matrix[4][4]) and then read back what my image
>>> reader has:
>>>
>>> Here's a code snippet right after I've calculated the transform I  
>>> want:
>>>
>>>> matrix = vtkMatrix4x4::New();
>>>> matrix->Identity();
>>>>
>>>> fprintf(stderr,"Setting VTK Matrix to align_matrix\n");
>>>> for(i = 0; i < 4; i++)
>>>> {
>>>> for(j = 0; j < 4; j++)
>>>>   {
>>>>   matrix->SetElement(i,j,align_matrix[i][j]);
>>>>   }
>>>> }
>>>>
>>>> printf("\n\n");
>>>> printf("FINAL VTK MATRIX Before Install\n");
>>>> for(i = 0;i < 4;i++)
>>>> {
>>>> for(j = 0;j < 4;j++)
>>>>   {
>>>>   e = matrix->GetElement(i,j);
>>>>   fprintf(stderr,"%12.5f  ",e);
>>>>   }
>>>> printf("\n");
>>>> }
>>>> printf("\n\n");
>>>>
>>>>
>>>> xform = vtkTransform::New();
>>>> xform->SetMatrix(matrix);
>>>> original_volume_reader->SetTransform(xform);
>>>> original_volume_reader->Update();
>>>>
>>>> vtkTransform *read_back_xform = original_volume_reader- 
>>>> >GetTransform();
>>>> vtkMatrix4x4 *read_back_matrix = read_back_xform->GetMatrix();
>>>>
>>>> printf("\n\n");
>>>> printf("Image Reader Transform\n");
>>>> double row_sum;
>>>> for(i = 0;i < 4;i++)
>>>> {
>>>> row_sum = 0.0;
>>>> for(j = 0;j < 4;j++)
>>>>   {
>>>>   e = read_back_matrix->GetElement(i,j);
>>>>   row_sum = row_sum + e;
>>>>   fprintf(stderr,"%12.5f  ",e);
>>>>   }
>>>> printf("     row_sum[%12.5f]\n",row_sum);
>>>> }
>>>> printf("\n\n");
>>>>
>>> and this is the output I get:
>>>
>>> Setting VTK Matrix to align_matrix
>>>
>>>
>>> FINAL VTK Affine MATRIX Before Install
>>>   0.99990       0.01129      -0.00862       0.00000     
>>> -0.01126       0.99993       0.00335       0.00000      
>>> 0.00866      -0.00325       0.99996       0.00000     
>>> -1.05445       1.22598      -0.63108       1.00000
>>>
>>>
>>>
>>> Image Reader Transform
>>>   0.99990       0.01129      -0.00862       0.00000        
>>> row_sum[     1.00257]
>>>  -0.01126       0.99993       0.00335       0.00000        
>>> row_sum[     0.99202]
>>>   0.00866      -0.00325       0.99996       0.00000        
>>> row_sum[     1.00537]
>>>  -1.05445       1.22598      -0.63108       1.00000        
>>> row_sum[     0.54045]
>>>
>>> My image volume is now a bunch of dots. If I send in an identity  
>>> matrix, it renders
>>> correctly, but with the wrong coordinates.
>>>
>>> Am I missing a step that converts the matrix into a permutation  
>>> matrix?
>>>
>>> Thanks in advance for any suggestions,
>>> Bruce
>>>
>>>
>>>
>>> Eric E. Monson wrote:
>>>> Hey Bruce,
>>>>
>>>> I'm not an expert in this, but it looks like you can create a  
>>>> vtkTransform object, set the rotation and translation on that  
>>>> object, and then feed this to the SetTransform method of your  
>>>> reader. This makes it easy to construct the required permutation  
>>>> matrix using a more intuitive interface (as long as what you're  
>>>> trying to do is really an affine transformation).
>>>>
>>>> Talk to you later,
>>>> -Eric
>>>>
>>>> ------------------------------------------------------
>>>> Eric E Monson
>>>> Duke Visualization Technology Group
>>>>
>>>>
>>>> On Jan 16, 2009, at 4:47 PM, Kall, Bruce A. wrote:
>>>>
>>>>> Anybody have any thoughts on my question from the other day?
>>>>> The only thing I can find in vtkImageReader is the SetTransform
>>>>> but that has to be a permutation matrix.  I need to rotate/ 
>>>>> translate.
>>>>> I've got the transform calculated, I just don't know where to  
>>>>> apply it.
>>>>>
>>>>> Thanks,
>>>>> Bruce
>>>>>
>>>>>
>>>>>
>>>>>> I'm reading in a premade (raw) image volume. I know the voxel  
>>>>>> size (same for all dimensions) as
>>>>>> well as the coordinates of all 8 corners of the volume.  I'm  
>>>>>> using vtkImageReader.
>>>>>>
>>>>>> This only seems to allow me to set the coordinate of the lower  
>>>>>> left voxel and the voxel size.
>>>>>>
>>>>>> How do you set the coordinate for another corner (e.g., upper  
>>>>>> right) so the coordinates
>>>>>> run in the direction I want using the fixed voxel size I have?   
>>>>>> Right now it seems to just
>>>>>> increment in the x,y,z dimensions by the voxel size and the  
>>>>>> coordinate of the upper right
>>>>>> is not correct (my volume is slightly oblique for lack of a  
>>>>>> better phrase).
>>>>>>
>>>>>>
>>>>>> _______________________________________________
>>>>>> This is the private VTK discussion list.
>>>>>> Please keep messages on-topic. Check the FAQ at: http://www.vtk.org/Wiki/VTK_FAQ
>>>>>> Follow this link to subscribe/unsubscribe:
>>>>>> http://www.vtk.org/mailman/listinfo/vtkusers
>>>>>>
>>>>> _______________________________________________
>>>>> This is the private VTK discussion list.
>>>>> Please keep messages on-topic. Check the FAQ at: http://www.vtk.org/Wiki/VTK_FAQ
>>>>> Follow this link to subscribe/unsubscribe:
>>>>> http://www.vtk.org/mailman/listinfo/vtkusers
>>>>
>>>>
>>
>>
> _______________________________________________
> This is the private VTK discussion list.
> Please keep messages on-topic. Check the FAQ at: http://www.vtk.org/Wiki/VTK_FAQ
> Follow this link to subscribe/unsubscribe:
> http://www.vtk.org/mailman/listinfo/vtkusers




More information about the vtkusers mailing list