This file is indexed.

/usr/include/root/TGLMarchingCubes.h is in libroot-graf3d-gl-dev 5.34.14-1build1.

This file is owned by root:root, with mode 0o644.

The actual contents of the file can be viewed below.

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
// @(#)root/gl:$Id$
// Author:  Timur Pocheptsov  06/01/2009

/*************************************************************************
 * Copyright (C) 1995-2009, Rene Brun and Fons Rademakers.               *
 * All rights reserved.                                                  *
 *                                                                       *
 * For the licensing terms see $ROOTSYS/LICENSE.                         *
 * For the list of contributors see $ROOTSYS/README/CREDITS.             *
 *************************************************************************/

#ifndef ROOT_TGLMarchingCubes
#define ROOT_TGLMarchingCubes

#include <vector>

#ifndef ROOT_TH3
#include "TH3.h"
#endif

#ifndef ROOT_TGLIsoMesh
#include "TGLIsoMesh.h"
#endif
#ifndef ROOT_TKDEAdapter
#include "TKDEAdapter.h"
#endif

/*
Implementation of "marching cubes" algortihm for GL module. Used by
TGLTF3Painter and TGLIsoPainter.
Good and clear algorithm explanation can be found here:
http://local.wasp.uwa.edu.au/~pbourke/geometry/polygonise/
*/

class TF3;
class TKDEFGT;

namespace Rgl {
namespace Mc {

/*
Some routines, values and tables for marching cube method.
*/
extern const UInt_t  eInt[256];
extern const Float_t vOff[8][3];
extern const UChar_t eConn[12][2];
extern const Float_t eDir[12][3];
extern const Int_t   conTbl[256][16];

/*
"T" prefix in class names is only for code-style checker.
*/

/*
TCell is a cube from marching cubes algorithm.
It has "type" - defines, which vertices
are under iso level, which are above.

Vertices numeration:

           |z
           |
           4____________7
          /|           /|
         / |          / |
        /  |         /  |
       /   |        /   |
      5____|_______6    |
      |    0_______|____3______ y
      |   /        |   /
      |  /         |  /
      | /          | /
      |/           |/
      1____________2
     /
    /x

TCell's "type" is 8-bit number, one bit per vertex.
So, if vertex 1 and 2 are under iso-surface, type
will be:

 7 6 5 4 3 2 1 0 (bit number)
[0 0 0 0 0 1 1 0] bit pattern

type == 6.

Edges numeration:

           |z
           |
           |_____7______
          /|           /|
         / |          / |
       4/  8         6  11
       /   |        /   |
      /____|5______/    |
      |    |_____3_|____|______ y
      |   /        |   /
      9  /        10  /
      | /0         | /2
      |/           |/
      /____________/
     /      1
    /x

There are 12 edges, any of them can be intersected by iso-surface
(not all 12 simultaneously). Edge's intersection is a vertex in
iso-mesh's vertices array, cell holds index of this vertex in
fIds array.
fVals holds "scalar field" or density values in vertices [0, 7].

"V" parameter is the type to hold such values.
*/

template<class V>
class TCell {
public:
   TCell() : fType(), fIds(), fVals()
   {
      //TCell ctor.
      //Such mem-initializer list can produce
      //warnings with some versions of MSVC,
      //but this list is what I want.
   }

   UInt_t     fType;
   UInt_t     fIds[12];
   V          fVals[8];
};

/*
TSlice of marching cubes' grid. Has W * H cells.
If you have TH3 hist, GetNbinsX() is W and GetNbinsY() is H.
*/
template<class V>
class TSlice {
public:
   TSlice()
   {
   }

   void ResizeSlice(UInt_t w, UInt_t h)
   {
      fCells.resize(w * h);
   }

   std::vector<TCell<V> > fCells;
private:
   TSlice(const TSlice &rhs);
   TSlice & operator = (const TSlice &rhs);
};

/*
Mesh builder requires generic "data source": it can
be a wrapped TH3 object, a wrapped TF3 object or some
"density estimator" object.
Mesh builder inherits this data source type.

TH3Adapter is one of such data sources.
It has _direct_ access to TH3 internal data.
GetBinContent(i, j, k) is a virtual function
and it calls two other virtual functions - this
is very expensive if you call GetBinContent
several million times as I do in marching cubes.

"H" parameter is one of TH3 classes,
"E" is the type of internal data.

For example, H == TH3C, E == Char_t.
*/

template<class H, class E>
class TH3Adapter {
protected:

   typedef E    ElementType_t;

