Skip to content

Commit d11fef2

Browse files
author
tsing
committed
More comment, less dead code
1 parent 54aa191 commit d11fef2

11 files changed

+77
-60
lines changed

src/app/App.cpp

+1
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ int main(int argc, char** argv)
4545
auto pointCloud = reconstruct.reconstruct();
4646

4747
auto extension = output.substr(output.find_last_of(".")+1);
48+
pointCloud.exportPointCloud( p.get<std::string>("output"), extension);
4849
//SLS::exportPointCloud(output, extension, reconstruct);
4950

5051
LOG::writeLog("DONE!\n");

src/lib/GrayCode/GrayCode.cpp

+8-2
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,14 @@ void GrayCode::generateGrayCode()
1616
// Set first frame to white
1717
grayCodes_[0] = cv::Mat(height_, width_, CV_8UC1, cv::Scalar(255));
1818
uchar flag = 0;
19+
20+
// Generate patterns to encode x pixels.
21+
// For each column
1922
for (size_t j=0; j<width_; j++)
2023
{
2124
int rem=0, num=j, prevRem=j%2;
25+
26+
// For each bit in the column
2227
for (size_t k=0; k<numColBits; k++)
2328
{
2429
num=num/2;
@@ -42,15 +47,17 @@ void GrayCode::generateGrayCode()
4247

4348
}
4449

50+
// Generate patterns to encode y pixels
51+
// For each row
4552
for (size_t i=0;i<height_;i++)
4653
{
4754
int rem=0, num=i, prevRem=i%2;
55+
// For each bit in the row
4856
for (size_t k=0; k<numRowBits; k++)
4957
{
5058

5159
num=num/2;
5260
rem=num%2;
53-
5461
if ((rem==0 && prevRem==1) || (rem==1 && prevRem==0)) {
5562
flag=1;
5663
}
@@ -68,7 +75,6 @@ void GrayCode::generateGrayCode()
6875

6976
prevRem=rem;
7077
}
71-
7278
}
7379
for (size_t i=0; i<grayCodes_.size(); i++)
7480
{

src/lib/GrayCode/GrayCode.hpp

+8
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,14 @@ class GrayCode
1414
for (auto &img: grayCodes_)
1515
img.release();
1616
}
17+
18+
/*! Generate and display gray code
19+
*
20+
* The patterns are encoded by [gray code](https://en.wikipedia.org/wiki/Gray_code) to
21+
* avoid error.
22+
* The binary are encoded separately for columns and rows. i.e. for a projector pixel (x, y)
23+
* we have (BitSeqX, BitSeqY).
24+
*/
1725
void generateGrayCode();
1826
private:
1927
//! Projector width and height

src/lib/ReconstructorCUDA/ReconstructorCUDA.cu

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ void ReconstructorCUDA::addCamera(Camera *cam)
1818
}
1919
PointCloud ReconstructorCUDA::reconstruct()
2020
{
21-
// For each camera, hack
21+
// For each camera, supports only two cameras now.
2222
GPUBuckets buckets[2] =
2323
{
2424
GPUBuckets( projector_->getNumPixels(),110),

src/lib/ReconstructorCUDA/ReconstructorCUDA.cuh

-28
Original file line numberDiff line numberDiff line change
@@ -32,11 +32,7 @@ struct GPUBucketsObj
3232
{
3333
return;
3434
}
35-
//uint count = atomicAdd( &(count_[bktIdx]), 1);
36-
//data_[count+bktIdx*MAX_CNT_PER_BKT_] = val;
3735
data_[atomicInc( &(count_[bktIdx]), MAX_CNT_PER_BKT_)+bktIdx*MAX_CNT_PER_BKT_] = val;
38-
//if (bktIdx * MAX_CNT_PER_BKT_ > (1<<20)-1)
39-
// printf("Too big!\n");
4036
}
4137
};
4238

@@ -70,30 +66,6 @@ public:
7066
}
7167
uint getNumBKTs() const{ return NUM_BKTS_;}
7268

73-
// Debug function
74-
uint getMaxCount(uint idx) const
75-
{
76-
std::vector<uint> count_h;
77-
count_h.resize(NUM_BKTS_);
78-
gpuErrchk( cudaMemcpy( &(count_h[0]), count_, sizeof(uint)*NUM_BKTS_, cudaMemcpyDeviceToHost));
79-
uint max = 0;
80-
FILE *pFp = std::fopen((std::string("testBucket")+std::to_string((int)idx)+std::string(".ppm")).c_str(), "wb");
81-
size_t w = 1024;
82-
size_t h = 768;
83-
if (pFp){
84-
std::fprintf(pFp, "P5\n%zu\n%zu\n%d\n", (size_t )w, (size_t )h, 255);
85-
for (size_t i=0; i<count_h.size(); i++)
86-
{
87-
if (count_h[i] > max) max = count_h[i];
88-
if (count_h[i] != 0)
89-
putc((unsigned char) 255, pFp);
90-
else
91-
putc((unsigned char) 0, pFp);
92-
}
93-
}
94-
return max;
95-
}
96-
9769
};
9870

