Logo ROOT   6.12/07
Reference Guide
TGraphEdge.cxx
Go to the documentation of this file.
1 // @(#)root/hist:$Id$
2 // Author: Olivier Couet 13/07/09
3 
4 /*************************************************************************
5  * Copyright (C) 1995-2000, Rene Brun and Fons Rademakers. *
6  * All rights reserved. *
7  * *
8  * For the licensing terms see $ROOTSYS/LICENSE. *
9  * For the list of contributors see $ROOTSYS/README/CREDITS. *
10  *************************************************************************/
11 
12 #include "TGraph.h"
13 #include "TArrow.h"
14 #include "TPolyLine.h"
15 #include "TGraphEdge.h"
16 #include "TGraphNode.h"
17 
18 #include <gvc.h>
19 
21 
22 /** \class TGraphEdge
23 \ingroup gviz
24 
25 An edge object connecting two nodes which can be added in a
26 TGraphStruct.
27 */
28 
29 ////////////////////////////////////////////////////////////////////////////////
30 /// Graph Edge default constructor.
31 
33 {
34  fNode1 = 0;
35  fNode2 = 0;
36  fGVEdge = 0;
37  fX = 0;
38  fY = 0;
39  fN = 0;
40  fArrX = 0;
41  fArrY = 0;
42 }
43 
44 ////////////////////////////////////////////////////////////////////////////////
45 /// Graph Edge normal constructor.
46 
48  :TObject(), TAttLine()
49 {
50  fNode1 = n1;
51  fNode2 = n2;
52  fGVEdge = 0;
53  fX = 0;
54  fY = 0;
55  fN = 0;
56  fArrX = 0;
57  fArrY = 0;
58 }
59 
60 ////////////////////////////////////////////////////////////////////////////////
61 /// Graph Edge default destructor.
62 
64 {
65  if (fNode1) delete fNode1;
66  if (fNode2) delete fNode2;
67  if (fX) { delete [] fX; fX = 0; }
68  if (fY) { delete [] fY; fY = 0; }
69  if (fN) { delete [] fN; fN = 0; }
70 }
71 
72 ////////////////////////////////////////////////////////////////////////////////
73 /// Create the GraphViz edge into the GraphViz data structure gv.
74 
75 void TGraphEdge::CreateGVEdge(GVizAgraph_t *gv)
76 {
77  if (gv) {
78  Agnode_t *n1 = (Agnode_t*)fNode1->GetGVNode();
79  Agnode_t *n2 = (Agnode_t*)fNode2->GetGVNode();
80 #ifdef WITH_CGRAPH
81  fGVEdge = (GVizAgedge_t*)agedge((Agraph_t *)gv, n1, n2, NULL, 1);
82 #else
83  fGVEdge = (GVizAgedge_t*)agedge((Agraph_t *)gv, n1, n2);
84 #endif
85  } else {
86  Error("CreateGVEdge","Invalid graphviz graph");
87  }
88 }
89 
90 ////////////////////////////////////////////////////////////////////////////////
91 /// Compute distance from point px,py to an edge.
92 
94 {
95  Int_t i,n,a,dist=999;
96 
97  TPolyLine *polyline;
98  a = 0;
99 
100  for (i=1; i<=fN[0]; i++) {
101  n = fN[i];
102  polyline = new TPolyLine(n, &fX[a], &fY[a], "L");
103  dist = polyline->DistancetoPrimitive(px, py);
104  a = a+n;
105  }
106 
107  return dist;
108 }
109 
110 ////////////////////////////////////////////////////////////////////////////////
111 /// Execute action corresponding to one event.
112 
114 {
115  Int_t i,n,a;
116 
117  TPolyLine *polyline;
118  a = 0;
119 
120  for (i=1; i<=fN[0]; i++) {
121  n = fN[i];
122  polyline = new TPolyLine(n, &fX[a], &fY[a], "L");
123  polyline->ExecuteEvent(event, px, py);
124  a = a+n;
125  }
126 }
127 
128 ////////////////////////////////////////////////////////////////////////////////
129 /// Layout this edge in the GraphViz space. This is done after gvLayout
130 /// has been performed.
131 
133 {
134  bezier bz;
135  Int_t i,j;
136 
137  if (fX) { delete [] fX; fX = 0; }
138  if (fY) { delete [] fY; fY = 0; }
139  if (fN) { delete [] fN; fN = 0; }
140 
141  Int_t np = ED_spl((Agedge_t*)fGVEdge)->size;
142  fN = new Int_t[np+1];
143  fN[0] = np;
144  Int_t nb = 0;
145 
146  // Compute the total size of the splines arrays
147  for (i=0; i<np; i++) {
148  bz = ED_spl((Agedge_t*)fGVEdge)->list[i];
149  fN[i+1] = bz.size;
150  nb = nb+fN[i+1];
151  }
152 
153  // Create the vectors holding all the splines' points.
154  fX = new Double_t[nb];
155  fY = new Double_t[nb];
156 
157  // Fill the vectors with the splines' points.
158  Int_t k=0;
159  for (i=0; i<np; i++) {
160  bz = ED_spl((Agedge_t*)fGVEdge)->list[i];
161  fArrX = bz.ep.x;
162  fArrY = bz.ep.y;
163  for (j=0; j<fN[i+1]; j++) {
164  fX[k] = bz.list[j].x;
165  fY[k] = bz.list[j].y;
166  k++;
167  }
168  }
169 }
170 
171 ////////////////////////////////////////////////////////////////////////////////
172 /// Paint this edge with its current attributes.
173 
175 {
176  Int_t i,n,a;
177 
178  TArrow arrow;
179  TGraph graph;
180 
181  graph.SetLineColor(GetLineColor());
182  graph.SetLineStyle(GetLineStyle());
183  graph.SetLineWidth(GetLineWidth());
184  arrow.SetAngle(38);
185  arrow.SetFillColor(GetLineColor());
186  arrow.SetLineColor(GetLineColor());
187 
188  a = 0;
189 
190  for (i=1; i<=fN[0]; i++) {
191 
192  // Draw the edge body
193  n = fN[i];
194  graph.PaintGraph(n, &fX[a], &fY[a], "L");
195 
196  // Draw the edge arrow
197  arrow.PaintArrow(fX[a+n-1], fY[a+n-1], fArrX, fArrY, 0.03, "|>");
198 
199  a = a+n;
200  }
201 }
202 
203 ////////////////////////////////////////////////////////////////////////////////
204 /// Save primitive as a C++ statement(s) on output stream out
205 
206 void TGraphEdge::SavePrimitive(std::ostream &, Option_t *)
207 {
208 }
209 
210 ////////////////////////////////////////////////////////////////////////////////
211 /// Save attributes as a C++ statement(s) on output stream out
212 /// called by TGraphStruct::SavePrimitive.
213 
214 void TGraphEdge::SaveAttributes(std::ostream &out, const char* name)
215 {
216  SaveLineAttributes(out,name,1,1,1);
217 }
218 
219 ////////////////////////////////////////////////////////////////////////////////
220 
221 void TGraphEdge::Streamer(TBuffer &/*b*/)
222 {
223 }
virtual void SetLineWidth(Width_t lwidth)
Set the line width.
Definition: TAttLine.h:43
double dist(Rotation3D const &r1, Rotation3D const &r2)
Definition: 3DDistances.cxx:48
Int_t * fN
number of edge points (GV) fN[0] = number of splines fN[1...n] = number of points in each spline ...
Definition: TGraphEdge.h:35
GVizAgedge_t * fGVEdge
Graphviz edge.
Definition: TGraphEdge.h:32
void PaintGraph(Int_t npoints, const Double_t *x, const Double_t *y, Option_t *chopt)
Draw the (x,y) as a graph.
Definition: TGraph.cxx:1968
const char Option_t
Definition: RtypesCore.h:62
Buffer base class used for serializing objects.
Definition: TBuffer.h:40
int Int_t
Definition: RtypesCore.h:41
virtual Width_t GetLineWidth() const
Return the line width.
Definition: TAttLine.h:35
virtual Style_t GetLineStyle() const
Return the line style.
Definition: TAttLine.h:34
An edge object connecting two nodes which can be added in a TGraphStruct.
Definition: TGraphEdge.h:25
TArrow * arrow
virtual void SaveLineAttributes(std::ostream &out, const char *name, Int_t coldef=1, Int_t stydef=1, Int_t widdef=1)
Save line attributes as C++ statement(s) on output stream out.
Definition: TAttLine.cxx:260
virtual void ExecuteEvent(Int_t event, Int_t px, Int_t py)
Execute action corresponding to one event.
Definition: TGraphEdge.cxx:113
virtual void ExecuteEvent(Int_t event, Int_t px, Int_t py)
Execute action corresponding to one event.
Definition: TPolyLine.cxx:261
void Layout()
Layout this edge in the GraphViz space.
Definition: TGraphEdge.cxx:132
virtual void Paint(Option_t *option="")
Paint this edge with its current attributes.
Definition: TGraphEdge.cxx:174
Double_t * fX
X edge points (GV)
Definition: TGraphEdge.h:33
virtual void SetLineColor(Color_t lcolor)
Set the line color.
Definition: TAttLine.h:40
virtual void SetFillColor(Color_t fcolor)
Set the fill area color.
Definition: TAttFill.h:37
auto * a
Definition: textangle.C:12
virtual Int_t DistancetoPrimitive(Int_t px, Int_t py)
Compute distance from point px,py to an edge.
Definition: TGraphEdge.cxx:93
virtual void PaintArrow(Double_t x1, Double_t y1, Double_t x2, Double_t y2, Float_t arrowsize=0.05, Option_t *option=">")
Draw this arrow.
Definition: TArrow.cxx:173
virtual void Error(const char *method, const char *msgfmt,...) const
Issue error message.
Definition: TObject.cxx:880
Double_t fArrX
Arrow X position.
Definition: TGraphEdge.h:38
Definition: graph.py:1
TGraphEdge()
Graph Edge default constructor.
Definition: TGraphEdge.cxx:32
virtual Color_t GetLineColor() const
Return the line color.
Definition: TAttLine.h:33
TGraphNode * fNode2
Second node.
Definition: TGraphEdge.h:31
Double_t * fY
X edge points (GV)
Definition: TGraphEdge.h:34
#define ClassImp(name)
Definition: Rtypes.h:359
double Double_t
Definition: RtypesCore.h:55
A graph node object which can be added in a TGraphStruct.
Definition: TGraphNode.h:27
virtual Int_t DistancetoPrimitive(Int_t px, Int_t py)
Returns closest distance in pixels from point (px, py) to a polyline.
Definition: TPolyLine.cxx:198
GVizAgnode_t * GetGVNode()
Definition: TGraphNode.h:50
virtual void SetLineStyle(Style_t lstyle)
Set the line style.
Definition: TAttLine.h:42
Mother of all ROOT objects.
Definition: TObject.h:37
Double_t fArrY
Arrow Y position.
Definition: TGraphEdge.h:39
void CreateGVEdge(GVizAgraph_t *gv)
Create the GraphViz edge into the GraphViz data structure gv.
Definition: TGraphEdge.cxx:75
A Graph is a graphics object made of two arrays X and Y with npoints each.
Definition: TGraph.h:41
Defined by an array on N points in a 2-D space.
Definition: TPolyLine.h:23
void SaveAttributes(std::ostream &, const char *)
Save attributes as a C++ statement(s) on output stream out called by TGraphStruct::SavePrimitive.
Definition: TGraphEdge.cxx:214
virtual void SavePrimitive(std::ostream &, Option_t *)
Save primitive as a C++ statement(s) on output stream out.
Definition: TGraphEdge.cxx:206
Draw all kinds of Arrows.
Definition: TArrow.h:29
virtual ~TGraphEdge()
Graph Edge default destructor.
Definition: TGraphEdge.cxx:63
const Int_t n
Definition: legend1.C:16
Line Attributes class.
Definition: TAttLine.h:18
char name[80]
Definition: TGX11.cxx:109
virtual void SetAngle(Float_t angle=60)
Definition: TArrow.h:58
TGraphNode * fNode1
First node.
Definition: TGraphEdge.h:30