本文整理汇总了C++中OcTree::search方法的典型用法代码示例。如果您正苦于以下问题:C++ OcTree::search方法的具体用法?C++ OcTree::search怎么用?C++ OcTree::search使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类OcTree
的用法示例。
在下文中一共展示了OcTree::search方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: main
int main(int argc, char** argv) {
cout << endl;
cout << "generating example map" << endl;
OcTree tree (0.1); // create empty tree with resolution 0.1
// insert some measurements of occupied cells
for (int x=-20; x<20; x++) {
for (int y=-20; y<20; y++) {
for (int z=-20; z<20; z++) {
point3d endpoint ((float) x*0.05f, (float) y*0.05f, (float) z*0.05f);
tree.updateNode(endpoint, true); // integrate 'occupied' measurement
}
}
}
// insert some measurements of free cells
for (int x=-30; x<30; x++) {
for (int y=-30; y<30; y++) {
for (int z=-30; z<30; z++) {
point3d endpoint ((float) x*0.02f-1.0f, (float) y*0.02f-1.0f, (float) z*0.02f-1.0f);
tree.updateNode(endpoint, false); // integrate 'free' measurement
}
}
}
cout << endl;
cout << "performing some queries:" << endl;
point3d query (0., 0., 0.);
OcTreeNode* result = tree.search (query);
print_query_info(query, result);
query = point3d(-1.,-1.,-1.);
result = tree.search (query);
print_query_info(query, result);
query = point3d(1.,1.,1.);
result = tree.search (query);
print_query_info(query, result);
cout << endl;
tree.writeBinary("simple_tree.bt");
cout << "wrote example file simple_tree.bt" << endl << endl;
cout << "now you can use octovis to visualize: octovis simple_tree.bt" << endl;
cout << "Hint: hit 'F'-key in viewer to see the freespace" << endl << endl;
}
示例2: printChanges
void printChanges(OcTree& tree){
unsigned int changedOccupied = 0;
unsigned int changedFree = 0;
unsigned int actualOccupied = 0;
unsigned int actualFree = 0;
unsigned int missingChanged = 0;
tree.expand();
// iterate through the changed nodes
KeyBoolMap::const_iterator it;
for (it=tree.changedKeysBegin(); it!=tree.changedKeysEnd(); it++) {
OcTreeNode* node = tree.search(it->first);
if (node != NULL) {
if (tree.isNodeOccupied(node)) {
changedOccupied += 1;
}
else {
changedFree += 1;
}
} else {
missingChanged +=1;
}
}
// iterate through the entire tree
for(OcTree::tree_iterator it=tree.begin_tree(),
end=tree.end_tree(); it!= end; ++it) {
if (it.isLeaf()) {
if (tree.isNodeOccupied(*it)) {
actualOccupied += 1;
}
else {
actualFree += 1;
}
}
}
cout << "change detection: " << changedOccupied << " occ; " << changedFree << " free; "<< missingChanged << " missing" << endl;
cout << "actual: " << actualOccupied << " occ; " << actualFree << " free; " << endl;
tree.prune();
}
示例3: main
int main(int argc, char** argv) {
if (argc != 2){
std::cerr << "Error: you need to specify a testfile (.bt) as argument to read" << std::endl;
return 1; // exit 1 means failure
}
std::cout << "Testing empty OcTree...\n";
//empty tree
{
OcTree emptyTree(0.999);
EXPECT_EQ(emptyTree.size(), 0);
EXPECT_TRUE(emptyTree.writeBinary("empty.bt"));
EXPECT_TRUE(emptyTree.write("empty.ot"));
OcTree emptyReadTree(0.2);
EXPECT_TRUE(emptyReadTree.readBinary("empty.bt"));
EXPECT_EQ(emptyReadTree.size(), 0);
EXPECT_TRUE(emptyTree == emptyReadTree);
AbstractOcTree* readTreeAbstract = AbstractOcTree::read("empty.ot");
EXPECT_TRUE(readTreeAbstract);
OcTree* readTreeOt = dynamic_cast<OcTree*>(readTreeAbstract);
EXPECT_TRUE(readTreeOt);
EXPECT_EQ(readTreeOt->size(), 0);
EXPECT_TRUE(emptyTree == *readTreeOt);
delete readTreeOt;
}
std::cout << "Testing reference OcTree from file ...\n";
string filename = string(argv[1]);
{
string filenameOt = "test_io_file.ot";
string filenameBtOut = "test_io_file.bt";
string filenameBtCopyOut = "test_io_file_copy.bt";
// read reference tree from input file
OcTree tree (0.1);
EXPECT_TRUE (tree.readBinary(filename));
std::cout << " Copy Constructor / assignment / ==\n";
// test copy constructor / assignment:
OcTree* treeCopy = new OcTree(tree);
EXPECT_TRUE(tree == *treeCopy);
EXPECT_TRUE(treeCopy->writeBinary(filenameBtCopyOut));
// change a tree property, trees must be different afterwards
treeCopy->setResolution(tree.getResolution()*2.0);
EXPECT_FALSE(tree == *treeCopy);
treeCopy->setResolution(tree.getResolution());
EXPECT_TRUE(tree == *treeCopy);
// flip one value, trees must be different afterwards:
point3d pt(0.5, 0.5, 0.5);
OcTreeNode* node = treeCopy->search(pt);
if (node && treeCopy->isNodeOccupied(node))
treeCopy->updateNode(pt, false);
else
treeCopy->updateNode(pt, true);
EXPECT_FALSE(tree == *treeCopy);
delete treeCopy;
std::cout << " Swap\n";
// test swap:
OcTree emptyT(tree.getResolution());
OcTree emptySw(emptyT);
OcTree otherSw(tree);
emptySw.swapContent(otherSw);
EXPECT_FALSE(emptyT == emptySw);
EXPECT_TRUE(emptySw == tree);
EXPECT_TRUE(otherSw == emptyT);
// write again to bt, read & compare
EXPECT_TRUE(tree.writeBinary(filenameBtOut));
OcTree readTreeBt(0.1);
EXPECT_TRUE(readTreeBt.readBinary(filenameBtOut));
EXPECT_TRUE(tree == readTreeBt);
std::cout <<" Write to .ot / read through AbstractOcTree\n";
// now write to .ot, read & compare
EXPECT_TRUE(tree.write(filenameOt));
AbstractOcTree* readTreeAbstract = AbstractOcTree::read(filenameOt);
EXPECT_TRUE(readTreeAbstract);
OcTree* readTreeOt = dynamic_cast<OcTree*>(readTreeAbstract);
EXPECT_TRUE(readTreeOt);
EXPECT_TRUE(tree == *readTreeOt);
// sanity test for "==": flip one node, compare again
point3d coord(0.1f, 0.1f, 0.1f);
node = readTreeOt->search(coord);
if (node && readTreeOt->isNodeOccupied(node))
readTreeOt->updateNode(coord, false);
//.........这里部分代码省略.........
示例4: main
//.........这里部分代码省略.........
/**
* bounding box tests
*/
//tree->expand();
// test complete tree (should be equal to no bbx)
OcTreeKey bbxMinKey, bbxMaxKey;
double temp_x,temp_y,temp_z;
tree->getMetricMin(temp_x,temp_y,temp_z);
octomap::point3d bbxMin(temp_x,temp_y,temp_z);
tree->getMetricMax(temp_x,temp_y,temp_z);
octomap::point3d bbxMax(temp_x,temp_y,temp_z);
EXPECT_TRUE(tree->coordToKeyChecked(bbxMin, bbxMinKey));
EXPECT_TRUE(tree->coordToKeyChecked(bbxMax, bbxMaxKey));
OcTree::leaf_bbx_iterator it_bbx = tree->begin_leafs_bbx(bbxMinKey,bbxMaxKey);
EXPECT_TRUE(it_bbx == tree->begin_leafs_bbx(bbxMinKey,bbxMaxKey));
OcTree::leaf_bbx_iterator end_bbx = tree->end_leafs_bbx();
EXPECT_TRUE(end_bbx == tree->end_leafs_bbx());
OcTree::leaf_iterator it = tree->begin_leafs();
EXPECT_TRUE(it == tree->begin_leafs());
OcTree::leaf_iterator end = tree->end_leafs();
EXPECT_TRUE(end == tree->end_leafs());
for( ; it!= end && it_bbx != end_bbx; ++it, ++it_bbx){
EXPECT_TRUE(it == it_bbx);
}
EXPECT_TRUE(it == end && it_bbx == end_bbx);
// now test an actual bounding box:
tree->expand(); // (currently only works properly for expanded tree (no multires)
bbxMin = point3d(-1, -1, - 1);
bbxMax = point3d(3, 2, 1);
EXPECT_TRUE(tree->coordToKeyChecked(bbxMin, bbxMinKey));
EXPECT_TRUE(tree->coordToKeyChecked(bbxMax, bbxMaxKey));
typedef unordered_ns::unordered_map<OcTreeKey, double, OcTreeKey::KeyHash> KeyVolumeMap;
KeyVolumeMap bbxVoxels;
count = 0;
for(OcTree::leaf_bbx_iterator it = tree->begin_leafs_bbx(bbxMinKey,bbxMaxKey), end=tree->end_leafs_bbx();
it!= end; ++it)
{
count++;
OcTreeKey currentKey = it.getKey();
// leaf is actually a leaf:
EXPECT_FALSE(it->hasChildren());
// leaf exists in tree:
OcTreeNode* node = tree->search(currentKey);
EXPECT_TRUE(node);
EXPECT_EQ(node, &(*it));
// all leafs are actually in the bbx:
for (unsigned i = 0; i < 3; ++i){
// if (!(currentKey[i] >= bbxMinKey[i] && currentKey[i] <= bbxMaxKey[i])){
// std::cout << "Key failed: " << i << " " << currentKey[i] << " "<< bbxMinKey[i] << " "<< bbxMaxKey[i]
// << "size: "<< it.getSize()<< std::endl;
// }
EXPECT_TRUE(currentKey[i] >= bbxMinKey[i] && currentKey[i] <= bbxMaxKey[i]);
}
bbxVoxels.insert(std::pair<OcTreeKey,double>(currentKey, it.getSize()));
}
EXPECT_EQ(bbxVoxels.size(), count);
std::cout << "Bounding box traversed ("<< count << " leaf nodes)\n\n";
// compare with manual BBX check on all leafs:
for(OcTree::leaf_iterator it = tree->begin(), end=tree->end(); it!= end; ++it) {
OcTreeKey key = it.getKey();
if ( key[0] >= bbxMinKey[0] && key[0] <= bbxMaxKey[0]
&& key[1] >= bbxMinKey[1] && key[1] <= bbxMaxKey[1]
&& key[2] >= bbxMinKey[2] && key[2] <= bbxMaxKey[2])
{
KeyVolumeMap::iterator bbxIt = bbxVoxels.find(key);
EXPECT_FALSE(bbxIt == bbxVoxels.end());
EXPECT_TRUE(key == bbxIt->first);
EXPECT_EQ(it.getSize(), bbxIt->second);
}
}
// test tree with one node:
OcTree simpleTree(0.01);
simpleTree.updateNode(point3d(10, 10, 10), 5.0f);
for(OcTree::leaf_iterator it = simpleTree.begin_leafs(maxDepth), end=simpleTree.end_leafs(); it!= end; ++it) {
std::cout << it.getDepth() << " " << " "<<it.getCoordinate()<< std::endl;
}
std::cout << "Tests successful\n";
return 0;
}
示例5: mexFunction
void mexFunction(int nlhs, mxArray* plhs[], int nrhs, const mxArray* prhs[]) {
// Usage:
// Constructors/Destructor:
// octree = octomapWrapper(resolution); // constructor: new tree with
// specified resolution
// octree = octomapWrapper(filename); // constructor: load from file
// octomapWrapper(octree); // destructor
//
// Queries:
// results = octomapWrapper(octree, 1, pts) // search
// leaf_nodes = octomapWrapper(octree, 2) // getLeafNodes
//
// Update tree:
// octomapWrapper(octree, 11, pts, occupied) // updateNote(pts, occupied).
// pts is 3-by-n, occupied is 1-by-n logical
//
// General operations:
// octomapWrapper(octree, 21, filename) // save to file
OcTree* tree = NULL;
if (nrhs == 1) {
if (mxIsNumeric(prhs[0])) { // constructor w/ resolution
if (nlhs > 0) {
double resolution = mxGetScalar(prhs[0]);
// mexPrintf("Creating octree w/ resolution %f\n", resolution);
tree = new OcTree(resolution);
plhs[0] = createDrakeMexPointer((void*)tree, "OcTree");
}
} else if (mxIsChar(prhs[0])) {
if (nlhs > 0) {
char* filename = mxArrayToString(prhs[0]);
// mexPrintf("Loading octree from %s\n", filename);
tree = new OcTree(filename);
plhs[0] = createDrakeMexPointer((void*)tree, "OcTree");
mxFree(filename);
}
} else { // destructor. note: assumes prhs[0] is a DrakeMexPointer (todo:
// could check)
// mexPrintf("Deleting octree\n");
destroyDrakeMexPointer<OcTree*>(prhs[0]);
}
return;
}
tree = (OcTree*)getDrakeMexPointer(prhs[0]);
int COMMAND = (int)mxGetScalar(prhs[1]);
switch (COMMAND) {
case 1: // search
{
mexPrintf("octree search\n");
if (mxGetM(prhs[2]) != 3)
mexErrMsgTxt("octomapWrapper: pts must be 3-by-n");
int n = mxGetN(prhs[2]);
double* pts = mxGetPrSafe(prhs[2]);
if (nlhs > 0) {
plhs[0] = mxCreateDoubleMatrix(1, n, mxREAL);
double* presults = mxGetPrSafe(plhs[0]);
for (int i = 0; i < n; i++) {
OcTreeNode* result =
tree->search(pts[3 * i], pts[3 * i + 1], pts[3 * i + 2]);
if (result == NULL)
presults[i] = -1.0;
else
presults[i] = result->getOccupancy();
}
}
} break;
case 2: // get leaf nodes
{
// mexPrintf("octree get leaf nodes\n");
int N = tree->getNumLeafNodes();
plhs[0] = mxCreateDoubleMatrix(3, N, mxREAL);
double* leaf_xyz = mxGetPrSafe(plhs[0]);
double* leaf_value = NULL, * leaf_size = NULL;
if (nlhs > 1) { // return value
plhs[1] = mxCreateDoubleMatrix(1, N, mxREAL);
leaf_value = mxGetPrSafe(plhs[1]);
}
if (nlhs > 2) { // return size
plhs[2] = mxCreateDoubleMatrix(1, N, mxREAL);
leaf_size = mxGetPrSafe(plhs[2]);
}
for (OcTree::leaf_iterator leaf = tree->begin_leafs(),
end = tree->end_leafs();
leaf != end; ++leaf) {
leaf_xyz[0] = leaf.getX();
leaf_xyz[1] = leaf.getY();
leaf_xyz[2] = leaf.getZ();
leaf_xyz += 3;
if (leaf_value) *leaf_value++ = leaf->getValue();
if (leaf_size) *leaf_size++ = leaf.getSize();
}
} break;
case 11: // add occupied pts
{
// mexPrintf("octree updateNode\n");
//.........这里部分代码省略.........
示例6: main
int main(int argc, char** argv) {
// default values:
double res = 0.1;
if (argc < 2)
printUsage(argv[0]);
string graphFilename = std::string(argv[1]);
double maxrange = -1;
int max_scan_no = -1;
int skip_scan_eval = 5;
int arg = 1;
while (++arg < argc) {
if (! strcmp(argv[arg], "-i"))
graphFilename = std::string(argv[++arg]);
else if (! strcmp(argv[arg], "-res"))
res = atof(argv[++arg]);
else if (! strcmp(argv[arg], "-m"))
maxrange = atof(argv[++arg]);
else if (! strcmp(argv[arg], "-n"))
max_scan_no = atoi(argv[++arg]);
else {
printUsage(argv[0]);
}
}
cout << "\nReading Graph file\n===========================\n";
ScanGraph* graph = new ScanGraph();
if (!graph->readBinary(graphFilename))
exit(2);
size_t num_points_in_graph = 0;
if (max_scan_no > 0) {
num_points_in_graph = graph->getNumPoints(max_scan_no-1);
cout << "\n Data points in graph up to scan " << max_scan_no << ": " << num_points_in_graph << endl;
}
else {
num_points_in_graph = graph->getNumPoints();
cout << "\n Data points in graph: " << num_points_in_graph << endl;
}
cout << "\nCreating tree\n===========================\n";
OcTree* tree = new OcTree(res);
size_t numScans = graph->size();
unsigned int currentScan = 1;
for (ScanGraph::iterator scan_it = graph->begin(); scan_it != graph->end(); scan_it++) {
if (currentScan % skip_scan_eval != 0){
if (max_scan_no > 0) cout << "("<<currentScan << "/" << max_scan_no << ") " << flush;
else cout << "("<<currentScan << "/" << numScans << ") " << flush;
tree->insertPointCloud(**scan_it, maxrange);
} else
cout << "(SKIP) " << flush;
if ((max_scan_no > 0) && (currentScan == (unsigned int) max_scan_no))
break;
currentScan++;
}
tree->expand();
cout << "\nEvaluating scans\n===========================\n";
currentScan = 1;
size_t num_points = 0;
size_t num_voxels_correct = 0;
size_t num_voxels_wrong = 0;
size_t num_voxels_unknown = 0;
for (ScanGraph::iterator scan_it = graph->begin(); scan_it != graph->end(); scan_it++) {
if (currentScan % skip_scan_eval == 0){
if (max_scan_no > 0) cout << "("<<currentScan << "/" << max_scan_no << ") " << flush;
else cout << "("<<currentScan << "/" << numScans << ") " << flush;
pose6d frame_origin = (*scan_it)->pose;
point3d sensor_origin = frame_origin.inv().transform((*scan_it)->pose.trans());
// transform pointcloud:
Pointcloud scan (*(*scan_it)->scan);
scan.transform(frame_origin);
point3d origin = frame_origin.transform(sensor_origin);
KeySet free_cells, occupied_cells;
tree->computeUpdate(scan, origin, free_cells, occupied_cells, maxrange);
num_points += scan.size();
// count free cells
for (KeySet::iterator it = free_cells.begin(); it != free_cells.end(); ++it) {
OcTreeNode* n = tree->search(*it);
if (n){
if (tree->isNodeOccupied(n))
num_voxels_wrong++;
//.........这里部分代码省略.........
示例7: main
int main(int argc, char** argv) {
cout << endl;
cout << "generating example map" << endl;
OcTree tree (0.1); // create empty tree with resolution 0.1
// insert some measurements of occupied cells
for (int x=-20; x<20; x++) {
for (int y=-20; y<20; y++) {
for (int z=-20; z<20; z++) {
point3d endpoint ((float) x*0.05f, (float) y*0.05f, (float) z*0.05f);
tree.updateNode(endpoint, true); // integrate 'occupied' measurement
}
}
}
// insert some measurements of free cells
for (int x=-30; x<30; x++) {
for (int y=-30; y<30; y++) {
for (int z=-30; z<30; z++) {
point3d endpoint ((float) x*0.02f-1.0f, (float) y*0.02f-1.0f, (float) z*0.02f-1.0f);
tree.updateNode(endpoint, false); // integrate 'free' measurement
}
}
}
cout << endl;
cout << "performing some queries around the desired voxel:" << endl;
point3d query;
OcTreeNode* result = NULL;
for(float z = -0.6; z < -0.21; z += 0.1){
for(float y = -0.6; y < -0.21; y += 0.1){
for(float x = -0.6; x < -0.21; x += 0.1){
query = point3d(x, y, z);
result = tree.search(query);
print_query_info(query, result);
}
}
}
query = point3d(-0.5, -0.4, -0.4);
result = tree.search(query);
vector<point3d> normals;
if (tree.getNormals(query, normals)){
cout << endl;
string s_norm = (normals.size() > 1) ? " normals " : " normal ";
cout << "MC algorithm gives " << normals.size() << s_norm << "in voxel at " << query << endl;
for(unsigned i = 0; i < normals.size(); ++i)
cout << "\t" << normals[i].x() << "; " << normals[i].y() << "; " << normals[i].z() << endl;
} else{
cout << "query point unknown (no normals)\n";
}
}