/*! Subdivides the face at faceindex into a vector of faces
*/
std::vector< std::vector<Vector3<float> > > LoopSubdivisionMesh::Subdivide(unsigned int faceIndex)
{
  std::vector< std::vector<Vector3<float> > > faces;
  EdgeIterator eit = GetEdgeIterator( f(faceIndex).edge );

  // get the inner halfedges
  unsigned int e0, e1, e2;
  // and their vertex indices
  unsigned int v0, v1, v2;

  e0 = eit.GetEdgeIndex();
  v0 = eit.GetEdgeVertexIndex();
  eit.Next();
  e1 = eit.GetEdgeIndex();
  v1 = eit.GetEdgeVertexIndex();
  eit.Next();
  e2 = eit.GetEdgeIndex();
  v2 = eit.GetEdgeVertexIndex();

  // Compute positions of the vertices
  Vector3<float> pn0 = VertexRule(v0);
  Vector3<float> pn1 = VertexRule(v1);
  Vector3<float> pn2 = VertexRule(v2);

  // Compute positions of the edge vertices
  Vector3<float> pn3 = EdgeRule(e0);
  Vector3<float> pn4 = EdgeRule(e1);
  Vector3<float> pn5 = EdgeRule(e2);

  // add the four new triangles to new mesh
  std::vector<Vector3<float> > verts;
  verts.push_back(pn0); verts.push_back(pn3); verts.push_back(pn5);
  faces.push_back(verts);
  verts.clear();
  verts.push_back(pn3); verts.push_back(pn4); verts.push_back(pn5);
  faces.push_back(verts);
  verts.clear();
  verts.push_back(pn3); verts.push_back(pn1); verts.push_back(pn4);
  faces.push_back(verts);
  verts.clear();
  verts.push_back(pn5); verts.push_back(pn4); verts.push_back(pn2);
  faces.push_back(verts);
  return faces;
}
Esempio n. 2
0
float HalfEdgeMesh::FaceCurvature(unsigned int faceIndex) const
{
  // NB Assumes vertex curvature already computed
  unsigned int indx = f(faceIndex).edge;
  const EdgeIterator it = GetEdgeIterator(indx);

  const Vertex& v1 = v(it.GetEdgeVertexIndex());
  const Vertex &v2 = v(it.Next().GetEdgeVertexIndex());
  const Vertex &v3 = v(it.Next().GetEdgeVertexIndex());

  return (v1.curvature + v2.curvature + v3.curvature) / 3.f;
}
/*! Subdivides the face at faceIndex given 3 not subdividable neighbors
  or if subdividable for this face is false
*/
std::vector< std::vector<Vector3<float> > >
AdaptiveLoopSubdivisionMesh::Subdivide3(unsigned int faceIndex){

  EdgeIterator eit = GetEdgeIterator( f(faceIndex).edge );
  Vector3<float> v1 = VertexRule(eit.GetEdgeVertexIndex());
  Vector3<float> v2 = VertexRule(eit.Next().GetEdgeVertexIndex());
  Vector3<float> v3 = VertexRule(eit.Next().GetEdgeVertexIndex());
  std::vector<Vector3<float> > face;
  face.push_back(v1); face.push_back(v2); face.push_back(v3);
  std::vector< std::vector<Vector3<float> > > faces;
  faces.push_back(face);
  return faces;
}
Esempio n. 4
0
Vector3<float> HalfEdgeMesh::FaceNormal(unsigned int faceIndex) const
{
  unsigned int indx = f(faceIndex).edge;
  const EdgeIterator it = GetEdgeIterator(indx);

  const Vector3<float> &p1 = v(it.GetEdgeVertexIndex()).pos;
  const Vector3<float> &p2 = v(it.Next().GetEdgeVertexIndex()).pos;
  const Vector3<float> &p3 = v(it.Next().GetEdgeVertexIndex()).pos;

  const Vector3<float> e1 = p2-p1;
  const Vector3<float> e2 = p3-p1;
  return Cross(e1, e2).Normalize();
}
/*! Subdivides the face at faceIndex given 2 not subdividable neighbors
 */
std::vector< std::vector<Vector3<float> > >
AdaptiveLoopSubdivisionMesh::Subdivide2(unsigned int faceIndex){

  // We know we have otwo false faces

  // 1. Start by orienting the triangle so that we always have the same case
  // We find the start edge as the edge who shares face with the _subdividable_ neighbor
  EdgeIterator eit = GetEdgeIterator( f(faceIndex).edge );
  unsigned int num = 0;
  while( !Subdividable(eit.Pair().GetEdgeFaceIndex()) ){
    eit.Pair().Next();
    assert(num++ < 3);
  }
  // go back to inner edge
  eit.Pair();

  // 2. Now find the vertices
  std::vector< std::vector<Vector3<float> > > faces;

  // corner vertices, labeled from current edge's origin vertex
  Vector3<float> v1 = VertexRule(eit.GetEdgeVertexIndex());
  Vector3<float> v2 = VertexRule(eit.Next().GetEdgeVertexIndex());
  Vector3<float> v3 = VertexRule(eit.Next().GetEdgeVertexIndex());

  // edge vertices, labeled from start edge
  Vector3<float> e1v = EdgeRule( eit.Next().GetEdgeIndex() );

  // 3. Create the 2 faces and push them on the vector
  std::vector<Vector3<float> > face;
  face.push_back(v1); face.push_back(e1v); face.push_back(v3);
  faces.push_back(face);
  face.clear();

  face.push_back(e1v); face.push_back(v2); face.push_back(v3);
  faces.push_back(face);
  face.clear();

  // 4. Return
  return faces;
}