# Write to vtkImageData using parallel threads

**URL:** https://discourse.vtk.org/t/write-to-vtkimagedata-using-parallel-threads/5423
**Category:** Support
**Created:** [March 23, 2021, 6:28am UTC](https://discourse.vtk.org/t/write-to-vtkimagedata-using-parallel-threads/5423 "2021-03-23T06:28:50Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![janhavi\_deshpande](https://discourse.vtk.org/user_avatar/discourse.vtk.org/janhavi_deshpande/32/1774_2.png) [@janhavi\_deshpande](https://discourse.vtk.org/u/janhavi_deshpande)
#### Post date: [March 23, 2021, 6:28am UTC](https://discourse.vtk.org/t/write-to-vtkimagedata-using-parallel-threads/5423/1 "2021-03-23T06:28:50Z")

</div>

Hello,  
I am working in C# and I am currently using setScalarComponentFromDouble function of vtkImageData to set values to ImageData grid. This function is not thread-safe. I have also tried getting image pointer through ImageData.GetScalarPointer() and then setting value to this pointer which is also not thread-safe. Is it possible to populate vtkImageData using parallel code?

Thank you,  
Janhavi

---

<div class="post-metadata">

### Author: ![will.schroeder](https://discourse.vtk.org/user_avatar/discourse.vtk.org/will.schroeder/32/233_2.png) [@will.schroeder](https://discourse.vtk.org/u/will.schroeder)
#### Post date: [March 23, 2021, 11:00am UTC](https://discourse.vtk.org/t/write-to-vtkimagedata-using-parallel-threads/5423/2 "2021-03-23T11:00:13Z")

</div>

Yes of course, in C++ we use threading all the time to populate images. So it should be doable, although I haven’t coded in C# for years.

Have you tried (and this is incorrect C# code but hopefully it will provide hints): 1) use img.AllocateScalars(int dataType, int numComponents); then 2) obtaining the data array arr=img.GetPointData().GetScalars(); finally use some variant of SetTuple (e.g., arr.SetTuple1(id,value)) to populate the image data?
