commit d08693c64c27986d22e127710dcd71b95075193d Author: Giovanni Di Grezia Date: Sun Aug 28 04:42:41 2016 +0200 First release. All scripts in v1. diff --git a/xg_2d_curve_editor.py b/xg_2d_curve_editor.py new file mode 100644 index 0000000..ac7a2ec --- /dev/null +++ b/xg_2d_curve_editor.py @@ -0,0 +1,718 @@ +# +# +# 3DE4.script.name: Adjust 2D Curve Local Filter +# +# 3DE4.script.version: v1.0 +# +# 3DE4.script.comment: Adjustment of 2d Points positions using 1D Fourier filter on different frames ranges +# +# 3DE4.script.gui: Main Window::Adjustment +# +# 3DE4.script.hide: false +# 3DE4.script.startup: false +# +# Giovanni Di Grezia 2016 +# http://www.xgiovio.com +# + + +script_base = tde4.get3DEInstallPath() + "/sys_data/py_scripts/" + +#script related +adj_script_name = "xg_2d_curve_editor_adj_script.py" + + +editor_width = 1200 +editor_height = 800 + +curvex = 0 +curvey = 0 +curvex_filtered_min = 0 +curvex_filtered_max = 0 +curvey_filtered_min = 0 +curvey_filtered_max = 0 +curvex_reloaded = 0 +curvey_reloaded = 0 +loaded_point = "" +loaded_cam = "" +import_status = False + +adj_parameters_list = [] + +first_time_range_adj = True + + +def callback_editor (req): + cam = tde4.getCurrentCamera() + tde4.setCurveAreaWidgetCursorPosition(req,"CurveAreaWidgetX",tde4.getCurrentFrame(cam),1) + tde4.setCurveAreaWidgetCursorPosition(req,"CurveAreaWidgetY",tde4.getCurrentFrame(cam),1) + +def list_adjs (req): + tde4.removeAllListWidgetItems(req,"ListAdj") + for i in range(len(adj_parameters_list)): + tde4.insertListWidgetItem(req,"ListAdj",adj_parameters_list[i],i) + + +def callback (req,label,event): + + global adj_parameters_list + global loaded_point + global loaded_cam + global import_status + global first_time_range_adj + + if label == "LoadCurve": + + cam = tde4.getCurrentCamera() + current_point_group = tde4.getCurrentPGroup() + selected_point = tde4.getPointList (current_point_group,1) + playback = tde4.getCameraPlaybackRange(cam) + firstframe = playback[0] + lastframe = playback[1] + + if first_time_range_adj: + tde4.setWidgetValue(req,"Range_Min",str(firstframe)) + tde4.setWidgetValue(req,"Range_Max",str(lastframe)) + first_time_range_adj = False + + + if len(selected_point) != 1 : + tde4.postQuestionRequester("Error","You need to select 1 2D point only","OK") + tde4.setWidgetSensitiveFlag(req,"FilterAllX",0) + tde4.setWidgetSensitiveFlag(req,"FilterAllY",0) + tde4.setWidgetSensitiveFlag(req,"FilterAllXAdd",0) + tde4.setWidgetSensitiveFlag(req,"FilterAllYAdd",0) + tde4.setWidgetSensitiveFlag(req,"FilterLocX",0) + tde4.setWidgetSensitiveFlag(req,"FilterLocY",0) + tde4.setWidgetSensitiveFlag(req,"FilterLocXAdd",0) + tde4.setWidgetSensitiveFlag(req,"FilterLocYAdd",0) + elif lastframe - firstframe < 2 : + tde4.postQuestionRequester("Error","You need a camera with at least 3 frames","OK") + tde4.setWidgetSensitiveFlag(req,"FilterAllX",0) + tde4.setWidgetSensitiveFlag(req,"FilterAllY",0) + tde4.setWidgetSensitiveFlag(req,"FilterAllXAdd",0) + tde4.setWidgetSensitiveFlag(req,"FilterAllYAdd",0) + tde4.setWidgetSensitiveFlag(req,"FilterLocX",0) + tde4.setWidgetSensitiveFlag(req,"FilterLocY",0) + tde4.setWidgetSensitiveFlag(req,"FilterLocXAdd",0) + tde4.setWidgetSensitiveFlag(req,"FilterLocYAdd",0) + else : + tde4.setWidgetSensitiveFlag(req,"FilterAllX",1) + tde4.setWidgetSensitiveFlag(req,"FilterAllY",1) + tde4.setWidgetSensitiveFlag(req,"FilterAllXAdd",1) + tde4.setWidgetSensitiveFlag(req,"FilterAllYAdd",1) + tde4.setWidgetSensitiveFlag(req,"FilterLocX",1) + tde4.setWidgetSensitiveFlag(req,"FilterLocY",1) + tde4.setWidgetSensitiveFlag(req,"FilterLocXAdd",1) + tde4.setWidgetSensitiveFlag(req,"FilterLocYAdd",1) + + name = tde4.getPointName(current_point_group,selected_point[0]) + tde4.setWidgetValue(req,"PointName",name) + tde4.setWidgetValue(req,"PointID",selected_point[0]) + + selected_point_positions = [] + for frame in range (firstframe, lastframe + 1): + if tde4.isPointPos2DValid(current_point_group,selected_point[0],cam,frame): + selected_point_position = tde4.getPointPosition2D(current_point_group,selected_point[0],cam,frame) + selected_point_positions.append([frame,selected_point_position[0],selected_point_position[1]]) + + + global curvex + global curvey + global curvex_filtered_min + global curvex_filtered_max + global curvey_filtered_min + global curvey_filtered_max + global curvex_reloaded + global curvey_reloaded + + + if curvex == 0 or loaded_point != selected_point[0] or loaded_cam!= cam: + + tde4.detachCurveAreaWidgetAllCurves(req,"CurveAreaWidgetX") + tde4.detachCurveAreaWidgetAllCurves(req,"CurveAreaWidgetY") + + + curvex = tde4.createCurve() + curvey = tde4.createCurve() + curvex_filtered_min = tde4.createCurve() + curvex_filtered_max = tde4.createCurve() + curvey_filtered_min = tde4.createCurve() + curvey_filtered_max = tde4.createCurve() + curvex_reloaded = 0 + curvey_reloaded = 0 + loaded_point = selected_point[0] + loaded_cam= cam + + tde4.removeAllListWidgetItems(req,"ListAdj") + adj_parameters_list = [] + + frame_min = 0 + frame_max = 0 + x_y_min = 0 + x_y_max = 0 + y_y_min = 0 + y_y_max = 0 + + first_x = True + first_y = True + for i in selected_point_positions: + c = tde4.createCurveKey(curvex,[i[0],i[1]]) + #tde4.setCurveKeyMode(curvex,c,"LINEAR") + #tde4.setCurveKeyFixedXFlag(curvex,c,1) + if first_x: + frame_min = i[0] + frame_max = i[0] + x_y_min = i[1] + x_y_max = i[1] + first_x = False + else: + if i[0] < frame_min: + frame_min = i[0] + if i[0] > frame_max: + frame_max = i[0] + if i[1] < x_y_min: + x_y_min = i[1] + if i[1] > x_y_max: + x_y_max = i[1] + + + c = tde4.createCurveKey(curvey,[i[0],i[2]]) + #tde4.setCurveKeyMode(curvey,c,"LINEAR") + #tde4.setCurveKeyFixedXFlag(curvey,c,1) + if first_y: + y_y_min = i[2] + y_y_max = i[2] + first_y = False + else: + if i[2] < y_y_min: + y_y_min = i[2] + if i[2] > y_y_max: + y_y_max = i[2] + + + tde4.attachCurveAreaWidgetCurve(req,"CurveAreaWidgetX",curvex,1,1,1,0) + tde4.attachCurveAreaWidgetCurve(req,"CurveAreaWidgetY",curvey,1,1,1,0) + + if not import_status: + if frame_min == frame_max: + tde4.setCurveAreaWidgetDimensions (req,"CurveAreaWidgetX",firstframe,lastframe,0,1) + tde4.setCurveAreaWidgetFOV (req,"CurveAreaWidgetX",firstframe,lastframe,0,1) + tde4.setCurveAreaWidgetDimensions (req,"CurveAreaWidgetY",firstframe,lastframe,0,1) + tde4.setCurveAreaWidgetFOV (req,"CurveAreaWidgetY",firstframe,lastframe,0,1) + else: + tde4.setCurveAreaWidgetDimensions (req,"CurveAreaWidgetX",frame_min,frame_max,x_y_min,x_y_max) + tde4.setCurveAreaWidgetFOV (req,"CurveAreaWidgetX",frame_min,frame_max,x_y_min,x_y_max) + tde4.setCurveAreaWidgetDimensions (req,"CurveAreaWidgetY",frame_min,frame_max,y_y_min,y_y_max) + tde4.setCurveAreaWidgetFOV (req,"CurveAreaWidgetY",frame_min,frame_max,y_y_min,y_y_max) + + else: + import_status = False + + tde4.setCurveAreaWidgetCursorPosition(req,"CurveAreaWidgetX",tde4.getCurrentFrame(cam),1) + tde4.setCurveAreaWidgetCursorPosition(req,"CurveAreaWidgetY",tde4.getCurrentFrame(cam),1) + else: + + curvex_reloaded_temp = tde4.createCurve() + curvey_reloaded_temp = tde4.createCurve() + + for i in selected_point_positions: + tde4.createCurveKey(curvex_reloaded_temp,[i[0],i[1]]) + tde4.createCurveKey(curvey_reloaded_temp,[i[0],i[2]]) + + + if curvex_reloaded!= 0 : + tde4.detachCurveAreaWidgetCurve(req,"CurveAreaWidgetX",curvex_reloaded) + curvex_reloaded = 0 + tde4.setWidgetSensitiveFlag(req,"RestoreCurve",0) + tde4.setWidgetSensitiveFlag(req,"ImportCurve",0) + + + if curvey_reloaded!= 0 : + tde4.detachCurveAreaWidgetCurve(req,"CurveAreaWidgetY",curvey_reloaded) + curvey_reloaded = 0 + tde4.setWidgetSensitiveFlag(req,"RestoreCurve",0) + tde4.setWidgetSensitiveFlag(req,"ImportCurve",0) + + pos_curvex = [] + pos_curvey = [] + pos_curvex_reloaded_temp=[] + pos_curvey_reloaded_temp=[] + + curvex_keys= tde4.getCurveKeyList(curvex,0) + curvey_keys= tde4.getCurveKeyList(curvey,0) + curvex_reloaded_temp_keys= tde4.getCurveKeyList(curvex_reloaded_temp,0) + curvey_reloaded_temp_keys= tde4.getCurveKeyList(curvey_reloaded_temp,0) + + for k in curvex_keys: + pos_curvex.append(tde4.getCurveKeyPosition(curvex,k)) + for k in curvey_keys: + pos_curvey.append(tde4.getCurveKeyPosition(curvey,k)) + for k in curvex_reloaded_temp_keys: + pos_curvex_reloaded_temp.append(tde4.getCurveKeyPosition(curvex_reloaded_temp,k)) + for k in curvey_reloaded_temp_keys: + pos_curvey_reloaded_temp.append(tde4.getCurveKeyPosition(curvey_reloaded_temp,k)) + + status = True + if len(pos_curvex) == len(pos_curvex_reloaded_temp): + for i in range(len(pos_curvex) ): + if pos_curvex[i] != pos_curvex_reloaded_temp[i]: + status = False + break + else: + status = False + if status == False: + curvex_reloaded = curvex_reloaded_temp + tde4.attachCurveAreaWidgetCurve(req,"CurveAreaWidgetX",curvex_reloaded,0,1,0,0) + tde4.setWidgetSensitiveFlag(req,"RestoreCurve",1) + tde4.setWidgetSensitiveFlag(req,"ImportCurve",1) + + status = True + if len(pos_curvey) == len(pos_curvey_reloaded_temp): + for i in range(len(pos_curvey) ): + if pos_curvey[i] != pos_curvey_reloaded_temp[i]: + status = False + break + else: + status = False + if status == False: + curvey_reloaded = curvey_reloaded_temp + tde4.attachCurveAreaWidgetCurve(req,"CurveAreaWidgetY",curvey_reloaded,0,1,0,0) + tde4.setWidgetSensitiveFlag(req,"RestoreCurve",1) + tde4.setWidgetSensitiveFlag(req,"ImportCurve",1) + + + + + elif label == "FilterAllX": + + if float(tde4.getWidgetValue(req,"FilterAll_Min")) > float(tde4.getWidgetValue(req,"FilterAll_Max")) : + tde4.postQuestionRequester("Error","Filter Min should be less than Filter Max","OK") + else: + if curvex_filtered_min!= 0 and curvex_filtered_max!= 0: + tde4.detachCurveAreaWidgetCurve(req,"CurveAreaWidgetX",curvex_filtered_min) + tde4.detachCurveAreaWidgetCurve(req,"CurveAreaWidgetX",curvex_filtered_max) + curvex_filtered_min = tde4.createCurve() + curvex_filtered_max = tde4.createCurve() + curvex_y_to_filter = [] + curvex_x = [] + curvex_keys= tde4.getCurveKeyList(curvex,0) + for k in curvex_keys: + pos = tde4.getCurveKeyPosition(curvex,k) + curvex_y_to_filter.append(pos[1]) + curvex_x.append(pos[0]) + + if len(curvex_y_to_filter) > 3: + curvex_y_filtered_min = tde4.filter1D(curvex_y_to_filter,float(tde4.getWidgetValue(req,"FilterAll_Min")),"FOURIER_FILTER") + curvex_y_filtered_max = tde4.filter1D(curvex_y_to_filter,float(tde4.getWidgetValue(req,"FilterAll_Max")),"FOURIER_FILTER") + else: + curvex_y_filtered_min = curvex_y_to_filter + curvex_y_filtered_max = curvex_y_to_filter + + for i in range(len(curvex_x)): + tde4.createCurveKey(curvex_filtered_min ,[curvex_x[i],curvex_y_filtered_min[i]]) + tde4.createCurveKey(curvex_filtered_max ,[curvex_x[i],curvex_y_filtered_max[i]]) + + + tde4.attachCurveAreaWidgetCurve(req,"CurveAreaWidgetX",curvex_filtered_min,1,0,0,0) + tde4.attachCurveAreaWidgetCurve(req,"CurveAreaWidgetX",curvex_filtered_max,0,0,1,0) + + elif label == "FilterAllY": + if float(tde4.getWidgetValue(req,"FilterAll_Min")) > float(tde4.getWidgetValue(req,"FilterAll_Max")) : + tde4.postQuestionRequester("Error","Filter Min should be less than Filter Max","OK") + else: + if curvey_filtered_min!= 0 and curvey_filtered_max!= 0: + tde4.detachCurveAreaWidgetCurve(req,"CurveAreaWidgetY",curvey_filtered_min) + tde4.detachCurveAreaWidgetCurve(req,"CurveAreaWidgetY",curvey_filtered_max) + + curvey_filtered_min = tde4.createCurve() + curvey_filtered_max = tde4.createCurve() + curvey_y_to_filter = [] + curvey_x = [] + curvey_keys= tde4.getCurveKeyList(curvey,0) + for k in curvey_keys: + pos = tde4.getCurveKeyPosition(curvey,k) + curvey_y_to_filter.append(pos[1]) + curvey_x.append(pos[0]) + + + if len(curvey_y_to_filter) > 3: + curvey_y_filtered_min = tde4.filter1D(curvey_y_to_filter,float(tde4.getWidgetValue(req,"FilterAll_Min")),"FOURIER_FILTER") + curvey_y_filtered_max = tde4.filter1D(curvey_y_to_filter,float(tde4.getWidgetValue(req,"FilterAll_Max")),"FOURIER_FILTER") + else: + curvey_y_filtered_min = curvey_y_to_filter + curvey_y_filtered_max = curvey_y_to_filter + + + for i in range(len(curvey_x)): + tde4.createCurveKey(curvey_filtered_min ,[curvey_x[i],curvey_y_filtered_min[i]]) + tde4.createCurveKey(curvey_filtered_max ,[curvey_x[i],curvey_y_filtered_max[i]]) + + tde4.attachCurveAreaWidgetCurve(req,"CurveAreaWidgetY",curvey_filtered_min,1,0,0,0) + tde4.attachCurveAreaWidgetCurve(req,"CurveAreaWidgetY",curvey_filtered_max,0,0,1,0) + + elif label == "FilterAllXAdd": + if float(tde4.getWidgetValue(req,"FilterAll_Min")) > float(tde4.getWidgetValue(req,"FilterAll_Max")) : + tde4.postQuestionRequester("Error","Filter Min should be less than Filter Max","OK") + else: + curvex_x = [] + curvex_keys= tde4.getCurveKeyList(curvex,0) + for k in curvex_keys: + pos = tde4.getCurveKeyPosition(curvex,k) + curvex_x.append(pos[0]) + adj_parameters_list.append(loaded_point + " " + "x" + " " + str(min(curvex_x)) + " " + str(max(curvex_x)) + " " + tde4.getWidgetValue(req,"FilterAll_Min") + " " + tde4.getWidgetValue(req,"FilterAll_Max") ) + list_adjs (req) + elif label == "FilterAllYAdd": + if float(tde4.getWidgetValue(req,"FilterAll_Min")) > float(tde4.getWidgetValue(req,"FilterAll_Max")) : + tde4.postQuestionRequester("Error","Filter Min should be less than Filter Max","OK") + else: + curvey_x = [] + curvey_keys= tde4.getCurveKeyList(curvey,0) + for k in curvey_keys: + pos = tde4.getCurveKeyPosition(curvey,k) + curvey_x.append(pos[0]) + adj_parameters_list.append(loaded_point + " " + "y" + " " + str(min(curvey_x)) + " " + str(max(curvey_x)) + " " + tde4.getWidgetValue(req,"FilterAll_Min") + " " + tde4.getWidgetValue(req,"FilterAll_Max") ) + list_adjs (req) + + elif label == "FilterLocX": + if float(tde4.getWidgetValue(req,"FilterLoc_Min")) > float(tde4.getWidgetValue(req,"FilterLoc_Max")) : + tde4.postQuestionRequester("Error","Filter Min should be less than Filter Max","OK") + elif float(tde4.getWidgetValue(req,"Range_Max")) - float(tde4.getWidgetValue(req,"Range_Min")) < 2: + tde4.postQuestionRequester("Error","Range Min Max should be at least 3 frames","OK") + else: + if curvex_filtered_min!= 0 and curvex_filtered_max!= 0: + tde4.detachCurveAreaWidgetCurve(req,"CurveAreaWidgetX",curvex_filtered_min) + tde4.detachCurveAreaWidgetCurve(req,"CurveAreaWidgetX",curvex_filtered_max) + curvex_filtered_min = tde4.createCurve() + curvex_filtered_max = tde4.createCurve() + curvex_y_to_filter = [] + curvex_x = [] + curvex_keys= tde4.getCurveKeyList(curvex,0) + for k in curvex_keys: + pos = tde4.getCurveKeyPosition(curvex,k) + if pos[0] >= float(tde4.getWidgetValue(req,"Range_Min")) and pos[0] <= float(tde4.getWidgetValue(req,"Range_Max")): + curvex_y_to_filter.append(pos[1]) + curvex_x.append(pos[0]) + + if len(curvex_y_to_filter) > 3: + curvex_y_filtered_min = tde4.filter1D(curvex_y_to_filter,float(tde4.getWidgetValue(req,"FilterLoc_Min")),"FOURIER_FILTER") + curvex_y_filtered_max = tde4.filter1D(curvex_y_to_filter,float(tde4.getWidgetValue(req,"FilterLoc_Max")),"FOURIER_FILTER") + else: + curvex_y_filtered_min = curvex_y_to_filter + curvex_y_filtered_max = curvex_y_to_filter + + for i in range(len(curvex_x)): + tde4.createCurveKey(curvex_filtered_min ,[curvex_x[i],curvex_y_filtered_min[i]]) + tde4.createCurveKey(curvex_filtered_max ,[curvex_x[i],curvex_y_filtered_max[i]]) + + + tde4.attachCurveAreaWidgetCurve(req,"CurveAreaWidgetX",curvex_filtered_min,1,0,0,0) + tde4.attachCurveAreaWidgetCurve(req,"CurveAreaWidgetX",curvex_filtered_max,0,0,1,0) + + elif label == "FilterLocY": + if float(tde4.getWidgetValue(req,"FilterLoc_Min")) > float(tde4.getWidgetValue(req,"FilterLoc_Max")) : + tde4.postQuestionRequester("Error","Filter Min should be less than Filter Max","OK") + elif float(tde4.getWidgetValue(req,"Range_Max")) - float(tde4.getWidgetValue(req,"Range_Min")) < 2: + tde4.postQuestionRequester("Error","Range Min Max should be at least 3 frames","OK") + else: + if curvey_filtered_min!= 0 and curvey_filtered_max!= 0: + tde4.detachCurveAreaWidgetCurve(req,"CurveAreaWidgetY",curvey_filtered_min) + tde4.detachCurveAreaWidgetCurve(req,"CurveAreaWidgetY",curvey_filtered_max) + + curvey_filtered_min = tde4.createCurve() + curvey_filtered_max = tde4.createCurve() + curvey_y_to_filter = [] + curvey_x = [] + curvey_keys= tde4.getCurveKeyList(curvey,0) + for k in curvey_keys: + pos = tde4.getCurveKeyPosition(curvey,k) + if pos[0] >= float(tde4.getWidgetValue(req,"Range_Min")) and pos[0] <= float(tde4.getWidgetValue(req,"Range_Max")): + curvey_y_to_filter.append(pos[1]) + curvey_x.append(pos[0]) + + if len(curvey_y_to_filter) > 3: + curvey_y_filtered_min = tde4.filter1D(curvey_y_to_filter,float(tde4.getWidgetValue(req,"FilterLoc_Min")),"FOURIER_FILTER") + curvey_y_filtered_max = tde4.filter1D(curvey_y_to_filter,float(tde4.getWidgetValue(req,"FilterLoc_Max")),"FOURIER_FILTER") + else: + curvey_y_filtered_min = curvey_y_to_filter + curvey_y_filtered_max = curvey_y_to_filter + + for i in range(len(curvey_x)): + tde4.createCurveKey(curvey_filtered_min ,[curvey_x[i],curvey_y_filtered_min[i]]) + tde4.createCurveKey(curvey_filtered_max ,[curvey_x[i],curvey_y_filtered_max[i]]) + + tde4.attachCurveAreaWidgetCurve(req,"CurveAreaWidgetY",curvey_filtered_min,1,0,0,0) + tde4.attachCurveAreaWidgetCurve(req,"CurveAreaWidgetY",curvey_filtered_max,0,0,1,0) + + elif label == "FilterLocXAdd": + if float(tde4.getWidgetValue(req,"FilterLoc_Min")) > float(tde4.getWidgetValue(req,"FilterLoc_Max")) : + tde4.postQuestionRequester("Error","Filter Min should be less than Filter Max","OK") + elif float(tde4.getWidgetValue(req,"Range_Max")) - float(tde4.getWidgetValue(req,"Range_Min")) < 2: + tde4.postQuestionRequester("Error","Range Min Max should be at least 3 frames","OK") + else: + adj_parameters_list.append(loaded_point + " " + "x" + " " + tde4.getWidgetValue(req,"Range_Min") + " " + tde4.getWidgetValue(req,"Range_Max") + " " + tde4.getWidgetValue(req,"FilterLoc_Min") + " " + tde4.getWidgetValue(req,"FilterLoc_Max") ) + list_adjs (req) + elif label == "FilterLocYAdd": + if float(tde4.getWidgetValue(req,"FilterLoc_Min")) > float(tde4.getWidgetValue(req,"FilterLoc_Max")) : + tde4.postQuestionRequester("Error","Filter Min should be less than Filter Max","OK") + elif float(tde4.getWidgetValue(req,"Range_Max")) - float(tde4.getWidgetValue(req,"Range_Min")) < 2: + tde4.postQuestionRequester("Error","Range Min Max should be at least 3 frames","OK") + else: + adj_parameters_list.append(loaded_point + " " + "y" + " " + tde4.getWidgetValue(req,"Range_Min") + " " +tde4.getWidgetValue(req,"Range_Max") + " " + tde4.getWidgetValue(req,"FilterLoc_Min") + " " + tde4.getWidgetValue(req,"FilterLoc_Max") ) + list_adjs (req) + elif label == "DeleteAdj": + for i in range(tde4.getListWidgetNoItems(req,"ListAdj") -1 , -1 , -1 ): + if tde4.getListWidgetItemSelectionFlag(req,"ListAdj",i) == 1: + userdata = tde4.getListWidgetItemUserdata(req,"ListAdj",i) + tde4.removeListWidgetItem(req,"ListAdj",i) + del adj_parameters_list [userdata] + elif label == "DeleteAdjAll": + tde4.removeAllListWidgetItems(req,"ListAdj") + adj_parameters_list = [] + elif label == "SendAdj": + + for i in range(tde4.getListWidgetNoItems(req,"ListAdj")): + if tde4.getListWidgetItemSelectionFlag(req,"ListAdj",i) == 1: + userdata = tde4.getListWidgetItemUserdata(req,"ListAdj",i) + param = adj_parameters_list [userdata].split() + pointid_curve_start_end = str(param[0]) + " " + str(param[1]) + " " + str(param[2]) + " " + str(param[3]) + filter_start = param[4] + filter_end = param[5] + tde4.createParameterAdjustScript(script_base + adj_script_name,"filter adj " + pointid_curve_start_end,pointid_curve_start_end ,float(filter_start),float(filter_end)) + elif label == "SendAdjAll": + for i in range(tde4.getListWidgetNoItems(req,"ListAdj")): + userdata = tde4.getListWidgetItemUserdata(req,"ListAdj",i) + param = adj_parameters_list [userdata].split() + pointid_curve_start_end = str(param[0]) + " " + str(param[1]) + " " + str(param[2]) + " " + str(param[3]) + filter_start = param[4] + filter_end = param[5] + tde4.createParameterAdjustScript(script_base + adj_script_name,"filter adj " + pointid_curve_start_end,pointid_curve_start_end ,float(filter_start),float(filter_end)) + + elif label == "RestoreCurve": + cam = tde4.getCurrentCamera() + current_point_group = tde4.getCurrentPGroup() + playback = tde4.getCameraPlaybackRange(cam) + firstframe = playback[0] + lastframe = playback[1] + + + pos_x = [] + pos_y = [] + curvex_keys= tde4.getCurveKeyList(curvex,0) + for k in curvex_keys: + pos_x.append(tde4.getCurveKeyPosition(curvex,k)) + curvey_keys= tde4.getCurveKeyList(curvey,0) + for k in curvey_keys: + pos_y.append(tde4.getCurveKeyPosition(curvey,k)) + + for i in range(len(pos_x)): + tde4.setPointPosition2D(current_point_group,loaded_point,cam,int(pos_x[i][0]),[pos_x[i][1],pos_y[i][1]]) + + callback(req,"ImportCurve","") + tde4.setWidgetSensitiveFlag(req,"RestoreCurve",0) + tde4.setWidgetSensitiveFlag(req,"ImportCurve",0) + + elif label == "ImportCurve": + loaded_point = "" + import_status = True + callback(req,"LoadCurve","") + tde4.setWidgetSensitiveFlag(req,"RestoreCurve",0) + tde4.setWidgetSensitiveFlag(req,"ImportCurve",0) + + + + +editor = tde4.createCustomRequester() + + +tde4.addCurveAreaWidget(editor,"CurveAreaWidgetX","X",0) +tde4.setWidgetAttachModes(editor,"CurveAreaWidgetX","ATTACH_WINDOW","ATTACH_WINDOW","ATTACH_WINDOW","ATTACH_WINDOW") +tde4.setWidgetOffsets(editor,"CurveAreaWidgetX",25,280,0,450) + +tde4.addCurveAreaWidget(editor,"CurveAreaWidgetY","Y",0) +tde4.setWidgetLinks(editor,"CurveAreaWidgetY","","","CurveAreaWidgetX","") +tde4.setWidgetAttachModes(editor,"CurveAreaWidgetY","ATTACH_WINDOW","ATTACH_WINDOW","ATTACH_WIDGET","ATTACH_WINDOW") +tde4.setWidgetOffsets(editor,"CurveAreaWidgetY",25,280,5,100) + +tde4.addListWidget(editor,"ListAdj","",1,0) +tde4.setWidgetLinks(editor,"ListAdj","CurveAreaWidgetX","","","") +tde4.setWidgetAttachModes(editor,"ListAdj","ATTACH_WIDGET","ATTACH_WINDOW","ATTACH_WINDOW","ATTACH_WINDOW") +tde4.setWidgetOffsets(editor,"ListAdj",5,5,0,155) + + +tde4.addButtonWidget(editor,"DeleteAdj","Delete",100,10) +tde4.setWidgetSize(editor,"DeleteAdj",50,50) +tde4.setWidgetLinks(editor,"DeleteAdj","CurveAreaWidgetY","","ListAdj","") +tde4.setWidgetAttachModes(editor,"DeleteAdj","ATTACH_WIDGET","ATTACH_AS_IS","ATTACH_WIDGET","ATTACH_AS_IS") +tde4.setWidgetCallbackFunction(editor,"DeleteAdj","callback") + +tde4.addButtonWidget(editor,"DeleteAdjAll","Delete All",100,10) +tde4.setWidgetSize(editor,"DeleteAdjAll",50,50) +tde4.setWidgetLinks(editor,"DeleteAdjAll","DeleteAdj","","ListAdj","") +tde4.setWidgetAttachModes(editor,"DeleteAdjAll","ATTACH_WIDGET","ATTACH_AS_IS","ATTACH_WIDGET","ATTACH_AS_IS") +tde4.setWidgetCallbackFunction(editor,"DeleteAdjAll","callback") + +tde4.addButtonWidget(editor,"SendAdj","Send Adj",100,10) +tde4.setWidgetSize(editor,"SendAdj",50,50) +tde4.setWidgetLinks(editor,"SendAdj","DeleteAdjAll","","ListAdj","") +tde4.setWidgetAttachModes(editor,"SendAdj","ATTACH_WIDGET","ATTACH_AS_IS","ATTACH_WIDGET","ATTACH_AS_IS") +tde4.setWidgetCallbackFunction(editor,"SendAdj","callback") + +tde4.addButtonWidget(editor,"SendAdjAll","Send Adj All",100,10) +tde4.setWidgetSize(editor,"SendAdjAll",80,50) +tde4.setWidgetLinks(editor,"SendAdjAll","SendAdj","","ListAdj","") +tde4.setWidgetAttachModes(editor,"SendAdjAll","ATTACH_WIDGET","ATTACH_AS_IS","ATTACH_WIDGET","ATTACH_AS_IS") +tde4.setWidgetCallbackFunction(editor,"SendAdjAll","callback") + + + + +tde4.addButtonWidget(editor,"LoadCurve","LoadCurve",100,10) +tde4.setWidgetSize(editor,"LoadCurve",100,50) +tde4.setWidgetLinks(editor,"LoadCurve","","","CurveAreaWidgetY","") +tde4.setWidgetAttachModes(editor,"LoadCurve","ATTACH_WINDOW","ATTACH_AS_IS","ATTACH_WIDGET","ATTACH_AS_IS") +tde4.setWidgetCallbackFunction(editor,"LoadCurve","callback") + +tde4.addButtonWidget(editor,"RestoreCurve","Restore",100,10) +tde4.setWidgetSize(editor,"RestoreCurve",100,50) +tde4.setWidgetLinks(editor,"RestoreCurve","LoadCurve","","CurveAreaWidgetY","") +tde4.setWidgetAttachModes(editor,"RestoreCurve","ATTACH_WIDGET","ATTACH_AS_IS","ATTACH_WIDGET","ATTACH_AS_IS") +tde4.setWidgetSensitiveFlag(editor,"RestoreCurve",0) +tde4.setWidgetCallbackFunction(editor,"RestoreCurve","callback") + +tde4.addButtonWidget(editor,"ImportCurve","Import",100,10) +tde4.setWidgetSize(editor,"ImportCurve",100,50) +tde4.setWidgetLinks(editor,"ImportCurve","RestoreCurve","","CurveAreaWidgetY","") +tde4.setWidgetAttachModes(editor,"ImportCurve","ATTACH_WIDGET","ATTACH_AS_IS","ATTACH_WIDGET","ATTACH_AS_IS") +tde4.setWidgetSensitiveFlag(editor,"ImportCurve",0) +tde4.setWidgetCallbackFunction(editor,"ImportCurve","callback") + + +tde4.addTextFieldWidget(editor,"FilterAll_Min","","0.1") +tde4.setWidgetLinks(editor,"FilterAll_Min","ImportCurve","ImportCurve","CurveAreaWidgetY","") +tde4.setWidgetAttachModes(editor,"FilterAll_Min","ATTACH_WIDGET","ATTACH_OPPOSITE_WIDGET","ATTACH_WIDGET","ATTACH_AS_IS") +tde4.setWidgetSize(editor,"FilterAll_Min",50,50) +tde4.setWidgetOffsets(editor,"FilterAll_Min",50,-80,5,0) + +tde4.addTextFieldWidget(editor,"FilterAll_Max","","2") +tde4.setWidgetLinks(editor,"FilterAll_Max","FilterAll_Min","FilterAll_Min","CurveAreaWidgetY","") +tde4.setWidgetAttachModes(editor,"FilterAll_Max","ATTACH_WIDGET","ATTACH_OPPOSITE_WIDGET","ATTACH_WIDGET","ATTACH_AS_IS") +tde4.setWidgetSize(editor,"FilterAll_Max",50,50) +tde4.setWidgetOffsets(editor,"FilterAll_Max",10,-40,5,0) + + +tde4.addButtonWidget(editor,"FilterAllX","Global Preview X",100,10) +tde4.setWidgetSize(editor,"FilterAllX",150,50) +tde4.setWidgetLinks(editor,"FilterAllX","FilterAll_Max","","CurveAreaWidgetY","") +tde4.setWidgetAttachModes(editor,"FilterAllX","ATTACH_WIDGET","ATTACH_AS_IS","ATTACH_WIDGET","ATTACH_AS_IS") +tde4.setWidgetSensitiveFlag(editor,"FilterAllX",0) +tde4.setWidgetCallbackFunction(editor,"FilterAllX","callback") + +tde4.addButtonWidget(editor,"FilterAllY","Y",100,10) +tde4.setWidgetSize(editor,"FilterAllY",20,50) +tde4.setWidgetLinks(editor,"FilterAllY","FilterAllX","","CurveAreaWidgetY","") +tde4.setWidgetAttachModes(editor,"FilterAllY","ATTACH_WIDGET","ATTACH_AS_IS","ATTACH_WIDGET","ATTACH_AS_IS") +tde4.setWidgetSensitiveFlag(editor,"FilterAllY",0) +tde4.setWidgetCallbackFunction(editor,"FilterAllY","callback") + +tde4.addButtonWidget(editor,"FilterAllXAdd","+X",100,10) +tde4.setWidgetSize(editor,"FilterAllXAdd",25,50) +tde4.setWidgetLinks(editor,"FilterAllXAdd","FilterAllY","","CurveAreaWidgetY","") +tde4.setWidgetAttachModes(editor,"FilterAllXAdd","ATTACH_WIDGET","ATTACH_AS_IS","ATTACH_WIDGET","ATTACH_AS_IS") +tde4.setWidgetSensitiveFlag(editor,"FilterAllXAdd",0) +tde4.setWidgetCallbackFunction(editor,"FilterAllXAdd","callback") + +tde4.addButtonWidget(editor,"FilterAllYAdd","+Y",100,10) +tde4.setWidgetSize(editor,"FilterAllYAdd",25,50) +tde4.setWidgetLinks(editor,"FilterAllYAdd","FilterAllXAdd","","CurveAreaWidgetY","") +tde4.setWidgetAttachModes(editor,"FilterAllYAdd","ATTACH_WIDGET","ATTACH_AS_IS","ATTACH_WIDGET","ATTACH_AS_IS") +tde4.setWidgetSensitiveFlag(editor,"FilterAllYAdd",0) +tde4.setWidgetCallbackFunction(editor,"FilterAllYAdd","callback") + + + + +tde4.addTextFieldWidget(editor,"FilterLoc_Min","","0.1") +tde4.setWidgetLinks(editor,"FilterLoc_Min","FilterAllYAdd","FilterAllYAdd","CurveAreaWidgetY","") +tde4.setWidgetAttachModes(editor,"FilterLoc_Min","ATTACH_WIDGET","ATTACH_OPPOSITE_WIDGET","ATTACH_WIDGET","ATTACH_AS_IS") +tde4.setWidgetSize(editor,"FilterLoc_Min",50,50) +tde4.setWidgetOffsets(editor,"FilterLoc_Min",60,-90,5,0) + +tde4.addTextFieldWidget(editor,"FilterLoc_Max","","2") +tde4.setWidgetLinks(editor,"FilterLoc_Max","FilterLoc_Min","FilterLoc_Min","CurveAreaWidgetY","") +tde4.setWidgetAttachModes(editor,"FilterLoc_Max","ATTACH_WIDGET","ATTACH_OPPOSITE_WIDGET","ATTACH_WIDGET","ATTACH_AS_IS") +tde4.setWidgetSize(editor,"FilterLoc_Max",50,50) +tde4.setWidgetOffsets(editor,"FilterLoc_Max",10,-40,5,0) + + +tde4.addButtonWidget(editor,"FilterLocX","Local Preview X",100,10) +tde4.setWidgetSize(editor,"FilterLocX",150,50) +tde4.setWidgetLinks(editor,"FilterLocX","FilterLoc_Max","","CurveAreaWidgetY","") +tde4.setWidgetAttachModes(editor,"FilterLocX","ATTACH_WIDGET","ATTACH_AS_IS","ATTACH_WIDGET","ATTACH_AS_IS") +tde4.setWidgetSensitiveFlag(editor,"FilterLocX",0) +tde4.setWidgetCallbackFunction(editor,"FilterLocX","callback") + +tde4.addButtonWidget(editor,"FilterLocY","Y",100,10) +tde4.setWidgetSize(editor,"FilterLocY",20,50) +tde4.setWidgetLinks(editor,"FilterLocY","FilterLocX","","CurveAreaWidgetY","") +tde4.setWidgetAttachModes(editor,"FilterLocY","ATTACH_WIDGET","ATTACH_AS_IS","ATTACH_WIDGET","ATTACH_AS_IS") +tde4.setWidgetSensitiveFlag(editor,"FilterLocY",0) +tde4.setWidgetCallbackFunction(editor,"FilterLocY","callback") + +tde4.addButtonWidget(editor,"FilterLocXAdd","+X",100,10) +tde4.setWidgetSize(editor,"FilterLocXAdd",25,50) +tde4.setWidgetLinks(editor,"FilterLocXAdd","FilterLocY","","CurveAreaWidgetY","") +tde4.setWidgetAttachModes(editor,"FilterLocXAdd","ATTACH_WIDGET","ATTACH_AS_IS","ATTACH_WIDGET","ATTACH_AS_IS") +tde4.setWidgetSensitiveFlag(editor,"FilterLocXAdd",0) +tde4.setWidgetCallbackFunction(editor,"FilterLocXAdd","callback") + +tde4.addButtonWidget(editor,"FilterLocYAdd","+Y",100,10) +tde4.setWidgetSize(editor,"FilterLocYAdd",25,50) +tde4.setWidgetLinks(editor,"FilterLocYAdd","FilterLocXAdd","","CurveAreaWidgetY","") +tde4.setWidgetAttachModes(editor,"FilterLocYAdd","ATTACH_WIDGET","ATTACH_AS_IS","ATTACH_WIDGET","ATTACH_AS_IS") +tde4.setWidgetSensitiveFlag(editor,"FilterLocYAdd",0) +tde4.setWidgetCallbackFunction(editor,"FilterLocYAdd","callback") + + +tde4.addTextFieldWidget(editor,"Range_Min","","1") +tde4.setWidgetLinks(editor,"Range_Min","FilterLocYAdd","FilterLocYAdd","CurveAreaWidgetY","") +tde4.setWidgetAttachModes(editor,"Range_Min","ATTACH_WIDGET","ATTACH_OPPOSITE_WIDGET","ATTACH_WIDGET","ATTACH_AS_IS") +tde4.setWidgetSize(editor,"Range_Min",50,50) +tde4.setWidgetOffsets(editor,"Range_Min",10,-40,5,0) + +tde4.addTextFieldWidget(editor,"Range_Max","","3") +tde4.setWidgetLinks(editor,"Range_Max","Range_Min","Range_Min","CurveAreaWidgetY","") +tde4.setWidgetAttachModes(editor,"Range_Max","ATTACH_WIDGET","ATTACH_OPPOSITE_WIDGET","ATTACH_WIDGET","ATTACH_AS_IS") +tde4.setWidgetSize(editor,"Range_Max",50,50) +tde4.setWidgetOffsets(editor,"Range_Max",10,-40,5,0) + + + + + +tde4.addTextFieldWidget(editor,"PointName","Loaded Point Name","") +tde4.setWidgetSensitiveFlag(editor,"PointName",0) +tde4.setWidgetAttachModes(editor,"PointName","ATTACH_WINDOW","ATTACH_WINDOW","ATTACH_NONE","ATTACH_WINDOW") +tde4.setWidgetSize(editor,"PointName",20,20) +tde4.setWidgetOffsets(editor,"PointName",150,400,0,10) + + +tde4.addTextFieldWidget(editor,"PointID","Loaded Point ID","") +tde4.setWidgetSensitiveFlag(editor,"PointID",0) +tde4.setWidgetLinks(editor,"PointID","PointName","","","") +tde4.setWidgetAttachModes(editor,"PointID","ATTACH_WIDGET","ATTACH_WINDOW","ATTACH_NONE","ATTACH_WINDOW") +tde4.setWidgetSize(editor,"PointID",20,20) +tde4.setWidgetOffsets(editor,"PointID",150,50,0,10) + +''' + +tde4.addScaleWidget(editor,"scale1","scale1label","INT",-100,100,0,1) +tde4.setWidgetCallbackFunction(editor,"scale1","callback_scale") + +tde4.addTextFieldWidget(editor,"text","textlabel","0 0 0 0") + +''' + + + +tde4.postCustomRequesterAndContinue (editor,"2D Curve Local Filter Editor",editor_width,editor_height,"callback_editor") diff --git a/xg_2d_curve_editor_adj_script.py b/xg_2d_curve_editor_adj_script.py new file mode 100644 index 0000000..d03c326 --- /dev/null +++ b/xg_2d_curve_editor_adj_script.py @@ -0,0 +1,65 @@ +# +# +# 3DE4.script.hide: true +# 3DE4.script.startup: false +# +# Giovanni Di Grezia 2016 +# http://www.xgiovio.com +# + + +import math + +#init +current_value = tde4.getParameterAdjustCurrentValue() +best_value = tde4.getParameterAdjustCurrentValue() +get_custom_data = tde4.getParameterAdjustCustomParameters() +running = tde4.getParameterAdjustPhaseRunningFlag() + +# script specific +params = get_custom_data.split() +point_id = params[0] +curve = params[1] +start = math.floor(float(params[2])) +end = math.floor(float(params[3])) + + +cam = tde4.getCurrentCamera() +current_point_group = tde4.getCurrentPGroup() +playback = tde4.getCameraPlaybackRange(cam) +firstframe = playback[0] +lastframe = playback[1] + + + +selected_point_positions = [] +points_to_filter = [] +points_filtered = [] +for frame in range (firstframe, lastframe + 1): + if frame >= start and frame <= end and tde4.isPointPos2DValid(current_point_group,point_id,cam,frame): + selected_point_position = tde4.getPointPosition2D(current_point_group,point_id,cam,frame) + selected_point_positions.append([frame,selected_point_position[0],selected_point_position[1]]) + if curve =="x": + points_to_filter.append(selected_point_position[0]) + else: + points_to_filter.append(selected_point_position[1]) + +points_filtered = tde4.filter1D(points_to_filter,current_value,"FOURIER_FILTER") + +if (running): + #calculating + for i in range(len(selected_point_positions)): + if curve =="x": + tde4.applyParameterAdjustDataModification("project.pgroups.@" + current_point_group +".points.@" + point_id + ".cameras.@" + cam +".frame." + str(selected_point_positions[i][0]) + ".position_2d[0]",points_filtered[i]) + else: + tde4.applyParameterAdjustDataModification("project.pgroups.@" + current_point_group +".points.@" + point_id + ".cameras.@" + cam +".frame." + str(selected_point_positions[i][0]) + ".position_2d[1]",points_filtered[i]) +else: + #transfer_to_3de + for i in range(len(selected_point_positions)): + if curve =="x": + tde4.setPointPosition2D(current_point_group,point_id,cam, selected_point_positions[i][0], [ points_filtered[i],selected_point_positions[i][2]] ) + else: + tde4.setPointPosition2D(current_point_group,point_id,cam, selected_point_positions[i][0], [ selected_point_positions[i][1],points_filtered[i]] ) + + + diff --git a/xg_backup_2d_curves.py b/xg_backup_2d_curves.py new file mode 100644 index 0000000..fc936c9 --- /dev/null +++ b/xg_backup_2d_curves.py @@ -0,0 +1,28 @@ +# +# +# 3DE4.script.name: Backup 2D Curves +# +# 3DE4.script.version: v1.0 +# +# 3DE4.script.gui: Manual Tracking::Edit +# +# 3DE4.script.comment: Backup 2D Curves in memory +# 3DE4.script.gui.button: Manual Tracking::Backup, align-bottom-right, 120, 20 +# +# +# +# Giovanni Di Grezia 2016 +# http://www.xgiovio.com +# + +import xg_backup_restore_2d_curves +xg_backup_restore_2d_curves = reload(xg_backup_restore_2d_curves) + +xg_backup_restore_2d_curves.backup () + + + + + + + diff --git a/xg_backup_restore_2d_curves.py b/xg_backup_restore_2d_curves.py new file mode 100644 index 0000000..4d7f6e6 --- /dev/null +++ b/xg_backup_restore_2d_curves.py @@ -0,0 +1,50 @@ +# 3DE4.script.hide: true +# 3DE4.script.startup: false +# +# Giovanni Di Grezia 2016 +# http://www.xgiovio.com +# + +import tde4 + +global backup_2d_curves +try: + backup_2d_curves +except : + backup_2d_curves = {} + +cam = tde4.getCurrentCamera() +current_point_group = tde4.getCurrentPGroup() +selected_points = tde4.getPointList (current_point_group,1) +playback = tde4.getCameraPlaybackRange(cam) +firstframe = playback[0] +lastframe = playback[1] + +def backup () : + for point in selected_points: + backup_2d_curves[point] = [] + for frame in range (firstframe, lastframe + 1): + if tde4.isPointPos2DValid(current_point_group,point,cam,frame): + selected_point_position = tde4.getPointPosition2D(current_point_group,point,cam,frame) + selected_point_position_status = tde4.getPointStatus2D(current_point_group,point,cam,frame) + backup_2d_curves[point].append([frame,selected_point_position,selected_point_position_status]) + +def restore (): + for point in selected_points: + if point in backup_2d_curves: + tde4.deletePointCurve2D (current_point_group,point,cam) + for i in backup_2d_curves[point]: + tde4.setPointPosition2D(current_point_group,point,cam,i[0],i[1]) + for i in backup_2d_curves[point]: + tde4.setPointStatus2D(current_point_group,point,cam,i[0],i[2]) + + + + + + + + + + + diff --git a/xg_copy_2d_curve.py b/xg_copy_2d_curve.py new file mode 100644 index 0000000..94b797f --- /dev/null +++ b/xg_copy_2d_curve.py @@ -0,0 +1,25 @@ +# +# +# 3DE4.script.name: Copy 2D Curve +# +# 3DE4.script.version: v1.0 +# +# 3DE4.script.comment: Copy 2D Curve in memory +# +# 3DE4.script.gui: Manual Tracking Controls::Edit +# 3DE4.script.gui.button: Manual Tracking Controls::Copy, align-bottom-left, 100, 20 + + +# 3DE4.script.hide: false +# 3DE4.script.startup: false +# +# Giovanni Di Grezia 2016 +# http://www.xgiovio.com +# + + + +import xg_copy_paste_2d_curves +xg_copy_paste_2d_curves = reload(xg_copy_paste_2d_curves) + +xg_copy_paste_2d_curves.copy () diff --git a/xg_copy_paste_2d_curves.py b/xg_copy_paste_2d_curves.py new file mode 100644 index 0000000..b246e7b --- /dev/null +++ b/xg_copy_paste_2d_curves.py @@ -0,0 +1,117 @@ +# 3DE4.script.hide: true +# 3DE4.script.startup: false +# +# Giovanni Di Grezia 2016 +# http://www.xgiovio.com +# + +import tde4 + +global copied_2d_curve +try: + copied_2d_curve +except : + copied_2d_curve = {} + +cam = tde4.getCurrentCamera() +current_point_group = tde4.getCurrentPGroup() +selected_points = tde4.getPointList (current_point_group,1) +playback = tde4.getCameraPlaybackRange(cam) +firstframe = playback[0] +lastframe = playback[1] + +def copy () : + if len(selected_points) != 1 : + tde4.postQuestionRequester("Error","You need to select 1 2D point","OK") + else: + for point in selected_points: + for frame in range (firstframe, lastframe + 1): + if tde4.isPointPos2DValid(current_point_group,point,cam,frame): + selected_point_position = tde4.getPointPosition2D(current_point_group,point,cam,frame) + copied_2d_curve[frame] = selected_point_position + + + +def paste (adapt_to_keyframes = False, inside_only = False): + if len(selected_points) != 1 : + tde4.postQuestionRequester("Error","You need to select 1 2D point","OK") + else: + for point in selected_points: + if adapt_to_keyframes : + k_pos = {} + for frame in range (firstframe, lastframe + 1): + point_status = tde4.getPointStatus2D(current_point_group,point,cam,frame) + if point_status == "POINT_KEYFRAME" or point_status == "POINT_KEYFRAME_END": + pos = tde4.getPointPosition2D(current_point_group,point,cam,frame) + k_pos[frame]= pos + + tde4.deletePointCurve2D (current_point_group,point,cam) + + if not adapt_to_keyframes or len(k_pos) == 0 : + for frame in copied_2d_curve: + tde4.setPointPosition2D(current_point_group,point,cam,frame,copied_2d_curve[frame]) + else: + k_pos_to_delete = [] + for frame in k_pos: + if frame in copied_2d_curve: + copied_2d_curve_x = copied_2d_curve[frame][0] + copied_2d_curve_y = copied_2d_curve[frame][1] + k_pos_x = k_pos[frame][0] + k_pos_y = k_pos[frame][1] + offset_x = k_pos_x - copied_2d_curve_x + offset_y = k_pos_y - copied_2d_curve_y + k_pos[frame] = [offset_x,offset_y] + else : + k_pos_to_delete.append(frame) + for frame in k_pos_to_delete: + del k_pos[frame] + + + if len(k_pos) > 0: + #extend keyframes to source curve range + k_pos_extended = {} + + min_frame_k_pos = min(k_pos) + max_frame_k_pos = max(k_pos) + + min_frame_copied_2d_curve = min(copied_2d_curve) + max_frame_copied_2d_curve = max(copied_2d_curve) + + if min_frame_k_pos != min_frame_copied_2d_curve and not inside_only: + k_pos_extended[min_frame_copied_2d_curve] = k_pos[min_frame_k_pos] + for frame in k_pos: + k_pos_extended[frame] = k_pos[frame] + if max_frame_k_pos != max_frame_copied_2d_curve and not inside_only: + k_pos_extended[max_frame_copied_2d_curve] = k_pos[max_frame_k_pos] + + + k_pos_extended_keys = k_pos_extended.keys() + k_pos_extended_keys.sort() + + for i in range(len(k_pos_extended_keys) - 1): + print + f0 = k_pos_extended_keys[i] + f1 = k_pos_extended_keys[i + 1] + xo0 = k_pos_extended[k_pos_extended_keys[i]][0] + yo0 = k_pos_extended[k_pos_extended_keys[i]][1] + xo1 = k_pos_extended[k_pos_extended_keys[i+ 1]][0] + yo1 = k_pos_extended[k_pos_extended_keys[i + 1]][1] + # linear deform step + for f in range(f0, f1): + xoI = (xo0 + ((f - f0) * ((xo1 - xo0) / (f1 - f0)))) + yoI = (yo0 + ((f - f0) * ((yo1 - yo0) / (f1 - f0)))) + copied_2d_curve_x = copied_2d_curve[f][0] + copied_2d_curve_y = copied_2d_curve[f][1] + tde4.setPointPosition2D(current_point_group,point,cam,f,[copied_2d_curve_x + xoI, copied_2d_curve_y + yoI ] ) + #lastkeyframe + copied_2d_curve_x = copied_2d_curve[f1][0] + copied_2d_curve_y = copied_2d_curve[f1][1] + tde4.setPointPosition2D(current_point_group,point,cam,f1,[copied_2d_curve_x + xo1, copied_2d_curve_y + yo1 ] ) + + + + + + + + diff --git a/xg_delete_2d_curve.py b/xg_delete_2d_curve.py new file mode 100644 index 0000000..dfc3945 --- /dev/null +++ b/xg_delete_2d_curve.py @@ -0,0 +1,29 @@ +# +# +# 3DE4.script.name: Delete 2d Curve +# +# 3DE4.script.version: v1.0 +# +# 3DE4.script.gui: Manual Tracking::Edit +# 3DE4.script.gui: Object Browser::Context Menu Point +# +# 3DE4.script.comment: Delete 2d curve +# +# Giovanni Di Grezia 2016 +# http://www.xgiovio.com +# + +cam = tde4.getCurrentCamera() +current_point_group = tde4.getCurrentPGroup() +selected_points = tde4.getPointList (current_point_group,1) + +for point in selected_points: + tde4.deletePointCurve2D (current_point_group,point,cam) + + + + + + + + diff --git a/xg_fill2d.py b/xg_fill2d.py new file mode 100644 index 0000000..f4771cb --- /dev/null +++ b/xg_fill2d.py @@ -0,0 +1,56 @@ +# 3DE4.script.hide: true +# 3DE4.script.startup: false +# +# Giovanni Di Grezia 2016 +# http://www.xgiovio.com +# + +import itertools +import tde4 + + +def average_each_2_points (dist = False): + cam = tde4.getCurrentCamera() + playback = tde4.getCameraPlaybackRange(cam) + firstframe = playback[0] + lastframe = playback[1] + current_point_group = tde4.getCurrentPGroup() + selected_points = tde4.getPointList (current_point_group,1) + if (len(selected_points) < 2): + tde4.postQuestionRequester("Info","You need to select 2 or more 2D points","OK") + else: + exit = 0 + tde4.postProgressRequesterAndContinue("Calculating","Computing Points",100,"Cancel") + couples_selected_points = list(itertools.combinations(selected_points,2)) + counter = 0 + for i in couples_selected_points: + if exit == 1: + break + avg = tde4.createPoint (current_point_group) + aname = tde4.getPointName(current_point_group,i[0]) + bname = tde4.getPointName(current_point_group,i[1]) + tde4.setPointName(current_point_group,avg, "AVG_" + aname + "_" + bname) + for frame in range (firstframe, lastframe + 1): + counter+=1 + percentage = (100 * counter) / (len(couples_selected_points) * (lastframe + 1 - firstframe)) + status = tde4.updateProgressRequester(percentage,str(percentage) + " % - Frame " + str(frame) + " Point AVG_" + aname + "_" + bname) + if status != -1: + exit = 1 + break + apos = tde4.getPointPosition2D (current_point_group,i[0],cam,frame) + if dist: + apos = tde4.removeDistortion2D(cam,frame,apos) + avalid =tde4.isPointPos2DValid(current_point_group,i[0],cam,frame) + aposx = apos[0] + aposy = apos[1] + bpos = tde4.getPointPosition2D (current_point_group,i[1],cam,frame) + if dist: + bpos = tde4.removeDistortion2D(cam,frame,bpos) + bvalid =tde4.isPointPos2DValid(current_point_group,i[1],cam,frame) + bposx = bpos[0] + bposy = bpos[1] + if avalid and bvalid: + avgpos = [ aposx + ( (bposx - aposx) / 2 ) , aposy + ( (bposy - aposy) / 2 ) ] + if dist: + avgpos = tde4.applyDistortion2D(cam,frame,avgpos) + tde4.setPointPosition2D (current_point_group,avg,cam,frame,avgpos) \ No newline at end of file diff --git a/xg_fill2d_average_each_2_points.py b/xg_fill2d_average_each_2_points.py new file mode 100644 index 0000000..a0d6348 --- /dev/null +++ b/xg_fill2d_average_each_2_points.py @@ -0,0 +1,21 @@ +# +# +# 3DE4.script.name: Average each 2 points 2D +# +# 3DE4.script.version: v1.0 +# +# 3DE4.script.comment: Average each 2 2D points +# +# 3DE4.script.gui: Manual Tracking Controls::Fill2D +# 3DE4.script.hide: false +# 3DE4.script.startup: false +# +# Giovanni Di Grezia 2016 +# http://www.xgiovio.com +# + +import xg_fill2d +xg_fill2d = reload(xg_fill2d) + + +xg_fill2d.average_each_2_points (dist = False) \ No newline at end of file diff --git a/xg_fill2d_average_each_2_points_dist.py b/xg_fill2d_average_each_2_points_dist.py new file mode 100644 index 0000000..af5ecff --- /dev/null +++ b/xg_fill2d_average_each_2_points_dist.py @@ -0,0 +1,20 @@ +# +# +# 3DE4.script.name: Average each 2 points 2D with Dist +# +# 3DE4.script.version: v1.0 +# +# 3DE4.script.comment: Average each 2 2D points with Distortion +# +# 3DE4.script.gui: Manual Tracking Controls::Fill2D +# 3DE4.script.hide: false +# 3DE4.script.startup: false +# +# Giovanni Di Grezia 2016 +# http://www.xgiovio.com +# + +import xg_fill2d +xg_fill2d = reload(xg_fill2d) + +xg_fill2d.average_each_2_points (dist = True) \ No newline at end of file diff --git a/xg_fill3d.py b/xg_fill3d.py new file mode 100644 index 0000000..421d4ba --- /dev/null +++ b/xg_fill3d.py @@ -0,0 +1,63 @@ +# 3DE4.script.hide: true +# 3DE4.script.startup: false +# +# Giovanni Di Grezia 2016 +# http://www.xgiovio.com +# + +import itertools +import tde4 + + +def average_each_2_points (reelin= False, distortion = False, visible_only = False): + cam = tde4.getCurrentCamera() + current_point_group = tde4.getCurrentPGroup() + selected_points = tde4.getPointList (current_point_group,1) + playback = tde4.getCameraPlaybackRange(cam) + firstframe = playback[0] + lastframe = playback[1] + if (len(selected_points) < 2): + tde4.postQuestionRequester("Info","You need to select 2 or more 2D points with 3D Position","OK") + else: + tde4.postProgressRequesterAndContinue("Calculating","Computing Points",100,"Cancel") + couples_selected_points = list(itertools.combinations(selected_points,2)) + counter = 0 + for i in couples_selected_points: + counter+=1 + percentage = (100 * counter) / len(couples_selected_points) + aname = tde4.getPointName(current_point_group,i[0]) + bname = tde4.getPointName(current_point_group,i[1]) + status = tde4.updateProgressRequester(percentage,str(percentage) + " % -" + " Point AVG3D_" + aname + "_" + bname) + if tde4.getPointCalculated3DStatus(current_point_group,i[0]) != "NOT_CALCULATED" and tde4.getPointCalculated3DStatus(current_point_group,i[1]) != "NOT_CALCULATED" : + avg = tde4.createPoint (current_point_group) + tde4.setPointName(current_point_group,avg, "AVG3D_" + aname + "_" + bname) + + apos = tde4.getPointCalcPosition3D (current_point_group,i[0]) + aposx = apos[0] + aposy = apos[1] + aposz = apos[2] + bpos = tde4.getPointCalcPosition3D(current_point_group,i[1]) + bposx = bpos[0] + bposy = bpos[1] + bposz = bpos[2] + + + avgpos = [ aposx + ( (bposx - aposx) / 2 ) , aposy + ( (bposy - aposy) / 2 ), aposz + ( (bposz - aposz) / 2 ) ] + + tde4.setPointCalcPosition3D (current_point_group,avg,avgpos) + tde4.setPointCalculated3D(current_point_group,avg,1) + tde4.setPointCalculated3DStatus(current_point_group,avg,"TRIANGULATED") + if reelin : + for frame in range (firstframe, lastframe + 1): + if distortion: + pos = tde4.calcPointBackProjection2D(current_point_group,avg,cam,frame,1) + else: + pos = tde4.calcPointBackProjection2D(current_point_group,avg,cam,frame,0) + if visible_only : + if pos[0] >= 0 and pos[0] <= 1 and pos[1] >= 0 and pos[1] <= 1: + tde4.setPointPosition2D(current_point_group,avg,cam,frame,pos) + else: + tde4.setPointPosition2D(current_point_group,avg,cam,frame,pos) + + if status != -1: + break \ No newline at end of file diff --git a/xg_fill3d_average_each_2_points.py b/xg_fill3d_average_each_2_points.py new file mode 100644 index 0000000..f1a4882 --- /dev/null +++ b/xg_fill3d_average_each_2_points.py @@ -0,0 +1,22 @@ +# +# +# 3DE4.script.name: Average each 2 points 3D +# +# 3DE4.script.version: v1.0 +# +# 3DE4.script.comment: Average each 2 3d points. Calculate from scratch delete this 3d calculated point +# +# 3DE4.script.gui: Manual Tracking Controls::Fill3D +# 3DE4.script.gui: Manual Tracking Controls::Reconstruction +# 3DE4.script.hide: false +# 3DE4.script.startup: false +# +# Giovanni Di Grezia 2016 +# http://www.xgiovio.com +# + +import xg_fill3d +xg_fill3d = reload(xg_fill3d) + + +xg_fill3d.average_each_2_points () \ No newline at end of file diff --git a/xg_fill3d_average_each_2_points_reelin.py b/xg_fill3d_average_each_2_points_reelin.py new file mode 100644 index 0000000..48d8b01 --- /dev/null +++ b/xg_fill3d_average_each_2_points_reelin.py @@ -0,0 +1,22 @@ +# +# +# 3DE4.script.name: Average each 2 points 3D + Reel in +# +# 3DE4.script.version: v1.0 +# +# 3DE4.script.comment: Average each 2 3d points and reel in in +# +# 3DE4.script.gui: Manual Tracking Controls::Fill3D +# 3DE4.script.gui: Manual Tracking Controls::Reconstruction +# 3DE4.script.hide: false +# 3DE4.script.startup: false +# +# Giovanni Di Grezia 2016 +# http://www.xgiovio.com +# + +import xg_fill3d +xg_fill3d = reload(xg_fill3d) + + +xg_fill3d.average_each_2_points (reelin = True) \ No newline at end of file diff --git a/xg_fill3d_average_each_2_points_reelin_dist.py b/xg_fill3d_average_each_2_points_reelin_dist.py new file mode 100644 index 0000000..a6f2d6c --- /dev/null +++ b/xg_fill3d_average_each_2_points_reelin_dist.py @@ -0,0 +1,22 @@ +# +# +# 3DE4.script.name: Average each 2 points 3D + Reel in Dist +# +# 3DE4.script.version: v1.0 +# +# 3DE4.script.comment: Average each 2 3d points and reel in plus distortion +# +# 3DE4.script.gui: Manual Tracking Controls::Fill3D +# 3DE4.script.gui: Manual Tracking Controls::Reconstruction +# 3DE4.script.hide: false +# 3DE4.script.startup: false +# +# Giovanni Di Grezia 2016 +# http://www.xgiovio.com +# + +import xg_fill3d +xg_fill3d = reload(xg_fill3d) + + +xg_fill3d.average_each_2_points (reelin = True, distortion = True) \ No newline at end of file diff --git a/xg_fill3d_average_each_2_points_reelin_dist_visible.py b/xg_fill3d_average_each_2_points_reelin_dist_visible.py new file mode 100644 index 0000000..c8df3b0 --- /dev/null +++ b/xg_fill3d_average_each_2_points_reelin_dist_visible.py @@ -0,0 +1,22 @@ +# +# +# 3DE4.script.name: Avg each 2 points 3D + Reel in Visible Dist +# +# 3DE4.script.version: v1.0 +# +# 3DE4.script.comment: Average each 2 3d points and reel in in visibile frames area with distortion +# +# 3DE4.script.gui: Manual Tracking Controls::Fill3D +# 3DE4.script.gui: Manual Tracking Controls::Reconstruction +# 3DE4.script.hide: false +# 3DE4.script.startup: false +# +# Giovanni Di Grezia 2016 +# http://www.xgiovio.com +# + +import xg_fill3d +xg_fill3d = reload(xg_fill3d) + + +xg_fill3d.average_each_2_points (reelin = True, distortion = True, visible_only = True) \ No newline at end of file diff --git a/xg_fill3d_average_each_2_points_reelin_visible.py b/xg_fill3d_average_each_2_points_reelin_visible.py new file mode 100644 index 0000000..adf5127 --- /dev/null +++ b/xg_fill3d_average_each_2_points_reelin_visible.py @@ -0,0 +1,22 @@ +# +# +# 3DE4.script.name: Avg each 2 points 3D + Reel in Visible +# +# 3DE4.script.version: v1.0 +# +# 3DE4.script.comment: Average each 2 3d points and reel in in visibile frames area +# +# 3DE4.script.gui: Manual Tracking Controls::Fill3D +# 3DE4.script.gui: Manual Tracking Controls::Reconstruction +# 3DE4.script.hide: false +# 3DE4.script.startup: false +# +# Giovanni Di Grezia 2016 +# http://www.xgiovio.com +# + +import xg_fill3d +xg_fill3d = reload(xg_fill3d) + + +xg_fill3d.average_each_2_points (reelin = True, visible_only = True) \ No newline at end of file diff --git a/xg_paste_2d_curve.py b/xg_paste_2d_curve.py new file mode 100644 index 0000000..6546f7a --- /dev/null +++ b/xg_paste_2d_curve.py @@ -0,0 +1,25 @@ +# +# +# 3DE4.script.name: Paste 2D Curve +# +# 3DE4.script.version: v1.0 +# +# 3DE4.script.comment: Paste copied curve to selected point. Overwrite present curve +# +# 3DE4.script.gui: Manual Tracking Controls::Edit +# 3DE4.script.gui.button: Manual Tracking Controls::Paste, align-bottom-left, 100, 20 + + +# 3DE4.script.hide: false +# 3DE4.script.startup: false +# +# Giovanni Di Grezia 2016 +# http://www.xgiovio.com +# + + + +import xg_copy_paste_2d_curves +xg_copy_paste_2d_curves = reload(xg_copy_paste_2d_curves) + +xg_copy_paste_2d_curves.paste () diff --git a/xg_paste_def_to_keys_2d_curve.py b/xg_paste_def_to_keys_2d_curve.py new file mode 100644 index 0000000..5677594 --- /dev/null +++ b/xg_paste_def_to_keys_2d_curve.py @@ -0,0 +1,25 @@ +# +# +# 3DE4.script.name: Paste and Deform 2D Curve to Keys +# +# 3DE4.script.version: v1.0 +# +# 3DE4.script.comment: Paste copied curve to new curves deforming using actual keyframes on new curve. +# +# 3DE4.script.gui: Manual Tracking Controls::Edit +# 3DE4.script.gui.button: Manual Tracking Controls::Paste and Deform to Keys, align-bottom-left, 150, 20 + + +# 3DE4.script.hide: false +# 3DE4.script.startup: false +# +# Giovanni Di Grezia 2016 +# http://www.xgiovio.com +# + + + +import xg_copy_paste_2d_curves +xg_copy_paste_2d_curves = reload(xg_copy_paste_2d_curves) + +xg_copy_paste_2d_curves.paste (adapt_to_keyframes = True) diff --git a/xg_paste_def_to_keys_inside_2d_curve.py b/xg_paste_def_to_keys_inside_2d_curve.py new file mode 100644 index 0000000..fc85c0f --- /dev/null +++ b/xg_paste_def_to_keys_inside_2d_curve.py @@ -0,0 +1,26 @@ +# +# +# 3DE4.script.name: Paste and Deform 2D Curve to Keys Inside +# +# 3DE4.script.version: v1.0 +# +# 3DE4.script.comment: Paste copied curve to new curves deforming using actual keyframes on new curve. +# 3DE4.script.comment: Curve created only inside the the keyframe range +# +# 3DE4.script.gui: Manual Tracking Controls::Edit +# 3DE4.script.gui.button: Manual Tracking Controls::Paste and Deform to Keys Inside, align-bottom-left, 150, 20 + + +# 3DE4.script.hide: false +# 3DE4.script.startup: false +# +# Giovanni Di Grezia 2016 +# http://www.xgiovio.com +# + + + +import xg_copy_paste_2d_curves +xg_copy_paste_2d_curves = reload(xg_copy_paste_2d_curves) + +xg_copy_paste_2d_curves.paste (adapt_to_keyframes = True, inside_only = True) diff --git a/xg_reconstruct_del_non_keyframes.py b/xg_reconstruct_del_non_keyframes.py new file mode 100644 index 0000000..958ffed --- /dev/null +++ b/xg_reconstruct_del_non_keyframes.py @@ -0,0 +1,24 @@ +# +# +# 3DE4.script.name: Delete Non Keyframes +# +# 3DE4.script.version: v1.0 +# +# 3DE4.script.comment: Delete Non Keyframes +# +# 3DE4.script.gui: Manual Tracking Controls::Reconstruction + + +# 3DE4.script.hide: false +# 3DE4.script.startup: false +# +# Giovanni Di Grezia 2016 +# http://www.xgiovio.com +# + + + +import xg_reconstruct_tool +xg_reconstruct_tool = reload(xg_reconstruct_tool) + +xg_reconstruct_tool.operations (del_non_keyframes = True) diff --git a/xg_reconstruct_del_non_keyframes_and_triangulate.py b/xg_reconstruct_del_non_keyframes_and_triangulate.py new file mode 100644 index 0000000..7fc11dc --- /dev/null +++ b/xg_reconstruct_del_non_keyframes_and_triangulate.py @@ -0,0 +1,25 @@ +# +# +# 3DE4.script.name: Delete Non Keyframes and Triangulate +# +# 3DE4.script.version: v1.0 +# +# 3DE4.script.comment: Delete Non Keyframes,Triangulate +# +# 3DE4.script.gui: Manual Tracking Controls::Reconstruction +# 3DE4.script.gui.button: Manual Tracking Controls::Del Non Keyframes + Trian, align-bottom-left, 120, 20 + + +# 3DE4.script.hide: false +# 3DE4.script.startup: false +# +# Giovanni Di Grezia 2016 +# http://www.xgiovio.com +# + + + +import xg_reconstruct_tool +xg_reconstruct_tool = reload(xg_reconstruct_tool) + +xg_reconstruct_tool.operations (del_non_keyframes = True, triangulate = True) diff --git a/xg_reconstruct_del_non_keyframes_and_triangulate_and_backproj.py b/xg_reconstruct_del_non_keyframes_and_triangulate_and_backproj.py new file mode 100644 index 0000000..8a9913b --- /dev/null +++ b/xg_reconstruct_del_non_keyframes_and_triangulate_and_backproj.py @@ -0,0 +1,24 @@ +# +# +# 3DE4.script.name: Delete Non Keyframes,Triangulate and Reel in +# +# 3DE4.script.version: v1.0 +# +# 3DE4.script.comment: Delete Non Keyframes,Triangulate and Reel in +# +# 3DE4.script.gui: Manual Tracking Controls::Reconstruction + + +# 3DE4.script.hide: false +# 3DE4.script.startup: false +# +# Giovanni Di Grezia 2016 +# http://www.xgiovio.com +# + + + +import xg_reconstruct_tool +xg_reconstruct_tool = reload(xg_reconstruct_tool) + +xg_reconstruct_tool.operations (del_non_keyframes = True, triangulate = True, reelin = True) diff --git a/xg_reconstruct_del_non_keyframes_and_triangulate_and_backproj_deform.py b/xg_reconstruct_del_non_keyframes_and_triangulate_and_backproj_deform.py new file mode 100644 index 0000000..eeebc56 --- /dev/null +++ b/xg_reconstruct_del_non_keyframes_and_triangulate_and_backproj_deform.py @@ -0,0 +1,25 @@ +# +# +# 3DE4.script.name: Delete Non Keyframes,Triangulate,Reel Deform +# +# 3DE4.script.version: v1.0 +# +# 3DE4.script.comment: Delete Non Keyframes,Triangulate and Reel in with distortion +# 3DE4.script.comment: and deform the track on previous keyframes. Recalculate from scratch needed after this command. +# +# 3DE4.script.gui: Manual Tracking Controls::Reconstruction + + +# 3DE4.script.hide: false +# 3DE4.script.startup: false +# +# Giovanni Di Grezia 2016 +# http://www.xgiovio.com +# + + + +import xg_reconstruct_tool +xg_reconstruct_tool = reload(xg_reconstruct_tool) + +xg_reconstruct_tool.operations (del_non_keyframes = True, triangulate = True, reelin = True, deform = True) diff --git a/xg_reconstruct_del_non_keyframes_and_triangulate_and_backproj_deform_dist.py b/xg_reconstruct_del_non_keyframes_and_triangulate_and_backproj_deform_dist.py new file mode 100644 index 0000000..36537d4 --- /dev/null +++ b/xg_reconstruct_del_non_keyframes_and_triangulate_and_backproj_deform_dist.py @@ -0,0 +1,26 @@ +# +# +# 3DE4.script.name: Del Non Keys,Triangulate,Reel Deform Dist +# +# 3DE4.script.version: v1.0 +# +# 3DE4.script.comment: Delete Non Keyframes,Triangulate and Reel in with distortion +# 3DE4.script.comment: and deform the track on previous keyframes. Recalculate from scratch needed after this command. +# +# 3DE4.script.gui: Manual Tracking Controls::Reconstruction +# 3DE4.script.gui.button: Manual Tracking Controls::Del Non Keyframes - Trian - Reel in - Def Dist, align-bottom-left, 200, 20 + + +# 3DE4.script.hide: false +# 3DE4.script.startup: false +# +# Giovanni Di Grezia 2016 +# http://www.xgiovio.com +# + + + +import xg_reconstruct_tool +xg_reconstruct_tool = reload(xg_reconstruct_tool) + +xg_reconstruct_tool.operations (del_non_keyframes = True, triangulate = True, reelin = True, distortion = True, deform = True) diff --git a/xg_reconstruct_del_non_keyframes_and_triangulate_and_backproj_deform_inside.py b/xg_reconstruct_del_non_keyframes_and_triangulate_and_backproj_deform_inside.py new file mode 100644 index 0000000..05a7e02 --- /dev/null +++ b/xg_reconstruct_del_non_keyframes_and_triangulate_and_backproj_deform_inside.py @@ -0,0 +1,25 @@ +# +# +# 3DE4.script.name: Del Non Keys,Triangulate,Reel Deform Inside +# +# 3DE4.script.version: v1.0 +# +# 3DE4.script.comment: Delete Non Keyframes,Triangulate and Reel in Inside the keyframes range +# 3DE4.script.comment: and deform the track on previous keyframes. Recalculate from scratch needed after this command. +# +# 3DE4.script.gui: Manual Tracking Controls::Reconstruction + + +# 3DE4.script.hide: false +# 3DE4.script.startup: false +# +# Giovanni Di Grezia 2016 +# http://www.xgiovio.com +# + + + +import xg_reconstruct_tool +xg_reconstruct_tool = reload(xg_reconstruct_tool) + +xg_reconstruct_tool.operations (del_non_keyframes = True, triangulate = True, reelin = True, deform = True, inside_only = True) diff --git a/xg_reconstruct_del_non_keyframes_and_triangulate_and_backproj_deform_inside_dist.py b/xg_reconstruct_del_non_keyframes_and_triangulate_and_backproj_deform_inside_dist.py new file mode 100644 index 0000000..6db9520 --- /dev/null +++ b/xg_reconstruct_del_non_keyframes_and_triangulate_and_backproj_deform_inside_dist.py @@ -0,0 +1,25 @@ +# +# +# 3DE4.script.name: Del Non Keys,Triangulate,Reel Deform Inside Dist +# +# 3DE4.script.version: v1.0 +# +# 3DE4.script.comment: Delete Non Keyframes,Triangulate and Reel in Inside the keyframes range with distortion +# 3DE4.script.comment: and deform the track on previous keyframes. Recalculate from scratch needed after this command. +# +# 3DE4.script.gui: Manual Tracking Controls::Reconstruction +# 3DE4.script.gui.button: Manual Tracking Controls::Del Non Keyframes - Trian - Reel in - Def Inside Dist, align-bottom-left, 250, 20 + +# 3DE4.script.hide: false +# 3DE4.script.startup: false +# +# Giovanni Di Grezia 2016 +# http://www.xgiovio.com +# + + + +import xg_reconstruct_tool +xg_reconstruct_tool = reload(xg_reconstruct_tool) + +xg_reconstruct_tool.operations (del_non_keyframes = True, triangulate = True, reelin = True, deform = True, inside_only = True, distortion = True) diff --git a/xg_reconstruct_del_non_keyframes_and_triangulate_and_backproj_dist.py b/xg_reconstruct_del_non_keyframes_and_triangulate_and_backproj_dist.py new file mode 100644 index 0000000..803fde4 --- /dev/null +++ b/xg_reconstruct_del_non_keyframes_and_triangulate_and_backproj_dist.py @@ -0,0 +1,24 @@ +# +# +# 3DE4.script.name: Delete Non Keyframes,Triangulate and Reel in Dist +# +# 3DE4.script.version: v1.0 +# +# 3DE4.script.comment: Delete Non Keyframes,Triangulate and Reel in with distortion +# +# 3DE4.script.gui: Manual Tracking Controls::Reconstruction + + +# 3DE4.script.hide: false +# 3DE4.script.startup: false +# +# Giovanni Di Grezia 2016 +# http://www.xgiovio.com +# + + + +import xg_reconstruct_tool +xg_reconstruct_tool = reload(xg_reconstruct_tool) + +xg_reconstruct_tool.operations (del_non_keyframes = True, triangulate = True, reelin = True, distortion = True) diff --git a/xg_reconstruct_del_non_keyframes_and_triangulate_and_backproj_inside.py b/xg_reconstruct_del_non_keyframes_and_triangulate_and_backproj_inside.py new file mode 100644 index 0000000..861ee5f --- /dev/null +++ b/xg_reconstruct_del_non_keyframes_and_triangulate_and_backproj_inside.py @@ -0,0 +1,24 @@ +# +# +# 3DE4.script.name: Del Non Keys,Triangulate and Reel in Inside +# +# 3DE4.script.version: v1.0 +# +# 3DE4.script.comment: Delete Non Keyframes,Triangulate and Reel in Inside the keyframes range +# +# 3DE4.script.gui: Manual Tracking Controls::Reconstruction + + +# 3DE4.script.hide: false +# 3DE4.script.startup: false + +# +# Giovanni Di Grezia 2016 +# http://www.xgiovio.com +# + + +import xg_reconstruct_tool +xg_reconstruct_tool = reload(xg_reconstruct_tool) + +xg_reconstruct_tool.operations (del_non_keyframes = True, triangulate = True, reelin = True,inside_only = True) diff --git a/xg_reconstruct_del_non_keyframes_and_triangulate_and_backproj_inside_dist.py b/xg_reconstruct_del_non_keyframes_and_triangulate_and_backproj_inside_dist.py new file mode 100644 index 0000000..a66b591 --- /dev/null +++ b/xg_reconstruct_del_non_keyframes_and_triangulate_and_backproj_inside_dist.py @@ -0,0 +1,24 @@ +# +# +# 3DE4.script.name: Del Non Keys,Triangulate and Reel in Inside Dist +# +# 3DE4.script.version: v1.0 +# +# 3DE4.script.comment: Delete Non Keyframes,Triangulate and Reel in with Distortion inside the keyframes range +# +# 3DE4.script.gui: Manual Tracking Controls::Reconstruction + + +# 3DE4.script.hide: false +# 3DE4.script.startup: false +# +# Giovanni Di Grezia 2016 +# http://www.xgiovio.com +# + + + +import xg_reconstruct_tool +xg_reconstruct_tool = reload(xg_reconstruct_tool) + +xg_reconstruct_tool.operations (del_non_keyframes = True, triangulate = True, reelin = True,inside_only = True,distortion = True) diff --git a/xg_reconstruct_tool.py b/xg_reconstruct_tool.py new file mode 100644 index 0000000..9198df6 --- /dev/null +++ b/xg_reconstruct_tool.py @@ -0,0 +1,93 @@ + +# 3DE4.script.hide: true +# 3DE4.script.startup: false +# +# Giovanni Di Grezia 2016 +# http://www.xgiovio.com +# + +import tde4 + + +def operations (del_non_keyframes = False, triangulate = False, reelin = False, distortion = False , deform = False, inside_only = False): + + + cam = tde4.getCurrentCamera() + current_point_group = tde4.getCurrentPGroup() + selected_points = tde4.getPointList (current_point_group,1) + playback = tde4.getCameraPlaybackRange(cam) + firstframe = playback[0] + lastframe = playback[1] + + if del_non_keyframes : + for point in selected_points : + k_pos = [] + for frame in range (firstframe, lastframe + 1): + point_status = tde4.getPointStatus2D(current_point_group,point,cam,frame) + if point_status == "POINT_KEYFRAME" or point_status == "POINT_KEYFRAME_END": + pos = tde4.getPointPosition2D(current_point_group,point,cam,frame) + k_pos.append([frame,[ pos[0], pos[1] ] ]) + tde4.deletePointCurve2D (current_point_group,point,cam) + for i in k_pos : + tde4.setPointPosition2D(current_point_group,point,cam,i[0],i[1]) + if triangulate : + if len(k_pos) >= 2: + pos3d = tde4.calcPointPosition3D(current_point_group,point,cam) + tde4.setPointCalcPosition3D(current_point_group,point,pos3d) + tde4.setPointCalculated3D(current_point_group,point,1) + tde4.setPointCalculated3DStatus(current_point_group,point,"TRIANGULATED") + if reelin : + points_to_deform = {} + for frame in range (firstframe, lastframe + 1): + if distortion: + pos = tde4.calcPointBackProjection2D(current_point_group,point,cam,frame,1) + else: + pos = tde4.calcPointBackProjection2D(current_point_group,point,cam,frame,0) + if not deform: + if inside_only : + if frame >= k_pos[0][0] and frame <= k_pos[-1][0]: + tde4.setPointPosition2D(current_point_group,point,cam,frame,pos) + else: + tde4.setPointPosition2D(current_point_group,point,cam,frame,pos) + else: + points_to_deform[frame] = pos + if deform: + + #update k_pos with offset from reelincurve + for i in k_pos: + reel_in_x = points_to_deform[i[0]][0] + reel_in_y = points_to_deform[i[0]][1] + k_pos_x = i[1][0] + k_pos_y = i[1][1] + offset_x = k_pos_x - reel_in_x + offset_y = k_pos_y - reel_in_y + i[1] = [offset_x,offset_y] + + #extend keyframes to reelin range + k_pos_extended = [] + if k_pos[0][0] != firstframe and not inside_only: + k_pos_extended.append([firstframe,k_pos[0][1]]) + for i in k_pos: + k_pos_extended.append(i) + if k_pos[-1][0] != lastframe and not inside_only: + k_pos_extended.append([lastframe,k_pos[-1][1]]) + + + for i in range(len(k_pos_extended) - 1): + f0 = k_pos_extended[i][0] + f1 = k_pos_extended[i+1][0] + xo0 = k_pos_extended[i][1][0] + yo0 = k_pos_extended[i][1][1] + xo1 = k_pos_extended[i+1][1][0] + yo1 = k_pos_extended[i+1][1][1] + # linear deform step + for f in range(f0, f1): + xoI = (xo0 + ((f - f0) * ((xo1 - xo0) / (f1 - f0)))) + yoI = (yo0 + ((f - f0) * ((yo1 - yo0) / (f1 - f0)))) + reelin_curve_x = points_to_deform[f][0] + reelin_curve_y = points_to_deform[f][1] + tde4.setPointPosition2D(current_point_group,point,cam,f,[reelin_curve_x + xoI, reelin_curve_y + yoI ] ) + #lastkeyframe + reelin_curve_x = points_to_deform[f1][0] + reelin_curve_y = points_to_deform[f1][1] + tde4.setPointPosition2D(current_point_group,point,cam,f1,[reelin_curve_x + xo1, reelin_curve_y + yo1 ] ) \ No newline at end of file diff --git a/xg_restore_2d_curves.py b/xg_restore_2d_curves.py new file mode 100644 index 0000000..4721b67 --- /dev/null +++ b/xg_restore_2d_curves.py @@ -0,0 +1,28 @@ +# +# +# 3DE4.script.name: Restore 2D Curves +# +# 3DE4.script.version: v1.0 +# +# 3DE4.script.gui: Manual Tracking::Edit +# +# 3DE4.script.comment: Restore 2D Curves from memory +# 3DE4.script.gui.button: Manual Tracking::Restore, align-bottom-right, 120, 20 +# +# +# +# Giovanni Di Grezia 2016 +# http://www.xgiovio.com +# + +import xg_backup_restore_2d_curves +xg_backup_restore_2d_curves = reload(xg_backup_restore_2d_curves) + +xg_backup_restore_2d_curves.restore () + + + + + + + diff --git a/xg_restore_3d_calculated_points.py b/xg_restore_3d_calculated_points.py new file mode 100644 index 0000000..0e00a5d --- /dev/null +++ b/xg_restore_3d_calculated_points.py @@ -0,0 +1,28 @@ +# +# +# 3DE4.script.name: Restore 3D Points +# +# 3DE4.script.version: v1.0 +# +# 3DE4.script.gui: Orientation Controls::Edit +# +# 3DE4.script.comment: Restore 3D Calculated Positions of all selected points +# 3DE4.script.gui.button: Orientation Controls::Restore 3D Points, align-bottom-left, 120, 20 +# +# +# +# Giovanni Di Grezia 2016 +# http://www.xgiovio.com +# + +import xg_store_restore_3d_points +xg_store_restore_3d_points = reload(xg_store_restore_3d_points) + +xg_store_restore_3d_points.restore_3d () + + + + + + + diff --git a/xg_restore_3d_calculated_points_exact.py b/xg_restore_3d_calculated_points_exact.py new file mode 100644 index 0000000..aa8221e --- /dev/null +++ b/xg_restore_3d_calculated_points_exact.py @@ -0,0 +1,28 @@ +# +# +# 3DE4.script.name: Restore 3D Points + Set Exact Survey +# +# 3DE4.script.version: v1.0 +# +# 3DE4.script.gui: Orientation Controls::Edit +# +# 3DE4.script.comment: Restore 3D Calculated Positions of all selected points from memory plus set exact survey to all of them +# 3DE4.script.gui.button: Orientation Controls::Restore 3D Points + Set Exact Survey, align-bottom-left, 200, 20 +# +# +# +# Giovanni Di Grezia 2016 +# http://www.xgiovio.com +# + +import xg_store_restore_3d_points +xg_store_restore_3d_points = reload(xg_store_restore_3d_points) + +xg_store_restore_3d_points.restore_3d (exact = True) + + + + + + + diff --git a/xg_store_3d_calculated_points.py b/xg_store_3d_calculated_points.py new file mode 100644 index 0000000..a2194ec --- /dev/null +++ b/xg_store_3d_calculated_points.py @@ -0,0 +1,27 @@ +# +# +# 3DE4.script.name: Store 3D Points +# +# 3DE4.script.version: v1.0 +# +# 3DE4.script.gui: Orientation Controls::Edit +# +# 3DE4.script.comment: Store 3D Calculated Positions of all selected points in Memory +# 3DE4.script.gui.button: Orientation Controls::Store 3D Points, align-bottom-left, 120, 20 +# +# +# +# Giovanni Di Grezia 2016 +# http://www.xgiovio.com +# + +import xg_store_restore_3d_points +xg_store_restore_3d_points = reload(xg_store_restore_3d_points) + +xg_store_restore_3d_points.store_3d () + + + + + + diff --git a/xg_store_restore_3d_points.py b/xg_store_restore_3d_points.py new file mode 100644 index 0000000..b371d11 --- /dev/null +++ b/xg_store_restore_3d_points.py @@ -0,0 +1,47 @@ +# 3DE4.script.hide: true +# 3DE4.script.startup: false +# +# Giovanni Di Grezia 2016 +# http://www.xgiovio.com +# + +import tde4 + +global xg_3d_calculated_points_collection +try: + xg_3d_calculated_points_collection +except : + xg_3d_calculated_points_collection = {} + +cam = tde4.getCurrentCamera() +current_point_group = tde4.getCurrentPGroup() +selected_points = tde4.getPointList (current_point_group,1) + +def restore_3d (exact = False) : + for point in selected_points: + if point in xg_3d_calculated_points_collection: + tde4.setPointSurveyPosition3D(current_point_group,point,xg_3d_calculated_points_collection[point]) + tde4.setPointCalcPosition3D(current_point_group,point,xg_3d_calculated_points_collection[point]) + calculated_status = tde4.getPointCalculated3DStatus(current_point_group,point) + if calculated_status == "NOT_CALCULATED": + tde4.setPointCalculated3D(current_point_group,point,1) + tde4.setPointCalculated3DStatus(current_point_group,point,"CALCULATED") + if exact: + tde4.setPointSurveyMode(current_point_group,point,"SURVEY_EXACT") + + +def store_3d (): + for point in selected_points: + if tde4.isPointCalculated3D(current_point_group,point): + survey_mode = tde4.getPointSurveyMode(current_point_group,point) + if survey_mode != "SURVEY_EXACT": + xg_3d_calculated_points_collection[point] = tde4.getPointCalcPosition3D(current_point_group,point) + else: + xg_3d_calculated_points_collection[point] = tde4.getPointSurveyPosition3D(current_point_group,point) + + + + + + + diff --git a/xg_ui_adj_tests.py b/xg_ui_adj_tests.py new file mode 100644 index 0000000..4fd9278 --- /dev/null +++ b/xg_ui_adj_tests.py @@ -0,0 +1,27 @@ +# +# +# 3DE4.script.hide: true +# 3DE4.script.startup: false +# +# Giovanni Di Grezia 2016 +# http://www.xgiovio.com +# + +#init +current_value = tde4.getParameterAdjustCurrentValue() +best_value = tde4.getParameterAdjustCurrentValue() +get_custom_data = tde4.getParameterAdjustCustomParameters() +running = tde4.getParameterAdjustPhaseRunningFlag() + +# script specific +camera_id = get_custom_data +lens_id = tde4.getCameraLens(camera_id) + +if (running): + #calculating + tde4.applyParameterAdjustDataModification("@" + lens_id + ".focal_length_cm",current_value / 10) +else: + #transfer_to_3de + tde4.setLensFocalLength(lens_id,best_value / 10) + + diff --git a/xg_ui_adj_tests_gui.py b/xg_ui_adj_tests_gui.py new file mode 100644 index 0000000..301c541 --- /dev/null +++ b/xg_ui_adj_tests_gui.py @@ -0,0 +1,25 @@ +# +# +# 3DE4.script.name: TestAdjGui +# +# 3DE4.script.version: v1.0 +# +# 3DE4.script.comment: +# +# 3DE4.script.gui: Main Window::xgiovio +# +# 3DE4.script.hide: false +# 3DE4.script.startup: false +# +# Giovanni Di Grezia 2016 +# http://www.xgiovio.com +# + +#init +script_base = tde4.get3DEInstallPath() + "/sys_data/py_scripts/" + +#script related +adj_script_name = "xg_ui_adj_tests.py" + +#script +tde4.createParameterAdjustScript(script_base + adj_script_name,"xg_focal_" + tde4.getCameraName(tde4.getCurrentCamera()),tde4.getCurrentCamera() ,10,20) \ No newline at end of file diff --git a/xg_ui_tests.py b/xg_ui_tests.py new file mode 100644 index 0000000..b15332b --- /dev/null +++ b/xg_ui_tests.py @@ -0,0 +1,48 @@ +# +# +# 3DE4.script.name: TestUI +# +# 3DE4.script.version: v1.0 +# +# 3DE4.script.comment: +# +# 3DE4.script.gui: Main Window::xgiovio +# +# 3DE4.script.hide: false +# 3DE4.script.startup: false +# +# Giovanni Di Grezia 2016 +# http://www.xgiovio.com + +global gino +def f () : + + #gino += 4 + print gino +f() +print gino + +########## +''' +custom = tde4.createCustomRequester() +tde4.addListWidget (custom,"widget","widgetlabel",1,100) + + +for i in range (10): + tde4.insertListWidgetItem (custom,"widget","Item " + str(i),0) + +tde4.postCustomRequester (custom,"title",400,200,"Create","Cancel") +''' +############# +''' +m = tde4.postQuestionRequester("Titolo","Messaggio abbastanza lungo per titolo","a","b","c") +print m +''' + +###### +''' +tde4.postProgressRequesterAndContinue ("title","messaggio ok",50,"BUtton1","Button2") +tde4.updateProgressRequester (10,"ajeje") + +time.sleep(5) +'''