https://github.com/eryar/occQt/wiki/Make-Helix-Shape-in-occQt
OpenCASCADE 로 Spring 형상 만드는 방법..
아래는 tcl 코드..
#
# make helix torus(Ring Type Spring) in OpenCASCADE.
# Shing Liu(eryar@163.com)
# 2016-02-20 21:00
#
pload MODELING VISUALIZATION
# use torus surface.
torus aTorus 10 2
set aSlope 0.05
line aLine2d 0 0 $aSlope 1
trim aSegment aLine2d 0 2*pi
# make edge by the pcurve.
mkedge aHelixEdge aSegment aTorus 0 2*pi/$aSlope
# there is no curve 3d in the pcurve edge.
# so need this to approximate one.
mkedgecurve aHelixEdge 0.01
wire aHelixWire aHelixEdge
# make the profile.
circle aProfile 12 0 0 1 1 1 0.3
mkedge aProfile aProfile
wire aProfile aProfile
mkplane aProfile aProfile
# display the profile.
vdisplay aProfile aHelixEdge
# loft the circle along the helix curve.
pipe aSpring aHelixWire aProfile
# display the result.
vdisplay aSpring
#vsetmaterial aSpring steel
vsetgradientbg 180 200 255 180 180 180 2
vsetdispmode 1
vzbufftrihedron
set ray tracing
if { ! [catch {vrenderparams -raytrace -shadows -reflections -fsaa -rayDepth 5}] } {
vtextureenv on 1
}
아래는 c++ 로 바꾼 코드.. (출처: https://github.com/eryar/occQt/blob/master/occQt.cpp)
void occQt::testHelix()
{
makeCylindricalHelix();
makeConicalHelix();
makeToroidalHelix();
}
void occQt::makeCylindricalHelix()
{
Standard_Real aRadius = 3.0;
Standard_Real aPitch = 1.0;
// the pcurve is a 2d line in the parametric space.
gp_Lin2d aLine2d(gp_Pnt2d(0.0, 0.0), gp_Dir2d(aRadius, aPitch));
Handle(Geom2d_TrimmedCurve) aSegment = GCE2d_MakeSegment(aLine2d, 0.0, M_PI * 2.0).Value();
Handle(Geom_CylindricalSurface) aCylinder = new Geom_CylindricalSurface(gp::XOY(), aRadius);
TopoDS_Edge aHelixEdge = BRepBuilderAPI_MakeEdge(aSegment, aCylinder, 0.0, 6.0 * M_PI).Edge();
gp_Trsf aTrsf;
aTrsf.SetTranslation(gp_Vec(0.0, 120.0, 0.0));
BRepBuilderAPI_Transform aTransform(aHelixEdge, aTrsf);
Handle(AIS_Shape) anAisHelixCurve = new AIS_Shape(aTransform.Shape());
myOccView->getContext()->Display(anAisHelixCurve, Standard_True);
// sweep a circle profile along the helix curve.
// there is no curve3d in the pcurve edge, so approx one.
BRepLib::BuildCurve3d(aHelixEdge);
gp_Ax2 anAxis;
anAxis.SetDirection(gp_Dir(0.0, 4.0, 1.0));
anAxis.SetLocation(gp_Pnt(aRadius, 0.0, 0.0));
gp_Circ aProfileCircle(anAxis, 0.3);
TopoDS_Edge aProfileEdge = BRepBuilderAPI_MakeEdge(aProfileCircle).Edge();
TopoDS_Wire aProfileWire = BRepBuilderAPI_MakeWire(aProfileEdge).Wire();
TopoDS_Face aProfileFace = BRepBuilderAPI_MakeFace(aProfileWire).Face();
TopoDS_Wire aHelixWire = BRepBuilderAPI_MakeWire(aHelixEdge).Wire();
BRepOffsetAPI_MakePipe aPipeMaker(aHelixWire, aProfileFace);
if (aPipeMaker.IsDone())
{
aTrsf.SetTranslation(gp_Vec(8.0, 120.0, 0.0));
BRepBuilderAPI_Transform aPipeTransform(aPipeMaker.Shape(), aTrsf);
Handle(AIS_Shape) anAisPipe = new AIS_Shape(aPipeTransform.Shape());
anAisPipe->SetColor(Quantity_NOC_CORAL);
myOccView->getContext()->Display(anAisPipe, Standard_True);
}
}
/**
* make conical helix, it is the same as the cylindrical helix,
* the only different is the surface.
*/
void occQt::makeConicalHelix()
{
Standard_Real aRadius = 3.0;
Standard_Real aPitch = 1.0;
// the pcurve is a 2d line in the parametric space.
gp_Lin2d aLine2d(gp_Pnt2d(0.0, 0.0), gp_Dir2d(aRadius, aPitch));
Handle(Geom2d_TrimmedCurve) aSegment = GCE2d_MakeSegment(aLine2d, 0.0, M_PI * 2.0).Value();
Handle(Geom_ConicalSurface) aCylinder = new Geom_ConicalSurface(gp::XOY(), M_PI / 6.0, aRadius);
TopoDS_Edge aHelixEdge = BRepBuilderAPI_MakeEdge(aSegment, aCylinder, 0.0, 6.0 * M_PI).Edge();
gp_Trsf aTrsf;
aTrsf.SetTranslation(gp_Vec(18.0, 120.0, 0.0));
BRepBuilderAPI_Transform aTransform(aHelixEdge, aTrsf);
Handle(AIS_Shape) anAisHelixCurve = new AIS_Shape(aTransform.Shape());
myOccView->getContext()->Display(anAisHelixCurve, Standard_True);
// sweep a circle profile along the helix curve.
// there is no curve3d in the pcurve edge, so approx one.
BRepLib::BuildCurve3d(aHelixEdge);
gp_Ax2 anAxis;
anAxis.SetDirection(gp_Dir(0.0, 4.0, 1.0));
anAxis.SetLocation(gp_Pnt(aRadius, 0.0, 0.0));
gp_Circ aProfileCircle(anAxis, 0.3);
TopoDS_Edge aProfileEdge = BRepBuilderAPI_MakeEdge(aProfileCircle).Edge();
TopoDS_Wire aProfileWire = BRepBuilderAPI_MakeWire(aProfileEdge).Wire();
TopoDS_Face aProfileFace = BRepBuilderAPI_MakeFace(aProfileWire).Face();
TopoDS_Wire aHelixWire = BRepBuilderAPI_MakeWire(aHelixEdge).Wire();
BRepOffsetAPI_MakePipe aPipeMaker(aHelixWire, aProfileFace);
if (aPipeMaker.IsDone())
{
aTrsf.SetTranslation(gp_Vec(28.0, 120.0, 0.0));
BRepBuilderAPI_Transform aPipeTransform(aPipeMaker.Shape(), aTrsf);
Handle(AIS_Shape) anAisPipe = new AIS_Shape(aPipeTransform.Shape());
anAisPipe->SetColor(Quantity_NOC_DARKGOLDENROD);
myOccView->getContext()->Display(anAisPipe, Standard_True);
}
}
void occQt::makeToroidalHelix()
{
Standard_Real aRadius = 1.0;
Standard_Real aSlope = 0.05;
// the pcurve is a 2d line in the parametric space.
gp_Lin2d aLine2d(gp_Pnt2d(0.0, 0.0), gp_Dir2d(aSlope, 1.0));
Handle(Geom2d_TrimmedCurve) aSegment = GCE2d_MakeSegment(aLine2d, 0.0, M_PI * 2.0).Value();
Handle(Geom_ToroidalSurface) aCylinder = new Geom_ToroidalSurface(gp::XOY(), aRadius * 5.0, aRadius);
TopoDS_Edge aHelixEdge = BRepBuilderAPI_MakeEdge(aSegment, aCylinder, 0.0, 2.0 * M_PI / aSlope).Edge();
gp_Trsf aTrsf;
aTrsf.SetTranslation(gp_Vec(45.0, 120.0, 0.0));
BRepBuilderAPI_Transform aTransform(aHelixEdge, aTrsf);
Handle(AIS_Shape) anAisHelixCurve = new AIS_Shape(aTransform.Shape());
myOccView->getContext()->Display(anAisHelixCurve, Standard_True);
// sweep a circle profile along the helix curve.
// there is no curve3d in the pcurve edge, so approx one.
BRepLib::BuildCurve3d(aHelixEdge);
gp_Ax2 anAxis;
anAxis.SetDirection(gp_Dir(0.0, 0.0, 1.0));
anAxis.SetLocation(gp_Pnt(aRadius * 6.0, 0.0, 0.0));
gp_Circ aProfileCircle(anAxis, 0.3);
TopoDS_Edge aProfileEdge = BRepBuilderAPI_MakeEdge(aProfileCircle).Edge();
TopoDS_Wire aProfileWire = BRepBuilderAPI_MakeWire(aProfileEdge).Wire();
TopoDS_Face aProfileFace = BRepBuilderAPI_MakeFace(aProfileWire).Face();
TopoDS_Wire aHelixWire = BRepBuilderAPI_MakeWire(aHelixEdge).Wire();
BRepOffsetAPI_MakePipe aPipeMaker(aHelixWire, aProfileFace);
if (aPipeMaker.IsDone())
{
aTrsf.SetTranslation(gp_Vec(60.0, 120.0, 0.0));
BRepBuilderAPI_Transform aPipeTransform(aPipeMaker.Shape(), aTrsf);
Handle(AIS_Shape) anAisPipe = new AIS_Shape(aPipeTransform.Shape());
anAisPipe->SetColor(Quantity_NOC_CORNSILK1);
myOccView->getContext()->Display(anAisPipe, Standard_True);
}
}
'블로그 (Blog) > 개발로그 (Devlogs)' 카테고리의 다른 글
Helix 형상에 메시까지.. (0) | 2024.03.16 |
---|---|
std::stack 클리어 (0) | 2024.03.16 |
Enlightenment desktop 기반의 리눅스.. (0) | 2024.03.15 |
CentOS 6.x 에 xpra 설치하기 (0) | 2024.03.15 |
Xvfb 테스트 (0) | 2024.03.15 |