ROOT  6.06/09
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 Style_t GetLineStyle() const
Definition: TAttLine.h:48
virtual void SetLineWidth(Width_t lwidth)
Definition: TAttLine.h:57
double dist(Rotation3D const &r1, Rotation3D const &r2)
Definition: 3DDistances.cxx:48
Int_t * fN
Definition: TGraphEdge.h:47
GVizAgedge_t * fGVEdge
Definition: TGraphEdge.h:44
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:1916
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
TArc * a
Definition: textangle.C:12
An edge object connecting two nodes which can be added in a TGraphStruct.
Definition: TGraphEdge.h:37
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:257
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 Error(const char *method, const char *msgfmt,...) const
Issue error message.
Definition: TObject.cxx:918
virtual void Paint(Option_t *option="")
Paint this edge with its current attributes.
Definition: TGraphEdge.cxx:174
char * out
Definition: TBase64.cxx:29
Double_t * fX
Definition: TGraphEdge.h:45
virtual void SetLineColor(Color_t lcolor)
Definition: TAttLine.h:54
virtual void SetFillColor(Color_t fcolor)
Definition: TAttFill.h:50
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:172
Double_t fArrX
Definition: TGraphEdge.h:50
virtual Color_t GetLineColor() const
Definition: TAttLine.h:47
TGraphNode * fNode2
Definition: TGraphEdge.h:43
Double_t * fY
Definition: TGraphEdge.h:46
#define ClassImp(name)
Definition: Rtypes.h:279
double Double_t
Definition: RtypesCore.h:55
A graph node object which can be added in a TGraphStruct.
Definition: TGraphNode.h:43
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:66
virtual void SetLineStyle(Style_t lstyle)
Definition: TAttLine.h:56
#define name(a, b)
Definition: linkTestLib0.cpp:5
Mother of all ROOT objects.
Definition: TObject.h:58
Double_t fArrY
Definition: TGraphEdge.h:51
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:53
#define NULL
Definition: Rtypes.h:82
Defined by an array on N points in a 2-D space.
Definition: TPolyLine.h:40
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:35
virtual Width_t GetLineWidth() const
Definition: TAttLine.h:49
virtual ~TGraphEdge()
Graph Edge default destructor.
Definition: TGraphEdge.cxx:63
const Int_t n
Definition: legend1.C:16
Line Attributes class.
Definition: TAttLine.h:32
virtual void SetAngle(Float_t angle=60)
Definition: TArrow.h:64
TGraphNode * fNode1
Definition: TGraphEdge.h:42