images.reader.01

Option Explicit
‘Script written by
‘Script copyrighted by
‘Script version Monday, May 26, 2008 1:43:26 PM

Call Main()
Sub Main()
Dim surf
surf = Rhino.GetObject(“select surface”,8)
If isNull(surf) Then Exit Sub
Call reparameterize(surf)

Dim arrItems, arrValues, arrResults
arrItems = array(“Cell_Colums”,”Cell_Rows”,”Offset”,”Scale_btw_0-1″,”tabHeight”,”cutTemplate”,”surfaces”,”imageScale”,”imageOculi”)
arrValues= array(10,10,1,0.4,1,True,True,False,True)
arrResults = Rhino.PropertyListBox (arrItems, arrValues ,,”Volume Parameters”)
Dim scale, oculi

If CBool(arrResults(7)) = True Then
scale = arrImageSample(CInt(arrResults(0))*2+1, CInt(arrResults(1))*2+1)(6)
Else
scale = arrayValue(CInt(arrResults(0))*2+1, CInt(arrResults(1))*2+1,CDbl(arrResults(2)))
End If
If CBool(arrResults(8)) = True Then
oculi = arrImageSample(CInt(arrResults(0))*2, CInt(arrResults(1))*2)(6)
Else
oculi = arrayValue(CInt(arrResults(0))*2, CInt(arrResults(1))*2,CDbl(arrResults(3)))
End If

Dim tri, cut(2)
Call Rhino.EnableRedraw(False)
tri = TriangulateSurface(surf,CInt(arrResults(0))*2,CInt(arrResults(1))*2,CDbl(arrResults(2)),scale)
If CBool(arrResults(6)) = True Then
Call SurfaceMe(tri(0),oculi,CDbl(arrResults(3)),”surfaces_out”)
Call SurfaceMe(tri(1),oculi,CDbl(arrResults(3)),”surfaces_in”)
Call SurfaceMe(tri(2),oculi,CDbl(arrResults(3)),”surfaces_center”)
End If

If CBool(arrResults(5)) = True Then
cut(0) = UnfoldMe(tri(0),0,CDbl(arrResults(4)),oculi,CDbl(arrResults(3)),”A”)
cut(1) = UnfoldMe(tri(1),cut(0)+5,CDbl(arrResults(4)),oculi,CDbl(arrResults(3)),”B”)
cut(2) = UnfoldMe(tri(2),cut(1)+5,CDbl(arrResults(4)),oculi,CDbl(arrResults(3)),”C”)
End If

Call Rhino.EnableRedraw(True)

End Sub
Function TriangulateSurface(surface,cols,rows,offset,arrOffset)
TriangulateSurface = Null
Dim i,j
Dim uDom,vDom,uStep,vStep
uDom = Rhino.SurfaceDomain(surface,0)(1): uStep = uDom/cols
vDom = Rhino.SurfaceDomain(surface,1)(1): VStep = vDom/rows

