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 * Mark Elendt 00008 * Side Effects Software Inc. 00009 * 20 Maud St. 00010 * Toronto, Ontario, M5V 2M5 00011 * Canada 00012 * 416-366-4607 00013 * 00014 * NAME: Geometry Library (C++) 00015 * 00016 * COMMENTS: 00017 * This contains the class definition for attributes. 00018 * The size passed in is the size in bytes of the attribute. 00019 * STRING types are stored as a fixed length array, not as pointers 00020 * to strings. However, the string must still be null terminated. 00021 * 00022 * 00023 * COMMON ATTRIBUTE NAMES: 00024 * (see also GEO_Standard_Attributes in GEO_Detail) 00025 * N vector Normals (point or primitive) 00026 * Dclr 3*float Display color (for wireframe) 00027 * Ca 3*float Ambient color 00028 * Cd 3*float Diffuse color 00029 * Cs 3*float Specular color 00030 * Ct 3*float Transmit color 00031 * Ce 3*float Emittence color 00032 * Ct 1*float Transparency 00033 * Mat 32*char Material reference (name of material) 00034 * UV 2*float Texture coordinates (tuple) 00035 * UVW 3*float Texture coordinates (triple) 00036 * Dopt GB_DrawOpt Type of feedback, eg w/ or w/o hull, CVs, wire 00037 * Lod 1*float Level of detail 00038 * v vector Velocity of point/primitive 00039 * Rest 3*float Rest position for a point: X Y Z 00040 * 00041 */ 00042 00043 #ifndef __GB_Attribute_h__ 00044 #define __GB_Attribute_h__ 00045 00046 #include "GB_API.h" 00047 #include <UT/UT_LinkList.h> 00048 #include <UT/UT_PtrArray.h> 00049 00050 #include "GB_AttributeDefines.h" 00051 #include "GB_AttributeDict.h" 00052 #include "GB_AttributeElem.h" 00053 #include "GB_AttributeTable.h" 00054 00055 class UT_IStream; 00056 class UT_StringArray; 00057 00058 /// Definition of a geometry attribute 00059 class GB_API GB_Attribute : public UT_LinkNode 00060 { 00061 public: 00062 GB_Attribute(const char *n, int s, GB_AttribType t, const void *def); 00063 GB_Attribute(const char *n, int s, GB_AttribType t, GB_AttribTypeInfo f, 00064 const void *def); 00065 ~GB_Attribute(); 00066 00067 void initialize(const char *n, int s, GB_AttribType t, GB_AttribTypeInfo f, 00068 const void *def); 00069 void setDefault( const void *def ); 00070 00071 /// Return the name of the attribute 00072 const char *getName() const { return myName; } 00073 00074 /// @{ 00075 /// Return the size (in @b bytes) of the attribute 00076 /// @warning The size of the attribute is the size in @b bytes that the 00077 /// attribute data requires. 00078 /// @note Due to memory alignment issues on some processors, the allocated 00079 /// size may be larger than the size required. Please be aware of this. 00080 int getSize() const { return mySize; } 00081 int getAllocSize() const 00082 { return alignSizeWithWord(mySize); } 00083 /// @} 00084 00085 /// Return the type of the attribute 00086 GB_AttribType getType() const { return myType; } 00087 /// Return the extended type information for the attribute 00088 GB_AttribTypeInfo getTypeInfo() const { return myTypeInfo; } 00089 /// Return a pointer to the default data (may be NULL) 00090 const void *getDefault() const { return myDefValue; } 00091 00092 /// Change the name of the attribute 00093 /// @warning This does @b not check for duplicate names 00094 void rename(const char *newname); 00095 00096 /// Set the type of the attribute. 00097 void setType(GB_AttribType t) { myType = t; } 00098 /// Set extended type information 00099 void setTypeInfo(GB_AttribTypeInfo t) { myTypeInfo = t; } 00100 00101 /// @{ 00102 /// Save/load string index table values 00103 int saveIndexValues(ostream &os, int binary) const; 00104 bool loadIndexValues(UT_IStream &is); 00105 /// @} 00106 00107 /// Add or return an existing index of a string. 00108 /// @see GB_AttribType 00109 int addIndex(const char *label); 00110 00111 /// Similar to addIndex(), this method adds a string to the shared string 00112 /// table, returning the index of the string. You should only set the 00113 /// @c check_dups flag to @c false if you are positive the label doesn't 00114 /// already exist in the string table (or will be calling 00115 /// removeRedundantIndex() after the fact. 00116 int addString(const char *label, bool check_dups=true); 00117 00118 /// @{ 00119 /// Add multiple strings to the string table. You should only set the @c 00120 /// check_dups flag to @c false if you are positive that there are no 00121 /// duplicates in the string list @b and there are no duplicate entries in 00122 /// the list itself. If an integer array is passed in, the indices 00123 /// associated with each string will be set. 00124 /// The method returns the number of strings added. 00125 size_t addStrings(const UT_StringArray &strings, 00126 bool check_duplicates=true, 00127 int *string_ids=NULL); 00128 size_t addStrings(const UT_StringList &strings, 00129 bool check_duplicates=true, 00130 int *string_ids=NULL); 00131 /// @} 00132 00133 /// Renames a string from one value to another. 00134 void renameIndex(int idx, const char *label); 00135 /// Removes a string from the index table. This may adjust the index 00136 /// values of other strings. The attribute values will @b not be adjusted 00137 /// automatically. 00138 int destroyIndex(const char *label) 00139 { 00140 return destroyIndex(getIndex(label)); 00141 } 00142 /// Removes the string with the given index. This may adjust the index 00143 /// values of other strings. The attribute values will @b not be adjusted 00144 /// automatically. 00145 int destroyIndex(int index); 00146 /// Remove @b all strings from the index table. Attribute values will @b 00147 /// not be adjusted automatically. 00148 void clearIndex(void); 00149 /// Remove duplicate entries in the index table 00150 void removeRedundantIndex(void); 00151 /// Return the number of strings in the index table 00152 int getIndexSize(void) const { return myIndexSize; } 00153 00154 /// Find the index of a given string. Returns -1 if no string is found 00155 int getIndex(const char *label) const; 00156 /// Return the string at the given index. This function may return NULL. 00157 const char *getIndex(int idx) const 00158 { 00159 return (idx < myIndexSize && idx >= 0) ? 00160 myIndexArray[idx] : 0; 00161 } 00162 00163 /// @private Merging index attributes is available for the merge() operation 00164 int mergeIndex(const GB_Attribute *atr); 00165 00166 /// @private Merging index attributes is available for the merge() operation 00167 /// The following method simply appends the source's string table to ours. 00168 int mergeIndexByAppending(const GB_Attribute *atr); 00169 00170 /// @private Used to perform byte alignment of buffers 00171 static inline int alignSizeWithWord(int size) 00172 { 00173 if ((size & (GB_ATTRIB_ALIGN_SIZE-1)) != 0) 00174 size += GB_ATTRIB_ALIGN_SIZE - 00175 (size & (GB_ATTRIB_ALIGN_SIZE-1)); 00176 return size; 00177 } 00178 00179 protected: 00180 friend class GB_AttributeDict; 00181 00182 private: 00183 void grow(unsigned int addedsize); 00184 void shrink( unsigned int removedsize ); 00185 void growIndexArray(size_t by_how_much=1); 00186 00187 char *myName; 00188 int mySize; 00189 GB_AttribType myType; 00190 GB_AttribTypeInfo myTypeInfo; 00191 void *myDefValue; // Default value for attribute 00192 char **myIndexArray; 00193 int myIndexSize; 00194 }; 00195 00196 #endif
1.5.9