def rotate_scaffold(self, angle, value):
     next_angle_value = value
     if angle == 'yaw':
         if next_angle_value > self._current_angle_value[0]:
             angle_value = next_angle_value - self._current_angle_value[0]
         else:
             angle_value = -(self._current_angle_value[0] - next_angle_value)
         euler_angles = [angle_value, 0., 0.]
         self._current_angle_value[0] = next_angle_value
         self._settings['yaw'] = next_angle_value
     elif angle == 'pitch':
         if next_angle_value > self._current_angle_value[1]:
             angle_value = next_angle_value - self._current_angle_value[1]
         else:
             angle_value = -(self._current_angle_value[1] - next_angle_value)
         euler_angles = [0., angle_value, 0.]
         self._current_angle_value[1] = next_angle_value
         self._settings['pitch'] = next_angle_value
     else:
         if next_angle_value > self._current_angle_value[2]:
             angle_value = next_angle_value - self._current_angle_value[2]
         else:
             angle_value = -(self._current_angle_value[2] - next_angle_value)
         euler_angles = [0., 0., angle_value]
         self._current_angle_value[2] = next_angle_value
         self._settings['roll'] = next_angle_value
     angles = euler_angles
     angles = [radians(x) for x in angles]
     rotation = maths.eulerToRotationMatrix3(angles)
     zincutils.transform_coordinates(self._scaffold_coordinate_field, rotation)
     self._apply_callback()
 def rotateModel(self, axis, angle):
     quat = vectorops.axisAngleToQuaternion(axis, angle)
     mat1 = vectorops.rotmx(quat)
     mat2 = vectorops.eulerToRotationMatrix3(self._alignSettings['euler_angles'])
     newmat = vectorops.mxmult(mat1, mat2)
     self._alignSettings['euler_angles'] = vectorops.rotationMatrix3ToEuler(newmat)
     self._applyAlignSettings()
 def _applyAlignSettings(self):
     rot = vectorops.eulerToRotationMatrix3(
         self._alignSettings['euler_angles'])
     scale = self._alignSettings['scale']
     xScale = scale[0]
     yScale = scale[1]
     zScale = scale[2]
     # if self.isAlignMirror():
     #     xScale = -scale
     rotationScale = [
         rot[0][0] * xScale, rot[0][1] * yScale, rot[0][2] * zScale,
         rot[1][0] * xScale, rot[1][1] * yScale, rot[1][2] * zScale,
         rot[2][0] * xScale, rot[2][1] * yScale, rot[2][2] * zScale
     ]
     offset_vector = self._alignSettings['offset']
     transformation_matrix = [
         rotationScale[0], rotationScale[1], rotationScale[2],
         offset_vector[0], rotationScale[3], rotationScale[4],
         rotationScale[5], offset_vector[1], rotationScale[6],
         rotationScale[7], rotationScale[8], offset_vector[2], 0.0, 0.0,
         0.0, 1.0
     ]
     self._scene.setTransformationMatrix(transformation_matrix)
     if self._alignSettingsChangeCallback is not None:
         self._alignSettingsChangeCallback()
 def getPlaneInfo(self):
     original_up = [0.0, 1.0, 0.0]
     original_normal = [0.0, 0.0, 1.0]
     euler_angles = self.getAlignEulerAngles()
     offset = self.getAlignOffset()
     rot = vectorops.eulerToRotationMatrix3(euler_angles)
     normal = vectorops.mxvectormult(rot, original_normal)
     up = vectorops.mxvectormult(rot, original_up)
     return normal, up, offset
