GSoC/Ogre3D Detecting outside faces of a mesh · 2013. 5. 29. · Algorithm overview Needs two...
Transcript of GSoC/Ogre3D Detecting outside faces of a mesh · 2013. 5. 29. · Algorithm overview Needs two...
GSoC/Ogre3D Detecting outside faces of a mesh
Student: Peter Szücs
Mentor: Murat Sari
Input, output, requirements • Input: A mesh, that can contain everything! However
the algorithm is only usefull on meshes, which has internal faces. • Output: List of marked vertices, which are visible from outside. • Visible face = all three vertices are marked. • Requirements: Performance vs approximation quality? • The algorithm is only approximating the outside and it may miss
some visible parts. • Solution: I don’t have found any algorithm for this problem.
So I have written my own technique explained in this slide.
Algorithm overview Needs two passes: 1. pass: Calculate convex hull. (Fact: Convex hull vertices are outside) 2. pass: Walk/mark faces. (Convex hull misses lot of vertices, so find them) Image description: • Blue points: goal is to mark these points. • Red faces: Convex hull faces. • Red arrow: Normals of convex hull. • Black faces: faces of the mesh. • Black arrow: Normals of mesh faces.
What is Convex Hull?
• http://en.wikipedia.org/wiki/Convex_hull
• Input: Set of points.
• Output: A shape which contains all points with minimal volume.
• The shape is convex (obviously).
Convex hull algorithms • http://en.wikipedia.org/wiki/Convex_hull_algorithms • n = vertices in mesh • h = vertices in hull • Problem: Handling 4 vertices on the same plane. Algorithms: • Gift wrapping: O(nh) • Graham’s scan: O(n log n) • Chan’s algorithm: O(n log h) • Incremental: O(n log n) • Quick hull: O(n log n)
Convex hull algorithms: Gift wrapping (Jarvis march) Applet:http://www.cs.princeton.edu/courses/archive/spr09/cos226/demo/ah/JarvisMarch.html • Complexity: O(nh) 1. Take minx point with y dirvector. 2. Find point with smallest angle
to the dirvector and add to hull. 3. Continue, until you get back to
start point.
Convex hull algorithms: Graham’s scan Applet:http://www.cs.princeton.edu/courses/archive/spr10/cos226/demo/ah/GrahamScan.html • Complexity: O(n log n) 1. Select minx point 2. Calculate angles from minx to all points. 3. Sort angles. O(n log n) 4. Walk the angles while looking for
concave turns. 5. Remove previous point from hull on
concave turn.
Convex hull algorithms: Chan’s algorithm
• Complexity: O(n log h)
• Runs Graham’s scan on h partitions.
• Combines partitions with Gift wrapping.
• NOTE: You need to approximate h (hull vertex count) to get O(n log h) complexity.
Convex hull algorithms: Incremental
• Applet:http://www.cse.unsw.edu.au/~lambert/java/3d/
• Complexity: O(n log n)
1. Start: Determine a Tetrahedron with extreme points.
2. Select random vertex.
3. Find faces visible from that vertex.
4. If not found the vertex is inside hull and ignored
5. If found remove them and create new faces including that vertex into the hull
Convex hull algorithms: QuickHull
Applet:http://www.cse.yorku.ca/~aaw/Hang/quick_hull/QuickHull.html
• Complexity: O(n log n)
• Same as Incremental except some improvements:
– You always select furthest away vertex of a hull face.
– You only check face visibility of the face and its neighbors.
Face marking pass
• For each Convex hull (CH) face: – Compute CH face normal vector.
– Create a stack and add vertices of the face.
– While stack is not empty process/pop vertices: • Mark every vertex on stack as being visible.
• Find neighbor faces, which has less then 90° difference to CH normal vector.
• Add the points of these faces to the stack.
Face marking pass example
1. Mesh input 2. Compute Convex hull 3. Compute normals
Face marking pass example
P1
P2
• Create a stack and add vertices of CH face.
Face marking pass example
P2
P3
• Find P1 neighbor faces, which has less then 90° difference to
CH normal vector.
• P1-P3 face:
– 30° < 90°
– Add P3 to stack.
Face marking pass example
P2
P3
• Find P1 neighbor faces, which has less then 90° difference to
CH normal vector.
• P1-P4 face:
– 1° < 90°
– Add P4 to stack. P4
Face marking pass example
P3
P4
• Find P2 neighbor faces, which has less then 90° difference to
CH normal vector.
• P2-P3 face: Skip
• P2-P5 face:
– 91° > 90°
– Ignore P5.
Face marking pass example
• Continue the algorithm until stack is empty
• Process it on every CH face.
Prototype
Features:
• Show hull in transparent blue. (Works without threads only)
• Set outsie weight.
• Set walk angle (missing). Fixed to 90°
Improvements: Cast rays
1. Create a list of points of a geosphere.
2. Generate an Octree of the mesh and CH.
3. Cast rays from geosphere towards CH centroid point.
4. Ray will collide with a CH face and a mesh face.
5. Walk on mesh face compared to CH face normal vector.
More information
• Convex hull and geometry algorithms: http://www.cs.umd.edu/~mount/754/Lects/754lects.pdf
• Development topic: http://www.ogre3d.org/forums/viewtopic.php?f=13&t=77319