/* presumed to be called when no threads are running */ void IMB_tile_cache_params(int totthread, int maxmem) { int a; /* always one cache for non-threaded access */ totthread++; /* lazy initialize cache */ if(GLOBAL_CACHE.totthread == totthread && GLOBAL_CACHE.maxmem == maxmem) return; imb_tile_cache_exit(); memset(&GLOBAL_CACHE, 0, sizeof(ImGlobalTileCache)); GLOBAL_CACHE.tilehash= BLI_ghash_new(imb_global_tile_hash, imb_global_tile_cmp, "tile_cache_params gh"); GLOBAL_CACHE.memarena= BLI_memarena_new(BLI_MEMARENA_STD_BUFSIZE, "ImTileCache arena"); BLI_memarena_use_calloc(GLOBAL_CACHE.memarena); GLOBAL_CACHE.maxmem= maxmem*1024*1024; GLOBAL_CACHE.totthread= totthread; for(a=0; a<totthread; a++) imb_thread_cache_init(&GLOBAL_CACHE.thread_cache[a]); BLI_mutex_init(&GLOBAL_CACHE.mutex); }
BME_TransData_Head *BME_init_transdata(int bufsize) { BME_TransData_Head *td; td = MEM_callocN(sizeof(BME_TransData_Head), "BMesh transdata header"); td->gh = BLI_ghash_new(BLI_ghashutil_ptrhash,BLI_ghashutil_ptrcmp, "BME_init_transdata gh"); td->ma = BLI_memarena_new(bufsize, "BME_TransData arena"); BLI_memarena_use_calloc(td->ma); return td; }
static void push_propagate_stack(SmoothEdge *edge, SmoothVert *vert, SmoothMesh *mesh) { PropagateEdge *pedge = mesh->reusestack.first; if(pedge) { BLI_remlink(&mesh->reusestack, pedge); } else { if(!mesh->arena) { mesh->arena = BLI_memarena_new(BLI_MEMARENA_STD_BUFSIZE, "edgesplit arena"); BLI_memarena_use_calloc(mesh->arena); } pedge = BLI_memarena_alloc(mesh->arena, sizeof(PropagateEdge)); } pedge->edge = edge; pedge->vert = vert; BLI_addhead(&mesh->propagatestack, pedge); }
void scatter_tree_build(ScatterTree *tree) { ScatterPoint *newpoints, **tmppoints; float mid[3], size[3]; int totpoint= tree->totpoint; newpoints = MEM_callocN(sizeof(ScatterPoint) * totpoint, "ScatterPoints"); tmppoints = MEM_callocN(sizeof(ScatterPoint *) * totpoint, "ScatterTmpPoints"); tree->tmppoints= tmppoints; tree->arena= BLI_memarena_new(0x8000 * sizeof(ScatterNode), "sss tree arena"); BLI_memarena_use_calloc(tree->arena); /* build tree */ tree->root= BLI_memarena_alloc(tree->arena, sizeof(ScatterNode)); tree->root->points= newpoints; tree->root->totpoint= totpoint; mid[0]= (tree->min[0]+tree->max[0])*0.5f; mid[1]= (tree->min[1]+tree->max[1])*0.5f; mid[2]= (tree->min[2]+tree->max[2])*0.5f; size[0]= (tree->max[0]-tree->min[0])*0.5f; size[1]= (tree->max[1]-tree->min[1])*0.5f; size[2]= (tree->max[2]-tree->min[2])*0.5f; create_octree_node(tree, tree->root, mid, size, tree->refpoints, 0); MEM_freeN(tree->points); MEM_freeN(tree->refpoints); MEM_freeN(tree->tmppoints); tree->refpoints= NULL; tree->tmppoints= NULL; tree->points= newpoints; /* sum radiance at nodes */ sum_radiance(tree, tree->root); }
static void harmonic_coordinates_bind(Scene *UNUSED(scene), MeshDeformModifierData *mmd, MeshDeformBind *mdb) { MDefBindInfluence *inf; MDefInfluence *mdinf; MDefCell *cell; float center[3], vec[3], maxwidth, totweight; int a, b, x, y, z, totinside, offset; /* compute bounding box of the cage mesh */ INIT_MINMAX(mdb->min, mdb->max); for (a = 0; a < mdb->totcagevert; a++) minmax_v3v3_v3(mdb->min, mdb->max, mdb->cagecos[a]); /* allocate memory */ mdb->size = (2 << (mmd->gridsize - 1)) + 2; mdb->size3 = mdb->size * mdb->size * mdb->size; mdb->tag = MEM_callocN(sizeof(int) * mdb->size3, "MeshDeformBindTag"); mdb->phi = MEM_callocN(sizeof(float) * mdb->size3, "MeshDeformBindPhi"); mdb->totalphi = MEM_callocN(sizeof(float) * mdb->size3, "MeshDeformBindTotalPhi"); mdb->boundisect = MEM_callocN(sizeof(*mdb->boundisect) * mdb->size3, "MDefBoundIsect"); mdb->semibound = MEM_callocN(sizeof(int) * mdb->size3, "MDefSemiBound"); mdb->bvhtree = bvhtree_from_mesh_looptri(&mdb->bvhdata, mdb->cagedm, FLT_EPSILON * 100, 4, 6); mdb->inside = MEM_callocN(sizeof(int) * mdb->totvert, "MDefInside"); if (mmd->flag & MOD_MDEF_DYNAMIC_BIND) mdb->dyngrid = MEM_callocN(sizeof(MDefBindInfluence *) * mdb->size3, "MDefDynGrid"); else mdb->weights = MEM_callocN(sizeof(float) * mdb->totvert * mdb->totcagevert, "MDefWeights"); mdb->memarena = BLI_memarena_new(BLI_MEMARENA_STD_BUFSIZE, "harmonic coords arena"); BLI_memarena_use_calloc(mdb->memarena); /* initialize data from 'cagedm' for reuse */ { DerivedMesh *dm = mdb->cagedm; mdb->cagedm_cache.mpoly = dm->getPolyArray(dm); mdb->cagedm_cache.mloop = dm->getLoopArray(dm); mdb->cagedm_cache.looptri = dm->getLoopTriArray(dm); mdb->cagedm_cache.poly_nors = dm->getPolyDataArray(dm, CD_NORMAL); /* can be NULL */ } /* make bounding box equal size in all directions, add padding, and compute * width of the cells */ maxwidth = -1.0f; for (a = 0; a < 3; a++) if (mdb->max[a] - mdb->min[a] > maxwidth) maxwidth = mdb->max[a] - mdb->min[a]; for (a = 0; a < 3; a++) { center[a] = (mdb->min[a] + mdb->max[a]) * 0.5f; mdb->min[a] = center[a] - maxwidth * 0.5f; mdb->max[a] = center[a] + maxwidth * 0.5f; mdb->width[a] = (mdb->max[a] - mdb->min[a]) / (mdb->size - 4); mdb->min[a] -= 2.1f * mdb->width[a]; mdb->max[a] += 2.1f * mdb->width[a]; mdb->width[a] = (mdb->max[a] - mdb->min[a]) / mdb->size; mdb->halfwidth[a] = mdb->width[a] * 0.5f; } progress_bar(0, "Setting up mesh deform system"); totinside = 0; for (a = 0; a < mdb->totvert; a++) { copy_v3_v3(vec, mdb->vertexcos[a]); mdb->inside[a] = meshdeform_inside_cage(mdb, vec); if (mdb->inside[a]) totinside++; } /* free temporary MDefBoundIsects */ BLI_memarena_free(mdb->memarena); mdb->memarena = BLI_memarena_new(BLI_MEMARENA_STD_BUFSIZE, "harmonic coords arena"); /* start with all cells untyped */ for (a = 0; a < mdb->size3; a++) mdb->tag[a] = MESHDEFORM_TAG_UNTYPED; /* detect intersections and tag boundary cells */ for (z = 0; z < mdb->size; z++) for (y = 0; y < mdb->size; y++) for (x = 0; x < mdb->size; x++) meshdeform_add_intersections(mdb, x, y, z); /* compute exterior and interior tags */ meshdeform_bind_floodfill(mdb); for (z = 0; z < mdb->size; z++) for (y = 0; y < mdb->size; y++) for (x = 0; x < mdb->size; x++) meshdeform_check_semibound(mdb, x, y, z); /* solve */ meshdeform_matrix_solve(mmd, mdb); /* assign results */ if (mmd->flag & MOD_MDEF_DYNAMIC_BIND) { mmd->totinfluence = 0; for (a = 0; a < mdb->size3; a++) for (inf = mdb->dyngrid[a]; inf; inf = inf->next) mmd->totinfluence++; /* convert MDefBindInfluences to smaller MDefInfluences */ mmd->dyngrid = MEM_callocN(sizeof(MDefCell) * mdb->size3, "MDefDynGrid"); mmd->dyninfluences = MEM_callocN(sizeof(MDefInfluence) * mmd->totinfluence, "MDefInfluence"); offset = 0; for (a = 0; a < mdb->size3; a++) { cell = &mmd->dyngrid[a]; cell->offset = offset; totweight = 0.0f; mdinf = mmd->dyninfluences + cell->offset; for (inf = mdb->dyngrid[a]; inf; inf = inf->next, mdinf++) { mdinf->weight = inf->weight; mdinf->vertex = inf->vertex; totweight += mdinf->weight; cell->totinfluence++; } if (totweight > 0.0f) { mdinf = mmd->dyninfluences + cell->offset; for (b = 0; b < cell->totinfluence; b++, mdinf++) mdinf->weight /= totweight; } offset += cell->totinfluence; } mmd->dynverts = mdb->inside; mmd->dyngridsize = mdb->size; copy_v3_v3(mmd->dyncellmin, mdb->min); mmd->dyncellwidth = mdb->width[0]; MEM_freeN(mdb->dyngrid); } else { mmd->bindweights = mdb->weights; MEM_freeN(mdb->inside); } MEM_freeN(mdb->tag); MEM_freeN(mdb->phi); MEM_freeN(mdb->totalphi); MEM_freeN(mdb->boundisect); MEM_freeN(mdb->semibound); BLI_memarena_free(mdb->memarena); free_bvhtree_from_mesh(&mdb->bvhdata); }