SimpleITK  
FilterProgressReporting/FilterProgressReporting.cs
/*=========================================================================
*
* Copyright NumFOCUS
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0.txt
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*=========================================================================*/
using System;
using itk.simple;
namespace itk.simple.examples {
class MyCommand : Command {
private ProcessObject m_ProcessObject;
public MyCommand(ProcessObject po){
m_ProcessObject = po;
}
public override void Execute() {
Console.WriteLine("{0} Progress: {1:0.00}", m_ProcessObject.GetName(), m_ProcessObject.GetProgress() );
}
}
class FilterProgressReporting {
static void Main(string[] args) {
try {
if (args.Length < 3) {
Console.WriteLine("Usage: {0} <input> <variance> <output>", args[0]);
return;
}
// Read input image
reader.SetFileName(args[0]);
Image image = reader.Execute();
// Execute Gaussian smoothing filter
filter.SetVariance(Double.Parse(args[1]));
MyCommand cmd = new MyCommand(filter);
filter.AddCommand(EventEnum.sitkProgressEvent, cmd);
image = filter.Execute(image);
// Write output image
writer.SetFileName(args[2]);
writer.Execute(image);
} catch (Exception ex) {
Console.WriteLine(ex);
}
}
}
}
An implementation of the Command design pattern for callback.
Definition sitkCommand.h:45
Blurs an image by separable convolution with discrete gaussian kernels. This filter performs Gaussian...
Image Execute(const Image &image1)
Self & SetVariance(std::vector< double > Variance)
Read an image file and return a SimpleITK Image.
Image Execute() override
Set/Get The output PixelType of the image.
Self & SetFileName(const PathType &fn)
Write out a SimpleITK image to the specified file location.
Self & SetFileName(const PathType &fileName)
Self & Execute(const Image &)
The Image class for SimpleITK.
Definition sitkImage.h:77
Base class for SimpleITK classes based on ProcessObject.
virtual int AddCommand(itk::simple::EventEnum event, itk::simple::Command &cmd)
Add a Command Object to observer the event.
virtual float GetProgress() const
An Active Measurement of the progress of execution.
virtual std::string GetName() const =0
EventEnum
Events which can be observed from ProcessObject.
Definition sitkEvent.h:32