简体   繁体   中英

VTK 7 - why object gets destroyed?

I am trying to load raw image data using vtkImageImport and display 2D texture:

    char* data = (char*)imgData->data(); // size is 786432

    vtkSmartPointer<vtkImageImport> importer = vtkSmartPointer<vtkImageImport>::New();
    importer->SetWholeExtent(0, 511, 0, 511, 0, 0);
    importer->SetDataExtentToWholeExtent();
    importer->SetDataScalarTypeToUnsignedChar();
    importer->SetImportVoidPointer(data);
    importer->SetNumberOfScalarComponents(3);
    importer->Update();
    double bounds[6];
    vtkImageData* vtk_image_data = importer->GetOutput(); // this is null
    vtk_image_data->GetBounds(bounds);

When I call importer->Update() then destructor of vtkDataSet is invoked, and importer->GetOutput() returns null... Any ideas why that happens?

I compiled and ran your code on MSVC 2010 with VTK 6.2.0. I did not get any null vtk_image_data. check out some macro pre-processors it might help.

Finally, I have found cause of the problem. In general, we are porting VTK to use with Google Chrome's Portable Native Client (PNaCl) and I had to create project vtkCommonCore from scratch and set all settings to work with PPAPI\\PNACL. I was missing special build rule for vtkInformationDataObjectKey.cxx which has to be set manually in .vcxproj:

<ClCompile Include="vtkInformationDataObjectKey.cxx">
      <PreprocessorDefinitions Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">vtkCommonDataModel_ENABLED;%(PreprocessorDefinitions)</PreprocessorDefinitions>
      <PreprocessorDefinitions Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">vtkCommonDataModel_ENABLED;%(PreprocessorDefinitions)</PreprocessorDefinitions>
      <PreprocessorDefinitions Condition="'$(Configuration)|$(Platform)'=='MinSizeRel|Win32'">vtkCommonDataModel_ENABLED;%(PreprocessorDefinitions)</PreprocessorDefinitions>
      <PreprocessorDefinitions Condition="'$(Configuration)|$(Platform)'=='RelWithDebInfo|Win32'">vtkCommonDataModel_ENABLED;%(PreprocessorDefinitions)</PreprocessorDefinitions>
      <PreprocessorDefinitions Condition="'$(Configuration)|$(Platform)'=='Debug|PPAPI'">vtkCommonDataModel_ENABLED;%(PreprocessorDefinitions)</PreprocessorDefinitions>
      <!-- adding above rule for Debug|PPAPI solved the problem -->
</ClCompile>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM