ROOT logo
// @(#)root/g3d:$Id$
// Author: Matevz Tadel  7/4/2006

/*************************************************************************
 * Copyright (C) 1995-2006, Rene Brun and Fons Rademakers.               *
 * All rights reserved.                                                  *
 *                                                                       *
 * For the licensing terms see $ROOTSYS/LICENSE.                         *
 * For the list of contributors see $ROOTSYS/README/CREDITS.             *
 *************************************************************************/


#include "TPointSet3D.h"
#include "TClass.h"

//______________________________________________________________________
//
// TPolyMarker3D using TPointSet3DGL for direct OpenGL rendering.
// Supports only elementary marker types:
// 4, 20, 24 : round points, size in pixels;
//   2, 3, 5 : crosses, size in scene units;
//        28 : as above, line width 2 pixels;
// all other : square points, size in pixels.
//
// Marker-size (from TAttMarker) is multiplied by 5!
//
// An identification of type TObject* can be assigned to each point
// via SetPointId() method. Set the fOwnIds flag if the ids are owned
// by the point-set and should be deleted when pointset is cleared or
// destructed.
//
// Copy-constructor and assignment operator COPIES the ids if the are
// not owned and CLONES them if they are owned.
//
// The ids are not streamed. 

ClassImp(TPointSet3D);

//______________________________________________________________________________
TPointSet3D::TPointSet3D(const TPointSet3D &t) :
   TPolyMarker3D(t), TAttBBox(t), fOwnIds(kFALSE), fIds()
{
   // Copy constructor.

   CopyIds(t);
}

//______________________________________________________________________________
TPointSet3D::~TPointSet3D()
{
   // Destructor.

   ClearIds();
}

//______________________________________________________________________________
void TPointSet3D::CopyIds(const TPointSet3D& t)
{
   // Copy id objects from point-set 't'.

   fOwnIds = t.fOwnIds;
   fIds.Expand(t.fIds.GetSize());
   if (fOwnIds) {
      for (Int_t i=0; i<t.fIds.GetSize(); ++i)
         fIds.AddAt(t.fIds.At(i)->Clone(), i);
   } else {
      for (Int_t i=0; i<t.fIds.GetSize(); ++i)
         fIds.AddAt(t.fIds.At(i), i);
   }
}

//______________________________________________________________________________
TPointSet3D& TPointSet3D::operator=(const TPointSet3D& t)
{
   // Assignement operator.

   if (this != &t) {
      ClearIds();
      TPolyMarker3D::operator=(t);
      CopyIds(t);
   }
   return *this;
}

//______________________________________________________________________________
void TPointSet3D::ComputeBBox()
{
   // Compute the bounding box of this points set.

   if (Size() > 0) {
      BBoxInit();
      Int_t    n = Size();
      Float_t* p = fP;
      for (Int_t i = 0; i < n; ++i, p += 3) {
         BBoxCheckPoint(p);
      }
   } else {
      BBoxZero();
   }
}
//______________________________________________________________________________
void TPointSet3D::SetPointId(TObject* id)
{
   // Set id of last point.
   // Use this method if you also use TPolyMarker3D::SetNextPoint().

   SetPointId(fLastPoint, id);
}

//______________________________________________________________________________
void TPointSet3D::SetPointId(Int_t n, TObject* id)
{
   // Set id of point n.

   if (n >= fN) return;
   if (fN > fIds.GetSize())
      fIds.Expand(fN);
   fIds.AddAt(id, n);
}

//______________________________________________________________________________
void TPointSet3D::ClearIds()
{
   // Clears the id-array. If ids are owned the TObjects are deleted.

   if (fOwnIds) {
      for (Int_t i=0; i<fIds.GetSize(); ++i)
         delete GetPointId(i);
   }
   fIds.Expand(0);
}

//______________________________________________________________________________
void TPointSet3D::PointSelected(Int_t n)
{
   // This virtual method is called from TPointSet3DGL when a point is
   // selected.
   // At this point it just prints out n and id of the point (if it exists).
   // To make something useful out of this do:
   //  a) subclass and re-implement this method;
   //  b) extend this class to include TExec or some other kind of callback.

   TObject* id = GetPointId(n);
   printf("TPointSet3D::PointSelected n=%d, id=(%s*)0x%lx\n",
          n, id ? id->IsA()->GetName() : "void", (ULong_t)id);
   if (id)
      id->Print();
}

