MVE - Multi-View Environment mve-devel
Loading...
Searching...
No Matches
single_view.h
Go to the documentation of this file.
1/*
2 * Copyright (C) 2015, Ronny Klowsky, Simon Fuhrmann
3 * TU Darmstadt - Graphics, Capture and Massively Parallel Computing
4 * All rights reserved.
5 *
6 * This software may be modified and distributed under the terms
7 * of the BSD 3-Clause license. See the LICENSE.txt file for details.
8 */
9
10#ifndef DMRECON_SINGLE_VIEW_H
11#define DMRECON_SINGLE_VIEW_H
12
13#include <cassert>
14#include <set>
15#include <iostream>
16#include <utility>
17#include <memory>
18
19#include "math/vector.h"
20#include "math/matrix.h"
21#include "mve/view.h"
22#include "mve/image.h"
23#include "dmrecon/defines.h"
25
27
29{
30public:
31 typedef std::shared_ptr<SingleView> Ptr;
32 typedef std::shared_ptr<SingleView const> ConstPtr;
33
34public:
35 static Ptr create (mve::Scene::Ptr scene, mve::View::Ptr view,
36 std::string const& embedding);
38
39 void addFeature(std::size_t idx);
40 std::vector<std::size_t> const& getFeatureIndices() const;
41 int clampLevel(int level) const;
42 mve::ByteImage::ConstPtr const& getScaledImg() const;
43 mve::ByteImage::ConstPtr const& getPyramidImg(int level) const;
44 mve::View::Ptr getMVEView() const;
45
46 std::string createFileName(float scale) const;
47 float footPrint(math::Vec3f const& point);
48 float footPrintScaled(math::Vec3f const& point);
49 math::Vec3f viewRay(int x, int y, int level) const;
50 math::Vec3f viewRay(float x, float y, int level) const;
51 math::Vec3f viewRayScaled(int x, int y) const;
52 void loadColorImage(int minLevel);
53 bool pointInFrustum(math::Vec3f const& wp) const;
54 void saveReconAsPly(std::string const& path, float scale) const;
55 bool seesFeature(std::size_t idx) const;
56 void prepareMasterView(int scale);
57 math::Vec2f worldToScreen(math::Vec3f const& point, int level);
58 math::Vec2f worldToScreenScaled(math::Vec3f const& point);
59 std::size_t getViewID() const;
60
61public:
67
68private:
71 std::string const& _embedding);
72
73private:
74 math::Matrix4f worldToCam;
75 mve::Scene::Ptr scene;
76 mve::View::Ptr view;
77 std::string embedding;
78
80 std::vector<std::size_t> featInd;
81
82 bool has_target_level;
83
85 ImagePyramid::ConstPtr img_pyramid;
86 ImagePyramidLevel source_level;
87 ImagePyramidLevel target_level;
88 int minLevel;
89};
90
91/* ------------------------ Implementation ------------------------ */
92
93inline SingleView::Ptr
94SingleView::create (mve::Scene::Ptr scene, mve::View::Ptr view,
95 std::string const& embedding)
96{
97 return Ptr(new SingleView(scene, view, embedding));
98}
99
100inline void
101SingleView::addFeature(std::size_t idx)
102{
103 featInd.push_back(idx);
104}
105
106inline std::vector<std::size_t> const &
107SingleView::getFeatureIndices() const
108{
109 return featInd;
110}
111
112inline int
113SingleView::clampLevel(int level) const
114{
115 if (level < minLevel)
116 return minLevel;
117
118 int maxLevel = this->img_pyramid->size() - 1;
119 if (level > maxLevel)
120 return maxLevel;
121
122 return level;
123}
124
125inline mve::View::Ptr
126SingleView::getMVEView() const
127{
128 return this->view;
129}
130
131inline mve::ByteImage::ConstPtr const&
132SingleView::getPyramidImg(int level) const
133{
134 return this->img_pyramid->at(level).image;
135}
136
137inline mve::ByteImage::ConstPtr const&
138SingleView::getScaledImg() const
139{
140 return this->target_level.image;
141}
142
143inline std::string
144SingleView::createFileName(float scale) const
145{
146 std::string fileName = "mvs-";
147 fileName += util::string::get_filled(this->getViewID(), 4);
148 fileName += "-L";
149 fileName += util::string::get(scale);
150 return fileName;
151}
152
153inline float
154SingleView::footPrint(math::Vec3f const& point)
155{
156 return (this->worldToCam.mult(point, 1)[2] * this->source_level.invproj[0]);
157}
158
159inline float
160SingleView::footPrintScaled(math::Vec3f const& point)
161{
162 assert(this->has_target_level);
163 return (this->worldToCam.mult(point, 1)[2] * this->target_level.invproj[0]);
164}
165
166inline bool
167SingleView::seesFeature(std::size_t idx) const
168{
169 for (std::size_t i = 0; i < featInd.size(); ++i)
170 if (featInd[i] == idx)
171 return true;
172 return false;
173}
174
175inline math::Vec2f
176SingleView::worldToScreenScaled(math::Vec3f const& point)
177{
178 assert(this->has_target_level);
179
180 math::Vec3f cp(this->worldToCam.mult(point,1.f));
181 math::Vec3f sp = this->target_level.proj * cp;
182
183 math::Vec2f res(sp[0] / sp[2] - 0.5f, sp[1] / sp[2] - 0.5f);
184 return res;
185}
186
187inline math::Vec2f
188SingleView::worldToScreen(math::Vec3f const& point, int level)
189{
190 math::Vec3f cp(this->worldToCam.mult(point,1.f));
191 math::Vec3f sp = this->img_pyramid->at(level).proj * cp;
192
193 math::Vec2f res(sp[0] / sp[2] - 0.5f, sp[1] / sp[2] - 0.5f);
194 return res;
195}
196
197inline std::size_t
198SingleView::getViewID() const
199{
200 return this->view->get_id();
201}
202
204
205#endif
Matrix class for arbitrary dimensions and types.
Definition matrix.h:54
Vector class for arbitrary dimensions and types.
Definition vector.h:87
std::shared_ptr< Image< T > > Ptr
Definition image.h:42
std::shared_ptr< Image< T > const > ConstPtr
Definition image.h:43
std::shared_ptr< Scene > Ptr
Definition scene.h:37
std::shared_ptr< View > Ptr
Definition view.h:68
std::shared_ptr< ImagePyramid const > ConstPtr
mve::FloatImage::Ptr confImg
Definition single_view.h:66
mve::FloatImage::Ptr dzImg
Definition single_view.h:65
math::Vec3f camPos
Definition single_view.h:62
std::shared_ptr< SingleView const > ConstPtr
Definition single_view.h:32
mve::FloatImage::Ptr normalImg
Definition single_view.h:64
std::shared_ptr< SingleView > Ptr
Definition single_view.h:31
mve::FloatImage::Ptr depthImg
Definition single_view.h:63
#define MVS_NAMESPACE_BEGIN
Definition defines.h:18
#define MVS_NAMESPACE_END
Definition defines.h:19
std::string get_filled(T const &value, int width, char fill='0')
Returns a string filled to the left to a length of 'width' chars.
Definition strings.h:142
std::string get(T const &value)
From arbitrary types to string conversion.
Definition strings.h:108