RhinoSweep1 and Rhino1RailSweep and sweep1 command

I have a rail curve and some shape curves.

when I using sweep1 command I can get a brep jus as my required.
when I using Rhino1RailSweep fuction I also can get a brep,but this brep is not my required.
when I using RhinoSweep1 funtion I can’t get any breps.

next is my whole codes,I want upload the 3dm file and codes as a attachment.
but I don’t konw how to upload a attachmen

//获取形状线端点在路径线上的参数值
bool GetShapeParameterOnRail( const ON_Curve& shape,  const ON_Curve& rail, double tol, double& t   )
{
	ON_Interval rail_domain = rail.Domain();    
	double dis1=100000;
	double t1;
	double dis2=100000;
	double t2;

	//测试开始点;                                                       
	bool rc = rail.GetClosestPoint( shape.PointAtStart(), &t1, tol );//得到起点;
	if( rc )
	{
		if( rail.IsClosed() )
		{
			if( fabs(t - rail_domain.Max()) < ON_SQRT_EPSILON )
				t1 = rail_domain.Min();
			if( fabs(t - rail_domain.Min()) < ON_SQRT_EPSILON )
				t1 = rail_domain.Min();
		}
		ON_3dPoint point1=rail.PointAt(t1);
		dis1=point1.DistanceTo(shape.PointAtStart());
	}

	// 测试端点;
	rc = rail.GetClosestPoint( shape.PointAtEnd(), &t2, tol );
	if( rc )
	{
		if( rail.IsClosed() )
		{
			if( fabs(t2 - rail_domain.Max()) < ON_SQRT_EPSILON )
				t2 = rail_domain.Min();
			if( fabs(t2 - rail_domain.Min()) < ON_SQRT_EPSILON )
				t2 = rail_domain.Min();
		}
		ON_3dPoint point2=rail.PointAt(t2);
		dis2=point2.DistanceTo(shape.PointAtEnd());
	}


	if(rc)//说明起点和终点有一个是在路径线上,取最近的那个点
	{
		if(dis1<dis2)
		{
			t=t1;
		}
		else
		{
			t=t2;
		}

		return true;
	}

	// 尝试相交
	ON_SimpleArray<ON_X_EVENT> x;
	if( 1 == rail.IntersectCurve(&shape, x, tol, 0.0) && x[0].IsPointEvent() )
	{
		t = x[0].m_a[0];
		if( rail.IsClosed() )
		{
			if( fabs(t - rail_domain.Max()) < ON_SQRT_EPSILON )
				t = rail_domain.Min();
		}
		return true;
	}

	return false;
}

bool Sweep1(ON_Curve* in_rail,ON_SimpleArray<const ON_Curve*>in_secs,ON_SimpleArray<ON_Brep*>& out_breps)
{
	CArgsRhinoSweep1 args;
	CRhinoPolyEdge edge_copy;
	edge_copy.Create(in_rail);
	args.m_rail_curve =&edge_copy;
	args.m_bHaveRailPickPoint = false;
	args.m_bUsePivotPoint = false;

	double tol= RhinoApp().ActiveDoc()->AbsoluteTolerance();
	for( int i = 0; i < in_secs.Count(); i++ )
	{
		double t = 0;
		if( !GetShapeParameterOnRail(*in_secs[i], edge_copy, 0.2, t) )
			return 0;
		args.m_shape_curves.Append( const_cast<ON_Curve*>(in_secs[i]));
		args.m_rail_params.Append( t );
	}

	args.m_bUsePoints[0] = 0;
	args.m_bUsePoints[1] = 0;
	args.m_bClosed = true; 
	args.m_style = 0;
	args.m_planar_up = ON_zaxis; // Don't need this, but set it anyway.. 
	args.m_simplify = 0; // Simplify method for shape curves
	args.m_rebuild_count = -1; // Sample point count for rebuilding shapes
	args.m_refit_tolerance = 0.01;
	args.m_sweep_tolerance =0.01;
	args.m_angle_tolerance =0.01;// RhinoApp().ActiveDoc()->AngleToleranceRadians();

	RhinoSweep1(args, out_breps);

	return (out_breps.Count()>=1) ? true : false;
}

CRhinoCommand::result CCommandHide::RunCommand( const CRhinoCommandContext& context )
{
	CRhinoGetObject go;
	go.SetCommandPrompt( L"Select rail curve" );
	go.SetGeometryFilter( CRhinoGetObject::curve_object );
	go.GetObjects(1,1);
	if( go.CommandResult() != success )
		return go.CommandResult();

	const CRhinoObjRef& rail_ref = go.Object(0);
	const CRhinoObject* rail_obj = rail_ref.Object();
	if( !rail_obj )
		return failure;
	const ON_Curve* rail_crv = rail_ref.Curve();
	if( !rail_crv )
		return failure;


	CRhinoGetObject gx;
	gx.SetCommandPrompt( L"Select cross section curves" );
	gx.SetGeometryFilter( CRhinoGetObject::curve_object );
	gx.EnablePreSelect( false );
	gx.EnableDeselectAllBeforePostSelect( false );
	gx.GetObjects(1,0);
	if( gx.CommandResult() != success )
		return gx.CommandResult();


	ON_Curve* rail=rail_crv->DuplicateCurve();
	ON_SimpleArray<const ON_Curve*>shapes;

	int i;
	for( i = 0; i < gx.ObjectCount(); i++ )
	{
		const CRhinoObjRef& obj_ref = gx.Object(i);
		const ON_Curve* crv = obj_ref.Curve();
		if( crv )
		{
			ON_Curve* dup_crv = crv->DuplicateCurve();
			shapes.Append(dup_crv);
		}
	}


	ON_SimpleArray<ON_Brep*> breps;
#if 0
	Sweep1(rail,shapes,breps);
#else
	Rhino1RailSweep(breps,rail,shapes,true);
#endif

	for( i = 0; i < breps.Count(); i++ )
	{
		context.m_doc.AddBrepObject( *breps[i] );
		delete breps[i];
	}

	delete rail;
	for( i = 0; i < shapes.Count(); i++ )
		delete shapes[i];

	context.m_doc.Redraw();
	return success;
}

Can you also provide a 3dm file that contains the results of the Sweep1 command. Also, what parameters for the Sweep1 command did you use. A screen capture of the Sweep1 dialog box might be useful.

You can email me directly, if needed, at dale@mcneel.com.

Thanks!

thanks,dale:
I have send the attchment to you,why this forums doesn’t suppot upload attchment?
(just like the newsgroup)
If can upload will very convenient to all of us.

Attachments are supported. You can drag and drop images directly into your response. For other file types hit the little icon that looks like an image attachment in the formatting bar above your response. A popup box will appear with a place to drag and drop your file.
–Mitch

[sweep_1.rar][1]
[1]: https://www.filepicker.io/api/file/C9QWyHyqQMi2XJl4oR4H

thanks for you help

@sam or @discourse. The above post contains a large code block which is getting cut off when presented on a page. Is there a setting I need to adjust to fix this or is this a bug?

Hi,
Dale is away from the office for a while and he asked me to help you with this.
I got your 3dm file and the bmp of the sweep1 settings.

– Is the brep in sweep1_2.3dm that you sent the surface you would like to get from your plugin?

– Can you attach the code for your plugin so that I can see what you are trying to do?

Thanks,
Lowell Walmsley
McNeel & Associates

OK, I have the code you sent now.
I’ll look and get back to you.

Thanks,
Lowell

Hi,
Looks like the main problem is that you have to set the endpoint of the rail to the starting shape location.
You also have to get the shape curves going the same direction.
I made a couple of changes to your Sweep1() function to do those things.

Thanks,
Lowell

