Skip to content

Commit

Permalink
city map and drone trajectory included
Browse files Browse the repository at this point in the history
  • Loading branch information
jbueno committed Sep 10, 2021
1 parent 2d83efe commit cb826dd
Show file tree
Hide file tree
Showing 40 changed files with 193,067 additions and 300 deletions.
17 changes: 17 additions & 0 deletions .project
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>bluesky</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>org.python.pydev.PyDevBuilder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.python.pydev.pythonNature</nature>
</natures>
</projectDescription>
8 changes: 8 additions & 0 deletions .pydevproject
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<?eclipse-pydev version="1.0"?><pydev_project>
<pydev_property name="org.python.pydev.PYTHON_PROJECT_INTERPRETER">Default</pydev_property>
<pydev_property name="org.python.pydev.PYTHON_PROJECT_VERSION">python interpreter</pydev_property>
<pydev_pathproperty name="org.python.pydev.PROJECT_SOURCE_PATH">
<path>/${PROJECT_DIR_NAME}</path>
</pydev_pathproperty>
</pydev_project>
92 changes: 46 additions & 46 deletions bluesky/ui/qtgl/glmap.py
Original file line number Diff line number Diff line change
@@ -1,86 +1,86 @@
''' BlueSky OpenGL map object. '''
from os import path
import numpy as np

from bluesky import settings
from bluesky.ui import palette
from bluesky.ui.qtgl import glhelpers as glh
from bluesky.ui.loadvisuals import load_coastlines
from bluesky import settings
from bluesky.ui.qtgl import glhelpers as glh
import numpy as np


settings.set_variable_defaults(gfx_path='data/graphics')
palette.set_default_colours(
background=(0, 0, 0),
coastlines=(85, 85, 115))
settings.set_variable_defaults( gfx_path='data/graphics' )
palette.set_default_colours(
background=( 0, 0, 0 ),
coastlines=( 85, 85, 115 ) )


class Map(glh.RenderObject, layer=-100):
class Map( glh.RenderObject, layer=-100 ):
''' Radar screen map OpenGL object. '''
def __init__(self, parent=None):
super().__init__(parent)
def __init__( self, parent=None ):
super().__init__( parent )

self.map = glh.VertexArrayObject(glh.gl.GL_TRIANGLE_FAN)
self.coastlines = glh.VertexArrayObject(glh.gl.GL_LINES)
self.map = glh.VertexArrayObject( glh.gl.GL_TRIANGLE_FAN )
self.coastlines = glh.VertexArrayObject( glh.gl.GL_LINES )
self.coastindices = []
self.vcount_coast = 0
self.wraplon_loc = 0

def create(self):
def create( self ):
''' Create GL objects. '''
# ------- Coastlines -----------------------------
coastvertices, self.coastindices = load_coastlines()
self.coastlines.create(vertex=coastvertices, color=palette.coastlines)
self.vcount_coast = len(coastvertices)
self.coastlines.create( vertex=coastvertices, color=palette.coastlines )
self.vcount_coast = len( coastvertices )

mapvertices = np.array(
[-90.0, 540.0, -90.0, -540.0, 90.0, -540.0, 90.0, 540.0], dtype=np.float32)
texcoords = np.array(
[1, 3, 1, 0, 0, 0, 0, 3], dtype=np.float32)
self.wraplon_loc = glh.ShaderSet.get_shader(self.coastlines.shader_type).attribs['lon'].loc
mapvertices = np.array(
[-90.0, 540.0, -90.0, -540.0, 90.0, -540.0, 90.0, 540.0], dtype=np.float32 )
texcoords = np.array(
[1, 3, 1, 0, 0, 0, 0, 3], dtype=np.float32 )
self.wraplon_loc = glh.ShaderSet.get_shader( self.coastlines.shader_type ).attribs['lon'].loc

# Load and bind world texture
max_texture_size = glh.gl.glGetIntegerv(glh.gl.GL_MAX_TEXTURE_SIZE)
print('Maximum supported texture size: %d' % max_texture_size)
max_texture_size = glh.gl.glGetIntegerv( glh.gl.GL_MAX_TEXTURE_SIZE )
print( 'Maximum supported texture size: %d' % max_texture_size )
for i in [16384, 8192, 4096]:
if max_texture_size >= i:
fname = path.join(settings.gfx_path,
'world.%dx%d.dds' % (i, i // 2))
print('Loading texture ' + fname)
self.map.create(vertex=mapvertices,
texcoords=texcoords, texture=fname)
fname = path.join( settings.gfx_path,
'world.%dx%d.dds' % ( i, i // 2 ) )
print( 'Loading texture ' + fname )
self.map.create( vertex=mapvertices,
texcoords=texcoords, texture=fname )
break

def draw(self, skipmap=False):
def draw( self, skipmap=False ):
# Send the (possibly) updated global uniforms to the buffer
self.shaderset.set_vertex_scale_type(self.shaderset.VERTEX_IS_LATLON)
self.shaderset.set_vertex_scale_type( self.shaderset.VERTEX_IS_LATLON )

# --- DRAW THE MAP AND COASTLINES ---------------------------------------------
# Map and coastlines: don't wrap around in the shader
self.shaderset.enable_wrap(False)
self.shaderset.enable_wrap( False )

if not skipmap:
self.map.draw()
shaderset = glh.ShaderSet.selected
if shaderset.data.wrapdir == 0:
# Normal case, no wrap around
self.coastlines.draw(
first_vertex=0, vertex_count=self.vcount_coast)
self.coastlines.draw(
first_vertex=0, vertex_count=self.vcount_coast )
else:
self.coastlines.bind()
shader = glh.ShaderProgram.bound_shader
wrapindex = np.uint32(
self.coastindices[int(shaderset.data.wraplon) + 180])
wrapindex = np.uint32(
self.coastindices[int( shaderset.data.wraplon ) + 180] )
if shaderset.data.wrapdir == 1:
shader.setAttributeValue(self.wraplon_loc, 360.0)
self.coastlines.draw(
first_vertex=0, vertex_count=wrapindex)
shader.setAttributeValue(self.wraplon_loc, 0.0)
self.coastlines.draw(
first_vertex=wrapindex, vertex_count=self.vcount_coast - wrapindex)
shader.setAttributeValue( self.wraplon_loc, 360.0 )
self.coastlines.draw(
first_vertex=0, vertex_count=wrapindex )
shader.setAttributeValue( self.wraplon_loc, 0.0 )
self.coastlines.draw(
first_vertex=wrapindex, vertex_count=self.vcount_coast - wrapindex )
else:
shader.setAttributeValue(self.wraplon_loc, -360.0)
self.coastlines.draw(
first_vertex=wrapindex, vertex_count=self.vcount_coast - wrapindex)
shader.setAttributeValue(self.wraplon_loc, 0.0)
self.coastlines.draw(
first_vertex=0, vertex_count=wrapindex)
shader.setAttributeValue( self.wraplon_loc, -360.0 )
self.coastlines.draw(
first_vertex=wrapindex, vertex_count=self.vcount_coast - wrapindex )
shader.setAttributeValue( self.wraplon_loc, 0.0 )
self.coastlines.draw(
first_vertex=0, vertex_count=wrapindex )
96 changes: 49 additions & 47 deletions bluesky/ui/qtgl/glpoly.py
Original file line number Diff line number Diff line change
@@ -1,54 +1,56 @@
''' BlueSky OpenGL line and polygon (areafilter) drawing. '''
import numpy as np
import bluesky as bs
from bluesky.ui import palette
from bluesky.ui.qtgl import console
from bluesky.ui.qtgl import glhelpers as glh
import bluesky as bs
import numpy as np


palette.set_default_colours(
polys=(0, 0, 255),
previewpoly=(0, 204, 255)
)
palette.set_default_colours(
polys=( 0, 0, 255 ),
previewpoly=( 0, 204, 255 )
)

# Static defines
POLYPREV_SIZE = 100
POLYPREV_SIZE = 10
POLY_SIZE = 2000
POLY_SIZE = 2000000


class Poly(glh.RenderObject, layer=-20):
class Poly( glh.RenderObject, layer=-20 ):
''' Poly OpenGL object. '''

def __init__(self, parent=None):
super().__init__(parent)
def __init__( self, parent=None ):
super().__init__( parent )
# Polygon preview object
self.polyprev = glh.VertexArrayObject(glh.gl.GL_LINE_LOOP)
self.polyprev = glh.VertexArrayObject( glh.gl.GL_LINE_LOOP )

# Fixed polygons
self.allpolys = glh.VertexArrayObject(glh.gl.GL_LINES)
self.allpfill = glh.VertexArrayObject(glh.gl.GL_TRIANGLES)
self.allpolys = glh.VertexArrayObject( glh.gl.GL_LINES )
self.allpfill = glh.VertexArrayObject( glh.gl.GL_TRIANGLES )

self.prevmousepos = (0, 0)
self.prevmousepos = ( 0, 0 )

bs.Signal('cmdline_stacked').connect(self.cmdline_stacked)
bs.Signal('radarmouse').connect(self.previewpoly)
bs.net.actnodedata_changed.connect(self.actdata_changed)
bs.Signal( 'cmdline_stacked' ).connect( self.cmdline_stacked )
bs.Signal( 'radarmouse' ).connect( self.previewpoly )
bs.net.actnodedata_changed.connect( self.actdata_changed )

def create(self):
self.polyprev.create(vertex=POLYPREV_SIZE * 8,
color=palette.previewpoly, usage=glh.gl.GL_DYNAMIC_DRAW)
self.allpolys.create(vertex=POLY_SIZE * 16, color=POLY_SIZE * 8)
self.allpfill.create(vertex=POLY_SIZE * 24,
color=np.append(palette.polys, 50))
def create( self ):
self.polyprev.create( vertex=POLYPREV_SIZE * 8,
color=palette.previewpoly, usage=glh.gl.GL_DYNAMIC_DRAW )
self.allpolys.create( vertex=POLY_SIZE * 16, color=POLY_SIZE * 8 )
self.allpfill.create( vertex=POLY_SIZE * 24,
color=np.append( palette.polys, 50 ) )

def draw(self):
def draw( self ):
actdata = bs.net.get_nodedata()
# Send the (possibly) updated global uniforms to the buffer
self.shaderset.set_vertex_scale_type(self.shaderset.VERTEX_IS_LATLON)
self.shaderset.set_vertex_scale_type( self.shaderset.VERTEX_IS_LATLON )

# --- DRAW THE MAP AND COASTLINES ---------------------------------------------
# Map and coastlines: don't wrap around in the shader
self.shaderset.enable_wrap(False)
self.shaderset.enable_wrap( False )

# --- DRAW PREVIEW SHAPE (WHEN AVAILABLE) -----------------------------
self.polyprev.draw()
Expand All @@ -58,68 +60,68 @@ def draw(self):
self.allpolys.draw()
if actdata.show_poly > 1:
self.allpfill.draw()
def cmdline_stacked(self, cmd, args):

def cmdline_stacked( self, cmd, args ):
if cmd in ['AREA', 'BOX', 'POLY', 'POLYGON', 'CIRCLE', 'LINE', 'POLYLINE']:
self.polyprev.set_vertex_count(0)
self.polyprev.set_vertex_count( 0 )

# def previewpoly(self, shape_type, data_in=None):
def previewpoly(self, mouseevent):
def previewpoly( self, mouseevent ):
if mouseevent.type() != mouseevent.MouseMove:
return
mousepos = (mouseevent.x(), mouseevent.y())
mousepos = ( mouseevent.x(), mouseevent.y() )
# Check if we are updating a preview poly
if mousepos != self.prevmousepos:
cmd = console.get_cmd()
nargs = len(console.get_args())
nargs = len( console.get_args() )
if cmd in ['AREA', 'BOX', 'POLY', 'POLYLINE',
'POLYALT', 'POLYGON', 'CIRCLE', 'LINE'] and nargs >= 2:
self.prevmousepos = mousepos
try:
# get the largest even number of points
start = 0 if cmd == 'AREA' else 3 if cmd == 'POLYALT' else 1
end = ((nargs - start) // 2) * 2 + start
data = [float(v) for v in console.get_args()[start:end]]
data += self.glsurface.pixelCoordsToLatLon(*mousepos)
end = ( ( nargs - start ) // 2 ) * 2 + start
data = [float( v ) for v in console.get_args()[start:end]]
data += self.glsurface.pixelCoordsToLatLon( *mousepos )
self.glsurface.makeCurrent()
if cmd is None:
self.polyprev.set_vertex_count(0)
self.polyprev.set_vertex_count( 0 )
return
if cmd in ['BOX', 'AREA']:
# For a box (an area is a box) we need to add two additional corners
polydata = np.zeros(8, dtype=np.float32)
polydata = np.zeros( 8, dtype=np.float32 )
polydata[0:2] = data[0:2]
polydata[2:4] = data[2], data[1]
polydata[4:6] = data[2:4]
polydata[6:8] = data[0], data[3]
else:
polydata = np.array(data, dtype=np.float32)
polydata = np.array( data, dtype=np.float32 )

if cmd[-4:] == 'LINE':
self.polyprev.set_primitive_type(glh.gl.GL_LINE_STRIP)
self.polyprev.set_primitive_type( glh.gl.GL_LINE_STRIP )
else:
self.polyprev.set_primitive_type(glh.gl.GL_LINE_LOOP)
self.polyprev.set_primitive_type( glh.gl.GL_LINE_LOOP )

self.polyprev.update(vertex=polydata)
self.polyprev.update( vertex=polydata )


except ValueError:
pass

def actdata_changed(self, nodeid, nodedata, changed_elems):
def actdata_changed( self, nodeid, nodedata, changed_elems ):
''' Update buffers when a different node is selected, or when
the data of the current node is updated. '''
# Shape data change
if 'SHAPE' in changed_elems:
if nodedata.polys:
self.glsurface.makeCurrent()
contours, fills, colors = zip(*nodedata.polys.values())
contours, fills, colors = zip( *nodedata.polys.values() )
# Create contour buffer with color
self.allpolys.update(vertex=np.concatenate(contours),
color=np.concatenate(colors))
self.allpolys.update( vertex=np.concatenate( contours ),
color=np.concatenate( colors ) )

# Create fill buffer
self.allpfill.update(vertex=np.concatenate(fills))
self.allpfill.update( vertex=np.concatenate( fills ) )
else:
self.allpolys.set_vertex_count(0)
self.allpfill.set_vertex_count(0)
self.allpolys.set_vertex_count( 0 )
self.allpfill.set_vertex_count( 0 )
Loading

0 comments on commit cb826dd

Please sign in to comment.