HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
PXL_DeepPixel.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: PXL_DeepPixel.h ( PXL Library, C++)
7  *
8  * COMMENTS:
9  */
10 
11 #ifndef __PXL_DeepPixel__
12 #define __PXL_DeepPixel__
13 
14 #include "PXL_API.h"
15 #include <UT/UT_Array.h>
16 #include <UT/UT_Lock.h>
17 #include "PXL_Forward.h"
18 
19 /// Class to accumulate multiple deep samples and merge them into a single list.
20 ///
21 /// Since this class allocates memory, it can be reused for multiple pixels,
22 /// reusing it's buffers.
23 ///
24 /// There are two modes of operation for the class:
25 /// - Accept a tuple of (int sample_id, uint8 flags, const float *data)
26 /// representing a single deep sample. In this mode, the deep pixel
27 /// accumulates mutiple sample tuples. The @c extract method will merge
28 /// them into a single PXL_DeepSampleListPtr based on the compressor passed
29 /// in.
30 /// - Accept one to four PXL_DeepSampleListPtr objects. This mode is typically
31 /// used when creating MIP maps. The @c extract method will call the
32 /// compressor to merge the existing PXL_DeepSampleListPtr objects into a
33 /// single PXL_DeepSampleListPtr.
34 ///
36 {
37 public:
38  /// SampleKey is used to keep track of the samples in the pixel and can be
39  /// used to sort them if need be.
40  class SampleKey
41  {
42  public:
43  SampleKey(const PXL_DeepPixel *pixel=0, int id=-1, int off=-1)
44  : myPixel(pixel)
45  , myId(id)
46  , myOffset(off)
47  {
48  }
49  bool operator<(const SampleKey &src) const
50  {
51  // For sorting, we sort by id's, then by zfront values. This lets
52  // us build sorted records for the sample list.
53  if (myId == src.myId)
54  return myPixel->samplez(*this) < myPixel->samplez(src);
55  return myId < src.myId;
56  }
57  int getId() const { return myId; }
58  int offset() const { return myOffset; }
59  private:
60  const PXL_DeepPixel *myPixel;
61  int myId;
62  int myOffset;
63  };
64 
66  int sample_lists_per_pixel);
67  ~PXL_DeepPixel();
68 
69  /// Test whether the pixel is accepting samples
70  bool isOpen() const { return myX >= 0; }
71 
72  /// Test whether the pixel is collecting PXL_DeepSampleListPtr's (rather
73  /// than raw float samples). Note, if no samples have been written, the
74  /// pixel could be in both MIP and raw style.
75  bool isMipStyle() const { return myMipCount.relaxedLoad() > 0; }
76  /// Test whether the pixel is collecting raw float data (rather than
77  /// PXL_DeepSampleListPtr's). Note, if no samples have been written, the
78  /// pixel could be in both MIP and raw style.
79  bool isRawStyle() const { return mySampleLists.size() > 0; }
80 
81  /// Return channel list passed into the c-tor
82  const PXL_DeepChannelListPtr &channels() const { return myChannels; }
83 
84  // Pixel Interface
85 
86  /// Start collecting samples for the given pixel. The @c precomposited
87  /// flag indicates whether the incoming samples are pre-composited or
88  /// uncomposited.
89  void startPixel(int x, int y, bool precomposted);
90 
91  /// Store a sample for MIP style accumulation.
92  void store(const PXL_DeepSampleListPtr &sample);
93  /// Store a raw sample. The samples do not have to be added in order.
94  /// - @c zfront @n
95  /// The nearest z value for the sample.
96  /// - @c zback @n
97  /// The far z value for the sample. For hard surfaces, this is likely
98  /// the same as @c zfront.
99  /// - @c channel_data @n
100  /// The floating point data for all the channels. The length of this
101  /// array should be @c channels()->totalSize() and the data in the array
102  /// should be ordered according to the channel order.
103  /// - @c flags @n
104  /// Please see the list of flags in PXL_DeepSampleList.h
105  /// - @c sample_id @n
106  /// This represents the sub-pixel sample id. For example with 3x3 pixel
107  /// sampling, the sample id's would run between 0 and 9. A value of -1
108  /// indicates that no sample id is available. The sample id is used in
109  /// creating the @c coverage for the pixel.
110  void store(float zfront, float zback, const float *channel_data,
111  int flags, int sample_id);
112 
113  /// Close the pixel, returning the result of the compressor's merge
114  /// operation.
115  PXL_DeepSampleListPtr closePixel(
116  const PXL_DeepCompressorPtr &compress);
117 
118  /// @{
119  /// Return coordinate passed into @c startPixel()
120  int x() const { return myX; }
121  int y() const { return myY; }
122  /// @}
123 
124  float samplez(const SampleKey &k) const
125  {
126  int off = k.offset();
127  UT_ASSERT(off >= 0 && off < mySampleLists.size());
128  return myFloats[off*myFloatCount];
129  }
130  void dump(const char *msg="") const;
131 
132 private:
133  int sort();
134  void extract(PXL_DeepSampleListPtr *samples, int count) const;
135 
136  float zfront(int off) const
137  {
138  UT_ASSERT_P(myFloats && !myMipCount.relaxedLoad());
139  UT_ASSERT(off >= 0 && off < mySampleLists.size());
140  off = mySampleLists(off).offset();
141  return myFloats[off*myFloatCount];
142  }
143  float zback(int off) const
144  {
145  UT_ASSERT_P(myFloats && !myMipCount.relaxedLoad());
146  UT_ASSERT(off >= 0 && off < mySampleLists.size());
147  off = mySampleLists(off).offset();
148  return myFloats[off*myFloatCount+1];
149  }
150  const float *data(int off) const
151  {
152  UT_ASSERT_P(myFloats && !myMipCount.relaxedLoad());
153  UT_ASSERT(off >= 0 && off < mySampleLists.size());
154  off = mySampleLists(off).offset();
155  return myFloats + off*myFloatCount + 2;
156  }
157  int getId(int off) const
158  {
159  return mySampleLists(off).getId();
160  }
161 private:
162  void clear();
163  PXL_DeepSampleListPtr extract(int start, int end) const;
164 
165  PXL_DeepChannelListPtr myChannels;
166  UT_Lock myLock;
167  PXL_DeepSampleListPtr myMip[4];
168  float *myFloats;
169  uint8 *myFlags;
170  UT_Array<SampleKey> mySampleLists;
171  int mySampleListsPerPixel;
172  int myX, myY; // Current pixel
173  SYS_AtomicInt32 myMipCount;
174  int myFloatCount;
175  bool myPrecomposited;
176 };
177 
178 #endif
GLbitfield flags
Definition: glcorearb.h:1596
int y() const
GLboolean * data
Definition: glcorearb.h:131
GLuint start
Definition: glcorearb.h:475
float samplez(const SampleKey &k) const
GLint y
Definition: glcorearb.h:103
bool operator<(const SampleKey &src) const
Definition: PXL_DeepPixel.h:49
#define PXL_API
Definition: PXL_API.h:10
unsigned char uint8
Definition: SYS_Types.h:36
OIIO_FORCEINLINE bool extract(const vbool4 &a)
Definition: simd.h:3426
#define UT_ASSERT_P(ZZ)
Definition: UT_Assert.h:155
GLuint GLuint end
Definition: glcorearb.h:475
GLuint id
Definition: glcorearb.h:655
bool isOpen() const
Test whether the pixel is accepting samples.
Definition: PXL_DeepPixel.h:70
GLint GLenum GLint x
Definition: glcorearb.h:409
bool isMipStyle() const
Definition: PXL_DeepPixel.h:75
GLsizei samples
Definition: glcorearb.h:1298
int x() const
bool isRawStyle() const
Definition: PXL_DeepPixel.h:79
#define UT_ASSERT(ZZ)
Definition: UT_Assert.h:156
UT_SharedPtr< PXL_DeepCompressor > PXL_DeepCompressorPtr
Definition: PXL_Forward.h:26
void sort(I begin, I end, const Pred &pred)
Definition: pugixml.cpp:7334
const PXL_DeepChannelListPtr & channels() const
Return channel list passed into the c-tor.
Definition: PXL_DeepPixel.h:82
GLint GLsizei count
Definition: glcorearb.h:405
ImageBuf OIIO_API channels(const ImageBuf &src, int nchannels, cspan< int > channelorder, cspan< float > channelvalues={}, cspan< std::string > newchannelnames={}, bool shuffle_channel_names=false, int nthreads=0)
SampleKey(const PXL_DeepPixel *pixel=0, int id=-1, int off=-1)
Definition: PXL_DeepPixel.h:43
GLenum src
Definition: glcorearb.h:1793