JimYuan's Blog

Sharing the things I learned

0%

The original article:
Link

When we delete a node, three possibilites arise.

  1. Node to be deleted is leaf: Simply remove from the tree.
  2. Node to be deleted has only one child: Copy the child to the node and delete the child.
  3. Node to be deleted has two children: Find inorder successor of the node. Copy contents of the inorder successor to the node and delete the inorder successor. Note that inorder predecessor can also be used.

The important thing to note is:
Inorder successor is needed only when right child is not empty.

Also, I learned from the visualization algorithm websiteLINK.

1
2
3
4
5
6
7
8
search for v
if v is a leaf
delete leaf v
else if v has 1 child
bypass v
else
replace v with successor

It is worth noting that when you delete nodes in a tree, deletion process will be in post-order. That is to say, when you delete a node, you will delete its left child and its right child before you delete the node itself.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
#include <bits/stdc++.h>
using namespace std;

struct node{
int key;
struct node *left, *right;
}

struct node* newNode(int item){
struct node* temp = (struct node*)malloc(sizeof(struct node));
temp->key = item;
temp->left = temp->right = NULL;
return temp;
}

void inorder(struct node* root){
if(root != NULL){
inorder(root->left);
cout<<root->key;
inorder(root->right);
}
}

struct node* insert(struct node* node, int key){
if(node == NULL)
return newNode(key);
if(key < node->key){
node->left = insert(node->left, key);
}
else
node->right = insert(node->right, key);

// return the (unchanged) node pointer.
return node;
}

struct node* minValueNode(struct node* node){
struct node* current = node;

while(current && current->left != NULL)
current = current->left;

return current;
}

struct node* deleteNode(struct node* root, int key){
if(root == NULL)
return root;

if(key < root->key)
root->left = deleteNode(root->left, key);
else if(key > root->key)
root->right = deleteNode(root->right, key);
// if key is same as root's key, then this is the node
// to be deleted
else{
// 1. node with only one child or no child
if(root->left == NULL){
struct node* temp = root->right;
free(root);
return temp;
}
else if(root->right == NULL){
struct node* temp = root->left;
free(root);
return temp;
}
// 2. node with 2 children: Get the inorder successor(smallest in the right subtree)
struct node* temp = minValueNode(root->right);
root->key = temp->key;
root->right = deleteNode(root->right, temp->key);
}
return root;
}


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
using System;
public class BinarySearchTree{
class Node{
public int key;
public Node left, right;
public Node(int item){
key = item;
left = right = null;
}
}
// Root of BST
Node root;
BinarySearchTree(){root = null;}
void deleteRec(Node root, int key){
if(root == null)
return root;
if(key< root.key)
root.left = deleteRec(root.left, key);
else if(key > root.key)
root.right = deleteRec(root.right,key);
else{
if(root.left == null)
return root.right;
else if(root.right == null)
return root.left;

root.key = minValue(root.right);
root.right = deleteRec(root.right, root.key);
}
return root;
}

int minValue(Node root){
int minv = root.key;
while(root.left != null){
minv = root.left.key;
root = root.left;
}
return minv;
}

void insert(int key){root = insertRec(root, key);}

Node insertRec(Node root, int key){
if(root == NULL){
root = new Node(key);
return root;
}
}

void inorder(){ inorderRec(root);}

void inorderRec(Node root){
if(root!=null){
inorderRec(root.left);
Console.Write(root.key + " ");
inorderRec(root.right);
}
}
}

This post is for the notes for me re-learning ‘binary search’, somehow I feel like I have been learned this algorithm couple times. But shame to say, I still do not feel I totally get the idea behind, as for how to implement this. I hope I can spend some quailty time for once again learn and master binary Tree.

The note here, and as code are from the GeeksforGeeksLink.

Binary Search Tree

**Binary Search Tree ** is a ‘node-based’ binary tree data structure which has the following properties.

  • The left subtree of a node contains only nodes with keys lesser than the node’s key.
  • The right subtree of a node contains only nodes with keys greater than the node’s key.
  • The left and right subtree each must also be a binary search tree.

Binary Search Tree| Set1(Search and Insertion)

Operations like search, minimum and maximum can be done fast.

Searching a key

If we had a sorted array we could performed a binary search.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
#include <iostream>
using namespace std;

class BST{
int data;
BST *left, *right;
public:
BST();
BST(int);
BST* Insert(BST*, int);
void Inorder(BST*); // Inorder traversal.
};

// default constructor definition
BST:: BST() : data(0), left(NULL),right(NULL){

}
// Parameterized constructor definition
BST::BST(int value){
data = value;
left = right = NULL;
}

// Insert function definition.
BST* BST :: Insert(BST* root, int value){
if(!root){
// insert the first node, if root is NULL
return new BST(value);
}
// Insert data
if(value > root->data){
root->right = Insert(root->right,value);
}
else{
root->left = Insert(root->left,value);
}
return root;
}
// Inorder traversal function
void BST::Inorder(BST* root){
if(!root){
return;
}
Inorder(root->left);
cout<<root->data<<endl;
Inorder(root->right);
}

// Driver code
int main()
{
BST b, *root = NULL;
root = b.Insert(root, 50);
b.Insert(root, 30);
b.Insert(root, 20);
b.Insert(root, 40);
b.Insert(root, 70);
b.Insert(root, 60);
b.Insert(root, 80);

b.Inorder(root);
return 0;
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
using System;
class BinarySearchTree{
public class Node{
public int key;
public Node left, right;
public Node(int item){
key = item;
left = right = NULL;
}
}

Node root;
BinarySearchTree(){
root = null;
}

void insert(int key){
root = insertRec(root, key);
}

Node insertRec(Node root, int key){
if(root == null){
root = new Node(key);
return root;
}

if(key < root.key)
root.left = insertRec(root.left, key);
else if( key> root.key)
root.right = insertRec(root.right, key);

//return the (unchanged) node pointer
return root;
}

void inorder(){
inorderRec(root);
}

void inorderRec(Node root){
if(root != null){
inorderRec(root.left);
Console.WriteLine(root.key);
inorderRec(root.right);
}
}


public static void Main(String[] args)
{
BinarySearchTree tree = new BinarySearchTree();

/* Let us create following BST
50
/ \
30 70
/ \ / \
20 40 60 80 */
tree.insert(50);
tree.insert(30);
tree.insert(20);
tree.insert(40);
tree.insert(70);
tree.insert(60);
tree.insert(80);

// Print inorder traversal of the BST
tree.inorder();
}

}



OriginalTag

From this week’s(2020/07/03) Parametric Camp, Professor Jose Luis García del Castillo y López challenged us to do Chaikin’s Algorithm by ourselves.
I think it will be great if I made some notes about how I thought and my work here.

The code is pretty straight forward, some little thing might notice

  • while iterating thought points, the index // should careful segmentation fault
  • Points in RhinoCommon can work like vector, this concept inherit from linear algebra, anyway this means you can multiple them scale the vector
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
private void RunScript(List<Point3d> polyLinePts, int iterNum, ref object A)
{
vertex = polyLinePts;
List<Point3d> smoothPts = new List<Point3d>();
for(int i = 0; i < iterNum ;i++){
smooth(vertex, ref vertex);
}
A = vertex;
}
// <Custom additional code>
List<Point3d> vertex;
//Deal with one iteration
void smooth(List<Point3d> inputPts, ref List<Point3d> resultPts){
List<Point3d> nextGen = new List<Point3d>();
// point 0 1 2 ... n
// point 1 2 3 ... n-1
// line 0 1 2 ... n
for(int i = 0; i < inputPts.Count - 1; i++){
Point3d oneFourth = inputPts[i] * 0.25 + inputPts[i + 1] * 0.75;
Point3d threeFourth = inputPts[i] * 0.75 + inputPts[i + 1] * 0.25;

nextGen.Add(threeFourth);
nextGen.Add(oneFourth);
}
resultPts = nextGen;
}

Thing that I have not achieved,

  • the endpoints are not included.
  • Have not tackled the closed polyline situation

Some thought about Closed one, should deal with the iteration, especially the end point. LOL

We can also change the ratio(0.25, 0.75) to something else
OriginalTag

One thing can be noticed that there is always one point will converge to the original segment.
While iteration goes larger the point will be the middle point of the original segment.

Here I would like to note the way to customize the self-defined line weight display in Grasshopper.

Regular Tag/ dimension

Some readers might familir with the original tag/dimension components provided in Grasshopper.
A very simple demo picture is like these,

Line Dimension

OriginalTag

Aligned Dimension

OriginalTag
Little difference might be noticed, alignmenet dimension can offset the display lines.

Line Weight + Tag (Csharp customized)

OriginalTag

Tag

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
private void RunScript(List<Point3d> Locations, List<string> Descriptions, string Font, int Size, System.Drawing.Color Color, bool Tag, ref object A)
{
clear_textdots();

if(Tag){
var attr = new Rhino.DocObjects.ObjectAttributes();
attr.ColorSource = Rhino.DocObjects.ObjectColorSource.ColorFromObject;
attr.ObjectColor = Color;
for(int i = 0; i < Locations.Count;i++){
var tdot = create_textdot(Descriptions[i], Locations[i], Size, Font);
Rhino.RhinoDoc.ActiveDoc.Objects.AddTextDot(tdot, attr);
}
}
else{
clear_textdots();
}
}

TextDot create_textdot(string text_str, Point3d point, int height, string font){
height = -1;
var textdot = new TextDot(text_str, point);
if(height > 0)
textdot.FontHeight = height;
if(font != null)
textdot.FontFace = font;
return textdot;
}

void clear_textdots(){
var textdots = Rhino.RhinoDoc.ActiveDoc.Objects.FindByObjectType(Rhino.DocObjects.ObjectType.TextDot);
if(textdots.Length > 0){
foreach(var tdot in textdots){
Rhino.RhinoDoc.ActiveDoc.Objects.Delete(tdot, true);
}
}
}

Line Weight

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
private void RunScript(List<Polyline> plns, System.Drawing.Color Color, List<Point3d> pts, int width, ref object A)
{
pln = plns;
IList<Point3d> ipts = pts;
_clippingBox = new BoundingBox(ipts);
_color = Color;
_width = width;
//A = _clippingBox;
}

// <Custom additional code>
List<Polyline> pln;
Color _color;
int _width;
BoundingBox _clippingBox;
public override void BeforeRunScript(){
_clippingBox = BoundingBox.Empty;
}
public override BoundingBox ClippingBox{
get{return _clippingBox;}
}
public override void DrawViewportMeshes(IGH_PreviewArgs args) {
//for (int i = 0 ; i < limit; i++)
//args.Display.DrawPoint(pts[i], Rhino.Display.PointStyle.Simple, 10, Color.FromArgb(100, 255 - i / 10, 255 - i / 10, 255 - i / 10));
foreach(Polyline tmppln in pln)
args.Display.DrawPolyline(tmppln, _color, _width);

}

In the case of override the DataTree(Point3d):

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
private void RunScript(DataTree<Point3d> points, List<System.Drawing.Color> colors, ref object A)
{

Bpoints = points;
Bcolor = colors;
}

// <Custom additional code>
DataTree<Point3d> Bpoints = new DataTree<Point3d>();
List<Color> Bcolor = new List<Color>();
public override BoundingBox ClippingBox{
get{
return new BoundingBox(new Point3d(0, 0, 0), new Point3d(10, 10, 10));
}
}
public override void DrawViewportWires(IGH_PreviewArgs args){
int j = 0;
for(int i = 0;i < Bpoints.BranchCount;i++){
args.Display.DrawPoints(Bpoints.Branches[i], Rhino.Display.PointStyle.Circle, 5, Bcolor[j]);
//args.Display.DrawPoints(,)
j++;
}
}

SweepLineSeries

Line-Segment Intersection

Problem

Given a set S of n closed non-overlapping line segments in the plane, compute…

  • all points where at least two segments intersect and
  • for each such point report all segments that contain it.
  1. Brute Force, takes $O(n^2)$
  2. Process segments top-to-bottom using a sweep line.

Consider when we should do something while using sweepLine algorithm

  1. SweepLine touch the endpoint
  2. SweepLine touch(identify) the intersection point

Event Points

  • Endpoints on the segments
  • intersection points

Once the SweepLine run over the intersection point, should reconsider the possible intersect pair(neighbor) situation.

DataStructure For Event Points queue Q

When we think about situable data structure to tackle this problem should consider,
The data structure should fit

  1. can easily find the top most point
  2. can insert new event point while finding the intersection points, in run time.

Store event points in balanced binary search tree

SweepLine status T

When segments intersect to the SweepLine, we want them be ordered from left to right.

  1. easily add/reomove a segment
  2. swap the segment order, happen right after the intersection point found

Pseudo-code

findIntersections(S)

Input:

set S of n non-overlapping closed line segments

Output:

  • set I of intersection points
  • for each $p \in I$ every $s \in S$ with $p \in s$

There are 2 goals of partitions into convex pieces

  1. parition a polygon into as few convex pieces as possible
  2. do so as quickly as possible

Two types of partition of a polygon P may be distingusihed

  1. a partition by diagonals (endpoints must be vertices)
  2. a partition by segments (endpoints need lie on $\partial P$)

The distinction is that diagonal endpoints must be vertices, whereas segment endpoints need lie on $\partial P$

Optimum Partition

To evalute the efficiency of partitions, it is useful to have bounds on the best possible partition.

Theorem 2.5.1(Chazelle)

Let $\phi$ be the fewest number of convex pieces into which a polygon may be partitioned.
For a polygon of r reflex vertices,
$$\frac{r}{2}+1 \leq \phi \leq r+1$$

Reflex vertice:
In a polygon, a vertex is called “convex“ if the internal angle of the polygon is less the $\pi$ randians; otherwise, it is called “concave“ or “reflex

Hertel and Mehlhorn Algorithm

Hertel & Melhorn (1983) found a very clean algorithm that partitions with diagonals quickly and has bounded “badness” in terms of the number of convex pieces.
In some convex partition of a polygon by diagonals, call a diagonal d is essential vertex v if removal of d creates a piece that is nonconvex at v.
Clearly if d is essential it must be incident to v, and v must be reflexed.
A diagonal that is not essential for either of its endpoints is called inessential

Hertel and Mehlhorn’s algorithm is simply this:
Satrt with a trinagulation of P; remove an inessential diagonal; repeat.
Clearly this algorithm results in a partition of P by diagonals into convex pieces.
It can be accomplished in linear time with the use of appropriate data structure. So the only issue is how far from the optimum might it be.

Lemma 2.5.2

There can be at most two diagonals essential for any reflex vertex

Philipp Kindermann

Part. a Polygon into Monotone Pieces

Idea: Classify vertices of given simple polygon P

  • turn vertices:
    • start vertex
    • split vertex
    • end vertex
    • merge vertex
  • regular vertices

Lemma.

Let P be a simple polygon. Then P is y-monotone <-> P has neither split vertices nor merge vertices

The idea here is try to destory

  1. split vertices
  2. merge vertices

Problem: Diagonals must not cross

  • each other
  • edges of P

前言

可能大家有接觸過用Grasshopper作環境分析,那可能會知道Isovist這個方便的component。從下面看到這Component可以幫助決定視野範圍
Orientation

原理很簡單就是2D的圓看根最近的建築物交界到哪裡。

建築物的線我是透過Elk放入OpenStreetMap達成的。可以參考一下
OSM_Through_Elk
或是我的方式:
Orientation

Csharp code

我意外看到這篇討論,想說自己也來實作一下用C#做一個IsoVist之後討論一下怎麼加速,跟後續可能可以玩的方向
IsoVist_Optimization
而我自己的Code

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
private void RunScript(Point3d PlanePt, int Count, int Radius, List<Polyline> ObsCrv, ref object Points, ref object C, ref object A)
{
List<Point3d> pts = new List<Point3d>();
Circle cir = new Circle(PlanePt, Radius);
Curve CirCrv = cir.ToNurbsCurve();
Point3d[] CirPts;
double[] CirPts_double = CirCrv.DivideByCount(Count, true, out CirPts);
List<Point3d> result_net = new List<Point3d>();
for(int k = 0; k < Count; k++){
Line ln = new Line(PlanePt, CirPts[k]);
List<Point3d> ln_Pts = new List<Point3d>();
for(int i = 0; i < ObsCrv.Count; i++){
Line[] segs = ObsCrv[i].GetSegments();
for(int j = 0; j < segs.Length; j++){
double a;
double b;
Intersection.LineLine(ln, segs[j], out a, out b, 0.00000001, true);
if(Intersection.LineLine(ln, segs[j], out a, out b, 0.00000001, true)){
ln_Pts.Add(segs[j].PointAt(b));
}
}
}
Point3d closest_pt;
if(ln_Pts.Count > 0)
closest_pt = Point3dList.ClosestPointInList(ln_Pts, PlanePt);
else{
closest_pt = CirPts[k];
}
result_net.Add(closest_pt);
}
A = result_net;
C = CirPts;
}

演算法的想法

  • 平分個一個以人為圓點的圓,分成Count分
  • 用圓點跟在圓周上的點連線ln 和 每個建築物的牆壁segs[j]找相交點
  • 有兩個以上交點的話找離圓點最近的,沒有跟建築物相交的話 回傳圓周上的點

關於LineLine的相交

在部落格我分別寫了兩篇(2D/3D)的線與線相交的判定。
三維的線與線相交其實是看兩條線的最短距離<容許值

ParametricCamp有比較完整的介紹
Computational Design Live Stream #14

論壇po文想達成的是盡量加速這個運算,之後我也能往那方向想,目前是跟Component效能差不多
Orientation

  • 目前的想到的想法是可以先對那些牆壁的line以角度sort過一遍,應該可以加速一個for-loop
  • Demo

    Orientation

可能的發展

加速

加速的理由有很多,

  1. 為了一次分析多一點人
  2. 讓計算時間變短-Real time result

導入Magnetic field

在Grasshopper裡面有Fields對人流動線的分析應該會很有幫助
有興趣可以看看這個
https://www.youtube.com/watch?v=zSI1StT07LM

扇形視野

最後可能可以分析的是更接近真實的視野,不是360度。轉成170之類的。
Orientation

Resource

Events

  • A mechanism for communication between objects
  • Used in building Loosely Coupled Applications
  • Helps extending applications

Example

1
2
3
4
5
6
7
8
9
public class VideoEncoder{
public void Encode(Video video){
// Encoding logic
// ...

_mailService.Send(new Mail());

}
}

but, in the future, if we want to send text message to the video owner.

1
2
3
4
5
6
7
8
9
10
public class VideoEncoder{
public void Encode(Video video){
// Encoding logic
// ...

_mailService.Send(new Mail());

_messageService.Send(new Text());
}
}

but if we do it this way, the whole Encode() method will need to be recompiled, and the class depends on this function, will need to be recompiled and redeploied.

We want to design our application such that when you want to change that, it changes the minimum impact on the application

We can use Event to deal with this problem.

How we do event in this case

  • VideoEncoder
    1. publisher
    2. event sender
  • MailService
    1. Subscriber
    2. event receiver

So, in future.

  • MessageService
    1. Subscriber
    2. event receiver

Main changes

1
2
3
4
5
6
7
8
public class VideoEncoder{
public void Encode(Video video){
// Encoding logic
// ...

OnVideoEncoded();
}
}

OnVidoEncoded() method simply notify the subscribers.

VideoEncoder knows absoulately nothing about the MailService and MessageService or any other subscribers.
They(subscribers) can come later, and we can add more subscribers.

One Question Raise: How VideoEncoder(publisher) notify its subscribers

We need an agreement or contract between publisher and its subscribers.

1
2
3
public void OnVideoEncoded(object source, EventArgs e){

}

This is a very typical implementation of method in the subscribers, and it is called EventHandler.
This is also the method which called by the publisher when the event is raised.

Again, VideoEncoder(Event Publisher) do not know the existence of its publishers. Publisher decoupled from them(subscribers).
All the publisher knows, is a method(EventHandler).

How do you tell VideoEncoder(Publisher) what method to call?

That’s where a Delegate comes in.

Delegates

  • Agreement/ Contract between Publisher and Subscriber
  • Determines the signature of the event handler method in Subscriber
  1. Define a delegate
  2. Define an event based on that delegate
  3. Raise the event
1
public delegate void VideoEncodedEventHandler(object source, EventArgs args);
  • object source : source of that event
  • EventArgs args: any additional data we want to send to the event

Here we declare an event, which hold a reference to a function, look like

1
void VideoEncodedEventHandler(object source, EventArgs args);

Implementation

Program.cs

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
namespace EventsAndDelegates
{
class Program
{
static void Main(string[] args)
{
var video = new Video() { Title = "Video 1" };
var videoEncoder = new VideoEncoder(); // publisher
var mailService = new MailService(); // subscriber
var messageSerive = new MessageService(); // subscriber


videoEncoder.VideoEncoded += mailService.OnVideoEncoded; // VideoEncoded event behind the scene, is a list of function pointers. OnVideoEncoded is the function pointer
videoEncoder.VideoEncoded += messageSerive.OnVideoEncoded;


videoEncoder.Encode(video);
}
}
}

Video.cs

1
2
3
4
5
6
7
namespace EventsAndDelegates
{
public class Video
{
public string Title { get; set; }
}
}

VideoEncoder.cs

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
using System;
using System.Threading;

namespace EventsAndDelegates
{
public class VideoEventArgs : EventArgs
{
public Video Video { get; set; }
}

public class VideoEncoder
{
// 1- Define a delegate
// 2- Define an event based on that delegate
// 3- Raise the event

public delegate void VideoEncodedEventHandler(object source, VideoEventArgs args); // 1. define a delegate
public event VideoEncodedEventHandler VideoEncoded; // 2. define an event based on the delegate

public event EventHandler<VideoEventArgs> VideoEncoding;
public void Encode(Video video)
{
Console.WriteLine("Encoding Video...");
Thread.Sleep(3000);

OnVideoEncoded(video); // 3. Raise the event
}
protected virtual void OnVideoEncoded(Video video)
{
if (VideoEncoded != null)
VideoEncoded(this, new VideoEventArgs() { Video = video });
}
}
}

MailService.cs

1
2
3
4
5
6
7
8
9
10
11
12
using System;

namespace EventsAndDelegates
{
public class MailService
{
public void OnVideoEncoded(object source, VideoEventArgs e)
{
Console.WriteLine("MailService: Sending an email..." + e.Video.Title);
}
}
}

MessageService.cs

1
2
3
4
5
6
7
8
9
10
11
12
using System;

namespace EventsAndDelegates
{
public class MessageService
{
public void OnVideoEncoded(object source, VideoEventArgs e)
{
Console.WriteLine("MessageService: Sending a text message..." + e.Video.Title);
}
}
}

Result

idea

clarification_about_IGH

All objects that want to be part of a GH_Document must implement the IGH_DocumentObject interface.

This interface provides core methods needed for all objects

  1. Undo
  2. Autosave
  3. Display
  4. Menu
  5. Tooltip

IGH_ActiveObject extends upon IGH_DocumentObject and it provides methods for participating in the solution.

Parameters

Parameters(via the IGH_Param interface and several GH_Param<T> classes) maintain a data tree which is associated with a special type of IGH_Goo data. They have the logic build in that allows them to communicate with other parameters via their input/output wires.

Components

Components tend to drive from GH_Component(or at the very least implemeny IGH_Component), as that class provides all the bookkeeping methods for managing a collection of input and output parameters.

Attribute

Attributes are used primary for display purposes. Every object must be capable of creating and maintaining a class which ultimately implements IGH_Attributes. The attributes are in charge of

  1. rendering the object to the canvas
  2. providing basic information about the shape of an object
  3. handling mouse and key events
  4. responding correctly to selection actions
  5. maintaining the object hierarchy (Basically, it means that component attributes must be able to talk to input and output parameters, and the parameters need to be able to figure out they are slaved to a component.)

Custom Attribute SDK
Objects on the Grasshopper canvas consist of two part.
The most important piece is the class that implements the IGH_DocumentObject interface.
This interface provides the basic plumbing needed to make objects work within a Grasshopper node network.

The interface part of objects however is handled seperately.

Every IGH_DocumentObject carries around an instance of a class that implements the IGH_Attriibutes interface(indeed, every IGH_DocumentOBject knows how to create its own stand-alone attributes).

It is not possible to have an IGH_Attributes instance work on its own, we need an IGH_DocoumentObject to tie it to.

SQL

Structured Query Langauge

SQL is a programming language used to talk to the databases

Databases that use SQL

  1. SQL server
  2. Oracle
  3. MySQL
  4. Postgre SQL
  5. SQLite
  6. DB2
  7. BigData

Tools to write SQL

  1. SQL Server Management Studio (SSMS)
  2. SQL Developer
  3. SQL Workbench
  4. TOAD

Create Database


What is a Database(DB)?

  • Phone Book
  • Shopping list
  • Todo list
  • Your 5 best friends
  • Facebook’s User Base

Database can be stored in different ways

  • On paper
  • In your mind
  • On a computer
  • This powerpoint
  • Comment Section

Computers + Databases = <3

Amazon.com

  • Keeps track of Products, Reviews, Purchase Orders, Credit Cards…etc
  • Information is extremely valuable and critical to Amazon.com’s functioning
  • Security is essential

Computers are great at keeping track of large amounts of information

Database Managemeny Systems(DBMS)

  • A special software program that hekps users create and maintain a database.
    • Make it easy to manage large amounts of information
    • Handle Security
    • Backups
    • Importing/Exporting data
    • Concurrency
    • Interacts with software applications
      • Programming Languages

Amazon.com will interact with the DBMS in order to create, read, update and delete information.

C.R.U.D

  • Create
  • Read
  • Update
  • Delete

Two Types of Databases

Rational Databases(SQL)

  • Organize data into one or more tables
    • Each table has columns and rows
    • A unique key identifies each row

Non-Retional(noSQL/ not just SQL)

  • Organize data is anything but a tranditional table
    • Key-value stores
    • Documents(JSON, XML, etc)
    • Graphs
    • Flexible Table

Relational Databases(SQL)

Student Table

ID# Name Major
1 Jack Biology
2 Kate Sociology
3 Claire English
4 John Chemistry

User Table

UserName Password Email
jsmith22 wordpass
catlover45 apple223
gamerkid
  • Retional Database Management Systems(RDBMS)

    • Help users create and maintain a relational database
      • mySQL, Oracle, postgreSQL, mariaDB, etc.
  • Structed Query Language(SQL)

    • Standardized language for interacting with RDBMS
    • Used to perfrom C.R.U.D operations, as well as other administrative tasks(user management, security, backup, etc)
    • Used to define tables and structures
    • SQL code used on one RDBMS is not always portable to another without modification
  • Non-Relational Databases

    • Non-Relational Database Management Systems(NRDBMS)
      • Help users create and maintain a non-relational database
        • mongoDB, dynamoDB, apache, cassandra, firebase,etc
  • Implementation Specific

    • Any non-relational database falls under this category, so there’s no set language standard
    • Most NRDBMS will implement their own language for performing C.R.U.D and administrative operations on the database

Summary

Warp up

  • Database is any collection of related information
  • Computer are great for storing databases
  • Database Management Systems(DBMS) make it easy to create, maintain and secure a database.
  • DBMS allows you to perform the C.R.U.D operations and other administrative tasks
  • two types of Database, Relational & Non-Relational
  • Relational databases uses SQL and store data in tables with rows and columns
  • Non-Relational data store data using other data structures

student_id name major
1 Kate Sociology
2 Jack Biology
3 Claire English
4 Jack Biology
5 Mike Comp. Sci

Though there are two Jacks and they both major in Biology, we can use primary key, namely the student id, to identify them.

Structured Query Language(SQL)

  • SQL is a language used for interacting with Relational Database Management Systems(RDBMS)
    • You can use SQL to get the RDBMS to do things for you.
      • Create, retrieve, update & delete data
      • Create & manage databases
      • Design & create databases tables
      • Perform administration tasks(security, user management, import/export, etc)
    • SQL implementations cary between systems
      • Not all RDBMS’ follow the SQL standard to a T
      • The concepts are the same but the implementation may vary

Structured Query Language(SQL) _ Hybrid language

SQL is actually a hybrid language, it’s basically 4 types of languages in one

Data Query Language (DQL)

  • Used to query the database for information
  • Get information that is already stored there

Data Definition Language (DDL)

  • Used for defining database schemas

Data Control Language (DCL)

  • Used for controlling access to the data in the database.
  • User & permissions managemnet

Data Manipulation Language (DML)

  • Used for inserting, updating and deleting data from the databases

Queries

A query is a set of instructions given to the RDBMS(written is SQL) that tell the RDBMS what information you want it to retrieve for you.

  • Tons of data in a DB
  • Often hidden in a complex schema
  • Goal is only get the data you need
1
2
3
SELECT employee.name, employee.age
FROM employee
WHERE employee.salary > 30000;