def save_camera_setting(self,filename=''): filename = QFileDialog.getSaveFileName(self, 'Save Camera Setting File', self.camera_setting_dir) filename = abspath(str(filename)) self.camera_setting_dir = dirname(filename) cam = self.qvtkWidget.GetRenderWindow().GetRenderers().GetFirstRenderer().GetActiveCamera() cam_node = JSONNode() clipping_range_node = cam_node.add_child_node('clipping_range') clipping_range = cam.GetClippingRange() clipping_range_node['min'] = clipping_range[0] clipping_range_node['max'] = clipping_range[1] focal_point = cam.GetFocalPoint() focal_point_node = cam_node.add_child_node('focal_point') focal_point_node['x'] = focal_point[0] focal_point_node['y'] = focal_point[1] focal_point_node['z'] = focal_point[2] position = cam.GetPosition() position_node = cam_node.add_child_node('position') position_node['x'] = position[0] position_node['y'] = position[1] position_node['z'] = position[2] view_up = cam.GetViewUp() view_up_node = cam_node.add_child_node('view_up') view_up_node['x'] = view_up[0] view_up_node['y'] = view_up[1] view_up_node['z'] = view_up[2] print cam_node.output() cam_node.write(filename) # cam_node.write('default.camera.json') # # top view # cam.SetClippingRange((312.385, 827.346)) # cam.SetFocalPoint(23.9803, -13.4557, 27.6483) # cam.SetPosition(-2.03758, 20.7186, 539.993) # cam.SetViewUp(0.0346923, 0.997298, -0.0647596) pass
def load_camera_settings(self,filename=''): if not filename: filename = 'default.camera.json' cam = self.qvtkWidget.GetRenderWindow().GetRenderers().GetFirstRenderer().GetActiveCamera() cam_node = JSONNode.read(filename) cam.SetClippingRange(float(cam_node['clipping_range']['min']),float(cam_node['clipping_range']['max'])) cam.SetFocalPoint(float(cam_node['focal_point']['x']),float(cam_node['focal_point']['y']),float(cam_node['focal_point']['z'])) cam.SetPosition(float(cam_node['position']['x']),float(cam_node['position']['y']),float(cam_node['position']['z'])) cam.SetViewUp(float(cam_node['view_up']['x']),float(cam_node['view_up']['y']),float(cam_node['view_up']['z'])) self.render_scene() pass