36 #ifndef VIGRA_ACCUMULATOR_HXX
37 #define VIGRA_ACCUMULATOR_HXX
40 #pragma warning (disable: 4503)
43 #include "accumulator-grammar.hxx"
45 #include "metaprogramming.hxx"
46 #include "bit_array.hxx"
47 #include "static_assert.hxx"
48 #include "mathutil.hxx"
49 #include "utilities.hxx"
50 #include "multi_iterator_coupled.hxx"
52 #include "multi_math.hxx"
53 #include "eigensystem.hxx"
54 #include "histogram.hxx"
334 template <
class T01=void,
class T02=void,
class T03=void,
class T04=void,
class T05=void,
335 class T06=void,
class T07=void,
class T08=void,
class T09=void,
class T10=void,
336 class T11=void,
class T12=void,
class T13=void,
class T14=void,
class T15=void,
337 class T16=void,
class T17=void,
class T18=void,
class T19=void,
class T20=
void>
339 :
public MakeTypeList<
340 typename StandardizeTag<T01>::type, typename StandardizeTag<T02>::type, typename StandardizeTag<T03>::type,
341 typename StandardizeTag<T04>::type, typename StandardizeTag<T05>::type, typename StandardizeTag<T06>::type,
342 typename StandardizeTag<T07>::type, typename StandardizeTag<T08>::type, typename StandardizeTag<T09>::type,
343 typename StandardizeTag<T10>::type, typename StandardizeTag<T11>::type, typename StandardizeTag<T12>::type,
344 typename StandardizeTag<T13>::type, typename StandardizeTag<T14>::type, typename StandardizeTag<T15>::type,
345 typename StandardizeTag<T16>::type, typename StandardizeTag<T17>::type, typename StandardizeTag<T18>::type,
346 typename StandardizeTag<T19>::type, typename StandardizeTag<T20>::type
351 template <
class T01,
class T02,
class T03,
class T04,
class T05,
352 class T06,
class T07,
class T08,
class T09,
class T10,
353 class T11,
class T12,
class T13,
class T14,
class T15,
354 class T16,
class T17,
class T18,
class T19,
class T20>
355 struct StandardizeTag<
Select<T01, T02, T03, T04, T05,
356 T06, T07, T08, T09, T10,
357 T11, T12, T13, T14, T15,
358 T16, T17, T18, T19, T20>,
359 Select<T01, T02, T03, T04, T05,
360 T06, T07, T08, T09, T10,
361 T11, T12, T13, T14, T15,
362 T16, T17, T18, T19, T20> >
364 typedef typename Select<T01, T02, T03, T04, T05,
365 T06, T07, T08, T09, T10,
366 T11, T12, T13, T14, T15,
367 T16, T17, T18, T19, T20>::type type;
370 struct AccumulatorBegin
372 typedef Select<> Dependencies;
374 static std::string
const & name()
376 static const std::string n(
"AccumulatorBegin (internal)");
380 template <
class T,
class BASE>
387 struct AccumulatorEnd;
392 struct LabelDispatchTag;
394 struct Error__Global_statistics_are_only_defined_for_AccumulatorChainArray;
404 typedef Select<> Dependencies;
406 static std::string
const & name()
408 static const std::string n = std::string(
"LabelArg<") +
asString(INDEX) +
"> (internal)";
412 template <
class T,
class BASE>
416 typedef LabelArgTag Tag;
417 typedef void value_type;
418 typedef void result_type;
420 static const int value = INDEX;
421 static const unsigned int workInPass = 0;
429 typedef Select<> Dependencies;
431 static std::string
const & name()
433 static const std::string n = std::string(
"CoordArg<") +
asString(INDEX) +
"> (internal)";
437 template <
class T,
class BASE>
441 typedef CoordArgTag Tag;
442 typedef void value_type;
443 typedef void result_type;
445 static const int value = INDEX;
446 static const unsigned int workInPass = 0;
450 template <
class T,
class TAG,
class NEXT=AccumulatorEnd>
451 struct AccumulatorBase;
453 template <
class Tag,
class A>
456 template <
class Tag,
class A,
class TargetTag=
typename A::Tag>
457 struct LookupDependency;
459 #ifndef _MSC_VER // compiler bug? (causes 'ambiguous overload error')
461 template <
class TAG,
class A>
462 typename LookupTag<TAG, A>::reference
465 template <
class TAG,
class A>
466 typename LookupDependency<TAG, A>::result_type
467 getDependency(A
const & a);
482 struct PushArgTagToTail
487 #define VIGRA_PUSHARGTAG(TAG) \
488 template <int INDEX, class TAIL> \
489 struct PushArgTagToTail<TypeList<TAG<INDEX>, TAIL> > \
491 typedef typename Push<TAIL, TypeList<TAG<INDEX> > >::type type; \
494 VIGRA_PUSHARGTAG(DataArg)
495 VIGRA_PUSHARGTAG(WeightArg)
496 VIGRA_PUSHARGTAG(CoordArg)
497 VIGRA_PUSHARGTAG(LabelArg)
499 #undef VIGRA_PUSHARGTAG
505 struct AddDependencies;
507 template <
class HEAD,
class TAIL>
508 struct AddDependencies<TypeList<HEAD, TAIL> >
510 typedef typename AddDependencies<TAIL>::type TailWithDependencies;
511 typedef typename StandardizeDependencies<HEAD>::type HeadDependencies;
512 typedef typename AddDependencies<HeadDependencies>::type TransitiveHeadDependencies;
513 typedef TypeList<HEAD, TransitiveHeadDependencies> HeadWithDependencies;
514 typedef typename PushUnique<HeadWithDependencies, TailWithDependencies>::type UnsortedDependencies;
515 typedef typename PushArgTagToTail<UnsortedDependencies>::type type;
519 struct AddDependencies<void>
526 template <
class Dependencies>
527 struct ActivateDependencies;
529 template <
class HEAD,
class TAIL>
530 struct ActivateDependencies<TypeList<HEAD, TAIL> >
532 template <
class Chain,
class ActiveFlags>
533 static void exec(ActiveFlags & flags)
535 LookupTag<HEAD, Chain>::type::activateImpl(flags);
536 ActivateDependencies<TAIL>::template exec<Chain>(flags);
539 template <
class Chain,
class ActiveFlags,
class GlobalFlags>
540 static void exec(ActiveFlags & flags, GlobalFlags & gflags)
542 LookupTag<HEAD, Chain>::type::template activateImpl<Chain>(flags, gflags);
543 ActivateDependencies<TAIL>::template exec<Chain>(flags, gflags);
547 template <
class HEAD,
class TAIL>
548 struct ActivateDependencies<TypeList<Global<HEAD>, TAIL> >
550 template <
class Chain,
class ActiveFlags,
class GlobalFlags>
551 static void exec(ActiveFlags & flags, GlobalFlags & gflags)
553 LookupTag<Global<HEAD>, Chain>::type::activateImpl(gflags);
554 ActivateDependencies<TAIL>::template exec<Chain>(flags, gflags);
559 struct ActivateDependencies<void>
561 template <
class Chain,
class ActiveFlags>
562 static void exec(ActiveFlags &)
565 template <
class Chain,
class ActiveFlags,
class GlobalFlags>
566 static void exec(ActiveFlags &, GlobalFlags &)
570 template <
class List>
571 struct SeparateGlobalAndRegionTags;
573 template <
class HEAD,
class TAIL>
574 struct SeparateGlobalAndRegionTags<TypeList<HEAD, TAIL> >
576 typedef SeparateGlobalAndRegionTags<TAIL> Inner;
577 typedef TypeList<HEAD, typename Inner::RegionTags> RegionTags;
578 typedef typename Inner::GlobalTags GlobalTags;
581 template <
class HEAD,
class TAIL>
582 struct SeparateGlobalAndRegionTags<TypeList<Global<HEAD>, TAIL> >
584 typedef SeparateGlobalAndRegionTags<TAIL> Inner;
585 typedef typename Inner::RegionTags RegionTags;
586 typedef TypeList<HEAD, typename Inner::GlobalTags> GlobalTags;
589 template <
int INDEX,
class TAIL>
590 struct SeparateGlobalAndRegionTags<TypeList<DataArg<INDEX>, TAIL> >
592 typedef SeparateGlobalAndRegionTags<TAIL> Inner;
593 typedef TypeList<DataArg<INDEX>,
typename Inner::RegionTags> RegionTags;
594 typedef TypeList<DataArg<INDEX>,
typename Inner::GlobalTags> GlobalTags;
597 template <
int INDEX,
class TAIL>
598 struct SeparateGlobalAndRegionTags<TypeList<LabelArg<INDEX>, TAIL> >
600 typedef SeparateGlobalAndRegionTags<TAIL> Inner;
601 typedef typename Inner::RegionTags RegionTags;
602 typedef TypeList<LabelArg<INDEX>,
typename Inner::GlobalTags> GlobalTags;
605 template <
int INDEX,
class TAIL>
606 struct SeparateGlobalAndRegionTags<TypeList<WeightArg<INDEX>, TAIL> >
608 typedef SeparateGlobalAndRegionTags<TAIL> Inner;
609 typedef TypeList<WeightArg<INDEX>,
typename Inner::RegionTags> RegionTags;
610 typedef TypeList<WeightArg<INDEX>,
typename Inner::GlobalTags> GlobalTags;
613 template <
int INDEX,
class TAIL>
614 struct SeparateGlobalAndRegionTags<TypeList<CoordArg<INDEX>, TAIL> >
616 typedef SeparateGlobalAndRegionTags<TAIL> Inner;
617 typedef TypeList<CoordArg<INDEX>,
typename Inner::RegionTags> RegionTags;
618 typedef TypeList<CoordArg<INDEX>,
typename Inner::GlobalTags> GlobalTags;
622 struct SeparateGlobalAndRegionTags<void>
624 typedef void RegionTags;
625 typedef void GlobalTags;
634 template <
class Accumulators>
635 struct CollectAccumulatorNames;
637 template <
class HEAD,
class TAIL>
638 struct CollectAccumulatorNames<TypeList<HEAD, TAIL> >
640 template <
class BackInsertable>
641 static void exec(BackInsertable & a,
bool skipInternals=
true)
643 if(!skipInternals || HEAD::name().find(
"internal") == std::string::npos)
644 a.push_back(HEAD::name());
645 CollectAccumulatorNames<TAIL>::exec(a, skipInternals);
650 struct CollectAccumulatorNames<void>
652 template <
class BackInsertable>
653 static void exec(BackInsertable & a,
bool skipInternals=
true)
658 struct ApplyVisitorToTag;
660 template <
class HEAD,
class TAIL>
661 struct ApplyVisitorToTag<TypeList<HEAD, TAIL> >
663 template <
class Accu,
class Visitor>
664 static bool exec(Accu & a, std::string
const & tag, Visitor
const & v)
669 v.template exec<HEAD>(a);
674 return ApplyVisitorToTag<TAIL>::exec(a, tag, v);
680 struct ApplyVisitorToTag<void>
682 template <
class Accu,
class Visitor>
683 static bool exec(Accu & a, std::string
const & tag, Visitor
const & v)
689 struct ActivateTag_Visitor
691 template <
class TAG,
class Accu>
692 void exec(Accu & a)
const
694 a.template activate<TAG>();
698 struct TagIsActive_Visitor
702 template <
class TAG,
class Accu>
703 void exec(Accu & a)
const
705 result = a.template isActive<TAG>();
716 struct SetHistogramBincount
718 template <
class Accu>
719 static void exec(Accu & a, HistogramOptions
const & options)
723 template <
template <
int>
class Histogram>
724 struct SetHistogramBincount<Histogram<0> >
726 template <
class Accu>
727 static void exec(Accu & a, HistogramOptions
const & options)
729 a.setBinCount(options.binCount);
734 struct ApplyHistogramOptions
736 template <
class Accu>
737 static void exec(Accu & a, HistogramOptions
const & options)
742 struct ApplyHistogramOptions<StandardQuantiles<TAG> >
744 template <
class Accu>
745 static void exec(Accu & a, HistogramOptions
const & options)
749 template <
class TAG,
template <
class>
class MODIFIER>
750 struct ApplyHistogramOptions<MODIFIER<TAG> >
751 :
public ApplyHistogramOptions<TAG>
755 struct ApplyHistogramOptions<IntegerHistogram<0> >
757 template <
class Accu>
758 static void exec(Accu & a, HistogramOptions
const & options)
760 SetHistogramBincount<IntegerHistogram<0> >::exec(a, options);
764 template <
int BinCount>
765 struct ApplyHistogramOptions<UserRangeHistogram<BinCount> >
767 template <
class Accu>
768 static void exec(Accu & a, HistogramOptions
const & options)
770 SetHistogramBincount<UserRangeHistogram<BinCount> >::exec(a, options);
771 if(a.scale_ == 0.0 && options.validMinMax())
772 a.setMinMax(options.minimum, options.maximum);
776 template <
int BinCount>
777 struct ApplyHistogramOptions<AutoRangeHistogram<BinCount> >
779 template <
class Accu>
780 static void exec(Accu & a, HistogramOptions
const & options)
782 SetHistogramBincount<AutoRangeHistogram<BinCount> >::exec(a, options);
783 if(a.scale_ == 0.0 && options.validMinMax())
784 a.setMinMax(options.minimum, options.maximum);
788 template <
int BinCount>
789 struct ApplyHistogramOptions<GlobalRangeHistogram<BinCount> >
791 template <
class Accu>
792 static void exec(Accu & a, HistogramOptions
const & options)
794 SetHistogramBincount<GlobalRangeHistogram<BinCount> >::exec(a, options);
797 if(options.validMinMax())
798 a.setMinMax(options.minimum, options.maximum);
800 a.setRegionAutoInit(options.local_auto_init);
817 template <
unsigned LEVEL,
class GlobalAccumulatorHandle>
818 struct AccumulatorEndImpl
820 typedef typename GlobalAccumulatorHandle::type GlobalAccumulatorType;
822 typedef AccumulatorEnd Tag;
823 typedef void value_type;
824 typedef bool result_type;
825 typedef BitArray<LEVEL> AccumulatorFlags;
827 static const unsigned int workInPass = 0;
828 static const int index = -1;
829 static const unsigned level = LEVEL;
831 AccumulatorFlags active_accumulators_;
832 mutable AccumulatorFlags is_dirty_;
833 GlobalAccumulatorHandle globalAccumulator_;
835 template <
class GlobalAccumulator>
836 void setGlobalAccumulator(GlobalAccumulator
const * a)
838 globalAccumulator_.pointer_ = a;
841 static std::string name()
843 return "AccumulatorEnd (internal)";
846 bool operator()()
const {
return false; }
847 bool get()
const {
return false; }
849 template <
unsigned,
class U>
853 template <
unsigned,
class U>
854 void pass(U
const &,
double)
858 void merge(U
const &)
862 void resize(U
const &)
873 template <
class Flags>
874 static void activateImpl(Flags &)
877 template <
class Accu,
class Flags1,
class Flags2>
878 static void activateImpl(Flags1 &, Flags2 &)
881 template <
class Flags>
882 static bool isActiveImpl(Flags
const &)
887 void applyHistogramOptions(HistogramOptions
const &)
890 static unsigned int passesRequired()
895 static unsigned int passesRequired(AccumulatorFlags
const &)
902 active_accumulators_.clear();
907 void setDirtyImpl()
const
909 is_dirty_.template set<which>();
913 void setCleanImpl()
const
915 is_dirty_.template reset<which>();
919 bool isDirtyImpl()
const
921 return is_dirty_.template test<which>();
926 template <
class A,
unsigned CurrentPass,
bool allowRuntimeActivation,
unsigned WorkPass=A::workInPass>
930 static void exec(A & a, T
const & t)
934 static void exec(A & a, T
const & t,
double weight)
938 template <
class A,
unsigned CurrentPass>
939 struct DecoratorImpl<A, CurrentPass, false, CurrentPass>
942 static void exec(A & a, T
const & t)
948 static void exec(A & a, T
const & t,
double weight)
953 static typename A::result_type
get(A
const & a)
958 static void merge(A & a, A
const & o)
964 static void resize(A & a, T
const & t)
969 static void applyHistogramOptions(A & a, HistogramOptions
const & options)
971 ApplyHistogramOptions<typename A::Tag>::exec(a, options);
974 static unsigned int passesRequired()
976 static const unsigned int A_workInPass = A::workInPass;
977 return std::max(A_workInPass, A::InternalBaseType::passesRequired());
981 template <
class A,
unsigned CurrentPass>
982 struct DecoratorImpl<A, CurrentPass, true, CurrentPass>
986 return A::isActiveImpl(getAccumulator<AccumulatorEnd>(a).active_accumulators_);
990 static void exec(A & a, T
const & t)
997 static void exec(A & a, T
const & t,
double weight)
1000 a.update(t, weight);
1003 static typename A::result_type
get(A
const & a)
1005 static const std::string message = std::string(
"get(accumulator): attempt to access inactive statistic '") +
1006 typeid(
typename A::Tag).name() +
"'.";
1007 vigra_precondition(
isActive(a), message);
1011 static void merge(A & a, A
const & o)
1018 static void resize(A & a, T
const & t)
1024 static void applyHistogramOptions(A & a, HistogramOptions
const & options)
1027 ApplyHistogramOptions<typename A::Tag>::exec(a, options);
1030 template <
class ActiveFlags>
1031 static unsigned int passesRequired(ActiveFlags
const & flags)
1033 static const unsigned int A_workInPass = A::workInPass;
1034 return A::isActiveImpl(flags)
1035 ? std::max(A_workInPass, A::InternalBaseType::passesRequired(flags))
1036 : A::InternalBaseType::passesRequired(flags);
1042 template <
class T,
class Shape>
1043 void reshapeImpl(T &, Shape
const &)
1046 template <
class T,
class Shape,
class Initial>
1047 void reshapeImpl(T &, Shape
const &, Initial
const & = T())
1050 template <
unsigned int N,
class T,
class Alloc,
class Shape>
1051 void reshapeImpl(MultiArray<N, T, Alloc> & a, Shape
const & s, T
const & initial = T())
1053 MultiArray<N, T, Alloc>(s, initial).swap(a);
1056 template <
class T,
class Alloc,
class Shape>
1057 void reshapeImpl(Matrix<T, Alloc> & a, Shape
const & s, T
const & initial = T())
1059 Matrix<T, Alloc>(s, initial).swap(a);
1063 template <
unsigned int N,
class T,
class Str
ide>
1064 inline typename MultiArrayShape<N>::type
1065 shapeOf(MultiArrayView<N, T, Stride>
const & a)
1070 template <
class T,
int N>
1072 shapeOf(TinyVector<T, N>
const &)
1077 template <
class T,
class NEXT>
1078 inline CoupledHandle<T, NEXT>
const &
1079 shapeOf(CoupledHandle<T, NEXT>
const & t)
1084 #define VIGRA_SHAPE_OF(type) \
1091 VIGRA_SHAPE_OF(
unsigned char)
1092 VIGRA_SHAPE_OF(
signed char)
1093 VIGRA_SHAPE_OF(
unsigned short)
1094 VIGRA_SHAPE_OF(
short)
1095 VIGRA_SHAPE_OF(
unsigned int)
1097 VIGRA_SHAPE_OF(
unsigned long)
1098 VIGRA_SHAPE_OF(
long)
1099 VIGRA_SHAPE_OF(
unsigned long long)
1100 VIGRA_SHAPE_OF(
long long)
1101 VIGRA_SHAPE_OF(
float)
1102 VIGRA_SHAPE_OF(
double)
1103 VIGRA_SHAPE_OF(
long double)
1105 #undef VIGRA_SHAPE_OF
1114 template <
class T,
class GlobalAccumulators,
class RegionAccumulators>
1115 struct LabelDispatch
1117 typedef LabelDispatchTag Tag;
1118 typedef GlobalAccumulators GlobalAccumulatorChain;
1119 typedef RegionAccumulators RegionAccumulatorChain;
1120 typedef typename LookupTag<AccumulatorEnd, RegionAccumulatorChain>::type::AccumulatorFlags ActiveFlagsType;
1121 typedef ArrayVector<RegionAccumulatorChain> RegionAccumulatorArray;
1123 typedef LabelDispatch type;
1124 typedef LabelDispatch & reference;
1125 typedef LabelDispatch
const & const_reference;
1126 typedef GlobalAccumulatorChain InternalBaseType;
1128 typedef T
const & argument_type;
1129 typedef argument_type first_argument_type;
1130 typedef double second_argument_type;
1131 typedef RegionAccumulatorChain & result_type;
1133 static const int index = GlobalAccumulatorChain::index + 1;
1135 GlobalAccumulatorChain next_;
1136 RegionAccumulatorArray regions_;
1137 HistogramOptions region_histogram_options_;
1139 ActiveFlagsType active_region_accumulators_;
1141 template <
class IndexDefinition,
class TagFound=
typename IndexDefinition::Tag>
1142 struct LabelIndexSelector
1144 static const int value = 2;
1146 template <
class U,
class NEXT>
1153 template <
class IndexDefinition>
1154 struct LabelIndexSelector<IndexDefinition, LabelArgTag>
1156 static const int value = IndexDefinition::value;
1158 template <
class U,
class NEXT>
1165 template <
class TAG>
1168 typedef typename LookupTag<TAG, type>::type TargetAccumulator;
1170 static void activate(GlobalAccumulatorChain & globals, RegionAccumulatorArray & regions,
1171 ActiveFlagsType & flags)
1173 TargetAccumulator::template activateImpl<LabelDispatch>(
1174 flags, getAccumulator<AccumulatorEnd>(globals).active_accumulators_);
1175 for(
unsigned int k=0; k<regions.size(); ++k)
1176 getAccumulator<AccumulatorEnd>(regions[k]).active_accumulators_ = flags;
1179 static bool isActive(GlobalAccumulatorChain
const &, ActiveFlagsType
const & flags)
1181 return TargetAccumulator::isActiveImpl(flags);
1185 template <
class TAG>
1186 struct ActivateImpl<Global<TAG> >
1188 static void activate(GlobalAccumulatorChain & globals, RegionAccumulatorArray &, ActiveFlagsType &)
1190 LookupTag<TAG, GlobalAccumulatorChain>::type::activateImpl(getAccumulator<AccumulatorEnd>(globals).active_accumulators_);
1193 static bool isActive(GlobalAccumulatorChain
const & globals, ActiveFlagsType
const &)
1195 return LookupTag<TAG, GlobalAccumulatorChain>::type::isActiveImpl(getAccumulator<AccumulatorEnd>(globals).active_accumulators_);
1199 template <
int INDEX>
1200 struct ActivateImpl<LabelArg<INDEX> >
1202 static void activate(GlobalAccumulatorChain &, RegionAccumulatorArray &, ActiveFlagsType &)
1205 static bool isActive(GlobalAccumulatorChain
const & globals, ActiveFlagsType
const &)
1207 return getAccumulator<LabelArg<INDEX> >(globals).
isActive();
1211 typedef typename LookupTag<LabelArgTag, GlobalAccumulatorChain>::type FindLabelIndex;
1216 region_histogram_options_(),
1218 active_region_accumulators_()
1221 LabelDispatch(LabelDispatch
const & o)
1223 regions_(o.regions_),
1224 region_histogram_options_(o.region_histogram_options_),
1225 ignore_label_(o.ignore_label_),
1226 active_region_accumulators_(o.active_region_accumulators_)
1228 for(
unsigned int k=0; k<regions_.size(); ++k)
1230 getAccumulator<AccumulatorEnd>(regions_[k]).setGlobalAccumulator(&next_);
1239 void setMaxRegionLabel(
unsigned maxlabel)
1243 unsigned int oldSize = regions_.size();
1244 regions_.resize(maxlabel + 1);
1245 for(
unsigned int k=oldSize; k<regions_.size(); ++k)
1247 getAccumulator<AccumulatorEnd>(regions_[k]).setGlobalAccumulator(&next_);
1248 getAccumulator<AccumulatorEnd>(regions_[k]).active_accumulators_ = active_region_accumulators_;
1249 regions_[k].applyHistogramOptions(region_histogram_options_);
1258 void applyHistogramOptions(HistogramOptions
const & options)
1260 applyHistogramOptions(options, options);
1263 void applyHistogramOptions(HistogramOptions
const & regionoptions, HistogramOptions
const & globaloptions)
1265 region_histogram_options_ = regionoptions;
1266 next_.applyHistogramOptions(globaloptions);
1270 void resize(U
const & t)
1272 if(regions_.size() == 0)
1274 static const int labelIndex = LabelIndexSelector<FindLabelIndex>::value;
1275 typedef typename CoupledHandleCast<labelIndex, T>::type LabelHandle;
1276 typedef typename LabelHandle::value_type LabelType;
1277 typedef MultiArrayView<LabelHandle::dimensions, LabelType, StridedArrayTag> LabelArray;
1278 LabelArray labelArray(t.shape(), cast<labelIndex>(t).strides(),
const_cast<LabelType *
>(cast<labelIndex>(t).ptr()));
1280 LabelType minimum, maximum;
1281 labelArray.minmax(&minimum, &maximum);
1282 setMaxRegionLabel(maximum);
1286 for(
unsigned int k=0; k<regions_.size(); ++k)
1287 regions_[k].resize(t);
1290 template <
unsigned N>
1291 void pass(T
const & t)
1293 if(LabelIndexSelector<FindLabelIndex>::exec(t) != ignore_label_)
1295 next_.template pass<N>(t);
1296 regions_[LabelIndexSelector<FindLabelIndex>::exec(t)].template pass<N>(t);
1300 template <
unsigned N>
1301 void pass(T
const & t,
double weight)
1303 if(LabelIndexSelector<FindLabelIndex>::exec(t) != ignore_label_)
1305 next_.template pass<N>(t, weight);
1306 regions_[LabelIndexSelector<FindLabelIndex>::exec(t)].template pass<N>(t, weight);
1310 static unsigned int passesRequired()
1312 return std::max(GlobalAccumulatorChain::passesRequired(), RegionAccumulatorChain::passesRequired());
1315 unsigned int passesRequiredDynamic()
const
1317 return std::max(GlobalAccumulatorChain::passesRequired(getAccumulator<AccumulatorEnd>(next_).active_accumulators_),
1318 RegionAccumulatorChain::passesRequired(active_region_accumulators_));
1325 active_region_accumulators_.clear();
1326 RegionAccumulatorArray().swap(regions_);
1332 template <
class TAG>
1335 ActivateImpl<TAG>::activate(next_, regions_, active_region_accumulators_);
1340 getAccumulator<AccumulatorEnd>(next_).active_accumulators_.set();
1341 active_region_accumulators_.set();
1342 for(
unsigned int k=0; k<regions_.size(); ++k)
1343 getAccumulator<AccumulatorEnd>(regions_[k]).active_accumulators_.set();
1346 template <
class TAG>
1349 return ActivateImpl<TAG>::isActive(next_, active_region_accumulators_);
1352 void merge(LabelDispatch
const & o)
1354 for(
unsigned int k=0; k<regions_.size(); ++k)
1355 regions_[k].merge(o.regions_[k]);
1356 next_.merge(o.next_);
1359 void merge(
unsigned i,
unsigned j)
1361 regions_[i].merge(regions_[j]);
1362 regions_[j].reset();
1363 getAccumulator<AccumulatorEnd>(regions_[j]).active_accumulators_ = active_region_accumulators_;
1366 template <
class ArrayLike>
1367 void merge(LabelDispatch
const & o, ArrayLike
const & labelMapping)
1369 MultiArrayIndex newMaxLabel = std::max<MultiArrayIndex>(maxRegionLabel(), *
argMax(labelMapping.begin(), labelMapping.end()));
1370 setMaxRegionLabel(newMaxLabel);
1371 for(
unsigned int k=0; k<labelMapping.size(); ++k)
1372 regions_[labelMapping[k]].merge(o.regions_[k]);
1373 next_.merge(o.next_);
1377 template <
class TargetTag,
class TagList>
1380 template <
class TargetTag,
class HEAD,
class TAIL>
1381 struct FindNextTag<TargetTag, TypeList<HEAD, TAIL> >
1383 typedef typename FindNextTag<TargetTag, TAIL>::type type;
1386 template <
class TargetTag,
class TAIL>
1387 struct FindNextTag<TargetTag, TypeList<TargetTag, TAIL> >
1389 typedef typename TAIL::Head type;
1392 template <
class TargetTag>
1393 struct FindNextTag<TargetTag, TypeList<TargetTag, void> >
1398 template <
class TargetTag>
1399 struct FindNextTag<TargetTag, void>
1405 template <
class TAG,
class CONFIG,
unsigned LEVEL=0>
1406 struct AccumulatorFactory
1408 typedef typename FindNextTag<TAG, typename CONFIG::TagList>::type NextTag;
1409 typedef typename AccumulatorFactory<NextTag, CONFIG, LEVEL+1>::type NextType;
1410 typedef typename CONFIG::InputType InputType;
1421 template <
class T,
class NEXT>
1422 struct ConfigureTag<CoupledHandle<T, NEXT> >
1424 typedef typename StandardizeTag<DataFromHandle<TAG> >::type WrappedTag;
1425 typedef typename IfBool<(!HasModifierPriority<WrappedTag, WeightingPriority>::value && ShouldBeWeighted<WrappedTag>::value),
1426 Weighted<WrappedTag>, WrappedTag>::type type;
1429 typedef typename ConfigureTag<InputType>::type UseTag;
1433 struct AccumulatorBase
1435 typedef AccumulatorBase ThisType;
1437 typedef NextType InternalBaseType;
1438 typedef InputType input_type;
1439 typedef input_type
const & argument_type;
1440 typedef argument_type first_argument_type;
1441 typedef double second_argument_type;
1442 typedef void result_type;
1444 static const unsigned int workInPass = 1;
1445 static const int index = InternalBaseType::index + 1;
1447 InternalBaseType next_;
1449 static std::string name()
1454 template <
class ActiveFlags>
1455 static void activateImpl(ActiveFlags & flags)
1457 flags.template set<index>();
1458 typedef typename StandardizeDependencies<Tag>::type StdDeps;
1459 detail::ActivateDependencies<StdDeps>::template exec<ThisType>(flags);
1462 template <
class Accu,
class ActiveFlags,
class GlobalFlags>
1463 static void activateImpl(ActiveFlags & flags, GlobalFlags & gflags)
1465 flags.template set<index>();
1466 typedef typename StandardizeDependencies<Tag>::type StdDeps;
1467 detail::ActivateDependencies<StdDeps>::template exec<Accu>(flags, gflags);
1470 template <
class ActiveFlags>
1471 static bool isActiveImpl(ActiveFlags & flags)
1473 return flags.template test<index>();
1476 void setDirty()
const
1478 next_.template setDirtyImpl<index>();
1481 template <
int INDEX>
1482 void setDirtyImpl()
const
1484 next_.template setDirtyImpl<INDEX>();
1487 void setClean()
const
1489 next_.template setCleanImpl<index>();
1492 template <
int INDEX>
1493 void setCleanImpl()
const
1495 next_.template setCleanImpl<INDEX>();
1498 bool isDirty()
const
1500 return next_.template isDirtyImpl<index>();
1503 template <
int INDEX>
1504 bool isDirtyImpl()
const
1506 return next_.template isDirtyImpl<INDEX>();
1512 template <
class Shape>
1513 void reshape(Shape
const &)
1520 void update(U
const &)
1524 void update(U
const &,
double)
1527 template <
class TargetTag>
1528 typename LookupDependency<TargetTag, ThisType>::result_type
1529 call_getDependency()
const
1531 return getDependency<TargetTag>(*this);
1536 typedef typename UseTag::template Impl<InputType, AccumulatorBase> AccumulatorImpl;
1543 :
public AccumulatorImpl
1545 typedef Accumulator type;
1546 typedef Accumulator & reference;
1547 typedef Accumulator
const & const_reference;
1548 typedef AccumulatorImpl A;
1550 static const unsigned int workInPass = A::workInPass;
1551 static const bool allowRuntimeActivation = CONFIG::allowRuntimeActivation;
1554 void resize(T
const & t)
1556 this->next_.resize(t);
1557 DecoratorImpl<Accumulator, workInPass, allowRuntimeActivation>::resize(*
this, t);
1562 this->next_.reset();
1566 typename A::result_type
get()
const
1571 template <
unsigned N,
class T>
1572 void pass(T
const & t)
1574 this->next_.template pass<N>(t);
1575 DecoratorImpl<Accumulator, N, allowRuntimeActivation>::exec(*
this, t);
1578 template <
unsigned N,
class T>
1579 void pass(T
const & t,
double weight)
1581 this->next_.template pass<N>(t, weight);
1582 DecoratorImpl<Accumulator, N, allowRuntimeActivation>::exec(*
this, t, weight);
1585 void merge(Accumulator
const & o)
1587 DecoratorImpl<Accumulator, Accumulator::workInPass, allowRuntimeActivation>::merge(*
this, o);
1588 this->next_.merge(o.next_);
1591 void applyHistogramOptions(HistogramOptions
const & options)
1593 DecoratorImpl<Accumulator, workInPass, allowRuntimeActivation>::applyHistogramOptions(*
this, options);
1594 this->next_.applyHistogramOptions(options);
1597 static unsigned int passesRequired()
1599 return DecoratorImpl<Accumulator, workInPass, allowRuntimeActivation>::passesRequired();
1602 template <
class ActiveFlags>
1603 static unsigned int passesRequired(ActiveFlags
const & flags)
1605 return DecoratorImpl<Accumulator, workInPass, allowRuntimeActivation>::passesRequired(flags);
1609 typedef Accumulator type;
1612 template <
class CONFIG,
unsigned LEVEL>
1613 struct AccumulatorFactory<void, CONFIG, LEVEL>
1615 typedef AccumulatorEndImpl<LEVEL, typename CONFIG::GlobalAccumulatorHandle> type;
1618 struct InvalidGlobalAccumulatorHandle
1620 typedef Error__Global_statistics_are_only_defined_for_AccumulatorChainArray type;
1622 InvalidGlobalAccumulatorHandle()
1626 type
const * pointer_;
1632 template <
class T,
class Selected,
bool dynamic=false,
class GlobalHandle=Inval
idGlobalAccumulatorHandle>
1633 struct ConfigureAccumulatorChain
1635 :
public ConfigureAccumulatorChain<T, typename AddDependencies<typename Selected::type>::type, dynamic>
1639 template <
class T,
class HEAD,
class TAIL,
bool dynamic,
class GlobalHandle>
1640 struct ConfigureAccumulatorChain<T, TypeList<HEAD, TAIL>, dynamic, GlobalHandle>
1642 typedef TypeList<HEAD, TAIL> TagList;
1643 typedef T InputType;
1644 static const bool allowRuntimeActivation = dynamic;
1645 typedef GlobalHandle GlobalAccumulatorHandle;
1647 typedef typename AccumulatorFactory<HEAD, ConfigureAccumulatorChain>::type type;
1650 template <
class T,
class Selected,
bool dynamic=false>
1651 struct ConfigureAccumulatorChainArray
1653 :
public ConfigureAccumulatorChainArray<T, typename AddDependencies<typename Selected::type>::type, dynamic>
1657 template <
class T,
class HEAD,
class TAIL,
bool dynamic>
1658 struct ConfigureAccumulatorChainArray<T, TypeList<HEAD, TAIL>, dynamic>
1660 typedef TypeList<HEAD, TAIL> TagList;
1661 typedef SeparateGlobalAndRegionTags<TagList> TagSeparator;
1662 typedef typename TagSeparator::GlobalTags GlobalTags;
1663 typedef typename TagSeparator::RegionTags RegionTags;
1664 typedef typename ConfigureAccumulatorChain<T, GlobalTags, dynamic>::type GlobalAccumulatorChain;
1666 struct GlobalAccumulatorHandle
1668 typedef GlobalAccumulatorChain type;
1670 GlobalAccumulatorHandle()
1674 type
const * pointer_;
1677 typedef typename ConfigureAccumulatorChain<T, RegionTags, dynamic, GlobalAccumulatorHandle>::type RegionAccumulatorChain;
1679 typedef LabelDispatch<T, GlobalAccumulatorChain, RegionAccumulatorChain> type;
1691 template <
class T,
class NEXT>
1692 class AccumulatorChainImpl
1695 typedef NEXT InternalBaseType;
1696 typedef AccumulatorBegin Tag;
1697 typedef typename InternalBaseType::argument_type argument_type;
1698 typedef typename InternalBaseType::first_argument_type first_argument_type;
1699 typedef typename InternalBaseType::second_argument_type second_argument_type;
1700 typedef void value_type;
1701 typedef typename InternalBaseType::result_type result_type;
1703 static const int staticSize = InternalBaseType::index;
1705 InternalBaseType next_;
1709 unsigned int current_pass_;
1711 AccumulatorChainImpl()
1717 void setHistogramOptions(HistogramOptions
const & options)
1719 next_.applyHistogramOptions(options);
1725 void setHistogramOptions(HistogramOptions
const & regionoptions, HistogramOptions
const & globaloptions)
1727 next_.applyHistogramOptions(regionoptions, globaloptions);
1732 void reset(
unsigned int reset_to_pass = 0)
1734 current_pass_ = reset_to_pass;
1735 if(reset_to_pass == 0)
1739 template <
unsigned N>
1740 void update(T
const & t)
1742 if(current_pass_ == N)
1744 next_.template pass<N>(t);
1746 else if(current_pass_ < N)
1750 next_.resize(detail::shapeOf(t));
1751 next_.template pass<N>(t);
1755 std::string message(
"AccumulatorChain::update(): cannot return to pass ");
1756 message << N <<
" after working on pass " << current_pass_ <<
".";
1757 vigra_precondition(
false, message);
1761 template <
unsigned N>
1762 void update(T
const & t,
double weight)
1764 if(current_pass_ == N)
1766 next_.template pass<N>(t, weight);
1768 else if(current_pass_ < N)
1772 next_.resize(detail::shapeOf(t));
1773 next_.template pass<N>(t, weight);
1777 std::string message(
"AccumulatorChain::update(): cannot return to pass ");
1778 message << N <<
" after working on pass " << current_pass_ <<
".";
1779 vigra_precondition(
false, message);
1785 void operator+=(AccumulatorChainImpl
const & o)
1792 void merge(AccumulatorChainImpl
const & o)
1794 next_.merge(o.next_);
1797 result_type operator()()
const
1802 void operator()(T
const & t)
1807 void operator()(T
const & t,
double weight)
1809 update<1>(t, weight);
1812 void updatePass2(T
const & t)
1817 void updatePass2(T
const & t,
double weight)
1819 update<2>(t, weight);
1824 void updatePassN(T
const & t,
unsigned int N)
1828 case 1: update<1>(t);
break;
1829 case 2: update<2>(t);
break;
1830 case 3: update<3>(t);
break;
1831 case 4: update<4>(t);
break;
1832 case 5: update<5>(t);
break;
1834 vigra_precondition(
false,
1835 "AccumulatorChain::updatePassN(): 0 < N < 6 required.");
1841 void updatePassN(T
const & t,
double weight,
unsigned int N)
1845 case 1: update<1>(t, weight);
break;
1846 case 2: update<2>(t, weight);
break;
1847 case 3: update<3>(t, weight);
break;
1848 case 4: update<4>(t, weight);
break;
1849 case 5: update<5>(t, weight);
break;
1851 vigra_precondition(
false,
1852 "AccumulatorChain::updatePassN(): 0 < N < 6 required.");
1858 unsigned int passesRequired()
const
1860 return InternalBaseType::passesRequired();
1895 template <
class T,
class Selected,
bool dynamic=false>
1898 :
public AccumulatorChainImpl<T, typename detail::ConfigureAccumulatorChain<T, Selected, dynamic>::type>
1903 typedef typename detail::ConfigureAccumulatorChain<T, Selected, dynamic>::TagList AccumulatorTags;
1907 template <
class U,
int N>
1910 vigra_precondition(this->current_pass_ == 0,
1911 "AccumulatorChain::reshape(): cannot reshape after seeing data. Call AccumulatorChain::reset() first.");
1912 this->next_.resize(s);
1913 this->current_pass_ = 1;
1925 #ifdef DOXYGEN // hide AccumulatorChainImpl from documentation
1932 void reset(
unsigned int reset_to_pass = 0);
1935 void operator+=(AccumulatorChainImpl
const & o);
1939 void merge(AccumulatorChainImpl
const & o);
1947 void updatePassN(T
const & t,
double weight,
unsigned int N);
1959 detail::CollectAccumulatorNames<AccumulatorTags>::exec(n);
1995 template <
class T,
class Selected>
2001 typedef typename DynamicAccumulatorChain::AccumulatorTags AccumulatorTags;
2007 vigra_precondition(activateImpl(tag),
2008 std::string(
"DynamicAccumulatorChain::activate(): Tag '") + tag +
"' not found.");
2013 template <
class TAG>
2016 LookupTag<TAG, DynamicAccumulatorChain>::type::activateImpl(getAccumulator<AccumulatorEnd>(*this).active_accumulators_);
2023 getAccumulator<AccumulatorEnd>(*this).active_accumulators_.set();
2029 detail::TagIsActive_Visitor v;
2030 vigra_precondition(isActiveImpl(tag, v),
2031 std::string(
"DynamicAccumulatorChain::isActive(): Tag '") + tag +
"' not found.");
2037 template <
class TAG>
2040 return LookupTag<TAG, DynamicAccumulatorChain>::type::isActiveImpl(getAccumulator<AccumulatorEnd>(*this).active_accumulators_);
2058 return InternalBaseType::passesRequired(getAccumulator<AccumulatorEnd>(*this).active_accumulators_);
2063 bool activateImpl(std::string tag)
2065 return detail::ApplyVisitorToTag<AccumulatorTags>::exec(*
this,
2069 bool isActiveImpl(std::string tag, detail::TagIsActive_Visitor & v)
const
2071 return detail::ApplyVisitorToTag<AccumulatorTags>::exec(*
this,
normalizeString(tag), v);
2095 template <
class T,
class Selected,
bool dynamic=false>
2098 :
public AccumulatorChainImpl<T, typename detail::ConfigureAccumulatorChainArray<T, Selected, dynamic>::type>
2102 typedef typename detail::ConfigureAccumulatorChainArray<T, Selected, dynamic> Creator;
2103 typedef typename Creator::TagList AccumulatorTags;
2104 typedef typename Creator::GlobalTags GlobalTags;
2105 typedef typename Creator::RegionTags RegionTags;
2111 this->next_.ignoreLabel(l);
2118 this->next_.setMaxRegionLabel(label);
2125 return this->next_.maxRegionLabel();
2132 return this->next_.regions_.size();
2140 "AccumulatorChainArray::merge(): region labels out of range.");
2141 this->next_.merge(i, j);
2151 "AccumulatorChainArray::merge(): maxRegionLabel must be equal.");
2152 this->next_.merge(o.next_);
2157 template <
class ArrayLike>
2160 vigra_precondition(labelMapping.size() == o.
regionCount(),
2161 "AccumulatorChainArray::merge(): labelMapping.size() must match regionCount() of RHS.");
2162 this->next_.merge(o.next_, labelMapping);
2174 #ifdef DOXYGEN // hide AccumulatorChainImpl from documentation
2184 void reset(
unsigned int reset_to_pass = 0);
2187 void operator+=(AccumulatorChainImpl
const & o);
2193 void updatePassN(T
const & t,
double weight,
unsigned int N);
2203 detail::CollectAccumulatorNames<AccumulatorTags>::exec(n);
2230 template <
class T,
class Selected>
2235 typedef typename DynamicAccumulatorChainArray::AccumulatorTags AccumulatorTags;
2240 vigra_precondition(activateImpl(tag),
2241 std::string(
"DynamicAccumulatorChainArray::activate(): Tag '") + tag +
"' not found.");
2245 template <
class TAG>
2248 this->next_.template activate<TAG>();
2254 this->next_.activateAll();
2261 detail::TagIsActive_Visitor v;
2262 vigra_precondition(isActiveImpl(tag, v),
2263 std::string(
"DynamicAccumulatorChainArray::isActive(): Tag '") + tag +
"' not found.");
2269 template <
class TAG>
2272 return this->next_.template isActive<TAG>();
2288 return this->next_.passesRequiredDynamic();
2293 bool activateImpl(std::string tag)
2295 return detail::ApplyVisitorToTag<AccumulatorTags>::exec(this->next_,
2299 bool isActiveImpl(std::string tag, detail::TagIsActive_Visitor & v)
const
2301 return detail::ApplyVisitorToTag<AccumulatorTags>::exec(this->next_,
normalizeString(tag), v);
2311 template <
class TAG>
2312 struct Error__Attempt_to_access_inactive_statistic;
2319 template <
class TAG,
class A,
class FromTag=
typename A::Tag>
2320 struct LookupTagImpl
2322 :
public LookupTagImpl<TAG, typename A::InternalBaseType>
2327 template <
class TAG,
class A,
class FromTag>
2328 struct LookupTagImpl<TAG, A const, FromTag>
2329 :
public LookupTagImpl<TAG, A>
2331 typedef typename LookupTagImpl<TAG, A>::type
const & reference;
2332 typedef typename LookupTagImpl<TAG, A>::type
const * pointer;
2336 template <
class TAG,
class A>
2337 struct LookupTagImpl<TAG, A, TAG>
2341 typedef A & reference;
2342 typedef A * pointer;
2343 typedef typename A::value_type value_type;
2344 typedef typename A::result_type result_type;
2348 template <
class TAG,
class A>
2349 struct LookupTagImpl<TAG, A const, TAG>
2350 :
public LookupTagImpl<TAG, A, TAG>
2352 typedef typename LookupTagImpl<TAG, A, TAG>::type
const & reference;
2353 typedef typename LookupTagImpl<TAG, A, TAG>::type
const * pointer;
2358 template <
class TAG,
class A>
2359 struct LookupTagImpl<TAG, A, AccumulatorEnd>
2363 typedef A & reference;
2364 typedef A * pointer;
2365 typedef Error__Attempt_to_access_inactive_statistic<TAG> value_type;
2366 typedef Error__Attempt_to_access_inactive_statistic<TAG> result_type;
2371 struct LookupTagImpl<AccumulatorEnd, A, AccumulatorEnd>
2373 typedef AccumulatorEnd Tag;
2375 typedef A & reference;
2376 typedef A * pointer;
2377 typedef void value_type;
2378 typedef void result_type;
2384 template <
class TAG,
class A>
2385 struct LookupTagImpl<Global<TAG>, A, AccumulatorEnd>
2386 :
public LookupTagImpl<TAG, typename A::GlobalAccumulatorType>
2388 typedef Global<TAG> Tag;
2393 template <
class TAG,
class A>
2394 struct LookupTagImpl<TAG, A, LabelDispatchTag>
2395 :
public LookupTagImpl<TAG, typename A::RegionAccumulatorChain>
2401 template <
class TAG,
class A>
2402 struct LookupTagImpl<Global<TAG>, A, LabelDispatchTag>
2403 :
public LookupTagImpl<TAG, typename A::GlobalAccumulatorChain>
2405 typedef Global<TAG> Tag;
2410 struct LookupTagImpl<LabelDispatchTag, A, LabelDispatchTag>
2412 typedef LabelDispatchTag Tag;
2414 typedef A & reference;
2415 typedef A * pointer;
2416 typedef void value_type;
2417 typedef void result_type;
2423 template <
class Tag,
class A>
2425 :
public detail::LookupTagImpl<typename StandardizeTag<Tag>::type, A>
2432 template <
class Tag,
class A,
class TargetTag>
2433 struct LookupDependency
2434 :
public detail::LookupTagImpl<
2435 typename TransferModifiers<TargetTag, typename StandardizeTag<Tag>::type>::type, A>
2443 template <
class Tag,
class FromTag,
class reference>
2447 static reference exec(A & a)
2449 return CastImpl<Tag, typename A::InternalBaseType::Tag, reference>::exec(a.next_);
2455 return CastImpl<Tag, typename A::InternalBaseType::Tag, reference>::exec(a.next_, label);
2459 template <
class Tag,
class reference>
2460 struct CastImpl<Tag, Tag, reference>
2463 static reference exec(A & a)
2465 return const_cast<reference
>(a);
2471 vigra_precondition(
false,
2472 "getAccumulator(): region accumulators can only be queried for AccumulatorChainArray.");
2477 template <
class Tag,
class reference>
2478 struct CastImpl<Tag, AccumulatorEnd, reference>
2481 static reference exec(A & a)
2493 template <
class Tag,
class reference>
2494 struct CastImpl<Global<Tag>, AccumulatorEnd, reference>
2497 static reference exec(A & a)
2499 return CastImpl<Tag, typename A::GlobalAccumulatorType::Tag, reference>::exec(*a.globalAccumulator_.pointer_);
2503 template <
class reference>
2504 struct CastImpl<AccumulatorEnd, AccumulatorEnd, reference>
2507 static reference exec(A & a)
2519 template <
class Tag,
class reference>
2520 struct CastImpl<Tag, LabelDispatchTag, reference>
2523 static reference exec(A & a)
2525 vigra_precondition(
false,
2526 "getAccumulator(): a region label is required when a region accumulator is queried.");
2527 return CastImpl<Tag, typename A::RegionAccumulatorChain::Tag, reference>::exec(a.regions_[0]);
2533 return CastImpl<Tag, typename A::RegionAccumulatorChain::Tag, reference>::exec(a.regions_[label]);
2537 template <
class Tag,
class reference>
2538 struct CastImpl<Global<Tag>, LabelDispatchTag, reference>
2541 static reference exec(A & a)
2543 return CastImpl<Tag, typename A::GlobalAccumulatorChain::Tag, reference>::exec(a.next_);
2547 template <
class reference>
2548 struct CastImpl<LabelDispatchTag, LabelDispatchTag, reference>
2551 static reference exec(A & a)
2584 template <
class TAG,
class A>
2585 inline typename LookupTag<TAG, A>::reference
2588 typedef typename LookupTag<TAG, A>::Tag StandardizedTag;
2589 typedef typename LookupTag<TAG, A>::reference reference;
2590 return detail::CastImpl<StandardizedTag, typename A::Tag, reference>::exec(a);
2596 template <
class TAG,
class A>
2597 inline typename LookupTag<TAG, A>::reference
2600 typedef typename LookupTag<TAG, A>::Tag StandardizedTag;
2601 typedef typename LookupTag<TAG, A>::reference reference;
2602 return detail::CastImpl<StandardizedTag, typename A::Tag, reference>::exec(a, label);
2616 template <
class TAG,
class A>
2617 inline typename LookupTag<TAG, A>::result_type
2620 return getAccumulator<TAG>(a).
get();
2644 template <
class TAG,
class A>
2645 inline typename LookupTag<TAG, A>::result_type
2648 return getAccumulator<TAG>(a, label).
get();
2655 template <
class TAG,
class A>
2656 inline typename LookupDependency<TAG, A>::result_type
2657 getDependency(A
const & a)
2659 typedef typename LookupDependency<TAG, A>::Tag StandardizedTag;
2660 typedef typename LookupDependency<TAG, A>::reference reference;
2661 return detail::CastImpl<StandardizedTag, typename A::Tag, reference>::exec(a)();
2668 template <
class Tag,
class A>
2672 a.template activate<Tag>();
2679 template <
class Tag,
class A>
2683 return a.template isActive<Tag>();
2711 template <
class ITERATOR,
class ACCUMULATOR>
2714 for(
unsigned int k=1; k <= a.passesRequired(); ++k)
2715 for(ITERATOR i=start; i < end; ++i)
2716 a.updatePassN(*i, k);
2726 struct AccumulatorResultTraits
2729 typedef T element_type;
2730 typedef double element_promote_type;
2731 typedef T MinmaxType;
2732 typedef element_promote_type SumType;
2733 typedef element_promote_type FlatCovarianceType;
2734 typedef element_promote_type CovarianceType;
2737 template <
class T,
int N>
2738 struct AccumulatorResultTraits<TinyVector<T, N> >
2740 typedef TinyVector<T, N> type;
2741 typedef T element_type;
2742 typedef double element_promote_type;
2743 typedef TinyVector<T, N> MinmaxType;
2744 typedef TinyVector<element_promote_type, N> SumType;
2745 typedef TinyVector<element_promote_type, N*(N+1)/2> FlatCovarianceType;
2746 typedef Matrix<element_promote_type> CovarianceType;
2750 template <
class T,
unsigned int RED_IDX,
unsigned int GREEN_IDX,
unsigned int BLUE_IDX>
2751 struct AccumulatorResultTraits<RGBValue<T, RED_IDX, GREEN_IDX, BLUE_IDX> >
2753 typedef RGBValue<T> type;
2754 typedef T element_type;
2755 typedef double element_promote_type;
2756 typedef RGBValue<T> MinmaxType;
2757 typedef RGBValue<element_promote_type> SumType;
2758 typedef TinyVector<element_promote_type, 3*(3+1)/2> FlatCovarianceType;
2759 typedef Matrix<element_promote_type> CovarianceType;
2764 template <
unsigned int N,
class T,
class Str
ide>
2765 struct AccumulatorResultTraits<MultiArrayView<N, T, Stride> >
2767 typedef MultiArrayView<N, T, Stride> type;
2768 typedef T element_type;
2769 typedef double element_promote_type;
2770 typedef MultiArray<N, T> MinmaxType;
2771 typedef MultiArray<N, element_promote_type> SumType;
2772 typedef MultiArray<1, element_promote_type> FlatCovarianceType;
2773 typedef Matrix<element_promote_type> CovarianceType;
2776 template <
unsigned int N,
class T,
class Alloc>
2777 struct AccumulatorResultTraits<MultiArray<N, T, Alloc> >
2779 typedef MultiArrayView<N, T, Alloc> type;
2780 typedef T element_type;
2781 typedef double element_promote_type;
2782 typedef MultiArray<N, T> MinmaxType;
2783 typedef MultiArray<N, element_promote_type> SumType;
2784 typedef MultiArray<1, element_promote_type> FlatCovarianceType;
2785 typedef Matrix<element_promote_type> CovarianceType;
2798 template <
class TAG>
2802 typedef typename StandardizeTag<TAG>::type TargetTag;
2803 typedef typename TargetTag::Dependencies Dependencies;
2805 static std::string
const & name()
2807 static const std::string n = std::string(
"Global<") + TargetTag::name() +
" >";
2816 template <
int INDEX>
2820 typedef Select<> Dependencies;
2822 static std::string
const & name()
2824 static const std::string n = std::string(
"DataArg<") +
asString(INDEX) +
"> (internal)";
2828 template <
class T,
class BASE>
2832 typedef DataArgTag Tag;
2833 typedef void value_type;
2834 typedef void result_type;
2836 static const int value = INDEX;
2837 static const unsigned int workInPass = 0;
2842 template <
class TAG>
2843 class DataFromHandle
2846 typedef typename StandardizeTag<TAG>::type TargetTag;
2847 typedef typename TargetTag::Dependencies Dependencies;
2849 static std::string
const & name()
2851 static const std::string n = std::string(
"DataFromHandle<") + TargetTag::name() +
" > (internal)";
2855 template <
class IndexDefinition,
class TagFound=
typename IndexDefinition::Tag>
2856 struct DataIndexSelector
2858 static const int value = 1;
2860 template <
class U,
class NEXT>
2861 static typename CoupledHandleCast<value, CoupledHandle<U, NEXT> >::type::const_reference
2862 exec(CoupledHandle<U, NEXT>
const & t)
2864 return get<value>(t);
2868 template <
class IndexDefinition>
2869 struct DataIndexSelector<IndexDefinition, DataArgTag>
2871 static const int value = IndexDefinition::value;
2873 template <
class U,
class NEXT>
2874 static typename CoupledHandleCast<value, CoupledHandle<U, NEXT> >::type::const_reference
2875 exec(CoupledHandle<U, NEXT>
const & t)
2877 return get<value>(t);
2881 template <
class T,
class BASE>
2882 struct SelectInputType
2884 typedef typename LookupTag<DataArgTag, BASE>::type FindDataIndex;
2885 typedef DataIndexSelector<FindDataIndex> DataIndex;
2886 typedef typename CoupledHandleCast<DataIndex::value, T>::type::value_type type;
2889 template <
class T,
class BASE>
2891 :
public TargetTag::template Impl<typename SelectInputType<T, BASE>::type, BASE>
2893 typedef SelectInputType<T, BASE> InputTypeSelector;
2894 typedef typename InputTypeSelector::DataIndex DataIndex;
2895 typedef typename InputTypeSelector::type input_type;
2896 typedef input_type
const & argument_type;
2897 typedef argument_type first_argument_type;
2899 typedef typename TargetTag::template Impl<input_type, BASE> ImplType;
2901 using ImplType::reshape;
2903 template <
class U,
class NEXT>
2904 void reshape(CoupledHandle<U, NEXT>
const & t)
2906 ImplType::reshape(detail::shapeOf(DataIndex::exec(t)));
2909 template <
class U,
class NEXT>
2910 void update(CoupledHandle<U, NEXT>
const & t)
2912 ImplType::update(DataIndex::exec(t));
2915 template <
class U,
class NEXT>
2916 void update(CoupledHandle<U, NEXT>
const & t,
double weight)
2918 ImplType::update(DataIndex::exec(t), weight);
2927 template <
class TAG>
2931 typedef typename StandardizeTag<TAG>::type TargetTag;
2932 typedef typename TargetTag::Dependencies Dependencies;
2934 static std::string
const & name()
2936 static const std::string n = std::string(
"Coord<") + TargetTag::name() +
" >";
2940 template <
class IndexDefinition,
class TagFound=
typename IndexDefinition::Tag>
2941 struct CoordIndexSelector
2943 static const int value = 0;
2945 template <
class U,
class NEXT>
2946 static typename CoupledHandleCast<value, CoupledHandle<U, NEXT> >::type::const_reference
2947 exec(CoupledHandle<U, NEXT>
const & t)
2949 return get<value>(t);
2953 template <
class IndexDefinition>
2954 struct CoordIndexSelector<IndexDefinition, CoordArgTag>
2956 static const int value = IndexDefinition::value;
2958 template <
class U,
class NEXT>
2959 static typename CoupledHandleCast<value, CoupledHandle<U, NEXT> >::type::const_reference
2960 exec(CoupledHandle<U, NEXT>
const & t)
2962 return get<value>(t);
2966 template <
class T,
class BASE>
2967 struct SelectInputType
2969 typedef typename LookupTag<CoordArgTag, BASE>::type FindDataIndex;
2970 typedef CoordIndexSelector<FindDataIndex> CoordIndex;
2971 typedef typename CoupledHandleCast<CoordIndex::value, T>::type::value_type type;
2974 template <
class T,
class BASE>
2976 :
public TargetTag::template Impl<typename SelectInputType<T, BASE>::type, BASE>
2978 typedef SelectInputType<T, BASE> InputTypeSelector;
2979 typedef typename InputTypeSelector::CoordIndex CoordIndex;
2980 typedef typename InputTypeSelector::type input_type;
2981 typedef input_type
const & argument_type;
2982 typedef argument_type first_argument_type;
2984 typedef typename TargetTag::template Impl<input_type, BASE> ImplType;
2986 using ImplType::reshape;
2988 template <
class U,
class NEXT>
2989 void reshape(CoupledHandle<U, NEXT>
const & t)
2991 ImplType::reshape(detail::shapeOf(CoordIndex::exec(t)));
2994 template <
class U,
class NEXT>
2995 void update(CoupledHandle<U, NEXT>
const & t)
2997 ImplType::update(CoordIndex::exec(t));
3000 template <
class U,
class NEXT>
3001 void update(CoupledHandle<U, NEXT>
const & t,
double weight)
3003 ImplType::update(CoordIndex::exec(t), weight);
3012 template <
int INDEX>
3016 typedef Select<> Dependencies;
3018 static std::string
const & name()
3020 static const std::string n = std::string(
"WeightArg<") +
asString(INDEX) +
"> (internal)";
3024 template <
class T,
class BASE>
3028 typedef WeightArgTag Tag;
3029 typedef void value_type;
3030 typedef void result_type;
3032 static const int value = INDEX;
3033 static const unsigned int workInPass = 0;
3039 template <
class TAG>
3043 typedef typename StandardizeTag<TAG>::type TargetTag;
3044 typedef typename TargetTag::Dependencies Dependencies;
3046 static std::string
const & name()
3048 static const std::string n = std::string(
"Weighted<") + TargetTag::name() +
" >";
3052 template <
class IndexDefinition,
class TagFound=
typename IndexDefinition::Tag>
3053 struct WeightIndexSelector
3055 template <
class U,
class NEXT>
3056 static double exec(CoupledHandle<U, NEXT>
const & t)
3062 template <
class IndexDefinition>
3063 struct WeightIndexSelector<IndexDefinition, WeightArgTag>
3065 template <
class U,
class NEXT>
3066 static double exec(CoupledHandle<U, NEXT>
const & t)
3068 return (
double)get<IndexDefinition::value>(t);
3072 template <
class T,
class BASE>
3074 :
public TargetTag::template Impl<T, BASE>
3076 typedef typename TargetTag::template Impl<T, BASE> ImplType;
3078 typedef typename LookupTag<WeightArgTag, BASE>::type FindWeightIndex;
3080 template <
class U,
class NEXT>
3081 void update(CoupledHandle<U, NEXT>
const & t)
3083 ImplType::update(t, WeightIndexSelector<FindWeightIndex>::exec(t));
3092 typedef Select<Mean> Dependencies;
3094 static std::string
const & name()
3096 static const std::string n(
"Centralize (internal)");
3100 template <
class U,
class BASE>
3104 static const unsigned int workInPass = 2;
3106 typedef typename AccumulatorResultTraits<U>::element_promote_type element_type;
3107 typedef typename AccumulatorResultTraits<U>::SumType value_type;
3108 typedef value_type
const & result_type;
3110 mutable value_type value_;
3118 value_ = element_type();
3121 template <
class Shape>
3122 void reshape(Shape
const & s)
3124 detail::reshapeImpl(value_, s);
3127 void update(U
const & t)
const
3129 using namespace vigra::multi_math;
3130 value_ = t - getDependency<Mean>(*this);
3133 void update(U
const & t,
double)
const
3138 result_type operator()(U
const & t)
const
3144 result_type operator()()
const
3155 template <
class TAG>
3159 typedef typename StandardizeTag<TAG>::type TargetTag;
3160 typedef Select<Centralize, typename TargetTag::Dependencies> Dependencies;
3162 static std::string
const & name()
3164 static const std::string n = std::string(
"Central<") + TargetTag::name() +
" >";
3168 template <
class U,
class BASE>
3170 :
public TargetTag::template Impl<typename AccumulatorResultTraits<U>::SumType, BASE>
3172 typedef typename TargetTag::template Impl<typename AccumulatorResultTraits<U>::SumType, BASE> ImplType;
3174 static const unsigned int workInPass = 2;
3178 vigra_precondition(
false,
3179 "Central<...>::operator+=(): not supported.");
3183 void update(T
const & t)
3185 ImplType::update(getDependency<Centralize>(*
this));
3189 void update(T
const & t,
double weight)
3191 ImplType::update(getDependency<Centralize>(*
this), weight);
3234 class PrincipalProjection
3237 typedef Select<Centralize, Principal<CoordinateSystem> > Dependencies;
3239 static std::string
const & name()
3241 static const std::string n(
"PrincipalProjection (internal)");
3245 template <
class U,
class BASE>
3249 static const unsigned int workInPass = 2;
3251 typedef typename AccumulatorResultTraits<U>::element_promote_type element_type;
3252 typedef typename AccumulatorResultTraits<U>::SumType value_type;
3253 typedef value_type
const & result_type;
3255 mutable value_type value_;
3263 value_ = element_type();
3266 template <
class Shape>
3267 void reshape(Shape
const & s)
3269 detail::reshapeImpl(value_, s);
3272 void update(U
const & t)
const
3274 for(
unsigned int k=0; k<t.size(); ++k)
3276 value_[k] = getDependency<Principal<CoordinateSystem> >(*this)(0, k)*getDependency<Centralize>(*
this)[0];
3277 for(
unsigned int d=1; d<t.size(); ++d)
3278 value_[k] += getDependency<Principal<CoordinateSystem> >(*
this)(d, k)*getDependency<Centralize>(*
this)[d];
3282 void update(U
const & t,
double)
const
3287 result_type operator()(U
const & t)
const
3289 getAccumulator<Centralize>(*this).update(t);
3294 result_type operator()()
const
3305 template <
class TAG>
3309 typedef typename StandardizeTag<TAG>::type TargetTag;
3310 typedef Select<PrincipalProjection, typename TargetTag::Dependencies> Dependencies;
3312 static std::string
const & name()
3314 static const std::string n = std::string(
"Principal<") + TargetTag::name() +
" >";
3318 template <
class U,
class BASE>
3320 :
public TargetTag::template Impl<typename AccumulatorResultTraits<U>::SumType, BASE>
3322 typedef typename TargetTag::template Impl<typename AccumulatorResultTraits<U>::SumType, BASE> ImplType;
3324 static const unsigned int workInPass = 2;
3328 vigra_precondition(
false,
3329 "Principal<...>::operator+=(): not supported.");
3333 void update(T
const & t)
3335 ImplType::update(getDependency<PrincipalProjection>(*
this));
3339 void update(T
const & t,
double weight)
3341 ImplType::update(getDependency<PrincipalProjection>(*
this), weight);
3378 static std::string
const & name()
3380 static const std::string n(
"CoordinateSystem");
3384 template <
class U,
class BASE>
3388 typedef double element_type;
3389 typedef Matrix<double> value_type;
3390 typedef value_type
const & result_type;
3400 value_ = element_type();
3403 template <
class Shape>
3404 void reshape(Shape
const & s)
3406 detail::reshapeImpl(value_, s);
3409 result_type operator()()
const
3416 template <
class BASE,
class T,
3417 class ElementType=
typename AccumulatorResultTraits<T>::element_promote_type,
3418 class SumType=
typename AccumulatorResultTraits<T>::SumType>
3422 typedef ElementType element_type;
3423 typedef SumType value_type;
3424 typedef value_type
const & result_type;
3434 value_ = element_type();
3437 template <
class Shape>
3438 void reshape(Shape
const & s)
3440 detail::reshapeImpl(value_, s);
3448 result_type operator()()
const
3459 typedef Select<> Dependencies;
3461 static std::string
const & name()
3463 static const std::string n(
"PowerSum<0>");
3467 template <
class T,
class BASE>
3469 :
public SumBaseImpl<BASE, T, double, double>
3471 void update(T
const & t)
3476 void update(T
const & t,
double weight)
3478 this->value_ += weight;
3488 typedef Select<> Dependencies;
3490 static std::string
const & name()
3492 static const std::string n(
"PowerSum<1>");
3496 template <
class U,
class BASE>
3498 :
public SumBaseImpl<BASE, U>
3500 void update(U
const & t)
3505 void update(U
const & t,
double weight)
3507 this->value_ += weight*t;
3516 template <
unsigned N>
3520 typedef Select<> Dependencies;
3522 static std::string
const & name()
3524 static const std::string n = std::string(
"PowerSum<") +
asString(N) +
">";
3528 template <
class U,
class BASE>
3530 :
public SumBaseImpl<BASE, U>
3532 void update(U
const & t)
3534 using namespace vigra::multi_math;
3535 this->value_ += pow(t, (
int)N);
3538 void update(U
const & t,
double weight)
3540 using namespace vigra::multi_math;
3541 this->value_ += weight*pow(t, (
int)N);
3547 class AbsPowerSum<1>
3550 typedef Select<> Dependencies;
3552 static std::string
const & name()
3554 static const std::string n(
"AbsPowerSum<1>");
3558 template <
class U,
class BASE>
3560 :
public SumBaseImpl<BASE, U>
3562 void update(U
const & t)
3564 using namespace vigra::multi_math;
3565 this->value_ +=
abs(t);
3568 void update(U
const & t,
double weight)
3570 using namespace vigra::multi_math;
3571 this->value_ += weight*
abs(t);
3580 template <
unsigned N>
3584 typedef Select<> Dependencies;
3586 static std::string
const & name()
3588 static const std::string n = std::string(
"AbsPowerSum<") +
asString(N) +
">";
3592 template <
class U,
class BASE>
3594 :
public SumBaseImpl<BASE, U>
3596 void update(U
const & t)
3598 using namespace vigra::multi_math;
3599 this->value_ += pow(
abs(t), (
int)N);
3602 void update(U
const & t,
double weight)
3604 using namespace vigra::multi_math;
3605 this->value_ += weight*pow(
abs(t), (
int)N);
3610 template <
class BASE,
class VALUE_TYPE,
class U>
3611 struct CachedResultBase
3614 typedef typename AccumulatorResultTraits<U>::element_type element_type;
3615 typedef VALUE_TYPE value_type;
3616 typedef value_type
const & result_type;
3618 mutable value_type value_;
3626 value_ = element_type();
3630 template <
class Shape>
3631 void reshape(Shape
const & s)
3633 detail::reshapeImpl(value_, s);
3641 void update(U
const &)
3646 void update(U
const &,
double)
3655 template <
class TAG>
3659 typedef typename StandardizeTag<TAG>::type TargetTag;
3660 typedef Select<TargetTag, Count> Dependencies;
3662 static std::string
const & name()
3664 static const std::string n = std::string(
"DivideByCount<") + TargetTag::name() +
" >";
3668 template <
class U,
class BASE>
3670 :
public CachedResultBase<BASE, typename LookupDependency<TargetTag, BASE>::value_type, U>
3672 typedef typename CachedResultBase<BASE, typename LookupDependency<TargetTag, BASE>::value_type, U>::result_type result_type;
3674 result_type operator()()
const
3678 using namespace multi_math;
3679 this->value_ = getDependency<TargetTag>(*this) / getDependency<Count>(*this);
3682 return this->value_;
3690 template <
class TAG>
3691 class DivideUnbiased
3694 typedef typename StandardizeTag<TAG>::type TargetTag;
3695 typedef Select<TargetTag, Count> Dependencies;
3697 static std::string
const & name()
3699 static const std::string n = std::string(
"DivideUnbiased<") + TargetTag::name() +
" >";
3703 template <
class U,
class BASE>
3707 typedef typename LookupDependency<TargetTag, BASE>::value_type value_type;
3708 typedef value_type result_type;
3710 result_type operator()()
const
3712 using namespace multi_math;
3713 return getDependency<TargetTag>(*this) / (getDependency<Count>(*this) - 1.0);
3721 template <
class TAG>
3722 class RootDivideByCount
3725 typedef typename StandardizeTag<DivideByCount<TAG> >::type TargetTag;
3726 typedef Select<TargetTag> Dependencies;
3728 static std::string
const & name()
3730 typedef typename StandardizeTag<TAG>::type InnerTag;
3731 static const std::string n = std::string(
"RootDivideByCount<") + InnerTag::name() +
" >";
3735 template <
class U,
class BASE>
3739 typedef typename LookupDependency<TargetTag, BASE>::value_type value_type;
3740 typedef value_type result_type;
3742 result_type operator()()
const
3744 using namespace multi_math;
3745 return sqrt(getDependency<TargetTag>(*
this));
3753 template <
class TAG>
3754 class RootDivideUnbiased
3757 typedef typename StandardizeTag<DivideUnbiased<TAG> >::type TargetTag;
3758 typedef Select<TargetTag> Dependencies;
3760 static std::string
const & name()
3762 typedef typename StandardizeTag<TAG>::type InnerTag;
3763 static const std::string n = std::string(
"RootDivideUnbiased<") + InnerTag::name() +
" >";
3767 template <
class U,
class BASE>
3771 typedef typename LookupDependency<TargetTag, BASE>::value_type value_type;
3772 typedef value_type result_type;
3774 result_type operator()()
const
3776 using namespace multi_math;
3777 return sqrt(getDependency<TargetTag>(*
this));
3790 static std::string
const & name()
3792 static const std::string n(
"Central<PowerSum<2> >");
3796 template <
class U,
class BASE>
3798 :
public SumBaseImpl<BASE, U>
3802 using namespace vigra::multi_math;
3803 double n1 = getDependency<Count>(*this), n2 = getDependency<Count>(o);
3806 this->value_ = o.value_;
3810 this->value_ += o.value_ + n1 * n2 / (n1 + n2) *
sq(getDependency<Mean>(*
this) - getDependency<Mean>(o));
3814 void update(U
const & t)
3816 double n = getDependency<Count>(*this);
3819 using namespace vigra::multi_math;
3820 this->value_ += n / (n - 1.0) *
sq(getDependency<Mean>(*
this) - t);
3824 void update(U
const & t,
double weight)
3826 double n = getDependency<Count>(*this);
3829 using namespace vigra::multi_math;
3830 this->value_ += n / (n - weight) *
sq(getDependency<Mean>(*
this) - t);
3844 static std::string
const & name()
3846 static const std::string n(
"Central<PowerSum<3> >");
3850 template <
class U,
class BASE>
3852 :
public SumBaseImpl<BASE, U>
3854 typedef typename SumBaseImpl<BASE, U>::value_type value_type;
3856 static const unsigned int workInPass = 2;
3862 using namespace vigra::multi_math;
3863 double n1 = getDependency<Count>(*this), n2 = getDependency<Count>(o);
3866 this->value_ = o.value_;
3871 double weight = n1 * n2 * (n1 - n2) /
sq(n);
3872 value_type delta = getDependency<Mean>(o) - getDependency<Mean>(*
this);
3873 this->value_ += o.value_ + weight * pow(delta, 3) +
3874 3.0 / n * delta * (n1 * getDependency<Sum2Tag>(o) - n2 * getDependency<Sum2Tag>(*
this));
3878 void update(U
const & t)
3880 using namespace vigra::multi_math;
3881 this->value_ += pow(getDependency<Centralize>(*
this), 3);
3884 void update(U
const & t,
double weight)
3886 using namespace vigra::multi_math;
3887 this->value_ += weight*pow(getDependency<Centralize>(*
this), 3);
3899 static std::string
const & name()
3901 static const std::string n(
"Central<PowerSum<4> >");
3905 template <
class U,
class BASE>
3907 :
public SumBaseImpl<BASE, U>
3909 typedef typename SumBaseImpl<BASE, U>::value_type value_type;
3911 static const unsigned int workInPass = 2;
3918 using namespace vigra::multi_math;
3919 double n1 = getDependency<Count>(*this), n2 = getDependency<Count>(o);
3922 this->value_ = o.value_;
3927 double n1_2 =
sq(n1);
3928 double n2_2 =
sq(n2);
3930 double weight = n1 * n2 * (n1_2 - n1*n2 + n2_2) / n_2 / n;
3931 value_type delta = getDependency<Mean>(o) - getDependency<Mean>(*
this);
3932 this->value_ += o.value_ + weight * pow(delta, 4) +
3933 6.0 / n_2 *
sq(delta) * (n1_2 * getDependency<Sum2Tag>(o) + n2_2 * getDependency<Sum2Tag>(*
this)) +
3934 4.0 / n * delta * (n1 * getDependency<Sum3Tag>(o) - n2 * getDependency<Sum3Tag>(*this));
3938 void update(U
const & t)
3940 using namespace vigra::multi_math;
3941 this->value_ += pow(getDependency<Centralize>(*
this), 4);
3944 void update(U
const & t,
double weight)
3946 using namespace vigra::multi_math;
3947 this->value_ += weight*pow(getDependency<Centralize>(*
this), 4);
3962 static std::string
const & name()
3964 static const std::string n(
"Skewness");
3968 template <
class U,
class BASE>
3972 static const unsigned int workInPass = 2;
3974 typedef typename LookupDependency<Central<PowerSum<3> >, BASE>::value_type value_type;
3975 typedef value_type result_type;
3977 result_type operator()()
const
3982 using namespace multi_math;
3983 return sqrt(getDependency<Count>(*
this)) * getDependency<Sum3>(*this) / pow(getDependency<Sum2>(*
this), 1.5);
3997 static std::string
const & name()
3999 static const std::string n(
"UnbiasedSkewness");
4003 template <
class U,
class BASE>
4007 static const unsigned int workInPass = 2;
4009 typedef typename LookupDependency<Central<PowerSum<3> >, BASE>::value_type value_type;
4010 typedef value_type result_type;
4012 result_type operator()()
const
4014 using namespace multi_math;
4015 double n = getDependency<Count>(*this);
4016 return sqrt(n*(n-1.0)) / (n - 2.0) * getDependency<Skewness>(*this);
4032 static std::string
const & name()
4034 static const std::string n(
"Kurtosis");
4038 template <
class U,
class BASE>
4042 static const unsigned int workInPass = 2;
4044 typedef typename LookupDependency<Central<PowerSum<4> >, BASE>::value_type value_type;
4045 typedef value_type result_type;
4047 result_type operator()()
const
4052 using namespace multi_math;
4053 return getDependency<Count>(*this) * getDependency<Sum4>(*this) /
sq(getDependency<Sum2>(*
this)) - value_type(3.0);
4067 static std::string
const & name()
4069 static const std::string n(
"UnbiasedKurtosis");
4073 template <
class U,
class BASE>
4077 static const unsigned int workInPass = 2;
4079 typedef typename LookupDependency<Central<PowerSum<4> >, BASE>::value_type value_type;
4080 typedef value_type result_type;
4082 result_type operator()()
const
4084 using namespace multi_math;
4085 double n = getDependency<Count>(*this);
4086 return (n-1.0)/((n-2.0)*(n-3.0))*((n+1.0)*getDependency<Kurtosis>(*this) + value_type(6.0));
4093 template <
class Scatter,
class Sum>
4094 void updateFlatScatterMatrix(Scatter & sc,
Sum const & s,
double w)
4096 int size = s.size();
4099 sc[k] += w*s[i]*s[j];
4102 template <
class Sum>
4103 void updateFlatScatterMatrix(
double & sc,
Sum const & s,
double w)
4108 template <
class Cov,
class Scatter>
4109 void flatScatterMatrixToScatterMatrix(Cov & cov, Scatter
const & sc)
4111 int size = cov.shape(0), k=0;
4118 cov(j,i) = cov(i,j);
4123 template <
class Scatter>
4124 void flatScatterMatrixToScatterMatrix(
double & cov, Scatter
const & sc)
4129 template <
class Cov,
class Scatter>
4130 void flatScatterMatrixToCovariance(Cov & cov, Scatter
const & sc,
double n)
4132 int size = cov.shape(0), k=0;
4135 cov(j,j) = sc[k++] / n;
4138 cov(i,j) = sc[k++] / n;
4139 cov(j,i) = cov(i,j);
4144 template <
class Scatter>
4145 void flatScatterMatrixToCovariance(
double & cov, Scatter
const & sc,
double n)
4162 static std::string
const & name()
4164 static const std::string n(
"FlatScatterMatrix");
4168 template <
class U,
class BASE>
4172 typedef typename AccumulatorResultTraits<U>::element_promote_type element_type;
4173 typedef typename AccumulatorResultTraits<U>::FlatCovarianceType value_type;
4174 typedef value_type
const & result_type;
4176 typedef typename AccumulatorResultTraits<U>::SumType SumType;
4188 value_ = element_type();
4191 template <
class Shape>
4192 void reshape(Shape
const & s)
4195 detail::reshapeImpl(value_,
Shape1(size*(size+1)/2));
4196 detail::reshapeImpl(diff_, s);
4201 double n1 = getDependency<Count>(*this), n2 = getDependency<Count>(o);
4208 using namespace vigra::multi_math;
4209 diff_ = getDependency<Mean>(*this) - getDependency<Mean>(o);
4210 detail::updateFlatScatterMatrix(value_, diff_, n1 * n2 / (n1 + n2));
4215 void update(U
const & t)
4220 void update(U
const & t,
double weight)
4225 result_type operator()()
const
4231 void compute(U
const & t,
double weight = 1.0)
4233 double n = getDependency<Count>(*this);
4236 using namespace vigra::multi_math;
4237 diff_ = getDependency<Mean>(*this) - t;
4238 detail::updateFlatScatterMatrix(value_, diff_, n * weight / (n - weight));
4251 static std::string
const & name()
4253 static const std::string n(
"DivideByCount<FlatScatterMatrix>");
4257 template <
class U,
class BASE>
4259 :
public CachedResultBase<BASE, typename AccumulatorResultTraits<U>::CovarianceType, U>
4261 typedef CachedResultBase<BASE, typename AccumulatorResultTraits<U>::CovarianceType, U> BaseType;
4262 typedef typename BaseType::result_type result_type;
4264 template <
class Shape>
4265 void reshape(Shape
const & s)
4268 detail::reshapeImpl(this->value_,
Shape2(size,size));
4271 result_type operator()()
const
4275 detail::flatScatterMatrixToCovariance(this->value_, getDependency<FlatScatterMatrix>(*
this), getDependency<Count>(*
this));
4278 return this->value_;
4285 class DivideUnbiased<FlatScatterMatrix>
4288 typedef Select<FlatScatterMatrix, Count> Dependencies;
4290 static std::string
const & name()
4292 static const std::string n(
"DivideUnbiased<FlatScatterMatrix>");
4296 template <
class U,
class BASE>
4298 :
public CachedResultBase<BASE, typename AccumulatorResultTraits<U>::CovarianceType, U>
4300 typedef CachedResultBase<BASE, typename AccumulatorResultTraits<U>::CovarianceType, U> BaseType;
4301 typedef typename BaseType::result_type result_type;
4303 template <
class Shape>
4304 void reshape(Shape
const & s)
4307 detail::reshapeImpl(this->value_,
Shape2(size,size));
4310 result_type operator()()
const
4314 detail::flatScatterMatrixToCovariance(this->value_, getDependency<FlatScatterMatrix>(*
this), getDependency<Count>(*
this) - 1.0);
4317 return this->value_;
4329 static std::string
const & name()
4331 static const std::string n(
"ScatterMatrixEigensystem");
4335 template <
class U,
class BASE>
4339 typedef typename AccumulatorResultTraits<U>::element_promote_type element_type;
4340 typedef typename AccumulatorResultTraits<U>::SumType EigenvalueType;
4341 typedef typename AccumulatorResultTraits<U>::CovarianceType EigenvectorType;
4342 typedef std::pair<EigenvalueType, EigenvectorType> value_type;
4343 typedef value_type
const & result_type;
4345 mutable value_type value_;
4356 void update(U
const &)
4361 void update(U
const &,
double)
4368 value_.first = element_type();
4369 value_.second = element_type();
4373 template <
class Shape>
4374 void reshape(Shape
const & s)
4377 detail::reshapeImpl(value_.first,
Shape1(size));
4378 detail::reshapeImpl(value_.second,
Shape2(size,size));
4381 result_type operator()()
const
4385 compute(getDependency<FlatScatterMatrix>(*
this), value_.first, value_.second);
4392 template <
class Flat,
class EW,
class EV>
4393 static void compute(Flat
const & flatScatter, EW & ew, EV & ev)
4395 EigenvectorType scatter(ev.shape());
4396 detail::flatScatterMatrixToScatterMatrix(scatter, flatScatter);
4402 static void compute(
double v,
double & ew,
double & ev)
4417 static std::string
const & name()
4419 static const std::string n(
"DivideByCount<ScatterMatrixEigensystem>");
4423 template <
class U,
class BASE>
4427 typedef typename LookupDependency<ScatterMatrixEigensystem, BASE>::type SMImpl;
4428 typedef typename SMImpl::element_type element_type;
4429 typedef typename SMImpl::EigenvalueType EigenvalueType;
4430 typedef typename SMImpl::EigenvectorType EigenvectorType;
4431 typedef std::pair<EigenvalueType, EigenvectorType const &> value_type;
4432 typedef value_type
const & result_type;
4434 mutable value_type value_;
4437 : value_(EigenvalueType(), BASE::template call_getDependency<ScatterMatrixEigensystem>().second)
4445 void update(U
const &)
4450 void update(U
const &,
double)
4457 value_.first = element_type();
4461 template <
class Shape>
4462 void reshape(Shape
const & s)
4465 detail::reshapeImpl(value_.first,
Shape2(size,1));
4468 result_type operator()()
const
4472 value_.first = getDependency<ScatterMatrixEigensystem>(*this).first / getDependency<Count>(*this);
4570 static std::string
const & name()
4572 static const std::string n(
"Principal<PowerSum<2> >");
4576 template <
class U,
class BASE>
4580 typedef typename LookupDependency<ScatterMatrixEigensystem, BASE>::type::EigenvalueType value_type;
4581 typedef value_type
const & result_type;
4583 result_type operator()()
const
4585 return getDependency<ScatterMatrixEigensystem>(*this).first;
4600 static std::string
const & name()
4602 static const std::string n(
"Principal<CoordinateSystem>");
4606 template <
class U,
class BASE>
4610 typedef typename LookupDependency<ScatterMatrixEigensystem, BASE>::type::EigenvectorType value_type;
4611 typedef value_type
const & result_type;
4613 result_type operator()()
const
4615 return getDependency<ScatterMatrixEigensystem>(*this).second;
4629 static std::string
const & name()
4631 static const std::string n(
"Minimum");
4635 template <
class U,
class BASE>
4639 typedef typename AccumulatorResultTraits<U>::element_type element_type;
4640 typedef typename AccumulatorResultTraits<U>::MinmaxType value_type;
4641 typedef value_type
const & result_type;
4647 value_ = NumericTraits<element_type>::max();
4652 value_ = NumericTraits<element_type>::max();
4655 template <
class Shape>
4656 void reshape(Shape
const & s)
4658 detail::reshapeImpl(value_, s, NumericTraits<element_type>::max());
4663 updateImpl(o.value_);
4666 void update(U
const & t)
4671 void update(U
const & t,
double)
4676 result_type operator()()
const
4683 void updateImpl(T
const & o)
4685 using namespace multi_math;
4686 value_ = min(value_, o);
4689 template <
class T,
class Alloc>
4692 value_ = multi_math::min(value_, o);
4706 static std::string
const & name()
4708 static const std::string n(
"Maximum");
4712 template <
class U,
class BASE>
4716 typedef typename AccumulatorResultTraits<U>::element_type element_type;
4717 typedef typename AccumulatorResultTraits<U>::MinmaxType value_type;
4718 typedef value_type
const & result_type;
4724 value_ = NumericTraits<element_type>::min();
4729 value_ = NumericTraits<element_type>::min();
4732 template <
class Shape>
4733 void reshape(Shape
const & s)
4735 detail::reshapeImpl(value_, s, NumericTraits<element_type>::min());
4740 updateImpl(o.value_);
4743 void update(U
const & t)
4748 void update(U
const & t,
double)
4753 result_type operator()()
const
4760 void updateImpl(T
const & o)
4762 using namespace multi_math;
4763 value_ = max(value_, o);
4766 template <
class T,
class Alloc>
4769 value_ = multi_math::max(value_, o);
4783 static std::string
const & name()
4785 static const std::string n(
"ArgMinWeight");
4789 template <
class U,
class BASE>
4793 typedef typename AccumulatorResultTraits<U>::element_type element_type;
4794 typedef typename AccumulatorResultTraits<U>::MinmaxType value_type;
4795 typedef value_type
const & result_type;
4801 : min_weight_(NumericTraits<double>::max()),
4807 min_weight_ = NumericTraits<double>::max();
4808 value_ = element_type();
4811 template <
class Shape>
4812 void reshape(Shape
const & s)
4814 detail::reshapeImpl(value_, s);
4819 using namespace multi_math;
4820 if(o.min_weight_ < min_weight_)
4822 min_weight_ = o.min_weight_;
4827 void update(U
const & t)
4829 vigra_precondition(
false,
"ArgMinWeight::update() needs weights.");
4832 void update(U
const & t,
double weight)
4834 if(weight < min_weight_)
4836 min_weight_ = weight;
4841 result_type operator()()
const
4857 static std::string
const & name()
4859 static const std::string n(
"ArgMaxWeight");
4863 template <
class U,
class BASE>
4867 typedef typename AccumulatorResultTraits<U>::element_type element_type;
4868 typedef typename AccumulatorResultTraits<U>::MinmaxType value_type;
4869 typedef value_type
const & result_type;
4875 : max_weight_(NumericTraits<double>::min()),
4881 max_weight_ = NumericTraits<double>::min();
4882 value_ = element_type();
4885 template <
class Shape>
4886 void reshape(Shape
const & s)
4888 detail::reshapeImpl(value_, s);
4893 using namespace multi_math;
4894 if(o.max_weight_ > max_weight_)
4896 max_weight_ = o.max_weight_;
4901 void update(U
const & t)
4903 vigra_precondition(
false,
"ArgMaxWeight::update() needs weights.");
4906 void update(U
const & t,
double weight)
4908 if(weight > max_weight_)
4910 max_weight_ = weight;
4915 result_type operator()()
const
4923 template <
class BASE,
int BinCount>
4929 typedef double element_type;
4931 typedef value_type
const & result_type;
4934 double left_outliers, right_outliers;
4944 value_ = element_type();
4945 left_outliers = 0.0;
4946 right_outliers = 0.0;
4952 left_outliers += o.left_outliers;
4953 right_outliers += o.right_outliers;
4956 result_type operator()()
const
4962 template <
class BASE>
4963 class HistogramBase<BASE, 0>
4968 typedef double element_type;
4969 typedef MultiArray<1, double> value_type;
4970 typedef value_type
const & result_type;
4973 double left_outliers, right_outliers;
4983 value_ = element_type();
4984 left_outliers = 0.0;
4985 right_outliers = 0.0;
4991 left_outliers += o.left_outliers;
4992 right_outliers += o.right_outliers;
4995 void setBinCount(
int binCount)
4997 vigra_precondition(binCount > 0,
4998 "HistogramBase:.setBinCount(): binCount > 0 required.");
4999 value_type(
Shape1(binCount)).swap(value_);
5002 result_type operator()()
const
5008 template <
class BASE,
int BinCount,
class U=
typename BASE::input_type>
5009 class RangeHistogramBase
5010 :
public HistogramBase<BASE, BinCount>
5013 double scale_, offset_, inverse_scale_;
5015 RangeHistogramBase()
5025 inverse_scale_ = 0.0;
5026 HistogramBase<BASE, BinCount>::reset();
5029 void operator+=(RangeHistogramBase
const & o)
5031 vigra_precondition(scale_ == 0.0 || o.scale_ == 0.0 || (scale_ == o.scale_ && offset_ == o.offset_),
5032 "RangeHistogramBase::operator+=(): cannot merge histograms with different data mapping.");
5038 offset_ = o.offset_;
5039 inverse_scale_ = o.inverse_scale_;
5043 void update(U
const & t)
5048 void update(U
const & t,
double weight)
5050 double m = mapItem(t);
5051 int index = (m == (double)this->value_.size())
5055 this->left_outliers += weight;
5056 else if(index >= (
int)this->value_.size())
5057 this->right_outliers += weight;
5059 this->value_[index] += weight;
5062 void setMinMax(
double mi,
double ma)
5064 vigra_precondition(this->value_.size() > 0,
5065 "RangeHistogramBase::setMinMax(...): setBinCount(...) has not been called.");
5066 vigra_precondition(mi < ma,
5067 "RangeHistogramBase::setMinMax(...): min < max required.");
5069 scale_ = (double)this->value_.size() / (ma - mi);
5070 inverse_scale_ = 1.0 / scale_;
5073 double mapItem(
double t)
const
5075 return scale_ * (t - offset_);
5078 double mapItemInverse(
double t)
const
5080 return inverse_scale_ * t + offset_;
5083 template <
class ArrayLike>
5084 void computeStandardQuantiles(
double minimum,
double maximum,
double count,
5085 ArrayLike
const & desiredQuantiles, ArrayLike & res)
const
5087 ArrayVector<double> keypoints, cumhist;
5088 double mappedMinimum = mapItem(minimum);
5089 double mappedMaximum = mapItem(maximum);
5091 keypoints.push_back(mappedMinimum);
5092 cumhist.push_back(0.0);
5094 if(this->left_outliers > 0.0)
5096 keypoints.push_back(0.0);
5097 cumhist.push_back(this->left_outliers);
5100 int size = (int)this->value_.size();
5101 double cumulative = this->left_outliers;
5102 for(
int k=0; k<size; ++k)
5104 if(this->value_[k] > 0.0)
5106 if(keypoints.back() <= k)
5108 keypoints.push_back(k);
5109 cumhist.push_back(cumulative);
5111 cumulative += this->value_[k];
5112 keypoints.push_back(k+1);
5113 cumhist.push_back(cumulative);
5117 if(this->right_outliers > 0.0)
5119 if(keypoints.back() != size)
5121 keypoints.push_back(size);
5122 cumhist.push_back(cumulative);
5124 keypoints.push_back(mappedMaximum);
5125 cumhist.push_back(count);
5129 keypoints.back() = mappedMaximum;
5130 cumhist.back() = count;
5133 int quantile = 0, end = (int)desiredQuantiles.size();
5135 if(desiredQuantiles[0] == 0.0)
5140 if(desiredQuantiles[end-1] == 1.0)
5142 res[end-1] = maximum;
5147 double qcount = count * desiredQuantiles[quantile];
5148 while(quantile < end)
5150 if(cumhist[point] < qcount && cumhist[point+1] >= qcount)
5152 double t = (qcount - cumhist[point]) / (cumhist[point+1] - cumhist[point]) * (keypoints[point+1] - keypoints[point]);
5153 res[quantile] = mapItemInverse(t + keypoints[point]);
5155 qcount = count * desiredQuantiles[quantile];
5173 template <
int BinCount>
5174 class IntegerHistogram
5178 typedef Select<> Dependencies;
5180 static std::string
const & name()
5182 static const std::string n = std::string(
"IntegerHistogram<") +
asString(BinCount) +
">";
5186 template <
class U,
class BASE>
5188 :
public HistogramBase<BASE, BinCount>
5190 void update(
int index)
5193 ++this->left_outliers;
5194 else if(index >= (
int)this->value_.size())
5195 ++this->right_outliers;
5197 ++this->value_[index];
5200 void update(
int index,
double weight)
5204 vigra_precondition(
false,
"IntegerHistogram::update(): weighted histograms not supported, use another histogram type.");
5207 template <
class ArrayLike>
5208 void computeStandardQuantiles(
double minimum,
double maximum,
double count,
5209 ArrayLike
const & desiredQuantiles, ArrayLike & res)
const
5211 int quantile = 0, end = (int)desiredQuantiles.size();
5213 if(desiredQuantiles[0] == 0.0)
5218 if(desiredQuantiles[end-1] == 1.0)
5220 res[end-1] = maximum;
5225 int currentBin = 0, size = (int)this->value_.size();
5226 double cumulative1 = this->left_outliers,
5227 cumulative2 = this->value_[currentBin] + cumulative1;
5231 double qcount = desiredQuantiles[quantile]*count + 1.0;
5233 while(quantile < end)
5235 if(cumulative2 == qcount)
5237 res[quantile] = currentBin;
5239 qcount = desiredQuantiles[quantile]*count + 1.0;
5241 else if(cumulative2 > qcount)
5243 if(cumulative1 > qcount)
5245 res[quantile] = minimum;
5247 if(cumulative1 + 1.0 > qcount)
5249 res[quantile] = currentBin - 1 + qcount -
std::floor(qcount);
5253 res[quantile] = currentBin;
5256 qcount = desiredQuantiles[quantile]*count + 1.0;
5258 else if(currentBin == size-1)
5260 res[quantile] = maximum;
5262 qcount = desiredQuantiles[quantile]*count + 1.0;
5267 cumulative1 = cumulative2;
5268 cumulative2 += this->value_[currentBin];
5285 template <
int BinCount>
5286 class UserRangeHistogram
5290 typedef Select<> Dependencies;
5292 static std::string
const & name()
5294 static const std::string n = std::string(
"UserRangeHistogram<") +
asString(BinCount) +
">";
5298 template <
class U,
class BASE>
5300 :
public RangeHistogramBase<BASE, BinCount, U>
5302 void update(U
const & t)
5307 void update(U
const & t,
double weight)
5309 vigra_precondition(this->scale_ != 0.0,
5310 "UserRangeHistogram::update(): setMinMax(...) has not been called.");
5312 RangeHistogramBase<BASE, BinCount, U>::update(t, weight);
5326 template <
int BinCount>
5327 class AutoRangeHistogram
5331 typedef Select<Minimum, Maximum> Dependencies;
5333 static std::string
const & name()
5335 static const std::string n = std::string(
"AutoRangeHistogram<") +
asString(BinCount) +
">";
5339 template <
class U,
class BASE>
5341 :
public RangeHistogramBase<BASE, BinCount, U>
5343 static const unsigned int workInPass = LookupDependency<Minimum, BASE>::type::workInPass + 1;
5345 void update(U
const & t)
5350 void update(U
const & t,
double weight)
5352 if(this->scale_ == 0.0)
5353 this->setMinMax(getDependency<Minimum>(*
this), getDependency<Maximum>(*
this));
5355 RangeHistogramBase<BASE, BinCount, U>::update(t, weight);
5369 template <
int BinCount>
5370 class GlobalRangeHistogram
5374 typedef Select<Global<Minimum>, Global<Maximum>, Minimum, Maximum> Dependencies;
5376 static std::string
const & name()
5378 static const std::string n = std::string(
"GlobalRangeHistogram<") +
asString(BinCount) +
">";
5382 template <
class U,
class BASE>
5384 :
public RangeHistogramBase<BASE, BinCount, U>
5386 static const unsigned int workInPass = LookupDependency<Minimum, BASE>::type::workInPass + 1;
5388 bool useLocalMinimax_;
5391 : useLocalMinimax_(false)
5394 void setRegionAutoInit(
bool locally)
5397 useLocalMinimax_ = locally;
5400 void update(U
const & t)
5405 void update(U
const & t,
double weight)
5407 if(this->scale_ == 0.0)
5409 if(useLocalMinimax_)
5410 this->setMinMax(getDependency<Minimum>(*
this), getDependency<Maximum>(*
this));
5412 this->setMinMax(getDependency<Global<Minimum> >(*
this), getDependency<Global<Maximum> >(*
this));
5415 RangeHistogramBase<BASE, BinCount, U>::update(t, weight);
5424 template <
class HistogramAccumulator>
5425 class StandardQuantiles
5429 typedef typename StandardizeTag<HistogramAccumulator>::type HistogramTag;
5430 typedef Select<HistogramTag, Minimum, Maximum, Count> Dependencies;
5432 static std::string
const & name()
5434 static const std::string n = std::string(
"StandardQuantiles<") + HistogramTag::name() +
" >";
5438 template <
class U,
class BASE>
5440 :
public CachedResultBase<BASE, TinyVector<double, 7>, U>
5442 typedef typename CachedResultBase<BASE, TinyVector<double, 7>, U>::result_type result_type;
5443 typedef typename CachedResultBase<BASE, TinyVector<double, 7>, U>::value_type value_type;
5445 static const unsigned int workInPass = LookupDependency<HistogramTag, BASE>::type::workInPass;
5447 result_type operator()()
const
5451 static const double desiredQuantiles[] = {0.0, 0.1, 0.25, 0.5, 0.75, 0.9, 1.0 };
5452 getAccumulator<HistogramTag>(*this).computeStandardQuantiles(getDependency<Minimum>(*
this), getDependency<Maximum>(*
this),
5453 getDependency<Count>(*
this), value_type(desiredQuantiles),
5457 return this->value_;
5464 #endif // VIGRA_ACCUMULATOR_HXX
Basic statistic. Data value where weight assumes its minimal value.
Definition: accumulator.hxx:4778
void extractFeatures(ITERATOR start, ITERATOR end, ACCUMULATOR &a)
Definition: accumulator.hxx:2712
Basic statistic. PowerSum = .
Definition: accumulator-grammar.hxx:59
ArrayVector< std::string > activeNames() const
Definition: accumulator.hxx:2045
Basic statistic. Maximum value.
Definition: accumulator.hxx:4701
unsigned int passesRequired() const
Definition: accumulator.hxx:2286
Basic statistic. Skewness.
Definition: accumulator.hxx:3957
unsigned int passesRequired() const
Definition: accumulator.hxx:2056
void reshape(TinyVector< U, N > const &s)
Definition: accumulator.hxx:1908
Basic statistic. Identity matrix of appropriate size.
Definition: accumulator.hxx:3373
ArrayVector< std::string > activeNames() const
Definition: accumulator.hxx:2276
const_iterator begin() const
Definition: array_vector.hxx:223
void setMaxRegionLabel(unsigned label)
Definition: accumulator.hxx:2116
Basic statistic. Kurtosis.
Definition: accumulator.hxx:4027
Basic statistic. Unbiased Kurtosis.
Definition: accumulator.hxx:4062
Main MultiArray class containing the memory management.
Definition: multi_array.hxx:595
void reset(unsigned int reset_to_pass=0)
void activateAll()
Definition: accumulator.hxx:2021
LookupTag< TAG, A >::reference getAccumulator(A &a)
Definition: accumulator.hxx:2586
void merge(AccumulatorChainImpl const &o)
Create an accumulator chain containing the selected statistics and their dependencies.
Definition: accumulator.hxx:1896
Basic statistic. Flattened uppter-triangular part of scatter matrix.
Definition: accumulator.hxx:4157
Modifier. Substract mean before computing statistic.
Definition: accumulator-grammar.hxx:139
Wrapper for MakeTypeList that additionally performs tag standardization.
Definition: accumulator.hxx:338
std::ptrdiff_t MultiArrayIndex
Definition: multi_iterator.hxx:348
bool isActive(A const &a)
Definition: accumulator.hxx:2681
Create an array of dynamic accumulator chains containing the selected per-region and global statistic...
Definition: accumulator.hxx:2231
void reset(unsigned int reset_to_pass=0)
CoupledHandleCast< TARGET_INDEX, Handle >::type::reference get(Handle &handle)
Definition: multi_iterator_coupled.hxx:504
bool isActive(std::string tag) const
Definition: accumulator.hxx:2259
void activate(std::string tag)
Definition: accumulator.hxx:2005
bool isActive() const
Definition: accumulator.hxx:2270
bool isActive() const
Definition: accumulator.hxx:2038
Definition: array_vector.hxx:58
FFTWComplex< R > & operator+=(FFTWComplex< R > &a, const FFTWComplex< R > &b)
add-assignment
Definition: fftw3.hxx:859
NumericTraits< T >::Promote sq(T t)
Definition: mathutil.hxx:341
void activate()
Definition: accumulator.hxx:2246
Basic statistic. Unbiased Skewness.
Definition: accumulator.hxx:3992
NumericTraits< V >::Promote prod(TinyVectorBase< V, SIZE, D1, D2 > const &l)
product of the vector's elements
Definition: tinyvector.hxx:1707
void activate()
Definition: accumulator.hxx:2014
bool symmetricEigensystem(MultiArrayView< 2, T, C1 > const &a, MultiArrayView< 2, T, C2 > &ew, MultiArrayView< 2, T, C3 > &ev)
Definition: eigensystem.hxx:1008
void merge(AccumulatorChainArray const &o)
Definition: accumulator.hxx:2146
std::string asString(T t)(...)
void operator+=(AccumulatorChainImpl const &o)
void activateAll()
Definition: accumulator.hxx:2252
static ArrayVector< std::string > const & tagNames()
Definition: accumulator.hxx:2167
void operator+=(AccumulatorChainImpl const &o)
void updatePassN(T const &t, unsigned int N)
Iterator argMax(Iterator first, Iterator last)
Definition: algorithm.hxx:96
std::string normalizeString(std::string const &s)
Definition: utilities.hxx:107
void updatePassN(T const &t, unsigned int N)
unsigned int regionCount() const
Definition: accumulator.hxx:2130
PowerSum< 1 > Sum
Alias. Sum.
Definition: accumulator-grammar.hxx:156
Class for fixed size vectors.This class contains an array of size SIZE of the specified VALUETYPE...
Definition: accessor.hxx:939
void ignoreLabel(MultiArrayIndex l)
Definition: accumulator.hxx:2109
unsigned int passesRequired() const
Definition: accumulator.hxx:4324
void setHistogramOptions(HistogramOptions const &options)
Modifier. Project onto PCA eigenvectors.
Definition: accumulator-grammar.hxx:140
MultiArrayShape< 2 >::type Shape2
shape type for MultiArray<2, T>
Definition: multi_iterator.hxx:364
Basic statistic. Data where weight assumes its maximal value.
Definition: accumulator.hxx:4852
bool isActive(std::string tag) const
Definition: accumulator.hxx:2027
MultiArrayShape< 1 >::type Shape1
shape type for MultiArray<1, T>
Definition: multi_iterator.hxx:363
static ArrayVector< std::string > const & tagNames()
Definition: accumulator.hxx:1918
FFTWComplex< R >::NormType abs(const FFTWComplex< R > &a)
absolute value (= magnitude)
Definition: fftw3.hxx:1002
Base class for, and view to, vigra::MultiArray.
Definition: multi_array.hxx:593
void merge(unsigned i, unsigned j)
Definition: accumulator.hxx:2137
void activate(std::string tag)
Definition: accumulator.hxx:2238
MultiArrayIndex maxRegionLabel() const
Definition: accumulator.hxx:2123
const_iterator end() const
Definition: array_vector.hxx:237
void merge(AccumulatorChainArray const &o, ArrayLike const &labelMapping)
Definition: accumulator.hxx:2158
Modifier. Divide statistic by Count: DivideByCount = TAG / Count .
Definition: accumulator-grammar.hxx:127
void activate(A &a)
Definition: accumulator.hxx:2670
void setHistogramOptions(HistogramOptions const &options)
int floor(FixedPoint< IntBits, FracBits > v)
rounding down.
Definition: fixedpoint.hxx:667
Basic statistic. Minimum value.
Definition: accumulator.hxx:4624
Create a dynamic accumulator chain containing the selected statistics and their dependencies.
Definition: accumulator.hxx:1996
SquareRootTraits< FixedPoint< IntBits, FracBits > >::SquareRootResult sqrt(FixedPoint< IntBits, FracBits > v)
square root.
Definition: fixedpoint.hxx:616
Create an array of accumulator chains containing the selected per-region and global statistics and th...
Definition: accumulator.hxx:2096
Set histogram options.
Definition: histogram.hxx:49