[Insight-users] Extending a Transform?

Luis Ibanez luis.ibanez at kitware.com
Mon Feb 22 11:48:06 EST 2010


Hi Motes,


The problem  is with the line:


>  typedef itk::MyTransform<double,3,3> Transform;
>  Transform transform;


That's not how a transform can be instantiated.

You should do:


typedef itk::MyTransform<double,3,3> TransformType;

TransformType::Pointer transform = TransformType::New();


Just as you do with all other ITK classes that are managed
by smart pointers.


The compiler is telling you that the constructor of the transform
class is protected. On purpose, we make the constructor protected
in order to make sure that classes are instantiated via the New()
operator.


     Regards,


            Luis


-----------------------------------------------------------
On Sat, Feb 20, 2010 at 2:51 PM, motes motes <mort.motes at gmail.com> wrote:
> I am trying to write a transform that extends
> iktBsplineDeformableTransform. I have just copied the code from the
> code/common folder and renamed to BSplineDeformableTransform in the .h
> and .txx file to MyTransform and changed the class declaration to:
>
> template <
>    class TScalarType = double,          // Data type for scalars
>    unsigned int NDimensions = 3,        // Number of dimensions
>    unsigned int VSplineOrder = 3 >      // Spline order
> class ITK_EXPORT  MyTransform : public BSplineDeformableTransform<
> TScalarType, NDimensions, NDimensions >
> {
> public:
>
> I then create the transform like:
>
> #include "MyTransform.h"
> int main(){
>  typedef itk::MyTransform<double,3,3> Transform;
>  Transform transform;
>  return 0;
> }
>
>
>
>
> But when I compile I get:
>
>
> mort at mort-desktop:~/test/src/benchmark/build/release$ make
> [100%] Building CXX object CMakeFiles/benchmark.dir/main.cpp.o
> /home/mort/test/src/benchmark/MyTransform.txx: In function ‘int main()’:
> /home/mort/test/src/benchmark/MyTransform.txx:16: error:
> ‘itk::MyTransform<TScalarType, NDimensions,
> VSplineOrder>::MyTransform() [with TScalarType = double, unsigned int
> NDimensions = 3u, unsigned int VSplineOrder = 3u]’ is protected
> /home/mort/test/src/benchmark/main.cpp:5: error: within this context
> /home/mort/test/src/benchmark/MyTransform.txx:116: error:
> ‘itk::MyTransform<TScalarType, NDimensions,
> VSplineOrder>::~MyTransform() [with TScalarType = double, unsigned int
> NDimensions = 3u, unsigned int VSplineOrder = 3u]’ is protected
> /home/mort/test/src/benchmark/main.cpp:5: error: within this context
> In file included from /home/mort/test/src/benchmark/MyTransform.h:383,
>                 from /home/mort/test/src/benchmark/main.cpp:1:
> /home/mort/test/src/benchmark/MyTransform.txx: In constructor
> ‘itk::MyTransform<TScalarType, NDimensions,
> VSplineOrder>::MyTransform() [with TScalarType = double, unsigned int
> NDimensions = 3u, unsigned int VSplineOrder = 3u]’:
> /home/mort/test/src/benchmark/main.cpp:5:   instantiated from here
> /home/mort/test/src/benchmark/MyTransform.txx:17: error: type
> ‘itk::Transform<double, 3u, 3u>’ is not a direct base of
> ‘itk::MyTransform<double, 3u, 3u>’
> make[2]: *** [CMakeFiles/benchmark.dir/main.cpp.o] Error 1
> make[1]: *** [CMakeFiles/benchmark.dir/all] Error 2
> make: *** [all] Error 2
> mort at mort-desktop:~//test/src/benchmark/build/release$
>
> These errors are related to the 'protected' visibility. But why this
> error when I extend the BSplineDeformableTransform class?
>
> This error:
>
> ‘itk::Transform<double, 3u, 3u>’ is not a direct base of
> ‘itk::MyTransform<double, 3u, 3u>’
>
> also indicates that its no legal to extend from BSplineDeformableTransform.
>
> Any ideas?
> _____________________________________
> 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
>


More information about the Insight-users mailing list