FaceGen 3 SDKs Reference
Loading...
Searching...
No Matches
fimImgTransMap.hpp
1//
2// Copyright (c) Singular Inversions Inc. 2001.
3//
4// File: fimImgTransMap.hpp
5// Description: A simple class for storing image transform mapping between
6// two images.
7// Authors: John Leung
8// Created: June 29, 2001
9//
10
11#ifndef FIM_IMG_TRANS_MAP_HPP
12#define FIM_IMG_TRANS_MAP_HPP
13
14#include "vect2.hpp"
15
16namespace Fg {
17
18template <typename T>
20{
21 private:
22
23 std::size_t nrows;
24 std::size_t ncols;
25 std::vector< FR2Vect2TC<T> > mapping;
26
27 class RowT
28 {
29 public:
30 RowT(FR2Vect2TC<T> *pp, size_t nc) :
31 ptr(pp), ncol(nc) {}
32 FR2Vect2TC<T> &operator[](size_t ii) const
33 { FGASSERT_FAST(ii<ncol); return ptr[ii]; }
34
35 private:
36 FR2Vect2TC<T>* const ptr;
37 size_t const ncol;
38 };
39
40 class ConstRowT
41 {
42 public:
43 ConstRowT(const FR2Vect2TC<T> *pp, size_t nc) :
44 ptr(pp), ncol(nc) {}
45 const FR2Vect2TC<T> &operator[](size_t ii) const
46 { FGASSERT_FAST(ii<ncol); return ptr[ii]; }
47
48 private:
49 const FR2Vect2TC<T>* const ptr;
50 size_t const ncol;
51 };
52
53 public:
54
55 FimImgTransMapT() : nrows(0), ncols(0), mapping(0) {}
56
57 FimImgTransMapT(size_t width, size_t height) :
58 nrows(height), ncols(width), mapping(width*height) {}
59
60 void resize(size_t width, size_t height)
61 { nrows = height; ncols = width;
62 mapping.resize(height*width); }
63
64 size_t numRows() const { return nrows; }
65 size_t numCols() const { return ncols; }
66 size_t rowByteSize() const
67 { return (sizeof(FR2Vect2TC<T>)*ncols); }
68
69 RowT operator[](size_t ii)
70 { FGASSERT_FAST(ii<nrows);
71 return RowT(&mapping[0]+ii*ncols,ncols); }
72 ConstRowT operator[](size_t ii) const
73 { FGASSERT_FAST(ii<nrows);
74 return ConstRowT(&mapping[0]+ii*ncols,ncols); }
75 const FimImgTransMapT<T> & operator=(const FimImgTransMapT<T> &aa)
76 {
77 if (this == &aa)
78 return *this;
79 nrows = aa.nrows;
80 ncols = aa.ncols;
81 mapping.resize(aa.mapping.size());
82 memcpy(&mapping[0],&aa.mapping[0],
83 sizeof(FR2Vect2TC<T>)*aa.mapping.size());
84 return *this;
85 }
86
87 typename std::vector< FR2Vect2TC<T> >::iterator begin()
88 { return mapping.begin(); }
89 typename std::vector< FR2Vect2TC<T> >::const_iterator begin() const
90 { return mapping.begin(); }
91
92 typename std::vector< FR2Vect2TC<T> >::iterator end()
93 { return mapping.end(); }
94 typename std::vector< FR2Vect2TC<T> >::const_iterator end() const
95 { return mapping.end(); }
96};
97
98
99//****************************************************************************
100// Some aliases
101//****************************************************************************
105
106}
107
108#endif