1 package jogamp.opengl.glu.nurbs; 2 3 /* 4 ** License Applicability. Except to the extent portions of this file are 5 ** made subject to an alternative license as permitted in the SGI Free 6 ** Software License B, Version 2.0 (the "License"), the contents of this 7 ** file are subject only to the provisions of the License. You may not use 8 ** this file except in compliance with the License. You may obtain a copy 9 ** of the License at Silicon Graphics, Inc., attn: Legal Services, 1600 10 ** Amphitheatre Parkway, Mountain View, CA 94043-1351, or at: 11 ** 12 ** http://oss.sgi.com/projects/FreeB 13 ** 14 ** Note that, as provided in the License, the Software is distributed on an 15 ** "AS IS" basis, with ALL EXPRESS AND IMPLIED WARRANTIES AND CONDITIONS 16 ** DISCLAIMED, INCLUDING, WITHOUT LIMITATION, ANY IMPLIED WARRANTIES AND 17 ** CONDITIONS OF MERCHANTABILITY, SATISFACTORY QUALITY, FITNESS FOR A 18 ** PARTICULAR PURPOSE, AND NON-INFRINGEMENT. 19 ** 20 ** Original Code. The Original Code is: OpenGL Sample Implementation, 21 ** Version 1.2.1, released January 26, 2000, developed by Silicon Graphics, 22 ** Inc. The Original Code is Copyright (c) 1991-2000 Silicon Graphics, Inc. 23 ** Copyright in any portions created by third parties is as indicated 24 ** elsewhere herein. All Rights Reserved. 25 ** 26 ** Additional Notice Provisions: The application programming interfaces 27 ** established by SGI in conjunction with the Original Code are The 28 ** OpenGL(R) Graphics System: A Specification (Version 1.2.1), released 29 ** April 1, 1999; The OpenGL(R) Graphics System Utility Library (Version 30 ** 1.3), released November 4, 1998; and OpenGL(R) Graphics with the X 31 ** Window System(R) (Version 1.3), released October 19, 1998. This software 32 ** was created using the OpenGL(R) version 1.2.1 Sample Implementation 33 ** published by SGI, but has not been independently verified as being 34 ** compliant with the OpenGL(R) version 1.2.1 Specification. 35 */ 36 37 /** 38 * NURBS definition 39 * @author Tomas Hrasky 40 * 41 */ 42 public class Splinespec { 43 44 /** 45 * Dimension 46 */ 47 private final int dim; 48 49 /** 50 * Knot vector specs 51 */ 52 private Knotspec kspec; 53 54 /** 55 * Control points after conversion 56 */ 57 private CArrayOfFloats outcpts; 58 59 /** 60 * Makes new Splinespec with given dimension 61 * @param i dimension 62 */ Splinespec(final int i)63 public Splinespec(final int i) { 64 // DONE 65 this.dim = i; 66 } 67 68 /** 69 * Initializes knotspec according to knotvector 70 * @param knotvector basic knotvector 71 */ kspecinit(final Knotvector knotvector)72 public void kspecinit(final Knotvector knotvector) { 73 // DONE 74 this.kspec = new Knotspec(); 75 kspec.inkbegin = new CArrayOfFloats(knotvector.knotlist, 0); 76 kspec.inkend = new CArrayOfFloats(knotvector.knotlist, 77 knotvector.knotcount); 78 kspec.prestride = knotvector.stride; 79 kspec.order = knotvector.order; 80 kspec.next = null; 81 } 82 83 /** 84 * Initializes knotspec according to knotvector - SURFACE 85 * @param sknotvector knotvector in u dir 86 * @param tknotvector knotvector in v dir 87 */ kspecinit(final Knotvector sknotvector, final Knotvector tknotvector)88 public void kspecinit(final Knotvector sknotvector, final Knotvector tknotvector) { 89 // DONE 90 this.kspec = new Knotspec(); 91 final Knotspec tkspec = new Knotspec(); 92 93 kspec.inkbegin = new CArrayOfFloats(sknotvector.knotlist, 0); 94 kspec.inkend = new CArrayOfFloats(sknotvector.knotlist, 95 sknotvector.knotcount); 96 kspec.prestride = sknotvector.stride; 97 kspec.order = sknotvector.order; 98 kspec.next = tkspec; 99 100 tkspec.inkbegin = new CArrayOfFloats(tknotvector.knotlist, 0); 101 tkspec.inkend = new CArrayOfFloats(tknotvector.knotlist, 102 tknotvector.knotcount); 103 tkspec.prestride = tknotvector.stride; 104 tkspec.order = tknotvector.order; 105 tkspec.next = null; 106 } 107 108 /** 109 * Preselect and select knotspecs 110 */ select()111 public void select() { 112 // DONE 113 for (Knotspec knotspec = kspec; knotspec != null; knotspec = knotspec.next) { 114 knotspec.preselect(); 115 knotspec.select(); 116 } 117 118 } 119 120 /** 121 * Prepares for conversion 122 * @param ncoords number of coords 123 */ layout(final int ncoords)124 public void layout(final int ncoords) { 125 // DONE 126 int stride = ncoords; 127 for (Knotspec knotspec = kspec; knotspec != null; knotspec = knotspec.next) { 128 knotspec.poststride = stride; 129 stride *= (knotspec.bend.getPointer() - knotspec.bbegin 130 .getPointer()) 131 * knotspec.order + knotspec.postoffset; 132 knotspec.preoffset *= knotspec.prestride; 133 knotspec.prewidth *= knotspec.poststride; 134 knotspec.postwidth *= knotspec.poststride; 135 knotspec.postoffset *= knotspec.poststride; 136 knotspec.ncoords = ncoords; 137 } 138 outcpts = new CArrayOfFloats(new float[stride]); 139 140 } 141 142 /** 143 * Prepares quilt for conversion 144 * @param quilt quilt to work with 145 */ setupquilt(final Quilt quilt)146 public void setupquilt(final Quilt quilt) { 147 // DONE 148 final CArrayOfQuiltspecs qspec = new CArrayOfQuiltspecs(quilt.qspec); 149 quilt.eqspec = new CArrayOfQuiltspecs(qspec.getArray(), dim); 150 for (Knotspec knotspec = kspec; knotspec != null;) { 151 qspec.get().stride = knotspec.poststride; 152 qspec.get().width = knotspec.bend.getPointer() 153 - knotspec.bbegin.getPointer(); 154 qspec.get().order = knotspec.order; 155 qspec.get().offset = knotspec.postoffset; 156 qspec.get().index = 0; 157 qspec.get().bdry[0] = (knotspec.kleft.getPointer() == knotspec.kfirst 158 .getPointer()) ? 1 : 0; 159 qspec.get().bdry[1] = (knotspec.kright.getPointer() == knotspec.klast 160 .getPointer()) ? 1 : 0; 161 qspec.get().breakpoints = new float[qspec.get().width + 1]; 162 final CArrayOfFloats k = new CArrayOfFloats(qspec.get().breakpoints, 0); 163 for (final CArrayOfBreakpts bk = new CArrayOfBreakpts(knotspec.bbegin); bk 164 .getPointer() <= knotspec.bend.getPointer(); bk.pp()) { 165 k.set(bk.get().value); 166 k.pp(); 167 } 168 knotspec = knotspec.next; 169 if (knotspec != null) 170 qspec.pp(); 171 } 172 quilt.cpts = new CArrayOfFloats(outcpts); 173 quilt.next = null; 174 } 175 176 /** 177 * Copies array of control points to output array 178 * @param ctlarray control points array 179 */ copy(final CArrayOfFloats ctlarray)180 public void copy(final CArrayOfFloats ctlarray) { 181 // DONE 182 kspec.copy(ctlarray, outcpts); 183 184 } 185 186 /** 187 * Transforms knotspecs - conversion 188 */ transform()189 public void transform() { 190 // DONE 191 Knotspec knotspec; 192 outcpts.setPointer(0); 193 for (knotspec = kspec; knotspec != null; knotspec = knotspec.next) 194 knotspec.istransformed = false; 195 196 for (knotspec = kspec; knotspec != null; knotspec = knotspec.next) { 197 for (Knotspec kspec2 = kspec; kspec2 != null; kspec2 = kspec2.next) 198 kspec2.kspectotrans = knotspec; 199 kspec.transform(outcpts); 200 knotspec.istransformed = true; 201 } 202 203 } 204 } 205