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

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

Added original make3d

File size: 5.0 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_NORM_RLE_
23#define _OCC_GRID_NORM_RLE_
24
25#include "vrip.h"
26#include "ChunkAllocator.h"
27#include <limits.h>
28
29
30typedef ushort RunLength;
31
32
33class 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
51class 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
119inline void
120OccScanlineNormRLE::reset()
121{
122    currentElem = elements;
123    currentLength = lengths;
124}
125
126inline OccNormElement *
127OccScanlineNormRLE::getNextElement()
128{
129    return currentElem++;
130}
131
132
133inline RunLength
134OccScanlineNormRLE::getNextLength()
135{
136    return *currentLength++;
137}
138
139
140inline void 
141OccScanlineNormRLE::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
154inline void 
155OccScanlineNormRLE::putNextLength(RunLength length)
156{
157    *currentLength = length;
158    currentLength++;
159}
160
161
162inline void
163OccGridNormRLE::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
178inline void
179OccGridNormRLE::putNextLength(RunLength length)
180{
181    RunLength *newLength = 
182        (RunLength *)this->lengthChunker->alloc(sizeof(RunLength));
183    *newLength = length;
184}
185
186
187inline OccNormElement *
188OccGridNormRLE::getNextElement()
189{
190    return currentElem++;
191}
192
193inline RunLength
194OccGridNormRLE::getNextLength()
195{
196    return *currentLength++;
197}
198
199
200inline int
201OccGridNormRLE::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
219inline void
220OccGridNormRLE::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
Note: See TracBrowser for help on using the repository browser.