[OpenCascade] Mouse click to determine the corresponding point on the model

In the process of establishing the dimension line, it is necessary to realize the function of selecting any point on the surface by clicking the mouse. There is no corresponding solution to this problem in the OCC document. Refer to some ideas given on the Internet to finally realize this function.

general idea

  • after mouse click
  • First determine the direction perpendicular to the screen at this time
  • Create a line at the mouse position to run in a straight line perpendicular to the screen
  • Find the intersection point of the line and the model
  • Find the corresponding selected point

Implementation

// 确定一条垂直于屏幕的线 用到的函数有:
void Convert (const Standard_Integer Xp,	// 输入鼠标坐标
		      const Standard_Integer Yp,
              Standard_Real& X,						// 输出X,Y,Z
              Standard_Real& Y,
              Standard_Real& Z) const;
              
void Proj (Standard_Real& Vx, Standard_Real& Vy, Standard_Real& Vz) const; // 当前投影方向
// 根据一点及其方向可以确定该线

// 至于确定线和曲面的交点 
// 可以用OCC的IntCurvesFace_ShapeIntersector类来实现

achieve results

Taking a brep data provided by OCC as an example, the functions are as follows.
insert image description here

Guess you like

Origin blog.csdn.net/weixin_41243045/article/details/90143259