Added the ability to choose output types and the ability to show what points came from the left laser versus the right

This commit is contained in:
Uriah Liggett
2015-02-22 18:52:40 +00:00
parent 834232c02c
commit 0824e1a7bc
21 changed files with 724 additions and 318 deletions

View File

@@ -28,6 +28,12 @@
#include "PresetManager.h"
#include "PropertyReaderWriter.h"
#include "Setup.h"
#include <algorithm>
static bool SortRecordByRow(const freelss::NeutralFileRecord& a, const freelss::NeutralFileRecord& b)
{
return a.pixel.y < b.pixel.y;
}
void ReleaseSingletons()
{
@@ -53,6 +59,17 @@ int main(int argc, char **argv)
{
int retVal = 0;
pid_t pid = fork();
if (pid < 0)
{
std::cerr << "Error forking process!!!" << std::endl;
return 1;
}
else if (pid != 0)
{
return 0;
}
// Initialize the Raspberry Pi hardware
bcm_host_init();
@@ -74,10 +91,9 @@ int main(int argc, char **argv)
while (true)
{
freelss::Thread::usleep(100000);
freelss::Thread::usleep(500000); // Sleep 500ms
}
ReleaseSingletons();
}
catch (freelss::Exception& ex)
@@ -120,6 +136,124 @@ time_t ScanResult::getScanDate() const
return files.front().creationTime;
}
bool NeutralFileRecord::readNextFrame(std::vector<NeutralFileRecord>& out, const std::vector<NeutralFileRecord>& results, size_t & resultIndex)
{
out.clear();
if (resultIndex >= results.size() || results.empty())
{
return false;
}
int pseudoStep = results[resultIndex].pseudoFrame;
while (pseudoStep == results[resultIndex].pseudoFrame && resultIndex < results.size())
{
out.push_back(results[resultIndex]);
resultIndex++;
}
return true;
}
void NeutralFileRecord::computeAverage(const std::vector<NeutralFileRecord>& bin, NeutralFileRecord& out)
{
out = bin.front();
real32 invSize = 1.0f / bin.size();
real32 rotation = 0;
real32 pixelLocationX = 0;
real32 pixelLocationY = 0;
real32 ptX = 0;
real32 ptY = 0;
real32 ptZ = 0;
real32 ptR = 0;
real32 ptG = 0;
real32 ptB = 0;
for (size_t iBin = 0; iBin < bin.size(); iBin++)
{
const NeutralFileRecord& br = bin[iBin];
rotation += invSize * br.rotation;
pixelLocationX += invSize * br.pixel.x;
pixelLocationY += invSize * br.pixel.y;
ptX += invSize * br.point.x;
ptY += invSize * br.point.y;
ptZ += invSize * br.point.z;
ptR += invSize * br.point.r;
ptG += invSize * br.point.g;
ptB += invSize * br.point.b;
}
out.rotation = rotation;
out.pixel.x = pixelLocationX; // TODO: We should probably round these values
out.pixel.y = pixelLocationY;
out.point.x = ptX;
out.point.y = ptY;
out.point.z = ptZ;
out.point.r = ptR;
out.point.g = ptG;
out.point.b = ptB;
}
void NeutralFileRecord::lowpassFilter(std::vector<NeutralFileRecord>& output, std::vector<NeutralFileRecord>& frame, unsigned maxNumRows, unsigned numRowBins)
{
output.clear();
// Sanity check
if (frame.empty())
{
return;
}
// Sort by image row
std::sort(frame.begin(), frame.end(), SortRecordByRow);
unsigned binSize = maxNumRows / numRowBins;
// Holds the current contents of the bin
std::vector<NeutralFileRecord> bin;
unsigned nextBinY = frame.front().pixel.y + binSize;
// unsigned bin = frame.front().pixel.y / numRowBins;
for (size_t iFr = 0; iFr < frame.size(); iFr++)
{
NeutralFileRecord& record = frame[iFr];
if (record.pixel.y < nextBinY)
{
bin.push_back(record);
}
else
{
// Average the bin results and add it to the output
if (!bin.empty())
{
NeutralFileRecord out;
computeAverage(bin, out);
output.push_back(out);
bin.clear();
}
nextBinY = record.pixel.y + binSize;
bin.push_back(record);
}
}
// Process any results still left in the bin
if (!bin.empty())
{
NeutralFileRecord out;
computeAverage(bin, out);
output.push_back(out);
bin.clear();
}
}
void LoadProperties()
{
PropertyReaderWriter reader;
@@ -196,6 +330,11 @@ std::string ToString(int value)
return sstr.str();
}
std::string ToString(bool value)
{
return value ? "1" : "0";
}
real ToReal(const std::string& str)
{
return atof(str.c_str());
@@ -206,6 +345,11 @@ int ToInt(const std::string& str)
return atoi(str.c_str());
}
bool ToBool(const std::string& str)
{
return str == "1" || str == "true";
}
bool EndsWith(const std::string& str, const std::string& ending)
{
if (str.length() >= ending.length())