Debian Codegraph @

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

raw
1 /* Allows reading in very large files */
2 #ifndef _LARGEFILE_SOURCE
3 #define _LARGEFILE_SOURCE
4 #endif
5 #ifndef _FILE_OFFSET_BITS
6 #define _FILE_OFFSET_BITS 64
7 #endif
8
9 #include "bifurcation.h"
10
11 #include <stdlib.h>
12 #include <stdio.h>
13
14 #ifdef DEBUG
15 using namespace std;
16 #include <iostream>
17 #endif
18
19 #include "gplaut04.h"
20 #include "createCoords.h"
21 #include "rounding.h"
22 #include "tube.h"
23
24 extern UserData clientData;
25 Bifurcation *myBifNode;
26
27 //////////////////////////////////////////////////////////////////////////
28 //
29 // Routine to create a scene graph representing an auto bifurcation
30 //
31 SoSeparator *
32 Bifurcation::createScene()
33 //
34 //////////////////////////////////////////////////////////////////////////
35 {
36 SoSeparator *result = new SoSeparator;
37 result->ref();
38
39 if(whichCoord != NO_COORD)
40 {
41 SoSeparator * coordSep = new SoSeparator;
42
43 SoTransform * coordXform = new SoTransform;
44 coordXform->rotation.setValue(SbVec3f(1.0, 0.0, 0.0),M_PI_2);
45
46 coordSep->addChild(coordXform);
47 static int tickers[3];
48 if(blDrawTicker)
49 {
50 tickers[0]=tickers[1]=tickers[2]=5;
51 }
52 else
53 {
54 tickers[0]=tickers[1]=tickers[2]=-1;
55 }
56
57 float asMax[3], asMin[3];
58 if(options[OPT_NORMALIZE_DATA])
59 {
60 asMax[0]=max_[0]; asMax[1]=max_[1];asMax[2]=max_[2];
61 asMin[0]=min_[0]; asMin[1]=min_[1];asMin[2]=min_[2];
62 }
63 else
64 {
65 asMax[0] = asMax[1] = asMax[2] = 1;
66 asMin[0] = asMin[1] = asMin[2] = -1;
67 }
68
69 coordSep->addChild(createCoordinates(setShow3D, whichCoord, asMax, asMin, tickers, &envColors[1]));
70
71 result->addChild(coordSep);
72 }
73
74 if(useR3B)
75 result->addChild(createR3BPoints(min_, max_));
76
77 // create bifurcation graph
78 SoSeparator * bifBranchSep = render();
79 result->addChild(bifBranchSep);
80
81 return result;
82 }
83
84 ///////////////////////////////////////////////////////////////////////////
85 //
86 SoSeparator *
87 Bifurcation::drawALabel(int row, float xoffset, long int label)
88 //
89 ///////////////////////////////////////////////////////////////////////////
90 {
91 SoSeparator *result = new SoSeparator;
92 SoTranslation *labelTranslate = new SoTranslation;
93 SoText2 *labelMsg = new SoText2;
94 SoFont *labelFont = new SoFont;
95 labelFont->name.setValue("Helvetica");
96 labelFont->size.setValue(12);
97
98 float xyz[3], firstxyz[3], secondxyz[3];
99 normalizeData(row, xyz);
100
101 //pick a good direction for the label
102 int first = row;
103 int second = row + 1;
104 if (second >= totalNumPoints_)
105 {
106 first--;
107 second--;
108 }
109 if (first < 0) first = 0;
110 float yoffset = xoffset;
111 normalizeData(first, firstxyz);
112 normalizeData(second, secondxyz);
113 if ((secondxyz[1] - firstxyz[1]) * (secondxyz[0] - firstxyz[0]) >= 0)
114 {
115 xoffset = -xoffset;
116 labelMsg->justification = SoText2::RIGHT;
117 }
118 labelTranslate->translation.setValue(xyz[0] + xoffset, xyz[1] + yoffset,
119 xyz[2]);
120 char a[30];
121 sprintf(a, "%ld", label);
122 labelMsg->string.setValue(a);
123 result->addChild(labelTranslate);
124 result->addChild(labelFont);
125 result->addChild(labelMsg);
126 return result;
127 }
128
129
130 //////////////////////////////////////////////////////////////////////////
131 //
132 SoSeparator *
133 Bifurcation::drawLabelPtsInScene()
134 //
135 //////////////////////////////////////////////////////////////////////////
136 {
137 float dis = !options[OPT_NORMALIZE_DATA] ? fabs(std::max(std::max(
138 (max_[0]-min_[0]),
139 (max_[1]-min_[1])),
140 (max_[2]-min_[2]))) : 2.0;
141
142 SoSeparator * result = new SoSeparator;
143 int lbl = myLabels[lblIndices[0]], row = 0;
144 float position[3];
145 int lbType;
146
147 if(lbl == MY_ALL)
148 {
149 for(int k = 0; k < totalLabels_; k++)
150 {
151 SoMaterial *lblMtl;
152 row = clientData.labelIndex[k][1];
153 lbType = clientData.labelIndex[k][2];
154
155 lblMtl = setLabelMaterial(lbType);
156 result->addChild(lblMtl);
157 normalizeData(row, position);
158
159 float size = dis*0.005*labelRadius;
160 size *= lineWidthScaler;
161 result->addChild( drawASphere(position, size));
162 if(options[OPT_LABEL_NUMBERS])
163 result->addChild( drawALabel(row, size, orbits_[k].label));
164 }
165 }
166 else if(lbl != MY_NONE)
167 {
168 for(std::vector<int>::size_type i=0; i<lblIndices.size(); ++i)
169 {
170 SoMaterial *lblMtl;
171
172 int k = lblIndices[i];
173 row = clientData.labelIndex[k][1];
174 lbType = clientData.labelIndex[k][2];
175
176 lblMtl = setLabelMaterial(lbType);
177 result->addChild(lblMtl);
178
179 normalizeData(row, position);
180
181 float size = dis*0.005*labelRadius;
182 size *= lineWidthScaler;
183 result->addChild( drawASphere(position, size));
184 if(options[OPT_LABEL_NUMBERS])
185 result->addChild( drawALabel(row, size, orbits_[k].label));
186 }
187 }
188 return result;
189 }
190
191
192 /////////////////////////////////////////////////////////////////
193 //
194 // Set Material for Labels
195 // This function sets the material(color) for each different
196 // type of labels.
197 //
198 SoMaterial *
199 Bifurcation::setLabelMaterial(int lblType)
200 //
201 /////////////////////////////////////////////////////////////////
202 {
203 SoMaterial *lblMtl = new SoMaterial;
204 lblMtl->transparency = 0.0;
205 switch(lblType)
206 {
207 case 0 :
208 lblMtl->diffuseColor.setValue(lineColor[0]);
209 break;
210 case 1 :
211 lblMtl->diffuseColor.setValue(lineColor[1]);
212 break;
213 case 2 :
214 lblMtl->diffuseColor.setValue(lineColor[2]);
215 break;
216 case 3 :
217 lblMtl->diffuseColor.setValue(lineColor[3]);
218 break;
219 case 4 :
220 lblMtl->diffuseColor.setValue(lineColor[4]);
221 break;
222 case -4 :
223 lblMtl->diffuseColor.setValue(lineColor[5]);
224 break;
225 case 5 :
226 lblMtl->diffuseColor.setValue(lineColor[6]);
227 break;
228 case 6 :
229 lblMtl->diffuseColor.setValue(lineColor[7]);
230 break;
231 case 7 :
232 lblMtl->diffuseColor.setValue(lineColor[8]);
233 break;
234 case 8 :
235 lblMtl->diffuseColor.setValue(lineColor[9]);
236 break;
237 case 9 :
238 lblMtl->diffuseColor.setValue(lineColor[10]);
239 break;
240 case -9 :
241 lblMtl->diffuseColor.setValue(lineColor[11]);
242 break;
243 default :
244 lblMtl->diffuseColor.setValue(lineColor[12]);
245 }
246 return lblMtl;
247 }
248
249
250 /////////////////////////////////////////////////////////////////
251 //
252 SoSeparator *
253 Bifurcation::drawABranchUsingTubes(int iBranch, long int l,
254 long int sumX, float scaler)
255 //
256 //
257 /////////////////////////////////////////////////////////////////
258 {
259 SoSeparator * tSep = new SoSeparator;
260 long int upperlimit = numVerticesEachBranch_[l];
261
262 if(upperlimit <= 1)
263 {
264 return tSep;
265 }
266
267 float (*path)[3] = new float[upperlimit][3];
268 float *colorBase = new float[upperlimit*11];
269 Tube tube;
270
271 for(long int i=0; i<upperlimit; i++)
272 {
273 long int idx = i+sumX;
274 normalizeData(idx, path[i]);
275 if(coloringMethod>=0)
276 for(int k=0; k<11; ++k)
277 colorBase[i*11+k] = data_[idx*nar_ + coloringMethod];
278 else if(coloringMethod==CL_POINT_NUMBER)
279 for(int k=0; k<11; ++k)
280 colorBase[i*11+k] = i;
281 else if(coloringMethod == CL_STABILITY)
282 for(int k=0; k<11; ++k)
283 colorBase[i*11+k] = ptStability_[idx];
284 }
285
286 if(coloringMethod == CL_BRANCH_NUMBER || coloringMethod == CL_CURVE_NUMBER)
287 tSep->addChild(setLineAttributesByBranch(iBranch, 0, scaler));
288 else if(coloringMethod == CL_STABILITY)
289 tSep->addChild(setLineColorBlendingByStability(colorBase, upperlimit*11, 0, scaler));
290 else /* CL_POINT_NUMBER or >= 0 */
291 tSep->addChild(setLineColorBlending(colorBase,
292 upperlimit*11, 0, scaler));
293
294 tube = Tube(upperlimit, path, lineWidthScaler*0.005, 10);
295 tSep->addChild(tube.createTube());
296 delete [] path;
297 delete [] colorBase;
298 return tSep;
299 }
300
301
302 ///////////////////////////////////////////////////////////////////////////
303 //
304 // animate the solution by using lines. This version use less memory
305 // and much faster.
306 //////////////////////////////////////////////////////////////////////////
307 //
308 SoSeparator *
309 Bifurcation::drawABranchUsingLines(int iBranch, long int l, long int si,
310 float scaler)
311 //
312 //////////////////////////////////////////////////////////////////////////
313 {
314 int32_t myint[10];
315
316 SoSeparator * aBranch = new SoSeparator;
317 long int size = numVerticesEachBranch_[l];
318 float *colorBase = new float[size];
319 float (*vertices)[3] = new float[size][3];
320
321 long int curSize = 0;
322
323 int lastStab = ptStability_[si];
324 int curStab = lastStab;
325 long int m = 0;
326 long int idx = si+m;
327 do
328 {
329 lastStab = curStab;
330 normalizeData(idx, vertices[curSize]);
331 if(coloringMethod >= 0)
332 colorBase[curSize] = data_[idx * nar_ + coloringMethod];
333 else if(coloringMethod == CL_POINT_NUMBER)
334 colorBase[curSize] = m;
335 else if(coloringMethod == CL_STABILITY)
336 colorBase[curSize] = ptStability_[idx];
337 m++;
338 idx = si+m;
339 if(m < size)
340 curStab = ptStability_[idx];
341 curSize++;
342 if( (lastStab == curStab || curSize <= 1) && m != size) continue;
343
344 SoCoordinate3 *myCoords = new SoCoordinate3;
345 myCoords->point.setValues(0, curSize, vertices);
346 myint[0]= curSize;
347
348 // define the solution line set
349 SoLineSet *myLine= new SoLineSet;
350 myLine->numVertices.setValues(0, 1, myint);
351
352 if(coloringMethod == CL_BRANCH_NUMBER || coloringMethod == CL_CURVE_NUMBER)
353 aBranch->addChild(setLineAttributesByBranch(iBranch, lastStab, scaler));
354 else if(coloringMethod == CL_STABILITY)
355 aBranch->addChild(setLineColorBlendingByStability(colorBase, curSize, lastStab, scaler));
356 else /* CL_POINT_NUMBER or >= 0 */
357 aBranch->addChild(setLineColorBlending(colorBase, curSize,
358 lastStab, scaler));
359
360 aBranch->addChild(myCoords);
361 aBranch->addChild(myLine);
362
363 curSize = 0;
364 normalizeData(idx-1, vertices[curSize]);
365 if(coloringMethod >= 0)
366 colorBase[curSize] = data_[(idx-1) * nar_ + coloringMethod];
367 else if(coloringMethod == CL_POINT_NUMBER)
368 colorBase[curSize] = m-1;
369 else if(coloringMethod == CL_STABILITY)
370 colorBase[curSize] = ptStability_[idx-1];
371 curSize++;
372 }while( m < size);
373
374 delete [] vertices;
375 delete [] colorBase;
376 return aBranch;
377 }
378
379
380 //////////////////////////////////////////////////////////////////////////
381 // Draw a bif branch using NURBS curve
382 //
383 SoSeparator *
384 Bifurcation::drawABranchUsingNurbsCurve(int iBranch, long int l,
385 long int si, float scaler)
386 //
387 //////////////////////////////////////////////////////////////////////////
388 {
389 int32_t myint[10];
390
391 SoSeparator * aBranch = new SoSeparator;
392 long int size = numVerticesEachBranch_[l];
393 float (*vertices)[3] = new float[size][3];
394 float *colorBase = new float[size];
395 for(long int m=0; m<size; ++m)
396 {
397 long idx = si+m;
398 normalizeData(idx, vertices[m]);
399 if(coloringMethod>=0)
400 colorBase[m] =data_[idx * nar_ + coloringMethod];
401 if(coloringMethod==CL_POINT_NUMBER)
402 colorBase[m] = m;
403 }
404 SoCoordinate3 *myCoords = new SoCoordinate3;
405 myCoords->point.setValues(0, size, vertices);
406 myint[0]= size;
407
408 SoGroup *cvGrp = new SoGroup;
409
410 float * knots = new float[size+4];
411 if(size> 4)
412 {
413 for (int i=0; i<4; ++i) knots[i]=0, knots[i+size]=size-3;
414 for(int i=4; i<size; ++i) knots[i]=i-3;
415 SoNurbsCurve *myCurve = new SoNurbsCurve;
416 myCurve->numControlPoints = size;
417 myCurve->knotVector.setValues(0, size+4, knots);
418 cvGrp->addChild(myCurve);
419 }
420 else
421 {
422 SoLineSet *myLine= new SoLineSet;
423 myLine->numVertices.setValues(0,1,myint);
424 cvGrp->addChild(myLine);
425 }
426
427 if(coloringMethod == CL_BRANCH_NUMBER || coloringMethod == CL_CURVE_NUMBER)
428 aBranch->addChild(setLineAttributesByBranch(iBranch, 0, scaler));
429 else if(coloringMethod == CL_STABILITY)
430 aBranch->addChild(setLineAttributesByStability(0, scaler));
431 else /* CL_POINT_NUMBER or >= 0 */
432 aBranch->addChild(setLineColorBlending(colorBase, size,
433 0, scaler));
434 aBranch->addChild(myCoords);
435 aBranch->addChild(cvGrp);
436
437 delete [] vertices;
438 delete [] colorBase;
439 delete [] knots;
440 return aBranch;
441 }
442
443 #if 0
444 //////////////////////////////////////////////////////////////////////////
445 //
446 // Draw a label interval
447 //
448 SoSeparator *
449 drawABifLabelInterval(long int l, long int si, float scaler, int stability, int type)
450 //
451 //////////////////////////////////////////////////////////////////////////
452 {
453 int32_t myint[10];
454
455 SoSeparator * anInterval = new SoSeparator;
456 long int size = orbits_[l].numVerticesEachLabelInterval;
457 float *colorBase = new float[size];
458 float (*vertices)[3] = new float[size][3];
459 for(int m=0; m<size; m++)
460 {
461 long int idx = si+m;
462 normalizeData(idx, vertices[m]);
463 if(coloringMethod>=0)
464 colorBase[m] =data_[idx * nar_ + coloringMethod];
465 if(coloringMethod==CL_POINT_NUMBER)
466 colorBase[m] = m;
467 }
468 SoCoordinate3 *myCoords = new SoCoordinate3;
469 myCoords->point.setValues(0, size, vertices);
470 myint[0]=size;
471
472 SoLineSet *myLine= new SoLineSet;
473 myLine->numVertices.setValues(0,1,myint);
474
475 if(coloringMethod == CL_STABILITY)
476 anInterval->addChild(setLineAttributesByStability(stability, scaler));
477 else if(coloringMethod == CL_ORBIT_TYPE)
478 anInterval->addChild(setLineAttributesByType(stability, type, scaler));
479 else
480 anInterval->addChild(setLineColorBlending(colorBase, size,
481 stability, scaler));
482
483 anInterval->addChild(myCoords);
484 anInterval->addChild(myLine);
485 delete [] vertices;
486 return anInterval;
487 }
488
489
490 //////////////////////////////////////////////////////////////////////////
491 //
492 // Draw a label interval using NURBS curve
493 //
494 SoSeparator *
495 drawABifLabelIntervalUsingNurbsCurve(long int l,
496 long int si, float scaler, int stability, int type)
497 //
498 //////////////////////////////////////////////////////////////////////////
499 {
500 int32_t myint[10];
501
502 SoSeparator * anInterval = new SoSeparator;
503 float (*vertices)[3];
504 vertices = new float[orbits_[l].numVerticesEachLabelInterval][3];
505 for(int m=0; m<orbits_[l].numVerticesEachLabelInterval; m++)
506 {
507 vertices[m][0]=xyzCoords_[si+m][0];
508 vertices[m][1]=xyzCoords_[si+m][1];
509 vertices[m][2]=xyzCoords_[si+m][2];
510 }
511 SoCoordinate3 *myCoords = new SoCoordinate3;
512 myCoords->point.setValues(0, orbits_[l].numVerticesEachLabelInterval, vertices);
513 myint[0]=orbits_[l].numVerticesEachLabelInterval;
514
515 SoGroup *cvGrp = new SoGroup;
516
517 int number = orbits_[l].numVerticesEachLabelInterval;
518 float * knots = new float[number+4];
519 if(number > 4)
520 {
521 for (int i=0; i<4; ++i) knots[i]=0, knots[i+number]=number-3;
522 for(int i=4; i<number; ++i) knots[i]=i-3;
523 SoNurbsCurve *myCurve = new SoNurbsCurve;
524 myCurve->numControlPoints = number;
525 myCurve->knotVector.setValues(0, number+4, knots);
526 cvGrp->addChild(myCurve);
527 }
528 else
529 {
530 SoLineSet *myLine= new SoLineSet;
531 myLine->numVertices.setValues(0,1,myint);
532 cvGrp->addChild(myLine);
533 }
534
535 anInterval->addChild(setLineAttributesByType(stability, type, scaler));
536 anInterval->addChild(myCoords);
537 anInterval->addChild(cvGrp);
538
539 delete [] vertices;
540 delete [] knots;
541 return anInterval;
542 }
543 #endif
544
545
546 /////////////////////////////////////////////////////////////////
547 //
548 // create bifurcation scene
549 //
550 SoSeparator *
551 Bifurcation::render()
552 //
553 //////////////////////////////////////////////////////////////////////////
554 {
555 SoSeparator *bifSep = new SoSeparator;
556 SoMaterial *bifMtl= new SoMaterial;
557
558 bifMtl->ambientColor.setValue(0.5,0.5,0.5);
559 bifMtl->diffuseColor.setValue(0.9,1.0,0.9);
560 bifMtl->specularColor.setValue(0.0,0.5,0.5);
561 bifMtl->shininess = 0.5;
562 bifMtl->transparency = 0.0;
563
564 SoGroup *bifGroup = new SoGroup;
565
566 if(whichStyle == TUBE )
567 {
568 long int si = 0, k = 0;
569 for(int ka=0; ka<numBranches_; ka++)
570 {
571 bifGroup->addChild(drawABranchUsingTubes(ka, k, si, 1*lineWidthScaler));
572 k = k+1;
573 si += numVerticesEachBranch_[ka];
574 }
575 }
576 else if (whichStyle == NURBS)
577 {
578 long int si = 0, k = 0;
579 for(int ka=0; ka<numBranches_; ka++)
580 {
581 bifGroup->addChild(drawABranchUsingNurbsCurve(ka, k, si, 1*lineWidthScaler));
582 k = k+1;
583 si += numVerticesEachBranch_[ka];
584 }
585
586 }
587 else
588 {
589 long int si = 0, k = 0;
590 for(int ka=0; ka<numBranches_; ka++)
591 {
592 bifGroup->addChild(drawABranchUsingLines(ka, k, si, 1*lineWidthScaler));
593 k = k+1;
594 si += numVerticesEachBranch_[ka];
595 }
596 }
597
598 if(options[OPT_DRAW_LABELS])
599 bifSep->addChild(drawLabelPtsInScene());
600
601 bifSep->addChild(bifMtl);
602 bifSep->addChild(bifGroup);
603
604 return bifSep;
605 }
606
607 ////////////////////////////////////////////////////////////////////////
608 //
609 //
610 //
611 void
612 Bifurcation::copyDataToWorkArray(int varIndices[])
613 //
614 ////////////////////////////////////////////////////////////////////////
615 {
616
617 double mx, mi;
618
619 for(int k=0; k<3; k++)
620 {
621 varIndices_[k] = varIndices[k];
622 for(long int row=0; row<totalNumPoints_; ++row)
623 {
624 if(varIndices[k]>=0)
625 {
626 float dummy = data_[row*nar_ + varIndices[k]];
627
628 if(row==0 || dummy>max_[k])
629 max_[k] = dummy;
630 if(row==0 || dummy<min_[k])
631 min_[k] = dummy;
632 }
633 else if(varIndices[k]<0)
634 {
635 max_[k]= 1;
636 min_[k]=-1;
637 }
638 }
639
640 mx = max_[k];
641 mi =min_[k];
642 rounding(mx, mi);
643 max_[k] = mx;
644 min_[k] = mi;
645 }
646 }
647
648 void
649 Bifurcation::alloc()
650 {
651 ptStability_ = new unsigned char[totalNumPoints_];
652 numVerticesEachBranch_ = new int32_t[numBranches_];
653 branchID_ = new long[numBranches_];
654
655 data_ = new float[totalNumPoints_*nar_];
656 orbits_ = new struct orbit[totalLabels_];
657 }
658
659 void
660 Bifurcation::denormalizePosition(float position[])
661 {
662 for(int k=0; k<3; k++) {
663 float div = (max_[k]-min_[k])/2.0;
664 if( !((max_[k]<=1.0 && max_[k]>0.5 &&
665 min_[k]>=-1.0 && min_[k]<-0.5 )||
666 (div<0.00000001)))
667 {
668 float avg = (max_[k]+min_[k])/2.0;
669 position[k] = position[k]*div+avg;
670 }
671 }
672 }
673
674 /*go to the end of the line*/
675 static void go_to_eol(FILE *f)
676 {
677 int i;
678 do
679 {
680 i = fgetc(f);
681 } while (i != '\n' && i != EOF );
682 }
683
684 ////////////////////////////////////////////////////////////////////////////////
685 //
686 bool
687 Bifurcation::read(const char *bFileName, int varIndices[])
688 //
689 ////////////////////////////////////////////////////////////////////////////////
690 {
691 int branch;
692 FILE * inFile;
693 inFile = fopen(bFileName, "rt");
694 maxndim_ = 0;
695 if(!inFile)
696 {
697 printf(" Cannot open input file: %s\n", bFileName);
698 return false;
699 }
700
701 long int numBranches = 0;
702 long int totalPoints = 0;
703 long int numPtsInThisBranch = 0;
704 int maxColSize = 0;
705 int lb, lbType, lbStability;
706 int totalLabels = 0;
707 int numPtInCurrentInterval = 0;
708 int ndim;
709 long int pt = 1;
710
711 while(fscanf(inFile, "%d", &branch) == 1)
712 {
713 int ic = 0;
714 if(branch == 0) {
715 pt = 1;
716 if(fscanf(inFile, " NDIM=%d", &ndim) == 1 &&
717 ndim > maxndim_)
718 maxndim_ = ndim;
719 go_to_eol(inFile);
720 }
721 else
722 {
723 long int prevpt = pt;
724 fscanf(inFile, "%ld %d %d", &pt, &lbType, &lb);
725 int i = 0;
726 char dummystr[25], c;
727 while (fscanf(inFile,"%24s%c", dummystr, &c) == 2) {
728 data_[totalPoints*nar_+(i++)] = fortranatof(dummystr);
729 if(c=='\n')break;
730 }
731
732 if(abs(pt) == 1 &&
733 // Sometimes the point numbers rotate, like
734 // 9996, 9997, 9998, 9999, 1, 2, ...
735 // -9996, -9997, 1, 0, -1, -2, ... (an AUTO bug)
736 // do not define a new branch if that happens
737 (abs(prevpt) != 9999 && abs(prevpt) != 9997 && abs(prevpt) != 0))
738 {
739 branchID_[numBranches] = branch;
740 if(numBranches>0) {
741 numVerticesEachBranch_[numBranches-1] = numPtsInThisBranch;
742 }
743 ++numBranches;
744 numPtsInThisBranch = 0;
745 }
746 ++numPtsInThisBranch;
747
748 // set the stability of the point
749 if(branch > 0)
750 {
751 lbStability = (pt>0 ? 1 : 2);
752 }
753 else
754 {
755 lbStability = (pt>0 ? 3 : 4);
756 }
757
758 ++numPtInCurrentInterval;
759 if(lb != 0)
760 {
761 orbits_[totalLabels].numVerticesEachLabelInterval = numPtInCurrentInterval;
762 numPtInCurrentInterval = 0;
763 orbits_[totalLabels].label = lb;
764 clientData.labelIndex[totalLabels][1] = totalPoints;
765 clientData.labelIndex[totalLabels][2] = lbType;
766 clientData.labelIndex[totalLabels][3] = lbStability;
767 totalLabels++;
768 }
769
770 maxColSize=(maxColSize>ic) ? maxColSize : ic;
771 ptStability_[totalPoints] = lbStability;
772 ++totalPoints;
773 }
774 }
775
776 if(numBranches>0)
777 numVerticesEachBranch_[numBranches-1] = numPtsInThisBranch;
778
779 #ifdef DEBUG
780 cout <<"======================================"<<endl;
781 cout <<" nar_ : "<<nar_<<endl;
782 cout <<" numBranches_ : "<<numBranches_<<endl;
783 cout <<" totalNumPoints_: "<<totalNumPoints_<<endl;
784 cout <<" ID "<<" numVerticesEachBranch_: "<<endl;
785 for(int xi=0; xi<numBranches_; xi++)
786 cout << xi<<" "<<numVerticesEachBranch_[xi]<<endl;
787 for(int xi=0; xi<totalLabels; xi++)
788 {
789 int xxx = clientData.labelIndex[xi][1];
790 #if 0
791 cout <<"index"<<xi<<" | Num points in : "<<clientData.labelIndex[xi][1]
792 <<" | labelIndex: "<<labels_[xi]<< " | data: "
793 <<data_[xxx-1][0]<<" Type: "<<clientData.labelIndex[xi][2]<<endl;
794 #endif
795 }
796 cout <<"======================================"<<endl;
797
798 #if 0
799 for(int xi=0; xi<220; xi++)
800 cout <<" Index: "<<xi<<" "<<data_[xi][0]<<" "
801 <<data_[xi][1]<<" "<<data_[xi][2]<<endl;
802 #endif
803 cout <<"======================================"<<endl;
804 #endif
805
806 fclose(inFile);
807 return true;
808 }
809
810
811 ////////////////////////////////////////////////////////////////////
812 //
813 bool
814 Bifurcation::parse(const char *bFileName)
815 //
816 ////////////////////////////////////////////////////////////////////
817 {
818 FILE * inFile;
819 totalLabels_ = 0;
820 maxndim_ = 0;
821 inFile = fopen(bFileName, "rt");
822 if(!inFile)
823 {
824 printf(" Cannot open input file: %s\n", bFileName);
825 return false;
826 }
827
828 long int totalPoints = 0;
829 long int numBranches = 0;
830 int maxColSize = 0;
831 int branch;
832 long int pt = 1;
833
834 while(fscanf(inFile, "%d", &branch) == 1)
835 {
836 if(branch != 0)
837 {
838 int lbType, lb;
839 long int prevpt = pt;
840 fscanf(inFile, "%ld %d %d", &pt, &lbType, &lb);
841 if (lb != 0) totalLabels_++;
842 if(abs(pt) == 1 &&
843 // Sometimes the point numbers rotate, like
844 // 9996, 9997, 9998, 9999, 1, 2, ...
845 // -9996, -9997, 1, 0, -1, -2, ... (an AUTO bug)
846 // do not define a new branch if that happens
847 (abs(prevpt) != 9999 && abs(prevpt) != 9997 && abs(prevpt) != 0))
848 numBranches++;
849 char c;
850 int ic = 1;
851 while (fscanf(inFile,"%*s%c", &c) == 1 && c !='\n') ic++;
852 if (ic > maxColSize) maxColSize = ic;
853 ++totalPoints;
854 }
855 else
856 {
857 pt = 1;
858 go_to_eol(inFile);
859 }
860 }
861 nar_ = maxColSize;
862 totalNumPoints_ = totalPoints;
863 numBranches_ = numBranches;
864
865 fclose(inFile);
866 return true;
867 }
868
869 /////////////////////////////////////////////////////////////////////////////////
870 //
871 void
872 Bifurcation::normalizeData(long int idx, float xyzCoords[3])
873 //
874 /////////////////////////////////////////////////////////////////////////////////
875 {
876 for(int k=0; k<3; k++)
877 {
878 if (varIndices_[k] == -1)
879 xyzCoords[k] = 0.0;
880 else
881 xyzCoords[k] = data_[idx*nar_ + varIndices_[k]];
882 }
883 if(!options[OPT_NORMALIZE_DATA]) return;
884 for(int k=0; k<3; k++)
885 {
886 float avg = (max_[k]+min_[k])/2.0;
887 float div = (max_[k]-min_[k])/2.0;
888 if( !((max_[k]<=1.0 && max_[k]>0.5 &&
889 min_[k]>=-1.0 && min_[k]<-0.5 )||
890 (div<0.00000001)))
891 {
892 xyzCoords[k]=(xyzCoords[k]-avg)/div;
893 }
894 }
895 }
896
897 void
898 Bifurcation::dealloc()
899 {
900 delete [] ptStability_;
901 delete [] numVerticesEachBranch_;
902 delete [] branchID_;
903 delete [] data_;
904 delete [] orbits_;
905 }