Exemple #1
0
 def createScene(self):
     self.rootEntity = Qt3DCore.QEntity()
     self.scannerEntity = Qt3DCore.QEntity(self.rootEntity)
     # QSceneLoader loads materials from scanner.mtl referenced in scanner.obj
     self.scanner = Qt3DRender.QSceneLoader(self.scannerEntity)
     self.scanner.setSource(QUrl.fromLocalFile("scanner.obj"))
     self.scannerEntity.addComponent(self.scanner)
     self.addTransform()
Exemple #2
0
    def __init__(self, parentEntity):
        super(Cube, self).__init__()

        # build the cube
        side = 15
        self.cubeEntity = Qt3DCore.QEntity(parentEntity)

        # init params of the 6 planes
        planeTranslations = [[0, -side / 2, 0], [0, +side / 2, 0],
                             [-side / 2, 0, 0], [+side / 2, 0, 0],
                             [0, 0, -side / 2], [0, 0, +side / 2]]
        planeRotations = [[0, 0, 180], [0, 0, 0], [0, 0, 90], [0, 0, 270],
                          [270, 0, 0], [90, 0, 0]]

        # allocate planes
        self.planeEntities = [None for i in range(6)]
        self.planeMeshes = [None for i in range(6)]
        self.planeTransforms = [None for i in range(6)]
        self.materials = [None for i in range(6)]

        # build the planes
        for i in range(0, 6):
            self.planeMeshes[i] = Qt3DExtras.QPlaneMesh()
            self.planeMeshes[i].setWidth(side)
            self.planeMeshes[i].setHeight(side)

            self.planeTransforms[i] = Qt3DCore.QTransform()
            self.planeTransforms[i].setRotationX(planeRotations[i][0])
            self.planeTransforms[i].setRotationY(planeRotations[i][1])
            self.planeTransforms[i].setRotationZ(planeRotations[i][2])
            self.planeTransforms[i].setTranslation(
                QVector3D(planeTranslations[i][0], planeTranslations[i][1],
                          planeTranslations[i][2]))

            self.materials[i] = Qt3DExtras.QPhongMaterial(self.cubeEntity)
            self.materials[i].setAmbient(
                QColor(random.randint(0, 255), random.randint(0, 255),
                       random.randint(0, 255)))

            self.planeEntities[i] = Qt3DCore.QEntity(self.cubeEntity)
            self.planeEntities[i].addComponent(self.planeMeshes[i])
            self.planeEntities[i].addComponent(self.planeTransforms[i])
            self.planeEntities[i].addComponent(self.materials[i])

        #initial rotation
        self.yaw = -15
        self.pitch = 15
        self.yawSpeed = 0
        self.pitchSpeed = 0
        self.cubeTransform = Qt3DCore.QTransform()
        self.cubeEntity.addComponent(self.cubeTransform)
        self.rotate(
            0, 0
        )  #trigger the computation of the rotation matrix for the initial rotation
Exemple #3
0
    def showAll(self):

        self.rootEntity = Qt3DCore.QEntity()
        self.materialSquare = Qt3DExtras.QPhongMaterial(self.rootEntity)
        self.materialSphere = Qt3DExtras.QPhongMaterial(self.rootEntity)
        # self.material = Qt3DExtras.QPhongMaterial(self.rootEntity)
        with open('local2.csv', 'r') as file:
            reader = csv.reader(file)
            for row in reader:
                if row[0] == 's':

                    self.sphereEntity = Qt3DCore.QEntity(self.rootEntity)
                    self.sphereMesh = Qt3DExtras.QSphereMesh()
                    self.name = row[1]
                    self.materialSphere.setAmbient(
                        QColor(int(row[2]), int(row[3]), int(row[4]),
                               int(row[5])))
                    self.sphereMesh.setRadius(int(row[6]))
                    self.QTransformSphere = Qt3DCore.QTransform()
                    self.sphereEntity.addComponent(self.sphereMesh)
                    self.sphereEntity.addComponent(self.materialSphere)
                    self.sphereEntity.addComponent(self.QTransformSphere)
                    sphereVector3D = QVector3D()
                    sphereVector3D.setX(int(row[7]))
                    sphereVector3D.setY(int(row[8]))
                    sphereVector3D.setZ(int(row[9]))
                    self.QTransformSphere.setTranslation(sphereVector3D)

                else:

                    self.squareEntity = Qt3DCore.QEntity(self.rootEntity)
                    self.squareMesh = Qt3DExtras.QCuboidMesh()
                    self.name = row[1]
                    self.materialSquare.setAmbient(
                        QColor(int(row[2]), int(row[3]), int(row[4]),
                               int(row[5])))
                    self.squareMesh.setXExtent(int(row[6]))
                    self.squareMesh.setYExtent(int(row[7]))
                    self.squareMesh.setZExtent(int(row[8]))
                    self.QTransformSquare = Qt3DCore.QTransform()
                    self.squareEntity.addComponent(self.squareMesh)
                    self.squareEntity.addComponent(self.materialSquare)
                    self.squareEntity.addComponent(self.QTransformSquare)

                    squareVector3D = QVector3D()
                    squareVector3D.setX(int(row[9]))
                    squareVector3D.setY(int(row[10]))
                    squareVector3D.setZ(int(row[11]))
                    self.QTransformSquare.setTranslation(squareVector3D)
                    self.QTransformSquare.setRotationX(int(row[12]))
                    self.QTransformSquare.setRotationY(int(row[13]))
                    self.QTransformSquare.setRotationZ(int(row[14]))
Exemple #4
0
    def __init__(self):
        super().__init__()
        #store objects into array
        self.i = 0
        self.listOfObjects = []
        with open('local2.csv', 'r') as file:
            reader = csv.reader(file)
            for row in reader:
                self.listOfObjects.append(row)
        print(self.listOfObjects)
        # Camera
        self.camera().lens().setPerspectiveProjection(45, 16 / 9, 0.1, 1000)
        #setting focus on selected object
        if self.listOfObjects[0][0] == 's':
            self.camera().setPosition(
                QVector3D(int(row[7]), int(row[8]), 50 + int(row[9])))
            self.camera().setViewCenter(
                QVector3D(int(row[7]), int(row[8]), int(row[9])))
        else:
            self.camera().setPosition(
                QVector3D(int(row[9]), int(row[10]), 50 + int(row[11])))
            self.camera().setViewCenter(
                QVector3D(int(row[9]), int(row[10]), int(row[11])))
        # For camera controls
        self.rootEntity = Qt3DCore.QEntity()

        self.showAll()
        self.camController = Qt3DExtras.QOrbitCameraController(self.rootEntity)
        self.camController.setLinearSpeed(50)
        self.camController.setLookSpeed(180)
        self.camController.setCamera(self.camera())
        self.setRootEntity(self.rootEntity)
