table_objects.h
Go to the documentation of this file.
00001 /*
00002  * Software License Agreement (BSD License)
00003  *
00004  *  Copyright (c) 2010, Willow Garage, Inc.
00005  *  All rights reserved.
00006  *
00007  *  Redistribution and use in source and binary forms, with or without
00008  *  modification, are permitted provided that the following conditions
00009  *  are met:
00010  *
00011  *   * Redistributions of source code must retain the above copyright
00012  *     notice, this list of conditions and the following disclaimer.
00013  *   * Redistributions in binary form must reproduce the above
00014  *     copyright notice, this list of conditions and the following
00015  *     disclaimer in the documentation and/or other materials provided
00016  *     with the distribution.
00017  *   * Neither the name of Willow Garage, Inc. nor the names of its
00018  *     contributors may be used to endorse or promote products derived
00019  *     from this software without specific prior written permission.
00020  *
00021  *  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
00022  *  "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
00023  *  LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
00024  *  FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
00025  *  COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
00026  *  INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
00027  *  BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
00028  *  LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
00029  *  CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
00030  *  LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
00031  *  ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
00032  *  POSSIBILITY OF SUCH DAMAGE.
00033  *
00034  * $Id$
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   // Set the tree metric type
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   // --[ Read the kdtree index file
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   // Check if the tree index has already been saved to disk
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   // --[ Read the training data h5 file
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   // --[ Read the training data list file
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   // Check if the data has already been saved to disk
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


table_objects
Author(s): Zoltan-Csaba Marton
autogenerated on Mon Oct 6 2014 08:15:32