mirror of
https://github.com/PhotonVision/photonvision
synced 2026-06-28 02:11:40 +00:00
Recreate user pipeline on type change (#1290)
* Recreate user pipeline on type change * Fix typo --------- Co-authored-by: shueja <32416547+shueja@users.noreply.github.com>
This commit is contained in:
@@ -226,44 +226,10 @@ public class PipelineManager {
|
||||
return;
|
||||
}
|
||||
|
||||
// Cleanup potential old native resources before swapping over for user pipelines
|
||||
if (currentUserPipeline != null && !(newIndex < 0)) {
|
||||
currentUserPipeline.release();
|
||||
}
|
||||
|
||||
currentPipelineIndex = newIndex;
|
||||
if (newIndex >= 0) {
|
||||
var desiredPipelineSettings = userPipelineSettings.get(currentPipelineIndex);
|
||||
switch (desiredPipelineSettings.pipelineType) {
|
||||
case Reflective:
|
||||
logger.debug("Creating Reflective pipeline");
|
||||
currentUserPipeline =
|
||||
new ReflectivePipeline((ReflectivePipelineSettings) desiredPipelineSettings);
|
||||
break;
|
||||
case ColoredShape:
|
||||
logger.debug("Creating ColoredShape pipeline");
|
||||
currentUserPipeline =
|
||||
new ColoredShapePipeline((ColoredShapePipelineSettings) desiredPipelineSettings);
|
||||
break;
|
||||
case AprilTag:
|
||||
logger.debug("Creating AprilTag pipeline");
|
||||
currentUserPipeline =
|
||||
new AprilTagPipeline((AprilTagPipelineSettings) desiredPipelineSettings);
|
||||
break;
|
||||
|
||||
case Aruco:
|
||||
logger.debug("Creating Aruco Pipeline");
|
||||
currentUserPipeline = new ArucoPipeline((ArucoPipelineSettings) desiredPipelineSettings);
|
||||
break;
|
||||
case ObjectDetection:
|
||||
logger.debug("Creating ObjectDetection Pipeline");
|
||||
currentUserPipeline =
|
||||
new ObjectDetectionPipeline(
|
||||
(ObjectDetectionPipelineSettings) desiredPipelineSettings);
|
||||
default:
|
||||
// Can be calib3d or drivermode, both of which are special cases
|
||||
break;
|
||||
}
|
||||
if (newIndex >= 0) {
|
||||
recreateUserPipeline();
|
||||
}
|
||||
|
||||
DataChangeService.getInstance()
|
||||
@@ -272,6 +238,48 @@ public class PipelineManager {
|
||||
"fullsettings", ConfigManager.getInstance().getConfig().toHashMap()));
|
||||
}
|
||||
|
||||
/**
|
||||
* Recreate the current user pipeline with the current pipeline index. Useful to force a
|
||||
* recreation after changing pipeline type
|
||||
*/
|
||||
private void recreateUserPipeline() {
|
||||
// Cleanup potential old native resources before swapping over from a user pipeline
|
||||
if (currentUserPipeline != null && !(currentPipelineIndex < 0)) {
|
||||
currentUserPipeline.release();
|
||||
}
|
||||
|
||||
var desiredPipelineSettings = userPipelineSettings.get(currentPipelineIndex);
|
||||
switch (desiredPipelineSettings.pipelineType) {
|
||||
case Reflective:
|
||||
logger.debug("Creating Reflective pipeline");
|
||||
currentUserPipeline =
|
||||
new ReflectivePipeline((ReflectivePipelineSettings) desiredPipelineSettings);
|
||||
break;
|
||||
case ColoredShape:
|
||||
logger.debug("Creating ColoredShape pipeline");
|
||||
currentUserPipeline =
|
||||
new ColoredShapePipeline((ColoredShapePipelineSettings) desiredPipelineSettings);
|
||||
break;
|
||||
case AprilTag:
|
||||
logger.debug("Creating AprilTag pipeline");
|
||||
currentUserPipeline =
|
||||
new AprilTagPipeline((AprilTagPipelineSettings) desiredPipelineSettings);
|
||||
break;
|
||||
|
||||
case Aruco:
|
||||
logger.debug("Creating Aruco Pipeline");
|
||||
currentUserPipeline = new ArucoPipeline((ArucoPipelineSettings) desiredPipelineSettings);
|
||||
break;
|
||||
case ObjectDetection:
|
||||
logger.debug("Creating ObjectDetection Pipeline");
|
||||
currentUserPipeline =
|
||||
new ObjectDetectionPipeline((ObjectDetectionPipelineSettings) desiredPipelineSettings);
|
||||
default:
|
||||
// Can be calib3d or drivermode, both of which are special cases
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Enters or exits calibration mode based on the parameter. <br>
|
||||
* <br>
|
||||
@@ -502,5 +510,6 @@ public class PipelineManager {
|
||||
userPipelineSettings.set(idx, newSettings);
|
||||
setPipelineInternal(idx);
|
||||
reassignIndexes();
|
||||
recreateUserPipeline();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user