Skip to content

Slowdown inside QGIS window #730

@GGDRriedel

Description

@GGDRriedel

I am using the library to display some loaded profiles in QGIS .

So far so good, but the window slows down EXTREMELY during interaction.

I suspect something about the different loops not interacting correctly but that's where I am out of my league here, here is my basic code:

class GPR3DViewerDialog(QDialog):
    def __init__(self, gpr_data, profile_coords, dz=0.1, parent=None):
        super().__init__(parent)
        self.setWindowTitle("3D GPR Profile Viewer")
        self.resize(1000, 700)

        layout = QVBoxLayout()
        self.plotter = QtInteractor(self)
        layout.addWidget(self.plotter.interactor)
        self.setLayout(layout)

        self.grid = self.create_3d_gpr_surface(gpr_data, profile_coords, dz)
        self.plot_3d_profile()

    def create_3d_gpr_surface(self, gpr_data, profile_coords, dz):
        """Convert 2D GPR data and profile coords into a PyVista StructuredGrid"""
        n_depth, n_traces = gpr_data.shape
        points = []

        for i, coord in enumerate(profile_coords):
            x, y = coord.x(), coord.y()
            for j in range(n_depth):
                z = -j * dz
                points.append([x, y, z])

        points = np.array(points)
        values = gpr_data.flatten(order='F')  # depth major order

        grid = pv.StructuredGrid()
        grid.points = points
        grid.dimensions = [1, n_traces, n_depth]  # (x,y,z)
        grid["amplitude"] = values

        return grid

    def plot_3d_profile(self):
        """Render the 3D grid in the embedded PyVista viewer"""
        self.plotter.clear()
        self.plotter.add_mesh(
            self.grid, 
            scalars="amplitude", 
            cmap="seismic", 
            clim=[-abs(self.grid["amplitude"]).max(), abs(self.grid["amplitude"]).max()],
            show_scalar_bar=True
        )
        self.plotter.reset_camera()
        self.plotter.show_axes()
        
        
        
    #override for propper closing
    def closeEvent(self, event):
        self.plotter.close()
        self.plotter = None
        self.grid = None
        event.accept()

I added the override because otherwise the 3d window would only be hidden in the background and keep running. The grid setup is ok, I get a picture and interactive window.

My suspicion is that wrapping it in an interactive layout is causing some mayhem.
Could somebody more down with this stuff have a look?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions