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