1 /*
2 Copyright (c) 2013 Khaled Mammou - Advanced Micro Devices, Inc.
3 
4 Permission is hereby granted, free of charge, to any person obtaining a copy
5 of this software and associated documentation files (the "Software"), to deal
6 in the Software without restriction, including without limitation the rights
7 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8 copies of the Software, and to permit persons to whom the Software is
9 furnished to do so, subject to the following conditions:
10 
11 The above copyright notice and this permission notice shall be included in
12 all copies or substantial portions of the Software.
13 
14 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
20 THE SOFTWARE.
21 */
22 
23 
24 #pragma once
25 #ifndef O3DGC_INDEXED_FACE_SET_H
26 #define O3DGC_INDEXED_FACE_SET_H
27 
28 #include "o3dgcCommon.h"
29 
30 namespace o3dgc
31 {
32     template<class T>
33     class IndexedFaceSet
34     {
35     public:
36         //! Constructor.
IndexedFaceSet(void)37                                          IndexedFaceSet(void)
38                                          {
39                                              memset(this, 0, sizeof(IndexedFaceSet));
40                                              m_ccw              = true;
41                                              m_solid            = true;
42                                              m_convex           = true;
43                                              m_isTriangularMesh = true;
44                                              m_creaseAngle      = 30;
45                                          };
46         //! Destructor.
~IndexedFaceSet(void)47                                          ~IndexedFaceSet(void) {};
48 
GetNCoordIndex()49         unsigned long                    GetNCoordIndex() const { return m_nCoordIndex     ;}
50         // only coordIndex is supported
GetNCoord()51         unsigned long                    GetNCoord()           const { return m_nCoord         ;}
GetNNormal()52         unsigned long                    GetNNormal()          const { return m_nNormal        ;}
GetNFloatAttribute(unsigned long a)53         unsigned long                    GetNFloatAttribute(unsigned long a)  const
54                                          {
55                                              assert(a < O3DGC_SC3DMC_MAX_NUM_FLOAT_ATTRIBUTES);
56                                              return m_nFloatAttribute[a];
57                                          }
GetNIntAttribute(unsigned long a)58         unsigned long                    GetNIntAttribute(unsigned long a)  const
59                                          {
60                                              assert(a < O3DGC_SC3DMC_MAX_NUM_INT_ATTRIBUTES);
61                                              return m_nIntAttribute[a];
62                                          }
GetNumFloatAttributes()63         unsigned long                    GetNumFloatAttributes()  const { return m_numFloatAttributes;}
GetNumIntAttributes()64         unsigned long                    GetNumIntAttributes()    const { return m_numIntAttributes  ;}
GetCoordMin()65         const Real *                     GetCoordMin   () const { return m_coordMin;}
GetCoordMax()66         const Real *                     GetCoordMax   () const { return m_coordMax;}
GetNormalMin()67         const Real *                     GetNormalMin  () const { return m_normalMin;}
GetNormalMax()68         const Real *                     GetNormalMax  () const { return m_normalMax;}
GetCoordMin(int j)69         Real                             GetCoordMin   (int j)  const { return m_coordMin[j]       ;}
GetCoordMax(int j)70         Real                             GetCoordMax   (int j)  const { return m_coordMax[j]       ;}
GetNormalMin(int j)71         Real                             GetNormalMin  (int j)  const { return m_normalMin[j]      ;}
GetNormalMax(int j)72         Real                             GetNormalMax  (int j)  const { return m_normalMax[j]      ;}
73 
GetFloatAttributeType(unsigned long a)74         O3DGCIFSFloatAttributeType       GetFloatAttributeType(unsigned long a) const
75                                          {
76                                              assert(a < O3DGC_SC3DMC_MAX_NUM_FLOAT_ATTRIBUTES);
77                                              return m_typeFloatAttribute[a];
78                                          }
GetIntAttributeType(unsigned long a)79         O3DGCIFSIntAttributeType         GetIntAttributeType(unsigned long a) const
80                                          {
81                                              assert(a < O3DGC_SC3DMC_MAX_NUM_INT_ATTRIBUTES);
82                                              return m_typeIntAttribute[a];
83                                          }
GetFloatAttributeDim(unsigned long a)84         unsigned long                    GetFloatAttributeDim(unsigned long a) const
85                                          {
86                                              assert(a < O3DGC_SC3DMC_MAX_NUM_FLOAT_ATTRIBUTES);
87                                              return m_dimFloatAttribute[a];
88                                          }
GetIntAttributeDim(unsigned long a)89         unsigned long                    GetIntAttributeDim(unsigned long a) const
90                                          {
91                                              assert(a < O3DGC_SC3DMC_MAX_NUM_INT_ATTRIBUTES);
92                                              return m_dimIntAttribute[a];
93                                          }
GetFloatAttributeMin(unsigned long a)94         const Real *                     GetFloatAttributeMin(unsigned long a) const
95                                          {
96                                              assert(a < O3DGC_SC3DMC_MAX_NUM_FLOAT_ATTRIBUTES);
97                                              return &(m_minFloatAttribute[a * O3DGC_SC3DMC_MAX_DIM_ATTRIBUTES]);
98                                          }
GetFloatAttributeMax(unsigned long a)99         const Real *                     GetFloatAttributeMax(unsigned long a) const
100                                          {
101                                              assert(a < O3DGC_SC3DMC_MAX_NUM_FLOAT_ATTRIBUTES);
102                                              return &(m_maxFloatAttribute[a * O3DGC_SC3DMC_MAX_DIM_ATTRIBUTES]);
103                                          }
GetFloatAttributeMin(unsigned long a,unsigned long dim)104         Real                             GetFloatAttributeMin(unsigned long a, unsigned long dim) const
105                                          {
106                                              assert(a < O3DGC_SC3DMC_MAX_NUM_FLOAT_ATTRIBUTES);
107                                              assert(dim < O3DGC_SC3DMC_MAX_DIM_ATTRIBUTES);
108                                              return m_minFloatAttribute[a * O3DGC_SC3DMC_MAX_DIM_ATTRIBUTES + dim];
109                                          }
GetFloatAttributeMax(unsigned long a,unsigned long dim)110         Real                             GetFloatAttributeMax(unsigned long a, unsigned long dim) const
111                                          {
112                                              assert(a < O3DGC_SC3DMC_MAX_NUM_FLOAT_ATTRIBUTES);
113                                              assert(dim < O3DGC_SC3DMC_MAX_DIM_ATTRIBUTES);
114                                              return m_maxFloatAttribute[a * O3DGC_SC3DMC_MAX_DIM_ATTRIBUTES + dim];
115                                          }
GetCreaseAngle()116         Real                             GetCreaseAngle()      const { return m_creaseAngle     ;}
GetCCW()117         bool                             GetCCW()              const { return m_ccw             ;}
GetSolid()118         bool                             GetSolid()            const { return m_solid           ;}
GetConvex()119         bool                             GetConvex()           const { return m_convex          ;}
GetIsTriangularMesh()120         bool                             GetIsTriangularMesh() const { return m_isTriangularMesh;}
GetIndexBufferID()121         const unsigned long *            GetIndexBufferID()    const { return m_indexBufferID   ;}
GetCoordIndex()122         const T *                        GetCoordIndex()       const { return m_coordIndex;}
GetCoordIndex()123         T *                              GetCoordIndex()             { return m_coordIndex;}
GetCoord()124         Real *                           GetCoord()            const { return m_coord     ;}
GetNormal()125         Real *                           GetNormal()           const { return m_normal    ;}
GetFloatAttribute(unsigned long a)126         Real *                           GetFloatAttribute(unsigned long a)  const
127                                          {
128                                              assert(a < O3DGC_SC3DMC_MAX_NUM_FLOAT_ATTRIBUTES);
129                                              return m_floatAttribute[a];
130                                          }
GetIntAttribute(unsigned long a)131         long *                           GetIntAttribute(unsigned long a)   const
132                                          {
133                                              assert(a < O3DGC_SC3DMC_MAX_NUM_INT_ATTRIBUTES);
134                                              return m_intAttribute[a]  ;
135                                          }
136         // only coordIndex is supported
SetNNormalIndex(unsigned long)137         void                             SetNNormalIndex(unsigned long)      {}
SetNTexCoordIndex(unsigned long)138         void                             SetNTexCoordIndex(unsigned long)    {}
SetNFloatAttributeIndex(int,unsigned long)139         void                             SetNFloatAttributeIndex(int, unsigned long) {}
SetNIntAttributeIndex(int,unsigned long)140         void                             SetNIntAttributeIndex (int, unsigned long) {}
141         // per triangle attributes not supported
SetNormalPerVertex(bool)142         void                             SetNormalPerVertex(bool)   {}
SetColorPerVertex(bool)143         void                             SetColorPerVertex(bool)    {}
SetFloatAttributePerVertex(int,bool)144         void                             SetFloatAttributePerVertex(int, bool){}
SetIntAttributePerVertex(int,bool)145         void                             SetIntAttributePerVertex  (int, bool){}
SetNCoordIndex(unsigned long nCoordIndex)146         void                             SetNCoordIndex     (unsigned long nCoordIndex)     { m_nCoordIndex = nCoordIndex;}
SetNCoord(unsigned long nCoord)147         void                             SetNCoord          (unsigned long nCoord)          { m_nCoord      = nCoord     ;}
SetNNormal(unsigned long nNormal)148         void                             SetNNormal         (unsigned long nNormal)         { m_nNormal     = nNormal    ;}
SetNumFloatAttributes(unsigned long numFloatAttributes)149         void                             SetNumFloatAttributes(unsigned long numFloatAttributes)
150                                          {
151                                              assert(numFloatAttributes < O3DGC_SC3DMC_MAX_NUM_FLOAT_ATTRIBUTES);
152                                              m_numFloatAttributes = numFloatAttributes;
153                                          }
SetNumIntAttributes(unsigned long numIntAttributes)154         void                             SetNumIntAttributes  (unsigned long numIntAttributes)
155                                          {
156                                              assert(numIntAttributes < O3DGC_SC3DMC_MAX_NUM_INT_ATTRIBUTES);
157                                              m_numIntAttributes = numIntAttributes;
158                                          }
SetCreaseAngle(Real creaseAngle)159         void                             SetCreaseAngle      (Real creaseAngle)      { m_creaseAngle      = creaseAngle     ;}
SetCCW(bool ccw)160         void                             SetCCW              (bool ccw)              { m_ccw              = ccw             ;}
SetSolid(bool solid)161         void                             SetSolid            (bool solid)            { m_solid            = solid           ;}
SetConvex(bool convex)162         void                             SetConvex           (bool convex)           { m_convex           = convex          ;}
SetIsTriangularMesh(bool isTriangularMesh)163         void                             SetIsTriangularMesh (bool isTriangularMesh) { m_isTriangularMesh = isTriangularMesh;}
SetCoordMin(int j,Real min)164         void                             SetCoordMin        (int j, Real min) { m_coordMin[j]    = min;}
SetCoordMax(int j,Real max)165         void                             SetCoordMax        (int j, Real max) { m_coordMax[j]    = max;}
SetNormalMin(int j,Real min)166         void                             SetNormalMin       (int j, Real min) { m_normalMin[j]   = min;}
SetNormalMax(int j,Real max)167         void                             SetNormalMax       (int j, Real max) { m_normalMax[j]   = max;}
SetNFloatAttribute(unsigned long a,unsigned long nFloatAttribute)168         void                             SetNFloatAttribute(unsigned long a, unsigned long nFloatAttribute)
169                                          {
170                                              assert(a < O3DGC_SC3DMC_MAX_NUM_FLOAT_ATTRIBUTES);
171                                              m_nFloatAttribute[a] = nFloatAttribute;
172                                          }
SetNIntAttribute(unsigned long a,unsigned long nIntAttribute)173         void                             SetNIntAttribute(unsigned long a, unsigned long nIntAttribute)
174                                          {
175                                              assert(a < O3DGC_SC3DMC_MAX_NUM_INT_ATTRIBUTES);
176                                              m_nIntAttribute[a] = nIntAttribute;
177                                          }
SetFloatAttributeDim(unsigned long a,unsigned long d)178         void                             SetFloatAttributeDim(unsigned long a, unsigned long d)
179                                          {
180                                              assert(a < O3DGC_SC3DMC_MAX_NUM_FLOAT_ATTRIBUTES);
181                                              m_dimFloatAttribute[a] = d;
182                                          }
SetIntAttributeDim(unsigned long a,unsigned long d)183         void                             SetIntAttributeDim(unsigned long a, unsigned long d)
184                                          {
185                                              assert(a < O3DGC_SC3DMC_MAX_NUM_INT_ATTRIBUTES);
186                                              m_dimIntAttribute[a] = d;
187                                          }
SetFloatAttributeType(unsigned long a,O3DGCIFSFloatAttributeType t)188         void                             SetFloatAttributeType(unsigned long a, O3DGCIFSFloatAttributeType t)
189                                          {
190                                              assert(a < O3DGC_SC3DMC_MAX_NUM_FLOAT_ATTRIBUTES);
191                                              m_typeFloatAttribute[a] = t;
192                                          }
SetIntAttributeType(unsigned long a,O3DGCIFSIntAttributeType t)193         void                             SetIntAttributeType(unsigned long a, O3DGCIFSIntAttributeType t)
194                                          {
195                                              assert(a < O3DGC_SC3DMC_MAX_NUM_INT_ATTRIBUTES);
196                                              m_typeIntAttribute[a] = t;
197                                          }
SetFloatAttributeMin(unsigned long a,unsigned long dim,Real min)198         void                             SetFloatAttributeMin(unsigned long a, unsigned long dim, Real min)
199                                          {
200                                              assert(a < O3DGC_SC3DMC_MAX_NUM_FLOAT_ATTRIBUTES);
201                                              assert(dim < O3DGC_SC3DMC_MAX_DIM_ATTRIBUTES);
202                                              m_minFloatAttribute[a * O3DGC_SC3DMC_MAX_DIM_ATTRIBUTES + dim] = min;
203                                          }
SetFloatAttributeMax(unsigned long a,unsigned long dim,Real max)204         void                             SetFloatAttributeMax(unsigned long a, unsigned long dim, Real max)
205                                          {
206                                              assert(a < O3DGC_SC3DMC_MAX_NUM_FLOAT_ATTRIBUTES);
207                                              assert(dim < O3DGC_SC3DMC_MAX_DIM_ATTRIBUTES);
208                                              m_maxFloatAttribute[a * O3DGC_SC3DMC_MAX_DIM_ATTRIBUTES + dim] = max;
209                                          }
SetIndexBufferID(unsigned long * const indexBufferID)210         void                             SetIndexBufferID  (unsigned long * const indexBufferID) { m_indexBufferID = indexBufferID;}
SetCoordIndex(T * const coordIndex)211         void                             SetCoordIndex     (T * const coordIndex)    { m_coordIndex = coordIndex;}
SetCoord(Real * const coord)212         void                             SetCoord          (Real * const coord     ) { m_coord      = coord    ;}
SetNormal(Real * const normal)213         void                             SetNormal         (Real * const normal    ) { m_normal     = normal   ;}
SetFloatAttribute(unsigned long a,Real * const floatAttribute)214         void                             SetFloatAttribute (unsigned long a, Real * const floatAttribute)
215                                          {
216                                              assert(a < O3DGC_SC3DMC_MAX_NUM_FLOAT_ATTRIBUTES);
217                                              m_floatAttribute[a] = floatAttribute;
218                                          }
SetIntAttribute(unsigned long a,long * const intAttribute)219         void                             SetIntAttribute   (unsigned long a, long * const intAttribute)
220                                          {
221                                              assert(a < O3DGC_SC3DMC_MAX_NUM_INT_ATTRIBUTES);
222                                              m_intAttribute[a] = intAttribute ;
223                                          }
224         void                             ComputeMinMax(O3DGCSC3DMCQuantizationMode quantMode);
225 
226     private:
227         // triangles list
228         unsigned long                    m_nCoordIndex;
229         T *                              m_coordIndex;
230         unsigned long *                  m_indexBufferID;
231         // coord, normals, texcoord and color
232         unsigned long                    m_nCoord;
233         unsigned long                    m_nNormal;
234         Real                             m_coordMin   [3];
235         Real                             m_coordMax   [3];
236         Real                             m_normalMin  [3];
237         Real                             m_normalMax  [3];
238         Real *                           m_coord;
239         Real *                           m_normal;
240         // other attributes
241         unsigned long                    m_numFloatAttributes;
242         unsigned long                    m_numIntAttributes;
243         O3DGCIFSFloatAttributeType       m_typeFloatAttribute [O3DGC_SC3DMC_MAX_NUM_FLOAT_ATTRIBUTES];
244         O3DGCIFSIntAttributeType         m_typeIntAttribute   [O3DGC_SC3DMC_MAX_NUM_INT_ATTRIBUTES  ];
245         unsigned long                    m_nFloatAttribute    [O3DGC_SC3DMC_MAX_NUM_FLOAT_ATTRIBUTES];
246         unsigned long                    m_nIntAttribute      [O3DGC_SC3DMC_MAX_NUM_INT_ATTRIBUTES  ];
247         unsigned long                    m_dimFloatAttribute  [O3DGC_SC3DMC_MAX_NUM_FLOAT_ATTRIBUTES];
248         unsigned long                    m_dimIntAttribute    [O3DGC_SC3DMC_MAX_NUM_INT_ATTRIBUTES  ];
249         Real                             m_minFloatAttribute  [O3DGC_SC3DMC_MAX_NUM_FLOAT_ATTRIBUTES * O3DGC_SC3DMC_MAX_DIM_ATTRIBUTES];
250         Real                             m_maxFloatAttribute  [O3DGC_SC3DMC_MAX_NUM_FLOAT_ATTRIBUTES * O3DGC_SC3DMC_MAX_DIM_ATTRIBUTES];
251         Real *                           m_floatAttribute     [O3DGC_SC3DMC_MAX_NUM_FLOAT_ATTRIBUTES];
252         long *                           m_intAttribute       [O3DGC_SC3DMC_MAX_NUM_FLOAT_ATTRIBUTES];
253         // mesh info
254         Real                             m_creaseAngle;
255         bool                             m_ccw;
256         bool                             m_solid;
257         bool                             m_convex;
258         bool                             m_isTriangularMesh;
259     };
260 }
261 #include "o3dgcIndexedFaceSet.inl"    // template implementation
262 #endif // O3DGC_INDEXED_FACE_SET_H
263 
264