[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [22037] branches/blender2.5/blender/source /blender: Move some sketching base code in kernel.

Martin Poirier theeth at yahoo.com
Thu Jul 30 03:39:44 CEST 2009


Revision: 22037
          http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=22037
Author:   theeth
Date:     2009-07-30 03:39:42 +0200 (Thu, 30 Jul 2009)

Log Message:
-----------
Move some sketching base code in kernel.

Other code will eventually move out of armature editor (to help reuse).

This solves the issue reported by Cambo on the ml about kernel code calling editor functions.

Modified Paths:
--------------
    branches/blender2.5/blender/source/blender/blenkernel/intern/armature.c
    branches/blender2.5/blender/source/blender/editors/armature/editarmature_sketch.c
    branches/blender2.5/blender/source/blender/editors/include/ED_armature.h

Added Paths:
-----------
    branches/blender2.5/blender/source/blender/blenkernel/BKE_sketch.h
    branches/blender2.5/blender/source/blender/blenkernel/intern/sketch.c

Added: branches/blender2.5/blender/source/blender/blenkernel/BKE_sketch.h
===================================================================
--- branches/blender2.5/blender/source/blender/blenkernel/BKE_sketch.h	                        (rev 0)
+++ branches/blender2.5/blender/source/blender/blenkernel/BKE_sketch.h	2009-07-30 01:39:42 UTC (rev 22037)
@@ -0,0 +1,157 @@
+/**
+ *	
+ * $Id$ 
+ *
+ * ***** BEGIN GPL LICENSE BLOCK *****
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
+ *
+ * Contributor(s): none yet.
+ *
+ * ***** END GPL LICENSE BLOCK *****
+ */
+#ifndef BKE_SKETCH_H
+#define BKE_SKETCH_H
+
+typedef enum SK_PType
+{
+	PT_CONTINUOUS,
+	PT_EXACT,
+} SK_PType;
+
+typedef enum SK_PMode
+{
+	PT_SNAP,
+	PT_PROJECT,
+} SK_PMode;
+
+typedef struct SK_Point
+{
+	float p[3];
+	short p2d[2];
+	float no[3];
+	float size;
+	SK_PType type;
+	SK_PMode mode;
+} SK_Point;
+
+typedef struct SK_Stroke
+{
+	struct SK_Stroke *next, *prev;
+
+	SK_Point *points;
+	int nb_points;
+	int buf_size;
+	int selected;
+} SK_Stroke;
+
+#define SK_OVERDRAW_LIMIT	5
+
+typedef struct SK_Overdraw
+{
+	SK_Stroke *target;
+	int	start, end;
+	int count;
+} SK_Overdraw;
+
+#define SK_Stroke_BUFFER_INIT_SIZE 20
+
+typedef struct SK_DrawData
+{
+	short mval[2];
+	short previous_mval[2];
+	SK_PType type;
+} SK_DrawData;
+
+typedef struct SK_Intersection
+{
+	struct SK_Intersection *next, *prev;
+	SK_Stroke *stroke;
+	int			before;
+	int			after;
+	int			gesture_index;
+	float		p[3];
+	float		lambda; /* used for sorting intersection points */
+} SK_Intersection;
+
+typedef struct SK_Sketch
+{
+	ListBase	strokes;
+	ListBase	depth_peels;
+	SK_Stroke	*active_stroke;
+	SK_Stroke	*gesture;
+	SK_Point	next_point;
+	SK_Overdraw over;
+} SK_Sketch;
+
+
+typedef struct SK_Gesture {
+	SK_Stroke	*stk;
+	SK_Stroke	*segments;
+
+	ListBase	intersections;
+	ListBase	self_intersections;
+
+	int			nb_self_intersections;
+	int			nb_intersections;
+	int			nb_segments;
+} SK_Gesture;
+
+
+/************************************************/
+
+void freeSketch(SK_Sketch *sketch);
+SK_Sketch* createSketch();
+
+void sk_removeStroke(SK_Sketch *sketch, SK_Stroke *stk);
+
+void sk_freeStroke(SK_Stroke *stk);
+SK_Stroke* sk_createStroke();
+
+SK_Point *sk_lastStrokePoint(SK_Stroke *stk);
+
+void sk_allocStrokeBuffer(SK_Stroke *stk);
+void sk_shrinkStrokeBuffer(SK_Stroke *stk);
+void sk_growStrokeBuffer(SK_Stroke *stk);
+void sk_growStrokeBufferN(SK_Stroke *stk, int n);
+
+void sk_replaceStrokePoint(SK_Stroke *stk, SK_Point *pt, int n);
+void sk_insertStrokePoint(SK_Stroke *stk, SK_Point *pt, int n);
+void sk_appendStrokePoint(SK_Stroke *stk, SK_Point *pt);
+void sk_insertStrokePoints(SK_Stroke *stk, SK_Point *pts, int len, int start, int end);
+
+void sk_trimStroke(SK_Stroke *stk, int start, int end);
+void sk_straightenStroke(SK_Stroke *stk, int start, int end, float p_start[3], float p_end[3]);
+void sk_polygonizeStroke(SK_Stroke *stk, int start, int end);
+void sk_flattenStroke(SK_Stroke *stk, int start, int end);
+void sk_reverseStroke(SK_Stroke *stk);
+
+void sk_filterLastContinuousStroke(SK_Stroke *stk);
+void sk_filterStroke(SK_Stroke *stk, int start, int end);
+
+void sk_initPoint(SK_Point *pt, SK_DrawData *dd, float *no);
+void sk_copyPoint(SK_Point *dst, SK_Point *src);
+
+int sk_stroke_filtermval(SK_DrawData *dd);
+void sk_endContinuousStroke(SK_Stroke *stk);
+
+void sk_updateNextPoint(SK_Sketch *sketch, SK_Stroke *stk);
+
+void sk_initDrawData(SK_DrawData *dd, short mval[2]);
+
+void sk_deleteSelectedStrokes(SK_Sketch *sketch);
+void sk_selectAllSketch(SK_Sketch *sketch, int mode);
+
+#endif


Property changes on: branches/blender2.5/blender/source/blender/blenkernel/BKE_sketch.h
___________________________________________________________________
Name: svn:keywords
   + Author Date Id Revision
Name: svn:eol-style
   + native

Modified: branches/blender2.5/blender/source/blender/blenkernel/intern/armature.c
===================================================================
--- branches/blender2.5/blender/source/blender/blenkernel/intern/armature.c	2009-07-30 00:46:48 UTC (rev 22036)
+++ branches/blender2.5/blender/source/blender/blenkernel/intern/armature.c	2009-07-30 01:39:42 UTC (rev 22037)
@@ -66,9 +66,8 @@
 #include "BKE_object.h"
 #include "BKE_object.h"
 #include "BKE_utildefines.h"
+#include "BKE_sketch.h"
 
-//XXX #include "BIF_editdeform.h"
-
 #include "IK_solver.h"
 
 #ifdef HAVE_CONFIG_H
@@ -144,7 +143,7 @@
 
 		/* free sketch */
 		if (arm->sketch) {
-			ED_freeSketch(arm->sketch);
+			freeSketch(arm->sketch);
 			arm->sketch = NULL;
 		}
 	}