9971

src/lib/core/FileReader.cpp

+2-4
Original file line numberDiff line numberDiff line change
@@ -136,15 +136,13 @@ void FileReader::computeShadowsAndThresholds()
136136
shadowMask_.setBit(j+i*resY_);
137137
else
138138
shadowMask_.clearBit(j+i*resY_);
139+
140+
// Experimental: Calculate thresholds based on the contrast of each pixel
139141
#ifdef AUTO_CONTRAST
140142
thresholds_[j+i*resY_]=diff/2;
141143
#endif
142144
}
143145
}
144-
// Output mask
145-
std::string pgmFName=name_+".pgm";
146-
LOG::writeLog("Writing mask to %s\n", pgmFName.c_str());
147-
shadowMask_.writeToPGM(pgmFName.c_str(), resX_, resY_, true);
148146
}
149147

150148
Ray FileReader::getRay(const size_t &x, const size_t &y)

src/lib/core/PointCloud.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ namespace SLS
3232
memcpy (p.data(), &pointCloud[i], sizeof(float) * 6);
3333
float sum = 0.0;
3434
for (const auto &elem : p)
35-
sum += abs(elem);
35+
sum += std::abs(elem);
3636
if (std::abs(sum - 0.0) < 0.0000001)
3737
continue;
3838
dataSS<<pointCloud[i+0]<<" "<<pointCloud[i+1]<<" "<<pointCloud[i+2]<<" "

src/lib/core/PointCloud.hpp

