Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Polygonidl #720

Merged
merged 49 commits into from
May 7, 2013
Merged
Show file tree
Hide file tree
Changes from 40 commits
Commits
Show all changes
49 commits
Select commit Hold shift + click to select a range
ce3bb4e
First cut of triangle plane test.
pjcozzi Jul 14, 2012
499da4f
Made line segment plane intersection test private
pjcozzi Jul 14, 2012
a57c0bb
Added Plane type
pjcozzi Jul 14, 2012
1779db8
Added Plane type and triangle-plane test to CHANGES.md.
pjcozzi Jul 14, 2012
2ef3f70
Use Plane instead of separate normal and d
pjcozzi Jul 14, 2012
553e45b
Merge branch 'polygonidl' of github.com:AnalyticalGraphicsInc/cesium …
pjcozzi Jul 14, 2012
ddebb2d
Added tests for exceptions
pjcozzi Jul 14, 2012
55bf30e
First cut of PolygonPipeline.wrapLongitude. Does not work yet.
pjcozzi Jul 15, 2012
97cfe50
Merged master into polygonidl
pjcozzi Jul 19, 2012
dc54e69
Merge master into polygonidl. The time to run the tests almost went …
pjcozzi Jul 29, 2012
1437541
Merged master into polygonidl
pjcozzi Aug 1, 2012
41df010
Merged master into polygonidl
pjcozzi Aug 2, 2012
eaaee87
Merged master into polygonidl
pjcozzi Aug 2, 2012
84b5a25
Merged master into polygonidl
pjcozzi Aug 23, 2012
1a82ec5
Fixed polygon tests
pjcozzi Aug 23, 2012
62dc7ec
Merge master to polygonidl
pjcozzi Aug 29, 2012
2046355
Merged master into polygonidl
pjcozzi Sep 4, 2012
72019c5
Merged master into polygonidl
pjcozzi Sep 27, 2012
604eb10
Updates after merge
pjcozzi Sep 27, 2012
9a91e5f
Merge branch 'master' into polygonidl
pjcozzi Sep 28, 2012
8a72ddd
Merged master to polygonidl
pjcozzi Oct 21, 2012
1b1f945
Merge branch 'polygonidl' of github.com:AnalyticalGraphicsInc/cesium …
pjcozzi Oct 21, 2012
b387eee
Merged master into polygonidl
pjcozzi Nov 8, 2012
e45eae3
Merge branch 'master' into polygonidl
bagnell Feb 6, 2013
9a5e145
Merge branch 'plane' into polygonidl
bagnell Feb 6, 2013
1438d9b
Update code after merge.
bagnell Feb 6, 2013
5eb53e5
Merge remote-tracking branch 'origin/master' into polygonidl
pjcozzi Feb 9, 2013
0b60e0b
Merge branch 'master' into polygonidl
pjcozzi Feb 15, 2013
9debf43
Merge remote-tracking branch 'origin/master' into polygonidl
pjcozzi Feb 16, 2013
ccc6eaf
Merged master to polygonidl
pjcozzi Mar 5, 2013
da9adc0
Merged master to polygonidl
pjcozzi Mar 11, 2013
f063d96
Merge remote-tracking branch 'origin/master' into polygonidl
pjcozzi Apr 15, 2013
8708500
Merge remote-tracking branch 'origin/master' into polygonidl
pjcozzi Apr 19, 2013
5455333
Merge master to polygonidl
pjcozzi Apr 26, 2013
fe52dcb
offset new triangles away from IDL
Apr 29, 2013
78420ba
variable cleanup
Apr 29, 2013
956052a
Check if bounding sphere intersects with IDL
Apr 29, 2013
8299faa
catch case of 2 points of triangle being at the the intersection with…
Apr 29, 2013
51958a7
Merge remote-tracking branch 'agi/master' into polygonidl
Apr 30, 2013
2413324
added IDL specific triangle plane intersection test.
Apr 30, 2013
fce825c
cleaned up documentation and comments
Apr 30, 2013
cd33da6
Merge branch 'master' into polygonidl
May 1, 2013
3a7d363
Merge branch 'master' into polygonidl
May 6, 2013
7843283
fixed documentation
May 6, 2013
eaf79f2
fixed documentation
May 6, 2013
d997fbb
consolidated slice triangle function into wrapLongitude
May 6, 2013
ccc4723
removed unused requires
May 6, 2013
06a7a4e
calculate bounding sphere before creating mesh
May 7, 2013
3486a02
Merge branch 'master' into polygonidl
May 7, 2013
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,10 @@ Beta Releases
* Fixed an error in Web Worker creation when loading Cesium.js from a different origin.
* Fixed `EllipsoidPrimitive` picking and picking objects with materials that have transparent parts.

### TODO
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These changes should be moved up to the b16 section.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove this section and move it to b16 (that's hoping we merge it quickly, of course).

Also add a note that we fixed the polygon International Dateline in 2D and Columbus view.


* Added `IntersectionTests.trianglePlaneIntersection`.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry, we should move these to a new section for b17 since b16 is already done.


### b15 - 2013-04-01

* Breaking changes:
Expand Down
2 changes: 1 addition & 1 deletion Source/Core/EllipsoidTangentPlane.js
Original file line number Diff line number Diff line change
Expand Up @@ -208,4 +208,4 @@ define([
};

return EllipsoidTangentPlane;
});
});
282 changes: 282 additions & 0 deletions Source/Core/IntersectionTests.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,13 @@ define([
QuarticRealPolynomial) {
"use strict";

// TODO
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These are TODOs I had from a while back.

// equals, etc. for Plane?
// Should ray constructor normalize?
// Make EllipsoidTangentPlane contain plane?

Nah.

// Does extent triangulator work over IDL?

Please test this, but if it doesn't work in 2D or Columbus view, write an issue. It doesn't need to holdup this pull request.

// Tests for new wrapLongitude.

Please add them. Even though the polygon tests it indirectly, we want to have specific tests.

// equals, etc. for Plane?
// Should ray constructor normalize?
// Make EllipsoidTangentPlane contain plane?
// Does extent triangulator work over IDL?
// Tests for new wrapLongitude.

/**
* DOC_TBA
*
Expand Down Expand Up @@ -418,5 +425,280 @@ define([
return result;
};

/**
* Computes the intersection of a triangle and a plane
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you mind adding an @example? Also, it it is a good idea to build the doc and make sure everything shows up OK.

* @memberof IntersectionTests
*
* @param {Cartesian3} p0 First point of the triangle
* @param {Cartesian3} p1 Second point of the triangle
* @param {Cartesian3} p2 Third point of the triangle
* @param {Plane} plane Intersection plane
*
* @returns Three triangles that do not cross the plane. (Undefined if no intersection exists)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The return type is missing.

*
* @exception {DeveloperError} p0, p1, p2, and plane are required.
*/
IntersectionTests.trianglePlaneIntersection = function(p0, p1, p2, plane) {
if ((typeof p0 === 'undefined') ||
(typeof p1 === 'undefined') ||
(typeof p2 === 'undefined') ||
(typeof plane === 'undefined')) {
throw new DeveloperError('p0, p1, p2, and plane are required.');
}

// TODO: returning triangle strips or fans?
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can remove this.

var planeNormal = plane.normal;
var planeD = plane.distance;
var p0Behind = (Cartesian3.dot(planeNormal, p0) + planeD) < 0.0;
var p1Behind = (Cartesian3.dot(planeNormal, p1) + planeD) < 0.0;
var p2Behind = (Cartesian3.dot(planeNormal, p2) + planeD) < 0.0;
// Given these dots products, the calls to lineSegmentPlaneIntersection
// always have defined results.

var numBehind = 0;
numBehind += p0Behind ? 1 : 0;
numBehind += p1Behind ? 1 : 0;
numBehind += p2Behind ? 1 : 0;

var u1, u2;
if (numBehind === 1 || numBehind === 2) {
u1 = new Cartesian3();
u2 = new Cartesian3();
}

if (numBehind === 1) {
if (p0Behind) {
IntersectionTests.lineSegmentPlane(p0, p1, plane, u1);
IntersectionTests.lineSegmentPlane(p0, p2, plane, u2);

return {
positions : [p0, p1, p2, u1, u2 ],
indices : [
// Behind
0, 3, 4,

// In front
1, 2, 4,
1, 4, 3
]
};
} else if (p1Behind) {
IntersectionTests.lineSegmentPlane(p1, p2, plane, u1);
IntersectionTests.lineSegmentPlane(p1, p0, plane, u2);

return {
positions : [p0, p1, p2, u1, u2 ],
indices : [
// Behind
1, 3, 4,

// In front
2, 0, 4,
2, 4, 3
]
};
} else if (p2Behind) {
IntersectionTests.lineSegmentPlane(p2, p0, plane, u1);
IntersectionTests.lineSegmentPlane(p2, p1, plane, u2);

return {
positions : [p0, p1, p2, u1, u2 ],
indices : [
// Behind
2, 3, 4,

// In front
0, 1, 4,
0, 4, 3
]
};
}
} else if (numBehind === 2) {
if (!p0Behind) {
IntersectionTests.lineSegmentPlane(p1, p0, plane, u1);
IntersectionTests.lineSegmentPlane(p2, p0, plane, u2);

return {
positions : [p0, p1, p2, u1, u2 ],
indices : [
// Behind
1, 2, 4,
1, 4, 3,

// In front
0, 3, 4
]
};
} else if (!p1Behind) {
IntersectionTests.lineSegmentPlane(p2, p1, plane, u1);
IntersectionTests.lineSegmentPlane(p0, p1, plane, u2);

return {
positions : [p0, p1, p2, u1, u2 ],
indices : [
// Behind
2, 0, 4,
2, 4, 3,

// In front
1, 3, 4
]
};
} else if (!p2Behind) {
IntersectionTests.lineSegmentPlane(p0, p2, plane, u1);
IntersectionTests.lineSegmentPlane(p1, p2, plane, u2);

return {
positions : [p0, p1, p2, u1, u2 ],
indices : [
// Behind
0, 1, 4,
0, 4, 3,

// In front
2, 3, 4
]
};
}
}

// if numBehind is 3, the triangle is completely behind the plane;
// otherwise, it is completely in front (numBehind is 0).
return undefined;
};


/**
* Computes the intersection of a triangle and the XZ plane. Offsets points from the XZ plane.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add an @example.

It will also be good to add some motivation for this function compared to trianglePlaneIntersection.

* @memberof IntersectionTests
*
* @param {Cartesian3} p0 First point of triangle
* @param {Cartesian3} p1 Second point of triange
* @param {Cartesian3} p2 Third point of triange
*
* @return Three triangles that are offset from intersecting with the plane. (Undefined if no intersection found)
*
* @exception {DeveloperError} p0, p1 and p2 are required.
*/
var xz_plane = new Plane(Cartesian3.UNIT_Y, 0.0);
IntersectionTests.triangleXZPlaneIntersection = function(p0, p1, p2) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Given the use of the epsilon, this is pretty specific. This could use a new name like splitTriangleAtInternationalDateLine.

Since this is specific, it probably belongs as a file-level scope function in PolygonPipeline.js, in which case you don't have to worry about doc.

Also, when I originally wrote wrapLongitude, I think I thought that I would merge a function like this right into it or at least more tightly couple them, which would clean up the index conversion starting at

// Replace triangle that crosses the IDL with three
// triangles that do not cross.

@bagnell thoughts?

if ((typeof p0 === 'undefined') ||
(typeof p1 === 'undefined') ||
(typeof p2 === 'undefined')) {
throw new DeveloperError('p0, p1 and p2 are required.');
}

var p0Behind = p0.y < 0.0;
var p1Behind = p1.y < 0.0;
var p2Behind = p2.y < 0.0;

offsetPointFromXZPlane(p0, p0Behind);
offsetPointFromXZPlane(p1, p1Behind);
offsetPointFromXZPlane(p2, p2Behind);

var numBehind = 0;
numBehind += p0Behind ? 1 : 0;
numBehind += p1Behind ? 1 : 0;
numBehind += p2Behind ? 1 : 0;

var u1, u2, v1, v2, result;

if (numBehind === 1 || numBehind === 2) {
u1 = new Cartesian3();
u2 = new Cartesian3();
v1 = new Cartesian3();
v2 = new Cartesian3();
result = { positions : [p0, p1, p2, u1, u2, v1, v2 ] };
}

if (numBehind === 1) {
if (p0Behind) {
getXZIntersectionOffsetPoints(p0, p1, p2, u1, u2, v1, v2);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we can optimize this even more given that we are dealing with the yz plane (not xz, it is the plane, x = 0). @bagnell?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Whoops, sorry, it is the xz plane. I still think there is more we can do to optimize.

result.indices = [
// Behind
0, 3, 4,

// In front
1, 2, 6,
1, 6, 5
];
} else if (p1Behind) {
getXZIntersectionOffsetPoints(p1, p0, p2, u1, u2, v1, v2);
result.indices = [
// Behind
1, 3, 4,

// In front
2, 0, 6,
2, 6, 5
];
} else if (p2Behind) {
getXZIntersectionOffsetPoints(p2, p0, p1, u1, u2, v1, v2);
result.indices = [
// Behind
2, 3, 4,

// In front
0, 1, 6,
0, 6, 5
];
}
} else if (numBehind === 2) {
if (!p0Behind) {
getXZIntersectionOffsetPoints(p0, p1, p2, u1, u2, v1, v2);
result.indices = [
// Behind
1, 2, 4,
1, 4, 3,

// In front
0, 5, 6
];
} else if (!p1Behind) {
getXZIntersectionOffsetPoints(p1, p2, p0, u1, u2, v1, v2);
result.indices = [
// Behind
2, 0, 4,
2, 4, 3,

// In front
1, 5, 6
];
} else if (!p2Behind) {
getXZIntersectionOffsetPoints(p2, p0, p1, u1, u2, v1, v2);
result.indices = [
// Behind
0, 1, 4,
0, 4, 3,

// In front
2, 5, 6
];
}
}
return result;
};

function getXZIntersectionOffsetPoints(p, p1, p2, u1, u2, v1, v2) {
IntersectionTests.lineSegmentPlane(p, p1, xz_plane, u1);
IntersectionTests.lineSegmentPlane(p, p2, xz_plane, u2);
Cartesian3.clone(u1, v1);
Cartesian3.clone(u2, v2);
offsetPointFromXZPlane(u1, true);
offsetPointFromXZPlane(u2, true);
offsetPointFromXZPlane(v1, false);
offsetPointFromXZPlane(v2, false);
}

function offsetPointFromXZPlane(p, isBehind) {
if (Math.abs(p.y) < CesiumMath.EPSILON11){
if (isBehind) {
p.y = -CesiumMath.EPSILON11;
} else {
p.y = CesiumMath.EPSILON11;
}
}
}

return IntersectionTests;
});
2 changes: 1 addition & 1 deletion Source/Core/Plane.js
Original file line number Diff line number Diff line change
Expand Up @@ -144,4 +144,4 @@ define([
};

return Plane;
});
});
Loading