1
2
3 #include "regionstyles.h"
4 #include "tgl.h"
5 #include "tcolorfunctions.h"
6 #include "trandom.h"
7 #include "colorfxutils.h"
8 #include "tregion.h"
9 #include "tcurves.h"
10 #include "tmathutil.h"
11 #include "tstencilcontrol.h"
12
13 //***************************************************************************
14 // MovingModifier implementation
15 //***************************************************************************
16
clone() const17 TOutlineStyle::RegionOutlineModifier *MovingModifier::clone() const {
18 return new MovingModifier(*this);
19 }
20
21 //------------------------------------------------------------
22
modify(TRegionOutline & outline) const23 void MovingModifier::modify(TRegionOutline &outline) const {
24 TRegionOutline::Boundary::iterator regIt = outline.m_exterior.begin();
25 TRegionOutline::Boundary::iterator regItEnd = outline.m_exterior.end();
26
27 TRegionOutline::PointVector::iterator pIt;
28 TRegionOutline::PointVector::iterator pItEnd;
29
30 for (; regIt != regItEnd; ++regIt) {
31 pIt = regIt->begin();
32 pItEnd = regIt->end();
33
34 for (; pIt != pItEnd; ++pIt) {
35 pIt->x += m_move.x;
36 pIt->y += m_move.y;
37 }
38 }
39
40 regIt = outline.m_interior.begin();
41 regItEnd = outline.m_interior.end();
42 for (; regIt != regItEnd; ++regIt) {
43 pIt = regIt->begin();
44 pItEnd = regIt->end();
45
46 for (; pIt != pItEnd; ++pIt) {
47 pIt->x += m_move.x;
48 pIt->y += m_move.y;
49 }
50 }
51 }
52
53 //***************************************************************************
54 // MovingSolidColor implementation
55 //***************************************************************************
56
MovingSolidColor(const TPixel32 & color,const TPointD & move)57 MovingSolidColor::MovingSolidColor(const TPixel32 &color, const TPointD &move)
58 : TSolidColorStyle(color) {
59 m_regionOutlineModifier = new MovingModifier(move);
60 }
61
62 //------------------------------------------------------------
63
clone() const64 TColorStyle *MovingSolidColor::clone() const {
65 return new MovingSolidColor(*this);
66 }
67
68 //------------------------------------------------------------
69
loadData(TInputStreamInterface & is)70 void MovingSolidColor::loadData(TInputStreamInterface &is) {
71 TSolidColorStyle::loadData(is);
72 delete m_regionOutlineModifier;
73 MovingModifier *mov = new MovingModifier(TPointD());
74 mov->loadData(is);
75 m_regionOutlineModifier = mov;
76 }
77
78 //------------------------------------------------------------
79
saveData(TOutputStreamInterface & os) const80 void MovingSolidColor::saveData(TOutputStreamInterface &os) const {
81 TSolidColorStyle::saveData(os);
82
83 assert(m_regionOutlineModifier);
84 ((MovingModifier *)m_regionOutlineModifier)->saveData(os);
85 }
86
87 //------------------------------------------------------------
88
getParamCount() const89 int MovingSolidColor::getParamCount() const { return 2; }
90
91 //-----------------------------------------------------------------------------
92
getParamType(int index) const93 TColorStyle::ParamType MovingSolidColor::getParamType(int index) const {
94 assert(0 <= index && index < getParamCount());
95 return TColorStyle::DOUBLE;
96 }
97
98 //-----------------------------------------------------------------------------
99
getParamNames(int index) const100 QString MovingSolidColor::getParamNames(int index) const {
101 assert(0 <= index && index < 2);
102
103 return index == 0
104 ? QCoreApplication::translate("MovingSolidColor", "Horiz Offset")
105 : QCoreApplication::translate("MovingSolidColor", "Vert Offset");
106 }
107
108 //-----------------------------------------------------------------------------
109
getParamRange(int index,double & min,double & max) const110 void MovingSolidColor::getParamRange(int index, double &min,
111 double &max) const {
112 assert(0 <= index && index < 2);
113 min = -100.0;
114 max = 100.0;
115 }
116
117 //-----------------------------------------------------------------------------
118
getParamValue(TColorStyle::double_tag,int index) const119 double MovingSolidColor::getParamValue(TColorStyle::double_tag,
120 int index) const {
121 assert(0 <= index && index < 2);
122
123 if (index)
124 return ((MovingModifier *)m_regionOutlineModifier)->getMovePoint().y;
125 else
126 return ((MovingModifier *)m_regionOutlineModifier)->getMovePoint().x;
127 }
128
129 //-----------------------------------------------------------------------------
130
setParamValue(int index,double value)131 void MovingSolidColor::setParamValue(int index, double value) {
132 assert(0 <= index && index < 2);
133
134 TPointD oldMove = ((MovingModifier *)m_regionOutlineModifier)->getMovePoint();
135
136 if (!index) {
137 if (oldMove.x != value) {
138 delete m_regionOutlineModifier;
139 oldMove.x = value;
140 m_regionOutlineModifier = new MovingModifier(oldMove);
141 updateVersionNumber();
142 }
143 } else {
144 if (oldMove.y != value) {
145 delete m_regionOutlineModifier;
146 oldMove.y = value;
147 m_regionOutlineModifier = new MovingModifier(oldMove);
148 updateVersionNumber();
149 }
150 }
151 }
152
153 //------------------------------------------------------------
154
drawRegion(const TColorFunction * cf,const bool antiAliasing,TRegionOutline & boundary) const155 void MovingSolidColor::drawRegion(const TColorFunction *cf,
156 const bool antiAliasing,
157 TRegionOutline &boundary) const {
158 TSolidColorStyle::drawRegion(cf, true, boundary);
159 }
160
161 //***************************************************************************
162 // ShadowStyle implementation
163 //***************************************************************************
164
ShadowStyle(const TPixel32 & bgColor,const TPixel32 & shadowColor,const TPointD & shadowDirection,double len,double density)165 ShadowStyle::ShadowStyle(const TPixel32 &bgColor, const TPixel32 &shadowColor,
166 const TPointD &shadowDirection, double len,
167 double density)
168 : TSolidColorStyle(bgColor)
169 , m_shadowColor(shadowColor)
170 , m_shadowDirection(normalize(shadowDirection))
171 , m_len(len)
172 , m_density(density) {}
173
174 //------------------------------------------------------------
175
clone() const176 TColorStyle *ShadowStyle::clone() const { return new ShadowStyle(*this); }
177
178 //------------------------------------------------------------
179
loadData(TInputStreamInterface & is)180 void ShadowStyle::loadData(TInputStreamInterface &is) {
181 TSolidColorStyle::loadData(is);
182 is >> m_shadowDirection.x >> m_shadowDirection.y;
183 is >> m_density;
184 is >> m_shadowColor;
185 is >> m_len;
186 }
187
188 //------------------------------------------------------------
189
saveData(TOutputStreamInterface & os) const190 void ShadowStyle::saveData(TOutputStreamInterface &os) const {
191 TSolidColorStyle::saveData(os);
192 os << m_shadowDirection.x << m_shadowDirection.y;
193 os << m_density;
194 os << m_shadowColor;
195 os << m_len;
196 }
197
198 //------------------------------------------------------------
199
getParamCount() const200 int ShadowStyle::getParamCount() const { return 3; }
201
202 //-----------------------------------------------------------------------------
203
getParamType(int index) const204 TColorStyle::ParamType ShadowStyle::getParamType(int index) const {
205 assert(0 <= index && index < getParamCount());
206 return TColorStyle::DOUBLE;
207 }
208
209 //-----------------------------------------------------------------------------
210
getParamNames(int index) const211 QString ShadowStyle::getParamNames(int index) const {
212 assert(0 <= index && index < 3);
213
214 switch (index) {
215 case 0:
216 return QCoreApplication::translate("ShadowStyle", "Angle");
217 case 1:
218 return QCoreApplication::translate("ShadowStyle", "Density");
219 case 2:
220 return QCoreApplication::translate("ShadowStyle", "Length");
221
222 default:
223 return QString();
224 }
225
226 assert(0);
227 return QString();
228 }
229
230 //-----------------------------------------------------------------------------
231
getParamRange(int index,double & min,double & max) const232 void ShadowStyle::getParamRange(int index, double &min, double &max) const {
233 assert(0 <= index && index < 3);
234
235 switch (index) {
236 case 0:
237 min = 0.0;
238 max = 360.0;
239 break;
240 case 1:
241 min = 0.0;
242 max = 1.0;
243 break;
244 case 2:
245 min = 0.0;
246 max = 100.0;
247 break;
248 }
249 }
250
251 //-----------------------------------------------------------------------------
252
getParamValue(TColorStyle::double_tag,int index) const253 double ShadowStyle::getParamValue(TColorStyle::double_tag, int index) const {
254 assert(0 <= index && index < 3);
255
256 double degree;
257
258 switch (index) {
259 case 0:
260 degree = asin(m_shadowDirection.y);
261 if (m_shadowDirection.x < 0) degree = M_PI - degree;
262 if (degree < 0) degree += M_2PI;
263 return degree * M_180_PI;
264
265 case 1:
266 return m_density;
267
268 case 2:
269 return m_len;
270 }
271
272 assert(0);
273 return 0.0;
274 }
275
276 //-----------------------------------------------------------------------------
277
setParamValue(int index,double value)278 void ShadowStyle::setParamValue(int index, double value) {
279 assert(0 <= index && index < 3);
280 double degree;
281
282 switch (index) {
283 case 0:
284 degree = value * M_PI_180;
285 m_shadowDirection.x = cos(degree);
286 m_shadowDirection.y = sin(degree);
287 break;
288
289 case 1:
290 m_density = value;
291 break;
292
293 case 2:
294 m_len = value;
295 break;
296 }
297 }
298
299 //------------------------------------------------------------
300
drawPolyline(const TColorFunction * cf,std::vector<T3DPointD> & polyline,TPointD shadowDirection) const301 void ShadowStyle::drawPolyline(const TColorFunction *cf,
302 std::vector<T3DPointD> &polyline,
303 TPointD shadowDirection) const {
304 int i;
305 int stepNumber;
306 double distance;
307
308 TPointD v1, v2, diff, midPoint, ratio;
309 double len;
310
311 TPixel32 color;
312 if (cf)
313 color = (*(cf))(m_shadowColor);
314 else
315 color = m_shadowColor;
316
317 tglColor(color);
318
319 // glEnable(GL_BLEND);
320 // glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
321 //// <-- tglEnableBlending();
322
323 TRegionOutline::PointVector::iterator it;
324 TRegionOutline::PointVector::iterator it_b = polyline.begin();
325 TRegionOutline::PointVector::iterator it_e = polyline.end();
326
327 v1.x = polyline.back().x;
328 v1.y = polyline.back().y;
329
330 for (it = it_b; it != it_e; ++it) {
331 v2.x = it->x;
332 v2.y = it->y;
333 if (v1 == v2) continue;
334
335 diff = normalize(rotate90(v2 - v1));
336 len = diff * shadowDirection;
337
338 if (len > 0) {
339 distance = tdistance(v1, v2) * m_density;
340
341 ratio = (v2 - v1) * (1.0 / distance);
342 midPoint = v1;
343 stepNumber = (int)distance;
344
345 for (i = 0; i < stepNumber; i++) {
346 glBegin(GL_LINE_STRIP);
347
348 tglColor(TPixel32(color.r, color.g, color.b, 0));
349 tglVertex(midPoint);
350
351 tglColor(color);
352 tglVertex(midPoint + (shadowDirection * len * m_len * 0.5));
353
354 tglColor(TPixel32(color.r, color.g, color.b, 0));
355 tglVertex(midPoint + (shadowDirection * len * m_len));
356
357 midPoint += ratio;
358
359 glEnd();
360 }
361 }
362
363 v1 = v2;
364 }
365 // tglColor(TPixel32::White);
366 }
367
368 //------------------------------------------------------------
369
drawRegion(const TColorFunction * cf,const bool antiAliasing,TRegionOutline & regionOutline) const370 void ShadowStyle::drawRegion(const TColorFunction *cf, const bool antiAliasing,
371 TRegionOutline ®ionOutline) const {
372 TStencilControl *stenc = TStencilControl::instance();
373
374 TPixel32 backgroundColor = TSolidColorStyle::getMainColor();
375 if (cf) backgroundColor = (*(cf))(backgroundColor);
376
377 ////stenc->beginMask();
378 /*
379 glBegin(GL_QUADS);
380 glVertex2d (regionOutline.m_bbox.getP00().x, regionOutline.m_bbox.getP00().y);
381 glVertex2d (regionOutline.m_bbox.getP01().x, regionOutline.m_bbox.getP01().y);
382 glVertex2d (regionOutline.m_bbox.getP11().x, regionOutline.m_bbox.getP11().y);
383 glVertex2d (regionOutline.m_bbox.getP10().x, regionOutline.m_bbox.getP10().y);
384 glEnd();
385 */
386 ////stenc->endMask();
387 ////stenc->enableMask(TStencilControl::SHOW_INSIDE);
388
389 if (backgroundColor.m == 0) { // only to create stencil mask
390 TSolidColorStyle appStyle(TPixel32::White);
391 stenc->beginMask();
392 appStyle.drawRegion(0, false, regionOutline);
393 } else {
394 stenc->beginMask(TStencilControl::DRAW_ALSO_ON_SCREEN);
395 TSolidColorStyle::drawRegion(cf, antiAliasing, regionOutline);
396 }
397 stenc->endMask();
398 stenc->enableMask(TStencilControl::SHOW_INSIDE);
399
400 TRegionOutline::Boundary::iterator regions_it;
401 TRegionOutline::Boundary::iterator regions_it_b =
402 regionOutline.m_exterior.begin();
403 TRegionOutline::Boundary::iterator regions_it_e =
404 regionOutline.m_exterior.end();
405 for (regions_it = regions_it_b; regions_it != regions_it_e; ++regions_it)
406 drawPolyline(cf, *regions_it, m_shadowDirection);
407
408 stenc->enableMask(TStencilControl::SHOW_OUTSIDE);
409
410 regions_it_b = regionOutline.m_interior.begin();
411 regions_it_e = regionOutline.m_interior.end();
412
413 for (regions_it = regions_it_b; regions_it != regions_it_e; ++regions_it)
414 drawPolyline(cf, *regions_it, -m_shadowDirection);
415
416 // tglColor(TPixel32::White);
417
418 stenc->disableMask();
419 }
420
421 //------------------------------------------------------------
422
getColorParamValue(int index) const423 TPixel32 ShadowStyle::getColorParamValue(int index) const {
424 return index == 0 ? m_shadowColor : TSolidColorStyle::getMainColor();
425 }
426
427 //------------------------------------------------------------
428
setColorParamValue(int index,const TPixel32 & color)429 void ShadowStyle::setColorParamValue(int index, const TPixel32 &color) {
430 if (index == 0)
431 m_shadowColor = color;
432 else {
433 TSolidColorStyle::setMainColor(color);
434 }
435 }
436
437 //------------------------------------------------------------
438
makeIcon(const TDimension & d)439 void ShadowStyle::makeIcon(const TDimension &d) {
440 double oldVal = getParamValue(TColorStyle::double_tag(), 1);
441 setParamValue(1, oldVal * 0.25);
442 TColorStyle::makeIcon(d);
443 setParamValue(1, oldVal);
444 }
445
446 //***************************************************************************
447 // ShadowStyle2 implementation
448 //***************************************************************************
449
ShadowStyle2(const TPixel32 & bgColor,const TPixel32 & shadowColor,const TPointD & shadowDirection,double shadowLength)450 ShadowStyle2::ShadowStyle2(const TPixel32 &bgColor, const TPixel32 &shadowColor,
451 const TPointD &shadowDirection, double shadowLength)
452 : TSolidColorStyle(bgColor)
453 , m_shadowColor(shadowColor)
454 , m_shadowLength(shadowLength)
455 , m_shadowDirection(normalize(shadowDirection)) {}
456
457 //------------------------------------------------------------
458
clone() const459 TColorStyle *ShadowStyle2::clone() const { return new ShadowStyle2(*this); }
460
461 //------------------------------------------------------------
462
loadData(TInputStreamInterface & is)463 void ShadowStyle2::loadData(TInputStreamInterface &is) {
464 TSolidColorStyle::loadData(is);
465 is >> m_shadowDirection.x >> m_shadowDirection.y;
466 is >> m_shadowLength;
467 is >> m_shadowColor;
468 }
469
470 //------------------------------------------------------------
471
saveData(TOutputStreamInterface & os) const472 void ShadowStyle2::saveData(TOutputStreamInterface &os) const {
473 TSolidColorStyle::saveData(os);
474 os << m_shadowDirection.x << m_shadowDirection.y;
475 os << m_shadowLength;
476 os << m_shadowColor;
477 }
478
479 //------------------------------------------------------------
480
getParamCount() const481 int ShadowStyle2::getParamCount() const { return 2; }
482
483 //-----------------------------------------------------------------------------
484
getParamType(int index) const485 TColorStyle::ParamType ShadowStyle2::getParamType(int index) const {
486 assert(0 <= index && index < getParamCount());
487 return TColorStyle::DOUBLE;
488 }
489
490 //-----------------------------------------------------------------------------
491
getParamNames(int index) const492 QString ShadowStyle2::getParamNames(int index) const {
493 assert(0 <= index && index < 2);
494
495 return index == 0 ? QCoreApplication::translate("ShadowStyle2", "Angle")
496 : QCoreApplication::translate("ShadowStyle2", "Size");
497 }
498
499 //-----------------------------------------------------------------------------
500
getParamRange(int index,double & min,double & max) const501 void ShadowStyle2::getParamRange(int index, double &min, double &max) const {
502 assert(0 <= index && index < 2);
503 if (index == 0) {
504 min = 0.0;
505 max = 360.0;
506 } else {
507 min = 0.0;
508 max = 500.0;
509 }
510 }
511
512 //-----------------------------------------------------------------------------
513
getParamValue(TColorStyle::double_tag,int index) const514 double ShadowStyle2::getParamValue(TColorStyle::double_tag, int index) const {
515 assert(0 <= index && index < 2);
516
517 if (index == 1) return m_shadowLength;
518
519 double degree = asin(m_shadowDirection.y);
520 if (m_shadowDirection.x < 0) degree = M_PI - degree;
521
522 if (degree < 0) degree += M_2PI;
523
524 return degree * M_180_PI;
525 }
526
527 //-----------------------------------------------------------------------------
528
nbDiffVerts(const std::vector<TPointD> & pv)529 static int nbDiffVerts(const std::vector<TPointD> &pv) {
530 std::vector<TPointD> lpv;
531 if (pv.size() == 0) return 0;
532 lpv.push_back(pv[0]);
533 for (int i = 1; i < (int)pv.size(); i++) {
534 bool isDiff = true;
535 for (int j = 0; j < (int)lpv.size() && isDiff; j++)
536 isDiff = lpv[j] == pv[i] ? false : isDiff;
537 if (isDiff) {
538 lpv.push_back(pv[i]);
539 }
540 }
541 return lpv.size();
542 }
543
setParamValue(int index,double value)544 void ShadowStyle2::setParamValue(int index, double value) {
545 assert(0 <= index && index < 2);
546
547 if (index == 1) {
548 m_shadowLength = value;
549 } else {
550 double degree = value * M_PI_180;
551 m_shadowDirection.x = cos(degree);
552 m_shadowDirection.y = sin(degree);
553 }
554 }
555
556 //------------------------------------------------------------
557
558 namespace {
559
drawShadowLine(TPixel32 shadowColor,TPixel32 color,TPointD v1,TPointD v2,TPointD diff1,TPointD diff2)560 void drawShadowLine(TPixel32 shadowColor, TPixel32 color, TPointD v1,
561 TPointD v2, TPointD diff1, TPointD diff2) {
562 v1 = v1 + diff1;
563 v2 = v2 + diff2;
564 diff1 = -diff1;
565 diff2 = -diff2;
566
567 double r1, r2;
568 double t = 0.0;
569
570 glBegin(GL_QUAD_STRIP);
571
572 for (; t <= 1; t += 0.1) {
573 r1 = t * t * t;
574 r2 = 1 - r1;
575
576 TPixel32 c((int)(color.r * r2 + shadowColor.r * r1),
577 (int)(color.g * r2 + shadowColor.g * r1),
578 (int)(color.b * r2 + shadowColor.b * r1),
579 (int)(color.m * r2 + shadowColor.m * r1));
580 tglColor(c);
581 tglVertex(v1 + t * diff1);
582 tglVertex(v2 + t * diff2);
583 }
584
585 glEnd();
586 }
587 }
588
589 //------------------------------------------------------------
590
drawPolyline(const TColorFunction * cf,const std::vector<T3DPointD> & polyline,TPointD shadowDirection) const591 void ShadowStyle2::drawPolyline(const TColorFunction *cf,
592 const std::vector<T3DPointD> &polyline,
593 TPointD shadowDirection) const {
594 if (polyline.empty()) return;
595 TPointD v0, v1, diff;
596 double len1, len2;
597
598 TPixel32 color, shadowColor;
599
600 if (cf)
601 color = (*(cf))(TSolidColorStyle::getMainColor());
602 else
603 color = TSolidColorStyle::getMainColor();
604
605 if (cf)
606 shadowColor = (*(cf))(m_shadowColor);
607 else
608 shadowColor = m_shadowColor;
609
610 tglColor(shadowColor);
611
612 // glEnable(GL_BLEND);
613 // glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
614 //// <-- tglEnableBlending();
615 TRegionOutline::PointVector::const_iterator it;
616 TRegionOutline::PointVector::const_iterator it_b = polyline.begin();
617 TRegionOutline::PointVector::const_iterator it_e = polyline.end();
618
619 int size = polyline.size();
620 std::vector<double> lens(size);
621 v0.x = polyline.back().x;
622 v0.y = polyline.back().y;
623 int count = 0;
624 for (it = it_b; it != it_e; ++it) {
625 v1.x = it->x;
626 v1.y = it->y;
627 if (v1 != v0) {
628 diff = normalize(rotate90(v1 - v0));
629 len1 = diff * shadowDirection;
630 if (len1 < 0) len1 = 0;
631 lens[count++] = len1;
632 } else
633 lens[count++] = 0;
634
635 v0 = v1;
636 }
637
638 double firstVal = lens.front();
639 for (count = 0; count != size - 1; count++) {
640 lens[count] = (lens[count] + lens[count + 1]) * 0.5;
641 }
642 lens[size - 1] = (lens[size - 1] + firstVal) * 0.5;
643
644 for (count = 0; count != size - 1; count++) {
645 v0.x = polyline[count].x;
646 v0.y = polyline[count].y;
647 v1.x = polyline[count + 1].x;
648 v1.y = polyline[count + 1].y;
649 len1 = lens[count];
650 len2 = lens[count + 1];
651
652 if (v0 != v1 && len1 >= 0 && len2 >= 0 && (len1 + len2) > 0)
653 drawShadowLine(shadowColor, color, v0, v1,
654 shadowDirection * len1 * m_shadowLength,
655 shadowDirection * len2 * m_shadowLength);
656 }
657 v0.x = polyline[count].x;
658 v0.y = polyline[count].y;
659 v1.x = polyline.front().x;
660 v1.y = polyline.front().y;
661 len1 = lens[count];
662 len2 = lens[0];
663 if (v0 != v1 && len1 >= 0 && len2 >= 0 && (len1 + len2) > 0)
664 drawShadowLine(shadowColor, color, v0, v1,
665 shadowDirection * len1 * m_shadowLength,
666 shadowDirection * len2 * m_shadowLength);
667
668 // tglColor(TPixel32::White);
669 }
670
671 //------------------------------------------------------------
672
getColorParamValue(int index) const673 TPixel32 ShadowStyle2::getColorParamValue(int index) const {
674 return index == 0 ? m_shadowColor : TSolidColorStyle::getMainColor();
675 }
676
677 //------------------------------------------------------------
678
setColorParamValue(int index,const TPixel32 & color)679 void ShadowStyle2::setColorParamValue(int index, const TPixel32 &color) {
680 if (index == 0)
681 m_shadowColor = color;
682 else {
683 TSolidColorStyle::setMainColor(color);
684 }
685 }
686
687 //------------------------------------------------------------
688
drawRegion(const TColorFunction * cf,const bool antiAliasing,TRegionOutline & boundary) const689 void ShadowStyle2::drawRegion(const TColorFunction *cf, const bool antiAliasing,
690 TRegionOutline &boundary) const {
691 TStencilControl *stenc = TStencilControl::instance();
692 TPixel32 backgroundColor = TSolidColorStyle::getMainColor();
693 if (cf) backgroundColor = (*(cf))(backgroundColor);
694
695 if (backgroundColor.m == 0) { // only to create stencil mask
696 TSolidColorStyle appStyle(TPixel32::White);
697 stenc->beginMask(); // does not draw on screen
698 appStyle.drawRegion(0, false, boundary);
699 } else { // create stencil mask and draw on screen
700 stenc->beginMask(TStencilControl::DRAW_ALSO_ON_SCREEN);
701 TSolidColorStyle::drawRegion(cf, antiAliasing, boundary);
702 }
703 stenc->endMask();
704
705 stenc->enableMask(TStencilControl::SHOW_INSIDE);
706
707 TRegionOutline::Boundary::iterator regions_it;
708 TRegionOutline::Boundary::iterator regions_it_b = boundary.m_exterior.begin();
709 TRegionOutline::Boundary::iterator regions_it_e = boundary.m_exterior.end();
710
711 for (regions_it = regions_it_b; regions_it != regions_it_e; ++regions_it)
712 drawPolyline(cf, *regions_it, m_shadowDirection);
713
714 // tglColor(TPixel32::White);
715
716 stenc->disableMask();
717 }
718
719 //***************************************************************************
720 // RubberModifier implementation
721 //***************************************************************************
722
clone() const723 TOutlineStyle::RegionOutlineModifier *RubberModifier::clone() const {
724 return new RubberModifier(*this);
725 }
726
727 //------------------------------------------------------------
728
modify(TRegionOutline & outline) const729 void RubberModifier::modify(TRegionOutline &outline) const {
730 double deformSize = 40.0 + (100 - m_deform) * 0.60;
731
732 TRegionOutline::Boundary::iterator regions_it;
733 TRegionOutline::Boundary::iterator regions_it_b = outline.m_exterior.begin();
734 TRegionOutline::Boundary::iterator regions_it_e = outline.m_exterior.end();
735
736 for (regions_it = regions_it_b; regions_it != regions_it_e; ++regions_it) {
737 RubberDeform rd(®ions_it[0]);
738 rd.deform(deformSize);
739 }
740
741 regions_it_b = outline.m_interior.begin();
742 regions_it_e = outline.m_interior.end();
743
744 for (regions_it = regions_it_b; regions_it != regions_it_e; ++regions_it) {
745 RubberDeform rd(®ions_it[0]);
746 rd.deform(deformSize);
747 }
748 }
749
750 //***************************************************************************
751 // TRubberFillStyle implementation
752 //***************************************************************************
753
TRubberFillStyle(const TPixel32 & color,double deform)754 TRubberFillStyle::TRubberFillStyle(const TPixel32 &color, double deform)
755 : TSolidColorStyle(color) {
756 m_regionOutlineModifier = new RubberModifier(deform);
757 }
758
759 //------------------------------------------------------------
760
clone() const761 TColorStyle *TRubberFillStyle::clone() const {
762 return new TRubberFillStyle(*this);
763 }
764
765 //------------------------------------------------------------
766
makeIcon(const TDimension & d)767 void TRubberFillStyle::makeIcon(const TDimension &d) {
768 // Saves the values of member variables and sets the right icon values
769
770 RubberModifier *prm = (RubberModifier *)(m_regionOutlineModifier);
771 double LDeform = prm->getDeform();
772 prm->setDeform(LDeform);
773
774 TColorStyle::makeIcon(d);
775
776 // Loads the original values
777 prm->setDeform(LDeform);
778 }
779
780 //------------------------------------------------------------
781
getParamCount() const782 int TRubberFillStyle::getParamCount() const { return 1; }
783
784 //-----------------------------------------------------------------------------
785
getParamType(int index) const786 TColorStyle::ParamType TRubberFillStyle::getParamType(int index) const {
787 assert(0 <= index && index < getParamCount());
788 return TColorStyle::DOUBLE;
789 }
790
791 //-----------------------------------------------------------------------------
792
getParamNames(int index) const793 QString TRubberFillStyle::getParamNames(int index) const {
794 assert(0 <= index && index < 1);
795
796 return QCoreApplication::translate("TRubberFillStyle", "Intensity");
797 }
798
799 //-----------------------------------------------------------------------------
800
getParamRange(int index,double & min,double & max) const801 void TRubberFillStyle::getParamRange(int index, double &min,
802 double &max) const {
803 assert(0 <= index && index < 1);
804 min = 0.;
805 max = 100.0;
806 }
807
808 //-----------------------------------------------------------------------------
809
getParamValue(TColorStyle::double_tag,int index) const810 double TRubberFillStyle::getParamValue(TColorStyle::double_tag,
811 int index) const {
812 assert(0 <= index && index < 1);
813 return ((RubberModifier *)m_regionOutlineModifier)->getDeform();
814 }
815
816 //-----------------------------------------------------------------------------
817
setParamValue(int index,double value)818 void TRubberFillStyle::setParamValue(int index, double value) {
819 assert(0 <= index && index < 1);
820
821 double oldDeform = ((RubberModifier *)m_regionOutlineModifier)->getDeform();
822
823 if (oldDeform != value) {
824 delete m_regionOutlineModifier;
825 m_regionOutlineModifier = new RubberModifier(value);
826 updateVersionNumber();
827 }
828 }
829
830 //------------------------------------------------------------
831
loadData(TInputStreamInterface & is)832 void TRubberFillStyle::loadData(TInputStreamInterface &is) {
833 TSolidColorStyle::loadData(is);
834 delete m_regionOutlineModifier;
835 RubberModifier *rub = new RubberModifier(0.0);
836 rub->loadData(is);
837 m_regionOutlineModifier = rub;
838 }
839
840 //------------------------------------------------------------
841
saveData(TOutputStreamInterface & os) const842 void TRubberFillStyle::saveData(TOutputStreamInterface &os) const {
843 TSolidColorStyle::saveData(os);
844
845 assert(m_regionOutlineModifier);
846 ((RubberModifier *)m_regionOutlineModifier)->saveData(os);
847 }
848
849 //------------------------------------------------------------
850
drawRegion(const TColorFunction * cf,const bool antiAliasing,TRegionOutline & boundary) const851 void TRubberFillStyle::drawRegion(const TColorFunction *cf,
852 const bool antiAliasing,
853 TRegionOutline &boundary) const {
854 TSolidColorStyle::drawRegion(cf, true, boundary);
855 }
856
857 //***************************************************************************
858 // TPointShadowFillStyle implementation
859 //***************************************************************************
860
TPointShadowFillStyle(const TPixel32 & bgColor,const TPixel32 & shadowColor,const TPointD & shadowDirection,double density,double shadowSize,double pointSize)861 TPointShadowFillStyle::TPointShadowFillStyle(const TPixel32 &bgColor,
862 const TPixel32 &shadowColor,
863 const TPointD &shadowDirection,
864 double density, double shadowSize,
865 double pointSize)
866 : TSolidColorStyle(bgColor)
867 , m_shadowColor(shadowColor)
868 , m_shadowDirection(normalize(shadowDirection))
869 , m_shadowSize(shadowSize)
870 , m_density(density)
871 , m_pointSize(pointSize) {}
872
873 //-----------------------------------------------------------------------------
874
clone() const875 TColorStyle *TPointShadowFillStyle::clone() const {
876 return new TPointShadowFillStyle(*this);
877 }
878
879 //-----------------------------------------------------------------------------
880
getParamCount() const881 int TPointShadowFillStyle::getParamCount() const { return 4; }
882
883 //-----------------------------------------------------------------------------
884
getParamType(int index) const885 TColorStyle::ParamType TPointShadowFillStyle::getParamType(int index) const {
886 assert(0 <= index && index < getParamCount());
887 return TColorStyle::DOUBLE;
888 }
889
890 //-----------------------------------------------------------------------------
891
getParamNames(int index) const892 QString TPointShadowFillStyle::getParamNames(int index) const {
893 assert(0 <= index && index < 4);
894
895 QString value;
896 switch (index) {
897 case 0:
898 value = QCoreApplication::translate("TPointShadowFillStyle", "Angle");
899 break;
900 case 1:
901 value = QCoreApplication::translate("TPointShadowFillStyle", "Density");
902 break;
903 case 2:
904 value = QCoreApplication::translate("TPointShadowFillStyle", "Size");
905 break;
906 case 3:
907 value = QCoreApplication::translate("TPointShadowFillStyle", "Point Size");
908 break;
909 }
910
911 return value;
912 }
913
914 //-----------------------------------------------------------------------------
915
getParamRange(int index,double & min,double & max) const916 void TPointShadowFillStyle::getParamRange(int index, double &min,
917 double &max) const {
918 assert(0 <= index && index < 4);
919
920 switch (index) {
921 case 0:
922 min = 0.0;
923 max = 360.0;
924 break;
925 case 1:
926 min = 0.0;
927 max = 1.0;
928 break;
929 case 2:
930 min = 0.0;
931 max = 100.0;
932 break;
933 case 3:
934 min = 0.01;
935 max = 100.0;
936 break;
937 }
938 }
939
940 //-----------------------------------------------------------------------------
941
getParamValue(TColorStyle::double_tag,int index) const942 double TPointShadowFillStyle::getParamValue(TColorStyle::double_tag,
943 int index) const {
944 assert(0 <= index && index < 4);
945
946 double degree = 0.0;
947
948 switch (index) {
949 case 0:
950 degree = asin(m_shadowDirection.y);
951 if (m_shadowDirection.x < 0) degree = M_PI - degree;
952 if (degree < 0) degree += M_2PI;
953 return degree * M_180_PI;
954
955 case 1:
956 return m_density;
957
958 case 2:
959 return m_shadowSize;
960
961 case 3:
962 return m_pointSize;
963 }
964
965 // never
966 return 0;
967 }
968
969 //-----------------------------------------------------------------------------
970
setParamValue(int index,double value)971 void TPointShadowFillStyle::setParamValue(int index, double value) {
972 assert(0 <= index && index < 4);
973
974 double degree = 0.0;
975
976 switch (index) {
977 case 0:
978 degree = value * M_PI_180;
979 m_shadowDirection.x = cos(degree);
980 m_shadowDirection.y = sin(degree);
981
982 break;
983
984 case 1:
985 m_density = value;
986 break;
987
988 case 2:
989 m_shadowSize = value;
990 break;
991
992 case 3:
993 m_pointSize = value;
994 break;
995 }
996 }
997
998 //------------------------------------------------------------
loadData(TInputStreamInterface & is)999 void TPointShadowFillStyle::loadData(TInputStreamInterface &is) {
1000 TSolidColorStyle::loadData(is);
1001 is >> m_shadowDirection.x >> m_shadowDirection.y;
1002 is >> m_density;
1003 is >> m_shadowSize;
1004 is >> m_pointSize;
1005 is >> m_shadowColor;
1006 }
1007
1008 //------------------------------------------------------------
1009
saveData(TOutputStreamInterface & os) const1010 void TPointShadowFillStyle::saveData(TOutputStreamInterface &os) const {
1011 TSolidColorStyle::saveData(os);
1012 os << m_shadowDirection.x << m_shadowDirection.y;
1013 os << m_density;
1014 os << m_shadowSize;
1015 os << m_pointSize;
1016 os << m_shadowColor;
1017 }
1018
1019 //------------------------------------------------------------
1020
getColorParamValue(int index) const1021 TPixel32 TPointShadowFillStyle::getColorParamValue(int index) const {
1022 return index == 0 ? m_shadowColor : TSolidColorStyle::getMainColor();
1023 }
1024
1025 //------------------------------------------------------------
setColorParamValue(int index,const TPixel32 & color)1026 void TPointShadowFillStyle::setColorParamValue(int index,
1027 const TPixel32 &color) {
1028 if (index == 0)
1029 m_shadowColor = color;
1030 else {
1031 TSolidColorStyle::setMainColor(color);
1032 }
1033 }
1034
1035 //------------------------------------------------------------
1036
triangleArea(const TPointD & a,const TPointD & b,const TPointD & c) const1037 double TPointShadowFillStyle::triangleArea(const TPointD &a, const TPointD &b,
1038 const TPointD &c) const {
1039 double ab = tdistance(a, b);
1040 double ac = tdistance(a, c);
1041 double bc = tdistance(b, c);
1042 double s = (ab + bc + ac) / 2.0;
1043 return sqrt(s * (s - ab) * (s - ac) * (s - bc));
1044 }
1045
1046 //------------------------------------------------------------
1047
shadowOnEdge_parallel(const TPointD & p0,const TPointD & p1,const TPointD & p2,TRandom & rnd) const1048 void TPointShadowFillStyle::shadowOnEdge_parallel(const TPointD &p0,
1049 const TPointD &p1,
1050 const TPointD &p2,
1051 TRandom &rnd) const {
1052 if (p0 == p1 || p1 == p2) return;
1053
1054 TPointD diff = normalize(rotate90(p1 - p0));
1055 double len1 = diff * m_shadowDirection;
1056
1057 diff = normalize(rotate90(p2 - p1));
1058 double len2 = diff * m_shadowDirection;
1059
1060 if (len1 >= 0 && len2 >= 0 && (len1 + len2) > 0) {
1061 TPointD la = p1 + m_shadowDirection * len1 * m_shadowSize;
1062 TPointD lb = p2 + m_shadowDirection * len2 * m_shadowSize;
1063 double t = triangleArea(p1, p2, lb) + triangleArea(p2, lb, la);
1064 int nb = (int)(m_density * t);
1065 for (int i = 0; i < nb; i++) {
1066 double q = rnd.getUInt(1001) / 1000.0;
1067 double r = rnd.getUInt(1001) / 1000.0;
1068 r = r * r;
1069 TPointD u = p1 + (p2 - p1) * q;
1070 u = u +
1071 r * (len1 * (1.0 - q) + len2 * q) * m_shadowDirection * m_shadowSize;
1072 tglColor(TPixel32(m_shadowColor.r, m_shadowColor.g, m_shadowColor.b,
1073 (int)((1.0 - r) * (double)m_shadowColor.m)));
1074 tglVertex(u);
1075 }
1076 }
1077 }
1078
1079 //------------------------------------------------------------
1080
deleteSameVerts(TRegionOutline::Boundary::iterator & rit,std::vector<T3DPointD> & pv) const1081 void TPointShadowFillStyle::deleteSameVerts(
1082 TRegionOutline::Boundary::iterator &rit, std::vector<T3DPointD> &pv) const {
1083 pv.clear();
1084 if (rit->size() <= 0) return;
1085 TRegionOutline::PointVector::iterator it_beg = rit->begin();
1086 TRegionOutline::PointVector::iterator it_end = rit->end();
1087 TRegionOutline::PointVector::iterator it = it_beg;
1088 pv.push_back(*it);
1089 it++;
1090 for (; it != it_end; it++) {
1091 if (tdistance(*it, pv.back()) > TConsts::epsilon) {
1092 pv.push_back(*it);
1093 }
1094 }
1095
1096 if (pv.size() > 2) {
1097 if (tdistance(*(pv.begin()), pv.back()) <= TConsts::epsilon) pv.pop_back();
1098 }
1099 }
1100
1101 //------------------------------------------------------------
1102
drawRegion(const TColorFunction * cf,const bool antiAliasing,TRegionOutline & boundary) const1103 void TPointShadowFillStyle::drawRegion(const TColorFunction *cf,
1104 const bool antiAliasing,
1105 TRegionOutline &boundary) const {
1106 TStencilControl *stenc = TStencilControl::instance();
1107 TPixel32 backgroundColor = TSolidColorStyle::getMainColor();
1108 if (cf) backgroundColor = (*(cf))(backgroundColor);
1109
1110 if (backgroundColor.m == 0) { // only to create stencil mask
1111 TSolidColorStyle appStyle(TPixel32::White);
1112 stenc->beginMask(); // does not draw on screen
1113 appStyle.drawRegion(0, false, boundary);
1114 } else { // create stencil mask and draw on screen
1115 stenc->beginMask(TStencilControl::DRAW_ALSO_ON_SCREEN);
1116 TSolidColorStyle::drawRegion(cf, antiAliasing, boundary);
1117 }
1118 stenc->endMask();
1119 stenc->enableMask(TStencilControl::SHOW_INSIDE);
1120
1121 GLfloat pointSizeSave;
1122 glGetFloatv(GL_POINT_SIZE, &pointSizeSave);
1123 GLfloat sizes[2];
1124 glGetFloatv(GL_POINT_SIZE_RANGE, sizes);
1125 // glEnable(GL_BLEND);
1126 // glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
1127 // glEnable(GL_POINT_SMOOTH);
1128 // glPointSize((float)(sizes[0]+(sizes[1]-sizes[0])*m_pointSize*0.01));
1129 tglEnablePointSmooth(
1130 (float)(sizes[0] + (sizes[1] - sizes[0]) * m_pointSize * 0.01));
1131
1132 TRegionOutline::Boundary::iterator regions_it;
1133 TRegionOutline::Boundary::iterator regions_it_b = boundary.m_exterior.begin();
1134 TRegionOutline::Boundary::iterator regions_it_e = boundary.m_exterior.end();
1135
1136 TPixel32 color;
1137 if (cf)
1138 color = (*(cf))(m_shadowColor);
1139 else
1140 color = m_shadowColor;
1141
1142 TRandom rnd;
1143
1144 for (regions_it = regions_it_b; regions_it != regions_it_e; ++regions_it) {
1145 std::vector<T3DPointD> pv;
1146 deleteSameVerts(regions_it, pv);
1147 if (pv.size() < 3) continue;
1148 std::vector<T3DPointD>::iterator it_beg = pv.begin();
1149 std::vector<T3DPointD>::iterator it_end = pv.end();
1150 std::vector<T3DPointD>::iterator it_last = it_end - 1;
1151 std::vector<T3DPointD>::iterator it0, it1, it2;
1152 glBegin(GL_POINTS);
1153 for (it1 = it_beg; it1 != it_end; it1++) {
1154 it0 = it1 == it_beg ? it_last : it1 - 1;
1155 it2 = it1 == it_last ? it_beg : it1 + 1;
1156
1157 shadowOnEdge_parallel(TPointD(it0->x, it0->y), TPointD(it1->x, it1->y),
1158 TPointD(it2->x, it2->y), rnd);
1159 }
1160 glEnd();
1161 }
1162
1163 glPointSize(pointSizeSave);
1164 stenc->disableMask();
1165 }
1166
1167 //***************************************************************************
1168 // TDottedFillStyle implementation
1169 //***************************************************************************
1170
TDottedFillStyle(const TPixel32 & bgColor,const TPixel32 & pointColor,const double dotSize,const double dotDist,const bool isShifted)1171 TDottedFillStyle::TDottedFillStyle(const TPixel32 &bgColor,
1172 const TPixel32 &pointColor,
1173 const double dotSize, const double dotDist,
1174 const bool isShifted)
1175 : TSolidColorStyle(bgColor)
1176 , m_pointColor(pointColor)
1177 , m_dotSize(dotSize)
1178 , m_dotDist(dotDist)
1179 , m_isShifted(isShifted) {}
1180
1181 //------------------------------------------------------------
1182
TDottedFillStyle(const TPixel32 & color)1183 TDottedFillStyle::TDottedFillStyle(const TPixel32 &color)
1184 : TSolidColorStyle(TPixel32(0, 0, 200))
1185 , m_pointColor(color)
1186 , m_dotSize(3.0)
1187 , m_dotDist(15.0)
1188 , m_isShifted(true) {}
1189
1190 //------------------------------------------------------------
1191
clone() const1192 TColorStyle *TDottedFillStyle::clone() const {
1193 return new TDottedFillStyle(*this);
1194 }
1195
1196 //------------------------------------------------------------
1197
getParamCount() const1198 int TDottedFillStyle::getParamCount() const { return 2; }
1199
1200 //-----------------------------------------------------------------------------
1201
getParamType(int index) const1202 TColorStyle::ParamType TDottedFillStyle::getParamType(int index) const {
1203 assert(0 <= index && index < getParamCount());
1204 return TColorStyle::DOUBLE;
1205 }
1206
1207 //-----------------------------------------------------------------------------
1208
getParamNames(int index) const1209 QString TDottedFillStyle::getParamNames(int index) const {
1210 assert(0 <= index && index < 2);
1211
1212 return index == 0
1213 ? QCoreApplication::translate("TDottedFillStyle", "Dot Size")
1214 : QCoreApplication::translate("TDottedFillStyle", "Dot Distance");
1215 }
1216
1217 //-----------------------------------------------------------------------------
1218
getParamRange(int index,double & min,double & max) const1219 void TDottedFillStyle::getParamRange(int index, double &min,
1220 double &max) const {
1221 assert(0 <= index && index < 2);
1222 if (index == 0) {
1223 min = 0.001;
1224 max = 30.0;
1225 } else {
1226 min = 2.0;
1227 max = 100.0;
1228 }
1229 }
1230
1231 //-----------------------------------------------------------------------------
1232
getParamValue(TColorStyle::double_tag,int index) const1233 double TDottedFillStyle::getParamValue(TColorStyle::double_tag,
1234 int index) const {
1235 assert(0 <= index && index < 2);
1236
1237 if (!index)
1238 return m_dotSize;
1239 else
1240 return m_dotDist;
1241 }
1242
1243 //-----------------------------------------------------------------------------
1244
setParamValue(int index,double value)1245 void TDottedFillStyle::setParamValue(int index, double value) {
1246 assert(0 <= index && index < 2);
1247
1248 if (!index) {
1249 m_dotSize = value;
1250 } else {
1251 m_dotDist = value;
1252 }
1253 }
1254
1255 //------------------------------------------------------------
1256
loadData(TInputStreamInterface & is)1257 void TDottedFillStyle::loadData(TInputStreamInterface &is) {
1258 TSolidColorStyle::loadData(is);
1259 is >> m_dotSize;
1260 is >> m_dotDist;
1261 is >> m_pointColor;
1262 }
1263
1264 //------------------------------------------------------------
1265
saveData(TOutputStreamInterface & os) const1266 void TDottedFillStyle::saveData(TOutputStreamInterface &os) const {
1267 TSolidColorStyle::saveData(os);
1268 os << m_dotSize;
1269 os << m_dotDist;
1270 os << m_pointColor;
1271 }
1272
1273 //------------------------------------------------------------
1274
getColorParamValue(int index) const1275 TPixel32 TDottedFillStyle::getColorParamValue(int index) const {
1276 return index == 0 ? m_pointColor : TSolidColorStyle::getMainColor();
1277 }
1278
1279 //------------------------------------------------------------
1280
setColorParamValue(int index,const TPixel32 & color)1281 void TDottedFillStyle::setColorParamValue(int index, const TPixel32 &color) {
1282 if (index == 0)
1283 m_pointColor = color;
1284 else {
1285 TSolidColorStyle::setMainColor(color);
1286 }
1287 }
1288
1289 //------------------------------------------------------------
1290
drawRegion(const TColorFunction * cf,const bool antiAliasing,TRegionOutline & boundary) const1291 void TDottedFillStyle::drawRegion(const TColorFunction *cf,
1292 const bool antiAliasing,
1293 TRegionOutline &boundary) const {
1294 double LDotDist = std::max(m_dotDist, 0.1);
1295 // double LDotSize=m_dotSize;
1296 bool LIsShifted = m_isShifted;
1297 const bool isTransparent = m_pointColor.m < 255;
1298
1299 TStencilControl *stenc = TStencilControl::instance();
1300 TPixel32 backgroundColor = TSolidColorStyle::getMainColor();
1301 if (cf) backgroundColor = (*(cf))(backgroundColor);
1302
1303 if (backgroundColor.m == 0) { // only to create stencil mask
1304 TSolidColorStyle appStyle(TPixel32::White);
1305 stenc->beginMask(); // does not draw on screen
1306 appStyle.drawRegion(0, false, boundary);
1307 } else { // create stencil mask and draw on screen
1308 stenc->beginMask(TStencilControl::DRAW_ALSO_ON_SCREEN);
1309 TSolidColorStyle::drawRegion(cf, antiAliasing, boundary);
1310 }
1311 stenc->endMask();
1312
1313 stenc->enableMask(TStencilControl::SHOW_INSIDE);
1314
1315 if (isTransparent) {
1316 // glEnable(GL_BLEND);
1317 // glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
1318 //// <-- tglEnableBlending();
1319 }
1320
1321 TPixel32 color;
1322 if (cf)
1323 color = (*(cf))(m_pointColor);
1324 else
1325 color = m_pointColor;
1326
1327 tglColor(color);
1328
1329 int i = 0;
1330 for (double y = boundary.m_bbox.y0; y <= boundary.m_bbox.y1;
1331 y += LDotDist, ++i) {
1332 double x = LIsShifted && (i % 2) == 1 ? boundary.m_bbox.x0 + LDotDist / 2.0
1333 : boundary.m_bbox.x0;
1334 for (; x <= boundary.m_bbox.x1; x += LDotDist)
1335 tglDrawDisk(TPointD(x, y), m_dotSize);
1336 // tglDrawCircle(TPointD(x,y),m_dotSize);
1337 }
1338
1339 if (isTransparent) {
1340 // tglColor(TPixel32::White);
1341 // glDisable(GL_BLEND);
1342 }
1343
1344 stenc->disableMask();
1345 }
1346
1347 //------------------------------------------------------------
1348
nbClip(const double LDotDist,const bool LIsShifted,const TRectD & bbox) const1349 int TDottedFillStyle::nbClip(const double LDotDist, const bool LIsShifted,
1350 const TRectD &bbox) const {
1351 int nbClipLayers = 1; // the bbox rectangle
1352 int i = 0;
1353 for (double y = bbox.y0; y <= bbox.y1; y += LDotDist, ++i) {
1354 double x = LIsShifted && (i % 2) == 1 ? bbox.x0 + LDotDist / 2.0 : bbox.x0;
1355 for (; x <= bbox.x1; x += LDotDist) nbClipLayers++;
1356 }
1357 return nbClipLayers;
1358 }
1359
1360 //***************************************************************************
1361 // TCheckedFillStyle implementation
1362 //***************************************************************************
1363
TCheckedFillStyle(const TPixel32 & bgColor,const TPixel32 & pointColor,const double HDist,const double HAngle,const double VDist,const double VAngle,const double Thickness)1364 TCheckedFillStyle::TCheckedFillStyle(const TPixel32 &bgColor,
1365 const TPixel32 &pointColor,
1366 const double HDist, const double HAngle,
1367 const double VDist, const double VAngle,
1368 const double Thickness)
1369 : TSolidColorStyle(bgColor)
1370 , m_pointColor(pointColor)
1371 , m_HDist(HDist)
1372 , m_HAngle(HAngle)
1373 , m_VDist(VDist)
1374 , m_VAngle(VAngle)
1375 , m_Thickness(Thickness) {}
1376
1377 //------------------------------------------------------------
1378
TCheckedFillStyle(const TPixel32 & color)1379 TCheckedFillStyle::TCheckedFillStyle(const TPixel32 &color)
1380 : TSolidColorStyle(TPixel32::Transparent)
1381 , m_pointColor(color)
1382 , m_HDist(15.0)
1383 , m_HAngle(0.0)
1384 , m_VDist(15.0)
1385 , m_VAngle(0.0)
1386 , m_Thickness(6.0) {}
1387
1388 //------------------------------------------------------------
1389
clone() const1390 TColorStyle *TCheckedFillStyle::clone() const {
1391 return new TCheckedFillStyle(*this);
1392 }
1393
1394 //------------------------------------------------------------
1395
getParamCount() const1396 int TCheckedFillStyle::getParamCount() const { return 5; }
1397
1398 //-----------------------------------------------------------------------------
1399
getParamType(int index) const1400 TColorStyle::ParamType TCheckedFillStyle::getParamType(int index) const {
1401 assert(0 <= index && index < getParamCount());
1402 return TColorStyle::DOUBLE;
1403 }
1404
1405 //-----------------------------------------------------------------------------
1406
getParamNames(int index) const1407 QString TCheckedFillStyle::getParamNames(int index) const {
1408 assert(0 <= index && index < 5);
1409
1410 QString value;
1411 switch (index) {
1412 case 0:
1413 value = QCoreApplication::translate("TCheckedFillStyle", "Horiz Dist");
1414 break;
1415 case 1:
1416 value = QCoreApplication::translate("TCheckedFillStyle", "Horiz Angle");
1417 break;
1418 case 2:
1419 value = QCoreApplication::translate("TCheckedFillStyle", "Vert Dist");
1420 break;
1421 case 3:
1422 value = QCoreApplication::translate("TCheckedFillStyle", "Vert Angle");
1423 break;
1424 case 4:
1425 value = QCoreApplication::translate("TCheckedFillStyle", "Thickness");
1426 break;
1427 }
1428
1429 return value;
1430 }
1431
1432 //-----------------------------------------------------------------------------
1433
getParamRange(int index,double & min,double & max) const1434 void TCheckedFillStyle::getParamRange(int index, double &min,
1435 double &max) const {
1436 assert(0 <= index && index < 5);
1437 switch (index) {
1438 case 0:
1439 min = 1.0;
1440 max = 100.0;
1441 break;
1442 case 1:
1443 min = -45.0;
1444 max = 45.0;
1445 break;
1446 case 2:
1447 min = 1.0;
1448 max = 100.0;
1449 break;
1450 case 3:
1451 min = -45.0;
1452 max = 45.0;
1453 break;
1454 case 4:
1455 min = 0.5;
1456 max = 100.0;
1457 break;
1458 }
1459 }
1460
1461 //-----------------------------------------------------------------------------
1462
getParamValue(TColorStyle::double_tag,int index) const1463 double TCheckedFillStyle::getParamValue(TColorStyle::double_tag,
1464 int index) const {
1465 assert(0 <= index && index < 5);
1466
1467 switch (index) {
1468 case 0:
1469 return m_HDist;
1470 case 1:
1471 return m_HAngle;
1472 case 2:
1473 return m_VDist;
1474 case 3:
1475 return m_VAngle;
1476 case 4:
1477 return m_Thickness;
1478 }
1479 return 0.0;
1480 }
1481
1482 //-----------------------------------------------------------------------------
1483
setParamValue(int index,double value)1484 void TCheckedFillStyle::setParamValue(int index, double value) {
1485 assert(0 <= index && index < 5);
1486
1487 switch (index) {
1488 case 0:
1489 m_HDist = value;
1490 break;
1491 case 1:
1492 m_HAngle = value;
1493 break;
1494 case 2:
1495 m_VDist = value;
1496 break;
1497 case 3:
1498 m_VAngle = value;
1499 break;
1500 case 4:
1501 m_Thickness = value;
1502 break;
1503 }
1504 }
1505
1506 //------------------------------------------------------------
1507
loadData(TInputStreamInterface & is)1508 void TCheckedFillStyle::loadData(TInputStreamInterface &is) {
1509 TSolidColorStyle::loadData(is);
1510 is >> m_HDist;
1511 is >> m_HAngle;
1512 is >> m_VDist;
1513 is >> m_VAngle;
1514 is >> m_Thickness;
1515 is >> m_pointColor;
1516 }
1517
1518 //------------------------------------------------------------
1519
saveData(TOutputStreamInterface & os) const1520 void TCheckedFillStyle::saveData(TOutputStreamInterface &os) const {
1521 TSolidColorStyle::saveData(os);
1522 os << m_HDist;
1523 os << m_HAngle;
1524 os << m_VDist;
1525 os << m_VAngle;
1526 os << m_Thickness;
1527 os << m_pointColor;
1528 }
1529
1530 //------------------------------------------------------------
1531
getHThickline(const TPointD & lc,const double lx,TPointD & p0,TPointD & p1,TPointD & p2,TPointD & p3) const1532 void TCheckedFillStyle::getHThickline(const TPointD &lc, const double lx,
1533 TPointD &p0, TPointD &p1, TPointD &p2,
1534 TPointD &p3) const {
1535 double l = m_Thickness / cos(degree2rad(m_HAngle));
1536 l *= 0.5;
1537 p0 = TPointD(lc.x, lc.y - l);
1538 p1 = TPointD(lc.x, lc.y + l);
1539 double y = lc.y + lx * tan(degree2rad(m_HAngle));
1540 p2 = TPointD(lc.x + lx, y + l);
1541 p3 = TPointD(lc.x + lx, y - l);
1542 }
1543
1544 //------------------------------------------------------------
1545
getVThickline(const TPointD & lc,const double ly,TPointD & p0,TPointD & p1,TPointD & p2,TPointD & p3) const1546 void TCheckedFillStyle::getVThickline(const TPointD &lc, const double ly,
1547 TPointD &p0, TPointD &p1, TPointD &p2,
1548 TPointD &p3) const {
1549 double l = m_Thickness / cos(degree2rad(-m_VAngle));
1550 l *= 0.5;
1551 p0 = TPointD(lc.x - l, lc.y);
1552 p1 = TPointD(lc.x + l, lc.y);
1553 double x = lc.x + ly * tan(degree2rad(-m_VAngle));
1554 p2 = TPointD(x + l, lc.y + ly);
1555 p3 = TPointD(x - l, lc.y + ly);
1556 }
1557
1558 //------------------------------------------------------------
1559
getColorParamValue(int index) const1560 TPixel32 TCheckedFillStyle::getColorParamValue(int index) const {
1561 return index == 0 ? m_pointColor : TSolidColorStyle::getMainColor();
1562 }
1563
1564 //------------------------------------------------------------
1565
setColorParamValue(int index,const TPixel32 & color)1566 void TCheckedFillStyle::setColorParamValue(int index, const TPixel32 &color) {
1567 if (index == 0)
1568 m_pointColor = color;
1569 else {
1570 TSolidColorStyle::setMainColor(color);
1571 }
1572 }
1573
1574 //------------------------------------------------------------
1575
drawRegion(const TColorFunction * cf,const bool antiAliasing,TRegionOutline & boundary) const1576 void TCheckedFillStyle::drawRegion(const TColorFunction *cf,
1577 const bool antiAliasing,
1578 TRegionOutline &boundary) const {
1579 TStencilControl *stenc = TStencilControl::instance();
1580 TPixel32 backgroundColor = TSolidColorStyle::getMainColor();
1581 if (cf) backgroundColor = (*(cf))(backgroundColor);
1582
1583 if (backgroundColor.m == 0) { // only to create stencil mask
1584 TSolidColorStyle appStyle(TPixel32::White);
1585 stenc->beginMask(); // does not draw on screen
1586 appStyle.drawRegion(0, false, boundary);
1587 } else { // create stencil mask and draw on screen
1588 stenc->beginMask(TStencilControl::DRAW_ALSO_ON_SCREEN);
1589 TSolidColorStyle::drawRegion(cf, antiAliasing, boundary);
1590 }
1591 stenc->endMask();
1592 stenc->enableMask(TStencilControl::SHOW_INSIDE);
1593
1594 const bool isTransparent = m_pointColor.m < 255;
1595 if (isTransparent) {
1596 // glEnable(GL_BLEND);
1597 // glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
1598 //// <-- tglEnableBlending();
1599 }
1600
1601 glBegin(GL_QUADS);
1602 TPixel32 color;
1603 if (cf)
1604 color = (*(cf))(m_pointColor);
1605 else
1606 color = m_pointColor;
1607
1608 tglColor(color);
1609
1610 // Horizontal Lines
1611 double lx = boundary.m_bbox.x1 - boundary.m_bbox.x0;
1612 double ly = boundary.m_bbox.y1 - boundary.m_bbox.y0;
1613 double beg = boundary.m_bbox.y0;
1614 double end = boundary.m_bbox.y1;
1615 beg = m_HAngle <= 0 ? beg : beg - lx * tan(degree2rad(m_HAngle));
1616 end = m_HAngle >= 0 ? end : end - lx * tan(degree2rad(m_HAngle));
1617 double dist = m_HDist / cos(degree2rad(m_HAngle));
1618 for (double y = beg; y <= end; y += dist) {
1619 TPointD p0, p1, p2, p3;
1620 getHThickline(TPointD(boundary.m_bbox.x0, y), lx, p0, p1, p2, p3);
1621 tglVertex(p0);
1622 tglVertex(p1);
1623 tglVertex(p2);
1624 tglVertex(p3);
1625 }
1626
1627 // Vertical Lines
1628 beg = boundary.m_bbox.x0;
1629 end = boundary.m_bbox.x1;
1630 beg = (-m_VAngle) <= 0 ? beg : beg - ly * tan(degree2rad(-m_VAngle));
1631 end = (-m_VAngle) >= 0 ? end : end - ly * tan(degree2rad(-m_VAngle));
1632 dist = m_VDist / cos(degree2rad(-m_VAngle));
1633 for (double x = beg; x <= end; x += dist) {
1634 TPointD p0, p1, p2, p3;
1635 getVThickline(TPointD(x, boundary.m_bbox.y0), ly, p0, p1, p2, p3);
1636 tglVertex(p0);
1637 tglVertex(p1);
1638 tglVertex(p2);
1639 tglVertex(p3);
1640 }
1641
1642 glEnd();
1643
1644 if (isTransparent) {
1645 // tglColor(TPixel32::White);
1646 // glDisable(GL_BLEND);
1647 }
1648
1649 stenc->disableMask();
1650 }
1651
1652 //------------------------------------------------------------
1653
nbClip(const TRectD & bbox) const1654 int TCheckedFillStyle::nbClip(const TRectD &bbox) const {
1655 int nbClip = 1; // the bbox rectangle
1656
1657 double lx = bbox.x1 - bbox.x0;
1658 double ly = bbox.y1 - bbox.y0;
1659 double beg = bbox.y0;
1660 double end = bbox.y1;
1661 beg = m_HAngle <= 0 ? beg : beg - lx * tan(degree2rad(m_HAngle));
1662 end = m_HAngle >= 0 ? end : end - lx * tan(degree2rad(m_HAngle));
1663 double dist = m_HDist / cos(degree2rad(m_HAngle));
1664 for (double y = beg; y <= end; y += dist) nbClip++;
1665
1666 // Vertical lines
1667 beg = bbox.x0;
1668 end = bbox.x1;
1669 beg = (-m_VAngle) <= 0 ? beg : beg - ly * tan(degree2rad(-m_VAngle));
1670 end = (-m_VAngle) >= 0 ? end : end - ly * tan(degree2rad(-m_VAngle));
1671 dist = m_VDist / cos(degree2rad(-m_VAngle));
1672 for (double x = beg; x <= end; x += dist) nbClip++;
1673 return nbClip;
1674 }
1675
1676 //***************************************************************************
1677 // ArtisticModifier implementation
1678 //***************************************************************************
1679
modify(TRegionOutline & outline) const1680 void ArtisticModifier::modify(TRegionOutline &outline) const {
1681 TRegionOutline::Boundary::iterator regIt = outline.m_exterior.begin();
1682 TRegionOutline::Boundary::iterator regItEnd = outline.m_exterior.end();
1683
1684 TRegionOutline::PointVector::iterator pIt;
1685 TRegionOutline::PointVector::iterator pItEnd;
1686 TRandom rnd;
1687 double counter = 0;
1688 double maxcounter = 0;
1689 for (; regIt != regItEnd; ++regIt) {
1690 pIt = regIt->begin();
1691 pItEnd = regIt->end();
1692
1693 for (; pIt != pItEnd; ++pIt) {
1694 if (counter >= maxcounter) {
1695 double tmp = (201 - m_period) * (rnd.getFloat() + 1);
1696 maxcounter = tmp * tmp;
1697 counter = 0;
1698 }
1699 if (pIt != regIt->begin()) {
1700 double distance = (pIt->x - (pIt - 1)->x) * (pIt->x - (pIt - 1)->x) +
1701 (pIt->y - (pIt - 1)->y) * (pIt->y - (pIt - 1)->y);
1702 counter += distance;
1703 }
1704 double wave = 1;
1705 if (maxcounter) wave = sin(M_2PI * counter / maxcounter);
1706
1707 pIt->x += m_move.x * wave;
1708 pIt->y += m_move.y * wave;
1709 }
1710 }
1711
1712 regIt = outline.m_interior.begin();
1713 regItEnd = outline.m_interior.end();
1714 for (; regIt != regItEnd; ++regIt) {
1715 pIt = regIt->begin();
1716 pItEnd = regIt->end();
1717
1718 for (; pIt != pItEnd; ++pIt) {
1719 pIt->x += (0.5 - rnd.getFloat()) * m_move.x;
1720 pIt->y += (0.5 - rnd.getFloat()) * m_move.y;
1721 }
1722 }
1723 }
1724
1725 //------------------------------------------------------------
1726
clone() const1727 TOutlineStyle::RegionOutlineModifier *ArtisticModifier::clone() const {
1728 return new ArtisticModifier(*this);
1729 }
1730
1731 //***************************************************************************
1732 // ArtisticSolidColor implementation
1733 //***************************************************************************
1734
ArtisticSolidColor(const TPixel32 & color,const TPointD & move,double period)1735 ArtisticSolidColor::ArtisticSolidColor(const TPixel32 &color,
1736 const TPointD &move, double period)
1737 : TSolidColorStyle(color) {
1738 m_regionOutlineModifier = new ArtisticModifier(move, period);
1739 }
1740
1741 //------------------------------------------------------------
1742
clone() const1743 TColorStyle *ArtisticSolidColor::clone() const {
1744 return new ArtisticSolidColor(*this);
1745 }
1746
1747 //------------------------------------------------------------
1748
loadData(TInputStreamInterface & is)1749 void ArtisticSolidColor::loadData(TInputStreamInterface &is) {
1750 TSolidColorStyle::loadData(is);
1751 delete m_regionOutlineModifier;
1752 ArtisticModifier *mov = new ArtisticModifier(TPointD(), double());
1753 mov->loadData(is);
1754 m_regionOutlineModifier = mov;
1755 }
1756
1757 //------------------------------------------------------------
1758
saveData(TOutputStreamInterface & os) const1759 void ArtisticSolidColor::saveData(TOutputStreamInterface &os) const {
1760 TSolidColorStyle::saveData(os);
1761
1762 assert(m_regionOutlineModifier);
1763 ((ArtisticModifier *)m_regionOutlineModifier)->saveData(os);
1764 }
1765
1766 //------------------------------------------------------------
1767
getParamCount() const1768 int ArtisticSolidColor::getParamCount() const { return 3; }
1769
1770 //-----------------------------------------------------------------------------
1771
getParamType(int index) const1772 TColorStyle::ParamType ArtisticSolidColor::getParamType(int index) const {
1773 assert(0 <= index && index < getParamCount());
1774 return TColorStyle::DOUBLE;
1775 }
1776
1777 //-----------------------------------------------------------------------------
1778
getParamNames(int index) const1779 QString ArtisticSolidColor::getParamNames(int index) const {
1780 assert(0 <= index && index < 3);
1781 QString value;
1782 switch (index) {
1783 case 0:
1784 value = QCoreApplication::translate("ArtisticSolidColor", "Horiz Offset");
1785 break;
1786 case 1:
1787 value = QCoreApplication::translate("ArtisticSolidColor", "Vert Offset");
1788 break;
1789 case 2:
1790 value = QCoreApplication::translate("ArtisticSolidColor", "Noise");
1791 break;
1792 }
1793 return value;
1794 }
1795
1796 //-----------------------------------------------------------------------------
1797
getParamRange(int index,double & min,double & max) const1798 void ArtisticSolidColor::getParamRange(int index, double &min,
1799 double &max) const {
1800 assert(0 <= index && index < 3);
1801 switch (index) {
1802 case 0:
1803 min = 0.0;
1804 max = 20.0;
1805 break;
1806 case 1:
1807 min = 0.0;
1808 max = 20.0;
1809 break;
1810 case 2:
1811 min = 0.0;
1812 max = 200.0;
1813 break;
1814 }
1815 }
1816
1817 //-----------------------------------------------------------------------------
1818
getParamValue(TColorStyle::double_tag,int index) const1819 double ArtisticSolidColor::getParamValue(TColorStyle::double_tag,
1820 int index) const {
1821 assert(0 <= index && index < 3);
1822 double value;
1823 switch (index) {
1824 case 0:
1825 value = ((ArtisticModifier *)m_regionOutlineModifier)->getMovePoint().x;
1826 break;
1827 case 1:
1828 value = ((ArtisticModifier *)m_regionOutlineModifier)->getMovePoint().y;
1829 break;
1830 case 2:
1831 value = ((ArtisticModifier *)m_regionOutlineModifier)->getPeriod();
1832 break;
1833 }
1834 return value;
1835 }
1836
1837 //-----------------------------------------------------------------------------
1838
setParamValue(int index,double value)1839 void ArtisticSolidColor::setParamValue(int index, double value) {
1840 assert(0 <= index && index < 3);
1841
1842 TPointD oldMove =
1843 ((ArtisticModifier *)m_regionOutlineModifier)->getMovePoint();
1844 double oldPeriod = ((ArtisticModifier *)m_regionOutlineModifier)->getPeriod();
1845
1846 switch (index) {
1847 case 0:
1848 if (oldMove.x != value) {
1849 delete m_regionOutlineModifier;
1850 oldMove.x = value;
1851 m_regionOutlineModifier = new ArtisticModifier(oldMove, oldPeriod);
1852 updateVersionNumber();
1853 }
1854 break;
1855 case 1:
1856 if (oldMove.y != value) {
1857 delete m_regionOutlineModifier;
1858 oldMove.y = value;
1859 m_regionOutlineModifier = new ArtisticModifier(oldMove, oldPeriod);
1860 updateVersionNumber();
1861 }
1862 break;
1863 case 2:
1864 if (oldPeriod != value) {
1865 delete m_regionOutlineModifier;
1866 oldPeriod = value;
1867 m_regionOutlineModifier = new ArtisticModifier(oldMove, oldPeriod);
1868 updateVersionNumber();
1869 }
1870 break;
1871 }
1872 }
1873
1874 //------------------------------------------------------------
1875
drawRegion(const TColorFunction * cf,const bool antiAliasing,TRegionOutline & boundary) const1876 void ArtisticSolidColor::drawRegion(const TColorFunction *cf,
1877 const bool antiAliasing,
1878 TRegionOutline &boundary) const {
1879 TSolidColorStyle::drawRegion(cf, true, boundary);
1880 }
1881
1882 //***************************************************************************
1883 // TChalkFillStyle implementation
1884 //***************************************************************************
1885
TChalkFillStyle(const TPixel32 & color0,const TPixel32 & color1,const double density,const double size)1886 TChalkFillStyle::TChalkFillStyle(const TPixel32 &color0, const TPixel32 &color1,
1887 const double density, const double size)
1888 : TSolidColorStyle(color1)
1889 , m_color0(color0)
1890 , m_density(density)
1891 , m_size(size) {}
1892
1893 //------------------------------------------------------------
1894
TChalkFillStyle(const TPixel32 & color0,const TPixel32 & color1)1895 TChalkFillStyle::TChalkFillStyle(const TPixel32 &color0, const TPixel32 &color1)
1896 : TSolidColorStyle(color0)
1897 , m_color0(color1)
1898 , m_density(25.0)
1899 , m_size(1.0) {}
1900
1901 //------------------------------------------------------------
1902
clone() const1903 TColorStyle *TChalkFillStyle::clone() const {
1904 return new TChalkFillStyle(*this);
1905 }
1906
1907 //------------------------------------------------------------
1908
getParamCount() const1909 int TChalkFillStyle::getParamCount() const { return 2; }
1910
1911 //-----------------------------------------------------------------------------
1912
getParamType(int index) const1913 TColorStyle::ParamType TChalkFillStyle::getParamType(int index) const {
1914 assert(0 <= index && index < getParamCount());
1915 return TColorStyle::DOUBLE;
1916 }
1917
1918 //-----------------------------------------------------------------------------
1919
getParamNames(int index) const1920 QString TChalkFillStyle::getParamNames(int index) const {
1921 assert(0 <= index && index < 2);
1922 QString value;
1923 switch (index) {
1924 case 0:
1925 value = QCoreApplication::translate("TChalkFillStyle", "Density");
1926 break;
1927 case 1:
1928 value = QCoreApplication::translate("TChalkFillStyle", "Dot Size");
1929 break;
1930 }
1931
1932 return value;
1933 }
1934
1935 //-----------------------------------------------------------------------------
1936
loadData(int ids,TInputStreamInterface & is)1937 void TChalkFillStyle::loadData(int ids, TInputStreamInterface &is) {
1938 if (ids != 1133)
1939 throw TException("Chalk Fill style: unknown obsolete format");
1940 TSolidColorStyle::loadData(is);
1941 is >> m_color0 >> m_density >> m_size;
1942 m_density = m_density / 1000;
1943 if (m_density > 100) m_density = 100;
1944 }
1945
1946 //-----------------------------------------------------------------------------
1947
getParamRange(int index,double & min,double & max) const1948 void TChalkFillStyle::getParamRange(int index, double &min, double &max) const {
1949 assert(0 <= index && index < 2);
1950 switch (index) {
1951 case 0:
1952 min = 0;
1953 max = 100.0;
1954 break;
1955 case 1:
1956 min = 0.0;
1957 max = 10.0;
1958 break;
1959 }
1960 }
1961
1962 //-----------------------------------------------------------------------------
1963
getParamValue(TColorStyle::double_tag,int index) const1964 double TChalkFillStyle::getParamValue(TColorStyle::double_tag,
1965 int index) const {
1966 assert(0 <= index && index < 2);
1967 double value;
1968 switch (index) {
1969 case 0:
1970 value = m_density;
1971 break;
1972 case 1:
1973 value = m_size;
1974 break;
1975 }
1976 return value;
1977 }
1978
1979 //-----------------------------------------------------------------------------
1980
setParamValue(int index,double value)1981 void TChalkFillStyle::setParamValue(int index, double value) {
1982 assert(0 <= index && index < 2);
1983
1984 switch (index) {
1985 case 0:
1986 m_density = value;
1987 break;
1988 case 1:
1989 m_size = value;
1990 break;
1991 }
1992 }
1993
1994 //------------------------------------------------------------
1995
loadData(TInputStreamInterface & is)1996 void TChalkFillStyle::loadData(TInputStreamInterface &is) {
1997 TSolidColorStyle::loadData(is);
1998 is >> m_color0;
1999 is >> m_density;
2000 is >> m_size;
2001 }
2002
2003 //------------------------------------------------------------
saveData(TOutputStreamInterface & os) const2004 void TChalkFillStyle::saveData(TOutputStreamInterface &os) const {
2005 TSolidColorStyle::saveData(os);
2006 os << m_color0;
2007 os << m_density;
2008 os << m_size;
2009 }
2010 //------------------------------------------------------------
getColorParamValue(int index) const2011 TPixel32 TChalkFillStyle::getColorParamValue(int index) const {
2012 return index == 0 ? m_color0 : TSolidColorStyle::getMainColor();
2013 }
2014 //------------------------------------------------------------
setColorParamValue(int index,const TPixel32 & color)2015 void TChalkFillStyle::setColorParamValue(int index, const TPixel32 &color) {
2016 if (index == 0)
2017 m_color0 = color;
2018 else {
2019 TSolidColorStyle::setMainColor(color);
2020 }
2021 }
2022
2023 //------------------------------------------------------------
2024
drawRegion(const TColorFunction * cf,const bool antiAliasing,TRegionOutline & boundary) const2025 void TChalkFillStyle::drawRegion(const TColorFunction *cf,
2026 const bool antiAliasing,
2027 TRegionOutline &boundary) const {
2028 // const bool isTransparent=m_color0.m<255;
2029
2030 // TRegionOutline::Boundary& exter=*(boundary.m_exterior);
2031 // TRegionOutline::Boundary& inter=*(boundary.m_interior);
2032
2033 TPixel32 color0;
2034 if (cf)
2035 color0 = (*(cf))(m_color0);
2036 else
2037 color0 = m_color0;
2038
2039 TStencilControl *stenc = TStencilControl::instance();
2040 TPixel32 backgroundColor = TSolidColorStyle::getMainColor();
2041 if (cf) backgroundColor = (*(cf))(backgroundColor);
2042
2043 if (backgroundColor.m == 0) { // only to create stencil mask
2044 TSolidColorStyle appStyle(TPixel32::White);
2045 stenc->beginMask(); // does not draw on screen
2046 appStyle.drawRegion(0, false, boundary);
2047 } else { // create stencil mask and draw on screen
2048 stenc->beginMask(TStencilControl::DRAW_ALSO_ON_SCREEN);
2049 TSolidColorStyle::drawRegion(cf, antiAliasing, boundary);
2050 }
2051 stenc->endMask();
2052 stenc->enableMask(TStencilControl::SHOW_INSIDE);
2053
2054 int chalkId = glGenLists(1);
2055 glNewList(chalkId, GL_COMPILE);
2056 glBegin(GL_QUADS);
2057 glVertex2d(m_size, m_size);
2058 glVertex2d(-m_size, m_size);
2059 glVertex2d(-m_size, -m_size);
2060 glVertex2d(m_size, -m_size);
2061 glEnd();
2062 glEndList();
2063 TRandom rnd;
2064
2065 double lx = boundary.m_bbox.x1 - boundary.m_bbox.x0;
2066 double ly = boundary.m_bbox.y1 - boundary.m_bbox.y0;
2067
2068 // cioe' imposta una densita' tale, per cui in una regione che ha bbox 200x200
2069 // inserisce esattamente m_density punti
2070 int pointNumber = (int)(m_density * ((lx * ly) * 0.02));
2071
2072 for (int i = 0; i < pointNumber; i++) {
2073 TPixel32 tmpcolor = color0;
2074 double shiftx = boundary.m_bbox.x0 + rnd.getFloat() * lx;
2075 double shifty = boundary.m_bbox.y0 + rnd.getFloat() * ly;
2076 tmpcolor.m = (UCHAR)(tmpcolor.m * rnd.getFloat());
2077 tglColor(tmpcolor);
2078 glPushMatrix();
2079 glTranslated(shiftx, shifty, 0.0);
2080 glCallList(chalkId);
2081 glPopMatrix();
2082 }
2083
2084 // glEnd(); e questo che era???
2085
2086 glDeleteLists(chalkId, 1);
2087
2088 stenc->disableMask();
2089 }
2090
2091 //***************************************************************************
2092 // TChessFillStyle implementation
2093 //***************************************************************************
2094
TChessFillStyle(const TPixel32 & bgColor,const TPixel32 & pointColor,const double HDist,const double VDist,const double Angle)2095 TChessFillStyle::TChessFillStyle(const TPixel32 &bgColor,
2096 const TPixel32 &pointColor, const double HDist,
2097 const double VDist, const double Angle)
2098 : TSolidColorStyle(bgColor)
2099 , m_pointColor(pointColor)
2100 , m_HDist(HDist)
2101 , m_VDist(VDist)
2102 , m_Angle(Angle) {}
2103
2104 //------------------------------------------------------------
2105
TChessFillStyle(const TPixel32 & color)2106 TChessFillStyle::TChessFillStyle(const TPixel32 &color)
2107 : TSolidColorStyle(TPixel32::White)
2108 , m_pointColor(color)
2109 , m_HDist(10.0)
2110 , m_VDist(10.0)
2111 , m_Angle(0.0) {}
2112
2113 //------------------------------------------------------------
2114
clone() const2115 TColorStyle *TChessFillStyle::clone() const {
2116 return new TChessFillStyle(*this);
2117 }
2118
2119 //------------------------------------------------------------
2120
getParamCount() const2121 int TChessFillStyle::getParamCount() const { return 3; }
2122
2123 //-----------------------------------------------------------------------------
2124
getParamType(int index) const2125 TColorStyle::ParamType TChessFillStyle::getParamType(int index) const {
2126 assert(0 <= index && index < getParamCount());
2127 return TColorStyle::DOUBLE;
2128 }
2129
2130 //-----------------------------------------------------------------------------
2131
getParamNames(int index) const2132 QString TChessFillStyle::getParamNames(int index) const {
2133 assert(0 <= index && index < 3);
2134
2135 QString value;
2136 switch (index) {
2137 case 0:
2138 value = QCoreApplication::translate("TChessFillStyle", "Horiz Size");
2139 break;
2140 case 1:
2141 value = QCoreApplication::translate("TChessFillStyle", "Vert Size");
2142 break;
2143 case 2:
2144 value = QCoreApplication::translate("TChessFillStyle", "Angle");
2145 break;
2146 }
2147
2148 return value;
2149 }
2150
2151 //-----------------------------------------------------------------------------
2152
getParamRange(int index,double & min,double & max) const2153 void TChessFillStyle::getParamRange(int index, double &min, double &max) const {
2154 assert(0 <= index && index < 3);
2155 switch (index) {
2156 case 0:
2157 min = 1.0;
2158 max = 100.0;
2159 break;
2160 case 1:
2161 min = 1.0;
2162 max = 100.0;
2163 break;
2164 case 2:
2165 min = -45.0;
2166 max = 45.0;
2167 break;
2168 }
2169 }
2170
2171 //-----------------------------------------------------------------------------
2172
getParamValue(TColorStyle::double_tag,int index) const2173 double TChessFillStyle::getParamValue(TColorStyle::double_tag,
2174 int index) const {
2175 assert(0 <= index && index < 3);
2176
2177 switch (index) {
2178 case 0:
2179 return m_HDist;
2180 case 1:
2181 return m_VDist;
2182 case 2:
2183 return m_Angle;
2184 }
2185 return 0.0;
2186 }
2187
2188 //-----------------------------------------------------------------------------
2189
setParamValue(int index,double value)2190 void TChessFillStyle::setParamValue(int index, double value) {
2191 assert(0 <= index && index < 3);
2192
2193 switch (index) {
2194 case 0:
2195 m_HDist = value;
2196 break;
2197 case 1:
2198 m_VDist = value;
2199 break;
2200 case 2:
2201 m_Angle = value;
2202 break;
2203 }
2204 }
2205
2206 //------------------------------------------------------------
2207
loadData(TInputStreamInterface & is)2208 void TChessFillStyle::loadData(TInputStreamInterface &is) {
2209 TSolidColorStyle::loadData(is);
2210 is >> m_HDist;
2211 is >> m_VDist;
2212 is >> m_Angle;
2213 is >> m_pointColor;
2214 }
2215
2216 //------------------------------------------------------------
2217
saveData(TOutputStreamInterface & os) const2218 void TChessFillStyle::saveData(TOutputStreamInterface &os) const {
2219 TSolidColorStyle::saveData(os);
2220 os << m_HDist;
2221 os << m_VDist;
2222 os << m_Angle;
2223 os << m_pointColor;
2224 }
2225
2226 //------------------------------------------------------------
2227
getColorParamValue(int index) const2228 TPixel32 TChessFillStyle::getColorParamValue(int index) const {
2229 return index == 0 ? m_pointColor : TSolidColorStyle::getMainColor();
2230 }
2231
2232 //------------------------------------------------------------
2233
setColorParamValue(int index,const TPixel32 & color)2234 void TChessFillStyle::setColorParamValue(int index, const TPixel32 &color) {
2235 if (index == 0)
2236 m_pointColor = color;
2237 else {
2238 TSolidColorStyle::setMainColor(color);
2239 }
2240 }
2241
2242 //------------------------------------------------------------
2243
makeGrid(TRectD & bbox,TRotation & rotM,std::vector<TPointD> & grid,int & nbClip) const2244 void TChessFillStyle::makeGrid(TRectD &bbox, TRotation &rotM,
2245 std::vector<TPointD> &grid, int &nbClip) const {
2246 double lx = bbox.x1 - bbox.x0;
2247 double ly = bbox.y1 - bbox.y0;
2248 TPointD center =
2249 TPointD((bbox.x1 + bbox.x0) * 0.5, (bbox.y1 + bbox.y0) * 0.5);
2250 double l = (lx + ly) / 1.3;
2251 double l2 = l / 2;
2252
2253 bool isFirst = true;
2254 for (double y = -l2; y < (l2 + m_VDist); y += m_VDist) {
2255 double x = isFirst ? -l2 : -l2 + m_HDist;
2256 isFirst = !isFirst;
2257 for (; x < (l2 + m_HDist); x += 2 * m_HDist) {
2258 grid.push_back(rotM * TPointD(x, y) + center);
2259 nbClip++;
2260 }
2261 }
2262 }
2263
2264 //------------------------------------------------------------
2265
drawRegion(const TColorFunction * cf,const bool antiAliasing,TRegionOutline & boundary) const2266 void TChessFillStyle::drawRegion(const TColorFunction *cf,
2267 const bool antiAliasing,
2268 TRegionOutline &boundary) const {
2269 // const bool isTransparent=m_pointColor.m<255;
2270
2271 TStencilControl *stenc = TStencilControl::instance();
2272 TPixel32 backgroundColor = TSolidColorStyle::getMainColor();
2273 if (cf) backgroundColor = (*(cf))(backgroundColor);
2274
2275 if (backgroundColor.m == 0) { // only to create stencil mask
2276 TSolidColorStyle appStyle(TPixel32::White);
2277 stenc->beginMask(); // does not draw on screen
2278 appStyle.drawRegion(0, false, boundary);
2279 } else { // create stencil mask and draw on screen
2280 stenc->beginMask(TStencilControl::DRAW_ALSO_ON_SCREEN);
2281 TSolidColorStyle::drawRegion(cf, antiAliasing, boundary);
2282 }
2283 stenc->endMask();
2284
2285 stenc->enableMask(TStencilControl::SHOW_INSIDE);
2286
2287 TPixel32 color;
2288 if (cf)
2289 color = (*(cf))(m_pointColor);
2290 else
2291 color = m_pointColor;
2292
2293 tglColor(color);
2294
2295 TPointD vert[4];
2296 vert[0].x = -0.5;
2297 vert[0].y = 0.5;
2298 vert[1].x = -0.5;
2299 vert[1].y = -0.5;
2300 vert[2].x = 0.5;
2301 vert[2].y = -0.5;
2302 vert[3].x = 0.5;
2303 vert[3].y = 0.5;
2304
2305 TRotation rotM(m_Angle);
2306 TScale scaleM(m_HDist, m_VDist);
2307 for (int i = 0; i < 4; i++) vert[i] = rotM * scaleM * vert[i];
2308
2309 int chessId = glGenLists(1);
2310 glNewList(chessId, GL_COMPILE);
2311 glBegin(GL_QUADS);
2312 glVertex2d(vert[0].x, vert[0].y);
2313 glVertex2d(vert[1].x, vert[1].y);
2314 glVertex2d(vert[2].x, vert[2].y);
2315 glVertex2d(vert[3].x, vert[3].y);
2316 glEnd();
2317 glEndList();
2318
2319 int nbClip = 1;
2320 std::vector<TPointD> grid;
2321 makeGrid(boundary.m_bbox, rotM, grid, nbClip);
2322
2323 std::vector<TPointD>::const_iterator it = grid.begin();
2324 std::vector<TPointD>::const_iterator ite = grid.end();
2325 for (; it != ite; it++) {
2326 glPushMatrix();
2327 glTranslated(it->x, it->y, 0.0);
2328 glCallList(chessId);
2329 glPopMatrix();
2330 }
2331
2332 stenc->disableMask();
2333 glDeleteLists(chessId, 1);
2334 }
2335
2336 //***************************************************************************
2337 // TStripeFillStyle implementation
2338 //***************************************************************************
2339
TStripeFillStyle(const TPixel32 & bgColor,const TPixel32 & pointColor,const double Dist,const double Angle,const double Thickness)2340 TStripeFillStyle::TStripeFillStyle(const TPixel32 &bgColor,
2341 const TPixel32 &pointColor,
2342 const double Dist, const double Angle,
2343 const double Thickness)
2344 : TSolidColorStyle(bgColor)
2345 , m_pointColor(pointColor)
2346 , m_Dist(Dist)
2347 , m_Angle(Angle)
2348 , m_Thickness(Thickness) {}
2349
2350 //------------------------------------------------------------
2351
TStripeFillStyle(const TPixel32 & color)2352 TStripeFillStyle::TStripeFillStyle(const TPixel32 &color)
2353 : TSolidColorStyle(TPixel32::Transparent)
2354 , m_pointColor(color)
2355 , m_Dist(15.0)
2356 , m_Angle(0.0)
2357 , m_Thickness(6.0) {}
2358
2359 //------------------------------------------------------------
2360
clone() const2361 TColorStyle *TStripeFillStyle::clone() const {
2362 return new TStripeFillStyle(*this);
2363 }
2364
2365 //------------------------------------------------------------
2366
getParamCount() const2367 int TStripeFillStyle::getParamCount() const { return 3; }
2368
2369 //-----------------------------------------------------------------------------
2370
getParamType(int index) const2371 TColorStyle::ParamType TStripeFillStyle::getParamType(int index) const {
2372 assert(0 <= index && index < getParamCount());
2373 return TColorStyle::DOUBLE;
2374 }
2375
2376 //-----------------------------------------------------------------------------
2377
getParamNames(int index) const2378 QString TStripeFillStyle::getParamNames(int index) const {
2379 assert(0 <= index && index < 3);
2380
2381 QString value;
2382 switch (index) {
2383 case 0:
2384 value = QCoreApplication::translate("TStripeFillStyle", "Distance");
2385 break;
2386 case 1:
2387 value = QCoreApplication::translate("TStripeFillStyle", "Angle");
2388 break;
2389 case 2:
2390 value = QCoreApplication::translate("TStripeFillStyle", "Thickness");
2391 break;
2392 }
2393
2394 return value;
2395 }
2396
2397 //-----------------------------------------------------------------------------
2398
getParamRange(int index,double & min,double & max) const2399 void TStripeFillStyle::getParamRange(int index, double &min,
2400 double &max) const {
2401 assert(0 <= index && index < 3);
2402 switch (index) {
2403 case 0:
2404 min = 1.0;
2405 max = 100.0;
2406 break;
2407 case 1:
2408 min = -90.0;
2409 max = 90.0;
2410 break;
2411 case 2:
2412 min = 0.5;
2413 max = 100.0;
2414 break;
2415 }
2416 }
2417
2418 //-----------------------------------------------------------------------------
2419
getParamValue(TColorStyle::double_tag,int index) const2420 double TStripeFillStyle::getParamValue(TColorStyle::double_tag,
2421 int index) const {
2422 assert(0 <= index && index < 3);
2423
2424 switch (index) {
2425 case 0:
2426 return m_Dist;
2427 case 1:
2428 return m_Angle;
2429 case 2:
2430 return m_Thickness;
2431 }
2432 return 0.0;
2433 }
2434
2435 //-----------------------------------------------------------------------------
2436
setParamValue(int index,double value)2437 void TStripeFillStyle::setParamValue(int index, double value) {
2438 assert(0 <= index && index < 3);
2439
2440 switch (index) {
2441 case 0:
2442 m_Dist = value;
2443 break;
2444 case 1:
2445 m_Angle = value;
2446 break;
2447 case 2:
2448 m_Thickness = value;
2449 break;
2450 }
2451 }
2452
2453 //------------------------------------------------------------
2454
loadData(TInputStreamInterface & is)2455 void TStripeFillStyle::loadData(TInputStreamInterface &is) {
2456 TSolidColorStyle::loadData(is);
2457 is >> m_Dist;
2458 is >> m_Angle;
2459 is >> m_Thickness;
2460 is >> m_pointColor;
2461 }
2462
2463 //------------------------------------------------------------
2464
saveData(TOutputStreamInterface & os) const2465 void TStripeFillStyle::saveData(TOutputStreamInterface &os) const {
2466 TSolidColorStyle::saveData(os);
2467 os << m_Dist;
2468 os << m_Angle;
2469 os << m_Thickness;
2470 os << m_pointColor;
2471 }
2472
getThickline(const TPointD & lc,const double lx,TPointD & p0,TPointD & p1,TPointD & p2,TPointD & p3) const2473 void TStripeFillStyle::getThickline(const TPointD &lc, const double lx,
2474 TPointD &p0, TPointD &p1, TPointD &p2,
2475 TPointD &p3) const {
2476 double l = m_Thickness / cos(degree2rad(m_Angle));
2477 l *= 0.5;
2478 p0 = TPointD(lc.x, lc.y - l);
2479 p1 = TPointD(lc.x, lc.y + l);
2480 double y = lc.y + lx * tan(degree2rad(m_Angle));
2481 p2 = TPointD(lc.x + lx, y + l);
2482 p3 = TPointD(lc.x + lx, y - l);
2483 }
2484
2485 //------------------------------------------------------------
2486
getColorParamValue(int index) const2487 TPixel32 TStripeFillStyle::getColorParamValue(int index) const {
2488 return index == 0 ? m_pointColor : TSolidColorStyle::getMainColor();
2489 }
2490
2491 //------------------------------------------------------------
setColorParamValue(int index,const TPixel32 & color)2492 void TStripeFillStyle::setColorParamValue(int index, const TPixel32 &color) {
2493 if (index == 0)
2494 m_pointColor = color;
2495 else {
2496 TSolidColorStyle::setMainColor(color);
2497 }
2498 }
2499
2500 //------------------------------------------------------------
2501
trim(TPointD & p0,TPointD & p1,double y0,double y1)2502 inline void trim(TPointD &p0, TPointD &p1, double y0, double y1) {
2503 if (p0.y < y0) {
2504 // Trim the first extreme of the segment at y0
2505 double t = (y0 - p0.y) / (p1.y - p0.y);
2506 p0.x = p0.x + t * (p1.x - p0.x);
2507 p0.y = y0;
2508 } else if (p0.y > y1) {
2509 // The same, at y1
2510 double t = (y1 - p0.y) / (p1.y - p0.y);
2511 p0.x = p0.x + t * (p1.x - p0.x);
2512 p0.y = y1;
2513 }
2514
2515 // Same for p1
2516 if (p1.y < y0) {
2517 double t = (y0 - p1.y) / (p0.y - p1.y);
2518 p1.x = p1.x + t * (p0.x - p1.x);
2519 p1.y = y0;
2520 } else if (p1.y > y1) {
2521 double t = (y1 - p1.y) / (p0.y - p1.y);
2522 p1.x = p1.x + t * (p0.x - p1.x);
2523 p1.y = y1;
2524 }
2525 }
2526
2527 //------------------------------------------------------------
2528
drawRegion(const TColorFunction * cf,const bool antiAliasing,TRegionOutline & boundary) const2529 void TStripeFillStyle::drawRegion(const TColorFunction *cf,
2530 const bool antiAliasing,
2531 TRegionOutline &boundary) const {
2532 const bool isTransparent = m_pointColor.m < 255;
2533
2534 TStencilControl *stenc = TStencilControl::instance();
2535
2536 TPixel32 backgroundColor = TSolidColorStyle::getMainColor();
2537 if (cf) backgroundColor = (*(cf))(backgroundColor);
2538
2539 if (backgroundColor.m == 0) { // only to create stencil mask
2540 TSolidColorStyle appStyle(TPixel32::White);
2541 stenc->beginMask();
2542 appStyle.drawRegion(0, false, boundary);
2543 } else {
2544 stenc->beginMask(TStencilControl::DRAW_ALSO_ON_SCREEN);
2545 TSolidColorStyle::drawRegion(cf, antiAliasing, boundary);
2546 }
2547 stenc->endMask();
2548
2549 stenc->enableMask(TStencilControl::SHOW_INSIDE);
2550
2551 if (isTransparent) {
2552 // glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
2553 // glEnable(GL_BLEND);
2554 //// <-- tglEnableBlending();
2555 }
2556
2557 TPixel32 color;
2558 if (cf)
2559 color = (*(cf))(m_pointColor);
2560 else
2561 color = m_pointColor;
2562
2563 tglColor(color);
2564
2565 // Horizontal Lines
2566 if (fabs(m_Angle) != 90) {
2567 double lx = boundary.m_bbox.x1 - boundary.m_bbox.x0;
2568 // double ly=boundary.m_bbox.y1-boundary.m_bbox.y0;
2569 double beg = boundary.m_bbox.y0;
2570 double end = boundary.m_bbox.y1;
2571 beg = m_Angle <= 0 ? beg : beg - lx * tan(degree2rad(m_Angle));
2572 end = m_Angle >= 0 ? end : end - lx * tan(degree2rad(m_Angle));
2573 double dist = m_Dist / cos(degree2rad(m_Angle));
2574
2575 double y;
2576
2577 TStencilControl *stenc2 = TStencilControl::instance();
2578 stenc2->beginMask(TStencilControl::DRAW_ALSO_ON_SCREEN);
2579
2580 glBegin(GL_QUADS);
2581 for (y = beg; y <= end; y += dist) {
2582 TPointD p0, p1, p2, p3;
2583 getThickline(TPointD(boundary.m_bbox.x0, y), lx, p0, p1, p2, p3);
2584 tglVertex(p0);
2585 tglVertex(p1);
2586 tglVertex(p2);
2587 tglVertex(p3);
2588 }
2589 glEnd();
2590 stenc2->endMask();
2591
2592 stenc2->enableMask(TStencilControl::SHOW_OUTSIDE);
2593
2594 if (m_Angle != 0) // ANTIALIASING
2595 {
2596 // glHint(GL_LINE_SMOOTH_HINT, GL_NICEST);
2597 // glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
2598 // glEnable(GL_BLEND);
2599 // glEnable(GL_LINE_SMOOTH);
2600
2601 tglEnableLineSmooth();
2602
2603 // NOTE: Trimming the fat lines is necessary outside the (-60, 60) angles
2604 // interval
2605 // seemingly due to a bug in MAC-Leopard's openGL implementation...
2606
2607 glBegin(GL_LINES);
2608 for (y = beg; y <= end; y += dist) {
2609 TPointD p0, p1, p2, p3;
2610 getThickline(TPointD(boundary.m_bbox.x0, y), lx, p0, p1, p2, p3);
2611 trim(p1, p2, boundary.m_bbox.y0, boundary.m_bbox.y1);
2612 tglVertex(p1);
2613 tglVertex(p2);
2614
2615 trim(p0, p3, boundary.m_bbox.y0, boundary.m_bbox.y1);
2616 tglVertex(p0);
2617 tglVertex(p3);
2618 }
2619 glEnd();
2620 }
2621 stenc2->disableMask();
2622
2623 } else {
2624 double beg = boundary.m_bbox.x0;
2625 double end = boundary.m_bbox.x1;
2626 double y0 = boundary.m_bbox.y0;
2627 double y1 = boundary.m_bbox.y1;
2628
2629 glBegin(GL_QUADS);
2630 for (double x = beg; x <= end; x += m_Dist) {
2631 TPointD p0(x, y0);
2632 TPointD p1(x + m_Thickness, y0);
2633 TPointD p2(x, y1);
2634 TPointD p3(x + m_Thickness, y1);
2635 tglVertex(p0);
2636 tglVertex(p1);
2637 tglVertex(p3);
2638 tglVertex(p2);
2639 }
2640 glEnd();
2641 }
2642
2643 // tglColor(TPixel32::White);
2644
2645 stenc->disableMask();
2646 }
2647
2648 //------------------------------------------------------------
2649
nbClip(const TRectD & bbox) const2650 int TStripeFillStyle::nbClip(const TRectD &bbox) const {
2651 int nbClip = 1; // the bbox rectangle
2652
2653 if (fabs(m_Angle) != 90) {
2654 double lx = bbox.x1 - bbox.x0;
2655 // double ly=bbox.y1-bbox.y0;
2656 double beg = bbox.y0;
2657 double end = bbox.y1;
2658 beg = m_Angle <= 0 ? beg : beg - lx * tan(degree2rad(m_Angle));
2659 end = m_Angle >= 0 ? end : end - lx * tan(degree2rad(m_Angle));
2660 double dist = m_Dist / cos(degree2rad(m_Angle));
2661 for (double y = beg; y <= end; y += dist) nbClip++;
2662 } else {
2663 double beg = bbox.x0;
2664 double end = bbox.x1;
2665 // double y0=bbox.y0;
2666 // double y1=bbox.y1;
2667 for (double x = beg; x <= end; x += m_Dist) nbClip++;
2668 }
2669
2670 return nbClip;
2671 }
2672
2673 //------------------------------------------------------------
2674
makeIcon(const TDimension & d)2675 void TStripeFillStyle::makeIcon(const TDimension &d) {
2676 // Saves the values of member variables and sets the right icon values
2677 double LDist = m_Dist;
2678 double LAngle = m_Angle;
2679 double LThickness = m_Thickness;
2680
2681 m_Dist *= 1.33;
2682 m_Thickness *= 1.66;
2683
2684 TColorStyle::makeIcon(d);
2685
2686 m_Dist = LDist;
2687 m_Angle = LAngle;
2688 m_Thickness = LThickness;
2689 }
2690
2691 //***************************************************************************
2692 // TLinGradFillStyle implementation
2693 //***************************************************************************
2694
TLinGradFillStyle(const TPixel32 & bgColor,const TPixel32 & pointColor,const double Angle,const double XPos,const double YPos,const double Size)2695 TLinGradFillStyle::TLinGradFillStyle(const TPixel32 &bgColor,
2696 const TPixel32 &pointColor,
2697 const double Angle, const double XPos,
2698 const double YPos, const double Size)
2699 : TSolidColorStyle(bgColor)
2700 , m_pointColor(pointColor)
2701 , m_Angle(Angle)
2702 , m_XPos(XPos)
2703 , m_YPos(YPos)
2704 , m_Size(Size) {}
2705
2706 //-----------------------------------------------------------------------------
2707
TLinGradFillStyle(const TPixel32 & color)2708 TLinGradFillStyle::TLinGradFillStyle(const TPixel32 &color)
2709 : TSolidColorStyle(TPixel32::White)
2710 , m_pointColor(color)
2711 , m_Angle(0.0)
2712 , m_XPos(0.0)
2713 , m_YPos(0.0)
2714 , m_Size(100.0) {}
2715
2716 //-----------------------------------------------------------------------------
2717
clone() const2718 TColorStyle *TLinGradFillStyle::clone() const {
2719 return new TLinGradFillStyle(*this);
2720 }
2721
2722 //------------------------------------------------------------
2723
getParamCount() const2724 int TLinGradFillStyle::getParamCount() const { return 4; }
2725
2726 //-----------------------------------------------------------------------------
2727
getParamType(int index) const2728 TColorStyle::ParamType TLinGradFillStyle::getParamType(int index) const {
2729 assert(0 <= index && index < getParamCount());
2730 return TColorStyle::DOUBLE;
2731 }
2732
2733 //-----------------------------------------------------------------------------
2734
getParamNames(int index) const2735 QString TLinGradFillStyle::getParamNames(int index) const {
2736 assert(0 <= index && index < 4);
2737
2738 QString value;
2739 switch (index) {
2740 case 0:
2741 value = QCoreApplication::translate("TLinGradFillStyle", "Angle");
2742 break;
2743 case 1:
2744 value = QCoreApplication::translate("TLinGradFillStyle", "X Position");
2745 break;
2746 case 2:
2747 value = QCoreApplication::translate("TLinGradFillStyle", "Y Position");
2748 break;
2749 case 3:
2750 value = QCoreApplication::translate("TLinGradFillStyle", "Smoothness");
2751 break;
2752 }
2753
2754 return value;
2755 }
2756
2757 //-----------------------------------------------------------------------------
2758
getParamRange(int index,double & min,double & max) const2759 void TLinGradFillStyle::getParamRange(int index, double &min,
2760 double &max) const {
2761 assert(0 <= index && index < 4);
2762 switch (index) {
2763 case 0:
2764 min = -180.0;
2765 max = 180.0;
2766 break;
2767 case 1:
2768 min = -100.0;
2769 max = 100.0;
2770 break;
2771 case 2:
2772 min = -100.0;
2773 max = 100.0;
2774 break;
2775 case 3:
2776 min = 1.0;
2777 max = 500.0;
2778 break;
2779 }
2780 }
2781
2782 //-----------------------------------------------------------------------------
2783
getParamValue(TColorStyle::double_tag,int index) const2784 double TLinGradFillStyle::getParamValue(TColorStyle::double_tag,
2785 int index) const {
2786 assert(0 <= index && index < 4);
2787
2788 switch (index) {
2789 case 0:
2790 return m_Angle;
2791 case 1:
2792 return m_XPos;
2793 case 2:
2794 return m_YPos;
2795 case 3:
2796 return m_Size;
2797 }
2798 return 0.0;
2799 }
2800
2801 //-----------------------------------------------------------------------------
2802
setParamValue(int index,double value)2803 void TLinGradFillStyle::setParamValue(int index, double value) {
2804 assert(0 <= index && index < 4);
2805
2806 switch (index) {
2807 case 0:
2808 m_Angle = value;
2809 break;
2810 case 1:
2811 m_XPos = value;
2812 break;
2813 case 2:
2814 m_YPos = value;
2815 break;
2816 case 3:
2817 m_Size = value;
2818 break;
2819 }
2820 }
2821
2822 //------------------------------------------------------------
2823
loadData(TInputStreamInterface & is)2824 void TLinGradFillStyle::loadData(TInputStreamInterface &is) {
2825 TSolidColorStyle::loadData(is);
2826 is >> m_Angle;
2827 is >> m_XPos;
2828 is >> m_YPos;
2829 is >> m_Size;
2830 is >> m_pointColor;
2831 }
2832
2833 //------------------------------------------------------------
2834
saveData(TOutputStreamInterface & os) const2835 void TLinGradFillStyle::saveData(TOutputStreamInterface &os) const {
2836 TSolidColorStyle::saveData(os);
2837 os << m_Angle;
2838 os << m_XPos;
2839 os << m_YPos;
2840 os << m_Size;
2841 os << m_pointColor;
2842 }
2843
2844 //------------------------------------------------------------
2845
getColorParamValue(int index) const2846 TPixel32 TLinGradFillStyle::getColorParamValue(int index) const {
2847 return index == 0 ? m_pointColor : TSolidColorStyle::getMainColor();
2848 }
2849
2850 //------------------------------------------------------------
2851
setColorParamValue(int index,const TPixel32 & color)2852 void TLinGradFillStyle::setColorParamValue(int index, const TPixel32 &color) {
2853 if (index == 0)
2854 m_pointColor = color;
2855 else {
2856 TSolidColorStyle::setMainColor(color);
2857 }
2858 }
2859
2860 //------------------------------------------------------------
2861
getRects(const TRectD & bbox,std::vector<TPointD> & r0,std::vector<TPointD> & r1,std::vector<TPointD> & r2) const2862 void TLinGradFillStyle::getRects(const TRectD &bbox, std::vector<TPointD> &r0,
2863 std::vector<TPointD> &r1,
2864 std::vector<TPointD> &r2) const {
2865 r0.clear();
2866 r1.clear();
2867 r2.clear();
2868
2869 TPointD p0, p1, p2, p3;
2870 double lx = bbox.x1 - bbox.x0;
2871 double ly = bbox.y1 - bbox.y0;
2872 TPointD center((bbox.x1 + bbox.x0) / 2.0, (bbox.y1 + bbox.y0) / 2.0);
2873 center = center + TPointD(m_XPos * 0.01 * lx * 0.5, m_YPos * 0.01 * ly * 0.5);
2874 double l = tdistance(TPointD(bbox.x0, bbox.y0), TPointD(bbox.x1, bbox.y1));
2875
2876 r0.push_back(TPointD(-m_Size - l, l));
2877 r0.push_back(TPointD(-m_Size - l, -l));
2878 r0.push_back(TPointD(-m_Size, -l));
2879 r0.push_back(TPointD(-m_Size, l));
2880
2881 r1.push_back(TPointD(-m_Size, l));
2882 r1.push_back(TPointD(-m_Size, -l));
2883 r1.push_back(TPointD(m_Size, -l));
2884 r1.push_back(TPointD(m_Size, l));
2885
2886 r2.push_back(TPointD(m_Size, l));
2887 r2.push_back(TPointD(m_Size, -l));
2888 r2.push_back(TPointD(m_Size + l, -l));
2889 r2.push_back(TPointD(m_Size + l, l));
2890
2891 TRotation rotM(m_Angle);
2892 TTranslation traM(center);
2893 TAffine M(traM * rotM);
2894
2895 for (int i = 0; i < 4; i++) {
2896 r0[i] = M * r0[i];
2897 r1[i] = M * r1[i];
2898 r2[i] = M * r2[i];
2899 }
2900 }
2901
2902 //------------------------------------------------------------
2903
drawRegion(const TColorFunction * cf,const bool antiAliasing,TRegionOutline & boundary) const2904 void TLinGradFillStyle::drawRegion(const TColorFunction *cf,
2905 const bool antiAliasing,
2906 TRegionOutline &boundary) const {
2907 // only to create stencil mask
2908 TStencilControl *stenc = TStencilControl::instance();
2909 TSolidColorStyle appStyle(TPixel32::White);
2910 stenc->beginMask(); // does not draw on screen
2911 appStyle.drawRegion(0, false, boundary);
2912 stenc->endMask();
2913
2914 // compute colors
2915 TPixel32 color1, color2;
2916 if (cf) {
2917 color1 = (*(cf))(TSolidColorStyle::getMainColor());
2918 color2 = (*(cf))(m_pointColor);
2919 } else {
2920 color1 = TSolidColorStyle::getMainColor();
2921 color2 = m_pointColor;
2922 }
2923
2924 // compute points
2925 TRectD bbox(boundary.m_bbox);
2926 std::vector<TPointD> r0, r1, r2;
2927 getRects(bbox, r0, r1, r2);
2928 assert(r0.size() == 4);
2929 assert(r1.size() == 4);
2930 assert(r2.size() == 4);
2931
2932 // draw
2933
2934 stenc->enableMask(TStencilControl::SHOW_INSIDE);
2935
2936 glBegin(GL_QUADS);
2937
2938 tglColor(color2);
2939 int i = 0;
2940 for (; i < 4; tglVertex(r0[i++]))
2941 ;
2942 tglVertex(r1[0]);
2943 tglVertex(r1[1]);
2944
2945 tglColor(color1);
2946 tglVertex(r1[2]);
2947 tglVertex(r1[3]);
2948 for (i = 0; i < 4; tglVertex(r2[i++]))
2949 ;
2950
2951 glEnd();
2952
2953 stenc->disableMask();
2954 }
2955
2956 //***************************************************************************
2957 // TRadGradFillStyle implementation
2958 //***************************************************************************
2959
TRadGradFillStyle(const TPixel32 & bgColor,const TPixel32 & pointColor,const double XPos,const double YPos,const double Radius,const double Smooth)2960 TRadGradFillStyle::TRadGradFillStyle(const TPixel32 &bgColor,
2961 const TPixel32 &pointColor,
2962 const double XPos, const double YPos,
2963 const double Radius, const double Smooth)
2964 : TSolidColorStyle(bgColor)
2965 , m_pointColor(pointColor)
2966 , m_XPos(XPos)
2967 , m_YPos(YPos)
2968 , m_Radius(Radius)
2969 , m_Smooth(Smooth) {}
2970
2971 //-----------------------------------------------------------------------------
2972
TRadGradFillStyle(const TPixel32 & color)2973 TRadGradFillStyle::TRadGradFillStyle(const TPixel32 &color)
2974 : TSolidColorStyle(TPixel32::White)
2975 , m_pointColor(color)
2976 , m_XPos(0.0)
2977 , m_YPos(0.0)
2978 , m_Radius(50.0)
2979 , m_Smooth(50) {}
2980
2981 //-----------------------------------------------------------------------------
2982
clone() const2983 TColorStyle *TRadGradFillStyle::clone() const {
2984 return new TRadGradFillStyle(*this);
2985 }
2986
2987 //------------------------------------------------------------
2988
getParamCount() const2989 int TRadGradFillStyle::getParamCount() const { return 4; }
2990
2991 //-----------------------------------------------------------------------------
2992
getParamType(int index) const2993 TColorStyle::ParamType TRadGradFillStyle::getParamType(int index) const {
2994 assert(0 <= index && index < getParamCount());
2995 return TColorStyle::DOUBLE;
2996 }
2997
2998 //-----------------------------------------------------------------------------
2999
getParamNames(int index) const3000 QString TRadGradFillStyle::getParamNames(int index) const {
3001 assert(0 <= index && index < 4);
3002
3003 QString value;
3004 switch (index) {
3005 case 0:
3006 value = QCoreApplication::translate("TRadGradFillStyle", "X Position");
3007 break;
3008 case 1:
3009 value = QCoreApplication::translate("TRadGradFillStyle", "Y Position");
3010 break;
3011 case 2:
3012 value = QCoreApplication::translate("TRadGradFillStyle", "Radius");
3013 break;
3014 case 3:
3015 value = QCoreApplication::translate("TRadGradFillStyle", "Smoothness");
3016 break;
3017 }
3018
3019 return value;
3020 }
3021
3022 //-----------------------------------------------------------------------------
3023
getParamRange(int index,double & min,double & max) const3024 void TRadGradFillStyle::getParamRange(int index, double &min,
3025 double &max) const {
3026 assert(0 <= index && index < 4);
3027 switch (index) {
3028 case 0:
3029 min = -100.0;
3030 max = 100.0;
3031 break;
3032 case 1:
3033 min = -100.0;
3034 max = 100.0;
3035 break;
3036 case 2:
3037 min = 0.01;
3038 max = 100.0;
3039 break;
3040 case 3:
3041 min = 0.01;
3042 max = 100.0;
3043 break;
3044 }
3045 }
3046
3047 //-----------------------------------------------------------------------------
3048
getParamValue(TColorStyle::double_tag,int index) const3049 double TRadGradFillStyle::getParamValue(TColorStyle::double_tag,
3050 int index) const {
3051 assert(0 <= index && index < 4);
3052
3053 switch (index) {
3054 case 0:
3055 return m_XPos;
3056 case 1:
3057 return m_YPos;
3058 case 2:
3059 return m_Radius;
3060 case 3:
3061 return m_Smooth;
3062 }
3063 return 0.0;
3064 }
3065
3066 //-----------------------------------------------------------------------------
3067
setParamValue(int index,double value)3068 void TRadGradFillStyle::setParamValue(int index, double value) {
3069 assert(0 <= index && index < 4);
3070
3071 switch (index) {
3072 case 0:
3073 m_XPos = value;
3074 break;
3075 case 1:
3076 m_YPos = value;
3077 break;
3078 case 2:
3079 m_Radius = value;
3080 break;
3081 case 3:
3082 m_Smooth = value;
3083 break;
3084 }
3085 }
3086
3087 //------------------------------------------------------------
3088
loadData(TInputStreamInterface & is)3089 void TRadGradFillStyle::loadData(TInputStreamInterface &is) {
3090 TSolidColorStyle::loadData(is);
3091 is >> m_XPos;
3092 is >> m_YPos;
3093 is >> m_Radius;
3094 is >> m_Smooth;
3095 is >> m_pointColor;
3096 }
3097
3098 //------------------------------------------------------------
3099
saveData(TOutputStreamInterface & os) const3100 void TRadGradFillStyle::saveData(TOutputStreamInterface &os) const {
3101 TSolidColorStyle::saveData(os);
3102 os << m_XPos;
3103 os << m_YPos;
3104 os << m_Radius;
3105 os << m_Smooth;
3106 os << m_pointColor;
3107 }
3108
3109 //------------------------------------------------------------
3110
getColorParamValue(int index) const3111 TPixel32 TRadGradFillStyle::getColorParamValue(int index) const {
3112 return index == 0 ? m_pointColor : TSolidColorStyle::getMainColor();
3113 }
3114
3115 //------------------------------------------------------------
3116
setColorParamValue(int index,const TPixel32 & color)3117 void TRadGradFillStyle::setColorParamValue(int index, const TPixel32 &color) {
3118 if (index == 0)
3119 m_pointColor = color;
3120 else {
3121 TSolidColorStyle::setMainColor(color);
3122 }
3123 }
3124
3125 //------------------------------------------------------------
3126
drawRegion(const TColorFunction * cf,const bool antiAliasing,TRegionOutline & boundary) const3127 void TRadGradFillStyle::drawRegion(const TColorFunction *cf,
3128 const bool antiAliasing,
3129 TRegionOutline &boundary) const {
3130 TStencilControl *stenc = TStencilControl::instance();
3131 // only to create stencil mask
3132 TSolidColorStyle appStyle(TPixel32::White);
3133 stenc->beginMask(); // does not draw on screen
3134 appStyle.drawRegion(0, false, boundary);
3135 stenc->endMask();
3136
3137 TPixel32 backgroundColor, color;
3138 if (cf) {
3139 backgroundColor = (*(cf))(TSolidColorStyle::getMainColor());
3140 color = (*(cf))(m_pointColor);
3141 } else {
3142 backgroundColor = TSolidColorStyle::getMainColor();
3143 color = m_pointColor;
3144 }
3145
3146 TRectD bbox(boundary.m_bbox);
3147 double lx = bbox.x1 - bbox.x0;
3148 double ly = bbox.y1 - bbox.y0;
3149 double r2 = std::max(lx, ly) * 5.0;
3150 double r1 = 0.5 * std::max(lx, ly) * m_Radius * 0.01;
3151 double r0 = r1 * (100.0 - m_Smooth) * 0.01;
3152
3153 TPointD center((bbox.x1 + bbox.x0) / 2.0, (bbox.y1 + bbox.y0) / 2.0);
3154 center = center + TPointD(m_XPos * 0.01 * lx * 0.5, m_YPos * 0.01 * ly * 0.5);
3155
3156 const double dAngle = 5.0;
3157 std::vector<TPointD> sincos;
3158 for (double angle = 0.0; angle <= 360.0; angle += dAngle)
3159 sincos.push_back(TPointD(sin(degree2rad(angle)), cos(degree2rad(angle))));
3160
3161 stenc->enableMask(TStencilControl::SHOW_INSIDE);
3162
3163 glBegin(GL_TRIANGLE_FAN);
3164 tglColor(color);
3165 tglVertex(center);
3166 int i = 0;
3167 for (; i < (int)sincos.size(); i++)
3168 tglVertex(center + TPointD(r0 * sincos[i].x, r0 * sincos[i].y));
3169 glEnd();
3170
3171 if (fabs(r0 - r1) > TConsts::epsilon) {
3172 glBegin(GL_QUAD_STRIP);
3173 for (i = 0; i < (int)sincos.size(); i++) {
3174 tglColor(color);
3175 tglVertex(center + TPointD(r0 * sincos[i].x, r0 * sincos[i].y));
3176 tglColor(backgroundColor);
3177 tglVertex(center + TPointD(r1 * sincos[i].x, r1 * sincos[i].y));
3178 }
3179 glEnd();
3180 }
3181
3182 tglColor(backgroundColor);
3183 glBegin(GL_QUAD_STRIP);
3184 for (i = 0; i < (int)sincos.size(); i++) {
3185 tglVertex(center + TPointD(r1 * sincos[i].x, r1 * sincos[i].y));
3186 tglVertex(center + TPointD(r2 * sincos[i].x, r2 * sincos[i].y));
3187 }
3188 glEnd();
3189
3190 stenc->disableMask();
3191 }
3192
3193 //***************************************************************************
3194 // TCircleStripeFillStyle implementation
3195 //***************************************************************************
3196
TCircleStripeFillStyle(const TPixel32 & bgColor,const TPixel32 & pointColor,const double XPos,const double YPos,const double Dist,const double Thickness)3197 TCircleStripeFillStyle::TCircleStripeFillStyle(
3198 const TPixel32 &bgColor, const TPixel32 &pointColor, const double XPos,
3199 const double YPos, const double Dist, const double Thickness)
3200 : TSolidColorStyle(bgColor)
3201 , m_pointColor(pointColor)
3202 , m_XPos(XPos)
3203 , m_YPos(YPos)
3204 , m_Dist(Dist)
3205 , m_Thickness(Thickness) {}
3206
3207 //------------------------------------------------------------
3208
TCircleStripeFillStyle(const TPixel32 & color)3209 TCircleStripeFillStyle::TCircleStripeFillStyle(const TPixel32 &color)
3210 : TSolidColorStyle(TPixel32::Transparent)
3211 , m_pointColor(color)
3212 , m_XPos(0.0)
3213 , m_YPos(0.0)
3214 , m_Dist(15.0)
3215 , m_Thickness(3.0) {}
3216
3217 //------------------------------------------------------------
3218
clone() const3219 TColorStyle *TCircleStripeFillStyle::clone() const {
3220 return new TCircleStripeFillStyle(*this);
3221 }
3222
3223 //------------------------------------------------------------
3224
getParamCount() const3225 int TCircleStripeFillStyle::getParamCount() const { return 4; }
3226
3227 //-----------------------------------------------------------------------------
3228
getParamType(int index) const3229 TColorStyle::ParamType TCircleStripeFillStyle::getParamType(int index) const {
3230 assert(0 <= index && index < getParamCount());
3231 return TColorStyle::DOUBLE;
3232 }
3233
3234 //-----------------------------------------------------------------------------
3235
getParamNames(int index) const3236 QString TCircleStripeFillStyle::getParamNames(int index) const {
3237 assert(0 <= index && index < 4);
3238
3239 QString value;
3240 switch (index) {
3241 case 0:
3242 value = QCoreApplication::translate("TCircleStripeFillStyle", "X Position");
3243 break;
3244 case 1:
3245 value = QCoreApplication::translate("TCircleStripeFillStyle", "Y Position");
3246 break;
3247 case 2:
3248 value = QCoreApplication::translate("TCircleStripeFillStyle", "Distance");
3249 break;
3250 case 3:
3251 value = QCoreApplication::translate("TCircleStripeFillStyle", "Thickness");
3252 break;
3253 }
3254
3255 return value;
3256 }
3257
3258 //-----------------------------------------------------------------------------
3259
getParamRange(int index,double & min,double & max) const3260 void TCircleStripeFillStyle::getParamRange(int index, double &min,
3261 double &max) const {
3262 assert(0 <= index && index < 4);
3263 switch (index) {
3264 case 0:
3265 min = -200.0;
3266 max = 200.0;
3267 break;
3268 case 1:
3269 min = -200.0;
3270 max = 200.0;
3271 break;
3272 case 2:
3273 min = 0.5;
3274 max = 100.0;
3275 break;
3276 case 3:
3277 min = 0.5;
3278 max = 100.0;
3279 break;
3280 }
3281 }
3282
3283 //-----------------------------------------------------------------------------
3284
getParamValue(TColorStyle::double_tag,int index) const3285 double TCircleStripeFillStyle::getParamValue(TColorStyle::double_tag,
3286 int index) const {
3287 assert(0 <= index && index < 4);
3288
3289 switch (index) {
3290 case 0:
3291 return m_XPos;
3292 case 1:
3293 return m_YPos;
3294 case 2:
3295 return m_Dist;
3296 case 3:
3297 return m_Thickness;
3298 }
3299 return 0.0;
3300 }
3301
3302 //-----------------------------------------------------------------------------
3303
setParamValue(int index,double value)3304 void TCircleStripeFillStyle::setParamValue(int index, double value) {
3305 assert(0 <= index && index < 4);
3306
3307 switch (index) {
3308 case 0:
3309 m_XPos = value;
3310 break;
3311 case 1:
3312 m_YPos = value;
3313 break;
3314 case 2:
3315 m_Dist = value;
3316 break;
3317 case 3:
3318 m_Thickness = value;
3319 break;
3320 }
3321 }
3322
3323 //------------------------------------------------------------
3324
loadData(TInputStreamInterface & is)3325 void TCircleStripeFillStyle::loadData(TInputStreamInterface &is) {
3326 TSolidColorStyle::loadData(is);
3327 is >> m_XPos;
3328 is >> m_YPos;
3329 is >> m_Dist;
3330 is >> m_Thickness;
3331 is >> m_pointColor;
3332 }
3333
3334 //------------------------------------------------------------
3335
saveData(TOutputStreamInterface & os) const3336 void TCircleStripeFillStyle::saveData(TOutputStreamInterface &os) const {
3337 TSolidColorStyle::saveData(os);
3338 os << m_XPos;
3339 os << m_YPos;
3340 os << m_Dist;
3341 os << m_Thickness;
3342 os << m_pointColor;
3343 }
3344
3345 //------------------------------------------------------------
3346
getColorParamValue(int index) const3347 TPixel32 TCircleStripeFillStyle::getColorParamValue(int index) const {
3348 return index == 0 ? m_pointColor : TSolidColorStyle::getMainColor();
3349 }
3350
3351 //------------------------------------------------------------
3352
setColorParamValue(int index,const TPixel32 & color)3353 void TCircleStripeFillStyle::setColorParamValue(int index,
3354 const TPixel32 &color) {
3355 if (index == 0)
3356 m_pointColor = color;
3357 else {
3358 TSolidColorStyle::setMainColor(color);
3359 }
3360 }
3361
3362 //------------------------------------------------------------
3363
getCircleStripeQuads(const TPointD & center,const double r1,const double r2,std::vector<TPointD> & pv) const3364 void TCircleStripeFillStyle::getCircleStripeQuads(
3365 const TPointD ¢er, const double r1, const double r2,
3366 std::vector<TPointD> &pv) const {
3367 pv.clear();
3368 const double dAng = 10.0;
3369 for (double ang = 0.0; ang <= 360; ang += dAng) {
3370 pv.push_back(center +
3371 TPointD(r1 * cos(degree2rad(ang)), r1 * sin(degree2rad(ang))));
3372 pv.push_back(center +
3373 TPointD(r2 * cos(degree2rad(ang)), r2 * sin(degree2rad(ang))));
3374 }
3375 }
3376
3377 //------------------------------------------------------------
3378
drawCircleStripe(const TPointD & center,const double r1,const double r2,const TPixel32 & col) const3379 void TCircleStripeFillStyle::drawCircleStripe(const TPointD ¢er,
3380 const double r1, const double r2,
3381 const TPixel32 &col) const {
3382 std::vector<TPointD> pv;
3383 getCircleStripeQuads(center, r1, r2, pv);
3384
3385 TStencilControl *stencil = TStencilControl::instance();
3386 stencil->beginMask(TStencilControl::DRAW_ALSO_ON_SCREEN);
3387
3388 glBegin(GL_QUAD_STRIP);
3389 tglColor(col);
3390 int i = 0;
3391 for (; i < (int)pv.size(); i++) tglVertex(pv[i]);
3392 glEnd();
3393
3394 stencil->endMask();
3395 stencil->enableMask(TStencilControl::SHOW_OUTSIDE);
3396
3397 // glHint(GL_LINE_SMOOTH_HINT, GL_NICEST);
3398 // glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
3399 // glEnable(GL_BLEND);
3400 // glEnable(GL_LINE_SMOOTH);
3401 tglEnableLineSmooth();
3402
3403 // Just for the antialiasing
3404 glBegin(GL_LINE_STRIP);
3405 tglColor(col);
3406 for (i = 0; i < (int)pv.size(); i += 2) tglVertex(pv[i]);
3407 glEnd();
3408
3409 glBegin(GL_LINE_STRIP);
3410 tglColor(col);
3411 for (i = 1; i < (int)pv.size(); i += 2) tglVertex(pv[i]);
3412 glEnd();
3413
3414 stencil->disableMask();
3415 }
3416
3417 //------------------------------------------------------------
3418
drawRegion(const TColorFunction * cf,const bool antiAliasing,TRegionOutline & boundary) const3419 void TCircleStripeFillStyle::drawRegion(const TColorFunction *cf,
3420 const bool antiAliasing,
3421 TRegionOutline &boundary) const {
3422 const bool isTransparent = m_pointColor.m < 255;
3423
3424 TStencilControl *stenc = TStencilControl::instance();
3425 TPixel32 backgroundColor = TSolidColorStyle::getMainColor();
3426 if (cf) backgroundColor = (*(cf))(m_pointColor);
3427
3428 TPixel32 foregroundColor;
3429 if (cf)
3430 foregroundColor = (*(cf))(m_pointColor);
3431 else
3432 foregroundColor = m_pointColor;
3433
3434 if (backgroundColor.m == 0) { // only to create stencil mask
3435 TSolidColorStyle appStyle(TPixel32::White);
3436 stenc->beginMask(); // does not draw on screen
3437 appStyle.drawRegion(0, false, boundary);
3438 } else { // create stencil mask and draw on screen
3439 stenc->beginMask(TStencilControl::DRAW_ALSO_ON_SCREEN);
3440 TSolidColorStyle::drawRegion(cf, antiAliasing, boundary);
3441 }
3442 stenc->endMask();
3443 stenc->enableMask(TStencilControl::SHOW_INSIDE);
3444
3445 if (isTransparent) {
3446 // glEnable(GL_BLEND);
3447 // glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
3448 //// <-- tglEnableBlending();
3449 }
3450
3451 TRectD bbox = boundary.m_bbox;
3452 double lx = bbox.x1 - bbox.x0;
3453 double ly = bbox.y1 - bbox.y0;
3454 TPointD center((bbox.x1 + bbox.x0) * 0.5, (bbox.y1 + bbox.y0) * 0.5);
3455 center.x = center.x + m_XPos * 0.01 * 0.5 * lx;
3456 center.y = center.y + m_YPos * 0.01 * 0.5 * ly;
3457
3458 double maxDist = 0.0;
3459 maxDist = std::max(tdistance(center, TPointD(bbox.x0, bbox.y0)), maxDist);
3460 maxDist = std::max(tdistance(center, TPointD(bbox.x0, bbox.y1)), maxDist);
3461 maxDist = std::max(tdistance(center, TPointD(bbox.x1, bbox.y0)), maxDist);
3462 maxDist = std::max(tdistance(center, TPointD(bbox.x1, bbox.y1)), maxDist);
3463
3464 double halfThick = m_Thickness * 0.5;
3465 for (double d = 0; d <= maxDist; d += m_Dist)
3466 drawCircleStripe(center, d - halfThick, d + halfThick, foregroundColor);
3467
3468 if (isTransparent) {
3469 // tglColor(TPixel32::White);
3470 // glDisable(GL_BLEND);
3471 }
3472
3473 stenc->disableMask();
3474 }
3475
3476 //***************************************************************************
3477 // TMosaicFillStyle implementation
3478 //***************************************************************************
3479
TMosaicFillStyle(const TPixel32 & bgColor,const TPixel32 pointColor[4],const double size,const double deform,const double minThickness,const double maxThickness)3480 TMosaicFillStyle::TMosaicFillStyle(const TPixel32 &bgColor,
3481 const TPixel32 pointColor[4],
3482 const double size, const double deform,
3483 const double minThickness,
3484 const double maxThickness)
3485 : TSolidColorStyle(bgColor)
3486 , m_size(size)
3487 , m_deform(deform)
3488 , m_minThickness(minThickness)
3489 , m_maxThickness(maxThickness) {
3490 for (int i = 0; i < 4; i++) m_pointColor[i] = pointColor[i];
3491 }
3492
3493 //------------------------------------------------------------
3494
TMosaicFillStyle(const TPixel32 bgColor)3495 TMosaicFillStyle::TMosaicFillStyle(const TPixel32 bgColor)
3496 : TSolidColorStyle(bgColor)
3497 , m_size(25.0)
3498 , m_deform(70.0)
3499 , m_minThickness(20)
3500 , m_maxThickness(40) {
3501 m_pointColor[0] = TPixel32::Blue;
3502 m_pointColor[1] = TPixel32::Green;
3503 m_pointColor[2] = TPixel32::Yellow;
3504 m_pointColor[3] = TPixel32::Cyan;
3505 }
3506
3507 //------------------------------------------------------------
3508
clone() const3509 TColorStyle *TMosaicFillStyle::clone() const {
3510 return new TMosaicFillStyle(*this);
3511 }
3512
3513 //------------------------------------------------------------
3514
getParamCount() const3515 int TMosaicFillStyle::getParamCount() const { return 4; }
3516
3517 //-----------------------------------------------------------------------------
3518
getParamType(int index) const3519 TColorStyle::ParamType TMosaicFillStyle::getParamType(int index) const {
3520 assert(0 <= index && index < getParamCount());
3521 return TColorStyle::DOUBLE;
3522 }
3523
3524 //-----------------------------------------------------------------------------
3525
getParamNames(int index) const3526 QString TMosaicFillStyle::getParamNames(int index) const {
3527 assert(0 <= index && index < 4);
3528 QString value;
3529 switch (index) {
3530 case 0:
3531 value = QCoreApplication::translate("TMosaicFillStyle", "Size");
3532 break;
3533 case 1:
3534 value = QCoreApplication::translate("TMosaicFillStyle", "Distortion");
3535 break;
3536 case 2:
3537 value = QCoreApplication::translate("TMosaicFillStyle", "Min Thick");
3538 break;
3539 case 3:
3540 value = QCoreApplication::translate("TMosaicFillStyle", "Max Thick");
3541 break;
3542 }
3543
3544 return value;
3545 }
3546
3547 //-----------------------------------------------------------------------------
3548
getParamRange(int index,double & min,double & max) const3549 void TMosaicFillStyle::getParamRange(int index, double &min,
3550 double &max) const {
3551 assert(0 <= index && index < 4);
3552 min = (index == 0) ? 2 : 0.001;
3553 max = 100.0;
3554 }
3555
3556 //-----------------------------------------------------------------------------
3557
getParamValue(TColorStyle::double_tag,int index) const3558 double TMosaicFillStyle::getParamValue(TColorStyle::double_tag,
3559 int index) const {
3560 assert(0 <= index && index < 4);
3561
3562 double value;
3563 switch (index) {
3564 case 0:
3565 value = m_size;
3566 break;
3567 case 1:
3568 value = m_deform;
3569 break;
3570 case 2:
3571 value = m_minThickness;
3572 break;
3573 case 3:
3574 value = m_maxThickness;
3575 break;
3576 }
3577 return value;
3578 }
3579
3580 //-----------------------------------------------------------------------------
3581
setParamValue(int index,double value)3582 void TMosaicFillStyle::setParamValue(int index, double value) {
3583 assert(0 <= index && index < 4);
3584
3585 switch (index) {
3586 case 0:
3587 m_size = value;
3588 break;
3589 case 1:
3590 m_deform = value;
3591 break;
3592 case 2:
3593 m_minThickness = value;
3594 break;
3595 case 3:
3596 m_maxThickness = value;
3597 break;
3598 }
3599 }
3600
3601 //------------------------------------------------------------
3602
loadData(TInputStreamInterface & is)3603 void TMosaicFillStyle::loadData(TInputStreamInterface &is) {
3604 TSolidColorStyle::loadData(is);
3605 is >> m_size;
3606 is >> m_deform;
3607 is >> m_minThickness;
3608 is >> m_maxThickness;
3609 is >> m_pointColor[0];
3610 is >> m_pointColor[1];
3611 is >> m_pointColor[2];
3612 is >> m_pointColor[3];
3613 }
3614
3615 //------------------------------------------------------------
3616
saveData(TOutputStreamInterface & os) const3617 void TMosaicFillStyle::saveData(TOutputStreamInterface &os) const {
3618 TSolidColorStyle::saveData(os);
3619 os << m_size;
3620 os << m_deform;
3621 os << m_minThickness;
3622 os << m_maxThickness;
3623 os << m_pointColor[0];
3624 os << m_pointColor[1];
3625 os << m_pointColor[2];
3626 os << m_pointColor[3];
3627 }
3628
3629 //------------------------------------------------------------
3630
getColorParamValue(int index) const3631 TPixel32 TMosaicFillStyle::getColorParamValue(int index) const {
3632 TPixel32 tmp;
3633 if (index == 0)
3634 tmp = TSolidColorStyle::getMainColor();
3635 else if (index >= 1 && index <= 4)
3636 tmp = m_pointColor[index - 1];
3637 else
3638 assert(!"bad color index");
3639
3640 return tmp;
3641 }
3642
3643 //------------------------------------------------------------
setColorParamValue(int index,const TPixel32 & color)3644 void TMosaicFillStyle::setColorParamValue(int index, const TPixel32 &color) {
3645 if (index == 0)
3646 TSolidColorStyle::setMainColor(color);
3647 else if (index >= 1 && index <= 4)
3648 m_pointColor[index - 1] = color;
3649 else
3650 assert(!"bad color index");
3651 }
3652
3653 //------------------------------------------------------------
3654
preaprePos(const TRectD & box,std::vector<TPointD> & v,int & lX,int & lY,TRandom & rand) const3655 void TMosaicFillStyle::preaprePos(const TRectD &box, std::vector<TPointD> &v,
3656 int &lX, int &lY, TRandom &rand) const {
3657 double dist = 5.0 + (60.0 - 5.0) * tcrop(m_size, 0.0, 100.0) * 0.01;
3658 lY = lX = 0;
3659 double ld = 0.4 * tcrop(m_deform, 0.0, 100.0) * 0.01;
3660 for (double y = box.y0 - dist; y <= (box.y1 + dist); y += dist, lY++) {
3661 lX = 0;
3662 for (double x = box.x0 - dist; x <= (box.x1 + dist); x += dist, lX++) {
3663 double dx = (rand.getInt(0, 2001) * 0.001 - 1.0) * ld * dist;
3664 double dy = (rand.getInt(0, 2001) * 0.001 - 1.0) * ld * dist;
3665 TPointD pos(x + dx, y + dy);
3666 v.push_back(pos);
3667 }
3668 }
3669 }
3670
3671 //------------------------------------------------------------
3672
getQuad(const int ix,const int iy,const int lX,const int lY,std::vector<TPointD> & v,TPointD * pquad,TRandom & rand) const3673 bool TMosaicFillStyle::getQuad(const int ix, const int iy, const int lX,
3674 const int lY, std::vector<TPointD> &v,
3675 TPointD *pquad, TRandom &rand) const {
3676 if (ix < 0 || iy < 0 || ix >= (lX - 1) || iy >= (lY - 1)) return false;
3677
3678 double dmin = tcrop(m_minThickness, 0.0, 100.0) * 0.01;
3679 double dmax = tcrop(m_maxThickness, 0.0, 100.0) * 0.01;
3680
3681 TPointD &p1 = v[iy * lX + ix];
3682 TPointD &p2 = v[iy * lX + ix + 1];
3683 TPointD &p3 = v[(iy + 1) * lX + ix + 1];
3684 TPointD &p4 = v[(iy + 1) * lX + ix];
3685
3686 double q1 = 0.5 * (dmin + (dmax - dmin) * rand.getInt(0, 101) * 0.01);
3687 double q2 = 0.5 * (dmin + (dmax - dmin) * rand.getInt(0, 101) * 0.01);
3688 double q3 = 0.5 * (dmin + (dmax - dmin) * rand.getInt(0, 101) * 0.01);
3689 double q4 = 0.5 * (dmin + (dmax - dmin) * rand.getInt(0, 101) * 0.01);
3690
3691 pquad[0] = (1.0 - q1) * p1 + q1 * p3;
3692 pquad[1] = (1.0 - q2) * p2 + q2 * p4;
3693 pquad[2] = (1.0 - q3) * p3 + q3 * p1;
3694 pquad[3] = (1.0 - q4) * p4 + q4 * p2;
3695
3696 return true;
3697 }
3698
3699 //------------------------------------------------------------
3700
drawRegion(const TColorFunction * cf,const bool antiAliasing,TRegionOutline & boundary) const3701 void TMosaicFillStyle::drawRegion(const TColorFunction *cf,
3702 const bool antiAliasing,
3703 TRegionOutline &boundary) const {
3704 TStencilControl *stenc = TStencilControl::instance();
3705 TPixel32 backgroundColor = TSolidColorStyle::getMainColor();
3706 if (cf) backgroundColor = (*(cf))(backgroundColor);
3707
3708 if (backgroundColor.m == 0) { // only to create stencil mask
3709 TSolidColorStyle appStyle(TPixel32::White);
3710 stenc->beginMask(); // does not draw on screen
3711 appStyle.drawRegion(0, false, boundary);
3712 } else { // create stencil mask and draw on screen
3713 stenc->beginMask(TStencilControl::DRAW_ALSO_ON_SCREEN);
3714 TSolidColorStyle::drawRegion(cf, antiAliasing, boundary);
3715 }
3716 stenc->endMask();
3717 stenc->enableMask(TStencilControl::SHOW_INSIDE);
3718
3719 // glEnable(GL_BLEND);
3720 // glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
3721 //// <-- tglEnableBlending();
3722
3723 TPixel32 color[4];
3724 for (int i = 0; i < 4; i++) {
3725 if (cf)
3726 color[i] = (*(cf))(m_pointColor[i]);
3727 else
3728 color[i] = m_pointColor[i];
3729 }
3730 TPixel32 currentColor;
3731
3732 std::vector<TPointD> pos;
3733 int posLX, posLY;
3734 TRandom rand;
3735 TPointD quad[4];
3736
3737 preaprePos(boundary.m_bbox, pos, posLX, posLY, rand);
3738
3739 glBegin(GL_QUADS);
3740
3741 /* ma serve ?
3742 tglColor(getMainColor());
3743 tglVertex(TPointD(boundary.m_bbox.x0,boundary.m_bbox.y0));
3744 tglVertex(TPointD(boundary.m_bbox.x0,boundary.m_bbox.y1));
3745 tglVertex(TPointD(boundary.m_bbox.x1,boundary.m_bbox.y1));
3746 tglVertex(TPointD(boundary.m_bbox.x1,boundary.m_bbox.y0));
3747 */
3748
3749 for (int y = 0; y < (posLY - 1); y++)
3750 for (int x = 0; x < (posLX - 1); x++)
3751 if (getQuad(x, y, posLX, posLY, pos, quad, rand)) {
3752 currentColor = color[rand.getInt(0, 4)];
3753 if (currentColor.m != 0) {
3754 tglColor(currentColor);
3755 tglVertex(quad[0]);
3756 tglVertex(quad[1]);
3757 tglVertex(quad[2]);
3758 tglVertex(quad[3]);
3759 }
3760 }
3761 glEnd();
3762
3763 // tglColor(TPixel32::White);
3764
3765 stenc->disableMask();
3766 }
3767
3768 //***************************************************************************
3769 // TPatchFillStyle implementation
3770 //***************************************************************************
3771
TPatchFillStyle(const TPixel32 & bgColor,const TPixel32 pointColor[6],const double size,const double deform,const double thickness)3772 TPatchFillStyle::TPatchFillStyle(const TPixel32 &bgColor,
3773 const TPixel32 pointColor[6],
3774 const double size, const double deform,
3775 const double thickness)
3776 : TSolidColorStyle(bgColor)
3777 , m_size(size)
3778 , m_deform(deform)
3779 , m_thickness(thickness) {
3780 for (int i = 0; i < 6; i++) m_pointColor[i] = pointColor[i];
3781 }
3782
3783 //-----------------------------------------------------------------------------
3784
TPatchFillStyle(const TPixel32 & bgColor)3785 TPatchFillStyle::TPatchFillStyle(const TPixel32 &bgColor)
3786 : TSolidColorStyle(bgColor), m_size(25.0), m_deform(50.0), m_thickness(30) {
3787 m_pointColor[0] = TPixel32::Red;
3788 m_pointColor[1] = TPixel32::Green;
3789 m_pointColor[2] = TPixel32::Yellow;
3790 m_pointColor[3] = TPixel32::Cyan;
3791 m_pointColor[4] = TPixel32::Magenta;
3792 m_pointColor[5] = TPixel32::White;
3793 }
3794
3795 //-----------------------------------------------------------------------------
3796
clone() const3797 TColorStyle *TPatchFillStyle::clone() const {
3798 return new TPatchFillStyle(*this);
3799 }
3800
3801 //------------------------------------------------------------
3802
getParamCount() const3803 int TPatchFillStyle::getParamCount() const { return 3; }
3804
3805 //-----------------------------------------------------------------------------
3806
getParamType(int index) const3807 TColorStyle::ParamType TPatchFillStyle::getParamType(int index) const {
3808 assert(0 <= index && index < getParamCount());
3809 return TColorStyle::DOUBLE;
3810 }
3811
3812 //-----------------------------------------------------------------------------
3813
getParamNames(int index) const3814 QString TPatchFillStyle::getParamNames(int index) const {
3815 assert(0 <= index && index < 3);
3816 QString value;
3817 switch (index) {
3818 case 0:
3819 value = QCoreApplication::translate("TPatchFillStyle", "Size");
3820 break;
3821 case 1:
3822 value = QCoreApplication::translate("TPatchFillStyle", "Distortion");
3823 break;
3824 case 2:
3825 value = QCoreApplication::translate("TPatchFillStyle", "Thickness");
3826 break;
3827 }
3828
3829 return value;
3830 }
3831
3832 //-----------------------------------------------------------------------------
3833
getParamRange(int index,double & min,double & max) const3834 void TPatchFillStyle::getParamRange(int index, double &min, double &max) const {
3835 assert(0 <= index && index < 3);
3836 min = (index == 0) ? 2 : 0.001;
3837 max = 100.0;
3838 }
3839
3840 //-----------------------------------------------------------------------------
3841
getParamValue(TColorStyle::double_tag,int index) const3842 double TPatchFillStyle::getParamValue(TColorStyle::double_tag,
3843 int index) const {
3844 assert(0 <= index && index < 3);
3845
3846 double value;
3847 switch (index) {
3848 case 0:
3849 value = m_size;
3850 break;
3851 case 1:
3852 value = m_deform;
3853 break;
3854 case 2:
3855 value = m_thickness;
3856 break;
3857 }
3858 return value;
3859 }
3860
3861 //-----------------------------------------------------------------------------
3862
setParamValue(int index,double value)3863 void TPatchFillStyle::setParamValue(int index, double value) {
3864 assert(0 <= index && index < 3);
3865
3866 switch (index) {
3867 case 0:
3868 m_size = value;
3869 break;
3870 case 1:
3871 m_deform = value;
3872 break;
3873 case 2:
3874 m_thickness = value;
3875 break;
3876 }
3877 }
3878
3879 //------------------------------------------------------------
3880
loadData(TInputStreamInterface & is)3881 void TPatchFillStyle::loadData(TInputStreamInterface &is) {
3882 TSolidColorStyle::loadData(is);
3883 is >> m_size;
3884 is >> m_deform;
3885 is >> m_thickness;
3886 for (int i = 0; i < 6; i++) is >> m_pointColor[i];
3887 }
3888
3889 //------------------------------------------------------------
3890
saveData(TOutputStreamInterface & os) const3891 void TPatchFillStyle::saveData(TOutputStreamInterface &os) const {
3892 TSolidColorStyle::saveData(os);
3893 os << m_size;
3894 os << m_deform;
3895 os << m_thickness;
3896 for (int i = 0; i < 6; i++) os << m_pointColor[i];
3897 }
3898
3899 //------------------------------------------------------------
getColorParamValue(int index) const3900 TPixel32 TPatchFillStyle::getColorParamValue(int index) const {
3901 TPixel32 tmp;
3902 if (index == 0)
3903 tmp = TSolidColorStyle::getMainColor();
3904 else if (index >= 1 && index <= 6)
3905 tmp = m_pointColor[index - 1];
3906 else
3907 assert(!"bad color index");
3908
3909 return tmp;
3910 }
3911
3912 //------------------------------------------------------------
setColorParamValue(int index,const TPixel32 & color)3913 void TPatchFillStyle::setColorParamValue(int index, const TPixel32 &color) {
3914 if (index == 0)
3915 TSolidColorStyle::setMainColor(color);
3916 else if (index >= 1 && index <= 6)
3917 m_pointColor[index - 1] = color;
3918 else
3919 assert(!"bad color index");
3920 }
3921
3922 //------------------------------------------------------------
3923
preaprePos(const TRectD & box,std::vector<TPointD> & v,int & lX,int & lY,TRandom & rand) const3924 void TPatchFillStyle::preaprePos(const TRectD &box, std::vector<TPointD> &v,
3925 int &lX, int &lY, TRandom &rand) const {
3926 double q = tcrop(m_size, 0.0, 100.0) * 0.01;
3927 double r = 5.0 + (60.0 - 5.0) * q;
3928 double m = r * sqrt(3.0) / 2.0;
3929 lY = 5 + (int)((box.y1 - box.y0) / (2 * m));
3930 int ix = 0;
3931 for (double x = box.x0 - r; x <= (box.x1 + r); ix++) {
3932 int nb = ix % 4;
3933 double y = (nb == 0 || nb == 1) ? box.y0 - 2 * m : box.y0 - m;
3934 for (int iy = 0; iy < lY; iy++, y += (2 * m)) v.push_back(TPointD(x, y));
3935 x = (nb == 0 || nb == 2) ? x + r : x + r / 2.0;
3936 }
3937 lX = ix;
3938
3939 double maxDeform = r * 0.6 * tcrop(m_deform, 0.0, 100.0) * 0.01;
3940 for (UINT i = 0; i < v.size(); i++) {
3941 v[i].x += (rand.getInt(0, 200) - 100) * 0.01 * maxDeform;
3942 v[i].y += (rand.getInt(0, 200) - 100) * 0.01 * maxDeform;
3943 }
3944 }
3945
3946 //------------------------------------------------------------
3947
getQuadLine(const TPointD & a,const TPointD & b,const double thickn,TPointD * quad) const3948 bool TPatchFillStyle::getQuadLine(const TPointD &a, const TPointD &b,
3949 const double thickn, TPointD *quad) const {
3950 if (tdistance(a, b) < TConsts::epsilon) return false;
3951
3952 TPointD ab(b - a);
3953 ab = normalize(ab);
3954 ab = rotate90(ab);
3955 ab = ab * thickn;
3956
3957 quad[0] = a + ab;
3958 quad[1] = a - ab;
3959 quad[2] = b - ab;
3960 quad[3] = b + ab;
3961
3962 return true;
3963 }
3964
3965 //------------------------------------------------------------
3966
drawGLQuad(const TPointD * quad) const3967 void TPatchFillStyle::drawGLQuad(const TPointD *quad) const {
3968 glBegin(GL_QUADS);
3969 tglVertex(quad[0]);
3970 tglVertex(quad[1]);
3971 tglVertex(quad[2]);
3972 tglVertex(quad[3]);
3973 glEnd();
3974 double r = tdistance(quad[0], quad[1]) / 2.0;
3975 tglDrawDisk(quad[0] * 0.5 + quad[1] * 0.5, r);
3976 tglDrawDisk(quad[2] * 0.5 + quad[3] * 0.5, r);
3977 }
3978
3979 //------------------------------------------------------------
3980
drawRegion(const TColorFunction * cf,const bool antiAliasing,TRegionOutline & boundary) const3981 void TPatchFillStyle::drawRegion(const TColorFunction *cf,
3982 const bool antiAliasing,
3983 TRegionOutline &boundary) const {
3984 TStencilControl *stenc = TStencilControl::instance();
3985 TPixel32 backgroundColor = TSolidColorStyle::getMainColor();
3986 if (cf) backgroundColor = (*(cf))(backgroundColor);
3987
3988 if (backgroundColor.m == 0) { // only to create stencil mask
3989 TSolidColorStyle appStyle(TPixel32::White);
3990 stenc->beginMask(); // does not draw on screen
3991 appStyle.drawRegion(0, false, boundary);
3992 } else { // create stencil mask and draw on screen
3993 stenc->beginMask(TStencilControl::DRAW_ALSO_ON_SCREEN);
3994 TSolidColorStyle::drawRegion(cf, antiAliasing, boundary);
3995 }
3996 stenc->endMask();
3997 stenc->enableMask(TStencilControl::SHOW_INSIDE);
3998
3999 // glEnable(GL_BLEND);
4000 // glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
4001 //// <-- tglEnableBlending();
4002
4003 TPixel32 color[6];
4004 for (int i = 0; i < 6; i++)
4005 if (cf)
4006 color[i] = (*(cf))(m_pointColor[i]);
4007 else
4008 color[i] = m_pointColor[i];
4009
4010 TPixel32 currentColor;
4011
4012 std::vector<TPointD> pos;
4013 int posLX, posLY;
4014 TRandom rand;
4015 TPointD quad[4];
4016
4017 preaprePos(boundary.m_bbox, pos, posLX, posLY, rand);
4018 glBegin(GL_TRIANGLES);
4019 int x = 2;
4020 for (; x < (posLX - 2); x += 2)
4021 for (int y = 1; y < posLY; y++) {
4022 TPointD q[6];
4023 if ((x % 4) == 2) {
4024 q[0] = pos[(x - 1) * posLY + y];
4025 q[1] = pos[(x)*posLY + y];
4026 q[2] = pos[(x + 1) * posLY + y];
4027 q[3] = pos[(x + 2) * posLY + y];
4028 q[4] = pos[(x + 1) * posLY + y - 1];
4029 q[5] = pos[(x)*posLY + y - 1];
4030 } else {
4031 q[0] = pos[(x - 1) * posLY + y - 1];
4032 q[1] = pos[(x)*posLY + y - 1];
4033 q[2] = pos[(x + 1) * posLY + y - 1];
4034 q[3] = pos[(x + 2) * posLY + y - 1];
4035 q[4] = pos[(x + 1) * posLY + y];
4036 q[5] = pos[(x)*posLY + y];
4037 }
4038
4039 currentColor = color[rand.getInt(0, 6)];
4040 if (currentColor.m != 0) {
4041 tglColor(currentColor);
4042
4043 tglVertex(q[0]);
4044 tglVertex(q[1]);
4045 tglVertex(q[2]);
4046
4047 tglVertex(q[2]);
4048 tglVertex(q[3]);
4049 tglVertex(q[4]);
4050
4051 tglVertex(q[4]);
4052 tglVertex(q[5]);
4053 tglVertex(q[0]);
4054
4055 tglVertex(q[0]);
4056 tglVertex(q[2]);
4057 tglVertex(q[4]);
4058 }
4059 }
4060 glEnd();
4061
4062 double thickn = tcrop(m_thickness, 0.0, 100.0) * 0.01 * 5.0;
4063 if (thickn > 0.001) tglColor(backgroundColor);
4064 for (x = 0; x < (posLX - 1); x++) {
4065 int nb = x % 4;
4066 for (int y = 0; y < posLY; y++) {
4067 if (getQuadLine(pos[x * posLY + y], pos[(x + 1) * posLY + y], thickn,
4068 quad))
4069 drawGLQuad(quad);
4070 if (y > 0 && nb == 1)
4071 if (getQuadLine(pos[x * posLY + y], pos[(x + 1) * posLY + y - 1],
4072 thickn, quad))
4073 drawGLQuad(quad);
4074 if (y < (posLY - 1) && nb == 3)
4075 if (getQuadLine(pos[x * posLY + y], pos[(x + 1) * posLY + y + 1],
4076 thickn, quad))
4077 drawGLQuad(quad);
4078 }
4079 }
4080
4081 // tglColor(TPixel32::White);
4082
4083 stenc->disableMask();
4084 }
4085
4086 //------------------------------------------------------------
4087
nbClip(const int lX,const int lY,const std::vector<TPointD> & v) const4088 int TPatchFillStyle::nbClip(const int lX, const int lY,
4089 const std::vector<TPointD> &v) const {
4090 TPointD quad[4];
4091 double thickn = tcrop(m_thickness, 0.0, 100.0) * 0.01 * 5.0;
4092 int nbC = 0;
4093 int x = 2;
4094 for (; x < (lX - 2); x += 2)
4095 for (int y = 1; y < lY; y++) nbC += 1;
4096 if (thickn > 0.001)
4097 for (x = 0; x < (lX - 1); x++) {
4098 int nb = x % 4;
4099 for (int y = 0; y < lY; y++) {
4100 if (getQuadLine(v[x * lY + y], v[(x + 1) * lY + y], thickn, quad))
4101 nbC += 3;
4102 if (y > 0 && nb == 1)
4103 if (getQuadLine(v[x * lY + y], v[(x + 1) * lY + y - 1], thickn, quad))
4104 nbC += 3;
4105 if (y < (lY - 1) && nb == 3)
4106 if (getQuadLine(v[x * lY + y], v[(x + 1) * lY + y + 1], thickn, quad))
4107 nbC += 3;
4108 }
4109 }
4110 return nbC;
4111 }
4112