Openholo  v5.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 #include "ImgCodecDefine.h"
54 
55 namespace oph
56 {
58  public: /* method */
59  ImgCodecOhc();
60  ImgCodecOhc(const std::string &_fname);
61  ImgCodecOhc(const std::string &_fname, const oph::ohcHeader &_Header);
62  virtual ~ImgCodecOhc() = 0;
63  virtual void initOHCheader();
64  virtual void releaseFldData();
65  void releaseOHCheader();
66  void releaseCodeBuffer();
67 
68  bool setFileName(const std::string &_fname);
69  bool setOHCheader(const oph::ohcHeader &_Header);
70 
71  void getOHCheader(oph::ohcHeader &_Header);
72  void getFieldInfo(oph::ohcFieldInfoHeader &_FieldInfo, std::vector<double_t> &_wavlenTable);
73 
74  void getComplexFieldData(OphComplexField& cmplx_field, uint wavelen_idx) { cmplx_field = field_cmplx[wavelen_idx]; }
75  void getComplexFieldData(Complex<Real>** cmplx_field, uint wavelen_idx);
76 
77  void getComplexFieldData(OphComplexField** cmplx_field);
78  void getComplexFieldData(Complex<Real>*** cmplx_field);
79 
80 
81  protected: /* field */
82  std::string fname;
83  //void* buf = nullptr; //coded data
84  float* buf_f32 = nullptr; //coded data
85  double* buf_f64 = nullptr; //coded data
86  std::vector<OphComplexField> field_cmplx; //Real & Imagine data
87  std::vector<std::string> linkFilePath;
88 
89  oph::ohcHeader* Header = nullptr;
90  };
91 
92 
93  /* Load *.ohc file format to Complex field data */
95  public:
96  ImgDecoderOhc();
97  ImgDecoderOhc(const std::string &_fname);
98  ImgDecoderOhc(const std::string &_fname, const oph::ohcHeader &_Header);
99  virtual ~ImgDecoderOhc();
100  virtual void releaseFldData();
101 
102  //Get field Info parameters functions
103  ivec2 getNumOfPixel();
104  vec2 getPixelPitch();
105  oph::LenUnit getPixelPitchUnit();
106  uint getNumOfWavlen();
107  oph::ColorType getColorType();
108  oph::ColorArran getColorArrange();
109  oph::LenUnit getUnitOfWavlen();
110  oph::CompresType getCompressedFormatType();
111  void getWavelength(std::vector<double_t> &wavlen_array);
112  void getLinkFilePath(std::vector<std::string> &linkFilePath_array);
113 
114  bool load();
115 
116  protected:
117  void fieldToComplex(void);
118 
119  bool bLoadFile = false;
120  //template<typename T> bool decodeFieldData();
121  //template<typename T> Real decodePhase(const T phase, const Real min_p, const Real max_p, const double min_T, const double max_T);
122  bool decodeFieldData();
123 
124  //Only Amplitude Encoding or Only Phase Encoding or Amplitude & Phase data
125  std::vector<OphRealField> field_ampli;
126  std::vector<OphRealField> field_phase;
127  std::ifstream File;
128  };
129 
130 
131  /* Save Complex field data to *.ohc file format */
133  public:
134  ImgEncoderOhc();
135  ImgEncoderOhc(const std::string &_fname);
136  ImgEncoderOhc(const std::string &_fname, const ohcHeader &_Header);
137  virtual ~ImgEncoderOhc();
138  void initOHCheader();
139 
140  //Set field Info parameters functions
141  void setNumOfPixel(const uint _pxNumX, const uint _pxNumY);
142  void setNumOfPixel(const ivec2 _pxNum);
143  void setPixelPitch(const double _pxPitchX, const double _pxPitchY, const LenUnit unit = LenUnit::m);
144  void setPixelPitch(const vec2 _pxPitch, const LenUnit unit = LenUnit::m);
145  void setNumOfWavlen(const uint n_wavlens);
146  void setWavelength(const Real _wavlen, const LenUnit _unit = LenUnit::m);
147  void setColorType(const ColorType _clrType);
148  void setColorArrange(const ColorArran _clrArrange);
149  void setUnitOfWavlen(const LenUnit unit);
150  void setFieldEncoding(const FldStore _fldStore, const FldCodeType _fldCodeType); //const DataType _cmplxFldType = DataType::Float64);
151  void setPhaseEncoding(const BPhaseCode _bPhaseCode, const double _phaseCodeMin, const double _phaseCodeMax);
152  void setPhaseEncoding(const BPhaseCode _bPhaseCode, const vec2 _phaseCodeRange);
153  //void setCompressedFormatType(const CompresType _comprsType);
154 
155  void addWavelengthNComplexFieldData(const Real wavlen, const OphComplexField &data);
156  void addComplexFieldData(const OphComplexField &data);
157  void addComplexFieldData(const Complex<Real> *data);
158  void addWavelength(const Real wavlen);
159  void clearWavelength();
160  //void addLinkFilePath(const std::string &path);
161 
162  bool save();
163 
164  protected:
165  //template<typename T> uint64_t encodeFieldData();
166  //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);
167  uint64_t encodeFieldData();
168 
169  std::ofstream File;
170  };
171 }
172 
173 #endif // !__ImgCodecOhc_h
std::vector< std::string > linkFilePath
Definition: ImgCodecOhc.h:87
float Real
Definition: typedef.h:55
std::vector< OphComplexField > field_cmplx
Definition: ImgCodecOhc.h:86
structure for 2-dimensional integer vector and its arithmetic.
Definition: ivec.h:66
void getComplexFieldData(OphComplexField &cmplx_field, uint wavelen_idx)
Definition: ImgCodecOhc.h:74
#define OPH_DLL
Definition: Base.h:59
std::ofstream File
Definition: ImgCodecOhc.h:169
structure for 2-dimensional Real type vector and its arithmetic.
Definition: vec.h:66
std::string fname
Definition: ImgCodecOhc.h:82
std::vector< OphRealField > field_phase
Definition: ImgCodecOhc.h:126
std::ifstream File
Definition: ImgCodecOhc.h:127
std::vector< OphRealField > field_ampli
Definition: ImgCodecOhc.h:125
Definition: Bitmap.h:49
unsigned int uint
Definition: typedef.h:62
vec2 unit(const vec2 &a)
Definition: vec.h:426