Skip to Content.
Sympa Menu

cgal-discuss - Re: [cgal-discuss] Mesh Simplification

Subject: CGAL users discussion list

List archive

Re: [cgal-discuss] Mesh Simplification


Chronological Thread 
  • From: "ZhiQuan Cheng" <>
  • To: ,
  • Subject: Re: [cgal-discuss] Mesh Simplification
  • Date: Wed, 19 Dec 2007 10:26:22 +0800
  • Domainkey-signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=message-id:date:from:to:subject:in-reply-to:mime-version:content-type:references; b=OataIogZoGkmptafNNezE4Fgvw8ap1FiNqhzLyFhLXDQaiygrQPzzzYZEbXzlYKs5Lg4Aumlzd7RYgT4DP2isFWOKAc3y18FisWFHTWxviFvKOvgUgOtxYAbANUMMqo7AJFQQQe6QfMMWT7Gxym3Al+Xtel7b6QP9PAP/EZHNjw=

Dear Xue-Tao.
   Our team has tested the simplified process of CGAL under visual studio 2005 with OpenGL glut3.7 display. The appendix has included one pre-released platform source codes.
   Best regards.
And the related codes of simplifer visitor are listed as follows:.
  

#include "../Enriched_polyhedron.h"

#include "HalfedgeGraph_Enriched_polyhedron.h"

#include <CGAL/Surface_mesh_simplification/edge_collapse.h>

#include <CGAL/Surface_mesh_simplification/Policies/Edge_collapse/Count_ratio_stop_predicate.h>

#include <CGAL/Surface_mesh_simplification/Policies/Edge_collapse/Midpoint_and_length.h>

#include "../../../MeshStudioDoc.h"

namespace SMS = CGAL::Surface_mesh_simplification;

 

// The following is a Visitor that keeps track of the simplification process.
// In this example the progress is printed real-time and a few statistics are
// recorded (and printed in the end).
//
template <class Polyhedron, class Kernel>
struct Visitor
{
  typedef SMS::Edge_profile<Polyhedron> Profile;
  typedef typename Kernel::Point_3 Point;

  Visitor(CMeshStudioDoc *pDoc)
    : collected(0)
    , processed(0)
    , collapsed(0)
    , non_collapsable(0)
    , cost_uncomputable(0)
    , placement_uncomputable(0)
 , m_pDoc(pDoc)
  {}

  // Called on algorithm entry 
  void OnStarted( Polyhedron& ) {}
 
  // Called on algorithm exit 
  void OnFinished ( Polyhedron& ) {}
 
  // Called when the stop condition returned true
  void OnStopConditionReached( Profile const& ) {}
 
  // Called during the collecting phase for each edge collected.
  void OnCollected( Profile const&, boost::optional<double> const& )
  {
   if (m_pDoc == NULL)
    return;
    ++collected;
 m_pDoc->StatusMessage("Simplification: edges collected: %d", collected);
  }               
 
  // Called during the processing phase for each edge selected.
  // If cost is absent the edge won't be collapsed.
  void OnSelected(Profile const&         
                 ,boost::optional<double> cost
                 ,std::size_t             initial
                 ,std::size_t             current
                 )
  {
   if (m_pDoc == NULL)
    return;
    ++ processed ;
    if ( !cost )
      ++ cost_uncomputable ;
     
    if ( current == initial )
      std::cerr << "\n" << std::flush;
  //  std::cerr << "\r" << current << std::flush ;
 m_pDoc->StatusMessage("Simplification: current edges: %d", current);
  }               
 
  // Called during the processing phase for each edge being collapsed.
  // If placement is absent the edge is left uncollapsed.
  void OnCollapsing(Profile const&         
                   ,boost::optional<Point>  placement
                   )
  {
   if (m_pDoc == NULL)
    return;
    if ( placement )
         ++ collapsed;
    else ++ placement_uncomputable ;
  }               
 
  // Called for each edge which failed the so called link-condition,
  // that is, which cannot be collapsed because doing so would
  // turn the surface into a non-manifold.
  void OnNonCollapsable( Profile const& )
  {
   if (m_pDoc == NULL)
    return;
    ++ non_collapsable;
  }               
 
  std::size_t  collected
             , processed
             , collapsed
             , non_collapsable
             , cost_uncomputable 
             , placement_uncomputable;
  CMeshStudioDoc *m_pDoc;
};

template <class Polyhedron, class Kernel>
class CSimplifier
{
 typedef typename Kernel::FT FT;

private:
 // data
 Polyhedron *m_pMesh;

public:
 // life cycle
 CSimplifier(Polyhedron *pMesh)
 {
  m_pMesh = pMesh;
 }
 ~CSimplifier() {}

 void run(FT ratio_stop=0.1, CMeshStudioDoc *pDoc=NULL)
 {
  Visitor<Polyhedron, Kernel> vis(pDoc);
  if (!m_pMesh->is_set_items_id()) {
   m_pMesh->set_hds_items_id();
  }
  // The simplification stops when the number of undirected edges
  // drops below 10% of the initial count
  SMS::Count_ratio_stop_predicate<Polyhedron> stop(ratio_stop);
  SMS::edge_collapse(*m_pMesh,
       stop,
       CGAL::get_cost(SMS::Edge_length_cost<Polyhedron>())
        .get_placement(SMS::Midpoint_placement<Polyhedron>())
        .visitor(&vis)
       );
 }
};

  


 
2007/12/14, Yin Xuetao <>:
Hi, Guys
 
I am making a small application to do mesh simplification using Edge_Collapse template in CGAL.
 
Somehow, i need to access the vertex that is kept in the mesh after one edge is collapsed.
Is there a neat way to get that "vertex_descriptor" information?
 
I am thinking of adding a function OnCollapsed(vertex_descriptor & ) to the Visitor,  can someone point to me the right way to do so?
 
Thanks a lot!
 
Have a nice day!

--
Xuetao Yin
(Shu-e-tao)



--
--
Yours Sincerely
Zhi-Quan Cheng
http://zhiquan.cheng.googlepages.com

Attachment: MeshStudio07-11-20.rar
Description: Binary data



  • Mesh Simplification, Yin Xuetao, 12/14/2007
    • Re: [cgal-discuss] Mesh Simplification, ZhiQuan Cheng, 12/19/2007

Archive powered by MHonArc 2.6.16.

Top of Page