1,刚开始学习使用CGAL,主要用到了Boost库,使用VS2012建了一个MFC项目,添加include如下:
#include <CGAL/Simple_cartesian.h> #include <CGAL/Polyhedron_3.h> #include <CGAL/IO/Polyhedron_iostream.h> // #include <CGAL/Surface_mesh_simplification/HalfedgeGraph_Polyhedron_3.h>
#include <CGAL/Surface_mesh_simplification/edge_collapse.h> #include <CGAL/Surface_mesh_simplification/Policies/Edge_collapse/Constrained_placement.h> #include <CGAL/Surface_mesh_simplification/Policies/Edge_collapse/Midpoint_placement.h> #include <CGAL/Surface_mesh_simplification/Policies/Edge_collapse/Count_stop_predicate.h> //#include <CGAL/Surface_mesh_simplification> #include <CGAL/Unique_hash_map.h> #include <CGAL/Mesh_3/dihedral_angle_3.h> #include <CGAL/property_map.h> #include <cmath>
运行时出现如下错误:
错误 2 error C2064: 项不会计算为接受 2 个参数的函数 d:\boost\boost_1_54_0\boost\type_traits\has_new_operator.hpp 33 1 app2 错误 3 error C2064: 项不会计算为接受 2 个参数的函数 d:\boost\boost_1_54_0\boost\type_traits\has_new_operator.hpp 44 1 app2 错误 4 error C2064: 项不会计算为接受 2 个参数的函数 d:\boost\boost_1_54_0\boost\type_traits\has_new_operator.hpp 55 1 app2 错误 5 error C2064: 项不会计算为接受 2 个参数的函数 d:\boost\boost_1_54_0\boost\type_traits\has_new_operator.hpp 67 1 app2 错误 7 error C2059: 语法错误:“]” d:\boost\boost_1_54_0\boost\type_traits\has_new_operator.hpp 67 1 app2 错误 8 error C2059: 语法错误:“)” d:\boost\boost_1_54_0\boost\type_traits\has_new_operator.hpp 69 1 app2 错误 9 error C2649: “typename”: 不是“class” d:\boost\boost_1_54_0\boost\type_traits\has_new_operator.hpp 70 1 app2 错误 10 error C2649: “typename”: 不是“class” d:\boost\boost_1_54_0\boost\type_traits\has_new_operator.hpp 73 1 app2
//has_new_operator.hpp namespace detail { template <class U, U x> struct test; template <typename T> struct has_new_operator_impl { template<class U> static type_traits::yes_type check_sig1( U*, test< void *(*)(std::size_t), &U::operator new //项不能计算为接受两个参数的函数 >* = NULL );
但是当我把把关于Surface_mesh_simplification的include注释掉之后就不会报错了,如下:
#include <CGAL/Simple_cartesian.h> #include <CGAL/Polyhedron_3.h> #include <CGAL/IO/Polyhedron_iostream.h> // //#include <CGAL/Surface_mesh_simplification/HalfedgeGraph_Polyhedron_3.h> //#include <CGAL/Surface_mesh_simplification/edge_collapse.h> //#include <CGAL/Surface_mesh_simplification/Policies/Edge_collapse/Constrained_placement.h> //#include <CGAL/Surface_mesh_simplification/Policies/Edge_collapse/Midpoint_placement.h> //#include <CGAL/Surface_mesh_simplification/Policies/Edge_collapse/Count_stop_predicate.h> //#include <CGAL/Surface_mesh_simplification> #include <CGAL/Unique_hash_map.h> #include <CGAL/Mesh_3/dihedral_angle_3.h> #include <CGAL/property_map.h> #include <cmath>
求解?
2,CGAL读的是OFF格式的文件(ASCII或者Binary),但是为什么我用Maya生成的obj文件转化成off格式的文件之后为什么CGAL不能计算?
参考代码如下(obj-->off):
using namespace std; // TODO: 在此添加命令处理程序代码 //::MessageBox(NULL,_T("读取成功"),_T("标题"),MB_OK); CFileDialog dlg(true,NULL,NULL,OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT,(LPCTSTR)_T("obj files|*.obj||")); CString filePathAll; CString filePath; long int countPoint; long int countFace; countPoint = 0; countFace = 0; if(dlg.DoModal()==IDOK) { filePathAll = dlg.GetPathName(); int pos = filePathAll.ReverseFind('\\'); filePath = filePathAll.Mid(0,pos); filePath += "\\"; CString fileTitle = dlg.GetFileTitle(); char *cfilePathAllCopy = (LPSTR)(LPCTSTR)filePathAll; //memset(cfilePathAllCopy,0,sizeof(cfilePathAllCopy)); char *cfilePathAll = cfilePathAllCopy; CStdioFile sFile; CString *pointALLCopy = new CString[300000]; CString *faceALLCopy = new CString[300000]; //memset(pointALLCopy,0,300000); //memset(faceALLCopy,0,300000); CString *pointALL = pointALLCopy; CString *faceALL = faceALLCopy; int positionPre = 0; int positionPos; if(sFile.Open((LPCTSTR)cfilePathAll,CFile::modeReadWrite | CFile::typeText )) { CString filePart = (CString)(" "); CString sSpace =_T( " "); //CString men; while(sFile.ReadString(filePart)) { if(filePart != "") { if(filePart.GetAt(0) == 'v' && filePart.GetAt(1) == ' ') { pointALL[countPoint] = filePart.Mid(2); countPoint ++ ; } if(filePart.GetAt(0) == 'f' && filePart.GetAt(1) == ' ') { //if(i != 0) i=0; //if(j%31 == 0) //{ CString bufferFace; positionPre = 0; for(int i = 0;i < 3;i++) { positionPre = filePart.Find(' ',positionPre) + 1; positionPos = filePart.Find('/',positionPre); bufferFace = filePart.Mid(positionPre , positionPos - positionPre); bufferFace.TrimLeft(); bufferFace.TrimRight(); char *cFace = new char[bufferFace.GetLength()]; for(int j = 0;j<bufferFace.GetLength();j++) { cFace[j] = bufferFace[j]; } int iFace = atoi(cFace) - 1; itoa(iFace,cFace,10); bufferFace = CString(cFace); if(i < 2) { faceALL[countFace] += bufferFace + sSpace; } else faceALL[countFace] += bufferFace; positionPre = positionPos; } //faceALL[countFace] = filePart.Mid(2); countFace ++; //} //j++; } //if(filePart.GetAt(0) == 'f'&&label == 0 ) // label = countHeadPoint; }//if(filePart != "" ) }//while(sFile.ReadString(filePart)) if(pointALL!=NULL) ::MessageBox(NULL,_T("读取成功"),_T("标题"),MB_OK); }//if(sFile.Open((LPCTSTR)cfilePathAll,CFile::modeReadWrite | CFile::typeText )) char *ccountPointCopy; ccountPointCopy = new char[20]; memset(ccountPointCopy,0,20); char *ccountPoint = ccountPointCopy; itoa(countPoint,ccountPoint,10); CString scountPoint = (CString)ccountPoint; char *ccountFaceCopy; ccountFaceCopy = new char[20]; memset(ccountFaceCopy,0,20); char *ccountFace = ccountFaceCopy; itoa(countFace,ccountFace,10); CString scountFace = (CString)ccountFace; char *ccountLineCopy; ccountLineCopy = new char[20]; memset(ccountLineCopy,0,20); char *ccountLine = ccountLineCopy; itoa(0,ccountLine,10); CString scountLine = (CString)ccountLine; char *cConstCopy; cConstCopy = new char[5]; memset(cConstCopy,0,5); char *cConst = cConstCopy; itoa(3,cConst,10); CString sConst = (CString)cConst; //itoa(outCount,cCount,10); // //CString sCount = (CString)cCount; CString filePathAllOFF; CString filePathOFF; CFileDialog dlgOFF(FALSE,_T("mdl"),_T("*.off")); CString sn =_T( "\x0A"); CString sOff =_T( "OFF"); CString sSpace =_T( " "); if(IDOK == dlgOFF.DoModal()) { filePathAllOFF = dlgOFF.GetPathName(); int posOFF = filePathAllOFF.ReverseFind('\\'); filePathOFF = filePathAllOFF.Mid(0,posOFF); filePathOFF += "\\"; CString fileNameOFF = dlgOFF.GetFileName(); filePathOFF += fileNameOFF; ////二进制写入文件 ofstream file; file.open(filePathOFF,ios_base::out|ios_base::binary|ios::badbit); if(file.is_open()) { for(int i = 0;i<sOff.GetLength();i++) { file.put(sOff[i]); } //file<<sOff; file.put('\n'); //file<<sn; for(int i = 0;i<scountPoint.GetLength();i++) { file.put(scountPoint[i]); } //file<<scountPoint; file.put(' '); //file<<sSpace; for(int i = 0;i<scountFace.GetLength();i++) { file.put(scountFace[i]); } //file<<scountFace; file.put(' '); //file<<sSpace; file.put('0'); //file<<scountLine; file.put('\n'); //file<<sn; //file.WriteString(sn); positionPre = 0; CString bufferPoint; CString bufferPoint2 = NULL; for(int i = 0;i<countPoint;i++) { //memset(bufferPoint,0,sizeof(bufferPoint)); file.put('\n'); pointALL[i].TrimLeft(); for(int j = 0;j<pointALL[i].GetLength();j++) file.put(pointALL[i][j]); } for(int i = 0;i<countFace;i++) { file.put('\n'); //file<<sn; file.put('3'); //file<<sConst; file.put(' '); //file<<sSpace; //file<<sSpace; for(int j = 0;j<faceALL[i].GetLength();j++) file.put(faceALL[i][j]); //file<<faceALL[i]; } }//if(file.is_open()) else ::MessageBox(NULL,_T("文件打开失败"),_T("标题"),MB_OK); if(file!=NULL) ::MessageBox(NULL,_T("文件已写入"),_T("标题"),MB_OK); }//if(IDOK == dlgOFF.DoModal()) }//if(dlg.DoModal()==IDOK)
我也遇到了同样的报错信息,尚未找到解决办法。
版权声明:本文内容由阿里云实名注册用户自发贡献,版权归原作者所有,阿里云开发者社区不拥有其著作权,亦不承担相应法律责任。具体规则请查看《阿里云开发者社区用户服务协议》和《阿里云开发者社区知识产权保护指引》。如果您发现本社区中有涉嫌抄袭的内容,填写侵权投诉表单进行举报,一经查实,本社区将立刻删除涉嫌侵权内容。