Пример #1
0
    Document DocumentSource::documentFromBsonWithDeps(const BSONObj& bson,
                                                      const ParsedDeps& neededFields) {
        MutableDocument md(neededFields.size());

        BSONObjIterator it(bson);
        while (it.more()) {
            BSONElement bsonElement (it.next());
            StringData fieldName = bsonElement.fieldNameStringData();
            Value isNeeded = neededFields[fieldName];

            if (isNeeded.missing())
                continue;

            if (isNeeded.getType() == Bool) {
                md.addField(fieldName, Value(bsonElement));
                continue;
            }

            dassert(isNeeded.getType() == Object);

            if (bsonElement.type() == Object) {
                Document sub = documentFromBsonWithDeps(bsonElement.embeddedObject(),
                                                        isNeeded.getDocument());
                md.addField(fieldName, Value(sub));
            }

            if (bsonElement.type() == Array) {
                md.addField(fieldName, arrayHelper(bsonElement.embeddedObject(),
                                                   isNeeded.getDocument()));
            }
        }

        return md.freeze();
    }
Пример #2
0
void SReadArray::updating() throw( ::fwTools::Failed )
{
    ::fwData::Array::sptr array = this->getObject< ::fwData::Array >();
    ::fwData::mt::ObjectWriteLock writeLock(array);
    SLM_ASSERT("No array.", array);

    const int arraySize = 10;

    ::fwData::Array::SizeType size(1, arraySize);

    array->resize("uint32", size, 1, true);

    ::fwComEd::helper::Array arrayHelper(array);

    unsigned int *buffer = static_cast< unsigned int* >( arrayHelper.getBuffer() );

    for (int i = 0 ; i < arraySize; i++)
    {
        buffer[i] = i;
    }

    ::fwData::Object::ObjectModifiedSignalType::sptr sig
        = array->signal< ::fwData::Object::ObjectModifiedSignalType>( ::fwData::Object::s_OBJECT_MODIFIED_SIG );

    ::fwServices::ObjectMsg::sptr msg = ::fwServices::ObjectMsg::New();
    msg->addEvent("MODIFIED_EVENT");
    sig->asyncEmit(msg);
}
Пример #3
0
void SShowArray::updating()
{
    ::fwData::Array::csptr array = this->getInput< ::fwData::Array >("array");
    ::fwData::mt::ObjectReadLock readLock(array);
    SLM_ASSERT("No array.", array);

    ::fwDataTools::helper::ArrayGetter arrayHelper(array);
    const unsigned int* buffer = static_cast< const unsigned int* >( arrayHelper.getBuffer() );

    std::stringstream str;
    std::ostream_iterator<unsigned int> coutIter(str, ", ");
    std::copy(buffer, buffer+10, coutIter );
    SLM_INFO("Buffer : " + str.str());
}
Пример #4
0
    // Helper for next function
    static Value arrayHelper(const BSONObj& bson, const DocumentSource::ParsedDeps& neededFields) {
        BSONObjIterator it(bson);

        vector<Value> values;
        while (it.more()) {
            BSONElement bsonElement(it.next());
            if (bsonElement.type() == Object) {
                Document sub = DocumentSource::documentFromBsonWithDeps(
                                                    bsonElement.embeddedObject(),
                                                    neededFields);
                values.push_back(Value(sub));
            }

            if (bsonElement.type() == Array) {
                values.push_back(arrayHelper(bsonElement.embeddedObject(), neededFields));
            }
        }

        return Value::consume(values);
    }
Пример #5
0
void ImageTest::testSetGetPixel()
{
    ::fwData::Image::sptr img = ::fwData::Image::New();
    ::fwDataTools::helper::Image imgHelper(img);

    const std::uint8_t DIMENSION = 3;
    ::fwTools::Type TYPE = ::fwTools::Type::create("int16");
    ::fwData::Image::SizeType VECTORSIZE(DIMENSION);
    VECTORSIZE[0] = 10;
    VECTORSIZE[1] = 20;
    VECTORSIZE[2] = 30;

    img->allocate(VECTORSIZE, TYPE);

    ::fwData::Array::sptr array = img->getDataArray();
    ::fwDataTools::helper::Array arrayHelper(array);

    // test 1 : use getPixelBuffer
    short count = 0;
    short* iter = arrayHelper.begin<short>();
    for (; iter != arrayHelper.end<short>(); ++iter)
    {
        *iter = count++;
    }

    for (unsigned int x = 0; x < VECTORSIZE[0]; ++x)
    {
        for (unsigned int y = 0; y < VECTORSIZE[1]; ++y)
        {
            for (unsigned int z = 0; z < VECTORSIZE[2]; ++z)
            {
                short val = static_cast<short>(x+y*VECTORSIZE[0]+z*VECTORSIZE[0]*VECTORSIZE[1]);
                ::fwData::Image::IndexType index = val;
                CPPUNIT_ASSERT_EQUAL(val, *reinterpret_cast<short*>(imgHelper.getPixelBuffer(x, y, z)));
                CPPUNIT_ASSERT_EQUAL(val, *reinterpret_cast<short*>(imgHelper.getPixelBuffer(index)));
                ::fwData::Image::BufferType* buffer =
                    reinterpret_cast< ::fwData::Image::BufferType* >(imgHelper.getBuffer());
                CPPUNIT_ASSERT_EQUAL(val, *reinterpret_cast<short*>(imgHelper.getPixelBuffer(index)));

                std::stringstream ss;
                ss << val;
                CPPUNIT_ASSERT_EQUAL( ss.str(), imgHelper.getPixelAsString(x, y, z));
            }
        }
    }

    // test 2 : use setPixelBuffer
    for (unsigned int x = 0; x < VECTORSIZE[0]; ++x)
    {
        for (unsigned int y = 0; y < VECTORSIZE[1]; ++y)
        {
            for (unsigned int z = 0; z < VECTORSIZE[2]; ++z)
            {
                ::fwData::Image::IndexType index = x+y*VECTORSIZE[0]+z*VECTORSIZE[0]*VECTORSIZE[1];
                short val = static_cast<short>(index * 2);
                imgHelper.setPixelBuffer(index, reinterpret_cast< ::fwData::Image::BufferType* >(&val));
            }
        }
    }

    count = 0;
    iter  = arrayHelper.begin<short>();
    for (; iter != arrayHelper.end<short>(); ++iter)
    {
        CPPUNIT_ASSERT_EQUAL(static_cast<short>(count++ *2), *iter);
    }
}