Skip to content

Commit

Permalink
Updating nomenclature: "EarlyComplete" -> "Complete"
Browse files Browse the repository at this point in the history
Signed-off-by: jepietryga <jacobpietryga@gmail.com>
  • Loading branch information
jepietryga committed Aug 27, 2021
1 parent b256009 commit 610cc03
Show file tree
Hide file tree
Showing 15 changed files with 47 additions and 48 deletions.
4 changes: 2 additions & 2 deletions tomviz/ProgressDialogManager.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ void ProgressDialogManager::operationStarted()
layout->addWidget(progressBar);
}
layout->addWidget(progressWidget);
if (op->supportsEarlyCompletionMidTransform()) {
if (op->supportsCompletionMidTransform()) {
// Unless widget has custom progress handling, can't done it
QDialogButtonBox* dialogButtons =
new QDialogButtonBox(QDialogButtonBox::Ok | QDialogButtonBox::Cancel,
Expand All @@ -94,7 +94,7 @@ void ProgressDialogManager::operationStarted()
&QDialog::reject);

QObject::connect(progressDialog, &QDialog::accepted, op,
&Operator::earlyCompletionTransform);
&Operator::completionTransform);
QObject::connect(dialogButtons, &QDialogButtonBox::accepted, progressDialog,
&QDialog::accept);
} else if (op->supportsCancelingMidTransform()) {
Expand Down
2 changes: 1 addition & 1 deletion tomviz/core/OperatorProxyBase.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ class OperatorProxyBase

virtual bool canceled() = 0;

virtual bool earlyCompleted() = 0;
virtual bool completed() = 0;

virtual void setTotalProgressSteps(int progress) = 0;

Expand Down
4 changes: 2 additions & 2 deletions tomviz/operators/Operator.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -218,9 +218,9 @@ void Operator::cancelTransform()
emit transformCanceled();
}

void Operator::earlyCompletionTransform()
void Operator::completionTransform()
{
m_state = OperatorState::Complete;
emit transformEarlyCompleted();
emit transformCompleted();
}
} // namespace tomviz
18 changes: 9 additions & 9 deletions tomviz/operators/Operator.h
Original file line number Diff line number Diff line change
Expand Up @@ -147,11 +147,11 @@ class Operator : public QObject

/// Returns true if the operation supports early completion midway through the
/// applyTransform function via the cancelTransform slot.
/// Defaults to false, can be set by the setSupportsEarlyCompletion(bool)
/// Defaults to false, can be set by the setSupportsCompletion(bool)
/// method by subclasses.
bool supportsEarlyCompletionMidTransform() const
bool supportsCompletionMidTransform() const
{
return m_supportsEarlyCompletion;
return m_supportsCompletion;
}

/// Return the total number of progress updates (assuming each update
Expand Down Expand Up @@ -247,20 +247,20 @@ class Operator : public QObject
// transform. The operator will still be running, so there has to be
// a request to cancel the operator as well as encourage the next
// operator to run.
void transformEarlyCompleted();
void transformCompleted();

public slots:
/// Called when the 'Cancel' button is pressed on the progress dialog.
/// Subclasses overriding this method should call the base implementation
/// to ensure the operator is marked as canceled.
/// TODO: Not sure we need this/want this virtual anymore?
virtual void cancelTransform();
virtual void earlyCompletionTransform();
virtual void completionTransform();
bool isCanceled() { return m_state == OperatorState::Canceled; }

/// Distinction between this and isFinished is necessary to prevent cascading
/// errors
bool isEarlyCompleted() { return m_state == OperatorState::Complete; }
bool isCompleted() { return m_state == OperatorState::Complete; }
bool isFinished()
{
return m_state == OperatorState::Complete ||
Expand Down Expand Up @@ -297,16 +297,16 @@ protected slots:
/// Method to set whether the operator supports early completion midway
/// through the transform method call.
/// If you set this to true, you should also override the
/// earlyCompletionTransform slot to listen for the done signal and handle
/// completionTransform slot to listen for the done signal and handle
/// it.
void setSupportsEarlyCompletion(bool b) { m_supportsEarlyCompletion = b; }
void setSupportsCompletion(bool b) { m_supportsCompletion = b; }

private:
Q_DISABLE_COPY(Operator)

QList<OperatorResult*> m_results;
bool m_supportsCancel = false;
bool m_supportsEarlyCompletion = false;
bool m_supportsCompletion = false;
bool m_hasChildDataSource = false;
bool m_modified = true;
bool m_new = true;
Expand Down
4 changes: 2 additions & 2 deletions tomviz/operators/OperatorProxy.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@ bool OperatorProxy::canceled()
return m_op->isCanceled();
}

