Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008 #include "articulation_models/models/factory.h"
00009
00010 #include <typeinfo>
00011
00012 #include "articulation_models/models/generic_model.h"
00013 #include "articulation_models/models/rigid_model.h"
00014 #include "articulation_models/models/prismatic_model.h"
00015 #include "articulation_models/models/rotational_model.h"
00016 #include "articulation_models/models/pca_gp_model.h"
00017
00018 using namespace std;
00019
00020 namespace articulation_models {
00021
00022 MultiModelFactory MultiModelFactory::instance;
00023
00024 MultiModelFactory::MultiModelFactory() {
00025 all_factories.push_back(new SingleModelFactory<RigidModel>("rigid"));
00026 all_factories.push_back(new SingleModelFactory<PrismaticModel>("prismatic"));
00027 all_factories.push_back(new SingleModelFactory<RotationalModel>("rotational"));
00028 all_factories.push_back(new SingleModelFactory<PCAGPModel>("pca_gp"));
00029 setFilter("");
00030 }
00031
00032 GenericModelVector MultiModelFactory::createModels(const articulation_msgs::TrackMsg& trackMsg) {
00033 GenericModelVector models;
00034 for(size_t i=0;i<factories.size();i++) {
00035 models.push_back( factories[i]->createModel(trackMsg) );
00036 }
00037 return(models);
00038 }
00039
00040 GenericModelVector MultiModelFactory::createModels(articulation_msgs::TrackMsgConstPtr trackMsg) {
00041 GenericModelVector models;
00042 for(size_t i=0;i<factories.size();i++) {
00043 models.push_back( factories[i]->createModel(trackMsg) );
00044 }
00045 return(models);
00046 }
00047
00048 GenericModelVector MultiModelFactory::createModels(const articulation_msgs::ModelMsg& modelMsg) {
00049 GenericModelVector models;
00050 for(size_t i=0;i<factories.size();i++) {
00051 models.push_back( factories[i]->createModel(modelMsg) );
00052 }
00053 return(models);
00054 }
00055
00056 GenericModelVector MultiModelFactory::createModels(articulation_msgs::ModelMsgConstPtr modelMsg) {
00057 GenericModelVector models;
00058 for(size_t i=0;i<factories.size();i++) {
00059 models.push_back( factories[i]->createModel(modelMsg) );
00060 }
00061 return(models);
00062 }
00063
00064 GenericModelPtr MultiModelFactory::restoreModel(articulation_msgs::ModelMsgConstPtr modelMsg) {
00065 for(size_t i=0;i<factories.size();i++) {
00066 if( factories[i]->getLongName() == modelMsg->name ) {
00067 return( factories[i]->createModel(modelMsg) );
00068 }
00069 }
00070 return( GenericModelPtr() );
00071 }
00072
00073 GenericModelPtr MultiModelFactory::restoreModel(const articulation_msgs::ModelMsg &modelMsg) {
00074 for(size_t i=0;i<factories.size();i++) {
00075 if( factories[i]->getLongName() == modelMsg.name ) {
00076 return( factories[i]->createModel(modelMsg) );
00077 }
00078 }
00079 return( GenericModelPtr() );
00080 }
00081
00082 void MultiModelFactory::listModelFactories() {
00083 cout << "MultiModelFactory::listModelFactories(), "<< factories.size()<<" model factories registered:"<< endl;
00084 for(size_t i=0;i<factories.size();i++) {
00085 cout << factories[i]->getLongName() << endl;
00086 }
00087 }
00088
00089 std::string MultiModelFactory::getLongName(GenericModel* model) {
00090 std::string classname = typeid(*model).name();
00091 for(size_t i=0;i<instance.factories.size();i++) {
00092 if( classname == instance.factories[i]->getClassName() )
00093 return instance.factories[i]->getLongName();
00094 }
00095 return("unknown_model");
00096 }
00097
00098 int MultiModelFactory::getModelIndex(std::string name) {
00099 for(size_t i=0;i<instance.factories.size();i++) {
00100 if( name == instance.factories[i]->getClassName() || name == instance.factories[i]->getLongName() )
00101 return i;
00102 }
00103 return -1;
00104 }
00105
00106 int MultiModelFactory::getFactoryCount() {
00107 return(factories.size());
00108 }
00109
00110 void MultiModelFactory::setFilter(std::string filter) {
00111 if(filter=="") {
00112 factories = all_factories;
00113
00114 for(size_t i=0;i<factories.size();i++) {
00115
00116
00117 }
00118 return;
00119 }
00120
00121 std::stringstream ss(filter);
00122 factories.clear();
00123 while(!ss.eof()) {
00124 std::string allowed_model = "";
00125 ss >> allowed_model;
00126 bool found = false;
00127 for(size_t i=0;i<all_factories.size();i++) {
00128 if( all_factories[i]->getLongName() == allowed_model ) {
00129 factories.push_back(all_factories[i]);
00130
00131 found = true;
00132 }
00133 }
00134 if(!found) {
00135 cout << "MultiModelFactory: cannot add, because model unknown: "<< allowed_model<< endl;
00136 exit(1);
00137 }
00138 }
00139 }
00140
00141
00142 }