VS2008中利用CGAL库生成计算凸包的dll文件

(1)VC文件->新建->项目->Win32项目(DLL-CGAL-CONVELL)
下一步->下一步->应用程序类型:DLL

(2)解决方案示图:
头文件:(右键)—》添加dtriangulate(.h),输入如下代码
#ifndef _DTRIANGULATE_H
#define _DTRIANGULATE_H

#ifdef _USRDLL
#define DLLAPI __declspec(dllexport)
#else
#define DLLAPI __declspec(dllimport)
#endif

//定义结构体点的类型
struct Point{
 double x;
 double y;
 double z;
};
//定义结构体三角形
struct Triangle{
 Point p1;
 Point p2;
 Point p3;
};


DLLAPI int triangulate(Point *pts, int length, Point **outPts);


#endif


(3)在DLL-CGAL-CONVELL.cpp中输入如下代码:
// DLL-CGAL-CONVELL.cpp : 定义 DLL 应用程序的导出函数。
//

#include "stdafx.h"
#include <CGAL/Exact_predicates_inexact_constructions_kernel.h>
#include <CGAL/convex_hull_2.h>
#include <vector>
#include "dtriangulate.h"


typedef CGAL::Exact_predicates_inexact_constructions_kernel K;
typedef K::Point_2 Point_2;
//定义向量(动态数组),包含元素为Point_2点
typedef std::vector<Point_2> PointList;

//传入指向点的指针pts及长度length,返回的结果int型数表示三角形个数
int triangulate(Point *pts, int length, Point **outPts)
{
 //定义包含点的向量PointList,将pts的数据传给pl,pl处理后的数据传给result
 PointList pl, result;
 //将pts指向的(length-1)个点存入pl中
 for(int i=0;  i< length; i++){
  pl.push_back(Point_2(pts[i].x,pts[i].y));
  //cout<<"Point_2: "<<pts[i].x<<"  "<<pts[i].y<<endl;
 }
  
    CGAL::convex_hull_2(pl.begin(), pl.end(), std::back_inserter(result) );
 
 
 *outPts = new Point[result.size()];
 //将result的元素逐个复制给outPts
 for(size_t i=0;i<result.size();i++){
  (*outPts)[i].x = result[i].x();
  (*outPts)[i].y = result[i].y();
  (*outPts)[i].z = 0;
  //cout<<"outPts "<<i<<"  "<<result[i].x()<<"  "<<result[i].y()<<endl;
 }

    //result convert to outPts
 return result.size();

}

(4)项目->DLL-CGAL-CONVELL属性->连接器->常规->附加库目录:"C:/CGAL-3.4/cmake-wrx/include"(对CGAL编译之后存在cmake-wrx文件夹中)

(5)对项目编译即可生成dll,lib

 

你可能感兴趣的:(c,struct,dll)