[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [19043] branches/nurbs/blender: New Split tool by Laurynas Duburas
Emmanuel Stone
emmanuel.stone at gmail.com
Thu Feb 19 19:53:44 CET 2009
Revision: 19043
http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=19043
Author: eman
Date: 2009-02-19 19:53:43 +0100 (Thu, 19 Feb 2009)
Log Message:
-----------
New Split tool by Laurynas Duburas
Specials Menu (w) -> Split
Also:
Smart knot vector editing in extrude functions (actually currently overwritten by NRB_SizeChanged in cases other than knottype == 9)
Modified Paths:
--------------
branches/nurbs/blender/intern/nurbana/extern/nurbana.h
branches/nurbs/blender/intern/nurbana/intern/NURBS_Degree.cpp
branches/nurbs/blender/intern/nurbana/intern/NURBS_Knot.cpp
branches/nurbs/blender/intern/nurbana/intern/NURBS_Knot.h
branches/nurbs/blender/intern/nurbana/intern/NURBS_Utils.h
branches/nurbs/blender/intern/nurbana/intern/Object_NURBS.cpp
branches/nurbs/blender/intern/nurbana/intern/Object_NURBS.h
branches/nurbs/blender/intern/nurbana/intern/Object_Primitives.cpp
branches/nurbs/blender/intern/nurbana/intern/libNurbana.cpp
branches/nurbs/blender/source/blender/include/butspace.h
branches/nurbs/blender/source/blender/src/editcurve.c
branches/nurbs/blender/source/blender/src/editobject.c
branches/nurbs/blender/source/blender/src/header_view3d.c
Modified: branches/nurbs/blender/intern/nurbana/extern/nurbana.h
===================================================================
--- branches/nurbs/blender/intern/nurbana/extern/nurbana.h 2009-02-19 17:13:04 UTC (rev 19042)
+++ branches/nurbs/blender/intern/nurbana/extern/nurbana.h 2009-02-19 18:53:43 UTC (rev 19043)
@@ -114,6 +114,7 @@
extern void NRB_setLength(int U, int V, int shiftU, int shiftV, int copyKnots, NurbanaObj_ptr nurb);
extern void NRB_reallocKnots(int U, int V, int copy, NurbanaObj_ptr nurb);
+extern void NRB_copyPatchFromBuffer(nbReal4 *buffer, int curveLength, int nextCurve, int curveCount, NurbanaObj_ptr nurb, int uOffset, int vOffset);
extern void NRB_reallocCtlPts(int U, int V, int shiftU, int shiftV, NurbanaObj_ptr nurb);
extern void NRB_ConvertToPrimitive(NurbanaObj_ptr nop,unsigned char type);
@@ -151,6 +152,9 @@
extern void NRB_Refine(NurbanaObj_ptr nop, int U, int V);
extern void NRB_KnotInsert(NurbanaObj_ptr nop,nbReal *X, int r, int UV);
+extern void NRB_split(NurbanaObj_ptr nop, nbReal x, int uv, nbReal4* dst, int dstLen, int* frstLen, int* scndLen, int* k, int* newPoints, int* inserted);
+extern void NRB_splitBuffer(nbReal4* buffer, int newPoints, NurbanaObj_ptr nop, NurbanaObj_ptr nop2, nbReal splitKnot, int newLength, int span, int uv, int frstLen, int scndLen);
+
extern void NRB_DegreeElevate(NurbanaObj_ptr nop,int Uinc, int Vinc);
extern void NRB_DegreeReduce(NurbanaObj_ptr nop,int Udec, int Vdec);
Modified: branches/nurbs/blender/intern/nurbana/intern/NURBS_Degree.cpp
===================================================================
--- branches/nurbs/blender/intern/nurbana/intern/NURBS_Degree.cpp 2009-02-19 17:13:04 UTC (rev 19042)
+++ branches/nurbs/blender/intern/nurbana/intern/NURBS_Degree.cpp 2009-02-19 18:53:43 UTC (rev 19043)
@@ -138,7 +138,7 @@
if (frstInsNum) {
if (cyclic) {
memcpy(pts - degree, pts - degree + curveLength, sizeof(*pts) * degree);
- NURBS_Knot::insertCurveKnot(pts, curveLength + lastInsNum, 1, pts, 1, unwrappedKnots + degree, degree, frstInsKnot, frstInsIndex, degree - frstInsNum, frstInsNum);
+ insertCurveKnot(pts, curveLength + lastInsNum, 1, pts, 1, unwrappedKnots + degree, degree, frstInsKnot, frstInsIndex, degree - frstInsNum, frstInsNum);
curveLength += frstInsNum;
memcpy(pts - degree + curveLength, pts - degree, sizeof(*pts) * degree);
pts += frstInsIndex - (degree - frstInsNum);
Modified: branches/nurbs/blender/intern/nurbana/intern/NURBS_Knot.cpp
===================================================================
--- branches/nurbs/blender/intern/nurbana/intern/NURBS_Knot.cpp 2009-02-19 17:13:04 UTC (rev 19042)
+++ branches/nurbs/blender/intern/nurbana/intern/NURBS_Knot.cpp 2009-02-19 18:53:43 UTC (rev 19043)
@@ -135,6 +135,15 @@
return count;
}
+void NURBS_Knot::getSpanAndMult(nbReal u, int degree, int curveLength, bool cyclic, const nbReal *knots, int& k, int& mult) {
+ mult = 0;
+ for (int i = 0; i <= curveLength + degree + 1; i++) {
+ if (knots[i] == u)
+ mult++;
+ }
+ k = NURBS_Knot::FindSpanRef(u, degree, curveLength + 1 + (cyclic ? degree: 0), knots);
+}
+
int NURBS_Knot::FindSpan(int Unpts, int p, nbReal u, nbReal *KnotVector) {
int low,mid,high;
@@ -244,16 +253,19 @@
const int degree = order - 1;
const int last = cyclic ? oldKnotCount - 1 : oldKnotCount - degree - 1;
if(obj->Cyclic(UV))
- return obj -> KnotVector(UV)[(obj->Length(UV) - 1)]; // don't need a different number for cyclic because of virtual CP
+ return obj -> KnotVector(UV)[(obj->Length(UV) + order - 1)]; // don't need a different number for cyclic because of virtual CP
else
- return obj -> KnotVector(UV)[(obj->Length(UV) + obj->Order(UV))-1];
+ return obj -> KnotVector(UV)[obj->Length(UV)];
// printf("Last knot value: %.4f\n",obj -> KnotVector(UV)[last]);
// return obj -> KnotVector(UV)[last];
}
nbReal NURBS_Knot::getFirstKnotValue(Object_NURBS *obj, bool UV) {
- return obj -> KnotVector(UV)[0];
+// if (obj -> Cyclic(UV))
+// return obj -> KnotVector(UV)[0];
+// else
+ return obj -> KnotVector(UV)[obj -> Order(UV) - 1];
}
void NURBS_Knot::refine(int order, int curveLength, int curveCount, bool cyclic, const Point3d* inCps, int nextCurveIn, Point3d* outCps, int nextCurveOut, int nextCp, const nbReal* inKnotVect, nbReal* outKnotVect, nbReal* X, int r, bool cpsIn4D) {
@@ -862,37 +874,12 @@
*outCp = *inCp;
}
-void NURBS_Knot::insertCurveKnot(nbReal4* inCps, int cpCount, int nextInCp, nbReal4* outCps, int nextOutCp, nbReal* knots, int degree, nbReal u, int k, int mult, int num) {
- nbReal4 Rw[MAX_ORDER];
- if (inCps != outCps) {
- //FIXME: copy leading control points
- }
-
-// for (int i = cpCount - 1; i >= k - mult; i--) {
-// cps [i + num][0] = cps [i][0];
-// cps [i + num][1] = cps [i][1];
-// }
-
- copyBackCurve(inCps + (cpCount - 1) * nextInCp, nextInCp, outCps + (cpCount - 1 + num) * nextOutCp, nextOutCp, cpCount - k + mult);
- copyCurve(inCps + (k - degree) * nextInCp, nextInCp, Rw, 1, degree + 1 - mult);
-
- int l = 0;
- for (int j = 1; j <= num; j++) {
- l = k - degree + j;
- for (int i = 0; i <= degree - j - mult; i++) {
- float alpha = (u - knots[l + i]) / (knots[i + k + 1] - knots[l + i]);
- Rw[i].x = alpha * Rw[i + 1].x + (1.0f - alpha) * Rw[i].x;
- Rw[i].y = alpha * Rw[i + 1].y + (1.0f - alpha) * Rw[i].y;
- Rw[i].z = alpha * Rw[i + 1].z + (1.0f - alpha) * Rw[i].z;
- Rw[i].a = alpha * Rw[i + 1].a + (1.0f - alpha) * Rw[i].a;
- }
- *(outCps + l * nextOutCp) = Rw[0];
- *(outCps + (k + num - j - mult) * nextOutCp) = Rw[degree - j - mult];
- }
- copyCurve(Rw + 1, 1, outCps + (l + 1) * nextOutCp, nextOutCp, k - num - l - 1);
-}
-
void NURBS_Knot::insertKnot(const nbReal* inKnots, nbReal* outKnots, nbReal u, int k, int num, int cpCount, int order, bool cyclic) {
+ const int degree = order - 1;
+ if (cyclic && k >= cpCount) {
+ k -= cpCount;
+ u -= inKnots[cpCount];
+ }
if (inKnots != outKnots)
memcpy(outKnots, inKnots, sizeof(*inKnots) * (k + 1));
int tail = (cyclic ? cpCount - k : cpCount + order - k - 1);
Modified: branches/nurbs/blender/intern/nurbana/intern/NURBS_Knot.h
===================================================================
--- branches/nurbs/blender/intern/nurbana/intern/NURBS_Knot.h 2009-02-19 17:13:04 UTC (rev 19042)
+++ branches/nurbs/blender/intern/nurbana/intern/NURBS_Knot.h 2009-02-19 18:53:43 UTC (rev 19043)
@@ -22,8 +22,6 @@
#include "NGlobal.h"
#endif
-#define MAX_ORDER 6
-
class Object_NURBS;
class NURBS_Knot {
public:
@@ -37,10 +35,11 @@
static int getKnotMultiplicity(const nbReal knotVect[], int index, int cpCount, int order, bool cyclic);
static int getFwdKnotMultiplicity(const nbReal knotVect[], int index, int cpCount, int order, bool cyclic);
-
+ static void getSpanAndMult(nbReal u, int degree, int curveLength, bool cyclic, const nbReal *knots, int& k, int& mult);
+
static void Difference(nbReal *KV1, int L1, nbReal *KV2, int L2, nbReal *KV3, int &L3);
static int FindSpan(int Unpts, int p, nbReal u, nbReal *KnotVector);
- static int FindSpanRef(nbReal &u, int first, int last, const nbReal *KnotVector);
+ static int FindSpanRef(nbReal &u, int first, int last, const nbReal *KnotVector);
static void Scale(nbReal *KV, int r, nbReal Max);
static void MergeKnotVectors(int Ulen, nbReal *U, int Vlen, nbReal *V, int &Ki, nbReal *KV);
static void Refine(Object_NURBS *obj, nbReal *X, int r, bool UV);
@@ -50,10 +49,13 @@
static void Remove(Object_NURBS *obj);
static void BezierDecompose(int Npts, int Order, Point3d *CtlPts, nbReal *KV);
static void removeCurveKnot(nbReal4* inCps, int cpCount, int nextInCp, nbReal4* outCps, int nextOutCp, nbReal* knots, int degree, int r, int num);
- static void insertCurveKnot(nbReal4* inCps, int cpCount, int nextInCp, nbReal4* outCps, int nextOutCp, nbReal* knots, int degree, nbReal u, int k, int mult, int num);
- static nbReal getLastKnotValue(Object_NURBS *obj, bool UV);
+// static void splitCurve(const nbReal4* srcCps, int cpCount, int nextSrcCp, nbReal4* dstCps, int nextDstCp, const nbReal* knots, int degree, nbReal u, int k, int mult, bool cyclic, int& frstLen, int& scndLen);
+// static void insertCurveKnot(const nbReal4* inCps, int cpCount, int nextInCp, nbReal4* outCps, int nextOutCp, const nbReal* knots, int degree, nbReal u, int k, int mult, int num, bool cyclic = false);
+ static nbReal getLastKnotValue(Object_NURBS *obj, bool UV);
static nbReal getFirstKnotValue(Object_NURBS *obj, bool UV);
+ template <class SrcPoint, class DstPoint>
+ static void split(const SrcPoint* srcCps, int curveLength, int curveCount, int nextSrcCp, int nextSrcCurve, DstPoint* dstCps, int nextDstCp, int nextDstCurve, const nbReal* knots, int degree, nbReal u, bool cyclic, int& k, int& newPoints, int& inserted, int& frstLen, int& scndLen, bool pointsIn3D);
/**
* Inserts knot into knot vector.
* @param inKnots input knot vector.
@@ -82,4 +84,56 @@
}; //eof class NURBS_Knot
+
+template <class SrcPoint, class DstPoint>
+void NURBS_Knot::split(const SrcPoint* srcCps, int curveLength, int curveCount, int nextSrcCp, int nextSrcCurve, DstPoint* dstCps, int nextDstCp, int nextDstCurve, const nbReal* knots, int degree, nbReal u, bool cyclic, int& k, int& newPoints, int& inserted, int& frstLen, int& scndLen, bool pointsIn3D = false) {
+ //number of knots to insert
+ SrcPoint* srcCurve = const_cast<SrcPoint* >(srcCps);
+ DstPoint* dstCurve = dstCps;
+ const int srcBufferLength = curveLength + (cyclic ? degree + 1 : 0);
+ const int nextSrcBufferCp = cyclic ? 1 : nextSrcCp;
+
+ int mult;
+ NURBS_Knot::getSpanAndMult(u, degree, curveLength, cyclic, knots, k, mult);
+ //printf("u: %f, k: %i, mult: %i\n", u, k, mult);
+ const int num = NurbanaMath::Max(degree - mult, 0);
+ inserted = num;
+
+ if (num) {
+ SrcPoint* srcBuffer;
+ if (cyclic)
+ srcBuffer = (SrcPoint*) MEM_callocN(sizeof(*srcBuffer) * srcBufferLength, "split() srcBuffer");
+
+ for (int i = 0; i < curveCount; i++, srcCurve += nextSrcCurve, dstCurve += nextDstCurve) {
+ if (cyclic) {
+ copyCurve(srcCurve, nextSrcCp, srcBuffer, 1, curveLength);
+ copyCurve(srcCurve, nextSrcCp, srcBuffer + curveLength, 1, degree + 1);
+ } else srcBuffer = srcCurve;
@@ Diff output truncated at 10240 characters. @@
More information about the Bf-blender-cvs
mailing list