Skip to content
Snippets Groups Projects

Resolve "(LearnerND) add iso-surface plot feature"

Merged Jorn Hoofwijk requested to merge 112-learnernd-add-iso-surface-plot-feature into master
All threads resolved!
Compare and Show latest version
1 file
+ 9
9
Compare changes
  • Side-by-side
  • Inline
@@ -605,8 +605,8 @@ class LearnerND(BaseLearner):
return from_line_to_vertex[(a, b)]
# Otherwise compute it and cache the result.
vertex_a = np.array(self.tri.vertices[a])
vertex_b = np.array(self.tri.vertices[b])
vertex_a = self.tri.vertices[a]
vertex_b = self.tri.vertices[b]
value_a = self.data[vertex_a]
value_b = self.data[vertex_b]
@@ -614,7 +614,7 @@ class LearnerND(BaseLearner):
db = abs(value_b - level)
dab = da + db
new_pt = db / dab * vertex_a + da / dab * vertex_b
new_pt = db / dab * np.array(vertex_a) + da / dab * np.array(vertex_b)
new_index = len(vertices)
vertices.append(new_pt)
@@ -623,10 +623,10 @@ class LearnerND(BaseLearner):
for simplex in self.tri.simplices:
plane = []
for a,b in itertools.combinations(simplex, 2):
for a, b in itertools.combinations(simplex, 2):
va = self.data[self.tri.vertices[a]]
vb = self.data[self.tri.vertices[b]]
if min(va,vb) < level <= max(va,vb):
if min(va, vb) < level <= max(va, vb):
vi = _get_vertex_index(a, b)
should_add = True
for pi in plane:
@@ -653,7 +653,7 @@ class LearnerND(BaseLearner):
return vertices, faces
def plot_isosurface(self, level=0.0, hull_opacity=0.2):
"""Plots the linearly interpolated iso-surface of the function, based on
"""Plots the linearly interpolated iso-surface of the function, based on
the currently evaluated points. This is the 3d analog of an iso-line.
Parameters
@@ -685,8 +685,9 @@ class LearnerND(BaseLearner):
# Find the colors of each plane, giving triangles which are coplanar the
# same color, such that a square face has the same color.
color_dict = {}
def _get_plane_color(simplex):
simplex= tuple(simplex)
simplex = tuple(simplex)
# If the volume of the two triangles combined is zero then they
# belong to the same plane.
for simplex_key, color in color_dict.items():
@@ -695,7 +696,7 @@ class LearnerND(BaseLearner):
return color
if scipy.spatial.ConvexHull(points).volume < 1e-5:
return color
color_dict[simplex] = tuple(random.randint(0,255) for _ in range(3))
color_dict[simplex] = tuple(random.randint(0, 255) for _ in range(3))
return color_dict[simplex]
colors = [_get_plane_color(simplex) for simplex in hull.simplices]
@@ -704,4 +705,3 @@ class LearnerND(BaseLearner):
i, j, k = hull.simplices.T
return plotly.graph_objs.Mesh3d(x=x, y=y, z=z, i=i, j=j, k=k,
facecolor=(colors), opacity=opacity)
\ No newline at end of file
Loading