src/kdtree.cc
branchpyrit
changeset 42 fbdeb3e04543
parent 35 fb170fccb19f
child 44 3763b26244f0
equal deleted inserted replaced
41:c1080cb5bd6d 42:fbdeb3e04543
   160 		}
   160 		}
   161 	}
   161 	}
   162 
   162 
   163 	// choose best split pos
   163 	// choose best split pos
   164 	const Float K = 1.4; // constant, K = cost of traversal / cost of ray-triangle intersection
   164 	const Float K = 1.4; // constant, K = cost of traversal / cost of ray-triangle intersection
   165 	Float SAV = 2*(bbox.w()*bbox.h() + bbox.w()*bbox.d() + bbox.h()*bbox.d()); // surface area of node
   165 	Float SAV = (bbox.w()*bbox.h() + bbox.w()*bbox.d() + bbox.h()*bbox.d()); // surface area of node
   166 	Float cost = SAV * (K + shapes->size()); // initial cost = non-split cost
   166 	Float cost = SAV * (K + shapes->size()); // initial cost = non-split cost
   167 	bool leaf = true;
   167 	bool leaf = true;
   168 	BBox lbb = bbox;
   168 	BBox lbb = bbox;
   169 	BBox rbb = bbox;
   169 	BBox rbb = bbox;
   170 	for (spl = splitlist.begin(); spl != splitlist.end(); spl++)
   170 	for (spl = splitlist.begin(); spl != splitlist.end(); spl++)
   171 	{
   171 	{
   172 		// calculate SAH cost of this split
   172 		// calculate SAH cost of this split
   173 		lbb.H.cell[axis] = spl->pos;
   173 		lbb.H.cell[axis] = spl->pos;
   174 		rbb.L.cell[axis] = spl->pos;
   174 		rbb.L.cell[axis] = spl->pos;
   175 		Float SAL = 2*(lbb.w()*lbb.h() + lbb.w()*lbb.d() + lbb.h()*lbb.d());
   175 		Float SAL = (lbb.w()*lbb.h() + lbb.w()*lbb.d() + lbb.h()*lbb.d());
   176 		Float SAR = 2*(rbb.w()*rbb.h() + rbb.w()*rbb.d() + rbb.h()*rbb.d());
   176 		Float SAR = (rbb.w()*rbb.h() + rbb.w()*rbb.d() + rbb.h()*rbb.d());
   177 		Float splitcost = K + SAL/SAV*(K+spl->lnum) + SAR/SAV*(K+spl->rnum);
   177 		Float splitcost = K*SAV + SAL*(K+spl->lnum) + SAR*(K+spl->rnum);
   178 
   178 
   179 		if (splitcost < cost)
   179 		if (splitcost < cost)
   180 		{
   180 		{
   181 			leaf = false;
   181 			leaf = false;
   182 			cost = splitcost;
   182 			cost = splitcost;