VTK Real Time 3D Model Orientation Tracker

Hey all,

I’m trying to build a real-time 3D model visualization tool with VTK and PyQt5 and I’m looking for some assistance.

I am currently reading data from a 6 axis IMU over serial as the following:

"second, accel_x, accel_y, accel_z, gyro_x, gyro_y, gyro_z"

with accel values in m/s^2 and gyro values in degrees/second.


Currently I have a skeleton of a function to read values over serial and I want to be able to then rotate my 3D model to match the orientation of my sensor.

    def display_rotations_on_visual(self, data):
        if not self.uic.buttonConnectSerial.isChecked():
            pass
        else:
            line = data.strip().split(',')
            if len(line) != 7: # Checks if len is correct
                pass 
            else:
                try:
                    seconds = line[0]

                    # Accel values
                    accelX = float(line[1])
                    accelY = float(line[2])
                    accelZ = float(line[3])

                    # Gyro values 
                    gyroX = float(line[4])
                    gyroY = float(line[5])
                    gyroZ = float(line[6])
 
                    # Additional data processing and rotation handling

                except:
                    pass

Ideally I’m looking for some sort of data fusion with quaternions (to help negate gyro drift), but anything that remotely tracks my sensor is helpful and can be iterated on.


Now, how would I go about this? How can I apply rotations and re-render my model in real time without causing any memory issues? Any information is useful, and I appreciate any messages.

Thank you in advance!

Hello,

Integrating gyroscope and accelerometer inputs to update a model is not a trivial task, but doable if you pay attention. Here, the following instructable drills down the math involved such you can implement it in any programming language with basic math functions without scratching your head too much. It’s a long read but I believe all the necessary details are there. In the end, you get good estimates of the current position and orientation with respect to some starting position and orientation.

best,

PC

1 Like

I see. I already have a basic implementation in PyOpenGl, but I’m more so looking for code specifics within VTK.

I don’t think VTK (let alone OpenGL) has a class or algorithm in it to do that in a single shot.

I need to apply the rotations to the rendering continuously, but I don’t know how to do that.

I’ve just posted a detailed guide to do exactly that. But if you don’t care about the acceleration input to update position, just take a look at the following example on how to apply rotations in VTK: https://examples.vtk.org/site/Python/Rendering/Rotations/ .

I’ve read the guide before and can do/have done the data fusion. I’m just having trouble implementing it within VTK. I’ll check out the rotation link you posted. Thank you so much for your help!

If you want to learn how to do stuff with VTK, then I suggest reading its primer: VTK Textbook | VTK