Custom ParticleReader?

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/

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

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/

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);

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