Scope
PixelmapperFrameResonanceSW.cpp
1 #include "stdafx.h"
2 #include "PixelmapperFrameResonanceSW.h"
3 #include "parameters\Framescan.h"
4 #include "helpers\DaqChunkResonance.h"
5 #include "helpers\ScopeImage.h"
6 #include "helpers\ScopeMultiImageResonanceSW.h"
7 
8 namespace scope {
9 
10 PixelmapperFrameResonanceSW::PixelmapperFrameResonanceSW()
11  : PixelmapperBasic(ScannerTypeHelper::Resonance, ScannerVectorTypeHelper::ResonanceBiDi)
12  , firstchunk(true) {
13 }
14 
15 PixelmapperResult PixelmapperFrameResonanceSW::LookupChunk(DaqChunkResonancePtr const _chunk, const uint16_t& _currentavgcount) {
16  PixelmapperResult result(Nothing);
17  uint32_t n = 1;
18  const uint32_t multiplier = _currentavgcount; // currentavgcount = 0: first frame, multiply by 0 -> overwrite last image pixel (for running update of old pixels), see PipelineController
19  const uint32_t divisor = std::max<uint32_t>(1, _currentavgcount + 1); // currentavgcount = 1: second frame, multiply by 1, divide by 2
20  const uint32_t halfdivisor = std::max<uint32_t>(1, divisor >> 2); // etc etc
21 
23  const uint32_t xturnpixelsleft = tmp->XTurnPixelsLeft();
24  const uint32_t xturnpixelsright = tmp->XTurnPixelsRight();
25  const uint32_t ximagepixels = tmp->XImagePixels();
26  const uint32_t cutofflines = tmp->YCutoffLines();
27  const uint32_t scanlines = tmp->YScanLines();
28  const uint32_t ytotallines = tmp->YTotalLines();
29  const uint32_t xtotalpixels = tmp->XTotalPixels();
30  const uint32_t totalpixels = tmp->TotalPixels();
31  const uint32_t totalimagepixels = tmp->XImagePixels()*tmp->YImageLines();
32 
33  uint32_t imagepos;
34  bool forthline;
35  uint32_t l;
36  uint32_t i;
37  uint32_t lx;
38  DaqChunkResonance::iterator channelend;
41 
42  // Go through all channels
43  for ( uint32_t c = 0 ; c < _chunk->NChannels() ; c++ ) {
44  // Get the data
45  ScopeImageAccessU16 imagedata(*current_frame->GetChannel(c));
46  std::vector<uint16_t>* const dataptr(imagedata.GetData());
47 
48  ScopeImageAccessU16 averagedimagedata(*current_averaged_frame->GetChannel(c));
49  std::vector<uint16_t>* const averageddataptr(averagedimagedata.GetData());
50 
51  // Which sample did we map last in this chunk (initially std::begin) and at what position of the sync signal
52  chunkit = _chunk->lastmapped[c];
53  syncit = _chunk->lastsyncsig[c];
54  // where does this channel end in the chunk's data vector
55  channelend = std::begin(_chunk->data)+(c+1)*_chunk->PerChannel();
56  // Which pixel did we last map into the image
57  imagepos = current_frame->LastImagePos(c);
58  forthline = current_frame->LastForthline(c);
59 
60  // find beginning of the first line of the first chunk
61  if ( firstchunk ) {
62  firstchunk = false;
63  do {
64  chunkit++;
65  syncit++;
66  } while ( (chunkit+1 != channelend) && !( *syncit == 1 && *(syncit+1) == 0 ));
67  }
68 
69  // always aligning on the left
70  // y scanner is based on given number of lines
71  for ( l = current_frame->LastL(c) ; l < ytotallines ; l++ ) {
72  // x (resonant) scanner is based on the synchronization signal and waits until it switches from 1 to 0
73  if ( forthline ) {
74  for ( i = current_frame->LastX(c); (chunkit != channelend) && (i < (xtotalpixels - xturnpixelsright)); i++, syncit++, chunkit++ ) {
75  if ( (l >= cutofflines) && (l < scanlines) && (i >= xturnpixelsleft) ) {
76  // write into the frame that is not averaged
77  dataptr->operator[](imagepos) = *chunkit;
78 
79  // write into the averaged frame
80  n = (static_cast<uint32_t>(averageddataptr->operator[](imagepos)) * multiplier) + static_cast<uint32_t>(*chunkit);
81  averageddataptr->operator[](imagepos) = static_cast<uint16_t>( n / divisor + ((n%divisor)>halfdivisor?1u:0u) );
82 
83  imagepos++;
84  }
85  lx = i;
86  }
87  current_frame->SetLastX(c, 0);
88  }
89  else {
90  for ( i = current_frame->LastX(c); chunkit != channelend; i++, syncit++, chunkit++ ) {
91  // save intermediately in a vector
92  current_frame->CurrentLineData()->at(c).at(i) = *chunkit;
93  if ( (chunkit+1 != channelend) && ( *syncit == 1 && *(syncit+1) == 0 ) ) {
94  // fill in beginning at the end of the intermediate vector
95  for ( uint32_t x = 0; x < ((i>=xtotalpixels-xturnpixelsright)?(xtotalpixels-xturnpixelsright):i); x++ ) {
96  if ( (l >= cutofflines) && (l < scanlines) && (x >= xturnpixelsleft) ) {
97  imagepos--;
98 
99  // write into the frame that is not averaged
100  dataptr->operator[](imagepos) = current_frame->CurrentLineData()->at(c).at(i - x - 1);
101 
102  // write into the averaged frame
103  n = (static_cast<uint32_t>(averageddataptr->operator[](imagepos)) * multiplier) + static_cast<uint32_t>(current_frame->CurrentLineData()->at(c).at(i - x - 1));
104  averageddataptr->operator[](imagepos) = static_cast<uint16_t>( n / divisor + ((n%divisor)>halfdivisor?1u:0u) );
105  }
106  }
107  syncit++;
108  chunkit++;
109  current_frame->SetLastX(c, 0);
110  break;
111  }
112  lx = i;
113  }
114  }
115 
116  if( chunkit == channelend ) {
117  current_frame->SetLastX(c, lx);
118  result = PixelmapperResult(result | EndOfChunk);
119  break;
120  }
121  if ( (l >= cutofflines) && (l < scanlines) ) {
122  if ( forthline )
123  imagepos = (l-cutofflines+2) * ximagepixels;
124  else
125  imagepos = (l-cutofflines+1) * ximagepixels;
126  }
127  forthline = !forthline;
128  }
129 
130  // save in the chunk which sample was last mapped and the position of the sync signal
131  _chunk->SetLastMapped(c, chunkit);
132  _chunk->SetLastSyncSig(c, syncit);
133 
134  // save which pixel we last looked up
135  if ( l >= ytotallines ) {
136  current_frame->SetLastImagepos(c, 0);
137  current_frame->SetLastL(c, 0);
138  current_frame->SetLastForthline(c, true);
139  current_frame->SetLastX(c, 0);
140 
141  result = PixelmapperResult(result | FrameComplete);
142  }
143  else {
144  current_frame->SetLastImagepos(c, imagepos);
145  current_frame->SetLastL(c, l);
146  }
147  current_frame->SetLastForthline(c, forthline);
148  }
149 
150  return result;
151 
152 }
153 
154 void PixelmapperFrameResonanceSW::SetCurrentAveragedFrame(ScopeMultiImageResonanceSWPtr const _current_averaged_frame) {
155  current_averaged_frame = _current_averaged_frame;
156 }
157 
158 }
parameters::ScannerVectorFrameBasic * svparameters
current scanner vector parameter set (needs to be pointer for dynamic_cast in derived classes and bec...
ScopeMultiImageResonanceSWPtr current_frame
pointer to the current frame to be mapped into (for SW resonance mapping, different type than the one...
std::vector< bool >::iterator iteratorSync
Iterator over the sync vector.
std::vector< uint16_t >::iterator iterator
Iterator over the data vector.
Definition: DaqChunk.h:23
Parameters for a ScannerVectorFrameResonance.
Definition: Framescan.h:439
Gives RAII safe access (read&write) to the pixeldata of a ScopeImage.
Definition: ScopeImage.h:11
void SetCurrentAveragedFrame(ScopeMultiImageResonanceSWPtr const _current_averaged_frame)
Sets pointer to the current averaged (displayed) frame to be mapped into.
This is the include file for standard system include files, or project specific include files that ar...
ScopeMultiImageResonanceSWPtr current_averaged_frame
pointer to the current averaged frame to be mapped into
PixelmapperResult LookupChunk(DaqChunkResonancePtr const _chunk, const uint16_t &_currentavgcount) override
Maps a chunk.
bool firstchunk
true only for mapping first chunk