TViewer3DPad.cxx

Go to the documentation of this file.
00001 // @(#)root/base:$Id: TViewer3DPad.cxx 21346 2007-12-12 16:18:29Z couet $
00002 // Author: Richard Maunder  10/3/2005
00003 
00004 /*************************************************************************
00005  * Copyright (C) 1995-2000, 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 "TViewer3DPad.h"
00013 #include "TVirtualPad.h"
00014 #include "TView.h"
00015 #include "TBuffer3D.h"
00016 #include "TBuffer3DTypes.h"
00017 
00018 #include <assert.h>
00019 
00020 //______________________________________________________________________________
00021 //
00022 // Provides 3D viewer interface (TVirtualViewer3D) support on a pad.
00023 // Will be merged with TView / TView3D eventually.
00024 
00025 
00026 ClassImp(TViewer3DPad)
00027 
00028 //______________________________________________________________________________
00029 Bool_t TViewer3DPad::PreferLocalFrame() const
00030 {
00031    // Indicates if we prefer positions in local frame. Always false - pad
00032    // drawing is always done in master frame.
00033    return kFALSE;
00034 }
00035 
00036 
00037 //______________________________________________________________________________
00038 void TViewer3DPad::BeginScene()
00039 {
00040    // Open a scene on the viewer
00041    assert(!fBuilding);
00042 
00043    // Create a 3D view if none exists
00044    TView *view = fPad.GetView();
00045    if (!view) {
00046       view = TView::CreateView(1,0,0); // Cartesian view by default
00047       if (!view) {
00048          assert(kFALSE);
00049          return;
00050       }
00051       fPad.SetView(view);
00052 
00053       // Set view to perform first auto-range (scaling) pass 
00054       view->SetAutoRange(kTRUE);
00055    }
00056 
00057    fBuilding = kTRUE;
00058 }
00059 
00060 //______________________________________________________________________________
00061 void TViewer3DPad::EndScene()
00062 {
00063    // Close the scene on the viewer
00064    assert(fBuilding);
00065 
00066    // If we are doing for auto-range pass on view invoke another pass
00067    TView *view = fPad.GetView();
00068    if (view) {
00069       if (view->GetAutoRange()) {
00070          view->SetAutoRange(kFALSE);
00071          fPad.Paint();
00072       }
00073    }   
00074    
00075    fBuilding = kFALSE;
00076 }
00077 
00078 //______________________________________________________________________________
00079 Int_t TViewer3DPad::AddObject(const TBuffer3D & buffer, Bool_t * addChildren)
00080 {
00081    // Add an 3D object described by the buffer to the viewer. Returns flags
00082    // to indicate:
00083    // i) if extra sections of the buffer need completing. 
00084    // ii) if child objects of the buffer object should be added (always true)
00085 
00086    // Accept any children
00087    if (addChildren) {
00088       *addChildren = kTRUE;
00089    }
00090 
00091    TView * view = fPad.GetView();
00092    if (!view) {
00093       assert(kFALSE);
00094       return TBuffer3D::kNone;
00095    }
00096 
00097    UInt_t reqSections = TBuffer3D::kCore|TBuffer3D::kRawSizes|TBuffer3D::kRaw;
00098    if (!buffer.SectionsValid(reqSections)) {
00099       return reqSections;
00100    }
00101 
00102    UInt_t i;
00103    Int_t i0, i1, i2;
00104 
00105    // Range pass
00106    if (view->GetAutoRange()) {
00107       Double_t x0, y0, z0, x1, y1, z1;
00108 
00109       x0 = x1 = buffer.fPnts[0];
00110       y0 = y1 = buffer.fPnts[1];
00111       z0 = z1 = buffer.fPnts[2];
00112       for (i=1; i<buffer.NbPnts(); i++) {
00113          i0 = 3*i; i1 = i0+1; i2 = i0+2;
00114          x0 = buffer.fPnts[i0] < x0 ? buffer.fPnts[i0] : x0;
00115          y0 = buffer.fPnts[i1] < y0 ? buffer.fPnts[i1] : y0;
00116          z0 = buffer.fPnts[i2] < z0 ? buffer.fPnts[i2] : z0;
00117          x1 = buffer.fPnts[i0] > x1 ? buffer.fPnts[i0] : x1;
00118          y1 = buffer.fPnts[i1] > y1 ? buffer.fPnts[i1] : y1;
00119          z1 = buffer.fPnts[i2] > z1 ? buffer.fPnts[i2] : z1;
00120       }
00121       view->SetRange(x0,y0,z0,x1,y1,z1,2);
00122    }
00123    // Actual drawing pass
00124    else {
00125       // Do not show semi transparent objects
00126       if (buffer.fTransparency > 50) {
00127          return TBuffer3D::kNone;
00128       }
00129       if (buffer.Type()== TBuffer3DTypes::kMarker ) {
00130          Double_t pndc[3], temp[3];
00131          for (i=0; i<buffer.NbPnts(); i++) {
00132             for ( i0=0; i0<3; i0++ ) temp[i0] = buffer.fPnts[3*i+i0];
00133             view->WCtoNDC(temp, pndc);
00134             fPad.PaintPolyMarker(1, &pndc[0], &pndc[1]);
00135          }
00136       } else {
00137          for (i=0; i<buffer.NbSegs(); i++) {
00138             i0 = 3*buffer.fSegs[3*i+1];
00139             Double_t *ptpoints_0 = &(buffer.fPnts[i0]);
00140             i0 = 3*buffer.fSegs[3*i+2];
00141             Double_t *ptpoints_3 = &(buffer.fPnts[i0]);
00142             fPad.PaintLine3D(ptpoints_0, ptpoints_3);
00143          }
00144       }
00145    }
00146 
00147    return TBuffer3D::kNone;
00148 }
00149 
00150 //______________________________________________________________________________
00151 Int_t TViewer3DPad::AddObject(UInt_t /*placedID*/, const TBuffer3D & buffer, Bool_t * addChildren)
00152 {
00153    // We don't support placed ID shapes - ID is discarded
00154    return AddObject(buffer,addChildren);
00155 }
00156 
00157 
00158 //______________________________________________________________________________
00159 Bool_t TViewer3DPad::OpenComposite(const TBuffer3D & /*buffer*/, Bool_t * /*addChildren*/) 
00160 {
00161    // Composite shapes not supported on this viewer currently - ignore.
00162    // Will result in a set of individual component shapes
00163    return kTRUE;
00164 };
00165 
00166 //______________________________________________________________________________
00167 void TViewer3DPad::CloseComposite() 
00168 {};
00169 
00170 //______________________________________________________________________________
00171 void TViewer3DPad::AddCompositeOp(UInt_t /*operation*/) 
00172 {};

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