static VALUE block_pass_fcall(VALUE recv, ID mid, VALUE args, VALUE proc) { #ifdef RUBY_VM /* TODO: need to set filename on node for 1.9 */ /* TODO: would be better to construct an iseq directly */ NODE * node = NEW_FCALL( mid, NEW_NODE( NODE_BLOCK_PASS, NEW_SPLAT( NEW_LIT(args)), NEW_LIT(proc), 0)); #else NODE * node = NEW_NODE( NODE_BLOCK_PASS, 0, NEW_LIT(proc), NEW_FCALL( mid, NEW_SPLAT( NEW_LIT(args)))); #endif return eval_ruby_node(node, recv, Qnil); }
static NODE * new_assign(NODE * lnode, NODE * rhs) { switch (nd_type(lnode)) { case NODE_LASGN:{ return NEW_NODE(NODE_LASGN, lnode->nd_vid, rhs, lnode->nd_cnt); /* NEW_LASGN(lnode->nd_vid, rhs); */ } case NODE_GASGN:{ return NEW_GASGN(lnode->nd_vid, rhs); } case NODE_DASGN:{ return NEW_DASGN(lnode->nd_vid, rhs); } case NODE_ATTRASGN:{ NODE *args = 0; if (lnode->nd_args) { args = NEW_ARRAY(lnode->nd_args->nd_head); args->nd_next = NEW_ARRAY(rhs); args->nd_alen = 2; } else { args = NEW_ARRAY(rhs); } return NEW_ATTRASGN(lnode->nd_recv, lnode->nd_mid, args); } default: rb_bug("unimplemented (block inlining): %s", ruby_node_name(nd_type(lnode))); } return 0; }
SoCallbackAction::Response SoToVRMLActionP::post_primitives_cb(void * closure, SoCallbackAction * COIN_UNUSED_ARG(action), const SoNode * node) { SoToVRMLActionP * thisp = THISP(closure); int n; SoGroup * tail = thisp->get_current_tail(); SoCoordinate3 * coord = new SoCoordinate3; coord->point.setValues(0, thisp->bsptree->numPoints(), thisp->bsptree->getPointsArrayPtr()); tail->addChild(coord); SoIndexedFaceSet * ifs = NEW_NODE(SoIndexedFaceSet, node); SoNormal * normal = new SoNormal; normal->vector.setValues(0, thisp->bsptreenormal->numPoints(), thisp->bsptreenormal->getPointsArrayPtr()); tail->addChild(normal); ifs->coordIndex.setValues(0, thisp->coordidx->getLength(), thisp->coordidx->getArrayPtr()); ifs->normalIndex.setValues(0, thisp->normalidx->getLength(), thisp->normalidx->getArrayPtr()); if (thisp->texidx) { SoTextureCoordinate2 * tex = new SoTextureCoordinate2; ifs->textureCoordIndex.setValues(0, thisp->texidx->getLength(), thisp->texidx->getArrayPtr()); tail->addChild(tex); n = thisp->bsptreetex->numPoints(); tex->point.setNum(n); SbVec2f * ptr = tex->point.startEditing(); for (int i = 0; i < n; i++) { SbVec3f p = thisp->bsptreetex->getPoint(i); ptr[i] = SbVec2f(p[0], p[1]); } tex->point.finishEditing(); } if (thisp->coloridx) { SoMaterialBinding * bind = new SoMaterialBinding; bind->value = SoMaterialBinding::PER_VERTEX_INDEXED; tail->addChild(bind); ifs->materialIndex.setValues(0, thisp->coloridx->getLength(), thisp->coloridx->getArrayPtr()); } tail->addChild(ifs); delete thisp->bsptree; thisp->bsptree = NULL; delete thisp->bsptreetex; thisp->bsptreetex = NULL; delete thisp->bsptreenormal; thisp->bsptreenormal = NULL; delete thisp->coordidx; thisp->coordidx = NULL; delete thisp->normalidx; thisp->normalidx = NULL; delete thisp->texidx; thisp->texidx = NULL; delete thisp->coloridx; thisp->coloridx = NULL; return SoCallbackAction::CONTINUE; }
SoCallbackAction::Response SoToVRMLActionP::vrmlsphere_cb(void * closure, SoCallbackAction * COIN_UNUSED_ARG(action), const SoNode * node) { SoSphere * sphere = NEW_NODE(SoSphere, node); const SoVRMLSphere * oldsphere = coin_assert_cast<const SoVRMLSphere *>(node); sphere->radius = oldsphere->radius.getValue(); THISP(closure)->get_current_tail()->addChild(sphere); return SoCallbackAction::CONTINUE; }
static VALUE ludicrous_splat_iterate_proc_(VALUE val) { struct Ludicrous_Splat_Iterate_Proc_Data * data = (struct Ludicrous_Splat_Iterate_Proc_Data *)val; ID varname = rb_intern("ludicrous_splat_iterate_var"); /* Create a new scope */ NEWOBJ(scope, struct SCOPE); OBJSETUP(scope, 0, T_SCOPE); scope->super = ruby_scope->super; scope->local_tbl = ALLOC_N(ID, 4); scope->local_vars = ALLOC_N(VALUE, 4); scope->flags = SCOPE_MALLOC; /* Set the names of the scope's local variables */ scope->local_tbl[0] = 3; scope->local_tbl[1] = '_'; scope->local_tbl[2] = '~'; scope->local_tbl[3] = varname; /* And and their values */ scope->local_vars[0] = 3; scope->local_vars[1] = Qnil; scope->local_vars[2] = Qnil; scope->local_vars[3] = Qnil; ++scope->local_vars; scope->local_vars[0] = ruby_scope->local_vars[0]; /* $_ */ scope->local_vars[1] = ruby_scope->local_vars[1]; /* $~ */ /* Temporarily set ruby_scope to the new scope, so the proc being * created below will pick it up (it will be set back when this * function returns) */ ruby_scope = scope; /* Create a new proc */ VALUE proc = rb_proc_new( data->body, data->val); NODE * * var; Data_Get_Struct(proc, NODE *, var); /* Set the iterator's assignment node to set a local variable that the * iterator's body can retrieve */ *var = NEW_MASGN( 0, NEW_NODE( NODE_LASGN, varname, 0, 2)); /* And return the proc */ return proc; }
//4/single_size/4 void RBPoolAllctor::expand_free_list(int single_size,void** header,int n /* = g_pool_expand_node_number = 32 */) { CHECK(*header == NULL ); /* p //XXX4/XXXXXXXXXXXXXXXX.../XXXX */ void* p = NEW_NODE(single_size); *header = (void*)p; //*(void**)&p[-4] = p; for(int i = 0;i<n-1;++i) { NEXT_NODE(p) = NEW_NODE(single_size); p = NEXT_NODE(p); } NEXT_NODE(p) = NULL; }
SoCallbackAction::Response SoToVRMLActionP::vrmlswitch_cb(void * closure, SoCallbackAction * COIN_UNUSED_ARG(action), const SoNode * node) { SoSwitch * sw = NEW_NODE(SoSwitch, node); const SoVRMLSwitch * oldsw = coin_assert_cast<const SoVRMLSwitch *>(node); sw->whichChild = oldsw->whichChoice.getValue(); THISP(closure)->get_current_tail()->addChild(sw); THISP(closure)->vrmlpath->append(sw); return SoCallbackAction::CONTINUE; }
SoCallbackAction::Response SoToVRMLActionP::unsupported_cb(void * closure, SoCallbackAction * COIN_UNUSED_ARG(action), const SoNode * node) { SoInfo * info = NEW_NODE(SoInfo, node); SbString str; str.sprintf("Unsupported node: %s", node->getTypeId().getName().getString()); info->string = str; THISP(closure)->get_current_tail()->addChild(info); return SoCallbackAction::CONTINUE; }
SoCallbackAction::Response SoToVRMLActionP::push_cb(void * closure, SoCallbackAction * COIN_UNUSED_ARG(action), const SoNode * node) { SoToVRMLActionP * thisp = THISP(closure); SoSeparator * newsep = NEW_NODE(SoSeparator, node); SoGroup * prevgroup = THISP(closure)->get_current_tail(); prevgroup->addChild(newsep); thisp->vrmlpath->append(newsep); return SoCallbackAction::CONTINUE; }
SoCallbackAction::Response SoToVRMLActionP::vrmlbox_cb(void * closure, SoCallbackAction * COIN_UNUSED_ARG(action), const SoNode * node) { SoCube * cube = NEW_NODE(SoCube, node); const SoVRMLBox * box = coin_assert_cast<const SoVRMLBox *>(node); cube->width = box->size.getValue()[0]; cube->height = box->size.getValue()[1]; cube->depth = box->size.getValue()[2]; THISP(closure)->get_current_tail()->addChild(cube); return SoCallbackAction::CONTINUE; }
SoCallbackAction::Response SoToVRMLActionP::vrmlimagetex_cb(void * closure, SoCallbackAction * COIN_UNUSED_ARG(action), const SoNode * node) { SoTexture2 * tex = NEW_NODE(SoTexture2, node); const SoVRMLImageTexture * oldtex = coin_assert_cast<const SoVRMLImageTexture*>(node); if (oldtex->url.getNum()) { tex->filename = oldtex->url[0]; } THISP(closure)->get_current_tail()->addChild(tex); return SoCallbackAction::CONTINUE; }
SoCallbackAction::Response SoToVRMLActionP::vrmllod_cb(void * closure, SoCallbackAction * COIN_UNUSED_ARG(action), const SoNode * node) { SoLOD * lod = NEW_NODE(SoLOD, node); const SoVRMLLOD * oldlod = coin_assert_cast<const SoVRMLLOD*>(node); lod->center = oldlod->center.getValue(); lod->range.setValues(0, oldlod->range.getNum(), oldlod->range.getValues(0)); THISP(closure)->get_current_tail()->addChild(lod); THISP(closure)->vrmlpath->append(lod); return SoCallbackAction::CONTINUE; }
SoCallbackAction::Response SoToVRMLActionP::vrmlpixeltex_cb(void * closure, SoCallbackAction * COIN_UNUSED_ARG(action), const SoNode * node) { SoTexture2 * tex = NEW_NODE(SoTexture2, node); const SoVRMLPixelTexture * oldtex = coin_assert_cast<const SoVRMLPixelTexture*>(node); SbVec2s size; int nc; const unsigned char * bytes = oldtex->image.getValue(size, nc); tex->image.setValue(size, nc, bytes); THISP(closure)->get_current_tail()->addChild(tex); return SoCallbackAction::CONTINUE; }
/* * call-seq: * proc.push(anotherProc) => self * * Append the body of anotherProc onto proc. */ static VALUE proc_push(VALUE self, VALUE other) { #ifdef RUBY_VM rb_raise(rb_eRuntimeError, "Proc#push not implemented yet for YARV"); #else struct BLOCK * b1; struct BLOCK * b2; Data_Get_Struct(self, struct BLOCK, b1); Data_Get_Struct(other, struct BLOCK, b2); b1->body = NEW_NODE(NODE_BLOCK, b1->body, 0, b2->body); return self; #endif }
static VALUE block_pass_call(VALUE recv, ID mid, VALUE args, VALUE proc) { /* TODO: need to set filename on node for 1.9 */ NODE * node = NEW_NODE( NODE_BLOCK_PASS, 0, NEW_LIT(proc), NEW_CALL( NEW_LIT(recv), mid, NEW_SPLAT( NEW_LIT(args)))); return eval_ruby_node(node, recv, Qnil); }
SoCallbackAction::Response SoToVRMLActionP::vrmltransform_cb(void * closure, SoCallbackAction * action, const SoNode * node) { push_cb(closure, action, node); const SoVRMLTransform * oldt = coin_assert_cast<const SoVRMLTransform *>(node); SoTransform * newt = NEW_NODE(SoTransform, node); newt->translation = oldt->translation.getValue(); newt->rotation = oldt->rotation.getValue(); newt->scaleFactor = oldt->scale.getValue(); newt->scaleOrientation = oldt->scaleOrientation.getValue(); newt->center = oldt->center.getValue(); THISP(closure)->get_current_tail()->addChild(newt); return SoCallbackAction::CONTINUE; }
SoCallbackAction::Response SoToVRMLActionP::vrmlcone_cb(void * closure, SoCallbackAction * COIN_UNUSED_ARG(action), const SoNode * node) { SoCone * cone = NEW_NODE(SoCone, node); const SoVRMLCone * oldcone = coin_assert_cast<const SoVRMLCone *>(node); cone->bottomRadius = oldcone->bottomRadius.getValue(); cone->height = oldcone->height.getValue(); int parts = 0; if (oldcone->bottom.getValue()) parts |= SoCone::BOTTOM; if (oldcone->side.getValue()) parts |= SoCone::SIDES; cone->parts = static_cast<SoCone::Part>(parts); THISP(closure)->get_current_tail()->addChild(cone); return SoCallbackAction::CONTINUE; }
SoCallbackAction::Response SoToVRMLActionP::vrmlcylinder_cb(void * closure, SoCallbackAction * COIN_UNUSED_ARG(action), const SoNode * node) { SoCylinder * cyl = NEW_NODE(SoCylinder, node); const SoVRMLCylinder * oldcyl = coin_assert_cast<const SoVRMLCylinder*>(node); cyl->radius = oldcyl->radius.getValue(); cyl->height = oldcyl->height.getValue(); int parts = 0; if (oldcyl->side.getValue()) parts |= SoCylinder::SIDES; if (oldcyl->top.getValue()) parts |= SoCylinder::TOP; if (oldcyl->bottom.getValue()) parts |= SoCylinder::BOTTOM; cyl->parts = static_cast<SoCylinder::Part>(parts); THISP(closure)->get_current_tail()->addChild(cyl); return SoCallbackAction::CONTINUE; }
SoCallbackAction::Response SoToVRMLActionP::vrmlmaterial_cb(void * closure, SoCallbackAction * COIN_UNUSED_ARG(action), const SoNode * node) { SoMaterial * mat = NEW_NODE(SoMaterial, node); const SoVRMLMaterial * oldmat = coin_assert_cast<const SoVRMLMaterial *>(node); SbColor diffuse = oldmat->diffuseColor.getValue(); mat->diffuseColor = diffuse; diffuse *= oldmat->ambientIntensity.getValue(); mat->ambientColor = diffuse; mat->emissiveColor = oldmat->emissiveColor.getValue(); mat->specularColor = oldmat->specularColor.getValue(); mat->shininess = oldmat->shininess.getValue(); mat->transparency = oldmat->transparency.getValue(); THISP(closure)->get_current_tail()->addChild(mat); return SoCallbackAction::CONTINUE; }
void node_newfile(node_t *dir, const char *fname, size_t s, const char *path, int m) { node_t *f = NEW_NODE(); f->id = node_id++; f->filename = strdup(fname); f->type = MFS_TYPE_REG; f->parent = dir; f->childs = NULL; f->childcnt = 0; f->size = s; f->attr = m; dir->childcnt++; f->next = dir->childs; f->fullpath = (char*)xmalloc(strlen(fname)+2+strlen(path)); sprintf(f->fullpath, "%s/%s", path, fname); dir->childs = f; }
node_t * node_newdir(node_t *p, const char *fname, int m) { node_t *d = NEW_NODE(); d->id = node_id++; d->filename = strdup(fname); d->type = MFS_TYPE_DIR; d->parent = p; d->childs = NULL; d->childcnt = 0; d->size = 0; d->attr = m; if (p == NULL) { d->next = NULL; } else { p->childcnt++; d->next = p->childs; p->childs = d; } return d; }
SoCallbackAction::Response SoToVRMLActionP::vrmlpointset_cb(void * closure, SoCallbackAction * COIN_UNUSED_ARG(action), const SoNode * node) { SoToVRMLActionP * thisp = THISP(closure); const SoVRMLPointSet * oldps = coin_assert_cast<const SoVRMLPointSet*>(node); SoPointSet * ps = NEW_NODE(SoPointSet, node); SoGroup * tail = thisp->get_current_tail(); SoVRMLColor * color = coin_assert_cast<SoVRMLColor*>(oldps->color.getValue()); SoVRMLCoordinate * coord = coin_assert_cast<SoVRMLCoordinate*>(oldps->coord.getValue()); if (coord) { SbName name = coord->getName(); SoCoordinate3 * newcoord = coin_assert_cast<SoCoordinate3 *> ( thisp->search_for_node(thisp->vrmlpath->getHead(), name, SoCoordinate3::getClassTypeId()) ); if (!newcoord) { newcoord = new SoCoordinate3; newcoord->setName(name); newcoord->point.setValues(0, coord->point.getNum(), coord->point.getValues(0)); } tail->addChild(newcoord); } if (color) { SoMaterial * mat = thisp->find_or_create_material(); mat->diffuseColor.setValues(0, color->color.getNum(), color->color.getValues(0)); } tail->addChild(ps); return SoCallbackAction::CONTINUE; }
static int sort(struct pqNode **ps, pTree *node, int M) { int sp=0; pTree *pLeft=NULL, *pRight=NULL; int nBucket = 0; /*======================================================================== * Allocate stack *======================================================================*/ int ns = (int)MMAX(1, floor(log(((double)(NPARTICLES+1))/(M+1))/log(2.0))); sp = 0; sortStack = (pTree **)realloc(sortStack, ns * sizeof(pTree *)); assert(sortStack != NULL); if (node->iUpper - node->iLower + 1 <= M) return 0; while (1) { int i, j; struct pqNode *t; int nl, nr; int d; FLOAT fSplit; assert(node != NULL); split(node, &d, &fSplit); i = node->iLower; j = node->iUpper; partitionCount++; PARTITION(ps, t, ->r[d], i,j, < fSplit,> fSplit); nl = i - node->iLower; nr = node->iUpper - i + 1; //fprintf(err, "nl=%i nr=%i\n", nl, nr); /*======================================================================== * If both sides of the partition are not empty then create two new nodes * and crop the bounding boxes. Otherwise, undo the split operation. *======================================================================*/ if (nl > 0 || nr > 0) { // jpc changed this from && to || so that a split is always created. NEW_NODE(node, pLeft, node->iLower, i - 1); NEW_NODE(node, pRight, i, node->iUpper); nodeCount += 2; #if 0 crop(ps, node->pLeft, node->pLeft->iLower, node->pLeft->iUpper); crop(ps, node->pRight, node->pRight->iLower, node->pRight->iUpper); #else _3x_(i) node->pLeft->bnd.fCenter[i] = node->bnd.fCenter[i]; _3x_(i) node->pLeft->bnd.fMax[i] = node->bnd.fMax[i]; _3x_(i) node->pRight->bnd.fCenter[i] = node->bnd.fCenter[i]; _3x_(i) node->pRight->bnd.fMax[i] = node->bnd.fMax[i]; node->pLeft->bnd.fMax[d] *= 0.5; node->pLeft->bnd.fCenter[d] -= node->pLeft->bnd.fMax[d]; node->pRight->bnd.fMax[d] *= 0.5; node->pRight->bnd.fCenter[d] += node->pRight->bnd.fMax[d]; #endif pLeft = node->pLeft; pRight = node->pRight; } else { node->bnd.fMax[d] *= 0.5; if (nl > 0) { node->bnd.fCenter[d] -= node->bnd.fMax[d]; pLeft = node; } else { node->bnd.fCenter[d] += node->bnd.fMax[d]; pRight = node; } } /*======================================================================== * Now figure out which subfile to process next *======================================================================*/ if (nl > M && nr > M) { if (nr > nl) sortStack[sp++] = pRight, node = pLeft; else sortStack[sp++] = pLeft, node = pRight; } else { if (nl > M) node = pLeft; //else if (nl > 0) pLeft->iLower = 0; if (nr > M) node = pRight; //else if (nr > 0) pRight->iLower = 0; } if (nl <= M && nr <= M) { if (sp) node = sortStack[--sp]; /* pop tn */ else break; } } return 0; }
SoCallbackAction::Response SoToVRMLActionP::vrmlils_cb(void * closure, SoCallbackAction * COIN_UNUSED_ARG(action), const SoNode * node) { SoToVRMLActionP * thisp = THISP(closure); const SoVRMLIndexedLineSet * oldils = coin_assert_cast<const SoVRMLIndexedLineSet*>(node); if (oldils->coordIndex.getNum() == 0 || oldils->coordIndex[0] < 0) return SoCallbackAction::CONTINUE; SoIndexedLineSet * ils = NEW_NODE(SoIndexedLineSet, node); SoVRMLColor * color = coin_assert_cast<SoVRMLColor *>(oldils->color.getValue()); SoVRMLCoordinate * coord = coin_assert_cast<SoVRMLCoordinate *>(oldils->coord.getValue()); SoGroup * tail = thisp->get_current_tail(); SoCoordinate3 * newcoord = NULL; if (coord) { if (thisp->nodefuse) { newcoord = new SoCoordinate3; } else { SbName name = coord->getName(); newcoord = coin_assert_cast<SoCoordinate3*>( thisp->search_for_node(thisp->vrmlpath->getHead(), name, SoCoordinate3::getClassTypeId())); if (!newcoord) { newcoord = new SoCoordinate3; newcoord->setName(name); newcoord->point.setValues(0, coord->point.getNum(), coord->point.getValues(0)); } } tail->addChild(newcoord); } if (color) { SoMaterialBinding * bind = new SoMaterialBinding; if (oldils->colorPerVertex.getValue()) { bind->value = SoMaterialBinding::PER_VERTEX_INDEXED; } else { if (oldils->colorIndex.getNum()) { bind->value = SoMaterialBinding::PER_FACE_INDEXED; } else { bind->value = SoMaterialBinding::PER_FACE; } tail->addChild(bind); } SoMaterial * mat = thisp->find_or_create_material(); mat->diffuseColor.setValues(0, color->color.getNum(), color->color.getValues(0)); } if (thisp->nodefuse && coord) { SbBSPTree bsp; int n = oldils->coordIndex.getNum(); const int32_t * src = oldils->coordIndex.getValues(0); const SbVec3f * c = coord->point.getValues(0); ils->coordIndex.setNum(n); int32_t * dst = ils->coordIndex.startEditing(); for (int i = 0; i < n; i++) { int idx = src[i]; if (idx >= 0) { dst[i] = bsp.addPoint(c[idx]); } else dst[i] = -1; } ils->coordIndex.finishEditing(); newcoord->point.setValues(0, bsp.numPoints(), bsp.getPointsArrayPtr()); } else { ils->coordIndex.setValues(0, oldils->coordIndex.getNum(), oldils->coordIndex.getValues(0)); } if (oldils->colorIndex.getNum()) { ils->materialIndex.setValues(0, oldils->colorIndex.getNum(), oldils->colorIndex.getValues(0)); } tail->addChild(ils); return SoCallbackAction::CONTINUE; }
SoCallbackAction::Response SoToVRMLActionP::vrmlifs_cb(void * closure, SoCallbackAction * COIN_UNUSED_ARG(action), const SoNode * node) { const SoVRMLIndexedFaceSet * oldifs = coin_assert_cast<const SoVRMLIndexedFaceSet *>(node); if (oldifs->coordIndex.getNum() == 0 || oldifs->coordIndex[0] < 0) return SoCallbackAction::CONTINUE; SoToVRMLActionP * thisp = THISP(closure); SoIndexedFaceSet * ifs = NEW_NODE(SoIndexedFaceSet, node); SoVRMLColor * color = coin_assert_cast<SoVRMLColor*>(oldifs->color.getValue()); SoVRMLCoordinate * coord = coin_assert_cast<SoVRMLCoordinate *>(oldifs->coord.getValue()); SoVRMLNormal * normal = coin_assert_cast<SoVRMLNormal *>(oldifs->normal.getValue()); SoVRMLTextureCoordinate * texcoord = coin_assert_cast<SoVRMLTextureCoordinate*>(oldifs->texCoord.getValue()); SoShapeHints * sh = new SoShapeHints; sh->creaseAngle = oldifs->creaseAngle.getValue(); sh->vertexOrdering = oldifs->ccw.getValue() ? SoShapeHints::COUNTERCLOCKWISE : SoShapeHints::CLOCKWISE; sh->shapeType = oldifs->solid.getValue() ? SoShapeHints::SOLID : SoShapeHints::UNKNOWN_SHAPE_TYPE; sh->faceType = oldifs->convex.getValue() ? SoShapeHints::CONVEX : SoShapeHints::UNKNOWN_FACE_TYPE; SoGroup * tail = thisp->get_current_tail(); tail->addChild(sh); if (coord) { SbName name = coord->getName(); SoCoordinate3 * newcoord = coin_assert_cast<SoCoordinate3*>( thisp->search_for_node(thisp->vrmlpath->getHead(), name, SoCoordinate3::getClassTypeId())); if (!newcoord) { newcoord = new SoCoordinate3; newcoord->setName(name); newcoord->point.setValues(0, coord->point.getNum(), coord->point.getValues(0)); } tail->addChild(newcoord); } if (normal) { if (oldifs->normalPerVertex.getValue() != TRUE) { SoNormalBinding * bind = new SoNormalBinding; if (oldifs->normalIndex.getNum()) { bind->value = SoMaterialBinding::PER_FACE_INDEXED; } else bind->value = SoMaterialBinding::PER_FACE; tail->addChild(bind); } SbName name = normal->getName(); SoNormal * newnormal = coin_assert_cast<SoNormal*>(thisp->search_for_node(thisp->vrmlpath->getHead(), name, SoNormal::getClassTypeId()) ); if (!newnormal) { newnormal = new SoNormal; newnormal->setName(name); newnormal->vector.setValues(0, normal->vector.getNum(), normal->vector.getValues(0)); } tail->addChild(newnormal); } if (color) { SoMaterialBinding * bind = new SoMaterialBinding; if (oldifs->colorPerVertex.getValue()) { bind->value = SoMaterialBinding::PER_VERTEX_INDEXED; } else { if (oldifs->colorIndex.getNum()) { bind->value = SoMaterialBinding::PER_FACE_INDEXED; } else { bind->value = SoMaterialBinding::PER_FACE; } tail->addChild(bind); } SoMaterial * mat = thisp->find_or_create_material(); mat->diffuseColor.setValues(0, color->color.getNum(), color->color.getValues(0)); } if (texcoord) { SbName name = texcoord->getName(); SoTextureCoordinate2 * newtc = coin_assert_cast<SoTextureCoordinate2*>( thisp->search_for_node(thisp->vrmlpath->getHead(), name, SoTextureCoordinate2::getClassTypeId()) ); if (!newtc) { newtc = new SoTextureCoordinate2; newtc->setName(name); newtc->point.setValues(0, texcoord->point.getNum(), texcoord->point.getValues(0)); } tail->addChild(newtc); } ifs->coordIndex.setValues(0, oldifs->coordIndex.getNum(), oldifs->coordIndex.getValues(0)); if (oldifs->texCoordIndex.getNum()) { ifs->textureCoordIndex.setValues(0, oldifs->texCoordIndex.getNum(), oldifs->texCoordIndex.getValues(0)); } if (oldifs->colorIndex.getNum()) { ifs->materialIndex.setValues(0, oldifs->colorIndex.getNum(), oldifs->colorIndex.getValues(0)); } if (oldifs->normalIndex.getNum()) { ifs->normalIndex.setValues(0, oldifs->normalIndex.getNum(), oldifs->normalIndex.getValues(0)); } tail->addChild(ifs); return SoCallbackAction::CONTINUE; }
static int sort(struct env *env, int M) { int sp=0; struct tree *left=NULL, *right=NULL; int nBucket = 0; struct particle **ps = env->p; struct tree *node = env->tree; /*======================================================================== * Allocate stack *======================================================================*/ int ns = (int)MMAX(1, floor(log(((double)(env->N+1))/(M+1))/log(2.0))); sp = 0; sortStack = (struct tree **)realloc(sortStack, ns * sizeof(struct tree *)); assert(sortStack != NULL); if (node->iUpper - node->iLower + 1 <= M) return 0; while (1) { int i, p, k; struct particle *t; int nl, nr; int d; real fSplit; assert(node != NULL); split(node, &d, &fSplit); #if 0 i = node->iLower; int j = node->iUpper; //partitionCount++; //PARTITION(ps, t, ->r[d], i,j, < fSplit,> fSplit); while (i <= j && ((ps[i] ->r[d]) < fSplit)) { ++i; } #if 0 while (i <= j) { switch ((i-j) & 0x7) case 7: if } #endif while (i <= j && ((ps[j] ->r[d]) > fSplit)) { --j; } while (i < j) { SWAP(ps[i], ps[j], t); while ((ps[++i] ->r[d]) < fSplit) { } while ((ps[--j] ->r[d]) > fSplit) { } } #else # define PART(A, i, j, t, d, CMPL) \ do { \ int k = i--; \ do { \ if (A[k]->r[d] CMPL) { i++; SWAP(A[i], A[k], t); } \ } while (++k <= j); \ i++; \ } while(0) i = node->iLower; const int j = node->iUpper; switch (d) { case 0: PART(ps, i, j, t, 0, < fSplit); break; case 1: PART(ps, i, j, t, 1, < fSplit); break; case 2: PART(ps, i, j, t, 2, < fSplit); break; } #endif //fprintf(err, "(%i %i)\n", i, node->iUpper); nl = i - node->iLower; nr = node->iUpper - i + 1; //fprintf(err, "nl=%i nr=%i\n", nl, nr); /*======================================================================== * If both sides of the partition are not empty then create two new nodes * and crop the bounding boxes. Otherwise, undo the split operation. *======================================================================*/ if (nl > 0 || nr > 0) { // jpc changed this from && to || so that a split is always created. NEW_NODE(node, left, node->iLower, i - 1); NEW_NODE(node, right, i, node->iUpper); nodeCount += 2; X3( node->left->bnd.r [_] = node->bnd.r [_] ); X3( node->left->bnd.max [_] = node->bnd.max [_] ); node->left->bnd.max[d] *= 0.5; node->left->bnd.r[d] -= node->left->bnd.max[d]; left = node->left; X3( node->right->bnd.r [_] = node->bnd.r [_] ); X3( node->right->bnd.max [_] = node->bnd.max [_] ); node->right->bnd.max[d] *= 0.5; node->right->bnd.r[d] += node->right->bnd.max[d]; right = node->right; } else { node->bnd.max[d] *= 0.5; if (nl > 0) { node->bnd.r[d] -= node->bnd.max[d]; left = node; } else { node->bnd.r[d] += node->bnd.max[d]; right = node; } } /*======================================================================== * Now figure out which subfile to process next *======================================================================*/ if (nl > M && nr > M) { if (nr > nl) sortStack[sp++] = right, node = left; else sortStack[sp++] = left, node = right; } else { if (nl > M) node = left; //else if (nl > 0) left->iLower = 0; if (nr > M) node = right; //else if (nr > 0) right->iLower = 0; } if (nl <= M && nr <= M) { if (sp) node = sortStack[--sp]; /* pop tn */ else break; } } return 0; }
static void dump_tree_hierarchy_to_file_4_6 (char *fname) { gdl_graph *graph; gdl_node *node; graph = vcg_plugin_common.top_graph; gdl_set_graph_orientation (graph, "left_to_right"); #define NEW_NODE(name) \ node = gdl_new_graph_node (graph, name); \ gdl_set_node_label (node, name); NEW_NODE ("tree_base") NEW_NODE ("tree_common") NEW_NODE ("tree_int_cst") NEW_NODE ("tree_real_cst") NEW_NODE ("tree_fixed_cst") NEW_NODE ("tree_vector") NEW_NODE ("tree_string") NEW_NODE ("tree_complex") NEW_NODE ("tree_identifier") NEW_NODE ("tree_decl_minimal") NEW_NODE ("tree_decl_common") NEW_NODE ("tree_decl_with_rtl") NEW_NODE ("tree_decl_non_common") NEW_NODE ("tree_parm_decl") NEW_NODE ("tree_decl_with_vis") NEW_NODE ("tree_var_decl") NEW_NODE ("tree_field_decl") NEW_NODE ("tree_label_decl") NEW_NODE ("tree_result_decl") NEW_NODE ("tree_const_decl") NEW_NODE ("tree_type_decl") NEW_NODE ("tree_function_decl") NEW_NODE ("tree_translation_unit_decl") NEW_NODE ("tree_type") NEW_NODE ("tree_list") NEW_NODE ("tree_vec") NEW_NODE ("tree_exp") NEW_NODE ("tree_ssa_name") NEW_NODE ("tree_block") NEW_NODE ("tree_binfo") NEW_NODE ("tree_statement_list") NEW_NODE ("tree_constructor") NEW_NODE ("tree_omp_clause") NEW_NODE ("tree_optimization_option") NEW_NODE ("tree_target_option") #define NEW_EDGE(src, dest) \ gdl_new_graph_edge (graph, src, dest); NEW_EDGE ("tree_base", "tree_common") NEW_EDGE ("tree_common", "tree_int_cst") NEW_EDGE ("tree_common", "tree_real_cst") NEW_EDGE ("tree_common", "tree_fixed_cst") NEW_EDGE ("tree_common", "tree_string") NEW_EDGE ("tree_common", "tree_complex") NEW_EDGE ("tree_common", "tree_vector") NEW_EDGE ("tree_common", "tree_identifier") NEW_EDGE ("tree_common", "tree_list") NEW_EDGE ("tree_common", "tree_vec") NEW_EDGE ("tree_common", "tree_constructor") NEW_EDGE ("tree_common", "tree_exp") NEW_EDGE ("tree_common", "tree_ssa_name") NEW_EDGE ("tree_common", "tree_omp_clause") NEW_EDGE ("tree_common", "tree_block") NEW_EDGE ("tree_common", "tree_type") NEW_EDGE ("tree_common", "tree_binfo") NEW_EDGE ("tree_common", "tree_decl_minimal") NEW_EDGE ("tree_decl_minimal", "tree_decl_common") NEW_EDGE ("tree_decl_common", "tree_decl_with_rtl") NEW_EDGE ("tree_decl_common", "tree_field_decl") NEW_EDGE ("tree_decl_with_rtl", "tree_label_decl") NEW_EDGE ("tree_decl_with_rtl", "tree_result_decl") NEW_EDGE ("tree_decl_with_rtl", "tree_const_decl") NEW_EDGE ("tree_decl_with_rtl", "tree_parm_decl") NEW_EDGE ("tree_decl_with_rtl", "tree_decl_with_vis") NEW_EDGE ("tree_decl_with_vis", "tree_var_decl") NEW_EDGE ("tree_decl_with_vis", "tree_decl_non_common") NEW_EDGE ("tree_decl_non_common", "tree_function_decl") NEW_EDGE ("tree_decl_common", "tree_translation_unit_decl") NEW_EDGE ("tree_decl_non_common", "tree_type_decl") NEW_EDGE ("tree_common", "tree_statement_list") NEW_EDGE ("tree_common", "tree_optimization_option") NEW_EDGE ("tree_common", "tree_target_option") vcg_plugin_common.dump (fname); }