| 1 |
#include "solution.h" |
| 2 |
|
| 3 |
#include <stdlib.h> |
| 4 |
#include <stdio.h> |
| 5 |
#include <stddef.h> |
| 6 |
#include <ctype.h> |
| 7 |
#include <math.h> |
| 8 |
|
| 9 |
#include "gplaut04.h" |
| 10 |
#include "createCoords.h" |
| 11 |
#include "tube.h" |
| 12 |
#include "rounding.h" |
| 13 |
|
| 14 |
#define MAX_LINE_LENGTH 256 |
| 15 |
|
| 16 |
extern float *tv; |
| 17 |
extern int whichCoordSystem; |
| 18 |
extern UserData clientData; |
| 19 |
|
| 20 |
Solution *mySolNode; |
| 21 |
|
| 22 |
const float STATIONARY_POINT_RADIUS = 0.01; |
| 23 |
|
| 24 |
static int maxComponent = 1; |
| 25 |
static int curComponent = 1; |
| 26 |
static int time_on = 0; |
| 27 |
|
| 28 |
const float distance = 1; |
| 29 |
const float sPrimPeriod = 31558118.4; |
| 30 |
const float gravity = 9.18; |
| 31 |
|
| 32 |
//////////////////////////////////////////////////////////////////// |
| 33 |
//////////////////////////////////////////////////////////////////////// |
| 34 |
// |
| 35 |
// Routine to create a scene graph representing an auto solution |
| 36 |
// |
| 37 |
SoSeparator * |
| 38 |
Solution::createSceneWithWidgets() |
| 39 |
// |
| 40 |
//////////////////////////////////////////////////////////////////// |
| 41 |
//////////////////////////////////////////////////////////////////////// |
| 42 |
{ |
| 43 |
SoSeparator *result = new SoSeparator; |
| 44 |
|
| 45 |
if(options[OPT_NORMALIZE_DATA]) |
| 46 |
{ |
| 47 |
normalizeData(); |
| 48 |
} |
| 49 |
|
| 50 |
if(useR3B) |
| 51 |
result->addChild(createR3BPoints(min_, max_)); |
| 52 |
if(!useR3B || whichCoordSystem == ROTATING_F) |
| 53 |
{ |
| 54 |
if(whichCoord != NO_COORD) |
| 55 |
{ |
| 56 |
SoSeparator * coordSep = new SoSeparator; |
| 57 |
|
| 58 |
SoTransform * coordXform = new SoTransform; |
| 59 |
coordXform->rotation.setValue(SbVec3f(1.0, 0.0, 0.0), M_PI_2); |
| 60 |
|
| 61 |
coordSep->addChild(coordXform); |
| 62 |
static int tickers[3]; |
| 63 |
if(blDrawTicker) |
| 64 |
{ |
| 65 |
tickers[0]=tickers[1]=tickers[2]=5; |
| 66 |
} |
| 67 |
else |
| 68 |
{ |
| 69 |
tickers[0]=tickers[1]=tickers[2]=-1; |
| 70 |
} |
| 71 |
|
| 72 |
float asMax[3], asMin[3]; |
| 73 |
if(options[OPT_NORMALIZE_DATA]) |
| 74 |
{ |
| 75 |
asMin[0]=min_[0]; asMin[1]=min_[1]; asMin[2]=min_[2]; |
| 76 |
asMax[0]=max_[0]; asMax[1]=max_[1]; asMax[2]=max_[2]; |
| 77 |
if (time_on == TIME_ON_X) asMax[0] = 1; |
| 78 |
else if (time_on == TIME_ON_Y) asMax[1] = 1; |
| 79 |
else if (time_on == TIME_ON_Z) asMax[2] = 1; |
| 80 |
} |
| 81 |
else |
| 82 |
{ |
| 83 |
asMax[0] = asMax[1] = asMax[2] = 1; |
| 84 |
asMin[0] = asMin[1] = asMin[2] = -1; |
| 85 |
} |
| 86 |
|
| 87 |
coordSep->addChild(createCoordinates(setShow3D, whichCoord, asMax, asMin, tickers, &envColors[1])); |
| 88 |
result->addChild(coordSep); |
| 89 |
} |
| 90 |
|
| 91 |
// create solution scene |
| 92 |
result->addChild(render()); |
| 93 |
|
| 94 |
} |
| 95 |
return result; |
| 96 |
} |
| 97 |
|
| 98 |
////////////////////////////////////////////////////////////////////////// |
| 99 |
// |
| 100 |
// Description: Draw the whole solution family using TUBES. |
| 101 |
// Draw the whole solution family using TUBES. |
| 102 |
// |
| 103 |
SoSeparator * |
| 104 |
Solution::drawUsingTubes() |
| 105 |
// |
| 106 |
////////////////////////////////////////////////////////////////////////// |
| 107 |
{ |
| 108 |
SoSeparator * tubeSep = new SoSeparator; |
| 109 |
|
| 110 |
float dis = (!options[OPT_NORMALIZE_DATA]) ? (std::max(std::max( |
| 111 |
fabs(max_[0]-min_[0]), |
| 112 |
fabs(max_[1]-min_[1])), |
| 113 |
fabs(max_[2]-min_[2]))) : 2; |
| 114 |
|
| 115 |
long int sumX = 0; |
| 116 |
int iBranch = 0; |
| 117 |
int sumOrbit = numOrbitsInEachBranch_[iBranch]; |
| 118 |
|
| 119 |
for(long int j=0; j<numOrbits_; ++j) |
| 120 |
{ |
| 121 |
if(j >= sumOrbit) |
| 122 |
{ |
| 123 |
sumOrbit += numOrbitsInEachBranch_[++iBranch]; |
| 124 |
} |
| 125 |
long int upperlimit = orbits_[j].numVerticesEachPeriod; |
| 126 |
|
| 127 |
if(upperlimit >0 ) |
| 128 |
{ |
| 129 |
if(upperlimit == 1) |
| 130 |
{ |
| 131 |
int idx = sumX; |
| 132 |
SoSeparator * ptSep = new SoSeparator; |
| 133 |
|
| 134 |
int stability=clientData.labelIndex[j][3]; |
| 135 |
int type =clientData.labelIndex[j][2]; |
| 136 |
float scaler = lineWidthScaler; |
| 137 |
|
| 138 |
if(coloringMethod == CL_BRANCH_NUMBER || coloringMethod == CL_CURVE_NUMBER) |
| 139 |
ptSep->addChild(setLineAttributesByBranch(iBranch, stability, scaler)); |
| 140 |
else if(coloringMethod == CL_STABILITY) |
| 141 |
ptSep->addChild(setLineAttributesByStability(stability, scaler)); |
| 142 |
else if(coloringMethod == CL_ORBIT_TYPE) |
| 143 |
ptSep->addChild(setLineAttributesByType(stability, type, scaler)); |
| 144 |
else if(coloringMethod == CL_LABELS) |
| 145 |
{ |
| 146 |
ptSep->addChild(setLineAttributesByParameterValue( |
| 147 |
j, totalLabels_, totalLabels_/2.0, 0, |
| 148 |
stability, scaler)); |
| 149 |
} |
| 150 |
else if(coloringMethod == CL_COMPONENT) |
| 151 |
{ |
| 152 |
ptSep->addChild(setLineAttributesByParameterValue( |
| 153 |
curComponent, maxComponent, maxComponent/2.0, 0, |
| 154 |
stability, scaler)); |
| 155 |
} |
| 156 |
else |
| 157 |
{ |
| 158 |
SoMaterial * ptMtl = new SoMaterial; |
| 159 |
ptMtl->diffuseColor.setValue(1,0,0); |
| 160 |
ptSep->addChild(ptMtl); |
| 161 |
} |
| 162 |
|
| 163 |
float ver[2][3]; |
| 164 |
|
| 165 |
if(time_on != TIME_IS_OFF) |
| 166 |
{ |
| 167 |
int32_t myint[10]; |
| 168 |
if(time_on == TIME_ON_X) |
| 169 |
{ |
| 170 |
ver[0][0] = (options[OPT_NORMALIZE_DATA]) ? -1 : 0; |
| 171 |
//-(max_[0]-min_[0]) : 0; |
| 172 |
ver[0][1] = xyzCoords_[idx][1]; |
| 173 |
ver[0][2] = 0; |
| 174 |
ver[1][0] = (max_[0] <= 1.0) ? 1.0 : max_[0]; |
| 175 |
ver[1][1] = xyzCoords_[idx][1]; |
| 176 |
ver[1][2] = 0; |
| 177 |
} |
| 178 |
else if(time_on == TIME_ON_Y) |
| 179 |
{ |
| 180 |
ver[0][0] = xyzCoords_[idx][0]; |
| 181 |
ver[0][1] = (options[OPT_NORMALIZE_DATA]) ? -1 : 0; |
| 182 |
//-(max_[1]-min_[1]) : 0; |
| 183 |
ver[0][2] = 0; |
| 184 |
ver[1][0] = xyzCoords_[idx][0]; |
| 185 |
ver[1][1] = ( max_[1] <= 1.0 ) ? 1.0 : max_[1]; |
| 186 |
ver[1][2] = 0; |
| 187 |
} |
| 188 |
else if(time_on == TIME_ON_Z) |
| 189 |
{ |
| 190 |
ver[0][0] = xyzCoords_[idx][0]; |
| 191 |
ver[0][1] = 0; |
| 192 |
ver[0][2] = (options[OPT_NORMALIZE_DATA]) ? -1 : 0; |
| 193 |
//-(max_[2]-min_[2]) : 0; |
| 194 |
ver[1][0] = xyzCoords_[idx][0]; |
| 195 |
ver[1][1] = 0; |
| 196 |
ver[1][2] = ( max_[2] <= 1.0 ) ? 1.0 : max_[2]; |
| 197 |
} |
| 198 |
|
| 199 |
SoCoordinate3 *myC = new SoCoordinate3; |
| 200 |
myC->point.setValues(0, 2, ver); |
| 201 |
myint[0]=2; |
| 202 |
SoLineSet *myL = new SoLineSet; |
| 203 |
myL->numVertices.setValues(0, 1, myint); |
| 204 |
ptSep->addChild(myC); |
| 205 |
ptSep->addChild(myL); |
| 206 |
} |
| 207 |
else |
| 208 |
{ |
| 209 |
SoTransform * aTrans = new SoTransform; |
| 210 |
aTrans->translation.setValue(xyzCoords_[idx][0], |
| 211 |
xyzCoords_[idx][1], xyzCoords_[idx][2]); |
| 212 |
ptSep->addChild(aTrans); |
| 213 |
SoSphere *aPoint = new SoSphere; |
| 214 |
aPoint->radius = dis * STATIONARY_POINT_RADIUS; |
| 215 |
ptSep->addChild(aPoint); |
| 216 |
} |
| 217 |
tubeSep->addChild(ptSep); |
| 218 |
} |
| 219 |
else |
| 220 |
{ |
| 221 |
|
| 222 |
float (*path)[3] = new float[upperlimit][3]; |
| 223 |
float *colorBase = new float[upperlimit*11]; |
| 224 |
Tube tube; |
| 225 |
for(int i=0; i<upperlimit; i++) |
| 226 |
{ |
| 227 |
int idx = i+sumX; |
| 228 |
path[i][0]=xyzCoords_[idx][0]; |
| 229 |
path[i][1]=xyzCoords_[idx][1]; |
| 230 |
path[i][2]=xyzCoords_[idx][2]; |
| 231 |
if(coloringMethod>=0) |
| 232 |
for(int k=0; k<11; ++k) |
| 233 |
colorBase[i*11+k] = data_[idx][coloringMethod]; |
| 234 |
if(coloringMethod==CL_POINT_NUMBER) |
| 235 |
for(int k=0; k<11; ++k) |
| 236 |
colorBase[i*11+k] = i; |
| 237 |
|
| 238 |
} |
| 239 |
int stability=clientData.labelIndex[j][3]; |
| 240 |
int type =clientData.labelIndex[j][2]; |
| 241 |
float scaler = lineWidthScaler; |
| 242 |
|
| 243 |
if(coloringMethod == CL_BRANCH_NUMBER || coloringMethod == CL_CURVE_NUMBER) |
| 244 |
tubeSep->addChild(setLineAttributesByBranch(iBranch, stability, scaler)); |
| 245 |
else if(coloringMethod == CL_STABILITY) |
| 246 |
tubeSep->addChild(setLineAttributesByStability(stability, scaler)); |
| 247 |
else if(coloringMethod == CL_ORBIT_TYPE) |
| 248 |
tubeSep->addChild(setLineAttributesByType(stability, type, scaler)); |
| 249 |
else if(coloringMethod == CL_LABELS) |
| 250 |
tubeSep->addChild(setLineAttributesByParameterValue( |
| 251 |
j, totalLabels_, totalLabels_/2.0, 0, |
| 252 |
stability, scaler)); |
| 253 |
else if(coloringMethod == CL_COMPONENT) |
| 254 |
tubeSep->addChild(setLineAttributesByParameterValue( |
| 255 |
curComponent, maxComponent, maxComponent/2.0, 0, |
| 256 |
stability, scaler)); |
| 257 |
else if(coloringMethod >= nar_) |
| 258 |
tubeSep->addChild(setLineAttributesByParameterValue( |
| 259 |
orbits_[j].par[parID_[coloringMethod-nar_]], |
| 260 |
parMax_[iBranch][coloringMethod-nar_], |
| 261 |
parMid_[iBranch][coloringMethod-nar_], |
| 262 |
parMin_[iBranch][coloringMethod-nar_], |
| 263 |
stability, scaler)); |
| 264 |
else |
| 265 |
tubeSep->addChild(setLineColorBlending(colorBase, |
| 266 |
upperlimit*11,stability, scaler)); |
| 267 |
|
| 268 |
tube = Tube(upperlimit, path, lineWidthScaler*0.005, 10); |
| 269 |
tubeSep->addChild(tube.createTube()); |
| 270 |
delete [] path; |
| 271 |
delete [] colorBase; |
| 272 |
} |
| 273 |
} |
| 274 |
sumX += upperlimit; |
| 275 |
} |
| 276 |
return tubeSep; |
| 277 |
} |
| 278 |
|
| 279 |
|
| 280 |
////////////////////////////////////////////////////////////////////////// |
| 281 |
// |
| 282 |
// draw the diagram with surface |
| 283 |
// |
| 284 |
SoSeparator * |
| 285 |
Solution::drawABranchUsingSurface(long obStart, long obEnd, long numVert) |
| 286 |
// |
| 287 |
////////////////////////////////////////////////////////////////////////// |
| 288 |
{ |
| 289 |
float dis = (!options[OPT_NORMALIZE_DATA]) ? (std::max(std::max( |
| 290 |
fabs(max_[0]-min_[0]), |
| 291 |
fabs(max_[1]-min_[1])), |
| 292 |
fabs(max_[2]-min_[2]))) : 2.0; |
| 293 |
|
| 294 |
SoSeparator *solSurface = new SoSeparator; |
| 295 |
float (*strip)[3]; |
| 296 |
long int npt = numVert; |
| 297 |
long int sum = 0; |
| 298 |
|
| 299 |
strip = new float[2*npt][3]; |
| 300 |
|
| 301 |
//write the strip set |
| 302 |
if((obEnd-obStart)>1) |
| 303 |
{ |
| 304 |
if(npt>1) |
| 305 |
{ |
| 306 |
for(int i=0; i<npt; i++) |
| 307 |
{ |
| 308 |
strip[i*2][0] = xyzCoords_[i][0]; |
| 309 |
strip[i*2][1] = xyzCoords_[i][1]; |
| 310 |
strip[i*2][2] = xyzCoords_[i][2]; |
| 311 |
} |
| 312 |
} |
| 313 |
else |
| 314 |
{ |
| 315 |
printf(" Only one point in the period, no surface can be drawn!\n"); |
| 316 |
long int idx = obStart; |
| 317 |
SoSeparator * ptSep = new SoSeparator; |
| 318 |
SoTransform * aTrans = new SoTransform; |
| 319 |
aTrans->translation.setValue(xyzCoords_[idx][0], |
| 320 |
xyzCoords_[idx][1], xyzCoords_[idx][2]); |
| 321 |
ptSep->addChild(aTrans); |
| 322 |
|
| 323 |
SoSphere *aPoint = new SoSphere; |
| 324 |
aPoint->radius = dis * STATIONARY_POINT_RADIUS; |
| 325 |
ptSep->addChild(aPoint); |
| 326 |
solSurface->addChild(ptSep); |
| 327 |
return solSurface; |
| 328 |
} |
| 329 |
|
| 330 |
sum += npt; |
| 331 |
for(int j=obStart; j<obEnd; ++j) |
| 332 |
{ |
| 333 |
npt= orbits_[j].numVerticesEachPeriod; |
| 334 |
if(npt>1) |
| 335 |
{ |
| 336 |
for(int i=0; i<npt; i++) |
| 337 |
{ |
| 338 |
strip[i*2+1][0] = xyzCoords_[i+sum][0]; |
| 339 |
strip[i*2+1][1] = xyzCoords_[i+sum][1]; |
| 340 |
strip[i*2+1][2] = xyzCoords_[i+sum][2]; |
| 341 |
} |
| 342 |
solSurface->addChild(drawAStrip(strip,npt*2)); |
| 343 |
for(int i=0; i<npt; i++) |
| 344 |
{ |
| 345 |
strip[i*2][0] = strip[i*2+1][0]; |
| 346 |
strip[i*2][1] = strip[i*2+1][1]; |
| 347 |
strip[i*2][2] = strip[i*2+1][2]; |
| 348 |
} |
| 349 |
sum += npt; |
| 350 |
} |
| 351 |
else |
| 352 |
{ |
| 353 |
printf(" Only one point in the period, no surface can be drawn!\n"); |
| 354 |
long int idx = sum; |
| 355 |
SoSeparator * ptSep = new SoSeparator; |
| 356 |
SoTransform * aTrans = new SoTransform; |
| 357 |
aTrans->translation.setValue(xyzCoords_[idx][0], |
| 358 |
xyzCoords_[idx][1], xyzCoords_[idx][2]); |
| 359 |
ptSep->addChild(aTrans); |
| 360 |
|
| 361 |
SoSphere *aPoint = new SoSphere; |
| 362 |
aPoint->radius = dis * STATIONARY_POINT_RADIUS; |
| 363 |
ptSep->addChild(aPoint); |
| 364 |
solSurface->addChild(ptSep); |
| 365 |
return solSurface; |
| 366 |
|
| 367 |
} |
| 368 |
} |
| 369 |
} |
| 370 |
else |
| 371 |
{ |
| 372 |
printf(" Only one solution! No surface is able to be drawn!\n"); |
| 373 |
printf(" Choose LINE/TUBE to view it.\n"); |
| 374 |
return NULL; |
| 375 |
} |
| 376 |
delete [] strip; |
| 377 |
return solSurface; |
| 378 |
} |
| 379 |
|
| 380 |
|
| 381 |
/////////////////////////////////////////////////////////////////// |
| 382 |
// |
| 383 |
SoGroup * |
| 384 |
Solution::renderTubes() |
| 385 |
// |
| 386 |
////////////////////////////////////////////////////////////////////////// |
| 387 |
{ |
| 388 |
SoGroup * solGroup = new SoGroup; |
| 389 |
|
| 390 |
// draw every orbit by using giving tube thickness and color. |
| 391 |
if(animationLabel == MY_ALL) |
| 392 |
solGroup->addChild(drawUsingTubes()); |
| 393 |
else if(animationLabel != MY_NONE) |
| 394 |
{ |
| 395 |
for(std::vector<int>::size_type n=0; n<lblIndices.size(); ++n) |
| 396 |
{ |
| 397 |
animationLabel=myLabels[lblIndices[n]]; |
| 398 |
|
| 399 |
int si = 0, k = 0; |
| 400 |
int iBranch = 0; |
| 401 |
int sumOrbit = numOrbitsInEachBranch_[iBranch]; |
| 402 |
|
| 403 |
for(int ka=0; ka<numOrbits_; ka++) |
| 404 |
{ |
| 405 |
if(ka >= sumOrbit) |
| 406 |
{ |
| 407 |
sumOrbit += numOrbitsInEachBranch_[++iBranch]; |
| 408 |
} |
| 409 |
if(myLabels[ka]>=animationLabel) break; |
| 410 |
k = k+1; |
| 411 |
si += orbits_[ka].numVerticesEachPeriod; |
| 412 |
} |
| 413 |
|
| 414 |
if(options[OPT_SAT_ANI]) |
| 415 |
{ |
| 416 |
solGroup->addChild(animateOrbitWithTail(iBranch, k, si)); |
| 417 |
} |
| 418 |
else |
| 419 |
{ |
| 420 |
solGroup->addChild(drawAnOrbitUsingTubes(iBranch, k, si, 1*lineWidthScaler, |
| 421 |
clientData.labelIndex[k][3], clientData.labelIndex[k][2])); |
| 422 |
} |
| 423 |
} |
| 424 |
} |
| 425 |
|
| 426 |
if(options[OPT_PERIOD_ANI]) |
| 427 |
{ |
| 428 |
bool aniColoring; |
| 429 |
aniColoring = (animationLabel == MY_ALL) ? false : true; |
| 430 |
solGroup->addChild(animateUsingTubes(aniColoring)); |
| 431 |
} |
| 432 |
return solGroup; |
| 433 |
} |
| 434 |
|
| 435 |
|
| 436 |
////////////////////////////////////////////////////////////////////////// |
| 437 |
// |
| 438 |
SoGroup * |
| 439 |
Solution::renderSurface() |
| 440 |
// |
| 441 |
////////////////////////////////////////////////////////////////////////// |
| 442 |
{ |
| 443 |
SoGroup *solGroup = new SoGroup; |
| 444 |
SoMaterial *solMtl = new SoMaterial; |
| 445 |
solMtl->diffuseColor.setValue(envColors[4]); |
| 446 |
solGroup->addChild(solMtl); |
| 447 |
SoMaterialBinding *myMtlBinding = new SoMaterialBinding; |
| 448 |
myMtlBinding->value= SoMaterialBinding::PER_PART; |
| 449 |
solGroup->addChild(myMtlBinding); |
| 450 |
|
| 451 |
long start = 0; |
| 452 |
long end = 0; |
| 453 |
|
| 454 |
int sumOrbit = 0; |
| 455 |
long numVert = 0; |
| 456 |
for(int iBranch = 0; iBranch < numBranches_; ++iBranch) |
| 457 |
{ |
| 458 |
end += numOrbitsInEachBranch_[iBranch]; |
| 459 |
numVert = orbits_[sumOrbit].numVerticesEachPeriod; |
| 460 |
SoSeparator * as = drawABranchUsingSurface(start+1, end, numVert); |
| 461 |
if(as !=NULL) |
| 462 |
solGroup->addChild(as); |
| 463 |
start += numOrbitsInEachBranch_[iBranch]; |
| 464 |
sumOrbit += numOrbitsInEachBranch_[iBranch]; |
| 465 |
} |
| 466 |
|
| 467 |
if(options[OPT_PERIOD_ANI]) |
| 468 |
solGroup->addChild(animateUsingTubes(true)); |
| 469 |
|
| 470 |
int si = 0, k = 0; |
| 471 |
int iBranch = 0; |
| 472 |
sumOrbit = numOrbitsInEachBranch_[iBranch]; |
| 473 |
for(int ka=0; ka<numOrbits_; ka++) |
| 474 |
{ |
| 475 |
if(ka >= sumOrbit) |
| 476 |
{ |
| 477 |
sumOrbit += numOrbitsInEachBranch_[++iBranch]; |
| 478 |
} |
| 479 |
if(myLabels[ka]>=animationLabel) break; |
| 480 |
k = k+1; |
| 481 |
si += orbits_[ka].numVerticesEachPeriod; |
| 482 |
} |
| 483 |
|
| 484 |
if(options[OPT_SAT_ANI]) |
| 485 |
solGroup->addChild(animateOrbitWithTail(iBranch, k, si)); |
| 486 |
else |
| 487 |
solGroup->addChild(drawAnOrbitUsingTubes(iBranch, k, si, 1*lineWidthScaler, |
| 488 |
clientData.labelIndex[k][3], clientData.labelIndex[k][2])); |
| 489 |
return solGroup; |
| 490 |
} |
| 491 |
|
| 492 |
/////////////////////////////////////////////////////////////////////// |
| 493 |
// |
| 494 |
// draw the solutions by Mesh points |
| 495 |
// |
| 496 |
// draw the solutions by Points |
| 497 |
SoGroup * |
| 498 |
Solution::renderPoints(int style) |
| 499 |
// |
| 500 |
////////////////////////////////////////////////////////////////////////// |
| 501 |
{ |
| 502 |
SoGroup *solGroup = new SoGroup; |
| 503 |
|
| 504 |
if(animationLabel == MY_ALL) |
| 505 |
{ |
| 506 |
long int si = 0, k = 0; |
| 507 |
int iBranch = 0; |
| 508 |
int sumOrbit = numOrbitsInEachBranch_[iBranch]; |
| 509 |
|
| 510 |
for(long int ka=0; ka<numOrbits_; ka++) |
| 511 |
{ |
| 512 |
if(ka >= sumOrbit) |
| 513 |
{ |
| 514 |
sumOrbit+= numOrbitsInEachBranch_[++iBranch]; |
| 515 |
} |
| 516 |
|
| 517 |
solGroup->addChild(drawAnOrbitUsingPoints(style, iBranch, /*curBranchID,*/ k, si, lineWidthScaler, |
| 518 |
clientData.labelIndex[k][3], clientData.labelIndex[k][2], true)); |
| 519 |
k = k+1; |
| 520 |
si += orbits_[ka].numVerticesEachPeriod; |
| 521 |
} |
| 522 |
} |
| 523 |
else if(animationLabel != MY_NONE) |
| 524 |
{ |
| 525 |
for(std::vector<int>::size_type n=0; n<lblIndices.size(); ++n) |
| 526 |
{ |
| 527 |
animationLabel=myLabels[lblIndices[n]]; |
| 528 |
int si = 0, k = 0; |
| 529 |
int iBranch = 0; |
| 530 |
int sumOrbit = numOrbitsInEachBranch_[iBranch]; |
| 531 |
for(int ka=0; ka<numOrbits_; ka++) |
| 532 |
{ |
| 533 |
if(ka >= sumOrbit) |
| 534 |
{ |
| 535 |
sumOrbit+= numOrbitsInEachBranch_[++iBranch]; |
| 536 |
} |
| 537 |
|
| 538 |
if(myLabels[ka]>=animationLabel) break; |
| 539 |
k = k+1; |
| 540 |
si += orbits_[ka].numVerticesEachPeriod; |
| 541 |
} |
| 542 |
if(options[OPT_SAT_ANI]) |
| 543 |
{ |
| 544 |
solGroup->addChild(animateOrbitWithTail(iBranch, k, si)); |
| 545 |
} |
| 546 |
else |
| 547 |
{ |
| 548 |
solGroup->addChild(drawAnOrbitUsingPoints(style, iBranch, k, si, lineWidthScaler, |
| 549 |
clientData.labelIndex[k][3], clientData.labelIndex[k][2], true)); |
| 550 |
} |
| 551 |
} |
| 552 |
} |
| 553 |
|
| 554 |
if(options[OPT_PERIOD_ANI]) |
| 555 |
{ |
| 556 |
bool coloring; |
| 557 |
coloring = (animationLabel == MY_ALL) ? false : true; |
| 558 |
solGroup->addChild(animateUsingPoints(style, coloring)); |
| 559 |
} |
| 560 |
|
| 561 |
return solGroup; |
| 562 |
} |
| 563 |
|
| 564 |
|
| 565 |
/////////////////////////////////////////////////////////////////////// |
| 566 |
// |
| 567 |
// draw the solutions by lines |
| 568 |
// |
| 569 |
SoGroup * |
| 570 |
Solution::renderLines() |
| 571 |
// |
| 572 |
////////////////////////////////////////////////////////////////////////// |
| 573 |
{ |
| 574 |
SoGroup *solGroup = new SoGroup; |
| 575 |
|
| 576 |
if(animationLabel == MY_ALL) |
| 577 |
{ |
| 578 |
long int si = 0, k = 0; |
| 579 |
int iBranch = 0; |
| 580 |
int sumOrbit = numOrbitsInEachBranch_[iBranch]; |
| 581 |
|
| 582 |
for(long int ka=0; ka<numOrbits_; ka++) |
| 583 |
{ |
| 584 |
if(ka >= sumOrbit) |
| 585 |
{ |
| 586 |
sumOrbit+= numOrbitsInEachBranch_[++iBranch]; |
| 587 |
} |
| 588 |
|
| 589 |
solGroup->addChild(drawAnOrbitUsingLines(iBranch, k, si, lineWidthScaler, |
| 590 |
clientData.labelIndex[k][3], clientData.labelIndex[k][2], true)); |
| 591 |
k = k+1; |
| 592 |
si += orbits_[ka].numVerticesEachPeriod; |
| 593 |
} |
| 594 |
} |
| 595 |
else if(animationLabel != MY_NONE) |
| 596 |
{ |
| 597 |
for(std::vector<int>::size_type n=0; n<lblIndices.size(); ++n) |
| 598 |
{ |
| 599 |
animationLabel=myLabels[lblIndices[n]]; |
| 600 |
int si = 0, k = 0; |
| 601 |
int iBranch = 0; |
| 602 |
int sumOrbit = numOrbitsInEachBranch_[iBranch]; |
| 603 |
for(int ka=0; ka<numOrbits_; ka++) |
| 604 |
{ |
| 605 |
if(ka >= sumOrbit) |
| 606 |
{ |
| 607 |
sumOrbit+= numOrbitsInEachBranch_[++iBranch]; |
| 608 |
} |
| 609 |
|
| 610 |
if(myLabels[ka]>=animationLabel) break; |
| 611 |
k = k+1; |
| 612 |
si += orbits_[ka].numVerticesEachPeriod; |
| 613 |
} |
| 614 |
|
| 615 |
if(options[OPT_SAT_ANI]) |
| 616 |
{ |
| 617 |
solGroup->addChild(animateOrbitWithTail(iBranch, k, si)); |
| 618 |
} |
| 619 |
else |
| 620 |
{ |
| 621 |
solGroup->addChild(drawAnOrbitUsingLines(iBranch, k, si, lineWidthScaler, |
| 622 |
clientData.labelIndex[k][3], clientData.labelIndex[k][2], true)); |
| 623 |
} |
| 624 |
} |
| 625 |
} |
| 626 |
|
| 627 |
if(options[OPT_PERIOD_ANI]) |
| 628 |
{ |
| 629 |
bool coloring; |
| 630 |
coloring = (animationLabel == MY_ALL) ? false : true; |
| 631 |
solGroup->addChild(animateUsingLines(coloring)); |
| 632 |
} |
| 633 |
|
| 634 |
return solGroup; |
| 635 |
} |
| 636 |
|
| 637 |
|
| 638 |
/////////////////////////////////////////////////////////////////////// |
| 639 |
// |
| 640 |
// draw the solutions using NURBS CURVE lines |
| 641 |
// |
| 642 |
SoGroup * |
| 643 |
Solution::renderNurbsCurve() |
| 644 |
// |
| 645 |
////////////////////////////////////////////////////////////////////////// |
| 646 |
{ |
| 647 |
SoGroup * solGroup = new SoGroup; |
| 648 |
|
| 649 |
if(animationLabel == MY_ALL) |
| 650 |
{ |
| 651 |
long int si = 0, k = 0; |
| 652 |
int iBranch = 0; |
| 653 |
int sumOrbit = numOrbitsInEachBranch_[iBranch]; |
| 654 |
for(long int ka=0; ka<numOrbits_; ka++) |
| 655 |
{ |
| 656 |
if(ka >= sumOrbit) |
| 657 |
{ |
| 658 |
sumOrbit += numOrbitsInEachBranch_[++iBranch]; |
| 659 |
} |
| 660 |
solGroup->addChild(drawAnOrbitUsingNurbsCurve(iBranch, k+1, si, lineWidthScaler, |
| 661 |
clientData.labelIndex[k][3], clientData.labelIndex[k][2])); |
| 662 |
k = k+1; |
| 663 |
si += orbits_[ka].numVerticesEachPeriod; |
| 664 |
} |
| 665 |
} |
| 666 |
else if(animationLabel != MY_NONE) |
| 667 |
{ |
| 668 |
for(std::vector<int>::size_type n=0; n<lblIndices.size(); ++n) |
| 669 |
{ |
| 670 |
animationLabel=myLabels[lblIndices[n]]; |
| 671 |
int si = 0, k = 0; |
| 672 |
int iBranch = 0; |
| 673 |
int sumOrbit = numOrbitsInEachBranch_[iBranch]; |
| 674 |
for(int ka=0; ka<numOrbits_; ka++) |
| 675 |
{ |
| 676 |
if(ka >= sumOrbit) |
| 677 |
{ |
| 678 |
sumOrbit += numOrbitsInEachBranch_[++iBranch]; |
| 679 |
} |
| 680 |
if(myLabels[ka]>=animationLabel) break; |
| 681 |
k = k+1; |
| 682 |
si += orbits_[ka].numVerticesEachPeriod; |
| 683 |
} |
| 684 |
|
| 685 |
if(options[OPT_SAT_ANI]) |
| 686 |
{ |
| 687 |
solGroup->addChild(animateOrbitWithTail(iBranch, k, si)); |
| 688 |
} |
| 689 |
else |
| 690 |
{ |
| 691 |
solGroup->addChild(drawAnOrbitUsingNurbsCurve(iBranch, k, si, lineWidthScaler, |
| 692 |
clientData.labelIndex[k][3], clientData.labelIndex[k][2])); |
| 693 |
} |
| 694 |
} |
| 695 |
} |
| 696 |
|
| 697 |
if(options[OPT_PERIOD_ANI]) |
| 698 |
{ |
| 699 |
bool coloring = (animationLabel == MY_ALL) ? true : false; |
| 700 |
solGroup->addChild(animateUsingLines(coloring)); |
| 701 |
} |
| 702 |
return solGroup; |
| 703 |
} |
| 704 |
|
| 705 |
|
| 706 |
////////////////////////////////////////////////////////////////////////// |
| 707 |
// |
| 708 |
SoSeparator * |
| 709 |
Solution::animateUsingPoints(int style, bool aniColoring) |
| 710 |
// |
| 711 |
////////////////////////////////////////////////////////////////////////// |
| 712 |
{ |
| 713 |
SoSeparator *solGroup = new SoSeparator; |
| 714 |
SoSeparator *solStand = new SoSeparator; |
| 715 |
int si = 0; |
| 716 |
SoBlinker * solBlinker = new SoBlinker; |
| 717 |
solBlinker->speed = orbitSpeed; |
| 718 |
solBlinker->on = TRUE; |
| 719 |
int iBranch = 0; |
| 720 |
int sumOrbit = numOrbitsInEachBranch_[iBranch]; |
| 721 |
for(int l=0; l<numOrbits_; l++) |
| 722 |
{ |
| 723 |
long numVertices = orbits_[l].numVerticesEachPeriod; |
| 724 |
if(l >= sumOrbit) |
| 725 |
{ |
| 726 |
sumOrbit+= numOrbitsInEachBranch_[++iBranch]; |
| 727 |
} |
| 728 |
|
| 729 |
if(numVertices == 1) |
| 730 |
solStand->addChild(drawAnOrbitUsingPoints(style, iBranch,/* curBranchID,*/ l, si, aniLineScaler*lineWidthScaler, |
| 731 |
clientData.labelIndex[l][3], clientData.labelIndex[l][2], aniColoring)); |
| 732 |
else |
| 733 |
solBlinker->addChild(drawAnOrbitUsingPoints(style, iBranch,/* curBranchID,*/ l, si, aniLineScaler*lineWidthScaler, |
| 734 |
clientData.labelIndex[l][3], clientData.labelIndex[l][2], aniColoring)); |
| 735 |
si+=orbits_[l].numVerticesEachPeriod; |
| 736 |
} |
| 737 |
solGroup->addChild(solStand); |
| 738 |
solGroup->addChild(solBlinker); |
| 739 |
return solGroup; |
| 740 |
} |
| 741 |
|
| 742 |
|
| 743 |
////////////////////////////////////////////////////////////////////////// |
| 744 |
// |
| 745 |
SoSeparator * |
| 746 |
Solution::animateUsingLines(bool aniColoring) |
| 747 |
// |
| 748 |
////////////////////////////////////////////////////////////////////////// |
| 749 |
{ |
| 750 |
// the following is the line version |
| 751 |
SoSeparator *solGroup = new SoSeparator; |
| 752 |
SoSeparator *solStand = new SoSeparator; |
| 753 |
int si = 0; |
| 754 |
SoBlinker * solBlinker = new SoBlinker; |
| 755 |
solBlinker->speed = orbitSpeed; |
| 756 |
solBlinker->on = TRUE; |
| 757 |
int iBranch = 0; |
| 758 |
int sumOrbit = numOrbitsInEachBranch_[iBranch]; |
| 759 |
for(int l=0; l<numOrbits_; l++) |
| 760 |
{ |
| 761 |
long numVertices = orbits_[l].numVerticesEachPeriod; |
| 762 |
if(l >= sumOrbit) |
| 763 |
{ |
| 764 |
sumOrbit+= numOrbitsInEachBranch_[++iBranch]; |
| 765 |
} |
| 766 |
|
| 767 |
if(numVertices == 1) |
| 768 |
solStand->addChild(drawAnOrbitUsingLines(iBranch, l, si, aniLineScaler*lineWidthScaler, |
| 769 |
clientData.labelIndex[l][3], clientData.labelIndex[l][2], aniColoring)); |
| 770 |
else |
| 771 |
solBlinker->addChild(drawAnOrbitUsingLines(iBranch, l, si, aniLineScaler*lineWidthScaler, |
| 772 |
clientData.labelIndex[l][3], clientData.labelIndex[l][2], aniColoring)); |
| 773 |
si+=orbits_[l].numVerticesEachPeriod; |
| 774 |
} |
| 775 |
solGroup->addChild(solStand); |
| 776 |
solGroup->addChild(solBlinker); |
| 777 |
return solGroup; |
| 778 |
} |
| 779 |
|
| 780 |
|
| 781 |
#if 0 |
| 782 |
////////////////////////////////////////////////////////////////////////// |
| 783 |
// |
| 784 |
SoSeparator * |
| 785 |
Solution::animateUsingNurbsCurve() |
| 786 |
// |
| 787 |
///////////////////////////////////////////////////////////////// |
| 788 |
{ |
| 789 |
SoSeparator *solGroup = new SoSeparator; |
| 790 |
long int si = 0; |
| 791 |
SoBlinker * solBlinker = new SoBlinker; |
| 792 |
solBlinker->speed = orbitSpeed; |
| 793 |
solBlinker->on = TRUE; |
| 794 |
int iBranch = 0; |
| 795 |
int sumOrbit = numOrbitsInEachBranch_[iBranch]; |
| 796 |
for(long int l=0; l<numOrbits_; l++) |
| 797 |
{ |
| 798 |
if(l >= sumOrbit) |
| 799 |
{ |
| 800 |
sumOrbit += numOrbitsInEachBranch_[++iBranch]; |
| 801 |
} |
| 802 |
solBlinker->addChild(drawAnOrbitUsingNurbsCurve(iBranch, l, si, lineWidthScaler, |
| 803 |
clientData.labelIndex[l][3], clientData.labelIndex[l][2])); |
| 804 |
si+=orbits_[l].numVerticesEachPeriod; |
| 805 |
} |
| 806 |
solGroup->addChild(solBlinker); |
| 807 |
return solGroup; |
| 808 |
} |
| 809 |
#endif |
| 810 |
|
| 811 |
///////////////////////////////////////////////////////////////// |
| 812 |
// create solution orbits scene |
| 813 |
SoSeparator * |
| 814 |
Solution::render() |
| 815 |
// |
| 816 |
///////////////////////////////////////////////////////////////// |
| 817 |
{ |
| 818 |
SoSeparator *solSep = new SoSeparator; |
| 819 |
SoGroup *solGroup = new SoGroup; |
| 820 |
|
| 821 |
if(whichStyle==TUBE) |
| 822 |
{ |
| 823 |
solGroup->addChild(renderTubes()); |
| 824 |
} |
| 825 |
else if(whichStyle==SURFACE) |
| 826 |
{ |
| 827 |
solGroup->addChild(renderSurface()); |
| 828 |
} |
| 829 |
else if(whichStyle==NURBS) |
| 830 |
{ |
| 831 |
solGroup->addChild(renderNurbsCurve()); |
| 832 |
} |
| 833 |
else if(whichStyle==MESH_POINTS || whichStyle== ALL_POINTS) |
| 834 |
{ |
| 835 |
solGroup->addChild(renderPoints(whichStyle)); |
| 836 |
} |
| 837 |
else |
| 838 |
{ |
| 839 |
solGroup->addChild(renderLines()); |
| 840 |
} |
| 841 |
solSep->addChild(solGroup); |
| 842 |
return solSep; |
| 843 |
} |
| 844 |
|
| 845 |
/////////////////////////////////////////////////////////////////////////// |
| 846 |
// |
| 847 |
// animate the solution by using lines. This version use less memory |
| 848 |
// and much faster. |
| 849 |
// =============================================================== |
| 850 |
// + + UNSTABLE STEADY STATE 1 |
| 851 |
// + - STABLE STEADY STATE 2 |
| 852 |
// - + UNSTABLE PERIODIC 3 |
| 853 |
// - - STABLE PERIODIC 4 |
| 854 |
// =============================================================== |
| 855 |
// |
| 856 |
// |
| 857 |
SoSeparator * |
| 858 |
Solution::drawAnOrbitUsingLines(int iBranch, long int l, long int si, |
| 859 |
float scaler, int stability, int type, bool aniColoring) |
| 860 |
// |
| 861 |
////////////////////////////////////////////////////////////////////////// |
| 862 |
{ |
| 863 |
SoSeparator * anOrbit = new SoSeparator; |
| 864 |
|
| 865 |
float dis = !options[OPT_NORMALIZE_DATA] ? |
| 866 |
(std::max(std::max( |
| 867 |
fabs(max_[0]-min_[0]), |
| 868 |
fabs(max_[1]-min_[1])), |
| 869 |
fabs(max_[2]-min_[2]))) : 2.0; |
| 870 |
|
| 871 |
long numVertices = orbits_[l].numVerticesEachPeriod; |
| 872 |
if(numVertices == 1 ) |
| 873 |
{ |
| 874 |
long int idx = si; |
| 875 |
SoSeparator * ptSep = new SoSeparator; |
| 876 |
|
| 877 |
if(coloringMethod == CL_BRANCH_NUMBER || coloringMethod == CL_CURVE_NUMBER) |
| 878 |
ptSep->addChild(setLineAttributesByBranch(iBranch, stability, scaler)); |
| 879 |
else if(coloringMethod == CL_STABILITY) |
| 880 |
ptSep->addChild(setLineAttributesByStability(stability, scaler)); |
| 881 |
else if(coloringMethod == CL_ORBIT_TYPE) |
| 882 |
ptSep->addChild(setLineAttributesByType(stability, type, scaler)); |
| 883 |
else if(coloringMethod == CL_LABELS) |
| 884 |
{ |
| 885 |
ptSep->addChild(setLineAttributesByParameterValue( |
| 886 |
l, totalLabels_, totalLabels_/2.0, 0, |
| 887 |
stability, scaler)); |
| 888 |
} |
| 889 |
else if(coloringMethod == CL_COMPONENT) |
| 890 |
{ |
| 891 |
ptSep->addChild(setLineAttributesByParameterValue( |
| 892 |
curComponent, maxComponent, maxComponent/2.0, 0, |
| 893 |
stability, scaler)); |
| 894 |
} |
| 895 |
else |
| 896 |
{ |
| 897 |
SoMaterial * ptMtl = new SoMaterial; |
| 898 |
ptMtl->diffuseColor.setValue(1,0,0); |
| 899 |
ptSep->addChild(ptMtl); |
| 900 |
} |
| 901 |
|
| 902 |
|
| 903 |
float ver[2][3]; |
| 904 |
|
| 905 |
if(time_on != TIME_IS_OFF) |
| 906 |
{ |
| 907 |
int32_t myint[10]; |
| 908 |
if(time_on == TIME_ON_X) |
| 909 |
{ |
| 910 |
ver[0][0] = (options[OPT_NORMALIZE_DATA]) ? -1 : 0; |
| 911 |
//-(max_[0]-min_[0]) : 0; |
| 912 |
ver[0][1] = xyzCoords_[idx][1]; |
| 913 |
ver[0][2] = 0; |
| 914 |
ver[1][0] = (max_[0] <= 1.0) ? 1.0 : max_[0]; |
| 915 |
ver[1][1] = xyzCoords_[idx][1]; |
| 916 |
ver[1][2] = 0; |
| 917 |
} |
| 918 |
else if(time_on == TIME_ON_Y) |
| 919 |
{ |
| 920 |
ver[0][0] = xyzCoords_[idx][0]; |
| 921 |
ver[0][1] = (options[OPT_NORMALIZE_DATA]) ? -1 : 0; |
| 922 |
//-(max_[1]-min_[1]) : 0; |
| 923 |
ver[0][2] = 0; |
| 924 |
ver[1][0] = xyzCoords_[idx][0]; |
| 925 |
ver[1][1] = ( max_[1] <= 1.0 ) ? 1.0 : max_[1]; |
| 926 |
ver[1][2] = 0; |
| 927 |
} |
| 928 |
else if(time_on == TIME_ON_Z) |
| 929 |
{ |
| 930 |
ver[0][0] = xyzCoords_[idx][0]; |
| 931 |
ver[0][1] = 0; |
| 932 |
ver[0][2] = (options[OPT_NORMALIZE_DATA]) ? -1 : 0; |
| 933 |
//-(max_[2]-min_[2]) : 0; |
| 934 |
ver[1][0] = xyzCoords_[idx][0]; |
| 935 |
ver[1][1] = 0; |
| 936 |
ver[1][2] = ( max_[2] <= 1.0 ) ? 1.0 : max_[2]; |
| 937 |
} |
| 938 |
|
| 939 |
SoCoordinate3 *myC = new SoCoordinate3; |
| 940 |
myC->point.setValues(0, 2, ver); |
| 941 |
myint[0]=2; |
| 942 |
SoLineSet *myL = new SoLineSet; |
| 943 |
myL->numVertices.setValues(0, 1, myint); |
| 944 |
ptSep->addChild(myC); |
| 945 |
ptSep->addChild(myL); |
| 946 |
anOrbit->addChild(ptSep); |
| 947 |
} |
| 948 |
else |
| 949 |
{ |
| 950 |
SoTransform * aTrans = new SoTransform; |
| 951 |
aTrans->translation.setValue(xyzCoords_[idx][0], |
| 952 |
xyzCoords_[idx][1], xyzCoords_[idx][2]); |
| 953 |
ptSep->addChild(aTrans); |
| 954 |
SoSphere *aPoint = new SoSphere; |
| 955 |
aPoint->radius = dis * STATIONARY_POINT_RADIUS; |
| 956 |
ptSep->addChild(aPoint); |
| 957 |
anOrbit->addChild(ptSep); |
| 958 |
} |
| 959 |
return anOrbit; |
| 960 |
} |
| 961 |
|
| 962 |
float (*vertices)[3] = new float[numVertices][3]; |
| 963 |
float *colorBase = new float[numVertices]; |
| 964 |
|
| 965 |
for(int m=0; m<numVertices; m++) |
| 966 |
{ |
| 967 |
long int idx = si+m; |
| 968 |
vertices[m][0]=xyzCoords_[idx][0]; |
| 969 |
vertices[m][1]=xyzCoords_[idx][1]; |
| 970 |
vertices[m][2]=xyzCoords_[idx][2]; |
| 971 |
if(coloringMethod>=0)colorBase[m] = data_[idx][coloringMethod]; |
| 972 |
if(coloringMethod==CL_POINT_NUMBER)colorBase[m] = m; |
| 973 |
} |
| 974 |
|
| 975 |
SoCoordinate3 *myCoords = new SoCoordinate3; |
| 976 |
myCoords->point.setValues(0, orbits_[l].numVerticesEachPeriod, vertices); |
| 977 |
int32_t myint[10]; |
| 978 |
myint[0]=orbits_[l].numVerticesEachPeriod; |
| 979 |
|
| 980 |
// define the solution line set |
| 981 |
SoLineSet *myLine= new SoLineSet; |
| 982 |
myLine->numVertices.setValues(0,1,myint); |
| 983 |
if(!aniColoring) |
| 984 |
{ |
| 985 |
anOrbit->addChild(setLineAttributesByType(stability, 0, scaler)); |
| 986 |
} |
| 987 |
else if(coloringMethod == CL_BRANCH_NUMBER || coloringMethod == CL_CURVE_NUMBER) |
| 988 |
anOrbit->addChild(setLineAttributesByBranch(iBranch, stability, scaler)); |
| 989 |
else if(coloringMethod == CL_STABILITY) |
| 990 |
anOrbit->addChild(setLineAttributesByStability(stability, scaler)); |
| 991 |
else if(coloringMethod == CL_ORBIT_TYPE) |
| 992 |
anOrbit->addChild(setLineAttributesByType(stability, type, scaler)); |
| 993 |
else if(coloringMethod == CL_LABELS) |
| 994 |
{ |
| 995 |
anOrbit->addChild(setLineAttributesByParameterValue( |
| 996 |
l, totalLabels_, totalLabels_/2.0, 0, |
| 997 |
stability, scaler)); |
| 998 |
} |
| 999 |
else if(coloringMethod == CL_COMPONENT) |
| 1000 |
anOrbit->addChild(setLineAttributesByParameterValue( |
| 1001 |
curComponent, maxComponent, maxComponent/2.0, 0, |
| 1002 |
stability, scaler)); |
| 1003 |
else if(coloringMethod >= nar_) |
| 1004 |
anOrbit->addChild(setLineAttributesByParameterValue( |
| 1005 |
orbits_[l].par[parID_[coloringMethod-nar_]], |
| 1006 |
parMax_[iBranch][coloringMethod-nar_], |
| 1007 |
parMid_[iBranch][coloringMethod-nar_], |
| 1008 |
parMin_[iBranch][coloringMethod-nar_], |
| 1009 |
stability, scaler)); |
| 1010 |
else |
| 1011 |
anOrbit->addChild(setLineColorBlending(colorBase, |
| 1012 |
orbits_[l].numVerticesEachPeriod,stability, scaler)); |
| 1013 |
|
| 1014 |
anOrbit->addChild(myCoords); |
| 1015 |
anOrbit->addChild(myLine); |
| 1016 |
|
| 1017 |
delete [] vertices; |
| 1018 |
delete [] colorBase; |
| 1019 |
|
| 1020 |
return anOrbit; |
| 1021 |
} |
| 1022 |
|
| 1023 |
////////////////////////////////////////////////////////////////////////// |
| 1024 |
// |
| 1025 |
SoSeparator * |
| 1026 |
Solution::drawAnOrbitUsingPoints(int style, int iBranch, long int l, |
| 1027 |
long int si, float scaler, int stability, int type, bool aniColoring) |
| 1028 |
// |
| 1029 |
////////////////////////////////////////////////////////////////////////// |
| 1030 |
{ |
| 1031 |
SoSeparator * anOrbit = new SoSeparator; |
| 1032 |
|
| 1033 |
float dis = !options[OPT_NORMALIZE_DATA] ? (std::max(std::max( |
| 1034 |
fabs(max_[0]-min_[0]), |
| 1035 |
fabs(max_[1]-min_[1])), |
| 1036 |
fabs(max_[2]-min_[2]))) : 2.0; |
| 1037 |
|
| 1038 |
long numVertices = orbits_[l].numVerticesEachPeriod; |
| 1039 |
if(numVertices == 1) |
| 1040 |
{ |
| 1041 |
long int idx = si; |
| 1042 |
SoSeparator * ptSep = new SoSeparator; |
| 1043 |
SoTransform * aTrans = new SoTransform; |
| 1044 |
|
| 1045 |
if(coloringMethod == CL_BRANCH_NUMBER || coloringMethod == CL_CURVE_NUMBER) |
| 1046 |
ptSep->addChild(setLineAttributesByBranch(iBranch, stability, scaler)); |
| 1047 |
else if(coloringMethod == CL_STABILITY) |
| 1048 |
ptSep->addChild(setLineAttributesByStability(stability, scaler)); |
| 1049 |
else if(coloringMethod == CL_ORBIT_TYPE) |
| 1050 |
ptSep->addChild(setLineAttributesByType(stability, type, scaler)); |
| 1051 |
else if(coloringMethod == CL_LABELS) |
| 1052 |
{ |
| 1053 |
ptSep->addChild(setLineAttributesByParameterValue( |
| 1054 |
l, totalLabels_, totalLabels_/2.0, 0, |
| 1055 |
stability, scaler)); |
| 1056 |
} |
| 1057 |
else if(coloringMethod == CL_COMPONENT) |
| 1058 |
{ |
| 1059 |
ptSep->addChild(setLineAttributesByParameterValue( |
| 1060 |
curComponent, maxComponent, maxComponent/2.0, 0, |
| 1061 |
stability, scaler)); |
| 1062 |
} |
| 1063 |
else |
| 1064 |
{ |
| 1065 |
SoMaterial * ptMtl = new SoMaterial; |
| 1066 |
ptMtl->diffuseColor.setValue(1,0,0); |
| 1067 |
ptSep->addChild(ptMtl); |
| 1068 |
} |
| 1069 |
|
| 1070 |
aTrans->translation.setValue(xyzCoords_[idx][0], |
| 1071 |
xyzCoords_[idx][1], xyzCoords_[idx][2]); |
| 1072 |
ptSep->addChild(aTrans); |
| 1073 |
|
| 1074 |
SoSphere *aPoint = new SoSphere; |
| 1075 |
aPoint->radius = dis * STATIONARY_POINT_RADIUS; |
| 1076 |
ptSep->addChild(aPoint); |
| 1077 |
anOrbit->addChild(ptSep); |
| 1078 |
return anOrbit; |
| 1079 |
} |
| 1080 |
|
| 1081 |
float (*vertices)[3] = new float[numVertices][3]; |
| 1082 |
float *colorBase = new float[numVertices]; |
| 1083 |
|
| 1084 |
for(int m=0; m<numVertices; m++) |
| 1085 |
{ |
| 1086 |
long int idx = si+m; |
| 1087 |
vertices[m][0]=xyzCoords_[idx][0]; |
| 1088 |
vertices[m][1]=xyzCoords_[idx][1]; |
| 1089 |
vertices[m][2]=xyzCoords_[idx][2]; |
| 1090 |
if(coloringMethod>=0)colorBase[m] = data_[idx][coloringMethod]; |
| 1091 |
if(coloringMethod==CL_POINT_NUMBER)colorBase[m] = m; |
| 1092 |
|
| 1093 |
if(!aniColoring) |
| 1094 |
{ |
| 1095 |
anOrbit->addChild(setLineAttributesByType(stability, 0, scaler)); |
| 1096 |
} |
| 1097 |
else if(coloringMethod == CL_BRANCH_NUMBER || coloringMethod == CL_CURVE_NUMBER) |
| 1098 |
anOrbit->addChild(setLineAttributesByBranch(iBranch, stability, scaler)); |
| 1099 |
else if(coloringMethod == CL_STABILITY) |
| 1100 |
anOrbit->addChild(setLineAttributesByStability(stability, scaler)); |
| 1101 |
else if(coloringMethod == CL_ORBIT_TYPE) |
| 1102 |
anOrbit->addChild(setLineAttributesByType(stability, type, scaler)); |
| 1103 |
else if(coloringMethod == CL_LABELS) |
| 1104 |
{ |
| 1105 |
anOrbit->addChild(setLineAttributesByParameterValue( |
| 1106 |
l, totalLabels_, totalLabels_/2.0, 0, |
| 1107 |
stability, scaler)); |
| 1108 |
} |
| 1109 |
else if(coloringMethod == CL_COMPONENT) |
| 1110 |
anOrbit->addChild(setLineAttributesByParameterValue( |
| 1111 |
curComponent, maxComponent, maxComponent/2.0, 0, |
| 1112 |
stability, scaler)); |
| 1113 |
else if(coloringMethod >= nar_) |
| 1114 |
{ |
| 1115 |
anOrbit->addChild(setLineAttributesByParameterValue( |
| 1116 |
orbits_[l].par[parID_[coloringMethod-nar_]], |
| 1117 |
parMax_[iBranch][coloringMethod-nar_], |
| 1118 |
parMid_[iBranch][coloringMethod-nar_], |
| 1119 |
parMin_[iBranch][coloringMethod-nar_], |
| 1120 |
stability, scaler)); |
| 1121 |
} |
| 1122 |
else |
| 1123 |
anOrbit->addChild(setLineColorBlending(colorBase, |
| 1124 |
orbits_[l].numVerticesEachPeriod,stability, scaler)); |
| 1125 |
|
| 1126 |
if(style == MESH_POINTS) |
| 1127 |
{ |
| 1128 |
if(m%orbits_[l].ncol == 0) |
| 1129 |
anOrbit->addChild(drawAPoint(xyzCoords_[idx][0], xyzCoords_[idx][1], |
| 1130 |
xyzCoords_[idx][2], dis, STATIONARY_POINT_RADIUS*0.5)); |
| 1131 |
}else |
| 1132 |
anOrbit->addChild(drawAPoint(xyzCoords_[idx][0], xyzCoords_[idx][1], |
| 1133 |
xyzCoords_[idx][2], dis, STATIONARY_POINT_RADIUS*0.5)); |
| 1134 |
} |
| 1135 |
|
| 1136 |
|
| 1137 |
delete [] vertices; |
| 1138 |
delete [] colorBase; |
| 1139 |
|
| 1140 |
return anOrbit; |
| 1141 |
} |
| 1142 |
|
| 1143 |
|
| 1144 |
////////////////////////////////////////////////////////////////////////// |
| 1145 |
// |
| 1146 |
SoSeparator * |
| 1147 |
Solution::drawAnOrbitUsingNurbsCurve(int iBranch, long int l, long int si, |
| 1148 |
float scaler, int stability, int type) |
| 1149 |
// |
| 1150 |
////////////////////////////////////////////////////////////////////////// |
| 1151 |
{ |
| 1152 |
SoSeparator * anOrbit = new SoSeparator; |
| 1153 |
float (*vertices)[3]; |
| 1154 |
vertices = new float[orbits_[l].numVerticesEachPeriod][3]; |
| 1155 |
for(int m=0; m<orbits_[l].numVerticesEachPeriod; m++) |
| 1156 |
{ |
| 1157 |
vertices[m][0]=xyzCoords_[si+m][0]; |
| 1158 |
vertices[m][1]=xyzCoords_[si+m][1]; |
| 1159 |
vertices[m][2]=xyzCoords_[si+m][2]; |
| 1160 |
} |
| 1161 |
SoCoordinate3 *myCoords = new SoCoordinate3; |
| 1162 |
myCoords->point.setValues(0, orbits_[l].numVerticesEachPeriod, vertices); |
| 1163 |
|
| 1164 |
int number = orbits_[l].numVerticesEachPeriod; |
| 1165 |
float * knots = new float[number+4]; |
| 1166 |
for (int i=0; i<4; ++i) knots[i]=0, knots[i+number]=number-3; |
| 1167 |
for(int i=4; i<number; ++i) knots[i]=i-3; |
| 1168 |
SoNurbsCurve *myCurve = new SoNurbsCurve; |
| 1169 |
myCurve->numControlPoints = orbits_[l].numVerticesEachPeriod; |
| 1170 |
myCurve->knotVector.setValues(0, number+4, knots); |
| 1171 |
|
| 1172 |
if(coloringMethod == CL_BRANCH_NUMBER || coloringMethod == CL_CURVE_NUMBER) |
| 1173 |
anOrbit->addChild(setLineAttributesByBranch(iBranch,stability,scaler)); |
| 1174 |
else if(coloringMethod == CL_STABILITY) |
| 1175 |
anOrbit->addChild(setLineAttributesByStability(stability, scaler)); |
| 1176 |
else if(coloringMethod == CL_LABELS) |
| 1177 |
{ |
| 1178 |
anOrbit->addChild(setLineAttributesByParameterValue( |
| 1179 |
l, totalLabels_, totalLabels_/2.0, 0, |
| 1180 |
stability, scaler)); |
| 1181 |
} |
| 1182 |
else |
| 1183 |
anOrbit->addChild(setLineAttributesByType(stability, type, scaler)); |
| 1184 |
anOrbit->addChild(myCoords); |
| 1185 |
anOrbit->addChild(myCurve); |
| 1186 |
delete [] vertices; |
| 1187 |
delete [] knots; |
| 1188 |
return anOrbit; |
| 1189 |
} |
| 1190 |
|
| 1191 |
|
| 1192 |
////////////////////////////////////////////////////////////////////////// |
| 1193 |
// |
| 1194 |
SoSeparator * |
| 1195 |
Solution::drawAnOrbitUsingTubes(int iBranch, long int l, long int si, |
| 1196 |
float scaler, int stability, int type) |
| 1197 |
// |
| 1198 |
////////////////////////////////////////////////////////////////////////// |
| 1199 |
{ |
| 1200 |
float dis = !options[OPT_NORMALIZE_DATA] ? (std::max(std::max( |
| 1201 |
fabs(max_[0]-min_[0]), |
| 1202 |
fabs(max_[1]-min_[1])), |
| 1203 |
fabs(max_[2]-min_[2]))) : 2.0 ; |
| 1204 |
|
| 1205 |
SoSeparator * anOrbit = new SoSeparator; |
| 1206 |
long int numVertices = orbits_[l].numVerticesEachPeriod; |
| 1207 |
if(numVertices == 1) |
| 1208 |
{ |
| 1209 |
int idx = si; |
| 1210 |
SoSeparator * ptSep = new SoSeparator; |
| 1211 |
SoSphere * aPoint = new SoSphere; |
| 1212 |
aPoint->radius = dis * STATIONARY_POINT_RADIUS; |
| 1213 |
|
| 1214 |
if(coloringMethod == CL_BRANCH_NUMBER || coloringMethod == CL_CURVE_NUMBER) |
| 1215 |
ptSep->addChild(setLineAttributesByBranch(iBranch, stability, scaler)); |
| 1216 |
else if(coloringMethod == CL_STABILITY) |
| 1217 |
ptSep->addChild(setLineAttributesByStability(stability, scaler)); |
| 1218 |
else if(coloringMethod == CL_ORBIT_TYPE) |
| 1219 |
ptSep->addChild(setLineAttributesByType(stability, type, scaler)); |
| 1220 |
else if(coloringMethod == CL_LABELS) |
| 1221 |
{ |
| 1222 |
anOrbit->addChild(setLineAttributesByParameterValue( |
| 1223 |
l, totalLabels_, totalLabels_/2.0, 0, |
| 1224 |
stability, scaler)); |
| 1225 |
} |
| 1226 |
else if(coloringMethod == CL_COMPONENT) |
| 1227 |
{ |
| 1228 |
anOrbit->addChild(setLineAttributesByParameterValue( |
| 1229 |
curComponent, maxComponent, maxComponent/2.0, 0, |
| 1230 |
stability, scaler)); |
| 1231 |
} |
| 1232 |
else |
| 1233 |
{ |
| 1234 |
SoMaterial * ptMtl = new SoMaterial; |
| 1235 |
ptMtl->diffuseColor.setValue(1,0,0); |
| 1236 |
ptSep->addChild(ptMtl); |
| 1237 |
} |
| 1238 |
|
| 1239 |
float ver[2][3]; |
| 1240 |
|
| 1241 |
if(time_on != TIME_IS_OFF) |
| 1242 |
{ |
| 1243 |
if(time_on == TIME_ON_X) |
| 1244 |
{ |
| 1245 |
ver[0][0] = (options[OPT_NORMALIZE_DATA]) ? -1 : 0 ; //-(max_[0]-min_[0]) : 0; |
| 1246 |
ver[0][1] = xyzCoords_[idx][1]; |
| 1247 |
ver[0][2] = 0; |
| 1248 |
ver[1][0] = (max_[0] <= 1.0) ? 1.0 : max_[0]; |
| 1249 |
ver[1][1] = xyzCoords_[idx][1]; |
| 1250 |
ver[1][2] = 0; |
| 1251 |
} |
| 1252 |
else if(time_on == TIME_ON_Y) |
| 1253 |
{ |
| 1254 |
ver[0][0] = xyzCoords_[idx][0]; |
| 1255 |
ver[0][1] = (options[OPT_NORMALIZE_DATA]) ? -1 : 0; //-(max_[1]-min_[1]) : 0; |
| 1256 |
ver[0][2] = 0; |
| 1257 |
ver[1][0] = xyzCoords_[idx][0]; |
| 1258 |
ver[1][1] = ( max_[1] <= 1.0 ) ? 1.0 : max_[1]; |
| 1259 |
ver[1][2] = 0; |
| 1260 |
} |
| 1261 |
else if(time_on == TIME_ON_Z) |
| 1262 |
{ |
| 1263 |
ver[0][0] = xyzCoords_[idx][0]; |
| 1264 |
ver[0][1] = 0; |
| 1265 |
ver[0][2] = (options[OPT_NORMALIZE_DATA]) ? -1 : 0; //-(max_[2]-min_[2]) : 0; |
| 1266 |
ver[1][0] = xyzCoords_[idx][0]; |
| 1267 |
ver[1][1] = 0; |
| 1268 |
ver[1][2] = ( max_[2] <= 1.0 ) ? 1.0 : max_[2]; |
| 1269 |
} |
| 1270 |
SoCoordinate3 *myC = new SoCoordinate3; |
| 1271 |
myC->point.setValues(0, 2, ver); |
| 1272 |
int32_t myint[10]; |
| 1273 |
myint[0]=2; |
| 1274 |
SoLineSet *myL = new SoLineSet; |
| 1275 |
myL->numVertices.setValues(0, 1, myint); |
| 1276 |
ptSep->addChild(myC); |
| 1277 |
ptSep->addChild(myL); |
| 1278 |
anOrbit->addChild(ptSep); |
| 1279 |
} |
| 1280 |
else |
| 1281 |
{ |
| 1282 |
SoTransform * aTrans = new SoTransform; |
| 1283 |
aTrans->translation.setValue(xyzCoords_[idx][0], |
| 1284 |
xyzCoords_[idx][1], xyzCoords_[idx][2]); |
| 1285 |
ptSep->addChild(aTrans); |
| 1286 |
SoSphere *aPoint = new SoSphere; |
| 1287 |
aPoint->radius = dis * STATIONARY_POINT_RADIUS; |
| 1288 |
ptSep->addChild(aPoint); |
| 1289 |
anOrbit->addChild(ptSep); |
| 1290 |
} |
| 1291 |
return anOrbit; |
| 1292 |
} |
| 1293 |
else if( numVertices < 1 ) |
| 1294 |
{ |
| 1295 |
return anOrbit; |
| 1296 |
} |
| 1297 |
|
| 1298 |
float (*vertices)[3] = new float[orbits_[l].numVerticesEachPeriod][3]; |
| 1299 |
float *colorBase = new float[orbits_[l].numVerticesEachPeriod*11]; |
| 1300 |
Tube tube; |
| 1301 |
for(int m=0; m<orbits_[l].numVerticesEachPeriod; m++) |
| 1302 |
{ |
| 1303 |
vertices[m][0]=xyzCoords_[si+m][0]; |
| 1304 |
vertices[m][1]=xyzCoords_[si+m][1]; |
| 1305 |
vertices[m][2]=xyzCoords_[si+m][2]; |
| 1306 |
if(coloringMethod>=0) |
| 1307 |
for(int j=0; j<11; ++j) |
| 1308 |
colorBase[m*11+j] = data_[si+m][coloringMethod]; |
| 1309 |
if(coloringMethod==CL_POINT_NUMBER) |
| 1310 |
for(int j=0; j<11; ++j) |
| 1311 |
colorBase[m*11+j] = m; |
| 1312 |
} |
| 1313 |
tube = Tube(orbits_[l].numVerticesEachPeriod, vertices, lineWidthScaler*0.005, 10); |
| 1314 |
|
| 1315 |
if(coloringMethod == CL_BRANCH_NUMBER || coloringMethod == CL_CURVE_NUMBER) |
| 1316 |
anOrbit->addChild(setLineAttributesByBranch(iBranch, stability, scaler)); |
| 1317 |
else if(coloringMethod == CL_STABILITY) |
| 1318 |
anOrbit->addChild(setLineAttributesByStability(stability, scaler)); |
| 1319 |
else if(coloringMethod == CL_ORBIT_TYPE) |
| 1320 |
anOrbit->addChild(setLineAttributesByType(stability, type, scaler)); |
| 1321 |
else if(coloringMethod == CL_LABELS) |
| 1322 |
// always set the first label blue, the last red, namely look all |
| 1323 |
// branches as one. |
| 1324 |
anOrbit->addChild(setLineAttributesByParameterValue( |
| 1325 |
l, totalLabels_, totalLabels_/2.0, 0, |
| 1326 |
stability, scaler)); |
| 1327 |
else if(coloringMethod == CL_COMPONENT) |
| 1328 |
anOrbit->addChild(setLineAttributesByParameterValue( |
| 1329 |
curComponent, maxComponent, maxComponent/2.0, 0, |
| 1330 |
stability, scaler)); |
| 1331 |
else if(coloringMethod >= nar_) |
| 1332 |
anOrbit->addChild(setLineAttributesByParameterValue( |
| 1333 |
orbits_[l].par[parID_[coloringMethod-nar_]], |
| 1334 |
parMax_[iBranch][coloringMethod-nar_], |
| 1335 |
parMid_[iBranch][coloringMethod-nar_], |
| 1336 |
parMin_[iBranch][coloringMethod-nar_], |
| 1337 |
stability, scaler)); |
| 1338 |
else |
| 1339 |
anOrbit->addChild(setLineColorBlending(colorBase, |
| 1340 |
orbits_[l].numVerticesEachPeriod*11,stability, scaler)); |
| 1341 |
|
| 1342 |
anOrbit->addChild(tube.createTube()); |
| 1343 |
|
| 1344 |
delete [] vertices; |
| 1345 |
return anOrbit; |
| 1346 |
} |
| 1347 |
|
| 1348 |
/////////////////////////////////////////////////////////////////////////// |
| 1349 |
// |
| 1350 |
// animate solution by using tubes. |
| 1351 |
// animate solution by using tubes. This version use much memory and |
| 1352 |
// much slower. |
| 1353 |
// |
| 1354 |
SoSeparator * |
| 1355 |
Solution::animateUsingTubes(bool aniColoring) |
| 1356 |
// |
| 1357 |
/////////////////////////////////////////////////////////////////////////// |
| 1358 |
{ |
| 1359 |
long int sumX = 0; |
| 1360 |
SoSeparator *solGroup = new SoSeparator; |
| 1361 |
|
| 1362 |
float dis = !options[OPT_NORMALIZE_DATA] ? (std::max(std::max( |
| 1363 |
fabs(max_[0]-min_[0]), |
| 1364 |
fabs(max_[1]-min_[1])), |
| 1365 |
fabs(max_[2]-min_[2]))) : 2.0; |
| 1366 |
|
| 1367 |
SoBlinker *tubeBlker = new SoBlinker; |
| 1368 |
tubeBlker->speed = orbitSpeed; |
| 1369 |
int iBranch = 0; |
| 1370 |
int sumOrbit = numOrbitsInEachBranch_[iBranch]; |
| 1371 |
for(int j=0; j<numOrbits_; j++) |
| 1372 |
{ |
| 1373 |
long int upperlimit = orbits_[j].numVerticesEachPeriod; |
| 1374 |
if(upperlimit == 1) |
| 1375 |
{ |
| 1376 |
int idx = sumX; |
| 1377 |
SoSeparator * ptSep = new SoSeparator; |
| 1378 |
SoSphere * aPoint = new SoSphere; |
| 1379 |
aPoint->radius = dis * STATIONARY_POINT_RADIUS; |
| 1380 |
|
| 1381 |
SoTransform * aTrans = new SoTransform; |
| 1382 |
aTrans->translation.setValue(xyzCoords_[idx][0], |
| 1383 |
xyzCoords_[idx][1], |
| 1384 |
xyzCoords_[idx][2]); |
| 1385 |
ptSep->addChild(aTrans); |
| 1386 |
ptSep->addChild(aPoint); |
| 1387 |
solGroup->addChild(ptSep); |
| 1388 |
} |
| 1389 |
else |
| 1390 |
{ |
| 1391 |
float (*path)[3] = new float[upperlimit][3]; |
| 1392 |
float *colorBase = new float[upperlimit*11]; |
| 1393 |
int stability=clientData.labelIndex[j][3]; |
| 1394 |
int type =clientData.labelIndex[j][2]; |
| 1395 |
SoSeparator *anOrbit = new SoSeparator; |
| 1396 |
Tube tube; |
| 1397 |
if(j >= sumOrbit) |
| 1398 |
{ |
| 1399 |
sumOrbit += numOrbitsInEachBranch_[++iBranch]; |
| 1400 |
} |
| 1401 |
|
| 1402 |
for(int i=0; i<upperlimit; i++) |
| 1403 |
{ |
| 1404 |
int idx = i+sumX; |
| 1405 |
path[i][0]=xyzCoords_[idx][0]; |
| 1406 |
path[i][1]=xyzCoords_[idx][1]; |
| 1407 |
path[i][2]=xyzCoords_[idx][2]; |
| 1408 |
if(coloringMethod>=0) |
| 1409 |
for(int j=0; j<11; ++j) |
| 1410 |
colorBase[i*11+j] = data_[idx][coloringMethod]; |
| 1411 |
if(coloringMethod==CL_POINT_NUMBER) |
| 1412 |
for(int j=0; j<11; ++j) |
| 1413 |
colorBase[i*11+j] = i; |
| 1414 |
} |
| 1415 |
|
| 1416 |
if(!aniColoring) |
| 1417 |
anOrbit->addChild(setLineAttributesByType(stability, 0, lineWidthScaler)); |
| 1418 |
else if(coloringMethod == CL_STABILITY) |
| 1419 |
anOrbit->addChild(setLineAttributesByStability(stability, lineWidthScaler)); |
| 1420 |
else if(coloringMethod == CL_BRANCH_NUMBER || coloringMethod == CL_CURVE_NUMBER) |
| 1421 |
anOrbit->addChild(setLineAttributesByBranch(iBranch, stability, lineWidthScaler)); |
| 1422 |
else if(coloringMethod == CL_ORBIT_TYPE) |
| 1423 |
anOrbit->addChild(setLineAttributesByType(stability, type, lineWidthScaler)); |
| 1424 |
else if(coloringMethod == CL_LABELS) |
| 1425 |
anOrbit->addChild(setLineAttributesByParameterValue( |
| 1426 |
j, totalLabels_, totalLabels_/2.0, 0, |
| 1427 |
stability, lineWidthScaler)); |
| 1428 |
else if(coloringMethod >= nar_) |
| 1429 |
anOrbit->addChild(setLineAttributesByParameterValue( |
| 1430 |
orbits_[j].par[parID_[coloringMethod-nar_]], |
| 1431 |
parMax_[iBranch][coloringMethod-nar_], |
| 1432 |
parMid_[iBranch][coloringMethod-nar_], |
| 1433 |
parMin_[iBranch][coloringMethod-nar_], |
| 1434 |
stability, lineWidthScaler)); |
| 1435 |
else if(coloringMethod == CL_COMPONENT) |
| 1436 |
anOrbit->addChild(setLineAttributesByParameterValue( |
| 1437 |
curComponent, maxComponent, maxComponent/2.0, 0, |
| 1438 |
stability, lineWidthScaler)); |
| 1439 |
else |
| 1440 |
anOrbit->addChild(setLineColorBlending(colorBase, |
| 1441 |
upperlimit*11,stability, lineWidthScaler)); |
| 1442 |
|
| 1443 |
tube = Tube(upperlimit, path, lineWidthScaler*0.0075, 10); |
| 1444 |
anOrbit->addChild(tube.createTube()); |
| 1445 |
tubeBlker->addChild(anOrbit); |
| 1446 |
delete [] path; |
| 1447 |
delete [] colorBase; |
| 1448 |
} |
| 1449 |
sumX += upperlimit; |
| 1450 |
} |
| 1451 |
solGroup->addChild(tubeBlker); |
| 1452 |
return solGroup; |
| 1453 |
} |
| 1454 |
|
| 1455 |
|
| 1456 |
/////////////////////////////////////////////////////////////////////////// |
| 1457 |
// Using a red ball to simulate the movement of a sattelite and using |
| 1458 |
// white lines to simulate the trace of the sattelite. |
| 1459 |
// |
| 1460 |
SoSeparator * |
| 1461 |
Solution::animateOrbitWithTail(int iBranch, long int j, long int si) |
| 1462 |
// |
| 1463 |
/////////////////////////////////////////////////////////////////////////// |
| 1464 |
{ |
| 1465 |
SoSeparator *satGroup = new SoSeparator; |
| 1466 |
|
| 1467 |
float distance = !options[OPT_NORMALIZE_DATA] ? (std::max(std::max( |
| 1468 |
fabs(max_[0]-min_[0]), |
| 1469 |
fabs(max_[1]-min_[1])), |
| 1470 |
fabs(max_[2]-min_[2]))) : 2.0; |
| 1471 |
int stability = clientData.labelIndex[j][3]; |
| 1472 |
int type = clientData.labelIndex[j][2]; |
| 1473 |
|
| 1474 |
long int upperlimit = orbits_[j].numVerticesEachPeriod; |
| 1475 |
long int idx = si; |
| 1476 |
if(upperlimit == 1) |
| 1477 |
{ |
| 1478 |
SoSeparator * ptSep = new SoSeparator; |
| 1479 |
SoTransform * aTrans = new SoTransform; |
| 1480 |
aTrans->translation.setValue(xyzCoords_[idx][0], |
| 1481 |
xyzCoords_[idx][1], |
| 1482 |
xyzCoords_[idx][2]); |
| 1483 |
ptSep->addChild(aTrans); |
| 1484 |
|
| 1485 |
SoSphere * aPoint = new SoSphere; |
| 1486 |
aPoint->radius = distance * STATIONARY_POINT_RADIUS; |
| 1487 |
ptSep->addChild(aPoint); |
| 1488 |
satGroup->addChild(ptSep); |
| 1489 |
return satGroup; |
| 1490 |
} |
| 1491 |
|
| 1492 |
float maxV[3], minV[3]; |
| 1493 |
long int orbitSize = upperlimit; |
| 1494 |
long int arrSize = orbitSize; |
| 1495 |
|
| 1496 |
double *time = new double[upperlimit+1]; |
| 1497 |
double dt = 1.0/upperlimit; |
| 1498 |
|
| 1499 |
maxV[0]=minV[0]=xyzCoords_[idx+0][0]; |
| 1500 |
maxV[1]=minV[1]=xyzCoords_[idx+0][0]; |
| 1501 |
maxV[2]=minV[2]=xyzCoords_[idx+0][0]; |
| 1502 |
|
| 1503 |
time[0] = 0.0; |
| 1504 |
for(long int i=1; i<upperlimit; i++) |
| 1505 |
{ |
| 1506 |
if(maxV[0]<xyzCoords_[idx+i][0]) maxV[0]=xyzCoords_[idx+i][0] ; |
| 1507 |
if(minV[0]>xyzCoords_[idx+i][0]) minV[0]=xyzCoords_[idx+i][0] ; |
| 1508 |
if(maxV[1]<xyzCoords_[idx+i][1]) maxV[1]=xyzCoords_[idx+i][1] ; |
| 1509 |
if(minV[1]>xyzCoords_[idx+i][1]) minV[1]=xyzCoords_[idx+i][1] ; |
| 1510 |
if(maxV[2]<xyzCoords_[idx+i][2]) maxV[2]=xyzCoords_[idx+i][2] ; |
| 1511 |
if(minV[2]>xyzCoords_[idx+i][2]) minV[2]=xyzCoords_[idx+i][2] ; |
| 1512 |
time[i] = i*dt; |
| 1513 |
} |
| 1514 |
|
| 1515 |
float dis = distance;// fabs(std::max(std::max((maxV[0]-minV[0]), (maxV[1]-minV[1])), (maxV[2]-minV[2]))); |
| 1516 |
float (*myVertices)[3]= new float[arrSize+1][3]; |
| 1517 |
float *myColorBase = new float [arrSize+1]; |
| 1518 |
|
| 1519 |
myVertices[0][0] = myVertices[arrSize][0] = xyzCoords_[idx][0]; |
| 1520 |
myVertices[0][1] = myVertices[arrSize][1] = xyzCoords_[idx][1]; |
| 1521 |
myVertices[0][2] = myVertices[arrSize][2] = xyzCoords_[idx][2]; |
| 1522 |
if(coloringMethod>=0)myColorBase[0] = data_[idx][coloringMethod]; |
| 1523 |
if(coloringMethod==CL_POINT_NUMBER)myColorBase[0] = 0; |
| 1524 |
for(long int i=1; i<upperlimit; i++) |
| 1525 |
{ |
| 1526 |
double tTemp = time[i]; |
| 1527 |
long int m = 0; |
| 1528 |
while(tTemp > time_[idx+m] && m < upperlimit) ++m; |
| 1529 |
|
| 1530 |
if( fabs(tTemp-time_[idx+m]) <= 1.0e-9 || |
| 1531 |
fabs(time_[idx+m]-time_[idx+m-1])<=1.0e-8) |
| 1532 |
{ |
| 1533 |
myVertices[i][0] = xyzCoords_[idx+m][0]; |
| 1534 |
myVertices[i][1] = xyzCoords_[idx+m][1]; |
| 1535 |
myVertices[i][2] = xyzCoords_[idx+m][2]; |
| 1536 |
} |
| 1537 |
else |
| 1538 |
{ |
| 1539 |
myVertices[i][0] = (xyzCoords_[idx+m][0] + |
| 1540 |
xyzCoords_[idx+m-1][0])*0.5; |
| 1541 |
myVertices[i][1] = (xyzCoords_[idx+m][1] + |
| 1542 |
xyzCoords_[idx+m-1][1])*0.5; |
| 1543 |
myVertices[i][2] = (xyzCoords_[idx+m][2] + |
| 1544 |
xyzCoords_[idx+m-1][2])*0.5; |
| 1545 |
} |
| 1546 |
|
| 1547 |
if(coloringMethod>=0)myColorBase[i] = data_[idx+m][coloringMethod]; |
| 1548 |
if(coloringMethod==CL_POINT_NUMBER)myColorBase[i] = i; |
| 1549 |
} |
| 1550 |
|
| 1551 |
SoDrawStyle *satStyle = new SoDrawStyle; |
| 1552 |
satStyle->style = SoDrawStyle::FILLED; |
| 1553 |
satGroup->addChild(satStyle); |
| 1554 |
|
| 1555 |
SoCoordinate3 *myCoords = new SoCoordinate3; |
| 1556 |
myCoords->point.setValues(0, arrSize+1, myVertices); |
| 1557 |
satGroup->addChild(myCoords); |
| 1558 |
|
| 1559 |
|
| 1560 |
SoTimeCounter *myCounter = new SoTimeCounter; |
| 1561 |
myCounter->max = arrSize+1; |
| 1562 |
myCounter->min = 0; |
| 1563 |
|
| 1564 |
float freq, fduty; |
| 1565 |
|
| 1566 |
if ( numPeriodAnimated == -1 ) |
| 1567 |
{ |
| 1568 |
freq = 0.1*satSpeed/128; |
| 1569 |
fduty = 127*arrSize; |
| 1570 |
} |
| 1571 |
else if( numPeriodAnimated == 0 ) |
| 1572 |
{ |
| 1573 |
freq = 0; |
| 1574 |
fduty = 0; |
| 1575 |
} |
| 1576 |
else if ( numPeriodAnimated == 1 ){ |
| 1577 |
freq = 0.1*satSpeed; |
| 1578 |
fduty = 1; |
| 1579 |
} |
| 1580 |
else { |
| 1581 |
freq = 0.1*satSpeed/numPeriodAnimated; |
| 1582 |
fduty = (numPeriodAnimated-1)*arrSize; |
| 1583 |
} |
| 1584 |
|
| 1585 |
myCounter->frequency = freq ; |
| 1586 |
|
| 1587 |
int iduty = 0; |
| 1588 |
for(iduty = 0; iduty <= arrSize+1; ++iduty) |
| 1589 |
if(iduty == arrSize+1) myCounter->duty.set1Value(iduty, fduty) ; |
| 1590 |
else myCounter->duty.set1Value(iduty, 1) ; |
| 1591 |
|
| 1592 |
//------------------------------------------Begin----------------------------------------- |
| 1593 |
float scaler = lineWidthScaler; |
| 1594 |
|
| 1595 |
//------------------------------------------End----------------------------------------- |
| 1596 |
if(coloringMethod == CL_BRANCH_NUMBER || coloringMethod == CL_CURVE_NUMBER) |
| 1597 |
satGroup->addChild(setLineAttributesByBranch(iBranch, stability, lineWidthScaler)); |
| 1598 |
else if(coloringMethod == CL_STABILITY) |
| 1599 |
satGroup->addChild(setLineAttributesByStability(stability, lineWidthScaler)); |
| 1600 |
else if(coloringMethod == CL_ORBIT_TYPE) |
| 1601 |
satGroup->addChild(setLineAttributesByType(stability, type, lineWidthScaler)); |
| 1602 |
else if(coloringMethod == CL_LABELS) |
| 1603 |
satGroup->addChild(setLineAttributesByParameterValue( |
| 1604 |
j-1, totalLabels_, totalLabels_/2.0, 0, |
| 1605 |
stability, lineWidthScaler)); |
| 1606 |
else if(coloringMethod == CL_COMPONENT) |
| 1607 |
satGroup->addChild(setLineAttributesByParameterValue( |
| 1608 |
curComponent, maxComponent, maxComponent/2.0, 0, |
| 1609 |
stability, scaler)); |
| 1610 |
else if(coloringMethod >= nar_) |
| 1611 |
satGroup->addChild(setLineAttributesByParameterValue( |
| 1612 |
orbits_[j].par[parID_[coloringMethod-nar_]], |
| 1613 |
parMax_[iBranch][coloringMethod-nar_], |
| 1614 |
parMid_[iBranch][coloringMethod-nar_], |
| 1615 |
parMin_[iBranch][coloringMethod-nar_], |
| 1616 |
stability, lineWidthScaler)); |
| 1617 |
else |
| 1618 |
satGroup->addChild(setLineColorBlending(myColorBase, arrSize, |
| 1619 |
stability, lineWidthScaler)); |
| 1620 |
|
| 1621 |
// define the solution line set |
| 1622 |
SoLineSet *myLine= new SoLineSet; |
| 1623 |
myLine->numVertices.connectFrom(&myCounter->output); |
| 1624 |
satGroup->addChild(myLine); |
| 1625 |
|
| 1626 |
SoSphere * mySat = new SoSphere; |
| 1627 |
mySat->radius = satRadius*dis*0.005; |
| 1628 |
|
| 1629 |
|
| 1630 |
SoTranslation * satTrans = new SoTranslation; |
| 1631 |
SoMaterial * satMtl = new SoMaterial; |
| 1632 |
satMtl->diffuseColor.setValue(envColors[7]); |
| 1633 |
satGroup->addChild(satMtl); |
| 1634 |
satGroup->addChild(satTrans); |
| 1635 |
satGroup->addChild(mySat); |
| 1636 |
|
| 1637 |
SoTimeCounter *myCounter2 = new SoTimeCounter; |
| 1638 |
myCounter2->max = arrSize; |
| 1639 |
myCounter2->min = 0; |
| 1640 |
if (numPeriodAnimated != 0) |
| 1641 |
myCounter2->frequency = 0.1*satSpeed;//*numPeriodAnimated; |
| 1642 |
else |
| 1643 |
myCounter2->frequency = 0.1*satSpeed; |
| 1644 |
for(iduty = 0; iduty < arrSize; ++iduty) |
| 1645 |
myCounter2->duty.set1Value(iduty, 1) ; |
| 1646 |
|
| 1647 |
SoSelectOne *mysel = new SoSelectOne(SoMFVec3f::getClassTypeId()); |
| 1648 |
mysel->index.connectFrom(&myCounter2->output); |
| 1649 |
mysel->input->enableConnection(TRUE); |
| 1650 |
mysel->input->connectFrom(&myCoords->point); |
| 1651 |
satTrans->translation.connectFrom(mysel->output); |
| 1652 |
|
| 1653 |
delete [] myVertices; |
| 1654 |
delete [] myColorBase; |
| 1655 |
delete [] time; |
| 1656 |
return satGroup; |
| 1657 |
} |
| 1658 |
|
| 1659 |
//////////////////////////////////////////////////////////////////////// |
| 1660 |
// |
| 1661 |
// |
| 1662 |
// |
| 1663 |
void |
| 1664 |
Solution::copyDataToWorkArray(int varIndices[], int cur, int mx, int to) |
| 1665 |
// |
| 1666 |
//////////////////////////////////////////////////////////////////////// |
| 1667 |
{ |
| 1668 |
curComponent = cur; |
| 1669 |
maxComponent = mx; |
| 1670 |
time_on = to; |
| 1671 |
for(int k=0; k<3; k++) |
| 1672 |
{ |
| 1673 |
for(long int row=0; row<totalNumPoints_; ++row) |
| 1674 |
{ |
| 1675 |
time_[row] = data_[row][0]; |
| 1676 |
if(varIndices[k]>=0) |
| 1677 |
{ |
| 1678 |
float dummy = data_[row][varIndices[k]]; |
| 1679 |
xyzCoords_[row][k] = dummy; |
| 1680 |
} |
| 1681 |
else if(varIndices[k]<0) |
| 1682 |
{ |
| 1683 |
xyzCoords_[row][k]=0.0; |
| 1684 |
} |
| 1685 |
} |
| 1686 |
} |
| 1687 |
} |
| 1688 |
|
| 1689 |
////////////////////////////////////////////////////////////////////////// |
| 1690 |
// |
| 1691 |
SoSeparator * |
| 1692 |
Solution::drawAPoint(float x, float y, float z, float size, float scale) |
| 1693 |
// |
| 1694 |
////////////////////////////////////////////////////////////////////////// |
| 1695 |
{ |
| 1696 |
SoSeparator * ptSep = new SoSeparator; |
| 1697 |
SoTransform * ptTrans = new SoTransform; |
| 1698 |
ptTrans->translation.setValue(x, y, z); |
| 1699 |
ptSep->addChild(ptTrans); |
| 1700 |
|
| 1701 |
SoCube *aPoint = new SoCube; |
| 1702 |
aPoint->width = size*scale; |
| 1703 |
aPoint->height= size*scale; |
| 1704 |
aPoint->depth = size*scale; |
| 1705 |
ptSep->addChild(aPoint); |
| 1706 |
return ptSep; |
| 1707 |
} |
| 1708 |
|
| 1709 |
//////////////////////////////// START /////////////////////////////// |
| 1710 |
// |
| 1711 |
// draw a strip by giving the stripset |
| 1712 |
SoSeparator * |
| 1713 |
Solution::drawAStrip(float stripSet[][3], int size) |
| 1714 |
// |
| 1715 |
////////////////////////////////////////////////////////////////////// |
| 1716 |
{ |
| 1717 |
SoSeparator * myStrip = new SoSeparator; |
| 1718 |
SoShapeHints * solHints = new SoShapeHints; |
| 1719 |
solHints->vertexOrdering = SoShapeHints::COUNTERCLOCKWISE; |
| 1720 |
myStrip->addChild(solHints); |
| 1721 |
|
| 1722 |
SoCoordinate3 *solCoords = new SoCoordinate3; |
| 1723 |
solCoords->point.setValues(0, size, stripSet); |
| 1724 |
|
| 1725 |
int32_t mySize[1]; |
| 1726 |
mySize[0] = size; |
| 1727 |
SoTriangleStripSet *solStrips = new SoTriangleStripSet; |
| 1728 |
solStrips->numVertices.setValues(0, 1, mySize); |
| 1729 |
|
| 1730 |
myStrip->addChild(solCoords); |
| 1731 |
myStrip->addChild(solStrips); |
| 1732 |
return myStrip; |
| 1733 |
} |
| 1734 |
|
| 1735 |
//////////////////////////////////////////////////////////////////////// |
| 1736 |
// |
| 1737 |
// |
| 1738 |
// |
| 1739 |
void |
| 1740 |
Solution::searchForMaxMin(int component, int varIndices[]) |
| 1741 |
// |
| 1742 |
//////////////////////////////////////////////////////////////////////// |
| 1743 |
{ |
| 1744 |
double mx, mi; |
| 1745 |
for(int k=0; k<3; k++) |
| 1746 |
{ |
| 1747 |
for(long int row=0; row<totalNumPoints_; ++row) |
| 1748 |
{ |
| 1749 |
if(varIndices[k]>=0) |
| 1750 |
{ |
| 1751 |
float dummy = data_[row][varIndices[k]]; |
| 1752 |
if(dummy>max_[k] || (row==0 && component==1)) |
| 1753 |
max_[k] = dummy; |
| 1754 |
if(dummy<min_[k] || (row==0 && component==1)) |
| 1755 |
min_[k] = dummy; |
| 1756 |
} |
| 1757 |
else if(varIndices[k]<0) |
| 1758 |
{ |
| 1759 |
max_[k]= 1; |
| 1760 |
min_[k]=-1; |
| 1761 |
} |
| 1762 |
} |
| 1763 |
mx = max_[k]; |
| 1764 |
mi = min_[k]; |
| 1765 |
rounding(mx, mi); |
| 1766 |
max_[k] = mx; |
| 1767 |
min_[k] = mi; |
| 1768 |
} |
| 1769 |
} |
| 1770 |
|
| 1771 |
/////////////////////////////////////////////////////////////////////////////////////// |
| 1772 |
//////////////////////////////////////////////////////////////////////////////// |
| 1773 |
// |
| 1774 |
bool Solution::parse( const char* sFileName ) |
| 1775 |
// |
| 1776 |
/////////////////////////////////////////////////////////////////////////////////////// |
| 1777 |
//////////////////////////////////////////////////////////////////////////////// |
| 1778 |
{ |
| 1779 |
FILE * inFile; |
| 1780 |
long int position, i; |
| 1781 |
int ibr,ntot,itp,lab,nfpr,isw,ntpl,nar,nrowpr,ntst,ncol,npar1; |
| 1782 |
int maxColSize=0; |
| 1783 |
long int branchCounter = 0; |
| 1784 |
long int lastBranchID = -999; |
| 1785 |
totalLabels_ = 0; |
| 1786 |
totalNumPoints_ = 0; |
| 1787 |
|
| 1788 |
// Open input file |
| 1789 |
if((inFile=fopen(sFileName,"r"))==NULL) |
| 1790 |
{ |
| 1791 |
printf(" Cannot open input file : %s ! \n", sFileName); |
| 1792 |
nar_ = maxColSize; |
| 1793 |
return false; |
| 1794 |
} |
| 1795 |
|
| 1796 |
long int totalNumPoints= 0; |
| 1797 |
position = ftell(inFile); |
| 1798 |
|
| 1799 |
long int total = 0; |
| 1800 |
while(fscanf(inFile,"%d %d %d %d %d %d %d %d %d %d %d %d", |
| 1801 |
&ibr,&ntot,&itp,&lab,&nfpr,&isw,&ntpl,&nar, |
| 1802 |
&nrowpr,&ntst,&ncol,&npar1) == 12) |
| 1803 |
{ |
| 1804 |
if(maxColSize < nar) maxColSize = nar; |
| 1805 |
if(lastBranchID == -999) lastBranchID = ibr; |
| 1806 |
if(lastBranchID != ibr && lastBranchID != -999) { |
| 1807 |
branchCounter++; |
| 1808 |
lastBranchID = ibr; |
| 1809 |
} |
| 1810 |
|
| 1811 |
totalNumPoints += (ntpl != 1) ? ntpl : 2; |
| 1812 |
positions_.push(position); |
| 1813 |
|
| 1814 |
for(i=0;i<nrowpr+1;i++) |
| 1815 |
while(fgetc(inFile)!='\n'); |
| 1816 |
|
| 1817 |
if(ntpl != 0) |
| 1818 |
{ |
| 1819 |
total=total+1; |
| 1820 |
} |
| 1821 |
|
| 1822 |
position = ftell(inFile); |
| 1823 |
} |
| 1824 |
|
| 1825 |
fclose(inFile); |
| 1826 |
|
| 1827 |
totalLabels_ = total; |
| 1828 |
numOrbits_ = total; |
| 1829 |
totalNumPoints_ = totalNumPoints; |
| 1830 |
numBranches_ = ++branchCounter; |
| 1831 |
nar_ = maxColSize; |
| 1832 |
return true; |
| 1833 |
} |
| 1834 |
|
| 1835 |
|
| 1836 |
/////////////////////////////////////////////////////////////////////// |
| 1837 |
// |
| 1838 |
// READ solution (orbits) to the array |
| 1839 |
// |
| 1840 |
bool Solution::read(const char* sFileName, int varIndices[]) |
| 1841 |
// |
| 1842 |
/////////////////////////////////////////////////////////////////////// |
| 1843 |
|
| 1844 |
{ |
| 1845 |
FILE * inFile; |
| 1846 |
int ibr,ntot,itp,lab,nfpr,isw,ntpl,nar,nrowpr,ntst,ncol,npar1; |
| 1847 |
long int i, j; |
| 1848 |
float dummy; |
| 1849 |
char line[MAX_LINE_LENGTH]; |
| 1850 |
|
| 1851 |
if((inFile = fopen(sFileName,"r")) == NULL) |
| 1852 |
{ |
| 1853 |
printf(" Cannot open input file: %s\n", sFileName); |
| 1854 |
return false; |
| 1855 |
} |
| 1856 |
|
| 1857 |
totalNumPoints_ = 0; |
| 1858 |
for(i=0; i<3; i++) |
| 1859 |
{ |
| 1860 |
max_[i]=0.0; |
| 1861 |
min_[i]=0.0; |
| 1862 |
} |
| 1863 |
long int counter = 0; |
| 1864 |
long int orbitCounter = 0; |
| 1865 |
long int row = 0; |
| 1866 |
long int branchCounter = 0; |
| 1867 |
long int lastBranchID = -999; |
| 1868 |
long int totalNumPointsInEachBranch= 0; |
| 1869 |
int lbStability = 0; |
| 1870 |
|
| 1871 |
orbits_[0].label=0; |
| 1872 |
orbits_[0].ntst=0; |
| 1873 |
orbits_[0].ncol=0; |
| 1874 |
|
| 1875 |
while(!positions_.empty()) |
| 1876 |
{ |
| 1877 |
fseek(inFile,positions_.front(),SEEK_SET); |
| 1878 |
positions_.pop(); |
| 1879 |
|
| 1880 |
fscanf(inFile,"%d %d %d %d %d %d %d %d %d %d %d %d",\ |
| 1881 |
&ibr,&ntot,&itp,&lab,&nfpr,&isw,&ntpl,&nar,\ |
| 1882 |
&nrowpr,&ntst,&ncol,&npar1); |
| 1883 |
if(lastBranchID == -999) lastBranchID = ibr; |
| 1884 |
if(lastBranchID != ibr && lastBranchID != -999) |
| 1885 |
{ |
| 1886 |
numVerticesEachBranch_[branchCounter]=totalNumPointsInEachBranch; |
| 1887 |
numOrbitsInEachBranch_[branchCounter]=orbitCounter; |
| 1888 |
branchID_[branchCounter++]=lastBranchID; |
| 1889 |
totalNumPointsInEachBranch = 0; |
| 1890 |
lastBranchID = ibr; |
| 1891 |
orbitCounter = 0; |
| 1892 |
} |
| 1893 |
clientData.labelIndex[counter][0] = row; |
| 1894 |
clientData.labelIndex[counter][2] = itp; |
| 1895 |
|
| 1896 |
if(ibr > 0) |
| 1897 |
{ |
| 1898 |
lbStability = ((ntot>0) ? 1 : 2); |
| 1899 |
} |
| 1900 |
else |
| 1901 |
{ |
| 1902 |
lbStability = ((ntot>0) ? 3 : 4); |
| 1903 |
} |
| 1904 |
|
| 1905 |
clientData.labelIndex[counter][3] = lbStability; |
| 1906 |
|
| 1907 |
if( ntpl != 0) |
| 1908 |
{ |
| 1909 |
orbits_[counter].numVerticesEachPeriod=ntpl; |
| 1910 |
orbits_[counter].label = lab; |
| 1911 |
orbits_[counter].ntst = ntst; |
| 1912 |
orbits_[counter].ncol = ncol; |
| 1913 |
orbitCounter++; |
| 1914 |
} |
| 1915 |
|
| 1916 |
while(fgetc(inFile)!='\n'); |
| 1917 |
{ |
| 1918 |
{ |
| 1919 |
for(i=0; i<ntpl; ++i) |
| 1920 |
{ |
| 1921 |
++(totalNumPoints_); |
| 1922 |
++totalNumPointsInEachBranch; |
| 1923 |
for(j=0; j<nar; ++j) |
| 1924 |
{ |
| 1925 |
// read all the data set to the dynamic array. |
| 1926 |
char dummystr[25]; |
| 1927 |
fscanf(inFile,"%24s",dummystr); |
| 1928 |
dummy=fortranatof(dummystr); |
| 1929 |
data_[row][j]=dummy; |
| 1930 |
if(row == 0) clientData.solMax[j] = dummy; |
| 1931 |
else |
| 1932 |
if(clientData.solMax[j] < dummy) clientData.solMax[j] = dummy; |
| 1933 |
if(row == 0) clientData.solMin[j] = dummy; |
| 1934 |
else |
| 1935 |
if(clientData.solMin[j] > dummy) clientData.solMin[j] = dummy; |
| 1936 |
} |
| 1937 |
++row; |
| 1938 |
} |
| 1939 |
|
| 1940 |
int nLines = (npar1+6)/7; |
| 1941 |
int nrowprsmall = ((nar-1)/7+1)*ntpl + nLines; |
| 1942 |
if(ntst != 0 && nrowpr > nrowprsmall) |
| 1943 |
{ |
| 1944 |
int ndim=nar-1; |
| 1945 |
int nrd=(ndim+6)/7; |
| 1946 |
int nLines = nrd*ntpl + (nfpr+6)/7 + (nfpr+19)/20; |
| 1947 |
for(i=0; i<nLines; ++i) fgets(line, sizeof(line), inFile); |
| 1948 |
} |
| 1949 |
|
| 1950 |
orbits_[counter].par = new double[npar1]; |
| 1951 |
for(int nzoo = 0; nzoo<nLines; ++nzoo) |
| 1952 |
{ |
| 1953 |
fgets(line, sizeof(line), inFile); |
| 1954 |
int xCol = (npar1 - nzoo*7) > 7 ? 7 : npar1 - nzoo*7; |
| 1955 |
for(i=0; i<xCol; ++i) |
| 1956 |
{ |
| 1957 |
char dummystr[25]; |
| 1958 |
fscanf(inFile,"%*[ \t\n]"); |
| 1959 |
fscanf(inFile,"%24[^ \t\n]",dummystr); |
| 1960 |
dummy=fortranatof(dummystr); |
| 1961 |
if(dummy != 0) |
| 1962 |
{ |
| 1963 |
orbits_[counter].par[nzoo*7+i] = dummy; |
| 1964 |
if( nzoo*7+i==1 ) orbits_[counter].mass = dummy; |
| 1965 |
else if( nzoo*7+i==10 ) orbits_[counter].period=dummy; |
| 1966 |
} |
| 1967 |
} |
| 1968 |
} |
| 1969 |
} |
| 1970 |
} |
| 1971 |
if( ntpl != 0) |
| 1972 |
counter++; |
| 1973 |
} |
| 1974 |
numVerticesEachBranch_[branchCounter]=totalNumPointsInEachBranch; |
| 1975 |
numOrbitsInEachBranch_[branchCounter]=orbitCounter; |
| 1976 |
branchID_[branchCounter]=ibr; |
| 1977 |
|
| 1978 |
totalLabels_ = counter; |
| 1979 |
numOrbits_ = counter; |
| 1980 |
|
| 1981 |
|
| 1982 |
double parMax, parMin, parMid; |
| 1983 |
|
| 1984 |
for(int jv = 0; jv<npar_; ++jv) |
| 1985 |
{ |
| 1986 |
long int startBranch = 0; |
| 1987 |
long int endBranch = 0; |
| 1988 |
for(int iBranch=0; iBranch<numBranches_; iBranch++) |
| 1989 |
{ |
| 1990 |
int parid = parID_[jv]; |
| 1991 |
parMax = parMin = parMid = orbits_[startBranch].par[parid]; |
| 1992 |
endBranch = startBranch+numOrbitsInEachBranch_[iBranch]; |
| 1993 |
for(int innerLoop = startBranch; innerLoop<endBranch; ++innerLoop) |
| 1994 |
{ |
| 1995 |
float par = orbits_[innerLoop].par[parID_[jv]]; |
| 1996 |
if(parMax < par) |
| 1997 |
parMax = par; |
| 1998 |
if(parMin > par) |
| 1999 |
parMin = par; |
| 2000 |
} |
| 2001 |
parMax_[iBranch][jv]=parMax; |
| 2002 |
parMin_[iBranch][jv]=parMin; |
| 2003 |
parMid_[iBranch][jv]=(parMin+parMax)/2.0; |
| 2004 |
startBranch = endBranch; |
| 2005 |
} |
| 2006 |
} |
| 2007 |
|
| 2008 |
|
| 2009 |
if(whichCoordSystem != ROTATING_F) |
| 2010 |
{ |
| 2011 |
float r[3] = {0.0,0.0,0.0}; |
| 2012 |
for(int i=0; i<totalNumPoints_; i++) |
| 2013 |
{ |
| 2014 |
xyzCoords_[i][0]=r[0]; |
| 2015 |
xyzCoords_[i][1]=r[1]; |
| 2016 |
xyzCoords_[i][2]=r[2]; |
| 2017 |
} |
| 2018 |
} |
| 2019 |
fclose(inFile); |
| 2020 |
return true; |
| 2021 |
} |
| 2022 |
|
| 2023 |
void |
| 2024 |
Solution::normalizeData() |
| 2025 |
{ |
| 2026 |
// To convert the original data to [-1,1]; |
| 2027 |
int np = numOrbits_; |
| 2028 |
|
| 2029 |
#ifdef DEBUG |
| 2030 |
cout <<" Max sol 0 :" <<max_[0]<<" Min "<<min_[0]<<endl; |
| 2031 |
cout <<" Max sol 1 :" <<max_[1]<<" Min "<<min_[1]<<endl; |
| 2032 |
cout <<" Max sol 2 :" <<max_[2]<<" Min "<<min_[2]<<endl; |
| 2033 |
#endif |
| 2034 |
double div[3], con[3]; |
| 2035 |
for(int k=0; k<3; k++) |
| 2036 |
{ |
| 2037 |
con[k] = 0.0; |
| 2038 |
div[k] = (max_[k]-min_[k])/2.0; |
| 2039 |
|
| 2040 |
if(div[k]/max_[k]>1.0e-10) |
| 2041 |
{ |
| 2042 |
div[k] = 1.0/div[k]; |
| 2043 |
con[k] = div[k]*min_[k]; |
| 2044 |
} |
| 2045 |
} |
| 2046 |
|
| 2047 |
long int sump = 0; |
| 2048 |
for(int i=0; i<np; i++) |
| 2049 |
{ |
| 2050 |
long int nt = orbits_[i].numVerticesEachPeriod; |
| 2051 |
for(int j=0; j<nt; j++) |
| 2052 |
{ |
| 2053 |
for(int k=0; k<3; k++) |
| 2054 |
{ |
| 2055 |
if(div[k]/max_[k]>1.0e-10) |
| 2056 |
xyzCoords_[sump+j][k]= |
| 2057 |
xyzCoords_[sump+j][k]*div[k]-con[k]-1.0; |
| 2058 |
} |
| 2059 |
/** |
| 2060 |
if( !((max_[k]<=1.0 && max_[k]>0.5 && |
| 2061 |
min_[k]>=-1.0 && min_[k]<-0.5 )|| |
| 2062 |
(div[k]<0.00000001))) |
| 2063 |
{ |
| 2064 |
xyzCoords_[sump+j][k]= |
| 2065 |
(xyzCoords_[sump+j][k]-avg[k])/div[k]; |
| 2066 |
} |
| 2067 |
**/ |
| 2068 |
} |
| 2069 |
sump += nt; |
| 2070 |
} |
| 2071 |
} |
| 2072 |
|
| 2073 |
void |
| 2074 |
Solution::alloc() |
| 2075 |
{ |
| 2076 |
time_ = new double[totalNumPoints_]; |
| 2077 |
xyzCoords_ = new float[totalNumPoints_][3]; |
| 2078 |
numVerticesEachBranch_ = new int32_t[numBranches_]; |
| 2079 |
numOrbitsInEachBranch_ = new int32_t[numBranches_]; |
| 2080 |
branchID_ = new long[numBranches_]; |
| 2081 |
parMax_ = new double*[numBranches_]; |
| 2082 |
parMin_ = new double*[numBranches_]; |
| 2083 |
parMid_ = new double*[numBranches_]; |
| 2084 |
if (numBranches_ > 0) |
| 2085 |
{ |
| 2086 |
parMax_[0] = new double[numBranches_*npar_]; |
| 2087 |
parMin_[0] = new double[numBranches_*npar_]; |
| 2088 |
parMid_[0] = new double[numBranches_*npar_]; |
| 2089 |
for(int i=1; i<numBranches_; ++i) |
| 2090 |
{ |
| 2091 |
parMax_[i] = &parMax_[0][i*npar_]; |
| 2092 |
parMin_[i] = &parMin_[0][i*npar_]; |
| 2093 |
parMid_[i] = &parMid_[0][i*npar_]; |
| 2094 |
} |
| 2095 |
} |
| 2096 |
numAxis_ = 3; |
| 2097 |
|
| 2098 |
data_ = new float*[totalNumPoints_]; |
| 2099 |
if (totalNumPoints_ > 0) { |
| 2100 |
data_[0] = new float[totalNumPoints_*nar_]; |
| 2101 |
for(int ml=1; ml<totalNumPoints_; ++ml) |
| 2102 |
data_[ml] = &data_[0][ml*nar_]; |
| 2103 |
} |
| 2104 |
orbits_ = new struct orbit[numOrbits_]; |
| 2105 |
} |
| 2106 |
|
| 2107 |
void |
| 2108 |
Solution::denormalizePosition(float position[]) |
| 2109 |
{ |
| 2110 |
for(int k=0; k<3; k++) |
| 2111 |
{ |
| 2112 |
float con = 0.0; |
| 2113 |
float div = (max_[k]-min_[k])/2.0; |
| 2114 |
if(div/max_[k]>1.0e-10) |
| 2115 |
{ |
| 2116 |
div = 1.0/div; |
| 2117 |
con = div*min_[k]; |
| 2118 |
} |
| 2119 |
if(div/max_[k]>1.0e-10) |
| 2120 |
position[k] = (position[k]+con+1.0)/div; |
| 2121 |
} |
| 2122 |
} |
| 2123 |
|
| 2124 |
void |
| 2125 |
Solution::set_parID(std::queue<int>& parIDs) |
| 2126 |
{ |
| 2127 |
if (npar_ != 0) delete [] parID_; |
| 2128 |
npar_ = parIDs.size(); |
| 2129 |
parID_ = new int[npar_]; |
| 2130 |
for(int is=0; is < npar_; ++is) |
| 2131 |
{ |
| 2132 |
parID_[is] = parIDs.front(); |
| 2133 |
parIDs.pop(); |
| 2134 |
} |
| 2135 |
} |
| 2136 |
|
| 2137 |
|
| 2138 |
void |
| 2139 |
Solution::dealloc() |
| 2140 |
{ |
| 2141 |
delete [] time_; |
| 2142 |
delete [] xyzCoords_; |
| 2143 |
delete [] numVerticesEachBranch_; |
| 2144 |
delete [] numOrbitsInEachBranch_; |
| 2145 |
delete [] branchID_; |
| 2146 |
if (numBranches_ > 0) |
| 2147 |
{ |
| 2148 |
delete [] parMax_[0]; |
| 2149 |
delete [] parMin_[0]; |
| 2150 |
delete [] parMid_[0]; |
| 2151 |
} |
| 2152 |
delete [] parMax_; |
| 2153 |
delete [] parMin_; |
| 2154 |
delete [] parMid_; |
| 2155 |
if (totalNumPoints_ > 0) |
| 2156 |
delete [] data_[0]; |
| 2157 |
delete [] data_; |
| 2158 |
totalNumPoints_ = 0; |
| 2159 |
for (int i = 0; i < numOrbits_; i++) |
| 2160 |
delete [] orbits_[i].par; |
| 2161 |
delete [] orbits_; |
| 2162 |
} |
| 2163 |
|
| 2164 |
|
| 2165 |
/////////////////////////////////////////////////////////////////////////// |
| 2166 |
// |
| 2167 |
// Using a red ball to simulate the movement of a sattelite and using |
| 2168 |
// white lines to simulate the trace of the sattelite. |
| 2169 |
// |
| 2170 |
SoSeparator * |
| 2171 |
Solution::animateOrbitInertialSysUsingLine(int iBranch, int iOrbit, |
| 2172 |
float (*vertices)[3], float (*largePrimPos)[3], float (*smallPrimPos)[3], |
| 2173 |
float * myColorBase, float period, int size, |
| 2174 |
float scaler, int stability, int type) |
| 2175 |
// |
| 2176 |
/////////////////////////////////////////////////////////////////////////// |
| 2177 |
{ |
| 2178 |
SoSeparator *result = new SoSeparator; |
| 2179 |
SoSeparator *satGroup = new SoSeparator; |
| 2180 |
|
| 2181 |
SoDrawStyle *satStyle = new SoDrawStyle; |
| 2182 |
satStyle->style = SoDrawStyle::FILLED; |
| 2183 |
satGroup->addChild(satStyle); |
| 2184 |
|
| 2185 |
float maxV[3], minV[3]; |
| 2186 |
maxV[0]=minV[0]=vertices[0][0]; |
| 2187 |
maxV[1]=minV[1]=vertices[0][1]; |
| 2188 |
maxV[2]=minV[2]=vertices[0][2]; |
| 2189 |
float (*vertices1)[3] = new float[size][3]; |
| 2190 |
|
| 2191 |
for(int j=0; j<3; ++j) |
| 2192 |
{ |
| 2193 |
for(int i=1; i<size; i++) |
| 2194 |
{ |
| 2195 |
if(maxV[j] < vertices[i][j]) maxV[j] = vertices[i][j] ; |
| 2196 |
if(maxV[j] < largePrimPos[i][j]) maxV[j] = largePrimPos[i][j] ; |
| 2197 |
if(maxV[j] < smallPrimPos[i][j]) maxV[j] = smallPrimPos[i][j] ; |
| 2198 |
|
| 2199 |
if(minV[j] > vertices[i][j]) minV[j] = vertices[i][j] ; |
| 2200 |
if(minV[j] > largePrimPos[i][j]) minV[j] = largePrimPos[i][j] ; |
| 2201 |
if(minV[j] > smallPrimPos[i][j]) minV[j] = smallPrimPos[i][j] ; |
| 2202 |
vertices1[i-1][j]= vertices[i][j]; |
| 2203 |
} |
| 2204 |
} |
| 2205 |
|
| 2206 |
float dis = fabs(std::max(std::max((maxV[0]-minV[0]), (maxV[1]-minV[1])), |
| 2207 |
(maxV[2]-minV[2]))); |
| 2208 |
|
| 2209 |
// animate the orbit |
| 2210 |
SoCoordinate3 *myCoords = new SoCoordinate3; |
| 2211 |
myCoords->point.setValues(0, size, vertices); |
| 2212 |
satGroup->addChild(myCoords); |
| 2213 |
|
| 2214 |
SoTimeCounter *myCounter = new SoTimeCounter; |
| 2215 |
myCounter->max = size-1; |
| 2216 |
myCounter->min = 0; |
| 2217 |
myCounter->frequency = (numPeriodAnimated !=0) ? 0.1*satSpeed/numPeriodAnimated : 0.1*satSpeed; |
| 2218 |
|
| 2219 |
// define the solution line set |
| 2220 |
if(numPeriodAnimated!=0) |
| 2221 |
{ |
| 2222 |
SoLineSet *myLine= new SoLineSet; |
| 2223 |
myLine->numVertices.connectFrom(&myCounter->output); |
| 2224 |
|
| 2225 |
if(coloringMethod == CL_BRANCH_NUMBER || coloringMethod == CL_CURVE_NUMBER) |
| 2226 |
satGroup->addChild(setLineAttributesByBranch(iBranch,stability,scaler)); |
| 2227 |
else if(coloringMethod == CL_STABILITY) |
| 2228 |
satGroup->addChild(setLineAttributesByStability(stability, scaler)); |
| 2229 |
else if(coloringMethod == CL_ORBIT_TYPE) |
| 2230 |
satGroup->addChild(setLineAttributesByType(stability, type, scaler)); |
| 2231 |
else if(coloringMethod == CL_LABELS) |
| 2232 |
{ |
| 2233 |
double bMin = 0; |
| 2234 |
for(int ib = 0; ib< iBranch; ++ib) |
| 2235 |
bMin += numOrbitsInEachBranch_[ib]; |
| 2236 |
double bMax = bMin+numOrbitsInEachBranch_[iBranch]-1; |
| 2237 |
satGroup->addChild(setLineAttributesByParameterValue( |
| 2238 |
iOrbit, bMax, (bMax+bMin)/2.0, bMin, |
| 2239 |
stability, scaler)); |
| 2240 |
} |
| 2241 |
else if(coloringMethod >= nar_) |
| 2242 |
satGroup->addChild(setLineAttributesByParameterValue( |
| 2243 |
orbits_[iOrbit].par[parID_[coloringMethod-nar_]], |
| 2244 |
parMax_[iBranch][coloringMethod-nar_], |
| 2245 |
parMid_[iBranch][coloringMethod-nar_], |
| 2246 |
parMin_[iBranch][coloringMethod-nar_], |
| 2247 |
stability, scaler)); |
| 2248 |
else |
| 2249 |
satGroup->addChild(setLineColorBlending(myColorBase, size, |
| 2250 |
stability, scaler)); |
| 2251 |
satGroup->addChild(myLine); |
| 2252 |
} |
| 2253 |
|
| 2254 |
SoMaterial * satMtl = new SoMaterial; |
| 2255 |
SoSphere * mySat = new SoSphere; |
| 2256 |
mySat->radius = dis*0.005*satRadius; |
| 2257 |
|
| 2258 |
SoTranslation * satTrans = new SoTranslation; |
| 2259 |
satMtl->diffuseColor.setValue(envColors[7]); |
| 2260 |
satGroup->addChild(satMtl); |
| 2261 |
satGroup->addChild(satTrans); |
| 2262 |
satGroup->addChild(mySat); |
| 2263 |
|
| 2264 |
SoSelectOne *mysel = new SoSelectOne(SoMFVec3f::getClassTypeId()); |
| 2265 |
mysel->index.connectFrom(&myCounter->output); |
| 2266 |
mysel->input->enableConnection(TRUE); |
| 2267 |
mysel->input->connectFrom(&myCoords->point); |
| 2268 |
satTrans->translation.connectFrom(mysel->output); |
| 2269 |
|
| 2270 |
result->addChild(satGroup); |
| 2271 |
|
| 2272 |
// animate the primary movement. |
| 2273 |
SoSeparator * smallPrimLineSep = new SoSeparator; |
| 2274 |
SoCoordinate3 *smallPrimCoords = new SoCoordinate3; |
| 2275 |
smallPrimCoords->point.setValues(0, size, smallPrimPos); |
| 2276 |
smallPrimLineSep->addChild(smallPrimCoords); |
| 2277 |
|
| 2278 |
SoLineSet *smallPrimLine= new SoLineSet; |
| 2279 |
smallPrimLine->numVertices.connectFrom(&myCounter->output); |
| 2280 |
SoMaterial * smallPrimLineMtl = new SoMaterial; |
| 2281 |
smallPrimLineMtl->diffuseColor.setValue(envColors[11]); |
| 2282 |
smallPrimLineSep->addChild(smallPrimLineMtl); |
| 2283 |
smallPrimLineSep->addChild(smallPrimLine); |
| 2284 |
|
| 2285 |
SoTranslation * smallPrimTrans = new SoTranslation; |
| 2286 |
|
| 2287 |
SoSelectOne *smallPrimSel = new SoSelectOne(SoMFVec3f::getClassTypeId()); |
| 2288 |
smallPrimSel->index.connectFrom(&myCounter->output); |
| 2289 |
smallPrimSel->input->enableConnection(TRUE); |
| 2290 |
smallPrimSel->input->connectFrom(&smallPrimCoords->point); |
| 2291 |
smallPrimTrans->translation.connectFrom(smallPrimSel->output); |
| 2292 |
|
| 2293 |
result->addChild(smallPrimLineSep); |
| 2294 |
|
| 2295 |
SoSeparator * largePrimLineSep = new SoSeparator; |
| 2296 |
|
| 2297 |
SoCoordinate3 *largePrimCoords = new SoCoordinate3; |
| 2298 |
largePrimCoords->point.setValues(0, size, largePrimPos); |
| 2299 |
largePrimLineSep->addChild(largePrimCoords); |
| 2300 |
|
| 2301 |
SoLineSet *largePrimLine= new SoLineSet; |
| 2302 |
largePrimLine->numVertices.connectFrom(&myCounter->output); |
| 2303 |
SoMaterial * largePrimLineMtl = new SoMaterial; |
| 2304 |
largePrimLineMtl->diffuseColor.setValue(envColors[9]); |
| 2305 |
largePrimLineSep->addChild(largePrimLineMtl); |
| 2306 |
largePrimLineSep->addChild(largePrimLine); |
| 2307 |
|
| 2308 |
SoTranslation * largePrimTrans = new SoTranslation; |
| 2309 |
|
| 2310 |
SoSelectOne *largePrimSel = new SoSelectOne(SoMFVec3f::getClassTypeId()); |
| 2311 |
largePrimSel->index.connectFrom(&myCounter->output); |
| 2312 |
largePrimSel->input->enableConnection(TRUE); |
| 2313 |
largePrimSel->input->connectFrom(&largePrimCoords->point); |
| 2314 |
largePrimTrans->translation.connectFrom(largePrimSel->output); |
| 2315 |
|
| 2316 |
result->addChild(largePrimLineSep); |
| 2317 |
|
| 2318 |
delete []vertices1; |
| 2319 |
return result; |
| 2320 |
} |
| 2321 |
|
| 2322 |
|
| 2323 |
SoSeparator * |
| 2324 |
Solution::drawAnOrbitInertialSysUsingLines(int iBranch, int iOrbit, |
| 2325 |
float (*myVertices)[3], float *myColorBase, |
| 2326 |
long int arrSize, float scaler, int stability, int type) |
| 2327 |
{ |
| 2328 |
int32_t myint[10]; |
| 2329 |
|
| 2330 |
SoSeparator * anOrbit = new SoSeparator; |
| 2331 |
|
| 2332 |
SoCoordinate3 *myCoords = new SoCoordinate3; |
| 2333 |
myCoords->point.setValues(0, arrSize, myVertices); |
| 2334 |
myint[0]=-1; |
| 2335 |
|
| 2336 |
// define the solution line set |
| 2337 |
SoLineSet *myLine= new SoLineSet; |
| 2338 |
myLine->numVertices.setValues(0,1,myint); |
| 2339 |
|
| 2340 |
if(coloringMethod == CL_BRANCH_NUMBER || coloringMethod == CL_CURVE_NUMBER) |
| 2341 |
anOrbit->addChild(setLineAttributesByBranch(iBranch, stability, scaler)); |
| 2342 |
else if(coloringMethod == CL_STABILITY) |
| 2343 |
anOrbit->addChild(setLineAttributesByStability(stability, scaler)); |
| 2344 |
else if(coloringMethod == CL_ORBIT_TYPE) |
| 2345 |
anOrbit->addChild(setLineAttributesByType(stability, type, scaler)); |
| 2346 |
else if(coloringMethod == CL_LABELS) |
| 2347 |
{ |
| 2348 |
double bMin = 0; |
| 2349 |
for(int ib = 0; ib< iBranch; ++ib) |
| 2350 |
bMin += numOrbitsInEachBranch_[ib]; |
| 2351 |
double bMax = bMin+numOrbitsInEachBranch_[iBranch]-1; |
| 2352 |
anOrbit->addChild(setLineAttributesByParameterValue( |
| 2353 |
iOrbit, bMax, (bMax+bMin)/2.0, bMin, |
| 2354 |
stability, scaler)); |
| 2355 |
} |
| 2356 |
else if(coloringMethod >= nar_) |
| 2357 |
anOrbit->addChild(setLineAttributesByParameterValue( |
| 2358 |
orbits_[iOrbit].par[parID_[coloringMethod-nar_]], |
| 2359 |
parMax_[iBranch][coloringMethod-nar_], |
| 2360 |
parMid_[iBranch][coloringMethod-nar_], |
| 2361 |
parMin_[iBranch][coloringMethod-nar_], |
| 2362 |
stability, scaler)); |
| 2363 |
else |
| 2364 |
anOrbit->addChild(setLineColorBlending(myColorBase, arrSize, |
| 2365 |
stability, scaler)); |
| 2366 |
anOrbit->addChild(myCoords); |
| 2367 |
anOrbit->addChild(myLine); |
| 2368 |
|
| 2369 |
return anOrbit; |
| 2370 |
} |
| 2371 |
|
| 2372 |
|
| 2373 |
//////////////////////////////////////////////////////////////////////// |
| 2374 |
// |
| 2375 |
void |
| 2376 |
Solution::convertDataToInertialSystem(float (*myVertices)[3], |
| 2377 |
float *timeEqualDiv, float *myColorBase, |
| 2378 |
long int arrSize, long int orbitSize, long int kth, long int sumX) |
| 2379 |
// |
| 2380 |
//////////////////////////////////////////////////////////////////////// |
| 2381 |
{ |
| 2382 |
float (*workArray)[3] = new float [arrSize][3]; |
| 2383 |
float *time = new float [arrSize]; |
| 2384 |
float satPeriod = orbits_[kth].period; |
| 2385 |
float rpp[3], vpp[3]; |
| 2386 |
float massCurLabeledOrbit = orbits_[kth].mass; |
| 2387 |
|
| 2388 |
for(int i=0; i<arrSize; ++i) |
| 2389 |
{ |
| 2390 |
workArray[i][0]=xyzCoords_[sumX+i%orbitSize][0]; |
| 2391 |
workArray[i][1]=xyzCoords_[sumX+i%orbitSize][1]; |
| 2392 |
workArray[i][2]=xyzCoords_[sumX+i%orbitSize][2]; |
| 2393 |
if(whichStyle==TUBE && !options[OPT_SAT_ANI] ) |
| 2394 |
{ |
| 2395 |
if(coloringMethod>=0 && coloringMethod < nar_) |
| 2396 |
for(int k=0; k<11; ++k) |
| 2397 |
myColorBase[i*11+k] = data_[sumX+i%orbitSize][coloringMethod]; |
| 2398 |
else if(coloringMethod==CL_POINT_NUMBER ) |
| 2399 |
for(int k=0; k<11; ++k) |
| 2400 |
myColorBase[i*11+k] = i; |
| 2401 |
} |
| 2402 |
else |
| 2403 |
{ |
| 2404 |
if(coloringMethod>=0 && coloringMethod < nar_) |
| 2405 |
myColorBase[i]=data_[sumX+i%orbitSize][coloringMethod]; |
| 2406 |
else if(coloringMethod==CL_POINT_NUMBER ) |
| 2407 |
myColorBase[i]=i; |
| 2408 |
} |
| 2409 |
|
| 2410 |
time[i] = time_[sumX+i%orbitSize]+i/orbitSize; |
| 2411 |
|
| 2412 |
satelliteMovingOrbit(whichCoordSystem, |
| 2413 |
workArray[i], time[i], massCurLabeledOrbit, distance, satPeriod, sPrimPeriod, gravity, rpp, vpp ); |
| 2414 |
for(int jk=0; jk<3; ++jk) workArray[i][jk]=rpp[jk]; |
| 2415 |
} |
| 2416 |
|
| 2417 |
float Tr3b = 1; |
| 2418 |
|
| 2419 |
Tr3b = (numPeriodAnimated==0) ? Tr3b/arrSize : numPeriodAnimated * Tr3b/arrSize; |
| 2420 |
for(int i=0; i <arrSize; ++i) |
| 2421 |
timeEqualDiv[i] = i * Tr3b; |
| 2422 |
|
| 2423 |
myVertices[0][0]= workArray[0][0]; |
| 2424 |
myVertices[0][1]= workArray[0][1]; |
| 2425 |
myVertices[0][2]= workArray[0][2]; |
| 2426 |
for(int i=1; i<arrSize; i++) |
| 2427 |
{ |
| 2428 |
float tTemp = timeEqualDiv[i]; |
| 2429 |
int m = 0; |
| 2430 |
while(tTemp > time[m] && m < arrSize) ++m; |
| 2431 |
if( fabs(tTemp-time[m]) <= 1.0e-9 || fabs(time[m]-time[m-1])<=1.0e-8) |
| 2432 |
{ |
| 2433 |
myVertices[i][0]=workArray[m][0]; |
| 2434 |
myVertices[i][1]=workArray[m][1]; |
| 2435 |
myVertices[i][2]=workArray[m][2]; |
| 2436 |
} |
| 2437 |
else |
| 2438 |
{ |
| 2439 |
float dt = (tTemp-time[m-1])/(time[m]-time[m-1]); |
| 2440 |
myVertices[i][0]= workArray[m-1][0]+(workArray[m][0]-workArray[m-1][0])*dt; |
| 2441 |
myVertices[i][1]= workArray[m-1][1]+(workArray[m][1]-workArray[m-1][1])*dt; |
| 2442 |
myVertices[i][2]= workArray[m-1][2]+(workArray[m][2]-workArray[m-1][2])*dt; |
| 2443 |
} |
| 2444 |
} |
| 2445 |
delete [] time; |
| 2446 |
delete [] workArray; |
| 2447 |
} |
| 2448 |
|
| 2449 |
|
| 2450 |
|
| 2451 |
////////////////////////////////////////////////////////////////////////// |
| 2452 |
// |
| 2453 |
SoSeparator * |
| 2454 |
Solution::drawAnOrbitInertialSysUsingTubes(int iBranch, int iOrbit, |
| 2455 |
float (*myVertices)[3], float *myColorBase, const long int arrSize, |
| 2456 |
const float tubeRadiusScaler, const int stability, const int type) |
| 2457 |
// |
| 2458 |
////////////////////////////////////////////////////////////////////////// |
| 2459 |
{ |
| 2460 |
SoSeparator * anOrbit = new SoSeparator; |
| 2461 |
|
| 2462 |
Tube tube; |
| 2463 |
|
| 2464 |
if(coloringMethod == CL_BRANCH_NUMBER || coloringMethod == CL_CURVE_NUMBER) |
| 2465 |
anOrbit->addChild(setLineAttributesByBranch(iBranch, stability, tubeRadiusScaler)); |
| 2466 |
else if(coloringMethod == CL_STABILITY) |
| 2467 |
anOrbit->addChild(setLineAttributesByStability(stability, tubeRadiusScaler)); |
| 2468 |
else if(coloringMethod == CL_ORBIT_TYPE) |
| 2469 |
anOrbit->addChild(setLineAttributesByType(stability, type, tubeRadiusScaler)); |
| 2470 |
else if(coloringMethod == CL_LABELS) |
| 2471 |
{ |
| 2472 |
double bMin = 0; |
| 2473 |
for(int ib = 0; ib< iBranch; ++ib) |
| 2474 |
bMin += numOrbitsInEachBranch_[ib]; |
| 2475 |
double bMax = bMin+numOrbitsInEachBranch_[iBranch]-1; |
| 2476 |
anOrbit->addChild(setLineAttributesByParameterValue( |
| 2477 |
iOrbit, bMax, (bMax+bMin)/2.0, bMin, |
| 2478 |
stability, tubeRadiusScaler)); |
| 2479 |
} |
| 2480 |
else if(coloringMethod >= nar_) |
| 2481 |
anOrbit->addChild(setLineAttributesByParameterValue( |
| 2482 |
orbits_[iOrbit].par[parID_[coloringMethod-nar_]], |
| 2483 |
parMax_[iBranch][coloringMethod-nar_], |
| 2484 |
parMid_[iBranch][coloringMethod-nar_], |
| 2485 |
parMin_[iBranch][coloringMethod-nar_], |
| 2486 |
stability, tubeRadiusScaler)); |
| 2487 |
else |
| 2488 |
anOrbit->addChild(setLineColorBlending(myColorBase, arrSize*11, |
| 2489 |
stability, tubeRadiusScaler)); |
| 2490 |
|
| 2491 |
tube = Tube(arrSize, myVertices, tubeRadiusScaler*0.005, 10); |
| 2492 |
anOrbit->addChild(tube.createTube()); |
| 2493 |
|
| 2494 |
return anOrbit; |
| 2495 |
} |
| 2496 |
|
| 2497 |
|
| 2498 |
////////////////////////////////////////////////////////////////////////// |
| 2499 |
// |
| 2500 |
SoSeparator * |
| 2501 |
Solution::drawAnOrbitInertialSysUsingNurbsCurve(int iBranch, int iOrbit, |
| 2502 |
float (*myVertices)[3], const long int arrSize, |
| 2503 |
const float scaler, const int stability, const int type) |
| 2504 |
// |
| 2505 |
////////////////////////////////////////////////////////////////////////// |
| 2506 |
{ |
| 2507 |
SoSeparator * anOrbit = new SoSeparator; |
| 2508 |
SoCoordinate3 *myCoords = new SoCoordinate3; |
| 2509 |
myCoords->point.setValues(0, arrSize, myVertices); |
| 2510 |
|
| 2511 |
// define a nurbs curve |
| 2512 |
int number = arrSize; |
| 2513 |
float * knots = new float[number+4]; |
| 2514 |
for (int i=0; i<4; ++i) knots[i]=0, knots[i+number]=number-3; |
| 2515 |
for(int i=4; i<number; ++i) knots[i]=i-3; |
| 2516 |
SoNurbsCurve *myCurve = new SoNurbsCurve; |
| 2517 |
myCurve->numControlPoints = arrSize; |
| 2518 |
myCurve->knotVector.setValues(0, number+4, knots); |
| 2519 |
|
| 2520 |
if(coloringMethod == CL_BRANCH_NUMBER || coloringMethod == CL_CURVE_NUMBER) |
| 2521 |
anOrbit->addChild(setLineAttributesByBranch(iBranch, stability, scaler)); |
| 2522 |
else if(coloringMethod == CL_STABILITY) |
| 2523 |
anOrbit->addChild(setLineAttributesByStability(stability, scaler)); |
| 2524 |
else if(coloringMethod == CL_ORBIT_TYPE) |
| 2525 |
anOrbit->addChild(setLineAttributesByType(stability, type, scaler)); |
| 2526 |
else if(coloringMethod == CL_LABELS) |
| 2527 |
{ |
| 2528 |
double bMin = 0; |
| 2529 |
for(int ib = 0; ib< iBranch; ++ib) |
| 2530 |
bMin += numOrbitsInEachBranch_[ib]; |
| 2531 |
double bMax = bMin+numOrbitsInEachBranch_[iBranch]-1; |
| 2532 |
anOrbit->addChild(setLineAttributesByParameterValue( |
| 2533 |
iOrbit, bMax, (bMax+bMin)/2.0, bMin, |
| 2534 |
stability, scaler)); |
| 2535 |
} |
| 2536 |
else if(coloringMethod >= nar_) |
| 2537 |
anOrbit->addChild(setLineAttributesByParameterValue( |
| 2538 |
orbits_[iOrbit].par[parID_[coloringMethod-nar_]], |
| 2539 |
parMax_[iBranch][coloringMethod-nar_], |
| 2540 |
parMid_[iBranch][coloringMethod-nar_], |
| 2541 |
parMin_[iBranch][coloringMethod-nar_], |
| 2542 |
stability, scaler)); |
| 2543 |
else |
| 2544 |
anOrbit->addChild(setLineAttributesByType(stability, type, scaler)); |
| 2545 |
|
| 2546 |
anOrbit->addChild(myCoords); |
| 2547 |
anOrbit->addChild(myCurve); |
| 2548 |
delete [] knots; |
| 2549 |
return anOrbit; |
| 2550 |
} |
| 2551 |
|
| 2552 |
|
| 2553 |
////////////////////////////////////////////////////////////////////////// |
| 2554 |
// |
| 2555 |
SoSeparator * |
| 2556 |
Solution::createInertialFrameScene(float dis) |
| 2557 |
// |
| 2558 |
////////////////////////////////////////////////////////////////////////// |
| 2559 |
{ |
| 2560 |
SoSeparator * solGroup = new SoSeparator; |
| 2561 |
int stability, type; |
| 2562 |
float satPeriod = 1; |
| 2563 |
long int arrSize = 0; |
| 2564 |
|
| 2565 |
if(animationLabel == MY_ALL) |
| 2566 |
{ |
| 2567 |
long int si = 0; |
| 2568 |
long int orbitSize; |
| 2569 |
float (*myVertices)[3]; |
| 2570 |
float *myColorBase; |
| 2571 |
float *time; |
| 2572 |
int iBranch = 0; |
| 2573 |
int sumOrbit = numOrbitsInEachBranch_[iBranch]; |
| 2574 |
for(int k=0; k<numOrbits_; ++k) |
| 2575 |
{ |
| 2576 |
if(k >= sumOrbit) |
| 2577 |
{ |
| 2578 |
sumOrbit += numOrbitsInEachBranch_[++iBranch]; |
| 2579 |
} |
| 2580 |
orbitSize = orbits_[k].numVerticesEachPeriod; |
| 2581 |
arrSize = (numPeriodAnimated==0) ? orbitSize : (int)(numPeriodAnimated * orbitSize); |
| 2582 |
|
| 2583 |
myVertices = new float [arrSize][3]; |
| 2584 |
myColorBase= new float [arrSize*11]; |
| 2585 |
time = new float [arrSize]; |
| 2586 |
|
| 2587 |
convertDataToInertialSystem(myVertices, time, myColorBase, arrSize, orbitSize, k, si); |
| 2588 |
stability = clientData.labelIndex[k][3]; |
| 2589 |
type = clientData.labelIndex[k][2]; |
| 2590 |
|
| 2591 |
if(whichStyle==TUBE) |
| 2592 |
{ |
| 2593 |
solGroup->addChild(drawAnOrbitInertialSysUsingTubes( |
| 2594 |
iBranch, k, myVertices,myColorBase, arrSize, lineWidthScaler, |
| 2595 |
stability, type)); |
| 2596 |
} |
| 2597 |
else if(whichStyle==SURFACE) |
| 2598 |
{ |
| 2599 |
solGroup->addChild(drawAnOrbitInertialSysUsingLines( |
| 2600 |
iBranch, k, myVertices, myColorBase, arrSize, lineWidthScaler, |
| 2601 |
stability, type)); |
| 2602 |
} |
| 2603 |
else if(whichStyle==NURBS) |
| 2604 |
{ |
| 2605 |
solGroup->addChild(drawAnOrbitInertialSysUsingNurbsCurve( |
| 2606 |
iBranch, k, myVertices, arrSize, lineWidthScaler, |
| 2607 |
stability, type)); |
| 2608 |
} |
| 2609 |
else |
| 2610 |
{ |
| 2611 |
solGroup->addChild(drawAnOrbitInertialSysUsingLines( |
| 2612 |
iBranch, k, myVertices, myColorBase, arrSize, lineWidthScaler, |
| 2613 |
stability, type)); |
| 2614 |
} |
| 2615 |
|
| 2616 |
si += orbits_[k].numVerticesEachPeriod; |
| 2617 |
delete [] myVertices; |
| 2618 |
delete [] time; |
| 2619 |
} |
| 2620 |
} |
| 2621 |
else if(animationLabel != MY_NONE) |
| 2622 |
{ |
| 2623 |
float vpp[3]; |
| 2624 |
for(std::vector<int>::size_type n=0; n<lblIndices.size(); ++n) |
| 2625 |
{ |
| 2626 |
animationLabel=myLabels[lblIndices[n]]; |
| 2627 |
int si = 0, kno = 0; |
| 2628 |
int iBranch = 0; |
| 2629 |
int sumOrbit = numOrbitsInEachBranch_[iBranch]; |
| 2630 |
while(kno<numOrbits_ && myLabels[kno]<animationLabel) |
| 2631 |
{ |
| 2632 |
si += orbits_[kno].numVerticesEachPeriod; |
| 2633 |
if(kno >= sumOrbit) |
| 2634 |
{ |
| 2635 |
sumOrbit += numOrbitsInEachBranch_[++iBranch]; |
| 2636 |
} |
| 2637 |
} |
| 2638 |
|
| 2639 |
satPeriod = orbits_[kno].period; |
| 2640 |
long int orbitSize = orbits_[kno].numVerticesEachPeriod; |
| 2641 |
arrSize = (numPeriodAnimated==0) ? orbitSize : (int)(numPeriodAnimated * orbitSize); |
| 2642 |
|
| 2643 |
float (*myVertices)[3] = new float [arrSize][3]; |
| 2644 |
float *myColorBase = new float [arrSize*11]; |
| 2645 |
float *time = new float [arrSize]; |
| 2646 |
|
| 2647 |
convertDataToInertialSystem(myVertices, time, myColorBase, arrSize, orbitSize, kno, si); |
| 2648 |
|
| 2649 |
float (*largePrimPos)[3] = new float [arrSize][3]; |
| 2650 |
float (*smallPrimPos)[3] = new float [arrSize][3]; |
| 2651 |
|
| 2652 |
for(int i=0; i<arrSize; ++i) |
| 2653 |
{ |
| 2654 |
computePrimaryPositionInInertialSystem(whichCoordSystem, |
| 2655 |
mass, distance, sPrimPeriod, time[i]*satPeriod, |
| 2656 |
largePrimPos[i], smallPrimPos[i], vpp); |
| 2657 |
} |
| 2658 |
|
| 2659 |
stability = clientData.labelIndex[kno][3]; |
| 2660 |
type = clientData.labelIndex[kno][2]; |
| 2661 |
if(options[OPT_SAT_ANI]) |
| 2662 |
{ |
| 2663 |
solGroup->addChild(animateOrbitInertialSysUsingLine( |
| 2664 |
iBranch, kno, myVertices, largePrimPos, smallPrimPos, myColorBase, |
| 2665 |
satPeriod, arrSize, lineWidthScaler, stability, type)); |
| 2666 |
} |
| 2667 |
else |
| 2668 |
{ |
| 2669 |
if(whichStyle==TUBE) |
| 2670 |
{ |
| 2671 |
solGroup->addChild(drawAnOrbitInertialSysUsingTubes( |
| 2672 |
iBranch, kno, myVertices, myColorBase, arrSize, lineWidthScaler, |
| 2673 |
stability, type)); |
| 2674 |
} |
| 2675 |
else if(whichStyle==SURFACE) |
| 2676 |
{ |
| 2677 |
solGroup->addChild(drawAnOrbitInertialSysUsingLines( |
| 2678 |
iBranch, kno, myVertices,myColorBase, arrSize, lineWidthScaler, |
| 2679 |
stability, type)); |
| 2680 |
} |
| 2681 |
else if(whichStyle==NURBS) |
| 2682 |
{ |
| 2683 |
solGroup->addChild(drawAnOrbitInertialSysUsingNurbsCurve( |
| 2684 |
iBranch, kno, myVertices, arrSize, lineWidthScaler, |
| 2685 |
stability, type)); |
| 2686 |
} |
| 2687 |
else |
| 2688 |
{ |
| 2689 |
solGroup->addChild(drawAnOrbitInertialSysUsingLines( |
| 2690 |
iBranch, kno, myVertices, myColorBase, arrSize, lineWidthScaler, |
| 2691 |
stability, type)); |
| 2692 |
} |
| 2693 |
} |
| 2694 |
delete [] myVertices; |
| 2695 |
delete [] myColorBase; |
| 2696 |
delete [] smallPrimPos; |
| 2697 |
delete [] largePrimPos; |
| 2698 |
delete [] time; |
| 2699 |
} |
| 2700 |
} |
| 2701 |
SoSeparator *aSep = new SoSeparator; |
| 2702 |
SoTimeCounter *myCounter = new SoTimeCounter; |
| 2703 |
myCounter->ref(); |
| 2704 |
myCounter->max = 10*(arrSize - 1); |
| 2705 |
myCounter->min = 0; |
| 2706 |
myCounter->frequency = (numPeriodAnimated !=0) ? 0.1*satSpeed/numPeriodAnimated : 0.1*satSpeed; |
| 2707 |
|
| 2708 |
float pseudoPeriod = 0.1*satPeriod*numPeriodAnimated/(arrSize-1); |
| 2709 |
SoCalculator *aCalc = new SoCalculator; |
| 2710 |
aCalc->a.connectFrom(&myCounter->output); |
| 2711 |
aCalc->b.setValue(pseudoPeriod); |
| 2712 |
aCalc->expression.setValue("oa = fmod(2.0*M_PI*a*b, 2*M_PI)"); |
| 2713 |
|
| 2714 |
SoRotationXYZ *aRotation = new SoRotationXYZ; |
| 2715 |
aRotation->axis = SoRotationXYZ::Z; |
| 2716 |
aRotation->angle.connectFrom(&aCalc->oa); |
| 2717 |
aSep->addChild(aRotation); |
| 2718 |
|
| 2719 |
// create the primaries |
| 2720 |
if(options[OPT_PRIMARY]) |
| 2721 |
{ |
| 2722 |
double pos1 = -mass; |
| 2723 |
double pos2 = 1-mass; |
| 2724 |
if(whichCoordSystem == INERTIAL_B ) |
| 2725 |
pos1 = -mass , pos2=1-mass; |
| 2726 |
else if(whichCoordSystem == INERTIAL_S ) |
| 2727 |
pos1 = 0, pos2= 1; |
| 2728 |
else if(whichCoordSystem == INERTIAL_E ) |
| 2729 |
pos1 = -1, pos2= 0; |
| 2730 |
char *txtureFileName = new char [strlen(autoDir) + 30]; |
| 2731 |
sprintf(txtureFileName, "%s%s", autoDir, "/plaut04/widgets/large.rgb"); |
| 2732 |
aSep->addChild(createPrimary(1-mass, pos1, 0.25*largePrimRadius, txtureFileName)); |
| 2733 |
sprintf(txtureFileName, "%s%s", autoDir, "/plaut04/widgets/small.rgb"); |
| 2734 |
aSep->addChild(createPrimary(mass, pos2, 0.25*smallPrimRadius, txtureFileName)); |
| 2735 |
delete [] txtureFileName; |
| 2736 |
} |
| 2737 |
|
| 2738 |
// create the libration points |
| 2739 |
SoSeparator * libPtsSep = createLibrationPoint(mass, dis, libPtScaler, |
| 2740 |
whichCoordSystem); |
| 2741 |
if(options[OPT_LIB_POINTS]) |
| 2742 |
{ |
| 2743 |
aSep->addChild(libPtsSep); |
| 2744 |
} |
| 2745 |
|
| 2746 |
// create solution coordinate axis |
| 2747 |
if(whichCoord != NO_COORD) |
| 2748 |
{ |
| 2749 |
SoSeparator * coordSep = new SoSeparator; |
| 2750 |
|
| 2751 |
SoTransform * coordXform = new SoTransform; |
| 2752 |
coordXform->rotation.setValue(SbVec3f(1.0, 0.0, 0.0),M_PI_2); |
| 2753 |
|
| 2754 |
coordSep->addChild(coordXform); |
| 2755 |
static int tickers[3]; |
| 2756 |
if(blDrawTicker) |
| 2757 |
{ |
| 2758 |
tickers[0]=tickers[1]=tickers[2]=5; |
| 2759 |
} |
| 2760 |
else |
| 2761 |
{ |
| 2762 |
tickers[0]=tickers[1]=tickers[2]=-1; |
| 2763 |
} |
| 2764 |
float asMax[3], asMin[3]; |
| 2765 |
if(options[OPT_NORMALIZE_DATA]) |
| 2766 |
{ |
| 2767 |
asMax[0]=max_[0]; asMax[1]=max_[1];asMax[2]=max_[2]; |
| 2768 |
asMin[0]=min_[0]; asMin[1]=min_[1];asMin[2]=min_[2]; |
| 2769 |
} |
| 2770 |
else |
| 2771 |
{ |
| 2772 |
asMax[0] = asMax[1] = asMax[2] = 1; |
| 2773 |
asMin[0] = asMin[1] = asMin[2] = -1; |
| 2774 |
} |
| 2775 |
|
| 2776 |
coordSep->addChild(createCoordinates(setShow3D, whichCoord, asMax, asMin, tickers, &envColors[1])); |
| 2777 |
|
| 2778 |
aSep->addChild(coordSep); |
| 2779 |
} |
| 2780 |
|
| 2781 |
solGroup->addChild(aSep); |
| 2782 |
if(options[OPT_PERIOD_ANI]) |
| 2783 |
{ |
| 2784 |
int iBranch = 0; |
| 2785 |
int sumOrbit = numOrbitsInEachBranch_[iBranch]; |
| 2786 |
long int si = 0; |
| 2787 |
SoBlinker * solBlinker = new SoBlinker; |
| 2788 |
solBlinker->speed = orbitSpeed; |
| 2789 |
solBlinker->on = TRUE; |
| 2790 |
for(int k=0; k<numOrbits_; ++k) |
| 2791 |
{ |
| 2792 |
if(k >= sumOrbit) |
| 2793 |
{ |
| 2794 |
sumOrbit += numOrbitsInEachBranch_[++iBranch]; |
| 2795 |
} |
| 2796 |
long int orbitSize = orbits_[k].numVerticesEachPeriod; |
| 2797 |
long int arrSize = (numPeriodAnimated==0) ? |
| 2798 |
orbitSize : (int)(numPeriodAnimated * orbitSize); |
| 2799 |
|
| 2800 |
float (*myVertices)[3] = new float [arrSize][3]; |
| 2801 |
float *myColorBase = new float [arrSize*11]; |
| 2802 |
float *time = new float [arrSize]; |
| 2803 |
|
| 2804 |
convertDataToInertialSystem(myVertices, time, myColorBase, arrSize, orbitSize, k, si); |
| 2805 |
|
| 2806 |
solBlinker->addChild(drawAnOrbitInertialSysUsingLines( |
| 2807 |
iBranch, k, myVertices, myColorBase, arrSize, aniLineScaler*lineWidthScaler, |
| 2808 |
clientData.labelIndex[k][3],clientData.labelIndex[k][2])); |
| 2809 |
si += orbits_[k].numVerticesEachPeriod; |
| 2810 |
delete [] myVertices; |
| 2811 |
delete [] myColorBase; |
| 2812 |
delete [] time; |
| 2813 |
} |
| 2814 |
solGroup->addChild(solBlinker); |
| 2815 |
} |
| 2816 |
return solGroup; |
| 2817 |
|
| 2818 |
} |
| 2819 |
|
| 2820 |
#if 0 // unused R3B related functions |
| 2821 |
/////////////////////////////////////////////////////////////////////////// |
| 2822 |
// |
| 2823 |
// |
| 2824 |
SoSeparator * |
| 2825 |
Solution::animateIner2(long int lblJ,long int si) |
| 2826 |
// |
| 2827 |
/////////////////////////////////////////////////////////////////////////// |
| 2828 |
{ |
| 2829 |
float ptb[3]; |
| 2830 |
int center = 0; |
| 2831 |
float mu = 0.01215; |
| 2832 |
SoSeparator *satGroup = new SoSeparator; |
| 2833 |
SoMaterial *satMtl = new SoMaterial; |
| 2834 |
satMtl->diffuseColor.setValue(envColors[7]); |
| 2835 |
satMtl->transparency = 0.0; |
| 2836 |
|
| 2837 |
SoDrawStyle *satStyle = new SoDrawStyle; |
| 2838 |
satStyle->style = SoDrawStyle::FILLED; |
| 2839 |
satGroup->addChild(satStyle); |
| 2840 |
|
| 2841 |
SoBlinker *satBlker = new SoBlinker; |
| 2842 |
|
| 2843 |
int upperlimit = orbits_[lblJ].numVerticesEachPeriod; |
| 2844 |
int idx = si; |
| 2845 |
satBlker->speed = 0.5; |
| 2846 |
|
| 2847 |
// go thr the whole dataset to find the max and min in this set |
| 2848 |
// so that we can decide the size of the ball. |
| 2849 |
float maxV[3], minV[3]; |
| 2850 |
maxV[0]=minV[0]=xyzCoords_[idx+0][0]; |
| 2851 |
maxV[1]=minV[1]=xyzCoords_[idx+0][0]; |
| 2852 |
maxV[2]=minV[2]=xyzCoords_[idx+0][0]; |
| 2853 |
for(int i=1; i<upperlimit; i++) |
| 2854 |
{ |
| 2855 |
if(maxV[0]<xyzCoords_[idx+i][0]) maxV[0]=xyzCoords_[idx+i][0] ; |
| 2856 |
if(minV[0]>xyzCoords_[idx+i][0]) minV[0]=xyzCoords_[idx+i][0] ; |
| 2857 |
if(maxV[1]<xyzCoords_[idx+i][1]) maxV[1]=xyzCoords_[idx+i][1] ; |
| 2858 |
if(minV[1]>xyzCoords_[idx+i][1]) minV[1]=xyzCoords_[idx+i][1] ; |
| 2859 |
if(maxV[2]<xyzCoords_[idx+i][2]) maxV[2]=xyzCoords_[idx+i][2] ; |
| 2860 |
if(minV[2]>xyzCoords_[idx+i][2]) minV[2]=xyzCoords_[idx+i][2] ; |
| 2861 |
} |
| 2862 |
float dis = fabs(std::max(std::max((maxV[0]-minV[0]), (maxV[1]-minV[1])), |
| 2863 |
(maxV[2]-minV[2]))); |
| 2864 |
float pta[3], vertices[2][3]; |
| 2865 |
float rgb1[3], rgb2[3]; |
| 2866 |
rgb1[0]=0; rgb1[2]=0; rgb1[1]=1; |
| 2867 |
rgb2[0]=1; rgb2[1]=0; rgb2[2]=0; |
| 2868 |
|
| 2869 |
// animate the orbit |
| 2870 |
ptb[0]=xyzCoords_[idx+0][0]; |
| 2871 |
ptb[1]=xyzCoords_[idx+0][1]; |
| 2872 |
ptb[2]=xyzCoords_[idx+0][2]; |
| 2873 |
float primPos[3]; |
| 2874 |
|
| 2875 |
float satPeriod ; |
| 2876 |
satPeriod = period_[lblJ]; |
| 2877 |
float wholePeriod = satPeriod*2.0*M_PI; |
| 2878 |
float aniTime = 0.0, dt = 0.0, incTime = 0.0; |
| 2879 |
dt = 1.0/200.0; |
| 2880 |
do |
| 2881 |
{ |
| 2882 |
pta[0]=ptb[0]; pta[1]=ptb[1]; pta[2]=ptb[2]; |
| 2883 |
|
| 2884 |
//find the point with the time: aniTime; |
| 2885 |
int i; |
| 2886 |
for(i=0; i<upperlimit; ++i) |
| 2887 |
{ |
| 2888 |
if(time_[idx+i]>=aniTime/2.0/M_PI) break; |
| 2889 |
} |
| 2890 |
|
| 2891 |
// calculate the position of this record. |
| 2892 |
if(i==upperlimit) |
| 2893 |
{ |
| 2894 |
ptb[0]=xyzCoords_[idx+i-1][0]; |
| 2895 |
ptb[1]=xyzCoords_[idx+i-1][1]; |
| 2896 |
ptb[2]=xyzCoords_[idx+i-1][2]; |
| 2897 |
} |
| 2898 |
else if(i==0) |
| 2899 |
{ |
| 2900 |
ptb[0]=xyzCoords_[idx][0]; |
| 2901 |
ptb[1]=xyzCoords_[idx][1]; |
| 2902 |
ptb[2]=xyzCoords_[idx][2]; |
| 2903 |
} |
| 2904 |
else |
| 2905 |
{ |
| 2906 |
ptb[0]=(xyzCoords_[idx+i-1][0]+xyzCoords_[idx+i][0])/2.0; |
| 2907 |
ptb[1]=(xyzCoords_[idx+i-1][1]+xyzCoords_[idx+i][1])/2.0; |
| 2908 |
ptb[2]=(xyzCoords_[idx+i-1][2]+xyzCoords_[idx+i][2])/2.0; |
| 2909 |
} |
| 2910 |
|
| 2911 |
// calculate the position of the primary at aniTime. |
| 2912 |
calPrimPos(aniTime, primPos); |
| 2913 |
satBlker->addChild(drawASphereWithColor(rgb1, primPos, 1.*dis/100.0)); |
| 2914 |
|
| 2915 |
// calculate the position of the satallite at aniTime. |
| 2916 |
calSatPos(center, mu, aniTime, primPos, ptb); |
| 2917 |
satBlker->addChild(drawASphereWithColor(rgb2, ptb, 1.*dis/100.0)); |
| 2918 |
|
| 2919 |
vertices[0][0]=pta[0]; |
| 2920 |
vertices[0][1]=pta[1]; |
| 2921 |
vertices[0][2]=pta[2]; |
| 2922 |
vertices[1][0]=ptb[0]; |
| 2923 |
vertices[1][1]=ptb[1]; |
| 2924 |
vertices[1][2]=ptb[2]; |
| 2925 |
SoCoordinate3 *myCoords = new SoCoordinate3; |
| 2926 |
myCoords->point.setValues(0, 2, vertices); |
| 2927 |
|
| 2928 |
int32_t myint[1]; |
| 2929 |
myint[0]=-1; |
| 2930 |
|
| 2931 |
// define the orbit line set |
| 2932 |
SoLineSet *myLine= new SoLineSet; |
| 2933 |
myLine->numVertices.setValues(0,1,myint); |
| 2934 |
satGroup->addChild(satMtl); |
| 2935 |
satGroup->addChild(myCoords); |
| 2936 |
satGroup->addChild(myLine); |
| 2937 |
|
| 2938 |
// increase the time. |
| 2939 |
incTime += dt; |
| 2940 |
aniTime += dt; |
| 2941 |
}while(incTime <= wholePeriod); |
| 2942 |
|
| 2943 |
satGroup->addChild(satMtl); |
| 2944 |
satGroup->addChild(satBlker); |
| 2945 |
return satGroup; |
| 2946 |
} |
| 2947 |
|
| 2948 |
|
| 2949 |
/////////////////////////////////////////////////////////////////////////// |
| 2950 |
// |
| 2951 |
// Using a red sphere to simulate the movement of a sattelite. |
| 2952 |
// |
| 2953 |
SoSeparator * |
| 2954 |
Solution::animateOrbitMovement(long int j, long int si) |
| 2955 |
// |
| 2956 |
/////////////////////////////////////////////////////////////////////////// |
| 2957 |
{ |
| 2958 |
float ptb[3]; |
| 2959 |
SoSeparator *satGroup = new SoSeparator; |
| 2960 |
|
| 2961 |
SoMaterial *satMtl = new SoMaterial; |
| 2962 |
satMtl->diffuseColor.setValue(1.0,0.0,0.0); |
| 2963 |
satMtl->transparency = 0.0; |
| 2964 |
|
| 2965 |
SoDrawStyle *satStyle = new SoDrawStyle; |
| 2966 |
satStyle->style = SoDrawStyle::FILLED; |
| 2967 |
satGroup->addChild(satStyle); |
| 2968 |
|
| 2969 |
SoBlinker *satBlker = new SoBlinker; |
| 2970 |
|
| 2971 |
int upperlimit = orbits_[j].numVerticesEachPeriod; |
| 2972 |
int idx = si; |
| 2973 |
satBlker->speed = satSpeed; |
| 2974 |
|
| 2975 |
float maxV[3], minV[3]; |
| 2976 |
maxV[0]=minV[0]=xyzCoords_[idx+0][0]; |
| 2977 |
maxV[1]=minV[1]=xyzCoords_[idx+0][0]; |
| 2978 |
maxV[2]=minV[2]=xyzCoords_[idx+0][0]; |
| 2979 |
double *time = new double[upperlimit]; |
| 2980 |
float dt = 1.0/upperlimit; |
| 2981 |
time[0] = 0.0; |
| 2982 |
for(int i=1; i<upperlimit; i++) |
| 2983 |
{ |
| 2984 |
if(maxV[0]<xyzCoords_[idx+i][0]) maxV[0]=xyzCoords_[idx+i][0] ; |
| 2985 |
if(minV[0]>xyzCoords_[idx+i][0]) minV[0]=xyzCoords_[idx+i][0] ; |
| 2986 |
if(maxV[1]<xyzCoords_[idx+i][1]) maxV[1]=xyzCoords_[idx+i][1] ; |
| 2987 |
if(minV[1]>xyzCoords_[idx+i][1]) minV[1]=xyzCoords_[idx+i][1] ; |
| 2988 |
if(maxV[2]<xyzCoords_[idx+i][2]) maxV[2]=xyzCoords_[idx+i][2] ; |
| 2989 |
if(minV[2]>xyzCoords_[idx+i][2]) minV[2]=xyzCoords_[idx+i][2] ; |
| 2990 |
time[i] = i*dt; |
| 2991 |
} |
| 2992 |
float dis = std::max(std::max((maxV[0]-minV[0]), (maxV[1]-minV[1])), |
| 2993 |
(maxV[2]-minV[2])); |
| 2994 |
|
| 2995 |
// animate the orbit |
| 2996 |
ptb[0]=xyzCoords_[idx][0]; |
| 2997 |
ptb[1]=xyzCoords_[idx][1]; |
| 2998 |
ptb[2]=xyzCoords_[idx][2]; |
| 2999 |
satBlker->addChild(drawASphere(ptb,1.*dis/100.0)); |
| 3000 |
|
| 3001 |
for(int i=1; i<upperlimit; i++) |
| 3002 |
{ |
| 3003 |
int m = 1; |
| 3004 |
while(time[i] > time_[idx+m] && m < upperlimit) ++m; |
| 3005 |
|
| 3006 |
if( fabs(time[i]-time_[m]) <= 1.0e-9 ) |
| 3007 |
{ |
| 3008 |
ptb[0]=xyzCoords_[idx+m][0]; |
| 3009 |
ptb[1]=xyzCoords_[idx+m][1]; |
| 3010 |
ptb[2]=xyzCoords_[idx+m][2]; |
| 3011 |
satBlker->addChild(drawASphere(ptb,1.*dis/100.0)); |
| 3012 |
} |
| 3013 |
else |
| 3014 |
{ |
| 3015 |
ptb[0]= (xyzCoords_[idx+m][0]+xyzCoords_[idx+m-1][0])/2.0; |
| 3016 |
ptb[1]= (xyzCoords_[idx+m][1]+xyzCoords_[idx+m-1][1])/2.0; |
| 3017 |
ptb[2]= (xyzCoords_[idx+m][2]+xyzCoords_[idx+m-1][2])/2.0; |
| 3018 |
satBlker->addChild(drawASphere(ptb,1.*dis/100.0)); |
| 3019 |
} |
| 3020 |
} |
| 3021 |
delete [] time; |
| 3022 |
satGroup->addChild(satMtl); |
| 3023 |
satGroup->addChild(satBlker); |
| 3024 |
return satGroup; |
| 3025 |
} |
| 3026 |
|
| 3027 |
/////////////////////////////////////////////////////////////////////////// |
| 3028 |
// |
| 3029 |
// This routine animate the calculation steps, namely the density of the |
| 3030 |
// collocation points. |
| 3031 |
// |
| 3032 |
SoSeparator * |
| 3033 |
Solution::animateOrbitCalSteps(long int snOrbit, long int si) |
| 3034 |
// |
| 3035 |
/////////////////////////////////////////////////////////////////////////// |
| 3036 |
{ |
| 3037 |
float ptb[3]; |
| 3038 |
SoSeparator *satGroup = new SoSeparator; |
| 3039 |
SoMaterial *satMtl = new SoMaterial; |
| 3040 |
satMtl->diffuseColor.setValue(envColors[7]); |
| 3041 |
satMtl->transparency = 0.0; |
| 3042 |
|
| 3043 |
SoDrawStyle *satStyle = new SoDrawStyle; |
| 3044 |
satStyle->style = SoDrawStyle::FILLED; |
| 3045 |
satGroup->addChild(satStyle); |
| 3046 |
|
| 3047 |
SoBlinker *satBlker = new SoBlinker; |
| 3048 |
|
| 3049 |
int upperlimit = numVerticesEachPeriod_[snOrbit-1]; |
| 3050 |
int idx = si; |
| 3051 |
satBlker->speed = satSpeed; |
| 3052 |
|
| 3053 |
float maxV[3], minV[3]; |
| 3054 |
maxV[0]=minV[0]=xyzCoords_[idx+0][0]; |
| 3055 |
maxV[1]=minV[1]=xyzCoords_[idx+0][0]; |
| 3056 |
maxV[2]=minV[2]=xyzCoords_[idx+0][0]; |
| 3057 |
|
| 3058 |
for(int i=1; i<upperlimit; i++) |
| 3059 |
{ |
| 3060 |
if(maxV[0]<xyzCoords_[idx+i][0]) maxV[0]=xyzCoords_[idx+i][0] ; |
| 3061 |
if(minV[0]>xyzCoords_[idx+i][0]) minV[0]=xyzCoords_[idx+i][0] ; |
| 3062 |
if(maxV[1]<xyzCoords_[idx+i][1]) maxV[1]=xyzCoords_[idx+i][1] ; |
| 3063 |
if(minV[1]>xyzCoords_[idx+i][1]) minV[1]=xyzCoords_[idx+i][1] ; |
| 3064 |
if(maxV[2]<xyzCoords_[idx+i][2]) maxV[2]=xyzCoords_[idx+i][2] ; |
| 3065 |
if(minV[2]>xyzCoords_[idx+i][2]) minV[2]=xyzCoords_[idx+i][2] ; |
| 3066 |
} |
| 3067 |
|
| 3068 |
float dis = fabs(std::max(std::max((maxV[0]-minV[0]), (maxV[1]-minV[1])), |
| 3069 |
(maxV[2]-minV[2]))); |
| 3070 |
for(int i=0; i<upperlimit; i++) |
| 3071 |
{ |
| 3072 |
ptb[0]=xyzCoords_[idx+i][0]; |
| 3073 |
ptb[1]=xyzCoords_[idx+i][1]; |
| 3074 |
ptb[2]=xyzCoords_[idx+i][2]; |
| 3075 |
satBlker->addChild(drawASphere(ptb,1.*dis/100.0)); |
| 3076 |
} |
| 3077 |
satGroup->addChild(satMtl); |
| 3078 |
satGroup->addChild(satBlker); |
| 3079 |
|
| 3080 |
return satGroup; |
| 3081 |
} |
| 3082 |
|
| 3083 |
/////////////////////////////////////////////////////////////////////////// |
| 3084 |
// Using a red ball to simulate the movement of a sattelite and using |
| 3085 |
// white lines to simulate the trace of the sattelite. |
| 3086 |
// |
| 3087 |
// !!!!!!!!!!!!!!!!!!!THIS VERSION DOES NOT WORK YET!!!!!!!!!!!!! |
| 3088 |
// |
| 3089 |
// |
| 3090 |
SoSeparator * |
| 3091 |
Solution::animateOrbitWithNurbsCurveTail(long int j, long int si) |
| 3092 |
// |
| 3093 |
/////////////////////////////////////////////////////////////////////////// |
| 3094 |
{ |
| 3095 |
SoSeparator *satGroup = new SoSeparator; |
| 3096 |
SoMaterial *tailMtl = new SoMaterial; |
| 3097 |
tailMtl->diffuseColor.setValue(1.0,1.0,1.0); |
| 3098 |
tailMtl->transparency = 0.0; |
| 3099 |
|
| 3100 |
SoDrawStyle *satStyle = new SoDrawStyle; |
| 3101 |
satStyle->style = SoDrawStyle::FILLED; |
| 3102 |
satGroup->addChild(satStyle); |
| 3103 |
|
| 3104 |
int upperlimit = orbits_[j].numVerticesEachPeriod; |
| 3105 |
int idx = si; |
| 3106 |
|
| 3107 |
float maxV[3], minV[3]; |
| 3108 |
double *time = new double[upperlimit]; |
| 3109 |
double dt = 1.0/upperlimit; |
| 3110 |
maxV[0]=minV[0]=xyzCoords_[idx+0][0]; |
| 3111 |
maxV[1]=minV[1]=xyzCoords_[idx+0][0]; |
| 3112 |
maxV[2]=minV[2]=xyzCoords_[idx+0][0]; |
| 3113 |
|
| 3114 |
time[0] = 0.0; |
| 3115 |
for(int i=1; i<upperlimit; i++) |
| 3116 |
{ |
| 3117 |
if(maxV[0]<xyzCoords_[idx+i][0]) maxV[0]=xyzCoords_[idx+i][0] ; |
| 3118 |
if(minV[0]>xyzCoords_[idx+i][0]) minV[0]=xyzCoords_[idx+i][0] ; |
| 3119 |
if(maxV[1]<xyzCoords_[idx+i][1]) maxV[1]=xyzCoords_[idx+i][1] ; |
| 3120 |
if(minV[1]>xyzCoords_[idx+i][1]) minV[1]=xyzCoords_[idx+i][1] ; |
| 3121 |
if(maxV[2]<xyzCoords_[idx+i][2]) maxV[2]=xyzCoords_[idx+i][2] ; |
| 3122 |
if(minV[2]>xyzCoords_[idx+i][2]) minV[2]=xyzCoords_[idx+i][2] ; |
| 3123 |
time[i] = i*dt; |
| 3124 |
} |
| 3125 |
|
| 3126 |
float dis = fabs(std::max(std::max((maxV[0]-minV[0]), (maxV[1]-minV[1])), |
| 3127 |
(maxV[2]-minV[2]))); |
| 3128 |
|
| 3129 |
float (*myVertices)[3]= new float[upperlimit][3]; |
| 3130 |
|
| 3131 |
myVertices[0][0]=xyzCoords_[idx][0]; |
| 3132 |
myVertices[0][1]=xyzCoords_[idx][1]; |
| 3133 |
myVertices[0][2]=xyzCoords_[idx][2]; |
| 3134 |
for(int i=1; i<upperlimit; i++) |
| 3135 |
{ |
| 3136 |
int m = 1; |
| 3137 |
while(time[i] > time_[idx+m] && m < upperlimit) ++m; |
| 3138 |
|
| 3139 |
if( fabs(time[i]-time_[m]) <= 1.0e-9 ) |
| 3140 |
{ |
| 3141 |
myVertices[i][0]=xyzCoords_[idx+m][0]; |
| 3142 |
myVertices[i][1]=xyzCoords_[idx+m][1]; |
| 3143 |
myVertices[i][2]=xyzCoords_[idx+m][2]; |
| 3144 |
} |
| 3145 |
else |
| 3146 |
{ |
| 3147 |
myVertices[i][0]= (xyzCoords_[idx+m][0]+xyzCoords_[idx+m-1][0])/2.0; |
| 3148 |
myVertices[i][1]= (xyzCoords_[idx+m][1]+xyzCoords_[idx+m-1][1])/2.0; |
| 3149 |
myVertices[i][2]= (xyzCoords_[idx+m][2]+xyzCoords_[idx+m-1][2])/2.0; |
| 3150 |
} |
| 3151 |
} |
| 3152 |
|
| 3153 |
SoCoordinate3 *myCoords = new SoCoordinate3; |
| 3154 |
myCoords->point.setValues(0, upperlimit, myVertices); |
| 3155 |
satGroup->addChild(myCoords); |
| 3156 |
|
| 3157 |
SoTimeCounter *myCounter = new SoTimeCounter; |
| 3158 |
myCounter->max = upperlimit-1; |
| 3159 |
myCounter->min = 4; |
| 3160 |
myCounter->frequency = 0.1*satSpeed; |
| 3161 |
|
| 3162 |
SoLineSet *myLine= new SoLineSet; |
| 3163 |
myLine->numVertices.connectFrom(&myCounter->output); |
| 3164 |
satGroup->addChild(tailMtl); |
| 3165 |
satGroup->addChild(myLine); |
| 3166 |
|
| 3167 |
SoMaterial * satMtl = new SoMaterial; |
| 3168 |
SoSphere * mySat = new SoSphere; |
| 3169 |
mySat->radius = dis*0.005*satRadius; |
| 3170 |
|
| 3171 |
SoTranslation * satTrans = new SoTranslation; |
| 3172 |
satMtl->diffuseColor.setValue(envColors[7]); |
| 3173 |
satGroup->addChild(satMtl); |
| 3174 |
satGroup->addChild(satTrans); |
| 3175 |
satGroup->addChild(mySat); |
| 3176 |
|
| 3177 |
SoSelectOne *mysel = new SoSelectOne(SoMFVec3f::getClassTypeId()); |
| 3178 |
mysel->index.connectFrom(&myCounter->output); |
| 3179 |
mysel->input->enableConnection(TRUE); |
| 3180 |
mysel->input->connectFrom(&myCoords->point); |
| 3181 |
satTrans->translation.connectFrom(mysel->output); |
| 3182 |
|
| 3183 |
delete [] myVertices; |
| 3184 |
delete [] time; |
| 3185 |
|
| 3186 |
return satGroup; |
| 3187 |
} |
| 3188 |
|
| 3189 |
/////////////////////////////////////////////////////////////////////////// |
| 3190 |
// |
| 3191 |
SoSeparator * |
| 3192 |
Solution::drawEarthMovement(int k) |
| 3193 |
// |
| 3194 |
/////////////////////////////////////////////////////////////////////////// |
| 3195 |
{ |
| 3196 |
SoSeparator * eSep = new SoSeparator; |
| 3197 |
int32_t myint[10]; |
| 3198 |
|
| 3199 |
SoDrawStyle *drawStyle = new SoDrawStyle; |
| 3200 |
drawStyle->style = SoDrawStyle::FILLED; |
| 3201 |
drawStyle->lineWidth = 3.0; |
| 3202 |
eSep->addChild(drawStyle); |
| 3203 |
|
| 3204 |
SoMaterial *eMtl= new SoMaterial; |
| 3205 |
|
| 3206 |
eMtl->diffuseColor.setValue(0.0,0.5,0.5); |
| 3207 |
eMtl->transparency = 0.0; |
| 3208 |
eSep->addChild(eMtl); |
| 3209 |
|
| 3210 |
float vertices[30000][3]; |
| 3211 |
for(int i=0; i<orbits_[k].numVerticesEachPeriod; ++i) |
| 3212 |
{ |
| 3213 |
vertices[i][0]= cos(time_[i]/2.0/M_PI*360.0); |
| 3214 |
vertices[i][1]= sin(time_[i]*360.0/2.0/M_PI); |
| 3215 |
vertices[i][2]= 0; |
| 3216 |
} |
| 3217 |
myint[0]=orbits_[k].numVerticesEachPeriod; |
| 3218 |
SoCoordinate3 * eCoords = new SoCoordinate3; |
| 3219 |
eCoords->point.setValues(0, orbits_[k].numVerticesEachPeriod, vertices); |
| 3220 |
SoLineSet *eLine= new SoLineSet; |
| 3221 |
eLine->numVertices.setValues(0, 1, myint); |
| 3222 |
eSep->addChild(eCoords); |
| 3223 |
eSep->addChild(eLine); |
| 3224 |
return eSep; |
| 3225 |
} |
| 3226 |
|
| 3227 |
/////////////////////////////////////////////////////////////////////////// |
| 3228 |
// |
| 3229 |
// calculate the current position of the primary at time t in the inertial frame |
| 3230 |
// |
| 3231 |
void |
| 3232 |
Solution::calPrimPos(float t, float pos[]) |
| 3233 |
// |
| 3234 |
/////////////////////////////////////////////////////////////////////////// |
| 3235 |
{ |
| 3236 |
pos[0] = cos(t); |
| 3237 |
pos[1] = sin(t); |
| 3238 |
pos[2] = 0; |
| 3239 |
} |
| 3240 |
|
| 3241 |
|
| 3242 |
/////////////////////////////////////////////////////////////////////////// |
| 3243 |
// |
| 3244 |
// Given time t and the position of the moving primary in the inertial frame |
| 3245 |
// to calculate the current position of the satllite position in the intertial frame. |
| 3246 |
// |
| 3247 |
void |
| 3248 |
Solution::calSatPos(int center, float mu, float t, float primPos[], float satPos[]) |
| 3249 |
// |
| 3250 |
/////////////////////////////////////////////////////////////////////////// |
| 3251 |
{ |
| 3252 |
float a1, a0, b1, b0; |
| 3253 |
float c = 0; |
| 3254 |
|
| 3255 |
// c = 1-mu if the center of the inertial system is |
| 3256 |
// the Earth(smaller primary). |
| 3257 |
// c = -mu if the center is the Sun (bigger primary). |
| 3258 |
// c = 0 if the center is the barycenter. |
| 3259 |
if(center == 0) c = 0; |
| 3260 |
else if(center == 1) c = -mu; |
| 3261 |
else c = 1-mu; |
| 3262 |
|
| 3263 |
// calculate the current position of the satllite |
| 3264 |
a1 = primPos[1]; |
| 3265 |
a0 = primPos[0]; |
| 3266 |
b1 = satPos[1]; |
| 3267 |
b0 = satPos[0]; |
| 3268 |
satPos[0] = b0*a0-b1*a1; |
| 3269 |
satPos[1] = b1*a0+b0*a1; |
| 3270 |
} |
| 3271 |
|
| 3272 |
/////////////////////////////////////////////////////////////////////////// |
| 3273 |
// |
| 3274 |
SoSeparator * |
| 3275 |
Solution::drawASphereWithColor(float color[], float position[], float size) |
| 3276 |
// |
| 3277 |
/////////////////////////////////////////////////////////////////////////// |
| 3278 |
{ |
| 3279 |
SoSeparator *satSep = new SoSeparator; |
| 3280 |
SoTransform *satXform = new SoTransform; |
| 3281 |
satXform->translation.setValue(position[0],position[1],position[2]); |
| 3282 |
|
| 3283 |
SoMaterial *satMtl = new SoMaterial; |
| 3284 |
satMtl->diffuseColor.setValue(color); |
| 3285 |
satMtl->transparency = 0.0; |
| 3286 |
satSep->addChild(satMtl); |
| 3287 |
|
| 3288 |
SoSphere *satSph = new SoSphere; |
| 3289 |
satSph->radius = size; |
| 3290 |
|
| 3291 |
satSep->addChild(satXform); |
| 3292 |
satSep->addChild(satSph); |
| 3293 |
|
| 3294 |
return satSep; |
| 3295 |
} |
| 3296 |
#endif |