I am working on a code for a colleague where I am trying to compute the Bond Orientational Order for a cluster of particles. To make life easier for processing a large number of images I wish to implement a GUI (although it is not easy in Mathematica).
I have failed to understand why for the code below, CreateDocument fails to create a new notebook if the ExpressionCell has RegionMember/@poly as argument. I can create the document when the expression is ExpressionCell[poly]and the cell displays the list of polygons. It seems like RegionMember/@poly does not evaluate whereas poly does.
Note:
There is no minimal example that I can post here for the purpose of the code I am dealing with. My actual code for packagedFunction goes a bit beyond to generate the final results but I am posting it till the point where the problem originates.
for imgs kindly use the image:
Code
CreatePalette[
DynamicModule[{segmentImage, showFunc, deleteFalsePts, addPts,
packagedFunction, img = imgs[[1]], ovimg, data},
Grid[{
{Button["create Voronoi", packagedFunction[data]]} ,
{Button["particle centroids", CreateDocument[{
TextCell["Coordinate List", "Title"],
TextCell[
Row[{"Report generated @ ", DateString[], "\n",
"Particles #: ", Length@data}], "Text"],
ExpressionCell[data, "Output"]
}]
]} ,
{Pane[
Dynamic@If[Head[img] === Image,
LocatorPane[
Dynamic@data, ovimg, LocatorAutoCreate -> All,
Appearance -> Style["*", 20, Red]]
]
]
}
}],
Initialization :> (
segmentImage[img_, circ_: 0.95, thresh_: {10, 50}] :=
SelectComponents[
ColorNegate@
DeleteSmallComponents@
MorphologicalBinarize@
img, (First[thresh] <= #Count <
Last[thresh] && #Circularity > circ) &] //
MorphologicalComponents //
ComponentMeasurements[#, "Centroid"] & // Values;
data = segmentImage@img;
showFunc[img_, pts_] :=
Show[img,
Graphics[{XYZColor[0, 0, 1, 0.4], Thickness[0.005],
Circle[#, 8] & /@ pts}]];
ovimg = showFunc[img, data];
packagedFunction[pts_?(Length@# > 1 &)] :=
Block[{delMesh, vertexcoords, vertexconn, cellNeighCoords, angles,
anglesC, poly, pos, polyOrdered, colourVM},
delMesh = DelaunayMesh@pts;
vertexcoords = <|delMesh["VertexCoordinateRules"]|>;
vertexconn = delMesh["VertexVertexConnectivityRules"];
cellNeighCoords = With[{vertexpts = vertexcoords},
FlattenAt[{Lookup[vertexpts, Keys@#],
Lookup[vertexpts, Values@#]}, {2}] & /@ vertexconn
];
angles = (Abs[(Plus @@ Exp[6.0 I #])/Length@#]) & /@
Map[Map[x \[Function] VectorAngle[{1, 0}, First[#] - x ],
Rest@#] &, cellNeighCoords];
anglesC = ColorData["TemperatureMap", #] & /@ angles;
poly = MeshPrimitives[VoronoiMesh[pts, None], 2];
CreateDocument[{ExpressionCell[RegionMember /@ poly, Automatic]}] (* PROBLEM HERE? *)
];
)
], WindowTitle -> "BondOrientationalOrder"]

ExpressionCellhandle any type of dataGraphics,Textor evenRegionMemberFunction? – Ali Hashmi Apr 29 '18 at 11:22Method -> "Queued"will fix your problem. Since the calculation is long, please take a look at Button action monitored with progress bar to learn how to show to users that something is going on. – Kuba Apr 29 '18 at 17:18