Exemple #1
0
void TestDim::index() {
	Dim sca;
	Dim row2(Dim::row_vec(2));
	Dim row3(Dim::row_vec(3));
	Dim col2(Dim::col_vec(2));
	Dim col3(Dim::col_vec(3));
	Dim mat22(Dim::matrix(2,2));
	Dim mat32(Dim::matrix(3,2));
	Dim mat23(Dim::matrix(2,3));
	Dim mat33(Dim::matrix(3,3));

	CPPUNIT_ASSERT      (sca.index_dim(DoubleIndex::one_elt(sca,0,0))==sca);

	CPPUNIT_ASSERT      (row3.index_dim(DoubleIndex::one_elt(row3,0,0))==sca);
	CPPUNIT_ASSERT      (row3.index_dim(DoubleIndex::one_row(row3,0))==row3);
	CPPUNIT_ASSERT      (row3.index_dim(DoubleIndex::cols(row3,0,1))==row2);

	CPPUNIT_ASSERT      (col3.index_dim(DoubleIndex::one_elt(col3,0,0))==sca);
	CPPUNIT_ASSERT      (col3.index_dim(DoubleIndex::one_col(col3,0))==col3);
	CPPUNIT_ASSERT      (col3.index_dim(DoubleIndex::rows(col3,0,1))==col2);

	CPPUNIT_ASSERT      (mat23.index_dim(DoubleIndex::one_elt(mat23,0,0))==sca);
	CPPUNIT_ASSERT      (mat23.index_dim(DoubleIndex::one_row(mat23,0))==row3);
	CPPUNIT_ASSERT      (mat23.index_dim(DoubleIndex::one_col(mat23,0))==col2);
	CPPUNIT_ASSERT      (mat23.index_dim(DoubleIndex::cols(mat23,0,1))==mat22);
	CPPUNIT_ASSERT      (mat23.index_dim(DoubleIndex::subrow(mat23,0,0,1))==row2);
	CPPUNIT_ASSERT      (mat23.index_dim(DoubleIndex::all(mat23))==mat23);

	CPPUNIT_ASSERT      (mat32.index_dim(DoubleIndex::subcol(mat32,0,1,0))==col2);

	CPPUNIT_ASSERT      (mat33.index_dim(DoubleIndex::rows(mat33,0,1))==mat23);
	CPPUNIT_ASSERT      (mat33.index_dim(DoubleIndex::cols(mat33,0,1))==mat32);
}
TEST(PaletteTranslator, BuildSortLuminance)
{
	//uint32 y = r * 299 + g * 587 + b * 114;

	Color col0(0, 0, 10);
	Color col1(0, 0, 11);
	Color col2(10, 0, 0);
	Color col3(11, 0, 0);
	Color col4(0, 10, 0);
	Color col5(0, 11, 0);

	Palette pal;
	pal.m_count = 6;
	pal[0] = col3;
	pal[1] = col5;
	pal[2] = col1;
	pal[3] = col2;
	pal[4] = col4;
	pal[5] = col0;

	Palette exp;
	exp.m_count = 6;
	exp[0] = col0;
	exp[1] = col1;
	exp[2] = col2;
	exp[3] = col3;
	exp[4] = col4;
	exp[5] = col5;

	PaletteTranslator pt;
	pt.BuildSortLuminance(pal, nullptr);

	ASSERT_TRUE( pal == exp );
}
Exemple #3
0
BOOST_AUTO_TEST_CASE_TEMPLATE(create, T, float_types) {
	// default constructor
	vmath::core::Matrix<T, 2, 3> M_default;
	BOOST_CHECK_SMALL(M_default[0][0], static_cast<T>(1e-7));
	BOOST_CHECK_SMALL(M_default[0][1], static_cast<T>(1e-7));
	BOOST_CHECK_SMALL(M_default[1][0], static_cast<T>(1e-7));
	BOOST_CHECK_SMALL(M_default[1][1], static_cast<T>(1e-7));
	BOOST_CHECK_SMALL(M_default[2][0], static_cast<T>(1e-7));
	BOOST_CHECK_SMALL(M_default[2][1], static_cast<T>(1e-7));
	// parameterized constructor
	std::array<vmath::core::Vector<T, 2>, 3> data = {{
			vmath::core::Vector<T, 2>(static_cast<T>(1.0), static_cast<T>(2.0)),
			vmath::core::Vector<T, 2>(static_cast<T>(3.0), static_cast<T>(4.0)),
			vmath::core::Vector<T, 2>(static_cast<T>(5.0), static_cast<T>(6.0))
		}};
	vmath::core::Matrix<T, 2, 3> M_param(data);
	BOOST_CHECK_CLOSE(M_param[0][0], static_cast<T>(1.0), 1e-4f);
	BOOST_CHECK_CLOSE(M_param[0][1], static_cast<T>(2.0), 1e-4f);
	BOOST_CHECK_CLOSE(M_param[1][0], static_cast<T>(3.0), 1e-4f);
	BOOST_CHECK_CLOSE(M_param[1][1], static_cast<T>(4.0), 1e-4f);
	BOOST_CHECK_CLOSE(M_param[2][0], static_cast<T>(5.0), 1e-4f);
	BOOST_CHECK_CLOSE(M_param[2][1], static_cast<T>(6.0), 1e-4f);
	// parameterized constructor
	vmath::core::Vector<T, 2> col1(static_cast<T>(1.0), static_cast<T>(2.0));
	vmath::core::Vector<T, 2> col2(static_cast<T>(3.0), static_cast<T>(4.0));
	vmath::core::Vector<T, 2> col3(static_cast<T>(5.0), static_cast<T>(6.0));
	vmath::core::Matrix<T, 2, 3> M_param2(col1, col2, col3);
	BOOST_CHECK_CLOSE(M_param2[0][0], static_cast<T>(1.0), 1e-4f);
	BOOST_CHECK_CLOSE(M_param2[0][1], static_cast<T>(2.0), 1e-4f);
	BOOST_CHECK_CLOSE(M_param2[1][0], static_cast<T>(3.0), 1e-4f);
	BOOST_CHECK_CLOSE(M_param2[1][1], static_cast<T>(4.0), 1e-4f);
	BOOST_CHECK_CLOSE(M_param2[2][0], static_cast<T>(5.0), 1e-4f);
	BOOST_CHECK_CLOSE(M_param2[2][1], static_cast<T>(6.0), 1e-4f);
}
Matrix4 Matrix4::multiply(Matrix4 a)
{
    Matrix4 b;
  /*
	for (int i = 0; i < 4; i++) {
		for (int j = 0; j < 4; j++) {
			b.m[i][j] = m[0][j] * a.m[i][0] + m[1][j] * a.m[i][1] + m[2][j] * a.m[i][2] + m[3][j] * a.m[i][3];
		}
	}*/
	Vector4 row1(m[0][0], m[1][0], m[2][0], m[3][0]);
	Vector4 row2(m[0][1], m[1][1], m[2][1], m[3][1]);
	Vector4 row3(m[0][2], m[1][2], m[2][2], m[3][2]);
	Vector4 row4(m[0][3], m[1][3], m[2][3], m[3][3]);

	Vector4 col1(a.m[0][0], a.m[0][1], a.m[0][2], a.m[0][3]);
	Vector4 col2(a.m[1][0], a.m[1][1], a.m[1][2], a.m[1][3]);
	Vector4 col3(a.m[2][0], a.m[2][1], a.m[2][2], a.m[2][3]);
	Vector4 col4(a.m[3][0], a.m[3][1], a.m[3][2], a.m[3][3]);

	b.set(row1.dot(col1), row2.dot(col1), row3.dot(col1), row4.dot(col1),
		row1.dot(col2), row2.dot(col2), row3.dot(col2), row4.dot(col2),
		row1.dot(col3), row2.dot(col3), row3.dot(col3), row4.dot(col3),
		row1.dot(col4), row2.dot(col4), row3.dot(col4), row4.dot(col4));

    return b;
}
/**
 * Decomposes matrix M such that T * R * S = M, where T is translation matrix,
 * R is rotation matrix and S is scaling matrix.
 * http://code.google.com/p/assimp-net/source/browse/trunk/AssimpNet/Matrix4x4.cs
 * (this method is exact to at least 0.0001f)
 *
 * | 1  0  0  T1 | | R11 R12 R13 0 | | a 0 0 0 |   | aR11 bR12 cR13 T1 |
 * | 0  1  0  T2 |.| R21 R22 R23 0 |.| 0 b 0 0 | = | aR21 bR22 cR23 T2 |
 * | 0  0  0  T3 | | R31 R32 R33 0 | | 0 0 c 0 |   | aR31 bR32 cR33 T3 |
 * | 0  0  0   1 | |  0   0   0  1 | | 0 0 0 1 |   |  0    0    0    1 |
 *
 * @param m (in) matrix to decompose
 * @param scaling (out) scaling vector
 * @param rotation (out) rotation matrix
 * @param translation (out) translation vector
 */
