# Custom ParticleReader?

**URL:** https://discourse.vtk.org/t/custom-particlereader/2473
**Category:** Support
**Created:** [January 21, 2020, 5:49pm UTC](https://discourse.vtk.org/t/custom-particlereader/2473 "2020-01-21T17:49:20Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![Ahmed\_Salih](https://discourse.vtk.org/user_avatar/discourse.vtk.org/ahmed_salih/32/1164_2.png) [@Ahmed\_Salih](https://discourse.vtk.org/u/Ahmed_Salih)
#### Post date: [January 21, 2020, 5:49pm UTC](https://discourse.vtk.org/t/custom-particlereader/2473/1 "2020-01-21T17:49:20Z")

</div>

Hello!

I am new to this forum and new to C programming in general, but having a lot of fun, so please bear with me.

Currently I am working with this great example:

[https://lorensen.github.io/VTKExamples/site/Cxx/IO/ParticleReader/](https://lorensen.github.io/VTKExamples/site/Cxx/IO/ParticleReader/)

Which I have understood and gotten to work properly. Now my problem is that I want to work with binary files - I am aware that this reader tool is capable of reading binary files, but the binary files I am working with have a very special structure in that they contain a lot of different data (position,velocity,density etc.) and small headers / comments in between - therefore the standard reader tool is not sufficient. Instead I have been working on a tool which can extract my data and place it in pointers - so my question is if someone could show me how to transform these lines of codes from the link;

vtkSmartPointer reader =  
vtkSmartPointer::New();

reader-\>SetFileName ( filePath.c\_str() );  
// if nothing gets displayed or totally wrong, swap the endianness  
reader-\>SetDataByteOrderToBigEndian();  
reader-\>Update();

// Visualize  
vtkSmartPointer mapper =  
vtkSmartPointer::New();  
mapper-\>SetInputConnection(reader-\>GetOutputPort());  
std::cout \<\< "number of pieces: " \<\< mapper-\>GetNumberOfPieces() \<\< std::endl;  
mapper-\>SetScalarRange(4, 9);

vtkSmartPointer actor =  
vtkSmartPointer::New();

actor-\>SetMapper(mapper);  
actor-\>GetProperty()-\>SetPointSize(4);

So that instead of using the native reader, I would be able to point the mapper to some kind of pointer holding information for xyz etc. and do the correct vizualisation in VTK. If anybody with more knowledge and some spare time, could just show me how to do this with some arbitrary data in a pointer I would be happy.

Kind regards

P.S. please all do tell me how to format code correctly, I couldn’t get it to work sorry

---

<div class="post-metadata">

### Author: ![Andrew](https://discourse.vtk.org/user_avatar/discourse.vtk.org/andrew/32/3861_2.png) [@Andrew](https://discourse.vtk.org/u/Andrew)
#### Post date: [January 25, 2020, 6:52am UTC](https://discourse.vtk.org/t/custom-particlereader/2473/2 "2020-01-25T06:52:07Z")

</div>

Can you copy the data to one of VTKs data structures? That would certainly be the easiest solution.

vtkParticleReader outputs a vtkPolyData which is then rendered with vtkPolyDataMapper. You could follow something similar to this example: [https://lorensen.github.io/VTKExamples/site/Cxx/PolyData/ColoredPoints/](https://lorensen.github.io/VTKExamples/site/Cxx/PolyData/ColoredPoints/)

Additionally scalars can be added by creating a vtk array, such as a vtkDoubleArray and adding that to the poly data’s PointData.

```
polyData->GetPointData()->SetScalars(your array here);
```

---

<div class="post-metadata">

### Author: ![Ahmed\_Salih](https://discourse.vtk.org/user_avatar/discourse.vtk.org/ahmed_salih/32/1164_2.png) [@Ahmed\_Salih](https://discourse.vtk.org/u/Ahmed_Salih)
#### Post date: [January 26, 2020, 3:30pm UTC](https://discourse.vtk.org/t/custom-particlereader/2473/3 "2020-01-26T15:30:25Z")

</div>

Thank you for your suggestion! I will look at this through February and will post some updates of progress / where I get stuck etc.

Kind regards
