Scope
PixelmapperFrameBiDi.cpp
1 #include "stdafx.h"
2 #include "PixelmapperFrameBiDi.h"
3 #include "helpers/ScopeImage.h"
4 #include "helpers/ScopeMultiImage.h"
5 
6 namespace scope {
7 
8 PixelmapperFrameBiDi::PixelmapperFrameBiDi()
9  : PixelmapperBasic(ScannerTypeHelper::Regular, ScannerVectorTypeHelper::Bidirectional) {
10 }
11 
12 PixelmapperResult PixelmapperFrameBiDi::LookupChunk(DaqChunkPtr const _chunk, const uint16_t& _currentavgcount) {
13  PixelmapperResult result(Nothing);
14  uint32_t n = 1;
15  const uint32_t multiplier = _currentavgcount; // currentavgcount = 0: first frame, multiply by 0 -> overwrite last image pixel (for running update of old pixels), see PipelineController
16  const uint32_t divisor = std::max<uint32_t>(1, _currentavgcount + 1); // currentavgcount = 1: second frame, multiply by 1, divide by 2
17  const uint32_t halfdivisor = std::max<uint32_t>(1, divisor >> 2); // etc etc
18 
19  auto lookit = lastlookup;
20  DaqChunk::iterator channelend;
21  DaqChunk::iterator chunkit;
22  // Go through all channels
23  for ( uint32_t c = 0 ; c < _chunk->NChannels() ; c++ ) {
24  // Get the data
25  ScopeImageAccessU16 imagedata(*current_frame->GetChannel(c));
26  std::vector<uint16_t>* const dataptr(imagedata.GetData());
27  // Which sample did we map last in this chunk (initially std::begin)
28  chunkit = _chunk->lastmapped[c];
29  // where does this channel end in the chunk's data vector
30  channelend = std::begin(_chunk->data)+(c+1)*_chunk->PerChannel();
31  // Which pixel did we last look up in the lookup vector
32  lookit = lastlookup;
33  // Advance iterators in chunk and lookup vector in parallel
34  auto lookupend = std::end(*lookup);
35  for ( ; (lookit != lookupend) && (chunkit != channelend) ; lookit++, chunkit++ ) {
36  // Do a little calculation for the online averaging
37  n = (static_cast<uint32_t>(dataptr->operator[](*lookit)) * multiplier) + static_cast<uint32_t>(*chunkit);
38  dataptr->operator[](*lookit) = static_cast<uint16_t>( n / divisor + ((n%divisor)>halfdivisor?1u:0u) );
39  }
40  // save in the chunk which sample was last mapped
41  _chunk->lastmapped[c] = chunkit;
42  }
43  // save which pixel we last looked up
44  if ( lookit == std::end(*lookup) ) {
45  lastlookup = std::begin(*lookup);
46  result = PixelmapperResult(result | FrameComplete);
47  }
48  else
49  lastlookup = lookit;
50 
51  if ( chunkit == channelend )
52  result = PixelmapperResult(result | EndOfChunk);
53 
54  return result;
55 }
56 
57 }
std::vector< uint16_t >::iterator iterator
Iterator over the data vector.
Definition: DaqChunk.h:23
Gives RAII safe access (read&write) to the pixeldata of a ScopeImage.
Definition: ScopeImage.h:11
This is the include file for standard system include files, or project specific include files that ar...
PixelmapperResult LookupChunk(DaqChunkPtr const _chunk, const uint16_t &_currentavgcount) override
Maps a chunk via the lookup vector.
std::shared_ptr< const std::vector< std::size_t > > lookup
for position lookup
ScopeMultiImagePtr current_frame
pointer to the current frame to be mapped into
std::vector< std::size_t >::const_iterator lastlookup
last position in lookup where we looked up last time