0026936: Drawbacks of inlining in new type system in OCCT 7.0 -- automatic
[occt.git] / samples / mfc / standard / 01_Geometry / src / ISession2D / ISession2D_Curve.cpp
CommitLineData
7fd59977 1#include "stdafx.h"
2
3#include <ISession2D_Curve.h>
4#include "..\\GeometryApp.h"
234e52be 5#include <Graphic3d_ArrayOfPolylines.hxx>
6#include <Geom2d_BezierCurve.hxx>
7#include <Geom2dLProp_CLProps2d.hxx>
8#include <TColStd_Array1OfReal.hxx>
9#include <Geom2d_BSplineCurve.hxx>
7fd59977 10
7fd59977 11IMPLEMENT_STANDARD_RTTIEXT(ISession2D_Curve,AIS_InteractiveObject)
12
5c1f974e 13
92efcf78 14ISession2D_Curve::ISession2D_Curve(const Handle(Geom2d_Curve) aGeom2dCurve,
5c1f974e 15 const Aspect_TypeOfLine aTypeOfLine,
16 const Aspect_WidthOfLine aWidthOfLine,
17 const Standard_Integer aColorIndex)
18 :AIS_InteractiveObject()
7fd59977 19{
20 myGeom2dCurve = aGeom2dCurve;
21 myTypeOfLine = aTypeOfLine ;
22 myWidthOfLine = aWidthOfLine;
23 myColorIndex = aColorIndex ;
24 myDisplayPole = Standard_True;
25 myDisplayCurbure = Standard_False;
26 myDiscretisation = 20;
27 myradiusmax = 10;
28 myradiusratio = 1;
29}
30
5c573e69 31void ISession2D_Curve::Compute(const Handle(PrsMgr_PresentationManager3d)& /*aPresentationManager*/,
5c1f974e 32 const Handle(Prs3d_Presentation)& aPresentation,
5c573e69 33 const Standard_Integer /*aMode*/)
7fd59977 34{
7fd59977 35
5c1f974e 36 Geom2dAdaptor_Curve anAdaptor(myGeom2dCurve);
37 GCPnts_QuasiUniformDeflection anEdgeDistrib(anAdaptor,1.e-2);
38 if(anEdgeDistrib.IsDone())
39 {
40 Handle(Graphic3d_ArrayOfPolylines) aCurve =
41 new Graphic3d_ArrayOfPolylines(anEdgeDistrib.NbPoints());
42 for(Standard_Integer i=1;i<=anEdgeDistrib.NbPoints();++i)
43 aCurve->AddVertex(anEdgeDistrib.Value(i));
7fd59977 44
5c1f974e 45 Prs3d_Root::CurrentGroup(aPresentation)->AddPrimitiveArray(aCurve);
46 }
7fd59977 47
7fd59977 48 if (myDisplayPole)
5c1f974e 49 {
7fd59977 50 if (anAdaptor.GetType() == GeomAbs_BezierCurve )
51 {
52 Handle(Geom2d_BezierCurve) aBezier = anAdaptor.Bezier();
5c1f974e 53 Handle(Graphic3d_ArrayOfPolylines) anArrayOfVertex = new Graphic3d_ArrayOfPolylines(aBezier->NbPoles());
7fd59977 54 for(int i=1;i<=aBezier->NbPoles();i++)
5c1f974e 55 {
56 gp_Pnt2d CurrentPoint = aBezier->Pole(i);
57 anArrayOfVertex->AddVertex(CurrentPoint.X(),CurrentPoint.Y(),0.);
7fd59977 58 }
5c1f974e 59 Prs3d_Root::CurrentGroup(aPresentation)->AddPrimitiveArray(anArrayOfVertex);
60 }
7fd59977 61
62 if (anAdaptor.GetType() == GeomAbs_BSplineCurve )
63 {
64 Handle(Geom2d_BSplineCurve) aBSpline = anAdaptor.BSpline();
65
5c1f974e 66 Handle(Graphic3d_ArrayOfPolylines) anArrayOfVertex =
67 new Graphic3d_ArrayOfPolylines(aBSpline->NbPoles());
7fd59977 68
69 for(int i=1;i<=aBSpline->NbPoles();i++)
5c1f974e 70 {
71 gp_Pnt2d CurrentPoint = aBSpline->Pole(i);
72 anArrayOfVertex->AddVertex(CurrentPoint.X(),CurrentPoint.Y(),0.);
7fd59977 73 }
5c1f974e 74 Prs3d_Root::CurrentGroup(aPresentation)->AddPrimitiveArray(anArrayOfVertex);
7fd59977 75 }
5c1f974e 76 }
7fd59977 77
78 if (myDisplayCurbure && (anAdaptor.GetType() != GeomAbs_Line))
79 {
80 Standard_Integer ii;
81 Standard_Integer intrv, nbintv = anAdaptor.NbIntervals(GeomAbs_CN);
82 TColStd_Array1OfReal TI(1,nbintv+1);
83 anAdaptor.Intervals(TI,GeomAbs_CN);
84 Standard_Real Resolution = 1.0e-9, Curvature;
85 Geom2dLProp_CLProps2d LProp(myGeom2dCurve, 2, Resolution);
86 gp_Pnt2d P1, P2;
87
88 for (intrv = 1; intrv <= nbintv; intrv++)
5c1f974e 89 {
90 Standard_Real t = TI(intrv);
91 Standard_Real step = (TI(intrv+1) - t) / GetDiscretisation();
92 Standard_Real LRad, ratio;
93 for (ii = 1; ii <= myDiscretisation; ii++)
94 {
95 LProp.SetParameter(t);
7fd59977 96 if (LProp.IsTangentDefined())
5c1f974e 97 {
98 Curvature = Abs(LProp.Curvature());
99 if ( Curvature > Resolution)
100 {
101 myGeom2dCurve->D0(t, P1);
102 LRad = 1./Curvature;
103 ratio = ( ( LRad > myradiusmax) ? myradiusmax/LRad : 1 );
104 ratio *= myradiusratio;
105 LProp.CentreOfCurvature(P2);
106 gp_Vec2d V(P1, P2);
107 gp_Pnt2d P3 = P1.Translated(ratio*V);
108 Handle(Graphic3d_ArrayOfPolylines) aSegment = new Graphic3d_ArrayOfPolylines(2);
109 aSegment->AddVertex(P1.X(),P1.Y(),0.);
110 aSegment->AddVertex(P3.X(),P3.Y(),0.);
111 Prs3d_Root::CurrentGroup(aPresentation)->AddPrimitiveArray(aSegment);
112 }
113 }
114 t += step;
115 }
7fd59977 116 }
117 }
118}
119
5c573e69 120void ISession2D_Curve::ComputeSelection(const Handle(SelectMgr_Selection)& /*aSelection*/,
121 const Standard_Integer /*aMode*/)
7fd59977 122{
123}
124
125