def createFairnessControlMeshCoefs(quad_list, AVertexList, B1VertexList, B2VertexList, CVertexList,
                                   quad_control_point_indices):
    """
    takes the list of N quads, the corner points and the connectivity
    information and spits out the fairness coefficients as an
    (N*16*3)x(N*16) matrix.
    """
    N = quad_control_point_indices.shape[0] * quad_control_point_indices.shape[1] * 3
    M = quad_control_point_indices.shape[0] * quad_control_point_indices.shape[1]
    coefsMatrix = np.zeros((N, M))

    """
    precalculate the coefficients between all the vertex control points and
    the bezier control points for 7 different number of intersecting
    edges as a start
    (number of incoming edges(between 3 an 7 hardcoded), [A,B1,B2,C], [in which quad 1-7], bezier point
    first coord, bezier point second coord)
    """

    ordinaryCoefsRaw = np.zeros((3,3,3,3))
    ACoefsRaw = np.zeros((7, 7, 4, 4))
    B1CoefsRaw = np.zeros((7, 7, 4, 4))
    B2CoefsRaw = np.zeros((7, 7, 4, 4))
    CCoefsRaw = np.zeros((7, 7, 4, 4))

    for num_quads in range(3,8):
        ACoefsRaw[num_quads-1, 0:num_quads, :, :], \
        B1CoefsRaw[num_quads-1, 0:num_quads, :, :], \
        B2CoefsRaw[num_quads-1, 0:num_quads, :, :], \
        CCoefsRaw[num_quads-1, 0:num_quads, :, :] = createBicubicCoefMatrices(num_quads)

    for bezierI in range(3):
        for bezierJ in range(3):
            ordinaryCoefsRaw[:, :, bezierI, bezierJ] = getBiquadraticPatchCoefs(bezierI, bezierJ)

    coefsRawTemp = np.zeros((4, 7, 4, 4))

    uu2mat = np.array([[2.0, 2.0, 2.0], [-4.0, -4.0, -4.0], [2.0, 2.0, 2.0]]) / 3.0
    vv2mat = np.transpose(uu2mat)
    uv2mat = np.array([[1.0, 0.0, -1.0], [0.0, 0.0, 0.0], [-1.0, 0.0, 1.0]])
    uu3mat = np.array(
            [[3.0, 3.0, 3.0, 3.0], [-3.0, -3.0, -3.0, -3.0], [-3.0, -3.0, -3.0, -3.0], [3.0, 3.0, 3.0, 3.0]]) / 4.0
    vv3mat = np.transpose(uu3mat)
    uv3mat = np.array([[1.0, 0.0, 0.0, -1.0], [0.0, 0.0, 0.0, 0.0], [0.0, 0.0, 0.0, 0.0], [-1.0, 0.0, 0.0, 1.0]])

    biqBezCoefs = np.array([uu2mat, 2.0 * uv2mat, vv2mat])
    bicBezCoefs = np.array([uu3mat, 2.0 * uv3mat, vv3mat])

    whichCornerList = np.array([[0, 3], [1, 2]], dtype=int)

    p = 0
    print "Main Loop Fairness Coeffs"
    for q in range(quad_list.shape[0]):
        if q%100 == 0:
            print "processing quad %d of %d..." % (q, quad_list.shape[0])
        for j in range(4):
            for i in range(4):
                if (i == 0 or i == 3) and (j == 0 or j == 3):  # bicubic patches
                    whichCorner = whichCornerFun(i, j, whichCornerList)
                    indexMask = getExtraOrdCornerIndexMask(quad_list, AVertexList, B1VertexList, B2VertexList,
                                                           CVertexList, quad_control_point_indices, q, whichCorner)
                    numberOfEdges = indexMask.shape[1]

                    coefsRawTemp[0, 0:numberOfEdges, :, :] = ACoefsRaw[numberOfEdges - 1, 0:numberOfEdges, :, :]
                    coefsRawTemp[1, 0:numberOfEdges, :, :] = B1CoefsRaw[numberOfEdges - 1, 0:numberOfEdges, :, :]
                    coefsRawTemp[2, 0:numberOfEdges, :, :] = B2CoefsRaw[numberOfEdges - 1, 0:numberOfEdges, :, :]
                    coefsRawTemp[3, 0:numberOfEdges, :, :] = CCoefsRaw[numberOfEdges - 1, 0:numberOfEdges, :, :]

                    for matType in range(3):
                        bezier_points = np.squeeze(bicBezCoefs[matType, :, :])  # squeeze
                        patchCoefsMatrix = getPetersControlPointCoefs(bezier_points,
                                                                      coefsRawTemp[:, 0:numberOfEdges, :, :])
                        coefsMatrix[p][indexMask[:]] = patchCoefsMatrix[:]
                        p += 1

                else:  # biquadratic patches
                    neighbourMask = get3x3ControlPointIndexMask(quad_list=quad_list,
                                                                quad_control_point_indices=quad_control_point_indices,
                                                                quad_index=q,
                                                                localIndexXY=np.array([i, j])).astype(int)  # correct??

                    for matType in range(3):
                        bezier_points = np.squeeze(biqBezCoefs[matType, :, :])
                        ordinaryPatchCoefsMatrix = getPetersControlPointCoefs(bezier_points,
                                                                              ordinaryCoefsRaw)
                        coefsMatrix[p][neighbourMask[:]] = ordinaryPatchCoefsMatrix[:]
                        p += 1

    return coefsMatrix
def createGlobalControlMeshCoefs(parameterCoordinates, quad_list, AVertexList, B1VertexList, B2VertexList, CVertexList,
                                     quad_control_point_indices):
    '''
    Takes, for N datapoints, an array parameterCoordinates[Nx3](for every
    datapoint: first entry the quad index, second and third parameters
    on a patch that spans over [0,1]x[0,1]
    for the quad. The function computes the coefficient matrix for between
    each datapoint and the array of M/16 quads x [4x4] vertex control points,
    outputting the coefficients as an N x M scipy.sparse COO-type sparse matrix

    @param parameterCoordinates: Nx3 numpy.ndarray of datapoint parameters
    @param quad_list:
    @param AVertexList:
    @param B1VertexList:
    @param B2VertexList:
    @param CVertexList:
    @param quad_control_point_indices: (M/16)x16 numpy.ndarray of control points on each quad
    @return: NxM scipy.sparse COO-type sparse matrix of coefficients, maximum 22 nonzero entries per row
    '''


    N = parameterCoordinates.shape[0]
    M = quad_control_point_indices.shape[0] * quad_control_point_indices.shape[1]
    max_size = N*28 #4 types of vertices times maximum 7 quads around an extraordinary vertex (large estimate)
    rows = np.zeros(max_size, dtype=int)
    cols = np.zeros(max_size, dtype=int)
    data = np.zeros(max_size)

    """
    Precalculate the coefficients between all the vertex control points and
    the bezier control points for 7 different number of intersecting
    edges as a start

    (number of incoming edges(between 3 an 7 hardcoded), [A,B1,B2,C], [in which quad 1-7], bezier point
    first coord, bezier point second coord)
    """

    ACoefsRaw = np.zeros((7,7,4,4))
    B1CoefsRaw = np.zeros((7,7,4,4))
    B2CoefsRaw = np.zeros((7,7,4,4))
    CCoefsRaw  = np.zeros((7,7,4,4))

    for num_quads in range(3,8):
        [ACoefsRaw[num_quads-1, 0:num_quads, :, :],
         B1CoefsRaw[num_quads-1, 0:num_quads, :, :],
         B2CoefsRaw[num_quads-1, 0:num_quads, :, :],
         CCoefsRaw[num_quads-1, 0:num_quads, :, :]] = createBicubicCoefMatrices(num_quads) # compared to matlab by Saumi & Benni -> VALID

    coefsRawTemp = np.zeros((4,7,4,4))

    indexCounter = 0

    print "Main Loop Coefs"
    for p in range(N):
        if p%100 == 0:
            print "processing point %d of %d..." % (p, N)
        #check if on a corner patch : if both coords are outside [0.25,0.75]
        quadParameters = parameterCoordinates[p, 1:3]
        quad_index = int(parameterCoordinates[p, 0])
        [localCoords, whichCorner, whichPatch] = createLocalParamsExtraordinary(global_quad_params=quadParameters)
        #print "p=%d"%p # todo for p=1 get3x3... fails! -> Resolved(?).
        #print "whichPatch="+str(whichPatch)
        # if there is a specified corner set
        if whichCorner != -1:

            cornerVertexIndex = quad_list[quad_index, whichCorner]

            numberOfEdges = get_num_edges_meeting(AVertexList, cornerVertexIndex)
            #TODO: Check output PROBLEM!
            indexMask = getExtraOrdCornerIndexMask(quad_list, AVertexList, B1VertexList, B2VertexList, CVertexList,
                                                   quad_control_point_indices, quad_index, whichCorner)

            coefsRawTemp[0, 0:numberOfEdges, :, :] = ACoefsRaw[numberOfEdges-1, 0:numberOfEdges, :, :]
            coefsRawTemp[1, 0:numberOfEdges, :, :] = B1CoefsRaw[numberOfEdges-1, 0:numberOfEdges, :, :]
            coefsRawTemp[2, 0:numberOfEdges, :, :] = B2CoefsRaw[numberOfEdges-1, 0:numberOfEdges, :, :]
            coefsRawTemp[3, 0:numberOfEdges, :, :] = CCoefsRaw[numberOfEdges-1, 0:numberOfEdges, :, :]

            patchCoefsMatrix = getBicubicBezierPointCoefs(localCoords, coefsRawTemp[:, 0:numberOfEdges, :, :])

            numberOfEntries = numberOfEdges*4

            rows[indexCounter:(indexCounter + numberOfEntries)] = p
            cols[indexCounter:(indexCounter + numberOfEntries)] = indexMask.flatten()[:]
            data[indexCounter:(indexCounter + numberOfEntries)] = patchCoefsMatrix.flatten()[:]

            indexCounter += numberOfEntries


        else:
            neighbourMask = get3x3ControlPointIndexMask(quad_list=quad_list,
                                                        quad_control_point_indices=quad_control_point_indices,
                                                        quad_index=quad_index,
                                                        localIndexXY=whichPatch)
            neighbourCoefs = getBezierPointCoefs(localCoords)

            numberOfEntries = 9

            rows[indexCounter:(indexCounter + numberOfEntries)] = p
            cols[indexCounter:(indexCounter + numberOfEntries)] = neighbourMask.flatten()[:]
            data[indexCounter:(indexCounter + numberOfEntries)] = neighbourCoefs.flatten()[:]

            indexCounter += numberOfEntries

    print "Main Loop Coeffs Done."

    return ssp.coo_matrix((data, (rows, cols)), shape=(N, M))
