Пример #1
0
::fwData::Object::sptr ObjectTracker::buildObject( const std::string &className, const std::string &uniqueIDXML  )
{
    if ( uniqueIDXML.empty() )
    {
        OSLM_DEBUG( className << " generated without id");
        return ::fwData::Factory::New( className );
    }

    Registry::iterator i =  m_buildedObject.find( uniqueIDXML );

    if ( i == m_buildedObject.end() )
    {
        // not already registred : create it then register it
        ::fwData::Object::sptr newObject = ::fwData::Factory::New( className );
        m_buildedObject[uniqueIDXML] = newObject;
        OSLM_DEBUG(className<<"-"<<newObject.get() << " first instantiation");

        std::string uuid = ::fwTools::UUID::get(newObject); // generate a new one if not supervised
        m_oldNewUUIDTranslation[uniqueIDXML] = uuid;
        OSLM_DEBUG(className<<"-"<<newObject.get() << " UUID : " << uuid);

        return newObject;
    }
    else
    {
        OSLM_DEBUG( className <<"-"<< uniqueIDXML << " previoulsy instantiated : use this one" );
        return ::fwData::Object::dynamicCast( i->second ); // object exist we return it
    }
}
Пример #2
0
    static void  containerFromXml( xmlNodePtr rootNode, InserterIterator  inserter )
    {
        // parse rootNode child then generateObject and insertit
        SLM_ASSERT("rootNode not instanced", rootNode);
        if ( rootNode->children != NULL )
        {
            xmlNodePtr currentNode = XMLParser::nextXMLElement(rootNode->children);
            while (currentNode )
            {
                OSLM_DEBUG(" containerFromXml" << (const char*)currentNode->name << currentNode );
                // dot not create duplicate object
                ::fwData::Object::sptr obj = fromXML(currentNode);

                // append to container
                typedef typename InserterIterator::container_type::value_type SharedPtrConcreteObject;
                SharedPtrConcreteObject cobj;
                cobj = ::boost::dynamic_pointer_cast< typename SharedPtrConcreteObject::element_type >( obj );
                assert ( cobj );
                *inserter = cobj;

                // go to next element
                currentNode = XMLParser::nextXMLElement(currentNode->next);
            }
        }
    }
