From: <cd...@us...> - 2009-09-14 13:30:45
|
Revision: 6244 http://octave.svn.sourceforge.net/octave/?rev=6244&view=rev Author: cdf Date: 2009-09-14 13:30:37 +0000 (Mon, 14 Sep 2009) Log Message: ----------- fix bug in surfderivcpts Modified Paths: -------------- trunk/octave-forge/extra/nurbs/src/low_level_functions.cc trunk/octave-forge/extra/nurbs/src/low_level_functions.h trunk/octave-forge/extra/nurbs/src/nrbsurfderiveval.cc trunk/octave-forge/extra/nurbs/src/surfderiveval.cc Modified: trunk/octave-forge/extra/nurbs/src/low_level_functions.cc =================================================================== --- trunk/octave-forge/extra/nurbs/src/low_level_functions.cc 2009-09-13 19:19:37 UTC (rev 6243) +++ trunk/octave-forge/extra/nurbs/src/low_level_functions.cc 2009-09-14 13:30:37 UTC (rev 6244) @@ -260,9 +260,10 @@ { octave_idx_type r = r2-r1, s = s2-s1; + octave_idx_type du = d <= p ? d : p; octave_idx_type dv = d <= q ? d : q; - + //std::cout << "r1=" << r1 << " r2=" << r2 << " s1=" << s1 << " s2=" << s2 << "\n"; Array<octave_idx_type> idxta (4, 0); Array<idx_vector> idxva (4, idx_vector (':')); dim_vector idxa; idxa.resize (4); @@ -280,10 +281,11 @@ { for ( octave_idx_type i(0); i<=r-k; i++) - { - + { + //std::cout << "k=" << k << " " << idxa(0) << " i=" << i << " " << idxa(2) << " j-s1=" << j << " " << idxa(3)<< "\n"; + assert (k<idxa(0) && i<idxa(2) && j-s1<idxa(3)); idxta (0) = k; idxta (1) = 0; - idxta (2) = i; idxta (3) = j; + idxta (2) = i; idxta (3) = j-s1; pkl(idxta) = temp (k, i); } } @@ -308,7 +310,7 @@ for (octave_idx_type j(0); j<=s-l; j++) { - + assert (k<idxa(0) && l<idxa(1) && i<idxa(2) && j<idxa(3)); idxta (0) = k; idxta (1) = l; idxta (2) = i; idxta (3) = j; pkl(idxta) = temp (l, j); @@ -321,9 +323,9 @@ } -int surfderiveval (octave_idx_type n, octave_idx_type p, RowVector U, - octave_idx_type m, octave_idx_type q, RowVector V, - Matrix P, double u, double v, octave_idx_type d, +int surfderiveval (octave_idx_type n, octave_idx_type p, const RowVector &U, + octave_idx_type m, octave_idx_type q, const RowVector &V, + const Matrix &P, double u, double v, octave_idx_type d, Matrix &skl) { Array<octave_idx_type> idx(4, 0); @@ -341,7 +343,7 @@ Nu.insert (temp.transpose (), 0,ip); } - octave_idx_type vspan = findspan (n, p, u, U); + octave_idx_type vspan = findspan (m, q, v, V); Matrix Nv (q+1, q+1, 0.0); for (octave_idx_type iq(0); iq<=q; iq++) { Modified: trunk/octave-forge/extra/nurbs/src/low_level_functions.h =================================================================== --- trunk/octave-forge/extra/nurbs/src/low_level_functions.h 2009-09-13 19:19:37 UTC (rev 6243) +++ trunk/octave-forge/extra/nurbs/src/low_level_functions.h 2009-09-14 13:30:37 UTC (rev 6244) @@ -34,7 +34,7 @@ octave_idx_type r2, octave_idx_type s1, octave_idx_type s2, NDArray &pkl); -int surfderiveval (octave_idx_type n, octave_idx_type p, RowVector U, - octave_idx_type m, octave_idx_type q, RowVector V, - Matrix P, double u, double v, octave_idx_type d, +int surfderiveval (octave_idx_type n, octave_idx_type p, const RowVector &U, + octave_idx_type m, octave_idx_type q, const RowVector &V, + const Matrix &P, double u, double v, octave_idx_type d, Matrix &skl); Modified: trunk/octave-forge/extra/nurbs/src/nrbsurfderiveval.cc =================================================================== --- trunk/octave-forge/extra/nurbs/src/nrbsurfderiveval.cc 2009-09-13 19:19:37 UTC (rev 6243) +++ trunk/octave-forge/extra/nurbs/src/nrbsurfderiveval.cc 2009-09-14 13:30:37 UTC (rev 6244) @@ -155,17 +155,43 @@ %! [coef(2,:,:), coef(1,:,:)] = meshgrid (c, c); %! coef(3,:,:) = coef(1,:,:); %! srf = nrbmak (coef, {k, k}); -%! uv = linspace(0,1,11)([1 1],:); +%! [u, v] = meshgrid (linspace(0,1,11)); +%! uv = [u(:)';v(:)']; +%! skl = nrbsurfderiveval (srf, uv, 0); +%! assert (squeeze (skl (1:2,1,1,:)), nrbeval (srf, uv)(1:2,:), 1e3*eps) + +%!test +%! k = [0 0 1 1]; +%! c = [0 1]; +%! [coef(2,:,:), coef(1,:,:)] = meshgrid (c, c); +%! coef(3,:,:) = coef(1,:,:); +%! srf = nrbmak (coef, {k, k}); +%! srf = nrbkntins (srf, {[], rand(2,1)}); +%! [u, v] = meshgrid (linspace(0,1,11)); +%! uv = [u(:)';v(:)']; +%! skl = nrbsurfderiveval (srf, uv, 0); +%! assert (squeeze (skl (1:2,1,1,:)), nrbeval (srf, uv)(1:2,:), 1e3*eps) + +%!test +%! k = [0 0 1 1]; +%! c = [0 1]; +%! [coef(2,:,:), coef(1,:,:)] = meshgrid (c, c); +%! coef(3,:,:) = coef(1,:,:); +%! srf = nrbmak (coef, {k, k}); +%! [u, v] = meshgrid (linspace(0,1,11)); +%! uv = [u(:)';v(:)']; %! skl = nrbsurfderiveval (srf, uv, 1); %! assert (squeeze (skl (2,:,:,3)), [.2 1; 0 0]) +%! assert (squeeze (skl (1:2,1,1,:)), nrbeval (srf, uv)(1:2,:), 1e3*eps) -%!shared uv, P, dPdx, d2Pdx2, c1, c2 +%!shared srf, uv, P, dPdx, d2Pdx2, c1, c2 %!test -%! uv = [sort(rand(1,10)); (rand(1,10))]; +%! [u, v] = meshgrid (linspace(0,1,10)); +%! uv = [u(:)';v(:)']; %! c1 = nrbmak([0 1/2 1; 0 1 0],[0 0 0 1 1 1]); %! c1 = nrbtform (c1, vecrotx (pi/2)); %! c2 = nrbtform(c1, vectrans([0 1 0])); -%! srf = nrbdegelev (nrbruled (c1, c2), [0, 1]); +%! srf = nrbdegelev (nrbruled (c1, c2), [3, 1]); %! skl = nrbsurfderiveval (srf, uv, 2); %! P = squeeze(skl(:,1,1,:)); %! dPdx = squeeze(skl(:,2,1,:)); @@ -178,13 +204,19 @@ %! P = squeeze(skl(:,1,1,:)); %! dPdx = squeeze(skl(:,2,1,:)); %! d2Pdx2 = squeeze(skl(:,3,1,:)); +%! assert (squeeze (skl (1:2,1,1,:)), nrbeval (srf, uv)(1:2,:), 1e3*eps) %!assert(P(3,:), 2*(P(1,:)-P(1,:).^2),100*eps) %!assert(dPdx(3,:), 2-4*P(1,:), 100*eps) %!assert(d2Pdx2(3,:), -4+0*P(1,:), 100*eps) +%! +%!test +%! skl = nrbsurfderiveval (srf, uv, 0); +%! assert (squeeze (skl (1:2,1,1,:)), nrbeval (srf, uv)(1:2,:), 1e3*eps) -%!shared dPdu, d2Pdu2, P +%!shared dPdu, d2Pdu2, P, srf, uv %!test -%! uv = [sort(rand(1,10)); (rand(1,10))]; +%! [u, v] = meshgrid (linspace(0,1,10)); +%! uv = [u(:)';v(:)']; %! c1 = nrbmak([0 1/2 1; 0.1 1.6 1.1; 0 0 0],[0 0 0 1 1 1]); %! c2 = nrbmak([0 1/2 1; 0.1 1.6 1.1; 1 1 1],[0 0 0 1 1 1]); %! srf = nrbdegelev (nrbruled (c1, c2), [0, 1]); @@ -193,6 +225,12 @@ %! dPdu = squeeze(skl(:,2,1,:)); %! dPdv = squeeze(skl(:,1,2,:)); %! d2Pdu2 = squeeze(skl(:,3,1,:)); +%! assert (squeeze (skl (1:2,1,1,:)), nrbeval (srf, uv)(1:2,:), 1e3*eps) %!assert(dPdu(2,:), 3-4*P(1,:),100*eps) %!assert(d2Pdu2(2,:), -4+0*P(1,:),100*eps) +%! +%!test +%! skl = nrbsurfderiveval (srf, uv, 0); +%! assert (squeeze (skl (1:2,1,1,:)), nrbeval (srf, uv)(1:2,:), 1e3*eps) + */ Modified: trunk/octave-forge/extra/nurbs/src/surfderiveval.cc =================================================================== --- trunk/octave-forge/extra/nurbs/src/surfderiveval.cc 2009-09-13 19:19:37 UTC (rev 6243) +++ trunk/octave-forge/extra/nurbs/src/surfderiveval.cc 2009-09-14 13:30:37 UTC (rev 6244) @@ -63,6 +63,7 @@ } /* +%!shared srf %!test %! k = [0 0 0 1 1 1]; %! c = [0 1/2 1]; @@ -70,10 +71,20 @@ %! srf = nrbmak (coef, {k, k}); %! skl = surfderiveval (srf.number(1)-1, %! srf.order(1)-1, -%! k, +%! srf.knots{1}, %! srf.number(2)-1, %! srf.order(2)-1, -%! k, -%! squeeze(coef(1,:,:)), .5, .5, 1) ; +%! srf.knots{2}, +%! squeeze(srf.coefs(1,:,:)), .5, .5, 1) ; %! assert (skl, [.5 0; 1 0]) +%!test +%! srf = nrbkntins (srf, {[], rand(1,2)}); +%! skl = surfderiveval (srf.number(1)-1, +%! srf.order(1)-1, +%! srf.knots{1}, +%! srf.number(2)-1, +%! srf.order(2)-1, +%! srf.knots{2}, +%! squeeze(srf.coefs(1,:,:)), .5, .5, 1) ; +%! assert (skl, [.5 0; 1 0]) */ This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |