Subject: CGAL users discussion list
List archive
- From: Danyang Su <>
- To:
- Subject: [cgal-discuss] Question about mesh_domain as a global variable
- Date: Thu, 17 Mar 2016 07:03:09 -0700
- Authentication-results: mail3-smtp-sop.national.inria.fr; spf=None ; spf=Pass ; spf=None
- Ironport-phdr: 9a23:cwDC5RVAqBZEqCQCF+r4YP9d93HV8LGtZVwlr6E/grcLSJyIuqrYZhePt8tkgFKBZ4jH8fUM07OQ6PCwHzRcqsrf+Fk5M7VyFDY9wf0MmAIhBMPXQWbaF9XNKxIAIcJZSVV+9Gu6O0UGUOz3ZlnVv2HgpWVKQka3CwN5K6zPF5LIiIzvjqbpq82VO1kD2GT1SIgxBSv1hD2ZjtMRj4pmJ/R54TryiVwMRd5rw3h1L0mYhRf265T41pdi9yNNp6BprJYYAu2pN5g/GLdXBTBjP2Eu79DwrjHCSxGO7z0SSDY4iB1NViTM6gDzWJi5iTay4uZ03jiTO8KwVq0cVjGr7qMtQxjt3nRUfwUl+X3a35QjxJlQpwis8kRy
Dear All, I am a fortran programmer that I want to port CGAL 3d mesh generation from c++ to Fortran by using the interface. I can make it work if I wrap all the steps in one single function. However, if I separate the steps, because some of the variables cannot be saved, the code does not work. For example, I would like to generate the mesh generation by the following steps. In setmeshDomainFeatures function, the mesh_domain is generated. But this variable does not support operator '=' that I cannot save this object as a global value, which will be used by the function after this step. My question is, is it possible to save this variable as a global one? If so, what can I do? The source code and example input file have been attached. //++++++++++++++++++++++++++++++++++++++++++ // Set input file and output file cout << "Set input file and output file" << endl; setMeshInputOutputFile(11,"T3d_rec.off",11,"T3d_tri.off"); // Make surface mesh cout << "Make surface mesh" << endl; if (makeSurfaceMesh() < 1) return 0; // Set 3d mesh domain and dectect features cout << "Set 3d mesh domain and dectect features" << endl; setMeshDomainFeatures(); // Optional, Set 3d mesh criteria cout << "Set 3d mesh criteria" << endl; setMeshCriteria(0.025, 25, 0.05, 0.005, 3, 0.5); // Make mesh using default setting, without optimization cout << "Make mesh using default setting, without optimization" << endl; makeMesh(); // Optional, Optimize 3d mesh using lloyd_optimize_mesh_3 method cout << "Optimize 3d mesh using lloyd_optimize_mesh_3 method" << endl; optimizeMeshLloyd(10, 10.0); // Optional, Optimize 3d mesh using exude_mesh_3 method cout << "Optimize 3d mesh using exude_mesh_3 method" << endl; optimizeMeshExude(10.0, 10.0); // Optional, Optimize 3d mesh using perturb_mesh_3 method cout << "Optimize 3d mesh using perturb_mesh_3 method" << endl; optimizeMeshPerturb(10.0, 10.0); // Output mesh to file cout << "Output mesh to file" << endl; outputMesh(); //++++++++++++++++++++++++++++++++++++++++++ Thanks and regards, Danyang |
//*****Revision Informations Automatically Generated by VisualSVN*****! //--------------------------------------------------------------------- //> $ID:$ //> $Revision: 384 $ //> $Author: dsu $ //> $Date: 2014-08-05 14:29:49 -0700 (Tue, 05 Aug 2014) $ //> $URL: https://biot.eos.ubc.ca/svn/min3p_thcm/branches/dsu_usg_basic/src/usg/cgal_make_mesh_3d.cc $ //--------------------------------------------------------------------- //********************************************************************! // -------------------------------------------------------------------- // Module of CGAL 3d mesh generation // Written by: Danyang Su - Nov. 26, 2015 // Last modified: // -------------------------------------------------------------------- #define _USE_MATH_DEFINES #define CGAL_MESH_3_OPTIMIZER_VERBOSE //#define CGAL_MESH_3_OPTIMIZERS_DEBUG //#define CGAL_MESH_3_SIZING_FIELD_USE_BARYCENTRIC_COORDINATES #include <fstream> #include <iostream> #include <vector> #include <string> //CGAL 3d mesh generation head files #include <CGAL/Exact_predicates_inexact_constructions_kernel.h> #include <CGAL/Surface_mesh.h> #include <CGAL/boost/graph/graph_traits_Surface_mesh.h> #include <CGAL/Mesh_triangulation_3.h> #include <CGAL/Mesh_complex_3_in_triangulation_3.h> #include <CGAL/Mesh_criteria_3.h> #include <CGAL/Surface_mesh_default_criteria_3.h> #include <CGAL/Polyhedral_mesh_domain_3.h> #include <CGAL/Polyhedral_mesh_domain_with_features_3.h> #include <CGAL/make_mesh_3.h> //User defined mesh generation head files #include "cgal_surface_mesh.h" // Domain typedef CGAL::Exact_predicates_inexact_constructions_kernel K; typedef CGAL::Polyhedral_mesh_domain_with_features_3<K> Mesh_domain; typedef K::Point_3 Point3d; typedef CGAL::Surface_mesh<Point3d> Surface_mesh; // Triangulation #ifdef CGAL_CONCURRENT_MESH_3 typedef CGAL::Mesh_triangulation_3< Mesh_domain, CGAL::Kernel_traits<Mesh_domain>::Kernel, // Same as sequential CGAL::Parallel_tag // Tag to activate parallelism >::type Tr; #else typedef CGAL::Mesh_triangulation_3<Mesh_domain>::type Tr; #endif typedef CGAL::Mesh_complex_3_in_triangulation_3<Tr, Mesh_domain::Corner_index,Mesh_domain::Curve_segment_index> C3t3; // Criteria typedef CGAL::Mesh_criteria_3<Tr> Mesh_criteria; // To avoid verbose function and named parameters call using namespace CGAL::parameters; using std::cout; using std::endl; //Shared global variables std::string strfile_mesh_input; std::string strfile_mesh_surface; std::string strfile_mesh_output; Mesh_criteria mesh_criteria; Mesh_domain mesh_domain(""); C3t3 mesh_c3t3; // // Set 3d mesh generation input file and output file, with default mesh criteria // Variables description: // sfile_len: length of input mesh frame file name in 'off' format // sfile: input mesh frame file name in 'off' format // sfileout_len: length of output mesh file name in 'mesh' format // sfileout: output mesh file name in 'mesh' format // void setMeshInputOutputFile(const int sfile_len,const char* sfile,const int sfileout_len, const char* sfileout){ strfile_mesh_input = std::string(sfile,0,sfile_len); strfile_mesh_surface = strfile_mesh_input+".temp"; strfile_mesh_output = std::string(sfileout,0,sfileout_len); } // // Make surface mesh that will be used as the input for the 3d mesh generation // int makeSurfaceMesh(){ int iflag = makeSurfaceMesh(strfile_mesh_input,strfile_mesh_surface); return iflag; } // // Set 3d mesh domain and dectect features // void setMeshDomainFeatures(){ // Create domain Mesh_domain mesh_domain(strfile_mesh_surface); // Get sharp features mesh_domain.detect_features(); mesh_criteria = Mesh_criteria(edge_size = 0.05, facet_angle = 20, facet_size = 0.1, facet_distance = 0.05, cell_radius_edge_ratio = 3, cell_size = 0.1); } // // Set 3d mesh generation criteria // Variables description: // sfile_len: length of input mesh frame file name in 'off' format // sfile: input mesh frame file name in 'off' format // sfileout_len: length of output mesh file name in 'mesh' format // sfileout: output mesh file name in 'mesh' format // parameter edge_size: a scalar field (resp. a constant) providing a space varying (resp. a uniform) // upper bound for the lengths of curve segment edges. This parameter has to be // set to a positive value when 1-dimensional features protection is used. // parameter facet_angle: a lower bound for the angles (in degrees) of the surface mesh facets. // parameter facet_size: a scalar field (resp. a constant) describing a space varying (resp. a uniform) // upper-bound or for the radii of the surface Delaunay balls. // parameter facet_distance: a scalar field (resp. a constant) describing a space varying (resp. a uniform) // upper bound for the same distance. // parameter cell_radius_edge_ratio: an upper bound for the radius-edge ratio of the mesh tetrahedra. // parameter cell_size: a scalar field (resp. a constant) describing a space varying (resp. a uniform) // upper-bound for the circumradii of the mesh tetrahedra. // void setMeshCriteria(const double edge_size_in, const double facet_angle_in, const double facet_size_in, const double facet_distance_in, const double cell_radius_edge_ratio_in, const double cell_size_in){ mesh_criteria = Mesh_criteria(edge_size = edge_size_in, facet_angle = facet_angle_in, facet_size = facet_size_in, facet_distance = facet_distance_in, cell_radius_edge_ratio = cell_radius_edge_ratio_in, cell_size = cell_size_in); } // // Make mesh using default setting, without optimization // void makeMesh(){ mesh_c3t3 = CGAL::make_mesh_3<C3t3>(mesh_domain, mesh_criteria, no_perturb(), no_exude()); } // // Optimize 3d mesh using lloyd_optimize_mesh_3 method // Variables description // maxIteration: maximum lloyd optimization iteration number // timeLimit: time limit (CPU time in seconds) after which optimization process is stopped // void optimizeMeshLloyd(int maxIteration, double timeLimit){ CGAL::lloyd_optimize_mesh_3(mesh_c3t3, mesh_domain, max_iteration_number = maxIteration, time_limit=timeLimit); } // // Optimize 3d mesh using exude_mesh_3 method // Variables description // sliverBound: a targeted lower bound (in degree) on dihedral angles of mesh cells // timeLimit: time limit (CPU time in seconds) after which optimization process is stopped // void optimizeMeshExude(double sliverBound, double timeLimit){ CGAL::exude_mesh_3(mesh_c3t3, sliver_bound=sliverBound, time_limit=timeLimit); } // // Optimize 3d mesh using perturb_mesh_3 method // Variables description // sliverBound: a targeted lower bound (in degree) on dihedral angles of mesh cells // timeLimit: time limit (CPU time in seconds) after which optimization process is stopped // void optimizeMeshPerturb(double sliverBound, double timeLimit){ CGAL::perturb_mesh_3(mesh_c3t3, mesh_domain, sliver_bound=sliverBound, time_limit=timeLimit); } // // Output mesh to "mesh" file // void outputMesh(){ // Output std::ofstream medit_file(strfile_mesh_output); mesh_c3t3.output_to_medit(medit_file); medit_file.close(); } extern "C" { // // Make surface mesh that will be used as the input for the 3d mesh generation // int make_surface_mesh(){ return makeSurfaceMesh(strfile_mesh_input,strfile_mesh_surface); } } int main() { // Set input file and output file cout << "Set input file and output file" << endl; setMeshInputOutputFile(11,"T3d_rec.off",11,"T3d_tri.off"); // Make surface mesh cout << "Make surface mesh" << endl; if (makeSurfaceMesh() < 1) return 0; // Set 3d mesh domain and dectect features cout << "Set 3d mesh domain and dectect features" << endl; setMeshDomainFeatures(); // Optional, Set 3d mesh criteria cout << "Set 3d mesh criteria" << endl; setMeshCriteria(0.025, 25, 0.05, 0.005, 3, 0.5); // Make mesh using default setting, without optimization cout << "Make mesh using default setting, without optimization" << endl; makeMesh(); // Optional, Optimize 3d mesh using lloyd_optimize_mesh_3 method cout << "Optimize 3d mesh using lloyd_optimize_mesh_3 method" << endl; optimizeMeshLloyd(10, 10.0); // Optional, Optimize 3d mesh using exude_mesh_3 method cout << "Optimize 3d mesh using exude_mesh_3 method" << endl; optimizeMeshExude(10.0, 10.0); // Optional, Optimize 3d mesh using perturb_mesh_3 method cout << "Optimize 3d mesh using perturb_mesh_3 method" << endl; optimizeMeshPerturb(10.0, 10.0); // Output mesh to file cout << "Output mesh to file" << endl; outputMesh(); return 1; }
//*****Revision Informations Automatically Generated by VisualSVN*****! //--------------------------------------------------------------------- //> $ID:$ //> $Revision: 384 $ //> $Author: dsu $ //> $Date: 2014-08-05 14:29:49 -0700 (Tue, 05 Aug 2014) $ //> $URL: https://biot.eos.ubc.ca/svn/min3p_thcm/branches/dsu_usg_basic/src/usg/cgal_mesh.cc $ //--------------------------------------------------------------------- //********************************************************************! // -------------------------------------------------------------------- // Module of CGAL surface mesh generation // Written by: Danyang Su - Nov. 26, 2015 // Last modified: // -------------------------------------------------------------------- #include <CGAL/Exact_predicates_inexact_constructions_kernel.h> #include <CGAL/Surface_mesh.h> #include <CGAL/boost/graph/graph_traits_Surface_mesh.h> #include <CGAL/Polygon_mesh_processing/triangulate_faces.h> #include <fstream> //User defined mesh generation head files #include "cgal_surface_mesh.h" typedef CGAL::Exact_predicates_inexact_constructions_kernel K; typedef K::Point_3 Point3d; typedef CGAL::Surface_mesh<Point3d> Surface_mesh; int makeSurfaceMesh(std::string strfile,std::string strfileout){ std::ifstream input(strfile); Surface_mesh surfacemesh; if (!input || !(input >> surfacemesh) || surfacemesh.is_empty()) { std::cerr << "Not a valid off file." << std::endl; return 0; } // Create surface mesh (triangulate the input polyhedra) CGAL::Polygon_mesh_processing::triangulate_faces(surfacemesh); std::ofstream mesh_tri(strfileout); mesh_tri << surfacemesh; mesh_tri.close(); return 1; } /*int main() { return makeSurfaceMesh("T3d_rec.off","T3d_tri.off"); }*/
//*****Revision Informations Automatically Generated by VisualSVN*****! //--------------------------------------------------------------------- //> $ID:$ //> $Revision: 384 $ //> $Author: dsu $ //> $Date: 2014-08-05 14:29:49 -0700 (Tue, 05 Aug 2014) $ //> $URL: https://biot.eos.ubc.ca/svn/min3p_thcm/branches/dsu_usg_basic/src/usg/cgal_surface_mesh.h $ //--------------------------------------------------------------------- //********************************************************************! // -------------------------------------------------------------------- // Headfile of CGAL surface mesh generation // Written by: Danyang Su - Mar. 16, 2016 // Last modified: // -------------------------------------------------------------------- // This is start of the header guard. By convention, we use the name of the header file. #ifndef MAKE_SURFACE_MESH_H #define MAKE_SURFACE_MESH_H // This is the content of the .h file, which is where the declarations go int makeSurfaceMesh(std::string strfile,std::string strfileout); // This is the end of the header guard #endifOFF
8 6 0
-0.4603 -0.25555 0.500000
0.4603 -0.25555 0.500000
-0.4603 0.25555 0.500000
0.4603 0.25555 0.500000
-0.4603 0.25555 -0.500000
0.4603 0.25555 -0.500000
-0.4603 -0.25555 -0.500000
0.4603 -0.25555 -0.500000
4 0 1 3 2
4 2 3 5 4
4 4 5 7 6
4 6 7 1 0
4 1 7 5 3
4 6 0 2 4
Attachment:
cgal_make_mesh_3d_main.sh
Description: application/shellscript
- [cgal-discuss] Question about mesh_domain as a global variable, Danyang Su, 03/17/2016
Archive powered by MHonArc 2.6.18.