Skip to content

Commit

Permalink
ENH: Add option to user to force calculate collisions when flagged as…
Browse files Browse the repository at this point in the history
… lengthy

Re #218
  • Loading branch information
cpinter committed Oct 17, 2023
1 parent 47d8eb3 commit a5f2521
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 14 deletions.
20 changes: 10 additions & 10 deletions RoomsEyeView/Logic/vtkSlicerRoomsEyeViewModuleLogic.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -534,7 +534,7 @@ vtkSlicerRoomsEyeViewModuleLogic::LoadTreatmentMachine(vtkMRMLRoomsEyeViewNode*

//----------------------------------------------------------------------------
std::vector<vtkSlicerRoomsEyeViewModuleLogic::TreatmentMachinePartType>
vtkSlicerRoomsEyeViewModuleLogic::SetupTreatmentMachineModels(vtkMRMLRoomsEyeViewNode* parameterNode)
vtkSlicerRoomsEyeViewModuleLogic::SetupTreatmentMachineModels(vtkMRMLRoomsEyeViewNode* parameterNode, bool forceEnableCollisionDetection/*=false*/)
{
vtkMRMLScene* scene = this->GetMRMLScene();
if (!scene)
Expand Down Expand Up @@ -649,24 +649,24 @@ vtkSlicerRoomsEyeViewModuleLogic::SetupTreatmentMachineModels(vtkMRMLRoomsEyeVie
}

// Disable collision detection if product of number of triangles of the two models is above threshold
if (loadedPartsNumTriangles[Gantry] * loadedPartsNumTriangles[TableTop] > MAX_TRIANGLE_NUMBER_PRODUCT_FOR_COLLISIONS)
if (loadedPartsNumTriangles[Gantry] * loadedPartsNumTriangles[TableTop] > MAX_TRIANGLE_NUMBER_PRODUCT_FOR_COLLISIONS && !forceEnableCollisionDetection)
{
vtkWarningMacro("Collision detection between gantry and table top is disabled due to too many combined triangles (product = "
<< loadedPartsNumTriangles[Gantry] * loadedPartsNumTriangles[TableTop] << ")");
vtkWarningMacro("Too many combined triangles (product = " << loadedPartsNumTriangles[Gantry] * loadedPartsNumTriangles[TableTop]
<< ") detected between gantry and table top. Collision detection may take a very long time.");
this->GantryTableTopCollisionDetection->SetInputData(0, nullptr);
this->GantryTableTopCollisionDetection->SetInputData(1, nullptr);
}
if (loadedPartsNumTriangles[Gantry] * loadedPartsNumTriangles[PatientSupport] > MAX_TRIANGLE_NUMBER_PRODUCT_FOR_COLLISIONS)
if (loadedPartsNumTriangles[Gantry] * loadedPartsNumTriangles[PatientSupport] > MAX_TRIANGLE_NUMBER_PRODUCT_FOR_COLLISIONS && !forceEnableCollisionDetection)
{
vtkWarningMacro("Collision detection between gantry and patient support is disabled due to too many combined triangles (product = "
<< loadedPartsNumTriangles[Gantry] * loadedPartsNumTriangles[PatientSupport] << ")");
vtkWarningMacro("Too many combined triangles (product = " << loadedPartsNumTriangles[Gantry] * loadedPartsNumTriangles[PatientSupport]
<< ") detected between gantry and patient support. Collision detection may take a very long time.");
this->GantryPatientSupportCollisionDetection->SetInputData(0, nullptr);
this->GantryPatientSupportCollisionDetection->SetInputData(1, nullptr);
}
if (loadedPartsNumTriangles[Collimator] * loadedPartsNumTriangles[TableTop] > MAX_TRIANGLE_NUMBER_PRODUCT_FOR_COLLISIONS)
if (loadedPartsNumTriangles[Collimator] * loadedPartsNumTriangles[TableTop] > MAX_TRIANGLE_NUMBER_PRODUCT_FOR_COLLISIONS && !forceEnableCollisionDetection)
{
vtkWarningMacro("Collision detection between collimator and table top is disabled due to too many combined triangles (product = "
<< loadedPartsNumTriangles[Collimator] * loadedPartsNumTriangles[TableTop] << ")");
vtkWarningMacro("Too many combined triangles (product = " << loadedPartsNumTriangles[Collimator] * loadedPartsNumTriangles[TableTop]
<< ") detected between collimator and table top. Collision detection may take a very long time.");
this->CollimatorTableTopCollisionDetection->SetInputData(0, nullptr);
this->CollimatorTableTopCollisionDetection->SetInputData(1, nullptr);
}
Expand Down
5 changes: 4 additions & 1 deletion RoomsEyeView/Logic/vtkSlicerRoomsEyeViewModuleLogic.h
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,11 @@ class VTK_SLICER_ROOMSEYEVIEW_LOGIC_EXPORT vtkSlicerRoomsEyeViewModuleLogic :
/// \return List of parts that were successfully set up.
std::vector<TreatmentMachinePartType> LoadTreatmentMachine(vtkMRMLRoomsEyeViewNode* parameterNode);
/// Set up the IEC transforms and model properties on the treatment machine models.
/// \param forceEnableCollisionDetection Enable collision detection between parts even if calculation is potentially
/// lengthy absed on the number of triangles of the parts.
/// \return List of parts that were successfully set up.
std::vector<TreatmentMachinePartType> SetupTreatmentMachineModels(vtkMRMLRoomsEyeViewNode* parameterNode);
std::vector<TreatmentMachinePartType> SetupTreatmentMachineModels(
vtkMRMLRoomsEyeViewNode* parameterNode, bool forceEnableCollisionDetection=false);
/// Create or get transforms taking part in the IEC logic and additional devices, and build the transform hierarchy
void BuildRoomsEyeViewTransformHierarchy();

Expand Down
26 changes: 23 additions & 3 deletions RoomsEyeView/qSlicerRoomsEyeViewModuleWidget.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -592,7 +592,7 @@ void qSlicerRoomsEyeViewModuleWidget::onLoadTreatmentMachineButtonClicked()

// Warn the user if collision detection is disabled for certain part pairs
QString disabledCollisionDetectionMessage(
"Collision detection has been disabled for the following part pairs due to high triangle numbers:\n\n");
tr("Collision detection for the following part pairs may take very long due to high triangle numbers:\n\n"));
bool collisionDetectionDisabled = false;
if (d->logic()->GetGantryTableTopCollisionDetection()->GetInputData(0) == nullptr)
{
Expand All @@ -609,9 +609,22 @@ void qSlicerRoomsEyeViewModuleWidget::onLoadTreatmentMachineButtonClicked()
disabledCollisionDetectionMessage.append("Collimator-TableTop\n");
collisionDetectionDisabled = true;
}
disabledCollisionDetectionMessage.append(tr("\nWhat would you like to do?"));
if (collisionDetectionDisabled)
{
QMessageBox::warning(this, tr("Collision detection disabled"), disabledCollisionDetectionMessage);
ctkMessageBox* existingMachineMsgBox = new ctkMessageBox(this);
existingMachineMsgBox->setWindowTitle(tr("Collision detection might take too long"));
existingMachineMsgBox->setText(disabledCollisionDetectionMessage);
existingMachineMsgBox->addButton(tr("Disable on these part pairs"), QMessageBox::AcceptRole);
existingMachineMsgBox->addButton(tr("Calculate anyway"), QMessageBox::RejectRole);
existingMachineMsgBox->setIcon(QMessageBox::Warning);
existingMachineMsgBox->exec();
int resultCode = existingMachineMsgBox->buttonRole(existingMachineMsgBox->clickedButton());
if (resultCode == QMessageBox::RejectRole)
{
// Set up treatment machine models again but make sure collision detection is not disabled between any parts
d->logic()->SetupTreatmentMachineModels(paramNode, true);
}
}

// Set treatment machine dependent properties //TODO: Use degrees of freedom from JSON
Expand Down Expand Up @@ -1058,7 +1071,14 @@ void qSlicerRoomsEyeViewModuleWidget::checkForCollisions()
}
else
{
d->CollisionDetectionStatusLabel->setText(QString::fromStdString("No collisions detected"));
QString noCollisionsMessage(tr("No collisions detected"));
if (d->logic()->GetGantryTableTopCollisionDetection()->GetInputData(0) == nullptr
|| d->logic()->GetGantryPatientSupportCollisionDetection()->GetInputData(0) == nullptr
|| d->logic()->GetCollimatorTableTopCollisionDetection()->GetInputData(0) == nullptr)
{
noCollisionsMessage.append(tr(" (excluding certain parts)"));
}
d->CollisionDetectionStatusLabel->setText(noCollisionsMessage);
d->CollisionDetectionStatusLabel->setStyleSheet("color: green");
}
}
Expand Down

0 comments on commit a5f2521

Please sign in to comment.