Exemple #5
0
    def createScene(self):
        # Root entity
        self.rootEntity = Qt3DCore.QEntity()

        # Material
        self.material = Qt3DExtras.QPhongMaterial(self.rootEntity)

        # Torus
        self.torusEntity = Qt3DCore.QEntity(self.rootEntity)
        self.torusMesh = Qt3DExtras.QTorusMesh()
        self.torusMesh.setRadius(5)
        self.torusMesh.setMinorRadius(1)
        self.torusMesh.setRings(100)
        self.torusMesh.setSlices(20)

        self.torusTransform = Qt3DCore.QTransform()
        self.torusTransform.setScale3D(QVector3D(1.5, 1, 0.5))
        self.torusTransform.setRotation(
            QQuaternion.fromAxisAndAngle(QVector3D(1, 0, 0), 45))

        self.torusEntity.addComponent(self.torusMesh)
        self.torusEntity.addComponent(self.torusTransform)
        self.torusEntity.addComponent(self.material)

        # Sphere
        self.sphereEntity = Qt3DCore.QEntity(self.rootEntity)
        self.sphereMesh = Qt3DExtras.QSphereMesh()
        self.sphereMesh.setRadius(3)

        self.sphereTransform = Qt3DCore.QTransform()
        self.controller = OrbitTransformController(self.sphereTransform)
        self.controller.setTarget(self.sphereTransform)
        self.controller.setRadius(20)

        self.sphereRotateTransformAnimation = QPropertyAnimation(
            self.sphereTransform)
        self.sphereRotateTransformAnimation.setTargetObject(self.controller)
        self.sphereRotateTransformAnimation.setPropertyName("angle")
        self.sphereRotateTransformAnimation.setStartValue(0)
        self.sphereRotateTransformAnimation.setEndValue(360)
        self.sphereRotateTransformAnimation.setDuration(10000)
        self.sphereRotateTransformAnimation.setLoopCount(-1)
        self.sphereRotateTransformAnimation.start()

        self.sphereEntity.addComponent(self.sphereMesh)
        self.sphereEntity.addComponent(self.sphereTransform)
        self.sphereEntity.addComponent(self.material)
def create_qentity(components: List[Qt3DCore.QComponent],
                   parent=None) -> Qt3DCore.QEntity:
    """
    Creates a QEntity and gives it all of the QComponents that are contained in a list.
    """
    entity = Qt3DCore.QEntity(parent)
    for component in components:
        entity.addComponent(component)
    return entity
Exemple #7
0
    def __init__(self, view: Qt3DExtras.Qt3DWindow) -> None:
        """
        Initialize a new instance.
        Args:
            view: where to render the planetary sphere.
        """
        self.root_entity = Qt3DCore.QEntity()

        ce = self.camera_entity = view.camera()
        ce.lens().setPerspectiveProjection(45.0, 1.0, 0.1, 1000.0)
        ce.setPosition(V3(0, 8, 8))
        ce.setUpVector(V3(0, 1, 0))
        ce.setViewCenter(V3(0, 0, 0))

        self.light = Qt3DCore.QEntity(self.root_entity)
        self.point_light = Qt3DRender.QPointLight(self.light)
        self.point_light.setColor("white")
        self.point_light.setIntensity(1.0)
        self.light.addComponent(self.point_light)
        # Move the light to the camera's position - on-camera 'flash'!
        t = self.light_transform = Qt3DCore.QTransform(self.light)
        t.setTranslation(ce.position())
        self.light.addComponent(t)

        self.mesh = Qt3DExtras.QSphereMesh()
        self.mesh.setRings(30)
        self.mesh.setSlices(30)
        self.mesh.setRadius(2)

        t = self.transform = Qt3DCore.QTransform()
        t.setScale(1.3)
        t.setTranslation(V3(0.0, 0.0, 0.0))

        m = self.material = Qt3DExtras.QDiffuseSpecularMaterial()
        m.setAmbient(QColor(200, 200, 255))
        m.setShininess(20.0)

        self.entity = Qt3DCore.QEntity(self.root_entity)
        self.entity.addComponent(self.mesh)
        self.entity.addComponent(self.material)
        self.entity.addComponent(self.transform)

        view.setRootEntity(self.root_entity)
        self.entity.setEnabled(True)
    def add_acq_sphere(self, df, label):
        pos = df.loc[label, ["x", "y", "z"]].values*1000  # m to mm
        if label not in self.acq_coordinate_entities:
            self.acq_coordinate_meshes[label] = Qt3DExtras.QSphereMesh(rings=20, slices=20, radius=3)
            self.acq_coordinate_entities[label] = Qt3DCore.QEntity(self.root_entity)
            self.acq_coordinate_transforms[label] = Qt3DCore.QTransform(self.acq_coordinate_meshes[label])

            self.acq_coordinate_entities[label].addComponent(self.acq_coordinate_meshes[label])
            self.acq_coordinate_entities[label].addComponent(self.acq_coordinate_transforms[label])
            self.acq_coordinate_entities[label].addComponent(self.acq_material)

        self.acq_coordinate_transforms[label].setTranslation(QtGui.QVector3D(*pos))
Exemple #9
0
 def __init__(self, type, parent):
     super(Node, self).__init__()
     parentEntity = parent.entity() if parent else None
     self._entity = Qt3DCore.QEntity(parentEntity)
     self._id = Node.Id
     Node.Id += 1
     self._type = type
     self._parent = parent
     self._children = []  # C++: QList<Node*>
     self._components = {}  # C++: QHash<ComponentType, Component*>
     self._propertyMap = []  # C++: QList<NodeProperty*>
     self._componentMap = []  # C++: QList<Component*>
     if parent is not None:
         parent.addChild(self)
