Esempio n. 1
0
/** Check might look into the file.
\param file File handle to check.
\return True if file seems to be loadable. */
bool CArchiveLoaderTAR::isALoadableFileFormat(io::IReadFile* file) const
{
	// TAR files consist of blocks of 512 bytes
	// if it isn't a multiple of 512 then it's not a TAR file.
	if (file->getSize() % 512)
		return false;

	file->seek(0);

	// read header of first file
	STarHeader fHead;
	file->read(&fHead, sizeof(STarHeader));

	u32 checksum = 0;
	sscanf(fHead.Checksum, "%o", &checksum);

	// verify checksum

	// some old TAR writers assume that chars are signed, others assume unsigned
	// USTAR archives have a longer header, old TAR archives end after linkname

	u32 checksum1=0;
	s32 checksum2=0;

	// remember to blank the checksum field!
	memset(fHead.Checksum, ' ', 8);

	// old header
	for (u8* p = (u8*)(&fHead); p < (u8*)(&fHead.Magic[0]); ++p)
	{
		checksum1 += *p;
		checksum2 += c8(*p);
	}

	if (!strncmp(fHead.Magic, "ustar", 5))
	{
		for (u8* p = (u8*)(&fHead.Magic[0]); p < (u8*)(&fHead) + sizeof(fHead); ++p)
		{
			checksum1 += *p;
			checksum2 += c8(*p);
		}
	}
	return checksum1 == checksum || checksum2 == (s32)checksum;
}
Esempio n. 2
0
int main(int argc, char *argv[]) {
	char const *testData = "ACGTTGCACATG";
	for (unsigned int i = 0; i < ::strlen(testData); ++i) {
		ChromosomeBase<2> c2(::strdup(testData), i);
		ChromosomeBase<4> c4(::strdup(testData), i);
		ChromosomeBase<8> c8(::strdup(testData), i);
		for (unsigned int j = 0; j < i; ++j) {
			assert(c2[j] == testData[j]);
			assert(c4[j] == testData[j]);
			assert(c8[j] == testData[j]);
		}
	}
}
Esempio n. 3
0
void check_split(Curve_type &xcv1, Curve_type &xcv2)
{
  Polycurve_conic_traits_2 traits;

  //split x poly-curves

  Conic_curve_2 c6(1,1,0,6,-26,162,CGAL::COUNTERCLOCKWISE,
                   Conic_point_2(Algebraic(-7), Algebraic(13)),
                   Conic_point_2(Algebraic(-3), Algebraic(9)));
  Conic_curve_2 c7(1,0,0,0,-1,0,CGAL::COUNTERCLOCKWISE,
                   Conic_point_2(Algebraic(-3), Algebraic(9)),
                   Conic_point_2(Algebraic(0), Algebraic(0)));
  Conic_curve_2 c8(0,1,0,-1,0,0, CGAL::COUNTERCLOCKWISE,
                   Conic_point_2(Algebraic(0), Algebraic(0)),
                   Conic_point_2(Algebraic(4), Algebraic(-2)));

  Conic_x_monotone_curve_2 xc6(c6);
  Conic_x_monotone_curve_2 xc7(c7);
  Conic_x_monotone_curve_2 xc8(c8);
  std::vector<Conic_x_monotone_curve_2> xmono_conic_curves_2;

  xmono_conic_curves_2.push_back(xc6);
  xmono_conic_curves_2.push_back(xc7);
  Pc_x_monotone_curve_2 split_expected_1 =
    traits.construct_x_monotone_curve_2_object()(xmono_conic_curves_2.begin(),
                                                 xmono_conic_curves_2.end());

  xmono_conic_curves_2.clear();
  xmono_conic_curves_2.push_back(xc8);
  Pc_x_monotone_curve_2 split_expected_2 =
    traits.construct_x_monotone_curve_2_object()(xmono_conic_curves_2.begin(),
                                                 xmono_conic_curves_2.end());


  Polycurve_conic_traits_2::X_monotone_curve_2 split_curve_1, split_curve_2;
  Polycurve_conic_traits_2::Point_2
    point_of_split = Polycurve_conic_traits_2::Point_2(0,0);

  //Split functor
  traits.split_2_object()(xcv2, point_of_split, split_curve_1, split_curve_2);

  bool split_1_chk = traits.equal_2_object()(split_curve_1, split_expected_1);
  bool split_2_chk = traits.equal_2_object()(split_curve_2, split_expected_2);

  if(split_1_chk && split_2_chk)
    std::cout << "Split is working fine" << std::endl;
  else
    std::cout << "Something is wrong with split" << std::endl;
}
Esempio n. 4
0
int main()
{
    // Några saker som ska fungera:
    UIntVector a(10);               // initiering med 7 element
    std::cout << "a(10)"<< a.length << std::endl;
    std::cout << "kopiering" << std::endl;
    UIntVector b(a);           // kopieringskonstruktor 
    std::cout << "kopiering" << std::endl;
    a = a;
    std::cout << "s**t" << std::endl;
    UIntVector c = a;          // kopieringskonstruktor 

    //Extra tester för alla Requirments
    a = b;                 // tilldelning genom kopiering
    a[5] = 7;              // tilldelning till element

    const UIntVector e(100000);    // konstant objekt med 10 element
    int i = e[5];          // const int oper[](int) const körs
    i = a[0];              // vektorn är nollindexerad
    i = a[5];              // int oper[](int) körs
    
    a[5]++;                // öka värdet till 8
    
    //Extra tester för alla Requirments
    std::cout << "(1)TEST" << std::endl;
    int aa = e[9];
    int ab = e[0];
    std::cout << "(1)S**T" << aa << ab << std::endl;


    std::cout << "(2)TEST" << std::endl;
    for(long int i = 0; i < 100000; i++)
    {
        e[i];
    } 
    std::cout << "(2)S**T" << std::endl;




    std::cout << "(3)TEST" << std::endl;
    UIntVector a3(10); UIntVector b3(0); UIntVector c3(0);
    b3 = a3;
    a3 = c3;
    std::cout << "(3)S**T" << std::endl;




    std::cout << "(4) START" << std::endl;
    std::initializer_list<unsigned int> list = {1,2,3};
    UIntVector a4(list); UIntVector b4(0);
    a4 = b4;
    std::cout << "length a" << a4.size() << "len b " << b4.size() << std::endl;
    std::cout << "(4) S**T" << std::endl;



    std::cout << "(5)TEST" << std::endl;
    UIntVector b5(list);
    UIntVector a5(std::move(b5));
    std::cout << "(5)S**T" << std::endl;





    std::cout << "(6)TEST" << std::endl;
    UIntVector a6(30);
    UIntVector b6(a6);
    std::cout << "(6)S**T" << std::endl;


    std::cout << "(7)TEST" << std::endl;
    UIntVector a7(1); 
    std::cout << "a) len innan " <<a7.length << std::endl;
    UIntVector b7(std::move(a7));
    std::cout << "b) len " <<b7.length << std::endl;
    std::cout << "a) len " <<a7.length << std::endl;
    std::cout << "(7)S**T" << std::endl;

    std::cout << "(8)TEST" << std::endl;
    UIntVector a8(10);
    a8.reset();
    UIntVector b8(11);
    std::cout << "a) INNAN len " <<a8.size() << "ptr " << a8.vector_ptr <<std::endl;
    UIntVector c8(std::move(a8));
    std::cout << "c) len " <<c8.size() << "ptr" << c8.vector_ptr <<std::endl;
    std::cout << "a) len " <<a8.size() << "ptr " << a8.vector_ptr <<std::endl;
    std::cout << "(8)S**T" << std::endl;


    std::cout << "(9)TEST COPY TO SELF" << std::endl;
    b8 = b8;
    std::cout << "(9)S**T" << std::endl;
    try {
        i = e[10];             // försöker hämta element som ligger utanför e
    } catch (std::out_of_range e) {
        std::cout << e.what() << std::endl;
    }

    
#if 0
    // Diverse saker att testa
    e[5] = 3;              // fel: (kompilerar ej) tilldelning till const
    b = b;                 // hmm: se till att inte minnet som skall behållas frigörs
#endif

    return 0;
}
Esempio n. 5
0
int main()
{
   // check that it'll find nodes exactly MAX away
   {
      tree_type exact_dist(std::ptr_fun(tac));
        triplet c0(5, 4, 0);
        exact_dist.insert(c0);
        triplet target(7,4,0);

      std::pair<tree_type::const_iterator,double> found = exact_dist.find_nearest(target,2);
      assert(found.first != exact_dist.end());
      assert(found.second == 2);
      std::cout << "Test find_nearest(), found at exact distance away from " << target << ", found " << *found.first << std::endl;
   }

   // do the same test, except use alternate_triplet as the search key
   {
      // NOTE: stores triplet, but we search with alternate_triplet
      typedef KDTree::KDTree<3, triplet, alternate_tac> alt_tree;

      triplet actual_target(7,0,0);

      alt_tree tree;
      tree.insert( triplet(0, 0, 7) );
      tree.insert( triplet(0, 0, 7) );
      tree.insert( triplet(0, 0, 7) );
      tree.insert( triplet(3, 0, 0) );
      tree.insert( actual_target );
      tree.optimise();

      alternate_triplet target( actual_target );

      std::pair<alt_tree::const_iterator,double> found = tree.find_nearest(target);
      assert(found.first != tree.end());
      std::cout << "Test with alternate search type, found: " << *found.first << ", wanted " << actual_target << std::endl;
      assert(found.second == 0);
      assert(*found.first == actual_target);
   }


   {
      tree_type exact_dist(std::ptr_fun(tac));
        triplet c0(5, 2, 0);
        exact_dist.insert(c0);
        triplet target(7,4,0);

        // call find_nearest without a range value - it found a compile error earlier.
      std::pair<tree_type::const_iterator,double> found = exact_dist.find_nearest(target);
      assert(found.first != exact_dist.end());
      std::cout << "Test find_nearest(), found at exact distance away from " << target << ", found " << *found.first << " @ " << found.second << " should be " << std::sqrt(8) << std::endl;
      assert(found.second == std::sqrt(8));
   }

   {
      tree_type exact_dist(std::ptr_fun(tac));
        triplet c0(5, 2, 0);
        exact_dist.insert(c0);
        triplet target(7,4,0);

      std::pair<tree_type::const_iterator,double> found = exact_dist.find_nearest(target,std::sqrt(8));
      assert(found.first != exact_dist.end());
      std::cout << "Test find_nearest(), found at exact distance away from " << target << ", found " << *found.first << " @ " << found.second << " should be " << std::sqrt(8) << std::endl;
      assert(found.second == std::sqrt(8));
   }

  tree_type src(std::ptr_fun(tac));

  triplet c0(5, 4, 0); src.insert(c0);
  triplet c1(4, 2, 1); src.insert(c1);
  triplet c2(7, 6, 9); src.insert(c2);
  triplet c3(2, 2, 1); src.insert(c3);
  triplet c4(8, 0, 5); src.insert(c4);
  triplet c5(5, 7, 0); src.insert(c5);
  triplet c6(3, 3, 8); src.insert(c6);
  triplet c7(9, 7, 3); src.insert(c7);
  triplet c8(2, 2, 6); src.insert(c8);
  triplet c9(2, 0, 6); src.insert(c9);

  std::cout << src << std::endl;

  src.erase(c0);
  src.erase(c1);
  src.erase(c3);
  src.erase(c5);

  src.optimise();


  // test the efficient_replace_and_optimise()
  tree_type eff_repl = src;
  {
     std::vector<triplet> vec;
     // erased above as part of test vec.push_back(triplet(5, 4, 0));
     // erased above as part of test vec.push_back(triplet(4, 2, 1));
     vec.push_back(triplet(7, 6, 9));
     // erased above as part of test vec.push_back(triplet(2, 2, 1));
     vec.push_back(triplet(8, 0, 5));
     // erased above as part of test vec.push_back(triplet(5, 7, 0));
     vec.push_back(triplet(3, 3, 8));
     vec.push_back(triplet(9, 7, 3));
     vec.push_back(triplet(2, 2, 6));
     vec.push_back(triplet(2, 0, 6));

     eff_repl.clear();
     eff_repl.efficient_replace_and_optimise(vec);
  }


  std::cout << std::endl << src << std::endl;

  tree_type copied(src);
  std::cout << copied << std::endl;
  tree_type assigned;
  assigned = src;
  std::cout << assigned << std::endl;

  for (int loop = 0; loop != 4; ++loop)
    {
      tree_type * target;
      switch (loop)
	{
	case 0: std::cout << "Testing plain construction" << std::endl;
	  target = &src;
	  break;

	case 1: std::cout << "Testing copy-construction" << std::endl;
	  target = &copied;
	  break;

	case 2: std::cout << "Testing assign-construction" << std::endl;
	  target = &assigned;
	  break;

   default:
	case 4: std::cout << "Testing efficient-replace-and-optimise" << std::endl;
	  target = &eff_repl;
	  break;
	}
      tree_type & t = *target;

      int i=0;
      for (tree_type::const_iterator iter=t.begin(); iter!=t.end(); ++iter, ++i);
      std::cout << "iterator walked through " << i << " nodes in total" << std::endl;
      if (i!=6)
	{
	  std::cerr << "Error: does not tally with the expected number of nodes (6)" << std::endl;
	  return 1;
	}
      i=0;
      for (tree_type::const_reverse_iterator iter=t.rbegin(); iter!=t.rend(); ++iter, ++i);
      std::cout << "reverse_iterator walked through " << i << " nodes in total" << std::endl;
      if (i!=6)
	{
	  std::cerr << "Error: does not tally with the expected number of nodes (6)" << std::endl;
	  return 1;
	}

      triplet s(5, 4, 3);
      std::vector<triplet> v;
      unsigned int const RANGE = 3;

      size_t count = t.count_within_range(s, RANGE);
      std::cout << "counted " << count
		<< " nodes within range " << RANGE << " of " << s << ".\n";
      t.find_within_range(s, RANGE, std::back_inserter(v));

      std::cout << "found   " << v.size() << " nodes within range " << RANGE
		<< " of " << s << ":\n";
      std::vector<triplet>::const_iterator ci = v.begin();
      for (; ci != v.end(); ++ci)
	std::cout << *ci << " ";
      std::cout << "\n" << std::endl;

      std::cout << std::endl << t << std::endl;

      // search for all the nodes at exactly 0 dist away
      for (tree_type::const_iterator target = t.begin(); target != t.end(); ++target)
      {
         std::pair<tree_type::const_iterator,double> found = t.find_nearest(*target,0);
         assert(found.first != t.end());
         assert(*found.first == *target);
         std::cout << "Test find_nearest(), found at exact distance away from " << *target << ", found " << *found.first << std::endl;
      }

      {
         const double small_dist = 0.0001;
         std::pair<tree_type::const_iterator,double> notfound = t.find_nearest(s,small_dist);
         std::cout << "Test find_nearest(), nearest to " << s << " within " << small_dist << " should not be found" << std::endl;

         if (notfound.first != t.end())
         {
            std::cout << "ERROR found a node at dist " << notfound.second << " : " << *notfound.first << std::endl;
            std::cout << "Actual distance = " << s.distance_to(*notfound.first) << std::endl;
         }

         assert(notfound.first == t.end());
      }

      {
         std::pair<tree_type::const_iterator,double> nif = t.find_nearest_if(s,std::numeric_limits<double>::max(),Predicate());
         std::cout << "Test find_nearest_if(), nearest to " << s << " @ " << nif.second << ": " << *nif.first << std::endl;

         std::pair<tree_type::const_iterator,double> cantfind = t.find_nearest_if(s,std::numeric_limits<double>::max(),FalsePredicate());
         std::cout << "Test find_nearest_if(), nearest to " << s << " should never be found (predicate too strong)" << std::endl;
         assert(cantfind.first == t.end());
      }




      {
      std::pair<tree_type::const_iterator,double> found = t.find_nearest(s,std::numeric_limits<double>::max());
      std::cout << "Nearest to " << s << " @ " << found.second << " " << *found.first << std::endl;
      std::cout << "Should be " << found.first->distance_to(s) << std::endl;
      // NOTE: the assert does not check for an exact match, as it is not exact when -O2 or -O3 is
      // switched on.  Some sort of optimisation makes the math inexact.
      assert( fabs(found.second - found.first->distance_to(s)) < std::numeric_limits<double>::epsilon() );
      }

      {
      triplet s2(10, 10, 2);
      std::pair<tree_type::const_iterator,double> found = t.find_nearest(s2,std::numeric_limits<double>::max());
      std::cout << "Nearest to " << s2 << " @ " << found.second << " " << *found.first << std::endl;
      std::cout << "Should be " << found.first->distance_to(s2) << std::endl;
      // NOTE: the assert does not check for an exact match, as it is not exact when -O2 or -O3 is
      // switched on.  Some sort of optimisation makes the math inexact.
      assert( fabs(found.second - found.first->distance_to(s2)) < std::numeric_limits<double>::epsilon() );
      }

      std::cout << std::endl;

      std::cout << t << std::endl;

      // Testing iterators
      {
	std::cout << "Testing iterators" << std::endl;

	t.erase(c2);
	t.erase(c4);
	t.erase(c6);
	t.erase(c7);
	t.erase(c8);
	//    t.erase(c9);

	std::cout << std::endl << t << std::endl;

	std::cout << "Forward iterator test..." << std::endl;
	std::vector<triplet> forwards;
	for (tree_type::iterator i = t.begin(); i != t.end(); ++i)
	  { std::cout << *i << " " << std::flush; forwards.push_back(*i); }
	std::cout << std::endl;
	std::cout << "Reverse iterator test..." << std::endl;
	std::vector<triplet> backwards;
	for (tree_type::reverse_iterator i = t.rbegin(); i != t.rend(); ++i)
	  { std::cout << *i << " " << std::flush; backwards.push_back(*i); }
	std::cout << std::endl;
	std::reverse(backwards.begin(),backwards.end());
	assert(backwards == forwards);
      }
    }


  // Walter reported that the find_within_range() wasn't giving results that were within
  // the specified range... this is the test.
  {
     tree_type tree(std::ptr_fun(tac));
     tree.insert( triplet(28.771200,16.921600,-2.665970) );
     tree.insert( triplet(28.553101,18.649700,-2.155560) );
     tree.insert( triplet(28.107500,20.341400,-1.188940) );
     tree.optimise();

     std::deque< triplet > vectors;
     triplet sv(18.892500,20.341400,-1.188940);
     tree.find_within_range(sv, 10.0f, std::back_inserter(vectors));

     std::cout << std::endl << "Test find_with_range( " << sv << ", 10.0f) found " << vectors.size() << " candidates." << std::endl;

     // double-check the ranges
     for (std::deque<triplet>::iterator v = vectors.begin(); v != vectors.end(); ++v)
     {
        double dist = sv.distance_to(*v);
        std::cout << "  " << *v << " dist=" << dist << std::endl;
        if (dist > 10.0f)
           std::cout << "    This point is too far! But that is by design, its within a 'box' with a 'radius' of 10, not a sphere with a radius of 10" << std::endl;
        // Not a valid test, it can be greater than 10 if the point is in the corners of the box.
        // assert(dist <= 10.0f);
     }
  }


  return 0;
}
int read_multiplet_data(int lineno, char filename[], opt* opts,
						vector<string> *listname, vector<metab_template> *Tems, vector<double> *x,
						char chemshift[], int s, char inputdir[])
