[Paraview] ParaView reader plugin - error: Cannot volume render since no point (or cell) data available.

Radek Lonka lonka.radek at gmail.com
Tue Dec 17 05:48:52 EST 2013


Hi,

I am new here and to paraview. I have been trying to create reader plugin
for some data but even it works on my simple qt based application together
with vtk it does not work in paraview. It loads the data, I can see the
Information with cell data and point data correctly but it deros not
visualize anything and when I use either Volume or slices it says: Cannot
volume render since no point (or cell) data available.

Could you please help me what am I doing wrong? Here is my code:

#include "MyReader.h"
 
#include "vtkObjectFactory.h"
#include "vtkStreamingDemandDrivenPipeline.h"
#include "vtkInformationVector.h"
#include "vtkInformation.h"
#include "vtkDataObject.h"
#include "vtkSmartPointer.h"
#include <vtkVector.h>
#include <vtkFloatArray.h>
#include <vtkImageFlip.h>
#include <vtkVector.h>
#include <vtkImageData.h>
#include <vtkPointData.h>
#include <vtkCellData.h>

#include <iostream>

 
vtkStandardNewMacro(MyReader);
 
MyReader::EMyReader()
{
  this->FileName = NULL;
  this->SetNumberOfInputPorts(0);
  this->SetNumberOfOutputPorts(1);
}

int MyReader::RequestInformation (
   vtkInformation*,
   vtkInformationVector**,
   vtkInformationVector* outputVector)
{

   vtkInformation* outInfo =
      outputVector->GetInformationObject(0);

   // Here is where you would read the data from the file.
    // Make sure we have a file to read.
    if(!this->FileName)
    {
        vtkErrorMacro("A FileName must be specified.");
        return 0;
    }
    ifstream fin(this->FileName, ios::in | ios::binary);
    if( !fin.is_open() )
    {
        vtkErrorMacro("Error opening file " << this->FileName);
        return 0;
    }

 //   vtkVector<float, 3> header_origin;
 //   vtkVector<float, 3> header_delta;
 //   vtkVector<int, 3> header_size;

    fin.read( (char *)(&header_origin[0]), sizeof(header_origin[0]) );
    fin.read( (char *)(&header_origin[1]), sizeof(header_origin[1]) );
    fin.read( (char *)(&header_origin[2]), sizeof(header_origin[2]) );
    fin.read( (char *)(&header_delta[0]), sizeof(header_delta[0]) );
    fin.read( (char *)(&header_delta[1]), sizeof(header_delta[1]) );
    fin.read( (char *)(&header_delta[2]), sizeof(header_delta[2]) );
    fin.read( (char *)(&header_size[0]), sizeof(header_size[0]) );
    fin.read( (char *)(&header_size[1]), sizeof(header_size[1]) );
    fin.read( (char *)(&header_size[2]), sizeof(header_size[2]) );

    int nx = header_size[0];
    int ny = header_size[1];
    int nz = header_size[2];
    float* data_array = new float[nx*ny*nz];
    fin.seekg(0);
    fin.seekg(36);
 //   fin.read((char *) data_array, nx*ny*nz*sizeof(float));
    fin.close();

    for (int i = 0; i < nx*ny*nz; i++)
        data_array[i] = i * 0.1;

    array = vtkFloatArray::New();
    array->SetArray(data_array, nx*ny*nz, 1);
    array->SetName("Conductivity");

    int ext[6] = {0, 0, 0, header_size[0], header_size[1], header_size[2]};
    double spacing[3] = {header_delta[0], header_delta[1], header_delta[2]};
    double origin[3] = {header_origin[0], header_origin[1], header_origin[2]};

    outInfo->Set(
                vtkStreamingDemandDrivenPipeline::
                WHOLE_EXTENT(),
                ext, 6);
    outInfo->Set(vtkDataObject::SPACING(),
                 spacing, 3);
    outInfo->Set(vtkDataObject::ORIGIN(), origin, 3);
    vtkDataObject::SetPointDataActiveScalarInfo(
                outInfo, VTK_FLOAT, 1);
   return 1;

}

