From 9ffe0cecd43c916746ac4627a6b6ee6e21f01946 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?P=C3=A5l=20Gr=C3=B8n=C3=A5s=20Drange?= Date: Wed, 5 Apr 2017 10:51:18 +0200 Subject: [PATCH] removed select_halfspace and use only de/select above/below --- python/python/ert/geo/geo_region.py | 50 ++++++++++++++--------------- 1 file changed, 24 insertions(+), 26 deletions(-) diff --git a/python/python/ert/geo/geo_region.py b/python/python/ert/geo/geo_region.py index 39b69e502c..648a0dabc7 100644 --- a/python/python/ert/geo/geo_region.py +++ b/python/python/ert/geo/geo_region.py @@ -45,31 +45,21 @@ def __init__(self, pointset, preselect=False): super(GeoRegion, self).__init__(c_ptr) else: raise ValueError('Could not construct GeoRegion from pointset %s.' % pointset) - self.select_polygon_fn = { - (True, True): self._select_inside_polygon, - (False, True): self._select_outside_polygon, - (True, False): self._deselect_inside_polygon, - (False, False): self._deselect_outside_polygon - } - self.select_halfspace_fn = { - (True, True): self._select_above_line, - (False, True): self._select_below_line, - (True, False): self._deselect_above_line, - (False, False): self._deselect_below_line - } def getActiveList(self): return self._get_index_list() - def select_polygon(self, polygon, inside=True, select=True): + def _assert_polygon(self, polygon): if not isinstance(polygon, CPolyline): raise ValueError('Need to select with a CPolyline, not %s.' % type(polygon)) - selector_fn = self.select_polygon_fn[(inside, select)] - selector_fn(polygon) - def select_halfspace(self, line, above=True, select=True): + + def _construct_cline(self, line): + """Takes a line ((x1,y1), (x2,y2)) and returns two double[2]* but + reordered to (x1x2, y1y2). + """ try: p1, p2 = line x1, y1 = map(float, p1) @@ -79,33 +69,41 @@ def select_halfspace(self, line, above=True, select=True): raise ValueError(err_msg % (line, err)) x1x2_ptr = cpair(x1, x2) y1y2_ptr = cpair(y1, y2) - selector_fn = self.select_halfspace_fn[(above, select)] - selector_fn(x1x2_ptr, y1y2_ptr) # note that it takes xx, yy + return x1x2_ptr, y1y2_ptr + def select_inside(self, polygon): - self.select_polygon(polygon, inside=True, select=True) + self._assert_polygon(polygon) + self._select_inside_polygon(polygon) def select_outside(self, polygon): - self.select_polygon(polygon, inside=False, select=True) + self._assert_polygon(polygon) + self._select_outside_polygon(polygon) def deselect_inside(self, polygon): - self.select_polygon(polygon, inside=True, select=False) + self._assert_polygon(polygon) + self._deselect_inside_polygon(polygon) def deselect_outside(self, polygon): - self.select_polygon(polygon, inside=False, select=False) + self._assert_polygon(polygon) + self._deselect_outside_polygon(polygon) def select_above(self, line): - self.select_halfspace(line, above=True, select=True) + x_ptr, y_ptr = self._construct_cline(line) + self._select_above_line(x_ptr, y_ptr) def select_below(self, line): - self.select_halfspace(line, above=False, select=True) + x_ptr, y_ptr = self._construct_cline(line) + self._select_below_line(x_ptr, y_ptr) def deselect_above(self, line): - self.select_halfspace(line, above=True, select=False) + x_ptr, y_ptr = self._construct_cline(line) + self._deselect_above_line(x_ptr, y_ptr) def deselect_below(self, line): - self.select_halfspace(line, above=False, select=False) + x_ptr, y_ptr = self._construct_cline(line) + self._deselect_below_line(x_ptr, y_ptr) def __len__(self):