47 std::cerr <<
"\nUSAGE: " <<
self <<
" input.(ot|bt|cot) [output.ot]\n\n";
49 std::cerr <<
"This tool converts between OctoMap octree file formats, \n"
50 "e.g. to convert old legacy files to the new .ot format or to convert \n"
51 "between .bt and .ot files. The default output format is .ot.\n\n";
56 int main(
int argc,
char** argv) {
57 string inputFilename =
"";
58 string outputFilename =
"";
60 if (argc < 2 || argc > 3 || (argc > 1 && strcmp(argv[1],
"-h") == 0)){
64 inputFilename = std::string(argv[1]);
66 outputFilename = std::string(argv[2]);
68 outputFilename = inputFilename +
".ot";
72 cout <<
"\nReading OcTree file\n===========================\n";
73 std::ifstream file(inputFilename.c_str(), std::ios_base::in |std::ios_base::binary);
76 OCTOMAP_ERROR_STR(
"Filestream to "<< inputFilename <<
" not open, nothing read.");
80 std::istream::pos_type streampos = file.tellg();
84 if (inputFilename.length() > 3 && (inputFilename.compare(inputFilename.length()-3, 3,
".bt") == 0)){
95 tree = AbstractOcTree::read(file);
101 file.seekg(streampos);
104 if (colorTree->
size() > 1 && file.good()){
105 OCTOMAP_WARNING_STR(
"Detected Binary ColorOcTree to convert. \nPlease check and update the new file header (resolution will likely be wrong).");
109 std::cerr <<
"Error reading from file " << inputFilename << std::endl;
121 if (outputFilename.length() > 3 && (outputFilename.compare(outputFilename.length()-3, 3,
".bt") == 0)){
122 std::cerr <<
"Writing binary (BonsaiTree) file" << std::endl;
126 std::cerr <<
"Error writing to " << outputFilename << std::endl;
130 std::cerr <<
"Error: Writing to .bt is not supported for this tree type: " << tree->
getTreeType() << std::endl;
134 std::cerr <<
"Writing general OcTree file" << std::endl;
135 if (!tree->
write(outputFilename)){
136 std::cerr <<
"Error writing to " << outputFilename << std::endl;
145 std::cout <<
"Finished writing to " << outputFilename << std::endl;