Loading...
Searching...
No Matches
Map.cpp
1// =================================================================================== //
2// INCLUDES //
3// =================================================================================== //
4#include "tree_constants.hpp"
5#include "Map.hpp"
6#include <cmath>
7
8namespace bitpit {
9
10// =================================================================================== //
11// NAME SPACES //
12// =================================================================================== //
13using namespace std;
14
15// =================================================================================== //
16// CLASS IMPLEMENTATION //
17// =================================================================================== //
18
19// =================================================================================== //
20// CONSTRUCTORS AND OPERATORS
21// =================================================================================== //
22
25Map::Map(){
26 initialize();
27};
28
33Map::Map(uint8_t dim){
34 initialize(dim);
35};
36
37// =================================================================================== //
38// METHODS
39// =================================================================================== //
40
43void Map::initialize(){
44 initialize(0);
45}
46
51void Map::initialize(uint8_t dim){
52 m_dim = dim;
53
54 m_origin[0] = 0.;
55 m_origin[1] = 0.;
56 m_origin[2] = 0.;
57
58 m_L = 1.0;
59
60 if (m_dim > 0) {
61 const TreeConstants &treeConstants = TreeConstants::instance(m_dim);
62
63 m_nnodes = treeConstants.nNodes;
64 m_nnodesPerFace = treeConstants.nNodesPerFace;
65
66 m_maxLength = treeConstants.lengths[0];
67 m_maxArea = treeConstants.areas[0];
68 m_maxVolume = treeConstants.volumes[0];
69
70 m_maxLength_1 = 1. / double(m_maxLength);
71 m_maxArea_1 = 1. / double(m_maxArea);
72 m_maxVolume_1 = 1. / double(m_maxVolume);
73 } else {
74 m_nnodes = 0;
75 m_nnodesPerFace = 0;
76
77 m_maxLength = 0;
78 m_maxArea = 0;
79 m_maxVolume = 0;
80
81 m_maxLength_1 = std::numeric_limits<double>::infinity();
82 m_maxArea_1 = std::numeric_limits<double>::infinity();
83 m_maxVolume_1 = std::numeric_limits<double>::infinity();
84 }
85
86};
87
92darray3 Map::mapCoordinates(u32array3 const & X) const {
93 darray3 coords;
94 for (int i=0; i<3; ++i){
95 coords[i] = m_maxLength_1 * double(X[i]);
96 }
97 return coords;
98};
99
104double Map::mapX(uint32_t X) const {
105 return m_maxLength_1 * double(X);
106};
107
112double Map::mapY(uint32_t Y) const {
113 return m_maxLength_1 * double(Y);
114};
115
120double Map::mapZ(uint32_t Z) const {
121 return m_maxLength_1 * double(Z);
122};
123
128u32array3 Map::mapCoordinates(darray3 const & X) const {
129 u32array3 coords = {{0, 0, 0}};
130 for (int i=0; i<3; ++i){
131 coords[i] = (uint32_t)(double(m_maxLength) * X[i]);
132 }
133 return coords;
134};
135
140uint32_t Map::mapX(double X) const {
141 return (uint32_t)(double(m_maxLength) * X);
142};
143
148uint32_t Map::mapY(double Y) const {
149 return (uint32_t)(double(m_maxLength) * Y);
150};
151
156uint32_t Map::mapZ(double Z) const {
157 return (uint32_t)(double(m_maxLength) * Z);
158};
159
164double Map::mapSize(uint32_t size) const {
165 return m_maxLength_1 *double(size);
166};
167
172double Map::mapArea(uint64_t area) const {
173 return m_maxArea_1*double(area);
174};
175
180double Map::mapVolume(uint64_t volume) const {
181 return m_maxVolume_1*double(volume);
182};
183
188void Map::mapCenter(double* & center, darray3 & mapcenter) const {
189 for (int i=0; i<3; i++){
190 mapcenter[i] = m_maxLength_1 * center[i];
191 }
192};
193
198void Map::mapCenter(darray3 & center, darray3 & mapcenter) const {
199 for (int i=0; i<3; i++){
200 mapcenter[i] = m_maxLength_1 * center[i];
201 }
202};
203
208void Map::mapNodes(uint32_t (*nodes)[3], darr3vector & mapnodes) const {
209 mapnodes.resize(m_nnodes);
210 for (int i=0; i<m_nnodes; i++){
211 for (int j=0; j<3; j++){
212 mapnodes[i][j] = m_maxLength_1 * double(nodes[i][j]);
213 }
214 }
215};
216
221void Map::mapNodes(u32arr3vector nodes, darr3vector & mapnodes) const {
222 mapnodes.resize(m_nnodes);
223 for (int i=0; i<m_nnodes; i++){
224 for (int j=0; j<3; j++){
225 mapnodes[i][j] = m_maxLength_1 * double(nodes[i][j]);
226 }
227 }
228};
229
234void Map::mapNode(u32array3 & node, darray3 & mapnode) const {
235 for (int j=0; j<3; j++){
236 mapnode[j] = m_maxLength_1 * double(node[j]);
237 }
238};
239
244void Map::mapNodesIntersection(uint32_t (*nodes)[3], darr3vector & mapnodes) const {
245 mapnodes.resize(m_nnodesPerFace);
246 for (int i=0; i<m_nnodesPerFace; i++){
247 for (int j=0; j<3; j++){
248 mapnodes[i][j] = m_maxLength_1 * double(nodes[i][j]);
249 }
250 }
251};
252
257void Map::mapNodesIntersection(u32arr3vector nodes, darr3vector & mapnodes) const {
258 mapnodes.resize(m_nnodesPerFace);
259 for (int i=0; i<m_nnodesPerFace; i++){
260 for (int j=0; j<3; j++){
261 mapnodes[i][j] = m_maxLength_1 * double(nodes[i][j]);
262 }
263 }
264};
265
270void Map::mapNormals(i8array3 normal, darray3 & mapnormal) const {
271 mapnormal[0] = double(normal[0]);
272 mapnormal[1] = double(normal[1]);
273 mapnormal[2] = double(normal[2]);
274};
275
276}
static BITPIT_PUBLIC_API const TreeConstants & instance(uint8_t dim)
--- layout: doxygen_footer ---