Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

@B1ueber2y
Copy link
Contributor

@B1ueber2y B1ueber2y commented Feb 1, 2024

Since we want to pybind substeps of the IncrementalMapperController in python in the end, we need to disentangle the threading-related function from the controller class, such that we can further abstract the controller and manipulate the same thread in python.

This DRAFT feature contains several updates as follows (need discussions on the naming and infrastructure. This PR is potentially dangerous):

  • Remove the usage of timer from the Thread class, to prepare for separating the Run function into several steps in Python. Now the timer is initialized in the upper level at the start of the "Run" function.
  • Make a new BaseController class that inherits from a CoreController class, which supports all the previous features from the Thread class (https://github.com/B1ueber2y/colmap/blob/features/remove_thread_from_exe/src/colmap/util/threading_ctrl.h). While all the threading-related operations are set as callbacks with empty as default. When the threading is needed, one can use ControllerThread class which uses a controller class as its template class and implements the callbacks in the constructor.
  • Change the virtual method Run from private into public (such that we can bind substeps later). Change the calling at top level from Start() + Wait() into a single Run() (e.g., https://github.com/colmap/colmap/pull/2392/files#diff-a075407d92533f0fe38542d18c5b0d9a8110138218e77a67deff2db3bb2811beR113). Only ui needs threading-related functions.
  • Change the parent of the IncrementalMapper into BaseController and update the ui by using ControllerThread.

If approved we can later change all the classes (now this draft PR only updates IncrementalMapperController and the UI) into this new design by changing the parents of most controller from Thread to BaseController, and only use ControllerThread class when threading-related functions are needed.

@ahojnnes @sarlinpe

@B1ueber2y B1ueber2y marked this pull request as draft February 1, 2024 20:46
@ahojnnes
Copy link
Contributor

ahojnnes commented Feb 3, 2024

Thanks, I am not sure how this helps with the next steps that you are envisioning and thus cannot formulate an opinion on these changes. For me to understand a little better: Would the existing "Thread" class still exist after these changes or simplify?

@B1ueber2y
Copy link
Contributor Author

B1ueber2y commented Feb 3, 2024

With the new update just now the controller and threading is further disentangled by registering the callbacks of the controller in the thread class. Now the controller only supports the threading-functions as follows:

  • SignalValidSetup()
  • SignalInValidSetup()
  • CheckValidSetup()
  • IsStopped()
  • BlockIfPaused()

Note that now functions such as Start(), IsStarted(), Wait(), etc. is not supported in the controller anymore, and can only be called in the ControllerThread class.

Also, @sarlinpe suggested to combine BlockIfPaused() and IsStopped() together in a CheckIfStopped() method, such that we can modify this handle in python in the future outside the C++ threading design. I have made this possible and integrated into the IncrementalMapperController, such that now in the IncrementalMapperController we only used this CheckIfStopped method.

@ahojnnes About the next steps, Now the new design is only integrated in the IncrementalMapperController as a draft. The initial plan is indeed to replace the Thread class with ControllerThread in the end. But I also have no problem to keep the Thread class implementation for convenience (while it may cause confusion in the future). In the end BaseController will go into the controller folder, and ControllerThread can stay in the ui or be put into the threading header. If approved we can update all the controller with this new design and then we can split the Run() method further into substeps, such that we can support better and detailed bindings in Python.

@B1ueber2y
Copy link
Contributor Author

B1ueber2y commented Feb 3, 2024

The polymorphism with active_thread_ in the mapper controller can be further supported with the SetCheckIfStoppedFunc method from the controller (f82b002#diff-faf29b81ac33239a3b5179ec793d7f032660ae99f8cf1865341f7b4eb09476edR230), which is a callback that returns boolean value. This is also used in the IncrementalMapperController.

@B1ueber2y B1ueber2y changed the title Disentangle the controller from threading Disentangle the controller from threading and integrate the new logic into IncrementalMapperController Feb 3, 2024
@B1ueber2y B1ueber2y marked this pull request as ready for review February 3, 2024 22:08
@sarlinpe
Copy link
Member

sarlinpe commented Feb 5, 2024

@B1ueber2y This design is much cleaner than the previous one. I think that we can move more threading logic out of the BaseController - see my comments.

@B1ueber2y
Copy link
Contributor Author

B1ueber2y commented Feb 5, 2024

I have made a new design update on the ControllerThread class by directly inheriting from Thread. The only added feature is

In this design we wont deprecate the Thread class, but can still migrate most controller class into the new design to disentangle the threading. This feels like a far more elegant way to me and also the update becomes more stable without significant changes.

@sarlinpe
Copy link
Member

sarlinpe commented Feb 5, 2024

LGTM, great work, thanks a lot!

@sarlinpe sarlinpe self-requested a review February 6, 2024 07:40
@ahojnnes
Copy link
Contributor

ahojnnes commented Feb 6, 2024

Thanks, looks great. I assume you will follow up with equivalent changes for other controllers?

@ahojnnes ahojnnes merged commit 74e21c4 into colmap:main Feb 6, 2024
@B1ueber2y B1ueber2y deleted the features/remove_thread_from_exe branch February 9, 2024 11:58
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.

3 participants