Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Avoid memcpy when possible #37

Open
finetjul opened this issue Jun 26, 2014 · 1 comment
Open

Avoid memcpy when possible #37

finetjul opened this issue Jun 26, 2014 · 1 comment

Comments

@finetjul
Copy link

vtkIGTLToMRMLImage.cxx:326 (vtkIGTLToMRMLImage::IGTLToMRML), there is a coslty memcpy.

Instead, the pointer on the array could be passed to the vtkImageData array. For example (I did not try, but something like that could work):

switch(imageData->GetDataType())
   {
   vtkTemplateMacro(static_cast<vtkDataArrayTemplate<VTK_TT>* >(imageData->GetPointData()->GetScalars())->SetVoidArray(imgMsg->GetScalarPointer(), imgMsg->GetSubVolumeImageSize(), /*save*/1);
  }

Of course, the array memory should stay valid for as long as the imagedata is around.

See:
http://www.vtk.org/doc/nightly/html/classvtkDataArrayTemplate.html#a5d4281c3356c18a276ae7a8db8ca0c87
https://github.com/Slicer/Slicer/blob/master/Libs/vtkITK/vtkITKArchetypeImageSeriesScalarReader.cxx#L130-L132

@tokjun
Copy link
Contributor

tokjun commented Jul 11, 2014

Thanks for the suggestion. This is a bit tricky issue for the following reasons:

  1. Although the array format of the igtl::ImageMessage class is similar to VTK's, the array may contain values in different Endian. I'm not sure VTK can handle it properly. Probably we call memcpy() only when the array uses different Endian? I guess both external software and Slicer use the same Endian in most cases.
  2. A thread in the vtkMRMLIGTLConnectorNode will keep updating the array, while it is receiving image stream from external software. So the question is, what would happen if the array is being updated by another thread, while vtkImageData is handling the same array. (I guess it should be safe most of the time, because vtkMRMLIGTLConnectorNode uses circular buffer to pass received images from the connector thread to the main thread...)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants