Skip to content
Snippets Groups Projects
Commit e9300123 authored by Fons Rademakers's avatar Fons Rademakers
Browse files

From Matevz:

Use TRefArray for storing per-point object ids; provide custom
Streamer to write-out the referenced objects in case they're owned
by the TPointSet3D.


git-svn-id: http://root.cern.ch/svn/root/trunk@16355 27541ba8-7e3a-0410-8455-c3a389f83636
parent 6637700e
Branches
Tags
No related merge requests found
/* @(#)root/g3d:$Name: $:$Id: LinkDef.h,v 1.7 2004/12/06 07:22:55 brun Exp $ */ /* @(#)root/g3d:$Name: $:$Id: LinkDef.h,v 1.8 2006/04/07 08:43:59 brun Exp $ */
/************************************************************************* /*************************************************************************
* Copyright (C) 1995-2000, Rene Brun and Fons Rademakers. * * Copyright (C) 1995-2000, Rene Brun and Fons Rademakers. *
...@@ -37,7 +37,7 @@ ...@@ -37,7 +37,7 @@
#pragma link C++ class TPGON+; #pragma link C++ class TPGON+;
#pragma link C++ class TPolyLine3D-; #pragma link C++ class TPolyLine3D-;
#pragma link C++ class TPolyMarker3D-; #pragma link C++ class TPolyMarker3D-;
#pragma link C++ class TPointSet3D+; #pragma link C++ class TPointSet3D-;
#pragma link C++ class TRotMatrix-; #pragma link C++ class TRotMatrix-;
#pragma link C++ class TShape-; #pragma link C++ class TShape-;
#pragma link C++ class TSPHE-; #pragma link C++ class TSPHE-;
......
// @(#)root/g3d:$Name: $:$Id: TPointSet3D.h,v 1.2 2006/04/07 09:20:43 rdm Exp $ // @(#)root/g3d:$Name: $:$Id: TPointSet3D.h,v 1.3 2006/08/23 14:39:40 brun Exp $
// Author: Matevz Tadel 7/4/2006 // Author: Matevz Tadel 7/4/2006
/************************************************************************* /*************************************************************************
...@@ -20,32 +20,27 @@ ...@@ -20,32 +20,27 @@
#include "TAttBBox.h" #include "TAttBBox.h"
#endif #endif
#include "TRefArray.h"
class TPointSet3D : public TPolyMarker3D, public TAttBBox class TPointSet3D : public TPolyMarker3D, public TAttBBox
{ {
protected: protected:
TObject** fIds; //!User-provided point identifications Bool_t fOwnIds; //Flag specifying id-objects are owned by the point-set
Int_t fNIds; //!Number of allocated entries for user-ids TRefArray fIds; //User-provided point identifications
Bool_t fOwnIds; //!Flag specifying id-objects are owned by the point-set
Bool_t fFakeIds;//!Flag specifying ids are not TObject*
TPointSet3D& operator=(const TPointSet3D&); TPointSet3D& operator=(const TPointSet3D&);
public: public:
TPointSet3D() : TPointSet3D() :
TPolyMarker3D(), fIds(0), fNIds(0), TPolyMarker3D(), fOwnIds(kFALSE) { fName = "TPointSet3D"; }
fOwnIds(kFALSE), fFakeIds(kFALSE) { fName = "TPointSet3D"; }
TPointSet3D(Int_t n, Marker_t m=1, Option_t *opt="") : TPointSet3D(Int_t n, Marker_t m=1, Option_t *opt="") :
TPolyMarker3D(n, m, opt), fIds(0), fNIds(0), TPolyMarker3D(n, m, opt), fOwnIds(kFALSE) { fName = "TPointSet3D"; }
fOwnIds(kFALSE), fFakeIds(kFALSE) { fName = "TPointSet3D"; }
TPointSet3D(Int_t n, Float_t *p, Marker_t m=1, Option_t *opt="") : TPointSet3D(Int_t n, Float_t *p, Marker_t m=1, Option_t *opt="") :
TPolyMarker3D(n, p, m, opt), fIds(0), fNIds(0), TPolyMarker3D(n, p, m, opt), fOwnIds(kFALSE) { fName = "TPointSet3D"; }
fOwnIds(kFALSE), fFakeIds(kFALSE) { fName = "TPointSet3D"; }
TPointSet3D(Int_t n, Double_t *p, Marker_t m=1, Option_t *opt="") : TPointSet3D(Int_t n, Double_t *p, Marker_t m=1, Option_t *opt="") :
TPolyMarker3D(n, p, m, opt), fIds(0), fNIds(0), TPolyMarker3D(n, p, m, opt), fOwnIds(kFALSE) { fName = "TPointSet3D"; }
fOwnIds(kFALSE), fFakeIds(kFALSE) { fName = "TPointSet3D"; }
TPointSet3D(const TPointSet3D &ps) : TPointSet3D(const TPointSet3D &ps) :
TPolyMarker3D(ps), TAttBBox(), fIds(0), fNIds(0), TPolyMarker3D(ps), TAttBBox(ps), fOwnIds(kFALSE), fIds(ps.fIds) {}
fOwnIds(kFALSE), fFakeIds(kFALSE) { fName = "TPointSet3D"; }
virtual ~TPointSet3D(); virtual ~TPointSet3D();
...@@ -53,13 +48,11 @@ public: ...@@ -53,13 +48,11 @@ public:
void SetPointId(TObject* id); void SetPointId(TObject* id);
void SetPointId(Int_t n, TObject* id); void SetPointId(Int_t n, TObject* id);
TObject* GetPointId(Int_t n) const; TObject* GetPointId(Int_t n) const { return fIds.At(n); }
void ClearIds(); void ClearIds();
Bool_t GetOwnIds() const { return fOwnIds; } Bool_t GetOwnIds() const { return fOwnIds; }
void SetOwnIds(Bool_t o) { fOwnIds = o; } void SetOwnIds(Bool_t o) { fOwnIds = o; }
Bool_t GetFakeIds() const { return fFakeIds; }
void SetFakeIds(Bool_t f) { fFakeIds = f; }
virtual void PointSelected(Int_t n); virtual void PointSelected(Int_t n);
......
// @(#)root/g3d:$Name: $:$Id: TPointSet3D.cxx,v 1.4 2006/05/09 19:08:44 brun Exp $ // @(#)root/g3d:$Name: $:$Id: TPointSet3D.cxx,v 1.5 2006/08/23 14:39:40 brun Exp $
// Author: Matevz Tadel 7/4/2006 // Author: Matevz Tadel 7/4/2006
/************************************************************************* /*************************************************************************
...@@ -42,6 +42,10 @@ TPointSet3D& TPointSet3D::operator=(const TPointSet3D& tp3) ...@@ -42,6 +42,10 @@ TPointSet3D& TPointSet3D::operator=(const TPointSet3D& tp3)
if(this!=&tp3) { if(this!=&tp3) {
ClearIds(); ClearIds();
TPolyMarker3D::operator=(tp3); TPolyMarker3D::operator=(tp3);
fOwnIds = kFALSE;
fIds.Expand(tp3.fIds.GetSize());
for (Int_t i=0; i<tp3.fIds.GetSize(); ++i)
fIds.AddAt(tp3.fIds.At(i), i);
} }
return *this; return *this;
} }
...@@ -85,27 +89,9 @@ void TPointSet3D::SetPointId(Int_t n, TObject* id) ...@@ -85,27 +89,9 @@ void TPointSet3D::SetPointId(Int_t n, TObject* id)
// Set id of point n. // Set id of point n.
if (n >= fN) return; if (n >= fN) return;
if (fN > fNIds) { if (fN > fIds.GetSize())
TObject** idarr = new TObject* [fN]; fIds.Expand(fN);
if (fIds && fNIds) { fIds.AddAt(id, n);
memcpy(idarr, fIds, fNIds*sizeof(TObject*));
memset(idarr+fNIds, 0, (fN-fNIds)*sizeof(TObject*));
delete [] fIds;
}
fIds = idarr;
fNIds = fN;
}
fIds[n] = id;
}
//______________________________________________________________________________
TObject* TPointSet3D::GetPointId(Int_t n) const
{
// Get id of point n.
// If n is out of range 0 is returned.
if (n < 0 || n >= fNIds) return 0;
return fIds[n];
} }
//______________________________________________________________________________ //______________________________________________________________________________
...@@ -113,13 +99,11 @@ void TPointSet3D::ClearIds() ...@@ -113,13 +99,11 @@ void TPointSet3D::ClearIds()
{ {
// Clears the id-array. If ids are owned the TObjects are deleted. // Clears the id-array. If ids are owned the TObjects are deleted.
if (fNIds <= 0) return;
if (fOwnIds) { if (fOwnIds) {
for (Int_t i=0; i<fNIds; ++i) for (Int_t i=0; i<fIds.GetSize(); ++i)
if (fIds[i]) delete fIds[i]; delete GetPointId(i);
} }
delete [] fIds; fIds.Expand(0);
fNIds = 0;
} }
//______________________________________________________________________________ //______________________________________________________________________________
...@@ -133,9 +117,37 @@ void TPointSet3D::PointSelected(Int_t n) ...@@ -133,9 +117,37 @@ void TPointSet3D::PointSelected(Int_t n)
// b) extend this class to include TExec or some other kind of callback. // b) extend this class to include TExec or some other kind of callback.
TObject* id = GetPointId(n); TObject* id = GetPointId(n);
Bool_t idok = (id != 0 && fFakeIds == kFALSE);
printf("TPointSet3D::PointSelected n=%d, id=(%s*)0x%lx\n", printf("TPointSet3D::PointSelected n=%d, id=(%s*)0x%lx\n",
n, idok ? id->IsA()->GetName() : "void", (ULong_t)id); n, id ? id->IsA()->GetName() : "void", (ULong_t)id);
if (idok) if (id)
id->Print(); id->Print();
} }
//______________________________________________________________________________
void TPointSet3D::Streamer(TBuffer &R__b)
{
// Stream an object of class TPointSet3D.
if (R__b.IsReading()) {
TPointSet3D::Class()->ReadBuffer(R__b, this);
if (fOwnIds) {
Int_t n;
R__b >> n;
for (Int_t i=0; i<n; ++i) {
TObject* o = (TObject*) R__b.ReadObjectAny(TObject::Class());
if (gDebug > 0) printf("Read[%2d]: ", i); o->Print();
}
}
} else {
TPointSet3D::Class()->WriteBuffer(R__b, this);
if (fOwnIds) {
R__b << fIds.GetEntries();
TObject* o;
TIter next(&fIds);
while ((o = next())) {
if (gDebug > 0) printf("Writing: "); o->Print();
R__b.WriteObjectAny(o, TObject::Class());
}
}
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment