Skip to content
Snippets Groups Projects
Commit 80ee81d1 authored by Nicolas Pope's avatar Nicolas Pope
Browse files

Resolves #36 and most of #59

parent 781500c2
No related branches found
No related tags found
No related merge requests found
Showing
with 208 additions and 130 deletions
......@@ -20,7 +20,7 @@
#include "src_window.hpp"
using std::string;
using ftl::rgbd::RGBDSource;
using ftl::rgbd::Source;
/*struct SourceViews {
ftl::rgbd::RGBDSource *source;
......
......@@ -9,11 +9,11 @@
#include <nanogui/layout.h>
#ifdef HAVE_LIBARCHIVE
#include "ftl/snapshot.hpp"
#include "ftl/rgbd/snapshot.hpp"
#endif
using ftl::gui::SourceWindow;
using ftl::rgbd::RGBDSource;
using ftl::rgbd::Source;
using std::string;
class GLTexture {
......@@ -84,7 +84,7 @@ class VirtualCameraView : public nanogui::ImageView {
depth_ = false;
}
void setSource(RGBDSource *src) { src_ = src; }
void setSource(Source *src) { src_ = src; }
bool mouseButtonEvent(const nanogui::Vector2i &p, int button, bool down, int modifiers) {
//LOG(INFO) << "Mouse move: " << p[0];
......@@ -118,7 +118,7 @@ class VirtualCameraView : public nanogui::ImageView {
src_->setPose(viewPose);
src_->grab();
src_->getRGBD(rgb, depth);
src_->getFrames(rgb, depth);
if (depth_) {
if (depth.rows > 0) {
......@@ -143,7 +143,7 @@ class VirtualCameraView : public nanogui::ImageView {
void setDepth(bool d) { depth_ = d; }
private:
RGBDSource *src_;
Source *src_;
GLTexture texture_;
Eigen::Vector3f eye_;
Eigen::Vector3f centre_;
......@@ -159,7 +159,7 @@ SourceWindow::SourceWindow(nanogui::Widget *parent, ftl::ctrl::Master *ctrl)
using namespace nanogui;
src_ = ftl::create<ftl::rgbd::NetSource>(ctrl->getRoot(), "source", ctrl->getNet());
src_ = ftl::create<Source>(ctrl->getRoot(), "source", ctrl->getNet());
Widget *tools = new Widget(this);
tools->setLayout(new BoxLayout(Orientation::Horizontal,
......@@ -193,13 +193,13 @@ SourceWindow::SourceWindow(nanogui::Widget *parent, ftl::ctrl::Master *ctrl)
std::strftime(timestamp, sizeof(timestamp), "%F-%H%M%S", std::localtime(&t));
auto writer = ftl::rgbd::SnapshotWriter(std::string(timestamp) + ".tar.gz");
cv::Mat rgb, depth;
this->src_->getRGBD(rgb, depth);
this->src_->getFrames(rgb, depth);
if (!writer.addCameraRGBD(
"0", // TODO
rgb,
depth,
this->src_->getPose(),
this->src_->getParameters()
this->src_->parameters()
)) {
LOG(ERROR) << "Snapshot failed";
}
......
......@@ -4,7 +4,7 @@
#include <nanogui/window.h>
#include <ftl/master.hpp>
#include <ftl/uuid.hpp>
#include <ftl/net_source.hpp>
#include <ftl/rgbd/source.hpp>
#include <vector>
#include <string>
......@@ -23,7 +23,7 @@ class SourceWindow : public nanogui::Window {
private:
ftl::ctrl::Master *ctrl_;
ftl::rgbd::NetSource *src_;
ftl::rgbd::Source *src_;
VirtualCameraView *image_;
std::vector<std::string> available_;
......
......@@ -6,7 +6,7 @@
#include <cuda_runtime.h>
#include <ftl/cuda_matrix_util.hpp>
#include <ftl/camera_params.hpp>
#include <ftl/rgbd/camera.hpp>
struct __align__(16) DepthCameraParams {
float fx;
......
......@@ -28,12 +28,12 @@ Eigen::Matrix4f findTransformation( std::vector<pcl::PointCloud<pcl::PointXYZ>::
/** @brief Convert chessboard corners found with OpenCV's findChessboardCorners to PCL point cloud. */
pcl::PointCloud<pcl::PointXYZ>::Ptr cornersToPointCloud(const std::vector<cv::Point2f> &corners, const cv::Mat &disp, const ftl::rgbd::CameraParameters &p);
pcl::PointCloud<pcl::PointXYZ>::Ptr cornersToPointCloud(const std::vector<cv::Point2f> &corners, const cv::Mat &disp, const ftl::rgbd::Camera &p);
/** @brief Find chessboard corners from image and store them in PCL PointCloud.
* @note Corners will be drawn in rgb.
*/
bool findChessboardCorners(cv::Mat &rgb, const cv::Mat &depth, const ftl::rgbd::CameraParameters &p, const cv::Size pattern_size, pcl::PointCloud<pcl::PointXYZ>::Ptr &out, float error_threshold);
bool findChessboardCorners(cv::Mat &rgb, const cv::Mat &depth, const ftl::rgbd::Camera &p, const cv::Size pattern_size, pcl::PointCloud<pcl::PointXYZ>::Ptr &out, float error_threshold);
/**
* @brief Abstract class for registration
......@@ -45,7 +45,7 @@ bool findChessboardCorners(cv::Mat &rgb, const cv::Mat &depth, const ftl::rgbd::
class Registration : public ftl::Configurable {
public:
explicit Registration(nlohmann::json &config);
void addSource(ftl::rgbd::RGBDSource* source);
void addSource(ftl::rgbd::Source* source);
size_t getSourcesCount() { return sources_.size(); }
/**
......@@ -75,11 +75,11 @@ public:
virtual bool findTransformations(std::map<std::string, Eigen::Matrix4f> &data);
protected:
ftl::rgbd::RGBDSource* getSource(size_t idx);
ftl::rgbd::Source* getSource(size_t idx);
bool isTargetSourceSet();
bool isTargetSourceFound();
bool isTargetSource(ftl::rgbd::RGBDSource* source);
bool isTargetSource(ftl::rgbd::Source* source);
bool isTargetSource(size_t idx);
/**
......@@ -124,13 +124,13 @@ protected:
* always have same idx. Implementations may choose to ignore it.
* @return True/false if feature was found. Used to build adjacency matrix.
*/
virtual bool findFeatures(ftl::rgbd::RGBDSource* source, size_t idx)=0;
virtual bool findFeatures(ftl::rgbd::Source* source, size_t idx)=0;
std::vector<std::vector<bool>> visibility_; /*< Adjacency matrix for sources (feature visibility). */
private:
std::optional<std::string> target_source_; /*< Reference coordinate system for transformations. */
std::vector<ftl::rgbd::RGBDSource*> sources_;
std::vector<ftl::rgbd::Source*> sources_;
};
/**
......@@ -173,7 +173,7 @@ public:
bool findTransformations(std::vector<Eigen::Matrix4f> &data) override;
protected:
bool findFeatures(ftl::rgbd::RGBDSource* source, size_t idx) override;
bool findFeatures(ftl::rgbd::Source* source, size_t idx) override;
bool processData() override;
cv::Size pattern_size_;
std::vector<std::vector<std::optional<pcl::PointCloud<pcl::PointXYZ>::Ptr>>> data_;
......
......@@ -337,7 +337,7 @@ private:
//t.startEvent("compactifyAllInOne");
m_hashParams.m_numOccupiedBlocks = compactifyHashAllInOneCUDA(m_hashData, m_hashParams); //this version uses atomics over prefix sums, which has a much better performance
//std::cout << "Occ blocks = " << m_hashParams.m_numOccupiedBlocks << std::endl;
std::cout << "Occ blocks = " << m_hashParams.m_numOccupiedBlocks << std::endl;
m_hashData.updateParams(m_hashParams); //make sure numOccupiedBlocks is updated on the GPU
//t.endEvent();
//t.evaluate();
......
......@@ -2,7 +2,7 @@
#ifndef _FTL_RGBD_VIRTUAL_HPP_
#define _FTL_RGBD_VIRTUAL_HPP_
#include <ftl/rgbd_source.hpp>
#include <ftl/rgbd/source.hpp>
class CUDARayCastSDF;
......@@ -19,21 +19,17 @@ namespace rgbd {
* calculating disparity, before converting to depth. Calibration of the images
* is also performed.
*/
class VirtualSource : public RGBDSource {
class VirtualSource : public ftl::rgbd::detail::Source {
public:
VirtualSource(nlohmann::json &config, ftl::net::Universe *net);
VirtualSource(ftl::rgbd::Source*);
~VirtualSource();
void setScene(ftl::voxhash::SceneRep *);
void grab();
void getRGBD(cv::Mat &rgb, cv::Mat &depth);
bool grab();
//void getRGBD(cv::Mat &rgb, cv::Mat &depth);
bool isReady();
static inline RGBDSource *create(nlohmann::json &config, ftl::net::Universe *net) {
return new VirtualSource(config, net);
}
private:
ftl::voxhash::SceneRep *scene_;
CUDARayCastSDF *rays_;
......
......@@ -12,7 +12,7 @@
#include <ftl/scene_rep_hash_sdf.hpp>
#include <ftl/rgbd.hpp>
#include <ftl/virtual_source.hpp>
#include <ftl/rgbd_streamer.hpp>
#include <ftl/rgbd/streamer.hpp>
// #include <zlib.h>
// #include <lz4.h>
......@@ -50,7 +50,7 @@ using ftl::net::Universe;
using ftl::rgbd::Display;
using std::string;
using std::vector;
using ftl::rgbd::RGBDSource;
using ftl::rgbd::Source;
using ftl::config::json_t;
using json = nlohmann::json;
......@@ -67,7 +67,7 @@ using ftl::registration::loadTransformations;
using ftl::registration::saveTransformations;
struct Cameras {
RGBDSource *source;
Source *source;
DepthCameraData gpu;
DepthCameraParams params;
};
......@@ -76,36 +76,21 @@ static void run(ftl::Configurable *root) {
Universe *net = ftl::create<Universe>(root, "net");
net->start();
net->waitConnections();
//net->waitConnections();
std::vector<Cameras> inputs;
auto sources = root->get<vector<json_t>>("sources");
auto sources = ftl::createArray<Source>(root, "sources", net); //root->get<vector<json_t>>("sources");
if (!sources) {
if (sources.size() == 0) {
LOG(ERROR) << "No sources configured!";
return;
}
// TODO Allow for non-net source types
for (auto &src : *sources) {
RGBDSource *in = ftl::rgbd::RGBDSource::create(src, net);
if (!in) {
LOG(ERROR) << "Unrecognized source: " << src;
} else {
auto &cam = inputs.emplace_back();
cam.source = in;
cam.params.fx = in->getParameters().fx;
cam.params.fy = in->getParameters().fy;
cam.params.mx = -in->getParameters().cx;
cam.params.my = -in->getParameters().cy;
cam.params.m_imageWidth = in->getParameters().width;
cam.params.m_imageHeight = in->getParameters().height;
cam.params.m_sensorDepthWorldMax = in->getParameters().maxDepth;
cam.params.m_sensorDepthWorldMin = in->getParameters().minDepth;
cam.gpu.alloc(cam.params);
LOG(INFO) << (string) src["uri"] << " loaded " << cam.params.fx;
}
for (int i=0; i<sources.size(); i++) {
Source *in = sources[i];
auto &cam = inputs.emplace_back();
cam.source = in;
cam.params.m_imageWidth = 0;
}
// TODO move this block in its own method and add automated tests
......@@ -115,6 +100,7 @@ static void run(ftl::Configurable *root) {
if (!merge) {
LOG(WARNING) << "Input merging not configured, using only first input in configuration";
inputs = { inputs[0] };
inputs[0].source->setPose(Eigen::Matrix4f::Identity());
}
if (inputs.size() > 1) {
......@@ -171,9 +157,13 @@ static void run(ftl::Configurable *root) {
for (auto &input : inputs) { LOG(INFO) << " " + (string) input.source->getURI(); }
ftl::rgbd::Display *display = ftl::create<ftl::rgbd::Display>(root, "display");
ftl::rgbd::VirtualSource *virt = ftl::create<ftl::rgbd::VirtualSource>(root, "virtual", net);
ftl::rgbd::Source *virt = ftl::create<ftl::rgbd::Source>(root, "virtual", net);
auto virtimpl = new ftl::rgbd::VirtualSource(virt);
virt->customImplementation(virtimpl);
ftl::voxhash::SceneRep *scene = ftl::create<ftl::voxhash::SceneRep>(root, "voxelhash");
virt->setScene(scene);
virtimpl->setScene(scene);
display->setSource(virt);
ftl::rgbd::Streamer *stream = ftl::create<ftl::rgbd::Streamer>(root, "stream", net);
......@@ -192,7 +182,12 @@ static void run(ftl::Configurable *root) {
});
int active = inputs.size();
while (active > 0 && display->active()) {
while (ftl::running && display->active()) {
if (active == 0) {
LOG(INFO) << "Waiting for sources...";
sleep_for(milliseconds(1000));
}
active = 0;
if (!paused) {
......@@ -200,11 +195,34 @@ static void run(ftl::Configurable *root) {
scene->nextFrame();
for (size_t i = 0; i < inputs.size(); i++) {
if (!inputs[i].source->isReady()) {
inputs[i].params.m_imageWidth = 0;
// TODO(Nick) : Free gpu allocs if was ready before
continue;
} else {
auto &cam = inputs[i];
auto in = inputs[i].source;
if (cam.params.m_imageWidth == 0) {
LOG(INFO) << "SETTING UP CAM PARAMS: " << in->parameters().fx;
cam.params.fx = in->parameters().fx;
cam.params.fy = in->parameters().fy;
cam.params.mx = -in->parameters().cx;
cam.params.my = -in->parameters().cy;
cam.params.m_imageWidth = in->parameters().width;
cam.params.m_imageHeight = in->parameters().height;
cam.params.m_sensorDepthWorldMax = in->parameters().maxDepth;
cam.params.m_sensorDepthWorldMin = in->parameters().minDepth;
cam.gpu.alloc(cam.params);
}
//LOG(INFO) << in->getURI() << " loaded " << cam.params.fx;
}
// Get the RGB-Depth frame from input
RGBDSource *input = inputs[i].source;
Source *input = inputs[i].source;
Mat rgb, depth;
input->grab();
input->getRGBD(rgb,depth);
input->getFrames(rgb,depth);
active += 1;
......
......@@ -25,8 +25,8 @@
namespace ftl {
namespace registration {
using ftl::rgbd::CameraParameters;
using ftl::rgbd::RGBDSource;
using ftl::rgbd::Camera;
using ftl::rgbd::Source;
using std::string;
using std::vector;
......@@ -132,7 +132,7 @@ float fitPlaneError(PointCloud<PointXYZ>::Ptr cloud_in, float distance_threshold
}
//template<typename T = PointXYZ> typename
PointCloud<PointXYZ>::Ptr cornersToPointCloud(const vector<cv::Point2f> &corners, const Mat &depth, const CameraParameters &p) {
PointCloud<PointXYZ>::Ptr cornersToPointCloud(const vector<cv::Point2f> &corners, const Mat &depth, const Camera &p) {
int corners_len = corners.size();
vector<cv::Vec3f> points(corners_len);
......@@ -170,7 +170,7 @@ PointCloud<PointXYZ>::Ptr cornersToPointCloud(const vector<cv::Point2f> &corners
return cloud;
}
bool findChessboardCorners(Mat &rgb, const Mat &depth, const CameraParameters &p, const cv::Size pattern_size, PointCloud<PointXYZ>::Ptr &out, float error_threshold) {
bool findChessboardCorners(Mat &rgb, const Mat &depth, const Camera &p, const cv::Size pattern_size, PointCloud<PointXYZ>::Ptr &out, float error_threshold) {
vector<cv::Point2f> corners(pattern_size.width * pattern_size.height);
#if CV_VERSION_MAJOR >= 4
......@@ -257,7 +257,7 @@ Registration::Registration(nlohmann::json &config) :
}
}
RGBDSource* Registration::getSource(size_t idx) {
Source* Registration::getSource(size_t idx) {
return sources_[idx];
}
......@@ -266,14 +266,14 @@ bool Registration::isTargetSourceSet() {
}
bool Registration::isTargetSourceFound() {
for (RGBDSource* source : sources_ ) {
for (Source* source : sources_ ) {
if (isTargetSource(source)) return true;
}
return false;
}
bool Registration::isTargetSource(RGBDSource *source) {
if (target_source_) { return source->getURI() == *target_source_; }
bool Registration::isTargetSource(Source *source) {
if (target_source_) { return source->getID() == *target_source_; }
return false;
}
......@@ -291,7 +291,7 @@ size_t Registration::getTargetSourceIdx() {
return 0;
}
void Registration::addSource(RGBDSource *source) {
void Registration::addSource(Source *source) {
// TODO: check that source is not already included
sources_.push_back(source);
}
......@@ -390,7 +390,7 @@ bool Registration::findTransformations(map<string, Matrix4f> &data) {
if (!findTransformations(T)) return false;
for (size_t i = 0; i < sources_.size(); ++i) {
data[sources_[i]->getURI()] = T[i];
data[sources_[i]->getID()] = T[i];
}
return true;
}
......@@ -438,31 +438,31 @@ void ChessboardRegistration::run() {
// TODO: Move GUI elsewhere. Also applies to processData() and findFeatures()
for (size_t i = 0; i < getSourcesCount(); ++i) {
cv::namedWindow("Registration: " + getSource(i)->getURI(),
cv::namedWindow("Registration: " + getSource(i)->getID(),
cv::WINDOW_KEEPRATIO|cv::WINDOW_NORMAL);
}
Registration::run();
for (size_t i = 0; i < getSourcesCount(); ++i) {
cv::destroyWindow("Registration: " + getSource(i)->getURI());
cv::destroyWindow("Registration: " + getSource(i)->getID());
}
}
bool ChessboardRegistration::findFeatures(RGBDSource *source, size_t idx) {
bool ChessboardRegistration::findFeatures(Source *source, size_t idx) {
optional<PointCloud<PointXYZ>::Ptr> result;
PointCloud<PointXYZ>::Ptr cloud(new PointCloud<PointXYZ>);
Mat rgb, depth;
source->getRGBD(rgb, depth);
source->getFrames(rgb, depth);
bool retval = findChessboardCorners(rgb, depth, source->getParameters(), pattern_size_, cloud, error_threshold_);
bool retval = findChessboardCorners(rgb, depth, source->parameters(), pattern_size_, cloud, error_threshold_);
if (retval) {
result.emplace(cloud);
}
data_[idx].push_back(result);
cv::imshow("Registration: " + source->getURI(), rgb);
cv::imshow("Registration: " + source->getID(), rgb);
return retval;
}
......@@ -546,11 +546,11 @@ bool ChessboardRegistrationChain::findTransformations(vector<Matrix4f> &data) {
for (vector<pair<size_t, size_t>> level : edges_) {
for (pair<size_t, size_t> edge : level) {
LOG(INFO) << "Registering source "
<< getSource(edge.second)->getURI() << " to source"
<< getSource(edge.first)->getURI();
<< getSource(edge.second)->getID() << " to source"
<< getSource(edge.first)->getID();
nlohmann::json conf(config_);
conf["targetsource"] = getSource(edge.first)->getURI();
conf["targetsource"] = getSource(edge.first)->getID();
conf["chain"] = false;
vector<Matrix4f> result;
......
......@@ -10,19 +10,19 @@ using ftl::rgbd::VirtualSource;
using std::mutex;
using std::unique_lock;
VirtualSource::VirtualSource(nlohmann::json &config, ftl::net::Universe *net)
: RGBDSource(config, net) {
rays_ = new CUDARayCastSDF(config);
VirtualSource::VirtualSource(ftl::rgbd::Source *host)
: ftl::rgbd::detail::Source(host) {
rays_ = ftl::create<CUDARayCastSDF>(host, "raycaster"); //new CUDARayCastSDF(host->getConfig());
scene_ = nullptr;
params_.fx = config.value("focal", 430.0f);
params_.fx = rays_->value("focal", 430.0f);
params_.fy = params_.fx;
params_.width = config.value("width", 640);
params_.height = config.value("height", 480);
params_.width = rays_->value("width", 640);
params_.height = rays_->value("height", 480);
params_.cx = params_.width / 2;
params_.cy = params_.height / 2;
params_.maxDepth = config.value("max_depth", 10.0f);
params_.minDepth = config.value("min_depth", 0.1f);
params_.maxDepth = rays_->value("max_depth", 10.0f);
params_.minDepth = rays_->value("min_depth", 0.1f);
rgb_ = cv::Mat(cv::Size(params_.width,params_.height), CV_8UC3);
idepth_ = cv::Mat(cv::Size(params_.width,params_.height), CV_32SC1);
......@@ -37,7 +37,7 @@ void VirtualSource::setScene(ftl::voxhash::SceneRep *scene) {
scene_ = scene;
}
void VirtualSource::grab() {
bool VirtualSource::grab() {
if (scene_) {
DepthCameraParams params;
params.fx = params_.fx;
......@@ -49,12 +49,13 @@ void VirtualSource::grab() {
params.m_sensorDepthWorldMin = params_.minDepth;
params.m_sensorDepthWorldMax = params_.maxDepth;
rays_->render(scene_->getHashData(), scene_->getHashParams(), params, getPose());
rays_->render(scene_->getHashData(), scene_->getHashParams(), params, host_->getPose());
unique_lock<mutex> lk(mutex_);
//unique_lock<mutex> lk(mutex_);
rays_->getRayCastData().download((int*)idepth_.data, (uchar3*)rgb_.data, rays_->getRayCastParams());
idepth_.convertTo(depth_, CV_32FC1, 1.0f / 100.0f);
}
return true;
}
bool VirtualSource::isReady() {
......
......@@ -22,7 +22,7 @@
#include <ftl/rgbd.hpp>
#include <ftl/middlebury.hpp>
#include <ftl/display.hpp>
#include <ftl/rgbd_streamer.hpp>
#include <ftl/rgbd/streamer.hpp>
#include <ftl/net/universe.hpp>
#include <ftl/slave.hpp>
#include <nlohmann/json.hpp>
......@@ -36,9 +36,8 @@
#pragma comment(lib, "Rpcrt4.lib")
#endif
using ftl::rgbd::RGBDSource;
using ftl::rgbd::CameraParameters;
using ftl::rgbd::StereoVideoSource;
using ftl::rgbd::Source;
using ftl::rgbd::Camera;
using ftl::Display;
using ftl::rgbd::Streamer;
using ftl::net::Universe;
......@@ -87,8 +86,10 @@ static void run(ftl::Configurable *root) {
string file = "";
if (paths && (*paths).size() > 0) file = (*paths)[0];
StereoVideoSource *source = nullptr;
source = ftl::create<StereoVideoSource>(root, "source", file);
Source *source = nullptr;
source = ftl::create<Source>(root, "source");
if (file != "") source->set("uri", file);
Display *display = ftl::create<Display>(root, "display", "local");
......@@ -101,8 +102,8 @@ static void run(ftl::Configurable *root) {
while (ftl::running && display->active()) {
cv::Mat rgb, depth;
source->getRGBD(rgb, depth);
if (!rgb.empty()) display->render(rgb, depth, source->getParameters());
source->getFrames(rgb, depth);
if (!rgb.empty()) display->render(rgb, depth, source->parameters());
display->wait(10);
}
......@@ -113,7 +114,7 @@ static void run(ftl::Configurable *root) {
delete stream;
delete display;
delete source;
//delete source; // TODO(Nick) Add ftl::destroy
delete net;
}
......
......@@ -30,6 +30,8 @@ extern const int FTL_VERSION_PATCH;
extern const int FTL_VERSION_COMMITS;
extern const char *FTL_VERSION_SHA1;
#define FTL_SOURCE_DIRECTORY "@CMAKE_SOURCE_DIR@"
#define FTL_LOCAL_CONFIG_ROOT @FTL_LOCAL_CONFIG_ROOT@
#define FTL_LOCAL_CACHE_ROOT @FTL_LOCAL_CACHE_ROOT@
#define FTL_LOCAL_DATA_ROOT @FTL_LOCAL_DATA_ROOT@
......
......@@ -60,6 +60,8 @@ class Configurable {
template <typename T>
std::optional<T> get(const std::string &name);
std::string getID() { return *get<std::string>("$id"); }
/**
* Get a configuration property, but return a default if not found.
*/
......
......@@ -31,6 +31,8 @@ std::optional<std::string> locateFile(const std::string &name);
Configurable *configure(int argc, char **argv, const std::string &root);
Configurable *configure(json_t &);
/**
* Change a configuration value based upon a URI. Return true if changed,
* false if it was not able to change.
......@@ -84,8 +86,13 @@ T *create(ftl::Configurable *parent, const std::string &name, ARGS ...args);
* Create a configurable rooted on a parent but with a specific object
* that is not directly a child of the parent. Used by RGB-D Factory.
*/
//template <typename T, typename... ARGS>
//T *create(ftl::Configurable *parent, json_t &obj, const std::string &name, ARGS ...args);
template <typename T, typename... ARGS>
T *create(ftl::Configurable *parent, json_t &obj, const std::string &name, ARGS ...args);
std::vector<T*> createArray(ftl::Configurable *parent, const std::string &name, ARGS ...args);
void destroy(ftl::Configurable *);
void set(const std::string &uri, const nlohmann::json &);
......@@ -93,6 +100,7 @@ void set(const std::string &uri, const nlohmann::json &);
// Deprecated
using config::create;
using config::createArray;
using config::locateFile;
using config::configure;
......@@ -128,8 +136,9 @@ T *ftl::config::create(json_t &link, ARGS ...args) {
template <typename T, typename... ARGS>
T *ftl::config::create(ftl::Configurable *parent, const std::string &name, ARGS ...args) {
//nlohmann::json &entity = ftl::config::resolve(parent->getConfig()[name]);
nlohmann::json &entity = (!parent->getConfig()[name].is_null()) ? parent->getConfig()[name] : ftl::config::resolve(parent->getConfig())[name];
nlohmann::json &entity = (!parent->getConfig()[name].is_null())
? parent->getConfig()[name]
: ftl::config::resolve(parent->getConfig())[name];
if (entity.is_object()) {
if (!entity["$id"].is_string()) {
......@@ -164,26 +173,51 @@ T *ftl::config::create(ftl::Configurable *parent, const std::string &name, ARGS
}
template <typename T, typename... ARGS>
T *ftl::config::create(ftl::Configurable *parent, json_t &obj, const std::string &name, ARGS ...args) {
//nlohmann::json &entity = ftl::config::resolve(parent->getConfig()[name]);
nlohmann::json &entity = obj;
std::vector<T*> ftl::config::createArray(ftl::Configurable *parent, const std::string &name, ARGS ...args) {
nlohmann::json &base = (!parent->getConfig()[name].is_null())
? parent->getConfig()[name]
: ftl::config::resolve(parent->getConfig())[name];
std::vector<T*> result;
if (base.is_array()) {
for (auto &entity : base) {
if (entity.is_object()) {
if (!entity["$id"].is_string()) {
std::string id_str = *parent->get<std::string>("$id");
if (id_str.find('#') != std::string::npos) {
entity["$id"] = id_str + std::string("/") + name;
} else {
entity["$id"] = id_str + std::string("#") + name;
}
}
result.push_back(create<T>(entity, args...));
} else if (entity.is_null()) {
// Must create the object from scratch...
std::string id_str = *parent->get<std::string>("$id");
if (id_str.find('#') != std::string::npos) {
id_str = id_str + std::string("/") + name;
} else {
id_str = id_str + std::string("#") + name;
}
parent->getConfig()[name] = {
// cppcheck-suppress constStatement
{"$id", id_str}
};
nlohmann::json &entity2 = parent->getConfig()[name];
result.push_back(create<T>(entity2, args...));
}
}
} else {
LOG(WARNING) << "Expected an array for '" << name << "' in " << parent->getID();
}
return result;
}
if (entity.is_object()) {
if (!entity["$id"].is_string()) {
std::string id_str = *parent->get<std::string>("$id");
if (id_str.find('#') != std::string::npos) {
entity["$id"] = id_str + std::string("/") + name;
} else {
entity["$id"] = id_str + std::string("#") + name;
}
}
return create<T>(entity, args...);
} else if (entity.is_null()) {
LOG(FATAL) << "Invalid raw object in Configurable construction";
return nullptr;
}
}
#endif // _FTL_COMMON_CONFIGURATION_HPP_
......@@ -30,7 +30,8 @@ namespace ftl {
SCHEME_WS,
SCHEME_IPC,
SCHEME_FILE,
SCHEME_OTHER
SCHEME_OTHER,
SCHEME_DEVICE
};
bool isValid() const { return m_valid; };
......
......@@ -189,7 +189,7 @@ void ftl::config::registerConfigurable(ftl::Configurable *cfg) {
}
auto ix = config_instance.find(*uri);
if (ix != config_instance.end()) {
LOG(ERROR) << "Attempting to create a duplicate object: " << *uri;
LOG(FATAL) << "Attempting to create a duplicate object: " << *uri;
} else {
config_instance[*uri] = cfg;
LOG(INFO) << "Registering instance: " << *uri;
......@@ -430,6 +430,24 @@ static void signalIntHandler( int signum ) {
ftl::running = false;
}
Configurable *ftl::config::configure(ftl::config::json_t &cfg) {
loguru::g_preamble_date = false;
loguru::g_preamble_uptime = false;
loguru::g_preamble_thread = false;
int argc = 1;
const char *argv[] = {"d",0};
loguru::init(argc, const_cast<char**>(argv), "--verbosity");
config_index.clear();
config_instance.clear();
config = cfg;
_indexConfig(config);
Configurable *rootcfg = create<Configurable>(config);
return rootcfg;
}
Configurable *ftl::config::configure(int argc, char **argv, const std::string &root) {
loguru::g_preamble_date = false;
loguru::g_preamble_uptime = false;
......
......@@ -533,6 +533,9 @@ namespace loguru
CHECK_GT_F(argc, 0, "Expected proper argc/argv");
CHECK_EQ_F(argv[argc], nullptr, "Expected proper argc/argv");
// Nick: Added to allow for multiple calls to init during tests
if (s_argv0_filename.size() > 0) return;
s_argv0_filename = filename(argv[0]);
#ifdef _WIN32
......
......@@ -51,6 +51,8 @@ void URI::_parse(uri_t puri) {
else if (prototext == "http") m_proto = SCHEME_HTTP;
else if (prototext == "ws") m_proto = SCHEME_WS;
else if (prototext == "ipc") m_proto = SCHEME_IPC;
else if (prototext == "device") m_proto = SCHEME_DEVICE;
else if (prototext == "file") m_proto = SCHEME_FILE;
else m_proto = SCHEME_OTHER;
m_protostr = prototext;
......@@ -91,7 +93,7 @@ void URI::_parse(uri_t puri) {
m_frag = std::string(uri.fragment.first, fraglast - uri.fragment.first);
}
m_valid = m_proto != SCHEME_NONE && m_host.size() > 0;
m_valid = m_proto != SCHEME_NONE && (m_host.size() > 0 || m_path.size() > 0);
if (m_valid) {
if (m_qmap.size() > 0) m_base = std::string(uri.scheme.first, uri.query.first - uri.scheme.first - 1);
......
......@@ -7,7 +7,7 @@
#include <ftl/config.h>
#include <ftl/configurable.hpp>
#include "../../../rgbd-sources/include/ftl/camera_params.hpp"
#include "../../../rgbd-sources/include/ftl/rgbd/camera.hpp"
#include <nlohmann/json.hpp>
#include <opencv2/opencv.hpp>
......@@ -35,7 +35,7 @@ class Display : public ftl::Configurable {
explicit Display(nlohmann::json &config, std::string name);
~Display();
bool render(const cv::Mat &rgb, const cv::Mat &depth, const ftl::rgbd::CameraParameters &p);
bool render(const cv::Mat &rgb, const cv::Mat &depth, const ftl::rgbd::Camera &p);
#if defined HAVE_PCL
bool render(pcl::PointCloud<pcl::PointXYZRGB>::ConstPtr);
......
......@@ -2,7 +2,7 @@
#define _FTL_RGBD_DISPLAY_HPP_
#include <nlohmann/json.hpp>
#include <ftl/rgbd_source.hpp>
#include <ftl/rgbd/source.hpp>
using MouseAction = std::function<void(int, int, int, int)>;
......@@ -12,10 +12,10 @@ namespace rgbd {
class Display : public ftl::Configurable {
public:
explicit Display(nlohmann::json &);
Display(nlohmann::json &, RGBDSource *);
Display(nlohmann::json &, Source *);
~Display();
void setSource(RGBDSource *src) { source_ = src; }
void setSource(Source *src) { source_ = src; }
void update();
bool active() const { return active_; }
......@@ -25,7 +25,7 @@ class Display : public ftl::Configurable {
void wait(int ms);
private:
RGBDSource *source_;
Source *source_;
std::string name_;
std::vector<std::function<void(int)>> key_handlers_;
Eigen::Vector3f eye_;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment