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);
        }
    }
}
  • Share/Bookmark
Posted in Generative Components, Mathematics, Software Programming | Leave a comment

Wall Drawing 38

Drawing 38

Wall Drawing 38 is a wall sculpture designed by Sol LeWitt and first created in 1970 for the Tokyo Biennale.  The piece was reproduced in 2008 for the exhibition “Sol LeWitt: A Wall Drawing Retrospective” at the Massachusetts Museum of Contemporary Art in North Adams, MA and will be on display for 25 years.  The instructions for the piece call for the systematic insertion of tightly rolled and colored origami paper sheets into four peg-board walls.  Wall Drawing 38 is an early work of LeWitt that may have played a role in a transition towards the integration of variable steps and random events into the plans for later wall drawing projects.  Wall Drawing 38 highlights the reproducibility of LeWitt wall drawings, but also questions the validity of the reproduction and LeWitt’s assertion that “the same work can exist in two or more places at the same time” (Chan 14).   Read More »

  • Share/Bookmark
Posted in Sculpture | Leave a comment

Generative Components Feature Cache

This is a useful piece of code.  When you replicate features in GC, they are run serially.  By using a serialized cache of the point data, calls to the backend data source can be kept to a minimum.  This also provides a hook for late binding to the data source and making modifications before the points are sent on up to GC.  Another cache could be used by a cache modifier, so that serial tweaks could be made the the series of features as they are generated.

VIEW THE CODE

  • Share/Bookmark
Posted in C#, Generative Components, Software Programming | Leave a comment

Torus Knot

Torus Rapid Prototyped - Smart Geometry Conference 2009

Torus Rapid Prototyped - Smart Geometry Conference 2009

  • Share/Bookmark
Posted in Digital Media, Engineering, Generative Components, Mathematics, Sculpture, Software Programming | Leave a comment

Laplace Dirichlet Test

This is a milestone in the development of the project because the generation of this BSplineSurface depends on integration performed by Mathematica.

A lof of work has been done to solidify this piece of code since the Smart Geometry Conference 2009.

Performace on this object has been greatly improved.

Performace on this object has been greatly improved.

VIEW THE CODE

  • Share/Bookmark
Posted in Generative Components, Mathematics, Software Programming | Leave a comment

Torus Knot

TorusKnot

Mathematica Integration Providing a Torus Knot BSplineCurve

Added a Frenet Frame to Torus Knot

Added a Frenet Frame to Torus Knot

Added Solids to Frenet Frame and adjusted Torus h

Added Solids to Frenet Frame and adjusted Torus h

VIEW THE CODE

  • Share/Bookmark
Posted in Generative Components, Mathematics, Software Programming | 1 Comment

BSplineCurveMath byXYZFunction

bsplinecurvemath3

VIEW THE CODE

  • Share/Bookmark
Posted in Generative Components, Mathematics, Software Programming | 3 Comments

Simple Mathematica / Generative Components Integration

So I am attempting to connect Generative Components to Mathematica using c#. This is a first step: math commands can be executed by passing a string from GC to Mathematica. A new feature called MathCommand is available. The question remains: what can I do with this? What kind of data can I get back from Mathematica that might be useful, and how can I consume that data to render something on the screen?

using System;
using Bentley.Geometry;
using Bentley.GenerativeComponents;
using Bentley.GenerativeComponents.MicroStation;
using Bentley.Interop.MicroStationDGN;
using Wolfram.NETLink;

namespace Bentley.GenerativeComponents.Features
{
    public class MathCommand : Feature
    {
        [Update]
        public bool ByString
        (
            FeatureUpdateContext updateContext,
            string command
        )
        {
            MathKernel mathKernel = new MathKernel();

            if (mathKernel.IsComputing)
            {
                mathKernel.Abort();
            }
            else
            {
                mathKernel.Compute(command);
            }
            return true;
        }
    }
}
  • Share/Bookmark
Posted in Generative Components, Mathematics, Software Programming | Leave a comment

Frenet Frame

Frenet Frame on Helix

Frenet Frame on Helix

  • Share/Bookmark
Posted in Generative Components | Leave a comment

Lines in Space

  • Share/Bookmark
Posted in Sculpture | Leave a comment

Default Configuration

Here is a default way to setup a breadboard, with a power light and a protective diode.

DSC_0409

  • Share/Bookmark
Posted in Digital Media | Leave a comment

Digital IO

From http://itp.nyu.edu/physcomp/Labs/DigitalInOut

DSC_0407 DSC_0408

  • Share/Bookmark
Posted in Digital Media | Leave a comment

Simple Switch

Here is a simple switch.  Magnetic kissing dolls powered by two 3v coin cells in series.  LED’s are in series.  Would like them to be in parallel, but made the setup too messy.

DSC_0405

DSC_0406

  • Share/Bookmark
Posted in Digital Media | Leave a comment

Knight Rider

From http://www.arduino.cc/en/Tutorial/KnightRider

We have named this example in memory to a TV-series from the 80′s where the famous David Hasselhoff had an AI machine driving his Pontiac. The car had been augmented with plenty of LEDs in all possible sizes performing flashy effects.

Thus we decided that in order to learn more about sequential programming and good programming techniques for the I/O board, it would be interesting to use the Knight Rider as a metaphor.

This example makes use of 6 LEDs connected to the pins 2 – 7 on the board using 220 Ohm resistors. The first code example will make the LEDs blink in a sequence, one by one using only digitalWrite(pinNum,HIGH/LOW) and delay(time). The second example shows how to use a for(;;) construction to perform the very same thing, but in fewer lines. The third and last example concentrates in the visual effect of turning the LEDs on/off in a more softer way.

I loaded the three sets of example code onto the Arduino.

DSC_0400 

  • Share/Bookmark
Posted in Digital Media | Leave a comment

Protected: Markus Schinwald, “Bob,” 2007.

This post is password protected. To view it please enter your password below:


  • Share/Bookmark
Posted in Digital Media | Leave a comment

Creating a full text search interface using Adobe Flex

I wanted to see how easy it would be to create a search interface using SQL Server 2005 Express, Microsoft Visual Web Developer Express 2008, and Adobe Flex Builder 2. It turns out, it is quite easy.

The first step was to install both SQL Server 2005 Express and Visual Web Developer 2008 – free downloads available from Microsoft’s Web Site. I then downloaded Microsoft’s sample Adventure Works database. I played around a bit with full text searching and full text indexed most of the columns in the customers table. I then wrote a simple stored procedure:

CREATE PROCEDURE [dbo].[fts_Customers]
(@SearchWords nvarchar(255))
AS
SELECT * FROM SalesLT.Customer
WHERE CONTAINS(*, @SearchWords);

The next step was creating the web service code. It seems as though datasets and Flex are not very friendly towards one another, so I created a simple struct to represent a customer:

public struct Customer{
public int CustomerID;
public string Title;
public string FirstName;
public string MiddleName;
public string LastName;
public string CompanyName;
public string SalesPerson;
public string EmailAddress;
public string Phone;
}

And then the Web Service:

[WebService(Namespace = "http://tempuri.org/")]
public class CustomersService : System.Web.Services.WebService {
[WebMethod]public Customer[] fts_Customers(string searchtext)
{
SqlConnection conn = new    SqlConnection(ConnectionStrings["ADVENTUREWORKSLT_DATA.MDFConnectionString"].ConnectionString);
SqlCommand comm = new SqlCommand("fts_Customers", conn);
comm.CommandType = System.Data.CommandType.StoredProcedure;
comm.Parameters.AddWithValue("@SearchWords", searchtext);
conn.Open();
SqlDataAdapter da = new SqlDataAdapter(comm);
DataSet ds = new DataSet();
da.Fill(ds);
conn.Close();
int i = 0;
Customer[] customers = new Customer[ds.Tables[0].Rows.Count];
foreach (DataRow row in ds.Tables[0].Rows)
{
customers[i] = new Customer();
customers[i].CustomerID = (int)row["CustomerID"];
customers[i].Title = row["Title"].ToString();
customers[i].FirstName = row["FirstName"].ToString();
customers[i].MiddleName = row["MiddleName"].ToString();
customers[i].LastName = row["LastName"].ToString();
customers[i].CompanyName = row["CompanyName"].ToString();
customers[i].SalesPerson = row["SalesPerson"].ToString();
customers[i].EmailAddress = row["EmailAddress"].ToString();
customers[i].Phone = row["Phone"].ToString();
i++;
}
return customers;
}
}

Next we can move on to the Flex coding. Here is how I defined the call to the WebService:


{SearchTextBox.text}

Finally, add the text input, the button, and the datagrid.


There we have it. All the cool features of the Adobe Flex Data Grid at our disposal.

flexgrid.jpg

  • Share/Bookmark
Posted in C#, Software Programming | Leave a comment

Correctly parsing quotation marks in Full Text search queries

I ran into an issue with my current client involving full text search queries. Microsoft explains the issue best, here:

The CONTAINS syntax requires double quotation marks for prefix (“choc*”) and for multiple word or phrase searches (“chocolate chip” or “oatmeal”). This can be problematic in terms of UI design, because users are not accustomed to having to properly quote their searches and are prone to making mistakes when they do. A simple function is needed that developers can use to properly quote a query string before passing it to SQL Server.

http://support.microsoft.com/kb/246800

Microsoft then goes on to provide a solution using only VBScript and JavaScript. Well, if you are interested in a C# version of the code, look no further.


public class FullTextSearchParser
{
public static string Parse(string searchString)
{
searchString = ReplaceAllDoubleQuotes(searchString);
if (ContainsSpecial(searchString))
{
return searchString;
}
else
{
searchString = SurroundAndAndNot(searchString);
searchString = SurroundOrOrNot(searchString);
searchString = SurroundWithQuotes(searchString);
return searchString;
}
}

public static string ReplaceAllDoubleQuotes(string instring) {
return instring.Replace("\"", "");
}

public static bool ContainsSpecial(string instring)
{
if (ContainsNear(instring) | ContainsFormsOf(instring) | ContainsIsAbout(instring))
{
return true;
}
else
{
return false;
}
}

public static bool ContainsNear(string instring)
{
return instring.ToUpper().Contains("NEAR");
}

public static bool ContainsFormsOf(string instring)
{
return instring.ToUpper().Contains("FORMSOF");
}

public static bool ContainsIsAbout(string instring)
{
return instring.ToUpper().Contains("ISABOUT");
}

public static string SurroundAndAndNot(string instring)
{
Regex andNotAnd = new Regex("(and not|and)", RegexOptions.IgnoreCase);
return andNotAnd.Replace(instring, "\"" + "$1" + "\"");
}

public static string SurroundOrOrNot(string instring)
{
Regex andNotAnd = new Regex("(or not|or)", RegexOptions.IgnoreCase);
return andNotAnd.Replace(instring, "\"" + "$1" + "\"");
}

public static string SurroundWithQuotes(string instring)
{
return "\"" + instring + "\"";
}

}
  • Share/Bookmark
Posted in C#, Software Programming | Leave a comment