ACloudViewer  3.9.4
A Modern Library for 3D Data Processing
LasIOFilter.h
Go to the documentation of this file.
1 // ----------------------------------------------------------------------------
2 // - CloudViewer: www.cloudViewer.org -
3 // ----------------------------------------------------------------------------
4 // Copyright (c) 2018-2024 www.cloudViewer.org
5 // SPDX-License-Identifier: MIT
6 // ----------------------------------------------------------------------------
7 
8 #pragma once
9 
10 // ##########################################################################
11 // # #
12 // # CloudViewer PLUGIN: LAS-IO Plugin #
13 // # #
14 // # This program is free software; you can redistribute it and/or modify #
15 // # it under the terms of the GNU General Public License as published by #
16 // # the Free Software Foundation; version 2 of the License. #
17 // # #
18 // # This program is distributed in the hope that it will be useful, #
19 // # but WITHOUT ANY WARRANTY; without even the implied warranty of #
20 // # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the #
21 // # GNU General Public License for more details. #
22 // # #
23 // # COPYRIGHT: Thomas Montaigu #
24 // # #
25 // ##########################################################################
26 
27 #include "FileIOFilter.h"
28 #include "LasDetails.h"
29 #include "LasExtraScalarField.h"
30 #include "LasOpenDialog.h"
31 
32 // System
33 #include <memory>
34 
35 class LasIOFilter : public FileIOFilter
36 {
37  public:
38  LasIOFilter();
39 
40  // Inherited from FileIOFilter
41  CC_FILE_ERROR loadFile(const QString& fileName, ccHObject& container, LoadParameters& parameters) override;
42  bool canSave(CV_CLASS_ENUM type, bool& multiple, bool& exclusive) const override;
43  CC_FILE_ERROR saveToFile(ccHObject* entity, const QString& filename, const SaveParameters& parameters) override;
44 
45  private:
46  struct FileInfo
47  {
49  std::vector<LasExtraScalarField> extraScalarFields;
50 
51  bool operator==(const FileInfo& other)
52  {
53  bool versionIsSame = version.minorVersion == other.version.minorVersion && version.pointFormat == other.version.pointFormat;
54  if (!versionIsSame)
55  {
56  return false;
57  }
58 
59  if (extraScalarFields.size() != other.extraScalarFields.size())
60  {
61  return false;
62  }
63 
64  for (size_t i = 0; i < extraScalarFields.size(); ++i)
65  {
66  const auto& lhs = extraScalarFields[i];
67  const auto& rhs = other.extraScalarFields[i];
68 
69  if (strncmp(lhs.name, rhs.name, LasExtraScalarField::MAX_NAME_SIZE) != 0
70  || lhs.type != rhs.type
71  || lhs.byteOffset != rhs.byteOffset
72  || lhs.numElements() != rhs.numElements()
73  || lhs.options != rhs.options)
74  {
75  return false;
76  }
77  }
78  return true;
79  }
80 
81  bool operator!=(const FileInfo& other)
82  {
83  return !(*this == other);
84  }
85  };
86 
87  std::unique_ptr<FileInfo> m_infoOfLastOpened;
88  LasOpenDialog m_openDialog{};
89 };
int64_t CV_CLASS_ENUM
Type of object type flags (64 bits)
Definition: CVTypes.h:97
std::string filename
std::string version
char type
CC_FILE_ERROR
Typical I/O filter errors.
Definition: FileIOFilter.h:20
Generic file I/O filter.
Definition: FileIOFilter.h:46
static constexpr unsigned MAX_NAME_SIZE
CC_FILE_ERROR loadFile(const QString &fileName, ccHObject &container, LoadParameters &parameters) override
Loads one or more entities from a file.
Definition: LasIOFilter.cpp:91
bool canSave(CV_CLASS_ENUM type, bool &multiple, bool &exclusive) const override
Returns whether this I/O filter can save the specified type of entity.
CC_FILE_ERROR saveToFile(ccHObject *entity, const QString &filename, const SaveParameters &parameters) override
Saves an entity (or a group of) to a file.
Dialog shown to the user when opening a LAS file.
Definition: LasOpenDialog.h:46
Hierarchical CLOUDVIEWER Object.
Definition: ecvHObject.h:25
constexpr bool operator!=(const optional< T > &x, const optional< T > &y)
Definition: Optional.h:620
constexpr bool operator==(const optional< T > &x, const optional< T > &y)
Definition: Optional.h:615
Generic loading parameters.
Definition: FileIOFilter.h:51
Generic saving parameters.
Definition: FileIOFilter.h:84
See SelectBestVersion
Definition: LasDetails.h:178