@duanemclemore, ok I also just saw your code.
I think you are doing some very weird stuff. What is the purpose of of the Lattice
class? it cant just be a 1D array with 3 elements, it has no functionality for graph theory applications as you can see on my above examples there are many more things to add.
In my head the Lattice
class you are trying to do is more like a " Field " of data or, better yet a Graph which in your case it will store a N points. So I ask you again, what are you trying to achieve?
If you just want to store some objects with properties in a Graph class you can do something like this to start with
public class Node<T>
{
private T m_value;
private Point3d m_position
public Node() { }
/// <summary>
///
/// </summary>
/// <param name="val"></param>
public Node( Point3d position, T val)
{
m_value = val;
m_position = position;
}
/// <summary>
/// Get value stored in node
/// </summary>
public T Value
{
get { return m_value; }
set { m_value = value; }
}
public Point3d Position
{
get { return m_position; }
set { m_position = value; }
}
}
public class Graph
{
private int m_columns;
private int m_rows;
private int m_height;
private double m_resolution;
private Node<T>[,,] m_Field;
/// Create Graph Object
public Graph(int columns, int rows,int height, double resolution, T [,,]data)
{
m_columns = columns;
m_rows = rows;
m_height = height
m_resolution = resolution;
m_Field = new Node<T>[m_columns, m_rows,m_height];
/// Initialize nodes
for (int i = 0; i < m_columns; i++)
{
for (int j = 0; j < m_rows; j++)
{
for (int j = 0; j < m_rows; j++)
{
m_Field[i, j,k] = new Node<T>( new Vec3(i * m_resolution, j * m_resolution, 0), data[i, j,k]);
}
}
}
}
public int Columns
{
get { return m_columns; }
set{m_columns = value;}
}
public Node<T>[,,] Field
{
get { return m_Field; }
set{ m_Field = value;}
}
public Point3d [,] Grid
{
get { return DisplayField(); }
}
public double Resolution
{
get { return m_resolution; }
set{m_resolution = value}
}
public int Rows
{
get { return m_rows; }
set{m_rows = value}
}
#region METHODS
// Here you can all all your methods
vecs[i, j] = (Point3d)m_Field[i, j].Position;
private Point3d[,] DisplayField()
{
Point3d[,,] pts = new Point3d[m_columns, m_rows,m_height];
for (int i = 0; i < m_columns; i++)
{
for (int j = 0; j < m_rows; j++)
{
for (int k = 0; k < m_height; k++)
{
pts[i, j,k] = m_Field[i, j,k].Position;
}
}
}
return pts;
}
#enregion
}
In your grasshopper component:
protected override void RegisterInputParams(GH_Component.GH_InputParamManager pManager)
{
pManager.AddIntegerParameter("columns", "columns", "", GH_ParamAccess.item, 50);
pManager.AddIntegerParameter("rows", "rows", "", GH_ParamAccess.item, 50);
pManager.AddIntegerParameter("height", "height", "", GH_ParamAccess.item, 50);
pManager.AddNumberParameter("resolution", "resolution", "", GH_ParamAccess.item, 1);
pManager.AddNumberParameter("values", "", "", GH_ParamAccess.list);
}
/// <summary>
/// Registers all the output parameters for this component.
/// </summary>
protected override void RegisterOutputParams(GH_Component.GH_OutputParamManager pManager)
{
pManager.AddGenericParameter("Graph", "Graph", "", GH_ParamAccess.item);
pManager.AddPointParameter("Graph", "Graph", "", GH_ParamAccess.item);
}
/// <summary>
/// This is the method that actually does the work.
/// </summary>
/// <param name="DA">The DA object is used to retrieve from inputs and store in outputs.</param>
protected override void SolveInstance(IGH_DataAccess DA)
{
int _columns = 0;
int _rows = 0;
int _height = 0;
double _resolution = 0;
/// just assuming its double but data is supposed to be generic
List<double> _data = new List<double>();
DA.GetData(0, ref _columns);
DA.GetData(1, ref _rows);
DA.GetData(2, ref _height);
DA.GetData(3, ref _resolution);
DA.GetDataList(4, ref _data);
int var index = 0;
double [,,] data3D = new double [_columns,_rows,_height];
for (int i = 0; i < _columns; i++)
{
for (int j = 0; j < _rows; j++)
{
for (int k = 0; k < _height; k++)
{
data3D[i, j,k] = _data[index++];
}
}
}
Graph g = new Graph<double>(_columns, _rows, _resolution, data3D);
// send to ouptut
DA.SetData(0, g);
// This will show all the points in grasshopper
DA.SetDataList(1, g.Grid);
}