DAVID4 SDK  1.8.7
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Groups Pages
TimedScans.cpp
1 /// @example TimedScans.cpp
2 ///
3 /// Takes a scan every x minute.
4 
5 #include "davidSDK/david.h"
6 
7 #include <time.h>
8 #include <iostream>
9 #include <chrono>
10 #include <thread>
11 
12 namespace examples {
13 
14 
15 /// Take a scan every 'waitTimeInSeconds' seconds.
16 /// This example assumes that the scanner is calibrated and camera and projector are connected and correctly configured.
17 /// The scans are saved in the current directory.
18 ///
19 /// @param[in] waitTimeInSeconds Wait time in seconds until next scan.
20 /// @param[in] scanCount Total number of scans to be taken.
21 void main_TimedScans(double waitTimeInSeconds, int scanCount)
22 {
23  try
24  {
25  david::Client david;
26  david.Connect();
27  david.fusion().DeleteAllMeshes();
28 
29  for (int i=0; i < scanCount; ++i)
30  {
31  // Get filename and save current time.
32  time_t begin = time(0);
33  std::string filename;
34  {
35  tm tstruct;
36 #ifdef _WIN32
37  localtime_s(&tstruct, &begin);
38 #else
39  tstruct = *localtime(&begin);
40 #endif
41  char buf[80];
42  strftime(buf, sizeof(buf), "%Y-%m-%d_%H-%M-%S", &tstruct);
43 
44  filename = buf;
45  filename += ".obj";
46 
47  std::cout << "filename: " << filename << std::endl;
48  }
49 
50  // Scan and export.
51  david.sls().Scan();
52  david.sls().ExportMesh(filename);
53  david.sls().AddScanToShapeFusion();
54 
55  // Wait.
56  double dif = 0.0;
57  while (dif < waitTimeInSeconds)
58  {
59  dif = difftime(time(0), begin);
60  std::this_thread::sleep_for(std::chrono::milliseconds(100));
61  }
62  }
63  }
64  catch (david::Exception& e)
65  {
66  e.PrintError();
67  }
68 }
69 
70 } // namespace