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 import label_object, scan_dataset
00031 import util as ut  #Uses: load_pickle, save_pickle, formatted_time
00032 import shutil #file operations
00033 
00034 class scans_database(object):
00035     '''
00036     classdocs
00037     '''
00038 
00039 
00040     def __init__(self):
00041         '''
00042         Constructor
00043         '''
00044         self.datasets = []
00045         self.current_index = 0
00046         
00047         
00048     def load(self, path, filename):
00049         self.filename = filename
00050         self.path = path
00051         #try:
00052         dict = ut.load_pickle(self.path+'/'+self.filename)
00053         #except:
00054         #    print 'loading of '+self.path+'/'+filename+' failed. WARNING: it will be overwritten on save()!'
00055         #    return
00056             
00057         self.datasets = dict['datasets']
00058         
00059     def save(self):
00060         dict = {'datasets': self.datasets,'version': 0.1} 
00061         
00062         #for now: make a backup first:
00063         database_filename = self.path+'/'+self.filename
00064         backup_filename = self.path+'/'+self.filename+'_backup_'+ut.formatted_time()
00065         print 'Backing up old database to ' + backup_filename       
00066         shutil.copy(database_filename, backup_filename)
00067         
00068         print "Saving: "+database_filename
00069         ut.save_pickle(dict,database_filename)    
00070            
00071         
00072     def get_path(self):
00073         return self.path
00074         
00075     def get_dataset(self, index):
00076         self.current_index = index
00077         return self.datasets[index]
00078     
00079     def get_dataset_by_id(self, id):
00080         #TODO: faster lookup, probably using a dictionary instead of a list?
00081         
00082         for dataset in self.datasets:
00083             if dataset.id == id:
00084                 return dataset
00085         return False
00086     
00087     def set_internal_pointer_to_dataset(self, id):
00088         self.current_index = 0
00089         for dataset in self.datasets:
00090             if dataset.id == id:
00091                 return True
00092             self.current_index += 1
00093         return False
00094     
00095     def get_next_dataset(self):
00096         if self.current_index < len(self.datasets) - 1:
00097             self.current_index = self.current_index + 1
00098             return self.datasets[self.current_index]
00099         else:
00100             return False
00101             
00102     def get_prev_dataset(self):
00103         if self.current_index > 0:
00104             self.current_index = self.current_index - 1
00105             return self.datasets[self.current_index]
00106         else:
00107             return False    
00108         
00109     def get_first_dataset(self):
00110         if len(self.datasets) > 0:
00111             self.current_index = 0
00112             return self.datasets[self.current_index]
00113         else:
00114             return False    
00115         
00116     def get_last_dataset(self):
00117         if len(self.datasets) > 0:
00118             self.current_index = len(self.datasets) - 1
00119             return self.datasets[self.current_index]
00120         else:
00121             return False                     
00122         
00123         
00124     def get_count(self):
00125         return len(self.datasets)
00126     
00127     def add_dataset(self, dataset):
00128         self.datasets.append(dataset)
00129         
00130     def delete_current_dataset(self):
00131         del self.datasets[self.current_index]
00132         dataset = self.get_prev_dataset()
00133         if False != dataset:
00134             return  dataset
00135         else: 
00136             dataset = self.get_next_dataset()
00137         return dataset #TODO: still fails if there is only one dataset!
00138         
00139         
00140     def add_attribute_to_every_dataset(self, name):
00141         for dataset in self.datasets:
00142             dataset.dict[name]=''
00143         
00144     


clutter_segmentation
Author(s): Jason Okerman, Martin Schuster, Advisors: Prof. Charlie Kemp and Jim Regh, Lab: Healthcare Robotics Lab at Georgia Tech
autogenerated on Wed Nov 27 2013 12:07:15