hello ,everyone! i have code like that :
vtkSmartPointer ImageFillActor;
vtkSmartPointer Reslice;
vtkSmartPointer SliceToImageTransform;
vtkSmartPointer LookupTableFill;
vtkSmartPointer ImageThreshold;
{
// this->ImageOutlineActor = vtkSmartPointer<vtkActor2D>::New();
ImageFillActor = vtkSmartPointer<vtkActor2D>::New();
Reslice = vtkSmartPointer<vtkImageReslice>::New();
Reslice->SetOutputSpacing(1, 1, 1);
Reslice->SetOutputDimensionality(2);
Reslice->SetOutputOrigin(pDataLayer->GetAxialImageData()->GetOrigin()[0],
pDataLayer->GetAxialImageData()->GetOrigin()[1],
pDataLayer->GetAxialImageData()->GetOrigin()[2]);
Reslice->GenerateStencilOutputOn();
Reslice->SetBackgroundColor(0.0, 0.0, 0.0, 0.0);
Reslice->AutoCropOutputOff();
Reslice->SetOptimization(1);
SliceToImageTransform = vtkSmartPointer<vtkGeneralTransform>::New();
vtkNew<vtkMatrix4x4> matrix;
ConstructWorldToImageMatrix(TestBrushImage, matrix);
SliceToImageTransform->PostMultiply();
{
SliceToImageTransform->Translate(0, 0, 0);
// SliceToImageTransform
}
Reslice->SetResliceTransform(SliceToImageTransform);
Reslice->SetInputData(TestBrushImage);
int* extent = pDataLayer->GetAxialImageData()->GetExtent();
double* spacing = pDataLayer->GetAxialImageData()->GetSpacing();
int extent2[6] = { 0,0,0,0,0,0 };
extent2[1] = std::round(extent[1] * spacing[0]);
extent2[3] = std::round(extent[3] * spacing[1]);
extent2[5] = std::round(extent[5] * spacing[2]);
Reslice->SetOutputExtent(extent2);
// Reslice->SetOutputExtent(extent);
//vtkSmartPointer<vtkMatrix4x4> worldToImageMatrix = vtkSmartPointer<vtkMatrix4x4>::New();
LookupTableFill = vtkSmartPointer<vtkLookupTable>::New();
LookupTableFill->SetNumberOfTableValues(2);
LookupTableFill->SetRange(0, 1);
LookupTableFill->IndexedLookupOff();
LookupTableFill->Build();
int index = LookupTableFill->GetIndex(1.0);
LookupTableFill->SetTableValue(index, 255, 0, 0, 0);
// Image fill
vtkSmartPointer<vtkImageMapToRGBA> fillColorMapper = vtkSmartPointer<vtkImageMapToRGBA>::New();
fillColorMapper->SetInputConnection(Reslice->GetOutputPort());
fillColorMapper->SetOutputFormatToRGBA();
fillColorMapper->SetLookupTable(LookupTableFill);
fillColorMapper->Update();
vtkSmartPointer<vtkImageMapper> imageFillMapper = vtkSmartPointer<vtkImageMapper>::New();
imageFillMapper->SetInputConnection(fillColorMapper->GetOutputPort());
imageFillMapper->SetColorWindow(255);
imageFillMapper->SetColorLevel(127.5);
//imageFillMapper->Update();
ImageFillActor->SetMapper(imageFillMapper);
this->CurrentRenderer->DisplayToWorld();
this->CurrentRenderer->AddActor2D(ImageFillActor);
ImageFillActor->SetPosition(0, 0);
this->CurrentRenderer->ResetCamera();
this->Interactor->Render();