Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
P
polymesh
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container registry
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Philip Trettner
polymesh
Commits
f3ce6a89
Commit
f3ce6a89
authored
3 years ago
by
Julius Nehring-Wirxel
Browse files
Options
Downloads
Patches
Plain Diff
Normalize now returns scale and center
parent
76e20b6b
No related branches found
No related tags found
1 merge request
!31
Normalize now returns scale and center
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/polymesh/algorithms/normalize.hh
+16
-5
16 additions, 5 deletions
src/polymesh/algorithms/normalize.hh
with
16 additions
and
5 deletions
src/polymesh/algorithms/normalize.hh
+
16
−
5
View file @
f3ce6a89
...
...
@@ -5,9 +5,19 @@
namespace
polymesh
{
template
<
class
ScalarT
>
struct
normalize_result
{
ScalarT
scale
;
ScalarT
center_x
;
ScalarT
center_y
;
ScalarT
center_z
;
};
/// Applies a translation and a uniform rescaling such that the mesh is centerd at (0,0,0) and within the [-1 .. 1] cube
/// Returns scale and center so that applying scale * p + center on a normalized point p yields in the original point
template
<
class
Pos3
>
void
normalize
(
vertex_attribute
<
Pos3
>&
pos
)
auto
normalize
(
vertex_attribute
<
Pos3
>&
pos
)
{
using
ScalarT
=
std
::
decay_t
<
decltype
(
pos
.
first
()[
0
])
>
;
...
...
@@ -27,12 +37,13 @@ void normalize(vertex_attribute<Pos3>& pos)
auto
sz
=
ma
[
2
]
-
mi
[
2
];
auto
s
=
std
::
max
(
sx
,
std
::
max
(
sy
,
sz
))
*
ScalarT
(
0.5
);
s
=
std
::
max
(
s
,
std
::
numeric_limits
<
ScalarT
>::
min
());
auto
s_inv
=
1
/
s
;
for
(
auto
&
p
:
pos
)
{
p
[
0
]
=
(
p
[
0
]
-
cx
)
/
s
;
p
[
1
]
=
(
p
[
1
]
-
cy
)
/
s
;
p
[
2
]
=
(
p
[
2
]
-
cz
)
/
s
;
p
[
0
]
=
(
p
[
0
]
-
cx
)
*
s
_inv
;
p
[
1
]
=
(
p
[
1
]
-
cy
)
*
s
_inv
;
p
[
2
]
=
(
p
[
2
]
-
cz
)
*
s
_inv
;
}
return
normalize_result
<
ScalarT
>
{
s
,
cx
,
cy
,
cz
};
}
}
// namespace polymesh
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
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!
Save comment
Cancel
Please
register
or
sign in
to comment