void decomposeTRS(const glm::mat4& m, glm::vec3& translation, glm::mat4& rotation, glm::vec3& scaling)
{
    // Extract the translation
    translation.x = m[3][0];
    translation.y = m[3][1];
    translation.z = m[3][2];

    // Extract col vectors of the matrix
    glm::vec3 col1(m[0][0], m[0][1], m[0][2]);
    glm::vec3 col2(m[1][0], m[1][1], m[1][2]);
    glm::vec3 col3(m[2][0], m[2][1], m[2][2]);

    //Extract the scaling factors
    scaling.x = glm::length(col1);
    scaling.y = glm::length(col2);
    scaling.z = glm::length(col3);

    // Handle negative scaling
    if (glm::determinant(m) < 0) {
        scaling.x = -scaling.x;
        scaling.y = -scaling.y;
        scaling.z = -scaling.z;
    }

    // Remove scaling from the matrix
    if (scaling.x != 0) {
        col1 /= scaling.x;
    }

    if (scaling.y != 0) {
        col2 /= scaling.y;
    }

    if (scaling.z != 0) {
        col3 /= scaling.z;
    }

    rotation[0][0] = col1.x;
    rotation[0][1] = col1.y;
    rotation[0][2] = col1.z;
    rotation[0][3] = 0.0;

    rotation[1][0] = col2.x;
    rotation[1][1] = col2.y;
    rotation[1][2] = col2.z;
    rotation[1][3] = 0.0;

    rotation[2][0] = col3.x;
    rotation[2][1] = col3.y;
    rotation[2][2] = col3.z;
    rotation[2][3] = 0.0;

    rotation[3][0] = 0.0;
    rotation[3][1] = 0.0;
    rotation[3][2] = 0.0;
    rotation[3][3] = 1.0;
}
Exemple #6
0
int main()
{
	zdb::Database database(L"test");
	zdb::DbColumn col1(L"lalka1", DbDataType::Int32);
	zdb::DbColumn col2(L"lalka2", DbDataType::Int64);
	zdb::DbColumn col3(L"lalka3", DbDataType::Int8);
	std::vector<zdb::DbColumn> columns = { col1, col2, col3 };
	database.AddTable(L"testTable", columns);
	return 0;
}
void
ColumnMajorMatrixTest::ThreeColConstructor()
{
  VectorValue<Real> col1( 1, 2, 3 );
  VectorValue<Real> col2( 4, 5, 6 );
  VectorValue<Real> col3( 7, 8, 9 );

  ColumnMajorMatrix test( col1, col2, col3 );

  CPPUNIT_ASSERT( test == *a );
  CPPUNIT_ASSERT( test.numEntries() == 9 );
}
    // extract frustum plane in world space.
    // the normals facing inward.
    // pass in view * projection matrix.
    void Frustum::InitFromMatrix(const Matrix &VP)
    {

        // near and far plane corners
        static float3 verts[8] =
        {
            // near plane corners
            float3( -1, -1,0 ),
            float3( 1, -1,0 ),
            float3( 1, 1,0 ),
            float3( -1, 1 ,0),

            // far plane corners.
            float3( -1, -1 ,1),
            float3( 1,  -1,1 ),
            float3( 1,  1,1 ),
            float3( -1, 1,1 )
        };

        this->m_matrix = VP;

        float4 col0(VP(0,0), VP(1,0), VP(2,0), VP(3,0));
        float4 col1(VP(0,1), VP(1,1), VP(2,1), VP(3,1));
        float4 col2(VP(0,2), VP(1,2), VP(2,2), VP(3,2));
        float4 col3(VP(0,3), VP(1,3), VP(2,3), VP(3,3));

        
        // Planes face inward.
        m_planes[Near]   = Plane(col2);        // near
        m_planes[Far]    = Plane(col3 - col2); // far
        m_planes[Left]   = Plane(col3 + col0); // left
        m_planes[Right]  = Plane(col3 - col0); // right
        m_planes[Top]    = Plane(col3 - col1); // top
        m_planes[Bottom] = Plane(col3 + col1); // bottom

        // normalize all six planes
        for(int i = 0; i < 6; i++)
        {
            m_planes[i].Normalize();
        }


        // tranform eight corner from device coordiate to world coordinate.
        Matrix invVP = VP;
        invVP.Invert();
        for(int i = 0; i < 8; i++)
        {
            this->m_corners[i] = float3::Transform(verts[i],invVP);
        }
    }
