warp-lang 1.0.2__py3-none-manylinux2014_x86_64.whl → 1.2.0__py3-none-manylinux2014_x86_64.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Potentially problematic release.
This version of warp-lang might be problematic. Click here for more details.
- warp/__init__.py +108 -97
- warp/__init__.pyi +1 -1
- warp/bin/warp-clang.so +0 -0
- warp/bin/warp.so +0 -0
- warp/build.py +88 -113
- warp/build_dll.py +383 -375
- warp/builtins.py +3693 -3354
- warp/codegen.py +2925 -2792
- warp/config.py +40 -36
- warp/constants.py +49 -45
- warp/context.py +5409 -5102
- warp/dlpack.py +442 -442
- warp/examples/__init__.py +16 -16
- warp/examples/assets/bear.usd +0 -0
- warp/examples/assets/bunny.usd +0 -0
- warp/examples/assets/cartpole.urdf +110 -110
- warp/examples/assets/crazyflie.usd +0 -0
- warp/examples/assets/cube.usd +0 -0
- warp/examples/assets/nv_ant.xml +92 -92
- warp/examples/assets/nv_humanoid.xml +183 -183
- warp/examples/assets/quadruped.urdf +267 -267
- warp/examples/assets/rocks.nvdb +0 -0
- warp/examples/assets/rocks.usd +0 -0
- warp/examples/assets/sphere.usd +0 -0
- warp/examples/benchmarks/benchmark_api.py +381 -383
- warp/examples/benchmarks/benchmark_cloth.py +278 -277
- warp/examples/benchmarks/benchmark_cloth_cupy.py +88 -88
- warp/examples/benchmarks/benchmark_cloth_jax.py +97 -100
- warp/examples/benchmarks/benchmark_cloth_numba.py +146 -142
- warp/examples/benchmarks/benchmark_cloth_numpy.py +77 -77
- warp/examples/benchmarks/benchmark_cloth_pytorch.py +86 -86
- warp/examples/benchmarks/benchmark_cloth_taichi.py +112 -112
- warp/examples/benchmarks/benchmark_cloth_warp.py +145 -146
- warp/examples/benchmarks/benchmark_launches.py +293 -295
- warp/examples/browse.py +29 -29
- warp/examples/core/example_dem.py +232 -219
- warp/examples/core/example_fluid.py +291 -267
- warp/examples/core/example_graph_capture.py +142 -126
- warp/examples/core/example_marching_cubes.py +186 -174
- warp/examples/core/example_mesh.py +172 -155
- warp/examples/core/example_mesh_intersect.py +203 -193
- warp/examples/core/example_nvdb.py +174 -170
- warp/examples/core/example_raycast.py +103 -90
- warp/examples/core/example_raymarch.py +197 -178
- warp/examples/core/example_render_opengl.py +183 -141
- warp/examples/core/example_sph.py +403 -387
- warp/examples/core/example_torch.py +219 -181
- warp/examples/core/example_wave.py +261 -248
- warp/examples/fem/bsr_utils.py +378 -380
- warp/examples/fem/example_apic_fluid.py +432 -389
- warp/examples/fem/example_burgers.py +262 -0
- warp/examples/fem/example_convection_diffusion.py +180 -168
- warp/examples/fem/example_convection_diffusion_dg.py +217 -209
- warp/examples/fem/example_deformed_geometry.py +175 -159
- warp/examples/fem/example_diffusion.py +199 -173
- warp/examples/fem/example_diffusion_3d.py +178 -152
- warp/examples/fem/example_diffusion_mgpu.py +219 -214
- warp/examples/fem/example_mixed_elasticity.py +242 -222
- warp/examples/fem/example_navier_stokes.py +257 -243
- warp/examples/fem/example_stokes.py +218 -192
- warp/examples/fem/example_stokes_transfer.py +263 -249
- warp/examples/fem/mesh_utils.py +133 -109
- warp/examples/fem/plot_utils.py +292 -287
- warp/examples/optim/example_bounce.py +258 -246
- warp/examples/optim/example_cloth_throw.py +220 -209
- warp/examples/optim/example_diffray.py +564 -536
- warp/examples/optim/example_drone.py +862 -835
- warp/examples/optim/example_inverse_kinematics.py +174 -168
- warp/examples/optim/example_inverse_kinematics_torch.py +183 -169
- warp/examples/optim/example_spring_cage.py +237 -231
- warp/examples/optim/example_trajectory.py +221 -199
- warp/examples/optim/example_walker.py +304 -293
- warp/examples/sim/example_cartpole.py +137 -129
- warp/examples/sim/example_cloth.py +194 -186
- warp/examples/sim/example_granular.py +122 -111
- warp/examples/sim/example_granular_collision_sdf.py +195 -186
- warp/examples/sim/example_jacobian_ik.py +234 -214
- warp/examples/sim/example_particle_chain.py +116 -105
- warp/examples/sim/example_quadruped.py +191 -180
- warp/examples/sim/example_rigid_chain.py +195 -187
- warp/examples/sim/example_rigid_contact.py +187 -177
- warp/examples/sim/example_rigid_force.py +125 -125
- warp/examples/sim/example_rigid_gyroscopic.py +107 -95
- warp/examples/sim/example_rigid_soft_contact.py +132 -122
- warp/examples/sim/example_soft_body.py +188 -177
- warp/fabric.py +337 -335
- warp/fem/__init__.py +61 -27
- warp/fem/cache.py +403 -388
- warp/fem/dirichlet.py +178 -179
- warp/fem/domain.py +262 -263
- warp/fem/field/__init__.py +100 -101
- warp/fem/field/field.py +148 -149
- warp/fem/field/nodal_field.py +298 -299
- warp/fem/field/restriction.py +22 -21
- warp/fem/field/test.py +180 -181
- warp/fem/field/trial.py +183 -183
- warp/fem/geometry/__init__.py +16 -19
- warp/fem/geometry/closest_point.py +69 -70
- warp/fem/geometry/deformed_geometry.py +270 -271
- warp/fem/geometry/element.py +748 -744
- warp/fem/geometry/geometry.py +184 -186
- warp/fem/geometry/grid_2d.py +380 -373
- warp/fem/geometry/grid_3d.py +437 -435
- warp/fem/geometry/hexmesh.py +953 -953
- warp/fem/geometry/nanogrid.py +455 -0
- warp/fem/geometry/partition.py +374 -376
- warp/fem/geometry/quadmesh_2d.py +532 -532
- warp/fem/geometry/tetmesh.py +840 -840
- warp/fem/geometry/trimesh_2d.py +577 -577
- warp/fem/integrate.py +1684 -1615
- warp/fem/operator.py +190 -191
- warp/fem/polynomial.py +214 -213
- warp/fem/quadrature/__init__.py +2 -2
- warp/fem/quadrature/pic_quadrature.py +243 -245
- warp/fem/quadrature/quadrature.py +295 -294
- warp/fem/space/__init__.py +179 -292
- warp/fem/space/basis_space.py +522 -489
- warp/fem/space/collocated_function_space.py +100 -105
- warp/fem/space/dof_mapper.py +236 -236
- warp/fem/space/function_space.py +148 -145
- warp/fem/space/grid_2d_function_space.py +148 -267
- warp/fem/space/grid_3d_function_space.py +167 -306
- warp/fem/space/hexmesh_function_space.py +253 -352
- warp/fem/space/nanogrid_function_space.py +202 -0
- warp/fem/space/partition.py +350 -350
- warp/fem/space/quadmesh_2d_function_space.py +261 -369
- warp/fem/space/restriction.py +161 -160
- warp/fem/space/shape/__init__.py +90 -15
- warp/fem/space/shape/cube_shape_function.py +728 -738
- warp/fem/space/shape/shape_function.py +102 -103
- warp/fem/space/shape/square_shape_function.py +611 -611
- warp/fem/space/shape/tet_shape_function.py +565 -567
- warp/fem/space/shape/triangle_shape_function.py +429 -429
- warp/fem/space/tetmesh_function_space.py +224 -292
- warp/fem/space/topology.py +297 -295
- warp/fem/space/trimesh_2d_function_space.py +153 -221
- warp/fem/types.py +77 -77
- warp/fem/utils.py +495 -495
- warp/jax.py +166 -141
- warp/jax_experimental.py +341 -339
- warp/native/array.h +1081 -1025
- warp/native/builtin.h +1603 -1560
- warp/native/bvh.cpp +402 -398
- warp/native/bvh.cu +533 -525
- warp/native/bvh.h +430 -429
- warp/native/clang/clang.cpp +496 -464
- warp/native/crt.cpp +42 -32
- warp/native/crt.h +352 -335
- warp/native/cuda_crt.h +1049 -1049
- warp/native/cuda_util.cpp +549 -540
- warp/native/cuda_util.h +288 -203
- warp/native/cutlass_gemm.cpp +34 -34
- warp/native/cutlass_gemm.cu +372 -372
- warp/native/error.cpp +66 -66
- warp/native/error.h +27 -27
- warp/native/exports.h +187 -0
- warp/native/fabric.h +228 -228
- warp/native/hashgrid.cpp +301 -278
- warp/native/hashgrid.cu +78 -77
- warp/native/hashgrid.h +227 -227
- warp/native/initializer_array.h +32 -32
- warp/native/intersect.h +1204 -1204
- warp/native/intersect_adj.h +365 -365
- warp/native/intersect_tri.h +322 -322
- warp/native/marching.cpp +2 -2
- warp/native/marching.cu +497 -497
- warp/native/marching.h +2 -2
- warp/native/mat.h +1545 -1498
- warp/native/matnn.h +333 -333
- warp/native/mesh.cpp +203 -203
- warp/native/mesh.cu +292 -293
- warp/native/mesh.h +1887 -1887
- warp/native/nanovdb/GridHandle.h +366 -0
- warp/native/nanovdb/HostBuffer.h +590 -0
- warp/native/nanovdb/NanoVDB.h +6624 -4782
- warp/native/nanovdb/PNanoVDB.h +3390 -2553
- warp/native/noise.h +850 -850
- warp/native/quat.h +1112 -1085
- warp/native/rand.h +303 -299
- warp/native/range.h +108 -108
- warp/native/reduce.cpp +156 -156
- warp/native/reduce.cu +348 -348
- warp/native/runlength_encode.cpp +61 -61
- warp/native/runlength_encode.cu +46 -46
- warp/native/scan.cpp +30 -30
- warp/native/scan.cu +36 -36
- warp/native/scan.h +7 -7
- warp/native/solid_angle.h +442 -442
- warp/native/sort.cpp +94 -94
- warp/native/sort.cu +97 -97
- warp/native/sort.h +14 -14
- warp/native/sparse.cpp +337 -337
- warp/native/sparse.cu +544 -544
- warp/native/spatial.h +630 -630
- warp/native/svd.h +562 -562
- warp/native/temp_buffer.h +30 -30
- warp/native/vec.h +1177 -1133
- warp/native/volume.cpp +529 -297
- warp/native/volume.cu +58 -32
- warp/native/volume.h +960 -538
- warp/native/volume_builder.cu +446 -425
- warp/native/volume_builder.h +34 -19
- warp/native/volume_impl.h +61 -0
- warp/native/warp.cpp +1057 -1052
- warp/native/warp.cu +2949 -2828
- warp/native/warp.h +321 -305
- warp/optim/__init__.py +9 -9
- warp/optim/adam.py +120 -120
- warp/optim/linear.py +1104 -939
- warp/optim/sgd.py +104 -92
- warp/render/__init__.py +10 -10
- warp/render/render_opengl.py +3356 -3204
- warp/render/render_usd.py +768 -749
- warp/render/utils.py +152 -150
- warp/sim/__init__.py +52 -59
- warp/sim/articulation.py +685 -685
- warp/sim/collide.py +1594 -1590
- warp/sim/import_mjcf.py +489 -481
- warp/sim/import_snu.py +220 -221
- warp/sim/import_urdf.py +536 -516
- warp/sim/import_usd.py +887 -881
- warp/sim/inertia.py +316 -317
- warp/sim/integrator.py +234 -233
- warp/sim/integrator_euler.py +1956 -1956
- warp/sim/integrator_featherstone.py +1917 -1991
- warp/sim/integrator_xpbd.py +3288 -3312
- warp/sim/model.py +4473 -4314
- warp/sim/particles.py +113 -112
- warp/sim/render.py +417 -403
- warp/sim/utils.py +413 -410
- warp/sparse.py +1289 -1227
- warp/stubs.py +2192 -2469
- warp/tape.py +1162 -225
- warp/tests/__init__.py +1 -1
- warp/tests/__main__.py +4 -4
- warp/tests/assets/test_index_grid.nvdb +0 -0
- warp/tests/assets/torus.usda +105 -105
- warp/tests/aux_test_class_kernel.py +26 -26
- warp/tests/aux_test_compile_consts_dummy.py +10 -10
- warp/tests/aux_test_conditional_unequal_types_kernels.py +21 -21
- warp/tests/aux_test_dependent.py +20 -22
- warp/tests/aux_test_grad_customs.py +21 -23
- warp/tests/aux_test_reference.py +9 -11
- warp/tests/aux_test_reference_reference.py +8 -10
- warp/tests/aux_test_square.py +15 -17
- warp/tests/aux_test_unresolved_func.py +14 -14
- warp/tests/aux_test_unresolved_symbol.py +14 -14
- warp/tests/disabled_kinematics.py +237 -239
- warp/tests/run_coverage_serial.py +31 -31
- warp/tests/test_adam.py +155 -157
- warp/tests/test_arithmetic.py +1088 -1124
- warp/tests/test_array.py +2415 -2326
- warp/tests/test_array_reduce.py +148 -150
- warp/tests/test_async.py +666 -656
- warp/tests/test_atomic.py +139 -141
- warp/tests/test_bool.py +212 -149
- warp/tests/test_builtins_resolution.py +1290 -1292
- warp/tests/test_bvh.py +162 -171
- warp/tests/test_closest_point_edge_edge.py +227 -228
- warp/tests/test_codegen.py +562 -553
- warp/tests/test_compile_consts.py +217 -101
- warp/tests/test_conditional.py +244 -246
- warp/tests/test_copy.py +230 -215
- warp/tests/test_ctypes.py +630 -632
- warp/tests/test_dense.py +65 -67
- warp/tests/test_devices.py +89 -98
- warp/tests/test_dlpack.py +528 -529
- warp/tests/test_examples.py +403 -378
- warp/tests/test_fabricarray.py +952 -955
- warp/tests/test_fast_math.py +60 -54
- warp/tests/test_fem.py +1298 -1278
- warp/tests/test_fp16.py +128 -130
- warp/tests/test_func.py +336 -337
- warp/tests/test_generics.py +596 -571
- warp/tests/test_grad.py +885 -640
- warp/tests/test_grad_customs.py +331 -336
- warp/tests/test_hash_grid.py +208 -164
- warp/tests/test_import.py +37 -39
- warp/tests/test_indexedarray.py +1132 -1134
- warp/tests/test_intersect.py +65 -67
- warp/tests/test_jax.py +305 -307
- warp/tests/test_large.py +169 -164
- warp/tests/test_launch.py +352 -354
- warp/tests/test_lerp.py +217 -261
- warp/tests/test_linear_solvers.py +189 -171
- warp/tests/test_lvalue.py +419 -493
- warp/tests/test_marching_cubes.py +63 -65
- warp/tests/test_mat.py +1799 -1827
- warp/tests/test_mat_lite.py +113 -115
- warp/tests/test_mat_scalar_ops.py +2905 -2889
- warp/tests/test_math.py +124 -193
- warp/tests/test_matmul.py +498 -499
- warp/tests/test_matmul_lite.py +408 -410
- warp/tests/test_mempool.py +186 -190
- warp/tests/test_mesh.py +281 -324
- warp/tests/test_mesh_query_aabb.py +226 -241
- warp/tests/test_mesh_query_point.py +690 -702
- warp/tests/test_mesh_query_ray.py +290 -303
- warp/tests/test_mlp.py +274 -276
- warp/tests/test_model.py +108 -110
- warp/tests/test_module_hashing.py +111 -0
- warp/tests/test_modules_lite.py +36 -39
- warp/tests/test_multigpu.py +161 -163
- warp/tests/test_noise.py +244 -248
- warp/tests/test_operators.py +248 -250
- warp/tests/test_options.py +121 -125
- warp/tests/test_peer.py +131 -137
- warp/tests/test_pinned.py +76 -78
- warp/tests/test_print.py +52 -54
- warp/tests/test_quat.py +2084 -2086
- warp/tests/test_rand.py +324 -288
- warp/tests/test_reload.py +207 -217
- warp/tests/test_rounding.py +177 -179
- warp/tests/test_runlength_encode.py +188 -190
- warp/tests/test_sim_grad.py +241 -0
- warp/tests/test_sim_kinematics.py +89 -97
- warp/tests/test_smoothstep.py +166 -168
- warp/tests/test_snippet.py +303 -266
- warp/tests/test_sparse.py +466 -460
- warp/tests/test_spatial.py +2146 -2148
- warp/tests/test_special_values.py +362 -0
- warp/tests/test_streams.py +484 -473
- warp/tests/test_struct.py +708 -675
- warp/tests/test_tape.py +171 -148
- warp/tests/test_torch.py +741 -743
- warp/tests/test_transient_module.py +85 -87
- warp/tests/test_types.py +554 -659
- warp/tests/test_utils.py +488 -499
- warp/tests/test_vec.py +1262 -1268
- warp/tests/test_vec_lite.py +71 -73
- warp/tests/test_vec_scalar_ops.py +2097 -2099
- warp/tests/test_verify_fp.py +92 -94
- warp/tests/test_volume.py +961 -736
- warp/tests/test_volume_write.py +338 -265
- warp/tests/unittest_serial.py +38 -37
- warp/tests/unittest_suites.py +367 -359
- warp/tests/unittest_utils.py +434 -578
- warp/tests/unused_test_misc.py +69 -71
- warp/tests/walkthrough_debug.py +85 -85
- warp/thirdparty/appdirs.py +598 -598
- warp/thirdparty/dlpack.py +143 -143
- warp/thirdparty/unittest_parallel.py +563 -561
- warp/torch.py +321 -295
- warp/types.py +4941 -4450
- warp/utils.py +1008 -821
- {warp_lang-1.0.2.dist-info → warp_lang-1.2.0.dist-info}/LICENSE.md +126 -126
- {warp_lang-1.0.2.dist-info → warp_lang-1.2.0.dist-info}/METADATA +365 -400
- warp_lang-1.2.0.dist-info/RECORD +359 -0
- warp/examples/assets/cube.usda +0 -42
- warp/examples/assets/sphere.usda +0 -56
- warp/examples/assets/torus.usda +0 -105
- warp/examples/fem/example_convection_diffusion_dg0.py +0 -194
- warp/native/nanovdb/PNanoVDBWrite.h +0 -295
- warp_lang-1.0.2.dist-info/RECORD +0 -352
- {warp_lang-1.0.2.dist-info → warp_lang-1.2.0.dist-info}/WHEEL +0 -0
- {warp_lang-1.0.2.dist-info → warp_lang-1.2.0.dist-info}/top_level.txt +0 -0
warp/native/quat.h
CHANGED
|
@@ -1,1085 +1,1112 @@
|
|
|
1
|
-
/** Copyright (c) 2022 NVIDIA CORPORATION. All rights reserved.
|
|
2
|
-
* NVIDIA CORPORATION and its licensors retain all intellectual property
|
|
3
|
-
* and proprietary rights in and to this software, related documentation
|
|
4
|
-
* and any modifications thereto. Any use, reproduction, disclosure or
|
|
5
|
-
* distribution of this software and related documentation without an express
|
|
6
|
-
* license agreement from NVIDIA CORPORATION is strictly prohibited.
|
|
7
|
-
*/
|
|
8
|
-
|
|
9
|
-
#pragma once
|
|
10
|
-
|
|
11
|
-
#include "mat.h"
|
|
12
|
-
|
|
13
|
-
namespace wp
|
|
14
|
-
{
|
|
15
|
-
|
|
16
|
-
template<typename Type>
|
|
17
|
-
struct quat_t
|
|
18
|
-
{
|
|
19
|
-
// zero constructor for adjoint variable initialization
|
|
20
|
-
inline CUDA_CALLABLE quat_t(Type x=Type(0), Type y=Type(0), Type z=Type(0), Type w=Type(0)) : x(x), y(y), z(z), w(w) {}
|
|
21
|
-
explicit inline CUDA_CALLABLE quat_t(const vec_t<3,Type>& v, Type w=Type(0)) : x(v[0]), y(v[1]), z(v[2]), w(w) {}
|
|
22
|
-
|
|
23
|
-
template<typename OtherType>
|
|
24
|
-
explicit inline CUDA_CALLABLE quat_t(const quat_t<OtherType>& other)
|
|
25
|
-
{
|
|
26
|
-
x = static_cast<Type>(other.x);
|
|
27
|
-
y = static_cast<Type>(other.y);
|
|
28
|
-
z = static_cast<Type>(other.z);
|
|
29
|
-
w = static_cast<Type>(other.w);
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
// imaginary part
|
|
33
|
-
Type x;
|
|
34
|
-
Type y;
|
|
35
|
-
Type z;
|
|
36
|
-
|
|
37
|
-
// real part
|
|
38
|
-
Type w;
|
|
39
|
-
};
|
|
40
|
-
|
|
41
|
-
using quat = quat_t<float>;
|
|
42
|
-
using quath = quat_t<half>;
|
|
43
|
-
using quatf = quat_t<float>;
|
|
44
|
-
using quatd = quat_t<double>;
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
template<typename Type>
|
|
48
|
-
inline CUDA_CALLABLE bool operator==(const quat_t<Type>& a, const quat_t<Type>& b)
|
|
49
|
-
{
|
|
50
|
-
return a.x == b.x && a.y == b.y && a.z == b.z && a.w == b.w;
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
template<typename Type>
|
|
54
|
-
inline bool CUDA_CALLABLE isfinite(const quat_t<Type>& q)
|
|
55
|
-
{
|
|
56
|
-
return isfinite(q.x) && isfinite(q.y) && isfinite(q.z) && isfinite(q.w);
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
template<typename Type>
|
|
60
|
-
inline CUDA_CALLABLE
|
|
61
|
-
{
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
return
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
template<typename Type>
|
|
71
|
-
inline CUDA_CALLABLE
|
|
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
|
-
Type
|
|
131
|
-
Type
|
|
132
|
-
|
|
133
|
-
Type
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
template<typename Type>
|
|
148
|
-
inline CUDA_CALLABLE Type
|
|
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
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
}
|
|
214
|
-
|
|
215
|
-
template<typename Type>
|
|
216
|
-
inline CUDA_CALLABLE quat_t<Type>
|
|
217
|
-
{
|
|
218
|
-
return
|
|
219
|
-
}
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
}
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
Type
|
|
441
|
-
|
|
442
|
-
Type
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
}
|
|
634
|
-
|
|
635
|
-
template<typename Type>
|
|
636
|
-
inline CUDA_CALLABLE void
|
|
637
|
-
{
|
|
638
|
-
|
|
639
|
-
|
|
640
|
-
|
|
641
|
-
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
|
|
648
|
-
|
|
649
|
-
|
|
650
|
-
|
|
651
|
-
|
|
652
|
-
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
|
|
661
|
-
|
|
662
|
-
|
|
663
|
-
|
|
664
|
-
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
|
|
675
|
-
Type
|
|
676
|
-
|
|
677
|
-
|
|
678
|
-
|
|
679
|
-
|
|
680
|
-
|
|
681
|
-
|
|
682
|
-
|
|
683
|
-
Type
|
|
684
|
-
|
|
685
|
-
|
|
686
|
-
|
|
687
|
-
|
|
688
|
-
|
|
689
|
-
|
|
690
|
-
|
|
691
|
-
|
|
692
|
-
|
|
693
|
-
|
|
694
|
-
|
|
695
|
-
|
|
696
|
-
|
|
697
|
-
|
|
698
|
-
|
|
699
|
-
|
|
700
|
-
|
|
701
|
-
|
|
702
|
-
|
|
703
|
-
|
|
704
|
-
|
|
705
|
-
|
|
706
|
-
|
|
707
|
-
|
|
708
|
-
|
|
709
|
-
|
|
710
|
-
|
|
711
|
-
|
|
712
|
-
|
|
713
|
-
|
|
714
|
-
|
|
715
|
-
|
|
716
|
-
|
|
717
|
-
|
|
718
|
-
|
|
719
|
-
|
|
720
|
-
|
|
721
|
-
|
|
722
|
-
|
|
723
|
-
|
|
724
|
-
|
|
725
|
-
|
|
726
|
-
|
|
727
|
-
|
|
728
|
-
|
|
729
|
-
|
|
730
|
-
|
|
731
|
-
|
|
732
|
-
|
|
733
|
-
|
|
734
|
-
|
|
735
|
-
quat_t<Type>
|
|
736
|
-
quat_t<Type>
|
|
737
|
-
|
|
738
|
-
|
|
739
|
-
|
|
740
|
-
|
|
741
|
-
|
|
742
|
-
|
|
743
|
-
|
|
744
|
-
|
|
745
|
-
|
|
746
|
-
quat_t<Type>
|
|
747
|
-
quat_t<Type>
|
|
748
|
-
quat_t<Type>
|
|
749
|
-
|
|
750
|
-
|
|
751
|
-
Type
|
|
752
|
-
Type
|
|
753
|
-
Type
|
|
754
|
-
|
|
755
|
-
|
|
756
|
-
|
|
757
|
-
|
|
758
|
-
|
|
759
|
-
|
|
760
|
-
Type
|
|
761
|
-
Type
|
|
762
|
-
Type
|
|
763
|
-
Type
|
|
764
|
-
|
|
765
|
-
|
|
766
|
-
|
|
767
|
-
|
|
768
|
-
|
|
769
|
-
|
|
770
|
-
|
|
771
|
-
|
|
772
|
-
|
|
773
|
-
|
|
774
|
-
quat_t<Type>
|
|
775
|
-
|
|
776
|
-
|
|
777
|
-
|
|
778
|
-
|
|
779
|
-
|
|
780
|
-
|
|
781
|
-
|
|
782
|
-
|
|
783
|
-
|
|
784
|
-
|
|
785
|
-
|
|
786
|
-
|
|
787
|
-
|
|
788
|
-
|
|
789
|
-
|
|
790
|
-
|
|
791
|
-
|
|
792
|
-
|
|
793
|
-
|
|
794
|
-
|
|
795
|
-
|
|
796
|
-
|
|
797
|
-
|
|
798
|
-
|
|
799
|
-
|
|
800
|
-
|
|
801
|
-
quat_t<Type>
|
|
802
|
-
|
|
803
|
-
|
|
804
|
-
|
|
805
|
-
|
|
806
|
-
|
|
807
|
-
Type
|
|
808
|
-
|
|
809
|
-
|
|
810
|
-
|
|
811
|
-
|
|
812
|
-
|
|
813
|
-
Type
|
|
814
|
-
|
|
815
|
-
|
|
816
|
-
|
|
817
|
-
|
|
818
|
-
|
|
819
|
-
|
|
820
|
-
|
|
821
|
-
|
|
822
|
-
|
|
823
|
-
|
|
824
|
-
|
|
825
|
-
|
|
826
|
-
quat_t<Type>
|
|
827
|
-
|
|
828
|
-
|
|
829
|
-
|
|
830
|
-
|
|
831
|
-
|
|
832
|
-
|
|
833
|
-
|
|
834
|
-
|
|
835
|
-
|
|
836
|
-
|
|
837
|
-
|
|
838
|
-
|
|
839
|
-
|
|
840
|
-
|
|
841
|
-
|
|
842
|
-
|
|
843
|
-
|
|
844
|
-
|
|
845
|
-
|
|
846
|
-
|
|
847
|
-
|
|
848
|
-
|
|
849
|
-
|
|
850
|
-
|
|
851
|
-
|
|
852
|
-
|
|
853
|
-
|
|
854
|
-
|
|
855
|
-
|
|
856
|
-
|
|
857
|
-
|
|
858
|
-
|
|
859
|
-
|
|
860
|
-
|
|
861
|
-
|
|
862
|
-
|
|
863
|
-
|
|
864
|
-
|
|
865
|
-
|
|
866
|
-
|
|
867
|
-
|
|
868
|
-
|
|
869
|
-
|
|
870
|
-
|
|
871
|
-
|
|
872
|
-
|
|
873
|
-
|
|
874
|
-
|
|
875
|
-
|
|
876
|
-
|
|
877
|
-
|
|
878
|
-
|
|
879
|
-
|
|
880
|
-
|
|
881
|
-
|
|
882
|
-
|
|
883
|
-
|
|
884
|
-
|
|
885
|
-
|
|
886
|
-
|
|
887
|
-
|
|
888
|
-
|
|
889
|
-
|
|
890
|
-
|
|
891
|
-
|
|
892
|
-
|
|
893
|
-
|
|
894
|
-
|
|
895
|
-
|
|
896
|
-
|
|
897
|
-
|
|
898
|
-
|
|
899
|
-
|
|
900
|
-
|
|
901
|
-
|
|
902
|
-
|
|
903
|
-
|
|
904
|
-
|
|
905
|
-
|
|
906
|
-
|
|
907
|
-
|
|
908
|
-
|
|
909
|
-
|
|
910
|
-
|
|
911
|
-
|
|
912
|
-
|
|
913
|
-
|
|
914
|
-
|
|
915
|
-
|
|
916
|
-
|
|
917
|
-
|
|
918
|
-
|
|
919
|
-
|
|
920
|
-
|
|
921
|
-
|
|
922
|
-
|
|
923
|
-
|
|
924
|
-
|
|
925
|
-
|
|
926
|
-
|
|
927
|
-
|
|
928
|
-
|
|
929
|
-
|
|
930
|
-
|
|
931
|
-
|
|
932
|
-
|
|
933
|
-
|
|
934
|
-
|
|
935
|
-
|
|
936
|
-
|
|
937
|
-
|
|
938
|
-
|
|
939
|
-
|
|
940
|
-
|
|
941
|
-
|
|
942
|
-
|
|
943
|
-
|
|
944
|
-
|
|
945
|
-
h = sqrt((m.data[
|
|
946
|
-
|
|
947
|
-
h = Type(0.5) / h;
|
|
948
|
-
|
|
949
|
-
|
|
950
|
-
|
|
951
|
-
w = (m.data[
|
|
952
|
-
|
|
953
|
-
|
|
954
|
-
|
|
955
|
-
|
|
956
|
-
|
|
957
|
-
|
|
958
|
-
|
|
959
|
-
|
|
960
|
-
|
|
961
|
-
|
|
962
|
-
|
|
963
|
-
|
|
964
|
-
|
|
965
|
-
|
|
966
|
-
|
|
967
|
-
|
|
968
|
-
dw_dm00 = Type(2) * h*h*h * (m.data[
|
|
969
|
-
dw_dm11 = Type(2) * h*h*h * (m.data[2][
|
|
970
|
-
dw_dm22 = Type(2) * h*h*h * (m.data[
|
|
971
|
-
} if (max_diag ==
|
|
972
|
-
h = sqrt((m.data[
|
|
973
|
-
|
|
974
|
-
h = Type(0.5) / h;
|
|
975
|
-
|
|
976
|
-
|
|
977
|
-
|
|
978
|
-
w = (m.data[
|
|
979
|
-
|
|
980
|
-
|
|
981
|
-
|
|
982
|
-
|
|
983
|
-
|
|
984
|
-
|
|
985
|
-
|
|
986
|
-
|
|
987
|
-
|
|
988
|
-
|
|
989
|
-
|
|
990
|
-
|
|
991
|
-
|
|
992
|
-
|
|
993
|
-
|
|
994
|
-
|
|
995
|
-
dw_dm00 = Type(2) * h*h*h * (m.data[
|
|
996
|
-
dw_dm11 = Type(2) * h*h*h * (m.data[
|
|
997
|
-
dw_dm22 = Type(2) * h*h*h * (m.data[0][
|
|
998
|
-
}
|
|
999
|
-
|
|
1000
|
-
|
|
1001
|
-
|
|
1002
|
-
|
|
1003
|
-
|
|
1004
|
-
|
|
1005
|
-
|
|
1006
|
-
|
|
1007
|
-
|
|
1008
|
-
|
|
1009
|
-
|
|
1010
|
-
|
|
1011
|
-
|
|
1012
|
-
|
|
1013
|
-
|
|
1014
|
-
|
|
1015
|
-
|
|
1016
|
-
|
|
1017
|
-
|
|
1018
|
-
|
|
1019
|
-
|
|
1020
|
-
|
|
1021
|
-
|
|
1022
|
-
|
|
1023
|
-
|
|
1024
|
-
|
|
1025
|
-
|
|
1026
|
-
|
|
1027
|
-
|
|
1028
|
-
|
|
1029
|
-
|
|
1030
|
-
|
|
1031
|
-
|
|
1032
|
-
|
|
1033
|
-
|
|
1034
|
-
|
|
1035
|
-
|
|
1036
|
-
|
|
1037
|
-
|
|
1038
|
-
|
|
1039
|
-
|
|
1040
|
-
|
|
1041
|
-
|
|
1042
|
-
|
|
1043
|
-
|
|
1044
|
-
|
|
1045
|
-
|
|
1046
|
-
|
|
1047
|
-
|
|
1048
|
-
|
|
1049
|
-
|
|
1050
|
-
|
|
1051
|
-
|
|
1052
|
-
|
|
1053
|
-
|
|
1054
|
-
|
|
1055
|
-
|
|
1056
|
-
|
|
1057
|
-
|
|
1058
|
-
|
|
1059
|
-
|
|
1060
|
-
|
|
1061
|
-
|
|
1062
|
-
|
|
1063
|
-
data[
|
|
1064
|
-
data[
|
|
1065
|
-
|
|
1066
|
-
|
|
1067
|
-
data[1][
|
|
1068
|
-
data[
|
|
1069
|
-
data[
|
|
1070
|
-
|
|
1071
|
-
data[0][
|
|
1072
|
-
data[1][
|
|
1073
|
-
data[2][
|
|
1074
|
-
|
|
1075
|
-
|
|
1076
|
-
|
|
1077
|
-
|
|
1078
|
-
|
|
1079
|
-
|
|
1080
|
-
|
|
1081
|
-
|
|
1082
|
-
|
|
1083
|
-
|
|
1084
|
-
|
|
1085
|
-
|
|
1
|
+
/** Copyright (c) 2022 NVIDIA CORPORATION. All rights reserved.
|
|
2
|
+
* NVIDIA CORPORATION and its licensors retain all intellectual property
|
|
3
|
+
* and proprietary rights in and to this software, related documentation
|
|
4
|
+
* and any modifications thereto. Any use, reproduction, disclosure or
|
|
5
|
+
* distribution of this software and related documentation without an express
|
|
6
|
+
* license agreement from NVIDIA CORPORATION is strictly prohibited.
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
#pragma once
|
|
10
|
+
|
|
11
|
+
#include "mat.h"
|
|
12
|
+
|
|
13
|
+
namespace wp
|
|
14
|
+
{
|
|
15
|
+
|
|
16
|
+
template<typename Type>
|
|
17
|
+
struct quat_t
|
|
18
|
+
{
|
|
19
|
+
// zero constructor for adjoint variable initialization
|
|
20
|
+
inline CUDA_CALLABLE quat_t(Type x=Type(0), Type y=Type(0), Type z=Type(0), Type w=Type(0)) : x(x), y(y), z(z), w(w) {}
|
|
21
|
+
explicit inline CUDA_CALLABLE quat_t(const vec_t<3,Type>& v, Type w=Type(0)) : x(v[0]), y(v[1]), z(v[2]), w(w) {}
|
|
22
|
+
|
|
23
|
+
template<typename OtherType>
|
|
24
|
+
explicit inline CUDA_CALLABLE quat_t(const quat_t<OtherType>& other)
|
|
25
|
+
{
|
|
26
|
+
x = static_cast<Type>(other.x);
|
|
27
|
+
y = static_cast<Type>(other.y);
|
|
28
|
+
z = static_cast<Type>(other.z);
|
|
29
|
+
w = static_cast<Type>(other.w);
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
// imaginary part
|
|
33
|
+
Type x;
|
|
34
|
+
Type y;
|
|
35
|
+
Type z;
|
|
36
|
+
|
|
37
|
+
// real part
|
|
38
|
+
Type w;
|
|
39
|
+
};
|
|
40
|
+
|
|
41
|
+
using quat = quat_t<float>;
|
|
42
|
+
using quath = quat_t<half>;
|
|
43
|
+
using quatf = quat_t<float>;
|
|
44
|
+
using quatd = quat_t<double>;
|
|
45
|
+
|
|
46
|
+
|
|
47
|
+
template<typename Type>
|
|
48
|
+
inline CUDA_CALLABLE bool operator==(const quat_t<Type>& a, const quat_t<Type>& b)
|
|
49
|
+
{
|
|
50
|
+
return a.x == b.x && a.y == b.y && a.z == b.z && a.w == b.w;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
template<typename Type>
|
|
54
|
+
inline bool CUDA_CALLABLE isfinite(const quat_t<Type>& q)
|
|
55
|
+
{
|
|
56
|
+
return isfinite(q.x) && isfinite(q.y) && isfinite(q.z) && isfinite(q.w);
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
template<typename Type>
|
|
60
|
+
inline void CUDA_CALLABLE adj_isfinite(const quat_t<Type>& q, quat_t<Type>& adj_q, const bool &adj_ret)
|
|
61
|
+
{
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
template<typename Type>
|
|
65
|
+
inline bool CUDA_CALLABLE isnan(const quat_t<Type>& q)
|
|
66
|
+
{
|
|
67
|
+
return isnan(q.x) || isnan(q.y) || isnan(q.z) || isnan(q.w);
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
template<typename Type>
|
|
71
|
+
inline void CUDA_CALLABLE adj_isnan(const quat_t<Type>& q, quat_t<Type>& adj_q, const bool &adj_ret)
|
|
72
|
+
{
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
template<typename Type>
|
|
76
|
+
inline bool CUDA_CALLABLE isinf(const quat_t<Type>& q)
|
|
77
|
+
{
|
|
78
|
+
return isinf(q.x) || isinf(q.y) || isinf(q.z) || isinf(q.w);
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
template<typename Type>
|
|
82
|
+
inline void CUDA_CALLABLE adj_isinf(const quat_t<Type>& q, quat_t<Type>& adj_q, const bool &adj_ret)
|
|
83
|
+
{
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
template<typename Type>
|
|
87
|
+
inline CUDA_CALLABLE quat_t<Type> atomic_add(quat_t<Type> * addr, quat_t<Type> value)
|
|
88
|
+
{
|
|
89
|
+
Type x = atomic_add(&(addr -> x), value.x);
|
|
90
|
+
Type y = atomic_add(&(addr -> y), value.y);
|
|
91
|
+
Type z = atomic_add(&(addr -> z), value.z);
|
|
92
|
+
Type w = atomic_add(&(addr -> w), value.w);
|
|
93
|
+
|
|
94
|
+
return quat_t<Type>(x, y, z, w);
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
template<typename Type>
|
|
98
|
+
inline CUDA_CALLABLE void adj_quat_t(Type x, Type y, Type z, Type w, Type& adj_x, Type& adj_y, Type& adj_z, Type& adj_w, quat_t<Type> adj_ret)
|
|
99
|
+
{
|
|
100
|
+
adj_x += adj_ret.x;
|
|
101
|
+
adj_y += adj_ret.y;
|
|
102
|
+
adj_z += adj_ret.z;
|
|
103
|
+
adj_w += adj_ret.w;
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
template<typename Type>
|
|
107
|
+
inline CUDA_CALLABLE void adj_quat_t(const vec_t<3,Type>& v, Type w, vec_t<3,Type>& adj_v, Type& adj_w, quat_t<Type> adj_ret)
|
|
108
|
+
{
|
|
109
|
+
adj_v[0] += adj_ret.x;
|
|
110
|
+
adj_v[1] += adj_ret.y;
|
|
111
|
+
adj_v[2] += adj_ret.z;
|
|
112
|
+
adj_w += adj_ret.w;
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
// casting constructor adjoint
|
|
116
|
+
template<typename Type, typename OtherType>
|
|
117
|
+
inline CUDA_CALLABLE void adj_quat_t(const quat_t<OtherType>& other, quat_t<OtherType>& adj_other, const quat_t<Type>& adj_ret)
|
|
118
|
+
{
|
|
119
|
+
adj_other.x += static_cast<OtherType>(adj_ret.x);
|
|
120
|
+
adj_other.y += static_cast<OtherType>(adj_ret.y);
|
|
121
|
+
adj_other.z += static_cast<OtherType>(adj_ret.z);
|
|
122
|
+
adj_other.w += static_cast<OtherType>(adj_ret.w);
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
// forward methods
|
|
126
|
+
|
|
127
|
+
template<typename Type>
|
|
128
|
+
inline CUDA_CALLABLE quat_t<Type> quat_from_axis_angle(const vec_t<3,Type>& axis, Type angle)
|
|
129
|
+
{
|
|
130
|
+
Type half = angle*Type(Type(0.5));
|
|
131
|
+
Type w = cos(half);
|
|
132
|
+
|
|
133
|
+
Type sin_theta_over_two = sin(half);
|
|
134
|
+
vec_t<3,Type> v = axis*sin_theta_over_two;
|
|
135
|
+
|
|
136
|
+
return quat_t<Type>(v[0], v[1], v[2], w);
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
template<typename Type>
|
|
140
|
+
inline CUDA_CALLABLE void quat_to_axis_angle(const quat_t<Type>& q, vec_t<3,Type>& axis, Type& angle)
|
|
141
|
+
{
|
|
142
|
+
vec_t<3,Type> v = vec_t<3,Type>(q.x, q.y, q.z);
|
|
143
|
+
axis = q.w < Type(0) ? -normalize(v) : normalize(v);
|
|
144
|
+
angle = Type(2) * atan2(length(v), abs(q.w));
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
template<typename Type>
|
|
148
|
+
inline CUDA_CALLABLE quat_t<Type> quat_rpy(Type roll, Type pitch, Type yaw)
|
|
149
|
+
{
|
|
150
|
+
Type cy = cos(yaw * Type(0.5));
|
|
151
|
+
Type sy = sin(yaw * Type(0.5));
|
|
152
|
+
Type cr = cos(roll * Type(0.5));
|
|
153
|
+
Type sr = sin(roll * Type(0.5));
|
|
154
|
+
Type cp = cos(pitch * Type(0.5));
|
|
155
|
+
Type sp = sin(pitch * Type(0.5));
|
|
156
|
+
|
|
157
|
+
Type w = (cy * cr * cp + sy * sr * sp);
|
|
158
|
+
Type x = (cy * sr * cp - sy * cr * sp);
|
|
159
|
+
Type y = (cy * cr * sp + sy * sr * cp);
|
|
160
|
+
Type z = (sy * cr * cp - cy * sr * sp);
|
|
161
|
+
|
|
162
|
+
return quat_t<Type>(x, y, z, w);
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
|
|
166
|
+
|
|
167
|
+
template<typename Type>
|
|
168
|
+
inline CUDA_CALLABLE quat_t<Type> quat_inverse(const quat_t<Type>& q)
|
|
169
|
+
{
|
|
170
|
+
return quat_t<Type>(-q.x, -q.y, -q.z, q.w);
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
|
|
174
|
+
template<typename Type>
|
|
175
|
+
inline CUDA_CALLABLE Type dot(const quat_t<Type>& a, const quat_t<Type>& b)
|
|
176
|
+
{
|
|
177
|
+
return a.x*b.x + a.y*b.y + a.z*b.z + a.w*b.w;
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
template<typename Type>
|
|
181
|
+
inline CUDA_CALLABLE Type tensordot(const quat_t<Type>& a, const quat_t<Type>& b)
|
|
182
|
+
{
|
|
183
|
+
// corresponds to `np.tensordot()` with all axes being contracted
|
|
184
|
+
return dot(a, b);
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
template<typename Type>
|
|
188
|
+
inline CUDA_CALLABLE Type length(const quat_t<Type>& q)
|
|
189
|
+
{
|
|
190
|
+
return sqrt(dot(q, q));
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
template<typename Type>
|
|
194
|
+
inline CUDA_CALLABLE Type length_sq(const quat_t<Type>& q)
|
|
195
|
+
{
|
|
196
|
+
return dot(q, q);
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
template<typename Type>
|
|
200
|
+
inline CUDA_CALLABLE quat_t<Type> normalize(const quat_t<Type>& q)
|
|
201
|
+
{
|
|
202
|
+
Type l = length(q);
|
|
203
|
+
if (l > Type(kEps))
|
|
204
|
+
{
|
|
205
|
+
Type inv_l = Type(1)/l;
|
|
206
|
+
|
|
207
|
+
return quat_t<Type>(q.x*inv_l, q.y*inv_l, q.z*inv_l, q.w*inv_l);
|
|
208
|
+
}
|
|
209
|
+
else
|
|
210
|
+
{
|
|
211
|
+
return quat_t<Type>(Type(0), Type(0), Type(0), Type(1));
|
|
212
|
+
}
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
template<typename Type>
|
|
216
|
+
inline CUDA_CALLABLE quat_t<Type> add(const quat_t<Type>& a, const quat_t<Type>& b)
|
|
217
|
+
{
|
|
218
|
+
return quat_t<Type>(a.x+b.x, a.y+b.y, a.z+b.z, a.w+b.w);
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
template<typename Type>
|
|
222
|
+
inline CUDA_CALLABLE quat_t<Type> sub(const quat_t<Type>& a, const quat_t<Type>& b)
|
|
223
|
+
{
|
|
224
|
+
return quat_t<Type>(a.x-b.x, a.y-b.y, a.z-b.z, a.w-b.w);}
|
|
225
|
+
|
|
226
|
+
|
|
227
|
+
template<typename Type>
|
|
228
|
+
inline CUDA_CALLABLE quat_t<Type> mul(const quat_t<Type>& a, const quat_t<Type>& b)
|
|
229
|
+
{
|
|
230
|
+
return quat_t<Type>(a.w*b.x + b.w*a.x + a.y*b.z - b.y*a.z,
|
|
231
|
+
a.w*b.y + b.w*a.y + a.z*b.x - b.z*a.x,
|
|
232
|
+
a.w*b.z + b.w*a.z + a.x*b.y - b.x*a.y,
|
|
233
|
+
a.w*b.w - a.x*b.x - a.y*b.y - a.z*b.z);
|
|
234
|
+
}
|
|
235
|
+
|
|
236
|
+
template<typename Type>
|
|
237
|
+
inline CUDA_CALLABLE quat_t<Type> mul(const quat_t<Type>& a, Type s)
|
|
238
|
+
{
|
|
239
|
+
return quat_t<Type>(a.x*s, a.y*s, a.z*s, a.w*s);
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
template<typename Type>
|
|
243
|
+
inline CUDA_CALLABLE quat_t<Type> mul(Type s, const quat_t<Type>& a)
|
|
244
|
+
{
|
|
245
|
+
return mul(a, s);
|
|
246
|
+
}
|
|
247
|
+
|
|
248
|
+
// division
|
|
249
|
+
template<typename Type>
|
|
250
|
+
inline CUDA_CALLABLE quat_t<Type> div(quat_t<Type> q, Type s)
|
|
251
|
+
{
|
|
252
|
+
return quat_t<Type>(q.x/s, q.y/s, q.z/s, q.w/s);
|
|
253
|
+
}
|
|
254
|
+
|
|
255
|
+
template<typename Type>
|
|
256
|
+
inline CUDA_CALLABLE quat_t<Type> div(Type s, quat_t<Type> q)
|
|
257
|
+
{
|
|
258
|
+
return quat_t<Type>(s/q.x, s/q.y, s/q.z, s/q.w);
|
|
259
|
+
}
|
|
260
|
+
|
|
261
|
+
template<typename Type>
|
|
262
|
+
inline CUDA_CALLABLE quat_t<Type> operator / (quat_t<Type> a, Type s)
|
|
263
|
+
{
|
|
264
|
+
return div(a,s);
|
|
265
|
+
}
|
|
266
|
+
|
|
267
|
+
template<typename Type>
|
|
268
|
+
inline CUDA_CALLABLE quat_t<Type> operator / (Type s, quat_t<Type> a)
|
|
269
|
+
{
|
|
270
|
+
return div(s,a);
|
|
271
|
+
}
|
|
272
|
+
|
|
273
|
+
template<typename Type>
|
|
274
|
+
inline CUDA_CALLABLE quat_t<Type> operator*(Type s, const quat_t<Type>& a)
|
|
275
|
+
{
|
|
276
|
+
return mul(a, s);
|
|
277
|
+
}
|
|
278
|
+
|
|
279
|
+
template<typename Type>
|
|
280
|
+
inline CUDA_CALLABLE quat_t<Type> operator*(const quat_t<Type>& a, Type s)
|
|
281
|
+
{
|
|
282
|
+
return mul(a, s);
|
|
283
|
+
}
|
|
284
|
+
|
|
285
|
+
template<typename Type>
|
|
286
|
+
inline CUDA_CALLABLE vec_t<3,Type> quat_rotate(const quat_t<Type>& q, const vec_t<3,Type>& x)
|
|
287
|
+
{
|
|
288
|
+
Type c = (Type(2)*q.w*q.w-Type(1));
|
|
289
|
+
Type d = Type(2)*(q.x*x.c[0] + q.y*x.c[1] + q.z*x.c[2]);
|
|
290
|
+
return vec_t<3,Type>(
|
|
291
|
+
x.c[0]*c + q.x*d + (q.y * x[2] - q.z * x[1])*q.w*Type(2),
|
|
292
|
+
x.c[1]*c + q.y*d + (q.z * x[0] - q.x * x[2])*q.w*Type(2),
|
|
293
|
+
x.c[2]*c + q.z*d + (q.x * x[1] - q.y * x[0])*q.w*Type(2)
|
|
294
|
+
);
|
|
295
|
+
}
|
|
296
|
+
|
|
297
|
+
template<typename Type>
|
|
298
|
+
inline CUDA_CALLABLE vec_t<3,Type> quat_rotate_inv(const quat_t<Type>& q, const vec_t<3,Type>& x)
|
|
299
|
+
{
|
|
300
|
+
Type c = (Type(2)*q.w*q.w-Type(1));
|
|
301
|
+
Type d = Type(2)*(q.x*x.c[0] + q.y*x.c[1] + q.z*x.c[2]);
|
|
302
|
+
return vec_t<3,Type>(
|
|
303
|
+
x.c[0]*c + q.x*d - (q.y * x[2] - q.z * x[1])*q.w*Type(2),
|
|
304
|
+
x.c[1]*c + q.y*d - (q.z * x[0] - q.x * x[2])*q.w*Type(2),
|
|
305
|
+
x.c[2]*c + q.z*d - (q.x * x[1] - q.y * x[0])*q.w*Type(2)
|
|
306
|
+
);
|
|
307
|
+
}
|
|
308
|
+
|
|
309
|
+
template<typename Type>
|
|
310
|
+
inline CUDA_CALLABLE quat_t<Type> quat_slerp(const quat_t<Type>& q0, const quat_t<Type>& q1, Type t)
|
|
311
|
+
{
|
|
312
|
+
vec_t<3,Type> axis;
|
|
313
|
+
Type angle;
|
|
314
|
+
quat_to_axis_angle(mul(quat_inverse(q0), q1), axis, angle);
|
|
315
|
+
return mul(q0, quat_from_axis_angle(axis, t * angle));
|
|
316
|
+
}
|
|
317
|
+
|
|
318
|
+
template<typename Type>
|
|
319
|
+
inline CUDA_CALLABLE mat_t<3,3,Type> quat_to_matrix(const quat_t<Type>& q)
|
|
320
|
+
{
|
|
321
|
+
vec_t<3,Type> c1 = quat_rotate(q, vec_t<3,Type>(1.0, 0.0, 0.0));
|
|
322
|
+
vec_t<3,Type> c2 = quat_rotate(q, vec_t<3,Type>(0.0, 1.0, 0.0));
|
|
323
|
+
vec_t<3,Type> c3 = quat_rotate(q, vec_t<3,Type>(0.0, 0.0, 1.0));
|
|
324
|
+
|
|
325
|
+
return mat_t<3,3,Type>(c1, c2, c3);
|
|
326
|
+
}
|
|
327
|
+
|
|
328
|
+
template<typename Type>
|
|
329
|
+
inline CUDA_CALLABLE quat_t<Type> quat_from_matrix(const mat_t<3,3,Type>& m)
|
|
330
|
+
{
|
|
331
|
+
const Type tr = m.data[0][0] + m.data[1][1] + m.data[2][2];
|
|
332
|
+
Type x, y, z, w, h = Type(0);
|
|
333
|
+
|
|
334
|
+
if (tr >= Type(0)) {
|
|
335
|
+
h = sqrt(tr + Type(1));
|
|
336
|
+
w = Type(0.5) * h;
|
|
337
|
+
h = Type(0.5) / h;
|
|
338
|
+
|
|
339
|
+
x = (m.data[2][1] - m.data[1][2]) * h;
|
|
340
|
+
y = (m.data[0][2] - m.data[2][0]) * h;
|
|
341
|
+
z = (m.data[1][0] - m.data[0][1]) * h;
|
|
342
|
+
} else {
|
|
343
|
+
size_t max_diag = 0;
|
|
344
|
+
if (m.data[1][1] > m.data[0][0]) {
|
|
345
|
+
max_diag = 1;
|
|
346
|
+
}
|
|
347
|
+
if (m.data[2][2] > m.data[max_diag][max_diag]) {
|
|
348
|
+
max_diag = 2;
|
|
349
|
+
}
|
|
350
|
+
|
|
351
|
+
if (max_diag == 0) {
|
|
352
|
+
h = sqrt((m.data[0][0] - (m.data[1][1] + m.data[2][2])) + Type(1));
|
|
353
|
+
x = Type(0.5) * h;
|
|
354
|
+
h = Type(0.5) / h;
|
|
355
|
+
|
|
356
|
+
y = (m.data[0][1] + m.data[1][0]) * h;
|
|
357
|
+
z = (m.data[2][0] + m.data[0][2]) * h;
|
|
358
|
+
w = (m.data[2][1] - m.data[1][2]) * h;
|
|
359
|
+
} else if (max_diag == 1) {
|
|
360
|
+
h = sqrt((m.data[1][1] - (m.data[2][2] + m.data[0][0])) + Type(1));
|
|
361
|
+
y = Type(0.5) * h;
|
|
362
|
+
h = Type(0.5) / h;
|
|
363
|
+
|
|
364
|
+
z = (m.data[1][2] + m.data[2][1]) * h;
|
|
365
|
+
x = (m.data[0][1] + m.data[1][0]) * h;
|
|
366
|
+
w = (m.data[0][2] - m.data[2][0]) * h;
|
|
367
|
+
} if (max_diag == 2) {
|
|
368
|
+
h = sqrt((m.data[2][2] - (m.data[0][0] + m.data[1][1])) + Type(1));
|
|
369
|
+
z = Type(0.5) * h;
|
|
370
|
+
h = Type(0.5) / h;
|
|
371
|
+
|
|
372
|
+
x = (m.data[2][0] + m.data[0][2]) * h;
|
|
373
|
+
y = (m.data[1][2] + m.data[2][1]) * h;
|
|
374
|
+
w = (m.data[1][0] - m.data[0][1]) * h;
|
|
375
|
+
}
|
|
376
|
+
}
|
|
377
|
+
|
|
378
|
+
return normalize(quat_t<Type>(x, y, z, w));
|
|
379
|
+
}
|
|
380
|
+
|
|
381
|
+
template<typename Type>
|
|
382
|
+
inline CUDA_CALLABLE Type extract(const quat_t<Type>& a, int idx)
|
|
383
|
+
{
|
|
384
|
+
#if FP_CHECK
|
|
385
|
+
if (idx < 0 || idx > 3)
|
|
386
|
+
{
|
|
387
|
+
printf("quat_t index %d out of bounds at %s %d", idx, __FILE__, __LINE__);
|
|
388
|
+
assert(0);
|
|
389
|
+
}
|
|
390
|
+
#endif
|
|
391
|
+
|
|
392
|
+
/*
|
|
393
|
+
* Because quat data is not stored in an array, we index the quaternion by checking all possible idx values.
|
|
394
|
+
* (&a.x)[idx] would be the preferred access strategy, but this results in undefined behavior in the clang compiler
|
|
395
|
+
* at optimization level 3.
|
|
396
|
+
*/
|
|
397
|
+
if (idx == 0) {return a.x;}
|
|
398
|
+
else if (idx == 1) {return a.y;}
|
|
399
|
+
else if (idx == 2) {return a.z;}
|
|
400
|
+
else {return a.w;}
|
|
401
|
+
}
|
|
402
|
+
|
|
403
|
+
template<typename Type>
|
|
404
|
+
CUDA_CALLABLE inline quat_t<Type> lerp(const quat_t<Type>& a, const quat_t<Type>& b, Type t)
|
|
405
|
+
{
|
|
406
|
+
return a*(Type(1)-t) + b*t;
|
|
407
|
+
}
|
|
408
|
+
|
|
409
|
+
template<typename Type>
|
|
410
|
+
CUDA_CALLABLE inline void adj_lerp(const quat_t<Type>& a, const quat_t<Type>& b, Type t, quat_t<Type>& adj_a, quat_t<Type>& adj_b, Type& adj_t, const quat_t<Type>& adj_ret)
|
|
411
|
+
{
|
|
412
|
+
adj_a += adj_ret*(Type(1)-t);
|
|
413
|
+
adj_b += adj_ret*t;
|
|
414
|
+
adj_t += tensordot(b, adj_ret) - tensordot(a, adj_ret);
|
|
415
|
+
}
|
|
416
|
+
|
|
417
|
+
template<typename Type>
|
|
418
|
+
inline CUDA_CALLABLE void adj_extract(const quat_t<Type>& a, int idx, quat_t<Type>& adj_a, int & adj_idx, Type & adj_ret)
|
|
419
|
+
{
|
|
420
|
+
#if FP_CHECK
|
|
421
|
+
if (idx < 0 || idx > 3)
|
|
422
|
+
{
|
|
423
|
+
printf("quat_t index %d out of bounds at %s %d", idx, __FILE__, __LINE__);
|
|
424
|
+
assert(0);
|
|
425
|
+
}
|
|
426
|
+
#endif
|
|
427
|
+
|
|
428
|
+
// See wp::extract(const quat_t<Type>& a, int idx) note
|
|
429
|
+
if (idx == 0) {adj_a.x += adj_ret;}
|
|
430
|
+
else if (idx == 1) {adj_a.y += adj_ret;}
|
|
431
|
+
else if (idx == 2) {adj_a.z += adj_ret;}
|
|
432
|
+
else {adj_a.w += adj_ret;}
|
|
433
|
+
}
|
|
434
|
+
|
|
435
|
+
|
|
436
|
+
// backward methods
|
|
437
|
+
template<typename Type>
|
|
438
|
+
inline CUDA_CALLABLE void adj_quat_from_axis_angle(const vec_t<3,Type>& axis, Type angle, vec_t<3,Type>& adj_axis, Type& adj_angle, const quat_t<Type>& adj_ret)
|
|
439
|
+
{
|
|
440
|
+
vec_t<3,Type> v = vec_t<3,Type>(adj_ret.x, adj_ret.y, adj_ret.z);
|
|
441
|
+
|
|
442
|
+
Type s = sin(angle*Type(0.5));
|
|
443
|
+
Type c = cos(angle*Type(0.5));
|
|
444
|
+
|
|
445
|
+
quat_t<Type> dqda = quat_t<Type>(axis[0]*c, axis[1]*c, axis[2]*c, -s)*Type(0.5);
|
|
446
|
+
|
|
447
|
+
adj_axis += v*s;
|
|
448
|
+
adj_angle += dot(dqda, adj_ret);
|
|
449
|
+
}
|
|
450
|
+
|
|
451
|
+
template<typename Type>
|
|
452
|
+
inline CUDA_CALLABLE void adj_quat_to_axis_angle(const quat_t<Type>& q, vec_t<3,Type>& axis, Type& angle, quat_t<Type>& adj_q, const vec_t<3,Type>& adj_axis, const Type& adj_angle)
|
|
453
|
+
{
|
|
454
|
+
Type l = length(vec_t<3,Type>(q.x, q.y, q.z));
|
|
455
|
+
|
|
456
|
+
Type ax_qx = Type(0);
|
|
457
|
+
Type ax_qy = Type(0);
|
|
458
|
+
Type ax_qz = Type(0);
|
|
459
|
+
Type ay_qx = Type(0);
|
|
460
|
+
Type ay_qy = Type(0);
|
|
461
|
+
Type ay_qz = Type(0);
|
|
462
|
+
Type az_qx = Type(0);
|
|
463
|
+
Type az_qy = Type(0);
|
|
464
|
+
Type az_qz = Type(0);
|
|
465
|
+
|
|
466
|
+
Type t_qx = Type(0);
|
|
467
|
+
Type t_qy = Type(0);
|
|
468
|
+
Type t_qz = Type(0);
|
|
469
|
+
Type t_qw = Type(0);
|
|
470
|
+
|
|
471
|
+
Type flip = q.w < Type(0) ? -1.0 : 1.0;
|
|
472
|
+
|
|
473
|
+
if (l > Type(0))
|
|
474
|
+
{
|
|
475
|
+
Type l_sq = l*l;
|
|
476
|
+
Type l_inv = Type(1) / l;
|
|
477
|
+
Type l_inv_sq = l_inv * l_inv;
|
|
478
|
+
Type l_inv_cu = l_inv_sq * l_inv;
|
|
479
|
+
|
|
480
|
+
Type C = flip * l_inv_cu;
|
|
481
|
+
ax_qx = C * (q.y*q.y + q.z*q.z);
|
|
482
|
+
ax_qy = -C * q.x*q.y;
|
|
483
|
+
ax_qz = -C * q.x*q.z;
|
|
484
|
+
ay_qx = -C * q.y*q.x;
|
|
485
|
+
ay_qy = C * (q.x*q.x + q.z*q.z);
|
|
486
|
+
ay_qz = -C * q.y*q.z;
|
|
487
|
+
az_qx = -C * q.z*q.x;
|
|
488
|
+
az_qy = -C * q.z*q.y;
|
|
489
|
+
az_qz = C * (q.x*q.x + q.y*q.y);
|
|
490
|
+
|
|
491
|
+
Type D = Type(2) * flip / (l_sq + q.w*q.w);
|
|
492
|
+
t_qx = D * l_inv * q.x * q.w;
|
|
493
|
+
t_qy = D * l_inv * q.y * q.w;
|
|
494
|
+
t_qz = D * l_inv * q.z * q.w;
|
|
495
|
+
t_qw = -D * l;
|
|
496
|
+
}
|
|
497
|
+
else
|
|
498
|
+
{
|
|
499
|
+
if (abs(q.w) > Type(kEps))
|
|
500
|
+
{
|
|
501
|
+
Type t_qx = Type(2) / (sqrt(Type(3)) * abs(q.w));
|
|
502
|
+
Type t_qy = Type(2) / (sqrt(Type(3)) * abs(q.w));
|
|
503
|
+
Type t_qz = Type(2) / (sqrt(Type(3)) * abs(q.w));
|
|
504
|
+
}
|
|
505
|
+
// o/w we have a null quat_t which cannot backpropagate
|
|
506
|
+
}
|
|
507
|
+
|
|
508
|
+
adj_q.x += ax_qx * adj_axis[0] + ay_qx * adj_axis[1] + az_qx * adj_axis[2] + t_qx * adj_angle;
|
|
509
|
+
adj_q.y += ax_qy * adj_axis[0] + ay_qy * adj_axis[1] + az_qy * adj_axis[2] + t_qy * adj_angle;
|
|
510
|
+
adj_q.z += ax_qz * adj_axis[0] + ay_qz * adj_axis[1] + az_qz * adj_axis[2] + t_qz * adj_angle;
|
|
511
|
+
adj_q.w += t_qw * adj_angle;
|
|
512
|
+
}
|
|
513
|
+
|
|
514
|
+
template<typename Type>
|
|
515
|
+
inline CUDA_CALLABLE void adj_quat_rpy(Type roll, Type pitch, Type yaw, Type& adj_roll, Type& adj_pitch, Type& adj_yaw, const quat_t<Type>& adj_ret)
|
|
516
|
+
{
|
|
517
|
+
Type cy = cos(yaw * Type(0.5));
|
|
518
|
+
Type sy = sin(yaw * Type(0.5));
|
|
519
|
+
Type cr = cos(roll * Type(0.5));
|
|
520
|
+
Type sr = sin(roll * Type(0.5));
|
|
521
|
+
Type cp = cos(pitch * Type(0.5));
|
|
522
|
+
Type sp = sin(pitch * Type(0.5));
|
|
523
|
+
|
|
524
|
+
Type w = (cy * cr * cp + sy * sr * sp);
|
|
525
|
+
Type x = (cy * sr * cp - sy * cr * sp);
|
|
526
|
+
Type y = (cy * cr * sp + sy * sr * cp);
|
|
527
|
+
Type z = (sy * cr * cp - cy * sr * sp);
|
|
528
|
+
|
|
529
|
+
Type dx_dr = Type(0.5) * w;
|
|
530
|
+
Type dx_dp = -Type(0.5) * cy * sr * sp - Type(0.5) * sy * cr * cp;
|
|
531
|
+
Type dx_dy = -Type(0.5) * y;
|
|
532
|
+
|
|
533
|
+
Type dy_dr = Type(0.5) * z;
|
|
534
|
+
Type dy_dp = Type(0.5) * cy * cr * cp - Type(0.5) * sy * sr * sp;
|
|
535
|
+
Type dy_dy = Type(0.5) * x;
|
|
536
|
+
|
|
537
|
+
Type dz_dr = -Type(0.5) * y;
|
|
538
|
+
Type dz_dp = -Type(0.5) * sy * cr * sp - Type(0.5) * cy * sr * cp;
|
|
539
|
+
Type dz_dy = Type(0.5) * w;
|
|
540
|
+
|
|
541
|
+
Type dw_dr = -Type(0.5) * x;
|
|
542
|
+
Type dw_dp = -Type(0.5) * cy * cr * sp + Type(0.5) * sy * sr * cp;
|
|
543
|
+
Type dw_dy = -Type(0.5) * z;
|
|
544
|
+
|
|
545
|
+
adj_roll += dot(quat_t<Type>(dx_dr, dy_dr, dz_dr, dw_dr), adj_ret);
|
|
546
|
+
adj_pitch += dot(quat_t<Type>(dx_dp, dy_dp, dz_dp, dw_dp), adj_ret);
|
|
547
|
+
adj_yaw += dot(quat_t<Type>(dx_dy, dy_dy, dz_dy, dw_dy), adj_ret);
|
|
548
|
+
}
|
|
549
|
+
|
|
550
|
+
|
|
551
|
+
template<typename Type>
|
|
552
|
+
inline CUDA_CALLABLE void adj_dot(const quat_t<Type>& a, const quat_t<Type>& b, quat_t<Type>& adj_a, quat_t<Type>& adj_b, const Type adj_ret)
|
|
553
|
+
{
|
|
554
|
+
adj_a += b*adj_ret;
|
|
555
|
+
adj_b += a*adj_ret;
|
|
556
|
+
}
|
|
557
|
+
|
|
558
|
+
template<typename Type>
|
|
559
|
+
inline CUDA_CALLABLE void tensordot(const quat_t<Type>& a, const quat_t<Type>& b, quat_t<Type>& adj_a, quat_t<Type>& adj_b, const Type adj_ret)
|
|
560
|
+
{
|
|
561
|
+
adj_dot(a, b, adj_a, adj_b, adj_ret);
|
|
562
|
+
}
|
|
563
|
+
|
|
564
|
+
template<typename Type>
|
|
565
|
+
inline CUDA_CALLABLE void adj_length(const quat_t<Type>& a, Type ret, quat_t<Type>& adj_a, const Type adj_ret)
|
|
566
|
+
{
|
|
567
|
+
if (ret > Type(kEps))
|
|
568
|
+
{
|
|
569
|
+
Type inv_l = Type(1)/ret;
|
|
570
|
+
|
|
571
|
+
adj_a += quat_t<Type>(a.x*inv_l, a.y*inv_l, a.z*inv_l, a.w*inv_l) * adj_ret;
|
|
572
|
+
}
|
|
573
|
+
}
|
|
574
|
+
|
|
575
|
+
template<typename Type>
|
|
576
|
+
inline CUDA_CALLABLE void adj_length_sq(const quat_t<Type>& a, quat_t<Type>& adj_a, const Type adj_ret)
|
|
577
|
+
{
|
|
578
|
+
adj_a += Type(2)*a*adj_ret;
|
|
579
|
+
}
|
|
580
|
+
|
|
581
|
+
template<typename Type>
|
|
582
|
+
inline CUDA_CALLABLE void adj_normalize(const quat_t<Type>& q, quat_t<Type>& adj_q, const quat_t<Type>& adj_ret)
|
|
583
|
+
{
|
|
584
|
+
Type l = length(q);
|
|
585
|
+
|
|
586
|
+
if (l > Type(kEps))
|
|
587
|
+
{
|
|
588
|
+
Type l_inv = Type(1)/l;
|
|
589
|
+
|
|
590
|
+
adj_q += adj_ret*l_inv - q*(l_inv*l_inv*l_inv*dot(q, adj_ret));
|
|
591
|
+
}
|
|
592
|
+
}
|
|
593
|
+
|
|
594
|
+
template<typename Type>
|
|
595
|
+
inline CUDA_CALLABLE void adj_quat_inverse(const quat_t<Type>& q, quat_t<Type>& adj_q, const quat_t<Type>& adj_ret)
|
|
596
|
+
{
|
|
597
|
+
adj_q.x -= adj_ret.x;
|
|
598
|
+
adj_q.y -= adj_ret.y;
|
|
599
|
+
adj_q.z -= adj_ret.z;
|
|
600
|
+
adj_q.w += adj_ret.w;
|
|
601
|
+
}
|
|
602
|
+
|
|
603
|
+
template<typename Type>
|
|
604
|
+
inline CUDA_CALLABLE void adj_add(const quat_t<Type>& a, const quat_t<Type>& b, quat_t<Type>& adj_a, quat_t<Type>& adj_b, const quat_t<Type>& adj_ret)
|
|
605
|
+
{
|
|
606
|
+
adj_a += adj_ret;
|
|
607
|
+
adj_b += adj_ret;
|
|
608
|
+
}
|
|
609
|
+
|
|
610
|
+
template<typename Type>
|
|
611
|
+
inline CUDA_CALLABLE void adj_sub(const quat_t<Type>& a, const quat_t<Type>& b, quat_t<Type>& adj_a, quat_t<Type>& adj_b, const quat_t<Type>& adj_ret)
|
|
612
|
+
{
|
|
613
|
+
adj_a += adj_ret;
|
|
614
|
+
adj_b -= adj_ret;
|
|
615
|
+
}
|
|
616
|
+
|
|
617
|
+
template<typename Type>
|
|
618
|
+
inline CUDA_CALLABLE void adj_mul(const quat_t<Type>& a, const quat_t<Type>& b, quat_t<Type>& adj_a, quat_t<Type>& adj_b, const quat_t<Type>& adj_ret)
|
|
619
|
+
{
|
|
620
|
+
// shorthand
|
|
621
|
+
const quat_t<Type>& r = adj_ret;
|
|
622
|
+
|
|
623
|
+
adj_a += quat_t<Type>(b.w*r.x - b.x*r.w + b.y*r.z - b.z*r.y,
|
|
624
|
+
b.w*r.y - b.y*r.w - b.x*r.z + b.z*r.x,
|
|
625
|
+
b.w*r.z + b.x*r.y - b.y*r.x - b.z*r.w,
|
|
626
|
+
b.w*r.w + b.x*r.x + b.y*r.y + b.z*r.z);
|
|
627
|
+
|
|
628
|
+
adj_b += quat_t<Type>(a.w*r.x - a.x*r.w - a.y*r.z + a.z*r.y,
|
|
629
|
+
a.w*r.y - a.y*r.w + a.x*r.z - a.z*r.x,
|
|
630
|
+
a.w*r.z - a.x*r.y + a.y*r.x - a.z*r.w,
|
|
631
|
+
a.w*r.w + a.x*r.x + a.y*r.y + a.z*r.z);
|
|
632
|
+
|
|
633
|
+
}
|
|
634
|
+
|
|
635
|
+
template<typename Type>
|
|
636
|
+
inline CUDA_CALLABLE void adj_mul(const quat_t<Type>& a, Type s, quat_t<Type>& adj_a, Type& adj_s, const quat_t<Type>& adj_ret)
|
|
637
|
+
{
|
|
638
|
+
adj_a += adj_ret*s;
|
|
639
|
+
adj_s += dot(a, adj_ret);
|
|
640
|
+
}
|
|
641
|
+
|
|
642
|
+
template<typename Type>
|
|
643
|
+
inline CUDA_CALLABLE void adj_mul(Type s, const quat_t<Type>& a, Type& adj_s, quat_t<Type>& adj_a, const quat_t<Type>& adj_ret)
|
|
644
|
+
{
|
|
645
|
+
adj_mul(a, s, adj_a, adj_s, adj_ret);
|
|
646
|
+
}
|
|
647
|
+
|
|
648
|
+
template<typename Type>
|
|
649
|
+
inline CUDA_CALLABLE void adj_div(quat_t<Type> a, Type s, quat_t<Type>& adj_a, Type& adj_s, const quat_t<Type>& adj_ret)
|
|
650
|
+
{
|
|
651
|
+
adj_s -= dot(a, adj_ret)/ (s * s); // - a / s^2
|
|
652
|
+
adj_a += adj_ret / s;
|
|
653
|
+
}
|
|
654
|
+
|
|
655
|
+
template<typename Type>
|
|
656
|
+
inline CUDA_CALLABLE void adj_div(Type s, quat_t<Type> a, Type& adj_s, quat_t<Type>& adj_a, const quat_t<Type>& adj_ret)
|
|
657
|
+
{
|
|
658
|
+
adj_s -= dot(a, adj_ret)/ (s * s); // - a / s^2
|
|
659
|
+
adj_a += s / adj_ret;
|
|
660
|
+
}
|
|
661
|
+
|
|
662
|
+
template<typename Type>
|
|
663
|
+
inline CUDA_CALLABLE void adj_quat_rotate(const quat_t<Type>& q, const vec_t<3,Type>& p, quat_t<Type>& adj_q, vec_t<3,Type>& adj_p, const vec_t<3,Type>& adj_ret)
|
|
664
|
+
{
|
|
665
|
+
|
|
666
|
+
{
|
|
667
|
+
Type t2 = p[2]*q.z*Type(2);
|
|
668
|
+
Type t3 = p[1]*q.w*Type(2);
|
|
669
|
+
Type t4 = p[0]*q.w*Type(2);
|
|
670
|
+
Type t5 = p[0]*q.x*Type(2);
|
|
671
|
+
Type t6 = p[1]*q.y*Type(2);
|
|
672
|
+
Type t7 = p[2]*q.y*Type(2);
|
|
673
|
+
Type t8 = p[0]*q.z*Type(2);
|
|
674
|
+
Type t9 = p[0]*q.y*Type(2);
|
|
675
|
+
Type t10 = p[1]*q.x*Type(2);
|
|
676
|
+
adj_q.x += adj_ret[2]*(t3+t8)+adj_ret[0]*(t2+t6+p[0]*q.x*Type(4))+adj_ret[1]*(t9-p[2]*q.w*Type(2));
|
|
677
|
+
adj_q.y += adj_ret[1]*(t2+t5+p[1]*q.y*Type(4))+adj_ret[0]*(t10+p[2]*q.w*Type(2))-adj_ret[2]*(t4-p[1]*q.z*Type(2));
|
|
678
|
+
adj_q.z += adj_ret[1]*(t4+t7)+adj_ret[2]*(t5+t6+p[2]*q.z*Type(4))-adj_ret[0]*(t3-p[2]*q.x*Type(2));
|
|
679
|
+
adj_q.w += adj_ret[0]*(t7+p[0]*q.w*Type(4)-p[1]*q.z*Type(2))+adj_ret[1]*(t8+p[1]*q.w*Type(4)-p[2]*q.x*Type(2))+adj_ret[2]*(-t9+t10+p[2]*q.w*Type(4));
|
|
680
|
+
}
|
|
681
|
+
|
|
682
|
+
{
|
|
683
|
+
Type t2 = q.w*q.w;
|
|
684
|
+
Type t3 = t2*Type(2);
|
|
685
|
+
Type t4 = q.w*q.z*Type(2);
|
|
686
|
+
Type t5 = q.x*q.y*Type(2);
|
|
687
|
+
Type t6 = q.w*q.y*Type(2);
|
|
688
|
+
Type t7 = q.w*q.x*Type(2);
|
|
689
|
+
Type t8 = q.y*q.z*Type(2);
|
|
690
|
+
adj_p[0] += adj_ret[1]*(t4+t5)+adj_ret[0]*(t3+(q.x*q.x)*Type(2)-Type(1))-adj_ret[2]*(t6-q.x*q.z*Type(2));
|
|
691
|
+
adj_p[1] += adj_ret[2]*(t7+t8)-adj_ret[0]*(t4-t5)+adj_ret[1]*(t3+(q.y*q.y)*Type(2)-Type(1));
|
|
692
|
+
adj_p[2] += -adj_ret[1]*(t7-t8)+adj_ret[2]*(t3+(q.z*q.z)*Type(2)-Type(1))+adj_ret[0]*(t6+q.x*q.z*Type(2));
|
|
693
|
+
}
|
|
694
|
+
}
|
|
695
|
+
|
|
696
|
+
template<typename Type>
|
|
697
|
+
inline CUDA_CALLABLE void adj_quat_rotate_inv(const quat_t<Type>& q, const vec_t<3,Type>& p, quat_t<Type>& adj_q, vec_t<3,Type>& adj_p, const vec_t<3,Type>& adj_ret)
|
|
698
|
+
{
|
|
699
|
+
const vec_t<3,Type>& r = adj_ret;
|
|
700
|
+
|
|
701
|
+
{
|
|
702
|
+
Type t2 = p[2]*q.w*Type(2);
|
|
703
|
+
Type t3 = p[2]*q.z*Type(2);
|
|
704
|
+
Type t4 = p[1]*q.w*Type(2);
|
|
705
|
+
Type t5 = p[0]*q.w*Type(2);
|
|
706
|
+
Type t6 = p[0]*q.x*Type(2);
|
|
707
|
+
Type t7 = p[1]*q.y*Type(2);
|
|
708
|
+
Type t8 = p[1]*q.z*Type(2);
|
|
709
|
+
Type t9 = p[2]*q.x*Type(2);
|
|
710
|
+
Type t10 = p[0]*q.y*Type(2);
|
|
711
|
+
adj_q.x += r[1]*(t2+t10)+r[0]*(t3+t7+p[0]*q.x*Type(4))-r[2]*(t4-p[0]*q.z*Type(2));
|
|
712
|
+
adj_q.y += r[2]*(t5+t8)+r[1]*(t3+t6+p[1]*q.y*Type(4))-r[0]*(t2-p[1]*q.x*Type(2));
|
|
713
|
+
adj_q.z += r[0]*(t4+t9)+r[2]*(t6+t7+p[2]*q.z*Type(4))-r[1]*(t5-p[2]*q.y*Type(2));
|
|
714
|
+
adj_q.w += r[0]*(t8+p[0]*q.w*Type(4)-p[2]*q.y*Type(2))+r[1]*(t9+p[1]*q.w*Type(4)-p[0]*q.z*Type(2))+r[2]*(t10-p[1]*q.x*Type(2)+p[2]*q.w*Type(4));
|
|
715
|
+
}
|
|
716
|
+
|
|
717
|
+
{
|
|
718
|
+
Type t2 = q.w*q.w;
|
|
719
|
+
Type t3 = t2*Type(2);
|
|
720
|
+
Type t4 = q.w*q.z*Type(2);
|
|
721
|
+
Type t5 = q.w*q.y*Type(2);
|
|
722
|
+
Type t6 = q.x*q.z*Type(2);
|
|
723
|
+
Type t7 = q.w*q.x*Type(2);
|
|
724
|
+
adj_p[0] += r[2]*(t5+t6)+r[0]*(t3+(q.x*q.x)*Type(2)-Type(1))-r[1]*(t4-q.x*q.y*Type(2));
|
|
725
|
+
adj_p[1] += r[1]*(t3+(q.y*q.y)*Type(2)-Type(1))+r[0]*(t4+q.x*q.y*Type(2))-r[2]*(t7-q.y*q.z*Type(2));
|
|
726
|
+
adj_p[2] += -r[0]*(t5-t6)+r[2]*(t3+(q.z*q.z)*Type(2)-Type(1))+r[1]*(t7+q.y*q.z*Type(2));
|
|
727
|
+
}
|
|
728
|
+
}
|
|
729
|
+
|
|
730
|
+
template<typename Type>
|
|
731
|
+
inline CUDA_CALLABLE void adj_quat_slerp(const quat_t<Type>& q0, const quat_t<Type>& q1, Type t, quat_t<Type>& ret, quat_t<Type>& adj_q0, quat_t<Type>& adj_q1, Type& adj_t, const quat_t<Type>& adj_ret)
|
|
732
|
+
{
|
|
733
|
+
vec_t<3,Type> axis;
|
|
734
|
+
Type angle;
|
|
735
|
+
quat_t<Type> q0_inv = quat_inverse(q0);
|
|
736
|
+
quat_t<Type> q_inc = mul(q0_inv, q1);
|
|
737
|
+
quat_to_axis_angle(q_inc, axis, angle);
|
|
738
|
+
quat_t<Type> qt = quat_from_axis_angle(axis, angle * t);
|
|
739
|
+
angle = angle * 0.5;
|
|
740
|
+
|
|
741
|
+
// adj_t
|
|
742
|
+
adj_t += dot(mul(ret, quat_t<Type>(angle*axis[0], angle*axis[1], angle*axis[2], Type(0))), adj_ret);
|
|
743
|
+
|
|
744
|
+
// adj_q0
|
|
745
|
+
quat_t<Type> q_inc_x_q0;
|
|
746
|
+
quat_t<Type> q_inc_y_q0;
|
|
747
|
+
quat_t<Type> q_inc_z_q0;
|
|
748
|
+
quat_t<Type> q_inc_w_q0;
|
|
749
|
+
|
|
750
|
+
quat_t<Type> q_inc_x_q1;
|
|
751
|
+
quat_t<Type> q_inc_y_q1;
|
|
752
|
+
quat_t<Type> q_inc_z_q1;
|
|
753
|
+
quat_t<Type> q_inc_w_q1;
|
|
754
|
+
|
|
755
|
+
adj_mul(q0_inv, q1, q_inc_x_q0, q_inc_x_q1, quat_t<Type>(1.f, Type(0), Type(0), Type(0)));
|
|
756
|
+
adj_mul(q0_inv, q1, q_inc_y_q0, q_inc_y_q1, quat_t<Type>(Type(0), 1.f, Type(0), Type(0)));
|
|
757
|
+
adj_mul(q0_inv, q1, q_inc_z_q0, q_inc_z_q1, quat_t<Type>(Type(0), Type(0), 1.f, Type(0)));
|
|
758
|
+
adj_mul(q0_inv, q1, q_inc_w_q0, q_inc_w_q1, quat_t<Type>(Type(0), Type(0), Type(0), 1.f));
|
|
759
|
+
|
|
760
|
+
quat_t<Type> a_x_q_inc;
|
|
761
|
+
quat_t<Type> a_y_q_inc;
|
|
762
|
+
quat_t<Type> a_z_q_inc;
|
|
763
|
+
quat_t<Type> t_q_inc;
|
|
764
|
+
|
|
765
|
+
adj_quat_to_axis_angle(q_inc, axis, angle, a_x_q_inc, vec_t<3,Type>(1.f, Type(0), Type(0)), Type(0));
|
|
766
|
+
adj_quat_to_axis_angle(q_inc, axis, angle, a_y_q_inc, vec_t<3,Type>(Type(0), 1.f, Type(0)), Type(0));
|
|
767
|
+
adj_quat_to_axis_angle(q_inc, axis, angle, a_z_q_inc, vec_t<3,Type>(Type(0), Type(0), 1.f), Type(0));
|
|
768
|
+
adj_quat_to_axis_angle(q_inc, axis, angle, t_q_inc, vec_t<3,Type>(Type(0), Type(0), Type(0)), Type(1));
|
|
769
|
+
|
|
770
|
+
Type cs = cos(angle*t);
|
|
771
|
+
Type sn = sin(angle*t);
|
|
772
|
+
|
|
773
|
+
quat_t<Type> q_inc_q0_x = quat_t<Type>(-q_inc_x_q0.x, -q_inc_y_q0.x, -q_inc_z_q0.x, -q_inc_w_q0.x);
|
|
774
|
+
quat_t<Type> q_inc_q0_y = quat_t<Type>(-q_inc_x_q0.y, -q_inc_y_q0.y, -q_inc_z_q0.y, -q_inc_w_q0.y);
|
|
775
|
+
quat_t<Type> q_inc_q0_z = quat_t<Type>(-q_inc_x_q0.z, -q_inc_y_q0.z, -q_inc_z_q0.z, -q_inc_w_q0.z);
|
|
776
|
+
quat_t<Type> q_inc_q0_w = quat_t<Type>(q_inc_x_q0.w, q_inc_y_q0.w, q_inc_z_q0.w, q_inc_w_q0.w);
|
|
777
|
+
|
|
778
|
+
Type a_x_q0_x = dot(a_x_q_inc, q_inc_q0_x);
|
|
779
|
+
Type a_x_q0_y = dot(a_x_q_inc, q_inc_q0_y);
|
|
780
|
+
Type a_x_q0_z = dot(a_x_q_inc, q_inc_q0_z);
|
|
781
|
+
Type a_x_q0_w = dot(a_x_q_inc, q_inc_q0_w);
|
|
782
|
+
Type a_y_q0_x = dot(a_y_q_inc, q_inc_q0_x);
|
|
783
|
+
Type a_y_q0_y = dot(a_y_q_inc, q_inc_q0_y);
|
|
784
|
+
Type a_y_q0_z = dot(a_y_q_inc, q_inc_q0_z);
|
|
785
|
+
Type a_y_q0_w = dot(a_y_q_inc, q_inc_q0_w);
|
|
786
|
+
Type a_z_q0_x = dot(a_z_q_inc, q_inc_q0_x);
|
|
787
|
+
Type a_z_q0_y = dot(a_z_q_inc, q_inc_q0_y);
|
|
788
|
+
Type a_z_q0_z = dot(a_z_q_inc, q_inc_q0_z);
|
|
789
|
+
Type a_z_q0_w = dot(a_z_q_inc, q_inc_q0_w);
|
|
790
|
+
Type t_q0_x = dot(t_q_inc, q_inc_q0_x);
|
|
791
|
+
Type t_q0_y = dot(t_q_inc, q_inc_q0_y);
|
|
792
|
+
Type t_q0_z = dot(t_q_inc, q_inc_q0_z);
|
|
793
|
+
Type t_q0_w = dot(t_q_inc, q_inc_q0_w);
|
|
794
|
+
|
|
795
|
+
quat_t<Type> q_s_q0_x = mul(quat_t<Type>(1.f, Type(0), Type(0), Type(0)), qt) + mul(q0, quat_t<Type>(
|
|
796
|
+
0.5 * t * axis[0] * t_q0_x * cs + a_x_q0_x * sn,
|
|
797
|
+
0.5 * t * axis[1] * t_q0_x * cs + a_y_q0_x * sn,
|
|
798
|
+
0.5 * t * axis[2] * t_q0_x * cs + a_z_q0_x * sn,
|
|
799
|
+
-0.5 * t * t_q0_x * sn));
|
|
800
|
+
|
|
801
|
+
quat_t<Type> q_s_q0_y = mul(quat_t<Type>(Type(0), 1.f, Type(0), Type(0)), qt) + mul(q0, quat_t<Type>(
|
|
802
|
+
0.5 * t * axis[0] * t_q0_y * cs + a_x_q0_y * sn,
|
|
803
|
+
0.5 * t * axis[1] * t_q0_y * cs + a_y_q0_y * sn,
|
|
804
|
+
0.5 * t * axis[2] * t_q0_y * cs + a_z_q0_y * sn,
|
|
805
|
+
-0.5 * t * t_q0_y * sn));
|
|
806
|
+
|
|
807
|
+
quat_t<Type> q_s_q0_z = mul(quat_t<Type>(Type(0), Type(0), 1.f, Type(0)), qt) + mul(q0, quat_t<Type>(
|
|
808
|
+
0.5 * t * axis[0] * t_q0_z * cs + a_x_q0_z * sn,
|
|
809
|
+
0.5 * t * axis[1] * t_q0_z * cs + a_y_q0_z * sn,
|
|
810
|
+
0.5 * t * axis[2] * t_q0_z * cs + a_z_q0_z * sn,
|
|
811
|
+
-0.5 * t * t_q0_z * sn));
|
|
812
|
+
|
|
813
|
+
quat_t<Type> q_s_q0_w = mul(quat_t<Type>(Type(0), Type(0), Type(0), 1.f), qt) + mul(q0, quat_t<Type>(
|
|
814
|
+
0.5 * t * axis[0] * t_q0_w * cs + a_x_q0_w * sn,
|
|
815
|
+
0.5 * t * axis[1] * t_q0_w * cs + a_y_q0_w * sn,
|
|
816
|
+
0.5 * t * axis[2] * t_q0_w * cs + a_z_q0_w * sn,
|
|
817
|
+
-0.5 * t * t_q0_w * sn));
|
|
818
|
+
|
|
819
|
+
adj_q0.x += dot(q_s_q0_x, adj_ret);
|
|
820
|
+
adj_q0.y += dot(q_s_q0_y, adj_ret);
|
|
821
|
+
adj_q0.z += dot(q_s_q0_z, adj_ret);
|
|
822
|
+
adj_q0.w += dot(q_s_q0_w, adj_ret);
|
|
823
|
+
|
|
824
|
+
// adj_q1
|
|
825
|
+
quat_t<Type> q_inc_q1_x = quat_t<Type>(q_inc_x_q1.x, q_inc_y_q1.x, q_inc_z_q1.x, q_inc_w_q1.x);
|
|
826
|
+
quat_t<Type> q_inc_q1_y = quat_t<Type>(q_inc_x_q1.y, q_inc_y_q1.y, q_inc_z_q1.y, q_inc_w_q1.y);
|
|
827
|
+
quat_t<Type> q_inc_q1_z = quat_t<Type>(q_inc_x_q1.z, q_inc_y_q1.z, q_inc_z_q1.z, q_inc_w_q1.z);
|
|
828
|
+
quat_t<Type> q_inc_q1_w = quat_t<Type>(q_inc_x_q1.w, q_inc_y_q1.w, q_inc_z_q1.w, q_inc_w_q1.w);
|
|
829
|
+
|
|
830
|
+
Type a_x_q1_x = dot(a_x_q_inc, q_inc_q1_x);
|
|
831
|
+
Type a_x_q1_y = dot(a_x_q_inc, q_inc_q1_y);
|
|
832
|
+
Type a_x_q1_z = dot(a_x_q_inc, q_inc_q1_z);
|
|
833
|
+
Type a_x_q1_w = dot(a_x_q_inc, q_inc_q1_w);
|
|
834
|
+
Type a_y_q1_x = dot(a_y_q_inc, q_inc_q1_x);
|
|
835
|
+
Type a_y_q1_y = dot(a_y_q_inc, q_inc_q1_y);
|
|
836
|
+
Type a_y_q1_z = dot(a_y_q_inc, q_inc_q1_z);
|
|
837
|
+
Type a_y_q1_w = dot(a_y_q_inc, q_inc_q1_w);
|
|
838
|
+
Type a_z_q1_x = dot(a_z_q_inc, q_inc_q1_x);
|
|
839
|
+
Type a_z_q1_y = dot(a_z_q_inc, q_inc_q1_y);
|
|
840
|
+
Type a_z_q1_z = dot(a_z_q_inc, q_inc_q1_z);
|
|
841
|
+
Type a_z_q1_w = dot(a_z_q_inc, q_inc_q1_w);
|
|
842
|
+
Type t_q1_x = dot(t_q_inc, q_inc_q1_x);
|
|
843
|
+
Type t_q1_y = dot(t_q_inc, q_inc_q1_y);
|
|
844
|
+
Type t_q1_z = dot(t_q_inc, q_inc_q1_z);
|
|
845
|
+
Type t_q1_w = dot(t_q_inc, q_inc_q1_w);
|
|
846
|
+
|
|
847
|
+
quat_t<Type> q_s_q1_x = mul(q0, quat_t<Type>(
|
|
848
|
+
0.5 * t * axis[0] * t_q1_x * cs + a_x_q1_x * sn,
|
|
849
|
+
0.5 * t * axis[1] * t_q1_x * cs + a_y_q1_x * sn,
|
|
850
|
+
0.5 * t * axis[2] * t_q1_x * cs + a_z_q1_x * sn,
|
|
851
|
+
-0.5 * t * t_q1_x * sn));
|
|
852
|
+
|
|
853
|
+
quat_t<Type> q_s_q1_y = mul(q0, quat_t<Type>(
|
|
854
|
+
0.5 * t * axis[0] * t_q1_y * cs + a_x_q1_y * sn,
|
|
855
|
+
0.5 * t * axis[1] * t_q1_y * cs + a_y_q1_y * sn,
|
|
856
|
+
0.5 * t * axis[2] * t_q1_y * cs + a_z_q1_y * sn,
|
|
857
|
+
-0.5 * t * t_q1_y * sn));
|
|
858
|
+
|
|
859
|
+
quat_t<Type> q_s_q1_z = mul(q0, quat_t<Type>(
|
|
860
|
+
0.5 * t * axis[0] * t_q1_z * cs + a_x_q1_z * sn,
|
|
861
|
+
0.5 * t * axis[1] * t_q1_z * cs + a_y_q1_z * sn,
|
|
862
|
+
0.5 * t * axis[2] * t_q1_z * cs + a_z_q1_z * sn,
|
|
863
|
+
-0.5 * t * t_q1_z * sn));
|
|
864
|
+
|
|
865
|
+
quat_t<Type> q_s_q1_w = mul(q0, quat_t<Type>(
|
|
866
|
+
0.5 * t * axis[0] * t_q1_w * cs + a_x_q1_w * sn,
|
|
867
|
+
0.5 * t * axis[1] * t_q1_w * cs + a_y_q1_w * sn,
|
|
868
|
+
0.5 * t * axis[2] * t_q1_w * cs + a_z_q1_w * sn,
|
|
869
|
+
-0.5 * t * t_q1_w * sn));
|
|
870
|
+
|
|
871
|
+
adj_q1.x += dot(q_s_q1_x, adj_ret);
|
|
872
|
+
adj_q1.y += dot(q_s_q1_y, adj_ret);
|
|
873
|
+
adj_q1.z += dot(q_s_q1_z, adj_ret);
|
|
874
|
+
adj_q1.w += dot(q_s_q1_w, adj_ret);
|
|
875
|
+
|
|
876
|
+
}
|
|
877
|
+
|
|
878
|
+
template<typename Type>
|
|
879
|
+
inline CUDA_CALLABLE void adj_quat_to_matrix(const quat_t<Type>& q, quat_t<Type>& adj_q, mat_t<3,3,Type>& adj_ret)
|
|
880
|
+
{
|
|
881
|
+
// we don't care about adjoint w.r.t. constant identity matrix
|
|
882
|
+
vec_t<3,Type> t;
|
|
883
|
+
|
|
884
|
+
adj_quat_rotate(q, vec_t<3,Type>(1.0, 0.0, 0.0), adj_q, t, adj_ret.get_col(0));
|
|
885
|
+
adj_quat_rotate(q, vec_t<3,Type>(0.0, 1.0, 0.0), adj_q, t, adj_ret.get_col(1));
|
|
886
|
+
adj_quat_rotate(q, vec_t<3,Type>(0.0, 0.0, 1.0), adj_q, t, adj_ret.get_col(2));
|
|
887
|
+
}
|
|
888
|
+
|
|
889
|
+
template<typename Type>
|
|
890
|
+
inline CUDA_CALLABLE void adj_quat_from_matrix(const mat_t<3,3,Type>& m, mat_t<3,3,Type>& adj_m, const quat_t<Type>& adj_ret)
|
|
891
|
+
{
|
|
892
|
+
const Type tr = m.data[0][0] + m.data[1][1] + m.data[2][2];
|
|
893
|
+
Type x, y, z, w, h = Type(0);
|
|
894
|
+
|
|
895
|
+
Type dx_dm00 = Type(0), dx_dm01 = Type(0), dx_dm02 = Type(0);
|
|
896
|
+
Type dx_dm10 = Type(0), dx_dm11 = Type(0), dx_dm12 = Type(0);
|
|
897
|
+
Type dx_dm20 = Type(0), dx_dm21 = Type(0), dx_dm22 = Type(0);
|
|
898
|
+
Type dy_dm00 = Type(0), dy_dm01 = Type(0), dy_dm02 = Type(0);
|
|
899
|
+
Type dy_dm10 = Type(0), dy_dm11 = Type(0), dy_dm12 = Type(0);
|
|
900
|
+
Type dy_dm20 = Type(0), dy_dm21 = Type(0), dy_dm22 = Type(0);
|
|
901
|
+
Type dz_dm00 = Type(0), dz_dm01 = Type(0), dz_dm02 = Type(0);
|
|
902
|
+
Type dz_dm10 = Type(0), dz_dm11 = Type(0), dz_dm12 = Type(0);
|
|
903
|
+
Type dz_dm20 = Type(0), dz_dm21 = Type(0), dz_dm22 = Type(0);
|
|
904
|
+
Type dw_dm00 = Type(0), dw_dm01 = Type(0), dw_dm02 = Type(0);
|
|
905
|
+
Type dw_dm10 = Type(0), dw_dm11 = Type(0), dw_dm12 = Type(0);
|
|
906
|
+
Type dw_dm20 = Type(0), dw_dm21 = Type(0), dw_dm22 = Type(0);
|
|
907
|
+
|
|
908
|
+
if (tr >= Type(0)) {
|
|
909
|
+
h = sqrt(tr + Type(1));
|
|
910
|
+
w = Type(0.5) * h;
|
|
911
|
+
h = Type(0.5) / h;
|
|
912
|
+
|
|
913
|
+
x = (m.data[2][1] - m.data[1][2]) * h;
|
|
914
|
+
y = (m.data[0][2] - m.data[2][0]) * h;
|
|
915
|
+
z = (m.data[1][0] - m.data[0][1]) * h;
|
|
916
|
+
|
|
917
|
+
dw_dm00 = Type(0.5) * h;
|
|
918
|
+
dw_dm11 = Type(0.5) * h;
|
|
919
|
+
dw_dm22 = Type(0.5) * h;
|
|
920
|
+
dx_dm21 = h;
|
|
921
|
+
dx_dm12 = -h;
|
|
922
|
+
dx_dm00 = Type(2) * h*h*h * (m.data[1][2] - m.data[2][1]);
|
|
923
|
+
dx_dm11 = Type(2) * h*h*h * (m.data[1][2] - m.data[2][1]);
|
|
924
|
+
dx_dm22 = Type(2) * h*h*h * (m.data[1][2] - m.data[2][1]);
|
|
925
|
+
dy_dm02 = h;
|
|
926
|
+
dy_dm20 = -h;
|
|
927
|
+
dy_dm00 = Type(2) * h*h*h * (m.data[2][0] - m.data[0][2]);
|
|
928
|
+
dy_dm11 = Type(2) * h*h*h * (m.data[2][0] - m.data[0][2]);
|
|
929
|
+
dy_dm22 = Type(2) * h*h*h * (m.data[2][0] - m.data[0][2]);
|
|
930
|
+
dz_dm10 = h;
|
|
931
|
+
dz_dm01 = -h;
|
|
932
|
+
dz_dm00 = Type(2) * h*h*h * (m.data[0][1] - m.data[1][0]);
|
|
933
|
+
dz_dm11 = Type(2) * h*h*h * (m.data[0][1] - m.data[1][0]);
|
|
934
|
+
dz_dm22 = Type(2) * h*h*h * (m.data[0][1] - m.data[1][0]);
|
|
935
|
+
} else {
|
|
936
|
+
size_t max_diag = 0;
|
|
937
|
+
if (m.data[1][1] > m.data[0][0]) {
|
|
938
|
+
max_diag = 1;
|
|
939
|
+
}
|
|
940
|
+
if (m.data[2][2] > m.data[max_diag][max_diag]) {
|
|
941
|
+
max_diag = 2;
|
|
942
|
+
}
|
|
943
|
+
|
|
944
|
+
if (max_diag == 0) {
|
|
945
|
+
h = sqrt((m.data[0][0] - (m.data[1][1] + m.data[2][2])) + Type(1));
|
|
946
|
+
x = Type(0.5) * h;
|
|
947
|
+
h = Type(0.5) / h;
|
|
948
|
+
|
|
949
|
+
y = (m.data[0][1] + m.data[1][0]) * h;
|
|
950
|
+
z = (m.data[2][0] + m.data[0][2]) * h;
|
|
951
|
+
w = (m.data[2][1] - m.data[1][2]) * h;
|
|
952
|
+
|
|
953
|
+
dx_dm00 = Type(0.5) * h;
|
|
954
|
+
dx_dm11 = -Type(0.5) * h;
|
|
955
|
+
dx_dm22 = -Type(0.5) * h;
|
|
956
|
+
dy_dm01 = h;
|
|
957
|
+
dy_dm10 = h;
|
|
958
|
+
dy_dm00 = -Type(2) * h*h*h * (m.data[0][1] + m.data[1][0]);
|
|
959
|
+
dy_dm11 = Type(2) * h*h*h * (m.data[0][1] + m.data[1][0]);
|
|
960
|
+
dy_dm22 = Type(2) * h*h*h * (m.data[0][1] + m.data[1][0]);
|
|
961
|
+
dz_dm20 = h;
|
|
962
|
+
dz_dm02 = h;
|
|
963
|
+
dz_dm00 = -Type(2) * h*h*h * (m.data[2][0] + m.data[0][2]);
|
|
964
|
+
dz_dm11 = Type(2) * h*h*h * (m.data[2][0] + m.data[0][2]);
|
|
965
|
+
dz_dm22 = Type(2) * h*h*h * (m.data[2][0] + m.data[0][2]);
|
|
966
|
+
dw_dm21 = h;
|
|
967
|
+
dw_dm12 = -h;
|
|
968
|
+
dw_dm00 = Type(2) * h*h*h * (m.data[1][2] - m.data[2][1]);
|
|
969
|
+
dw_dm11 = Type(2) * h*h*h * (m.data[2][1] - m.data[1][2]);
|
|
970
|
+
dw_dm22 = Type(2) * h*h*h * (m.data[2][1] - m.data[1][2]);
|
|
971
|
+
} else if (max_diag == 1) {
|
|
972
|
+
h = sqrt((m.data[1][1] - (m.data[2][2] + m.data[0][0])) + Type(1));
|
|
973
|
+
y = Type(0.5) * h;
|
|
974
|
+
h = Type(0.5) / h;
|
|
975
|
+
|
|
976
|
+
z = (m.data[1][2] + m.data[2][1]) * h;
|
|
977
|
+
x = (m.data[0][1] + m.data[1][0]) * h;
|
|
978
|
+
w = (m.data[0][2] - m.data[2][0]) * h;
|
|
979
|
+
|
|
980
|
+
dy_dm00 = -Type(0.5) * h;
|
|
981
|
+
dy_dm11 = Type(0.5) * h;
|
|
982
|
+
dy_dm22 = -Type(0.5) * h;
|
|
983
|
+
dz_dm12 = h;
|
|
984
|
+
dz_dm21 = h;
|
|
985
|
+
dz_dm00 = Type(2) * h*h*h * (m.data[1][2] + m.data[2][1]);
|
|
986
|
+
dz_dm11 = -Type(2) * h*h*h * (m.data[1][2] + m.data[2][1]);
|
|
987
|
+
dz_dm22 = Type(2) * h*h*h * (m.data[1][2] + m.data[2][1]);
|
|
988
|
+
dx_dm01 = h;
|
|
989
|
+
dx_dm10 = h;
|
|
990
|
+
dx_dm00 = Type(2) * h*h*h * (m.data[0][1] + m.data[1][0]);
|
|
991
|
+
dx_dm11 = -Type(2) * h*h*h * (m.data[0][1] + m.data[1][0]);
|
|
992
|
+
dx_dm22 = Type(2) * h*h*h * (m.data[0][1] + m.data[1][0]);
|
|
993
|
+
dw_dm02 = h;
|
|
994
|
+
dw_dm20 = -h;
|
|
995
|
+
dw_dm00 = Type(2) * h*h*h * (m.data[0][2] - m.data[2][0]);
|
|
996
|
+
dw_dm11 = Type(2) * h*h*h * (m.data[2][0] - m.data[0][2]);
|
|
997
|
+
dw_dm22 = Type(2) * h*h*h * (m.data[0][2] - m.data[2][0]);
|
|
998
|
+
} if (max_diag == 2) {
|
|
999
|
+
h = sqrt((m.data[2][2] - (m.data[0][0] + m.data[1][1])) + Type(1));
|
|
1000
|
+
z = Type(0.5) * h;
|
|
1001
|
+
h = Type(0.5) / h;
|
|
1002
|
+
|
|
1003
|
+
x = (m.data[2][0] + m.data[0][2]) * h;
|
|
1004
|
+
y = (m.data[1][2] + m.data[2][1]) * h;
|
|
1005
|
+
w = (m.data[1][0] - m.data[0][1]) * h;
|
|
1006
|
+
|
|
1007
|
+
dz_dm00 = -Type(0.5) * h;
|
|
1008
|
+
dz_dm11 = -Type(0.5) * h;
|
|
1009
|
+
dz_dm22 = Type(0.5) * h;
|
|
1010
|
+
dx_dm20 = h;
|
|
1011
|
+
dx_dm02 = h;
|
|
1012
|
+
dx_dm00 = Type(2) * h*h*h * (m.data[2][0] + m.data[0][2]);
|
|
1013
|
+
dx_dm11 = Type(2) * h*h*h * (m.data[2][0] + m.data[0][2]);
|
|
1014
|
+
dx_dm22 = -Type(2) * h*h*h * (m.data[2][0] + m.data[0][2]);
|
|
1015
|
+
dy_dm12 = h;
|
|
1016
|
+
dy_dm21 = h;
|
|
1017
|
+
dy_dm00 = Type(2) * h*h*h * (m.data[1][2] + m.data[2][1]);
|
|
1018
|
+
dy_dm11 = Type(2) * h*h*h * (m.data[1][2] + m.data[2][1]);
|
|
1019
|
+
dy_dm22 = -Type(2) * h*h*h * (m.data[1][2] + m.data[2][1]);
|
|
1020
|
+
dw_dm10 = h;
|
|
1021
|
+
dw_dm01 = -h;
|
|
1022
|
+
dw_dm00 = Type(2) * h*h*h * (m.data[1][0] - m.data[0][1]);
|
|
1023
|
+
dw_dm11 = Type(2) * h*h*h * (m.data[1][0] - m.data[0][1]);
|
|
1024
|
+
dw_dm22 = Type(2) * h*h*h * (m.data[0][1] - m.data[1][0]);
|
|
1025
|
+
}
|
|
1026
|
+
}
|
|
1027
|
+
|
|
1028
|
+
quat_t<Type> dq_dm00 = quat_t<Type>(dx_dm00, dy_dm00, dz_dm00, dw_dm00);
|
|
1029
|
+
quat_t<Type> dq_dm01 = quat_t<Type>(dx_dm01, dy_dm01, dz_dm01, dw_dm01);
|
|
1030
|
+
quat_t<Type> dq_dm02 = quat_t<Type>(dx_dm02, dy_dm02, dz_dm02, dw_dm02);
|
|
1031
|
+
quat_t<Type> dq_dm10 = quat_t<Type>(dx_dm10, dy_dm10, dz_dm10, dw_dm10);
|
|
1032
|
+
quat_t<Type> dq_dm11 = quat_t<Type>(dx_dm11, dy_dm11, dz_dm11, dw_dm11);
|
|
1033
|
+
quat_t<Type> dq_dm12 = quat_t<Type>(dx_dm12, dy_dm12, dz_dm12, dw_dm12);
|
|
1034
|
+
quat_t<Type> dq_dm20 = quat_t<Type>(dx_dm20, dy_dm20, dz_dm20, dw_dm20);
|
|
1035
|
+
quat_t<Type> dq_dm21 = quat_t<Type>(dx_dm21, dy_dm21, dz_dm21, dw_dm21);
|
|
1036
|
+
quat_t<Type> dq_dm22 = quat_t<Type>(dx_dm22, dy_dm22, dz_dm22, dw_dm22);
|
|
1037
|
+
|
|
1038
|
+
quat_t<Type> adj_q;
|
|
1039
|
+
adj_normalize(quat_t<Type>(x, y, z, w), adj_q, adj_ret);
|
|
1040
|
+
|
|
1041
|
+
adj_m.data[0][0] += dot(dq_dm00, adj_q);
|
|
1042
|
+
adj_m.data[0][1] += dot(dq_dm01, adj_q);
|
|
1043
|
+
adj_m.data[0][2] += dot(dq_dm02, adj_q);
|
|
1044
|
+
adj_m.data[1][0] += dot(dq_dm10, adj_q);
|
|
1045
|
+
adj_m.data[1][1] += dot(dq_dm11, adj_q);
|
|
1046
|
+
adj_m.data[1][2] += dot(dq_dm12, adj_q);
|
|
1047
|
+
adj_m.data[2][0] += dot(dq_dm20, adj_q);
|
|
1048
|
+
adj_m.data[2][1] += dot(dq_dm21, adj_q);
|
|
1049
|
+
adj_m.data[2][2] += dot(dq_dm22, adj_q);
|
|
1050
|
+
}
|
|
1051
|
+
|
|
1052
|
+
template<typename Type>
|
|
1053
|
+
inline CUDA_CALLABLE void adj_mat_t(const vec_t<3,Type>& pos, const quat_t<Type>& rot, const vec_t<3,Type>& scale,
|
|
1054
|
+
vec_t<3,Type>& adj_pos, quat_t<Type>& adj_rot, vec_t<3,Type>& adj_scale, const mat_t<4,4,Type>& adj_ret)
|
|
1055
|
+
{
|
|
1056
|
+
mat_t<3,3,Type> R = quat_to_matrix(rot);
|
|
1057
|
+
mat_t<3,3,Type> adj_R(0);
|
|
1058
|
+
|
|
1059
|
+
adj_pos[0] += adj_ret.data[0][3];
|
|
1060
|
+
adj_pos[1] += adj_ret.data[1][3];
|
|
1061
|
+
adj_pos[2] += adj_ret.data[2][3];
|
|
1062
|
+
|
|
1063
|
+
adj_mul(R.data[0][0], scale[0], adj_R.data[0][0], adj_scale[0], adj_ret.data[0][0]);
|
|
1064
|
+
adj_mul(R.data[1][0], scale[0], adj_R.data[1][0], adj_scale[0], adj_ret.data[1][0]);
|
|
1065
|
+
adj_mul(R.data[2][0], scale[0], adj_R.data[2][0], adj_scale[0], adj_ret.data[2][0]);
|
|
1066
|
+
|
|
1067
|
+
adj_mul(R.data[0][1], scale[1], adj_R.data[0][1], adj_scale[1], adj_ret.data[0][1]);
|
|
1068
|
+
adj_mul(R.data[1][1], scale[1], adj_R.data[1][1], adj_scale[1], adj_ret.data[1][1]);
|
|
1069
|
+
adj_mul(R.data[2][1], scale[1], adj_R.data[2][1], adj_scale[1], adj_ret.data[2][1]);
|
|
1070
|
+
|
|
1071
|
+
adj_mul(R.data[0][2], scale[2], adj_R.data[0][2], adj_scale[2], adj_ret.data[0][2]);
|
|
1072
|
+
adj_mul(R.data[1][2], scale[2], adj_R.data[1][2], adj_scale[2], adj_ret.data[1][2]);
|
|
1073
|
+
adj_mul(R.data[2][2], scale[2], adj_R.data[2][2], adj_scale[2], adj_ret.data[2][2]);
|
|
1074
|
+
|
|
1075
|
+
adj_quat_to_matrix(rot, adj_rot, adj_R);
|
|
1076
|
+
}
|
|
1077
|
+
|
|
1078
|
+
template<unsigned Rows, unsigned Cols, typename Type>
|
|
1079
|
+
inline CUDA_CALLABLE mat_t<Rows,Cols,Type>::mat_t(const vec_t<3,Type>& pos, const quat_t<Type>& rot, const vec_t<3,Type>& scale)
|
|
1080
|
+
{
|
|
1081
|
+
mat_t<3,3,Type> R = quat_to_matrix(rot);
|
|
1082
|
+
|
|
1083
|
+
data[0][0] = R.data[0][0]*scale[0];
|
|
1084
|
+
data[1][0] = R.data[1][0]*scale[0];
|
|
1085
|
+
data[2][0] = R.data[2][0]*scale[0];
|
|
1086
|
+
data[3][0] = Type(0);
|
|
1087
|
+
|
|
1088
|
+
data[0][1] = R.data[0][1]*scale[1];
|
|
1089
|
+
data[1][1] = R.data[1][1]*scale[1];
|
|
1090
|
+
data[2][1] = R.data[2][1]*scale[1];
|
|
1091
|
+
data[3][1] = Type(0);
|
|
1092
|
+
|
|
1093
|
+
data[0][2] = R.data[0][2]*scale[2];
|
|
1094
|
+
data[1][2] = R.data[1][2]*scale[2];
|
|
1095
|
+
data[2][2] = R.data[2][2]*scale[2];
|
|
1096
|
+
data[3][2] = Type(0);
|
|
1097
|
+
|
|
1098
|
+
data[0][3] = pos[0];
|
|
1099
|
+
data[1][3] = pos[1];
|
|
1100
|
+
data[2][3] = pos[2];
|
|
1101
|
+
data[3][3] = Type(1);
|
|
1102
|
+
}
|
|
1103
|
+
|
|
1104
|
+
template<typename Type=float32>
|
|
1105
|
+
inline CUDA_CALLABLE quat_t<Type> quat_identity()
|
|
1106
|
+
{
|
|
1107
|
+
return quat_t<Type>(Type(0), Type(0), Type(0), Type(1));
|
|
1108
|
+
}
|
|
1109
|
+
|
|
1110
|
+
|
|
1111
|
+
|
|
1112
|
+
} // namespace wp
|