Clean-up.

This commit is contained in:
Maxime Gimeno 2016-10-07 15:48:34 +02:00
parent 198b12f787
commit e0faeefdb8
3 changed files with 36 additions and 56 deletions

View File

@ -806,6 +806,24 @@ bool Io_image_plugin::canLoad() const {
return true;
}
template<typename Word>
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; x<image->xdim(); ++x)
for(std::size_t y = 0; y<image->ydim(); ++y)
for(std::size_t z = 0; z<image->zdim(); ++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; x<image->xdim(); ++x)
for(std::size_t y = 0; y<image->ydim(); ++y)
for(std::size_t z = 0; z<image->zdim(); ++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<double>(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; x<image->xdim(); ++x)
for(std::size_t y = 0; y<image->ydim(); ++y)
for(std::size_t z = 0; z<image->zdim(); ++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<short>(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; x<image->xdim(); ++x)
for(std::size_t y = 0; y<image->ydim(); ++y)
for(std::size_t z = 0; z<image->zdim(); ++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<int>(image);
break;
}
default:
is_gray = false;
break;

View File

@ -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 {

View File

@ -23,17 +23,17 @@
<item row="2" column="0">
<widget class="QRadioButton" name="short_bt">
<property name="toolTip">
<string>Word kind of the image : short int.</string>
<string/>
</property>
<property name="text">
<string>Short (16 bits)</string>
<string>Short int (16 bits)</string>
</property>
</widget>
</item>
<item row="3" column="0">
<widget class="QRadioButton" name="float_bt">
<property name="toolTip">
<string>Word kind of the image : float.</string>
<string/>
</property>
<property name="text">
<string>Float</string>
@ -43,7 +43,7 @@
<item row="0" column="1">
<widget class="QRadioButton" name="int_bt">
<property name="toolTip">
<string>Word kind of the image : integer.</string>
<string/>
</property>
<property name="text">
<string>Int (32 bits)</string>
@ -53,7 +53,7 @@
<item row="3" column="1">
<widget class="QRadioButton" name="double_bt">
<property name="toolTip">
<string>Word kind of the image : double.</string>
<string/>
</property>
<property name="text">
<string>Double</string>
@ -73,7 +73,7 @@
<item row="0" column="0">
<widget class="QRadioButton" name="char_bt">
<property name="toolTip">
<string>Word kind of the image : unsigned byte.</string>
<string/>
</property>
<property name="text">
<string>char (8 bits)</string>
@ -213,7 +213,7 @@
<item row="3" column="0">
<widget class="QLabel" name="offset_label">
<property name="toolTip">
<string>Specifies how many bytes must be skipped before reading the data. (Use it to skip unhandled headers fo example)</string>
<string/>
</property>
<property name="text">
<string>&amp;Offset:</string>
@ -229,7 +229,7 @@
<item row="3" column="1">
<widget class="QSpinBox" name="offset">
<property name="toolTip">
<string>Specifies how many bytes must be skipped before reading the data. (Use it to skip unhandled headers fo example)</string>
<string>Specifies how many bytes must be skipped before reading the data. (Use it to skip unhandled headers for example.)</string>
</property>
<property name="suffix">
<string> bytes</string>