Merge pull request #7083 from afabri/Demo-readBMP-GF

3d Demo: Try to read bmp files
This commit is contained in:
Laurent Rineau 2022-12-14 10:39:53 +01:00
commit ae3ae6e8d6
5 changed files with 612 additions and 356 deletions

View File

@ -69,26 +69,57 @@ read_vtk_image_data(vtkImageData* vtk_image, Image_3::Own owning = Image_3::OWN_
image->ty = static_cast<float>(offset[1]);
image->tz = static_cast<float>(offset[2]);
image->endianness = ::_getEndianness();
int vtk_type = vtk_image->GetScalarType();
if(vtk_type == VTK_SIGNED_CHAR) vtk_type = VTK_CHAR;
if(vtk_type < 0 || vtk_type > VTK_DOUBLE)
vtk_type = VTK_DOUBLE;
const VTK_to_ImageIO_type_mapper& imageio_type =
VTK_to_ImageIO_type[vtk_type];
if(vtk_type < 0 || vtk_type > VTK_DOUBLE) vtk_type = VTK_DOUBLE;
const VTK_to_ImageIO_type_mapper& imageio_type = VTK_to_ImageIO_type[vtk_type];
image->wdim = imageio_type.wdim;
image->wordKind = imageio_type.wordKind;
image->sign = imageio_type.sign;
const int cn = vtk_image->GetNumberOfScalarComponents();
if (!vtk_image->GetPointData() || !vtk_image->GetPointData()->GetScalars()) {
::_freeImage(image);
return Image_3();
}
// If there is more than a scalar per point, vtk_image->data is not immediately
// interpretable in Image_3->data
CGAL_assertion(owning == Image_3::OWN_THE_DATA || cn == 1);
CGAL_assertion(vtk_image->GetPointData()->GetScalars()->GetNumberOfTuples() == dims[0]*dims[1]*dims[2]);
if(owning == Image_3::OWN_THE_DATA) {
image->data = ::ImageIO_alloc(dims[0]*dims[1]*dims[2]*image->wdim);
// std::cerr << "GetNumberOfTuples()=" << vtk_image->GetPointData()->GetScalars()->GetNumberOfTuples()
// << "\nimage->size()=" << dims[0]*dims[1]*dims[2]
// << "\nwdim=" << image->wdim << '\n';
int dims_n = dims[0]*dims[1]*dims[2];
image->data = ::ImageIO_alloc(dims_n * image->wdim);
// std::cerr << "GetNumberOfTuples() = " << vtk_image->GetPointData()->GetScalars()->GetNumberOfTuples() << "\n"
// << "components = " << cn << "\n"
// << "wdim = " << image->wdim << "\n"
// << "image->size() = " << dims_n << std::endl;
if(cn == 1) {
vtk_image->GetPointData()->GetScalars()->ExportToVoidPointer(image->data);
} else {
std::cerr << "Warning: input has " << cn << " components; only the value of the first component will be used." << std::endl;
CGAL_assertion(cn >= 3); // if it's more than 1, it needs to be at least 3
// cast the data void pointers to make it possible to do pointer arithmetic
char* src = static_cast<char*>(vtk_image->GetPointData()->GetScalars()->GetVoidPointer(0));
char* dest = static_cast<char*>(image->data);
for(int i=0; i<dims_n; ++i)
{
// multiply by image->wdim because we casted to char* and not the actual data type
memcpy(dest + image->wdim*i, src + cn*image->wdim*i, image->wdim);
// Check that we are not discarding useful data (i.e., green & blue are identical to red)
CGAL_assertion(memcmp(src + cn*image->wdim*i, src + cn*image->wdim*i + image->wdim, image->wdim) == 0);
CGAL_assertion(memcmp(src + cn*image->wdim*i, src + cn*image->wdim*i + 2*image->wdim, image->wdim) == 0);
}
}
} else {
image->data = vtk_image->GetPointData()->GetScalars()->GetVoidPointer(0);
}

View File

@ -87,7 +87,7 @@ public:
protected:
Image_shared_ptr image_ptr;
// implementation in src/CGAL_ImageIO/Image_3.cpp
// implementation in Image_3_impl.h
bool private_read(_image* im, Own own_the_data = OWN_THE_DATA);
public:

View File

@ -14,7 +14,7 @@ public:
/// The default-constructor. The object is invalid until a call to `read()`.
Image_3();
/// Open an 3D image file.
/// Open a 3D image file.
///
/// Returns `true` if the file was sucessfully loaded.
bool read(const char* file);

View File

@ -6,8 +6,8 @@
<rect>
<x>0</x>
<y>0</y>
<width>421</width>
<height>370</height>
<width>561</width>
<height>347</height>
</rect>
</property>
<property name="sizePolicy">
@ -19,24 +19,8 @@
<property name="windowTitle">
<string>Load a 3D image</string>
</property>
<layout class="QGridLayout" name="gridLayout" rowstretch="0,0,0,0,0,0,0,0,0,0,0,0,0" columnstretch="0,1">
<item row="11" column="0" colspan="2">
<spacer name="verticalSpacer">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>0</height>
</size>
</property>
</spacer>
</item>
<item row="0" column="1">
<widget class="QComboBox" name="imageType"/>
</item>
<item row="12" column="0" colspan="2">
<layout class="QGridLayout" name="gridLayout" rowstretch="0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0" columnstretch="0,0">
<item row="25" column="0" colspan="2">
<widget class="QDialogButtonBox" name="buttonBox">
<property name="orientation">
<enum>Qt::Horizontal</enum>
@ -46,33 +30,31 @@
</property>
</widget>
</item>
<item row="0" column="0">
<widget class="QLabel" name="label_3">
<property name="text">
<string>Please choose the image &amp;type</string>
</property>
<property name="buddy">
<cstring>imageType</cstring>
</property>
</widget>
</item>
<item row="2" column="0" colspan="2">
<item row="3" column="0" colspan="2">
<widget class="QGroupBox" name="groupBox">
<property name="title">
<string>Drawing settings for a segment image</string>
<string/>
</property>
<layout class="QGridLayout" name="gridLayout_2">
<item row="0" column="0">
<layout class="QGridLayout" name="gridLayout_3" columnstretch="0,1">
<item row="2" column="1">
<widget class="QComboBox" name="precisionList">
<property name="editable">
<bool>false</bool>
<property name="leftMargin">
<number>0</number>
</property>
<property name="rightMargin">
<number>0</number>
</property>
<property name="horizontalSpacing">
<number>0</number>
</property>
</widget>
</item>
<item row="0" column="0">
<widget class="QLabel" name="label_2">
<layout class="QGridLayout" name="gridLayout_3" columnstretch="0,0">
<property name="horizontalSpacing">
<number>0</number>
</property>
<property name="verticalSpacing">
<number>6</number>
</property>
<item row="2" column="0">
<widget class="QLabel" name="drawingPrecisionCommentLabel">
<property name="font">
<font>
<pointsize>11</pointsize>
@ -80,20 +62,23 @@
</font>
</property>
<property name="text">
<string>1:x means that x voxels of the original image are represented by 1 cube in the drawn image</string>
<string>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p align=&quot;center&quot;&gt;&lt;span style=&quot; font-size:10pt;&quot;&gt;1:x means that x voxels of the original image are represented by 1 cube in the drawn image&lt;/span&gt;&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
</property>
<property name="wordWrap">
<bool>true</bool>
</property>
</widget>
</item>
<item row="2" column="0">
<widget class="QLabel" name="label">
<item row="1" column="0">
<widget class="QLabel" name="drawingPrecisionLabel">
<property name="enabled">
<bool>true</bool>
</property>
<property name="lineWidth">
<number>1</number>
</property>
<property name="text">
<string>Please choose the image drawing &amp;precision</string>
<string>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p align=&quot;right&quot;&gt;Segmented image drawing &amp;amp;precision &lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
</property>
<property name="wordWrap">
<bool>true</bool>
@ -103,11 +88,81 @@
</property>
</widget>
</item>
<item row="1" column="1">
<widget class="QComboBox" name="precisionList">
<property name="editable">
<bool>false</bool>
</property>
</widget>
</item>
</layout>
</item>
</layout>
</widget>
</item>
<item row="5" column="0" colspan="2">
<spacer name="verticalSpacer">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>40</height>
</size>
</property>
</spacer>
</item>
<item row="20" column="0" colspan="2">
<spacer name="verticalSpacer_2">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>40</height>
</size>
</property>
</spacer>
</item>
<item row="0" column="0">
<widget class="QLabel" name="imageTypeLabel">
<property name="text">
<string>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p align=&quot;right&quot;&gt;Image &amp;amp;type&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
</property>
<property name="buddy">
<cstring>imageType</cstring>
</property>
</widget>
</item>
<item row="6" column="0" colspan="2">
<widget class="Line" name="line">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
</widget>
</item>
<item row="21" column="0" alignment="Qt::AlignRight">
<widget class="QLabel" name="smoothImageLabel">
<property name="text">
<string>Smooth image data</string>
</property>
</widget>
</item>
<item row="21" column="1" alignment="Qt::AlignLeft">
<widget class="QCheckBox" name="smoothImage">
<property name="text">
<string/>
</property>
<property name="checked">
<bool>true</bool>
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="QComboBox" name="imageType"/>
</item>
</layout>
</widget>
<resources/>

File diff suppressed because it is too large Load Diff