12 #ifndef ROOT_TGLMarchingCubes
13 #define ROOT_TGLMarchingCubes
38 extern const UInt_t eInt[256];
39 extern const Float_t vOff[8][3];
40 extern const UChar_t eConn[12][2];
41 extern const Float_t eDir[12][3];
42 extern const Int_t conTbl[256][16];
112 TCell() : fType(), fIds(), fVals()
136 void ResizeSlice(UInt_t w, UInt_t h)
138 fCells.resize(w * h);
141 std::vector<TCell<V> > fCells;
143 TSlice(
const TSlice &rhs);
144 TSlice & operator = (
const TSlice &rhs);
166 template<
class H,
class E>
170 typedef E ElementType_t;
173 : fSrc(0), fW(0), fH(0), fD(0), fSliceSize(0)
192 void SetDataSource(
const H *hist)
194 fSrc = hist->GetArray();
195 fW = hist->GetNbinsX() + 2;
196 fH = hist->GetNbinsY() + 2;
197 fD = hist->GetNbinsZ() + 2;
198 fSliceSize = fW * fH;
201 void FetchDensities()
const{}
203 ElementType_t GetData(UInt_t i, UInt_t j, UInt_t k)
const
208 return fSrc[k * fSliceSize + j * fW + i];
211 const ElementType_t *fSrc;
224 class TF3Adapter :
protected virtual TGridGeometry<Double_t> {
226 typedef Double_t ElementType_t;
228 TF3Adapter() : fTF3(0), fW(0), fH(0), fD(0)
247 void SetDataSource(
const TF3 *f);
249 void FetchDensities()
const{}
251 Double_t GetData(UInt_t i, UInt_t j, UInt_t k)
const;
264 template<
class>
class TSourceAdapterSelector;
267 class TSourceAdapterSelector<TH3C> {
269 typedef TH3Adapter<TH3C, Char_t> Type_t;
273 class TSourceAdapterSelector<TH3S> {
275 typedef TH3Adapter<TH3S, Short_t> Type_t;
279 class TSourceAdapterSelector<TH3I> {
281 typedef TH3Adapter<TH3I, Int_t> Type_t;
285 class TSourceAdapterSelector<TH3F> {
287 typedef TH3Adapter<TH3F, Float_t> Type_t;
291 class TSourceAdapterSelector<TH3D> {
293 typedef TH3Adapter<TH3D, Double_t> Type_t;
297 class TSourceAdapterSelector<TF3> {
299 typedef TF3Adapter Type_t;
303 class TSourceAdapterSelector<TKDEFGT> {
305 typedef Fgt::TKDEAdapter Type_t;
315 template<
class E,
class V>
316 V GetOffset(E val1, E val2, V iso)
318 const V delta = val2 - val1;
321 return (iso - val1) / delta;
324 template<
class H,
class E,
class V>
325 class TDefaultSplitter :
protected virtual TGridGeometry<V> {
327 void SetNormalEvaluator(
const H * )
330 void SplitEdge(TCell<E> & cell, TIsoMesh<V> * mesh, UInt_t i,
331 V x, V y, V z, V iso)
const
334 const V offset = GetOffset(cell.fVals[eConn[i][0]],
335 cell.fVals[eConn[i][1]],
337 v[0] = x + (vOff[eConn[i][0]][0] + offset * eDir[i][0]) * this->fStepX;
338 v[1] = y + (vOff[eConn[i][0]][1] + offset * eDir[i][1]) * this->fStepY;
339 v[2] = z + (vOff[eConn[i][0]][2] + offset * eDir[i][2]) * this->fStepZ;
340 cell.fIds[i] = mesh->AddVertex(v);
351 class TF3EdgeSplitter :
protected virtual TGridGeometry<Double_t> {
353 TF3EdgeSplitter() : fTF3(0)
357 void SetNormalEvaluator(
const TF3 *tf3)
362 void SplitEdge(TCell<Double_t> & cell, TIsoMesh<Double_t> * mesh, UInt_t i,
363 Double_t x, Double_t y, Double_t z, Double_t iso)
const;
373 template<
class,
class>
class TSplitterSelector;
376 class TSplitterSelector<TH3C, V> {
378 typedef TDefaultSplitter<TH3C, Char_t, V> Type_t;
382 class TSplitterSelector<TH3S, V> {
384 typedef TDefaultSplitter<TH3S, Short_t, V> Type_t;
388 class TSplitterSelector<TH3I, V> {
390 typedef TDefaultSplitter<TH3I, Int_t, V> Type_t;
394 class TSplitterSelector<TH3F, V> {
396 typedef TDefaultSplitter<TH3F, Float_t, V> Type_t;
400 class TSplitterSelector<TH3D, V> {
402 typedef TDefaultSplitter<TH3D, Double_t, V> Type_t;
406 class TSplitterSelector<TKDEFGT, V> {
408 typedef TDefaultSplitter<TKDEFGT, Float_t, Float_t> Type_t;
412 class TSplitterSelector<TF3, V> {
414 typedef TF3EdgeSplitter Type_t;
425 template<
class DataSource,
class ValueType>
426 class TMeshBuilder :
public TSourceAdapterSelector<DataSource>::Type_t,
427 public TSplitterSelector<DataSource, ValueType>::Type_t
431 typedef typename TSourceAdapterSelector<DataSource>::Type_t DataSourceBase_t;
432 typedef typename TSplitterSelector<DataSource, ValueType>::Type_t SplitterBase_t;
435 using DataSourceBase_t::GetW;
436 using DataSourceBase_t::GetH;
437 using DataSourceBase_t::GetD;
438 using DataSourceBase_t::GetData;
439 using SplitterBase_t::SplitEdge;
441 typedef typename DataSourceBase_t::ElementType_t ElementType_t;
443 typedef TCell<ElementType_t> CellType_t;
444 typedef TSlice<ElementType_t> SliceType_t;
445 typedef TIsoMesh<ValueType> MeshType_t;
448 TMeshBuilder(Bool_t averagedNormals, ValueType eps = 1e-7)
449 : fAvgNormals(averagedNormals), fMesh(0), fIso(), fEpsilon(eps)
453 void BuildMesh(
const DataSource *src,
const TGridGeometry<ValueType> &geom,
454 MeshType_t *mesh, ValueType iso);
459 SliceType_t fSlices[2];
464 void NextStep(UInt_t depth,
const SliceType_t *prevSlice,
465 SliceType_t *curr)
const;
467 void BuildFirstCube(SliceType_t *slice)
const;
468 void BuildRow(SliceType_t *slice)
const;
469 void BuildCol(SliceType_t *slice)
const;
470 void BuildSlice(SliceType_t *slice)
const;
471 void BuildFirstCube(UInt_t depth,
const SliceType_t *prevSlice,
472 SliceType_t *slice)
const;
473 void BuildRow(UInt_t depth,
const SliceType_t *prevSlice,
474 SliceType_t *slice)
const;
475 void BuildCol(UInt_t depth,
const SliceType_t *prevSlice,
476 SliceType_t *slice)
const;
477 void BuildSlice(UInt_t depth,
const SliceType_t *prevSlice,
478 SliceType_t *slice)
const;
480 void BuildNormals()
const;
482 TMeshBuilder(
const TMeshBuilder &rhs);
483 TMeshBuilder & operator = (
const TMeshBuilder &rhs);