createRectangleOutlineGeometry.js 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428
  1. /* This file is automatically rebuilt by the Cesium build process. */
  2. define(['./defined-26bd4a03', './Check-da037458', './freezeObject-2d83f591', './defaultValue-f2e68450', './Math-fa6e45cb', './Cartesian2-2a723276', './defineProperties-6f7a50f2', './Transforms-65aba0a4', './RuntimeError-ad75c885', './WebGLConstants-497deb20', './ComponentDatatype-69643096', './GeometryAttribute-ed359d71', './when-ee12a2cb', './GeometryAttributes-eecc9f43', './IndexDatatype-3de60176', './GeometryOffsetAttribute-cb30cd97', './EllipsoidRhumbLine-c6cdbfd3', './PolygonPipeline-e486c11c', './RectangleGeometryLibrary-39950242'], function (defined, Check, freezeObject, defaultValue, _Math, Cartesian2, defineProperties, Transforms, RuntimeError, WebGLConstants, ComponentDatatype, GeometryAttribute, when, GeometryAttributes, IndexDatatype, GeometryOffsetAttribute, EllipsoidRhumbLine, PolygonPipeline, RectangleGeometryLibrary) { 'use strict';
  3. var bottomBoundingSphere = new Transforms.BoundingSphere();
  4. var topBoundingSphere = new Transforms.BoundingSphere();
  5. var positionScratch = new Cartesian2.Cartesian3();
  6. var rectangleScratch = new Cartesian2.Rectangle();
  7. function constructRectangle(geometry, computedOptions) {
  8. var ellipsoid = geometry._ellipsoid;
  9. var height = computedOptions.height;
  10. var width = computedOptions.width;
  11. var northCap = computedOptions.northCap;
  12. var southCap = computedOptions.southCap;
  13. var rowHeight = height;
  14. var widthMultiplier = 2;
  15. var size = 0;
  16. var corners = 4;
  17. if (northCap) {
  18. widthMultiplier -= 1;
  19. rowHeight -= 1;
  20. size += 1;
  21. corners -= 2;
  22. }
  23. if (southCap) {
  24. widthMultiplier -= 1;
  25. rowHeight -= 1;
  26. size += 1;
  27. corners -= 2;
  28. }
  29. size += (widthMultiplier * width + 2 * rowHeight - corners);
  30. var positions = new Float64Array(size * 3);
  31. var posIndex = 0;
  32. var row = 0;
  33. var col;
  34. var position = positionScratch;
  35. if (northCap) {
  36. RectangleGeometryLibrary.RectangleGeometryLibrary.computePosition(computedOptions, ellipsoid, false, row, 0, position);
  37. positions[posIndex++] = position.x;
  38. positions[posIndex++] = position.y;
  39. positions[posIndex++] = position.z;
  40. } else {
  41. for (col = 0; col < width; col++) {
  42. RectangleGeometryLibrary.RectangleGeometryLibrary.computePosition(computedOptions, ellipsoid, false, row, col, position);
  43. positions[posIndex++] = position.x;
  44. positions[posIndex++] = position.y;
  45. positions[posIndex++] = position.z;
  46. }
  47. }
  48. col = width - 1;
  49. for (row = 1; row < height; row++) {
  50. RectangleGeometryLibrary.RectangleGeometryLibrary.computePosition(computedOptions, ellipsoid, false, row, col, position);
  51. positions[posIndex++] = position.x;
  52. positions[posIndex++] = position.y;
  53. positions[posIndex++] = position.z;
  54. }
  55. row = height - 1;
  56. if (!southCap) { // if southCap is true, we dont need to add any more points because the south pole point was added by the iteration above
  57. for (col = width - 2; col >= 0; col--) {
  58. RectangleGeometryLibrary.RectangleGeometryLibrary.computePosition(computedOptions, ellipsoid, false, row, col, position);
  59. positions[posIndex++] = position.x;
  60. positions[posIndex++] = position.y;
  61. positions[posIndex++] = position.z;
  62. }
  63. }
  64. col = 0;
  65. for (row = height - 2; row > 0; row--) {
  66. RectangleGeometryLibrary.RectangleGeometryLibrary.computePosition(computedOptions, ellipsoid, false, row, col, position);
  67. positions[posIndex++] = position.x;
  68. positions[posIndex++] = position.y;
  69. positions[posIndex++] = position.z;
  70. }
  71. var indicesSize = positions.length / 3 * 2;
  72. var indices = IndexDatatype.IndexDatatype.createTypedArray(positions.length / 3, indicesSize);
  73. var index = 0;
  74. for (var i = 0; i < (positions.length / 3) - 1; i++) {
  75. indices[index++] = i;
  76. indices[index++] = i + 1;
  77. }
  78. indices[index++] = (positions.length / 3) - 1;
  79. indices[index++] = 0;
  80. var geo = new GeometryAttribute.Geometry({
  81. attributes : new GeometryAttributes.GeometryAttributes(),
  82. primitiveType : GeometryAttribute.PrimitiveType.LINES
  83. });
  84. geo.attributes.position = new GeometryAttribute.GeometryAttribute({
  85. componentDatatype : ComponentDatatype.ComponentDatatype.DOUBLE,
  86. componentsPerAttribute : 3,
  87. values : positions
  88. });
  89. geo.indices = indices;
  90. return geo;
  91. }
  92. function constructExtrudedRectangle(rectangleGeometry, computedOptions) {
  93. var surfaceHeight = rectangleGeometry._surfaceHeight;
  94. var extrudedHeight = rectangleGeometry._extrudedHeight;
  95. var ellipsoid = rectangleGeometry._ellipsoid;
  96. var minHeight = extrudedHeight;
  97. var maxHeight = surfaceHeight;
  98. var geo = constructRectangle(rectangleGeometry, computedOptions);
  99. var height = computedOptions.height;
  100. var width = computedOptions.width;
  101. var topPositions = PolygonPipeline.PolygonPipeline.scaleToGeodeticHeight(geo.attributes.position.values, maxHeight, ellipsoid, false);
  102. var length = topPositions.length;
  103. var positions = new Float64Array(length * 2);
  104. positions.set(topPositions);
  105. var bottomPositions = PolygonPipeline.PolygonPipeline.scaleToGeodeticHeight(geo.attributes.position.values, minHeight, ellipsoid);
  106. positions.set(bottomPositions, length);
  107. geo.attributes.position.values = positions;
  108. var northCap = computedOptions.northCap;
  109. var southCap = computedOptions.southCap;
  110. var corners = 4;
  111. if (northCap) {
  112. corners -= 1;
  113. }
  114. if (southCap) {
  115. corners -= 1;
  116. }
  117. var indicesSize = (positions.length / 3 + corners) * 2;
  118. var indices = IndexDatatype.IndexDatatype.createTypedArray(positions.length / 3, indicesSize);
  119. length = positions.length / 6;
  120. var index = 0;
  121. for (var i = 0; i < length - 1; i++) {
  122. indices[index++] = i;
  123. indices[index++] = i + 1;
  124. indices[index++] = i + length;
  125. indices[index++] = i + length + 1;
  126. }
  127. indices[index++] = length - 1;
  128. indices[index++] = 0;
  129. indices[index++] = length + length - 1;
  130. indices[index++] = length;
  131. indices[index++] = 0;
  132. indices[index++] = length;
  133. var bottomCorner;
  134. if (northCap) {
  135. bottomCorner = height - 1;
  136. } else {
  137. var topRightCorner = width - 1;
  138. indices[index++] = topRightCorner;
  139. indices[index++] = topRightCorner + length;
  140. bottomCorner = width + height - 2;
  141. }
  142. indices[index++] = bottomCorner;
  143. indices[index++] = bottomCorner + length;
  144. if (!southCap) {
  145. var bottomLeftCorner = width + bottomCorner - 1;
  146. indices[index++] = bottomLeftCorner;
  147. indices[index] = bottomLeftCorner + length;
  148. }
  149. geo.indices = indices;
  150. return geo;
  151. }
  152. /**
  153. * A description of the outline of a a cartographic rectangle on an ellipsoid centered at the origin.
  154. *
  155. * @alias RectangleOutlineGeometry
  156. * @constructor
  157. *
  158. * @param {Object} options Object with the following properties:
  159. * @param {Rectangle} options.rectangle A cartographic rectangle with north, south, east and west properties in radians.
  160. * @param {Ellipsoid} [options.ellipsoid=Ellipsoid.WGS84] The ellipsoid on which the rectangle lies.
  161. * @param {Number} [options.granularity=CesiumMath.RADIANS_PER_DEGREE] The distance, in radians, between each latitude and longitude. Determines the number of positions in the buffer.
  162. * @param {Number} [options.height=0.0] The distance in meters between the rectangle and the ellipsoid surface.
  163. * @param {Number} [options.rotation=0.0] The rotation of the rectangle, in radians. A positive rotation is counter-clockwise.
  164. * @param {Number} [options.extrudedHeight] The distance in meters between the rectangle's extruded face and the ellipsoid surface.
  165. *
  166. * @exception {DeveloperError} <code>options.rectangle.north</code> must be in the interval [<code>-Pi/2</code>, <code>Pi/2</code>].
  167. * @exception {DeveloperError} <code>options.rectangle.south</code> must be in the interval [<code>-Pi/2</code>, <code>Pi/2</code>].
  168. * @exception {DeveloperError} <code>options.rectangle.east</code> must be in the interval [<code>-Pi</code>, <code>Pi</code>].
  169. * @exception {DeveloperError} <code>options.rectangle.west</code> must be in the interval [<code>-Pi</code>, <code>Pi</code>].
  170. * @exception {DeveloperError} <code>options.rectangle.north</code> must be greater than <code>rectangle.south</code>.
  171. *
  172. * @see RectangleOutlineGeometry#createGeometry
  173. *
  174. * @example
  175. * var rectangle = new Cesium.RectangleOutlineGeometry({
  176. * ellipsoid : Cesium.Ellipsoid.WGS84,
  177. * rectangle : Cesium.Rectangle.fromDegrees(-80.0, 39.0, -74.0, 42.0),
  178. * height : 10000.0
  179. * });
  180. * var geometry = Cesium.RectangleOutlineGeometry.createGeometry(rectangle);
  181. */
  182. function RectangleOutlineGeometry(options) {
  183. options = defaultValue.defaultValue(options, defaultValue.defaultValue.EMPTY_OBJECT);
  184. var rectangle = options.rectangle;
  185. var granularity = defaultValue.defaultValue(options.granularity, _Math.CesiumMath.RADIANS_PER_DEGREE);
  186. var ellipsoid = defaultValue.defaultValue(options.ellipsoid, Cartesian2.Ellipsoid.WGS84);
  187. var rotation = defaultValue.defaultValue(options.rotation, 0.0);
  188. //>>includeStart('debug', pragmas.debug);
  189. if (!defined.defined(rectangle)) {
  190. throw new Check.DeveloperError('rectangle is required.');
  191. }
  192. Cartesian2.Rectangle.validate(rectangle);
  193. if (rectangle.north < rectangle.south) {
  194. throw new Check.DeveloperError('options.rectangle.north must be greater than options.rectangle.south');
  195. }
  196. //>>includeEnd('debug');
  197. var height = defaultValue.defaultValue(options.height, 0.0);
  198. var extrudedHeight = defaultValue.defaultValue(options.extrudedHeight, height);
  199. this._rectangle = Cartesian2.Rectangle.clone(rectangle);
  200. this._granularity = granularity;
  201. this._ellipsoid = ellipsoid;
  202. this._surfaceHeight = Math.max(height, extrudedHeight);
  203. this._rotation = rotation;
  204. this._extrudedHeight = Math.min(height, extrudedHeight);
  205. this._offsetAttribute = options.offsetAttribute;
  206. this._workerName = 'createRectangleOutlineGeometry';
  207. }
  208. /**
  209. * The number of elements used to pack the object into an array.
  210. * @type {Number}
  211. */
  212. RectangleOutlineGeometry.packedLength = Cartesian2.Rectangle.packedLength + Cartesian2.Ellipsoid.packedLength + 5;
  213. /**
  214. * Stores the provided instance into the provided array.
  215. *
  216. * @param {RectangleOutlineGeometry} value The value to pack.
  217. * @param {Number[]} array The array to pack into.
  218. * @param {Number} [startingIndex=0] The index into the array at which to start packing the elements.
  219. *
  220. * @returns {Number[]} The array that was packed into
  221. */
  222. RectangleOutlineGeometry.pack = function(value, array, startingIndex) {
  223. //>>includeStart('debug', pragmas.debug);
  224. if (!defined.defined(value)) {
  225. throw new Check.DeveloperError('value is required');
  226. }
  227. if (!defined.defined(array)) {
  228. throw new Check.DeveloperError('array is required');
  229. }
  230. //>>includeEnd('debug');
  231. startingIndex = defaultValue.defaultValue(startingIndex, 0);
  232. Cartesian2.Rectangle.pack(value._rectangle, array, startingIndex);
  233. startingIndex += Cartesian2.Rectangle.packedLength;
  234. Cartesian2.Ellipsoid.pack(value._ellipsoid, array, startingIndex);
  235. startingIndex += Cartesian2.Ellipsoid.packedLength;
  236. array[startingIndex++] = value._granularity;
  237. array[startingIndex++] = value._surfaceHeight;
  238. array[startingIndex++] = value._rotation;
  239. array[startingIndex++] = value._extrudedHeight;
  240. array[startingIndex] = defaultValue.defaultValue(value._offsetAttribute, -1);
  241. return array;
  242. };
  243. var scratchRectangle = new Cartesian2.Rectangle();
  244. var scratchEllipsoid = Cartesian2.Ellipsoid.clone(Cartesian2.Ellipsoid.UNIT_SPHERE);
  245. var scratchOptions = {
  246. rectangle : scratchRectangle,
  247. ellipsoid : scratchEllipsoid,
  248. granularity : undefined,
  249. height : undefined,
  250. rotation : undefined,
  251. extrudedHeight : undefined,
  252. offsetAttribute : undefined
  253. };
  254. /**
  255. * Retrieves an instance from a packed array.
  256. *
  257. * @param {Number[]} array The packed array.
  258. * @param {Number} [startingIndex=0] The starting index of the element to be unpacked.
  259. * @param {RectangleOutlineGeometry} [result] The object into which to store the result.
  260. * @returns {RectangleOutlineGeometry} The modified result parameter or a new Quaternion instance if one was not provided.
  261. */
  262. RectangleOutlineGeometry.unpack = function(array, startingIndex, result) {
  263. //>>includeStart('debug', pragmas.debug);
  264. if (!defined.defined(array)) {
  265. throw new Check.DeveloperError('array is required');
  266. }
  267. //>>includeEnd('debug');
  268. startingIndex = defaultValue.defaultValue(startingIndex, 0);
  269. var rectangle = Cartesian2.Rectangle.unpack(array, startingIndex, scratchRectangle);
  270. startingIndex += Cartesian2.Rectangle.packedLength;
  271. var ellipsoid = Cartesian2.Ellipsoid.unpack(array, startingIndex, scratchEllipsoid);
  272. startingIndex += Cartesian2.Ellipsoid.packedLength;
  273. var granularity = array[startingIndex++];
  274. var height = array[startingIndex++];
  275. var rotation = array[startingIndex++];
  276. var extrudedHeight = array[startingIndex++];
  277. var offsetAttribute = array[startingIndex];
  278. if (!defined.defined(result)) {
  279. scratchOptions.granularity = granularity;
  280. scratchOptions.height = height;
  281. scratchOptions.rotation = rotation;
  282. scratchOptions.extrudedHeight = extrudedHeight;
  283. scratchOptions.offsetAttribute = offsetAttribute === -1 ? undefined : offsetAttribute;
  284. return new RectangleOutlineGeometry(scratchOptions);
  285. }
  286. result._rectangle = Cartesian2.Rectangle.clone(rectangle, result._rectangle);
  287. result._ellipsoid = Cartesian2.Ellipsoid.clone(ellipsoid, result._ellipsoid);
  288. result._surfaceHeight = height;
  289. result._rotation = rotation;
  290. result._extrudedHeight = extrudedHeight;
  291. result._offsetAttribute = offsetAttribute === -1 ? undefined : offsetAttribute;
  292. return result;
  293. };
  294. var nwScratch = new Cartesian2.Cartographic();
  295. /**
  296. * Computes the geometric representation of an outline of a rectangle, including its vertices, indices, and a bounding sphere.
  297. *
  298. * @param {RectangleOutlineGeometry} rectangleGeometry A description of the rectangle outline.
  299. * @returns {Geometry|undefined} The computed vertices and indices.
  300. *
  301. * @exception {DeveloperError} Rotated rectangle is invalid.
  302. */
  303. RectangleOutlineGeometry.createGeometry = function(rectangleGeometry) {
  304. var rectangle = rectangleGeometry._rectangle;
  305. var ellipsoid = rectangleGeometry._ellipsoid;
  306. var computedOptions = RectangleGeometryLibrary.RectangleGeometryLibrary.computeOptions(rectangle, rectangleGeometry._granularity, rectangleGeometry._rotation, 0, rectangleScratch, nwScratch);
  307. var geometry;
  308. var boundingSphere;
  309. if ((_Math.CesiumMath.equalsEpsilon(rectangle.north, rectangle.south, _Math.CesiumMath.EPSILON10) ||
  310. (_Math.CesiumMath.equalsEpsilon(rectangle.east, rectangle.west, _Math.CesiumMath.EPSILON10)))) {
  311. return undefined;
  312. }
  313. var surfaceHeight = rectangleGeometry._surfaceHeight;
  314. var extrudedHeight = rectangleGeometry._extrudedHeight;
  315. var extrude = !_Math.CesiumMath.equalsEpsilon(surfaceHeight, extrudedHeight, 0, _Math.CesiumMath.EPSILON2);
  316. var offsetValue;
  317. if (extrude) {
  318. geometry = constructExtrudedRectangle(rectangleGeometry, computedOptions);
  319. if (defined.defined(rectangleGeometry._offsetAttribute)) {
  320. var size = geometry.attributes.position.values.length / 3;
  321. var offsetAttribute = new Uint8Array(size);
  322. if (rectangleGeometry._offsetAttribute === GeometryOffsetAttribute.GeometryOffsetAttribute.TOP) {
  323. offsetAttribute = GeometryOffsetAttribute.arrayFill(offsetAttribute, 1, 0, size / 2);
  324. } else {
  325. offsetValue = rectangleGeometry._offsetAttribute === GeometryOffsetAttribute.GeometryOffsetAttribute.NONE ? 0 : 1;
  326. offsetAttribute = GeometryOffsetAttribute.arrayFill(offsetAttribute, offsetValue);
  327. }
  328. geometry.attributes.applyOffset = new GeometryAttribute.GeometryAttribute({
  329. componentDatatype : ComponentDatatype.ComponentDatatype.UNSIGNED_BYTE,
  330. componentsPerAttribute : 1,
  331. values : offsetAttribute
  332. });
  333. }
  334. var topBS = Transforms.BoundingSphere.fromRectangle3D(rectangle, ellipsoid, surfaceHeight, topBoundingSphere);
  335. var bottomBS = Transforms.BoundingSphere.fromRectangle3D(rectangle, ellipsoid, extrudedHeight, bottomBoundingSphere);
  336. boundingSphere = Transforms.BoundingSphere.union(topBS, bottomBS);
  337. } else {
  338. geometry = constructRectangle(rectangleGeometry, computedOptions);
  339. geometry.attributes.position.values = PolygonPipeline.PolygonPipeline.scaleToGeodeticHeight(geometry.attributes.position.values, surfaceHeight, ellipsoid, false);
  340. if (defined.defined(rectangleGeometry._offsetAttribute)) {
  341. var length = geometry.attributes.position.values.length;
  342. var applyOffset = new Uint8Array(length / 3);
  343. offsetValue = rectangleGeometry._offsetAttribute === GeometryOffsetAttribute.GeometryOffsetAttribute.NONE ? 0 : 1;
  344. GeometryOffsetAttribute.arrayFill(applyOffset, offsetValue);
  345. geometry.attributes.applyOffset = new GeometryAttribute.GeometryAttribute({
  346. componentDatatype : ComponentDatatype.ComponentDatatype.UNSIGNED_BYTE,
  347. componentsPerAttribute : 1,
  348. values : applyOffset
  349. });
  350. }
  351. boundingSphere = Transforms.BoundingSphere.fromRectangle3D(rectangle, ellipsoid, surfaceHeight);
  352. }
  353. return new GeometryAttribute.Geometry({
  354. attributes : geometry.attributes,
  355. indices : geometry.indices,
  356. primitiveType : GeometryAttribute.PrimitiveType.LINES,
  357. boundingSphere : boundingSphere,
  358. offsetAttribute : rectangleGeometry._offsetAttribute
  359. });
  360. };
  361. function createRectangleOutlineGeometry(rectangleGeometry, offset) {
  362. if (defined.defined(offset)) {
  363. rectangleGeometry = RectangleOutlineGeometry.unpack(rectangleGeometry, offset);
  364. }
  365. rectangleGeometry._ellipsoid = Cartesian2.Ellipsoid.clone(rectangleGeometry._ellipsoid);
  366. rectangleGeometry._rectangle = Cartesian2.Rectangle.clone(rectangleGeometry._rectangle);
  367. return RectangleOutlineGeometry.createGeometry(rectangleGeometry);
  368. }
  369. return createRectangleOutlineGeometry;
  370. });