@@ -177,7 +177,9 @@ namespace tmd
177
177
*
178
178
* @return Result containing distance, nearest point on the mesh, nearest entity and the nearest triangle index.
179
179
*/
180
- Result unsigned_distance (const Vec3d &point) const ;
180
+ template <typename IndexableVector3double>
181
+ Result unsigned_distance (const IndexableVector3double& point) const ;
182
+ Result unsigned_distance (const std::array<double , 3 >& point) const ;
181
183
182
184
/* *
183
185
* @brief Computes the unsigned distance from a point to the triangle mesh. Thread safe.
@@ -186,7 +188,9 @@ namespace tmd
186
188
*
187
189
* @return Result containing distance, nearest point on the mesh, nearest entity and the nearest triangle index.
188
190
*/
189
- Result signed_distance (const Vec3d& point) const ;
191
+ template <typename IndexableVector3double>
192
+ Result signed_distance (const IndexableVector3double& point) const ;
193
+ Result signed_distance (const std::array<double , 3 >& point) const ;
190
194
};
191
195
}
192
196
@@ -243,9 +247,10 @@ inline void tmd::TriangleMeshDistance::construct(const std::vector<IndexableVect
243
247
this ->_construct ();
244
248
}
245
249
246
- inline tmd::Result tmd::TriangleMeshDistance::signed_distance (const Vec3d & point) const
250
+ inline tmd::Result tmd::TriangleMeshDistance::signed_distance (const std::array< double , 3 > & point) const
247
251
{
248
- Result result = this ->unsigned_distance (point);
252
+ const Vec3d p (point[0 ], point[1 ], point[2 ]);
253
+ Result result = this ->unsigned_distance (p);
249
254
250
255
const std::array<int , 3 >& triangle = this ->triangles [result.triangle_id ];
251
256
Vec3d pseudonormal;
@@ -277,25 +282,38 @@ inline tmd::Result tmd::TriangleMeshDistance::signed_distance(const Vec3d& point
277
282
break ;
278
283
}
279
284
280
- const Vec3d u = point - result.nearest_point ;
285
+ const Vec3d u = p - result.nearest_point ;
281
286
result.distance *= (u.dot (pseudonormal) >= 0.0 ) ? 1.0 : -1.0 ;
282
287
283
288
return result;
284
289
}
285
290
286
- inline tmd::Result tmd::TriangleMeshDistance::unsigned_distance (const Vec3d& point) const
291
+ template <typename IndexableVector3double>
292
+ inline tmd::Result tmd::TriangleMeshDistance::signed_distance (const IndexableVector3double& point) const
293
+ {
294
+ return this ->signed_distance ({ static_cast <double >(point[0 ]), static_cast <double >(point[1 ]), static_cast <double >(point[2 ]) });
295
+ }
296
+
297
+ inline tmd::Result tmd::TriangleMeshDistance::unsigned_distance (const std::array<double , 3 >& point) const
287
298
{
288
299
if (!this ->is_constructed ) {
289
300
std::cout << " DistanceTriangleMesh error: not constructed." << std::endl;
290
301
exit (-1 );
291
302
}
292
303
304
+ const Vec3d p (point[0 ], point[1 ], point[2 ]);
293
305
Result result;
294
306
result.distance = std::numeric_limits<double >::max ();
295
- this ->_query (result, this ->nodes [0 ], point );
307
+ this ->_query (result, this ->nodes [0 ], p );
296
308
return result;
297
309
}
298
310
311
+ template <typename IndexableVector3double>
312
+ inline tmd::Result tmd::TriangleMeshDistance::unsigned_distance (const IndexableVector3double& point) const
313
+ {
314
+ return this ->unsigned_distance ({static_cast <double >(point[0 ]), static_cast <double >(point[1 ]), static_cast <double >(point[2 ])});
315
+ }
316
+
299
317
inline void tmd::TriangleMeshDistance::_construct ()
300
318
{
301
319
if (this ->triangles .size () == 0 ) {
0 commit comments