Logo ROOT  
Reference Guide
TViewer3DPad.cxx
Go to the documentation of this file.
1// @(#)root/base:$Id$
2// Author: Richard Maunder 10/3/2005
3
4/*************************************************************************
5 * Copyright (C) 1995-2000, 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 "TViewer3DPad.h"
13#include "TVirtualPad.h"
14#include "TView.h"
15#include "TBuffer3D.h"
16#include "TBuffer3DTypes.h"
17
18#include <assert.h>
19
20/** \class TViewer3DPad
21\ingroup gpad
22
23Provides 3D viewer interface (TVirtualViewer3D) support on a pad.
24Will be merged with TView / TView3D eventually.
25*/
26
28
29////////////////////////////////////////////////////////////////////////////////
30/// Indicates if we prefer positions in local frame. Always false - pad
31/// drawing is always done in master frame.
32
34{
35 return kFALSE;
36}
37
38////////////////////////////////////////////////////////////////////////////////
39/// Open a scene on the viewer
40
42{
43 assert(!fBuilding);
44
45 // Create a 3D view if none exists
46 TView *view = fPad.GetView();
47 if (!view) {
48 view = TView::CreateView(1,0,0); // Cartesian view by default
49 if (!view) {
50 assert(kFALSE);
51 return;
52 }
53 fPad.SetView(view);
54
55 // Set view to perform first auto-range (scaling) pass
56 view->SetAutoRange(kTRUE);
57 }
58
60}
61
62////////////////////////////////////////////////////////////////////////////////
63/// Close the scene on the viewer
64
66{
67 assert(fBuilding);
68
69 // If we are doing for auto-range pass on view invoke another pass
70 TView *view = fPad.GetView();
71 if (view) {
72 if (view->GetAutoRange()) {
73 view->SetAutoRange(kFALSE);
74 fPad.Paint();
75 }
76 }
77
79}
80
81////////////////////////////////////////////////////////////////////////////////
82/// Add an 3D object described by the buffer to the viewer. Returns flags
83/// to indicate:
84///
85/// 1. if extra sections of the buffer need completing.
86/// 2. if child objects of the buffer object should be added (always true)
87
88Int_t TViewer3DPad::AddObject(const TBuffer3D & buffer, Bool_t * addChildren)
89{
90 // Accept any children
91 if (addChildren) {
92 *addChildren = kTRUE;
93 }
94
95 TView * view = fPad.GetView();
96 if (!view) {
97 assert(kFALSE);
98 return TBuffer3D::kNone;
99 }
100
102 if (!buffer.SectionsValid(reqSections)) {
103 return reqSections;
104 }
105
106 UInt_t i;
107 Int_t i0, i1, i2;
108
109 // Range pass
110 if (view->GetAutoRange()) {
111 Double_t x0, y0, z0, x1, y1, z1;
112
113 x0 = x1 = buffer.fPnts[0];
114 y0 = y1 = buffer.fPnts[1];
115 z0 = z1 = buffer.fPnts[2];
116 for (i=1; i<buffer.NbPnts(); i++) {
117 i0 = 3*i; i1 = i0+1; i2 = i0+2;
118 x0 = buffer.fPnts[i0] < x0 ? buffer.fPnts[i0] : x0;
119 y0 = buffer.fPnts[i1] < y0 ? buffer.fPnts[i1] : y0;
120 z0 = buffer.fPnts[i2] < z0 ? buffer.fPnts[i2] : z0;
121 x1 = buffer.fPnts[i0] > x1 ? buffer.fPnts[i0] : x1;
122 y1 = buffer.fPnts[i1] > y1 ? buffer.fPnts[i1] : y1;
123 z1 = buffer.fPnts[i2] > z1 ? buffer.fPnts[i2] : z1;
124 }
125 view->SetRange(x0,y0,z0,x1,y1,z1,2);
126 }
127 // Actual drawing pass
128 else {
129 // Do not show semi transparent objects
130 if (buffer.fTransparency > 50) {
131 return TBuffer3D::kNone;
132 }
133 if (buffer.Type()== TBuffer3DTypes::kMarker ) {
134 Double_t pndc[3], temp[3];
135 for (i=0; i<buffer.NbPnts(); i++) {
136 for ( i0=0; i0<3; i0++ ) temp[i0] = buffer.fPnts[3*i+i0];
137 view->WCtoNDC(temp, pndc);
138 fPad.PaintPolyMarker(1, &pndc[0], &pndc[1]);
139 }
140 } else {
141 for (i=0; i<buffer.NbSegs(); i++) {
142 i0 = 3*buffer.fSegs[3*i+1];
143 Double_t *ptpoints_0 = &(buffer.fPnts[i0]);
144 i0 = 3*buffer.fSegs[3*i+2];
145 Double_t *ptpoints_3 = &(buffer.fPnts[i0]);
146 fPad.PaintLine3D(ptpoints_0, ptpoints_3);
147 }
148 }
149 }
150
151 return TBuffer3D::kNone;
152}
153
154////////////////////////////////////////////////////////////////////////////////
155/// We don't support placed ID shapes - ID is discarded
156
157Int_t TViewer3DPad::AddObject(UInt_t /*placedID*/, const TBuffer3D & buffer, Bool_t * addChildren)
158{
159 return AddObject(buffer,addChildren);
160}
161
162////////////////////////////////////////////////////////////////////////////////
163/// Composite shapes not supported on this viewer currently - ignore.
164/// Will result in a set of individual component shapes
165
166Bool_t TViewer3DPad::OpenComposite(const TBuffer3D & /*buffer*/, Bool_t * /*addChildren*/)
167{
168 return kTRUE;
169};
170
171////////////////////////////////////////////////////////////////////////////////
172
174{};
175
176////////////////////////////////////////////////////////////////////////////////
177
179{};
static const double x1[5]
const Bool_t kFALSE
Definition: RtypesCore.h:90
double Double_t
Definition: RtypesCore.h:57
const Bool_t kTRUE
Definition: RtypesCore.h:89
#define ClassImp(name)
Definition: Rtypes.h:361
Generic 3D primitive description class.
Definition: TBuffer3D.h:18
Int_t Type() const
Definition: TBuffer3D.h:85
UInt_t NbPnts() const
Definition: TBuffer3D.h:80
UInt_t NbSegs() const
Definition: TBuffer3D.h:81
Bool_t SectionsValid(UInt_t mask) const
Definition: TBuffer3D.h:67
@ kRawSizes
Definition: TBuffer3D.h:53
Int_t * fSegs
Definition: TBuffer3D.h:113
Short_t fTransparency
Definition: TBuffer3D.h:89
Double_t * fPnts
Definition: TBuffer3D.h:112
See TView3D.
Definition: TView.h:25
virtual void WCtoNDC(const Float_t *pw, Float_t *pn)=0
virtual Bool_t GetAutoRange()=0
virtual void SetAutoRange(Bool_t autorange=kTRUE)=0
static TView * CreateView(Int_t system=1, const Double_t *rmin=0, const Double_t *rmax=0)
Create a concrete default 3-d view via the plug-in manager.
Definition: TView.cxx:27
virtual void SetRange(const Double_t *min, const Double_t *max)=0
Provides 3D viewer interface (TVirtualViewer3D) support on a pad.
Definition: TViewer3DPad.h:20
virtual Bool_t OpenComposite(const TBuffer3D &buffer, Bool_t *addChildren=0)
Composite shapes not supported on this viewer currently - ignore.
virtual Int_t AddObject(const TBuffer3D &buffer, Bool_t *addChildren=0)
Add an 3D object described by the buffer to the viewer.
virtual void AddCompositeOp(UInt_t operation)
virtual void BeginScene()
Open a scene on the viewer.
Bool_t fBuilding
is scene being built?
Definition: TViewer3DPad.h:23
virtual void CloseComposite()
TVirtualPad & fPad
the pad we paint into.
Definition: TViewer3DPad.h:22
virtual Bool_t PreferLocalFrame() const
Indicates if we prefer positions in local frame.
virtual void EndScene()
Close the scene on the viewer.
virtual void PaintLine3D(Float_t *p1, Float_t *p2)=0
virtual void PaintPolyMarker(Int_t n, Float_t *x, Float_t *y, Option_t *option="")=0
virtual void Paint(Option_t *option="")=0
This method must be overridden if a class wants to paint itself.
virtual void SetView(TView *view=0)=0
virtual TView * GetView() const =0