[vtkusers] Issue when reading unstructured grid on VTK legacy file

Cory Quammen cory.quammen at kitware.com
Sun Nov 8 09:44:52 EST 2015


Hi,

Three things:

1). A possibly simpler way to tell the mapper which array to color by is:

mapper->SetScalarModeToUseCellFieldData(); // note this is different form
what you had
mapper->SelectColorArray(arrayName);

This does not require you to go through setting up the active scalars in
the cell data as you have done in your code. That will work, but the way I
suggest takes fewer lines of code.

2). The problem you see is likely that you need to specify a lookup table
range that matches your data range. Try calling

mapper->SetScalarRange(min, max);

where min and max are the min and max of your array.

3). The default color map in VTK is not the same as in ParaView, so if you
don't see a direct match after doing 2). above, don't worry. You'll just
need to specify a different lookup table.

HTH,
Cory

On Sat, Nov 7, 2015 at 11:03 AM, joaoroberto88 <joaorobertojr88 at gmail.com>
wrote:

> Hello VTK Users,
>
> I'm facing a problem reading a legacy VTK file that stores a
> vtkUnstructuredGrid with some scalar arrays. Specifically, I'm interested
> on
> waterSurfaceElevation array. When I open it on Paraview it displays
> correctly (please see attached), but when I try to render it in my own
> application a wrong result is shown (attached). Could anyone help me? I'm
> using the code bellow to read and render the legacy file (available at
> https://www.dropbox.com/s/fgm1rgne32rd0qw/output-00000001.vtk?dl=0).
>
> std::string filename = "output-00000001.vtk";
> std::string arrayName = "waterSurfaceElevation";
>
> vtkSmartPointer<vtkGenericDataObjectReader> reader =
> vtkSmartPointer<vtkGenericDataObjectReader>::New();
> reader->SetFileName(filename.c_str());
> reader->Update();
>
> vtkSmartPointer<vtkUnstructuredGrid> unstructuredGrid =
> reader->GetUnstructuredGridOutput();
> unstructuredGrid->GetCellData()->SetActiveScalars(arrayName.c_str());
>
> vtkSmartPointer<vtkDataSetMapper> mapper =
> vtkSmartPointer<vtkDataSetMapper>::New();
> mapper->SetInputData(unstructuredGrid);
> mapper->SetScalarModeToUseCellData();
>
> vtkSmartPointer<vtkActor> meshActor = vtkSmartPointer<vtkActor>::New();
> meshActor->SetMapper(mapper->GetPolyDataMapper());
>
> // All rendering stuff allocated in class constructor
> renderer->AddActor(meshActor);
> renderer->ResetCamera();
>
> Thanks!
> <http://vtk.1045678.n5.nabble.com/file/n5734867/paraview.png>
> <http://vtk.1045678.n5.nabble.com/file/n5734867/wrong_result.png>
>
>
>
> --
> View this message in context:
> http://vtk.1045678.n5.nabble.com/Issue-when-reading-unstructured-grid-on-VTK-legacy-file-tp5734867.html
> Sent from the VTK - Users mailing list archive at Nabble.com.
> _______________________________________________
> Powered by www.kitware.com
>
> Visit other Kitware open-source projects at
> http://www.kitware.com/opensource/opensource.html
>
> Please keep messages on-topic and check the VTK FAQ at:
> http://www.vtk.org/Wiki/VTK_FAQ
>
> Search the list archives at: http://markmail.org/search/?q=vtkusers
>
> Follow this link to subscribe/unsubscribe:
> http://public.kitware.com/mailman/listinfo/vtkusers
>



-- 
Cory Quammen
R&D Engineer
Kitware, Inc.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://public.kitware.com/pipermail/vtkusers/attachments/20151108/e83a94b0/attachment.html>


More information about the vtkusers mailing list