Page MenuHomePhabricator

0001-Fixed-a-crash-for-loading-images-with-active-scalars.patch

Authored By
khlebnikov
Oct 15 2015, 9:46 PM
Size
3 KB
Referenced Files
None
Subscribers
None

0001-Fixed-a-crash-for-loading-images-with-active-scalars.patch

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

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)