1
# coordinates.rb: coordinate transformations
2
# copyright (c) 2009 by Vincent Fourmond
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.
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).
14
require 'ctioga2/utils'
20
Version::register_svn_info('$Revision: 177 $', '$Date: 2010-10-25 13:22:39 +0200 (Mon, 25 Oct 2010) $')
24
# Deals with transforming the coordinates of all datasets
30
# * non-linear transformations ?
31
# * the possibility to provide locations using this.
32
# * conversion of datasets.
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 !).
38
# @todo For now, this is a mess: these things completely mess up
39
# the data processing... This is a complex problem:
41
# * if the Dataset are modified in place, this is a nightmare for
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
52
# A scaling factor for coordinates:
53
attr_accessor :x_scale, :y_scale
55
# An offset for coordinates
56
attr_accessor :x_offset, :y_offset
58
# Whether to use logarithmic coordinates
59
attr_accessor :x_log, :y_log
61
# Creates a CoordinateTransformations object.
65
# Apply a transformation to a Data::Dataset holding 2D signals.
66
# Modifies the dataset in place.
67
def transform_2d!(dataset)
69
if v = self.send("#{w}_scale")
70
dataset.send(w).apply do |x|
74
if v = self.send("#{w}_offset")
75
dataset.send(w).apply do |x|
79
if v = self.send("#{w}_log")
80
dataset.send(w).apply do |x|