[brlcad-commits] SF.net SVN: brlcad:[36088] brlcad/trunk/src/librt/primitives/pipe/pipe_brep .cpp
Open Source Solid Modeling CAD
Brought to you by:
brlcad
From: <sta...@us...> - 2009-09-29 22:03:19
|
Revision: 36088 http://brlcad.svn.sourceforge.net/brlcad/?rev=36088&view=rev Author: starseeker Date: 2009-09-29 22:03:11 +0000 (Tue, 29 Sep 2009) Log Message: ----------- Still likely very fragile, but can do curved pipe. Modified Paths: -------------- brlcad/trunk/src/librt/primitives/pipe/pipe_brep.cpp Modified: brlcad/trunk/src/librt/primitives/pipe/pipe_brep.cpp =================================================================== --- brlcad/trunk/src/librt/primitives/pipe/pipe_brep.cpp 2009-09-29 21:17:04 UTC (rev 36087) +++ brlcad/trunk/src/librt/primitives/pipe/pipe_brep.cpp 2009-09-29 22:03:11 UTC (rev 36088) @@ -35,9 +35,8 @@ * R T _ P I P E _ B R E P */ -void generate_curves(point_t prevp, point_t curp, double od, double id, ON_Plane *plane, ON_SimpleArray<ON_Curve*> *outer, ON_SimpleArray<ON_Curve*> *inner) { - point_t current_point; - ON_Circle outercirclestart = ON_Circle(*plane, od/2.0); +void generate_curves(double od, double id, ON_Plane *plane, ON_SimpleArray<ON_Curve*> *outer, ON_SimpleArray<ON_Curve*> *inner) { + ON_Circle outercirclestart = ON_Circle(*plane, od/2.0); ON_NurbsCurve *ocurve = ON_NurbsCurve::New(); outercirclestart.GetNurbForm(*ocurve); outer->Append(ON_Curve::Cast(ocurve)); @@ -93,12 +92,23 @@ } } -void make_curved_surfaces(ON_Brep **b, ON_SimpleArray<ON_Curve*> *startoutercurves, ON_SimpleArray<ON_Curve*> *startinnercurves, fastf_t angle, point_t bend_start, point_t bend_center, point_t bend_end) { - ON_Arc *patharc = new ON_Arc(ON_3dPoint(bend_start), ON_3dPoint(bend_center), ON_3dPoint(bend_end)); - ON_ArcCurve *pathcurve = new ON_ArcCurve(*patharc); - ON_SumSurface *sumsurf = new ON_SumSurface(); - sumsurf->Create(*startoutercurves[0],ON_Curve::Cast(pathcurve)); - ON_BrepFace *face = (*b)->NewFace(*sumsurf); +void make_curved_surfaces(ON_Brep **b, ON_SimpleArray<ON_Curve*> *startoutercurves, ON_SimpleArray<ON_Curve*> *startinnercurves, fastf_t angle, point_t bend_center, vect_t norm) { + point_t rev, raxis; + VADD2(rev, bend_center, norm); + + ON_Line *revaxis = new ON_Line(ON_3dPoint(bend_center), ON_3dPoint(rev)); + ON_RevSurface* revsurf = ON_RevSurface::New(); + revsurf->m_curve = *startoutercurves[0]; + revsurf->m_axis = *revaxis; + revsurf->m_angle = ON_Interval(2*ON_PI - angle, 2*ON_PI); + ON_BrepFace *face = (*b)->NewFace(*revsurf); + + revsurf = ON_RevSurface::New(); + revsurf->m_curve = *startinnercurves[0]; + revsurf->m_axis = *revaxis; + revsurf->m_angle = ON_Interval(2*ON_PI - angle, 2*ON_PI); + face = (*b)->NewFace(*revsurf); + } extern "C" void @@ -109,6 +119,8 @@ register struct wdb_pipept *prevp; register struct wdb_pipept *curp; register struct wdb_pipept *nextp; + point_t current_point; + vect_t x_dir, y_dir, pipe_dir; ON_SimpleArray<ON_Curve*> startoutercurves; ON_SimpleArray<ON_Curve*> startinnercurves; @@ -116,7 +128,6 @@ ON_SimpleArray<ON_Curve*> endoutercurves; ON_SimpleArray<ON_Curve*> endinnercurves; - vect_t x_dir, y_dir, pipe_dir; ON_3dPoint plane_origin; ON_3dVector plane_x_dir, plane_y_dir; @@ -135,7 +146,9 @@ curp = BU_LIST_NEXT(wdb_pipept, &prevp->l); nextp = BU_LIST_NEXT(wdb_pipept, &curp->l); if (BU_LIST_IS_HEAD(&curp->l, &pip->pipe_segs_head)) return; - + + VMOVE(current_point, prevp->pp_coord); + *b = new ON_Brep(); @@ -143,12 +156,13 @@ bn_vec_ortho(x_dir, pipe_dir); VCROSS(y_dir, pipe_dir, x_dir); VUNITIZE(y_dir); + plane_origin = ON_3dPoint(prevp->pp_coord); plane_x_dir = ON_3dVector(x_dir); plane_y_dir = ON_3dVector(y_dir); endplane = new ON_Plane(plane_origin, plane_x_dir, plane_y_dir); - generate_curves(prevp->pp_coord, curp->pp_coord, prevp->pp_id, prevp->pp_od, endplane, &endoutercurves, &endinnercurves); + generate_curves(prevp->pp_id, prevp->pp_od, endplane, &endoutercurves, &endinnercurves); ON_PlaneSurface* bp = new ON_PlaneSurface(); bp->m_plane = (*endplane); @@ -179,7 +193,7 @@ if (prevp->pp_id > 0.0) { (*b)->NewPlanarFaceLoop(bface.m_face_index, ON_BrepLoop::inner, endinnercurves, true); } - (*b)->SetTrimIsoFlags(bface); + (*b)->SetTrimIsoFlags(bface); while (1) { vect_t n1, n2; @@ -200,7 +214,7 @@ plane_x_dir = ON_3dVector(x_dir); plane_y_dir = ON_3dVector(y_dir); endplane = new ON_Plane(plane_origin, plane_x_dir, plane_y_dir); - generate_curves(prevp->pp_coord, curp->pp_coord, prevp->pp_id, prevp->pp_od, endplane, &endoutercurves, &endinnercurves); + generate_curves(prevp->pp_id, prevp->pp_od, endplane, &endoutercurves, &endinnercurves); make_linear_surfaces(b, &startoutercurves, &endoutercurves, &startinnercurves, &endinnercurves); break; } @@ -217,38 +231,57 @@ if (isnan(dist_to_bend) || VNEAR_ZERO(norm, SQRT_SMALL_FASTF) || NEAR_ZERO(dist_to_bend, SQRT_SMALL_FASTF)) { // points are colinear, treat as linear segment - VSUB2(pipe_dir, prevp->pp_coord, curp->pp_coord); + VSUB2(pipe_dir, prevp->pp_coord, current_point); bn_vec_ortho(x_dir, pipe_dir); VCROSS(y_dir, pipe_dir, x_dir); VUNITIZE(y_dir); - plane_origin = ON_3dPoint(curp->pp_coord); + plane_origin = ON_3dPoint(current_point); plane_x_dir = ON_3dVector(x_dir); plane_y_dir = ON_3dVector(y_dir); endplane = new ON_Plane(plane_origin, plane_x_dir, plane_y_dir); - generate_curves(prevp->pp_coord, curp->pp_coord, prevp->pp_id, prevp->pp_od, endplane, &endoutercurves, &endinnercurves); + generate_curves(prevp->pp_id, prevp->pp_od, endplane, &endoutercurves, &endinnercurves); make_linear_surfaces(b, &startoutercurves, &endoutercurves, &startinnercurves, &endinnercurves); + VMOVE(current_point, curp->pp_coord); } else { point_t bend_center; point_t bend_start; point_t bend_end; vect_t v1, v2; + VUNITIZE(norm); + + // Linear part first VJOIN1(bend_start, curp->pp_coord, dist_to_bend, n1); VSUB2(pipe_dir, prevp->pp_coord, curp->pp_coord); bn_vec_ortho(x_dir, pipe_dir); VCROSS(y_dir, pipe_dir, x_dir); VUNITIZE(y_dir); - plane_origin = ON_3dPoint(curp->pp_coord); + plane_origin = ON_3dPoint(bend_start); plane_x_dir = ON_3dVector(x_dir); plane_y_dir = ON_3dVector(y_dir); endplane = new ON_Plane(plane_origin, plane_x_dir, plane_y_dir); - generate_curves(prevp->pp_coord, bend_start, prevp->pp_id, prevp->pp_od, endplane, &endoutercurves, &endinnercurves); + generate_curves(prevp->pp_id, prevp->pp_od, endplane, &endoutercurves, &endinnercurves); make_linear_surfaces(b, &startoutercurves, &endoutercurves, &startinnercurves, &endinnercurves); + + // Now do curved section VJOIN1(bend_end, curp->pp_coord, dist_to_bend, n2); VCROSS(v1, n1, norm); VCROSS(v2, v1, norm); VJOIN1(bend_center, bend_start, -curp->pp_bendradius, v1); - make_curved_surfaces(b, &startoutercurves, &startinnercurves, angle, bend_start, bend_center, bend_end); + make_curved_surfaces(b, &startinnercurves, &startoutercurves, angle, bend_center, norm); + startinnercurves.Empty(); + startoutercurves.Empty(); + VSUB2(pipe_dir, curp->pp_coord, nextp->pp_coord); + bn_vec_ortho(x_dir, pipe_dir); + VCROSS(y_dir, pipe_dir, x_dir); + VUNITIZE(y_dir); + plane_origin = ON_3dPoint(bend_end); + plane_x_dir = ON_3dVector(x_dir); + plane_y_dir = ON_3dVector(y_dir); + endplane = new ON_Plane(plane_origin, plane_x_dir, plane_y_dir); + generate_curves(prevp->pp_id, prevp->pp_od, endplane, &startoutercurves, &startinnercurves); + + VMOVE(current_point, bend_end); } } prevp = curp; @@ -268,7 +301,7 @@ plane_y_dir = ON_3dVector(y_dir); endplane = new ON_Plane(plane_origin, plane_x_dir, plane_y_dir); - generate_curves(prevp->pp_coord, curp->pp_coord, prevp->pp_id, prevp->pp_od, endplane, &endoutercurves, &endinnercurves); + generate_curves(prevp->pp_id, prevp->pp_od, endplane, &endoutercurves, &endinnercurves); ON_PlaneSurface* ebp = new ON_PlaneSurface(); ebp->m_plane = (*endplane); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |