示例#1
0
    def _get_iso_mesh(self, data, color, sign):

        iso_val = sign * self.options.get_iso_val()
        vertices, faces = isosurface(data, iso_val * data.max())
        nx, ny, nz = data.shape

        # Center Isosurface around Origin
        vertices[:, 0] = vertices[:, 0] - nx / 2
        vertices[:, 1] = vertices[:, 1] - ny / 2
        vertices[:, 2] = vertices[:, 2] - nz / 2

        mesh_data = MeshData(vertexes=vertices, faces=faces)
        colors = np.zeros((mesh_data.faceCount(), 4), dtype=float)
        # Sets color to Red (RGB, 0 = red, 1 = green, 2 = blue)
        if color == 'red':
            colors[:, 0] = 1.0
            colors[:, 1] = 0.2
            colors[:, 2] = 0.2

        elif color == 'blue':
            colors[:, 0] = 0.2
            colors[:, 1] = 0.2
            colors[:, 2] = 1.0
        # Transparency (I guess)
        colors[:, 3] = 1
        mesh_data.setFaceColors(colors)

        mesh = GLMeshItem(meshdata=mesh_data,
                          smooth=True,
                          shader='edgeHilight')
        mesh.setGLOptions('translucent')

        return mesh
示例#2
0
    def _get_iso_mesh(self,
                      data,
                      iso=None,
                      color=(1, 0.2, 0.2, 1),
                      z_shift=True):

        if iso is None:
            iso_val = self.options.get_iso_val() * data.max()
        else:
            iso_val = iso

        vertices, faces = isosurface(data, iso_val)
        nx, ny, nz = data.shape

        # Center Isosurface around Origin
        vertices[:, 0] = vertices[:, 0] - nx / 2
        vertices[:, 1] = vertices[:, 1] - ny / 2
        if z_shift:
            vertices[:, 2] = vertices[:, 2] - nz / 2

        mesh_data = MeshData(vertexes=vertices, faces=faces)
        colors = np.zeros((mesh_data.faceCount(), 4), dtype=float)
        for idx in range(4):
            colors[:, idx] = color[idx]

        mesh_data.setFaceColors(colors)

        mesh = GLMeshItem(meshdata=mesh_data,
                          smooth=True,
                          shader='edgeHilight')
        mesh.setGLOptions('translucent')

        return mesh
示例#3
0
    def __init__(self, vertexes=None, indices=None, *args, **kwds):
        """
        Constructor for the MeshObject class.

        Parameters:
        vertexes (list): List of vertices used in the mesh.
        indices (list): List of indices for the faces used in the mesh.
        rot_quat (glm.quat): Quaternion defining the rotation of the object.
        rot_vec (vec3): Vector3 defining the rotation of the object.
        scale (vec3): Scale factor for each axis of the object. Defaults to (1.0, 1.0, 1.0)
        position (vec3): Position of the object. Defaults to (0.0, 0.0, 0.0)
        """
        GLMeshItem.__init__(self)
        SpatialObject.__init__(self)
        # Argument extraction
        self.opts = {
            "vertexes": None,
            "model_verts": None,
            "indices": None,
            "position": vec3(0.0),
            "rot_vec": None,
            "rot_quat": None,
            "scale": vec3(1.0),
            "smooth": True,
            "computeNormals": False,
            "drawEdges": False,
            "drawFaces": True,
            "shader": None,
            "color": (1.0, 1.0, 1.0, 1.0),
            "edgeColor": (0.5, 0.5, 0.5, 1.0),
        }
        for k, v in kwds.items():
            self.opts[k] = v
        if(vertexes is not None):
            self.opts["vertexes"] = vertexes
        if(indices is not None):
            self.opts["indices"] = indices
            
        self.set_position(self.opts["position"], False)
        if (self.opts["rot_quat"] is not None):
          self.rotation = R.from_quat(self.opts["rot_quat"])
        if (self.opts["rot_vec"] is not None):
          self.rotation = R.from_rotvec(self.opts["rot_vec"])
        self.set_scale(self.opts["scale"], False)
        self.opts["meshdata"] = MeshData()
        self.set_vertexes(self.opts["vertexes"], False)
        self.set_indices(self.opts["indices"], False)
        if (self.opts["vertexes"] is not None):
            self.update_vertices()
示例#4
0
def make_center():
    """
    Create a marker for the center and wrap it in a GLMeshItem.
    """
    mesh = MeshData.sphere(10, 10, 1)
    item = GLMeshItem(meshdata=mesh, color=[0.4, 0.4, 0.4, 1])
    return item
示例#5
0
 def plot_letter(self):
     self.widget.removeItem(self.letter)
     self.letter = GLMeshItem(meshdata=MeshData(self.vertexes, self.faces),
                              drawFaces=False,
                              edgeColor=QColor(51, 204, 255),
                              drawEdges=True)
     self.widget.addItem(self.letter)
示例#6
0
def make_arrow(color):
    """
    Create an axis arrow mesh and wrap it in a GLMeshItem.

    :param Sequence[float] color: the color for the arrow, e.g. [r, g, b, a]
    """
    mesh = MeshData.cylinder(10, 10)
    item = GLMeshItem(meshdata=mesh, color=color)
    return item
示例#7
0
    def run(self):
        """
        This does the actual mesh generation.

        The labeling is converted into a mesh which is then wrapped in a GLMeshItem.
        For each generated mesh the signal mesh_generated is emitted containing the label/name and mesh.

        When finished the signal mesh_generated is emitted again with label 0 and mesh None
        """
        for label, mesh in labeling_to_mesh(self._labeling, self._labels):
            item = GLMeshItem(meshdata=mesh, smooth=True, shader="toon")
            self.mesh_generated.emit(self._mapping.get(label, label), item)
        self.mesh_generated.emit(0, None)
示例#8
0
 def build_projections(self):
     if self.projectXY is not None and self.projectionsVisible:
         self.widget.removeItem(self.projectXY)
     if self.projectXZ is not None and self.projectionsVisible:
         self.widget.removeItem(self.projectXZ)
     if self.projectYZ is not None and self.projectionsVisible:
         self.widget.removeItem(self.projectYZ)
     self.projectionsVisible = False
     projectXY = [[0.0 for _ in range(self.dim + 1)]
                  for _ in range(self.dim + 1)]
     for i in range(self.dim + 1):
         projectXY[i][i] = 1.0
     projectYZ = copy.deepcopy(projectXY)
     projectXZ = copy.deepcopy(projectXY)
     projectXY[2][2] = 0.0
     projectXZ[1][1] = 0.0
     projectYZ[0][0] = 0.0
     projectXY_vert = []
     projectXZ_vert = []
     projectYZ_vert = []
     for vertex in self.vertexes:
         projectXY_vert.append(multiply_matvec(projectXY, vertex))
         projectXZ_vert.append(multiply_matvec(projectXZ, vertex))
         projectYZ_vert.append(multiply_matvec(projectYZ, vertex))
     self.projectXY = GLMeshItem(meshdata=MeshData(np.array(projectXY_vert),
                                                   self.faces),
                                 drawFaces=True,
                                 edgeColor=QColor(9, 156, 19),
                                 drawEdges=False)
     self.projectXZ = GLMeshItem(meshdata=MeshData(np.array(projectXZ_vert),
                                                   self.faces),
                                 drawFaces=True,
                                 edgeColor=QColor(9, 156, 19),
                                 drawEdges=False)
     self.projectYZ = GLMeshItem(meshdata=MeshData(np.array(projectYZ_vert),
                                                   self.faces),
                                 drawFaces=True,
                                 edgeColor=QColor(9, 156, 19),
                                 drawEdges=False)
示例#9
0
 def __init__(self, *args, **kwargs):
     super(MainWindow, self).__init__(*args, **kwargs)
     self.setupUi(self)
     self.numberValidator = QDoubleValidator()
     self.translateX.setValidator(self.numberValidator)
     self.translateY.setValidator(self.numberValidator)
     self.translateZ.setValidator(self.numberValidator)
     self.scaleX.setValidator(self.numberValidator)
     self.scaleY.setValidator(self.numberValidator)
     self.scaleZ.setValidator(self.numberValidator)
     self.rotateX.setValidator(self.numberValidator)
     self.rotateY.setValidator(self.numberValidator)
     self.rotateZ.setValidator(self.numberValidator)
     self.projectionsVisible = False
     self.projectXY = None
     self.projectXZ = None
     self.projectYZ = None
     self.dim = 3
     self.setWindowTitle("3D Letter")
     self.vertexes = np.array([[20, -20, -10], [20, -20, 10], [10, -20, 10],
                               [10, -20, -10], [20, 10, -10], [20, 10, 10],
                               [10, 10, 10], [10, 10, -10], [20, 20, -10],
                               [20, 20, 10], [10, 20, 10], [10, 20, -10],
                               [0, 0, -10], [0, 10, -10], [0, 0, 10],
                               [0, 10, 10], [-10, -20, -10], [-10, -20, 10],
                               [-20, -20, 10], [-20, -20, -10],
                               [-10, 10, -10], [-10, 10, 10], [-20, 10, 10],
                               [-20, 10, -10], [-10, 20,
                                                -10], [-10, 20, 10],
                               [-20, 20, 10], [-20, 20, -10]])
     self.faces = np.array([[3, 0, 8], [8, 11, 3], [0, 1, 9], [9, 8, 0],
                            [2, 3, 7], [7, 6, 2], [1, 2, 10], [10, 9, 1],
                            [0, 3, 2], [2, 1, 0], [12, 7, 11], [11, 13, 12],
                            [20, 12, 13], [13, 24, 20], [13, 11, 10],
                            [10, 15, 13], [24, 13, 15], [15, 25, 24],
                            [14, 21, 25], [25, 15, 14], [6, 14, 15],
                            [15, 10, 6], [14, 6, 7], [7, 12, 14],
                            [21, 14, 12], [12, 20, 21], [16, 17, 21],
                            [21, 20, 16], [18, 19, 27], [27, 26, 18],
                            [19, 16, 24], [24, 27, 19], [17, 18, 26],
                            [26, 27, 17], [18, 17, 16], [16, 19, 18],
                            [27, 24, 25], [25, 26, 27]])
     self.original_vertexes = copy.deepcopy(self.vertexes)
     self.letter = GLMeshItem(meshdata=MeshData(self.vertexes, self.faces),
                              drawFaces=False,
                              edgeColor=QColor(51, 204, 255),
                              drawEdges=True)
     self.pushButton.clicked.connect(self.perform_transformations)
     self.resetButton.clicked.connect(self.reset)
     self.projectionButton.clicked.connect(self.show_projections)
     self.init_plot()
示例#10
0
 def __init__(self, **kwds):
     #super(CustomFrame, self,).__init__(size, color, glOptions)
     GLMeshItem.__init__(self, **kwds)