Openholo  v4.2
Open Source Digital Holographic Library
examPointCloud.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 <time.h>
50 #include "ophPointCloud.h"
51 
52 namespace fs = std::experimental::filesystem;
53 
54 int main() {
55  // Create ophPointCloud instance
56  ophPointCloud* Hologram = new ophPointCloud();
57 
58  std::string proj_dir = fs::current_path().generic_string();
59  std::string conf_file = proj_dir + "/../dataset/Dice/PointCloud/Dice_PointCloud.xml";
60 
61  // Read Config Parameters for Point Cloud CGH
62  if (!Hologram->readConfig(conf_file.c_str())) {
63  std::cerr << "Fail to load Config file : " << conf_file << std::endl;
64  exit(1);
65  }
66 
67  // Load Point Cloud Data(*.PLY)
68  std::string pc_file = proj_dir + "/../dataset/Dice/PointCloud/dice_100000.ply";
69  if (Hologram->loadPointCloud(pc_file.c_str()) < 0) {
70  std::cerr << "Fail to load Point Cloud file : " << pc_file << std::endl;
71  exit(1);
72  }
73 
74  // Select CPU or GPU Processing
75  // param = MODE_CPU or MODE_GPU
76  Hologram->SetMode(MODE_GPU);
77 
78  // Select R-S diffraction or Fresnel diffraction
79  // param = PC_DIFF_RS or PC_DIFF_FRESNEL
80  Hologram->generateHologram(ophPointCloud::PC_DIFF_FLAG::PC_DIFF_RS);
81 
82  // Save to ohc(Openholo complex field file format)
83  std::string res_path = "./result/";
84  if (!fs::exists(res_path)) {
85  fs::create_directories(res_path);
86  }
87 
88  //
89  time_t cur_time = time(nullptr);
90 
91  struct tm local;
92 #ifdef _MSC_VER
93  localtime_s(&local, &cur_time);
94 #else
95  localtime_r(&cur_time, &local);
96 #endif
97 
98  char buff[32];
99 #ifdef _MSC_VER
100  sprintf_s(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 #else
104  sprintf(buff, "%4d%02d%02d-%02d%02d%02d",
105  local.tm_year + 1900, local.tm_mon + 1, local.tm_mday,
106  local.tm_hour, local.tm_min, local.tm_sec);
107 #endif
108 
109  std::string ohc_file = res_path + "pc_sample_" + std::string(buff) + ".ohc";
110  if (!Hologram->saveAsOhc(ohc_file.c_str())) {
111  std::cerr << "Fail to save OHC file : " << ohc_file << std::endl;
112  exit(1);
113  }
114 
115  // Encode Complex Field to Real Field
116  Hologram->encoding(Hologram->ENCODE_PHASE);
117 
118  // Normalize Real Field to unsigned char(0~255) for save to image(*.BMP)
119  Hologram->normalize();
120 
121  // Save to bmp
122  std::string bmp_file = res_path + "pc_sample_" + std::string(buff) + ".bmp";
123  if (!Hologram->save(bmp_file.c_str())) {
124  std::cerr << "Fail to save BMP file : " << bmp_file << std::endl;
125  exit(1);
126  }
127 
128  // Release memory used to Generate Point Cloud
129  Hologram->release();
130 
131  return 0;
132 }
#define MODE_GPU
Definition: define.h:156
void SetMode(unsigned int mode)
Definition: ophGen.h:538
void normalize(void)
Normalization function to save as image file after hologram creation.
Definition: ophGen.cpp:677
bool save(const char *fname, uint8_t bitsperpixel=8, uchar *src=nullptr, uint px=0, uint py=0)
Function for saving image files.
int loadPointCloud(const char *pc_file)
override
bool readConfig(const char *cfg_file)
Import Specification Config File(*.config) file.
int main()
Openholo Point Cloud based Compter-generated holography.
virtual void encoding(unsigned int ENCODE_FLAG, unsigned int SSB_PASSBAND)
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
Real generateHologram(uint diff_flag=PC_DIFF_RS)
Generate a hologram, main funtion.