mirror of https://github.com/CGAL/cgal
Merge pull request #7083 from afabri/Demo-readBMP-GF
3d Demo: Try to read bmp files
This commit is contained in:
commit
ae3ae6e8d6
|
|
@ -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->ty = static_cast<float>(offset[1]);
|
||||||
image->tz = static_cast<float>(offset[2]);
|
image->tz = static_cast<float>(offset[2]);
|
||||||
image->endianness = ::_getEndianness();
|
image->endianness = ::_getEndianness();
|
||||||
|
|
||||||
int vtk_type = vtk_image->GetScalarType();
|
int vtk_type = vtk_image->GetScalarType();
|
||||||
if(vtk_type == VTK_SIGNED_CHAR) vtk_type = VTK_CHAR;
|
if(vtk_type == VTK_SIGNED_CHAR) vtk_type = VTK_CHAR;
|
||||||
if(vtk_type < 0 || vtk_type > VTK_DOUBLE)
|
if(vtk_type < 0 || vtk_type > VTK_DOUBLE) vtk_type = VTK_DOUBLE;
|
||||||
vtk_type = VTK_DOUBLE;
|
const VTK_to_ImageIO_type_mapper& imageio_type = VTK_to_ImageIO_type[vtk_type];
|
||||||
const VTK_to_ImageIO_type_mapper& imageio_type =
|
|
||||||
VTK_to_ImageIO_type[vtk_type];
|
|
||||||
image->wdim = imageio_type.wdim;
|
image->wdim = imageio_type.wdim;
|
||||||
image->wordKind = imageio_type.wordKind;
|
image->wordKind = imageio_type.wordKind;
|
||||||
image->sign = imageio_type.sign;
|
image->sign = imageio_type.sign;
|
||||||
|
|
||||||
|
const int cn = vtk_image->GetNumberOfScalarComponents();
|
||||||
|
|
||||||
if (!vtk_image->GetPointData() || !vtk_image->GetPointData()->GetScalars()) {
|
if (!vtk_image->GetPointData() || !vtk_image->GetPointData()->GetScalars()) {
|
||||||
::_freeImage(image);
|
::_freeImage(image);
|
||||||
return Image_3();
|
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]);
|
CGAL_assertion(vtk_image->GetPointData()->GetScalars()->GetNumberOfTuples() == dims[0]*dims[1]*dims[2]);
|
||||||
|
|
||||||
if(owning == Image_3::OWN_THE_DATA) {
|
if(owning == Image_3::OWN_THE_DATA) {
|
||||||
image->data = ::ImageIO_alloc(dims[0]*dims[1]*dims[2]*image->wdim);
|
int dims_n = dims[0]*dims[1]*dims[2];
|
||||||
// std::cerr << "GetNumberOfTuples()=" << vtk_image->GetPointData()->GetScalars()->GetNumberOfTuples()
|
image->data = ::ImageIO_alloc(dims_n * image->wdim);
|
||||||
// << "\nimage->size()=" << dims[0]*dims[1]*dims[2]
|
|
||||||
// << "\nwdim=" << image->wdim << '\n';
|
// std::cerr << "GetNumberOfTuples() = " << vtk_image->GetPointData()->GetScalars()->GetNumberOfTuples() << "\n"
|
||||||
vtk_image->GetPointData()->GetScalars()->ExportToVoidPointer(image->data);
|
// << "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 {
|
} else {
|
||||||
image->data = vtk_image->GetPointData()->GetScalars()->GetVoidPointer(0);
|
image->data = vtk_image->GetPointData()->GetScalars()->GetVoidPointer(0);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -87,7 +87,7 @@ public:
|
||||||
protected:
|
protected:
|
||||||
Image_shared_ptr image_ptr;
|
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);
|
bool private_read(_image* im, Own own_the_data = OWN_THE_DATA);
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
|
||||||
|
|
@ -14,7 +14,7 @@ public:
|
||||||
/// The default-constructor. The object is invalid until a call to `read()`.
|
/// The default-constructor. The object is invalid until a call to `read()`.
|
||||||
Image_3();
|
Image_3();
|
||||||
|
|
||||||
/// Open an 3D image file.
|
/// Open a 3D image file.
|
||||||
///
|
///
|
||||||
/// Returns `true` if the file was sucessfully loaded.
|
/// Returns `true` if the file was sucessfully loaded.
|
||||||
bool read(const char* file);
|
bool read(const char* file);
|
||||||
|
|
|
||||||
|
|
@ -6,8 +6,8 @@
|
||||||
<rect>
|
<rect>
|
||||||
<x>0</x>
|
<x>0</x>
|
||||||
<y>0</y>
|
<y>0</y>
|
||||||
<width>421</width>
|
<width>561</width>
|
||||||
<height>370</height>
|
<height>347</height>
|
||||||
</rect>
|
</rect>
|
||||||
</property>
|
</property>
|
||||||
<property name="sizePolicy">
|
<property name="sizePolicy">
|
||||||
|
|
@ -19,24 +19,8 @@
|
||||||
<property name="windowTitle">
|
<property name="windowTitle">
|
||||||
<string>Load a 3D image</string>
|
<string>Load a 3D image</string>
|
||||||
</property>
|
</property>
|
||||||
<layout class="QGridLayout" name="gridLayout" rowstretch="0,0,0,0,0,0,0,0,0,0,0,0,0" columnstretch="0,1">
|
<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="11" column="0" colspan="2">
|
<item row="25" 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">
|
|
||||||
<widget class="QDialogButtonBox" name="buttonBox">
|
<widget class="QDialogButtonBox" name="buttonBox">
|
||||||
<property name="orientation">
|
<property name="orientation">
|
||||||
<enum>Qt::Horizontal</enum>
|
<enum>Qt::Horizontal</enum>
|
||||||
|
|
@ -46,33 +30,31 @@
|
||||||
</property>
|
</property>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
<item row="0" column="0">
|
<item row="3" column="0" colspan="2">
|
||||||
<widget class="QLabel" name="label_3">
|
|
||||||
<property name="text">
|
|
||||||
<string>Please choose the image &type</string>
|
|
||||||
</property>
|
|
||||||
<property name="buddy">
|
|
||||||
<cstring>imageType</cstring>
|
|
||||||
</property>
|
|
||||||
</widget>
|
|
||||||
</item>
|
|
||||||
<item row="2" column="0" colspan="2">
|
|
||||||
<widget class="QGroupBox" name="groupBox">
|
<widget class="QGroupBox" name="groupBox">
|
||||||
<property name="title">
|
<property name="title">
|
||||||
<string>Drawing settings for a segment image</string>
|
<string/>
|
||||||
</property>
|
</property>
|
||||||
<layout class="QGridLayout" name="gridLayout_2">
|
<layout class="QGridLayout" name="gridLayout_2">
|
||||||
|
<property name="leftMargin">
|
||||||
|
<number>0</number>
|
||||||
|
</property>
|
||||||
|
<property name="rightMargin">
|
||||||
|
<number>0</number>
|
||||||
|
</property>
|
||||||
|
<property name="horizontalSpacing">
|
||||||
|
<number>0</number>
|
||||||
|
</property>
|
||||||
<item row="0" column="0">
|
<item row="0" column="0">
|
||||||
<layout class="QGridLayout" name="gridLayout_3" columnstretch="0,1">
|
<layout class="QGridLayout" name="gridLayout_3" columnstretch="0,0">
|
||||||
<item row="2" column="1">
|
<property name="horizontalSpacing">
|
||||||
<widget class="QComboBox" name="precisionList">
|
<number>0</number>
|
||||||
<property name="editable">
|
</property>
|
||||||
<bool>false</bool>
|
<property name="verticalSpacing">
|
||||||
</property>
|
<number>6</number>
|
||||||
</widget>
|
</property>
|
||||||
</item>
|
<item row="2" column="0">
|
||||||
<item row="0" column="0">
|
<widget class="QLabel" name="drawingPrecisionCommentLabel">
|
||||||
<widget class="QLabel" name="label_2">
|
|
||||||
<property name="font">
|
<property name="font">
|
||||||
<font>
|
<font>
|
||||||
<pointsize>11</pointsize>
|
<pointsize>11</pointsize>
|
||||||
|
|
@ -80,20 +62,23 @@
|
||||||
</font>
|
</font>
|
||||||
</property>
|
</property>
|
||||||
<property name="text">
|
<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><html><head/><body><p align="center"><span style=" font-size:10pt;">1:x means that x voxels of the original image are represented by 1 cube in the drawn image</span></p></body></html></string>
|
||||||
</property>
|
</property>
|
||||||
<property name="wordWrap">
|
<property name="wordWrap">
|
||||||
<bool>true</bool>
|
<bool>true</bool>
|
||||||
</property>
|
</property>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
<item row="2" column="0">
|
<item row="1" column="0">
|
||||||
<widget class="QLabel" name="label">
|
<widget class="QLabel" name="drawingPrecisionLabel">
|
||||||
|
<property name="enabled">
|
||||||
|
<bool>true</bool>
|
||||||
|
</property>
|
||||||
<property name="lineWidth">
|
<property name="lineWidth">
|
||||||
<number>1</number>
|
<number>1</number>
|
||||||
</property>
|
</property>
|
||||||
<property name="text">
|
<property name="text">
|
||||||
<string>Please choose the image drawing &precision</string>
|
<string><html><head/><body><p align="right">Segmented image drawing &amp;precision </p></body></html></string>
|
||||||
</property>
|
</property>
|
||||||
<property name="wordWrap">
|
<property name="wordWrap">
|
||||||
<bool>true</bool>
|
<bool>true</bool>
|
||||||
|
|
@ -103,11 +88,81 @@
|
||||||
</property>
|
</property>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
|
<item row="1" column="1">
|
||||||
|
<widget class="QComboBox" name="precisionList">
|
||||||
|
<property name="editable">
|
||||||
|
<bool>false</bool>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
</layout>
|
</layout>
|
||||||
</item>
|
</item>
|
||||||
</layout>
|
</layout>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</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><html><head/><body><p align="right">Image &amp;type</p></body></html></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>
|
</layout>
|
||||||
</widget>
|
</widget>
|
||||||
<resources/>
|
<resources/>
|
||||||
|
|
|
||||||
File diff suppressed because it is too large
Load Diff
Loading…
Reference in New Issue