1
我是一個具有基本C++經驗的新CGAL用戶,試圖找到一組點的3D Alpha形狀。我正在使用ex_alpha_shapes_3示例代碼,然後使用saving CGAL alpha shape surface mesh中的說明來顯示結果。一切似乎正常工作,但是當我嘗試通過與在CGAL和可視化中創建3D Alpha形狀
Alpha_shape_3 as(lp.begin(),lp.end(),1, Alpha_shape_3::GENERAL);
假設第三可變替換
Alpha_shape_3 as(lp.begin(),lp.end());
改變的α的值是阿爾法的值(= 1)和改變該值每次都沒有獲得結果的變化。
更具體地說,在我的一組粒子中,有些與大多數是分離的,我想用分開的體積(類似於Figure 41.1)使用凹形或alpha形狀來表示它們。目前我得到的結果(使用Tecplot進行可視化)是: 正如您所看到的,分離的粒子與其他粒子相連。最後,我也附上我的代碼。我希望在這個問題上有任何幫助。
#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;
}
非常感謝您的回覆。我剛剛刪除了「找到最佳阿爾法值」部分,現在它工作:) – Vahid