def test_update_nodes(self): file_names = [ 'test_v1.uv', 'test_v3.uv', # only contains 1 point 'test_v3_with_3d_point.uv', ] for file_name in file_names: path = self.get_data_path('uvtrack', file_name) create_marker.main() # mkr = # mkr_list = [mkr] _, mkr_data_list = marker_read.read(path) mkr_list = lib_utils.get_selected_markers() marker_read.update_nodes(mkr_list, mkr_data_list, load_bundle_position=False) marker_read.update_nodes(mkr_list, mkr_data_list, load_bundle_position=True) return
def apply(self): cam = None mkr_grp = None col = None file_path = self.subForm.getFilePath() load_mode = self.subForm.getLoadModeText() camera_text = self.subForm.getCameraText() camera_data = self.subForm.getCameraData() mkr_grp_text = self.subForm.getMarkerGroupText() mkr_grp_data = self.subForm.getMarkerGroupData() add_to_collection = self.subForm.getAddToCollectionValue() collection_text = self.subForm.getCollectionText() collection_data = self.subForm.getCollectionData() load_bnd_pos = self.subForm.getLoadBundlePositions() undist_mode = self.subForm.getDistortionModeText() use_overscan = self.subForm.getUseOverscanValue() undistorted = undist_mode == const.UNDISTORTION_MODE_VALUE width, height = self.subForm.getImageResolution() camera_field_of_view = None if use_overscan is True: camera_field_of_view = self.subForm.getCameraFieldOfViewValue() # Temporarily disable adding new Markers to the Active # Collection. config = userprefs_lib.get_config() key = userprefs_const.REG_EVNT_ADD_NEW_MKR_TO_KEY old_value = userprefs_lib.get_value(config, key) temp_value = userprefs_const.REG_EVNT_ADD_NEW_MKR_TO_NONE_VALUE userprefs_lib.set_value(config, key, temp_value) try: self.progressBar.setValue(0) self.progressBar.show() with undoutils.undo_chunk_context(): _, mkr_data_list = mayareadfile.read( file_path, image_width=width, image_height=height, undistorted=undistorted, ) self.progressBar.setValue(50) if load_mode == const.LOAD_MODE_NEW_VALUE: # Get Camera and MarkerGroup. if camera_text == const.NEW_CAMERA_VALUE: cam = lib.create_new_camera() mkr_grp = lib.create_new_marker_group(cam) else: cam = camera_data if mkr_grp_text == const.NEW_MARKER_GROUP_VALUE: mkr_grp = lib.create_new_marker_group(cam) else: mkr_grp = mkr_grp_data self.progressBar.setValue(60) # Get Collection col = None if add_to_collection is True: if collection_text == const.NEW_COLLECTION_VALUE: col = col_lib.create_collection() else: col = collection_data self.progressBar.setValue(70) mayareadfile.create_nodes( mkr_data_list, cam=cam, mkr_grp=mkr_grp, col=col, with_bundles=True, load_bundle_position=load_bnd_pos, camera_field_of_view=camera_field_of_view, ) elif load_mode == const.LOAD_MODE_REPLACE_VALUE: self.progressBar.setValue(60) mkr_list = lib.get_selected_markers() # NOTE: camera_field_of_view can only be from one # camera, because (we assume) only one MarkerData # file can be loaded at once. mayareadfile.update_nodes( mkr_list, mkr_data_list, load_bundle_position=load_bnd_pos, camera_field_of_view=camera_field_of_view) else: raise ValueError('Load mode is not valid: %r' % load_mode) self.progressBar.setValue(99) lib.trigger_maya_to_refresh() finally: self.progressBar.setValue(100) self.progressBar.hide() # Restore original config value. lib.deferred_revert_of_config_value(config, key, old_value) # Update the camera comboBox with the created camera, or # the last used camera. all_camera_nodes = lib.get_cameras() selected_cameras = [cam] active_camera = cam self.subForm.updateCameraList(self.subForm.camera_comboBox, self.subForm.camera_model, all_camera_nodes, selected_cameras, active_camera) active_camera = cam active_mkr_grp = mkr_grp mkr_grp_nodes = lib.get_marker_groups(active_camera) self.subForm.updateMarkerGroupList( self.subForm.markerGroup_comboBox, self.subForm.markerGroup_model, active_mkr_grp, mkr_grp_nodes) # Update the list of Collections, and pick the last used # Collection. active_col = col col_list = col_lib.get_collections() self.subForm.updateCollectionList(self.subForm.collection_comboBox, self.subForm.collection_model, active_col, col_list) # Update config file with latest values. config = get_config() if config is not None: config.set_value("data/use_overscan", use_overscan) config.set_value("data/load_bundle_position", load_bnd_pos) config.set_value("data/distortion_mode", undist_mode) config.set_value("data/load_mode", load_mode) config.write() return
def apply(self): cam = None mkr_grp = None file_path = self.subForm.getFilePath() load_mode = self.subForm.getLoadModeText() camera_text = self.subForm.getCameraText() camera_data = self.subForm.getCameraData() mkr_grp_text = self.subForm.getMarkerGroupText() mkr_grp_data = self.subForm.getMarkerGroupData() load_bnd_pos = self.subForm.getLoadBundlePositions() undist_mode = self.subForm.getDistortionModeText() use_overscan = self.subForm.getUseOverscanValue() undistorted = undist_mode == const.UNDISTORTION_MODE_VALUE width, height = self.subForm.getImageResolution() camera_field_of_view = None if use_overscan is True: camera_field_of_view = self.subForm.getCameraFieldOfViewValue() try: self.progressBar.setValue(0) self.progressBar.show() with undoutils.undo_chunk_context(): _, mkr_data_list = mayareadfile.read( file_path, image_width=width, image_height=height, undistorted=undistorted, ) self.progressBar.setValue(50) if load_mode == const.LOAD_MODE_NEW_VALUE: if camera_text == const.NEW_CAMERA_VALUE: cam = lib.create_new_camera() mkr_grp = lib.create_new_marker_group(cam) else: cam = camera_data if mkr_grp_text == const.NEW_MARKER_GROUP_VALUE: mkr_grp = lib.create_new_marker_group(cam) else: mkr_grp = mkr_grp_data self.progressBar.setValue(60) mayareadfile.create_nodes( mkr_data_list, cam=cam, mkr_grp=mkr_grp, with_bundles=True, load_bundle_position=load_bnd_pos, camera_field_of_view=camera_field_of_view, ) elif load_mode == const.LOAD_MODE_REPLACE_VALUE: self.progressBar.setValue(60) mkr_list = lib.get_selected_markers() # NOTE: camera_field_of_view can only be from one # camera, because (we assume) only one MarkerData # file can be loaded at once. mayareadfile.update_nodes( mkr_list, mkr_data_list, load_bundle_position=load_bnd_pos, camera_field_of_view=camera_field_of_view) else: raise ValueError('Load mode is not valid: %r' % load_mode) self.progressBar.setValue(99) lib.trigger_maya_to_refresh() finally: self.progressBar.setValue(100) self.progressBar.hide() # Update the camera comboBox with the created camera, or # the last used camera. all_camera_nodes = lib.get_cameras() selected_cameras = [cam] active_camera = cam self.subForm.updateCameraList(self.subForm.camera_comboBox, self.subForm.camera_model, all_camera_nodes, selected_cameras, active_camera) active_camera = cam active_mkr_grp = mkr_grp mkr_grp_nodes = lib.get_marker_groups(active_camera) self.subForm.updateMarkerGroupList( self.subForm.markerGroup_comboBox, self.subForm.markerGroup_model, active_mkr_grp, mkr_grp_nodes) # Update config file with latest values. config = get_config() if config is not None: config.set_value("data/use_overscan", use_overscan) config.set_value("data/load_bundle_position", load_bnd_pos) config.set_value("data/distortion_mode", undist_mode) config.set_value("data/load_mode", load_mode) config.write() return
def apply(self): cam = None mkr_grp = None file_path = self.subForm.getFilePath() load_mode = self.subForm.getLoadModeText() camera_text = self.subForm.getCameraText() camera_data = self.subForm.getCameraData() mkr_grp_text = self.subForm.getMarkerGroupText() mkr_grp_data = self.subForm.getMarkerGroupData() load_bnd_pos = self.subForm.getLoadBundlePositions() undist_mode = self.subForm.getDistortionModeText() undistorted = undist_mode == const.UNDISTORTION_MODE_VALUE width, height = self.subForm.getImageResolution() try: self.progressBar.setValue(0) self.progressBar.show() with undoutils.undo_chunk_context(): _, mkr_data_list = mayareadfile.read( file_path, image_width=width, image_height=height, undistorted=undistorted, ) self.progressBar.setValue(50) if load_mode == const.LOAD_MODE_NEW_VALUE: if camera_text == const.NEW_CAMERA_VALUE: cam = lib.create_new_camera() else: cam = camera_data if mkr_grp_text == const.NEW_MARKER_GROUP_VALUE: mkr_grp = lib.create_new_marker_group(cam) else: mkr_grp = mkr_grp_data self.progressBar.setValue(60) mayareadfile.create_nodes( mkr_data_list, cam=cam, mkr_grp=mkr_grp, with_bundles=True, load_bundle_position=load_bnd_pos, ) elif load_mode == const.LOAD_MODE_REPLACE_VALUE: self.progressBar.setValue(60) mkr_list = lib.get_selected_markers() mayareadfile.update_nodes(mkr_list, mkr_data_list) else: raise ValueError('Load mode is not valid: %r' % load_mode) self.progressBar.setValue(99) lib.trigger_maya_to_refresh() finally: self.progressBar.setValue(100) self.progressBar.hide() # Update the camera comboBox with the created camera, or # the last used camera. all_camera_nodes = lib.get_cameras() selected_cameras = [cam] active_camera = cam self.subForm.updateCameraList( self.subForm.camera_comboBox, self.subForm.camera_model, all_camera_nodes, selected_cameras, active_camera ) active_camera = cam active_mkr_grp = mkr_grp mkr_grp_nodes = lib.get_marker_groups(active_camera) self.subForm.updateMarkerGroupList( self.subForm.markerGroup_comboBox, self.subForm.markerGroup_model, active_mkr_grp, mkr_grp_nodes ) return