# VTK VolumeRendering.How to process .txt file data

**URL:** <https://discourse.vtk.org/t/vtk-volumerendering-how-to-process-txt-file-data/12553>\
**Category:** Development\
**Created:** [October 27, 2023, 7:57am UTC](https://discourse.vtk.org/t/vtk-volumerendering-how-to-process-txt-file-data/12553 "2023-10-27T07:57:06Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![cityW](https://discourse.vtk.org/letter_avatar_proxy/v4/letter/c/82dd89/32.png) [@cityW](https://discourse.vtk.org/u/cityW)\
**Post date:** [October 27, 2023, 7:57am UTC](https://discourse.vtk.org/t/vtk-volumerendering-how-to-process-txt-file-data/12553/1 "2023-10-27T07:57:06Z")

</div>

Hello everyone,  
I am a beginner to VTK.I’m trying to volume render with vtk C++ in VS.  
My teacher sent me a txt file and asked me to perform volume rendering on the data inside.  
In the past few days, I have studied some VTK cases and successfully rendered some .vtk and .mhd format documents.But I don’t know how to process txt format documents.

The document content is as follows：

 ![R3OYGNI594{MS~LNH0}$(4](https://discourse.vtk.org/uploads/default/original/2X/7/775f5e33d9853efb709747c68f424640b49d157f.png)

Model data only knows size：100_100_240

What should I do with this data？Thanks！！

---

<div class="post-metadata">

**Author:** ![sankhesh](https://discourse.vtk.org/user_avatar/discourse.vtk.org/sankhesh/32/73_2.png) [@sankhesh](https://discourse.vtk.org/u/sankhesh)\
**Post date:** [October 27, 2023, 2:04pm UTC](https://discourse.vtk.org/t/vtk-volumerendering-how-to-process-txt-file-data/12553/2 "2023-10-27T14:04:31Z")

</div>

You can read the text file into a buffer using STL filestream and then use `vtkImageImport` to set the buffer as the scalar array on a vtkImageData.

---

<div class="post-metadata">

**Author:** ![cityW](https://discourse.vtk.org/letter_avatar_proxy/v4/letter/c/82dd89/32.png) [@cityW](https://discourse.vtk.org/u/cityW)\
**Post date:** [October 27, 2023, 2:10pm UTC](https://discourse.vtk.org/t/vtk-volumerendering-how-to-process-txt-file-data/12553/3 "2023-10-27T14:10:35Z")

</div>

> [@cityW](#):
>
> _100_240

This is my script：

std::ifstream file(“data501.txt”);  
std::vectordata;  
float value;

```
while (file>>value)
{
	data.push_back(value);
}

vtkSmartPointer<vtkImageData>imagedata =
	vtkSmartPointer<vtkImageData>::New();
imagedata->SetDimensions(100, 100, 240);
imagedata->AllocateScalars(VTK_FLOAT,1);

```

And then what should I do？Thank you very much

---

<div class="post-metadata">

**Author:** ![sankhesh](https://discourse.vtk.org/user_avatar/discourse.vtk.org/sankhesh/32/73_2.png) [@sankhesh](https://discourse.vtk.org/u/sankhesh)\
**Post date:** [October 27, 2023, 2:43pm UTC](https://discourse.vtk.org/t/vtk-volumerendering-how-to-process-txt-file-data/12553/4 "2023-10-27T14:43:51Z")

</div>

See [https://examples.vtk.org/site/Cxx/Images/ImageImport/](https://examples.vtk.org/site/Cxx/Images/ImageImport/)
