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_CACHING_ALIGNER_H
00031 #define DB_PLANNER_CACHING_ALIGNER_H
00032
00033 #include <string>
00034 #include "aligner.h"
00035 #include "db_manager.h"
00036 #include "model.h"
00037 using std::string;
00038
00039 namespace db_planner {
00040
00042
00048 class CachingAligner : public Aligner<Model>{
00049 private:
00051 const DatabaseManager& db_manager_;
00053 const bool cache_results_;
00055 const bool cache_inverse_results_;
00057 const string alignment_method_name_;
00059 const Aligner<Model> aligner_;
00061 bool InvertTransform(float* ,
00062 float* ) const { return false; }
00063 public:
00064 CachingAligner(const DatabaseManager& db_manager,
00065 const bool cache_results,
00066 const bool cache_inverse_results,
00067 const string alignment_method_name,
00068 const Aligner<Model>& aligner = Aligner<Model>())
00069 : db_manager_(db_manager),
00070 cache_results_(cache_results),
00071 cache_inverse_results_(cache_inverse_results),
00072 alignment_method_name_(alignment_method_name),
00073 aligner_(aligner) { }
00074
00076
00077 virtual bool Align(const Model& source,
00078 const Model& dest,
00079 float transform[16]) const {
00080
00081 if (db_manager_.GetAlignment(source,
00082 dest,
00083 alignment_method_name_,
00084 transform)) {
00085 return true;
00086 }
00087
00088 if (aligner_.Align(source, dest, transform)) {
00089 if (cache_results_)
00090 db_manager_.SaveAlignment(source,
00091 dest,
00092 alignment_method_name_,
00093 transform);
00094 float inverse[16];
00095
00096 if (cache_inverse_results_ && InvertTransform(transform, inverse))
00097 db_manager_.SaveAlignment(dest,
00098 source,
00099 alignment_method_name_,
00100 inverse);
00101 return true;
00102 }
00103 return false;
00104 }
00105 };
00106
00107
00108 }
00109
00110 #endif // DB_PLANNER_CACHING_ALIGNER_H