OpenCasCade(OCC) 显示导入的点云数据(MFC+OCC)

1、首先需要定义显示点的函数

//ISession_Point.h
// ISession_Point.h: interface for the ISession_Point class.
//
//

#if !defined(AFX_ISESSION_POINT_H__A9B277C3_A69E_11D1_8DA4_0800369C8A03__INCLUDED_)
#define AFX_ISESSION_POINT_H__A9B277C3_A69E_11D1_8DA4_0800369C8A03__INCLUDED_

#if _MSC_VER >= 1000
#pragma once
#endif // _MSC_VER >= 1000

#include <Standard_Macro.hxx>
#include <Standard_DefineHandle.hxx>

class ISession_Point;
DEFINE_STANDARD_HANDLE(ISession_Point,AIS_InteractiveObject)
class ISession_Point : public AIS_InteractiveObject  
{
public:
	ISession_Point();
	ISession_Point(Standard_Real X,Standard_Real Y ,Standard_Real Z);
	ISession_Point(const gp_Pnt2d& aPoint,Standard_Real Elevation = 0);
	ISession_Point(const gp_Pnt& aPoint);
	virtual ~ISession_Point();
	DEFINE_STANDARD_RTTIEXT(ISession_Point,AIS_InteractiveObject)

private :

        void Compute (const Handle(PrsMgr_PresentationManager3d)& aPresentationManager,
		const Handle(Prs3d_Presentation)& aPresentation,
		const Standard_Integer aMode);
	    void Compute (const Handle(Prs3d_Projector)& aProjector,
		const Handle(Prs3d_Presentation)& aPresentation);
	   void ComputeSelection (const Handle(SelectMgr_Selection)& aSelection,
		const Standard_Integer unMode);
	   gp_Pnt myPoint;
};

#endif // !defined(AFX_ISESSION_POINT_H__A9B277C3_A69E_11D1_8DA4_0800369C8A03__INCLUDED_)

//ISession_Point.cpp
// ISession_Point.cpp: implementation of the ISession_Point class.
//
//

#include "stdafx.h"
#include "ISession_Point.h"
#include <StdPrs_Point.hxx>

#ifdef _DEBUG
#undef THIS_FILE
static char THIS_FILE[]=__FILE__;
//#define new DEBUG_NEW
#endif

IMPLEMENT_STANDARD_RTTIEXT(ISession_Point,AIS_InteractiveObject)

	//
	// Construction/Destruction
	//
	ISession_Point::ISession_Point(Standard_Real X,Standard_Real Y ,Standard_Real Z)
	:myPoint(gp_Pnt(X,Y,Z))
{

}

ISession_Point::ISession_Point(const gp_Pnt2d& aPoint,Standard_Real Elevation)
	:myPoint(gp_Pnt(aPoint.X(),aPoint.Y(),Elevation))
{

}

ISession_Point::ISession_Point(const gp_Pnt& aPoint)
	:myPoint(aPoint)
{

}

ISession_Point::~ISession_Point()
{

}

void ISession_Point::Compute(const Handle(PrsMgr_PresentationManager3d)& /*aPresentationManager*/,
	const Handle(Prs3d_Presentation)& aPresentation,
	const Standard_Integer /*aMode*/)
{
	Handle(Geom_CartesianPoint) aGeomPoint = new Geom_CartesianPoint(myPoint);

	StdPrs_Point::Add(aPresentation,aGeomPoint,myDrawer);
}


void ISession_Point::Compute(const Handle(Prs3d_Projector)& /*aProjector*/,
	const Handle(Prs3d_Presentation)& /*aPresentation*/) 
{
}

void ISession_Point::ComputeSelection(const Handle(SelectMgr_Selection)& /*aSelection*/, 
	const Standard_Integer /*unMode*/)
{
}


2、编写显示的点云数据的函数

//其中PointXYZ是自己定义的存储X,Y,Z的类
void CXXView::showClouddata(vector<PointXYZ> MeasSurfaceXYZ)//显示点云数据
{
	//读取文件的数据
	//获取测量值的曲面信息
	//获取上下文的AIS_InteractiveContext
	Handle(AIS_InteractiveContext) myAISContext = GetDocument()->GetIC();
	size_t sizev = MeasSurfaceXYZ.size();
	for (size_t i =0;i<sizev;i++)
	{
		gp_Pnt p(MeasSurfaceXYZ[i].X,MeasSurfaceXYZ[i].Y,MeasSurfaceXYZ[i].Z);
		Handle(ISession_Point) iPoint = new ISession_Point(p);
		myAISContext->Display(iPoint,Standard_False);
	}
}

3、在其他类中可以直接调用,显示点云数据。
在这里插入图片描述

猜你喜欢

转载自blog.csdn.net/qq_40247982/article/details/106144917