9 #include <tr1/functional>
47 index_t
operator+(
const index_t& lhs,
const index_t& rhs)
49 return make_pair(lhs.first + rhs.first,
50 lhs.second + rhs.second);
63 index_t
operator-(
const index_t& lhs,
const index_t& rhs)
65 return make_pair(lhs.first - rhs.first,
66 lhs.second - rhs.second);
79 index_t
operator*(
const index_t& lhs,
const index_t& rhs)
81 return make_pair(lhs.first * rhs.first,
82 lhs.second * rhs.second);
95 indexf_t
operator/(
const indexf_t& lhs,
const indexf_t& rhs)
97 return make_pair(lhs.first / rhs.first,
98 lhs.second / rhs.second);
111 bool operator<(
const indexf_t& lhs,
const indexf_t::first_type rhs)
113 return ((lhs.first + lhs.second) < rhs);
126 index_t::first_type
dot(
const index_t& lhs,
const index_t& rhs)
128 return ((lhs.first*rhs.first)+(lhs.second*lhs.second));
142 return matrixIndex.second * width + matrixIndex.first;
155 return make_pair(linearisedIndex % width,
156 linearisedIndex / width);
178 const index_t center(make_pair(s.
value(
"CenterX",500).toUInt(),
179 s.
value(
"CenterY",500).toUInt()));
180 const index_t::first_type radius(s.
value(
"Radius",2).toUInt());
182 if ((center.first < radius) ||
183 (center.second < radius) ||
184 (static_cast<int>(data.
columns) <= (center.first + radius)) ||
185 (
static_cast<int>(data.
rows) <= (center.second + radius)))
187 throw out_of_range(
"addCircle(): The radius '" +
toString(radius) +
188 "' is choosen to big and does not fit the image. Center of cirlce ("
192 const size_t radius_sq(radius*radius);
193 const index_t lowerLeft(make_pair(center.first-radius, center.second-radius));
194 const index_t upperRight(make_pair(center.first+radius, center.second+radius));
197 for (index_t::first_type row(lowerLeft.second); row < upperRight.second; ++row)
199 for (index_t::first_type column(lowerLeft.first); column < upperRight.first; ++column)
201 const index_t idx(make_pair(column,row));
202 const index_t idx_sq((idx - center)*(idx - center));
228 const index_t lowerLeft(make_pair(s.
value(
"LowerLeftX",0).toUInt(),
229 s.
value(
"LowerLeftY",0).toUInt()));
230 const index_t upperRight(make_pair(s.
value(
"UpperRightX",1024).toUInt(),
231 s.
value(
"UpperRightY",1024).toUInt()));
232 if ((static_cast<int>(data.
columns) <= upperRight.first) ||
233 (static_cast<int>(data.
rows) <= upperRight.second))
234 throw invalid_argument(
"addSquare(): The upper right coordinate ("
237 "is too big for the mask that has a size of ("
240 if((upperRight.first < lowerLeft.first) ||
241 (upperRight.second < lowerLeft.second))
242 throw out_of_range(
"addSquare(): The lowerLeft corner ("
245 "is not really to the lower left of ("
247 +
toString(upperRight.second)+
") ");
250 for (index_t::first_type row(lowerLeft.second); row <= upperRight.second; ++row)
252 for (index_t::first_type column(lowerLeft.first); column <= upperRight.first; ++column)
254 const index_t idx(make_pair(column,row));
281 const index_t center(make_pair(s.
value(
"CenterX",500).toUInt(),
282 s.
value(
"CenterY",500).toUInt()));
283 const index_t::first_type a(s.
value(
"SemiAxisX",5).toUInt());
284 const index_t::first_type b(s.
value(
"SemiAxisY",2).toUInt());
287 if ((center.first < a) ||
289 throw invalid_argument(
"addCircle(): The semi axis a '" +
toString(a) +
291 "' are choosen to big and do not fit with center ("
294 if((static_cast<int>(data.
columns) <= (center.first + a)) ||
295 (static_cast<int>(data.
rows) <= (center.second + b)))
296 throw out_of_range(
"addCircle(): The semi axis boundaries a '" +
toString(center.first + a) +
297 "' and b '" +
toString(center.second + b) +
298 "' are choosen to big and do not fit with center ("
302 const index_t lowerLeft(make_pair(center.first-a, center.second-b));
303 const index_t upperRight(make_pair(center.first+a, center.second+b));
304 const index_t axis_sq(make_pair(a,b)*make_pair(a,b));
306 for (index_t::first_type row(lowerLeft.second); row <= upperRight.second; ++row)
308 for (index_t::first_type column(lowerLeft.first); column <= upperRight.first; ++column)
311 const index_t idx(make_pair(column,row));
312 const index_t idx_sq((idx - center)*(idx - center));
313 const indexf_t idx_tmp(idx_sq / axis_sq);
343 const index_t outer_center(make_pair(s.
value(
"OuterCenterX",500).toUInt(),
344 s.
value(
"OuterCenterY",500).toUInt()));
345 const index_t::first_type outer_a(s.
value(
"OuterSemiAxisX",5).toUInt());
346 const index_t::first_type outer_b(s.
value(
"OuterSemiAxisY",2).toUInt());
347 const index_t inner_center(make_pair(s.
value(
"InnerCenterX",500).toUInt(),
348 s.
value(
"InnerCenterY",500).toUInt()));
349 const index_t::first_type inner_a(s.
value(
"InnerSemiAxisX",20).toUInt());
350 const index_t::first_type inner_b(s.
value(
"InnerSemiAxisY",20).toUInt());
353 if ((outer_center.first < outer_a) ||
354 (outer_center.second < outer_b))
355 throw invalid_argument(
"addCircle(): The outer semi axis x '" +
toString(outer_a) +
357 "' are choosen to big and do not fit with center ("
359 +
toString(outer_center.second)+
")");
360 if ((static_cast<int>(data.
columns) <= (outer_center.first + outer_a)) ||
361 (static_cast<int>(data.
rows) <= (outer_center.second + outer_b)))
362 throw out_of_range(
"addCircle(): The outer semi axis boundaries a '" +
toString(outer_center.first + outer_a) +
363 "' and b '" +
toString(outer_center.second + outer_b) +
364 "' are choosen to big and do not fit into image ("
368 if ((inner_center.first < inner_a) ||
369 (inner_center.second < inner_b))
370 throw invalid_argument(
"addCircle(): The inner semi axis x '" +
toString(inner_a) +
372 "' are choosen to big and do not fit with center ("
374 +
toString(inner_center.second)+
")");
376 if((static_cast<int>(data.
columns) <= (inner_center.first + inner_a)) ||
377 (static_cast<int>(data.
rows) <= (inner_center.second + inner_b)))
378 throw out_of_range(
"addCircle(): The inner semi axis boundaries a '" +
toString(inner_center.first + inner_a) +
379 "' and b '" +
toString(inner_center.second + inner_b) +
380 "' are choosen to big and do not fit into image ("
384 const size_t min_col(min(outer_center.first - outer_a,
385 inner_center.first - inner_a));
386 const size_t max_col(max(outer_center.first + outer_a,
387 inner_center.first + inner_a));
388 const size_t min_row(min(outer_center.second - outer_b,
389 inner_center.second - inner_b));
390 const size_t max_row(max(outer_center.second + outer_b,
391 inner_center.second + inner_b));
393 const index_t outer_axis_sq(make_pair(outer_a,outer_b)*make_pair(outer_a,outer_b));
394 const index_t inner_axis_sq(make_pair(inner_a,inner_b)*make_pair(inner_a,inner_b));
396 for (
size_t row(min_row); row <= max_row; ++row)
398 for (
size_t column(min_col); column <= max_col; ++column)
400 const index_t idx(make_pair(column,row));
402 const index_t idx_sq_inner((idx - inner_center)*(idx - inner_center));
403 const indexf_t idx_tmp_inner(idx_sq_inner / inner_axis_sq);
404 const bool isNotInInner(!(idx_tmp_inner < 1));
406 const index_t idx_sq_outer((idx - outer_center)*(idx - outer_center));
407 const indexf_t idx_tmp_outer(idx_sq_outer / outer_axis_sq);
408 const bool isInOuter(idx_tmp_outer < 1);
410 data.
mask[
TwoD2OneD(idx,width)] *= !(isInOuter && isNotInInner);
449 const index_t
A(make_pair(s.
value(
"PointA_X",500).toUInt(),
450 s.
value(
"PointA_Y",500).toUInt()));
451 const index_t B(make_pair(s.
value(
"PointB_X",500).toUInt(),
452 s.
value(
"PointB_Y",500).toUInt()));
453 const index_t C(make_pair(s.
value(
"PointC_X",500).toUInt(),
454 s.
value(
"PointC_Y",500).toUInt()));
459 throw invalid_argument(
"addTriangle(): the 3 Points "
463 "are inconsistent.");
465 if (static_cast<int>(data.
columns) <= A.first ||
466 static_cast<int>(data.
columns) <= B.first ||
467 static_cast<int>(data.
columns) <= C.first ||
468 static_cast<int>(data.
rows) <= A.second ||
469 static_cast<int>(data.
rows) <= B.second ||
470 static_cast<int>(data.
rows) <= C.second )
471 throw out_of_range(
"addTriangle(): the 3 Points "
475 "are outside the the mask boundaries "+
479 const index_t::first_type minX(min(min(A.first,B.first),C.first));
480 const index_t::first_type minY(min(min(A.second,B.second),C.second));
481 const index_t::first_type maxX(max(max(A.first,B.first),C.first));
482 const index_t::first_type maxY(max(max(A.second,B.second),C.second));
483 const index_t lowerLeft(make_pair(minX,minY));
484 const index_t upperRight(make_pair(maxX,maxY));
485 const float x1(A.first);
486 const float x2(B.first);
487 const float x3(C.first);
488 const float y1(A.second);
489 const float y2(B.second);
490 const float y3(C.second);
491 const float denom( (y2-y3)*(x1-x3) + (x3-x2)*(y1-y3) );
493 for (index_t::first_type row(lowerLeft.second); row <= upperRight.second; ++row)
495 for (index_t::first_type column(lowerLeft.first); column <= upperRight.first; ++column)
497 const index_t P(make_pair(column,row));
498 const float x(P.first);
499 const float y(P.second);
501 const float l1( ( (y2-y3)*(x-x3) + (x3-x2)*(y-y3) ) / denom );
502 const float l2( ( (y3-y1)*(x-x3) + (x1-x3)*(y-y3) ) / denom );
503 const float l3( 1 - l1 - l2 );
506 (0<=l2) && (l2<=1) &&
514 map<string,std::tr1::function<void(CommonData&, CASSSettings&)> > functions;
523 fill(data.
mask.begin(),data.
mask.end(),1);
525 for (
int i = 0; i <
size; ++i)
528 string type(s.
value(
"MaskElementType",
"Unknown").toString().toStdString());
529 if (type ==
"Unknown")
531 if (functions.find(type) == functions.end())
532 throw invalid_argument(
"createCASSMask(): Unknown Mask Element Type '" +type+
"'");
534 functions[type](
data,s);
pair< int, int > index_t
an index within a matrix
void addRing(CommonData &data, CASSSettings &s)
add a ring
indexf_t operator/(const indexf_t &lhs, const indexf_t &rhs)
operates devides on two indices
void addCircle(CommonData &data, CASSSettings &s)
add a circle to the mask
index_t operator*(const index_t &lhs, const index_t &rhs)
operates times on two indices
index_t operator+(const index_t &lhs, const index_t &rhs)
operates a plus on two indices
things written only at end of run H5Dump ProcessorSummary size
index_t OneD2TwoD(const size_t linearisedIndex, const size_t width)
convert linearised index to matrixindex
static void add(Level level, const std::string &line)
add a string to the log
index_t::first_type dot(const index_t &lhs, const index_t &rhs)
calculate the scalar product of two indices
beginReadArray(const QString &prefix)
void addTriangle(CommonData &data, CASSSettings &s)
add a triangluar element to the mask
size_t columns
the width of the maps
size_t rows
the height of the maps
contains definition of the mask of a pixeldetector
pair< float, float > indexf_t
an index within a matrix but with with floating point precision
std::string toString(const Type &t)
convert any type to a string
auxiliary data[Processor]
Data used commonly for one AdvancedDetector.
value(const QString &key, const QVariant &defaultValue=QVariant()
bool operator<(const indexf_t &lhs, const indexf_t::first_type rhs)
operates less of an indices to a scalar
size_t TwoD2OneD(const index_t &matrixIndex, const size_t width)
convert matrix index to linearised index
QReadWriteLock lock
lock to synchronize read and write acces to the common data
contains the common data for one advanced pixeldetector
file contains specialized class that do the settings for cass
void addSquare(CommonData &data, CASSSettings &s)
add a square element to the mask
void createCASSMask(CommonData &data, CASSSettings &s)
create the mask
contains a logger for cass
mask_t mask
the detector mask
index_t operator-(const index_t &lhs, const index_t &rhs)
operates a minus on two indices
void addEllipse(CommonData &data, CASSSettings &s)
add a ellipsodial element to the mask