Selaa lähdekoodia

-added root directory selection for PASCAL files.
-added root directory as an option to the options list

gapchich 13 vuotta sitten
vanhempi
commit
a8cc096bc3
4 muutettua tiedostoa jossa 121 lisäystä ja 5 poistoa
  1. 27 4
      ImageLabeler.cpp
  2. 2 1
      ImageLabeler.h
  3. 79 0
      OptionsForm.cpp
  4. 13 0
      OptionsForm.h

+ 27 - 4
ImageLabeler.cpp

@@ -472,7 +472,7 @@ ImageLabeler::ImageLabeler(QWidget *aParent) :
 		action_options_,
 		SIGNAL(triggered()),
 		&options_form_,
-		SLOT(show())
+		SLOT(showOptions())
 		);
 	connect(
 		button_add_label_,
@@ -660,6 +660,8 @@ ImageLabeler::ImageLabeler(QWidget *aParent) :
 	image_holder_->setLabelColorList(&list_label_colors_);
 	image_holder_->setMainLabelNum(&main_label_);
 	image_holder_->setImage(image_);
+
+	options_form_.setPASCALpath(&PASCALpath_);
 }
 
 ImageLabeler::~ImageLabeler()
@@ -1807,6 +1809,23 @@ ImageLabeler::loadPascalFile()
 		/* NOTREACHED */
 	}
 
+	if (PASCALpath_.isEmpty()) {
+		showWarning(tr("before opening first PASCAL file please choose \"root\" directory"
+			" where a folder with segmentations,"
+			" a folder with polygons,"
+			" a folder with image descriptions and"
+			" a folder with the pure images are."));
+
+		QFileDialog fileDialog(0, tr("root directory for the PASCAL files"));
+		fileDialog.setFileMode(QFileDialog::Directory);
+		if (fileDialog.exec())
+			PASCALpath_ = fileDialog.selectedFiles().last();
+		else {
+			return;
+			/* NOTREACHED */
+		}
+	}
+
 	QFileDialog fileDialog(0, tr("Load pascal file"));
 	fileDialog.setAcceptMode(QFileDialog::AcceptOpen);
 	fileDialog.setDefaultSuffix("xml");
@@ -1829,7 +1848,7 @@ ImageLabeler::loadPascalFile()
 
 	clearAllTool();
 	clearLabelList();
-	if (loadPascalFile(filename)) {
+	if (loadPascalFile(filename, PASCALpath_)) {
 		enableTools();
 		Image newImage;
 		newImage.image_ = current_image_;
@@ -1844,7 +1863,7 @@ ImageLabeler::loadPascalFile()
 }
 
 bool
-ImageLabeler::loadPascalFile(QString aFilename)
+ImageLabeler::loadPascalFile(QString aFilename, QString aPath)
 {
 	QDomDocument doc;
 	QFile file(aFilename);
@@ -1871,7 +1890,11 @@ ImageLabeler::loadPascalFile(QString aFilename)
 	QDomElement elements = doc.documentElement();
 	QDomNode rootNode = elements.firstChild();
 	QString string;
-	QString path = getPathFromFilename(aFilename);
+	QString path;
+	if (aPath.isEmpty())
+		path = getPathFromFilename(aFilename);
+	else
+		path = aPath + "/";
 	QString filename;
 	QStringList labels;
 	labels << "BACKGROUND";

+ 2 - 1
ImageLabeler.h

@@ -84,7 +84,7 @@ protected:
 	void objectsToXml(QDomDocument *aDoc, QDomElement *aRoot);
 	void addImage(Image *anImage);
 	bool loadInfo(QString filename);
-	bool loadPascalFile(QString aFilename);
+	bool loadPascalFile(QString aFilename, QString aPath = QString());
 	bool loadPascalPolys(QString aFilename);
 	bool selectImage(int anImageID);
 
@@ -256,6 +256,7 @@ private:
 
 	QString image_description_;
 	QString tags_;
+	QString PASCALpath_;
 	QList< Image > *list_images_;
 	//QStringList::iterator current_image_;
 	QString current_image_;

+ 79 - 0
OptionsForm.cpp

@@ -9,32 +9,51 @@
 
 #include <QCheckBox>
 #include <QPushButton>
+#include <QLabel>
 #include <QBoxLayout>
 #include <QMessageBox>
 #include <QApplication>
 #include <QDesktopWidget>
+#include <QFileDialog>
+#include <QKeyEvent>
 
 OptionsForm::OptionsForm(QWidget *aParent)
 	: QWidget(aParent)
 {
 	setWindowTitle(tr("Options"));
 
+	PASCALpath_ = 0;
+
 	layout_v_ = new QVBoxLayout(this);
+	layout_PASCAL_root_ = new QHBoxLayout;
 	layout_h_ = new QHBoxLayout;
 
 	auto_color_generation_ = new QCheckBox(this);
 	auto_color_generation_->setText(tr("Automatic label color generation"));
+	button_set_PASCAL_root_ = new QPushButton(this);
+	button_set_PASCAL_root_->setText(tr("set PASCAL root path"));
+	label_PASCAL_root_ = new QLabel("", this);
 	button_ok_ = new QPushButton(this);
 	button_ok_->setText(tr("OK"));
 	button_cancel_ = new QPushButton(this);
 	button_cancel_->setText(tr("Cancel"));
 
 	layout_v_->addWidget(auto_color_generation_);
+	layout_v_->addLayout(layout_PASCAL_root_);
 	layout_v_->addLayout(layout_h_);
 
+	layout_PASCAL_root_->addWidget(button_set_PASCAL_root_);
+	layout_PASCAL_root_->addWidget(label_PASCAL_root_);
+
 	layout_h_->addWidget(button_ok_);
 	layout_h_->addWidget(button_cancel_);
 
+	connect(
+		button_set_PASCAL_root_,
+		SIGNAL(clicked()),
+		this,
+		SLOT(newPascalPath())
+		);
 	connect(
 		button_ok_,
 		SIGNAL(clicked()),
@@ -55,6 +74,8 @@ OptionsForm::OptionsForm(QWidget *aParent)
 OptionsForm::~OptionsForm()
 {
 	delete auto_color_generation_;
+	delete button_set_PASCAL_root_;
+	delete label_PASCAL_root_;
 	delete button_ok_;
 	delete button_cancel_;
 
@@ -68,12 +89,70 @@ OptionsForm::setOptions()
 	hide();
 }
 
+void
+OptionsForm::setPASCALpath(QString *aPath)
+{
+	if (!aPath) {
+		return;
+		/* NOTREACHED */
+	}
+
+	PASCALpath_ = aPath;
+}
+
+void
+OptionsForm::newPascalPath()
+{
+	QString newPath;
+	QFileDialog fileDialog(0, tr("root directory for the PASCAL files"));
+	fileDialog.setFileMode(QFileDialog::Directory);
+	if (fileDialog.exec())
+		newPath = fileDialog.selectedFiles().last();
+	else {
+		return;
+		/* NOTREACHED */
+	}
+
+	if (newPath.isEmpty()) {
+		return;
+		/* NOTREACHED */
+	}
+
+	*PASCALpath_ = newPath;
+	label_PASCAL_root_->setText(newPath);
+}
+
 bool
 OptionsForm::autoColorGeneration()
 {
 	return auto_color_generation_->isChecked();
 }
 
+void
+OptionsForm::showOptions()
+{
+	if (!PASCALpath_) {
+		return;
+		/* NOTREACHED */
+	}
+
+	if (PASCALpath_->isEmpty())
+		label_PASCAL_root_->setText(tr("root path is not set yet"));
+	else
+		label_PASCAL_root_->setText(*PASCALpath_);
+
+	show();
+}
+
+void
+OptionsForm::keyPressEvent(QKeyEvent *anEvent)
+{
+	if ((Qt::Key_Enter == anEvent->key() ||
+		Qt::Key_Return == anEvent->key())) {
+		setOptions();
+	}
+}
+
 /*
  *
  */

+ 13 - 0
OptionsForm.h

@@ -12,30 +12,43 @@
 
 class QCheckBox;
 class QPushButton;
+class QLabel;
 class QVBoxLayout;
 class QHBoxLayout;
+class QKeyEvent;
 
 class OptionsForm : public QWidget {
 	Q_OBJECT
+protected:
+	void keyPressEvent(QKeyEvent *anEvent);
 public:
 	OptionsForm(QWidget *aParent = 0);
 	virtual ~OptionsForm();
 
 	bool autoColorGeneration();
+	void setPASCALpath(QString *aPath);
 
 public slots:
 	void setOptions();
+	void showOptions();
+	void newPascalPath();
 
 signals:
 	void optionsSet();
 
 private:
 	QCheckBox *auto_color_generation_;
+	QPushButton *button_set_PASCAL_root_;
+	QLabel *label_PASCAL_root_;
 	QPushButton *button_ok_;
 	QPushButton *button_cancel_;
 
 	QVBoxLayout *layout_v_;
+	QHBoxLayout *layout_PASCAL_root_;
 	QHBoxLayout *layout_h_;
+
+	/* pointers to variables */
+	QString *PASCALpath_;
 };
 
 #endif /* __OPTIONSFORM_H__ */