Scope
ScannerVectorFrameBiDi.cpp
1 #include "stdafx.h"
2 #include "ScannerVectorFrameBiDi.h"
3 
4 namespace scope {
6  : ScannerVectorFrameBasic(ScannerVectorTypeHelper::Bidirectional, _filltype) {
7 }
8 
9 ScannerVectorFrameBiDi::~ScannerVectorFrameBiDi() {
10 
11 }
12 
14  // samples for x,y,z,pockels
15  vecptr->resize(4 * svparameters->TotalPixels());
16  lookup->resize(svparameters->TotalPixels());
17 
18  FillX();
19  FillY();
20  FillZ();
21  FillP();
22  FillLookup();
23 }
24 
27  const uint32_t xturnpixels = tmp->XTurnPixels();
28  const uint32_t cutofflines = tmp->YCutoffLines();
29  const uint32_t scanlines = tmp->YScanLines();
30  const uint32_t ytotallines = tmp->YTotalLines();
31  const uint32_t xtotalpixels = tmp->XTotalPixels();
32  uint32_t datapos = 0;
33  uint32_t imagepos = 0;
34  bool forthline = true;
35  // advance datapos on every sampled pixel, advance imagepos only on pixels that are inside the image -> build up the lookup vector
36  for ( uint32_t l = 0 ; l < ytotallines ; l++ ) {
37  for ( uint32_t x = 0 ; x < xtotalpixels ; x++ ) {
38  // only pixels after y cutoff and before y retrace, and after the first 0.5*xturnpixels and before the last 0.5*xturnpixels (?)
39  if ( (l >= cutofflines) && (l < scanlines) && (x >= xturnpixels)) {
40  if ( forthline )
41  lookup->at(datapos) = imagepos++;
42  else
43  lookup->at(datapos) = --imagepos; // backline is opposite direction
44  }
45  else // Discard y cutoff and retrace pixels, and x turnpixels
46  lookup->at(datapos) = 0;
47 
48  datapos++;
49  }
50  if ( (l >= cutofflines) && (l < scanlines) )
51  imagepos += xtotalpixels - xturnpixels;
52  forthline = !forthline;
53  }
54  // Adjust for the scannerdelay by rotating the lookup vector (do not respect oversampling, since lookup is done on downsampled data
56  if ( lookup_rotation > 0 )
57  std::rotate(std::begin(*lookup), std::begin(*lookup)+lookup_rotation, std::end(*lookup));
58  if ( lookup_rotation < 0 )
59  std::rotate(std::begin(*lookup), std::end(*lookup)+lookup_rotation, std::end(*lookup));
60 }
61 
64  const uint32_t framesamples(svparameters->TotalPixels()); // fill y forth and back with the same x stuff
65  const uint32_t linesamples(svparameters->XTotalPixels());
66  const Scaler<int16_t> scaletodevice(-daqparameters->outputs->range(), daqparameters->outputs->range()); // convert full device range to full range of int16_t
67  const double zoom = svparameters->zoom();
68  const double range = daqparameters->outputs->maxoutputscanner() - daqparameters->outputs->minoutputscanner();
69  const double rangezoomed = range / zoom;
70 
71  // choose the maximum scanner amplitude for the larger frame side
72  double xrangezoomed;
73  if(tmp->xaspectratio >= tmp->yaspectratio) {
74  xrangezoomed = rangezoomed;
75  }
76  else {
77  xrangezoomed = static_cast<double>(tmp->xaspectratio) / static_cast<double>(tmp->yaspectratio) * rangezoomed;
78  }
79  const double devicecenter = (daqparameters->outputs->minoutputscanner() + daqparameters->outputs->maxoutputscanner()) * 0.5; // center of the device range (e.g. scanner takes +-3V -> center is 0V)
80  double center = devicecenter + svparameters->xoffset()*0.5*range; // center of the frame, offset +-1 means maximum offset
81  if ( center - 0.5*xrangezoomed < daqparameters->outputs->minoutputscanner() )
82  center = daqparameters->outputs->minoutputscanner()+0.5*xrangezoomed;
83  if ( center + 0.5*xrangezoomed > daqparameters->outputs->maxoutputscanner() )
84  center = daqparameters->outputs->maxoutputscanner()-0.5*xrangezoomed;
85  const double xminzoomed = center - 0.5*xrangezoomed; // minimum x value after zoom
86  const double xmaxzoomed = center + 0.5*xrangezoomed; // maximum x value after zoom
87  const double xslope = xrangezoomed / static_cast<double>(svparameters->XTotalPixels());
88 
89  uint32_t x = 0;
90  size_t cx = 0;
91 
92  do {
93  // fill in XTotalPixels() with increasing values (scanning forth) in X
94  x = 0;
95  for ( size_t i = cx ; i < cx+4*svparameters->XTotalPixels() ; i += 4, x++ )
96  vecptr->at(i) = scaletodevice(xminzoomed + x * xslope);
97 
98  cx += 4*linesamples;
99  if ( cx >= 4*framesamples) // for odd total number of lines, break do not scan back (although bad for scanner
100  break;
101 
102  // fill in XTotalPixels() with decreasing values (scanning back) in X
103  for ( size_t i = cx ; i < cx+4*svparameters->XTotalPixels() ; i += 4, x-- )
104  vecptr->at(i) = scaletodevice(xminzoomed + x * xslope);
105 
106  cx += 4*linesamples;
107  } while ( cx < 4*framesamples );
108 }
109 
110 
113  const uint32_t framesamples(tmp->TotalPixels());
114  const uint32_t linesamples(tmp->XTotalPixels());
115  const Scaler<int16_t> scaletodevice(-daqparameters->outputs->range(), daqparameters->outputs->range()); // convert full device range to full range of int16_t
116  const double zoom = tmp->zoom();
117  const double range = daqparameters->outputs->maxoutputscanner() - daqparameters->outputs->minoutputscanner();
118  const double rangezoomed = range / zoom;
119 
120  // choose the maximum scanner amplitude for the larger frame side
121  double yrangezoomed;
122  if(tmp->xaspectratio >= tmp->yaspectratio) {
123  yrangezoomed = static_cast<double>(tmp->yaspectratio) / static_cast<double>(tmp->xaspectratio) * rangezoomed;
124  }
125  else {
126  yrangezoomed = rangezoomed;
127  }
128  const double devicecenter = (daqparameters->outputs->minoutputscanner() + daqparameters->outputs->maxoutputscanner()) * 0.5; // center of the device range (e.g. scanner takes +-3V -> center is 0V)
129  double center = devicecenter + tmp->yoffset()*0.5*range; // center of the frame, offset +-1 means maximum offset
130  if ( center - 0.5*yrangezoomed < daqparameters->outputs->minoutputscanner() )
131  center = daqparameters->outputs->minoutputscanner()+0.5*yrangezoomed;
132  if ( center + 0.5*yrangezoomed > daqparameters->outputs->maxoutputscanner() )
133  center = daqparameters->outputs->maxoutputscanner()-0.5*yrangezoomed;
134  const double yminzoomed = center - 0.5*yrangezoomed; // minimum y value after zoom
135  const double ymaxzoomed = center + 0.5*yrangezoomed; // maximum y value after zoom
136  const double yscanslope = yrangezoomed / static_cast<double>(tmp->YScanLines());
137  const double yretraceslope = -yrangezoomed / static_cast<double>(tmp->YRetraceLines() * tmp->XTotalPixels());
138  const uint32_t yscanlinesamples = 4*tmp->YScanLines()*linesamples;
139  uint32_t yscan = 0;
140  uint32_t yretrace = 0;
141  size_t cy = 1; // y starts at sample 1
142 
143  do {
144  // fill in linesamples with the same value for scanning
145  if ( cy < (1 + yscanlinesamples) ) {
146  for ( size_t i = cy ; i < cy+4*linesamples ; i += 4 )
147  vecptr->at(i) = scaletodevice(yminzoomed + yscan * yscanslope);
148  yscan++;
149  }
150  else {
151  // do a smoother retracing
152  for ( size_t i = cy ; i < cy+4*linesamples ; i += 4 ) {
153  vecptr->at(i) = scaletodevice(ymaxzoomed + yretrace * yretraceslope);
154  yretrace++;
155  }
156  }
157  cy += 4*linesamples;
158  } while ( cy < (4*framesamples + 1) );
159 }
160 
163  const uint32_t framesamples(svparameters->TotalPixels());
164  const uint32_t linesamples(svparameters->XTotalPixels());
165  // convert full device range to full range of int16_t
166  const Scaler<int16_t> scaletodevice(-daqparameters->outputs->range(), daqparameters->outputs->range());
167  // get the voltage corresponding to current ETL position in micron and scale to device
168  const int16_t fastzoutdev = scaletodevice(zparameters->PositionToVoltage(svparameters->fastz()));
169  // z starts at sample 2
170  size_t cz = 2;
171 
172  do {
173  // Fast z position stays constant during normal frame scanning
174  for ( size_t i = cz ; i < cz + 4*linesamples ; i += 4 )
175  vecptr->at(i) = fastzoutdev;
176  cz += 4*linesamples;
177  } while ( cz < (4*framesamples + 2) );
178 }
179 
182  const uint32_t framesamples(svparameters->TotalPixels());
183  const uint32_t linesamples(svparameters->XTotalPixels());
184  const uint32_t cutofflines = tmp->YCutoffLines();
185  const uint32_t scanlines = tmp->YScanLines();
186  // convert full device range to full range of int16_t
187  const Scaler<int16_t> scaletodevice(-daqparameters->outputs->range(), daqparameters->outputs->range());
188  // get the voltage corresponding to current ETL position in micron and scale to device
189  const int16_t pockelsdev = scaletodevice(tmp->pockels());
190  // pockels starts at sample 3
191  size_t cp = 3;
192 
193  do {
194  // Pockels blanking during Y cutoff and retrace
195  if ( (cp < (3 + 4*cutofflines*linesamples))
196  || (cp > (3 + 4*scanlines*linesamples)) ) {
197  for ( size_t i = cp ; i < cp + 4*linesamples ; i += 4 )
198  vecptr->at(i) = scaletodevice(0.0);
199  }
200  else {
201  // Pockels stays constant during scan (no x-flyback blanking needed)
202  for ( size_t i = cp ; i < cp + 4*linesamples ; i += 4 )
203  vecptr->at(i) = pockelsdev;
204  }
205  cp += 4*linesamples;
206  } while ( cp < (4*framesamples + 2) );
207 }
208 
209 
210 }
virtual uint32_t XTotalPixels() const
Definition: Framescan.h:178
std::unique_ptr< Outputs > outputs
the output parameters
Definition: IO.h:767
ScopeNumber< double > pockels
pockels cell value
Definition: Framescan.h:163
Parameters for a ScannerVectorFrameBiDi.
Definition: Framescan.h:306
uint32_t YTotalLines() const override
Definition: Framescan.h:370
Parent class for frame scans.
ScopeNumber< double > xaspectratio
aspect ratio in x direction
Definition: Framescan.h:141
Class for scaling to the full range of a datatype.
Definition: helpers.h:113
void UpdateVector() override
Calculate the scanner vector based on the current parameters.
ScopeNumber< double > yaspectratio
aspect ratio in y direction
Definition: Framescan.h:144
Base class for all Scope datatypes here, provides a uniform interface (and saves typing...).
void FillP()
Fill the samples for the Pockels cell (cutoff&retrace blanking for x and y)
uint32_t TotalPixels() const override
Definition: Framescan.h:374
This is the include file for standard system include files, or project specific include files that ar...
int32_t ScannerDelaySamples(const bool &_respectoversampling) const
Definition: IO.cpp:655
uint32_t XTotalPixels() const override
Definition: Framescan.h:358
parameters::ScannerVectorFrameBasic * svparameters
current scanner vector parameter set (needs to be pointer for dynamic_cast in derived classes and bec...
int32_t lookup_rotation
how much is the current lookup vector rotated to adjust for scannerdelay
std::shared_ptr< std::vector< std::size_t > > lookup
gives the position in the image vector for each position in the acquired data vector (keep in mind th...
ScopeNumber< double > xoffset
x offset
Definition: Framescan.h:154
parameters::Daq * daqparameters
current daq parameter set
std::shared_ptr< std::vector< int16_t > > vecptr
the actual scanner vector (if fullframevector) with x, y, fast z, Pockels either interleaved (for ful...
ScannerVectorFrameBiDi(const ScannerVectorFillType &_filltype)
Describes the scanner vector type.
ScopeNumber< double > yoffset
y offset
Definition: Framescan.h:157
void FillZ()
Fill the samples for the fast z axis (stays constant here)
ScopeNumber< double > zoom
current zoom factor (from 1 to 20).
Definition: Framescan.h:151
void FillLookup()
Fill in the lookup vector.
ScopeNumber< double > fastz
current fast z position
Definition: Framescan.h:160
void FillY()
Fill the samples for the y scanner axis.
uint32_t TotalPixels() const override
Definition: Framescan.h:183
parameters::SCOPE_FPUZCONTROL_T * zparameters
current fast z parameter set
void FillX()
Fill the samples for the x scanner axis.