Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
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
19TPolyMarker3D using TPointSet3DGL for direct OpenGL rendering.
20Supports 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
26Marker-size (from TAttMarker) is multiplied by 5!
27
28An identification of type TObject* can be assigned to each point
29via SetPointId() method. Set the fOwnIds flag if the ids are owned
30by the point-set and should be deleted when pointset is cleared or
31destructed.
32
33Copy-constructor and assignment operator COPIES the ids if the are
34not owned and CLONES them if they are owned.
35
36The ids are not streamed.
37*/
38
39
40////////////////////////////////////////////////////////////////////////////////
41/// Copy constructor.
42
44 TPolyMarker3D(t), TAttBBox(t), fOwnIds(kFALSE), fIds()
45{
46 CopyIds(t);
47}
48
49////////////////////////////////////////////////////////////////////////////////
50/// Destructor.
51
56
57////////////////////////////////////////////////////////////////////////////////
58/// Copy id objects from point-set 't'.
59
61{
62 fOwnIds = t.fOwnIds;
64 if (fOwnIds) {
65 for (Int_t i=0; i<t.fIds.GetSize(); ++i)
66 fIds.AddAt(t.fIds.At(i)->Clone(), i);
67 } else {
68 for (Int_t i=0; i<t.fIds.GetSize(); ++i)
69 fIds.AddAt(t.fIds.At(i), i);
70 }
71}
72
73////////////////////////////////////////////////////////////////////////////////
74/// Assignment operator.
75
77{
78 if (this != &t) {
79 ClearIds();
81 CopyIds(t);
82 }
83 return *this;
84}
85
86////////////////////////////////////////////////////////////////////////////////
87/// Compute the bounding box of this points set.
88
90{
91 if (Size() > 0) {
92 BBoxInit();
93 Int_t n = Size();
94 Float_t* p = fP;
95 for (Int_t i = 0; i < n; ++i, p += 3) {
97 }
98 } else {
99 BBoxZero();
100 }
101}
102////////////////////////////////////////////////////////////////////////////////
103/// Set id of last point.
104/// Use this method if you also use TPolyMarker3D::SetNextPoint().
105
110
111////////////////////////////////////////////////////////////////////////////////
112/// Set id of point n.
113
115{
116 if (n >= fN) return;
117 if (fN > fIds.GetSize())
118 fIds.Expand(fN);
119 fIds.AddAt(id, n);
120}
121
122////////////////////////////////////////////////////////////////////////////////
123/// Clears the id-array. If ids are owned the TObjects are deleted.
124
126{
127 if (fOwnIds) {
128 for (Int_t i=0; i<fIds.GetSize(); ++i)
129 delete GetPointId(i);
130 }
131 fIds.Expand(0);
132}
133
134////////////////////////////////////////////////////////////////////////////////
135/// This virtual method is called from TPointSet3DGL when a point is
136/// selected.
137///
138/// At this point it just prints out n and id of the point (if it exists).
139/// To make something useful out of this do:
140///
141/// 1. subclass and re-implement this method;
142/// 2. extend this class to include TExec or some other kind of callback.
143
145{
146 TObject* id = GetPointId(n);
147 printf("TPointSet3D::PointSelected n=%d, id=(%s*)0x%zx\n",
148 n, id ? id->IsA()->GetName() : "void", (size_t)id);
149 if (id)
150 id->Print();
151}
152
153////////////////////////////////////////////////////////////////////////////////
154/// Stream an object of class TPointSet3D.
155
157{
158 if (R__b.IsReading()) {
159 R__b.ReadClassBuffer(TPointSet3D::Class(), this);
160 if (fOwnIds) {
161 Int_t n;
162 R__b >> n;
163 for (Int_t i=0; i<n; ++i) {
164 TObject* o = (TObject*) R__b.ReadObjectAny(TObject::Class());
165 if (gDebug > 0) { printf("Read[%2d]: ", i); o->Print(); }
166 }
167 }
168 } else {
169 R__b.WriteClassBuffer(TPointSet3D::Class(), this);
170 if (fOwnIds) {
171 R__b << fIds.GetEntries();
172 TObject* o;
173 TIter next(&fIds);
174 while ((o = next())) {
175 if (gDebug > 0) { printf("Writing: "); o->Print(); }
176 R__b.WriteObjectAny(o, TObject::Class());
177 }
178 }
179 }
180}
float Float_t
Float 4 bytes (float)
Definition RtypesCore.h:71
constexpr Bool_t kFALSE
Definition RtypesCore.h:108
ROOT::Detail::TRangeCast< T, true > TRangeDynCast
TRangeDynCast is an adapter class that allows the typed iteration through a TCollection.
winID h TVirtualViewer3D TVirtualGLPainter p
Int_t gDebug
Global variable setting the debug level. Set to 0 to disable, increase it in steps of 1 to increase t...
Definition TROOT.cxx:627
Helper for management of bounding-box information.
Definition TAttBBox.h:18
void BBoxCheckPoint(Float_t x, Float_t y, Float_t z)
Definition TAttBBox.h:69
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:41
void BBoxInit(Float_t infinity=1e6)
Dynamic Float_t[6] X(min,max), Y(min,max), Z(min,max)
Definition TAttBBox.cxx:28
Buffer base class used for serializing objects.
Definition TBuffer.h:43
virtual Int_t GetSize() const
Return the capacity of the collection, i.e.
Mother of all ROOT objects.
Definition TObject.h:41
virtual TObject * Clone(const char *newname="") const
Make a clone of an object using the Streamer facility.
Definition TObject.cxx:242
static TClass * Class()
virtual void Print(Option_t *option="") const
This method must be overridden when a class wants to print itself.
Definition TObject.cxx:655
TPolyMarker3D using TPointSet3DGL for direct OpenGL rendering.
Definition TPointSet3D.h:22
static TClass * Class()
void Streamer(TBuffer &) override
Stream an object of class TPointSet3D.
TRefArray fIds
Definition TPointSet3D.h:25
virtual void PointSelected(Int_t n)
This virtual method is called from TPointSet3DGL when a point is selected.
Bool_t fOwnIds
Definition TPointSet3D.h:24
TPointSet3D & operator=(const TPointSet3D &t)
Assignment operator.
void ClearIds()
Clears the id-array. If ids are owned the TObjects are deleted.
~TPointSet3D() override
Destructor.
void CopyIds(const TPointSet3D &t)
Copy id objects from point-set 't'.
void SetPointId(TObject *id)
Set id of last point.
TObject * GetPointId(Int_t n) const
Definition TPointSet3D.h:48
void ComputeBBox() override
Compute the bounding box of this points set.
A 3D polymarker.
virtual Int_t Size() const
TPolyMarker3D & operator=(const TPolyMarker3D &)
assignment operator
void AddAt(TObject *obj, Int_t idx) override
Add object at position ids.
TObject * At(Int_t idx) const override
Definition TRefArray.h:178
virtual void Expand(Int_t newSize)
Expand or shrink the array to newSize elements.
Int_t GetEntries() const override
Return the number of objects in array (i.e.
const Int_t n
Definition legend1.C:16