Newton Dynamics  4.00
dIsoSurface.h
1 /* Copyright (c) <2003-2019> <Julio Jerez, Newton Game Dynamics>
2 *
3 * This software is provided 'as-is', without any express or implied
4 * warranty. In no event will the authors be held liable for any damages
5 * arising from the use of this software.
6 *
7 * Permission is granted to anyone to use this software for any purpose,
8 * including commercial applications, and to alter it and redistribute it
9 * freely, subject to the following restrictions:
10 *
11 * 1. The origin of this software must not be misrepresented; you must not
12 * claim that you wrote the original software. If you use this software
13 * in a product, an acknowledgment in the product documentation would be
14 * appreciated but is not required.
15 *
16 * 2. Altered source versions must be plainly marked as such, and must not be
17 * misrepresented as being the original software.
18 *
19 * 3. This notice may not be removed or altered from any source distribution.
20 */
21 
22 // adapted from code by written by Paul Bourke may 1994
23 //http://paulbourke.net/geometry/polygonise/
24 
25 #ifndef __D_ISO_SURFACE_H__
26 #define __D_ISO_SURFACE_H__
27 
28 #include "dCoreStdafx.h"
29 #include "dTypes.h"
30 #include "dArray.h"
31 #include "dTree.h"
32 
33 class dIsoSurface: public dClassAlloc
34 {
35  public:
36  class dIsoCell
37  {
38  public:
39  dFloat32 m_isoValues[2][2][2];
40  dInt32 m_x;
41  dInt32 m_y;
42  dInt32 m_z;
43  };
44 
46  {
47  public:
48  dUnsigned64 m_pointId[3];
49  };
50 
51  class dIsoVertexMap: public dTree<dVector, dUnsigned64, dContainersFreeListAlloc<dVector>>
52  {
53  public:
54  };
55 
56  D_CORE_API dIsoSurface();
57  D_CORE_API ~dIsoSurface();
58 
59  D_CORE_API void Begin(const dVector& origin, dFloat32 isovalue, dFloat32 gridSize, dInt32 sizex, dInt32 sizey, dInt32 sizez);
60  D_CORE_API void ProcessCell(const dIsoCell& cell);
61  D_CORE_API void End();
62 
63  const dInt32 GetIndexCount() const;
64  const dInt32 GetVertexCount() const;
65  const dVector* GetPoints() const;
66  const dVector* GetNormals() const;
67  const dUnsigned64* GetIndexList() const;
68 
69  private:
70  dUnsigned64 GetVertexID(dInt32 x, dInt32 y, dInt32 z);
71  dUnsigned64 GetEdgeID(const dIsoCell& cell, dInt32 edgeCode);
72  dVector CalculateIntersection(const dIsoCell& cell, dInt32 edgeCode);
73  dVector InterpolateEdge(dFloat32 fX1, dFloat32 fY1, dFloat32 fZ1, dFloat32 fX2, dFloat32 fY2, dFloat32 fZ2, dFloat32 tVal1, dFloat32 tVal2);
74 
75  void RemapIndexList();
76  void CalculateNormals();
77 
78  dVector m_origin;
79  dArray<dVector> m_points;
80  dArray<dVector> m_normals;
81  dArray<dIsoTriangle> m_trianglesList;
82 
83  dIsoVertexMap m_vertexMap;
84  dInt32 m_xCellSize;
85  dInt32 m_yCellSize;
86  dInt32 m_zCellSize;
87  dFloat32 m_gridSize;
88  dFloat32 m_isoValue;
89 
90  static const dInt32 m_edgeTable[];
91  static const dInt32 m_triangleTable[][16];
92 };
93 
94 inline const dInt32 dIsoSurface::GetIndexCount() const
95 {
96  return m_trianglesList.GetCount() * 3;
97 }
98 
99 inline const dInt32 dIsoSurface::GetVertexCount() const
100 {
101  return m_points.GetCount();
102 }
103 
104 inline const dVector* dIsoSurface::GetPoints() const
105 {
106  return m_points.GetCount() ? &m_points[0] : nullptr;
107 }
108 
109 inline const dVector* dIsoSurface::GetNormals() const
110 {
111  return m_normals.GetCount() ? &m_normals[0] : nullptr;
112 }
113 
114 inline const dUnsigned64* dIsoSurface::GetIndexList() const
115 {
116  return m_trianglesList.GetCount() ? &m_trianglesList[0].m_pointId[0] : nullptr;
117 }
118 
119 #endif
120 
dTree
Definition: dTree.h:80
dIsoSurface
Definition: dIsoSurface.h:34
dIsoSurface::dIsoTriangle
Definition: dIsoSurface.h:46
dArray< dVector >
dClassAlloc
Base class for providing memory allocation for all other engine classes.
Definition: dClassAlloc.h:29
dIsoSurface::dIsoCell
Definition: dIsoSurface.h:37
dVector
Definition: dVectorArmNeon.h:1104
dIsoSurface::dIsoVertexMap
Definition: dIsoSurface.h:52