炸天的3D引擎OpenCASCADE的用法及案例(https://blog.csdn.net/xipengbozai/article/details/117044032?spm=1001.2014.3001.5502)

What CASCADE?
Open CASCADE(簡稱OCC)平台是由法國Matra Datavision公司開發的CAD/CAE/CAM軟體平台,可以說是世界上最重要的幾何造型基礎軟體平台之一。開源OCC對象庫是一個面向對象C++類庫,用於快速開發設計領域的專業應用程式。

用它可以做很多三維模型,如下面兩種。簡單地說它可以開發三維CAD或者Solidworks等等軟體,可以說強大無比。

 

 

 OpenCASCADE的下載與安裝
1.OpenCASCADE下載。
1)去官網下載://dev.opencascade.org/release

2)去CSDN下載://download.csdn.net/download/xipengbozai/18883824

3)下載你需要的版本,推薦下載安裝版,比較省事://download.csdn.net/download/xipengbozai/18883824

2.OpenCASCADE安裝。
1)匹配VS版本,我的是VS2017 64位版本,所以安裝的是opencascade-7.4.0-vc14-64.exe

 

 

 

2)單機安裝,選擇下一步

 

 

 

3)然後安裝full版本,也就是完全版,單擊安裝直到完成即可。

 

 

 

4)安裝完的目錄效果,opencascade-7.4.0是主目錄,其他是附加庫

 

 

 

 OpenCASCADE的用法
1.建立項目工程,包含目錄

 

 

 

2.添加庫目錄,如下所示

 

3.鏈接器-輸入-附加依賴項輸入如下項

TKBin.lib
TKBinL.lib
TKBinTObj.lib
TKBinXCAF.lib
TKBO.lib
TKBool.lib
TKBRep.lib
TKCAF.lib
TKCDF.lib
TKD3DHost.lib
TKDCAF.lib
TKDFBrowser.lib
TKDraw.lib
TKernel.lib
TKFeat.lib
TKFillet.lib
TKG2d.lib
TKG3d.lib
TKGeomAlgo.lib
TKGeomBase.lib
TKHLR.lib
TKIGES.lib
TKIVtk.lib
TKIVtkDraw.lib
TKLCAF.lib
TKMath.lib
TKMesh.lib
TKMeshVS.lib
TKOffset.lib
TKOpenGl.lib
TKPrim.lib
TKQADraw.lib
TKRWMesh.lib
TKService.lib
TKShapeView.lib
TKShHealing.lib
TKStd.lib
TKStdL.lib
TKSTEP.lib
TKSTEP209.lib
TKSTEPAttr.lib
TKSTEPBase.lib
TKSTL.lib
TKTInspector.lib
TKTInspectorAPI.lib
TKTObj.lib
TKTObjDRAW.lib
TKToolsDraw.lib
TKTopAlgo.lib
TKTopTest.lib
TKTreeModel.lib
TKV3d.lib
TKVCAF.lib
TKView.lib
TKViewerTest.lib
TKVInspector.lib
TKVRML.lib
TKXCAF.lib
TKXDEDRAW.lib
TKXDEIGES.lib
TKXDESTEP.lib
TKXMesh.lib
TKXml.lib
TKXmlL.lib
TKXmlTObj.lib
TKXmlXCAF.lib
TKXSBase.lib
TKXSDRAW.lib

4.添加頭文件,一定要注意添加位置,#include <afxdisp.h>        // MFC 自動化類之後,#ifndef _AFX_NO_OLE_SUPPORT之前的中間。

#include <BRepTools.hxx> 
#include <Standard_DefineHandle.hxx> 
#include <DsgPrs_LengthPresentation.hxx> 
#include <GCPnts_TangentialDeflection.hxx> 
#include <Geom_Axis2Placement.hxx> 
#include <Geom_CartesianPoint.hxx> 
#include <Geom_Line.hxx> 
#include <Geom_Surface.hxx> 
#include <BRepAdaptor_Surface.hxx> 
#include <GeomAbs_CurveType.hxx> 
#include <GeomAdaptor_Curve.hxx> 
#include <GeomTools_Curve2dSet.hxx> 
#include <gp_Vec.hxx> 
#include <Graphic3d_NameOfMaterial.hxx> 
#include <MMgt_TShared.hxx> 
#include <OSD_Environment.hxx> 
#include <Precision.hxx> 
#include <Prs3d_IsoAspect.hxx> 
#include <Prs3d_LineAspect.hxx> 
#include <Prs3d_Projector.hxx> 
#include <Prs3d_Text.hxx> 
#include <Quantity_Factor.hxx> 
#include <Quantity_Length.hxx> 
#include <Quantity_NameOfColor.hxx> 
#include <Quantity_PhysicalQuantity.hxx> 
#include <Quantity_PlaneAngle.hxx> 
#include <Quantity_TypeOfColor.hxx> 
#include <SelectMgr_EntityOwner.hxx> 
#include <SelectMgr_SelectableObject.hxx> 
#include <SelectMgr_Selection.hxx> 
#include <SelectMgr_SelectionManager.hxx> 
#include <SelectMgr_ListOfFilter.hxx> 
#include <SelectMgr_Filter.hxx> 
#include <StdSelect_EdgeFilter.hxx> 
#include <StdSelect_ShapeTypeFilter.hxx> 
#include <Standard_Boolean.hxx> 
#include <Standard_CString.hxx> 
#include <Standard_ErrorHandler.hxx> 
#include <Standard_Integer.hxx> 
#include <Standard_IStream.hxx> 
#include <Standard_Macro.hxx> 
#include <Standard_NotImplemented.hxx> 
#include <Standard_OStream.hxx> 
#include <Standard_Real.hxx> 
#include <StdPrs_Curve.hxx> 
#include <StdPrs_Point.hxx> 
#include <StdPrs_PoleCurve.hxx> 
#include <TCollection_AsciiString.hxx> 
#include <TColgp_Array1OfPnt2d.hxx> 
#include <TColgp_HArray1OfPnt2d.hxx> 
#include <TCollection_AsciiString.hxx> 
#include <TColStd_HSequenceOfTransient.hxx> 
#include <TColStd_MapIteratorOfMapOfTransient.hxx> 
#include <TColStd_MapOfTransient.hxx> 
#include <TopExp_Explorer.hxx> 
#include <TopoDS.hxx> 
#include <TopoDS_Compound.hxx> 
#include <TopoDS_Shape.hxx> 
#include <TopoDS_Solid.hxx> 
#include <TopoDS_Vertex.hxx> 
#include <TopExp.hxx> 
#include <TopTools_HSequenceOfShape.hxx> 
#include <UnitsAPI.hxx> 
#include <V3d_View.hxx> 
#include <V3d_Viewer.hxx> 
#include <WNT_Window.hxx> 


#include <Prs3d_PointAspect.hxx> 
#include <AIS_Point.hxx> 
#include <AIS_InteractiveContext.hxx>
#include <AIS_Shape.hxx>
#include <BRep_Tool.hxx> 
#include <BRepAlgoAPI_Fuse.hxx> 
#include <BRepBuilderAPI_MakeEdge.hxx> 
#include <BRepBuilderAPI_MakeFace.hxx> 
#include <BRepBuilderAPI_MakeWire.hxx> 
#include <BRepBuilderAPI_MakeVertex.hxx> 
#include <BRepBuilderAPI_Transform.hxx> 
#include <BRepPrimAPI_MakeCone.hxx> 
#include <BRepPrimAPI_MakeRevol.hxx> 
#include <BRepFilletAPI_MakeFillet.hxx> 
#include <BRepBuilderAPI_Copy.hxx> 
#include <BRepBuilderAPI_MakePolygon.hxx> 
#include <BRepLib.hxx> 
#include <BRepOffsetAPI_MakeThickSolid.hxx> 
#include <BRepOffsetAPI_ThruSections.hxx> 
#include <BRepPrimAPI_MakeCylinder.hxx> 
#include <BRepPrimAPI_MakePrism.hxx> 
#include <BRepPrimAPI_MakeTorus.hxx> 
#include <BRepAlgoAPI_Section.hxx> 
#include <BRepPrimAPI_MakeSphere.hxx> 
#include <BRepFeat_SplitShape.hxx> 
#include <TColgp_HArray1OfPnt.hxx> 
#include <GeomAPI_Interpolate.hxx> 
#include <GC_MakeArcOfCircle.hxx> 
#include <GC_MakeSegment.hxx> 
#include <GC_MakeCircle.hxx> 
#include <GCE2d_MakeSegment.hxx> 



#include <gp.hxx> 
#include <gp_Ax1.hxx> 
#include <gp_Ax2.hxx> 
#include <gp_Ax2d.hxx> 
#include <gp_Dir.hxx> 
#include <gp_Dir2d.hxx> 
#include <gp_Pnt.hxx> 
#include <gp_Pnt2d.hxx> 
#include <gp_Trsf.hxx> 
#include <gp_Vec.hxx> 
#include <Geom_CylindricalSurface.hxx> 
#include <Geom_Plane.hxx> 
#include <Geom_Surface.hxx> 
#include <Geom_TrimmedCurve.hxx> 
#include <Geom2d_Ellipse.hxx> 
#include <Geom2d_TrimmedCurve.hxx> 
#include <TopExp_Explorer.hxx> 
#include <TopoDS.hxx> 
#include <TopoDS_Edge.hxx> 
#include <TopoDS_Face.hxx> 
#include <TopoDS_Wire.hxx> 
#include <TopoDS_Shape.hxx> 
#include <TopoDS_Compound.hxx> 
#include <GCPnts_AbscissaPoint.hxx> 
#include <BRepAdaptor_Curve.hxx> 
#include <GeomLib.hxx> 



#include <GeomConvert_CompCurveToBSplineCurve.hxx> 
#include <TopTools_ListOfShape.hxx> 
#include <TopTools_ListIteratorOfListOfShape.hxx> 
#include <TopTools_DataMapOfShapeInteger.hxx> 
#include <TopTools_DataMapOfShapeReal.hxx> 
#include <TopTools_IndexedDataMapOfShapeAddress.hxx> 


#include <V3d_PositionalLight.hxx> 
#include <V3d_DirectionalLight.hxx> 
#include <V3d_AmbientLight.hxx> 
#include <IGESControl_Controller.hxx> 
#include <IGESControl_Writer.hxx> 
#include <Interface_Static.hxx> 
#include <OpenGl_GraphicDriver.hxx> 
#include <Graphic3d_GraphicDriver.hxx>

 OpenCASCADE開發案例
1.建立MFC工程

 

 

 

2.stdafx.h頭文件中包含OpenCASCADE頭文件

// stdafx.h : 標準系統包含文件的包含文件,
// 或是經常使用但不常更改的
// 特定於項目的包含文件

#pragma once

#ifndef VC_EXTRALEAN
#define VC_EXTRALEAN // 從 Windows 頭中排除極少使用的資料
#endif

#include "targetver.h"








#define _ATL_CSTRING_EXPLICIT_CONSTRUCTORS // 某些 CString 構造函數將是顯式的

// 關閉 MFC 對某些常見但經常可放心忽略的警告消息的隱藏
#define _AFX_ALL_WARNINGS

#include <afxwin.h> // MFC 核心組件和標準組件
#include <afxext.h> // MFC 擴展


#include <afxdisp.h> // MFC 自動化類

