Does vtk not allow changing display images?

#include “vtkSmartPointer.h”

#include<vtkRenderer.h>
#include <vtkRenderWindowInteractor.h>
#include “vtkAutoInit.h”
#include<vtkImageData.h>
#include <vtkDICOMImageReader.h>
#include <vtkImageViewer2.h>
#include <vtkRenderWindowInteractor.h>
#include <vtkCallbackCommand.h>

VTK_MODULE_INIT(vtkRenderingOpenGL2);

VTK_MODULE_INIT(vtkInteractionStyle);
#include <vtkDICOMImageReader.h>
#include <vtkImageViewer2.h>
#include <vtkRenderWindowInteractor.h>

// 定义全局变量
vtkSmartPointer reader1;
vtkSmartPointer reader2;
vtkSmartPointer viewer;

// 按键事件回调函数
void KeyPressCallback(vtkObject* caller, long unsigned int vtkNotUsed(eventId), void* vtkNotUsed(clientData), void* vtkNotUsed(callData))
{
vtkRenderWindowInteractor* interactor = static_cast<vtkRenderWindowInteractor*>(caller);
std::string key = interactor->GetKeySym();

if (key == "1")
{
    viewer->SetInputConnection(reader1->GetOutputPort());
    viewer->SetColorLevel(reader1->GetOutput()->GetScalarRange()[0] + reader1->GetOutput()->GetScalarRange()[1]);
    viewer->SetColorWindow(reader1->GetOutput()->GetScalarRange()[1] - reader1->GetOutput()->GetScalarRange()[0]);
    viewer->GetRenderer()->ResetCamera();
    viewer->Render();
}
else if (key == "2")
{

    viewer->SetInputConnection(reader2->GetOutputPort());
    viewer->SetColorLevel(reader2->GetOutput()->GetScalarRange()[0] + reader2->GetOutput()->GetScalarRange()[1]);
    viewer->SetColorWindow(reader2->GetOutput()->GetScalarRange()[1] - reader2->GetOutput()->GetScalarRange()[0]);
    
    viewer->Render();
}

}

int main(int argc, char* argv[])
{
// 创建 DICOM 文件读取器
reader1 = vtkSmartPointer::New();
reader1->SetFileName(“1.dcm”);
reader1->Update();

reader2 = vtkSmartPointer<vtkDICOMImageReader>::New();
reader2->SetFileName("2.dcm");
reader2->Update();

// 创建图像显示器
viewer = vtkSmartPointer<vtkImageViewer2>::New();
viewer->SetInputConnection(reader1->GetOutputPort());
viewer->SetupInteractor(nullptr);
viewer->SetColorLevel(reader1->GetOutput()->GetScalarRange()[0] + reader1->GetOutput()->GetScalarRange()[1]);
viewer->SetColorWindow(reader1->GetOutput()->GetScalarRange()[1] - reader1->GetOutput()->GetScalarRange()[0]);
viewer->SetSize(400,400);
viewer->Render();

// 创建交互器
vtkSmartPointer<vtkRenderWindowInteractor> interactor = vtkSmartPointer<vtkRenderWindowInteractor>::New();
interactor->SetRenderWindow(viewer->GetRenderWindow());

// 添加按键事件处理器
vtkSmartPointer<vtkCallbackCommand> keypressCallback = vtkSmartPointer<vtkCallbackCommand>::New();
keypressCallback->SetCallback(KeyPressCallback);
interactor->AddObserver(vtkCommand::KeyPressEvent, keypressCallback);

// 开始交互循环
interactor->Initialize();
interactor->Start();

return 0;

}

This is my code. Why can’t I switch images correctly?