00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00030 #ifndef DB_PLANNER_DB_MANAGER_H
00031 #define DB_PLANNER_DB_MANAGER_H
00032
00033 #include <string>
00034 #include <vector>
00035 #include <utility>
00036 #include "model.h"
00037 #include "task.h"
00038 #include "grasp.h"
00039 using std::pair;
00040 using std::string;
00041 using std::vector;
00042
00043 class GraspAllocator;
00044 class ModelAllocator;
00045
00046 namespace db_planner {
00047
00050 class FilterList{
00051 public:
00053 enum FilterType{NONE, HAS_HUMAN_GRASPS, HAS_HUMAN_REFINED_GRASPS, OLD_STYLE_IV};
00055 static string GetWhereClause(FilterType filter) {
00056 if (filter == HAS_HUMAN_GRASPS) {
00057 return "WHERE model_name IN (SELECT DISTINCT scaled_model_name "
00058 "FROM grasp JOIN scaled_model USING(scaled_model_id) "
00059 "WHERE grasp_source_id = 2)";
00060 } else if (filter == HAS_HUMAN_REFINED_GRASPS) {
00061 return "WHERE model_name IN (SELECT DISTINCT scaled_model_name "
00062 "FROM grasp JOIN scaled_model USING(scaled_model_id) "
00063 "WHERE grasp_source_id = 3)";
00064 } else if (filter == OLD_STYLE_IV) {
00065 return "WHERE model_name LIKE 'matei%'";
00066 } else {
00067 return "";
00068 }
00069 }
00070 };
00071
00072
00074 class DatabaseManager {
00075 protected:
00076
00078
00079 ModelAllocator *model_allocator_;
00081
00082 GraspAllocator *grasp_allocator_;
00083
00084 public:
00085
00087 virtual void SetGraspAllocator(GraspAllocator* allocator) = 0;
00088
00090 virtual void SetModelAllocator(ModelAllocator* allocator) = 0;
00091
00093 virtual bool isConnected() const = 0;
00095
00097 virtual bool GetAlignment(const Model& source,
00098 const Model& dest,
00099 const string& alignment_method_name,
00100 float alignment[16]) const = 0;
00102
00103 virtual bool SaveAlignment(const Model& source,
00104 const Model& dest,
00105 const string& alignment_method_name,
00106 const float alignment[16]) const = 0;
00108
00110 virtual bool GetNeighbors(const Model& model,
00111 const string& distance_function_name,
00112 const int num_neighbors,
00113 vector<pair<Model*, double> >* neighbors)
00114 const = 0;
00116 virtual bool SaveNeighbors(const Model& model,
00117 const string& distance_function_name,
00118 const vector<pair<Model*, double> >& neighbors)
00119 const = 0;
00121 virtual bool GetGrasps(const Model& model,
00122 const string& hand_name,
00123 vector<Grasp*>* grasp_list) const = 0;
00125
00127 virtual bool AcquireNextTask(TaskRecord *rec) = 0;
00129 virtual bool SetTaskStatus(int task_id, const string &status) = 0;
00131 virtual bool GetPlanningTaskRecord(int task_id, PlanningTaskRecord *rec) = 0;
00133 virtual bool GetOptimizationTaskRecord(int , OptimizationTaskRecord* ) {return false;}
00135 virtual bool SaveOptimizationResults(const OptimizationTaskRecord& ,
00136 const std::vector<double>& ,
00137 const std::vector<double>& ) {return false;}
00138
00140 virtual bool SaveGrasp(const Grasp*) const = 0;
00142 virtual bool SaveGrasps(const vector<Grasp*> graspList) const{
00143 for(size_t i = 0; i < graspList.size(); ++i){
00144 if (!SaveGrasp(graspList[i])) {
00145 return false;
00146 }
00147 }
00148 return true;
00149 }
00151 virtual bool DeleteGrasp(Grasp* grasp) const = 0;
00153
00157 virtual bool SetGraspClusterRep(Grasp *grasp, bool rep) const = 0;
00158
00160 virtual bool InsertGraspPair(const Grasp *grasp1, const Grasp *grasp2) const = 0;
00162 virtual bool SetGraspTableClearance(Grasp *grasp, double clearance) const = 0;
00164 virtual bool ModelList(vector<Model*>* model_list,
00165 FilterList::FilterType filter = FilterList::NONE) const = 0;
00167 virtual bool ScaledModel(Model* &model, int scaled_model_id) const = 0;
00169 virtual bool GraspTypeList(vector<string>* type_list) const = 0;
00171 virtual bool DistanceFunctionList(
00172 vector<string>* distance_function_list) const = 0;
00174 virtual bool AlignmentMethodList(
00175 vector<string>* alignment_method_list) const = 0;
00177 virtual bool LoadModelGeometry(Model*) const = 0;
00178 };
00179
00180 }
00181 #endif // DB_PLANNER_DB_MANAGER