Logo ROOT   6.30.04
Reference Guide
 All Namespaces Files Pages
TPointSet3D.cxx
Go to the documentation of this file.
1 // @(#)root/g3d:$Id$
2 // Author: Matevz Tadel 7/4/2006
3 
4 /*************************************************************************
5  * Copyright (C) 1995-2006, 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 "TPointSet3D.h"
13 #include "TBuffer.h"
14 #include "TClass.h"
15 
16 /** \class TPointSet3D
17 \ingroup g3d
18 
19 TPolyMarker3D using TPointSet3DGL for direct OpenGL rendering.
20 Supports only elementary marker types:
21  - 4, 20, 24 : round points, size in pixels;
22  - 2, 3, 5 : crosses, size in scene units;
23  - 28 : as above, line width 2 pixels;
24  - all other : square points, size in pixels.
25 
26 Marker-size (from TAttMarker) is multiplied by 5!
27 
28 An identification of type TObject* can be assigned to each point
29 via SetPointId() method. Set the fOwnIds flag if the ids are owned
30 by the point-set and should be deleted when pointset is cleared or
31 destructed.
32 
33 Copy-constructor and assignment operator COPIES the ids if the are
34 not owned and CLONES them if they are owned.
35 
36 The ids are not streamed.
37 */
38 
39 ClassImp(TPointSet3D);
40 
41 ////////////////////////////////////////////////////////////////////////////////
42 /// Copy constructor.
43 
44 TPointSet3D::TPointSet3D(const TPointSet3D &t) :
45  TPolyMarker3D(t), TAttBBox(t), fOwnIds(kFALSE), fIds()
46 {
47  CopyIds(t);
48 }
49 
50 ////////////////////////////////////////////////////////////////////////////////
51 /// Destructor.
52 
53 TPointSet3D::~TPointSet3D()
54 {
55  ClearIds();
56 }
57 
58 ////////////////////////////////////////////////////////////////////////////////
59 /// Copy id objects from point-set 't'.
60 
61 void TPointSet3D::CopyIds(const TPointSet3D& t)
62 {
63  fOwnIds = t.fOwnIds;
64  fIds.Expand(t.fIds.GetSize());
65  if (fOwnIds) {
66  for (Int_t i=0; i<t.fIds.GetSize(); ++i)
67  fIds.AddAt(t.fIds.At(i)->Clone(), i);
68  } else {
69  for (Int_t i=0; i<t.fIds.GetSize(); ++i)
70  fIds.AddAt(t.fIds.At(i), i);
71  }
72 }
73 
74 ////////////////////////////////////////////////////////////////////////////////
75 /// Assignment operator.
76 
77 TPointSet3D& TPointSet3D::operator=(const TPointSet3D& t)
78 {
79  if (this != &t) {
80  ClearIds();
81  TPolyMarker3D::operator=(t);
82  CopyIds(t);
83  }
84  return *this;
85 }
86 
87 ////////////////////////////////////////////////////////////////////////////////
88 /// Compute the bounding box of this points set.
89 
90 void TPointSet3D::ComputeBBox()
91 {
92  if (Size() > 0) {
93  BBoxInit();
94  Int_t n = Size();
95  Float_t* p = fP;
96  for (Int_t i = 0; i < n; ++i, p += 3) {
97  BBoxCheckPoint(p);
98  }
99  } else {
100  BBoxZero();
101  }
102 }
103 ////////////////////////////////////////////////////////////////////////////////
104 /// Set id of last point.
105 /// Use this method if you also use TPolyMarker3D::SetNextPoint().
106 
107 void TPointSet3D::SetPointId(TObject* id)
108 {
109  SetPointId(fLastPoint, id);
110 }
111 
112 ////////////////////////////////////////////////////////////////////////////////
113 /// Set id of point n.
114 
115 void TPointSet3D::SetPointId(Int_t n, TObject* id)
116 {
117  if (n >= fN) return;
118  if (fN > fIds.GetSize())
119  fIds.Expand(fN);
120  fIds.AddAt(id, n);
121 }
122 
123 ////////////////////////////////////////////////////////////////////////////////
124 /// Clears the id-array. If ids are owned the TObjects are deleted.
125 
126 void TPointSet3D::ClearIds()
127 {
128  if (fOwnIds) {
129  for (Int_t i=0; i<fIds.GetSize(); ++i)
130  delete GetPointId(i);
131  }
132  fIds.Expand(0);
133 }
134 
135 ////////////////////////////////////////////////////////////////////////////////
136 /// This virtual method is called from TPointSet3DGL when a point is
137 /// selected.
138 ///
139 /// At this point it just prints out n and id of the point (if it exists).
140 /// To make something useful out of this do:
141 ///
142 /// 1. subclass and re-implement this method;
143 /// 2. extend this class to include TExec or some other kind of callback.
144 
145 void TPointSet3D::PointSelected(Int_t n)
146 {
147  TObject* id = GetPointId(n);
148  printf("TPointSet3D::PointSelected n=%d, id=(%s*)0x%lx\n",
149  n, id ? id->IsA()->GetName() : "void", (ULong_t)id);
150  if (id)
151  id->Print();
152 }
153 
154 ////////////////////////////////////////////////////////////////////////////////
155 /// Stream an object of class TPointSet3D.
156 
157 void TPointSet3D::Streamer(TBuffer &R__b)
158 {
159  if (R__b.IsReading()) {
160  R__b.ReadClassBuffer(TPointSet3D::Class(), this);
161  if (fOwnIds) {
162  Int_t n;
163  R__b >> n;
164  for (Int_t i=0; i<n; ++i) {
165  TObject* o = (TObject*) R__b.ReadObjectAny(TObject::Class());
166  if (gDebug > 0) { printf("Read[%2d]: ", i); o->Print(); }
167  }
168  }
169  } else {
170  R__b.WriteClassBuffer(TPointSet3D::Class(), this);
171  if (fOwnIds) {
172  R__b << fIds.GetEntries();
173  TObject* o;
174  TIter next(&fIds);
175  while ((o = next())) {
176  if (gDebug > 0) { printf("Writing: "); o->Print(); }
177  R__b.WriteObjectAny(o, TObject::Class());
178  }
179  }
180  }
181 }