Exemple #10
0
    def createScene(self):
        # Root entity
        self.rootEntity = Qt3DCore.QEntity()

        # Material
        self.material = Qt3DExtras.QPhongMaterial(self.rootEntity)

        # Torus
        self.torusEntity = Qt3DCore.QEntity(self.rootEntity)
        self.torusMesh = Qt3DExtras.QTorusMesh()
        self.torusMesh.setRadius(5)
        self.torusMesh.setMinorRadius(1)
        self.torusMesh.setRings(100)
        self.torusMesh.setSlices(20)

        self.torusTransform = Qt3DCore.QTransform()
        self.torusTransform.setScale3D(QVector3D(1.5, 1, 0.5))
        self.torusTransform.setRotation(
            QQuaternion.fromAxisAndAngle(QVector3D(1, 0, 0), 45))

        self.torusEntity.addComponent(self.torusMesh)
        self.torusEntity.addComponent(self.torusTransform)
        self.torusEntity.addComponent(self.material)

        # Sphere
        self.sphereEntity = Qt3DCore.QEntity(self.rootEntity)
        self.sphereMesh = Qt3DExtras.QSphereMesh()
        self.sphereMesh.setRadius(3)

        self.sphereTransform = Qt3DCore.QTransform()
        self.controller = OrbitTransformController(self.sphereTransform)
        self.controller.setTarget(self.sphereTransform)
        self.controller.setRadius(20)

        self.sphereEntity.addComponent(self.sphereMesh)
        self.sphereEntity.addComponent(self.sphereTransform)
        self.sphereEntity.addComponent(self.material)
Exemple #11
0
    def __init__(self):
        super(Cube3DWindow, self).__init__()

        # Root entity
        self.rootEntity = Qt3DCore.QEntity()
        self.setRootEntity(self.rootEntity)

        # Camera
        self.camera().lens().setPerspectiveProjection(45, 16 / 9, 0.1, 1000)
        self.camera().setPosition(QVector3D(0, 0, 40))
        self.camera().setViewCenter(QVector3D(0, 0, 0))

        self.mouseLastPos = QPoint()
        self.mouseDown = False
        self.timer = QTimer(self)
        self.timer.timeout.connect(self.onTimer)
Exemple #12
0
    def importerLoaded(self, status):
        if status != Kuesa.GLTF2Importer.Status.Ready:
            return

        # First let's take the components that we are going to use to create our clones
        parent = self.rootEntity.entity("KuesaEntity_0")

        parent.setObjectName("KuesaEntity_0")
        orig_entity = self.rootEntity.entity("KuesaEntity_2").childNodes()[1]
        orig_geometry = orig_entity.childNodes()[0]
        orig_material = orig_entity.childNodes()[1]

        row = 10
        col = 10
        distance = 200
        r = 500
        # Then create clones by giving them a custom transform, and the same components than before
        for i in range(0, col):
            for j in range(0, row):
                new_entity = Qt3DCore.QEntity(parent)

                # Note : there is an inconsistency in the Python bindings -
                # In C++ it is not necessary to assign a parent to the transform.
                new_transform = Qt3DCore.QTransform(new_entity)

                new_material = self.cloneMaterial(orig_material, new_entity)
                new_material.setEffect(orig_material.effect())
                new_props = new_material.metallicRoughnessProperties()

                new_props.setMetallicFactor(i / col)
                new_props.setRoughnessFactor(j / row)

                dt = QVector3D(i * distance, j * distance, 0)
                new_transform.setTranslation(dt)

                # Add the custom transform to the entity
                new_entity.addComponent(new_transform)

                # Add the material we created
                new_entity.addComponent(new_material)

                # These two components will be shared across all the ducks.
                new_entity.addComponent(orig_geometry)
Exemple #13
0
    def add_sphere(self, radius, x, y, z, rings=10, slices=10):

        sphereEntity = Qt3DCore.QEntity(self.rootEntity)

        # Mesh
        sphereMesh = Qt3DExtras.QSphereMesh()
        sphereMesh.setRadius(radius)
        sphereMesh.setRings(rings)
        sphereMesh.setSlices(slices)

        # Transforms
        sphereTransform = Qt3DCore.QTransform()
        sphereTransform.setTranslation(QVector3D(x, y, z))

        sphereEntity.addComponent(sphereMesh)
        sphereEntity.addComponent(self.material)
        sphereEntity.addComponent(sphereTransform)

        self.spheres.append(sphereEntity)
        self.meshes.append(sphereMesh)
        self.transforms.append(sphereTransform)
