#include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include typedef itk::Image ImageType; typedef itk::ImageFileReader ReaderType; typedef cpPlugins::Interface::Image TPluginImage; int main() { auto memento = cpExtensions::IO::MementoState(); //here goes the code std::string filePath = "julia_mha.mhd"; std::string filePathRaw = "julia_mha.raw"; // Create an image vtkSmartPointer source = vtkSmartPointer::New(); vtkSmartPointer castFilter = vtkSmartPointer::New(); castFilter->SetOutputScalarTypeToUnsignedChar(); castFilter->SetInputConnection(source->GetOutputPort()); castFilter->Update(); vtkSmartPointer writer = vtkSmartPointer::New(); writer->SetInputConnection(castFilter->GetOutputPort()); writer->SetFileName(filePath.c_str()); writer->SetRAWFileName(filePathRaw.c_str()); writer->Write(); //ReaderType::Pointer reader = ReaderType::New(); vtkSmartPointer reader = vtkSmartPointer::New(); reader->SetFileName(filePath.c_str()); reader->Update(); //first memento /* auto obj = TPluginImage::New(); auto oo = dynamic_cast (reader->GetOutput()); obj->SetSource(oo); memento.SetToMemento(oo);*/ // filter 1 (state 2) --------------------------------------------------------------- typedef itk::BinaryBallStructuringElement< ImageType::PixelType, 2> StructuringElementType; StructuringElementType structuringElement; structuringElement.SetRadius(10); structuringElement.CreateStructuringElement(); typedef itk::VTKImageToImageFilter imgToFilter; imgToFilter::Pointer connectorimg = imgToFilter::New(); connectorimg->SetInput(reader->GetOutput()); connectorimg->Update(); typedef itk::BinaryErodeImageFilter BinaryErodeImageFilterType; BinaryErodeImageFilterType::Pointer erodeFilter = BinaryErodeImageFilterType::New(); erodeFilter->SetInput(connectorimg->GetOutput()); erodeFilter->SetKernel(structuringElement); // filter 2 (state 3) --------------------------------------------------------------- typedef itk::BinaryThresholdImageFilter BinaryThresholdImageFilterType; BinaryThresholdImageFilterType::Pointer thresholdFilter = BinaryThresholdImageFilterType::New(); thresholdFilter->SetInput(erodeFilter->GetOutput()); thresholdFilter->SetLowerThreshold(10); thresholdFilter->SetUpperThreshold(30); thresholdFilter->SetInsideValue(255); thresholdFilter->SetOutsideValue(0); // filter 3 (state 4) --------------------------------------------------------------- typedef itk::InvertIntensityImageFilter InvertIntensityImageFilterType; InvertIntensityImageFilterType::Pointer invertIntensityFilter = InvertIntensityImageFilterType::New(); invertIntensityFilter->SetInput(thresholdFilter->GetOutput()); invertIntensityFilter->SetMaximum(255); // undo (state 3) --------------------------------------------------------------- // undo (state 2) --------------------------------------------------------------- // redo (state 3) --------------------------------------------------------------- // visualization -- just for test typedef itk::ImageToVTKImageFilter ConnectorType; ConnectorType::Pointer connector = ConnectorType::New(); connector->SetInput(invertIntensityFilter->GetOutput()); connector->Update(); vtkSmartPointer actor = vtkSmartPointer::New(); actor->GetMapper()->SetInputData(connector->GetOutput()); vtkSmartPointer renderer = vtkSmartPointer::New(); vtkSmartPointer renderWindow = vtkSmartPointer::New(); renderWindow->AddRenderer(renderer); vtkSmartPointer renderWindowInteractor = vtkSmartPointer::New(); renderWindowInteractor->SetRenderWindow(renderWindow); renderer->AddActor(actor); renderer->SetBackground(.2, .3, .4); renderWindow->Render(); renderWindowInteractor->Start(); //#ifdef _DEBUG // auto i = 0; // std::cout << "wait for close"; // std::cin >> i; //#endif return 0; }