def _stdViewsButtonClicked(self):
     sceneviewer = self._ui.alignmentsceneviewerwidget.getSceneviewer()
     if sceneviewer is not None:
         result, eyePosition, lookatPosition, upVector = sceneviewer.getLookatParameters(
         )
         upVector = normalize(upVector)
         viewVector = sub(lookatPosition, eyePosition)
         viewDistance = magnitude(viewVector)
         viewVector = normalize(viewVector)
         viewX = dot(viewVector, [1.0, 0.0, 0.0])
         viewY = dot(viewVector, [0.0, 1.0, 0.0])
         viewZ = dot(viewVector, [0.0, 0.0, 1.0])
         upX = dot(upVector, [1.0, 0.0, 0.0])
         upY = dot(upVector, [0.0, 1.0, 0.0])
         upZ = dot(upVector, [0.0, 0.0, 1.0])
         if (viewZ < -0.999) and (upY > 0.999):
             # XY -> XZ
             viewVector = [0.0, 1.0, 0.0]
             upVector = [0.0, 0.0, 1.0]
         elif (viewY > 0.999) and (upZ > 0.999):
             # XZ -> YZ
             viewVector = [-1.0, 0.0, 0.0]
             upVector = [0.0, 0.0, 1.0]
         else:
             # XY
             viewVector = [0.0, 0.0, -1.0]
             upVector = [0.0, 1.0, 0.0]
         eyePosition = sub(lookatPosition, mult(viewVector, viewDistance))
         sceneviewer.setLookatParametersNonSkew(eyePosition, lookatPosition,
                                                upVector)
예제 #2
0
def get_bifurcation_triple_point(p1x, p1d, p2x, p2d, p3x, p3d):
    '''
    Get coordinates and derivatives of triple point between p1, p2 and p3 with derivatives.
    :param p1x..p3d: Point coordinates and derivatives, numbered anticlockwise around triple point.
    All derivatives point away from triple point.
    Returned d1 points from triple point to p2, d2 points from triple point to p3.
    :return: x, d1, d2
    '''
    trx1 = interpolateCubicHermite(p1x, mult(p1d, -2.0), p2x, mult(p2d, 2.0), 0.5)
    trx2 = interpolateCubicHermite(p2x, mult(p2d, -2.0), p3x, mult(p3d, 2.0), 0.5)
    trx3 = interpolateCubicHermite(p3x, mult(p3d, -2.0), p1x, mult(p1d, 2.0), 0.5)
    trx = [ (trx1[c] + trx2[c] + trx3[c])/3.0 for c in range(3) ]
    td1 = interpolateLagrangeHermiteDerivative(trx, p1x, p1d, 0.0)
    td2 = interpolateLagrangeHermiteDerivative(trx, p2x, p2d, 0.0)
    td3 = interpolateLagrangeHermiteDerivative(trx, p3x, p3d, 0.0)
    n12 = cross(td1, td2)
    n23 = cross(td2, td3)
    n31 = cross(td3, td1)
    norm = normalize([ (n12[c] + n23[c] + n31[c]) for c in range(3) ])
    sd1 = smoothCubicHermiteDerivativesLine([ trx, p1x ], [ normalize(cross(norm, cross(td1, norm))), p1d ], fixStartDirection=True, fixEndDerivative=True)[0]
    sd2 = smoothCubicHermiteDerivativesLine([ trx, p2x ], [ normalize(cross(norm, cross(td2, norm))), p2d ], fixStartDirection=True, fixEndDerivative=True)[0]
    sd3 = smoothCubicHermiteDerivativesLine([ trx, p3x ], [ normalize(cross(norm, cross(td3, norm))), p3d ], fixStartDirection=True, fixEndDerivative=True)[0]
    trd1 = mult(sub(sd2, add(sd3, sd1)), 0.5)
    trd2 = mult(sub(sd3, add(sd1, sd2)), 0.5)
    return trx, trd1, trd2
