[vtkusers] Visualising vorticity from NC file structured grid

henlau henrylau9677 at gmail.com
Mon Apr 10 12:09:41 EDT 2017


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







--
View this message in context: http://vtk.1045678.n5.nabble.com/Visualising-vorticity-from-NC-file-structured-grid-tp5742780.html
Sent from the VTK - Users mailing list archive at Nabble.com.


More information about the vtkusers mailing list