ScanIOUtils.cpp
Go to the documentation of this file.
1 #include <boost/regex.hpp>
2 #include <opencv2/opencv.hpp>
3 
6 #include "lvr2/io/yaml/Scan.hpp"
13 
14 #include <sstream>
15 
16 namespace lvr2
17 {
18 
19 std::string getSensorType(const boost::filesystem::path& dir)
20 {
21  std::string sensorType = "";
22 
23  // Try to open meta.yaml
24  boost::filesystem::path metaPath = dir / "meta.yaml";
25  if(boost::filesystem::exists(metaPath))
26  {
27  YAML::Node meta = YAML::LoadFile(metaPath.string());
28 
29  // Get sensor type
30  if(meta["sensor_type"])
31  {
32  sensorType = meta["sensor_type"].as<std::string>();
33  }
34  }
35  return sensorType;
36 }
37 
39  const boost::filesystem::path& root,
40  const ScanImage& image,
41  const size_t& positionNumber,
42  const size_t& camNumber,
43  const size_t& imageNumber)
44 {
45  std::stringstream posStr;
46  posStr << std::setfill('0') << std::setw(8) << positionNumber;
47 
48  std::stringstream camStr;
49  camStr << std::setfill('0') << std::setw(8) << camNumber;
50 
51  saveScanImage(root, image, posStr.str(), camStr.str(), imageNumber);
52 }
53 
55  const boost::filesystem::path& root,
56  const ScanImage& image,
57  const std::string positionDirectory,
58  const size_t& cameraNumber,
59  const size_t& imageNumber)
60 {
61  std::stringstream camStr;
62  camStr << std::setfill('0') << std::setw(8) << cameraNumber;
63 
64  saveScanImage(root, image, positionDirectory, camStr.str(), imageNumber);
65 }
66 
67 boost::filesystem::path getScanImageDirectory(
68  boost::filesystem::path root,
69  const std::string positionDirectory,
70  const std::string cameraDirectory)
71 {
72  boost::filesystem::path pos(positionDirectory);
73  boost::filesystem::path cam(cameraDirectory);
74  boost::filesystem::path data("data/");
75  return root / pos /cam / data;
76 }
77 
79  const boost::filesystem::path& root,
80  const ScanImage& image,
81  const std::string positionDirectory,
82  const std::string cameraDirectory,
83  const size_t& imageNumber)
84 {
85  // Some directory parsing stuff
86  std::stringstream metaFileName;
87  metaFileName << std::setfill('0') << std::setw(8) << imageNumber << ".yaml";
88 
89  std::stringstream imageFileName;
90  imageFileName << std::setfill('0') << std::setw(8) << imageNumber << ".png";
91 
92  boost::filesystem::path imageDirectory =
93  getScanImageDirectory(root, positionDirectory, cameraDirectory);
94 
95  if(!boost::filesystem::exists(imageDirectory))
96  {
97  std::cout << timestamp << "Creating: " << imageDirectory << std::endl;
98  boost::filesystem::create_directory(imageDirectory);
99  }
100 
101  boost::filesystem::path imagePath = imageDirectory / imageFileName.str();
102  boost::filesystem::path metaPath = imageDirectory / metaFileName.str();
103 
104  // Write meta information for scan image
105  YAML::Node meta;
106  meta = image;
107 
108  std::ofstream out(metaPath.c_str());
109  if (out.good())
110  {
111  std::cout << timestamp << "Writing " << metaPath << std::endl;
112  out << meta;
113  }
114  else
115  {
116  std::cout << timestamp
117  << "Warning: to write " << metaPath << std::endl;
118  }
119 
120  // Write image data
121  std::cout << timestamp << "Writing " << imagePath << std::endl;
122  cv::imwrite(imagePath.string(), image.image);
123 }
124 
126  const boost::filesystem::path& root,
127  ScanImage& image,
128  const size_t& positionNumber,
129  const size_t& cameraNumber,
130  const size_t& imageNumber)
131 {
132  std::stringstream posStr;
133  posStr << std::setfill('0') << std::setw(8) << positionNumber;
134 
135  std::stringstream camStr;
136  camStr << std::setfill('0') << std::setw(8) << cameraNumber;
137 
138  return loadScanImage(root, image, posStr.str(), camStr.str(), imageNumber);
139 }
140 
142  const boost::filesystem::path& root,
143  ScanImage& image,
144  const std::string& positionDirectory,
145  const size_t& cameraNumber,
146  const size_t& imageNumber)
147 {
148  std::stringstream camStr;
149  camStr << std::setfill('0') << std::setw(8) << cameraNumber;
150 
151  return loadScanImage(root, image, positionDirectory, camStr.str(), imageNumber);
152 }
153 
155  const boost::filesystem::path& root,
156  ScanImage& image,
157  const std::string& positionDirectory,
158  const std::string& cameraDirectory,
159  const size_t& imageNumber)
160 {
161  // Some directory parsing stuff
162  std::stringstream metaFileName;
163  metaFileName << std::setfill('0') << std::setw(8) << imageNumber << ".yaml";
164 
165  std::stringstream imageFileName;
166  imageFileName << std::setfill('0') << std::setw(8) << imageNumber << ".png";
167 
168  boost::filesystem::path imageDirectory =
169  getScanImageDirectory(root, positionDirectory, cameraDirectory);
170 
171  boost::filesystem::path imagePath(imageDirectory / boost::filesystem::path(imageFileName.str()));
172  boost::filesystem::path metaPath(imageDirectory / boost::filesystem::path(metaFileName.str()));
173 
174  // Load meta info
175  std::cout << timestamp << "Loading " << metaPath << std::endl;
176  YAML::Node meta = YAML::LoadFile(metaPath.string());
177  image = meta.as<ScanImage>();
178 
179  // Load image data
180  std::cout << timestamp << "Loading " << imagePath << std::endl;
181  image.imageFile = imagePath;
182  image.image = cv::imread(imagePath.string());
183 
184  return true;
185 }
186 
188  std::vector<ScanImagePtr>& images,
189  boost::filesystem::path dataPath)
190 {
191  bool stop = false;
192  size_t c = 0;
193  while(!stop)
194  {
195  std::stringstream metaStr;
196  metaStr << std::setfill('0') << std::setw(8) << c << ".yaml";
197 
198  std::stringstream pngStr;
199  pngStr << std::setfill('0') << std::setw(8) << c << ".png";
200 
201  boost::filesystem::path metaPath = dataPath / metaStr.str();
202  boost::filesystem::path pngPath = dataPath / pngStr.str();
203 
204  // Check if both .png and corresponding .yaml file exist
205  if(boost::filesystem::exists(metaPath)
206  && boost::filesystem::exists(pngPath) )
207  {
208  // Load meta info
209  ScanImage* image = new ScanImage;
210 
211  std::cout << timestamp << "Loading " << metaPath << std::endl;
212  YAML::Node meta = YAML::LoadFile(metaPath.string());
213 
214  // *image = meta.as<ScanImage>();
215  if(YAML::convert<ScanImage>::decode(meta, *image))
216  {
217  // Load image data
218  std::cout << timestamp << "Loading " << pngPath << std::endl;
219  image->imageFile = pngPath;
220  image->image = cv::imread(pngPath.string());
221 
222  // Store new image
223  images.push_back(ScanImagePtr(image));
224  } else {
225  std::cout << timestamp << "Could not convert " << metaPath << std::endl;
226  }
227 
228  c++;
229  }
230  else
231  {
232  std::cout
233  << timestamp << "Read " << c << " images from " << dataPath << std::endl;
234  stop = true;
235  }
236  }
237 }
238 
242 
243 boost::filesystem::path getScanCameraDirectory(
244  boost::filesystem::path root,
245  const std::string positionDirectory,
246  const std::string cameraDirectory)
247 {
248  boost::filesystem::path pos(positionDirectory);
249  boost::filesystem::path cam(cameraDirectory);
250  return root / pos /cam;
251 }
252 
253 
255  const boost::filesystem::path& root,
256  const ScanCamera& camera,
257  const std::string positionDirectory,
258  const std::string cameraDirectory)
259 {
260  boost::filesystem::path cameraPath =
261  getScanCameraDirectory(root, positionDirectory, cameraDirectory);
262 
263  if(!boost::filesystem::exists(cameraPath))
264  {
265  std::cout << timestamp << "Creating: " << cameraPath << std::endl;
266  boost::filesystem::create_directory(cameraPath);
267  }
268 
269  boost::filesystem::path metaPath(cameraPath / "meta.yaml");
270 
271  // Write meta information of scan camera
272  YAML::Node meta;
273  meta = camera;
274 
275  std::ofstream out(metaPath.c_str());
276  if (out.good())
277  {
278  std::cout << timestamp << "Writing " << metaPath << std::endl;
279  out << meta;
280  }
281  else
282  {
283  std::cout << timestamp
284  << "Warning: Unable to write " << metaPath << std::endl;
285  }
286 
287  // Save all images
288  for(size_t i = 0; i < camera.images.size(); i++)
289  {
290  saveScanImage(root, *camera.images[i], positionDirectory, cameraDirectory, i);
291  }
292 }
293 
295  const boost::filesystem::path& root,
296  const ScanCamera& camera,
297  const std::string& positionDirectory,
298  const size_t& cameraNumber)
299 {
300  std::stringstream camStr;
301  camStr << "cam_" << cameraNumber;
302 
303  return saveScanCamera(root, camera, positionDirectory, camStr.str());
304 }
305 
307  const boost::filesystem::path& root,
308  const ScanCamera& camera,
309  const size_t& positionNumber,
310  const size_t& cameraNumber)
311 {
312  std::stringstream posStr;
313  posStr << std::setfill('0') << std::setw(8) << positionNumber;
314 
315  return saveScanCamera(root, camera, posStr.str(), cameraNumber);
316 }
317 
318 
320  const boost::filesystem::path& root,
321  ScanCamera& camera,
322  const std::string& positionDirectory,
323  const size_t& cameraNumber)
324 {
325  std::stringstream camStr;
326  camStr << std::setfill('0') << std::setw(8) << cameraNumber;
327 
328  return loadScanCamera(root, camera, positionDirectory, camStr.str());
329 }
330 
332  const boost::filesystem::path& root,
333  ScanCamera& camera,
334  const size_t& positionNumber,
335  const size_t& cameraNumber)
336 {
337  std::stringstream posStr;
338  posStr << std::setfill('0') << std::setw(8) << positionNumber;
339 
340  std::stringstream camStr;
341  camStr << std::setfill('0') << std::setw(8) << cameraNumber;
342 
343  return loadScanCamera(root, camera, posStr.str(), camStr.str());
344 }
345 
347  const boost::filesystem::path& root,
348  ScanCamera& camera,
349  const std::string& positionDirectory,
350  const std::string& cameraDirectory)
351 {
352  boost::filesystem::path cameraPath =
353  getScanCameraDirectory(root, positionDirectory, cameraDirectory);
354 
355  if(getSensorType(cameraPath) == camera.sensorType)
356  {
357 
358  boost::filesystem::path metaPath = cameraPath / "meta.yaml";
359 
360  // Load camera data
361  std::cout << timestamp << "Loading " << metaPath << std::endl;
362  YAML::Node meta = YAML::LoadFile(metaPath.string());
363  camera = meta.as<ScanCamera>();
364 
365  // Load all scan images
366  loadScanImages(camera.images, cameraPath / "data");
367  return true;
368  }
369  else
370  {
371  return false;
372  }
373 }
374 
378 
379 void saveScan(
380  const boost::filesystem::path& root,
381  const Scan& scan,
382  const std::string positionDirectory,
383  const std::string scanDirectory,
384  const std::string scanName)
385 {
386 
387  boost::filesystem::path scanPosPath = root / positionDirectory;
388 
389  if(!boost::filesystem::exists(scanPosPath))
390  {
391  std::cout << timestamp << "Creating: " << scanPosPath << std::endl;
392  boost::filesystem::create_directory(scanPosPath);
393  }
394 
395  boost::filesystem::path scanPath = scanPosPath / scanDirectory;
396  if(!boost::filesystem::exists(scanPath))
397  {
398  std::cout << timestamp << "Creating: " << scanPath << std::endl;
399  boost::filesystem::create_directory(scanPath);
400  }
401 
402  // Check if meta.yaml exists for given directory
403  boost::filesystem::path metaPath = scanPath / "meta.yaml";
404  if(!boost::filesystem::exists(metaPath))
405  {
406  YAML::Node node;
407  node = scan;
408 
409  std::ofstream out(metaPath.c_str());
410  if (out.good())
411  {
412  std::cout << timestamp << "Writing " << metaPath << std::endl;
413  out << node;
414  }
415  else
416  {
417  std::cout << timestamp
418  << "Warning: Unable to write " << metaPath << std::endl;
419  }
420  }
421 
422  // write data
423  boost::filesystem::path scanDataPath = scanPath / "data";
424  if(!boost::filesystem::exists(scanDataPath))
425  {
426  std::cout << timestamp << "Creating: " << scanDataPath << std::endl;
427  boost::filesystem::create_directory(scanDataPath);
428  }
429 
430  boost::filesystem::path scanOut = scanDataPath / (scanName + ".ply");
431  boost::filesystem::path scanMetaOut = scanDataPath / (scanName + ".yaml");
432 
433  // if(!boost::ex)
434 
435  // Write meta.yaml
436  YAML::Node node;
437  node = scan;
438 
439  std::ofstream out(scanMetaOut.string());
440  if (out.good())
441  {
442  std::cout << timestamp << "Writing " << scanMetaOut << std::endl;
443  out << node;
444  }
445  else
446  {
447  std::cout << timestamp
448  << "Warning: Unable to write " << scanMetaOut << std::endl;
449  }
450 
451  // Write point cloud data
452  std::cout << timestamp << "Writing " << scanOut << std::endl;
453 
454  ModelPtr model(new Model);
455  model->m_pointCloud = scan.points;
456  ModelFactory::saveModel(model, scanOut.string());
457 }
458 
459 void saveScan(
460  const boost::filesystem::path& root,
461  const Scan& scan,
462  const std::string positionDirectory,
463  const std::string scanDirectory,
464  const size_t& scanNumber)
465 {
466  std::stringstream scanStr;
467  scanStr << std::setfill('0') << std::setw(8) << scanNumber;
468 
469  saveScan(root, scan, positionDirectory, scanDirectory, scanStr.str());
470 }
471 
472 void saveScan(
473  const boost::filesystem::path& root,
474  const Scan& scan,
475  const size_t& positionNumber,
476  const size_t& scanNumber)
477 {
478  std::stringstream posStr;
479  posStr << std::setfill('0') << std::setw(8) << positionNumber;
480 
481  std::stringstream scanStr;
482  scanStr << std::setfill('0') << std::setw(8) << scanNumber << ".ply";
483 
484  saveScan(root, scan, posStr.str(), "scans", scanStr.str());
485 }
486 
487 bool loadScan(
488  const boost::filesystem::path& root,
489  Scan& scan,
490  const std::string& positionDirectory,
491  const std::string& scanSubDirectory,
492  const std::string& scanName)
493 {
494 
495  boost::filesystem::path scanDirectoryPath = root / positionDirectory / scanSubDirectory;
496 
497  if(!boost::filesystem::exists(scanDirectoryPath))
498  {
499  std::cerr << timestamp << "Could not open " << scanDirectoryPath << std::endl;
500  return false;
501  }
502 
503 
504 
505  if(getSensorType(scanDirectoryPath) == scan.sensorType)
506  {
507  boost::filesystem::path scanDataPath = scanDirectoryPath / "data";
508  // Load meta data
509 
510  boost::filesystem::path metaPath = scanDataPath / (scanName + ".yaml");
511  std::cout << timestamp << "Loading " << metaPath << std::endl;
512  YAML::Node meta = YAML::LoadFile(metaPath.string());
513  scan = meta.as<Scan>();
514 
515  // Load scan
516  boost::filesystem::path scanFile = scanDataPath / (scanName + ".ply");
517  std::cout << timestamp << "Loading " << scanFile << std::endl;
518  ModelPtr model = ModelFactory::readModel(scanFile.string());
519 
520  if(model->m_pointCloud)
521  {
522  scan.points = model->m_pointCloud;
523  }
524  else
525  {
526  std::cout << timestamp
527  << "Warning: Loading " << scanFile << " failed." << std::endl;
528  return false;
529  }
530 
531 
532  return true;
533  }
534 
535  return false;
536 }
537 
538 bool loadScan(
539  const boost::filesystem::path& root,
540  Scan& scan,
541  const std::string& positionDirectory,
542  const size_t& scanNumber)
543 {
544  std::stringstream scanStr;
545  scanStr << std::setfill('0') << std::setw(8) << scanNumber;
546 
547  return loadScan(root, scan, positionDirectory, "scans", scanStr.str());
548 }
549 
550 bool loadScan(
551  const boost::filesystem::path& root,
552  Scan& scan,
553  const size_t& positionNumber,
554  const size_t& scanNumber)
555 {
556  std::stringstream posStr;
557  posStr << std::setfill('0') << std::setw(8) << positionNumber;
558 
559  std::stringstream scanStr;
560  scanStr << std::setfill('0') << std::setw(8) << scanNumber;
561 
562  return loadScan(root, scan, posStr.str(), "scans", scanStr.str());
563 }
564 
565 
569 
570 
571 boost::filesystem::path getPanoramaChannelDirectory(
572  boost::filesystem::path root,
573  const std::string positionDirectory,
574  const std::string panoramaDirectory)
575 {
576  boost::filesystem::path pos(positionDirectory);
577  boost::filesystem::path pan(panoramaDirectory);
578  return root / pos / "spectral" / "data" / pan;
579 }
580 
581 // void saveHyperspectralPanoramaChannel(
582 // const boost::filesystem::path& root,
583 // const HyperspectralPanoramaChannel& channel,
584 // const size_t& positionNumber,
585 // const size_t& panoramaNumber,
586 // const size_t& channelNumber)
587 // {
588 // std::stringstream posStr;
589 // posStr << std::setfill('0') << std::setw(8) << positionNumber;
590 
591 // std::stringstream camStr;
592 // camStr << std::setfill('0') << std::setw(8) << panoramaNumber;
593 
594 // saveHyperspectralPanoramaChannel(root, channel, posStr.str(), camStr.str(), channelNumber);
595 // }
596 
597 // void saveHyperspectralPanoramaChannel(
598 // const boost::filesystem::path& root,
599 // const HyperspectralPanoramaChannel& channel,
600 // const std::string positionDirectory,
601 // const size_t& panoramaNumber,
602 // const size_t& channelNumber)
603 // {
604 // std::stringstream camStr;
605 // camStr << std::setfill('0') << std::setw(8) << panoramaNumber;
606 
607 // saveHyperspectralPanoramaChannel(root, channel, positionDirectory, camStr.str(), channelNumber);
608 // }
609 
611  const boost::filesystem::path& root,
612  const HyperspectralPanoramaChannel& channel,
613  const std::string positionDirectory,
614  const std::string panoramaDirectory,
615  const size_t& channelNumber)
616 {
617  // Some directory parsing stuff
618  std::stringstream metaFileName;
619  metaFileName << std::setfill('0') << std::setw(8) << channelNumber << ".yaml";
620 
621  std::stringstream channelFileName;
622  channelFileName << std::setfill('0') << std::setw(8) << channelNumber << ".png";
623 
624  boost::filesystem::path channelDirectory =
625  getPanoramaChannelDirectory(root, positionDirectory, panoramaDirectory);
626 
627  if(!boost::filesystem::exists(channelDirectory))
628  {
629  std::cout << timestamp << "Creating: " << channelDirectory << std::endl;
630  boost::filesystem::create_directory(channelDirectory);
631  }
632 
633  boost::filesystem::path imagePath = channelDirectory / channelFileName.str();
634  boost::filesystem::path metaPath = channelDirectory / metaFileName.str();
635 
636  // Write meta information for scan image
637  YAML::Node meta;
638  meta = channel;
639 
640  std::ofstream out(metaPath.c_str());
641  if (out.good())
642  {
643  std::cout << timestamp << "Writing " << metaPath << std::endl;
644  out << meta;
645  }
646  else
647  {
648  std::cout << timestamp
649  << "Warning: to write " << metaPath << std::endl;
650  }
651 
652  // Write image data
653  std::cout << timestamp << "Writing " << imagePath << std::endl;
654  cv::imwrite(imagePath.string(), channel.channel);
655 }
656 
658  std::vector<HyperspectralPanoramaChannelPtr>& channels,
659  boost::filesystem::path dataPath)
660 {
661  bool stop = false;
662  size_t c = 0;
663  while(!stop)
664  {
665  std::stringstream metaStr;
666  metaStr << std::setfill('0') << std::setw(8) << c << ".yaml";
667 
668  std::stringstream pngStr;
669  pngStr << std::setfill('0') << std::setw(8) << c << ".png";
670 
671  boost::filesystem::path metaPath = dataPath / metaStr.str();
672  boost::filesystem::path pngPath = dataPath / pngStr.str();
673 
674  // Check if both .png and corresponding .yaml file exist
675  if(boost::filesystem::exists(metaPath)
676  && boost::filesystem::exists(pngPath) )
677  {
678  // Load meta info
680 
681  // std::cout << timestamp << "Loading " << metaPath << std::endl;
682  YAML::Node meta = YAML::LoadFile(metaPath.string());
683 
684  // *channel = meta.as<ScanImage>();
685  if(YAML::convert<HyperspectralPanoramaChannel>::decode(meta, *channel))
686  {
687  // Load channel data
688  // std::cout << timestamp << "Loading " << pngPath << std::endl;
689  channel->channelFile = pngPath;
690  channel->channel = cv::imread(pngPath.string());
691 
692  // Store new channel
693  channels.push_back(HyperspectralPanoramaChannelPtr(channel));
694  } else {
695  std::cout << timestamp << "Could not convert " << metaPath << std::endl;
696  }
697 
698  c++;
699  }
700  else
701  {
702  std::cout
703  << timestamp << "Read " << c << " channels from " << dataPath << std::endl;
704  stop = true;
705  }
706  }
707 }
708 
709 
713 
714 boost::filesystem::path getHyperspectralCameraDirectory(
715  boost::filesystem::path root,
716  const std::string positionDirectory,
717  const std::string cameraDirectory)
718 {
719  boost::filesystem::path pos(positionDirectory);
720  boost::filesystem::path cam(cameraDirectory);
721  return root / pos /cam;
722 }
723 
724 void saveHyperspectralCamera(const boost::filesystem::path& root,
725  const HyperspectralCamera& camera,
726  const std::string positionDirectory,
727  const std::string& cameraDirectory)
728 {
729  boost::filesystem::path spectral_pos_path = getHyperspectralCameraDirectory(root, positionDirectory, cameraDirectory);
730 
731  if(!boost::filesystem::exists(spectral_pos_path))
732  {
733  std::cout << timestamp << "Creating: " << spectral_pos_path << std::endl;
734  boost::filesystem::create_directory(spectral_pos_path);
735  }
736 
737  boost::filesystem::path spectral_data_path = spectral_pos_path / "data";
738  if(!boost::filesystem::exists(spectral_data_path))
739  {
740  std::cout << timestamp << "Creating: " << spectral_data_path << std::endl;
741  boost::filesystem::create_directory(spectral_data_path);
742  }
743 
744  // Check if meta.yaml exists for given directory
745  boost::filesystem::path metaPath = spectral_pos_path / "meta.yaml";
746  if(!boost::filesystem::exists(metaPath))
747  {
748  YAML::Node node;
749  node = camera;
750 
751  std::ofstream out(metaPath.c_str());
752  if (out.good())
753  {
754  std::cout << timestamp << "Writing " << metaPath << std::endl;
755  out << node;
756  }
757  else
758  {
759  std::cout << timestamp
760  << "Warning: Unable to write " << metaPath << std::endl;
761  }
762  }
763 
764  // saving panoramas
765  for(int panorama_id = 0; panorama_id < camera.panoramas.size(); panorama_id++)
766  {
767  char buffer[sizeof(int) * 5];
768  sprintf(buffer, "%08d", panorama_id);
769  string nr_str(buffer);
770 
771  boost::filesystem::path panorama_pos_path = spectral_data_path / nr_str;
772  if(!boost::filesystem::exists(panorama_pos_path))
773  {
774  std::cout << timestamp << "Creating: " << panorama_pos_path << std::endl;
775  boost::filesystem::create_directory(panorama_pos_path);
776  }
777 
778  // saving channels
779  for(int channel_id = 0; channel_id < camera.panoramas[panorama_id]->channels.size(); channel_id++)
780  {
781  saveHyperspectralPanoramaChannel(root, *(camera.panoramas[panorama_id]->channels[channel_id]), positionDirectory, nr_str, channel_id);
782  }
783  }
784 }
785 
787  const boost::filesystem::path& root,
788  const HyperspectralCamera& camera,
789  const std::string& positionDirectory)
790 {
791  return saveHyperspectralCamera(root, camera, positionDirectory, "spectral");
792 }
793 
795  const boost::filesystem::path& root,
796  const HyperspectralCamera& camera,
797  const size_t& positionNumber)
798 {
799  std::stringstream posStr;
800  posStr << std::setfill('0') << std::setw(8) << positionNumber;
801 
802  return saveHyperspectralCamera(root, camera, posStr.str(), "spectral");
803 }
804 
806  const boost::filesystem::path& root,
807  HyperspectralCamera& camera,
808  const std::string& positionDirectory,
809  const std::string& cameraDirectory)
810 {
811  boost::filesystem::path cameraPath =
812  getHyperspectralCameraDirectory(root, positionDirectory, cameraDirectory);
813 
814  if(getSensorType(cameraPath) == camera.sensorType)
815  {
816 
817  boost::filesystem::path metaPath = cameraPath / "meta.yaml";
818 
819  // Load camera data
820  std::cout << timestamp << "Loading " << metaPath << std::endl;
821  YAML::Node meta = YAML::LoadFile(metaPath.string());
822  camera = meta.as<HyperspectralCamera>();
823 
824  // Load all hyperspectral images
825  // loadScanImages(camera.images, cameraPath / "data");
826 
827  boost::filesystem::path dataPath = cameraPath / "data";
828 
829  bool stop = false;
830  size_t c = 0;
831  while(!stop)
832  {
833  std::stringstream metaStr;
834  metaStr << std::setfill('0') << std::setw(8) << c;
835 
836  boost::filesystem::path channelPath = dataPath / metaStr.str();
837 
838  if(boost::filesystem::exists(channelPath))
839  {
840  std::vector<HyperspectralPanoramaChannelPtr> channels;
841  loadHyperspectralPanoramaChannels(channels, channelPath);
842 
844  panorama->channels = channels;
845  camera.panoramas.push_back(panorama);
846 
847  c++;
848  }
849  else
850  {
851  std::cout
852  << timestamp << "Read " << c << " panoramas from " << cameraPath << std::endl;
853  stop = true;
854  }
855  }
856 
857  return true;
858  }
859  else
860  {
861  return false;
862  }
863 }
864 
866  const boost::filesystem::path& root,
867  HyperspectralCamera& camera,
868  const std::string& positionDirectory)
869 {
870  return loadHyperspectralCamera(root, camera, positionDirectory, "spectral");
871 }
872 
874  const boost::filesystem::path& root,
875  HyperspectralCamera& camera,
876  const size_t& positionNumber)
877 {
878  std::stringstream posStr;
879  posStr << std::setfill('0') << std::setw(8) << positionNumber;
880 
881  return loadHyperspectralCamera(root, camera, posStr.str(), "spectral");
882 }
883 
884 
889  const boost::filesystem::path& root,
890  const ScanPosition& scanPos,
891  const std::string positionDirectory)
892 {
893  boost::filesystem::path scan_pos_path = root / positionDirectory;
894 
895  if(!boost::filesystem::exists(root))
896  {
897  std::cout << timestamp << "Creating: " << root << std::endl;
898  boost::filesystem::create_directory(root);
899  }
900 
901  if(!boost::filesystem::exists(scan_pos_path))
902  {
903  std::cout << timestamp << "Creating: " << scan_pos_path << std::endl;
904  boost::filesystem::create_directory(scan_pos_path);
905  }
906 
907 
908  boost::filesystem::path scanPosMetaOut = scan_pos_path / "meta.yaml";
909  YAML::Node meta;
910  meta = scanPos;
911 
912  std::ofstream out(scanPosMetaOut.string());
913  if (out.good())
914  {
915  std::cout << timestamp << "Writing " << scanPosMetaOut << std::endl;
916  out << meta;
917  }
918  else
919  {
920  std::cout << timestamp
921  << "Warning: Unable to write " << scanPosMetaOut << std::endl;
922  }
923 
924  for(size_t scan_id = 0; scan_id < scanPos.scans.size(); scan_id++)
925  {
926  saveScan(root, *scanPos.scans[scan_id], positionDirectory, "scans", scan_id);
927  }
928 
929  for(size_t cam_id = 0; cam_id < scanPos.cams.size(); cam_id++)
930  {
931  saveScanCamera(root, *scanPos.cams[cam_id], positionDirectory, cam_id);
932  }
933 
934  if(scanPos.hyperspectralCamera)
935  {
936  saveHyperspectralCamera(root, *scanPos.hyperspectralCamera, positionDirectory);
937  }
938 }
939 
941  const boost::filesystem::path& root,
942  const ScanPosition& scanPos,
943  const size_t& positionNumber)
944 {
945  std::stringstream posStr;
946  posStr << std::setfill('0') << std::setw(8) << positionNumber;
947 
948  saveScanPosition(root, scanPos, posStr.str());
949 }
950 
952  const boost::filesystem::path& root,
953  ScanPosition& scanPos,
954  const std::string& positionDirectory)
955 {
956 
957  boost::filesystem::path scanPosDir = root / positionDirectory;
958 
959  if(!boost::filesystem::exists(scanPosDir))
960  {
961  std::cerr << timestamp << "Could not open " << scanPosDir << std::endl;
962  return false;
963  }
964 
965  boost::filesystem::path scanPosMetaPath = scanPosDir / "meta.yaml";
966  if(!boost::filesystem::is_regular_file(scanPosMetaPath))
967  {
968  std::cerr << timestamp << "Could not open " << scanPosMetaPath << std::endl;
969  return false;
970  }
971 
972  YAML::Node meta = YAML::LoadFile(scanPosMetaPath.string());
973 
974  scanPos = meta.as<ScanPosition>();
975 
976 
977  boost::filesystem::directory_iterator it{scanPosDir};
978  while (it != boost::filesystem::directory_iterator{})
979  {
980  const std::string sensorType = getSensorType(*it);
981 
982  if(sensorType == Scan::sensorType)
983  {
984  boost::filesystem::path scanDataDir = it->path() / "data";
985 
986  boost::filesystem::directory_iterator itScans{scanDataDir};
987  while (itScans != boost::filesystem::directory_iterator{})
988  {
989  if(itScans->path().extension() == ".yaml")
990  {
991  std::string scanName = itScans->path().stem().string();
992  ScanPtr scan(new Scan);
993 
994  if(loadScan(root, *scan, positionDirectory, it->path().stem().string(), scanName))
995  {
996  scanPos.scans.push_back(scan);
997  }
998  }
999  ++itScans;
1000  }
1001  }
1002  else if(sensorType == ScanCamera::sensorType)
1003  {
1004  ScanCameraPtr cam(new ScanCamera);
1005 
1006  if(loadScanCamera(root, *cam, positionDirectory, it->path().stem().string()))
1007  {
1008  scanPos.cams.push_back(cam);
1009  } else {
1010  std::cout << timestamp << "[ WARNING ] Could not load camera from " << it->path() << std::endl;
1011  }
1012  }
1013  else if(sensorType == HyperspectralCamera::sensorType)
1014  {
1016 
1017  if(loadHyperspectralCamera(root, *cam, positionDirectory))
1018  {
1019  scanPos.hyperspectralCamera = cam;
1020  } else {
1021  std::cout << timestamp << "[ WARNING ] Could not load hyperspectral camera from " << it->path() << std::endl;
1022  }
1023  }
1024 
1025  ++it;
1026  }
1027 
1028 
1029  return true;
1030 }
1031 
1033  const boost::filesystem::path& root,
1034  ScanPosition& scanPos,
1035  const size_t& positionNumber)
1036 {
1037  std::stringstream posStr;
1038  posStr << std::setfill('0') << std::setw(8) << positionNumber;
1039  return loadScanPosition(root, scanPos, posStr.str());
1040 }
1041 
1045 
1047  const boost::filesystem::path& root,
1048  const ScanProject& scanProj)
1049 {
1050 
1051  if(!boost::filesystem::exists(root))
1052  {
1053  boost::filesystem::create_directory(root);
1054  }
1055 
1056  boost::filesystem::path scanProjMetaPath = root / "meta.yaml";
1057 
1058  YAML::Node meta;
1059  meta = scanProj;
1060 
1061  std::ofstream out(scanProjMetaPath.string());
1062  if (out.good())
1063  {
1064  std::cout << timestamp << "Writing " << scanProjMetaPath << std::endl;
1065  out << meta;
1066  }
1067  else
1068  {
1069  std::cout << timestamp
1070  << "Warning: Unable to write " << scanProjMetaPath << std::endl;
1071  }
1072 
1073 
1074  // Writing scan positions
1075  for(size_t i=0; i<scanProj.positions.size(); i++)
1076  {
1077  saveScanPosition(root, *scanProj.positions[0], i);
1078  }
1079 
1080 
1081 }
1082 
1084  const boost::filesystem::path& root,
1085  ScanProject& scanProj)
1086 {
1087  if(!boost::filesystem::exists(root))
1088  {
1089  std::cerr << timestamp << "Could not open " << root << std::endl;
1090  return false;
1091  }
1092 
1093  boost::filesystem::path scanProjMetaPath = root / "meta.yaml";
1094 
1095  if(!boost::filesystem::is_regular_file(scanProjMetaPath))
1096  {
1097  std::cerr << timestamp << "Could not load " << scanProjMetaPath << std::endl;
1098  return false;
1099  }
1100 
1101  YAML::Node meta = YAML::LoadFile(scanProjMetaPath.string());
1102  scanProj = meta.as<ScanProject>();
1103 
1104  std::vector<boost::filesystem::path> paths;
1105 
1106  std::copy(boost::filesystem::directory_iterator(root), boost::filesystem::directory_iterator(), back_inserter(paths));
1107  std::sort(paths.begin(), paths.end());
1108  // boost::filesystem::directory_iterator it{root};
1109  for (std::vector<boost::filesystem::path>::const_iterator it(paths.begin()), it_end(paths.end()); it != it_end; ++it)
1110  {
1112  {
1113  std::cout << *it << '\n';
1114  ScanPositionPtr scanPos(new ScanPosition);
1115 
1116  loadScanPosition(root, *scanPos, it->filename().string());
1117  scanProj.positions.push_back(scanPos);
1118  }
1119 
1120  // ++it;
1121  }
1122 
1123  return true;
1124 }
1125 
1126 
1127 
1128 
1129 
1130 
1131 
1132 
1133 
1134 
1135 
1136 
1137 
1138 
1139 
1140 
1141 
1142 
1143 
1144 
1145 
1146 
1147 
1148 
1149 
1150 
1151 
1152 
1153 // std::set<size_t> loadPositionIdsFromDirectory(
1154 // const boost::filesystem::path& path
1155 // )
1156 // {
1157 // std::set<size_t> positions;
1158 // boost::filesystem::path scan_path = path / "scans";
1159 // const boost::regex scan_dir_filter("^([0-9]{5}).*$");
1160 
1161 // boost::filesystem::directory_iterator end_itr;
1162 // for(boost::filesystem::directory_iterator it(scan_path); it != end_itr; ++it )
1163 // {
1164 // if( !boost::filesystem::is_directory( it->path() ) ) continue;
1165 // boost::smatch what;
1166 // if( !boost::regex_match( it->path().filename().string(), what, scan_dir_filter ) ) continue;
1167 // positions.insert(static_cast<size_t>(std::stoul(what[1])));
1168 // }
1169 
1170 // return positions;
1171 // }
1172 
1173 // std::set<size_t> loadCamIdsFromDirectory(
1174 // const boost::filesystem::path& path,
1175 // const size_t& positionNr
1176 // )
1177 // {
1178 // std::set<size_t> cam_ids;
1179 
1180 // std::stringstream ss;
1181 // ss << std::setfill('0') << std::setw(5) << positionNr;
1182 // boost::filesystem::path scan_images_dir = path / "scan_images" / ss.str();
1183 
1184 // if(boost::filesystem::exists(scan_images_dir))
1185 // {
1186 // const boost::regex image_filter("^(\\d+)_(\\d+)\\.(bmp|dib|jpeg|jpg|jpe|jp2|png|pbm|pgm|ppm|sr|ras|tiff|tif)$");
1187 
1188 // boost::filesystem::directory_iterator end_itr;
1189 // for(boost::filesystem::directory_iterator it(scan_images_dir); it != end_itr; ++it )
1190 // {
1191 // if( !boost::filesystem::is_regular_file( it->path() ) ) continue;
1192 
1193 // boost::smatch what;
1194 // if( !boost::regex_match( it->path().filename().string(), what, image_filter ) ) continue;
1195 
1196 // cam_ids.insert(static_cast<size_t>(std::stoul(what[1])));
1197 
1198 // }
1199 // }
1200 
1201 // return cam_ids;
1202 // }
1203 
1204 // std::set<size_t> loadImageIdsFromDirectory(
1205 // const boost::filesystem::path& path,
1206 // const size_t& positionNr,
1207 // const size_t& camNr
1208 // )
1209 // {
1210 // std::set<size_t> img_ids;
1211 
1212 // std::stringstream ss;
1213 // ss << std::setfill('0') << std::setw(5) << positionNr;
1214 // boost::filesystem::path scan_images_dir = path / "scan_images" / ss.str();
1215 
1216 
1217 // if(boost::filesystem::exists(scan_images_dir))
1218 // {
1219 // const boost::regex image_filter("^(\\d+)_(\\d+)\\.(bmp|dib|jpeg|jpg|jpe|jp2|png|pbm|pgm|ppm|sr|ras|tiff|tif)$");
1220 
1221 // boost::filesystem::directory_iterator end_itr;
1222 // for(boost::filesystem::directory_iterator it(scan_images_dir); it != end_itr; ++it )
1223 // {
1224 // if( !boost::filesystem::is_regular_file( it->path() ) ) continue;
1225 
1226 // boost::smatch what;
1227 // if( !boost::regex_match( it->path().filename().string(), what, image_filter ) ) continue;
1228 
1229 // if(static_cast<size_t>(std::stoul(what[1])) == camNr)
1230 // {
1231 // img_ids.insert(static_cast<size_t>(std::stoul(what[2])));
1232 // }
1233 // }
1234 // }
1235 
1236 
1237 // return img_ids;
1238 // }
1239 
1240 // void writeScanMetaYAML(const boost::filesystem::path& path, const Scan& scan)
1241 // {
1242 
1243 // YAML::Node meta;
1244 // meta = scan;
1245 
1246 // std::ofstream out(path.c_str());
1247 // if (out.good())
1248 // {
1249 // out << meta;
1250 // }
1251 // else
1252 // {
1253 // std::cout << timestamp << "Warning: Unable to open "
1254 // << path.string() << "for writing." << std::endl;
1255 // }
1256 
1257 // }
1258 
1259 // void saveScanToDirectory(
1260 // const boost::filesystem::path& path,
1261 // const Scan& scan,
1262 // const size_t& positionNr)
1263 // {
1264 // // Create full path from root and scan number
1265 // std::stringstream ss;
1266 // ss << std::setfill('0') << std::setw(5) << positionNr;
1267 // boost::filesystem::path directory = path / "scans" / ss.str();
1268 
1269 // // Check if directory exists, if not create it and write meta data
1270 // // and into the new directory
1271 
1272 // if(!boost::filesystem::exists(path))
1273 // {
1274 // std::cout << timestamp << "Creating " << path << std::endl;
1275 // boost::filesystem::create_directory(path);
1276 // }
1277 
1278 // if(!boost::filesystem::exists(path / "scans")) {
1279 // std::cout << timestamp << "Creating " << path / "scans" << std::endl;
1280 // boost::filesystem::create_directory(path / "scans");
1281 // }
1282 
1283 // if(!boost::filesystem::exists(directory))
1284 // {
1285 // std::cout << timestamp << "Creating " << directory << std::endl;
1286 // boost::filesystem::create_directory(directory);
1287 // }
1288 
1289 // // Create yaml file with meta information
1290 // std::cout << timestamp << "Creating scan meta.yaml..." << std::endl;
1291 // writeScanMetaYAML(directory / "meta.yaml", scan);
1292 
1293 // // Save points
1294 // std::string scanFileName( (directory / "scan.ply").string() );
1295 // std::cout << timestamp << "Writing " << scanFileName << std::endl;
1296 
1297 // ModelPtr model(new Model());
1298 // if(scan.m_points)
1299 // {
1300 // model->m_pointCloud = scan.m_points;
1301 // PLYIO io;
1302 // io.save(model, scanFileName);
1303 // }
1304 // else
1305 // {
1306 // std::cout << timestamp << "Warning: Point cloud pointer is empty!" << std::endl;
1307 // }
1308 
1309 
1310 // }
1311 
1312 // bool loadScanFromDirectory(
1313 // const boost::filesystem::path& path,
1314 // Scan& scan, const size_t& positionNr, bool load)
1315 // {
1316 // if(boost::filesystem::exists(path) && boost::filesystem::is_directory(path))
1317 // {
1318 // std::stringstream ss;
1319 // ss << std::setfill('0') << std::setw(5) << positionNr;
1320 // boost::filesystem::path position_directory = path / "scans" / ss.str();
1321 
1322 // if(boost::filesystem::exists(position_directory))
1323 // {
1324 // // Load meta data
1325 // boost::filesystem::path meta_yaml_path = position_directory / "meta.yaml";
1326 // std::cout << timestamp << "Reading " << meta_yaml_path << std::endl;
1327 // loadScanMetaInfoFromYAML(meta_yaml_path, scan);
1328 
1329 
1330 // // Load scan data
1331 // boost::filesystem::path scan_path = position_directory / "scan.ply";
1332 // std::cout << timestamp << "Reading " << scan_path << std::endl;
1333 
1334 // if (boost::filesystem::exists(scan_path))
1335 // {
1336 // scan.m_scanFile = scan_path;
1337 // scan.m_scanRoot = path; // TODO: Check root dir or scan dir??
1338 // if (load)
1339 // {
1340 // PLYIO io;
1341 // ModelPtr model = io.read(scan_path.string());
1342 // scan.m_points = model->m_pointCloud;
1343 // scan.m_pointsLoaded = true;
1344 // }
1345 // else
1346 // {
1347 // scan.m_pointsLoaded = false;
1348 // }
1349 // return true;
1350 // }
1351 // else
1352 // {
1353 // std::cout << "Warning: scan.ply not found in directory "
1354 // << scan_path << std::endl;
1355 // return false;
1356 // }
1357 // }
1358 // else
1359 // {
1360 // std::cout << timestamp
1361 // << "Warning: Scan directory " << position_directory << " "
1362 // << "does not exist." << std::endl;
1363 // return false;
1364 // }
1365 // }
1366 // else
1367 // {
1368 // std::cout << timestamp
1369 // << "Warning: '" << path.string()
1370 // << "' does not exist or is not a directory." << std::endl;
1371 // return false;
1372 // }
1373 // }
1374 
1375 // void loadScanMetaInfoFromYAML(const boost::filesystem::path& path, Scan& scan)
1376 // {
1377 // YAML::Node meta = YAML::LoadFile(path.string());
1378 // scan = meta.as<Scan>();
1379 // }
1380 
1381 
1382 // void saveScanToHDF5(const std::string filename, const size_t& positionNr)
1383 // {
1384 
1385 // }
1386 
1387 // bool loadScanFromHDF5(const std::string filename, const size_t& positionNr)
1388 // {
1389 // return true;
1390 // }
1391 
1392 // void saveScanImageToDirectory(
1393 // const boost::filesystem::path& path,
1394 // const std::string& camDir,
1395 // const ScanImage& image,
1396 // const size_t& positionNr,
1397 // const size_t& imageNr)
1398 // {
1399 // std::stringstream pos_ss;
1400 // pos_ss << std::setfill('0') << std::setw(5) << positionNr;
1401 // boost::filesystem::path scanimage_directory = path / pos_ss.str() / camDir;
1402 
1403 // // Create directory for scan image if necessary
1404 // if(!boost::filesystem::exists(scanimage_directory))
1405 // {
1406 // boost::filesystem::create_directory(scanimage_directory);
1407 // }
1408 
1409 // // Create directory for scan image data frame data if necessary
1410 // boost::filesystem::path scanimage_data_directory = scanimage_directory / "data";
1411 // if(!boost::filesystem::exists(scanimage_data_directory))
1412 // {
1413 // boost::filesystem::create_directory(scanimage_data_directory);
1414 // }
1415 
1416 
1417 
1418 // }
1419 
1420 // void writePinholeModelToYAML(
1421 // const boost::filesystem::path& path, const PinholeModeld& model)
1422 // {
1423 // // YAML::Node meta;
1424 // // meta = model;
1425 
1426 // // std::ofstream out(path.c_str());
1427 // // if (out.good())
1428 // // {
1429 // // out << meta;
1430 // // }
1431 // // else
1432 // // {
1433 // // std::cout << timestamp << "Warning: Unable to open "
1434 // // << path.string() << "for writing." << std::endl;
1435 // // }
1436 
1437 // }
1438 
1439 // void loadPinholeModelFromYAML(const boost::filesystem::path& path, PinholeModeld& model)
1440 // {
1441 // // YAML::Node model_file = YAML::LoadFile(path.string());
1442 // // model = model_file.as<PinholeModeld>();
1443 // //
1444 // }
1445 
1446 // bool loadScanImageFromDirectory(
1447 // const boost::filesystem::path& path,
1448 // ScanImage& image,
1449 // const size_t& positionNr,
1450 // const size_t& camNr,
1451 // const size_t& imageNr)
1452 // {
1453 // // // Convert position and image number to strings
1454 // // stringstream pos_str;
1455 // // pos_str << std::setfill('0') << std::setw(5) << positionNr;
1456 
1457 // // // Construct a path to image directory and check
1458 // // boost::filesystem::path scan_image_dir = path / "scan_images" / pos_str.str();
1459 // // if(boost::filesystem::exists(scan_image_dir))
1460 // // {
1461 // // std::stringstream yaml_file, image_file;
1462 // // yaml_file << camNr << "_" << imageNr << ".yaml";
1463 // // image_file << camNr << "_" << imageNr << ".png";
1464 
1465 // // boost::filesystem::path meta_path = scan_image_dir / yaml_file.str();
1466 // // boost::filesystem::path image_path = scan_image_dir / image_file.str();
1467 
1468 // // if(!boost::filesystem::exists(meta_path))
1469 // // {
1470 // // std::cout << timestamp << "Could not load meta file of scan/cam/img: " << positionNr << "/" << camNr << "/" << imageNr << std::endl;
1471 // // return false;
1472 // // }
1473 
1474 // // std::cout << timestamp << "Loading " << image_path << std::endl;
1475 // // image.image = cv::imread(image_path.string(), 1);
1476 // // image.imageFile = image_path;
1477 
1478 // // std::cout << timestamp << "Loading " << meta_path << std::endl;
1479 // // loadPinholeModelFromYAML(meta_path, image.camera);
1480 // // }
1481 // // else
1482 // // {
1483 // // std::cout << timestamp << "Warning: Image directory does not exist: "
1484 // // << scan_image_dir << std::endl;
1485 // // return false;
1486 // // }
1487 
1488 // return true;
1489 // }
1490 
1491 // void saveScanPositionToDirectory(const boost::filesystem::path& path, const ScanPosition& position, const size_t& positionNr)
1492 // {
1493 // // // Save scan data
1494 // // std::cout << timestamp << "Saving scan postion " << positionNr << std::endl;
1495 // // if(position.scan)
1496 // // {
1497 // // saveScanToDirectory(path, *position.scan, positionNr);
1498 // // }
1499 // // else
1500 // // {
1501 // // std::cout << timestamp << "Warning: Scan position " << positionNr
1502 // // << " contains no scan data." << std::endl;
1503 // // }
1504 
1505 // // // Save rgb camera recordings
1506 // // for(size_t cam_id = 0; cam_id < position.cams.size(); cam_id++)
1507 // // {
1508 // // // store each image of camera
1509 // // for(size_t img_id = 0; img_id < position.cams[cam_id]->images.size(); img_id++ )
1510 // // {
1511 // // saveScanImageToDirectory(path, *position.cams[cam_id]->images[img_id], positionNr, cam_id, img_id);
1512 // // }
1513 // // }
1514 // }
1515 
1516 // void get_all(
1517 // const boost::filesystem::path& root,
1518 // const string& ext, vector<boost::filesystem::path>& ret)
1519 // {
1520 // if(!boost::filesystem::exists(root) || !boost::filesystem::is_directory(root))
1521 // {
1522 // return;
1523 // }
1524 
1525 // boost::filesystem::directory_iterator it(root);
1526 // boost::filesystem::directory_iterator endit;
1527 
1528 // while(it != endit)
1529 // {
1530 // if(boost::filesystem::is_regular_file(*it) && it->path().extension() == ext)
1531 // {
1532 // ret.push_back(it->path().filename());
1533 // }
1534 // ++it;
1535 // }
1536 // }
1537 
1538 // bool loadScanPositionFromDirectory(
1539 // const boost::filesystem::path& path,
1540 // ScanPosition& position,
1541 // const size_t& positionNr)
1542 // {
1543 // // bool scan_read = false;
1544 // // bool images_read = false;
1545 
1546 // // std::cout << timestamp << "Loading scan position " << positionNr << std::endl;
1547 // // Scan scan;
1548 // // if(!loadScanFromDirectory(path, scan, positionNr, true))
1549 // // {
1550 // // std::cout << timestamp << "Warning: Scan position " << positionNr
1551 // // << " does not contain scan data." << std::endl;
1552 // // } else {
1553 // // position.scan = scan;
1554 // // }
1555 
1556 
1557 // // boost::filesystem::path img_directory = path / "scan_images";
1558 // // if(boost::filesystem::exists(img_directory))
1559 // // {
1560 // // std::stringstream ss;
1561 // // ss << std::setfill('0') << std::setw(5) << positionNr;
1562 // // boost::filesystem::path scanimage_directory = img_directory / ss.str();
1563 // // if(boost::filesystem::exists(scanimage_directory))
1564 // // {
1565 // // std::set<size_t> cam_ids = loadCamIdsFromDirectory(path, positionNr);
1566 
1567 // // for(const size_t& cam_id : cam_ids)
1568 // // {
1569 // // ScanCameraPtr cam(new ScanCamera);
1570 // // std::set<size_t> img_ids = loadImageIdsFromDirectory(path, positionNr, cam_id);
1571 // // for(const size_t& img_id : img_ids)
1572 // // {
1573 // // ScanImagePtr img(new ScanImage);
1574 // // loadScanImageFromDirectory(path, *img, positionNr, cam_id, img_id);
1575 // // cam->images.push_back(img);
1576 // // }
1577 // // position.cams.push_back(cam);
1578 // // }
1579 // // } else {
1580 // // std::cout << timestamp << "Warning: Specified scan has no images." << std::endl;
1581 // // }
1582 
1583 // // }
1584 // // else
1585 // // {
1586 // // std::cout << timestamp << "Scan position " << positionNr
1587 // // << " has no images." << std::endl;
1588 // // }
1589 // // return true;
1590 // }
1591 
1592 // void saveScanProjectToDirectory(const boost::filesystem::path& path, const ScanProject& project)
1593 // {
1594 // boost::filesystem::create_directory(path);
1595 
1596 // YAML::Node yaml;
1597 // yaml["pose"] = project.pose;
1598 // std::ofstream out( (path / "meta.yaml").string() );
1599 // if (out.good())
1600 // {
1601 // out << yaml;
1602 // }
1603 // else
1604 // {
1605 // std::cout << timestamp << "Warning: Unable to open "
1606 // << path.string() << "for writing." << std::endl;
1607 // }
1608 
1609 // for(size_t i = 0; i < project.positions.size(); i++)
1610 // {
1611 // saveScanPositionToDirectory(path, *project.positions[i], i);
1612 // }
1613 // }
1614 
1615 // bool loadScanProjectFromDirectory(const boost::filesystem::path& path, ScanProject& project)
1616 // {
1617 // YAML::Node meta = YAML::LoadFile((path / "meta.yaml").string() );
1618 // project.pose = meta["pose"].as<Transformd>();
1619 
1620 
1621 // boost::filesystem::directory_iterator it(path / "scans");
1622 // boost::filesystem::directory_iterator endit;
1623 
1624 // std::set<size_t> scan_pos_ids = loadPositionIdsFromDirectory(path);
1625 
1626 // for(size_t scan_pos_id : scan_pos_ids)
1627 // {
1628 // ScanPositionPtr scan_pos(new ScanPosition);
1629 // loadScanPositionFromDirectory(path, *scan_pos, scan_pos_id);
1630 // project.positions.push_back(scan_pos);
1631 // }
1632 
1633 
1634 // return true;
1635 // }
1636 
1637 } // namespace lvr2
static constexpr char sensorType[]
Description of the sensor model.
Definition: ScanTypes.hpp:141
void saveScanPosition(const boost::filesystem::path &root, const ScanPosition &scanPos, const std::string positionDirectory)
SCAN_POSITION.
std::shared_ptr< HyperspectralPanoramaChannel > HyperspectralPanoramaChannelPtr
Definition: ScanTypes.hpp:177
cv::Mat channel
OpenCV representation.
Definition: ScanTypes.hpp:174
void saveHyperspectralCamera(const boost::filesystem::path &root, const HyperspectralCamera &camera, const std::string positionDirectory, const std::string &cameraDirectory)
void saveScanCamera(const boost::filesystem::path &root, const ScanCamera &image, const std::string positionDirectory, const std::string cameraDirectory)
SCANCAMERA.
void saveScanImage(const boost::filesystem::path &root, const ScanImage &image, const size_t &positionNumber, const size_t &cameraNumber, const size_t &imageNumber)
SCANIMAGE.
Definition: ScanIOUtils.cpp:38
boost::filesystem::path getPanoramaChannelDirectory(boost::filesystem::path root, const std::string positionDirectory, const std::string panoramaDirectory)
HYPERSPECTRAL_PANORAMA_CHANNEL.
void saveScan(const boost::filesystem::path &root, const Scan &scan, const std::string positionName, const std::string scanDirectoryName, const std::string scanName)
SCAN.
bool loadScanPosition(const boost::filesystem::path &root, ScanPosition &scanPos, const std::string &positionDirectory)
boost::filesystem::path imageFile
Path to stored image.
Definition: ScanTypes.hpp:119
static Timestamp timestamp
A global time stamp object for program runtime measurement.
Definition: Timestamp.hpp:116
static ModelPtr readModel(std::string filename)
bool loadHyperspectralCamera(const boost::filesystem::path &root, HyperspectralCamera &camera, const std::string &positionDirectory, const std::string &cameraDirectory)
std::shared_ptr< HyperspectralPanorama > HyperspectralPanoramaPtr
Definition: ScanTypes.hpp:195
std::shared_ptr< Scan > ScanPtr
Shared pointer to scans.
Definition: ScanTypes.hpp:98
boost::filesystem::path getScanCameraDirectory(boost::filesystem::path root, const std::string positionDirectory, const std::string cameraDirectory)
SCANCAMERA.
static constexpr char sensorType[]
Definition: ScanTypes.hpp:42
std::vector< ScanPositionPtr > positions
Vector of scan positions for this project.
Definition: ScanTypes.hpp:336
std::shared_ptr< ScanCamera > ScanCameraPtr
Definition: ScanTypes.hpp:153
std::vector< ScanCameraPtr > cams
Image data (optional, empty vector of no images were taken)
Definition: ScanTypes.hpp:286
static constexpr char sensorType[]
Definition: ScanTypes.hpp:278
void loadScanImages(vector< ScanImagePtr > &images, boost::filesystem::path dataPath)
PointBufferPtr points
Point buffer containing the scan points.
Definition: ScanTypes.hpp:45
bool loadScanCamera(const boost::filesystem::path &root, ScanCamera &image, const std::string &positionDirectory, const std::string &cameraDirectory)
static constexpr char sensorType[]
Sensor type flag.
Definition: ScanTypes.hpp:241
std::vector< HyperspectralPanoramaPtr > panoramas
OpenCV representation.
Definition: ScanTypes.hpp:265
std::string getSensorType(const boost::filesystem::path &dir)
Gets the sensor type for a given directory. Return an empty string if the directory does not contain ...
Definition: ScanIOUtils.cpp:19
std::shared_ptr< HyperspectralCamera > HyperspectralCameraPtr
Definition: ScanTypes.hpp:268
std::shared_ptr< ScanImage > ScanImagePtr
Definition: ScanTypes.hpp:127
std::vector< ScanPtr > scans
Definition: ScanTypes.hpp:283
boost::filesystem::path getHyperspectralCameraDirectory(boost::filesystem::path root, const std::string positionDirectory, const std::string cameraDirectory)
HYPERSPECTRAL_CAMERA.
std::shared_ptr< Model > ModelPtr
Definition: Model.hpp:80
void saveHyperspectralPanoramaChannel(const boost::filesystem::path &root, const HyperspectralPanoramaChannel &channel, const std::string positionDirectory, const std::string panoramaDirectory, const size_t &channelNumber)
boost::filesystem::path channelFile
Path to stored image.
Definition: ScanTypes.hpp:171
std::vector< ScanImagePtr > images
Pointer to a set of images taken at a scan position.
Definition: ScanTypes.hpp:150
boost::filesystem::path getScanImageDirectory(boost::filesystem::path root, const std::string positionDirectory, const std::string cameraDirectory)
Definition: ScanIOUtils.cpp:67
bool loadScanImage(const boost::filesystem::path &root, ScanImage &image, const std::string &positionDirectory, const size_t &cameraNumber, const size_t &imageNumber)
bool loadScanProject(const boost::filesystem::path &root, ScanProject &scanProj)
bool loadScan(const boost::filesystem::path &root, Scan &scan, const std::string &positionDirectory, const std::string &scanDirectory, const std::string &scanName)
void saveScanProject(const boost::filesystem::path &root, const ScanProject &scanProj)
SCAN_PROJECT.
HyperspectralCameraPtr hyperspectralCamera
Image data (optional, empty vector of no hyperspactral panoramas were taken)
Definition: ScanTypes.hpp:289
std::shared_ptr< ScanPosition > ScanPositionPtr
Definition: ScanTypes.hpp:311
cv::Mat image
OpenCV representation.
Definition: ScanTypes.hpp:122
static void saveModel(ModelPtr m, std::string file)
void loadHyperspectralPanoramaChannels(std::vector< HyperspectralPanoramaChannelPtr > &channels, boost::filesystem::path dataPath)


lvr2
Author(s): Thomas Wiemann , Sebastian Pütz , Alexander Mock , Lars Kiesow , Lukas Kalbertodt , Tristan Igelbrink , Johan M. von Behren , Dominik Feldschnieders , Alexander Löhr
autogenerated on Mon Feb 28 2022 22:46:09