2
// File: CladogramPlot.cpp
3
// Created by: Julien Dutheil
4
// Created on: Tue Oct 9 17:22 2006
8
Copyright or © or Copr. CNRS, (November 16, 2004)
10
This software is a computer program whose purpose is to provide
11
graphic components to develop bioinformatics applications.
13
This software is governed by the CeCILL license under French law and
14
abiding by the rules of distribution of free software. You can use,
15
modify and/ or redistribute the software under the terms of the CeCILL
16
license as circulated by CEA, CNRS and INRIA at the following URL
17
"http://www.cecill.info".
19
As a counterpart to the access to the source code and rights to copy,
20
modify and redistribute granted by the license, users are provided only
21
with a limited warranty and the software's author, the holder of the
22
economic rights, and the successive licensors have only limited
25
In this respect, the user's attention is drawn to the risks associated
26
with loading, using, modifying and/or developing or reproducing the
27
software by the user in light of its specific status of free software,
28
that may mean that it is complicated to manipulate, and that also
29
therefore means that it is reserved for developers and experienced
30
professionals having in-depth computer knowledge. Users are therefore
31
encouraged to load and test the software's suitability as regards their
32
requirements in conditions enabling the security of their systems and/or
33
data to be ensured and, more generally, to use and operate it in the
34
same conditions as regards security.
36
The fact that you are presently reading this means that you have had
37
knowledge of the CeCILL license and that you accept its terms.
40
#include "CladogramPlot.h"
41
#include "../TreeTemplateTools.h"
49
CladogramDrawBranchEvent::CladogramDrawBranchEvent(const TreeDrawing* source, GraphicDevice* gd, const INode* node, double length, const Cursor& cursor, short orientation) :
50
DrawIBranchEvent(source, gd, node, cursor), orientation_(), length_(length)
52
orientation_ = (orientation == AbstractDendrogramPlot::ORIENTATION_LEFT_TO_RIGHT ? -1 : 1);
55
Cursor CladogramDrawBranchEvent::getBranchCursor(double position) const
58
if (getINode()->hasDistanceToFather())
60
offset = orientation_ * length_ * position;
62
return getCursor().getTranslation(offset, 0);
65
void CladogramPlot::setTree(const Tree* tree)
67
AbstractDendrogramPlot::setTree(tree);
69
totalDepth_ = TreeTemplateTools::getDepth(*getTree_()->getRootNode());
72
void CladogramPlot::drawDendrogram_(GraphicDevice& gDevice) const throw (Exception)
76
DrawTreeEvent treeEvent(this, &gDevice);
77
fireBeforeTreeEvent_(treeEvent);
78
unsigned int* tipCounter = new unsigned int(0);
80
recursivePlot_(gDevice, *const_cast<INode*>(getTree_()->getRootNode()),
81
getHorizontalOrientation() == ORIENTATION_LEFT_TO_RIGHT ? 0 : getWidth() * getXUnit(),
83
getHorizontalOrientation() == ORIENTATION_LEFT_TO_RIGHT ? 1. : -1.,
84
getVerticalOrientation() == ORIENTATION_TOP_TO_BOTTOM ? 1. : -1.,
86
fireAfterTreeEvent_(treeEvent);
90
void CladogramPlot::recursivePlot_(GraphicDevice& gDevice, INode& node, double x, double& y, double hDirection, double vDirection, unsigned int* tipCounter) const
92
double depth = static_cast<double>(TreeTemplateTools::getDepth(node));
93
double x2 = ((getHorizontalOrientation() == ORIENTATION_LEFT_TO_RIGHT ? totalDepth_ : 0) - depth) * getXUnit() * hDirection;
94
auto_ptr<Cursor> cursor;
95
auto_ptr<DrawINodeEvent> nodeEvent;
96
auto_ptr<DrawIBranchEvent> branchEvent;
97
short hpos = (getHorizontalOrientation() == ORIENTATION_LEFT_TO_RIGHT ? GraphicDevice::TEXT_HORIZONTAL_LEFT : GraphicDevice::TEXT_HORIZONTAL_RIGHT);
100
y = ((getVerticalOrientation() == ORIENTATION_TOP_TO_BOTTOM ? 0 : getHeight()) + static_cast<double>(*tipCounter) * vDirection) * getYUnit();
102
cursor.reset(new Cursor(x2, y, 0, hpos));
103
nodeEvent.reset(new DrawINodeEvent(this, &gDevice, &node, *cursor));
104
fireBeforeNodeEvent_(*nodeEvent);
106
else if (node.getInfos().isCollapsed())
108
y = ((getVerticalOrientation() == ORIENTATION_TOP_TO_BOTTOM ? 0 : getHeight()) + static_cast<double>(*tipCounter) * vDirection) * getYUnit();
110
cursor.reset(new Cursor(x2, y, 0, hpos));
111
nodeEvent.reset(new DrawINodeEvent(this, &gDevice, &node, *cursor));
112
fireBeforeNodeEvent_(*nodeEvent);
116
//Vertical line. Call the method on son nodes first:
117
double miny = 1000000; //(unsigned int)(-log(0));
119
for(unsigned int i = 0; i < node.getNumberOfSons(); i++)
122
recursivePlot_(gDevice, *node.getSon(i), x2, yson, hDirection, vDirection, tipCounter);
123
if(yson < miny) miny = yson;
124
if(yson > maxy) maxy = yson;
126
y = (maxy + miny) / 2.;
127
cursor.reset(new Cursor(x2, y, 0, hpos));
128
nodeEvent.reset(new DrawINodeEvent(this, &gDevice, &node, *cursor));
129
fireBeforeNodeEvent_(*nodeEvent);
130
gDevice.drawLine(x2, miny, x2, maxy);
132
//Actualize node infos:
133
node.getInfos().setX(x2);
134
node.getInfos().setY(y);
135
nodeEvent.reset(new DrawINodeEvent(this, &gDevice, &node, *cursor));
136
fireAfterNodeEvent_(*nodeEvent);
139
branchEvent.reset(new CladogramDrawBranchEvent(this, &gDevice, &node, x2 - x, *cursor, getHorizontalOrientation()));
140
fireBeforeBranchEvent_(*branchEvent);
141
gDevice.drawLine(x, y, x2, y);
142
fireAfterBranchEvent_(*branchEvent);