[vtkusers] reading vti file with multiple dataarrays

Waldin Nicholas nwaldin at student.ethz.ch
Tue Jul 23 09:19:39 EDT 2013


Hi everyone,


Basically I have a vti file with multiple dataarrays. I want to create a contour filter based on one of the arrays. But for some reason all I'm getting is zeros out of the file. I've removed the later part of the code (contour filter and stuff after it) and left the reading part in. The Contour-filter stuff is the usual "setinputconnection(x->getoutputport)". Instead I added a part where I print part of the data to the command line.

Anyone know what I'm doing wrong?


the xml part of the file

<VTKFile type="ImageData" version="0.1" byte_order="LittleEndian">
  <ImageData WholeExtent="0 119 0 119 0 119" Origin="0 0 0" Spacing="500000 500000 500000">
    <Piece Extent="0 119 0 119 0 119">
      <PointData Scalars="div_B_(???)">
        <DataArray type="Float32" Name="velocity_(cm_s)" NumberOfComponents="3" format="appended" RangeMin="1384237.9406"         RangeMax="7378847219.9"         offset="0"                   />
        <DataArray type="Float32" Name="magnetic_field_(Gauss)" NumberOfComponents="3" format="appended" RangeMin="2.2244114442e+11"     RangeMax="2.0786569987e+16"     offset="20736004"            />
        <DataArray type="Float32" Name="density_rho_(g_cm^3)" format="appended" RangeMin="86074216"             RangeMax="3.325061004e+14"      offset="41472008"            />
        <DataArray type="Float32" Name="entropy_s_(kB_baryon)" format="appended" RangeMin="0.50499993563"        RangeMax="40.273681641"         offset="48384012"            />
        <DataArray type="Float32" Name="electron_fraction_Ye_()" format="appended" RangeMin="0.27528589964"        RangeMax="0.48046275973"        offset="55296016"            />
        <DataArray type="Float32" Name="gravitational_potential_phi_(erg_g)" format="appended" RangeMin="-1.517959541e+20"     RangeMax="-3.7108132608e+18"    offset="62208020"            />
        <DataArray type="Float32" Name="div_B_(???)" format="appended" RangeMin="-1.9072103896e-09"    RangeMax="2.0322659111e-09"     offset="69120024"            />
      </PointData>
      <CellData>
      </CellData>
    </Piece>
  </ImageData>
  <AppendedData encoding="raw">




CODE:



  std::string inputFilename = "s15t-652.vti";

// Read the file
  vtkSmartPointer<vtkXMLImageDataReader> reader =
    vtkSmartPointer<vtkXMLImageDataReader>::New();
  reader->SetFileName(inputFilename.c_str());

  reader->UpdateInformation();


int numScal = reader->GetNumberOfPointArrays();
 std::cout << numScal << std::endl;
std:: cout << "numer of arrays in file: " << numScal << std::endl;

for (int i = 0; i< numScal; i++){
 std::cout << "Array " << i << " :" << reader->GetPointArrayName(i) << std::endl;
 std::cout << "status of " << i << " :" << reader->GetPointArrayStatus( reader->GetPointArrayName(i)) << std::endl;
}


for (int i = 0; i< numScal; i++){

reader->SetPointArrayStatus(reader->GetPointArrayName(i),0);
}

//std::string name = "entropy_s_(kB_baryon)";
std::string name = "density_rho_(g_cm^3)";
char * cname = (char*) name.c_str();
reader->SetPointArrayStatus(cname, 1);
for (int i = 0; i< numScal; i++){
 std::cout << "Array " << i << " :" << reader->GetPointArrayName(i) << std::endl;
 std::cout << "status of " << i << " :" << reader->GetPointArrayStatus( reader->GetPointArrayName(i)) << std::endl;
}

reader->Update();




//vtkImageData* data = reader->GetOutput();
int *dims = reader->GetOutput()->GetDimensions();
float min=100000000, max=-1111111;
std::cout <<"dims 0 " << dims[0] << " 1 " << dims[1] << " 2 " << dims[2] << std::endl;

for (int i = 0; i< dims[2]; i++){
    for (int j=0; j<dims[1]; j++){
        for (int k = 0; k< dims[0]; k++){
            float pixel = reader->GetOutput()->GetScalarComponentAsFloat(k,j,i,0);
            min>pixel ? min=pixel : min=min; //min = min and max=max is for compiling
            max<pixel ? max=pixel : max = max;

        }
    }
}
std::cout << " min " << min << " max " << max << std::endl;




OUTPUT

7
numer of arrays in file: 7
Array 0 :velocity_(cm_s)
status of 0 :1
Array 1 :magnetic_field_(Gauss)
status of 1 :1
Array 2 :density_rho_(g_cm^3)
status of 2 :1
Array 3 :entropy_s_(kB_baryon)
status of 3 :1
Array 4 :electron_fraction_Ye_()
status of 4 :1
Array 5 :gravitational_potential_phi_(erg_g)
status of 5 :1
Array 6 :div_B_(???)
status of 6 :1
Array 0 :velocity_(cm_s)
status of 0 :0
Array 1 :magnetic_field_(Gauss)
status of 1 :0
Array 2 :density_rho_(g_cm^3)
status of 2 :1
Array 3 :entropy_s_(kB_baryon)
status of 3 :0
Array 4 :electron_fraction_Ye_()
status of 4 :0
Array 5 :gravitational_potential_phi_(erg_g)
status of 5 :0
Array 6 :div_B_(???)
status of 6 :0
dims 0 120 1 120 2 120
 min 0 max 0




More information about the vtkusers mailing list