1 #ifndef GfxTL__L2NORM_HEADER__
2 #define GfxTL__L2NORM_HEADER__
28 template<
unsigned int SizeT >
46 template<
class VectorKernelT,
class MaskElemSizeT = FixedMaskElementSize< 1 > >
48 :
public VectorKernelT
49 ,
public MaskElemSizeT
54 template<
class ScalarAT,
class ScalarBT >
58 ScalarBT >::DifferenceType
Type;
61 template<
class Po
intAT,
class Po
intBT >
69 typedef typename DistanceType
74 DistType d = p[0] -
v[0], di;
76 for (
unsigned int i = 1; i < VectorKernelT::m_dim; ++i)
84 template<
class Po
intAT,
class Po
intBT >
92 typedef typename DistanceType
97 DistType d = p[0] -
v[0], di;
99 for (
unsigned int i = 1; i < VectorKernelT::m_dim; ++i)
107 template<
class Po
intAT,
class Po
intBT >
108 typename DistanceType
114 typename DistanceType
118 >::
Type abortDist)
const
120 typedef typename DistanceType
125 DistType d = p[0] -
v[0], di;
127 for (
unsigned int i = 1; i < VectorKernelT::m_dim && d < abortDist; ++i)
135 template<
class Po
intAT,
class Po
intBT,
class MaskAT,
class MaskBT >
136 typename DistanceType
142 const MaskBT& mb)
const
144 typedef typename DistanceType
150 for (
unsigned int i = 0; i < VectorKernelT::m_dim / MaskElemSizeT::m_maskElemSize; ++i)
152 if (!(ma[i] && mb[i]))
156 for (
unsigned int j = 0; j < MaskElemSizeT::m_maskElemSize; ++j)
158 dj = p[i * MaskElemSizeT::m_maskElemSize + j] -
v[i * MaskElemSizeT::m_maskElemSize + j];
165 template<
class Po
intAT,
class Po
intBT,
class MaskAT,
class MaskBT >
166 typename DistanceType
173 typename DistanceType
177 >::
Type abortDist)
const
179 typedef typename DistanceType
185 for (
unsigned int i = 0; i < VectorKernelT::m_dim / MaskElemSizeT::m_maskElemSize && d < abortDist; ++i)
187 if (!(ma[i] && mb[i]))
191 for (
unsigned int j = 0; j < MaskElemSizeT::m_maskElemSize && d < abortDist; ++j)
193 dj = p[i * MaskElemSizeT::m_maskElemSize + j] -
v[i * MaskElemSizeT::m_maskElemSize + j];
200 template<
class Po
intAT,
class Po
intBT,
class MaskBT >
201 typename DistanceType
207 const MaskBT& mb)
const
209 typedef typename DistanceType
215 for (
unsigned int i = 0; i < VectorKernelT::m_dim / MaskElemSizeT::m_maskElemSize; ++i)
221 for (
unsigned int j = 0; j < MaskElemSizeT::m_maskElemSize; ++j)
223 dj = p[i * MaskElemSizeT::m_maskElemSize + j] -
v[i * MaskElemSizeT::m_maskElemSize + j];
230 template<
class Po
intAT,
class Po
intBT,
class MaskBT >
231 typename DistanceType
238 typename DistanceType
242 >::
Type abortDist)
const
244 typedef typename DistanceType
250 for (
unsigned int i = 0; i < VectorKernelT::m_dim / MaskElemSizeT::m_maskElemSize && d < abortDist; ++i)
256 for (
unsigned int j = 0; j < MaskElemSizeT::m_maskElemSize && d < abortDist; ++j)
258 dj = p[i * MaskElemSizeT::m_maskElemSize + j] -
v[i * MaskElemSizeT::m_maskElemSize + j];
265 template<
class Po
intAT,
class Po
intBT,
class MaskAT,
class MaskBT >
266 typename DistanceType
271 Distance(
const PointAT& p,
const PointBT&
v,
const MaskAT& ma,
272 const MaskBT& mb)
const
277 template<
class ScalarT >
283 template<
class DistScalarT,
class DiffScalarT >
285 DiffScalarT cutDiff)
const
287 return boxSqrDist - ((DistScalarT)boxDiff * (DistScalarT)boxDiff)
288 + ((DistScalarT)cutDiff * (DistScalarT)cutDiff);
291 template<
class Po
intAT,
class Po
intBT >
292 typename DistanceType
298 const PointBT&
max)
const
300 typename DistanceType
305 for (
unsigned int i = 0; i < VectorKernelT::m_dim; ++i)
312 else if (
a[i] >
max[i])
321 template<
class Po
intAT,
class Po
intBT >
322 typename DistanceType
328 const PointBT&
max)
const
330 typedef typename DistanceType
335 DistType sqrDist = 0, t;
336 for (
unsigned int i = 0; i < VectorKernelT::m_dim; ++i)
342 template<
class Po
intAT,
class MaskAT,
class Po
intBT >
343 typename DistanceType
349 const PointBT&
max)
const
351 typename DistanceType
356 for (
unsigned int i = 0; i < VectorKernelT::m_dim / MaskElemSizeT::m_maskElemSize; ++i)
362 for (
unsigned int j = 0; j < MaskElemSizeT::m_maskElemSize; ++j)
364 if (
min[i * MaskElemSizeT::m_maskElemSize + j] >
max[i * MaskElemSizeT::m_maskElemSize + j])
368 if (
a[i * MaskElemSizeT::m_maskElemSize + j] <
min[i * MaskElemSizeT::m_maskElemSize + j])
370 t =
min[i * MaskElemSizeT::m_maskElemSize + j] -
a[i * MaskElemSizeT::m_maskElemSize + j];
373 else if (
a[i * MaskElemSizeT::m_maskElemSize + j] >
max[i * MaskElemSizeT::m_maskElemSize + j])
375 t =
a[i * MaskElemSizeT::m_maskElemSize + j] -
max[i * MaskElemSizeT::m_maskElemSize + j];
383 template<
class Po
intAT,
class MaskAT,
class Po
intBT >
384 typename DistanceType
390 const PointBT&
min,
const PointBT&
max)
const
392 typedef typename DistanceType
397 DistType sqrDist = 0, t;
398 for (
unsigned int i = 0; i < VectorKernelT::m_dim / MaskElemSizeT::m_maskElemSize; ++i)
404 for (
unsigned int j = 0; j < MaskElemSizeT::m_maskElemSize; ++j)
406 if (
min[i * MaskElemSizeT::m_maskElemSize + j] >
max[i * MaskElemSizeT::m_maskElemSize + j])
417 template<
class Po
intAT,
class Po
intBT,
class W
idthT >
418 typename DistanceType
426 typename DistanceType
431 for (
unsigned int i = 0; i < VectorKernelT::m_dim; ++i)
438 else if (
a[i] >
min[i] + width)
440 t =
a[i] - (
min[i] + width);
455 template<
class Po
intAT,
class Po
intBT >
458 for (
unsigned int i = 0; i < VectorKernelT::m_dim; ++i)
460 (*bboxMin)[i] = vec[i];
464 template<
class Po
intAT,
class Po
intBT >
467 for (
unsigned int i = 0; i < VectorKernelT::m_dim; ++i)
469 (*bboxMax)[i] = vec[i];
473 template<
class Po
intAT,
class MaskAT,
class Po
intBT >
475 PointBT* bboxMin)
const
478 for (
unsigned int i = 0; i < VectorKernelT::m_dim / MaskElemSizeT::m_maskElemSize; ++i)
480 for (
unsigned int j = 0; j < MaskElemSizeT::m_maskElemSize; ++j)
482 (*bboxMin)[i * MaskElemSizeT::m_maskElemSize + j] = vec[i * MaskElemSizeT::m_maskElemSize + j];
485 for (
unsigned int j = 0; j < MaskElemSizeT::m_maskElemSize; ++j)
487 (*bboxMin)[i * MaskElemSizeT::m_maskElemSize + j] = -std::numeric_limits< ScalarType >::infinity();
491 template<
class Po
intAT,
class MaskAT,
class Po
intBT >
493 PointBT* bboxMin)
const
496 for (
unsigned int i = 0; i < VectorKernelT::m_dim / MaskElemSizeT::m_maskElemSize; ++i)
498 for (
unsigned int j = 0; j < MaskElemSizeT::m_maskElemSize; ++j)
500 (*bboxMin)[i * MaskElemSizeT::m_maskElemSize + j] = vec[i * MaskElemSizeT::m_maskElemSize + j];
503 for (
unsigned int j = 0; j < MaskElemSizeT::m_maskElemSize; ++j)
505 (*bboxMin)[i * MaskElemSizeT::m_maskElemSize + j] = std::numeric_limits< ScalarType >::infinity();
509 template<
class Po
intAT,
class MaskAT,
class Po
intBT >
511 PointBT* bboxMax)
const
514 for (
unsigned int i = 0; i < VectorKernelT::m_dim / MaskElemSizeT::m_maskElemSize; ++i)
516 for (
unsigned int j = 0; j < MaskElemSizeT::m_maskElemSize; ++j)
518 (*bboxMax)[i * MaskElemSizeT::m_maskElemSize + j] = vec[i * MaskElemSizeT::m_maskElemSize + j];
521 for (
unsigned int j = 0; j < MaskElemSizeT::m_maskElemSize; ++j)
523 (*bboxMax)[i * MaskElemSizeT::m_maskElemSize + j] = std::numeric_limits< ScalarType >::infinity();
527 template<
class Po
intAT,
class MaskAT,
class Po
intBT >
529 PointBT* bboxMax)
const
532 for (
unsigned int i = 0; i < VectorKernelT::m_dim / MaskElemSizeT::m_maskElemSize; ++i)
534 for (
unsigned int j = 0; j < MaskElemSizeT::m_maskElemSize; ++j)
536 (*bboxMax)[i * MaskElemSizeT::m_maskElemSize + j] = vec[i * MaskElemSizeT::m_maskElemSize + j];
539 for (
unsigned int j = 0; j < MaskElemSizeT::m_maskElemSize; ++j)
541 (*bboxMax)[i * MaskElemSizeT::m_maskElemSize + j] = -std::numeric_limits< ScalarType >::infinity();
545 template<
class BoxPo
intT >
550 for (
unsigned int i = 0; i < VectorKernelT::m_dim; ++i)
557 template<
class Po
intT,
class BoxPo
intT >
560 for (
unsigned int i = 0; i < VectorKernelT::m_dim; ++i)
562 if (box[0][i] > p[i])
566 else if (box[1][i] < p[i])
573 template<
class Po
intT,
class MaskT,
class BoxPo
intT >
578 for (
unsigned int i = 0; i < VectorKernelT::m_dim / MaskElemSizeT::m_maskElemSize; ++i)
581 for (
unsigned int j = 0; j < MaskElemSizeT::m_maskElemSize; ++j)
583 if (box[0][i * MaskElemSizeT::m_maskElemSize + j] > p[i * MaskElemSizeT::m_maskElemSize + j])
585 box[0][i * MaskElemSizeT::m_maskElemSize + j] = p[i * MaskElemSizeT::m_maskElemSize + j];
587 else if (box[1][i * MaskElemSizeT::m_maskElemSize + j] < p[i * MaskElemSizeT::m_maskElemSize + j])
589 box[1][i * MaskElemSizeT::m_maskElemSize + j] = p[i * MaskElemSizeT::m_maskElemSize + j];
593 for (
unsigned int j = 0; j < MaskElemSizeT::m_maskElemSize; ++j)
595 box[0][i * MaskElemSizeT::m_maskElemSize + j] = -std::numeric_limits< ScalarType >::infinity();
596 box[1][i * MaskElemSizeT::m_maskElemSize + j] = std::numeric_limits< ScalarType >::infinity();
601 template<
class Po
intT,
class MaskT,
class BoxPo
intT >
606 for (
unsigned int i = 0; i < VectorKernelT::m_dim / MaskElemSizeT::m_maskElemSize; ++i)
608 for (
unsigned int j = 0; j < MaskElemSizeT::m_maskElemSize; ++j)
610 if (box[0][i * MaskElemSizeT::m_maskElemSize + j] > p[i * MaskElemSizeT::m_maskElemSize + j])
612 box[0][i * MaskElemSizeT::m_maskElemSize + j] = p[i * MaskElemSizeT::m_maskElemSize + j];
614 else if (box[1][i * MaskElemSizeT::m_maskElemSize + j] < p[i * MaskElemSizeT::m_maskElemSize + j])
616 box[1][i * MaskElemSizeT::m_maskElemSize + j] = p[i * MaskElemSizeT::m_maskElemSize + j];
622 template<
class VectorKernelT >
624 :
public L2NormWithMask< VectorKernelT, FixedMaskElementSize< 1 > >
627 template<
class MaskElemSizeT >
630 template<
class VectorKernelT >