iMSTK
Interactive Medical Simulation Toolkit
iMSTK contributing guide

Forking workflow

To contribute your changes to iMSTK, you will need to follow the Gitlab forking workflow.

  1. Fork the iMSTK project to your own namespace.
  2. Add the forked remote repository to your git source directory.
    git remote add myremote git@gitlab.kitware.com:<mynamespace>/iMSTK.git
  3. Create a new branch where you will commit your changes, and name it based on the feature or fix you are implementing.
    git checkout -b new-feature
  4. Implement your changes: please follow the coding guidelines below.
  5. Commit your changes: please follow the commit guidelines below.
  6. Push your development branch to your namespace.
    git push myremote new-feature
  7. Create a merge request once your branch is ready for merging, or earlier as WIP if this is a long merge request and need other developers to discuss it.
  8. Stay available for the review process: you might need to address some issues and push new changes.
  9. Once your changes have been reviewed and the associated builds and tests pass on iMSTK dashboards, your branch will be merged into master.
  10. At that point, you may decide to get rid of your development branch and pull the latest commits from the master branch, then repeat from step 3 for further development
    git branch -d new-feature
    git checkout master
    git pull origin master

Coding guidelines

See the https://gitlab.kitware.com/iMSTK/iMSTK/-/tree/master/Docs/CodingGuide.md "Imstk Coding Guide"

Code style check

You should use the uncrustify tool to check and/or adjust code style of your files.

*INDENT-ON* and *INDENT-OFF* keywords in comments can be used to disable uncrustify's style check for a portion of the code, this is currently used to avoid some issues uncrustify has with macros.

Testing Code

A developer with Developer role in giltab may run tests on MRs submitted. Assign or ping one for review and to run tests on our machines. A developer may run:

Test results are repoted to our CDash. Here you will find a Merge Requests section with cmake configure, build, & test sections.

Commit guidelines

Commit 101

  1. Commit often

    You do not need to have a lot of changes to create a commit. On the contrary, you should try to split your changes into small logical steps and commit each of them. They should be consistent, self-contained (work independently of later commits), and pass the same test which previously did (or more) to ensure you do not introduce any regression. On the other hand, do not push it to the extreme: if your changes are tightly related and stay clear as a whole, there is no need to create multiple commits, even if they are applied to different files, methods, etc. >TIP: git gui will allow you to stage changes by lines or by hunk instead of the whole file. It is extremely useful when your recent changes could be divided in multiple commits.

  2. Style only rhymes with style

    Style changes can introduce a big number of diffs in your whole project (take a variable name change, tabulation in a whole file...). If commited as part of a commit for enhancement or bug fixes, it becomes very difficult for a reviewer to track down the changes specific to your work, and the ones specific to style changes. For that reason, prefer grouping style changes in a separate commit.

  3. Push often

    A good reason to push often is to have your work somewhere else than just on your computer in the event of something were to happen to local computer. Another reason is to facilitate code sharing: even if your branch is not at maturity, creating a pull request as WIP will allow you to discuss your progress, ask questions, and get feedbacks during the development process and not just at the end.

  4. Merge often...

    The whole idea behind continuous integration (or CI) is to integrate your own code with the main repository as often as you can. If you make small changes and put them into single commits you may integrate them often (and probably should). Doing so minimizes merge conflicts with your team members. You can read more about CI in a Git context in Martin Fowler’s excellent FeatureBranch article.

  5. **... but never the other way around!**

    If your branch and the master branch diverge and are in conflicts, never resolve those by merging master into your branch. Instead, rebase your branch against master. This will allow you to adress the conflicts where they were introduced instead of commiting a patch complicated to review, and will keep the commit history clean.

Some of the content above was directly or partially taken from Crealytics blog : 5 reasons for keeping your git commits small.

Commit messages

Proper commit messages are important as they allow to speed up the review process. They are also crucial for development down the road to be able to come back to that commit and understand the logic behind the changes.

  1. Describe thoroughly

    Assume the reviewers do not know your motivation behind your work: every change you make has a reason you need to explicitly write down in the commit description, even the little things (ex: why changing a default value). This will accelerate the review process by allowing reviewers to rely on your work description instead of having to contact you for answers.

  2. Document accordingly

    A great addition is to offer links to additional information like your source (reference to the algorithm you are using, online discussion supporting your changes...), hash of the commit that introduced the regression being fixed, etc.

  3. Be specific

    When making changes to multiple classes or refering to other classes than the one being modified, be specific about class functions and member variables by properly specifying the namespace: Class:function() or Class::m_member.

  4. List changes

    If your commit is composed of multiple changes in order to stay self-contained, list your changes instead of appending them in long paragraphs for clarity.

  5. Use a clear and short commit title

    Describe the topic in a couple words while being as specific as possible. "Improve rendering" or "Fix controllers" would be considered too broad.

  6. Use the appropriate title prefix to help quickly understand broad context
    • BUG: Fix for runtime crash or incorrect result
    • COMP: Compiler error or warning fix
    • DOC: Documentation change
    • ENH: New functionality
    • REFAC: Rework of existing functionality
    • PERF: Performance improvement
    • TEST: Test change
    • STYLE: No logic impact (indentation, comments)
    • WIP: Work In Progress not ready for merge

Editing previous commits

While implementing your topic that would be holding multiple commits, you might end up making changes which should be coupled with or which revert changes from previous commits. The same can happen when your merge request has been reviewed and you need to make changes that should be applied in an existing commit.

It is possible to change previous commits in order to keep your topic clean and make the reviewing process easier, a couple options are listed below.

This process consists of rewriting the branch history, therefore re-syncing it with other remote and local repositories will be necessary (see below).

Data Management

iMSTKs data sits in a separate repository https://gitlab.kitware.com/iMSTK/imstk-data managed with git LFS. It is downloaded by iMSTK's superbuild when either the testing or the examples is enabled.

Add Data:

  1. Checkout imstk-data repository. imstk-data.
  2. Commit & push changes.
  3. Copy the sha of the desired commit to pull in iMSTK's CMake/External/External_iMSTKData.cmake file.
  4. Clean build or rebuild the iMSTKData target.

Fetch Data:

A clean build will always acquire the latest changes. If incrementally building, go up to the superbuild and rebuild the iMSTKData target.

Data Usage:

The path to the data directory is defined by iMSTK_DATA_ROOT which can be used in your C++ code as shown below :

{c++}
imstk::MeshIO::read<TetrahedralMesh>(iMSTK\_DATA\_ROOT"/relative/path/to/mesh.vtk");

Dashboards

Dashboards - powered by CDash - helps visualizing the latest state of iMSTK builds on Windows, MacOSx, and Linux, to avoid introducing regressions when offering changes to the toolkit: >http://open.cdash.org/index.php?project=iMSTK

**Name** CDash Build Group Description
**Nightly** Builds running every night
**Continuous** Builds running every time there is a change to the master branch
**Experimental** Builds running after calling do: test in the comment section of a Merge Request