ReDim uv(rows),pt(rows),ptA(rows),ptB(rows),uvSet(cols),ptSet(cols),ptSetA(cols),ptSetB(cols)
‘plot point grid
For i = 0 To cols Step 1
For j = 0 To rows Step 1
uv(j) = array(i*uStep,j*vStep)
ptB(j) = Rhino.EvaluateSurface(surface,uv(j))
If arrOffset(i)(j) 0.9 Then
If i Mod(2) Then
If j Mod(2) Then
srfA(j) = Rhino.AddSrfPt(array(ptSet(i)(j),ptSet(i)(j+1),ptSet(i+1)(j)))
srfB(j) = Rhino.AddSrfPt(array(ptSet(i+1)(j+1),ptSet(i)(j+1),ptSet(i+1)(j)))
Else
srfA(j) = Rhino.AddSrfPt(array(ptSet(i+1)(j),ptSet(i+1)(j+1),ptSet(i)(j)))
srfB(j) = Rhino.AddSrfPt(array(ptSet(i)(j+1),ptSet(i+1)(j+1),ptSet(i)(j)))
End If
Else
If j Mod(2) Then
srfA(j) = Rhino.AddSrfPt(array(ptSet(i+1)(j),ptSet(i+1)(j+1),ptSet(i)(j)))
srfB(j) = Rhino.AddSrfPt(array(ptSet(i)(j+1),ptSet(i+1)(j+1),ptSet(i)(j)))
Else
srfA(j) = Rhino.AddSrfPt(array(ptSet(i)(j),ptSet(i)(j+1),ptSet(i+1)(j)))
srfB(j) = Rhino.AddSrfPt(array(ptSet(i+1)(j+1),ptSet(i)(j+1),ptSet(i+1)(j)))
End If
End If
Call Rhino.ObjectLayer(srfA(j),objLayer)
Call Rhino.ObjectLayer(srfB(j),objLayer)
Else
If scale(i)(j) ptC(j-1)(1) Then
angX(j) = -Rhino.Angle2(array(ptB(j-1),Rhino.PointAdd(ptB(j-1),wrldCS(1))),array(ptB(j-1),ptC(j-1)))(0)
Else
angX(j) = Rhino.Angle2(array(ptB(j-1),Rhino.PointAdd(ptB(j-1),wrldCS(1))),array(ptB(j-1),ptC(j-1)))(0)
End If
End If
If i Mod(2) Then
r = j+1
Else
r = j
End If
If r Mod(2) Then
ptA(j) = Rhino.PointAdd(oriPt(j),Rhino.VectorScale(Rhino.VectorRotate(wrldCS(1),angX(j),wrldCS(3)),d(i)(0)(j)))
ptB(j) = Rhino.PointAdd(oriPt(j),Rhino.VectorScale(Rhino.VectorRotate(wrldCS(1),angX(j)+a(i)(1)(j)+a(i)(2)(j),wrldCS(3)),d(i)(2)(j)))
ptC(j) = Rhino.PointAdd(ptA(j),Rhino.VectorScale(Rhino.VectorRotate(wrldCS(1),angX(j)+180-a(i)(0)(j),wrldCS(3)),d(i)(1)(j)))
Else
ptA(j) = Rhino.PointAdd(oriPt(j),Rhino.VectorScale(Rhino.VectorRotate(wrldCS(1),angX(j),wrldCS(3)),d(i)(0)(j)))
ptB(j) = Rhino.PointAdd(oriPt(j),Rhino.VectorScale(Rhino.VectorRotate(wrldCS(1),angX(j)+a(i)(0)(j),wrldCS(3)),d(i)(1)(j)))
ptC(j) = Rhino.PointAdd(ptA(j),Rhino.VectorScale(Rhino.VectorRotate(wrldCS(1),angX(j)+180-a(i)(1)(j)-a(i)(2)(j),wrldCS(3)),d(i)(2)(j)))
End If
minX(j) = Rhino.Min(array(ptA(j)(0),ptB(j)(0),ptC(j)(0)))
maxX(j) = Rhino.Max(array(ptA(j)(0),ptB(j)(0),ptC(j)(0)))
r=r+1
Next
mn(i) = Rhino.Min(minX)
If mn(i) > 0 Then
mn(i) = 0
Else
mn(i) = abs(mn(i))
End If
mx(i) = abs(Rhino.Max(maxX))
pts(i) = array(oriPt,ptA,ptB,ptC)
Next
Dim ptX, k,u
Dim points(3),yVal(3),dblY
ReDim yMax(rows-1), yM(cols-1)
Dim edge(),edgeA(), edgeB(), span()
ReDim edge(cols-1),edgeA(rows-1), edgeB(rows-1), span(rows*2)
Dim cPt(1), oculi(1)
r=0
For i = 0 To cols-1 Step 1
k=0
If i > 0 Then
r = r+mx(i-1)+mn(i)+tabHeight*2
End If
For j = 0 To rows-1 Step 1
ptX = array(r,0,0)
For u = 0 To 3 Step 1
points(u) = Rhino.PointAdd(ptX,pts(i)(u)(j))
Next
If j Mod(2) Then
span(k) = Rhino.AddLine(points(0),points(3))
Call Rhino.ObjectLayer(span(k),”scores”)
k=k+1
Else
span(k) = Rhino.AddLine(points(1),points(2))
Call Rhino.ObjectLayer(span(k),”scores”)
k=k+1
End If
If j = 0 Then
span(k) = Rhino.AddLine(points(0),points(1))
Call Rhino.ObjectLayer(span(k),”cuts”)
k=k+1
End If
If j = rows-1 Then
span(k) = Rhino.AddLine(points(2),points(3))
Call Rhino.ObjectLayer(span(k),”cuts”)
k=k+1
Else
span(k) = Rhino.AddLine(points(2),points(3))
Call Rhino.ObjectLayer(span(k),”scores”)
k=k+1
End If

If scale(i)(j) <= .9 Then
If scale(i)(j) w Then
x = w
End If

If y>h Then
y = h
End If

r(j) = RhPicture.Red(x,y)/255
g(j) = RhPicture.Green(x,y)/255
b(j) = RhPicture.Blue(x,y)/255
a(j) = RhPicture.Alpha(x,y)/255
hu(j) = RhPicture.Hue(x,y)/360
s(j) = RhPicture.Saturation(x,y)
u(j) = RhPicture.Luminance(x,y)

Next
rValSet(i) = r
gValSet(i) = g
bValSet(i) = b
aValSet(i) = a
hValSet(i) = hu
sValSet(i) = s
uValSet(i) = u
Next
Set RhPicture = Nothing
‘ image outputs (0)red(1)green(2)blue(3)alpha(4)hue(5)saturation(6)luminance
arrImageSample = array(rValSet,gValSet,bValSet,aValSet,hValSet,sValSet,uValSet)
End Function
Function arrayValue(cols,rows,value)
arrayValue = Null
Dim i,j
ReDim val(rows), arrVal(cols)
For i = 0 To cols Step 1
For j = 0 To rows Step 1
val(j) = value
Next
arrVal(i) = val
Next
arrayValue = arrVal
End Function

Advertisements

There are no comments on this post.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: