1. node Structure of the BST tree:
Bstnode
{
Bstnode * link; // polygon linked list
Bstnode * front;
Bstnode * back;
Vector3d polygon;
}
2. Create a BST tree:
Void bst_create (bstnode_ptr root)
{
If (root = NULL)
Return;
While (root-> link! = NULL)
{
If (root-> link before root)
{
Insertbst (root-> back, root-> link );
}
Else
{
Insertbst (root-> front, root-> link );
}
Root-> link = root-> link;
}
Bst_create (root-> front );
Bst_create (root-> back );
}
3. insert to the linked list:
Void insertbst (bstnode_ptr root, bstnode_ptr pinsert)
{
If (root = NULL)
Return;
Insertbst (root-> link, pinsert );
Root-> link = pinsert;
}
4. Traversal method:
Void bst_search (bstnode_ptr root, vector3d viewpoint)
{
If (root = NULL)
Return;
If (the viewpoint is in front of the root polygon)
{
Bst_search (root-> back, viewpoint );
Render the root polygon;
Bst_search (root-> front, viewpoint );
}
Else
{
Bst_search (root-> front, viewpoint );
Render the root polygon;
Bst_search (root-> back, viewpoint );
}
}