Page Menu
Home
Phabricator
Search
Configure Global Search
Log In
Files
F1182
0001-Fixed-a-crash-for-loading-images-with-active-scalars.patch
Public
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Authored By
khlebnikov
Oct 15 2015, 9:46 PM
2015-10-15 21:46:59 (UTC+2)
Size
3 KB
Referenced Files
None
Subscribers
None
0001-Fixed-a-crash-for-loading-images-with-active-scalars.patch
View Options
From effbeb19bc3a3d7d1abb453f5d042c5a1b62c525 Mon Sep 17 00:00:00 2001
From: Rostislav Khlebnikov <r.khlebnikov@gmail.com>
Date: Thu, 15 Oct 2015 20:42:56 +0100
Subject: [PATCH] Fixed a crash for loading images with active scalars not set.
---
Modules/Core/src/IO/mitkImageVtkLegacyIO.cpp | 23 ++++++++++++++++++++++-
Modules/Core/src/IO/mitkImageVtkXmlIO.cpp | 23 ++++++++++++++++++++++-
2 files changed, 44 insertions(+), 2 deletions(-)
diff --git a/Modules/Core/src/IO/mitkImageVtkLegacyIO.cpp b/Modules/Core/src/IO/mitkImageVtkLegacyIO.cpp
index a24fd7e..a0204fb 100644
--- a/Modules/Core/src/IO/mitkImageVtkLegacyIO.cpp
+++ b/Modules/Core/src/IO/mitkImageVtkLegacyIO.cpp
@@ -25,6 +25,8 @@ See LICENSE.txt or http://www.mitk.org for details.
#include <vtkStructuredPoints.h>
#include <vtkErrorCode.h>
#include <vtkSmartPointer.h>
+#include <vtkPointData.h>
+#include <vtkDataArray.h>
namespace mitk {
@@ -44,9 +46,28 @@ std::vector<BaseData::Pointer> ImageVtkLegacyIO::Read()
if ( reader->GetOutput() != NULL )
{
+ auto pointData = reader->GetOutput()->GetPointData();
+
+ if (pointData->GetScalars() == nullptr)
+ {
+ for (int i = 0; i < pointData->GetNumberOfArrays(); ++i)
+ {
+ if (pointData->GetArray(i)->GetNumberOfComponents() == 1)
+ {
+ pointData->SetActiveAttribute(i, vtkDataSetAttributes::SCALARS);
+ break;
+ }
+ }
+ }
+
+ if (pointData->GetScalars() == nullptr)
+ {
+ mitkThrow() << "mitkImageVtkXmlIO error: could not find scalars in the image.";
+ }
+
mitk::Image::Pointer output = mitk::Image::New();
output->Initialize(reader->GetOutput());
- output->SetVolume(reader->GetOutput()->GetScalarPointer());
+ output->SetVolume(pointData->GetScalars()->GetVoidPointer(0));
std::vector<BaseData::Pointer> result;
result.push_back(output.GetPointer());
return result;
diff --git a/Modules/Core/src/IO/mitkImageVtkXmlIO.cpp b/Modules/Core/src/IO/mitkImageVtkXmlIO.cpp
index 881f70b..3da6aa9 100644
--- a/Modules/Core/src/IO/mitkImageVtkXmlIO.cpp
+++ b/Modules/Core/src/IO/mitkImageVtkXmlIO.cpp
@@ -25,6 +25,8 @@ See LICENSE.txt or http://www.mitk.org for details.
#include <vtkImageData.h>
#include <vtkErrorCode.h>
#include <vtkSmartPointer.h>
+#include <vtkPointData.h>
+#include <vtkDataArray.h>
namespace mitk {
@@ -69,9 +71,28 @@ std::vector<BaseData::Pointer> ImageVtkXmlIO::Read()
if (reader->GetOutput() != NULL)
{
+ auto pointData = reader->GetOutput()->GetPointData();
+
+ if (pointData->GetScalars() == nullptr)
+ {
+ for (int i = 0; i < pointData->GetNumberOfArrays(); ++i)
+ {
+ if (pointData->GetArray(i)->GetNumberOfComponents() == 1)
+ {
+ pointData->SetActiveAttribute(i, vtkDataSetAttributes::SCALARS);
+ break;
+ }
+ }
+ }
+
+ if (pointData->GetScalars() == nullptr)
+ {
+ mitkThrow() << "mitkImageVtkXmlIO error: could not find scalars in the image.";
+ }
+
mitk::Image::Pointer output = mitk::Image::New();
output->Initialize(reader->GetOutput());
- output->SetVolume(reader->GetOutput()->GetScalarPointer());
+ output->SetVolume(pointData->GetScalars()->GetVoidPointer(0));
std::vector<BaseData::Pointer> result;
result.push_back(output.GetPointer());
return result;
--
1.8.4.msysgit.0
File Metadata
Details
Attached
Mime Type
text/plain
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
1143
Default Alt Text
0001-Fixed-a-crash-for-loading-images-with-active-scalars.patch (3 KB)
Attached To
Mode
T18496: Crash while loading *.vtk Images with ITK VTKImageIO
Attached
Detach File
Event Timeline
khlebnikov
added a comment.
Oct 15 2015, 9:46 PM
2015-10-15 21:46:59 (UTC+2)
Comment Actions
patch
Log In to Comment