Example #1
0
void NegatoOneSlice::doUpdate(::fwServices::ObjectMsg::csptr msg) throw(::fwTools::Failed)
{
    SLM_TRACE_FUNC();

    if ( msg->hasEvent( ::fwComEd::ImageMsg::CHANGE_SLICE_TYPE ))
    {
        ::fwData::Object::csptr cObjInfo = msg->getDataInfo( ::fwComEd::ImageMsg::CHANGE_SLICE_TYPE );
        ::fwData::Object::sptr objInfo = ::boost::const_pointer_cast< ::fwData::Object > ( cObjInfo );
        ::fwData::Composite::sptr info = ::fwData::Composite::dynamicCast ( objInfo );

        int fromSliceType = ::fwData::Integer::dynamicCast( info->getContainer()["fromSliceType"] )->value();
        int toSliceType =   ::fwData::Integer::dynamicCast( info->getContainer()["toSliceType"] )->value();

        if( toSliceType == static_cast<int>(m_orientation) )
        {
            setOrientation( static_cast< Orientation >( fromSliceType ));
        }
        else if(fromSliceType == static_cast<int>(m_orientation))
        {
            setOrientation( static_cast< Orientation >( toSliceType ));
        }
    }
    else
    {
        this->doStop();
        this->doStart();
        this->doUpdate();
    }
}
void ImageFromPDBSelectorUpdaterSrv::updating( ::fwServices::ObjectMsg::csptr _msg ) throw ( ::fwTools::Failed )
{
    ::fwData::Composite::sptr composite = this->getObject< ::fwData::Composite >();
    for (   ManagedEvents::iterator it = m_managedEvents.begin();
            it != m_managedEvents.end();
            ++it )
    {
        // First element of tuple ( it->get<0>() ) is the event, test if message correspond to a defined event
        if( _msg->hasEvent( it->get<0>() ) )
        {
            ::fwData::Object::sptr obj = ::fwData::Object::dynamicCast( _msg->getSubject().lock() );
            SLM_ASSERT(obj,"Sorry, the subject of message is not a ::fwData::Object");

            // Test if we manage this event from this object message uid ( it->get<1>() )
            if( obj->getID() == it->get<1>() )
            {
                ::fwData::PatientDB::sptr patientDB = ::fwData::PatientDB::dynamicCast(obj);
                SLM_ASSERT("Sorry, the subject of message is not a ::fwData::PatientDB", patientDB);
                ::fwData::Image::sptr img;
                 if( it->get<3>() != REMOVE )
                 {
                     img = ::fwComEd::fieldHelper::BackupHelper::getSelectedImage(patientDB);
                 }
                // Udapte the composite object referenced by the composite key ( it->get<2>() )
                this->updateComposite(composite, img, it->get<2>(), it->get<3>() );
            }
        }
    }
}
void DataInfoFromMsgUpdaterSrv::receiving( ::fwServices::ObjectMsg::csptr _msg ) throw ( ::fwTools::Failed )
{
    ::fwData::Composite::sptr composite = this->getObject< ::fwData::Composite >();
    for (   ManagedEvents::iterator it = m_managedEvents.begin();
            it != m_managedEvents.end();
            ++it )
    {
        std::string event         = it->get<0>();
        std::string uuid          = it->get<1>();
        std::string compositeKey  = it->get<2>();
        ctrlSelection::IUpdaterSrv::ActionType action        = it->get<3>();

        //  test if message correspond to a defined event
        if( _msg->hasEvent( event ) )
        {
            ::fwData::Object::sptr obj = ::fwData::Object::dynamicCast( _msg->getSubject().lock() );
            SLM_ASSERT("Sorry, the subject of message is not a ::fwData::Object", obj);

            // Test if we manage this event from this object message uid
            if( obj->getID() == uuid || uuid == "*")
            {
                ::fwData::Object::sptr dataInfo = ::boost::const_pointer_cast< ::fwData::Object >(_msg->getDataInfo(  event ));
                SLM_ASSERT("no dataInfo set!!!" ,  dataInfo
                        ||  action== ctrlSelection::IUpdaterSrv::REMOVE
                        ||  action== ctrlSelection::IUpdaterSrv::REMOVE_IF_PRESENT
                );
                // Udpate the composite object referenced by the composite key
                this->updateComposite(composite, dataInfo , compositeKey , action );
            }
        }
    }
}
Example #4
0
void SSplineAdaptor::doReceive(::fwServices::ObjectMsg::csptr msg) throw(fwTools::Failed)
{
    if( msg->hasEvent(::fwComEd::PointListMsg::ELEMENT_ADDED) )
    {
        ::fwData::PointList::sptr pointList = this->getObject< ::fwData::PointList>();
        m_numberOfPoints = pointList->getRefPoints().size();
        ::navigation::computeSpline(pointList, m_numberOfPoints - 1, m_vtkpoints, m_parametricSpline, m_splineLength);

        this->doUpdate(); 
    }

    if( msg->hasEvent(::fwComEd::PointListMsg::ELEMENT_REMOVED) )
    {
        ::fwData::PointList::sptr pointList = this->getObject< ::fwData::PointList>();
        m_numberOfPoints = pointList->getRefPoints().size();
        ::navigation::updateSpline(pointList, m_vtkpoints, m_parametricSpline, m_splineLength);

        this->doUpdate();
    } 

    if( msg->hasEvent(::fwComEd::PointListMsg::ELEMENT_MODIFIED) )
    {
        ::fwData::PointList::sptr pointList = this->getObject< ::fwData::PointList>();
        ::navigation::updateSpline(pointList, m_vtkpoints, m_parametricSpline, m_splineLength);

        this->doUpdate();
    }
}
void ImagePickerInteractor::doReceive( ::fwServices::ObjectMsg::csptr msg) throw(fwTools::Failed)
{
    if ( msg->hasEvent( ::fwComEd::ImageMsg::BUFFER ) || ( msg->hasEvent( ::fwComEd::ImageMsg::NEW_IMAGE )) )
    {
        ::fwData::Image::sptr image = this->getObject< ::fwData::Image >();
        this->updateImageInfos(image);
    }

    if ( msg->hasEvent( ::fwComEd::ImageMsg::SLICE_INDEX ) )
    {
        ::fwComEd::ImageMsg::dynamicConstCast(msg)->getSliceIndex( m_axialIndex, m_frontalIndex, m_sagittalIndex);
    }
}
Example #6
0
void ImageInfo::receiving( ::fwServices::ObjectMsg::csptr _msg ) throw(::fwTools::Failed)
{
    SLM_TRACE_FUNC();
    ::fwComEd::InteractionMsg::csptr interactionMsg = ::fwComEd::InteractionMsg::dynamicConstCast(_msg);

    if (interactionMsg && _msg->hasEvent(::fwComEd::InteractionMsg::MOUSE_MOVE))
    {
        ::fwData::Image::sptr image = this->getObject< ::fwData::Image >();
        bool imageIsValid = ::fwComEd::fieldHelper::MedicalImageHelpers::checkImageValidity( image );
        m_valueText->setEnabled(imageIsValid);
        if (imageIsValid)
        {
            ::fwData::Point::csptr point = interactionMsg->getEventPoint();
            SLM_ASSERT("Sorry, the object is null", point);
            if(point)
            {
                fwVec3d  pointCoord = point->getCoord();
                ::fwComEd::helper::Image imageHelper(image);

                std::string intensity = imageHelper.getPixelAsString(pointCoord[0], pointCoord[1], pointCoord[2] );;
                m_valueText->setText(QString::fromStdString(intensity));
            }
        }
    }
}
Example #7
0
void Axis::doReceive( ::fwServices::ObjectMsg::csptr _msg) throw( ::fwTools::Failed)
{
    if( _msg->hasEvent( ::scene2D::data::ViewportMsg::VALUE_IS_MODIFIED) )
    {
        doUpdate();
    }
}
void PSAFromPDBSelectorUpdaterSrv::updating( ::fwServices::ObjectMsg::csptr _msg ) throw ( ::fwTools::Failed )
{
    ::fwData::Composite::sptr composite = this->getObject< ::fwData::Composite >();
    for (   PSAManagedEvents::iterator it = m_psaManagedEvents.begin();
            it != m_psaManagedEvents.end();
            ++it )
    {
        // First element of tuple ( it->get<0>() ) is the event, test if message correspond to a defined event
        if( _msg->hasEvent( it->get<0>() ) )
        {
            ::fwData::Object::sptr obj = ::fwData::Object::dynamicCast( _msg->getSubject().lock() );
            SLM_ASSERT(obj,"Sorry, the subject of message is not a ::fwData::Object");

            // Test if we manage this event from this object message uid ( it->get<1>() )
            if( obj->getID() == it->get<1>() )
            {
                ::fwData::PatientDB::sptr patientDB = ::fwData::PatientDB::dynamicCast(obj);
                SLM_ASSERT("Sorry, the subject of message is not a ::fwData::PatientDB", patientDB);

                ::fwData::Patient::sptr pat;
                ::fwData::String::sptr patientName;
                ::fwData::String::sptr patientInfo;
                ::fwData::Study::sptr stu;
                ::fwData::Acquisition::sptr acq;
                if( it->get<7>() != REMOVE )
                {
                    // Get selection
                    pat = ::fwComEd::fieldHelper::BackupHelper::getSelectedPatient(patientDB);
                    stu = ::fwComEd::fieldHelper::BackupHelper::getSelectedStudy(patientDB);
                    acq = ::fwComEd::fieldHelper::BackupHelper::getSelectedAcquisition(patientDB);
                    patientName = ::fwData::String::NewSptr( pat->getCRefName() );
                    std::string acqDate = ::boost::posix_time::to_iso_extended_string( acq->getCreationDate() );
                    acqDate =  acqDate.substr(0,10) + " " + acqDate.substr(11,5);
                    std::stringstream info;
                    info << pat->getCRefName() << "\n" << acqDate;
                    patientInfo = ::fwData::String::NewSptr( info.str() );
                }
                // Udapte the composite object referenced by the composite key ( it->get<2>() )
                this->updateComposite(composite, pat, it->get<2>(), it->get<7>() );
                this->updateComposite(composite, stu, it->get<3>(), it->get<7>() );
                this->updateComposite(composite, acq, it->get<4>(), it->get<7>() );
                this->updateComposite(composite, patientName, it->get<5>(), it->get<7>() );
                this->updateComposite(composite, patientInfo, it->get<6>(), it->get<7>() );
            }
        }
    }
}
Example #9
0
void Image::doReceive(::fwServices::ObjectMsg::csptr msg) throw(::fwTools::Failed)
{
    ::fwData::Image::sptr image = this->getObject< ::fwData::Image >();
    bool imageIsValid = ::fwComEd::fieldHelper::MedicalImageHelpers::checkImageValidity( image );

    if (imageIsValid)
    {
        if ( msg->hasEvent( ::fwComEd::ImageMsg::BUFFER ) || ( msg->hasEvent( ::fwComEd::ImageMsg::NEW_IMAGE )) )
        {
            this->doUpdate();

            // Hack to force imageSlice update until it is not able to detect a new image
            ::fwComEd::ImageMsg::sptr msg = ::fwComEd::ImageMsg::New();
            msg->setSliceIndex(m_axialIndex, m_frontalIndex, m_sagittalIndex);
            ::fwServices::IEditionService::notify(this->getSptr(), image, msg);
        }

        if ( msg->hasEvent( ::fwComEd::ImageMsg::MODIFIED ) )
        {
            m_imageData->Modified();

            this->setVtkPipelineModified();
        }

        if (this->upadteTFObserver(msg, this->getSptr()) || msg->hasEvent( ::fwComEd::TransferFunctionMsg::MODIFIED_POINTS ) )
        {
            this->updateImageTransferFunction(image);
        }

        if ( msg->hasEvent( ::fwComEd::TransferFunctionMsg::WINDOWING ) )
        {
            ::fwComEd::TransferFunctionMsg::csptr tfmsg = ::fwComEd::TransferFunctionMsg::dynamicConstCast(msg);
            this->setWindow(tfmsg->getWindow());
            this->setLevel(tfmsg->getLevel());
            updateWindowing(image);
        }

        if ( msg->hasEvent( ::fwComEd::ImageMsg::TRANSPARENCY ) || msg->hasEvent( ::fwComEd::ImageMsg::VISIBILITY ) )
        {
            this->updateImageOpacity();
        }
    }
    else
    {
        this->destroyPipeline();
    }
}
Example #10
0
void WindowLevel::receiving( ::fwServices::ObjectMsg::csptr msg ) throw(::fwTools::Failed)
{
    SLM_TRACE_FUNC();

    this->upadteTFObserver(msg, this->getSptr());

    if (msg->hasEvent( ::fwComEd::ImageMsg::BUFFER ))
    {
        this->updating();
    }
    if (msg->hasEvent( ::fwComEd::TransferFunctionMsg::WINDOWING ))
    {
        ::fwData::Image::sptr image = this->getObject< ::fwData::Image >();

        bool imageIsValid = ::fwComEd::fieldHelper::MedicalImageHelpers::checkImageValidity( image );
        SLM_ASSERT("Image is not valid",imageIsValid);
        this->updateTransferFunction(image, this->getSptr());

        ::fwData::TransferFunction::sptr pTF = this->getTransferFunction();
        SLM_ASSERT("TransferFunction null pointer", pTF);
        ::fwData::TransferFunction::TFValuePairType minMax = pTF->getWLMinMax();
        this->onImageWindowLevelChanged( minMax.first, minMax.second );
    }
}
Example #11
0
void Camera2::doUpdate( ::fwServices::ObjectMsg::csptr msg) throw(fwTools::Failed)
{
    if( msg->hasEvent( ::fwComEd::TransformationMatrix3DMsg::MATRIX_IS_MODIFIED ) )
    {
        vtkCamera* camera = this->getRenderer()->GetActiveCamera();
        camera->RemoveObserver( m_cameraCommand );

        ::fwData::TransformationMatrix3D::sptr transMat = this->getObject< ::fwData::TransformationMatrix3D >();

        vtkMatrix4x4* mat = vtkMatrix4x4::New();

        for(int lt=0; lt<4; lt++)
        {
            for(int ct=0; ct<4; ct++)
            {
                mat->SetElement(lt, ct, transMat->getCoefficient(lt,ct));
            }
        }

        // Position camera on origin
        vtkPerspectiveTransform* oldTrans = vtkPerspectiveTransform::New();
        oldTrans->Identity();
        oldTrans->SetupCamera(camera->GetPosition(), camera->GetFocalPoint(), camera->GetViewUp());
        oldTrans->Inverse();
        oldTrans->Concatenate(m_transOrig);
        oldTrans->Inverse();

        // Apply new transform
        vtkTransform* trans =  vtkTransform::New();
        trans->SetMatrix(mat);
        trans->Concatenate(oldTrans->GetMatrix());
        camera->ApplyTransform(trans);

        this->getRenderer()->ResetCameraClippingRange();
        this->setVtkPipelineModified();

        camera->AddObserver( ::vtkCommand::ModifiedEvent, m_cameraCommand );

        mat->Delete();
        oldTrans->Delete();
        trans->Delete();
    }
}
Example #12
0
/**
 * @brief Called by a data to notify a service.
 *
 * @param _pMsg : Incoming message
 */