   TH3Adapter()
      : fSrc(0), fW(0), fH(0), fD(0), fSliceSize(0)
   {
   }

   UInt_t GetW()const
   {
      return fW - 2;
   }

   UInt_t GetH()const
   {
      return fH - 2;
   }

   UInt_t GetD()const
   {
      return fD - 2;
   }

   void SetDataSource(const H *hist)
   {
      fSrc = hist->GetArray();
      fW   = hist->GetNbinsX() + 2;
      fH   = hist->GetNbinsY() + 2;
      fD   = hist->GetNbinsZ() + 2;
      fSliceSize = fW * fH;
   }

   void FetchDensities()const{}//Do nothing.

   ElementType_t GetData(UInt_t i, UInt_t j, UInt_t k)const
   {
      i += 1;
      j += 1;
      k += 1;
      return fSrc[k * fSliceSize + j * fW + i];
   }

   const ElementType_t *fSrc;
   UInt_t fW;
   UInt_t fH;
   UInt_t fD;
   UInt_t fSliceSize;
};

/*
TF3Adapter. Lets TMeshBuilder to use TF3 as a 3d array.
TF3Adapter, TF3EdgeSplitter (see below) and TMeshBuilder<TF3, ValueType>
need TGridGeometry<ValueType>, so TGridGeometry is a virtual base.
*/

class TF3Adapter : protected virtual TGridGeometry<Double_t> {
protected:
   typedef Double_t ElementType_t;

   TF3Adapter() : fTF3(0), fW(0), fH(0), fD(0)
   {
   }

   UInt_t GetW()const
   {
      return fW;
   }

   UInt_t GetH()const
   {
      return fH;
   }

   UInt_t GetD()const
   {
      return fD;
   }

   void SetDataSource(const TF3 *f);

   void FetchDensities()const{}//Do nothing.

   Double_t GetData(UInt_t i, UInt_t j, UInt_t k)const;

   const TF3 *fTF3;//TF3 data source.
   //TF3 grid's dimensions.
   UInt_t     fW;
   UInt_t     fH;
   UInt_t     fD;
};

/*
TSourceAdapterSelector is aux. class used by TMeshBuilder to
select "data-source" base depending on data-source type.
*/
template<class> class TSourceAdapterSelector;

template<>
class TSourceAdapterSelector<TH3C> {
public:
   typedef TH3Adapter<TH3C, Char_t> Type_t;
};

template<>
class TSourceAdapterSelector<TH3S> {
public:
   typedef TH3Adapter<TH3S, Short_t> Type_t;
};

template<>
class TSourceAdapterSelector<TH3I> {
public:
   typedef TH3Adapter<TH3I, Int_t> Type_t;
};

template<>
class TSourceAdapterSelector<TH3F> {
public:
   typedef TH3Adapter<TH3F, Float_t> Type_t;
};

template<>
class TSourceAdapterSelector<TH3D> {
public:
   typedef TH3Adapter<TH3D, Double_t> Type_t;
};

template<>
class TSourceAdapterSelector<TF3> {
public:
   typedef TF3Adapter Type_t;
};

template<>
class TSourceAdapterSelector<TKDEFGT> {
public:
   typedef Fgt::TKDEAdapter Type_t;
};

/*
Edge splitter is the second base class for TMeshBuilder.
Its task is to split cell's edge by adding new vertex
into mesh.
Default splitter is used by TH3 and KDE.
*/

template<class E, class V>
V GetOffset(E val1, E val2, V iso)
{
   const V delta = val2 - val1;
   if (!delta)
      return 0.5f;
   return (iso - val1) / delta;
}

template<class H, class E, class V>
class TDefaultSplitter : protected virtual TGridGeometry<V> {
protected:
   void SetNormalEvaluator(const H * /*source*/)
   {
   }
   void SplitEdge(TCell<E> & cell, TIsoMesh<V> * mesh, UInt_t i,
                  V x, V y, V z, V iso)const
{
   V v[3];
   const V offset = GetOffset(cell.fVals[eConn[i][0]],
                              cell.fVals[eConn[i][1]],
                              iso);
   v[0] = x + (vOff[eConn[i][0]][0] + offset * eDir[i][0]) * this->fStepX;
   v[1] = y + (vOff[eConn[i][0]][1] + offset * eDir[i][1]) * this->fStepY;
   v[2] = z + (vOff[eConn[i][0]][2] + offset * eDir[i][2]) * this->fStepZ;
   cell.fIds[i] = mesh->AddVertex(v);
}


};

/*
TF3's edge splitter. Calculates new vertex and surface normal
in this vertex using TF3.
*/

class TF3EdgeSplitter : protected virtual TGridGeometry<Double_t> {
protected:
   TF3EdgeSplitter() : fTF3(0)
   {
   }

   void SetNormalEvaluator(const TF3 *tf3)
   {
      fTF3 = tf3;
   }

   void SplitEdge(TCell<Double_t> & cell, TIsoMesh<Double_t> * mesh, UInt_t i,
                  Double_t x, Double_t y, Double_t z, Double_t iso)const;

   const TF3 *fTF3;
};

/*
TSplitterSelector is aux. class to select "edge-splitter" base
for TMeshBuilder.
*/

template<class, class> class TSplitterSelector;

template<class V>
class TSplitterSelector<TH3C, V> {
public:
   typedef TDefaultSplitter<TH3C, Char_t, V> Type_t;
};

template<class V>
class TSplitterSelector<TH3S, V> {
public:
   typedef TDefaultSplitter<TH3S, Short_t, V> Type_t;
};

template<class V>
class TSplitterSelector<TH3I, V> {
public:
   typedef TDefaultSplitter<TH3I, Int_t, V> Type_t;
};

template<class V>
class TSplitterSelector<TH3F, V> {
public:
   typedef TDefaultSplitter<TH3F, Float_t, V> Type_t;
};

template<class V>
class TSplitterSelector<TH3D, V> {
public:
   typedef TDefaultSplitter<TH3D, Double_t, V> Type_t;
};

template<class V>
class TSplitterSelector<TKDEFGT, V> {
public:
   typedef TDefaultSplitter<TKDEFGT, Float_t, Float_t> Type_t;
};

template<class V>
class TSplitterSelector<TF3, V> {
public:
   typedef TF3EdgeSplitter Type_t;
};

/*
Mesh builder. Polygonizes scalar field - TH3, TF3 or
something else (some density estimator as data-source).

ValueType is Float_t or Double_t - the type of vertex'
x,y,z components.
*/

template<class DataSource, class ValueType>
class TMeshBuilder : public TSourceAdapterSelector<DataSource>::Type_t,
                     public TSplitterSelector<DataSource, ValueType>::Type_t
{
private:
   //Two base classes.
   typedef typename TSourceAdapterSelector<DataSource>::Type_t       DataSourceBase_t;
   typedef typename TSplitterSelector<DataSource, ValueType>::Type_t SplitterBase_t;
   //Using declarations required, since these are
   //type-dependant names in template.
   using DataSourceBase_t::GetW;
   using DataSourceBase_t::GetH;
   using DataSourceBase_t::GetD;
   using DataSourceBase_t::GetData;
   using SplitterBase_t::SplitEdge;

   typedef typename DataSourceBase_t::ElementType_t ElementType_t;

   typedef TCell<ElementType_t>  CellType_t;
   typedef TSlice<ElementType_t> SliceType_t;
   typedef TIsoMesh<ValueType>   MeshType_t;

public:
   TMeshBuilder(Bool_t averagedNormals, ValueType eps = 1e-7)
      : fAvgNormals(averagedNormals), fMesh(0), fIso(), fEpsilon(eps)
   {
   }

   void BuildMesh(const DataSource *src, const TGridGeometry<ValueType> &geom,
                  MeshType_t *mesh, ValueType iso);

private:

   Bool_t      fAvgNormals;
   SliceType_t fSlices[2];
   MeshType_t *fMesh;
   ValueType   fIso;
   ValueType   fEpsilon;

   void NextStep(UInt_t depth, const SliceType_t *prevSlice,
                 SliceType_t *curr)const;

   void BuildFirstCube(SliceType_t *slice)const;
   void BuildRow(SliceType_t *slice)const;
   void BuildCol(SliceType_t *slice)const;
   void BuildSlice(SliceType_t *slice)const;
   void BuildFirstCube(UInt_t depth, const SliceType_t *prevSlice,
                       SliceType_t *slice)const;
   void BuildRow(UInt_t depth, const SliceType_t *prevSlice,
                 SliceType_t *slice)const;
   void BuildCol(UInt_t depth, const SliceType_t *prevSlice,
                 SliceType_t *slice)const;
   void BuildSlice(UInt_t depth, const SliceType_t *prevSlice,
                   SliceType_t *slice)const;

   void BuildNormals()const;

   TMeshBuilder(const TMeshBuilder &rhs);
   TMeshBuilder & operator = (const TMeshBuilder &rhs);
};

}//namespace Mc
}//namespace Rgl

#endif