Since the last topic I posted this in got quite of topic from the original topic I want to post this here again.
As stated in the title this code unexpectedly crashes when calling paint() on the initiated View3D. This sadly crashes before the program can write any console output.
After the crash VS points to ThrowCastAndCallException
in VariantArrayHandleContainer.cxx
with a ErrorBadValue
exception.
#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().
I really hope for some help here, semes like im tipping from error to error here. Any suggestions what could cause this?
Thank you for your time,
David
Edit:
I forgot the example data to run this with:
https://drive.google.com/drive/folders/1IaU8p2LC-gSlFff-Qv8aOC8IcbWLLUUj?usp=sharing
You will have to adjust the path to the .raw file in the .mhd file before running.