Je suis un nouvel utilisateur CGAL avec une expérience C++ de base, essayant de trouver les formes alpha 3D d'un ensemble de points. J'utilise le code d'exemple ex_alpha_shapes_3, puis en utilisant les instructions dans saving CGAL alpha shape surface mesh pour la visualisation des résultats. Tout semble fonctionner correctement, mais lorsque je tente de changer la valeur de l'alpha en remplaçantCréation de formes alpha 3D dans CGAL et la visualisation
Alpha_shape_3 as(lp.begin(),lp.end());
avec
Alpha_shape_3 as(lp.begin(),lp.end(),1, Alpha_shape_3::GENERAL);
en supposant que la troisième variable est la valeur de l'alpha (= 1) et modifier cette valeur chaque fois, aucun changement dans les résultats n'est obtenu. Plus précisément, dans mon ensemble de particules, certaines sont détachées de la majorité et j'aimerais les représenter avec des volumes séparés (similaires au Figure 41.1) en utilisant la forme concave ou les formes alpha. Actuellement, ce que je reçois (en utilisant le Tecplot pour la visualisation) est: et comme vous pouvez le voir, les particules détachées sont connectées aux autres particules. Je joins également mon code, à la fin. J'apprécierais toute aide à ce sujet.
#include <CGAL/Exact_predicates_inexact_constructions_kernel.h>
#include <CGAL/Delaunay_triangulation_3.h>
#include <CGAL/Alpha_shape_3.h>
#include <iostream>
#include <fstream>
#include <list>
#include <cassert>
typedef CGAL::Exact_predicates_inexact_constructions_kernel Gt;
typedef CGAL::Alpha_shape_vertex_base_3<Gt> Vb;
typedef CGAL::Alpha_shape_cell_base_3<Gt> Fb;
typedef CGAL::Triangulation_data_structure_3<Vb,Fb> Tds;
typedef CGAL::Delaunay_triangulation_3<Gt,Tds> Triangulation_3;
typedef CGAL::Alpha_shape_3<Triangulation_3> Alpha_shape_3;
typedef Gt::Point_3 Point;
typedef Alpha_shape_3::Alpha_iterator Alpha_iterator;
using namespace std;
int main()
{
std::list<Point> lp;
//read input
std::ifstream is("./data/finalwater4.dat");
int n;
is >> n;
std::cout << "Reading " << n << " points " << std::endl;
Point p;
for(; n>0 ; n--) {
is >> p;
lp.push_back(p);
}
// compute alpha shape
// Alpha_shape_3 as(lp.begin(),lp.end());
Alpha_shape_3 as(lp.begin(),lp.end(),0.001, Alpha_shape_3::GENERAL);
// find optimal alpha value
Alpha_iterator opt = as.find_optimal_alpha(1);
std::cout << "Optimal alpha value to get one connected component is "
<< *opt << std::endl;
as.set_alpha(*opt);
assert(as.number_of_solid_components() == 1);
/// the rest of the code, prepares the output to be written into a file
/// collect all regular facets (fetch regular facets from as and inserts in facets)
std::vector<Alpha_shape_3::Facet> facets;
as.get_alpha_shape_facets(std::back_inserter(facets), Alpha_shape_3::REGULAR);
std::stringstream pts;
std::stringstream ind;
std::size_t nbf=facets.size();
for (std::size_t i=0;i<nbf;++i)
{
//To have a consistent orientation of the facet, always consider an exterior cell
if (as.classify(facets[i].first)!=Alpha_shape_3::EXTERIOR)
facets[i]=as.mirror_facet(facets[i]);
CGAL_assertion( as.classify(facets[i].first)==Alpha_shape_3::EXTERIOR );
int indices[3]={
(facets[i].second+1)%4,
(facets[i].second+2)%4,
(facets[i].second+3)%4,
};
/// according to the encoding of vertex indices, this is needed to get
/// a consistent orienation
if (facets[i].second%2==0) std::swap(indices[0], indices[1]);
pts <<
facets[i].first->vertex(indices[0])->point() << "\n" <<
facets[i].first->vertex(indices[1])->point() << "\n" <<
facets[i].first->vertex(indices[2])->point() << "\n";
ind << 3*i+1 << " " << 3*i+2 << " " << 3*i+3 << "\n";
}
ofstream myfile;
myfile.open ("output.dat");
myfile << "variables = x, y, z\n";
myfile << "zone n="<< 3*nbf << " , e=" << nbf << " , f=fepoint, et=triangle\n";
myfile << pts.str();
myfile << ind.str();
myfile.close();
return 0;
}
Merci beaucoup pour votre réponse. Je viens de supprimer la section "trouver la valeur alpha optimale", et cela fonctionne maintenant :) – Vahid