using System;
using Bentley.Geometry;
using Bentley.GenerativeComponents;
using Bentley.GenerativeComponents.MicroStation;
using Bentley.Interop.MicroStationDGN;
using Wolfram.NETLink;
// Must be in this namespace.
namespace Bentley.GenerativeComponents.Features
{
public class BSplineCurveMath : Features.BSplineCurve
{
/// <summary>
/// Takes an xFunction, yFunction, and zFunction and
/// generates a curve.
/// </summary>
/// TODO: Error handling, ReFactor Generation of points.
[Update]
public bool ByXYZFunction
(
FeatureUpdateContext updateContext,
[ParentModel] CoordinateSystem coord,
[Replicatable] string xFunction,
[Replicatable] string yFunction,
[Replicatable] string zFunction
)
{
// This launches the Mathematica kernel:
IKernelLink ml = MathLinkFactory.CreateKernelLink();
// Discard the initial InputNamePacket the kernel will send when launched.
ml.WaitAndDiscardAnswer();
// Evaluate the definitions for xFunction, yFunction, and zFunction.
// These are coming from Generative Components Feature Definition.
// For example, Make the following assignments in GC:
// xFunction = "X[t_] = Sin[t];"
// yFunction = "Y[t_] = Cos[t];"
// zFunction = "t;"
// This defines a helix in the Mathematica Environment.
ml.EvaluateToOutputForm(xFunction, 0);
ml.EvaluateToOutputForm(yFunction, 0);
ml.EvaluateToOutputForm(zFunction, 0);
DPoint3d[] points = new DPoint3d[10];
// This is where the points are assigned. Refactoring neccecary here.
points[0] = new DPoint3d(Convert.ToDouble(ml.EvaluateToOutputForm("X[0.]", 0)), Convert.ToDouble(ml.EvaluateToOutputForm("Y[0.]", 0)), Convert.ToDouble(ml.EvaluateToOutputForm("Z[0.]", 0)));
points[1] = new DPoint3d(Convert.ToDouble(ml.EvaluateToOutputForm("X[1.]", 0)), Convert.ToDouble(ml.EvaluateToOutputForm("Y[1.]", 0)), Convert.ToDouble(ml.EvaluateToOutputForm("Z[1.]", 0)));
points[2] = new DPoint3d(Convert.ToDouble(ml.EvaluateToOutputForm("X[2.]", 0)), Convert.ToDouble(ml.EvaluateToOutputForm("Y[2.]", 0)), Convert.ToDouble(ml.EvaluateToOutputForm("Z[2.]", 0)));
points[3] = new DPoint3d(Convert.ToDouble(ml.EvaluateToOutputForm("X[3.]", 0)), Convert.ToDouble(ml.EvaluateToOutputForm("Y[3.]", 0)), Convert.ToDouble(ml.EvaluateToOutputForm("Z[3.]", 0)));
points[4] = new DPoint3d(Convert.ToDouble(ml.EvaluateToOutputForm("X[4.]", 0)), Convert.ToDouble(ml.EvaluateToOutputForm("Y[4.]", 0)), Convert.ToDouble(ml.EvaluateToOutputForm("Z[4.]", 0)));
points[5] = new DPoint3d(Convert.ToDouble(ml.EvaluateToOutputForm("X[5.]", 0)), Convert.ToDouble(ml.EvaluateToOutputForm("Y[5.]", 0)), Convert.ToDouble(ml.EvaluateToOutputForm("Z[5.]", 0)));
points[6] = new DPoint3d(Convert.ToDouble(ml.EvaluateToOutputForm("X[6.]", 0)), Convert.ToDouble(ml.EvaluateToOutputForm("Y[6.]", 0)), Convert.ToDouble(ml.EvaluateToOutputForm("Z[6.]", 0)));
points[7] = new DPoint3d(Convert.ToDouble(ml.EvaluateToOutputForm("X[7.]", 0)), Convert.ToDouble(ml.EvaluateToOutputForm("Y[7.]", 0)), Convert.ToDouble(ml.EvaluateToOutputForm("Z[7.]", 0)));
points[8] = new DPoint3d(Convert.ToDouble(ml.EvaluateToOutputForm("X[8.]", 0)), Convert.ToDouble(ml.EvaluateToOutputForm("Y[8.]", 0)), Convert.ToDouble(ml.EvaluateToOutputForm("Z[8.]", 0)));
points[9] = new DPoint3d(Convert.ToDouble(ml.EvaluateToOutputForm("X[9.]", 0)), Convert.ToDouble(ml.EvaluateToOutputForm("Y[9.]", 0)), Convert.ToDouble(ml.EvaluateToOutputForm("Z[9.]", 0)));
// Always close the math link.
ml.Close();
// Since we are inheriting from base bSplineCurve class,
// we can call the base to generate the curve based on a collection of DPoint3ds.
return base.ByPointsAsDPoint3ds(coord, points, false);
}
}
}
bSplineCurve by xFunction, yFunction and zFunction
using System; using Bentley.Geometry; using Bentley.GenerativeComponents; using Bentley.GenerativeComponents.MicroStation; using Bentley.Interop.MicroStationDGN; using Wolfram.NETLink; // Must be in this namespace. namespace Bentley.GenerativeComponents.Features { public class BSplineCurveMath : Features.BSplineCurve { /// <summary> /// Takes an xFunction, yFunction, and zFunction and /// generates a curve. /// </summary> /// TODO: Error handling, ReFactor Generation of points. [Update] public bool ByXYZFunction ( FeatureUpdateContext updateContext, [ParentModel] CoordinateSystem coord, [Replicatable] string xFunction, [Replicatable] string yFunction, [Replicatable] string zFunction ) { // This launches the Mathematica kernel: IKernelLink ml = MathLinkFactory.CreateKernelLink(); // Discard the initial InputNamePacket the kernel will send when launched. ml.WaitAndDiscardAnswer(); // Evaluate the definitions for xFunction, yFunction, and zFunction. // These are coming from Generative Components Feature Definition. // For example, Make the following assignments in GC: // xFunction = "X[t_] = Sin[t];" // yFunction = "Y[t_] = Cos[t];" // zFunction = "t;" // This defines a helix in the Mathematica Environment. ml.EvaluateToOutputForm(xFunction, 0); ml.EvaluateToOutputForm(yFunction, 0); ml.EvaluateToOutputForm(zFunction, 0); DPoint3d[] points = new DPoint3d[10]; // This is where the points are assigned. Refactoring neccecary here. points[0] = new DPoint3d(Convert.ToDouble(ml.EvaluateToOutputForm("X[0.]", 0)), Convert.ToDouble(ml.EvaluateToOutputForm("Y[0.]", 0)), Convert.ToDouble(ml.EvaluateToOutputForm("Z[0.]", 0))); points[1] = new DPoint3d(Convert.ToDouble(ml.EvaluateToOutputForm("X[1.]", 0)), Convert.ToDouble(ml.EvaluateToOutputForm("Y[1.]", 0)), Convert.ToDouble(ml.EvaluateToOutputForm("Z[1.]", 0))); points[2] = new DPoint3d(Convert.ToDouble(ml.EvaluateToOutputForm("X[2.]", 0)), Convert.ToDouble(ml.EvaluateToOutputForm("Y[2.]", 0)), Convert.ToDouble(ml.EvaluateToOutputForm("Z[2.]", 0))); points[3] = new DPoint3d(Convert.ToDouble(ml.EvaluateToOutputForm("X[3.]", 0)), Convert.ToDouble(ml.EvaluateToOutputForm("Y[3.]", 0)), Convert.ToDouble(ml.EvaluateToOutputForm("Z[3.]", 0))); points[4] = new DPoint3d(Convert.ToDouble(ml.EvaluateToOutputForm("X[4.]", 0)), Convert.ToDouble(ml.EvaluateToOutputForm("Y[4.]", 0)), Convert.ToDouble(ml.EvaluateToOutputForm("Z[4.]", 0))); points[5] = new DPoint3d(Convert.ToDouble(ml.EvaluateToOutputForm("X[5.]", 0)), Convert.ToDouble(ml.EvaluateToOutputForm("Y[5.]", 0)), Convert.ToDouble(ml.EvaluateToOutputForm("Z[5.]", 0))); points[6] = new DPoint3d(Convert.ToDouble(ml.EvaluateToOutputForm("X[6.]", 0)), Convert.ToDouble(ml.EvaluateToOutputForm("Y[6.]", 0)), Convert.ToDouble(ml.EvaluateToOutputForm("Z[6.]", 0))); points[7] = new DPoint3d(Convert.ToDouble(ml.EvaluateToOutputForm("X[7.]", 0)), Convert.ToDouble(ml.EvaluateToOutputForm("Y[7.]", 0)), Convert.ToDouble(ml.EvaluateToOutputForm("Z[7.]", 0))); points[8] = new DPoint3d(Convert.ToDouble(ml.EvaluateToOutputForm("X[8.]", 0)), Convert.ToDouble(ml.EvaluateToOutputForm("Y[8.]", 0)), Convert.ToDouble(ml.EvaluateToOutputForm("Z[8.]", 0))); points[9] = new DPoint3d(Convert.ToDouble(ml.EvaluateToOutputForm("X[9.]", 0)), Convert.ToDouble(ml.EvaluateToOutputForm("Y[9.]", 0)), Convert.ToDouble(ml.EvaluateToOutputForm("Z[9.]", 0))); // Always close the math link. ml.Close(); // Since we are inheriting from base bSplineCurve class, // we can call the base to generate the curve based on a collection of DPoint3ds. return base.ByPointsAsDPoint3ds(coord, points, false); } } }