00001 /* 00002 * PROPRIETARY INFORMATION. This software is proprietary to 00003 * Side Effects Software Inc., and is not to be reproduced, 00004 * transmitted, or disclosed in any way without written permission. 00005 * 00006 * Produced by: 00007 * George ElKoura 00008 * Side Effects 00009 * 477 Richmond Street West 00010 * Toronto, Ontario 00011 * Canada M5V 3E7 00012 * 416-504-9876 00013 * 00014 * NAME: GDT Library. (Geo Delta) 00015 * 00016 * COMMENTS: GDT_VertexList contains tokens for vertex attributes. 00017 * All these tokens are not sparse. 00018 * 00019 */ 00020 #ifndef __GDT_VertexList_h__ 00021 #define __GDT_VertexList_h__ 00022 00023 #include "GDT_API.h" 00024 #include "GDT_TokenList.h" 00025 00026 #include <UT/UT_IntArray.h> 00027 #include <UT/UT_ValArray.h> 00028 #include <UT/UT_PtrArray.h> 00029 #include <GEO/GEO_Detail.h> 00030 00031 class GDT_API GDT_VertexList : public GDT_TokenList 00032 { 00033 public: 00034 GDT_VertexList(); 00035 GDT_VertexList(const GDT_VertexList &other); 00036 virtual ~GDT_VertexList() {} 00037 00038 // Implement the pure virtual applyDeltas() from GDT_TokenList. 00039 virtual void applyDeltas(GEO_Detail &gdp, bool inverse=false) const; 00040 00041 // Merge vertex deltas from another GDT_VertexList 00042 void mergeVertexDeltas(const GDT_VertexList &other, 00043 bool inverse = false); 00044 00045 // Apply a scaled delta... 00046 void applyScaledDelta(GEO_Detail &gdp, GEO_Primitive &prim, 00047 int vtxidx, float scale) const; 00048 00049 // Overload hiding base class method which requires a GA_AIFEditDeltaMap. 00050 void endAttributeChange(const GEO_Detail &gdp); 00051 00052 // Compute the vertex offsets array. 00053 // This array must always be in sync with the gdp, 00054 // otherwise endVertexAttributeChange calls will fail. 00055 void updateVertexOffsets(const GEO_Detail &gdp); 00056 00057 // Methods used to iterate through the vertices 00058 virtual unsigned int getElementCount(const GEO_Detail &gdp) const; 00059 00060 virtual const GA_AttributeDict &getAttributeDict( 00061 const GEO_Detail &gdp) const 00062 { return gdp.vertexAttribs(); } 00063 00064 bool saveOffsets(UT_JSONWriter &w) const; 00065 bool loadOffsets(UT_JSONParser &p); 00066 00067 virtual bool legacyLoadAttribs(UT_IStream &is, uint size); 00068 00069 // Destroy the vertex deltas 00070 virtual void destroy(); 00071 00072 // Given an index and an array of offsets, this method computes the 00073 // primitive number and vertex index of the corresponding element. 00074 // start and end delimit the entries to search in the offsets array 00075 // Returns true if succesful, false otherwise 00076 static bool calculatePrimVertex(unsigned int idx, 00077 const UT_ValArray<GA_Index> &offsets, 00078 unsigned int &primidx, 00079 unsigned int &vertexidx, 00080 int start=0, 00081 int end=-1); 00082 00083 protected: 00084 // Builds the offset array for a particular gdp. See below for comments 00085 // on how the offset array is used. 00086 void buildOffsetArray(const GEO_Detail &gdp, 00087 UT_ValArray<GA_Index> &array); 00088 00089 private: 00090 00091 // myOffsets is used as a way to flatten the vertex indices. A cell at 00092 // index i of myOffsets contains the total number of vertices up to, 00093 // but not including the primitive i. For example, myOffsets[0] is always 00094 // 0. If primitive 0 had 4 vertices and primitive 1 had 2 then myOffsets[1] 00095 // would be 4 and myOffsets[2] would be 6, and so on. That way it is 00096 // very efficient to index a vertex based on a vertex number and primitive 00097 // number, it's index would be myOffsets[primnum] + vertexnum. 00098 // By its nature the offsets array is sorted, so to compute the inverse, 00099 // that is to find the primitive and vertex index given and index into 00100 // the vertex array, you just have to do a binary search. The last 00101 // entry in the array contains the total number of vertices in the gdp. 00102 // 00103 // Note that this array should be treated as though it were part of the 00104 // delta. Since we don't keep around a gdp, this array might not coincide 00105 // with the gdp that we have to apply the delta to. This should be treated 00106 // the same way we treat topology changes in the other lists. 00107 UT_ValArray<GA_Index> myOffsets; 00108 00109 // This is a temporary offset array (like the one above) used to cache this 00110 // information for another gdp. (This makes taking a snapshot of the 00111 // whole gdp faster). But we do risk it not being in sync with the gdp. 00112 // 00113 // This array is used for the "other" gdp when we are taking a snapshot, 00114 // in case the two gdp's have the same point and primitive count but 00115 // a different vertex distribution. 00116 UT_ValArray<GA_Index> myTempOffsets; 00117 00118 // Cache the last primitive and last vertex indices we used for fast 00119 // iterations. 00120 mutable unsigned int myNextPrim; 00121 mutable unsigned int myNextVertex; 00122 }; 00123 #endif
1.5.9