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

Go to the SVN repository for this file.

1 /* $Id: cross_aln_render.cpp 27503 2013-02-26 18:16:55Z 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: Vlad Lebedev
27  *
28  */
29 
30 #include <ncbi_pch.hpp>
31 #include "cross_aln_render.hpp"
33 
34 #include <gui/opengl/glutils.hpp>
35 #include <math.h>
36 
37 
39 
40 
41 
43 
45 {
46  m_DS = NULL;
47  m_MinZoomX = log(1.0f / kMaxPixelsBase); // Enougth to fit seq. letters
48 
50  m_RP_Q.EnableZoom(true, false);
51  m_RP_Q.SetAdjustToLimits(true, false);
53 
54  m_CP.EnableZoom(false, false);
55  //m_CP.EnableOffset();
56 
58  m_RP_S.EnableZoom(true, false);
59  m_RP_S.SetAdjustToLimits(true, false);
61 
63 
66 }
67 
69 {
70 }
71 
72 
73 
75 {
76  if (!m_DS) return;
77 
78  CBioseq_Handle hndl1 = m_DS->GetQueryHandle();
79  CBioseq_Handle hndl2 = m_DS->GetSubjectHandle();
80 
81  if ( !hndl1 ) {
82  NCBI_THROW(CException, eUnknown, "The query sequence can't be resolved!");
83  }
84 
85  if ( !hndl2 ) {
86  NCBI_THROW(CException, eUnknown, "The subject sequence can't be resolved!");
87  }
88 
91 
94 }
95 
96 
98 {
99  m_DS = ds;
100 
102  x_SetupViewPorts(rc);
103 }
104 
105 
107 {
108  TVPUnit total = rc.Top();
109  TVPUnit ruler_height = m_RulerPanel_Q.GetVPRect().Height();
110  TVPUnit cross_height = total - ruler_height * 2;
111 
112  m_RP_Q.SetViewport( TVPRect(rc.Left(), total - ruler_height,
113  rc.Right() - 1, total) );
114  total -= ruler_height;
115 
116  m_CP.SetViewport( TVPRect(rc.Left(), total - cross_height, rc.Right(), total) );
117  total -= cross_height;
118 
119  m_RP_S.SetViewport( TVPRect(rc.Left(), total - ruler_height,
120  rc.Right() - 1, total) );
121 
124 }
125 
126 
127 
129 {
130  TSeqRange rQ = m_DS->GetQueryHitsRange();
131  TSeqRange rS = m_DS->GetSubjectHitsRange();
132 
133  // 3% offset on each side of each sequence
134  TModelUnit pQ = m_RP_Q.GetViewport().Width() * 3.0 / 100.0;
135  TModelUnit pS = m_RP_S.GetViewport().Width() * 3.0 / 100.0;
136 
137 
138  TModelRect rc2( max(TModelUnit(0.0), rQ.GetFrom()-pQ), 0, min(m_SeqLength_Q + TModelUnit(1.0),
139  rQ.GetTo() + TModelUnit(1) + pQ), m_RP_Q.GetViewport().Height());
140  TModelRect rc3( max(TModelUnit(0.0), rS.GetFrom()-pS), TModelUnit(0), min(m_SeqLength_S+TModelUnit(1.0),
141  rS.GetTo() + TModelUnit(1) + pS), m_RP_S.GetViewport().Height());
142 
143  TModelRect rcc(TModelUnit(0), TModelUnit(100), TModelUnit(1), TModelUnit(0));
144 
147 
149  m_RP_Q.SetVisibleRect (rc2);
150 
152  m_CP.SetVisibleRect (rcc);
153 
155  m_RP_S.SetVisibleRect (rc3);
156 
158 }
159 
160 
162 {
164 }
165 
166 
168 {
170 }
171 
172 
173 void CCrossAlnRenderer::SetObjectSelection(const vector<const CSeq_align*> sel_aligns)
174 {
175  m_CrossPanel.SetObjectSelection(sel_aligns);
176 }
177 
178 
180 {
181  if ( !m_DS ) {
182  return;
183  }
184 
185  // draw all panels
186  m_RulerPanel_Q.Render(m_RP_Q); // Query
187  m_CrossPanel.Render(m_CP); // Cross Panel
188  m_RulerPanel_S.Render(m_RP_S); // Subject
189 
191 }
192 
193 
194 
196 {
197  x_SetupViewPorts(rc);
198 }
199 
200 
202 {
204 }
205 
206 
208 {
209  m_CrossPanel.ColorByScore(score_id);
210 }
211 
212 
214 {
215  return m_CrossPanel.GetScoreId();
216 }
217 
218 
220 {
221  return m_CrossPanel.HitTest(m_CP, x, y, true);
222 }
223 
224 
225 
227 {
228  return m_CrossPanel.HitTest(m_CP, x, y);
229 }
230 
231 
232 void CCrossAlnRenderer::GetTooltip(int x, int y, string* title)
233 {
234  *title = "";
235 }
236 
237 
238 
240 {
241  TModelUnit scale_x = log(m_RP_Q.GetScaleX());
242  return (float)(1.0f - (scale_x - m_MinZoomX) / (m_MaxZoomX_Q - m_MinZoomX));
243 }
244 
245 
247 {
249  * (1.0f - value);
250 
251  m_RP_Q.SetScale(exp(scale), m_RP_Q.GetScaleY(),
253 
255 }
256 
257 
259 {
260  TModelUnit scale_x = log(m_RP_S.GetScaleX());
261  return (float)(1.0f - (scale_x - m_MinZoomX) / (m_MaxZoomX_S - m_MinZoomX));
262 }
263 
264 
266 {
268  * (1.0f - value);
269 
270  m_RP_S.SetScale(exp(scale), m_RP_S.GetScaleY(),
272 
274 }
275 
276 
277 
279 {
282 }
283 
284 
286  const TModelPoint& point)
287 {
288  if(scale_x > m_RP_Q.GetMinScaleX()) {
289  TModelPoint ref_p(point.X(), m_RP_Q.GetVisibleRect().Top());
290 
291  m_RP_Q.SetScaleRefPoint(scale_x, 1, ref_p); // -1
293  }
294 }
295 
296 
297 
299  const TModelPoint& point)
300 {
301  if(scale_x > m_RP_S.GetMinScaleX()) {
302  TModelPoint ref_p(point.X(), m_RP_S.GetVisibleRect().Top());
303 
304  m_RP_S.SetScaleRefPoint(scale_x, 1, ref_p); // -1
306  }
307 }
308 
309 
311  const TModelPoint& point)
312 {
313 }
314 
315 
317 {
318  // calculate model space limits
321 
324 
325  // our accuracy is within 5%
326  TModelUnit s5l = sMl / 100.0f * 5.0f;
327  TModelUnit s5r = sMr / 100.0f * 5.0f;
328 
329  TModelUnit q5l = qMl / 100.0f * 5.0f;
330  TModelUnit q5r = qMr / 100.0f * 5.0f;
331 
332  // calculate scale limits
333  TModelUnit qSx = m_RP_Q.GetScaleX();
334  TModelUnit sSx = m_RP_S.GetScaleX();
335 
336  // scale limits for subject sequence
337  TModelUnit s5s = sSx / 100.0f * 5.0f;
338  TModelUnit minAVs = sSx - s5s;
339  TModelUnit maxAVs = sSx + s5s;
340 
341  // scale limits for query sequence
342  TModelUnit q5s = qSx / 100.0f * 5.0f;
343  TModelUnit minAVq = qSx - q5s;
344  TModelUnit maxAVq = qSx + q5s;
345 
346  // our new zoom factor
347  m_RP_S.SetZoomFactor(1.05f);
348  m_RP_Q.SetZoomFactor(1.05f);
349 
350  // initially, zoom all the way
351  ZoomOnRange_Q(rc.Left(), rc.Right());
352  ZoomOnRange_S(rc.Bottom(), rc.Top());
353 
354  // "slowly" zoom out until the scales are correct or until nowhere to zoom
355  do {
360 
361  TModelUnit qSx = m_RP_Q.GetScaleX();
362  TModelUnit sSx = m_RP_S.GetScaleX();
363 
364  // check limits first, and then the scales
365  if (sVl <= sMl + s5l || qVl <= qMl + q5l ||
366  sVr >= sMr - s5r || qVr >= qMr - q5r ||
367  (qSx >= minAVq && qSx <= maxAVq) ||
368  (sSx >= minAVs && sSx <= maxAVs) ) {
369  break;
370  } else {
373  }
374  } while (true);
375 
377 }
378 
379 
381 {
383  rc.SetHorz(from, to);
384  m_RP_Q.ZoomRect(rc);
385 
386  // Now add five pixels offset on each side
387  m_RP_Q.OpenOrtho();
389  m_RP_Q.Close();
390 
391  rc.SetHorz(from - pQ, to + pQ);
392  m_RP_Q.ZoomRect(rc);
393 
395 }
396 
397 
399 {
401  rc.SetHorz(from, to);
402  m_RP_S.ZoomRect(rc);
403 
404  // Now add five pixels offset on each side
405  m_RP_S.OpenOrtho();
407  m_RP_S.Close();
408 
409  rc.SetHorz(from - pS, to + pS);
410  m_RP_S.ZoomRect(rc);
411 
413 }
414 
415 
416 
417 // Query
419 {
422 }
423 
424 
426 {
429 }
430 
431 
433 {
434  SetZoomX_Q(0.0f);
435 }
436 
438 {
439  SetZoomX_Q(1.0f);
440 }
441 
442 
443 // Subject
445 {
448 }
449 
450 
452 {
455 }
456 
457 
459 {
460  SetZoomX_S(0.0f);
461 }
462 
463 
465 {
466  SetZoomX_S(1.0f);
467 }
468 
469 
471 {
472  return m_CP;
473 }
474 
476 {
477  return m_CP;
478 }
479 
480 
482 {
483  return m_RP_Q;
484 }
485 
486 
488 {
489  return m_RP_S;
490 }
491 
492 
494 {
495  m_RP_Q.Scroll(dxQ, 0.0f);
496  m_RP_S.Scroll(dxS, 0.0f);
497 
499 }
500 
501 
CBioseq_Handle –.
void SetViewport(const TVPRect &R)
Definition: glpane.cpp:95
T Left() const
Definition: glrect.hpp:81
void SetObjectSelection(const vector< const CSeq_align * > sel_aligns)
CConstRef< objects::CObject_id > GetScoreId() const
void SetColor(EColorType type, const CRgbaColor &color)
Definition: ruler.cpp:131
void Scroll(TModelUnit dxQ, TModelUnit dxS)
void SetScaleRef_S(TModelUnit m_x, TModelUnit m_y, const TModelPoint &point)
void SetVisibleRect(const TModelRect &R)
Definition: glpane.cpp:112
TModelUnit GetScaleX(void) const
Definition: glpane.cpp:117
CIRef< ICrossAlnDataSource > m_DS
GLdouble TModelUnit
Definition: gltypes.hpp:48
void ZoomOutCenter(int options=fZoomXY)
Definition: glpane.cpp:342
void SetDataSource(ICrossAlnDataSource *ds)
TModelRect & GetVisibleRect(void)
Definition: glpane.hpp:357
void SetMinScaleX(TModelUnit scale)
Definition: glpane.hpp:442
void SetScale(TModelUnit scale_x, TModelUnit scale_y, TModelPoint p_center)
Definition: glpane.cpp:360
void ZoomRect(const TModelRect &r)
Definition: glpane.cpp:347
void ColorByScore(CConstRef< CObject_id > score_id)
void SetHorizontal(bool b_horz, ELabelPlacement place=eDefault, ELabelAlign aln=eAln_Center)
Definition: ruler.cpp:90
void SetScaleRef_Q(TModelUnit m_x, TModelUnit m_y, const TModelPoint &point)
void x_SetupViewPorts(const TVPRect &rc)
CCrossPanelIR m_CrossPanel
T X() const
Definition: glpoint.hpp:59
void SetLimits(TVPRect rcm1, TModelRect rcv1, TVPRect rcm2, TModelRect rcv2)
int TVPUnit
Definition: gltypes.hpp:47
void SetZoomFactor(TModelUnit factor=2.0)
Definition: glpane.hpp:473
TModelUnit GetScaleY(void) const
Definition: glpane.cpp:122
virtual TVPRect GetVPRect() const
Definition: ruler.cpp:293
class CGlPane
Definition: glpane.hpp:61
void SetZoomX_S(float value)
void ZoomOnRange_Q(TModelUnit from, TModelUnit to)
#define NULL
Definition: ncbistd.hpp:225
void SetDataSource(const TVPRect &rc, ICrossAlnDataSource *ds)
vector< CConstRef< CObject > > TConstObjects
Definition: objects.hpp:64
void GetObjectSelection(TConstObjects &objs) const
TVPRect & GetViewport(void)
Definition: glpane.hpp:332
T Width() const
Definition: glrect.hpp:86
TModelRect HitTest(CGlPane &pane, int x, int y, bool select=false)
void Close(void)
Definition: glpane.cpp:177
#define END_NCBI_SCOPE
End previously defined NCBI scope.
Definition: ncbistl.hpp:101
const TVPUnit kMaxPixelsBase
void SquareOnRect(TModelRect rc)
void SetScaleRefPoint(TModelUnit scale_x, TModelUnit scale_y, TModelPoint p_ref)
Definition: glpane.cpp:381
void SetAdjustToLimits(bool adjust_x, bool adjust_y)
Definition: glpane.hpp:389
double f(double x_, const double &y_)
Definition: njn_root.hpp:188
void SetAutoRange()
SetAutoRange() activates automatic mode; in this mode ruler's range is equal to the provided model li...
Definition: ruler.cpp:169
CGlRect< TVPUnit > TVPRect
Definition: gltypes.hpp:53
TModelRect SelectHitTest(int x, int y)
void SetZoomX_Q(float value)
CGlPoint< T > CenterPoint() const
Definition: glrect.hpp:94
void Scroll(TModelUnit dx, TModelUnit dy)
Definition: glpane.cpp:601
void ColorByScore(CConstRef< objects::CObject_id > score_id)
void SetHorz(T left, T right)
Definition: glrect.hpp:117
static bool CheckGlError()
Check if there are any OpenGL errors.
Definition: glutils.cpp:161
void GetTooltip(int x, int y, string *title)
void ZoomOnRange_S(TModelUnit from, TModelUnit to)
void SetViewport(const TVPRect &rc)
T Bottom() const
Definition: glrect.hpp:82
void ZoomInCenter(int options=fZoomXY)
Definition: glpane.cpp:337
virtual void Render(CGlPane &pane)
Definition: ruler.cpp:458
T max(T x_, T y_)
void SetObjectSelection(const vector< const objects::CSeq_align * > sel_aligns)
position_type GetTo(void) const
Definition: range.hpp:142
TModelRect HitTest(int x, int y)
char value[7]
Definition: config.c:428
T min(T x_, T y_)
void ColorBySegments()
position_type GetFrom(void) const
Definition: range.hpp:134
void ResetObjectSelection()
TSeqPos GetBioseqLength(void) const
void SetScaleRef_C(TModelUnit m_x, TModelUnit m_y, const TModelPoint &point)
T Height() const
Definition: glrect.hpp:90
IHitMatrixDataSource - abstract Data Source for Hit Matrix Widget.
TModelUnit UnProjectWidth(TVPUnit vp_w) const
Definition: glpane.cpp:754
T Top() const
Definition: glrect.hpp:84
void EnableOffset(bool b_en=true)
Offset is used as a workaround for OpenGL precision problems emerging when size of visible range is s...
Definition: glpane.hpp:405
virtual void Render(CGlPane &pane)
void GetObjectSelection(TConstObjects &objs) const
#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:547
T Right() const
Definition: glrect.hpp:83
float GetZoomX_Q(void) const
CConstRef< CObject_id > GetScoreId() const
class CRgbaColor provides a simple abstraction for managing colors.
Definition: rgba_color.hpp:57
#define BEGIN_NCBI_SCOPE
Define ncbi namespace.
Definition: ncbistl.hpp:98
void SetModelLimitsRect(const TModelRect &R)
Definition: glpane.hpp:342
float GetZoomX_S(void) const
bool OpenOrtho()
Definition: glpane.hpp:427
TModelRect & GetModelLimitsRect(void)
Definition: glpane.hpp:347
TModelUnit GetMinScaleX(void) const
Definition: glpane.hpp:452
void EnableZoom(bool en_x, bool en_y)
Definition: glpane.hpp:462
Modified on Sat Dec 16 14:07:53 2017 by modify_doxy.py rev. 546573