NCBI C++ ToolKit
phylo_tree.cpp
Go to the documentation of this file.

Go to the SVN repository for this file.

1 /* $Id: phylo_tree.cpp 39527 2017-10-05 15:12:08Z falkrb $
2  * ===========================================================================
3  *
4  * PUBLIC DOMAIN NOTICE
5  * National Center for Biotechnology Information
6  *
7  * This software/database is a "United States Government Work" under the
8  * terms of the United States Copyright Act. It was written as part of
9  * the author's official duties as a United States Government employee and
10  * thus cannot be copyrighted. This software/database is freely available
11  * to the public for use. The National Library of Medicine and the U.S.
12  * Government have not placed any restriction on its use or reproduction.
13  *
14  * Although all reasonable efforts have been taken to ensure the accuracy
15  * and reliability of the software and data, the NLM and the U.S.
16  * Government do not and cannot warrant the performance or results that
17  * may be obtained by using this software or data. The NLM and the U.S.
18  * Government disclaim all warranties, express or implied, including
19  * warranties of performance, merchantability or fitness for any particular
20  * purpose.
21  *
22  * Please cite the author in any work or product based on this material.
23  *
24  * ===========================================================================
25  *
26  * Authors: Bob Falk
27  *
28  * File Description:
29  *
30  */
31 
32 #include <ncbi_pch.hpp>
35 
37 
38 ///////////////////////////////////////////////////////////////////////////////
39 // CPhyloTree
40 ///////////////////////////////////////////////////////////////////////////////
41 
43  : m_CurrentNode(Null())
44 {
45  Clear();
46 }
47 
49 {
50  // Delete nodes and set root index to null
52 
53  // Do not create a new model if it doesn't exist at this point
54  // Model requires opengl so we don't want to accidently create
55  // at startup (prior to context creation)
56  if (!m_GraphicsModel.IsNull()) {
58  m_GraphicsModel->Init(this);
59  }
60 
62 }
63 
65 {
66  if (m_ColorTable.IsNull()) {
68  }
69 
70  return m_ColorTable.GetPointer();
71 }
72 
73 
75 {
76  if (m_GraphicsModel.IsNull()) {
78  m_GraphicsModel->Init(this);
79  }
80 
81  return m_GraphicsModel.GetObject();
82 }
83 
84 
86 {
87 public:
88  CNodeOrderPredNumChildren(const CPhyloTree& m, bool order)
89  : m_Tree(m), m_Order(order) {}
90 
91  bool operator()(const CPhyloTree::TTreeIdx& lhs,
92  const CPhyloTree::TTreeIdx& rhs) const {
93  if (m_Order) {
94  return m_Tree[lhs].GetValue().GetNumLeavesEx() < m_Tree[rhs].GetValue().GetNumLeavesEx();
95  }
96  else {
97  return m_Tree[lhs].GetValue().GetNumLeavesEx() > m_Tree[rhs].GetValue().GetNumLeavesEx();
98  }
99  }
100 
101 protected:
103  bool m_Order;
104 };
105 
107 {
108 public:
109  CNodeOrderPredDist(const CPhyloTree& m, bool order)
110  : m_Tree(m), m_Order(order) {}
111 
113  const CPhyloTree::TTreeIdx& rhs) const {
114  if (m_Order) {
115  return m_Tree[lhs].GetValue().GetDistance() < m_Tree[rhs].GetValue().GetDistance();
116  }
117  else {
118  return m_Tree[lhs].GetValue().GetDistance() > m_Tree[rhs].GetValue().GetDistance();
119  }
120  }
121 
122 protected:
124  bool m_Order;
125 };
126 
128 {
129 public:
131  const vector<float>& distances,
132  bool order)
133  : m_Tree(m), m_Distances(distances), m_Order(order) {}
134 
136  const CPhyloTree::TTreeIdx& rhs) const {
137 
138  if (m_Order) {
139  return m_Distances[lhs] < m_Distances[rhs];
140  }
141  else {
142  return m_Distances[lhs] > m_Distances[rhs];
143  }
144  }
145 
146 protected:
148  const vector<float>& m_Distances;
149  bool m_Order;
150 };
151 
153 {
154 public:
155  CNodeOrderPredLabel(const CPhyloTree& m, bool order)
156  : m_Tree(m), m_Order(order) {}
157 
159  const CPhyloTree::TTreeIdx& rhs) const {
160  const string &l1 = m_Tree[lhs].GetValue().GetLabel();
161  const string &l2 = m_Tree[rhs].GetValue().GetLabel();
162 
163  // Nodes with blank labels, including interior nodes, will come first.
164  if (m_Order) {
165  return l1 < l2;
166  }
167  else {
168  return l1 > l2;
169  }
170  }
171 
172 protected:
174  bool m_Order;
175 };
176 
178 {
179 public:
181  const vector<pair<string,string> >& labels,
182  bool order)
183  : m_Tree(m), m_SubtreeLabels(labels), m_Order(order) {}
184 
186  const CPhyloTree::TTreeIdx& rhs) const {
187 
188  // There are multiple ways that subtree labels can be compared. We are doing
189  // the simplest one here of just picking the node whose label range has the
190  // alphabetically smallest value.
191  if (m_Order) {
192  return m_SubtreeLabels[lhs].first < m_SubtreeLabels[rhs].first;
193  }
194  else {
195  return m_SubtreeLabels[lhs].first > m_SubtreeLabels[rhs].first;
196  }
197  }
198 
199 protected:
201  // Each pair is the lexicographical min and max from a nodes subtree labels
202  const vector<pair<string,string> >& m_SubtreeLabels;
203  bool m_Order;
204 };
205 
206 
207 
208 void CPhyloTree::Sort(TTreeIdx idx, bool order)
209 {
210  CNodeOrderPredNumChildren pred(*this, order);
211 
212  sort(m_Nodes[idx].GetChildren().begin(),
213  m_Nodes[idx].GetChildren().end(), pred);
214 }
215 
216 void CPhyloTree::SortSubtreeDist(TTreeIdx idx, const vector<float>& distances, bool order)
217 {
218  CNodeOrderPredSubtreeDist pred(*this, distances, order);
219 
220  sort(m_Nodes[idx].GetChildren().begin(),
221  m_Nodes[idx].GetChildren().end(), pred);
222 }
223 
224 void CPhyloTree::SortLabel(TTreeIdx idx, bool order)
225 {
226  CNodeOrderPredLabel pred(*this, order);
227 
228  sort(m_Nodes[idx].GetChildren().begin(),
229  m_Nodes[idx].GetChildren().end(), pred);
230 }
231 
233  const vector<pair<string,string> >& subtree_labels,
234  bool order)
235 {
236  CNodeOrderPredSubtreeLabel pred(*this, subtree_labels, order);
237 
238  sort(m_Nodes[idx].GetChildren().begin(),
239  m_Nodes[idx].GetChildren().end(), pred);
240 }
241 
243 {
244  TNodeVecType::iterator iter;
245 
246  for (iter=m_Nodes.begin(); iter!=m_Nodes.end(); ++iter) {
247  (*iter).GetValue().SetSelectedState(CPhyloNodeData::eNotSelected);
248  }
249 
250  m_Selected.clear();
252 
253  m_CurrentNode = Null();
254 
257 }
258 
259 void CPhyloTree::GetSelected(vector<TTreeIdx>& sel) const
260 {
261  sel.reserve(sel.size() + m_Selected.size());
262  std::copy(m_Selected.begin(), m_Selected.end(), back_inserter(sel));
263 }
264 
265 void CPhyloTree::GetSelectedIDs(vector<TID>& sel) const
266 {
267  sel.reserve(sel.size() + m_Selected.size());
269  sel.push_back(m_Nodes[*it].GetValue().GetId());
270  }
271 }
272 
273 void CPhyloTree::GetExplicitlySelected(vector<TTreeIdx>& esel) const
274 {
275  esel.reserve(esel.size() + m_ExplicitlySelected.size());
276  std::copy(m_ExplicitlySelected.begin(), m_ExplicitlySelected.end(), back_inserter(esel));
277 }
278 
279 void CPhyloTree::GetExplicitlySelectedAndNotCollapsed(vector<TTreeIdx>& esel) const
280 {
281  esel.reserve(m_ExplicitlySelected.size());
282 
283  for (auto iter = m_ExplicitlySelected.begin(); iter != m_ExplicitlySelected.end(); ++iter) {
284  // Check if any of the parent nodes of the current node, up to the root, are collapsed
285  // and, if so, return the collapsed node closest to the root.
286  const TNodeType& n = m_Nodes[*iter];
287  TTreeIdx parent = n.GetParent();
288  TTreeIdx ex_sel_node = *iter;
289 
290  while (parent != TNodeType::Null()) {
291  const TNodeType& p = m_Nodes[parent];
292  if (!p.Expanded())
293  ex_sel_node = parent;
294  parent = p.GetParent();
295  }
296 
297  // If a node is a parent node, check if it's a duplicate before adding it to the array.
298  // Most duplicates will be adjacent because trees indicies will almost always be
299  // in depth-first order
300  if (ex_sel_node != *iter && esel.size() > 0) {
301  if (esel[esel.size() - 1] != ex_sel_node) {
302  if (std::find(esel.begin(), esel.end(), ex_sel_node) == esel.end()) {
303  esel.push_back(ex_sel_node);
304  }
305  }
306  }
307  else {
308  esel.push_back(ex_sel_node);
309  }
310  }
311 }
312 
313 void CPhyloTree::GetExplicitlySelectedIDs(vector<TID>& esel) const
314 {
315  esel.reserve(esel.size() + m_ExplicitlySelected.size());
317  esel.push_back(m_Nodes[*it].GetValue().GetId());
318  }
319 }
320 
321 void CPhyloTree::SetExplicitlySelected(const vector<TID>& esel)
322 {
324  if (esel.size() == 0)
325  return;
326 
327  // For each ID, find its corresponding index then check if it is in
328  // the set of selected nodes. If it is, mark it as explicitly selected.
329  ITERATE(vector<TID>, it, esel) {
330  TTreeIdx idx = FindNodeById(*it);
331 
332  if (m_Selected.find(idx) != m_Selected.end())
334  }
335 }
336 
338 {
341  if (m_Nodes[*it].IsLeaf())
343  }
344 }
345 
346 void CPhyloTree::SetSelectionIDs(const vector<TID>& ids, bool sel, bool sel_children)
347 {
348  TTreeIdx idx;
349  ITERATE(vector<TID>,iter,ids) {
350  idx = FindNodeById(*iter);
351  if (Null() == idx)
352  continue;
353  SetSelection(idx, sel, sel_children);
354  }
355 }
356 
357 void CPhyloTree::SetSelection(const vector<TTreeIdx>& sel,
358  bool sel_children,
359  bool sel_parents)
360 {
361  vector<TTreeIdx>::const_iterator iter;
362 
363  for (iter=sel.begin(); iter!=sel.end(); ++iter) {
364  SetSelection(*iter, true, sel_children, sel_parents);
365  }
366 }
367 
368 vector<CPhyloTree::TTreeIdx> CPhyloTree::GetAllCollapsed() const
369 {
370  vector<TTreeIdx> collapsed_nodes;
371 
372  for (size_t i=0; i<m_Nodes.size(); ++i) {
373  if (m_Nodes[i]->GetDisplayChildren() == CPhyloNodeData::eHideChildren &&
374  !m_Nodes[i].IsUnused()) {
375  collapsed_nodes.push_back(TTreeIdx(i));
376  }
377  }
378 
379  return collapsed_nodes;
380 }
381 
383 {
384  TTreeIdx result = node_idx;
385 
386  CPhyloTree::TTreeIdx parent_idx = GetNode(node_idx).GetParent();
387  while (parent_idx != CPhyloTreeNode::Null()) {
388  if (!GetNode(parent_idx).Expanded()) {
389  result = parent_idx;
390  }
391  parent_idx = GetNode(parent_idx).GetParent();
392  }
393 
394  return result;
395 }
396 
398  CVect2<float>& ur)
399 {
402 
403  ITERATE(TTreeIdxSet, iter, m_Selected) {
404  CVect2<float> p = m_Nodes[*iter]->XY();
405  ll.X() = std::min(ll.X(), p.X());
406  ll.Y() = std::min(ll.Y(), p.Y());
407 
408  ur.X() = std::max(ur.X(), p.X());
409  ur.Y() = std::max(ur.Y(), p.Y());
410  }
411 
412  return m_Selected.size()>0;
413 }
414 
416 {
417  m_CurrentNode = node_idx;
418 }
419 
420 bool CPhyloTree::SetCurrentNode(const CVect2<float>& pt, bool labels_visible, bool rotated_labels,
421  bool unselect)
422 {
423  if (unselect)
424  m_CurrentNode = Null();
425 
426  TTreeIdx new_current_node = TestForNode(pt, labels_visible, rotated_labels);
427  if (new_current_node != Null()) {
428  m_CurrentNode = new_current_node;
429  return true;
430  }
431  return false;
432 }
433 
435 {
436  if (!HasCurrentNode())
437  NCBI_THROW(CException, eUnknown, "Attempt to get current node from tree when there is none");
438 
439  return m_Nodes[m_CurrentNode];
440 }
441 
442 void CPhyloTree::SetCurrentEdge(TTreeIdx child_idx, TTreeIdx parent_idx)
443 {
444  m_CurrentEdgeChild = child_idx;
445  m_CurrentEdgeParent = parent_idx;
446 }
447 
448 void CPhyloTree::GetCurrentEdge(TTreeIdx& child_idx, TTreeIdx& parent_idx) const
449 {
450  child_idx = m_CurrentEdgeChild;
451  parent_idx = m_CurrentEdgeParent;
452 }
453 
455 {
456  // It should never be the case that only one of these is Null
457  return (m_CurrentEdgeChild != Null() && m_CurrentEdgeParent != Null());
458 }
459 
460 CPhyloTree::TTreeIdx CPhyloTree::TestForNode(const CVect2<float>& pt, bool labels_visible, bool rotated_labels)
461 {
463 
464  idx = GetGraphicsModel().GetCollisionData().TestForNode(pt.X(), pt.Y(), labels_visible, rotated_labels);
465 
466  return idx;
467 }
468 
470 {
471  TNodeType* node = &m_Nodes[node_idx];
472  TNodeType* parent = NULL;
473  TTreeIdx parent_idx;
474 
475  while ((parent_idx=node->GetParent())!=TNodeType::Null()) {
476  parent = &m_Nodes[parent_idx];
477  if ((**parent).GetDisplayChildren()==CPhyloNodeData::eHideChildren){
478  return false;
479  }
480  node = parent;
481  }
482 
483  return true;
484 }
485 
486 bool CPhyloTree::SelectByPoint(const CVect2<float>& pt, bool sel, bool toggle,
487  bool labels_visible, bool rotated_labels)
488 {
489  TTreeIdx idx = TestForNode(pt, labels_visible, rotated_labels);
490 
491  if (idx != Null()) {
492  CPhyloTreeNode& node = m_Nodes[idx];
493 
494  // If it is not an incremental selection and we clicked on a node, clear
495  // previous selection
496  if (sel) {
497  ClearSelection();
498  }
499 
500  if (toggle)
501  SetSelection(idx, !((*node).GetSelectedState()==CPhyloNodeData::eSelected), true);
502  else
504 
505  m_CurrentNode = idx;
506 
507  return true;
508  }
509  return false;
510 }
511 
513  const CVect2<float>& ur,
514  bool toggle)
515 {
516  vector<CPhyloTree::TTreeIdx> selected;
517 
518  selected = GetGraphicsModel().GetCollisionData().SelectNodes(ll.X(), ll.Y(), ur.X(), ur.Y());
519 
520  for (size_t i=0; i<selected.size(); ++i) {
521  TNodeType& node = m_Nodes[size_t(selected[i])];
522 
523  bool sel;
524  if (toggle)
525  sel = !((*node).GetSelectedState()==CPhyloNodeData::eSelected);
526  else
527  sel = true;
528 
529  SetSelection(selected[i], sel, true);
530  }
531 
532  return (selected.size() > 0);
533 }
534 
536 {
537  m_NodesMap.clear();
539  m_NodesMap[(*it).GetValue().GetId()] = (TTreeIdx)(it-m_Nodes.begin());
540  }
541 }
542 
545  bool override_explicit)
546 {
547  CPhyloTreeNode& node = m_Nodes[idx];
548 
550  (*node).GetSelectedState() == CPhyloNodeData::eSelected) {
552  if (sel_it != m_ExplicitlySelected.end()){
553  // This allows us to not allow parent-selection/de-selection to
554  // remove selection of parent that was selected explicitly (e.g.
555  // clicked on directly or met results of a query)
556  if (!override_explicit)
557  return;
558 
559  // And we also preserve explicitly selected nodes even if the
560  // de-selection as a child node will now show the node as traced,
561  // not selected.
562  m_ExplicitlySelected.erase(sel_it);
563  }
564  sel_it = m_Selected.find(idx);
565  if (sel_it!=m_Selected.end()){
566  m_Selected.erase(sel_it);
567  }
568  }
569  else if (state == CPhyloNodeData::eSelected &&
570  (*node).GetSelectedState() != CPhyloNodeData::eSelected) {
571  m_Selected.insert(idx);
572  }
573 
574  (*node).SetSelectedState(state);
575 }
576 
578  bool sel,
579  bool sel_children,
580  bool sel_parents)
581 {
584 
585  // This function is called for nodes user clicks on or selects through a query
586  // - explicitly selected nodes so keep that set up-to-date here. Children
587  // and parent nodes of the selected set may also be selected based on
588  // sel_children/sel_parents.
589  if (!sel) {
591  if (sel_it != m_ExplicitlySelected.end()){
592  m_ExplicitlySelected.erase(sel_it);
593  }
594  }
595  else {
597  }
598 
599  CPhyloTreeNode& node = m_Nodes[idx];
600 
601  if (sel_children) {
602  x_SelectChildren(node, sel);
603  }
604 
605  if (sel_parents) {
606  x_SelectParents(node, sel, sel_children);
607  TTreeIdx common_idx = x_CommonNodeSearch(idx);
608  if (common_idx != Null())
609  x_PropagateCommonState(m_Nodes[common_idx]);
610  }
611 }
612 
614  TTreeIdx idx,
615  bool sel_children,
616  bool sel_parents) const
617 {
618 
619  const CPhyloTreeNode& node = m_Nodes[idx];
620 
621  if ((*node).GetSelectedState() == CPhyloNodeData::eSelected) {
622  sel_state.push_back(TSelStateValue(idx, CPhyloNodeData::eSelected));
623  }
624  // If a selected node is not a leaf, sometimes it is set as shared rather than selected,
625  // so see if it might be in explicitly selected set too.
626  else if (!node.IsLeaf()) {
628  if (sel_it != m_ExplicitlySelected.end()){
629  sel_state.push_back(TSelStateValue(idx, CPhyloNodeData::eSelected));
630  }
631  }
632 
633  if (sel_children) {
634  x_GetChildState(sel_state, idx);
635  }
636 
637  if (sel_parents && node.HasParent()) {
638  x_GetParentState(sel_state, node.GetParent());
639  }
640 }
641 
643  bool sel)
644 {
646  for (it=node.SubNodeBegin(); it != node.SubNodeEnd(); ++it) {
647  TNodeType& child_node = m_Nodes[*it];
650 
651  x_SelectChildren(child_node, sel);
652  }
653 }
654 
655 void CPhyloTree::x_SelectParents(CPhyloTreeNode& node, bool sel, bool children_selected)
656 {
657  if (!node.HasParent())
658  return;
659 
660  CPhyloTreeNode& parent = m_Nodes[node.GetParent()];
661 
662  bool all_selected = true;
663  bool some_selected = false;
664 
666  for (it = parent.SubNodeBegin(); it != parent.SubNodeEnd(); ++it ) {
667  TNodeType& child_node = m_Nodes[*it];
668 
669  bool sel_state = ((*child_node).GetSelectedState() == CPhyloNodeData::eSelected);
670  bool trace_state = ((*child_node).GetSelectedState() != CPhyloNodeData::eNotSelected);
671 
672  all_selected &= sel_state;
673  some_selected |= trace_state;
674  }
675  if (all_selected) {
678  }
679  else {
680  // When we don't selecte children, selecting a group of nodes can cause previously
681  // selected parents to be unselelected so we disable un-selection of parents in this case
682  x_SetSelState(node.GetParent(), some_selected ? CPhyloNodeData::eTraced :
683  CPhyloNodeData::eNotSelected, children_selected);
684  }
685 
686  x_SelectParents(parent, sel, children_selected);
687 }
688 
690 {
691  // finding common node
692  TTreeIdx common_idx = Null();
693  TTreeIdx cursor_idx = idx;
694 
695  while (cursor_idx != Null()){
696  int iMarkedNodes=0;
697  CPhyloTreeNode& cursor = m_Nodes[cursor_idx];
698 
700  for (it = cursor.SubNodeBegin(); it != cursor.SubNodeEnd(); ++it ) {
701  if (m_Nodes[*it].GetValue().GetSelectedState()!=
703  ++iMarkedNodes;
704  }
705  }
706  if (iMarkedNodes > 1) {
707  common_idx = cursor_idx;
708  }
709 
710  cursor_idx = cursor.GetParent();
711  }
712 
713  if (common_idx != Null() && !m_Nodes[common_idx].IsLeaf())
714  return common_idx;
715  return Null();
716 }
717 
719 {
720  if ((*node).GetSelectedState()==CPhyloNodeData::eTraced) {
721  (*node).SetSelectedState(CPhyloNodeData::eShared);
722 
724  for(it=node.SubNodeBegin(); it != node.SubNodeEnd(); ++it) {
726  }
727  }
728 }
729 
731  TTreeIdx idx) const
732 {
733  const CPhyloTreeNode& node = m_Nodes[idx];
734 
735  if ((*node).GetSelectedState() != CPhyloNodeData::eNotSelected) {
736  sel_state.push_back(TSelStateValue(idx, (*node).GetSelectedState()));
737 
738  if (node.HasParent())
739  x_GetParentState(sel_state, node.GetParent());
740  }
741 }
742 
744  TTreeIdx idx) const
745 {
746  const CPhyloTreeNode& node = m_Nodes[idx];
747 
749  for (it = node.SubNodeBegin(); it != node.SubNodeEnd(); ++it) {
750  const CPhyloTreeNode& n = m_Nodes[*it];
751  if ((*n).GetSelectedState() != CPhyloNodeData::eNotSelected) {
752  sel_state.push_back(TSelStateValue(*it, (*node).GetSelectedState()));
753  x_GetChildState(sel_state, *it);
754  }
755  }
756 }
757 
759 {
760  TTreeIdx parent_idx = m_Nodes[node_idx].GetParent();
761 
762  if (parent_idx != Null()) {
763  RemoveChild(parent_idx, node_idx);
764  x_ConvertUpstream(parent_idx);
765  AddChild(node_idx, parent_idx);
766 
767  // Disance values are stored in child nodes as distance of the child from
768  // the parent, so when we swap child and parent nodes, we need to move the
769  // distance from the former child to the former parent.
770  GetNode(parent_idx).GetValue().SetDistance(
771  GetNode(node_idx).GetValue().GetDistance());
772  GetNode(parent_idx).GetValue().Sync(m_FeatureDict);
773  }
774 }
775 
776 
CNodeOrderPredDist(const CPhyloTree &m, bool order)
Definition: phylo_tree.cpp:109
const CPhyloTree & m_Tree
Definition: phylo_tree.cpp:123
bool operator()(const CPhyloTree::TTreeIdx &lhs, const CPhyloTree::TTreeIdx &rhs) const
Definition: phylo_tree.cpp:112
CNodeOrderPredLabel(const CPhyloTree &m, bool order)
Definition: phylo_tree.cpp:155
bool operator()(const CPhyloTree::TTreeIdx &lhs, const CPhyloTree::TTreeIdx &rhs) const
Definition: phylo_tree.cpp:158
const CPhyloTree & m_Tree
Definition: phylo_tree.cpp:173
bool operator()(const CPhyloTree::TTreeIdx &lhs, const CPhyloTree::TTreeIdx &rhs) const
Definition: phylo_tree.cpp:91
CNodeOrderPredNumChildren(const CPhyloTree &m, bool order)
Definition: phylo_tree.cpp:88
const CPhyloTree & m_Tree
Definition: phylo_tree.cpp:102
CNodeOrderPredSubtreeDist(const CPhyloTree &m, const vector< float > &distances, bool order)
Definition: phylo_tree.cpp:130
const vector< float > & m_Distances
Definition: phylo_tree.cpp:148
const CPhyloTree & m_Tree
Definition: phylo_tree.cpp:147
bool operator()(const CPhyloTree::TTreeIdx &lhs, const CPhyloTree::TTreeIdx &rhs) const
Definition: phylo_tree.cpp:135
const vector< pair< string, string > > & m_SubtreeLabels
Definition: phylo_tree.cpp:202
const CPhyloTree & m_Tree
Definition: phylo_tree.cpp:200
bool operator()(const CPhyloTree::TTreeIdx &lhs, const CPhyloTree::TTreeIdx &rhs) const
Definition: phylo_tree.cpp:185
CNodeOrderPredSubtreeLabel(const CPhyloTree &m, const vector< pair< string, string > > &labels, bool order)
Definition: phylo_tree.cpp:180
void Sync(CBioTreeFeatureDictionary &dict)
void SetDistance(TDistance x_dist)
bool Expanded() const
Return true if node is currently not collapsed.
Tree subclass also has functions and data needed for rendering and selection.
Definition: phylo_tree.hpp:52
CRef< CTreeGraphicsModel > m_GraphicsModel
Model for rendering (updated from current tree state)
Definition: phylo_tree.hpp:382
void SetExplicitlySelected(const vector< TID > &esel)
Reset explicitly selected nodes to those currently selected nodes that are also found in the vector '...
Definition: phylo_tree.cpp:321
bool SelectByPoint(const CVect2< float > &pt, bool sel, bool toggle, bool labels_visible, bool rotated_labels=false)
Determine if the point pt is close enough to a node to select or deselect it.
Definition: phylo_tree.cpp:486
void SetSelectionIDs(const vector< TID > &ids, bool sel=true, bool sel_children=true)
Select a set of nodes - equivalent to calling SetSelection(idx, true, true, true) on each of the node...
Definition: phylo_tree.cpp:346
void SortSubtreeDist(TTreeIdx idx, const vector< float > &distances, bool order)
Sort the children of a node based on length of longest subtree.
Definition: phylo_tree.cpp:216
bool IsUnused(TTreeIdx idx) const
Return true if the given position in the array is not currently included as a node in the tree.
Definition: phylo_tree.hpp:320
TTreeIdx x_CommonNodeSearch(TTreeIdx idx)
Check recursively parents of node and set selection state to eShared if all of their children are sel...
Definition: phylo_tree.cpp:689
TTIDPhyloTreeNodeMap m_NodesMap
Definition: phylo_tree.hpp:371
TTreeIdx m_CurrentEdgeChild
Currently active edge (to allow re-rooting by edge).
Definition: phylo_tree.hpp:378
void SetLeavesExplicitlySelected()
Set the nodes used for iteration to default to the leaf nodes.
Definition: phylo_tree.cpp:337
void ClearSelection()
Sets selection state of all nodes to eNotSelected and clears m_Selected.
Definition: phylo_tree.cpp:242
void x_SelectChildren(CPhyloTreeNode &node, bool sel)
Propogate selection operation (selecte/deselect) to a nodes children.
Definition: phylo_tree.cpp:642
void GetCurrentEdge(TTreeIdx &child_idx, TTreeIdx &parent_idx) const
Definition: phylo_tree.cpp:448
TTreeIdxSet m_Selected
Definition: phylo_tree.hpp:361
void Clear()
Clear the tree nodes, graphics model and selected nodes.
Definition: phylo_tree.cpp:48
TTreeIdx m_CurrentNode
Currently active node (for operations like edit), or Null()
Definition: phylo_tree.hpp:374
void GetSelectedIDs(vector< TID > &sel) const
Returns the node ids of selected nodes.
Definition: phylo_tree.cpp:265
void x_SetSelState(TTreeIdx idx, CPhyloNodeData::TSelectedState state, bool override_explicit=true)
Set selected state of anode and add/remove it from m_Selected as needed.
Definition: phylo_tree.cpp:543
TTreeIdxSet m_ExplicitlySelected
Often when you select a node, it's children or parents may also join the selection set.
Definition: phylo_tree.hpp:367
bool GetSelectedBoundary(CVect2< float > &ll, CVect2< float > &ur)
Return bounding rectangle from lower-left to upper-right of selected nodes (eSelected) and false if n...
Definition: phylo_tree.cpp:397
void UpdateNodesMapping()
Definition: phylo_tree.cpp:535
bool IsVisible(TTreeIdx node_idx)
Determine if the node at node_idx is within a collapsed subtree or not.
Definition: phylo_tree.cpp:469
void SetCurrentNode(TTreeIdx node_idx)
Set the index of the currently active node.
Definition: phylo_tree.cpp:415
void SetSelection(TTreeIdx idx, bool sel, bool sel_children=true, bool sel_parents=true)
Select or deselect the node at the specified index and, optionally, its parents and children as well.
Definition: phylo_tree.cpp:577
CRef< CRgbaGradColorTable > m_ColorTable
Color table to store colors by index.
Definition: phylo_tree.hpp:384
vector< TSelStateValue > TSelState
Definition: phylo_tree.hpp:57
TTreeIdx TestForNode(const CVect2< float > &pt, bool labels_visible, bool rotated_labels=false)
Search nodes to find and return closest node to 'pt' that is within the max.
Definition: phylo_tree.cpp:460
void GetExplicitlySelectedAndNotCollapsed(vector< TTreeIdx > &esel) const
Returns only indices of nodes explicitly selected, but when a node is underneath a collapsed node,...
Definition: phylo_tree.cpp:279
void x_GetChildState(TSelState &sel_state, TTreeIdx idx) const
Get (and return) selection state for children of a given node.
Definition: phylo_tree.cpp:743
void x_SelectParents(CPhyloTreeNode &node, bool sel, bool children_selected=true)
Propogate selection (eTraced) to a nodes parents and if children aren't be selected,...
Definition: phylo_tree.cpp:655
TTreeIdx m_CurrentEdgeParent
Definition: phylo_tree.hpp:379
virtual void x_ConvertUpstream(TTreeIdx node_idx)
Convert parents of node_idx to be its children.
Definition: phylo_tree.cpp:758
CPhyloTree()
ctor - need to add nodes to make tree valid
Definition: phylo_tree.cpp:42
CPhyloTreeNode & GetCurrentNode()
Get reference to currently active node. Throws exception if it's Null()
Definition: phylo_tree.cpp:434
void x_GetParentState(TSelState &sel_state, TTreeIdx idx) const
Get (and return) selection state for parents of a given node.
Definition: phylo_tree.cpp:730
CRgbaGradColorTable * GetColorTable()
Definition: phylo_tree.cpp:64
bool HasCurrentNode() const
Return true if the currently active node is not Null()
Definition: phylo_tree.hpp:274
void GetExplicitlySelectedIDs(vector< TID > &esel) const
Returns only ids of nodes explicitly selected, not their parents or children, i.e.
Definition: phylo_tree.cpp:313
TTreeIdx FindNodeById(TID id) const
Return index of the node with the given id or Null().
Definition: phylo_tree.hpp:307
void GetExplicitlySelected(vector< TTreeIdx > &esel) const
Returns only indices of nodes explicitly selected, not their parents or children, i....
Definition: phylo_tree.cpp:273
void SetCurrentEdge(TTreeIdx child_idx, TTreeIdx parent_idx)
Set/Get the edge between the two specified nodes as current.
Definition: phylo_tree.cpp:442
pair< TTreeIdx, CPhyloNodeData::TSelectedState > TSelStateValue
Definition: phylo_tree.hpp:56
void GetSelected(vector< TTreeIdx > &sel) const
Returns indices of selected nodes.
Definition: phylo_tree.cpp:259
TTreeIdx GetCollapsedParentIdx(TTreeIdx node_idx) const
Return the index of the given node (node_idx) if none of its parent nodes up to the root are collapse...
Definition: phylo_tree.cpp:382
void SortLabel(TTreeIdx idx, bool order)
Sort the children of a node based on label comparison (alphabetical order)
Definition: phylo_tree.cpp:224
void GetSelState(TSelState &sel_state, TTreeIdx idx, bool sel_children=true, bool sel_parents=true) const
Given the selection of node 'idx', store the selection state (selected, traced, shared) of that node ...
Definition: phylo_tree.cpp:613
void SortLabelRange(TTreeIdx idx, const vector< pair< string, string > > &subtree_labels, bool order)
Sort the children of a node based on the alphanumeric range of their child nodes.
Definition: phylo_tree.cpp:232
bool HasCurrentEdge() const
Definition: phylo_tree.cpp:454
CBioTreeFeatureDictionary m_FeatureDict
Feature dictionary.
Definition: phylo_tree.hpp:387
void Sort(TTreeIdx idx, bool order)
Sort the children of a node based on the number of children they have.
Definition: phylo_tree.cpp:208
bool SelectByRect(const CVect2< float > &ll, const CVect2< float > &ur, bool toggle)
Select or deselect all nodes in the rectangle bounded by ll and ur.
Definition: phylo_tree.cpp:512
void x_PropagateCommonState(CPhyloTreeNode &node)
Definition: phylo_tree.cpp:718
vector< TTreeIdx > GetAllCollapsed() const
Returns indices of nodes thate are currently collapsed.
Definition: phylo_tree.cpp:368
CTreeGraphicsModel & GetGraphicsModel()
Get model for rendering.
Definition: phylo_tree.cpp:74
CRgbaGradColorTable Provides a storage for colors (to eliminate color creation overhead) and Function...
vector< size_t > SelectNodes(float x1, float y1, float x2, float y2)
Return all nodes within the region (x1,y1) - (x2,y2)
size_t TestForNode(float x, float y, bool labels_visible, bool rotated_labels=false)
Return node at position (x,y), if any.
class CTreeGraphicsModel Model for rendering tree graphics data.
void Init(CPhyloTree *t)
Allocate any default buffers etc.
CTreeCollisionModel2D & GetCollisionData()
TTreeIdx GetParent() const
Get node's parent.
Definition: tree_model.hpp:82
TNodeList_CI SubNodeEnd() const
Return const iterator to end of subnode list.
Definition: tree_model.hpp:136
TNodeList::iterator TNodeList_I
Definition: tree_model.hpp:63
TData & GetValue()
Return the value object for the node.
Definition: tree_model.hpp:159
bool HasParent() const
Check if the node has a parent.
Definition: tree_model.hpp:90
TNodeList::const_iterator TNodeList_CI
Definition: tree_model.hpp:64
bool IsLeaf() const
Report whether this is a leaf node.
Definition: tree_model.hpp:121
static TTreeIdx Null()
Static function that returns the null value.
Definition: tree_model.hpp:636
TNodeList_CI SubNodeBegin() const
Return const iterator to first subnode index.
Definition: tree_model.hpp:130
TNodeVecType m_Nodes
The list of nodes in the tree.
Definition: tree_model.hpp:318
static TTreeIdx Null()
Return the index value that represents a NULL node.
Definition: tree_model.hpp:678
TNodeType & GetNode(TTreeIdx idx)
Return a reference to the node at the given index.
Definition: tree_model.hpp:207
void Clear()
Remove all nodes (empty array) and set root index to Null.
Definition: tree_model.hpp:681
void AddChild(TTreeIdx parent_idx, TTreeIdx child_idx)
Add the node at 'child_idx' to the children 'parent_idx'.
Definition: tree_model.hpp:715
std::vector< TNodeType > TNodeVecType
Definition: tree_model.hpp:184
void RemoveChild(TTreeIdx parent_idx, TTreeIdx child_idx)
Remove the node at 'child_idx' from its parent 'parent_idx' Nothing is done if the node 'child_idx' i...
Definition: tree_model.hpp:708
void clear()
Definition: map.hpp:169
iterator_bool insert(const value_type &val)
Definition: set.hpp:149
const_iterator begin() const
Definition: set.hpp:135
void clear()
Definition: set.hpp:153
parent_type::iterator iterator
Definition: set.hpp:80
size_type size() const
Definition: set.hpp:132
const_iterator find(const key_type &key) const
Definition: set.hpp:137
void erase(iterator pos)
Definition: set.hpp:151
const_iterator end() const
Definition: set.hpp:136
#define ITERATE(Type, Var, Cont)
ITERATE macro to sequence through container elements.
Definition: ncbimisc.hpp:815
#define NULL
Definition: ncbistd.hpp:225
#define NCBI_THROW(exception_class, err_code, message)
Generic macro to throw an exception, given the exception class, error code and message string.
Definition: ncbiexpt.hpp:704
T & X()
Definition: vect2.hpp:107
T & Y()
Definition: vect2.hpp:109
virtual void ClearAll()
clear everything - vectors and vertex buffers
Definition: glmodel2d.cpp:74
const CSeq_id & GetId(const CSeq_loc &loc, CScope *scope)
If all CSeq_ids embedded in CSeq_loc refer to the same CBioseq, returns the first CSeq_id found,...
TObjectType * GetPointer(void) THROWS_NONE
Get pointer,.
Definition: ncbiobj.hpp:998
void Reset(void)
Reset reference object.
Definition: ncbiobj.hpp:773
bool IsNull(void) const THROWS_NONE
Check if pointer is null – same effect as Empty().
Definition: ncbiobj.hpp:735
TObjectType & GetObject(void)
Get object.
Definition: ncbiobj.hpp:1011
#define END_NCBI_SCOPE
End previously defined NCBI scope.
Definition: ncbistl.hpp:103
#define BEGIN_NCBI_SCOPE
Define ncbi namespace.
Definition: ncbistl.hpp:100
int i
yy_size_t n
constexpr auto sort(_Init &&init)
T max(T x_, T y_)
T min(T x_, T y_)
void copy(Njn::Matrix< S > *matrix_, const Njn::Matrix< T > &matrix0_)
Definition: njn_matrix.hpp:613
else result
Definition: token2.c:20
size_t TTreeIdx
Bi-directionaly linked N way tree allocated in a contiguous memory block.
Definition: tree_model.hpp:48
Modified on Sat Jul 13 13:38:02 2024 by modify_doxy.py rev. 669887