Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
threevis
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
11
Issues
11
List
Boards
Labels
Service Desk
Milestones
Operations
Operations
Incidents
Packages & Registries
Packages & Registries
Container Registry
Analytics
Analytics
Repository
Value Stream
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
threevis
threevis
Commits
5b5f51cd
Commit
5b5f51cd
authored
Feb 22, 2018
by
Dario Seyb
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fixed point normals for non-tri faces
parent
3ff4f00f
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
21 additions
and
18 deletions
+21
-18
examples/.ipynb_checkpoints/MixedValenceTest-checkpoint.ipynb
...ples/.ipynb_checkpoints/MixedValenceTest-checkpoint.ipynb
+3
-2
examples/MixedValenceTest.ipynb
examples/MixedValenceTest.ipynb
+3
-2
meshvis/indexed_attribute.py
meshvis/indexed_attribute.py
+8
-4
meshvis/mesh_helper.py
meshvis/mesh_helper.py
+7
-10
No files found.
examples/.ipynb_checkpoints/MixedValenceTest-checkpoint.ipynb
View file @
5b5f51cd
...
...
@@ -19,9 +19,10 @@
"\n",
"mesh = meshvis.Mesh(vertices, faces)\n",
"mesh.colors = meshvis.FaceAttribute(np.random.rand(len(faces), 3))\n",
"mesh.normals = meshvis.calculate
Face
Normals(vertices, faces)\n",
"mesh.normals = meshvis.calculate
Point
Normals(vertices, faces)\n",
"\n",
"normal_vis_verts, normal_vis_edges = meshvis.calculateNormalEdges(vertices, faces, mesh.normals, 1)\n",
"\n",
"normal_vis_verts, normal_vis_edges = meshvis.calculateNormalEdges(vertices, faces, mesh.normals, 0.5)\n",
"\n",
"ctx = meshvis.Context()\n",
"\n",
...
...
examples/MixedValenceTest.ipynb
View file @
5b5f51cd
...
...
@@ -19,9 +19,10 @@
"\n",
"mesh = meshvis.Mesh(vertices, faces)\n",
"mesh.colors = meshvis.FaceAttribute(np.random.rand(len(faces), 3))\n",
"mesh.normals = meshvis.calculate
Face
Normals(vertices, faces)\n",
"mesh.normals = meshvis.calculate
Point
Normals(vertices, faces)\n",
"\n",
"normal_vis_verts, normal_vis_edges = meshvis.calculateNormalEdges(vertices, faces, mesh.normals, 1)\n",
"\n",
"normal_vis_verts, normal_vis_edges = meshvis.calculateNormalEdges(vertices, faces, mesh.normals, 0.5)\n",
"\n",
"ctx = meshvis.Context()\n",
"\n",
...
...
meshvis/indexed_attribute.py
View file @
5b5f51cd
...
...
@@ -5,7 +5,8 @@ def stretch_vertices(vertices, face_indices):
for
face
in
face_indices
:
for
vidx
in
face
:
stretched_verts
.
append
(
vertices
[
vidx
])
if
vidx
!=
-
1
:
stretched_verts
.
append
(
vertices
[
vidx
])
return
np
.
array
(
stretched_verts
),
np
.
arange
(
0
,
len
(
stretched_verts
))
...
...
@@ -24,11 +25,14 @@ def resolve_attributes(face_indices, attribs):
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
)
face_valence
=
(
face_indices
!=
-
1
).
sum
(
1
)
totalVertexCount
=
face_valence
.
sum
()
flattened_face_start
=
np
.
cumsum
(
face_valence
)
-
face_valence
stretched_attrib
=
[
None
]
*
totalVertexCount
for
val
in
resolved_attrib
:
stretched_attrib
[
val
[
0
]
*
vs_per_face
+
val
[
1
]]
=
val
[
2
]
stretched_attrib
[
flattened_face_start
[
val
[
0
]]
+
val
[
1
]]
=
val
[
2
]
return
np
.
array
(
stretched_attrib
)
...
...
meshvis/mesh_helper.py
View file @
5b5f51cd
...
...
@@ -10,13 +10,13 @@ def calculateNormalEdges(vertices, face_indices, normals, length):
resolved_normals
=
normals
.
values
face_centers
=
[]
for
face
in
face_indices
:
face_vertices
=
vertices
[
face
]
face_centers
.
append
(
np
.
average
(
face_vertices
,
axis
=
0
,
weights
=
face
!=-
1
))
face_centers
.
append
(
np
.
average
(
vertices
[
face
],
axis
=
0
,
weights
=
face
!=-
1
))
vertices
=
face_centers
else
:
resolved_normals
=
resolve_attributes
(
face_indices
,
[
normals
])[
0
]
vertices
,
face_indices
=
stretch_vertices
(
vertices
,
face_indices
)
edge_vertices
=
[]
edge_indices
=
[]
for
i
,
vert
in
enumerate
(
vertices
):
...
...
@@ -34,6 +34,7 @@ def calculateNormalEdges(vertices, face_indices, normals, length):
def
calculateFaceNormals
(
vertices
,
face_indices
):
values
=
[]
for
face
in
face_indices
:
# Assuming face is planar
v1
=
np
.
array
(
vertices
[
face
[
0
]])
v2
=
np
.
array
(
vertices
[
face
[
1
]])
v3
=
np
.
array
(
vertices
[
face
[
2
]])
...
...
@@ -52,6 +53,7 @@ def calculatePointNormals(vertices, face_indices):
counts
=
np
.
zeros
(
vertices
.
shape
[
0
])
for
face
in
face_indices
:
# Assuming face is planar
v1
=
np
.
array
(
vertices
[
face
[
0
]])
v2
=
np
.
array
(
vertices
[
face
[
1
]])
v3
=
np
.
array
(
vertices
[
face
[
2
]])
...
...
@@ -61,14 +63,9 @@ def calculatePointNormals(vertices, face_indices):
norm
=
np
.
cross
(
v12
,
v13
)
normals
[
face
[
0
]]
+=
norm
normals
[
face
[
1
]]
+=
norm
normals
[
face
[
2
]]
+=
norm
counts
[
face
[
0
]]
+=
1
counts
[
face
[
1
]]
+=
1
counts
[
face
[
2
]]
+=
1
filtered_face
=
face
[
np
.
where
(
face
!=
-
1
)]
normals
[
filtered_face
]
+=
norm
counts
[
filtered_face
]
+=
1
normals
/=
counts
.
reshape
(
-
1
,
1
)
normals
/=
np
.
linalg
.
norm
(
normals
,
axis
=
1
).
reshape
(
-
1
,
1
)
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment