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 | #include <math.h> |
---|
23 | #include <limits.h> |
---|
24 | #include <stdio.h> |
---|
25 | #include <unistd.h> |
---|
26 | |
---|
27 | #include "vrip.h" |
---|
28 | #include "vripGlobals.h" |
---|
29 | #include "linePersp.h" |
---|
30 | #include "resample.h" |
---|
31 | #include "occFunc.h" |
---|
32 | #include "scanNormRLE.h" |
---|
33 | |
---|
34 | |
---|
35 | void |
---|
36 | scanConvertTree(OccGridNormRLE *gridIn, OccGridNormRLE *gridOut, |
---|
37 | OrthoShear *shear, DepthMap *depthMap) |
---|
38 | { |
---|
39 | float xOff, yOff, res, depth, confidence; |
---|
40 | OccNormElement *buf, *scanline; |
---|
41 | int xx,yy,zz; |
---|
42 | int *depthRuns, numRuns; |
---|
43 | float zmin, zmax, xNewOff; |
---|
44 | int xmin, xmax; |
---|
45 | OccScanlineNormRLE *rleScanline; |
---|
46 | Vec3f norm; |
---|
47 | |
---|
48 | float sampleSpacing = sqrt(1 + shear->sx*shear->sx + shear->sy*shear->sy); |
---|
49 | |
---|
50 | res = gridIn->resolution; |
---|
51 | |
---|
52 | gridOut->copyParams(gridIn); |
---|
53 | |
---|
54 | gridOut->reset(); |
---|
55 | |
---|
56 | for (zz = 0; zz < gridIn->zdim; zz++) { |
---|
57 | printf("\rTraversing slice %d of %d.", zz, gridIn->zdim-1); |
---|
58 | fflush(stdout); |
---|
59 | |
---|
60 | // Something is really backwards here! |
---|
61 | |
---|
62 | /* |
---|
63 | zmin = gridIn->sliceOrigins[zz][2] + C5/sampleSpacing; |
---|
64 | zmax = gridIn->sliceOrigins[zz][2] + 2*C1/sampleSpacing; |
---|
65 | */ |
---|
66 | zmin = gridIn->sliceOrigins[zz][2] - C1/sampleSpacing; |
---|
67 | zmax = gridIn->sliceOrigins[zz][2] - C5/sampleSpacing; |
---|
68 | yOff = (gridIn->sliceOrigins[zz][1] - depthMap->origin[1])/res; |
---|
69 | for (yy = 0; yy < gridIn->ydim; yy++, yOff++) { |
---|
70 | depthRuns = depthMap->getDepthRuns(yOff, zmin, zmax, &numRuns); |
---|
71 | if (numRuns == 0) { |
---|
72 | rleScanline = gridIn->getRLEScanline(yy, zz); |
---|
73 | gridOut->copyScanline(rleScanline, yy, zz); |
---|
74 | continue; |
---|
75 | } |
---|
76 | xOff = (gridIn->sliceOrigins[zz][0] - depthMap->origin[0])/res; |
---|
77 | scanline = gridIn->getScanline(yy,zz); |
---|
78 | for (int i = 0; i < numRuns; i++) { |
---|
79 | xmin = int(depthRuns[2*i] - xOff); |
---|
80 | xmin = MAX(xmin, 0); |
---|
81 | xmax = int(ceil(depthRuns[2*i+1] - xOff)); |
---|
82 | xmax = MIN(xmax, gridIn->xdim-1); |
---|
83 | xNewOff = xOff + xmin; |
---|
84 | buf = scanline + xmin; |
---|
85 | for (xx = xmin; xx <= xmax; xx++, xNewOff++, buf++) { |
---|
86 | resampleNorm(depthMap, xNewOff, yOff, |
---|
87 | &depth, &confidence, norm); |
---|
88 | |
---|
89 | updateCell(gridIn->sliceOrigins[zz][2], depth, norm, |
---|
90 | sampleSpacing, confidence, buf); |
---|
91 | } |
---|
92 | } |
---|
93 | |
---|
94 | gridOut->putScanline(scanline,yy,zz); |
---|
95 | |
---|
96 | } |
---|
97 | } |
---|
98 | printf("\n"); |
---|
99 | } |
---|
100 | |
---|
101 | |
---|
102 | void |
---|
103 | scanConvertTree2(OccGridNormRLE *gridIn, OccGridNormRLE *gridOut, |
---|
104 | OrthoShear *shear, DepthMap *depthMap) |
---|
105 | { |
---|
106 | float xOff, yOff, res, depth, confidence; |
---|
107 | OccNormElement *buf, *scanline; |
---|
108 | int xx,yy,zz; |
---|
109 | int *depthRuns, numRuns, oldNumRuns; |
---|
110 | float zmin, zmax, xNewOff; |
---|
111 | int xmin, xmax; |
---|
112 | OccScanlineNormRLE *rleScanline; |
---|
113 | |
---|
114 | float sampleSpacing = sqrt(1 + shear->sx*shear->sx + shear->sy*shear->sy); |
---|
115 | |
---|
116 | res = gridIn->resolution; |
---|
117 | |
---|
118 | gridOut->copyParams(gridIn); |
---|
119 | |
---|
120 | gridOut->reset(); |
---|
121 | |
---|
122 | for (zz = 0; zz < gridIn->zdim; zz++) { |
---|
123 | printf("\rTraversing slice %d of %d.", zz, gridIn->zdim-1); |
---|
124 | fflush(stdout); |
---|
125 | |
---|
126 | // Something is really backwards here! |
---|
127 | |
---|
128 | /* |
---|
129 | zmin = gridIn->sliceOrigins[zz][2] + C5/sampleSpacing; |
---|
130 | zmax = gridIn->sliceOrigins[zz][2] + 2*C1/sampleSpacing; |
---|
131 | */ |
---|
132 | zmin = gridIn->sliceOrigins[zz][2] - C1/sampleSpacing; |
---|
133 | zmax = gridIn->sliceOrigins[zz][2] - C5/sampleSpacing; |
---|
134 | yOff = (gridIn->sliceOrigins[zz][1] - depthMap->origin[1])/res; |
---|
135 | for (yy = 0; yy < gridIn->ydim; yy++, yOff++) { |
---|
136 | |
---|
137 | // Points near the surface |
---|
138 | depthRuns = depthMap->getDepthRuns(yOff, zmin, zmax, &numRuns); |
---|
139 | if (numRuns != 0) { |
---|
140 | xOff = (gridIn->sliceOrigins[zz][0] - depthMap->origin[0])/res; |
---|
141 | scanline = gridIn->getScanline(yy,zz); |
---|
142 | for (int i = 0; i < numRuns; i++) { |
---|
143 | xmin = int(depthRuns[2*i] - xOff); |
---|
144 | xmin = MAX(xmin, 0); |
---|
145 | xmax = int(ceil(depthRuns[2*i+1] - xOff)); |
---|
146 | xmax = MIN(xmax, gridIn->xdim-1); |
---|
147 | xNewOff = xOff + xmin; |
---|
148 | buf = scanline + xmin; |
---|
149 | for (xx = xmin; xx <= xmax; xx++, xNewOff++, buf++) { |
---|
150 | resampleForCarving(depthMap, xNewOff, |
---|
151 | yOff, &depth, &confidence); |
---|
152 | updateCellForCarving(gridIn->sliceOrigins[zz][2], |
---|
153 | depth, |
---|
154 | sampleSpacing, confidence, buf); |
---|
155 | } |
---|
156 | } |
---|
157 | } |
---|
158 | |
---|
159 | oldNumRuns = numRuns; |
---|
160 | |
---|
161 | // Points in front of the surface |
---|
162 | depthRuns = depthMap->getDepthRunsUpperBound |
---|
163 | (yOff, zmin, &numRuns); |
---|
164 | |
---|
165 | if (oldNumRuns == 0 && numRuns == 0) { |
---|
166 | rleScanline = gridIn->getRLEScanline(yy, zz); |
---|
167 | gridOut->copyScanline(rleScanline, yy, zz); |
---|
168 | continue; |
---|
169 | } else if (numRuns == 0) { |
---|
170 | gridOut->putScanline(scanline,yy,zz); |
---|
171 | continue; |
---|
172 | } else if (oldNumRuns == 0) { |
---|
173 | scanline = gridIn->getScanline(yy,zz); |
---|
174 | } |
---|
175 | |
---|
176 | xOff = (gridIn->sliceOrigins[zz][0] - depthMap->origin[0])/res; |
---|
177 | for (int i = 0; i < numRuns; i++) { |
---|
178 | xmin = int(depthRuns[2*i] - xOff); |
---|
179 | xmin = MAX(xmin, 0); |
---|
180 | xmax = int(ceil(depthRuns[2*i+1] - xOff)); |
---|
181 | xmax = MIN(xmax, gridIn->xdim-1); |
---|
182 | buf = scanline + xmin; |
---|
183 | for (xx = xmin; xx <= xmax; xx++, buf++) { |
---|
184 | if (buf->totalWeight == 0) { |
---|
185 | buf->value = 0; |
---|
186 | } |
---|
187 | } |
---|
188 | } |
---|
189 | gridOut->putScanline(scanline,yy,zz); |
---|
190 | } |
---|
191 | } |
---|
192 | printf("\n"); |
---|
193 | } |
---|
194 | |
---|