Openholo  v1.0
Open Source Digital Holographic Library
ImgCodecOhc.h
Go to the documentation of this file.
1 /*M///////////////////////////////////////////////////////////////////////////////////////
2 //
3 // IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
4 //
5 // By downloading, copying, installing or using the software you agree to this license.
6 // If you do not agree to this license, do not download, install, copy or use the software.
7 //
8 //
9 // License Agreement
10 // For Open Source Digital Holographic Library
11 //
12 // Openholo library is free software;
13 // you can redistribute it and/or modify it under the terms of the BSD 2-Clause license.
14 //
15 // Copyright (C) 2017-2024, Korea Electronics Technology Institute. All rights reserved.
16 // E-mail : contact.openholo@gmail.com
17 // Web : http://www.openholo.org
18 //
19 // Redistribution and use in source and binary forms, with or without modification,
20 // are permitted provided that the following conditions are met:
21 //
22 // 1. Redistribution's of source code must retain the above copyright notice,
23 // this list of conditions and the following disclaimer.
24 //
25 // 2. Redistribution's in binary form must reproduce the above copyright notice,
26 // this list of conditions and the following disclaimer in the documentation
27 // and/or other materials provided with the distribution.
28 //
29 // This software is provided by the copyright holders and contributors "as is" and
30 // any express or implied warranties, including, but not limited to, the implied
31 // warranties of merchantability and fitness for a particular purpose are disclaimed.
32 // In no event shall the copyright holder or contributors be liable for any direct,
33 // indirect, incidental, special, exemplary, or consequential damages
34 // (including, but not limited to, procurement of substitute goods or services;
35 // loss of use, data, or profits; or business interruption) however caused
36 // and on any theory of liability, whether in contract, strict liability,
37 // or tort (including negligence or otherwise) arising in any way out of
38 // the use of this software, even if advised of the possibility of such damage.
39 //
40 // This software contains opensource software released under GNU Generic Public License,
41 // NVDIA Software License Agreement, or CUDA supplement to Software License Agreement.
42 // Check whether software you use contains licensed software.
43 //
44 //M*/
45 
46 #ifndef __ImgCodecOhc_h
47 #define __ImgCodecOhc_h
48 
49 #include <fstream>
50 #include "include.h"
51 #include "mat.h"
52 #include "vec.h"
53 
54 #include "ImgCodecDefine.h"
55 
56 #ifdef OPH_EXPORT
57 #define OPH_DLL __declspec(dllexport)
58 #else
59 #define OPH_DLL __declspec(dllimport)
60 #endif
61 
62 namespace oph
63 {
65  public: /* method */
66  ImgCodecOhc();
67  ImgCodecOhc(const std::string &_fname);
68  ImgCodecOhc(const std::string &_fname, const ohcHeader &_Header);
69  virtual ~ImgCodecOhc() = 0;
70  virtual void initOHCheader();
71  virtual void releaseFldData();
72  void releaseOHCheader();
73  void releaseCodeBuffer();
74 
75  bool setFileName(const std::string &_fname);
76  bool setOHCheader(const ohcHeader &_Header);
77 
78  void getOHCheader(ohcHeader &_Header);
79  void getFieldInfo(ohcFieldInfoHeader &_FieldInfo, std::vector<double_t> &_wavlenTable);
80 
81  void getComplexFieldData(OphComplexField& cmplx_field, uint wavelen_idx) { cmplx_field = field_cmplx[wavelen_idx]; }
82  void getComplexFieldData(Complex<Real>** cmplx_field, uint wavelen_idx);
83 
84  void getComplexFieldData(OphComplexField** cmplx_field);
85  void getComplexFieldData(Complex<Real>*** cmplx_field);
86 
87 
88  protected: /* field */
89  std::string fname;
90  //void* buf = nullptr; //coded data
91  float* buf_f32 = nullptr; //coded data
92  double* buf_f64 = nullptr; //coded data
93  std::vector<OphComplexField> field_cmplx; //Real & Imagine data
94  std::vector<std::string> linkFilePath;
95 
96  ohcHeader* Header = nullptr;
97  };
98 
99 
100  /* Load *.ohc file format to Complex field data */
102  public:
103  ImgDecoderOhc();
104  ImgDecoderOhc(const std::string &_fname);
105  ImgDecoderOhc(const std::string &_fname, const ohcHeader &_Header);
106  virtual ~ImgDecoderOhc();
107  virtual void releaseFldData();
108 
109  //Get field Info parameters functions
110  ivec2 getNumOfPixel();
111  vec2 getPixelPitch();
112  LenUnit getPixelPitchUnit();
113  uint getNumOfWavlen();
114  ColorType getColorType();
115  ColorArran getColorArrange();
116  LenUnit getUnitOfWavlen();
117  CompresType getCompressedFormatType();
118  void getWavelength(std::vector<double_t> &wavlen_array);
119  void getLinkFilePath(std::vector<std::string> &linkFilePath_array);
120 
121  bool load();
122 
123  protected:
124  void fieldToComplex(void);
125 
126  bool bLoadFile = false;
127  //template<typename T> bool decodeFieldData();
128  //template<typename T> Real decodePhase(const T phase, const Real min_p, const Real max_p, const double min_T, const double max_T);
129  bool decodeFieldData();
130 
131  //Only Amplitude Encoding or Only Phase Encoding or Amplitude & Phase data
132  std::vector<OphRealField> field_ampli;
133  std::vector<OphRealField> field_phase;
134  std::ifstream File;
135  };
136 
137 
138  /* Save Complex field data to *.ohc file format */
140  public:
141  ImgEncoderOhc();
142  ImgEncoderOhc(const std::string &_fname);
143  ImgEncoderOhc(const std::string &_fname, const ohcHeader &_Header);
144  virtual ~ImgEncoderOhc();
145  void initOHCheader();
146 
147  //Set field Info parameters functions
148  void setNumOfPixel(const uint _pxNumX, const uint _pxNumY);
149  void setNumOfPixel(const ivec2 _pxNum);
150  void setPixelPitch(const double _pxPitchX, const double _pxPitchY, const LenUnit unit = LenUnit::m);
151  void setPixelPitch(const vec2 _pxPitch, const LenUnit unit = LenUnit::m);
152  void setNumOfWavlen(const uint n_wavlens);
153  void setWavelength(const Real _wavlen, const LenUnit _unit = LenUnit::m);
154  void setColorType(const ColorType _clrType);
155  void setColorArrange(const ColorArran _clrArrange);
156  void setUnitOfWavlen(const LenUnit unit);
157  void setFieldEncoding(const FldStore _fldStore, const FldCodeType _fldCodeType); //const DataType _cmplxFldType = DataType::Float64);
158  void setPhaseEncoding(const BPhaseCode _bPhaseCode, const double _phaseCodeMin, const double _phaseCodeMax);
159  void setPhaseEncoding(const BPhaseCode _bPhaseCode, const vec2 _phaseCodeRange);
160  //void setCompressedFormatType(const CompresType _comprsType);
161 
162  void addWavelengthNComplexFieldData(const Real wavlen, const OphComplexField &data);
163  void addComplexFieldData(const OphComplexField &data);
164  void addComplexFieldData(const Complex<Real> *data);
165  void addWavelength(const Real wavlen);
166  void clearWavelength();
167  //void addLinkFilePath(const std::string &path);
168 
169  bool save();
170 
171  protected:
172  //template<typename T> uint64_t encodeFieldData();
173  //template<typename T> T encodePhase(const Real phase_angle, const Real min_p, const Real max_p, const double min_T, const double max_T);
174  uint64_t encodeFieldData();
175 
176  std::ofstream File;
177  };
178 }
179 
180 #endif // !__ImgCodecOhc_h
std::vector< std::string > linkFilePath
Definition: ImgCodecOhc.h:94
float Real
Definition: typedef.h:55
std::vector< OphComplexField > field_cmplx
Definition: ImgCodecOhc.h:93
void getComplexFieldData(OphComplexField &cmplx_field, uint wavelen_idx)
Definition: ImgCodecOhc.h:81
std::ofstream File
Definition: ImgCodecOhc.h:176
#define OPH_DLL
Definition: ImgCodecOhc.h:59
oph::matrix< Complex< Real > > OphComplexField
Definition: mat.h:421
std::string fname
Definition: ImgCodecOhc.h:89
std::vector< OphRealField > field_phase
Definition: ImgCodecOhc.h:133
std::ifstream File
Definition: ImgCodecOhc.h:134
std::vector< OphRealField > field_ampli
Definition: ImgCodecOhc.h:132
Definition: Bitmap.h:49
unsigned int uint
Definition: typedef.h:62
vec2 unit(const vec2 &a)
Definition: vec.h:426