bool OperatorProxy::earlyCompleted()
bool OperatorProxy::completed()
{
return m_op->isEarlyCompleted();
return m_op->isCompleted();
}

void OperatorProxy::setTotalProgressSteps(int progress)
Expand Down
2 changes: 1 addition & 1 deletion tomviz/operators/OperatorProxy.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ class OperatorProxy : public OperatorProxyBase

bool canceled() override;

bool earlyCompleted() override;
bool completed() override;

void setTotalProgressSteps(int progress) override;

Expand Down
20 changes: 10 additions & 10 deletions tomviz/operators/OperatorPython.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ class OperatorPython::OPInternals
Python::Module InternalModule;
Python::Function FindTransformFunction;
Python::Function IsCancelableFunction;
Python::Function IsEarlyCompletableFunction;
Python::Function IsCompletableFunction;
Python::Function DeleteModuleFunction;
};

Expand All @@ -161,10 +161,10 @@ OperatorPython::OperatorPython(DataSource* parentObject)
qCritical() << "Unable to locate is_cancelable.";
}

d->IsEarlyCompletableFunction =
d->InternalModule.findFunction("is_early_completable");
if (!d->IsEarlyCompletableFunction.isValid()) {
qCritical() << "Unable to locate is_early_completeable.";
d->IsCompletableFunction =
d->InternalModule.findFunction("is_completable");
if (!d->IsCompletableFunction.isValid()) {
qCritical() << "Unable to locate is_completable.";
return;
}

Expand Down Expand Up @@ -321,7 +321,7 @@ void OperatorPython::setScript(const QString& str)
m_script = str;

Python::Object result;
Python::Object resultEarlyComplete;
Python::Object resultComplete;
{
Python python;
QString moduleName = QString("tomviz_%1").arg(label());
Expand Down Expand Up @@ -363,15 +363,15 @@ void OperatorPython::setScript(const QString& str)
return;
}

resultEarlyComplete = d->IsEarlyCompletableFunction.call(isArgs);
if (!resultEarlyComplete.isValid()) {
qCritical("Error calling is_early_completable.");
resultComplete = d->IsCompletableFunction.call(isArgs);
if (!resultComplete.isValid()) {
qCritical("Error calling is_completable.");
return;
}
}

setSupportsCancel(result.toBool());
setSupportsEarlyCompletion(resultEarlyComplete.toBool());
setSupportsCompletion(resultComplete.toBool());

emit transformModified();
}
Expand Down
4 changes: 2 additions & 2 deletions tomviz/pybind11/OperatorPythonWrapper.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@ bool OperatorPythonWrapper::canceled()
return m_op->canceled();
}

bool OperatorPythonWrapper::earlyCompleted()
bool OperatorPythonWrapper::completed()
{
return m_op->earlyCompleted();
return m_op->completed();
}

