Opencascade子類化AIS_PointCloud實現自定義顯示和選擇樣式


//Opencascade負責繪制的“Drawer” 有3個,分別是:

//1.myDrawer    main presentation attributes

//2.myHilightDrawer  custom presentation attributes for highlighting selected object

//3.myDynHilightDrawer  custom presentation attributes for highlighting detected object

//2和3是可選的,但如果需要對鼠標懸浮或者選中時,幾何元素有不同的顏色,線型等做進一步控制

//則需要定義2和3的行為。

 

//定義子類myAisPointCloud .h

//myAisPointCloud .h

class myAisPointCloud :public AIS_PointCloud

{

public:

  bmAisPointCloud(const std::vector<gp_Pnt>& vecPoint);

  Standard_Boolean AcceptDisplayMode(const Standard_Integer aMode) const Standard_OVERRIDE;

private:

void Compute (const Handle(PrsMgr_PresentationManager3d)& aPresentationManager,
        const Handle(Prs3d_Presentation)& aPresentation,
        const Standard_Integer aMode);

void ComputeSelection(const Handle(SelectMgr_Selection)& aSelection, const Standard_Integer aMode);

//

};

//myAisPointCloud .cpp

//構造函數

myAisPointCloud ::myAisPointCloud (const std::vector<gp_Pnt>& vecPoint)
:AIS_PointCloud()
{

  //myDrawer的顯示樣式,顏色,線性和線寬

  Handle(Prs3d_LineAspect) myLineAspect = new Prs3d_LineAspect(Quantity_NOC_GREEN, Aspect_TOL_SOLID, 2);
  myDrawer->SetLineAspect(myLineAspect);

  /myHilightDrawer的顯示樣式,顏色,線性和線寬

  Handle(Prs3d_LineAspect) myHilightLineAspect = new Prs3d_LineAspect(Quantity_NOC_GREEN, Aspect_TOL_SOLID, 4);
  myHilightDrawer->SetLineAspect(myHilightLineAspect);
  myHilightDrawer->SetColor( Quantity_NOC_GREEN);

      // MY_MODE 非0整數

  myHilightDrawer->SetDisplayMode(MY_MODE);

  /myDynHilightDrawer的顯示樣式,顏色,線性和線寬

  Handle(Prs3d_LineAspect) myDynHilightLineAspect = new Prs3d_LineAspect(Quantity_NOC_GREEN, Aspect_TOL_SOLID, 4);
  COLORREF MSColor = RGB(111, 0, 204);
  Quantity_Color CSFColor = Quantity_Color(GetRValue(MSColor) / 255., GetGValue(MSColor) / 255., GetBValue(MSColor) / 255., Quantity_TOC_RGB);
  myDynHilightDrawer->SetLineAspect(myDynHilightLineAspect);
  myDynHilightDrawer->SetColor(CSFColor.Name());

  myDynHilightDrawer->SetDisplayMode(MY_MODE);

}

Standard_Boolean myAisPointCloud ::AcceptDisplayMode(const Standard_Integer aMode) const
{
  return aMode == 0|| aMode == MY_MODE;
}

void bmAisPointCloud::Compute(const Handle(PrsMgr_PresentationManager3d)&  aPresentationManager ,const Handle(Prs3d_Presentation)& thePrs,const Standard_Integer aMode)

{
   switch (aMode)
  {  
    case AIS_PointCloud::DM_Points:
    case MY_MODE:
    {
    const Handle(Graphic3d_ArrayOfPoints) aPoints = GetPoints();
    if (aPoints.IsNull())
    {
      return;
    }
    Handle(Graphic3d_Group) aGroup = thePrs->NewGroup();

  //點雲是通過mark來呈現

  Handle(Graphic3d_AspectMarker3d) aMarker = new Graphic3d_AspectMarker3d(Aspect_TOM_POINT, Quantity_NOC_GREEN, 1.0);

  //點的放大比例設為2.5
  aMarker->SetScale(2.5);

  Handle(Graphic3d_AspectMarker3d) asp;

  //設置鼠標hover時單個點的顯示樣式

  asp = myDynHilightDrawer->PointAspect()->Aspect();

  //加號“ + ”樣式
  asp->SetType(Aspect_TOM_PLUS);

  //綠色
  asp->SetColor(Quantity_NOC_GREEN); 

    

 

 

  //設置被選中時(整體或者局部選中)顯示樣式

  asp = myHilightDrawer->PointAspect()->Aspect();

  //加號“ + ”樣式
  asp->SetType(Aspect_TOM_PLUS);

  //黑色
  asp->SetColor(Quantity_NOC_BLACK);

   

  //設置當前GroupPrimitives的Marker aspect

  aGroup->SetGroupPrimitivesAspect(aMarker);

  //將點雲add到PrimitiveArray

  aGroup->AddPrimitiveArray(aPoints);
  break;
      }

  //點雲作為整體選中的樣式,顯示包圍盒

      case AIS_PointCloud::DM_BndBox:
  {
  Bnd_Box aBndBox = GetBoundingBox();
  if (aBndBox.IsVoid())
  {
    return;
  }

  StdPrs_BndBox::Add(thePrs, aBndBox, AIS_PointCloud::myDrawer);
  break;

  }
}

}


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM