Skip to content

Commit

Permalink
Recover image label (original path) when opening a project.
Browse files Browse the repository at this point in the history
  • Loading branch information
steveicarus committed Apr 26, 2011
1 parent cbd2584 commit 8f450ca
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 18 deletions.
3 changes: 2 additions & 1 deletion src/AstrobenchMain.cpp
Expand Up @@ -27,6 +27,7 @@
# include <QString>
# include "AstrobenchMain.h"
# include "StackItemWidget.h"
# include <iostream>
# include <cassert>

using namespace vips;
Expand Down Expand Up @@ -194,7 +195,7 @@ void AstrobenchMain::stack_next_image_button_slot_()
// the project settings.
StackItemWidget*cur = new StackItemWidget(this, item_id);
ident_map_[cur->ident()] = cur;
project_->setValue(QString("items/%1").arg(cur->ident()), "present");
project_->setValue(QString("items/%1").arg(cur->ident()), next_path_);

// Move the image to the StackItemWidget.
cur->set_image(next_path_, *next_image_);
Expand Down
28 changes: 21 additions & 7 deletions src/AstrobenchMain_proj.cpp
Expand Up @@ -118,6 +118,7 @@ void AstrobenchMain::menu_open_project_slot_(void)

QFileDialog selector(this, tr("Select an existing project"));
selector.setFilter(QDir::Dirs);
selector.setFileMode(QFileDialog::Directory);
selector.setNameFilter("Icarus AstroBench project (*.iab)");

int rc = selector.exec();
Expand All @@ -134,6 +135,13 @@ void AstrobenchMain::menu_open_project_slot_(void)
// Check that the directory exists, and that it contains
// sensible project files. Then open the project.
project_path_ = files[0];
if (! project_path_.exists()) {
QMessageBox::information(this, tr("Internal Error"),
tr("Selected path [%1] doesn't exist.").arg(project_path_.path()));
project_path_ = QString();
return;
}

assert(project_path_.exists());
if (!project_path_.exists(ASTRO_PROJECT_INI)) {
QMessageBox::information(this, tr("Error"),
Expand Down Expand Up @@ -161,16 +169,22 @@ void AstrobenchMain::menu_open_project_slot_(void)
StackItemWidget*cur = new StackItemWidget(this, item_id);
ident_map_[cur->ident()] = cur;

QString use_label = project_->value(QString("items/")+item_str).toString();
printf("XXXX recover image %u\n", cur->ident());
cur->recover_data();
cur->recover_data(use_label);
}

// First recover the base image and push it to the stack.
unsigned base_id = project_->value("base_image").toUInt();
printf("XXXX Use image %u as the base image\n", base_id);
StackItemWidget*base = ident_map_[base_id];
assert(base);
push_stack_item_(base);
// First recover the base image and push it to the
// stack. Defensively catch the case that this is an empty
// project.
StackItemWidget*base = 0;
if (ident_map_.size() > 0) {
unsigned base_id = project_->value("base_image").toUInt();
printf("XXXX Use image %u as the base image\n", base_id);
base = ident_map_[base_id];
assert(base);
push_stack_item_(base);
}

// Now push all the remaining images to the stack.
for (map<unsigned,StackItemWidget*>::iterator cur = ident_map_.begin()
Expand Down
21 changes: 13 additions & 8 deletions src/StackItemWidget.cpp
Expand Up @@ -20,8 +20,10 @@
# include "StackItemWidget.h"
# include "AstrobenchMain.h"
# include <stdio.h>
# include <iostream>
# include <cassert>

using namespace std;
using namespace vips;

StackItemWidget::StackItemWidget(AstrobenchMain*am, unsigned id, QWidget*parent)
Expand Down Expand Up @@ -49,13 +51,14 @@ StackItemWidget::~StackItemWidget()
* and uses it to generate the various other default (generated) image
* members.
*/
void StackItemWidget::initialize_from_image_(const QString&path)
void StackItemWidget::initialize_from_image_(const QString&use_label)
{
accumulated_stats_ = VDMask();

processed_ = image_;
accumulated_ = image_;
accumulated_stats_ = accumulated_.stats();
ui.stack_item_path->setText(path);
ui.stack_item_path->setToolTip(path);
ui.stack_item_path->setText(use_label);
ui.stack_item_path->setToolTip(use_label);

vips::VImage ref_tmp;
if (image_.Bands() == 3)
Expand All @@ -66,26 +69,26 @@ void StackItemWidget::initialize_from_image_(const QString&path)
image_fwfft_ = ref_tmp.fwfft();
}

void StackItemWidget::set_image(const QString&path, vips::VImage img)
void StackItemWidget::set_image(const QString&use_label, vips::VImage img)
{
QString fname = QString("item.%1.base.v").arg(ident_);
QString fpath = astromain_->project_root().filePath(fname);
VImage file (fpath.toStdString().c_str(), "w");
img.write(file);

image_ = file;
initialize_from_image_(path);
initialize_from_image_(use_label);
}

void StackItemWidget::recover_data(void)
void StackItemWidget::recover_data(const QString&use_label)
{
QString fname = QString("item.%1.base.v").arg(ident_);
assert(astromain_->project_root().exists(fname));
QString fpath = astromain_->project_root().filePath(fname);

VImage file (fpath.toStdString().c_str(), "r");
image_ = file;
initialize_from_image_(fname);
initialize_from_image_(use_label);
}

void StackItemWidget::calculate_offset_from(StackItemWidget*that)
Expand Down Expand Up @@ -166,6 +169,8 @@ const VImage& StackItemWidget::accumulated_image(void) const

unsigned StackItemWidget::accumulated_pixel_max()
{
if (accumulated_stats_.size() == 0)
accumulated_stats_ = accumulated_.stats();
return accumulated_stats_(1,0);
}

Expand Down
4 changes: 2 additions & 2 deletions src/StackItemWidget.h
Expand Up @@ -37,12 +37,12 @@ class StackItemWidget : public QWidget {
unsigned ident() const { return ident_; }

// Set the raw image for this item.
void set_image(const QString&path, vips::VImage img);
void set_image(const QString&use_label, vips::VImage img);

// If opening an existing project, this method is used in
// place of the set_image method to recover the image from the
// image file.
void recover_data();
void recover_data(const QString&use_label);

// Calculate the offset of this image from the image argument,
// which is expected to the be base image.
Expand Down

0 comments on commit 8f450ca

Please sign in to comment.