58 #define CUR_TIME std::chrono::system_clock::now() 59 #define ELAPSED_TIME(x,y) ((std::chrono::duration<double>)(y - x)).count() 60 #define CUR_TIME_DURATION CUR_TIME.time_since_epoch() 61 #define CUR_TIME_DURATION_MILLI_SEC std::chrono::duration_cast<std::chrono::milliseconds>(CUR_TIME_DURATION).count() 63 template<
typename type,
typename T>
65 return type(p.real());
68 template<
typename type,
typename T>
75 for (
auto item : arr) {
if (item < min) min = item; }
81 for (
int i = 0; i < size; i++) {
82 if (*(src + i) < min) min = *(src + i);
89 for (
auto item : arr) {
if (item > max) max = item; }
95 for (
int i = 0; i < size; i++) {
96 if (*(src + i) > max) max = *(src + i);
104 for (
int i = 0; i < size; i++) {
120 dst.reserve(src.size());
121 for (
auto item : src) dst.push_back(
oph::abs(item));
126 if (src.getSize() != dst.getSize())
return;
128 for (
int x = 0; x < matSize[
_X]; x++) {
129 for (
int y = 0; y < matSize[
_Y]; y++)
136 dst = sqrt(src.real() * src.real() + src.imag() * src.imag());
141 for (
int i = 0; i < size; i++) {
142 absCplx<T>(*(src + i), *(dst + i));
153 for (
int i = 0; i < size; i++) {
154 *(dst + i) = (src + i)->real();
161 dst.reserve(src.size());
162 for (
auto item : src) { dst.push_back(src.angle()); }
168 dst = atan2(src.imag(), src.real());
178 oph::absCplxArr<Real>(src,
abs, size);
182 for (
int i = 0; i < size; i++) {
183 *(dst + i) = *(src + i) / max;
188 inline void normalize(
const T* src, T* dst,
const int& size) {
193 for (
int i = 0; i < size; i++) {
194 *(dst + i) = (*(src + i) - min) / (max - min);
204 minVal = maxVal = src[0];
205 for (
oph::uint ydx = 0; ydx < ny; ydx++){
206 for (
oph::uint xdx = 0; xdx < nx; xdx++){
207 T *temp_pos = src + xdx + ydx * nx;
208 if ((xdx == 0) && (ydx == 0)) { minVal = *(temp_pos); maxVal = *(temp_pos); }
210 if ((*temp_pos) < minVal) minVal = (*temp_pos);
211 if ((*temp_pos) > maxVal) maxVal = (*temp_pos);
216 for (
oph::uint ydx = 0; ydx < ny; ydx++) {
217 for (
oph::uint xdx = 0; xdx < nx; xdx++) {
218 T *src_pos = src + xdx + ydx * nx;
221 *(res_pos) = oph::force_cast<oph::uchar>(((*(src_pos)-minVal) / (maxVal - minVal)) * 255 + 0.5);
230 inline void normalize(
const std::vector<T>* src, std::vector<oph::uchar>* dst) {
232 if (src->size() != dst->size())
235 dst->reserve(src->size());
238 for (
auto iter = src->begin(); iter != src->end(); iter++) {
239 if (iter == src->begin()) {
243 if (*iter < minVal) minVal = *iter;
244 if (*iter > maxVal) maxVal = *iter;
248 for (
auto iter = src->begin(); iter != src->end(); iter++)
249 dst->push_back(oph::force_cast<oph::uchar>((((*iter) - minVal) / (maxVal - minVal)) * 255 + 0.5));
257 auto iter = pArr->begin() + (beginIndex);
258 auto it_end = pArr->begin() + (endIndex);
259 for (; iter != it_end; iter++) { (*iter) = _Value; }
264 for (
uint i = beginIndex; i <= endIndex; i++) {
265 *(pArr + i) = _Value;
273 inline void circShift(
const T* src, T* dst,
int shift_x,
int shift_y,
int xdim,
int ydim) {
274 for (
int i = 0; i < xdim; i++) {
275 int ti = (i + shift_x) % xdim;
276 if (ti < 0) ti = xdim + ti;
277 for (
int j = 0; j < ydim; j++) {
278 int tj = (j + shift_y) % ydim;
279 if (tj < 0) tj = ydim + tj;
280 dst[ti * ydim + tj] = src[i * ydim + j];
295 std::mt19937_64 rand_dev;
297 else rand_dev = std::mt19937_64(_SEED_VALUE);
299 std::uniform_real_distribution<Real> dist(min, max);
301 return dist(rand_dev);
314 std::mt19937_64 rand_dev;
316 else rand_dev = std::mt19937_64(_SEED_VALUE);
318 std::uniform_int_distribution<int> dist(min, max);
320 return dist(rand_dev);
325 for (
int i = 0; i < size; i++) {
326 *(dst + i) = angle<Real>(*(src + i)) +
M_PI;
331 absCplxArr<Real>(src, dst, size);
341 for (
int x = 0; x < bufferSize[
_X]; x++) {
342 for (
int y = 0; y < bufferSize[
_Y]; y++) {
343 (*dst)[idx] = src[x][y];
351 ivec2 matSize = buffer_size;
354 for (
int x = 0; x < matSize[
_X]; x++) {
355 for (
int y = 0; y < matSize[
_Y]; y++) {
356 dst[x][y] = src[idx];
370 #endif // !__function_h void abs(const oph::Complex< T > &src, oph::Complex< T > &dst)
oph::ivec2 & getSize(void)
class for the complex number and its arithmetic. type T == type cplx type only float || double T real...
void absMat(const oph::matrix< oph::Complex< T >> &src, oph::matrix< oph::Complex< T >> &dst)
void circShift(const T *src, T *dst, int shift_x, int shift_y, int xdim, int ydim)
Shifts the elements by shift_x, shift_y.
Real average(const Real *src, const int &size)
void absCplxArr(const oph::Complex< T > *src, T *dst, const int &size)
#define CUR_TIME_DURATION_MILLI_SEC
structure for 2-dimensional integer vector and its arithmetic.
void getPhase(oph::Complex< Real > *src, Real *dst, const int &size)
void normalize(const Complex< T > *src, Complex< T > *dst, const int &size)
Normalize all elements of Complex<T>* src from 0 to 1.
void realPart(const oph::Complex< T > *src, T *dst, const int &size)
void absArr(const std::vector< Complex< T >> &src, std::vector< oph::Complex< T >> &dst)
void memsetArr(const std::vector< T > *pArr, T _Value, oph::uint beginIndex, oph::uint endIndex)
Set elements to specific values from begin index to end index.
void Field2Buffer(matrix< T > &src, T **dst)
type force_cast(const Complex< T > &p)
T getReal(const oph::Complex< T > src)
Real rand(const Real min, const Real max, oph::ulong _SEED_VALUE=0)
Get random Real value from min to max.
void getAmplitude(oph::Complex< Real > *src, Real *dst, const int &size)
void angle(const std::vector< Complex< T >> &src, std::vector< T > &dst)
Real minOfArr(const std::vector< Real > &arr)
Real maxOfArr(const std::vector< Real > &arr)
void Buffer2Field(const T *src, matrix< T > &dst, const ivec2 buffer_size)
void absCplx(const oph::Complex< T > &src, T &dst)