def extend(self, new_edge): """ Create a new <Paths> that contains path of current <Paths> which the new_edge if possible is appended to each :param new_edge: :return: """ new_output = [] if len(self) == 0: self.append(Path([])) for item in self: if item.addable(new_edge): path = Path() for edge in item: if edge.uri == new_edge.uri and \ edge.source_node.are_all_uris_generic() and \ edge.dest_node.are_all_uris_generic() and \ not ( new_edge.source_node.are_all_uris_generic() and new_edge.dest_node.are_all_uris_generic()): pass else: path.append(edge) new_output.append(Path(path + [new_edge])) else: new_output.append(item) return Paths(new_output)
def toPath(self, bid): block = self.blocks[bid] paths = [] path = Path(block.name()) self.initPath(bid) start = Vector(self.cnc.x, self.cnc.y) for line in block: cmds = self.cnc.parseLine(line) if cmds is None: continue self.cnc.processPath(cmds) end = Vector(self.cnc.xval, self.cnc.yval) if self.cnc.gcode == 0: # rapid move (new block) if path: paths.append(path) path = Path(block.name()) elif self.cnc.gcode == 1: # line if self.cnc.dx != 0.0 or self.cnc.dy != 0.0: path.append(Segment(1, start, end)) elif self.cnc.gcode in (2,3): # arc xc,yc,zc = self.cnc.motionCenter() center = Vector(xc,yc) phi = math.atan2(self.cnc.y-yc, self.cnc.x-xc) ephi = math.atan2(self.cnc.yval-yc, self.cnc.xval-xc) if self.cnc.gcode==2: if ephi<=phi+1e-10: ephi += 2.0*math.pi else: if ephi<=phi+1e-10: ephi += 2.0*math.pi path.append(Segment(self.cnc.gcode, start,end, center, self.cnc.rval, phi, ephi)) self.cnc.motionPathEnd() start = end if path: paths.append(path) return paths
def sample_path(self): it = self.sample_start_position(self.start_u_current) path = Path() path.append(it) theta = np.radians(self.start_angle_current) wo = [np.cos(theta), np.sin(theta)] if wo @ it.n < 0.0: return path while True: ray = Ray2f(it.p, wo) it = self.ray_intersect(ray) wi = -ray.d path.append(it) m = it.s * it.n_offset[0] + it.n * it.n_offset[1] if it.shape.type == Shape.Type.Reflection: if wi @ it.n < 0: break wo = reflect(wi, m) elif it.shape.type == Shape.Type.Refraction: wo = refract(wi, m, it.shape.eta) else: break if not wo[0]: break wo = wo[1] return path
def reproject_path_me(self, offset_vertices): path = Path() p0 = offset_vertices[0] t0 = self.cpp_scene.start_shape().project(p0) it = self.cpp_scene.start_shape().sample_position(t0) path.append(it) p1 = offset_vertices[1] wo = normalize(p1 - p0) while True: ray = Ray2f(it.p, wo) it = self.ray_intersect(ray) wi = -ray.d path.append(it) m = it.s * it.n_offset[0] + it.n * it.n_offset[1] if it.shape.type == Shape.Type.Reflection: if wi @ it.n < 0: break wo = reflect(wi, m) elif it.shape.type == Shape.Type.Refraction: wo = refract(wi, m, it.shape.eta) else: break if not wo[0]: break wo = wo[1] return path
def generate_paths(self, start, goal): """Begin generation of all paths beginning at the start and ending at the goal. Args: start: The beginning Coordinate. goal: The ending Coordinate. """ self.goal = goal path = Path() path.append(start) self._generate_paths(path)
def sample_seed_path(self, n_spec_bounces=1): path = Path() it1 = self.sample_start_position(self.start_u_current) it2 = self.sample_spec_position(self.spec_u_current) wo = normalize(it2.p - it1.p) if wo @ it1.n < 0.0: return path ray = Ray2f(it1.p, wo) it = self.ray_intersect(ray) if not it.is_valid() or (it.shape != it2.shape): return path it2 = it path.append(it1) path.append(it) while True: wi = -wo if len(path) - 1 >= n_spec_bounces: break m = it.s * it.n_offset[0] + it.n * it.n_offset[1] if it.shape.type == Shape.Type.Reflection: if wi @ it.n < 0: break wo = reflect(wi, m) elif it.shape.type == Shape.Type.Refraction: wo = refract(wi, m, it.shape.eta) else: print("Should not happen!!") break if not wo[0]: break wo = wo[1] ray = Ray2f(it.p, wo) it = self.ray_intersect(ray) if not (it.shape.type == Shape.Type.Reflection or it.shape.type == Shape.Type.Refraction): break path.append(it) it3 = self.sample_end_position(self.end_u_current) path.append(it3) if len(path) != n_spec_bounces + 2: return Path() return path
def sample_mnee_seed_path(self): path = Path() it1 = self.sample_start_position(self.start_u_current) it3 = self.sample_end_position(self.end_u_current) wo = normalize(it3.p - it1.p) if wo @ it1.n < 0.0: return path path.append(it1) it = it1 while True: ray = Ray2f(it.p, wo) it = self.ray_intersect(ray) if it.shape.type == Shape.Type.Reflection: break elif it.shape.type == Shape.Type.Refraction: pass else: break path.append(it) it3 = self.sample_end_position(self.end_u_current) path.append(it3) return path
def flood(self, p1, p2): idx1 = self.gf.idx(p1) idx2 = self.gf.idx(p2) self._flood_init(idx1, idx2) meeting_node_A, meeting_node_B = self._floodfill() path_idx = self._follow_path(meeting_node_A, meeting_node_B) path = Path() for idx in path_idx: coords_idx = self.gf.coords_idx(idx) coords = self.gf.coords(coords_idx) pot = self.gf.pot_1D[idx] has_nan_neighbor = False for neighbor in self.gf.neighbors_idx(idx): if np.isnan(self.gf.pot_1D[neighbor]): has_nan_neighbor = True break path.append(Point(coords_idx=coords_idx, coords=coords, pot=pot, has_nan_neighbor=has_nan_neighbor)) return path
# move 'th_text.csv' file into 'D:\\neural_image_assessment_master' directory df = pd.read_csv('th_text.csv') imagelist = df.video_id.unique() # after putting all thumbnail images into .\\image directory PATH_TO_TEST_IMAGES_DIR = 'image' TEST_IMAGE_PATHS = [ os.path.join(PATH_TO_TEST_IMAGES_DIR, '{i}.jpg'.format(i=i)) for i in imagelist ] import glob imgs = [] for img in glob.glob("image/*.jpg"): imgs.append(img) with tf.device('/CPU:0'): base_model = MobileNet((None, None, 3), alpha=1, include_top=False, pooling='avg', weights=None) x = Dropout(0.75)(base_model.output) x = Dense(10, activation='softmax')(x) model = Model(base_model.input, x) model.load_weights('weights/mobilenet_weights.h5') score_list = []
def parse_path(pathdef, current_pos=0j): # In the SVG specs, initial movetos are absolute, even if # specified as 'm'. This is the default behavior here as well. # But if you pass in a current_pos variable, the initial moveto # will be relative to that current_pos. This is useful. elements = list(_tokenize_path(pathdef)) # Reverse for easy use of .pop() elements.reverse() segments = Path() start_pos = None command = None while elements: if elements[-1] in COMMANDS: # New command. last_command = command # Used by S and T command = elements.pop() absolute = command in UPPERCASE command = command.upper() else: # If this element starts with numbers, it is an implicit command # and we don't change the command. Check that it's allowed: if command is None: raise ValueError("Unallowed implicit command in %s, position %s" % ( pathdef, len(pathdef.split()) - len(elements))) if command == 'M': # Moveto command. x = elements.pop() y = elements.pop() pos = float(x) + float(y) * 1j if absolute: current_pos = pos else: current_pos += pos # when M is called, reset start_pos # This behavior of Z is defined in svg spec: # http://www.w3.org/TR/SVG/paths.html#PathDataClosePathCommand start_pos = current_pos # Implicit moveto commands are treated as lineto commands. # So we set command to lineto here, in case there are # further implicit commands after this moveto. command = 'L' elif command == 'Z': # Close path if not (current_pos == start_pos): segments.append(Line(current_pos, start_pos)) segments.closed = True current_pos = start_pos start_pos = None command = None # You can't have implicit commands after closing. elif command == 'L': x = elements.pop() y = elements.pop() pos = float(x) + float(y) * 1j if not absolute: pos += current_pos segments.append(Line(current_pos, pos)) current_pos = pos elif command == 'H': x = elements.pop() pos = float(x) + current_pos.imag * 1j if not absolute: pos += current_pos.real segments.append(Line(current_pos, pos)) current_pos = pos elif command == 'V': y = elements.pop() pos = current_pos.real + float(y) * 1j if not absolute: pos += current_pos.imag * 1j segments.append(Line(current_pos, pos)) current_pos = pos elif command == 'C': control1 = float(elements.pop()) + float(elements.pop()) * 1j control2 = float(elements.pop()) + float(elements.pop()) * 1j end = float(elements.pop()) + float(elements.pop()) * 1j if not absolute: control1 += current_pos control2 += current_pos end += current_pos segments.append(CubicBezier(current_pos, control1, control2, end)) current_pos = end elif command == 'S': # Smooth curve. First control point is the "reflection" of # the second control point in the previous path. if last_command not in 'CS': # If there is no previous command or if the previous command # was not an C, c, S or s, assume the first control point is # coincident with the current point. control1 = current_pos else: # The first control point is assumed to be the reflection of # the second control point on the previous command relative # to the current point. control1 = current_pos + current_pos - segments[-1].control2 control2 = float(elements.pop()) + float(elements.pop()) * 1j end = float(elements.pop()) + float(elements.pop()) * 1j if not absolute: control2 += current_pos end += current_pos segments.append(CubicBezier(current_pos, control1, control2, end)) current_pos = end elif command == 'Q': control = float(elements.pop()) + float(elements.pop()) * 1j end = float(elements.pop()) + float(elements.pop()) * 1j if not absolute: control += current_pos end += current_pos segments.append(QuadraticBezier(current_pos, control, end)) current_pos = end elif command == 'T': # Smooth curve. Control point is the "reflection" of # the second control point in the previous path. if last_command not in 'QT': # If there is no previous command or if the previous command # was not an Q, q, T or t, assume the first control point is # coincident with the current point. control = current_pos else: # The control point is assumed to be the reflection of # the control point on the previous command relative # to the current point. control = current_pos + current_pos - segments[-1].control end = float(elements.pop()) + float(elements.pop()) * 1j if not absolute: end += current_pos segments.append(QuadraticBezier(current_pos, control, end)) current_pos = end elif command == 'A': radius = float(elements.pop()) + float(elements.pop()) * 1j rotation = float(elements.pop()) arc = float(elements.pop()) sweep = float(elements.pop()) end = float(elements.pop()) + float(elements.pop()) * 1j if not absolute: end += current_pos segments.append(Arc(current_pos, radius, rotation, arc, sweep, end)) current_pos = end return segments
def reproject_path_sms(self, offset_vertices, previous_path, n_spec_bounces=1): path = Path() p1 = offset_vertices[0] t1 = self.cpp_scene.start_shape().project(p1) it1 = self.cpp_scene.start_shape().sample_position(t1) p2 = offset_vertices[1] wo = normalize(p2 - p1) if wo @ it1.n < 0.0: return path ray = Ray2f(p1, wo) it2 = self.ray_intersect(ray) if it2.shape.id != self.cpp_scene.first_specular_shape().id: return path it2.n_offset = previous_path.vertices[1].n_offset path.append(it1) path.append(it2) it = it2 while True: wi = -wo if len(path) - 1 >= n_spec_bounces: break m = it.s * it.n_offset[0] + it.n * it.n_offset[1] if it.shape.type == Shape.Type.Reflection: if wi @ it.n < 0: break wo = reflect(wi, m) elif it.shape.type == Shape.Type.Refraction: wo = refract(wi, m, it.shape.eta) else: print("Should not happen!!") break if not wo[0]: break wo = wo[1] ray = Ray2f(it.p, wo) it = self.ray_intersect(ray) if not (it.shape.type == Shape.Type.Reflection or it.shape.type == Shape.Type.Refraction): break if len(path) > len(previous_path): break it.n_offset = previous_path.vertices[len(path)].n_offset path.append(it) it3 = self.sample_end_position(self.end_u_current) path.append(it3) if len(path) != n_spec_bounces + 2: return Path() return path