在CGAL中创建3D Alpha形状及其可视化 我是一个新的CGAL用户,有C++的基本经验,试图找到一组点的3D alpha形状。我正在使用示例代码,然后使用中的说明对结果进行可视化。一切似乎都正常工作,但当我试图通过替换 Alpha_shape_3 as(lp.begin(),lp.end());
与 假设第三个变量是alpha(=1)的值,并且每次更改该值,则结果不会发生任何更改 更具体地说,在我的粒子集中,一些粒子与大多数粒子分离,我希望使用凹面外壳或alpha形状使用单独的体积(类似于)来表示它们。目前我得到的(使用Tecplot进行可视化)是: 如你所见,分离的粒子与其他粒子相连。我也附上我的代码,在最后。在这件事上,如果有任何帮助,我将不胜感激在CGAL中创建3D Alpha形状及其可视化 我是一个新的CGAL用户,有C++的基本经验,试图找到一组点的3D alpha形状。我正在使用示例代码,然后使用中的说明对结果进行可视化。一切似乎都正常工作,但当我试图通过替换 Alpha_shape_3 as(lp.begin(),lp.end());,c++,visualization,mesh,cgal,concave-hull,C++,Visualization,Mesh,Cgal,Concave Hull,与 假设第三个变量是alpha(=1)的值,并且每次更改该值,则结果不会发生任何更改 更具体地说,在我的粒子集中,一些粒子与大多数粒子分离,我希望使用凹面外壳或alpha形状使用单独的体积(类似于)来表示它们。目前我得到的(使用Tecplot进行可视化)是: 如你所见,分离的粒子与其他粒子相连。我也附上我的代码,在最后。在这件事上,如果有任何帮助,我将不胜感激 #include <CGAL/Exact_predicates_inexact_constructions_kernel.
#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;
}
#包括
#包括
#包括
#包括
#包括
#包括
#包括
typedef CGAL::精确谓词不精确结构内核Gt;
typedef CGAL::Alpha_形状_顶点_底面_3 Vb;
typedef CGAL::Alpha_形状_单元_基底_3 Fb;
typedef CGAL::三角测量数据结构Tds;
typedef CGAL::Delaunay_三角剖分_3三角剖分_3;
typedef CGAL::Alpha_shape_3 Alpha_shape_3;
类型定义Gt::点_3点;
typedef Alpha_shape_3::Alpha_迭代器Alpha_迭代器;
使用名称空间std;
int main()
{
std::list-lp;
//读取输入
标准::如果流是(“./data/finalwater4.dat”);
int n;
是>>n;
std::cout如果你想过滤掉东西,你需要采用一个alpha形状,它的值小于as.find_optimal_alpha(1)返回的值。我建议运行alpha形状演示,该演示具有一个滑块,该滑块将根据alpha的值显示alpha形状的外观。输入文件的扩展名应为.pts,并且必须包含点数,后跟点的坐标。非常感谢您的回复。我刚刚删除了该部分“找到最佳alpha值”,现在可以使用了:)
#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;
}