Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove the use of triplot #514

Merged
merged 1 commit into from
Nov 24, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 10 additions & 6 deletions menpo/shape/mesh/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,15 @@
from .normals import compute_normals


def trilist_to_adjacency_array(trilist):
wrap_around_adj = np.hstack([trilist[:, -1][..., None],
trilist[:, 0][..., None]])
# Build the array of all pairs
return np.concatenate([trilist[:, :2],
trilist[:, 1:],
wrap_around_adj])


class TriMesh(PointCloud):
r"""
A pointcloud with a connectivity defined by a triangle list. These are
Expand Down Expand Up @@ -125,12 +134,7 @@ def as_pointgraph(self, copy=True):
from .. import PointUndirectedGraph
# Since we have triangles we need the last connection
# that 'completes' the triangle
wrap_around_adj = np.hstack([self.trilist[:, -1][..., None],
self.trilist[:, 0][..., None]])
# Build the array of all pairs
adjacency_array = np.concatenate([self.trilist[:, :2],
self.trilist[:, 1:],
wrap_around_adj])
adjacency_array = trilist_to_adjacency_array(self.trilist)
pg = PointUndirectedGraph(self.points, adjacency_array, copy=copy)
# This is always a copy
pg.landmarks = self.landmarks
Expand Down
4 changes: 2 additions & 2 deletions menpo/visualize/__init__.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from .base import (
Viewable, Menpo3dErrorMessage,
PointCloudViewer, PointCloudViewer2d, PointGraphViewer, TriMeshViewer,
TriMeshViewer2d, LandmarkViewer, LandmarkViewer2d, ImageViewer2d,
LandmarkViewer, LandmarkViewer2d, ImageViewer2d,
AlignmentViewer2d)
from .text_utils import progress_bar_str, print_dynamic, print_bytes
from .text_utils import progress_bar_str, print_dynamic
from .widgets import visualize_images, visualize_shapes
9 changes: 4 additions & 5 deletions menpo/visualize/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -161,15 +161,13 @@ def view(self, **kwargs):
from menpo.visualize.viewmatplotlib import (
MatplotlibImageViewer2d, MatplotlibImageSubplotsViewer2d,
MatplotlibPointCloudViewer2d, MatplotlibLandmarkViewer2d,
MatplotlibTriMeshViewer2d,
MatplotlibAlignmentViewer2d, MatplotlibGraphPlotter,
MatplotlibMultiImageViewer2d, MatplotlibMultiImageSubplotsViewer2d,
MatplotlibPointGraphViewer2d)

# Default importer types
PointGraphViewer2d = MatplotlibPointGraphViewer2d
PointCloudViewer2d = MatplotlibPointCloudViewer2d
TriMeshViewer2d = MatplotlibTriMeshViewer2d
LandmarkViewer2d = MatplotlibLandmarkViewer2d
ImageViewer2d = MatplotlibImageViewer2d
ImageSubplotsViewer2d = MatplotlibImageSubplotsViewer2d
Expand Down Expand Up @@ -526,9 +524,10 @@ def render(self, **kwargs):
Only 2D and 3D viewers are supported.
"""
if self.points.shape[1] == 2:
return TriMeshViewer2d(self.figure_id, self.new_figure,
self.points, self.trilist).render(**kwargs)

from menpo.shape.mesh.base import trilist_to_adjacency_array
return PointGraphViewer2d(
self.figure_id, self.new_figure, self.points,
trilist_to_adjacency_array(self.trilist)).render(**kwargs)
elif self.points.shape[1] == 3:
try:
from menpo3d.visualize import TriMeshViewer3d
Expand Down
17 changes: 0 additions & 17 deletions menpo/visualize/viewmatplotlib.py
Original file line number Diff line number Diff line change
Expand Up @@ -190,23 +190,6 @@ def _render(self, image_view=False, cmap=None,
return self


class MatplotlibTriMeshViewer2d(MatplotlibRenderer):
def __init__(self, figure_id, new_figure, points, trilist):
super(MatplotlibTriMeshViewer2d, self).__init__(figure_id, new_figure)
self.points = points
self.trilist = trilist

def _render(self, image_view=False, label=None, colour_array='b',
**kwargs):
import matplotlib.pyplot as plt
# Flip x and y for viewing if points are tied to an image
points = self.points[:, ::-1] if image_view else self.points
plt.triplot(points[:, 0], points[:, 1], self.trilist,
label=label, color=colour_array, marker='.')

return self


class MatplotlibLandmarkViewer2d(MatplotlibRenderer):
def __init__(self, figure_id, new_figure, group, pointcloud,
labels_to_masks):
Expand Down