Closing Issue #63 . Also relates to contour misplacement. Problems arise when canceling autoreg. Now fixed.
Also closing issue #91 - Not the most elegant solution. For amoeba we do not visualise Iteration but value of optimizer.
This commit is contained in:
@ -28,9 +28,23 @@ public slots:
|
||||
void onAbortProcessCommand(){
|
||||
bAbortProcessCommand = true;
|
||||
};
|
||||
void onIteration(double dI,double dX,double dY,double dZ){
|
||||
emit
|
||||
sendRegistrationProgress(dI,dX,dY,dZ);
|
||||
void onIteration(itk::tOptimizerTypeEnum eType,double dI,double dX,double dY,double dZ){
|
||||
|
||||
switch (eType) {
|
||||
case itk::eOptimizerType::POWELL:
|
||||
|
||||
emit
|
||||
sendRegistrationProgress(0,dI,dX,dY,dZ);
|
||||
|
||||
break;
|
||||
|
||||
case itk::eOptimizerType::AMOEBA:
|
||||
|
||||
emit
|
||||
sendRegistrationProgress(1,dI,dX,dY,dZ);
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
}
|
||||
private:
|
||||
@ -42,7 +56,7 @@ private:
|
||||
|
||||
|
||||
signals:
|
||||
void sendRegistrationProgress(double,double,double,double);
|
||||
void sendRegistrationProgress(int,double,double,double,double);
|
||||
|
||||
};
|
||||
|
||||
@ -57,6 +71,11 @@ class CommandIterationUpdate : public itk::Command {
|
||||
|
||||
public:
|
||||
QObjectIterationUpdate *objIterUpdate;
|
||||
tOptimizerTypeEnum
|
||||
eOptimType;
|
||||
|
||||
int
|
||||
iAmoebaIterations;
|
||||
|
||||
using Self = CommandIterationUpdate;
|
||||
using Superclass = itk::Command;
|
||||
@ -85,7 +104,12 @@ public:
|
||||
using OptimizerPointer = const OptimizerType*;
|
||||
|
||||
using AmoebaOptimizerType = itk::AmoebaOptimizer;
|
||||
using AmoebaOptimizerPointer = const OptimizerType*;
|
||||
using AmoebaOptimizerPointer = const AmoebaOptimizerType*;
|
||||
|
||||
void setOptimizerTypeOfIterationUpdate(tOptimizerTypeEnum eOptType){
|
||||
eOptimType = eOptType;
|
||||
iAmoebaIterations = 0;
|
||||
}
|
||||
|
||||
void
|
||||
Execute(itk::Object* caller, const itk::EventObject& event) override
|
||||
@ -103,34 +127,70 @@ public:
|
||||
}
|
||||
// std::cout << "Progress: " << this->m_Process->GetAbortGenerateData() << std::endl;
|
||||
|
||||
auto optimizer = dynamic_cast<OptimizerPointer>(object);
|
||||
OptimizerPointer optPow;
|
||||
AmoebaOptimizerPointer optAm;
|
||||
|
||||
if (typeid(event) == typeid(itk::IterationEvent)) {
|
||||
switch (eOptimType) {
|
||||
case eOptimizerType::POWELL:
|
||||
optPow = dynamic_cast<OptimizerPointer>(object);
|
||||
if (typeid(event) == typeid(itk::IterationEvent)) {
|
||||
|
||||
//Feedback from the optimizer executed at the end of every itteration
|
||||
// currently just print the result into the cout. We might add
|
||||
// functionality to register and emit signals to update the UI.
|
||||
objIterUpdate->onIteration(
|
||||
eOptimType,
|
||||
optPow->GetCurrentIteration()+1,
|
||||
optPow->GetCurrentPosition()[0],
|
||||
optPow->GetCurrentPosition()[1],
|
||||
optPow->GetCurrentPosition()[2]
|
||||
);
|
||||
}
|
||||
|
||||
std::cout << "Iteration: " << optimizer->GetCurrentIteration() << std::endl;
|
||||
auto oldprecision = std::cout.precision();
|
||||
std::cout.precision(std::numeric_limits<double>::digits10 + 2);
|
||||
std::cout << "Similarity: " << optimizer->GetValue() << std::endl;
|
||||
std::cout.precision(oldprecision);
|
||||
std::cout << "Position: " << optimizer->GetCurrentPosition() << std::endl;
|
||||
break;
|
||||
case eOptimizerType::AMOEBA:
|
||||
optAm = dynamic_cast<AmoebaOptimizerPointer>(object);
|
||||
iAmoebaIterations ++;
|
||||
if(iAmoebaIterations == 100){
|
||||
iAmoebaIterations = 100;
|
||||
}
|
||||
|
||||
objIterUpdate->onIteration(
|
||||
eOptimType,
|
||||
optAm->GetCachedValue(),
|
||||
optAm->GetCachedCurrentPosition()[0],
|
||||
optAm->GetCachedCurrentPosition()[1],
|
||||
optAm->GetCachedCurrentPosition()[2]
|
||||
);
|
||||
break;
|
||||
|
||||
}
|
||||
|
||||
// auto optimizer = dynamic_cast<OptimizerPointer>(object);
|
||||
|
||||
// if (typeid(event) == typeid(itk::IterationEvent)) {
|
||||
|
||||
// //Feedback from the optimizer executed at the end of every itteration
|
||||
// // currently just print the result into the cout. We might add
|
||||
// // functionality to register and emit signals to update the UI.
|
||||
|
||||
//// std::cout << "Iteration: " << optimizer->GetCurrentIteration() << std::endl;
|
||||
//// auto oldprecision = std::cout.precision();
|
||||
//// std::cout.precision(std::numeric_limits<double>::digits10 + 2);
|
||||
//// std::cout << "Similarity: " << optimizer->GetValue() << std::endl;
|
||||
//// std::cout.precision(oldprecision);
|
||||
//// std::cout << "Position: " << optimizer->GetCurrentPosition() << std::endl;
|
||||
|
||||
//// objIterUpdate->onIteration(
|
||||
//// optimizer->GetCurrentIteration()+1,
|
||||
//// optimizer->GetCurrentPosition()[0],
|
||||
//// optimizer->GetCurrentPosition()[2],
|
||||
//// -optimizer->GetCurrentPosition()[1]
|
||||
//// );
|
||||
// objIterUpdate->onIteration(
|
||||
// optimizer->GetCurrentIteration()+1,
|
||||
// optimizer->GetCurrentPosition()[0],
|
||||
// optimizer->GetCurrentPosition()[2],
|
||||
// -optimizer->GetCurrentPosition()[1]
|
||||
// optimizer->GetCurrentPosition()[1],
|
||||
// optimizer->GetCurrentPosition()[2]
|
||||
// );
|
||||
objIterUpdate->onIteration(
|
||||
optimizer->GetCurrentIteration()+1,
|
||||
optimizer->GetCurrentPosition()[0],
|
||||
optimizer->GetCurrentPosition()[1],
|
||||
optimizer->GetCurrentPosition()[2]
|
||||
);
|
||||
}
|
||||
// }
|
||||
return;
|
||||
}
|
||||
};
|
||||
|
@ -153,6 +153,7 @@ void itkReg23::InitializeRegistration()
|
||||
PowellOptimizer->SetValueTolerance(m_PowellMeta->GetValueTolerance());
|
||||
PowellOptimizer->RemoveAllObservers();
|
||||
PowellOptimizer->AddObserver(itk::IterationEvent(), m_OptimizerObserver);
|
||||
m_OptimizerObserver->setOptimizerTypeOfIterationUpdate(tOptimizerTypeEnum::POWELL);
|
||||
|
||||
registration->SetOptimizer(PowellOptimizer);
|
||||
|
||||
@ -177,6 +178,7 @@ void itkReg23::InitializeRegistration()
|
||||
AmoebaOptimizer->SetInitialSimplexDelta(simplexDelta);
|
||||
AmoebaOptimizer->RemoveAllObservers();
|
||||
AmoebaOptimizer->AddObserver(itk::IterationEvent(), m_OptimizerObserver);
|
||||
m_OptimizerObserver->setOptimizerTypeOfIterationUpdate(tOptimizerTypeEnum::AMOEBA);
|
||||
|
||||
registration->SetOptimizer(AmoebaOptimizer);
|
||||
|
||||
|
Reference in New Issue
Block a user