Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Qt for Python
  4. Fast way to create a QSurfaceDataArray from a numpy array
Forum Update on Monday, May 27th 2025

Fast way to create a QSurfaceDataArray from a numpy array

Scheduled Pinned Locked Moved Unsolved Qt for Python
3 Posts 2 Posters 564 Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • L Offline
    L Offline
    ludw
    wrote on 23 Mar 2022, 12:43 last edited by
    #1

    Is there a fast way to create a QSurfaceDataArray from a numpy array?
    In the example for the Surface example, they added each point separately to the QSurfaceDataArray.
    This is too slow for a live view with a lot of points.
    In my case, the update of the 3D surface graph takes roughly 0.08s, which is acceptable. The parsing from a numpy array to a QSurfaceDataArray takes 10 times longer, which is an order too long. The problem is that I have to loop through the entire array and convert every point separately.

    It would be nice if there exist a vectorized parsing method. Maybe I could implement the code in C++ with the QVector3D C++ class. I never did this, and I don't know if it works, if I return a List of List s of QVector3D objects.

    My code that is too slow:

    def parse_data(data: np.ndarray):
        global vector_list
        for y_index in range(data.shape[0]):
            for x_index in range(data.shape[1]):
                vector_list[y_index][x_index] = QVector3D(x_index, data[y_index, x_index], y_index)
    
    1 Reply Last reply
    0
    • S Offline
      S Offline
      Shyamnath
      wrote on 31 Mar 2022, 10:18 last edited by
      #2

      As far as I know Shiboken6 (the binding generator for PySide6) does support numpy array converters enabling direct conversion from Numpy arrays to C++ sequence containers. Maybe it is actually possible to do it.

      Could you raise a feature suggestion for this here: https://wiki.qt.io/Qt_for_Python/Reporting_Bugs

      The senior PySide6 developers would have an opinion on this.

      1 Reply Last reply
      0
      • L Offline
        L Offline
        ludw
        wrote on 6 Apr 2022, 11:08 last edited by
        #3

        Link to the opened suggestion report:
        https://bugreports.qt.io/browse/PYSIDE-1880?jql=project %3D PYSIDE AND component %3D Shiboken

        1 Reply Last reply
        0

        • Login

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • Users
        • Groups
        • Search
        • Get Qt Extensions
        • Unsolved