00001
00003
00004
00005
00006
00007
00008
#include "../src/main.h"
00009
#include "../src/Node.h"
00010
00011
00012
00013
00014
00015
00016
00017
int Node::operator==(
Node &to_compare_node)
00018 {
00019
00020
if (
id_ == to_compare_node.
getID())
00021 {
00022
return(1);
00023 }
00024
return(0);
00025 }
00026
00027
00028
00029
00030
00031
00032
void Node::setID(GLuint
id)
00033 {
00034
id_ =
id;
00035 }
00036
00037
00038
00039
00040
00041
00042 GLuint
Node::getID()
00043 {
00044
return (
id_);
00045 }
00046
00047
00048
00049
00050
00051
00052
void Node::setCaption(
char const *caption)
00053 {
00054
caption_ = reinterpret_cast<char const*>(caption);
00055 }
00056
00057
00058
00059
00060
00061
00062
char const *
Node::getCaption()
00063 {
00064
return(
caption_);
00065 }
00066
00067
00068
00069
00070
00071
00072
00073
void Node::setPointVector(
Vector3D *point_vector)
00074 {
00075
if (
point_vector_ != NULL)
00076 {
00077
delete(
point_vector_);
00078 }
00079
point_vector_ = point_vector;
00080 }
00081
00082
00083
00084
00085
00086
00087
00088
Vector3D *
Node::getPointVector()
const
00089
{
00090
return(
point_vector_);
00091 }
00092
00093
00094
00095
00096
00097
00098
void Node::setAngularWidth(GLfloat angular_width)
00099 {
00100
angular_width_ = angular_width;
00101 }
00102
00103
00104
00105
00106
00107
00108 GLfloat
Node::getAngularWidth()
00109 {
00110
return(
angular_width_);
00111 }
00112
00113
00114
00115
00116
00117
00118
void Node::setRing(GLuint ring_number)
00119 {
00120
ring_number_ = ring_number;
00121 }
00122
00123
00124
00125
00126
00127
00128 GLuint
Node::getRing()
const
00129
{
00130
return(
ring_number_);
00131 }
00132
00133
00134
00135
00136
00137
00138
void Node::setOneAdjacentNode(
Node *node)
00139 {
00140
adjacents_.push_back(node);
00141
00142
num_leafs_.push_back(0);
00143 }
00144
00145
00146
00147
00148
00149
00150
void Node::deleteOneAdjacentNode(
Node *node)
00151 {
00152 vector<Node*>::iterator iter =
adjacents_.begin();
00153
while (iter !=
adjacents_.end())
00154 {
00155
if ((*iter) == node)
00156 {
00157
adjacents_.erase(iter);
00158
break;
00159 }
00160 ++iter;
00161 }
00162 }
00163
00164
00165
00166
00167
00168
00169 vector<Node*> *
Node::getListOfAdjacentNodes()
00170 {
00171
return(&
adjacents_);
00172 }
00173
00174
00175
00176
00177
00178
00179 vector<GLuint> *
Node::getListOfLeafeNodes()
00180 {
00181
return(&
num_leafs_);
00182 }
00183
00184
00185
00186
00187
00188
00189 GLuint
Node::getDegree()
00190 {
00191
return((GLuint)
adjacents_.size());
00192 }
00193
00194
00195
00196
00197
00198
00199
00200
void Node::incrNumOfLeafs(
Node *root)
00201 {
00202 vector<Node*>::iterator iter_1 =
adjacents_.begin();
00203 vector<GLuint>::iterator iter_2 =
num_leafs_.begin();
00204 GLuint index = 0;
00205
while (iter_1 !=
adjacents_.end())
00206 {
00207 GLuint num_leafs = (*iter_2);
00208
if (((*iter_1)->getID() != root->
getID()))
00209
00210 {
00211
num_leafs_[index] = ++num_leafs;
00212
last_visitor_ = root->
getID();
00213 (*iter_1)->incrNumOfLeafs(
this);
00214 }
00215 ++index;
00216 ++iter_1;
00217 ++iter_2;
00218 }
00219 }
00220
00221
00222
00223
00224
00225
00226
00227 GLuint
Node::getNumLeafs(
Node *node)
00228 {
00229 vector<Node*>::iterator iter_1 =
adjacents_.begin();
00230 vector<GLuint>::iterator iter_2 =
num_leafs_.begin();
00231
while (iter_1 !=
adjacents_.end())
00232 {
00233
if (node->
getID() == (*iter_1)->getID())
00234 {
00235
break;
00236 }
00237 ++iter_1;
00238 ++iter_2;
00239 }
00240
return(*iter_2);
00241 }
00242
00243
00244
00245
00246
00247
00248
00249 GLuint
Node::getTotalNumOfLeafsExceptRoot(
Node *root)
00250 {
00251 vector<Node*>::iterator iter_1 =
adjacents_.begin();
00252 vector<GLuint>::iterator iter_2 =
num_leafs_.begin();
00253 GLuint num_leafs = 0;
00254
while (iter_1 !=
adjacents_.end())
00255 {
00256
if (root->
getID() != (*iter_1)->getID())
00257 {
00258 num_leafs += *iter_2;
00259 }
00260 ++iter_1;
00261 ++iter_2;
00262 }
00263
return(num_leafs);
00264 }
00265
00266
00267
00268
00269
00270
00271
void Node::eraseNode(
Node *node)
00272 {
00273 vector<Node*>::iterator iter_1 =
adjacents_.begin();
00274 vector<Node*>::iterator iter_2;
00275
00276
while (iter_1 !=
adjacents_.end())
00277 {
00278 iter_2 = (((*iter_1)->getListOfAdjacentNodes()))->begin();
00279
while (iter_2 != ((*iter_1)->getListOfAdjacentNodes())->end())
00280 {
00281
if (((*iter_2)->getID()) == (node->
getID()))
00282 {
00283 ((*iter_1)->getListOfAdjacentNodes())->erase(iter_2);
00284 --iter_2;
00285 }
00286 ++iter_2;
00287 }
00288 iter_1++;
00289 }
00290 }
00291
00292
00293
00294
00295
00296
00297
00298
00299
void Node::drawNode(GLUquadricObj *quadric,
bool render_mode,
bool caption_mode)
00300 {
00301
00302 GLfloat mat_ambient[] = {0.0f, 0.0f, 1.0f, 1.0f};
00303 GLfloat mat_diffuse[] = {0.0f, 0.0f, 0.8f, 1.0f};
00304 GLfloat light_position[] = {0.0f, 0.0f, -1.0f, 1.0f};
00305 GLfloat shininess[] = {0.5f};
00306
00307 glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
00308 glMaterialfv( GL_FRONT, GL_AMBIENT, mat_ambient);
00309 glMaterialfv( GL_FRONT, GL_DIFFUSE, mat_diffuse);
00310 glMaterialfv( GL_FRONT, GL_SHININESS, shininess);
00311 glLightfv(GL_LIGHT0, GL_POSITION, light_position);
00312
00313
00314 glEnable(GL_LIGHTING);
00315 glEnable(GL_LIGHT0);
00316 glEnable(GL_COLOR_MATERIAL);
00317 glEnable(GL_LINE_SMOOTH);
00318
00319
if (render_mode ==
true)
00320 {
00321 glEnable(GL_BLEND);
00322 glColor4f(red_, green_, blue_, 0.3f);
00323 }
00324
else
00325 {
00326 glDisable(GL_BLEND);
00327 glColor4ub(red_, green_, blue_, 1);
00328 }
00329 glTranslated(
point_vector_->
getXCoord(),
point_vector_->
getYCoord(), 0.0);
00330
00331 glPushMatrix();
00332 gluQuadricNormals(quadric, GLU_SMOOTH);
00333 gluQuadricDrawStyle(quadric, GLU_FILL);
00334 gluSphere(quadric, node_radius_, 50, 50);
00335 glPopMatrix();
00336
if (
is_selected_ ==
true)
00337 {
00338
00339
00340
00341
00342 glDisable(GL_BLEND);
00343 glDisable(GL_LIGHTING);
00344 glDisable(GL_LIGHT0);
00345 glDisable(GL_COLOR_MATERIAL);
00346 glColor3f(0.0f, 1.0f, 0.0f);
00347 gluQuadricNormals(quadric, GLU_SMOOTH);
00348 gluQuadricDrawStyle(quadric, GLU_FILL);
00349 glLineWidth(1.5f);
00350
00351 gluDisk(quadric, node_radius_, node_radius_ + 0.02, 200, 1);
00352 glEnable(GL_LIGHTING);
00353 glEnable(GL_LIGHT0);
00354 glEnable(GL_COLOR_MATERIAL);
00355 glColor3f(1.0f, 1.0f, 1.0f);
00356 glLineWidth(1.0f);
00357 glEnable(GL_BLEND);
00358 }
00359
00360 gluQuadricNormals(quadric, GLU_SMOOTH);
00361
00362
if (caption_mode)
00363 {
00364 glPushMatrix();
00365
00366
if (render_mode ==
true)
00367 {
00368 glDisable(GL_LIGHTING);
00369 glColor3ub(255, 255, 255);
00370 glDisable(GL_BLEND);
00371 }
00372
else
00373 {
00374 glDisable(GL_LIGHTING);
00375 glColor3ub(255, 255, 0);
00376 }
00377 glRasterPos3f(
point_vector_->
getXCoord()/100 - 0.04,
00378
point_vector_->
getYCoord()/100 - 0.04, 0.0f);
00379
00380
00381
for(
int curr_character = 0;
00382 curr_character < (
int)strlen(caption_);
00383 ++curr_character)
00384 {
00385 glutBitmapCharacter(GLUT_BITMAP_HELVETICA_18,
00386 caption_[curr_character]);
00387 }
00388 glPopMatrix();
00389 }
00390
00391
00392 glDisable(GL_LIGHTING);
00393 glDisable(GL_LIGHT0);
00394 glDisable(GL_COLOR_MATERIAL);
00395 glDisable(GL_LINE_SMOOTH);
00396
00397
if (render_mode ==
true)
00398 {
00399 glDisable(GL_BLEND);
00400 }
00401 }
00402
00403
00404
00405
00406
00407
00408
void Node::setAngle(GLfloat polar_phi)
00409 {
00410
polar_phi_ = polar_phi;
00411 }
00412
00413
00414
00415
00416
00417
00418 GLfloat
Node::getAngle()
const
00419
{
00420
return(
polar_phi_);
00421 }
00422
00423
00424
00425
00426
00427
00428
void Node::setRadius(GLfloat ring_radius)
00429 {
00430
ring_radius_ = ring_radius;
00431 }
00432
00433
00434
00435
00436
00437
00438 GLfloat
Node::getRadius()
const
00439
{
00440
return(
ring_radius_);
00441 }
00442
00443
00444
00445
00446
00447
00448
void Node::setRed(GLuint red)
00449 {
00450
red_ = red;
00451 }
00452
00453
00454
00455
00456
00457
00458
void Node::setGreen(GLuint green)
00459 {
00460
green_ = green;
00461 }
00462
00463
00464
00465
00466
00467
00468
void Node::setBlue(GLuint blue)
00469 {
00470
blue_ = blue;
00471 }
00472
00473
00474
00475
00476
00477
00478 GLuint
Node::getRed()
00479 {
00480
return(
red_);
00481 }
00482
00483
00484
00485
00486
00487
00488 GLuint
Node::getGreen()
00489 {
00490
return(
green_);
00491 }
00492
00493
00494
00495
00496
00497
00498 GLuint
Node::getBlue()
00499 {
00500
return(
blue_);
00501 }
00502
00503
00504
00505
00506
00507
00508
void Node::setNodeRadius(GLfloat node_radius)
00509 {
00510
node_radius_ = node_radius;
00511 }
00512
00513
00514
00515
00516
00517
00518 GLfloat
Node::getNodeRadius()
const
00519
{
00520
return(
node_radius_);
00521 }
00522
00523
00524
00525
00526
00527
00528
void Node::setLastVisitor(GLint last_visitor)
00529 {
00530
last_visitor_ = last_visitor;
00531 }
00532
00533
00534
00535
00536
00537
00538
00539 GLint
Node::getLastVisitor()
00540 {
00541
return(
last_visitor_);
00542 }
00543
00544
00545
00546
00547
00548
00549
void Node::setSelected(
bool is_selected)
00550 {
00551
is_selected_ = is_selected;
00552 }
00553
00554
00555
00556
00557
00558
00559
void Node::addAngleOffset(GLfloat additional_angle_offset)
00560 {
00561
angle_offset_ += additional_angle_offset;
00562 }
00563
00564
00565
00566
00567
00568
00569 GLfloat
Node::getAngleOffset()
00570 {
00571
return(
angle_offset_);
00572 }
00573
00574
00575
00576
00577
00578
void Node::resetMembers()
00579 {
00580
angular_width_ = 0.0f;
00581
ring_number_ = 0;
00582
ring_radius_ = 0;
00583
polar_phi_ = 0;
00584
polar_r_ = 0;
00585
alpha_ = 0;
00586
red_ = 0;
00587
green_ = 0;
00588
blue_ = 0;
00589
node_radius_ = 0;
00590
angle_offset_ = 0.0f;
00591 vector<GLuint>::iterator iter =
num_leafs_.begin();
00592
while (iter !=
num_leafs_.end())
00593 {
00594 (*iter) = 0;
00595 ++iter;
00596 }
00597 }
00598
00599
00600
00601
00602
00603
00604
00605
00606
void Node::setSceneRotation(GLfloat x_rotation, GLfloat y_rotation,
00607 GLfloat z_rotation)
00608 {
00609
x_rotation_ = x_rotation;
00610
y_rotation_ = y_rotation;
00611
z_rotation_ = z_rotation;
00612 }
00613
00614