Logo ROOT   6.14/05
Reference Guide
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 
40 
41 ////////////////////////////////////////////////////////////////////////////////
42 /// Copy constructor.
43 
45  TPolyMarker3D(t), TAttBBox(t), fOwnIds(kFALSE), fIds()
46 {
47  CopyIds(t);
48 }
49 
50 ////////////////////////////////////////////////////////////////////////////////
51 /// Destructor.
52 
54 {
55  ClearIds();
56 }
57 
58 ////////////////////////////////////////////////////////////////////////////////
59 /// Copy id objects from point-set 't'.
60 
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 
78 {
79  if (this != &t) {
80  ClearIds();
82  CopyIds(t);
83  }
84  return *this;
85 }
86 
87 ////////////////////////////////////////////////////////////////////////////////
88 /// Compute the bounding box of this points set.
89 
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 
108 {
109  SetPointId(fLastPoint, id);
110 }
111 
112 ////////////////////////////////////////////////////////////////////////////////
113 /// Set id of point n.
114 
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 
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 
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) {
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 }
Bool_t IsReading() const
Definition: TBuffer.h:83
virtual Int_t WriteClassBuffer(const TClass *cl, void *pointer)=0
float Float_t
Definition: RtypesCore.h:53
virtual void Expand(Int_t newSize)
Expand or shrink the array to newSize elements.
Definition: TRefArray.cxx:474
Bool_t fOwnIds
Definition: TPointSet3D.h:24
Buffer base class used for serializing objects.
Definition: TBuffer.h:40
void ClearIds()
Clears the id-array. If ids are owned the TObjects are deleted.
int Int_t
Definition: RtypesCore.h:41
TPolyMarker3D & operator=(const TPolyMarker3D &)
assignment operator
TObject * GetPointId(Int_t n) const
Definition: TPointSet3D.h:48
virtual void Print(Option_t *option="") const
This method must be overridden when a class wants to print itself.
Definition: TObject.cxx:550
virtual Int_t WriteObjectAny(const void *obj, const TClass *ptrClass, Bool_t cacheReuse=kTRUE)=0
void BBoxCheckPoint(Float_t x, Float_t y, Float_t z)
Definition: TAttBBox.h:58
virtual ~TPointSet3D()
Destructor.
Definition: TPointSet3D.cxx:53
void Class()
Definition: Class.C:29
void SetPointId(TObject *id)
Set id of last point.
Int_t GetEntries() const
Return the number of objects in array (i.e.
Definition: TRefArray.cxx:589
TObject * At(Int_t idx) const
Definition: TRefArray.h:180
TPointSet3D & operator=(const TPointSet3D &t)
Assignment operator.
Definition: TPointSet3D.cxx:77
virtual void PointSelected(Int_t n)
This virtual method is called from TPointSet3DGL when a point is selected.
virtual void AddAt(TObject *obj, Int_t idx)
Add object at position ids.
Definition: TRefArray.cxx:359
void BBoxZero(Float_t epsilon=0, Float_t x=0, Float_t y=0, Float_t z=0)
Create cube of volume (2*epsilon)^3 at (x,y,z).
Definition: TAttBBox.cxx:42
virtual void ComputeBBox()
Compute the bounding box of this points set.
Definition: TPointSet3D.cxx:90
void CopyIds(const TPointSet3D &t)
Copy id objects from point-set &#39;t&#39;.
Definition: TPointSet3D.cxx:61
const Bool_t kFALSE
Definition: RtypesCore.h:88
virtual Int_t ReadClassBuffer(const TClass *cl, void *pointer, const TClass *onfile_class=0)=0
#define ClassImp(name)
Definition: Rtypes.h:359
unsigned long ULong_t
Definition: RtypesCore.h:51
virtual void * ReadObjectAny(const TClass *cast)=0
Mother of all ROOT objects.
Definition: TObject.h:37
virtual TObject * Clone(const char *newname="") const
Make a clone of an object using the Streamer facility.
Definition: TObject.cxx:144
TRefArray fIds
Definition: TPointSet3D.h:25
A 3D polymarker.
Definition: TPolyMarker3D.h:32
Helper for management of bounding-box information.
Definition: TAttBBox.h:17
R__EXTERN Int_t gDebug
Definition: Rtypes.h:86
TPolyMarker3D using TPointSet3DGL for direct OpenGL rendering.
Definition: TPointSet3D.h:21
Float_t * fP
Definition: TPolyMarker3D.h:36
virtual const char * GetName() const
Returns name of object.
Definition: TObject.cxx:357
virtual Int_t GetSize() const
Return the capacity of the collection, i.e.
Definition: TCollection.h:182
const Int_t n
Definition: legend1.C:16
void BBoxInit(Float_t infinity=1e6)
Dynamic Float_t[6] X(min,max), Y(min,max), Z(min,max)
Definition: TAttBBox.cxx:29
virtual Int_t Size() const
Definition: TPolyMarker3D.h:73