// read in metabolite multiplet data, note at present this assumes the file
// is ordered in groups corresponding to different metabolites
{
	vector<string> names(lineno);// name characters the first line
	matrix c1(lineno);
	matrix c2(lineno);
	matrix c3(lineno);
	matrix c4(lineno);
	matrix c5(lineno);
	//matrix c6(lineno);
	matrix c7(lineno);
	matrixI c8(lineno);
	// for ph
	vector<string> names2(lineno);
	matrix c11(lineno);
	matrix c12(lineno);
	
	
	int count = 0;
	double pst, ped;
	
	int nl = read_datf(&names,&c1, &c2, &c3, &c4, &c5, &c7, &c8, filename);
	
	if (nl < 0)
	{
		return nl;
	}
	
	
	if ((*opts).usechemshift == 1)
	{
		int nl2 = read_dat_chemshift(&names2, &c11,&c12, chemshift, s);
		if (nl2 < 0)
		{
			return nl2;
		}
		
		if (nl != nl2)
		{
			printf("Different number of multiplets, exiting ...\n");
			system("PAUSE");
			exit(1);
			//return -999;
		}
		for (unsigned int j = 0; j < nl2; j++)
		{
			if (!((c12[j][0]+50)<0.0000001))
			{
				//	if(names[j].compare(names2[j]) == 0 && c11[j][0] == c1[j][0])
				//{
				c1[j][0] = c12[j][0];
				//}else{
				//	printf("something wrong with multi chemshift, exiting ...\n");
				//	system("PAUSE");
				//	exit(1);
				//}
			}
		}
	}
	
	
	char prevname[80]=" ";
	char name[80] = {'\0'};
	char lis[80] = {'\0'};
	metab_template templa("",(*x).size());
	
	for (unsigned int i  = 0; i < (*listname).size(); i++)
	{
		strcpy(lis,(*listname)[i].c_str());
		
		for (int it = 0; it < nl; it++)
		{
			strcpy(name,names[it].c_str());
			if (!strcmp(lis,name) && c8[it][0]==1) // find a match in the list
			{
				if (!strcmp(prevname, " ")&& c8[it][0]==1)//first prevname do not match prevname
				{
					metab_template templa1(name,(*x).size());
					templa = templa1;
				}
				
				if (strcmp(prevname,name) && strcmp(prevname, " ") && c8[it][0]==1) // make a new template
				{
					metab_template templa1(name,(*x).size());
					templa = templa1;
				}
				
				strcpy(prevname,name);
				
				for (unsigned int n2 = 0; n2<(*opts).st.size(); n2++)
				{
					if ((*opts).st[n2]>(*opts).ed[n2])
					{
						pst = (*opts).ed[n2];
						ped = (*opts).st[n2];
					} else {
						ped = (*opts).ed[n2];
						pst = (*opts).st[n2];
					}
					if ((c5[it][0]+50)<0.0000001)
					{
						if (!((c7[it][0]+50)<0.0000001))
						{
							if (c1[it][0]<ped+(15.0*(*opts).log_fwhh_prop_var)+c7[it][0]
								&& c1[it][0]>pst-(15.0*(*opts).log_fwhh_prop_var)-c7[it][0])
							{
								count = 1;
							}
						} else {
							if (c1[it][0]<ped+(15.0*(*opts).log_fwhh_prop_var)+(*opts).rdelta
								&& c1[it][0]>pst-(15.0*(*opts).log_fwhh_prop_var)-(*opts).rdelta)
							{
								count = 1;
							}
						}
					} else {
						if (!((c7[it][0]+50)<0.0000001))
						{
							if (c5[it][0]<ped+(15.0*(*opts).log_fwhh_prop_var)+c7[it][0]
								&& c5[it][0]>pst-(15.0*(*opts).log_fwhh_prop_var)-c7[it][0])
							{
								count = 1;
							}
						} else {
							if (c5[it][0]<ped+(15.0*(*opts).log_fwhh_prop_var)+(*opts).rdelta
								&& c5[it][0]>pst-(15.0*(*opts).log_fwhh_prop_var)-(*opts).rdelta)
							{
								count = 1;
							}
						}
					}
				}
				if (count == 1)
				{
					if((c2[it][0]+1 <0.0000001) && (c2[it][0]+1 > -0.0000001))
					{
						if (c3[it].size()!=c4[it].size())
						{
							cout<<"\nNo. of protons do not match no. of J constant for metabolite "<<names[it]<<", exiting ...\n";
							//system("PAUSE");
							exit(1);
						}
						double prot=0;
						
						for(unsigned int locit=0;locit<c4[it].size();locit++)
							prot+=c4[it][locit];
						vector<double> weights(c4[it]);
						for(unsigned int locit=0;locit<c4[it].size();locit++)
							weights[locit]/=prot;
						
						//multiplet_site ms(prot, c1[it][0]);
						multiplet_site ms(&c2[it], c1[it][0], &c3[it], prot,
										  x, c5[it][0],-50, c7[it][0], opts);
						
						// vector<unsigned int> c2int(c2[it].size(),0);
						//vecftoi(c2[it], c2int);
						ms.setup_param_extra(c3[it],weights);
						templa.add_multiplet(ms);
					} else if ((c2[it][0]+2 <0.0000001) && (c2[it][0]+2 > -0.0000001)) {
						
						//multiplet_site new_mult2(&pos_vec,&nprot_vec, &x);
						//cout << "c2 "<<c2[it][0] << endl;
						
						vector<double> raster(0.0);
						double vec_el;
						
						multiplet_site ms(&c2[it], c1[it][0], &c3[it], c4[it][0],
										  x, c5[it][0], -50, c7[it][0], opts);
						
						if (c3[it].size() == 2)
						{
							// raster
							//printf("find input raster\n");
							raster.clear();
							char fdirR[3000]={'\0'};
							strcpy(fdirR,inputdir);
							strcat(fdirR,name);
							strcat(fdirR,".txt");
							ifstream inA3_str(fdirR);
							//cout<<"route "<< fdirR<<endl;
							//cout<<"file is "<< inA3_str<< endl;
							
							//if (!inA3_str)
							//cout<<"empty, no file "<< inA3_str<< endl;
							//int tst = 1;
							int tst2 = 0;
							
							while(inA3_str.good())
							{
								tst2 = tst2 +1;
								
								inA3_str>>vec_el;
								//cout<<"vec_el ppm "<<vec_el<<",tst2 " <<tst2<<endl;
								inA3_str.ignore(1);
								inA3_str.peek();
								if (tst2%2 != 0)
								{
									//cout<<"tst2 " <<tst2<<endl;
									if(vec_el<=max(c3[it][1],c3[it][0]) && vec_el>=min(c3[it][1],c3[it][0]))
									{
																			
											inA3_str>>vec_el;
										raster.push_back(vec_el);
										tst2 = tst2 +1;
									} 
								}

							}
							/*cout<<"tst = " <<tst<<endl;
							cout<<"raster1 = "<< raster[0]<<"rasterE = "<<raster[raster.size()-1]<<endl;
							//cout << "c3 "<<c3[it].size()<<endl;
							//for (int ii = 0; ii <raster.size(); ii++)
							//cout<<"raster "<< raster[ii] << " ";
							FILE *outM;
							outM = fopen("raster.txt","w");
							// wirte to file the metabolites in range for anaylsis
							for (unsigned int cv = 0; cv <raster.size(); cv++)
							{
								fprintf(outM, "%f",raster[cv]);
								if (cv <=(raster.size()-1))
								{
									fprintf(outM, "\n");
								}
							}
							fclose(outM);*/
							
							
							ms.raster_setup(abs(c3[it][1]-c3[it][0]), &raster);
						} else {
							printf("Wrong ppm ranges for raster (-2) in J_constant, exiting ...\n");
							system("PAUSE");
							exit(1);
						}
						templa.add_multiplet(ms);
						
					} else {
Esempio n. 7
0
void Sputnik::Launch()
{
    cout << "starting RhoToolsTest" << endl;
    
    // the tests are organized as blocks to let variables
    // go out of scope.  In the output, each block is 
    // separated by a lines of ----
    
    
    // start testing OpAdd4
    
    ostream& theStream = cerr; 
    theStream  <<  "Before Testing OpAdd4 " << endl;
    theStream << endl;
    
    
    TOpAdd4 b4;
    {
	cout << "create a pair of objects:" << endl;
	TCandidate c1(TLorentzVector(1,0,0,0),0);
	TCandidate c2(TLorentzVector(0,2,0,0),0);
	TCandidate c3(TLorentzVector(0,0,3,0),0);
	PC("c1",c1);
	PC("c2",c2);
	PC("c3",c3);
	
	cout << "after OpAdd4.Fill(c3, c1, c2); "<<endl;
	b4.Fill(c3,c1,c2);
	PC("c1",c1);
	PC("c2",c2);
	PC("c3",c3);
	
	TCandidate c4(TLorentzVector(0,0,3,0),0);
	cout <<endl<< "c4(); c4 = OpAdd4().combine( c1, c2); "<<endl;
	c4 = TOpAdd4().Combine(c1,c2);
	PC("c1",c1);
	PC("c2",c2);
	PC("c3",c3);
	PC("c4",c4);
	
	cout << "---------------------------------------------------"<<endl;
    }
    
    {
	cout << "create objects:" << endl;
	TCandidate c1(TLorentzVector(1,0,0,0),0);
	TCandidate c2(TLorentzVector(0,2,0,0),0);
	TCandidate c3(TLorentzVector(0,0,3,0),0);
	TCandidate c4(TLorentzVector(0,0,0,4),0);
	PC("c1",c1);
	PC("c2",c2);
	PC("c3",c3);
	PC("c4",c4);
	
	cout <<endl<< "OpAdd4.Fill(c4,c1,c2,c3); "<<endl;
	b4.Fill(c4,c3,c2,c1);
	PC("c1",c1);
	PC("c2",c2);
	PC("c3",c3);
	PC("c4",c4);
	
	cout << "---------------------------------------------------"<<endl;
    }
    
    {
	cout << "create objects:" << endl;
	TCandidate c1(TLorentzVector(1,0,0,0),1);
	TCandidate c2(TLorentzVector(0,2,0,0),-1);
	TCandidate c3(TLorentzVector(0,0,3,0),0);
	TCandidate c4(TLorentzVector(0,0,0,4),0);
	TCandidate c5(TLorentzVector(0,0,0,0),5);
	TCandidate c6(TLorentzVector(0,0,0,0),6);
	TCandidate c7(TLorentzVector(0,0,0,0),7);
	PC("c1",c1);
	PC("c2",c2);
	PC("c3",c3);
	PC("c4",c4);
	PC("c5",c5);
	PC("c6",c6);
	PC("c7",c7);
	
	cout <<endl<< "after Add4::Fill(c5,c1,c2); Add4::Fill(c6,c3,c4); "<<endl;
	b4.Fill(c5,c1,c2);
	b4.Fill(c6,c3,c4);
	PC("c1",c1);
	PC("c2",c2);
	PC("c3",c3);
	PC("c4",c4);
	PC("c5",c5);
	PC("c6",c6);
	PC("c7",c7);
	
	cout <<endl<< "after Add4::Fill(c7,c5,c6); "<<endl;
	b4.Fill(c7,c5,c6);
	PC("c1",c1);
	PC("c2",c2);
	PC("c3",c3);
	PC("c4",c4);
	PC("c5",c5);
	PC("c6",c6);
	PC("c7",c7);
	
	// do some additional checks of copying, etc
	cout <<endl<< "after c8(c7);"<<endl;
	TCandidate c8(c7);
	PC("c1",c1);
	PC("c2",c2);
	PC("c3",c3);
	PC("c4",c4);
	PC("c5",c5);
	PC("c6",c6);
	PC("c7",c7);
	PC("c8",c8);
	
	cout <<endl<< "create c9(c1); then c9 = c7;"<<endl;
	TCandidate c9(c1); c9 = c7;
	PC("c1",c1);
	PC("c2",c2);
	PC("c3",c3);
	PC("c4",c4);
	PC("c5",c5);
	PC("c6",c6);
	PC("c7",c7);
	PC("c8",c8);
	PC("c9",c9);
	
	cout <<endl<< "c9 = c5;"<<endl;
	c9 = c5;
	PC("c1",c1);
	PC("c2",c2);
	PC("c3",c3);
	PC("c4",c4);
	PC("c5",c5);
	PC("c6",c6);
	PC("c7",c7);
	PC("c8",c8);
	PC("c9",c9);
	
	cout << endl;
	cout << "testing Overlaps:"<<endl;
	cout << "c1 and c2: "<<(c1.Overlaps(c2)?"t":"f")<<endl;
	cout << "c9 and c5: "<<(c9.Overlaps(c5)?"t":"f")<<endl;
	cout << "c8 and c5: "<<(c8.Overlaps(c5)?"t":"f")<<endl;
	cout << "c7 and c5: "<<(c7.Overlaps(c5)?"t":"f")<<endl;
	cout << "c6 and c5: "<<(c6.Overlaps(c5)?"t":"f")<<endl;
	cout << "c5 and c5: "<<(c5.Overlaps(c5)?"t":"f")<<endl;
	cout << "c5 and c9: "<<(c5.Overlaps(c9)?"t":"f")<<endl;
	cout << "c5 and c8: "<<(c5.Overlaps(c8)?"t":"f")<<endl;
	cout << "c5 and c7: "<<(c5.Overlaps(c7)?"t":"f")<<endl;
	cout << "c5 and c6: "<<(c5.Overlaps(c6)?"t":"f")<<endl;
	cout << "c5 and c5: "<<(c5.Overlaps(c5)?"t":"f")<<endl;
	cout << "---------------------------------------------------"<<endl;
    }
    
    //
    // start testing OpMakeTree
    
    theStream  <<  "Before Making Tree " << endl;
    theStream << endl;
    
    {
	
	cout << "Initialization of Pdt " << endl;
	//Pdt::readMCppTable("PARENT/PDT/pdt.table");
	TDatabasePDG *Pdt = TRho::Instance()->GetPDG();
	cout << "done." << endl;
	
	// now let's consider the Y(4S)
	double beamAngle  = 0.0204;
	double beamDeltaP = 9.-3.1; 
	
	TVector3 pY4S( -beamDeltaP*sin(beamAngle),0, 
	    beamDeltaP*cos(beamAngle) );
	TCandidate Y4S( pY4S, Pdt->GetParticle("Upsilon(4S)") );
	TTreeNavigator::PrintTree( Y4S );
	cout << "theta " << Y4S.P3().Theta() << endl;
	cout << "phi "   << Y4S.P3().Phi() << endl;
	
	// instanciate a Booster
	TBooster cmsBooster( &Y4S , kTRUE);
	
	// Let's imagine a photon with a certain angle in the CMS frame
	
	// a photon 
	double ePhot = 1.;
	double photAngle = 30*3.1416/180.;
	double photPhi   = 45*3.1416/180.;
	TCandidate 
	    photon( TVector3( ePhot*sin(photAngle)*cos(photPhi), ePhot*sin(photAngle)*sin(photPhi), ePhot*cos(photAngle) ), 
	    Pdt->GetParticle("gamma") );
	
	cout << endl << "The original photon in the CMS frame " << endl;
	TTreeNavigator::PrintTree( photon );
	cout << "theta " << photon.P3().Theta() << endl;
	cout << "phi "   << photon.P3().Phi() << endl;
	
	// the same photon in the LAB frame :
	TCandidate boostedPhoton = cmsBooster.BoostFrom( photon );
	TLorentzVector theLabP4 = cmsBooster.BoostedP4( photon, TBooster::From );
	cout << "the lab Four-Vector (" << 
	    theLabP4.X() << "," << theLabP4.Y() << "," << theLabP4.Z() << ";" << theLabP4.E() << ")" << endl;
	cout << endl << "The lab boosted photon " << endl;
	TTreeNavigator::PrintTree( boostedPhoton );
	cout << "theta " << boostedPhoton.P3().Theta() << endl;
	cout << "phi "   << boostedPhoton.P3().Phi() << endl;
	
	// now boost back in the CMS frame
	TLorentzVector theP4 = cmsBooster.BoostedP4( boostedPhoton, TBooster::To );
	cout << "the Four-Vector in CMS frame (" << 
	    theP4.X() << "," << theP4.Y() << "," << theP4.Z() << ";" << theP4.E() << ")" << endl;
	cout << " from cand :    (" << 
	    photon.P4().X() << "," << photon.P4().Y() << "," << photon.P4().Z() << ";" <<photon.P4().E() << ")" << endl;
	
	
	double mPsi = Pdt->GetParticle("J/psi")->Mass();
	double mMu  = Pdt->GetParticle("mu+")->Mass();
	double mPi  = Pdt->GetParticle("pi+")->Mass();
	double mK   = Pdt->GetParticle("K+")->Mass();
	double mB   = Pdt->GetParticle("B+")->Mass();
	double mDst = Pdt->GetParticle("D*+")->Mass();
	double mD0  = Pdt->GetParticle("D0")->Mass();
	double mRho = Pdt->GetParticle("rho+")->Mass();
	
	//
	// Let's start with a simple example   :  B+ -> J/Psi K+
	//
	
	// muons in the J/Psi frame
	double E(0.), P(0.), th(0.), ph(0.);
	TVector3 p3;
	
	th = 0.3;
	ph = 1.3;
	P  = 0.5*sqrt( pow(mPsi,2) - 4*pow(mMu,2) );
	E  = sqrt( pow(mMu,2) + pow(P,2) );
	p3 = TVector3( sin(th)*cos(ph)*P, sin(th)*sin(ph)*P, cos(th)*P );
	
	TLorentzVector mu1P4(  p3, E );
	TLorentzVector mu2P4( -p3, E );
	
	// J/psi in the B frame
	th = 1.1;
	ph = 0.5;
	P = 0.5*sqrt((pow(mB,2)-pow(mPsi-mK,2))*(pow(mB,2)-pow(mPsi+mK,2)))/mB;
	p3 = TVector3( sin(th)*cos(ph)*P, sin(th)*sin(ph)*P, cos(th)*P );
	E = sqrt( pow(mPsi,2) + pow(P,2) ); 
	TVector3 boostVector( p3.X()/E, p3.Y()/E,p3.Z()/E );
	mu1P4.Boost( boostVector );
	mu2P4.Boost( boostVector );
	E = sqrt( pow(mK,2) + pow(P,2) ); 
	TLorentzVector KP4( -p3, E );
	
	// create the TCandidates
	TCandidate* mu1 = new TCandidate( mu1P4.Vect(), Pdt->GetParticle("mu+") );
	TCandidate* mu2 = new TCandidate( mu2P4.Vect(), Pdt->GetParticle("mu-") );
	TCandidate* K   = new TCandidate( KP4.Vect(), Pdt->GetParticle("K+") );
	
	// now create the Make Tree operator
	TOpMakeTree op;
	
	// now create the J/Psi
	TCandidate psi = op.Combine( *mu1, *mu2 );
	psi.SetType( "J/psi" );
	psi.SetMassConstraint();
	
	cout << endl << "The original psi " << endl;
	TTreeNavigator::PrintTree( psi );
	
	// now create the B+
	TCandidate B = op.Combine( psi, *K );
	B.SetType( "B+" );
	B.SetMassConstraint();
	
	cout << endl << "The B " << endl;
	TTreeNavigator::PrintTree( B );
	
	// create a TTreeNavigator
	TTreeNavigator treeNavigator( B );
	TTreeNavigator::PrintTree( psi );
	
	theStream << "After tree making" << endl;
	theStream << endl;
	
	//instanciate the fitter with the B Candidate
	VAbsFitter* fitter = new TDummyFitter( psi );
	
	theStream << "After fitter construction " << endl;
	theStream << endl;
	
	// get the "fitted" TCandidates
	TCandidate fittedPsi = fitter->GetFitted( psi );
	TTreeNavigator::PrintTree( fittedPsi );
	
	TCandListIterator iterDau =  psi.DaughterIterator();
	TCandidate* dau=0;
	while( dau=iterDau.Next() )
	{
	    TCandidate fittedDau = fitter->GetFitted( *dau );
	    TTreeNavigator::PrintTree( fittedDau );
	}
	
	delete fitter;
	
	fitter = new TDummyFitter( B );
	
	// get the "fitted" TCandidates
	TCandidate fittedB = fitter->GetFitted( B );
	TTreeNavigator::PrintTree( fittedB );
	
	iterDau.Rewind();
	dau=0;
	while( dau=iterDau.Next() )
	{
	    TCandidate fittedDau = fitter->GetFitted( *dau );
	    TTreeNavigator::PrintTree( fittedDau );
	}
	
	TCandidate hello = fitter->GetFitted( psi );
	TTreeNavigator::PrintTree( hello );
	
	delete fitter;
	
	theStream << "After fitter deletion " << endl;
	theStream << endl;
	
	// first let's boost the kaon
	TCandidate boostedKaon = cmsBooster.BoostTo( *K );
	cout << endl << "The boosted Kaon " << endl;
	TTreeNavigator::PrintTree( *K );
	
	// let's boost the psi
	TCandidate boostedPsi = cmsBooster.BoostTo( psi );
	cout << endl << "The boosted Psi " << endl;
	TTreeNavigator::PrintTree( boostedPsi );
	
	
	theStream << "before tree boosting " << endl;
	theStream << endl;
	
	// now let's boost the B in the Y4S frame
	TCandidate boostedB = cmsBooster.BoostTo( B );
	
	// let's see the tree
	cout << endl << "The boosted B " << endl;
	TTreeNavigator::PrintTree( boostedB );
	
	theStream << "after tree boosting " << endl;
	theStream << endl;
	
	// now let's boost a list
	TCandList theList;
	theList.Add( psi );
	theList.Add( *K );
	theList.Add( B );
	TCandList theBoostedList;
	cmsBooster.BoostTo( theList, theBoostedList );
	TCandListIterator iter(theBoostedList);
	TCandidate* c(0);
	while( c=iter.Next() )
	{
	    cout << "boosted cand " << c->PdtEntry()->GetName() << endl;
	    TTreeNavigator::PrintTree( *c );
	}
	
	
	theBoostedList.Cleanup();
	
	PrintAncestors( *mu1 );
	
	delete mu1;
	delete mu2;
	delete K;
	
	cout << "---------------------------------------------------"<<endl;
     }
     
     theStream  <<  "At the end of the test program " << endl;
     theStream << endl;
}
Esempio n. 8
0
int test0 (void) {
int ret = 0;

	printf ("TEST: CBString constructor\n");

	try {
		printf ("\tCBString c;\n");
		CBString c0;
		ret += (0 != c0.length());
		ret += '\0' != ((const char *)c0)[c0.length()];

		printf ("\tCBString c(\"test\");\n");
		CBString c1 ("test");
		ret += (c1 != "test");
		ret += '\0' != ((const char *)c1)[c1.length()];

		printf ("\tCBString c(25, \"test\");\n");
		CBString c8 (25, "test");
		ret += (c8 != "test");
		ret += c8.mlen < 25;
		ret += '\0' != ((const char *)c8)[c8.length()];

		printf ("\tCBString c('t');\n");
		CBString c2 ('t');
		ret += (c2 != "t");
		ret += '\0' != ((const char *)c2)[c2.length()];

		printf ("\tCBString c('\\0');\n");
		CBString c3 ('\0');
		ret += (1 != c3.length()) || ('\0' != c3[0]);
		ret += '\0' != ((const char *)c3)[c3.length()];

		printf ("\tCBString c(bstr[\"test\"]);\n");
		struct tagbstring t = bsStatic ("test");
		CBString c4 (t);
		ret += (c4 != t.data);
		ret += '\0' != ((const char *)c4)[c4.length()];

		printf ("\tCBString c(CBstr[\"test\"]);\n");
		CBString c5 (c1);
		ret += (c1 != c5);
		ret += '\0' != ((const char *)c5)[c5.length()];

		printf ("\tCBString c('x',5);\n");
		CBString c6 ('x',5);
		ret += (c6 != "xxxxx");
		ret += '\0' != ((const char *)c6)[c6.length()];

		printf ("\tCBString c(\"123456\",4);\n");
		CBString c7 ((void *)"123456",4);
		ret += (c7 != "1234");
		ret += '\0' != ((const char *)c7)[c7.length()];
	}

	catch (struct CBStringException err) {
		printf ("Exception thrown [%d]: %s\n", __LINE__, err.what());
		ret ++;
	}

	printf ("\t# failures: %d\n", ret);
	return ret;
}
Esempio n. 9
0
int main()
{
   // check that it'll find nodes exactly MAX away
   {
      tree_type exact_dist(std::ptr_fun(tac));
        triplet c0(5, 4, 0);
        exact_dist.insert(c0);
        triplet target(7,4,0);

      std::pair<tree_type::const_iterator,double> found = exact_dist.find_nearest(target,2);
      assert(found.first != exact_dist.end());
      assert(found.second == 2);
      std::cout << "Test find_nearest(), found at exact distance away from " << target << ", found " << *found.first << std::endl;
   }

   {
      tree_type exact_dist(std::ptr_fun(tac));
        triplet c0(5, 2, 0);
        exact_dist.insert(c0);
        triplet target(7,4,0);

        // call find_nearest without a range value - it found a compile error earlier.
      std::pair<tree_type::const_iterator,double> found = exact_dist.find_nearest(target);
      assert(found.first != exact_dist.end());
      std::cout << "Test find_nearest(), found at exact distance away from " << target << ", found " << *found.first << " @ " << found.second << " should be " << sqrt(8) << std::endl;
      assert(found.second == sqrt(8));
   }

   {
      tree_type exact_dist(std::ptr_fun(tac));
        triplet c0(5, 2, 0);
        exact_dist.insert(c0);
        triplet target(7,4,0);

      std::pair<tree_type::const_iterator,double> found = exact_dist.find_nearest(target,sqrt(8));
      assert(found.first != exact_dist.end());
      std::cout << "Test find_nearest(), found at exact distance away from " << target << ", found " << *found.first << " @ " << found.second << " should be " << sqrt(8) << std::endl;
      assert(found.second == sqrt(8));
   }

  tree_type src(std::ptr_fun(tac));

  triplet c0(5, 4, 0); src.insert(c0);
  triplet c1(4, 2, 1); src.insert(c1);
  triplet c2(7, 6, 9); src.insert(c2);
  triplet c3(2, 2, 1); src.insert(c3);
  triplet c4(8, 0, 5); src.insert(c4);
  triplet c5(5, 7, 0); src.insert(c5);
  triplet c6(3, 3, 8); src.insert(c6);
  triplet c7(9, 7, 3); src.insert(c7);
  triplet c8(2, 2, 6); src.insert(c8);
  triplet c9(2, 0, 6); src.insert(c9);

  std::cout << src << std::endl;

  src.erase(c0);
  src.erase(c1);
  src.erase(c3);
  src.erase(c5);

  src.optimise();


  // test the efficient_replace_and_optimise()
  tree_type eff_repl = src;
  {
     std::vector<triplet> vec;
     // erased above as part of test vec.push_back(triplet(5, 4, 0));
     // erased above as part of test vec.push_back(triplet(4, 2, 1));
     vec.push_back(triplet(7, 6, 9));
     // erased above as part of test vec.push_back(triplet(2, 2, 1));
     vec.push_back(triplet(8, 0, 5));
     // erased above as part of test vec.push_back(triplet(5, 7, 0));
     vec.push_back(triplet(3, 3, 8));
     vec.push_back(triplet(9, 7, 3));
     vec.push_back(triplet(2, 2, 6));
     vec.push_back(triplet(2, 0, 6));

     eff_repl.clear();
     eff_repl.efficient_replace_and_optimise(vec);
  }


  std::cout << std::endl << src << std::endl;

  tree_type copied(src);
  std::cout << copied << std::endl;
  tree_type assigned;
  assigned = src;
  std::cout << assigned << std::endl;

  for (int loop = 0; loop != 4; ++loop)
    {
      tree_type * target;
      switch (loop)
	{
	case 0: std::cout << "Testing plain construction" << std::endl;
	  target = &src;
	  break;

	case 1: std::cout << "Testing copy-construction" << std::endl;
	  target = &copied;
	  break;

	case 2: std::cout << "Testing assign-construction" << std::endl;
	  target = &assigned;
	  break;

   default:
	case 4: std::cout << "Testing efficient-replace-and-optimise" << std::endl;
	  target = &eff_repl;
	  break;
	}
      tree_type & t = *target;

      int i=0;
      for (tree_type::const_iterator iter=t.begin(); iter!=t.end(); ++iter, ++i);
      std::cout << "iterator walked through " << i << " nodes in total" << std::endl;
      if (i!=6)
	{
	  std::cerr << "Error: does not tally with the expected number of nodes (6)" << std::endl;
	  return 1;
	}
      i=0;
      for (tree_type::const_reverse_iterator iter=t.rbegin(); iter!=t.rend(); ++iter, ++i);
      std::cout << "reverse_iterator walked through " << i << " nodes in total" << std::endl;
      if (i!=6)
	{
	  std::cerr << "Error: does not tally with the expected number of nodes (6)" << std::endl;
	  return 1;
	}

      triplet s(5, 4, 3);
      std::vector<triplet> v;
      unsigned int const RANGE = 3;

      size_t count = t.count_within_range(s, RANGE);
      std::cout << "counted " << count
		<< " nodes within range " << RANGE << " of " << s << ".\n";
      t.find_within_range(s, RANGE, std::back_inserter(v));

      std::cout << "found   " << v.size() << " nodes within range " << RANGE
		<< " of " << s << ":\n";
      std::vector<triplet>::const_iterator ci = v.begin();
      for (; ci != v.end(); ++ci)
	std::cout << *ci << " ";
      std::cout << "\n" << std::endl;

      std::cout << std::endl << t << std::endl;

      // search for all the nodes at exactly 0 dist away
      for (tree_type::const_iterator target = t.begin(); target != t.end(); ++target)
      {
         std::pair<tree_type::const_iterator,double> found = t.find_nearest(*target,0);
         assert(found.first != t.end());
         assert(*found.first == *target);
         std::cout << "Test find_nearest(), found at exact distance away from " << *target << ", found " << *found.first << std::endl;
      }

      {
         const double small_dist = 0.0001;
         std::pair<tree_type::const_iterator,double> notfound = t.find_nearest(s,small_dist);
         std::cout << "Test find_nearest(), nearest to " << s << " within " << small_dist << " should not be found" << std::endl;

         if (notfound.first != t.end())
         {
            std::cout << "ERROR found a node at dist " << notfound.second << " : " << *notfound.first << std::endl;
            std::cout << "Actual distance = " << s.distance_to(*notfound.first) << std::endl;
         }

         assert(notfound.first == t.end());
      }

      {
         std::pair<tree_type::const_iterator,double> nif = t.find_nearest_if(s,std::numeric_limits<double>::max(),Predicate());
         std::cout << "Test find_nearest_if(), nearest to " << s << " @ " << nif.second << ": " << *nif.first << std::endl;

         std::pair<tree_type::const_iterator,double> cantfind = t.find_nearest_if(s,std::numeric_limits<double>::max(),FalsePredicate());
         std::cout << "Test find_nearest_if(), nearest to " << s << " should never be found (predicate too strong)" << std::endl;
         assert(cantfind.first == t.end());
      }




      {
      std::pair<tree_type::const_iterator,double> found = t.find_nearest(s,std::numeric_limits<double>::max());
      std::cout << "Nearest to " << s << " @ " << found.second << " " << *found.first << std::endl;
      std::cout << "Should be " << found.first->distance_to(s) << std::endl;
      // NOTE: the assert does not check for an exact match, as it is not exact when -O2 or -O3 is
      // switched on.  Some sort of optimisation makes the math inexact.
      assert( fabs(found.second - found.first->distance_to(s)) < std::numeric_limits<double>::epsilon() );
      }

      {
      triplet s2(10, 10, 2);
      std::pair<tree_type::const_iterator,double> found = t.find_nearest(s2,std::numeric_limits<double>::max());
      std::cout << "Nearest to " << s2 << " @ " << found.second << " " << *found.first << std::endl;
      std::cout << "Should be " << found.first->distance_to(s2) << std::endl;
      // NOTE: the assert does not check for an exact match, as it is not exact when -O2 or -O3 is
      // switched on.  Some sort of optimisation makes the math inexact.
      assert( fabs(found.second - found.first->distance_to(s2)) < std::numeric_limits<double>::epsilon() );
      }

      std::cout << std::endl;

      std::cout << t << std::endl;

      // Testing iterators
      {
	std::cout << "Testing iterators" << std::endl;

	t.erase(c2);
	t.erase(c4);
	t.erase(c6);
	t.erase(c7);
	t.erase(c8);
	//    t.erase(c9);

	std::cout << std::endl << t << std::endl;

	std::cout << "Forward iterator test..." << std::endl;
	std::vector<triplet> forwards;
	for (tree_type::iterator i = t.begin(); i != t.end(); ++i)
	  { std::cout << *i << " " << std::flush; forwards.push_back(*i); }
	std::cout << std::endl;
	std::cout << "Reverse iterator test..." << std::endl;
	std::vector<triplet> backwards;
	for (tree_type::reverse_iterator i = t.rbegin(); i != t.rend(); ++i)
	  { std::cout << *i << " " << std::flush; backwards.push_back(*i); }
	std::cout << std::endl;
	std::reverse(backwards.begin(),backwards.end());
	assert(backwards == forwards);
      }
    }

  return 0;
}
Esempio n. 10
0
int main(int argc, char* argv[])
{
  Polycurve_conic_traits_2 traits;
    //polycurve constructors
  Polycurve_conic_traits_2::Construct_x_monotone_curve_2
    construct_x_mono_polycurve = traits.construct_x_monotone_curve_2_object();
  Polycurve_conic_traits_2::Construct_curve_2  construct_polycurve =
    traits.construct_curve_2_object();

   //create a curve

  Conic_curve_2 c3(1,0,0,0,-1,0,CGAL::COUNTERCLOCKWISE,
                   Conic_point_2(Algebraic(0), Algebraic(0)),
                   Conic_point_2(Algebraic(3), Algebraic(9)));
  Conic_curve_2 c4(1,0,0,0,-1,0,CGAL::COUNTERCLOCKWISE,
                   Conic_point_2(Algebraic(3), Algebraic(9)),
                   Conic_point_2(Algebraic(5), Algebraic(25)));
  Conic_curve_2 c5(0,1,0,1,0,0, CGAL::COUNTERCLOCKWISE,
                   Conic_point_2(Algebraic(-25), Algebraic(-5)),
                   Conic_point_2(Algebraic(0), Algebraic(0)));

  Conic_curve_2 c6(1,1,0,6,-26,162,CGAL::COUNTERCLOCKWISE,
                   Conic_point_2(Algebraic(-7), Algebraic(13)),
                   Conic_point_2(Algebraic(-3), Algebraic(9)));
  Conic_curve_2 c7(1,0,0,0,-1,0,CGAL::COUNTERCLOCKWISE,
                   Conic_point_2(Algebraic(-3), Algebraic(9)),
                   Conic_point_2(Algebraic(0), Algebraic(0)));
  Conic_curve_2 c8(0,1,0,-1,0,0, CGAL::COUNTERCLOCKWISE,
                   Conic_point_2(Algebraic(0), Algebraic(0)),
                   Conic_point_2(Algebraic(4), Algebraic(-2)));

  Conic_curve_2 c9(1,0,0,0,-1,0,CGAL::COUNTERCLOCKWISE,
                   Conic_point_2(Algebraic(-5), Algebraic(25)),
                   Conic_point_2(Algebraic(5), Algebraic(25)));
  Conic_curve_2 c10(58, 72, -48, 0, 0, -360);

  //This vector is used to store curves that will be used to create polycurve
  std::vector<Conic_curve_2> conic_curves;
  conic_curves.push_back(c9);

  //construct poly-curve
  Polycurve_conic_traits_2::Curve_2 conic_polycurve =
    construct_polycurve(conic_curves.begin(), conic_curves.end());

  Conic_curve_2 c11(0,1,0,-1,0,0,CGAL::COUNTERCLOCKWISE,
                     Conic_point_2(Algebraic(25), Algebraic(-5)),
                     Conic_point_2(Algebraic(0), Algebraic(0)));
  Conic_curve_2 c12(1,0,0,0,-1,0,CGAL::COUNTERCLOCKWISE,
                     Conic_point_2(Algebraic(0), Algebraic(0)),
                     Conic_point_2(Algebraic(5), Algebraic(25)));
  conic_curves.clear();
  conic_curves.push_back(c11);
  conic_curves.push_back(c12);

  //construct poly-curve
  Polycurve_conic_traits_2::Curve_2 conic_polycurve_2 =
    construct_polycurve(conic_curves.begin(), conic_curves.end());

  /* VERY IMPORTANT
   * For efficiency reasons, we recommend users not to construct
   * x-monotone conic arc directly, but rather use the Make_x_monotone_2
   * functor supplied by the conic-arc traits class to convert conic curves
   * to x-monotone curves.
   */
  Conic_x_monotone_curve_2 xc3(c3);
  Conic_x_monotone_curve_2 xc4(c4);
  Conic_x_monotone_curve_2 xc5(c5);
  Conic_x_monotone_curve_2 xc6(c6);
  Conic_x_monotone_curve_2 xc7(c7);
  Conic_x_monotone_curve_2 xc8(c8);


  //This vector is used to store curves that will be used to create
  //X-monotone-polycurve
  std::vector<Conic_x_monotone_curve_2> xmono_conic_curves_2;
  xmono_conic_curves_2.push_back(xc5);
  xmono_conic_curves_2.push_back(xc3);
  xmono_conic_curves_2.push_back(xc4);


  //construct x-monotone poly-curve
  Pc_x_monotone_curve_2 conic_x_mono_polycurve_1 =
    construct_x_mono_polycurve(xmono_conic_curves_2.begin(),
                               xmono_conic_curves_2.end());

  xmono_conic_curves_2.clear();
  xmono_conic_curves_2.push_back(xc6);
  xmono_conic_curves_2.push_back(xc7);
  xmono_conic_curves_2.push_back(xc8);
  //construct x-monotone poly-curve
  Pc_x_monotone_curve_2 conic_x_mono_polycurve_2 =
    construct_x_mono_polycurve(xmono_conic_curves_2.begin(),
                               xmono_conic_curves_2.end());

  xmono_conic_curves_2.clear();
  xmono_conic_curves_2.push_back(xc5);

  Pc_x_monotone_curve_2 x_polycurve_push =
    construct_x_mono_polycurve(xmono_conic_curves_2.begin(),
                               xmono_conic_curves_2.end());
  Polycurve_conic_traits_2::X_monotone_subcurve_2 xcurve_push =
    Polycurve_conic_traits_2::X_monotone_subcurve_2(c5);
  //traits.construct_x_monotone_curve_2_object()(c5);

  xmono_conic_curves_2.clear();
  xmono_conic_curves_2.push_back(xc3);
  xmono_conic_curves_2.push_back(xc4);
  Pc_x_monotone_curve_2 base_curve =
    construct_x_mono_polycurve(xmono_conic_curves_2.begin(),
                               xmono_conic_curves_2.end());

  //curves for push_back
  Conic_curve_2 c13(1,1,0,-50,12,660,CGAL::COUNTERCLOCKWISE,
                    Conic_point_2(Algebraic(25), Algebraic(-7)),
                    Conic_point_2(Algebraic(25), Algebraic(-5)));
  Conic_curve_2 c14(0,1,0,-1,0,0,CGAL::COUNTERCLOCKWISE,
                    Conic_point_2(Algebraic(25), Algebraic(-5)),
                    Conic_point_2(Algebraic(0), Algebraic(0)));
  Conic_curve_2 c15(-1,0,0,0,1,0,CGAL::COUNTERCLOCKWISE,
                    Conic_point_2(Algebraic(0), Algebraic(0)),
                    Conic_point_2(Algebraic(5), Algebraic(25)));
  conic_curves.clear();
  conic_curves.push_back(c13);
  conic_curves.push_back(c14);
  Polycurve_conic_traits_2::Curve_2 base_curve_push_back =
    construct_polycurve(conic_curves.begin(), conic_curves.end());

  conic_curves.push_back(c15);
  Polycurve_conic_traits_2::Curve_2 Expected_push_back_result =
    construct_polycurve(conic_curves.begin(), conic_curves.end());

  // //checking the orientattion consistency
  // Conic_curve_2 c21(0,1,0,1,0,0,CGAL::CLOCKWISE,
  //                  Conic_point_2(Algebraic(9), Algebraic(-3)),
  //                  Conic_point_2(Algebraic(0), Algebraic(0)));
  // Conic_curve_2 c20(1,0,0,0,-1,0,CGAL::COUNTERCLOCKWISE,
  //                   Conic_point_2(Algebraic(0), Algebraic(0)),
  //                   Conic_point_2(Algebraic(3), Algebraic(9)));
  //  Conic_x_monotone_curve_2 xc20(c20);
  //  Conic_x_monotone_curve_2 xc21(c21);
  //  xmono_conic_curves_2.clear();
  //  xmono_conic_curves_2.push_back(xc20);
  // xmono_conic_curves_2.push_back(xc21);
  // Pc_x_monotone_curve_2 eric_polycurve =
  //   construct_x_mono_polycurve(xmono_conic_curves_2.begin(),
  //                              xmono_conic_curves_2.end());
  // std::cout << "the polycurve is: " << eric_polycurve << std::endl;

  // std::cout<< std::endl;

  //check_compare_x_2(xc3, xc5);

  // check_equal();
  // std::cout<< std::endl;

   //check_intersect(conic_x_mono_polycurve_1, conic_x_mono_polycurve_2);
   //std::cout<< std::endl;

  // check_compare_end_points_xy_2();
  // std::cout<< std::endl;

  //check_split(conic_x_mono_polycurve_1, conic_x_mono_polycurve_2);
  // std::cout<< std::endl;

  //check_make_x_monotne_curve(conic_polycurve_2);
   //std::cout<< std::endl;

  // check_is_vertical();
  // std::cout<< std::endl;

  //check_compare_y_at_x_2();
  //std::cout<< std::endl;

  //adds the segment to the right.
  //check_push_back(base_curve_push_back, c15);
  //std::cout<< std::endl;

  //adds the segment to the left.
  //check_push_front(base_curve, xcurve_push);
  //std::cout<< std::endl;

  // check_are_mergable();
  // std::cout<< std::endl;

  // check_merge_2();
  // std::cout<< std::endl;

  // check_construct_opposite();
  // std::cout<< std::endl;

  // check_compare_y_at_x_right();
  // std::cout<< std::endl;

  // check_compare_y_at_x_left();
  // std::cout<< std::endl;
  //check_compare_points(conic_x_mono_polycurve_1);

  //number of segments
  //std::cout << "Number of segments: "
  //          << traits.number_of_points_2_object()(base_curve_push_back)
  //          << std::endl;

  check_trim(conic_x_mono_polycurve_1, atoi(argv[1]), atoi(argv[2]),
             atoi(argv[3]), atoi(argv[4]));
  std::cout << std::endl;

  //std::cout << (atoi(argv[1]) + atoi(argv[2])) << std::endl;
  // Conic_traits_2 con_traits;
  // Conic_curve_2 cc3(1,0,0,0,-1,0,CGAL::COUNTERCLOCKWISE,
  //                   Conic_point_2(Algebraic(0), Algebraic(0)),
  //                   Conic_point_2(Algebraic(3), Algebraic(9)));
  // Conic_x_monotone_curve_2 xcc3(cc3);
  // Conic_point_2       ps2(0, 0);
  // Conic_point_2       pt2(3, 9);
  // std::cout << "conic curve is : " << xcc3 << std::endl;
  // Conic_x_monotone_curve_2 trimmed_curve =
  //   con_traits.trim_2_object()(xc3, ps2, pt2);
  // std::cout << "trimmed conic curve is : " << trimmed_curve << std::endl;

  return 0;
}
int main()
{
    tQ4 a4( 1.1 );
    tQ4 b4( 1 );
    tQ12 a12( 3.3 );
    tQ12 b12( 3 );
    tQ18 a18;
    double ad;
    double bd;
    
    tQ8 a8( -2.3 );
    tQ8 b8( 2 );
    tQ8 c8( Q8CONST( -2,3 ) );
    tQ8 d8( a8 );
    tQ8 e8( a4 );
//  tQ8 f8( a12 );      // Warning: left shift count is negative
    tQ8 g8( a12.roundedTo< tQ8 >() );
    tQ8 h8( a12.roundedTo< 8 >() );
    
//  a8 = a4.roundedTo( h8 );  //Warning: left/right shift is negative
    
    a8 = 1;
    a8 = -2;
    a8 = 3;
    a8 = Q8CONST( 3,001 );
    a8 = tQ8( 3.001 );
    a8 = tQ8::truncated( 3.001 );
    a8 = tQ8::rounded( 3.001 );
    a8.setTruncated( 3.2 );
    a8.setRounded( 3.3 );
    a8 = tQ8( 123, 8 );
    a8 = tQ8::create( 123 << 8 );
    
    a8 = a4;
    a8 = a8;
//  a8 = a12;          // Warning: left shift count is negative
    a8 = a12.roundedTo< tQ8 >();
    a8 = a12.roundedTo( a8 );
    a8.setRounded( a12 );
    a8 = -a4;
    a8 = -a8;

    a8 += 3;
    a8 += 4u;
    a8 += 5l;
    a8 += 6lu;
    a8 += tQ8( 3.2 );
    a8 += truncatedTo( a8, 3.3 );
    a8 += roundedTo( a8, 3.4 );
    a8 += a4;
//  a8 += a12;          // Warning: left shift count is negative
    a8 += a12.roundedTo< tQ8 >();
    a8 += a12.roundedTo( a8 );
    a8 = a8 + 2;
    a8 = 3 + a8;
    a8 = a8 + a4;
//  a8 = a4 + a8;       // Warning: left shift count is negative
    
    a8 -= 3;
    a8 -= 4u;
    a8 -= 5l;
    a8 -= 6lu;
    a8 -= roundedTo< tQ8::cQBits >( 3.2 );
    a8 -= roundedTo( a8, 3.3 );
    a8 -= a4;
//  a8 -= a12;          // Warning: left shift count is negative
    a8 -= a12.roundedTo< tQ8 >();
    a8 -= a12.roundedTo( a8 );
    a8 = a8 - 2;
    a8 = 3 - a8;
    a8 = a8 - a4;
//  a8 = a4 - a8;       // Warning: left shift count is negative
    
    a8 *= 3;
    a8 *= 4u;
    a8 *= 5l;
    a8 *= 6lu;
//  a8 *= 3.2;          // Warning: converting to int from double
    a8 *= a4;
    a8 *= a12;
    a8 = a8 * 2;
    a8 = 3 * a8;
    a12 = a8 * a4;
    a12 = a4 * a8;
    
    a8 /= 3;
    a8 /= 4u;
    a8 /= 5l;
    a8 /= 6lu;
//  a8 /= 3.2;          // Warning: converting to int from double
    a8 /= a4;           // Note: possible overflow due to pre-shifting "(a8 << 4) / a4"
//  a8 /= a12;          // Warning: left shift count is negative
    a8 = a8.increasedBy( a12 ) / a12;
    a8 = a8 / 2;
//  a8 = 3 / a8;        // Error: no match for 'operator/'
    a8 = tQ16( 3 ) / a8;
    a12 = a8 / a4;
    a12 = a4 / a8;
    
    a8 == 3;
    a8 == 4u;
    a8 == 5l;
    a8 == 6lu;
    a8 == tQ8( 3.2 );
    a8 == truncatedTo( a8, 3.3 );
    a8 == roundedTo( a8, 3.4 );
    a8 == a4;
//  a8 == a12;          // Warning: left shift count is negative
    a8 == a12.roundedTo< tQ8 >();
    a8 == a12.roundedTo( a8 );
    3 == a8;
    int(4u) == a8;
    int(5l) == a8;
    int(6lu) == a8;
    
    a8 < 3;
    a8 < 4u;
    a8 < 5l;
    a8 < 6lu;
    a8 < tQ8( 3.2 );
    a8 < a4;
//  a8 < a12;          // Warning: left shift count is negative
    3 < a8;
    int(4u) < a8;
    int(5l) < a8;
    int(6lu) < a8;
    
    a8 > 3;
    a8 > 4u;
    a8 > 5l;
    a8 > 6lu;
    a8 > tQ8( 3.2 );
    a8 > a4;
//  a8 > a12;          // Warning: left shift count is negative
    3 > a8;
    int(4u) > a8;
    int(5l) > a8;
    int(6lu) > a8;
    
    !a8;
    int intPart = a8.intPart();
    int fracPart = a8.fracPart();
    int fracPlaces = a8.fracPlaces( 3 );
    unsigned abs = a8.absolute();

    ad = a8.toDouble();
    a8 = ad;
//  a8.set( ad );    // Warning: conversion from int to double, possible loss of data
    a8.setRounded( ad );
    a8 = truncatedTo( a8, ad );
    a8 = truncatedTo<8>( ad );
    a8 = truncatedTo<tQ8>( ad );
    
//  tBigQ36 aB36( 123567890 );     // Error: ambiguous
    tBigQ36 aB36( 123567890ll );
    tBigQ36 bB36( a8 );
    
    aB36 = tBigQ18( a18 ) * a18;
}
Esempio n. 12
0
int C8 ()
{
  return c8 ();
}