Beispiel #1
0
/* @bug 4109023
 * Need to override ParsePosition.equals and FieldPosition.equals.
 */
void ParsePositionTest::Test4109023()
{
    ParsePosition p(3);
    ParsePosition p2(3);
    if (p != p2)
        errln("Error : ParsePosition.equals() failed");
    FieldPosition fp(2);
    FieldPosition fp2(2);
    if (fp != fp2)
        errln("Error : FieldPosition.equals() failed");
}
Beispiel #2
0
sk_sp<GrFragmentProcessor> SkColorFilterShader::asFragmentProcessor(const AsFPArgs& args) const {

    sk_sp<GrFragmentProcessor> fp1(fShader->asFragmentProcessor(args));
    if (!fp1) {
        return nullptr;
    }

    sk_sp<GrFragmentProcessor> fp2(fFilter->asFragmentProcessor(args.fContext));
    if (!fp2) {
        return fp1;
    }

    sk_sp<GrFragmentProcessor> fpSeries[] = { std::move(fp1), std::move(fp2) };
    return GrFragmentProcessor::RunInSeries(fpSeries, 2);
}
void KisFixedPointMathsTest::testOperatorsNegative()
{
    KisFixedPoint fp1(qreal(-2.5));
    KisFixedPoint fp2(2);
    KisFixedPoint fp3(-3);

    QCOMPARE(fp1 + fp2, KisFixedPoint(qreal(-0.5)));
    QCOMPARE(fp1 - fp2, KisFixedPoint(qreal(-4.5)));
    QCOMPARE(fp1 * fp2, KisFixedPoint(-5));
    QCOMPARE(fp1 * fp3, KisFixedPoint(qreal(7.5)));

    QCOMPARE(fp2 / fp1, KisFixedPoint(qreal(-0.8)));
    QCOMPARE(fp1 / fp2, KisFixedPoint(qreal(-1.25)));
    QCOMPARE(fp3 / fp1, KisFixedPoint(qreal(1.2)));
}
Beispiel #4
0
void move_file(std::string const& old, std::string const& new_)
{
    {
        std::ifstream fp1(new_.c_str());
        if(!fp1)
            throw std::runtime_error( "couldn't open file '" + new_ + "' for reading" );
    
        std::ifstream fp2(old.c_str());
        if(fp2 && equal_streams(fp1, fp2))
            return;
    }

    fs::create_directories(fs::parent_path(old));
    fs::rename(new_.c_str(), old.c_str());
}
Beispiel #5
0
int test() {
  {
    int& (*fpi)(int*) = [](auto* a) -> auto& { return *a; }; // OK
    int (*fp2)(int) = [](auto b) -> int {  return b; };
    int (*fp3)(char) = [](auto c) -> int { return c; };
    char (*fp4)(int) = [](auto d) { return d; }; //expected-error{{no viable conversion}}\
                                                 //expected-note{{candidate template ignored}}
    char (*fp5)(char) = [](auto e) -> int { return e; }; //expected-error{{no viable conversion}}\
                                                 //expected-note{{candidate template ignored}}

    fp2(3);
    fp3('\n');
    fp3('a');
    return 0;
  }
} // end test()
Beispiel #6
0
template<class ... Ts> int fooV(Ts ... ts) {
  auto L = [](auto ... a) { 
    auto M = [](decltype(a) ... b) -> void {  
      auto N = [](auto c) -> void {
        int x = 0;
        x = sizeof...(a);        
        x = sizeof...(b);
        x = sizeof(c);
      };  
      N('a');
      N(N);
      N(FirstType<Ts...>{});
    };
    M(a...);
    return M;
  };
  auto M = L(L, ts...);
  decltype(L(L, ts...)) (*fp)(decltype(L), decltype(ts) ...) = L;
  void (*fp2)(decltype(L), decltype(ts) ...) = L(L, ts...);
  
  {
    auto L = [](auto ... a) { 
      auto M = [](decltype(a) ... b) {  
        auto N = [](auto c) -> void {
          int x = 0;
          x = sizeof...(a);        
          x = sizeof...(b);
          x = sizeof(c);
        };  
        N('a');
        N(N);
        N(FirstType<Ts...>{});
        return N;
      };
      M(a...);
      return M;
    };
    auto M = L(L, ts...);
    decltype(L(L, ts...)) (*fp)(decltype(L), decltype(ts) ...) = L;
    fp(L, ts...);
    decltype(L(L, ts...)(L, ts...)) (*fp2)(decltype(L), decltype(ts) ...) = L(L, ts...);
    fp2 = fp(L, ts...);
    void (*fp3)(char) = fp2(L, ts...);
    fp3('a');
  }
  return 0;
}
Beispiel #7
0
static void test_standalone_funcs() {
    printf("\r\n********** Starting test_standalone_funcs **********\r\n");
    const char *testmsg1 = "Test message 1";
    const char *testmsg2 = "Test message 2";
    const int testint1 = 13;
    const double testdouble = 100.0;

    // First call function pointers directly
    FunctionPointer1<void, const char*> fp1(sa_func_1);
    FunctionPointer1<void, int> fp2(sa_func_2);
    FunctionPointer0<void> fp3(sa_func_3);
    FunctionPointer3<void, int, const char*, double> fp4(sa_func_4);
    call_fp1("ptr to standalone func(char*)", fp1, testmsg1);
    call_fp1("ptr to standalone func(char*)", fp1, testmsg2);
    call_fp1("ptr to standalone func(int)", fp2, testint1);
    call_fp0("ptr to standalone func(void)", fp3);
    call_fp3("ptr to standalong func(int, const char*, double)", fp4, testint1, testmsg1, testdouble);
}
Beispiel #8
0
    void TestConstructor(void)
    {
        SCXCoreLib::SCXFilePath fp1;
        SCXCoreLib::SCXFilePath fp2(L"/some/path");
        std::wstring sp = L"C:\\some/other\\path/";
        SCXCoreLib::SCXFilePath fp3(sp);
        SCXCoreLib::SCXFilePath fp4(fp2);
        // Check that constructors create a path as expected.
        CPPUNIT_ASSERT(fp1.Get().compare(L"") == 0);
#if defined(WIN32)
        CPPUNIT_ASSERT(fp2.Get() == L"\\some\\path");
        CPPUNIT_ASSERT(fp3.Get() == L"C:\\some\\other\\path\\");
#else
        CPPUNIT_ASSERT(fp2.Get() == L"/some/path");
        CPPUNIT_ASSERT(fp3.Get() == L"C:/some/other/path/");
#endif
        // Check that copy constructor creates identical content.
        CPPUNIT_ASSERT(fp2.Get() == fp4.Get());
    }
