Cogs.Core
IsoSurfaces.h
1#pragma once
2#include "Resources/Resources.h"
3#include "Services/TaskManager.h"
4#include "Base.h"
5
6#include "Foundation/Memory/MemoryBuffer.h"
7
8#include <glm/glm.hpp>
9
10#include <atomic>
11#include <vector>
12
13namespace Cogs::Core {
14 class Context;
15}
16
17namespace Cogs::Core::IsoSurfaces
18{
19
23 struct Scratch
24 {
25 struct ijk_t {
26 uint16_t i, j, k;
27 uint8_t code;
28 uint8_t axes;
29 };
32 Cogs::Memory::TypedBuffer<int32_t> activeCellVertexOffsets;
33 Cogs::Memory::TypedBuffer<int32_t> activeCellIndexOffsets;
34 Cogs::Memory::TypedBuffer<int32_t> activeCellIndices;
37 };
38
47 MeshHandle COGSCORE_DLL_API createIsoSurfacesMesh(Context* context,
48 Scratch& scratch, //< Scratch memory, can be recycled between invocations.
49 const std::vector<float>& thresholds, //< List of up to 16 threshold values.
50 const float* densityField, //< Pointer to a 3D array of scalar float values.
51 const float* dataField, //< Optional data field, may be null, mapped to texcoord Y.
52 const glm::uvec3 fieldSize, //< The dimensions of field.
53 const glm::vec3 minCorner, //< The spatial position of the minimum corner of the scalar field grid.
54 const glm::vec3 maxCorner, //< The spatial position of the maximum corner of the scalar field grid.
55 const bool exteriorIsInside = true,
56 const bool flipOrientation = true,
57 const bool closeZNeg = true, //< Close surface at the Z negative face or leave it open?
58 const bool closeZPos = true,
59 const bool closeYNeg = true,
60 const bool closeYPos = true,
61 const bool closeXNeg = true,
62 const bool closeXPos = true,
64
68 void COGSCORE_DLL_API analyze(Context* context,
69 std::vector<int32_t>& vertexOffsets, // [L]
70 std::vector<int32_t>& indexOffsets, // [L]
71 std::vector<int32_t>& cellOffsets, // [L]
73 Memory::TypedBuffer<uint8_t>& activeCellCases,
74 Memory::TypedBuffer<int32_t>& activeCellVertexOffsets, // One element per active cell.
75 Memory::TypedBuffer<int32_t>& activeCellIndexOffsets, // One element per active cell.
76 Memory::TypedBuffer<int32_t>& activeCellIndices, // One element per active cell.
77 Memory::TypedBuffer<Scratch::ijk_t>& activeCellIJK, // One element per active cell.
78 const std::vector<float>& thresholds,
79 const bool exteriorIsInside,
80 const float* field,
81 const glm::ivec3 fieldDim,
82 const glm::ivec3 gridA,
83 const glm::ivec3 gridB,
84 std::atomic<uint64_t>* elapsed_us = nullptr);
85
99 typedef std::function<void(int32_t ixIndex, glm::ivec4* samples, const uint32_t ixN)> VertexEmitFunc;
100
104 void COGSCORE_DLL_API extractVertices(Context* context,
105 TaskId group,
106 VertexEmitFunc vertexEmit,
107 const uint8_t* activeCellCases,
108 const int32_t* activeCellVertexOffsets,
109 const int32_t* activeCellIndices,
110 const Scratch::ijk_t* activeCellIJK,
111 const int32_t activeCellCount,
112 const glm::ivec3 gridA,
113 const glm::ivec3 gridB,
114 std::atomic<uint64_t>* elapsed_us = nullptr);
115
116
127 typedef std::function<void(uint32_t ixIndex, glm::ivec3 cell, const uint32_t* indices, const uint32_t ixN)> IndexEmitFunc;
128
132 void COGSCORE_DLL_API extractIndices(Context* context,
133 TaskId group,
134 IndexEmitFunc& emitFunc,
135 const int32_t* cellMap,
136 const uint8_t* activeCellCases,
137 const int32_t* activeCellVertexOffsets,
138 const int32_t* activeCellIndexOffsets,
139 const int32_t* activeCellIndices,
140 const Scratch::ijk_t* activeCellIJK,
141 const int32_t activeCellCount,
142 const glm::ivec3 gridA,
143 const glm::ivec3 gridB,
144 std::atomic<uint64_t>* elapsed_us = nullptr);
145
146
147}
A Context instance contains all the services, systems and runtime components needed to use Cogs.
Definition: Context.h:83
Contains the Engine, Renderer, resource managers and other systems needed to run Cogs....
Struct that holds temporary data between the different passes.
Definition: IsoSurfaces.h:24
static const ResourceHandle_t NoHandle
Handle representing a default (or none if default not present) resource.
Task id struct used to identify unique Task instances.
Definition: TaskManager.h:20