Index.h 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. /******************************************************************************/
  2. #if EE_PRIVATE
  3. struct IndexGroup
  4. {
  5. Int num; Int *elm;
  6. void changeVal(Int from, Int to);
  7. void remVal(Int value);
  8. void subVal(Int value);
  9. void subElm(Int i);
  10. void inc(Int num=1) {T.num+=num;}
  11. void add(Int elm ) {T.elm[num++]=elm;}
  12. Int& operator[](Int i) {return elm[i];}
  13. Int operator[](Int i)C {return elm[i];}
  14. };
  15. /******************************************************************************/
  16. struct IndexPtrGroup
  17. {
  18. Int num; Ptr *elm;
  19. void changeVal(Ptr from, Ptr to);
  20. void remVal(Ptr value);
  21. void subVal(Ptr value);
  22. void subElm(Int i);
  23. void inc(Int num=1) {T.num+=num;}
  24. void add(Ptr elm ) {T.elm[num++]=elm;}
  25. Ptr& operator[](Int i) {return elm[i];}
  26. Ptr operator[](Int i)C {return elm[i];}
  27. };
  28. /******************************************************************************/
  29. struct Index
  30. {
  31. Int groups, elms, group_elms_max, elms_max, *elm_group;
  32. Int *groups_elm;
  33. IndexGroup *group;
  34. Index& del ();
  35. Index& create(Int groups, Int elms_max=0);
  36. Index& reset ();
  37. Index& set (Int *elm_group=null);
  38. void incGroup(Int group, Int num=1) {T.group[group].inc(num);}
  39. void addElm (Int group, Int elm ) {T.group[group].add(elm);}
  40. void elmGroup(Int group, Int elm ) {T.group[elm_group[elm]=group].num++;}
  41. ~Index( ) {del ( );}
  42. Index( ) {Zero(T);}
  43. explicit Index(Int groups, Int elms_max=0) {Zero(T); create(groups, elms_max);}
  44. NO_COPY_CONSTRUCTOR(Index);
  45. };
  46. /******************************************************************************/
  47. struct IndexPtr
  48. {
  49. Int groups, elms, group_elms_max;
  50. Ptr *groups_elm;
  51. IndexPtrGroup *group;
  52. IndexPtr& del ();
  53. IndexPtr& create(Int groups);
  54. IndexPtr& reset ();
  55. IndexPtr& set ();
  56. void incGroup(Int group, Int num=1) {T.group[group].inc(num);}
  57. void addElm (Int group, Ptr elm ) {T.group[group].add(elm);}
  58. ~IndexPtr( ) {del ( );}
  59. IndexPtr( ) {Zero(T);}
  60. explicit IndexPtr(Int groups) {Zero(T); create(groups);}
  61. NO_COPY_CONSTRUCTOR(IndexPtr);
  62. };
  63. /******************************************************************************/
  64. void CreateIs ( MemPtr<Bool> is, C MemPtr<Int> &selection, Int elms);
  65. void CreateIsNot ( MemPtr<Bool> is, C MemPtr<Int> &selection, Int elms);
  66. void CreateFaceIs ( MemPtr<Bool> tri_is, MemPtr<Bool> quad_is, C MemPtr<Int> &faces, Int tris, Int quads);
  67. void CreateFaceIsNot( MemPtr<Bool> tri_is, MemPtr<Bool> quad_is, C MemPtr<Int> &faces, Int tris, Int quads);
  68. /******************************************************************************/
  69. void SetFaceIndex(Ptr data, C VecI *tri, Int tris, C VecI4 *quad, Int quads, Bool bit16);
  70. /******************************************************************************/
  71. #if EE_PRIVATE
  72. void SetRemap( MemPtr<Int> remap, C MemPtr<Bool> &is, Int elms);
  73. void IndRemap(C MemPtr<Int> &remap, Int *ind, Int elms);
  74. inline void IndRemap(C MemPtr<Int> &remap, VecI2 *ind, Int elms) {IndRemap(remap, (Int*)ind, elms*2);}
  75. inline void IndRemap(C MemPtr<Int> &remap, VecI *ind, Int elms) {IndRemap(remap, (Int*)ind, elms*3);}
  76. inline void IndRemap(C MemPtr<Int> &remap, VecI4 *ind, Int elms) {IndRemap(remap, (Int*)ind, elms*4);}
  77. Bool IndSave(File &f, CPtr ind, Int inds, Int elms=-1);
  78. Bool IndLoad(File &f, Ptr ind, Int inds);
  79. #endif
  80. /******************************************************************************/
  81. inline Int Elms(C IndexGroup &index) {return index.num;}
  82. inline Int Elms(C IndexPtrGroup &index) {return index.num;}
  83. /******************************************************************************/
  84. #endif
  85. Bool ElmIs(C MemPtr<Bool> &is, Int i); // if i-th element is in range and set to true
  86. Int CountIs(C MemPtr<Bool> &is ); // return the number of elements in the 'is' array which are true
  87. /******************************************************************************/