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 #include <string>
00035 #include <fstream>
00036 #include <iostream>
00037 #include <octomap/octomap.h>
00038 #include <cstdlib>
00039 #include <cstring>
00040
00041 using namespace std;
00042 using namespace octomap;
00043
00044 typedef unsigned char byte;
00045
00046 int main(int argc, char **argv)
00047 {
00048
00049
00050 bool show_help = false;
00051 string outputFilename("");
00052 string inputFilename("");
00053
00054
00055
00056
00057
00058
00059
00060
00061 octomap::point3d offset(0.0, 0.0, 0.0);
00062
00063 double scale = 1.0;
00064 double res = -1.0;
00065
00066 if(argc == 1) show_help = true;
00067 for(int i = 1; i < argc && !show_help; i++) {
00068 if(strcmp(argv[i], "--help") == 0 || strcmp(argv[i], "-help") == 0 ||
00069 strcmp(argv[i], "--usage") == 0 || strcmp(argv[i], "-usage") == 0 ||
00070 strcmp(argv[i], "-h") == 0
00071 )
00072 show_help = true;
00073 }
00074
00075 if(show_help) {
00076 cout << "Usage: "<<argv[0]<<" [OPTIONS] <filename.bt>" << endl;
00077 cout << "\tOPTIONS:" << endl;
00078 cout << "\t -o <file> Output filename (default: first input filename + .bt)" << endl;
00079
00080
00081 cout << "\t --offset <x> <y> <z>: add an offset to the octree coordinates (translation)\n";
00082
00083 cout << "\t --res <resolution>: set ressolution of OcTree to new value\n";
00084 cout << "\t --scale <scale>: scale octree resolution by a value\n";
00085 exit(0);
00086 }
00087
00088 for(int i = 1; i < argc; i++) {
00089
00090 if(strcmp(argv[i], "--rotate") == 0) {
00091 OCTOMAP_WARNING_STR(argv[i] << " not yet implemented!\n");
00092
00093 continue;
00094 } else if(strcmp(argv[i], "-o") == 0 && i < argc - 1) {
00095 i++;
00096 outputFilename = argv[i];
00097 continue;
00098 } else if (strcmp(argv[i], "--bb") == 0 && i < argc - 7) {
00099 OCTOMAP_WARNING_STR(argv[i] << " not yet implemented!\n");
00100 i++;
00101
00102 i++;
00103
00104 i++;
00105
00106 i++;
00107
00108 i++;
00109
00110 i++;
00111
00112
00113
00114
00115 continue;
00116 } else if (strcmp(argv[i], "--res") == 0 && i < argc - 1) {
00117 i++;
00118 res = atof(argv[i]);
00119
00120 continue;
00121 } else if (strcmp(argv[i], "--scale") == 0 && i < argc - 1) {
00122 i++;
00123 scale = atof(argv[i]);
00124
00125 continue;
00126 } else if (strcmp(argv[i], "--offset") == 0 && i < argc - 4) {
00127 OCTOMAP_WARNING_STR(argv[i] << " not yet implemented!\n");
00128 i++;
00129 offset(0) = (float) atof(argv[i]);
00130 i++;
00131 offset(1) = (float) atof(argv[i]);
00132 i++;
00133 offset(2) = (float) atof(argv[i]);
00134
00135
00136
00137 continue;
00138 } else if (i == argc-1){
00139 inputFilename = string(argv[i]);
00140 }
00141 }
00142
00143 if (outputFilename == ""){
00144 outputFilename = inputFilename + ".edit.bt";
00145 }
00146
00147 OcTree* tree = new OcTree(0.1);
00148 if (!tree->readBinary(inputFilename)){
00149 OCTOMAP_ERROR("Could not open file, exiting.\n");
00150 exit(1);
00151 }
00152
00153
00154
00155 if (scale != 1.0){
00156 res = tree->getResolution() * scale;
00157 }
00158
00159 if (res > 0.0){
00160 std::cout << "Setting new tree resolution: " << res << std::endl;
00161 tree->setResolution(res);
00162 }
00163
00164
00165
00166
00167
00168
00169
00170
00171
00172
00173
00174
00175
00176
00177
00178
00179
00180
00181
00182
00183
00184
00185
00186
00187
00188
00189
00190
00191
00192
00193
00194
00195
00196
00197
00198
00199
00200
00201
00202
00203
00204
00205
00206
00207
00208
00209
00210
00211
00212
00213
00214
00215 cout << "Writing octree to " << outputFilename << endl;
00216
00217 if (!tree->writeBinary(outputFilename)){
00218 OCTOMAP_ERROR("Error writing tree to %s\n", outputFilename.c_str());
00219 exit(1);
00220 }
00221
00222 cout << "done" << endl << endl;
00223 delete tree;
00224 return 0;
00225 }