Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Daniel Boeckenhoff
tfields
Commits
c4f15ff6
Commit
c4f15ff6
authored
Sep 18, 2018
by
Daniel Boeckenhoff
Browse files
dunno
parent
ed580de2
Changes
4
Hide whitespace changes
Inline
Side-by-side
tfields/bounding_box.py
View file @
c4f15ff6
...
...
@@ -331,33 +331,41 @@ class Node(object):
class
Searcher
(
Node
):
def
__init__
(
self
,
mesh
,
n_sections
=
None
,
delta
=
0.
):
def
__init__
(
self
,
mesh
,
n_sections
=
None
,
delta
=
0.
,
cut_length
=
None
):
"""
Special cutting tree root node.
Provides a fast point in mesh search algorithm (Searcher.in_faces)
Args:
n_sections (None or list of len 3):
None: auto search n_sections
list: number of sections in the index dimension
delta (float): safety margin around the mesh to search in
cut_length (None / float): characteristic cell size. Be carefull,
to choose it high enough. If it is smaller than the largest
triangle, a box could lie in the triangle without containing it.
"""
minima
=
mesh
.
min
(
axis
=
0
)
-
0.0001
maxima
=
mesh
.
max
(
axis
=
0
)
+
0.0001
if
n_sections
is
None
or
any
([
ns
is
None
for
ns
in
n_sections
]):
# project all triangels to have one point at 0, 0, 0
triangles
=
mesh
.
triangles
().
copy
()
triangles
.
fields
=
[]
ab
,
ac
=
triangles
.
edges
()
bc
=
ac
-
ab
side_lengths
=
np
.
concatenate
([
np
.
linalg
.
norm
(
side
,
axis
=
1
)
for
side
in
[
ab
,
ac
,
bc
]]
)
# import mplTools as mpl
# axis= tfields.plotting.gca(2)
# mpl.plotHistogram(side_lengths, axis=axis
)
# mpl.pl
t.show(
)
# quit
()
characteristic_side_length
=
np
.
max
(
side_lengths
)
cut_length
=
characteristic_side_length
*
1.1
if
cut_length
is
None
:
# project all triangels to have one point at 0, 0, 0
triangles
=
mesh
.
triangles
().
copy
()
triangles
.
fields
=
[]
ab
,
ac
=
triangles
.
edges
()
bc
=
ac
-
ab
side_lengths
=
np
.
concatenate
([
np
.
linalg
.
norm
(
side
,
axis
=
1
)
for
side
in
[
ab
,
ac
,
bc
]])
# import mplTools as mpl
# axis= tfields.plotting.gca(2
)
# mpl.pl
otHistogram(side_lengths, axis=axis
)
# mpl.plt.show
()
# quit(
)
characteristic_side_length
=
np
.
max
(
side_lengths
)
cut_length
=
characteristic_side_length
*
1.1
elongation
=
maxima
-
minima
n_sections_auto
=
np
.
round
(
elongation
/
cut_length
).
astype
(
int
)
...
...
@@ -367,6 +375,8 @@ class Searcher(Node):
if
ns
is
not
None
:
n_sections_auto
[
i
]
=
int
(
ns
)
n_sections
=
n_sections_auto
elif
cut_length
is
not
None
:
raise
ValueError
(
"cut_length not used."
)
cut
=
{}
for
i
,
key
in
enumerate
([
'x'
,
'y'
,
'z'
]):
...
...
tfields/lib/sets.py
View file @
c4f15ff6
...
...
@@ -100,9 +100,14 @@ class UnionFind(object):
Build unions for whole iterators of any size
"""
self
.
insert_objects
(
tfields
.
lib
.
util
.
flatten
(
iterator
))
log
=
logging
.
getLogger
(
"UnionFind.__call__"
)
i
=
0
n
=
len
(
iterator
)
for
item
in
iterator
:
log
.
info
(
"Step {i} / n"
)
for
i1
,
i2
in
tfields
.
lib
.
util
.
pairwise
(
item
):
self
.
union
(
i1
,
i2
)
i
+=
1
def
groups
(
self
,
iterator
):
"""
...
...
tfields/mesh3D.py
View file @
c4f15ff6
...
...
@@ -245,7 +245,6 @@ class Mesh3D(tfields.TensorMaps):
directory
,
name
=
os
.
path
.
split
(
path
)
if
not
(
self
.
faceScalars
.
size
==
0
or
map_index
is
None
):
import
matplotlib.colors
as
colors
scalars
=
self
.
maps
[
0
].
fields
[
map_index
]
min_scalar
=
scalars
[
~
np
.
isnan
(
scalars
)].
min
()
max_scalar
=
scalars
[
~
np
.
isnan
(
scalars
)].
max
()
...
...
@@ -256,12 +255,17 @@ class Mesh3D(tfields.TensorMaps):
vmax
=
1.
else
:
vmin
=
0.
import
matplotlib.colors
as
colors
import
matplotlib.pyplot
as
plt
norm
=
colors
.
Normalize
(
vmin
,
vmax
)
color_map
=
plt
.
get_cmap
(
cmap
)
else
:
# switch for not coloring the triangles and thus not producing the materials
norm
=
None
if
len
(
kwargs
)
!=
0
:
raise
ValueError
(
"Unused arguments."
)
if
norm
is
not
None
:
mat_name
=
name
+
'_frame_{0}.mat'
.
format
(
map_index
)
scalars
[
np
.
isnan
(
scalars
)]
=
min_scalar
-
1
...
...
@@ -428,10 +432,10 @@ class Mesh3D(tfields.TensorMaps):
>>> sphere[:, 1] += 2
Oktaeder
>>> oktder = tfields.Mesh3D.grid((1, 1, 1),
... (-np.pi, np.pi, 5),
... (-np.pi / 2, np.pi / 2, 3),
... coord_sys='spherical')
>>> okt
ae
der = tfields.Mesh3D.grid((1, 1, 1),
...
(-np.pi, np.pi, 5),
...
(-np.pi / 2, np.pi / 2, 3),
...
coord_sys='spherical')
Cube with edge length of 2 units
>>> cube = tfields.Mesh3D.grid((-1, 1, 2),
...
...
@@ -707,7 +711,7 @@ class Mesh3D(tfields.TensorMaps):
nTrue
=
vertices_rejected
.
count
(
True
)
lonely_bool
=
True
if
nTrue
==
1
else
False
triangle_points
=
[
inst
[
f
]
for
f
in
face
]
triangle_points
=
[
vertices
[
f
]
for
f
in
face
]
"""
Add the intersection points and faces
"""
...
...
tfields/plotting/mpl.py
View file @
c4f15ff6
...
...
@@ -447,10 +447,11 @@ def to_colors(scalars, cmap=None, vmin=None, vmax=None):
"""
if
not
hasattr
(
scalars
,
'__iter__'
):
scalars
=
[
scalars
]
scalars
=
np
.
array
(
scalars
)
if
vmin
is
None
:
vmin
=
min
(
scalars
)
vmin
=
min
(
scalars
.
flat
)
if
vmax
is
None
:
vmax
=
max
(
scalars
)
vmax
=
max
(
scalars
.
flat
)
color_map
=
plt
.
get_cmap
(
cmap
)
norm
=
mpl
.
colors
.
Normalize
(
vmin
=
vmin
,
vmax
=
vmax
)
return
color_map
([
norm
(
s
)
for
s
in
scalars
])
...
...
@@ -600,7 +601,10 @@ def set_legend(axis, artists, **kwargs):
return
axis
.
legend
(
handles
=
handles
,
**
kwargs
)
def
set_colorbar
(
axis
,
artist
,
label
=
None
,
divide
=
True
,
**
kwargs
):
def
set_colorbar
(
axis
,
artist
,
label
=
None
,
divide
=
True
,
position
=
'right'
,
size
=
"2%"
,
pad
=
0.05
,
labelpad
=
None
,
**
kwargs
):
"""
Note:
Bug found in matplotlib:
...
...
@@ -616,11 +620,28 @@ def set_colorbar(axis, artist, label=None, divide=True, **kwargs):
>> axis.clear()
"""
ticks_position
=
'default'
label_position
=
'bottom'
labelpad
=
30
if
labelpad
is
None
else
labelpad
if
position
==
'right'
:
rotation
=
270
elif
position
==
'left'
:
rotation
=
90
elif
position
==
'top'
:
rotation
=
0
ticks_position
=
'top'
label_position
=
'top'
labelpad
=
5
elif
position
==
'bottom'
:
rotation
=
0
# colorbar
if
divide
:
divider
=
make_axes_locatable
(
axis
)
axis
=
divider
.
append_axes
(
"right"
,
size
=
"2%"
,
pad
=
0.05
)
axis
=
divider
.
append_axes
(
position
,
size
=
size
,
pad
=
pad
)
cbar
=
plt
.
colorbar
(
artist
,
cax
=
axis
,
**
kwargs
)
cbar
.
ax
.
xaxis
.
set_ticks_position
(
ticks_position
)
cbar
.
ax
.
xaxis
.
set_label_position
(
label_position
)
cbar
.
ax
.
tick_params
(
axis
=
'x'
,
which
=
'major'
,
pad
=
0
)
# label
if
label
is
None
:
...
...
@@ -628,8 +649,7 @@ def set_colorbar(axis, artist, label=None, divide=True, **kwargs):
if
art_label
:
label
=
art_label
if
label
is
not
None
:
labelpad
=
30
cbar
.
set_label
(
label
,
rotation
=
270
,
labelpad
=
labelpad
)
cbar
.
set_label
(
label
,
rotation
=
rotation
,
labelpad
=
labelpad
)
return
cbar
...
...
Write
Preview
Supports
Markdown
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