HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
GA_OffsetMatrix.h
Go to the documentation of this file.
1 /*
2  * PROPRIETARY INFORMATION. This software is proprietary to
3  * Side Effects Software Inc., and is not to be reproduced,
4  * transmitted, or disclosed in any way without written permission.
5  *
6  * NAME: GA_OffsetMatrix.h ( GA Library, C++)
7  *
8  * COMMENTS: Class to store a matrix of offsets/indices based on the
9  * GA_Offset/GA_Index types.
10  */
11 
12 #ifndef __GA_OffsetMatrix__
13 #define __GA_OffsetMatrix__
14 
15 #include "GA_API.h"
16 #include "GA_OffsetList.h"
17 #include "GA_Types.h"
18 
19 #include <SYS/SYS_Types.h>
20 
21 
22 class GA_Defragment;
23 class GA_LoadMap;
24 class GA_SaveMap;
25 
26 class UT_JSONParser;
27 class UT_JSONWriter;
28 class UT_MemoryCounter;
29 
30 /// GA_OffsetMatrix implements an array of GA_Offsets.
31 /// Copy-on-write is used to reduce memory usage and make the copying of a
32 /// GA_OffsetMatrix an inexpensive operation.
33 ///
34 /// See also: @ref JSON-GA_OffsetMatrix, GA_OffsetList
36 {
37 public:
38  explicit GA_OffsetMatrix() : myRows(0), myCols(0) {}
39  ~GA_OffsetMatrix() { clear(); }
40 
41  /// Report memory usage
42  int64 getMemoryUsage(bool inclusive) const
43  { return (inclusive ? sizeof(*this) : 0) + myList.getMemoryUsage(false); }
44 
45  /// Count memory usage using a UT_MemoryCounter in order to count
46  /// shared memory correctly.
47  /// If inclusive is true, the size of this object is counted,
48  /// else only memory owned by this object is counted.
49  /// If this is pointed to by the calling object, inclusive should be true.
50  /// If this is contained in the calling object, inclusive should be false.
51  /// (Its memory was already counted in the size of the calling object.)
52  void countMemory(UT_MemoryCounter &counter, bool inclusive) const;
53 
54  /// clear removes all of the entries
55  void clear()
56  {
57  myList.clear();
58  myRows = 0;
59  myCols = 0;
60  }
61 
62  /// Returns the used rows of the matrix (always <= to getRowCapacity())
63  GA_Size rows() const { return myRows; }
64  GA_Size getRows() const { return myRows; }
65  /// Returns the used columns of the matrix (always <= to getRowCapacity())
66  GA_Size cols() const { return myCols; }
67  GA_Size getCols() const { return myCols; }
68 
69  /// Reserve capacity for a number of rows/columns. The capacity may not be
70  /// decreased.
71  void reserve(GA_Size rows, GA_Size cols)
72  { myList.reserve(rows*cols); }
73 
74  /// Set the array size
75  void setEntries(GA_Size rows, GA_Size cols);
76 
77  /// Add a single entry (may grow array)
78  GA_Size appendRow() { return insertRow(myRows); }
79  /// Add a single entry (may grow array)
80  GA_Size insertRow(GA_Size index);
81  /// Remove the entry at the given offset
82  GA_Size removeRow(GA_Size i);
83 
84  /// Add a single entry (may grow array)
85  GA_Size appendCol() { return insertCol(myCols); }
86  /// Add a single entry (may grow array)
87  GA_Size insertCol(GA_Size index);
88  /// Remove the entry at the given offset
89  GA_Size removeCol(GA_Size i);
90 
91 
92  /// Set the index to the value
94  { myList.set(row*myCols+col, value); }
95  /// The the value at the index
96  GA_Offset get(GA_Size row, GA_Size col) const
97  { return myList.get(row*myCols+col); }
98 
99  /// Convenience () operator to access the list entries
101  { return get(row, col); }
102 
103  /// Cyclically shift the rows and/or columns
104  void cycle(GA_Size rowshift, GA_Size colshift);
105 
106  /// Returns the first linear index in the matrix whose value
107  /// is equal to value, or -1 if not present
109  { return myList.find(value); }
110 
111  /// @{
112  /// Swap offset values for defragmentation process. When defragmenting,
113  /// offsets will move. This method will update all references to offsets
114  /// to their new values. This returns the number of values updated.
116  { return myList.swapOffsetValues(defrag); }
117  /// @}
118 
119  /// @section JSON-GA_OffsetMatrix JSON Schema: GA_OffsetMatrix
120  /// @code
121  /// {
122  /// "name" : "GA_OffsetMatrix",
123  /// "description" :
124  /// "A 2D matrix of offsets/indicies.
125  /// Each item in the array represents a row of the matrix."
126  /// "type" : "array",
127  /// "items" : { "$ref" : "GA_OffsetList" }
128  /// }
129  /// @endcode
130  /// @see @ref JSON_FileFormat
131 
132  /// Save the offsets by doing the mapping to the points in the save map
133  bool jsonPointMatrix(UT_JSONWriter &w, const GA_SaveMap &save) const;
134  /// Save the offsets by doing the mapping to the vertices in the save map
135  bool jsonVertexMatrix(UT_JSONWriter &w, const GA_SaveMap &save) const;
136  /// Save the offsets by doing the mapping to the primitives in the save map
137  bool jsonPrimitiveMatrix(UT_JSONWriter &w, const GA_SaveMap &save) const;
138 
139  /// Load a point list from a JSON stream
140  bool jsonPointMatrix(UT_JSONParser &p, const GA_LoadMap &load);
141  /// Load a vertex list from a JSON stream
142  bool jsonVertexMatrix(UT_JSONParser &p, const GA_LoadMap &load);
143  /// Load a primitive list from a JSON stream
144  bool jsonPrimitiveMatrix(UT_JSONParser &p, const GA_LoadMap &load);
145 
146  /// Generic load given a load offset
147  bool jsonLoad(UT_JSONParser &p, GA_Offset load_offset);
148 
149 private:
150  GA_OffsetList myList;
151  GA_Size myRows;
152  GA_Size myCols;
153 };
154 
155 #endif
156 
GA_Size appendCol()
Add a single entry (may grow array)
Used to pass options and map offset values during saving.
Definition: GA_SaveMap.h:48
GA_Size getRows() const
GA_Size appendRow()
Add a single entry (may grow array)
JSON reader class which handles parsing of JSON or bJSON files.
Definition: UT_JSONParser.h:75
#define GA_API
Definition: GA_API.h:12
Class which writes ASCII or binary JSON streams.
Definition: UT_JSONWriter.h:32
void clear()
clear removes all of the entries
png_uint_32 i
Definition: png.h:2877
exint GA_Size
Defines the bit width for index and offset types in GA.
Definition: GA_Types.h:211
GA_Size GA_Offset
Definition: GA_Types.h:617
long long int64
Definition: SYS_Types.h:107
GA_Size cols() const
Returns the used columns of the matrix (always <= to getRowCapacity())
void reserve(GA_Size rows, GA_Size cols)
GA_Offset operator()(GA_Size row, GA_Size col) const
Convenience () operator to access the list entries.
GA_Size swapOffsetValues(const GA_Defragment &defrag)
Options during loading.
Definition: GA_LoadMap.h:42
Defragmentation of IndexMaps.
Definition: GA_Defragment.h:45
png_bytepp row
Definition: png.h:1836
void set(GA_Size row, GA_Size col, GA_Offset value)
Set the index to the value.
int64 getMemoryUsage(bool inclusive) const
Report memory usage.
GLsizei const GLfloat * value
Definition: glcorearb.h:823
GA_Size find(GA_Offset value) const
GLuint index
Definition: glcorearb.h:785
GA_Size rows() const
Returns the used rows of the matrix (always <= to getRowCapacity())
GLubyte GLubyte GLubyte GLubyte w
Definition: glcorearb.h:856
GA_Size getCols() const