Ejemplo n.º 1
0
def calc_colors(nPoints=1, USE_UNIFORM_COLOR = True):
# < 0.1ms

	''' USE_UNIFORM_COLOR is True or False by default
		USE_UNIFORM_COLOR can also be a list defining the color to use [1, 1, 1]
	'''

	# generate well visible (not too dark) colors
	if not USE_UNIFORM_COLOR:
		while True:
			color = [random.random() for j in xrange(0, 3)]
			if sum(color) > 0.5:
				break
	else:
		# default color used for all points
		if USE_UNIFORM_COLOR is not True and len(USE_UNIFORM_COLOR) == 3 and \
			(sum([int(isinstance( j, ( int, long ) )) for j in USE_UNIFORM_COLOR]) == 3 or \
			sum([int(isinstance( j, ( float, long ) )) for j in USE_UNIFORM_COLOR]) == 3):
			color = [float(j) for j in USE_UNIFORM_COLOR]
		else:
			color = [1, 0, 0]


	n_color_coord = len(color)

	# create long list of uniform colors
	colors = []
	for j in xrange(nPoints):
		for i in range(n_color_coord):
			colors.append(color[i])

	# return array of colors for number of points, as well as the 'color' that 
	# had been generated / used.
	return gl_transform_list_to_GLfloat(colors), color
Ejemplo n.º 2
0
def calc_points_equal_dist_zig_zag_y(nPoints=1, width_Max = 780, height_Max = 780, y_offset = 0, interleaved = True):
	# create list of x & y coordinates; x is followed by y. y scales with the window size.
	Min = 20
	y_offset = 50
	x_coords = np.arange(Min, width_Max, calc_stepsize(Min, width_Max, nPoints))
	y_scale = float(height_Max) / nPoints
	coords = []

	# show 100 zig-zags
	mod_value = int(nPoints / 100.0)

	# interleaved mode: x1y1 x2y2 x3y3
	if interleaved:
		for j in range(nPoints):
			coords.append(x_coords[j])
			if j % mod_value == 0:
				coords.append(y_offset + 0.3 * (y_scale * j))
			else:
				coords.append(y_offset + (y_scale * j))

	# non-interleaved mode: x1x2x3 y1y2y3
	else:
		# all x coordinates first
		for j in range(nPoints):
			coords.append(x_coords[j])

		# now all y coordinates
		for j in range(nPoints):
			if j % 2 == 0:
				coords.append(y_offset + (y_scale * j) - (2.0/3 * y_scale))
			else:
				coords.append(y_offset + (y_scale * j))
		
	# print coords
	return gl_transform_list_to_GLfloat(coords), coords, x_coords
Ejemplo n.º 3
0
def calc_points_equal_dist(nPoints=1, width_Max = 780, height_Max = 780, interleaved = True):

	# create list of x & y coordinates; x is followed by y. y is a random number.
	Min = 20

	x_coords = np.arange(Min, width_Max, calc_stepsize(Min, width_Max, nPoints))
	y_values = np.random.randint(Min, height_Max, nPoints)

	coords = []

	# interleaved mode: x1y1 x2y2 x3y3
	if interleaved:

		# slow:
		#for i, j in zip(x_coords, y_values):
		#    coords.append(i)
		#    coords.append(j)

		# fast:
		for j in range(nPoints):
			coords.append(x_coords[j])
			coords.append(y_values[j])

	# non-interleaved mode: x1x2x3 y1y2y3
	else:
		# all x coordinates first
		for j in range(nPoints):
			coords.append(x_coords[j])

		# now all y coordinates
		for j in range(nPoints):
			coords.append(random.randint(Min, height_Max))
		
	return gl_transform_list_to_GLfloat(coords), coords, x_coords
Ejemplo n.º 4
0
def calc_points_equal_dist_scale_y_with_x(nPoints=1, width_Max = 780, height_Max = 780, interleaved = True):
	# create list of x & y coordinates; x is followed by y. y scales with the window size.
	Min = 20
	x_coords = np.arange(Min, width_Max, calc_stepsize(Min, width_Max, nPoints))
	y_scale = float(height_Max) / nPoints
	coords = []

	# interleaved mode: x1y1 x2y2 x3y3
	if interleaved:
		for j in range(nPoints):
			coords.append(x_coords[j])
			coords.append(y_scale * (j+1))

	# non-interleaved mode: x1x2x3 y1y2y3
	else:
		# all x coordinates first
		for j in range(nPoints):
			coords.append(x_coords[j])

		# now all y coordinates
		for j in range(nPoints):
			coords.append(y_scale * (j+1))

		
	# print coords
	return gl_transform_list_to_GLfloat(coords), coords, x_coords
