开发者

Mesh smoothing with Gaussian

开发者 https://www.devze.com 2022-12-21 05:32 出处:网络
I wish to smooth a given 3D mesh, which uses the Half-Edge structure to store adjacency information, using a Gaussian function. The following is the algorithm that was proposed:

I wish to smooth a given 3D mesh, which uses the Half-Edge structure to store adjacency information, using a Gaussian function. The following is the algorithm that was proposed:

Smooth the mesh by moving every vertex to a position determined by a weighted average of its immediate neighbors (with weights determined by a Gaussian with sigma equal to the average length of edges attached to the vertex, normalized such that the weights sum to one).

So for each vertex curr_vertex, I

  1. calculate the average length of its attached edges
  2. obtain all of the neighboring vertices
  3. 开发者_运维知识库
  4. determine the weight of each neighboring vertex by doing the following: `

weight = exp(-(distance*distance)/(2.sigmasigma))

where distance is the 3D distance between thecurr_vertexand the neighbor andsigma= average length of attached edges ofcurr_vertex`

  1. sum up all of the weights and divide each neighbor's weight by this sum (normalization step)
  2. multiply the position of each neighboring vertex by its corresponding weight
  3. add up all of the weighted vertices and add the result to curr_vertex to produce the new vertex.

When I do this and run my algorithm, instead of smoothing what actually happens is a scale - my mesh just becomes enlarged without any apparent smoothing.

Any thoughts on what I'm doing wrong?

Edit: Here's the code that I have:

void R3Mesh::
Smooth(void)
{
  R3Mesh *new_mesh = new R3Mesh(*this);
  for(int i = 0; i < NVertices(); i++)
  {
    R3MeshVertex *v = Vertex(i);
    map<R3MeshVertex *, double> neighbors; // stores vertex-weight pairs 
    map<R3MeshVertex *, double>::iterator neighbors_iter;

    // store each vertex neighbor by going through
    // all adjacent edges and obtaining those edges' vertices
    R3MeshHalfEdge *tmp = v->half_edge;
    do
    {
      neighbors.insert(make_pair(tmp->opposite->vertex,0));
      tmp = tmp->opposite->next;
    }while(tmp != v->half_edge);

    // determine the sigma to use for Gaussian
    double sigma = v->AverageEdgeLength();
    double weight = 0, total_weight = 0;
    double distance;

    // determine and store the weight of each neighboring vertex
    for(neighbors_iter = neighbors.begin(); neighbors_iter != neighbors.end();
        neighbors_iter++)
    {
      distance = R3Distance(v->position, neighbors_iter->first->position);
      weight = (1./(sigma*sqrt(2.*3.14)))*exp(-(distance*distance)/(2.*sigma*sigma));
      total_weight += weight;
      neighbors_iter->second = weight;
    }

    // determine new position of current vertex
    R3Point new_pos = v->position;
    for(neighbors_iter = neighbors.begin(); neighbors_iter != neighbors.end();
        neighbors_iter++)
    {
      new_pos += (neighbors_iter->second/total_weight)*(neighbors_iter->first->position);
    }

    new_pos.Translate(new_pos - v->position);
    new_mesh->Vertex(i)->position.Reset(new_pos.X(), new_pos.Y(), new_pos.Z());

    neighbors.clear();
  }



  *this = *new_mesh;
}


This smacks of a head-slapping typo style bug. The algorithm as you described looks fine to me.

First clearly verify the normalization of the weights.

Next check your code where you write back the calculated vertex pos into the new smoothed mesh.

Those are my guesses. Feel free to post a code snippet if those don't work.

0

精彩评论

暂无评论...
验证码 换一张
取 消