1/*
2Open Asset Import Library (assimp)
3----------------------------------------------------------------------
4
5Copyright (c) 2006-2017, assimp team
6
7All rights reserved.
8
9Redistribution and use of this software in source and binary forms,
10with or without modification, are permitted provided that the
11following 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
27THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
28"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
29LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
30A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
31OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
32SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
33LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
34DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
35THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
36(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
37OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
38
39----------------------------------------------------------------------
40*/
41
42/** @file Defines a helper class to compute a vertex-triangle adjacency map */
43#ifndef AI_VTADJACENCY_H_INC
44#define AI_VTADJACENCY_H_INC
45
46#include "BaseProcess.h"
47#include <assimp/types.h>
48#include <assimp/ai_assert.h>
49
50struct aiMesh;
51struct aiFace;
52
53namespace Assimp {
54
55// --------------------------------------------------------------------------------------------
56/** @brief The VertexTriangleAdjacency class computes a vertex-triangle
57 * adjacency map from a given index buffer.
58 *
59 * @note Although it is called #VertexTriangleAdjacency, the current version does also
60 * support arbitrary polygons. */
61// --------------------------------------------------------------------------------------------
62class ASSIMP_API VertexTriangleAdjacency
63{
64public:
65
66 // ----------------------------------------------------------------------------
67 /** @brief Construction from an existing index buffer
68 * @param pcFaces Index buffer
69 * @param iNumFaces Number of faces in the buffer
70 * @param iNumVertices Number of referenced vertices. This value
71 * is computed automatically if 0 is specified.
72 * @param bComputeNumTriangles If you want the class to compute
73 * a list containing the number of referenced triangles per vertex
74 * per vertex - pass true. */
75 VertexTriangleAdjacency(aiFace* pcFaces,unsigned int iNumFaces,
76 unsigned int iNumVertices = 0,
77 bool bComputeNumTriangles = true);
78
79
80 // ----------------------------------------------------------------------------
81 /** @brief Destructor */
82 ~VertexTriangleAdjacency();
83
84
85public:
86
87 // ----------------------------------------------------------------------------
88 /** @brief Get all triangles adjacent to a vertex
89 * @param iVertIndex Index of the vertex
90 * @return A pointer to the adjacency list. */
91 unsigned int* GetAdjacentTriangles(unsigned int iVertIndex) const
92 {
93 ai_assert(iVertIndex < iNumVertices);
94 return &mAdjacencyTable[ mOffsetTable[iVertIndex]];
95 }
96
97
98 // ----------------------------------------------------------------------------
99 /** @brief Get the number of triangles that are referenced by
100 * a vertex. This function returns a reference that can be modified
101 * @param iVertIndex Index of the vertex
102 * @return Number of referenced triangles */
103 unsigned int& GetNumTrianglesPtr(unsigned int iVertIndex)
104 {
105 ai_assert(iVertIndex < iNumVertices && NULL != mLiveTriangles);
106 return mLiveTriangles[iVertIndex];
107 }
108
109
110public:
111
112 //! Offset table
113 unsigned int* mOffsetTable;
114
115 //! Adjacency table
116 unsigned int* mAdjacencyTable;
117
118 //! Table containing the number of referenced triangles per vertex
119 unsigned int* mLiveTriangles;
120
121 //! Debug: Number of referenced vertices
122 unsigned int iNumVertices;
123
124};
125}
126
127#endif // !! AI_VTADJACENCY_H_INC
128