import math 
import os.path 
import piper.app 
import piper.hbm 
import piper.KrigingDeformation 
project = piper.app.Project() 
projectFile = os.path.join("E:\\2318_Cybex\\03_Arbetsdokument\\Octave_code\\v0_6_0\\0A_Output_files\\51cm_95th\\Surface_Model_w_Joints_v0_0_1.pmr")
project.importModel(projectFile) 
targetFile = os.path.join("E:\\2318_Cybex\\03_Arbetsdokument\\Octave_code\\v0_6_0\\0A_Output_files\\51cm_95th\\tcp")
piper.app.loadTargetCPs(project, targetFile, "trg") 
sourceFile = os.path.join("E:\\2318_Cybex\\03_Arbetsdokument\\Octave_code\\v0_6_0\\0A_Output_files\\51cm_95th\\scp")
piper.app.loadSourceCPs(project, sourceFile, "src") 
cpPairs = piper.app.mapStringString({"trg": "src"}) 
project.model().metadata().interactionControlPoint("src").setGlobalAssociationSkin(1) 
project.model().metadata().interactionControlPoint("src").setGlobalAssociationBones(1) 
sourceCPs = piper.hbm.InteractionControlPoint() 
targetCPs = piper.hbm.InteractionControlPoint() 
project.collectControlPoints(sourceCPs, targetCPs, cpPairs) 
kr = piper.KrigingDeformation.IntermediateTargetsInterface(project.model()) 
project.moduleParameter().setInt("Kriging", "splitThresholdCP", 10000) 
kr.setControlPoints(sourceCPs, targetCPs) 
piper.app.applyCPScalingTarget(project, kr, False) 
resultDir = os.path.join("E:\\2318_Cybex\\03_Arbetsdokument\\Octave_code\\v0_6_0\\0A_Output_files\\51cm_95th\\morphed_outputs\\")
project.exportModel(resultDir) 
