布爾boolean運算效率對比

採用array的osgmodeling庫進行測試,測試用例1w個由長方體構成的bool體

創建Box

osg::ref_ptr<osg::Geometry> CreateBox(const osg::Vec3& center,float lengthX,float lengthY, float lengthZ)//創建方體
{
	float halflengthX = lengthX*0.5 ,halflengthY = lengthY*0.5 ,halflengthZ = lengthZ*0.5 ;
	osg::ref_ptr<osg::Vec3Array> mPtTempArray = new osg::Vec3Array ;//頂點數組;
	mPtTempArray->push_back(osg::Vec3(center.x() - halflengthX, center.y() - halflengthY, center.z() + halflengthZ));
	mPtTempArray->push_back(osg::Vec3(center.x() + halflengthX, center.y() - halflengthY, center.z() + halflengthZ));
	mPtTempArray->push_back(osg::Vec3(center.x() + halflengthX, center.y() + halflengthY, center.z() + halflengthZ));
	mPtTempArray->push_back(osg::Vec3(center.x() - halflengthX, center.y() + halflengthY, center.z() + halflengthZ));


	mPtTempArray->push_back(osg::Vec3(center.x() - halflengthX, center.y() - halflengthY, center.z() - halflengthZ));
	mPtTempArray->push_back(osg::Vec3(center.x() + halflengthX, center.y() - halflengthY, center.z() - halflengthZ));
	mPtTempArray->push_back(osg::Vec3(center.x() + halflengthX, center.y() + halflengthY, center.z() - halflengthZ));
	mPtTempArray->push_back(osg::Vec3(center.x() - halflengthX, center.y() + halflengthY, center.z() - halflengthZ));

	return CreatePolyMesh(mPtTempArray,2);

}

創建bool體

osg::ref_ptr<osg::Geometry> Createboolean(osgModeling::BoolOperator::Method mMethod,osg::ref_ptr<osg::Geometry> mGeometry1,osg::ref_ptr<osg::Geometry> mGeometry2)
{
	osg::ref_ptr<osgModeling::BoolOperator> mBoolOperator = new osgModeling::BoolOperator(mMethod);
	osg::ref_ptr<osgModeling::Model> mModel1 = new osgModeling::Model(*mGeometry1);
	osg::ref_ptr<osgModeling::Model> mModel2 = new osgModeling::Model(*mGeometry2);
	mBoolOperator->setOperands(mModel1,mModel2);
	osg::ref_ptr<osg::Geometry> mGeom = new osg::Geometry;

	mBoolOperator->output(mGeom);
	// A triangle strip generator should be used here, otherwise too many independent triangles may cause the graphics system crash. 
	osgUtil::TriStripVisitor tsv;
	tsv.stripify( *mGeom );
	return mGeom;

}

單個圖形結果

顯示1w個圖形顯示用時

AutoCAD:Amodeler:: Body:兩個長方體布爾運算,執行5000次,小於1s。

AutoCAD:Acdb3dSoild :

release: OCC  長方體:BRepAlgoAPI_Cut(布爾運算)  執行10000次 耗時223s。


                       BRepAlgoAPI_Fuse(布爾運算)  執行10000次 耗時196s.

SYSTEMTIME sys;
    GetLocalTime(&sys);
    int m1 = int(sys.wMinute);
    int s1 = int(sys.wSecond);
    s1 += m1 * 60;

       TopoDS_Shape theBox1 = BRepPrimAPI_MakeBox(200, 200, 200);
        TopoDS_Shape theBox2 = BRepPrimAPI_MakeBox(100, 100, 100);

    for ( int i = 0; i < 10000; ++i )
    {
 
        TopoDS_Shape FusedShape = BRepAlgoAPI_Cut(theBox1, theBox2);
    }
    
    SYSTEMTIME sys2;
    GetLocalTime(&sys2);
    int m2 = int(sys2.wMinute);
    int s2 = int(sys2.wSecond);
    s2 += m2 * 60;
    cout << "Cut" << s2 - s1;
 

 

 

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章