ATLAS Offline Software
IVP12DViewTransformation.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2021 CERN for the benefit of the ATLAS collaboration
3 */
4 
6 // //
7 // Implementation of class IVP12DViewTransformation //
8 // //
9 // Author: Thomas Kittelmann <Thomas.Kittelmann@cern.ch> //
10 // //
11 // Initial version: April 2007 //
12 // //
14 
16 
17 #include <QAbstractGraphicsShapeItem>
18 #include <QGraphicsLineItem>
19 #include <QGraphicsPixmapItem>
20 #include <QPainter>
21 
22 #include <iostream>//fixme
23 #include <cassert>
24 
25 //____________________________________________________________________
26 void IVP12DViewTransformation::transformPath(const QPainterPath &source, QPainterPath &target) const
27 {
28  assert(target.elementCount()==0);
29  target.addPath(source);
30  for (int i=0; i<target.elementCount(); ++i) {//Fixme:iterator better and possible?
31  const QPainterPath::Element &e = target.elementAt(i);
32  QPointF newpos = transform(QPointF(e.x,e.y));
33  target.setElementPositionAt(i,newpos.x(),newpos.y());
34  }
35 }
36 
37 //____________________________________________________________________
38 void IVP12DViewTransformation::inverseTransformPath(const QPainterPath &source, QPainterPath &target) const
39 {
40  assert(target.elementCount()==0);
41  target.addPath(source);
42  for (int i=0; i<target.elementCount(); ++i) {//Fixme:iterator better and possible?
43  const QPainterPath::Element &e = target.elementAt(i);
44  QPointF newpos = inverseTransform(QPointF(e.x,e.y));
45  target.setElementPositionAt(i,newpos.x(),newpos.y());
46  }
47 }
48 
49 //____________________________________________________________________
50 QRectF IVP12DViewTransformation::inverseTransform(const QRectF &source) const
51 {
52  QPointF p1 = inverseTransform(source.bottomLeft());
53  QPointF p2 = inverseTransform(source.bottomRight());
54  QPointF p3 = inverseTransform(source.topLeft());
55  QPointF p4 = inverseTransform(source.topRight());
56 
57  QPointF topleft(qMin(qMin(qMin(p1.x(),p2.x()),p3.x()),p4.x()),
58  qMin(qMin(qMin(p1.y(),p2.y()),p3.y()),p4.y()));
59  QPointF bottomright(qMax(qMax(qMax(p1.x(),p2.x()),p3.x()),p4.x()),
60  qMax(qMax(qMax(p1.y(),p2.y()),p3.y()),p4.y()));
61  return QRectF(topleft,QSizeF(bottomright.x()-topleft.x(),bottomright.y()-topleft.y()));
62 }
63 
64 //____________________________________________________________________
65 QRectF IVP12DViewTransformation::transform(const QRectF &source) const
66 {
67  QPointF p1 = transform(source.bottomLeft());
68  QPointF p2 = transform(source.bottomRight());
69  QPointF p3 = transform(source.topLeft());
70  QPointF p4 = transform(source.topRight());
71 
72  QPointF topleft(qMin(qMin(qMin(p1.x(),p2.x()),p3.x()),p4.x()),
73  qMin(qMin(qMin(p1.y(),p2.y()),p3.y()),p4.y()));
74  QPointF bottomright(qMax(qMax(qMax(p1.x(),p2.x()),p3.x()),p4.x()),
75  qMax(qMax(qMax(p1.y(),p2.y()),p3.y()),p4.y()));
76  return QRectF(topleft,QSizeF(bottomright.x()-topleft.x(),bottomright.y()-topleft.y()));
77 }
78 
79 //____________________________________________________________________
80 void IVP12DViewTransformation::paintItem(QPainter *painter, const QGraphicsItem*item) const
81 {
82  //We are redoing most of the stuff as found in the various paint
83  //methods in qgraphicsitem.cpp. We dont care about
84  //QStyleOptionGraphicsItem's since they only seem to involve drawing
85  //rectangles around selected items (which we do another way anyway).
86 
87  const QAbstractGraphicsShapeItem * shapeitem = qgraphicsitem_cast<const QAbstractGraphicsShapeItem*>(item);
88  const QGraphicsLineItem * lineitem(0);
89  if (!shapeitem)
90  lineitem = qgraphicsitem_cast<const QGraphicsLineItem*>(item);
91 
92  if (shapeitem||lineitem) {
93  std::cout<<"IVP12DViewTransformation::paintItem: INFO: Draws QAbstractGraphicsShapeItem/QGraphicsLineItem"<<std::endl;
94  if (shapeitem) {
95  const QGraphicsSimpleTextItem * simpletextitem = qgraphicsitem_cast<const QGraphicsSimpleTextItem*>(/*shape*/item);
96  if (simpletextitem) {
97  std::cout<<"IVP12DViewTransformation::paintItem: WARNING - does not presently draw QGraphicsSimpleTextItems"<<std::endl;
98  return;
99  }
100  }
101  QPainterPath path;
102  if (shapeitem) {
103  painter->setPen(shapeitem->pen());
104  painter->setBrush(shapeitem->brush());
105  transformPath(shapeitem->shape(), path);
106  }
107  else if (lineitem) {
108  painter->setPen(lineitem->pen());
109  transformPath(lineitem->shape(), path);
110  }
111  painter->drawPath(path);//Fixme:transform
112  // QPainterPath QGraphicsPolygonItem::shape();
113  // QPainterPath QGraphicsPathItem::shape();
114  // QPainterPath QGraphicsRectItem::shape();
115  // QPainterPath QGraphicsEllipseItem::shape();//good enough
116  //Fixme: Most standard QT shape items have slightly more efficient methods that might be useful...
117  return;
118  }
119  const QGraphicsItemGroup * groupitem = qgraphicsitem_cast<const QGraphicsItemGroup*>(item);
120  if (groupitem) {
121  std::cout<<"IVP12DViewTransformation::paintItem: INFO: drawing QGraphicsGroupItem"<<std::endl;
122  return;
123  }
124  const QGraphicsPixmapItem * pixmapitem = qgraphicsitem_cast<const QGraphicsPixmapItem*>(item);
125  if (pixmapitem) {
126  std::cout<<"IVP12DViewTransformation::paintItem: WARNING - does not presently draw QGraphicsPixmapItems"<<std::endl;
127  //Pixmap: construct matrix transformation from the corners, and hope that the transformation is linear enough that it works.
128  //Perhaps test the assumption on a few other points within the pixmap.
129  return;
130  }
131 
132  std::cout<<"IVP12DViewTransformation::paintItem: Can not paint graphics item in transformed view."
133  <<" Please only use items derived from either QAbstractGraphicsShapeItem, QGraphicsLineItem, QGraphicsGroupItem or QGraphicsPixmapItem."<<std::endl;
134  return;
135 
136 
137 }
IVP12DViewTransformation::transformPath
virtual void transformPath(const QPainterPath &source, QPainterPath &target) const
Definition: IVP12DViewTransformation.cxx:26
athena.path
path
python interpreter configuration --------------------------------------—
Definition: athena.py:126
IVP12DViewTransformation::transform
virtual QPointF transform(const QPointF &source) const =0
IVP12DViewTransformation::inverseTransformPath
virtual void inverseTransformPath(const QPainterPath &source, QPainterPath &target) const
Definition: IVP12DViewTransformation.cxx:38
ParticleJetTools::p3
Amg::Vector3D p3(const xAOD::TruthVertex *p)
Definition: ParticleJetLabelCommon.cxx:55
IVP12DViewTransformation::inverseTransform
virtual QPointF inverseTransform(const QPointF &source) const =0
lumiFormat.i
int i
Definition: lumiFormat.py:92
IVP12DViewTransformation::paintItem
void paintItem(QPainter *, const QGraphicsItem *) const
Definition: IVP12DViewTransformation.cxx:80
item
Definition: ItemListSvc.h:43
IVP12DViewTransformation.h
DiTauMassTools::MaxHistStrategyV2::e
e
Definition: PhysicsAnalysis/TauID/DiTauMassTools/DiTauMassTools/HelperFunctions.h:26
COOLRates.target
target
Definition: COOLRates.py:1106