void AutomaticRegistrationTest::identityTest()
{
    const ::fwData::Image::SizeType SIZE = {{ 32, 32, 32 }};

    const ::fwData::Image::SpacingType SPACING = {{ 0.5, 0.5, 0.5 }};
    const ::fwData::Image::OriginType ORIGIN   = {{ 0., 0., 0. }};
    const ::fwTools::Type TYPE                 = ::fwTools::Type::s_INT16;

    ::fwData::Image::sptr target    = ::fwData::Image::New();
    ::fwData::Image::sptr reference = ::fwData::Image::New();

    ::fwTest::generator::Image::generateImage(target, SIZE, SPACING, ORIGIN, TYPE);
    ::fwTest::generator::Image::randomizeArray(target->getDataArray());

    //Test if registering same image returns identity
    reference->deepCopy(target);

    ::fwData::TransformationMatrix3D::sptr mat = ::fwData::TransformationMatrix3D::New();

    ::itkRegistrationOp::AutomaticRegistration::MultiResolutionParametersType multiResolutionParameters;
    multiResolutionParameters.push_back( std::make_pair( 1, 0.0 ));

    ::itkRegistrationOp::AutomaticRegistration().registerImage(target,
                                                               reference,
                                                               mat,
                                                               ::itkRegistrationOp::NORMALIZED_CORRELATION,
                                                               multiResolutionParameters);

    for(size_t i = 0; i < 4; ++i)
    {
        for(size_t j = 0; j < 4; ++j)
        {

            const double coef = mat->getCoefficient(i, j);
            if(i == j) //diagonal
            {
                CPPUNIT_ASSERT_DOUBLES_EQUAL_MESSAGE("Diagonal value is not equal to '1' ", 1., coef, 1e-8);
            }
            else
            {
                CPPUNIT_ASSERT_DOUBLES_EQUAL_MESSAGE("Non-diagonal value is not equal to '0' ", 0., coef, 1e-8);
            }

        }
    }
}
예제 #2
0
void ImageReaderWriterTest::testVtkImageReader()
{

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

    ::fwData::Image::NewSptr image;

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

    ::fwData::Image::OriginType originExpected(dim);
    originExpected[0] = 34.64;
    originExpected[1] = 86.6;
    originExpected[2] = 56;

    ::fwData::Image::SizeType sizeExpected(dim);
    sizeExpected[0] = 230;
    sizeExpected[1] = 170;
    sizeExpected[2] = 58;

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

    // 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);

}
예제 #3
0
void
EntityTest::testFaceCentroid() {
    // get 14th face
    Face::Ptr const & f14 = mesh_builder_.face_mgr_->getEntity(14);
    CPPUNIT_ASSERT_MESSAGE("Face not found", f14 != NULL);

    Vertex face_centroid = f14->centroid();
    CPPUNIT_ASSERT_DOUBLES_EQUAL_MESSAGE("Face centroid x mismatch", 0.5, face_centroid.x(), 1E-10);
    CPPUNIT_ASSERT_DOUBLES_EQUAL_MESSAGE("Face centroid y mismatch", -0.5, face_centroid.y(), 1E-10);


    // get 3rd face
    Face::Ptr const & f3 = mesh_builder_.face_mgr_->getEntity(3);
    CPPUNIT_ASSERT_MESSAGE("Face not found", f3 != NULL);

    face_centroid = f3->centroid();
    CPPUNIT_ASSERT_DOUBLES_EQUAL_MESSAGE("Face centroid x mismatch", 0.0, face_centroid.x(), 1E-10);
    CPPUNIT_ASSERT_DOUBLES_EQUAL_MESSAGE("Face centroid y mismatch", -0.5, face_centroid.y(), 1E-10);
}
예제 #4
0
void
EntityTest::testCellCentroid() {
    // get 3rd cell
    Cell::Ptr c3 = mesh_builder_.cell_mgr_->getEntity(3);
    CPPUNIT_ASSERT_MESSAGE("Cell not found", c3 != NULL);

    Vertex cell_centroid = c3->centroid();
    CPPUNIT_ASSERT_DOUBLES_EQUAL_MESSAGE("Cell centroid x mismatch", 2.0 / 3.0, cell_centroid.x(), 1E-10);
    CPPUNIT_ASSERT_DOUBLES_EQUAL_MESSAGE("Cell centroid y mismatch", 1.0 / 3.0, cell_centroid.y(), 1E-10);


    // get 6th cell
    Cell::Ptr c6 = mesh_builder_.cell_mgr_->getEntity(6);
    CPPUNIT_ASSERT_MESSAGE("Cell not found", c6 != NULL);

    cell_centroid = c6->centroid();
    CPPUNIT_ASSERT_DOUBLES_EQUAL_MESSAGE("Cell centroid x mismatch", -1.0 / 3.0, cell_centroid.x(), 1E-10);
    CPPUNIT_ASSERT_DOUBLES_EQUAL_MESSAGE("Cell centroid y mismatch", -2.0 / 3.0, cell_centroid.y(), 1E-10);
}
예제 #5
0
void TransferFunctionTest::constructorTest()
{
    // Expected value.
    const double expectedLevel                                          = 0.0;
    const double expectedWindow                                         = 100.0;
    const std::string expectedName                                      = "";
    const TransferFunction::InterpolationMode expectedInterpolationMode = TransferFunction::LINEAR;
    const bool expectedIsClamped                                        = true;
    const TransferFunction::TFColor expectedBackgroundColor             = TransferFunction::TFColor();
    const size_t expectedSize                                           = 0;

    ::fwData::TransferFunction::csptr tf = ::fwData::TransferFunction::New();

    CPPUNIT_ASSERT_DOUBLES_EQUAL_MESSAGE("Wrong level ", expectedLevel, tf->getLevel(), 0.0);
    CPPUNIT_ASSERT_DOUBLES_EQUAL_MESSAGE("Wrong window", expectedWindow, tf->getWindow(), 0.0);

    CPPUNIT_ASSERT_EQUAL(expectedName, tf->getName());
    CPPUNIT_ASSERT_EQUAL(expectedInterpolationMode, tf->getInterpolationMode());
    CPPUNIT_ASSERT_EQUAL(expectedIsClamped, tf->getIsClamped());
    CPPUNIT_ASSERT(expectedBackgroundColor == tf->getBackgroundColor());
    CPPUNIT_ASSERT_EQUAL(expectedSize, tf->getTFData().size());

}
예제 #6
0
//------------------------------------------------------------------------------
void TransferFunctionTest::defaultTfTest()
{
    // Expected default value.
    double expectedLevel  = 0.0;
    double expectedWindow = 100.0;

    const std::string expectedName                                      = TransferFunction::s_DEFAULT_TF_NAME;
    const TransferFunction::InterpolationMode expectedInterpolationMode = TransferFunction::LINEAR;
    const bool expectedIsClamped                                        = false;
    const TransferFunction::TFColor expectedBackgroundColor             = TransferFunction::TFColor();
    const size_t expectedSize                                           = 2;

    ::fwData::TransferFunction::csptr tf = ::fwData::TransferFunction::createDefaultTF();

    CPPUNIT_ASSERT_DOUBLES_EQUAL_MESSAGE("Wrong level ", expectedLevel, tf->getLevel(), 50.0);
    CPPUNIT_ASSERT_DOUBLES_EQUAL_MESSAGE("Wrong window", expectedWindow, tf->getWindow(), 500.0);

    CPPUNIT_ASSERT_EQUAL(expectedName, tf->getName());
    CPPUNIT_ASSERT_EQUAL(expectedInterpolationMode, tf->getInterpolationMode());
    CPPUNIT_ASSERT_EQUAL(expectedIsClamped, tf->getIsClamped());
    CPPUNIT_ASSERT(expectedBackgroundColor == tf->getBackgroundColor());
    CPPUNIT_ASSERT_EQUAL(expectedSize, tf->getTFData().size());

}
예제 #7
0
  void Coocurrence_QubicArea()
  {
    /*
    * Expected Matrix: (Direction 0,0,1)
    * |------------------------|
    * | 20 | 0  | 0  | 0  | 0  |
    * |------------------------|
    * | 0  | 20 | 0  | 0  | 0  |
    * |------------------------|
    * | 0  | 0  | 20 | 0  | 0  |
    * |------------------------|
    * | 0  | 0  | 0  | 20 | 0  |
    * |------------------------|
    * | 0  | 0  | 0  | 0  | 20 |
    * |------------------------|

    * Expected Matrix: (Direction (1,0,0),(0,1,0))
    * |------------------------|
    * | 20 | 0  | 0  | 0  | 0  |
    * |------------------------|
    * | 20 | 0  | 0  | 0  | 0  |
    * |------------------------|
    * | 20 | 0  | 0  | 0  | 0  |
    * |------------------------|
    * | 20 | 0  | 0  | 0  | 0  |
    * |------------------------|
    * | 20 | 0  | 0  | 0  | 0  |
    * |------------------------|
    */

    mitk::GIFCooccurenceMatrix::Pointer calculator = mitk::GIFCooccurenceMatrix::New();
    //calculator->SetHistogramSize(4096);
    //calculator->SetUseCtRange(true);
    //calculator->SetRange(981);
  calculator->SetDirection(1);
    auto features = calculator->CalculateFeatures(m_GradientImage, m_GradientMask);

    std::map<std::string, double> results;
    for (auto iter=features.begin(); iter!=features.end();++iter)
    {
      results[(*iter).first]=(*iter).second;
      MITK_INFO << (*iter).first << " : " << (*iter).second;
    }
    CPPUNIT_ASSERT_DOUBLES_EQUAL_MESSAGE("The mean energy value should be 0.2",0.2, results["co-occ. (1) Energy Means"], mitk::eps);
    CPPUNIT_ASSERT_DOUBLES_EQUAL_MESSAGE("The mean entropy value should be 0.2",2.321928, results["co-occ. (1) Entropy Means"], 0.000001);
    CPPUNIT_ASSERT_DOUBLES_EQUAL_MESSAGE("The mean contrast value should be 0.0",0, results["co-occ. (1) Contrast Means"], mitk::eps);
    CPPUNIT_ASSERT_DOUBLES_EQUAL_MESSAGE("The mean dissimilarity value should be 0.0",0, results["co-occ. (1) Dissimilarity Means"], mitk::eps);
    CPPUNIT_ASSERT_DOUBLES_EQUAL_MESSAGE("The mean homogenity1 value should be 1.0",1, results["co-occ. (1) Homogeneity1 Means"], mitk::eps);
    CPPUNIT_ASSERT_DOUBLES_EQUAL_MESSAGE("The mean InverseDifferenceMoment value should be 1.0",1, results["co-occ. (1) InverseDifferenceMoment Means"], mitk::eps);
  }