#include <BRepTools.hxx> 
#include <Standard_DefineHandle.hxx> 
#include <DsgPrs_LengthPresentation.hxx> 
#include <GCPnts_TangentialDeflection.hxx> 
#include <Geom_Axis2Placement.hxx> 
#include <Geom_CartesianPoint.hxx> 
#include <Geom_Line.hxx> 
#include <Geom_Surface.hxx> 
#include <BRepAdaptor_Surface.hxx> 
#include <GeomAbs_CurveType.hxx> 
#include <GeomAdaptor_Curve.hxx> 
#include <GeomTools_Curve2dSet.hxx> 
#include <gp_Vec.hxx> 
#include <Graphic3d_NameOfMaterial.hxx> 
#include <MMgt_TShared.hxx> 
#include <OSD_Environment.hxx> 
#include <Precision.hxx> 
#include <Prs3d_IsoAspect.hxx> 
#include <Prs3d_LineAspect.hxx> 
#include <Prs3d_Projector.hxx> 
#include <Prs3d_Text.hxx> 
#include <Quantity_Factor.hxx> 
#include <Quantity_Length.hxx> 
#include <Quantity_NameOfColor.hxx> 
#include <Quantity_PhysicalQuantity.hxx> 
#include <Quantity_PlaneAngle.hxx> 
#include <Quantity_TypeOfColor.hxx> 
#include <SelectMgr_EntityOwner.hxx> 
#include <SelectMgr_SelectableObject.hxx> 
#include <SelectMgr_Selection.hxx> 
#include <SelectMgr_SelectionManager.hxx> 
#include <SelectMgr_ListOfFilter.hxx> 
#include <SelectMgr_Filter.hxx> 
#include <StdSelect_EdgeFilter.hxx> 
#include <StdSelect_ShapeTypeFilter.hxx> 
#include <Standard_Boolean.hxx> 
#include <Standard_CString.hxx> 
#include <Standard_ErrorHandler.hxx> 
#include <Standard_Integer.hxx> 
#include <Standard_IStream.hxx> 
#include <Standard_Macro.hxx> 
#include <Standard_NotImplemented.hxx> 
#include <Standard_OStream.hxx> 
#include <Standard_Real.hxx> 
#include <StdPrs_Curve.hxx> 
#include <StdPrs_Point.hxx> 
#include <StdPrs_PoleCurve.hxx> 
#include <TCollection_AsciiString.hxx> 
#include <TColgp_Array1OfPnt2d.hxx> 
#include <TColgp_HArray1OfPnt2d.hxx> 
#include <TCollection_AsciiString.hxx> 
#include <TColStd_HSequenceOfTransient.hxx> 
#include <TColStd_MapIteratorOfMapOfTransient.hxx> 
#include <TColStd_MapOfTransient.hxx> 
#include <TopExp_Explorer.hxx> 
#include <TopoDS.hxx> 
#include <TopoDS_Compound.hxx> 
#include <TopoDS_Shape.hxx> 
#include <TopoDS_Solid.hxx> 
#include <TopoDS_Vertex.hxx> 
#include <TopExp.hxx> 
#include <TopTools_HSequenceOfShape.hxx> 
#include <UnitsAPI.hxx> 
#include <V3d_View.hxx> 
#include <V3d_Viewer.hxx> 
#include <WNT_Window.hxx> 


#include <Prs3d_PointAspect.hxx> 
#include <AIS_Point.hxx> 
#include <AIS_InteractiveContext.hxx>
#include <AIS_Shape.hxx>
#include <BRep_Tool.hxx> 
#include <BRepAlgoAPI_Fuse.hxx> 
#include <BRepBuilderAPI_MakeEdge.hxx> 
#include <BRepBuilderAPI_MakeFace.hxx> 
#include <BRepBuilderAPI_MakeWire.hxx> 
#include <BRepBuilderAPI_MakeVertex.hxx> 
#include <BRepBuilderAPI_Transform.hxx> 
#include <BRepPrimAPI_MakeCone.hxx> 
#include <BRepPrimAPI_MakeRevol.hxx> 
#include <BRepFilletAPI_MakeFillet.hxx> 
#include <BRepBuilderAPI_Copy.hxx> 
#include <BRepBuilderAPI_MakePolygon.hxx> 
#include <BRepLib.hxx> 
#include <BRepOffsetAPI_MakeThickSolid.hxx> 
#include <BRepOffsetAPI_ThruSections.hxx> 
#include <BRepPrimAPI_MakeCylinder.hxx> 
#include <BRepPrimAPI_MakePrism.hxx> 
#include <BRepPrimAPI_MakeTorus.hxx> 
#include <BRepAlgoAPI_Section.hxx> 
#include <BRepPrimAPI_MakeSphere.hxx> 
#include <BRepFeat_SplitShape.hxx> 
#include <TColgp_HArray1OfPnt.hxx> 
#include <GeomAPI_Interpolate.hxx> 
#include <GC_MakeArcOfCircle.hxx> 
#include <GC_MakeSegment.hxx> 
#include <GC_MakeCircle.hxx> 
#include <GCE2d_MakeSegment.hxx> 