Exemple #14
0
    def importerLoaded(self, status):
        if status != Kuesa.GLTF2Importer.Status.Ready:
            return

        # First let's take the components that we are going to use to create our clones
        parent = self.rootEntity.entity("KuesaEntity_0")

        parent.setObjectName("KuesaEntity_0")
        orig_entity = self.rootEntity.entity("KuesaEntity_2").childNodes()[1]
        orig_geometry = orig_entity.childNodes()[0]
        orig_material = orig_entity.childNodes()[1]

        self.ducks = 1000
        r = 500
        # Then create clones by giving them a custom transform, and the same components than before
        for i in range(0, self.ducks):
            new_entity = Qt3DCore.QEntity(parent)

            # Note : there is an inconsistency in the Python bindings -
            # In C++ it is not necessary to assign a parent to the transform.
            new_transform = Qt3DCore.QTransform(new_entity)

            new_transform.setScale(0.2)

            dt = QVector3D(random.randint(-r, r), random.randint(-r, r),
                           random.randint(-r, r))
            new_transform.setTranslation(dt)

            new_transform.setRotationX(random.randint(0, 360))
            new_transform.setRotationY(random.randint(0, 360))
            new_transform.setRotationZ(random.randint(0, 360))

            # Add the custom transform, plus the original components, to the entity
            new_entity.addComponent(new_transform)

            # These two components will be shared across all the ducks.
            new_entity.addComponent(orig_geometry)
            new_entity.addComponent(orig_material)
    def __init__(self, parent):
        super().__init__()

        self.root_entity = Qt3DCore.QEntity()

        # Make additional entities for the gnomon and instrument components
        self.combined_component_axes_entity = Qt3DCore.QEntity(
            self.root_entity)
        self.component_root_entity = Qt3DCore.QEntity(
            self.combined_component_axes_entity)
        self.axes_root_entity = Qt3DCore.QEntity(
            self.combined_component_axes_entity)
        self.gnomon_root_entity = Qt3DCore.QEntity(self.root_entity)

        # Create the 3DWindow and place it in a widget with a layout
        lay = QVBoxLayout(self)
        self.view = InstrumentZooming3DWindow(self.component_root_entity)
        self.view.defaultFrameGraph().setClearColor(QColor("lightgrey"))
        self.view.setRootEntity(self.root_entity)
        container = QWidget.createWindowContainer(self.view)
        lay.addWidget(container)

        # Set the properties of the instrument camera controller
        camera_entity = self.view.camera()
        cam_controller = Qt3DExtras.QFirstPersonCameraController(
            self.root_entity)
        cam_controller.setLinearSpeed(20)
        cam_controller.setCamera(camera_entity)

        # Enable the camera to see a large distance by giving it a small nearView and large farView
        self.view.camera().lens().setPerspectiveProjection(
            45, 16 / 9, 0.01, 1000)

        # Set the camera view centre as the origin and position the camera so that it looks down at the initial sample
        self.view.camera().setPosition(QVector3D(6, 8, 30))
        self.view.camera().setViewCenter(QVector3D(0, 0, 0))

        # Make sure that the size of the gnomon stays the same when the 3D view is resized
        self.view.heightChanged.connect(self.update_gnomon_size)
        self.view.widthChanged.connect(self.update_gnomon_size)

        # Keep a reference to the gnomon viewport so that it can be resized to preserve the original size of the gnomon
        self.gnomon_viewport = None

        # Choose a fixed height and width for the gnomon so that this can be preserved when the 3D view is resized
        self.gnomon_height = self.gnomon_width = 140

        # Create the gnomon resources
        self.gnomon = Gnomon(self.gnomon_root_entity, self.view.camera())

        # Create the axes lines objects
        InstrumentViewAxes(self.axes_root_entity,
                           self.view.camera().farPlane())

        # Dictionary of components and transformations so that we can delete them later
        self.component_entities: Dict[str, EntityCollection] = {}
        self.transformations = {}

        # Create layers in order to allow one camera to only see the gnomon and one camera to only see the
        # components and axis lines
        self.create_layers()
        self.initialise_view()

        # Insert the beam cylinder last. This ensures that the semi-transparency works correctly.
        self.gnomon.setup_beam_cylinder()

        # Move the gnomon when the camera view changes
        self.view.camera().viewVectorChanged.connect(self.gnomon.update_gnomon)