void OperatorPythonWrapper::setTotalProgressSteps(int progress)
Expand Down
2 changes: 1 addition & 1 deletion tomviz/pybind11/OperatorPythonWrapper.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ struct OperatorPythonWrapper
{
OperatorPythonWrapper(void* o);
bool canceled();
bool earlyCompleted();
bool completed();
void setTotalProgressSteps(int progress);
int totalProgressSteps();
void setProgressStep(int progress);
Expand Down
3 changes: 1 addition & 2 deletions tomviz/pybind11/Wrapping.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,7 @@ PYBIND11_PLUGIN(_wrapping)
py::class_<OperatorPythonWrapper>(m, "OperatorPythonWrapper")
.def(py::init([](void* op) { return new OperatorPythonWrapper(op); }))
.def_property_readonly("canceled", &OperatorPythonWrapper::canceled)
.def_property_readonly("early_completed",
&OperatorPythonWrapper::earlyCompleted)
.def_property_readonly("completed", &OperatorPythonWrapper::completed)
.def_property("progress_maximum",
&OperatorPythonWrapper::totalProgressSteps,
&OperatorPythonWrapper::setTotalProgressSteps)
Expand Down
6 changes: 3 additions & 3 deletions tomviz/python/Recon_ART.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import time


class ReconARTOperator(tomviz.operators.EarlyCompletableOperator):
class ReconARTOperator(tomviz.operators.CompletableOperator):

def transform(self, dataset, Niter=1, Nupdates=0, beta=1.0):
"""
Expand Down Expand Up @@ -58,13 +58,13 @@ def transform(self, dataset, Niter=1, Nupdates=0, beta=1.0):
counter = 1
for i in range(Niter):

if self.early_completed:
if self.completed:
break

for s in range(Nslice):
if self.canceled:
return
elif self.early_completed:
elif self.completed:
break

self.progress.message = 'Iteration No.%d/%d,Slice No.%d/%d.' % (
Expand Down
6 changes: 3 additions & 3 deletions tomviz/python/Recon_SIRT.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import time


class ReconSirtOperator(tomviz.operators.EarlyCompletableOperator):
class ReconSirtOperator(tomviz.operators.CompletableOperator):

def transform(self, dataset, Niter=10, stepSize=0.0001,
updateMethodIndex=0, Nupdates=0):
Expand Down Expand Up @@ -65,14 +65,14 @@ def transform(self, dataset, Niter=10, stepSize=0.0001,

for i in range(Niter):

if self.early_completed:
if self.completed:
break

for s in range(Nslice):

if self.canceled:
return
elif self.early_completed:
elif self.completed:
break

self.progress.message = 'Iteration No.%d/%d,Slice No.%d/%d.' % (
Expand Down
6 changes: 3 additions & 3 deletions tomviz/python/Recon_TV_minimization.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import time


class ReconTVOperator(tomviz.operators.EarlyCompletableOperator):
class ReconTVOperator(tomviz.operators.CompletableOperator):

def transform(self, dataset, Niter=10, Nupdates=0): # noqa
"""3D Reconstruct from a tilt series using simple TV minimzation"""
Expand Down Expand Up @@ -55,7 +55,7 @@ def transform(self, dataset, Niter=10, Nupdates=0): # noqa

for i in range(Niter): #main loop

if self.early_completed:
if self.completed:
break

recon_temp = recon.copy()
Expand All @@ -64,7 +64,7 @@ def transform(self, dataset, Niter=10, Nupdates=0): # noqa
for s in range(Nslice): #
if self.canceled: #In case canceled during ART.
return
elif self.early_completed:
elif self.completed:
break

self.progress.message = 'Slice No.%d/%d, Iteration No.%d/%d. '\
Expand Down
4 changes: 2 additions & 2 deletions tomviz/python/tomviz/_internal.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ def is_cancelable(transform_module):
tomviz.operators.CancelableOperator)


def is_early_completable(transform_module):
def is_completable(transform_module):
cls = find_operator_class(transform_module)

if cls is None:
Expand All @@ -92,7 +92,7 @@ def is_early_completable(transform_module):

return cls is not None and issubclass(
cls,
tomviz.operators.EarlyCompletableOperator
tomviz.operators.CompletableOperator
)


Expand Down
10 changes: 5 additions & 5 deletions tomviz/python/tomviz/operators.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,19 +114,19 @@ def canceled(self):
return self._operator_wrapper.canceled


class EarlyCompletableOperator(CancelableOperator):
class CompletableOperator(CancelableOperator):
"""
An early completable operator allows a user to interrupt the execution of
an operator using either "cancel" or "early complete". The early
A completable operator allows a user to interrupt the execution of
an operator using either "cancel" or "complete". The
completable property can be used in the transform(...) method to break out
when an operator is finished early, like if an iterative algorithm is a
reasonable quality before the designated iterations are reached. Use
similar to "cancel", but be sure to return data.
"""
@property
def early_completed(self):
def completed(self):
"""
:returns True if the operator is early completed (from Button),
False otherwise
"""
return self._operator_wrapper.early_completed
return self._operator_wrapper.completed

0 comments on commit 610cc03

Please sign in to comment.