Visualising vorticity from NC file structured grid

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Visualising vorticity from NC file structured grid

henlau
Hi all,

I am new to VTK. I have a NC file and reading it with "vtknetCDFCFReader". In my NC file, there are 2 variable arrays and their corresponding dimension:

"ua" - (height, lon, lat) - Description: Eastward_wind - Unit: m s-1
"va" - (height, lon, lat) - Description: Northward_wind - Unit: m s-1

I safeDownCast the output of the reader and got a vtkStructuredGrid, with only cell data. The thing is I want to render the vorticity of the data. I saw people working with vtkHedgeHog, and the following is what I am doing:

   //reader
   vtkNetCDFCFReader *reader = vtkNetCDFCFReader::New();
   reader->SetFileName(fileName);
   reader->SetOutputTypeToStructured();
   reader->UpdateMetaData();
   reader->Update();

   reader->SetVariableArrayStatus("ua", 1);
   reader->SetVariableArrayStatus("va", 1);

  reader->SphericalCoordinatesOff();

  //SafeDownCast reader output to structuredGrid
   vtkStructuredGrid *weatherGrid = vtkStructuredGrid::SafeDownCast(reader->GetOutput());


  //Cell data to point data
    vtkCellDataToPointData *c2p = vtkCellDataToPointData::New();
    c2p->SetInputData(weatherGrid);
    c2p->PassCellDataOn();
    c2p->Update();

  //Convert it back to a structured grid
    vtkStructuredGrid* reformedWeatherGrid = c2p->GetStructuredGridOutput();


  //In the following code, I start doing the hedgehog
  //Here I am creating vector data for the "reformedWeatherGrid"
  //1430*1557*151 is the dimension of my first structured grid
    vtkFloatArray* vector = vtkFloatArray::New();
    vector->SetNumberOfComponents(3);
    vector->SetNumberOfTuples(1430*1557*151);
    for(int i = 0; i < 151; i++){

      double v[2];
      v[0] = reformedWeatherGrid->GetPointData()->GetArray("ua")->GetComponent(i,0);
      v[1] = reformedWeatherGrid->GetPointData()->GetArray("va")->GetComponent(i,0);
      vector->InsertTuple(i,v);
    }

    //Set new vector into reformedWeatherGrid
    reformedWeatherGrid->GetPointData()->SetVectors(vector);

    //HedgeHog
    vtkHedgeHog* hedgehog = vtkHedgeHog::New();
    hedgehog->SetInputData(reformedWeatherGrid);
    hedgehog->SetScaleFactor(0.1);

    //PolyDataMapper and Actor
    vtkPolyDataMapper* hhMapper = vtkPolyDataMapper::New();
    hhMapper->SetInputConnection(hedgehog->GetOutputPort());
    vtkActor* hhActor = vtkActor::New();
    hhActor->SetMapper(hhMapper);

   //renderer and render window
   .............

The problem is I got the following error:
vtkPointData (0x7fbb1af13d80): Can not set attribute Vectors. Incorrect number of components.
vtkHedgeHog (0x7fbb1af1def0): No vectors in input data

What should I do in order to solve this problem? Or is there any alternatives to render the vorticity of my data?

TIA



Loading...