Helios++
Helios software for LiDAR simulations
LasSyncFileWriter.h
1 #pragma once
2 
3 #include <filems/write/comps/SingleSyncFileWriter.h>
4 #include <filems/util/LasWriterSpec.h>
5 
6 #include <laswriter.hpp>
7 #include <glm/glm.hpp>
8 
9 #include <memory>
10 #include <string>
11 #include <ctime>
12 
13 namespace helios { namespace filems{
14 
22 template <typename ... WriteArgs>
23 class LasSyncFileWriter : public SingleSyncFileWriter<WriteArgs ...>{
24 protected:
25  // *** ATTRIBUTES *** //
26  // ******************** //
34  std::shared_ptr<LASwriter> lw;
38  bool finished;
39 
40 public:
41  // *** CONSTRUCTION / DESTRUCTION *** //
42  // ************************************ //
46  LasSyncFileWriter() : SingleSyncFileWriter<WriteArgs ...>() {};
58  const std::string &path,
59  bool const compress = false,
60  double const scaleFactor = 0.0001,
61  glm::dvec3 const offset = glm::dvec3(0, 0, 0),
62  double const minIntensity = 0.0,
63  double const deltaIntensity = 1000000.0,
64  bool const createWriter = true
65 
66  ) :
67  SingleSyncFileWriter<WriteArgs ...>(path),
68  lws(path, scaleFactor, offset, minIntensity, deltaIntensity),
69  finished(false)
70  {
71  // If construct must create the writer
72  if(createWriter){
73  // Create LASWriter
74  createLasWriter(path, compress);
75  }
76  }
77 
79 
80  // *** CREATE WRITER *** //
81  // *********************** //
88  virtual void createLasWriter(const std::string & path, bool const compress)
89  {
90  // Craft header and point format
91  craftSpec(lws);
92 
93  // Add extra attributes
95 
96  // Initialize LASpoint
97  lws.initLASPoint();
98 
99  // Create writer from specification
100  lw = lws.makeWriter(path, compress);
101  }
107  virtual void craftSpec(LasWriterSpec &lws){lws.craft();}
108 
109  // *** F I N I S H *** //
110  // ********************* //
120  void finish() override{
121  if(finished) return; // Check whether finished or not
122  lw->update_header(&lws.lwHeader, true); // Update the writer's header
123  lws.finish(); // Finish the initialized specification
124  lw->close(); // Close the writer itself
125  finished = true; // Flag as finished
126  };
127 };
128 
129 }}
Abstract specialization of SingleSyncFileWriter to write output in LAS format.
Definition: LasSyncFileWriter.h:23
LasWriterSpec lws
The specification defining the LAS writer.
Definition: LasSyncFileWriter.h:30
void finish() override
LasSyncFileWriter updates header and guarantees writings have been done only after the finish method ...
Definition: LasSyncFileWriter.h:120
std::shared_ptr< LASwriter > lw
LASwriter. Used to write to LAS file.
Definition: LasSyncFileWriter.h:34
virtual void craftSpec(LasWriterSpec &lws)
Assist the LasSyncFileWriter::createLasWriters method by crafting the given specification.
Definition: LasSyncFileWriter.h:107
virtual void createLasWriter(const std::string &path, bool const compress)
Creation of the LasWriter itself, including LASpoint initialization.
Definition: LasSyncFileWriter.h:88
bool finished
Flag used to control the sync writer status.
Definition: LasSyncFileWriter.h:38
LasSyncFileWriter()
Default constructor for Synchronous LAS file writer.
Definition: LasSyncFileWriter.h:46
LasSyncFileWriter(const std::string &path, bool const compress=false, double const scaleFactor=0.0001, glm::dvec3 const offset=glm::dvec3(0, 0, 0), double const minIntensity=0.0, double const deltaIntensity=1000000.0, bool const createWriter=true)
Synchronous LAS file writer constructor.
Definition: LasSyncFileWriter.h:57
Class representing the specification defining a LasWriter (not the writer itself)
Definition: LasWriterSpec.h:23
LASheader lwHeader
Header definition for the LAS file.
Definition: LasWriterSpec.h:34
void addExtraAttributes()
Creation of extra attributes to be added to each record.
Definition: LasWriterSpec.h:244
void initLASPoint()
Initialize the LAS point structure with data from header.
Definition: LasWriterSpec.h:300
void craft()
Craft the header of the LAS File for version 1.0.
Definition: LasWriterSpec.h:182
void finish()
Remove and release everything that has been initialized in the process of building the writer from th...
Definition: LasWriterSpec.h:332
shared_ptr< LASwriter > makeWriter(std::string const &path, bool const compress)
Build a LAS writer from this specification.
Definition: LasWriterSpec.h:315
Abstract class defining common behavior for all synchronous writers that work with a single file at a...
Definition: SingleSyncFileWriter.h:21
std::string path
Path to file to be written.
Definition: SingleSyncFileWriter.h:28