Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 22 additions & 5 deletions .clang-format
Original file line number Diff line number Diff line change
@@ -1,10 +1,27 @@
---
BasedOnStyle: Google

IndentWidth: 4
TabWidth: 4
AccessModifierOffset: -3
UseTab: Never
SortIncludes: Never
ColumnLimit: 120
AllowShortFunctionsOnASingleLine: Empty

PointerAlignment: Right
BreakConstructorInitializers: AfterColon
DerivePointerAlignment: false

AllowShortBlocksOnASingleLine: Empty
AllowShortFunctionsOnASingleLine: Inline
AllowShortIfStatementsOnASingleLine: WithoutElse

BreakStringLiterals: false
ReflowComments: false

SpaceAfterTemplateKeyword: false

SortIncludes: Never
IncludeBlocks: Preserve

AlignConsecutiveMacros: Consecutive

BinPackParameters: false
BinPackArguments: false
...
1 change: 1 addition & 0 deletions .clang-format-ignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
src/scope/command-line/parsing/options.hpp
19 changes: 18 additions & 1 deletion .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,22 @@
"workspaceFolder": "/workspace",
"overrideCommand": true,
"postCreateCommand": "git config --global user.name \"${GIT_AUTHOR_NAME:-Your Name}\" && git config --global user.email \"${GIT_AUTHOR_EMAIL:-you@example.com}\" && /workspace/build.sh cmake",
"shutdownAction": "stopCompose"
"shutdownAction": "stopCompose",
"customizations": {
"vscode": {
"extensions": [
"twxs.cmake",
"ms-vscode.cpptools"
],
"settings": {
"[cpp]": {
"editor.defaultFormatter": "ms-vscode.cpptools",
"editor.formatOnSave": true,
"editor.formatOnSaveMode": "modifications"
},
"C_Cpp.formatting": "clangFormat",
"C_Cpp.clang_format_style": "file"
}
}
}
}
10 changes: 5 additions & 5 deletions src/scope/command-line/execution/executors.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,11 @@

