Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
F
fslpy
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Deploy
Releases
Container Registry
Model registry
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Michiel Cottaar
fslpy
Commits
1614e9ee
Commit
1614e9ee
authored
7 years ago
by
Paul McCarthy
Browse files
Options
Downloads
Patches
Plain Diff
Mesh class calculates normals. Implementations are crap
parent
e1fcb14b
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
fsl/data/mesh.py
+68
-2
68 additions, 2 deletions
fsl/data/mesh.py
with
68 additions
and
2 deletions
fsl/data/mesh.py
+
68
−
2
View file @
1614e9ee
...
...
@@ -53,6 +53,12 @@ class TriangleMesh(object):
``indices`` A :meth:`M
\t
imes 3` ``numpy`` array containing
the vertex indices for :math:`M` triangles
``normals`` A :math:`M
\t
imes 3` ``numpy`` array containing
face normals.
``vnormals`` A :math:`N
\t
imes 3` ``numpy`` array containing
vertex normals.
============== ====================================================
...
...
@@ -101,8 +107,10 @@ class TriangleMesh(object):
self
.
indices
=
np
.
array
(
indices
).
reshape
((
-
1
,
3
))
self
.
__vertexData
=
{}
self
.
__loBounds
=
self
.
vertices
.
min
(
axis
=
0
)
self
.
__hiBounds
=
self
.
vertices
.
max
(
axis
=
0
)
self
.
__faceNormals
=
None
self
.
__vertNormals
=
None
self
.
__loBounds
=
self
.
vertices
.
min
(
axis
=
0
)
self
.
__hiBounds
=
self
.
vertices
.
max
(
axis
=
0
)
def
__repr__
(
self
):
...
...
@@ -118,6 +126,64 @@ class TriangleMesh(object):
return
self
.
__repr__
()
@property
def
normals
(
self
):
"""
Returns a ``(M, 3)`` array containing normals for every triangle
in the mesh.
"""
if
self
.
__faceNormals
is
not
None
:
return
self
.
__faceNormals
v1
=
self
.
vertices
[
self
.
indices
[:,
0
]]
v2
=
self
.
vertices
[
self
.
indices
[:,
1
]]
fnormals
=
np
.
cross
(
v1
,
v2
)
# TODO make fast, and make sure that this actually works.
for
i
in
range
(
self
.
indices
.
shape
[
0
]):
p0
,
p1
,
p2
=
self
.
vertices
[
self
.
indices
[
i
],
:]
n
=
fnormals
[
i
,
:]
if
np
.
dot
(
n
,
np
.
cross
(
p1
-
p0
,
p2
-
p0
))
>
0
:
fnormals
[
i
,
:]
*=
-
1
self
.
__faceNormals
=
fnormals
return
self
.
__faceNormals
@property
def
vnormals
(
self
):
"""
Returns a ``(N, 3)`` array containing normals for every vertex
in the mesh.
"""
if
self
.
__vertNormals
is
not
None
:
return
self
.
__vertNormals
# per-face normals
fnormals
=
self
.
normals
vnormals
=
np
.
zeros
((
self
.
vertices
.
shape
[
0
],
3
),
dtype
=
np
.
float
)
# TODO make fast
for
i
in
range
(
self
.
indices
.
shape
[
0
]):
v0
,
v1
,
v2
=
self
.
indices
[
i
]
vnormals
[
v0
,
:]
+=
fnormals
[
i
]
vnormals
[
v1
,
:]
+=
fnormals
[
i
]
vnormals
[
v2
,
:]
+=
fnormals
[
i
]
# normalise to unit length
lens
=
np
.
sqrt
(
np
.
sum
(
vnormals
*
vnormals
,
axis
=
1
))
vnormals
=
(
vnormals
.
T
/
lens
).
T
self
.
__vertNormals
=
vnormals
return
self
.
__vertNormals
def
getBounds
(
self
):
"""
Returns a tuple of values which define a minimal bounding box that
will contain all vertices in this ``TriangleMesh`` instance. The
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment