[Insight-users] Direct memory access to a vector field

Luis Ibanez luis.ibanez at kitware.com
Sat Oct 30 19:45:59 EDT 2010


Hi Demian,

Yeap,
strictly speaking, that buffer that you are providing to the method

                                           SetImportContainer()

should be a pointer to a VectorPixelType array.

However,
the itk::Vector class essentially contain just an array of T elements.

So, if you allocate an array of NPixels * 3 of doubles, and you
to the Import Container, things should go well...

image->GetPixelContainer()->
>
> SetImportPointer( bufferVectorImage,

            (VectorPixelType)bufferVectorImageSize, false );


or

image->GetPixelContainer()->
>
> SetImportPointer( bufferVectorImage,

            reinterpret_cast<VectorPixelType>(bufferVectorImageSize), false
);


----

Note also, that some compilers & some architectures may
decided to pad a type such as the itk::Vector, in which case,
the three doubles of one vector will not be just next to the
three doubles of the next vector...


    Luis


--------------------------------------------------------------------------------
On Tue, Oct 26, 2010 at 3:03 PM, Demian Wassermann
<demian at bwh.harvard.edu>wrote:

> Hi to all,
>
> I have a small problem, I want to interface ITK with python, I've used some
> of Steve Pieper's code (
> http://www.slicer.org/slicerWiki/index.php/Slicer3:Python:pitky ) and I've
> been successful in the scalar case however I need to interface a vector
> field.
>
> More precisely:
>
>  typedef itk::Image< double, Dimension >     ImageType;
>  ImageType::Pointer fixedImage = ImageType::New();
>  image->GetPixelContainer()->SetImportPointer( bufferImage,
> bufferImageSize, false );
>
> works like a charm. However if the image type changes to:
>
>  typedef itk::Vector< double, Dimension >    VectorPixelType;
>  typedef itk::Image   < VectorPixelType, Dimension >
>  VectorFieldType;
>
> The line
>
> image->GetPixelContainer()->SetImportPointer( bufferVectorImage,
> bufferVectorImageSize, false );
>
> does not seem to work as the element on each of the voxels is a
> VectorPixelType and not a straight double.
>
> hence bufferVectorImage must be of type VectorPixelType* and not double*
>
> Any ideas?
>
> Thanks!
>
> Demian
>
>
> --
> Demian Wassermann, PhD
> demian at bwh.harvard.edu
> LMI / PNL / SPL Labs
> Harvard Medical School
> Brigham and Women's Hospital
> 1249 Boylston, Boston, MA, USA
>
> _____________________________________
> Powered by www.kitware.com
>
> Visit other Kitware open-source projects at
> http://www.kitware.com/opensource/opensource.html
>
> Kitware offers ITK Training Courses, for more information visit:
> http://www.kitware.com/products/protraining.html
>
> Please keep messages on-topic and check the ITK FAQ at:
> http://www.itk.org/Wiki/ITK_FAQ
>
> Follow this link to subscribe/unsubscribe:
> http://www.itk.org/mailman/listinfo/insight-users
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.itk.org/pipermail/insight-users/attachments/20101030/a1f80573/attachment.htm>


More information about the Insight-users mailing list