question about Getpointer of the vktSmartPointer

Hello,

I try to send the vtk object between different services and manage the data object by a particular data structure, but I’m not clear why I can not get the raw pointer and assign it to void* from the GetPointer operation of the vtkSmartPointer

For this sample code

      vtkSmartPointer<vtkCharArray> recvbuffer = vtkSmartPointer<vtkCharArray>::New();
      // ... put marshaled data into the recvbuffer
      // ...
      // unmarshal
      vtkSmartPointer<vtkDataObject> recvobj = vtkCommunicator::UnMarshalDataObject(recvbuffer);

      //vtkSmartPointer<vtkDataObject> temp = recvobj; //ok
      //vtkDataObject* temp = recvobj.Get(); //error
      void* temp = (void*)recvobj.GetPointer(); //error

I got this error message when the left side is void* temp or vtkDataObject* temp

In file included from /global/u2/z/zw241/cworkspace/src/VTK/Common/Core/vtkGenericDataArray.h:73,
                 from /global/u2/z/zw241/cworkspace/src/VTK/Common/Core/vtkAOSDataArrayTemplate.h:36,
                 from /global/u2/z/zw241/cworkspace/src/VTK/Common/Core/vtkCharArray.h:27,
                 from /global/homes/z/zw241/cworkspace/src/Gorilla/server/unimosserver.cpp:29:
/global/u2/z/zw241/cworkspace/src/VTK/Common/Core/vtkSmartPointer.h: In instantiation of 'T* vtkSmartPointer<ArrayType>::GetPointer() const [with T = vtkDataObject]':

/global/homes/z/zw241/cworkspace/src/Gorilla/server/unimosserver.cpp:710:45:   required from here
/global/u2/z/zw241/cworkspace/src/VTK/Common/Core/vtkSmartPointer.h:181:43: error: invalid static_cast from type 'vtkObjectBase* const' to type 'vtkDataObject*'
   T* GetPointer() const noexcept { return static_cast<T*>(this->Object); }

Thanks a lot for your help!

It looks that we can use this function to marshal the data into a specific type of the data object

1 Like