19 : m_cloudToSave(cloud)
26 initLaszipHeader(parameters);
31 if (totalExtraByteSize > 0)
33 m_laszipHeader.point_data_record_length += totalExtraByteSize;
35 size_t newNumVlrs = m_laszipHeader.number_of_variable_length_records + 1;
38 for (
size_t i = 0; i < m_laszipHeader.number_of_variable_length_records; i++)
40 vlrs[i] = m_laszipHeader.vlrs[i];
44 delete m_laszipHeader.vlrs;
45 m_laszipHeader.vlrs = vlrs;
46 m_laszipHeader.number_of_variable_length_records =
static_cast<laszip_U32
>(newNumVlrs);
58 m_waveformSaver = std::make_unique<LasWaveformSaver>(cloud);
62 void LasSaver::initLaszipHeader(
const Parameters& parameters)
64 QDate currentDate = QDate::currentDate();
65 m_laszipHeader.file_creation_year = currentDate.year();
66 m_laszipHeader.file_creation_day = currentDate.dayOfYear();
68 m_laszipHeader.version_major = parameters.versionMajor;
69 m_laszipHeader.version_minor = parameters.versionMinor;
70 m_laszipHeader.point_data_format = parameters.pointFormat;
76 m_laszipHeader.global_encoding |= 0b0000'0100;
77 m_laszipHeader.global_encoding &= (~0b0000'0010);
81 m_laszipHeader.offset_to_point_data = m_laszipHeader.header_size;
88 m_laszipHeader.number_of_variable_length_records = vlr.
numVlrs();
89 for (laszip_U32 i = 0; i < m_laszipHeader.number_of_variable_length_records; ++i)
93 m_laszipHeader.offset_to_point_data +=
LasDetails::SizeOfVlrs(m_laszipHeader.vlrs, m_laszipHeader.number_of_variable_length_records);
97 m_laszipHeader.x_scale_factor = parameters.lasScale.x;
98 m_laszipHeader.y_scale_factor = parameters.lasScale.y;
99 m_laszipHeader.z_scale_factor = parameters.lasScale.z;
102 m_laszipHeader.x_offset = parameters.lasOffset.x;
103 m_laszipHeader.y_offset = parameters.lasOffset.y;
104 m_laszipHeader.z_offset = parameters.lasOffset.z;
106 strncpy(m_laszipHeader.generating_software,
"ACloudViewer", 32);
112 laszip_close_writer(m_laszipWriter);
113 laszip_clean(m_laszipWriter);
114 laszip_destroy(m_laszipWriter);
120 laszip_CHAR* errorMsg{
nullptr};
121 if (laszip_create(&m_laszipWriter))
127 if (laszip_set_header(m_laszipWriter, &m_laszipHeader))
129 laszip_get_error(m_laszipWriter, &errorMsg);
134 if (laszip_open_writer(m_laszipWriter, qPrintable(filePath), filePath.endsWith(
"laz")))
136 laszip_get_error(m_laszipWriter, &errorMsg);
141 if (laszip_get_point_pointer(m_laszipWriter, &m_laszipPoint))
143 fprintf(stderr,
"DLL ERROR: getting point pointer from laszip writer\n");
158 if (m_currentPointIndex >= m_cloudToSave.
size())
162 laszip_CHAR* errorMsg{
nullptr};
165 int totalExtraByteSize = m_laszipPoint->num_extra_bytes;
166 laszip_U8* extra_bytes = m_laszipPoint->extra_bytes;
168 m_laszipPoint->extra_bytes = extra_bytes;
169 m_laszipPoint->num_extra_bytes = totalExtraByteSize;
170 m_laszipPoint->extended_point_type = m_laszipHeader.point_data_format >= 6;
175 laszip_F64 coords[3];
176 coords[0] = globalPoint.
x;
177 coords[1] = globalPoint.
y;
178 coords[2] = globalPoint.
z;
180 if (laszip_set_coordinates(m_laszipWriter, coords))
182 laszip_get_error(m_laszipWriter, &errorMsg);
192 m_waveformSaver->handlePoint(m_currentPointIndex, *m_laszipPoint);
199 m_laszipPoint->rgb[0] =
static_cast<laszip_U16
>(
color.r) << 8;
200 m_laszipPoint->rgb[1] =
static_cast<laszip_U16
>(
color.g) << 8;
201 m_laszipPoint->rgb[2] =
static_cast<laszip_U16
>(
color.b) << 8;
204 if (laszip_write_point(m_laszipWriter))
206 laszip_get_error(m_laszipWriter, &errorMsg);
211 if (laszip_update_inventory(m_laszipWriter))
213 laszip_get_error(m_laszipWriter, &errorMsg);
218 m_currentPointIndex++;
224 return m_waveformSaver !=
nullptr;
229 laszip_CHAR* errorMsg{
nullptr};
230 laszip_get_error(m_laszipWriter, &errorMsg);
float PointCoordinateType
Type of the coordinates of a (N-D) point.
CC_FILE_ERROR
Typical I/O filter errors.
@ CC_FERR_THIRD_PARTY_LIB_FAILURE
laszip_vlr laszip_vlr_struct
static bool Warning(const char *format,...)
Prints out a formatted warning message in console.
LasSaver(ccPointCloud &cloud, Parameters ¶meters)
CC_FILE_ERROR open(const QString filePath)
bool savesWaveforms() const
QString getLastError() const
CC_FILE_ERROR saveNextPoint()
void setStandarFields(std::vector< LasScalarField > &&standardFields)
void setExtraFields(std::vector< LasExtraScalarField > &&extraFields)
void handleExtraFields(size_t pointIndex, laszip_point &point)
Saves the extra scalar fields values for pointIndex into the given laszip_point.
void handleScalarFields(size_t pointIndex, laszip_point &point)
Saves the scalar fields values for pointIndex into the given laszip_point.
A 3D cloud and its associated features (color, normals, scalar fields, etc.)
bool hasFWF() const
Returns whether the cloud has associated Full WaveForm data.
bool hasColors() const override
Returns whether colors are enabled or not.
const ecvColor::Rgb & getPointColor(unsigned pointIndex) const override
Returns color corresponding to a given point.
CCVector3d toGlobal3d(const Vector3Tpl< T > &Plocal) const
Returns the point back-projected into the original coordinates system.
unsigned size() const override
const CCVector3 * getPoint(unsigned index) const override
uint16_t PointFormatSize(unsigned pointFormat)
bool HasRGB(unsigned pointFormatId)
Returns whether the point format supports RGB.
bool HasWaveform(unsigned pointFormatId)
Returns whether the point format supports Waveforms.
uint16_t HeaderSize(unsigned versionMinor)
Returns the header size for the given minor version of the standard used.
void CloneVlrInto(const laszip_vlr_struct &src, laszip_vlr_struct &dst)
Clones the content of the src vlr into the dst vlr.
unsigned SizeOfVlrs(const laszip_vlr_struct *vlrs, unsigned numVlrs)
std::vector< LasScalarField > standardFields
std::vector< LasExtraScalarField > extraFields
std::vector< laszip_vlr_struct > vlrs
laszip_U32 numVlrs() const