~ubuntu-branches/debian/sid/simpleitk/sid

« back to all changes in this revision

Viewing changes to Examples/FilterProgressReporting/FilterProgressReporting.rb

  • Committer: Package Import Robot
  • Author(s): Ghislain Antony Vaillant
  • Date: 2017-11-02 08:49:18 UTC
  • Revision ID: package-import@ubuntu.com-20171102084918-7hs09ih668xq87ej
Tags: upstream-1.0.1
ImportĀ upstreamĀ versionĀ 1.0.1

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#=========================================================================
 
2
#
 
3
#  Copyright Insight Software Consortium
 
4
#
 
5
#  Licensed under the Apache License, Version 2.0 (the "License");
 
6
#  you may not use this file except in compliance with the License.
 
7
#  You may obtain a copy of the License at
 
8
#
 
9
#         http://www.apache.org/licenses/LICENSE-2.0.txt
 
10
#
 
11
#  Unless required by applicable law or agreed to in writing, software
 
12
#  distributed under the License is distributed on an "AS IS" BASIS,
 
13
#  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 
14
#  See the License for the specific language governing permissions and
 
15
#  limitations under the License.
 
16
#
 
17
#=========================================================================
 
18
require 'simpleitk'
 
19
 
 
20
if ARGV.length != 3 then
 
21
  puts "Usage: SimpleGaussian <input> <sigma> <output>";
 
22
  exit( 1 )
 
23
end
 
24
 
 
25
## [ruby director command]
 
26
# Derive a class from SimpleITK Command class to be used to observe
 
27
# events and report progress.
 
28
class MyCommand < Simpleitk::Command
 
29
  def initialize(po)
 
30
    # Explicit call to supoer class initlaizer is required to
 
31
    # initialize the SWIG director class to enable overloaded methods
 
32
    super()
 
33
    @po = po
 
34
  end
 
35
 
 
36
  # The Command method to be executed on the event from the filter.
 
37
  def execute
 
38
    puts "%s Progress: %0.2f" % [@po.get_name, @po.get_progress]
 
39
  end
 
40
end
 
41
## [ruby director command]
 
42
 
 
43
reader = Simpleitk::ImageFileReader.new
 
44
reader.set_file_name( ARGV[0] )
 
45
image = reader.execute
 
46
 
 
47
inputPixelType = image.get_pixel_idvalue
 
48
 
 
49
 
 
50
gaussian = Simpleitk::DiscreteGaussianImageFilter.new
 
51
gaussian.set_variance ARGV[1].to_f
 
52
 
 
53
# create a new MyCommand class, the references between the objects is
 
54
# automatically taked care of. The connection will automatically be
 
55
# removed when either object is deleted.
 
56
cmd = MyCommand.new gaussian
 
57
gaussian.add_command Simpleitk::SitkProgressEvent, cmd
 
58
 
 
59
image = gaussian.execute image
 
60
 
 
61
caster = Simpleitk::CastImageFilter.new
 
62
caster.set_output_pixel_type inputPixelType
 
63
image = caster.execute image
 
64
 
 
65
writer = Simpleitk::ImageFileWriter.new
 
66
writer.set_file_name ARGV[2]
 
67
writer.execute image