Lines Matching defs:node1
242 * merge nodes <node1> and <node2> at location <ref> with parent <parent>
244 static int octreeMerge(pool<Ocnode> *pool, Ocnode *parent, Ocnode **ref, Ocnode *node1, Ocnode *node2)
247 if (!node1 && !node2) return 0;
248 assert(node1 != node2);
250 if (!node1)
257 *ref = node1; node1->ref = ref; node1->parent = parent;
258 return node1->nleaf;
260 int dwitdth = node1->width - node2->width;
261 if (dwitdth > 0 && node1->rgb == node2->rgb >> dwitdth)
263 //place node2 below node1
264 { *ref = node1; node1->ref = ref; node1->parent = parent; }
266 node1->rs += node2->rs; node1->gs += node2->gs; node1->bs += node2->bs;
267 node1->weight += node2->weight;
268 node1->mi = 0;
269 if (node1->child[i]) node1->nleaf -= node1->child[i]->nleaf;
270 node1->nleaf +=
271 octreeMerge(pool, node1, &node1->child[i], node1->child[i], node2);
272 return node1->nleaf;
274 else if (dwitdth < 0 && node2->rgb == node1->rgb >> (-dwitdth))
276 //place node1 below node2
278 int i = childIndex(node1->rgb >> (-dwitdth - 1));
279 node2->rs += node1->rs; node2->gs += node1->gs; node2->bs += node1->bs;
280 node2->weight += node1->weight;
284 octreeMerge(pool, node2, &node2->child[i], node2->child[i], node1);
292 newnode->rs = node1->rs + node2->rs;
293 newnode->gs = node1->gs + node2->gs;
294 newnode->bs = node1->bs + node2->bs;
295 newnode->weight = node1->weight + node2->weight;
297 if (dwitdth == 0 && node1->rgb == node2->rgb)
300 newnode->width = node1->width; // == node2->width
301 newnode->rgb = node1->rgb; // == node2->rgb
304 if (node1->nchild == 0 && node2->nchild == 0)
308 if (node1->child[i] || node2->child[i])
311 node1->child[i], node2->child[i]);
312 ocnodeFree(pool, node1); ocnodeFree(pool, node2);
317 //use <newnode> as a fork node with children <node1> and <node2>
319 node1->width > node2->width ? node1->width : node2->width;
320 RGB rgb1 = node1->rgb >> (newwidth - node1->width);
328 newnode->nleaf = node1->nleaf + node2->nleaf;
329 int i1 = childIndex(node1->rgb >> (newwidth - node1->width - 1));
331 node1->parent = newnode;
332 node1->ref = &newnode->child[i1];
333 newnode->child[i1] = node1;