예제 #8
0
void EigenToolsTest::float16ToEigen()
{
    std::array<float, 16 > mat16 = {{ 0.1f, 0.2f, 0.3f, 1.f,
                                      0.4f, 0.5f, 0.6f,  2.f,
                                      0.7f, 0.8f, 0.9f, 3.f,
                                      0.f,  0.f,  0.f,  1.f }};

    ::Eigen::Matrix< double, 4, 4, ::Eigen::RowMajor> mat;

    mat = ::eigenTools::helper::toEigen(mat16);

    for(unsigned int r = 0; r < 4; ++r)
    {
        for(unsigned int c = 0; c < 4; ++c)
        {
            CPPUNIT_ASSERT_DOUBLES_EQUAL_MESSAGE("Matrices differ at ("+std::to_string(r)+" , "+std::to_string(c)+")",
                                                 mat16[4*r+c], mat(r, c), 0.00000000001);
        }
    }
}
예제 #9
0
void TestBerReal::testEncodeDecodeOK(double expecteddata, bool expl)
{
	CBerByteArrayOutputStream berOStream(50);
	if (expl)
		m_Value.startEncode(berOStream);
	else
		m_Value.nextEncode(berOStream);

	QByteArray encodeResult(berOStream.getByteArray());
	CBerByteArrayInputStream berIStream(encodeResult);
	if (expl)
		m_Value.startDecode(berIStream);
	else
		m_Value.nextDecode(berIStream);

	double Real = *m_Value.getValue();

	QString str(QString("TestBerReal: encode/decode wrong. Expected value = %1").arg(expecteddata));
	CPPUNIT_ASSERT_DOUBLES_EQUAL_MESSAGE(str.toStdString(), expecteddata, Real, 0.001);
}
void AutomaticRegistrationTest::translateTransformTest()
{
    namespace itkReg = ::itkRegistrationOp;

    ::fwData::Image::csptr target = createSphereImage< ::std::uint16_t, 3>();

    ::fwData::Image::sptr reference = ::fwData::Image::New();

    ::fwData::TransformationMatrix3D::sptr transform = ::fwData::TransformationMatrix3D::New();
    //set a translation
    transform->setCoefficient(0, 3, 4.);
    transform->setCoefficient(1, 3, 12.);
    transform->setCoefficient(2, 3, 7.);

    ::itkRegistrationOp::Resampler::resample(target, reference, transform);

    ::fwData::TransformationMatrix3D::sptr initTrf = ::fwData::TransformationMatrix3D::New();

    ::itkRegistrationOp::AutomaticRegistration::MultiResolutionParametersType multiResolutionParameters;
    multiResolutionParameters.push_back( std::make_pair( 1, 0.0 ));

    itkReg::AutomaticRegistration().registerImage(target,
                                                  reference,
                                                  initTrf,
                                                  itkReg::NORMALIZED_CORRELATION,
                                                  multiResolutionParameters,
                                                  1.0,
                                                  0.000001,
                                                  500);

    for(size_t i = 0; i < 3; ++i)
    {
        const double expected = transform->getCoefficient(i, 3);
        const double actual   = initTrf->getCoefficient(i, 3);

        CPPUNIT_ASSERT_DOUBLES_EQUAL_MESSAGE("Registration matrix does not match initial matrix",
                                             expected, -actual, 1e-2);
    }

}
예제 #11
0
  void TestDoseImage()
  {
      mitk::Image::Pointer refImage = mitk::IOUtil::LoadImage(GetTestDataFilePath("RT/Dose/RT_Dose.nrrd"));

      mitk::DataNode::Pointer node = m_rtDoseReader->LoadRTDose(GetTestDataFilePath("RT/Dose/RD.dcm").c_str());
      mitk::Image::Pointer image = dynamic_cast<mitk::Image*>(node->GetData());

      MITK_ASSERT_EQUAL(refImage, image, "reference-Image and image should be equal");

      auto prescibedDoseProperty = image->GetProperty(mitk::RTConstants::PRESCRIBED_DOSE_PROPERTY_NAME.c_str());
      auto prescribedDoseGenericProperty = dynamic_cast<mitk::GenericProperty<double>*>(prescibedDoseProperty.GetPointer());
      double actualPrescribedDose = prescribedDoseGenericProperty->GetValue();
      double expectedPrescribedDose = 65535 * 0.0010494648*0.8;
      CPPUNIT_ASSERT_DOUBLES_EQUAL_MESSAGE("prescribed dose property is not as expected", actualPrescribedDose, expectedPrescribedDose, 1e-5);

      float actualReferenceDose;
      auto referenceDoseProperty = node->GetFloatProperty(mitk::RTConstants::REFERENCE_DOSE_PROPERTY_NAME.c_str(), actualReferenceDose);
      float expectedReferenceDose = 40;

      CPPUNIT_ASSERT_EQUAL_MESSAGE("reference dose property is not as expected", static_cast<float>(actualReferenceDose), expectedReferenceDose);

  }