#include <gp.hxx> 
#include <gp_Ax1.hxx> 
#include <gp_Ax2.hxx> 
#include <gp_Ax2d.hxx> 
#include <gp_Dir.hxx> 
#include <gp_Dir2d.hxx> 
#include <gp_Pnt.hxx> 
#include <gp_Pnt2d.hxx> 
#include <gp_Trsf.hxx> 
#include <gp_Vec.hxx> 
#include <Geom_CylindricalSurface.hxx> 
#include <Geom_Plane.hxx> 
#include <Geom_Surface.hxx> 
#include <Geom_TrimmedCurve.hxx> 
#include <Geom2d_Ellipse.hxx> 
#include <Geom2d_TrimmedCurve.hxx> 
#include <TopExp_Explorer.hxx> 
#include <TopoDS.hxx> 
#include <TopoDS_Edge.hxx> 
#include <TopoDS_Face.hxx> 
#include <TopoDS_Wire.hxx> 
#include <TopoDS_Shape.hxx> 
#include <TopoDS_Compound.hxx> 
#include <GCPnts_AbscissaPoint.hxx> 
#include <BRepAdaptor_Curve.hxx> 
#include <GeomLib.hxx> 



#include <GeomConvert_CompCurveToBSplineCurve.hxx> 
#include <TopTools_ListOfShape.hxx> 
#include <TopTools_ListIteratorOfListOfShape.hxx> 
#include <TopTools_DataMapOfShapeInteger.hxx> 
#include <TopTools_DataMapOfShapeReal.hxx> 
#include <TopTools_IndexedDataMapOfShapeAddress.hxx> 


#include <V3d_PositionalLight.hxx> 
#include <V3d_DirectionalLight.hxx> 
#include <V3d_AmbientLight.hxx> 
#include <IGESControl_Controller.hxx> 
#include <IGESControl_Writer.hxx> 
#include <Interface_Static.hxx> 
#include <OpenGl_GraphicDriver.hxx> 
#include <Graphic3d_GraphicDriver.hxx>


#ifndef _AFX_NO_OLE_SUPPORT
#include <afxdtctl.h> // MFC 對 Internet Explorer 4 公共控制項的支援
#endif
#ifndef _AFX_NO_AFXCMN_SUPPORT
#include <afxcmn.h> // MFC 對 Windows 公共控制項的支援
#endif // _AFX_NO_AFXCMN_SUPPORT

#include <afxcontrolbars.h> // 功能區和控制項條的 MFC 支援



#ifdef _UNICODE#if defined _M_IX86#pragma comment(linker,"/manifestdependency:\"type='win32' name='Microsoft.Windows.Common-Controls' version='6.0.0.0' processorArchitecture='x86' publicKeyToken='6595b64144ccf1df' language='*'\"")#elif defined _M_X64#pragma comment(linker,"/manifestdependency:\"type='win32' name='Microsoft.Windows.Common-Controls' version='6.0.0.0' processorArchitecture='amd64' publicKeyToken='6595b64144ccf1df' language='*'\"")#else#pragma comment(linker,"/manifestdependency:\"type='win32' name='Microsoft.Windows.Common-Controls' version='6.0.0.0' processorArchitecture='*' publicKeyToken='6595b64144ccf1df' language='*'\"")#endif#endif 

 

3.mfcoccc.h文件中創建三維引擎句柄,

Handle(Graphic3d_GraphicDriver) m_GraphicDriver;
Handle(Graphic3d_GraphicDriver) GetGraphicDriver() { return m_GraphicDriver; }

4.mfcocccDoc.h文件中聲明上下文和顯示view句柄,繪圖函數聲明

Handle(AIS_InteractiveContext) myAISContext; Handle(V3d_Viewer) myViewer; Handle(V3d_Viewer) GetViewer(void) { return myViewer; } void DrawSphere(double Radius); void DrawBox(double MyHeight,double MyWidth,double MyThickness); //畫盒子5.mfcocccView.h中聲明視圖句柄

Handle(V3d_View) myView;6.實現程式碼較多,這裡就不一一列出來了

7.案例達到的效果如下,是一個立體的空瓶子。

 

 

 

源碼載地址://download.csdn.net/download/xipengbozai/18884650
————————————————
版權聲明:本文為CSDN部落客「卷積神經網路」的原創文章,遵循CC 4.0 BY-SA版權協議,轉載請附上原文出處鏈接及本聲明。
原文鏈接://blog.csdn.net/xipengbozai/article/details/117044032

Tags: