35 #define DISPATCH_ROBUST_KERNEL_FUNCTION(METHOD, scalar_t, scaling_parameter, \
36 shape_parameter, ...) \
38 scalar_t scale = static_cast<scalar_t>(scaling_parameter); \
39 if (METHOD == RobustKernelMethod::L2Loss) { \
40 auto GetWeightFromRobustKernel = \
41 [=] OPEN3D_HOST_DEVICE(scalar_t residual) -> scalar_t { \
44 return __VA_ARGS__(); \
45 } else if (METHOD == RobustKernelMethod::L1Loss) { \
46 auto GetWeightFromRobustKernel = \
47 [=] OPEN3D_HOST_DEVICE(scalar_t residual) -> scalar_t { \
48 return 1.0 / abs(residual); \
50 return __VA_ARGS__(); \
51 } else if (METHOD == RobustKernelMethod::HuberLoss) { \
52 auto GetWeightFromRobustKernel = \
53 [=] OPEN3D_HOST_DEVICE(scalar_t residual) -> scalar_t { \
54 return scale / max(abs(residual), scale); \
56 return __VA_ARGS__(); \
57 } else if (METHOD == RobustKernelMethod::CauchyLoss) { \
58 auto GetWeightFromRobustKernel = \
59 [=] OPEN3D_HOST_DEVICE(scalar_t residual) -> scalar_t { \
60 return 1.0 / (1.0 + Square(residual / scale)); \
62 return __VA_ARGS__(); \
63 } else if (METHOD == RobustKernelMethod::GMLoss) { \
64 auto GetWeightFromRobustKernel = \
65 [=] OPEN3D_HOST_DEVICE(scalar_t residual) -> scalar_t { \
66 return scale / Square(scale + Square(residual)); \
68 return __VA_ARGS__(); \
69 } else if (METHOD == RobustKernelMethod::TukeyLoss) { \
70 auto GetWeightFromRobustKernel = \
71 [=] OPEN3D_HOST_DEVICE(scalar_t residual) -> scalar_t { \
72 return Square(1.0 - Square(min((scalar_t)1.0, \
73 abs(residual) / scale))); \
75 return __VA_ARGS__(); \
76 } else if (METHOD == RobustKernelMethod::GeneralizedLoss) { \
77 if (open3d::IsClose(shape_parameter, 2.0, 1e-3)) { \
78 auto const_val = 1.0 / Square(scale); \
79 auto GetWeightFromRobustKernel = \
80 [=] OPEN3D_HOST_DEVICE( \
81 scalar_t residual) -> scalar_t { \
84 return __VA_ARGS__(); \
85 } else if (open3d::IsClose(shape_parameter, 0.0, 1e-3)) { \
86 auto GetWeightFromRobustKernel = \
87 [=] OPEN3D_HOST_DEVICE( \
88 scalar_t residual) -> scalar_t { \
89 return 2.0 / (Square(residual) + 2 * Square(scale)); \
91 return __VA_ARGS__(); \
92 } else if (shape_parameter < -1e7) { \
93 auto GetWeightFromRobustKernel = \
94 [=] OPEN3D_HOST_DEVICE( \
95 scalar_t residual) -> scalar_t { \
96 return exp(Square(residual / scale) / (-2.0)) / \
99 return __VA_ARGS__(); \
101 auto GetWeightFromRobustKernel = \
102 [=] OPEN3D_HOST_DEVICE( \
103 scalar_t residual) -> scalar_t { \
104 return pow((Square(residual / scale) / \
105 abs(shape_parameter - 2.0) + \
107 ((shape_parameter / 2.0) - 1.0)) / \
110 return __VA_ARGS__(); \
113 utility::LogError("Unsupported method."); \
122 #define DISPATCH_DUAL_ROBUST_KERNEL_FUNCTION(scalar_t, METHOD_1, \
123 scaling_parameter_1, METHOD_2, \
124 scaling_parameter_2, ...) \
126 scalar_t scale_1 = static_cast<scalar_t>(scaling_parameter_1); \
127 scalar_t scale_2 = static_cast<scalar_t>(scaling_parameter_2); \
128 if (METHOD_1 == RobustKernelMethod::L2Loss && \
129 METHOD_2 == RobustKernelMethod::L2Loss) { \
130 auto GetWeightFromRobustKernelFirst = \
131 [=] OPEN3D_HOST_DEVICE(scalar_t residual) -> scalar_t { \
134 auto GetWeightFromRobustKernelSecond = \
135 [=] OPEN3D_HOST_DEVICE(scalar_t residual) -> scalar_t { \
138 return __VA_ARGS__(); \
139 } else if (METHOD_1 == RobustKernelMethod::L2Loss && \
140 METHOD_2 == RobustKernelMethod::TukeyLoss) { \
141 auto GetWeightFromRobustKernelFirst = \
142 [=] OPEN3D_HOST_DEVICE(scalar_t residual) -> scalar_t { \
145 auto GetWeightFromRobustKernelSecond = \
146 [=] OPEN3D_HOST_DEVICE(scalar_t residual) -> scalar_t { \
147 return Square(1.0 - Square(min((scalar_t)1.0, \
148 abs(residual) / scale_2))); \
150 return __VA_ARGS__(); \
151 } else if (METHOD_1 == RobustKernelMethod::TukeyLoss && \
152 METHOD_2 == RobustKernelMethod::L2Loss) { \
153 auto GetWeightFromRobustKernelFirst = \
154 [=] OPEN3D_HOST_DEVICE(scalar_t residual) -> scalar_t { \
155 return Square(1.0 - Square(min((scalar_t)1.0, \
156 abs(residual) / scale_1))); \
158 auto GetWeightFromRobustKernelSecond = \
159 [=] OPEN3D_HOST_DEVICE(scalar_t residual) -> scalar_t { \
162 return __VA_ARGS__(); \
163 } else if (METHOD_1 == RobustKernelMethod::TukeyLoss && \
164 METHOD_2 == RobustKernelMethod::TukeyLoss) { \
165 auto GetWeightFromRobustKernelFirst = \
166 [=] OPEN3D_HOST_DEVICE(scalar_t residual) -> scalar_t { \
167 return Square(1.0 - Square(min((scalar_t)1.0, \
168 abs(residual) / scale_1))); \
170 auto GetWeightFromRobustKernelSecond = \
171 [=] OPEN3D_HOST_DEVICE(scalar_t residual) -> scalar_t { \
172 return Square(1.0 - Square(min((scalar_t)1.0, \
173 abs(residual) / scale_2))); \
175 return __VA_ARGS__(); \
177 utility::LogError("Unsupported method."); \
RobustKernelMethod
Definition: RobustKernel.h:15