def set_transformation(self, transformation, init=False): if not transformation.__class__ == self.Transformation: # create an object of the proper type and take only the attributes # of interest. if isinstance(transformation, Translation): t = transformation.t else: t = None if isinstance(transformation, Rotation): r = transformation.r else: r = None if self.Transformation == Translation: if t is None: transformation = Translation.identity() else: transformation = Translation(t) elif self.Transformation == Rotation: if r is None: transformation = Rotation.identity() else: transformation = Rotation(r) else: # self.Transformation == Complete: if r is None: r = numpy.identity(3, float) if t is None: t = numpy.zeros(3, float) transformation = Complete(r, t) self.transformation = transformation if not init: self.invalidate_transformation_list()
def ask_parameters(self): cache = context.application.cache nodes = cache.nodes last = cache.last next_to_last = cache.next_to_last if isinstance(last, Vector): if (len(nodes) >= 2) and isinstance(next_to_last, Vector): parent = nodes[-2].parent b1 = last.children[0].translation_relative_to(parent) e1 = last.children[1].translation_relative_to(parent) b2 = next_to_last.children[0].translation_relative_to(parent) e2 = next_to_last.children[1].translation_relative_to(parent) if (b1 is not None) and (e1 is not None) and (b2 is not None) and (e2 is not None): angle = compute_angle(e1 - b1, e2 - b2) axis = numpy.cross(e1 - b1, e2 - b2) self.parameters.center = Translation(0.5*(b1+b2)) self.parameters.rotation = Rotation.from_properties(angle, axis, False) else: parent = next_to_last.parent b = last.children[0].translation_relative_to(parent) e = last.children[1].translation_relative_to(parent) if (b is not None) and (e is not None): self.parameters.center = Translation(b) self.parameters.rotation = Rotation.from_properties(numpy.pi*0.25, e - b, False) elif isinstance(last, GLTransformationMixin) and isinstance(last.transformation, Translation): parent = last.parent self.parameters.center = Translation(last.get_frame_relative_to(parent).t) self.parameters.rotation = Rotation.identity() else: self.parameters.center = Translation(calculate_center(cache.translations)) if self.parameters_dialog.run(self.parameters) != gtk.RESPONSE_OK: self.parameters.clear()
def set_transformation(self, transformation, init=False): if not transformation.__class__ == self.Transformation: # create an object of the proper type and take only the attributes # of interest. if isinstance(transformation, Translation): t = transformation.t else: t = None if isinstance(transformation, Rotation): r = transformation.r else: r = None if self.Transformation == Translation: if t is None: transformation = Translation.identity() else: transformation = Translation(t) elif self.Transformation == Rotation: if r is None: transformation = Rotation.identity() else: transformation = Rotation(r) else: # self.Transformation == Complete: if r is None: r = numpy.identity(3, float) if t is None: t = numpy.zeros(3, float) transformation = Complete(r, t) self.transformation = transformation if not init: self.invalidate_transformation_list()
def reset(self): config = context.application.configuration self.rotation_center = Translation.identity() self.rotation = Rotation.identity() self.eye = Translation([0,0,config.viewer_distance]) self.opening_angle = config.opening_angle self.window_size = config.window_size self.window_depth = config.window_depth
def reset(self): config = context.application.configuration self.rotation_center = Translation.identity() self.rotation = Rotation.identity() self.eye = Translation([0, 0, config.viewer_distance]) self.opening_angle = config.opening_angle self.window_size = config.window_size self.window_depth = config.window_depth
def ask_parameters(self): cache = context.application.cache nodes = cache.nodes last = cache.last next_to_last = cache.next_to_last if isinstance(last, Vector): if (len(nodes) >= 2) and isinstance(next_to_last, Vector): parent = nodes[-2].parent b1 = last.children[0].translation_relative_to(parent) e1 = last.children[1].translation_relative_to(parent) b2 = next_to_last.children[0].translation_relative_to(parent) e2 = next_to_last.children[1].translation_relative_to(parent) if (b1 is not None) and (e1 is not None) and ( b2 is not None) and (e2 is not None): angle = compute_angle(e1 - b1, e2 - b2) axis = numpy.cross(e1 - b1, e2 - b2) self.parameters.center = Translation(0.5 * (b1 + b2)) self.parameters.rotation = Rotation.from_properties( angle, axis, False) else: parent = next_to_last.parent b = last.children[0].translation_relative_to(parent) e = last.children[1].translation_relative_to(parent) if (b is not None) and (e is not None): self.parameters.center = Translation(b) self.parameters.rotation = Rotation.from_properties( numpy.pi * 0.25, e - b, False) elif isinstance(last, GLTransformationMixin) and isinstance( last.transformation, Translation): parent = last.parent self.parameters.center = Translation( last.get_frame_relative_to(parent).t) self.parameters.rotation = Rotation.identity() else: self.parameters.center = Translation( calculate_center(cache.translations)) if self.parameters_dialog.run(self.parameters) != gtk.RESPONSE_OK: self.parameters.clear()
def do(self): cache = context.application.cache geometry_nodes = [[], []] def get_parameters(node, point_type, geometry_index, filter_expression, radius_expression): template = "An exception occured in the %%s expression\nfor the %s points of geometry %i." % ( point_type, geometry_index + 1) try: is_type = filter_expression(node) except Exception: raise UserError(template % "filter") if is_type: try: radius = radius_expression(node) except Exception: raise UserError(template % "radius") geometry_nodes[geometry_index].append(node) return True, radius else: return False, None def read_geometry(frame, geometry_index, connect_description, repulse_description): coordinates = [] connect_masks = [] radii = [] for child in frame.children: if isinstance(child, GLTransformationMixin) and \ isinstance(child.transformation, Translation): is_connect, radius = get_parameters( child, "connecting", geometry_index, *connect_description) if is_connect: coordinates.append(child.transformation.t) connect_masks.append(True) radii.append(radius) else: is_repulse, radius = get_parameters( child, "repulsive", geometry_index, *repulse_description) if is_repulse: coordinates.append(child.transformation.t) connect_masks.append(False) radii.append(radius) return Geometry( numpy.array(coordinates, float), numpy.array(connect_masks, bool), numpy.array(radii, float), ) inp = {} inp["geometry1"] = read_geometry(cache.nodes[0], 0, self.parameters.connect_description1, self.parameters.repulse_description1) if len(cache.nodes) == 2: inp["geometry2"] = read_geometry( cache.nodes[1], 1, self.parameters.connect_description2, self.parameters.repulse_description2) else: inp["geometry2"] = None inp["action_radius"] = self.parameters.action_radius inp["hit_tolerance"] = self.parameters.hit_tolerance if not isinstance(self.parameters.allow_inversions, Undefined): inp["allow_rotations"] = True inp["allow_inversions"] = self.parameters.allow_inversions inp["minimum_triangle_area"] = self.parameters.minimum_triangle_size**2 else: inp["allow_rotations"] = False if isinstance(self.parameters.rotation2, Undefined): inp["rotation2"] = Rotation.identity() else: inp["rotation2"] = self.parameters.rotation2 if inp["allow_rotations"]: connections = self.triangle_report_dialog.run(inp) else: connections = self.pair_report_dialog.run(inp) if connections is not None and len(connections) > 0: if len(cache.nodes) == 1: frame1 = cache.nodes[0] Duplicate = context.application.plugins.get_action("Duplicate") Duplicate() frame2 = cache.nodes[0] geometry_nodes[1] = geometry_nodes[0] else: frame1, frame2 = cache.nodes conscan_results = ConscanResults( targets=[frame1, frame2], connections=[( float(connection.quality), connection.transformation, [(geometry_nodes[0][first].get_index(), geometry_nodes[1][second].get_index()) for first, second in connection.pairs], [(geometry_nodes[0][second].get_index(), geometry_nodes[1][first].get_index()) for first, second in connection.pairs if connection.invertible], ) for connection in connections], ) primitive.Add(conscan_results, context.application.model.folder)
def default_parameters(cls): result = Parameters() result.center = Translation.identity() result.rotation = Rotation.identity() return result
def do(self): cache = context.application.cache geometry_nodes = [[], []] def get_parameters(node, point_type, geometry_index, filter_expression, radius_expression): template = "An exception occured in the %%s expression\nfor the %s points of geometry %i." % (point_type, geometry_index+1) try: is_type = filter_expression(node) except Exception: raise UserError(template % "filter") if is_type: try: radius = radius_expression(node) except Exception: raise UserError(template % "radius") geometry_nodes[geometry_index].append(node) return True, radius else: return False, None def read_geometry(frame, geometry_index, connect_description, repulse_description): coordinates = [] connect_masks = [] radii = [] for child in frame.children: if isinstance(child, GLTransformationMixin) and \ isinstance(child.transformation, Translation): is_connect, radius = get_parameters( child, "connecting", geometry_index, *connect_description ) if is_connect: coordinates.append(child.transformation.t) connect_masks.append(True) radii.append(radius) else: is_repulse, radius = get_parameters( child, "repulsive", geometry_index, *repulse_description ) if is_repulse: coordinates.append(child.transformation.t) connect_masks.append(False) radii.append(radius) return Geometry( numpy.array(coordinates, float), numpy.array(connect_masks, bool), numpy.array(radii, float), ) inp = {} inp["geometry1"] = read_geometry(cache.nodes[0], 0, self.parameters.connect_description1, self.parameters.repulse_description1) if len(cache.nodes) == 2: inp["geometry2"] = read_geometry(cache.nodes[1], 1, self.parameters.connect_description2, self.parameters.repulse_description2) else: inp["geometry2"] = None inp["action_radius"] = self.parameters.action_radius inp["hit_tolerance"] = self.parameters.hit_tolerance if not isinstance(self.parameters.allow_inversions, Undefined): inp["allow_rotations"] = True inp["allow_inversions"] = self.parameters.allow_inversions inp["minimum_triangle_area"] = self.parameters.minimum_triangle_size**2 else: inp["allow_rotations"] = False if isinstance(self.parameters.rotation2, Undefined): inp["rotation2"] = Rotation.identity() else: inp["rotation2"] = self.parameters.rotation2 if inp["allow_rotations"]: connections = self.triangle_report_dialog.run(inp) else: connections = self.pair_report_dialog.run(inp) if connections is not None and len(connections) > 0: if len(cache.nodes) == 1: frame1 = cache.nodes[0] Duplicate = context.application.plugins.get_action("Duplicate") Duplicate() frame2 = cache.nodes[0] geometry_nodes[1] = geometry_nodes[0] else: frame1, frame2 = cache.nodes conscan_results = ConscanResults( targets=[frame1, frame2], connections=[( float(connection.quality), connection.transformation, [ (geometry_nodes[0][first].get_index(), geometry_nodes[1][second].get_index()) for first, second in connection.pairs ], [ (geometry_nodes[0][second].get_index(), geometry_nodes[1][first].get_index()) for first, second in connection.pairs if connection.invertible ], ) for connection in connections], ) primitive.Add(conscan_results, context.application.model.folder)
def default_parameters(cls): result = Parameters() result.center = Translation.identity() result.rotation = Rotation.identity() return result