Skip to content

Commit 4ee0aaf

Browse files
committed
align tab now working
1 parent 6054735 commit 4ee0aaf

8 files changed

+55
-16
lines changed

relightlab/mainwindow.cpp

+1
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,7 @@ void MainWindow::clear() {
139139

140140
void MainWindow::init() {
141141
image_frame->init();
142+
align_frame->init();
142143
scale_frame->init();
143144
lights_frame->init();
144145
crop_frame->init();

relightlab/normalstask.cpp

+2-4
Original file line numberDiff line numberDiff line change
@@ -59,10 +59,8 @@ void NormalsTask::initFromProject(Project &project) {
5959
imageset.initImages(project.dir.absolutePath().toStdString().c_str());
6060
imageset.initFromDome(project.dome);
6161
assert(imageset.lights().size() == imageset.images.size());
62-
QRect &crop = project.crop;
63-
if(!crop.isNull()) {
64-
imageset.crop(crop.left(), crop.top(), crop.width(), crop.height());
65-
}
62+
imageset.setCrop(project.crop, project.offsets);
63+
6664
pixelSize = project.pixelSize;
6765
}
6866
void NormalsTask::setParameters(NormalsParameters &param) {

relightlab/roadmap.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
* shadow removal
2828
* 3d lights on sphere should take into account sphere posistion/
2929
* allow rescaling when building rti and normals
30-
30+
* rotate and crop an existing rti.
3131

3232
## Bugs
3333

relightlab/rtiframe.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ void RtiFrame::exportRti() {
116116
QMessageBox::warning(this, "Destination path is missing.", "Fill in the output folder or the filename for the RTI.");
117117
return;
118118
}
119-
RtiTask *rti_task = new RtiTask(qRelightApp->project());
119+
RtiTask *rti_task = new RtiTask(project);
120120
rti_task->setParameters(parameters);
121121
rti_task->output = parameters.path;
122122
rti_task->crop = project.crop;

relightlab/rtitask.cpp

+8-6
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ void RtiTask::run() {
6060
status = RUNNING;
6161
std::function<bool(QString s, int d)> callback = [this](QString s, int n)->bool { return this->progressed(s, n); };
6262

63+
//TODO mnove all this to the constructor (except what parameters can set.
6364
builder = new RtiBuilder;
6465
builder->imageset.pixel_size = project.pixelSize;
6566

@@ -84,15 +85,16 @@ void RtiTask::run() {
8485
imageset.images = project.getImages();
8586
imageset.pixel_size = project.pixelSize;
8687
imageset.initImages(input_folder.toStdString().c_str());
87-
imageset.initFromDome(project.dome); //lights after images
8888

89+
imageset.initFromDome(project.dome); //lights after images
90+
imageset.setCrop(crop,project.offsets);
8991

92+
//TODO too many crop locations!
9093
if(!crop.isNull()) {
91-
builder->crop[0] = crop.left();
92-
builder->crop[1] = crop.top();
93-
builder->crop[2] = crop.width();
94-
builder->crop[3] = crop.height();
95-
imageset.crop(crop.left(), crop.top(), crop.width(), crop.height());
94+
builder->crop[0] = imageset.left;
95+
builder->crop[1] = imageset.top;
96+
builder->crop[2] = imageset.width;
97+
builder->crop[3] = imageset.height;
9698
}
9799

98100
builder->width = imageset.width;

src/imageset.cpp

+35-4
Original file line numberDiff line numberDiff line change
@@ -278,11 +278,12 @@ void ImageSet::readLine(PixelArray &pixels) {
278278

279279
for(size_t i = 0; i < decoders.size(); i++) {
280280
decoders[i]->readRows(1, row.data());
281+
int x_offset = offsets.size() ? offsets[i].x() : 0;
281282

282283
for(int x = left; x < right; x++) {
283-
pixels[x - left][i].r = row[x*3 + 0];
284-
pixels[x - left][i].g = row[x*3 + 1];
285-
pixels[x - left][i].b = row[x*3 + 2];
284+
pixels[x - left][i].r = row[(x + x_offset)*3 + 0];
285+
pixels[x - left][i].g = row[(x + x_offset)*3 + 1];
286+
pixels[x - left][i].b = row[(x + x_offset)*3 + 2];
286287
}
287288
}
288289
if(light3d) {
@@ -387,11 +388,40 @@ void ImageSet::restart() {
387388
current_line = 0;
388389
}
389390

391+
void ImageSet::setCrop(QRect &_crop, std::vector<QPointF> &_offsets) {
392+
std::vector<QPoint> int_offsets;
393+
for(QPointF &p: _offsets)
394+
int_offsets.push_back(p.toPoint());
395+
396+
//find min and max of offsets to adjust the maxCrop;
397+
int l = 0;
398+
int r = 0;
399+
int t = image_width;
400+
int b = image_height;
401+
for(QPoint &o: int_offsets) {
402+
l = std::max(l, -o.x());
403+
r = std::min(image_width, -o.x());
404+
t = std::max(b, -o.y());
405+
b = std::min(image_height, -o.y());
406+
}
407+
//TODO check +1 problem
408+
QRect max_crop(l, t, r -l, t - b);
409+
if(_crop.isNull())
410+
_crop = max_crop;
411+
else
412+
_crop = max_crop.intersected(_crop);
413+
414+
left =_crop.left();
415+
crop(_crop.left(), _crop.top(), _crop.width(), _crop.height());
416+
offsets = int_offsets;
417+
}
418+
390419
void ImageSet::skipToTop() {
391420
std::vector<uint8_t> row(image_width*3);
392421

393422
for(uint32_t i = 0; i < decoders.size(); i++) {
394-
for(int y = 0; y < top; y++)
423+
int y_offset = offsets.size() ? offsets[i].y() : 0;
424+
for(int y = 0; y < top + y_offset; y++)
395425
decoders[i]->readRows(1, row.data());
396426

397427
if(callback && !(*callback)("Skipping cropped lines...", 100*i/(decoders.size()-1)))
@@ -400,3 +430,4 @@ void ImageSet::skipToTop() {
400430
current_line += top;
401431
}
402432

433+

src/imageset.h

+6
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,12 @@
1010

1111
#include <Eigen/Core>
1212
#include <QStringList>
13+
#include <QPoint>
1314

1415
class QJsonObject;
1516
class JpegDecoder;
1617
class QImage;
18+
class QRect;
1719

1820
class ImageSet {
1921
public:
@@ -31,6 +33,7 @@ class ImageSet {
3133
float idealLightDistance2 = 0.0f; //squared, used when rescaling intensity
3234

3335
int current_line = 0;
36+
std::vector<QPoint> offsets; //align offsets
3437

3538
ImageSet(const char *path = nullptr);
3639
~ImageSet();
@@ -51,6 +54,9 @@ class ImageSet {
5154
//open images and starts the decoders
5255
bool initImages(const char *path); //path points to the dir of the images.
5356

57+
void setCrop(QRect &crop, std::vector<QPointF> &offsets);
58+
59+
5460
void setLights(std::vector<Eigen::Vector3f> &lights, Dome::LightConfiguration configuration);
5561
std::vector<Eigen::Vector3f> &lights() { return lights1; }
5662

src/project.cpp

+1
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ void Project::operator=(const Project& project) {
5050
whites.push_back(new White(*w));
5151

5252
crop = project.crop;
53+
offsets = project.offsets;
5354
pixelSize = project.pixelSize;
5455
name = project.name;
5556
authors = project.authors;

0 commit comments

Comments
 (0)