Alphabetical Class Index  Class Hierarchy   File Members   Compound Members   File List  

HUtilitySparseShell.h
00001 // Copyright (c) 1998-2014 by Tech Soft 3D, Inc.
00002 //
00003 // The information contained herein is confidential and proprietary to Tech Soft 3D, Inc.,
00004 // and considered a trade secret as defined under civil and criminal statutes.
00005 // Tech Soft 3D, Inc. shall pursue its civil and criminal remedies in the event of
00006 // unauthorized use or misappropriation of its trade secrets.  Use of this information
00007 // by anyone other than authorized employees of Tech Soft 3D, Inc. is granted only under
00008 // a written non-disclosure agreement, expressly prescribing the scope and manner of such use.
00009 
00010 #ifndef _HUTILITYSPARSE_SHELL_H
00011 #define _HUTILITYSPARSE_SHELL_H
00012 
00013 #ifdef H_PACK_8
00014 #pragma pack(push)
00015 #pragma pack(8)
00016 #endif
00017 
00018 #include "HTools.h"
00019 
00020 #define VI_BITS         (16) //number of bits per section of vertex indices
00021 #define VI_MASK         ((1<<VI_BITS)-1)
00022 #define MAX_SI_INDEX    ((0x1 << (31-VI_BITS))-1)
00023 
00024 
00025 typedef struct {
00026     HC_KEY key;
00027     MVO_POINTER_SIZED_INT offset; //pointer-sized to maintain alignment
00028 } ShellInfo;
00029 
00030 
00031 typedef struct {
00032     HC_KEY key;
00033     int *bigIndices;
00034 } PairToIndex;
00035 
00036 
00037 #define UNUSED_INDEX_TO_PAIR 0xffffffff
00038 /* interpretation of IndexToPair (stored as unsigned int) values:
00039     if (HIGHBIT)
00040         if (0xffffffff)
00041             unused entry
00042         else
00043             use the remaining 31 bits as an index into m_SharedVertices
00044     else
00045         use the remaining upper 31-VI_INDEX bits as in index into the m_ShellLookup
00046         add the ShellInfo.offset to the lower VI_INDEX bits to form the shell's vertex index
00047         grab the shell's key out of the ShellInfo
00048 */
00049 
00050 
00051 typedef struct {
00052     //first int is the count, subsequent ints are interpreted as IndexToPair
00053     unsigned int *IndexToPair;
00054 } SharedVertex;
00055 
00056 /* STORAGE REQUIREMENTS:
00057     IndexToPair: 
00058     1 int per unshared vertex
00059     1 ptr + (2+N) ints for a vertex shared N times
00060     1 ptr + 1 int per shell
00061 
00062     PairToIndex
00063     1 ptr per shell
00064     1 int per shell vertex
00065 
00066    RESTRICTIONS:
00067     there can be no more than 2^15 ShellInfo structures.  Thus there can be 
00068     no more than 32k shells.  For these purposes, a shell with more than 2^VI_BITS 
00069     vertices counts as point_count >> VI_BITS.
00070 */
00071 
00072 
00073 class MVO_API HUtilitySparseShell
00074 {
00075   private:
00076     void ExpandSharedVertices();
00077     void ExpandShellLookup(int count);
00078     void ExpandPairToIndices();
00079 
00080     HPoint const *m_OldPoints; //needed for AddOneTrnslation
00081     HPoint * m_NewPoints;       //temporary scratch space
00082 
00083   protected:
00084     bool m_p2i;
00085     bool m_i2p;
00086     
00087     unsigned int *m_IndexToPairs;
00088     int m_IndexToPairsAllocated;
00089     int m_IndexToPairsUsed;
00090 
00091     SharedVertex *m_SharedVertices;
00092     int m_SharedVerticesAllocated;
00093     int m_SharedVerticesUsed;
00094 
00095     ShellInfo *m_ShellLookup;
00096     int m_ShellLookupAllocated;
00097     int m_ShellLookupUsed;
00098 
00099     PairToIndex *m_PairToIndex;
00100     int m_PairToIndexAllocated;
00101     int m_PairToIndexUsed;
00102 
00103     void AddOneIndexToPair (int bigIndex, int littleIndex);
00104     void RemoveOneTranslation (HC_KEY key, int littleIndex);
00105     void RemoveTranslations (HC_KEY key, int face_list_length, const int face_list[]);
00106 
00107     static void AddOneTranslation (void *arg1, void *arg2, void *arg3); 
00108   public: 
00109     HUtilitySparseShell (bool needPairToIndex, bool needIndexToPair);
00110     virtual ~HUtilitySparseShell ();
00111 
00121     HC_KEY KInsertShell (int point_count, const HPoint points[], int face_list_length, const int face_list[]);
00122 
00127     void DeleteByKey (HC_KEY key);
00128 
00129     void EditShellPoints (HC_KEY key, int littleIndexOffset, int ndelete, int insert, const HPoint points[]);
00130 
00133     void EditShellFaces (HC_KEY key, int ioffset, int ndelete, int insert_list_length, const int insert_list[]) {
00134         HC_Edit_Shell_Faces (key, ioffset, ndelete, insert_list_length, insert_list);
00135     }
00136 
00138     int GetPairCount (int bigIndex) const;
00145     bool GetPair (int bigIndex, int n, HC_KEY *key, int *littleIndex) const;
00151     bool GetPairs (int bigIndex, HC_KEY keys[], int littleIndices[]) const;
00153     bool GetIndex (HC_KEY key, int littleIndex, int *bigIndex) const;
00154 };
00155 
00156 
00157 #ifdef H_PACK_8
00158 #pragma pack(pop)
00159 #endif
00160 
00161 #endif
00162 
00163 
00164 
00165 
00166