-
Notifications
You must be signed in to change notification settings - Fork 167
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
13 changed files
with
962 additions
and
167 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
#include <tinyformat/tinyformat.hpp> | ||
|
||
#include <iostream> | ||
#include <string> | ||
#include <ctime> | ||
|
||
namespace Tungsten { | ||
|
||
void printProgressBar(int tick, int maxTicks) | ||
{ | ||
const int numCols = 80; | ||
const int numTicks = numCols - 19; | ||
|
||
int numFilledPrev = ((tick - 1)*numTicks)/maxTicks; | ||
int numFilledCur = ((tick + 0)*numTicks)/maxTicks; | ||
if (tick != 0 && numFilledPrev == numFilledCur) | ||
return; | ||
|
||
std::string bar(numTicks, ' '); | ||
for (int i = 0; i < numFilledCur; ++i) | ||
bar[i] = '#'; | ||
|
||
std::cout << tfm::format("\r [%s] %3d%%", bar, (100*tick)/maxTicks); | ||
std::cout.flush(); | ||
|
||
if (tick == maxTicks) { | ||
std::cout << '\r' << std::string(numCols, ' ') << '\r'; | ||
std::cout.flush(); | ||
} | ||
} | ||
|
||
void printTimestampedLog(const std::string &s) | ||
{ | ||
std::time_t t = std::time(NULL); | ||
char mbstr[100]; | ||
std::strftime(mbstr, sizeof(mbstr), "[%H:%M:%S] ", std::localtime(&t)); | ||
std::cout << mbstr << s << '\n'; | ||
std::cout.flush(); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
#ifndef LOGGING_HPP_ | ||
#define LOGGING_HPP_ | ||
|
||
#include <string> | ||
|
||
namespace Tungsten { | ||
|
||
void printProgressBar(int tick, int maxTicks); | ||
void printTimestampedLog(const std::string &s); | ||
|
||
} | ||
|
||
#endif /* LOGGING_HPP_ */ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
#ifndef RANGE_HPP_ | ||
#define RANGE_HPP_ | ||
|
||
namespace Tungsten { | ||
|
||
template<typename T> class RangeIterator; | ||
|
||
template<typename T> | ||
class Range | ||
{ | ||
T _start, _end, _step; | ||
|
||
public: | ||
Range(T start, T end, T step = T(1)) | ||
: _start(start), _end(end), _step(step) | ||
{ | ||
} | ||
|
||
RangeIterator<T> begin() const; | ||
RangeIterator<T> end() const; | ||
}; | ||
|
||
template<typename T> | ||
Range<T> range(T start, T end, T step = T(1)) | ||
{ | ||
return Range<T>(start, end, step); | ||
} | ||
|
||
template<typename T> | ||
class RangeIterator | ||
{ | ||
T _pos, _step; | ||
|
||
public: | ||
RangeIterator(T pos, T step) : _pos(pos), _step(step) {} | ||
|
||
bool operator!=(const RangeIterator &o) const { return _pos < o._pos; } | ||
RangeIterator &operator++() { _pos += _step; return *this; } | ||
RangeIterator operator++(int) { RangeIterator copy(*this); operator++(); return copy; } | ||
T operator*() const { return _pos; } | ||
}; | ||
|
||
template<typename T> | ||
RangeIterator<T> Range<T>::begin() const { return RangeIterator<T>(_start, _step); } | ||
|
||
template<typename T> | ||
RangeIterator<T> Range<T>::end() const { return RangeIterator<T>(_end, _step); } | ||
|
||
} | ||
|
||
#endif /* RANGE_HPP_ */ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
#ifndef BOXFILTER_HPP_ | ||
#define BOXFILTER_HPP_ | ||
|
||
#include "math/Box.hpp" | ||
|
||
#include "Pixmap.hpp" | ||
|
||
namespace Tungsten { | ||
|
||
template<typename Texel> | ||
void boxFilterSlow(const Pixmap<Texel> &src, Pixmap<Texel> &result, int R, Box2i subImage = Box2i()) | ||
{ | ||
if (subImage.empty()) | ||
subImage = Box2i(Vec2i(0), Vec2i(src.w(), src.h())); | ||
|
||
int x0 = subImage.min().x(), x1 = subImage.max().x(); | ||
int y0 = subImage.min().y(), y1 = subImage.max().y(); | ||
|
||
for (int y = y0; y < y1; ++y) { | ||
for (int x = x0; x < x1; ++x) { | ||
Texel sum(0.0f); | ||
int pixelCount = 0; | ||
for (int dy = -R; dy <= R; ++dy) { | ||
for (int dx = -R; dx <= R; ++dx) { | ||
int xp = x + dx; | ||
int yp = y + dy; | ||
if (xp >= x0 && xp < x1 && yp >= y0 && yp < y1) { | ||
sum += src(xp, yp); | ||
pixelCount++; | ||
} | ||
} | ||
} | ||
|
||
result(x, y) = sum/pixelCount; | ||
} | ||
} | ||
} | ||
|
||
template<typename Texel> | ||
void boxFilter(const Pixmap<Texel> &src, Pixmap<Texel> &tmp, Pixmap<Texel> &result, int R, Box2i subImage = Box2i()) | ||
{ | ||
if (subImage.empty()) | ||
subImage = Box2i(Vec2i(0), Vec2i(src.w(), src.h())); | ||
|
||
int x0 = subImage.min().x(), x1 = subImage.max().x(); | ||
int y0 = subImage.min().y(), y1 = subImage.max().y(); | ||
|
||
if (x1 - x0 < 2*R || y1 - y0 < 2*R) { | ||
boxFilterSlow(src, result, R, subImage); | ||
return; | ||
} | ||
|
||
float factor = 1.0f/(2*R + 1); | ||
|
||
for (int y = y0; y < y1; ++y) { | ||
Texel sumL(0.0f); | ||
Texel sumR(0.0f); | ||
for (int x = 0; x < 2*R; ++x) { | ||
sumL += src(x0 + x, y); | ||
sumR += src(x1 - 1 - x, y); | ||
if (x >= R) { | ||
tmp(x0 + x - R , y) = sumL/(x + 1); | ||
tmp(x1 - 1 - (x - R), y) = sumR/(x + 1); | ||
} | ||
} | ||
for (int x = x0 + R; x < x1 - R; ++x) { | ||
sumL += src(x + R, y); | ||
tmp(x, y) = sumL*factor; | ||
sumL -= src(x - R, y); | ||
} | ||
} | ||
|
||
for (int x = x0; x < x1; ++x) { | ||
Texel sumL(0.0f); | ||
Texel sumR(0.0f); | ||
for (int y = 0; y < 2*R; ++y) { | ||
sumL += tmp(x, y0 + y); | ||
sumR += tmp(x, y1 - 1 - y); | ||
if (y >= R) { | ||
result(x, y0 + y - R) = sumL/(y + 1); | ||
result(x, y1 - 1 - (y - R)) = sumR/(y + 1); | ||
} | ||
} | ||
for (int y = y0 + R; y < y1 - R; ++y) { | ||
sumL += tmp(x, y + R); | ||
result(x, y) = sumL*factor; | ||
sumL -= tmp(x, y - R); | ||
} | ||
} | ||
} | ||
|
||
} | ||
|
||
#endif /* BOXFILTER_HPP_ */ |
Oops, something went wrong.