本文整理汇总了C++中QuadTree::begin方法的典型用法代码示例。如果您正苦于以下问题:C++ QuadTree::begin方法的具体用法?C++ QuadTree::begin怎么用?C++ QuadTree::begin使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类QuadTree
的用法示例。
在下文中一共展示了QuadTree::begin方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: draw_it
void draw_it(const world::Line& line)
{
glPushMatrix();
glRotatef(40, 1, 0, 0);
glTranslatef(-300, 0, -300);
::glDisable(GL_DEPTH_TEST);
glColor3f(0, 1, 0);
glBegin(GL_TRIANGLES);
world::tri_iterator c, e = qt.end();
for (c = qt.begin(); c != e; ++c) {
glVertex3fv(c->a.get());
glVertex3fv(c->b.get());
glVertex3fv(c->c.get());
}
glEnd();
glColor3f(0, 0, 1);
glBegin(GL_TRIANGLES);
for (c = qt.find(line); c != e; ++c) {
glVertex3fv(c->a.get());
glVertex3fv(c->b.get());
glVertex3fv(c->c.get());
}
glEnd();
::glEnable(GL_DEPTH_TEST);
glColor3f(1,1,1);
glBegin(GL_LINES);
glVertex3fv(line.p1.get());
glVertex3fv(line.p2.get());
glEnd();
glPopMatrix();
glColor3f(1,1,1);
}
示例2: simple_test
//.........这里部分代码省略.........
// check for an element that exists
QuadTree<int,char>::iterator itr = simple.find(4,7);
assert (itr != simple.end());
assert (itr.getLabel() == 'H');
assert ((*itr).x == 4);
assert ((*itr).y == 7);
// check for a couple elements that aren't in the tree
itr = simple.find(14,14);
assert (itr == simple.end());
itr = simple.find(15,18);
assert (itr == simple.end());
// another visualization of the tree structure
// note: this is a pre-order traversal of the data (print the node, then recurse on each child)
std::cout << "\na 'sideways' printing of the tree structure with 9 nodes:" << std::endl;
simple.print_sideways();
}
}
// --------------------------------------------------------
// a few more checks
std::cout << "\nafter inserting all 21 data points:" << std::endl;
simple.plot(40,20);
assert (simple.size() == 21);
assert (simple.height() == 2);
QuadTree<int,char>::iterator itr = simple.find(15,18);
assert (itr != simple.end());
assert (itr.getLabel() == 'Q');
assert ((*itr).x == 15);
assert ((*itr).y == 18);
// plot the data without the lines
std::cout << "\na plot of the point data without the lines:" << std::endl;
simple.plot(40,20,false);
// --------------------------------------------------------
// another visualization of the tree structure
// note: this is a pre-order traversal of the data (print the node, then recurse on each child)
std::cout << "\na 'sideways' printing of the finished tree structure:" << std::endl;
simple.print_sideways();
// --------------------------------------------------------
// use the primary (depth-first) iterator to traverse the tree structure
// note: this is a pre-order traversal, the same order as the 'sideways' tree above!!
std::cout << "\nA depth-first traversal of the simple tree (should match sideways output!):" << std::endl;
QuadTree<int,char>::iterator df_itr = simple.begin();
char expected_depth_first_order[21] =
{ 'A','B','F','G','H','I','C','J','K','L','M','D','N','O','P','Q','E','R','S','T','U' };
for (int i = 0; i < 21; i++) {
assert (df_itr != simple.end());
// get the depth/level of this element in the tree (distance from root node!)
int depth = df_itr.getDepth();
// use the depth to indent the output (& match the sideways tree output above)
std::cout << std::string(depth*2,' ') << df_itr.getLabel() << " " << *df_itr << std::endl;
// check that the output is in the correct order!
assert (df_itr.getLabel() == expected_depth_first_order[i]);
// test the pre-increment operator++
++df_itr;
}
// after 21 increments, we better be at the end!
assert (df_itr == simple.end());
// --------------------------------------------------------
// using the breadth-first iterator to traverse the data by level
std::cout << "\nA breadth first traversal of the simple tree:";
QuadTree<int,char>::bf_iterator bf_itr = simple.bf_begin();
char expected_breadth_first_order[21] =
{ 'A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U' };
int level = -1;
for (int i = 0; i < 21; i++) {
assert (bf_itr != simple.bf_end());
// get the depth/level of this element in the tree (distance from root node!)
int depth = bf_itr.getDepth();
if (level != depth) {
level = depth;
// starting a new level!
std::cout << std::endl << " level " << level << ":";
}
// print out this data point
std::cout << " " << bf_itr.getLabel() << *bf_itr;
// check that the output is in the correct order!
assert (bf_itr.getLabel() == expected_breadth_first_order[i]);
// test the pre-increment operator++
++bf_itr;
}
// after 21 increments, we better be at the end!
assert (bf_itr == simple.bf_end());
std::cout << std::endl;
// --------------------------------------------------------
std::cout << "\nFinished with simple_test().\n" << std::endl;
// Note: the destructor for the QuadTree object 'simple' is
// automatically called when we leave this function and the variable
// goes out of scope!
}