15 #include "GmshConfig.h"
77 for(std::size_t i = 0; i <
PView::list.size(); i++) {
83 std::vector<bool> visible(_size);
86 std::list<TriangleToSort *> tlist;
88 for(std::size_t ivp = 0; ivp <
PView::list.size(); ivp++) {
97 visible[_count] =
true;
100 _current->
xmin = min(p0[0], min(p1[0], p2[0]));
101 _current->
ymin = min(p0[1], min(p1[1], p2[1]));
102 _current->
zmin = min(p0[2], min(p1[2], p2[2]));
103 _current->
xmax = max(p0[0], max(p1[0], p2[0]));
104 _current->
ymax = max(p0[1], max(p1[1], p2[1]));
105 _current->
zmax = max(p0[2], max(p1[2], p2[2]));
107 tlist.push_back(_current);
119 std::list<TriangleToSort *>::iterator pt, nt;
120 for(pt = tlist.begin(); pt != tlist.end(); pt++) {
125 int ip = (*pt)->_index;
129 int gip = (*pt)->_globalIndex;
130 while(nt != tlist.end() && !found) {
131 int gin = (*nt)->_globalIndex;
132 if((((abs((*pt)->xmin - (*nt)->xmin) < 1.e-9) &&
133 (abs((*pt)->ymin - (*nt)->ymin) < 1.e-9)) &&
134 (abs((*pt)->zmin - (*nt)->zmin) < 1.e-9)) &&
135 (((abs((*pt)->xmax - (*nt)->xmax) < 1.e-9) &&
136 (abs((*pt)->ymax - (*nt)->ymax) < 1.e-9)) &&
137 (abs((*pt)->zmax - (*nt)->zmax) < 1.e-9))) {
139 int in = (*nt)->_index;
197 visible[gip] =
false;
198 visible[gin] =
false;
199 if(pt != tlist.end()) pt++;
210 for(pt = tlist.begin(); pt != tlist.end(); pt++) {
220 timeinfo = localtime(&rawtime);
221 FILE *fp =
Fopen(fileName.c_str(),
"w");
223 Msg::Error(
"Unable to open file '%s'", fileName.c_str());
228 fprintf(fp,
"<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n");
229 fprintf(fp,
"<!DOCTYPE X3D PUBLIC \"ISO//Web3D//DTD X3D 3.3//EN\" "
230 "\"http://www.web3d.org/specifications/x3d-3.3.dtd\">\n");
231 fprintf(fp,
"<X3D profile='Interchange' version='3.3' "
232 "xmlns:xsd='http://www.w3.org/2001/XMLSchema-instance' >\n");
233 fprintf(fp,
" <head>\n");
234 fprintf(fp,
" <meta name='title' content='PView'/> \n");
235 fprintf(fp,
" <meta name='description' content='%s'/>\n",
237 fprintf(fp,
" <meta name='creator' content='gmsh'/> \n");
238 fprintf(fp,
" <meta name='created' content=' %s '/>\n",
240 fprintf(fp,
" </head>\n");
244 PViewData *data = (*pvit)->getData(
true);
251 double _diagonal = bb.
diag();
252 fprintf(fp,
" <Scene>\n");
254 " <Viewpoint description='Book View' orientation='0 0. 1. 0.' "
255 "position='%g %g %g'/> \n",
256 _center.
x(), _center.
y(), _center.
z() + _diagonal * 1.2);
257 fprintf(fp,
" <Background skyColor='.7 .7 1'/> \n");
262 double viewportWidth = .9;
263 double viewportHeight = .56;
264 double font_size = 0.02;
266 std::vector<PView *> scales;
267 for(std::size_t i = 0; i <
PView::list.size(); i++) {
275 if(!scales.empty()) {
276 fprintf(fp,
" <ProtoDeclare appinfo='Heads-up display (HUD)' "
277 "name='HeadsUpDisplay'> \n");
278 fprintf(fp,
" <ProtoInterface> \n");
280 " <field accessType='inputOutput' appinfo='offset "
282 "name='screenOffset' type='SFVec3f' value='%g %g %g'/> \n",
283 _center.
x(), _center.
y(), 5 * _center.
z() + _diagonal * 1.2);
284 fprintf(fp,
" <field accessType='inputOutput' appinfo='X3D "
285 "content positioned at HUD offset' "
286 "name='children' type='MFNode'> \n");
287 fprintf(fp,
" </field> \n");
288 fprintf(fp,
" <field accessType='outputOnly' appinfo='HUD "
289 "position update (in world "
290 "coordinates) relative to original location' "
291 "name='position_changed' type='SFVec3f'/> \n");
294 " <field accessType='outputOnly' appinfo='HUD orientation "
295 "update relative to "
296 "original location' name='orientation_changed' type='SFRotation'/> \n");
297 fprintf(fp,
" </ProtoInterface> \n");
298 fprintf(fp,
" <ProtoBody> \n");
299 fprintf(fp,
" <Group bboxCenter=\"%g %g %g\"> \n", _center.
x(),
300 _center.
y(), _center.
z());
301 fprintf(fp,
" <Transform DEF='HudContainer'> \n");
302 fprintf(fp,
" <Transform> \n");
303 fprintf(fp,
" <IS> \n");
304 fprintf(fp,
" <connect nodeField='translation' "
305 "protoField='screenOffset'/> \n");
306 fprintf(fp,
" </IS> \n");
307 fprintf(fp,
" <Group> \n");
308 fprintf(fp,
" <IS> \n");
309 fprintf(fp,
" <connect nodeField='children' "
310 "protoField='children'/> \n");
311 fprintf(fp,
" </IS> \n");
312 fprintf(fp,
" </Group> \n");
313 fprintf(fp,
" </Transform> \n");
314 fprintf(fp,
" </Transform> \n");
315 fprintf(fp,
" <ProximitySensor DEF='HereIAm' size='10000000 "
316 "10000000 10000000'> \n");
317 fprintf(fp,
" <IS> \n");
318 fprintf(fp,
" <connect nodeField='position_changed' "
319 "protoField='position_changed'/> \n");
320 fprintf(fp,
" <connect nodeField='orientation_changed' "
321 "protoField='orientation_changed'/> \n");
322 fprintf(fp,
" </IS> \n");
323 fprintf(fp,
" </ProximitySensor> \n");
324 fprintf(fp,
" <ROUTE fromField='orientation_changed' "
325 "fromNode='HereIAm' toField='rotation' "
326 "toNode='HudContainer'/> \n");
327 fprintf(fp,
" <ROUTE fromField='position_changed' "
328 "fromNode='HereIAm' toField='translation' "
329 "toNode='HudContainer'/> \n");
330 fprintf(fp,
" </Group> \n");
331 fprintf(fp,
" </ProtoBody> \n");
332 fprintf(fp,
" </ProtoDeclare> \n");
335 " <Viewpoint description='Book View' orientation='0 0. 1. 0.' "
336 "position='%g %g %g'/> \n",
337 _center.
x(), _center.
y(), _center.
z() + _diagonal * 1.2);
338 fprintf(fp,
" <!-- ProtoDeclare is the \"cookie cutter\" template, "
339 "ProtoInstance creates an actual "
340 "occurrence --> \n");
343 " <ProtoInstance DEF='HeadsUpDisplay' name='HeadsUpDisplay'> \n");
344 fprintf(fp,
" <!-- example: upper left-hand corner of screen (x=-2, "
345 "y=1) and set back z=-5 from "
347 fprintf(fp,
" <fieldValue name='screenOffset' value='%g %g %g'/> \n",
348 _center.
x(), _center.
y(), _center.
z() - .2 * _diagonal);
349 fprintf(fp,
" <fieldValue name='children'> \n");
352 double maxw = 10. * font_size * 3. / 4.;
353 const double tic = viewportWidth / 100;
354 const double bar_size = tic * 1.6;
355 double width = 0., width_prev = 0., width_total = 0.;
357 for(std::size_t i = 0; i < scales.size(); i++) {
358 PView *p = scales[i];
363 double w = viewportWidth / 3;
364 double h = viewportHeight / 11;
366 double y = -viewportHeight;
371 double ysep = viewportHeight / 40;
373 if(scales.size() == 1) {
374 double w = viewportWidth / 2., h = bar_size;
375 double x = xc - w / 2., y = -viewportHeight / 2 + ysep;
379 double xsep = maxw / 4. + viewportWidth / 10.;
380 double w = (viewportWidth - 4. * xsep) / 2.;
381 if(w < 30. * viewportWidth / 1000) w = 30. * viewportWidth / 1000;
383 double x = xc - (i % 2 ? -xsep / 1.5 : w + xsep / 1.5);
384 double y = -viewportHeight / 2 + ysep +
385 (i / 2) * (bar_size + tic + 2 * font_size + ysep);
390 double xsep = viewportWidth / 50;
391 double dy = 2. * font_size;
392 if(scales.size() == 1) {
393 double ysep = (viewportHeight) / 6.;
394 double w = bar_size, h = viewportHeight - 2 * ysep - dy;
395 double x = -viewportWidth / 2 + xsep,
396 y = -viewportHeight / 2 + ysep + dy;
400 double ysep = viewportHeight / 30.;
402 double h = (viewportHeight - 3 * ysep - 2.5 * dy) / 2.;
403 double x = -viewportWidth / 2 + xsep + width_total + (i / 2) * xsep;
404 double y = -viewportHeight / 2 + ysep + dy +
405 (1 - i % 2) * (h + 1.5 * dy + ysep);
410 width = bar_size + tic + 10. * font_size * 3 / 4;
414 sprintf(label,
"%s (%s)", data->
getName().c_str(), tmp);
417 sprintf(label,
"%s", data->
getName().c_str());
419 width = max(width, strlen(label) * font_size * 3 / 4);
421 width_total += std::max(bar_size + width, bar_size + width_prev);
424 fprintf(fp,
" </fieldValue> \n");
425 fprintf(fp,
" </ProtoInstance> \n");
464 fprintf(fp,
" <Shape> \n");
465 fprintf(fp,
" <IndexedLineSet coordIndex=' ");
466 for(std::size_t ipv = 0; ipv <
PView::list.size(); ipv++) {
473 fprintf(fp,
"%i %i %i ", _ind, _ind + 1, -1);
480 fprintf(fp,
" <Coordinate DEF='TurnPoints' point=' ");
481 for(std::size_t ipv = 0; ipv <
PView::list.size(); ipv++) {
490 fprintf(fp,
"%g %g %g %g %g %g ", p0[0], p0[1], p0[2], p1[0], p1[1],
496 fprintf(fp,
"'/> \n");
497 fprintf(fp,
" </IndexedLineSet> \n");
498 fprintf(fp,
" <Appearance> \n");
499 fprintf(fp,
" <Material emissiveColor='0 0 0'/>\n");
500 fprintf(fp,
" <LineProperties containerField='lineProperties'> \n");
501 fprintf(fp,
" </LineProperties> \n");
502 fprintf(fp,
" </Appearance> \n");
503 fprintf(fp,
" </Shape>\n");
506 for(std::size_t ipv = 0; ipv <
PView::list.size(); ipv++) {
517 double l = sqrt(v[0] * v[0] + v[1] * v[1] + v[2] * v[2]);
518 double lmax = opt->
tmpMax;
520 double scale = .5 / _diagonal;
521 double theta = acos(v[1] / l);
524 " <Transform rotation='%g %g %g %g' translation='%e %e %e' >\n",
525 v[2], 0., -v[0], theta, s[0] + .5 *
scale * v[0],
526 s[1] + .5 *
scale * v[1], s[2] + .5 *
scale * v[2]);
527 fprintf(fp,
" <Shape>\n");
528 fprintf(fp,
" <Cone bottomRadius='%g' height='%g'/>\n",
530 fprintf(fp,
" <Appearance>\n");
531 fprintf(fp,
" <Material diffuseColor='%g %g %g'/>\n",
532 rgba[0], rgba[1], rgba[2]);
533 fprintf(fp,
" </Appearance>\n");
534 fprintf(fp,
" </Shape>\n");
535 fprintf(fp,
" </Transform>\n");
545 fprintf(fp,
" <Transform> \n");
546 fprintf(fp,
" <Shape> \n");
547 fprintf(fp,
" <Appearance> \n");
548 fprintf(fp,
" <Material transparency='%g' ",
550 fprintf(fp,
" ambientIntensity='0.15' diffuseColor='.5 .5 .5' "
551 "emissiveColor='0 0 0' ");
552 fprintf(fp,
" shininess='0.1' specularColor='.1 .1 .1' /> \n");
553 fprintf(fp,
" </Appearance> \n");
554 fprintf(fp,
" <IndexedTriangleSet solid='true' ccw='true' "
555 "colorPerVertex='true' \n ");
557 fp,
" normalPerVertex='true' containerField='geometry' index=' ");
558 for(std::size_t ipv = 0; ipv <
PView::list.size(); ipv++) {
566 fprintf(fp,
"%i %i %i ", _ind, _ind + 1, _ind + 2);
574 fprintf(fp,
" ' > \n");
575 fprintf(fp,
" <Coordinate point='");
577 for(std::size_t ipv = 0; ipv <
PView::list.size(); ipv++) {
589 fprintf(fp,
"%e %e %e %e %e %e %e %e %e ", p0[0], p0[1], p0[2], p1[0],
590 p1[1], p1[2], p2[0], p2[1], p2[2]);
596 fprintf(fp,
" '/> \n");
598 fprintf(fp,
" <Color color='");
600 for(std::size_t ipv = 0; ipv <
PView::list.size(); ipv++) {
611 double rgba0[4], rgba1[4], rgba2[4];
616 fprintf(fp,
"%g %g %g %g %g %g %g %g %g ", rgba0[0], rgba0[1],
617 rgba0[2], rgba1[0], rgba1[1], rgba1[2], rgba2[0], rgba2[1],
624 fprintf(fp,
" '/>\n");
625 fprintf(fp,
" </IndexedTriangleSet> \n");
626 fprintf(fp,
" </Shape> \n");
627 fprintf(fp,
" </Transform> \n");
629 fprintf(fp,
" </Scene>\n");
630 fprintf(fp,
"</X3D>\n");
636 double width,
double height,
double tic,
637 int horizontal,
double font_size)
668 double width,
double height,
double tic,
672 double box = (horizontal ? width : height) / (opt->
nbIso ? opt->
nbIso : 1);
674 for(
int i = 0; i < opt->
nbIso; i++) {
678 fprintf(fp,
" <Shape> \n");
681 " <IndexedFaceSet colorPerVertex='true' normalPerVertex='true' "
682 "coordIndex='0 1 2 3 -1' solid='false' ccw='true' > \n");
683 fprintf(fp,
" <Coordinate point='");
685 fprintf(fp,
"%e %e %e %e %e %e %e %e %e %e %e %e ", xmin + i *
box,
686 ymin, 0., xmin + (i + 1) *
box, ymin, 0., xmin + (i + 1) *
box,
687 ymin + height, 0., xmin + i *
box, ymin + height, 0.);
690 fprintf(fp,
"%e %e %e %e %e %e %e %e %e %e %e %e ", xmin,
691 ymin + i *
box, 0., xmin + width, ymin + i *
box, 0.,
692 xmin + width, ymin + (i + 1) *
box, 0., xmin,
693 ymin + (i + 1) *
box, 0.);
695 fprintf(fp,
" '/> \n");
699 double rgba[4] = {.5, .5, .5, 1.};
703 " <Color color=' %g %g %g %g %g %g %g %g %g %g %g "
705 rgba[0], rgba[1], rgba[2], rgba[0], rgba[1], rgba[2], rgba[0],
706 rgba[1], rgba[2], rgba[0], rgba[1], rgba[2]);
710 double v1 = opt->
tmpMin + i * dv;
711 double v2 = opt->
tmpMin + (i + 1) * dv;
714 double rgba1[4] = {.5, .5, .5, 1.};
715 double rgba2[4] = {.5, .5, .5, 1.};
719 " <Color color=' %g %g %g %g %g %g %g %g %g %g %g "
721 rgba1[0], rgba1[1], rgba1[2], rgba2[0], rgba2[1], rgba2[2],
722 rgba2[0], rgba2[1], rgba2[2], rgba1[0], rgba1[1], rgba1[2]);
724 fprintf(fp,
" </IndexedFaceSet> \n");
727 fprintf(fp,
" <Shape> \n");
728 fprintf(fp,
" <IndexedLineSet colorPerVertex='true' "
729 "coordIndex='0 1 -1' > \n");
730 fprintf(fp,
" <Coordinate point='");
732 fprintf(fp,
"%e %e %e %e %e %e ", xmin +
box / 2. + i *
box, ymin, 0.,
733 xmin +
box / 2. + i *
box, ymin + height, 0.);
736 fprintf(fp,
"%e %e %e %e %e %e ", xmin, ymin +
box / 2. + i *
box, 0.,
737 xmin + width, ymin +
box / 2. + i *
box, 0.);
739 fprintf(fp,
" '/> \n");
740 double rgba[4] = {.5, .5, .5, 1.};
743 fprintf(fp,
" <Color color=' %g %g %g %g %g %g '/>\n", rgba[0],
744 rgba[1], rgba[2], rgba[0], rgba[1], rgba[2]);
745 fprintf(fp,
" </IndexedLineSet> \n");
747 fprintf(fp,
" </Shape> \n");
752 double width,
double height,
double tic,
753 int horizontal,
double font_size)
756 if(!opt->
nbIso)
return;
757 double font_h = font_size;
758 double font_a = font_size * 3. / 4.;
760 int nbv = opt->
nbIso;
762 for(
int i = 0; i < nbv + 1; i++) {
764 sprintf(label, opt->
format.c_str(), v);
765 maxw = max(maxw, strlen(label) * font_size * 3. / 4.);
773 if(horizontal && width < nbv * maxw) {
779 else if(!horizontal && height < nbv * font_h) {
780 if(height <
f * font_h)
785 double box = (horizontal ? width : height) / opt->
nbIso;
786 double vbox = (horizontal ? width : height) / nbv;
793 for(
int i = 0; i < nbv + 1; i++) {
795 sprintf(label, opt->
format.c_str(), v);
802 ymin + i * vbox - font_a / 3., 0., font_h);
807 if(opt->
nbIso > 2 && (nbv == 1 || nbv == 2)) {
808 vbox = (vbox * nbv -
box) / nbv;
811 for(
int i = 0; i < nbv; i++) {
813 sprintf(label, opt->
format.c_str(), v);
816 ymin + height + tic, 0., font_h);
820 ymin +
box / 2. + i * vbox - font_a / 3., 0.,
828 double width,
double height,
double tic,
829 int horizontal,
double font_size)
840 double font_h = font_size;
847 sprintf(label,
"%s (%s)", data->
getName().c_str(), tmp);
854 sprintf(label,
"%s", data->
getName().c_str());
857 ymin + height + tic + .9 * font_h, 0., font_h);
865 double z,
double font_size)
867 fprintf(fp,
" <Transform translation='%g %g %g'> \n", x, y, 0.);
868 fprintf(fp,
" <Shape> \n");
869 fprintf(fp,
" <Text string='\"%s\"'>\n", label);
872 " <FontStyle justify='\"MIDDLE\" \"MIDDLE\"' size=' %d '/> \n",
874 fprintf(fp,
" </Text>\n");
875 fprintf(fp,
" <Appearance>\n");
876 fprintf(fp,
" <Material diffuseColor='0. 0. 0. '/>\n");
877 fprintf(fp,
" </Appearance>\n");
878 fprintf(fp,
" </Shape>\n");
879 fprintf(fp,
" </Transform> \n");