void medJobRunner::run()
{
    emit m_job->running(true);
    medAbstractJob::medJobExitStatus jobExitStatus = medAbstractJob::MED_JOB_EXIT_FAILURE;
    try
    {
        jobExitStatus = m_job->run();
        if(jobExitStatus == medAbstractJob::MED_JOB_EXIT_CANCELLED)
        {
            dtkDebug() << "job aborted (cancelled)"
                       << m_job->caption() << m_job;
        }
    }
    catch(std::exception &err)
    {
        QString errorMessage = QString::fromLatin1(err.what());
        dtkWarn() << "Error occured while runing job"
                  << m_job->caption() << m_job
                  << "\n\t" <<errorMessage;

        emit exceptionCaught(errorMessage);
    }
    catch(...)
    {
        dtkWarn() << "Error occured while runing job"
                  << m_job->caption() << m_job;
    }
    emit m_job->finished(jobExitStatus);
    emit m_job->running(false);
}
void dtkComposerNodeVectorRealExtractor::run(void)
{
    if (!d->receiver_vector.isEmpty() && !d->receiver_index.isEmpty()) {

        dtkVectorReal *vector = d->receiver_vector.data();
        qlonglong index = *d->receiver_index.data();

        if (!vector) {
            dtkError() << "Input vector is not defined.";
            return;
        }

        if (index >= vector->size()) {
            dtkWarn() << "index > size of the input vector. Zero is returned.";
            d->value = 0;

        } else {
            d->value = (*vector)[index];

        }

    } else {
        dtkWarn() << "Inputs not specified. Zero is returned.";
        d->value = 0;
    }        
}
void dtkComposerNodeArrayScalarOperatorDivide::run(void)
{
    if (!d->receiver_array.isEmpty() && !d->receiver_index.isEmpty() && !d->receiver_value.isEmpty() ) {

        dtkContainerVectorReal *array = d->receiver_array.data();

        if (!array) {
            dtkError() << "Input array is not defined.";
            d->emitter_array.clearData();
            return;
        }

        qlonglong index = *d->receiver_index.data<qlonglong>();
        qreal value = *d->receiver_value.data<qreal>();

        if (index >= array->count()) {
            dtkWarn() << "index > size of the vector. Same array is returned.";

        } else {
            if (value == 0)
                dtkWarn() << "Value is zero. Same array is returned." ;

            else
                (*array)[index] /= value;

        }

        d->emitter_array.setData(array);

    } else {
        dtkWarn() << "Inputs not specified. Nothing is done";
        d->emitter_array.clearData();
    }
}
void dtkComposerGraphView::update(void)
{
    if (!d->graphviz_avail)
        return;

    QByteArray content = d->graph->toString().append("\n").toLocal8Bit() ;
    // run dot
    QStringList arglist;
    arglist << "-Tsvg";
    QString command = "dot";
    QProcess cmd;
    QStringList PATH =  QProcessEnvironment::systemEnvironment().value("PATH").split(":") ;
    QDir::setSearchPaths("bin",PATH);
    if(QFile("bin:"+command).exists()) {

        dtkTrace() << "run graphviz dot" ;
        cmd.start(command, arglist, QProcess::Unbuffered | QProcess::ReadWrite);
        cmd.write(content);
        cmd.closeWriteChannel();
        cmd.waitForBytesWritten();
        qlonglong timeout = 3000;
        QString stdout_data;
        if (cmd.waitForFinished(timeout)) {
            QByteArray svg = cmd.readAllStandardOutput();
            this->load(svg);
        } else {
            dtkWarn() << "graphviz timeout !";
        }
    } else {
        d->graphviz_avail = false;
        dtkWarn() << "can't find 'dot' binary in PATH, graphviz probably not installed";
    }
}
void dtkComposerNodeArrayScalarOperatorModifierAllDivide::run(void)
{
    if (!d->receiver_array.isEmpty() && !d->receiver_value.isEmpty() ) {

        dtkContainerVectorReal *array = d->receiver_array.data();

        if (!array) {
            dtkError() << "Input array is not defined.";
            d->emitter_array.clearData();
            return;
        }

        qreal value = *d->receiver_value.data<qreal>();

        if (value == 0) {
            dtkWarn() << "Value is zero. Same array is returned." ;

        } else {
            for(qlonglong i = 0 ; i < array->count(); ++i)
                (*array)[i] /= value ;

        }

        d->emitter_array.setData(array);

    } else {
        dtkWarn() << "Inputs not specified. Nothing is done";
        d->emitter_array.clearData();
    }
}
bool undoRedoRegistrationPlugin::initialize(void)
{
    if (!undoRedoRegistration::registered())        { dtkWarn() << "Unable to register undoRedoRegistration type";    }
    if (!undoRedoRegistrationToolBox::registered()) { dtkWarn() << "Unable to register undoRedoRegistration toolbox"; }
    
    return true;
}
QByteArray dtkDistributedServerDaemon::waitForData(int rank, QString jobid)
{
    dtkDistributedSocket *socket = d->sockets.value(qMakePair(rank, jobid), NULL);

    if(!socket) {
        dtkWarn() << "No socket found for rank " << rank;
        return QByteArray();
    }

    socket->blockSignals(true);

    dtkDistributedMessage *data = NULL;

    if (socket->waitForReadyRead(30000))
        data = socket->parseRequest();
    else
        dtkWarn() << "Data not ready for rank " << rank;

    socket->blockSignals(false);

    if (data) {
        return data->content();
    } else {
        dtkWarn() << "Message not allocated - return void QByteArray";
        return QByteArray();
    }
}
Exemple #8
0
bool medVtkViewPlugin::initialize()
{
    if (!medVtkView::registered()) { dtkWarn() << "Unable to register medVtkView type"; }

    if (!medVtkViewNavigator::registered()) { dtkWarn() << "Unable to register medVtkViewNavigator type"; }

    return true;
}
Exemple #9
0
itkPhilipsRECDataImageReader::FloatImageType::PointType itkPhilipsRECDataImageReader::ExtractPARRECImageOrigin (
        FloatImageType::DirectionType direction)
{
    typedef FloatImageType::PointType PointType;
    PointType nullorigin;
    nullorigin[0] = nullorigin[1] = nullorigin[2] = 0.0;

    if (!this->io->GetFileName())
    {
        dtkWarn() << "io doesn't have a filename, call readInformation first";
        return nullorigin;
    }

    itk::MetaDataDictionary PARheader = this->io->GetMetaDataDictionary();

    typedef itk::PhilipsRECImageIO::OffCentreMidSliceType OffCentreType;

    OffCentreType offcenter;

    bool valid = itk::ExposeMetaData<OffCentreType>(PARheader, "PAR_OffCentreMidSlice", offcenter);
    if (!valid)
    {
        dtkWarn() << "cannot find off-center information in PAR header, no correction";
        return nullorigin;
    }

    double dimensions[3];
    dimensions[0] = this->io->GetDimensions (0);
    dimensions[1] = this->io->GetDimensions (1);
    dimensions[2] = this->io->GetDimensions (2);

    FloatImageType::SpacingType midoffset;
    midoffset[0] = this->io->GetSpacing (0) * (dimensions[0] - 1) / 2.0;
    midoffset[1] = this->io->GetSpacing (1) * (dimensions[1] - 1) / 2.0;
    midoffset[2] = this->io->GetSpacing (2) * (dimensions[2] - 1) / 2.0;
    midoffset = direction * midoffset;

    PointType offcenterpoint;
    offcenterpoint[0] = offcenter[0];
    offcenterpoint[1] = offcenter[1];
    offcenterpoint[2] = offcenter[2];

    FloatImageType::DirectionType AFRtoLPS;
    AFRtoLPS.Fill (0);
    AFRtoLPS[0][2] = 1;
    AFRtoLPS[1][0] = 1;
    AFRtoLPS[2][1] = 1;

    offcenterpoint = AFRtoLPS * offcenterpoint;
    offcenterpoint -= midoffset;

    return offcenterpoint;
}
bool itkN4BiasCorrectionPlugin::initialize()
{
    if(!itkN4BiasCorrection::registered())
    {
        dtkWarn() << "Unable to register itkN4BiasCorrection type";
    }

    if ( !itkN4BiasCorrectionToolBox::registered() )
    {
        dtkWarn() << "Unable to register itkN4BiasCorrection toolbox";
    }
    return true;
}
bool iterativeClosestPointPlugin::initialize()
{
    if(!iterativeClosestPointProcess::registered())
    {
        dtkWarn() << "Unable to register iterativeClosestPoint type";
    }
    
    if(!iterativeClosestPointToolBox::registered())
    {
        dtkWarn() << "Unable to register iterativeClosestPoint toolbox";
    }
    
    return true;
}
bool manualRegistrationPlugin::initialize()
{
    if(!manualRegistration::registered())
    {
        dtkWarn() << "Unable to register manualRegistration type";
    }
    
    if ( !manualRegistrationToolBox::registered() )
    {
        dtkWarn() << "Unable to register manualRegistration toolbox";
    }
    
    return true;
}
bool MyPluginPlugin::initialize(void)
{
    MyPluginPlugin::dataFactSingleton = dtkAbstractDataFactory::instance();
    //dataFactorySingleton();
    MyPluginPlugin::processFactSingleton = dtkAbstractProcessFactory::instance();
    //processFactorySingleton();
    
    if(!MyPluginDefaultProcess::registered())
        dtkWarn() << "Unable to register MyPluginProcess type";
    
    if(!MyPluginDefaultProcessDialog::registered())
        dtkWarn() << "Unable to register MyPluginProcessDialog type";
    
    if(!MyPluginDefaultData::registered())
        dtkWarn() << "Unable to register MyPluginData type";
    
    if(!MyPluginDefaultDataDialog::registered())
        dtkWarn() << "Unable to register MyPluginDataDialog type";
    
    if(!MyPluginDefaultDataReader::registered())
        dtkWarn() << "Unable to register MyPluginDataReader type";
    
    if(!MyPluginDefaultDataWriter::registered())
        dtkWarn() << "Unable to register MyPluginDataWriter type";
    
    if(!MyPluginDefaultDataConverter::registered())
        dtkWarn() << "Unable to register MyPluginDataConverter type";
    
    if(!MyPluginDefaultDataCreatorProcessDialog::registered())
        dtkWarn() << "Unable to register MyPluginDataCreatorProcessDialog type";
    
    return true;
}
void dtkComposerNodeStringListSet::run(void)
{
    if (!d->receiver_list.isEmpty() && !d->receiver_value.isEmpty()&& !d->receiver_index.isEmpty()  ) {
        d->list = *(d->receiver_list.data());
        qlonglong index = d->receiver_index.data();
         if (index >= 0 && index < d->list.size())
             d->list.replace(index, d->receiver_value.data());
         else
             dtkWarn() << "bad index value in set string list" << index;
    } else {
        dtkWarn() << "Inputs not specified. Nothing is done";
        d->emitter.clearData();
    }

}
Exemple #15
0
bool itkDataTensorImageWriterBase::write(const QString& path)
{
    if (!this->data())
        return false;

    if (this->io.IsNull())
        return false;

    if (medAbstractData *medData = dynamic_cast<medAbstractData*>(this->data()) ) {

        if(medData->identifier()=="itkDataTensorImageFloat3") {

            float dummy = 0;
            write(path, dummy);
        }

        else if(medData->identifier()=="itkDataTensorImageDouble3") {

            double dummy = 0;
            write(path, dummy);
        }

        else {
            dtkWarn() << "Unrecognized pixel type";
            return false;
        }
    }

    return true;
}
Exemple #16
0
void medRegistrationWorkspace::updateFromRegistrationSuccess(medAbstractData *output)
{
    if(!d->registrationToolBox)
        return;

    //TODO disconnect because we dont want to change input of the undo redo process.
    //  find a better way to do it ? - RDE
    d->movingContainer->disconnect(this);

    d->movingContainer->removeView();
    d->movingContainer->addData(output);

    d->fuseContainer->removeView();
    d->fuseContainer->addData(d->registrationToolBox->fixedData());
    d->fuseContainer->addData(output);


    // Relink the views...
    medAbstractLayeredView* movingView  = dynamic_cast<medAbstractLayeredView*>(d->movingContainer->view());
    if(!movingView)
    {
        dtkWarn() << "Non layered view are not suported yet in registration workspace.";
        return;
    }


    medAbstractLayeredView* fuseView  = dynamic_cast<medAbstractLayeredView*>(d->fuseContainer->view());
    if(!fuseView)
    {
        dtkWarn() << "Non layered view are not suported yet in registration workspace.";
        return;
    }

    d->viewGroup->addImpactedView(movingView);
    d->viewGroup->addImpactedView(fuseView);
    d->viewGroup->removeParameter("DataList");

    d->movingLayerGroup->addImpactedlayer(movingView, output);
    d->movingLayerGroup->addImpactedlayer(fuseView, output);

    connect(d->movingContainer,SIGNAL(viewContentChanged()),
            this, SLOT(updateFromMovingContainer()));

    connect(d->movingContainer,SIGNAL(viewRemoved()),
            this, SLOT(updateFromMovingContainer()));
}
Exemple #17
0
bool itkDataDiffusionGradientListPlugin::initialize()
{
    if (!itkDataDiffusionGradientList::registered()) {
        dtkWarn() << "Unable to register itkDataDiffusionGradientList type";
    }

    return true;
}
Exemple #18
0
void medRegistrationWorkspace::updateFromFixedContainer()
{
    if(!d->registrationToolBox)
        return;

    if(!d->fixedContainer->view())
    {
        medAbstractLayeredView* fuseView  = dynamic_cast<medAbstractLayeredView*>(d->fuseContainer->view());
        if(fuseView)
        {
            if(fuseView->layer(d->registrationToolBox->fixedData()) == 0)
            {
                d->fuseContainer->removeView();
                d->fuseContainer->addData(d->registrationToolBox->movingData());
            }
            else
                fuseView->removeLayer(1);

        }

        d->registrationToolBox->setFixedData(NULL);
        return;
    }

    medAbstractLayeredView* fixedView  = dynamic_cast<medAbstractLayeredView*>(d->fixedContainer->view());
    if(!fixedView)
    {
        dtkWarn() << "Non layered view are not suported yet in registration workspace.";
        return;
    }

    medAbstractData *fixedData = fixedView->layerData(fixedView->currentLayer());
    medAbstractLayeredView* fuseView  = dynamic_cast<medAbstractLayeredView*>(d->fuseContainer->view());
    if(fuseView)
        fuseView->removeData(fixedData);

    d->fuseContainer->addData(fixedData);
    fuseView  = dynamic_cast<medAbstractLayeredView*>(d->fuseContainer->view());

    if(fixedData)
    {
        d->viewGroup->addImpactedView(fixedView);
        d->viewGroup->addImpactedView(fuseView);
        d->viewGroup->removeParameter("DataList");

        d->fixedLayerGroup->addImpactedlayer(fixedView, fixedData);
        d->fixedLayerGroup->addImpactedlayer(fuseView, fixedData);
    }

    if (!d->registrationToolBox->setFixedData(fixedData))
    {
        // delete the view because something failed at some point
        d->viewGroup->removeImpactedView(fixedView);
        d->fixedLayerGroup->removeImpactedlayer(fixedView, fixedData);
        d->fixedLayerGroup->removeImpactedlayer(fuseView, fixedData);
        fixedView->deleteLater();
    }
}
bool itkDataSHImageWriterPlugin::initialize()
{
    if(!itkMetaDataSHImageWriter::registered())
    {
        dtkWarn() << "Unable to register itkMetaDataSHImageWriter type";
    }

    return true;
}
void dtkComposerNodeMetaContainerAt::run(void)
{
    if(!d->receiver_container.isEmpty()) {
        QVariant var_container = d->receiver_container.data();
        dtkMetaContainerSequential m_c = var_container.value<dtkMetaContainerSequential>();
        if(!d->receiver_index.isEmpty()) {
            d->emitter_value.setData(m_c.at(d->receiver_index.data()));

        } else {
            dtkWarn() << "No input index for the at operation. First item of the container is returned.";
            d->emitter_value.setData(m_c.at(0));
        }

    } else {
        dtkWarn() << "No input container for at operation. Nothing is emitted.";
        d->emitter_value.clearData();
    }
}
inline void deref(int index, QString & s, const QRegExp & regex, const QHash<QString, QString> & vars, int lineCount) {
    QString varName = regex.cap(1).isEmpty() ? regex.cap(2) : regex.cap(1);
    if (vars.contains(varName)) {
        s.replace(index, regex.matchedLength(), vars[varName]);
    } else {
        s.replace(index, regex.matchedLength(), "");
        dtkWarn() << "Unknown variable name line " << lineCount << " :" << varName;
    }
}
// set method, and also, if necessary, jobid and rank
void dtkDistributedMessage::setMethod(QString method)
{
    QStringList tokens = QString(method).split(QRegExp("/"));
    if (method.startsWith("GET /status")) {
        d->method = STATUS;
    } else if (method.startsWith("PUT /job HTTP")) {
        d->method = NEWJOB;
    } else if (method.startsWith("DELETE /job")) {
        d->jobid  = tokens[2].remove("HTTP").trimmed();
        if (d->headers.contains("x-dtk-finished")) {
            d->method = ENDJOB;
        } else {
            d->method = DELJOB;
        }
    } else if (method.startsWith("DELETE /")) {
        d->method = STOP;
    } else if (method.startsWith("POST /data")) {
        d->method = DATA;
        d->jobid  = tokens[2];
        if (tokens.size() > 2)
            d->rank  = tokens[3].remove("HTTP").toInt();
    } else if (method.startsWith("PUT /rank")) {
        d->method = SETRANK;
        d->jobid  = tokens[2];
        d->rank   = tokens[3].remove("HTTP").toInt();
    } else if (method.startsWith("HTTP/1.1 200 OK")) {
        if (d->headers.contains("x-dtk-status")) {
            d->method = OKSTATUS;
        } else {
            dtkWarn() << "Unsupported method " << method;
        }
    } else if (method.startsWith("HTTP/1.1 201 OK")) {
        d->method = OKJOB;
    } else if (method.startsWith("HTTP/1.1 204 OK")) {
        d->method = OKDEL;
    } else if (method.startsWith("HTTP/1.1 400 OK")) {
        d->method = ERRORJOB;
    } else if (method.startsWith("HTTP/1.1 410 OK")) {
        d->method = ERRORDEL;
    } else {
        dtkWarn() << "Unsupported method " << method;
    }

}
bool exampleProcessImageFilterPlugin::initialize() {

    //  Register the process

    if (!exampleProcessImageFilter::registered())
        dtkWarn() << "Unable to register exampleProcessImageFilter type";
    else
        dtkWarn() << "ABLE to register exampleProcessImageFilter type";

    //  Register the toolbox of the process with the Custon diffusionToolBox

    if (!medToolBoxFactory::instance()->registerToolBox
            <exampleProcessImageFilterToolBox>("exampleProcessImageFilter", name(), description(), QStringList()<<"diffusion"))
        qDebug() << "Unable to register exampleProcessImageFilter toolbox";
    else
        qDebug() << "ABLE to register exampleProcessImageFilter toolbox";

    return true;
}
void dtkComposerNodeVectorRealExtractorSubVector::run(void)
{
    if (!d->receiver_vector.isEmpty() && !d->receiver_from.isEmpty()) {

        dtkVectorReal *vector = d->receiver_vector.data();

        if (!vector) {
            dtkError() << DTK_PRETTY_FUNCTION << "Input vector is not defined.";
            d->emitter_subvector.clearData();
            return;
        }

        qlonglong from = *d->receiver_from.data();
        if (from >= vector->size()) {
            dtkWarn() << DTK_PRETTY_FUNCTION << "Starting value from is greater than vector size:" << from << ">=" << vector->size();
            d->emitter_subvector.clearData();
            return;
        }

        qlonglong length = vector->size();
        if (!d->receiver_length.isEmpty())
            length = *d->receiver_length.data();

        if (length < 0) {
            dtkWarn() << DTK_PRETTY_FUNCTION << "Length value is negative:" << length << "<" << 0;
            d->emitter_subvector.clearData();
            return;
        }

        qlonglong to = qMin((from + length), static_cast<qlonglong>(vector->size()));
        qlonglong size = to - from;
        
        if (d->subvector->size() != size)
            d->subvector->allocate(size);
        
        for(qlonglong i = from, count = 0; i < to; ++i, ++count)
            (*d->subvector)[count] = (*vector)[i];

    } else {
        dtkWarn() << DTK_PRETTY_FUNCTION << "Inputs not specified. Nothing is done";
        d->emitter_subvector.clearData();
    }
}
bool itkDataTensorImagePlugin::initialize()
{
    if (!itkDataTensorImageDouble3::registered()) { dtkWarn() << "Unable to register itkDataTensorImageDouble3 type"; }
    if (!itkDataTensorImageFloat3::registered())  { dtkWarn() << "Unable to register itkDataTensorImageFloat3 type";  }
    if (!itkDataTensorImageVtkViewInteractor::registered())  { dtkWarn() << "Unable to register itkDataTensorImageVtkViewInteractor type";  }

    if (!itkMetaDataTensorImageWriter::registered())  { dtkWarn() << "Unable to register itkMetaDataTensorImageWriter type";  }
    if (!itkNiftiDataTensorImageWriter::registered()) { dtkWarn() << "Unable to register itkNiftiDataTensorImageWriter type"; }
    if (!itkNrrdDataTensorImageWriter::registered())  { dtkWarn() << "Unable to register itkNrrdDataTensorImageWriter type";  }

    if (!itkMetaDataTensorImageReader::registered())  { dtkWarn() << "Unable to register itkMetaDataTensorImageReader type";  }
    if (!itkNiftiDataTensorImageReader::registered()) { dtkWarn() << "Unable to register itkNiftiDataTensorImageReader type"; }
    if (!itkNrrdDataTensorImageReader::registered())  { dtkWarn() << "Unable to register itkNrrdDataTensorImageReader type";  }

    return true;
}
bool medVtkFibersDataPlugin::initialize()
{
    if (!medVtkFibersData::registered()) {
        dtkWarn() << "Unable to register medVtkFibersData type";
    }

    if (!medVtkFibersDataWriter::registered()) {
        dtkWarn() << "Unable to register medVtkFibersDataWriter type";
    }

    if (!medVtkFibersDataReader::registered()) {
        dtkWarn() << "Unable to register medVtkFibersDataReader type";
    }

    if (!medVtkFibersDataInteractor::registered()) {
        dtkWarn() << "Unable to register medVtkFibersDataInteractor";
    }

    return true;
}
bool reformatPlugin::initialize()
{
    if(!medReformatWorkspace::registered())
    {
        dtkWarn() << "Unable to register medReformatWorkspace type";
    }
    if (!resliceToolBox::registered())
    {
        dtkWarn() << "Unable to register resliceToolBox type";
    }
    if (!medCropToolBox::registered())
    {
        dtkWarn() << "Unable to register medCropToolBox type";
    }
    if (!resampleProcess::registered())
    {
        dtkWarn() << "Unable to register resample process";
    }
    return true;
}
void dtkComposerNodeVectorIntegerOperatorUnaryScalarNorm::run(void)
{
    if (d->receiver_vec.isEmpty()){
        dtkWarn() << "Input not specified. Nothing is done";
        d->value = -1.;

    } else {
        d->value = d->receiver_vec.data()->norm();
    }

}
void dtkComposerNodeStringListExtract::run(void)
{
    if (!d->receiver_list.isEmpty() && !d->receiver_index.isEmpty() ) {
        QStringList *list = d->receiver_list.data();
        d->value = list->at(d->receiver_index.data());
        d->emitter.setData(d->value);
    } else {
        dtkWarn() << "Inputs not specified. Nothing is done";
        d->emitter.clearData();
    }
}
void dtkComposerNodeMetaContainerAppend::run(void)
{
    if(!d->receiver_container.isEmpty()) {
        QVariant var_container = d->receiver_container.data();

        if(!d->receiver_value.isEmpty()) {
            dtkMetaContainerSequential m_c = var_container.value<dtkMetaContainerSequential>();
            m_c.append(d->receiver_value.data());

        } else {
            dtkWarn() << "No input value to append to the container. The container is not modified.";
        }

        d->emitter_container.setData(var_container);

    } else {
        dtkWarn() << "No input container for append operation. Nothing is emitted.";
        d->emitter_container.clearData();
    }
}