contour.h
1 /************************************************************
2 * (C) Voxel Farm Inc. 2015
3 */
4 
5 #pragma once
6 
7 #include "Vector.h"
8 #include "MaterialLibrary.h"
9 #include "CellData.h"
10 #include "Matrix.h"
11 #include "Generator.h"
12 #include "FastQuadrics.h"
13 
14 namespace VoxelFarm
15 {
17  const int CONTOUR_OCTREE_LEVELS = 7;
19  const int CONTOUR_OCTREE_SIZE = 64;
20 
22  struct OctreeNode
23  {
25  unsigned int map;
27  unsigned int index;
29  unsigned int children[8];
31  short targetLevel;
35  int count;
37  bool leaf;
39  bool boundary;
41  double maxError;
45  int material;
47  bool homogeneus;
48  };
49 
52  {
53  public:
55  virtual ~ContourThreadContext();
56  ContourVoxelData* data;
57  CCellData::CVert* points;
58  int* pointIndex;
59  OctreeNode* nodes;
60  int* quadIndex;
61  int* quadTypes;
62  int* vertexTypes;
63  bool* edgeSign;
64  MaterialId* materials;
65  };
66 
68  int contour(
70  int level,
72  ContourVoxelData* data,
74  CMaterialLibrary* materialLibrary,
76  OctreeNode* nodes,
78  CCellData::CVert* points,
80  int* pointIndex,
82  int* quadIndex,
84  int* quadType,
86  bool* edgeSign,
88  MaterialId* materials,
90  int& lastPointId);
91 
93  int contour(
95  int level,
97  ContourVoxelData* data,
99  CMaterialLibrary* materialLibrary,
101  CCellData::CVert* points,
103  int* pointIndex,
105  int* quadIndex,
107  int* vertexType,
109  bool* edgeSign,
111  MaterialId* materials,
113  int& lastPointId);
114 
116  bool contourCellData(
120  CMaterialLibrary* materialLibrary,
122  CCellData* cellData,
124  CBillboardCache* billboardCache,
125  CCellData::ThreadContext* cellDataThreadContext,
127  LODStats stats);
128 
129  bool contourCellDataMCA(
133  CMaterialLibrary* materialLibrary,
135  CCellData* cellData,
137  CBillboardCache* billboardCache,
139  CCellData::ThreadContext* cellDataThreadContext,
141  bool compress,
143  LODStats stats
144  );
145 
146  bool processCellDataMCA(
148  CMaterialLibrary* materialLibrary,
150  CCellData* cellData,
152  CBillboardCache* billboardCache,
154  CCellData::ThreadContext* cellDataThreadContext,
156  LODStats stats
157  );
158 
164  CMaterialLibrary* materialLibrary,
166  CCellData* cellData,
168  bool compress,
170  LODStats stats
171  );
172 
173  //Navigation Mesh
174 
177  {
178  public:
180  virtual bool voxelCellData(
182  CellId cell,
184  ContourVoxelData* data,
186  int layerGroup
187  ) = 0;
189  virtual bool meshCellData(
191  CellId cell,
193  bool medium[CCellData::MEDIUM_MAX],
195  CFastQuadrics* mesh[CCellData::MEDIUM_MAX]
196  ) = 0;
197  };
198 
202  ICellDataCache* cellDataCache,
204  CGenerator* generator,
206  CellId cell,
207  int childLevel,
209  double featureSize,
211  double maxError,
213  bool computeMedium[CCellData::MEDIUM_MAX],
215  CFastQuadrics* meshes[CCellData::MEDIUM_MAX],
217  CMaterialLibrary* materialLibrary
218  );
219 
220  void removePockets(CFastQuadrics* mesh);
221 }
A node in the contouring octree. This octree is used to compress the polygonal output of the contouri...
Definition: contour.h:22
Algebra::QEFMatrix qef
Quadratic Error collected for the cell.
Definition: contour.h:43
Combines several voxel layers into the final dataset sent to the contouring phase.
Definition: Generator.h:20
Contains all classes and functions for the VoxelFarm engine.
Contains all materials available in the system.
A 3D Vector.
Definition: Vector.h:34
Algebra::Vector p
A point inside the cell where the isosurface crosses.
Definition: contour.h:33
bool homogeneus
Node is made of same material inside.
Definition: contour.h:47
static const int MEDIUM_MAX
Number of different mediums in the world. Each medium may be subject to a different rendering logic...
Definition: CellData.h:111
int material
Material id for the node.
Definition: contour.h:45
unsigned __int64 CellId
A 64bit integer that identifies a single world octree Cell.
Definition: mapindex.h:23
double maxError
Maximum simplification error allowed for the node.
Definition: contour.h:41
Stores the information for a Cell that has already been converted to a polygonal mesh.
Definition: CellData.h:107
Generation of voxel data and then meshes out if it can be time consuming. The engine allows multiple ...
Definition: contour.h:51
const int CONTOUR_OCTREE_LEVELS
How many times the contouring octree can subdivide.
Definition: contour.h:17
int contourCellDataLayerGroup(ContourThreadContext *tc, CMaterialLibrary *materialLibrary, CCellData *cellData, bool compress, LODStats stats)
Contours voxel data of each group of layers and stores the output in a polygonal mesh (CCellData) obj...
bool leaf
Indicates whether it is a end node in the octree.
Definition: contour.h:37
StatTracker LODStats[LEVELS][STAT_NULL]
Used to track stats across all LOD.
Definition: VoxelLayer.h:530
bool contourCellDataMCA(ContourThreadContext *tc, CMaterialLibrary *materialLibrary, CCellData *cellData, CBillboardCache *billboardCache, CCellData::ThreadContext *cellDataThreadContext, bool compress, LODStats stats)
const int CONTOUR_OCTREE_SIZE
Number of voxels along one dimension in the contouring octree.
Definition: contour.h:19
An interface for caching data.
Definition: contour.h:176
A matrix for minimizing Quadratic Error functions.
Definition: matrix.h:18
virtual bool voxelCellData(CellId cell, ContourVoxelData *data, int layerGroup)=0
Cache a buffer of voxels. Return true if there are cached data for the cell.
unsigned int map
Links the node to another node in the octree. This is set when the octree is compressed.
Definition: contour.h:25
void getCellChildrenNavigationMeshes(ICellDataCache *cellDataCache, CGenerator *generator, CellId cell, int childLevel, double featureSize, double maxError, bool computeMedium[CCellData::MEDIUM_MAX], CFastQuadrics *meshes[CCellData::MEDIUM_MAX], CMaterialLibrary *materialLibrary)
Get the simplified mesh for a cell using child cells.
virtual bool meshCellData(CellId cell, bool medium[CCellData::MEDIUM_MAX], CFastQuadrics *mesh[CCellData::MEDIUM_MAX])=0
Cache a mesh as a CFastQuadrics by each medium. Return true if there are any cached mesh for the cell...
unsigned int children[8]
Pointers to the eight children.
Definition: contour.h:29
unsigned int index
Pointer to the vertex information.
Definition: contour.h:27
bool processCellDataMCA(CMaterialLibrary *materialLibrary, CCellData *cellData, CBillboardCache *billboardCache, CCellData::ThreadContext *cellDataThreadContext, LODStats stats)
bool contourCellData(ContourThreadContext *tc, CMaterialLibrary *materialLibrary, CCellData *cellData, CBillboardCache *billboardCache, CCellData::ThreadContext *cellDataThreadContext, LODStats stats)
Contours voxel data and stores the output in a polygonal mesh (CCellData) object. ...
int count
Number of isosurface crossings.
Definition: contour.h:35
An efficient mesh representation that features Quadratic Error function simplification using a Multip...
Definition: FastQuadrics.h:44
int contour(int level, ContourVoxelData *data, CMaterialLibrary *materialLibrary, OctreeNode *nodes, CCellData::CVert *points, int *pointIndex, int *quadIndex, int *quadType, bool *edgeSign, MaterialId *materials, int &lastPointId)
Performs contouring on the voxel data.
short targetLevel
Octree can collapse below this specified level.
Definition: contour.h:31
Keeps an billboard cache entry for each cell that had its billboards and material instances generated...
Definition: CellData.h:75
bool boundary
Indicates whether the node is in the world cell boundary.
Definition: contour.h:39