namespace scope {

PrimaryScopePipelineExecutor::PrimaryScopePipelineExecutor(
RecalibrationOptions &&options, std::unique_ptr<NoiseFilterAlgorithm> noiseFilterAlgorithm,
std::unique_ptr<StarCentroidAlgorithm> starCentroidAlgorithm,
std::unique_ptr<OptimizationAlgorithm> optimizationAlgorithm) :
options_(std::move(options)) {
PrimaryScopePipelineExecutor::PrimaryScopePipelineExecutor(RecalibrationOptions &&options,
std::unique_ptr<NoiseFilterAlgorithm> noiseFilterAlgorithm,
std::unique_ptr<StarCentroidAlgorithm> starCentroidAlgorithm,
std::unique_ptr<OptimizationAlgorithm> optimizationAlgorithm)
: options_(std::move(options)) {
// TODO: change inputs + outputs of stages to actual values we will use
std::unique_ptr<found::FunctionStage<Images, Image>> noiseFilterStage(std::move(noiseFilterAlgorithm));
std::unique_ptr<found::FunctionStage<Image, std::vector<float>>> starCentroidStage(
Expand Down
4 changes: 1 addition & 3 deletions src/scope/command-line/parsing/options.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,7 @@ SCOPE_CLI_OPTION("input-images", scope::Images, images, {}, scope::strtoimages(o
/** Parsed CLI options driving a recalibration run. */
class RecalibrationOptions {
public:
#define SCOPE_CLI_OPTION(name, type, prop, defaultVal, converter, defaultArg, \
ASSIGN, doc) \
type prop = defaultVal;
#define SCOPE_CLI_OPTION(name, type, prop, defaultVal, converter, defaultArg, ASSIGN, doc) type prop = defaultVal;
RECALIBRATE
#undef SCOPE_CLI_OPTION
};
Expand Down
46 changes: 21 additions & 25 deletions src/scope/command-line/parsing/parser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,17 @@

int optind = 2;

#define OPTIONAL_OPTARG() \
((optarg == NULL && optind < argc && argv[optind][0] != '-') \
? static_cast<bool>(optarg = argv[optind++]) \
: (optarg != NULL))
#define OPTIONAL_OPTARG() \
((optarg == NULL && optind < argc && argv[optind][0] != '-') ? static_cast<bool>(optarg = argv[optind++]) \
: (optarg != NULL))

#define REQ_ASSIGN(options, prop, value, default) options.prop = (value);

#define OPT_ASSIGN(options, prop, value, default) \
if (OPTIONAL_OPTARG()) { \
options.prop = value; \
} else { \
options.prop = default; \
#define OPT_ASSIGN(options, prop, value, default) \
if (OPTIONAL_OPTARG()) { \
options.prop = value; \
} else { \
options.prop = default; \
}

namespace scope {
Expand All @@ -31,19 +30,17 @@ RecalibrationOptions ParseRecalibrationOptions(int argc, char **argv) {
// Each block below re-expands RECALIBRATE to derive a piece of getopt
// wiring from the option table in options.hpp.
enum class ClientOption {
#define SCOPE_CLI_OPTION(name, type, prop, defaultVal, converter, defaultArg, \
ASSIGN, doc) \
prop,
#define SCOPE_CLI_OPTION(name, type, prop, defaultVal, converter, defaultArg, ASSIGN, doc) prop,
RECALIBRATE
#undef SCOPE_CLI_OPTION
};

static option long_options[] = {
#define SCOPE_CLI_OPTION(name, type, prop, defaultVal, converter, defaultArg, \
ASSIGN, doc) \
{name, \
defaultArg == kNoDefaultArgument ? required_argument : optional_argument, \
0, static_cast<int>(ClientOption::prop)},
#define SCOPE_CLI_OPTION(name, type, prop, defaultVal, converter, defaultArg, ASSIGN, doc) \
{name, \
defaultArg == kNoDefaultArgument ? required_argument : optional_argument, \
0, \
static_cast<int>(ClientOption::prop)},
RECALIBRATE
#undef SCOPE_CLI_OPTION
{0}};
Expand All @@ -54,17 +51,16 @@ RecalibrationOptions ParseRecalibrationOptions(int argc, char **argv) {

while ((option = getopt_long(argc, argv, "", long_options, &index)) != -1) {
switch (option) {
#define SCOPE_CLI_OPTION(name, type, prop, defaultVal, converter, defaultArg, \
ASSIGN, doc) \
case static_cast<int>(ClientOption::prop): \
ASSIGN(options, prop, converter, defaultArg) \
#define SCOPE_CLI_OPTION(name, type, prop, defaultVal, converter, defaultArg, ASSIGN, doc) \
case static_cast<int>(ClientOption::prop): \
ASSIGN(options, prop, converter, defaultArg) \
break;
RECALIBRATE
#undef SCOPE_CLI_OPTION
default:
LOG_ERROR("Illegal flag detected. " << HELP_MSG);
exit(EXIT_FAILURE);
break;
default:
LOG_ERROR("Illegal flag detected. " << HELP_MSG);
exit(EXIT_FAILURE);
break;
}
}

Expand Down
16 changes: 6 additions & 10 deletions src/scope/command-line/scope-main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,18 +15,15 @@ namespace scope {
namespace {

void PrintHelp() {
std::cout << "Usage: ./scope <option> [[flag value]...] [[flag=value]...]"
<< std::endl;
std::cout << "Usage: ./scope <option> [[flag value]...] [[flag=value]...]" << std::endl;
std::cout << std::endl;
std::cout << "Current capabilities:" << std::endl;
std::cout << "\tCalculates camera intrisic and distortion paramters."
<< std::endl;
std::cout << "\tCalculates camera intrisic and distortion paramters." << std::endl;
std::cout << std::endl;
std::cout << "==================== Calibration Flags ===================="
<< std::endl;
std::cout << "==================== Calibration Flags ====================" << std::endl;
std::cout << std::endl;
#define SCOPE_CLI_OPTION(name, type, prop, defaultVal, converter, defaultArg, ASSIGN, doc) \
std::cout << "\t--" << name << std::endl; \
#define SCOPE_CLI_OPTION(name, type, prop, defaultVal, converter, defaultArg, ASSIGN, doc) \
std::cout << "\t--" << name << std::endl; \
std::cout << "\t\t" << doc << std::endl;
RECALIBRATE
#undef SCOPE_CLI_OPTION
Expand All @@ -48,8 +45,7 @@ int main(int argc, char **argv) {
}

std::unique_ptr<found::PipelineExecutor> executor;
executor = CreatePrimaryScopePipelineExecutor(
ParseRecalibrationOptions(argc, argv));
executor = CreatePrimaryScopePipelineExecutor(ParseRecalibrationOptions(argc, argv));

executor->ExecutePipeline();
executor->OutputResults();
Expand Down
2 changes: 1 addition & 1 deletion src/scope/command-line/scope-main.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ namespace scope {
*
* @return 0 on success, non-zero on failure.
*/
int main(int argc, char** argv);
int main(int argc, char **argv);

} // namespace scope

Expand Down
4 changes: 3 additions & 1 deletion src/scope/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,6 @@
* successfully
*
*/
int main(int argc, char** argv) { return scope::main(argc, argv); }
int main(int argc, char **argv) {
return scope::main(argc, argv);
}
36 changes: 13 additions & 23 deletions src/scope/noise-filter/noise-filter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,48 +15,41 @@ namespace {
/// @param images Input images to validate.
/// @throws std::invalid_argument if the image collection is empty.
/// @throws std::runtime_error if any image is null or has mismatched dimensions.
void ValidateInput(const Images& images) {
void ValidateInput(const Images &images) {
if (images.empty()) {
throw std::invalid_argument(
"DarkScreenFilter requires at least one image");
throw std::invalid_argument("DarkScreenFilter requires at least one image");
}

const Image& reference = images.front();
const Image &reference = images.front();
if (reference.image == nullptr) {
throw std::runtime_error("Input image pointer is null");
}
if (reference.width <= 0 || reference.height <= 0 ||
reference.channels <= 0) {
throw std::runtime_error(
"Input image dimensions/channels must be positive");
if (reference.width <= 0 || reference.height <= 0 || reference.channels <= 0) {
throw std::runtime_error("Input image dimensions/channels must be positive");
}

for (size_t i = 1; i < images.size(); ++i) {
const Image& image = images[i];
const Image &image = images[i];
if (image.image == nullptr) {
throw std::runtime_error("Input image pointer is null");
}
if (image.width != reference.width ||
image.height != reference.height ||
if (image.width != reference.width || image.height != reference.height ||
image.channels != reference.channels) {
throw std::runtime_error(
"All images must share width, height, and channels");
throw std::runtime_error("All images must share width, height, and channels");
}
}
}

} // namespace

Image DarkScreenFilter::Run(const Images& images) {
Image DarkScreenFilter::Run(const Images &images) {
ValidateInput(images);

const Image& reference = images.front();
const size_t valueCount = static_cast<size_t>(reference.width) *
static_cast<size_t>(reference.height) *
const Image &reference = images.front();
const size_t valueCount = static_cast<size_t>(reference.width) * static_cast<size_t>(reference.height) *
static_cast<size_t>(reference.channels);

unsigned char* buffer =
static_cast<unsigned char*>(std::malloc(valueCount));
unsigned char *buffer = static_cast<unsigned char *>(std::malloc(valueCount));
if (buffer == nullptr) {
throw std::bad_alloc();
}
Expand All @@ -69,10 +62,7 @@ Image DarkScreenFilter::Run(const Images& images) {
samples[j] = images[j].image[i];
}

std::nth_element(
samples.begin(),
samples.begin() + static_cast<std::ptrdiff_t>(medianIndex),
samples.end());
std::nth_element(samples.begin(), samples.begin() + static_cast<std::ptrdiff_t>(medianIndex), samples.end());
buffer[i] = samples[medianIndex];
}

Expand Down
19 changes: 8 additions & 11 deletions src/scope/providers/factory.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,19 +18,16 @@ namespace scope {
* @return The assembled PrimaryScopePipelineExecutor.
*/
inline std::unique_ptr<PrimaryScopePipelineExecutor> CreatePrimaryScopePipelineExecutor(
RecalibrationOptions &&options) {
std::unique_ptr<NoiseFilterAlgorithm> noiseAlg = ProvideNoiseFilterAlgorithm(
std::forward<const RecalibrationOptions&&>(options));
std::unique_ptr<StarCentroidAlgorithm> starAlg = ProvideStarCentroidAlgorithm(
std::forward<const RecalibrationOptions&&>(options));
std::unique_ptr<OptimizationAlgorithm> optAlg = ProvideOptimizationAlgorithm(
std::forward<const RecalibrationOptions&&>(options));
RecalibrationOptions &&options) {
std::unique_ptr<NoiseFilterAlgorithm> noiseAlg =
ProvideNoiseFilterAlgorithm(std::forward<const RecalibrationOptions &&>(options));
std::unique_ptr<StarCentroidAlgorithm> starAlg =
ProvideStarCentroidAlgorithm(std::forward<const RecalibrationOptions &&>(options));
std::unique_ptr<OptimizationAlgorithm> optAlg =
ProvideOptimizationAlgorithm(std::forward<const RecalibrationOptions &&>(options));

return std::make_unique<PrimaryScopePipelineExecutor>(
std::move(options),
std::move(noiseAlg),
std::move(starAlg),
std::move(optAlg));
std::move(options), std::move(noiseAlg), std::move(starAlg), std::move(optAlg));
}

} // namespace scope
Expand Down
Loading