|
|
/*
There are actually two systems here for getting the triangle meshes, but
the one called Rag I've temporarily abandoned for now.
The Pary array is more expensive in terms of memory than Rag would be, but
Rag would require more complex programming and an ability to resize an
array after it's loaded. (Either that or you count the holes in your mask
and find the maximum number on a "scan" line.)
It's called Rag because it should be a "ragged array" if this were C.
Pary works by loading an array that's the same size as the scaled picture,
in fact, Pary use to be the picture array. However, since we are using a
mask to cut portions off the picture and the mesh we need is a smaller
less orderly array, and that's Mary, which stores the <x,y,z> location of
every vertice. Pary holds an index into Mary's data plus a flag, -1000, to
tell us when a pixel has been cut out. If its a vertice, it's positive, if
a hole, negative.
-- Norman Doering
---------------------------------
*/
#version 3.5;
global_settings {assumed_gamma 1.0}
// ----------------------------------------
camera
{ location <0.0, 0, -100.0>
look_at <0.0, 0.0, 0.0>
angle 28
}
background {rgb <0.02,0.02,0.1>}
// ----------------------------------------
#declare Rag = array[9][18]; // store compressed info
#declare Pary = array[9][18]; // represents the photo with mask on it using
flags
#declare Mask = array[9][18] // represents the mask
{ {0,0,0,0,1,1,1,0,0,1,1,1,0,0,0,0,0,0} //0
{0,0,1,1,1,1,1,0,0,0,1,0,0,0,0,0,0,0} //1
{0,0,0,1,1,1,1,1,0,0,0,0,1,1,1,1,0,0} //2
{0,0,0,0,1,1,1,0,0,0,0,1,1,1,1,0,0,0} //3
{0,0,0,1,1,1,1,0,0,0,1,1,1,1,1,1,1,1} //4
{0,0,0,0,1,1,1,0,0,1,1,1,1,1,1,0,0,0} //5
{0,0,0,0,1,1,1,0,0,0,1,1,1,1,0,0,0,0} //6
{0,0,0,0,0,1,1,1,1,1,1,1,1,0,0,0,0,0} //7
{0,0,0,0,1,1,1,1,1,1,1,1,0,0,0,0,0,0} //8
}
#declare Mary = array[200]; // represents actual vertice array to
// load into a mesh2
#declare triang = array[200]; // represents facet making data for mesh2
#declare Resx = 18;
#declare Resy = 9;
#declare RagMark = 0; // this loop sets up two experiments for getting
triangles
#declare Rcnt = 0;
#declare totalV = 0;
#declare ycnt = 0;
#while (ycnt < Resy)
#declare xcnt = 0;
#declare Rcnt = 0;
#while (xcnt < Resx)
#if(Mask[ycnt][xcnt] > 0)
#if (RagMark != 1)
#declare Rag[ycnt][Rcnt]=totalV;
#declare Rcnt = Rcnt+1;
#declare RagMark = 1;
#end
#declare Mary[totalV] = <xcnt*2,ycnt*2,0>; // 0 will be z
#declare Pary[ycnt][xcnt] = totalV; // questionable method
#declare totalV = totalV+1;
#else
#declare Pary[ycnt][xcnt] = -1000;
#if (RagMark = 1)
#declare Rag[ycnt][Rcnt]=totalV-1;
#declare Rcnt = Rcnt+1;
#end
#declare RagMark = -10;
#end
#declare xcnt = xcnt+1;
#end
#if(Rcnt < Resx)
#while (Rcnt < Resx)
#declare Rag[ycnt][Rcnt] = -1;
#declare Rcnt = Rcnt+1;
#end
#end
#declare ycnt = ycnt+1;
#end
#declare checkMary = union
{
#declare cnt = 0;
#while (cnt < totalV)
sphere
{ <Mary[cnt].x, Mary[cnt].y-0.3, -0.3> 0.3
texture { pigment { rgb <0,1,1> } }
finish{ambient 0.7}
}
#declare cnt = cnt+1;
#end
}
object {checkMary translate <-12, -8, 0>}
#declare usePary = union // to be part of macro, without cylinders
{
#declare totalF = 0;
#declare ycnt = 1;
#while (ycnt < Resy) //A
#declare xcnt = 0;
#while (xcnt < Resx) //B
#if(xcnt < (Resx-1)) // C
#if(Pary[ycnt][xcnt] > -10 & Pary[ycnt-1][xcnt] > -10
& Pary[ycnt-1][xcnt+1] > -10
) // D // <y,x><y-,x><y-,x+>
#declare triang[totalF] =
< Pary[ycnt][xcnt], Pary[ycnt-1][xcnt], Pary[ycnt-1][xcnt+1] >;
// <y,x> <y-,x> <y-,x+> is a triangle with
// right angle on upper right
#declare totalF = totalF+1;
#end // D
#if( Pary[ycnt][xcnt] > -10 & Pary[ycnt][xcnt+1] > -10 &
Pary[ycnt-1][xcnt+1] > -10
) // E
#declare triang[totalF] =
< Pary[ycnt][xcnt], Pary[ycnt][xcnt+1], Pary[ycnt-1][xcnt+1] >;
// <y,x> <y,x+> <y-,x+> is a triangle with
// right angle on lower left
#declare totalF = totalF+1;
#end // E
//----- These two triangles use another diagonal -----:
#if( Pary[ycnt][xcnt] > -10 & Pary[ycnt][xcnt+1] > -10 &
Pary[ycnt-1][xcnt+1] < -10 & Pary[ycnt-1][xcnt] > -10
) // E
#declare triang[totalF] =
< Pary[ycnt][xcnt], Pary[ycnt][xcnt+1], Pary[ycnt-1][xcnt] >;
#declare totalF = totalF+1;
#end // E
// ---
#if( Pary[ycnt][xcnt] < -10 & Pary[ycnt][xcnt+1] > -10 &
Pary[ycnt-1][xcnt+1] > -10 & Pary[ycnt-1][xcnt] > -10
) // E
#declare triang[totalF] =
< Pary[ycnt-1][xcnt+1], Pary[ycnt][xcnt+1], Pary[ycnt-1][xcnt]
>;
#declare totalF = totalF+1;
#end // E
// ---
#end // C
#declare xcnt = xcnt+1;
#end // B
#declare ycnt = ycnt+1;
#end // A
// ---- check the data ----
#declare cnt = 0;
#while (cnt < totalF)
cylinder
{ Mary[triang[cnt].x], Mary[triang[cnt].y], 0.14
pigment {rgbft <1,1,0,0.46,0.34>} finish {ambient 0.7}
}
cylinder
{ Mary[triang[cnt].x], Mary[triang[cnt].z], 0.14
pigment {rgbft <1,0,1,0.46,0.34>} finish {ambient 0.7}
}
cylinder
{ Mary[triang[cnt].y], Mary[triang[cnt].z], 0.14
pigment {rgbft <0,1,1,0.46,0.34>} finish {ambient 0.7}
}
#declare cnt = cnt+1;
#end
}
object { usePary translate <-12, -8, 0> }
//-------------------------
#declare checkRag = union
{
#declare ycnt = 0;
#while (ycnt < Resy)
#declare xcnt = 0;
#while (xcnt < Resx)
#if(Rag[ycnt][xcnt] > -1)
sphere
{ <Mary[Rag[ycnt][xcnt]].x, Mary[Rag[ycnt][xcnt]].y+0.3, -0.3> 0.3
texture { pigment { rgb <1,1,1> } }
finish{ambient 0.7}
}
#end
#declare xcnt = xcnt+1;
#end
#declare ycnt = ycnt+1;
#end
}
//object {checkRag translate <-12, -8, 0>}
#declare ragcontent = union
{
#declare ycnt = 0;
#while (ycnt < Resy)
#declare xcnt = 0;
#while (xcnt < Resx)
text
{ ttf "timrom.ttf"
concat(" ",str(Rag[ycnt][xcnt], 0,0)),0.4,0.1 translate
<xcnt*2.2,ycnt*2.4,0>
}
#declare xcnt = xcnt+1;
#end
#declare ycnt = ycnt+1;
#end
}
/*
object
{ ragcontent
scale 1.5
translate <-20, -16, 0>
pigment{ rgb <1,1,0> } finish {ambient 1}
}
*/
/*
Uncomment above ragcontent object to see the kind of information Rag would
contain. It represents an index into Mary that uses number pairs to
represent
long rows of vertices. This system was not used but it could possibly
replace
the Pary array with something much smaller yet having essentially the same
information. Perhaps even the beginning of a mesh3 system where every facet
doesn't have to be declared but only the beginning and end points of rows of
vertices and an internal code system that knows how to make the facets.
*/
--normdoering
Post a reply to this message
|
|