Exemple #9
0
void door(void) {
    initLeds();
    col1();
    col4();
    col7();
    _delay_ms(200);
    col1();
    col5();
    col9();
    _delay_ms(200);
    col1();
    col2();
    col3();
    _delay_ms(200);
}
Exemple #10
0
void Camera::buildFrustumPlanes()
{
	D3DXMATRIX VP = m_view * m_proj;

	D3DXVECTOR4 col0(VP(0, 0), VP(1, 0), VP(2, 0), VP(3, 0));
	D3DXVECTOR4 col1(VP(0, 1), VP(1, 1), VP(2, 1), VP(3, 1));
	D3DXVECTOR4 col2(VP(0, 2), VP(1, 2), VP(2, 2), VP(3, 2));
	D3DXVECTOR4 col3(VP(0, 3), VP(1, 3), VP(2, 3), VP(3, 3));

	// Planes face inward.
	mFrustumPlanes[0] = (D3DXPLANE)(col2);        // near
	mFrustumPlanes[1] = (D3DXPLANE)(col3 - col2); // far
	mFrustumPlanes[2] = (D3DXPLANE)(col3 + col0); // left
	mFrustumPlanes[3] = (D3DXPLANE)(col3 - col0); // right
	mFrustumPlanes[4] = (D3DXPLANE)(col3 - col1); // top
	mFrustumPlanes[5] = (D3DXPLANE)(col3 + col1); // bottom

	for (int i = 0; i < 6; i++)
		D3DXPlaneNormalize(&mFrustumPlanes[i], &mFrustumPlanes[i]);
}
TEST(PaletteTranslator, BuildDuplicatedColors)
{
	Color col0(11, 12, 13);
	Color col1(14, 15, 16);
	Color col2(20, 21, 22, 0);
	Color col3(11, 12, 13);
	Color col4(30, 31, 32, 0);

	Palette pal;
	pal.m_count = 5;
	pal[0] = col0;
	pal[1] = col1;
	pal[2] = col2;
	pal[3] = col3;
	pal[4] = col4;

	Palette exp;
	exp.m_count = 3;
	exp[0] = col0;
	exp[1] = col1;
	exp[2] = col2;

	uint32 colCounts[256] = { 1, 10, 100, 1000, 10000 };
	uint32 expectedColCounts[256] = { 1001, 10, 10100, 0, 0 };

	PaletteTranslator pt;
	pt.BuildDuplicatedColors(pal, colCounts);
	ASSERT_TRUE( pal == exp );
	ASSERT_TRUE( memcmp(colCounts, expectedColCounts, sizeof(colCounts)) == 0 );

	uint8 pixels[] = { 0, 1, 2, 3, 4 };
	const uint8 expectedPixels[] = { 0, 1, 2, 0, 2 };
	
	pt.Translate(pixels, sizeof(pixels));
	
	ASSERT_TRUE( memcmp(pixels, expectedPixels, sizeof(pixels)) == 0 );
}
Exemple #12
0
void TestDim::vec() {
	Dim sca;
	Dim row2(Dim::row_vec(2));
	Dim row3(Dim::row_vec(3));
	Dim col2(Dim::col_vec(2));
	Dim col3(Dim::col_vec(3));
	Dim mat22(Dim::matrix(2,2));
	Dim mat32(Dim::matrix(3,2));
	Dim mat23(Dim::matrix(2,3));
	Dim mat33(Dim::matrix(3,3));

	CPPUNIT_ASSERT      (vec_dim(Array<const Dim>(sca),true)==sca);
	CPPUNIT_ASSERT      (vec_dim(Array<const Dim>(sca),false)==sca);
	CPPUNIT_ASSERT      (vec_dim(Array<const Dim>(sca,sca),true)==row2);
	CPPUNIT_ASSERT      (vec_dim(Array<const Dim>(sca,sca),false)==col2);
	CPPUNIT_ASSERT      (vec_dim(Array<const Dim>(sca,sca,sca),true)==row3);
	CPPUNIT_ASSERT      (vec_dim(Array<const Dim>(sca,sca,sca),false)==col3);

	CPPUNIT_ASSERT_THROW(vec_dim(Array<const Dim>(sca,col2),true),DimException);
	CPPUNIT_ASSERT      (vec_dim(Array<const Dim>(sca,col2),false)==col3);
	CPPUNIT_ASSERT      (vec_dim(Array<const Dim>(sca,row2),true)==row3);
	CPPUNIT_ASSERT_THROW(vec_dim(Array<const Dim>(sca,row2),false),DimException);
	CPPUNIT_ASSERT_THROW(vec_dim(Array<const Dim>(sca,mat22),true),DimException);
	CPPUNIT_ASSERT_THROW(vec_dim(Array<const Dim>(sca,mat22),false),DimException);

	CPPUNIT_ASSERT      (vec_dim(Array<const Dim>(col2),true)==col2);
	CPPUNIT_ASSERT      (vec_dim(Array<const Dim>(col2),false)==col2);
	CPPUNIT_ASSERT      (vec_dim(Array<const Dim>(col2,col2),true)==mat22);
	CPPUNIT_ASSERT      (vec_dim(Array<const Dim>(col2,col2),false)==Dim::col_vec(4));
	CPPUNIT_ASSERT      (vec_dim(Array<const Dim>(col2,col2,col2),true)==mat23);
	CPPUNIT_ASSERT      (vec_dim(Array<const Dim>(col2,col2,col2),false)==Dim::col_vec(6));
	CPPUNIT_ASSERT_THROW(vec_dim(Array<const Dim>(col2,row2),true),DimException);
	CPPUNIT_ASSERT_THROW(vec_dim(Array<const Dim>(col2,row2),false),DimException);
	CPPUNIT_ASSERT      (vec_dim(Array<const Dim>(col2,mat22),true)==mat23);
	CPPUNIT_ASSERT_THROW(vec_dim(Array<const Dim>(col2,mat22),false),DimException);
	CPPUNIT_ASSERT      (vec_dim(Array<const Dim>(col2,mat22,col2),true)==Dim::matrix(2,4));
}
void Board::Initialise()
{
	float zbase = 400;							//  Variable to store how deep in the z axis the object is based.
	
	
	Vector4 temp1(-600, 800, 1200 + zbase, 1);
	Vector4 temp2(600, 800, 1200 + zbase, 1);
	Vector4 temp3(600, 800, 0 + zbase, 1);
	Vector4 temp4(-600,800,0 + zbase,1);
	top.Initialise(temp1, temp2, temp3, temp4);		//  Set individual vertex locations for the top face of the board
	
	Vector4 col1(70,50,4,1);
	Vector4 col2(92,67,5,1);
	Vector4 col3(102,75,6,1);
	Vector4 col4(119,77,0,1);
	Vector4 col5(69, 25, 18, 1);
	top.SetColours(col1, col2, col2, col3);			//  Set individual colour values of each of those vertices
	
	
	
	Vector4 temp5(-600, 800, 0 + zbase, 1);
	Vector4 temp6(600, 800, 0 + zbase, 1);
	Vector4 temp7(600, 1000, 0 + zbase, 1);
	Vector4 temp8(-600,1000, 0 + zbase,1);			//  Individual vertices for the front face
	
	Vector4 temp9(-800, 1000, 1200 + zbase + 300, 1);
	Vector4 temp10(800, 1000, 1200 + zbase + 300, 1);
	Vector4 temp11(800, 1000, 100, 1);
	Vector4 temp12(-800, 1000, 100,1);				//  Individual vertices for the base face
	table.Initialise(temp9, temp10, temp11, temp12);
	table.SetColours(col5, col5, col5, col5);		//  Set to one mat colour, no shading.
	
	Vector4 temp13(-600, 800, 1200 + zbase, 1);
	Vector4 temp14(-600, 800, 0 + zbase, 1);
	Vector4 temp15(-600, 1000, 0 + zbase, 1);
	Vector4 temp16(-600, 1000, 1200 + zbase, 1);	//  Set individual vertices for the left face
	
	Vector4 temp17(600, 800, 0 + zbase, 1);
	Vector4 temp18(600, 800, 1200 + zbase, 1);
	Vector4 temp19(600, 1000, 1200 + zbase, 1);
	Vector4 temp20(600, 1000, 0 + zbase, 1);		//  Set individual vertices for the right face

	sides[0].Initialise(temp5, temp6, temp7, temp8);
	sides[1].Initialise(temp13, temp14, temp15, temp16);
	sides[2].Initialise(temp17, temp18, temp19, temp20);
	sides[3].Initialise(temp2, temp1, temp16, temp19);		//  Use known vertices to initialise the side faces
	
	sides[0].SetColours(col3, col4, col4, col2);
	sides[1].SetColours(col1, col2, col2, col1);
	sides[2].SetColours(col2, col1, col1, col2);
	sides[3].SetColours(col4, col4, col4, col4);			//  Then set the colours
	
	
	float positionLocations[24][2] =   {{-450, 1050 + zbase},		//1					An array holding the centre locations
										{-300,  900 + zbase},		//2					of each of the positions where pieces
										{-150,  750 + zbase},		//3					can be placed.
										{  0 ,  750 + zbase},		//4
										{ 150,  750 + zbase},		//5
										{ 300,  900 + zbase},		//6
										{ 450, 1050 + zbase},		//7
										{  0 ,  900 + zbase},		//8
										{  0 , 1050 + zbase},		//9
										{-450,  600 + zbase},		//10
										{-300,  600 + zbase},		//11
										{-150,  600 + zbase},		//12
										{-450,  150 + zbase},		//13
										{-300,  300 + zbase},		//14
										{-150,  450 + zbase},		//15
										{  0 ,  150 + zbase},		//16
										{  0 ,  300 + zbase},		//17
										{  0 ,  450 + zbase},		//18
										{ 450,  150 + zbase},		//19
										{ 300,  300 + zbase},		//20
										{ 150,  450 + zbase},		//21
										{ 450,  600 + zbase},		//22
										{ 300,  600 + zbase},		//23
										{ 150,  600 + zbase}};		//24
	for (int i = 0; i < 24; i++) {									
		boardpositions[i].Initialise(positionLocations[i][0], positionLocations[i][1]);			//  Create the individual graphical representations
	}																							//  (class Position) and put in array for easy drawing.
	InitialiseLines();				//  Ugly function to draw each and every line on the
									//  board with individual hand-placed vertices.
									
	SetupMills();					//  Set up the mills (groups of three) with pointers to the positions
									//  as alternate referencing option
	
}
int test_main(int, char* [])
{
    typedef bg::model::d2::point_xy<boost::long_long_type> point;
    typedef bg::model::segment<point> segment;

    typedef bg::strategy::side::side_of_intersection side;

    point no_fb(-99, -99);

    segment a(point(20, 10), point(10, 20));

    segment b1(point(11, 16), point(20, 14));  // IP with a: (14.857, 15.143)
    segment b2(point(10, 16), point(20, 14));  // IP with a: (15, 15)

    segment c1(point(15, 16), point(13, 8));
    segment c2(point(15, 16), point(14, 8));
    segment c3(point(15, 16), point(15, 8));


    BOOST_CHECK_EQUAL( 1, side::apply(a, b1, c1, no_fb));
    BOOST_CHECK_EQUAL(-1, side::apply(a, b1, c2, no_fb));
    BOOST_CHECK_EQUAL(-1, side::apply(a, b1, c3, no_fb));

    BOOST_CHECK_EQUAL( 1, side::apply(a, b2, c1, no_fb));
    BOOST_CHECK_EQUAL( 1, side::apply(a, b2, c2, no_fb));
    BOOST_CHECK_EQUAL( 0, side::apply(a, b2, c3, no_fb));

    // Collinear cases
    // 1: segments intersecting are collinear (with a fallback point):
    {
        point fb(5, 5);
        segment col1(point(0, 5), point(5, 5));
        segment col2(point(5, 5), point(10, 5)); // One IP with col1 at (5,5)
        segment col3(point(5, 0), point(5, 5));
        BOOST_CHECK_EQUAL( 0, side::apply(col1, col2, col3, fb));
    }
    // 2: segment of side calculation collinear with one of the segments
    {
        point fb(5, 5);
        segment col1(point(0, 5), point(10, 5));
        segment col2(point(5, 5), point(5, 12)); // IP with col1 at (5,5)
        segment col3(point(5, 1), point(5, 5)); // collinear with col2
        BOOST_CHECK_EQUAL( 0, side::apply(col1, col2, col3, fb));
    }
    {
        point fb(5, 5);
        segment col1(point(10, 5), point(0, 5));
        segment col2(point(5, 5), point(5, 12)); // IP with col1 at (5,5)
        segment col3(point(5, 1), point(5, 5)); // collinear with col2
        BOOST_CHECK_EQUAL( 0, side::apply(col1, col2, col3, fb));
    }
    {
        point fb(5, 5);
        segment col1(point(0, 5), point(10, 5));
        segment col2(point(5, 12), point(5, 5)); // IP with col1 at (5,5)
        segment col3(point(5, 1), point(5, 5)); // collinear with col2
        BOOST_CHECK_EQUAL( 0, side::apply(col1, col2, col3, fb));
    }

    {
        point fb(517248, -517236);
        segment col1(point(-172408, -517236), point(862076, -517236));
        segment col2(point(517248, -862064), point(517248, -172408));
        segment col3(point(517248, -172408), point(517248, -517236));
        BOOST_CHECK_EQUAL( 0, side::apply(col1, col2, col3, fb));
    }
    {
        point fb(-221647, -830336);
        segment col1(point(-153817, -837972), point(-222457, -830244));
        segment col2(point(-221139, -833615), point(-290654, -384388));
        segment col3(point(-255266, -814663), point(-264389, -811197));
        BOOST_CHECK_EQUAL(1, side::apply(col1, col2, col3, fb)); // Left of segment...
    }


    {
        point fb(27671131, 30809240);
        segment col1(point(27671116, 30809247), point(27675474, 30807351));
        segment col2(point(27666779, 30811130), point(27671139, 30809237));
        segment col3(point(27671122, 30809244), point(27675480, 30807348));
        BOOST_CHECK_EQUAL(1, side::apply(col1, col2, col3, fb)); // Left of segment...
    }

    // TODO: we might add a check calculating the IP, determining the side
    // with the normal side strategy, and verify the results are equal

    return 0;
}
Exemple #15
0
void TestDim::mul() {
	Dim sca;
	Dim row2(Dim::row_vec(2));
	Dim row3(Dim::row_vec(3));
	Dim col2(Dim::col_vec(2));
	Dim col3(Dim::col_vec(3));
	Dim mat22(Dim::matrix(2,2));
	Dim mat32(Dim::matrix(3,2));
	Dim mat23(Dim::matrix(2,3));
	Dim mat33(Dim::matrix(3,3));

	CPPUNIT_ASSERT      (mul_dim(sca,sca)==sca);
	CPPUNIT_ASSERT      (mul_dim(sca,row2)==row2);
	CPPUNIT_ASSERT      (mul_dim(sca,row3)==row3);
	CPPUNIT_ASSERT      (mul_dim(sca,col2)==col2);
	CPPUNIT_ASSERT      (mul_dim(sca,col3)==col3);
	CPPUNIT_ASSERT      (mul_dim(sca,mat22)==mat22);
	CPPUNIT_ASSERT      (mul_dim(sca,mat23)==mat23);
	CPPUNIT_ASSERT      (mul_dim(sca,mat32)==mat32);
	CPPUNIT_ASSERT      (mul_dim(sca,mat33)==mat33);

	CPPUNIT_ASSERT_THROW(mul_dim(row2,sca),DimException);
	CPPUNIT_ASSERT_THROW(mul_dim(row2,row2),DimException);
	CPPUNIT_ASSERT_THROW(mul_dim(row2,row3),DimException);
	CPPUNIT_ASSERT      (mul_dim(row2,col2)==sca);
	CPPUNIT_ASSERT_THROW(mul_dim(row2,col3),DimException);
	CPPUNIT_ASSERT      (mul_dim(row2,mat22)==row2);
	CPPUNIT_ASSERT_THROW(mul_dim(row2,mat32),DimException);
	CPPUNIT_ASSERT      (mul_dim(row2,mat23)==row3);
	CPPUNIT_ASSERT_THROW(mul_dim(row2,mat33),DimException);

	CPPUNIT_ASSERT_THROW(mul_dim(row3,sca),DimException);
	CPPUNIT_ASSERT_THROW(mul_dim(row3,row2),DimException);
	CPPUNIT_ASSERT_THROW(mul_dim(row3,row3),DimException);
	CPPUNIT_ASSERT_THROW(mul_dim(row3,col2),DimException);
	CPPUNIT_ASSERT      (mul_dim(row3,col3)==sca);
	CPPUNIT_ASSERT_THROW(mul_dim(row3,mat22),DimException);
	CPPUNIT_ASSERT      (mul_dim(row3,mat32)==row2);
	CPPUNIT_ASSERT_THROW(mul_dim(row3,mat23),DimException);
	CPPUNIT_ASSERT      (mul_dim(row3,mat33)==row3);

	CPPUNIT_ASSERT      (mul_dim(col2,sca)==col2);
	CPPUNIT_ASSERT      (mul_dim(col2,row2)==mat22);
	CPPUNIT_ASSERT      (mul_dim(col2,row3)==mat23);
	CPPUNIT_ASSERT_THROW(mul_dim(col2,col2),DimException);
	CPPUNIT_ASSERT_THROW(mul_dim(col2,col3),DimException);
	CPPUNIT_ASSERT_THROW(mul_dim(col2,mat22),DimException);
	CPPUNIT_ASSERT_THROW(mul_dim(col2,mat32),DimException);
	CPPUNIT_ASSERT_THROW(mul_dim(col2,mat23),DimException);
	CPPUNIT_ASSERT_THROW(mul_dim(col2,mat33),DimException);

	CPPUNIT_ASSERT      (mul_dim(col3,sca)==col3);
	CPPUNIT_ASSERT      (mul_dim(col3,row2)==mat32);
	CPPUNIT_ASSERT      (mul_dim(col3,row3)==mat33);
	CPPUNIT_ASSERT_THROW(mul_dim(col3,col2),DimException);
	CPPUNIT_ASSERT_THROW(mul_dim(col3,col3),DimException);
	CPPUNIT_ASSERT_THROW(mul_dim(col3,mat22),DimException);
	CPPUNIT_ASSERT_THROW(mul_dim(col3,mat32),DimException);
	CPPUNIT_ASSERT_THROW(mul_dim(col3,mat23),DimException);
	CPPUNIT_ASSERT_THROW(mul_dim(col3,mat33),DimException);

	CPPUNIT_ASSERT_THROW(mul_dim(mat22,sca),DimException);
	CPPUNIT_ASSERT_THROW(mul_dim(mat22,row2),DimException);
	CPPUNIT_ASSERT_THROW(mul_dim(mat22,row3),DimException);
	CPPUNIT_ASSERT      (mul_dim(mat22,col2)==col2);
	CPPUNIT_ASSERT_THROW(mul_dim(mat22,col3),DimException);
	CPPUNIT_ASSERT      (mul_dim(mat22,mat22)==mat22);
	CPPUNIT_ASSERT_THROW(mul_dim(mat22,mat32),DimException);
	CPPUNIT_ASSERT      (mul_dim(mat22,mat23)==mat23);
	CPPUNIT_ASSERT_THROW(mul_dim(mat22,mat33),DimException);

	CPPUNIT_ASSERT_THROW(mul_dim(mat32,sca),DimException);
	CPPUNIT_ASSERT_THROW(mul_dim(mat32,row2),DimException);
	CPPUNIT_ASSERT_THROW(mul_dim(mat32,row3),DimException);
	CPPUNIT_ASSERT      (mul_dim(mat32,col2)==col3);
	CPPUNIT_ASSERT_THROW(mul_dim(mat32,col3),DimException);
	CPPUNIT_ASSERT      (mul_dim(mat32,mat22)==mat32);
	CPPUNIT_ASSERT_THROW(mul_dim(mat32,mat32),DimException);
	CPPUNIT_ASSERT      (mul_dim(mat32,mat23)==mat33);
	CPPUNIT_ASSERT_THROW(mul_dim(mat32,mat33),DimException);

	CPPUNIT_ASSERT_THROW(mul_dim(mat23,sca),DimException);
	CPPUNIT_ASSERT_THROW(mul_dim(mat23,row2),DimException);
	CPPUNIT_ASSERT_THROW(mul_dim(mat23,row3),DimException);
	CPPUNIT_ASSERT_THROW(mul_dim(mat23,col2),DimException);
	CPPUNIT_ASSERT      (mul_dim(mat23,col3)==col2);
	CPPUNIT_ASSERT_THROW(mul_dim(mat23,mat22),DimException);
	CPPUNIT_ASSERT      (mul_dim(mat23,mat32)==mat22);
	CPPUNIT_ASSERT_THROW(mul_dim(mat23,mat23),DimException);
	CPPUNIT_ASSERT      (mul_dim(mat23,mat33)==mat23);

	CPPUNIT_ASSERT_THROW(mul_dim(mat33,sca),DimException);
	CPPUNIT_ASSERT_THROW(mul_dim(mat33,row2),DimException);
	CPPUNIT_ASSERT_THROW(mul_dim(mat33,row3),DimException);
	CPPUNIT_ASSERT_THROW(mul_dim(mat33,col2),DimException);
	CPPUNIT_ASSERT      (mul_dim(mat33,col3)==col3);
	CPPUNIT_ASSERT_THROW(mul_dim(mat33,mat22),DimException);
	CPPUNIT_ASSERT      (mul_dim(mat33,mat32)==mat32);
	CPPUNIT_ASSERT_THROW(mul_dim(mat33,mat23),DimException);
	CPPUNIT_ASSERT      (mul_dim(mat33,mat33)==mat33);
}
Exemple #16
0
// --------------
// -----Main-----
// --------------
int
main (int argc, char** argv)
{
  // --------------------------------------
  // -----Parse Command Line Arguments-----
  // --------------------------------------
  
    double normals_radius= 0.005;
  if (pcl::console::parse (argc, argv, "-n", normals_radius) >= 0)
  {
    std::cout << " Radius: " << normals_radius << "\n";
  }
  
      double harris_radius = 0.5;
  if (pcl::console::parse (argc, argv, "--hariss_radius", harris_radius) >= 0)
  {
    std::cout << " harris_radius: " << harris_radius << "\n";
  }
 
      double harris_search_radius = 0.01;
  if (pcl::console::parse (argc, argv, "--harris_search_radius", harris_search_radius) >= 0)
  {
    std::cout << " harris_search_radius: " << harris_search_radius << "\n";
  }

  
    pcl::PointCloud<pcl::PointXYZRGB>::Ptr cloudRGB (new pcl::PointCloud<pcl::PointXYZRGB>);
    pcl::PointCloud<pcl::PointXYZ>::Ptr cloud (new pcl::PointCloud<pcl::PointXYZ>);

  if (pcl::io::loadPCDFile<pcl::PointXYZRGB> (argv[1], *cloudRGB) == -1) //* load the file
  {
    std::cout << "Couldn't read file cloud.pcd ";
    return (-1);
  }
  
  pcl::copyPointCloud(*cloudRGB, *cloud);

      pcl::PointCloud<pcl::PointXYZ>::Ptr harris3d (new pcl::PointCloud<pcl::PointXYZ>);
      pcl::PointCloud<pcl::PointXYZ>::Ptr iss3d (new pcl::PointCloud<pcl::PointXYZ>);
      pcl::PointCloud<pcl::PointXYZ>::Ptr susan (new pcl::PointCloud<pcl::PointXYZ>);
      pcl::PointCloud<pcl::PointXYZ>::Ptr harris6d (new pcl::PointCloud<pcl::PointXYZ>);
      pcl::PointCloud<pcl::PointXYZ>::Ptr sift (new pcl::PointCloud<pcl::PointXYZ>);

  
  	NormalCloudPtr normals(new NormalCloud());
	pcl::NormalEstimationOMP<PointT, NormalT> est;
	est.setRadiusSearch(normals_radius);
	est.setInputCloud(cloud);
	est.compute(*normals);

	{

	pcl::search::KdTree<pcl::PointXYZ>::Ptr tree (new pcl::search::KdTree<pcl::PointXYZ> ());

		pcl::PointCloud<pcl::PointXYZI>::Ptr keypoints_temp(
				new pcl::PointCloud<pcl::PointXYZI>());

		HarrisKeypoint* detector = new HarrisKeypoint(HarrisKeypoint::HARRIS);

		detector->setNonMaxSupression(true);
		detector->setRadius(harris_radius);

		detector->setRadiusSearch(harris_search_radius);
		detector->setMethod(HarrisKeypoint::HARRIS);
	//	detector->setKSearch();
		detector->setNumberOfThreads(10);
		detector->setSearchMethod(tree);
	//	detector->setThreshold();
	//	detector->use_indices_ = false;
		detector->setInputCloud(cloud);


		detector->compute(*keypoints_temp);

		pcl::PointCloud<pcl::PointXYZ>::Ptr keypoints(
				new pcl::PointCloud<pcl::PointXYZ>());

		pcl::copyPointCloud(*keypoints_temp, *harris3d);
}

	std::cout <<  " harris3d size :" << harris3d->size() << std::endl;;
	
	

/*
	{

		double iss_salient_radius_;
			double iss_non_max_radius_;
			double iss_gamma_21_ (0.975);
			double iss_gamma_32_ (0.975);
			double iss_min_neighbors_ (20);
			int iss_threads_ (10);

			pcl::PointCloud<pcl::PointXYZ>::Ptr keypoints (new pcl::PointCloud<pcl::PointXYZ> ());
			pcl::search::KdTree<pcl::PointXYZ>::Ptr tree (new pcl::search::KdTree<pcl::PointXYZ> ());

			// Fill in the model cloud

			double model_resolution = 0.01;

			// Compute model_resolution

			iss_salient_radius_ = 6 * model_resolution;
			iss_non_max_radius_ = 4 * model_resolution;

			//
			// Compute keypoints
			//
			pcl::ISSKeypoint3D<pcl::PointXYZ, pcl::PointXYZ> iss_detector;

			iss_detector.setSearchMethod (tree);
			iss_detector.setSalientRadius (iss_salient_radius_);
			iss_detector.setNonMaxRadius (iss_non_max_radius_);
			iss_detector.setThreshold21 (iss_gamma_21_);
			iss_detector.setThreshold32 (iss_gamma_32_);
			iss_detector.setMinNeighbors (iss_min_neighbors_);
			iss_detector.setNumberOfThreads (iss_threads_);
			iss_detector.setInputCloud (cloud);
			iss_detector.compute (*iss3d);
	}


	std::cout << " iss3d size :" << iss3d->size() << std::endl;

	
	
	{
		pcl::search::KdTree<pcl::PointXYZRGB>::Ptr tree (new pcl::search::KdTree<pcl::PointXYZRGB> ());

		pcl::SUSANKeypoint<pcl::PointXYZRGB, pcl::PointXYZRGB>* susan3D = new  pcl::SUSANKeypoint<pcl::PointXYZRGB, pcl::PointXYZRGB>;
		susan3D->setInputCloud(cloudRGB);
		susan3D->setNonMaxSupression(true);
		susan3D->setSearchMethod(tree);
		
		susan3D->setRadius(harris_radius);
		susan3D->setRadiusSearch(harris_search_radius);
		
		pcl::PointCloud<pcl::PointXYZRGB>::Ptr keypoints (new pcl::PointCloud<pcl::PointXYZRGB> ());
		susan3D->compute(*keypoints);

		pcl::PointCloud<pcl::PointXYZ>::Ptr susan(new pcl::PointCloud<pcl::PointXYZ>());

		pcl::copyPointCloud(*keypoints, *susan);
	}

	std::cout <<  " susan size :" << susan->size() << std::endl;

	
	
	{

	pcl::search::KdTree<pcl::PointXYZRGB>::Ptr tree (new pcl::search::KdTree<pcl::PointXYZRGB> ());

		pcl::PointCloud<pcl::PointXYZI>::Ptr keypoints_temp(
				new pcl::PointCloud<pcl::PointXYZI>());

		HarrisKeypoint6D* detector = new HarrisKeypoint6D(HarrisKeypoint::HARRIS);

		detector->setNonMaxSupression(true);
		detector->setRadius(harris_radius);
		detector->setRadiusSearch(harris_search_radius);
	//	detector->setMethod(HarrisKeypoint::HARRIS);
		

		detector->setNumberOfThreads(10);
		detector->setSearchMethod(tree);
	//	detector->setThreshold();
	//	detector->use_indices_ = false;
		detector->setInputCloud(cloudRGB);


		detector->compute(*keypoints_temp);

		pcl::copyPointCloud(*keypoints_temp, *harris6d);
}

	std::cout <<  " harris6d size :" << harris6d->size() << std::endl;

	/*
	*/

		pcl::visualization::PointCloudColorHandlerCustom<pcl::PointXYZ> white (cloud, 255, 255, 255);
	pcl::visualization::PointCloudColorHandlerCustom<pcl::PointXYZ> red (harris3d, 255, 0, 0);
	pcl::visualization::PointCloudColorHandlerCustom<pcl::PointXYZ> green (iss3d, 0, 255, 0);
	pcl::visualization::PointCloudColorHandlerCustom<pcl::PointXYZ> blue (susan, 0, 0, 255);
	pcl::visualization::PointCloudColorHandlerCustom<pcl::PointXYZ> col2 (harris6d, 255, 0, 255);
	pcl::visualization::PointCloudColorHandlerCustom<pcl::PointXYZ> col3 (sift, 255, 255, 0);
	//////
  
   boost::shared_ptr<pcl::visualization::PCLVisualizer> viewer (new pcl::visualization::PCLVisualizer ("3D Viewer"));
  viewer->setBackgroundColor (0, 0, 0);
  viewer->addPointCloud<pcl::PointXYZ> (cloud, white, "cloud");
    viewer->addPointCloud<pcl::PointXYZ> (harris3d, red, "keypoints2");
    viewer->addPointCloud<pcl::PointXYZ> (iss3d, green, "keypoints3");
    viewer->addPointCloud<pcl::PointXYZ> (susan, blue, "keypoint4s");
    viewer->addPointCloud<pcl::PointXYZ> (harris6d, col2, "keypoin3ts");
    viewer->addPointCloud<pcl::PointXYZ> (sift, col3, "keypoint36");
  viewer->setPointCloudRenderingProperties (pcl::visualization::PCL_VISUALIZER_POINT_SIZE, 4, "keypoints2");
  viewer->setPointCloudRenderingProperties (pcl::visualization::PCL_VISUALIZER_POINT_SIZE, 4, "keypoints3");
  viewer->setPointCloudRenderingProperties (pcl::visualization::PCL_VISUALIZER_POINT_SIZE, 4, "keypoint4s");
  viewer->setPointCloudRenderingProperties (pcl::visualization::PCL_VISUALIZER_POINT_SIZE, 4, "keypoin3ts");
  viewer->setPointCloudRenderingProperties (pcl::visualization::PCL_VISUALIZER_POINT_SIZE, 4, "keypoint36");
 // viewer->addPointCloudNormals<pcl::PointXYZ, pcl::Normal> (cloud, normals, 5, 0.05, "normals");
  viewer->addCoordinateSystem (1.0, "global");
  viewer->initCameraParameters ();
//   viewer->addSphere (cloud->points[0], normals_radius, "sphere+norm", 0);
  //  viewer->addSphere (cloud->points[0], shot_radius, "sphere+shot", 0);


  //--------------------
  // -----Main loop-----
  //--------------------
  while (!viewer->wasStopped ())
  {
    viewer->spinOnce (100);
    boost::this_thread::sleep (boost::posix_time::microseconds (100000));
  }
}
void    GLUI_Translation::draw_2d_arrow( int radius, int filled, int orientation )
{
  float x1 = .2, x2 = .4, y1 = .54, y2 = .94, y0;
  float x1a, x1b;
  vec3  col1( 0.0, 0.0, 0.0 ), col2( .45, .45, .45 ), 
    col3( .7, .7, .7 ), col4( 1.0, 1.0, 1.0 );
  vec3  c1, c2, c3, c4, c5, c6;
  vec3  white(1.0,1.0,1.0), black(0.0,0.0,0.0), gray(.45,.45,.45), 
    bkgd(.7,.7,.7);
  int   c_off; /* color index offset */

  if ( glui )
    bkgd.set(glui->bkgd_color_f[0],
	     glui->bkgd_color_f[1],
	     glui->bkgd_color_f[2]);

  /*	bkgd[0] = 255.0; bkgd[1] = 0;              */

  /** The following 8 colors define the shading of an octagon, in
    clockwise order, starting from the upstroke on the left  **/
  /** This is for an outside and inside octagons **/
  vec3 colors_out[]={white, white, white, gray, black, black, black, gray};
  vec3 colors_in[] ={bkgd,white,bkgd,gray,gray,gray,gray,gray};

#define SET_COL_OUT(i) glColor3fv((float*) &colors_out[(i)%8][0]);
#define SET_COL_IN(i) glColor3fv((float*) &colors_in[(i)%8][0]);

  x1 = (float)radius * .2;
  x2 = x1 * 2;
  y1 = (float)radius * .54;
  y2 = y1 + x2;
  x1a = x1;
  x1b = x1;

  glMatrixMode(GL_MODELVIEW);
  glPushMatrix();

#define DRAW_SEG( xa,ya,xb,yb ) glVertex2f(xa,ya); glVertex2f(xb,yb);

  glScalef( -1.0, 1.0, 1.0 );
	
  if ( orientation == 2 ) {
    c_off = 4;
  }
  else if ( orientation == 0 ) {
    c_off = 0;
    glRotatef( 180.0, 0.0, 0.0, 1.0 );
  }
  else if ( orientation == 1 ) {
    c_off = 2;
    glRotatef( 90.0, 0.0, 0.0, 1.0 );
  }
  else if ( orientation == 3 ) {
    c_off = 6;
    glRotatef( -90.0, 0.0, 0.0, 1.0 );
  }

  if ( trans_type == GLUI_TRANSLATION_Z )
    y0 = 0.0;
  else if ( trans_type == GLUI_TRANSLATION_XY )
    y0 = x1;
  else
    y0 = 0.0;

	
  if ( trans_type == GLUI_TRANSLATION_Z ) {
    if ( orientation == 0 ) {
      y1 += 2.0;
      y2 += 0.0;

      x1b -= 2.0;
      x2  -= 2.0;
      x1a += 2.0;
    }
    else if ( orientation == 2 ) {
      y1 -= 6.0;
      x1a += 2.0;
      x1b += 4.0;
      x2  += 6.0; 
    }
  }

  /*** Fill in inside of arrow  ***/
  if ( NOT filled ) {  /*** Means button is up - control is not clicked ***/
    /*glColor3f( .8, .8, .8 );              */
    set_to_bkgd_color();
    glColor3f( bkgd[0]+.07, bkgd[1]+.07, bkgd[2]+.07 );
  }
  else {               /*** Button is down on control ***/
    glColor3f( .6, .6, .6 );
    c_off += 4;  /* Indents the shadows - goes from a raised look to embossed */
  }

  /*** Check if control is enabled or not ***/
  if ( NOT enabled ) {
    set_to_bkgd_color();
    /*c_off += 4;  -- Indents the shadows - goes from a raised look to embossed */              
    colors_out[0] = colors_out[1] = colors_out[2] = colors_out[7] = gray;
    colors_out[3] = colors_out[4] = colors_out[5] = colors_out[6] = white;
    colors_in[0] = colors_in[1] = colors_in[2] = colors_in[7] = white;
    colors_in[3] = colors_in[4] = colors_in[5] = colors_in[6] = gray;
	
  }

  glBegin( GL_POLYGON );
  glVertex2f( 0.0, 0.0  );  glVertex2f( -x1a, 0.0 );
  glVertex2f( -x1a, 0.0   );  glVertex2f( -x1b, y1 );
  glVertex2f( x1b, y1);      glVertex2f( x1a, 0.0 );
  glVertex2f( x1a, 0.0 );     glVertex2f( 0.0, 0.0  );
  glEnd();
  glBegin( GL_TRIANGLES );
  glVertex2f( -x2, y1 ); glVertex2f( 0.0, y2 ); glVertex2f( x2, y1 );
  glEnd();

  glLineWidth( 1.0 );
  /*** Draw arrow outline ***/
  glBegin( GL_LINES );

  SET_COL_IN(1+c_off);  DRAW_SEG( 0.0, y2-1.0, -x2, y1-1.0 );
  SET_COL_IN(6+c_off);	DRAW_SEG( -x2+2.0, y1+1.0, -x1b+1.0, y1+1.0 );
  SET_COL_IN(0+c_off);	DRAW_SEG( -x1b+1.0, y1+1.0, -x1a+1.0, y0 );
  SET_COL_IN(3+c_off);	DRAW_SEG( 0.0, y2-1.0, x2, y1-1.0 );
  SET_COL_IN(6+c_off);	DRAW_SEG( x2-1.0, y1+1.0, x1b-1.0, y1+1.0 );
  SET_COL_IN(4+c_off);	DRAW_SEG( x1b-1.0, y1+1.0, x1a-1.0, y0 );

  SET_COL_OUT(0+c_off);  DRAW_SEG( -x1a, y0, -x1b, y1  );
  SET_COL_OUT(6+c_off);  DRAW_SEG( -x1b, y1,  -x2, y1  );
  SET_COL_OUT(1+c_off);  DRAW_SEG( -x2, y1,  0.0, y2  );
  SET_COL_OUT(3+c_off);  DRAW_SEG( 0.0, y2,   x2, y1  );
  SET_COL_OUT(6+c_off);  DRAW_SEG(  x2, y1,   x1b, y1  );
  SET_COL_OUT(4+c_off);  DRAW_SEG(  x1b, y1,   x1a, y0 );

  glEnd();

#undef DRAW_SEG

  glPopMatrix();
}
Exemple #18
0
	// bilinear filtering
	void PointSampler::Sample(shading::Sample *samples, Cache &, bool mipmapping) const {
		for(int k = 0 + 0; k < 4; k++) {
			shading::Sample &s = samples[k];

			Vec2q pos = ClampTexCoord <i32x4>(s.texCoord) * Vec2q(wMul, hMul);

			uint mip = 0;
			if(mipmapping) {
				floatq min = Min(s.texDiff.x * wMul, s.texDiff.y * hMul);
				uint   pixels = uint(Minimize(min) * 0.6f);
				mip = 0;
				while(pixels) {
					mip++;
					pixels >>= 1;
				}
				mip = Min(mip, tex->Mips() - 1);
			}

			const u8 *data = (u8 *)tex->DataPointer(mip);
			int pitch = mipPitch[mip];

			i32x4 x1(pos.x), y1(pos.y);
			i32x4 x2 = x1 + i32x4(1), y2 = y1 + i32x4(1);

			floatq dx = pos.x - floatq(x1), dy = pos.y - floatq(y1);

			//TODO: wylaczyc odbicie w pionie
			y1 = int(tex->Height()) - y1;
			y2 = int(tex->Height()) - y2;

			x1 >>= mip;
			y1 >>= mip;
			x2 >>= mip;
			y2 >>= mip;

			x1 &= i32x4(wMask >> mip);
			y1 &= i32x4(hMask >> mip);
			x2 &= i32x4(wMask >> mip);
			y2 &= i32x4(hMask >> mip);
			x1  = x1 + x1 + x1;
			x2  = x2 + x2 + x2;

			y1 *= pitch;
			y2 *= pitch;

			i32x4 o[4] = { x1 + y1, x2 + y1, x1 + y2, x2 + y2 };

#define DATA(a, b)    *(u32*)&data[o[a][b]]

			//	s.temp1 = Vec3q(B(0, 0), G(0, 0), R(0, 0)) * f32x4(1.0f / 255.0f);
			//	continue;
			floatq red, green, blue; {
				// TODO upewnic sie ze mozna czytac zawsze 4 bajty
				i32x4 col0( DATA(0, 0), DATA(0, 1), DATA(0, 2), DATA(0, 3) );
				i32x4 col1( DATA(1, 0), DATA(1, 1), DATA(1, 2), DATA(1, 3) );
				i32x4 col2( DATA(2, 0), DATA(2, 1), DATA(2, 2), DATA(2, 3) );
				i32x4 col3( DATA(3, 0), DATA(3, 1), DATA(3, 2), DATA(3, 3) );

				floatq r[4], g[4], b[4];

				r[0] = floatq( col0 & i32x4(255) );
				g[0] = floatq( Shr<8>(col0) & i32x4(255) );
				b[0] = floatq( Shr<16>(col0) & i32x4(255) );

				r[1] = floatq( col1 & i32x4(255) );
				g[1] = floatq( Shr<8>(col1) & i32x4(255) );
				b[1] = floatq( Shr<16>(col1) & i32x4(255) );

				r[2] = floatq( col2 & i32x4(255) );
				g[2] = floatq( Shr<8>(col2) & i32x4(255) );
				b[2] = floatq( Shr<16>(col2) & i32x4(255) );

				r[3] = floatq( col3 & i32x4(255) );
				g[3] = floatq( Shr<8>(col3) & i32x4(255) );
				b[3] = floatq( Shr<16>(col3) & i32x4(255) );

				red = Lerp(Lerp(r[0], r[1], dx), Lerp(r[2], r[3], dx), dy);
				green = Lerp(Lerp(g[0], g[1], dx), Lerp(g[2], g[3], dx), dy);
				blue = Lerp(Lerp(b[0], b[1], dx), Lerp(b[2], b[3], dx), dy);
			}
#undef DATA

			s.temp1 = Vec3q(red, green, blue) * f32x4(1.0f / 255.0f);
		}
	}