HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
POP_RTIParticlePoints.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: POP_RTIParticlePoints.h ( POP Library, C++)
7  *
8  * COMMENTS:
9  */
10 
11 #ifndef __POP_RTIParticlePoints__
12 #define __POP_RTIParticlePoints__
13 
14 #include "POP_API.h"
15 #include <GU/GU_Detail.h>
17 #include <GA/GA_OffsetList.h>
18 #include "POP_ParticleList.h"
19 #include <GEO/GEO_PrimPart.h>
20 #include <UT/UT_IntArray.h>
21 
22 /// Class to iterate over points in particle systems
24 {
25 public:
27  const POP_ParticleList &plist);
28 
30  const UT_IntArray &pagestarts,
31  const GA_OffsetList &offsetlist,
32  exint start, exint end);
33  virtual ~POP_RTIParticlePoints();
34 
35  /// @{
36  /// RangeTypeInterface API
37  virtual GA_RangeTypeInterface *copy() const
38  {
39  return new POP_RTIParticlePoints(myGeo,
40  myPageStarts,
41  myOffsetList,
42  myStart, myEnd);
43  }
44  virtual bool isSplittable() const { return true; }
45  virtual bool isEmpty() const { return myEnd - myStart == 0; }
46  virtual bool split(GA_RangeTypeInterface *list[2]) const;
47  virtual GA_Size getPageCount() const
48  { return myPageStarts.entries(); }
49  virtual bool getPageElementRange(GA_Range &range,
50  GA_Size start, GA_Size npages) const;
51  virtual GA_Offset getFirstOffsetInPage(GA_Size page) const;
52 
53  virtual bool isEqual(const GA_RangeTypeInterface &src) const
54  {
55  const POP_RTIParticlePoints *psrc;
56  psrc = dynamic_cast<const POP_RTIParticlePoints *>(&src);
57  if (!psrc)
58  return false;
59  return &myGeo == &(psrc->myGeo) &&
60  myOffsetList.isEqual(psrc->myOffsetList, myStart, myEnd) &&
61  myStart == psrc->myStart &&
62  myEnd == psrc->myEnd;
63  }
64  virtual GA_Size getMaxEntries() const
65  { return myEnd - myStart; }
66  virtual GA_Size getEntries() const
67  { return myEnd - myStart; }
68  /// @}
69 
70  class IState
71  {
72  public:
73  IState(const GA_OffsetList &offsets, int start, int end)
74  {
75  myOffsets = offsets;
76  myStart = start;
77  myEnd = end;
78  myIdx = start;
79  }
80  IState(const IState &src)
81  : myOffsets(src.myOffsets)
82  , myStart(src.myStart)
83  , myEnd(src.myEnd)
84  , myIdx(src.myIdx)
85  { }
86  ~IState() {}
87 
88  void rewind()
89  {
90  myIdx = myStart;
91  }
92  bool atEnd() const
93  {
94  return myIdx == myEnd;
95  }
96 
98  {
99  if (atEnd() || myEnd <= myStart)
100  {
101  s = GA_INVALID_OFFSET; // Invalid range
102  e = GA_INVALID_OFFSET;
103  }
104  else
105  {
106  s = myOffsets.get(myIdx);
107  e = GA_Offset(s + 1);
108  for(;;)
109  {
110  myIdx++;
111  if(myIdx >= myEnd)
112  {
113  break;
114  }
115  if (e != myOffsets.get(myIdx))
116  break;
117  ++e;
118  }
119  }
120  }
121 
122  private:
123  GA_OffsetList myOffsets;
124  exint myStart, myEnd;
125  exint myIdx;
126  };
127 
128 
129  /// @{
130  /// Iterator state information
131  virtual void iterateCreate(GA_IteratorState &state) const
132  {
133  // Copy over my particle list
134  state.myPointer = new IState(myOffsetList, myStart, myEnd);
135  }
136  virtual void iterateDestroy(GA_IteratorState &state) const
137  {
138  // Copy over my particle list
139  delete static_cast<IState *>(state.myPointer);
140  }
141  virtual void iterateCopy(GA_IteratorState &dest,
142  const GA_IteratorState &src) const
143  {
144  const IState *state;
145  state = static_cast<IState *>(src.myPointer);
146  dest.myPointer = new IState(*state);
147  }
148  virtual void iterateRewind(GA_IteratorState &state,
149  GA_Offset &start, GA_Offset &end) const
150  {
151  IState *it;
152  it = static_cast<IState *>(state.myPointer);
153  it->rewind();
154  it->extractRange(start, end);
155  }
156  virtual void iterateNext(GA_IteratorState &state,
157  GA_Offset &start, GA_Offset &end) const
158  {
159  IState *it;
160  it = static_cast<IState *>(state.myPointer);
161  it->extractRange(start, end);
162  }
163  /// @}
164 
165 private:
166  exint getPageStart(exint page) const
167  {
168  return myPageStarts(page);
169  }
170  exint getPageEnd(exint page) const
171  {
172  return page < myPageStarts.entries()-1
173  ? myPageStarts(page+1)
174  : myOffsetList.entries();
175  }
176  const GU_Detail &myGeo;
177  GA_OffsetList myOffsetList;
178  UT_IntArray myPageStarts;
179  // [start, end)
180  exint myStart, myEnd;
181 };
182 
183 #endif
184 
virtual bool isSplittable() const
GLenum GLint * range
Definition: glcorearb.h:1924
virtual bool isEqual(const GA_RangeTypeInterface &src) const
#define POP_API
Definition: POP_API.h:10
virtual bool split(GA_RangeTypeInterface *list[2]) const =0
virtual bool isEmpty() const
GLuint start
Definition: glcorearb.h:474
virtual GA_Size getEntries() const
exint GA_Size
Defines the bit width for index and offset types in GA.
Definition: GA_Types.h:211
#define GA_INVALID_OFFSET
Definition: GA_Types.h:654
A range of elements in an index-map.
Definition: GA_Range.h:42
GLuint GLsizei const GLuint const GLintptr * offsets
Definition: glcorearb.h:2620
IState(const GA_OffsetList &offsets, int start, int end)
GA_Size GA_Offset
Definition: GA_Types.h:617
int64 exint
Definition: SYS_Types.h:109
virtual void iterateDestroy(GA_IteratorState &state) const
virtual bool getPageElementRange(GA_Range &range, GA_Size relative_page, GA_Size npages=1) const =0
GLuint GLuint end
Definition: glcorearb.h:474
virtual GA_Size getMaxEntries() const
virtual void iterateCopy(GA_IteratorState &dest, const GA_IteratorState &src) const
void extractRange(GA_Offset &s, GA_Offset &e)
Abstract implementation of a range.
virtual void iterateCreate(GA_IteratorState &state) const
png_infop png_sPLT_tpp entries
Definition: png.h:2481
virtual GA_RangeTypeInterface * copy() const
virtual GA_Size getPageCount() const
virtual void iterateNext(GA_IteratorState &state, GA_Offset &start, GA_Offset &end) const
virtual GA_Offset getFirstOffsetInPage(GA_Size relative_page) const =0
Class to iterate over points in particle systems.
virtual void iterateRewind(GA_IteratorState &state, GA_Offset &start, GA_Offset &end) const
GLenum src
Definition: glcorearb.h:1792