Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Philip Trettner
polymesh
Commits
9c1d0adc
Commit
9c1d0adc
authored
Jul 17, 2018
by
Philip Trettner
Browse files
working on optimization
parent
ccd228a2
Changes
4
Hide whitespace changes
Inline
Side-by-side
src/polymesh/algorithms/optimization.hh
View file @
9c1d0adc
...
...
@@ -4,6 +4,7 @@
#include
"../detail/permutation.hh"
#include
"../detail/random.hh"
#include
"../detail/union_find.hh"
namespace
polymesh
{
...
...
@@ -62,6 +63,17 @@ inline void optimize_for_rendering(Mesh& m)
inline
std
::
vector
<
int
>
cache_coherent_face_layout
(
Mesh
const
&
m
)
{
// build binary tree
// - approx min cut
// - refine approx
// - split
std
::
vector
<
std
::
pair
<
int
,
int
>>
edges
;
for
(
auto
e
:
m
.
edges
())
edges
.
emplace_back
((
int
)
e
.
faceA
(),
(
int
)
e
.
faceB
());
// TODO
std
::
vector
<
int
>
id
;
for
(
auto
i
=
0u
;
i
<
m
.
faces
().
size
();
++
i
)
id
.
push_back
(
i
);
...
...
src/polymesh/algorithms/topology.hh
0 → 100644
View file @
9c1d0adc
#pragma once
#include
<vector>
#include
"../Mesh.hh"
namespace
polymesh
{
/// Given a face handle, returns the topologically farthest (but finite) face
/// (i.e. the last face that would be visited in a BFS)
face_handle
farthest_face
(
face_handle
f
);
/// ======== IMPLEMENTATION ========
/*inline face_handle farthest_face(face_handle f)
{
std::vector<face_index> q_curr;
std::vector<face_index> q_next;
q_curr.push_back(f.idx);
face_handle last_f = f;
while (!q_curr.empty())
{
for (auto f : q_curr)
{
// TODO
}
std::swap(q_curr, q_next);
}
return last_f;
}*/
}
src/polymesh/cursors.hh
View file @
9c1d0adc
...
...
@@ -31,6 +31,8 @@ struct primitive_index
bool
operator
==
(
handle_t
const
&
rhs
)
const
{
return
value
==
rhs
.
idx
.
value
;
}
bool
operator
!=
(
handle_t
const
&
rhs
)
const
{
return
value
!=
rhs
.
idx
.
value
;
}
explicit
operator
int
()
const
{
return
value
;
}
/// indexes this primitive by a functor
/// also works for attributes
/// - e.g. v[position] or f[area]
...
...
@@ -57,6 +59,8 @@ struct primitive_handle
bool
operator
==
(
handle_t
const
&
rhs
)
const
{
return
mesh
==
rhs
.
mesh
&&
idx
==
rhs
.
idx
;
}
bool
operator
!=
(
handle_t
const
&
rhs
)
const
{
return
mesh
!=
rhs
.
mesh
||
idx
!=
rhs
.
idx
;
}
explicit
operator
int
()
const
{
return
(
int
)
idx
;
}
/// indexes this primitive by a functor
/// also works for attributes
/// - e.g. v[position] or f[area]
...
...
src/polymesh/detail/union_find.hh
0 → 100644
View file @
9c1d0adc
#pragma once
#include
<vector>
namespace
polymesh
{
namespace
detail
{
struct
disjoint_set
{
public:
disjoint_set
(
int
size
)
:
entries
(
size
)
{
for
(
auto
i
=
0
;
i
<
size
;
++
i
)
{
auto
&
e
=
entries
[
i
];
e
.
parent
=
i
;
e
.
size
=
1
;
}
}
int
find
(
int
idx
)
{
auto
&
e
=
entries
[
idx
];
if
(
e
.
parent
!=
idx
)
e
.
parent
=
find
(
e
.
parent
);
return
e
.
parent
;
}
bool
do_union
(
int
x
,
int
y
)
{
// union by size
auto
x_root
=
find
(
x
);
auto
y_root
=
find
(
y
);
if
(
x_root
==
y_root
)
return
false
;
if
(
entries
[
x_root
].
size
<
entries
[
y_root
].
size
)
std
::
swap
(
x_root
,
y_root
);
// |X| > |Y|
entries
[
y_root
].
parent
=
x_root
;
entries
[
x_root
].
size
+=
entries
[
y_root
].
size
;
return
true
;
}
private:
struct
entry
{
int
parent
;
int
size
;
};
private:
std
::
vector
<
entry
>
entries
;
};
}
}
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment