Openholo  v4.2
Open Source Digital Holographic Library
examWRP.cpp
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 #include <iostream>
47 #include <string>
48 #include <filesystem>
49 #include <ctime>
50 
51 #include "ophWRP.h"
52 
53 namespace fs = std::experimental::filesystem;
54 
55 int main() {
56  // Create ophWRP instance
57  ophWRP* Hologram = new ophWRP();
58 
59  std::string proj_dir = fs::current_path().generic_string();
60  std::string conf_file = proj_dir + "/../dataset/Dice/WRP/Dice_WRP.xml";
61 
62  // Read Config Parameters for Point Cloud CGH based WRP algorism
63  if (!Hologram->readConfig(conf_file.c_str())) {
64  std::cerr << "Fail to load Config file : " << conf_file << std::endl;
65  exit(1);
66  }
67 
68  // Load Point Cloud Data(*.PLY)
69  std::string wrp_file = proj_dir + "/../dataset/Dice/WRP/dice_100000.ply";
70  if (Hologram->loadPointCloud(wrp_file.c_str()) < 0) {
71  std::cerr << "Fail to load WRP file : " << wrp_file << std::endl;
72  exit(1);
73  }
74 
75  // CGH from WRP
76  Hologram->generateHologram();
77 
78  // Save to ohc(Openholo complex field file format)
79  std::string res_path = "./result/";
80  if (!fs::exists(res_path)) {
81  fs::create_directories(res_path);
82  }
83 
84  //
85  time_t cur_time = time(nullptr);
86 
87  struct tm local;
88 #ifdef _MSC_VER
89  localtime_s(&local, &cur_time);
90 #else
91  localtime_r(&cur_time, &local);
92 #endif
93 
94  char buff[32];
95 #ifdef _MSC_VER
96  sprintf_s(buff, "%4d%02d%02d-%02d%02d%02d",
97  local.tm_year + 1900, local.tm_mon + 1, local.tm_mday,
98  local.tm_hour, local.tm_min, local.tm_sec);
99 #else
100  sprintf(buff, "%4d%02d%02d-%02d%02d%02d",
101  local.tm_year + 1900, local.tm_mon + 1, local.tm_mday,
102  local.tm_hour, local.tm_min, local.tm_sec);
103 #endif
104 
105  std::string ohc_file = res_path + "wrp_sample_" + std::string(buff) + ".ohc";
106  if (!Hologram->saveAsOhc(ohc_file.c_str())) {
107  std::cerr << "Fail to save OHC file : " << ohc_file << std::endl;
108  exit(1);
109  }
110 
111  // Encode Complex Field to Real Field
112  Hologram->encoding(Hologram->ENCODE_PHASE);
113 
114  // Normalize Real Field to unsigned char(0~255) for save to image(*.BMP)
115  Hologram->normalize();
116 
117  // Save to bmp
118  std::string bmp_file = res_path + "wrp_sample_" + std::string(buff) + ".bmp";
119  if (!Hologram->save(bmp_file.c_str())) {
120  std::cerr << "Fail to save BMP file : " << bmp_file << std::endl;
121  exit(1);
122  }
123 
124  // Release memory used to Generate WRP
125  Hologram->release();
126 
127  return 0;
128 }
int main()
Definition: examWRP.cpp:55
Definition: ophWRP.h:114
virtual bool readConfig(const char *fname)
load to configuration file.
Definition: ophWRP.cpp:136
void normalize(void)
Normalization function to save as image file after hologram creation.
Definition: ophGen.cpp:677
void encoding(unsigned int ENCODE_FLAG)
Encoding Functions.
Definition: ophGen.cpp:839
bool save(const char *fname, uint8_t bitsperpixel=8, uchar *src=nullptr, uint px=0, uint py=0)
Function for saving image files.
virtual int loadPointCloud(const char *pc_file)
load to point cloud data.
Definition: ophWRP.cpp:128
virtual bool saveAsOhc(const char *fname)
Function to write OHC file
Definition: Openholo.cpp:252
unsigned long release(void)
Call release() when reference is finished.
Definition: Base.h:88
void generateHologram(void)
Generate a hologram, main funtion.
Definition: ophWRP.cpp:434