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
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;
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) {
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{
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%zx\n",
149 n, id ? id->IsA()->GetName() : "void", (size_t)id);
150 if (id)
151 id->Print();
152}
153
154////////////////////////////////////////////////////////////////////////////////
155/// Stream an object of class TPointSet3D.
156
158{
159 if (R__b.IsReading()) {
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 {
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(); }
178 }
179 }
180 }
181}
float Float_t
Definition RtypesCore.h:57
constexpr Bool_t kFALSE
Definition RtypesCore.h:101
#define ClassImp(name)
Definition Rtypes.h:377
winID h TVirtualViewer3D TVirtualGLPainter p
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize id
Int_t gDebug
Definition TROOT.cxx:597
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:42
void BBoxInit(Float_t infinity=1e6)
Dynamic Float_t[6] X(min,max), Y(min,max), Z(min,max)
Definition TAttBBox.cxx:29
Buffer base class used for serializing objects.
Definition TBuffer.h:43
virtual void * ReadObjectAny(const TClass *cast)=0
virtual Int_t WriteObjectAny(const void *obj, const TClass *ptrClass, Bool_t cacheReuse=kTRUE)=0
virtual Int_t ReadClassBuffer(const TClass *cl, void *pointer, const TClass *onfile_class=nullptr)=0
Bool_t IsReading() const
Definition TBuffer.h:86
virtual Int_t WriteClassBuffer(const TClass *cl, void *pointer)=0
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:223
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:636
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