EnSight reader example (C++)

Hello,

I’m trying to read EnSight Gold data using the VTK library for C++.

Unfortunately I didn’t find any example for this files type, and since my global knowledge in C++ is far from being perfect, I didn’t managed so far to solve my issues by going through the VTK manual…

Here is what I did… and which worked :slightly_smiling_face:

#include <vtkSmartPointer.h>
#include <vtkGenericEnSightReader.h>

#include <vtkProperty.h>
#include <vtkCellCenters.h>

int main ( int argc, char *argv[] )
{
//parse command line arguments
if(argc < 2)
{
std::cerr << “Usage: " << argv[0]
<< " Filename(.case)” << std::endl;
return EXIT_FAILURE;
}

std::string filename = argv[1];

//read all the data from the file
vtkSmartPointer reader =
vtkSmartPointer::New();
reader->SetCaseFileName(filename.c_str());
reader->Update();

//Check for data content
reader->PrintSelf(std::cout, vtkIndent(2));

return EXIT_SUCCESS;
}

My goal would be

  • First, to extract the cell center coordinates for each cells (the CellCenter filter might be helpful, but I wasn’t able to push data into it…)
  • Go through every scalar and vector data (Cell Data) for every cell, one time step at a time

If needed to better understand my case study, here the case file of my data:

FORMAT
type: ensight gold

GEOMETRY
model: square.geo

VARIABLE
scalar per element: 1 Pressure square.pressure.*****
vector per element: 1 U1 square.u1.*****

TIME
time set: 1
number of steps: 3
filename start number: 1
filename increment: 1
time values:
0
10
20

Thank you very much for your help, I’m tried anything possible for a week but I think I reached the maximum of what I can achieve by myself :slight_smile:

Up !

Since last time I managed to extract scalar data from a given cell, but it is the dirtiest way and I’m pretty sure there is a cleaner way to do it using vtk specific tools (filters, pipelines …)

//Select iteration 3
int itime = 3;
reader->SetTimeValue(m_reader->GetTimeSets()->GetItem(0)->GetTuple1(itime));
reader->Update();
// Ouptut scalar pressure of cell 1000
vtkSmartPointer pressure = reader->GetOutput()->GetBlock(0)->GetAttributes(vtkCompositeDataSet::CELL)->GetScalars (“pressure”);

int icell = 1000;
cout << pressure->GetTuple1(icell) << endl;