source: proiecte/pmake3d/make3d_original/Make3dSingleImageStanford_version0.1/third_party/vrippack-0.31/src/vrip/OccGridRLE.h @ 37

Last change on this file since 37 was 37, checked in by (none), 14 years ago

Added original make3d

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