SPHinXsys  alpha version
image_mhd.h
1 /* -------------------------------------------------------------------------*
2 * SPHinXsys *
3 * --------------------------------------------------------------------------*
4 * SPHinXsys (pronunciation: s'finksis) is an acronym from Smoothed Particle *
5 * Hydrodynamics for industrial compleX systems. It provides C++ APIs for *
6 * physical accurate simulation and aims to model coupled industrial dynamic *
7 * systems including fluid, solid, multi-body dynamics and beyond with SPH *
8 * (smoothed particle hydrodynamics), a meshless computational method using *
9 * particle discretization. *
10 * *
11 * SPHinXsys is partially funded by German Research Foundation *
12 * (Deutsche Forschungsgemeinschaft) DFG HU1527/6-1, HU1527/10-1 *
13 * and HU1527/12-1. *
14 * *
15 * Portions copyright (c) 2017-2020 Technical University of Munich and *
16 * the authors' affiliations. *
17 * *
18 * Licensed under the Apache License, Version 2.0 (the "License"); you may *
19 * not use this file except in compliance with the License. You may obtain a *
20 * copy of the License at http://www.apache.org/licenses/LICENSE-2.0. *
21 * *
22 * --------------------------------------------------------------------------*/
30 #ifndef IMAGE_MHD_H
31 #define IMAGE_MHD_H
32 
33 #ifndef __EMSCRIPTEN__
34 
35 #include "vector_functions.h"
36 #include "sph_data_containers.h"
37 
38 #include <iostream>
39 #include <string>
40 #include <fstream>
41 
42 namespace SPH {
43 
44  enum Image_Data_Type
45  {
46  MET_FLOAT,
47  MET_UCHAR,
48  MET_LONG
49  };
50 
51  enum Output_Mode
52  {
53  BINARY,
54  ASCII
55  };
56 
57  template <typename T, int nDims>
58  class ImageMHD
59  {
60  public:
61  ImageMHD() {};
62  // constructor for input files
63  ImageMHD(std::string full_path_file);
64  // constructor for sphere
65  ImageMHD(Real radius, Vec3i dxdydz, Vec3d spacings);
66  ~ImageMHD();
67 
68  void set_objectType(std::string objectType)
69  {
70  objectType_ = objectType;
71  };
72 
73  void set_binaryData(bool binaryData)
74  {
75  binaryData_ = binaryData;
76  };
77  void set_binaryDataByteOrderMSB(bool binaryDataByteOrderMSB)
78  {
79  binaryDataByteOrderMSB_ = binaryDataByteOrderMSB;
80  };
81  void set_compressedData(bool compressedData)
82  {
83  compressedData_ = compressedData;
84  };
85  void set_transformMatrix(Mat3d transformMatrix)
86  {
87  transformMatrix_ = transformMatrix;
88  };
89  void set_offset(Vec3d offset)
90  {
91  offset_ = offset;
92  };
93  void set_centerOfRotation(Vec3d centerOfRotation)
94  {
95  centerOfRotation_ = centerOfRotation;
96  };
97  void set_elementSpacing(Vec3d elementSpacing)
98  {
99  elementSpacing_ = elementSpacing;
100  };
101  void set_dimSize(Vec3d dimSize)
102  {
103  dimSize_ = dimSize;
104  };
105  void set_anatomicalOrientation(std::string anatomicalOrientation)
106  {
107  anatomicalOrientation_ = anatomicalOrientation;
108  };
109  void set_elementType(std::string elementType)
110  {
111  elementType_ = elementType;
112  };
113  void set_elementDataFile(std::string elementDataFile)
114  {
115  elementDataFile_ = elementDataFile;
116  };
117 
118  T* get_data() { return data_; };
119 
120  int get_size() { return size_; }
121 
122  Real get_min_value() { return min_value_; };
123  Real get_max_value() { return max_value_; };
124 
125  Vec3d findClosestPoint(const Vec3d& input_pnt);
126  BoundingBox findBounds();
127  Real findValueAtPoint(const Vec3d& input_pnt);
128  Vec3d findNormalAtPoint(const Vec3d & input_pnt);
129 
130  void write(std::string filename, Output_Mode=BINARY);
131 
132  private:
133  std::string objectType_;
134  int ndims_;
135  bool binaryData_;
136  bool binaryDataByteOrderMSB_;
137  bool compressedData_;
138  Mat3d transformMatrix_;
139  Vec3d offset_;
140  Vec3d centerOfRotation_;
141  Vec3d elementSpacing_;
142  Vec3i dimSize_;
143  int width_;
144  int height_;
145  int depth_;
146  int size_;
147  std::string anatomicalOrientation_;
148  Image_Data_Type elementType_;
149  std::string elementDataFile_;
150  Real min_value_;
151  Real max_value_;
152  T *data_;
153 
154  std::vector<int> findNeighbors(const Vec3d& input_pnt, Vec3i& this_cell);
155  Vec3d computeGradientAtCell(int i);
156  Vec3d computeNormalAtCell(int i);
157  T getValueAtCell(int i);
158  Vec3d convertToPhysicalSpace(Vec3d p);
159  void split(const std::string &s, char delim, std::vector<std::string> &elems);
160  };
161 
162 }
163 
164 #include "image_mhd.hpp"
165 
166 #endif //__EMSCRIPTEN__
167 
168 #endif //IMAGE_MHD_H
Definition: image_mhd.h:58
Set up of basic data structure.
Definition: solid_body_supplementary.cpp:9