예제 #3
0
def get_curve_circle_points(x1, xd1, x2, xd2, r1, rd1, r2, rd2, xi, dmag, side, elementsCountAround):
    '''
    :param dmag: Magnitude of derivative on curve.
    :param side: Vector in side direction of first node around.
    Need not be unit or exactly normal to curve at xi.
    :return: x[], d1[] around, d2[] along
    '''
    cx = interpolateCubicHermite(x1, xd1, x2, xd2, xi)
    cxd = interpolateCubicHermiteDerivative(x1, xd1, x2, xd2, xi)
    mag_cxd = magnitude(cxd)
    cxd2 = interpolateCubicHermiteSecondDerivative(x1, xd1, x2, xd2, xi)
    mag_cxd2 = magnitude(cxd2)
    r = interpolateCubicHermite([ r1 ], [ rd1 ], [ r2 ], [ rd2 ], xi)[0]
    rd = interpolateCubicHermiteDerivative([ r1 ], [ rd1 ], [ r2 ], [ rd2 ], xi)[0]
    axis1 = normalize(cxd)
    axis3 = normalize(cross(axis1, side))
    axis2 = cross(axis3, axis1)
    x, d1 = createCirclePoints(cx, mult(axis2, r), mult(axis3, r), elementsCountAround)
    curvatureVector = mult(cxd2, 1.0/(mag_cxd*mag_cxd))
    d2 = []
    radialGrowth = rd/(mag_cxd*r)
    for e in range(elementsCountAround):
        radialVector = sub(x[e], cx)
        dmagFinal = dmag*(1.0 - dot(radialVector, curvatureVector))
        # add curvature and radius change components:
        d2.append(add(mult(cxd, dmagFinal/mag_cxd), mult(radialVector, dmagFinal*radialGrowth)))
    return x, d1, d2
예제 #4
0
    def generateBaseMesh(cls, region, options):
        """
        Generate the base bicubic Hermite mesh.
        :param region: Zinc region to define model in. Must be empty.
        :param options: Dict containing options. See getDefaultOptions().
        :return: list of AnnotationGroup
        """
        paCount = options['Number of elements around parent']
        c1Count = options['Number of elements around child 1']
        c2Count = options['Number of elements around child 2']
        parentRadius = 0.5 * options['Parent diameter']
        parentLength = options['Parent length']
        parentLengthScaleFactor = options['Parent length scale factor']
        child1AngleRadians = math.radians(options['Child 1 angle degrees'])
        child1Radius = 0.5 * options['Child 1 diameter']
        child1Length = options['Child 1 length']
        child1LengthScaleFactor = options['Child 1 length scale factor']
        child2AngleRadians = math.radians(options['Child 2 angle degrees'])
        child2Radius = 0.5 * options['Child 2 diameter']
        child2Length = options['Child 2 length']
        child2LengthScaleFactor = options['Child 2 length scale factor']
        useCrossDerivatives = False

        # centres:
        paCentre = [0.0, 0.0, -parentLength]
        c1Centre = [
            child1Length * math.sin(child1AngleRadians), 0.0,
            child1Length * math.cos(child1AngleRadians)
        ]
        c2Centre = [
            child2Length * math.sin(child2AngleRadians), 0.0,
            child2Length * math.cos(child2AngleRadians)
        ]
        c12 = sub(c1Centre, c2Centre)

        pac1Count, pac2Count, c1c2Count = get_tube_bifurcation_connection_elements_counts(
            paCount, c1Count, c2Count)

        # parent ring
        paAxis3 = [0.0, 0.0, parentLength]
        paAxis2 = mult(normalize(cross(paAxis3, c12)), parentRadius)
        paAxis1 = mult(normalize(cross(paAxis2, paAxis3)), parentRadius)
        paStartRadians = -math.pi * (pac1Count / paCount)
        pax, pad1 = createCirclePoints(paCentre, paAxis1, paAxis2, paCount,
                                       paStartRadians)
        pad2 = [mult(paAxis3, parentLengthScaleFactor)] * paCount
        # child 1 ring
        c1Axis3 = c1Centre
        c1Axis2 = mult(normalize(cross(c1Axis3, c12)), child1Radius)
        c1Axis1 = mult(normalize(cross(c1Axis2, c1Axis3)), child1Radius)
        c1StartRadians = -math.pi * (pac1Count / c1Count)
        c1x, c1d1 = createCirclePoints(c1Centre, c1Axis1, c1Axis2, c1Count,
                                       c1StartRadians)
        c1d2 = [mult(c1Axis3, child1LengthScaleFactor)] * c1Count
        # child 2 ring
        c2Axis3 = c2Centre
        c2Axis2 = mult(normalize(cross(c2Axis3, c12)), child2Radius)
        c2Axis1 = mult(normalize(cross(c2Axis2, c2Axis3)), child2Radius)
        c2StartRadians = -math.pi * (c1c2Count / c2Count)
        c2x, c2d1 = createCirclePoints(c2Centre, c2Axis1, c2Axis2, c2Count,
                                       c2StartRadians)
        c2d2 = [mult(c2Axis3, child2LengthScaleFactor)] * c2Count

        rox, rod1, rod2, cox, cod1, cod2, paStartIndex, c1StartIndex, c2StartIndex = \
            make_tube_bifurcation_points(paCentre, pax, pad2, c1Centre, c1x, c1d2, c2Centre, c2x, c2d2)

        fm = region.getFieldmodule()
        coordinates = findOrCreateFieldCoordinates(fm)
        cache = fm.createFieldcache()

        nodes = fm.findNodesetByFieldDomainType(Field.DOMAIN_TYPE_NODES)

        ##############
        # Create nodes
        ##############

        nodeIdentifier = 1

        nodetemplate = nodes.createNodetemplate()
        nodetemplate.defineField(coordinates)
        nodetemplate.setValueNumberOfVersions(coordinates, -1,
                                              Node.VALUE_LABEL_VALUE, 1)
        nodetemplate.setValueNumberOfVersions(coordinates, -1,
                                              Node.VALUE_LABEL_D_DS1, 1)
        nodetemplate.setValueNumberOfVersions(coordinates, -1,
                                              Node.VALUE_LABEL_D_DS2, 1)
        paNodeId = []
        for n in range(paCount):
            node = nodes.createNode(nodeIdentifier, nodetemplate)
            cache.setNode(node)
            coordinates.setNodeParameters(cache, -1, Node.VALUE_LABEL_VALUE, 1,
                                          pax[n])
            coordinates.setNodeParameters(cache, -1, Node.VALUE_LABEL_D_DS1, 1,
                                          pad1[n])
            coordinates.setNodeParameters(cache, -1, Node.VALUE_LABEL_D_DS2, 1,
                                          pad2[n])
            paNodeId.append(nodeIdentifier)
            nodeIdentifier = nodeIdentifier + 1
        roNodeId = []
        for n in range(len(rox)):
            node = nodes.createNode(nodeIdentifier, nodetemplate)
            cache.setNode(node)
            coordinates.setNodeParameters(cache, -1, Node.VALUE_LABEL_VALUE, 1,
                                          rox[n])
            coordinates.setNodeParameters(cache, -1, Node.VALUE_LABEL_D_DS1, 1,
                                          rod1[n])
            coordinates.setNodeParameters(cache, -1, Node.VALUE_LABEL_D_DS2, 1,
                                          rod2[n])
            roNodeId.append(nodeIdentifier)
            nodeIdentifier = nodeIdentifier + 1
        coNodeId = []
        for n in range(len(cox)):
            node = nodes.createNode(nodeIdentifier, nodetemplate)
            cache.setNode(node)
            coordinates.setNodeParameters(cache, -1, Node.VALUE_LABEL_VALUE, 1,
                                          cox[n])
            coordinates.setNodeParameters(cache, -1, Node.VALUE_LABEL_D_DS1, 1,
                                          cod1[n])
            coordinates.setNodeParameters(cache, -1, Node.VALUE_LABEL_D_DS2, 1,
                                          cod2[n])
            coNodeId.append(nodeIdentifier)
            nodeIdentifier = nodeIdentifier + 1
        c1NodeId = []
        for n in range(c1Count):
            node = nodes.createNode(nodeIdentifier, nodetemplate)
            cache.setNode(node)
            coordinates.setNodeParameters(cache, -1, Node.VALUE_LABEL_VALUE, 1,
                                          c1x[n])
            coordinates.setNodeParameters(cache, -1, Node.VALUE_LABEL_D_DS1, 1,
                                          c1d1[n])
            coordinates.setNodeParameters(cache, -1, Node.VALUE_LABEL_D_DS2, 1,
                                          c1d2[n])
            c1NodeId.append(nodeIdentifier)
            nodeIdentifier = nodeIdentifier + 1
        c2NodeId = []
        for n in range(c2Count):
            node = nodes.createNode(nodeIdentifier, nodetemplate)
            cache.setNode(node)
            coordinates.setNodeParameters(cache, -1, Node.VALUE_LABEL_VALUE, 1,
                                          c2x[n])
            coordinates.setNodeParameters(cache, -1, Node.VALUE_LABEL_D_DS1, 1,
                                          c2d1[n])
            coordinates.setNodeParameters(cache, -1, Node.VALUE_LABEL_D_DS2, 1,
                                          c2d2[n])
            c2NodeId.append(nodeIdentifier)
            nodeIdentifier = nodeIdentifier + 1

        #################
        # Create elements
        #################

        elementIdentifier = 1
        elementIdentifier = make_tube_bifurcation_elements_2d(
            region, coordinates, elementIdentifier, paNodeId, paStartIndex,
            c1NodeId, c1StartIndex, c2NodeId, c2StartIndex, roNodeId, coNodeId,
            useCrossDerivatives)

        return []