Пример #3
0
//@todo remove throw specifications
void IEditionService::attach( ::fwServices::ComChannelService::sptr observer) throw()
{
    // Pre-condition : This observer must exist and must not be already registered.
    SLM_ASSERT("The ComChannelService given in parameter is a null shared pointer.", observer != 0 );
    SLM_ASSERT("ACH : The ComChannelService, given in parameter, is already registered", !isAttached( observer ) );

    // Get the service observer
    ::fwServices::IService::sptr service = observer->getDest();

    // Test if this service handling all events or if it has a specific configuration
    if ( service->isHandlingAllEvents() )
    {
        OSLM_WARN("Sorry, IService API to manage events has changed, this service "<< service->getClassname() <<" must define a list of handling message thanks to method IService::addNewHandledEvent() which must be used the service constructor.");
        m_globalObservers.push_back( observer );
        // sort the list to put the new element at the right place.
        m_globalObservers.sort( Less );
    }
    else
    {
        OSLM_DEBUG("This service not handling all events : " << service->getClassname() );
        std::vector< std::string > handlingEvents = service->getHandledEvents();
        BOOST_FOREACH(std::string handlingEvent, handlingEvents)
        {
            ObserverContainer & specificObservers = m_event2SpecificObservers[ handlingEvent ];
            specificObservers.push_back( observer );
            specificObservers.sort( Less );
        }
    }
Пример #4
0
    /// get XML from current object
    FWXML_API xmlNodePtr getXMLFrom( ::fwData::Object::sptr obj )
    {
        OSLM_DEBUG("GenericXMLTranslator for " << obj->className() << "-" <<  obj.get() );

        // check obj is well realated to RealObject
        ::boost::shared_ptr<RealData> robj = ::boost::dynamic_pointer_cast<RealData >(obj);
        SLM_ASSERT("robj not instanced", robj);

        // create master node with className+id
        xmlNodePtr node = XMLTranslatorHelper::MasterNode( robj );


        // create data information using boost tweaked archive

        ::boost::archive::fw_xml_oarchive ao_xml(0);
        {
            ao_xml.operator&( ::boost::serialization::make_nvp("BoostManagedObject", *robj ) ); // Serialization with pointer generate an NVP (.first with NULL name !!!)
        }

        xmlNodePtr boostXML =  ao_xml.getXMLNode();
        SLM_ASSERT("boostXML not instanced", boostXML);
        boostXML = boostXML->children;
        while ( boostXML!=NULL )
        {
            if ( boostXML->type == XML_ELEMENT_NODE )
            {
                xmlAddChild( node, xmlCopyNode(boostXML,1) );
            }
            boostXML =  boostXML->next;
        }

        xmlFree( ao_xml.getXMLNode() );
        return node;
    }
void PSAFromPDBSelectorUpdaterSrv::configuring()  throw ( ::fwTools::Failed )
{
    SLM_TRACE_FUNC();

    ::fwRuntime::ConfigurationElementContainer handleEvents = m_configuration->findAllConfigurationElement("update");

    SLM_ASSERT("Problem with configuration for PSAFromPDBSelectorUpdaterSrv type, missing element \"update\"", handleEvents.size() != 0 );
    OSLM_DEBUG( "handleEvents.size() = " << handleEvents.size() );
    m_psaManagedEvents.clear();
    for(    ::fwRuntime::ConfigurationElementContainer::Iterator item = handleEvents.begin();
            item != handleEvents.end();
            ++item )
    {
        SLM_FATAL_IF( "Sorry, attribute \"patientKey\" is missing", !(*item)->hasAttribute("patientKey") );
        std::string patientKey =  (*item)->getExistingAttributeValue("patientKey");

        SLM_FATAL_IF( "Sorry, attribute \"studyKey\" is missing", !(*item)->hasAttribute("studyKey") );
        std::string studyKey =  (*item)->getExistingAttributeValue("studyKey");

        SLM_FATAL_IF( "Sorry, attribute \"acquisitionKey\" is missing", !(*item)->hasAttribute("acquisitionKey") );
        std::string acquisitionKey =  (*item)->getExistingAttributeValue("acquisitionKey");

        SLM_FATAL_IF( "Sorry, attribute \"patientNameKey\" is missing", !(*item)->hasAttribute("patientNameKey") );
        std::string patientNameKey =  (*item)->getExistingAttributeValue("patientNameKey");

        SLM_FATAL_IF( "Sorry, attribute \"patientInfoKey\" is missing", !(*item)->hasAttribute("patientInfoKey") );
        std::string patientInfoKey =  (*item)->getExistingAttributeValue("patientInfoKey");

        SLM_FATAL_IF( "Sorry, attribute \"onEvent\" is missing", !(*item)->hasAttribute("onEvent") );
        std::string onEvent =  (*item)->getExistingAttributeValue("onEvent");

        SLM_FATAL_IF( "Sorry, attribute \"fromUID\" is missing", !(*item)->hasAttribute("fromUID") );
        std::string fromUID =  (*item)->getExistingAttributeValue("fromUID");

        SLM_FATAL_IF( "Sorry, attribute \"actionType\" is missing", !(*item)->hasAttribute("actionType") );
        std::string actionType =  (*item)->getExistingAttributeValue("actionType");

        ActionType action;
        if ( actionType == "ADD" )                    { action = ADD; }
        else if ( actionType == "SWAP" )              { action = SWAP; }
        else if ( actionType == "REMOVE" )            { action = REMOVE; }
        else if ( actionType == "ADD_OR_SWAP" )       { action = ADD_OR_SWAP; }
        else if ( actionType == "REMOVE_IF_PRESENT" ) { action = REMOVE_IF_PRESENT; }
        else if ( actionType == "DO_NOTHING" )        { action = DO_NOTHING; }
        else
        {
            SLM_FATAL("Sorry this type of \"actionType\" is not managed by PSAFromPDBSelectorUpdaterSrv type");
        }

        OSLM_INFO( "Manage event "<< onEvent <<" from this object "<< fromUID <<" and "<< actionType << " "<< patientKey << "  " << studyKey << "  " << acquisitionKey << "  " << patientNameKey << " in my composite.");
        PSAManagedEvent managedEvent (onEvent, fromUID, patientKey, studyKey, acquisitionKey, patientNameKey, patientInfoKey, action);
        m_psaManagedEvents.push_back( managedEvent );
        addNewHandledEvent( onEvent );
    }
}
Пример #6
0
bool DoubleValidator::TransferToWindow()
{
    wxTextCtrl  * textCtrl = wxStaticCast( GetWindow(), wxTextCtrl );
    OSLM_DEBUG( "DoubleValidator::TransferFromWindow() => " << this->m_value );
    wxString    value = wxString::Format( _("%0.4f"), this->m_value );

    if( textCtrl->GetValue() != value )
    {
        textCtrl->SetValue( value );
    }
    return true;
}
Пример #7
0
 /**
  * @brief Constructor : create the factory and register it
  * @param[in] key type that factory can candle
  */
 ClassRegistrar(const KEY & key)
 {
     // create factory
     ::fwTools::IClassFactory::sptr  af( new ClassFactory< BASECLASS,SUBCLASS,KEY >(key) );
     // register it
     OSLM_DEBUG( "Class Factory Registration BaseClass= " << getString( af->baseClassId() )
             << " SubClass= " << ::fwTools::getString( af->subClassId() )
             << " KeyClass= " << ::fwTools::getString( af->keyId() )
             << " KeyValue= " << af->stringizedKey()
     );
     ::fwTools::ClassFactoryRegistry::addFactory( af );
 }
Пример #8
0
void SStringReader::updating()
{
    SLM_TRACE_FUNC();

    if ( this->hasLocationDefined() )
    {
        // Read data.txt
        std::string line;
        std::string data("");
        std::ifstream myfile( this->getFile().string().c_str() );
        if ( myfile.is_open() )
        {
            while ( myfile.good() )
            {
                getline( myfile, line );
                OSLM_DEBUG("Read line : " << line );
                data += line;
            }
            myfile.close();
        }
        else
        {
            OSLM_ERROR("Unable to open file : " << this->getFile() );
        }
        OSLM_DEBUG("Loaded data : " << data );

        // Set new string value in your associated object
        auto myAssociatedData = this->getInOut< ::fwData::String >("targetString");
        SLM_ASSERT("Data not found", myAssociatedData);

        myAssociatedData->setValue( data );
    }
    else
    {
        SLM_WARN("Be careful, reader failed because no file location is defined." );
    }

    // Then, notifies listeners that the image has been modified
    this->notifyMessage();
}
Пример #9
0
void CompareObjects::visit(const camp::MapProperty& property)
{
    SLM_TRACE_FUNC();
    const std::string name(property.name());
    OSLM_DEBUG("MapProperty name = " << name);

    OSLM_DEBUG( "Ok MapProperty name =" << name );

    std::pair< ::camp::Value, ::camp::Value > value;
    std::string mapKey;
    for (unsigned int i = 0; i < property.getSize(m_campObj); ++i)
    {
        value = property.getElement(m_campObj, i);
        mapKey = value.first.to< std::string >();
        PropertyVisitor visitor(getPath(name + "." + mapKey), m_props);
        PropType pt = value.second.visit(visitor);
        if(!pt.first.empty())
        {
            m_props->insert(m_props->end(), pt);
        }
    }
}
::fwData::PatientDB::sptr FwXMLPatientDBReaderService::manageZipAndCreatePatientDB( const ::boost::filesystem::path _pArchivePath )
{
    ::fwData::PatientDB::sptr patientDB;
    // Unzip folder
    ::boost::filesystem::path destFolder = ::fwTools::System::getTemporaryFolder() / "fwxmlArchiveFolder";

    OSLM_DEBUG("srcZipFileName = " << _pArchivePath );
    OSLM_DEBUG("destFolderName = " << destFolder );

    ::fwZip::ZipFolder::NewSptr zip;
    ::fwGui::dialog::ProgressDialog progress("Reading patient");
    zip->addHandler( progress );
    zip->unpackFolder( _pArchivePath, destFolder );

    // Load
    ::boost::filesystem::path xmlFile;
    if(::boost::filesystem::exists(destFolder/"patient.xml"))
    {
        xmlFile = destFolder / "patient.xml";
        patientDB = this->createPatientDB( xmlFile );
    }
    else if(::boost::filesystem::exists(destFolder/"root.xml"))
    {
        xmlFile = destFolder / "root.xml";
        patientDB = this->createPatientDB( xmlFile );
    }
    else
    {
        std::stringstream stream;
        stream << "Sorry, "<<_pArchivePath<< " is not a valid " FWXML_ARCHIVE_EXTENSION " file."
               << this->getObject()->getRootedClassname();
        ::fwGui::dialog::MessageDialog::showMessageDialog("Warning",
                        stream.str(),
                        ::fwGui::dialog::IMessageDialog::WARNING);
    }
    // Remove temp folder
    ::boost::filesystem::remove_all( destFolder );
    return patientDB;
}
Пример #11
0
void Activities::parseBundleInformation(const std::vector< SPTR( ::fwRuntime::Extension ) >& extensions)
{

    for( const SPTR( ::fwRuntime::Extension ) &ext :  extensions )
    {
        OSLM_DEBUG("Parsing <" << ext->getBundle()->getIdentifier() << "> Activities");
        ActivityInfo info(ext);

        ::fwCore::mt::WriteLock lock(m_registryMutex);
        SLM_ASSERT("The id " <<  info.id << "(" << info.title << ")"
                             << " already exists in the Activities registry", m_reg.find( info.id ) == m_reg.end());
        m_reg.insert( Registry::value_type(info.id, info) );
    }
}
Пример #12
0
void MedicalImageManagerSrv::configuring()  throw ( ::fwTools::Failed )
{
    ::fwRuntime::ConfigurationElementContainer updaters = m_configuration->findAllConfigurationElement("update");

    SLM_ASSERT("Problem with configuration for MedicalImageManagerSrv type, missing element \"update\"", updaters.size() != 0 );
    OSLM_DEBUG( "updaters.size() = " << updaters.size() );
    m_imageCompositeKeys.clear();
    for(    ::fwRuntime::ConfigurationElementContainer::Iterator item = updaters.begin();
            item != updaters.end();
            ++item )
    {
        SLM_FATAL_IF( "Sorry, attribute \"imageCompositeKey\" is missing", !(*item)->hasAttribute("imageCompositeKey") );
        std::string imageCompositeKey =  (*item)->getExistingAttributeValue("imageCompositeKey");
        m_imageCompositeKeys.push_back(imageCompositeKey);
    }
}
Пример #13
0
bool DoubleValidator::TransferFromWindow()
{
    wxTextCtrl * textCtrl( wxStaticCast(GetWindow(), wxTextCtrl) );
    wxString textValue( textCtrl->GetValue() );
    double doubleValue;
    bool success;

    success = textValue.ToDouble( &doubleValue );
    OSLM_DEBUG( "DoubleValidator::TransferFromWindow() => " << doubleValue );
    if( success &&
        (m_minValue == m_maxValue || doubleValue >= m_minValue && doubleValue <= m_maxValue))
    {
        this->m_value = (double) doubleValue;
    }
    return success;
}
Пример #14
0
void CompareObjects::visit(const camp::UserProperty& property)
{
    SLM_TRACE_FUNC();
    const std::string name ( property.name() );
    OSLM_DEBUG( "UserProperty name =" << name );
    ::camp::Value elemValue = property.get( m_campObj );

    if(m_campObj.call("is_a", ::camp::Args("::fwData::Object")).to<bool>())
    {
        PropertyVisitor visitor(getPath(name), m_props);
        PropType pt = elemValue.visit(visitor);
        if(!pt.first.empty())
        {
            m_props->insert(m_props->end(), pt);
        }
    }
}
Пример #15
0
    /// get Object from an XML node
    FWXML_API void updateDataFromXML( ::fwData::Object::sptr toUpdate,  xmlNodePtr source)
    {
        // TODO assertion xmlNode.name() == RealData.className();
        OSLM_DEBUG("GenericXMLTranslator::updateDataFromXML( obj " << toUpdate->className() << " XMLNode source " << source->name );

        xmlNodePtr boostRoot = getBoostRootNode(source);

        SLM_DEBUG( XMLParser::toString(boostRoot) );
        assert( dynamic_cast<RealData *>(toUpdate.get()) );
        RealData *robj=dynamic_cast<RealData *>(toUpdate.get());

        // get data information using boost tweaked archive
        ::boost::archive::fw_xml_iarchive ai_xml(0);
        ai_xml.setXMLNode(boostRoot);
        ai_xml.operator&( ::boost::serialization::make_nvp("DummyRootFORBoostNode", *robj ) );
        SLM_DEBUG("GenericXMLTranslator::updateDataFromXML DONE");
    }
Пример #16
0
void SSplineAdaptor::doUpdate() throw (fwTools::Failed)
{
    OSLM_ASSERT("No valid spline", m_parametricSpline);

    vtkSmartPointer<vtkPolyDataMapper> mapper = vtkSmartPointer<vtkPolyDataMapper>::New();
    vtkSmartPointer<vtkActor> actor = vtkSmartPointer<vtkActor>::New();

    m_functionSource->SetUResolution(floor(m_splineLength));
    m_functionSource->SetParametricFunction(m_parametricSpline);
    m_functionSource->Update();

    OSLM_DEBUG(" U resolution " << m_functionSource->GetUResolution());

    mapper->SetInputConnection(m_functionSource->GetOutputPort());
    actor->SetMapper(mapper);

    this->addToRenderer(actor);
    this->setVtkPipelineModified();
}
Пример #17
0
void CompareObjects::visit(const camp::ArrayProperty& property)
{
    SLM_TRACE_FUNC();
    const std::string name(property.name());
    OSLM_DEBUG( "ArrayProperty name =" << name );

    for(unsigned int i = 0; i < property.size(m_campObj); ++i)
    {
        ::camp::Value elemValue = property.get(m_campObj, i);
        std::stringstream ss;
        ss << name << "." << i;
        PropertyVisitor visitor(getPath(ss.str()), m_props);
        PropType pt = elemValue.visit(visitor);
        if(!pt.first.empty())
        {
            m_props->insert(m_props->end(), pt);
        }
    }
}
Пример #18
0
    static void  PODcontainerFromXml( xmlNodePtr rootNode, InserterIterator  inserter )
    {
        // parse rootNode child then generateObject and insertit
        SLM_ASSERT("rootNode not instanced", rootNode);
        if ( rootNode->children != NULL )
        {
            xmlNodePtr currentNode = XMLParser::nextXMLElement(rootNode->children);
            while (currentNode )
            {
                OSLM_DEBUG(" PODcontainerFromXml" << (const char*)currentNode->name << currentNode );

                // append to container
                typedef typename InserterIterator::container_type::value_type PODType;
                PODType value = getElement< PODType >(currentNode);

                *inserter = value;

                // go to next element
                currentNode = XMLParser::nextXMLElement(currentNode->next);
            }
        }
    }
Пример #19
0
void S2DWheel::starting()
{
    this->initialize();

    fwVtkWheelRepresentation* wheelRepresentation = fwVtkWheelRepresentation::New();

    wheelRepresentation->SetVisibility(m_visible);
    m_wheelWidget->SetInteractor(this->getRenderer()->GetRenderWindow()->GetInteractor());
    m_wheelWidget->SetPriority(1.f); // Set a priority higher than that of the ::visuVTKAdaptor::SProbeCursor
    m_wheelWidget->SetRepresentation(wheelRepresentation);
    m_wheelWidget->On();
    m_wheelWidget->SetWheelUpdateCallback([this](double cx, double cy, double o)
        {
            OSLM_DEBUG("Center : " << "(" << cx << ", " << cy << "), Orientation : " << o);
            this->m_wheelUpdatedSignal->asyncEmit(cx, cy, o);
        });

    m_resizeCallback = vtkSmartPointer< ::fwVtkIO::helper::vtkLambdaCommand >::New();
    m_resizeCallback->SetCallback(
        [this](vtkObject*, long unsigned int, void* )
        {
            const int viewportWidth = this->getRenderer()->GetRenderWindow()->GetSize()[0];
            const int viewportHeight = this->getRenderer()->GetRenderWindow()->GetSize()[1];

            if(viewportHeight != 0 && viewportWidth != 0)
            {
                this->m_wheelWidget->GetRepresentation()->UpdateRepresentation();
            }

            this->requestRender();
        });
    this->getRenderer()->GetRenderWindow()->AddObserver(vtkCommand::ModifiedEvent, m_resizeCallback);

    this->setVtkPipelineModified();
    this->requestRender();
}
Пример #20
0
    void operator()( const  Parameter &param )
    {
        OSLM_DEBUG( "itk::ImageSeriesWriter with PIXELTYPE "<<  fwTools::DynamicType::string<PIXELTYPE>() );

        ::fwData::Image::sptr image = param.m_dataImage;

        // VAG attention : ImageFileReader ne notifie AUCUNE progressEvent mais son ImageIO oui!!!! mais ImageFileReader ne permet pas de l'atteindre
        // car soit mis a la mano ou alors construit lors de l'Update donc trop tard
        // Il faut dont creer une ImageIO a la mano (*1*): affecter l'observation  sur IO (*2*) et mettre le IO dans le reader (voir *3*)

        // Reader IO (*1*)
        typename itk::ImageIOBase::Pointer imageIOWrite = itk::ImageIOFactory::CreateImageIO( "image.jpg", itk::ImageIOFactory::WriteMode);
        assert( imageIOWrite.IsNotNull() );

        // create writer
        typedef itk::Image< PIXELTYPE, 3> itkImageType;
        typedef itk::Image< unsigned char, 2 >      Image2DType;
        typedef typename  itk::ImageSeriesWriter< itkImageType, Image2DType > WriterType;
        typename WriterType::Pointer writer = WriterType::New();

        // set observation (*2*)
        itk::LightProcessObject::Pointer castHelper= (itk::LightProcessObject *)(imageIOWrite.GetPointer());
        assert( castHelper.IsNotNull() );
        Progressor progress(castHelper, param.m_fwWriter, param.m_filename);

        // create itk Image
        typename itkImageType::Pointer itkImage = ::fwItkIO::itkImageFactory<itkImageType>( image );

        typedef ::itk::IntensityWindowingImageFilter< itkImageType, itkImageType > RescaleFilterType;
        typename RescaleFilterType::Pointer rescaleFilter = RescaleFilterType::New();

        double min, max;
        ::fwData::Composite::sptr poolTF;
        poolTF = image->getField< ::fwData::Composite>( ::fwComEd::Dictionary::m_transferFunctionCompositeId );
        if(poolTF)
        {
            ::fwData::Composite::iterator iter = poolTF->find(::fwData::TransferFunction::s_DEFAULT_TF_NAME);
            if(iter != poolTF->end())
            {
                ::fwData::TransferFunction::sptr tf;
                tf = ::fwData::TransferFunction::dynamicCast(iter->second);
                min = tf->getWLMinMax().first;
                max = tf->getWLMinMax().second;
            }
        }
        else
        {
            ::fwComEd::fieldHelper::MedicalImageHelpers::getMinMax(image, min, max);
        }

        rescaleFilter->SetWindowMinimum( min );
        rescaleFilter->SetWindowMaximum( max );
        rescaleFilter->SetOutputMinimum( 0 );
        rescaleFilter->SetOutputMaximum( 255 );
        rescaleFilter->InPlaceOff();
        rescaleFilter->SetInput( itkImage );
        rescaleFilter->Update();

        writer->SetInput( rescaleFilter->GetOutput() );

        typedef itk::NumericSeriesFileNames    NameGeneratorType;

        NameGeneratorType::Pointer nameGenerator = NameGeneratorType::New();

        std::string format = param.m_filename;
        format += "/%04d.jpg";
        nameGenerator->SetSeriesFormat( format.c_str() );
        nameGenerator->SetStartIndex( 1 );
        nameGenerator->SetEndIndex( image->getSize()[2] );
        nameGenerator->SetIncrementIndex( 1 );

        writer->SetFileNames( nameGenerator->GetFileNames() );

        writer->SetImageIO( imageIOWrite  );

        // save image;
        writer->Update();
    }
Пример #21
0
bool ObjectTracker::isAlreadyInstanciated( const std::string &uniqueID  )
{
    bool result = m_buildedObject.find( uniqueID ) != m_buildedObject.end();
    OSLM_DEBUG("ObjectTracker::isAlreadyInstanciated(" << uniqueID << ") return bool = "<< result);
    return  result;
}
Пример #22
0
void ItkLogger::DisplayDebugText(const char* _txt)
{
    OSLM_DEBUG("[ITK]: " << _txt);
}