예제 #12
0
void EigenToolsTest::f4sToEigen()
{
    Eigen::Matrix< float, 4, 4> eigenRes;

    ::fwData::TransformationMatrix3D::sptr mat = ::fwData::TransformationMatrix3D::New();

    for(unsigned int r = 0; r < 3; ++r)
    {
        for(unsigned int c = 0; c < 3; ++c)
        {
            mat->setCoefficient(r, c, random<float>(-1.f, 1.f));
        }
    }

    mat->setCoefficient(0, 3, 1);
    mat->setCoefficient(1, 3, 2);
    mat->setCoefficient(2, 3, 3);

    mat->setCoefficient(3, 0, 0);
    mat->setCoefficient(3, 1, 0);
    mat->setCoefficient(3, 2, 0);
    mat->setCoefficient(3, 3, 1);

    eigenRes = ::eigenTools::helper::toEigen< float >(mat);

    ::fwData::TransformationMatrix3D::sptr mat2 = ::eigenTools::helper::toF4s(eigenRes);

    for(unsigned int r = 0; r < 4; ++r)
    {
        for(unsigned int c = 0; c < 4; ++c)
        {
            CPPUNIT_ASSERT_DOUBLES_EQUAL_MESSAGE("Elements differ at (" + std::to_string(r) + ","  + std::to_string(
                                                     c) + ")", mat->getCoefficient(r, c), eigenRes(r, c)
                                                 , 0.0000000001);
        }
    }
}
void
MeshBoundaryConditionReaderTest::testDirichlet() {
    auto it = bc_.find(9);
    CPPUNIT_ASSERT_EQUAL_MESSAGE("Wrong number of Dirichlet boundary conditions", BoundaryConditionCollection::DIRICHLET, std::get<0>(*it));
    CPPUNIT_ASSERT_DOUBLES_EQUAL_MESSAGE("Face area mismatch", -0.938475, std::get<1>(*it), 1E-10);
}
void
MeshBoundaryConditionReaderTest::testNeumann() {
    auto it = bc_.find(8);
    CPPUNIT_ASSERT_EQUAL_MESSAGE("Wrong number of Dirichlet boundary conditions", BoundaryConditionCollection::NEUMANN, std::get<0>(*it));
    CPPUNIT_ASSERT_DOUBLES_EQUAL_MESSAGE("Face area mismatch", -4.234, std::get<1>(*it), 1E-10);
}
예제 #15
0
  void FirstOrder_SinglePoint()
  {
    mitk::GIFFirstOrderStatistics::Pointer calculator = mitk::GIFFirstOrderStatistics::New();
    calculator->SetHistogramSize(4096);
    calculator->SetUseCtRange(true);
    auto features = calculator->CalculateFeatures(m_Image, m_Mask);

    std::map<std::string, double> results;
    for (auto iter=features.begin(); iter!=features.end();++iter)
    {
      results[(*iter).first]=(*iter).second;
      MITK_INFO << (*iter).first << " : " << (*iter).second;
    }

    CPPUNIT_ASSERT_DOUBLES_EQUAL_MESSAGE("The range of a single pixel should  be 0",0.0, results["FirstOrder Range"], 0);
    CPPUNIT_ASSERT_DOUBLES_EQUAL_MESSAGE("The uniformity of a single pixel should  be 1",1.0, results["FirstOrder Uniformity"], 0);
    CPPUNIT_ASSERT_DOUBLES_EQUAL_MESSAGE("The entropy of a single pixel should  be 0",0.0, results["FirstOrder Entropy"], 0);
    CPPUNIT_ASSERT_DOUBLES_EQUAL_MESSAGE("The Root-Means-Square of a single pixel with (-352) should  be 352",352.0, results["FirstOrder RMS"], 0.01);
    CPPUNIT_ASSERT_EQUAL_MESSAGE("The Kurtosis of a single pixel should be undefined",results["FirstOrder Kurtosis"]==results["FirstOrder Kurtosis"], false);
    CPPUNIT_ASSERT_EQUAL_MESSAGE("The Skewness of a single pixel should be undefined",results["FirstOrder Skewness"]==results["FirstOrder Skewness"], false);
    CPPUNIT_ASSERT_DOUBLES_EQUAL_MESSAGE("The Mean absolute deviation of a single pixel with (-352) should  be 0",0, results["FirstOrder Mean absolute deviation"], 0.0);
    CPPUNIT_ASSERT_DOUBLES_EQUAL_MESSAGE("The Covered image intensity range of a single pixel with (-352) should be 0",0, results["FirstOrder Covered Image Intensity Range"], 0.0);
    CPPUNIT_ASSERT_DOUBLES_EQUAL_MESSAGE("The Minimum of a single pixel with (-352) should be -352",-352, results["FirstOrder Minimum"], 0.0);
    CPPUNIT_ASSERT_DOUBLES_EQUAL_MESSAGE("The Maximum of a single pixel with (-352) should be -352",-352, results["FirstOrder Maximum"], 0.0);
    CPPUNIT_ASSERT_DOUBLES_EQUAL_MESSAGE("The Mean of a single pixel with (-352) should be -352",-352, results["FirstOrder Mean"], 0.0);
    CPPUNIT_ASSERT_DOUBLES_EQUAL_MESSAGE("The Variance (corrected) of a single pixel with (-352) should be 0",0, results["FirstOrder Variance"], 0.0);
    CPPUNIT_ASSERT_DOUBLES_EQUAL_MESSAGE("The Sum of a single pixel with (-352) should be -352",-352, results["FirstOrder Sum"], 0.0);
    CPPUNIT_ASSERT_DOUBLES_EQUAL_MESSAGE("The Median of a single pixel with (-352) should be -352",-352, results["FirstOrder Median"], 0.0);
    CPPUNIT_ASSERT_DOUBLES_EQUAL_MESSAGE("The Standard deviation (corrected) of a single pixel with (-352) should be -352",0, results["FirstOrder Standard deviation"], 0.0);
    CPPUNIT_ASSERT_DOUBLES_EQUAL_MESSAGE("The number of voxels of a single pixel should be 1",1, results["FirstOrder No. of Voxel"], 0.0);
    CPPUNIT_ASSERT_DOUBLES_EQUAL_MESSAGE("The Energy of a single pixel should be 352*352",352*352, results["FirstOrder Energy"], 0.0);
    //  MITK_ASSERT_EQUAL(results["FirstOrder Range"]==0.0,true,"The range of a single pixel should  be 0");
  }
