//------------------------------------------------------------------------------ void RectangleTreeDrawer::CalcCoordinates () { t->MakeNodeList(); maxDepth = 0; // Clear internal node depths for (int i = t->GetNumLeaves(); i < t->GetNumNodes(); i++) { (*t)[i]->SetDepth(0); } for (int i = 0; i < t->GetNumLeaves(); i++) { NodePtr p = (*t)[i]->GetAnc(); int count = 1; while (p) { if (count > p->GetDepth()) { p->SetDepth(count); if (count > maxDepth) maxDepth = count; } count++; p = p->GetAnc(); } } double l = t->GetNumLeaves(); leafGap = height / (l - 1.0); l = maxDepth + 1.0; if (rooted) nodeGap = width / l; else nodeGap = width / (l - 1.0); leafCount = 0; if (rooted) { // Allow for edge below root left += nodeGap; width -= nodeGap; } NodeIterator <Node> n (t->GetRoot()); Node *q = n.begin(); while (q) { if (q->IsLeaf ()) { CalcLeaf (q); } else { CalcInternal (q); } q = n.next(); } }
//------------------------------------------------------------------------------ // Compute node depth (i.e, height above root). Based on COMPONENT 2.0 code, // assumes count is set to 0 prior to calling code void Tree::getNodeDepth(NodePtr p) { if (p) { p->SetDepth (count); count++; getNodeDepth (p->GetChild()); count--; getNodeDepth (p->GetSibling()); } }
//------------------------------------------------------------------------------ void CircleTreeDrawer::CalcCoordinates () { t->MakeNodeList(); maxDepth = 0; // Clear internal node depths for (int i = t->GetNumLeaves(); i < t->GetNumNodes(); i++) { (*t)[i]->SetDepth(0); } for (int i = 0; i < t->GetNumLeaves(); i++) { NodePtr p = (*t)[i]->GetAnc(); int count = 1; while (p) { if (count > p->GetDepth()) { p->SetDepth(count); if (count > maxDepth) maxDepth = count; } count++; p = p->GetAnc(); } } leaf_angle = 2 * M_PI / t->GetNumLeaves(); left = top = 0.0; width = height = 400.0; leaf_radius = width / 2.0; leafCount = 0; nodeGap = leaf_radius / double(maxDepth); origin.x = 0.0; origin.y = 0.0; NodeIterator <Node> n (t->GetRoot()); Node *q = n.begin(); while (q) { if (q->IsLeaf ()) { CalcLeaf (q); } else { CalcInternal (q); } q = n.next(); } // Translate origin.x = left + (width/2.0); origin.y = top + (height/2.0); q = n.begin(); while (q) { node_coordinates[q].x += origin.x; node_coordinates[q].y += origin.y; node_backarc[q].x += origin.x; node_backarc[q].y += origin.y; q = n.next(); } }