summaryrefslogtreecommitdiffstats
path: root/src/3rdparty/assimp/contrib/Open3DGC/o3dgcAdjacencyInfo.h
blob: 72fe3d4c6cd92236a86b343298c524cf72964918 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
/*
Copyright (c) 2013 Khaled Mammou - Advanced Micro Devices, Inc.

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
*/


#pragma once
#ifndef O3DGC_ADJACENCY_INFO_H
#define O3DGC_ADJACENCY_INFO_H

#include "o3dgcCommon.h"

namespace o3dgc
{
    const long O3DGC_MIN_NEIGHBORS_SIZE     = 128;
    const long O3DGC_MIN_NUM_NEIGHBORS_SIZE = 16;
    //! 
    class AdjacencyInfo
    {
    public:
        //! Constructor.
                                AdjacencyInfo(long numNeighborsSize = O3DGC_MIN_NUM_NEIGHBORS_SIZE,
                                              long neighborsSize    = O3DGC_MIN_NUM_NEIGHBORS_SIZE)
                                {
                                    m_numElements      = 0;
                                    m_neighborsSize    = neighborsSize; 
                                    m_numNeighborsSize = numNeighborsSize;
                                    m_numNeighbors     = new long [m_numNeighborsSize];
                                    m_neighbors        = new long [m_neighborsSize   ];
                                };
        //! Destructor.
                                ~AdjacencyInfo(void)
                                {
                                    delete [] m_neighbors;
                                    delete [] m_numNeighbors;
                                };
        O3DGCErrorCode          Allocate(long numNeighborsSize, long neighborsSize)
                                {
                                    m_numElements = numNeighborsSize;
                                    if (neighborsSize > m_neighborsSize)
                                    {
                                        delete [] m_numNeighbors;
                                        m_neighborsSize    = neighborsSize;
                                        m_numNeighbors     = new long [m_numNeighborsSize];
                                    }
                                    if (numNeighborsSize > m_numNeighborsSize)
                                    {
                                        delete [] m_neighbors;
                                        m_numNeighborsSize = numNeighborsSize;
                                        m_neighbors        = new long [m_neighborsSize];
                                    }
                                    return O3DGC_OK;
                                }
        O3DGCErrorCode          AllocateNumNeighborsArray(long numElements)
                                {
                                    if (numElements > m_numNeighborsSize)
                                    {
                                        delete [] m_numNeighbors;
                                        m_numNeighborsSize = numElements;
                                        m_numNeighbors = new long [m_numNeighborsSize];
                                    }
                                    m_numElements = numElements;
                                    return O3DGC_OK;
                                }
        O3DGCErrorCode          AllocateNeighborsArray()
                                {
                                    for(long i = 1; i < m_numElements; ++i)
                                    {
                                        m_numNeighbors[i] += m_numNeighbors[i-1];
                                    }
                                    if (m_numNeighbors[m_numElements-1] > m_neighborsSize)
                                    {
                                        delete [] m_neighbors;
                                        m_neighborsSize = m_numNeighbors[m_numElements-1];
                                        m_neighbors = new long [m_neighborsSize];
                                    }
                                    return O3DGC_OK;
                                }
        O3DGCErrorCode          ClearNumNeighborsArray()
                                {
                                    memset(m_numNeighbors, 0x00, sizeof(long) * m_numElements);
                                    return O3DGC_OK;
                                }
        O3DGCErrorCode          ClearNeighborsArray()
                                {
                                    memset(m_neighbors, 0xFF, sizeof(long) * m_neighborsSize);
                                    return O3DGC_OK;
                                }
        O3DGCErrorCode          AddNeighbor(long element, long neighbor)
                                {
                                    assert(m_numNeighbors[element] <= m_numNeighbors[m_numElements-1]);
                                    long p0 = Begin(element);
                                    long p1 = End(element);
                                    for(long p = p0; p < p1; p++)
                                    {
                                        if (m_neighbors[p] == -1)
                                        {
                                            m_neighbors[p] = neighbor;
                                            return O3DGC_OK;
                                        }
                                    }
                                    return O3DGC_ERROR_BUFFER_FULL;
                                }
        long                    Begin(long element) const 
                                {
                                    assert(element < m_numElements);
                                    assert(element >= 0);
                                    return (element>0)?m_numNeighbors[element-1]:0;
                                }
        long                    End(long element) const
                                {
                                    assert(element < m_numElements);
                                    assert(element >= 0);
                                    return m_numNeighbors[element];
                                }
        long                    GetNeighbor(long element) const
                                {
                                    assert(element < m_neighborsSize);
                                    assert(element >= 0);
                                    return m_neighbors[element];
                                }    
        long                    GetNumNeighbors(long element)  const 
                                { 
                                    return End(element) - Begin(element);
                                }
        long *                  GetNumNeighborsBuffer() { return m_numNeighbors;}
        long *                  GetNeighborsBuffer()    { return m_neighbors;}

    private:
        long                    m_neighborsSize;    // actual allocated size for m_neighbors
        long                    m_numNeighborsSize; // actual allocated size for m_numNeighbors
        long                    m_numElements;      // number of elements 
        long *                  m_neighbors;        // 
        long *                  m_numNeighbors;     //         
    };
}
#endif // O3DGC_ADJACENCY_INFO_H