Пример #1
0
static void consistsOf(std::vector<v8> parts, const v8& data) {
	auto it = data.begin();
	while (it != data.end()) {
		if (parts.empty()) {
			FAIL() << "Unexpected elements left in data: "
			       << testing::PrintToString(v8(it, data.end())) << std::endl;
			return;
		}

		std::vector<v8>::iterator found = findElement(it, parts);
		if (found == parts.end()) {
			ADD_FAILURE() << "None of the following values could be found at position "
		                << std::distance(data.begin(), it) << " of data:\n"
										<< testing::PrintToString(v8(it, data.end())) << "\n";
			for (auto part : parts)
				std::cerr << testing::PrintToString(part) << "\n";

			return;
		}

		it += found->size();
		parts.erase(found);
	}

	ASSERT_TRUE(parts.empty());
}
Пример #2
0
vector<uint8_t> HttpSession::getContent() {
	auto sz = contentSize();
	vector<uint8_t> v8(sz);
	istream is(&impl->data);
	is.read((char*)&v8[0], sz);
	return v8;
}
Пример #3
0
void DynamicGeometry::AddLineBox(const glm::vec3 & min, const glm::vec3 & max, const glm::vec3& color)
{
	glm::vec3 v1(min.x, min.y, min.z);
	glm::vec3 v2(max.x, min.y, min.z);
	glm::vec3 v3(max.x, min.y, max.z);
	glm::vec3 v4(min.x, min.y, max.z);
	glm::vec3 v5(min.x, max.y, min.z);
	glm::vec3 v6(max.x, max.y, min.z);
	glm::vec3 v7(max.x, max.y, max.z);
	glm::vec3 v8(min.x, max.y, max.z);

	unsigned int base_index = (unsigned int)m_verts.size();
	m_verts.push_back(v1);
	m_verts.push_back(v2);
	m_verts.push_back(v3);
	m_verts.push_back(v4);
	m_verts.push_back(v5);
	m_verts.push_back(v6);
	m_verts.push_back(v7);
	m_verts.push_back(v8);

	m_vert_colors.push_back(color);
	m_vert_colors.push_back(color);
	m_vert_colors.push_back(color);
	m_vert_colors.push_back(color);
	m_vert_colors.push_back(color);
	m_vert_colors.push_back(color);
	m_vert_colors.push_back(color);
	m_vert_colors.push_back(color);

	m_inds.push_back(base_index + 0);
	m_inds.push_back(base_index + 1);
	m_inds.push_back(base_index + 1);
	m_inds.push_back(base_index + 2);
	m_inds.push_back(base_index + 2);
	m_inds.push_back(base_index + 3);
	m_inds.push_back(base_index + 3);
	m_inds.push_back(base_index + 0);

	m_inds.push_back(base_index + 4);
	m_inds.push_back(base_index + 5);
	m_inds.push_back(base_index + 5);
	m_inds.push_back(base_index + 6);
	m_inds.push_back(base_index + 6);
	m_inds.push_back(base_index + 7);
	m_inds.push_back(base_index + 7);
	m_inds.push_back(base_index + 4);

	m_inds.push_back(base_index + 0);
	m_inds.push_back(base_index + 4);
	m_inds.push_back(base_index + 1);
	m_inds.push_back(base_index + 5);
	m_inds.push_back(base_index + 2);
	m_inds.push_back(base_index + 6);
	m_inds.push_back(base_index + 3);
	m_inds.push_back(base_index + 7);
}
Пример #4
0
String ReplaceEnvironmentVariables( const String& s0 )
{
   String s( s0 );
   size_type p = 0;

   for ( ;; )
   {
      for ( ;; )
      {
         p = s.Find( '$', p );
         if ( p == String::notFound )
            return s;
         if ( p == 0 || s[p-1] != '\\' )
            break;
         s.Delete( p-1 );
      }

      size_type p1 = p;
      size_type n = s.Length();
      while ( ++p1 < n )
      {
         int c = int( s[p1] );
         if ( (c < 'A' || c > 'Z') && (c < 'a' || c > 'z') && (c < '0' || c > '9') && c != '_' )
            break;
      }

      String var( s.Substring( p+1, p1-p-1 ) );
      if ( !var.IsEmpty() )
      {
         IsoString v8( var );
         var = ReplaceEnvironmentVariables( String( ::getenv( v8.c_str() ) ) );
      }

      s.Replace( p, p1-p, var );

      p += var.Length();
   }
}
Пример #5
0
void VectorTest::test_constructor(void)
{
   message += "test_constructor\n";

   std::string file_name = "../data/vector.dat";

   // Default 

   Vector<bool> v1;

   assert_true(v1.size() == 0, LOG);   

   // Size

   Vector<bool> v2(1);

   assert_true(v2.size() == 1, LOG);

   // Size initialization

   Vector<bool> v3(1, false);

   assert_true(v3.size() == 1, LOG);
   assert_true(v3[0] == false, LOG);

   // File

   Vector<int> v4(3, 0);
   v4.save(file_name);

   Vector<int> w4(file_name);
   
   assert_true(w4.size() == 3, LOG);
   assert_true(w4 == 0, LOG);

   // Sequential

   Vector<int> v6(10, 5, 50);

   assert_true(v6.size() == 9, LOG);
   assert_true(v6[0] == 10, LOG);
   assert_true(v6[8] == 50, LOG);

   Vector<double> v7(3.0, 0.2, 3.8);

   assert_true(v7.size() == 5, LOG);
   assert_true(v7[0] == 3.0, LOG);
   assert_true(v7[4] == 3.8, LOG);

   Vector<int> v8(9, -1, 1);

   assert_true(v8.size() == 9, LOG);
   assert_true(v8[0] == 9, LOG);
   assert_true(v8[8] == 1, LOG);

   // Copy

   Vector<std::string> v5(1, "hello");

   Vector<std::string> w5(v5);

   assert_true(w5.size() == 1, LOG);
   assert_true(w5[0] == "hello", LOG);

}
Пример #6
0
void ValueTest::onEnter()
{
    UnitTestDemo::onEnter();

    Value v1;
    CCASSERT(v1.getType() == Value::Type::NONE, "");
    CCASSERT(v1.isNull(), "");

    Value v2(100);
    CCASSERT(v2.getType() == Value::Type::INTEGER, "");
    CCASSERT(!v2.isNull(), "");

    Value v3(101.4f);
    CCASSERT(v3.getType() == Value::Type::FLOAT, "");
    CCASSERT(!v3.isNull(), "");

    Value v4(106.1);
    CCASSERT(v4.getType() == Value::Type::DOUBLE, "");
    CCASSERT(!v4.isNull(), "");

    unsigned char byte = 50;
    Value v5(byte);
    CCASSERT(v5.getType() == Value::Type::BYTE, "");
    CCASSERT(!v5.isNull(), "");

    Value v6(true);
    CCASSERT(v6.getType() == Value::Type::BOOLEAN, "");
    CCASSERT(!v6.isNull(), "");

    Value v7("string");
    CCASSERT(v7.getType() == Value::Type::STRING, "");
    CCASSERT(!v7.isNull(), "");

    Value v8(std::string("string2"));
    CCASSERT(v8.getType() == Value::Type::STRING, "");
    CCASSERT(!v8.isNull(), "");

    auto createValueVector = [&]() {
        ValueVector ret;
        ret.push_back(v1);
        ret.push_back(v2);
        ret.push_back(v3);
        return ret;
    };


    Value v9(createValueVector());
    CCASSERT(v9.getType() == Value::Type::VECTOR, "");
    CCASSERT(!v9.isNull(), "");

    auto createValueMap = [&]() {
        ValueMap ret;
        ret["aaa"] = v1;
        ret["bbb"] = v2;
        ret["ccc"] = v3;
        return ret;
    };

    Value v10(createValueMap());
    CCASSERT(v10.getType() == Value::Type::MAP, "");
    CCASSERT(!v10.isNull(), "");

    auto createValueMapIntKey = [&]() {
        ValueMapIntKey ret;
        ret[111] = v1;
        ret[222] = v2;
        ret[333] = v3;
        return ret;
    };

    Value v11(createValueMapIntKey());
    CCASSERT(v11.getType() == Value::Type::INT_KEY_MAP, "");
    CCASSERT(!v11.isNull(), "");
}
Пример #7
0
void TestTupleList()
{
	test_db_config::DbConfig config;
	bool bRet = config.Init();
	assert( bRet == true );
	occiwrapper::ConnectionInfo info( config.GetStrIp(), 1521, config.GetUserName(), config.GetPassword(), config.GetSid() );
	occiwrapper::SessionFactory sf;
	occiwrapper::Session s = sf.Create( info );
	string strErrMsg;

	struct tm objTm;
	objTm.tm_year = 2014 - 1900;
	objTm.tm_mon = 11;
	objTm.tm_mday = 30;
	objTm.tm_hour = 10;
	objTm.tm_min = 43;
	objTm.tm_sec = 0;

	s << strCreateTable, now, bRet, strErrMsg;

	// test 1 elements
	s << "truncate table tbl_test_tuple_elements", now, bRet, strErrMsg;
	assert( bRet );
	tuple< int > t1[ 2 ];
	t1[ 0 ] = make_tuple( 1 );
	t1[ 1 ] = make_tuple( 2 );
	list< tuple< int > > v1( t1, t1 + 2 );
	s << "insert into tbl_test_tuple_elements( t1 ) values ( :1 )", batched_use( v1 ), now, bRet, strErrMsg;
	assert( bRet );
	list< tuple< int > > v1Out;
	s << "select t1 from tbl_test_tuple_elements", into( v1Out ), now, bRet, strErrMsg;
	assert( bRet );
	assert( v1Out.size() == 2 );

	// test 2 elements
	s << "truncate table tbl_test_tuple_elements", now, bRet, strErrMsg;
	assert( bRet );
	tuple< int, float > t2[ 2 ];
	t2[ 0 ] = make_tuple( 1, 1.1 );
	t2[ 1 ] = make_tuple( 2, 2.1 );
	list< tuple< int, float > > v2( t2, t2 + 2 );
	s << "insert into tbl_test_tuple_elements( t1, t2 ) values ( :1, :2 )", batched_use( v2 ), now, bRet, strErrMsg;
	assert( bRet );
	list< tuple< int, float > > v2Out;
	s << "select t1, t2 from tbl_test_tuple_elements", into( v2Out ), now, bRet, strErrMsg;
	assert( bRet );
	assert( v2Out.size() == 2 );

	// test 3 elements
	s << "truncate table tbl_test_tuple_elements", now, bRet, strErrMsg;
	assert( bRet );
	tuple< int, float, string > t3[ 2 ];
	t3[ 0 ] = make_tuple( 1, 1.1, "str1" );
	t3[ 1 ] = make_tuple( 2, 2.1, "str2" );
	list< tuple< int, float, string > > v3( t3, t3 + 2 );
	s << "insert into tbl_test_tuple_elements( t1, t2, t3 ) values ( :1, :2, :3 )", batched_use( v3 ), now, bRet, strErrMsg;
	assert( bRet );
	list< tuple< int, float, string > > v3Out;
	s << "select t1, t2, t3 from tbl_test_tuple_elements", into( v3Out ), now, bRet, strErrMsg;
	assert( bRet );
	assert( v3Out.size() == 2 );

	// test 4 elements
	s << "truncate table tbl_test_tuple_elements", now, bRet, strErrMsg;
	assert( bRet );
	tuple< int, float, string, struct tm > t4[ 2 ];
	t4[ 0 ] = make_tuple( 1, 1.1, "str1", objTm );
	t4[ 1 ] = make_tuple( 2, 2.1, "str2", objTm );
	list< tuple< int, float, string, struct tm > > v4( t4, t4 + 2 );
	s << "insert into tbl_test_tuple_elements( t1, t2, t3, t4 ) values ( :1, :2, :3, :4 )", batched_use( v4 ), now, bRet, strErrMsg;
	assert( bRet );
	list< tuple< int, float, string, struct tm > > v4Out;
	s << "select t1, t2, t3, t4 from tbl_test_tuple_elements", into( v4Out ), now, bRet, strErrMsg;
	assert( bRet );
	assert( v4Out.size() == 2 );

	// test 5 elements
	s << "truncate table tbl_test_tuple_elements", now, bRet, strErrMsg;
	assert( bRet );
	tuple< int, float, string, struct tm, struct tm > t5[ 2 ];
	t5[ 0 ] = make_tuple( 1, 1.1, "str1", objTm, objTm );
	t5[ 1 ] = make_tuple( 2, 2.1, "str2", objTm, objTm );
	list< tuple< int, float, string, struct tm, struct tm > > v5( t5, t5 + 2 );
	s << "insert into tbl_test_tuple_elements( t1, t2, t3, t4, t5 ) values ( :1, :2, :3, :4, :5 )", batched_use( v5 ), now, bRet, strErrMsg;
	assert( bRet );
	list< tuple< int, float, string, struct tm, struct tm > > v5Out;
	s << "select t1, t2, t3, t4, t5 from tbl_test_tuple_elements", into( v5Out ), now, bRet, strErrMsg;
	assert( bRet );
	assert( v5Out.size() == 2 );

	
	// test 6 elements
	s << "truncate table tbl_test_tuple_elements", now, bRet, strErrMsg;
	assert( bRet );
	tuple< int, float, string, struct tm, struct tm, double > t6[ 2 ];
	t6[ 0 ] = make_tuple( 1, 1.1, "str1", objTm, objTm, 1.2 );
	t6[ 1 ] = make_tuple( 2, 2.1, "str2", objTm, objTm, 2.2 );
	list< tuple< int, float, string, struct tm, struct tm, double > > v6( t6, t6 + 2 );
	s << "insert into tbl_test_tuple_elements( t1, t2, t3, t4, t5, t6 ) values ( :1, :2, :3, :4, :5, :6 )", batched_use( v6 ), now, bRet, strErrMsg;
	assert( bRet );
	list< tuple< int, float, string, struct tm, struct tm, double > > v6Out;
	s << "select t1, t2, t3, t4, t5, t6 from tbl_test_tuple_elements", into( v6Out ), now, bRet, strErrMsg;
	assert( bRet );
	assert( v6Out.size() == 2 );

	// test 7 element
	s << "truncate table tbl_test_tuple_elements", now, bRet, strErrMsg;
	assert( bRet );
	tuple< int, float, string, struct tm, struct tm, double, double > t7[ 2 ];
	t7[ 0 ] = make_tuple( 1, 1.1, "str1", objTm, objTm, 1.2, 3.1 );
	t7[ 1 ] = make_tuple( 2, 2.1, "str2", objTm, objTm, 2.2, 3.2 );
	list< tuple< int, float, string, struct tm, struct tm, double, double > > v7( t7, t7 + 2 );
	s << "insert into tbl_test_tuple_elements( t1, t2, t3, t4, t5, t6, t7 ) values ( :1, :2, :3, :4, :5, :6, :7 )", batched_use( v7 ), now, bRet, strErrMsg;
	assert( bRet );
	list< tuple< int, float, string, struct tm, struct tm, double, double > > v7Out;
	s << "select t1, t2, t3, t4, t5, t6, t7 from tbl_test_tuple_elements", into( v7Out ), now, bRet, strErrMsg;
	assert( bRet );
	assert( v7Out.size() == 2 );

	// test 8 element
	s << "truncate table tbl_test_tuple_elements", now, bRet, strErrMsg;
	assert( bRet );
	tuple< int, float, string, struct tm, struct tm, double, double, string > t8[ 2 ];
	t8[ 0 ] = make_tuple( 1, 1.1, "str1", objTm, objTm, 1.2, 3.1, "str8_1" );
	t8[ 1 ] = make_tuple( 2, 2.1, "str2", objTm, objTm, 2.2, 3.2, "str8_2" );
	list< tuple< int, float, string, struct tm, struct tm, double, double, string > > v8( t8, t8 + 2 );
	s << "insert into tbl_test_tuple_elements( t1, t2, t3, t4, t5, t6, t7, t8 ) values ( :1, :2, :3, :4, :5, :6, :7, :8 )", batched_use( v8 ), now, bRet, strErrMsg;
	assert( bRet );
	list< tuple< int, float, string, struct tm, struct tm, double, double, string > > v8Out;
	s << "select t1, t2, t3, t4, t5, t6, t7, t8 from tbl_test_tuple_elements", into( v8Out ), now, bRet, strErrMsg;
	assert( bRet );
	assert( v8Out.size() == 2 );

	// test 9 element
	s << "truncate table tbl_test_tuple_elements", now, bRet, strErrMsg;
	assert( bRet );
	tuple< int, float, string, struct tm, struct tm, double, double, string, string > t9[ 2 ];
	t9[ 0 ] = make_tuple( 1, 1.1, "str1", objTm, objTm, 1.2, 3.1, "str8_1", "str9_1" );
	t9[ 1 ] = make_tuple( 2, 2.1, "str2", objTm, objTm, 2.2, 3.2, "str8_2", "str9_2" );
	list< tuple< int, float, string, struct tm, struct tm, double, double, string, string > > v9( t9, t9 + 2 );
	s << "insert into tbl_test_tuple_elements( t1, t2, t3, t4, t5, t6, t7, t8, t9 ) values ( :1, :2, :3, :4, :5, :6, :7, :8, :9 )", batched_use( v9 ), now, bRet, strErrMsg;
	assert( bRet );
	list< tuple< int, float, string, struct tm, struct tm, double, double, string, string > > v9Out;
	s << "select t1, t2, t3, t4, t5, t6, t7, t8, t9 from tbl_test_tuple_elements", into( v9Out ), now, bRet, strErrMsg;
	assert( bRet );
	assert( v9Out.size() == 2 );

	// test 10 element
	s << "truncate table tbl_test_tuple_elements", now, bRet, strErrMsg;
	assert( bRet );
	tuple< int, float, string, struct tm, struct tm, double, double, string, string, string > t10[ 2 ];
	t10[ 0 ] = make_tuple( 1, 1.1, "str1", objTm, objTm, 1.2, 3.1, "str8_1", "str9_1", "str10_1" );
	t10[ 1 ] = make_tuple( 2, 2.1, "str2", objTm, objTm, 2.2, 3.2, "str8_2", "str9_2", "str10_2" );
	list< tuple< int, float, string, struct tm, struct tm, double, double, string, string, string > > v10( t10, t10 + 2 );
	s << "insert into tbl_test_tuple_elements( t1, t2, t3, t4, t5, t6, t7, t8, t9, t10 ) values ( :1, :2, :3, :4, :5, :6, :7, :8, :9, :10 )", batched_use( v10 ), now, bRet, strErrMsg;
	assert( bRet );
	list< tuple< int, float, string, struct tm, struct tm, double, double, string, string, string > > v10Out;
	s << "select t1, t2, t3, t4, t5, t6, t7, t8, t9, t10 from tbl_test_tuple_elements", into( v10Out ), now, bRet, strErrMsg;
	assert( bRet );
	assert( v10Out.size() == 2 );

	s << "drop table tbl_test_tuple_elements", now, bRet, strErrMsg;
	assert( bRet );
}
void
dmz::StarfighterPluginSpaceBoxOSG::_create_box () {

   const String ImageName (_rc.find_file (_imgRc));

   osg::ref_ptr<osg::Image> img =
      (ImageName ? osgDB::readImageFile (ImageName.get_buffer ()) : 0);

   if (img.valid ()) {

      osg::Geode* geode = new osg::Geode ();

      osg::Geometry* geom = new osg::Geometry;

      osg::Vec4Array* colors = new osg::Vec4Array;
      colors->push_back (osg::Vec4 (1.0f, 1.0f, 1.0f, 1.0f));
      geom->setColorArray (colors);
      geom->setColorBinding (osg::Geometry::BIND_OVERALL);

      osg::StateSet *stateset = geom->getOrCreateStateSet ();
      stateset->setMode (GL_BLEND, osg::StateAttribute::ON);

#if 0
      osg::ref_ptr<osg::Material> material = new osg::Material;

      material->setEmission (
         osg::Material::FRONT_AND_BACK,
         osg::Vec4 (1.0, 1.0, 1.0, 1.0));

      stateset->setAttributeAndModes (material.get (), osg::StateAttribute::ON);
#endif

      osg::Texture2D *tex = new osg::Texture2D (img.get ());
      tex->setWrap (osg::Texture2D::WRAP_S, osg::Texture2D::REPEAT);
      tex->setWrap (osg::Texture2D::WRAP_T, osg::Texture2D::REPEAT);

      stateset->setTextureAttributeAndModes (0, tex, osg::StateAttribute::ON);

      stateset->setAttributeAndModes (new osg::CullFace (osg::CullFace::BACK));

      osg::Vec3Array *vertices = new osg::Vec3Array;
      osg::Vec2Array *tcoords = new osg::Vec2Array;
      osg::Vec3Array* normals = new osg::Vec3Array;

      const float Off (_offset);

      osg::Vec3 v1 (-Off, -Off, -Off);
      osg::Vec3 v2 ( Off, -Off, -Off);
      osg::Vec3 v3 ( Off,  Off, -Off);
      osg::Vec3 v4 (-Off,  Off, -Off);
      osg::Vec3 v5 (-Off, -Off,  Off);
      osg::Vec3 v6 ( Off, -Off,  Off);
      osg::Vec3 v7 ( Off,  Off,  Off);
      osg::Vec3 v8 (-Off,  Off,  Off);

      osg::Vec3 n1 ( 1.0,  1.0,  1.0);
      osg::Vec3 n2 (-1.0,  1.0,  1.0);
      osg::Vec3 n3 (-1.0, -1.0,  1.0);
      osg::Vec3 n4 ( 1.0, -1.0,  1.0);
      osg::Vec3 n5 ( 1.0,  1.0, -1.0);
      osg::Vec3 n6 (-1.0,  1.0, -1.0);
      osg::Vec3 n7 (-1.0, -1.0, -1.0);
      osg::Vec3 n8 ( 1.0, -1.0, -1.0);

      n1.normalize ();
      n2.normalize ();
      n3.normalize ();
      n4.normalize ();
      n5.normalize ();
      n6.normalize ();
      n7.normalize ();
      n8.normalize ();

//      const float F1 (5.0f);
//      const float F2 (2.5f);
      const float F1 (5.0f);
      const float F2 (2.5f);
      int count = 0;

      // 1
      vertices->push_back (v1);
      vertices->push_back (v2);
      vertices->push_back (v3);
      vertices->push_back (v4);
      tcoords->push_back (osg::Vec2 (0.0, 0.0));
      tcoords->push_back (osg::Vec2 (0.0, F1));
      tcoords->push_back (osg::Vec2 (F2, F1));
      tcoords->push_back (osg::Vec2 (F2, 0.0));
      normals->push_back (n1);
      normals->push_back (n2);
      normals->push_back (n3);
      normals->push_back (n4);
      count += 4;

      // 2
      vertices->push_back (v4);
      vertices->push_back (v3);
      vertices->push_back (v7);
      vertices->push_back (v8);
      tcoords->push_back (osg::Vec2 (0.0, 0.0));
      tcoords->push_back (osg::Vec2 (0.0, F1));
      tcoords->push_back (osg::Vec2 (F2, F1));
      tcoords->push_back (osg::Vec2 (F2, 0.0));
      normals->push_back (n4);
      normals->push_back (n3);
      normals->push_back (n7);
      normals->push_back (n8);
      count += 4;

      // 3
      vertices->push_back (v8);
      vertices->push_back (v7);
      vertices->push_back (v6);
      vertices->push_back (v5);
      tcoords->push_back (osg::Vec2 (0.0, 0.0));
      tcoords->push_back (osg::Vec2 (0.0, F1));
      tcoords->push_back (osg::Vec2 (F2, F1));
      tcoords->push_back (osg::Vec2 (F2, 0.0));
      normals->push_back (n8);
      normals->push_back (n7);
      normals->push_back (n6);
      normals->push_back (n5);
      count += 4;

      // 4
      vertices->push_back (v5);
      vertices->push_back (v6);
      vertices->push_back (v2);
      vertices->push_back (v1);
      tcoords->push_back (osg::Vec2 (0.0, 0.0));
      tcoords->push_back (osg::Vec2 (0.0, F1));
      tcoords->push_back (osg::Vec2 (F2, F1));
      tcoords->push_back (osg::Vec2 (F2, 0.0));
      normals->push_back (n5);
      normals->push_back (n6);
      normals->push_back (n2);
      normals->push_back (n1);
      count += 4;

      // 5
      vertices->push_back (v3);
      vertices->push_back (v2);
      vertices->push_back (v6);
      vertices->push_back (v7);
      tcoords->push_back (osg::Vec2 (0.0, 0.0));
      tcoords->push_back (osg::Vec2 (0.0, F1));
      tcoords->push_back (osg::Vec2 (F2, F1));
      tcoords->push_back (osg::Vec2 (F2, 0.0));
      normals->push_back (n3);
      normals->push_back (n2);
      normals->push_back (n6);
      normals->push_back (n7);
      count += 4;

      // 6
      vertices->push_back (v1);
      vertices->push_back (v4);
      vertices->push_back (v8);
      vertices->push_back (v5);
      tcoords->push_back (osg::Vec2 (0.0, 0.0));
      tcoords->push_back (osg::Vec2 (0.0, F1));
      tcoords->push_back (osg::Vec2 (F2, F1));
      tcoords->push_back (osg::Vec2 (F2, 0.0));
      normals->push_back (n1);
      normals->push_back (n4);
      normals->push_back (n8);
      normals->push_back (n5);
      count += 4;

      geom->setNormalArray (normals);
      geom->setNormalBinding (osg::Geometry::BIND_PER_VERTEX);
      geom->addPrimitiveSet (new osg::DrawArrays (GL_QUADS, 0, count));
      geom->setVertexArray (vertices);
      geom->setTexCoordArray (0, tcoords);
      geode->addDrawable (geom);

      _box = new osg::MatrixTransform ();

      _box->addChild (geode);
   }
   else { _log.error << "Failed to load: " << _imgRc << ":" << ImageName << endl; }
}
Пример #9
0
//Define vertices and triangles
void CTitanic::init(float aScale)
	{
	this->clearMesh();

	TVector3 v0(-4,2,2);
	this->iVertices.push_back(v0*aScale);

	TVector3 v1(-3,1,0);
	this->iVertices.push_back(v1*aScale);

	TVector3 v2(-3,-1,0);
	this->iVertices.push_back(v2*aScale);

	TVector3 v3(-4,-2,2);
	this->iVertices.push_back(v3*aScale);

	TVector3 v4(3,2,2);
	this->iVertices.push_back(v4*aScale);

	TVector3 v5(3,1,0);
	this->iVertices.push_back(v5*aScale);

	TVector3 v6(3,-1,0);
	this->iVertices.push_back(v6*aScale);

	TVector3 v7(3,-2,2);
	this->iVertices.push_back(v7*aScale);

	TVector3 v8(5,0,2);
	this->iVertices.push_back(v8*aScale);

/*
	TTriangle t0(0,2,1);
	this->iTriangles.push_back(t0);


	TTriangle t1(0,3,2);
	this->iTriangles.push_back(t1);


	TTriangle t2(0,1,4);
	this->iTriangles.push_back(t2);


	TTriangle t3(1,5,4);
	this->iTriangles.push_back(t3);


	TTriangle t4(1,6,5);
	this->iTriangles.push_back(t4);


	TTriangle t5(1,2,6);
	this->iTriangles.push_back(t5);


	TTriangle t6(2,3,6);
	this->iTriangles.push_back(t6);


	TTriangle t7(3,7,6);
	this->iTriangles.push_back(t7);


	TTriangle t8(4,5,8);
	this->iTriangles.push_back(t8);


	TTriangle t9(5,6,8);
	this->iTriangles.push_back(t9);


	TTriangle t10(6,7,8);
	this->iTriangles.push_back(t10);


	TTriangle t11(0,4,3);
	this->iTriangles.push_back(t11);


	TTriangle t12(3,4,7);
	this->iTriangles.push_back(t12);


	TTriangle t13(4,8,7);
	this->iTriangles.push_back(t13);

*/

	TTriangle t0(0,1,2);
	this->iTriangles.push_back(t0);

	TTriangle t1(0,2,3);
	this->iTriangles.push_back(t1);

	TTriangle t2(0,4,1);
	this->iTriangles.push_back(t2);

	TTriangle t3(1,4,5);
	this->iTriangles.push_back(t3);

	TTriangle t4(1,5,6);
	this->iTriangles.push_back(t4);

	TTriangle t5(1,6,2);
	this->iTriangles.push_back(t5);

	TTriangle t6(2,6,3);
	this->iTriangles.push_back(t6);

	TTriangle t7(3,6,7);
	this->iTriangles.push_back(t7);

	TTriangle t8(4,8,5);
	this->iTriangles.push_back(t8);

	TTriangle t9(5,8,6);
	this->iTriangles.push_back(t9);

	TTriangle t10(6,8,7);
	this->iTriangles.push_back(t10);

	TTriangle t11(0,3,4);
	this->iTriangles.push_back(t11);

	TTriangle t12(3,7,4);
	this->iTriangles.push_back(t12);

	TTriangle t13(4,7,8);
	this->iTriangles.push_back(t13);
	}
Пример #10
0
void QhullLinkedList_test::
t_QhullLinkedList_iterator()
{
    RboxPoints rcube("c");
    Qhull q(rcube,"QR0");  // rotated unit cube
    QhullVertexList vs(q.endVertex(), q.endVertex());
    QhullVertexListIterator i= vs;
    QCOMPARE(vs.count(), 0);
    QVERIFY(!i.hasNext());
    QVERIFY(!i.hasPrevious());
    i.toBack();
    QVERIFY(!i.hasNext());
    QVERIFY(!i.hasPrevious());

    QhullVertexList vs2 = q.vertexList();
    QhullVertexListIterator i2(vs2);
    QCOMPARE(vs2.count(), 8);
    i= vs2;
    QVERIFY(i2.hasNext());
    QVERIFY(!i2.hasPrevious());
    QVERIFY(i.hasNext());
    QVERIFY(!i.hasPrevious());
    i2.toBack();
    i.toFront();
    QVERIFY(!i2.hasNext());
    QVERIFY(i2.hasPrevious());
    QVERIFY(i.hasNext());
    QVERIFY(!i.hasPrevious());

    // i at front, i2 at end/back, 4 neighbors
    QhullVertexList vs3 = q.vertexList(); // same as vs2
    QhullVertex v3(vs3.first());
    QhullVertex v4= vs3.first();
    QCOMPARE(v3, v4);
    QVERIFY(v3==v4);
    QhullVertex v5(v4.next());
    QVERIFY(v4!=v5);
    QhullVertex v6(v5.next());
    QhullVertex v7(v6.next());
    QhullVertex v8(vs3.last());
    QCOMPARE(i2.peekPrevious(), v8);
    i2.previous();
    i2.previous();
    i2.previous();
    i2.previous();
    QCOMPARE(i2.previous(), v7);
    QCOMPARE(i2.previous(), v6);
    QCOMPARE(i2.previous(), v5);
    QCOMPARE(i2.previous(), v4);
    QVERIFY(!i2.hasPrevious());
    QCOMPARE(i.peekNext(), v4);
    // i.peekNext()= 1.0; // compiler error
    QCOMPARE(i.next(), v4);
    QCOMPARE(i.peekNext(), v5);
    QCOMPARE(i.next(), v5);
    QCOMPARE(i.next(), v6);
    QCOMPARE(i.next(), v7);
    i.next();
    i.next();
    i.next();
    QCOMPARE(i.next(), v8);
    QVERIFY(!i.hasNext());
    i.toFront();
    QCOMPARE(i.next(), v4);
}//t_QhullLinkedList_iterator
Пример #11
0
void bench_front_to_surf
     (
          Flux_Pts   front_8,
          Flux_Pts   front_4,
          Flux_Pts   surf_with_fr,
          Flux_Pts   surf_without_fr,
          Fonc_Num   fcarac,
          bool       with_fc,
          bool       test_dil,
          Pt2di      sz
     )
{
     Im2D_U_INT1 i1(sz.x,sz.y,0);
     Im2D_U_INT1 i2(sz.x,sz.y,0);

     INT dif;
     if (with_fc)
     {
         ELISE_COPY(surf_without_fr,1,i1.out());
         ELISE_COPY(i2.all_pts(),fcarac,i2.out());

         ELISE_COPY(i1.all_pts(),Abs(i1.in()-i2.in()),sigma(dif));

          BENCH_ASSERT(dif == 0);
     }
     else
         ELISE_COPY(surf_without_fr,1,i1.out()|i2.out());

     Neighbourhood v4 (TAB_4_NEIGH,4);
     Neighbourhood v8 (TAB_8_NEIGH,8);
     
     if (test_dil)
     {
         bench_fr_front_to_surf(front_8,i1,v4);

         bench_fr_front_to_surf(front_4,i2,v8);
     }


     ELISE_COPY(i1.all_pts(),1,i1.out());
     ELISE_COPY(i1.border(1),0,i1.out());
     ELISE_COPY(front_8,0,i1.out());
     ELISE_COPY(conc(Pt2di(1,1),sel_func(v4,i1.in()==1)),0,i1.out());

     ELISE_COPY(i2.all_pts(),0,i2.out());
     ELISE_COPY(surf_without_fr,1,i2.out());
     ELISE_COPY(i1.all_pts(),Abs(i1.in()-i2.in()),sigma(dif));
      
     BENCH_ASSERT(dif == 0);


     ELISE_COPY(i1.all_pts(),0,i1.out() | i2.out());

     ELISE_COPY(surf_with_fr   ,1,i1.out());
     ELISE_COPY(surf_without_fr,2,i1.histo());

     ELISE_COPY(surf_with_fr   ,3,i2.out());
     ELISE_COPY(front_8        ,1,i2.out());

     
     ELISE_COPY(i1.all_pts(),Abs(i1.in()-i2.in()),sigma(dif));

     BENCH_ASSERT(dif == 0);

}
Пример #12
0
	/** 
	 * Test constructing and destructing a vector
	 */
	void TestVector::TestConstructor()
	{
		// Plain Old Data
		//---------------
		
		// Default constructor
		Vector<int> v1;
		AssertEquals(0u, v1.Size());

		// Fill constructor
		Vector<int> v2(3u);
		AssertEquals(3u, v2.Size());
		AssertEquals(3u, v2.Capacity());
		for(uint i = 0; i < 3; ++i)
		{
			AssertEquals(0, v2[i]);
		}

		// Fill constructor with value
		Vector<int> v3(3u, 3);
		AssertEquals(3u, v3.Size());
		AssertEquals(3u, v3.Capacity());
		for(uint i = 0; i < 3; ++i)
		{
			AssertEquals(3, v3[i]);
		}
		 
		// Copy constructor
		Vector<int> v4(v3);
		AssertEquals(3u, v4.Size());
		AssertEquals(3u, v4.Capacity());
		for(uint i = 0; i < 3; ++i)
		{
			AssertEquals(3, v4[i]);
		}
		 
		// Assignment
		Vector<int> v5 = v4;
		AssertEquals(3u, v5.Size());
		AssertEquals(3u, v5.Capacity());
		for(uint i = 0; i < 3; ++i)
		{
			AssertEquals(3, v5[i]);
		}
		
		// Class
		//------
		
		// Default simple object
		SimpleClass c1 = SimpleClass();
		SimpleClass c2 = SimpleClass(1, 2);

		// Default constructor
		Vector<SimpleClass> v6;
		AssertEquals(0u, v6.Size());

		// Fill constructor
		Vector<SimpleClass> v7(3u);
		AssertEquals(3u, v7.Size());
		AssertEquals(3u, v7.Capacity());
		for(uint i = 0; i < 3; ++i)
		{
			AssertEquals(c1, v7[i]);
		}

		// Fill constructor with value
		Vector<SimpleClass> v8(3u, c2);
		AssertEquals(3u, v8.Size());
		AssertEquals(3u, v8.Capacity());
		for(uint i = 0; i < 3; ++i)
		{
			AssertEquals(c2, v8[i]);
		}
		 
		// Copy constructor
		Vector<SimpleClass> v9(v8);
		AssertEquals(3u, v9.Size());
		AssertEquals(3u, v9.Capacity());
		for(uint i = 0; i < 3; ++i)
		{
			AssertEquals(c2, v9[i]);
		}
		 
		// Assignment
		Vector<SimpleClass> v10 = v9;
		AssertEquals(3u, v10.Size());
		AssertEquals(3u, v10.Capacity());
		for(uint i = 0; i < 3; ++i)
		{
			AssertEquals(c2, v10[i]);
		}
	}
Пример #13
0
void CIcosahedron::init( float s  ){

	this->clearMesh();
	float p = ((1.0 + sqrt(5.0))/2.0)*s;

	TVector3 v0(s,0.0,p);
	this->iVertices.push_back(v0);
	TVector3 v1(-s,0.0,p);
	this->iVertices.push_back(v1);
	TVector3 v2(s,0.0,-p);
	this->iVertices.push_back(v2);
	TVector3 v3(-s,0.0,-p);
	this->iVertices.push_back(v3);
	TVector3 v4(0.0,p,s);
	this->iVertices.push_back(v4);
	TVector3 v5(0,-p,s);
	this->iVertices.push_back(v5);
	TVector3 v6(0,p,-s);
	this->iVertices.push_back(v6);
	TVector3 v7(0.0,-p,-s);
	this->iVertices.push_back(v7);
	TVector3 v8(p,s,0.0);
	this->iVertices.push_back(v8);
	TVector3 v9(-p,s,0.0);
	this->iVertices.push_back(v9);
	TVector3 v10(p,-s,0.0);
	this->iVertices.push_back(v10);
	TVector3 v11(-p,-s,0.0);
	this->iVertices.push_back(v11);


	TTriangle t0(0,4,1);
	this->iTriangles.push_back(t0);

	TTriangle t1(0,1,5);
	this->iTriangles.push_back(t1);

	TTriangle t2(0,5,10);
	this->iTriangles.push_back(t2);

	TTriangle t3(0,10,8);
	this->iTriangles.push_back(t3);

	TTriangle t4(0,8,4);
	this->iTriangles.push_back(t4);

	TTriangle t5(4,8,6);
	this->iTriangles.push_back(t5);

	TTriangle t6(4,6,9);
	this->iTriangles.push_back(t6);

	TTriangle t7(4,9,1);
	this->iTriangles.push_back(t7);

	TTriangle t8(1,9,11);
	this->iTriangles.push_back(t8);

	TTriangle t9(1,11,5);
	this->iTriangles.push_back(t9);

	TTriangle t10(2,7,3);
	this->iTriangles.push_back(t10);

	TTriangle t11(2,3,6);
	this->iTriangles.push_back(t11);

	TTriangle t12(2,6,8);
	this->iTriangles.push_back(t12);

	TTriangle t13(2,8,10);
	this->iTriangles.push_back(t13);

	TTriangle t14(2,10,7);
	this->iTriangles.push_back(t14);

	TTriangle t15(7,10,5);
	this->iTriangles.push_back(t15);

	TTriangle t16(7,5,11);
	this->iTriangles.push_back(t16);

	TTriangle t17(7,11,3);
	this->iTriangles.push_back(t17);

	TTriangle t18(3,11,9);
	this->iTriangles.push_back(t18);

	TTriangle t19(3,9,6);
	this->iTriangles.push_back(t19);
	}
Пример #14
0
//----------------------------------------------------------------------------
void BspNodes::CreateScene ()
{
	// Create the scene graph.
	//
	// 1. The rectangles represent the BSP planes of the BSP tree.  They
	//    share a VertexColor3Effect.  You can see a plane from either side
	//    (backface culling disabled).  The planes do not interfere with view
	//    of the solid objects (wirestate enabled).
	//
	// 2. The sphere, tetrahedron, and cube share a TextureEffect.  These
	//    objects are convex.  The backfacing triangles are discarded
	//    (backface culling enabled).  The front facing triangles are drawn
	//    correctly by convexity, so depthbuffer reads are disabled and
	//    depthbuffer writes are enabled.  The BSP-based sorting of objects
	//    guarantees that front faces of convex objects in the foreground
	//    are drawn after the front faces of convex objects in the background,
	//    which allows us to set the depthbuffer state as we have.  That is,
	//    BSPNode sorts from back to front.
	//
	// 3. The torus has backface culling enabled and depth buffering enabled.
	//    This is necessary, because the torus is not convex.
	//
	// 4. Generally, if all objects are opaque, then you want to draw from
	//    front to back with depth buffering fully enabled.  You need to
	//    reverse-order the elements of the visible set before drawing.  If
	//    any of the objects are semitransparent, then drawing back to front
	//    is the correct order to handle transparency.  However, you do not
	//    get the benefit of early z-rejection for opaque objects.  A better
	//    BSP sorter needs to be built to produce a visible set with opaque
	//    objects listed first (front-to-back order) and semitransparent
	//    objects listed last (back-to-front order).
	//
	// scene
	//     ground
	//     bsp0
	//         bsp1
	//             bsp3
	//                 torus
	//                 rectangle3
	//                 sphere
	//             rectangle1
	//             tetrahedron
	//         rectangle0
	//         bsp2
	//             cube
	//             rectangle2
	//             octahedron

	mScene = new0 Node();

	// Create the ground.  It covers a square with vertices (1,1,0), (1,-1,0),
	// (-1,1,0), and (-1,-1,0).  Multiply the texture coordinates by a factor
	// to enhance the wrap-around.
	VertexFormat* vformat = VertexFormat::Create(2,
	                        VertexFormat::AU_POSITION, VertexFormat::AT_FLOAT3, 0,
	                        VertexFormat::AU_TEXCOORD, VertexFormat::AT_FLOAT2, 0);

	StandardMesh sm(vformat);
	VertexBufferAccessor vba;

	TriMesh* ground = sm.Rectangle(2, 2, 16.0f, 16.0f);
	vba.ApplyTo(ground);
	for (int i = 0; i < vba.GetNumVertices(); ++i)
	{
		Float2& tcoord = vba.TCoord<Float2>(0, i);
		tcoord[0] *= 128.0f;
		tcoord[1] *= 128.0f;
	}

	std::string path = Environment::GetPathR("Horizontal.wmtf");
	Texture2D* texture = Texture2D::LoadWMTF(path);
	ground->SetEffectInstance(Texture2DEffect::CreateUniqueInstance(texture,
	                          Shader::SF_LINEAR_LINEAR, Shader::SC_REPEAT, Shader::SC_REPEAT));
	mScene->AttachChild(ground);

	// Partition the region above the ground into 5 convex pieces.  Each plane
	// is perpendicular to the ground (not required generally).
	VertexColor3Effect* vceffect = new0 VertexColor3Effect();
	vceffect->GetCullState(0, 0)->Enabled = false;
	vceffect->GetWireState(0, 0)->Enabled = true;

	Vector2f v0(-1.0f, 1.0f);
	Vector2f v1(1.0f, -1.0f);
	Vector2f v2(-0.25f, 0.25f);
	Vector2f v3(-1.0f, -1.0f);
	Vector2f v4(0.0f, 0.0f);
	Vector2f v5(1.0f, 0.5f);
	Vector2f v6(-0.75f, -7.0f/12.0f);
	Vector2f v7(-0.75f, 0.75f);
	Vector2f v8(1.0f, 1.0f);

	BspNode* bsp0 = CreateNode(v0, v1, vceffect, Float3(1.0f, 0.0f, 0.0f));
	BspNode* bsp1 = CreateNode(v2, v3, vceffect, Float3(0.0f, 0.5f, 0.0f));
	BspNode* bsp2 = CreateNode(v4, v5, vceffect, Float3(0.0f, 0.0f, 1.0f));
	BspNode* bsp3 = CreateNode(v6, v7, vceffect, Float3(0.0f, 0.0f, 0.0f));

	bsp0->AttachPositiveChild(bsp1);
	bsp0->AttachNegativeChild(bsp2);
	bsp1->AttachPositiveChild(bsp3);

	// Attach an object in each convex region.
	float height = 0.1f;
	Vector2f center;
	TriMesh* mesh;

	// The texture effect for the convex objects.
	Texture2DEffect* cvxeffect =
	    new0 Texture2DEffect(Shader::SF_LINEAR_LINEAR);
	cvxeffect->GetDepthState(0, 0)->Enabled = false;
	cvxeffect->GetDepthState(0, 0)->Writable = true;

	// The texture effect for the torus.
	Texture2DEffect* toreffect =
	    new0 Texture2DEffect(Shader::SF_LINEAR_LINEAR);

	// The texture image shared by the objects.
	path = Environment::GetPathR("Flower.wmtf");
	texture = Texture2D::LoadWMTF(path);

	// Region 0: Create a torus mesh.
	mesh = sm.Torus(16, 16, 1.0f, 0.25f);
	mesh->SetEffectInstance(toreffect->CreateInstance(texture));
	mesh->LocalTransform.SetUniformScale(0.1f);
	center = (v2 + v6 + v7)/3.0f;
	mesh->LocalTransform.SetTranslate(APoint(center[0], center[1], height));
	bsp3->AttachPositiveChild(mesh);

	// Region 1: Create a sphere mesh.
	mesh = sm.Sphere(32, 16, 1.0f);
	mesh->SetEffectInstance(cvxeffect->CreateInstance(texture));
	mesh->LocalTransform.SetUniformScale(0.1f);
	center = (v0 + v3 + v6 + v7)/4.0f;
	mesh->LocalTransform.SetTranslate(APoint(center[0], center[1], height));
	bsp3->AttachNegativeChild(mesh);

	// Region 2: Create a tetrahedron.
	mesh = sm.Tetrahedron();
	mesh->SetEffectInstance(cvxeffect->CreateInstance(texture));
	mesh->LocalTransform.SetUniformScale(0.1f);
	center = (v1 + v2 + v3)/3.0f;
	mesh->LocalTransform.SetTranslate(APoint(center[0], center[1], height));
	bsp1->AttachNegativeChild(mesh);

	// Region 3: Create a hexahedron (cube).
	mesh = sm.Hexahedron();
	mesh->SetEffectInstance(cvxeffect->CreateInstance(texture));
	mesh->LocalTransform.SetUniformScale(0.1f);
	center = (v1 + v4 + v5)/3.0f;
	mesh->LocalTransform.SetTranslate(APoint(center[0], center[1], height));
	bsp2->AttachPositiveChild(mesh);

	// Region 4: Create an octahedron.
	mesh = sm.Octahedron();
	mesh->SetEffectInstance(cvxeffect->CreateInstance(texture));
	mesh->LocalTransform.SetUniformScale(0.1f);
	center = (v0 + v4 + v5 + v8)/4.0f;
	mesh->LocalTransform.SetTranslate(APoint(center[0], center[1], height));
	bsp2->AttachNegativeChild(mesh);

	mScene->AttachChild(bsp0);
}
Пример #15
0
osg::Drawable *ReverseTileNode::createReverseTile(void) const {
    // Get the tile
    ReverseTile* tile = static_cast<ReverseTile*>(_lego);

    // Get tile color
    QColor color = tile->getColor();

    // Get integer sizes
    int width = tile->getWidth();
    int length = tile->getLength();
    int height = 3;

    // Get real position, according to tile size
    double mw = (-width)*Lego::length_unit/2;
    double pw = (width)*Lego::length_unit/2;
    double mwp = (-width+2)*Lego::length_unit/2;
    double ml = (-length)*Lego::length_unit/2;
    double pl = (length)*Lego::length_unit/2;
    double mh = (-height)*Lego::height_unit/2;
    double ph = (height)*Lego::height_unit/2;
    double phm = (height-1)*Lego::height_unit/2;

    // Create 14 vertices
    osg::ref_ptr<osg::Vec3Array> vertices = new osg::Vec3Array;
    osg::Vec3 v0(mw, ml, mh);
    osg::Vec3 v1(mw, pl, mh);
    osg::Vec3 v2(mwp, pl, mh);
    osg::Vec3 v3(mwp, ml, mh);
    osg::Vec3 v4(pw, ml, phm);
    osg::Vec3 v5(pw, pl, phm);
    osg::Vec3 v6(pw, pl, ph);
    osg::Vec3 v7(pw, ml, ph);
    osg::Vec3 v8(mw, ml, ph);
    osg::Vec3 v9(mw, pl, ph);
    osg::Vec3 v10(mwp, ml, phm);
    osg::Vec3 v11(mwp, ml, ph);
    osg::Vec3 v12(mwp, pl, ph);
    osg::Vec3 v13(mwp, pl, phm);

    // Create 10 faces, 8 faces are quads splitted into two triangles
    // NB: Down face is transparent, we don't even create it

    // Front face t1
    vertices->push_back(v4);
    vertices->push_back(v5);
    vertices->push_back(v6);
    // Front face t2
    vertices->push_back(v4);
    vertices->push_back(v6);
    vertices->push_back(v7);

    // Back face t1
    vertices->push_back(v0);
    vertices->push_back(v1);
    vertices->push_back(v8);
    // Back face t2
    vertices->push_back(v1);
    vertices->push_back(v8);
    vertices->push_back(v9);

    // Top face t1
    vertices->push_back(v6);
    vertices->push_back(v7);
    vertices->push_back(v9);
    // Top face t2
    vertices->push_back(v7);
    vertices->push_back(v8);
    vertices->push_back(v9);

    // Slop face t1
    vertices->push_back(v2);
    vertices->push_back(v3);
    vertices->push_back(v5);
    // Slop face t2
    vertices->push_back(v3);
    vertices->push_back(v4);
    vertices->push_back(v5);

    // Right triangle face
    vertices->push_back(v2);
    vertices->push_back(v13);
    vertices->push_back(v5);

    // Right quad face t1
    vertices->push_back(v13);
    vertices->push_back(v12);
    vertices->push_back(v6);
    // Right quad face t2
    vertices->push_back(v13);
    vertices->push_back(v6);
    vertices->push_back(v5);

    // Right quad face down t1
    vertices->push_back(v1);
    vertices->push_back(v9);
    vertices->push_back(v12);
    // Right quad face down t2
    vertices->push_back(v1);
    vertices->push_back(v2);
    vertices->push_back(v12);

    // Left triangle face
    vertices->push_back(v3);
    vertices->push_back(v4);
    vertices->push_back(v10);

    // Left quad face t1
    vertices->push_back(v4);
    vertices->push_back(v10);
    vertices->push_back(v11);
    // Left quad face t2
    vertices->push_back(v4);
    vertices->push_back(v7);
    vertices->push_back(v11);

    // Left quad face down t1
    vertices->push_back(v0);
    vertices->push_back(v3);
    vertices->push_back(v8);
    // Left quad face down t2
    vertices->push_back(v3);
    vertices->push_back(v8);
    vertices->push_back(v11);

    // Create tile geometry
    osg::ref_ptr<osg::Geometry> tileGeometry = new osg::Geometry;

    // Match vertices
    tileGeometry->setVertexArray(vertices);

    // Add color (each rectangle has the same color except for the down one which is transparent)
    osg::Vec4 osgColor(static_cast<float>(color.red())/255.0, static_cast<float>(color.green())/255.0, static_cast<float>(color.blue())/255.0, 1.0);
    osg::ref_ptr<osg::Vec4Array> colors = new osg::Vec4Array;
    // Every face has the same color, so there is only one color
    colors->push_back(osgColor);

    // Match color
    tileGeometry->setColorArray(colors);
    tileGeometry->setColorBinding(osg::Geometry::BIND_OVERALL);

    // Create normals
    osg::ref_ptr<osg::Vec3Array> normals = new osg::Vec3Array;
    normals->push_back(osg::Vec3(1, 0, 0));
    normals->push_back(osg::Vec3(1, 0, 0));
    normals->push_back(osg::Vec3(-1, 0, 0));
    normals->push_back(osg::Vec3(-1, 0, 0));
    normals->push_back(osg::Vec3(0, 0, 1));
    normals->push_back(osg::Vec3(0, 0, 1));
    double w = pw - mwp;
    double h = phm - mh;
    double norm = std::sqrt(w*w + h*h);
    normals->push_back(osg::Vec3(h/norm, 0, -w/norm));
    normals->push_back(osg::Vec3(h/norm, 0, -w/norm));
    normals->push_back(osg::Vec3(0, 1, 0));
    normals->push_back(osg::Vec3(0, 1, 0));
    normals->push_back(osg::Vec3(0, 1, 0));
    normals->push_back(osg::Vec3(0, 1, 0));
    normals->push_back(osg::Vec3(0, 1, 0));
    normals->push_back(osg::Vec3(0, -1, 0));
    normals->push_back(osg::Vec3(0, -1, 0));
    normals->push_back(osg::Vec3(0, -1, 0));
    normals->push_back(osg::Vec3(0, -1, 0));
    normals->push_back(osg::Vec3(0, -1, 0));

    // Match normals
    tileGeometry->setNormalArray(normals);
    tileGeometry->setNormalBinding(osg::Geometry::BIND_PER_PRIMITIVE);

    // Define tile 18 GL_TRIANGLES with 20*3 vertices
    tileGeometry->addPrimitiveSet(new osg::DrawArrays(osg::PrimitiveSet::TRIANGLES, 0, 18*3));

    // Return the tile whithout plot
    return tileGeometry.release();
}
Пример #16
0
osg::Drawable *ClampNode::createBrick(void) const {
    // Get the brick
    Clamp* clamp = static_cast<Clamp*>(_lego);
    
    // Get brick color
    QColor color = clamp->getColor();

    // Get clamp bounding box
    clamp->calculateBoundingBox();
    BoundingBox bb = clamp->getBoundingBox();
    // Get integer sizes
    int width = bb.getWidth();
    int length = bb.getLength();
    int height = bb.getHeight();

    // Get real position, according to tile size
    double mw = (-width)*Lego::length_unit/2;
    double mwpm = (-width)*Lego::length_unit/2+Lego::height_unit/2;
    double mwp = (-width)*Lego::length_unit/2+0.93*Lego::height_unit;
    double pw = (width)*Lego::length_unit/2;
    double pwm = (width)*Lego::length_unit/2-Lego::height_unit/2;
    double ml = (-length)*Lego::length_unit/2;
    double mlp = (-length+0.5)*Lego::length_unit/2;
    double pl = (length)*Lego::length_unit/2;
    double plm = (length-0.5)*Lego::length_unit/2;
    double mh = (-height)*Lego::height_unit/2;
    double mhp = (-height)*Lego::height_unit/2+2*Lego::plot_top_height;
    double mhpm = (-height)*Lego::height_unit/2+Lego::plot_top_height;
    double phm = (height)*Lego::height_unit/2-Lego::height_unit/2;
    double phmp = (height)*Lego::height_unit/2-0.5*Lego::height_unit/2;
    
    // Create 3 vertices
    osg::ref_ptr<osg::Vec3Array> vertices = new osg::Vec3Array;
    osg::Vec3 v0(ml, mw, mh);
    osg::Vec3 v1(pl, mw, mh);
    osg::Vec3 v2(pl, pw, mh);
    osg::Vec3 v3(ml, pw, mh);
    osg::Vec3 v4(ml, pw, mhp);
    osg::Vec3 v5(pl, pw, mhp);
    osg::Vec3 v6(pl, mw, mhp);
    osg::Vec3 v7(ml, mw, mhp);
    osg::Vec3 v8(mlp, mw, mhp);
    osg::Vec3 v9(mlp, mw, phm);
    osg::Vec3 v10(ml, mw, phm);
    osg::Vec3 v11(ml, mwp, phmp);
    osg::Vec3 v12(mlp, mwp, phmp);
    osg::Vec3 v13(mlp, pw, mhp);
    osg::Vec3 v14(plm, mw, mhp);
    osg::Vec3 v15(plm, mw, phm);
    osg::Vec3 v16(pl, mw, phm);
    osg::Vec3 v17(pl, mwp, phmp);
    osg::Vec3 v18(plm, mwp, phmp);
    osg::Vec3 v19(plm, pw, mhp);
    osg::Vec3 v20(mlp, mwpm, mh);
    osg::Vec3 v21(plm, mwpm, mh);
    osg::Vec3 v22(plm, pwm, mh);
    osg::Vec3 v23(mlp, pwm, mh);
    osg::Vec3 v24(mlp, mwpm, mhpm);
    osg::Vec3 v25(plm, mwpm, mhpm);
    osg::Vec3 v26(plm, pwm, mhpm);
    osg::Vec3 v27(mlp, pwm, mhpm);
    
    // Create 1 faces, 0 faces are quads splitted into two triangles
    // NB: Down face is transparent, we don't even create it

    // Bottom
    vertices->push_back(v3);
    vertices->push_back(v2);
    vertices->push_back(v1);
    vertices->push_back(v0);
    // Bottom hole
    vertices->push_back(v20);
    vertices->push_back(v21);
    vertices->push_back(v22);
    vertices->push_back(v23);
    // Bottom far
    vertices->push_back(v24);
    vertices->push_back(v25);
    vertices->push_back(v26);
    vertices->push_back(v27);

    // Front face
    vertices->push_back(v2);
    vertices->push_back(v3);
    vertices->push_back(v4);
    vertices->push_back(v5);

    // Back face
    vertices->push_back(v0);
    vertices->push_back(v1);
    vertices->push_back(v6);
    vertices->push_back(v7);

    // Left bottom face
    vertices->push_back(v0);
    vertices->push_back(v3);
    vertices->push_back(v4);
    vertices->push_back(v7);

    // Right bottom face
    vertices->push_back(v1);
    vertices->push_back(v2);
    vertices->push_back(v5);
    vertices->push_back(v6);

    // Top face
    vertices->push_back(v4);
    vertices->push_back(v5);
    vertices->push_back(v6);
    vertices->push_back(v7);

    // Left part back
    vertices->push_back(v7);
    vertices->push_back(v8);
    vertices->push_back(v9);
    vertices->push_back(v10);

    // Left part left ext
    vertices->push_back(v4);
    vertices->push_back(v7);
    vertices->push_back(v10);
    vertices->push_back(v11);

    // Left part front
    vertices->push_back(v4);
    vertices->push_back(v11);
    vertices->push_back(v12);
    vertices->push_back(v13);

    // Left part left int
    vertices->push_back(v8);
    vertices->push_back(v9);
    vertices->push_back(v12);
    vertices->push_back(v13);

    // Right part back
    vertices->push_back(v6);
    vertices->push_back(v14);
    vertices->push_back(v15);
    vertices->push_back(v16);

    // Left part left ext
    vertices->push_back(v5);
    vertices->push_back(v6);
    vertices->push_back(v16);
    vertices->push_back(v17);

    // Left part front
    vertices->push_back(v5);
    vertices->push_back(v17);
    vertices->push_back(v18);
    vertices->push_back(v19);

    // Left part left int
    vertices->push_back(v14);
    vertices->push_back(v15);
    vertices->push_back(v18);
    vertices->push_back(v19);

    // Bottom front
    vertices->push_back(v20);
    vertices->push_back(v21);
    vertices->push_back(v25);
    vertices->push_back(v24);

    // Bottom right
    vertices->push_back(v21);
    vertices->push_back(v22);
    vertices->push_back(v26);
    vertices->push_back(v25);

    // Bottom back
    vertices->push_back(v22);
    vertices->push_back(v23);
    vertices->push_back(v27);
    vertices->push_back(v26);

    // Bottom left
    vertices->push_back(v23);
    vertices->push_back(v20);
    vertices->push_back(v24);
    vertices->push_back(v27);

    // Create tile geometry
    osg::ref_ptr<osg::Geometry> clampGeometry = new osg::Geometry;
    
    // Match vertices
    clampGeometry->setVertexArray(vertices);
    
    // Create colors
    osg::Vec4 osgColor(static_cast<float>(color.red())/255.0, static_cast<float>(color.green())/255.0, static_cast<float>(color.blue())/255.0, 1.0);
    osg::ref_ptr<osg::Vec4Array> colors = new osg::Vec4Array;
    // Every face has the same color, so there is only one color
    colors->push_back(osgColor);
    
    // Match color
    clampGeometry->setColorArray(colors);
    clampGeometry->setColorBinding(osg::Geometry::BIND_OVERALL);
    
    // Create normals
    osg::ref_ptr<osg::Vec3Array> normals = new osg::Vec3Array;
    normals->push_back(osg::Vec3(0, 0, -1));
    normals->push_back(osg::Vec3(0, 0, -1));
    normals->push_back(osg::Vec3(0, 1, 0));
    normals->push_back(osg::Vec3(0, -1, 0));
    normals->push_back(osg::Vec3(-1, 0, 0));
    normals->push_back(osg::Vec3(1, 0, 0));
    normals->push_back(osg::Vec3(0, 0, 1));
    normals->push_back(osg::Vec3(0, -1, 0));
    normals->push_back(osg::Vec3(-1, 0, 0));
    double w = pw - mwp;
    double h = phmp - mhp;
    double norm = std::sqrt(w*w + h*h);
    normals->push_back(osg::Vec3(0, h/norm, w/norm));
    normals->push_back(osg::Vec3(1, 0, 0));
    normals->push_back(osg::Vec3(0, -1, 0));
    normals->push_back(osg::Vec3(1, 0, 0));
    normals->push_back(osg::Vec3(0, h/norm, w/norm));
    normals->push_back(osg::Vec3(-1, 0, 0));
    normals->push_back(osg::Vec3(0, 1, 0));
    normals->push_back(osg::Vec3(-1, 0, 0));
    normals->push_back(osg::Vec3(0, -1, 0));
    normals->push_back(osg::Vec3(1, 0, 0));
    
    // Match normals
    clampGeometry->setNormalArray(normals);
    clampGeometry->setNormalBinding(osg::Geometry::BIND_PER_PRIMITIVE);

    // Define 1 GL_QUADS with 1*4 vertices, corresponding to bottom part
    clampGeometry->addPrimitiveSet(new osg::DrawArrays(osg::PrimitiveSet::QUADS, 0*4, 4));

    // Define 1 GL_QUADS with 1*4 vertices, corresponding to 1 hole in bottom part
    clampGeometry->addPrimitiveSet(new osg::DrawArrays(osg::PrimitiveSet::QUADS, 1*4, 4));

    // Retesslate to create hole
    osgUtil::Tessellator tesslator;
    tesslator.setTessellationType(osgUtil::Tessellator::TESS_TYPE_GEOMETRY);
    tesslator.setWindingType(osgUtil::Tessellator::TESS_WINDING_ODD);
    tesslator.retessellatePolygons(*clampGeometry);

    // Create 17 GL_QUADS, i.e. 18*4 vertices
    clampGeometry->addPrimitiveSet(new osg::DrawArrays(osg::PrimitiveSet::QUADS, 2*4, 18*4));

    // Return the tile whithout plot
    return clampGeometry.release();
}
Пример #17
0
static const unsigned *
brw_cs_emit(struct brw_context *brw,
            void *mem_ctx,
            const struct brw_cs_prog_key *key,
            struct brw_cs_prog_data *prog_data,
            struct gl_compute_program *cp,
            struct gl_shader_program *prog,
            unsigned *final_assembly_size)
{
   bool start_busy = false;
   double start_time = 0;

   if (unlikely(brw->perf_debug)) {
      start_busy = (brw->batch.last_bo &&
                    drm_intel_bo_busy(brw->batch.last_bo));
      start_time = get_time();
   }

   struct brw_shader *shader =
      (struct brw_shader *) prog->_LinkedShaders[MESA_SHADER_COMPUTE];

   if (unlikely(INTEL_DEBUG & DEBUG_CS))
      brw_dump_ir("compute", prog, &shader->base, &cp->Base);

   prog_data->local_size[0] = cp->LocalSize[0];
   prog_data->local_size[1] = cp->LocalSize[1];
   prog_data->local_size[2] = cp->LocalSize[2];
   unsigned local_workgroup_size =
      cp->LocalSize[0] * cp->LocalSize[1] * cp->LocalSize[2];

   cfg_t *cfg = NULL;
   const char *fail_msg = NULL;

   int st_index = -1;
   if (INTEL_DEBUG & DEBUG_SHADER_TIME)
      st_index = brw_get_shader_time_index(brw, prog, &cp->Base, ST_CS);

   /* Now the main event: Visit the shader IR and generate our CS IR for it.
    */
   fs_visitor v8(brw->intelScreen->compiler, brw,
                 mem_ctx, MESA_SHADER_COMPUTE, key, &prog_data->base, prog,
                 &cp->Base, 8, st_index);
   if (!v8.run_cs()) {
      fail_msg = v8.fail_msg;
   } else if (local_workgroup_size <= 8 * brw->max_cs_threads) {
      cfg = v8.cfg;
      prog_data->simd_size = 8;
   }

   fs_visitor v16(brw->intelScreen->compiler, brw,
                  mem_ctx, MESA_SHADER_COMPUTE, key, &prog_data->base, prog,
                  &cp->Base, 16, st_index);
   if (likely(!(INTEL_DEBUG & DEBUG_NO16)) &&
       !fail_msg && !v8.simd16_unsupported &&
       local_workgroup_size <= 16 * brw->max_cs_threads) {
      /* Try a SIMD16 compile */
      v16.import_uniforms(&v8);
      if (!v16.run_cs()) {
         perf_debug("SIMD16 shader failed to compile: %s", v16.fail_msg);
         if (!cfg) {
            fail_msg =
               "Couldn't generate SIMD16 program and not "
               "enough threads for SIMD8";
         }
      } else {
         cfg = v16.cfg;
         prog_data->simd_size = 16;
      }
   }

   if (unlikely(cfg == NULL)) {
      assert(fail_msg);
      prog->LinkStatus = false;
      ralloc_strcat(&prog->InfoLog, fail_msg);
      _mesa_problem(NULL, "Failed to compile compute shader: %s\n",
                    fail_msg);
      return NULL;
   }

   fs_generator g(brw->intelScreen->compiler, brw,
                  mem_ctx, (void*) key, &prog_data->base, &cp->Base,
                  v8.promoted_constants, v8.runtime_check_aads_emit, "CS");
   if (INTEL_DEBUG & DEBUG_CS) {
      char *name = ralloc_asprintf(mem_ctx, "%s compute shader %d",
                                   prog->Label ? prog->Label : "unnamed",
                                   prog->Name);
      g.enable_debug(name);
   }

   g.generate_code(cfg, prog_data->simd_size);

   if (unlikely(brw->perf_debug) && shader) {
      if (shader->compiled_once) {
         _mesa_problem(&brw->ctx, "CS programs shouldn't need recompiles");
      }
      shader->compiled_once = true;

      if (start_busy && !drm_intel_bo_busy(brw->batch.last_bo)) {
         perf_debug("CS compile took %.03f ms and stalled the GPU\n",
                    (get_time() - start_time) * 1000);
      }
   }

   return g.get_assembly(final_assembly_size);
}
Пример #18
0
void test_n_voronoi(void)
{
    std::vector<Vector> pos;
    real L = 32;

    Vector a, b, c, d;
    a.x = 1.; a.y = 2.;
    b.x = 2.; b.y = 2.;
    c.x = 2.; c.y = 0.;
    d.x = 4.; d.y = 4.;

    pos = {a, b, c, d};

    MATRIX n(4, 4);
    n.Zero();
    calculate_n_voronoi(n, pos, L);

    MATRIX m(4, 4);
    /*
    0 1 1 1
    1 0 1 1
    1 1 0 1
    1 1 1 0
    */
    m.Set(0, 0, 0); m.Set(0, 1, 1); m.Set(0, 2, 1); m.Set(0, 3, 1);
    m.Set(1, 0, 1); m.Set(1, 1, 0); m.Set(1, 2, 1); m.Set(1, 3, 1);
    m.Set(2, 0, 1); m.Set(2, 1, 1); m.Set(2, 2, 0); m.Set(2, 3, 1);
    m.Set(3, 0, 1); m.Set(3, 1, 1); m.Set(3, 2, 1); m.Set(3, 3, 0);

    assert(n == m);

    /*9 particles Voronoi*/

    MATRIX n2(9, 9);
    n2.Zero();

    Vector v1(10,30), v2(20,30), v3(30,30), v4(10,20), v5(20,20), v6(30,20), v7(10,10), v8(20,10), v9(30,10);
    pos = {v1, v2, v3, v4, v5, v6, v7, v8, v9};
    calculate_n_voronoi(n2, pos, L);

    MATRIX m2(9, 9);
    /*
    0 1 1 1 0 0 1 0 0
    1 0 1 0 1 0 0 1 0
    1 1 0 0 0 1 0 0 1
    1 0 0 0 1 1 1 0 0
    0 1 0 1 0 1 0 1 0
    0 0 1 1 1 0 0 0 1
    1 0 0 1 0 0 0 1 1
    0 1 0 0 1 0 1 0 1
    0 0 1 0 0 1 1 1 0
    */
    m2.Set(0, 0, 0);m2.Set(0, 1, 1);m2.Set(0, 2, 1);m2.Set(0, 3, 1);m2.Set(0, 4, 0);m2.Set(0, 5, 0);m2.Set(0, 6, 1);m2.Set(0, 7, 0);m2.Set(0, 8, 0);
    m2.Set(1, 0, 1);m2.Set(1, 1, 0);m2.Set(1, 2, 1);m2.Set(1, 3, 0);m2.Set(1, 4, 1);m2.Set(1, 5, 0);m2.Set(1, 6, 0);m2.Set(1, 7, 1);m2.Set(1, 8, 0);
    m2.Set(2, 0, 1);m2.Set(2, 1, 1);m2.Set(2, 2, 0);m2.Set(2, 3, 0);m2.Set(2, 4, 0);m2.Set(2, 5, 1);m2.Set(2, 6, 0);m2.Set(2, 7, 0);m2.Set(2, 8, 1);
    m2.Set(3, 0, 1);m2.Set(3, 1, 0);m2.Set(3, 2, 0);m2.Set(3, 3, 0);m2.Set(3, 4, 1);m2.Set(3, 5, 1);m2.Set(3, 6, 1);m2.Set(3, 7, 0);m2.Set(3, 8, 0);
    m2.Set(4, 0, 0);m2.Set(4, 1, 1);m2.Set(4, 2, 0);m2.Set(4, 3, 1);m2.Set(4, 4, 0);m2.Set(4, 5, 1);m2.Set(4, 6, 0);m2.Set(4, 7, 1);m2.Set(4, 8, 0);
    m2.Set(5, 0, 0);m2.Set(5, 1, 0);m2.Set(5, 2, 1);m2.Set(5, 3, 1);m2.Set(5, 4, 1);m2.Set(5, 5, 0);m2.Set(5, 6, 0);m2.Set(5, 7, 0);m2.Set(5, 8, 1);
    m2.Set(6, 0, 1);m2.Set(6, 1, 0);m2.Set(6, 2, 0);m2.Set(6, 3, 1);m2.Set(6, 4, 0);m2.Set(6, 5, 0);m2.Set(6, 6, 0);m2.Set(6, 7, 1);m2.Set(6, 8, 1);
    m2.Set(7, 0, 0);m2.Set(7, 1, 1);m2.Set(7, 2, 0);m2.Set(7, 3, 0);m2.Set(7, 4, 1);m2.Set(7, 5, 0);m2.Set(7, 6, 1);m2.Set(7, 7, 0);m2.Set(7, 8, 1);
    m2.Set(8, 0, 0);m2.Set(8, 1, 0);m2.Set(8, 2, 1);m2.Set(8, 3, 0);m2.Set(8, 4, 0);m2.Set(8, 5, 1);m2.Set(8, 6, 1);m2.Set(8, 7, 1);m2.Set(8, 8, 0);
    assert(n2 == m2);
}
Пример #19
0
int main(int argc, char **argv)
{
	OpenMeshExtended mesh;

	typedef typename mesh_traits<OpenMeshExtended>::vertex_descriptor vd;

	//MyMesh mesh;

	OpenMeshXTraits::vertex_descriptor vhandle[8];

	vhandle[0] = mesh.add_vertex(OpenMeshExtended::Point(-1, -1,  1));
	vhandle[1] = mesh.add_vertex(OpenMeshExtended::Point( 1, -1,  1));
	vhandle[2] = mesh.add_vertex(OpenMeshExtended::Point( 1,  1,  1));
	vhandle[3] = mesh.add_vertex(OpenMeshExtended::Point(-1,  1,  1));
	vhandle[4] = mesh.add_vertex(OpenMeshExtended::Point(-1, -1, -1));
	vhandle[5] = mesh.add_vertex(OpenMeshExtended::Point( 1, -1, -1));
	vhandle[6] = mesh.add_vertex(OpenMeshExtended::Point( 1,  1, -1));
	vhandle[7] = mesh.add_vertex(OpenMeshExtended::Point(-1,  1, -1));


/*  testujem iteratory */

auto test_vv_iter_pair = OpenMeshXTraits::get_adjacent_vertices(mesh, vhandle[0]);
std::cout << "pre izolovany vrchol vyhodi rovny iterator:" << (test_vv_iter_pair.first == test_vv_iter_pair.second) << " great!" << std::endl;

/*# testujem iteratory*/



	std::vector<OpenMeshXTraits::vertex_descriptor>  face_vhandles;

	face_vhandles.clear();
	face_vhandles.push_back(vhandle[0]);
	face_vhandles.push_back(vhandle[1]);
	face_vhandles.push_back(vhandle[2]);
	face_vhandles.push_back(vhandle[3]);


	
	
	/*0 0 1*/
/*	
	face_vhandles.clear();
	face_vhandles.push_back(vhandle[3]);
	face_vhandles.push_back(vhandle[2]);
	face_vhandles.push_back(vhandle[1]);
	face_vhandles.push_back(vhandle[0]);
*/
	/*0 0 -1*/
	OpenMesh::PolyMesh_ArrayKernelT<>::FaceHandle omx_face = mesh.add_face(face_vhandles);
	
	OpenMeshExtended::Normal normal = mesh.calc_face_normal(omx_face);
	std::cout << "normala:" << normal << std::endl;

	flip_normals<OpenMeshExtended, advanced_mesh_traits<OpenMeshExtended>>(mesh);	


	auto old_face_pair = mesh_traits<OpenMeshExtended>::get_all_faces(mesh);
	for (auto i = old_face_pair.first; i != old_face_pair.second; ++i)
	{
		auto old_face = *i;
		OpenMeshExtended::Normal n = mesh.calc_face_normal(old_face);
		std::cout << "norm:" << n << std::endl;
	} 

	triangulate<OpenMeshExtended, advanced_mesh_traits<OpenMeshExtended>>(mesh);
	
	std::cout << "pocet je " << compute_components<OpenMeshExtended, OpenMeshXTraits>(mesh) << std::endl;


	OpenMeshXTraits::face_descriptor fh = *mesh.faces_begin();


	for ( auto fvi = mesh.fv_begin(fh); fvi < mesh.fv_end(fh); ++fvi) {
		std::cout << "h" << std::endl;
	}

	for (auto e_it = mesh.edges_begin(); e_it != mesh.edges_end(); ++e_it)
	{
		std::cout << "joe" << e_it->idx() << std::endl;
	}

	boost::adjacency_matrix<boost::directedS> a(N);
	add_edge(A, B, a);

	my_mesh G;

	my_mesh::vertex v1(1);
	my_mesh::vertex v2(2);
	my_mesh::vertex v3(3);
	my_mesh::vertex v4(4);
	my_mesh::vertex v5(5);
	my_mesh::vertex v6(6);
	my_mesh::vertex v7(7);
	my_mesh::vertex v8(8);

/* 2 testujem iteratory */

auto test_vv_iter_pair2 = my_mesh_traits::get_adjacent_vertices(G, &v1);
std::cout << "2: pre izolovany vrchol vyhodi rovny iterator:" << (test_vv_iter_pair2.first == test_vv_iter_pair2.second) << " great!" << std::endl;

/*# 2 testujem iteratory*/




	my_mesh_traits::add_vertex(&v1, &G);
	my_mesh_traits::add_vertex(&v2, &G);
	my_mesh_traits::add_vertex(&v3, &G);
	my_mesh_traits::add_vertex(&v4, &G);
	my_mesh_traits::add_vertex(&v5, &G);
	my_mesh_traits::add_vertex(&v6, &G);
	my_mesh_traits::add_vertex(&v7, &G);
	my_mesh_traits::add_vertex(&v8, &G);

	my_mesh_traits::create_face(&v1, &v2, &v3, &G);
	my_mesh_traits::create_face(&v2, &v3, &v4, &G);
	my_mesh_traits::create_face(&v6, &v7, &v8, &G);

	std::cout << std::endl;

	auto my_pair = my_mesh_traits::get_all_vertices(G);
	for (auto i = my_pair.first; i != my_pair.second; ++i) {
		std::cout << (*i)->get_id() << ", ";
	}
	std::cout << std::endl;

	auto my_pair_edges = my_mesh_traits::get_all_edges(G);
	for (auto i = my_pair_edges.first; i != my_pair_edges.second; ++i) {
		std::cout << ((*i)->getVertices().first ? (*i)->getVertices().first->get_id() : 0) << "-" ;
		std::cout << ((*i)->getVertices().second ? (*i)->getVertices().second->get_id() : 0) << ",";
	}
	std::cout << std::endl;


	std::cout << G.isTriangle() << std::endl;
	std::cout << "joe more!!!!";

	auto my_pair_vv = v1.get_adjacent_vertices();// get_adjacent_vertices(G, &v1);
	for (auto i = my_pair_vv.first; i != my_pair_vv.second; ++i) {
		std::cout << (*i)->get_id() << ",";
	}
	std::cout << std::endl;

	std::cout << "pocet je: " << compute_components<my_mesh, my_mesh_traits>(G) << std::endl;

	std::cout << "norma: c++0x" << std::endl;


	//M4D::Imaging::AImage::Ptr image = M4D::Imaging::ImageFactory::LoadDumpedImage( path );

	return 0;
}
Пример #20
0
int testVector() {
	int numErr = 0;

	logMessage(_T("TESTING  -  class GM_3dVector ...\n\n"));

	// Default constructor, vector must be invalid
	GM_3dVector v;
	if (v.isValid()) {
		logMessage(_T("\tERROR - Default constructor creates valid vector\n"));
		numErr++;
	}
	else {
		logMessage(_T("\tOK - Default constructor creates invalid vector\n"));
	}

	// Get/Set vector coordinates
	double x = getRandomDouble();
	double y = getRandomDouble();
	double z = getRandomDouble();
	v.x(x); v.y(y); v.z(z);
	if (!v.isValid() || v.x() != x || v.y() != y || v.z() != z) {
		logMessage(_T("\tERROR - Get/Set not working\n"));
		numErr++;
	}
	else {
		logMessage(_T("\tOK - Get/Set working\n"));
	}

	// Copy constructor
	GM_3dVector v1(v);
	if (v.isValid() != v1.isValid() || v1.x() != v.x() || v1.y() != v.y() || v1.z() != v.z()) {
		logMessage(_T("\tERROR - Copy constructor not working\n"));
		numErr++;
	}
	else {
		logMessage(_T("\tOK - Copy constructor working\n"));
	}

	// Constructor (point)
	GM_3dPoint pt(getRandomDouble(), getRandomDouble(), getRandomDouble());
	GM_3dVector v2(pt);
	if (!v2.isValid() || v2.x() != pt.x() || v2.y() != pt.y() || v2.z() != pt.z()) {
		logMessage(_T("\tERROR - Constructor from point not working\n"));
		numErr++;
	}
	else {
		logMessage(_T("\tOK - Constructor from point working\n"));
	}

	// Constructor (line)
	GM_3dLine line(getRandomDouble(), getRandomDouble(), getRandomDouble(), getRandomDouble(), getRandomDouble(), getRandomDouble());
	GM_3dVector v3(line);
	if (!v3.isValid() || v3.x() != line.end().x() - line.begin().x() || v3.y() != line.end().y() - line.begin().y() || v3.z() != line.end().z() - line.begin().z()) {
		logMessage(_T("\tERROR - Constructor from line not working\n"));
		numErr++;
	}
	else {
		logMessage(_T("\tOK - Constructor from line working\n"));
	}

	// Constructor (angle)
	double ang = getRandomAngle();
	GM_3dVector v4(ang);
	if (!v4.isValid() || v4.x() != cos(ang) || v4.y() != sin(ang) || v4.z() != 0.0) {
		logMessage(_T("\tERROR - XY angle constructor not working\n"));
		numErr++;
	}
	else {
		logMessage(_T("\tOK - XY angle constructor working\n"));
	}

	// Module
	double module = v.mod();
	if (module != sqrt(v.x()*v.x() + v.y()*v.y() + v.z()*v.z())) {
		logMessage(_T("\tERROR - Module computation not working\n"));
		numErr++;
	}
	else {
		logMessage(_T("\tOK - Module computation working\n"));
	}

	// Normalization
	v.normalize();
	if (fabs(v.mod()-1.0) > GM_NULL_TOLERANCE) {
		logMessage(_T("\tERROR - Normalization not working\n"));
		numErr++;
	}
	else {
		logMessage(_T("\tOK - Normalization working\n"));
	}

	// xy Angle
	double checkAng = v4.xyAngle();
	if (checkAng > GM_PI) {
		checkAng -= 2.0 * GM_PI;
	}
	if (fabs(checkAng - ang) > GM_NULL_TOLERANCE) {
		logMessage(_T("\tERROR - xy angle computation not working\n"));
		numErr++;
	}
	else {
		logMessage(_T("\tOK - xy angle computation working\n"));
	}

	// Angle between vectors
	ang = getRandomAngle();
	GM_3dVector v5(ang);
	GM_3dVector baseVect(0.0);
	checkAng = baseVect.xyAngle(v5);
	if (checkAng > GM_PI) {
		checkAng -= 2.0 * GM_PI;
	}
	double checkAng1 = v5.xyAngle(baseVect);
	if (checkAng1 > GM_PI) {
		checkAng1 -= 2.0 * GM_PI;
	}
	if (fabs(checkAng - ang) > GM_NULL_TOLERANCE || fabs(-checkAng1 - ang) > GM_NULL_TOLERANCE) {
		logMessage(_T("\tERROR - Angle between vectors computation not working\n"));
		numErr++;
	}
	else {
		logMessage(_T("\tOK - Angle between vectors computation working\n"));
	}

	// At left
	ang = getRandomAngle();
	if (ang < 0.0) {
		ang = 2.0 * GM_PI + ang;
	}
	double ang1 = getRandomAngle();
	if (ang1 < 0.0) {
		ang1 = 2.0 * GM_PI + ang1;
	}
	GM_3dVector v6(ang);
	GM_3dVector v7(ang1);
	bool v6AtLeftv7 = v6.isAtLeftOnXY(v7);
	bool v7AtLeftv6 = v7.isAtLeftOnXY(v6);
	double checkv6Ang = v6.xyAngle();
	double checkv7Ang = v7.xyAngle();
	bool checkv6AtLeftv7 = ang > ang1 ? true : false;
	if (fabs(ang - checkv6Ang) > GM_NULL_TOLERANCE || fabs(ang1 - checkv7Ang) > GM_NULL_TOLERANCE || checkv6AtLeftv7 != v6AtLeftv7 || v6AtLeftv7 == v7AtLeftv6) {
		logMessage(_T("\tERROR - At left not working\n"));
		numErr++;
	}
	else {
		logMessage(_T("\tOK - At left working\n"));
	}

	// Dot product
	GM_3dVector v8(getRandomDouble(), getRandomDouble(), getRandomDouble());
	GM_3dVector v9(getRandomDouble(), getRandomDouble(), getRandomDouble());
	double dotProd = v8 * v9;
	double dotProd1 = v9 * v8;
	double checkDotProd = v8.x()*v9.x() + v8.y()*v9.y() + v8.z()*v9.z();
	if (dotProd != checkDotProd || dotProd1 != checkDotProd) {
		logMessage(_T("\tERROR - Dot product not working\n"));
		numErr++;
	}
	else {
		logMessage(_T("\tOK - Dot product working\n"));
	}

	// Cross product
	GM_3dVector crossProd = v8 ^ v9;
	GM_3dVector crossProd1 = v9 ^ v8;
	double checkCrossProdX = v8.y()*v9.z() - v8.z()*v9.y();
	double checkCrossProdY = v8.z()*v9.x() - v8.x()*v9.z();
	double checkCrossProdZ = v8.x()*v9.y() - v8.y()*v9.x();
	if (crossProd.x() != checkCrossProdX || crossProd.y() != checkCrossProdY || crossProd.z() != checkCrossProdZ ||
		crossProd1.x() != -checkCrossProdX || crossProd1.y() != -checkCrossProdY || crossProd1.z() != -checkCrossProdZ) {
		logMessage(_T("\tERROR - Cross product not working\n"));
		numErr++;
	}
	else {
		logMessage(_T("\tOK - Cross product working\n"));
	}

	// Scale
	double factor = getRandomDouble();
	GM_3dVector v8Scaled = v8 * factor;
	if (v8Scaled.x() != v8.x()*factor || v8Scaled.y() != v8.y()*factor || v8Scaled.z() != v8.z()*factor) {
		logMessage(_T("\tERROR - Scaling not working\n"));
		numErr++;
	}
	else {
		logMessage(_T("\tOK - Scaling working\n"));
	}

	// Sum
	GM_3dVector sum = v8 + v9;
	if (sum.x() != v8.x()+v9.x() || sum.y() != v8.y()+v9.y() || sum.z() != v8.z()+v9.z()) {
		logMessage(_T("\tERROR - Sum not working\n"));
		numErr++;
	}
	else {
		logMessage(_T("\tOK - Sum working\n"));
	}

	// Difference
	GM_3dVector diff = v8 - v9;
	if (diff.x() != v8.x()-v9.x() || diff.y() != v8.y()-v9.y() || diff.z() != v8.z()-v9.z()) {
		logMessage(_T("\tERROR - Difference not working\n"));
		numErr++;
	}
	else {
		logMessage(_T("\tOK - Difference working\n"));
	}

	return numErr;
}