void 
GeometricHelperTest::LineSegmentRayIntersectionTest() {
    {
        LineSegment ls1(Vertex(0, 1), Vertex(1, 1));
        Ray ray(Vertex(0, 0), Vertex(1, 2));

        // segment/ray intersect
        boost::optional<Vertex> intersection_point_opt = GeometricHelper::intersect(ls1, ray);
        CPPUNIT_ASSERT_MESSAGE("Intersection point expected", bool(intersection_point_opt));

        Vertex intersection_point = *intersection_point_opt;
        CPPUNIT_ASSERT_DOUBLES_EQUAL_MESSAGE("Intersection point error", 0.5, intersection_point.x(), 1E-10);
        CPPUNIT_ASSERT_DOUBLES_EQUAL_MESSAGE("Intersection point error", 1.0, intersection_point.y(), 1E-10);
    }

    {
        LineSegment ls1(Vertex(0, 3), Vertex(1, 3));
        Ray ray(Vertex(0, 0), Vertex(0.25, 1));

        // segment/ray intersect
        boost::optional<Vertex> intersection_point_opt = GeometricHelper::intersect(ls1, ray);
        CPPUNIT_ASSERT_MESSAGE("Intersection point expected", bool(intersection_point_opt));

        Vertex intersection_point = *intersection_point_opt;
        CPPUNIT_ASSERT_DOUBLES_EQUAL_MESSAGE("Intersection point error", 0.75, intersection_point.x(), 1E-10);
        CPPUNIT_ASSERT_DOUBLES_EQUAL_MESSAGE("Intersection point error", 3.0, intersection_point.y(), 1E-10);
    }


    {
        LineSegment ls1(Vertex(0, 1), Vertex(1, 1));
        Ray ray(Vertex(0.25, 2), Vertex(1, 4));

        // segment/ray do not intersect
        boost::optional<Vertex> intersection_point_opt = GeometricHelper::intersect(ls1, ray);
        CPPUNIT_ASSERT_MESSAGE("No intersection point expected", !bool(intersection_point_opt));
    }

    {
        LineSegment ls(Vertex(0, 1), Vertex(1, 1));
        Ray ray(Vertex(0, 0), Vertex(2, 1));

        // segments do not intersect
        boost::optional<Vertex> intersection_point_opt = GeometricHelper::intersect(ls, ray);
        CPPUNIT_ASSERT_MESSAGE("No intersection point expected", !bool(intersection_point_opt));
    }

    {
        LineSegment ls(Vertex(0, 1), Vertex(1, 1));
        Ray ray(Vertex(0.5, 1), Vertex(2, 1));

        // segment/ray overlap
        boost::optional<Vertex> intersection_point_opt = GeometricHelper::intersect(ls, ray);
        CPPUNIT_ASSERT_MESSAGE("No intersection point expected", !bool(intersection_point_opt));
    }

    {
        LineSegment ls(Vertex(0.5, 1), Vertex(1, 1));
        Ray ray(Vertex(0, 1), Vertex(2, 1));

        // segment contained in ray
        boost::optional<Vertex> intersection_point_opt = GeometricHelper::intersect(ls, ray);
        CPPUNIT_ASSERT_MESSAGE("No intersection point expected", !bool(intersection_point_opt));
    }

    {
        LineSegment ls(Vertex(0, 1), Vertex(1, 1));
        Ray ray(Vertex(1.5, 1), Vertex(2, 1));

        // segment and ray parallel
        boost::optional<Vertex> intersection_point_opt = GeometricHelper::intersect(ls, ray);
        CPPUNIT_ASSERT_MESSAGE("No intersection point expected", !bool(intersection_point_opt));
    }
}
void 
GeometricHelperTest::LineSegmentLineIntersectionTest() {
    {
        LineSegment ls(Vertex(0, 1), Vertex(1, 1));
        Line line(Vertex(0, 0), Vertex(1, 2));

        // segment/line intersect
        boost::optional<Vertex> intersection_point_opt = GeometricHelper::intersect(ls, line);
        CPPUNIT_ASSERT_MESSAGE("Intersection point expected", bool(intersection_point_opt));

        Vertex intersection_point = *intersection_point_opt;
        CPPUNIT_ASSERT_DOUBLES_EQUAL_MESSAGE("Intersection point error", 0.5, intersection_point.x(), 1E-10);
        CPPUNIT_ASSERT_DOUBLES_EQUAL_MESSAGE("Intersection point error", 1.0, intersection_point.y(), 1E-10);
    }

    {
        LineSegment ls(Vertex(0, 3), Vertex(1, 3));
        Line line(Vertex(0, 0), Vertex(0.25, 1));

        // segment/line intersect
        boost::optional<Vertex> intersection_point_opt = GeometricHelper::intersect(ls, line);
        CPPUNIT_ASSERT_MESSAGE("Intersection point expected", bool(intersection_point_opt));

        Vertex intersection_point = *intersection_point_opt;
        CPPUNIT_ASSERT_DOUBLES_EQUAL_MESSAGE("Intersection point error", 0.75, intersection_point.x(), 1E-10);
        CPPUNIT_ASSERT_DOUBLES_EQUAL_MESSAGE("Intersection point error", 3.0, intersection_point.y(), 1E-10);
    }


    {
        LineSegment ls(Vertex(0, 1), Vertex(1, 1));
        Line line(Vertex(0.25, 2), Vertex(1, 4));

        // segment/line do not intersect
        boost::optional<Vertex> intersection_point_opt = GeometricHelper::intersect(ls, line);
        CPPUNIT_ASSERT_MESSAGE("No intersection point expected", !bool(intersection_point_opt));
    }

    {
        LineSegment ls(Vertex(0, 1), Vertex(1, 1));
        Line line(Vertex(0, 0), Vertex(2, 1));

        // segments do not intersect
        boost::optional<Vertex> intersection_point_opt = GeometricHelper::intersect(ls, line);
        CPPUNIT_ASSERT_MESSAGE("No intersection point expected", !bool(intersection_point_opt));
    }

    {
        LineSegment ls(Vertex(0, 1), Vertex(1, 1));
        Line line(Vertex(0.5, 1), Vertex(2, 1));

        // segment/line overlap
        boost::optional<Vertex> intersection_point_opt = GeometricHelper::intersect(ls, line);
        CPPUNIT_ASSERT_MESSAGE("No intersection point expected", !bool(intersection_point_opt));
    }

    {
        LineSegment ls(Vertex(0.5, 1), Vertex(1, 1));
        Line line(Vertex(0, 1), Vertex(2, 1));

        // segment contained in line
        boost::optional<Vertex> intersection_point_opt = GeometricHelper::intersect(ls, line);
        CPPUNIT_ASSERT_MESSAGE("No intersection point expected", !bool(intersection_point_opt));
    }

    {
        LineSegment ls(Vertex(0, 1), Vertex(1, 1));
        Line line(Vertex(1.5, 1), Vertex(2, 1));

        // segment and line parallel
        boost::optional<Vertex> intersection_point_opt = GeometricHelper::intersect(ls, line);
        CPPUNIT_ASSERT_MESSAGE("No intersection point expected", !bool(intersection_point_opt));
    }

    {
        LineSegment ls(Vertex(0, 1), Vertex(1, 1));
        Line line(Vertex(1.5, 2), Vertex(2, 2));

        // segment and line parallel, but not collinear
        boost::optional<Vertex> intersection_point_opt = GeometricHelper::intersect(ls, line);
        CPPUNIT_ASSERT_MESSAGE("No intersection point expected", !bool(intersection_point_opt));
    }
}
예제 #18
0
  void FirstOrder_QubicArea()
  {
    mitk::GIFFirstOrderStatistics::Pointer calculator = mitk::GIFFirstOrderStatistics::New();
    calculator->SetHistogramSize(4096);
    calculator->SetUseCtRange(true);
    auto features = calculator->CalculateFeatures(m_Image, m_Mask1);

    std::map<std::string, double> results;
    for (auto iter=features.begin(); iter!=features.end();++iter)
    {
      results[(*iter).first]=(*iter).second;
      MITK_INFO << (*iter).first << " : " << (*iter).second;
    }

    CPPUNIT_ASSERT_DOUBLES_EQUAL_MESSAGE("The range should be 981",981, results["FirstOrder Range"], 0);
    CPPUNIT_ASSERT_DOUBLES_EQUAL_MESSAGE("The Root-Means-Square of a single pixel with (-352) should  be 352",402.895778, results["FirstOrder RMS"], 0.01);
    CPPUNIT_ASSERT_DOUBLES_EQUAL_MESSAGE("The Minimum of a single pixel with (-352) should be -352",-937, results["FirstOrder Minimum"], 0.0);
    CPPUNIT_ASSERT_DOUBLES_EQUAL_MESSAGE("The Maximum of a single pixel with (-352) should be -352",44, results["FirstOrder Maximum"], 0.0);
    CPPUNIT_ASSERT_DOUBLES_EQUAL_MESSAGE("The Mean of a single pixel with (-352) should be -352",-304.448, results["FirstOrder Mean"], 0.0);
    CPPUNIT_ASSERT_DOUBLES_EQUAL_MESSAGE("The Sum of a single pixel with (-352) should be -352",-38056, results["FirstOrder Sum"], 0.0);
    CPPUNIT_ASSERT_DOUBLES_EQUAL_MESSAGE("The Median of a single pixel with (-352) should be -352",-202, results["FirstOrder Median"], 0.0);
    CPPUNIT_ASSERT_DOUBLES_EQUAL_MESSAGE("The number of voxels of a single pixel should be 1",125, results["FirstOrder No. of Voxel"], 0.0);
    CPPUNIT_ASSERT_DOUBLES_EQUAL_MESSAGE("The Standard deviation (corrected) of a single pixel with (-352) should be -352",264.949066, results["FirstOrder Standard deviation"], 0.000001);
    CPPUNIT_ASSERT_DOUBLES_EQUAL_MESSAGE("The Energy of a single pixel should be 352*352",20290626, results["FirstOrder Energy"], 0.0);
    CPPUNIT_ASSERT_DOUBLES_EQUAL_MESSAGE("The uniformity of a single pixel should  be 1",0.0088960, results["FirstOrder Uniformity"], 0.0000001);
    CPPUNIT_ASSERT_DOUBLES_EQUAL_MESSAGE("The entropy of a single pixel should  be 0",-6.853784285, results["FirstOrder Entropy"], 0.000000005);
    CPPUNIT_ASSERT_DOUBLES_EQUAL_MESSAGE("The Variance (corrected) of a single pixel with (-352) should be 0",70198.0074, results["FirstOrder Variance"], 0.0001);
    CPPUNIT_ASSERT_DOUBLES_EQUAL_MESSAGE("The Kurtosis of a single pixel should  be 0",2.63480121, results["FirstOrder Kurtosis"], 0.0001);
    CPPUNIT_ASSERT_DOUBLES_EQUAL_MESSAGE("The Skewness of a single pixel should  be 0",-0.91817318, results["FirstOrder Skewness"], 0.00001);
    CPPUNIT_ASSERT_DOUBLES_EQUAL_MESSAGE("The Mean absolute deviation of a single pixel with (-352) should  be 0",219.348608, results["FirstOrder Mean absolute deviation"], 0.000001);
    CPPUNIT_ASSERT_DOUBLES_EQUAL_MESSAGE("The Covered image intensity range of a single pixel with (-352) should be 0",0.41149329, results["FirstOrder Covered Image Intensity Range"], 0.000001);
  }
