46 #include "Exceptions.hpp" 49 #include <QVBoxLayout> 60 BaseWidget(parent,
"AngleCorrectionWidget",
"Angle Correction"),
61 mVerticalLayout(new QVBoxLayout(this)),
63 mVisServices(visServices)
65 mSettings =
profile()->getXmlSettings().descend(
"angleCorr");
66 connect(mVisServices->patient().get(), SIGNAL(patientChanged()),
this, SLOT(
patientChangedSlot()));
67 this->setWhatsThis(this->defaultWhatsThis());
70 mClDataSelectWidget->setUidRegexp(
"tsf_cl(?!.*angleCorr).*");
71 mClDataSelectWidget->setValueName(
"Centerline: ");
72 mVerticalLayout->addWidget(
new DataSelectWidget(mVisServices->view(), mVisServices->patient(),
this, mClDataSelectWidget));
73 connect(mClDataSelectWidget.get(), SIGNAL(changed()),
this, SLOT(
cLDataChangedSlot()));
74 connect(mClDataSelectWidget.get(), SIGNAL(changed()),
this, SLOT(step1ParamChangedSlot()));
77 mOptionsWidget = this->createOptionsWidget();
78 mOptionsWidget->setVisible(
settings()->value(
"AngleCorr/AngleCorrShowDetails").toBool());
79 mVerticalLayout->addWidget(mOptionsWidget);
82 QIcon(
":/icons/open_icon_library/system-run-5.png"),
83 "Details",
"Show angle correction settings",
87 mRunAngleCorrButton =
new QPushButton(
"Angle correct",
this);
89 mVerticalLayout->addWidget(mRunAngleCorrButton);
92 mOutDataSelectWidget->setUidRegexp(
"angleCorr");
93 mOutDataSelectWidget->setValueName(
"Output: ");
94 mVerticalLayout->addWidget(
new DataSelectWidget(mVisServices->view(), mVisServices->patient(),
this, mOutDataSelectWidget));
97 connect(mExecuter.get(), SIGNAL(finished()),
this, SLOT(executionFinished()));
98 connect(mExecuter.get(), SIGNAL(aboutToStart()),
this, SLOT(preprocessExecuter()));
100 mTimedAlgorithmProgressBar->
attach(mExecuter);
101 mVerticalLayout->addWidget(mTimedAlgorithmProgressBar);
103 mVerticalLayout->addStretch();
107 mOptionsWidget->setVisible(
false);
111 mStep1ParamChanged=
true;
122 QString AngleCorrectionWidget::defaultWhatsThis()
const 125 "<h3>AngleCorrection plugin.</h3>" 126 "<p>Angle correct velocities from ultrasound acquisitons</p>" 132 QString dataFilename = mVisServices->patient()->getActivePatientFolder() +
"/US_Acq/";
133 mVelFileSelectWidget->
setPath(dataFilename);
138 if(!mClDataSelectWidget->getMesh()){
141 QString clUid = mClDataSelectWidget->getMesh()->getUid().section(
"_",1,2 );
142 QStringList files=mVelFileSelectWidget->
getAllFiles();
143 for (
int i = 0; i < files.size(); ++i)
145 if(files.at(i).contains(clUid))
153 mOptionsWidget->setVisible(
true);
157 void AngleCorrectionWidget::step1ParamChangedSlot()
159 mStep1ParamChanged=
true;
162 void AngleCorrectionWidget::step2ParamChangedSlot()
164 if(mStep1ParamChanged)
return;
166 if(!mExecuter->calculate(
false))
return;
167 vtkSmartPointer<vtkPolyData> output = mExecuter->getOutput();
168 mOutData->setVtkPolyData(output);
169 report(QString(
"Angle correction updated"));
174 if (filename.isEmpty())
180 step1ParamChangedSlot();
185 mOptionsWidget->setVisible(!mOptionsWidget->isVisible());
186 settings()->
setValue(
"AngleCorr/AngleCorrShowDetails", mOptionsWidget->isVisible());
189 QWidget* AngleCorrectionWidget::createOptionsWidget()
191 QWidget* retval =
new QWidget(
this);
192 QGridLayout* layout =
new QGridLayout(retval);
193 layout->setMargin(0);
200 QLabel* velLabel =
new QLabel(
"Velocity data:");
201 layout->addWidget(velLabel,line,0);
205 mVelFileSelectWidget->
setNameFilter(QStringList() <<
"*Velocity.fts");
206 layout->addWidget(mVelFileSelectWidget,line,1);
209 layout->addWidget(
new QLabel(
"Centerline smoothing:",
this), line, 0);
212 connect(mClSmoothing.get(), SIGNAL(changed()),
this, SLOT(step1ParamChangedSlot()));
213 layout->addWidget(
createDataWidget(mVisServices->view(), mVisServices->patient(),
this, mClSmoothing), line, 1);
216 layout->addWidget(
new QLabel(
"Max angle cut off [deg]:",
this), line, 0);
219 connect(mMaxThetaCutoff.get(), SIGNAL(changed()),
this, SLOT(step1ParamChangedSlot()));
220 layout->addWidget(
createDataWidget(mVisServices->view(), mVisServices->patient(),
this, mMaxThetaCutoff), line, 1);
223 layout->addWidget(
new QLabel(
"FLow direction certainty cut off:",
this), line, 0);
226 connect(mUncertaintyLimit.get(), SIGNAL(changed()),
this, SLOT(step2ParamChangedSlot()));
227 layout->addWidget(
createDataWidget(mVisServices->view(), mVisServices->patient(),
this, mUncertaintyLimit), line, 1);
230 layout->addWidget(
new QLabel(
"Min arrow dist. [mm]:",
this), line, 0);
233 connect(mMinArrowDist.get(), SIGNAL(changed()),
this, SLOT(step2ParamChangedSlot()));
234 layout->addWidget(
createDataWidget(mVisServices->view(), mVisServices->patient(),
this, mMinArrowDist), line, 1);
248 mMinArrowDist->setValue(value);
253 mUncertaintyLimit->setValue(value);
258 mMaxThetaCutoff->setValue(value);
263 mClSmoothing->setValue(value);
273 mClDataSelectWidget->setValue(value);
279 return mExecuter->isRunning();
286 if(!mClDataSelectWidget->getMesh()){
290 QString clFilename =QDir(mVisServices->patient()->getActivePatientFolder()).filePath(mClDataSelectWidget->getMesh()->getFilename());
292 QString dataFilename = mVelFileSelectWidget->
getFilename();
293 if(dataFilename.length() ==0){
295 mOptionsWidget->setVisible(
true);
298 dataFilename.replace(
".fts",
"_");
299 double cutoff = cos(mMaxThetaCutoff->getValue()/180.0*
M_PI);
300 int nConvolutions = (int) mClSmoothing->getValue();
301 double uncertainty_limit = mUncertaintyLimit->getValue();
302 double minArrowDist = mMinArrowDist->getValue();
304 mExecuter->setInput(clFilename, dataFilename, mVNyq, cutoff, nConvolutions, uncertainty_limit, minArrowDist);
307 void AngleCorrectionWidget::preprocessExecuter()
310 mRunAngleCorrButton->setEnabled(
false);
315 mExecuter->execute();
318 void AngleCorrectionWidget::executionFinished()
320 mRunAngleCorrButton->setEnabled(
true);
321 vtkSmartPointer<vtkPolyData> output = mExecuter->getOutput();
324 reportError(
"Invalid output from anglecorrection algorithm");
327 if (mExecuter->getNumOfStepsRan() > 1)
329 mUid = mClDataSelectWidget->getMesh()->getUid() +
"_angleCorr%1";
330 mName = mClDataSelectWidget->getMesh()->getName()+
" angleCorr%1";
331 mOutData = mVisServices->patient()->createSpecificData<
Mesh>(mUid, mName);
332 mOutData->get_rMd_History()->setParentSpace(mClDataSelectWidget->getMesh()->getUid());
335 mOutData->setVtkPolyData(output);
337 mVisServices->patient()->insertData(mOutData);
338 mVisServices->view()->autoShowData(mOutData);
339 mOutDataSelectWidget->setValue(mOutData->getUid());
340 mStep1ParamChanged=
false;
cxResource_EXPORT ProfilePtr profile()
void reportError(QString msg)
boost::shared_ptr< class VisServices > VisServicesPtr
Utility class for describing a bounded numeric range.
Show progress for a TimedBaseAlgorithm.
QDomElement getElement()
return the current element
QWidget * createDataWidget(ViewServicePtr viewService, PatientModelServicePtr patientModelService, QWidget *parent, PropertyPtr data, QGridLayout *gridLayout, int row)
Create a widget capable of displaying the input data.
void setValue(const QString &key, const QVariant &value)
void reportWarning(QString msg)
Settings * settings()
Shortcut for accessing the settings instance.
void attach(TimedAlgorithmPtr algorithm)
static DoublePropertyPtr initialize(const QString &uid, QString name, QString help, double value, DoubleRange range, int decimals, QDomNode root=QDomNode())
static StringPropertySelectMeshPtr New(PatientModelServicePtr patientModelService)
boost::shared_ptr< class Mesh > MeshPtr
Namespace for all CustusX production code.