Exemple #16
0
    def __init__(self):
        super(Window, self).__init__()

        # Default set-up - by now you know the drill :-)
        self.rootEntity = Kuesa.SceneEntity()
        self.rootEntity.addComponent(DefaultEnvMap(self.rootEntity))

        self.gltfImporter = Kuesa.GLTF2Importer(self.rootEntity)
        self.gltfImporter.setSceneEntity(self.rootEntity)
        self.gltfImporter.setSource(assetsUrl() + "/models/duck/Duck.glb")

        self.camera().setPosition(QVector3D(10, 1.5, 10))
        self.camera().setViewCenter(QVector3D(0, .5, 0))
        self.camera().setUpVector(QVector3D(0, 1, 0))
        self.camera().setAspectRatio(16. / 9.)

        self.camController = Qt3DExtras.QOrbitCameraController(self.rootEntity)
        self.camController.setCamera(self.camera())

        self.fg = Kuesa.ForwardRenderer()
        self.fg.setCamera(self.camera())
        self.fg.setClearColor("white")
        self.setActiveFrameGraph(self.fg)

        envmap_root = assetsUrl() + "/envmaps/pink_sunrise"
        envmap_name = "pink_sunrise" + ("_16f" if platform.system() == "Darwin"
                                        else "") + "_radiance"
        self.skybox = Kuesa.Skybox(self.rootEntity)
        self.skybox.setBaseName(envmap_root + "/" + envmap_name)
        self.skybox.setExtension(".dds")

        # Now we create some lights.
        # All lights have an intensity and a color.
        # Specific light types have relevant additional properties.
        # Point light
        self.pointLightEntity = Qt3DCore.QEntity(self.rootEntity)
        self.pointLightTransform = Qt3DCore.QTransform(self.pointLightEntity)
        self.pointLightTransform.setTranslation(QVector3D(20, -10, -10))

        self.pointLight = Kuesa.PointLight(self.pointLightEntity)
        self.pointLight.setIntensity(1000.0)
        self.pointLight.setColor("red")

        self.pointLightEntity.addComponent(self.pointLightTransform)
        self.pointLightEntity.addComponent(self.pointLight)

        # Spot light
        self.spotLightEntity = Qt3DCore.QEntity(self.rootEntity)
        self.spotLightTransform = Qt3DCore.QTransform(self.spotLightEntity)
        self.spotLightTransform.setTranslation(QVector3D(-10, 10, 10))

        self.spotLight = Kuesa.SpotLight(self.spotLightEntity)
        self.spotLight.setIntensity(1000.0)
        self.spotLight.setColor("green")
        self.spotLight.setInnerConeAngle(50)
        self.spotLight.setOuterConeAngle(100)
        self.spotLight.setRange(1000)

        self.spotLightEntity.addComponent(self.spotLightTransform)
        self.spotLightEntity.addComponent(self.spotLight)

        # Directional light
        self.directionalLightEntity = Qt3DCore.QEntity(self.rootEntity)
        self.directionalLightTransform = Qt3DCore.QTransform(
            self.directionalLightEntity)

        self.directionalLight = Kuesa.DirectionalLight(
            self.directionalLightEntity)
        self.directionalLight.setIntensity(100.0)
        self.directionalLight.setColor("blue")
        self.directionalLight.setDirection(QVector3D(10, 10, -10))

        self.directionalLightEntity.addComponent(
            self.directionalLightTransform)
        self.directionalLightEntity.addComponent(self.directionalLight)

        self.setRootEntity(self.rootEntity)
    def __init__(self, parent, fs_subject="sample"):
        super(MeshDisplayWidget, self).__init__(parent)

        self.config = parent.config
        self.fs_subject = fs_subject

        self.view = Qt3DExtras.Qt3DWindow()
        self.view.defaultFrameGraph().setClearColor(QtGui.QColor("#4d4d4f"))
        self.container = QtWidgets.QWidget.createWindowContainer(self.view, self)
        screen_size = self.view.screen().size()
        self.container.setMinimumSize(QtCore.QSize(600, 100))
        self.container.setMaximumSize(screen_size)

        #h_layout = QtWidgets.QHBoxLayout(self)
        #h_layout.addWidget(self.container)
        self.addWidget(self.container)

        self.tableView = QtWidgets.QTableView(self)
        self.tableView.setObjectName("tableView")

        v_layout = QtWidgets.QVBoxLayout()
        v_layout.addWidget(self.tableView)

        self.overlay_btn = QtWidgets.QPushButton("Update and overlay digitized points")
        self.overlay_btn.clicked.connect(self.update_acquisition_overlay)
        v_layout.addWidget(self.overlay_btn)

        subject_name_layout = QtWidgets.QHBoxLayout()
        subject_name_layout.addWidget(QtWidgets.QLabel("Subject name:"))
        self.subject_name_wgt = QtWidgets.QComboBox()
        subject_name_layout.addWidget(self.subject_name_wgt)
        self.new_subject_wgt = QtWidgets.QPushButton("New subject")
        self.new_subject_wgt.clicked.connect(self.new_subject)
        subject_name_layout.addWidget(self.new_subject_wgt)

        self.mute_sound_wgt = QtWidgets.QCheckBox("Mute sound")
        subject_name_layout.addWidget(self.mute_sound_wgt)

        v_layout.addLayout(subject_name_layout)

        if "subject_dir" not in self.config["DEFAULT"]:
            self.config["DEFAULT"]["subject_dir"] = str(Path(__file__).parent.absolute() / "subjects_data")

        subject_dir_layout = QtWidgets.QHBoxLayout()
        subject_dir_layout.addWidget(QtWidgets.QLabel("Subject dir:"))
        self.subject_dir_wgt = QtWidgets.QLineEdit(self.config["DEFAULT"]["subject_dir"])
        self.subject_dir_wgt.setReadOnly(False)
        subject_dir_layout.addWidget(self.subject_dir_wgt)
        select_subject_dir_btn = QtWidgets.QPushButton("...")
        subject_dir_layout.addWidget(select_subject_dir_btn)
        select_subject_dir_btn.clicked.connect(self.open_subject_dir_dlg)

        v_layout.addLayout(subject_dir_layout)
        self.subject_dir_wgt.textChanged.connect(self.set_subject_dir)

        if not Path(self.config["DEFAULT"]["subject_dir"]).exists():
            msgBox = QtWidgets.QMessageBox()
            msgBox.setIcon(QtWidgets.QMessageBox.Information)
            msgBox.setText(f"The chosen subject directory (i.e. {self.config['DEFAULT']['subject_dir']}) does not "
                           "exist. Do you want to create it or to select a new directory?")
            msgBox.setWindowTitle("Non-existent subject directory")

            button_create = msgBox.addButton("Create it!", QtWidgets.QMessageBox.YesRole);
            msgBox.addButton("Select a different directory", QtWidgets.QMessageBox.NoRole)
            msgBox.exec_()
            if msgBox.clickedButton() == button_create:
                Path(self.config["DEFAULT"]["subject_dir"]).mkdir(exist_ok=True, parents=True)
            else:
                self.open_subject_dir_dlg()

        #h_layout.addLayout(v_layout)
        v_layout_widget = QtWidgets.QWidget(self)
        v_layout_widget.setLayout(v_layout)
        self.addWidget(v_layout_widget)

        self.data = QtCore.QUrl.fromLocalFile(str(Path(__file__).parent.absolute() / f"{self.fs_subject}_head.obj"))

        self.root_entity = Qt3DCore.QEntity()

        self.material = Qt3DExtras.QPhongMaterial()
        self.material.setDiffuse(QtGui.QColor(254, 254, 254))

        self.camera = self.view.camera()
        self.camera.lens().setPerspectiveProjection(400.0, 16.0/9.0, 100, 1200.0)
        self.camera.setPosition(QtGui.QVector3D(0, 500, 0))
        self.camera.setUpVector(QtGui.QVector3D(0, 0, 1))

        self.lightEntities = {}
        self.lights = {}
        self.lightTransforms = {}
        for trans_x in [200, -200]:
            for trans_y in [200, -200]:
                self.lightEntities[(trans_x, trans_y)] = Qt3DCore.QEntity(self.root_entity)
                self.lights[(trans_x, trans_y)] = Qt3DRender.QPointLight(self.lightEntities[(trans_x, trans_y)])
                self.lights[(trans_x, trans_y)].setColor("white")
                self.lights[(trans_x, trans_y)].setIntensity(0.4)
                self.lightEntities[(trans_x, trans_y)].addComponent(self.lights[(trans_x, trans_y)])
        
                self.lightTransforms[(trans_x, trans_y)] = Qt3DCore.QTransform(self.lightEntities[(trans_x, trans_y)])
                self.lightTransforms[(trans_x, trans_y)].setTranslation(QtGui.QVector3D(trans_x, trans_y, 100.0))
                self.lightEntities[(trans_x, trans_y)].addComponent(self.lightTransforms[(trans_x, trans_y)])

        # Get co-registered head, fiducials and electrodes
        data_path = Path(mne.datasets.sample.data_path())
        fs_subjects_dir = data_path / 'subjects'
        trans_fname = data_path / 'MEG' / 'sample' / 'sample_audvis_raw-trans.fif'
        trans = mne.read_trans(trans_fname)

        montage = mne.channels.make_standard_montage('GSN-HydroCel-129')
        info = mne.create_info(montage.ch_names, 100, ch_types='eeg')
        raw = mne.io.RawArray(np.zeros((len(montage.ch_names), 100)), info)
        raw.set_montage(montage)

        eeg, fid, surf = get_aligned_artifacts(raw.info, subject=self.fs_subject, trans=trans,
                                               subjects_dir=fs_subjects_dir, coord_frame='mri')
        self.head_surf = surf

        path_out = Path(str(Path(__file__).parent.absolute() / f"{self.fs_subject}_head.obj"))
        if True: #not path_out.exists():
            mesh = trimesh.Trimesh(surf["rr"] * 1000, surf["tris"])
            open3d_mesh = open3d.geometry.TriangleMesh(vertices=open3d.utility.Vector3dVector(mesh.vertices),
                                                       triangles=open3d.utility.Vector3iVector(mesh.faces))
            mesh = open3d_mesh.simplify_quadric_decimation(int(20000))
            mesh = trimesh.Trimesh(np.asarray(mesh.vertices), np.asarray(mesh.triangles))

            with path_out.open('w') as file_obj:
                file_obj.write(trimesh.exchange.obj.export_obj(mesh))

        # Head
        self.data = QtCore.QUrl.fromLocalFile(str(path_out))

        self.head_entity = Qt3DCore.QEntity(self.root_entity)
        self.head_mesh = Qt3DRender.QMesh()
        self.head_mesh.setMeshName(str(path_out))
        self.head_mesh.setSource(self.data)

        self.head_entity.addComponent(self.head_mesh)
        self.head_entity.addComponent(self.material)

        self.camController = Qt3DExtras.QOrbitCameraController(self.head_mesh)
        self.camController.setCamera(self.camera)
        self.camController.setLinearSpeed(self.camController.linearSpeed()*100)
        self.mesh_center_of_mass = np.median(surf['rr'], 0)*1000
        self.camera.setViewCenter(QtGui.QVector3D(*(self.mesh_center_of_mass)))

        self.camera.viewCenterChanged.connect(self.cam_view_center_changed)

        ## EEG electrodes and Fiducials
        self.electrode_material = Qt3DExtras.QPhongMaterial(diffuse=QtGui.QColor("#665423"))
        self.fid_material = Qt3DExtras.QPhongMaterial(diffuse=QtGui.QColor("#0000FF"))
        self.selected_material = Qt3DExtras.QPhongMaterial(diffuse=QtGui.QColor("#FF0000"))
        self.edited_material = Qt3DExtras.QPhongMaterial(diffuse=QtGui.QColor("#FFFF00"))
        self.acq_material = Qt3DExtras.QPhongMaterial(diffuse=QtGui.QColor("#00FF00"))
        self.selected_item = None

        self.coordinate_meshes = {}
        self.coordinate_entities = {}
        self.coordinate_transforms = {}
        self.coordinate_materials = {}

        for kind, var in zip(["fid", "elec"], [fid, eeg]):
            for label, pos in var.iterrows():
                pos = pos.values*1000
                self.coordinate_meshes[label] = Qt3DExtras.QSphereMesh(rings=20, slices=20, radius=3)
                self.coordinate_entities[label] = Qt3DCore.QEntity(self.root_entity)
                self.coordinate_transforms[label] = Qt3DCore.QTransform(self.coordinate_meshes[label])
                self.coordinate_transforms[label].setTranslation(QtGui.QVector3D(*pos))

                self.coordinate_entities[label].addComponent(self.coordinate_meshes[label])
                self.coordinate_entities[label].addComponent(self.coordinate_transforms[label])

        self.acq_coordinate_meshes = {}
        self.acq_coordinate_entities = {}
        self.acq_coordinate_transforms = {}

        self.df_montage = pd.concat([fid, eeg])
        self.df_montage.columns = ["x", "y", "z"]
        self.df_acq = pd.concat([self.df_montage.copy().rename(columns={"x": f"x{i+1}", "y": f"y{i+1}", "z": f"z{i+1}"})
                                 for i in range(4)], axis=1)
        model = DataFrameModel(self.df_acq)
        self.tableView.setModel(model)
        self.df_acq.loc[:, :] = np.nan

        self.set_table_view_selection(0)
        self.view.setRootEntity(self.root_entity)

        self.subject_name_wgt.currentTextChanged.connect(self.load_subject)
        self.update_subject_lst()
