# Python wrappers for a templated class derived from vtkMRMLNode

**URL:** <https://discourse.slicer.org/t/python-wrappers-for-a-templated-class-derived-from-vtkmrmlnode/26238>\
**Category:** Development\
**Created:** [November 14, 2022, 4:29pm UTC](https://discourse.slicer.org/t/python-wrappers-for-a-templated-class-derived-from-vtkmrmlnode/26238 "2022-11-14T16:29:04Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![adeguet1](https://avatars.discourse-cdn.com/v4/letter/a/aeb1de/32.png) [@adeguet1](https://discourse.slicer.org/u/adeguet1)\
**Post date:** [November 14, 2022, 4:29pm UTC](https://discourse.slicer.org/t/python-wrappers-for-a-templated-class-derived-from-vtkmrmlnode/26238/1 "2022-11-14T16:29:04Z")

</div>

Hello,

I’m trying to figure out if I can use C++ templates for a vtkMRMLNode. My current implementation has the following classes (pseudo-code):

```auto
/// generic base class so I can have containers of all my nodes
class vtkMRMLMyBaseNode: public vtkMRMLNode
{
public:
   virtual void MyMethod(void) = 0;
};

/// templated class
template <typename _some_type>
class vtkMRMLMyTemplatedNode: public vtkMRMLMyBaseNode
{
public:
  void GetValue(_some_type & result) const;
}

/// my template specialization:
typedef vtkMRMLMyTemplatedNode<double> vtkMRMLMyDoubleNode ;

```

Note that I skipped the code to support ::New(), hidden constructor and destructor, etc for conciseness. At that point I can create nodes using the specialized types in C++. I can see the nodes in the MRML scene but I run into a small (and expected) issue with the python interpreter. When I retrieve the node, I get the correct type but I can only access the methods from the MyBase class (MyMethod) but not the methods from the templated class (GetValue). I expected this to happen this I never “indicated” that the wrapping process should create wrappers for my specialization (aka typedef). I used SWIG in the past and needed to explicitly call %template. Is there an equivalent in VTK/Slicer to explicitly require wrappers for a template specialization?

---

<div class="post-metadata">

**Author:** ![lassoan](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/lassoan/32/13_2.png) [@lassoan](https://discourse.slicer.org/u/lassoan)\
**Post date:** [November 14, 2022, 8:50pm UTC](https://discourse.slicer.org/t/python-wrappers-for-a-templated-class-derived-from-vtkmrmlnode/26238/2 "2022-11-14T20:50:13Z")

</div>

VTK classes are wrapped with the VTK Python wrapper. This wrapper does not support templates in the public interface of the class (with a few very specific exceptions). You need to move any templated methods to private implementation an you can use VTK objects to get/set values of any type (e.g., vtkVariant for a single value VTK data arrays for efficient, zero-copy transfer of large arrays of any type).
