├── LICENSE
├── README.md
└── program
├── base
├── cmvs
│ ├── bundle.cc
│ ├── bundle.h
│ ├── graclus.cc
│ └── graclus.h
├── image
│ ├── camera.cc
│ ├── camera.h
│ ├── image.cc
│ ├── image.h
│ ├── photo.cc
│ ├── photo.h
│ ├── photoSetS.cc
│ └── photoSetS.h
├── numeric
│ ├── mat2.h
│ ├── mat3.h
│ ├── mat4.h
│ ├── mylapack.cc
│ ├── mylapack.h
│ ├── vec2.h
│ ├── vec3.h
│ └── vec4.h
├── pmvs
│ ├── asyncQueue.h
│ ├── detectFeatures.cc
│ ├── detectFeatures.h
│ ├── detector.cc
│ ├── detector.h
│ ├── dog.cc
│ ├── dog.h
│ ├── expand.cc
│ ├── expand.h
│ ├── filter.cc
│ ├── filter.h
│ ├── findMatch.cc
│ ├── findMatch.h
│ ├── harris.cc
│ ├── harris.h
│ ├── optim.cc
│ ├── optim.h
│ ├── option.cc
│ ├── option.h
│ ├── patch.cc
│ ├── patch.h
│ ├── patchOrganizerS.cc
│ ├── patchOrganizerS.h
│ ├── point.cc
│ ├── point.h
│ ├── refinePatch.cl
│ ├── refineThread.cc
│ ├── refineThread.h
│ ├── seed.cc
│ └── seed.h
└── stann
│ ├── Copyright.txt
│ ├── assert.hpp
│ ├── assert.hpp~
│ ├── bruteNN.hpp
│ ├── bruteNN.hpp~
│ ├── bsearch.hpp
│ ├── bsearch.hpp~
│ ├── dpoint.hpp
│ ├── pair_iter.hpp
│ ├── qknn.hpp
│ ├── rand.hpp
│ ├── sep_float.hpp
│ ├── sfcnn.hpp
│ ├── sfcnn.hpp~
│ ├── sfcnn_knng.hpp
│ ├── sfcnn_knng.hpp~
│ ├── test.hpp
│ ├── test.hpp~
│ ├── zorder_lt.hpp
│ ├── zorder_lt.hpp~
│ ├── zorder_type_traits.hpp
│ └── zorder_type_traits.hpp~
└── main
├── Makefile
├── cmvs.cc
├── genOption.cc
├── pmvs2.cc
├── run0.sh
├── run1.sh
└── run2.sh
/LICENSE:
--------------------------------------------------------------------------------
1 | This program is free software: you can redistribute it and/or modify
2 | it under the terms of the GNU General Public License as published by
3 | the Free Software Foundation, either version 3 of the License, or
4 | (at your option) any later version.
5 |
6 | This program is distributed in the hope that it will be useful,
7 | but WITHOUT ANY WARRANTY; without even the implied warranty of
8 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
9 | GNU General Public License for more details.
10 |
11 | You should have received a copy of the GNU General Public License
12 | along with this program. If not, see .
13 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # PMVS-GPU
2 | This project modifies [PMVS](http://www.di.ens.fr/pmvs/) to use the GPU. So far it has only been tested on Ubuntu 14.04 with NVIDIA graphics cards.
3 |
4 | ## Requirements
5 | #### OpenCL 1.2
6 | Verify OpenCL is configured correctly by running the `clinfo` utility. It should find a GPU device and return lots of info. On Ubuntu, OpenCL appears to be broken when using NVIDIA Ubuntu packages. If OpenCL isn't working, try removing all NVIDIA Ubuntu packages and reinstall drivers using the NVIDIA binary installer downloaded from [http://www.geforce.com/drivers](http://www.geforce.com/drivers).
7 |
8 | #### Ubuntu packages
9 |
10 | ```
11 | sudo apt-get install libgsl0-dev libblas-dev libatlas-dev liblapack-dev opencl-headers libjpeg-dev
12 | ```
13 |
14 | #### Other
15 | * [Graclus](http://www.cs.utexas.edu/users/dml/Software/graclus.html)
16 |
17 | When compiling Graclus be sure to set DNUMBITS to 64 in Makefile.in if you're using a 64 bit system.
18 |
19 | ## Build Instructions
20 | Update `program/main/Makefile` to point to your graclus dir (`YOUR_INCLUDE_METIS_PATH` and `YOUR_LDLIB_PATH`)
21 | ```
22 | cd program/main
23 | make depend
24 | make
25 | sudo make install
26 | ```
27 |
28 | ## Using with OpenDroneMap
29 | There is a more up-to-date branch of OpenDroneMap called python-port. When the input images have GPS metadata, the point matching step is much faster for large datasets. To use python-port, first clone the OpenDroneMap repository, then check out the branch using git.
30 | ```
31 | git clone https://github.com/OpenDroneMap/OpenDroneMap.git
32 | cd OpenDroneMap
33 | git fetch
34 | git checkout python-port
35 | ./install.sh
36 | ```
37 |
38 | OpenDroneMap comes with the original version of pmvs2. To use pmvs-gpu instead, copy the binary to the OpenDroneMap bin directory.
39 | ```cp /program/main/pmvs2 /bin```
40 |
41 | After installing, run OpenDroneMap by launching the `run.py` script from the directory that contains the input images. Note that if you're using the default branch (gh-pages), use `run.pl` instead.
42 |
--------------------------------------------------------------------------------
/program/base/cmvs/graclus.cc:
--------------------------------------------------------------------------------
1 | #include
2 | #include "graclus.h"
3 |
4 | using namespace CMVS;
5 | using namespace std;
6 |
7 | // Required by library
8 | int boundary_points;
9 | int spectral_initialization;
10 | int cutType;
11 | int memory_saving;
12 |
13 | Cgraclus::Cgraclus(void) {
14 | }
15 |
16 | Cgraclus::~Cgraclus() {
17 | }
18 |
19 | /*************************************************************************
20 | * This function reads the spd matrix
21 | **************************************************************************/
22 | void Cgraclus::initGraph(GraphType& graph) {
23 | graph.gdata = graph.rdata = NULL;
24 |
25 | graph.nvtxs = graph.nedges = -1;
26 | graph.mincut = graph.minvol = -1;
27 |
28 | graph.xadj = graph.vwgt = graph.adjncy = graph.adjwgt = NULL;
29 | graph.adjwgtsum = NULL;
30 | graph.label = NULL;
31 | graph.cmap = NULL;
32 |
33 | graph.where = graph.pwgts = NULL;
34 | graph.id = graph.ed = NULL;
35 | graph.bndptr = graph.bndind = NULL;
36 | graph.rinfo = NULL;
37 | graph.vrinfo = NULL;
38 | graph.nrinfo = NULL;
39 |
40 | graph.ncon = -1;
41 | graph.nvwgt = NULL;
42 | graph.npwgts = NULL;
43 |
44 | graph.vsize = NULL;
45 |
46 | graph.coarser = graph.finer = NULL;
47 | }
48 |
49 | //----------------------------------------------------------------------
50 | // cutType
51 | // 0: NCUT, 1: RASSO
52 | void Cgraclus::run(std::vector& xadj,
53 | std::vector& adjncy,
54 | const int nparts, const int cutType,
55 | std::vector& part) {
56 | GraphType graph;
57 | initGraph(graph);
58 |
59 | graph.ncon = 1;
60 |
61 | graph.xadj = &xadj[0];
62 | graph.adjncy = &adjncy[0];
63 | graph.vwgt = NULL;
64 | graph.adjwgt = NULL;
65 |
66 | graph.nvtxs = (int)xadj.size() - 1;
67 | graph.nedges = (int)adjncy.size();
68 |
69 | const int wgtflag = 0;
70 | runSub(graph, nparts, cutType, wgtflag, part);
71 | }
72 |
73 | void Cgraclus::runV(std::vector& xadj,
74 | std::vector& adjncy,
75 | std::vector& vwgt,
76 | const int nparts, const int cutType,
77 | std::vector& part) {
78 | GraphType graph;
79 | initGraph(graph);
80 |
81 | graph.ncon = 1;
82 |
83 | graph.xadj = &xadj[0];
84 | graph.adjncy = &adjncy[0];
85 | graph.vwgt = &vwgt[0];
86 | graph.adjwgt = NULL;
87 |
88 | graph.nvtxs = (int)xadj.size() - 1;
89 | graph.nedges = (int)adjncy.size();
90 |
91 | const int wgtflag = 2;
92 | runSub(graph, nparts, cutType, wgtflag, part);
93 | }
94 |
95 | //----------------------------------------------------------------------
96 | void Cgraclus::runE(std::vector& xadj,
97 | std::vector& adjncy,
98 | std::vector& adjwgt,
99 | const int nparts, const int cutType,
100 | std::vector& part) {
101 | GraphType graph;
102 | initGraph(graph);
103 |
104 | graph.ncon = 1;
105 |
106 | graph.xadj = &xadj[0];
107 | graph.adjncy = &adjncy[0];
108 | graph.vwgt = NULL;
109 | graph.adjwgt = &adjwgt[0];
110 |
111 | graph.nvtxs = (int)xadj.size() - 1;
112 | graph.nedges = (int)adjncy.size();
113 |
114 | const int wgtflag = 1;
115 | runSub(graph, nparts, cutType, wgtflag, part);
116 | }
117 |
118 | void Cgraclus::runVE(std::vector& xadj,
119 | std::vector& adjncy,
120 | std::vector& vwgt,
121 | std::vector& adjwgt,
122 | const int nparts, const int cutType,
123 | std::vector& part) {
124 | GraphType graph;
125 | initGraph(graph);
126 |
127 | graph.ncon = 1;
128 |
129 | graph.xadj = &xadj[0];
130 | graph.adjncy = &adjncy[0];
131 | graph.vwgt = &vwgt[0];
132 | graph.adjwgt = &adjwgt[0];
133 |
134 | graph.nvtxs = (int)xadj.size() - 1;
135 | graph.nedges = (int)adjncy.size();
136 |
137 | const int wgtflag = 3;
138 | runSub(graph, nparts, cutType, wgtflag, part);
139 | }
140 |
141 | int Cgraclus::mylog2(int a) {
142 | int i;
143 | for (i = 1 ; a > 1; i++, a = a>>1);
144 | return i-1;
145 | }
146 |
147 | void Cgraclus::runSub(GraphType& graph, int nparts, int cutType,
148 | int wgtflag, std::vector& part) {
149 | const int levels =
150 | amax((graph.nvtxs)/(40*mylog2(nparts)), 20*(nparts));
151 | part.resize(graph.nvtxs);
152 |
153 | int options[11]; options[0] = 0;
154 | int numflag = 0;
155 | int chain_length = 0; int edgecut;
156 |
157 | MLKKM_PartGraphKway(&graph.nvtxs, graph.xadj, graph.adjncy,
158 | graph.vwgt, graph.adjwgt,
159 | &wgtflag, &numflag, &nparts,
160 | &chain_length, options, &edgecut, &part[0], levels);
161 |
162 | float lbvec[MAXNCON];
163 | ComputePartitionBalance(&graph, nparts, &part[0], lbvec);
164 |
165 | float result;
166 | if (cutType == 0){
167 | result = ComputeNCut(&graph, &part[0], nparts);
168 | printf("\nNormalized-Cut... \n Cut value: %7f, Balance: ", result);
169 | }
170 | else{
171 | result = ComputeRAsso(&graph, &part[0], nparts);
172 | printf("\nRatio Association... \n Association value: %7f, Balance: ", result);
173 | }
174 | }
175 |
--------------------------------------------------------------------------------
/program/base/cmvs/graclus.h:
--------------------------------------------------------------------------------
1 | #ifndef CMVS_GRACLUS_H
2 | #define CMVS_GRACLUS_H
3 |
4 | #include
5 | #include
6 |
7 | /*
8 | 0 -- 1 -- 2 -- 3 -- 4
9 | | | | | |
10 | 5 -- 6 -- 7 -- 8 -- 9
11 | | | | | |
12 | 10 --11 --12 --13 --14
13 |
14 | CSR format
15 | xadj: 0 2 5 8 11 13 16 20 24 28 31 33 36 39 42 44
16 | Size of xadj is the number of vertices plus 1.
17 |
18 | adjncy: 1 5 0 2 6 1 3 7 2 4 8 3 9 0 6 10 1 5 7 11 2 6 8 12 3 7 9 13 4 8 14 5 11 6 10 12 7 11 13 8 12 14 9 13
19 |
20 | Size of adjncy is twice the number of edges.
21 | */
22 |
23 | namespace CMVS {
24 | class Cgraclus {
25 | public:
26 | Cgraclus(void);
27 | virtual ~Cgraclus();
28 |
29 | // Threads free. no weights
30 | static void run(std::vector& xadj,
31 | std::vector& adjncy,
32 | const int nparts, const int cutType,
33 | std::vector& part);
34 |
35 | // Threads free. vertex weights
36 | static void runV(std::vector& xadj,
37 | std::vector& adjncy,
38 | std::vector& vwgt,
39 | const int nparts, const int cutType,
40 | std::vector& part);
41 |
42 | // Threads free. edge weights
43 | static void runE(std::vector& xadj,
44 | std::vector& adjncy,
45 | std::vector& adjwgt,
46 | const int nparts, const int cutType,
47 | std::vector& part);
48 |
49 | // Threads free. vertex and edge weights
50 | static void runVE(std::vector& xadj,
51 | std::vector& adjncy,
52 | std::vector& vwgt,
53 | std::vector& adjwgt,
54 | const int nparts, const int cutType,
55 | std::vector& part);
56 |
57 | protected:
58 | static int mylog2(int a);
59 |
60 | static void runSub(GraphType& graph, int nparts, int cutType,
61 | int wgtflag, std::vector& part);
62 |
63 | static void initGraph(GraphType& graph);
64 | };
65 | };
66 |
67 | #endif // CMVS_GRACLUS_H
68 |
--------------------------------------------------------------------------------
/program/base/image/camera.h:
--------------------------------------------------------------------------------
1 | #ifndef IMAGE_CAMERA_H
2 | #define IMAGE_CAMERA_H
3 |
4 | #include
5 | #include
6 | #include
7 | #include "../numeric/vec4.h"
8 | #include "../numeric/mat4.h"
9 | #include "../numeric/mat3.h"
10 |
11 | namespace Image {
12 |
13 | class Ccamera {
14 | public:
15 | Ccamera(void);
16 | virtual ~Ccamera();
17 |
18 | // Update projection matrices from intrinsics and extrinsics
19 | void updateProjection(void);
20 | // Update all the camera related parameters
21 | void updateCamera(void);
22 |
23 | virtual void init(const std::string cname, const int maxLevel);
24 | void write(const std::string file);
25 |
26 | inline Vec3f project(const Vec4f& coord, const int level) const;
27 | inline Vec3f mult(const Vec4f& coord, const int level) const;
28 |
29 | static void setProjection(const std::vector& intrinsics,
30 | const std::vector& extrinsics,
31 | std::vector& projection,
32 | const int txtType);
33 |
34 | float getScale(const Vec4f& coord, const int level) const;
35 | void getPAxes(const Vec4f& coord, const Vec4f& normal,
36 | Vec4f& pxaxis, Vec4f& pyaxis, const int level = 0) const;
37 |
38 | void setAxesScale(const float axesScale);
39 |
40 | static void proj2q(Mat4& mat, double q[6]);
41 | static void q2proj(const double q[6], Mat4& mat);
42 | static void setProjectionSub(double params[], std::vector& projection,
43 | const int level);
44 |
45 | float computeDistance(const Vec4f& point) const;
46 | float computeDepth(const Vec4f& point) const;
47 | float computeDepthDif(const Vec4f& rhs, const Vec4f& lhs) const;
48 |
49 | // Compute where the viewing ray passing through coord intersects
50 | // with the plane abcd.
51 | Vec4f intersect(const Vec4f& coord, const Vec4f& abcd) const;
52 | void intersect(const Vec4f& coord, const Vec4f& abcd,
53 | Vec4f& cross, float& distance) const;
54 | // Computer a 3D coordinate that projects to a given image
55 | // coordinate. You can specify a different depth by the third
56 | // component of icoord.
57 | Vec4f unproject(const Vec3f& icoord, const int m_level) const;
58 |
59 | void setK(Mat3f& K) const;
60 | void setRT(Mat4f& RT) const;
61 |
62 | void getR(Mat3f& R) const;
63 |
64 | //----------------------------------------------------------------------
65 | // txt file name
66 | std::string m_cname;
67 | // Optical center
68 | Vec4f m_center;
69 | // Optical axis
70 | Vec4f m_oaxis;
71 |
72 | float m_ipscale;
73 | // 3x4 projection matrix
74 | std::vector > m_projection;
75 | Vec3f m_xaxis;
76 | Vec3f m_yaxis;
77 | Vec3f m_zaxis;
78 |
79 | // intrinsic and extrinsic camera parameters. Compact form.
80 | std::vector m_intrinsics;
81 | std::vector m_extrinsics;
82 | // camera parameter type
83 | int m_txtType;
84 | protected:
85 | int m_maxLevel;
86 |
87 | float m_axesScale;
88 |
89 | Vec4f getOpticalCenter(void) const;
90 | };
91 |
92 | inline Vec3f Ccamera::project(const Vec4f& coord,
93 | const int level) const {
94 | Vec3f vtmp;
95 | for (int i = 0; i < 3; ++i)
96 | vtmp[i] = m_projection[level][i] * coord;
97 |
98 | if (vtmp[2] <= 0.0) {
99 | vtmp[0] = -0xffff;
100 | vtmp[1] = -0xffff;
101 | vtmp[2] = -1.0f;
102 | return vtmp;
103 | }
104 | else
105 | vtmp /= vtmp[2];
106 |
107 | vtmp[0] = std::max((float)(INT_MIN + 3.0f),
108 | std::min((float)(INT_MAX - 3.0f),
109 | vtmp[0]));
110 | vtmp[1] = std::max((float)(INT_MIN + 3.0f),
111 | std::min((float)(INT_MAX - 3.0f),
112 | vtmp[1]));
113 |
114 | return vtmp;
115 | };
116 |
117 | inline Vec3f Ccamera::mult(const Vec4f& coord,
118 | const int level) const {
119 | Vec3f vtmp;
120 | for (int i = 0; i < 3; ++i)
121 | vtmp[i] = m_projection[level][i] * coord;
122 |
123 | return vtmp;
124 | };
125 |
126 | template
127 | float computeEPD(const TMat3& F, const TVec3& p0, const TVec3& p1) {
128 | TVec3 line = F * p1;
129 | const T ftmp = sqrt(line[0] * line[0] + line[1] * line[1]);
130 | if (ftmp == 0.0)
131 | return 0.0;
132 |
133 | line /= ftmp;
134 | return fabs(line * p0);
135 | };
136 |
137 | template
138 | void setF(const Image::Ccamera& lhs, const Image::Ccamera& rhs,
139 | TMat3& F, const int level = 0) {
140 | const TVec4& p00 = lhs.m_projection[level][0];
141 | const TVec4& p01 = lhs.m_projection[level][1];
142 | const TVec4& p02 = lhs.m_projection[level][2];
143 |
144 | const TVec4& p10 = rhs.m_projection[level][0];
145 | const TVec4& p11 = rhs.m_projection[level][1];
146 | const TVec4& p12 = rhs.m_projection[level][2];
147 |
148 | F[0][0] = det(TMat4(p01, p02, p11, p12));
149 | F[0][1] = det(TMat4(p01, p02, p12, p10));
150 | F[0][2] = det(TMat4(p01, p02, p10, p11));
151 |
152 | F[1][0] = det(TMat4(p02, p00, p11, p12));
153 | F[1][1] = det(TMat4(p02, p00, p12, p10));
154 | F[1][2] = det(TMat4(p02, p00, p10, p11));
155 |
156 | F[2][0] = det(TMat4(p00, p01, p11, p12));
157 | F[2][1] = det(TMat4(p00, p01, p12, p10));
158 | F[2][2] = det(TMat4(p00, p01, p10, p11));
159 | };
160 |
161 | }; // namespace image
162 |
163 | #endif // CAMERA_H
164 |
--------------------------------------------------------------------------------
/program/base/image/photo.cc:
--------------------------------------------------------------------------------
1 | #include
2 | #include "photo.h"
3 |
4 | using namespace std;
5 | using namespace Image;
6 |
7 | Cphoto::Cphoto(void) {
8 | }
9 |
10 | Cphoto::~Cphoto() {
11 | }
12 |
13 | void Cphoto::init(const std::string name, const std::string mname,
14 | const std::string cname, const int maxLevel) {
15 | Cimage::init(name, mname, maxLevel);
16 | Ccamera::init(cname, maxLevel);
17 | }
18 |
19 | void Cphoto::init(const std::string name, const std::string mname,
20 | const std::string ename,
21 | const std::string cname, const int maxLevel) {
22 | Cimage::init(name, mname, ename, maxLevel);
23 | Ccamera::init(cname, maxLevel);
24 | }
25 |
26 | float Cphoto::ssd(const std::vector& tex0,
27 | const std::vector& tex1) {
28 | float ans = 0.0f;
29 | for (int i = 0; i < (int)tex0.size(); ++i)
30 | ans += norm2(tex0[i] - tex1[i]);
31 |
32 | // Make sure that the score is below 2.0f
33 | ans /= (int)tex0.size() * (255.0 * 255.0 * 3.0);
34 |
35 | return ans;
36 | }
37 |
38 | float Cphoto::idot(const std::vector& tex0,
39 | const std::vector& tex1) {
40 | if (tex0.empty() || tex1.empty()) {
41 | cerr << "Error in idot. Empty textures" << endl;
42 | exit (1);
43 | }
44 | float ans = 0.0;
45 | for (int i = 0; i < (int)tex0.size(); ++i) {
46 | ans += tex0[i] * tex1[i];
47 | }
48 |
49 | return 1.0f - ans / (3 * (int)tex0.size());
50 | }
51 |
52 | void Cphoto::idotC(const std::vector& tex0,
53 | const std::vector& tex1, double* idc) {
54 | if (tex0.empty() || tex1.empty()) {
55 | cerr << "Error in idotC. Empty textures" << endl;
56 | exit (1);
57 | }
58 | idc[0] = 0.0; idc[1] = 0.0; idc[2] = 0.0;
59 | for (int i = 0; i < (int)tex0.size(); ++i) {
60 | for (int j = 0; j < 3; ++j)
61 | idc[j] += tex0[i][j] * tex1[i][j];
62 | }
63 | for (int j = 0; j < 3; ++j)
64 | idc[j] = 1.0 - idc[j] / (int)tex0.size();
65 | }
66 |
67 | void Cphoto::normalize(std::vector& tex) {
68 | //----------------------------------------------------------------------
69 | // normalize average
70 | Vec3f ave;
71 | for (int i = 0; i < (int)tex.size(); ++i)
72 | ave += tex[i];
73 | ave /= (int)tex.size();
74 |
75 | for (int i = 0; i < (int)tex.size(); ++i)
76 | tex[i] -= ave;
77 | //----------------------------------------------------------------------
78 | // compute variance
79 | float ave2 = 0.0f;
80 | for (int i = 0; i < (int)tex.size(); ++i)
81 | ave2 += tex[i] * tex[i];
82 | ave2 /= (int)tex.size() * 3;
83 | ave2 = sqrt(ave2);
84 | if (ave2 == 0.0f)
85 | ave2 = 1.0f;
86 |
87 | for (int i = 0; i < (int)tex.size(); ++i)
88 | tex[i] /= ave2;
89 | }
90 |
91 | void Cphoto::grabTex(const int level, const Vec2f& icoord,
92 | const Vec2f& xaxis, const Vec2f& yaxis,
93 | const int size, std::vector& tex,
94 | const int normalizef) const{
95 | const int margin = size / 2;
96 |
97 | // Check boundary condition
98 | const float maxx = icoord[0] + size * fabs(xaxis[0]) + size * fabs(yaxis[0]);
99 | const float minx = icoord[0] - size * fabs(xaxis[0]) - size * fabs(yaxis[0]);
100 | const float maxy = icoord[1] + size * fabs(xaxis[1]) + size * fabs(yaxis[1]);
101 | const float miny = icoord[1] - size * fabs(xaxis[1]) - size * fabs(yaxis[1]);
102 |
103 | tex.clear();
104 | if (minx < 0 || getWidth(level) - 1 <= maxx ||
105 | miny < 0 || getHeight(level) - 1 <= maxy)
106 | return;
107 |
108 | //tex.reserve(size * size);
109 | for (int y = -margin; y <= margin; ++y) {
110 | Vec2f v2ftmp = icoord - margin * xaxis + y * yaxis;
111 | for (int x = -margin; x <= margin; ++x) {
112 | tex.push_back(Cimage::getColor(v2ftmp[0], v2ftmp[1], level));
113 | v2ftmp += xaxis;
114 | }
115 | }
116 |
117 | if (normalizef)
118 | normalize(tex);
119 | }
120 |
121 | void Cphoto::grabTex(const int level, const Vec4f& coord,
122 | const Vec4f& pxaxis, const Vec4f& pyaxis, const Vec4f& pzaxis,
123 | const int size,
124 | std::vector& tex, float& weight,
125 | const int normalizef) const {
126 | const int scale = 0x0001 << level;
127 |
128 | const Vec3f icoord3 = project(coord, level);
129 | const Vec2f icoord(icoord3[0], icoord3[1]);
130 |
131 | const Vec3f xaxis3 = project(coord + pxaxis * scale, level) - icoord3;
132 | const Vec2f xaxis(xaxis3[0], xaxis3[1]);
133 |
134 | const Vec3f yaxis3 = project(coord + pyaxis * scale, level) - icoord3;
135 | const Vec2f yaxis(yaxis3[0], yaxis3[1]);
136 |
137 | grabTex(level, icoord, xaxis, yaxis, size, tex, normalizef);
138 |
139 | Vec4f ray = m_center - coord;
140 | unitize(ray);
141 | weight = max(0.0f, pzaxis * ray);
142 | }
143 |
--------------------------------------------------------------------------------
/program/base/image/photo.h:
--------------------------------------------------------------------------------
1 | #ifndef IMAGE_PHOTO_H
2 | #define IMAGE_PHOTO_H
3 |
4 | #include "../numeric/vec4.h"
5 | #include "image.h"
6 | #include "camera.h"
7 |
8 | namespace Image {
9 |
10 | // Cphoto is an image with camera parameters
11 | class Cphoto : public Cimage, public Ccamera {
12 | public:
13 | Cphoto(void);
14 | virtual ~Cphoto();
15 |
16 | virtual void init(const std::string name, const std::string mname,
17 | const std::string cname, const int maxLevel = 1);
18 |
19 | virtual void init(const std::string name, const std::string mname,
20 | const std::string ename,
21 | const std::string cname, const int maxLevel = 1);
22 |
23 | // grabTex given 2D sampling information
24 | void grabTex(const int level, const Vec2f& icoord,
25 | const Vec2f& xaxis, const Vec2f& yaxis, const int size,
26 | std::vector& tex, const int normalizef = 1) const;
27 |
28 | // grabTex given 3D sampling information
29 | void grabTex(const int level, const Vec4f& coord,
30 | const Vec4f& pxaxis, const Vec4f& pyaxis, const Vec4f& pzaxis,
31 | const int size, std::vector& tex, float& weight,
32 | const int normalizef = 1) const;
33 |
34 |
35 | inline Vec3f getColor(const float fx, const float fy, const int level) const;
36 | inline Vec3f getColor(const Vec4f& coord, const int level) const;
37 | inline int getMask(const Vec4f& coord, const int level) const;
38 | inline int getEdge(const Vec4f& coord, const int level) const;
39 |
40 | static float idot(const std::vector& tex0,
41 | const std::vector& tex1);
42 |
43 | static void idotC(const std::vector& tex0,
44 | const std::vector& tex1, double* idc);
45 |
46 | static void normalize(std::vector& tex);
47 |
48 | static float ssd(const std::vector& tex0,
49 | const std::vector& tex1);
50 | protected:
51 | };
52 |
53 | Vec3f Cphoto::getColor(const float fx, const float fy, const int level) const {
54 | return Cimage::getColor(fx, fy, level);
55 | };
56 |
57 | Vec3f Cphoto::getColor(const Vec4f& coord, const int level) const {
58 | const Vec3f icoord = project(coord, level);
59 | return Cimage::getColor(icoord[0], icoord[1], level);
60 | };
61 |
62 | int Cphoto::getMask(const Vec4f& coord, const int level) const {
63 | if (m_masks[level].empty())
64 | return 1;
65 |
66 | const Vec3f icoord = project(coord, level);
67 | return Cimage::getMask(icoord[0], icoord[1], level);
68 | };
69 |
70 | int Cphoto::getEdge(const Vec4f& coord, const int level) const {
71 | if (m_edges[level].empty())
72 | return 1;
73 |
74 | const Vec3f icoord = project(coord, level);
75 |
76 | if (icoord[0] < 0 || m_widths[level] - 1 <= icoord[0] ||
77 | icoord[1] < 0 || m_heights[level] - 1 <= icoord[1])
78 | return 0;
79 |
80 | return Cimage::getEdge(icoord[0], icoord[1], level);
81 | };
82 |
83 | };
84 |
85 | #endif // PHOTO_H
86 |
--------------------------------------------------------------------------------
/program/base/image/photoSetS.h:
--------------------------------------------------------------------------------
1 | #ifndef IMAGE_PHOTOSETS_H
2 | #define IMAGE_PHOTOSETS_H
3 |
4 | #include