<s>
In	O
computer	O
graphics	O
,	O
marching	B-Algorithm
squares	I-Algorithm
is	O
an	O
algorithm	O
that	O
generates	O
contours	O
for	O
a	O
two-dimensional	O
scalar	O
field	O
(	O
rectangular	O
array	B-Data_Structure
of	O
individual	O
numerical	O
values	O
)	O
.	O
</s>
<s>
A	O
similar	O
method	O
can	O
be	O
used	O
to	O
contour	O
2D	O
triangle	B-Algorithm
meshes	I-Algorithm
.	O
</s>
<s>
Isobands	B-Algorithm
–	O
filled	O
areas	O
between	O
isolines	O
.	O
</s>
<s>
Marching	B-Algorithm
squares	I-Algorithm
takes	O
a	O
similar	O
approach	O
to	O
the	O
3D	O
marching	B-Algorithm
cubes	I-Algorithm
algorithm	I-Algorithm
:	O
</s>
<s>
Use	O
a	O
pre-built	O
lookup	B-Data_Structure
table	I-Data_Structure
,	O
keyed	O
on	O
the	O
cell	O
index	O
,	O
to	O
describe	O
the	O
output	O
geometry	O
for	O
the	O
cell	O
.	O
</s>
<s>
Use	O
the	O
cell	O
index	O
to	O
access	O
a	O
pre-built	O
lookup	B-Data_Structure
table	I-Data_Structure
with	O
16	O
entries	O
listing	O
the	O
edges	O
needed	O
to	O
represent	O
the	O
cell	O
(	O
shown	O
in	O
the	O
lower	O
right	O
part	O
of	O
the	O
picture	O
below	O
)	O
.	O
</s>
<s>
The	O
same	O
basic	O
algorithm	O
can	O
be	O
applied	O
to	O
triangular	B-Algorithm
meshes	I-Algorithm
,	O
which	O
consist	O
of	O
connected	O
triangles	O
with	O
data	O
assigned	O
to	O
the	O
vertices	O
.	O
</s>
<s>
For	O
example	O
,	O
a	O
scattered	O
set	O
of	O
data	O
points	O
could	O
be	O
connected	O
with	O
a	O
Delaunay	B-Algorithm
triangulation	I-Algorithm
to	O
allow	O
the	O
data	O
field	O
to	O
be	O
contoured	O
.	O
</s>
<s>
The	O
analysis	O
for	O
isobands	B-Algorithm
over	O
triangles	O
requires	O
3	O
ternary	O
trits	O
,	O
so	O
there	O
are	O
27	O
possibilities	O
:	O
</s>
<s>
The	O
data	O
space	O
for	O
the	O
Marching	B-Algorithm
Squares	I-Algorithm
algorithm	I-Algorithm
is	O
2D	O
,	O
because	O
the	O
vertices	O
assigned	O
a	O
data	O
value	O
are	O
connected	O
to	O
their	O
neighbors	O
in	O
a	O
2D	O
topological	B-Architecture
grid	O
,	O
but	O
the	O
spatial	O
coordinates	O
assigned	O
to	O
the	O
vertices	O
can	O
be	O
in	O
2D	O
,	O
3D	O
or	O
higher	O
dimensions	O
.	O
</s>
<s>
The	O
algorithm	O
is	O
embarrassingly	B-Operating_System
parallel	I-Operating_System
,	O
because	O
all	O
cells	O
are	O
processed	O
independently	O
.	O
</s>
<s>
It	O
is	O
easy	O
to	O
write	O
a	O
parallel	B-Operating_System
algorithm	I-Operating_System
assuming	O
:	O
</s>
<s>
A	O
naive	O
implementation	O
of	O
Marching	B-Algorithm
Squares	I-Algorithm
that	O
processes	O
every	O
cell	O
independently	O
will	O
perform	O
every	O
linear	O
interpolation	O
twice	O
(	O
isoline	O
)	O
or	O
four	O
times	O
(	O
isoband	O
)	O
.	O
</s>
<s>
Similarly	O
,	O
the	O
output	O
will	O
contain	O
2	O
copies	O
of	O
the	O
2D	O
vertices	O
for	O
disjoint	O
lines	O
(	O
isoline	O
)	O
or	O
4	O
copies	O
for	O
polygons	O
(	O
isobands	B-Algorithm
)	O
.	O
</s>
<s>
[	O
Under	O
the	O
assumptions	O
that	O
:	O
the	O
grid	O
is	O
large	O
,	O
so	O
that	O
most	O
cells	O
are	O
internal	O
;	O
and	O
a	O
full	O
contiguous	O
set	O
of	O
isobands	B-Algorithm
is	O
being	O
created.	O
]	O
</s>
<s>
It	O
is	O
possible	O
to	O
reduce	O
the	O
computational	O
overhead	O
by	O
caching	B-General_Concept
the	O
results	O
of	O
interpolation	O
.	O
</s>
<s>
For	O
example	O
,	O
a	O
single-threaded	O
serial	O
version	O
would	O
only	O
need	O
to	O
cache	B-General_Concept
interpolated	O
results	O
for	O
one	O
row	O
of	O
the	O
input	O
grid	O
.	O
</s>
<s>
create	O
an	O
array	B-Data_Structure
of	O
2D	O
vertices	O
and	O
specify	O
lines	O
or	O
polygons	O
with	O
short	O
integer	O
offsets	O
into	O
the	O
array	B-Data_Structure
.	O
</s>
