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