From 2f7ccf76eb70c6311412757f02486bd0680ef738 Mon Sep 17 00:00:00 2001 From: Maxime Gimeno Date: Thu, 6 Oct 2016 09:27:32 +0200 Subject: [PATCH] Upgrades : - The dialog won't let the user create an image if its size doesn't match the file's - the offset is counted in the images's size - the fields of the dialog have tooltips - If the raw_image has a WK_FLOAT, the image is automatically detected as gray-level - Images can be saved in .inr.gz Remaining : convert images to the right format to be meshed when asked to. --- CGAL_ImageIO/include/CGAL/ImageIO_impl.h | 1 - CGAL_ImageIO/include/CGAL/Image_3.h | 9 +- .../Plugins/Mesh_3/Io_image_plugin.cpp | 76 +++-- .../Plugins/Mesh_3/Raw_image_dialog.cpp | 35 ++- .../Plugins/Mesh_3/Raw_image_dialog.h | 5 +- .../Polyhedron/Plugins/Mesh_3/raw_image.ui | 297 +++++++++++------- 6 files changed, 272 insertions(+), 151 deletions(-) diff --git a/CGAL_ImageIO/include/CGAL/ImageIO_impl.h b/CGAL_ImageIO/include/CGAL/ImageIO_impl.h index 86969c9d783..b4e6653ae2d 100644 --- a/CGAL_ImageIO/include/CGAL/ImageIO_impl.h +++ b/CGAL_ImageIO/include/CGAL/ImageIO_impl.h @@ -856,7 +856,6 @@ _image* _readNonInterlacedImage(const char *name) { on stdout */ CGAL_INLINE_FUNCTION int _writeImage(_image *im, const char *name_to_be_written ) { - int r = ImageIO_NO_ERROR; std::size_t length = 0; char *name = NULL; diff --git a/CGAL_ImageIO/include/CGAL/Image_3.h b/CGAL_ImageIO/include/CGAL/Image_3.h index 602ec4944b9..b1723d5e948 100644 --- a/CGAL_ImageIO/include/CGAL/Image_3.h +++ b/CGAL_ImageIO/include/CGAL/Image_3.h @@ -164,11 +164,16 @@ public: const double vx = 1, const double vy = 1, const double vz = 1, - const unsigned int offset = 0) + const unsigned int offset = 0, + std::size_t wdim=1, + WORD_KIND wk = WK_FIXED, + SIGN sign = SGN_UNSIGNED + ) { return private_read(::_readImage_raw(file, rx,ry,rz, - vx,vy,vz,offset)); + vx,vy,vz,offset, + wdim, wk, sign)); } public: diff --git a/Polyhedron/demo/Polyhedron/Plugins/Mesh_3/Io_image_plugin.cpp b/Polyhedron/demo/Polyhedron/Plugins/Mesh_3/Io_image_plugin.cpp index 40221a336af..52cfbba42d6 100644 --- a/Polyhedron/demo/Polyhedron/Plugins/Mesh_3/Io_image_plugin.cpp +++ b/Polyhedron/demo/Polyhedron/Plugins/Mesh_3/Io_image_plugin.cpp @@ -12,6 +12,7 @@ #include "ui_Image_res_dialog.h" #include +#include #include #include #include @@ -34,6 +35,7 @@ #include #include #include +#include #include #include @@ -210,6 +212,7 @@ public: this->message_interface = mi; this->scene = scene_interface; this->mw = mainWindow; + this->is_gray = false; x_control = NULL; y_control = NULL; z_control = NULL; @@ -274,7 +277,12 @@ public: CGAL::Three::Scene_item* load(QFileInfo fileinfo); bool canSave(const CGAL::Three::Scene_item*); - bool save(const CGAL::Three::Scene_item*, QFileInfo) { return false; } + bool save(const CGAL::Three::Scene_item* item, QFileInfo fi) { + const Scene_image_item* im_item = qobject_cast(item); + + point_image p_im = *im_item->image()->image(); + return _writeImage(&p_im, fi.filePath().toUtf8()) == 0; + } QString name() const { return "segmented images"; } @@ -439,6 +447,7 @@ private: vtkDemandDrivenPipeline* executive; vtkImageGaussianSmooth* smoother; #endif // CGAL_USE_VTK + bool is_gray; Messages_interface* message_interface; QMessageBox msgBox; QAction* planeSwitch; @@ -816,17 +825,24 @@ Io_image_plugin::load(QFileInfo fileinfo) { if(qmb.exec() == QMessageBox::Yes) { Raw_image_dialog raw_dialog; raw_dialog.label_file_size->setText(QString("%1 B").arg(fileinfo.size())); + raw_dialog.buttonBox->button(QDialogButtonBox::Open)->setEnabled(false); if( raw_dialog.exec() ){ + QApplication::setOverrideCursor(Qt::WaitCursor); if(image->read_raw(fileinfo.filePath().toUtf8(), - raw_dialog.dim_x->value(), - raw_dialog.dim_y->value(), - raw_dialog.dim_z->value(), - raw_dialog.spacing_x->value(), - raw_dialog.spacing_y->value(), - raw_dialog.spacing_z->value(), - raw_dialog.offset->value())){ + raw_dialog.dim_x->value(), + raw_dialog.dim_y->value(), + raw_dialog.dim_z->value(), + raw_dialog.spacing_x->value(), + raw_dialog.spacing_y->value(), + raw_dialog.spacing_z->value(), + raw_dialog.offset->value(), + raw_dialog.image_word_size(), + raw_dialog.image_word_kind(), + raw_dialog.image_sign()) + ){ + is_gray = (raw_dialog.image_word_kind() == WK_FLOAT); QSettings settings; settings.beginGroup(QUrl::toPercentEncoding(fileinfo.absoluteFilePath())); settings.setValue("is_raw", true); @@ -837,6 +853,9 @@ Io_image_plugin::load(QFileInfo fileinfo) { settings.setValue("spacing_y", raw_dialog.spacing_y->value()); settings.setValue("spacing_z", raw_dialog.spacing_z->value()); settings.setValue("offset", raw_dialog.offset->value()); + settings.setValue("wdim", QVariant::fromValue(raw_dialog.image_word_size())); + settings.setValue("wk", raw_dialog.image_word_kind()); + settings.setValue("sign", raw_dialog.image_sign()); settings.endGroup(); }else { success = false; @@ -845,7 +864,7 @@ Io_image_plugin::load(QFileInfo fileinfo) { success = false; } }else { - success = false; + success = false; } if(!success){ delete image; @@ -855,13 +874,13 @@ Io_image_plugin::load(QFileInfo fileinfo) { // Get display precision QDialog dialog; ui.setupUi(&dialog); - + connect(ui.buttonBox, SIGNAL(accepted()), &dialog, SLOT(accept())); connect(ui.buttonBox, SIGNAL(rejected()), &dialog, SLOT(reject())); connect(ui.imageType, SIGNAL(currentIndexChanged(int)), this, SLOT(on_imageType_changed(int))); dialog.setWindowFlags(Qt::Dialog|Qt::CustomizeWindowHint|Qt::WindowCloseButtonHint); - + // Add precision values to the dialog for ( int i=1 ; i<9 ; ++i ) { @@ -873,22 +892,29 @@ Io_image_plugin::load(QFileInfo fileinfo) { ui.imageType->addItem(QString("Segmented image")); ui.imageType->addItem(QString("Gray-level image")); - + QString type; + int voxel_scale; // Open window QApplication::restoreOverrideCursor(); - int return_code = dialog.exec(); - if(return_code != QDialog::Accepted) + if(!is_gray) { - delete image; - return NULL; - } - QApplication::setOverrideCursor(Qt::WaitCursor); - - // Get selected precision - int voxel_scale = ui.precisionList->currentIndex() + 1; + int return_code = dialog.exec(); + if(return_code != QDialog::Accepted) + { + delete image; + return NULL; + } + + // Get selected precision + voxel_scale = ui.precisionList->currentIndex() + 1; + + //Get the image type + type = ui.imageType->currentText(); + } + else + type = "Gray-level image"; + QApplication::setOverrideCursor(Qt::WaitCursor); - //Get the image type - QString type = ui.imageType->currentText(); Scene_image_item* image_item; if(type == "Gray-level image") { @@ -907,9 +933,9 @@ Io_image_plugin::load(QFileInfo fileinfo) { return image_item; } -bool Io_image_plugin::canSave(const CGAL::Three::Scene_item*) +bool Io_image_plugin::canSave(const CGAL::Three::Scene_item* item) { - return false; + return qobject_cast(item); } bool Io_image_plugin::loadDCM(QString dirname) diff --git a/Polyhedron/demo/Polyhedron/Plugins/Mesh_3/Raw_image_dialog.cpp b/Polyhedron/demo/Polyhedron/Plugins/Mesh_3/Raw_image_dialog.cpp index 9e5e1f9b738..71accbcf4f8 100644 --- a/Polyhedron/demo/Polyhedron/Plugins/Mesh_3/Raw_image_dialog.cpp +++ b/Polyhedron/demo/Polyhedron/Plugins/Mesh_3/Raw_image_dialog.cpp @@ -1,19 +1,27 @@ #include "Raw_image_dialog.h" +#include Raw_image_dialog::Raw_image_dialog(QWidget* parent) - : QDialog(parent) + : QDialog(parent) { setupUi(this); } void Raw_image_dialog::update_image_size() { - label_image_size->setNum((int)image_word_size() * - dim_x->value() * - dim_y->value() * - dim_z->value()); + int size = (int)image_word_size() * + dim_x->value() * + dim_y->value() * + dim_z->value() + + offset->value(); + label_image_size->setText(QString("%1 B").arg(size)); + + if(label_image_size->text() == label_file_size->text()) + buttonBox->button(QDialogButtonBox::Open)->setEnabled(true); + else + buttonBox->button(QDialogButtonBox::Open)->setEnabled(false); } -unsigned int Raw_image_dialog::image_word_size() const { +std::size_t Raw_image_dialog::image_word_size() const { if(short_bt->isChecked()) return 2; if(int_bt->isChecked()) @@ -26,3 +34,18 @@ unsigned int Raw_image_dialog::image_word_size() const { return 1; } +WORD_KIND Raw_image_dialog::image_word_kind() const +{ + if(float_bt->isChecked() || + double_bt->isChecked()) + return WK_FLOAT; + else + return WK_FIXED; +} +SIGN Raw_image_dialog::image_sign() const +{ + if(signed_bt->isChecked()) + return SGN_SIGNED; + else + return SGN_UNSIGNED; +} diff --git a/Polyhedron/demo/Polyhedron/Plugins/Mesh_3/Raw_image_dialog.h b/Polyhedron/demo/Polyhedron/Plugins/Mesh_3/Raw_image_dialog.h index 82551e020e3..4442330ee11 100644 --- a/Polyhedron/demo/Polyhedron/Plugins/Mesh_3/Raw_image_dialog.h +++ b/Polyhedron/demo/Polyhedron/Plugins/Mesh_3/Raw_image_dialog.h @@ -2,6 +2,7 @@ #define RAW_IMAGE_DIALOG_H #include "ui_raw_image.h" +#include class Raw_image_dialog : public QDialog, public Ui::Raw_image_dialog { @@ -10,7 +11,9 @@ class Raw_image_dialog : public QDialog, public Ui::Raw_image_dialog public: Raw_image_dialog(QWidget* parent = 0); - unsigned int image_word_size() const; + std::size_t image_word_size() const; + WORD_KIND image_word_kind() const; + SIGN image_sign() const; private Q_SLOTS: void update_image_size(); diff --git a/Polyhedron/demo/Polyhedron/Plugins/Mesh_3/raw_image.ui b/Polyhedron/demo/Polyhedron/Plugins/Mesh_3/raw_image.ui index e270d1de917..789eb657926 100644 --- a/Polyhedron/demo/Polyhedron/Plugins/Mesh_3/raw_image.ui +++ b/Polyhedron/demo/Polyhedron/Plugins/Mesh_3/raw_image.ui @@ -1,7 +1,8 @@ - + + Raw_image_dialog - - + + 0 0 @@ -9,54 +10,72 @@ 342 - + Open raw image - + - - + + Image &value type - - - - + + + + + Word kind of the image : short int. + + Short (16 bits) - - - + + + + Word kind of the image : float. + + Float - - - + + + + Word kind of the image : integer. + + Int (32 bits) - - - + + + + Word kind of the image : double. + + Double - - - + + + + Specifies if the image's word kind is signed. + + Signed - - - + + + + Word kind of the image : unsigned byte. + + char (8 bits) @@ -65,161 +84,191 @@ - - + + Image dimensions - + - - - - + + + + + Number of voxel along the axis. + + &Dimensions: - + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter - + dim_x - - - + + + + Changing those values will scale the image according to the proportions between vx, vy and vz. + + &Spacing: - + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter - + spacing_x - - - + + + + Number of voxels along the X axis. + + x: - + 100000000 - - - + + + + Number of voxels along the Y axis. + + y: - + 100000000 - - - + + + + Number of voxels along the Z axis. + + z: - + 100000000 - - - + + + + Voxel size in x. + + vx: - + 5 - + 1.000000000000000 - - - + + + + Voxel size in y. + + vy: - + 5 - + 1.000000000000000 - - - + + + + Voxel size in z. + + vz: - + 5 - + 1.000000000000000 - - - + + + + Specifies how many bytes must be skipped before reading the data. (Use it to skip unhandled headers fo example) + + &Offset: - + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter - + offset - - - + + + + Specifies how many bytes must be skipped before reading the data. (Use it to skip unhandled headers fo example) + + bytes - + 999999999 - - - + + + Image size: - + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter - - - + + + 0 - - - + + + File size: - + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter - - - + + + 0 @@ -230,8 +279,8 @@ - - + + QDialogButtonBox::Cancel|QDialogButtonBox::Open @@ -261,11 +310,11 @@ signed_bt setDisabled(bool) - + 47 112 - + 553 94 @@ -277,11 +326,11 @@ signed_bt setDisabled(bool) - + 564 127 - + 564 94 @@ -293,11 +342,11 @@ Raw_image_dialog accept() - + 191 316 - + 183 313 @@ -309,11 +358,11 @@ Raw_image_dialog reject() - + 253 319 - + 252 312 @@ -325,11 +374,11 @@ Raw_image_dialog update_image_size() - + 178 187 - + 99 141 @@ -341,11 +390,11 @@ Raw_image_dialog update_image_size() - + 473 178 - + 441 142 @@ -357,11 +406,11 @@ Raw_image_dialog update_image_size() - + 71 52 - + 137 3 @@ -373,11 +422,11 @@ Raw_image_dialog update_image_size() - + 117 81 - + 49 6 @@ -389,11 +438,11 @@ Raw_image_dialog update_image_size() - + 137 111 - + 67 -5 @@ -405,11 +454,11 @@ Raw_image_dialog update_image_size() - + 358 49 - + 584 52 @@ -421,11 +470,11 @@ Raw_image_dialog update_image_size() - + 332 186 - + 271 142 @@ -437,16 +486,32 @@ Raw_image_dialog update_image_size() - + 514 119 - + 581 116 + + offset + valueChanged(int) + Raw_image_dialog + update_image_size() + + + 225 + 278 + + + 292 + 170 + + + update_image_size()