Beispiel #9
0
int
main (void)
{
  void *h1;
  int (*fp1) (int);
  void *h2;
  int (*fp2) (int);
  int res1;
  int res2;

  mtrace ();

  h1 = dlopen ("testobj1.so", RTLD_LAZY);
  if (h1 == NULL)
    error (EXIT_FAILURE, 0, "while loading `%s': %s", "testobj1.so",
	   dlerror ());

  h2 = dlopen ("testobj1_1.so", RTLD_LAZY);
  if (h1 == NULL)
    error (EXIT_FAILURE, 0, "while loading `%s': %s", "testobj1_1.so",
	   dlerror ());

  fp1 = dlsym (h1, "obj1func1");
  if (fp1 == NULL)
    error (EXIT_FAILURE, 0, "getting `obj1func1' in `%s': %s",
	   "testobj1.so", dlerror ());

  fp2 = dlsym (h2, "obj1func1");
  if (fp2 == NULL)
    error (EXIT_FAILURE, 0, "getting `obj1func1' in `%s': %s",
	   "testobj1_1.so", dlerror ());

  res1 = fp1 (10);
  res2 = fp2 (10);
  printf ("fp1(10) = %d\nfp2(10) = %d\n", res1, res2);

  if (dlclose (h1) != 0)
    error (EXIT_FAILURE, 0, "cannot close testobj1.so: %s\n", dlerror ());
  if (dlclose (h2) != 0)
    error (EXIT_FAILURE, 0, "cannot close testobj1_1.so: %s\n", dlerror ());

  return res1 != 42 || res2 != 72;
}
Beispiel #10
0
static void test_array_of_events() {
    printf("\r\n********** Starting test_array_of_events **********\r\n");
    const char* testmsg1 = "Test message 1";
    const char* testmsg2 = "Test message 2";
    const int testint = 13;
    VDerived derived(20, 100);
    MyArg arg("array", 5, 10);

    FunctionPointer1<void, const char*> fp1((VBase*)&derived, &VBase::print_virtual_str);
    FunctionPointer0<void> fp2(sa_func_3);
    FunctionPointer1<void, int> fp3(sa_func_2);
    FunctionPointer0<void> fp4(&derived, &VDerived::print_virtual_noargs);
    FunctionPointer1<void, MyArg> fp5(sa_ntc);
    Event events[] = {fp1.bind(testmsg1), fp1.bind(testmsg2), fp2.bind(), fp3.bind(testint),
                      fp4.bind(), fp5.bind(arg)};

    for (unsigned i = 0; i < sizeof(events)/sizeof(events[0]); i ++) {
        events[i].call();
    }
}
Beispiel #11
0
static void test_funcs_nontca() {
    printf("\r\n********** Starting test_funcs_nontca **********\r\n");

    FunctionPointer1<void, MyArg> fp1(sa_ntc);
    Event e1, e2, e3;
    {
        // Test binding argument that gets out of scope at the end of this block
        MyArg arg("test", 10, 20);
        call_fp1("ptr to standalong func taking non-trivial arg", fp1, arg);
        e1 = e2 = e3 = fp1.bind(arg);
    }
    e1.call(); // This should work, since it has a copy of 'arg' above
    // Test functions taking non-trivial arguments inside classes
    ADerived d(10, 100);
    ABase *pDerived = &d;
    FunctionPointer1<void, MyArg> fp2(&d, &ADerived::print_virtual_arg);
    FunctionPointer1<void, MyArg> fp3(pDerived, &ABase::print_virtual_arg);
    call_fp1("ptr to virtual method taking non-tc argument", fp2, MyArg("notest", 5, 8));
    call_fp1("ptr to virtual method taking non-tc argument (via base class pointer)", fp2, MyArg("notest", 5, 8));
}
const GrFragmentProcessor* SkColorFilterShader::asFragmentProcessor(
                                                               GrContext* context,
                                                               const SkMatrix& viewM,
                                                               const SkMatrix* localMatrix,
                                                               SkFilterQuality fq) const {

    SkAutoTUnref<const GrFragmentProcessor> fp1(fShader->asFragmentProcessor(context, viewM,
                                                                             localMatrix, fq));
    if (!fp1.get()) {
        return nullptr;
    }

    SkAutoTUnref<const GrFragmentProcessor> fp2(fFilter->asFragmentProcessor(context));
    if (!fp2.get()) {
        return fp1.release();
    }

    const GrFragmentProcessor* fpSeries[] = { fp1.get(), fp2.get() };

    return GrFragmentProcessor::RunInSeries(fpSeries, 2);
}
void KisFixedPointMathsTest::testConversionsNegative()
{
    KisFixedPoint fp1(qreal(-2.5));
    KisFixedPoint fp2(qreal(-2.73));
    KisFixedPoint fp3(qreal(-2.34));

    QCOMPARE(fp1.toInt(), -2);
    QCOMPARE(fp1.toIntRound(), -3);
    QCOMPARE(fp1.toIntFloor(), -3);
    QCOMPARE(fp1.toIntCeil(), -2);

    QCOMPARE(fp2.toInt(), -2);
    QCOMPARE(fp2.toIntRound(), -3);
    QCOMPARE(fp2.toIntFloor(), -3);
    QCOMPARE(fp2.toIntCeil(), -2);

    QCOMPARE(fp3.toInt(), -2);
    QCOMPARE(fp3.toIntRound(), -2);
    QCOMPARE(fp3.toIntFloor(), -3);
    QCOMPARE(fp3.toIntCeil(), -2);
}
Beispiel #14
0
PyObject *_PY_fp2(PyObject *self, PyObject *args, PyObject *kwds)
   {int ok;
    PyObject *_lo;
    int _la1;
    char *_rv;
    char *kw_list[] = {"a1", NULL};

/* local variable initializations */
    _la1       = 0;

    ok = PyArg_ParseTupleAndKeywords(args, kwds,
                                     "i:fp2_p",
                                     kw_list,
                                     &_la1);
    if (ok == FALSE)
       return(NULL);

    _rv = fp2(_la1);
    _lo = PY_build_object("fp2",
                          G_STRING_I, 0, &_rv,
                          0);

    return(_lo);}
void KisFixedPointMathsTest::testConversions()
{
    KisFixedPoint fp1(qreal(2.5));
    KisFixedPoint fp2(qreal(2.73));
    KisFixedPoint fp3(qreal(2.34));

    QCOMPARE(fp1.toInt(), 2);
    QCOMPARE(fp1.toIntRound(), 3);
    QCOMPARE(fp1.toIntFloor(), 2);
    QCOMPARE(fp1.toIntCeil(), 3);
    QCOMPARE(fp1.toFloat(), qreal(2.5));

    QCOMPARE(fp2.toInt(), 2);
    QCOMPARE(fp2.toIntRound(), 3);
    QCOMPARE(fp2.toIntFloor(), 2);
    QCOMPARE(fp2.toIntCeil(), 3);
    QCOMPARE(fp2.toFloat(), qreal(698.0/256.0));

    QCOMPARE(fp3.toInt(), 2);
    QCOMPARE(fp3.toIntRound(), 2);
    QCOMPARE(fp3.toIntFloor(), 2);
    QCOMPARE(fp3.toIntCeil(), 3);
    QCOMPARE(fp3.toFloat(), qreal(599.0/256.0));
}
void KisFixedPointMathsTest::testOperators()
{
    KisFixedPoint fp1(1);
    KisFixedPoint fp2(2);
    KisFixedPoint fp3(qreal(2.5));
    KisFixedPoint fp4(qreal(2.0));

    QVERIFY(fp1 < fp2);
    QVERIFY(fp2 < fp3);

    QVERIFY(fp2 > fp1);
    QVERIFY(fp3 > fp2);

    QVERIFY(fp1 != fp2);
    QVERIFY(fp2 == fp4);

    QCOMPARE(fp1 + fp2, KisFixedPoint(3));
    QCOMPARE(fp1 - fp2, KisFixedPoint(-1));
    QCOMPARE(fp1 * fp2, KisFixedPoint(2));
    QCOMPARE(fp2 * fp3, KisFixedPoint(5));
    QCOMPARE(fp1 / fp2, KisFixedPoint(qreal(0.5)));
    QCOMPARE(fp1 / fp3, KisFixedPoint(qreal(0.4)));
    QCOMPARE(fp2 / fp3, KisFixedPoint(qreal(0.8)));
}
Beispiel #17
0
static int
do_test (void)
{
#ifdef USE_TLS
  static const char modname1[] = "tst-tlsmod3.so";
  static const char modname2[] = "tst-tlsmod4.so";
  int result = 0;
  int (*fp1) (void);
  int (*fp2) (int, int *);
  void *h1;
  void *h2;
  int i;
  size_t modid1 = (size_t) -1;
  size_t modid2 = (size_t) -1;
  int *bazp;

  for (i = 0; i < 10; ++i)
    {
      h1 = dlopen (modname1, RTLD_LAZY);
      if (h1 == NULL)
	{
	  printf ("cannot open '%s': %s\n", modname1, dlerror ());
	  exit (1);
	}

      /* Dirty test code here: we peek into a private data structure.
	 We make sure that the module gets assigned the same ID every
	 time.  The value of the first round is used.  */
#ifdef __UCLIBC__
      if (modid1 == (size_t) -1)
	modid1 = ((struct link_map *)((struct dyn_elf *)h1)->dyn)->l_tls_modid;
      else if (((struct link_map *)((struct dyn_elf *)h1)->dyn)->l_tls_modid
        != (size_t) modid1)
	{
	  printf ("round %d: modid now %zd, initially %zd\n",
		  i,
		  ((struct link_map *)((struct dyn_elf *)h1)->dyn)->l_tls_modid,
		  modid1);
	  result = 1;
	}
#else
      if (modid1 == (size_t) -1)
	modid1 = ((struct link_map *) h1)->l_tls_modid;
      else if (((struct link_map *) h1)->l_tls_modid != modid1)
	{
	  printf ("round %d: modid now %zd, initially %zd\n",
		  i, ((struct link_map *) h1)->l_tls_modid, modid1);
	  result = 1;
	}
#endif

      fp1 = dlsym (h1, "in_dso2");
      if (fp1 == NULL)
	{
	  printf ("cannot get symbol 'in_dso2' in %s\n", modname1);
	  exit (1);
	}

      result |= fp1 ();



      h2 = dlopen (modname2, RTLD_LAZY);
      if (h2 == NULL)
	{
	  printf ("cannot open '%s': %s\n", modname2, dlerror ());
	  exit (1);
	}

      /* Dirty test code here: we peek into a private data structure.
	 We make sure that the module gets assigned the same ID every
	 time.  The value of the first round is used.  */
#ifdef __UCLIBC__
      if (modid2 == (size_t) -1)
	modid2 = ((struct link_map *)((struct dyn_elf *)h1)->dyn)->l_tls_modid;
      else if (((struct link_map *)((struct dyn_elf *)h1)->dyn)->l_tls_modid
        != (size_t) modid2)
	{
	  printf ("round %d: modid now %zd, initially %zd\n",
		  i,
		  ((struct link_map *)((struct dyn_elf *)h1)->dyn)->l_tls_modid,
		  modid2);
	  result = 1;
	}
#else
      if (modid2 == (size_t) -1)
	modid2 = ((struct link_map *) h1)->l_tls_modid;
      else if (((struct link_map *) h1)->l_tls_modid != modid2)
	{
	  printf ("round %d: modid now %zd, initially %zd\n",
		  i, ((struct link_map *) h1)->l_tls_modid, modid2);
	  result = 1;
	}
#endif

      bazp = dlsym (h2, "baz");
      if (bazp == NULL)
	{
	  printf ("cannot get symbol 'baz' in %s\n", modname2);
	  exit (1);
	}

      *bazp = 42 + i;

      fp2 = dlsym (h2, "in_dso");
      if (fp2 == NULL)
	{
	  printf ("cannot get symbol 'in_dso' in %s\n", modname2);
	  exit (1);
	}

      result |= fp2 (42 + i, bazp);

      dlclose (h1);
      dlclose (h2);


      h1 = dlopen (modname1, RTLD_LAZY);
      if (h1 == NULL)
	{
	  printf ("cannot open '%s': %s\n", modname1, dlerror ());
	  exit (1);
	}

      /* Dirty test code here: we peek into a private data structure.
	 We make sure that the module gets assigned the same ID every
	 time.  The value of the first round is used.  */
#ifdef __UCLIBC__
      if (((struct link_map *)((struct dyn_elf *)h1)->dyn)->l_tls_modid
        != modid1)
	{
	  printf ("round %d: modid now %zd, initially %zd\n",
		  i,
		  ((struct link_map *)((struct dyn_elf *)h1)->dyn)->l_tls_modid,
		  modid1);
	  result = 1;
	}
#else
      if (((struct link_map *) h1)->l_tls_modid != modid1)
	{
	  printf ("round %d: modid now %zd, initially %zd\n",
		  i, ((struct link_map *) h1)->l_tls_modid, modid1);
	  result = 1;
	}
#endif

      fp1 = dlsym (h1, "in_dso2");
      if (fp1 == NULL)
	{
	  printf ("cannot get symbol 'in_dso2' in %s\n", modname1);
	  exit (1);
	}

      result |= fp1 ();



      h2 = dlopen (modname2, RTLD_LAZY);
      if (h2 == NULL)
	{
	  printf ("cannot open '%s': %s\n", modname2, dlerror ());
	  exit (1);
	}

      /* Dirty test code here: we peek into a private data structure.
	 We make sure that the module gets assigned the same ID every
	 time.  The value of the first round is used.  */
#ifdef __UCLIBC__
      if (((struct link_map *)((struct dyn_elf *)h1)->dyn)->l_tls_modid
        != modid2)
	{
	  printf ("round %d: modid now %zd, initially %zd\n",
		  i,
		  ((struct link_map *)((struct dyn_elf *)h1)->dyn)->l_tls_modid,
		  modid2);
	  result = 1;
	}
#else
      if (((struct link_map *) h1)->l_tls_modid != modid2)
	{
	  printf ("round %d: modid now %zd, initially %zd\n",
		  i, ((struct link_map *) h1)->l_tls_modid, modid2);
	  result = 1;
	}
#endif

      bazp = dlsym (h2, "baz");
      if (bazp == NULL)
	{
	  printf ("cannot get symbol 'baz' in %s\n", modname2);
	  exit (1);
	}

      *bazp = 62 + i;

      fp2 = dlsym (h2, "in_dso");
      if (fp2 == NULL)
	{
	  printf ("cannot get symbol 'in_dso' in %s\n", modname2);
	  exit (1);
	}

      result |= fp2 (62 + i, bazp);

      /* This time the dlclose calls are in reverse order.  */
      dlclose (h2);
      dlclose (h1);
    }

  return result;
#else
  return 0;
#endif
}
int main ()	{

	textmode (ATC_TEXT_MODE);
	clrscr();

	Position::MaxX = 30;
	Position::MaxY = 30;



	char pid;

	Position::MaxX = 30;
	Position::MaxY = 30;

	RadarScreen *r;
	Landmarks l;

	Traffic t;
	Plane *p1;
	Gate g (Position  (0,  10), 1, D90);
	Gate g1 (Position (0,  0),  2, D45);
	Gate g2 (Position (10, 0),  3, D0);
	Gate g3 (Position (MAX_X, MAX_Y), 4, D225);
//	Gate g4 (Position (10, 0), 4, D0);
	Airport a1 (Position (5, 5), 1, Heading (D90));
	Airport a2 (Position (10, 12), 2, Heading (D45));
	Beacon b1 (Position (7,13), 1);
	Beacon b2 (Position (1,1), 2);
	FlightPath fp (Position (MIN_FIELD_X, MIN_FIELD_Y),
		Position (MAX_FIELD_X, MAX_FIELD_Y));

	FlightPath fp1 (Position (MIN_FIELD_X, MAX_FIELD_Y),
		Position (MAX_FIELD_X, MIN_FIELD_Y));

	FlightPath fp2 (Position (10, 1), Position (10, MAX_FIELD_Y));

	int i;

	l.AddAirport (&a1);

	l.AddAirport (&a2);
	l.AddBeacon (&b1);
	l.AddBeacon (&b2);
	l.AddGate (&g);
	l.AddGate (&g1);
	l.AddGate (&g2);
	l.AddGate (&g3);
//	l.AddGate (&g4);
	l.AddFlightPath (&fp);
	l.AddFlightPath (&fp1);
	l.AddFlightPath (&fp2);

	r = new RadarScreen (&l);

	Boolean Crashed = False;

	r->Refresh();

	pid = t.NewId();

	p1 = new Plane (pid, g.NewPlaneCoords(), Prop, &g1);

	t.NewAirborne (p1);

	p1 = new Plane (t.NewId(), g1.NewPlaneCoords(), Jet, &g);

	t.NewAirborne (p1);


	p1 = new Plane (t.NewId(), g2.NewPlaneCoords(), Jet, &g);

	t.NewAirborne (p1);

	r->DisplayPlanes (&t);

	for (i = 0; i < 34; i++) {
		delay (500);


		if (i == 17)	{
			t.SearchAirborne ('a');
			t.FoundAirborne() -> AlterTargHeading (D270, AntiClockwise);

			t.SearchAirborne ('b');
			t.FoundAirborne() -> MakeCircle (AntiClockwise);
		}
		r->UnDisplayPlanes (&t);

		if (i % 2 == 0)	{
			t.StepJets();
		} else {
			t.StepAll();
		}

		r->DisplayPlanes (&t);

		if (!Crashed && t.Crashed ())	{
				cout << '\a';
			Crashed = True;
		}

	}

	textmode (C80);
	_setcursortype (_NORMALCURSOR);
	clrscr();

	return 0;
}
Beispiel #19
0
int main(int argc, char *argv[])
{
  try
  {
    edmplugin::PluginManager::configure(edmplugin::standard::config());
  }
  catch (cms::Exception& e)
  {
    edm::LogInfo("DDCompareCPV") << "Attempting to configure the plugin manager. Exception message: " << e.what();
    return 1;
  }
  
    // Process the command line arguments
    std::string descString("DDCompareCPV");
    descString += " [options] configurationFileName1 configurationFileName2 Compares two DDCompactViews\n";
    descString += "Allowed options";
    boost::program_options::options_description desc(descString);   
    desc.add_options()
      ("help,h", "Print this help message")
      ("file1,f", boost::program_options::value<std::string>(), "XML configuration file name. "
       "Default is DetectorDescription/RegressionTest/test/configuration.xml")
      ("file2,g", boost::program_options::value<std::string>(), "XML configuration file name. "
       "Default is DetectorDescription/RegressionTest/test/configuration.xml")
      ("dist-tolerance,t", boost::program_options::value<std::string>(), "Value tolerance for distances (in mm). "
       "Default value 0.0004 (anything larger is an error)")
      ("rot-tolerance,r", boost::program_options::value<std::string>(), "Value tolerance for rotation matrix elements. "
       "Default value is 0.0004 (anything larger is an error)")
      ("spec-tolerance,s", boost::program_options::value<std::string>(), "Value tolerance for rotation matrix elements. "
       "Default value is 0.0004 (anything larger is an error) NOT USED YET")
      ("user-ns,u", "Use the namespaces in each file and do NOT use the filename as namespace. "
       "Default is to use the filename of each file in the configuration.xml file as a filename")
      ("comp-rot,c", "Use the rotation name when comparing rotations. "
       "Default is to use the matrix only and not the name when comparing DDRotations")
      ("continue-on-error,e", "Continue after an error in values. "
       "Default is to stop at the first error. NOT IMPLEMENTED")
      ("attempt-resync,a", "Continue after an error in graph position, attempt to resync. "
       "Default is to stop at the first mis-match of the graph. NOT IMPLEMENTED");
    
    boost::program_options::positional_options_description p;
    p.add("file1", 1);
    p.add("file2", 2);
    
    boost::program_options::variables_map vm;
    try {
      store(boost::program_options::command_line_parser(argc,argv).options(desc).positional(p).run(),vm);
      notify(vm);
    } catch(boost::program_options::error const& iException) {
      std::cerr << "Exception from command line processing: "
                << iException.what() << "\n";
      std::cerr << desc << std::endl;
      return 1;
    }
    if(vm.count("help")) {
      std::cout << desc << std::endl;
      return 0;
    }

    bool fullPath = false;
    std::string configfile("DetectorDescription/RegressionTest/test/configuration.xml");
    std::string configfile2("DetectorDescription/RegressionTest/test/configuration.xml");
    DDCompOptions ddco;
    //    double dtol(0.0004), rottol(0.0004);
    // bool usrns(false), comprot(false);
    bool usrns(false);
    try {
      if (vm.count("file1")) {
	configfile = vm["file1"].as<std::string>();
	if (vm.count("file2")) {
	  configfile2 = vm["file2"].as<std::string>();
	}
      }
      if (vm.count("dist-tolerance"))
	ddco.distTol_ = vm["dist-tolerance"].as<double>();
      if (vm.count("rot-tolerance"))
	ddco.rotTol_ = vm["rot-tolerance"].as<double>();
      if (vm.count("spec-tolerance"))
	ddco.rotTol_ = vm["spec-tolerance"].as<double>();
      if (vm.count("user-ns")) 
	usrns = true;
      if (vm.count("comp-rot")) 
	ddco.compRotName_ = true;
      if (vm.count("continue-on-error")) 
	ddco.contOnError_ = true;
      if (vm.count("attempt-resync"))
	ddco.attResync_ = true;
    }
    catch(boost::exception& e)
    {
      edm::LogInfo("DDCompareCPV") << "Attempting to parse the options. Exception message: " << boost::diagnostic_information(e);
      return 1;
    }

    std::ios_base::fmtflags originalFlags = std::cout.flags();
    
    std::cout << "Settings are: " << std::endl;
    std::cout << "Configuration file 1: " << configfile << std::endl;
    std::cout << "Configuration file 2: " << configfile2 << std::endl;
    std::cout << "Length/distance tolerance: " << ddco.distTol_ << std::endl;
    std::cout << "Rotation matrix element tolerance: " << ddco.rotTol_ << std::endl;
    std::cout << "SpecPar tolerance: " << ddco.specTol_ << std::endl;
    std::cout << "User controlled namespace (both file sets)? " << std::boolalpha << usrns << std::endl;
    std::cout << "Compare Rotation names? " << ddco.compRotName_ << std::endl;
    std::cout << "Continue on error (data mismatch)? " << ddco.contOnError_ << std::endl;
    std::cout << "Attempt resyncronization of disparate graphs? " << ddco.attResync_ << std::endl;

    DDCompactView cpv1;
    DDLParser myP(cpv1);
    myP.getDDLSAX2FileHandler()->setUserNS(usrns);

    /* The configuration file tells the parser what to parse.
       The sequence of files to be parsed does not matter but for one exception:
       XML containing SpecPar-tags must be parsed AFTER all corresponding
       PosPart-tags were parsed. (Simply put all SpecPars-tags into seperate
       files and mention them at end of configuration.xml. Functional SW 
       will not suffer from this restriction).
    */  

    // Use the File-In-Path configuration document provider.
    FIPConfiguration fp(cpv1);
    try
    {
      fp.readConfig(configfile, fullPath);
    }
    catch (cms::Exception& e)
    {
      edm::LogInfo("DDCompareCPV") << "Attempting to read config. Exception message: " << e.what();
      return 1;
    }
    
    std::cout << "FILE 1: " << configfile << std::endl;
    if ( fp.getFileList().size() == 0 ) {
      std::cout << "FILE 1: configuration file has no DDD xml files in it!" << std::endl;
      exit(1);
    }
    int parserResult = myP.parse(fp);
    if (parserResult != 0) {
      std::cout << "FILE 1: problem encountered during parsing. exiting ... " << std::endl;
      exit(1);
    }
    cpv1.lockdown();

    DDCompactView cpv2;
    DDLParser myP2(cpv2);
    myP2.getDDLSAX2FileHandler()->setUserNS(usrns);

    /* The configuration file tells the parser what to parse.
       The sequence of files to be parsed does not matter but for one exception:
       XML containing SpecPar-tags must be parsed AFTER all corresponding
       PosPart-tags were parsed. (Simply put all SpecPars-tags into seperate
       files and mention them at end of configuration.xml. Functional SW 
       will not suffer from this restriction).
    */  

    // Use the File-In-Path configuration document provider.
    FIPConfiguration fp2(cpv2);
    fp2.readConfig(configfile2, fullPath);
    std::cout << "FILE 2: " << configfile2 << std::endl;
    if ( fp2.getFileList().size() == 0 ) {
      std::cout << "FILE 2: configuration file has no DDD xml files in it!" << std::endl;
      exit(1);
    }
    int parserResult2 = myP2.parse(fp2);
    if (parserResult2 != 0) {
      std::cout << "FILE 2: problem encountered during parsing. exiting ... " << std::endl;
      exit(1);
    }
    cpv2.lockdown();

    std::cout << "Parsing completed. Start comparing." << std::endl;

//      DDErrorDetection ed(cpv1);

//      bool noErrors = ed.noErrorsInTheReport(cpv1);
//      if (noErrors && fullPath) {
//        std::cout << "DDCompareCPV did not find any errors and is finished." << std::endl;
//      }
//     else {
//       ed.report(cpv1, std::cout);
//       if (!noErrors) {
//         return 1;
//       }
//     }

    DDCompareCPV ddccpv(ddco);
    bool graphmatch = ddccpv(cpv1, cpv2);

    if (graphmatch) {
      std::cout << "DDCompactView graphs match" << std::endl;
    } else {
      std::cout << "DDCompactView graphs do NOT match" << std::endl;
    }

    // Now set everything back to defaults
    std::cout.flags( originalFlags );

    return 0;
}
Beispiel #20
0
  DescriptorReader(const String& zernike_filename, const String& texture_filename, const String& dc_filename) {
    std::ifstream fp(zernike_filename.c_str());

    String line;
    while (fp) {
      std::getline(fp, line);

      if (line.length() <= 0) continue;

      size_t idx = line.find(" ");

      if (idx != String::npos) {
        String meshname = line.substr(0,idx);
        String descriptorStr = line.substr(idx+1);

        meshname = meshname.substr(meshname.find_last_of('/')+1);
        String meshnamefull = "meerkat:///tahirazim/apiupload/" + meshname + "/optimized/0/" + meshname;

        mZernikeDescriptorMap[meshnamefull] = ZernikeDescriptor(descriptorStr);
 
        meshnamefull = "meerkat:///tahirazim/apiupload/" + meshname + "/original/0/" + meshname;
        mZernikeDescriptorMap[meshnamefull] = ZernikeDescriptor(descriptorStr);


      }
    }

    fp.close();

    std::ifstream fp2(texture_filename.c_str());
    while (fp2) {
      std::getline(fp2, line);

      if (line.length() <= 0) continue;

      size_t idx = line.find(" ");

      if (idx != String::npos) {
        String meshname = line.substr(0,idx);
        String descriptorStr = line.substr(idx+1);

        if (meshname.find("meerkat:///") != 0) {
          //meshname = meshname.substr(meshname.find_last_of('/')+1); //this is no longer needed with ~/all_csds.txt
          String meshnamefull = "meerkat:///tahirazim/apiupload/" + meshname + "/optimized/0/" + meshname;
          mTextureDescriptorMap[meshnamefull] = ZernikeDescriptor(descriptorStr);
          meshnamefull = "meerkat:///tahirazim/apiupload/" + meshname + "/original/0/" + meshname;
          mTextureDescriptorMap[meshnamefull] = ZernikeDescriptor(descriptorStr);
        }
        else {
          mTextureDescriptorMap[meshname] = ZernikeDescriptor(descriptorStr);
        }
      }
    }

    fp2.close();

    std::ifstream fp3(dc_filename.c_str());
    std::getline(fp3, line);
    while (fp3) {
      String meshname=line;
      std::getline(fp3, line);  //texname
      String texname = line;
      String fullname = meshname + ":" + texname;
      std::getline(fp3, line);  //texname again
      std::getline(fp3, line);  //size info
      std::getline(fp3, line);  // sc (spatial coherence info)
      std::getline(fp3, line);  //percentage, color value, color variance table head.

      String value="abcde";
      int r = 0, g = 0, b = 0;
      std::getline(fp3, value);

      int maxPercentage = 0;
      //parse next "value: " line.
      while (value.substr(0,6) == "value:") {

        bool currentIsMax = false;

        char valueline[1024];
        strncpy(valueline, value.c_str(), value.length()+1);
        const char* delim = " :|";
        char* p;
        char*save;
        int count = 0;

        //tokenize the line
#if LIBPROX_PLATFORM == PLATFORM_WINDOWS
#define strtok_threadsafe strtok_s
#else
#define strtok_threadsafe strtok_r
#endif
        for (p=strtok_threadsafe(valueline, delim, &save); p; p = strtok_threadsafe(NULL, delim, &save) ) {
          if (count == 1) {
            int percentValue = atoi(p);
            if (percentValue > maxPercentage && percentValue > 90) {
              maxPercentage = percentValue;
              currentIsMax = true;
            }
          } //end if

          if (currentIsMax) {
            if (count == 2) r = atoi(p);
            if (count == 3) g = atoi(p);
            if (count == 4) b = atoi(p);
          } //end if

          count++;
        } //end for

        std::getline(fp3, value);
      } //end while

      line = value;

      //quantize the r,g,b's
      r = ((r/32)*32) + 16;
      g = ((g/32)*32) + 16;
      b = ((b/32)*32) + 16;

      //add to map.
      std::vector<float> rgb;
      rgb.push_back(r);
      rgb.push_back(g);
      rgb.push_back(b);

      //std::cout << fullname << " : " << r << " " << g << " " << b << "\n";
      if (maxPercentage != 0)
        mDominantColorMap[fullname] = ZernikeDescriptor(rgb);

      //std::cout << fullname << " : " << mDominantColorMap[fullname].toString() << "\n";
    }
    fp3.close();
  }
