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

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

Added original make3d

File size: 3.8 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#include <math.h>
23#include <limits.h>
24#include <stdio.h>
25#include <unistd.h>
26
27#include "occFunc.h"
28#include "scan.h"
29#include "vripGlobals.h"
30#include "resample.h"
31
32
33
34void
35scanConvert(OccGrid *grid, OrthoShear *shear, DepthMap *depthMap)
36{
37    float xOff, yOff, res, depth, confidence;
38    OccElement *buf;
39    int xx,yy,zz;
40
41    float sampleSpacing = sqrt(1 + shear->sx*shear->sx + shear->sy*shear->sy);
42
43    res = grid->resolution;
44
45    buf = grid->elems;
46    for (zz = 0; zz < grid->zdim; zz++) {
47        printf("\rTraversing slice %d of %d.", zz, grid->zdim-1);
48        fflush(stdout);
49        yOff = (grid->sliceOrigins[zz][1] - depthMap->origin[1])/res;
50        for (yy = 0; yy < grid->ydim; yy++, yOff++) {   
51            xOff = (grid->sliceOrigins[zz][0] - depthMap->origin[0])/res;
52            for (xx = 0; xx < grid->xdim; xx++, xOff++, buf++) {
53                resample(depthMap, xOff, yOff, &depth, &confidence);
54                updateCell(grid->sliceOrigins[zz][2], depth, sampleSpacing,
55                           confidence, buf);
56            }
57        }
58    }
59    printf("\n");
60}
61
62
63void
64scanConvertDragTails(OccGrid *grid, OrthoShear *shear, DepthMap *depthMap)
65{
66    float xOff, yOff, res, depth, confidence;
67    OccElement *buf;
68    int xx,yy,zz;
69
70    float sampleSpacing = sqrt(1 + shear->sx*shear->sx + shear->sy*shear->sy);
71
72    res = grid->resolution;
73
74    buf = grid->elems;
75    for (zz = 0; zz < grid->zdim; zz++) {
76        printf("\rTraversing slice %d of %d.", zz, grid->zdim-1);
77        fflush(stdout);
78        yOff = (grid->sliceOrigins[zz][1] - depthMap->origin[1])/res;
79        for (yy = 0; yy < grid->ydim; yy++, yOff++) {   
80            xOff = (grid->sliceOrigins[zz][0] - depthMap->origin[0])/res;
81            for (xx = 0; xx < grid->xdim; xx++, xOff++, buf++) {
82                resample(depthMap, xOff, yOff, &depth, &confidence);
83                updateCellForCarving(grid->sliceOrigins[zz][2], depth, sampleSpacing,
84                           confidence, buf);
85            }
86        }
87    }
88    printf("\n");
89}
90
91
92void
93scanConvertTree(OccGrid *grid, OrthoShear *shear, DepthMap *depthMap)
94{
95    float xOff, yOff, res, depth, confidence;
96    OccElement *buf;
97    int xx,yy,zz;
98    int *depthRuns, numRuns;
99    float zmin, zmax, xNewOff;
100    int xmin, xmax;
101
102    float sampleSpacing = sqrt(1 + shear->sx*shear->sx + shear->sy*shear->sy);
103
104    res = grid->resolution;
105
106    buf = grid->elems;
107    for (zz = 0; zz < grid->zdim; zz++) {
108        printf("\rTraversing slice %d of %d.", zz, grid->zdim-1);
109        fflush(stdout);
110        zmin = grid->sliceOrigins[zz][2] + C5/sampleSpacing;
111        zmax = grid->sliceOrigins[zz][2] + C1/sampleSpacing;
112        yOff = (grid->sliceOrigins[zz][1] - depthMap->origin[1])/res;
113        for (yy = 0; yy < grid->ydim; yy++, yOff++) {   
114            depthRuns = depthMap->getDepthRuns(yOff, zmin, zmax, &numRuns);
115            if (numRuns == 0)
116                continue;
117            xOff = (grid->sliceOrigins[zz][0] - depthMap->origin[0])/res;
118            for (int i = 0; i < numRuns; i++) {
119                xmin = int(depthRuns[2*i] - xOff);
120                xmin = MAX(xmin, 0);
121                xmax = int(ceil(depthRuns[2*i+1] - xOff));
122                xmax = MIN(xmax, grid->xdim-1);
123                xNewOff = xOff + xmin;
124                buf = grid->elems + xmin + yy*grid->xdim + 
125                    zz*grid->ydim*grid->xdim;
126                for (xx = xmin; xx <= xmax; xx++, xNewOff++, buf++) {
127                    resample(depthMap, xNewOff, yOff, &depth, &confidence);
128                    updateCell(grid->sliceOrigins[zz][2], depth, 
129                               sampleSpacing, confidence, buf);
130                }
131            }
132        }
133    }
134    printf("\n");
135}
136
Note: See TracBrowser for help on using the repository browser.