Added: branches/blender2.5/blender/source/blender/blenkernel/intern/sketch.c
===================================================================
--- branches/blender2.5/blender/source/blender/blenkernel/intern/sketch.c	                        (rev 0)
+++ branches/blender2.5/blender/source/blender/blenkernel/intern/sketch.c	2009-07-30 01:39:42 UTC (rev 22037)
@@ -0,0 +1,600 @@
+/**
+ *
+ * $Id$
+ *
+ * ***** BEGIN GPL LICENSE BLOCK *****
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
+ *
+ * Contributor(s): none yet.
+ *
+ * ***** END GPL LICENSE BLOCK *****
+ */
+
+#include <string.h>
+#include <math.h>
+#include <float.h>
+
+#include "MEM_guardedalloc.h"
+
+#include "BLI_blenlib.h"
+#include "BLI_arithb.h"
+
+#include "BKE_sketch.h"
+#include "BKE_utildefines.h"
+
+#include "DNA_userdef_types.h"
+
+void freeSketch(SK_Sketch *sketch)
+{
+	SK_Stroke *stk, *next;
+
+	for (stk = sketch->strokes.first; stk; stk = next)
+	{
+		next = stk->next;
+
+		sk_freeStroke(stk);
+	}
+
+	BLI_freelistN(&sketch->depth_peels);
+
+	MEM_freeN(sketch);
+}
+
+SK_Sketch* createSketch()
+{
+	SK_Sketch *sketch;
+
+	sketch = MEM_callocN(sizeof(SK_Sketch), "SK_Sketch");
+
+	sketch->active_stroke = NULL;
+	sketch->gesture = NULL;
+
+	sketch->strokes.first = NULL;
+	sketch->strokes.last = NULL;
+
+	return sketch;
+}
+
+void sk_initPoint(SK_Point *pt, SK_DrawData *dd, float *no)
+{
+	if (no)
+	{
+		VECCOPY(pt->no, no);
+		Normalize(pt->no);
+	}
+	else
+	{
+		pt->no[0] = 0;
+		pt->no[1] = 0;
+		pt->no[2] = 1;
+	}
+	pt->p2d[0] = dd->mval[0];
+	pt->p2d[1] = dd->mval[1];
+	/* more init code here */
+}
+
+void sk_copyPoint(SK_Point *dst, SK_Point *src)
+{
+	memcpy(dst, src, sizeof(SK_Point));
+}
+
+void sk_allocStrokeBuffer(SK_Stroke *stk)
+{
+	stk->points = MEM_callocN(sizeof(SK_Point) * stk->buf_size, "SK_Point buffer");
+}
+
+void sk_freeStroke(SK_Stroke *stk)
+{
+	MEM_freeN(stk->points);
+	MEM_freeN(stk);
+}
+
+SK_Stroke* sk_createStroke()
+{
+	SK_Stroke *stk;
+
+	stk = MEM_callocN(sizeof(SK_Stroke), "SK_Stroke");
+
+	stk->selected = 0;
+	stk->nb_points = 0;
+	stk->buf_size = SK_Stroke_BUFFER_INIT_SIZE;
+
+	sk_allocStrokeBuffer(stk);
+
+	return stk;
+}
+
+void sk_shrinkStrokeBuffer(SK_Stroke *stk)
+{
+	if (stk->nb_points < stk->buf_size)
+	{
+		SK_Point *old_points = stk->points;
+
+		stk->buf_size = stk->nb_points;
+
+		sk_allocStrokeBuffer(stk);
+
+		memcpy(stk->points, old_points, sizeof(SK_Point) * stk->nb_points);
+
+		MEM_freeN(old_points);
+	}
+}
+
+void sk_growStrokeBuffer(SK_Stroke *stk)
+{
+	if (stk->nb_points == stk->buf_size)
+	{
+		SK_Point *old_points = stk->points;
+
+		stk->buf_size *= 2;
+
+		sk_allocStrokeBuffer(stk);
+
+		memcpy(stk->points, old_points, sizeof(SK_Point) * stk->nb_points);
+
+		MEM_freeN(old_points);
+	}
+}
+
+void sk_growStrokeBufferN(SK_Stroke *stk, int n)
+{
+	if (stk->nb_points + n > stk->buf_size)
+	{
+		SK_Point *old_points = stk->points;
+
+		while (stk->nb_points + n > stk->buf_size)
+		{
+			stk->buf_size *= 2;
+		}
+
+		sk_allocStrokeBuffer(stk);
+
+		memcpy(stk->points, old_points, sizeof(SK_Point) * stk->nb_points);
+
+		MEM_freeN(old_points);
+	}
+}
+
+
+void sk_replaceStrokePoint(SK_Stroke *stk, SK_Point *pt, int n)
+{
+	memcpy(stk->points + n, pt, sizeof(SK_Point));
+}
+
+void sk_insertStrokePoint(SK_Stroke *stk, SK_Point *pt, int n)
+{
+	int size = stk->nb_points - n;
+
+	sk_growStrokeBuffer(stk);
+
+	memmove(stk->points + n + 1, stk->points + n, size * sizeof(SK_Point));
+
+	memcpy(stk->points + n, pt, sizeof(SK_Point));
+
+	stk->nb_points++;
+}
+
+void sk_appendStrokePoint(SK_Stroke *stk, SK_Point *pt)
+{
+	sk_growStrokeBuffer(stk);
+
+	memcpy(stk->points + stk->nb_points, pt, sizeof(SK_Point));
+
+	stk->nb_points++;
+}
+
+void sk_insertStrokePoints(SK_Stroke *stk, SK_Point *pts, int len, int start, int end)
+{
+	int size = end - start + 1;
+
+	sk_growStrokeBufferN(stk, len - size);
+
+	if (len != size)
+	{
+		int tail_size = stk->nb_points - end + 1;
+
+		memmove(stk->points + start + len, stk->points + end + 1, tail_size * sizeof(SK_Point));
+	}
+
+	memcpy(stk->points + start, pts, len * sizeof(SK_Point));
+
+	stk->nb_points += len - size;
+}
+
+void sk_trimStroke(SK_Stroke *stk, int start, int end)
+{
+	int size = end - start + 1;
+
+	if (start > 0)
+	{
+		memmove(stk->points, stk->points + start, size * sizeof(SK_Point));
+	}
+
+	stk->nb_points = size;
+}
+
+void sk_straightenStroke(SK_Stroke *stk, int start, int end, float p_start[3], float p_end[3])
+{
+	SK_Point pt1, pt2;
+	SK_Point *prev, *next;
+	float delta_p[3];
+	int i, total;
+
+	total = end - start;
+
+	VecSubf(delta_p, p_end, p_start);
+
+	prev = stk->points + start;
+	next = stk->points + end;
+
+	VECCOPY(pt1.p, p_start);

@@ Diff output truncated at 10240 characters. @@




More information about the Bf-blender-cvs mailing list