janba / GEL

A library of geometry processing tools for computer graphics
95 stars 23 forks source link

Smooth.cpp : TAL_smoothing . NaN issue with overlapping vertices #33

Closed RasmusRPaulsen closed 4 years ago

RasmusRPaulsen commented 4 years ago
                    {
                        Vec3d vec_a = normalize(m.pos(w.vertex()) - m.pos(*vid));
                        Vec3d vec_b = normalize(m.pos(w.circulate_vertex_ccw().vertex()) -
                                                m.pos(*vid));
                        angle_sum += acos(max(-1.0,min(1.0,dot(vec_a,vec_b))));
                    }

Behaves very badly if there are overlapping vertices. It happens in normalize that assumes a non-zero distance between vertices.

Since this is an iterative smoothing process, overlapping vertices DO happen from time to time.

A solution is: { Vec3d vec_a = m.pos(w.vertex()) - m.pos(vid); Vec3d vec_b = m.pos(w.circulate_vertex_ccw().vertex()) - m.pos(vid); if (vec_a.length() && vec_b.length()) { vec_a = normalize(vec_a ); vec_b = normalize(vec_b); angle_sum += acos(max(-1.0, min(1.0, dot(vec_a, vec_b)))); } }

janba commented 4 years ago

TAL_smoothing was a terrible, terrible function. It used cotangent weights which is probably not a good idea since these weights are for smoothing geometry without smoothing the parametrisation (too much), but tangential area weighted laplacian smoothing is used to smooth the parametrisation while not changing the geometry too much. It also looked like the tangential part was missing ...

I have changed the function in the following way:

image image image

I am making some additions to GEL to make it possible to use range based for loops instead of circulation to get the neighbours of vertices and faces. This function will be part of the update coming later today.