Пример #1
0
static void fcm_generator_verify(FModifier *fcm)
{
  FMod_Generator *data = (FMod_Generator *)fcm->data;

  /* requirements depend on mode */
  switch (data->mode) {
    case FCM_GENERATOR_POLYNOMIAL: /* expanded polynomial expression */
    {
      const int arraysize_new = data->poly_order + 1;
      /* arraysize needs to be order+1, so resize if not */
      if (data->arraysize != arraysize_new) {
        data->coefficients = MEM_recallocN(data->coefficients, sizeof(float) * arraysize_new);
        data->arraysize = arraysize_new;
      }
      break;
    }
    case FCM_GENERATOR_POLYNOMIAL_FACTORISED: /* expanded polynomial expression */
    {
      const int arraysize_new = data->poly_order * 2;
      /* arraysize needs to be (2 * order), so resize if not */
      if (data->arraysize != arraysize_new) {
        data->coefficients = MEM_recallocN(data->coefficients, sizeof(float) * arraysize_new);
        data->arraysize = arraysize_new;
      }
      break;
    }
  }
}
BArrayStore *BLI_array_store_at_size_ensure(
        struct BArrayStore_AtSize *bs_stride,
        const int stride, const int chunk_size)
{
	if (bs_stride->stride_table_len < stride) {
		bs_stride->stride_table_len = stride;
		bs_stride->stride_table = MEM_recallocN(bs_stride->stride_table, sizeof(*bs_stride->stride_table) * stride);
	}
	BArrayStore **bs_p = &bs_stride->stride_table[stride - 1];

	if ((*bs_p) == NULL) {
#if 0
		unsigned int chunk_count = chunk_size;
#else
		/* calculate best chunk-count to fit a power of two */
		unsigned int chunk_count = chunk_size;
		{
			unsigned int size = chunk_count * stride;
			size = power_of_2_max_u(size);
			size = MEM_SIZE_OPTIMAL(size);
			chunk_count = size / stride;
		}
#endif

		(*bs_p) = BLI_array_store_create(stride, chunk_count);
	}
	return *bs_p;
}
Пример #3
0
static int create_primitive_from_points(bContext *C, wmOperator *op, const float (*points)[2],
                                        int num_points, char handle_type)
{
	ScrArea *sa = CTX_wm_area(C);
	Scene *scene = CTX_data_scene(C);
	Mask *mask;
	MaskLayer *mask_layer;
	MaskSpline *new_spline;
	float scale, location[2], frame_size[2];
	int i, width, height;
	int size = RNA_float_get(op->ptr, "size");

	ED_mask_get_size(sa, &width, &height);
	scale = (float)size / max_ii(width, height);

	/* Get location in mask space. */
	frame_size[0] = width;
	frame_size[1] = height;
	RNA_float_get_array(op->ptr, "location", location);
	location[0] /= width;
	location[1] /= height;
	BKE_mask_coord_from_frame(location, location, frame_size);

	/* Make it so new primitive is centered to mouse location. */
	location[0] -= 0.5f * scale;
	location[1] -= 0.5f * scale;

	mask_layer = ED_mask_layer_ensure(C);
	mask = CTX_data_edit_mask(C);

	ED_mask_select_toggle_all(mask, SEL_DESELECT);

	new_spline = BKE_mask_spline_add(mask_layer);
	new_spline->flag = MASK_SPLINE_CYCLIC | SELECT;
	new_spline->tot_point = num_points;
	new_spline->points = MEM_recallocN(new_spline->points,
	                                   sizeof(MaskSplinePoint) * new_spline->tot_point);

	mask_layer->act_spline = new_spline;
	mask_layer->act_point = NULL;

	for (i = 0; i < num_points; i++) {
		MaskSplinePoint *new_point = &new_spline->points[i];

		copy_v2_v2(new_point->bezt.vec[1], points[i]);
		mul_v2_fl(new_point->bezt.vec[1], scale);
		add_v2_v2(new_point->bezt.vec[1], location);

		new_point->bezt.h1 = handle_type;
		new_point->bezt.h2 = handle_type;
		BKE_mask_point_select_set(new_point, true);
	}

	WM_event_add_notifier(C, NC_MASK | NA_EDITED, mask);

	/* TODO: only update this spline */
	BKE_mask_update_display(mask, CFRA);

	return OPERATOR_FINISHED;
}
Пример #4
0
void BLI_ghash_clear(GHash *gh, GHashKeyFreeFP keyfreefp, GHashValFreeFP valfreefp)
{
	unsigned int i;

	if (keyfreefp || valfreefp) {
		for (i = 0; i < gh->nbuckets; i++) {
			Entry *e;

			for (e = gh->buckets[i]; e; ) {
				Entry *n = e->next;

				if (keyfreefp) keyfreefp(e->key);
				if (valfreefp) valfreefp(e->val);

				e = n;
			}
		}
	}

	gh->cursize = 0;
	gh->nentries = 0;
	gh->nbuckets = hashsizes[gh->cursize];

	gh->buckets = MEM_recallocN(gh->buckets, gh->nbuckets * sizeof(*gh->buckets));
}
Пример #5
0
void BKE_paint_toolslots_len_ensure(Paint *paint, int len)
{
  /* Tool slots are 'uchar'. */
  BLI_assert(len <= UCHAR_MAX);
  if (paint->tool_slots_len < len) {
    paint->tool_slots = MEM_recallocN(paint->tool_slots, sizeof(*paint->tool_slots) * len);
    paint->tool_slots_len = len;
  }
}
Пример #6
0
static void rna_GPencil_stroke_point_add(bGPDstroke *stroke, int count)
{
	if (count > 0) {
		if (stroke->points == NULL)
			stroke->points = MEM_callocN(sizeof(bGPDspoint) * count, "gp_stroke_points");
		else
			stroke->points = MEM_recallocN(stroke->points, sizeof(bGPDspoint) * (stroke->totpoints + count));

		stroke->totpoints += count;
	}
}
Пример #7
0
static void rna_MaskSpline_points_add(ID *id, MaskSpline *spline, int count)
{
	Mask *mask = (Mask *) id;
	MaskLayer *layer;
	int active_point_index = -1;
	int i, spline_shape_index;

	if (count <= 0) {
		return;
	}

	for (layer = mask->masklayers.first; layer; layer = layer->next) {
		if (BLI_findindex(&layer->splines, spline) != -1) {
			break;
		}
	}

	if (!layer) {
		/* Shall not happen actually */
		BLI_assert(!"No layer found for the spline");
		return;
	}

	if (layer->act_spline == spline) {
		active_point_index = layer->act_point - spline->points;
	}

	spline->points = MEM_recallocN(spline->points, sizeof(MaskSplinePoint) * (spline->tot_point + count));
	spline->tot_point += count;

	if (active_point_index >= 0) {
		layer->act_point = spline->points + active_point_index;
	}

	spline_shape_index = BKE_mask_layer_shape_spline_to_index(layer, spline);

	for (i = 0; i < count; i++) {
		int point_index = spline->tot_point - count + i;
		MaskSplinePoint *new_point = spline->points + point_index;
		new_point->bezt.h1 = new_point->bezt.h2 = HD_ALIGN;
		BKE_mask_calc_handle_point_auto(spline, new_point, TRUE);
		BKE_mask_parent_init(&new_point->parent);

		/* Not efficient, but there's no other way for now */
		BKE_mask_layer_shape_changed_add(layer, spline_shape_index + point_index, true, true);
	}

	WM_main_add_notifier(NC_MASK | ND_DATA, mask);
	DAG_id_tag_update(&mask->id, 0);
}
Пример #8
0
/* add a shading group to the cache to create later */
GpencilBatchGroup *gpencil_group_cache_add(GpencilBatchGroup *cache_array,
                                           bGPDlayer *gpl,
                                           bGPDframe *gpf,
                                           bGPDstroke *gps,
                                           const short type,
                                           const bool onion,
                                           const int vertex_idx,
                                           int *grp_size,
                                           int *grp_used)
{
  GpencilBatchGroup *cache_elem = NULL;
  GpencilBatchGroup *p = NULL;

  /* By default a cache is created with one block with a predefined number of free slots,
   * if the size is not enough, the cache is reallocated adding a new block of free slots.
   * This is done in order to keep cache small. */
  if (*grp_used + 1 > *grp_size) {
    if ((*grp_size == 0) || (cache_array == NULL)) {
      p = MEM_callocN(sizeof(struct GpencilBatchGroup) * GPENCIL_GROUPS_BLOCK_SIZE,
                      "GpencilBatchGroup");
      *grp_size = GPENCIL_GROUPS_BLOCK_SIZE;
    }
    else {
      *grp_size += GPENCIL_GROUPS_BLOCK_SIZE;
      p = MEM_recallocN(cache_array, sizeof(struct GpencilBatchGroup) * *grp_size);
    }
    cache_array = p;
  }
  /* zero out all data */
  cache_elem = &cache_array[*grp_used];
  memset(cache_elem, 0, sizeof(*cache_elem));

  cache_elem->gpl = gpl;
  cache_elem->gpf = gpf;
  cache_elem->gps = gps;
  cache_elem->type = type;
  cache_elem->onion = onion;
  cache_elem->vertex_idx = vertex_idx;

  /* increase slots used in cache */
  (*grp_used)++;

  return cache_array;
}
Пример #9
0
/* add a gpencil object to cache to defer drawing */
tGPencilObjectCache *gpencil_object_cache_add(tGPencilObjectCache *cache_array,
                                              Object *ob,
                                              int *gp_cache_size,
                                              int *gp_cache_used)
{
  const DRWContextState *draw_ctx = DRW_context_state_get();
  tGPencilObjectCache *cache_elem = NULL;
  RegionView3D *rv3d = draw_ctx->rv3d;
  View3D *v3d = draw_ctx->v3d;
  tGPencilObjectCache *p = NULL;

  /* By default a cache is created with one block with a predefined number of free slots,
   * if the size is not enough, the cache is reallocated adding a new block of free slots.
   * This is done in order to keep cache small. */
  if (*gp_cache_used + 1 > *gp_cache_size) {
    if ((*gp_cache_size == 0) || (cache_array == NULL)) {
      p = MEM_callocN(sizeof(struct tGPencilObjectCache) * GP_CACHE_BLOCK_SIZE,
                      "tGPencilObjectCache");
      *gp_cache_size = GP_CACHE_BLOCK_SIZE;
    }
    else {
      *gp_cache_size += GP_CACHE_BLOCK_SIZE;
      p = MEM_recallocN(cache_array, sizeof(struct tGPencilObjectCache) * *gp_cache_size);
    }
    cache_array = p;
  }
  /* zero out all pointers */
  cache_elem = &cache_array[*gp_cache_used];
  memset(cache_elem, 0, sizeof(*cache_elem));

  cache_elem->ob = ob;
  cache_elem->gpd = (bGPdata *)ob->data;
  cache_elem->name = BKE_id_to_unique_string_key(&ob->id);

  copy_v3_v3(cache_elem->loc, ob->obmat[3]);
  copy_m4_m4(cache_elem->obmat, ob->obmat);
  cache_elem->idx = *gp_cache_used;

  /* object is duplicated (particle) */
  if (ob->base_flag & BASE_FROM_DUPLI) {
    /* Check if the original object is not in the viewlayer
     * and cannot be managed as dupli. This is slower, but required to keep
     * the particle drawing FPS and display instanced objects in scene
     * without the original object */
    bool has_original = gpencil_has_noninstanced_object(ob);
    cache_elem->is_dup_ob = (has_original) ? ob->base_flag & BASE_FROM_DUPLI : false;
  }
  else {
    cache_elem->is_dup_ob = false;
  }

  cache_elem->scale = mat4_to_scale(ob->obmat);

  /* save FXs */
  cache_elem->pixfactor = cache_elem->gpd->pixfactor;
  cache_elem->shader_fx = ob->shader_fx;

  /* save wire mode (object mode is always primary option) */
  if (ob->dt == OB_WIRE) {
    cache_elem->shading_type[0] = (int)OB_WIRE;
  }
  else {
    if (v3d) {
      cache_elem->shading_type[0] = (int)v3d->shading.type;
    }
  }

  /* shgrp array */
  cache_elem->tot_layers = 0;
  int totgpl = BLI_listbase_count(&cache_elem->gpd->layers);
  if (totgpl > 0) {
    cache_elem->shgrp_array = MEM_callocN(sizeof(tGPencilObjectCache_shgrp) * totgpl, __func__);
  }

  /* calculate zdepth from point of view */
  float zdepth = 0.0;
  if (rv3d) {
    if (rv3d->is_persp) {
      zdepth = ED_view3d_calc_zfac(rv3d, ob->obmat[3], NULL);
    }
    else {
      zdepth = -dot_v3v3(rv3d->viewinv[2], ob->obmat[3]);
    }
  }
  else {
    /* In render mode, rv3d is not available, so use the distance to camera.
     * The real distance is not important, but the relative distance to the camera plane
     * in order to sort by z_depth of the objects
     */
    float vn[3] = {0.0f, 0.0f, -1.0f}; /* always face down */
    float plane_cam[4];
    struct Object *camera = draw_ctx->scene->camera;
    if (camera) {
      mul_m4_v3(camera->obmat, vn);
      normalize_v3(vn);
      plane_from_point_normal_v3(plane_cam, camera->loc, vn);
      zdepth = dist_squared_to_plane_v3(ob->obmat[3], plane_cam);
    }
  }
  cache_elem->zdepth = zdepth;
  /* increase slots used in cache */
  (*gp_cache_used)++;

  return cache_array;
}