Skip to content

Commit

Permalink
working on the align functionality
Browse files Browse the repository at this point in the history
  • Loading branch information
ponchio committed Jan 22, 2025
1 parent 74ed36d commit 564cdb5
Show file tree
Hide file tree
Showing 17 changed files with 183 additions and 97 deletions.
13 changes: 7 additions & 6 deletions relightlab/alignframe.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,14 +33,15 @@ void AlignFrame::clear() {
while(aligns->count() > 0) {
QLayoutItem *item = aligns->takeAt(0);
AlignRow *row = dynamic_cast<AlignRow *>(item->widget());
//row->stopDetecting();
row->stopFinding();
delete row;
}
}

void AlignFrame::init() {
for(Align *align: qRelightApp->project().aligns) {
addAlign(align);
AlignRow *row = addAlign(align);
row->findAlignment(false);
}
}

Expand All @@ -49,7 +50,6 @@ void AlignFrame::newAlign() {
if(!marker_dialog)
marker_dialog = new MarkerDialog(MarkerDialog::ALIGN, this);

//TODO ACTUALLY images might be skipped!
Align *align = new Align(qRelightApp->project().images.size());
marker_dialog->setAlign(align);
int answer = marker_dialog->exec();
Expand All @@ -58,14 +58,15 @@ void AlignFrame::newAlign() {
return;
}
qRelightApp->project().aligns.push_back(align);
addAlign(align);
AlignRow *row = addAlign(align);
row->findAlignment();

}

