Commit 03a6f9f4 authored by Karol Actun's avatar Karol Actun
Browse files

marker renamed to location, grid's locations renamed to coordinates

parent c3a91e1f
......@@ -29,7 +29,7 @@ gui = default_gui
;# .obj (Wavefront) filenames in lib/visualization/models
;particle_model_file = 2d_particle.obj
;tile_model_file = 2d_quad_tile.obj
;marker_model_file = 2d_marker.obj
;location_model_file = 2d_location.obj
;grid_size = 1000
; end of Quadratic grid configs
......@@ -39,7 +39,7 @@ gui = default_gui
;# .obj (Wavefront) filenames in lib/visualization/models
;particle_model_file = 2d_particle.obj
;tile_model_file = 2d_hex_tile.obj
;marker_model_file = 2d_marker.obj
;location_model_file = 2d_location.obj
;grid_size = 100
; end of Triangular grid configs
......@@ -48,7 +48,7 @@ gui = default_gui
;grid_class = CubicGrid
;particle_model_file = 3d_particle_low_poly.obj
;tile_model_file = 3d_cube_tile.obj
;marker_model_file = 3d_marker.obj
;location_model_file = 3d_location.obj
;grid_size = 10
; end of cubic grid configs
......@@ -57,14 +57,14 @@ gui = default_gui
grid_class = CCPGrid
particle_model_file = 3d_particle.obj
tile_model_file = 3d_ccp_tile.obj
marker_model_file = 3d_marker.obj
location_model_file = 3d_location.obj
grid_size = 10
# end of ccp grid configs
# matter default colors (rgba)
particle_color = (0.8, 0.3, 0.3, 1.0)
tile_color = (0.3, 0.3, 0.8, 1.0)
marker_color = (0.3, 0.8, 0.3, 1.0)
location_color = (0.3, 0.8, 0.3, 1.0)
grid_color = (0.0, 0.0, 0.0, 1.0)
cursor_color = (0.5, 0.5, 0.5, 0.5)
center_color = (1.0, 0.0, 0.0, 0.5)
......@@ -77,12 +77,12 @@ line_color = (0.0, 0.0, 0.0, 1.0)
line_scaling = (1.0, 1.0, 1.0)
# flag for showing the lines
show_lines = True
# color of grid locations (rgba)
location_color = (0.0, 0.0, 0.0, 1.0)
# size/scaling of the location model. wouldn't make it bigger than 0.2, 0.2, 0.2
location_scaling = (0.05, 0.05, 0.05)
# flag for showing the location models
show_locations = True
# color of grid coordinates (rgba)
coordinates_color = (0.0, 0.0, 0.0, 1.0)
# size/scaling of the coordinate model. wouldn't make it bigger than 0.2, 0.2, 0.2
coordinates_scaling = (0.05, 0.05, 0.05)
# flag for showing the coordinate models
show_coordinates = True
# flag for showing the center of the grid
show_center = True
# camera focus color
......@@ -119,11 +119,11 @@ memory_limitation = False
## mm size in quantity
## Works only with memory_limitation flag set on 1
marker_mm_size = 2
location_mm_size = 2
particle_mm_size = 2
tile_mm_size = 2
[File]
scenario = rings_of _matter
scenario = lonely_particle
solution = random_walk_with_take_and_drop
......@@ -32,15 +32,15 @@ class CCPGrid(Grid):
for x in range(-int(width / 2), int(width / 2)):
for y in range(-int(width / 2), int(width / 2)):
for z in range(-int(width / 2), int(width / 2)):
if self.is_valid_location((x, y, z)):
if self.are_valid_coordinates((x, y, z)):
locations.append((x, y, z))
return locations
def is_valid_location(self, location):
x = location[0]
y = location[1]
z = location[2]
def are_valid_coordinates(self, coordinates):
x = coordinates[0]
y = coordinates[1]
z = coordinates[2]
if y % 2.0 == 0:
if x % 2.0 == z % 2.0 == 0 or x % 2.0 == z % 2.0 == 1:
return True
......@@ -49,7 +49,7 @@ class CCPGrid(Grid):
return True
return False
def get_nearest_location(self, coordinates):
def get_nearest_valid_coordinates(self, coordinates):
x = round(coordinates[0])
y = round(coordinates[1])
z = round(coordinates[2])
......
......@@ -28,13 +28,13 @@ class CubicGrid(Grid):
locations.append((x, y, z))
return locations
def is_valid_location(self, location):
if location[0] % 1 == 0 and location[1] % 1 == 0 and location[2] % 1 == 0:
def are_valid_coordinates(self, coordinates):
if coordinates[0] % 1 == 0 and coordinates[1] % 1 == 0 and coordinates[2] % 1 == 0:
return True
else:
return False
def get_nearest_location(self, coordinates):
def get_nearest_valid_coordinates(self, coordinates):
return (round(coordinates[0]),
round(coordinates[1]),
round(coordinates[2]))
......
......@@ -14,20 +14,20 @@ class Grid(ABC):
pass
@abstractmethod
def is_valid_location(self, location):
def are_valid_coordinates(self, coordinates):
"""
checks if given location is a valid location for matter in this grid
:param location: (float, float, float)
:return: true = location is valid, false = location invalid
checks if given coordinates are valid for this grid
:param coordinates: (float, float, float)
:return: true = coordinates are valid, false = coordinates invalid
"""
pass
@abstractmethod
def get_nearest_location(self, coordinates):
def get_nearest_valid_coordinates(self, coordinates):
"""
calculates the nearest location to given coordinates
calculates the nearest valid coordinates to given coordinates
:param coordinates: (float, float, float)
:return: valid location
:return: valid coordinates
"""
pass
......@@ -71,7 +71,7 @@ class Grid(ABC):
@abstractmethod
def get_box(self, width):
"""
calculates locations in a box
calculates all valid coordinates in a box
:return: list of 3d coordinates: [(x_start_l0, y_start_l0), (x_end_l0, y_end_l0), (x_start_l1, y_start_l1), ...)
"""
pass
......@@ -88,19 +88,19 @@ class Grid(ABC):
def get_distance(self, start, end):
"""
the metric or distance function for this grid
:param start: location, (float, float, float) tuple, start of path
:param end: location, (float, float, float) tuple, end of path
:param start: coordinates, (float, float, float) tuple, start of path
:param end: coordinates, (float, float, float) tuple, end of path
:return: integer, minimal amount of steps between start and end
"""
pass
@staticmethod
def get_location_in_direction(position, direction):
def get_coordinates_in_direction(position, direction):
"""
calculates a new position from current position and direction
:param position: location, (float, float, float) tuple, current position
:param direction: location, (float, float, float) tuple, direction
:return: location, (float, float, float) tuple, new position
:param position: coordinates, (float, float, float) tuple, current position
:param direction: coordinates, (float, float, float) tuple, direction
:return: coordinates, (float, float, float) tuple, new position
"""
new_pos = []
for i in range(len(position)):
......@@ -110,7 +110,7 @@ class Grid(ABC):
def get_center(self):
"""
returns the center of the grid. usually (0,0,0)
:return: location, (float, float, float) tuple
:return: coordinates, (float, float, float) tuple
"""
return 0.0, 0.0, 0.0
......@@ -121,75 +121,75 @@ class Grid(ABC):
"""
return 1.0, 1.0, 1.0
def get_adjacent_locations(self, location):
def get_adjacent_coordinates(self, coordinates):
"""
calculates a set of adjacent locations of the given location
:param location: the location of which the neighboring locations should be calculated
:return: a set of locations
calculates a set of adjacent coordinates of the given coordinates
:param coordinates: the coordinates of which the neighboring coordinates should be calculated
:return: a set of coordinates
"""
n = set()
for d in self.get_directions_list():
n.add(self.get_location_in_direction(location, d))
n.add(self.get_coordinates_in_direction(coordinates, d))
return n
def _get_adjacent_locations_not_in_set(self, location, not_in_set):
def _get_adjacent_coordinates_not_in_set(self, coordinates, not_in_set):
"""
the same as 'get_neighboring_locations', but doesn't return locations which are in the given 'not_in_set'.
:param location: the location of which the neighboring locations should be calculated
:param not_in_set: set of locations, which should not be included in the result
:return: a set of locations
the same as 'get_neighboring_coordinates', but doesn't return coordinates which are in the given 'not_in_set'.
:param coordinates: the coordinates of which the neighboring coordinates should be calculated
:param not_in_set: set of coordinates, which should not be included in the result
:return: a set of coordinates
"""
result = set()
for d in self.get_directions_list():
n = self.get_location_in_direction(location, d)
n = self.get_coordinates_in_direction(coordinates, d)
if n not in not_in_set:
result.add(n)
return result
def get_n_sphere(self, location, radius):
def get_n_sphere(self, coordinates, radius):
"""
calculates the n-sphere of this grid
:param location: center of the circle/sphere
:param coordinates: center of the circle/sphere
:param radius: radius of the circle/sphere
:return: set of locations
:return: set of coordinates
"""
result = set()
ns = self.get_adjacent_locations(location)
ns = self.get_adjacent_coordinates(coordinates)
current_ns = ns
result.update(ns)
for i in range(radius):
tmp = set()
for n in current_ns:
ns = self._get_adjacent_locations_not_in_set(n, result)
ns = self._get_adjacent_coordinates_not_in_set(n, result)
tmp.update(ns)
result.update(ns)
current_ns = tmp
return result
def get_n_sphere_border(self, location, radius):
def get_n_sphere_border(self, coordinates, radius):
"""
calculates the border of an n-sphere around the center with the given radius
:param location: center of the ring
:param coordinates: center of the ring
:param radius: radius of the ring
:return: set of locations
:return: set of coordinates
"""
if radius == 0:
r = set()
r.add(location)
r.add(coordinates)
return r
seen = set()
ns = self.get_adjacent_locations(location)
ns = self.get_adjacent_coordinates(coordinates)
current_ns = ns
seen.update(ns)
seen.add(location)
seen.add(coordinates)
for i in range(radius-1):
tmp = set()
for n in current_ns:
ns = self._get_adjacent_locations_not_in_set(n, seen)
ns = self._get_adjacent_coordinates_not_in_set(n, seen)
seen.update(ns)
tmp.update(ns)
current_ns = tmp
......
......@@ -25,13 +25,13 @@ class QuadraticGrid(Grid):
locations.append((x, y, 0.0))
return locations
def is_valid_location(self, location):
if location[0] % 1 == 0 and location[1] % 1 == 0:
def are_valid_coordinates(self, coordinates):
if coordinates[0] % 1 == 0 and coordinates[1] % 1 == 0:
return True
else:
return False
def get_nearest_location(self, coordinates):
def get_nearest_valid_coordinates(self, coordinates):
return (round(coordinates[0]),
round(coordinates[1]), 0.0)
......
......@@ -33,18 +33,18 @@ class TriangularGrid(Grid):
return locs
def is_valid_location(self, location):
if not location[2] == 0.0:
def are_valid_coordinates(self, coordinates):
if not coordinates[2] == 0.0:
return False
if location[1] % 2.0 == 0.0:
if location[0] % 1.0 == 0.0:
if coordinates[1] % 2.0 == 0.0:
if coordinates[0] % 1.0 == 0.0:
return True
else:
if location[0] % 1.0 == 0.5:
if coordinates[0] % 1.0 == 0.5:
return True
return False
def get_nearest_location(self, coordinates):
def get_nearest_valid_coordinates(self, coordinates):
nearest_y = round(coordinates[1])
if nearest_y % 2 == 0:
nearest_x = round(coordinates[0])
......
from PyQt5.QtGui import QColor, QIntValidator
from PyQt5.QtGui import QColor, QIntValidator, QFont
from PyQt5.QtWidgets import (QVBoxLayout, QPushButton, QColorDialog, QRadioButton, QLabel, QTabWidget,
QSlider, QHBoxLayout, QCheckBox, QTabBar, QTextEdit, QLineEdit, QStyle)
QSlider, QHBoxLayout, QCheckBox, QTabBar, QLineEdit, QComboBox)
from PyQt5.QtCore import Qt
from OpenGL.GL import glGetFloatv, GL_LINE_WIDTH_RANGE
from lib.vis3d import Visualization
from lib.visualization.utils import eprint
def create_slider(tick_interval: int, tick_position: int, max_position: int, min_position: int,
slider_position: int, callback, orientation=Qt.Horizontal):
"""
helper function for creating a slider
"""
slider = QSlider(orientation)
slider.setTickInterval(tick_interval)
slider.setTickPosition(tick_position)
slider.setMaximum(max_position)
slider.setMinimum(min_position)
slider.setSliderPosition(slider_position)
slider.valueChanged.connect(callback)
return slider
from lib.swarm_sim_header import eprint
from lib.vis3d import Visualization
def create_gui(world, vis: Visualization):
......@@ -30,6 +16,7 @@ def create_gui(world, vis: Visualization):
tabbar.addTab(vis_tab(vis), "Visualization")
tabbar.addTab(grid_tab(vis), "Grid")
tabbar.addTab(matter_tab(vis), "Matter")
tabbar.addTab(help_tab(), "Help")
return tabbar
......@@ -39,6 +26,51 @@ def key_handler(key, world, vis):
vis.start_stop()
def help_tab():
vcontrols = QLabel("view controls:")
lmd = QLabel("\tmouse dragging with left mouse button:\n\t\trotation (only in 3D)")
rmd = QLabel("\tmouse dragging with right mouse button:\n\t\tdragging the view")
mw = QLabel("\tscrolling:\n\t\tzooming")
ccontrols = QLabel("\ncursor controls:")
sc = QLabel("\tholding 'CTRL':\n\t\tshow cursor")
mcc = QLabel("\tleft mouse button click while holding 'CTRL':\n\t\tadding/removing matter at cursors position")
mwc = QLabel("\tscrolling while holding 'CTRL':\n\t\tmoving the cursor in the relative z-direction")
scontrols = QLabel("\nsimulation controls:")
sss = QLabel("\tspacebar:\n\t\tstart / stop the simulation")
vbox = QVBoxLayout()
vbox.addWidget(vcontrols)
vbox.addWidget(lmd)
vbox.addWidget(rmd)
vbox.addWidget(mw)
vbox.addWidget(ccontrols)
vbox.addWidget(sc)
vbox.addWidget(mcc)
vbox.addWidget(mwc)
vbox.addWidget(scontrols)
vbox.addWidget(sss)
vbox.addStretch(0)
tabbar = QTabBar()
tabbar.setLayout(vbox)
return tabbar
def create_slider(tick_interval: int, tick_position: int, max_position: int, min_position: int,
slider_position: int, callback, orientation=Qt.Horizontal):
"""
helper function for creating a slider
"""
slider = QSlider(orientation)
slider.setTickInterval(tick_interval)
slider.setTickPosition(tick_position)
slider.setMaximum(max_position)
slider.setMinimum(min_position)
slider.setSliderPosition(slider_position)
slider.valueChanged.connect(callback)
return slider
def sim_tab(vis, world):
tab = QTabBar()
layout = QVBoxLayout()
......@@ -109,7 +141,7 @@ def grid_tab(vis: Visualization):
layout = QVBoxLayout()
layout.addLayout(get_grid_width_slider(vis))
layout.addLayout(get_grid_lines_scale_slider(vis))
layout.addLayout(get_grid_locations_scale_slider(vis))
layout.addLayout(get_grid_coordinates_scale_slider(vis))
layout.addLayout(get_show_checkboxes(vis))
layout.addLayout(recalculate_grid(vis))
layout.addLayout(get_color_picker(vis))
......@@ -121,14 +153,34 @@ def grid_tab(vis: Visualization):
def matter_tab(vis):
tab = QTabBar()
layout = QVBoxLayout()
layout.addLayout(get_matter_combo(vis))
layout.addStretch(1)
layout.addLayout(get_particle_scaler(vis))
layout.addLayout(get_marker_scaler(vis))
layout.addStretch(1)
layout.addLayout(get_location_scaler(vis))
layout.addStretch(1)
layout.addLayout(get_tile_scaler(vis))
layout.addStretch(0)
layout.addStretch(1)
tab.setLayout(layout)
return tab
def get_matter_combo(vis):
combo = QComboBox()
combo.addItems(["particle", "tile", "location"])
combo.setCurrentIndex(1)
def on_change(value):
print(value)
combo.currentTextChanged.connect(on_change)
desc = QLabel("matter to create on cursor click:")
vbox = QVBoxLayout()
vbox.addWidget(desc, alignment=Qt.AlignBaseline)
vbox.addWidget(combo, alignment=Qt.AlignBaseline)
return vbox
def get_particle_scaler(vis):
def x_scaler_change(value):
current_scaling = vis.get_particle_scaling()
......@@ -221,23 +273,23 @@ def get_tile_scaler(vis):
return vbox
def get_marker_scaler(vis):
def get_location_scaler(vis):
def x_scaler_change(value):
current_scaling = vis.get_marker_scaling()
current_scaling = vis.get_location_scaling()
print(current_scaling)
new_scaling = (value/10.0, current_scaling[1], current_scaling[2])
print(new_scaling)
vis.set_marker_scaling(new_scaling)
vis.set_location_scaling(new_scaling)
def y_scaler_change(value):
current_scaling = vis.get_marker_scaling()
current_scaling = vis.get_location_scaling()
new_scaling = (current_scaling[0], value/10.0, current_scaling[2])
vis.set_marker_scaling(new_scaling)
vis.set_location_scaling(new_scaling)
def z_scaler_change(value):
current_scaling = vis.get_marker_scaling()
current_scaling = vis.get_location_scaling()
new_scaling = (current_scaling[0], current_scaling[1], value/10.0)
vis.set_marker_scaling(new_scaling)
vis.set_location_scaling(new_scaling)
x_desc = QLabel("x scale:")
y_desc = QLabel("y scale:")
......@@ -259,7 +311,7 @@ def get_marker_scaler(vis):
hbox3.addWidget(z_scaler, alignment=Qt.AlignBaseline)
vbox = QVBoxLayout()
vbox.addWidget(QLabel("marker scaling:"), alignment=Qt.AlignBaseline)
vbox.addWidget(QLabel("location scaling:"), alignment=Qt.AlignBaseline)
vbox.addLayout(hbox1)
vbox.addLayout(hbox2)
vbox.addLayout(hbox3)
......@@ -372,15 +424,15 @@ def get_color_picker(vis):
lines_button.clicked.connect(lines)
locs_button = QPushButton("grid locations")
locs_button = QPushButton("grid coordinates")
def locs():
qcd = QColorDialog()
qcd.setOption(QColorDialog.ShowAlphaChannel)
qcd.setCurrentColor(QColor.fromRgbF(*vis.get_grid_location_color()))
qcd.setCurrentColor(QColor.fromRgbF(*vis.get_grid_coordinates_color()))
qcd.exec()
if qcd.result() == 1:
vis.set_grid_location_color((qcd.selectedColor().getRgbF()))
vis.set_grid_coordinates_color((qcd.selectedColor().getRgbF()))
locs_button.clicked.connect(locs)
......@@ -432,14 +484,14 @@ def get_show_checkboxes(vis):
vis.set_show_lines(lines_cb.isChecked())
lines_cb.clicked.connect(lines_clicked)
locs_cb = QCheckBox()
locs_cb.setText("show locations")
locs_cb.setChecked(vis.get_show_locations())
coords_cb = QCheckBox()
coords_cb.setText("show coordinates")
coords_cb.setChecked(vis.get_show_coordinates())
def locs_clicked():
vis.set_show_locations(locs_cb.isChecked())
def coords_clicked():
vis.set_show_coordinates(coords_cb.isChecked())
locs_cb.clicked.connect(locs_clicked)
coords_cb.clicked.connect(coords_clicked)
center_cb = QCheckBox()
center_cb.setText("show center")
......@@ -470,7 +522,7 @@ def get_show_checkboxes(vis):
hbox1 = QHBoxLayout()
hbox1.addWidget(lines_cb)
hbox1.addWidget(locs_cb)
hbox1.addWidget(coords_cb)
hbox2 = QHBoxLayout()
hbox2.addWidget(center_cb)
hbox2.addWidget(focus_cb)
......@@ -498,16 +550,16 @@ def get_grid_lines_scale_slider(vis):
return vbox
def get_grid_locations_scale_slider(vis):
def get_grid_coordinates_scale_slider(vis):
vbox = QVBoxLayout()
desc = QLabel("grid locations model scale (%d%%):" % int(vis.get_grid_location_scaling()[0]*500))
desc = QLabel("grid coordinates model scale (%d%%):" % int(vis.get_grid_coordinates_scaling()[0]*500))
vbox.addWidget(desc, alignment=Qt.AlignBaseline)
def set_scale(value):
vis.set_grid_location_scaling([value/1000.0, value/1000.0, value/1000.0])
desc.setText("grid locations model scale (%d%%):" % (int(value/2.0)))
vis.set_grid_coordinates_scaling([value/1000.0, value/1000.0, value/1000.0])
desc.setText("grid coordinates model scale (%d%%):" % (int(value/2.0)))
vbox.addWidget(create_slider(10, 2, 200, 10, int(vis.get_grid_location_scaling()[0]*1000.0), set_scale),
vbox.addWidget(create_slider(10, 2, 200, 10, int(vis.get_grid_coordinates_scaling()[0]*1000.0), set_scale),
alignment=Qt.AlignBaseline)
return vbox
......
from PyQt5.QtCore import Qt
from PyQt5.QtWidgets import QVBoxLayout, QLabel, QSlider
from lib.vis3d import Visualization
from lib.world import World
......
......@@ -37,11 +37,11 @@ class ConfigData:
self.particle_model_file = config.get("Visualization", "particle_model_file")
self.tile_model_file = config.get("Visualization", "tile_model_file")
self.marker_model_file = config.get("Visualization", "marker_model_file")
self.location_model_file = config.get("Visualization", "location_model_file")
self.particle_color = make_tuple(config.get("Visualization", "particle_color"))
self.tile_color = make_tuple(config.get("Visualization", "tile_color"))
self.marker_color = make_tuple(config.get("Visualization", "marker_color"))
self.location_color = make_tuple(config.get("Visualization", "location_color"))
self.grid_color = make_tuple(config.get("Visualization", "grid_color"))
self.cursor_color = make_tuple(config.get("Visualization", "cursor_color"))
self.background_color = make_tuple(config.get("Visualization", "background_color"))
......@@ -49,9 +49,9 @@ class ConfigData:
self.line_color = make_tuple(config.get("Visualization", "line_color"))
self.line_scaling = make_tuple(config.get("Visualization", "line_scaling"))
self.show_lines = config.getboolean("Visualization", "show_lines")
self.location_color = make_tuple(config.get("Visualization", "location_color"))
self.location_scaling = make_tuple(config.get("Visualization", "location_scaling"))
self.show_locations = config.getboolean("Visualization", "show_locations")
self.coordinates_color = make_tuple(config.get("Visualization", "coordinates_color"))
self.coordinates_scaling = make_tuple(config.get("Visualization", "coordinates_scaling"))
self.show_coordinates = config.getboolean("Visualization", "show_coordinates")
self.show_center = config.getboolean("Visualization", "show_center")
self.focus_color = make_tuple(config.get("Visualization", "focus_color"))