Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
REveRenderData.cxx
Go to the documentation of this file.
1// @(#)root/eve7:$Id$
2// Authors: Matevz Tadel & Alja Mrak-Tadel: 2006, 2007, 2018
3
4/*************************************************************************
5 * Copyright (C) 1995-2019, 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
13#include <ROOT/REveUtil.hxx>
14
15#include <cstdio>
16#include <cstring>
17
18using namespace ROOT::Experimental;
19
20/////////////////////////////////////////////////////////////////////////////////////////
21/// Constructor
22
23REveRenderData::REveRenderData(const std::string &func, int size_vert, int size_norm, int size_idx) :
24 fRnrFunc(func)
25{
26 Reserve(size_vert, size_norm, size_idx);
27}
28
29/////////////////////////////////////////////////////////////////////////////////////////
30/// Reserve place for render data
31
32void REveRenderData::Reserve(int size_vert, int size_norm, int size_idx)
33{
34 if (size_vert > 0)
35 fVertexBuffer.reserve(size_vert);
36 if (size_norm > 0)
37 fNormalBuffer.reserve(size_norm);
38 if (size_idx > 0)
39 fIndexBuffer.reserve(size_idx);
40}
41
42/////////////////////////////////////////////////////////////////////////////////////////
43/// Write render data to binary buffer
44
45int REveRenderData::Write(char *msg, int maxlen)
46{
47 static const REveException eh("REveRenderData::Write ");
48
49 int off{0};
50
51 auto append = [&](void *buf, int len) {
52 if (off + len > maxlen)
53 throw eh + "output buffer does not have enough memory";
54 memcpy(msg + off, buf, len);
55 off += len;
56 };
57
58 if (!fMatrix.empty())
59 append(&fMatrix[0], fMatrix.size() * sizeof(float));
60
61 if (!fVertexBuffer.empty())
62 append(&fVertexBuffer[0], fVertexBuffer.size() * sizeof(float));
63
64 if (!fNormalBuffer.empty())
65 append(&fNormalBuffer[0], fNormalBuffer.size() * sizeof(float));
66
67 if (!fIndexBuffer.empty())
68 append(&fIndexBuffer[0], fIndexBuffer.size() * sizeof(int));
69
70 return off;
71}
72
73/////////////////////////////////////////////////////////////////////////////////////////
74/// Set transformation matrix
75
76void REveRenderData::SetMatrix(const double *arr)
77{
78 fMatrix.reserve(16);
79 for (int i = 0; i < 16; ++i) {
80 fMatrix.push_back(arr[i]);
81 }
82}
83
84/////////////////////////////////////////////////////////////////////////////////////////
85/// Calculate texture dimensions to hold nel elements with given alignment on x axis.
86/// Static function.
87///
88/// Implementation could be improved -- now it simply goes for near-square-root(size)
89/// dimensions that satisfy the alignment requirement.
90
91void REveRenderData::CalcTextureSize(int nel, int align, int &sx, int &sy)
92{
93 if (nel <= 0) { sx = sy = 0; return; }
94
95 sx = (int) std::ceil(std::sqrt(nel));
96 int rx = sx % align;
97 if (rx > 0) sx += align - rx;
98 sy = nel / sx;
99 if (nel % sx > 0) sy += 1;
100}
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 Float_t Float_t Int_t Int_t UInt_t UInt_t Rectangle_t Int_t Int_t Window_t TString Int_t GCValues_t GetPrimarySelectionOwner GetDisplay GetScreen GetColormap GetNativeEvent const char const char dpyName wid window const char font_name cursor keysym reg const char only_if_exist regb h Point_t winding char text const char depth char const char Int_t count const char ColorStruct_t color const char Pixmap_t Pixmap_t PictureAttributes_t attr const char char ret_data h unsigned char height h Atom_t Int_t ULong_t ULong_t unsigned char prop_list Atom_t Atom_t Atom_t Time_t UChar_t len
REveException Exception-type thrown by Eve classes.
Definition REveTypes.hxx:41
void Reserve(int size_vert=0, int size_norm=0, int size_idx=0)
Reserve place for render data.
int Write(char *msg, int maxlen)
Write render data to binary buffer.
static void CalcTextureSize(int nel, int align, int &sx, int &sy)
Calculate texture dimensions to hold nel elements with given alignment on x axis.
void SetMatrix(const double *arr)
Set transformation matrix.