// Computergraphik I // Prof. Dr. Juergen Doellner // Sommersemester 2001 // // Rahmenprogramm fuer Aufgabenzettel 8 #include "node.h" #include #include #include // // LeafNode // LeafNode::LeafNode(Shape* shape) : shape_(shape) { } void LeafNode::traverse() { if(shape_) { shape_->render(); } // cout << shape_ << " "; } // // GroupNode // GroupNode::GroupNode() { // Initialisiere alle Attribute mit NULL for(unsigned int i = 0; i < MAX_ATTRIBUTES; ++i) { attributes_[i] = 0; } // Initialisiere alle Kind-Knoten mit NULL for(unsigned int j = 0; j < MAX_CHILD_NODES; ++j) { children_[j] = 0; } } GroupNode* GroupNode::shareNode(Node* nodeObject, int nCount, Attribute* attrTransform1, Attribute* attrTransform2) { GroupNode* sharedNode = NULL; for (int shape = 1; shape <= nCount; shape++) { static GroupNode* oldNode; oldNode = sharedNode; sharedNode = new GroupNode; if (shape < nCount) { if (attrTransform1 != NULL) sharedNode->setAttribute(0, attrTransform1); if (attrTransform2 != NULL) sharedNode->setAttribute(1, attrTransform2); } sharedNode->setChildNode(0, nodeObject); if (oldNode != NULL) sharedNode->setChildNode(1, oldNode); } return sharedNode; } Attribute* GroupNode::getAttribute(unsigned int index) const { assert(index < MAX_ATTRIBUTES); return attributes_[index]; } void GroupNode::setAttribute(unsigned int index, Attribute* attribute) { assert(index < MAX_ATTRIBUTES); attributes_[index] = attribute; } Node* GroupNode::getChildNode(unsigned int index) const { assert(index < MAX_CHILD_NODES); return children_[index]; } void GroupNode::setChildNode(unsigned int index, Node* child) { assert(index < MAX_CHILD_NODES); children_[index] = child; } void GroupNode::traverse() { // Setzte alle Attribute for(unsigned int i = 0; i < MAX_ATTRIBUTES; ++i) { if(attributes_[i]) { attributes_[i]->set(); } } // Traversiere alle Kind-Knoten for(unsigned int j = 0; j < MAX_CHILD_NODES; ++j) { if(children_[j]) { children_[j]->traverse(); } } // Setzte alle Attribute in umgekehrter Reihenfolge zurueck for(unsigned int k = MAX_ATTRIBUTES; k > 0; --k) { if(attributes_[k - 1]) { attributes_[k - 1]->unset(); } } }