Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bezier v0.4.0 release #48

Open
wants to merge 24 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
9273f72
Add static method for Curve fitting onto a given polyline
Sep 17, 2024
5f116fa
Add static method for joining two Curves
Sep 17, 2024
05be740
Run formatter on all files
Sep 17, 2024
b315f52
Add method for offseting a curve
Sep 17, 2024
215b218
Reimplement fitting method from randomized guess to gradient descent …
Sep 18, 2024
19ea06a
A bit of refactoring.
Sep 18, 2024
e87172f
Merge branch 'master' into fit-join-offset
Sep 20, 2024
f79db79
Merge pull request #36 from romb-technologies/fit-join-offset
kturkovic Oct 1, 2024
b58675d
Remove manipulateCurvature method. Run formatter on example. Close #38
Sep 20, 2024
325b068
Remove macro ifs for c++17 features
Sep 20, 2024
8407260
Use optional instead of dynamic unique_ptr for cache
Oct 1, 2024
a952482
Rework polynomial solving and refactor a bit
Oct 1, 2024
cd6edb6
Remove leading underscore and utilize namespace for helper functions
Oct 1, 2024
a03ebc2
Small refactor for cached roots
Oct 1, 2024
ee7d796
Add missing cached values to reset()
Oct 1, 2024
c0828f1
Change default flatness parameter to be dynamic (0.1% of bbox diagonal)
stribor14 Sep 21, 2024
5e10de9
Change return type of splitCurve and add a method to split in multipl…
stribor14 Sep 20, 2024
dbc892e
Refactor fromPolyline static method with eigen3 LevenbergMarquadt solver
stribor14 Sep 21, 2024
6a7dd2d
Simplify implementation of Visvalingam-Wyatt algorithm
Sep 30, 2024
ebb1d67
Small cleanup
Oct 1, 2024
69e1b1a
Merge pull request #47 from romb-technologies/v04-remove-manipulate-c…
tiborbs1 Oct 9, 2024
0229184
Modernize cmake
mattangus Oct 18, 2024
7bfa742
Merge pull request #53 from HumanisingAutonomy/devel-v040
stribor14 Oct 23, 2024
aad2dd0
Merge pull request #51 from romb-technologies/v04-levenberg-fit
kturkovic Oct 30, 2024
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
23 changes: 13 additions & 10 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,22 +3,17 @@ project(bezier
LANGUAGES CXX
VERSION 0.3.2)

set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS OFF)

add_compile_options(-fPIC -O2)

find_package(Eigen3 REQUIRED)
include_directories(SYSTEM ${EIGEN3_INCLUDE_DIR} include)

set(Bezier_SRC
${PROJECT_SOURCE_DIR}/src/utils.cpp
${PROJECT_SOURCE_DIR}/src/bezier.cpp
${PROJECT_SOURCE_DIR}/src/polycurve.cpp
)

set(Bezier_INC
${PROJECT_SOURCE_DIR}/include/Bezier/declarations.h
${PROJECT_SOURCE_DIR}/include/Bezier/utils.h
${PROJECT_SOURCE_DIR}/include/Bezier/bezier.h
${PROJECT_SOURCE_DIR}/include/Bezier/polycurve.h
)
Expand All @@ -35,15 +30,23 @@ else()
endif()

target_include_directories(bezier PUBLIC
$<BUILD_INTERFACE:${Bezier_SOURCE_DIR}/include>
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
$<INSTALL_INTERFACE:include>
)
target_link_libraries(bezier PUBLIC Eigen3::Eigen)

set_target_properties(bezier PROPERTIES VERSION ${PROJECT_VERSION})
set_target_properties(bezier PROPERTIES PUBLIC_HEADER "${Bezier_INC}")
set_target_properties(bezier PROPERTIES
VERSION ${PROJECT_VERSION}
CXX_EXTENSIONS OFF
POSITION_INDEPENDENT_CODE ON
PUBLIC_HEADER "${Bezier_INC}"
)
target_compile_features(bezier PUBLIC cxx_std_17)

# install rules
install(TARGETS bezier
EXPORT bezier-export DESTINATION "lib"
PUBLIC_HEADER DESTINATION "include/Bezier")
install(EXPORT bezier-export DESTINATION "lib/cmake/Bezier" FILE BezierConfig.cmake)

add_library(bezier::bezier ALIAS bezier)
2 changes: 2 additions & 0 deletions example/bezier_example.pro
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ SOURCES += \
customscene.cpp \
qcurve.cpp \
qpolycurve.cpp \
../src/utils.cpp \
../src/bezier.cpp \
../src/polycurve.cpp \

Expand All @@ -44,6 +45,7 @@ HEADERS += \
customscene.h \
qcurve.h \
qpolycurve.h \
../include/Bezier/utils.h \
../include/Bezier/bezier.h \
../include/Bezier/polycurve.h \
../include/Bezier/declarations.h
Expand Down
110 changes: 46 additions & 64 deletions example/customscene.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,8 @@ void CustomScene::mousePressEvent(QGraphicsSceneMouseEvent* mouseEvent)
QPen(Qt::blue)));
auto t2 = c_curve->iterateByLength(t1, 50);
auto a = c_curve->valueAt(t2);
byLength.insert(curve, addEllipse(QRectF(QPointF(a.x() - 3, a.y() - 3), QSizeF(6, 6)), QPen(Qt::yellow), QBrush(Qt::red, Qt::SolidPattern)));
byLength.insert(curve, addEllipse(QRectF(QPointF(a.x() - 3, a.y() - 3), QSizeF(6, 6)), QPen(Qt::yellow),
QBrush(Qt::red, Qt::SolidPattern)));
}
if (is_poly)
{
Expand All @@ -90,7 +91,8 @@ void CustomScene::mousePressEvent(QGraphicsSceneMouseEvent* mouseEvent)
QPen(Qt::blue)));
auto t2 = c_poly->iterateByLength(t1, 50);
auto a = c_poly->valueAt(t2);
byLength.insert(curve, addEllipse(QRectF(QPointF(a.x() - 3, a.y() - 3), QSizeF(6, 6)), QPen(Qt::yellow), QBrush(Qt::red, Qt::SolidPattern)));
byLength.insert(curve, addEllipse(QRectF(QPointF(a.x() - 3, a.y() - 3), QSizeF(6, 6)), QPen(Qt::yellow),
QBrush(Qt::red, Qt::SolidPattern)));
}
}
show_projection = true;
Expand Down Expand Up @@ -145,18 +147,6 @@ void CustomScene::mousePressEvent(QGraphicsSceneMouseEvent* mouseEvent)
}
if (update_cp)
break;
if (is_curve)
{
double t = c_curve->projectPoint(p);
auto pt = c_curve->valueAt(t);
auto ep = c_curve->endPoints();
if ((pt - p).norm() < 10 && (pt - ep.first).norm() > 20 && (pt - ep.second).norm() > 20)
{
update_curvature = true;
t_to_update = std::make_pair(c_curve, t);
break;
}
}
}
}
}
Expand All @@ -173,8 +163,8 @@ void CustomScene::mousePressEvent(QGraphicsSceneMouseEvent* mouseEvent)
auto split = c_curve->splitCurve(t);
delete curve;
qCurve *c1, *c2;
c1 = new qCurve(split.first);
c2 = new qCurve(split.second);
c1 = new qCurve(split[0]);
c2 = new qCurve(split[1]);
this->addItem(c1);
this->addItem(c2);
update();
Expand Down Expand Up @@ -235,20 +225,6 @@ void CustomScene::mouseMoveEvent(QGraphicsSceneMouseEvent* mouseEvent)
}
update();
}
if (update_curvature)
{
try
{
t_to_update.first->prepareGeometryChange();
t_to_update.first->manipulateCurvature(t_to_update.second, p);
update();
}
catch (char const* err)
{
update_curvature = false;
QMessageBox::warning(nullptr, "Warning", QString().sprintf("%s", err));
}
}
QGraphicsScene::mouseMoveEvent(mouseEvent);
}

