Debian Codegraph @

07p/plaut04/src/gmain.c++

raw
1 #define XtNumber(arr) ((sizeof(arr) / sizeof(arr[0])))
2
3 #include <fstream>
4 #include <sstream>
5 #include <float.h>
6
7 #include "gplaut04.h"
8 #include "gVarNames.h"
9 #include "createDisk.h"
10 #include "createSphere.h"
11 #include "createLegend.h"
12 #include "readFM.h"
13 #include "stringtrim.h"
14 #include "solution.h"
15 #include "bifurcation.h"
16
17 int specialColorItems = CL_SP_ITEMS;
18
19 float fmData[12];
20 const char *autoDir;
21
22 SbColor lineColor[NUM_SP_POINTS];
23 SbColor lineColorTemp[NUM_SP_POINTS];
24 SbColor lineColorOld[NUM_SP_POINTS];
25 SbColor envColors[12];
26
27 struct DefaultAxisItems dai;
28
29 unsigned long linePattern[NUM_SP_POINTS];
30 unsigned long linePatternTemp[NUM_SP_POINTS];
31 unsigned long linePatternOld[NUM_SP_POINTS];
32
33 unsigned long stabilityLinePattern[2];
34 unsigned long stabilityLinePatternTemp[2];
35
36 bool blDrawTicker = false;
37 bool useR3B = false;
38
39 float diskTransparency = 0.7;
40 bool diskFromFile = false;
41 float diskRotation[4] = {1,0,0,M_PI_2};
42 float diskPosition[3];
43 float diskRadius = 1.0;
44 float diskHeight = 0.001;
45
46 float sphereTransparency = 0.7;
47 bool sphereFromFile = false;
48 float spherePosition[3];
49 float sphereRadius = 1.0;
50
51 int whichType= 0 ;
52 int whichTypeTemp= 0 ;
53 int whichTypeOld = 0 ;
54
55 int whichStyle= 0 ;
56 int whichStyleTemp= 0 ;
57 int whichStyleOld = 0 ;
58
59 int whichCoord = 0 ;
60 int whichCoordTemp = 0 ;
61 int whichCoordOld = 0 ;
62 int whichCoordSystem = 0 ;
63 int whichCoordSystemTemp = 0 ;
64 int whichCoordSystemOld = 0 ;
65
66 unsigned long graphWidgetToggleSet = (unsigned long) 0 ;
67 unsigned long graphWidgetToggleSetTemp = (unsigned long) 0 ;
68 unsigned long graphWidgetToggleSetOld = (unsigned long) 0 ;
69
70 UserData clientData;
71
72 bool options[]=
73 {
74 TRUE, TRUE, FALSE, TRUE, FALSE, FALSE, FALSE,
75 FALSE, FALSE, FALSE, FALSE
76 };
77 bool optionsTemp[11];
78 bool optionsOld[11];
79 bool optBif[11], optSol[11];
80 bool setShow3D, setShow3DSol, setShow3DBif;
81
82 long int animationLabel = MY_ALL;
83
84 int winWidth, winHeight;
85
86 std::vector<int> xCoordIndices, yCoordIndices, zCoordIndices;
87 std::vector<int> lblIndices, lblChoice;
88
89 int MAX_SAT_SPEED = 100;
90 int MIN_SAT_SPEED = 0;
91 int MAX_ORBIT_SPEED = 100;
92 int MIN_ORBIT_SPEED = 0;
93
94 float orbitSpeed = 1.0;
95 float satSpeed = 0.5;
96 float satRadius = 1.0;
97 float lineWidthScaler = 1.0;
98 float aniLineScaler = 2.0;
99 float labelRadius = 1.0;
100
101 int coloringMethod = -1;
102 int coloringMethodType[2] = {-1, -1};
103 float bgTransparency = 0;
104 float numPeriodAnimated = 1.0;
105
106 long int numLabels;
107
108 double legendScaleValues[2];
109
110 SoSeparator *userScene;
111 SoSeparator *root;
112 SoSeparator *starryBackground;
113
114 std::vector<std::string> xAxis, yAxis, zAxis, labels, coloringMethodList;
115 int *myLabels;
116
117 ///////////////////////////////////////////////////////////////
118 //
119 // Function prototypes
120 //
121
122 #if 0
123 static SoSeparator * drawATube(TubeNode cnode);
124 static SoSeparator * MyFileRead(const char *filename, SbString &errorMessage);
125 #endif
126 static void setLegendValues(double* values);
127
128 static void lookForThePoint(float position[],long int &bIdx, long int &sIdx);
129
130 #if 0
131 static SoSeparator * createStarryBackground(int total,float diameter);
132 #endif
133
134 static SoSeparator * addLegend();
135
136 static SoSeparator * drawStarryBackground(char * bgFileName);
137
138 static int readResourceParameters(const char *dir);
139
140 #if 0
141 static void processPrinting(char* filename );
142 #endif
143
144 //
145 ////////////////////////////////////////////////////////////////////////
146
147 ////////////////////////////////////////////////////////////////////////
148 //
149 // functions
150 //
151 ////////////////////////////////////////////////////////////////////////
152
153 #if 0
154 ////////////////////////////////////////////////////////////////////////
155 //
156 void
157 cropScene(const char* filename)
158 //
159 ////////////////////////////////////////////////////////////////////////
160 {
161 system("import my_temp.gif");
162 system("convert -crop 1024x768 my_temp.gif my_temp_cropped.gif");
163 system("convert my_temp_cropped.gif my_temp.eps");
164 system("rm my_temp.gif my_temp_cropped.gif");
165 }
166 #endif
167
168 ////////////////////////////////////////////////////////////////////////
169 //
170 // Write the graph to iv file.
171 //
172 void
173 writeToFile(const char * fileName)
174 //
175 ////////////////////////////////////////////////////////////////////////
176 {
177 SoWriteAction myWrite;
178 myWrite.getOutput()->openFile(fileName);
179 myWrite.getOutput()->setBinary(FALSE);
180 myWrite.apply(root);
181 myWrite.getOutput()->closeFile();
182 }
183
184
185 #if 0
186 ////////////////////////////////////////////////////////////////////////
187 //
188 static void
189 processPrinting(char* filename )
190 //
191 ////////////////////////////////////////////////////////////////////////
192 {
193 FILE *myFile = fopen(filename, "w");
194
195 if (myFile == NULL)
196 {
197 fprintf(stderr, "Cannot open output file\n");
198 exit(1);
199 }
200
201 printf("Printing scene... ");
202 fflush(stdout);
203
204 fclose(myFile);
205
206 printf(" ...done printing.\n");
207 fflush(stdout);
208 }
209 #endif
210
211
212 ////////////////////////////////////////////////////////////////////////
213 //
214 // Description:
215 // Brings up the "HELP INFORMATIO"
216 //
217 //
218 void
219 showHelpDialog()
220 //
221 ////////////////////////////////////////////////////////////////////////
222 {
223 char *command = new char [strlen(autoDir) + 50];
224 sprintf(command, "%s%s", autoDir, "/plaut04/doc/userguide.pdf");
225 if (access(command, R_OK) != 0)
226 {
227 system("xmessage 'Sorry, could not find "
228 "userguide.pdf' > /dev/null");
229 return;
230 }
231
232 int err = system("which xpdf> /dev/null");
233 if (err)
234 {
235 system("xmessage 'You must install xpdf"
236 " for this function to work' > /dev/null");
237 return;
238 }
239
240 sprintf(command, "%s%s%s", "xpdf ",autoDir,"/plaut04/doc/userguide.pdf &");
241 system(command);
242 delete [] command;
243 }
244
245
246 ////////////////////////////////////////////////////////////////////////
247 //
248 void
249 updateScene()
250 //
251 ////////////////////////////////////////////////////////////////////////
252 {
253 int varIndices[3];
254
255 SoSeparator * newScene = new SoSeparator;
256
257 std::vector<int>::size_type mx =
258 std::max(std::max(xCoordIndices.size(), yCoordIndices.size()),
259 std::max(yCoordIndices.size(), zCoordIndices.size()));
260
261 // look for the maximum/minum value in the x-axis, y-axis, z-axis
262 if(whichType != BIFURCATION)
263 {
264 for(std::vector<int>::size_type i=0; i<mx; i++)
265 {
266 std::vector<int>::size_type component = i+1;
267 varIndices[0]=xCoordIndices[
268 (i>=xCoordIndices.size())?(i%xCoordIndices.size()):(i)];
269 varIndices[1]=yCoordIndices[
270 (i>=yCoordIndices.size())?(i%yCoordIndices.size()):(i)];
271 varIndices[2]=zCoordIndices[
272 (i>=zCoordIndices.size())?(i%zCoordIndices.size()):(i)];
273 mySolNode->searchForMaxMin(component, varIndices);
274 }
275 }
276
277 int time_on = TIME_IS_OFF;
278
279 for(std::vector<int>::size_type i=0; i<mx; i++)
280 {
281 varIndices[0]=xCoordIndices[
282 (i>=xCoordIndices.size())?(i%xCoordIndices.size()):(i)];
283 varIndices[1]=yCoordIndices[
284 (i>=yCoordIndices.size())?(i%yCoordIndices.size()):(i)];
285 varIndices[2]=zCoordIndices[
286 (i>=zCoordIndices.size())?(i%zCoordIndices.size()):(i)];
287
288 if (varIndices[0] == 0) time_on = TIME_ON_X;
289 if (varIndices[1] == 0) time_on = TIME_ON_Y;
290 if (varIndices[2] == 0) time_on = TIME_ON_Z;
291
292 SoSeparator *result;
293 if(whichType != BIFURCATION)
294 {
295 animationLabel = myLabels[lblIndices[0]];
296 mySolNode->copyDataToWorkArray(varIndices, i+1, mx, time_on);
297 result = mySolNode->createSceneWithWidgets();
298 }
299 else
300 {
301 myBifNode->copyDataToWorkArray(varIndices);
302 result = myBifNode->createScene();
303 }
304
305 newScene->addChild( result );
306 }
307
308 // create starry background
309 if(options[OPT_BACKGROUND])
310 {
311 char *bgFileName = new char [strlen(autoDir) + 34];
312 sprintf(bgFileName, "%s%s",autoDir, "/plaut04/widgets/background.jpg");
313 newScene->addChild(drawStarryBackground(bgFileName));
314 delete [] bgFileName;
315 }
316
317 // add legend
318 if(options[OPT_LEGEND])
319 {
320 newScene->addChild(addLegend());
321 }
322
323 if (!useR3B && options[OPT_REF_PLAN])
324 newScene->addChild(createDisk(diskPosition,diskRadius));
325 if (options[OPT_REF_SPHERE])
326 newScene->addChild(createSphere(spherePosition,sphereRadius));
327
328
329 if(userScene == NULL)
330 {
331 userScene = newScene;
332 root->addChild(userScene);
333 }
334 else
335 {
336 root->removeAllChildren();
337 root->addChild(newScene);
338 userScene = newScene;
339 }
340 }
341
342
343
344 ////////////////////////////////////////////////////////////////////////
345 //
346 SoSeparator *
347 drawStarryBackground(char * bgFileName)
348 //
349 ////////////////////////////////////////////////////////////////////////
350 {
351 SoSeparator *starryBg = new SoSeparator;
352 SoTexture2 * bgTxture = new SoTexture2;
353 bgTxture->filename.setValue(bgFileName);
354 SoMaterial *bgMaterial = new SoMaterial;
355 bgMaterial->transparency = bgTransparency;
356 starryBg->addChild(bgMaterial);
357 starryBg->addChild(bgTxture);
358 SoTransform *bgXform = new SoTransform;
359 bgXform->translation.setValue(0,0,-9);
360
361 SoOrthographicCamera * bgCamera = new SoOrthographicCamera;
362
363 SoCube * bgPlane = new SoCube();
364 bgPlane->width = 3.0;
365 bgPlane->height = 3.0;
366 bgPlane->depth = 0.01;
367
368 SoDirectionalLight * bgLight = new SoDirectionalLight;
369 bgLight->intensity = 0.05;
370 bgLight->direction.setValue(0,0, -10);
371 starryBg->addChild(bgLight);
372 starryBg->addChild(bgCamera);
373 starryBg->addChild(bgXform);
374 starryBg->addChild(bgPlane);
375 return starryBg;
376 }
377
378
379 ////////////////////////////////////////////////////////////////////////
380 //
381 SoSeparator *
382 addLegend()
383 //
384 ////////////////////////////////////////////////////////////////////////
385 {
386 SoSeparator * result = new SoSeparator;
387 SoOrthographicCamera *legendCamera = new SoOrthographicCamera;
388 result->addChild(legendCamera);
389 SbVec3f lgPos;
390 lgPos.setValue(0.85, 0.65, -5.9);
391
392 if(coloringMethod == CL_CURVE_NUMBER || coloringMethod == CL_BRANCH_NUMBER)
393 {
394 result->addChild(createBranchLegend(lgPos, lineColor));
395 }
396 else if(coloringMethod == CL_STABILITY)
397 {
398 SbColor color[2];
399 color[0].setValue(1,0,0);
400 color[1].setValue(0,0,1);
401 result->addChild(createStabilityLegend(lgPos, color));
402 }
403 else if( coloringMethod == CL_ORBIT_TYPE)
404 {
405 result->addChild(createDiscreteLegend(lgPos, lineColor));
406 }
407 else
408 {
409 double values[5];
410 setLegendValues(values);
411 result->addChild(createLegend(lgPos, values));
412 }
413 result->addChild(new SoDirectionalLight);
414
415 return result;
416 }
417
418
419 ////////////////////////////////////////////////////////////////////////
420 //
421 void
422 setLegendValues(double* values)
423 //
424 ////////////////////////////////////////////////////////////////////////
425 {
426 for(int i=0; i<5; ++i)
427 values[i] = legendScaleValues[0] + i*(legendScaleValues[1]-legendScaleValues[0])/4.0;
428 }
429
430
431 //////////////////////////////////////////////////////////////////////////
432 //
433 // set parMax Color == RED
434 // parMid Color == GREEN
435 // parMin Color == BLUE
436 //
437 SoGroup *
438 setLineAttributesByParameterValue(double parValue, double parMax,
439 double parMid, double parMin, int stability, float scaler)
440 //
441 //////////////////////////////////////////////////////////////////////////
442 {
443 legendScaleValues[0] = parMin;
444 legendScaleValues[1] = parMax;
445
446 SoDrawStyle * lineStyle = new SoDrawStyle;
447 lineStyle->style = SoDrawStyle::FILLED;
448 if(stability == 1 || stability == 3)
449 lineStyle->linePattern = stabilityLinePattern[0];
450 else
451 lineStyle->linePattern = stabilityLinePattern[1];
452
453 SoMaterial * lineMtl = new SoMaterial;
454 lineMtl->diffuseColor.setValue(1.0, 1.0, 1.0);
455 lineMtl->transparency = 0.0;
456
457 // calculating the color.
458 double colFactor;
459 if(parMax != parMin)
460 {
461 if(parValue > parMid)
462 {
463 colFactor = (parValue-parMid)/(parMax-parMid);
464 lineMtl->diffuseColor.setValue(1.0*colFactor, 1.0*(1-colFactor), 0.0);
465 }
466 else
467 {
468 colFactor = (parValue-parMin)/(parMid-parMin);
469 lineMtl->diffuseColor.setValue(0.0*colFactor, 1.0*colFactor, 1.0*(1-colFactor));
470 }
471 }
472
473 lineStyle->lineWidth = 1.5*scaler;
474
475 lineStyle->lineWidth = scaler;
476
477 SoGroup * lineAttributes = new SoGroup;
478 lineAttributes->addChild(lineStyle);
479 lineAttributes->addChild(lineMtl);
480
481 return lineAttributes;
482 }
483
484
485 //////////////////////////////////////////////////////////////////////////
486 //
487 // Set the line pattern and color for the orbit according to
488 // its stablity and type.
489 //
490 SoGroup *
491 setLineAttributesByBranch(int branchID, int stability, float scaler)
492 //
493 //////////////////////////////////////////////////////////////////////////
494 {
495 SoDrawStyle * lineStyle = new SoDrawStyle;
496 lineStyle->style = SoDrawStyle::FILLED;
497 if(stability == 1 || stability == 3)
498 lineStyle->linePattern = stabilityLinePattern[0];
499 else
500 lineStyle->linePattern = stabilityLinePattern[1];
501
502 SoMaterial * lineMtl = new SoMaterial;
503 lineMtl->diffuseColor.setValue(1.0, 1.0, 1.0);
504 lineMtl->transparency = 0.0;
505
506 if(coloringMethod == CL_BRANCH_NUMBER)
507 {
508 if(whichType == SOLUTION)
509 branchID = mySolNode->branchID(branchID);
510 else
511 branchID = myBifNode->branchID(branchID);
512 branchID--;
513 }
514
515 lineStyle->lineWidth = 1.5*scaler;
516 switch(abs(branchID)%13)
517 {
518 case 0:
519 lineMtl->diffuseColor.setValue(lineColor[0]);
520 lineStyle->lineWidth = scaler;
521 break;
522 case 1:
523 lineMtl->diffuseColor.setValue(lineColor[1]);
524 break;
525 case 2:
526 lineMtl->diffuseColor.setValue(lineColor[2]);
527 break;
528 case 3:
529 lineMtl->diffuseColor.setValue(lineColor[3]);
530 break;
531 case 4:
532 lineMtl->diffuseColor.setValue(lineColor[4]);
533 break;
534 case 5:
535 lineMtl->diffuseColor.setValue(lineColor[5]);
536 break;
537 case 6:
538 lineMtl->diffuseColor.setValue(lineColor[6]);
539 break;
540 case 7:
541 lineMtl->diffuseColor.setValue(lineColor[7]);
542 break;
543 case 8:
544 lineMtl->diffuseColor.setValue(lineColor[8]);
545 break;
546 case 9:
547 lineMtl->diffuseColor.setValue(lineColor[9]);
548 break;
549 case 10:
550 lineMtl->diffuseColor.setValue(lineColor[10]);
551 lineStyle->lineWidth = scaler;
552 break;
553 case 11:
554 lineMtl->diffuseColor.setValue(lineColor[11]);
555 lineStyle->lineWidth = scaler;
556 break;
557 case 12:
558 default:
559 lineMtl->diffuseColor.setValue(lineColor[12]);
560 lineStyle->lineWidth = scaler;
561 break;
562 }
563
564 SoGroup * lineAttributes = new SoGroup;
565 lineAttributes->addChild(lineStyle);
566 lineAttributes->addChild(lineMtl);
567 return lineAttributes;
568 }
569
570
571 //////////////////////////////////////////////////////////////////////////
572 //
573 SoGroup *
574 setLineColorBlendingByStability(float * vertices, long int size, int stability, float scaler)
575 //
576 //////////////////////////////////////////////////////////////////////////
577 {
578 float (*colors)[3] = new float[size][3];
579 static float maxColor[3];
580 static float minColor[3];
581
582 for(int i=0; i<3; ++i)
583 {
584 maxColor[i] = envColors[5][i];
585 minColor[i] = envColors[6][i];
586 }
587
588 for(int i=0; i<size; ++i)
589 {
590 if(vertices[i]== 1 || vertices[i]== 3)
591 for(int j=0; j<3; ++j) colors[i][j] = maxColor[j];
592 else
593 for(int j=0; j<3; ++j) colors[i][j] = minColor[j];
594 }
595
596 SoGroup * result = new SoGroup ;
597
598 SoDrawStyle * lineStyle = new SoDrawStyle;
599 if(stability == 1 || stability == 3)
600 {
601 lineStyle->style = SoDrawStyle::FILLED;
602 lineStyle->linePattern = stabilityLinePattern[0];
603 }
604 else
605 {
606 lineStyle->style = SoDrawStyle::FILLED;
607 lineStyle->linePattern = stabilityLinePattern[1];
608 }
609 lineStyle->lineWidth = scaler;
610 result->addChild(lineStyle);
611
612 SoMaterial *myMaterials = new SoMaterial;
613 myMaterials->diffuseColor.setValues(0, size, colors);
614 result->addChild(myMaterials);
615
616 SoMaterialBinding *myMaterialBinding = new SoMaterialBinding;
617 myMaterialBinding->value = SoMaterialBinding::PER_VERTEX;
618 result->addChild(myMaterialBinding);
619 delete [] colors;
620 return result;
621 }
622
623
624 //////////////////////////////////////////////////////////////////////////
625 //
626 SoGroup *
627 setLineAttributesByStability(int stability, float scaler)
628 //
629 //////////////////////////////////////////////////////////////////////////
630 {
631 SoDrawStyle * lineStyle = new SoDrawStyle;
632 lineStyle->style = SoDrawStyle::FILLED;
633
634 SoMaterial * lineMtl = new SoMaterial;
635 lineMtl->shininess = 0.9;
636
637 if(stability == 1 || stability == 3)
638 {
639 lineStyle->linePattern = stabilityLinePattern[0];
640 lineMtl->diffuseColor.setValue(envColors[5]);
641 }
642 else
643 {
644 lineStyle->linePattern = stabilityLinePattern[1];
645 lineMtl->diffuseColor.setValue(envColors[6]);
646 }
647
648 lineStyle->lineWidth = scaler;
649
650 SoGroup * lineAttributes = new SoGroup;
651 lineAttributes->addChild(lineStyle);
652 lineAttributes->addChild(lineMtl);
653 return lineAttributes;
654 }
655
656
657 //////////////////////////////////////////////////////////////////////////
658 //
659 // Set the line pattern and color for the orbit according to
660 // its stablity and type.
661 //
662 SoGroup *
663 setLineAttributesByType(int stability, int type, float scaler)
664 //
665 //////////////////////////////////////////////////////////////////////////
666 {
667 SoDrawStyle * lineStyle = new SoDrawStyle;
668
669 lineStyle->style = SoDrawStyle::FILLED;
670 if(stability == 1 || stability == 3)
671 lineStyle->linePattern = stabilityLinePattern[0];
672 else
673 lineStyle->linePattern = stabilityLinePattern[1];
674
675 SoMaterial * lineMtl = new SoMaterial;
676 lineMtl->shininess = 0.9;
677
678 lineStyle->lineWidth = 1.5*scaler;
679 switch(type)
680 {
681 case 0:
682 lineMtl->diffuseColor.setValue(lineColor[0]);
683 lineStyle->lineWidth = scaler;
684 break;
685 case 1:
686 lineMtl->diffuseColor.setValue(lineColor[1]);
687 break;
688 case 2:
689 lineMtl->diffuseColor.setValue(lineColor[2]);
690 break;
691 case 3:
692 lineMtl->diffuseColor.setValue(lineColor[3]);
693 break;
694 case 4:
695 lineMtl->diffuseColor.setValue(lineColor[4]);
696 break;
697 case -4:
698 lineMtl->diffuseColor.setValue(lineColor[5]);
699 break;
700 case 5:
701 lineMtl->diffuseColor.setValue(lineColor[6]);
702 break;
703 case 6:
704 lineMtl->diffuseColor.setValue(lineColor[7]);
705 break;
706 case 7:
707 lineMtl->diffuseColor.setValue(lineColor[8]);
708 break;
709 case 8:
710 lineMtl->diffuseColor.setValue(lineColor[9]);
711 break;
712 case 9:
713 lineMtl->diffuseColor.setValue(lineColor[10]);
714 lineStyle->lineWidth = scaler;
715 break;
716 case -9:
717 lineMtl->diffuseColor.setValue(lineColor[11]);
718 lineStyle->lineWidth = scaler;
719 break;
720 default:
721 lineMtl->diffuseColor.setValue(lineColor[12]);
722 lineStyle->lineWidth = scaler;
723 break;
724 }
725
726 SoGroup * lineAttributes = new SoGroup;
727 lineAttributes->addChild(lineStyle);
728 lineAttributes->addChild(lineMtl);
729 return lineAttributes;
730 }
731
732
733 //////////////////////////////////////////////////////////////////////////
734 //
735 SoGroup *
736 setLineColorBlending(float * vertices, long int size, int stability, float scaler)
737 //
738 //////////////////////////////////////////////////////////////////////////
739 {
740 float (*colors)[3] = new float[size][3];
741 static float maxColor[3] = //red
742 {
743 1.0, 0.0, 0.0
744 };
745 static float midColor[3] = //green
746 {
747 0.0, 1.0, 0.0
748 };
749 static float minColor[3] = //blue
750 {
751 0.0, 0.0, 1.0
752 };
753
754 float maxValue = vertices[0];
755 float minValue = vertices[0];
756 float midValue = vertices[0];
757
758 for(int i=0; i<size; ++i)
759 {
760 if(maxValue<vertices[i])maxValue=vertices[i];
761 if(minValue>vertices[i])minValue=vertices[i];
762 }
763
764 if( whichType == SOLUTION &&
765 (coloringMethod != CL_POINT_NUMBER &&
766 (animationLabel == MY_ALL || options[OPT_PERIOD_ANI]) ))
767 {
768 legendScaleValues[0]= minValue = clientData.solMin[coloringMethod];
769 legendScaleValues[1]= maxValue = clientData.solMax[coloringMethod];
770 }
771 else
772 {
773 legendScaleValues[0]= minValue;
774 legendScaleValues[1]= maxValue;
775 }
776 midValue = (maxValue + minValue)/2.0;
777
778 // interpolate the colors for each vertices.
779 float dt = maxValue - minValue;
780 float dtColor;
781 for(int i=0; i<size; ++i)
782 {
783 for(int j=0; j<3; ++j)
784 {
785 if(vertices[i]>midValue)
786 {
787 dt = maxValue - midValue;
788 dtColor = maxColor[j]-midColor[j];
789 colors[i][j] = (dt<1.0e-9) ?
790 ((midColor[j]+maxColor[j])/2.0) :
791 (midColor[j] + dtColor * (vertices[i]-midValue)/dt);
792 }
793 else
794 {
795 dt = midValue - minValue;
796 dtColor = midColor[j]-minColor[j];
797 colors[i][j] = (dt<1.0e-9) ?
798 ((minColor[j]+midColor[j])/2.0) :
799 (minColor[j] + dtColor * (vertices[i]-minValue)/dt);
800 }
801 }
802 }
803
804 SoGroup * result = new SoGroup ;
805
806 // set line style and pattern
807 SoDrawStyle * lineStyle = new SoDrawStyle;
808 if(stability == 1 || stability == 3)
809 {
810 lineStyle->style = SoDrawStyle::FILLED;
811 lineStyle->linePattern = stabilityLinePattern[0];
812 }
813 else
814 {
815 lineStyle->style = SoDrawStyle::FILLED;
816 lineStyle->linePattern = stabilityLinePattern[1];
817 }
818 lineStyle->lineWidth = scaler;
819 result->addChild(lineStyle);
820
821 SoMaterial *myMaterials = new SoMaterial;
822 myMaterials->diffuseColor.setValues(0, size, colors);
823 result->addChild(myMaterials);
824
825 SoMaterialBinding *myMaterialBinding = new SoMaterialBinding;
826 myMaterialBinding->value = SoMaterialBinding::PER_VERTEX;
827 result->addChild(myMaterialBinding);
828 delete [] colors;
829 return result;
830 }
831
832
833 #if 0
834 ///////////////////////////////////////////////////////////////////////////
835 //
836 SoSeparator *
837 drawATube(TubeNode cnode)
838 //
839 ///////////////////////////////////////////////////////////////////////////
840 {
841 SoSeparator *tSep = new SoSeparator;
842 SoTransform *tXform = new SoTransform;
843 tXform->translation.setValue(cnode.translation.x,
844 cnode.translation.y,
845 cnode.translation.z);
846 tXform->rotation.setValue(SbVec3f(cnode.axis.x,
847 cnode.axis.y,
848 cnode.axis.z),
849 cnode.angle);
850 SoCylinder *tCyl = new SoCylinder;
851 tCyl->radius = 0.005;
852 tCyl->height = cnode.height;
853 tCyl->parts = SoCylinder::SIDES;
854
855 tSep->addChild(tXform);
856 tSep->addChild(tCyl);
857 return tSep;
858 }
859 #endif
860
861
862
863
864 ///////////////////////////////////////////////////////////////////////////
865 //
866 SoSeparator *
867 drawASphere(float position[], float size)
868 //
869 ///////////////////////////////////////////////////////////////////////////
870 {
871 float scaler = 1.0e-4;
872 SoSeparator *satSep = new SoSeparator;
873 SoTransform *satXform = new SoTransform;
874
875 satXform->translation.setValue(position[0],position[1],position[2]);
876 satSep->addChild(satXform);
877
878 SoSeparator *satSph;
879
880 bool obj = FALSE;
881 SoInput mySceneInput;
882 if (obj && mySceneInput.openFile("widgets/sattelite.iv"))
883 {
884 satSph = SoDB::readAll(&mySceneInput);
885 if (satSph == NULL)
886 {
887 obj=FALSE;
888 }
889 else
890 {
891
892 mySceneInput.closeFile();
893 SoTransform *satTrans = new SoTransform;
894 satTrans->scaleFactor.setValue(scaler,scaler,scaler);
895 satSep->addChild(satTrans);
896 satSep->addChild(satSph);
897 satSep->addChild(satSph);
898 obj = TRUE;
899 }
900 }
901 else
902 {
903 obj = FALSE;
904 }
905
906 if(!obj)
907 {
908 SoSphere *satSph = new SoSphere;
909 satSph->radius = size;
910 satSep->addChild(satSph);
911 }
912
913 return satSep;
914 }
915
916
917 ////////////////////////////////////////////////////////////////////////
918 //
919 // initialize win basic things
920 //
921 static bool
922 readSolutionAndBifurcationData(bool blFirstRead,
923 const std::string& sFileName,
924 const std::string& bFileName,
925 const std::string& dFileName)
926 //
927 ///////////////////////////////////////////////////////////////////////
928 {
929 bool blOpenSolFile, blOpenBifFile;
930
931 blOpenSolFile = mySolNode->parse(sFileName.c_str());
932 if(!blOpenSolFile)
933 printf(" Solution file does not exist.\n");
934
935 mySolNode->alloc();
936
937 clientData.solMax = new float [mySolNode->nar()+1];
938 clientData.solMin = new float [mySolNode->nar()+1];
939
940 blOpenBifFile = myBifNode->parse(bFileName.c_str());
941 if(!blOpenBifFile) printf(" Bifurcation file does not exist!\n");
942
943 if((!blOpenBifFile) && (!blOpenSolFile) && (!blFirstRead)) return false;
944 else if((!blOpenBifFile) && (!blOpenSolFile))
945 {
946 // printf(" Target files do not exist!\n");
947 exit(1);
948 }
949
950 myBifNode->alloc();
951
952 myLabels = new int[std::max(myBifNode->totalLabels(),
953 mySolNode->totalLabels())+SP_LBL_ITEMS];
954 clientData.labelIndex = new long int[std::max(myBifNode->totalLabels(),
955 mySolNode->totalLabels())][4];
956
957 int varIndices[3];
958
959 if( blOpenBifFile)
960 {
961 if (!myBifNode->read(bFileName.c_str(), varIndices))
962 printf(" Failed to read the bifurcation file!\n");
963 }
964 else
965 {
966 whichType = SOLUTION;
967 }
968
969 if( mySolNode->numOrbits() > 0 )
970 {
971 blOpenSolFile = mySolNode->read(sFileName.c_str(), varIndices);
972 if(!blOpenSolFile)
973 printf(" Failed to read the solution file!\n");
974 else if(myBifNode->totalLabels() != 0 &&
975 mySolNode->totalLabels() != myBifNode->totalLabels())
976 {
977 printf(" total labels in b-file is: %i, in s-file is: %i\n",
978 myBifNode->totalLabels(), mySolNode->totalLabels());
979 printf(" The total number of labels in the bifurcation file is different from\n");
980 printf(" the total number of labels in the solution file! CHECK IT.\n");
981 exit(1);
982 }
983
984 if(mySolNode->nar() <= 3)
985 {
986 setShow3DSol = false;
987 if(whichType != BIFURCATION) setShow3D = false;
988 }
989 }
990 else
991 {
992 whichType = BIFURCATION;
993 }
994
995 if((!blOpenBifFile) && (!blOpenSolFile))
996 {
997 exit(1);
998 }
999
1000 clientData.maxndim = std::max(myBifNode->maxndim(),mySolNode->nar()-1);
1001 int st = readFM(dFileName.c_str(), myBifNode->totalNumPoints());
1002 if(st!=0)
1003 printf(" Failed to read the diagnostic file.\n");
1004
1005 return TRUE;
1006 }
1007
1008
1009 ////////////////////////////////////////////////////////////////////////
1010 //
1011 void
1012 lookForThePoint(float position[],long int &bIdx, long int &sIdx)
1013 //
1014 ////////////////////////////////////////////////////////////////////////
1015 {
1016
1017 int varIndices[3];
1018 std::vector<int>::size_type mx =
1019 std::max(std::max(xCoordIndices.size(), yCoordIndices.size()),
1020 std::max(yCoordIndices.size(), zCoordIndices.size()));
1021 float minDis = FLT_MAX;
1022 long int index = 0;
1023 long int ib = 0;
1024 float distance;
1025 float *data;
1026 sIdx = bIdx = 0;
1027 for(std::vector<int>::size_type i=0; i<mx; i++)
1028 {
1029 varIndices[0]=xCoordIndices[
1030 (i>=xCoordIndices.size())?(i%xCoordIndices.size()):(i)];
1031 varIndices[1]=yCoordIndices[
1032 (i>=yCoordIndices.size())?(i%yCoordIndices.size()):(i)];
1033 varIndices[2]=zCoordIndices[
1034 (i>=zCoordIndices.size())?(i%zCoordIndices.size()):(i)];
1035 long int lblidx = lblIndices[0];
1036 long int maxp, sumup = 0;
1037 if(whichType == BIFURCATION)
1038 {
1039 maxp = myBifNode->totalNumPoints();
1040 }
1041 else
1042 {
1043 animationLabel = myLabels[lblIndices[0]];
1044 if(animationLabel == MY_ALL || lblIndices.size() >1)
1045 maxp = mySolNode->totalNumPoints();
1046 else
1047 {
1048 for(int j=0; j<lblidx; ++j)
1049 sumup += mySolNode->numVerticesEachPeriod(j);
1050 maxp = mySolNode->numVerticesEachPeriod(lblidx);
1051 }
1052 }
1053 for(long int j=0; j<maxp; ++j)
1054 {
1055 if(whichType == BIFURCATION)
1056 data = &myBifNode->data()[j*myBifNode->nar()];
1057 else
1058 data = mySolNode->data()[sumup+j];
1059 distance = 0;
1060 for(int k=0; k<3; ++k)
1061 if(varIndices[k] != -1)
1062 {
1063 float diff = position[k]-data[varIndices[k]];
1064 distance += diff * diff;
1065 }
1066 if(minDis > distance)
1067 {
1068 minDis = distance;
1069 index = j+sumup;
1070 }
1071 }
1072 if(whichType != BIFURCATION)
1073 {
1074 if(animationLabel == MY_ALL || lblIndices.size() >1)
1075 {
1076 for (ib = 0; ib < mySolNode->totalLabels(); ib++)
1077 {
1078 sumup += mySolNode->numVerticesEachPeriod(ib);
1079 if (sumup > index) break;
1080 }
1081 }
1082 else
1083 {
1084 ib = lblidx;
1085 }
1086 sIdx = index;
1087 bIdx = clientData.labelIndex[ib][1];
1088 }
1089 else
1090 {
1091 bIdx = index;
1092 }
1093 }
1094 }
1095
1096
1097 #if 0
1098 ///////////////////////////////////////////////////////////////////////////
1099 //
1100 void
1101 pointsToAxisAngle(float * a, float * b, TubeNode &value)
1102 //
1103 ///////////////////////////////////////////////////////////////////////////
1104 {
1105 float c[3]={0.,0.,0.};
1106 float normc[3];
1107 int i=0;
1108 value.translation.x=value.translation.y=value.translation.z=0.0;
1109 value.axis.x=value.axis.y=value.axis.z=0.0;
1110 value.angle=0.0;
1111 value.height=0.0;
1112 float scaler = 2.0;
1113 for(i=0; i<3; i++)
1114 c[i]=b[i]-a[i];
1115 if(c[1]<0)
1116 {
1117 value.translation.x=b[0];
1118 value.translation.y=b[1];
1119 value.translation.z=b[2];
1120 scaler = 2.0;
1121 for(i=0; i<3; i++)
1122 c[i]=-c[i];
1123 }
1124 else
1125 {
1126 value.translation.x=a[0];
1127 value.translation.y=a[1];
1128 value.translation.z=a[2];
1129 }
1130
1131 float c_norm, axis_norm;
1132 c_norm=sqrt(c[0]*c[0]+c[1]*c[1]+c[2]*c[2]);
1133 value.height=c_norm*scaler;
1134 if(c_norm>0.0000001)
1135 {
1136 for(i=0; i<3; i++)
1137 normc[i]=0.0;
1138 for(i=0; i<3; i++)
1139 normc[i]=c[i]/c_norm;
1140 value.axis.x=normc[2];
1141 value.axis.y=0.0;
1142 value.axis.z=-normc[0];
1143 axis_norm=sqrt(value.axis.x*value.axis.x +\
1144 value.axis.y*value.axis.y +\
1145 value.axis.z*value.axis.z);
1146 if(axis_norm < 0.00000001)
1147 {
1148 value.angle=0.0;
1149 }
1150 else
1151 {
1152 value.angle=asin(axis_norm);
1153 }
1154 }
1155 }
1156 #endif
1157
1158
1159 ////////////////////////////////////////////////////////////////////
1160 //
1161 static SbBool
1162 writePickedPath (SoNode *result, const SbViewportRegion &viewport,
1163 const SbVec2s &cursorPosition)
1164 //
1165 ////////////////////////////////////////////////////////////////////
1166 {
1167 SoRayPickAction myPickAction(viewport);
1168
1169 // Set an 4-pixel wide region around the pixel
1170 myPickAction.setPoint(cursorPosition);
1171 myPickAction.setRadius(4.0);
1172
1173 // Start a pick traversal
1174 myPickAction.apply(result);
1175 const SoPickedPoint *myPickedPoint =
1176 myPickAction.getPickedPoint();
1177 if (myPickedPoint == NULL)
1178 {
1179 return FALSE;
1180 }
1181
1182 SbVec3f myPosition;
1183 myPosition = myPickedPoint->getPoint();
1184 float position[3], x, y, z;
1185 long int sIdx, bIdx;
1186 int size;
1187
1188 myPosition.getValue(x, y, z);
1189 position[0]=x; position[1]=y; position[2]=z;
1190
1191 if (options[OPT_NORMALIZE_DATA]) {
1192 if(whichType != BIFURCATION)
1193 {
1194 mySolNode->denormalizePosition(position);
1195 }
1196 else
1197 {
1198 myBifNode->denormalizePosition(position);
1199 }
1200 }
1201
1202 lookForThePoint(position, bIdx, sIdx);
1203
1204 float *data;
1205 if(whichType != BIFURCATION)
1206 {
1207 if(sIdx > mySolNode->totalNumPoints() || sIdx < 0)
1208 return false;
1209 size = mySolNode->nar();
1210 data = mySolNode->data()[sIdx];
1211 }
1212 else {
1213 if (bIdx > myBifNode->totalNumPoints() || bIdx < 0)
1214 return false;
1215 size = myBifNode->nar();
1216 data = &myBifNode->data()[bIdx * size];
1217 }
1218
1219 for(int ms=0; ms<abs(clientData.numFM[bIdx]); ++ms)
1220 {
1221 fmData[2*ms] = clientData.multipliers[bIdx*clientData.maxndim+ms][0];
1222 fmData[2*ms+1] = clientData.multipliers[bIdx*clientData.maxndim+ms][1];
1223 }
1224
1225 popupFloquetMultiplierDialog(data, size, clientData.numFM[bIdx]);
1226 return TRUE;
1227 }
1228
1229
1230 ///////////////////////////////////////////////////////////////////
1231 //
1232 // This routine is called for every mouse button event.
1233 //
1234 void
1235 myMousePressCB(void *userData, SoEventCallback *eventCB)
1236 //
1237 ///////////////////////////////////////////////////////////////////
1238 {
1239 SoSeparator *result = (SoSeparator *) userData;
1240 const SoEvent *event = eventCB->getEvent();
1241
1242 if (SO_MOUSE_PRESS_EVENT(event, ANY))
1243 {
1244 const SbViewportRegion &myRegion =
1245 eventCB->getAction()->getViewportRegion();
1246 writePickedPath(result, myRegion,
1247 event->getPosition(myRegion));
1248 eventCB->setHandled();
1249 }
1250 }
1251
1252
1253 ///////////////////////////////////////////////////////////////////
1254 //
1255 // Initialize the coordinate selection drop down list items
1256 // and the drop down label list items.
1257 //
1258 static void
1259 initCoordAndLableListItems()
1260 //
1261 ///////////////////////////////////////////////////////////////////
1262 {
1263 int i = 0;
1264 int nar = whichType == SOLUTION ? mySolNode->nar() : myBifNode->nar();
1265 xAxis.clear();
1266 yAxis.clear();
1267 zAxis.clear();
1268 for(i=0; i<nar; i++)
1269 {
1270 std::stringstream s;
1271 s << i;
1272 xAxis.push_back(s.str());
1273 yAxis.push_back(s.str());
1274 zAxis.push_back(s.str());
1275 }
1276
1277 coloringMethodList.clear();
1278 coloringMethodList.push_back("BRAN");
1279 coloringMethodList.push_back("STAB");
1280 coloringMethodList.push_back("PONT");
1281 coloringMethodList.push_back("CURV");
1282 specialColorItems = 4;
1283
1284 if(whichType == SOLUTION)
1285 {
1286 coloringMethodList.push_back("TYPE");
1287 coloringMethodList.push_back("LABL");
1288 coloringMethodList.push_back("COMP");
1289 specialColorItems = 7;
1290 }
1291 for(i=0; i<nar; i++)
1292 {
1293 std::stringstream s;
1294 s << i;
1295 coloringMethodList.push_back(s.str());
1296 }
1297 if(whichType == SOLUTION)
1298 {
1299 for(i=0; i<mySolNode->npar(); ++i)
1300 {
1301 std::stringstream s;
1302 s << "PAR(" << mySolNode->parID(i)+1 << ")";
1303 coloringMethodList.push_back(s.str());
1304 }
1305 }
1306
1307 if(mySolNode->numOrbits() > 0)
1308 {
1309 // the solution file does exist.
1310 numLabels = mySolNode->numOrbits();
1311 for(int j=0; j<numLabels; j++) myLabels[j] = mySolNode->labels(j);
1312 if(useR3B)
1313 {
1314 // initial mass dependent options.
1315 float lastMass = mySolNode->masses(1);
1316 blMassDependantOption = true;
1317 for(i=1; i<mySolNode->numOrbits(); i++)
1318 {
1319 if(fabs(mySolNode->masses(i)-lastMass)/lastMass > 1.0e-3)
1320 {
1321 blMassDependantOption = false;
1322 break;
1323 }
1324 }
1325 if(blMassDependantOption) mass = lastMass;
1326 }
1327 }
1328 else
1329 {
1330 numLabels = myBifNode->totalLabels();
1331 for(int j=0; j<numLabels; j++) myLabels[j] = myBifNode->labels(j);
1332 if(useR3B) blMassDependantOption = false;
1333 }
1334
1335 if(useR3B && !blMassDependantOption)
1336 {
1337 options[OPT_PRIMARY ]= false;
1338 options[OPT_LIB_POINTS]= false;
1339 }
1340
1341 options[OPT_LEGEND] = false;
1342 options[OPT_BACKGROUND] = false;
1343
1344 numLabels += SP_LBL_ITEMS;
1345 myLabels[numLabels + MY_NONE] = MY_NONE; // -1
1346 myLabels[numLabels + MY_SPEC] = MY_SPEC; // -2
1347 myLabels[numLabels + MY_HALF] = MY_HALF; // -3
1348 myLabels[numLabels + MY_ALL] = MY_ALL; // -4
1349
1350 labels.clear();
1351 labels.push_back("ALL");
1352 labels.push_back("HALF");
1353 labels.push_back("SPEC");
1354 labels.push_back("NONE");
1355
1356 int nty;
1357 const char *tylabels[] = {
1358 "MX","R4","R3","R2","R1","UZ","ZH","CP","BT"," ",
1359 "BP","LP","HB"," ","LP","BP","PD","TR","EP",
1360 "GH","LPD","LTR","PTR","TTR"};
1361 for( i=0; i<numLabels-SP_LBL_ITEMS; ++i)
1362 {
1363 std::stringstream s;
1364 s << myLabels[i];
1365 nty = 0;
1366 switch (clientData.labelIndex[i][2])
1367 {
1368 case -32:
1369 nty = 10; // 'GH'
1370 break;
1371 case 28:
1372 case 78:
1373 nty = 11; // 'LPD'
1374 break;
1375 case 23:
1376 case 83:
1377 nty = 12; // 'LTR'
1378 break;
1379 case 77:
1380 case 87:
1381 nty = 13; // 'PTR'
1382 break;
1383 case 88:
1384 nty = 14; // 'TTR'
1385 break;
1386 default:
1387 if (clientData.labelIndex[i][2] >= 0)
1388 nty = clientData.labelIndex[i][2] % 10;
1389 else
1390 nty = -(-clientData.labelIndex[i][2] % 10);
1391 break;
1392 }
1393 if (nty != 0 && tylabels[nty+9][0] != ' ')
1394 {
1395 s << " " << tylabels[nty+9];
1396 }
1397 labels.push_back(s.str());
1398 }
1399
1400 if(whichType == SOLUTION)
1401 {
1402 xCoordIndices = dai.solX;
1403 yCoordIndices = dai.solY;
1404 zCoordIndices = dai.solZ;
1405 }
1406 else
1407 {
1408 xCoordIndices = dai.bifX;
1409 yCoordIndices = dai.bifY;
1410 zCoordIndices = dai.bifZ;
1411 }
1412
1413 //---------------------- Begin ---------------------------OCT 7, 04
1414
1415 int half = 2;
1416 lblIndices.clear();
1417 //tmp = strtok(manyChoice, ",");
1418 if( lblChoice[0] == MY_ALL) // -4
1419 {
1420 lblIndices.push_back(numLabels + MY_ALL);
1421 half = 2;
1422 }
1423 else if(lblChoice[0] == MY_HALF) // -3
1424 {
1425 for(int j = 0; j < numLabels - SP_LBL_ITEMS; j++)
1426 {
1427 if(abs(clientData.labelIndex[j][2])!= 4 || (j+1)%half == 0)
1428 lblIndices.push_back(j);
1429 }
1430
1431 half *= 2;
1432 }
1433 else if(lblChoice[0] == MY_SPEC) // -2
1434 {
1435 for(int j = 0; j < numLabels - SP_LBL_ITEMS; j++)
1436 {
1437 if(clientData.labelIndex[j][2] != TYPE_UZ && clientData.labelIndex[j][2] != TYPE_RG &&
1438 clientData.labelIndex[j][2] != TYPE_EP_ODE && clientData.labelIndex[j][2] != TYPE_MX)
1439 lblIndices.push_back(j);
1440 }
1441 half = 2;
1442 }
1443 else if(lblChoice[0] == MY_NONE) // -1
1444 {
1445 lblIndices.push_back(numLabels + MY_NONE);
1446 half = 2;
1447 }
1448 else // Specified labels
1449 {
1450 for(std::vector<int>::size_type idx = 0; idx < lblIndices.size(); idx++)
1451 lblIndices.push_back(lblChoice[idx]);
1452 half = 2;
1453 }
1454
1455 for(int i=0; i<11; ++i)
1456 {
1457 optSol[i] = options[i];
1458 optBif[i] = options[i];
1459 }
1460
1461
1462 //----------------------- End ----------------------------
1463
1464 if(!setShow3D)
1465 {
1466 for(std::vector<int>::size_type i=0; i<zCoordIndices.size(); i++)
1467 zCoordIndices[i] = -1;
1468 }
1469 }
1470
1471
1472 static std::stringstream&
1473 readAString(std::stringstream& buffer, std::string& aString);
1474
1475 ///////////////////////////////////////////////////////////////////
1476 //
1477 // Read line colors and line pattern from the resource file.
1478 // each call of this function, read one line
1479 //
1480 static void
1481 readLineColorAndPattern(std::stringstream& buffer, float *lineColor, unsigned long & linePattern)
1482 //
1483 ///////////////////////////////////////////////////////////////////
1484 {
1485 std::string word;
1486 for(int k=0; k<3; ++k)
1487 {
1488 readAString(buffer, word);
1489 std::stringstream(word) >> lineColor[k];
1490 }
1491 readAString(buffer, word);
1492 std::stringstream(word) >> std::hex >> linePattern;
1493 }
1494
1495
1496 ///////////////////////////////////////////////////////////////////
1497 //
1498 // Read flex number of numbers.
1499 // each call of this function, read one line
1500 //
1501 template <class T>
1502 static void
1503 readNData(std::stringstream& buffer, T *data, int size )
1504 //
1505 ///////////////////////////////////////////////////////////////////
1506 {
1507 std::string word;
1508 for(int k=0; k<size; ++k)
1509 {
1510 readAString(buffer, word);
1511 std::stringstream(word) >> data[k];
1512 }
1513 }
1514
1515 template <class T>
1516 static void
1517 readNData(std::stringstream& buffer, std::queue<T> &data)
1518 //
1519 ///////////////////////////////////////////////////////////////////
1520 {
1521 std::string word;
1522 T item;
1523 while ( readAString(buffer, word) )
1524 {
1525 std::stringstream(word) >> item;
1526 data.push(item);
1527 }
1528 }
1529
1530
1531 ///////////////////////////////////////////////////////////////////
1532 //
1533 // Read a string from the buffer. Used to parse those boolean
1534 // variables or sigle value in a line of the resource file.
1535 //
1536 static std::stringstream&
1537 readAString(std::stringstream& buffer, std::string& aString)
1538 //
1539 ///////////////////////////////////////////////////////////////////
1540 {
1541 std::getline(buffer, aString, ',');
1542 return buffer;
1543 }
1544
1545
1546 ///////////////////////////////////////////////////////////////////
1547 //
1548 static void
1549 readAHexdecimal(std::stringstream& buffer, unsigned long & aHexdecimal )
1550 //
1551 ///////////////////////////////////////////////////////////////////
1552 {
1553 std::string aString;
1554 readAString(buffer, aString);
1555 std::stringstream(aString) >> std::hex >> aHexdecimal;
1556 }
1557
1558
1559 ///////////////////////////////////////////////////////////////////
1560 //
1561 double
1562 fortranatof(char* word)
1563 //
1564 ///////////////////////////////////////////////////////////////////
1565 {
1566 // check for numbers such as 2.8430486351-315
1567 char *p;
1568 size_t len = strlen(word);
1569 double d = strtod(word, &p);
1570 if (len >= 6 && p == word+len-4 &&
1571 (*p == '-' || *p == '+' || *p++ == 'D')) {
1572 p[-2] = '1';
1573 p[-1] = 'E';
1574 d*=atof(p-2);
1575 }
1576 return d;
1577 }
1578
1579 ///////////////////////////////////////////////////////////////////
1580 //
1581 // INITIALIZE all the variables
1582 // If the resource file exists, read it and update the default values.
1583 // If it does not exist, just return and use default values.
1584 //
1585 int
1586 readResourceParameters(const char *dir)
1587 //
1588 ///////////////////////////////////////////////////////////////////
1589 {
1590 int state = 0;
1591
1592 float aVector[3];
1593 unsigned long aHex;
1594 std::string aString;
1595 const char *file;
1596
1597 if(!useR3B)
1598 file = "plaut04.rc";
1599 else
1600 file = "r3bplaut04.rc";
1601 std::ifstream inFile(file);
1602
1603 if (!inFile && dir)
1604 {
1605 std::string resource = dir;
1606 resource += "/";
1607 resource += file;
1608 inFile.open(resource.c_str());
1609 }
1610
1611 if (!inFile)
1612 {
1613 std::string resource = autoDir;
1614 resource += "/plaut04/";
1615 resource += file;
1616 inFile.open(resource.c_str());
1617 if(!inFile)
1618 {
1619 printf("Unable to open the resource file. I will use the default values.\n");
1620 state = 1;
1621 return state;
1622 }
1623 }
1624
1625 std::string line;
1626 while ( std::getline(inFile, line) )
1627 {
1628 if(line[0] != '#')
1629 // else it is a comment line, discard it. Nothing need to do here.
1630 {
1631 std::stringstream buffer(line);
1632 std::string str;
1633 std::getline(buffer, str, '=');
1634 strrighttrim(str);
1635 strlefttrim(str);
1636 const char *strTemp = str.c_str();
1637
1638 bool blDealt = false;
1639 if( !blDealt )
1640 {
1641 for(int i = 0; i<NUM_SP_POINTS; ++i)
1642 {
1643 if(strcasecmp(strTemp, typeTokenNames[i])==0)
1644 {
1645 readLineColorAndPattern(buffer, aVector, aHex);
1646 lineColor[i].setValue( aVector );
1647 linePattern[i] = aHex;
1648 blDealt = true;
1649 break;
1650 }
1651 }
1652 }
1653
1654 if( !blDealt )
1655 {
1656 for(unsigned i = 0; i<XtNumber(graphWidgetItems); ++i)
1657 {
1658 if(strcasecmp(strTemp, graphWidgetItems[i])==0)
1659 {
1660 readAString(buffer, aString);
1661 strrighttrim(aString);
1662 strlefttrim(aString);
1663 const char *aNewString = aString.c_str();
1664 options[i] = (strcasecmp(aNewString,"Yes")==0) ? true : false;
1665 blDealt = true;
1666 break;
1667 }
1668 }
1669 }
1670
1671 if( !blDealt )
1672 {
1673 for(unsigned i = 0; i<XtNumber(blWidgetName); ++i)
1674 {
1675 if(strcasecmp(strTemp, blWidgetName[i])==0)
1676 {
1677 readAString(buffer, aString);
1678 strrighttrim(aString);
1679 strlefttrim(aString);
1680 const char *aNewString = aString.c_str();
1681 switch(i) {
1682 case 0:
1683 setShow3DSol = (strcasecmp(aNewString,"Yes")==0);
1684 setShow3DBif = setShow3DSol;
1685 break;
1686 case 1:
1687 setShow3DBif = (strcasecmp(aNewString,"Yes")==0);
1688 break;
1689 case 2:
1690 setShow3DSol = (strcasecmp(aNewString,"Yes")==0);
1691 break;
1692 case 3:
1693 blDrawTicker = (strcasecmp(aNewString,"Yes")==0);
1694 break;
1695 case 4:
1696 useR3B = (strcasecmp(aNewString,"Yes")==0);
1697 break;
1698 }
1699 blDealt = true;
1700 break;
1701 }
1702 }
1703 }
1704
1705 if( !blDealt )
1706 {
1707 for(unsigned i = 0; i < XtNumber(intVariableNames) && (!blDealt); ++i)
1708 {
1709 if(strcasecmp(strTemp, intVariableNames[i])==0)
1710 {
1711 switch (i)
1712 {
1713 case 0:
1714 buffer >> whichType;
1715 break;
1716 case 1:
1717 buffer >> whichStyle;
1718 break;
1719 case 2:
1720 buffer >> winWidth;
1721 break;
1722 case 3:
1723 buffer >> winHeight;
1724 break;
1725 case 4:
1726 buffer >> coloringMethodType[BIFURCATION];
1727 coloringMethodType[SOLUTION] =
1728 coloringMethodType[BIFURCATION];
1729 break;
1730 case 5:
1731 buffer >> coloringMethodType[SOLUTION];
1732 break;
1733 case 6:
1734 buffer >> coloringMethodType[BIFURCATION];
1735 break;
1736 case 7:
1737 buffer >> lineWidthScaler;
1738 break;
1739 case 8:
1740 buffer >> aniLineScaler;
1741 break;
1742 case 9:
1743 buffer >> satSpeed;
1744 satSpeed /= 100.0;
1745 break;
1746 case 10:
1747 buffer >> MAX_SAT_SPEED;
1748 break;
1749 case 11:
1750 buffer >> MIN_SAT_SPEED;
1751 break;
1752 case 12:
1753 buffer >> orbitSpeed;
1754 orbitSpeed /= 50.0;
1755 break;
1756 case 13:
1757 buffer >> MAX_ORBIT_SPEED;
1758 break;
1759 case 14:
1760 buffer >> MIN_ORBIT_SPEED;
1761 break;
1762 case 15:
1763 buffer >> whichCoord;
1764 break;
1765 case 16:
1766 buffer >> bgTransparency;
1767 break;
1768 case 17:
1769 buffer >> numPeriodAnimated;
1770 break;
1771 case 18:
1772 buffer >> labelRadius;
1773 break;
1774 case 19:
1775 {
1776 readNData(buffer, diskRotation, 4);
1777 break;
1778 }
1779 case 20:
1780 {
1781 readNData(buffer, diskPosition, 3);
1782 break;
1783 }
1784 case 21:
1785 buffer >> diskRadius;
1786 break;
1787 case 22:
1788 buffer >> diskHeight;
1789 break;
1790 case 23:
1791 buffer >> diskTransparency;
1792 break;
1793 case 24:
1794 readAString(buffer, aString);
1795 strrighttrim(aString);
1796 strlefttrim(aString);
1797 diskFromFile = (strcasecmp(aString.c_str(),"Yes")==0) ? true : false;
1798 break;
1799 case 25:
1800 {
1801 readNData(buffer, spherePosition, 3);
1802 break;
1803 }
1804 case 26:
1805 buffer >> sphereRadius;
1806 break;
1807 case 27:
1808 buffer >> sphereTransparency;
1809 break;
1810 case 28:
1811 readAString(buffer, aString);
1812 strrighttrim(aString);
1813 strlefttrim(aString);
1814 sphereFromFile = (strcasecmp(aString.c_str(),"Yes")==0) ? true : false;
1815 break;
1816 case 29:
1817 buffer >> satRadius;
1818 break;
1819 case 30:
1820 buffer >> largePrimRadius;
1821 break;
1822 case 31:
1823 buffer >> smallPrimRadius;
1824 break;
1825 case 32:
1826 buffer >> libPtScaler;
1827 break;
1828 case 33:
1829 buffer >> whichCoordSystem;
1830 break;
1831 case 34:
1832 buffer >> numOfStars;
1833 break;
1834 }
1835
1836 blDealt = true;
1837 break;
1838 }
1839 }
1840 }
1841
1842 if( !blDealt )
1843 {
1844 for(int i = 0; i<2; ++i)
1845 {
1846 if(strcasecmp(strTemp, hexdecimalVarNames[i])==0)
1847 {
1848 readAHexdecimal(buffer, aHex);
1849 stabilityLinePattern[i] = aHex;
1850
1851 blDealt = true;
1852 break;
1853 }
1854 }
1855 }
1856
1857 if( !blDealt)
1858 {
1859 float colors[3];
1860 for(unsigned i = 0; i<XtNumber(nDataVarNames); ++i)
1861 {
1862 if(strcasecmp(strTemp, nDataVarNames[i])==0)
1863 {
1864 readNData(buffer, colors, 3);
1865 for(int j=0; j<3; ++j) envColors[i][j]=colors[j];
1866 blDealt = true;
1867 break;
1868 }
1869 }
1870 }
1871
1872 if(!blDealt && strcasecmp(strTemp, "parameter ID")==0)
1873 {
1874 std::queue<int> parIDs;
1875 readNData(buffer, parIDs);
1876 mySolNode->set_parID(parIDs);
1877 blDealt = true;
1878 }
1879
1880 //---------------------- Begin ---------------------------OCT 7, 04
1881
1882 if(!blDealt && strcasecmp(strTemp, "Labels")==0)
1883 {
1884 std::queue <int> lblIdx;
1885 readNData(buffer, lblIdx);
1886 blDealt = true;
1887 lblChoice.clear();
1888 while(!lblIdx.empty())
1889 {
1890 lblChoice.push_back(lblIdx.front() - 1);
1891 lblIdx.pop();
1892 }
1893 }
1894
1895 //----------------------- End ---------------------------OCT 7, 04
1896
1897 if(!blDealt)
1898 {
1899 for(unsigned i = 0; i < XtNumber(axesNames) && (!blDealt); ++i)
1900 {
1901 if(strcasecmp(strTemp, axesNames[i]) == 0)
1902 {
1903 std::queue<int> pars;
1904 readNData(buffer, pars);
1905 int size = pars.size();
1906 blDealt = true;
1907 std::vector<int> *xyz = 0;
1908 switch ( i )
1909 {
1910 case 0:
1911 xyz = &dai.solX;
1912 break;
1913 case 1:
1914 xyz = &dai.solY;
1915 break;
1916 case 2:
1917 xyz = &dai.solZ;
1918 break;
1919 case 3:
1920 xyz = &dai.bifX;
1921 break;
1922 case 4:
1923 xyz = &dai.bifY;
1924 break;
1925 case 5:
1926 xyz = &dai.bifZ;
1927 break;
1928 }
1929 xyz->clear();
1930 for(int is=0; is<size; ++is)
1931 {
1932 xyz->push_back(pars.front());
1933 pars.pop();
1934 }
1935 }
1936 }
1937 }
1938 }
1939 }
1940 if( whichType != BIFURCATION )
1941 {
1942 setShow3D = setShow3DSol;
1943 }
1944 else
1945 {
1946 setShow3D = setShow3DBif;
1947 }
1948 coloringMethod = coloringMethodType[whichType];
1949 return state;
1950 }
1951
1952
1953 /////////////////////////////////////////////////////////////////////
1954 //
1955 // Set initial values for those temp variables according to
1956 // their correspondent variables.
1957 //
1958 static void
1959 initTempVariables()
1960 //
1961 /////////////////////////////////////////////////////////////////////
1962 {
1963 graphWidgetToggleSet = 0;
1964 for(unsigned i = 0; i<XtNumber (graphWidgetItems); ++i)
1965 {
1966 if(options[i]) graphWidgetToggleSet |= (1 << i);
1967 optionsOld[i] = options[i];
1968 optionsTemp[i] = options[i];
1969 }
1970
1971 graphWidgetToggleSetTemp = graphWidgetToggleSet;
1972 graphWidgetToggleSetOld = graphWidgetToggleSet;
1973
1974 whichTypeTemp = whichType;
1975 whichTypeOld = whichType;
1976
1977 whichStyleTemp = whichStyle;
1978 whichStyleOld = whichStyle;
1979
1980 whichCoordSystemTemp = whichCoordSystem;
1981 whichCoordSystemOld = whichCoordSystem ;
1982
1983 for(int i=0; i<NUM_SP_POINTS; ++i)
1984 {
1985 linePatternTemp[i] = linePattern[i];
1986 linePatternOld[i] = linePattern[i];
1987 for(int j=0; j<3; ++j)
1988 lineColorOld[i][j] = lineColor[i][j];
1989 }
1990
1991 }
1992
1993
1994 /////////////////////////////////////////////////////////////////////
1995 //
1996 // Set default values for the base variables. These variable includes
1997 // lineColor, line pattern for each solution, the coordinate system,
1998 // the graph style, the graph type, orbit animation speed, sattelite
1999 // animation speed.
2000 //
2001 static void
2002 setVariableDefaultValues()
2003 //
2004 /////////////////////////////////////////////////////////////////////
2005 {
2006 winWidth = WIN_WIDTH;
2007 winHeight = WIN_HEIGHT;
2008
2009 static const float linecolor[][3] = {
2010 {1.0, 1.0, 1.0}, {1.0, 0.0, 0.0}, {0.0, 1.0, 0.0}, {0.0, 0.0, 1.0},
2011 {1.0, 1.0, 0.0}, {0.5, 0.5, 0.0}, {0.0, 0.0, 0.5}, {0.0, 0.5, 0.5},
2012 {1.0, 0.0, 1.0}, {0.0, 1.0, 0.0}, {0.3, 0.0, 0.3}, {0.6, 0.0, 0.6},
2013 {1.0, 1.0, 1.0} };
2014
2015 static const float envcolors[][3] = {
2016 {0.0, 0.0, 0.0}, {1.0, 0.0, 0.0}, {0.0, 1.0, 0.0}, {0.0, 0.0, 1.0},
2017 {0.0, 1.0, 0.0}, {1.0, 0.0, 0.0}, {0.0, 0.0, 1.0}, {1.0, 0.0, 0.0},
2018 {0.0, 1.0, 0.0}, {1.0, 0.0, 0.0}, {0.0, 0.0, 1.0}, {1.0, 0.0, 1.0}
2019 };
2020
2021 for(unsigned i = 0; i < sizeof(envcolors)/sizeof(envcolors[0]); ++i)
2022 envColors[i] = SbColor(envcolors[i]);
2023
2024 for(int i=0; i<NUM_SP_POINTS; ++i) {
2025 lineColor[i] = SbColor(linecolor[i]);
2026 linePattern[i] = 0xffff;
2027 }
2028
2029 stabilityLinePattern[0] = 0x1111;
2030 stabilityLinePattern[1] = 0xffff;
2031
2032 // set options.
2033 for(unsigned i = 0; i < sizeof(options); ++i)
2034 options[i] = false;
2035
2036 if(!useR3B)
2037 options[OPT_NORMALIZE_DATA] = true;
2038
2039 // set default graph type/style specification
2040 whichCoordSystem = ROTATING_F;
2041 whichStyle = 0;
2042 if(useR3B)
2043 {
2044 whichCoord = 3;
2045 blDrawTicker = true;
2046 }
2047 whichType = SOLUTION;
2048
2049 lblIndices.push_back(0);
2050
2051 if (useR3B)
2052 {
2053 dai.solX.push_back(1);
2054 dai.solY.push_back(2);
2055 dai.solZ.push_back(3);
2056 dai.bifX.push_back(4);
2057 dai.bifY.push_back(5);
2058 dai.bifZ.push_back(6);
2059 setShow3D = true;
2060 satSpeed = 1.0;
2061 coloringMethod = CL_STABILITY;
2062 largePrimRadius = 1.0;
2063 smallPrimRadius = 1.0;
2064 blMassDependantOption = false;
2065 intVariableNames[9] = "Sat Animation Speed";
2066 intVariableNames[10] = "Sat Max Animation Speed";
2067 intVariableNames[11] = "Sat Min Animation Speed";
2068 intVariableNames[29] = "Satellite Radius";
2069 nDataVarNames[7] = "satellite Color";
2070 graphWidgetItems[OPT_PERIOD_ANI] = "Orbit Animation";
2071 graphWidgetItems[OPT_SAT_ANI] = "Satellite Animation";
2072 }
2073 else {
2074 dai.solX.push_back(0);
2075 dai.solY.push_back(1);
2076 dai.solZ.push_back(2);
2077
2078 dai.bifX.push_back(0);
2079 dai.bifY.push_back(1);
2080 dai.bifZ.push_back(2);
2081 setShow3D = false;
2082 satSpeed = 0.5;
2083 coloringMethod = CL_COMPONENT;
2084 }
2085 animationLabel = MY_ALL;
2086 orbitSpeed = 1.0;
2087 lineWidthScaler = 1.0;
2088 labelRadius = 1.0;
2089 numPeriodAnimated = 1.0;
2090
2091 satRadius = 1.0;
2092
2093 std::queue<int> parIDs;
2094 parIDs.push(10);
2095 mySolNode->set_parID(parIDs);
2096
2097 setShow3DSol = setShow3D;
2098 setShow3DBif = setShow3D;
2099 coloringMethodType[SOLUTION] = coloringMethodType[BIFURCATION] =
2100 coloringMethod;
2101
2102 if((autoDir=getenv("AUTO_DIR")) == NULL)
2103 autoDir=(char *)".";
2104 }
2105
2106
2107 ////////////////////////////////////////////////////////////////////////
2108 //
2109 // main - init Inventor and Xt, set up a scene graph and the main window,
2110 // display this window, and loop forever...
2111 //
2112 int
2113 main(int argc, char *argv[])
2114 //
2115 ////////////////////////////////////////////////////////////////////////
2116 {
2117 // usage:
2118 // drawme --- using the default file with name "s.text" as input file.
2119 // drawme mu fileName --- using 'fileName' as input, file1 must be a AUTO s file.
2120
2121 // NOTE
2122 // if the s.xxx file does exist, the mass read from it will be used to substitue
2123 // that from the command line
2124 // even there are different. Because sometime the command line input mu may be
2125 // not as accurate as the one read from the s.xxx file
2126 // so the mu read from command line is not important in general. It can be used
2127 // only if the s.xxx file does not exist or the system fails to read it.
2128
2129 char **pargv = argv;
2130 char *dir = 0;
2131 int argcleft = argc - 1;
2132 std::string sFileName, bFileName, dFileName;
2133
2134 if( argcleft > 0 )
2135 {
2136 pargv = &argv[1];
2137
2138 if( strcmp(*pargv, "-r3b")==0 )
2139 {
2140 useR3B = true;
2141 pargv++;
2142 argcleft--;
2143 }
2144 }
2145 if( argcleft > 0 )
2146 {
2147 bool is97 = false;
2148
2149 if( argcleft > 1 && strcmp(*pargv, "97")==0 )
2150 {
2151 is97 = true;
2152 pargv++;
2153 argcleft--;
2154 }
2155 if( argcleft > 1)
2156 {
2157 sFileName = *pargv;
2158 bFileName = *pargv;
2159 dFileName = *pargv;
2160 dir = *pargv;
2161 pargv++;
2162 argcleft--;
2163 sFileName += "/";
2164 bFileName += "/";
2165 dFileName += "/";
2166 }
2167 if ( is97 )
2168 {
2169 sFileName += "q.";
2170 bFileName += "p.";
2171 dFileName += "d.";
2172 }
2173 else
2174 {
2175 sFileName += "s.";
2176 bFileName += "b.";
2177 dFileName += "d.";
2178 }
2179 sFileName += *pargv;
2180 bFileName += *pargv;
2181 dFileName += *pargv;
2182 argcleft--;
2183 }
2184 else
2185 {
2186 sFileName = "fort.8";
2187 bFileName = "fort.7";
2188 dFileName = "fort.9";
2189 }
2190 if( argcleft > 0)
2191 {
2192 if(!useR3B)
2193 printf(" usage: plaut04 [version] [path] [name]\n");
2194 else
2195 printf(" usage: r3bplaut04 [path] [name]\n");
2196 printf(" For example:\n");
2197 if(!useR3B)
2198 {
2199 printf(" plaut04 --- view the fort.7, fort.8 in the current directory \n");
2200 printf(" plaut04 H1 --- view s.H1, b.H1 in the current directory \n");
2201 printf(" plaut04 /home/he/myR3B/me H1 --- view s.H1, b.H1 in the /home/he/myR3B/me directory \n");
2202 printf(" plaut04 97 H1 --- view AUTO 97 files: q.H1, p.H1 in the current directory \n");
2203 printf(" plaut04 97 /home/he/myR3B/me H1 --- view AUTO 97 files: q.H1, p.H1 in the /home/he/myR3B/me directory \n");
2204 }
2205 else
2206 {
2207 printf(" r3bplaut04 --- view the fort.7, fort.8 in the current directory \n");
2208 printf(" r3bplaut04 H1 --- view s.H1, b.H1 in the current directory \n");
2209 printf(" r3bplaut04 /home/he/myR3B/me H1 --- view s.H1, b.H1 in the /home/he/myR3B/me directory \n");
2210 printf(" r3bplaut04 97 H1 --- view AUTO 97 files: q.H1, p.H1 in the current directory \n");
2211 printf(" r3bplaut04 97 /home/he/myR3B/me H1 --- view AUTO 97 files: q.H1, p.H1 in the /home/he/myR3B/me directory \n");
2212 }
2213 exit(1) ;
2214 }
2215
2216 mySolNode = new Solution;
2217 myBifNode = new Bifurcation;
2218
2219 setVariableDefaultValues();
2220
2221 readResourceParameters(dir);
2222
2223 readSolutionAndBifurcationData(true, sFileName, bFileName, dFileName);
2224
2225 initCoordAndLableListItems();
2226 initTempVariables();
2227
2228 soxtmain(argc,argv);
2229
2230 return 0;
2231 }
2232
2233
2234 //////////////////////////////////////////////////////////////////////////
2235 //
2236 void
2237 postDeals()
2238 //
2239 //////////////////////////////////////////////////////////////////////////
2240 {
2241 mySolNode->dealloc();
2242 myBifNode->dealloc();
2243
2244 delete [] clientData.multipliers;
2245 delete [] clientData.numFM;
2246 delete [] clientData.solMax;
2247 delete [] clientData.solMin;
2248
2249 delete [] myLabels;
2250 delete [] clientData.labelIndex;
2251 }
2252
2253
2254 //////////////////////////////////////////////////////////////////////////
2255 //
2256 int
2257 writePreferValuesToFile()
2258 //
2259 //////////////////////////////////////////////////////////////////////////
2260 {
2261 int state = 0;
2262
2263 FILE * outFile;
2264 if(!useR3B)
2265 outFile = fopen("plaut04.rc.out", "w");
2266 else
2267 outFile = fopen("r3bplaut04.rc.out", "w");
2268
2269 if (!outFile)
2270 {
2271 if(!useR3B)
2272 printf("Unable to open the resource file. I will use the default values.\n");
2273 else
2274 printf("Unable to open the resource file.\n");
2275 state = 1;
2276 return state;
2277 }
2278
2279 // write header
2280 fprintf(outFile,"#version 0.0\n\n");
2281 fprintf(outFile,"# Line colors are represented by RGB values from 0 to 1.0.\n");
2282 fprintf(outFile,"# DEFAULT color is also used when animationLabel == MY_ALL, i.e.,\n");
2283 fprintf(outFile,"# when showing all solutions and highlighting the solutions changes.\n");
2284 fprintf(outFile,"# Point Type RED GREEN BLUE\n");
2285
2286 // write line color and pattern
2287 for(int i = 0; i<NUM_SP_POINTS; ++i)
2288 {
2289 fprintf(outFile,"%-15.15s = %3.1f, %3.1f, %3.1f, 0x%lx\n",typeTokenNames[i],
2290 lineColor[i][0], lineColor[i][1],lineColor[i][2],linePattern[i]);
2291 }
2292
2293 fprintf(outFile, "\n# Initialize the line pattern for showing stability:\n");
2294 for(int i = 0; i<2; ++i)
2295 {
2296 fprintf(outFile,"%-21.21s = 0x%lx\n", hexdecimalVarNames[i], stabilityLinePattern[i]);
2297 }
2298
2299 fprintf(outFile, "\n# Initialize the default options:\n");
2300 for(unsigned i = 0; i<XtNumber(graphWidgetItems); ++i)
2301 {
2302 fprintf(outFile, "%-21.21s = ",graphWidgetItems[i]);
2303 options[i] ? fprintf(outFile, " Yes\n") : fprintf(outFile, " No\n");
2304 }
2305
2306 for(unsigned i = 0; i < XtNumber(intVariableNames); ++i)
2307 {
2308 switch (i)
2309 {
2310 case 0:
2311 // OK
2312 fprintf(outFile, "\n# Initialize the default graph type: \n");
2313 fprintf(outFile, "# 0 --- Solution (fort.8)\n");
2314 fprintf(outFile, "# 1 --- Bifurcation (fort.7)\n");
2315 fprintf(outFile, "%-25.25s = %i\n", intVariableNames[i],whichType);
2316 break;
2317 case 1:
2318 //OK
2319 fprintf(outFile, "\n# Initialize the default graph style:\n");
2320 fprintf(outFile, "# 0 --- LINES, 1 --- TUBES, 2 ---- SURFACE \n");
2321 fprintf(outFile, "%-25.25s = ", intVariableNames[i]);
2322 fprintf(outFile, "%i\n",whichStyle);
2323 break;
2324 case 2:
2325 fprintf(outFile, "\n# Set the window width and height:\n");
2326 fprintf(outFile, "%-25.25s = ", intVariableNames[i]);
2327 fprintf(outFile, "%i\n",winWidth);
2328 break;
2329 case 3:
2330 fprintf(outFile, "%-25.25s = ", intVariableNames[i]);
2331 fprintf(outFile, "%i\n",winHeight);
2332 break;
2333 case 4:
2334 fprintf(outFile, "\n# Set coloring method.\n");
2335 fprintf(outFile, "# -7 --- BRANCH\n");
2336 fprintf(outFile, "# -6 --- STABILITY\n");
2337 fprintf(outFile, "# -5 --- POINT\n");
2338 fprintf(outFile, "# -4 --- CURVE\n");
2339 fprintf(outFile, "# -3 --- TYPE\n");
2340 fprintf(outFile, "# -2 --- LABEL\n");
2341 fprintf(outFile, "# -1 --- COMPONENT\n");
2342 fprintf(outFile, "# Otherwise, according to the data in the ith column of the solution file.\n");
2343 fprintf(outFile, "# It can only be set to an integer value.\n");
2344 break;
2345 case 5:
2346 fprintf(outFile, "# For the solution diagram:\n");
2347 fprintf(outFile, "%-25.25s = ", intVariableNames[i]);
2348 fprintf(outFile, "%i\n", coloringMethodType[SOLUTION]);
2349 break;
2350 case 6:
2351 fprintf(outFile, "# For the bifurcation diagram:\n");
2352 fprintf(outFile, "%-27.27s = ", intVariableNames[i]);
2353 fprintf(outFile, "%i\n", coloringMethodType[BIFURCATION]);
2354 break;
2355 case 7:
2356 fprintf(outFile, "\n# Line Width Scaler adjusts the thickness of curves:\n");
2357 fprintf(outFile, "%-25.25s = ", intVariableNames[i]);
2358 fprintf(outFile, "%4.1f\n", lineWidthScaler);
2359 break;
2360 case 8:
2361 fprintf(outFile, "\n# The AniLine Thickness Scaler sets the thickness of animated solution curves:\n");
2362 fprintf(outFile, "%-25.25s = ", intVariableNames[i]);
2363 fprintf(outFile, "%4.1f\n", aniLineScaler);
2364 break;
2365 case 9:
2366 fprintf(outFile, "\n# Set the initial, maximum and minimum animation speed:\n");
2367 fprintf(outFile, "%-25.25s = ", intVariableNames[i]);
2368 fprintf(outFile, "%i\n", (int)floor(satSpeed*100+0.5));
2369 case 10:
2370 fprintf(outFile, "%-25.25s = ", intVariableNames[i]);
2371 fprintf(outFile, "%i\n", MAX_SAT_SPEED);
2372 break;
2373 case 11:
2374 fprintf(outFile, "%-25.25s = ", intVariableNames[i]);
2375 fprintf(outFile, "%i\n", MIN_SAT_SPEED);
2376 break;
2377 case 12:
2378 fprintf(outFile, "\n# Set the initial, maximum and minimum highlighting animation speed:\n");
2379 fprintf(outFile, "%-25.25s = ", intVariableNames[i]);
2380 fprintf(outFile, "%i\n", (int)floor(orbitSpeed*50+0.5));
2381 case 13:
2382 fprintf(outFile, "%-25.25s = ", intVariableNames[i]);
2383 fprintf(outFile, "%i\n", MAX_ORBIT_SPEED);
2384 break;
2385 case 14:
2386 fprintf(outFile, "%-25.25s = ", intVariableNames[i]);
2387 fprintf(outFile, "%i\n", MIN_ORBIT_SPEED);
2388 break;
2389 case 15:
2390 fprintf(outFile, "\n# Initialize the default coordinate axes:\n");
2391 fprintf(outFile, "# 0 --- None,\n");
2392 fprintf(outFile, "# 1 --- at geometry center or origin,\n");
2393 fprintf(outFile, "# 2 --- at left and behind,\n");
2394 fprintf(outFile, "# 3 --- at left and ahead. \n");
2395 fprintf(outFile, "# 4 --- always at origin. \n");
2396 fprintf(outFile, "%-25.25s = ", intVariableNames[i]);
2397 fprintf(outFile, "%i\n", whichCoord);
2398 break;
2399 case 16:
2400 fprintf(outFile, "\n# Background pictures transparency");
2401 fprintf(outFile, "\n# [0.0, 1.0] \n");
2402 fprintf(outFile, "%-25.25s = ", intVariableNames[i]);
2403 fprintf(outFile, "%4.1f\n", bgTransparency );
2404 break;
2405 case 17:
2406 if(useR3B)
2407 {
2408 fprintf(outFile, "\n# Set default number of periods animated\n");
2409 fprintf(outFile, "\n# The value should be power of 2.\n");
2410 }
2411 else
2412 fprintf(outFile, "\n# set default number of periods showing in inertial frame\n");
2413 fprintf(outFile, "%-25.25s = ", intVariableNames[i]);
2414 fprintf(outFile, "%f\n", numPeriodAnimated);
2415 break;
2416 case 18:
2417 fprintf(outFile, "\n# Set the radius of the spheres used for labels:\n");
2418 fprintf(outFile, "# The normal size is 1.0.\n");
2419 fprintf(outFile, "# For smaller radius, use 0.xxx\n");
2420 fprintf(outFile, "# For bigger radius, use X.XXX\n");
2421 fprintf(outFile, "%-25.25s = ", intVariableNames[i]);
2422 fprintf(outFile, "%4.1f\n", labelRadius);
2423 break;
2424 case 19:
2425 fprintf(outFile, "\n# Disk Rotation\n");
2426 fprintf(outFile, "%-25.25s = ", intVariableNames[i]);
2427 fprintf(outFile, "%f, %f, %f, %f\n", diskRotation[0],
2428 diskRotation[1], diskRotation[2], diskRotation[3] );
2429 break;
2430 case 20:
2431 fprintf(outFile, "\n# Disk Position\n");
2432 fprintf(outFile, "%-25.25s = ", intVariableNames[i]);
2433 fprintf(outFile, "%f, %f, %f\n", diskPosition[0],
2434 diskPosition[1], diskPosition[2] );
2435 break;
2436 case 21:
2437 fprintf(outFile, "\n# Disk Radius\n");
2438 fprintf(outFile, "%-25.25s = ", intVariableNames[i]);
2439 fprintf(outFile, "%f\n", diskRadius );
2440 break;
2441 case 22:
2442 fprintf(outFile, "\n# Disk Height\n");
2443 fprintf(outFile, "%-25.25s = ", intVariableNames[i]);
2444 fprintf(outFile, "%f\n", diskHeight );
2445 break;
2446 case 23:
2447 fprintf(outFile, "\n# Disk Transparency [0, 1] \n");
2448 fprintf(outFile, "%-25.25s = ", intVariableNames[i]);
2449 fprintf(outFile, "%4.1f\n", diskTransparency );
2450 break;
2451 case 24:
2452 fprintf(outFile, "\n# Read Disk From File \n");
2453 fprintf(outFile, "%-25.25s = ", intVariableNames[i]);
2454 (diskFromFile) ? fprintf(outFile, "Yes \n"): fprintf(outFile, "No\n");
2455 break;
2456 case 25:
2457 fprintf(outFile, "\n# Sphere Position\n");
2458 fprintf(outFile, "%-25.25s = ", intVariableNames[i]);
2459 fprintf(outFile, "%f, %f, %f\n", spherePosition[0],
2460 spherePosition[1], spherePosition[2] );
2461 break;
2462 case 26:
2463 fprintf(outFile, "\n# Sphere Radius\n");
2464 fprintf(outFile, "%-25.25s = ", intVariableNames[i]);
2465 fprintf(outFile, "%f\n", sphereRadius );
2466 break;
2467 case 27:
2468 fprintf(outFile, "\n# Sphere Transparency [0, 1] \n");
2469 fprintf(outFile, "%-25.25s = ", intVariableNames[i]);
2470 fprintf(outFile, "%4.1f\n", sphereTransparency );
2471 break;
2472 case 28:
2473 fprintf(outFile, "\n# Read Sphere From File \n");
2474 fprintf(outFile, "%-25.25s = ", intVariableNames[i]);
2475 (sphereFromFile) ? fprintf(outFile, "Yes \n"): fprintf(outFile, "No\n");
2476 break;
2477 case 29:
2478 if(useR3B)
2479 fprintf(outFile, "\n# set the radius of satellite, large primary, small primary\n");
2480 else
2481 fprintf(outFile, "\n# Set the radius of the animation object:\n");
2482 fprintf(outFile, "%-25.25s = ", intVariableNames[i]);
2483 fprintf(outFile, "%4.1f\n", satRadius);
2484 break;
2485 case 30:
2486 fprintf(outFile, "%-25.25s = ", intVariableNames[i]);
2487 fprintf(outFile, "%4.1f\n", largePrimRadius);
2488 break;
2489 case 31:
2490 fprintf(outFile, "%-25.25s = ", intVariableNames[i]);
2491 fprintf(outFile, "%4.1f\n", smallPrimRadius);
2492 break;
2493 case 32:
2494 fprintf(outFile, "%s = ", intVariableNames[i]);
2495 fprintf(outFile, "%f\n", libPtScaler);
2496 break;
2497 case 33:
2498 fprintf(outFile, "\n# initialize the default coordinate system");
2499 fprintf(outFile, "\n# 0 --- Rotating, 1 --- inertial Bary Centered,");
2500 fprintf(outFile, "\n# 2 --- Big Primary Centered, 3 --- Small Primary Centered\n");
2501 fprintf(outFile, "%-25.25s = ", intVariableNames[i]);
2502 fprintf(outFile, "%i\n",whichCoordSystem);
2503 break;
2504 case 34:
2505 fprintf(outFile, "%-25.25s = ", intVariableNames[i]);
2506 fprintf(outFile, "%d\n", numOfStars);
2507 break;
2508 }
2509 }
2510
2511 for(unsigned i = 0; i<XtNumber(nDataVarNames); ++i)
2512 {
2513 switch ( i ){
2514 case 0 :
2515 fprintf(outFile, "# Background color:\n");
2516 break;
2517 case 1 :
2518 fprintf(outFile, "# X-Axis color:\n");
2519 break;
2520 case 2 :
2521 fprintf(outFile, "# Y-Axis color:\n");
2522 break;
2523 case 3 :
2524 fprintf(outFile, "# Z-Axis color:\n");
2525 break;
2526 case 4 :
2527 fprintf(outFile, "# Surface color:\n");
2528 break;
2529 case 5 :
2530 fprintf(outFile, "# Unstable solution Color:\n");
2531 break;
2532 case 6 :
2533 fprintf(outFile, "# Stable solution Color:\n");
2534 break;
2535 case 7 :
2536 fprintf(outFile,"\n# sat, large prim, large prim line, small prim, small prim line\n");
2537 /* fall though */
2538 case 8 :
2539 case 9 :
2540 case 10 :
2541 case 11 :
2542 fprintf(outFile, "# Color of the animation object:\n");
2543 break;
2544 }
2545
2546 fprintf(outFile, "%-25.25s = %4.1f, %4.1f, %4.1f\n\n",nDataVarNames[i],envColors[i][0], envColors[i][1],envColors[i][2]);
2547 }
2548
2549 //----------Labels --- ?
2550 fprintf(outFile, "# Labeled solutions:\n");
2551 fprintf(outFile, "# -3 = Show all labeled solutions\n");
2552 fprintf(outFile, "# -2 = Show HALF labeled solutions\n");
2553 fprintf(outFile, "# -1 = Show SPEC labeled solutions\n");
2554 fprintf(outFile, "# 0 = Show NONE of the solutions\n");
2555 fprintf(outFile, "# Otherwise, show the specified solution(s)\n");
2556 for(std::vector<int>::size_type is=0; is < (lblChoice[is] < 0 ? 1 : lblIndices.size()); ++is)
2557 {
2558 fprintf(outFile, "Labels = %i", lblChoice[is]+1);
2559 }
2560 fprintf(outFile, "\n");
2561
2562 fprintf(outFile,"\n# Draw Scale:\n");
2563 fprintf(outFile, "Draw Scale = ");
2564 (blDrawTicker) ? fprintf(outFile, " YES \n") : fprintf(outFile, " NO \n");
2565
2566 // deal with parameter IDs
2567 fprintf(outFile,"\n# Set the active AUTO parameter indices:\n");
2568 fprintf(outFile, "parameter ID = ");
2569 for(int is=0; is<mySolNode->npar(); ++is)
2570 {
2571 fprintf(outFile, " %i, ", mySolNode->parID(is));
2572 }
2573 fprintf(outFile, " \n");
2574
2575 // turn 3D/2D
2576 fprintf(outFile,"\n# Choose 3D or 2D graph for the bifurcation diagram:\n");
2577 fprintf(outFile, "3DBif = %s\n", setShow3DBif ? "YES" : "No");
2578 fprintf(outFile,"\n# Choose 3D or 2D graph for the solution diagram:\n");
2579 fprintf(outFile, "3DSol = %s\n", setShow3DSol ? "YES" : "No");
2580
2581 fprintf(outFile,"\n# Set X, Y, Z axes for the solution diagram:\n");
2582 fprintf(outFile,"# 0 is Time for X,Y,Z.\n");
2583 fprintf(outFile,"%-25.25s = ", axesNames[0]);
2584 for(std::vector<int>::size_type is=0; is<dai.solX.size(); ++is)
2585 {
2586 fprintf(outFile, " %i ", dai.solX[is]);
2587 fprintf(outFile, (is != dai.solX.size()-1) ? "," : "\n");
2588 }
2589
2590 fprintf(outFile,"%-25.25s = ", axesNames[1]);
2591 for(std::vector<int>::size_type is=0; is<dai.solY.size(); ++is)
2592 {
2593 fprintf(outFile, " %i ", dai.solY[is]);
2594 fprintf(outFile, (is != dai.solY.size()-1) ? "," : "\n");
2595 }
2596
2597 fprintf(outFile,"%-25.25s = ", axesNames[2]);
2598 for(std::vector<int>::size_type is=0; is<dai.solZ.size(); ++is)
2599 {
2600 fprintf(outFile, " %i ", dai.solZ[is]);
2601 fprintf(outFile, (is != dai.solZ.size()-1) ? "," : "\n");
2602 }
2603
2604 fprintf(outFile,"\n# Set X, Y, Z axes for the bifurcation diagram:\n");
2605 fprintf(outFile,"# 0 is Time for X,Y,Z.\n");
2606 fprintf(outFile,"%-25.25s = ", axesNames[3]);
2607 for(std::vector<int>::size_type is=0; is<dai.bifX.size(); ++is)
2608 {
2609 fprintf(outFile, " %i ", dai.bifX[is]);
2610 fprintf(outFile, (is != dai.bifX.size()-1) ? "," : "\n");
2611 }
2612
2613 fprintf(outFile,"%-25.25s = ", axesNames[4]);
2614 for(std::vector<int>::size_type is=0; is<dai.bifY.size(); ++is)
2615 {
2616 fprintf(outFile, " %i ", dai.bifY[is]);
2617 fprintf(outFile, (is != dai.bifY.size()-1) ? "," : "\n");
2618 }
2619
2620 fprintf(outFile,"%-25.25s = ", axesNames[5]);
2621 for(std::vector<int>::size_type is=0; is<dai.bifZ.size(); ++is)
2622 {
2623 fprintf(outFile, " %i ", dai.bifZ[is]);
2624 fprintf(outFile, (is != dai.bifZ.size()-1) ? "," : "\n");
2625 }
2626
2627 fclose(outFile);
2628 return state;
2629 }
2630
2631 ////////////////////////////////////////////////////////////////////////
2632 //
2633 // detach everything and nuke the existing scene.
2634 //
2635 void
2636 deleteScene()
2637 //
2638 ////////////////////////////////////////////////////////////////////////
2639 {
2640 for (int i = root->getNumChildren(); i>0; i--)
2641 root->removeChild(i-1);
2642 }
2643
2644
2645 ////////////////////////////////////////////////////////////////////////
2646 //
2647 static bool
2648 parseFileName(const char *fname, std::string& sFileName,
2649 std::string& bFileName, std::string& dFileName)
2650 //
2651 ////////////////////////////////////////////////////////////////////////
2652 {
2653 std::stringstream filename(fname);
2654 std::string myPath, myName, path;
2655
2656 while(getline(filename, path, '/'))
2657 {
2658 myPath += "/";
2659 myPath += path;
2660 myName = path;
2661 }
2662
2663 sFileName = myPath;
2664 bFileName = myPath;
2665 dFileName = myPath;
2666
2667 int j = myPath.length();
2668 int i = myName.length();
2669 sFileName[j-i]='s'; sFileName[j-i+1]='.';
2670 bFileName[j-i]='b'; bFileName[j-i+1]='.';
2671 dFileName[j-i]='d'; dFileName[j-i+1]='.';
2672
2673 return true;
2674 }
2675
2676
2677 ////////////////////////////////////////////////////////////////////////
2678 //
2679 // Reads the given file and insert the geometry under the selection
2680 // node. If the node didn't have any children, the viewAll() method is
2681 // automatically called.
2682 //
2683 SbBool
2684 readFile(const char *filename)
2685 //
2686 ////////////////////////////////////////////////////////////////////////
2687 {
2688 SbString errorMessage;
2689 std::string sFileName, bFileName, dFileName;
2690
2691 postDeals();
2692 parseFileName(filename, sFileName, bFileName, dFileName);
2693 bool rs = readSolutionAndBifurcationData(false, sFileName, bFileName,
2694 dFileName);
2695 if(!rs)
2696 {
2697 SoText2 * errMsg = new SoText2;
2698 errMsg->string.setValue(" Open File Error! Maybe it is not a correct AUTO data file. ");
2699 root->addChild(errMsg);
2700 return false;
2701 }
2702 initCoordAndLableListItems();
2703 setListValue();
2704 initTempVariables();
2705
2706 updateScene();
2707
2708 return TRUE;
2709 }
2710
2711
2712 #if 0
2713 /////////////////////////////////////////////////////////////////////////////////
2714 //
2715 static FILE *
2716 convertToInventor(const char *filename)
2717 //
2718 ////////////////////////////////////////////////////////////////////////
2719 {
2720 #define BUFSIZE 512
2721 #define destinationFileType "Inventor2.1File"
2722
2723 char routeprintCmd[BUFSIZE];
2724 char conversionCmd[BUFSIZE];
2725 FILE *pipeFile;
2726 FILE *ivDataPipe = NULL;
2727
2728 sprintf(routeprintCmd, "/usr/sbin/routeprint -d %s %s 2> /dev/null",
2729 destinationFileType, filename);
2730
2731 if (NULL != (pipeFile = popen(routeprintCmd, "r")))
2732 {
2733 (void) fgets(conversionCmd, BUFSIZE, pipeFile);
2734 if (0 != pclose(pipeFile))
2735 {
2736 return ivDataPipe;
2737 }
2738 ivDataPipe = popen(conversionCmd, "r");
2739 }
2740
2741 return ivDataPipe;
2742 }
2743
2744
2745 /////////////////////////////////////////////////////////////////////////////
2746 //
2747 // Read all objects from the given file and return under one separator.
2748 //
2749 SoSeparator *
2750 MyFileRead(const char *filename, SbString &errorMessage)
2751 //
2752 /////////////////////////////////////////////////////////////////////////////
2753 {
2754 SoInput in;
2755 FILE *ivDataPipe = NULL;
2756
2757 if (0 != access(filename, R_OK))
2758 {
2759 errorMessage = "Error opening the file\n\"";
2760 errorMessage += filename;
2761 errorMessage += "\".";
2762 errorMessage += "\n\nThe file is unreadable or does not exist.";
2763 errorMessage += "\nYou may not have read permission on this file.";
2764 return NULL;
2765 }
2766
2767 if (! in.openFile(filename, TRUE))
2768 {
2769 errorMessage = "Error opening the file\n\"";
2770 errorMessage += filename;
2771 errorMessage += "\".";
2772 errorMessage += "\n\nInventor was unable to read that file.";
2773 errorMessage += "\nYou may not have permission to read this file.";
2774 return NULL;
2775 }
2776
2777
2778 if (! in.isValidFile() )
2779 {
2780 if ((ivDataPipe = convertToInventor(filename)) != NULL)
2781 {
2782 in.setFilePointer(ivDataPipe);
2783 }
2784 else
2785 {
2786 errorMessage = "Unable to read the file\n\"";
2787 errorMessage += filename;
2788 errorMessage += "\".";
2789 errorMessage += "\n\nInventor was unable to read that file, and";
2790 errorMessage += "\nthat file could not be translated to Inventor format.\n\n";
2791 errorMessage += "Are you sure that this is a supported filetype?";
2792 errorMessage += "\nYou may not have the proper translators installed,";
2793 errorMessage += "\nor the desktop filetype database may not be built.";
2794 return NULL;
2795 }
2796 }
2797
2798
2799 SoSeparator *sep = SoDB::readAll(&in);
2800
2801 if (sep == NULL)
2802 {
2803 errorMessage = "Inventor encountered an error while reading\n\"";
2804 errorMessage += filename;
2805 errorMessage += "\".";
2806 errorMessage += "\n\nThis may not be a valid Inventor file.";
2807 return NULL;
2808 }
2809
2810 in.closeFile();
2811 if (ivDataPipe != NULL)
2812 {
2813 fclose(ivDataPipe);
2814 }
2815 return sep;
2816 }
2817 #endif
2818