forked from swayfreeda/ImageBasedModellingEduV1.0
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtexture_atlas.h
executable file
·101 lines (77 loc) · 2.35 KB
/
texture_atlas.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
/*
* 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_TEXTUREATLAS_HEADER
#define TEX_TEXTUREATLAS_HEADER
#include <vector>
#include <util/exception.h>
#include <math/vector.h>
#include <core/mesh.h>
#include <core/image.h>
#include "tri.h"
#include "texture_patch.h"
#include "rectangular_bin.h"
/**
* Class representing a texture atlas.
*/
class TextureAtlas {
public:
typedef std::shared_ptr<TextureAtlas> Ptr;
typedef std::vector<std::size_t> Faces;
typedef std::vector<std::size_t> TexcoordIds;
typedef std::vector<math::Vec2f> Texcoords;
private:
unsigned int const size;
unsigned int const padding;
bool finalized;
Faces faces;
Texcoords texcoords;
TexcoordIds texcoord_ids;
core::ByteImage::Ptr image;
core::ByteImage::Ptr validity_mask;
RectangularBin::Ptr bin;
std::string filename;
void apply_edge_padding(void);
void merge_texcoords(void);
public:
/** Constructs a texture patch. */
TextureAtlas(unsigned int size);
~TextureAtlas(void);
static TextureAtlas::Ptr create(unsigned int size);
Faces const & get_faces(void) const;
TexcoordIds const & get_texcoord_ids(void) const;
Texcoords const & get_texcoords(void) const;
std::string const & get_filename(void) const;
bool insert(TexturePatch::ConstPtr texture_patch,
float vmin, float vmax);
void finalize(void);
};
inline TextureAtlas::Ptr
TextureAtlas::create(unsigned int size) {
return Ptr(new TextureAtlas(size));
}
inline TextureAtlas::Faces const &
TextureAtlas::get_faces(void) const {
return faces;
}
inline TextureAtlas::TexcoordIds const &
TextureAtlas::get_texcoord_ids(void) const {
return texcoord_ids;
}
inline TextureAtlas::Texcoords const &
TextureAtlas::get_texcoords(void) const {
return texcoords;
}
inline std::string const &
TextureAtlas::get_filename(void) const {
if (!finalized) {
throw util::Exception("Texture atlas not finalized");
}
return filename;
}
#endif /* TEX_TEXTUREATLAS_HEADER */