scans_database.py
Go to the documentation of this file.
00001 #
00002 # Copyright (c) 2010, Georgia Tech Research Corporation
00003 # All rights reserved.
00004 #
00005 # Redistribution and use in source and binary forms, with or without
00006 # modification, are permitted provided that the following conditions are met:
00007 #     * Redistributions of source code must retain the above copyright
00008 #       notice, this list of conditions and the following disclaimer.
00009 #     * Redistributions in binary form must reproduce the above copyright
00010 #       notice, this list of conditions and the following disclaimer in the
00011 #       documentation and/or other materials provided with the distribution.
00012 #     * Neither the name of the Georgia Tech Research Corporation nor the
00013 #       names of its contributors may be used to endorse or promote products
00014 #       derived from this software without specific prior written permission.
00015 #
00016 # THIS SOFTWARE IS PROVIDED BY GEORGIA TECH RESEARCH CORPORATION ''AS IS'' AND
00017 # ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
00018 # WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
00019 # DISCLAIMED. IN NO EVENT SHALL GEORGIA TECH BE LIABLE FOR ANY DIRECT, INDIRECT,
00020 # INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
00021 # LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
00022 # OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
00023 # LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
00024 # OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
00025 # ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00026 #
00027 
00028 #  \author Martin Schuster (Healthcare Robotics Lab, Georgia Tech.)
00029 
00030 from labeling import label_object, scan_dataset
00031 import hrl_lib.util as ut  
00032 
00033 import shutil #file operations
00034 
00035 class scans_database(object):
00036     '''
00037     classdocs
00038     '''
00039 
00040 
00041     def __init__(self):
00042         '''
00043         Constructor
00044         '''
00045         self.datasets = []
00046         self.current_index = 0
00047         
00048         
00049     def load(self, path, filename):
00050         self.filename = filename
00051         self.path = path
00052         #try:
00053         dict = ut.load_pickle(self.path+'/'+self.filename)
00054         #except:
00055         #    print 'loading of '+self.path+'/'+filename+' failed. WARNING: it will be overwritten on save()!'
00056         #    return
00057             
00058         self.datasets = dict['datasets']
00059         
00060     def save(self):
00061         dict = {'datasets': self.datasets,'version': 0.1} 
00062         
00063         #for now: make a backup first:
00064         database_filename = self.path+'/'+self.filename
00065         backup_filename = self.path+'/'+self.filename+'_backup_'+ut.formatted_time()
00066         print 'Backing up old database to ' + backup_filename       
00067         shutil.copy(database_filename, backup_filename)
00068         
00069         print "Saving: "+database_filename
00070         ut.save_pickle(dict,database_filename)    
00071            
00072         
00073     def get_path(self):
00074         return self.path
00075         
00076     def get_dataset(self, index):
00077         self.current_index = index
00078         return self.datasets[index]
00079     
00080     def get_dataset_by_id(self, id):
00081         #TODO: faster lookup, probably using a dictionary instead of a list?
00082         
00083         for dataset in self.datasets:
00084             if dataset.id == id:
00085                 return dataset
00086         return False
00087     
00088     def set_internal_pointer_to_dataset(self, id):
00089         self.current_index = 0
00090         for dataset in self.datasets:
00091             if dataset.id == id:
00092                 return True
00093             self.current_index += 1
00094         return False
00095     
00096     def get_next_dataset(self):
00097         if self.current_index < len(self.datasets) - 1:
00098             self.current_index = self.current_index + 1
00099             return self.datasets[self.current_index]
00100         else:
00101             return False
00102             
00103     def get_prev_dataset(self):
00104         if self.current_index > 0:
00105             self.current_index = self.current_index - 1
00106             return self.datasets[self.current_index]
00107         else:
00108             return False    
00109         
00110     def get_first_dataset(self):
00111         if len(self.datasets) > 0:
00112             self.current_index = 0
00113             return self.datasets[self.current_index]
00114         else:
00115             return False    
00116         
00117     def get_last_dataset(self):
00118         if len(self.datasets) > 0:
00119             self.current_index = len(self.datasets) - 1
00120             return self.datasets[self.current_index]
00121         else:
00122             return False                     
00123         
00124         
00125     def get_count(self):
00126         return len(self.datasets)
00127     
00128     def add_dataset(self, dataset):
00129         self.datasets.append(dataset)
00130         
00131     def delete_current_dataset(self):
00132         del self.datasets[self.current_index]
00133         dataset = self.get_prev_dataset()
00134         if False != dataset:
00135             return  dataset
00136         else: 
00137             dataset = self.get_next_dataset()
00138         return dataset #TODO: still fails if there is only one dataset!
00139         
00140         
00141     def add_attribute_to_every_dataset(self, name):
00142         for dataset in self.datasets:
00143             dataset.dict[name]=''
00144         
00145     


laser_camera_segmentation
Author(s): Martin Schuster, Advisor: Prof. Charlie Kemp, Lab: Healthcare Robotics Lab at Georgia Tech
autogenerated on Wed Nov 27 2013 11:56:44