HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
GA_KnotVector.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 Library (C++)
7  *
8  */
9 
10 #ifndef __GA_KnotVector_h__
11 #define __GA_KnotVector_h__
12 
13 #include "GA_API.h"
14 
15 #include "GA_Types.h"
16 
17 #include <UT/UT_Array.h>
18 #include <UT/UT_ValArray.h>
19 
20 #include <SYS/SYS_Types.h>
21 
22 
23 class UT_JSONWriter;
24 class UT_JSONParser;
26 
27 
28 typedef fpreal64 GA_KnotFloat;
29 
30 template <typename T>
31 class GA_KnotVectorT : public UT_ValArray<T>
32 {
33 public:
34  using value_type = T;
35 
37  : UT_ValArray<T>(a)
38  {}
39  GA_KnotVectorT(unsigned int sz, unsigned int count)
40  : UT_ValArray<T>(sz, count)
41  {}
42  explicit GA_KnotVectorT(unsigned int sz = 0)
43  : UT_ValArray<T>(sz)
44  {}
46 
48  {
50  return *this;
51  }
52 
53  /// Save data to a JSON stream.
54  /// @section JSON-GA_KnotVector JSON Schema: GA_KnotVector
55  /// @code
56  /// {
57  /// "name" : "GA_KnotVector",
58  /// "description" : "An knot vector array.",
59  /// "type" : "array",
60  /// "items" : "number",
61  /// }
62  /// @endcode
63  /// @see @ref JSON_FileFormat
64  bool jsonSave(UT_JSONWriter &w) const;
65 
66  /// Save to a JSON value
67  bool jsonSave(UT_JSONValue &w) const;
68 
69  /// Load from a JSON stream
70  bool jsonLoad(UT_JSONParser &p);
71 
72  /// Load from a JSON value
73  bool jsonLoad(UT_JSONParser &p, const UT_JSONValue &v);
74 
75 
76  void copyMemory(const GA_KnotVectorT &from)
77  {
78  *this = from;
79  }
80 
81  // Move howMany objects starting at index srcIndex to destIndex;
82  // Method returns 0 if OK, -1 if overflow.
83  int shift(GA_Size srcIdx, GA_Size destIdx, GA_Size howMany);
84 
85  const T &getValue(GA_Size index) const
86  {
87  return UT_Array<T>::operator()(index);
88  }
90  {
91  if (index >= UT_Array<T>::entries())
92  UT_Array<T>::entries(index + 1);
93  UT_Array<T>::operator()(index) = v;
94  }
95  void reserve(int size)
97 
99  { return insert(idx); }
101  { return insert(t, i); }
102 
103 private:
104  /// @{
105  /// The order of arguments for insert() is different for GA_Basis and for
106  /// UT_ValArray. Thus, we make the insert methods private and ask people
107  /// to use "insertKnot" instead.
108  unsigned int insert(unsigned index)
109  { return UT_ValArray<T>::insert(index); }
110  unsigned int insert(const T &t, unsigned int i)
111  { return UT_ValArray<T>::insert(t, i); }
112  /// @}
113 
114 };
115 
117 
118 #endif
GA_Size insertKnot(fpreal t, GA_Size i)
void copyMemory(const GA_KnotVectorT &from)
Definition: GA_KnotVector.h:76
const GLdouble * v
Definition: glcorearb.h:837
GLboolean GLboolean GLboolean GLboolean a
Definition: glcorearb.h:1222
JSON reader class which handles parsing of JSON or bJSON files.
Definition: UT_JSONParser.h:87
Class which writes ASCII or binary JSON streams.
Definition: UT_JSONWriter.h:37
GA_KnotVectorT(unsigned int sz=0)
Definition: GA_KnotVector.h:42
bool jsonLoad(UT_JSONParser &p)
Load from a JSON stream.
exint GA_Size
Defines the bit width for index and offset types in GA.
Definition: GA_Types.h:236
double fpreal64
Definition: SYS_Types.h:201
GA_Size insertKnot(GA_Size idx)
Definition: GA_KnotVector.h:98
UT_ValArray & operator=(const UT_ValArray< T > &src)
Definition: UT_ValArray.h:86
const T & getValue(GA_Size index) const
Definition: GA_KnotVector.h:85
GA_KnotVectorT(unsigned int sz, unsigned int count)
Definition: GA_KnotVector.h:39
int shift(GA_Size srcIdx, GA_Size destIdx, GA_Size howMany)
GA_KnotVectorT(const GA_KnotVectorT &a)
Definition: GA_KnotVector.h:36
void setCapacityIfNeeded(exint min_capacity)
Definition: UT_Array.h:603
bool jsonSave(UT_JSONWriter &w) const
GLdouble t
Definition: glad.h:2397
void reserve(int size)
Definition: GA_KnotVector.h:95
exint entries() const
Alias of size(). size() is preferred.
Definition: UT_Array.h:648
GLsizeiptr size
Definition: glcorearb.h:664
GA_KnotFloat value_type
Definition: UT_Array.h:93
void setValue(GA_Size index, fpreal v)
Definition: GA_KnotVector.h:89
fpreal64 fpreal
Definition: SYS_Types.h:277
GLuint index
Definition: glcorearb.h:786
GA_KnotVectorT & operator=(const GA_KnotVectorT &rhs)
Definition: GA_KnotVector.h:47
Class to store JSON objects as C++ objects.
Definition: UT_JSONValue.h:99
GLubyte GLubyte GLubyte GLubyte w
Definition: glcorearb.h:857
T & operator()(exint i)
Definition: UT_Array.h:767
fpreal64 GA_KnotFloat
Definition: GA_KnotVector.h:25
exint insert(exint index)
Definition: UT_ArrayImpl.h:721
GLint GLsizei count
Definition: glcorearb.h:405