Skip to content

Commit

Permalink
relight-pano tapioca
Browse files Browse the repository at this point in the history
  • Loading branch information
Erika committed Sep 6, 2024
1 parent b88410d commit e0cc02f
Show file tree
Hide file tree
Showing 9 changed files with 2,457 additions and 1 deletion.
2 changes: 1 addition & 1 deletion relight-cli/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -413,7 +413,7 @@ int main(int argc, char *argv[]) {
return 1;
}

} if(info.suffix() == "json") {
} else if(info.suffix() == "json") {
return convertToRTI(input.c_str(), output.c_str());

} else if(info.suffix() == "rti" || info.suffix() == "ptm") {
Expand Down
85 changes: 85 additions & 0 deletions relight-pano/main.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
#include "mainwindow.h"
#include <QDir>
#include <QApplication>
#include <QCommandLineParser>
#include <QCommandLineOption>
#include <iostream>
#include "panobuilder.h"
using namespace std;

void help(){
cout << R"(relight-pano
usage: relight-pano <folder> [-i]
folder: folder containing a set of rti photo datasets
-i: open user interface
)";
}
int main(int argc, char *argv[])
{
QCoreApplication app(argc, argv);
QCoreApplication::setApplicationName("relight-pano");


QCommandLineParser parser;
parser.setApplicationDescription("relight-pano: builds an RTI panorama");
parser.addHelpOption();
//folder
parser.addPositionalArgument("folder", "path folder containing rti datasets");

QCommandLineOption interactiveOption(QStringList() << "i" << "interactive",
"open users interface");
parser.addOption(interactiveOption);

QCommandLineOption stepOption(QStringList() << "s" << "step",
"starting step (rti, tapioca, )", "rti");
parser.addOption(stepOption);

// Process the actual command line arguments given by the user
parser.process(app);

const QStringList args = parser.positionalArguments();
if (args.size() < 1) {
cerr << "Missing command line Rti folder parameter." << endl;
return -1;
}

QString folder = args[0];
QDir dir(folder);
if (!dir.exists()) {
cerr << "Error: folder '"<< qPrintable(folder) << "' does not exist" << endl;
return -1;
}

bool interactive = parser.isSet(interactiveOption);
PanoBuilder::Steps startingStep = PanoBuilder::RTI;
bool steps = parser.isSet(stepOption);
if (interactive && steps) {
cout << "run in interactive mode" << endl;
MainWindow w;
w.show();
} else {
try{
PanoBuilder builder(folder);
if(steps){
QString step_name = parser.value(stepOption);
int s = builder.findStep(step_name);
if(s==-1){
cerr << "Unknown step: " << qPrintable(step_name) << endl;
return -1;
}
startingStep = (PanoBuilder::Steps) s;
}
builder.setMm3d("/Users/erika/Desktop/micmac/bin/mm3d");
builder.process(startingStep);
}
catch(QString error){
cerr << qPrintable(error) << endl;
}
return 0;
}


return app.exec();
}
7 changes: 7 additions & 0 deletions relight-pano/mainwindow.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#include "mainwindow.h"

MainWindow::MainWindow(QWidget *parent)
: QMainWindow(parent)
{}

MainWindow::~MainWindow() {}
14 changes: 14 additions & 0 deletions relight-pano/mainwindow.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#ifndef MAINWINDOW_H
#define MAINWINDOW_H

#include <QMainWindow>

class MainWindow : public QMainWindow
{
Q_OBJECT

public:
MainWindow(QWidget *parent = nullptr);
~MainWindow();
};
#endif // MAINWINDOW_H
194 changes: 194 additions & 0 deletions relight-pano/panobuilder.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,194 @@
#include "panobuilder.h"
#include <assert.h>
#include <QDir>
#include <iostream>
#include <QProcess>
#include <QFileInfo>
#include <QImage>
#include "qexifimageheader.h"
using namespace std;

PanoBuilder::PanoBuilder(QString dataset_path)
{
datasets_dir = QDir(QDir(dataset_path).absolutePath());
assert(datasets_dir.exists());
base_dir = datasets_dir;
base_dir.cdUp();
QDir::setCurrent(base_dir.absolutePath());
}
void PanoBuilder::setMm3d(QString path){
ensureExecutable(path);
mm3d_path = path;
}
void PanoBuilder::relightCli(QString path){
ensureExecutable(path);

relight_cli_path = path;
}
void PanoBuilder::relightMerge(QString path){
ensureExecutable(path);
relight_merge_path = path;
}

void PanoBuilder::ensureExecutable(QString path){
QFileInfo info(path);
if(!info.exists())
throw QString("File do not exists: ") + path;
if(!info.isExecutable() || !info.isFile())
throw QString("File is not executable") + path;

}
void PanoBuilder::cd(QString path, bool create){
QDir::setCurrent(base_dir.absolutePath());
QDir dir(path);
if(!dir.exists()){
if(create){
if (!base_dir.mkdir(path)) {
throw QString("Could not create directory: ") + path;
}
}
else
throw QString("Directory do not exist:") + path;
}
QDir::setCurrent(dir.absolutePath());
}
int PanoBuilder::findStep(QString step){
return (steps.indexOf(step));
}

/* directory structures:
* datasets
* face_A
* face_B
* rti
* face_A
* face_B
* photogrammetry
* Malt
* Ori-Abs
* Ori-Rel
* ...
*
*/
void PanoBuilder::process(Steps starting_step){
switch (starting_step) {
case RTI: rti();
case TAPIOCA: tapioca();
case SCHNAPS: schnaps();
case APERICLOUD: apericloud();
case ORTHOPLANE: orthoplane();
case TARAMA: tarama();
case MALT_MEC: malt_mec();
case C3DC: c3dc();
case MALT_ORTHO: malt_ortho();
case TAWNY: tawny();
case JPG: jpg();

}
}
//crea la directory rti se non esiste
//per ogni sottodir cerca file .relight e si passa nella command line di relight-cli
//command line specifica di fare le medie -m
// spostare le mean dentro fotogrammetry rinomina da rti/face_A/mean.jpg a photogrammetry/face_A.jpg
// chiama il merge, che ti chiede un'altra directory "merge", cancella la cartella rti e rinomina "merge" come "rti"
// output stampato a schermo e controlla gli errori



void PanoBuilder::rti(){
QDir rtiDir(base_dir.filePath("rti"));
if (!rtiDir.exists()) {
if (!base_dir.mkdir("rti")) {
throw QString("Could not create 'rti' directory");

}
}
//search the subdirectory, the QDir::Dirs | filter QDir::NoDotAndDotDot to get all subdirectories inside the root directory
QStringList subDirs = datasets_dir.entryList(QDir::Dirs | QDir::NoDotAndDotDot);
for (const QString &subDirName : subDirs) {
QDir subDir(datasets_dir.filePath(subDirName));

//search file .relight
QStringList relightFiles = subDir.entryList(QStringList() << "*.relight", QDir::Files);
if(relightFiles.size()==0)
throw QString("Missing .relight file in folder " )+ subDir.path();
QString relightFile = relightFiles[0];


QString program = "/Users/erika/Desktop/projects/relight/build/relight-cli/relight-cli";
QStringList arguments;
arguments << subDir.absoluteFilePath(relightFile) << rtiDir.filePath(subDir.dirName()) <<"-b" << "ptm" << "-p" << "18" << "-m";

QString command = program + " " + arguments.join(" ");
cout << "print command: " << qPrintable(command) <<endl;
QProcess process;
process.start(program, arguments);

if(!process.waitForStarted()){
throw QString("fail to start ") + process.program();
}

//wait for the process to finish
if(!process.waitForFinished(-1)) {
throw QString("fail to run ") + process.readAllStandardError();
}
}
}
void PanoBuilder::tapioca(){
cd("photogrammetry", true);

cout << qPrintable(base_dir.absolutePath()) << endl;
cout << qPrintable(base_dir.absoluteFilePath("rti")) << endl;
QDir rtiDir(base_dir.absoluteFilePath("rti"));
if (!rtiDir.exists()) {
throw QString("rti directory does not exist: ") + rtiDir.absolutePath();
}

QStringList subDirs = rtiDir.entryList(QDir::Dirs | QDir::NoDotAndDotDot);
for (const QString &subDirName : subDirs) {
QDir subDir(rtiDir.filePath(subDirName));
QStringList meanFiles = subDir.entryList(QStringList() << "means.png", QDir::Files);
if (meanFiles.size() == 0)
throw QString("Missing 'means.png' not found in ") + subDir.path();
QString meanFile = meanFiles[0];

QImage img;
img.load(subDir.filePath("means.png"));
img.save(subDir.dirName()+ ".jpg");

cout << qPrintable(datasets_dir.absolutePath()) << endl;
QDir dataset(datasets_dir.absoluteFilePath(subDirName));

QStringList photos = dataset.entryList(QStringList() << "*.jpg" << "*.JPG", QDir::Files);
if (photos.size() == 0)
throw QString("Missing '*.jpg' not found in ") + subDir.path();
QString photo = photos[0];

QExifImageHeader exif;
bool success = exif.loadFromJpeg(dataset.absoluteFilePath(photo));
if(!success)
throw QString("Unable to load exif from: ") + dataset.absoluteFilePath(photo);
//exif.saveToJpeg(subDir.dirName() + ".jpg");
}

QString program = mm3d_path;
QStringList arguments;
arguments << "tapioca" <<"All" << ".*jpg" << "1500" << "@SFS";

QString command = program + " " + arguments.join(" ");
cout << "Print command: " << qPrintable(command) << endl;

QProcess process;
process.start(program, arguments);

if (!process.waitForStarted()) {
throw QString("Failed to start ") + process.program();
}

if (!process.waitForFinished(-1)) {
throw QString("Failed to run ") + process.readAllStandardError();
}
cout << qPrintable(process.readAllStandardOutput()) << endl;
}


64 changes: 64 additions & 0 deletions relight-pano/panobuilder.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
#ifndef PANOBUILDER_H
#define PANOBUILDER_H

#include <QObject>
#include <QFile>
#include <QDir>

class PanoBuilder : public QObject
{
Q_OBJECT
public:
enum Steps{
RTI = 0, //rti e merge e medie
TAPIOCA,
SCHNAPS,
TAPAS,
APERICLOUD,
ORTHOPLANE,
TARAMA,
MALT_MEC,
C3DC,
MALT_ORTHO, //copy orientation xml and exif + ortho per image
TAWNY,
JPG //convert to jpg
};

QStringList steps = {"rti", "tapioca"};
QDir base_dir;
QDir datasets_dir;
QString mm3d_path;
QString relight_cli_path;
QString relight_merge_path;

QFile log;

PanoBuilder(QString path);
void setMm3d(QString path);
void relightCli(QString path);
void relightMerge(QString path);
int findStep(QString step);

void process(Steps starting_step = RTI);
//create the directory rti process the datasets and relight-merge the rti planes
void rti();
void tapioca();
void schnaps(){};
void tapas(){};
void apericloud(){};
void orthoplane(){};
void tarama(){};
void malt_mec(){};
void c3dc(){};
void malt_ortho(){};
void tawny(){};
void jpg(){};



signals:
private:
void ensureExecutable(QString path);
void cd(QString path, bool create = false);
};
#endif // PANOBUILDER_H
Loading

0 comments on commit e0cc02f

Please sign in to comment.