Ejemplo n.º 5
0
def calc_colors(nPoints=1, USE_UNIFORM_COLOR=True):
    # < 0.1ms
    ''' USE_UNIFORM_COLOR is True or False by default
		USE_UNIFORM_COLOR can also be a list defining the color to use [1, 1, 1]
	'''

    # generate well visible (not too dark) colors
    if not USE_UNIFORM_COLOR:
        while True:
            color = [random.random() for j in xrange(0, 3)]
            if sum(color) > 0.5:
                break
    else:
        # default color used for all points
        if USE_UNIFORM_COLOR is not True and len(USE_UNIFORM_COLOR) == 3 and \
         (sum([int(isinstance( j, ( int, long ) )) for j in USE_UNIFORM_COLOR]) == 3 or \
         sum([int(isinstance( j, ( float, long ) )) for j in USE_UNIFORM_COLOR]) == 3):
            color = [float(j) for j in USE_UNIFORM_COLOR]
        else:
            color = [1, 0, 0]

    n_color_coord = len(color)

    # create long list of uniform colors
    colors = []
    for j in xrange(nPoints):
        for i in range(n_color_coord):
            colors.append(color[i])

    # return array of colors for number of points, as well as the 'color' that
    # had been generated / used.
    return gl_transform_list_to_GLfloat(colors), color
Ejemplo n.º 6
0
def calc_points_equal_dist_scale_y_with_x(nPoints=1,
                                          width_Max=780,
                                          height_Max=780,
                                          interleaved=True):
    # create list of x & y coordinates; x is followed by y. y scales with the window size.
    Min = 20
    x_coords = np.arange(Min, width_Max, calc_stepsize(Min, width_Max,
                                                       nPoints))
    y_scale = float(height_Max) / nPoints
    coords = []

    # interleaved mode: x1y1 x2y2 x3y3
    if interleaved:
        for j in range(nPoints):
            coords.append(x_coords[j])
            coords.append(y_scale * (j + 1))

    # non-interleaved mode: x1x2x3 y1y2y3
    else:
        # all x coordinates first
        for j in range(nPoints):
            coords.append(x_coords[j])

        # now all y coordinates
        for j in range(nPoints):
            coords.append(y_scale * (j + 1))

    # print coords
    return gl_transform_list_to_GLfloat(coords), coords, x_coords
Ejemplo n.º 7
0
def generate_random_number_list_for_GPU(nPoints,
                                        coordinates_per_point=2,
                                        Float=True,
                                        Min=1,
                                        Max=200):
    data = generate_random_number_list(nPoints, coordinates_per_point, Float,
                                       Min, Max)
    # transform data into GLfloat pointer format for GPU
    return gl_transform_list_to_GLfloat(data)
Ejemplo n.º 8
0
def gl_transform_vector_of_buffers_to_GPU_format(raw_data, x_values):

    #import pdb; pdb.set_trace()

    # number channel to loop over.
    nbr_channels = len(raw_data)

    data = []
    for j in range(nbr_channels):
        data.append(gl_transform_list_to_GLfloat(create_2dim_list_from_arrays(x_values, raw_data[j])))

    return data
Ejemplo n.º 9
0
def calc_points_zeros(nPoints, width_Max = 780):

	Min = 20

	x_coords = np.arange(Min, width_Max, calc_stepsize(Min, width_Max, nPoints))
	y_values = np.zeros(nPoints)

	coords = []

	for j in range(nPoints):
		coords.append(x_coords[j])
		coords.append(y_values[j])

	return gl_transform_list_to_GLfloat(coords), coords, x_coords
Ejemplo n.º 10
0
def calc_points_zeros(nPoints, width_Max=780):

    Min = 20

    x_coords = np.arange(Min, width_Max, calc_stepsize(Min, width_Max,
                                                       nPoints))
    y_values = np.zeros(nPoints)

    coords = []

    for j in range(nPoints):
        coords.append(x_coords[j])
        coords.append(y_values[j])

    return gl_transform_list_to_GLfloat(coords), coords, x_coords
Ejemplo n.º 11
0
def gl_update_single_coordinate_in_VOB_static_view(raw_data, vbo_id, c, nPoints, nPointsToUpdate, BYTES_PER_POINT, BYTES_PER_COORDINATE, NBR_CHANNELS, x_coords):

    ''' Updates y coordinates in a single VBO.
        Works with multiple channels and one VBO only (04.07.2012).'''
    
    offset_to_start_from = c % (nPoints / nPointsToUpdate)
    nbr_points_rendered_in_previous_loop = int(offset_to_start_from * nPointsToUpdate)

    # offset to Y coordinate, assuming memory layout x1y1 x2y2
    pointer_offset_orig = (nbr_points_rendered_in_previous_loop * BYTES_PER_POINT) + BYTES_PER_COORDINATE

    # TODO: this will work with multiple channels, but only one VBO per channel right now.
    for channel in range(NBR_CHANNELS):

        # grab the data for this channel
        data = raw_data[channel]

        # reset the pointer offset
        pointer_offset = pointer_offset_orig

        # bind the VBO once
        # TODO: this is a temporary situation with one VBO per panel!
        glBindBuffer(GL_ARRAY_BUFFER, vbo_id[channel][0])

        # go through list of points that have to be updated.
        for j in range(nPointsToUpdate):
            # add the 'per-point' offset for each iteration, except the first one, 
            # which is already at the correct position.
            if j > 0:
                pointer_offset = pointer_offset + BYTES_PER_POINT

            # grab data point from list, make it a list again ([]), and transfer into 
            # GLfloat
            this_data = gl_transform_list_to_GLfloat([data[j]])
    
            # bind buffer and overwrite position with offset 'pointer_offset',
            # which points to the y coordinate only.
            glBufferSubData(GL_ARRAY_BUFFER, pointer_offset, sizeof(this_data), this_data)    

    return offset_to_start_from
Ejemplo n.º 12
0
def calc_points_equal_dist_zig_zag_y(nPoints=1,
                                     width_Max=780,
                                     height_Max=780,
                                     y_offset=0,
                                     interleaved=True):
    # create list of x & y coordinates; x is followed by y. y scales with the window size.
    Min = 20
    y_offset = 50
    x_coords = np.arange(Min, width_Max, calc_stepsize(Min, width_Max,
                                                       nPoints))
    y_scale = float(height_Max) / nPoints
    coords = []

    # show 100 zig-zags
    mod_value = int(nPoints / 100.0)

    # interleaved mode: x1y1 x2y2 x3y3
    if interleaved:
        for j in range(nPoints):
            coords.append(x_coords[j])
            if j % mod_value == 0:
                coords.append(y_offset + 0.3 * (y_scale * j))
            else:
                coords.append(y_offset + (y_scale * j))

    # non-interleaved mode: x1x2x3 y1y2y3
    else:
        # all x coordinates first
        for j in range(nPoints):
            coords.append(x_coords[j])

        # now all y coordinates
        for j in range(nPoints):
            if j % 2 == 0:
                coords.append(y_offset + (y_scale * j) - (2.0 / 3 * y_scale))
            else:
                coords.append(y_offset + (y_scale * j))

    # print coords
    return gl_transform_list_to_GLfloat(coords), coords, x_coords
Ejemplo n.º 13
0
def calc_points_equal_dist(nPoints=1,
                           width_Max=780,
                           height_Max=780,
                           interleaved=True):

    # create list of x & y coordinates; x is followed by y. y is a random number.
    Min = 20

    x_coords = np.arange(Min, width_Max, calc_stepsize(Min, width_Max,
                                                       nPoints))
    y_values = np.random.randint(Min, height_Max, nPoints)

    coords = []

    # interleaved mode: x1y1 x2y2 x3y3
    if interleaved:

        # slow:
        #for i, j in zip(x_coords, y_values):
        #    coords.append(i)
        #    coords.append(j)

        # fast:
        for j in range(nPoints):
            coords.append(x_coords[j])
            coords.append(y_values[j])

    # non-interleaved mode: x1x2x3 y1y2y3
    else:
        # all x coordinates first
        for j in range(nPoints):
            coords.append(x_coords[j])

        # now all y coordinates
        for j in range(nPoints):
            coords.append(random.randint(Min, height_Max))

    return gl_transform_list_to_GLfloat(coords), coords, x_coords
Ejemplo n.º 14
0
def generate_random_number_list_for_GPU(nPoints, coordinates_per_point=2, Float=True, Min=1, Max=200):
	data = generate_random_number_list(nPoints, coordinates_per_point, Float, Min, Max)
	# transform data into GLfloat pointer format for GPU
	return gl_transform_list_to_GLfloat(data)