[yt-svn] commit/yt: ngoldbaum: Merged in atmyers/yt (pull request #2194)
commits-noreply at bitbucket.org
commits-noreply at bitbucket.org
Fri May 27 11:00:24 PDT 2016
1 new commit in yt:
https://bitbucket.org/yt_analysis/yt/commits/b8a09cd382dd/
Changeset: b8a09cd382dd
Branch: yt
User: ngoldbaum
Date: 2016-05-27 18:00:13+00:00
Summary: Merged in atmyers/yt (pull request #2194)
IDV improvements for unstructured mesh.
Affected #: 4 files
diff -r 027e7591dc5a18423ab364582ef7c4b895fe9b44 -r b8a09cd382dd34f386ce3634e7f78df3f5d9401d yt/utilities/lib/mesh_triangulation.h
--- a/yt/utilities/lib/mesh_triangulation.h
+++ b/yt/utilities/lib/mesh_triangulation.h
@@ -22,10 +22,10 @@
// Similarly, this is used to triangulate the tetrahedral cells
int triangulate_tetra[MAX_NUM_TRI][3] = {
- {0, 1, 2},
- {0, 1, 3},
- {0, 2, 3},
- {1, 2, 3},
+ {0, 1, 3},
+ {2, 3, 1},
+ {0, 3, 2},
+ {0, 2, 1},
{-1, -1, -1},
{-1, -1, -1},
@@ -39,14 +39,14 @@
// Triangulate wedges
int triangulate_wedge[MAX_NUM_TRI][3] = {
- {0, 1, 2},
- {0, 3, 1},
- {1, 3, 4},
- {0, 2, 3},
- {2, 5, 3},
- {1, 4, 2},
- {2, 4, 5},
- {3, 5, 4},
+ {3, 0, 1},
+ {4, 3, 1},
+ {2, 5, 4},
+ {2, 4, 1},
+ {0, 3, 2},
+ {2, 3, 5},
+ {3, 4, 5},
+ {0, 2, 1},
{-1, -1, -1},
{-1, -1, -1},
diff -r 027e7591dc5a18423ab364582ef7c4b895fe9b44 -r b8a09cd382dd34f386ce3634e7f78df3f5d9401d yt/utilities/lib/mesh_triangulation.pyx
--- a/yt/utilities/lib/mesh_triangulation.pyx
+++ b/yt/utilities/lib/mesh_triangulation.pyx
@@ -56,3 +56,117 @@
offset = tri_array[j][k]
tri_indices_ptr[i*TPE*3 + 3*j + k] = indices_ptr[i*VPE + offset]
return tri_indices
+
+ at cython.boundscheck(False)
+ at cython.wraparound(False)
+ at cython.cdivision(True)
+def triangulate_vertex_data(np.ndarray[np.float64_t, ndim=2] coords,
+ np.ndarray[np.float64_t, ndim=2] data,
+ np.ndarray[np.int64_t, ndim=2] indices):
+
+ cdef np.int64_t num_elem = indices.shape[0]
+ cdef np.int64_t VPE = indices.shape[1] # num verts per element
+ cdef np.int64_t TPE # num triangles per element
+ cdef int[MAX_NUM_TRI][3] tri_array
+
+ if (VPE == 8 or VPE == 20 or VPE == 27):
+ TPE = HEX_NT
+ tri_array = triangulate_hex
+ elif VPE == 4:
+ TPE = TETRA_NT
+ tri_array = triangulate_tetra
+ elif VPE == 6:
+ TPE = WEDGE_NT
+ tri_array = triangulate_wedge
+ else:
+ raise YTElementTypeNotRecognized(3, VPE)
+
+ cdef np.int64_t num_tri = TPE * num_elem
+ cdef np.int64_t num_verts = coords.shape[0]
+
+ cdef np.ndarray[np.int32_t, ndim=1] tri_indices
+ tri_indices = np.empty(num_tri*3, dtype="int32")
+ cdef np.int32_t *tri_indices_ptr = <np.int32_t*> tri_indices.data
+
+ cdef np.ndarray[np.float32_t, ndim=1] tri_coords
+ tri_coords = np.empty(num_verts*3, dtype=np.float32)
+ cdef np.float32_t *tri_coords_ptr = <np.float32_t*> tri_coords.data
+
+ cdef np.ndarray[np.float32_t, ndim=1] tri_data
+ tri_data = np.zeros(num_verts, dtype="float32")
+ cdef np.float32_t *tri_data_ptr = <np.float32_t*> tri_data.data
+
+ cdef np.int64_t *indices_ptr = <np.int64_t*> indices.data
+ cdef np.float64_t *coords_ptr = <np.float64_t*> coords.data
+ cdef np.float64_t *data_ptr = <np.float64_t*> data.data
+
+ cdef np.int64_t i, j, k, offset
+ for i in range(num_elem):
+ for j in range(TPE):
+ for k in range(3):
+ offset = tri_array[j][k]
+ tri_indices_ptr[i*TPE*3 + 3*j + k] = indices_ptr[i*VPE + offset]
+ for j in range(VPE):
+ tri_data_ptr[indices_ptr[i*VPE + j]] = data_ptr[i*VPE + j]
+ for i in range(num_verts):
+ for j in range(3):
+ tri_coords_ptr[i*3 + j] = coords_ptr[i*3 + j]
+
+ return tri_coords, tri_data, tri_indices
+
+ at cython.boundscheck(False)
+ at cython.wraparound(False)
+ at cython.cdivision(True)
+def triangulate_element_data(np.ndarray[np.float64_t, ndim=2] coords,
+ np.ndarray[np.float64_t, ndim=1] data,
+ np.ndarray[np.int64_t, ndim=2] indices):
+
+ cdef np.int64_t num_elem = indices.shape[0]
+ cdef np.int64_t VPE = indices.shape[1] # num verts per element
+ cdef np.int64_t TPE # num triangles per element
+ cdef int[MAX_NUM_TRI][3] tri_array
+
+ if (VPE == 8 or VPE == 20 or VPE == 27):
+ TPE = HEX_NT
+ tri_array = triangulate_hex
+ elif VPE == 4:
+ TPE = TETRA_NT
+ tri_array = triangulate_tetra
+ elif VPE == 6:
+ TPE = WEDGE_NT
+ tri_array = triangulate_wedge
+ else:
+ raise YTElementTypeNotRecognized(3, VPE)
+
+ cdef np.int64_t num_tri = TPE * num_elem
+ cdef np.int64_t num_verts = num_tri*3
+
+ cdef np.ndarray[np.int32_t, ndim=1] tri_indices
+ tri_indices = np.empty(num_verts, dtype="int32")
+ cdef np.int32_t *tri_indices_ptr = <np.int32_t*> tri_indices.data
+
+ cdef np.ndarray[np.float32_t, ndim=1] tri_data
+ tri_data = np.empty(num_verts, dtype=np.float32)
+ cdef np.float32_t *tri_data_ptr = <np.float32_t*> tri_data.data
+
+ cdef np.ndarray[np.float32_t, ndim=1] tri_coords
+ tri_coords = np.empty(num_verts*3, dtype=np.float32)
+ cdef np.float32_t *tri_coords_ptr = <np.float32_t*> tri_coords.data
+
+ cdef np.float64_t *data_ptr = <np.float64_t*> data.data
+ cdef np.float64_t *coords_ptr = <np.float64_t*> coords.data
+ cdef np.int64_t *indices_ptr = <np.int64_t*> indices.data
+
+ cdef np.int64_t i, j, k, l,
+ cdef np.int64_t coord_index, vert_index
+ for i in range(num_elem):
+ for j in range(TPE):
+ for k in range(3):
+ coord_index = indices_ptr[i*VPE + tri_array[j][k]]*3
+ vert_index = i*TPE*3+j*3+k
+ tri_data_ptr[vert_index] = data_ptr[i]
+ for l in range(3):
+ tri_coords_ptr[vert_index*3 + l] = coords_ptr[coord_index + l]
+ tri_indices_ptr[vert_index] = vert_index
+
+ return tri_coords, tri_data, tri_indices
diff -r 027e7591dc5a18423ab364582ef7c4b895fe9b44 -r b8a09cd382dd34f386ce3634e7f78df3f5d9401d yt/visualization/volume_rendering/interactive_vr.py
--- a/yt/visualization/volume_rendering/interactive_vr.py
+++ b/yt/visualization/volume_rendering/interactive_vr.py
@@ -28,6 +28,8 @@
quaternion_mult, \
quaternion_to_rotation_matrix, \
rotation_matrix_to_quaternion
+from yt.utilities.lib.mesh_triangulation import triangulate_vertex_data, \
+ triangulate_element_data
from .shader_objects import known_shaders, ShaderProgram
bbox_vertices = np.array(
@@ -77,28 +79,6 @@
+1.0, +1.0, 0.0], dtype=np.float32
)
-triangulate_hex = np.array([
- [0, 2, 1], [0, 3, 2],
- [4, 5, 6], [4, 6, 7],
- [0, 1, 5], [0, 5, 4],
- [1, 2, 6], [1, 6, 5],
- [0, 7, 3], [0, 4, 7],
- [3, 6, 2], [3, 7, 6]]
-)
-
-triangulate_tetra = np.array([
- [0, 1, 3], [2, 3, 1],
- [0, 3, 2], [0, 2, 1]]
-)
-
-triangulate_wedge = np.array([
- [3, 0, 1], [4, 3, 1],
- [2, 5, 4], [2, 4, 1],
- [0, 3, 2], [2, 3, 5],
- [3, 4, 5], [0, 2, 1]]
-)
-
-
class IDVCamera(object):
'''Camera object used in the Interactive Data Visualization
@@ -655,38 +635,23 @@
"""
# get mesh information
- ftype, fname = field
- mesh_id = int(ftype[-1])
+ try:
+ ftype, fname = field
+ mesh_id = int(ftype[-1])
+ except ValueError:
+ mesh_id = 0
+
mesh = data_source.ds.index.meshes[mesh_id-1]
offset = mesh._index_offset
vertices = mesh.connectivity_coords
indices = mesh.connectivity_indices - offset
- # get vertex data
data = data_source[field]
- vertex_data = np.zeros(vertices.shape[0], dtype=data.dtype)
- vertex_data[indices.flatten()] = data.flatten()
- if indices.shape[1] == 8:
- tri_array = triangulate_hex
- elif indices.shape[1] == 4:
- tri_array = triangulate_tetra
- elif indices.shape[1] == 6:
- tri_array = triangulate_wedge
- else:
- raise NotImplementedError
-
- tri_indices = []
- for elem in indices:
- for tri in tri_array:
- tri_indices.append(elem[tri])
- tri_indices = np.array(tri_indices)
-
- v = vertices.astype(np.float32).flatten()
- d = vertex_data.astype(np.float32).flatten()
- i = tri_indices.astype(np.uint32).flatten()
-
- return v, d, i
+ if len(data.shape) == 1:
+ return triangulate_element_data(vertices, data, indices)
+ elif data.shape[1] == indices.shape[1]:
+ return triangulate_vertex_data(vertices, data, indices)
def run_program(self):
""" Renders one frame of the scene. """
diff -r 027e7591dc5a18423ab364582ef7c4b895fe9b44 -r b8a09cd382dd34f386ce3634e7f78df3f5d9401d yt/visualization/volume_rendering/interactive_vr_helpers.py
--- a/yt/visualization/volume_rendering/interactive_vr_helpers.py
+++ b/yt/visualization/volume_rendering/interactive_vr_helpers.py
@@ -70,7 +70,7 @@
field = dobj.ds.default_field
if field not in dobj.ds.derived_field_list:
raise YTSceneFieldNotFound("""Could not find field '%s' in %s.
- Please specify a field in create_scene()""" % (field, data_source.ds))
+ Please specify a field in create_scene()""" % (field, dobj.ds))
mylog.info('Setting default field to %s' % field.__repr__())
if window_size is None:
window_size = (1024, 1024)
Repository URL: https://bitbucket.org/yt_analysis/yt/
--
This is a commit notification from bitbucket.org. You are receiving
this because you have the service enabled, addressing the recipient of
this email.
More information about the yt-svn
mailing list