Beispiel #21
0
bool Lng::read_files( char *fname1, char *fname2, bool global, pwr_tStatus *sts)
{
  pwr_tFileName filename1, filename2;

  sprintf( filename2, fname2, get_language_str());

  dcli_translate_filename( filename1, fname1);
  dcli_translate_filename( filename2, filename2);

  ifstream fp1( filename1);
  if ( !fp1 && strcmp( fname1, "$pwr_exe/en_us/xtt_lng.dat") == 0) {
    // Try $pwr_eexe
    strcpy( fname1, "$pwr_eexe/en_us/xtt_lng.dat");
    dcli_translate_filename( filename1, fname1);
    fp1.open( filename1);
    if ( !fp1) {
      *sts = LNG__FILE;
      return false;
    }
  }
  else if ( !fp1) {
    *sts = LNG__FILE;
    return global ? false : true;
  }
  
  ifstream fp2( filename2);
  if ( !fp2 && strcmp( fname2, "$pwr_exe/%s/xtt_lng.dat") == 0) {
    // Try $pwr_eexe
    strcpy( fname2, "$pwr_eexe/%s/xtt_lng.dat");
    sprintf( filename2, fname2, get_language_str());
    dcli_translate_filename( filename2, filename2);
    fp2.open( filename2);
    if ( !fp2) {
      *sts = LNG__FILE;
      return false;
    }
  }
  else if ( !fp2) {
    *sts = LNG__FILE;
    return global ? false : true;
  }
  
  Row r1( fp1, filename1);
  Row r2( fp2, filename2);
  
  read_metadata( fp1, global, sts);
  read_metadata( fp2, global, sts);
  
  read_include( fp1, fp2, global, sts);

  bool hit = true;
  for (;;) {
    if ( hit) {
      if ( !read_line( r1))
	break;
      
      if ( !read_line( r2))
	break;
    }
    else if ( r1.lt( r2)) {
      if ( !read_line( r1))
	break;
    }
    else {
      if ( !read_line( r2))
	break;
    }
    
    hit = false;
    if ( r1.eq( r2))
      hit = true;
    if ( hit) {
      lang_sKey key;
      lang_sRecord *record;
      
      strncpy( key.text, r1.text, sizeof(key.text));
      key.type = r1.type;
      record = (lang_sRecord *) tree_Insert( sts, tree, &key);
      strcpy( record->transl, r2.text);
      // printf ( "%c %d.%d.%d '%s' '%s'\n", r1.type, r1.n1, r1.n2, r1.n3, r1.text,r2.text);
    }
  }    
  *sts = LNG__SUCCESS;
  return true;
}
Beispiel #22
0
int main(int argc, char *argv[])
{
    if (argc < 3)
    {
        Usage();
        return EXIT_FAILURE;
    }

    int cmd = !strcmp(argv[2], "list") ? CMD_LIST
            : !strcmp(argv[2], "get") ? CMD_GET
            : !strcmp(argv[2], "del") ? CMD_DEL
            : !strcmp(argv[2], "put") ? CMD_PUT
            : !strcmp(argv[2], "move") ? CMD_MOVE
            : !strcmp(argv[2], "rename") ? CMD_RENAME
            : !strcmp(argv[2], "type") ? CMD_TYPE
            : !strcmp(argv[2], "getpcx") ? CMD_GETPCX
            : !strcmp(argv[2], "putpcx") ? CMD_PUTPCX
            : CMD_INVALID;

    if (cmd == CMD_INVALID)
    {
        fprintf(stderr, "abuse-tool: unknown command `%s'\n", argv[2]);
        return EXIT_FAILURE;
    }

    /* Check argument count and file access mode */
    char const *mode = "rwb";
    int minargc = 3;

    switch (cmd)
    {
    case CMD_LIST:
        mode = "rb"; // Read-only access
        break;
    case CMD_GET:
        minargc = 4;
        mode = "rb"; // Read-only access
        break;
    case CMD_PUT:
        minargc = 6;
        break;
    case CMD_MOVE:
        minargc = 5;
        break;
    case CMD_RENAME:
        minargc = 5;
        break;
    case CMD_TYPE:
        minargc = 5;
        break;
    case CMD_DEL:
        minargc = 4;
        break;
    case CMD_GETPCX:
        minargc = 4;
        mode = "rb"; // Read-only access
        break;
    case CMD_PUTPCX:
        minargc = 6;
        break;
    }

    if (argc < minargc)
    {
        fprintf(stderr, "abuse-tool: too few arguments for command `%s'\n",
                         argv[2]);
        return EXIT_FAILURE;
    }

    /* Open the SPEC file */
    char tmpfile[4096];
    char const *file = argv[1];
    snprintf(tmpfile, 4096, "%s.tmp", file);

    jFILE fp(file, mode);
    if (fp.open_failure())
    {
        fprintf(stderr, "ERROR - could not open %s\n", file);
        return EXIT_FAILURE;
    }

    spec_directory dir(&fp);

    /* Now really execute commands */
    if (cmd == CMD_LIST)
    {
        printf("   id  type    bytes   crc  name & information\n");
        printf(" ----  ----  -------  ----  ----------------------------\n");

        dir.FullyLoad(&fp);

        for (int i = 0; i < dir.total; i++)
        {
            spec_entry *se = dir.entries[i];

            /* Print basic information */
            printf("% 5i   % 3i % 8i  %04x  %s", i, se->type, (int)se->size,
                   calc_crc(se->data, se->size), se->name);

            /* Is there anything special to say? */
            switch (se->type)
            {
            case SPEC_IMAGE:
            case SPEC_FORETILE:
            case SPEC_BACKTILE:
            case SPEC_CHARACTER:
            case SPEC_CHARACTER2:
              {
                image *im = new image(&fp, se);
                printf(" \t# %i x %i pixels", im->Size().x, im->Size().y);
                delete im;
                break;
              }
            case SPEC_PALETTE:
              {
                palette *pal = new palette(se, &fp);
                printf(" \t# %i colors", pal->pal_size());
                delete pal;
                break;
              }
#if 0
            default:
              {
                /* Try to print a representation of the item */
                int has_binary = 0;
                for (int i = 0; i < Min(20, (int)se->size); i++)
                {
                    uint8_t ch = ((uint8_t *)se->data)[i];
                    if (ch < 0x20 || ch >= 0x7f)
                        has_binary++;
                }
                if (has_binary <= 2 && se->size > 5)
                    has_binary = 0;

                printf(" \t# ");
                if (!has_binary)
                    putchar('\"');

                size_t max = Min(has_binary ? 15 : 30, (int)se->size);
                for (size_t i = 0; i < max; i++)
                {
                    uint8_t ch = ((uint8_t *)se->data)[i];
                    if (has_binary)
                        printf("%02x ", ch);
                    else if (ch && (ch < 0x20 || ch >= 0x7f))
                        printf("\\x%02x", ch);
                    else if (ch)
                        putchar(ch);
                    else
                        printf("\\0");
                }
                if (se->size > max)
                    printf("...");
                else if (!has_binary)
                    printf("\"");
                break;
              }
#endif
            }

            /* Finish line */
            putchar('\n');
        }

        return EXIT_SUCCESS;
    }
    else if (cmd == CMD_GET)
    {
        int id = atoi(argv[3]);

        if (id < 0 || id >= dir.total)
        {
            fprintf(stderr, "abuse-tool: id %i not found in %s\n", id, file);
            return EXIT_FAILURE;
        }

        spec_entry *se = dir.entries[id];
        fp.seek(se->offset, SEEK_SET);

        for (size_t todo = se->size; todo > 0; )
        {
            uint8_t buf[1024];
            int step = Min((int)todo, 1024);
            fp.read(buf, step);
            fwrite(buf, step, 1, stdout);
            todo -= step;
        }
        return EXIT_SUCCESS;
    }
    else if (cmd == CMD_GETPCX)
    {
        palette *pal;
        int imgid = atoi(argv[3]);
        int palid = argc > 4 ? atoi(argv[4]) : -1;

        for (int i = 0; palid == -1 && i < dir.total; i++)
            if (dir.entries[i]->type == SPEC_PALETTE)
                palid = i;

        if (palid == -1)
            pal = new palette(256);
        else
            pal = new palette(dir.entries[palid], &fp);

        image *im = new image(&fp, dir.entries[imgid]);
        write_PCX(im, pal, "/dev/stdout");
        delete im;
        delete pal;
        return EXIT_SUCCESS;
    }
    else if (cmd == CMD_MOVE)
    {
        int src = atoi(argv[3]);
        int dst = atoi(argv[4]);

        if (src < 0 || dst < 0 || src >= dir.total || dst >= dir.total)
        {
            fprintf(stderr, "abuse-tool: ids %i/%i out of range\n", src, dst);
            return EXIT_FAILURE;
        }

        dir.FullyLoad(&fp);

        spec_entry *tmp = dir.entries[src];
        for (int d = src < dst ? 1 : -1; src != dst; src += d)
            dir.entries[src] = dir.entries[src + d];
        dir.entries[dst] = tmp;
    }
    else if (cmd == CMD_RENAME || cmd == CMD_TYPE)
    {
        int id = atoi(argv[3]);

        if (id < 0 || id >= dir.total)
        {
            fprintf(stderr, "abuse-tool: id %i out of range\n", id);
            return EXIT_FAILURE;
        }

        dir.FullyLoad(&fp);
        if (cmd == CMD_RENAME)
            dir.entries[id]->name = argv[4];
        else
            dir.entries[id]->type = (uint8_t)atoi(argv[4]);
    }
    else if (cmd == CMD_DEL)
    {
        int id = atoi(argv[3]);

        if (id < 0 || id >= dir.total)
        {
            fprintf(stderr, "abuse-tool: id %i out of range\n", id);
            return EXIT_FAILURE;
        }

        dir.total--;
        for (int i = id; i < dir.total; i++)
            dir.entries[i] = dir.entries[i + 1];

        dir.FullyLoad(&fp);
    }
    else if (cmd == CMD_PUT || cmd == CMD_PUTPCX)
    {
        int id = atoi(argv[3]);
        uint8_t type = atoi(argv[4]);

        if (id == -1)
            id = dir.total;

        if (id < 0 || id > dir.total)
        {
            fprintf(stderr, "abuse-tool: id %i out of range\n", id);
            return EXIT_FAILURE;
        }

        dir.FullyLoad(&fp);
        dir.total++;
        dir.entries = (spec_entry **)realloc(dir.entries,
                                             dir.total * sizeof(spec_entry *));
        for (int i = dir.total - 1; i-- > id; )
            dir.entries[i + 1] = dir.entries[i];

        char *name = strrchr(argv[5], '/');
        if (!name)
            name = argv[5];

        uint8_t *data;
        size_t len;

        if (cmd == CMD_PUT)
        {
            jFILE fp2(argv[5], "rb");
            if (fp2.open_failure())
            {
                fprintf(stderr, "abuse-tool: cannot open %s\n", argv[5]);
                return EXIT_FAILURE;
            }
            len = fp2.file_size();
            data = (uint8_t *)malloc(len);
            fp2.read(data, len);
        }
        else
        {
            palette *pal = NULL;
            image *im = read_PCX(argv[5], pal);
            if (!im)
            {
                fprintf(stderr, "abuse-tool: cannot open %s\n", argv[5]);
                return EXIT_FAILURE;
            }
            vec2i size = im->Size();
            len = 2 * sizeof(uint16_t) + size.x * size.y;
            data = (uint8_t *)malloc(len);
            uint16_t x = lltl((uint16_t)size.x);
            uint16_t y = lltl((uint16_t)size.y);
            memcpy(data, &x, sizeof(x));
            memcpy(data + 2, &y, sizeof(y));
            memcpy(data + 4, im->scan_line(0), size.x * size.y);
        }
        dir.entries[id] = new spec_entry(type, name, NULL, len, 0);
        dir.entries[id]->data = data;
    }
    else
    {
        /* Not implemented yet */
        return EXIT_FAILURE;
    }

    /* If we get here, we need to write the directory back */
    dir.calc_offsets();
    fp.seek(0, SEEK_SET); // FIXME: create a new file
    dir.write(&fp);
    for (int i = 0; i < dir.total; i++)
        fp.write(dir.entries[i]->data, dir.entries[i]->size);

    return EXIT_SUCCESS;
}
bool Frustum::bakeProjectionOffset()
{
   // Nothing to bake if ortho
   if( mIsOrtho )
      return false;

   // Nothing to bake if no offset
   if( mProjectionOffset.isZero() )
      return false;

   // Near plane points in camera space
   Point3F np[4];
   np[0].set( mNearLeft, mNearDist, mNearTop );       // NearTopLeft
   np[1].set( mNearRight, mNearDist, mNearTop );      // NearTopRight
   np[2].set( mNearLeft, mNearDist, mNearBottom );    // NearBottomLeft
   np[3].set( mNearRight, mNearDist, mNearBottom );   // NearBottomRight

   // Generate the near plane
   PlaneF nearPlane( np[0], np[1], np[3] );

   // Far plane points in camera space
   const F32 farOverNear = mFarDist / mNearDist;
   Point3F fp0( mNearLeft * farOverNear, mFarDist, mNearTop * farOverNear );     // FarTopLeft
   Point3F fp1( mNearRight * farOverNear, mFarDist, mNearTop * farOverNear );    // FarTopRight
   Point3F fp2( mNearLeft * farOverNear, mFarDist, mNearBottom * farOverNear );  // FarBottomLeft
   Point3F fp3( mNearRight * farOverNear, mFarDist, mNearBottom * farOverNear ); // FarBottomRight

   // Generate the far plane
   PlaneF farPlane( fp0, fp1, fp3 );

   // The offset camera point
   Point3F offsetCamera( mProjectionOffset.x, 0.0f, mProjectionOffset.y );

   // The near plane point we'll be using for our calculations below
   U32 nIndex = 0;
   if( mProjectionOffset.x < 0.0 )
   {
      // Offset to the left so we'll need to use the near plane point on the right
      nIndex = 1;
   }
   if( mProjectionOffset.y > 0.0 )
   {
      // Offset to the top so we'll need to use the near plane point at the bottom
      nIndex += 2;
   }

   // Begin by calculating the offset point on the far plane as it goes
   // from the offset camera to the edge of the near plane.
   Point3F farPoint;
   Point3F fdir = np[nIndex] - offsetCamera;
   fdir.normalize();
   if( farPlane.intersect(offsetCamera, fdir, &farPoint) )
   {
      // Calculate the new near plane edge from the non-offset camera position
      // to the far plane point from above.
      Point3F nearPoint;
      Point3F ndir = farPoint;
      ndir.normalize();
      if( nearPlane.intersect( Point3F::Zero, ndir, &nearPoint) )
      {
         // Handle a x offset
         if( mProjectionOffset.x < 0.0 )
         {
            // The new near plane right side
            mNearRight = nearPoint.x;
         }
         else if( mProjectionOffset.x > 0.0 )
         {
            // The new near plane left side
            mNearLeft = nearPoint.x;
         }

         // Handle a y offset
         if( mProjectionOffset.y < 0.0 )
         {
            // The new near plane top side
            mNearTop = nearPoint.y;
         }
         else if( mProjectionOffset.y > 0.0 )
         {
            // The new near plane bottom side
            mNearBottom = nearPoint.y;
         }
      }
   }

   mDirty = true;

   // Indicate that we've modified the frustum
   return true;
}
Beispiel #24
0
int main() {
   constants_wrapper cfg;
   cfg.show();
   InitRNG RNG;
   RNG.seed(cfg.SEED);
   int a(0);
   if (!a) std::cout << "TRUEEEEE!!!" << std::endl;
   std::cout << std::endl << std::endl;
   std::cout << "X_MIN = " << cfg.X_MIN << std::endl;
   std::cout << "X_MAX = " << cfg.X_MAX << std::endl;
   std::cout << "Y_MIN = " << cfg.Y_MIN << std::endl;
   std::cout << "Y_MAX = " << cfg.Y_MAX << std::endl;

   std::cout << "READ_FOOD_FROM_FILE = " << cfg.READ_FOOD_FROM_FILE << std::endl;
   std::cout << "FOOD_POINT_DISTRIBUTION = " << cfg.FOOD_POINT_DISTRIBUTION << std::endl;


   chromo beauty_d(beauty_default);
   chromo dim_d(dim_default);
   chromo athlet_d(athlet_default);
   chromo karma_d(karma_default);
   chromo attracted_d(attracted_default);
   chromo charm_d(charm_default);

   DNA dna1(charm_d, beauty_d, dim_d, athlet_d, karma_d, attracted_d);
   DNA dna2(attracted_d, beauty_d, dim_d, athlet_d, karma_d, attracted_d);
   //dna2.set_chromo(c1,5);
   if (dna1 == dna2)  {
      std::cout << "TRUE1" << std::endl;
   } else { std::cout << "qualche problema" << std::endl;
     };
   
   being conf_being(dna1, 0, cfg.starting_energy, true, 1.0, 2.0, 0, 0);
   conf_being.configure(cfg);
   being b1(dna1, 0, cfg.starting_energy, true, 1.0, 2.0, 0, 0);
   //b1.show();
   being b2(dna2, 0, 100, true, 2.0, 2.0, 0, 0);

   food_point fp2(4.1, 4.2, cfg.default_nutrival);
   food_point fp3(1.1, 2.2, cfg.default_nutrival);

   point_2d p1(1,1);
   point_2d p2(2,2);

   // create and open a character archive for output
   std::ofstream ofs("./points.txt");
   // save data to archive
    {
        boost::archive::text_oarchive oa(ofs);
        // write class instance to archive
        oa << p1;
        oa << p2;
        oa << beauty_d;
        oa << dna1;
        oa << b1;
    	// archive and stream closed when destructors are called
    }


    // ... some time later restore the class instance to its orginal state
    point_2d p1new;
    point_2d p2new;
    chromo new_beauty;
    DNA dna1new;
    being b1new;

    {
        // create and open an archive for input
        std::ifstream ifs("./points.txt");
        boost::archive::text_iarchive ia(ifs);
        // read class state from archive
        ia >> p1new;
        ia >> p2new;
        ia >> new_beauty;
        ia >> dna1new;
        ia >> b1new;
        // archive and stream closed when destructors are called
    }

   std::cout << "P1new = ";
   p1new.show_point();
   std::cout << std::endl;

   std::cout << "P2new = ";
   p2new.show_point();
   std::cout << std::endl;

   std::cout << "new beauty = " << new_beauty << std::endl;
   std::cout << "newdna1 = " << dna1new << std::endl;

   if (dna1 == dna1new) std::cout << "TRUE!" << std::endl;

   std::cout << "B1NEW = " << std::endl << b1new << std::endl;

   world myworld(cfg.N_BEINGS,cfg.N_FOOD_POINT_AT_START);
   myworld.name("MyWorld");
   std::cout << "World name = " << myworld.name() << std::endl;
   
   //myworld.add(b1);
   //myworld.add(b2);
   //myworld.add(fp2);
   //myworld.add(fp3);
   //myworld.stats();
   //myworld.advance_one_generation();
   //myworld.stats();

//   myworld.load("DATA/200.txt");
//   myworld.stats();
//   myworld.evolve(1);
//   myworld.stats();

   std::vector<int> iv;
   iv.reserve(10);
   for (int i=0; i<10; ++i) iv.push_back(i);

   std::vector<int>::iterator iv_end = iv.end();
   for (std::vector<int>::iterator it = iv.begin(); it!=iv_end; ++it) {
      std::cout << *it << std::endl;
      iv.push_back(11);
   }

   if (cfg.BEINGS_START_DISTRIBUTION == "UNIFORM") {
      std::uniform_real_distribution<float> beings_distribution_x(cfg.X_MIN , cfg.X_MAX);
      std::uniform_real_distribution<float> beings_distribution_y(cfg.Y_MIN , cfg.Y_MAX);
      for (int i = 0; i < cfg.N_BEINGS; ++i) {
         b1.set_x(beings_distribution_x(RNG.generator));
         b1.set_y(beings_distribution_y(RNG.generator));
         myworld.add(b1) ;
      };
   };

   std::cout << "READ_FOOD_FROM_FILE = " << cfg.READ_FOOD_FROM_FILE << std::endl;
   if (!cfg.READ_FOOD_FROM_FILE) 
   {
      std::cout << "Creating food point from scratch" << std::endl;
      if (cfg.FOOD_POINT_DISTRIBUTION == "UNIFORM") {
         std::uniform_real_distribution<float> food_distribution_x(cfg.X_MIN , cfg.X_MAX);
         std::uniform_real_distribution<float> food_distribution_y(cfg.Y_MIN , cfg.Y_MAX);
         for (int i = 0; i < cfg.N_FOOD_POINT_AT_START; ++i) {
            food_point fpx( food_distribution_x(RNG.generator) , food_distribution_y(RNG.generator) , cfg.default_nutrival );
            myworld.add(fpx) ;
         }
      }
   }
   else 
   {
      std::cout << "Reading food points from file = " << cfg.food_file << std::endl;
      // create and open an archive for input
      std::ifstream ifs2(cfg.food_file);
      boost::archive::text_iarchive ia(ifs2);
      food_point newfp;
      // read class state from archive
      for (int i=0; i<cfg.N_FOOD_POINT_AT_START; ++i) {
         ia >> newfp;
         myworld.add(newfp);
      }
   };
  

   myworld.stats();

   //return 0;
   std::chrono::time_point<std::chrono::high_resolution_clock> start, end;
   start = std::chrono::high_resolution_clock::now();
   myworld.evolve(cfg.ITER_NUMBER);
   end = std::chrono::high_resolution_clock::now();
   cfg.save("myworld.cfg");
   std::cout << "World evolved in = " << std::chrono::duration_cast<std::chrono::milliseconds>(end - start).count() << "ms." << std::endl;
/*
   // create and open a character archive for output
   std::ofstream ofs2("./world.txt");
   // save data to archive
    {
        boost::archive::text_oarchive oa(ofs2);
        // write class instance to archive
        oa << myworld;
        // archive and stream closed when destructors are called
    }



    world newworld(1000,1000);


    {
        // create and open an archive for input
        std::ifstream ifs2("./world.txt");
        boost::archive::text_iarchive ia(ifs2);
        // read class state from archive
        ia >> newworld;
        // archive and stream closed when destructors are called
    }


   newworld.stats();
*/
   return 0;
};