예제 #1
0
//------------------------------------------------------------------------------
void TreeDrawer::CalcCoordinates ()
{
	double l = t->GetNumLeaves();
    leafGap = height / (l - 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();
    }

}
예제 #2
0
파일: femesh.C 프로젝트: anilkunwar/OOF2
Node *FEMesh::closestNode(const double x, const double y, const double z=0)
#endif
{
  double min=1.;   // (initial value provided to suppress compiler warnings)
  Node *node, *thenode=0;
  for(NodeIterator ni = node_iterator(); !ni.end(); ++ni) {
    node = ni.node();
    double dx = node->position()(0) - x;
    double dy = node->position()(1) - y;
#if DIM==2
    double dist = dx*dx + dy*dy;
#elif DIM==3
    double dz = node->position()(2) - z;
    double dist = dx*dx + dy*dy + dz*dz;
#endif
    if (ni.begin()) {
      min = dist;
      thenode = node;
    }
    else {
      if (dist <= min) {
	min = dist;
	thenode = node;
      }
    }
  }
  return thenode;
}
예제 #3
0
//------------------------------------------------------------------------------
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();
    }

}
예제 #4
0
//------------------------------------------------------------------------------
void TreeOrder::Order ()
{
    NodeIterator <Node> n (t->GetRoot());
    Node *q = n.begin();
    while (q)
    {
    	if (!q->IsLeaf ())
			SortDescendants (q);

        q = n.next();
    }
}
예제 #5
0
//------------------------------------------------------------------------------
void AlphaOrder::Order ()
{
    NodeIterator <Node> n (t->GetRoot());
    Node *q = n.begin();
    while (q)
    {
    	if (q->IsLeaf ())
        	labels[q] = q->GetLabel();
        q = n.next();
    }
	q = n.begin();
    while (q)
    while (q)
    {
    	if (!q->IsLeaf ())
        {
			SortDescendants (q);
            labels[q] = labels[q->GetChild()];
        }

        q = n.next();
    }
}
예제 #6
0
//------------------------------------------------------------------------------
void TreeDrawer::Draw ()
{
    NodeIterator <Node> n (t->GetRoot());
    Node *q = n.begin();
    while (q)
    {
    	if (q->IsLeaf ())
        {
        	DrawLeaf (q);
        }
        else
        {
			DrawInternal (q);
        }

        q = n.next();
    }
    if (rooted)
    {
    	DrawRoot ();
    }
}
예제 #7
0
//------------------------------------------------------------------------------
TreeDrawer::TreeDrawer (Tree *tree)
{
	t = tree;
    rooted = true;
    showInternalLabels = true;
    showLeafLabels = true;
    left = 0.0;
    top = 0.0;
    width = 400.0;
    height = 400.0;
    leafCount = 0;
    NodeIterator <Node> n (t->GetRoot());
    Node *q = n.begin();
    while (q)
    {
    	if (q->IsLeaf ())
        {
        	point p;
        	node_coordinates[q] = p;
        }
        q = n.next();
    }
}
예제 #8
0
//------------------------------------------------------------------------------
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();
    }


}
예제 #9
0
//------------------------------------------------------------------------------
void PhylogramDrawer::CalcCoordinates ()
{
	// 1. Get path lengths
	mMaxPathLength = 0.0;
	t->GetRoot()->SetPathLength (t->GetRoot()->GetEdgeLength()); // modify for rooted?


    // duh! this needs to be preorder!!!!!!!!!

    PreorderIterator <Node> n (t->GetRoot());
    Node *q = n.begin();
    while (q)
    {
       	double d = q->GetEdgeLength();
        if (d < 0.00001)
        	d = 0.0;
        if (q != t->GetRoot())
	    	q->SetPathLength (q->GetAnc()->GetPathLength() + d);
		if (q->GetPathLength() > mMaxPathLength)
			mMaxPathLength = q->GetPathLength();
        q = n.next();
    }

    // Is the tree ultrametric? (should really be a method of the tree class...)
    mUltrametric = true;
    NodeIterator <Node> u (t->GetRoot());
    q = u.begin();
    while (q && mUltrametric)
    {
        if (q->IsLeaf())
        {
            double d = q->GetPathLength() - mMaxPathLength;
            mUltrametric = (fabs(d) <= 0.0001); //remove std:: in front of fabs to comply with GCC 4.0 (added by BCO)
//            cout << mMaxPathLength << ":" << q->GetPathLength() << " " << d << endl;
        }
        q = u.next();
    }
            

    // Allow for scale bar

#if USE_VC2
	scalebar_space = Port.GetFontHeight() * 2;
#endif		

#if USE_WXWINDOWS
	scalebar_space = dc->GetCharHeight() * 2;
#endif		


#if USE_PS
	scalebar_space = font.GetSize() * 2;
#endif

	height -= scalebar_space;

 	double l = t->GetNumLeaves();
    leafGap = height / (l - 1.0);
	leafCount = 0;

    NodeIterator <Node> po (t->GetRoot());
    q = po.begin();
    while (q)
    {
    	if (q->IsLeaf ())
        {
        	CalcLeaf (q);
        }
        else
        {
			CalcInternal (q);
        }

        q = po.next();
    }

}