Helios++
Helios software for LiDAR simulations
MultiLasSyncFileWriter.h
1 #pragma once
2 
3 #include <filems/write/comps/MultiSyncFileWriter.h>
4 #include <filems/util/LasWriterSpec.h>
5 
6 #include <laswriter.hpp>
7 
8 #include <vector>
9 #include <memory>
10 
11 namespace helios { namespace filems{
12 
13 using std::vector;
14 using std::shared_ptr;
15 
23 template <typename ... WriteArgs>
24 class MultiLasSyncFileWriter : public MultiSyncFileWriter<WriteArgs ...>{
25 protected:
26  // *** ATTRIBUTES *** //
27  // ******************** //
31  vector<LasWriterSpec> lws;
35  vector<shared_ptr<LASwriter>> lw;
39  bool finished;
40 
41 public:
42  // *** CONSTRUCTION / DESTRUCTION *** //
43  // ************************************ //
52  vector<string> const &path,
53  bool const compress,
54  vector<double> const &scaleFactor,
55  vector<glm::dvec3> const &offset,
56  vector<double> const &minIntensity,
57  vector<double> const &deltaIntensity,
58  bool const createWriters = true
59  ) :
60  MultiSyncFileWriter<WriteArgs ...>(path),
61  finished(false)
62  {
63  // Initialize the specification for each LAS writer
64  size_t nWriters = path.size();
65  for(size_t i = 0 ; i < nWriters ; ++i){
66  lws.emplace_back(
67  path[i],
68  scaleFactor[i],
69  offset[i],
70  minIntensity[i],
71  deltaIntensity[i]
72  );
73  }
74  // If construct must create the writers
75  if(createWriters){
76  // Create each LASWriter
77  createLasWriters(path, compress);
78  }
79  }
81 
82  // *** CREATE WRITER *** //
83  // *********************** //
90  void createLasWriters(vector<string> const &path, bool const compress)
91  {
92  size_t const nWriters = path.size();
93  for(size_t i = 0 ; i < nWriters ; ++i){ // For each i-th writer
94  // Extract path and writer spec
95  string const &path = this->path[i];
96  LasWriterSpec &lws = this->lws[i];
97  // Craft header and point format+
98  craftSpec(lws);
99  // Add extra attributes
100  lws.addExtraAttributes();
101  // Initialize LASpoint
102  lws.initLASPoint();
103  // Create writer from specification
104  lw.push_back(lws.makeWriter(path, compress));
105  }
106  }
112  virtual void craftSpec(LasWriterSpec &lws){lws.craft();};
113 
114  // *** F I N I S H *** //
115  // ********************* //
125  void finish() override{
126  if(finished) return; // Check whether finished or not
127  // Finish each writer and its specification
128  size_t const nWriters = lw.size();
129  for(size_t i = 0 ; i < nWriters ; ++i){
130  // Extract writer and specification
131  shared_ptr<LASwriter> lw = this->lw[i];
132  LasWriterSpec &lws = this->lws[i];
133  // Do finishing stuff
134  lw->update_header(&lws.lwHeader, true); // Update the header
135  lws.finish(); // Finish the initialized specification
136  lw->close(); // Close the writer itself
137  }
138  // Flag the MultiLasSyncFileWriter as finished
139  finished = true;
140  }
141 };
142 
143 }}
Class representing the specification defining a LasWriter (not the writer itself)
Definition: LasWriterSpec.h:23
Abstract specialization of MultiSyncFileWriter to write output in LAS format.
Definition: MultiLasSyncFileWriter.h:24
MultiLasSyncFileWriter(vector< string > const &path, bool const compress, vector< double > const &scaleFactor, vector< glm::dvec3 > const &offset, vector< double > const &minIntensity, vector< double > const &deltaIntensity, bool const createWriters=true)
Constructor for Synchronous Multi LAS file writer.
Definition: MultiLasSyncFileWriter.h:51
virtual void craftSpec(LasWriterSpec &lws)
Assist the MultiLasSyncFileWriter::createLasWriters method by crafting the given specification.
Definition: MultiLasSyncFileWriter.h:112
vector< shared_ptr< LASwriter > > lw
The LASwriter used to write to each LAS file.
Definition: MultiLasSyncFileWriter.h:35
void finish() override
MultiLasSyncFileWriter updates each header and guarantees all writings have been done only after the ...
Definition: MultiLasSyncFileWriter.h:125
void createLasWriters(vector< string > const &path, bool const compress)
Creation of each LasWriter , including LASpoint initialization.
Definition: MultiLasSyncFileWriter.h:90
bool finished
Flag used to control the sync writer status.
Definition: MultiLasSyncFileWriter.h:39
MultiLasSyncFileWriter()
Default constructor for Synchronous Multi LAS file writer.
Definition: MultiLasSyncFileWriter.h:47
vector< LasWriterSpec > lws
The specifications defining each LAS writer.
Definition: MultiLasSyncFileWriter.h:31
Abstract class defining common behavior for all synchronous writers that work with multiple files at ...
Definition: MultiSyncFileWriter.h:21
std::vector< std::string > path
Paths to the files to be written.
Definition: MultiSyncFileWriter.h:28