Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
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-2021, 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 <cassert>
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
27
28////////////////////////////////////////////////////////////////////////////////
29/// Indicates if we prefer positions in local frame. Always false - pad
30/// drawing is always done in master frame.
31
33{
34 return kFALSE;
35}
36
37////////////////////////////////////////////////////////////////////////////////
38/// Open a scene on the viewer
39
41{
43
44 // Create a 3D view if none exists
45 TView *view = fPad.GetView();
46 if (!view) {
47 view = TView::CreateView(1, nullptr, nullptr); // Cartesian view by default
48 if (!view) {
50 return;
51 }
52 fPad.SetView(view);
53
54 // Set view to perform first auto-range (scaling) pass
55 view->SetAutoRange(kTRUE);
56 }
57
59}
60
61////////////////////////////////////////////////////////////////////////////////
62/// Close the scene on the viewer
63
65{
67
68 // If we are doing for auto-range pass on view invoke another pass
69 TView *view = fPad.GetView();
70 if (view) {
71 if (view->GetAutoRange()) {
72 view->SetAutoRange(kFALSE);
73 fPad.Paint();
74 }
75 }
76
78}
79
80////////////////////////////////////////////////////////////////////////////////
81/// Add an 3D object described by the buffer to the viewer. Returns flags
82/// to indicate:
83///
84/// 1. if extra sections of the buffer need completing.
85/// 2. if child objects of the buffer object should be added (always true)
86
88{
89 // Accept any children
90 if (addChildren) {
92 }
93
94 TView * view = fPad.GetView();
95 if (!view) {
97 return TBuffer3D::kNone;
98 }
99
101 if (!buffer.SectionsValid(reqSections)) {
102 return reqSections;
103 }
104
105 UInt_t i;
106 Int_t i0, i1, i2;
107
108 // Range pass
109 if (view->GetAutoRange()) {
110 Double_t x0, y0, z0, x1, y1, z1;
111
112 x0 = x1 = buffer.fPnts[0];
113 y0 = y1 = buffer.fPnts[1];
114 z0 = z1 = buffer.fPnts[2];
115 for (i=1; i<buffer.NbPnts(); i++) {
116 i0 = 3*i; i1 = i0+1; i2 = i0+2;
117 x0 = buffer.fPnts[i0] < x0 ? buffer.fPnts[i0] : x0;
118 y0 = buffer.fPnts[i1] < y0 ? buffer.fPnts[i1] : y0;
119 z0 = buffer.fPnts[i2] < z0 ? buffer.fPnts[i2] : z0;
120 x1 = buffer.fPnts[i0] > x1 ? buffer.fPnts[i0] : x1;
121 y1 = buffer.fPnts[i1] > y1 ? buffer.fPnts[i1] : y1;
122 z1 = buffer.fPnts[i2] > z1 ? buffer.fPnts[i2] : z1;
123 }
124 view->SetRange(x0,y0,z0,x1,y1,z1,2);
125 }
126 // Actual drawing pass
127 else {
128 // Do not show semi transparent objects
129 if (buffer.fTransparency > 50) {
130 return TBuffer3D::kNone;
131 }
132 if (buffer.Type()== TBuffer3DTypes::kMarker ) {
133 Double_t pndc[3], temp[3];
134 for (i=0; i<buffer.NbPnts(); i++) {
135 for ( i0=0; i0<3; i0++ ) temp[i0] = buffer.fPnts[3*i+i0];
136 view->WCtoNDC(temp, pndc);
137 fPad.PaintPolyMarker(1, &pndc[0], &pndc[1]);
138 }
139 } else {
140 for (i=0; i<buffer.NbSegs(); i++) {
141 i0 = 3*buffer.fSegs[3*i+1];
142 Double_t *ptpoints_0 = &(buffer.fPnts[i0]);
143 i0 = 3*buffer.fSegs[3*i+2];
144 Double_t *ptpoints_3 = &(buffer.fPnts[i0]);
146 }
147 }
148 }
149
150 return TBuffer3D::kNone;
151}
152
153////////////////////////////////////////////////////////////////////////////////
154/// We don't support placed ID shapes - ID is discarded
155
157{
158 return AddObject(buffer,addChildren);
159}
160
161////////////////////////////////////////////////////////////////////////////////
162/// Composite shapes not supported on this viewer currently - ignore.
163/// Will result in a set of individual component shapes
164
165Bool_t TViewer3DPad::OpenComposite(const TBuffer3D & /*buffer*/, Bool_t * /*addChildren*/)
166{
167 return kTRUE;
168}
169
170////////////////////////////////////////////////////////////////////////////////
171
175
176////////////////////////////////////////////////////////////////////////////////
177
179{
180}
constexpr Bool_t kFALSE
Definition RtypesCore.h:108
constexpr Bool_t kTRUE
Definition RtypesCore.h:107
ROOT::Detail::TRangeCast< T, true > TRangeDynCast
TRangeDynCast is an adapter class that allows the typed iteration through a TCollection.
Option_t Option_t TPoint TPoint const char x1
Option_t Option_t TPoint TPoint const char y1
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
Int_t * fSegs
Definition TBuffer3D.h:114
Short_t fTransparency
Definition TBuffer3D.h:89
Double_t * fPnts
Definition TBuffer3D.h:113
See TView3D.
Definition TView.h:25
virtual void WCtoNDC(const Float_t *pw, Float_t *pn)=0
static TView * CreateView(Int_t system=1, const Double_t *rmin=nullptr, const Double_t *rmax=nullptr)
Create a concrete default 3-d view via the plug-in manager.
Definition TView.cxx:26
virtual Bool_t GetAutoRange()=0
virtual void SetAutoRange(Bool_t autorange=kTRUE)=0
virtual void SetRange(const Double_t *min, const Double_t *max)=0
Int_t AddObject(const TBuffer3D &buffer, Bool_t *addChildren=nullptr) override
Add an 3D object described by the buffer to the viewer.
Bool_t PreferLocalFrame() const override
Indicates if we prefer positions in local frame.
void EndScene() override
Close the scene on the viewer.
Bool_t fBuilding
is scene being built?
void CloseComposite() override
Bool_t OpenComposite(const TBuffer3D &buffer, Bool_t *addChildren=nullptr) override
Composite shapes not supported on this viewer currently - ignore.
TVirtualPad & fPad
the pad we paint into.
void BeginScene() override
Open a scene on the viewer.
void AddCompositeOp(UInt_t operation) override
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 SetView(TView *view=nullptr)=0
void Paint(Option_t *option="") override=0
This method must be overridden if a class wants to paint itself.
virtual TView * GetView() const =0