+8-2
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,10 @@
1414
namespace SLS
1515
{
1616

17-
//! A point cloud class
17+
//! Export pointcloud to obj file
1818
void exportPointCloud2OBJ(std::string fileName, const std::vector<float> &pointCloud);
19+
20+
//! Export pointcloud to ply file with colors
1921
void exportPointCloud2PLY(std::string fileName, const std::vector<float> &pointCloud);
2022

2123
/*! A point cloud class
@@ -31,9 +33,13 @@ class PointCloud
3133
* furthur processing on GPU.
3234
*/
3335
std::vector<float> buffer_;
34-
const size_t FLOATS_PER_POINT = 6;
36+
37+
//! Number of float elements per point. (x, y, z, r, g, b)
38+
static const size_t FLOATS_PER_POINT = 6;
3539
public:
3640
PointCloud() {}
41+
42+
//! Initialize point cloud with number of points
3743
PointCloud(size_t numPoints)
3844
{
3945
buffer_.resize(numPoints * FLOATS_PER_POINT);

src/lib/core/Projector.h

+6
Original file line numberDiff line numberDiff line change
@@ -30,20 +30,26 @@ class Projector
3030
size_t width_, height_;
3131
public:
3232
Projector() = delete;
33+
3334
//! Initialize projector with height and width
3435
Projector(size_t width, size_t height):width_{width},height_{height}{}
36+
3537
virtual ~Projector(){};
3638
/*! Return the size of project
3739
* \param w Output width
3840
* \param h Output height
3941
*/
4042
void getSize(size_t &w, size_t &h){w = width_; h = height_;}
43+
4144
//! Get width
4245
size_t getWidth() const {return width_;}
46+
4347
//! Get height
4448
size_t getHeight() const {return height_;}
49+
4550
//! Get number of pixels = getWidth() * getHeight()
4651
size_t getNumPixels() const {return width_ * height_;}
52+
4753
/*! Get required number of frames to distinguish all of the projector pixel.
4854
*
4955
* The patterns are designed such that each projector pixel has a unique binary sequence.

src/lib/core/ReconstructorCPU.cpp

+11-22
Original file line numberDiff line numberDiff line change
@@ -39,25 +39,21 @@ void ReconstructorCPU::generateBuckets()
3939
xTimesY = x * y;
4040

4141
// For each camera pixel
42-
//assert(dynamic_cast<FileReader*>(cam)->getNumFrames() == projector_->getRequiredNumFrames()*2+2);
43-
4442
for (size_t i = 0; i < xTimesY; i++) {
4543
if (!cam->queryMask(i)) // No need to process if in shadow
4644
continue;
4745

4846
cam->getNextFrame();
49-
cam->getNextFrame();//skip first two frames
47+
cam->getNextFrame(); //skip first two frames
5048

5149
Dynamic_Bitset bits(projector_->getRequiredNumFrames());
5250

5351
bool discard = false;
52+
5453
// for each frame
5554
for (int bitIdx = projector_->getRequiredNumFrames() - 1; bitIdx >= 0; bitIdx--) {
56-
//for (int bitIdx = 0; bitIdx <projector_->getRequiredNumFrames(); bitIdx++) {
5755

58-
//std::cout<<((FileReader*)cam)->getCurrentIdx()<<std::endl;
5956
auto frame = cam->getNextFrame();
60-
//std::cout<<((FileReader*)cam)->getCurrentIdx()<<std::endl;
6157
auto invFrame = cam->getNextFrame();
6258
unsigned char pixel = frame.at<uchar>(i % y, i / y);
6359
unsigned char invPixel = invFrame.at<uchar>(i % y, i / y);
@@ -68,11 +64,6 @@ void ReconstructorCPU::generateBuckets()
6864
// No need to do anything since the array is initialized as all zeros
6965
bits.clearBit((size_t) bitIdx);
7066
continue;
71-
//std::cout<<"-----\n"<<bits<<std::endl;
72-
//bits.clearBit(bitIdx);
73-
//std::cout<<std::setw(bits.size()-bitIdx)<<"c"<<std::endl;
74-
//std::cout<<bits<<std::endl;
75-
7667
}
7768
else if (pixel > invPixel && pixel - invPixel >
7869
((FileReader*)cam)->getWhiteThreshold(i)) {
@@ -85,22 +76,23 @@ void ReconstructorCPU::generateBuckets()
8576
continue;
8677
}
8778
} // end for each frame
88-
if (!discard) {
8979

80+
// if the pixel is valid, add to bucket.
81+
if (!discard)
82+
{
9083
auto vec2Idx = bits.to_uint_gray();
9184
if ( projector_->getWidth() > vec2Idx.x &&
9285
vec2Idx.y < projector_->getHeight()) {
9386
buckets_[camIdx][vec2Idx.x * projector_->getHeight() + vec2Idx.y].push_back(i);
9487
}
9588
}
9689
}
97-
9890
// Keep track of maximum number of pixels in a grid
99-
unsigned maxCount = 0;
100-
for (const auto &bucket: buckets_[camIdx]){
101-
if (bucket.size() > maxCount)
102-
maxCount = bucket.size();
103-
}
91+
//unsigned maxCount = 0;
92+
//for (const auto &bucket: buckets_[camIdx]){
93+
// if (bucket.size() > maxCount)
94+
// maxCount = bucket.size();
95+
//}
10496
}
10597

10698
}
@@ -112,10 +104,8 @@ PointCloud ReconstructorCPU::reconstruct()
112104
size_t x,y;
113105
cameras_[0]->getResolution(x,y);
114106
initBuckets();
115-
116107
LOG::startTimer();
117-
118-
for ( size_t i=0; i<buckets_[0].size(); i++) // 1024*768
108+
for ( size_t i=0; i<buckets_[0].size(); i++)
119109
{
120110
const auto &cam0bucket = buckets_[0][i];
121111
const auto &cam1bucket = buckets_[1][i];
@@ -150,7 +140,6 @@ PointCloud ReconstructorCPU::reconstruct()
150140
}
151141
midPointAvg = midPointAvg/ptCount;
152142
{
153-
//pointCloud_.push_back(1);
154143
auto color0 = cameras_[0]->getColor(minCam0Idx);
155144
auto color1 = cameras_[1]->getColor(minCam1Idx);
156145
res.pushPoint( glm::vec3(midPointAvg), (color0 + color1) / 2.0f);

src/lib/core/ReconstructorCPU.h

+31
Original file line numberDiff line numberDiff line change
@@ -27,18 +27,49 @@ namespace SLS
2727
class ReconstructorCPU: public Reconstructor
2828
{
2929
private:
30+
/*! Reconstruction buckets of cameras
31+
*
32+
* In the reconstruction, camera pixels are assigned to different projector pixels.
33+
* Generally, one projector pixels contains more than one camera pixel. For each camera, we assign
34+
* pixels to projector pixels, and call those projector pixels buckets.
35+
* ```
36+
* ProjPixels(Buckets) Camera pixels
37+
* +------------------+ +---+---+---+
38+
* | 0 +->+ | | |
39+
* +------------------+ +-------+---+
40+
* | 1 +->+ |
41+
* +------------------+ +----
42+
*
43+
* +------------------+ +---+---+
44+
* | n +->+ | |
45+
* +------------------+ +---+---+
46+
*
47+
* ```
48+
* The camera pixels in the same bucket of two different cameras are considered correspondent pixels,
49+
* depth then can be extracted from those pixels.
50+
*/
3051
std::vector<std::vector<std::vector<size_t>>> buckets_;//[camIdx][ProjPixelIdx][camPixelIdx]
3152
void initBuckets();
3253
void generateBuckets();
3354
public:
55+
56+
/*! Create a reconstructor with given projector size
57+
*/
3458
ReconstructorCPU(const size_t projX, const size_t projY):
3559
Reconstructor()
3660
{
3761
projector_ = new Projector(projX, projY);
3862
}
3963
~ReconstructorCPU() override;
64+
4065
//Interfaces
66+
//! Reconstruct point cloud.
4167
PointCloud reconstruct() override;
68+
69+
/*! Add a camera to reconstructor\
70+
*
71+
* Accepts two camera now.
72+
*/
4273
void addCamera(Camera *cam) override;
4374
};
4475
} // namespace SLS

0 commit comments

Comments
 (0)