36 #ifndef VIGRA_ACCUMULATOR_GRAMMAR_HXX
37 #define VIGRA_ACCUMULATOR_GRAMMAR_HXX
40 #pragma warning (disable: 4503)
44 #include "metaprogramming.hxx"
86 template <
unsigned NDim>
class MultiHistogram;
90 class PrincipalProjection;
98 template <
int INDEX>
class CoordArg;
144 template <
class A>
class CoordWeighted;
145 template <
class A>
class DataFromHandle;
152 template <
class A>
class Whitened;
243 namespace acc_detail {
254 struct Error___Tag_modifiers_of_same_kind_must_not_be_combined;
257 template <class A, class S=typename acc_detail::ModifierRule<A>::type>
258 struct StandardizeTag
260 typedef typename StandardizeTag<S>::type type;
265 struct StandardizeTag<A, A>
271 template <
class A,
class B>
272 struct StandardizeTag<A, Error___Tag_modifiers_of_same_kind_must_not_be_combined<B> >
273 :
public Error___Tag_modifiers_of_same_kind_must_not_be_combined<B>
276 namespace acc_detail {
280 enum { MinPriority = 1,
281 AccumulatorPriority = 32,
282 PrepareDataPriority = 16,
283 NormalizePriority = 8,
284 AccessDataPriority = 4,
285 WeightingPriority = 2,
288 SubstitutionMask = PrepareDataPriority | AccessDataPriority | WeightingPriority | GlobalPriority };
291 struct ModifierPriority
293 static const int value = AccumulatorPriority;
296 #define VIGRA_MODIFIER_PRIORITY(MODIFIER, VALUE) \
298 struct ModifierPriority<MODIFIER<A> > \
300 static const int value = VALUE; \
303 VIGRA_MODIFIER_PRIORITY(Global, GlobalPriority)
305 VIGRA_MODIFIER_PRIORITY(Weighted, WeightingPriority)
307 VIGRA_MODIFIER_PRIORITY(Coord, AccessDataPriority)
308 VIGRA_MODIFIER_PRIORITY(DataFromHandle, AccessDataPriority)
310 VIGRA_MODIFIER_PRIORITY(DivideByCount, NormalizePriority)
311 VIGRA_MODIFIER_PRIORITY(RootDivideByCount, NormalizePriority)
312 VIGRA_MODIFIER_PRIORITY(DivideUnbiased, NormalizePriority)
313 VIGRA_MODIFIER_PRIORITY(RootDivideUnbiased, NormalizePriority)
315 VIGRA_MODIFIER_PRIORITY(Central, PrepareDataPriority)
316 VIGRA_MODIFIER_PRIORITY(Principal, PrepareDataPriority)
317 VIGRA_MODIFIER_PRIORITY(Whitened, PrepareDataPriority)
320 VIGRA_MODIFIER_PRIORITY(StandardQuantiles, AccumulatorPriority)
322 #undef VIGRA_MODIFIER_PRIORITY
325 template <class A, int TARGET_PRIORITY, int PRIORITY=ModifierPriority<A>::value>
326 struct HasModifierPriority
328 typedef VigraFalseType type;
329 static const bool value =
false;
332 template <
class A,
int TARGET_PRIORITY>
333 struct HasModifierPriority<A, TARGET_PRIORITY, TARGET_PRIORITY>
335 typedef VigraTrueType type;
336 static const bool value =
true;
339 template <
class A,
template <
class>
class B,
int TARGET_PRIORITY,
int PRIORITY>
340 struct HasModifierPriority<B<A>, TARGET_PRIORITY, PRIORITY>
341 :
public HasModifierPriority<A, TARGET_PRIORITY>
344 template <
class A,
template <
class>
class B,
int TARGET_PRIORITY>
345 struct HasModifierPriority<B<A>, TARGET_PRIORITY, TARGET_PRIORITY>
347 typedef VigraTrueType type;
348 static const bool value =
true;
352 template <
class A,
class B>
353 struct ModifierCompare
355 static const int p1 = ModifierPriority<A>::value;
356 static const int p2 = ModifierPriority<B>::value;
357 static const int value = p1 < p2
365 struct ModifierCompareToInner;
367 template <
class A,
template <
class>
class B>
368 struct ModifierCompareToInner<B<A> >
369 :
public ModifierCompare<B<A>, A>
373 template <class A, int compare=ModifierCompareToInner<A>::value>
374 struct ModifierOrder;
378 struct ModifierOrder<A, -1>
384 template <
class A,
template <
class>
class B,
template <
class>
class C>
385 struct ModifierOrder<C<B<A> >, 0>
387 typedef Error___Tag_modifiers_of_same_kind_must_not_be_combined<C<B<A> > > type;
391 template <
class A,
template <
class>
class B,
template <
class>
class C>
392 struct ModifierOrder<C<B<A> >, 1>
394 typedef B<C<A> > type;
397 #define VIGRA_CLEANUP_DATA_PREPARATION_MODIFIERS(OUTER, INNER, RESULT) \
399 struct ModifierOrder<OUTER<INNER<A > >, 0> \
401 typedef RESULT<A > type; \
405 VIGRA_CLEANUP_DATA_PREPARATION_MODIFIERS(Central, Central, Central)
406 VIGRA_CLEANUP_DATA_PREPARATION_MODIFIERS(Principal, Principal, Principal)
407 VIGRA_CLEANUP_DATA_PREPARATION_MODIFIERS(Whitened, Whitened, Whitened)
410 VIGRA_CLEANUP_DATA_PREPARATION_MODIFIERS(Principal, Central, Principal)
411 VIGRA_CLEANUP_DATA_PREPARATION_MODIFIERS(Whitened, Central, Whitened)
412 VIGRA_CLEANUP_DATA_PREPARATION_MODIFIERS(Whitened, Principal, Whitened)
415 VIGRA_CLEANUP_DATA_PREPARATION_MODIFIERS(DataFromHandle, Coord, Coord)
417 #undef VIGRA_CLEANUP_DATA_PREPARATION_MODIFIERS
420 template <
class A,
template <
class>
class B>
421 struct ModifierRule<B<B<A> > >
426 template <class A, int PRIORITY=ModifierPriority<A>::value>
427 struct RecurseModifier;
429 template <
class A,
template <
class>
class B,
int PRIORITY>
430 struct RecurseModifier<B<A>, PRIORITY>
432 typedef typename ModifierOrder<B<typename StandardizeTag<A>::type> >::type type;
435 template <
class A,
template <
class>
class B>
436 struct RecurseModifier<B<A>, AccumulatorPriority>
444 template <
class A,
template <
class>
class B>
445 struct ModifierRule<B<A> >
446 :
public RecurseModifier<B<A> >
452 #define VIGRA_REDUCE_MODFIER(TEMPLATE, SOURCE, TARGET) \
453 template <TEMPLATE > \
454 struct ModifierRule<SOURCE > \
456 typedef TARGET type; \
462 VIGRA_REDUCE_MODFIER(VIGRA_VOID, Central<CoordinateSystem>, CoordinateSystem)
464 VIGRA_REDUCE_MODFIER(VIGRA_VOID, Whitened<CoordinateSystem>, Principal<CoordinateSystem>)
467 VIGRA_REDUCE_MODFIER(template <class> class A, A<
Count>, Count)
468 VIGRA_REDUCE_MODFIER(VIGRA_VOID, Weighted<Count>, Weighted<Count>)
469 VIGRA_REDUCE_MODFIER(VIGRA_VOID, CoordWeighted<Count>, Weighted<Count>)
470 VIGRA_REDUCE_MODFIER(VIGRA_VOID, Global<Count>, Global<Count>)
473 VIGRA_REDUCE_MODFIER(
unsigned N, Moment<N>, DivideByCount<PowerSum<N> >)
474 VIGRA_REDUCE_MODFIER(
unsigned N, CentralMoment<N>, DivideByCount<Central<PowerSum<N> > >)
475 VIGRA_REDUCE_MODFIER(class A, CoordWeighted<A>, Weighted<Coord<A> >)
478 VIGRA_REDUCE_MODFIER(VIGRA_VOID, Central<Centralize>, Centralize)
479 VIGRA_REDUCE_MODFIER(VIGRA_VOID, Central<Skewness>, Skewness)
480 VIGRA_REDUCE_MODFIER(VIGRA_VOID, Central<Kurtosis>, Kurtosis)
481 VIGRA_REDUCE_MODFIER(VIGRA_VOID, Central<FlatScatterMatrix>, FlatScatterMatrix)
482 VIGRA_REDUCE_MODFIER(VIGRA_VOID, Central<ScatterMatrixEigensystem>, ScatterMatrixEigensystem)
484 VIGRA_REDUCE_MODFIER(VIGRA_VOID, Principal<Centralize>, PrincipalProjection)
485 VIGRA_REDUCE_MODFIER(VIGRA_VOID, Whitened<Centralize>, Whiten)
486 VIGRA_REDUCE_MODFIER(VIGRA_VOID, Principal<PrincipalProjection>, PrincipalProjection)
487 VIGRA_REDUCE_MODFIER(VIGRA_VOID, Whitened<PrincipalProjection>, Whiten)
488 VIGRA_REDUCE_MODFIER(VIGRA_VOID, Whitened<Whiten>, Whiten)
491 VIGRA_REDUCE_MODFIER(template <class> class A, A<RegionContour>, RegionContour)
492 VIGRA_REDUCE_MODFIER(template <class> class A, A<ConvexHull>, ConvexHull)
493 VIGRA_REDUCE_MODFIER(template <class> class A, A<RegionPerimeter>, RegionPerimeter)
494 VIGRA_REDUCE_MODFIER(template <class> class A, A<RegionCircularity>, RegionCircularity)
495 VIGRA_REDUCE_MODFIER(template <class> class A, A<RegionEccentricity>, RegionEccentricity)
496 VIGRA_REDUCE_MODFIER(VIGRA_VOID, Weighted<RegionEccentricity>, Weighted<RegionEccentricity>)
499 template <
unsigned N>
500 struct ModifierRule<AbsPowerSum<N> >
502 typedef typename IfBool<(N % 2 == 0), PowerSum<N>, AbsPowerSum<N> >::type type;
506 #undef VIGRA_REDUCE_MODFIER
509 struct ShouldBeWeighted
511 typedef VigraFalseType type;
512 static const bool value =
false;
516 struct ShouldBeWeighted<ArgMinWeight>
518 typedef VigraTrueType type;
519 static const bool value =
true;
523 struct ShouldBeWeighted<ArgMaxWeight>
525 typedef VigraTrueType type;
526 static const bool value =
true;
529 template <
class A,
template <
class>
class B>
530 struct ShouldBeWeighted<B<A> >
531 :
public ShouldBeWeighted<A>
537 struct IsCoordinateFeature
539 typedef VigraFalseType type;
540 static const bool value =
false;
543 template <
class A,
template <
class>
class B>
544 struct IsCoordinateFeature<B<A> >
546 typedef typename IsCoordinateFeature<A>::type type;
547 static const bool value = IsCoordinateFeature<A>::value;
551 struct IsCoordinateFeature<Coord<A> >
553 typedef VigraTrueType type;
554 static const bool value =
true;
558 struct IsPrincipalFeature
560 typedef VigraFalseType type;
561 static const bool value =
false;
564 template <
class A,
template <
class>
class B>
565 struct IsPrincipalFeature<B<A> >
567 typedef typename IsPrincipalFeature<A>::type type;
568 static const bool value = IsPrincipalFeature<A>::value;
572 struct IsPrincipalFeature<Principal<A> >
574 typedef VigraTrueType type;
575 static const bool value =
true;
579 struct IsPrincipalFeature<Whitened<A> >
581 typedef VigraTrueType type;
582 static const bool value =
true;
591 namespace acc_detail {
594 struct DefaultModifier;
597 struct ModifierPriority<DefaultModifier<A> >
599 static const int value = ModifierPriority<A>::value << 1;
602 template <class A, int TargetPriority, int Priority=ModifierPriority<A>::value>
603 struct InsertDefaultModifier
605 typedef DefaultModifier<typename InsertDefaultModifier<A, (TargetPriority << 1)>::type> type;
608 template <
class A,
int TargetPriority>
609 struct InsertDefaultModifier<A, TargetPriority, TargetPriority>
614 template <class A, int TargetPriority, int Priority=ModifierPriority<A>::value>
617 template <
class A,
int TargetPriority>
618 struct TagLongForm<A, TargetPriority, MaxPriority>
620 typedef typename InsertDefaultModifier<A, TargetPriority>::type type;
623 template <
class A,
template <
class>
class B,
int TargetPriority>
624 struct TagLongForm<B<A>, TargetPriority, MaxPriority>
626 typedef typename InsertDefaultModifier<B<A>, TargetPriority>::type type;
629 template <
class A,
template <
class>
class B,
int TargetPriority,
int Priority>
630 struct TagLongForm<B<A>, TargetPriority, Priority>
632 typedef typename TagLongForm<A, (Priority << 1)>::type Inner;
633 typedef typename InsertDefaultModifier<B<Inner>, TargetPriority>::type type;
636 template <
class A,
template <
class>
class B,
int TargetPriority>
637 struct TagLongForm<B<A>, TargetPriority, TargetPriority>
639 typedef typename TagLongForm<A, (TargetPriority << 1)>::type Inner;
640 typedef B<Inner> type;
644 struct LongModifierRule
650 template <class A, class S=typename LongModifierRule<A>::type>
651 struct StandardizeTagLongForm
653 typedef typename StandardizeTagLongForm<S>::type type;
658 struct StandardizeTagLongForm<A, A>
663 template <
class A,
template <
class>
class B>
664 struct LongModifierRule<B<A> >
666 typedef B<typename LongModifierRule<A>::type> type;
670 struct LongModifierRule<DefaultModifier<A> >
675 #define VIGRA_DROP_DATA_PREPARATION_MODIFIERS(SOURCE, TARGET) \
677 struct LongModifierRule<SOURCE > \
679 typedef TARGET type; \
682 VIGRA_DROP_DATA_PREPARATION_MODIFIERS(Central<Sum>,
Sum)
683 VIGRA_DROP_DATA_PREPARATION_MODIFIERS(Principal<
Sum>, Sum)
684 VIGRA_DROP_DATA_PREPARATION_MODIFIERS(Whitened<Sum>, Sum)
685 VIGRA_DROP_DATA_PREPARATION_MODIFIERS(Principal<FlatScatterMatrix>, FlatScatterMatrix)
686 VIGRA_DROP_DATA_PREPARATION_MODIFIERS(Whitened<FlatScatterMatrix>, FlatScatterMatrix)
687 VIGRA_DROP_DATA_PREPARATION_MODIFIERS(Principal<ScatterMatrixEigensystem>, ScatterMatrixEigensystem)
688 VIGRA_DROP_DATA_PREPARATION_MODIFIERS(Whitened<ScatterMatrixEigensystem>, ScatterMatrixEigensystem)
690 #undef VIGRA_DROP_DATA_PREPARATION_MODIFIERS
693 struct CheckSubstitutionFlag
695 static const bool value = (ModifierPriority<A>::value & SubstitutionMask) != 0;
698 template <
class A,
class B,
699 bool substitute=CheckSubstitutionFlag<A>::value>
700 struct SubstituteModifiers;
702 template <
class A,
class B>
703 struct SubstituteModifiers<A, B, false>
708 template <
class A,
template <
class>
class AA,
class B,
template <
class>
class BB>
709 struct SubstituteModifiers<AA<A>, BB<B>, true>
711 typedef AA<typename SubstituteModifiers<A, B>::type> type;
714 template <
class A,
class B,
template <
class>
class BB>
715 struct SubstituteModifiers<DefaultModifier<A>, BB<B>, true>
717 typedef BB<typename SubstituteModifiers<A, B>::type> type;
720 template <
class A,
template <
class>
class AA,
class B,
template <
class>
class BB>
721 struct SubstituteModifiers<AA<A>, BB<B>, false>
723 typedef BB<typename SubstituteModifiers<A, B>::type> type;
728 template <
class A,
class B>
729 struct TransferModifiers
731 typedef typename StandardizeTag<A>::type StdA;
732 typedef typename StandardizeTag<B>::type StdB;
733 typedef typename acc_detail::TagLongForm<StdA, acc_detail::MinPriority>::type AA;
734 typedef typename acc_detail::TagLongForm<StdB, acc_detail::MinPriority>::type BB;
735 typedef typename acc_detail::SubstituteModifiers<AA, BB>::type AB;
736 typedef typename acc_detail::StandardizeTagLongForm<AB>::type StdAB;
737 typedef typename StandardizeTag<StdAB>::type type;
740 template <
class A,
class HEAD,
class TAIL>
741 struct TransferModifiers<A, TypeList<HEAD, TAIL> >
743 typedef TypeList<typename TransferModifiers<A, HEAD>::type,
744 typename TransferModifiers<A, TAIL>::type> type;
748 struct TransferModifiers<A, void>
753 template <
class TargetTag,
class A=
typename TargetTag::Dependencies>
754 struct StandardizeDependencies
756 :
public StandardizeDependencies<TargetTag, typename A::type>
760 template <
class TargetTag,
class HEAD,
class TAIL>
761 struct StandardizeDependencies<TargetTag, TypeList<HEAD, TAIL> >
763 typedef typename StandardizeTag<TargetTag>::type Target;
764 typedef typename TransferModifiers<Target, TypeList<HEAD, TAIL> >::type type;
767 template <
class TargetTag>
768 struct StandardizeDependencies<TargetTag, void>
775 #endif // VIGRA_ACCUMULATOR_GRAMMAR_HXX
Basic statistic. Data value where weight assumes its minimal value.
Definition: accumulator.hxx:5378
Histogram where user provides bounds for linear range mapping from values to indices.
Definition: accumulator-grammar.hxx:71
Basic statistic. PowerSum = .
Definition: accumulator-grammar.hxx:59
RootDivideByCount< Central< PowerSum< 2 > > > StdDev
Alias. Standard deviation.
Definition: accumulator-grammar.hxx:194
PowerSum< 0 > Count
Alias. Count.
Definition: accumulator-grammar.hxx:154
Central< PowerSum< 2 > > SumOfSquaredDifferences
Alias. Sum of squared differences.
Definition: accumulator-grammar.hxx:184
Spezialization: works in pass 1, operator+=() supported (merging supported).
Definition: accumulator.hxx:4264
DivideByCount< Central< PowerSum< 2 > > > Variance
Alias. Variance.
Definition: accumulator-grammar.hxx:192
Basic statistic. First data value seen of the object.
Definition: accumulator.hxx:5279
DivideByCount< SumOfAbsDifferences > MeanAbsoluteDeviation
Alias. Mean absolute deviation.
Definition: accumulator-grammar.hxx:212
Basic statistic. Maximum value.
Definition: accumulator.hxx:5200
AbsPowerSum< 1 > AbsSum
Alias. Absolute sum.
Definition: accumulator-grammar.hxx:208
Compute the eccentricity of a 2D region in terms of its prinipal radii.
Definition: accumulator.hxx:6231
PowerSum< 2 > SumOfSquares
Alias. Sum of squares.
Definition: accumulator-grammar.hxx:167
Modifier. Compute statistic globally rather than per region.
Definition: accumulator-grammar.hxx:154
Return both the minimum and maximum in std::pair.
Definition: accumulator.hxx:5347
Basic statistic. Skewness.
Definition: accumulator.hxx:4439
SumOfSquaredDifferences SSD
Alias. Sum of squared differences.
Definition: accumulator-grammar.hxx:189
Coord< FirstSeen > RegionAnchor
Alias. Anchor point (first point of the region seen by scan-order traversal.
Definition: accumulator-grammar.hxx:217
Compute the contour of a 2D region.
Definition: accumulator.hxx:6268
Basic statistic. Identity matrix of appropriate size.
Definition: accumulator.hxx:3840
DivideByCount< ScatterMatrixEigensystem > CovarianceEigensystem
Alias. Covariance eigensystem.
Definition: accumulator-grammar.hxx:205
Basic statistic. Kurtosis.
Definition: accumulator.hxx:4511
Basic statistic. Unbiased Kurtosis.
Definition: accumulator.hxx:4547
DivideByCount< FlatScatterMatrix > Covariance
Alias. Covariance.
Definition: accumulator-grammar.hxx:201
Histogram where range mapping bounds are defined by minimum and maximum of data.
Definition: accumulator-grammar.hxx:72
Basic statistic. Flattened uppter-triangular part of scatter matrix.
Definition: accumulator.hxx:4643
Modifier. Substract mean before computing statistic.
Definition: accumulator-grammar.hxx:148
Compute weighted version of the statistic.
Definition: accumulator-grammar.hxx:143
DivideUnbiased< Central< PowerSum< 2 > > > UnbiasedVariance
Alias. Unbiased variance.
Definition: accumulator-grammar.hxx:196
Alias. CentralMoment.
Definition: accumulator-grammar.hxx:184
Weighted< RegionCenter > CenterOfMass
Alias. Center of mass.
Definition: accumulator-grammar.hxx:227
Weighted< Coord< Principal< Variance > > > MomentsOfInertia
Alias. Moments of inertia.
Definition: accumulator-grammar.hxx:231
Compute the contour of a 2D region.
Definition: accumulator.hxx:6093
Weighted< RegionRadii > WeightedRegionRadii
Alias. Region radius weighted by region intensity (square root of the moments of inertia).
Definition: accumulator-grammar.hxx:233
DivideByCount< Sum > Mean
Alias. Mean.
Definition: accumulator-grammar.hxx:170
Basic statistic. Unbiased Skewness.
Definition: accumulator.hxx:4475
Coord< Mean > RegionCenter
Alias. Region center.
Definition: accumulator-grammar.hxx:220
Specifies index of labels in CoupledHandle.
Definition: accumulator-grammar.hxx:97
Specifies index of data in CoupledHandle.
Definition: accumulator-grammar.hxx:96
Alias. Moment.
Definition: accumulator-grammar.hxx:182
PowerSum< 1 > Sum
Alias. Sum.
Definition: accumulator-grammar.hxx:165
Definition: accumulator.hxx:4813
RootDivideByCount< SumOfSquares > RootMeanSquares
Alias. Root mean square.
Definition: accumulator-grammar.hxx:172
Modifier. Project onto PCA eigenvectors.
Definition: accumulator-grammar.hxx:149
Coord< Range > BoundingBox
Alias. Rectangle enclosing the region, as a std::pair of coordinates.
Definition: accumulator-grammar.hxx:215
Central< AbsSum > SumOfAbsDifferences
Alias. Sum of absolute differences.
Definition: accumulator-grammar.hxx:210
Histogram where data values are equal to bin indices.
Definition: accumulator-grammar.hxx:70
Basic statistic. Data where weight assumes its maximal value.
Definition: accumulator.hxx:5453
Modifier. RootDivideByCount = sqrt( TAG/Count )
Definition: accumulator-grammar.hxx:137
DivideUnbiased< FlatScatterMatrix > UnbiasedCovariance
Alias. Unbiased covariance.
Definition: accumulator-grammar.hxx:203
Compute (0%, 10%, 25%, 50%, 75%, 90%, 100%) quantiles from given histogram.
Definition: accumulator-grammar.hxx:79
Compute the perimeter of a 2D region.
Definition: accumulator.hxx:6166
Modifier. Divide statistic by Count: DivideByCount = TAG / Count .
Definition: accumulator-grammar.hxx:136
Basic statistic. AbsPowerSum = .
Definition: accumulator-grammar.hxx:60
Weighted< RegionCenter > WeightedRegionCenter
Alias. Region center weighted by the region intensity (center of mass).
Definition: accumulator-grammar.hxx:229
Specifies index of data in CoupledHandle.
Definition: accumulator-grammar.hxx:95
Like AutoRangeHistogram, but use global min/max rather than region min/max.
Definition: accumulator-grammar.hxx:73
RootDivideUnbiased< Central< PowerSum< 2 > > > UnbiasedStdDev
Alias. Unbiased standard deviation.
Definition: accumulator-grammar.hxx:198
Coord< Principal< CoordinateSystem > > RegionAxes
Alias. Region axes.
Definition: accumulator-grammar.hxx:224
Basic statistic. Minimum value.
Definition: accumulator.hxx:5122
Weighted< RegionAxes > AxesOfInertia
Alias. Axes of inertia.
Definition: accumulator-grammar.hxx:235
Modifier. Divide statistics by Count-1: DivideUnbiased = TAG / (Count-1)
Definition: accumulator-grammar.hxx:138
Compute the circularity of a 2D region.
Definition: accumulator.hxx:6199
Modifier. Compute statistic from pixel coordinates rather than from pixel values. ...
Definition: accumulator-grammar.hxx:142
Coord< Principal< StdDev > > RegionRadii
Alias. Region radii.
Definition: accumulator-grammar.hxx:222
Modifier. RootDivideUnbiased = sqrt( TAG / (Count-1) )
Definition: accumulator-grammar.hxx:139