Commit bbc3901e authored by Dario Seyb's avatar Dario Seyb

attribute resolving

parent 8407ac4b
# Compiled python modules.
*.pyc
/.vscode
/.noseids
# Setuptools distribution folder.
/dist/
......
......@@ -2,7 +2,7 @@
"cells": [
{
"cell_type": "code",
"execution_count": 19,
"execution_count": 7,
"metadata": {
"scrolled": false
},
......@@ -10,7 +10,7 @@
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "572b1057b1c343ebbd3b94fcd339a803",
"model_id": "b65183b0ba9145dcb55ab172a64e0f0a",
"version_major": 2,
"version_minor": 0
},
......@@ -30,30 +30,25 @@
"</p>\n"
],
"text/plain": [
"Renderer(background='#dddddd', camera=PerspectiveCamera(aspect=1.3333333333333333, children=(DirectionalLight(intensity=0.5, position=(-3.0, 5.0, 1.0), quaternion=(0.0, 0.0, 0.0, 1.0), scale=(1.0, 1.0, 1.0), up=(0.0, 1.0, 0.0)),), fov=20.0, position=(3.0, 3.0, 3.0), quaternion=(0.0, 0.0, 0.0, 1.0), scale=(1.0, 1.0, 1.0), up=(0.0, 1.0, 0.0)), controls=[OrbitControls(controlling=PerspectiveCamera(aspect=1.3333333333333333, children=(DirectionalLight(intensity=0.5, position=(-3.0, 5.0, 1.0), quaternion=(0.0, 0.0, 0.0, 1.0), scale=(1.0, 1.0, 1.0), up=(0.0, 1.0, 0.0)),), fov=20.0, position=(3.0, 3.0, 3.0), quaternion=(0.0, 0.0, 0.0, 1.0), scale=(1.0, 1.0, 1.0), up=(0.0, 1.0, 0.0)))], scene=Scene(background=u'#dddddd', children=(AmbientLight(color=u'#dddddd', quaternion=(0.0, 0.0, 0.0, 1.0), scale=(1.0, 1.0, 1.0), up=(0.0, 1.0, 0.0)), Mesh(geometry=BufferGeometry(attributes={'index': BufferAttribute(array=array([0, 1, 2, 0, 2, 3, 5, 4, 7, 5, 7, 6, 6, 2, 1, 6, 1, 5, 3, 7, 4, 3,\n",
" 4, 0, 7, 3, 2, 7, 2, 6, 5, 1, 0, 5, 0, 4], dtype=uint16), normalized=False), 'position': BufferAttribute(array=array([[-1., -1., -1.],\n",
" [ 1., -1., -1.],\n",
" [ 1., 1., -1.],\n",
" [-1., 1., -1.],\n",
" [-1., -1., 1.],\n",
" [ 1., -1., 1.],\n",
" [ 1., 1., 1.],\n",
" [-1., 1., 1.]], dtype=float32), normalized=False)}), material=MeshLambertMaterial(alphaMap=None, aoMap=None, color=u'#dddddd', colorWrite=False, emissiveMap=None, envMap=None, lightMap=None, map=None, polygonOffset=True, polygonOffsetFactor=0.5, polygonOffsetUnits=0.1, specularMap=None), quaternion=(0.0, 0.0, 0.0, 1.0), scale=(1.0, 1.0, 1.0), up=(0.0, 1.0, 0.0)), LineSegments(geometry=BufferGeometry(attributes={'index': BufferAttribute(array=array([0, 1, 1, 2, 2, 0, 2, 3, 3, 0, 5, 4, 4, 7, 7, 5, 7, 6, 6, 5, 6, 2,\n",
" 1, 6, 1, 5, 3, 7, 4, 3, 4, 0, 2, 7, 0, 5], dtype=uint16), normalized=False), 'position': BufferAttribute(array=array([[-1., -1., -1.],\n",
" [ 1., -1., -1.],\n",
" [ 1., 1., -1.],\n",
" [-1., 1., -1.],\n",
" [-1., -1., 1.],\n",
" [ 1., -1., 1.],\n",
" [ 1., 1., 1.],\n",
" [-1., 1., 1.]], dtype=float32), normalized=False)}), material=LineBasicMaterial(color=u'#000000'), quaternion=(0.0, 0.0, 0.0, 1.0), scale=(1.0, 1.0, 1.0), up=(0.0, 1.0, 0.0)), Points(geometry=BufferGeometry(attributes={'position': BufferAttribute(array=array([[-1., -1., -1.],\n",
" [ 1., -1., -1.],\n",
" [ 1., 1., -1.],\n",
" [-1., 1., -1.],\n",
" [-1., -1., 1.],\n",
" [ 1., -1., 1.],\n",
" [ 1., 1., 1.],\n",
" [-1., 1., 1.]], dtype=float32), normalized=False)}), material=PointsMaterial(color=u'red', map=None, size=5.0, sizeAttenuation=False), quaternion=(0.0, 0.0, 0.0, 1.0), scale=(1.0, 1.0, 1.0), up=(0.0, 1.0, 0.0))), fog=None, overrideMaterial=None, quaternion=(0.0, 0.0, 0.0, 1.0), scale=(1.0, 1.0, 1.0), up=(0.0, 1.0, 0.0)), shadowMap=WebGLShadowMap())"
"Renderer(background='#dddddd', camera=PerspectiveCamera(aspect=1.3333333333333333, children=(DirectionalLight(intensity=0.5, position=(-3.0, 5.0, 1.0), quaternion=(0.0, 0.0, 0.0, 1.0), scale=(1.0, 1.0, 1.0), up=(0.0, 1.0, 0.0)),), fov=20.0, position=(3.0, 3.0, 3.0), quaternion=(0.0, 0.0, 0.0, 1.0), scale=(1.0, 1.0, 1.0), up=(0.0, 1.0, 0.0)), controls=[OrbitControls(controlling=PerspectiveCamera(aspect=1.3333333333333333, children=(DirectionalLight(intensity=0.5, position=(-3.0, 5.0, 1.0), quaternion=(0.0, 0.0, 0.0, 1.0), scale=(1.0, 1.0, 1.0), up=(0.0, 1.0, 0.0)),), fov=20.0, position=(3.0, 3.0, 3.0), quaternion=(0.0, 0.0, 0.0, 1.0), scale=(1.0, 1.0, 1.0), up=(0.0, 1.0, 0.0)))], scene=Scene(background=u'#dddddd', children=(AmbientLight(color=u'#dddddd', quaternion=(0.0, 0.0, 0.0, 1.0), scale=(1.0, 1.0, 1.0), up=(0.0, 1.0, 0.0)), Mesh(geometry=BufferGeometry(attributes={'index': BufferAttribute(array=array([ 0, 1, 2, ..., 3439, 3436, 3440], dtype=uint16), normalized=False), 'position': BufferAttribute(array=array([[-0.283628, 2.931106, -0.140772],\n",
" [-0.22873 , 2.855558, -0.135154],\n",
" [-0.34671 , 2.856239, -0.160498],\n",
" ...,\n",
" [-0.675122, 1.403736, -0.094798],\n",
" [-0.700144, 1.367866, -0.036312],\n",
" [-0.708084, 1.391306, -0.0961 ]], dtype=float32), normalized=False)}), material=MeshLambertMaterial(alphaMap=None, aoMap=None, color=u'#dddddd', colorWrite=False, emissiveMap=None, envMap=None, lightMap=None, map=None, polygonOffset=True, polygonOffsetFactor=0.5, polygonOffsetUnits=0.1, specularMap=None), quaternion=(0.0, 0.0, 0.0, 1.0), scale=(1.0, 1.0, 1.0), up=(0.0, 1.0, 0.0)), LineSegments(geometry=BufferGeometry(attributes={'index': BufferAttribute(array=array([ 0, 1, 1, ..., 3435, 3440, 3436], dtype=uint16), normalized=False), 'position': BufferAttribute(array=array([[-0.283628, 2.931106, -0.140772],\n",
" [-0.22873 , 2.855558, -0.135154],\n",
" [-0.34671 , 2.856239, -0.160498],\n",
" ...,\n",
" [-0.675122, 1.403736, -0.094798],\n",
" [-0.700144, 1.367866, -0.036312],\n",
" [-0.708084, 1.391306, -0.0961 ]], dtype=float32), normalized=False)}), material=LineBasicMaterial(color=u'#000000'), quaternion=(0.0, 0.0, 0.0, 1.0), scale=(1.0, 1.0, 1.0), up=(0.0, 1.0, 0.0)), Points(geometry=BufferGeometry(attributes={'position': BufferAttribute(array=array([[-0.283628, 2.931106, -0.140772],\n",
" [-0.22873 , 2.855558, -0.135154],\n",
" [-0.34671 , 2.856239, -0.160498],\n",
" ...,\n",
" [-0.675122, 1.403736, -0.094798],\n",
" [-0.700144, 1.367866, -0.036312],\n",
" [-0.708084, 1.391306, -0.0961 ]], dtype=float32), normalized=False)}), material=PointsMaterial(color=u'red', map=None, size=2.0, sizeAttenuation=False), quaternion=(0.0, 0.0, 0.0, 1.0), scale=(1.0, 1.0, 1.0), up=(0.0, 1.0, 0.0))), fog=None, overrideMaterial=None, quaternion=(0.0, 0.0, 0.0, 1.0), scale=(1.0, 1.0, 1.0), up=(0.0, 1.0, 0.0)), shadowMap=WebGLShadowMap())"
]
},
"metadata": {},
......@@ -64,7 +59,7 @@
"import meshvis\n",
"import openmesh as om\n",
"m = om.TriMesh()\n",
"om.read_mesh(m, \"/home/dseyb/git/openmesh-python/tests/TestFiles/cube-minimal-normals.ply\")\n",
"om.read_mesh(m, \"C:\\Users\\dario\\OneDrive\\Dokumente\\ANIMVR\\Import\\Models\\Mickey_Mouse.obj\")\n",
"\n",
"ctx = meshvis.Context(width=640, height=480)\n",
"\n",
......@@ -72,7 +67,7 @@
"\n",
"ctx.draw_edges(m.points(), m.ev_indices())\n",
"\n",
"ctx.draw_vertices(m.points(), point_size=5, colors='red')\n",
"ctx.draw_vertices(m.points(), point_size=2, colors='red')\n",
"\n",
"ctx.display()"
]
......@@ -85,7 +80,7 @@
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "72c8803bfd1f4a7eaee4bac39454a9d6",
"model_id": "c8a705ab47cb4ce6a7bcfd5e4459fc8c",
"version_major": 2,
"version_minor": 0
},
......@@ -139,13 +134,13 @@
},
{
"cell_type": "code",
"execution_count": 4,
"execution_count": 3,
"metadata": {},
"outputs": [
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "0e1762e519fa4ef68dfd9a9e962be650",
"model_id": "703dd68cfece4d5aa3ed20871bbda1a5",
"version_major": 2,
"version_minor": 0
},
......@@ -185,7 +180,7 @@
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "4b39b21a50c840e9889e98951b01e6e8",
"model_id": "dd25e52e709c4356a94f837e59dac0ed",
"version_major": 2,
"version_minor": 0
},
......@@ -275,7 +270,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython2",
"version": "2.7.13"
"version": "2.7.14"
}
},
"nbformat": 4,
......
try:
from .openmesh_utils import *
except ImportError as e:
print('OpenMesh not available')
print(e)
except ImportError as error:
print 'OpenMesh not available'
  • Let's try and stay python 2/3 compatible (or at least python 3 compatible). You can use from __future__ import print_function in python 2 and then print(...).

  • Ah, makes sense. My linter was screaming at me, but I'll just ignore that particular warning

Please register or sign in to reply
print error
from .context import *
from .immediate import *
\ No newline at end of file
from .immediate import *
from .indexed_attribute import UniformAttribute, PointAttribute, FaceAttribute, HalfEdgeAttribute, resolve_attributes
import pythreejs as three
import numpy as np
from IPython.display import display
......
def resolve_attributes(face_indices, attribs):
final_attributes = []
for attrib in attribs:
resolved_attrib = attrib.resolve(face_indices)
final_attributes.append(stretch_attribute(face_indices, resolved_attrib))
return final_attributes
def stretch_attribute(face_indices, resolved_attrib):
vs_per_face = len(face_indices[0])
stretched_attrib = [None] * (len(face_indices) * vs_per_face)
for val in resolved_attrib:
stretched_attrib[val[0] * vs_per_face + val[1]] = val[2]
return stretched_attrib
def find(element, list_element):
try:
index_element = list_element.index(element)
return index_element
except ValueError:
return None
class UniformAttribute(object):
def __init__(self, value):
self.value = value
def resolve(self, face_indices):
result = []
for f_idx, face in enumerate(face_indices):
for idx_in_face, _ in enumerate(face):
result.append((f_idx, idx_in_face, self.value))
return result
class IndexedAttribute(object):
def __init__(self, values, indices):
assert(len(values) is len(indices))
self.values = values
self.indices = indices
class PointAttribute(IndexedAttribute):
def __init__(self, values, indices = None):
if indices is None:
indices = range(0, len(values))
super(PointAttribute, self).__init__(values, indices)
def resolve(self, face_indices):
result = []
for i, val in enumerate(self.values):
idx = self.indices[i]
# find all faces that contain the vertex
for f_idx, face in enumerate(face_indices):
# check if vertex is in face
idx_in_face = find(idx, face)
# if yes, add value for vertex in that face
if idx_in_face is not None:
result.append((f_idx, idx_in_face, val))
return result
class FaceAttribute(IndexedAttribute):
def __init__(self, values, indices = None):
if indices is None:
indices = range(0, len(values))
super(FaceAttribute, self).__init__(values, indices)
def resolve(self, face_indices):
result = []
for i, val in enumerate(self.values):
idx = self.indices[i]
# Add value for all vertices in the face
for f_vidx in range(0, len(face_indices[idx])):
result.append((idx, f_vidx, val))
return result
class HalfEdgeAttribute(IndexedAttribute):
def __init__(self, values, indices):
super(HalfEdgeAttribute, self).__init__(values, indices)
def resolve(self, face_indices):
result = []
for i, val in enumerate(self.values):
idx = self.indices[i]
# find all faces that contain the vertex
for f_idx, face in enumerate(face_indices):
# check if edge is in face
start_idx_in_face = find(idx[0], face)
end_idx_in_face = find(idx[1], face)
# both ends need to be in the face
if start_idx_in_face is None or end_idx_in_face is None:
continue
# and the edge needs to point in the right direction
if (start_idx_in_face + 1) % len(face) is not end_idx_in_face:
continue
# value of half edge counts as value of the vertex that's pointed towards
result.append((f_idx, end_idx_in_face, val))
return result
\ No newline at end of file
import openmesh as om
from pythreejs import *
from .immediate import *
......
......@@ -2,7 +2,7 @@ from setuptools import setup
def readme():
with open('README.rst') as f:
return f.read();
return f.read()
setup(name='meshvis',
version='0.1',
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment