SPH
MarchingCubes.h
Go to the documentation of this file.
1 #pragma once
2 
4 #include "objects/geometry/Box.h"
7 
9 
10 class Storage;
11 class IScheduler;
12 
16 class Cell {
17 private:
19  StaticArray<Float, 8> values;
20 
21 public:
22  INLINE Float& value(const Size idx) {
23  return values[idx];
24  }
25 
26  INLINE Vector& node(const Size idx) {
27  return points[idx];
28  }
29 };
30 
32 class IScalarField : public Polymorphic {
33 public:
35  virtual Float operator()(const Vector& pos) = 0;
36 };
37 
40 private:
41  IScheduler& scheduler;
42 
44  Float surfaceLevel;
45 
48 
50  Array<Triangle> triangles;
51 
53  struct {
56  } cached;
57 
61  Function<bool(Float progress)> progressCallback = nullptr;
62 
63 public:
70  MarchingCubes(IScheduler& scheduler,
71  const Float surfaceLevel,
72  const SharedPtr<IScalarField>& field,
73  Function<bool(Float progress)> progressCallback = nullptr);
74 
81  void addComponent(const Box& box, const Float gridResolution);
82 
85  return triangles;
86  }
87 
90  return std::move(triangles);
91  }
92 
93 private:
97  INLINE void intersectCell(Cell& cell, Array<Triangle>& tri);
98 
100  Vector interpolate(const Vector& v1, const Float p1, const Vector& v2, const Float p2) const;
101 
105  template <typename TFunctor>
106  bool iterateWithIndices(const Box& box, const Vector& step, TFunctor&& functor);
107 };
108 
109 struct McConfig {
112 
116  Float surfaceLevel = 0.12_f;
117 
120 
122  bool useAnisotropicKernels = false;
123 
125  Function<bool(Float progress)> progressCallback = nullptr;
126 };
127 
133 Array<Triangle> getSurfaceMesh(IScheduler& scheduler, const Storage& storage, const McConfig& config);
134 
135 
Generic dynamically allocated resizable storage.
NAMESPACE_SPH_BEGIN
Definition: BarnesHut.cpp:13
Object representing a three-dimensional axis-aligned box.
Generic wrappers of lambdas, functors and other callables.
uint32_t Size
Integral type used to index arrays (by default).
Definition: Globals.h:16
double Float
Precision used withing the code. Use Float instead of float or double where precision is important.
Definition: Globals.h:13
Array< Triangle > getSurfaceMesh(IScheduler &scheduler, const Storage &storage, const McConfig &config)
Returns the triangle mesh of the body surface (or surfaces of bodies).
#define INLINE
Macros for conditional compilation based on selected compiler.
Definition: Object.h:31
#define NAMESPACE_SPH_END
Definition: Object.h:12
Helper object defining three-dimensional interval (box).
Definition: Box.h:17
Single cell used in mesh generation.
Definition: MarchingCubes.h:16
INLINE Float & value(const Size idx)
Definition: MarchingCubes.h:22
INLINE Vector & node(const Size idx)
Definition: MarchingCubes.h:26
Inferface for a generic scalar field, returning a float for given position.:w.
Definition: MarchingCubes.h:32
virtual Float operator()(const Vector &pos)=0
Returns the value of the scalar field at given position.
Interface that allows unified implementation of sequential and parallelized versions of algorithms.
Definition: Scheduler.h:27
Marching cubes algorithm for generation of mesh from iso-surface of given scalar field.
Definition: MarchingCubes.h:39
Array< Float > phi
Values of the scalar field defining the surface.
Definition: MarchingCubes.h:55
INLINE Array< Triangle > getTriangles() &&
Returns the generated triangles.
Definition: MarchingCubes.h:89
INLINE Array< Triangle > & getTriangles() &
Returns the generated triangles.
Definition: MarchingCubes.h:84
void addComponent(const Box &box, const Float gridResolution)
Adds a triangle mesh representing the boundary of particles.
MarchingCubes(IScheduler &scheduler, const Float surfaceLevel, const SharedPtr< IScalarField > &field, Function< bool(Float progress)> progressCallback=nullptr)
Constructs the object using given scalar field.
Array with fixed number of allocated elements.
Definition: StaticArray.h:19
Container storing all quantities used within the simulations.
Definition: Storage.h:230
Function< bool(Float progress)> progressCallback
Generic functor called during MC evaluation.
Float smoothingMult
Multiplier of the smoothing lengths.
Float gridResolution
Absolute size of each produced triangle.
bool useAnisotropicKernels
If true, anisotropic kernels of Yu & Turk (2010) are used instead of normal isotropic kernels.
Float surfaceLevel
Base class for all polymorphic objects.
Definition: Object.h:88