MVE - Multi-View Environment mve-devel
Loading...
Searching...
No Matches
basis_function.cc
Go to the documentation of this file.
1/*
2 * Copyright (C) 2015, 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#include <algorithm>
11
12#include "math/vector.h"
13#include "math/matrix.h"
14#include "math/matrix_tools.h"
15#include "math/functions.h"
16#include "fssr/basis_function.h"
17
19
20void
21evaluate (math::Vec3f const& pos, Sample const& sample,
22 double* value, double* weight,
23 math::Vector<double, 3>* value_deriv,
24 math::Vector<double, 3>* weight_deriv)
25{
26 /* Rotate voxel position into the sample's LCS. */
28 rotation_from_normal(sample.normal, &rot);
29 math::Vec3f tpos = rot * (pos - sample.pos);
30
31 /* Evaluate basis and weight functions. */
32 (*value) = fssr_basis<double>(sample.scale, tpos, value_deriv);
33 (*weight) = fssr_weight<double>(sample.scale, tpos, weight_deriv);
34
35 if (value_deriv == nullptr && weight_deriv == nullptr)
36 return;
37
38 /* Rotate derivative back to original coordinate system. */
39 math::Matrix3f irot = rot.transposed();
40 if (value_deriv != nullptr)
41 *value_deriv = irot.mult(*value_deriv);
42 if (weight_deriv != nullptr)
43 *weight_deriv = irot.mult(*weight_deriv);
44}
45
46/*
47 * Rotation from normal in 3D using two axis orthogonal to the normal.
48 */
49void
51{
52 math::Vec3f const ref(1.0f, 0.0f, 0.0f);
53 if (normal.is_similar(ref, 0.001f))
54 {
56 return;
57 }
58
59 math::Vec3f const mirror(-1.0f, 0.0f, 0.0f);
60 if (normal.is_similar(mirror, 0.001f))
61 {
62 /* 180 degree rotation around the z-axis. */
63 (*rot)[0] = -1.0f; (*rot)[1] = 0.0f; (*rot)[2] = 0.0f;
64 (*rot)[3] = 0.0f; (*rot)[4] = -1.0f; (*rot)[5] = 0.0f;
65 (*rot)[6] = 0.0f; (*rot)[7] = 0.0f; (*rot)[8] = 1.0f;
66 return;
67 }
68
69 math::Vec3f const axis1 = normal.cross(ref).normalized();
70 math::Vec3f const axis2 = normal.cross(axis1);
71 std::copy(normal.begin(), normal.end(), rot->begin() + 0);
72 std::copy(axis1.begin(), axis1.end(), rot->begin() + 3);
73 std::copy(axis2.begin(), axis2.end(), rot->begin() + 6);
74}
75
76/*
77 * The 2D rotation matrix where cos(angle) and sin(angle) is directly
78 * taken from the normal. The reference normal is oriented toward the
79 * positive x-axis.
80 */
81void
83{
84 (*rot)[0] = normal[0];
85 (*rot)[1] = normal[1];
86 (*rot)[2] = -normal[1];
87 (*rot)[3] = normal[0];
88}
89
Matrix class for arbitrary dimensions and types.
Definition matrix.h:54
Matrix< T, N, U > mult(Matrix< T, M, U > const &rhs) const
Matrix with matrix multiplication.
Definition matrix.h:462
Matrix< T, M, N > transposed(void) const
Returns a transposed copy of self by treating rows as columns.
Definition matrix.h:448
T * begin(void)
Definition matrix.h:506
Vector class for arbitrary dimensions and types.
Definition vector.h:87
Vector< T, N > cross(Vector< T, N > const &other) const
Cross product between this and another vector.
Definition vector.h:549
T * end(void)
Definition vector.h:597
bool is_similar(Vector< T, N > const &other, T const &epsilon) const
Component-wise similarity using epsilon checks.
Definition vector.h:574
T * begin(void)
Definition vector.h:583
#define FSSR_NAMESPACE_END
Definition defines.h:14
#define FSSR_NAMESPACE_BEGIN
Definition defines.h:13
void rotation_from_normal(math::Vec3f const &normal, math::Matrix3f *rot)
Generates a rotation matrix that transforms in the FSSR LCS.
void evaluate(math::Vec3f const &pos, Sample const &sample, double *value, double *weight, math::Vector< double, 3 > *value_deriv, math::Vector< double, 3 > *weight_deriv)
Rotates the given point in the LCS of the sample, evaluates the basis and weight functions and their ...
Matrix< T, N, N > & matrix_set_identity(Matrix< T, N, N > *mat)
Sets the given square matrix to the identity matrix.
Representation of a point sample.
Definition sample.h:22
math::Vec3f pos
Definition sample.h:23
math::Vec3f normal
Definition sample.h:24
float scale
Definition sample.h:26