//------------------------------------------------------------------------------
void ImageReaderWriterTest::testMhdImageReader()
{

    const ::boost::filesystem::path file = ::fwTest::Data::dir() / "fw4spl/image/mhd/BostonTeapot.mhd";

    ::fwData::Image::NewSptr image;
    this->runImageSrv("::io::IReader","::ioVTK::ImageReaderService",getIOConfiguration(file), image);

    // Data expected
    const size_t dim = 3;
    ::fwData::Image::SpacingType spacingExpected(dim);
    spacingExpected[0] = 1.0;
    spacingExpected[1] = 1.0;
    spacingExpected[2] = 1.0;

    ::fwData::Image::OriginType originExpected(dim);
    originExpected[0] = 1.1;
    originExpected[1] = 2.2;
    originExpected[2] = 3.3;

    ::fwData::Image::SizeType sizeExpected(dim);
    sizeExpected[0] = 256;
    sizeExpected[1] = 256;
    sizeExpected[2] = 178;

    ::fwTools::Type expectedType("int8"); // MHD File image type : MET_CHAR

    // Data read.
    ::fwData::Image::SpacingType spacingRead = image->getSpacing();
    ::fwData::Image::SpacingType originRead = image->getOrigin();
    ::fwData::Image::SizeType sizeRead = image->getSize();



    CPPUNIT_ASSERT_EQUAL(spacingExpected.size(), spacingRead.size() );
    CPPUNIT_ASSERT_EQUAL(originExpected.size(), originRead.size() );
    CPPUNIT_ASSERT_EQUAL(sizeExpected.size(), sizeRead.size() );

    CPPUNIT_ASSERT_DOUBLES_EQUAL_MESSAGE("Incorrect spacing on x", spacingExpected[0], spacingRead[0], epsilon);
    CPPUNIT_ASSERT_DOUBLES_EQUAL_MESSAGE("Incorrect spacing on y", spacingExpected[1], spacingRead[1], epsilon);
    CPPUNIT_ASSERT_DOUBLES_EQUAL_MESSAGE("Incorrect spacing on z", spacingExpected[2], spacingRead[2], epsilon);

    CPPUNIT_ASSERT_DOUBLES_EQUAL_MESSAGE("Incorrect origin on x", originExpected[0], originRead[0], epsilon);
    CPPUNIT_ASSERT_DOUBLES_EQUAL_MESSAGE("Incorrect origin on y", originExpected[1], originRead[1], epsilon);
    CPPUNIT_ASSERT_DOUBLES_EQUAL_MESSAGE("Incorrect origin on z", originExpected[2], originRead[2], epsilon);

    CPPUNIT_ASSERT_DOUBLES_EQUAL_MESSAGE("Incorrect size on x", sizeExpected[0], sizeRead[0], epsilon);
    CPPUNIT_ASSERT_DOUBLES_EQUAL_MESSAGE("Incorrect size on y", sizeExpected[1], sizeRead[1], epsilon);
    CPPUNIT_ASSERT_DOUBLES_EQUAL_MESSAGE("Incorrect size on z", sizeExpected[2], sizeRead[2], epsilon);

    CPPUNIT_ASSERT_EQUAL( expectedType, image->getType());

}
示例#2
0
void testCloneParticleFixedAttributes(Partio::ParticlesData* other, int& test)
{
    Partio::ParticlesData* p=Partio::cloneSchema(*other);

    int numFixedAttributes = p->numFixedAttributes();
    if (numFixedAttributes == 3) {
        std::cout << "ok " << test++
                  << " - Partio::cloneSchema() numFixedAttributes()" << std::endl;
    } else {
        std::cerr << "not ok " << test++
                  << " - Partio::cloneSchema() fixed attribute count is "
                  << numFixedAttributes << ", expected 3" << std::endl;
        exit(EXIT_FAILURE);
    }

    std::vector<std::string> expectedName(numFixedAttributes);
    std::vector<Partio::ParticleAttributeType> expectedType(numFixedAttributes);
    std::vector<int> expectedCount(numFixedAttributes);

    expectedName[0] = "origin";
    expectedType[0] = Partio::VECTOR;
    expectedCount[0] = 3;

    expectedName[1] = "uv";
    expectedType[1] = Partio::FLOAT;
    expectedCount[1] = 2;

    expectedName[2] = "sid";
    expectedType[2] = Partio::INT;
    expectedCount[2] = 1;

    // Test attributes
    for (int i=0;i<numFixedAttributes;++i) {
        Partio::FixedAttribute attr;
        p->fixedAttributeInfo(i,attr);

        if (attr.name == expectedName[i]) {
            std::cout << "ok " << test++
                      << " - Partio::cloneSchema() fixed attribute name for "
                      << attr.name << std::endl;
        } else {
            std::cerr << "not ok " << test++
                      << " - Partio::cloneSchema() fixed attribute name is "
                      << attr.name << ", expected " << expectedName[i] << std::endl;
            exit(EXIT_FAILURE);
        }

        if (attr.type == expectedType[i]) {
            std::cout << "ok " << test++
                      << " - Partio::cloneSchema() fixed attribute type for "
                      << attr.name << std::endl;
        } else {
            std::cerr << "not ok " << test++
                      << " - Partio::cloneSchema() fixed attribute type for "
                      << attr.name << ", expected "
                      << expectedType[i] << ", got " << attr.type << std::endl;
        }

        if (attr.count == expectedCount[i]) {
            std::cout << "ok " << test++
                      << " - Partio::cloneSchema() fixed attribute count for "
                      << attr.name << std::endl;
        } else {
            std::cerr << "not ok " << test++
                      << " - Partio::cloneSchema() fixed attribute count for "
                      << attr.name << ", expected "
                      << expectedCount[i] << ", got " << attr.count << std::endl;
        }
    }

    p->release();
}