~ubuntu-branches/ubuntu/oneiric/ctioga2/oneiric

« back to all changes in this revision

Viewing changes to lib/ctioga2/graphics/coordinates.rb

  • Committer: Bazaar Package Importer
  • Author(s): Vincent Fourmond
  • Date: 2011-01-24 21:36:06 UTC
  • Revision ID: james.westby@ubuntu.com-20110124213606-9ettx0ugl83z0bzp
Tags: upstream-0.1
ImportĀ upstreamĀ versionĀ 0.1

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# coordinates.rb: coordinate transformations
 
2
# copyright (c) 2009 by Vincent Fourmond
 
3
  
 
4
# This program is free software; you can redistribute it and/or modify
 
5
# it under the terms of the GNU General Public License as published by
 
6
# the Free Software Foundation; either version 2 of the License, or
 
7
# (at your option) any later version.
 
8
  
 
9
# This program is distributed in the hope that it will be useful,
 
10
# but WITHOUT ANY WARRANTY; without even the implied warranty of
 
11
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
12
# GNU General Public License for more details (in the COPYING file).
 
13
 
 
14
require 'ctioga2/utils'
 
15
require 'ctioga2/log'
 
16
 
 
17
 
 
18
module CTioga2
 
19
 
 
20
  Version::register_svn_info('$Revision: 177 $', '$Date: 2010-10-25 13:22:39 +0200 (Mon, 25 Oct 2010) $')
 
21
 
 
22
  module Graphics
 
23
 
 
24
    # Deals with transforming the coordinates of all datasets
 
25
    #
 
26
    # \todo
 
27
    # * offsets
 
28
    # * scales
 
29
    # * x/y log
 
30
    # * non-linear transformations ?
 
31
    # * the possibility to provide locations using this.
 
32
    # * conversion of datasets.
 
33
    #
 
34
    # \todo Shouldn't this facility be axis-local ? Non-linear
 
35
    # transformations definitely belong there as well (and that would
 
36
    # be almost trivial to write !).
 
37
    #
 
38
    # @todo For now, this is a mess: these things completely mess up
 
39
    # the data processing... This is a complex problem:
 
40
    # 
 
41
    # * if the Dataset are modified in place, this is a nightmare for
 
42
    #   data processing
 
43
    #   
 
44
    # * on the other hand, if they are not modified in place, this
 
45
    #   means that things that work on data sets and show things on
 
46
    #   the plot (think TangentPrimitive, for instance) will have to
 
47
    #   do additional things to get the target coordinates. This is
 
48
    #   probably the best way to go, though... This would need some
 
49
    #   functions to work directly on XY coordinates.
 
50
    class CoordinateTransforms
 
51
 
 
52
      # A scaling factor for coordinates:
 
53
      attr_accessor :x_scale, :y_scale
 
54
 
 
55
      # An offset for coordinates
 
56
      attr_accessor :x_offset, :y_offset
 
57
 
 
58
      # Whether to use logarithmic coordinates
 
59
      attr_accessor :x_log, :y_log
 
60
 
 
61
      # Creates a CoordinateTransformations object.
 
62
      def initialize
 
63
      end
 
64
 
 
65
      # Apply a transformation to a Data::Dataset holding 2D signals.
 
66
      # Modifies the dataset in place.
 
67
      def transform_2d!(dataset)
 
68
        for w in [:x , :y]
 
69
          if v = self.send("#{w}_scale") 
 
70
            dataset.send(w).apply do |x|
 
71
              x.mul!(v)
 
72
            end
 
73
          end
 
74
          if v = self.send("#{w}_offset") 
 
75
            dataset.send(w).apply do |x|
 
76
              x.add!(v)
 
77
            end
 
78
          end
 
79
          if v = self.send("#{w}_log") 
 
80
            dataset.send(w).apply do |x|
 
81
              x.safe_log10!
 
82
            end
 
83
          end
 
84
        end
 
85
      end
 
86
    end
 
87
 
 
88
  end
 
89
end
 
90