[vtkusers] Multi block data set for rectilinear grid.

Zoltan Kovacs Zoltan.Kovacs at esi-group.com
Wed Sep 26 05:56:59 EDT 2018


Dear all,

I have an issue with handling multiblock data of a rectilinear grid. I found an example program to plot the rectilinear grid. I modified this example
by inserting some lines which create one block for the grid in a multiblock data set. If I run the example with the original poly data mapper then
it shows the grid.
However if  I comment out the line
wireActor->SetMapper(gridMapper);
and I use the line
wireActor->SetMapper(compMapper);
for the multiblock data mapper then no grid appears in the scene. Is it possible that the class vtkCompositePolyDataMapper2 cannot handle data sets and some  composite data set mapper is needed for it? I could not find any composite mapper for general data sets. Thanks for your help.

Kind regards,
Zoltan


#include "vtkPolyData.h"
#include "vtkPolyDataMapper.h"
#include "vtkDataSetMapper.h"
#include "vtkActor.h"
#include "vtkRenderer.h"
#include "vtkRenderWindow.h"
#include "vtkRenderWindowInteractor.h"
#include "vtkProperty.h"
#include "vtkNamedColors.h"
#include "vtkPointData.h"
#include "vtkDataArray.h"
#include "vtkFloatArray.h"
#include "vtkRectilinearGrid.h"
#include "vtkMultiBlockDataSet.h"
#include "vtkCompositePolyDataMapper2.h"
#include "vtkCompositeDataDisplayAttributes.h"

#define VTK_CREATE(type,name)  \
vtkSmartPointer<type> name = vtkSmartPointer<type>::New()
#define VTK_INCOM(out,in) out->SetInputConnection(in->GetOutputPort())

int main( int argc, char *argv[] )
{
  float x[] = {
    -1.22396, -1.17188, -1.11979, -1.06771, -1.01562, -0.963542,
    -0.911458, -0.859375, -0.807292, -0.755208, -0.703125, -0.651042,
    -0.598958, -0.546875, -0.494792, -0.442708, -0.390625, -0.338542,
    -0.286458, -0.234375, -0.182292, -0.130209, -0.078125, -0.026042,
    0.0260415, 0.078125, 0.130208, 0.182291, 0.234375, 0.286458,
    0.338542, 0.390625, 0.442708, 0.494792, 0.546875, 0.598958,
    0.651042, 0.703125, 0.755208, 0.807292, 0.859375, 0.911458,
    0.963542, 1.01562, 1.06771, 1.11979, 1.17188, -100};

  float y[] = {
    -1.25, -1.17188, -1.09375, -1.01562, -0.9375, -0.859375,
    -0.78125, -0.703125, -0.625, -0.546875, -0.46875, -0.390625,
    -0.3125, -0.234375, -0.15625, -0.078125, 0, 0.078125,
    0.15625, 0.234375, 0.3125, 0.390625, 0.46875, 0.546875,
    0.625, 0.703125, 0.78125, 0.859375, 0.9375, 1.01562,
    1.09375, 1.17188, 1.25, -100 };

  float z[] = {
    0, 0.1, 0.2, 0.3, 0.4, 0.5,
    0.6, 0.7, 0.75, 0.8, 0.9, 1,
    1.1, 1.2, 1.3, 1.4, 1.5, 1.6,
    1.7, 1.75, 1.8, 1.9, 2, 2.1,
    2.2, 2.3, 2.4, 2.5, 2.6, 2.7,
    2.75, 2.8, 2.9, 3, 3.1, 3.2,
    3.3, 3.4, 3.5, 3.6, 3.7, 3.75,
    3.8, 3.9, -100 };

  VTK_CREATE(vtkRenderer, renderer);
  VTK_CREATE(vtkRenderWindow, renderWindow);
  VTK_CREATE(vtkRenderWindowInteractor, renderWindowInteractor);
  VTK_CREATE(vtkDataSetMapper, gridMapper);
  VTK_CREATE(vtkActor, wireActor);
  VTK_CREATE(vtkFloatArray, xCoords);
  VTK_CREATE(vtkFloatArray, yCoords);
  VTK_CREATE(vtkFloatArray, zCoords);
  VTK_CREATE(vtkRectilinearGrid, grid);
  VTK_CREATE(vtkMultiBlockDataSet, mbDataSet);
  VTK_CREATE(vtkCompositePolyDataMapper2, compMapper);
  VTK_CREATE(vtkCompositeDataDisplayAttributes, dataDispAttrib);

  int i = 0;
  while(x[i] > -99)
     xCoords->InsertNextValue(x[i++]);
  int j = 0;
  while(y[j] > -99)
     yCoords->InsertNextValue(y[j++]);

  int k = 0;
  while(z[k] > -99)
     zCoords->InsertNextValue(z[k++]);

  grid->SetDimensions(i-1, j-1, k-1);
  grid->SetXCoordinates(xCoords);
  grid->SetYCoordinates(yCoords);
  grid->SetZCoordinates(zCoords);
  gridMapper->SetInputData(grid);

  mbDataSet->SetNumberOfBlocks(1);
  mbDataSet->SetBlock(0, grid);

  compMapper->SetInputDataObject(mbDataSet);
  compMapper->SetCompositeDataDisplayAttributes(dataDispAttrib);

  wireActor->SetMapper(gridMapper);
  //wireActor->SetMapper(compMapper);
  wireActor->GetProperty()->SetRepresentationToWireframe();

  renderWindow->AddRenderer(renderer);
  renderWindowInteractor->SetRenderWindow(renderWindow);

  renderer->AddActor(wireActor);
  renderer->SetBackground(.3, .6, .3);

  renderWindow->Render();
  renderWindowInteractor->Start();
}


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://public.kitware.com/pipermail/vtkusers/attachments/20180926/d63ebfad/attachment.html>


More information about the vtkusers mailing list