# VTKm: Reading DataSet from Legacy .vtk-File

**URL:** https://discourse.vtk.org/t/vtkm-reading-dataset-from-legacy-vtk-file/3285
**Category:** Support
**Created:** [May 12, 2020, 2:28pm UTC](https://discourse.vtk.org/t/vtkm-reading-dataset-from-legacy-vtk-file/3285 "2020-05-12T14:28:44Z")
**Posts on this page:** 10
**Page:** 2

<div class="post-metadata">

### Author: ![RobertMaynard](https://discourse.vtk.org/user_avatar/discourse.vtk.org/robertmaynard/32/24_2.png) [@RobertMaynard](https://discourse.vtk.org/u/RobertMaynard)
#### Post date: [June 3, 2020, 12:33pm UTC](https://discourse.vtk.org/t/vtkm-reading-dataset-from-legacy-vtk-file/3285/21 "2020-06-03T12:33:51Z")

</div>

Posting a minimal reproducible example of this error would make it significantly easier for me to figure out what is failing.

---

<div class="post-metadata">

### Author: ![McDave17](https://discourse.vtk.org/user_avatar/discourse.vtk.org/mcdave17/32/1778_2.png) [@McDave17](https://discourse.vtk.org/u/McDave17)
#### Post date: [June 4, 2020, 5:16pm UTC](https://discourse.vtk.org/t/vtkm-reading-dataset-from-legacy-vtk-file/3285/22 "2020-06-04T17:16:09Z")

</div>

Hi Robert,

I constructed an minimal example. You’ll have to configure/generate this with CMake (I used Visual Studio 2017 as generator and selected x64 while setting up the project) and then I compiled and ran it using VS2017.

You will have to adjust the path in the “SetFileName” call.

main.cpp:

```
#include <vtkImageData.h>
#include <vtkMetaImageReader.h>
#include <vtkNew.h>

#include <vtkmlib/ImageDataConverter.h>

#include <vtkm/cont/DataSet.h>
#include <vtkm/cont/Initialize.h>
#include <vtkm/filter/Contour.h>

int main(int argc, char* argv[]) {
    vtkm::cont::Initialize();

	vtkNew<vtkMetaImageReader> reader;
	reader->SetFileName("D:/Studium/Abschlussarbeit/minimal/Lobster_u8_301_324_56_LE.mhd");
	reader->Update();

    vtkImageData *rawData = reader->GetOutput();

	double *scalarRange = rawData->GetScalarRange();
    std::vector<vtkm::Float64> isoValues = { scalarRange[0] + 50, scalarRange[1] - 50 };

	vtkm::cont::DataSet dataSet = tovtkm::Convert(rawData, tovtkm::FieldsFlag::PointsAndCells);

    vtkm::filter::Contour contour;

	contour.SetActiveField("MetaImage");
    contour.SetIsoValues(isoValues);

    vtkm::cont::DataSet outData = contour.Execute(dataSet);

    return 0;
}

```

CMakeLists.txt:

```
cmake_minimum_required(VERSION 3.5)

set(PROJECT_NAME minimal)

project(${PROJECT_NAME} LANGUAGES CXX)

set(CMAKE_INCLUDE_CURRENT_DIR ON)

set(CMAKE_CXX_STANDARD 11)
set(CMAKE_CXX_STANDARD_REQUIRED ON)

find_package(VTK REQUIRED)
find_package(VTKm REQUIRED)

include_directories(${VTK_INCLUDE_DIRS})

add_executable(${PROJECT_NAME} main.cpp)

target_link_libraries(${PROJECT_NAME} ${VTK_LIBRARIES} vtkm_cont vtkm_filter vtkm_rendering)

```

I also uploaded the project to google drive (including the example data) for your convenience:  
[https://drive.google.com/drive/folders/1ltrgqf3oalukarXPNTwxJGCSosQV6fwC?usp=sharing](https://drive.google.com/drive/folders/1ltrgqf3oalukarXPNTwxJGCSosQV6fwC?usp=sharing)

Thank you for your time.  
David

---

<div class="post-metadata">

### Author: ![McDave17](https://discourse.vtk.org/user_avatar/discourse.vtk.org/mcdave17/32/1778_2.png) [@McDave17](https://discourse.vtk.org/u/McDave17)
#### Post date: [June 11, 2020, 1:45pm UTC](https://discourse.vtk.org/t/vtkm-reading-dataset-from-legacy-vtk-file/3285/23 "2020-06-11T13:45:23Z")

</div>

Hi Robert,

have you been able to reproduce the problem? I am at the limits of my ideas.

Best regards,  
David

---

<div class="post-metadata">

### Author: ![RobertMaynard](https://discourse.vtk.org/user_avatar/discourse.vtk.org/robertmaynard/32/24_2.png) [@RobertMaynard](https://discourse.vtk.org/u/RobertMaynard)
#### Post date: [June 11, 2020, 7:02pm UTC](https://discourse.vtk.org/t/vtkm-reading-dataset-from-legacy-vtk-file/3285/24 "2020-06-11T19:02:52Z")

</div>

I should have time this weekend to look at reproducing this

---

<div class="post-metadata">

### Author: ![McDave17](https://discourse.vtk.org/user_avatar/discourse.vtk.org/mcdave17/32/1778_2.png) [@McDave17](https://discourse.vtk.org/u/McDave17)
#### Post date: [June 14, 2020, 10:54am UTC](https://discourse.vtk.org/t/vtkm-reading-dataset-from-legacy-vtk-file/3285/25 "2020-06-14T10:54:10Z")

</div>

If you think it helps I can also send you a example with that same DataSet working in VTK? I still had no luck and it’s starting to be very frustrating to fail this early on in the project. Any info I can provide im happy to.

---

<div class="post-metadata">

### Author: ![RobertMaynard](https://discourse.vtk.org/user_avatar/discourse.vtk.org/robertmaynard/32/24_2.png) [@RobertMaynard](https://discourse.vtk.org/u/RobertMaynard)
#### Post date: [June 14, 2020, 11:43am UTC](https://discourse.vtk.org/t/vtkm-reading-dataset-from-legacy-vtk-file/3285/26 "2020-06-14T11:43:31Z")

</div>

> [@McDave17](#):
>
> ```auto
> #include <vtkImageData.h>
> #include <vtkMetaImageReader.h>
> #include <vtkNew.h>
> 
> #include <vtkmlib/ImageDataConverter.h>
> 
> #include <vtkm/cont/DataSet.h>
> #include <vtkm/cont/Initialize.h>
> #include <vtkm/filter/Contour.h>
> 
> ```

Using VTK master ( SHA1- 1011d1b432ad ) I am able to successfully run your example without issue on Ubuntu 18.04. ( I don’t have VTK built on a local windows machine )

---

<div class="post-metadata">

### Author: ![McDave17](https://discourse.vtk.org/user_avatar/discourse.vtk.org/mcdave17/32/1778_2.png) [@McDave17](https://discourse.vtk.org/u/McDave17)
#### Post date: [June 14, 2020, 2:16pm UTC](https://discourse.vtk.org/t/vtkm-reading-dataset-from-legacy-vtk-file/3285/27 "2020-06-14T14:16:00Z")

</div>

I’ll give it a try on Linux later. Thank you.

---

<div class="post-metadata">

### Author: ![McDave17](https://discourse.vtk.org/user_avatar/discourse.vtk.org/mcdave17/32/1778_2.png) [@McDave17](https://discourse.vtk.org/u/McDave17)
#### Post date: [June 19, 2020, 4:03pm UTC](https://discourse.vtk.org/t/vtkm-reading-dataset-from-legacy-vtk-file/3285/28 "2020-06-19T16:03:56Z")

</div>

So I successfully ran my minimal example on Linux Mint, but my actual program still is having trouble. As mentioned once upon a time when I first posted the original code was able to run with a generated DataSet.

Now when I add an actor to the pipeline there’s an fatal crash:

```
DataSet:
  CoordSystems[1]
    Coordinate System coords assoc= Points valueType=N4vtkm3VecIfLi3EEE storageType=N4vtkm4cont17StorageTagVirtualE numValues=5461344 bytes=65536128 [(0,0,0) (1,0,0) (2,0,0) ... (298,323,55) (299,323,55) (300,323,55)]
  CellSet 
  StructuredCellSet: 
   UniformConnectivity<3> pointDim[301 324 56] 
  Fields[1]
   MetaImage assoc= Points valueType=h storageType=N4vtkm4cont17StorageTagVirtualE numValues=5461344 bytes=5461344 [0 0 0 ... 0 0 10]

Loguru caught a signal: SIGSEGV
Segmentation fault

```

You might be able to reproduce this if you add following code to the main-method of the given minimal example.

```
vtkm::rendering::Actor actor(
     outData.GetCellSet(),
     outData.GetCoordinateSystem(),
     outData.GetField("MetaImage")
);

```

Any idea how this now can happen? Can you reproduce this? Thank you for your immense help so far, sorry for only making these baby step achievements.

Sincerely,  
David

---

<div class="post-metadata">

### Author: ![McDave17](https://discourse.vtk.org/user_avatar/discourse.vtk.org/mcdave17/32/1778_2.png) [@McDave17](https://discourse.vtk.org/u/McDave17)
#### Post date: [June 23, 2020, 8:45am UTC](https://discourse.vtk.org/t/vtkm-reading-dataset-from-legacy-vtk-file/3285/29 "2020-06-23T08:45:33Z")

</div>

The output just changed to this:

```
Loguru caught a signal: SIGSEGV

malloc_consolidate(): invalid chunk size

Loguru caught a signal: SIGABRT

Loguru caught a signal: SIGSEGV

Loguru caught a signal: SIGSEGV

Killed
```

---

<div class="post-metadata">

### Author: ![McDave17](https://discourse.vtk.org/user_avatar/discourse.vtk.org/mcdave17/32/1778_2.png) [@McDave17](https://discourse.vtk.org/u/McDave17)
#### Post date: [July 5, 2020, 8:23pm UTC](https://discourse.vtk.org/t/vtkm-reading-dataset-from-legacy-vtk-file/3285/30 "2020-07-05T20:23:35Z")

</div>

After resolving my issues in my development enviroment this issues does not longer appear. However I stumbled onto the next issue I hope to get some help with.

When compiling the following code with the dataset posted above it crashed without a ErrorMessage. Can somebody maybe be so kind and validate that this isn’t just a issue on my local machine?

```
#include <vtkMetaImageReader.h>
#include <vtkNew.h>
#include <vtkImageData.h>

#include <vtkmlib/ImageDataConverter.h>

#include <vtkm/cont/DataSet.h>
#include <vtkm/filter/Contour.h>
#include <vtkm/rendering/Actor.h>
#include <vtkm/rendering/CanvasRayTracer.h>
#include <vtkm/rendering/MapperRayTracer.h>
#include <vtkm/rendering/Scene.h>
#include <vtkm/rendering/View3D.h>

int main(int argc, char* argv[]) {
    vtkNew<vtkMetaImageReader> reader;
    reader->SetFileName("D:\\Studium\\Abschlussarbeit\\raw\\Lobster_u8_301_324_56_LE.mhd");
    reader->Update();
    double *scalarRange = reader->GetOutput()->GetScalarRange();

    vtkm::cont::DataSet inData = tovtkm::Convert(reader->GetOutput(), tovtkm::FieldsFlag::PointsAndCells);
    inData.PrintSummary(std::cout);

    vtkm::filter::Contour contour;
    contour.SetActiveField("MetaImage");
    std::vector<vtkm::Float64> isoValues = {scalarRange[0] + 50, scalarRange[1] - 50 };
    contour.SetIsoValues(isoValues);

    vtkm::cont::DataSet outData = contour.Execute(inData);
    outData.PrintSummary(std::cout);

    vtkm::rendering::Actor actor(
	    outData.GetCellSet(),
	    outData.GetCoordinateSystem(),
	    outData.GetField("MetaImage")
        );

    vtkm::rendering::Scene scene;
    scene.AddActor(actor);

    vtkm::rendering::MapperRayTracer mapper;
    vtkm::rendering::CanvasRayTracer canvas(1920, 1080);

    vtkm::rendering::View3D view(scene, mapper, canvas);
    view.Initialize();
    view.Paint();
}

```

It crashes right on the view.Paint().

Any ideas?

While there is no console output printed during the crash I can see in VS that a CastAndCallException is thrown. I wonder why that is not printed.

[Previous page](https://discourse.vtk.org/t/vtkm-reading-dataset-from-legacy-vtk-file/3285.md?page=1)
