Coverage Report

Created: 2026-09-14 07:44

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/assimp/code/AssetLib/Ply/PlyLoader.h
Line
Count
Source
1
/*
2
Open Asset Import Library (assimp)
3
----------------------------------------------------------------------
4
5
Copyright (c) 2006-2026, assimp team
6
7
All rights reserved.
8
9
Redistribution and use of this software in source and binary forms,
10
with or without modification, are permitted provided that the
11
following conditions are met:
12
13
* Redistributions of source code must retain the above
14
  copyright notice, this list of conditions and the
15
  following disclaimer.
16
17
* Redistributions in binary form must reproduce the above
18
  copyright notice, this list of conditions and the
19
  following disclaimer in the documentation and/or other
20
  materials provided with the distribution.
21
22
* Neither the name of the assimp team, nor the names of its
23
  contributors may be used to endorse or promote products
24
  derived from this software without specific prior
25
  written permission of the assimp team.
26
27
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
28
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
29
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
30
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
31
OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
32
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
33
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
34
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
35
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
36
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
37
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
38
39
----------------------------------------------------------------------
40
*/
41
42
/** @file  PLYLoader.h
43
 *  @brief Declaration of the .ply importer class.
44
 */
45
#pragma once
46
#ifndef AI_PLYLOADER_H_INCLUDED
47
#define AI_PLYLOADER_H_INCLUDED
48
49
#include "PlyParser.h"
50
#include <assimp/BaseImporter.h>
51
#include <assimp/types.h>
52
#include <vector>
53
54
struct aiNode;
55
struct aiMaterial;
56
struct aiMesh;
57
58
namespace Assimp {
59
60
using namespace PLY;
61
62
// ---------------------------------------------------------------------------
63
/// @brief Importer class to load the stanford PLY file format
64
// ---------------------------------------------------------------------------
65
class PLYImporter final : public BaseImporter {
66
public:
67
    /// @brief Default constructor
68
146k
    PLYImporter() = default;
69
70
    /// @brief Destructor
71
    ~PLYImporter() override;
72
73
    // -------------------------------------------------------------------
74
    /// Returns whether the class can handle the format of the given file.
75
    /// @see BaseImporter::CanRead() for details.
76
    bool CanRead(const std::string &pFile, IOSystem *pIOHandler, bool checkSig) const override;
77
78
    // -------------------------------------------------------------------
79
    /// Extract a vertex from the DOM
80
    void LoadVertex(const PLY::Element *pcElement, const PLY::ElementInstance *instElement, unsigned int pos);
81
82
    // -------------------------------------------------------------------
83
    /// @brief Extract a face from the DOM
84
    /// The function will also take care of the correct winding order of the triangles.
85
    /// @param pcElement The element containing the face data
86
    /// @param instElement The element instance containing the face data
87
    /// @param pos The position of the face in the element instance. This is needed to correctly assign the face to the mesh.
88
    void LoadFace(const PLY::Element *pcElement, const PLY::ElementInstance *instElement, unsigned int pos);
89
90
    /// @brief Will create a triangle from a triangle strip. 
91
    /// The function will use the first three vertices of the strip to create the first triangle, then the second,
92
    /// third and fourth vertex to create the second triangle and so on. The function will also take care of the correct 
93
    /// winding order of the triangles.
94
    /// @param instElement The element instance containing the triangle strip data
95
    /// @param iProperty   The index of the property containing the triangle strip data
96
    /// @param eType       The data type of the triangle strip data
97
    void createFromeTriStrip(const Assimp::PLY::ElementInstance *instElement, unsigned int iProperty, Assimp::PLY::EDataType eType);
98
99
protected:
100
    // -------------------------------------------------------------------
101
    const aiImporterDesc *GetInfo() const override;
102
103
    // -------------------------------------------------------------------
104
    void InternReadFile(const std::string &pFile, aiScene *pScene, IOSystem *pIOHandler) override;
105
106
    // -------------------------------------------------------------------
107
    /// @brief  Extract a material list from the DOM    
108
    /// @param pvOut          The output material list. The function will fill the list with the extracted materials.
109
    /// @param defaultTexture The default texture to use for the materials. This is needed to correctly assign the texture to the materials.
110
    /// @param pointsOnly     Whether the file contains only points. This is needed to correctly assign the material properties.
111
    void LoadMaterial(std::vector<aiMaterial *> *pvOut, std::string &defaultTexture, const bool pointsOnly);
112
113
private:
114
    unsigned char *mBuffer{nullptr};
115
    PLY::DOM *pcDOM{nullptr};
116
    aiMesh *mGeneratedMesh{nullptr};
117
};
118
119
} // end of namespace Assimp
120
121
#endif // AI_3DSIMPORTER_H_INC