Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
REveSMorph.cxx
Go to the documentation of this file.
1// @(#)root/eve7:$Id$
2// Author: Matevz Tadel
3
4/*************************************************************************
5 * Copyright (C) 1995-2025, 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 <ROOT/REveSMorph.hxx>
14#include <ROOT/REveTrans.hxx>
15
16#include <cmath>
17
18using namespace ROOT::Experimental;
19
20/** \class REveSMorph
21\ingroup REve
22A parametric, texture-mapped surface of spherical topology: a sphere that can
23be twisted, pinched and sheared, and cut down to a patch in theta and phi.
24Ported from Gled, whose parameter names it keeps.
25
26The geometry is built on the client, by `makeSMorph` in EveElementsRCore.js.
27The surface is textured and `REveRenderData` has no channel for texture
28coordinates, so only the parameters are streamed.
29
30The surface is generated at unit size. Radius, position and orientation are
31in the element's transformation, so changing them streams one matrix under
32kCBTrans and the client rebuilds nothing. Every other setter stamps
33kCBObjProps and forces a rebuild.
34
35The parametrisation, with ct = cos(theta), st = sin(theta):
36
37 twist = ct * fTx, conv = ct * fCx
38 x = ct
39 y = (1 + conv) * st * cos(phi + twist)
40 z = (1 + conv) * st * sin(phi + twist)
41
42followed by a rotation about z through x * fRz, which shears the body along
43its polar axis. The polar axis is x, as in the original. The normal is the
44normalised position, which is exact for the unmorphed sphere and approximate
45for small fTx, fCx and fRz.
46
47Texture coordinates:
48
49 u = fTexX0 + fTexXC * phi / 2pi
50 v = fTexY0 + fTexYC * acos(ct) / pi
51
52A non-zero fTexYOff adds int(v) * fTexYOff to u, which offsets successive
53wraps into a brick bond.
54
55Worked example: `tutorials/visualisation/eve7/boing.C`.
56*/
57
58////////////////////////////////////////////////////////////////////////////////
59/// Constructor. Points the main colour at fColor.
60
61REveSMorph::REveSMorph(const std::string &n, const std::string &t) : REveElement(n, t)
62{
64}
65
66////////////////////////////////////////////////////////////////////////////////
67/// Uniform scale on the main transformation. Stamps kCBTrans only: the
68/// surface is built at unit size, so the client rebuilds nothing.
69
75
76////////////////////////////////////////////////////////////////////////////////
77/// Stream the shape and texture parameters and the bounding box.
78
79Int_t REveSMorph::WriteCoreJson(nlohmann::json &j, Int_t rnr_offset)
80{
81 Int_t ret = REveElement::WriteCoreJson(j, rnr_offset);
82
83 // clang-format off
84 j["fTLevel"] = fTLevel;
85 j["fPLevel"] = fPLevel;
86
87 j["fTx"] = fTx;
88 j["fCx"] = fCx;
89 j["fRz"] = fRz;
90
91 j["fThetaMin"] = fThetaMin;
92 j["fThetaMax"] = fThetaMax;
93 j["fPhiMean"] = fPhiMean;
94 j["fPhiRange"] = fPhiRange;
95 j["fEquiSurf"] = fEquiSurf;
96
97 j["fTexture"] = fTexture;
98 j["fTexX0"] = fTexX0;
99 j["fTexY0"] = fTexY0;
100 j["fTexXC"] = fTexXC;
101 j["fTexYC"] = fTexYC;
102 j["fTexYOff"] = fTexYOff;
103 // clang-format on
104
105 return ret;
106}
107
108////////////////////////////////////////////////////////////////////////////////
109/// Bounding box: the unit cube in the element's own frame. It does not follow
110/// the morph, so fCx > 0 can push the surface outside it. Tracking the morph
111/// would rescale the 3D axis, which takes its extent from the scene box, while
112/// the fCx slider is dragged.
113
115{
116 BBoxInit();
117 // clang-format off
118 BBoxCheckPoint(-1.f, -1.f, -1.f);
119 BBoxCheckPoint( 1.f, 1.f, 1.f);
120 // clang-format on
121}
122
123////////////////////////////////////////////////////////////////////////////////
124/// Name the client factory makeSMorph. No geometry is written; the base call
125/// adds the transformation, and one vertex keeps the buffer non-empty.
126
128{
129 fRenderData = std::make_unique<REveRenderData>("makeSMorph");
131 fRenderData->PushV(0.f, 0.f, 0.f);
132}
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t Float_t r
void SetMainColorPtr(Color_t *colptr)
virtual REveTrans & RefMainTrans()
Return reference to main transformation.
virtual Int_t WriteCoreJson(nlohmann::json &cj, Int_t rnr_offset)
Write core json.
void BBoxCheckPoint(const REveVector &v)
std::unique_ptr< REveRenderData > fRenderData
! Vertex / normal / triangle index information for rendering.
void BBoxInit()
Start filling the bounding box with BBoxCheckPoint(): min at +infinity, max at -infinity,...
virtual void BuildRenderData()
Build fRenderData, what the client draws.
Float_t fThetaMax
theta to fThetaMax * pi
Float_t fCx
radial convergence, proportional to cos(theta)
Float_t fPhiMean
phi centred on fPhiMean * 2pi
Bool_t fEquiSurf
Space the theta rings by equal surface area rather than by equal angle, which keeps the quads near th...
Float_t fRz
shear about z, proportional to x
Color_t fColor
Surface colour, multiplied by the texture where there is one.
Float_t fPhiRange
phi spanning fPhiRange * 2pi; 1 closes the seam
Float_t fTx
twist of phi, proportional to cos(theta)
void SetRadius(Float_t r)
Uniform scale on the main transformation.
std::string fTexture
File name under ui5/eve7/textures/. Empty draws in the main colour.
void BuildRenderData() override
Name the client factory makeSMorph.
Float_t fTexYOff
u shift per whole v, for a brick bond
void ComputeBBox() override
Bounding box: the unit cube in the element's own frame.
Float_t fTexXC
u wraps per turn in phi
Int_t fPLevel
divisions in phi
Int_t WriteCoreJson(nlohmann::json &j, Int_t rnr_offset) override
Stream the shape and texture parameters and the bounding box.
Int_t fTLevel
divisions in theta
Float_t fThetaMin
theta from fThetaMin * pi
Float_t fTexYC
v wraps per sweep in theta
void SetScale(Double_t sx, Double_t sy, Double_t sz)
Set scaling.
const Int_t n
Definition legend1.C:16
Namespace for ROOT features in testing.
Definition TROOT.h:100