[Insight-users] Access violation while creating smart pointer to RegistrationType

Siddharth Srivastava siddys at gmail.com
Sat Nov 5 01:52:34 EDT 2011


Hi all,
      I come with another problem with the same code as earlier:

// some preamble code

// I declare a registration type through:

printf("1\n");

typedef itk::ImageRegistrationMethod<BFrameType, BFrameType>
RegistrationType;
RegistrationType::Pointer registration = RegistrationType::New();

printf("2\n");

//Then I associate various things to it

registration->SetFixedImage(  ref ) ;
    registration->SetMovingImage( flt );

    registration->SetOptimizer( optimizer );
    registration->SetTransform( transform );
    registration->SetInterpolator (interpolator );
    registration->SetMetric( metric );

// rest of the code


After compiling (MSVC2010, Release mode), and running the application, I
get the following error:

 *System.AccessViolationException: Attempted to read or write protected
memory. This is often an indication that other memory is corrupt.*
Using the "printf" method of debugging, I can see that it prints 1, but not
2 above, implying that the creation of the smart pointer is throwing
the exception?

Curiously, the application runs to completion in the Debug mode. I am using
the appropriate Itk libs as per configuration (Debug, Release).
What could be going on here?

Thanks as always,
Sid.

On Fri, Nov 4, 2011 at 9:54 AM, Siddharth Srivastava <siddys at gmail.com>wrote:

> Hi Cagatay,
>       I sort of realised my error late last night! Thanks for the
> response.
> sid.
>
>
> On Fri, Nov 4, 2011 at 12:58 AM, cagatay bilgin <bilgincc at gmail.com>wrote:
>
>> Hi Siddharth,
>>
>> Try changing unsigned char to double here
>>
>> typedef itk::AffineTransform<unsigned char, 2> TransformType;
>>
>> From http://www.itk.org/Doxygen/html/classitk_1_1AffineTransform.html
>> "There are two template parameters for this class:
>>
>> ScalarT The type to be used for scalar numeric values. Either float or
>> double."
>> Regards,
>> Cagatay
>>
>> On Thu, Nov 3, 2011 at 1:58 PM, Siddharth Srivastava <siddys at gmail.com>wrote:
>>
>>> Hi ITK users,
>>>
>>>       I am trying to implement, following the example given in the ITK
>>> guide, an affine registration
>>> routine. Somewhere at the top of the code, I set
>>>
>>>     typedef itk::AffineTransform<unsigned char, 2> TransformType;
>>>     typedef itk::RegularStepGradientDescentOptimizer OptimizerType;
>>>     typedef itk::LinearInterpolateImageFunction< BFrameType, double >
>>> InterpolatorType;
>>>     typedef itk::MeanSquaresImageToImageMetric< BFrameType, BFrameType >
>>> MetricType;
>>>     typedef itk::ImageRegistrationMethod<BFrameType, BFrameType>
>>> RegistrationType;
>>>
>>> // then I create the necessary smart pointers to objects
>>>
>>>     TransformType::Pointer transform = TransformType::New();
>>>     OptimizerType::Pointer optimizer = OptimizerType::New();
>>>     InterpolatorType::Pointer interpolator = InterpolatorType::New();
>>>     RegistrationType::Pointer registration = RegistrationType::New();
>>>     MetricType::Pointer metric = MetricType::New();
>>>
>>> // and then I associate them to the registration filter:
>>>      registration->SetOptimizer( optimizer );
>>>     registration->SetTransform( transform ); // *error on this line*
>>>     registration->SetInterpolator (interpolator );
>>>     registration->SetMetric( metric );
>>>
>>> // including the reference and floating images
>>>
>>>     registration->SetFixedImage(  ref ) ;
>>>     registration->SetMovingImage( flt );
>>>
>>> during the build (on MS Visual studio 2010) I get the following error:
>>>
>>> Error    12    error C2664:
>>> 'itk::ImageRegistrationMethod<TFixedImage,TMovingImage>::SetTransform' :
>>> cannot convert parameter 1 from 'itk::SmartPointer<TObjectType>' to
>>> 'itk::Transform<TScalarType,NInputDimensions,NOutputDimensions> *'
>>>
>>> Can anyone help with useful insights?
>>>
>>> Thanks,
>>> Sid.
>>>
>>> _____________________________________
>>> 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/20111104/81ceb6ec/attachment.htm>


More information about the Insight-users mailing list