//______________________________________________________________________________
void TPointSet3D::Streamer(TBuffer &R__b)
{
   // Stream an object of class TPointSet3D.

   if (R__b.IsReading()) {
      R__b.ReadClassBuffer(TPointSet3D::Class(), 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 {
      R__b.WriteClassBuffer(TPointSet3D::Class(), 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());
         }
      }
   }
}
 TPointSet3D.cxx:1
 TPointSet3D.cxx:2
 TPointSet3D.cxx:3
 TPointSet3D.cxx:4
 TPointSet3D.cxx:5
 TPointSet3D.cxx:6
 TPointSet3D.cxx:7
 TPointSet3D.cxx:8
 TPointSet3D.cxx:9
 TPointSet3D.cxx:10
 TPointSet3D.cxx:11
 TPointSet3D.cxx:12
 TPointSet3D.cxx:13
 TPointSet3D.cxx:14
 TPointSet3D.cxx:15
 TPointSet3D.cxx:16
 TPointSet3D.cxx:17
 TPointSet3D.cxx:18
 TPointSet3D.cxx:19
 TPointSet3D.cxx:20
 TPointSet3D.cxx:21
 TPointSet3D.cxx:22
 TPointSet3D.cxx:23
 TPointSet3D.cxx:24
 TPointSet3D.cxx:25
 TPointSet3D.cxx:26
 TPointSet3D.cxx:27
 TPointSet3D.cxx:28
 TPointSet3D.cxx:29
 TPointSet3D.cxx:30
 TPointSet3D.cxx:31
 TPointSet3D.cxx:32
 TPointSet3D.cxx:33
 TPointSet3D.cxx:34
 TPointSet3D.cxx:35
 TPointSet3D.cxx:36
 TPointSet3D.cxx:37
 TPointSet3D.cxx:38
 TPointSet3D.cxx:39
 TPointSet3D.cxx:40
 TPointSet3D.cxx:41
 TPointSet3D.cxx:42
 TPointSet3D.cxx:43
 TPointSet3D.cxx:44
 TPointSet3D.cxx:45
 TPointSet3D.cxx:46
 TPointSet3D.cxx:47
 TPointSet3D.cxx:48
 TPointSet3D.cxx:49
 TPointSet3D.cxx:50
 TPointSet3D.cxx:51
 TPointSet3D.cxx:52
 TPointSet3D.cxx:53
 TPointSet3D.cxx:54
 TPointSet3D.cxx:55
 TPointSet3D.cxx:56
 TPointSet3D.cxx:57
 TPointSet3D.cxx:58
 TPointSet3D.cxx:59
 TPointSet3D.cxx:60
 TPointSet3D.cxx:61
 TPointSet3D.cxx:62
 TPointSet3D.cxx:63
 TPointSet3D.cxx:64
 TPointSet3D.cxx:65
 TPointSet3D.cxx:66
 TPointSet3D.cxx:67
 TPointSet3D.cxx:68
 TPointSet3D.cxx:69
 TPointSet3D.cxx:70
 TPointSet3D.cxx:71
 TPointSet3D.cxx:72
 TPointSet3D.cxx:73
 TPointSet3D.cxx:74
 TPointSet3D.cxx:75
 TPointSet3D.cxx:76
 TPointSet3D.cxx:77
 TPointSet3D.cxx:78
 TPointSet3D.cxx:79
 TPointSet3D.cxx:80
 TPointSet3D.cxx:81
 TPointSet3D.cxx:82
 TPointSet3D.cxx:83
 TPointSet3D.cxx:84
 TPointSet3D.cxx:85
 TPointSet3D.cxx:86
 TPointSet3D.cxx:87
 TPointSet3D.cxx:88
 TPointSet3D.cxx:89
 TPointSet3D.cxx:90
 TPointSet3D.cxx:91
 TPointSet3D.cxx:92
 TPointSet3D.cxx:93
 TPointSet3D.cxx:94
 TPointSet3D.cxx:95
 TPointSet3D.cxx:96
 TPointSet3D.cxx:97
 TPointSet3D.cxx:98
 TPointSet3D.cxx:99
 TPointSet3D.cxx:100
 TPointSet3D.cxx:101
 TPointSet3D.cxx:102
 TPointSet3D.cxx:103
 TPointSet3D.cxx:104
 TPointSet3D.cxx:105
 TPointSet3D.cxx:106
 TPointSet3D.cxx:107
 TPointSet3D.cxx:108
 TPointSet3D.cxx:109
 TPointSet3D.cxx:110
 TPointSet3D.cxx:111
 TPointSet3D.cxx:112
 TPointSet3D.cxx:113
 TPointSet3D.cxx:114
 TPointSet3D.cxx:115
 TPointSet3D.cxx:116
 TPointSet3D.cxx:117
 TPointSet3D.cxx:118
 TPointSet3D.cxx:119
 TPointSet3D.cxx:120
 TPointSet3D.cxx:121
 TPointSet3D.cxx:122
 TPointSet3D.cxx:123
 TPointSet3D.cxx:124
 TPointSet3D.cxx:125
 TPointSet3D.cxx:126
 TPointSet3D.cxx:127
 TPointSet3D.cxx:128
 TPointSet3D.cxx:129
 TPointSet3D.cxx:130
 TPointSet3D.cxx:131
 TPointSet3D.cxx:132
 TPointSet3D.cxx:133
 TPointSet3D.cxx:134
 TPointSet3D.cxx:135
 TPointSet3D.cxx:136
 TPointSet3D.cxx:137
 TPointSet3D.cxx:138
 TPointSet3D.cxx:139
 TPointSet3D.cxx:140
 TPointSet3D.cxx:141
 TPointSet3D.cxx:142
 TPointSet3D.cxx:143
 TPointSet3D.cxx:144
 TPointSet3D.cxx:145
 TPointSet3D.cxx:146
 TPointSet3D.cxx:147
 TPointSet3D.cxx:148
 TPointSet3D.cxx:149
 TPointSet3D.cxx:150
 TPointSet3D.cxx:151
 TPointSet3D.cxx:152
 TPointSet3D.cxx:153
 TPointSet3D.cxx:154
 TPointSet3D.cxx:155
 TPointSet3D.cxx:156
 TPointSet3D.cxx:157
 TPointSet3D.cxx:158
 TPointSet3D.cxx:159
 TPointSet3D.cxx:160
 TPointSet3D.cxx:161
 TPointSet3D.cxx:162
 TPointSet3D.cxx:163
 TPointSet3D.cxx:164
 TPointSet3D.cxx:165
 TPointSet3D.cxx:166
 TPointSet3D.cxx:167
 TPointSet3D.cxx:168
 TPointSet3D.cxx:169
 TPointSet3D.cxx:170
 TPointSet3D.cxx:171
 TPointSet3D.cxx:172
 TPointSet3D.cxx:173
 TPointSet3D.cxx:174
 TPointSet3D.cxx:175
 TPointSet3D.cxx:176
 TPointSet3D.cxx:177