Example #1
0
//--------------------------------------------------------------------------------------------------
/// 
//--------------------------------------------------------------------------------------------------
TEST(ArrayTest, resize)
{
    // Vec3f array
    Vec3dArray vA;
    vA.resize(4);
    ASSERT_EQ(4u, vA.size());

    vA[0] = Vec3d(1,2,3);
    vA[1] = Vec3d(1.1, 2.2, 3.3);
    vA[2] = Vec3d(0,0,0);
    vA[3] = Vec3d(4,5,6);

    vA.resize(5);
    vA[4] = Vec3d(9.9, 0, 3.5);

    ASSERT_EQ(5u, vA.size());
    ASSERT_EQ(true, vA[0] == Vec3d(1,2,3));
    ASSERT_EQ(true, vA[4] == Vec3d(9.9,0,3.5));

    vA.resize(3);
    ASSERT_EQ(3u, vA.size());
    ASSERT_EQ(true, vA[0] == Vec3d(1, 2, 3));
    ASSERT_EQ(true, vA[1] == Vec3d(1.1, 2.2, 3.3));
    ASSERT_EQ(true, vA[2] == Vec3d(0, 0, 0));
}
//--------------------------------------------------------------------------------------------------
/// 
//--------------------------------------------------------------------------------------------------
void BoundingBox::add(const Vec3dArray& points)
{
    size_t i;
    for (i = 0; i < points.size(); i++)
    {
        add(points[i]);
    }
}
Example #3
0
//--------------------------------------------------------------------------------------------------
/// 
//--------------------------------------------------------------------------------------------------
TEST(ArrayTest, BasicVec3dArray)
{
    // Vec3f array
    Vec3dArray vA;
    vA.resize(4);
    ASSERT_EQ(4u, vA.size());

    vA[0] = Vec3d(1,2,3);
    vA[1] = Vec3d(1.1, 2.2, 3.3);
    vA[2] = Vec3d(0,0,0);
    vA[3] = Vec3d(4,5,6);

    ASSERT_EQ(true, vA[0] == Vec3d(1, 2, 3));
    ASSERT_EQ(true, vA[1] == Vec3d(1.1, 2.2, 3.3));
    ASSERT_EQ(true, vA[2] == Vec3d(0, 0, 0));
    ASSERT_EQ(true, vA[3] == Vec3d(4, 5, 6));

    const double* pf = vA.ptr()->ptr();

    ASSERT_DOUBLE_EQ(1.0, pf[0]);
    ASSERT_DOUBLE_EQ(2.0, pf[1]);
    ASSERT_DOUBLE_EQ(3.0, pf[2]);
    ASSERT_DOUBLE_EQ(1.1, pf[3]);
    ASSERT_DOUBLE_EQ(2.2, pf[4]);
    ASSERT_DOUBLE_EQ(3.3, pf[5]);
    ASSERT_DOUBLE_EQ(0.0, pf[6]);
    ASSERT_DOUBLE_EQ(0.0, pf[7]);
    ASSERT_DOUBLE_EQ(0.0, pf[8]);
    ASSERT_DOUBLE_EQ(4.0, pf[9]);
    ASSERT_DOUBLE_EQ(5.0, pf[10]);
    ASSERT_DOUBLE_EQ(6.0, pf[11]);

    vA.clear();

    ASSERT_EQ(0u, vA.size());
}
//--------------------------------------------------------------------------------------------------
/// Classify where the points are located relative to the plane
/// 
/// \param  points  Points to test for location relative the plane
///  
/// \return Plane::FRONT if points are either Plane::FRONT or Plane::ON\n
///         Plane::BACK if points are either Plane::BACK or Plane::ON\n
///         Plane::ON if all points are Plane::ON\n
///         Plane::BOTH if points are located on both sides
//--------------------------------------------------------------------------------------------------
Plane::Side Plane::side(const Vec3dArray& points) const
{
    // Code taken from
    // http://code.google.com/p/papervision3d/source/browse/trunk/as3/trunk/src/org/papervision3d/core/math/util/ClassificationUtil.as

    cvf::uint frontCount = 0;
    cvf::uint backCount = 0;

    for (size_t i = 0; i < points.size(); i++)
    {
        Side s = side(points[i]);

        if (s == FRONT)
        {
            frontCount++;
        }
        else if (s == BACK)
        {
            backCount++;
        }
    }
    
    if (frontCount > 0 && backCount == 0)
    {
        return FRONT;
    }
    else if (frontCount == 0 && backCount > 0)
    {
        return BACK;
    }
    else if (frontCount > 0 && backCount > 0)
    {
        return BOTH;
    }
    else
    {
        return ON;
    }
}