これはcgal関連の質問ですが、一般的なC ++の質問でもあると思うので、ここで質問します。
クラスを使用して、という名前のサブルーチンのクラスにAlpha_shape_2
割り当てようとしています。問題は、の関数の一部が正しい結果を返さないことです。AlphaShapeCg
GetAlphaShalCg
Alpha_shape_2
Alpha_shape_2
これは私のコードであり、非常に単純ですが、サブルーチンでラッパーに割り当ててから、親ルーチンでメンバーにアクセスすることと、Alpha_shape_2
直接アクセスすることの違いがなぜあるのかよくわかりません。
CGALがインストールされている場合に、コンパイルして再生できる完全なコードは次のとおりです。
#include <CGAL/Exact_predicates_inexact_constructions_kernel.h>
#include <CGAL/algorithm.h>
#include <CGAL/Delaunay_triangulation_2.h>
#include <CGAL/Alpha_shape_2.h>
#include <iostream>
#include <fstream>
#include <vector>
#include <list>
typedef CGAL::Exact_predicates_inexact_constructions_kernel K;
typedef K::FT FT;
typedef K::Point_2 Point;
typedef K::Segment_2 Segment;
typedef CGAL::Alpha_shape_vertex_base_2<K> Vb;
typedef CGAL::Alpha_shape_face_base_2<K> Fb;
typedef CGAL::Triangulation_data_structure_2<Vb,Fb> Tds;
typedef CGAL::Delaunay_triangulation_2<K,Tds> Triangulation_2;
typedef CGAL::Alpha_shape_2<Triangulation_2> Alpha_shape_2;
template <class OutputIterator>
bool
file_input(OutputIterator out)
{
std::ifstream is("./data/fin", std::ios::in);
if(is.fail()){
std::cerr << "unable to open file for input" << std::endl;
return false;
}
int n;
is >> n;
std::cout << "Reading " << n << " points from file" << std::endl;
CGAL::copy_n(std::istream_iterator<Point>(is), n, out);
return true;
}
//------------------ main -------------------------------------------
struct AlphaShapeCg
{
Alpha_shape_2 *AlphaShape;
};
void GetAlphaShalCg(AlphaShapeCg *ashape, std::list<Point> points)
{
Alpha_shape_2 A(points.begin(), points.end(),
FT(100000),
Alpha_shape_2::GENERAL);
ashape->AlphaShape=&A;
}
int main()
{
std::list<Point> points;
if(! file_input(std::back_inserter(points))){
return -1;
}
AlphaShapeCg ashape;
GetAlphaShalCg(&ashape, points);
Alpha_shape_2 *APtrs=(ashape.AlphaShape);
int alphaEigenValue = APtrs->number_of_alphas(); // gives incorrect result; alphaEigenValue=0
//Alpha_shape_2 A(points.begin(), points.end(),
// FT(100000),
// Alpha_shape_2::GENERAL);
// int alphaEigenValue = APtrs->number_of_alphas(); // gives correct result; alphaEigenValue!=0
}
更新:使用しようとしました
Alpha_shape_2 =new A(points.begin(), points.end(), FT(100000), Alpha_shape_2::GENERAL);
しかし、このエラーのため、このコードは単にコンパイルされません。
エラーC2513:'CGAL :: Alpha_shape_2':'='の前に変数が宣言されていません