int MyReader::RequestData(
  vtkInformation *vtkNotUsed(request),
  vtkInformationVector **vtkNotUsed(inputVector),
  vtkInformationVector *outputVector)
{
    vtkInformation* outInfo =
       outputVector->GetInformationObject(0);
    // get the ouptut
    vtkImageData *output = vtkImageData::SafeDownCast(
        outInfo->Get(vtkDataObject::DATA_OBJECT()));

    output->GetCellData()->SetScalars(array);
    output->GetPointData()->SetScalars(array);
    output->SetNumberOfScalarComponents(1, outInfo);
    output->SetScalarType(VTK_FLOAT, outInfo);
    output->AllocateScalars(VTK_FLOAT, 1);
    int ext[6] = {0, 0, 0, header_size[0], header_size[1], header_size[2]};
    output->SetExtent(ext);
    output->SetDimensions(header_size[0], header_size[1], header_size[2]);
    output->SetOrigin(header_origin[0], header_origin[1], header_origin[2]);
    output->SetSpacing(header_delta[0], header_delta[1], header_delta[2] *4.0);

    output->Print(std::cout);

    return 1;
}

void MyReader::PrintSelf(ostream& os, vtkIndent indent)
{
  this->Superclass::PrintSelf(os,indent);
 
  os << indent << "File Name: "
      << (this->FileName ? this->FileName : "(none)") << "\n";
}


also the ouptut of ouptut->Print is:
vtkImageData (0x39d8310)
  Debug: Off
  Modified Time: 83874
  Reference Count: 1
  Registered Events: (none)
  Information: 0x39d1ac0
  Data Released: False
  Global Release Data: Off
  UpdateTime: 0
  Field Data:
    Debug: Off
    Modified Time: 83836
    Reference Count: 1
    Registered Events: (none)
    Number Of Arrays: 0
    Number Of Components: 0
    Number Of Tuples: 0
  Number Of Points: 9594507
  Number Of Cells: 9434880
  Cell Data:
    Debug: Off
    Modified Time: 83853
    Reference Count: 1
    Registered Events: (none)
    Number Of Arrays: 1
    Array 0 name = Conductivity
    Number Of Components: 1
    Number Of Tuples: 9594507
    Copy Tuple Flags: ( 1 1 1 1 1 0 1 1 )
    Interpolate Flags: ( 1 1 1 1 1 0 0 1 )
    Pass Through Flags: ( 1 1 1 1 1 1 1 1 )
    Scalars: 
      Debug: Off
      Modified Time: 79025
      Reference Count: 2
      Registered Events: (none)
      Name: Conductivity
      Data type: float
      Size: 9594507
      MaxId: 9594506
      NumberOfComponents: 1
      Information: 0
      Name: Conductivity
      Number Of Components: 1
      Number Of Tuples: 9594507
      Size: 9594507
      MaxId: 9594506
      LookupTable: (none)
      Array: 0x7f29adab3010
    Vectors: (none)
    Normals: (none)
    TCoords: (none)
    Tensors: (none)
    GlobalIds: (none)
    PedigreeIds: (none)
    EdgeFlag: (none)
  Point Data:
    Debug: Off
    Modified Time: 83860
    Reference Count: 1
    Registered Events: (none)
    Number Of Arrays: 1
    Array 0 name = ImageScalars
    Number Of Components: 1
    Number Of Tuples: 0
    Copy Tuple Flags: ( 1 1 1 1 1 0 1 1 )
    Interpolate Flags: ( 1 1 1 1 1 0 0 1 )
    Pass Through Flags: ( 1 1 1 1 1 1 1 1 )
    Scalars: 
      Debug: Off
      Modified Time: 83858
      Reference Count: 1
      Registered Events: (none)
      Name: ImageScalars
      Data type: float
      Size: 0
      MaxId: -1
      NumberOfComponents: 1
      Information: 0
      Name: ImageScalars
      Number Of Components: 1
      Number Of Tuples: 0
      Size: 0
      MaxId: -1
      LookupTable: (none)
      Array: (null)
    Vectors: (none)
    Normals: (none)
    TCoords: (none)
    Tensors: (none)
    GlobalIds: (none)
    PedigreeIds: (none)
    EdgeFlag: (none)
  Bounds: 
    Xmin,Xmax: (699975, 771975)
    Ymin,Ymax: (8.53492e+06, 8.56222e+06)
    Zmin,Zmax: (0, 25920)
  Compute Time: 83875
  Spacing: (150, 150, 240)
  Origin: (699975, 8.53492e+06, 0)
  Dimensions: (481, 183, 109)
  Increments: (0, 0, 0)
  Extent: (0, 480, 0, 182, 0, 108)


Anyone could help me?




More information about the ParaView mailing list