forked from swayfreeda/ImageBasedModellingEduV1.0
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtexture_patch.h
executable file
·175 lines (136 loc) · 4.86 KB
/
texture_patch.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
/*
* Copyright (C) 2015, Nils Moehrle
* TU Darmstadt - Graphics, Capture and Massively Parallel Computing
* All rights reserved.
*
* This software may be modified and distributed under the terms
* of the BSD 3-Clause license. See the LICENSE.txt file for details.
*/
#ifndef TEX_TEXTUREPATCH_HEADER
#define TEX_TEXTUREPATCH_HEADER
#include <vector>
#include <math/vector.h>
#include <core/mesh.h>
#include "tri.h"
#include "poisson_blending.h"
int const texture_patch_border = 1;
/**
* Class representing a texture patch.
* Contains additionaly to the rectangular part of the TextureView
* the faces which it textures and their relative texture coordinates.
*/
class TexturePatch {
public:
typedef std::shared_ptr<TexturePatch> Ptr;
typedef std::shared_ptr<const TexturePatch> ConstPtr;
typedef std::vector<std::size_t> Faces; //facets
typedef std::vector<math::Vec2f> Texcoords; // texcoords of vertices in Faces
private:
int label; // label of texture patch
Faces faces; // facets
Texcoords texcoords; // texcoords of each facet in Faces
core::FloatImage::Ptr image; // image
core::ByteImage::Ptr validity_mask;
core::ByteImage::Ptr blending_mask;
public:
/** Constructs a texture patch. */
TexturePatch(int _label, std::vector<std::size_t> const & _faces,
std::vector<math::Vec2f> const & _texcoords, core::ByteImage::Ptr _image);
TexturePatch(TexturePatch const & texture_patch);
static TexturePatch::Ptr create(TexturePatch::ConstPtr texture_patch);
static TexturePatch::Ptr create(int label, std::vector<std::size_t> const & faces,
std::vector<math::Vec2f> const & texcoords, core::ByteImage::Ptr image);
TexturePatch::Ptr duplicate(void);
/** Adjust the image colors and update validity mask. */
void adjust_colors(std::vector<math::Vec3f> const & adjust_values);
/** Compares texture patches image size. */
bool operator<(TexturePatch const & texture_patch) const;
math::Vec3f get_pixel_value(math::Vec2f pixel) const;
void set_pixel_value(math::Vec2i pixel, math::Vec3f color);
bool valid_pixel(math::Vec2i pixel) const;
bool valid_pixel(math::Vec2f pixel) const;
std::vector<std::size_t> & get_faces(void);
std::vector<std::size_t> const & get_faces(void) const;
std::vector<math::Vec2f> & get_texcoords(void);
std::vector<math::Vec2f> const & get_texcoords(void) const;
core::FloatImage::ConstPtr get_image(void) const;
core::ByteImage::ConstPtr get_validity_mask(void) const;
core::ByteImage::ConstPtr get_blending_mask(void) const;
std::pair<float, float> get_min_max(void) const;
void release_blending_mask(void);
void prepare_blending_mask(std::size_t strip_width);
void erode_validity_mask(void);
void blend(core::FloatImage::ConstPtr orig);
int get_label(void) const;
int get_width(void) const;
int get_height(void) const;
int get_size(void) const;
};
inline TexturePatch::Ptr
TexturePatch::create(TexturePatch::ConstPtr texture_patch) {
return Ptr(new TexturePatch(*texture_patch));
}
inline TexturePatch::Ptr
TexturePatch::create(int label, std::vector<std::size_t> const & faces,
std::vector<math::Vec2f> const & texcoords, core::ByteImage::Ptr image) {
return Ptr(new TexturePatch(label, faces, texcoords, image));
}
inline TexturePatch::Ptr
TexturePatch::duplicate(void) {
return Ptr(new TexturePatch(*this));
}
inline int
TexturePatch::get_label(void) const {
return label;
}
inline int
TexturePatch::get_width(void) const {
return image->width();
}
inline int
TexturePatch::get_height(void) const {
return image->height();
}
inline core::FloatImage::ConstPtr
TexturePatch::get_image(void) const {
return image;
}
inline core::ByteImage::ConstPtr
TexturePatch::get_validity_mask(void) const {
return validity_mask;
}
inline core::ByteImage::ConstPtr
TexturePatch::get_blending_mask(void) const {
assert(blending_mask != NULL);
return blending_mask;
}
inline void
TexturePatch::release_blending_mask(void) {
assert(blending_mask != NULL);
blending_mask.reset();
}
inline std::vector<math::Vec2f> &
TexturePatch::get_texcoords(void) {
return texcoords;
}
inline std::vector<std::size_t> &
TexturePatch::get_faces(void) {
return faces;
}
inline std::vector<math::Vec2f> const &
TexturePatch::get_texcoords(void) const {
return texcoords;
}
inline std::vector<std::size_t> const &
TexturePatch::get_faces(void) const {
return faces;
}
inline int
TexturePatch::get_size(void) const {
return get_width() * get_height();
}
inline bool
TexturePatch::operator<(TexturePatch const & other) const {
return get_size() < other.get_size();
}
#endif /* TEX_TEXTUREPATCH_HEADER */