def draw(self): with self.devices.frames[0] as deff: deff.clear(0, 0, 0, 1) deff.clear_depth() with self.devices.cameras[0] as cam: for pnt, (dx, dy) in zip(self._ref_pnts, ((1, 1), (-1, -1), (1, -1), (-1, 1))): a = 0.1 x, y = dx * a, dy * a pnt.geo = cam.tripod.plane.TM * gt.Pnt(x, y, -10) with self.devices.frames[1] as f: f.clear_depth() f.clear_texture(0, .5, .5, .5, 1) f.clear_texture(1, 0, 0, 0, 1) self.modeler.render() self.is_rendered = True with self.devices.panes[1] as p: self.devices.frames[1].render_pane_space_depth( 0, (0, 1, 0, 1), (-1, 1, -1, 1)) with self.devices.frames[1] as deff: # pos = p.cursor_pos(parameterize=True) goid, bitpattern = deff.pick_pixels(aid=1, pos=(.5, .5), size=(1, 1)) goid = goid[0][0] e = GIDP().get_registered_byvalue(goid, bitpattern) if e: print(goid, e)
def intersect(self, y): # calculate intersection if np.isclose(self.__low.y, y, atol=ATOL): i = self.__low elif np.isclose(self.__high.y, y, atol=ATOL): i = self.__high else: x = self.__gradient * (y - self.__low.y) + self.__low.x i = gt.Pnt(x, y, 0) return i
def __append_ending_edge(self, edge): if not self.__ending_edges: self.__ending_edges.append(edge) else: # maintain order e = self.__ending_edges[0] far_x = max(e.low.x, e.high.x) + 100 far_pnt = gt.Pnt(far_x, e.low.y, 0) if e.pnts_share_side(far_pnt, edge.low): self.__ending_edges.append(edge) else: self.__ending_edges.insert(0, edge)
def __append_starting_edge(self, edge): if not self.__starting_edges: self.__starting_edges.append(edge) else: e = self.__starting_edges[0] far_x = max(e.low.x, e.high.x) + 100 far_pnt = gt.Pnt(far_x, e.high.y, 0) if e.pnts_share_side(far_pnt, edge.high): self.__starting_edges.append(edge) else: self.__starting_edges.insert(0, edge)
def add_pnt(self, model, x, y, z) -> st.Pnt: """ add point :param x: Number, coordinate x :param y: Number, coordinate y :param z: Number, coordinate z :return: Pnt shape """ return self.__add_shape(model, args=(gt.Pnt(x, y, z), ), shape_type=st.Pnt)
def draw(self): if not self.num_scratch: self.ori = gt.Pnt(*(random.randint(-1500, 1500) for _ in range(2)), random.randint(-200, 200)) self.lin_vec = gt.Vec(*(random.uniform(-1, 1) for _ in range(2))).amplify(random.randint(200, 500)) self.offset_vec = gt.Vec.cross(gt.ZVec(), self.lin_vec).amplify(random.randint(10, 100)) self.num_scratch = random.randint(0, 25) self.thk = random.randint(2, 15) if self.fcount % 3 == 0: geo = gt.Lin.from_pnt_vec(self.ori + self.offset_vec * self.num_scratch, self.lin_vec) lin = self.modeler.add_raw(self.model, geo) lin.thk = self.thk self.num_scratch -= 1 self.fcount += 1 with self.devices.panes[0] as p: with self.devices.cameras[0] as c: p.clear(.5, .5, .5, 1) self.modeler.render()
def __edge_comparator(obj, sbj): # check side for inserting edge's vertex and far_x if obj is sbj: return 0 if obj.low == sbj.low and obj.high == sbj.high: return 0 far_pnt = gt.Pnt(far_x, obj.low.y, 0) is_same_side = sbj.pnts_share_side(obj.low, far_pnt) # object edge's vertex touches subject edge if is_same_side is None: if sbj.pnts_share_side(obj.high, far_pnt): return 1 else: return -1 elif is_same_side: # else search right, +1 return 1 else: # if side differs search left, -1 return -1
def pick_threshold(self): """ pick using texture pixel picking :return: picked, is picked an axis, closest point on the axis """ # pick goid goid = self.__id_picker.pick(pos=self.__cursor.pos_local, size=(1, 1))[0][0] goid = ClrRGBA(*goid).as_ubyte()[:3] entity = GIDP().get_registered(goid) idx = None for i, axis in enumerate(self.__axes): if entity == axis: idx = i break coord = self.__coord_picker.pick(self.__cursor.pos_global.astype(int), size=(1, 1))[0][0] return idx, gt.Pnt(*coord[:3])
import gkernel.dtype.geometric as gt l = gt.Lin([0, 0, 0], [10, 0, 0]) print(l.pnts_share_side(gt.Pnt(10, 10, 10), gt.Pnt(-10, -10, 0))) print(l.pnts_share_side(gt.Pnt(10, 10, 10), gt.Pnt(-10, 10, 0))) print(l.pnts_share_side(gt.Pnt(10, 10, 10), gt.Pnt(-10, 0, 0)))
def __stage_one(self, arr): """ four operations are executed within single loop 1. remove horizontal vertices 2. update far x 3. record edge vertices trapezoidation first stage 4. define vertex RBT 1. determine vertex category 2. determine sweep direction 3. create edge list :param arr: :return: """ arr = arr[:, :-1] def __vertex_comparator(obj, sbj): if np.isclose(obj.y, sbj.y, atol=ATOL): if np.isclose(obj.x, sbj.x, atol=ATOL): return 0 elif obj.x < sbj.x: return -1 else: return 1 elif obj.y < sbj.y: return -1 else: return 1 rb = RedBlackTree(comparator=__vertex_comparator) # sort by y,x far_x = -inf # find far x for further research vertices = deque([gt.Pnt(*coord) for coord in arr[:3].T]) edges, edge_vrtx = deque(), deque() while vertices: if not edges: a, b = vertices.popleft(), vertices[0] edges.append(self.__Edge(a, b)) edge_vrtx.append(a) continue this_vrtx = vertices.popleft() vrtx_next = vertices[0] if vertices else edge_vrtx[0] edge_next = self.__Edge(this_vrtx, vrtx_next) # 1. ignore horizontal if gt.Vec.cross(edges[-1].geo.as_vec(), edge_next.geo.as_vec()) == 0: # determine which vertex should become high low, _, high = sorted( (edges[-1].high, edges[-1].low, vrtx_next), key=lambda v: v.yx) edges[-1].low = low edges[-1].high = high else: edges.append(edge_next) edge_vrtx.append(this_vrtx) # 3. record edge vertex far_x = max(far_x, this_vrtx.x + 100) # 2. update far x # check last horizontal if gt.Vec.cross(edges[-1].geo.as_vec(), edges[0].geo.as_vec()) == 0: # determine which vertex should become high low, _, __, high = sorted( (edges[-1].high, edges[-1].low, edges[0].high, edges[0].low), key=lambda v: v.yx) edges[0].low = low edges[0].high = high edges.pop() edge_vrtx.popleft() edge_vrtx.appendleft(edge_vrtx.pop()) # 4. record trap vertex for i, v in enumerate(edge_vrtx): vrtx = self.__Vrtx(v) rb.insert(vrtx) pi, ni = i - 1, (i + 1) % len(edge_vrtx) vrtx.determine_cat_sweep(edge_vrtx[pi], v, edge_vrtx[ni], edges[pi], edges[i]) return rb, far_x, edge_vrtx