Expand All @@ -273,10 +249,7 @@ void CustomScene::mouseReleaseEvent(QGraphicsSceneMouseEvent* mouseEvent)
}
}
if (mouseEvent->button() == Qt::LeftButton)
{
update_cp = false;
update_curvature = false;
}
}

void CustomScene::keyPressEvent(QKeyEvent* keyEvent)
Expand All @@ -290,7 +263,6 @@ Ctrl + Scroll - zoom in/out\n\
Ctrl + Left click - select curves\n\
Left click - deselect curves\n\
Left click + drag control point - manipulate control point\n\
Left click + drag curve - manipulate curve (only for 2nd and 3rd order)\n\
\n\
Keyboard shortcuts:\n\
H - display help\n\
Expand Down Expand Up @@ -377,43 +349,53 @@ Delete - delete curve/polycurve");
}
update();
}
if (keyEvent->key() == Qt::Key_L) {
for (auto&& curve : selectedItems()) {
if (is_curve) {
c_curve->setLocked(!c_curve->getLocked());
}
if (keyEvent->key() == Qt::Key_L)
{
for (auto&& curve : selectedItems())
{
if (is_curve)
{
c_curve->setLocked(!c_curve->getLocked());
}
update();
}
update();
}
if (keyEvent->key() == Qt::Key_Enter || keyEvent->key() == Qt::Key_Return) {
if (selectedItems().size() != 2) {
return;
}
if (keyEvent->key() == Qt::Key_Enter || keyEvent->key() == Qt::Key_Return)
{
if (selectedItems().size() != 2)
{
return;
}

qCurve* curve_locked = nullptr;
qCurve* curve_unlocked = nullptr;
qCurve* curve_locked = nullptr;
qCurve* curve_unlocked = nullptr;

if (c_curve_item(selectedItems().first())->getLocked()) {
curve_locked = c_curve_item(selectedItems().first());
curve_unlocked = c_curve_item(selectedItems().last());
if (c_curve_item(selectedItems().first())->getLocked())
{
curve_locked = c_curve_item(selectedItems().first());
curve_unlocked = c_curve_item(selectedItems().last());
}
else if (c_curve_item(selectedItems().last())->getLocked())
{
curve_locked = c_curve_item(selectedItems().last());
curve_unlocked = c_curve_item(selectedItems().first());
}

if (curve_locked != nullptr && curve_unlocked != nullptr)
{
while (curve_locked->order() < 5)
{
curve_locked->elevateOrder();
}
else if (c_curve_item(selectedItems().last())->getLocked()) {
curve_locked = c_curve_item(selectedItems().last());
curve_unlocked = c_curve_item(selectedItems().first());
while (curve_unlocked->order() < 5)
{
curve_unlocked->elevateOrder();
}

if (curve_locked != nullptr && curve_unlocked != nullptr) {
while (curve_locked->order() < 5) {
curve_locked->elevateOrder();
}
while (curve_unlocked->order() < 5) {
curve_unlocked->elevateOrder();
}

std::vector<double> beta_coeffs = {1, 0, 0};
curve_unlocked->applyContinuity(*dynamic_cast<Bezier::Curve*>(curve_locked), beta_coeffs);
update();
}
std::vector<double> beta_coeffs = {1, 0, 0};
curve_unlocked->applyContinuity(*dynamic_cast<Bezier::Curve*>(curve_locked), beta_coeffs);
update();
}
}

// if (keyEvent->key() >= 48 && keyEvent->key() <= 59) // num keys
Expand Down
4 changes: 1 addition & 3 deletions example/customscene.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
#include <QGraphicsScene>

#include "qcurve.h"
#include "qpolycurve.h"
#include "qgraphicsviewzoom.h"
#include "qpolycurve.h"

namespace Ui
{
Expand All @@ -28,8 +28,6 @@ class CustomScene : public QGraphicsScene
bool draw_box_ = false;
bool draw_inter_ = false;
bool show_projection = false;
bool update_curvature = false;
std::pair<qCurve*, double> t_to_update;
bool update_cp = false;
std::pair<QGraphicsItem*, uint> cp_to_update;

Expand Down
13 changes: 3 additions & 10 deletions example/mainwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,9 @@ MainWindow::MainWindow(QWidget* parent) : QMainWindow(parent), ui(new Ui::MainWi
Eigen::MatrixX2d cp1, cp2;
cp1.resize(4, 2);
cp2.resize(5, 2);
cp1 << 84, 162,
246, 30,
48, 236,
180, 110;

cp2 << 180, 110,
175, 160,
60, 48,
164, 165,
124, 134;
cp1 << 84, 162, 246, 30, 48, 236, 180, 110;

cp2 << 180, 110, 175, 160, 60, 48, 164, 165, 124, 134;

scene->addItem(new qCurve(cp1 * 5));
scene->addItem(new qCurve(cp2 * 5));
Expand Down
10 changes: 2 additions & 8 deletions example/qcurve.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,9 @@ bool qCurve::getDraw_control_points() const { return draw_control_points; }

bool qCurve::getDraw_curvature_radious() const { return draw_curvature_radious; }

bool qCurve::getLocked() const
{
return locked;
}
bool qCurve::getLocked() const { return locked; }

void qCurve::setLocked(bool value)
{
locked = value;
}
void qCurve::setLocked(bool value) { locked = value; }

int qCurve::type() const { return QGraphicsItem::UserType + 1; }

Expand Down
2 changes: 1 addition & 1 deletion example/qcurve.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@

#include <QGraphicsItem>

#include "Bezier/declarations.h"
#include "Bezier/bezier.h"
#include "Bezier/declarations.h"

class qCurve : public QGraphicsItem, public Bezier::Curve
{
Expand Down
2 changes: 1 addition & 1 deletion example/qgraphicsviewzoom.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#include "qgraphicsviewzoom.h"

#include <QMouseEvent>
#include <QApplication>
#include <QMouseEvent>
#include <QScrollBar>
#include <qmath.h>

Expand Down
2 changes: 1 addition & 1 deletion example/qgraphicsviewzoom.h
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
#ifndef QGRAPHICSVIEWZOOM_H
#define QGRAPHICSVIEWZOOM_H

#include <QObject>
#include <QDebug>
#include <QGraphicsView>
#include <QObject>

/*!
* \brief This class adds ability to zoom QGraphicsView using mouse wheel. The point under cursor
Expand Down
4 changes: 2 additions & 2 deletions example/qpolycurve.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,8 @@ void qPolyCurve::paint(QPainter* painter, const QStyleOptionGraphicsItem* option
painter->setPen(Qt::green);
for (double t = 0; t <= size(); t += 1.0 / 500)
{
painter->setPen(QColor(static_cast<int>(std::fabs(255 * (0.5 - t / size()))),
static_cast<int>(255 * t / size()), static_cast<int>(255 * (1 - t / size()))));
painter->setPen(QColor(static_cast<int>(std::fabs(255 * (0.5 - t / size()))), static_cast<int>(255 * t / size()),
static_cast<int>(255 * (1 - t / size()))));
auto p = valueAt(t);
auto n1 = p + normalAt(t, false) * curvatureDerivativeAt(t);
auto n2 = p - normalAt(t, false) * curvatureDerivativeAt(t);
Expand Down
3 changes: 2 additions & 1 deletion example/qpolycurve.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,16 @@

#include <QGraphicsItem>

#include "Bezier/bezier.h"
#include "Bezier/declarations.h"
#include "Bezier/polycurve.h"
#include "Bezier/bezier.h"

class qPolyCurve : public QGraphicsItem, public Bezier::PolyCurve
{
private:
bool draw_control_points = false;
bool draw_curvature_radious = false;

public:
qPolyCurve(const std::deque<Bezier::Curve>& curve_list) : QGraphicsItem(), Bezier::PolyCurve(curve_list) {}
qPolyCurve(const Bezier::Curve& curve) : QGraphicsItem(), Bezier::PolyCurve(std::deque<Bezier::Curve>{curve}) {}
Expand Down
Loading