Skip to content

Commit 8c79e4f

Browse files
committed
removed dependency on matplotlib's griddata
Probably works, but need more extensive testing
1 parent 8631928 commit 8c79e4f

File tree

4 files changed

+67
-45
lines changed

4 files changed

+67
-45
lines changed

openstereo/data_models.py

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -705,16 +705,17 @@ def plot_Eigenvectors(self):
705705
return plot_data
706706

707707
def plot_Contours(self):
708-
grid = self.auttitude_data.grid
709-
grid.change_spacing(self.contour_calc_settings["spacing"])
710-
nodes = self.auttitude_data.grid_nodes
708+
# grid = self.auttitude_data.grid
709+
# grid.change_spacing(self.contour_calc_settings["spacing"])
710+
grid = au.stats.SphericalGrid(self.contour_calc_settings["spacing"])
711+
nodes = grid.grid
711712
if self.contour_check_settings["fisher"]:
712713
if self.contour_check_settings["autocount"]:
713714
if self.contour_check_settings["robinjowett"]:
714715
k = None
715716
else:
716717
try:
717-
k = grid.optimize_k(self.auttitude_data.data)
718+
k = grid.optimize_k(self.au_object)
718719
except ImportError:
719720
QtWidgets.QMessageBox.warning(
720721
self.parent(),
@@ -724,7 +725,7 @@ def plot_Contours(self):
724725
k = None
725726
else:
726727
k = self.contour_calc_settings["K"]
727-
count = self.auttitude_data.grid_fisher(k)
728+
count = self.au_object.count_fisher(k, grid=grid)
728729
else:
729730
if self.contour_check_settings["autocount"]:
730731
if self.contour_check_settings["robinjowett"]:
@@ -735,7 +736,7 @@ def plot_Contours(self):
735736
acos(
736737
1.0
737738
- 1.0
738-
/ grid.optimize_k(self.auttitude_data.data)
739+
/ grid.optimize_k(self.au_object)
739740
)
740741
)
741742
except ImportError:
@@ -753,7 +754,7 @@ def plot_Contours(self):
753754
0.141536 * self.contour_calc_settings["scperc"]
754755
)
755756
)
756-
count = self.auttitude_data.grid_kamb(theta)
757+
count = self.au_object.count_kamb(theta, grid=grid)
757758
return (
758759
ContourPlotData(
759760
nodes,

openstereo/os_auttitude.py

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -119,16 +119,16 @@ def regular_grid(node_spacing):
119119
Builds a regular grid over the hemisphere, with the given average node spacing."""
120120
nodes = [(0.0, 90.0)]
121121
spacing = math.radians(node_spacing)
122-
for phi in np.linspace(
123-
node_spacing, 90.0, 90.0 / node_spacing, endpoint=False
122+
for phi in np.arange(
123+
node_spacing, 90.0, node_spacing
124124
):
125125
azimuth_spacing = math.degrees(
126126
2
127127
* math.asin((math.sin(spacing / 2) / math.sin(math.radians(phi))))
128128
)
129-
for theta in np.linspace(0.0, 360.0, 360.0 / azimuth_spacing):
129+
for theta in np.arange(0.0, 360.0, azimuth_spacing):
130130
nodes.append((theta + phi + node_spacing / 2, 90.0 - phi))
131-
for theta in np.linspace(0.0, 360.0, 360.0 / azimuth_spacing):
131+
for theta in np.arange(0.0, 360.0, azimuth_spacing):
132132
nodes.append(((theta + 90.0 + node_spacing / 2) % 360.0, 0.0))
133133
return np.array(nodes)
134134

@@ -138,17 +138,17 @@ def sphere_regular_grid(node_spacing):
138138
Builds a regular grid over the sphere, with the given average node spacing."""
139139
nodes = [(0.0, 90.0), (0, -90.0)]
140140
spacing = math.radians(node_spacing)
141-
for phi in np.linspace(
142-
node_spacing, 90.0, 90.0 / node_spacing, endpoint=False
141+
for phi in np.arange(
142+
node_spacing, 90.0, node_spacing
143143
):
144144
azimuth_spacing = math.degrees(
145145
2
146146
* math.asin((math.sin(spacing / 2) / math.sin(math.radians(phi))))
147147
)
148-
for theta in np.linspace(0.0, 360.0, 360.0 / azimuth_spacing):
148+
for theta in np.arange(0.0, 360.0, azimuth_spacing):
149149
nodes.append((theta + phi + node_spacing / 2, 90.0 - phi))
150150
nodes.append((theta + phi + node_spacing / 2, phi - 90.0))
151-
for theta in np.linspace(0.0, 360.0, 360.0 / azimuth_spacing):
151+
for theta in np.arange(0.0, 360.0, azimuth_spacing):
152152
nodes.append(((theta + 90.0 + node_spacing / 2) % 360.0, 0.0))
153153
return np.array(nodes)
154154

@@ -630,13 +630,13 @@ def grid_rose(
630630
)
631631
if not self.kwargs.get("line"):
632632
circular_data = -circular_data
633-
if type(self.grid) == CircularGrid:
634-
grid = self.grid
633+
# if type(self.grid) == CircularGrid:
634+
# grid = self.grid
635+
# else:
636+
if self._cgrid is None:
637+
grid = self._cgrid = CircularGrid()
635638
else:
636-
if self._cgrid is None:
637-
grid = self._cgrid = CircularGrid()
638-
else:
639-
grid = self._cgrid
639+
grid = self._cgrid
640640
# count(self, data, aperture=None,\
641641
# axial=False, spacing=None, offset=0, nodes=None)
642642
if direction:
@@ -1151,7 +1151,7 @@ def count_munro(
11511151
1.0
11521152
+ 2.0
11531153
* np.power(
1154-
weight, np.linspace(0.0, aperture, radians(spacing))
1154+
weight, np.arange(0.0, aperture, radians(spacing))
11551155
).sum()
11561156
)
11571157
return (

openstereo/os_plot.py

Lines changed: 43 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
from math import pi, sin, cos, acos, atan2, degrees, radians, sqrt
33
import re
44

5-
from PyQt5 import QtWidgets
5+
from PyQt5 import QtWidgets, QtCore
66
from matplotlib.pyplot import colorbar, imread, get_cmap
77
from matplotlib.figure import Figure
88
from matplotlib.backends.backend_qt5agg import (
@@ -16,7 +16,7 @@
1616
PolyCollection,
1717
LineCollection,
1818
)
19-
from matplotlib.mlab import griddata
19+
# from matplotlib.mlab import griddata
2020
import matplotlib.patheffects as PathEffects
2121
from matplotlib.font_manager import FontProperties
2222
from mpl_toolkits.axes_grid.axislines import Subplot
@@ -148,6 +148,7 @@ def __init__(self, settings, projection, parent=None):
148148
self.circle_elements = []
149149
self.drag_rotate_mode = False
150150
self.current_rotation = np.eye(3)
151+
self.scroll_rotation = 0.0
151152
self.last_rotation = np.eye(3)
152153
self.last_rotation_I = np.eye(3)
153154

@@ -162,6 +163,9 @@ def connect_measure(self):
162163
self.cidmotion = self.plotFigure.canvas.mpl_connect(
163164
"motion_notify_event", self.measure_motion
164165
)
166+
self.cidmotion = self.plotFigure.canvas.mpl_connect(
167+
"scroll_event", self.measure_motion
168+
)
165169
# http://stackoverflow.com/a/18145817/1457481
166170

167171
def measure_press(self, event):
@@ -208,6 +212,7 @@ def measure_release(self, event):
208212
self.last_rotation = self.current_rotation
209213
self.last_rotation_I = np.linalg.inv(self.current_rotation)
210214
self.current_rotation = np.eye(3)
215+
self.scroll_rotation = 0.0
211216
self.plot_canvas.draw()
212217

213218
# thanks forever to http://stackoverflow.com/a/8956211/1457481 for basics on blit
@@ -272,9 +277,25 @@ def measure_motion(self, event):
272277
c_sphere = sphere(*c)
273278

274279
if self.drag_rotate_mode:
280+
if event.name == "scroll_event":
281+
# https://stackoverflow.com/q/49316067/1457481
282+
self.scroll_rotation += (
283+
5 * event.step
284+
if QtWidgets.QApplication.keyboardModifiers()
285+
== QtCore.Qt.ControlModifier
286+
else event.step
287+
)
275288
rotation_matrix = self.last_rotation.dot(
276289
au_c.get_rotation_matrix(-theta)
277-
)
290+
) if self.button_pressed == 1 else self.last_rotation
291+
if self.button_pressed == 1:
292+
rotation_matrix = rotation_matrix.dot(
293+
b.get_rotation_matrix(radians(self.scroll_rotation))
294+
)
295+
else:
296+
rotation_matrix = rotation_matrix.dot(
297+
a.get_rotation_matrix(radians(self.scroll_rotation))
298+
)
278299
self.current_rotation = rotation_matrix
279300
for point, element in self.point_elements:
280301
Xp, Yp = self.project(*(point.dot(rotation_matrix)).T)
@@ -522,8 +543,7 @@ def plot_arrow(self, planes, lines, arrow_settings, has_sense, sliplinear):
522543
if plane[-1] > 0:
523544
plane = -plane
524545
arrow_from = (
525-
cos(arrowsize / 2.0) * plane
526-
+ sin(arrowsize / 2.0) * line
546+
cos(arrowsize / 2.0) * plane + sin(arrowsize / 2.0) * line
527547
)
528548
arrow_to = (
529549
cos(-arrowsize / 2.0) * plane
@@ -536,8 +556,8 @@ def plot_arrow(self, planes, lines, arrow_settings, has_sense, sliplinear):
536556
invert_positive=False
537557
)
538558
else:
539-
line_direction = line[:2]/np.linalg.norm(line[:2])
540-
dx, dy = line_direction * arrow_settings["arrowsize"]*0.0075
559+
line_direction = line[:2] / np.linalg.norm(line[:2])
560+
dx, dy = line_direction * arrow_settings["arrowsize"] * 0.0075
541561
x, y = self.project(*line, invert_positive=True)
542562
X, Y = [x - dx, x + dx], [y - dy, y + dy]
543563
if not sense:
@@ -654,15 +674,16 @@ def plot_contours(
654674
b"[^-\\d\\.]+", contour_settings["intervals"]
655675
)
656676
]
657-
xi = yi = np.linspace(-1.1, 1.1, contour_settings["cresolution"])
658-
X, Y = self.project(*nodes.T, ztol=0.1)
677+
# xi = yi = np.linspace(-1.1, 1.1, contour_settings["cresolution"])
678+
# X, Y = self.project(*nodes.T, ztol=0.1)
679+
X, Y = self.project(*nodes.T, invert_positive=False)
659680

660-
zi = griddata(X, Y, count, xi, yi, interp="linear")
681+
# zi = griddata(X, Y, count, xi, yi, interp="linear")
661682
if contour_check_settings["fillcontours"]:
662-
contour_plot = axes.contourf(
663-
xi,
664-
yi,
665-
zi,
683+
contour_plot = axes.tricontourf(
684+
X,
685+
Y,
686+
count,
666687
intervals,
667688
cmap=contour_settings["cmap"],
668689
linestyles=contour_settings["linestyles"],
@@ -684,20 +705,20 @@ def plot_contours(
684705
or not contour_check_settings["fillcontours"]
685706
):
686707
if contour_check_settings["solidline"]:
687-
contour_lines_plot = axes.contour(
688-
xi,
689-
yi,
690-
zi,
708+
contour_lines_plot = axes.tricontour(
709+
X,
710+
Y,
711+
count,
691712
intervals,
692713
colors=contour_line_settings["colors"],
693714
linestyles=contour_settings["linestyles"],
694715
linewidths=contour_line_settings["linewidths"],
695716
)
696717
else:
697-
contour_lines_plot = axes.contour(
698-
xi,
699-
yi,
700-
zi,
718+
contour_lines_plot = axes.tricontour(
719+
X,
720+
Y,
721+
count,
701722
intervals,
702723
cmap=contour_line_settings["cmap"],
703724
linestyles=contour_settings["linestyles"],

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ def run(self):
7878
"PyShp",
7979
"networkx",
8080
"ply2atti",
81-
"auttitude",
81+
"auttitude==0.1.3",
8282
"chardet",
8383
],
8484
cmdclass={

0 commit comments

Comments
 (0)