How to convert vtk legacy files to vtu formatHow to represent voxel volume in VTK file format?Add scalars to vtk file (vtk 3.0 legacy) in Pythonvtk DATASET UNSTRUCTURED_GRID format for cylinderHow to set custom timestep values for a series of legacy VTK files in ParaView?VTK file format error for VTK_VertexHow does paraview read a vtk file?How to do a 2D STRUCTURED_POINTS VTK fileHow to split a STL into surfaces in VTKConverting VTK UnstructuredGrid to StructuredGridDefine data at cell centers using VTK format

Understanding "audieritis" in Psalm 94

Increase performance creating Mandelbrot set in python

How do I define a right arrow with bar in LaTeX?

Hide Select Output from T-SQL

Mapping a list into a phase plot

apt-get update is failing in debian

What is difference between behavior and behaviour

Is it correct to write "is not focus on"?

Was Spock the First Vulcan in Starfleet?

Products and sum of cubes in Fibonacci

Your magic is very sketchy

Using parameter substitution on a Bash array

Is there any easy technique written in Bhagavad GITA to control lust?

Hostile work environment after whistle-blowing on coworker and our boss. What do I do?

How does it work when somebody invests in my business?

What to do with wrong results in talks?

What would happen if the UK refused to take part in EU Parliamentary elections?

Can a monster with multiattack use this ability if they are missing a limb?

Failed to fetch jessie backports repository

Opposite of a diet

Personal Teleportation as a Weapon

Displaying the order of the columns of a table

Confused about a passage in Harry Potter y la piedra filosofal

Tiptoe or tiphoof? Adjusting words to better fit fantasy races



How to convert vtk legacy files to vtu format


How to represent voxel volume in VTK file format?Add scalars to vtk file (vtk 3.0 legacy) in Pythonvtk DATASET UNSTRUCTURED_GRID format for cylinderHow to set custom timestep values for a series of legacy VTK files in ParaView?VTK file format error for VTK_VertexHow does paraview read a vtk file?How to do a 2D STRUCTURED_POINTS VTK fileHow to split a STL into surfaces in VTKConverting VTK UnstructuredGrid to StructuredGridDefine data at cell centers using VTK format













2















I want to convert legacy .vtk files into binary files, preferably .vtu files, because I am using an Unstructured Grid.
To do so I adapted the ConvertFile-Example from http://www.vtk.org/Wiki/VTK/Examples/Cxx/IO/ConvertFile



#include <string>
#include <vtkSmartPointer.h>
#include <vtkGenericDataObjectReader.h>
#include <vtkVersion.h>
#include <vtkXMLUnstructuredGridWriter.h>
#include <vtkUnstructuredGrid.h>

int main(int argc, char *argv[])

if(argc < 3)

std::cerr << "Required arguments: input.vtk output.vtu" << std::endl;
return EXIT_FAILURE;


std::string inputFileName = argv[1];
std::string outputFileName = argv[2];

vtkSmartPointer<vtkGenericDataObjectReader> reader = vtkSmartPointer<vtkGenericDataObjectReader>::New();
reader->SetFileName(inputFileName.c_str());
reader->Update();

vtkSmartPointer<vtkXMLUnstructuredGridWriter> writer = vtkSmartPointer<vtkXMLUnstructuredGridWriter>::New();
writer->SetFileName(outputFileName.c_str());
writer->SetInputConnection(reader->GetOutputPort());
writer->Update();

return EXIT_SUCCESS;



But when I use this to convert my legacy file, i lose all Cell Data after the first set. In this minimal example of my legacy file Scal_1 is in the .vtu file but Scal_2 is not.



# vtk DataFile Version 3.1
Lattice Boltzmann data
ASCII
DATASET UNSTRUCTURED_GRID
POINTS 9 INT
0 0 0 1 0 0 2 0 0
0 1 0 1 1 0 2 1 0
0 2 0 1 2 0 2 2 0

CELLS 4 20
4 0 1 3 4
4 1 2 4 5
4 3 4 6 7
4 4 5 7 8

CELL_TYPES 4
8 8 8 8

CELL_DATA 4
SCALARS Scal_1 DOUBLE
LOOKUP_TABLE default
1 2 1 0

SCALARS Scal_2 DOUBLE
LOOKUP_TABLE default
1 3 2 1


I am still new to vtk. Should I use another reader or writer? Or is something completely wrong?










share|improve this question




























    2















    I want to convert legacy .vtk files into binary files, preferably .vtu files, because I am using an Unstructured Grid.
    To do so I adapted the ConvertFile-Example from http://www.vtk.org/Wiki/VTK/Examples/Cxx/IO/ConvertFile



    #include <string>
    #include <vtkSmartPointer.h>
    #include <vtkGenericDataObjectReader.h>
    #include <vtkVersion.h>
    #include <vtkXMLUnstructuredGridWriter.h>
    #include <vtkUnstructuredGrid.h>

    int main(int argc, char *argv[])

    if(argc < 3)

    std::cerr << "Required arguments: input.vtk output.vtu" << std::endl;
    return EXIT_FAILURE;


    std::string inputFileName = argv[1];
    std::string outputFileName = argv[2];

    vtkSmartPointer<vtkGenericDataObjectReader> reader = vtkSmartPointer<vtkGenericDataObjectReader>::New();
    reader->SetFileName(inputFileName.c_str());
    reader->Update();

    vtkSmartPointer<vtkXMLUnstructuredGridWriter> writer = vtkSmartPointer<vtkXMLUnstructuredGridWriter>::New();
    writer->SetFileName(outputFileName.c_str());
    writer->SetInputConnection(reader->GetOutputPort());
    writer->Update();

    return EXIT_SUCCESS;



    But when I use this to convert my legacy file, i lose all Cell Data after the first set. In this minimal example of my legacy file Scal_1 is in the .vtu file but Scal_2 is not.



    # vtk DataFile Version 3.1
    Lattice Boltzmann data
    ASCII
    DATASET UNSTRUCTURED_GRID
    POINTS 9 INT
    0 0 0 1 0 0 2 0 0
    0 1 0 1 1 0 2 1 0
    0 2 0 1 2 0 2 2 0

    CELLS 4 20
    4 0 1 3 4
    4 1 2 4 5
    4 3 4 6 7
    4 4 5 7 8

    CELL_TYPES 4
    8 8 8 8

    CELL_DATA 4
    SCALARS Scal_1 DOUBLE
    LOOKUP_TABLE default
    1 2 1 0

    SCALARS Scal_2 DOUBLE
    LOOKUP_TABLE default
    1 3 2 1


    I am still new to vtk. Should I use another reader or writer? Or is something completely wrong?










    share|improve this question


























      2












      2








      2








      I want to convert legacy .vtk files into binary files, preferably .vtu files, because I am using an Unstructured Grid.
      To do so I adapted the ConvertFile-Example from http://www.vtk.org/Wiki/VTK/Examples/Cxx/IO/ConvertFile



      #include <string>
      #include <vtkSmartPointer.h>
      #include <vtkGenericDataObjectReader.h>
      #include <vtkVersion.h>
      #include <vtkXMLUnstructuredGridWriter.h>
      #include <vtkUnstructuredGrid.h>

      int main(int argc, char *argv[])

      if(argc < 3)

      std::cerr << "Required arguments: input.vtk output.vtu" << std::endl;
      return EXIT_FAILURE;


      std::string inputFileName = argv[1];
      std::string outputFileName = argv[2];

      vtkSmartPointer<vtkGenericDataObjectReader> reader = vtkSmartPointer<vtkGenericDataObjectReader>::New();
      reader->SetFileName(inputFileName.c_str());
      reader->Update();

      vtkSmartPointer<vtkXMLUnstructuredGridWriter> writer = vtkSmartPointer<vtkXMLUnstructuredGridWriter>::New();
      writer->SetFileName(outputFileName.c_str());
      writer->SetInputConnection(reader->GetOutputPort());
      writer->Update();

      return EXIT_SUCCESS;



      But when I use this to convert my legacy file, i lose all Cell Data after the first set. In this minimal example of my legacy file Scal_1 is in the .vtu file but Scal_2 is not.



      # vtk DataFile Version 3.1
      Lattice Boltzmann data
      ASCII
      DATASET UNSTRUCTURED_GRID
      POINTS 9 INT
      0 0 0 1 0 0 2 0 0
      0 1 0 1 1 0 2 1 0
      0 2 0 1 2 0 2 2 0

      CELLS 4 20
      4 0 1 3 4
      4 1 2 4 5
      4 3 4 6 7
      4 4 5 7 8

      CELL_TYPES 4
      8 8 8 8

      CELL_DATA 4
      SCALARS Scal_1 DOUBLE
      LOOKUP_TABLE default
      1 2 1 0

      SCALARS Scal_2 DOUBLE
      LOOKUP_TABLE default
      1 3 2 1


      I am still new to vtk. Should I use another reader or writer? Or is something completely wrong?










      share|improve this question
















      I want to convert legacy .vtk files into binary files, preferably .vtu files, because I am using an Unstructured Grid.
      To do so I adapted the ConvertFile-Example from http://www.vtk.org/Wiki/VTK/Examples/Cxx/IO/ConvertFile



      #include <string>
      #include <vtkSmartPointer.h>
      #include <vtkGenericDataObjectReader.h>
      #include <vtkVersion.h>
      #include <vtkXMLUnstructuredGridWriter.h>
      #include <vtkUnstructuredGrid.h>

      int main(int argc, char *argv[])

      if(argc < 3)

      std::cerr << "Required arguments: input.vtk output.vtu" << std::endl;
      return EXIT_FAILURE;


      std::string inputFileName = argv[1];
      std::string outputFileName = argv[2];

      vtkSmartPointer<vtkGenericDataObjectReader> reader = vtkSmartPointer<vtkGenericDataObjectReader>::New();
      reader->SetFileName(inputFileName.c_str());
      reader->Update();

      vtkSmartPointer<vtkXMLUnstructuredGridWriter> writer = vtkSmartPointer<vtkXMLUnstructuredGridWriter>::New();
      writer->SetFileName(outputFileName.c_str());
      writer->SetInputConnection(reader->GetOutputPort());
      writer->Update();

      return EXIT_SUCCESS;



      But when I use this to convert my legacy file, i lose all Cell Data after the first set. In this minimal example of my legacy file Scal_1 is in the .vtu file but Scal_2 is not.



      # vtk DataFile Version 3.1
      Lattice Boltzmann data
      ASCII
      DATASET UNSTRUCTURED_GRID
      POINTS 9 INT
      0 0 0 1 0 0 2 0 0
      0 1 0 1 1 0 2 1 0
      0 2 0 1 2 0 2 2 0

      CELLS 4 20
      4 0 1 3 4
      4 1 2 4 5
      4 3 4 6 7
      4 4 5 7 8

      CELL_TYPES 4
      8 8 8 8

      CELL_DATA 4
      SCALARS Scal_1 DOUBLE
      LOOKUP_TABLE default
      1 2 1 0

      SCALARS Scal_2 DOUBLE
      LOOKUP_TABLE default
      1 3 2 1


      I am still new to vtk. Should I use another reader or writer? Or is something completely wrong?







      vtk paraview






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Oct 2 '14 at 11:24







      phirus

















      asked Oct 2 '14 at 10:06









      phirusphirus

      3416




      3416






















          2 Answers
          2






          active

          oldest

          votes


















          3














          The issue here is that the reader you chose is getting confused by having the input file containing 2 cell data arrays both marked as scalars. So with this the reader only outputs one cell data array. My suggestion is to use ParaView, specifically the pvpython executable, to convert the files. The corresponding Python code would look something like:



          from paraview.simple import *
          r = LegacyVTKReader( FileNames=['input.vtk'] )
          w = XMLUnstructuredGridWriter()
          w.FileName = 'output.vtu'
          w.UpdatePipeline()





          share|improve this answer






























            0














            You can just use meshio (a project of mine). Install with



            pip3 install meshio


            and run



            meshio-convert in.vtk out.vtu





            share|improve this answer






















              Your Answer






              StackExchange.ifUsing("editor", function ()
              StackExchange.using("externalEditor", function ()
              StackExchange.using("snippets", function ()
              StackExchange.snippets.init();
              );
              );
              , "code-snippets");

              StackExchange.ready(function()
              var channelOptions =
              tags: "".split(" "),
              id: "1"
              ;
              initTagRenderer("".split(" "), "".split(" "), channelOptions);

              StackExchange.using("externalEditor", function()
              // Have to fire editor after snippets, if snippets enabled
              if (StackExchange.settings.snippets.snippetsEnabled)
              StackExchange.using("snippets", function()
              createEditor();
              );

              else
              createEditor();

              );

              function createEditor()
              StackExchange.prepareEditor(
              heartbeatType: 'answer',
              autoActivateHeartbeat: false,
              convertImagesToLinks: true,
              noModals: true,
              showLowRepImageUploadWarning: true,
              reputationToPostImages: 10,
              bindNavPrevention: true,
              postfix: "",
              imageUploader:
              brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
              contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
              allowUrls: true
              ,
              onDemand: true,
              discardSelector: ".discard-answer"
              ,immediatelyShowMarkdownHelp:true
              );



              );













              draft saved

              draft discarded


















              StackExchange.ready(
              function ()
              StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f26158599%2fhow-to-convert-vtk-legacy-files-to-vtu-format%23new-answer', 'question_page');

              );

              Post as a guest















              Required, but never shown

























              2 Answers
              2






              active

              oldest

              votes








              2 Answers
              2






              active

              oldest

              votes









              active

              oldest

              votes






              active

              oldest

              votes









              3














              The issue here is that the reader you chose is getting confused by having the input file containing 2 cell data arrays both marked as scalars. So with this the reader only outputs one cell data array. My suggestion is to use ParaView, specifically the pvpython executable, to convert the files. The corresponding Python code would look something like:



              from paraview.simple import *
              r = LegacyVTKReader( FileNames=['input.vtk'] )
              w = XMLUnstructuredGridWriter()
              w.FileName = 'output.vtu'
              w.UpdatePipeline()





              share|improve this answer



























                3














                The issue here is that the reader you chose is getting confused by having the input file containing 2 cell data arrays both marked as scalars. So with this the reader only outputs one cell data array. My suggestion is to use ParaView, specifically the pvpython executable, to convert the files. The corresponding Python code would look something like:



                from paraview.simple import *
                r = LegacyVTKReader( FileNames=['input.vtk'] )
                w = XMLUnstructuredGridWriter()
                w.FileName = 'output.vtu'
                w.UpdatePipeline()





                share|improve this answer

























                  3












                  3








                  3







                  The issue here is that the reader you chose is getting confused by having the input file containing 2 cell data arrays both marked as scalars. So with this the reader only outputs one cell data array. My suggestion is to use ParaView, specifically the pvpython executable, to convert the files. The corresponding Python code would look something like:



                  from paraview.simple import *
                  r = LegacyVTKReader( FileNames=['input.vtk'] )
                  w = XMLUnstructuredGridWriter()
                  w.FileName = 'output.vtu'
                  w.UpdatePipeline()





                  share|improve this answer













                  The issue here is that the reader you chose is getting confused by having the input file containing 2 cell data arrays both marked as scalars. So with this the reader only outputs one cell data array. My suggestion is to use ParaView, specifically the pvpython executable, to convert the files. The corresponding Python code would look something like:



                  from paraview.simple import *
                  r = LegacyVTKReader( FileNames=['input.vtk'] )
                  w = XMLUnstructuredGridWriter()
                  w.FileName = 'output.vtu'
                  w.UpdatePipeline()






                  share|improve this answer












                  share|improve this answer



                  share|improve this answer










                  answered Oct 3 '14 at 17:14









                  andybauerandybauer

                  755512




                  755512























                      0














                      You can just use meshio (a project of mine). Install with



                      pip3 install meshio


                      and run



                      meshio-convert in.vtk out.vtu





                      share|improve this answer



























                        0














                        You can just use meshio (a project of mine). Install with



                        pip3 install meshio


                        and run



                        meshio-convert in.vtk out.vtu





                        share|improve this answer

























                          0












                          0








                          0







                          You can just use meshio (a project of mine). Install with



                          pip3 install meshio


                          and run



                          meshio-convert in.vtk out.vtu





                          share|improve this answer













                          You can just use meshio (a project of mine). Install with



                          pip3 install meshio


                          and run



                          meshio-convert in.vtk out.vtu






                          share|improve this answer












                          share|improve this answer



                          share|improve this answer










                          answered Mar 8 at 9:46









                          Nico SchlömerNico Schlömer

                          14.3k1175124




                          14.3k1175124



























                              draft saved

                              draft discarded
















































                              Thanks for contributing an answer to Stack Overflow!


                              • Please be sure to answer the question. Provide details and share your research!

                              But avoid


                              • Asking for help, clarification, or responding to other answers.

                              • Making statements based on opinion; back them up with references or personal experience.

                              To learn more, see our tips on writing great answers.




                              draft saved


                              draft discarded














                              StackExchange.ready(
                              function ()
                              StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f26158599%2fhow-to-convert-vtk-legacy-files-to-vtu-format%23new-answer', 'question_page');

                              );

                              Post as a guest















                              Required, but never shown





















































                              Required, but never shown














                              Required, but never shown












                              Required, but never shown







                              Required, but never shown

































                              Required, but never shown














                              Required, but never shown












                              Required, but never shown







                              Required, but never shown







                              Popular posts from this blog

                              Can't initialize raids on a new ASUS Prime B360M-A motherboard2019 Community Moderator ElectionSimilar to RAID config yet more like mirroring solution?Can't get motherboard serial numberWhy does the BIOS entry point start with a WBINVD instruction?UEFI performance Asus Maximus V Extreme

                              Identity Server 4 is not redirecting to Angular app after login2019 Community Moderator ElectionIdentity Server 4 and dockerIdentityserver implicit flow unauthorized_clientIdentityServer Hybrid Flow - Access Token is null after user successful loginIdentity Server to MVC client : Page Redirect After loginLogin with Steam OpenId(oidc-client-js)Identity Server 4+.NET Core 2.0 + IdentityIdentityServer4 post-login redirect not working in Edge browserCall to IdentityServer4 generates System.NullReferenceException: Object reference not set to an instance of an objectIdentityServer4 without HTTPS not workingHow to get Authorization code from identity server without login form

                              2005 Ahvaz unrest Contents Background Causes Casualties Aftermath See also References Navigation menue"At Least 10 Are Killed by Bombs in Iran""Iran"Archived"Arab-Iranians in Iran to make April 15 'Day of Fury'"State of Mind, State of Order: Reactions to Ethnic Unrest in the Islamic Republic of Iran.10.1111/j.1754-9469.2008.00028.x"Iran hangs Arab separatists"Iran Overview from ArchivedConstitution of the Islamic Republic of Iran"Tehran puzzled by forged 'riots' letter""Iran and its minorities: Down in the second class""Iran: Handling Of Ahvaz Unrest Could End With Televised Confessions""Bombings Rock Iran Ahead of Election""Five die in Iran ethnic clashes""Iran: Need for restraint as anniversary of unrest in Khuzestan approaches"Archived"Iranian Sunni protesters killed in clashes with security forces"Archived