ImagingTools Core SDK
CMesh3d.h
1// SPDX-License-Identifier: LGPL-2.1-or-later OR GPL-2.0-or-later OR GPL-3.0-or-later OR LicenseRef-ImtCore-Commercial
2#pragma once
3
4
5// Qt includes
6#include <QtCore/QFile>
7
8// ImtCore includes
9#include <imt3d/IMesh3d.h>
10#include <imt3d/CPointsBasedObject.h>
11
12
13namespace imt3d
14{
15
16
20class CMesh3d: virtual public IMesh3d, public CPointsBasedObject
21{
22public:
24
25 bool SaveToStlFile(const QString& filePath) const;
26 bool LoadFromStlFile(const QString& filePath, bool ensureNormalExists);
27
28 // reimplemented (imt3d::IMesh3d)
29 virtual bool CreateMesh(PointFormat pointFormat) override;
30 virtual bool CreateMesh(PointFormat pointFormat, int pointsCount, const void* pointsDataPtr, const Indices& indices) override;
31 virtual bool InsertData(int pointsCount, const void* pointsDataPtr, const Indices& indices) override;
32 virtual const Indices& GetIndices() const override;
33
34 // reimplemented (iser::ISerializable)
35 virtual bool Serialize(iser::IArchive& archive) override;
36
37 // reimplemented (istd::IChangeable)
38 virtual int GetSupportedOperations() const override;
39 virtual bool CopyFrom(const IChangeable& object, CompatibilityMode mode = CM_WITHOUT_REFS) override;
40 virtual bool IsEqual(const IChangeable& object) const override;
41 virtual istd::IChangeableUniquePtr CloneMe(CompatibilityMode mode = CM_WITHOUT_REFS) const override;
42 virtual bool ResetData(CompatibilityMode mode = CM_WITHOUT_REFS) override;
43
44private:
45 template <typename PointType> bool SaveToStlFile(const QString& filePath) const;
46 template <typename DataType> bool WriteTypedValue(const DataType& data, QFile& file) const;
47 template <typename PointType> bool WritePointData(int pointIndex, int pointComponentOffset, QFile& file) const;
48 bool ReadPointData(QFile& file, float* pointBufPtr) const;
49 void EnsureNormalExists(
50 IPointsBasedObject::PointXyzwNormal32& point1,
51 IPointsBasedObject::PointXyzwNormal32& point2,
52 IPointsBasedObject::PointXyzwNormal32& point3) const;
53
54private:
55 Indices m_indices;
56 static const int s_stlHeaderSize = 80;
57};
58
59
60} // namespace imt3d
61
62