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. Set mesh to QSurface3DSeries
Qt 6.11 is out! See what's new in the release blog

Set mesh to QSurface3DSeries

Scheduled Pinned Locked Moved Solved Qt for Python
2 Posts 1 Posters 581 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.
  • M Offline
    M Offline
    Mihaill
    wrote on last edited by
    #1

    Hi.
    I have triangles and vertecies.
    How I can create surface?
    Now I can create use only example "Surface examole", in tgis example using rows with vertices.
    In python I have 3 example in another librares (model - my object with triangles and vertecies ):

            if plotting_module == 'pyrender':
                import pyrender
                import trimesh
                vertex_colors = np.ones([vertices.shape[0], 4]) * [0.3, 0.3, 0.3, 0.8]
                tri_mesh = trimesh.Trimesh(vertices, model.faces,
                                           vertex_colors=vertex_colors
                                           # , body_pose=body_pose
                                           # , left_hand_pose=left_hand_pose
                                           )
    
                # save mesh in file
                # tri_mesh_fname = '/home/owner/Загрузки/tri_mesh.obj'
                # tri_mesh.export(tri_mesh_fname)
    
                mesh = pyrender.Mesh.from_trimesh(tri_mesh)
    
                scene = pyrender.Scene()
                scene.add(mesh)
    
                if plot_joints:
                    sm = trimesh.creation.uv_sphere(radius=0.005)
                    sm.visual.vertex_colors = [0.9, 0.1, 0.1, 1.0]
                    tfs = np.tile(np.eye(4), (len(joints), 1, 1))
                    tfs[:, :3, 3] = joints
                    joints_pcl = pyrender.Mesh.from_trimesh(sm, poses=tfs)
                    scene.add(joints_pcl)
    
                pyrender.Viewer(scene, use_raymond_lighting=True)
    
            elif plotting_module == 'matplotlib':
                from matplotlib import pyplot as plt
                from mpl_toolkits.mplot3d import Axes3D
                from mpl_toolkits.mplot3d.art3d import Poly3DCollection
    
                fig = plt.figure()
                ax = fig.add_subplot(111, projection='3d')
    
                mesh = Poly3DCollection(vertices[model.faces], alpha=0.1)
                face_color = (1.0, 1.0, 0.9)
                edge_color = (0, 0, 0)
                mesh.set_edgecolor(edge_color)
                mesh.set_facecolor(face_color)
                ax.add_collection3d(mesh)
                ax.scatter(joints[:, 0], joints[:, 1], joints[:, 2], color='r')
    
                if plot_joints:
                    ax.scatter(joints[:, 0], joints[:, 1], joints[:, 2], alpha=0.1)
                plt.show()
            elif plotting_module == 'open3d':
                import open3d as o3d
    
                mesh = o3d.geometry.TriangleMesh()
                mesh.vertices = o3d.utility.Vector3dVector(
                    vertices)
                mesh.triangles = o3d.utility.Vector3iVector(model.faces)
                mesh.compute_vertex_normals()
                mesh.paint_uniform_color([0.3, 0.3, 0.3])
    
                geometry = [mesh]
                if plot_joints:
                    joints_pcl = o3d.geometry.PointCloud()
                    joints_pcl.points = o3d.utility.Vector3dVector(joints)
                    joints_pcl.paint_uniform_color([0.7, 0.3, 0.3])
                    geometry.append(joints_pcl)
    
                o3d.visualization.draw_geometries(geometry)
    
    1 Reply Last reply
    0
    • M Offline
      M Offline
      Mihaill
      wrote on last edited by
      #2

      It is work in vtk

          def drawModel(self):
              nc = vtkNamedColors()
      
              rn = vtkMinimalStandardRandomSequence()
              rn.SetSeed(1)
      
              # Define points, triangles and colors
              colors = vtkUnsignedCharArray()
              colors.SetNumberOfComponents(3)
              points = vtkPoints()
              triangles = vtkCellArray()
      
              for i in range(len(self.vertices)):
                  points.InsertNextPoint(self.vertices[i][0], self.vertices[i][1], self.vertices[i][2])
              print(len(self.faces), self.faces.shape)
              for i in range(len(self.faces)):
                  triangle = vtkTriangle()
                  triangle.GetPointIds().SetId(0, self.faces[i][0])
                  triangle.GetPointIds().SetId(1, self.faces[i][1])
                  triangle.GetPointIds().SetId(2, self.faces[i][2])
                  triangles.InsertNextCell(triangle)
      
                  colors.InsertNextTypedTuple([189, 179, 179])  # grey color
      
              # Create a polydata object
              trianglePolyData = vtkPolyData()
      
              # Add the geometry and topology to the polydata
              trianglePolyData.SetPoints(points)
              trianglePolyData.GetPointData().SetScalars(colors)
              trianglePolyData.SetPolys(triangles)
      
              # Clean the polydata so that the edges are shared !
              cleanPolyData = vtkCleanPolyData()
              cleanPolyData.SetInputData(trianglePolyData)
      
              # Use a filter to smooth the data (will add triangles and smooth)
              # Use two different filters to show the difference
              smooth_loop = vtkLoopSubdivisionFilter()
              smooth_loop.SetNumberOfSubdivisions(3)
              smooth_loop.SetInputConnection(cleanPolyData.GetOutputPort())
              smooth_butterfly = vtkButterflySubdivisionFilter()
              smooth_butterfly.SetNumberOfSubdivisions(3)
              smooth_butterfly.SetInputConnection(cleanPolyData.GetOutputPort())
      
              # Create a mapper and actor for initial dataset
              mapper = vtkPolyDataMapper()
              mapper.SetInputData(trianglePolyData)
              actor = vtkActor()
              actor.SetMapper(mapper)
      
              # Visualise
              renderer = vtkRenderer()
              renderWindow = vtkRenderWindow()
              renderWindow.AddRenderer(renderer)
              renderWindowInteractor = vtkRenderWindowInteractor()
              renderWindowInteractor.SetRenderWindow(renderWindow)
      
              # Add actors and render
              renderer.AddActor(actor)
              renderer.SetBackground(nc.GetColor3d('AliceBlue'))
      
              renderWindow.SetSize(900, 300)
              renderWindow.Render()
              renderer.GetActiveCamera().Elevation(-45)
              renderer.GetActiveCamera().Zoom(3)
              renderWindow.Render()
              renderWindowInteractor.Start()
      
      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