VTKm: Reading DataSet from Legacy .vtk-File

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

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

Thank you for your time.
David

Hi Robert,

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

Best regards,
David

I should have time this weekend to look at reproducing this

1 Like

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.

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 )

1 Like

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

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

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

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.