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

K3D support #78

Open
wants to merge 63 commits into
base: master
Choose a base branch
from
Open
Changes from 1 commit
Commits
Show all changes
63 commits
Select commit Hold shift + click to select a range
3b92ab8
Comment fileno as it doesnt work with jupiter
apapaion Jul 13, 2018
6d34645
Adda control if fileno is used. It causes error with Juputer Unsuppor…
apapaion Feb 6, 2019
1505e03
The accepted version of menpo include 0.9
May 23, 2019
03bc209
Syncronize with menpo/menpo3D. Add moderngl
apapaion Nov 14, 2019
2d99764
Add scikit-sparse dependency at setup. Needed for faster registration
apapaion Nov 15, 2019
32aff71
Merge remote-tracking branch 'upstream/master'
apapaion Jan 17, 2020
dbb8445
Add itkwidgets option(inline) for view for TriMesh and PointCloud
Sep 8, 2020
f0dec19
Add K3d widgets for PointCloud, TriMesh and TexturedTriMesh
Sep 10, 2020
628c16f
Add k3d dependency
Sep 11, 2020
d318f16
Add examples folders with the first example for the K3dWidgets
Sep 11, 2020
2bd57fc
Add Landmark Inline Viewer
Sep 11, 2020
badf6d6
- Add K3d inline viewer in LandmarkerViewer LabelledPointUndirectedGr…
Sep 14, 2020
ac17cd0
Add view method for 3D Shape Model
Sep 16, 2020
1dd9f0c
Update Introduction notebook, move outside of build package
Sep 16, 2020
ec200df
Update Introduction K3d. New paths for loading data
Sep 16, 2020
98a371f
Update Introduction K3d. New paths for loading data
Sep 16, 2020
d3767c2
Add a reduced 3DMM in data folder
Sep 16, 2020
9237de4
Remove menpowidgets dependency. However, it is needed to install menp…
Oct 5, 2020
7a399df
Add dict_figures, list_figures, clear_figures in k3dwidgets
Oct 5, 2020
a82de41
Debugging of some code in viewk3dwidgets;
Oct 5, 2020
57ad92b
Debugging in viewk3dwidgets
Oct 5, 2020
8a5d73e
Remove dependency on mayavi. If someone wants to use it, she should i…
Oct 6, 2020
19d651d
Add heatmap method as a k3dwidget. Move definition of heatmap using m…
Oct 7, 2020
2f5fc44
Add list_figures, dict_figures, clear_figure in __init__, so they can…
Oct 8, 2020
f987088
Update 0_Introduction_to_K3d_Widgets notebook with heatmap example an…
Oct 8, 2020
d7e6d2d
Initialize spirals module. Add adj_trigs method
Oct 8, 2020
b411095
Remove viewitkwidgets
Oct 8, 2020
a6633db
Add VectorInlineViewer3d. Move the widget check to the abstract classs
Oct 9, 2020
73186f5
Add K3dGraphViewer and K3dNormalViewer class. Add numbering at landm…
Oct 11, 2020
5d07cc9
Add graph viewer, normals viewer and numbering examples
Oct 11, 2020
be91bc6
Checking and creation of widg_to_draw is happening in K3dRenderer for…
Oct 12, 2020
26437dc
One more check was added in order to plot in the same figure. All poi…
Oct 12, 2020
6fa44bc
Add ColouredTriMeshInlineViewer3d. TextureTriMesh can be rendered now…
Oct 12, 2020
cb67ce8
Add one more check for plotting an inline figure. If new_figure is Fa…
Oct 13, 2020
fbaa42e
Update Introduction with more examples for failure
Oct 13, 2020
8498462
decimate_mesh function added in vtkutils.py
Oct 13, 2020
5e7fe2f
Add landmark support in K3dwidgetsColouredTriMeshViewer3d. List of se…
Oct 16, 2020
55e1c14
Update 0_Introduction_to_K3d_Widgets
Nov 18, 2020
484cab4
Menpo requirement is now greater or equal to 0.9.0 in setup.py
Nov 18, 2020
25ed92e
Update README.md
Nov 20, 2020
8a6903f
Update 0_Introduction_to_K3d_Widgets.ipynb
Nov 20, 2020
d4da90d
Camera_auto_fit is false and the new camera posiition is defined by t…
Nov 25, 2020
53667bb
mesh_type argument in view method for trimesh is enabled in K3dwidget…
Nov 26, 2020
7beda9a
Add K3dwidgetIdentity class
Nov 27, 2020
f19938b
Update example 0_Introduction_to_K3d_Widgets
Dec 1, 2020
959b58c
K3dwidgetsPCAModelViewer3d supports PointClouds as well. Address issu…
Dec 16, 2020
29a7ae1
Remove commented deprecated commands
Dec 16, 2020
146710f
Add MayaviHeatmapViewer3d in import list in base.py
Jan 17, 2021
414b0e0
Fix error in import Heatmap3d in visualize/__init__.py
Jan 17, 2021
612af7c
Fix mayavi plotting for landmarks.
Jan 20, 2021
47875fd
Changes in instal_requires in setup.py. Added more packages for windows
Jan 20, 2021
2ca4ddf
Changes in viewk3dwidgets: rgbint and K3dwidgetsPointGraphViewer3d
Jan 28, 2021
050d38e
Merge with original menpo3d
Jan 29, 2021
46115ac
Remove dependency on menpowidgets package
Jan 29, 2021
d514b87
Merge from original menpo3d.
Feb 1, 2021
050adbb
Add PointCloud with colours example in 0_Introduction_to_K3d_Widgets
Feb 3, 2021
f097cbe
Add function generate_transform_matrices in spirals/base.py
Feb 15, 2021
bd64573
Fix default value for colours argument in K3dwidgetsPointGraphViewer3d
Feb 25, 2021
6c4bd75
Various changes to fix code in viewk3dwidgets
Feb 25, 2021
9ad80a5
Removing and tidying parameters for view_3d inline methods
Feb 26, 2021
7129245
Remove of 3DMM
Feb 26, 2021
f6f59f2
Merge branch 'master' of ssh://gitlab-uk.rnd.huawei.com:2222/london_c…
Feb 26, 2021
09aaeb3
Merge remote-tracking branch 'originmenpo/master' into master
apapaion Mar 20, 2021
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
Prev Previous commit
Next Next commit
Add view method for 3D Shape Model
- Use K3D and LinearModelParametersWidget from menpowidget
- Support of landmarks in shape model
Thanos committed Sep 16, 2020
commit ac17cd0c526c2f23d77ceda652bbda0579270dd4
2 changes: 1 addition & 1 deletion menpo3d/visualize/__init__.py
Original file line number Diff line number Diff line change
@@ -2,4 +2,4 @@
ColouredTriMeshViewer3d, TexturedTriMeshViewer3d,
LandmarkViewer3d, TriMeshInlineViewer3d,
PointGraphInlineViewer3d, TexturedTriMeshInlineViewer3d,
LandmarkInlineViewer3d)
LandmarkInlineViewer3d, PCAModelInlineViewer3d)
4 changes: 3 additions & 1 deletion menpo3d/visualize/base.py
Original file line number Diff line number Diff line change
@@ -9,7 +9,8 @@
from .viewk3dwidgets import (K3dwidgetsTriMeshViewer3d,
K3dwidgetsPointGraphViewer3d,
K3dwidgetsLandmarkViewer3d,
K3dwidgetsTexturedTriMeshViewer3d)
K3dwidgetsTexturedTriMeshViewer3d,
K3dwidgetsPCAModelViewer3d)

PointGraphViewer3d = MayaviPointGraphViewer3d
TriMeshViewer3d = MayaviTriMeshViewer3d
@@ -22,3 +23,4 @@
TexturedTriMeshInlineViewer3d = K3dwidgetsTexturedTriMeshViewer3d
LandmarkInlineViewer3d = K3dwidgetsLandmarkViewer3d
PointGraphInlineViewer3d = K3dwidgetsPointGraphViewer3d
PCAModelInlineViewer3d = K3dwidgetsPCAModelViewer3d
127 changes: 98 additions & 29 deletions menpo3d/visualize/viewk3dwidgets.py
Original file line number Diff line number Diff line change
@@ -4,6 +4,8 @@
# from ..vtkutils import trimesh_to_vtk
from k3d import Plot, mesh as k3d_mesh, points as k3d_points
from io import BytesIO
from ipywidgets import GridBox, Layout
from menpowidgets.options import LinearModelParametersWidget
# The colour map used for all lines and markers
GLOBAL_CMAP = 'jet'

@@ -59,6 +61,36 @@ def _check_colours_list(render_flag, colours_list, n_objects, error_str):
return colours_list


def _check_figure_id(obj, figure_id, new_figure):
if figure_id is None:
if new_figure:
# A new figure is created but with no figure_id
# we should create an id of 'Figure_n form'
list_ids = []
for x in obj.widgets.values():
if hasattr(x, 'figure_id') and x is not obj:
if x.figure_id is not None and 'Figure_' in str(x.figure_id):
try:
n_figure_id = int(x.figure_id.split('Figure_')[1])
except ValueError:
continue
list_ids.append(n_figure_id)
if len(list_ids):
figure_id = 'Figure_{}'.format(sorted(list_ids)[-1] + 1)
else:
figure_id = 'Figure_0'