bool Sweep1(ON_Curve* in_rail,ON_SimpleArray<const ON_Curve*>in_secs,ON_SimpleArray<ON_Brep*>& out_breps)
{
  // I guess you're only doing closed rails here
        bool bClosed = true;

	CRhinoPolyEdge edge_copy;
	edge_copy.Create(in_rail);

  // Set seam on closed rail to first shape location
  if(bClosed && edge_copy.IsClosed())
  {
    double t;
    if( !GetShapeParameterOnRail(*in_secs[0], edge_copy, 0.2, t) )
      return 0;
    ON_Interval domain = edge_copy.Domain();
    if(t != domain[0])
      if(!edge_copy.ChangeClosedCurveSeam(t))
        return 0;
  }
  
  CArgsRhinoSweep1 args;
	args.m_rail_curve = &edge_copy;
	args.m_bHaveRailPickPoint = false;
	args.m_bUsePivotPoint = false;

	for( int i = 0; i < in_secs.Count(); i++ )
	{
    double t;
		if( !GetShapeParameterOnRail(*in_secs[i], edge_copy, 0.2, t) )
			return 0;
		args.m_shape_curves.Append( const_cast<ON_Curve*>(in_secs[i]));
		args.m_rail_params.Append( t );

    // Set all of the shapes to go the same way.
    // This isn't a very robust way to do that but it works with the kind of shapes you're using.
    ON_3dPoint p = edge_copy.PointAt(t);
    if(args.m_shape_curves[i]->PointAtStart().DistanceTo(p) > args.m_shape_curves[i]->PointAtEnd().DistanceTo(p))
      args.m_shape_curves[i]->Reverse();
	}

	args.m_bUsePoints[0] = 0;
	args.m_bUsePoints[1] = 0;
	args.m_bClosed = true; 
	args.m_style = 0;
	args.m_planar_up = ON_zaxis; // Don't need this, but set it anyway.. 
	args.m_simplify = 0; // Simplify method for shape curves
	args.m_rebuild_count = -1; // Sample point count for rebuilding shapes
	args.m_refit_tolerance = 0.01;
	args.m_sweep_tolerance =0.01;
	args.m_angle_tolerance =0.01;// RhinoApp().ActiveDoc()->AngleToleranceRadians();

	RhinoSweep1(args, out_breps);

	return (out_breps.Count()>=1) ? true : false;
}
1 Like

Looks like this forum doesn’t work right for long messages - heres the rest of the function:

	for( int i = 0; i < in_secs.Count(); i++ )
	{
    double t;
		if( !GetShapeParameterOnRail(*in_secs[i], edge_copy, 0.2, t) )
			return 0;
		args.m_shape_curves.Append( const_cast<ON_Curve*>(in_secs[i]));
		args.m_rail_params.Append( t );

    // Set all of the shapes to go the same way.
    // This isn't a very robust way to do that but it works with the kind of shapes you're using.
    ON_3dPoint p = edge_copy.PointAt(t);
    if(args.m_shape_curves[i]->PointAtStart().DistanceTo(p) > args.m_shape_curves[i]->PointAtEnd().DistanceTo(p))
      args.m_shape_curves[i]->Reverse();
	}

	args.m_bUsePoints[0] = 0;
	args.m_bUsePoints[1] = 0;
	args.m_bClosed = true; 
	args.m_style = 0;
	args.m_planar_up = ON_zaxis; // Don't need this, but set it anyway.. 
	args.m_simplify = 0; // Simplify method for shape curves
	args.m_rebuild_count = -1; // Sample point count for rebuilding shapes
	args.m_refit_tolerance = 0.01;
	args.m_sweep_tolerance =0.01;
	args.m_angle_tolerance =0.01;// RhinoApp().ActiveDoc()->AngleToleranceRadians();

	RhinoSweep1(args, out_breps);

	return (out_breps.Count()>=1) ? true : false;
}


1 Like

I have this fixed in master, next time you update the issue will be gone.

1 Like

That’s very kind of you.

lowell:
thanks for you help.
I am on leave somedays,I will try you codes at present

hi,lowell:
I using you codes can sweep fluky with the 3dm upload before.
but now I have another 3dm file,this file still has the same problem:
when I using sweep1 command I can get a brep jus as my required.
when I using RhinoSweep1 funtion I can’t get any breps.
sweep1.rar is the file I mentioned

The shape curves in that file are not very good.
They look like lines, but they have lots of control points. The ones at the toe and at the heel are especially bad, with control points stacked and very close together.
If you clean those up (replace with lines) does your program work?

Lowell

I have try just using the curves start point and end point to creat a line as the new shape curve ,and let the line’s start point just on the rail curve.but still can’t sweep sucsuces

sweep1.rar is the changed shape curves.please help me to see what problem this curves have.

someone please help me to see this problem.
thanks very much.
I am very anxious to want solve this problem

@lowell, do you have time to look into the code again? The shape curves in the new 3dm file are all lines with 2 points, thanks.

Yes, I’ll look.
Lowell