Example #5
0
    def getPoints(cls, options):
        """
        Get point coordinates and derivatives for the arterial valve ring.
        Optional extra parameters allow origin and orientation to be set.
        :param options: Dict containing options. See getDefaultOptions().
        :return: x, d1, d2, d3 all indexed by [n3=wall][n2=inlet->outlet][n1=around] where
        d1 is around, d2 is in direction inlet->outlet.
        d3 is radial and undefined at n2 == 1.
         """
        unitScale = options['Unit scale']
        innerRadius = unitScale * 0.5 * options['Inner diameter']
        innerRadialDisplacement = unitScale * options[
            'Inner radial displacement']
        innerSinusRadialDisplacement = unitScale * options[
            'Inner sinus radial displacement']
        outerAngleRadians = math.radians(options['Outer angle degrees'])
        outerHeight = unitScale * options['Outer height']
        outerRadialDisplacement = unitScale * options[
            'Outer radial displacement']
        outerSinusRadialDisplacement = unitScale * options[
            'Outer sinus radial displacement']
        outletLength = unitScale * options['Outlet length']
        sinusAngleRadians = math.radians(options['Sinus angle degrees'])
        sinusDepth = unitScale * options['Sinus depth']
        wallThickness = unitScale * options['Wall thickness']
        rotationAzimuthRadians = math.radians(
            options['Rotation azimuth degrees'])
        rotationElevationRadians = math.radians(
            options['Rotation elevation degrees'])
        rotationRollRadians = math.radians(options['Rotation roll degrees'])
        centre = [
            unitScale * options['Translation x'],
            unitScale * options['Translation y'],
            unitScale * options['Translation z']
        ]
        outerRadius = innerRadius + wallThickness
        innerInletRadius = innerRadius + innerRadialDisplacement
        innerInletSinusRadius = innerRadius + innerSinusRadialDisplacement

        elementsCountAround = 6  # fixed
        radiansPerElementAround = 2.0 * math.pi / elementsCountAround
        pi_3 = radiansPerElementAround

        #centre = [ 0.0, 0.0, 0.0 ]
        #axis1 = [ 1.0, 0.0, 0.0 ]
        #axis2 = [ 0.0, 1.0, 0.0 ]
        #axis3 = vector.crossproduct3(axis1, axis2)
        axis1, axis2, axis3 = eulerToRotationMatrix3([
            rotationAzimuthRadians, rotationElevationRadians,
            rotationRollRadians
        ])

        x = [[None, None], [None, None]]
        d1 = [[None, None], [None, None]]
        d2 = [[None, None], [None, None]]
        d3 = [[None, None], [None, None]]

        # inlet
        # inner layer, with sinuses
        outletz = outerHeight
        inletz = outletz - outletLength
        sinusz = -sinusDepth
        outletCentre = [(centre[c] + outletz * axis3[c]) for c in range(3)]
        inletCentre = [(centre[c] + inletz * axis3[c]) for c in range(3)]
        sinusCentre = [(centre[c] + sinusz * axis3[c]) for c in range(3)]
        # calculate magnitude of d1, d2 at inner sinus
        leafd1mag = innerInletRadius * radiansPerElementAround  # was 0.5*
        leafd2r, leafd2z = interpolateLagrangeHermiteDerivative(
            [innerRadialDisplacement, 0.0], [0.0, outletLength],
            [0.0, outletLength], 0.0)
        sinusd1mag = innerInletSinusRadius * radiansPerElementAround  # initial value only
        sinusd1mag = vector.magnitude(
            smoothCubicHermiteDerivativesLine(
                [[innerInletRadius, 0.0, inletz],
                 [
                     innerInletSinusRadius * math.cos(pi_3),
                     innerInletSinusRadius * math.sin(pi_3), sinusz
                 ]], [[0.0, leafd1mag, 0.0],
                      [
                          -sinusd1mag * math.sin(pi_3),
                          sinusd1mag * math.cos(pi_3), 0.0
                      ]],
                fixStartDerivative=True,
                fixEndDirection=True)[1])
        sinusd2r, sinusd2z = smoothCubicHermiteDerivativesLine(
            [[innerInletSinusRadius, -sinusDepth],
             [innerInletRadius, outerHeight]], [[
                 outletLength * math.sin(sinusAngleRadians),
                 outletLength * math.cos(sinusAngleRadians)
             ], [0.0, outletLength]],
            fixStartDirection=True,
            fixEndDerivative=True)[0]
        magd3 = wallThickness + outerRadialDisplacement - innerRadialDisplacement
        x[0][0] = []
        d1[0][0] = []
        d2[0][0] = []
        d3[0][0] = []
        for n1 in range(elementsCountAround):
            radiansAround = n1 * radiansPerElementAround
            cosRadiansAround = math.cos(radiansAround)
            sinRadiansAround = math.sin(radiansAround)
            if (n1 % 2) == 0:
                # leaflet junction
                cx = inletCentre
                r = innerInletRadius
                d1mag = leafd1mag
                d2mag1 = leafd2r * cosRadiansAround
                d2mag2 = leafd2r * sinRadiansAround
                d2mag3 = leafd2z
            else:
                # sinus / leaflet centre
                cx = sinusCentre
                r = innerInletSinusRadius
                d1mag = sinusd1mag
                d2mag1 = sinusd2r * cosRadiansAround
                d2mag2 = sinusd2r * sinRadiansAround
                d2mag3 = sinusd2z
            d3mag1 = magd3 * cosRadiansAround
            d3mag2 = magd3 * sinRadiansAround
            d3mag3 = 0.0
            x[0][0].append([
                (cx[c] + r *
                 (cosRadiansAround * axis1[c] + sinRadiansAround * axis2[c]))
                for c in range(3)
            ])
            d1[0][0].append([
                d1mag *
                (-sinRadiansAround * axis1[c] + cosRadiansAround * axis2[c])
                for c in range(3)
            ])
            d2[0][0].append([
                (d2mag1 * axis1[c] + d2mag2 * axis2[c] + d2mag3 * axis3[c])
                for c in range(3)
            ])
            d3[0][0].append([
                (d3mag1 * axis1[c] + d3mag2 * axis2[c] + d3mag3 * axis3[c])
                for c in range(3)
            ])
        # outer layer
        extRadius = outerRadius + outerRadialDisplacement
        leafd2r, leafd2z = smoothCubicHermiteDerivativesLine(
            [[extRadius, 0.0], [outerRadius, outerHeight]], [[
                -outerHeight * math.sin(outerAngleRadians),
                outerHeight * math.cos(outerAngleRadians)
            ], [0.0, outletLength]],
            fixStartDirection=True,
            fixEndDerivative=True)[0]
        # calculate magnitude of d1, d2 at outer sinus
        extSinusRadius = outerRadius + outerSinusRadialDisplacement
        leafd1mag = extRadius * radiansPerElementAround
        sinusd1mag = extSinusRadius * radiansPerElementAround  # initial value only
        sinusd1mag = vector.magnitude(
            smoothCubicHermiteDerivativesLine(
                [[extRadius, 0.0, 0.0],
                 [
                     extSinusRadius * math.cos(pi_3),
                     extSinusRadius * math.sin(pi_3), 0.0
                 ]], [[0.0, leafd1mag, 0.0],
                      [
                          -sinusd1mag * math.sin(pi_3),
                          sinusd1mag * math.cos(pi_3), 0.0
                      ]],
                fixStartDerivative=True,
                fixEndDirection=True)[1])
        sinusd2r, sinusd2z = smoothCubicHermiteDerivativesLine(
            [[extSinusRadius, 0.0], [outerRadius, outerHeight]], [[
                -outerHeight * math.sin(outerAngleRadians),
                outerHeight * math.cos(outerAngleRadians)
            ], [0.0, outletLength]],
            fixStartDirection=True,
            fixEndDerivative=True)[0]
        centre = centre
        x[1][0] = []
        d1[1][0] = []
        d2[1][0] = []
        d3[1][0] = []
        for n1 in range(elementsCountAround):
            radiansAround = n1 * radiansPerElementAround
            cosRadiansAround = math.cos(radiansAround)
            sinRadiansAround = math.sin(radiansAround)
            if (n1 % 2) == 0:
                # leaflet junction
                cx = inletCentre
                r = extRadius
                d1mag = leafd1mag
                d2mag1 = leafd2r * cosRadiansAround
                d2mag2 = leafd2r * sinRadiansAround
                d2mag3 = leafd2z
            else:
                # sinus / leaflet centre
                cx = sinusCentre
                r = extSinusRadius
                d1mag = sinusd1mag
                d2mag1 = sinusd2r * cosRadiansAround
                d2mag2 = sinusd2r * sinRadiansAround
                d2mag3 = sinusd2z
            d3mag1 = magd3 * cosRadiansAround
            d3mag2 = magd3 * sinRadiansAround
            d3mag3 = 0.0
            x[1][0].append([
                (centre[c] + r *
                 (cosRadiansAround * axis1[c] + sinRadiansAround * axis2[c]))
                for c in range(3)
            ])
            d1[1][0].append([
                d1mag *
                (-sinRadiansAround * axis1[c] + cosRadiansAround * axis2[c])
                for c in range(3)
            ])
            d2[1][0].append([
                (d2mag1 * axis1[c] + d2mag2 * axis2[c] + d2mag3 * axis3[c])
                for c in range(3)
            ])
            d3[1][0].append([
                (d3mag1 * axis1[c] + d3mag2 * axis2[c] + d3mag3 * axis3[c])
                for c in range(3)
            ])

        # outlet
        x[0][1], d1[0][1] = createCirclePoints(
            outletCentre, [axis1[c] * innerRadius for c in range(3)],
            [axis2[c] * innerRadius for c in range(3)], elementsCountAround)
        x[1][1], d1[1][1] = createCirclePoints(
            outletCentre, [axis1[c] * outerRadius for c in range(3)],
            [axis2[c] * outerRadius for c in range(3)], elementsCountAround)
        d2[1][1] = d2[0][1] = [[axis3[c] * outletLength
                                for c in range(3)]] * elementsCountAround
        d3[1][1] = d3[0][1] = None

        return x, d1, d2, d3