Skip to content

Conversation

cjsha
Copy link
Member

@cjsha cjsha commented Apr 16, 2025

Resolve #427

@cjsha cjsha requested a review from bparks13 April 16, 2025 13:29
@cjsha cjsha requested a review from jonnew April 16, 2025 13:33
Copy link
Member

@bparks13 bparks13 left a 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.

cjsha added 2 commits April 16, 2025 16:07
- 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
@cjsha cjsha added this to the 0.5.0 milestone Apr 18, 2025
- 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.
Copy link
Member

@jonnew jonnew left a 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

  1. 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.
  2. 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
@cjsha cjsha requested a review from jonnew April 23, 2025 00:04
@cjsha
Copy link
Member Author

cjsha commented Apr 23, 2025

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.

@jonnew
Copy link
Member

jonnew commented May 6, 2025

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:

image

@jonnew
Copy link
Member

jonnew commented May 6, 2025

Instead of this:

image

use the standard "OK, Cancel" pattern:

image

See Rhs2116StimulusSequenceEditor for an example.

…Dialog

- This should recover the raw position values from P and Q alone without
  the M that is currently being edited.
Copy link
Member

@jonnew jonnew left a 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.

@cjsha
Copy link
Member Author

cjsha commented May 7, 2025

@jonnew Re:

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

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:

Screenshot 2025-05-07 084942

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
@cjsha
Copy link
Member Author

cjsha commented May 20, 2025

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.

@cjsha cjsha requested a review from jonnew May 20, 2025 00:02
@ChucklesOnGitHub ChucklesOnGitHub self-assigned this May 22, 2025
@jonnew
Copy link
Member

jonnew commented May 30, 2025

If I click measure for a coordinate with data in it, and the measurement is invalid, it doesnt get rid of the old measurement

image

Desired?

@jonnew
Copy link
Member

jonnew commented May 30, 2025

Here are some changes I think would be helpful to the UI

image

  • In addition, please put more line breaks between items in the instructions. Its very compact and hard to read.
  • Also, make sure Tab works as expected for the entered values (goes in row major order)
    image

@jonnew
Copy link
Member

jonnew commented May 30, 2025

It is possible to create a transform that collapses dimensions by providing zero for a given dimension. For instance if all my calibration data is in a single X,Y plane, this is the result:

image

This should not be permitted.

@jonnew
Copy link
Member

jonnew commented May 30, 2025

Several overall architectural comments:

  • The property M should be replaced with a custom class that holds both M and all the measurements and corresponding user coordinates used to create it. This way, when the GUI is invariably reopened, the user can make incremental edits instead of needing to start over.
  • The need to invert M to reopen the GUI needs to go away. To do this, I suggest that we turn this into a transform called TS4231SpatialTransform. TS4231PositionData remains the uncalibrated position data its always been. A new, EmbeddedWorkflow is created called TS4231CalibratedPositionData that combines TS4231PositionData with the TS4231SpatialTransform. This way the transform always has access to untransformed data an inversion of M is not required.

Copy link
Member

@jonnew jonnew left a 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

@jonnew jonnew modified the milestones: 0.5.0, 0.5.1 Jun 2, 2025
cjsha added 5 commits June 11, 2025 15:57
- 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
@ChucklesOnGitHub ChucklesOnGitHub requested a review from jonnew June 23, 2025 15:52
Copy link
Member

@jonnew jonnew left a 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; }
Copy link
Member

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;
}
}
Copy link
Member

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; }
Copy link
Member

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;
Copy link
Member

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.

Copy link
Member Author

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.

@cjsha
Copy link
Member Author

cjsha commented Aug 1, 2025

I rebased and pushed into another branch. I propose closing this PR and then making #477 the active one for this issue.

@cjsha
Copy link
Member Author

cjsha commented Aug 18, 2025

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.

@cjsha cjsha closed this Aug 18, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Allow users to apply a spatial transform matrix to ts4231 data in the data operator

4 participants