1 //: 2 // \file 3 // \author Isabel Restrepo 4 // \date 25-Jan-2011 5 6 #include "bvpl_taylor_basis_factory.h" 7 #include <iostream> 8 #include <map> 9 #include <utility> 10 #ifdef _MSC_VER 11 # include "vcl_msvc_warnings.h" 12 #endif 13 14 //: Constructor from filename bvpl_taylor_basis_factory(std::string filename)15bvpl_taylor_basis_factory::bvpl_taylor_basis_factory(std::string filename) 16 { 17 //initialize variables 18 filename_ = std::move(filename); 19 angle_ = 0.0f; 20 rotation_axis_ = canonical_rotation_axis_; 21 parallel_axis_ = canonical_parallel_axis_; 22 23 //this skernel is symmetric around main axis 24 angular_resolution_=0; 25 26 //create the default kernel 27 create_canonical(); 28 } 29 create_canonical()30void bvpl_taylor_basis_factory::create_canonical() 31 { 32 typedef bvpl_kernel_dispatch dispatch; 33 34 std::ifstream ifs(filename_.c_str()); 35 36 //set the dimension of the 3-d bounding box containing the kernels 37 if (!ifs.eof()) 38 { 39 ifs >> min_point_; 40 ifs >> max_point_; 41 } 42 std::cout << " Max point: " << max_point_ << " Min point: " << min_point_ << std::endl; 43 44 while (!ifs.eof()) 45 { 46 vgl_point_3d<float> this_loc; 47 float weight; 48 ifs >> this_loc; 49 ifs >> weight; 50 canonical_kernel_.emplace_back(this_loc, dispatch(weight)); 51 } 52 53 //set the current kernel 54 kernel_ = canonical_kernel_; 55 factory_name_ = name(); 56 } 57 58 59 /************************bvpl_taylor_basis_loader**************************************/ 60 create_basis(std::map<std::string,bvpl_kernel_sptr> & taylor_basis)61void bvpl_taylor_basis_loader::create_basis(std::map<std::string, bvpl_kernel_sptr> &taylor_basis) 62 { 63 //get filenames, iterate through files reading the kernels 64 std::vector<std::string> filenames; 65 files(filenames); 66 67 auto file_it =filenames.begin(); 68 69 for (; file_it != filenames.end(); file_it++) 70 { 71 std::string filename = path_ + '/' + *file_it + ".txt"; 72 std::cout << "Reading kernel file : " << filename << std::endl; 73 bvpl_taylor_basis_factory factory(filename); 74 bvpl_kernel_sptr kernel = new bvpl_kernel(factory.create()); 75 //kernel->print(); 76 taylor_basis.insert(std::pair<std::string, bvpl_kernel_sptr>(*file_it, kernel)); 77 } 78 } 79 80 //: Kernels needed for 2 degree approximation of 3D functions files(std::vector<std::string> & filenames)81void bvpl_taylor_basis_loader::files(std::vector<std::string> &filenames) 82 { 83 if (degree_ == 2) 84 { 85 filenames.emplace_back("I0"); 86 filenames.emplace_back("Ix"); 87 filenames.emplace_back("Iy"); 88 filenames.emplace_back("Iz"); 89 filenames.emplace_back("Ixx"); 90 filenames.emplace_back("Iyy"); 91 filenames.emplace_back("Izz"); 92 filenames.emplace_back("Ixy"); 93 filenames.emplace_back("Ixz"); 94 filenames.emplace_back("Iyz"); 95 } 96 } 97