Exemple #18
0
    def createScene(self):
        # Root entity
        self.rootEntity = Qt3DCore.QEntity()

        # Material
        self.material = Qt3DExtras.QPhongMaterial(self.rootEntity)
Exemple #19
0
    def __init__(self, parent=None):
        super().__init__(parent)
        self.rnd_lat = random.randrange(5200,5300)  / 100.0
        self.rnd_hdg = random.randrange(-300,300)  / 100.0
        self.rnd_dec = random.randrange(-50,50) / 10.0

        print(self.rnd_lat, self.rnd_hdg, self.rnd_dec)

        self.view = Qt3DExtras.Qt3DWindow()
        self.view.defaultFrameGraph().setClearColor(QtGui.QColor("#4d4d4f"))
        self.container = QtWidgets.QWidget.createWindowContainer(self.view)
        self.vLayout = QtWidgets.QVBoxLayout(self)
        self.vLayout.addWidget(self.container, 1)

        self.input_aspect = Qt3DInput.QInputAspect()
        self.view.registerAspect(self.input_aspect)

        self.rootEntity = Qt3DCore.QEntity()
        self.view.setRootEntity(self.rootEntity)

        ###

        cameraEntity = self.view.camera()
        cameraEntity.lens().setPerspectiveProjection(5.0, 16.0 / 9.0, 10, 100000.0)
        cameraEntity.setPosition(QtGui.QVector3D(0, 1000, 50000))
        cameraEntity.setUpVector(QtGui.QVector3D(0, 1, 0))
        cameraEntity.setViewCenter(QtGui.QVector3D(0, 1000, 0))

        self.camController = Qt3DExtras.QOrbitCameraController(self.rootEntity)
        self.camController.setCamera(cameraEntity)

        ###

        self.lightEntity = Qt3DCore.QEntity(self.rootEntity)
        self.light = Qt3DRender.QPointLight(self.lightEntity)
        self.light.setColor("white")
        self.light.setIntensity(1)

        self.lightTransform = Qt3DCore.QTransform(self.lightEntity)
        self.lightTransform.setTranslation(cameraEntity.position())

        self.lightEntity.addComponent(self.light)
        self.lightEntity.addComponent(self.lightTransform)

        ### sky
        # self.skyMesh = Qt3DExtras.QSphereMesh(radius=5000, rings=94, slices=48)
        # self.skyMaterial = Qt3DExtras.QPhongMaterial(diffuse=QtGui.QColor("#ff0000"))

        # self.skyEntity = Qt3DCore.QEntity(self.rootEntity)
        # self.skyEntity.addComponent(self.skyMesh)
        # self.skyEntity.addComponent(self.skyMaterial)

        ### hdg, x right, y up

        # Cylinder cog = (0,0,0) long direction = y
        self.hdgMesh = Qt3DExtras.QCylinderMesh(length=1200.0, radius=100.0, rings=100, slices=20)
        rotation = QtGui.QQuaternion.fromAxisAndAngle(QtGui.QVector3D(0.0, 0.0, 1.0), 15.0)
        translation = QtGui.QVector3D(0.0, 600.0, 0.0)
        self.hdgTransform = Qt3DCore.QTransform(translation=translation, rotation=rotation)
        self.hdgMaterial = Qt3DExtras.QPhongMaterial(diffuse=QtGui.QColor("#ff0000"))
        self.hdgEntity = Qt3DCore.QEntity(self.rootEntity)
        self.hdgEntity.addComponent(self.hdgMesh)
        self.hdgEntity.addComponent(self.hdgMaterial)
        self.hdgEntity.addComponent(self.hdgTransform)

        ### lat x up, y left
        self.latMesh = Qt3DExtras.QCylinderMesh(length=200.0, radius=100.0, rings=100, slices=20)
        rotation = QtGui.QQuaternion.fromAxisAndAngle(QtGui.QVector3D(0.0, 0.0, 1.0), 90.0)
        translation = QtGui.QVector3D(0.0, 700.0, 0.0)
        self.latTransform = Qt3DCore.QTransform(rotation=rotation, translation=translation)
        self.latMaterial = Qt3DExtras.QPhongMaterial(diffuse=QtGui.QColor("#00ff00"))
        self.latEntity = Qt3DCore.QEntity(self.hdgEntity)
        self.latEntity.addComponent(self.latMesh)
        self.latEntity.addComponent(self.latMaterial)
        self.latEntity.addComponent(self.latTransform)

        ### ra x up, y left

        self.raMesh = Qt3DExtras.QCylinderMesh(length=500.0, radius=100.0, rings=100, slices=20)
        rotation1 = QtGui.QQuaternion.fromAxisAndAngle(QtGui.QVector3D(0.0, 0.0, -1.0), 90)
        rotation2 = QtGui.QQuaternion.fromAxisAndAngle(QtGui.QVector3D(-1.0, 0.0, 0.0), 90)
        rotation = rotation1 * rotation2
        translation = QtGui.QVector3D(200.0, 0.0, 0.0)
        self.raTransform = Qt3DCore.QTransform(rotation=rotation, translation=translation)
        self.raMaterial = Qt3DExtras.QPhongMaterial(diffuse=QtGui.QColor("#beb32b"))
        self.raEntity = Qt3DCore.QEntity(self.latEntity)
        self.raEntity.addComponent(self.raMesh)
        self.raEntity.addComponent(self.raMaterial)
        self.raEntity.addComponent(self.raTransform)

        ### dec

        self.decMesh = Qt3DExtras.QCylinderMesh(length=500.0, radius=100.0, rings=100, slices=20)
        rotation = QtGui.QQuaternion.fromAxisAndAngle(QtGui.QVector3D(1.0, 0.0, 0.0), 90.0)
        translation = QtGui.QVector3D(0.0, 350.0, 0.0)
        self.decTransform = Qt3DCore.QTransform(rotation=rotation, translation=translation)
        self.decMaterial = Qt3DExtras.QPhongMaterial(diffuse=QtGui.QColor("#0000ff"))
        self.decEntity = Qt3DCore.QEntity(self.raEntity)
        self.decEntity.addComponent(self.decMesh)
        self.decEntity.addComponent(self.decMaterial)
        self.decEntity.addComponent(self.decTransform)

        ### tube

        self.tubeMesh = Qt3DExtras.QCylinderMesh(length=1200.0, radius=100.0, rings=100, slices=20)

        rotation = QtGui.QQuaternion.fromAxisAndAngle(QtGui.QVector3D(-1.0, 0.0, 0.0), 90.0)
        translation = QtGui.QVector3D(0.0, 350.0, 100.0)
        self.tubeTransform = Qt3DCore.QTransform(rotation=rotation, translation=translation)
        self.tubeMaterial = Qt3DExtras.QPhongMaterial(diffuse=QtGui.QColor("#ffffff"))
        self.tubeEntity = Qt3DCore.QEntity(self.decEntity)
        self.tubeEntity.addComponent(self.tubeMesh)
        self.tubeEntity.addComponent(self.tubeMaterial)
        self.tubeEntity.addComponent(self.tubeTransform)

        self.ocuMesh = Qt3DExtras.QCylinderMesh(length=100.0, radius=50.0, rings=100, slices=20)
        translation = QtGui.QVector3D(0.0, -650.0, 0.0)
        self.ocuTransform = Qt3DCore.QTransform(translation=translation)
        self.ocuMaterial = Qt3DExtras.QPhongMaterial(diffuse=QtGui.QColor("#ffffff"))
        self.ocuEntity = Qt3DCore.QEntity(self.tubeEntity)
        self.ocuEntity.addComponent(self.ocuMesh)
        self.ocuEntity.addComponent(self.ocuMaterial)
        self.ocuEntity.addComponent(self.ocuTransform)

        self.fakeMesh = Qt3DExtras.QCuboidMesh(xExtent=500, yExtent=500, zExtent=500)
        translation = QtGui.QVector3D(-1000.0, 0, 0.0)
        self.fakeTransform = Qt3DCore.QTransform(translation=translation)
        self.fakeMaterial = Qt3DExtras.QPhongMaterial(diffuse=QtGui.QColor("#ffffff"))
        self.fakeEntity = Qt3DCore.QEntity(self.rootEntity)
        self.fakeEntity.addComponent(self.fakeMesh)
        self.fakeEntity.addComponent(self.fakeMaterial)
        self.fakeEntity.addComponent(self.fakeTransform)

        self._heading = 0
        self._latitude = 45
        self._ra = 0
        self._dec = 90
