Subversion Repositories gelsvn

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
667 khor 1
//
2
//  XForm.h
3
//  PointReconstruction
4
//
5
//  Created by J. Andreas Bærentzen on 16/03/13.
6
//  Copyright (c) 2013 J. Andreas Bærentzen. All rights reserved.
7
//
8
 
9
#ifndef PointReconstruction_XForm_h
10
#define PointReconstruction_XForm_h
11
 
12
#include "../CGLA/Vec3d.h"
13
 
14
namespace Geometry
15
{
16
    class XForm
17
    {
18
        CGLA::Vec3d llf;
19
        CGLA::Vec3d urt;
20
        double scale, margin;
21
        CGLA::Vec3i DIM;
22
    public:
23
        XForm() {}
24
        XForm(const CGLA::Vec3d& _llf, const CGLA::Vec3d& _urt, const CGLA::Vec3i& _DIM, double _margin=0.1):
25
        llf(_llf), urt(_urt), DIM(_DIM)
26
        {
27
            if(urt[0]<llf[0])
28
            {
29
                margin = 0.0;
30
                scale = 1;
31
                llf = CGLA::Vec3d(0);
32
                urt = CGLA::Vec3d(DIM);
33
            }
34
            else
35
            {
36
                CGLA::Vec3d d = urt - llf;
37
                margin = d.max_coord() * _margin;
38
                double scale_x = (DIM[0])/(d[0] + 2.0 * margin);
39
                double scale_y = (DIM[1])/(d[1] + 2.0 * margin);
40
                double scale_z = (DIM[2])/(d[2] + 2.0 * margin);
41
                scale = std::min(std::min(scale_x, scale_y), scale_z);
42
            }
43
        }
44
 
45
        CGLA::Vec3i get_dims() const {return DIM;}
46
 
47
        const CGLA::Vec3d apply(const CGLA::Vec3d& p) const
48
        {
49
            return scale*(p-llf+CGLA::Vec3d(margin));
50
        }
51
 
52
        const CGLA::Vec3d inverse(const CGLA::Vec3d& p) const
53
        {
54
            return p/scale + llf - CGLA::Vec3d(margin);
55
        }
56
 
57
        double inv_scale() const {return 1.0/scale;}
58
 
59
        void print()
60
        {
61
            std::cout << scale << " " << (-llf+CGLA::Vec3d(margin)) << std::endl;
62
        }
63
    };
64
}
65
 
66
#endif