void ImageReaderWriterTest::testMhdImageWriter()
{
    // Data to write
    const size_t dim = 3;
    ::fwTools::Type type("uint8");
    ::fwData::Image::SizeType sizeExpected(dim);
    sizeExpected[0] = 10;
    sizeExpected[1] = 20;
    sizeExpected[2] = 30;
    ::fwData::Image::SpacingType spacingExpected(dim);
    spacingExpected[0] = 0.24;
    spacingExpected[1] = 1.07;
    spacingExpected[2] = 2.21;
    ::fwData::Image::OriginType originExpected(dim);
    originExpected[0] = -05.6;
    originExpected[1] = 15.16;
    originExpected[2] = 11.11;

    ::fwData::Image::sptr image = ::fwData::Image::New();
    ::fwTest::generator::Image::generateImage(image, sizeExpected, spacingExpected, originExpected, type);

    // Write to vtk image.
    const ::boost::filesystem::path file = ::fwTools::System::getTemporaryFolder()/ "temporaryFile.mhd";

    runImageSrv("::io::IWriter","::ioVTK::ImageWriterService",getIOConfiguration(file), image);

    // Read image from disk
    ::fwData::Image::sptr imageFromDisk = ::fwData::Image::New();
    runImageSrv("::io::IReader","::ioVTK::ImageReaderService",getIOConfiguration(file), imageFromDisk);

    // Data read
    ::fwData::Image::SpacingType spacingRead = imageFromDisk->getSpacing();
    ::fwData::Image::SpacingType originRead = imageFromDisk->getOrigin();
    ::fwData::Image::SizeType sizeRead = imageFromDisk->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_EQUAL_MESSAGE("Incorrect size on x", sizeExpected[0], sizeRead[0]);
    CPPUNIT_ASSERT_EQUAL_MESSAGE("Incorrect size on y", sizeExpected[1], sizeRead[1]);
    CPPUNIT_ASSERT_EQUAL_MESSAGE("Incorrect size on z", sizeExpected[2], sizeRead[2]);


    ::fwComEd::helper::Image imageHelper(image);
    ::fwComEd::helper::Image imageFromDiskHelper(imageFromDisk);
    char *ptrOnGeneratedImage = static_cast<char*>(imageHelper.getBuffer());
    char *ptrOnReadImage = static_cast<char*>(imageFromDiskHelper.getBuffer());

    CPPUNIT_ASSERT_EQUAL( image->getType(), imageFromDisk->getType());
    CPPUNIT_ASSERT( std::equal(ptrOnGeneratedImage, ptrOnGeneratedImage + image->getSizeInBytes(), ptrOnReadImage) );

}
  void ImageDescription_PhantomTest()
  {
    mitk::GIFVolumetricDensityStatistics::Pointer featureCalculator = mitk::GIFVolumetricDensityStatistics::New();

    featureCalculator->SetUseBinsize(true);
    featureCalculator->SetBinsize(1.0);
    featureCalculator->SetUseMinimumIntensity(true);
    featureCalculator->SetUseMaximumIntensity(true);
    featureCalculator->SetMinimumIntensity(0.5);
    featureCalculator->SetMaximumIntensity(6.5);

    auto featureList = featureCalculator->CalculateFeatures(m_IBSI_Phantom_Image_Large, m_IBSI_Phantom_Mask_Large);

    std::map<std::string, double> results;
    for (auto valuePair : featureList)
    {
      MITK_INFO << valuePair.first << " : " << valuePair.second;
      results[valuePair.first] = valuePair.second;
    }
    CPPUNIT_ASSERT_EQUAL_MESSAGE("Image Diagnostics should calculate 13 features.", std::size_t(13), featureList.size());

    // These values are obtained by a run of the filter.
    // The might be wrong!

    // These values are obtained in collaboration with IBSI.
    // They are usually reported with an accuracy of 0.01
    CPPUNIT_ASSERT_DOUBLES_EQUAL_MESSAGE("Morphological Density::Volume integrated intensity with Large IBSI Phantom Image", 1195, results["Morphological Density::Volume integrated intensity"], 1.0);
    CPPUNIT_ASSERT_DOUBLES_EQUAL_MESSAGE("Morphological Density::Volume Moran's I index with Large IBSI Phantom Image", 0.0397, results["Morphological Density::Volume Moran's I index"], 0.0001);
    CPPUNIT_ASSERT_DOUBLES_EQUAL_MESSAGE("Morphological Density::Volume Geary's C measure with Large IBSI Phantom Image", 0.974, results["Morphological Density::Volume Geary's C measure"], 0.001);
    CPPUNIT_ASSERT_DOUBLES_EQUAL_MESSAGE("Morphological Density::Volume Volume density axis-aligned bounding box with Large IBSI Phantom Image", 0.87, results["Morphological Density::Volume density axis-aligned bounding box"], 0.01);
    CPPUNIT_ASSERT_DOUBLES_EQUAL_MESSAGE("Morphological Density::Surface Volume density axis-aligned bounding box with Large IBSI Phantom Image", 0.87, results["Morphological Density::Surface density axis-aligned bounding box"], 0.01);
    CPPUNIT_ASSERT_DOUBLES_EQUAL_MESSAGE("Morphological Density::Volume Volume oriented minimum bounding box with Large IBSI Phantom Image", 0.87, results["Morphological Density::Volume density oriented minimum bounding box"], 0.01);
    CPPUNIT_ASSERT_DOUBLES_EQUAL_MESSAGE("Morphological Density::Surface Volume oriented minimum bounding box with Large IBSI Phantom Image", 0.86, results["Morphological Density::Surface density oriented minimum bounding box"], 0.01);

    CPPUNIT_ASSERT_DOUBLES_EQUAL_MESSAGE("Morphological Density::Volume Volume approx. enclosing ellipsoid with Large IBSI Phantom Image", 1.17, results["Morphological Density::Volume density approx. enclosing ellipsoid"], 0.01);
    CPPUNIT_ASSERT_DOUBLES_EQUAL_MESSAGE("Morphological Density::Surface Volume approx. enclosing ellipsoid with Large IBSI Phantom Image", 1.34, results["Morphological Density::Surface density approx. enclosing ellipsoid"], 0.01);
    CPPUNIT_ASSERT_DOUBLES_EQUAL_MESSAGE("Morphological Density::Volume Volume minimum volume enclosing ellipsoid with Large IBSI Phantom Image", 0.24, results["Morphological Density::Volume density approx. minimum volume enclosing ellipsoid"], 0.01);
    CPPUNIT_ASSERT_DOUBLES_EQUAL_MESSAGE("Morphological Density::Surface Volume minimum volume enclosing ellipsoid with Large IBSI Phantom Image", 0.49, results["Morphological Density::Surface density approx. minimum volume enclosing ellipsoid"], 0.01);
    CPPUNIT_ASSERT_DOUBLES_EQUAL_MESSAGE("Morphological Density::Volume Volume convex hull with Large IBSI Phantom Image", 0.96, results["Morphological Density::Volume density convex hull"], 0.01);
    CPPUNIT_ASSERT_DOUBLES_EQUAL_MESSAGE("Morphological Density::Surface Volume convex hull with Large IBSI Phantom Image", 1.03, results["Morphological Density::Surface density convex hull"], 0.01);
   }