1 | /* |
---|
2 | |
---|
3 | Brian Curless |
---|
4 | |
---|
5 | Computer Graphics Laboratory |
---|
6 | Stanford University |
---|
7 | |
---|
8 | --------------------------------------------------------------------- |
---|
9 | |
---|
10 | Copyright (1997) The Board of Trustees of the Leland Stanford Junior |
---|
11 | University. Except for commercial resale, lease, license or other |
---|
12 | commercial transactions, permission is hereby given to use, copy, |
---|
13 | modify this software for academic purposes only. No part of this |
---|
14 | software or any derivatives thereof may be used in the production of |
---|
15 | computer models for resale or for use in a commercial |
---|
16 | product. STANFORD MAKES NO REPRESENTATIONS OR WARRANTIES OF ANY KIND |
---|
17 | CONCERNING THIS SOFTWARE. No support is implied or provided. |
---|
18 | |
---|
19 | */ |
---|
20 | |
---|
21 | |
---|
22 | #ifndef _OCC_GRID_NORM_RLE_ |
---|
23 | #define _OCC_GRID_NORM_RLE_ |
---|
24 | |
---|
25 | #include "vrip.h" |
---|
26 | #include "ChunkAllocator.h" |
---|
27 | #include <limits.h> |
---|
28 | |
---|
29 | |
---|
30 | typedef ushort RunLength; |
---|
31 | |
---|
32 | |
---|
33 | class OccScanlineNormRLE { |
---|
34 | |
---|
35 | public: |
---|
36 | |
---|
37 | RunLength *lengths; |
---|
38 | OccNormElement *elements; |
---|
39 | RunLength *currentLength; |
---|
40 | OccNormElement *currentElem; |
---|
41 | |
---|
42 | void reset(); |
---|
43 | OccNormElement *getNextElement(); |
---|
44 | RunLength getNextLength(); |
---|
45 | void putNextElement(OccNormElement *element); |
---|
46 | void putNextLength(RunLength length); |
---|
47 | }; |
---|
48 | |
---|
49 | |
---|
50 | |
---|
51 | class OccGridNormRLE { |
---|
52 | |
---|
53 | public: |
---|
54 | enum {CONSTANT_DATA, VARYING_DATA, END_OF_RUN=USHRT_MAX}; |
---|
55 | static const ushort HIGHEST_BIT = 0x8000; |
---|
56 | |
---|
57 | int xdim, ydim, zdim; |
---|
58 | float resolution; |
---|
59 | vec3f origin; |
---|
60 | vec3f *sliceOrigins; |
---|
61 | int axis; |
---|
62 | int flip; |
---|
63 | |
---|
64 | RunLength **lengthAddr; |
---|
65 | ChunkAllocator *lengthChunker; |
---|
66 | RunLength *currentLength; |
---|
67 | |
---|
68 | OccNormElement **elementAddr; |
---|
69 | ChunkAllocator *elementChunker; |
---|
70 | OccNormElement *currentElem; |
---|
71 | |
---|
72 | OccScanlineNormRLE *rleScanline; |
---|
73 | OccNormElement *slice; |
---|
74 | OccNormElement *otherSlice; |
---|
75 | OccNormElement *scanline; |
---|
76 | OccNormElement *defaultElement; |
---|
77 | int transpXZbytesPerScanline; |
---|
78 | uchar *transpXZslice; |
---|
79 | |
---|
80 | OccGridNormRLE(); |
---|
81 | OccGridNormRLE(int,int,int,int); |
---|
82 | |
---|
83 | void init(int,int,int,int); |
---|
84 | void freeSpace(); |
---|
85 | |
---|
86 | void copy(OccGridNormRLE *other); |
---|
87 | void copyParams(OccGridNormRLE *other); |
---|
88 | |
---|
89 | int transposeXZ(OccGridNormRLE *other); |
---|
90 | int transposeXY(OccGridNormRLE *other); |
---|
91 | int transposeYZ(OccGridNormRLE *other); |
---|
92 | |
---|
93 | void clear(); |
---|
94 | void reset(); |
---|
95 | |
---|
96 | OccNormElement *getSlice(const char *axis, int sliceNum, int *pxdim, int *pydim); |
---|
97 | OccNormElement *getScanline(int y, int z); |
---|
98 | void putScanline(OccNormElement *line, int y, int z); |
---|
99 | void copyScanline(OccScanlineNormRLE *rleScanline, int y, int z); |
---|
100 | OccNormElement *transposeSlice(int xdim,int ydim); |
---|
101 | OccNormElement *getElement(int xx, int yy, int zz); |
---|
102 | void runStats(int yy, int zz, int *numRuns, int *numElems); |
---|
103 | int getRunType(RunLength *length); |
---|
104 | void setRunType(RunLength *length, int runType); |
---|
105 | void putNextElement(OccNormElement *element); |
---|
106 | void putNextLength(RunLength length); |
---|
107 | OccNormElement *getNextElement(); |
---|
108 | RunLength getNextLength(); |
---|
109 | void allocNewRun(int y, int z); |
---|
110 | void setScanline(int y, int z); |
---|
111 | int writeDen(const char *); |
---|
112 | int write(const char *); |
---|
113 | int read(const char *); |
---|
114 | OccScanlineNormRLE *getRLEScanline(int yy, int zz); |
---|
115 | ~OccGridNormRLE(); |
---|
116 | }; |
---|
117 | |
---|
118 | |
---|
119 | inline void |
---|
120 | OccScanlineNormRLE::reset() |
---|
121 | { |
---|
122 | currentElem = elements; |
---|
123 | currentLength = lengths; |
---|
124 | } |
---|
125 | |
---|
126 | inline OccNormElement * |
---|
127 | OccScanlineNormRLE::getNextElement() |
---|
128 | { |
---|
129 | return currentElem++; |
---|
130 | } |
---|
131 | |
---|
132 | |
---|
133 | inline RunLength |
---|
134 | OccScanlineNormRLE::getNextLength() |
---|
135 | { |
---|
136 | return *currentLength++; |
---|
137 | } |
---|
138 | |
---|
139 | |
---|
140 | inline void |
---|
141 | OccScanlineNormRLE::putNextElement(OccNormElement *element) |
---|
142 | { |
---|
143 | *currentElem = *element; |
---|
144 | |
---|
145 | /* |
---|
146 | currentElem->value = element->value; |
---|
147 | currentElem->totalWeight = element->totalWeight; |
---|
148 | */ |
---|
149 | |
---|
150 | currentElem++; |
---|
151 | } |
---|
152 | |
---|
153 | |
---|
154 | inline void |
---|
155 | OccScanlineNormRLE::putNextLength(RunLength length) |
---|
156 | { |
---|
157 | *currentLength = length; |
---|
158 | currentLength++; |
---|
159 | } |
---|
160 | |
---|
161 | |
---|
162 | inline void |
---|
163 | OccGridNormRLE::putNextElement(OccNormElement *element) |
---|
164 | { |
---|
165 | OccNormElement *newElem = |
---|
166 | (OccNormElement *)this->elementChunker->alloc(sizeof(OccNormElement)); |
---|
167 | |
---|
168 | *newElem = *element; |
---|
169 | |
---|
170 | |
---|
171 | /* |
---|
172 | newElem->value = element->value; |
---|
173 | newElem->totalWeight = element->totalWeight; |
---|
174 | */ |
---|
175 | } |
---|
176 | |
---|
177 | |
---|
178 | inline void |
---|
179 | OccGridNormRLE::putNextLength(RunLength length) |
---|
180 | { |
---|
181 | RunLength *newLength = |
---|
182 | (RunLength *)this->lengthChunker->alloc(sizeof(RunLength)); |
---|
183 | *newLength = length; |
---|
184 | } |
---|
185 | |
---|
186 | |
---|
187 | inline OccNormElement * |
---|
188 | OccGridNormRLE::getNextElement() |
---|
189 | { |
---|
190 | return currentElem++; |
---|
191 | } |
---|
192 | |
---|
193 | inline RunLength |
---|
194 | OccGridNormRLE::getNextLength() |
---|
195 | { |
---|
196 | return *currentLength++; |
---|
197 | } |
---|
198 | |
---|
199 | |
---|
200 | inline int |
---|
201 | OccGridNormRLE::getRunType(RunLength *length) |
---|
202 | { |
---|
203 | int flag; |
---|
204 | |
---|
205 | |
---|
206 | if (*length == OccGridNormRLE::END_OF_RUN) |
---|
207 | return OccGridNormRLE::END_OF_RUN; |
---|
208 | |
---|
209 | flag = *length & OccGridNormRLE::HIGHEST_BIT; |
---|
210 | *length = *length & ~OccGridNormRLE::HIGHEST_BIT; |
---|
211 | if (flag) { |
---|
212 | return OccGridNormRLE::VARYING_DATA; |
---|
213 | } else { |
---|
214 | return OccGridNormRLE::CONSTANT_DATA; |
---|
215 | } |
---|
216 | } |
---|
217 | |
---|
218 | |
---|
219 | inline void |
---|
220 | OccGridNormRLE::setRunType(RunLength *length, int runType) |
---|
221 | { |
---|
222 | if (runType == OccGridNormRLE::END_OF_RUN) |
---|
223 | *length = OccGridNormRLE::END_OF_RUN; |
---|
224 | else if (runType == OccGridNormRLE::VARYING_DATA) |
---|
225 | *length = *length | OccGridNormRLE::HIGHEST_BIT; |
---|
226 | |
---|
227 | // else leave it alone |
---|
228 | } |
---|
229 | |
---|
230 | |
---|
231 | |
---|
232 | #endif |
---|
233 | |
---|