Skip to content

Commit

Permalink
Merge pull request #3 from kipr/refactor
Browse files Browse the repository at this point in the history
Update Refactor branch
  • Loading branch information
chrehall68 committed Dec 1, 2022
2 parents 2bb3e7f + 3c879c2 commit 77530ea
Show file tree
Hide file tree
Showing 16 changed files with 156 additions and 90 deletions.
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
build
.vscode/
.vscode/
documentation/html
documentation/man
20 changes: 20 additions & 0 deletions documentation/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,26 @@ if (with_documentation)
endforeach()
list(APPEND DOCUMENTATION_DIRECTORIES ${CMAKE_SOURCE_DIR}/documentation/pages)

#Project Settings
set(DOXYGEN_PROJECT_LOGO ${CMAKE_SOURCE_DIR}/documentation/kipr.png)
set(DOXYGEN_OUTPUT_DIRECTORY ${CMAKE_SOURCE_DIR}/documentation)
#Build Settings
set(DOXYGEN_EXTRACT_ALL YES)
set(DOXYGEN_GENERATE_TODOLIST NO)
#Input Settings
set(DOXYGEN_RECURSIVE YES)
#Source Browser Settings
set(DOXYGEN_REFERENCED_BY_RELATION YES)
set(DOXYGEN_REFERENCES_RELATION YES)
#HTML
#Note: Finding a red color that wasn't ugly was a challenge, so it's purple for now
#(because purple is an awesome color)
set(DOXYGEN_HTML_COLORSTYLE_HUE 243)
set(DOXYGEN_HTML_COLORSTYLE_SAT 96)
set(DOXYGEN_HTML_COLORSTYLE_GAMMA 95)
set(DOXYGEN_DISABLE_INDEX YES)
set(DOXYGEN_GENERATE_TREEVIEW YES)

doxygen_add_docs(
documentation
${DOCUMENTATION_DIRECTORIES}
Expand Down
Binary file added documentation/kipr.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
6 changes: 3 additions & 3 deletions module/camera/dependencies/zlib/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,15 @@ set(ZLIB_COMMON_OPTIONS
if (CMAKE_CROSSCOMPILING)
get_property(ARCH GLOBAL PROPERTY arch)
ExternalProject_Add(dep_zlib
URL https://www.zlib.net/zlib-1.2.12.tar.gz
URL https://www.zlib.net/zlib-1.2.13.tar.gz
CMAKE_ARGS
-DCMAKE_TOOLCHAIN_FILE=${CMAKE_TOOLCHAIN_FILE}
${ZLIB_COMMON_OPTIONS}
INSTALL_COMMAND make install
)
else()
ExternalProject_Add(dep_zlib
URL https://www.zlib.net/zlib-1.2.12.tar.gz
URL https://www.zlib.net/zlib-1.2.13.tar.gz
CMAKE_ARGS
${ZLIB_COMMON_OPTIONS}
INSTALL_COMMAND make install
Expand All @@ -36,4 +36,4 @@ target_include_directories(zlib_wrapper INTERFACE ${ZLIB_INCLUDE_DIR})
# z
add_library(z_wrapper INTERFACE)
add_dependencies(z_wrapper zlib_wrapper)
target_link_libraries(z_wrapper INTERFACE zlib_wrapper z)
target_link_libraries(z_wrapper INTERFACE zlib_wrapper z)
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
#ifndef _KIPR_CAMERA_CHANNEL_HPP_
#define _KIPR_CAMERA_CHANNEL_HPP_
#ifndef _KIPR_CAMERA_CHANNEL_IMPL_HPP_
#define _KIPR_CAMERA_CHANNEL_IMPL_HPP_

#include "kipr/camera/object.hpp"
#include "kipr/config/config.hpp"
#include "kipr/camera/channel.hpp"

#include <opencv2/core/core.hpp>

Expand Down Expand Up @@ -41,29 +42,6 @@ namespace kipr
static std::map<std::string, ChannelImpl *> m_channelImpls;
};

class Channel
{
public:
Channel(Device *device, const config::Config &config);
~Channel();

void invalidate();
const ObjectVector *objects() const;
Device *device() const;

/**
* Do not call this method unless you know what you are doing!
*/
void setConfig(const config::Config &config);

private:
Device *m_device;
config::Config m_config;
mutable ObjectVector m_objects;
ChannelImpl *m_impl;
mutable bool m_valid;
};

typedef std::vector<Channel *> ChannelPtrVector;
}
}
Expand Down
39 changes: 39 additions & 0 deletions module/camera/public/kipr/camera/channel.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
#ifndef _KIPR_CAMERA_CHANNEL_HPP_
#define _KIPR_CAMERA_CHANNEL_HPP_

#include "kipr/camera/object.hpp"
#include "kipr/config/config.hpp"

namespace kipr
{
namespace camera
{
class Device;
class ChannelImpl;

class Channel
{
public:
Channel(Device *device, const config::Config &config);
~Channel();

void invalidate();
const ObjectVector *objects() const;
Device *device() const;

/**
* Do not call this method unless you know what you are doing!
*/
void setConfig(const config::Config &config);

private:
Device *m_device;
config::Config m_config;
mutable ObjectVector m_objects;
ChannelImpl *m_impl;
mutable bool m_valid;
};
}
}

#endif
15 changes: 15 additions & 0 deletions module/camera/public/kipr/camera/image.hpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
#ifndef _KIPR_CAMERA_IMAGE_HPP_
#define _KIPR_CAMERA_IMAGE_HPP_

#include <algorithm>

namespace kipr
{
namespace camera
Expand Down Expand Up @@ -29,6 +31,8 @@ namespace kipr
Image(const Image &);
Image(Image &&);

Image &operator=(Image);

~Image();

bool isEmpty() const;
Expand All @@ -41,6 +45,17 @@ namespace kipr
unsigned getStride() const;
bool isOwned() const;

friend void swap(Image &first, Image &second)
{
using std::swap;
swap(first.type_, second.type_);
swap(first.data_, second.data_);
swap(first.owned_, second.owned_);
swap(first.width_, second.width_);
swap(first.height_, second.height_);
swap(first.stride_, second.stride_);
}

private:
Type type_;
unsigned char *data_;
Expand Down
1 change: 1 addition & 0 deletions module/camera/src/camera.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
#include "channel_p.hpp"
#include "kipr/camera/camera.h"
#include "kipr/camera/channel.hpp"
#include "kipr/camera/channel_impl.hpp"
#include "UDPVideo.hpp"

#include <csetjmp>
Expand Down
1 change: 1 addition & 0 deletions module/camera/src/camera_c.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#include "kipr/camera/camera.h"
#include "kipr/camera/camera.hpp"
#include "kipr/camera/channel.hpp"
#include "kipr/camera/channel_impl.hpp"
#include "kipr/log/log.hpp"
#include "camera_c_p.hpp"
#include "logger.hpp"
Expand Down
45 changes: 0 additions & 45 deletions module/camera/src/channel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,51 +6,6 @@
using namespace kipr;
using namespace kipr::camera;

ChannelImpl::ChannelImpl() : m_dirty(true) {}

ChannelImpl::~ChannelImpl() {}

void ChannelImpl::setImage(const cv::Mat &image)
{
if (image.empty())
{
m_image = cv::Mat();
m_dirty = true;
return;
}
m_image = image;
m_dirty = true;
}

ObjectVector ChannelImpl::objects(const config::Config &config)
{
if (m_dirty)
{
update(m_image);
m_dirty = false;
}
return findObjects(config);
}

std::map<std::string, ChannelImpl *> ChannelImplManager::m_channelImpls = {
{"hsv", new HsvChannelImpl()},
};

void ChannelImplManager::setImage(const cv::Mat &image)
{
std::map<std::string, ChannelImpl *>::iterator it = m_channelImpls.begin();
for (; it != m_channelImpls.end(); ++it)
it->second->setImage(image);
}

ChannelImpl *ChannelImplManager::channelImpl(const std::string &name)
{
std::map<std::string, ChannelImpl *>::iterator it = m_channelImpls.find(name);
return (it == m_channelImpls.end()) ? 0 : it->second;
}

// Channel //

Channel::Channel(Device *device, const config::Config &config)
: m_device(device), m_config(config), m_impl(0), m_valid(false)
{
Expand Down
50 changes: 50 additions & 0 deletions module/camera/src/channel_impl.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
#include "kipr/camera/channel_impl.hpp"
#include "channel_p.hpp"

#include "logger.hpp"

using namespace kipr;
using namespace kipr::camera;

ChannelImpl::ChannelImpl() : m_dirty(true) {}

ChannelImpl::~ChannelImpl() {}

void ChannelImpl::setImage(const cv::Mat &image)
{
if (image.empty())
{
m_image = cv::Mat();
m_dirty = true;
return;
}
m_image = image;
m_dirty = true;
}

ObjectVector ChannelImpl::objects(const config::Config &config)
{
if (m_dirty)
{
update(m_image);
m_dirty = false;
}
return findObjects(config);
}

std::map<std::string, ChannelImpl *> ChannelImplManager::m_channelImpls = {
{"hsv", new HsvChannelImpl()},
};

void ChannelImplManager::setImage(const cv::Mat &image)
{
std::map<std::string, ChannelImpl *>::iterator it = m_channelImpls.begin();
for (; it != m_channelImpls.end(); ++it)
it->second->setImage(image);
}

ChannelImpl *ChannelImplManager::channelImpl(const std::string &name)
{
std::map<std::string, ChannelImpl *>::iterator it = m_channelImpls.find(name);
return (it == m_channelImpls.end()) ? 0 : it->second;
}
2 changes: 1 addition & 1 deletion module/camera/src/channel_p.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
#define _KIPR_CAMERA_CHANNEL_P_HPP_

#include "kipr/camera/camera.hpp"
#include "kipr/camera/channel.hpp"
#include "kipr/camera/channel_impl.hpp"
#include "kipr/camera/object.hpp"
#include <opencv2/core/core.hpp>

Expand Down
8 changes: 7 additions & 1 deletion module/camera/src/image.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ Image::Image(
unsigned char *const data,
const bool owned
) : type_(type)
, data_(nullptr)
, data_(data)
, owned_(owned)
, width_(width)
, height_(height)
Expand Down Expand Up @@ -53,6 +53,12 @@ Image::Image(Image &&rhs)
rhs.owned_ = false;
}

Image &Image::operator=(Image other)
{
swap(*this, other);
return *this;
}

Image::~Image()
{
if (owned_) delete[] data_;
Expand Down
2 changes: 1 addition & 1 deletion module/core/src/device/wombat/wombat_device.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ class WombatDevice : public kipr::core::Device
return false;
}

if (read_buffer[0] != 'J')
if (read_buffer && read_buffer[0] != 'J')
{
logger.error() << "DMA de-synchronized";
return false;
Expand Down
Loading

0 comments on commit 77530ea

Please sign in to comment.