Ejemplo n.º 3
0
def createNURBSMatricesAllraised(quad_list, AVertexList, B1VertexList, B2VertexList, CVertexList, quad_control_point_indices, control_points):

    import numpy as np

    assert type(control_points) is np.ndarray

    whichCornerList = np.array([[0, 3], [1, 2]], dtype=int)

    one4toone2 = lambda x: np.floor(x/3)

    whichCornerFun = lambda x, y: whichCornerList[one4toone2(x), one4toone2(y)]

    is_in_corner = lambda x, y: (x == 0 or x == 3) and (y == 0 or y == 3)

    number_of_quads = np.size(quad_list, 0)
    ordinaryCoefsRaw = np.zeros((3,3,3,3))
    allCoefsRaw = np.zeros((4, 7, 7, 4, 4))
    verticesTemp = np.zeros((4, 7, 3))
    tempBiquadBezierMatrix = np.zeros((3, 3, 3))
    NURBSMatrix = np.zeros((13*13*number_of_quads, 3))
    NURBSIndices = np.zeros((number_of_quads, 13*13), dtype=int)

    for num_quads in range(3,8):
        allCoefsRaw[0, num_quads-1, 0:num_quads, :, :], \
            allCoefsRaw[1, num_quads-1, 0:num_quads, :, :], \
            allCoefsRaw[2, num_quads-1, 0:num_quads, :, :], \
            allCoefsRaw[3, num_quads-1, 0:num_quads, :, :] = createBicubicCoefMatrices(num_quads)

    for bezierI in range(3):
        for bezierJ in range(3):
            ordinaryCoefsRaw[:, :, bezierI, bezierJ] = getBiquadraticPatchCoefs(bezierI, bezierJ)

    getLinearIndexing = lambda x, y, width: x + y*width

    addToIndex = lambda x: x*3

    #indices of 0-3 just for vectorized access of stuff
    ii, jj = np.meshgrid(np.arange(4), np.arange(4))

    for q in range(number_of_quads):
        for j in range(4):
            for i in range(4):
                addToIndexI = addToIndex(i)
                addToIndexJ = addToIndex(j)

                if is_in_corner(i, j):
                    whichCorner = whichCornerFun(i, j)
                    indexMask = getExtraOrdCornerIndexMask(quad_list, AVertexList, B1VertexList, B2VertexList, CVertexList, quad_control_point_indices, q, whichCorner)
                    numberOfEdges = np.size(indexMask,1)

                    for k in range(4):
                        verticesTemp[k, 0:numberOfEdges, :] = control_points[np.squeeze(indexMask[k, 0:numberOfEdges]), :]

                    patch = multiply_patch(allCoefsRaw[:, numberOfEdges-1, 0:numberOfEdges, :, :], verticesTemp[:, 0:numberOfEdges, :])

                    #shift the points to lie in the same order as the nurbs
                    #patch: corner 3 is in the correct orientation, the next
                    #(corner 4) needs to be rotated one 90deg rotation
                    #clockwise, the next another one clockwise etc...
                    patch = np.rot90(patch, (whichCorner-2) % 4)

                    patchIndexArray = getLinearIndexing(ii+addToIndexI, jj+addToIndexJ, 13)
                    NURBSMatrix[q*13*13 + patchIndexArray[:], :] = patch[ii[:], jj[:], :]
                    NURBSIndices[q, patchIndexArray[:]] = q*13*13 + patchIndexArray
                    '''
                    #equivalent code:
                    for jPatch in range(4):
                        for iPatch in range(4):
                            NURBScurrentIndex = q*13*13 + getLinearIndexing(iPatch+addToIndexI, jPatch+addToIndexJ, 13)
                            NURBSMatrix[NURBScurrentIndex, :] = patch[iPatch, jPatch, :]
                            NURBSIndices[q, getLinearIndexing(iPatch+addToIndexI, jPatch+addToIndexJ, 13)] = NURBScurrentIndex
                    '''

                else:
                    neighbourMask = get3x3ControlPointIndexMask(quad_list, quad_control_point_indices, q, np.array([i,j]))

                    for jPatch in range(3):
                        for iPatch in range(3):
                            tempBiquadBezierMatrix[iPatch, jPatch, :] = control_points[neighbourMask[iPatch,jPatch],:]

                    tempBiquadBezierMatrix = multiply_patch(ordinaryCoefsRaw, tempBiquadBezierMatrix)
                    raisedBiquadMatrix = raiseDeg2D_from3x3(tempBiquadBezierMatrix)

                    patchIndexArray = getLinearIndexing(ii+addToIndexI, jj+addToIndexJ, 13)
                    NURBSMatrix[q*13*13 + patchIndexArray[:], :] = raisedBiquadMatrix[ii[:], jj[:], :]
                    NURBSIndices[q, patchIndexArray[:]] = q*13*13 + patchIndexArray

    return NURBSMatrix, NURBSIndices