void SofaCoreSrv::updating( fwServices::ObjectMsg::csptr msg ) throw ( ::fwTools::Failed )
{
    if (msg->hasEvent("NEW_SOFA_SCENE")) {

        // Delete object sofa
        delete sofa;

        // Get Path Scn
        ::fwData::String::csptr pathScn = ::fwData::String::dynamicConstCast(msg->getDataInfo("NEW_SOFA_SCENE"));

        // Get acquisition
        ::fwData::Acquisition::sptr acq = this->getObject< ::fwData::Acquisition >();

        // Create object sofa
        sofa = new SofaBusiness();
        sofa->loadScn(pathScn->value(), acq, this->getSptr());

        // Apply at sofa the number of image by second
        sofa->setTimeStepAnimation(1000/50);

        if (sofa) {
            // if animation is running
            if (sofa->isAnimate()) {
                // Stop animation
                sofa->stopThread();
            } else {
                // Start animation
                sofa->startThread();
            }
        } else {
            QMessageBox::warning(0, "Warning", "To launch animation you must first load scene file !");
        }

    }

    else if (msg->hasEvent("START_STOP_SOFA")) {
        if (sofa) {
            // if animation is running
            if (sofa->isAnimate()) {
                // Stop animation
                sofa->stopThread();
            } else {
                // Start animation
                sofa->startThread();
            }
        } else {
            QMessageBox::warning(0, "Warning", "To launch animation you must first load scene file !");
        }
    }

    else if (msg->hasEvent("EDITOR_MESH_SOFA")) {
        if (sofa) {
            ::fwData::Vector::csptr data = ::fwData::Vector::dynamicConstCast(msg->getDataInfo("EDITOR_MESH_SOFA"));
            ::fwData::String::csptr idMesh = ::fwData::String::dynamicConstCast(data->at(0));
            ::fwData::Integer::csptr strength = ::fwData::Integer::dynamicConstCast(data->at(1));
            sofa->shakeMesh(idMesh->value(), strength->value());
        }
    }

    else if (msg->hasEvent("MOVE_MESH_SOFA")) {
        if (sofa) {
            ::fwData::Vector::csptr data = ::fwData::Vector::dynamicConstCast(msg->getDataInfo("MOVE_MESH_SOFA"));
            ::fwData::String::csptr idMesh = ::fwData::String::dynamicConstCast(data->at(0));
            ::fwData::Integer::csptr x = ::fwData::Integer::dynamicConstCast(data->at(1));
            ::fwData::Integer::csptr y = ::fwData::Integer::dynamicConstCast(data->at(2));
            ::fwData::Integer::csptr z = ::fwData::Integer::dynamicConstCast(data->at(3));
            ::fwData::Float::csptr rx = ::fwData::Float::dynamicConstCast(data->at(4));
            ::fwData::Float::csptr ry = ::fwData::Float::dynamicConstCast(data->at(5));
            ::fwData::Float::csptr rz = ::fwData::Float::dynamicConstCast(data->at(6));
            sofa->moveMesh(idMesh->value(), x->value(), y->value(), z->value(), rx->value(), ry->value(), rz->value());
        }
    }

    else if (msg->hasEvent("KINECT_NEW_POSITION_HAND")) {
        if (sofa) {
            // Get the position x y z of the main and his id
            ::fwData::Vector::csptr data = ::fwData::Vector::dynamicConstCast(msg->getDataInfo("KINECT_NEW_POSITION_HAND"));
            ::fwData::Integer::csptr x = ::fwData::Integer::dynamicConstCast(data->at(0));
            ::fwData::Integer::csptr y = ::fwData::Integer::dynamicConstCast(data->at(1));
            ::fwData::Integer::csptr z = ::fwData::Integer::dynamicConstCast(data->at(2));
            ::fwData::Integer::csptr id = ::fwData::Integer::dynamicConstCast(data->at(3));

            static int idTool1 = 0;
            static int idTool2 = 0;
            static int stage = 0;

            // Allow to switch tool
            if (id->value() == idTool1) {
                // move tool 1
                sofa->moveMesh("souris_mors2", x->value()/2 + 190, y->value()/2 + 152, z->value()/2 - 200, 0, 0, 0);
            } else if (id->value() == idTool2) {
                // move tool 2
                sofa->moveMesh("souris_cam", x->value()/2 + 190, y->value()/2 + 152, z->value()/2 - 200, 0, 0, 0);
            } else {
                if (stage%2) {
                    idTool1 = id->value();
                } else {
                    idTool2 = id->value();
                }
                stage++;
            }
        }
    }
}