else:
obj.remove_widget()
raise ValueError('You cannot plot a figure with no id and new figure False')
else:
if new_figure:
for x in obj.widgets.values():
if hasattr(x, 'figure_id') and x is not obj:
if x.figure_id == figure_id:
obj.remove_widget()
raise ValueError('Figure id is already given')
return figure_id
# def _set_numbering(figure, centers, render_numbering=True, numbers_size=None,
# numbers_colour='k'):
# import mayavi.mlab as mlab
@@ -70,6 +102,7 @@ def _check_colours_list(render_flag, colours_list, n_objects, error_str):
# scale=numbers_size, orient_to_camera=True,
# color=numbers_colour, line_width=2)


class K3dwidgetsRenderer(Plot, Renderer):
""" Abstract class for performing visualizations using K3dwidgets.

@@ -82,36 +115,8 @@ class K3dwidgetsRenderer(Plot, Renderer):
"""
def __init__(self, figure_id, new_figure):
super(K3dwidgetsRenderer, self).__init__()
if figure_id is None:
if new_figure:
# A new figure is created but with no figure_id
# we should create an id of 'Figure_n form'
list_ids = []
for x in self.widgets.values():
if isinstance(x, K3dwidgetsRenderer) and x is not self:
if x.figure_id is not None and 'Figure_' in str(x.figure_id):
try:
n_figure_id = int(x.figure_id.split('Figure_')[1])
except ValueError:
continue
list_ids.append(n_figure_id)
if len(list_ids):
figure_id = 'Figure_{}'.format(sorted(list_ids)[-1] + 1)
else:
figure_id = 'Figure_0'

else:
self.remove_widget()
raise ValueError('You cannot plot a figure with no id and new figure False')
else:
if new_figure:
for x in self.widgets.values():
if isinstance(x, K3dwidgetsRenderer) and x is not self:
if x.figure_id == figure_id:
self.remove_widget()
raise ValueError('Figure id is already given')

self.figure_id = figure_id
self.figure_id = _check_figure_id(self, figure_id, new_figure)
self.new_figure = new_figure
self.grid_visible = False

@@ -562,3 +567,67 @@ def _render(self, render_lines=True, line_colour='r', line_width=2,
def _build_sub_pointclouds(self):
return [(label, self.landmark_group.get_label(label))
for label in self.landmark_group.labels]


class K3dwidgetsPCAModelViewer3d(GridBox):#, K3dwidgetsRenderer):
def __init__(self, figure_id, new_figure, points, trilist,
components, eigenvalues, n_parameters, parameters_bound,
landmarks_indices, widget_style):

#self.figure_id = figure_id #self.check_figure_id(figure_id, new_figure)
self.figure_id = _check_figure_id(self, figure_id, new_figure)
self.new_figure = new_figure
self.points = points
self.trilist = trilist
self.components = components
self.eigenvalues = eigenvalues
self.n_parameters = n_parameters
self.landmarks_indices = landmarks_indices
self.layout = Layout(grid_template_columns='1fr 1fr')
self.wid = LinearModelParametersWidget(n_parameters=n_parameters,
render_function=self.render_function,
params_str='Parameter ',
mode='multiple',
params_bounds=parameters_bound,
plot_variance_visible=False,
style=widget_style)
self.mesh_window = K3dwidgetsTriMeshViewer3d(self.figure_id, False,
self.points, self.trilist)
super(K3dwidgetsPCAModelViewer3d, self).__init__(children=[self.wid, self.mesh_window],
layout=Layout(grid_template_columns='1fr 1fr'))

def _render_mesh(self, mesh_type, line_width, colour, marker_size,
marker_resolution, marker_style, step, alpha):
marker_size = _parse_marker_size(marker_size, self.points)
colour = _parse_colour(colour)

mesh_to_add = k3d_mesh(self.points.astype(np.float32),
self.trilist.flatten().astype(np.uint32),
flat_shading=False, color=colour,
name='Instance', side='double')

self.mesh_window += mesh_to_add

if self.landmarks_indices is not None:
landmarks_to_add = k3d_points(self.points[self.landmarks_indices].astype(np.float32),
color=0x00FF00, name='landmarks',
point_size=marker_size, shader='mesh')
self.mesh_window += landmarks_to_add
return self

def render_function(self, change):
mesh = self.points + (self.components[:self.n_parameters, :].T@(self.wid.selected_values*self.eigenvalues[:self.n_parameters]**0.5)).reshape(-1,3)
self.mesh_window.objects[0].vertices = mesh
if self.landmarks_indices is not None:
self.mesh_window.objects[1].positions = mesh[self.landmarks_indices]

def _render(self, mesh_type='wireframe', line_width=2, colour='r',
marker_style='sphere', marker_size=None, marker_resolution=8,
normals=None, normals_colour='k', normals_line_width=2,
normals_marker_resolution=8, step=None, alpha=1.0):

return self._render_mesh(mesh_type, line_width, colour, marker_size,
marker_resolution, marker_style, step, alpha)

def remove_widget(self):
super(K3dwidgetsPCAModelViewer3d, self).close()