def createGlobalControlMeshCoefs(parameterCoordinates, quad_list, AVertexList, B1VertexList, B2VertexList, CVertexList,
                                     quad_control_point_indices):
    """
    Takes, for N datapoints, an array parameterCoordinates[Nx3](for every
    datapoint: first entry the quad index, second and third parameterson a patch that spans over [0,1]x[0,1]
    for the quad. The function computes the coefficient matrix for between
    each datapoint and the array of M/16 quads x [4x4] vertex control points,
    outputting the coefficients as an N x M matrix.
    """

    N = parameterCoordinates.shape[0]
    M = quad_control_point_indices.shape[0] * quad_control_point_indices.shape[1]
    coefsMatrix = np.zeros((N,M))

    """
    Precalculate the coefficients between all the vertex control points and
    the bezier control points for 7 different number of intersecting
    edges as a start

    (number of incoming edges(between 3 an 7 hardcoded), [A,B1,B2,C], [in which quad 1-7], bezier point
    first coord, bezier point second coord)
    """

    ACoefsRaw = np.zeros((7,7,4,4))
    B1CoefsRaw = np.zeros((7,7,4,4))
    B2CoefsRaw = np.zeros((7,7,4,4))
    CCoefsRaw  = np.zeros((7,7,4,4))

    for num_quads in range(3,8):
        [ACoefsRaw[num_quads-1, 0:num_quads, :, :],
         B1CoefsRaw[num_quads-1, 0:num_quads, :, :],
         B2CoefsRaw[num_quads-1, 0:num_quads, :, :],
         CCoefsRaw[num_quads-1, 0:num_quads, :, :]] = createBicubicCoefMatrices(num_quads) # compared to matlab by Saumi & Benni -> VALID

    coefsRawTemp = np.zeros((4,7,4,4))

    print "Main Loop Coeffs"
    for p in range(N):
        if p%100 == 0:
            print "processing point %d of %d..." % (p, N)
        #check if on a corner patch : if both coords are outside [0.25,0.75]
        quadParameters = parameterCoordinates[p, 1:3]
        quad_index = int(parameterCoordinates[p, 0])
        [localCoords, whichCorner, whichPatch] = createLocalParamsExtraordinary(global_quad_params=quadParameters)
        #print "p=%d"%p # todo for p=1 get3x3... fails! -> Resolved(?).
        #print "whichPatch="+str(whichPatch)
        # if there is a specified corner set
        if whichCorner != -1:

            cornerVertexIndex = quad_list[quad_index, whichCorner]

            numberOfEdges = get_num_edges_meeting(AVertexList, cornerVertexIndex)
            #TODO: Check output PROBLEM!
            indexMask = getExtraOrdCornerIndexMask(quad_list, AVertexList, B1VertexList, B2VertexList, CVertexList,
                                                   quad_control_point_indices, quad_index, whichCorner)

            coefsRawTemp[0, 0:numberOfEdges, :, :] = ACoefsRaw[numberOfEdges-1, 0:numberOfEdges, :, :]
            coefsRawTemp[1, 0:numberOfEdges, :, :] = B1CoefsRaw[numberOfEdges-1, 0:numberOfEdges, :, :]
            coefsRawTemp[2, 0:numberOfEdges, :, :] = B2CoefsRaw[numberOfEdges-1, 0:numberOfEdges, :, :]
            coefsRawTemp[3, 0:numberOfEdges, :, :] = CCoefsRaw[numberOfEdges-1, 0:numberOfEdges, :, :]

            patchCoefsMatrix = getBicubicBezierPointCoefs(localCoords, coefsRawTemp[:, 0:numberOfEdges, :, :])

            coefsMatrix[p][indexMask[:]] = patchCoefsMatrix[:]

        else:
            neighbourMask = get3x3ControlPointIndexMask(quad_list=quad_list,
                                                        quad_control_point_indices=quad_control_point_indices,
                                                        quad_index=quad_index,
                                                        localIndexXY=whichPatch)
            neighbourCoefs = getBezierPointCoefs(localCoords)

            for j in range(3):
                for i in range(3):
                    coefsMatrix[p, neighbourMask[i, j]] = neighbourCoefs[i, j]
    print "Main Loop Coeffs Done."

    return coefsMatrix
Ejemplo n.º 5
0
def createGlobalControlMeshCoefs(parameterCoordinates, quad_list, AVertexList,
                                 B1VertexList, B2VertexList, CVertexList,
                                 quad_control_point_indices):
    '''
    Takes, for N datapoints, an array parameterCoordinates[Nx3](for every
    datapoint: first entry the quad index, second and third parameters
    on a patch that spans over [0,1]x[0,1]
    for the quad. The function computes the coefficient matrix for between
    each datapoint and the array of M/16 quads x [4x4] vertex control points,
    outputting the coefficients as an N x M scipy.sparse COO-type sparse matrix

    @param parameterCoordinates: Nx3 numpy.ndarray of datapoint parameters
    @param quad_list:
    @param AVertexList:
    @param B1VertexList:
    @param B2VertexList:
    @param CVertexList:
    @param quad_control_point_indices: (M/16)x16 numpy.ndarray of control points on each quad
    @return: NxM scipy.sparse COO-type sparse matrix of coefficients, maximum 22 nonzero entries per row
    '''

    N = parameterCoordinates.shape[0]
    M = quad_control_point_indices.shape[0] * quad_control_point_indices.shape[
        1]
    max_size = N * 28  #4 types of vertices times maximum 7 quads around an extraordinary vertex (large estimate)
    rows = np.zeros(max_size, dtype=int)
    cols = np.zeros(max_size, dtype=int)
    data = np.zeros(max_size)
    """
    Precalculate the coefficients between all the vertex control points and
    the bezier control points for 7 different number of intersecting
    edges as a start

    (number of incoming edges(between 3 an 7 hardcoded), [A,B1,B2,C], [in which quad 1-7], bezier point
    first coord, bezier point second coord)
    """

    ACoefsRaw = np.zeros((7, 7, 4, 4))
    B1CoefsRaw = np.zeros((7, 7, 4, 4))
    B2CoefsRaw = np.zeros((7, 7, 4, 4))
    CCoefsRaw = np.zeros((7, 7, 4, 4))

    for num_quads in range(3, 8):
        [
            ACoefsRaw[num_quads - 1, 0:num_quads, :, :],
            B1CoefsRaw[num_quads - 1, 0:num_quads, :, :],
            B2CoefsRaw[num_quads - 1,
                       0:num_quads, :, :], CCoefsRaw[num_quads - 1,
                                                     0:num_quads, :, :]
        ] = createBicubicCoefMatrices(
            num_quads)  # compared to matlab by Saumi & Benni -> VALID

    coefsRawTemp = np.zeros((4, 7, 4, 4))

    indexCounter = 0

    print "Main Loop Coefs"
    for p in range(N):
        if p % 100 == 0:
            print "processing point %d of %d..." % (p, N)
        #check if on a corner patch : if both coords are outside [0.25,0.75]
        quadParameters = parameterCoordinates[p, 1:3]
        quad_index = int(parameterCoordinates[p, 0])
        [localCoords, whichCorner, whichPatch
         ] = createLocalParamsExtraordinary(global_quad_params=quadParameters)
        #print "p=%d"%p # todo for p=1 get3x3... fails! -> Resolved(?).
        #print "whichPatch="+str(whichPatch)
        # if there is a specified corner set
        if whichCorner != -1:

            cornerVertexIndex = quad_list[quad_index, whichCorner]

            numberOfEdges = get_num_edges_meeting(AVertexList,
                                                  cornerVertexIndex)
            #TODO: Check output PROBLEM!
            indexMask = getExtraOrdCornerIndexMask(quad_list, AVertexList,
                                                   B1VertexList, B2VertexList,
                                                   CVertexList,
                                                   quad_control_point_indices,
                                                   quad_index, whichCorner)

            coefsRawTemp[0, 0:numberOfEdges, :, :] = ACoefsRaw[
                numberOfEdges - 1, 0:numberOfEdges, :, :]
            coefsRawTemp[1, 0:numberOfEdges, :, :] = B1CoefsRaw[
                numberOfEdges - 1, 0:numberOfEdges, :, :]
            coefsRawTemp[2, 0:numberOfEdges, :, :] = B2CoefsRaw[
                numberOfEdges - 1, 0:numberOfEdges, :, :]
            coefsRawTemp[3, 0:numberOfEdges, :, :] = CCoefsRaw[
                numberOfEdges - 1, 0:numberOfEdges, :, :]

            patchCoefsMatrix = getBicubicBezierPointCoefs(
                localCoords, coefsRawTemp[:, 0:numberOfEdges, :, :])

            numberOfEntries = numberOfEdges * 4

            rows[indexCounter:(indexCounter + numberOfEntries)] = p
            cols[indexCounter:(indexCounter +
                               numberOfEntries)] = indexMask.flatten()[:]
            data[indexCounter:(
                indexCounter +
                numberOfEntries)] = patchCoefsMatrix.flatten()[:]

            indexCounter += numberOfEntries

        else:
            neighbourMask = get3x3ControlPointIndexMask(
                quad_list=quad_list,
                quad_control_point_indices=quad_control_point_indices,
                quad_index=quad_index,
                localIndexXY=whichPatch)
            neighbourCoefs = getBezierPointCoefs(localCoords)

            numberOfEntries = 9

            rows[indexCounter:(indexCounter + numberOfEntries)] = p
            cols[indexCounter:(indexCounter +
                               numberOfEntries)] = neighbourMask.flatten()[:]
            data[indexCounter:(indexCounter +
                               numberOfEntries)] = neighbourCoefs.flatten()[:]

            indexCounter += numberOfEntries

    print "Main Loop Coeffs Done."

    return ssp.coo_matrix((data, (rows, cols)), shape=(N, M))
Ejemplo n.º 6
0
def createNURBSMatricesAllraised(quad_list, AVertexList, B1VertexList,
                                 B2VertexList, CVertexList,
                                 quad_control_point_indices, control_points):

    import numpy as np

    assert type(control_points) is np.ndarray

    whichCornerList = np.array([[0, 3], [1, 2]], dtype=int)

    one4toone2 = lambda x: np.floor(x / 3)

    whichCornerFun = lambda x, y: whichCornerList[one4toone2(x), one4toone2(y)]

    is_in_corner = lambda x, y: (x == 0 or x == 3) and (y == 0 or y == 3)

    number_of_quads = np.size(quad_list, 0)
    ordinaryCoefsRaw = np.zeros((3, 3, 3, 3))
    allCoefsRaw = np.zeros((4, 7, 7, 4, 4))
    verticesTemp = np.zeros((4, 7, 3))
    tempBiquadBezierMatrix = np.zeros((3, 3, 3))
    NURBSMatrix = np.zeros((13 * 13 * number_of_quads, 3))
    NURBSIndices = np.zeros((number_of_quads, 13 * 13), dtype=int)

    for num_quads in range(3, 8):
        allCoefsRaw[0, num_quads-1, 0:num_quads, :, :], \
            allCoefsRaw[1, num_quads-1, 0:num_quads, :, :], \
            allCoefsRaw[2, num_quads-1, 0:num_quads, :, :], \
            allCoefsRaw[3, num_quads-1, 0:num_quads, :, :] = createBicubicCoefMatrices(num_quads)

    for bezierI in range(3):
        for bezierJ in range(3):
            ordinaryCoefsRaw[:, :, bezierI,
                             bezierJ] = getBiquadraticPatchCoefs(
                                 bezierI, bezierJ)

    getLinearIndexing = lambda x, y, width: x + y * width

    addToIndex = lambda x: x * 3

    #indices of 0-3 just for vectorized access of stuff
    ii, jj = np.meshgrid(np.arange(4), np.arange(4))

    for q in range(number_of_quads):
        for j in range(4):
            for i in range(4):
                addToIndexI = addToIndex(i)
                addToIndexJ = addToIndex(j)

                if is_in_corner(i, j):
                    whichCorner = whichCornerFun(i, j)
                    indexMask = getExtraOrdCornerIndexMask(
                        quad_list, AVertexList, B1VertexList, B2VertexList,
                        CVertexList, quad_control_point_indices, q,
                        whichCorner)
                    numberOfEdges = np.size(indexMask, 1)

                    for k in range(4):
                        verticesTemp[k, 0:numberOfEdges, :] = control_points[
                            np.squeeze(indexMask[k, 0:numberOfEdges]), :]

                    patch = multiply_patch(
                        allCoefsRaw[:, numberOfEdges - 1,
                                    0:numberOfEdges, :, :],
                        verticesTemp[:, 0:numberOfEdges, :])

                    #shift the points to lie in the same order as the nurbs
                    #patch: corner 3 is in the correct orientation, the next
                    #(corner 4) needs to be rotated one 90deg rotation
                    #clockwise, the next another one clockwise etc...
                    patch = np.rot90(patch, (whichCorner - 2) % 4)

                    patchIndexArray = getLinearIndexing(
                        ii + addToIndexI, jj + addToIndexJ, 13)
                    NURBSMatrix[q * 13 * 13 +
                                patchIndexArray[:], :] = patch[ii[:], jj[:], :]
                    NURBSIndices[
                        q, patchIndexArray[:]] = q * 13 * 13 + patchIndexArray
                    '''
                    #equivalent code:
                    for jPatch in range(4):
                        for iPatch in range(4):
                            NURBScurrentIndex = q*13*13 + getLinearIndexing(iPatch+addToIndexI, jPatch+addToIndexJ, 13)
                            NURBSMatrix[NURBScurrentIndex, :] = patch[iPatch, jPatch, :]
                            NURBSIndices[q, getLinearIndexing(iPatch+addToIndexI, jPatch+addToIndexJ, 13)] = NURBScurrentIndex
                    '''

                else:
                    neighbourMask = get3x3ControlPointIndexMask(
                        quad_list, quad_control_point_indices, q,
                        np.array([i, j]))

                    for jPatch in range(3):
                        for iPatch in range(3):
                            tempBiquadBezierMatrix[
                                iPatch, jPatch, :] = control_points[
                                    neighbourMask[iPatch, jPatch], :]

                    tempBiquadBezierMatrix = multiply_patch(
                        ordinaryCoefsRaw, tempBiquadBezierMatrix)
                    raisedBiquadMatrix = raiseDeg2D_from3x3(
                        tempBiquadBezierMatrix)

                    patchIndexArray = getLinearIndexing(
                        ii + addToIndexI, jj + addToIndexJ, 13)
                    NURBSMatrix[q * 13 * 13 +
                                patchIndexArray[:], :] = raisedBiquadMatrix[
                                    ii[:], jj[:], :]
                    NURBSIndices[
                        q, patchIndexArray[:]] = q * 13 * 13 + patchIndexArray

    return NURBSMatrix, NURBSIndices
Ejemplo n.º 7
0
def createFairnessControlMeshCoefs(quad_list, AVertexList, B1VertexList, B2VertexList, CVertexList,
                                   quad_control_point_indices):
    """
    takes the list of N quads, the corner points and the connectivity
    information and spits out the fairness coefficients as an
    (N*16*3)x(N*16) matrix.
    """
    N = quad_control_point_indices.shape[0] * quad_control_point_indices.shape[1] * 3
    M = quad_control_point_indices.shape[0] * quad_control_point_indices.shape[1]
    max_size = N*14 #(4x7)x4 for extr. vertices, 12x9 for ordinary, then averaged => 13, one extra for safety (large estimate)
    rows = np.zeros(max_size, dtype=int)
    cols = np.zeros(max_size, dtype=int)
    data = np.zeros(max_size)
    #coefsMatrix = np.zeros((N, M))

    """
    precalculate the coefficients between all the vertex control points and
    the bezier control points for 7 different number of intersecting
    edges as a start
    (number of incoming edges(between 3 an 7 hardcoded), [A,B1,B2,C], [in which quad 1-7], bezier point
    first coord, bezier point second coord)
    """

    ordinaryCoefsRaw = np.zeros((3,3,3,3))
    ACoefsRaw = np.zeros((7, 7, 4, 4))
    B1CoefsRaw = np.zeros((7, 7, 4, 4))
    B2CoefsRaw = np.zeros((7, 7, 4, 4))
    CCoefsRaw = np.zeros((7, 7, 4, 4))

    for num_quads in range(3,8):
        ACoefsRaw[num_quads-1, 0:num_quads, :, :], \
        B1CoefsRaw[num_quads-1, 0:num_quads, :, :], \
        B2CoefsRaw[num_quads-1, 0:num_quads, :, :], \
        CCoefsRaw[num_quads-1, 0:num_quads, :, :] = createBicubicCoefMatrices(num_quads)

    for bezierI in range(3):
        for bezierJ in range(3):
            ordinaryCoefsRaw[:, :, bezierI, bezierJ] = getBiquadraticPatchCoefs(bezierI, bezierJ)

    coefsRawTemp = np.zeros((4, 7, 4, 4))

    uu2mat = np.array([[2.0, 2.0, 2.0], [-4.0, -4.0, -4.0], [2.0, 2.0, 2.0]]) / 3.0
    vv2mat = np.transpose(uu2mat)
    uv2mat = np.array([[1.0, 0.0, -1.0], [0.0, 0.0, 0.0], [-1.0, 0.0, 1.0]])
    uu3mat = np.array(
            [[3.0, 3.0, 3.0, 3.0], [-3.0, -3.0, -3.0, -3.0], [-3.0, -3.0, -3.0, -3.0], [3.0, 3.0, 3.0, 3.0]]) / 4.0
    vv3mat = np.transpose(uu3mat)
    uv3mat = np.array([[1.0, 0.0, 0.0, -1.0], [0.0, 0.0, 0.0, 0.0], [0.0, 0.0, 0.0, 0.0], [-1.0, 0.0, 0.0, 1.0]])

    biqBezCoefs = np.array([uu2mat, 2.0 * uv2mat, vv2mat])
    bicBezCoefs = np.array([uu3mat, 2.0 * uv3mat, vv3mat])

    whichCornerList = np.array([[0, 3], [1, 2]], dtype=int)

    indexCounter = 0

    p = 0
    print "Main Loop Fairness Coeffs"
    for q in range(quad_list.shape[0]):
        if q%100 == 0:
            print "processing quad %d of %d..." % (q, quad_list.shape[0])
        for j in range(4):
            for i in range(4):
                if (i == 0 or i == 3) and (j == 0 or j == 3):  # bicubic patches
                    whichCorner = whichCornerFun(i, j, whichCornerList)
                    indexMask = getExtraOrdCornerIndexMask(quad_list, AVertexList, B1VertexList, B2VertexList,
                                                           CVertexList, quad_control_point_indices, q, whichCorner)
                    numberOfEdges = indexMask.shape[1]

                    coefsRawTemp[0, 0:numberOfEdges, :, :] = ACoefsRaw[numberOfEdges - 1, 0:numberOfEdges, :, :]
                    coefsRawTemp[1, 0:numberOfEdges, :, :] = B1CoefsRaw[numberOfEdges - 1, 0:numberOfEdges, :, :]
                    coefsRawTemp[2, 0:numberOfEdges, :, :] = B2CoefsRaw[numberOfEdges - 1, 0:numberOfEdges, :, :]
                    coefsRawTemp[3, 0:numberOfEdges, :, :] = CCoefsRaw[numberOfEdges - 1, 0:numberOfEdges, :, :]

                    numberOfEntries = numberOfEdges*4

                    for matType in range(3):
                        bezier_points = np.squeeze(bicBezCoefs[matType, :, :])  # squeeze
                        data[indexCounter:(indexCounter + numberOfEntries)] = getPetersControlPointCoefs(bezier_points,
                                                                      coefsRawTemp[:, 0:numberOfEdges, :, :]).flatten()

                        rows[indexCounter:(indexCounter + numberOfEntries)] = p
                        cols[indexCounter:(indexCounter + numberOfEntries)] = indexMask.flatten()[:]
                        indexCounter += numberOfEntries

                        p += 1



                else:  # biquadratic patches
                    neighbourMask = get3x3ControlPointIndexMask(quad_list=quad_list,
                                                                quad_control_point_indices=quad_control_point_indices,
                                                                quad_index=q,
                                                                localIndexXY=np.array([i, j])).astype(int)  # correct??
                    numberOfEntries = 9

                    for matType in range(3):
                        bezier_points = np.squeeze(biqBezCoefs[matType, :, :])

                        data[indexCounter:(indexCounter + numberOfEntries)] = getPetersControlPointCoefs(bezier_points,
                                                                              ordinaryCoefsRaw).flatten()

                        rows[indexCounter:(indexCounter + numberOfEntries)] = p
                        cols[indexCounter:(indexCounter + numberOfEntries)] = neighbourMask.flatten()[:]
                        p += 1

                        indexCounter += numberOfEntries

    return ssp.coo_matrix((data, (rows, cols)), shape=(N, M))