GSoC/Ogre3D Detecting outside faces of a mesh · 2013. 5. 29. · Algorithm overview Needs two...

20
GSoC/Ogre3D Detecting outside faces of a mesh Student: Peter Szücs Mentor: Murat Sari

Transcript of GSoC/Ogre3D Detecting outside faces of a mesh · 2013. 5. 29. · Algorithm overview Needs two...

Page 1: GSoC/Ogre3D Detecting outside faces of a mesh · 2013. 5. 29. · Algorithm overview Needs two passes: 1. pass: Calculate convex hull. (Fact: Convex hull vertices are outside) 2.

GSoC/Ogre3D Detecting outside faces of a mesh

Student: Peter Szücs

Mentor: Murat Sari

Page 2: GSoC/Ogre3D Detecting outside faces of a mesh · 2013. 5. 29. · Algorithm overview Needs two passes: 1. pass: Calculate convex hull. (Fact: Convex hull vertices are outside) 2.

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.

Page 3: GSoC/Ogre3D Detecting outside faces of a mesh · 2013. 5. 29. · Algorithm overview Needs two passes: 1. pass: Calculate convex hull. (Fact: Convex hull vertices are outside) 2.

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.

Page 4: GSoC/Ogre3D Detecting outside faces of a mesh · 2013. 5. 29. · Algorithm overview Needs two passes: 1. pass: Calculate convex hull. (Fact: Convex hull vertices are outside) 2.

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).

Page 5: GSoC/Ogre3D Detecting outside faces of a mesh · 2013. 5. 29. · Algorithm overview Needs two passes: 1. pass: Calculate convex hull. (Fact: Convex hull vertices are outside) 2.

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)

Page 6: GSoC/Ogre3D Detecting outside faces of a mesh · 2013. 5. 29. · Algorithm overview Needs two passes: 1. pass: Calculate convex hull. (Fact: Convex hull vertices are outside) 2.

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.

Page 8: GSoC/Ogre3D Detecting outside faces of a mesh · 2013. 5. 29. · Algorithm overview Needs two passes: 1. pass: Calculate convex hull. (Fact: Convex hull vertices are outside) 2.

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.

Page 9: GSoC/Ogre3D Detecting outside faces of a mesh · 2013. 5. 29. · Algorithm overview Needs two passes: 1. pass: Calculate convex hull. (Fact: Convex hull vertices are outside) 2.

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

Page 11: GSoC/Ogre3D Detecting outside faces of a mesh · 2013. 5. 29. · Algorithm overview Needs two passes: 1. pass: Calculate convex hull. (Fact: Convex hull vertices are outside) 2.

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.

Page 12: GSoC/Ogre3D Detecting outside faces of a mesh · 2013. 5. 29. · Algorithm overview Needs two passes: 1. pass: Calculate convex hull. (Fact: Convex hull vertices are outside) 2.

Face marking pass example

1. Mesh input 2. Compute Convex hull 3. Compute normals

Page 13: GSoC/Ogre3D Detecting outside faces of a mesh · 2013. 5. 29. · Algorithm overview Needs two passes: 1. pass: Calculate convex hull. (Fact: Convex hull vertices are outside) 2.

Face marking pass example

P1

P2

• Create a stack and add vertices of CH face.

Page 14: GSoC/Ogre3D Detecting outside faces of a mesh · 2013. 5. 29. · Algorithm overview Needs two passes: 1. pass: Calculate convex hull. (Fact: Convex hull vertices are outside) 2.

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.

Page 15: GSoC/Ogre3D Detecting outside faces of a mesh · 2013. 5. 29. · Algorithm overview Needs two passes: 1. pass: Calculate convex hull. (Fact: Convex hull vertices are outside) 2.

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

Page 16: GSoC/Ogre3D Detecting outside faces of a mesh · 2013. 5. 29. · Algorithm overview Needs two passes: 1. pass: Calculate convex hull. (Fact: Convex hull vertices are outside) 2.

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.

Page 17: GSoC/Ogre3D Detecting outside faces of a mesh · 2013. 5. 29. · Algorithm overview Needs two passes: 1. pass: Calculate convex hull. (Fact: Convex hull vertices are outside) 2.

Face marking pass example

• Continue the algorithm until stack is empty

• Process it on every CH face.

Page 18: GSoC/Ogre3D Detecting outside faces of a mesh · 2013. 5. 29. · Algorithm overview Needs two passes: 1. pass: Calculate convex hull. (Fact: Convex hull vertices are outside) 2.

Prototype

Features:

• Show hull in transparent blue. (Works without threads only)

• Set outsie weight.

• Set walk angle (missing). Fixed to 90°

Page 19: GSoC/Ogre3D Detecting outside faces of a mesh · 2013. 5. 29. · Algorithm overview Needs two passes: 1. pass: Calculate convex hull. (Fact: Convex hull vertices are outside) 2.

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.