Skip to content

Commit

Permalink
added rtibuilder and task.
Browse files Browse the repository at this point in the history
  • Loading branch information
ponchio committed Nov 5, 2024
1 parent b1ff505 commit 2629c1b
Show file tree
Hide file tree
Showing 6 changed files with 69 additions and 59 deletions.
2 changes: 2 additions & 0 deletions relight-cli/rtibuilder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
#include <QImage>
#include <QRunnable>
#include <QThreadPool>
#include <QJsonDocument>
#include <QJsonObject>
#include <QtConcurrent>
#include <QFuture>

Expand Down
9 changes: 8 additions & 1 deletion relightlab/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,8 @@ set (RELIGHT_HEADERS
cropframe.h
rtiframe.h
rticard.h
rtitask.h
../relight/imagecropper.h

)

set (RELIGHTLAB_SOURCES
Expand Down Expand Up @@ -120,7 +120,14 @@ set (RELIGHTLAB_SOURCES
rtiplan.cpp
rticard.cpp
rtiexportdialog.cpp
rtitask.cpp
../relight/imagecropper.cpp
../relight-cli/rtibuilder.cpp
../src/rti.cpp
../src/legacy_rti.cpp
../src/imageset.cpp
../src/jpeg_encoder.cpp
../src/jpeg_decoder.cpp
)


Expand Down
16 changes: 14 additions & 2 deletions relightlab/relightlab.pro
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
QT += widgets xml
QT += widgets xml concurrent
CONFIG += c++11

#TODO: this might be needed in CMake
Expand Down Expand Up @@ -36,15 +36,22 @@ else: unix:!android: target.path = /opt/$${TARGET}/bin
!isEmpty(target.path): INSTALLS += target

SOURCES += main.cpp \
../relight-cli/convert_rti.cpp \
../relight-cli/rtibuilder.cpp \
../relight/parameter.cpp \
../relight/processqueue.cpp \
../src/align.cpp \
../src/dome.cpp \
../src/exif.cpp \
../src/image.cpp \
../src/imageset.cpp \
../src/jpeg_decoder.cpp \
../src/jpeg_encoder.cpp \
../src/legacy_rti.cpp \
../src/lens.cpp \
../src/measure.cpp \
../src/project.cpp \
../src/rti.cpp \
../src/sphere.cpp \
../src/white.cpp \
alignframe.cpp \
Expand Down Expand Up @@ -79,7 +86,6 @@ SOURCES += main.cpp \
directionsview.cpp \
spherepanel.cpp \
spheredialog.cpp \
../relight/task.cpp \
verifyview.cpp \
verifydialog.cpp \
helpbutton.cpp \
Expand All @@ -95,15 +101,21 @@ RESOURCES += \


HEADERS += \
../relight-cli/rtibuilder.h \
../relight/parameter.h \
../relight/processqueue.h \
../src/align.h \
../src/dome.h \
../src/exif.h \
../src/image.h \
../src/imageset.h \
../src/jpeg_decoder.h \
../src/jpeg_encoder.h \
../src/legacy_rti.h \
../src/lens.h \
../src/measure.h \
../src/project.h \
../src/rti.h \
../src/sphere.h \
../src/white.h \
alignframe.h \
Expand Down
93 changes: 40 additions & 53 deletions relightlab/rtitask.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,6 @@ RtiTask::~RtiTask() {
void RtiTask::run() {
status = RUNNING;
std::function<bool(QString s, int d)> callback = [this](QString s, int n)->bool { return this->progressed(s, n); };
QString err;


builder = new RtiBuilder;
builder->pixelSize = project.pixelSize;
Expand All @@ -47,60 +45,50 @@ void RtiTask::run() {
builder->yccplanes[1] = builder->yccplanes[2] = (builder->nplanes - builder->yccplanes[0])/2;
builder->nplanes = builder->yccplanes[0] + 2*builder->yccplanes[1];
}

builder->imageset.images = project.getImages();

//which lights?
builder->lights = builder->imageset.lights = lights;
builder->imageset.light3d = project.dome.lightConfiguration != Dome::DIRECTIONAL;
builder->imageset.dome_radius = project.dome.domeDiameter/2.0;
builder->imageset.vertical_offset = project.dome.verticalOffset;
builder->imageset.initLights();
builder->imageset.initImages(input_folder.toStdString().c_str());


if(hasParameter("crop")) {
QRect rect = (*this)["crop"].value.toRect();
builder->crop[0] = rect.left();
builder->crop[1] = rect.top();
builder->crop[2] = rect.width();
builder->crop[3] = rect.height();
builder->imageset.crop(rect.left(), rect.top(), rect.width(), rect.height());
ImageSet &imageset = builder->imageset;

imageset.images = project.getImages();

builder->lights = imageset.lights = project.dome.directions;
imageset.light3d = project.dome.lightConfiguration != Dome::DIRECTIONAL;
imageset.dome_radius = project.dome.domeDiameter/2.0;
imageset.vertical_offset = project.dome.verticalOffset;
imageset.initLights();
imageset.initImages(input_folder.toStdString().c_str());

if(!crop.isNull()) {
builder->crop[0] = crop.left();
builder->crop[1] = crop.top();
builder->crop[2] = crop.width();
builder->crop[3] = crop.height();
imageset.crop(crop.left(), crop.top(), crop.width(), crop.height());
}
builder->width = builder->imageset.width;
builder->height = builder->imageset.height;
int quality= (*this)["quality"].value.toInt();

std::function<bool(QString s, int n)> callback = [this](QString s, int n)->bool { return this->progressed(s, n); };
builder->width = imageset.width;
builder->height = imageset.height;

try {
if(!builder->init(&callback)) {
error = builder->error.c_str();
status = FAILED;
return;
}
if(saveLegacy) {
if(parameters.format == RtiParameters::RTI) {
if(builder->type == Rti::HSH)
builder->saveUniversal(output.toStdString());
else if(builder->type == Rti::PTM)
builder->savePTM(output.toStdString());
else
throw "Legacy RTI and PTM formats are supported only for HSH and PTM basis";
} else
builder->save(output.toStdString(), quality);
builder->save(output.toStdString(), parameters.quality);

} catch(std::string e) {
error = e.c_str();
status = STOPPED;
return;
}


for(auto step: steps) {
if(step == "relight")
relight();
else if(step == "rti")
relight(true, true);
/*
else if(step == "fromRTI")
fromRTI();
//TODO! deepZOOM should set error and status?
Expand All @@ -124,11 +112,11 @@ void RtiTask::run() {
}
else if(step == "openlime")
openlime();
}
} */
if(status != FAILED)
status = DONE;
}

/*
void RtiTask::relight(bool commonMinMax, bool saveLegacy) {
builder = new RtiBuilder;
builder->pixelSize =(*this)["pixelSize"].value.toDouble();
Expand All @@ -149,18 +137,18 @@ void RtiTask::relight(bool commonMinMax, bool saveLegacy) {
builder->nplanes = builder->yccplanes[0] + 2*builder->yccplanes[1];
}
builder->imageset.images = (*this)["images"].value.toStringList();
imageset.images = (*this)["images"].value.toStringList();
QList<QVariant> qlights = (*this)["lights"].value.toList();
std::vector<Vector3f> lights(qlights.size()/3);
for(int i = 0; i < qlights.size(); i+= 3)
for(int k = 0; k < 3; k++)
lights[i/3][k] = qlights[i+k].toDouble();
builder->lights = builder->imageset.lights = lights;
builder->imageset.light3d = project.dome.lightConfiguration != Dome::DIRECTIONAL;
builder->imageset.dome_radius = project.dome.domeDiameter/2.0;
builder->imageset.vertical_offset = project.dome.verticalOffset;
builder->imageset.initLights();
builder->imageset.initImages(input_folder.toStdString().c_str());
builder->lights = imageset.lights = lights;
imageset.light3d = project.dome.lightConfiguration != Dome::DIRECTIONAL;
imageset.dome_radius = project.dome.domeDiameter/2.0;
imageset.vertical_offset = project.dome.verticalOffset;
imageset.initLights();
imageset.initImages(input_folder.toStdString().c_str());
if(hasParameter("crop")) {
Expand All @@ -169,10 +157,10 @@ void RtiTask::relight(bool commonMinMax, bool saveLegacy) {
builder->crop[1] = rect.top();
builder->crop[2] = rect.width();
builder->crop[3] = rect.height();
builder->imageset.crop(rect.left(), rect.top(), rect.width(), rect.height());
imageset.crop(rect.left(), rect.top(), rect.width(), rect.height());
}
builder->width = builder->imageset.width;
builder->height = builder->imageset.height;
builder->width = imageset.width;
builder->height = imageset.height;
int quality= (*this)["quality"].value.toInt();
std::function<bool(QString s, int n)> callback = [this](QString s, int n)->bool { return this->progressed(s, n); };
Expand All @@ -199,8 +187,10 @@ void RtiTask::relight(bool commonMinMax, bool saveLegacy) {
return;
}
}
*/

void RtiTask::toRTI() {
/* not used anymore: build temporary rti and convert to legacy format */
/* void RtiTask::toRTI() {
QString filename = output;
QTemporaryDir tmp;
if(!tmp.isValid()) {
Expand All @@ -215,8 +205,9 @@ void RtiTask::toRTI() {
error = err;
status = FAILED;
}
}
} */

/*
void RtiTask::fromRTI() {
QString input = (*this)["input"].value.toString();
int quality= (*this)["quality"].value.toInt();
Expand All @@ -226,12 +217,8 @@ void RtiTask::fromRTI() {
error = err;
status = FAILED;
}
}
} */

int nPlanes(QString output) {
QDir destination(output);
return destination.entryList(QStringList("plane_*.jpg"), QDir::Files).size();
}

void RtiTask::openlime() {
QStringList files = QStringList() << ":/demo/index.html"
Expand Down
7 changes: 4 additions & 3 deletions relightlab/rtitask.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,16 +36,17 @@ class RtiTask: public Task {
public:
Project project;
RtiParameters parameters;
QRect crop;

RtiTask(const Project &_project);
virtual ~RtiTask();
virtual void run() override;

public slots:

void relight(bool commonMinMax = false, bool saveLegacy = false); //use true for .rti and .ptm
void toRTI();
void fromRTI();
//void relight(bool commonMinMax = false, bool saveLegacy = false); //use true for .rti and .ptm
//void toRTI();
//void fromRTI();
void openlime();

private:
Expand Down
1 change: 1 addition & 0 deletions src/imageset.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ class ImageSet {
int width = 0, height = 0;
int left = 0, top = 0, right = 0, bottom = 0;

/* REPLACE THIS WITH DOME */
//Lights
std::vector<Vector3f> lights;

Expand Down

0 comments on commit 2629c1b

Please sign in to comment.