metadata.cpp
Go to the documentation of this file.
00001 #include <megatree/metadata.h>
00002 #include <string>
00003 #include <string.h>
00004 #include <stdio.h>
00005 #include <stdlib.h>
00006 #include <sstream>
00007 #include <boost/program_options.hpp>
00008 
00009 
00010 namespace megatree
00011 {
00012 
00013   void MetaData::deserialize(const ByteVec& data)
00014   {
00015     // convert ByteVec to string
00016     std::string meta_str(data.size(), 'c');
00017     memcpy(&meta_str[0], &data[0], data.size());
00018     std::stringstream meta_stream(meta_str);
00019 
00020     // define options
00021     boost::program_options::options_description descr("MegaTree Options");
00022     descr.add_options()
00023       ("version", boost::program_options::value<unsigned>(), "Megatree version")
00024       ("min_cell_size", boost::program_options::value<double>(), "The minimum allowed size of a cell")
00025       ("subtree_width", boost::program_options::value<unsigned>(), "The width of the top of each subtree, in powers of 8")
00026       ("subfolder_depth", boost::program_options::value<unsigned>(), "The number of tree layers in each subfolder")
00027       ("tree_center_x", boost::program_options::value<double>(), "The center of the tree, x-coordinate")
00028       ("tree_center_y", boost::program_options::value<double>(), "The center of the tree, y-coordinate")
00029       ("tree_center_z", boost::program_options::value<double>(), "The center of the tree, z-coordinate")
00030       ("tree_size",     boost::program_options::value<double>(), "The size of the tree")
00031       ("default_camera_center_x",     boost::program_options::value<double>(), "The camera center, x-coordinate")
00032       ("default_camera_center_y",     boost::program_options::value<double>(), "The camera center, y-coordinate")
00033       ("default_camera_center_z",     boost::program_options::value<double>(), "The camera center, z-coordinate")
00034       ("default_camera_distance",     boost::program_options::value<double>(), "The camera distance")
00035       ("default_camera_pitch",        boost::program_options::value<double>(), "The camera pitch")
00036       ("default_camera_yaw",          boost::program_options::value<double>(), "The camera yaw");
00037     boost::program_options::variables_map vm;
00038     boost::program_options::store(boost::program_options::parse_config_file<char>(meta_stream, descr), vm);
00039     
00040     // check existance of parameters
00041     assert(vm.count("version"));
00042     assert(vm.count("min_cell_size"));
00043     assert(vm.count("subtree_width"));
00044     assert(vm.count("subfolder_depth"));
00045     assert(vm.count("tree_center_x"));
00046     assert(vm.count("tree_center_y"));
00047     assert(vm.count("tree_center_z"));
00048     assert(vm.count("tree_size"));
00049     
00050     // get params
00051     version = vm["version"].as<unsigned>();
00052     min_cell_size = vm["min_cell_size"].as<double>();
00053     root_size = vm["tree_size"].as<double>();
00054     root_center.resize(3);
00055     root_center[0] = vm["tree_center_x"].as<double>();
00056     root_center[1] = vm["tree_center_y"].as<double>();
00057     root_center[2] = vm["tree_center_z"].as<double>();
00058     subtree_width = vm["subtree_width"].as<unsigned>();
00059     subfolder_depth = vm["subfolder_depth"].as<unsigned>();
00060   }
00061 
00062 
00063   void MetaData::serialize(ByteVec& data)
00064   {
00065     std::stringstream output;
00066     output << "version = " << version << std::endl;
00067     output << "min_cell_size = " << min_cell_size << std::endl;
00068     output << "subtree_width = " << subtree_width << std::endl;
00069     output << "subfolder_depth = " << subfolder_depth << std::endl;
00070     output << "tree_center_x = " << root_center[0] << std::endl;
00071     output << "tree_center_y = " << root_center[1] << std::endl;
00072     output << "tree_center_z = " << root_center[2] << std::endl;
00073     output << "tree_size = " << root_size << std::endl;
00074 
00075     data.resize(output.str().size());
00076     memcpy(&data[0], &output.str()[0], data.size());
00077   }
00078 
00079 
00080 
00081 } // namespace


megatree_core
Author(s): Stuart Glaser
autogenerated on Thu Nov 28 2013 11:30:23