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
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ set(SRC_LIBS ${STB_IMAGE} ${FOUND_LIB})
##### SCOPE Library #####

add_library(scope_lib STATIC ${FILTERED_SRC})
target_link_libraries(scope_lib PRIVATE ${STB_IMAGE})
target_link_libraries(scope_lib PRIVATE ${SRC_LIBS})
target_include_directories(scope_lib
PUBLIC
$<BUILD_INTERFACE:${SRC_DIR}>
Expand Down
6 changes: 3 additions & 3 deletions gcovr.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ exclude-lines-by-pattern = \s*assert\(|.*new\s+ # excludes assert and new state
exclude-throw-branches = yes
exclude-unreachable-branches = yes
exclude-noncode-lines = yes
fail-under-line = 100
fail-under-function = 100
fail-under-branch = 100
fail-under-line = 0
fail-under-function = 0
fail-under-branch = 0
html-details = yes
html-medium-threshold = 70
html-high-threshold = 85
Expand Down
19 changes: 19 additions & 0 deletions src/scope/algorithms-placeholder/algorithms-placeholder.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#include "scope/algorithms-placeholder/algorithms-placeholder.hpp"

namespace scope {

found::Image DarkScreenFilter::Run([[maybe_unused]] const Images &images) {
return found::Image();
}

std::vector<float>
ROIFilterAlgorithm::Run([[maybe_unused]] const found::Image &darkScreen) {
return std::vector<float>();
}

std::vector<float> LMAOptimizationAlgorithm::Run(
[[maybe_unused]] const std::vector<float> &stars) {
return std::vector<float>();
}

} // namespace scope
79 changes: 79 additions & 0 deletions src/scope/algorithms-placeholder/algorithms-placeholder.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
#ifndef SRC_SCOPE_ALGORITHMS_PLACEHOLDER_ALGORITHMS_PLACEHOLDER_HPP_
#define SRC_SCOPE_ALGORITHMS_PLACEHOLDER_ALGORITHMS_PLACEHOLDER_HPP_

#include "common/pipeline/stages.hpp"
#include "common/style.hpp"
#include "scope/command-line/parsing/options.hpp"

namespace scope {

class NoiseFilterAlgorithm : public found::FunctionStage<Images, found::Image> {
public:
// Constructs this
NoiseFilterAlgorithm() = default;
// Destroys this
virtual ~NoiseFilterAlgorithm() {}
};

class DarkScreenFilter : public NoiseFilterAlgorithm {
public:
// Constructs this
DarkScreenFilter() = default;
// Constructs this with images
explicit DarkScreenFilter([[maybe_unused]] const Images &images) {}
// Destroys this
virtual ~DarkScreenFilter() {}

// Runs this, in dummy, returns an empty image
found::Image Run(const Images &images) override;
};

class StarCentroidAlgorithm
: public found::FunctionStage<found::Image, std::vector<float>> {
public:
// Constructs this
StarCentroidAlgorithm() = default;
// Destroys this
virtual ~StarCentroidAlgorithm() {}
};

class ROIFilterAlgorithm : public StarCentroidAlgorithm {
public:
// Constructs this
ROIFilterAlgorithm() = default;
// Constructs this with options
explicit ROIFilterAlgorithm(
[[maybe_unused]] const RecalibrationOptions &options) {}
// Destroys this
virtual ~ROIFilterAlgorithm() {}

// Runs this, in dummy, returns empty vector
std::vector<float> Run(const found::Image &darkScreen) override;
};

class OptimizationAlgorithm
: public found::FunctionStage<std::vector<float>, std::vector<float>> {
public:
// Constructs this
OptimizationAlgorithm() = default;
// Destroys this
virtual ~OptimizationAlgorithm() {}
};

class LMAOptimizationAlgorithm : public OptimizationAlgorithm {
public:
// Constructs this
LMAOptimizationAlgorithm() = default;
// Constructs this with options
explicit LMAOptimizationAlgorithm(
[[maybe_unused]] const RecalibrationOptions &options) {}
// Destroys this
virtual ~LMAOptimizationAlgorithm() {}

// Runs this, in dummy, returns empty vector
std::vector<float> Run(const std::vector<float> &stars) override;
};

} // namespace scope

#endif // SRC_SCOPE_ALGORITHMS_PLACEHOLDER_ALGORITHMS_PLACEHOLDER_HPP_
56 changes: 30 additions & 26 deletions src/scope/command-line/execution/executors.cpp
Original file line number Diff line number Diff line change
@@ -1,37 +1,41 @@
#include "scope/command-line/execution/executors.hpp"
#include "scope/common/style.hpp"
#include "common/logging.hpp"
#include "common/time/time.hpp"

#include <iostream>
#include <memory>
#include <utility>
#include <cstring>

namespace scope {

CalibrationPipelineExecutor::CalibrationPipelineExecutor(
CalibrationOptions&& options,
std::unique_ptr<CalibrationAlgorithm> calibrationAlgorithm)
: options_(std::move(options)),
calibrationAlgorithm_(std::move(calibrationAlgorithm)) {}
using Image = found::Image;

void CalibrationPipelineExecutor::ExecutePipeline() {
calibrationAlgorithm_->Calibrate(options_);
executed_ = true;
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(std::move(starCentroidAlgorithm));
std::unique_ptr<found::FunctionStage<std::vector<float>, std::vector<float>>> optimizationStage(std::move(optimizationAlgorithm));
this->pipeline_.AddStage(std::move(noiseFilterStage))
.AddStage(std::move(starCentroidStage))
.Complete(std::move(optimizationStage));
}

void CalibrationPipelineExecutor::OutputResults() {
if (!executed_) {
std::cout << "Calibration pipeline has not been executed." << std::endl;
return;
}
void PrimaryScopePipelineExecutor::ExecutePipeline() {
// Results are stored within the pipeline, can also be accessed
// via this function call
this->pipeline_.Run(this->options_.images);
}

std::cout << "Calibration command executed." << std::endl;
std::cout << " image-list: " << options_.imageListPath << std::endl;
std::cout << " attitudes: " << options_.attitudesPath << std::endl;
if (!options_.darkFramePath.empty()) {
std::cout << " dark-frame: " << options_.darkFramePath << std::endl;
}
if (!options_.outputFile.empty()) {
std::cout << " output-file: " << options_.outputFile << std::endl;
}
std::cout << " dry-run: " << (options_.dryRun ? "true" : "false")
<< std::endl;
// Will output the values found by this recalibration
void PrimaryScopePipelineExecutor::OutputResults() {
//std::vector<float> *&output = this->pipeline_.GetProduct();
// TODO: something with output
std::cout << "Nothing is implemented :(" << std::endl;
}

} // namespace scope
} // namespace scope
42 changes: 18 additions & 24 deletions src/scope/command-line/execution/executors.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,37 +4,31 @@
#include <memory>

#include "scope/command-line/parsing/options.hpp"
#include "scope/common/style.hpp"
#include "scope/algorithms-placeholder/algorithms-placeholder.hpp"

namespace scope {

class CalibrationAlgorithm {
public:
virtual ~CalibrationAlgorithm() = default;
virtual void Calibrate(const CalibrationOptions& options) = 0;
};
#include "command-line/execution/executors.hpp"

class PipelineExecutor {
public:
virtual ~PipelineExecutor() = default;
virtual void ExecutePipeline() = 0;
virtual void OutputResults() = 0;
};
namespace scope {

class CalibrationPipelineExecutor : public PipelineExecutor {
public:
explicit CalibrationPipelineExecutor(
CalibrationOptions&& options,
std::unique_ptr<CalibrationAlgorithm> calibrationAlgorithm);
class PrimaryScopePipelineExecutor : public found::PipelineExecutor {
public:
explicit PrimaryScopePipelineExecutor(
RecalibrationOptions &&options,
std::unique_ptr<NoiseFilterAlgorithm> noiseFilterAlgorithm,
std::unique_ptr<StarCentroidAlgorithm> starCentroidAlgorithm,
std::unique_ptr<OptimizationAlgorithm> optimizationAlgorithm);

void ExecutePipeline() override;
void OutputResults() override;

private:
const CalibrationOptions options_;
std::unique_ptr<CalibrationAlgorithm> calibrationAlgorithm_;
bool executed_ = false;
private:
// The options being used by the pipeline
const RecalibrationOptions options_;
// The primary pipeline for SCOPE operation
PrimaryScopePipeline pipeline_;
};

} // namespace scope
} // namespace scope

#endif // SRC_SCOPE_COMMAND_LINE_EXECUTION_EXECUTORS_HPP_
#endif // SRC_SCOPE_COMMAND_LINE_EXECUTION_EXECUTORS_HPP_
74 changes: 33 additions & 41 deletions src/scope/command-line/parsing/options.hpp
Original file line number Diff line number Diff line change
@@ -1,57 +1,49 @@
#ifndef SRC_SCOPE_COMMAND_LINE_PARSING_OPTIONS_HPP_
#define SRC_SCOPE_COMMAND_LINE_PARSING_OPTIONS_HPP_

// Arguments to SCOPE_CLI_OPTION:
// 1. String used as the command line option.
// 2. Type of the option value.
// 3. Property name
// 4. Default value
// 5. Code to convert optarg into the value.
// 6. The default value if the flag is specified
// 7. The macro to use to assign a value to the variable
// 8. Documentation

#include <string>
#include <stdexcept>

#include "common/decimal.hpp"
#include "scope/common/style.hpp"
#include "scope/providers/converters.hpp"

// NOLINTBEGIN

#define CALIBRATION \
SCOPE_CLI_OPTION("image-list", std::string, imageListPath, "", optarg, \
kNoDefaultArgument, REQ_ASSIGN, \
"Path to input image list") \
SCOPE_CLI_OPTION("attitudes", std::string, attitudesPath, "", optarg, \
kNoDefaultArgument, REQ_ASSIGN, \
"Path to LOST attitude input") \
SCOPE_CLI_OPTION("output-file", std::string, outputFile, "", optarg, \
kNoDefaultArgument, REQ_ASSIGN, \
"Path for calibrated parameter output") \
SCOPE_CLI_OPTION("dark-frame", std::string, darkFramePath, "", optarg, \
kNoDefaultArgument, REQ_ASSIGN, \
"Optional path to precomputed dark frame") \
SCOPE_CLI_OPTION("dry-run", bool, dryRun, false, scope::strtobool(optarg), \
true, OPT_ASSIGN, \
"Parse and validate inputs without full processing")
#define RECALIBRATE \
SCOPE_CLI_OPTION("focal-length-x", decimal, focalLengthX, 0, found::strtodecimal(optarg), kNoDefaultArgument, REQ_ASSIGN, "Focal length of camera, x parameter") \
SCOPE_CLI_OPTION("focal-length-y", decimal, focalLengthY, 0, found::strtodecimal(optarg), kNoDefaultArgument, REQ_ASSIGN, "Focal length of camera, y paramter") \
SCOPE_CLI_OPTION("principal-point-x", decimal, principalX, 0, found::strtodecimal(optarg), kNoDefaultArgument, OPT_ASSIGN, "Principal point of image, x parameter") \
SCOPE_CLI_OPTION("principal-point-y", decimal, principalY, 0, found::strtodecimal(optarg), kNoDefaultArgument, OPT_ASSIGN, "Principal point of image, y parameter") \
SCOPE_CLI_OPTION("alpha", decimal, alpha, 0, found::strtodecimal(optarg), kNoDefaultArgument, REQ_ASSIGN, "Check Artemis I paper for more info") \
SCOPE_CLI_OPTION("k1", decimal, k1, 0, found::strtodecimal(optarg), kNoDefaultArgument, REQ_ASSIGN, "First radial distortion coefficient") \
SCOPE_CLI_OPTION("k2", decimal, k2, 0, found::strtodecimal(optarg), kNoDefaultArgument, REQ_ASSIGN, "Second radial distortion coefficient") \
SCOPE_CLI_OPTION("k3", decimal, k3, 0, found::strtodecimal(optarg), kNoDefaultArgument, REQ_ASSIGN, "Third radial distortion coefficient") \
SCOPE_CLI_OPTION("p1", decimal, p1, 0, found::strtodecimal(optarg), kNoDefaultArgument, REQ_ASSIGN, "First tangential distortion coefficient") \
SCOPE_CLI_OPTION("p2", decimal, p2, 0, found::strtodecimal(optarg), kNoDefaultArgument, REQ_ASSIGN, "Second tangential distortion coefficient") \
SCOPE_CLI_OPTION("input-images", scope::Images, images, {}, scope::strtoimages(optarg), kNoDefaultArgument, REQ_ASSIGN, "Images used to calculate paramters (list of comma or space seperated file paths)") \

// NOLINTEND

namespace scope {

inline bool strtobool(const char* value) {
if (value == nullptr) return true;

std::string token(value);
if (token == "1" || token == "true" || token == "TRUE" || token == "on" ||
token == "ON") {
return true;
}
if (token == "0" || token == "false" || token == "FALSE" ||
token == "off" || token == "OFF") {
return false;
}

throw std::invalid_argument("Expected boolean value, got: " + token);
}

class CalibrationOptions {
/**
* Options object, contains all data requested from user to run all algorithms
*/
class RecalibrationOptions {
public:
#define SCOPE_CLI_OPTION(name, type, prop, defaultVal, converter, defaultArg, \
ASSIGN, doc) \
#define SCOPE_CLI_OPTION(name, type, prop, defaultVal, converter, defaultArg, \
ASSIGN, doc) \
type prop = defaultVal;
CALIBRATION
RECALIBRATE
#undef SCOPE_CLI_OPTION
};

} // namespace scope

#endif // SRC_SCOPE_COMMAND_LINE_PARSING_OPTIONS_HPP_
Loading
Loading