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 template<uint01 t_dims>
40 {
41 public:
43 {
44 lib_assert(location < m_size, "Out of bounds grid conversion lookup");
45 switch (t_dims)
46 {
47 case 1: return location[X];
48 case 2: return m_size[X] * location[Y] + location[X];
49 case 3: return m_size[X] * m_size[Y] * location[Z] + m_size[X] * location[Y] + location[X];
50 }
52 }
54 {
55 Vector<t_dims, uint04> vec_location;
56 switch (t_dims)
57 {
58 case 1:
59 vec_location[X] = location;
60 break;
61 case 2:
62 vec_location[Y] = location / m_size[X];
63 vec_location[X] = location % m_size[X];
64 break;
65 case 3:
66 vec_location[Z] = location / (m_size[X] * m_size[Y]);
67 vec_location[Y] = (location / m_size[X]) % m_size[Y];
68 vec_location[X] = location % m_size[X];
69 break;
70 }
71 lib_assert(vec_location < m_size, "Out of bounds grid conversion lookup");
72 return vec_location;
73 }
74 static constexpr uint01 getNumberOfCorners()
75 {
76 switch (t_dims)
77 {
78 case 1: return 2;
79 case 2: return 4;
80 case 3: return 8;
81 }
83 }
85 {
86 m_size = index_size;
87 }
88 protected:
90 };
91 template<uint01 t_dims>
92 class GridMesh : public GridIndexing<t_dims>
93 {
94 public:
96 {}
97 explicit GridMesh(const Geometry& model)
98 : m_geo(model)
99 {}
100 bool isValid() const
101 {
102 return m_geo.isValid();
103 }
105 , Geometry::VertexMode position
112 {
114 //m_geo.setGeometryType(t_dims == 2 ? GeometryType::e_grids : GeometryType::e_block_models);
116 uint04 count = index_size.product();
117 m_geo.setupVertexTable(count, position, normal, color, texture, tangent, bitangent, bones);
118 BitFlag flag(0);
121 //flag(VertexBitFlags::e_, true);
123 for (uint04 i = 0; i < count; i++)
124 {
125 iterator.setFlag(i, flag);
127 }
129 //m_geo.addPrimitive(PrimitiveProperty::Solid, index_size);
130 }
132 {
134 }
135
136
137 template<class t_type>
138 void setVertex(VertexProperty property, Vector<t_dims, uint04> index, const t_type& vector)
139 {
140 m_geo.setVertex(property, GridIndexing<t_dims>::convertToIndex(index), vector);
141 }
142
143 template<class t_type>
144 t_type vertex(VertexProperty property, Vector<t_dims, uint04> index) const
145 {
146 return m_geo.vertex<t_type>(property, GridIndexing<t_dims>::convertToIndex(index));
147 }
148
149 template<class t_type>
150 void setVertexProperty(uint04 property_index, Vector<t_dims, uint04> index, const t_type& value)
151 {
152 m_geo.setProperty(property_index, GridIndexing<t_dims>::convertToIndex(index), value);
153 }
154
155 template<class t_type>
156 t_type getVertexProperty(uint04 property_index, Vector<t_dims, uint04> index) const
157 {
159 }
160
161 template<class t_type>
163 {
165 for (uint01 dim = 0; dim < t_dims; dim++)
166 {
167 if (index[dim] < 0 || index[dim] > size[dim])
169 }
170 Vector<t_dims, uint04> discrete = index.template as<t_dims, uint04>();
171 Vector<t_dims, fltp08> dt = index - discrete.template as<t_dims, fltp08>();
172
173 if (dt == Vector<t_dims, fltp08>(0.0) || interpolation == InterpolationValues::nearest_neighbor)
174 return vertex<t_type>(property, discrete);
175
177 for (uint01 i = 0; i < GridIndexing<t_dims>::getNumberOfCorners(); i++)
178 {
179 Vector<t_dims, uint04> location_sum(0);
180 if constexpr (t_dims >= 3)
181 location_sum[Z] = (i / 4) % 2;
182 if constexpr (t_dims >= 2)
183 location_sum[Y] = (i / 2) % 2;
184 if constexpr (t_dims >= 1)
185 location_sum[X] = (i / 1) % 2;
186 if (discrete[X] == size[X] - 1)
187 location_sum[X] = 0;
188 if (discrete[Y] == size[Y] - 1)
189 location_sum[Y] = 0;
190 center[i] = vertex<t_type>(property, discrete + location_sum);
191 }
192
193 if (isNaN(center))
194 {
196 }
197 else if (interpolation == InterpolationValues::e_linear)
198 {
199 t_type value = 0;
200 for (uint01 i = 0; i < GridIndexing<t_dims>::getNumberOfCorners(); i++)
201 {
202 Vector<t_dims, uint04> location_sum(0);
203 if constexpr (t_dims >= 3)
204 location_sum[Z] = (i / 4) % 2;
205 if constexpr (t_dims >= 2)
206 location_sum[Y] = (i / 2) % 2;
207 if constexpr (t_dims >= 1)
208 location_sum[X] = (i / 1) % 2;
209 Vector<t_dims, fltp08> location_s = (discrete + location_sum).template as<t_dims, fltp08>();
210 Vector<t_dims, fltp08> difference = (1.0 - abs(location_s - index));
211 value += center[i] * difference.product();
212 }
213 return value;
214 }
215 else//bicubic
216 {
217 /*const uint04 d10 = getZ(discrete_x - 1, discrete_y + 0, d11);
218 const uint04 d13 = getZ(discrete_x + 2, discrete_y + 0, d12);
219 const uint04 d20 = getZ(discrete_x - 1, discrete_y + 1, d21);
220 const uint04 d23 = getZ(discrete_x + 2, discrete_y + 1, d22);
221
222 const uint04 d00 = getZ(discrete_x - 1, discrete_y - 1, d10);
223 const uint04 d01 = getZ(discrete_x - 0, discrete_y - 1, d11);
224 const uint04 d02 = getZ(discrete_x + 1, discrete_y - 1, d12);
225 const uint04 d03 = getZ(discrete_x + 2, discrete_y - 1, d02);
226
227 const uint04 d30 = getZ(discrete_x - 1, discrete_y + 2, d20);
228 const uint04 d31 = getZ(discrete_x - 0, discrete_y + 2, d21);
229 const uint04 d32 = getZ(discrete_x + 1, discrete_y + 2, d22);
230 const uint04 d33 = getZ(discrete_x + 2, discrete_y + 2, d23);
231
232 const fltp08 p0 = (d01 + 0.5 * dx
233 * (d02 - d00 + dx * (2.0 * d00 - 5.0 * d01 + 4.0 * d02 - d03 + dx * (3.0 * (d01 - d02) + d03 - d00))));
234 const fltp08 p1 = (d11 + 0.5 * dx
235 * (d12 - d10 + dx * (2.0 * d10 - 5.0 * d11 + 4.0 * d12 - d13 + dx * (3.0 * (d11 - d12) + d13 - d10))));
236 const fltp08 p2 = (d21 + 0.5 * dx
237 * (d22 - d20 + dx * (2.0 * d20 - 5.0 * d21 + 4.0 * d22 - d23 + dx * (3.0 * (d21 - d22) + d23 - d20))));
238 const fltp08 p3 = (d31 + 0.5 * dx
239 * (d32 - d30 + dx * (2.0 * d30 - 5.0 * d31 + 4.0 * d32 - d33 + dx * (3.0 * (d31 - d32) + d33 - d30))));
240
241 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))));*/
242 }
244 }
245 Geometry geometry() const { return m_geo; };
246 protected:
248 };
249};
250
251
252
253
#define lib_assert(expression, message)
Asserts some logic in the code. Disabled in non debug mode by default. Can be re-enabled in release u...
Definition LibAssert.h:70
A bitset that stores 8 bits (elements with only two possible values: 0 or 1, true or false,...
Definition BitFlag.hpp:68
bool isValid() const
Definition DesignObject.h:362
t_type getProperty(DesignProperty property) const
Definition DesignObject.h:263
void setProperty(DesignProperty property, const t_type &value)
Definition DesignObject.h:184
Definition Geometry.h:64
void updateVertexColumns(bool invalidate_bounds=true, bool erase_kd_tree=true)
Definition Geometry.cpp:2206
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)
Definition Geometry.cpp:1203
void setGeometryType(GeometryType geometry_type)
Definition Geometry.cpp:1016
void setVertex(VertexProperty property, uint04 index, const t_type &vector)
Definition Geometry.h:871
Definition GriddedMesh.h:40
Vector< t_dims, uint04 > convertFromIndex(const uint04 &location) const
Definition GriddedMesh.h:53
static constexpr uint01 getNumberOfCorners()
Definition GriddedMesh.h:74
uint04 convertToIndex(const Vector< t_dims, uint04 > &location) const
Definition GriddedMesh.h:42
void setSize(Vector< t_dims, uint04 > index_size)
Definition GriddedMesh.h:84
Vector< t_dims, uint04 > m_size
Definition GriddedMesh.h:89
Definition GriddedMesh.h:93
void setVertexProperty(uint04 property_index, Vector< t_dims, uint04 > index, const t_type &value)
Definition GriddedMesh.h:150
void setVertex(VertexProperty property, Vector< t_dims, uint04 > index, const t_type &vector)
Definition GriddedMesh.h:138
const Vector< t_dims, uint04 > & getIndexSize() const
Definition GriddedMesh.h:131
GridMesh(const Geometry &model)
Definition GriddedMesh.h:97
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:104
bool isValid() const
Definition GriddedMesh.h:100
t_type interpolateVertex(VertexProperty property, const Vector< t_dims, fltp08 > &index, InterpolationValues interpolation=InterpolationValues::e_linear) const
Definition GriddedMesh.h:162
t_type getVertexProperty(uint04 property_index, Vector< t_dims, uint04 > index) const
Definition GriddedMesh.h:156
Geometry geometry() const
Definition GriddedMesh.h:245
GridMesh()
Definition GriddedMesh.h:95
Geometry m_geo
Definition GriddedMesh.h:247
t_type vertex(VertexProperty property, Vector< t_dims, uint04 > index) const
Definition GriddedMesh.h:144
An element of a vector space. An element of the real coordinate space Rn Basis vector,...
Definition Vector.hpp:62
constexpr t_type product() const
Definition Vector.hpp:526
Definition Geometry.h:1452
void setVertex(uint04 index, const t_type &value)
Definition Geometry.h:1484
void setFlag(uint04 index, const BitFlag &value)
Definition Geometry.h:1488
Definition ACIColor.h:37
VertexProperty
Definition DesignObjectBase.h:52
InterpolationValues
Values that represent interpolation functions. Useful in large or complicated geological or time.
Definition BaseValues.hpp:255
@ nearest_neighbor
Definition BaseValues.hpp:256
@ e_linear
Definition BaseValues.hpp:257
uint8_t uint01
-Defines an alias representing a 1 byte, unsigned integer -Can represent exact integer values 0 throu...
Definition BaseValues.hpp:98
uint32_t uint04
-Defines an alias representing a 4 byte, unsigned integer -Can represent exact integer values 0 throu...
Definition BaseValues.hpp:120
constexpr t_to cast(const Angle< t_from > &value)
Definition Angle.h:514
constexpr Angle< t_angle_type > abs(const Angle< t_angle_type > &value)
Definition AngleFunctions.h:750
constexpr bool isNaN(const t_type &value)
Query if 'value' is valid or invalid.
Definition BaseFunctions.hpp:200
@ Y
Definition BaseValues.hpp:202
@ X
Definition BaseValues.hpp:200
@ Z
Definition BaseValues.hpp:204
double fltp08
Defines an alias representing an 8 byte floating-point number.
Definition BaseValues.hpp:181
Definition BaseValues.hpp:272