1cdef class IndexedOctreeSubsetSelector(SelectorObject):
2    # This is a numpy array, which will be a bool of ndim 1
3    cdef np.uint64_t min_ind
4    cdef np.uint64_t max_ind
5    cdef public SelectorObject base_selector
6    cdef int filter_bbox
7    cdef np.float64_t DLE[3]
8    cdef np.float64_t DRE[3]
9
10    def __init__(self, dobj):
11        self.min_ind = dobj.min_ind
12        self.max_ind = dobj.max_ind
13        self.base_selector = dobj.base_selector
14        self.min_level = self.base_selector.min_level
15        self.max_level = self.base_selector.max_level
16        self.filter_bbox = 0
17        if getattr(dobj.ds, "filter_bbox", False):
18            self.filter_bbox = 1
19        for i in range(3):
20            self.DLE[i] = dobj.ds.domain_left_edge[i]
21            self.DRE[i] = dobj.ds.domain_right_edge[i]
22
23    @cython.boundscheck(False)
24    @cython.wraparound(False)
25    @cython.cdivision(True)
26    def select_grids(self,
27                     np.ndarray[np.float64_t, ndim=2] left_edges,
28                     np.ndarray[np.float64_t, ndim=2] right_edges,
29                     np.ndarray[np.int32_t, ndim=2] levels):
30        raise RuntimeError
31
32    @cython.boundscheck(False)
33    @cython.wraparound(False)
34    @cython.cdivision(True)
35    cdef int select_sphere(self, np.float64_t pos[3], np.float64_t radius) nogil:
36        return 1
37
38    @cython.boundscheck(False)
39    @cython.wraparound(False)
40    @cython.cdivision(True)
41    cdef int select_cell(self, np.float64_t pos[3], np.float64_t dds[3]) nogil:
42        return 1
43
44    @cython.boundscheck(False)
45    @cython.wraparound(False)
46    @cython.cdivision(True)
47    cdef int select_point(self, np.float64_t pos[3]) nogil:
48        cdef int i
49        if self.filter_bbox == 0:
50            return 1
51        for i in range(3):
52            if pos[i] < self.DLE[i] or pos[i] > self.DRE[i]:
53                return 0
54        return 1
55
56    @cython.boundscheck(False)
57    @cython.wraparound(False)
58    @cython.cdivision(True)
59    cdef int select_bbox(self, np.float64_t left_edge[3],
60                               np.float64_t right_edge[3]) nogil:
61        return self.base_selector.select_bbox(left_edge, right_edge)
62
63    cdef int select_grid(self, np.float64_t left_edge[3],
64                         np.float64_t right_edge[3], np.int32_t level,
65                         Oct *o = NULL) nogil:
66        # Because visitors now use select_grid, we should be explicitly
67        # checking this.
68        return self.base_selector.select_grid(left_edge, right_edge, level, o)
69
70    def _hash_vals(self):
71        return (hash(self.base_selector), self.min_ind, self.max_ind)
72
73indexed_octree_subset_selector = IndexedOctreeSubsetSelector
74