(* Content-type: application/mathematica *)
(*** Wolfram Notebook File ***)
(* http://www.wolfram.com/nb *)
(* CreatedBy='Mathematica 7.0' *)
(*CacheID: 234*)
(* Internal cache information:
NotebookFileLineBreakTest
NotebookFileLineBreakTest
NotebookDataPosition[ 145, 7]
NotebookDataLength[ 18281, 516]
NotebookOptionsPosition[ 17951, 501]
NotebookOutlinePosition[ 18290, 516]
CellTagsIndexPosition[ 18247, 513]
WindowFrame->Normal*)
(* Beginning of Notebook Content *)
Notebook[{
Cell[BoxData[{
RowBox[{
RowBox[{
RowBox[{"polyg", "=",
RowBox[{"{",
RowBox[{
RowBox[{"{",
RowBox[{"160", ",", "230"}], "}"}], ",",
RowBox[{"{",
RowBox[{"140", ",", "220"}], "}"}], ",",
RowBox[{"{",
RowBox[{"113", ",", "210"}], "}"}], ",",
RowBox[{"{",
RowBox[{"100", ",", "220"}], "}"}], ",",
RowBox[{"{",
RowBox[{"30", ",", "150"}], "}"}], ",",
RowBox[{"{",
RowBox[{"25", ",", "70"}], "}"}], ",",
RowBox[{"{",
RowBox[{"65", ",", "30"}], "}"}], ",",
RowBox[{"{",
RowBox[{"170", ",", "25"}], "}"}], ",",
RowBox[{"{",
RowBox[{"200", ",", "37"}], "}"}], ",",
RowBox[{"{",
RowBox[{"240", ",", "70"}], "}"}], ",",
RowBox[{"{",
RowBox[{"250", ",", "90"}], "}"}], ",",
RowBox[{"{",
RowBox[{"250", ",", "185"}], "}"}], ",",
RowBox[{"{",
RowBox[{"190", ",", "230"}], "}"}]}], "}"}]}], ";"}],
"\[IndentingNewLine]"}], "\[IndentingNewLine]",
RowBox[{
RowBox[{
RowBox[{"gridelements", "=",
RowBox[{"{",
RowBox[{
RowBox[{"{",
RowBox[{
RowBox[{"Graphics", "[", "]"}], ",",
RowBox[{"Graphics", "[", "]"}]}], "}"}], ",",
RowBox[{"{",
RowBox[{
RowBox[{"Graphics", "[", "]"}], ",",
RowBox[{"Graphics", "[", "]"}]}], "}"}]}], "}"}]}], ";"}],
"\[IndentingNewLine]"}], "\[IndentingNewLine]",
RowBox[{
RowBox[{
RowBox[{
RowBox[{"conv", "[",
RowBox[{"im_", ",", "co_", ",", "li_", ",", "tv_"}], "]"}], ":=",
RowBox[{"Module", "[",
RowBox[{
RowBox[{"{",
RowBox[{
RowBox[{"image", "=", "im"}], ",",
RowBox[{"cutoff", "=", "co"}], ",",
RowBox[{"limit", "=", "li"}], ",",
RowBox[{"testvar", "=", "tv"}], ",", "a1", ",", "agr", ",", "d", ",",
"i", ",", "mtx", ",", "za"}], "}"}], ",",
RowBox[{
RowBox[{"eln", "=",
RowBox[{"StringDrop", "[",
RowBox[{"image", ",",
RowBox[{"-", "4"}]}], "]"}]}], ";",
RowBox[{"mtx", "=",
RowBox[{"Import", "[",
RowBox[{"image", ",", "\"\
\""}], "]"}]}], ";",
"\[IndentingNewLine]",
RowBox[{"d", "=",
RowBox[{"{", "}"}]}], ";",
RowBox[{"For", "[",
RowBox[{
RowBox[{"i", "=", "1"}], ",",
RowBox[{"i", "\[LessEqual]", "39"}], ",",
RowBox[{
RowBox[{"d", "=",
RowBox[{"Insert", "[",
RowBox[{"d", ",",
RowBox[{"{", "i", "}"}], ",",
RowBox[{"-", "1"}]}], "]"}]}], ";",
RowBox[{"i", "++"}]}]}], "]"}], ";", "\[IndentingNewLine]",
RowBox[{"a1", "=",
RowBox[{"Delete", "[",
RowBox[{"mtx", ",", "d"}], "]"}]}], ";",
RowBox[{"mtx", "=",
RowBox[{"Transpose", "[", "a1", "]"}]}], ";", "\[IndentingNewLine]",
RowBox[{"If", "[",
RowBox[{
RowBox[{"cutoff", "\[Equal]", "True"}], ",",
RowBox[{
RowBox[{"za", "=",
RowBox[{"ReplacePart", "[",
RowBox[{"mtx", ",", "0", ",",
RowBox[{"Position", "[",
RowBox[{"mtx", ",",
RowBox[{"_", "?",
RowBox[{"(",
RowBox[{
RowBox[{"#1", ">", "limit"}], "&"}], ")"}]}]}], "]"}]}],
"]"}]}], ";",
RowBox[{"mtx", "=", "za"}]}]}], "]"}], ";", "\[IndentingNewLine]",
RowBox[{"If", "[",
RowBox[{
RowBox[{"testvar", "\[Equal]", "1"}], ",",
RowBox[{"a", "=", "mtx"}], ",",
RowBox[{"b", "=", "mtx"}]}], "]"}], ";", "\[IndentingNewLine]",
RowBox[{"If", "[",
RowBox[{
RowBox[{"testvar", "\[Equal]", "1"}], ",",
RowBox[{"el1", "=", "eln"}], ",",
RowBox[{"el2", "=", "eln"}]}], "]"}], ";", "\[IndentingNewLine]",
RowBox[{"elmap", "=",
RowBox[{"ListDensityPlot", "[",
RowBox[{"mtx", ",",
RowBox[{"ImageSize", "\[Rule]",
RowBox[{"{",
RowBox[{"400", ",", "400"}], "}"}]}], ",",
RowBox[{"BaseStyle", "\[Rule]",
RowBox[{"{",
RowBox[{
RowBox[{"FontFamily", "\[Rule]", "\"\\""}], ",",
RowBox[{"FontSize", "\[Rule]", "18"}]}], "}"}]}], ",",
RowBox[{"Mesh", "\[Rule]", "False"}], ",",
RowBox[{"FrameLabel", "\[Rule]",
RowBox[{"{",
RowBox[{"\"\\"", ",", "\"\\""}], "}"}]}], ",",
RowBox[{"Epilog", "\[Rule]",
RowBox[{"{",
RowBox[{
RowBox[{"Rectangle", "[",
RowBox[{
RowBox[{"{",
RowBox[{"165", ",", "230"}], "}"}], ",",
RowBox[{"{",
RowBox[{"254", ",", "256"}], "}"}]}], "]"}], ",",
RowBox[{"Text", "[",
RowBox[{
RowBox[{"Style", "[",
RowBox[{"eln", ",", "White"}], "]"}], ",",
RowBox[{"{",
RowBox[{"210", ",", "240"}], "}"}]}], "]"}]}], "}"}]}], ",",
RowBox[{"DisplayFunction", "\[Rule]", "Identity"}], ",",
RowBox[{"ColorFunction", "\[Rule]", "GrayLevel"}]}], "]"}]}], ";",
"\[IndentingNewLine]",
RowBox[{"If", "[",
RowBox[{
RowBox[{"testvar", "\[Equal]", "1"}], ",",
RowBox[{"elmap1", "=", "elmap"}], ",",
RowBox[{"elmap2", "=", "elmap"}]}], "]"}]}]}], "]"}]}], ";"}],
"\[IndentingNewLine]", "\[IndentingNewLine]"}], "\[IndentingNewLine]",
RowBox[{
RowBox[{
RowBox[{
RowBox[{"PLSPolygon", "[",
RowBox[{
RowBox[{"poly", ":",
RowBox[{"{",
RowBox[{
RowBox[{"{",
RowBox[{"_", ",", "_"}], "}"}], ".."}], "}"}]}], ",",
RowBox[{"q", ":",
RowBox[{"{",
RowBox[{"x_", ",", "y_"}], "}"}]}]}], "]"}], "/;",
RowBox[{
RowBox[{"Length", "[", "poly", "]"}], "\[GreaterEqual]", "3"}]}], ":=",
RowBox[{"Module", "[",
RowBox[{
RowBox[{"{",
RowBox[{
RowBox[{"edges", "=",
RowBox[{
RowBox[{"(",
RowBox[{
RowBox[{"Partition", "[",
RowBox[{"#1", ",", "2", ",", "1"}], "]"}], "&"}], ")"}], "[",
RowBox[{"Append", "[",
RowBox[{"poly", ",",
RowBox[{"First", "[", "poly", "]"}]}], "]"}], "]"}]}], ",",
"temp"}], "}"}], ",",
RowBox[{
RowBox[{"temp", "=",
RowBox[{"DeleteCases", "[",
RowBox[{"edges", ",",
RowBox[{"{",
RowBox[{
RowBox[{"{",
RowBox[{"x1_", ",", "yy_"}], "}"}], ",",
RowBox[{"{",
RowBox[{"x2_", ",", "yy"}], "}"}]}], "}"}]}], "]"}]}], ";",
RowBox[{"temp", "=",
RowBox[{"DeleteCases", "[",
RowBox[{"temp", ",",
RowBox[{
RowBox[{"{",
RowBox[{
RowBox[{"{",
RowBox[{"x1_", ",", "y1_"}], "}"}], ",",
RowBox[{"{",
RowBox[{"x2_", ",", "y2_"}], "}"}]}], "}"}], "/;",
RowBox[{
RowBox[{
RowBox[{"Min", "[",
RowBox[{"y1", ",", "y2"}], "]"}], "\[GreaterEqual]", "y"}], "||",
RowBox[{
RowBox[{"Max", "[",
RowBox[{"y1", ",", "y2"}], "]"}], "<", "y"}]}]}]}], "]"}]}], ";",
RowBox[{"temp", "=",
RowBox[{
RowBox[{"(",
RowBox[{
RowBox[{"If", "[",
RowBox[{
RowBox[{
RowBox[{"#1", "\[LeftDoubleBracket]",
RowBox[{"1", ",", "2"}], "\[RightDoubleBracket]"}], ">",
RowBox[{"#1", "\[LeftDoubleBracket]",
RowBox[{"2", ",", "2"}], "\[RightDoubleBracket]"}]}], ",", "#1",
",",
RowBox[{"Reverse", "[", "#1", "]"}]}], "]"}], "&"}], ")"}], "/@",
"temp"}]}], ";",
RowBox[{"If", "[",
RowBox[{
RowBox[{"OddQ", "[",
RowBox[{"Count", "[",
RowBox[{"temp", ",",
RowBox[{"e_", "/;",
RowBox[{
RowBox[{"darea", "[",
RowBox[{"Append", "[",
RowBox[{"e", ",", "q"}], "]"}], "]"}], ">", "0"}]}]}], "]"}],
"]"}], ",", "True", ",", "False"}], "]"}]}]}], "]"}]}],
";"}], "\[IndentingNewLine]",
RowBox[{
RowBox[{
RowBox[{
RowBox[{"darea", "[",
RowBox[{"triangle", ":",
RowBox[{"{",
RowBox[{"p1_", ",", "p2_", ",", "p3_"}], "}"}]}], "]"}], ":=",
RowBox[{"Det", "[",
RowBox[{
RowBox[{"(",
RowBox[{
RowBox[{"Append", "[",
RowBox[{"#1", ",", "1"}], "]"}], "&"}], ")"}], "/@", "triangle"}],
"]"}]}], ";"}], "\[IndentingNewLine]"}], "\[IndentingNewLine]",
RowBox[{
RowBox[{
RowBox[{"cutout", "[", "pol_", "]"}], ":=",
RowBox[{"Module", "[",
RowBox[{
RowBox[{"{",
RowBox[{"polyno", "=", "pol"}], "}"}], ",", "\[IndentingNewLine]",
RowBox[{"a", ";", "\[IndentingNewLine]",
RowBox[{"is", "=",
RowBox[{"Dimensions", "[", "a", "]"}]}], ";",
RowBox[{"imagepixelsX", "=",
RowBox[{"is", "\[LeftDoubleBracket]", "2", "\[RightDoubleBracket]"}]}],
";",
RowBox[{"imagepixelsY", "=",
RowBox[{"is", "\[LeftDoubleBracket]", "1", "\[RightDoubleBracket]"}]}],
";", "\[IndentingNewLine]", "\[IndentingNewLine]",
"\[IndentingNewLine]",
RowBox[{"(*",
RowBox[{"--",
RowBox[{"--",
RowBox[{"--",
RowBox[{"--",
RowBox[{"--",
RowBox[{"--",
RowBox[{"--",
RowBox[{"--",
RowBox[{"--",
RowBox[{"--",
RowBox[{"--",
RowBox[{"--",
RowBox[{"--",
RowBox[{"--",
RowBox[{"--",
RowBox[{"--",
RowBox[{"--",
RowBox[{"--",
RowBox[{"--",
RowBox[{"--",
RowBox[{"--",
RowBox[{"--",
RowBox[{"--",
RowBox[{"--",
RowBox[{"--",
RowBox[{"--",
RowBox[{"--",
RowBox[{"--",
RowBox[{"--",
RowBox[{"--",
RowBox[{"--",
RowBox[{"--",
RowBox[{"--",
RowBox[{"--",
RowBox[{"--",
RowBox[{"--",
RowBox[{"--",
RowBox[{"--",
RowBox[{"--",
RowBox[{"--",
RowBox[{"--",
RowBox[{"--",
RowBox[{"--",
RowBox[{"--",
RowBox[{"--",
RowBox[{"--",
RowBox[{"--",
RowBox[{"--",
RowBox[{"--",
RowBox[{"--",
RowBox[{"--",
RowBox[{"--",
RowBox[{"--",
RowBox[{"--",
RowBox[{"--",
RowBox[{"--",
RowBox[{"--",
RowBox[{"--",
RowBox[{"--",
RowBox[{"--",
RowBox[{"--",
RowBox[{"--",
RowBox[{"--",
RowBox[{"--",
RowBox[{
"--", "--"}]}]}]}]}]}]}]}]}]}]}]}]}]}]}]}]}]}]}]}]}]}]}]}]\
}]}]}]}]}]}]}]}]}]}]}]}]}]}]}]}]}]}]}]}]}]}]}]}]}]}]}]}]}]}]}]}]}]}]}]}]}]}]}]\
}]}], "*)"}], "\[IndentingNewLine]",
RowBox[{"For", "[",
RowBox[{
RowBox[{"j", "=", "1"}], ",",
RowBox[{"j", "\[LessEqual]", "imagepixelsY"}], ",",
RowBox[{
RowBox[{"For", "[",
RowBox[{
RowBox[{"i", "=", "1"}], ",",
RowBox[{"i", "\[LessEqual]", "imagepixelsX"}], ",",
RowBox[{
RowBox[{"If", "[",
RowBox[{
RowBox[{
RowBox[{"PLSPolygon", "[",
RowBox[{"polyno", ",",
RowBox[{"{",
RowBox[{"i", ",", "j"}], "}"}]}], "]"}], "\[Equal]",
"False"}], ",",
RowBox[{"a", "=",
RowBox[{"ReplacePart", "[",
RowBox[{"a", ",", "0", ",",
RowBox[{"{",
RowBox[{"j", ",", "i"}], "}"}]}], "]"}]}]}], "]"}], ";",
RowBox[{"i", "++"}]}]}], "]"}], ";",
RowBox[{"j", "++"}]}]}], "]"}], ";", "\[IndentingNewLine]",
RowBox[{"(*",
RowBox[{"--",
RowBox[{"--",
RowBox[{"--",
RowBox[{"--",
RowBox[{"--",
RowBox[{"--",
RowBox[{"--",
RowBox[{"--",
RowBox[{"--",
RowBox[{"--",
RowBox[{"--",
RowBox[{"--",
RowBox[{"--",
RowBox[{"--",
RowBox[{"--",
RowBox[{"--",
RowBox[{"--",
RowBox[{"--",
RowBox[{"--",
RowBox[{"--",
RowBox[{"--",
RowBox[{"--",
RowBox[{"--",
RowBox[{"--",
RowBox[{"--",
RowBox[{"--",
RowBox[{"--",
RowBox[{"--",
RowBox[{"--",
RowBox[{"--",
RowBox[{"--",
RowBox[{"--",
RowBox[{"--",
RowBox[{"--",
RowBox[{"--",
RowBox[{"--",
RowBox[{"--",
RowBox[{"--",
RowBox[{"--",
RowBox[{"--",
RowBox[{"--",
RowBox[{"--",
RowBox[{"--",
RowBox[{"--",
RowBox[{"--",
RowBox[{"--",
RowBox[{"--",
RowBox[{"--",
RowBox[{"--",
RowBox[{"--",
RowBox[{"--",
RowBox[{"--",
RowBox[{"--",
RowBox[{"--",
RowBox[{"--",
RowBox[{"--",
RowBox[{"--",
RowBox[{"--",
RowBox[{"--",
RowBox[{"--",
RowBox[{"--",
RowBox[{"--",
RowBox[{"--",
RowBox[{"--",
RowBox[{"--",
"--"}]}]}]}]}]}]}]}]}]}]}]}]}]}]}]}]}]}]}]}]}]}]}]}]}]}]}]\
}]}]}]}]}]}]}]}]}]}]}]}]}]}]}]}]}]}]}]}]}]}]}]}]}]}]}]}]}]}]}]}]}]}]}]}]}]}],
"*)"}], "\[IndentingNewLine]", "\[IndentingNewLine]",
"\[IndentingNewLine]",
RowBox[{"cutoutimg", "=",
RowBox[{"ListDensityPlot", "[",
RowBox[{"a", ",",
RowBox[{"ImageSize", "\[Rule]",
RowBox[{"{",
RowBox[{"400", ",", "400"}], "}"}]}], ",",
RowBox[{"BaseStyle", "\[Rule]",
RowBox[{"{",
RowBox[{
RowBox[{"FontFamily", "\[Rule]", "\"\\""}], ",",
RowBox[{"FontSize", "\[Rule]", "18"}]}], "}"}]}], ",",
RowBox[{"Mesh", "\[Rule]", "False"}], ",",
RowBox[{"FrameLabel", "\[Rule]",
RowBox[{"{",
RowBox[{"\"\\"", ",", "\"\\""}], "}"}]}], ",",
RowBox[{"Epilog", "\[Rule]",
RowBox[{"{",
RowBox[{
RowBox[{"Rectangle", "[",
RowBox[{
RowBox[{"{",
RowBox[{"165", ",", "230"}], "}"}], ",",
RowBox[{"{",
RowBox[{"254", ",", "256"}], "}"}]}], "]"}], ",",
RowBox[{"Text", "[",
RowBox[{
RowBox[{"Style", "[",
RowBox[{"el1", ",", "White"}], "]"}], ",",
RowBox[{"{",
RowBox[{"210", ",", "240"}], "}"}]}], "]"}]}], "}"}]}], ",",
RowBox[{"DisplayFunction", "\[Rule]", "Identity"}], ",",
RowBox[{"ColorFunction", "\[Rule]", "GrayLevel"}]}], "]"}]}]}]}],
"]"}]}], ";"}]}], "Input",
CellChangeTimes->{{3.475492928728071*^9, 3.475492982169709*^9}}],
Cell[BoxData[
RowBox[{"\[IndentingNewLine]",
RowBox[{
RowBox[{
RowBox[{"conv", "[",
RowBox[{"\"\\"", ",", "cutoffa", ",", "limita", ",", "1"}],
"]"}], ";"}], "\[IndentingNewLine]", "elmap1",
"\[IndentingNewLine]"}]}]], "Input",
CellChangeTimes->{{3.475492971411612*^9, 3.475492976649432*^9}}],
Cell[BoxData[{
RowBox[{
RowBox[{"cutout", "[", "polyg", "]"}],
";"}], "\[IndentingNewLine]", "cutoutimg", "\[IndentingNewLine]"}], "Input",\
CellChangeTimes->{{3.475492972347517*^9, 3.4754929866010017`*^9}}]
},
WindowSize->{1635, 775},
WindowMargins->{{4, Automatic}, {Automatic, 0}},
FrontEndVersion->"7.0 for Mac OS X x86 (32-bit) (February 18, 2009)",
StyleDefinitions->"Default.nb"
]
(* End of Notebook Content *)
(* Internal cache information *)
(*CellTagsOutline
CellTagsIndex->{}
*)
(*CellTagsIndex
CellTagsIndex->{}
*)
(*NotebookFileOutline
Notebook[{
Cell[545, 20, 16852, 462, 478, "Input"],
Cell[17400, 484, 329, 8, 73, "Input"],
Cell[17732, 494, 215, 5, 58, "Input"]
}
]
*)
(* End of internal cache information *)