VTK 7 - 为什么对象被破坏?

时间:2016-03-15 07:19:31

标签: c++ c++11 vtk

我正在尝试使用vtkImageImport加载原始图像数据并显示2D纹理:

    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);

当我调用importer->Update()时,调用了vtkDataSet的析构函数,importer->GetOutput()返回null ...任何想法为什么会发生这种情况?

2 个答案:

答案 0 :(得分:1)

我使用VTK 6.2.0在MSVC 2010上编译并运行了您的代码。我没有得到任何null vtk_image_data。看看它可能有用的一些宏预处理器。

答案 1 :(得分:0)

最后,我找到了问题的原因。一般情况下,我们正在移植VTK以与Google Chrome的Portable Native Client(PNaCl)一起使用,我必须从头开始创建项目vtkCommonCore并将所有设置设置为与PPAPI \ PNACL一起使用。我错过了vtkInformationDataObjectKey.cxx的特殊构建规则,必须在.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>