기본 콘텐츠로 건너뛰기

라벨이 OpenCascade인 게시물 표시

여러개의 Edge에서 Wire 생성하기

다음과 같은 순서를 따라 여러개의 Edge에서 Wire를 생성할 수 있습니다. 1. ShapeAnalysis_FreeBounds::ConnectEdgesToWires 2. ShapeFix_Wire 클래스를 이용하여 Fix 3. ShapeAnalysis_FreeBounds::Connect WiresToWires TopExp_Explorer exp, exp2; TopoDS_Wire wire, outWireShape; TopoDS_Face newface; for(exp.Init(box, TopAbs_FACE); exp.More(); exp.Next()) { newface = TopoDS::Face(exp.Current()); outWireShape = TopoDS::Wire(BRepTools::OuterWire(newface)); for(exp2.Init(newface, TopAbs_WIRE); exp2.More(); exp2.Next()) { wire = TopoDS::Wire(exp2.Current()); if(wire==outWireShape) continue; BRepTools_ReShape reshaper; reshaper.Remove(wire); newface = TopoDS::Face(reshaper.Apply (newface)); } } 제목 Probleme creating a face with holes How to catch the exceptions? http://www.opencascade.org/org/forum/thread_26207/?forum=3 http://www.opencascade.org/org/forum/thread_24784/?forum=3 http://www.opencascade.org/org/forum/thread_23492/?forum=3

OpenCASCADE 6.6.0 빌드하기

1. 환경 변수 설정하기 OpenCASCADE 6.6.0은 이전 버젼과 바이너리 호환이 되지 않습니다. 따라서 이전 버젼으로 작성된 프로젝트는 소스를 다시 컴파일해야만 합니다.

Dgn File(J format) Viewer

OCC로 만들어 본 Dgn File(J format) Viewer입니다. 여기서 다운 로드 하세요

OCC 버그?

같은 위치, 같은 반지름으로 타원과 원을 생성하여 회전체를 생성했을 때 그 결과가 다르게 나타났습니다. 아래는 결과를 캡쳐한 이미지입니다. 타원으로 회전체를 생성했을 때 위에서 그림이 제대로 보이지 않아 마우스를 올려놓아 highlight 시켰을 때 원으로 회전체를 생성했을 때 위 그림을 보시면 타원으로 생성했을때는 결과가 제대로 나타나지 않는 것을 알수가 있습니다. 제가 테스트에 사용한 것은 OpenCASCADE6.3.0 입니다. 이후 버젼은 위의 내용이 수정되었는지 궁금하네요...

Hole in solid

Solid에 구멍을 만드는 예제입니다. //The cylinder gp_Pnt neckLocation ( gp_Pnt ( 30 , 30 , 0 ) ) ; gp_Dir neckNormal = gp :: DZ ( ) ; gp_Ax2 neckAx2 ( neckLocation , neckNormal ) ; TopoDS_Shape aHole = BRepPrimAPI_MakeCylinder ( neckAx2 , 10 , 60 ) ; //The cube TopoDS_Shape box = BRepPrimAPI_MakeBox ( gp_Pnt ( 0 , 0 , 0 ) , 60 , 60 , 60 ) ; //Cube - Cylinder TopoDS_Shape result = BRepAlgoAPI_Cut ( box , aHole ) ; return result ;

Surface of revolution 예제

아래는 OCC에 들어 있는 예제중의 하나 입니다. TopoDS_Edge E1 = BRepBuilderAPI_MakeEdge ( gp_Pnt ( 0 . , 0 . , 0 . ) , gp_Pnt ( 50 . , 0 . , 0 . ) ) ; TopoDS_Edge E2 = BRepBuilderAPI_MakeEdge ( gp_Pnt ( 50 . , 0 . , 0 . ) , gp_Pnt ( 50 . , 50 . , 0 . ) ) ; TopoDS_Edge E3 = BRepBuilderAPI_MakeEdge ( gp_Pnt ( 50 . , 50 . , 0 . ) , gp_Pnt ( 0 . , 0 . , 0 . ) ) ; TopoDS_Wire W = BRepBuilderAPI_MakeWire ( E1 , E2 , E3 ) ; gp_Ax1 axe = gp_Ax1 ( gp_Pnt ( 0 . , 0 . , 30 . ) , gp_Dir ( 0 . , 1 . , 0 . ) ) ; ///Handle(Geom_Axis1Placement) Gax3 = new Geom_Axis1Placement(axe); /// i don't know why below code raises error ///Handle (AIS_Axis) ax3 = new AIS_Axis(Gax3); ///m_hAISContext->Display(ax3,Standard_False); TopoDS_Shape S3 = BRepPrimAPI_MakeRevol ( W , axe , 210 . * PI180 ) ; Handle ( AIS_Shape ) ais5 = new AIS_Shape ( W ) ; m_hAISContext - > Display ( ais5 , Standard_True ) ; Handle ( AIS_Shape ) ais6 = new AIS_Shape ( S3 ) ; m_hAISContext - > SetColo...

BREP 데이타 출력

아래는 BREP 데이타를 출력하는 코드입니다. BRep_Builder B ; TopoDS_Shape S1 ; BRepTools :: Read ( S1 , lpszPathName , B ) ; if ( S1 . IsNull ( ) ) { AfxMessageBox ( _T ( " Shape(s) not found. " ) , MB_ICONERROR ) ; } else { Handle_AIS_Shape hAISShape = new AIS_Shape ( S1 ) ; hAISShape - > SetColor ( Quantity_NOC_GREEN ) ; hAISShape - > SetMaterial ( Graphic3d_NOM_PLASTIC ) ; m_hAISContext - > Display ( hAISShape , false ) ; }

How to pick object?

앞에서는 영역을 잡아서 object를 선택하는 것에 대해서 알아 봤는데, 이번에는 click하여 object를 선택하는 것에 대해서 알아보겠습니다. 아래와 같이 Select함수를 사용하게 되는데요 1 Standard_EXPORT AIS_StatusOfPick Select( const  Standard_Boolean updateviewer  =  Standard_True) ; cs 인자로 click한 좌표를 넘겨주지 않습니다. 그럼 어떻게 object를 선택할까요?(좌표없이 말이죠...) 이 함수는 highlight된 object를 선택하는 함수입니다. 따라서 이 Select 함수를 호출하기 전에 선택할 object가 highlight되어있어야 합니다. highlight는 마우스가 움직일때 MoveTo 함수를 통해서 쉽게 할수가 있습니다. 그림을 보시면 마우스 커서 밑의 원이 highlight된것을 볼수가 있습니다. 형상들을 선택한 후 color dialog에서 변경할 색상을 선택한 후에 선택한 형상의 색상을 변경합니다. 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 Quantity_Color CSFColor ; COLORREF MSColor ;        m_hAISContext - > Select(); m_hAISContext - > InitSelected(); if  (m_hAISContext - > MoreSelected()) {     m_hAISContext - > InitCurrent();    ...

선택한 형상의 색상 변경하기

영역으로 형상을 선택하고 선택한 형상의 색상을 변경하는 방법을 알아보도록 하겠습니다. 간단히 그림과 코드로 살펴보겠습니다. 형상들을 선택한 후 color dialog에서 변경할 색상을 선택한 후에 선택한 형상의 색상을 변경합니다. void CLibMesh2dTestCaseDoc :: InputEvent ( const Standard_Integer cXmin , const Standard_Integer cYmin , const Standard_Integer cXmax , const Standard_Integer cYmax , const Handle ( V3d_View ) & aView ) { Quantity_Color CSFColor ; COLORREF MSColor ; m_hAISContext - > Select ( cXmin , cYmin , cXmax , cYmax , aView ) ; m_hAISContext - > InitSelected ( ) ; if ( m_hAISContext - > MoreSelected ( ) ) { m_hAISContext - > InitCurrent ( ) ; Handle_AIS_InteractiveObject Current = m_hAISContext - > Current ( ) ; if ( Current - > HasColor ( ) ) { CSFColor = m_hAISContext - > Color ( Current ) ; MSColor = RGB ( CSFColor . Red ( ) * 255 . , CSFColor . Green ( ) * 255 . , CSFColor . Blue ( ) * 255 . ) ; } else { MSColor ...

Colorbar 표현하기

일반적으로 contour를 표현하는 프로그램을 보면 오른쪽 상단에 레벨별로 색상을 표현한 colorbar를 볼수가 있습니다. 이를 한번 구현해 보았습니다. 일단 Layer를 하나 만들고 그 위에 colorbar를 표기하도록 하였습니다. 신경쓰였던 부분은 윈도우의 크기가 변경될때 어떻게 colorbar의 크기를 일정하게 유지하는냐 하는 것이었습니다. 이렇게 해서 제가 원하는 colorbar를 표현하는데 성공했습니다.!!! 코드는 아래에... 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 glPushAttrib (GL_LIST_BIT);  charbuf[ 20 ]  =  { '\0' ,};  Quantity_Color color( 1. 0 ,  1. 0 ,  0. 0 , Quantity_TOC_RGB);  aToppestLayer - > SetColor(color);    //! pixel 단위의 colorbar의 min,max를 구한다. double  minx  =  right  -  (right  -  left) * 70 / w;  double  maxx  =  right  -  (right  -  left) * 50 / w;  double  maxy  =  top  -  (top  -  bottom) * 20 / h;  double  miny  =  top  -  (top  - ...

Gradient Background 표현하기

OpenCASCADE 6.5.0이상에서는 단 한줄의 코드로 Gradient Background color를 설정할 수 있습니다. 관련 링크 --------------------------------------------------------------------------------- 원문은 아래에서 확인하실 수 있습니다. http://sondra.egloos.com/5446008 MFC를 사용한다면 OnSize Mehtod에 원문의 코드를 넣으면 됩니다. 원문에 있는 코드를 사용해보니 윈도우의 크기가 변경될 때마다 gradient 색상이 조금씩 차이가 나는걸 발견하였습니다. 그 이유를 수소문해보니(?) 윈도우의 크기에 따라 opengl의 직교 좌표계의 범위를 OCC가 계산하여 설정하는 것을 알았습니다. 즉 우리가 layer에서 SetOrtho 함수를 사용하여 좌표계의 범위를 주어도 OCC에서 그댈 사용하지 않고 다시 계산하여 최종적으로 그 값을 사용하는 것입니다. 다행히 OCC에서 소스를 제공하니 소스에서 좌표계를 계산하는 루틴을 알수가 있습니다. 그 값을 적용하여 gradient를 그려주면 윈도우의 크기가 변경될때 마다 색상 차이가 나는 것을 방지할 수 있습니다.  1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 if (aBackgroundLayer.IsNull())  {      Standard_Boolean aSizeDependant  =  Standard_True;  //each window to have particular mapped layer?   ...

entity 색상 설정하기

gp_Circ gpCircle ; gpCircle . SetLocation ( center ) ; gpCircle . SetRadius ( dRadius ) ; Handle ( Geom_Circle ) aCircle = :: new Geom_Circle ( gpCircle ) ; Handle ( AIS_Circle ) hCircle = :: new AIS_Circle ( aCircle ) ; //! set red color7 Quantity_Color color(1.0, 0.0, 0.0, Quantity_TOC_RGB); m_pAISContext - > SetColor ( hCircle , color ) ; m_pAISContext - > Display ( hCircle , true ) ; 2011.08.25; m_pAISContext->Display 함수를 호출하면 화면이 바로 갱신되는 문제(?)가 있습니다. 이 문제를 피하고 싶으면 AIS 객체의 색상의 설정해 주면 됩니다. Handle ( AIS_Circle ) hCircle = :: new AIS_Circle ( aCircle ) ; Quantity_Color aColor ( 1.0 , 0.0 , 0.0 , Quantity_TOC_RGB ) ; hCircle - > SetColor ( aColor ) ;

Circle 그리기

gp_Circ gpCircle ; gpCircle . SetLocation ( center ) ; gpCircle . SetRadius ( dRadius ) ; Handle ( Geom_Circle ) aCircle = new Geom_Circle ( gpCircle ) ; Handle ( AIS_Circle ) hCircle = new AIS_Circle ( aCircle ) ; m_pAISContext - > Display ( hCircle , true ) ; Handle(Geom_Circle) aCircle = new Geom_Circle(gpCircle); 로 생성했는데 이를 해제하지 않아서 영~~ 찝찝하네요... 2011.08.25; 메모리 관리는 OCC에서 하는 것으로 보입니다.

UserType.dat 사용하기

OpenCasCade 배포판에서 UserType.dat 파일도 함께 배포하고 있습니다. (배포판 설치 폴더의 Tools 폴더 안에 보면 UserType.dat 파일이 있습니다.) 다들 아시다시피 이것을 사용하면 사용자 정의 Type도 highlighting할수 있습니다. 이 UserType.dat 파일을 예를 들면 C:\Program Files\Microsoft Visual Studio 9.0\Common7\IDE 폴더에 복사해 두면 OCC관련 Type들이 highlighting됩니다. 1 2 3 4 5 6 7 8 9 10 void  C3DWnd::DisplayAxis() {     CLibMesh2dTestCaseView *  pView  =  (CLibMesh2dTestCaseView * )GetParent();     CLibMesh2dTestCaseDoc *  pDoc  =  (CLibMesh2dTestCaseDoc * )pView - > GetDocument();       Handle(AIS_Trihedron) aTrihedron;     Handle(Geom_Axis2Placement) anAxis  =   new  Geom_Axis2Placement(gp::XOY());     aTrihedron  =   new  AIS_Trihedron(anAxis);     pDoc - > m_pAISContext - > Display(aTrihedron); } Colored by Color Scripter cs

Graphic Initialisation Error

앞의 테스트 코드를 오래간만에 컴파일 하여 실행할려니 "Fatal Error During Graphic Initialisation" 메세지가 뜨면서 종료가 되는게 아니겠습니까? 1시간 가량을 원인을 찾다가 어쩔수 없이 OpenCasCade를 다시 설치하였습니다. 그랬더니 에러없이 테스트 프로그램이 실행되었습니다. 도대체 뭐가 문제인지 아는 사람있으면 알려주세요 제발~~ 아래에서 에러가 발생했어요~~ CLibMesh2dTestCaseApp::CLibMesh2dTestCaseApp() { try { m_pGraphicDevice = ::new Graphic3d_WNTGraphicDevice; } catch(Standard_Failure a) { AfxMessageBox("Fatal Error During Graphic Initialisation"); ExitProcess(1); }; } 해결 : 환경변수중에서 CSF_GraphicShr 가 TKOpenGl.dll 을 제대로 가리키고 있는지 확인하세요!!! 저의 경우는 CSF_GraphicShr를 다시 알맞게 변경하니 해결되었습니다.

OpenCasCade - Face에 색상 설정

아래 코드를 참조하세요... Handle(Geom_TrimmedCurve) aSegment1 = GC_MakeSegment(pnt1 , pnt2); Handle(Geom_TrimmedCurve) aSegment2 = GC_MakeSegment(pnt2 , pnt3); Handle(Geom_TrimmedCurve) aSegment3 = GC_MakeSegment(pnt3 , pnt1); TopoDS_Edge aEdge1 = BRepBuilderAPI_MakeEdge(aSegment1); TopoDS_Edge aEdge2 = BRepBuilderAPI_MakeEdge(aSegment2); TopoDS_Edge aEdge3 = BRepBuilderAPI_MakeEdge(aSegment3); TopoDS_Wire aWire = BRepBuilderAPI_MakeWire(aEdge1 , aEdge2 , aEdge3); TopoDS_Face aFace = BRepBuilderAPI_MakeFace(aWire); Handle(AIS_Shape) aShape = ::new AIS_Shape(aFace); aShape->SetColor(Quantity_NOC_CORAL); //! 칼라 설정 m_pAISContext->SetMaterial(aShape , Graphic3d_NOM_DEFAULT); //! Material 정보는 DEFAULT로 m_pAISContext->SetDisplayMode(aShape,1,Standard_False); m_pAISContext->Display(aShape , false); 아래는 칼라 정보로 사용할수 있는 열거형 값입니다. enum Quantity_NameOfColor { Quantity_NOC_BLACK, Quantity_NOC_MATRABLUE, Quantity_NOC_MATRAGRAY, Quantity_NOC_ALICEBLUE, Quantity_NOC_ANTIQUEWHITE, Quanti...