HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
GT_DAClampedArray.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: GT_DAClampedArray.h ( GT Library, C++)
7  *
8  * COMMENTS:
9  */
10 #ifndef __GT_DAClampedArray__
11 #define __GT_DAClampedArray__
12 
13 #include "GT_API.h"
14 #include "GT_DAInherit.h"
15 
16 #include <UT/UT_StringArray.h>
17 #include <UT/UT_ValArray.h>
18 
19 /// @brief A value-clamped version of another array, useful for data ranges.
21 {
22 public:
24  : myMin(-SYS_FP64_MAX),
25  myMax(SYS_FP64_MAX)
26  {}
28  fpreal64 min_v, fpreal64 max_v)
29  : GT_DAInherit(data),
30  myMin(min_v),
31  myMax(max_v)
32  {}
34  : GT_DAInherit(src),
35  myMin(src.myMin),
36  myMax(src.myMax)
37  {}
38  ~GT_DAClampedArray() override;
39 
40  const char *className() const override { return "GT_DAClampedArray"; }
41  GT_Size entries() const override { return myData->entries(); }
42 #define CLAMP(EXPR, TYPE) SYSclamp((EXPR), (TYPE)myMin, (TYPE)myMax)
43  fpreal16 getF16(GT_Offset offset, int idx=0) const override
44  { return CLAMP(myData->getF16(offset, idx), fpreal16); }
45  fpreal32 getF32(GT_Offset offset, int idx=0) const override
46  { return CLAMP(myData->getF32(offset, idx), fpreal32); }
47  fpreal64 getF64(GT_Offset offset, int idx=0) const override
48  { return CLAMP(myData->getF64(offset, idx), fpreal64); }
49  uint8 getU8(GT_Offset offset, int idx=0) const override
50  { return CLAMP(myData->getU8(offset, idx), uint8); }
51  int32 getI32(GT_Offset offset, int idx=0) const override
52  { return CLAMP(myData->getI32(offset, idx), int32); }
53  int64 getI64(GT_Offset offset, int idx=0) const override
54  { return CLAMP(myData->getI64(offset, idx), int64); }
55  GT_String getS(GT_Offset offset, int idx=0) const override
56  { return myData->getS(offset, idx); }
57  GT_Size getStringIndexCount() const override
58  { return myData->getStringIndexCount(); }
59  GT_Offset getStringIndex(GT_Offset offset, int idx) const override
60  { return myData->getStringIndex(offset, idx); }
62  UT_IntArray &indices) const override
63  { myData->getIndexedStrings(strings, indices); }
64  bool getSA(UT_StringArray &a, GT_Offset offset) const override
65  { return myData->getSA(a, offset); }
66  GT_Size getDictIndexCount() const override
67  { return myData->getDictIndexCount(); }
68  GT_Offset getDictIndex(GT_Offset offset, int idx) const override
69  { return myData->getDictIndex(offset, idx); }
71  UT_IntArray &indices) const override
72  { myData->getIndexedDicts(dicts, indices); }
73 #undef CLAMP
74 #define CLAMP_VALUES(TYPE) \
75  for(exint i=0; i<sz; i++) \
76  d[i] = SYSclamp(d[i], TYPE(myMin), TYPE(myMax))
77 
78  void doImport(GT_Offset off, uint8 *d, GT_Size sz) const override
79  { myData->import(off, d, sz);
81  void doImport(GT_Offset off, int8 *d, GT_Size sz) const override
82  { myData->import(off, d, sz);
83  CLAMP_VALUES(int8); }
84  void doImport(GT_Offset off, int16 *d, GT_Size sz) const override
85  { myData->import(off, d, sz);
87  void doImport(GT_Offset off, int32 *d, GT_Size sz) const override
88  { myData->import(off, d, sz);
90  void doImport(GT_Offset off, int64 *d, GT_Size sz) const override
91  { myData->import(off, d, sz);
93  void doImport(GT_Offset off, fpreal16 *d, GT_Size sz) const override
94  { myData->import(off, d, sz);
96  void doImport(GT_Offset off, fpreal32 *d, GT_Size sz) const override
97  { myData->import(off, d, sz);
99  void doImport(GT_Offset off, fpreal64 *d,
100  GT_Size sz) const override
101  { myData->import(off, d, sz);
103 #undef CLAMP_VALUES
104 #define CLAMP_ARRAY(TYPE) \
105  for(int i=0; i<data.entries(); i++) \
106  data(i) = SYSclamp(data(i), (TYPE)myMin, (TYPE)myMax)
107 
109  UT_ValArray<fpreal16> &data) const override
110  { myData->import(off, data);
113  UT_ValArray<fpreal32> &data) const override
114  { myData->import(off, data);
117  UT_ValArray<fpreal64> &data) const override
118  { myData->import(off, data);
121  UT_ValArray<uint8> &data) const override
122  { myData->import(off, data);
123  CLAMP_ARRAY(uint8);}
125  UT_ValArray<int8> &data) const override
126  { myData->import(off, data);
127  CLAMP_ARRAY(int8); }
129  UT_ValArray<int16> &data) const override
130  { myData->import(off, data);
131  CLAMP_ARRAY(int16); }
133  UT_ValArray<int32> &data) const override
134  { myData->import(off, data);
135  CLAMP_ARRAY(int32); }
137  UT_ValArray<int64> &data) const override
138  { myData->import(off, data);
139  CLAMP_ARRAY(int64); }
142  GT_Offset start, GT_Size length) const override
143  {
144  UT_ASSERT(start >= 0 && length <= entries());
145  if (myData->getStorage() == GT_STORE_STRING)
146  {
147  UT_StringArray attr_strings;
148  for (GT_Offset off = start; off < length; ++off)
149  {
150  attr_strings.clear();
151  getSA(attr_strings, off);
152  sizes.append(attr_strings.entries());
153  data.concat(attr_strings);
154  }
155  }
156  }
157 
158 #undef CLAMP_ARRAY
159 
160 private:
161  double myMin;
162  double myMax;
163 };
164 
165 #endif
fpreal32 getF32(GT_Offset offset, int idx=0) const override
void doImport(GT_Offset off, int16 *d, GT_Size sz) const override
GLuint GLsizei const GLuint const GLintptr const GLsizeiptr * sizes
Definition: glcorearb.h:2621
#define CLAMP(EXPR, TYPE)
void doImportArray(GT_Offset off, UT_ValArray< fpreal64 > &data) const override
GLsizei GLenum const void * indices
Definition: glcorearb.h:406
int int32
Definition: SYS_Types.h:39
fpreal64 getF64(GT_Offset offset, int idx=0) const override
GT_DAClampedArray(const GT_DataArrayHandle &data, fpreal64 min_v, fpreal64 max_v)
GT_Size entries() const override
Number of entries in the array.
GLuint start
Definition: glcorearb.h:475
void doImport(GT_Offset off, fpreal32 *d, GT_Size sz) const override
uint8 getU8(GT_Offset offset, int idx=0) const override
GT_DAClampedArray(const GT_DAClampedArray &src)
void fillStringArray(UT_StringArray &data, UT_ValArray< int > &sizes, GT_Offset start, GT_Size length) const override
GT_Size getStringIndexCount() const override
void doImportArray(GT_Offset off, UT_ValArray< int32 > &data) const override
bool getSA(UT_StringArray &a, GT_Offset offset) const override
#define GT_API
Definition: GT_API.h:13
void doImport(GT_Offset off, fpreal64 *d, GT_Size sz) const override
#define CLAMP_ARRAY(TYPE)
GLboolean GLboolean GLboolean GLboolean a
Definition: glcorearb.h:1222
GLuint GLsizei GLsizei * length
Definition: glcorearb.h:795
A value-clamped version of another array, useful for data ranges.
void doImport(GT_Offset off, fpreal16 *d, GT_Size sz) const override
exint concat(const UT_Array< T > &a)
Takes another T array and concatenate it onto my end.
Definition: UT_ArrayImpl.h:982
void doImportArray(GT_Offset off, UT_ValArray< uint8 > &data) const override
void doImport(GT_Offset off, int32 *d, GT_Size sz) const override
float fpreal32
Definition: SYS_Types.h:200
#define SYS_FP64_MAX
Definition: SYS_Types.h:221
int32 getI32(GT_Offset offset, int idx=0) const override
const char * className() const override
double fpreal64
Definition: SYS_Types.h:201
unsigned char uint8
Definition: SYS_Types.h:36
GLintptr offset
Definition: glcorearb.h:665
void getIndexedDicts(UT_Array< UT_OptionsHolder > &dicts, UT_IntArray &indices) const override
GT_Offset getDictIndex(GT_Offset offset, int idx) const override
void doImport(GT_Offset off, int64 *d, GT_Size sz) const override
void doImportArray(GT_Offset off, UT_ValArray< int8 > &data) const override
int64 getI64(GT_Offset offset, int idx=0) const override
#define CLAMP_VALUES(TYPE)
int64 GT_Offset
Definition: GT_Types.h:129
long long int64
Definition: SYS_Types.h:116
virtual bool getSA(UT_StringArray &a, GT_Offset offset) const
Definition: GT_DataArray.h:118
signed char int8
Definition: SYS_Types.h:35
fpreal16 getF16(GT_Offset offset, int idx=0) const override
void doImport(GT_Offset off, uint8 *d, GT_Size sz) const override
GLsizei const GLchar *const * strings
Definition: glcorearb.h:1933
exint append()
Definition: UT_Array.h:142
virtual GT_Size entries() const =0
Number of entries in the array.
void doImportArray(GT_Offset off, UT_ValArray< fpreal16 > &data) const override
GT_Size getDictIndexCount() const override
exint entries() const
Alias of size(). size() is preferred.
Definition: UT_Array.h:648
int64 GT_Size
Definition: GT_Types.h:128
GT_String getS(GT_Offset offset, int idx=0) const override
void doImportArray(GT_Offset off, UT_ValArray< int64 > &data) const override
Base class for a data array which references another data array.
Definition: GT_DAInherit.h:18
short int16
Definition: SYS_Types.h:37
void getIndexedStrings(UT_StringArray &strings, UT_IntArray &indices) const override
GT_Offset getStringIndex(GT_Offset offset, int idx) const override
void doImportArray(GT_Offset off, UT_ValArray< int16 > &data) const override
#define UT_ASSERT(ZZ)
Definition: UT_Assert.h:156
void clear()
Resets list to an empty list.
Definition: UT_Array.h:729
void doImport(GT_Offset off, int8 *d, GT_Size sz) const override
Definition: format.h:895
void doImportArray(GT_Offset off, UT_ValArray< fpreal32 > &data) const override
GLenum src
Definition: glcorearb.h:1793