Node.cpp

Go to the documentation of this file.
00001 //------------------------------------------------------------------------------ 00003 00004 // Last Change: 2004/06/11 00005 // Version: 0.4 00006 00007 //---------------------------------------------------------------------includes- 00008 #include "../src/main.h" 00009 #include "../src/Node.h" 00010 00011 //---------------------------------------------------------operator overloading- 00012 // 00013 // This compares two nodes and returns 0 if they are not equal (member wise) 00014 // and 1 else. 00015 // @return Returns 0 if two nodes aren't equal and 0 else. 00016 // 00017 int Node::operator==(Node &to_compare_node) 00018 { 00019 // we assume that every node has a distinct caption !! 00020 if (id_ == to_compare_node.getID()) 00021 { 00022 return(1); 00023 } 00024 return(0); 00025 } 00026 00027 //------------------------------------------------------------------------setID- 00028 // 00029 // This sets the ID of one node. 00030 // @param id The ID of the node. 00031 // 00032 void Node::setID(GLuint id) 00033 { 00034 id_ = id; 00035 } 00036 00037 //------------------------------------------------------------------------getID- 00038 // 00039 // This returns the ID of one node. 00040 // @returns id The ID of the node. 00041 // 00042 GLuint Node::getID() 00043 { 00044 return (id_); 00045 } 00046 00047 //-------------------------------------------------------------------setCaption- 00048 // 00049 // This sets the caption of the node. 00050 // @param caption The caption to set. 00051 // 00052 void Node::setCaption(char const *caption) 00053 { 00054 caption_ = reinterpret_cast<char const*>(caption); 00055 } 00056 00057 //-------------------------------------------------------------------getID- 00058 // 00059 // This returns the caption of the node. 00060 // @return Returns the cpation of the node. 00061 // 00062 char const *Node::getCaption() 00063 { 00064 return(caption_); 00065 } 00066 00067 //---------------------------------------------------------------setPointVector- 00068 // 00069 // This sets point vector which indicates the position of the node in the 00070 // space. 00071 // @param point_vector The point vector of the node. 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 //---------------------------------------------------------------getPointVector- 00083 // 00084 // This returns the point vector which indicates the position of the node in 00085 // the space. 00086 // @return Returs the point vector of the node. 00087 // 00088 Vector3D *Node::getPointVector() const 00089 { 00090 return(point_vector_); 00091 } 00092 00093 //--------------------------------------------------------------setAngularWidth- 00094 // 00095 // This sets the angular width for the node. 00096 // @param angular_width The angular width to set. 00097 // 00098 void Node::setAngularWidth(GLfloat angular_width) 00099 { 00100 angular_width_ = angular_width; 00101 } 00102 00103 //--------------------------------------------------------------getAngularWidth- 00104 // 00105 // This returns the angular width for the node. 00106 // @return The angular width. 00107 // 00108 GLfloat Node::getAngularWidth() 00109 { 00110 return(angular_width_); 00111 } 00112 00113 //----------------------------------------------------------------------setRing- 00114 // 00115 // This sets the ring number. 00116 // @param ring The ring number. 00117 // 00118 void Node::setRing(GLuint ring_number) 00119 { 00120 ring_number_ = ring_number; 00121 } 00122 00123 //----------------------------------------------------------------------getRing- 00124 // 00125 // This returns the ring on which the node is sitting on. 00126 // @return The ring. 00127 // 00128 GLuint Node::getRing() const 00129 { 00130 return(ring_number_); 00131 } 00132 00133 //-----------------------------------------------------------setOneAdjacentNode- 00134 // 00135 // This sets one adjacent node to this node. 00136 // @param node The adjacent node to set. 00137 // 00138 void Node::setOneAdjacentNode(Node *node) 00139 { 00140 adjacents_.push_back(node); 00141 // initialize the number of leafs when node is connected with the graph 00142 num_leafs_.push_back(0); 00143 } 00144 00145 //--------------------------------------------------------deleteOneAdjacentNode- 00146 // 00147 // This deletes one adjacent node. 00148 // @param node The adjacent node to delet. 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 //-------------------------------------------------------getListOfAdjacentNodes- 00165 // 00166 // This returns the list (i.e. vector) of adjacent nodes. 00167 // @return The list of adjacent nodes. 00168 // 00169 vector<Node*> *Node::getListOfAdjacentNodes() 00170 { 00171 return(&adjacents_); 00172 } 00173 00174 //----------------------------------------------------------getListOfLeafeNodes- 00175 // 00176 // This returns the list (i.e. vector) of adjacent nodes. 00177 // @return The list of adjacent nodes. 00178 // 00179 vector<GLuint> *Node::getListOfLeafeNodes() 00180 { 00181 return(&num_leafs_); 00182 } 00183 00184 //--------------------------------------------------------------------getDegree- 00185 // 00186 // This returns the degree of the node. 00187 // @return The degree of the node. 00188 // 00189 GLuint Node::getDegree() 00190 { 00191 return((GLuint)adjacents_.size()); 00192 } 00193 00194 //--------------------------------------------------------------incrNumOfLeafs- 00195 // 00196 // This increments the number of leafs which are reachable from this node coming 00197 // from the specified node (see parameter). 00198 // @param root The root of the sub-tree. 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 // && ((*iter_1)->getLastVisitor() != id_)) 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 //-----------------------------------------------------------------getNumLeafs- 00222 // 00223 // This returns the number of leafs for the corresponding Node in the adjacent 00224 // nodes list. 00225 // @return The number of leafs. 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 //------------------------------------------------getTotalNumOfLeafsExceptRoot- 00244 // 00245 // This returns the number of leafs for the corresponding Node in the adjacent 00246 // nodes list and excludes the root. 00247 // @return The number of leafs. 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 //--------------------------------------------------------------------eraseNode- 00267 // 00268 // This erases this node. That means that every link to this node is going to be 00269 // erased. 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 //---------------------------------------------------------------------drawNode- 00293 // 00294 // This draws the node into an OpenGL viewport. 00295 // @param quadric The quadric which represents the node for drawing. 00296 // @param render_mode The render mode of the quardric. 00297 // @param render_mode The caption mode of the quardric. 00298 // 00299 void Node::drawNode(GLUquadricObj *quadric, bool render_mode, bool caption_mode) 00300 { 00301 // set material and light properties 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 // enable light and material color 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 // glRotatef(-z_rotation_, 0.0f, 0.0f, 1.0f); 00339 // glRotatef(-y_rotation_, 0.0f, 1.0f, 0.0f); 00340 // glRotatef(-x_rotation_, 1.0f, 0.0f, 0.0f); 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 // gluSphere(quadric, node_radius_ + 0.02, 50, 50); 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 // Disable lighting while we render text 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 // render the live character array 'text' 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 // disable light and material color 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 //----------------------------------------------------------------------setAngle- 00404 // 00405 // This sets the angle of one node 00406 // @param polar_phi_ The phi angle of the node 00407 // 00408 void Node::setAngle(GLfloat polar_phi) 00409 { 00410 polar_phi_ = polar_phi; 00411 } 00412 00413 //----------------------------------------------------------------------getAngle- 00414 // 00415 // This returns the angle of one node 00416 // @return Returns The phi angle of the node 00417 // 00418 GLfloat Node::getAngle() const 00419 { 00420 return(polar_phi_); 00421 } 00422 00423 //---------------------------------------------------------------------getRadius- 00424 // 00425 // This sets the radius of one node 00426 // @param ring_radius_ The node/ring 00427 // 00428 void Node::setRadius(GLfloat ring_radius) 00429 { 00430 ring_radius_ = ring_radius; 00431 } 00432 00433 //---------------------------------------------------------------------setRadius- 00434 // 00435 // This returns the radius of one node 00436 // @return Returns The radius of the node 00437 // 00438 GLfloat Node::getRadius() const 00439 { 00440 return(ring_radius_); 00441 } 00442 00443 //-----------------------------------------------------------------------setRed- 00444 // 00445 // This sets the color of one node 00446 // @param red The red part of the RGB color. 00447 // 00448 void Node::setRed(GLuint red) 00449 { 00450 red_ = red; 00451 } 00452 00453 //----------------------------------------------------------------------setGreen- 00454 // 00455 // This sets the color of one node 00456 // @param green The green part of the RGB color. 00457 // 00458 void Node::setGreen(GLuint green) 00459 { 00460 green_ = green; 00461 } 00462 00463 //----------------------------------------------------------------------setBlue- 00464 // 00465 // This sets the color of one node 00466 // @param blue The blue part of tehe RGB color. 00467 // 00468 void Node::setBlue(GLuint blue) 00469 { 00470 blue_ = blue; 00471 } 00472 00473 //-----------------------------------------------------------------------getRed- 00474 // 00475 // This returns the red part of tehe RGB color of one node. 00476 // @return red Returns the red part of the RGB color. 00477 // 00478 GLuint Node::getRed() 00479 { 00480 return(red_); 00481 } 00482 00483 //---------------------------------------------------------------------getGreen- 00484 // 00485 // This returns the green part of tehe RGB color of one node. 00486 // @return red Returns the green part of tehe RGB color. 00487 // 00488 GLuint Node::getGreen() 00489 { 00490 return(green_); 00491 } 00492 00493 //----------------------------------------------------------------------getBlue- 00494 // 00495 // This returns the blue part of tehe RGB color of one node. 00496 // @return red Returns the blue part of tehe RGB color. 00497 // 00498 GLuint Node::getBlue() 00499 { 00500 return(blue_); 00501 } 00502 00503 //----------------------------------------------------------------setNodeRadius- 00504 // 00505 // This sets the radius of one node, 00506 // @param ring_radius_ The node/ring 00507 // 00508 void Node::setNodeRadius(GLfloat node_radius) 00509 { 00510 node_radius_ = node_radius; 00511 } 00512 00513 //----------------------------------------------------------------getNodeRadius- 00514 // 00515 // This returns the radius of one node. 00516 // @return Returns The radius of the node 00517 // 00518 GLfloat Node::getNodeRadius() const 00519 { 00520 return(node_radius_); 00521 } 00522 00523 //---------------------------------------------------------------setLastVisitor- 00524 // 00525 // This sets the last visitor root. 00526 // @param last_visitor The last visitor root to set. 00527 // 00528 void Node::setLastVisitor(GLint last_visitor) 00529 { 00530 last_visitor_ = last_visitor; 00531 } 00532 00533 //---------------------------------------------------------------getLastVisitor- 00534 // 00535 // This returns the last visitor-root during the leaf number actualization 00536 // process. 00537 // @return red Returns the last visitor root. 00538 // 00539 GLint Node::getLastVisitor() 00540 { 00541 return(last_visitor_); 00542 } 00543 00544 //------------------------------------------------------------------setSelected- 00545 // 00546 // This sets a node to be selected (for highlighting). 00547 // @param is_selected Indicates if a node has been selected. 00548 // 00549 void Node::setSelected(bool is_selected) 00550 { 00551 is_selected_ = is_selected; 00552 } 00553 00554 //---------------------------------------------------------------addAngleOffset- 00555 // 00556 // This adds some angle value to the angle offset member. 00557 // @param additional_angle_offset The angle offset to add. 00558 // 00559 void Node::addAngleOffset(GLfloat additional_angle_offset) 00560 { 00561 angle_offset_ += additional_angle_offset; 00562 } 00563 00564 //---------------------------------------------------------------getAngleOffset- 00565 // 00566 // This returns the angle offset of the node. 00567 // @return The angle offset. 00568 // 00569 GLfloat Node::getAngleOffset() 00570 { 00571 return(angle_offset_); 00572 } 00573 00574 //-----------------------------------------------------------------resetMembers- 00575 // 00576 // This resets the members of the node to default values. 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 //------------------------------------------------------------setRotaionOfScene- 00600 // 00601 // This sets the current rotation of the entire scene. 00602 // @param x_rotation The rotation along the x axis. 00603 // @param y_rotation The rotation along the y axis. 00604 // @param z_rotation The rotation along the z axis. 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 // eof

Generated on Mon Jun 14 12:48:56 2004 for InfoVis by doxygen 1.3.7