AlignRow *AlignFrame::addAlign(Align *align) {
AlignRow *row = new AlignRow(align);
aligns->addWidget(row);


connect(row, SIGNAL(removeme(AlignRow *)), this, SLOT(removeAlign(AlignRow *)));
connect(row, SIGNAL(updated()), this, SIGNAL(updated()));
return row;
Expand All @@ -74,7 +75,7 @@ AlignRow *AlignFrame::addAlign(Align *align) {
void AlignFrame::removeAlign(AlignRow *row) {
layout()->removeWidget(row);

// row->stopDetecting();
row->stopFinding();

Align *align = row->align;
auto &aligns = qRelightApp->project().aligns;
Expand Down
3 changes: 2 additions & 1 deletion relightlab/alignframe.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ Q_OBJECT
public slots:
void newAlign();
void removeAlign(AlignRow *align);

signals:
void updated();

private:
MarkerDialog *marker_dialog = nullptr;
Expand Down
30 changes: 23 additions & 7 deletions relightlab/alignpicking.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,24 +7,35 @@
#include <QPen>
#include <QKeyEvent>


QVariant AlignRect::itemChange(GraphicsItemChange change, const QVariant &value) {
if ((change == ItemPositionChange && scene()) || change == ItemScenePositionHasChanged) {
picker->updateAlignPoint();
}
return QGraphicsItem::itemChange(change, value);
}

AlignPicking::AlignPicking(QWidget *parent): ImageViewer(parent) {

marker_side = 40;

connect(view, SIGNAL(clicked(QPoint)), this, SLOT(click(QPoint)));
rect = new AlignRect(this, 0, 0, 0, 0);
rect->setPen(QPen(Qt::yellow, 2));
rect->setBrush(Qt::transparent);
}


void AlignPicking::clear() {
scene().clear();
rect = nullptr;
if(rect) {
scene().removeItem(rect);
}
}

void AlignPicking::setAlign(Align *a) {
clear();
align = a;

rect = scene().addRect(a->rect, QPen(Qt::yellow), Qt::red);
rect->setRect(align->rect);
scene().addItem(rect);

showImage(0);
fit();
Expand All @@ -33,7 +44,7 @@ void AlignPicking::setAlign(Align *a) {


void AlignPicking::click(QPoint p) {
clear();
//clear();

QSize imgsize = qRelightApp->project().imgsize;
QPointF pos = view->mapToScene(p);
Expand All @@ -47,5 +58,10 @@ void AlignPicking::click(QPoint p) {
pos.setY(std::min(imgsize.height()-marker_side/2.0, pos.y()));

align->rect = QRect(pos.x()-marker_side/2.0, pos.y()-marker_side/2.0, marker_side, marker_side);
rect = scene().addRect(align->rect, QPen(Qt::yellow), Qt::red);
rect->setRect(align->rect);
}

void AlignPicking::updateAlignPoint() {
align->rect = rect->rect().toRect();
}

25 changes: 22 additions & 3 deletions relightlab/alignpicking.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,39 @@
#define ALIGN_PICKING_H

#include "imageview.h"
#include <QGraphicsRectItem>

class QGraphicsRectItem;
class Canvas;
class Align;

class AlignPicking;

class AlignRect: public QGraphicsRectItem {
public:
AlignRect(AlignPicking *_picker, qreal x, qreal y, qreal w, qreal h, QGraphicsItem *parent = Q_NULLPTR):
QGraphicsRectItem(x, y, w, h, parent), picker(_picker) {
setCursor(Qt::CrossCursor);
setFlag(QGraphicsItem::ItemIsMovable);
setFlag(QGraphicsItem::ItemIsSelectable);
setFlag(QGraphicsItem::ItemSendsScenePositionChanges);

}
virtual ~AlignRect() {}

protected:
AlignPicking *picker;
QVariant itemChange(GraphicsItemChange change, const QVariant &value);
};


class AlignPicking: public ImageViewer {
Q_OBJECT
public:
int marker_side = 40;
Align *align = nullptr;

QGraphicsRectItem *rect = nullptr;

AlignRect *rect = nullptr;

AlignPicking(QWidget *parent = nullptr);
void setAlign(Align *sphere);
Expand All @@ -24,7 +43,7 @@ class AlignPicking: public ImageViewer {

public slots:
void click(QPoint);

void updateAlignPoint();
};

#endif
54 changes: 26 additions & 28 deletions relightlab/alignrow.cpp
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
#include "alignrow.h"

#include "markerdialog.h"
#include "relightapp.h"
#include "verifydialog.h"
#include "reflectionview.h"
#include "../src/project.h"
#include "../src/sphere.h"
#include "../src/align.h"
#include "processqueue.h"

#include <QHBoxLayout>
Expand All @@ -22,19 +23,19 @@ void FindAlignment::run() {
mutex.lock();
status = RUNNING;
mutex.unlock();
/*

Project &project = qRelightApp->project();
for(size_t i = 0; i < project.images.size(); i++) {

Image &image = project.images[i];
if(image.skip) continue;

QImage img(image.filename);
sphere->findHighlight(img, i, update_positions);
align->readThumb(img, i);

int progress = std::min(99, (int)(100*(i+1) / project.images.size()));
progressed(QString("Detecting highlights"), progress);
} */
}
progressed(QString("Done"), 100);
mutex.lock();
status = DONE;
Expand All @@ -48,19 +49,19 @@ AlignRow::AlignRow(Align *_align, QWidget *parent): QWidget(parent) {
columns->setSpacing(20);

columns->addWidget(thumb = new QLabel());
/* position = new PositionView(sphere, rowHeight);
position = new AlignOverview(align->rect, rowHeight);
position->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed);
columns->addWidget(position);


reflections = new ReflectionView(sphere, rowHeight);
/*reflections = new ReflectionView(sphere, rowHeight);
reflections->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed);
columns->addWidget(reflections); */

QVBoxLayout *status_layout = new QVBoxLayout;
columns->addLayout(status_layout, 2);
status_layout->addStretch();
status = new QLabel("Locating highlights...");
status = new QLabel("Loading patches...");
status_layout->addWidget(status);
progress = new QProgressBar;
progress->setValue(0);
Expand All @@ -78,15 +79,17 @@ AlignRow::AlignRow(Align *_align, QWidget *parent): QWidget(parent) {
connect(remove, SIGNAL(clicked()), this, SLOT(remove()));
connect(verify, SIGNAL(clicked()), this, SLOT(verify()));


}
void AlignRow::edit() {
MarkerDialog *marker_dialog = new MarkerDialog(MarkerDialog::ALIGN, this);
marker_dialog->setAlign(align);
int answer = marker_dialog->exec();
if(answer == QDialog::Accepted) {
//position->update();
position->rect = align->rect;
position->update();
//reflections->init();
//detectHighlights();
findAlignment();
}
}

Expand All @@ -105,36 +108,31 @@ void AlignRow::remove() {
void AlignRow::updateStatus(QString msg, int percent) {
status->setText(msg);
progress->setValue(percent);
reflections->update();
//reflections->update();
if(percent == 100) {
emit updated();
}
}

void AlignRow::findAlignment(bool update) {
/* if(sphere->center.isNull()) {
status->setText("Needs at least 3 points.");
return;
}
if(!detect_highlights) {
detect_highlights = new DetectHighlights(sphere, update);
connect(detect_highlights, &DetectHighlights::progress, this, &SphereRow::updateStatus); //, Qt::QueuedConnection);
if(!find_alignment) {
find_alignment = new FindAlignment(align, update);
connect(find_alignment, &FindAlignment::progress, this, &AlignRow::updateStatus); //, Qt::QueuedConnection);
}
detect_highlights->stop();
find_alignment->stop();

ProcessQueue &queue = ProcessQueue::instance();
queue.removeTask(detect_highlights);
queue.addTask(detect_highlights);
queue.start(); */
queue.removeTask(find_alignment);
queue.addTask(find_alignment);
queue.start();
}

void AlignRow::stopFinding() {
/*
if(detect_highlights) {
if(detect_highlights->isRunning()) {
detect_highlights->stop();
detect_highlights->wait();
if(find_alignment) {
if(find_alignment->isRunning()) {
find_alignment->stop();
find_alignment->wait();
}
detect_highlights->deleteLater();
} */
find_alignment->deleteLater();
}
}
8 changes: 4 additions & 4 deletions relightlab/alignrow.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
class Align;
class QLabel;
class QProgressBar;
class ReflectionView;
class AlignOverview;
class QGraphicsPixmapItem;

class FindAlignment: public Task {
Expand All @@ -26,10 +26,10 @@ class FindAlignment: public Task {
class AlignRow: public QWidget {
Q_OBJECT
public:
Align *align;
int rowHeight = 92;
QLabel *thumb;
ReflectionView *reflections;
Align *align = nullptr;
QLabel *thumb = nullptr;
AlignOverview *position = nullptr;
QLabel *status = nullptr;
QProgressBar *progress = nullptr;
FindAlignment *find_alignment = nullptr;
Expand Down
18 changes: 7 additions & 11 deletions relightlab/docs/gettingstarted.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
#Getting started

<!-- Here we guide the user through the steps to create an RTI,
we do not need to cover every detail. -->

1. <a href="#newproject"> Prerequisites </a>
<!-- Here we guide the user through the steps to create an RTI, we do not need to cover every detail. -->

1. <a href="#newproject"> New project </a>
2. <a href="#lights"> Lights </a>
3. <a href="#rti"> Export RTIs </a>
4. <a href="#normals"> Export normals </a>
Expand All @@ -12,25 +12,21 @@ we do not need to cover every detail. -->

##New project

<!-- relight save the configuration in a .relight project. To creata a project select a folder where the all the images
are (in .jpg format) -->
<!-- relight save the configuration in a .relight project. To creata a project select a folder where the all the images are (in .jpg format) -->


##Light configuration

<!-- relight needs to know the position/direction of the lights, here we proporse to use an .lp if
present or to use a reflective sphere -->
<!-- relight needs to know the position/direction of the lights, here we proporse to use an .lp if present or to use a reflective sphere -->

##Export RTI

<!-- we instruct the user to crop the region of interest, than to select a simple ptm (link to rti/basis.md),
save in web image format, -->
<!-- we instruct the user to crop the region of interest, than to select a simple ptm (link to rti/basis.md), save in web image format, -->


#Working with normals

<!-- we can exporta a normalmap, ensure that the normal is flat (see interface/geometry.md),
and export also a mesh (.ply) or a depthmap -->
<!-- we can exporta a normalmap, ensure that the normal is flat (see interface/geometry.md), and export also a mesh (.ply) or a depthmap -->

#Explore the results

Expand Down
6 changes: 4 additions & 2 deletions relightlab/docs/home.md
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
# Documentation

<h2><a href="gettingstarted.md">Getting started</a></h2>


A selection of topics, links to to tutorials, etc.

RTI introduction.

Publishing on the web.

## <a href="index.md"> Index </a>
<h2><a href="index.md"> Index </a></h2>



Expand Down
2 changes: 1 addition & 1 deletion relightlab/docs/index.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Index

0. <a href="start/gettingstarted.md"> Getting started </a>
0. <a href="gettingstarted.md"> Getting started </a>

1. <a href="interface/index.md"> Interface </a>

Expand Down
Loading

0 comments on commit 564cdb5

Please sign in to comment.