[vtkusers] How can I read a "legacy" ASCII VTK file

David E DeMarle dave.demarle at kitware.com
Thu Mar 3 11:34:04 EST 2016


Try changing from polydatamapper to datasetmapper, or pretty much
equivalently put a datasetsurfacefilter (named "geometryfilter" in on of
the example) in between the reader and the polydatamapper.

In either case what happens is that the unstructured grid (potentially
containing volumetric elements eg tetrahedra) gets converted to a polydata
(containing only locally 2D elements eg triangles) which can be drawn by GL.


David E DeMarle
Kitware, Inc.
R&D Engineer
21 Corporate Drive
Clifton Park, NY 12065-8662
Phone: 518-881-4909

On Thu, Mar 3, 2016 at 9:50 AM, Vladi Mitover <vladi88 at gmx.de> wrote:

> Hello everyone,
>
> I use the VTK version 6.3.0-55.5.
>
> I am trying to do the following: read a "legacy" ASCII VTK file and that
> file represents an example of an unstructured grid in 3D, as done in the
> following VTK/Cxx-examples:
> 1)To read "legacy" ASCII VTK file:
>     http://www.vtk.org/Wiki/VTK/Examples/Cxx/IO/GenericDataObjectReader
>     I have included vtkGenericDataObjectReader.h, vtkPolyData.h, string
> 2)To make a 3DPlot:
>     http://www.vtk.org/Wiki/VTK/Examples/Cxx/IO/ReadPLOT3D
>     Here I change the vtkStructuredGridGeometryFilter.h to
> vtkUnstructuredGridReader.h
> 3)To read unstructured Grid:
>     http://www.vtk.org/Wiki/VTK/Examples/Cxx/IO/ReadUnstructuredGrid
>
> When I build it, it looks as if everything was okay but when I play it, in
> the opening window nothing is to see.
> Below is my code:
>
> #include <vtkVersion.h>
> #include <vtkPolyData.h>
> #if VTK_MAJOR_VERSION <= 5
> #include <vtkPLOT3DReader.h>
> #else
> #include <vtkMultiBlockPLOT3DReader.h>
> #include <vtkMultiBlockDataSet.h>
> #endif
> #include <vtkSmartPointer.h>
> #include <vtkPolyDataMapper.h>
> #include <vtkActor.h>
> #include <vtkRenderWindow.h>
> #include <vtkRenderer.h>
> #include <vtkRenderWindowInteractor.h>
> //===============================================
> //Header from example GenericDataObjectReader.cxx
> //===============================================
> #include <vtkGenericDataObjectReader.h>
> #include <vtkPolyData.h>
> #include <string>
> //=============================================
> //Header from example ReadUnstructuredGrid.cxx
> //=============================================
> #include <vtkUnstructuredGridReader.h>
> #include <vtkDataSetMapper.h>
>
> using namespace std;
> int main (int argc, char *argv[])
> {
>
>     //Ensure a filename was specified
>     if(argc != 2)
>     {
>         std::cerr << "Usage: " << argv[0] << " InputFilename(.vtk)" <<
> endl;
>         return EXIT_FAILURE;
>     }
>
>     //Get the filename from the command line
>     std::string inputFilename = argv[1];
>
>     //Read all the data from the file
>     vtkSmartPointer<vtkUnstructuredGridReader> reader =
>     vtkSmartPointer<vtkUnstructuredGridReader>::New();
>     reader->SetFileName(inputFilename.c_str());
>     reader->Update();
>
>     //Visualize
>     vtkSmartPointer<vtkPolyDataMapper> mapper =
>     vtkSmartPointer<vtkPolyDataMapper>::New();
>     //  mapper->SetInputConnection(geometryFilter->GetOutputPort());
>     mapper->SetInputConnection(reader->GetOutputPort());
>     mapper->ScalarVisibilityOff();
>
>     vtkSmartPointer<vtkActor> actor =
>     vtkSmartPointer<vtkActor>::New();
>     actor->SetMapper(mapper);
>
>     //Create a renderer, render window, and interactor
>     vtkSmartPointer<vtkRenderer> renderer =
>     vtkSmartPointer<vtkRenderer>::New();
>     vtkSmartPointer<vtkRenderWindow> renderWindow =
>     vtkSmartPointer<vtkRenderWindow>::New();
>     renderWindow->AddRenderer(renderer);
>     vtkSmartPointer<vtkRenderWindowInteractor> renderWindowInteractor =
>     vtkSmartPointer<vtkRenderWindowInteractor>::New();
>     renderWindowInteractor->SetRenderWindow(renderWindow);
>
>     renderer->AddActor(actor);
>     renderer->SetBackground(.3, .6, .3); // Background color green
>
>     renderWindow->Render();
>     renderWindowInteractor->Start();
>
>     return EXIT_SUCCESS;
> }
>
>
>
> What is wrong? Can anyone help?
>
> Thank you very much in advance.
>
> And here the file
>
>
> _______________________________________________
> 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
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://public.kitware.com/pipermail/vtkusers/attachments/20160303/5096ecc4/attachment.html>


More information about the vtkusers mailing list