Пример #1
0
def cameraHasDistortion(camera):
    if isClassicModel(camera):
        return cameraHasDistortionClassic(camera)
    else:
        lens = tde4.getCameraLens(camera)
        model = getCameraModel(camera)
        for parameterName in getLDmodelParameterList(model):
            defaultValue = tde4.getLDModelParameterDefault(
                model, parameterName)
            # distorsionMode
            dyndistmode = tde4.getLensDynamicDistortionMode(lens)
            if dyndistmode == "DISTORTION_STATIC":
                actualValue = tde4.getLensLDAdjustableParameter(
                    lens, parameterName, 1, 1)
                if defaultValue != actualValue:
                    return True
            else:
                num_frames = tde4.getCameraNoFrames(camera)
                for frame in range(1, num_frames + 1):
                    focal = tde4.getCameraFocalLength(camera, frame)
                    focus = tde4.getCameraFocus(camera, frame)
                    actualValue = tde4.getLensLDAdjustableParameter(
                        lens, parameterName, focal, focus)
                    if defaultValue != actualValue:
                        return True
        return False
def get_dynamic_distortion_mode(id_lens):
	try:
		dyndistmode	= tde4.getLensDynamicDistortionMode(id_lens)
	except:
# For 3DE4 Release 1:
		if tde4.getLensDynamicDistortionFlag(id_lens) == 1:
			dyndistmode = "DISTORTION_DYNAMIC_FOCAL_LENGTH"
		else:
			dyndistmode = "DISTORTION_STATIC"
	return dyndistmode
def get_dynamic_distortion_mode(id_lens):
	try:
		dyndistmode	= tde4.getLensDynamicDistortionMode(id_lens)
	except:
# For 3DE4 Release 1:
		if tde4.getLensDynamicDistortionFlag(id_lens) == 1:
			dyndistmode = "DISTORTION_DYNAMIC_FOCAL_LENGTH"
		else:
			dyndistmode = "DISTORTION_STATIC"
	return dyndistmode
Пример #4
0
def getOutSize(req, cameraIndex, cameraTmp):
    # get the actual image size from cameraTmp
    imageHeightInTmp = tde4.getCameraImageHeight(cameraTmp)
    imageWidthInTmp = tde4.getCameraImageWidth(cameraTmp)

    lensTmp = tde4.getCameraLens(cameraTmp)

    folcalParameter = getFocalParameters(lensTmp)

    # distorsionMode
    dyndistmode = tde4.getLensDynamicDistortionMode(lensTmp)

    log.debug('dyndistmode : ' + str(dyndistmode))

    if dyndistmode == "DISTORTION_STATIC":
        lensModelParameter = getLensModelParameter(camera=None,
                                                   lens=lensTmp,
                                                   frame=None)
        resOutTmp = get_bounding_box.calculateBoundigBox(
            imageWidthInTmp, imageHeightInTmp, "undistort", folcalParameter,
            lensModelParameter)
        imageWidthOuttmp = resOutTmp.width
        imageHeightOuttmp = resOutTmp.height
    else:
        imageHeightOuttmp = imageHeightInTmp
        imageWidthOuttmp = imageWidthInTmp
        for frame in range(1, tde4.getCameraNoFrames(cameraTmp) + 1):
            lensModelParameter = getLensModelParameter(camera=cameraTmp,
                                                       lens=lensTmp,
                                                       frame=frame)
            resOuttmp = get_bounding_box.calculateBoundigBox(
                imageWidthInTmp, imageHeightInTmp, "undistort",
                folcalParameter, lensModelParameter)
            if imageHeightOuttmp < resOuttmp.height:
                imageHeightOuttmp = resOuttmp.height
            if imageWidthOuttmp < resOuttmp.width:
                imageWidthOuttmp = resOuttmp.width

    if imageHeightInTmp > imageHeightOuttmp:
        imageHeightOuttmp = imageHeightInTmp
    if imageWidthInTmp > imageWidthOuttmp:
        imageWidthOuttmp = imageWidthInTmp

    log.debug('****************** lensModelParameter ********************')
    for key in lensModelParameter.keys():
        log.debug(key + ' : ' + str(lensModelParameter.get(key)))

    return imageHeightOuttmp, imageWidthOuttmp
Пример #5
0
def generateNukeNode(cam, direction, offset=0, index=0):
    lens = tde4.getCameraLens(cam)
    model = tde4.getLensLDModel(lens)
    num_frames = tde4.getCameraNoFrames(cam)
    w_fb_cm = tde4.getLensFBackWidth(lens)
    h_fb_cm = tde4.getLensFBackHeight(lens)
    lco_x_cm = tde4.getLensLensCenterX(lens)
    lco_y_cm = tde4.getLensLensCenterY(lens)
    pxa = tde4.getLensPixelAspect(lens)
    # xa,xb,ya,yb in unit coordinates, in this order.
    fov = tde4.getCameraFOV(cam)

    print 'camera: ', tde4.getCameraName(cam)
    print 'offset:', offset
    print 'lens:', tde4.getLensName(lens)
    print 'model: ', model

    nukeNode = []

    nukeNode.append('# Created by 3DEqualizer4 ')
    nukeNode.append('# using Export Nuke Distortion Nodes export script')
    nukeNode.append("LD" + tools.nukify_name(model) + ' {')
    nukeNode.append(' direction ' + direction)

    # write focal length curve if dynamic
    if tde4.getCameraZoomingFlag(cam):
        print 'dynamic focal length'
        dynFocalLength = []

        for frame in range(1, num_frames + 1):
            dynFocalLength.append('x%i' % (frame + offset))
            dynFocalLength.append(' %.7f ' %
                                  tde4.getCameraFocalLength(cam, frame))
        focalLenghtStr = "".join(dynFocalLength)
        nukeNode.append(' tde4_focal_length_cm {{curve ' + focalLenghtStr +
                        ' }}')

# write static focal length else
    else:
        print 'static focal length'
        focalLenghtStr = ' tde4_focal_length_cm %.7f '
        focalLenghtStr = focalLenghtStr % tde4.getCameraFocalLength(cam, 1)
        nukeNode.append(focalLenghtStr)

# write focus distance curve if dynamic
    try:
        if tde4.getCameraFocusMode(cam) == "FOCUS_DYNAMIC":
            print 'dynamic focus distance'
            dynFocusDistance = []
            for frame in range(1, num_frames + 1):
                dynFocusDistance.append('x%i' % (frame + offset))
                dynFocusDistance.append(' %.7f ' %
                                        tde4.getCameraFocus(cam, frame))
            focusDStr = "".join(dynFocusDistance)
            toWrite = ' tde4_custom_focus_distance_cm {{curve ' + focusDStr + '}}'
            nukeNode.append(toWrite)
    except:
        # For 3DE4 Release 1:
        pass
# write static focus distance else
    else:
        print 'static focus distance'
        try:
            cameraFocus = ' tde4_custom_focus_distance_cm %.7f '
            cameraFocus = cameraFocus % tde4.getCameraFocus(cam, 1)
            nukeNode.append(cameraFocus)
        except:
            # For 3DE4 Release 1:
            nukeNode.append(' tde4_custom_focus_distance_cm 100.0 ')