Exemple #20
0
    def __init__(self, args, parent=None):
        super().__init__(parent)
        ##############################################################################
        # UI初期化処理
        self.ui = MainWindowUi.loader(os.path.join(os.getcwd(), 'ui/main.ui'))
        self.setWindowTitle('self.viewer test')
        self.setCentralWidget(self.ui.widgets)

        self.view = Qt3DExtras.Qt3DWindow()
        self.view.defaultFrameGraph().setClearColor(QtGui.QColor(0, 0, 0))
        self.container = QWidget.createWindowContainer(self.view)

        screen_size = self.view.screen().size()
        self.ui.viewer.addWidget(self.container)
        self.container.setMinimumSize(QtCore.QSize(400, 600))
        self.container.setMaximumSize(screen_size)

        # QSize screenSize = self.view -> screen() -> size();
        # container -> setMinimumSize(QSize(200, 100));
        # container -> setMaximumSize(screenSize);

        # vLayout -> setAlignment(Qt: : AlignTop);
        # hLayout -> addWidget(container, 1);
        # hLayout -> addLayout(vLayout);

        # input_aspect = Qt3DInput.QInputAspect()
        # self.view.registerAspect(input_aspect)

        # root entity
        self.root_entity: Qt3DCore.QEntity = Qt3DCore.QEntity()

        # draw grid and axis
        """
        self.x_axis: Qt3DRender.QGeometry = Qt3DRender.QGeometry(self.root_entity)
        x_axis_pos: QtCore.QByteArray = QtCore.QByteArray()
        x_axis_pos.append(0)
        x_axis_pos.append(0)
        x_axis_pos.append(0)
        x_axis_pos.append(10)
        x_axis_pos.append(0)
        x_axis_pos.append(0)
        x_axis_buf: Qt3DRender.QBuffer = Qt3DRender.QBuffer(self.x_axis)
        x_axis_buf.setData(x_axis_pos)

        x_axis_attr: Qt3DRender.QAttribute = Qt3DRender.QAttribute(self.x_axis)
        x_axis_attr.setVertexBaseType(Qt3DRender.QAttribute.Float)
        x_axis_attr.setVertexSize(3)
        x_axis_attr.setAttributeType(Qt3DRender.QAttribute.VertexAttribute)
        x_axis_attr.setBuffer(x_axis_buf)
        x_axis_attr.setByteStride(3)
        x_axis_attr.setCount(2)
        self.x_axis.addAttribute(x_axis_attr)
        """

        test_mtl = Qt3DExtras.QTextureMaterial(self.root_entity)

        self.test = Qt3DCore.QEntity(self.root_entity)
        self.test_mesh: Qt3DExtras.QTorusMesh = Qt3DExtras.QTorusMesh()
        self.test_mesh.setRadius(5)
        self.test_mesh.setMinorRadius(1)
        self.test_mesh.setRings(100)
        self.test_mesh.setSlices(20)
        self.test_tr = Qt3DCore.QTransform()
        self.test_tr.setTranslation(QtGui.QVector3D(0, 0, 0))
        # test_tr.setScale3D()
        self.test.addComponent(self.test_mesh)
        self.test.addComponent(self.test_tr)
        self.test.addComponent(self.test_mtl)

        # camera entity
        camera_entity: Qt3DRender.QCamera = self.view.camera()

        camera_entity.lens().setPerspectiveProjection(45.0, 16.0 / 9.0, 0.1, 1000.0)
        camera_entity.setPosition(QtGui.QVector3D(0, 0, 20.0))
        camera_entity.setUpVector(QtGui.QVector3D(0, 1, 0))
        camera_entity.setViewCenter(QtGui.QVector3D(0, 0, 0))

        light_entity = Qt3DCore.QEntity(self.root_entity)
        light = Qt3DRender.QPointLight(light_entity)
        light.setColor("white")
        light.setIntensity(1)
        light_entity.addComponent(light)

        light_transform = Qt3DCore.QTransform(light_entity)
        light_transform.setTranslation(camera_entity.position())
        light_entity.addComponent(light_transform)

        # for camera controls
        cam_controller = Qt3DExtras.QFirstPersonCameraController(self.root_entity)
        cam_controller.setCamera(camera_entity)

        # set root object of the scene
        self.view.setRootEntity(self.root_entity)
Exemple #21
0
    def __init__(self):
        super(AthenaViewer, self).__init__()
        self._qtrefs = []

        self.framegraph = AthenaFrameGraph(self)
        self.setActiveFrameGraph(self.framegraph.root)

        self.resetBackgroundColor()
        self.lightOrientation = int(0) # Internal integer controlling light.position attribute
        self.renderSettings().setRenderPolicy(self.renderSettings().OnDemand)

        self.rootEntity = Qt3DCore.QEntity()

        self.initParameters() # defined in metaclass
        self.faceEnableChanged.connect( self.handleFaceRenderChange )
        self.lightPositionChanged.connect( self.handleLightPositionChange )
        self.wireEnableChanged.connect( self.handleWireframeRenderChange )

        self.sphere_material = self._imposterMaterial('sphere')
        self.cylinder_material = self._imposterMaterial('cylinder')
        self.cone_material = self._imposterMaterial('cone')

        self.flat_material = self._plyMeshMaterial( 'flat' )
        self.flat_material.addParameter( self._flatColorParam )

        self.gooch_material = self._plyMeshMaterial( 'gooch' )
        self.gooch_material.addParameter( self._coolColorParam )
        self.gooch_material.addParameter( self._warmColorParam )
        self.gooch_material.addParameter( self._lightPositionParam )

        # The vertical split line enabled for split-screen view
        self.overlay_material = self._overlayMaterial()

        self.splitLineEntity = decorations.LineDecoration( self.rootEntity, [0,-1,0], [0,1,0], [1,1,1,1] )
        self.splitLineEntity.addComponent( self.overlay_material )
        self.splitLineEntity.setEnabled(False)

        # Each time a mesh is loaded, we create a new Plymesh and add a material as a component.
        # Old meshes are deleteLater()-ed.  A problem with this approach is that the deleted QEntities
        # also delete their components (and this seems true even if we try to remove the component first).
        # The workaround we use here is to also add the materials as components of the root entity,
        # which keeps Qt3D from deleting them.  I don't know if this is the best approach, but it works.
        self.rootEntity.addComponent(self.flat_material)
        self.rootEntity.addComponent(self.gooch_material)
        self.rootEntity.addComponent(self.sphere_material)
        self.rootEntity.addComponent(self.cylinder_material)
        self.rootEntity.addComponent(self.cone_material)

        self.setRootEntity(self.rootEntity)

        self.meshEntityParent = Qt3DCore.QEntity( self.rootEntity )

        self.meshEntity = None

        class DecorationEntity(Qt3DCore.QEntity):
            def __init__(self, parent):
                super().__init__(parent)
                self.spheres = None
                self.cylinders = None
                self.cones = None

        self.cylModelEntity = DecorationEntity( self.rootEntity )
        self.routModelEntities = [ DecorationEntity( self.rootEntity ) for x in range(2) ]
        self.atomModelEntities = [ DecorationEntity( self.rootEntity ) for x in range(2) ]

        self.lastpos = None
        self.mouseTool = 'rotate'

        self.setDpi( self.screen().physicalDotsPerInch() )
        self.camControl = OrthoCamController(self,self.camera(),None,False)