def instantiate_observation(camera, pzInputMxs, pzOutputMxs): """ copy ``pzInputMxs`` to ``pzOutputMxs`` and create a sequence of maxwell cameras in pzOutputMxs according to ``camera`` Methods: instantiate_observation(CCamera camera, str pzInputMxs, str pzOutputMxs) Args: camera(CCamera): which to be instantiate pzInputMxs(str): the source path of the original maxwell scene file pzOutputMxs(str): the destination of the output maxwell scene file Note: * If the file of pzOutputMxs exists, it will be deleted except it is the same as pzInputMxs * It is highly recommended that the output file differ from the input file """ if pzInputMxs != pzOutputMxs: if Os.path.isfile(pzOutputMxs): print("Follwoing file exists: " + pzOutputMxs) print("We will remove it") ShUtil.rmtree(pzOutputMxs) ShUtil.copy(pzInputMxs, pzOutputMxs) curScene = MXS.readMXS(pzInputMxs) for frameIdx in range(camera.getFramesCount()): cameraName = "frame{}".format(frameIdx) camera.instantilize(curScene, cameraName, frameIdx) set_render_parameters(curScene, Os.path.basename(pzOutputMxs)) MXS.writeMXS(curScene, pzOutputMxs) curScene.freeScene()
def instantiate_frames(camera, pzInputMxs, pzOutputDir): if Os.path.isdir(pzOutputDir): print("Following directory exists: " + pzOutputDir) print("We will remove the content under it") ShUtil.rmtree(pzOutputDir) Os.mkdir(pzOutputDir) for frameIdx in range(camera.getFramesCount()): pzCurFile = Os.path.join(pzOutputDir, "frame{}.mxs".format(frameIdx)) ShUtil.copy(pzInputMxs, pzCurFile) curScene = MXS.readMXS(pzCurFile) cameraName = "camera" camera.instantilize(curScene, cameraName, frameIdx) set_render_parameters(curScene) MXS.writeMXS(curScene, pzCurFile) curScene.freeScene()