[Yt-svn] commit/yt: MatthewTurk: Adding initial pass at sampling (secondary) field values during isocontour extraction.

Bitbucket commits-noreply at bitbucket.org
Wed Oct 12 10:54:06 PDT 2011


1 new changeset in yt:

http://bitbucket.org/yt_analysis/yt/changeset/3f0d8fa22893/
changeset:   3f0d8fa22893
branch:      yt
user:        MatthewTurk
date:        2011-10-12 02:58:11
summary:     Adding initial pass at sampling (secondary) field values during isocontour extraction.
affected #:  2 files (-1 bytes)

--- a/yt/data_objects/data_containers.py	Tue Oct 11 08:05:53 2011 -0400
+++ b/yt/data_objects/data_containers.py	Tue Oct 11 20:58:11 2011 -0400
@@ -2432,7 +2432,7 @@
     quantities = property(__get_quantities)
 
     def extract_isocontours(self, field, value, filename = None,
-                            rescale = False):
+                            rescale = False, sample_values = None):
         r"""This identifies isocontours on a cell-by-cell basis, with no
         consideration of global connectedness, and returns the vertices of the
         Triangles in that isocontour.
@@ -2481,12 +2481,23 @@
         ...             "triangles.obj", True)
         """
         verts = []
+        samples = []
         for g in self._grids:
             mask = self._get_cut_mask(g) * g.child_mask
             vals = g.get_vertex_centered_data(field)
-            my_verts = march_cubes_grid(value, vals, mask, g.LeftEdge, g.dds)
+            if sample_values is not None:
+                svals = g.get_vertex_centered_data(sample_values)
+            else:
+                svals = None
+            my_verts = march_cubes_grid(value, vals, mask, g.LeftEdge, g.dds,
+                                        svals)
+            if sample_values is not None:
+                my_verts, svals = my_verts
+                samples.append(svals)
             verts.append(my_verts)
         verts = na.concatenate(verts)
+        if sample_values is not None:
+            samples = na.concatenate(samples)
         if rescale:
             mi = na.min(verts, axis=0)
             ma = na.max(verts, axis=0)
@@ -2497,6 +2508,8 @@
                 f.write("v %0.16e %0.16e %0.16e\n" % (v1[0], v1[1], v1[2]))
             for i in range(len(verts)/3):
                 f.write("f %s %s %s\n" % (i*3+1, i*3+2, i*3+3))
+        if sample_values is not None:
+            return verts, samples
         return verts
 
     def calculate_isocontour_flux(self, field, value,


--- a/yt/utilities/_amr_utils/VolumeIntegrator.pyx	Tue Oct 11 08:05:53 2011 -0400
+++ b/yt/utilities/_amr_utils/VolumeIntegrator.pyx	Tue Oct 11 20:58:11 2011 -0400
@@ -69,6 +69,7 @@
 cdef struct Triangle:
     Triangle *next
     np.float64_t p[3][3]
+    np.float64_t val
 
 cdef struct TriangleCollection:
     int count
@@ -98,6 +99,17 @@
         this = this.next
     return count
 
+cdef void FillTriangleValues(np.ndarray[np.float64_t, ndim=1] values,
+                             Triangle *first):
+    cdef Triangle *this = first
+    cdef Triangle *last
+    cdef int i = 0
+    while this != NULL:
+        values[i] = this.val
+        i += 1
+        last = this
+        this = this.next
+
 cdef void WipeTriangles(Triangle *first):
     cdef Triangle *this = first
     cdef Triangle *last
@@ -903,38 +915,77 @@
                      np.ndarray[np.float64_t, ndim=3] values,
                      np.ndarray[np.int32_t, ndim=3] mask,
                      np.ndarray[np.float64_t, ndim=1] left_edge,
-                     np.ndarray[np.float64_t, ndim=1] dxs):
+                     np.ndarray[np.float64_t, ndim=1] dxs,
+                     obj_sample = None):
     cdef int dims[3]
-    cdef int i, j, k, n
+    cdef int i, j, k, n, m, nt
     cdef int offset
-    cdef np.float64_t gv[8]
+    cdef np.float64_t gv[8], pos[3], point[3], idds[3]
     cdef np.float64_t *intdata = NULL
-    cdef np.float64_t x, y, z
+    cdef np.float64_t *sdata = NULL
+    cdef np.float64_t x, y, z, do_sample
+    cdef np.ndarray[np.float64_t, ndim=3] sample
+    cdef np.ndarray[np.float64_t, ndim=1] sampled
     cdef TriangleCollection triangles
-    for i in range(3): dims[i] = values.shape[i] - 1
+    cdef Triangle *last, *current
+    if obj_sample is not None:
+        sample = obj_sample
+        sdata = <np.float64_t *> sample.data
+        do_sample = 1
+    else:
+        do_sample = 0
+    for i in range(3):
+        dims[i] = values.shape[i] - 1
+        idds[i] = 1.0 / dxs[i]
     triangles.first = triangles.current = NULL
+    last = current = NULL
     triangles.count = 0
     cdef np.float64_t *data = <np.float64_t *> values.data
     cdef np.float64_t *dds = <np.float64_t *> dxs.data
-    x = left_edge[0]
+    pos[0] = left_edge[0]
     for i in range(dims[0]):
-        y = left_edge[1]
+        pos[1] = left_edge[1]
         for j in range(dims[1]):
-            z = left_edge[2]
+            pos[2] = left_edge[2]
             for k in range(dims[2]):
                 if mask[i,j,k] == 1:
                     offset = i * (dims[1] + 1) * (dims[2] + 1) \
                            + j * (dims[2] + 1) + k
                     intdata = data + offset
                     offset_fill(dims, intdata, gv)
-                    march_cubes(gv, isovalue, dds, x, y, z,
+                    nt = march_cubes(gv, isovalue, dds, pos[0], pos[1], pos[2],
                                 &triangles)
-                z += dds[2]
-            y += dds[1]
-        x += dds[0]
+                    if do_sample == 1 and nt > 0:
+                        # At each triangle's center, sample our secondary field
+                        if last == NULL and triangles.first != NULL:
+                            current = triangles.first
+                            last = NULL
+                        elif last != NULL:
+                            current = last.next
+                        while current != NULL:
+                            for n in range(3):
+                                point[n] = 0.0
+                            for n in range(3):
+                                for m in range(3):
+                                    point[m] += (current.p[n][m]-pos[m])*idds[m]
+                            for n in range(3):
+                                point[n] /= 3.0
+                            current.val = offset_interpolate(dims, point,
+                                                             sdata + offset)
+                            last = current
+                            if current.next == NULL: break
+                            current = current.next
+                pos[2] += dds[2]
+            pos[1] += dds[1]
+        pos[0] += dds[0]
     # Hallo, we are all done.
     cdef np.ndarray[np.float64_t, ndim=2] vertices 
     vertices = np.zeros((triangles.count*3,3), dtype='float64')
+    if do_sample == 1:
+        sampled = np.zeros(triangles.count, dtype='float64')
+        FillTriangleValues(sampled, triangles.first)
+        FillAndWipeTriangles(vertices, triangles.first)
+        return vertices, sampled
     FillAndWipeTriangles(vertices, triangles.first)
     return vertices

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