color_fixed raytracer ( ray *r, kdTreeNode* currentPacket, scene *myScene ) { // Initialing variables color_fixed c1 = {0,0,0}; //where to keep the color values node rayNodes[MAXRAYS]; node* freeRayNodes; freeRayNodes = initFreeNodeList( rayNodes ); //GENERATE TREE node* root = requestNode( &freeRayNodes ); if ( root != NULL ) { //cout << "root full" << endl; initNode( root, NULL, currentPacket, *r, NULL, 0, ROOT_RAY, OUTSIDE ); node * courant = root; //adding and inserting nodes while ( courant != NULL ) { // cout<< "ray: x " << courant->v.start.x // << " y"<< courant->v.start.y // <<" z " << courant->v.start.z <<endl; // cout << " Not arrived to the root yet" << endl; // cout << "ray start x"<< r.start.x // << " y " << r.start.y // << " z " << r.start.z <<endl; // cout << "ray dir x"<< r.dir.x // << " y " << r.dir.y // << " z " << r.dir.z <<endl; // cout << "r start x"<< courant->v.start.x // << " y " << courant->v.start.y // << " z " << courant->v.start.z <<endl; // cout << "r dir x"<< courant->v.dir.x // << " y " << courant->v.dir.y // << " z " << courant->v.dir.z <<endl; // cout << "intersection ray" << endl; courant->lastIntercepted = figureIntersection( courant, myScene, &courant->t ); c1 += lightContribution ( courant, myScene ); //cout << "intersection surface" << endl; courant = treeGenerator( &freeRayNodes, MAXDEPTH, courant, myScene ); } } else { //cout << "no node available" << endl; } //the tree will be destroyed when exiting the function return c1; }
vector<TreeNode*> treeGenerator(int s, int e) { vector<TreeNode*> rst; if (s > e) rst.push_back(NULL); if (s == e) rst.push_back(new TreeNode(s)); if (s < e){ for (int i = s; i <= e; ++i){ vector<TreeNode*> ltrees = treeGenerator(s, i - 1); vector<TreeNode*> rtrees = treeGenerator(i + 1, e); for (int j = 0; j < ltrees.size(); ++j) for (int k = 0; k < rtrees.size(); ++k){ TreeNode *node = new TreeNode(i); //if (ltrees[j]->val != 0) node->left = ltrees[j]; //if (rtrees[k]->val != 0) node->right = rtrees[k]; rst.push_back(node); } } } return rst; }
vector<TreeNode*> generateTrees(int n) { vector<TreeNode*> tmp; if (n == 0) return tmp; return treeGenerator(1, n); }