TGLSelectBuffer.cxx

Go to the documentation of this file.
00001 // @(#)root/gl:$Id: TGLSelectBuffer.cxx 21565 2007-12-28 12:28:46Z brun $
00002 // Author:  Matevz Tadel, Feb 2007
00003 
00004 /*************************************************************************
00005  * Copyright (C) 1995-2004, Rene Brun and Fons Rademakers.               *
00006  * All rights reserved.                                                  *
00007  *                                                                       *
00008  * For the licensing terms see $ROOTSYS/LICENSE.                         *
00009  * For the list of contributors see $ROOTSYS/README/CREDITS.             *
00010  *************************************************************************/
00011 
00012 #include "TGLSelectBuffer.h"
00013 #include "TGLSelectRecord.h"
00014 #include <TMath.h>
00015 
00016 #include <algorithm>
00017 
00018 //______________________________________________________________________________
00019 //
00020 // Encapsulates OpenGL select buffer.
00021 // Provides sorting of the results based on z-coordinate of the
00022 // selection hit and can fill the TGLSelectRecordBase records.
00023 
00024 Int_t TGLSelectBuffer::fgMaxBufSize = 1 << 20; // 1MByte
00025 
00026 //______________________________________________________________________________
00027 TGLSelectBuffer::TGLSelectBuffer() :
00028    fBufSize  (1024),
00029    fBuf      (new UInt_t [fBufSize]),
00030    fNRecords (-1)
00031 {
00032    // Constructor.
00033 }
00034 
00035 //______________________________________________________________________________
00036 TGLSelectBuffer::~TGLSelectBuffer()
00037 {
00038    // Destructor.
00039 
00040    delete [] fBuf;
00041 }
00042 
00043 //______________________________________________________________________________
00044 Bool_t TGLSelectBuffer::CanGrow()
00045 {
00046    //static: return true if current buffer is smaller than the max buffer size
00047    return fBufSize < fgMaxBufSize;
00048 }
00049 
00050 //______________________________________________________________________________
00051 void TGLSelectBuffer::Grow()
00052 {
00053    // Increase size of the select buffer.
00054 
00055    delete [] fBuf;
00056    fBufSize = TMath::Min(2*fBufSize, fgMaxBufSize);
00057    fBuf = new UInt_t[fBufSize];
00058 }
00059 
00060 //______________________________________________________________________________
00061 void TGLSelectBuffer::ProcessResult(Int_t glResult)
00062 {
00063    // Process result of GL-selection: sort the hits by their minimum
00064    // z-coordinate.
00065 
00066    // The '-1' case should be handled on the caller side.
00067    // Here we just assume no hits were recorded.
00068 
00069    if (glResult < 0)
00070       glResult = 0;
00071 
00072    fNRecords = glResult;
00073    fSortedRecords.resize(fNRecords);
00074 
00075    if (fNRecords > 0)
00076    {
00077       Int_t  i;
00078       UInt_t* buf = fBuf;
00079       for (i = 0; i < fNRecords; ++i)
00080       {
00081          fSortedRecords[i].first  = buf[1]; // minimum depth
00082          fSortedRecords[i].second = buf;    // record address
00083          buf += 3 + buf[0];
00084       }
00085       std::sort(fSortedRecords.begin(), fSortedRecords.end());
00086    }
00087 }
00088 
00089 //______________________________________________________________________________
00090 void TGLSelectBuffer::SelectRecord(TGLSelectRecordBase& rec, Int_t i)
00091 {
00092    // Return select record on (sorted) position i.
00093 
00094    rec.Set(fSortedRecords[i].second);
00095 }

Generated on Tue Jul 5 14:18:08 2011 for ROOT_528-00b_version by  doxygen 1.5.1