Go to the documentation of this file.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
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00046 #ifndef TABLE_OBJECTS_H_
00047 #define TABLE_OBJECTS_H_
00048
00049 #include <boost/filesystem.hpp>
00050
00051 #include <fstream>
00052 #include <sstream>
00053 #include <iostream>
00054 #include <utility>
00055 #include <cctype>
00056
00057 #include <flann/flann.h>
00058 #include <flann/io/hdf5.h>
00059
00060 #include <terminal_tools/parse.h>
00061 #include <terminal_tools/print.h>
00062
00063 #include <pcl/common/common.h>
00064 #include <pcl/features/feature.h>
00065 #include <pcl/registration/transforms.h>
00066 #include <pcl/features/normal_3d.h>
00067 #include <pcl/features/vfh.h>
00068 #include <pcl/point_types.h>
00069 #include <pcl/point_cloud.h>
00070 #include <pcl/io/pcd_io.h>
00071
00072 using namespace std;
00073 using namespace pcl;
00074 using namespace terminal_tools;
00075
00076 typedef std::pair<std::string, std::vector<float> > vfh_model;
00077
00078 int metric;
00079 std::string kdtree_idx_file_name;
00080 std::string training_data_h5_file_name;
00081 std::string training_data_list_file_name;
00082 std::vector<vfh_model> models;
00083
00085
00089 bool
00090 loadFileList (vector<vfh_model> &models, const string &filename)
00091 {
00092 ifstream fs;
00093 fs.open (filename.c_str ());
00094 if (!fs.is_open () || fs.fail ())
00095 return (false);
00096
00097 string line;
00098 while (!fs.eof ())
00099 {
00100 getline (fs, line);
00101 if (line.empty ())
00102 continue;
00103 vfh_model m;
00104 m.first = line;
00105 models.push_back (m);
00106 }
00107 fs.close ();
00108 return (true);
00109 }
00110
00111 int
00112 getParameters (int argc, char** argv)
00113 {
00114
00115 metric = 7;
00116 parse_argument (argc, argv, "-metric", metric);
00117 if (metric < 0 || metric > 7)
00118 {
00119 print_error ("Invalid metric specified (%d)!\n", metric);
00120 return (-1);
00121 }
00122 flann_set_distance_type ((flann_distance_t)metric, 0);
00123 print_highlight ("Using distance metric = "); print_value ("%d\n", metric);
00124
00125
00126 kdtree_idx_file_name = "kdtree.idx";
00127 vector<int> idx_indices = parse_file_extension_argument (argc, argv, ".idx");
00128 if (idx_indices.size () > 1)
00129 {
00130 print_error ("Need a single kdtree index file!\n");
00131 return (-1);
00132 }
00133 if (idx_indices.size () == 1)
00134 kdtree_idx_file_name = argv[idx_indices.at (0)];
00135
00136 if (!boost::filesystem::exists (kdtree_idx_file_name))
00137 {
00138 print_error ("Could not find kd-tree index in file %s!", kdtree_idx_file_name.c_str ());
00139 return (-1);
00140 }
00141 print_highlight ("Using "); print_value ("%s", kdtree_idx_file_name.c_str ()); print_info (" as the kdtree index file.\n");
00142
00143
00144 training_data_h5_file_name = "training_data.h5";
00145 vector<int> train_h5_indices = parse_file_extension_argument (argc, argv, ".h5");
00146 if (train_h5_indices.size () > 1)
00147 {
00148 print_error ("Need a single h5 training data file!\n");
00149 return (-1);
00150 }
00151 if (train_h5_indices.size () == 1)
00152 training_data_h5_file_name = argv[train_h5_indices.at (0)];
00153 print_highlight ("Using "); print_value ("%s", training_data_h5_file_name.c_str ()); print_info (" as the h5 training data file.\n");
00154
00155
00156 training_data_list_file_name = "training_data.list";
00157 vector<int> train_list_indices = parse_file_extension_argument (argc, argv, ".list");
00158 if (train_list_indices.size () > 1)
00159 {
00160 print_error ("Need a single list training data file!\n");
00161 return (-1);
00162 }
00163 if (train_list_indices.size () == 1)
00164 training_data_list_file_name = argv[train_list_indices.at (0)];
00165 print_highlight ("Using "); print_value ("%s", training_data_list_file_name.c_str ()); print_info (" as the list training data file.\n");
00166
00167
00168 if (!boost::filesystem::exists (training_data_h5_file_name) || !boost::filesystem::exists (training_data_list_file_name))
00169 {
00170 print_error ("Could not find training data models files %s and %s!\n", training_data_h5_file_name.c_str (), training_data_list_file_name.c_str ());
00171 return (-1);
00172 }
00173
00174 return (1);
00175 }
00176
00177 #endif