From 2f7ccf76eb70c6311412757f02486bd0680ef738 Mon Sep 17 00:00:00 2001 From: Maxime Gimeno Date: Thu, 6 Oct 2016 09:27:32 +0200 Subject: [PATCH 1/4] 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() From 60afd53120c378ef8991569d92e766d6c685ca5f Mon Sep 17 00:00:00 2001 From: Maxime Gimeno Date: Thu, 6 Oct 2016 15:38:36 +0200 Subject: [PATCH 2/4] Fix display and convert Double to Float types when an image is loaded to alow its meshing. --- .../Plugins/Mesh_3/Io_image_plugin.cpp | 30 ++++++++++++++++++- .../demo/Polyhedron/Scene_image_item.cpp | 2 +- 2 files changed, 30 insertions(+), 2 deletions(-) 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 52cfbba42d6..20d19509908 100644 --- a/Polyhedron/demo/Polyhedron/Plugins/Mesh_3/Io_image_plugin.cpp +++ b/Polyhedron/demo/Polyhedron/Plugins/Mesh_3/Io_image_plugin.cpp @@ -842,7 +842,35 @@ Io_image_plugin::load(QFileInfo fileinfo) { raw_dialog.image_word_kind(), raw_dialog.image_sign()) ){ - is_gray = (raw_dialog.image_word_kind() == WK_FLOAT); + switch(raw_dialog.image_word_kind()) + { + case WK_FLOAT: + is_gray = true; + if(raw_dialog.image_word_size() == 8) + { + float *f_data = new float[image->xdim()*image->ydim()*image->zdim()]; + double* d_data = (double*)(image->data()); + //convert image from double to float + for(std::size_t x = 0; xxdim(); ++x) + for(std::size_t y = 0; yydim(); ++y) + for(std::size_t z = 0; zzdim(); ++z) + { + std::size_t i =(z * image->ydim() + y) * image->xdim() + x; + f_data[i] =(float)d_data[i]; + } + + image->image()->data = (void*)f_data; + image->image()->wdim = 4; + } + break; + case WK_FIXED: + is_gray = false; + if(raw_dialog.image_word_size() == 8) + { + //convert image from double to float + } + break; + } QSettings settings; settings.beginGroup(QUrl::toPercentEncoding(fileinfo.absoluteFilePath())); settings.setValue("is_raw", true); diff --git a/Polyhedron/demo/Polyhedron/Scene_image_item.cpp b/Polyhedron/demo/Polyhedron/Scene_image_item.cpp index 9600b1385a2..33ae3f38580 100644 --- a/Polyhedron/demo/Polyhedron/Scene_image_item.cpp +++ b/Polyhedron/demo/Polyhedron/Scene_image_item.cpp @@ -333,7 +333,7 @@ Vertex_buffer_helper::push_vertex(std::size_t i, std::size_t j, std::size_t k) dk = 0.5; if (di == data_.xdim()) di = data_.xdim()-0.5; - if (dj == data_.xdim()) + if (dj == data_.ydim()) dj = data_.ydim()-0.5; if (dk == data_.zdim()) dk = data_.zdim()-0.5; From 198b12f7877e27ba4db961f2f8f66c653527bbc1 Mon Sep 17 00:00:00 2001 From: Maxime Gimeno Date: Fri, 7 Oct 2016 11:32:12 +0200 Subject: [PATCH 3/4] Casts not char images in float if the WORD_KIND is WK_WIXED to allow the meshing. --- .../Plugins/Mesh_3/Io_image_plugin.cpp | 54 ++++++++++++++++--- 1 file changed, 48 insertions(+), 6 deletions(-) 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 20d19509908..52b17f1857b 100644 --- a/Polyhedron/demo/Polyhedron/Plugins/Mesh_3/Io_image_plugin.cpp +++ b/Polyhedron/demo/Polyhedron/Plugins/Mesh_3/Io_image_plugin.cpp @@ -848,7 +848,7 @@ Io_image_plugin::load(QFileInfo fileinfo) { is_gray = true; if(raw_dialog.image_word_size() == 8) { - float *f_data = new float[image->xdim()*image->ydim()*image->zdim()]; + float *f_data = (float*)ImageIO_alloc(image->xdim()*image->ydim()*image->zdim()*sizeof(float)); double* d_data = (double*)(image->data()); //convert image from double to float for(std::size_t x = 0; xxdim(); ++x) @@ -858,17 +858,59 @@ Io_image_plugin::load(QFileInfo fileinfo) { std::size_t i =(z * image->ydim() + y) * image->xdim() + x; f_data[i] =(float)d_data[i]; } - + ImageIO_free(d_data); image->image()->data = (void*)f_data; image->image()->wdim = 4; } break; case WK_FIXED: - is_gray = false; - if(raw_dialog.image_word_size() == 8) + { + float *f_data = (float*)ImageIO_alloc(image->xdim()*image->ydim()*image->zdim()*sizeof(float)); + switch(raw_dialog.image_word_size()) { - //convert image from double to float + case 2: + { + is_gray = true; + //convert image from short to char + short* s_data = (short*)(image->data()); + for(std::size_t x = 0; xxdim(); ++x) + for(std::size_t y = 0; yydim(); ++y) + for(std::size_t z = 0; zzdim(); ++z) + { + std::size_t i =(z * image->ydim() + y) * image->xdim() + x; + f_data[i] =(char)s_data[i]; + } + ImageIO_free(s_data); + image->image()->data = (void*)f_data; + image->image()->wdim = 4; + image->image()->wordKind = WK_FLOAT; + break; } + case 4: + { + is_gray = true; + //convert image from int to char + int* i_data = (int*)(image->data()); + for(std::size_t x = 0; xxdim(); ++x) + for(std::size_t y = 0; yydim(); ++y) + for(std::size_t z = 0; zzdim(); ++z) + { + std::size_t i =(z * image->ydim() + y) * image->xdim() + x; + f_data[i] =(int)i_data[i]; + } + ImageIO_free(i_data); + image->image()->data = (void*)f_data; + image->image()->wdim = 4; + image->image()->wordKind = WK_FLOAT; + break; + } + default: + is_gray = false; + break; + } + break; + } + default: break; } QSettings settings; @@ -921,7 +963,7 @@ Io_image_plugin::load(QFileInfo fileinfo) { ui.imageType->addItem(QString("Gray-level image")); QString type; - int voxel_scale; + int voxel_scale = 0; // Open window QApplication::restoreOverrideCursor(); if(!is_gray) From e0faeefdb886ef2b39f1ff3dcafd0ac40ba3a428 Mon Sep 17 00:00:00 2001 From: Maxime Gimeno Date: Fri, 7 Oct 2016 15:48:34 +0200 Subject: [PATCH 4/4] Clean-up. --- .../Plugins/Mesh_3/Io_image_plugin.cpp | 68 ++++++------------- .../Plugins/Mesh_3/Raw_image_dialog.cpp | 8 ++- .../Polyhedron/Plugins/Mesh_3/raw_image.ui | 16 ++--- 3 files changed, 36 insertions(+), 56 deletions(-) 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 52b17f1857b..16ec17cb0ec 100644 --- a/Polyhedron/demo/Polyhedron/Plugins/Mesh_3/Io_image_plugin.cpp +++ b/Polyhedron/demo/Polyhedron/Plugins/Mesh_3/Io_image_plugin.cpp @@ -806,6 +806,24 @@ bool Io_image_plugin::canLoad() const { return true; } +template +void convert(Image* image) +{ + float *f_data = (float*)ImageIO_alloc(image->xdim()*image->ydim()*image->zdim()*sizeof(float)); + Word* d_data = (Word*)(image->data()); + //convert image from double to float + for(std::size_t x = 0; xxdim(); ++x) + for(std::size_t y = 0; yydim(); ++y) + for(std::size_t z = 0; zzdim(); ++z) + { + std::size_t i =(z * image->ydim() + y) * image->xdim() + x; + f_data[i] =(float)d_data[i]; + } + ImageIO_free(d_data); + image->image()->data = (void*)f_data; + image->image()->wdim = 4; + image->image()->wordKind = WK_FLOAT; +} CGAL::Three::Scene_item* Io_image_plugin::load(QFileInfo fileinfo) { QApplication::restoreOverrideCursor(); @@ -846,64 +864,20 @@ Io_image_plugin::load(QFileInfo fileinfo) { { case WK_FLOAT: is_gray = true; - if(raw_dialog.image_word_size() == 8) - { - float *f_data = (float*)ImageIO_alloc(image->xdim()*image->ydim()*image->zdim()*sizeof(float)); - double* d_data = (double*)(image->data()); - //convert image from double to float - for(std::size_t x = 0; xxdim(); ++x) - for(std::size_t y = 0; yydim(); ++y) - for(std::size_t z = 0; zzdim(); ++z) - { - std::size_t i =(z * image->ydim() + y) * image->xdim() + x; - f_data[i] =(float)d_data[i]; - } - ImageIO_free(d_data); - image->image()->data = (void*)f_data; - image->image()->wdim = 4; - } + convert(image); break; case WK_FIXED: { - float *f_data = (float*)ImageIO_alloc(image->xdim()*image->ydim()*image->zdim()*sizeof(float)); switch(raw_dialog.image_word_size()) { case 2: - { is_gray = true; - //convert image from short to char - short* s_data = (short*)(image->data()); - for(std::size_t x = 0; xxdim(); ++x) - for(std::size_t y = 0; yydim(); ++y) - for(std::size_t z = 0; zzdim(); ++z) - { - std::size_t i =(z * image->ydim() + y) * image->xdim() + x; - f_data[i] =(char)s_data[i]; - } - ImageIO_free(s_data); - image->image()->data = (void*)f_data; - image->image()->wdim = 4; - image->image()->wordKind = WK_FLOAT; + convert(image); break; - } case 4: - { is_gray = true; - //convert image from int to char - int* i_data = (int*)(image->data()); - for(std::size_t x = 0; xxdim(); ++x) - for(std::size_t y = 0; yydim(); ++y) - for(std::size_t z = 0; zzdim(); ++z) - { - std::size_t i =(z * image->ydim() + y) * image->xdim() + x; - f_data[i] =(int)i_data[i]; - } - ImageIO_free(i_data); - image->image()->data = (void*)f_data; - image->image()->wdim = 4; - image->image()->wordKind = WK_FLOAT; + convert(image); break; - } default: is_gray = false; break; 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 71accbcf4f8..92d7c116ef3 100644 --- a/Polyhedron/demo/Polyhedron/Plugins/Mesh_3/Raw_image_dialog.cpp +++ b/Polyhedron/demo/Polyhedron/Plugins/Mesh_3/Raw_image_dialog.cpp @@ -8,7 +8,7 @@ Raw_image_dialog::Raw_image_dialog(QWidget* parent) } void Raw_image_dialog::update_image_size() { - int size = (int)image_word_size() * + std::size_t size = image_word_size() * dim_x->value() * dim_y->value() * dim_z->value() + @@ -16,9 +16,15 @@ void Raw_image_dialog::update_image_size() { label_image_size->setText(QString("%1 B").arg(size)); if(label_image_size->text() == label_file_size->text()) + { buttonBox->button(QDialogButtonBox::Open)->setEnabled(true); + buttonBox->button(QDialogButtonBox::Open)->setToolTip(QString("")); + } else + { buttonBox->button(QDialogButtonBox::Open)->setEnabled(false); + buttonBox->button(QDialogButtonBox::Open)->setToolTip(QString("The image's size must fit the File's size.")); + } } std::size_t Raw_image_dialog::image_word_size() const { diff --git a/Polyhedron/demo/Polyhedron/Plugins/Mesh_3/raw_image.ui b/Polyhedron/demo/Polyhedron/Plugins/Mesh_3/raw_image.ui index 789eb657926..caca26af981 100644 --- a/Polyhedron/demo/Polyhedron/Plugins/Mesh_3/raw_image.ui +++ b/Polyhedron/demo/Polyhedron/Plugins/Mesh_3/raw_image.ui @@ -23,17 +23,17 @@ - Word kind of the image : short int. + - Short (16 bits) + Short int (16 bits) - Word kind of the image : float. + Float @@ -43,7 +43,7 @@ - Word kind of the image : integer. + Int (32 bits) @@ -53,7 +53,7 @@ - Word kind of the image : double. + Double @@ -73,7 +73,7 @@ - Word kind of the image : unsigned byte. + char (8 bits) @@ -213,7 +213,7 @@ - Specifies how many bytes must be skipped before reading the data. (Use it to skip unhandled headers fo example) + &Offset: @@ -229,7 +229,7 @@ - Specifies how many bytes must be skipped before reading the data. (Use it to skip unhandled headers fo example) + Specifies how many bytes must be skipped before reading the data. (Use it to skip unhandled headers for example.) bytes