Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6919501
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T09:59:53+00:00 2026-05-27T09:59:53+00:00

I have some VTK-files, which look like this: # vtk DataFile Version 1.0 Line

  • 0

I have some VTK-files, which look like this:

# vtk DataFile Version 1.0
Line representation of vtk
ASCII
DATASET POLYDATA
POINTS 30 FLOAT
234 462 35
233 463 35
231 464 35
232 464 35
229 465 35
[...]
LINES 120 360
2 0 1
2 0 1
2 1 0
2 1 3
2 1 0
2 1 3
2 2 5
2 2 3
[...]

I would like to get two lists out of these VTK-files: edgesList and verticesList:

  • edgesList should contain the edges as (FromVerticeIndex, ToVerticeIndex, Weight)-tuples
  • verticesList should contain the vertices as (x,y,z)-tuples. The index is the index mentioned in edgesList

I have no idea how to extract this with the standard-vtk-python library. I got so far:

import sys, vtk

filename = "/home/graphs/g000231.vtk"

reader = vtk.vtkSTLReader()
reader.SetFileName(filename)
reader.Update()

idList = vtk.vtkIdList() 

polyDataOutput = reader.GetOutput()
print polyDataOutput.GetPoints().GetData()

Its possible that my python-vtk-code doesn’t make sense. I would prefer to use the vtk library and not use any self-written pieces of code.

Here is my self-written piece of code. It works, but it would be better if I could use the vtk library for this:

import re
def readVTKtoGraph(filename):
    """ Specification of VTK-files:
        http://www.vtk.org/VTK/img/file-formats.pdf - page 4 """
    f = open(filename)
    lines = f.readlines()
    f.close()

    verticeList = []
    edgeList = []

    lineNr = 0
    pattern = re.compile('([\d]+) ([\d]+) ([\d]+)')
    while "POINTS" not in lines[lineNr]:
        lineNr += 1

    while "LINES" not in lines[lineNr]:
        lineNr += 1
        m = pattern.match(lines[lineNr])
        if m != None:
            x = float(m.group(1))
            y = float(m.group(2))
            z = float(m.group(3))
            verticeList.append((x,y,z))

    while lineNr < len(lines)-1:
        lineNr += 1
        m = pattern.match(lines[lineNr])
        nrOfPoints = m.group(1)
        vertice1 = int(m.group(2))
        vertice2 = int(m.group(3))
        gewicht = 1.0
        edgeList.append((vertice1, vertice2, gewicht))
    return (verticeList, edgeList)
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T09:59:53+00:00Added an answer on May 27, 2026 at 9:59 am

    I don’t use VTK with Python, but this reader should be able to read that file:
    http://www.vtk.org/Wiki/VTK/Examples/Cxx/IO/GenericDataObjectReader

    and here is an example of how to use a VTK reader in Python:
    http://www.vtk.org/Wiki/VTK/Examples/Python/STLReader

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have some HTML like this (which I cannot change): <div> <p class=name> <span>Employee
I have some classes layed out like this class A { public virtual void
I have some code like this in a winforms app I was writing to
I have some submodules organized like this: |-- app | |-- models | |
I have some perl code that looks something like this: my @array = map
I have some JSON data that looks like this: { 910719: { id: 910719,
I have some ASP.NET web services which all share a common helper class they
I have some C# / asp.net code I inherited which has a textbox which
We have some files on our website that users of our software can download.
I have some code which works fine on one server but is giving a

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.