Subject: CGAL users discussion list
List archive
- From: Ramin H <>
- To:
- Subject: Re: [cgal-discuss] meshing tool
- Date: Fri, 4 Jun 2010 10:13:09 -0400
- Domainkey-signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :content-type; b=QX1Ab5NmZPfbbXKF5OziFpmZfxPtE52E/pqix3Y+EpdMlFvopNexEQo1eKiicN3d+3 ODM3WvseGq1A7GOyS13Ei87h/2kqu16tk7DEZ019IDA8vO6FbiRlQgffQtQFEV+OaPEq KDwOz1dQlXbxlVTdnKTlP+fhCfj6ZJSz2SX4A=
Hi Hansjoerg,
The following should give you an idea how this can be done ...
1. First define the following in a new header file and name it sizing_functions.h
------begin----------------------
double cell_size_function(double x, double y, double z)
{
return 1+x*x+y*y+z*z; // replace with your function
}
template <typename FT, typename Point>
class FT_to_point_function_wrapper : public std::unary_function<Point, FT>
{
typedef FT (*Implicit_function)(FT, FT, FT);
Implicit_function function;
public:
FT_to_point_function_wrapper(Implicit_function f) : function(f) {}
FT operator()(Point p) const { return function(p.x(), p.y(), p.z()); }
};
-------end---------------------
2. Look at CGAL/Mesh_3/mesh_standard_cell_criteria.h and make a new similar header file, name it mesh_my_cell_criteria.h and put your criterion there:
-------begin-------------------------------------------
template <typename Function, typename Tr, typename Visitor_>
class My_new_criterion
: public Abstract_criterion<Tr, Visitor_>
{
typedef typename Tr::Cell_handle Cell_handle;
typedef typename Tr::Geom_traits::FT FT;
typedef Abstract_criterion<Tr, Visitor_> Base;
typedef typename Base::Quality Quality;
typedef typename Base::Badness Badness;
typedef My_new_criterion<Function,Tr, Visitor_> Self;
public:
// Constructor
My_new_criterion(const Function& f) : my_sizing_func_(f) { };
// Destructor
~Parametric_cell_radius_criterion() { };
protected:
virtual void do_accept(Visitor_& v) const
{
v.visit(*this);
}
virtual Self* do_clone() const
{
// Call copy ctor on this
return new Self(*this);
}
virtual Badness do_is_bad(const Cell_handle& ch) const
{
// put relevant code here ...
// calling my_sizing_func_(x, y, x) will return a double
// where x, y, x are coordiate of the center of
// the cell being refined
}
private:
const Function my_sizing_func_;
}; // end class My_new_criterion
--------end------------------------------------------
3. Copy CGAL/Mesh_cell_criteria_3.h and name it Mesh_new_cell_criteria.h
The new header file should look like this:
--------begin----------------------------------------
#include <CGAL/Mesh_3/mesh_standard_cell_criteria.h>
#include <mesh_my_cell_criteria.h>
namespace CGAL {
template <typename Function, typename Tr, typename Visitor_ = Mesh_3::Cell_criterion_visitor<Tr> >
class Mesh_new_cell_criteria_3
{
typedef Visitor_ Visitor;
typedef Mesh_3::Criteria<Tr,Visitor> Criteria;
typedef typename Tr::Cell_handle Cell_handle;
typedef typename Tr::Geom_traits::FT FT;
typedef typename Tr::Bare_point Point_3;
typedef Mesh_new_cell_criteria_3<Function,Tr> Self;
public:
typedef typename Visitor::Cell_quality Cell_quality;
typedef typename Visitor::Cell_badness Cell_badness;
Mesh_new_cell_criteria_3(const Function& my_func)
{
typedef Mesh_3::My_new_criterion<Function,Tr,Visitor> My_criterion;
criteria_.add(new My_criterion(my_func));
}
/// Destructor
~Mesh_cell_parametric_criteria_3() { }
Cell_badness operator()(const Cell_handle& cell) const
{
return criteria_(cell);
}
private:
Criteria criteria_;
};
} // end namespace CGAL
--------end------------------------------------------
4. Creat : mesh_new_criteria_3.h
------ begin -------------------
#include "Mesh_facet_parametric_criteria_3.h"
#include "Mesh_cell_parametric_criteria_3.h"
namespace CGAL {
// Class Mesh_new_criteria_3
// Provides meshing criteria to drive Mesh_3 process
template <typename Function, class Tr>
class Mesh_new_criteria_3
{
public:
typedef Mesh_facet_standard_criteria_3<Tr> Facet_criteria;
typedef Mesh_cell_new_criteria_3<Function,Tr> Cell_criteria;
// Constructor
Mesh_new_criteria_3(const Facet_criteria& facet_criteria,
const Cell_criteria& cell_criteria)
: facet_criteria_(facet_criteria)
, cell_criteria_(cell_criteria) { };
// Destructor
~Mesh_new_criteria_3() { };
const Facet_criteria& facet_criteria() const { return facet_criteria_; };
const Cell_criteria& cell_criteria() const { return cell_criteria_; };
private:
Facet_criteria facet_criteria_;
Cell_criteria cell_criteria_;
}; // end class Mesh_new_criteria_3
} // end namespace CGAL
------ end ---------------------
5. Then you should be able to pass the sizing function through your newly defined criterion to the meshing algorithm:
#include "sizing_functions.h"
// ...
main()
{
// ...
typedef CGAL::Exact_predicates_inexact_constructions_kernel K;
// Mesh Criteria
typedef FT_to_point_function_wrapper<K::FT, K::Point_3> Function;
typedef CGAL::Mesh_new_criteria_3<Function, Tr> Mesh_criteria;
typedef Mesh_criteria::Facet_criteria Facet_criteria;
typedef Mesh_criteria::Cell_criteria Cell_criteria;
// ...
Facet_criteria facet_criteria(30, 0.2, 0.02);
Function* cell_size = new Function(&cell_size_function);
Cell_criteria cell_criteria(*cell_size_);
// ...
Mesh_criteria meshCriteria(facet_criteria, cell_criteria);
C3t3 c3t3 = CGAL::make_mesh_3<C3t3>(domain, criteria, no_exude(), no_perturb());
// ...
}
Regards,
-Ramin
On Wed, Jun 2, 2010 at 7:51 PM, Hansjoerg Seybold <> wrote:
hi,
I am writing a meshing tool for a simple FEM code. I saw that with the cgal criteria object
it would be possible to define sizing functions and variable sizing constraints for the mesh builder
(see e.g. talk of pierre alliez )
www-sop.inria.fr/geometrica/.../CGAL-delaunay-refinement-2D-pa.pdf
does anybody have an example or some comments/hints how to use the criteria to implement sizing
functions as e.g. implicit algebraic functions etc...
Thanks a lot
hj
- [cgal-discuss] meshing tool, Hansjoerg Seybold, 06/03/2010
- Re: [cgal-discuss] meshing tool, Ramin H, 06/04/2010
Archive powered by MHonArc 2.6.16.