Exemplo n.º 1
0
 def add_rotation(
     self,
     axis: QVector3D,
     angle: float,
     name: str = None,
     depends_on: Transformation = None,
 ) -> Transformation:
     """
     Note, currently assumes angle is in degrees
     :param axis: axis
     :param angle:
     :param name: Name of the rotation group (Optional)
     :param depends_on: existing transformation which the new one depends on (otherwise relative to origin)
     """
     transforms_group = self.file.create_transformations_group_if_does_not_exist(
         self.group)
     if name is None:
         name = _generate_incremental_name(TransformationType.ROTATION,
                                           transforms_group)
     field = self.file.set_field_value(transforms_group, name, angle, float)
     self.file.set_attribute_value(field, CommonAttrs.UNITS, "degrees")
     self.file.set_attribute_value(field, CommonAttrs.VECTOR,
                                   qvector3d_to_numpy_array(axis))
     self.file.set_attribute_value(field, CommonAttrs.TRANSFORMATION_TYPE,
                                   TransformationType.ROTATION)
     rotation_transform = Transformation(self.file, field)
     rotation_transform.depends_on = depends_on
     rotation_transform.ui_value = angle
     return rotation_transform
Exemplo n.º 2
0
    def add_translation(self,
                        vector: QVector3D,
                        name: str = None,
                        depends_on: Transformation = None) -> Transformation:
        """
        Note, currently assumes translation is in metres
        :param vector: direction and magnitude of translation as a 3D vector
        :param name: name of the translation group (Optional)
        :param depends_on: existing transformation which the new one depends on (otherwise relative to origin)
        """
        transforms_group = self.file.create_transformations_group_if_does_not_exist(
            self.group)
        if name is None:
            name = _generate_incremental_name(TransformationType.TRANSLATION,
                                              transforms_group)
        unit_vector, magnitude = _normalise(vector)
        field = self.file.set_field_value(transforms_group, name, magnitude,
                                          float)
        self.file.set_attribute_value(field, CommonAttrs.UNITS, "m")
        self.file.set_attribute_value(field, CommonAttrs.VECTOR,
                                      qvector3d_to_numpy_array(unit_vector))
        self.file.set_attribute_value(field, CommonAttrs.TRANSFORMATION_TYPE,
                                      TransformationType.TRANSLATION)

        translation_transform = Transformation(self.file, field)
        translation_transform.ui_value = magnitude
        translation_transform.depends_on = depends_on
        return translation_transform
Exemplo n.º 3
0
 def refresh_depends_on(_, node):
     """
     Refresh the depends_on attribute of each transformation, which also results in registering dependents
     """
     if isinstance(node, h5py.Group):
         if CommonAttrs.NX_CLASS in node.attrs.keys():
             if node.attrs[CommonAttrs.NX_CLASS] == "NXtransformations":
                 for transformation_name in node:
                     transform = Transformation(
                         self.nexus, node[transformation_name]
                     )
                     transform.depends_on = transform.depends_on