OOFEM  2.4
OOFEM.org - Object Oriented Finite Element Solver
oofegutils.C
Go to the documentation of this file.
1 #ifdef __OOFEG
2 
3 
4 #include "oofeggraphiccontext.h"
5 #include "mathfem.h"
6 #include "oofegutils.h"
7 
8 namespace oofem {
9 void
10 oofeg_drawIsoLinesOnTriangle(WCRec coords [ 3 ], double s [ 3 ]) {
11  /* Draws the iso-lines on triangle given by its coordinates (coords argument).
12  * The values at vertices are stored in s argument.
13  * the layer and width are changed, so they should be set before.
14  */
15  // isoline implementation
16  double zcoord, zmin, zmax, minv, maxv;
17  int indx, inode, jnode, iside, zlevel;
18  int isc_color_scale_num_labels = COLOR_SCALE_NUM_LABELS;
19  FPNum delta;
20  EFringeTable ft;
21  EPixel color;
22  WCRec p [ 2 ];
23  GraphicObj *tr;
24 
25  minv = min( s [ 0 ], min(s [ 1 ], s [ 2 ]) );
26  maxv = max( s [ 0 ], max(s [ 1 ], s [ 2 ]) );
27 
28  ft = EMGetAssocFringeTable( ESIModel() );
29  ColorFringesMinMax(ft, & minv, & maxv);
30  delta = ( maxv - minv ) / isc_color_scale_num_labels;
31  zcoord = minv + delta / 2;
32 
33  for ( zlevel = 1; zlevel <= isc_color_scale_num_labels; zlevel++ ) {
34  indx = 0;
35  if ( ( zcoord <= minv ) || ( zcoord >= maxv ) ) {
36  return;
37  }
38 
39  for ( iside = 1; iside <= 3; iside++ ) {
40  inode = iside;
41  jnode = ( iside == 3 ? 1 : iside + 1 );
42  zmin = min(s [ inode - 1 ], s [ jnode - 1 ]);
43  zmax = max(s [ inode - 1 ], s [ jnode - 1 ]);
44  if ( ( zmax > zcoord ) && ( zmin < zcoord ) ) {
45  // find intersection
46  double ix, iy, iz, jx, jy, jz;
47  double t, edgeLength;
48 
49  ix = coords [ inode - 1 ].x;
50  iy = coords [ inode - 1 ].y;
51  iz = 0.;
52  jx = coords [ jnode - 1 ].x;
53  jy = coords [ jnode - 1 ].y;
54  jz = 0.;
55 
56  edgeLength = sqrt( ( ix - jx ) * ( ix - jx ) + ( iy - jy ) * ( iy - jy ) );
57  t = ( zcoord - s [ inode - 1 ] ) * edgeLength / ( s [ jnode - 1 ] - s [ inode - 1 ] );
58  t /= edgeLength;
59 
60  p [ indx ].x = ( FPNum ) ix + t * ( jx - ix );
61  p [ indx ].y = ( FPNum ) iy + t * ( jy - iy );
62  p [ indx ].z = 0.;
63  indx++;
64  if ( indx == 2 ) {
65  color = ColorFringeRangeToColor( ColorFringeValueToRange(ft, zcoord) );
66  EASValsSetColor(color);
67 
68  tr = CreateLine3D(p);
69  EGWithMaskChangeAttributes(LAYER_MASK | WIDTH_MASK | COLOR_MASK, tr);
70  EMAddGraphicsToModel(ESIModel(), tr);
71 
72  break;
73  }
74  }
75  }
76 
77  zcoord += delta;
78  }
79 }
80 
81 void
82 oofeg_drawIsoLinesOnQuad(WCRec coords [ 4 ], double s [ 4 ]) {
83  /* Draws the iso-lines on quad given by its coordinates (coords argument).
84  * The values at vertices are stored in s argument.
85  * the layer and width are changed, so they should be set before.
86  */
87  // isoline implementation
88  double zcoord, zmin, zmax, minv, maxv;
89  int i, indx, inode, jnode, iside, zlevel;
90  int isc_color_scale_num_labels = COLOR_SCALE_NUM_LABELS;
91  FPNum delta;
92  EFringeTable ft;
93  EPixel color;
94  WCRec p [ 4 ];
95  GraphicObj *tr;
96 
97  minv = maxv = s [ 0 ];
98  for ( i = 1; i < 4; i++ ) {
99  minv = min(minv, s [ i ]);
100  maxv = max(maxv, s [ i ]);
101  }
102 
103  ft = EMGetAssocFringeTable( ESIModel() );
104  ColorFringesMinMax(ft, & minv, & maxv);
105  delta = ( maxv - minv ) / isc_color_scale_num_labels;
106  zcoord = minv + delta / 2;
107 
108  for ( zlevel = 1; zlevel <= isc_color_scale_num_labels; zlevel++ ) {
109  indx = 0;
110  if ( ( zcoord <= minv ) || ( zcoord >= maxv ) ) {
111  return;
112  }
113 
114  for ( iside = 1; iside <= 4; iside++ ) {
115  inode = iside;
116  jnode = ( iside == 4 ? 1 : iside + 1 );
117  zmin = min(s [ inode - 1 ], s [ jnode - 1 ]);
118  zmax = max(s [ inode - 1 ], s [ jnode - 1 ]);
119  if ( ( zmax > zcoord ) && ( zmin < zcoord ) ) {
120  // find intersection
121  double ix, iy, iz, jx, jy, jz;
122  double t, edgeLength;
123 
124  ix = ( FPNum ) coords [ inode - 1 ].x;
125  iy = ( FPNum ) coords [ inode - 1 ].y;
126  iz = 0.;
127  jx = ( FPNum ) coords [ jnode - 1 ].x;
128  jy = ( FPNum ) coords [ jnode - 1 ].y;
129  jz = 0.;
130 
131 
132  edgeLength = sqrt( ( ix - jx ) * ( ix - jx ) + ( iy - jy ) * ( iy - jy ) );
133  t = ( zcoord - s [ inode - 1 ] ) * edgeLength / ( s [ jnode - 1 ] - s [ inode - 1 ] );
134  t /= edgeLength;
135 
136  p [ indx ].x = ( FPNum ) ix + t * ( jx - ix );
137  p [ indx ].y = ( FPNum ) iy + t * ( jy - iy );
138  p [ indx ].z = 0.;
139  indx++;
140  if ( indx == 4 ) {
141  break;
142  }
143  }
144  }
145 
146  color = ColorFringeRangeToColor( ColorFringeValueToRange(ft, zcoord) );
147  EASValsSetColor(color);
148 
149  if ( indx == 2 ) { // only two edges intersecting
150  tr = CreateLine3D(p);
151  EGWithMaskChangeAttributes(LAYER_MASK | WIDTH_MASK | COLOR_MASK, tr);
152  EMAddGraphicsToModel(ESIModel(), tr);
153  } else if ( indx == 4 ) {
154  // four edges intersecting
155  if ( s [ 0 ] > zcoord ) { // s[2] > zcoord
156  WCRec pp [ 2 ];
157  pp [ 0 ].x = p [ 0 ].x;
158  pp [ 0 ].y = p [ 0 ].y;
159  pp [ 0 ].z = p [ 0 ].z;
160  pp [ 1 ].x = p [ 3 ].x;
161  pp [ 1 ].y = p [ 3 ].y;
162  pp [ 1 ].z = p [ 3 ].z;
163  tr = CreateLine3D(pp);
164  EGWithMaskChangeAttributes(LAYER_MASK | WIDTH_MASK | COLOR_MASK, tr);
165  EMAddGraphicsToModel(ESIModel(), tr);
166 
167  pp [ 0 ].x = p [ 1 ].x;
168  pp [ 0 ].y = p [ 1 ].y;
169  pp [ 0 ].z = p [ 1 ].z;
170  pp [ 1 ].x = p [ 2 ].x;
171  pp [ 1 ].y = p [ 2 ].y;
172  pp [ 1 ].z = p [ 2 ].z;
173  tr = CreateLine3D(pp);
174  EGWithMaskChangeAttributes(LAYER_MASK | WIDTH_MASK | COLOR_MASK, tr);
175  EMAddGraphicsToModel(ESIModel(), tr);
176  } else {
177  WCRec pp [ 2 ];
178  pp [ 0 ].x = p [ 0 ].x;
179  pp [ 0 ].y = p [ 0 ].y;
180  pp [ 0 ].z = p [ 0 ].z;
181  pp [ 1 ].x = p [ 1 ].x;
182  pp [ 1 ].y = p [ 1 ].y;
183  pp [ 1 ].z = p [ 1 ].z;
184  tr = CreateLine3D(pp);
185  EGWithMaskChangeAttributes(LAYER_MASK | WIDTH_MASK | COLOR_MASK, tr);
186  EMAddGraphicsToModel(ESIModel(), tr);
187 
188  pp [ 0 ].x = p [ 3 ].x;
189  pp [ 0 ].y = p [ 3 ].y;
190  pp [ 0 ].z = p [ 3 ].z;
191  pp [ 1 ].x = p [ 2 ].x;
192  pp [ 1 ].y = p [ 2 ].y;
193  pp [ 1 ].z = p [ 2 ].z;
194  tr = CreateLine3D(pp);
195  EGWithMaskChangeAttributes(LAYER_MASK | WIDTH_MASK | COLOR_MASK, tr);
196  EMAddGraphicsToModel(ESIModel(), tr);
197  }
198  }
199 
200  zcoord += delta;
201  }
202 }
203 } // end namespace oofem
204 #endif
int max(int i, int j)
Returns bigger value form two given decimals.
Definition: mathfem.h:71
void oofeg_drawIsoLinesOnQuad(WCRec coords[4], double s[4])
Definition: oofegutils.C:82
void oofeg_drawIsoLinesOnTriangle(WCRec coords[3], double s[3])
Definition: oofegutils.C:10
int min(int i, int j)
Returns smaller value from two given decimals.
Definition: mathfem.h:59
the oofem namespace is to define a context or scope in which all oofem names are defined.

This page is part of the OOFEM documentation. Copyright (c) 2011 Borek Patzak
Project e-mail: info@oofem.org
Generated at Tue Jan 2 2018 20:07:30 for OOFEM by doxygen 1.8.11 written by Dimitri van Heesch, © 1997-2011