10 #include <QtCore/QString>
21 using std::tr1::placeholders::_1;
22 using std::tr1::placeholders::_2;
35 return matrixIndex.second * width + matrixIndex.first;
48 return make_pair(lhs.first - rhs.first, lhs.second - rhs.second);
61 return make_pair(lhs.first * rhs.first, lhs.second * rhs.second);
74 return make_pair(lhs.first + rhs.first, lhs.second + rhs.second);
89 return ((lhs.first + lhs.second) < rhs);
104 return make_pair(lhs.first / rhs.first,
105 lhs.second / rhs.second);
123 s.
value(
"sizeY", 1024).toInt()));
124 for (
int xx=0; xx<s.
value(
"sizeX", 1024).toInt(); ++xx)
125 for (
int yy=0; yy<s.
value(
"sizeY", 1024).toInt(); ++yy)
129 s.
value(
"FixedValue",
false).toBool() ? s.
value(
"Value",0).toFloat() : xx*yy;
130 string logout(
"processor " +
name() +
": creates test image with shape '" +
134 map<string,std::tr1::function<void(result_t&, CASSSettings&)> > functions;
135 functions[
"circle"] = std::tr1::bind(&
pp240::circle,
this,_1,_2);
136 functions[
"square"] = std::tr1::bind(&
pp240::square,
this,_1,_2);
138 functions[
"ellipse"] = std::tr1::bind(&
pp240::ellipse,
this,_1,_2);
139 functions[
"ring"] = std::tr1::bind(&
pp240::ring,
this,_1,_2);
141 for (
int i = 0; i <
size; ++i)
144 string type(s.
value(
"Type",
"Unknown").toString().toStdString());
145 if (type ==
"Unknown")
147 if (functions.find(type) == functions.end())
148 throw invalid_argument(
"pp240(): '" +
name() +
"': Unknown Mask Type '" +
161 const index_t center(make_pair(s.
value(
"CenterX",500).toUInt(),
162 s.
value(
"CenterY",500).toUInt()));
163 const index_t::first_type radius(s.
value(
"Radius",2).toUInt());
165 if ((center.first < radius) ||
166 (center.second < radius) ||
167 (static_cast<int>(data.
shape().first) <= (center.first + radius)) ||
168 (static_cast<int>(data.
shape().second) <= (center.second + radius)))
170 throw out_of_range(
"pp204:circle(): The radius '" +
toString(radius) +
171 "' is choosen to big and does not fit the image. Center of circle ("
175 const size_t radius_sq(radius*radius);
176 const index_t lowerLeft(make_pair(center.first-radius, center.second-radius));
177 const index_t upperRight(make_pair(center.first+radius, center.second+radius));
180 for (index_t::first_type row(lowerLeft.second); row < upperRight.second; ++row)
182 for (index_t::first_type column(lowerLeft.first); column < upperRight.first; ++column)
184 const index_t idx(make_pair(column,row));
185 const index_t idx_sq((idx - center)*(idx - center));
186 if (idx_sq < radius_sq)
194 const index_t lowerLeft(make_pair(s.
value(
"LowerLeftX",0).toUInt(),
195 s.
value(
"LowerLeftY",0).toUInt()));
196 const index_t upperRight(make_pair(s.
value(
"UpperRightX",1024).toUInt(),
197 s.
value(
"UpperRightY",1024).toUInt()));
198 if ((static_cast<int>(data.
shape().first) <= upperRight.first) ||
199 (
static_cast<int>(data.
shape().second) <= upperRight.second))
200 throw invalid_argument(
"addSquare(): The upper right coordinate ("
203 "is too big for the mask that has a size of ("
206 if((upperRight.first < lowerLeft.first) ||
207 (upperRight.second < lowerLeft.second))
208 throw out_of_range(
"addSquare(): The lowerLeft corner ("
211 "is not really to the lower left of ("
213 +
toString(upperRight.second)+
") ");
216 for (index_t::first_type row(lowerLeft.second); row <= upperRight.second; ++row)
218 for (index_t::first_type column(lowerLeft.first); column <= upperRight.first; ++column)
220 const index_t idx(make_pair(column,row));
228 const index_t center(make_pair(s.
value(
"CenterX",500).toUInt(),
229 s.
value(
"CenterY",500).toUInt()));
230 const index_t::first_type a(s.
value(
"SemiAxisX",5).toUInt());
231 const index_t::first_type b(s.
value(
"SemiAxisY",2).toUInt());
234 if ((center.first < a) ||
236 throw invalid_argument(
"addCircle(): The semi axis a '" +
toString(a) +
238 "' are choosen to big and do not fit with center ("
241 if((static_cast<int>(data.
shape().first) <= (center.first + a)) ||
242 (static_cast<int>(data.
shape().second) <= (center.second + b)))
243 throw out_of_range(
"addCircle(): The semi axis boundaries a '" +
toString(center.first + a) +
244 "' and b '" +
toString(center.second + b) +
245 "' are choosen to big and do not fit with center ("
249 const index_t lowerLeft(make_pair(center.first-a, center.second-b));
250 const index_t upperRight(make_pair(center.first+a, center.second+b));
251 const index_t axis_sq(make_pair(a,b)*make_pair(a,b));
253 for (index_t::first_type row(lowerLeft.second); row <= upperRight.second; ++row)
255 for (index_t::first_type column(lowerLeft.first); column <= upperRight.first; ++column)
258 const index_t idx(make_pair(column,row));
259 const index_t idx_sq((idx - center)*(idx - center));
260 const indexf_t idx_tmp(idx_sq / axis_sq);
269 const index_t outer_center(make_pair(s.
value(
"OuterCenterX",500).toUInt(),
270 s.
value(
"OuterCenterY",500).toUInt()));
271 const index_t::first_type outer_a(s.
value(
"OuterSemiAxisX",5).toUInt());
272 const index_t::first_type outer_b(s.
value(
"OuterSemiAxisY",2).toUInt());
273 const index_t inner_center(make_pair(s.
value(
"InnerCenterX",500).toUInt(),
274 s.
value(
"InnerCenterY",500).toUInt()));
275 const index_t::first_type inner_a(s.
value(
"InnerSemiAxisX",20).toUInt());
276 const index_t::first_type inner_b(s.
value(
"InnerSemiAxisY",20).toUInt());
279 if ((outer_center.first < outer_a) ||
280 (outer_center.second < outer_b))
281 throw invalid_argument(
"addCircle(): The outer semi axis x '" +
283 "' are choosen to big and do not fit with center ("
285 +
toString(outer_center.second)+
")");
286 if ((static_cast<int>(data.
shape().first) <= (outer_center.first + outer_a)) ||
287 (static_cast<int>(data.
shape().second) <= (outer_center.second + outer_b)))
288 throw out_of_range(
string(
"addCircle(): The outer semi axis boundaries a '") +
289 toString(outer_center.first + outer_a) +
290 "' and b '" +
toString(outer_center.second + outer_b) +
291 "' are choosen to big and do not fit into image ("
295 if ((inner_center.first < inner_a) ||
296 (inner_center.second < inner_b))
297 throw invalid_argument(
string(
"addCircle(): The inner semi axis x '") +
299 "' are choosen to big and do not fit with center ("
301 +
toString(inner_center.second)+
")");
303 if((static_cast<int>(data.
shape().first) <= (inner_center.first + inner_a)) ||
304 (static_cast<int>(data.
shape().second) <= (inner_center.second + inner_b)))
305 throw out_of_range(
string(
"addCircle(): The inner semi axis boundaries a '") +
306 toString(inner_center.first + inner_a) +
"' and b '" +
307 toString(inner_center.second + inner_b) +
308 "' are choosen to big and do not fit into image ("
312 const size_t min_col(min(outer_center.first - outer_a,
313 inner_center.first - inner_a));
314 const size_t max_col(max(outer_center.first + outer_a,
315 inner_center.first + inner_a));
316 const size_t min_row(min(outer_center.second - outer_b,
317 inner_center.second - inner_b));
318 const size_t max_row(max(outer_center.second + outer_b,
319 inner_center.second + inner_b));
321 const index_t outer_axis_sq(make_pair(outer_a,outer_b)*make_pair(outer_a,outer_b));
322 const index_t inner_axis_sq(make_pair(inner_a,inner_b)*make_pair(inner_a,inner_b));
324 for (
size_t row(min_row); row <= max_row; ++row)
326 for (
size_t column(min_col); column <= max_col; ++column)
328 const index_t idx(make_pair(column,row));
330 const index_t idx_sq_inner((idx - inner_center)*(idx - inner_center));
331 const indexf_t idx_tmp_inner(idx_sq_inner / inner_axis_sq);
332 const bool isNotInInner(!(idx_tmp_inner < 1));
334 const index_t idx_sq_outer((idx - outer_center)*(idx - outer_center));
335 const indexf_t idx_tmp_outer(idx_sq_outer / outer_axis_sq);
336 const bool isInOuter(idx_tmp_outer < 1);
338 if (isInOuter && isNotInInner)
347 s.
value(
"PointA_Y",500).toUInt()));
348 const index_t B(make_pair(s.
value(
"PointB_X",500).toUInt(),
349 s.
value(
"PointB_Y",500).toUInt()));
350 const index_t C(make_pair(s.
value(
"PointC_X",500).toUInt(),
351 s.
value(
"PointC_Y",500).toUInt()));
356 throw invalid_argument(
"addTriangle(): the 3 Points "
360 "are inconsistent.");
362 if (static_cast<int>(data.
shape().first) <= A.first ||
363 static_cast<int>(data.
shape().first) <= B.first ||
364 static_cast<int>(data.
shape().first) <= C.first ||
365 static_cast<int>(data.
shape().second) <= A.second ||
366 static_cast<int>(data.
shape().second) <= B.second ||
367 static_cast<int>(data.
shape().second) <= C.second )
368 throw out_of_range(
"addTriangle(): the 3 Points "
372 "are outside the the mask boundaries "+
376 const index_t::first_type minX(min(min(A.first,B.first),C.first));
377 const index_t::first_type minY(min(min(A.second,B.second),C.second));
378 const index_t::first_type maxX(max(max(A.first,B.first),C.first));
379 const index_t::first_type maxY(max(max(A.second,B.second),C.second));
380 const index_t lowerLeft(make_pair(minX,minY));
381 const index_t upperRight(make_pair(maxX,maxY));
382 const float x1(A.first);
383 const float x2(B.first);
384 const float x3(C.first);
385 const float y1(A.second);
386 const float y2(B.second);
387 const float y3(C.second);
388 const float denom( (y2-y3)*(x1-x3) + (x3-x2)*(y1-y3) );
390 for (index_t::first_type row(lowerLeft.second); row <= upperRight.second; ++row)
392 for (index_t::first_type column(lowerLeft.first); column <= upperRight.first; ++column)
394 const index_t P(make_pair(column,row));
395 const float x(P.first);
396 const float y(P.second);
398 const float l1( ( (y2-y3)*(x-x3) + (x3-x2)*(y-y3) ) / denom );
399 const float l2( ( (y3-y1)*(x-x3) + (x1-x3)*(y-y3) ) / denom );
400 const float l3( 1 - l1 - l2 );
402 if ((0<=l1) && (l1<=1) && (0<=l2) && (l2<=1) && (0<=l3) && (l3<=1))
CachedList::item_type result_t
define the results
void triangle(result_t &data, CASSSettings &s)
add a triangluar element to the mask
void ring(result_t &data, CASSSettings &s)
add a ring
pp240::indexf_t operator/(const pp240::indexf_t &lhs, const pp240::indexf_t &rhs)
operates devides on two indices
pp240::index_t::first_type toOneD(const pp240::index_t matrixIndex, pp240::index_t::first_type width)
helper to convert shape into the 1D index
const name_t name() const
retrieve the name of this processor
result_t::shared_pointer _result
the constant image
std::tr1::shared_ptr< self_type > shared_pointer
a shared pointer of this class
pp240::index_t operator*(const pp240::index_t &lhs, const pp240::index_t &rhs)
operates times on two indices
pp240::index_t operator+(const pp240::index_t &lhs, const pp240::index_t &rhs)
operates a plus on two indices
size_t bin(const Axis< AxisPrecessionType > &xaxis, const ResultValueType &value)
calculate the index of the lineared array
things written only at end of run H5Dump ProcessorSummary size
bool operator<(const pp240::indexf_t &lhs, const pp240::indexf_t::first_type rhs)
operates less of an indices to a scalar
static void add(Level level, const std::string &line)
add a string to the log
fromStdString(const std::string &str)
beginReadArray(const QString &prefix)
base class for processors.
std::pair< int, int > index_t
define the index type
pp240::index_t operator-(const pp240::index_t &lhs, const pp240::index_t &rhs)
operates a minus on two indices
void ellipse(result_t &data, CASSSettings &s)
add a ellipsodial element to the mask
std::string toString(const Type &t)
convert any type to a string
auxiliary data[Processor]
value(const QString &key, const QVariant &defaultValue=QVariant()
void circle(result_t &data, CASSSettings &s)
add a circle to the mask
file contains specialized class that do the settings for cass
void square(result_t &data, CASSSettings &s)
add a square element to the mask
pp240(const name_t &)
constructor.
std::pair< float, float > indexf_t
define a floating point version of the index
shape_t shape() const
return the shape of the result
std::string name_t
define the name type
contains a logger for cass
virtual void loadSettings(size_t)
load the settings of this pp
processors to generate a test image
beginGroup(const QString &prefix)