diff --git a/src/AstrobenchMain.cpp b/src/AstrobenchMain.cpp index 5040181..86a3a1f 100644 --- a/src/AstrobenchMain.cpp +++ b/src/AstrobenchMain.cpp @@ -27,6 +27,7 @@ # include # include "AstrobenchMain.h" # include "StackItemWidget.h" +# include # include using namespace vips; @@ -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_); diff --git a/src/AstrobenchMain_proj.cpp b/src/AstrobenchMain_proj.cpp index baa7315..d554b9c 100644 --- a/src/AstrobenchMain_proj.cpp +++ b/src/AstrobenchMain_proj.cpp @@ -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(); @@ -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"), @@ -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::iterator cur = ident_map_.begin() diff --git a/src/StackItemWidget.cpp b/src/StackItemWidget.cpp index 42638f2..dd3647c 100644 --- a/src/StackItemWidget.cpp +++ b/src/StackItemWidget.cpp @@ -20,8 +20,10 @@ # include "StackItemWidget.h" # include "AstrobenchMain.h" # include +# include # include +using namespace std; using namespace vips; StackItemWidget::StackItemWidget(AstrobenchMain*am, unsigned id, QWidget*parent) @@ -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) @@ -66,7 +69,7 @@ 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); @@ -74,10 +77,10 @@ void StackItemWidget::set_image(const QString&path, vips::VImage img) 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)); @@ -85,7 +88,7 @@ void StackItemWidget::recover_data(void) 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) @@ -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); } diff --git a/src/StackItemWidget.h b/src/StackItemWidget.h index a2b9202..0e229ee 100644 --- a/src/StackItemWidget.h +++ b/src/StackItemWidget.h @@ -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.