# write camera
    nukeNode.append(' tde4_filmback_width_cm %.7f ' % w_fb_cm)
    nukeNode.append(' tde4_filmback_height_cm %.7f ' % h_fb_cm)
    nukeNode.append(' tde4_lens_center_offset_x_cm %.7f ' % lco_x_cm)
    nukeNode.append(' tde4_lens_center_offset_y_cm %.7f ' % lco_y_cm)
    nukeNode.append(' tde4_pixel_aspect %.7f ' % pxa)
    nukeNode.append(' field_of_view_xa_unit %.7f ' % fov[0])
    nukeNode.append(' field_of_view_ya_unit %.7f ' % fov[2])
    nukeNode.append(' field_of_view_xb_unit %.7f ' % fov[1])
    nukeNode.append(' field_of_view_yb_unit %.7f ' % fov[3])
    nukeNode.append(' filter Simon')

    # dynamic distortion
    try:
        dyndistmode = tde4.getLensDynamicDistortionMode(lens)
    except:
        # For 3DE4 Release 1:
        if tde4.getLensDynamicDistortionFlag(lens) == 1:
            dyndistmode = "DISTORTION_DYNAMIC_FOCAL_LENGTH"
        else:
            dyndistmode = "DISTORTION_STATIC"

    if dyndistmode == "DISTORTION_STATIC":
        print 'static lens distortion'
        for para in (tools.getLDmodelParameterList(model)):
            distStr = ' %.7f ' % tde4.getLensLDAdjustableParameter(
                lens, para, 1, 1)
            nukeNode.append(' ' + tools.nukify_name(para) + distStr)
    else:
        print 'dynamic lens distortion,'
        # dynamic
        for para in (tools.getLDmodelParameterList(model)):

            lensCurve = []
            for frame in range(1, num_frames + 1):
                focal = tde4.getCameraFocalLength(cam, frame)
                focus = tde4.getCameraFocus(cam, frame)
                lensCurve.append('x%i' % (frame + offset))
                frameParam = tde4.getLensLDAdjustableParameter(
                    lens, para, focal, focus)
                lensCurve.append(' %.7f ' % frameParam)
            lensCurveStr = ' {{curve ' + "".join(lensCurve) + ' }}'
            nukeNode.append(' ' + tools.nukify_name(para) + lensCurveStr)

    nameNode = 'name ' + getLDNodeName(cam, direction, offset, index)
    nukeNode.append(nameNode)
    nukeNode.append('}')

    return nukeNode
def exportNukeDewarpNode(cam, offset, nuke_path):
    lens = tde4.getCameraLens(cam)
    model = tde4.getLensLDModel(lens)
    num_frames = tde4.getCameraNoFrames(cam)
    w_fb_cm = tde4.getLensFBackWidth(lens)
    h_fb_cm = tde4.getLensFBackHeight(lens)
    lco_x_cm = tde4.getLensLensCenterX(lens)
    lco_y_cm = tde4.getLensLensCenterY(lens)
    pxa = tde4.getLensPixelAspect(lens)
    # xa,xb,ya,yb in unit coordinates, in this order.
    fov = tde4.getCameraFOV(cam)

    print 'camera: ', tde4.getCameraName(cam)
    print 'offset:', offset
    print 'lens:', tde4.getLensName(lens)
    print 'model: ', model

    f = open(nuke_path, "w")
    try:
        f.write(
            '# Created by 3DEqualizer4 using Export Nuke Distortion Nodes export script\n'
        )
        f.write("LD" + nukify_name(model) + ' {\n')
        f.write(' direction undistort\n')

        # write focal length curve if dynamic
        if tde4.getCameraZoomingFlag(cam):
            print 'dynamic focal length'
            f.write(' tde4_focal_length_cm {{curve ')
            for frame in range(1, num_frames + 1):
                f.write('x%i' % (frame + offset))
                f.write(' %.7f ' % tde4.getCameraFocalLength(cam, frame))
            f.write('}}\n')
# write static focal length else
        else:
            print 'static focal length'
            f.write(' tde4_focal_length_cm %.7f \n' %
                    tde4.getCameraFocalLength(cam, 1))
# write focus distance curve if dynamic
        try:
            if tde4.getCameraFocusMode(cam) == "FOCUS_DYNAMIC":
                print 'dynamic focus distance'
                f.write(' tde4_custom_focus_distance_cm {{curve ')
                for frame in range(1, num_frames + 1):
                    f.write('x%i' % (frame + offset))
                    f.write(' %.7f ' % tde4.getCameraFocus(cam, frame))
                f.write('}}\n')
        except:
            # For 3DE4 Release 1:
            pass
# write static focus distance else
        else:
            print 'static focus distance'
            try:
                f.write(' tde4_custom_focus_distance_cm %.7f \n' %
                        tde4.getCameraFocus(cam, 1))
            except:
                # For 3DE4 Release 1:
                f.write(' tde4_custom_focus_distance_cm 100.0 \n')
# write camera
        f.write(' tde4_filmback_width_cm %.7f \n' % w_fb_cm)
        f.write(' tde4_filmback_height_cm %.7f \n' % h_fb_cm)
        f.write(' tde4_lens_center_offset_x_cm %.7f \n' % lco_x_cm)
        f.write(' tde4_lens_center_offset_y_cm %.7f \n' % lco_y_cm)
        f.write(' tde4_pixel_aspect %.7f \n' % pxa)
        f.write(' field_of_view_xa_unit %.7f \n' % fov[0])
        f.write(' field_of_view_ya_unit %.7f \n' % fov[2])
        f.write(' field_of_view_xb_unit %.7f \n' % fov[1])
        f.write(' field_of_view_yb_unit %.7f \n' % fov[3])

        # write distortion parameters
        #
        # dynamic distortion
        try:
            dyndistmode = tde4.getLensDynamicDistortionMode(lens)
        except:
            # For 3DE4 Release 1:
            if tde4.getLensDynamicDistortionFlag(lens) == 1:
                dyndistmode = "DISTORTION_DYNAMIC_FOCAL_LENGTH"
            else:
                dyndistmode = "DISTORTION_STATIC"

        old_api = True
        try:
            tde4.getLensLDAdjustableParameter(lens, para, 1)
        except:
            old_api = False

        if old_api:
            if dyndistmode == "DISTORTION_DYNAMIC_FOCAL_LENGTH":
                print 'dynamic lens distortion, focal length'
                # dynamic focal length (zoom)
                for para in (getLDmodelParameterList(model)):
                    f.write(' ' + nukify_name(para) + ' {{curve ')
                    for frame in range(1, num_frames + 1):
                        focal = tde4.getCameraFocalLength(cam, frame)
                        f.write('x%i' % (frame + offset))
                        f.write(' %.7f ' % tde4.getLensLDAdjustableParameter(
                            lens, para, focal))
                    f.write('}}\n')

            if dyndistmode == "DISTORTION_DYNAMIC_FOCUS_DISTANCE":
                print 'dynamic lens distortion, focus distance'
                # dynamic focus distance
                for para in (getLDmodelParameterList(model)):
                    f.write(' ' + nukify_name(para) + ' {{curve ')
                    for frame in range(1, num_frames + 1):
                        # Older Releases do not have Focus-methods.
                        try:
                            focus = tde4.getCameraFocus(cam, frame)
                        except:
                            focus = 100.0
                        f.write('x%i' % (frame + offset))
                        f.write(' %.7f ' % tde4.getLensLDAdjustableParameter(
                            lens, para, focus))
                    f.write('}}\n')

# static distortion
            if dyndistmode == "DISTORTION_STATIC":
                print 'static lens distortion'
                for para in (getLDmodelParameterList(model)):
                    f.write(' ' + nukify_name(para) + ' %.7f \n' %
                            tde4.getLensLDAdjustableParameter(lens, para, 1))
        else:
            # new API
            if dyndistmode == "DISTORTION_STATIC":
                print 'static lens distortion'
                for para in (getLDmodelParameterList(model)):
                    f.write(
                        ' ' + nukify_name(para) + ' %.7f \n' %
                        tde4.getLensLDAdjustableParameter(lens, para, 1, 1))
            else:
                print 'dynamic lens distortion,'
                # dynamic
                for para in (getLDmodelParameterList(model)):
                    f.write(' ' + nukify_name(para) + ' {{curve ')
                    for frame in range(1, num_frames + 1):
                        focal = tde4.getCameraFocalLength(cam, frame)
                        focus = tde4.getCameraFocus(cam, frame)
                        f.write('x%i' % (frame + offset))
                        f.write(' %.7f ' % tde4.getLensLDAdjustableParameter(
                            lens, para, focal, focus))
                    f.write('}}\n')

        f.write(' name LD_3DE4_' + decode_entities(tde4.getCameraName(cam)) +
                '\n')
        f.write('}\n')

    finally:
        f.close()
Пример #7
0
 def dynamic_distortion_mode(self):
     return tde4.getLensDynamicDistortionMode(self._lens_id)