API Documentation
Loading...
Searching...
No Matches
GriddedMesh.h
Go to the documentation of this file.
1/*--------------------------------------------------------------------------------------------
2Copyright (c) 2019, NDEVR LLC
3tyler.parke@ndevr.org
4 __ __ ____ _____ __ __ _______
5 | \ | | | __ \ | ___|\ \ / / | __ \
6 | \ | | | | \ \ | |___ \ \ / / | |__) |
7 | . \| | | |__/ / | |___ \ V / | _ /
8 | |\ |_|_____/__|_____|___\_/____| | \ \
9 |__| \__________________________________| \__\
10
11Subject to the terms of the Enterprise+ Agreement, NDEVR hereby grants
12Licensee a limited, non-exclusive, non-transferable, royalty-free license
13(without the right to sublicense) to use the API solely for the purpose of
14Licensee's internal development efforts to develop applications for which
15the API was provided.
16
17The above copyright notice and this permission notice shall be included in all
18copies or substantial portions of the Software.
19
20THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
21INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
22PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE
23FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
24OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
25DEALINGS IN THE SOFTWARE.
26
27Library: Design
28File: GriddedMesh
29Included in API: True
30Author(s): Tyler Parke
31 *-----------------------------------------------------------------------------------------**/
32#pragma once
33#include <NDEVR/Model.h>
34#include <NDEVR/Geometry.h>
35namespace NDEVR
36{
37 /**--------------------------------------------------------------------------------------------------
38 \brief Converts 1 dimensional index into N dimensional index based on size of each dimension.
39 **/
40 template<uint01 t_dims>
42 {
43 public:
45 {
46 lib_assert(location < m_size, "Out of bounds grid conversion lookup");
47 switch (t_dims)
48 {
49 case 1: return location[X];
50 case 2: return m_size[X] * location[Y] + location[X];
51 case 3: return m_size[X] * m_size[Y] * location[Z] + m_size[X] * location[Y] + location[X];
52 }
54 }
56 {
57 Vector<t_dims, uint04> vec_location;
58 switch (t_dims)
59 {
60 case 1:
61 vec_location[X] = location;
62 break;
63 case 2:
64 vec_location[Y] = location / m_size[X];
65 vec_location[X] = location % m_size[X];
66 break;
67 case 3:
68 vec_location[Z] = location / (m_size[X] * m_size[Y]);
69 vec_location[Y] = (location / m_size[X]) % m_size[Y];
70 vec_location[X] = location % m_size[X];
71 break;
72 }
73 lib_assert(vec_location < m_size, "Out of bounds grid conversion lookup");
74 return vec_location;
75 }
76 static constexpr uint01 getNumberOfCorners()
77 {
78 switch (t_dims)
79 {
80 case 1: return 2;
81 case 2: return 4;
82 case 3: return 8;
83 }
85 }
87 {
88 m_size = index_size;
89 }
90 protected:
92 };
93
94 /**--------------------------------------------------------------------------------------------------
95 \brief Stores a uniform grid of data in N dimensions into a Geometry object
96 **/
97 template<uint01 t_dims>
98 class GridMesh : public GridIndexing<t_dims>
99 {
100 public:
102 {}
103 explicit GridMesh(const Geometry& model)
104 : m_geo(model)
105 {}
106 bool isValid() const
107 {
108 return m_geo.isValid();
109 }
111 , Geometry::VertexMode position
118 {
120 //m_geo.setGeometryType(t_dims == 2 ? GeometryType::e_grids : GeometryType::e_block_models);
122 uint04 count = index_size.product();
123 m_geo.setupVertexTable(count, position, normal, color, texture, tangent, bitangent, bones);
124 BitFlag flag(0);
127 //flag(VertexBitFlags::e_, true);
129 for (uint04 i = 0; i < count; i++)
130 {
131 iterator.setFlag(i, flag);
133 }
135 //m_geo.addPrimitive(PrimitiveProperty::Solid, index_size);
136 }
138 {
140 }
141
142
143 template<class t_type>
144 void setVertex(VertexProperty property, Vector<t_dims, uint04> index, const t_type& vector)
145 {
146 m_geo.setVertex(property, GridIndexing<t_dims>::convertToIndex(index), vector);
147 }
148
149 template<class t_type>
150 t_type vertex(VertexProperty property, Vector<t_dims, uint04> index) const
151 {
152 return m_geo.vertex<t_type>(property, GridIndexing<t_dims>::convertToIndex(index));
153 }
154
155 template<class t_type>
156 void setVertexProperty(uint04 property_index, Vector<t_dims, uint04> index, const t_type& value)
157 {
158 m_geo.setProperty(property_index, GridIndexing<t_dims>::convertToIndex(index), value);
159 }
160
161 template<class t_type>
162 t_type getVertexProperty(uint04 property_index, Vector<t_dims, uint04> index) const
163 {
165 }
166
167 template<class t_type>
169 {
171 for (uint01 dim = 0; dim < t_dims; dim++)
172 {
173 if (index[dim] < 0 || index[dim] > size[dim])
175 }
176 Vector<t_dims, uint04> discrete = index.template as<t_dims, uint04>();
177 Vector<t_dims, fltp08> dt = index - discrete.template as<t_dims, fltp08>();
178
179 if (dt == Vector<t_dims, fltp08>(0.0) || interpolation == InterpolationValues::nearest_neighbor)
180 return vertex<t_type>(property, discrete);
181
183 for (uint01 i = 0; i < GridIndexing<t_dims>::getNumberOfCorners(); i++)
184 {
185 Vector<t_dims, uint04> location_sum(0);
186 if constexpr (t_dims >= 3)
187 location_sum[Z] = (i / 4) % 2;
188 if constexpr (t_dims >= 2)
189 location_sum[Y] = (i / 2) % 2;
190 if constexpr (t_dims >= 1)
191 location_sum[X] = (i / 1) % 2;
192 if (discrete[X] == size[X] - 1)
193 location_sum[X] = 0;
194 if (discrete[Y] == size[Y] - 1)
195 location_sum[Y] = 0;
196 center[i] = vertex<t_type>(property, discrete + location_sum);
197 }
198
199 if (IsInvalid(center))
200 {
202 }
203 else if (interpolation == InterpolationValues::e_linear)
204 {
205 t_type value = 0;
206 for (uint01 i = 0; i < GridIndexing<t_dims>::getNumberOfCorners(); i++)
207 {
208 Vector<t_dims, uint04> location_sum(0);
209 if constexpr (t_dims >= 3)
210 location_sum[Z] = (i / 4) % 2;
211 if constexpr (t_dims >= 2)
212 location_sum[Y] = (i / 2) % 2;
213 if constexpr (t_dims >= 1)
214 location_sum[X] = (i / 1) % 2;
215 Vector<t_dims, fltp08> location_s = (discrete + location_sum).template as<t_dims, fltp08>();
216 Vector<t_dims, fltp08> difference = (1.0 - abs(location_s - index));
217 value += center[i] * difference.product();
218 }
219 return value;
220 }
221 else//bicubic
222 {
223 /*const uint04 d10 = getZ(discrete_x - 1, discrete_y + 0, d11);
224 const uint04 d13 = getZ(discrete_x + 2, discrete_y + 0, d12);
225 const uint04 d20 = getZ(discrete_x - 1, discrete_y + 1, d21);
226 const uint04 d23 = getZ(discrete_x + 2, discrete_y + 1, d22);
227
228 const uint04 d00 = getZ(discrete_x - 1, discrete_y - 1, d10);
229 const uint04 d01 = getZ(discrete_x - 0, discrete_y - 1, d11);
230 const uint04 d02 = getZ(discrete_x + 1, discrete_y - 1, d12);
231 const uint04 d03 = getZ(discrete_x + 2, discrete_y - 1, d02);
232
233 const uint04 d30 = getZ(discrete_x - 1, discrete_y + 2, d20);
234 const uint04 d31 = getZ(discrete_x - 0, discrete_y + 2, d21);
235 const uint04 d32 = getZ(discrete_x + 1, discrete_y + 2, d22);
236 const uint04 d33 = getZ(discrete_x + 2, discrete_y + 2, d23);
237
238 const fltp08 p0 = (d01 + 0.5 * dx
239 * (d02 - d00 + dx * (2.0 * d00 - 5.0 * d01 + 4.0 * d02 - d03 + dx * (3.0 * (d01 - d02) + d03 - d00))));
240 const fltp08 p1 = (d11 + 0.5 * dx
241 * (d12 - d10 + dx * (2.0 * d10 - 5.0 * d11 + 4.0 * d12 - d13 + dx * (3.0 * (d11 - d12) + d13 - d10))));
242 const fltp08 p2 = (d21 + 0.5 * dx
243 * (d22 - d20 + dx * (2.0 * d20 - 5.0 * d21 + 4.0 * d22 - d23 + dx * (3.0 * (d21 - d22) + d23 - d20))));
244 const fltp08 p3 = (d31 + 0.5 * dx
245 * (d32 - d30 + dx * (2.0 * d30 - 5.0 * d31 + 4.0 * d32 - d33 + dx * (3.0 * (d31 - d32) + d33 - d30))));
246
247 return (p1 + 0.5f * dy * (p2 - p0 + dy * (2.0 * p0 - 5.0 * p1 + 4.0 * p2 - p3 + dy * (3.0 * (p1 - p2) + p3 - p0))));*/
248 }
250 }
251 Geometry geometry() const { return m_geo; };
252 protected:
254 };
255};
256
257
258
259
#define lib_assert(expression, message)
Definition LibAssert.h:61
A bitset that stores 8 bits (elements with only two possible values: 0 or 1, true or false,...
Definition BitFlag.hpp:55
bool isValid() const
Definition DesignObject.h:355
t_type getProperty(DesignProperty property) const
Definition DesignObject.h:256
void setProperty(DesignProperty property, const t_type &value)
Definition DesignObject.h:177
A core class within the model heirarchy containing vertex-based data (Usually 3D data) within a set c...
Definition Geometry.h:64
void updateVertexColumns(bool invalidate_bounds=true, bool erase_kd_tree=true)
t_type vertex(VertexProperty property, uint04 index) const
Definition Geometry.h:919
VertexMode
Definition Geometry.h:68
@ e_no_vertex
Definition Geometry.h:69
void setupVertexTable(uint04 vertex_size, VertexMode position, VertexMode normal=VertexMode::e_no_vertex, VertexMode color=VertexMode::e_no_vertex, VertexMode texture=VertexMode::e_no_vertex, VertexMode tangent=VertexMode::e_no_vertex, VertexMode bitangent=VertexMode::e_no_vertex, VertexMode bones=VertexMode::e_no_vertex)
void setGeometryType(GeometryType geometry_type)
void setVertex(VertexProperty property, uint04 index, const t_type &vector)
Definition Geometry.h:871
Converts 1 dimensional index into N dimensional index based on size of each dimension.
Definition GriddedMesh.h:42
Vector< t_dims, uint04 > convertFromIndex(const uint04 &location) const
Definition GriddedMesh.h:55
static constexpr uint01 getNumberOfCorners()
Definition GriddedMesh.h:76
uint04 convertToIndex(const Vector< t_dims, uint04 > &location) const
Definition GriddedMesh.h:44
void setSize(Vector< t_dims, uint04 > index_size)
Definition GriddedMesh.h:86
Vector< t_dims, uint04 > m_size
Definition GriddedMesh.h:91
Stores a uniform grid of data in N dimensions into a Geometry object.
Definition GriddedMesh.h:99
void setVertexProperty(uint04 property_index, Vector< t_dims, uint04 > index, const t_type &value)
Definition GriddedMesh.h:156
void setVertex(VertexProperty property, Vector< t_dims, uint04 > index, const t_type &vector)
Definition GriddedMesh.h:144
const Vector< t_dims, uint04 > & getIndexSize() const
Definition GriddedMesh.h:137
GridMesh(const Geometry &model)
Definition GriddedMesh.h:103
void setupVertexTable(Vector< t_dims, uint04 > index_size, Geometry::VertexMode position, Geometry::VertexMode normal=Geometry::VertexMode::e_no_vertex, Geometry::VertexMode color=Geometry::VertexMode::e_no_vertex, Geometry::VertexMode texture=Geometry::VertexMode::e_no_vertex, Geometry::VertexMode tangent=Geometry::VertexMode::e_no_vertex, Geometry::VertexMode bitangent=Geometry::VertexMode::e_no_vertex, Geometry::VertexMode bones=Geometry::VertexMode::e_no_vertex)
Definition GriddedMesh.h:110
bool isValid() const
Definition GriddedMesh.h:106
t_type interpolateVertex(VertexProperty property, const Vector< t_dims, fltp08 > &index, InterpolationValues interpolation=InterpolationValues::e_linear) const
Definition GriddedMesh.h:168
t_type getVertexProperty(uint04 property_index, Vector< t_dims, uint04 > index) const
Definition GriddedMesh.h:162
Geometry geometry() const
Definition GriddedMesh.h:251
GridMesh()
Definition GriddedMesh.h:101
Geometry m_geo
Definition GriddedMesh.h:253
t_type vertex(VertexProperty property, Vector< t_dims, uint04 > index) const
Definition GriddedMesh.h:150
A fixed-size array with better performance compared to dynamic containers.
Definition Vector.hpp:60
constexpr t_type product() const
Definition Vector.hpp:488
A class to easily iterate each vertex of a Geometry.
Definition Geometry.h:1455
void setVertex(uint04 index, const t_type &value)
Definition Geometry.h:1487
void setFlag(uint04 index, const BitFlag &value)
Definition Geometry.h:1491
Definition ACIColor.h:37
constexpr bool IsInvalid(const t_type &value)
Query if 'value' is valid or invalid. Invalid values should return invalid if used for calculations o...
Definition BaseFunctions.hpp:170
VertexProperty
Definition DesignObjectBase.h:52
InterpolationValues
Values that represent interpolation functions. Useful in large or complicated geological or time base...
Definition BaseValues.hpp:221
@ nearest_neighbor
Definition BaseValues.hpp:222
@ e_linear
Definition BaseValues.hpp:223
uint8_t uint01
-Defines an alias representing a 1 byte, unsigned integer -Can represent exact integer values 0 throu...
Definition BaseValues.hpp:80
uint32_t uint04
-Defines an alias representing a 4 byte, unsigned integer -Can represent exact integer values 0 throu...
Definition BaseValues.hpp:96
constexpr t_to cast(const Angle< t_from > &value)
Definition Angle.h:375
constexpr Angle< t_angle_type > abs(const Angle< t_angle_type > &value)
Changes an input with a negative sign, to a positive sign.
Definition AngleFunctions.h:645
@ Y
Definition BaseValues.hpp:169
@ X
Definition BaseValues.hpp:167
@ Z
Definition BaseValues.hpp:171
double fltp08
Defines an alias representing an 8 byte floating-point number.
Definition BaseValues.hpp:149
Defines for a given type (such as sint04, fltp08, UUID, etc) a maximum, minimum, and reserved 'invali...
Definition BaseValues.hpp:233