Reversing CreatePipe Function

Everything DG Kernel: Technical discussions and issues
Post Reply
Mito
Posts: 2
Joined: Thu Jan 30, 2025 7:11 am

Reversing CreatePipe Function

Post by Mito »

I want to use the CreatePipe function to sweep a circle over a 270-degree range.
With the code below, I can achieve a 90-degree sweep, but I don't know how to extend it to 270 degrees.
I am testing this by copying it into "InterfaceTests" > "IEntityTest.cs" from the sample.

Code: Select all

public void Test()
{
    IBRepWire_DG iWire;
    {
        IBRepBuilder_DG iBuilder = m_gen.Create<IBRepBuilder_DG>();

        IPlane_DG iPlane = m_gen.Create<IPlane_DG>();
        IBRepFace_DG iFace = iBuilder.CreateFace(iPlane);

        ICircle_DG circle1 = m_gen.Create<ICircle_DG>();
        circle1.Center = new PointDg(0, 0, 0);
        circle1.Radius = 200;

        IBRepEdge_DG edge1 = iBuilder.CreateEdge(circle1);
        iWire = iFace.AddNewWire();
        iWire.AddEdge(edge1);
    }

    IBRepShape_DG iShapePipe;
    {
        IBRepBuilderEx_DG iBuilderEx = m_gen.Create<IBRepBuilderEx_DG>();

        ICircle_DG circle1 = m_gen.Create<ICircle_DG>();
        circle1.Init(new PointDg(0, 0, 0), new PointDg(1000, 0, 1000), new PointDg(2000, 0, 0));

        ICurve_DG curve1 = circle1.As<ICurve_DG>();
        curve1.SlideEndPoint(0, new PointDg(0, 0, 0));
        curve1.SlideEndPoint(1, new PointDg(1000, 0, 1000));

        IBRepWire_DG iWire_R = m_gen.Create<IBRepWire_DG>();
        IBRepEdge_DG edge1 = m_gen.Create<IBRepEdge_DG>(curve1);
        iWire_R.AddEdge(edge1);

        IBRepShape_DG iShape = m_gen.Create<IBRepFace_DG>(iWire).As<IBRepShape_DG>();
        iShapePipe = iBuilderEx.CreatePipe(iWire_R, iShape);
    }

    IEntity_DG iEntity = m_iModel.AddBRepShape(iShapePipe);
    this.Display(iEntity);
}
Prashant Kande
Posts: 86
Joined: Tue Jun 18, 2024 6:12 am

Re: Reversing CreatePipe Function

Post by Prashant Kande »

Hi Mito
It is a nice code.

I have changed a little the second block:

Code: Select all

IBRepShape_DG iShapePipe;
{
    IBRepBuilderEx_DG iBuilderEx = m_gen.Create<IBRepBuilderEx_DG>();

    ICircle_DG circle1 = m_gen.Create<ICircle_DG>();
    circle1.Init(new PointDg(0, 0, 0), new PointDg(1000, 0, 1000), new PointDg(2000, 0, 0));

    ICurve_DG curve1 = circle1.As<ICurve_DG>();

    // The parameter should be the angle. Let's check
    RangeDg rg = curve1.ParameterRange;
    Debug.Assert(rg.Is(0, 2 * Math.PI, m_tol));

    // Modify
    rg.Max = 1.5*Math.PI;
    curve1.ParameterRange = rg;

    //curve1.SlideEndPoint(0, new PointDg(0, 0, 0));
    //curve1.SlideEndPoint(1, new PointDg(1000, 0, 1000));

    IBRepWire_DG iWire_R = m_gen.Create<IBRepWire_DG>();
    IBRepEdge_DG edge1 = m_gen.Create<IBRepEdge_DG>(curve1);
    iWire_R.AddEdge(edge1);

    IBRepShape_DG iShape = m_gen.Create<IBRepFace_DG>(iWire).As<IBRepShape_DG>();
    iShapePipe = iBuilderEx.CreatePipe(iWire_R, iShape);
}
It works. See the picture
Pipe.png
Pipe.png (59.63 KiB) Viewed 57424 times
The orientation is off, but I am sure you will figure it out.

Thanks for the good question
Mito
Posts: 2
Joined: Thu Jan 30, 2025 7:11 am

Re: Reversing CreatePipe Function

Post by Mito »

Thank you for your response. I really appreciate your help.
Prashant Kande
Posts: 86
Joined: Tue Jun 18, 2024 6:12 am

Re: Reversing CreatePipe Function

Post by Prashant Kande »

This is a useful code snippet. We will add it to InterfaceTests.BRepBuilderExTest in the next update.

Here is the fixed orientation and a bit of commenting / clarification:

Code: Select all

// Test suggested by Mito https://dynoinsightdev.com/viewtopic.php?p=268
public void CreatePipe()
{
    // Build the profile wire 
    ICircle_DG circleProfile = m_gen.Create<ICircle_DG>();
    circleProfile.Radius = 200;

    IBRepEdge_DG edgeProfile = m_iBuilder.CreateEdge(circleProfile);
    IBRepWire_DG iWireProfile = m_gen.Create<IBRepWire_DG>();
    iWireProfile.AddEdge(edgeProfile);

    IBRepShape_DG iShapeProfile = m_gen.Create<IBRepFace_DG>(iWireProfile).As<IBRepShape_DG>();

    // Construct the central (spine) wire 
    ICircle_DG circleSpine = m_gen.Create<ICircle_DG>();
    circleSpine.Radius = 1000;

    // We need only a part of the circle. So, we need to reduce the parameter range.
    // Parametrisation of the circle is defined by its construction frame
    // The default parameter range is [0, 2*PI]. Point at prameter 0 is on the x axis
    // The circle lies in the x and y plane of the construction frame
    // with the center at the origin of the construction frame. Radius = 1

    IFrame_DG fr = m_gen.Create<IFrame_DG>();
    // fr is identity (=global axes) by default. This can be checked in debugger and fr.GetAxis(0); fr.GetAxis(1);

    // Make sure we have the correct location and orientation
    fr.Rotate(-0.5*Math.PI, 0);
    fr.Rotate(Math.PI, 2);
    fr.SetOrigin(1000, 0, 0);

    circleSpine.Location = fr;

    // Reduce the parameter range
    ICurve_DG curve1 = circleSpine.As<ICurve_DG>();

    // The parameter should be the angle. Let's check
    RangeDg rg = curve1.ParameterRange;
    Debug.Assert(rg.Is(0, 2 * Math.PI, m_tol));

    // Modify
    rg.Max = 1.5 * Math.PI;
    curve1.ParameterRange = rg;

    IBRepWire_DG iWireSpine = m_gen.Create<IBRepWire_DG>();
    IBRepEdge_DG edgeCentralCurve = m_gen.Create<IBRepEdge_DG>(curve1);
    iWireSpine.AddEdge(edgeCentralCurve);

    // Build the pipe
    IBRepShape_DG iShapePipe = m_iBuilderEx.CreatePipe(iWireSpine, iShapeProfile);

    // Display
    IEntity_DG iEntity = m_iModel.AddBRepShape(iShapePipe);
    this.Display(iEntity, false);
}

 public void Display(IEntity_DG entity, bool addToModel)
 {
     entity.SetColor(Color.BlueViolet);
     if(addToModel)
         m_iModel.AddEntity(entity);
     // Show local frame 
     IScene_DG iScene = m_iView.As<IScene_DG>();
     iScene.ShowLocalFrame(entity, true);
     m_iView.GlobalAxes = true;
     m_iView.Reset(true, true);          // Fit
 }
Pipe2.png
Pipe2.png (51.01 KiB) Viewed 57041 times
Post Reply