Example #1
0
 def calc_vector_dimensions(self):
     relative_translation = self.shortest_vector_relative_to(self.parent)
     if relative_translation is None:
         self.length = 0
     else:
         self.length = numpy.sqrt(numpy.dot(relative_translation, relative_translation))
         if self.length > 0:
             t = self.children[0].translation_relative_to(self.parent)
             c = relative_translation[2] / self.length
             if c >= 1.0:
                 self.orientation = Translation(t)
             elif c <= -1.0:
                 alpha = numpy.pi
                 axis = numpy.array([1.0, 0.0, 0.0])
                 self.orientation = Complete.from_properties(alpha, axis, False, t)
             else:
                 x, y = relative_translation[0], relative_translation[1]
                 if abs(x) < abs(y):
                     signy = {True: 1, False: -1}[y >= 0]
                     a = -signy
                     b = signy * x / y
                 else:
                     signx = {True: 1, False: -1}[x >= 0]
                     a = -signx * y / x
                     b = signx
                 alpha = numpy.arccos(c)
                 axis = numpy.array([a, b, 0.0])
                 self.orientation = Complete.from_properties(alpha, axis, False, t)
Example #2
0
 def calc_vector_dimensions(self):
     relative_translation = self.shortest_vector_relative_to(self.parent)
     if relative_translation is None:
         self.length = 0
     else:
         self.length = numpy.sqrt(
             numpy.dot(relative_translation, relative_translation))
         if self.length > 0:
             t = self.children[0].translation_relative_to(self.parent)
             c = relative_translation[2] / self.length
             if c >= 1.0:
                 self.orientation = Translation(t)
             elif c <= -1.0:
                 alpha = numpy.pi
                 axis = numpy.array([1.0, 0.0, 0.0])
                 self.orientation = Complete.from_properties(
                     alpha, axis, False, t)
             else:
                 x, y = relative_translation[0], relative_translation[1]
                 if abs(x) < abs(y):
                     signy = {True: 1, False: -1}[y >= 0]
                     a = -signy
                     b = signy * x / y
                 else:
                     signx = {True: 1, False: -1}[x >= 0]
                     a = -signx * y / x
                     b = signx
                 alpha = numpy.arccos(c)
                 axis = numpy.array([a, b, 0.0])
                 self.orientation = Complete.from_properties(
                     alpha, axis, False, t)
Example #3
0
 def get_parentframe_up_to(self, upper_parent):
     if not isinstance(self.parent, GLMixin):
         assert upper_parent is None, "upper_parent must be (an indirect) parent of self."
         return Complete.identity()
     elif self.parent == upper_parent:
         return Complete.identity()
     else:
         return self.parent.get_frame_up_to(upper_parent)
Example #4
0
 def get_parentframe_up_to(self, upper_parent):
     if not isinstance(self.parent, GLMixin):
         assert upper_parent is None, "upper_parent must be (an indirect) parent of self."
         return Complete.identity()
     elif self.parent == upper_parent:
         return Complete.identity()
     else:
         return self.parent.get_frame_up_to(upper_parent)
Example #5
0
 def initnonstate(self):
     GLReferentBase.initnonstate(self)
     self.orientation = Complete.identity()
     self.set_children([
         SpatialReference(prefix="Begin"),
         SpatialReference(prefix="End")
     ])
Example #6
0
 def get_frame_up_to(self, upper_parent):
     if upper_parent == self:
         return Complete.identity()
     elif self.parent == upper_parent:
         return self.transformation
     else:
         return self.get_parentframe_up_to(upper_parent) * self.transformation
Example #7
0
 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()
Example #8
0
 def get_frame_up_to(self, upper_parent):
     if (upper_parent == self):
         return Complete.identity()
     elif (self.parent == upper_parent):
         return self.transformation
     else:
         return self.get_parentframe_up_to(
             upper_parent) * self.transformation
Example #9
0
    def do(self):
        transformation = Complete.about_axis(
            self.parameters.center,
            numpy.pi,
            self.parameters.normal,
            True
        )

        for victim in context.application.cache.translated_nodes:
            primitive.Transform(victim, transformation)
Example #10
0
    def do(self):
        cache = context.application.cache
        for node in cache.nodes:
            translated_children = []
            for child in node.children:
                if isinstance(child, GLTransformationMixin) and isinstance(
                        child.transformation, Translation):
                    if child.get_fixed():
                        translated_children = []
                        break
                    translated_children.append(child)
            if len(translated_children) == 0:
                continue

            mass, com = compute_center_of_mass(iter_particles(node))
            if mass == 0.0:
                continue

            tensor = compute_inertia_tensor(iter_particles(node), com)
            transformation = Complete(align_rotation_matrix(tensor), com)
            CenterAlignBase.do(self, node, translated_children, transformation)
Example #11
0
 def update_gui(self):
     if self.status is not None:
         self.la_num_iter.set_text("%i" % self.status.step)
         self.la_rms_error.set_text(
             express_measure(
                 numpy.sqrt(self.status.value / self.num_springs),
                 "Length"))
         self.progress_bar.set_text("%i%%" %
                                    int(self.status.progress * 100))
         self.progress_bar.set_fraction(self.status.progress)
         for state_index, frame, variable in zip(
                 self.state_indices, self.involved_frames,
                 self.minimize.root_expression.state_variables):
             if isinstance(variable, iterative.var.Frame):
                 r, t = variable.extract_state(state_index,
                                               self.status.state)
                 frame.set_transformation(Complete(r, t))
             elif isinstance(variable, iterative.var.Translation):
                 t = variable.extract_state(state_index, self.status.state)
                 new_transformation = frame.transformation.copy_with(t=t)
                 frame.set_transformation(new_transformation)
         context.application.main.drawing_area.queue_draw()
Example #12
0
 def get_frame_up_to(self, upper_parent):
     if (upper_parent == self) or (self.parent == upper_parent):
         return Complete.identity()
     else:
         return self.get_parentframe_up_to(upper_parent)
Example #13
0
 def get_absolute_parentframe(self):
     if not isinstance(self.parent, GLMixin):
         return Complete.identity()
     else:
         return self.parent.get_absolute_frame()
Example #14
0
 def initnonstate(self):
     GLReferentBase.initnonstate(self)
     self.orientation = Complete.identity()
     self.set_children(
         [SpatialReference(prefix="Begin"),
          SpatialReference(prefix="End")])
Example #15
0
    def do(self):
        transformation = Complete.about_axis(self.parameters.center, numpy.pi,
                                             self.parameters.normal, True)

        for victim in context.application.cache.translated_nodes:
            primitive.Transform(victim, transformation)
Example #16
0
 def get_frame_up_to(self, upper_parent):
     if (upper_parent == self) or (self.parent == upper_parent):
         return Complete.identity()
     else:
         return self.get_parentframe_up_to(upper_parent)
Example #17
0
    def endElement(self, name):
        if name == "zml_file": return
        # now that we have gatherd all information of this tag, create an appropriate object

        # first find the tags involved in this operation
        current_tag = self.hierarchy[-1][-1]
        child_tags = []
        if not current_tag.being_processed:
            current_tag = self.hierarchy[-2][-1]
            child_tags = self.hierarchy[-1]

        # do it
        if name == "str": current_tag.value = str(current_tag.content)
        elif name == "float": current_tag.value = float(current_tag.content)
        elif name == "int": current_tag.value = int(current_tag.content)
        elif name == "bool":
            temp = current_tag.content.lower().strip()
            if temp == 'true': current_tag.value = True
            else: current_tag.value = False
        elif name == "list": current_tag.value = [tag.value for tag in child_tags]
        elif name == "dict": current_tag.value = dict((tag.label, tag.value) for tag in child_tags)
        elif name == "tuple": current_tag.value = tuple(tag.value for tag in child_tags)
        elif name == "shape":
            current_tag.value = tuple(int(item) for item in current_tag.content.split())
        elif name == "cells":
            current_tag.value = numpy.array([eval(item) for item in current_tag.content.split()])
        elif name == "array":
            child_dict = dict((tag.name, tag.value) for tag in child_tags)
            current_tag.value = numpy.reshape(child_dict["cells"], child_dict["shape"])
        elif name == "grid":
            current_tag.value = numpy.reshape(numpy.array([eval(item) for item in current_tag.content.split()]), (int(current_tag.attributes["rows"]), int(current_tag.attributes["cols"]), -1))
        elif name == "binary":
            current_tag.value = StringIO.StringIO()
            current_tag.content.seek(0)
            base64.decode(current_tag.content, current_tag.value)
        elif name == "translation":
            current_tag.value = Translation(child_tags[0].value)
        elif name == "rotation":
            current_tag.value = Rotation(child_tags[0].value)
        elif name == "transformation":
            child_dict = dict((tag.label, tag.value) for tag in child_tags)
            current_tag.value = Complete(
                child_dict["rotation_matrix"],
                child_dict["translation_vector"],
            )
        elif name == "unit_cell":
            child_dict = dict((tag.label, tag.value) for tag in child_tags)
            current_tag.value = UnitCell(
                child_dict["matrix"],
                child_dict["active"],
            )
        elif name == "expression":
            current_tag.value = Expression(current_tag.content)
        elif name == "reference":
            current_tag.value = None
            referent_tag = self.hierarchy[-3][-1]
            target_ids = self.target_ids.get(referent_tag)
            if target_ids is None:
                target_ids = []
                self.target_ids[referent_tag] = target_ids
            target_ids.append(int(current_tag.attributes["to"]))
        elif name == "model_object":
            Class = context.application.plugins.get_node(str(current_tag.attributes["class"]))
            current_tag.state = dict((tag.label, tag.value) for tag in child_tags)
            current_tag.value = Class()
            self.model_object_tags[int(current_tag.attributes["id"])] = current_tag
        else: pass

        # close the door
        current_tag.content = None
        current_tag.close()
        if len(child_tags) > 0: self.hierarchy.pop()
Example #18
0
 def convert_to_value(self, representation):
     properties = (ComposedInTable.convert_to_value(self.fields[0],
                                                    representation[0]) +
                   (ComposedArray.convert_to_value(self.fields[1],
                                                   representation[1]), ))
     return MathComplete.from_properties(*properties)
Example #19
0
 def get_absolute_parentframe(self):
     if not isinstance(self.parent, GLMixin):
         return Complete.identity()
     else:
         return self.parent.get_absolute_frame()
Example #20
0
 def convert_to_value(self, representation):
     properties = (
         ComposedInTable.convert_to_value(self.fields[0], representation[0]) +
         (ComposedArray.convert_to_value(self.fields[1], representation[1]),)
     )
     return MathComplete.from_properties(*properties)