Strip comments and inline ids onto h*
This commit is contained in:
parent
1997a7846d
commit
0f5f617adb
362 changed files with 2519 additions and 6694 deletions
36
59-04.html
36
59-04.html
|
|
@ -10,16 +10,9 @@
|
|||
<meta name="vspubdate" content="07/01/97" />
|
||||
<meta name="vscategory" content="Web and Software Development: Game Development,Web and Software Development: Graphics and Multimedia Development" />
|
||||
|
||||
<title>Michael Abrash's Graphics Programming Black Book Special Edition: The Idea of BSP Trees</title><!-- HEADER -->
|
||||
<!-- Empty Reference Subhead -->
|
||||
<!--ISBN=1576101746//-->
|
||||
<!--TITLE=Michael Abrash's Graphics Programming Black Book Special Edition//-->
|
||||
<!--AUTHOR=Michael Abrash//-->
|
||||
<!--PUBLISHER=The Coriolis Group, Inc.//-->
|
||||
<title>Michael Abrash's Graphics Programming Black Book Special Edition: The Idea of BSP Trees</title>
|
||||
<meta name="chapter" content="59" />
|
||||
<meta name="pages" content="1107-1110" />
|
||||
<!--UNASSIGNED1//-->
|
||||
<!--UNASSIGNED2//-->
|
||||
</head>
|
||||
|
||||
<body>
|
||||
|
|
@ -37,7 +30,7 @@
|
|||
|
||||
<p><br /></p>
|
||||
|
||||
<h3><a id="Heading8"></a>Inorder Walks of BSP Trees</h3>
|
||||
<h3 id="Heading8">Inorder Walks of BSP Trees</h3>
|
||||
|
||||
<p>It was implementing BSP trees that got me to thinking about inorder tree traversal. In inorder traversal, the left subtree of each node gets visited first, then the node, and then the right subtree. You apply this sequence recursively to each node and its children until the entire tree has been visited, as shown in Figure 59.9. Walking a BSP tree is basically an inorder tree walk; the only difference is that with a BSP tree a decision is made before each descent as to which subtree to visit first, rather than simply visiting whatever’s pointed to by the left-subtree pointer. Conceptually, however, an inorder walk is what’s used to traverse a BSP tree; from now on I’ll discuss normal inorder walking, with the understanding that the same principles apply to BSP trees.</p>
|
||||
|
||||
|
|
@ -45,11 +38,10 @@
|
|||
|
||||
<p>First, I ask for an implementation of a function <b>WalkTree()</b> that visits each node in a passed-in tree in inorder sequence. Each candidate unhesitatingly writes something like the perfectly good code in Listings 59.2 and 59.3 shown next.</p>
|
||||
|
||||
<p><a id="Fig9"><!-- </A><A HREF="javascript:displayWindow('images/59-09.jpg',112,194 )"> --><img src="images/59-09.jpg" /><br />
|
||||
<!-- </A>
|
||||
<BR><A HREF="javascript:displayWindow('images/59-09.jpg',112,194)"> --><b>Figure 59.9</b></a> <i>An inorder walk of a BSP tree.</i></p>
|
||||
<p><a id="Fig9"><img src="images/59-09.jpg" /><br />
|
||||
<b>Figure 59.9</b></a> <i>An inorder walk of a BSP tree.</i></p>
|
||||
|
||||
<p><b>Listing 59.2 L59_2.C</b></p><!-- CODE //-->
|
||||
<p><b>Listing 59.2 L59_2.C</b></p>
|
||||
<pre>
|
||||
// Function to inorder walk a tree, using code recursion.
|
||||
// Tested with 32-bit Visual C++ 1.10.
|
||||
|
|
@ -75,9 +67,9 @@ void WalkTree(NODE *pNode)
|
|||
}
|
||||
}
|
||||
}
|
||||
</pre><!-- END CODE //-->
|
||||
</pre>
|
||||
|
||||
<p><b>Listing 59.3 L59_3.H</b></p><!-- CODE SNIP //-->
|
||||
<p><b>Listing 59.3 L59_3.H</b></p>
|
||||
<pre>
|
||||
// Header file TREE.H for tree-walking code.
|
||||
typedef struct _NODE {
|
||||
|
|
@ -85,7 +77,7 @@ struct _NODE *pLeftChild;
|
|||
struct _NODE *pRightChild;
|
||||
} NODE;
|
||||
|
||||
</pre><!-- END CODE SNIP //-->
|
||||
</pre>
|
||||
|
||||
<p>Then I ask if they have any idea how to make the code faster; some don’t, but most point out that function calls are pretty expensive. Either way, I then ask them to rewrite the function without code recursion.</p>
|
||||
|
||||
|
|
@ -95,11 +87,11 @@ struct _NODE *pRightChild;
|
|||
|
||||
<p>And yet, a data-recursive inorder walk implementation has exactly the same flowchart and <i>exactly</i> the same functionality as the code-recursive version they’ve already written. They already have a fully functional model to follow, with all the problems solved, but they can’t make the connection between that model and the code they’re trying to implement. Why is this?</p>
|
||||
|
||||
<h4 align="left"><a id="Heading9"></a>Know It <i>Cold</i></h4>
|
||||
<h4 align="left" id="Heading9">Know It <i>Cold</i></h4>
|
||||
|
||||
<p>The problem is that these people don’t understand inorder walking through and through. They understand the concepts of visiting left and right subtrees, and they have a general picture of how traversal moves about the tree, but they do not understand exactly what the code-recursive version does. If they really comprehended everything that happens in each iteration of <b>WalkTree()</b>—how each call saves the state, and what that implies for the order in which operations are performed—they would simply and without fuss implement code like that in Listing 59.4, working with the code-recursive version as a model.</p>
|
||||
|
||||
<p><b>Listing 59.4 L59_4.C</b></p><!-- CODE //-->
|
||||
<p><b>Listing 59.4 L59_4.C</b></p>
|
||||
<pre>
|
||||
// Function to inorder walk a tree, using data recursion.
|
||||
// No stack overflow testing is performed.
|
||||
|
|
@ -171,7 +163,7 @@ void WalkTree(NODE *pNode)
|
|||
}
|
||||
}
|
||||
|
||||
</pre><!-- END CODE //-->
|
||||
</pre>
|
||||
|
||||
<p><br /></p>
|
||||
|
||||
|
|
@ -190,10 +182,6 @@ void WalkTree(NODE *pNode)
|
|||
|
||||
<div align="center">
|
||||
Graphics Programming Black Book © 2001 Michael Abrash
|
||||
</div><!-- all of the reference materials (books) have the footer and subfoot reveresed -->
|
||||
<!-- reference_subfoot = footer -->
|
||||
<!-- reference_footer = subfoot -->
|
||||
<!-- BEGIN SUB FOOTER -->
|
||||
<!-- END FOOTER -->
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
||||
|
|
|
|||
Loading…
Reference in a new issue