-
Notifications
You must be signed in to change notification settings - Fork 5
Add operator to spatial transform ts4231 data #432
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Overall looks good, I did not test the functionality but did leave some comments on some potential restructuring of the code, and the need to add XML comments before we can merge this.
- Consolidate win form event handlers - Initialize SpatialTransformMatrix property to indentity matrix - Refactor some functions here and there
- This is a more elegant than using the `WinForm.Control.Invoke` pattern to avoid cross-threading errors
- I think the the sptial transform should be another property within TS4231PositionData that allows the user to map the base-station-based coordinate system into an external coordinate system - Defaulting to identity matrix means that this does nothing by default.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is an interesting idea but we need to do some things to make it useful generally. I've committed some changes that start to move in this direction. Other refinements are
- The user needs to be able to cancel a measurement and start over. Or a timeout needs to be set that will cancel a measurement if some time has elapsed before lighthouse data is received.
- Ideally the editor should not display unless the workflow is running. I think there are ways to check the run state of a workflow when an editor is opened.
- add cancel button - add timeout (probably only need timeout or cancel button) - check workflow is running before opening GUI - leave text boxes blank - correctly populate ts4231V1CoordinatesMatrix - give persistent scope to subscriptions so they can be disposed - simplify conditional statement for checking if user input is valid - minor edit to top-level label to be consistent with changes
I made changes and did some cursory testing to make sure it looks ok and still works. I didn't have time to extensively test this latest commit. There is one problem with the current implementation which is that the calculated matrix spatial transform is only correct if we are already starting with an identity matrix. |
It seems like the user supplied coordinates are verified in real-time for the correct format. It would be nice to have a status text indicating if the input is valid or not (e.g. "input coordinates invalid vs. input coordinates valid". You can a tool strip for this (see e.g. Rhs2116StimulusSequenceDialog.cs: |
…Dialog - This should recover the raw position values from P and Q alone without the M that is currently being edited.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Almost there. I added some comments and I think i took care of the issue with non-default values of M.
Please do some verification with real headstage in known space and wacky values for initial value of M.
@jonnew Re:
I'm wondering if it would be worth indicating which coordinate is invalid. like having green checks or red x-es for each row or each cell (probably instead of the status strip) as indicated by this screenshot: |
jonnew's feedback: - Add status strip - Use "OK", "Cancel" button paradigms additionally: - Improve resizing - Address all VS messages - PascalCase methods - Make "using" syntax more concise - Add/Edit some XML comments - Instead of transforming every Vector3 and then averaging, average all Vector3s and then take the transform - Inline/remove the GetData() function
I addressed feedback (look at commit message for more details). I tested calculating a new M from a pre-set M. This seems to work OK. |
Several overall architectural comments:
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please have a look at my comments in the PR
- The operator is now an included workflow comprising of ts4231 source node and a spatial transform node - The property that's set by the dialog is a struct containing pre-transform coordinates, post-transform coordinates and spatial transform matrix instead of just the matrix - Add workflows to ItemGroup in Onix1.csproj - Revert TS4231V1PositionData - Dialog changes: - Add X, Y, Z labels - Add a textbox for each component of each coordinate instead of one textbox - Add a textbox & label for displaying Spatial Transform Matrix - Change status messages TextBox to RichTextBox which allows changing font color and using newline characters instead of environment.newline. - Automatically calculate transform matrix when inputs are valid (avoids decoupling sets of pre-transform & post-transform coordinates and the spatial transform) - Simplify bottom toolstrip behavior - Move event handlers to top and helper methods underneath - Change instructions in top label according to the above changes
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The behavior of this is now correct. In terms of implementation I've provided some comments below. Additionally you should perform a git rebase main
on this to bring it up to date. I did this and there was one trivial conflict in the csproj file in which you can accept main
's version in its entirety.
/// <summary> | ||
/// The set of coordinates before undergoing a spatial transform. | ||
/// </summary> | ||
public Vector3[] Pre { get; set; } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ultimately this and Post
ends up being a Matrix4x4 when used in the inversion operation to find M. It seems like they should be stored as such as private variables with controlled access via setting functions that accept input types that are more amenable to interaction with the GUI elements. (e.g. Vector3 and index). Currently there is nothing here that controls the length of these vectors since they have public sets.
Array.Copy(other.Post, Post, 4); | ||
M = other.M; | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This class should probably be called SpatialTransform3D
or something and actually contain the math for performing the inversion operation whenever a correspondence (pre, post) is added.
/// The spatial transform matrix calculated from <see cref="Pre"/> and | ||
/// <see cref="Post"/>. | ||
/// </summary> | ||
public Matrix4x4? M { get; set; } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
M should have private set and be updated as a function of whatever function adds pre/post data. This way its a function of pre and post rather than requiring manual update and public setting.
|
||
private void CalculatePrintMatrix() | ||
{ | ||
SpatialTransform.M = null; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Move all of this logic the the SpatialTransformProperties
class. If M is a function of pre and post there, none of this checking is required.
Further, never put logic like this in a GUI. The GUI's logic should pertain to handling of GUI elements and perhaps setting the state of the object(s) the GUI represents via getters and setters.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
True. I think I achieved this now. In particular, this GUI is meant to provide the user a way of setting or viewing data in the SpatialTransform3D
class which is subsequently used to transform spatial transform data.
I rebased and pushed into another branch. I propose closing this PR and then making #477 the active one for this issue. |
I don't think it's particularly important to port my changes in issue-427_rebased back into this branch. I'm going to close this PR and we can finish our work on for the PR #477 corresponding to issue-427_rebased. |
Resolve #427