In the following code changing the InputField
does not result in observing changes in a result from FindGeometricTransform
, but moving the Locator
does.
This is related to a previous answer would seem to have a solution, but the fix from that solution doesn't fix the observed behavior, or rather, it causes other problems.
Manipulate not working inside DialogInput
In this Question/Answer, LocalizeVariables
is set to False
for the Manipulate
, and the control in question is explicitly set as Dynamic
. This then allows the Manipulate
to respond appropriately.
However, my FindGeometricTransform breaks when I try this.
In playing around with the system, I think that I have found that the situation is actually a bit more subtle than I thought. Using Nasser's suggestion, moving the Manipulate to the outside of the Module does partially solve the problem. I can get the GeometricTransform to update whenever I change the fields.
That would seem to solve the problem, however, it has a similar problem when I try to add data points to a table based upon the transform (my eventual goal). Here is a new function named maniTransform2 that illustrates the observed behavior.
imageIUsed = ExampleData[{"TestImage", "Clock"}]
maniTransform2[image_] := Manipulate[Module[{func, points},
func =
Dynamic[FindGeometricTransform[{{coord1x, coord1y}, {coord2x,
coord2y}}, {loc[[1]], loc[[2]]}][[2]]];
points =
If[Length[loc] > 2,
Setting@func[loc[[3 ;; Length[loc]]]], {}];
Row[{Show[{
Image[image],
Graphics[{Red, PointSize -> Large,
Point[{{coord1x, coord1y}, {coord2x, coord2y}}]}]}],
func, Spacer[40],
Grid[Join[{{"X-coord", "Y-Coord"}}, points
]
]
}]], {{loc, {{10, 10}, {20, 20}}}, Locator,
LocatorAutoCreate -> True}, {{coord1x, 50, "x-Position"},
InputField[#, Number] &}, {{coord1y, 50, "y-position"},
InputField[#, Number] &}, {{coord2x, 100, "x-Position"},
InputField[#, Number] &}, {{coord2y, 100, "y-position"},
InputField[#, Number] &}];
holderFunc := DynamicModule[{img = imageIUsed},
switcher =
Panel[TabView[{Dynamic[maniTransform2[img]], "Other Functions"}]];
DialogInput[Row[{Dynamic[switcher], InputField[Dynamic[img]]}]]]
So, calling maniTransform2[imageIUsed]
directly, the GeometricTransform
updates whenever I move one of the Locator
points or if I change a value in one of the various InputField
s.
If I call holderFunc
, then if I move any of the Locator
points the GeometricTranform2
updates. It also updates when I change one of the fields.
When I add a Locator (command-Click on a Mac), the procedure adds it to the Table of points below the transform function. Whatever the values are in the input fields are frozen for the transform at that point. Changing the values in the input fields will change the transform function, but they won't change the values of the points in the Table. For that matter, the If statement in general is frozen. I.e. it needs to be wrapped in a Dynamic somehow. However, doing so then places the func into a Dynamic and since func is declared in the Module, this is a no-no and it turns red.
Module[{a},Dynamic[a]]
is what causing the problem I think, without even trying it (wherea
here is yourimag
). Manipulate is a DynamicModule. $\endgroup$