[Insight-users] casting from void* to itk::Image
Navneeth Subramanian
navneeth.s at gmail.com
Fri Jan 7 10:11:20 EST 2011
Hi,
I am trying to cast some user data (void*) into an itk image as in the code
below:
~~~~~~~~~~~~~~~
#include "itkImage.h"
typedef itk::Image<unsigned char, 2> ImageType;
void myFunction(void* userData)
{
ImageType::Pointer myImage = reinterpret_cast< ImageType::Pointer
>(userData);
}
int main(int argc, char *argv[])
{
typedef itk::ImageFileReader<ImageType> ReaderType;
ReaderType::Pointer reader = ReaderType::New();
reader->SetFileName(argv[1]);
reader->Update();
ImageType::Pointer image = reader->GetOutput();
myFunction( image );
return EXIT_SUCCESS;
}
~~~~~~~~~~~~~~~~~~
However i keep running into this compile error:
1>d:\dev\src\ : error C2440: 'reinterpret_cast' : cannot convert from 'void
*' to 'itk::SmartPointer<TObjectType>'
1> with
1> [
1> TObjectType=itk::Image<unsigned char,2>
1> ]
1> Conversion requires a constructor or user-defined-conversion
operator, which can't be used by const_cast or reinterpret_cast
Any idea what I am doing wrong ?
many thanks,
navneeth
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.itk.org/pipermail/insight-users/attachments/20110107/c1b3852c/attachment.htm>
More information about the Insight-users
mailing list