- progress++;
-
- VFType::RegionType region4D=vf->GetLargestPossibleRegion();
- VFType::RegionType::SizeType size4D=region4D.GetSize();
- VFType::IndexType index4D=region4D.GetIndex();
- VFType::SpacingType spacing4D=vf->GetSpacing();
- VFType::PointType origin4D=vf->GetOrigin();
-
- OutputVFType::RegionType region;
- OutputVFType::RegionType::SizeType size;
- OutputVFType::IndexType index;
- OutputVFType::SpacingType spacing;
- OutputVFType::PointType origin;
- for (unsigned int i=0; i< 3; i++)
- {
- size[i]=size4D[i];
- index[i]=index4D[i];
- spacing[i]=spacing4D[i];
- origin[i]=origin4D[i];
+ progress++;
+
+ VFType::RegionType region4D=vf->GetLargestPossibleRegion();
+ VFType::RegionType::SizeType size4D=region4D.GetSize();
+ VFType::IndexType index4D=region4D.GetIndex();
+ VFType::SpacingType spacing4D=vf->GetSpacing();
+ VFType::PointType origin4D=vf->GetOrigin();
+
+ OutputVFType::RegionType region;
+ OutputVFType::RegionType::SizeType size;
+ OutputVFType::IndexType index;
+ OutputVFType::SpacingType spacing;
+ OutputVFType::PointType origin;
+ for (unsigned int i=0; i< 3; i++) {
+ size[i]=size4D[i];
+ index[i]=index4D[i];
+ spacing[i]=spacing4D[i];
+ origin[i]=origin4D[i];
+ }
+ region.SetSize(size);
+ region.SetIndex(index);
+ OutputVFType::Pointer output= OutputVFType::New();
+ output->SetRegions(region);
+ output->SetSpacing(spacing);
+ output->SetOrigin(origin);
+ output->Allocate();
+ progress++;
+
+
+ // Region iterators
+ typedef itk::ImageRegionConstIterator<VFType> IteratorType;
+ std::vector<IteratorType> iterators(size4D[3]);
+ for (unsigned int i=0; i< size4D[3]; i++) {
+ VFType::RegionType regionIt=region4D;
+ VFType::RegionType::SizeType sizeIt=regionIt.GetSize();
+ sizeIt[3]=1;
+ regionIt.SetSize(sizeIt);
+ VFType::IndexType indexIt=regionIt.GetIndex();
+ indexIt[3]=i;
+ regionIt.SetIndex(indexIt);
+ iterators[i]=IteratorType(vf, regionIt);
+ }
+ progress++;
+
+ typedef itk::ImageRegionIterator<OutputVFType> OutputIteratorType;
+ OutputIteratorType avIt(output, output->GetLargestPossibleRegion());
+
+ // Average
+ VFPixelType vector;
+ VFPixelType zeroVector=itk::NumericTraits<VFPixelType>::Zero;
+
+ while (!(iterators[0]).IsAtEnd()) {
+ vector=zeroVector;
+ for (unsigned int i=0; i<size4D[3]; i++) {
+ vector+=iterators[i].Get();
+ ++(iterators[i]);