Example #1
0
    def get_hardcoded_frame(scale):
        # edges = dome_obj_data.get_dome_faces()
        vertices = dome_obj_data.get_dome_vertices()
        r = [x[1:] for x in vertices]

        #Nastily apply scaling to vertices for return variable.
        r2 = []
        for i in range(len(r)):
            r2.append([])
            for j in range(len(r[i])):
                r2[i].append(r[i][j] * scale)
        r = r2
        nparr = np.array(r)
        # print("Hardcoded frame: "+str(nparr.shape))
        checkVerticesValidity(r)
        return r
def draw_dome( scale_multiplier =2,
                show_points     = False,
                show_led_spheres= True,
                show_tris       = False,
                show_lines      = False, 
                get_not_show_tris  = False,
                show_selected_leds = None ):
        """
            Draw the dome into the current OpenGL view using old style opengl. And/Or return its point coordinates.
            -- Ready for refactoring... nasty code resides within -- 
        """
        scale = scale_multiplier
        edges = dome_obj_data.get_dome_edges()
        vertices = dome_obj_data.get_dome_vertices()
        r = [x[1:]  for x in vertices]
        
        #Nastily apply scaling to vertices for return variable.
        r2 = []
        for i in range(len(r)):
            r2.append([])
            for j in range(len(r[i])):
                r2[i].append(  r[i][j]* scale )
        r = r2
        
        glColor3f(1.0,1.0,1.0)
        
        if show_selected_leds != None and type(show_selected_leds) == list:
            # Add the unselected LEDs as points.
            glPointSize(2.0)
            glBegin(GL_POINTS)
            for i in range(len(vertices)):
                    v = vertices[i]
                    if i not in show_selected_leds:
                        glVertex3f( v[1]*scale, v[2]*scale, v[3]*scale )
            glEnd()
            # Add the selected LEDs as spheres.
            size = 0.3
            for i in range(len(vertices)):
                    v = vertices[i]
                    if i in show_selected_leds:
                        glPushMatrix()
                        glTranslatef( v[1]*scale, v[2]*scale, v[3]*scale )
                        glutWireSphere(size, 10, 10)
                        glPopMatrix()
            
        else:
            if show_points:        
                    glPointSize(4.0)
                    glBegin(GL_POINTS)
                    for v in vertices:
                            glVertex3f( v[1]*scale, v[2]*scale, v[3]*scale )
                    glEnd()
            if show_led_spheres:
                    size = 0.1
                    for v in vertices:
		                glPushMatrix()
		                glTranslatef( v[1]*scale, v[2]*scale, v[3]*scale )
		                glutWireSphere(size, 10, 10)
		                glPopMatrix()
            if show_tris and not get_not_show_tris:
                    glPointSize(1.0)
                    glBegin(GL_TRIANGLES)
                    r = []
                    r.append([])
                    c = 0
                    j = 0
                    for e in edges:
                            for i in e[1:]:
                                    c+=1
                                    v = vertices[i-1]
                                    tmpv = [v[1]*scale, v[2]*scale, v[3]*scale]
                                    glVertex3f( tmpv[0], tmpv[1], tmpv[2] )
                                    r[j].append(tmpv)
                                    if c % 3 == 0:
                                            j+=1
                                            r.append([])
                    glEnd()
                    """ Returns a list of lists of lists. The final list has 3 values. The mid-list has 3 vertices.
                        The first list contains all the triangles.
                    """
            if get_not_show_tris:
                    r = []
                    r.append([])
                    c = 0
                    j = 0
                    for e in edges:
                            for i in e[1:]:
                                    c+=1
                                    v = vertices[i-1]
                                    tmpv = [v[1]*scale, v[2]*scale, v[3]*scale]
                                    r[j].append(tmpv)
                                    if c % 3 == 0:
                                            j+=1
                                            r.append([])        
                    r = r[:len(r)-1]    # remove the final empty list.
                    """ Returns a list of lists of lists. The final list has 3 values. The mid-list has 3 vertices.
                        The first list contains all the triangles.
                    """
            if show_lines:
                    glPointSize(1.0)
                    glBegin(GL_LINES)
                    qty_e = 0
                    for e in edges:
                            p1 = vertices[e[1]-1]
                            p2 = vertices[e[2]-1]
                            p3 = vertices[e[3]-1]
                            #edge 1-2
                            glVertex3f( p1[1]*scale, p1[2]*scale, p1[3]*scale )
                            glVertex3f( p2[1]*scale, p2[2]*scale, p2[3]*scale )
                            #edge 2-3
                            glVertex3f( p2[1]*scale, p2[2]*scale, p2[3]*scale )
                            glVertex3f( p3[1]*scale, p3[2]*scale, p3[3]*scale )
                            qty_e += 2
                    glEnd()
        checkShapeValidity( r )
        return r