Exemple #1
0
 double substitute(double x, double y) const {
   double val=0;
   for(const_iterator i(terms.begin());i!=terms.end();++i) {   
     val += i->first.substitute(x,y) * i->second;
   }
   return val;
 }
Exemple #2
0
void print_map(MAP& map) {
    std::cout << "MAP { " << std::endl;
    for (MAP::const_iterator it = map.begin(); it != map.end(); it++) {
        std::cout << it->first << " => " << it->second << std::endl;
    }
    std::cout << " }" << std::endl;
}
Exemple #3
0
Dart Topo3PrimalRender<PFP>::raySelection(MAP& map, const Geom::Vec3f& rayA, const Geom::Vec3f& rayAB, float dmax)
{
	float AB2 = rayAB*rayAB;
	Dart dFinal;
	float dm2 = dmax*dmax;
	double dist2 = std::numeric_limits<double>::max();

	for(Dart d = map.begin(); d!=map.end(); map.next(d))
	{
		// get back position of segment PQ
		const Geom::Vec3f& P = m_bufferDartPosition[m_attIndex[d]];
		const Geom::Vec3f& Q =m_bufferDartPosition[m_attIndex[d]+1];
		float ld2 = Geom::squaredDistanceLine2Seg(rayA, rayAB, AB2, P, Q);
		if (ld2 < dm2)
		{
			Geom::Vec3f V = (P+Q)/2.0f - rayA;
			double d2 = double(V*V);
			if (d2 < dist2)
			{
				dist2 = d2;
				dFinal = d;
			}
		}
	}
	return dFinal;
}
Exemple #4
0
 typename _MapT<MAP>::KeyIter
 eachMapKey (MAP& map)
 {
   typedef RangeIter<typename MAP::iterator> Range;
   
   Range contents (map.begin(), map.end());
   return wrapIter (takePairFirst (contents));
 }
Exemple #5
0
 typename _MapT<MAP>::KeyIter
 eachDistinctKey (MAP& map)
 {
   typedef RangeIter<typename MAP::iterator> Range;
   
   Range contents (map.begin(), map.end());
   return wrapIter (filterRepetitions (takePairFirst(contents)));
 }
Exemple #6
0
 typename _MapT<MAP>::ValIter
 eachMapVal (MAP& map)
 {
   typedef RangeIter<typename MAP::iterator> Range;
   
   Range contents (map.begin(), map.end());
   return wrapIter (takePairSecond(contents));
 }
void update(MAP & p , pii x){
	
	MAP::iterator it = p.lower_bound(x.F), ini = it;
	if( it != p.end() && it->F == x.F && it->S <= x.S) return;
	if( it != p.begin() && (--it)->S <= x.S) return;
	it = ini;
	while( it != p.end() && it->S >= x.S) it++;
	p.erase( ini, it);
	p[x.F] = x.S;
}
Exemple #8
0
long lcm(MAP& map) {
    long m = 1;
    for (MAP::const_iterator it = map.begin(); it != map.end(); it++) {
        long factor = it->first;
        long power = it->second;
        for (; power > 0; power--) {
            m *= factor; 
        }
    }
    return m;
}
Exemple #9
0
 static void s_listNames(MyOstream & os,
        const char * sep = "\n",const char * sep2 = "\n") {
   MAP::const_iterator w = s_map.begin(), e = s_map.end();
   if(w!=e)  {
     --e;
     while(w!=e) {
       os << (*w).first << sep; 
       ++w;
     };
     os << (*w).first << sep2;
   };
 };
Exemple #10
0
void Topo3PrimalRender<PFP>::computeDartMiddlePositions(MAP& map, DartAttribute<VEC3, MAP>& posExpl)
{
	m_vbo0->bind();
	Geom::Vec3f* positionsPtr = reinterpret_cast<Geom::Vec3f*>(glMapBuffer(GL_ARRAY_BUFFER, GL_READ_ONLY));

	for (Dart d = map.begin(); d != map.end(); map.next(d))
	{
		const Geom::Vec3f& v =(positionsPtr[m_attIndex[d]] + positionsPtr[m_attIndex[d]+1])*0.5f;
		posExpl[d] = PFP::toVec3f(v);
	}

	m_vbo0->bind();
	glUnmapBuffer(GL_ARRAY_BUFFER);
}
Exemple #11
0
 const std::string str() const {
   std::stringstream ss;
   // start with xs
   bool firstTime=true;
   for(const_iterator i(terms.begin());i!=terms.end();++i) {      
     if(!firstTime) { ss << " + "; }
     firstTime=false;
     simple_poly_term const &t(i->first);
     int count = i->second;
     if(count > 1) { ss << count; }
     ss << i->first.str();
   }
   
   return ss.str(); 
 }
void map_histogram(std::ostream &out, const MAP &map) {
  std::vector<int> hist;
  for (typename MAP::const_iterator i = map.begin(); i != map.end(); ++i) {
    size_t n = (*i).second.size();
    if (hist.size() <= n) {
      hist.resize(n + 1);
    }
    hist[n]++;
  }
  int total = map.size();
  std::string bar(50, '*');
  for (size_t i = 0; i < hist.size(); i++) {
    if (hist[i] > 0) {
      out << std::setw(5) << i << " : " << std::setw(5) << hist[i] << " " << bar.substr(50 - hist[i] * 50 / total) << std::endl;
    }
  }
}
Exemple #13
0
  // this is gary's shift operation
  void operator*=(xy_term const &p2) {
    if(p2.ypowerend == p2.ypower) {
      // I don't think the STL strictly would allow this,
      // but it doesn't hurt!      
      for(const_iterator i(terms.begin());i!=terms.end();++i) {      
	simple_poly_term &t((simple_poly_term &)i->first); // ouch ;)
	t.xpower += p2.xpower;
	t.ypower += p2.ypower;
      }
    } else {
      // recursive case (this is an ugly hack)
      simple_poly p(*this);

      for(unsigned int i=p2.ypower;i!=p2.ypowerend-1;++i) {
	*this += p;
	p *= xy_term(0,1);
      }
      
      *this += p;
    }
  }
Exemple #14
0
void Topo3PrimalRender<PFP>::updateColors(MAP& map, const VertexAttribute<VEC3, MAP>& colors)
{
	m_vbo2->bind();
	Geom::Vec3f* colorBuffer =  reinterpret_cast<Geom::Vec3f*>(glMapBuffer(GL_ARRAY_BUFFER, GL_READ_WRITE));
	unsigned int nb=0;

	for (Dart d = map.begin(); d != map.end(); map.next(d))
	{
		if (nb < m_nbDarts)
		{
			colorBuffer[m_attIndex[d]] = colors[d];
			nb++;
		}
		else
		{
			CGoGNerr << "Error buffer too small for color picking (change the selector parameter ?)" << CGoGNendl;
			break;
		}
	}
	glUnmapBuffer(GL_ARRAY_BUFFER);
}
int main(){
	MAP member;
	member.insert(make_pair(1000000000,1));		//使用strength做key关键字,因为题目已经给出了 实力值不可能相等 的条件
	int strength,id;							//也可使用id做key关键字,但这样每一次都需要完整遍历一次map,容易造成TLE
	int n;
	int low,high;
	cin >> n;
	while(n--){
		cin >> id >> strength;
		member.insert(make_pair(strength,id));
		MAP::iterator i,j,k;
		i = member.find(strength);
		if(i != member.end()){
			if(i == member.begin()){
				j = i;
				j++;
				cout << i->second << " " << j->second << endl;
			}
			else{
				j = i;
				k = i;
				j++;
				k--;
				low = i->first - k->first;
				high = j->first - i->first;
				if(low <= high){
					cout << i->second << " " << k->second << endl;
				}
				else{
					cout << i->second << " " << j->second << endl;
				}
			}
		}
		else continue;
	}
	return 0;
}
Exemple #16
0
int main()
{
    MAP table;

    string name;

    /******************************************************
* PHASE 0: Load the words in the text file *
* into a the table *
*******************************************************/

    cout << "File name? ";
    getline(cin, name);

    ifstream textFile(name.c_str());

    if (!textFile)
    {
        cerr << "Text file could not be opened!!" << endl;
        return 0;
    }

    string word;
    int nWords = 0;

    while(textFile >> word)
    {
        nWords++;
        //remove non-alpha chars
        word.erase(remove_if(word.begin(), word.end(), isNotAlpha), word.end());
        //convert to lower-case letters
        transform(word.begin(), word.end(), word.begin(), ::tolower);
        if (word == "") continue;

        ELEMENT e = make_pair(word,1);
        cout << word << endl;
        table.BST_threaded::insert(e);
    }

    textFile.close();

    /******************************************************
* PHASE 1: Display *
* - number of words in the text *
* - number of unique words (occurring only once) *
* - frequency table *
*******************************************************/
    //number of words in the text
    cout << "The number of words in the text file is: " << nWords << endl;
    cout << "Number of unique words in the file: " << table.size() << endl;

    cout << "\n\nTable sorted alphabetically:"
         << endl << endl;

    BiIterator it = table.begin();

    cout << " \tKEY" << "\tCOUNTER" << endl;
    cout << "==============================\n";
    for( ; it != table.end(); it++)
    {
         cout << setw(15) << it->first
              << setw(15) << it->second << endl;
    }


    /******************************************************
* PHASE 3: remove all words with counter 1 *
* and display table again *
*******************************************************/

    it = table.begin();
    vector<string> temp;
    for( ; it != table.end(); it++){
        if(it->second == 1){
            temp.push_back(it->first);
        }
    }
    for(int i = 0; i != temp.size(); i ++){
        table.remove(temp[i]);
    }


    cout << "Number of words after remove: " << table.size() << endl;

    cout << "Un-unique table sorted alphabetically:" << endl;

    cout << " \tKEY" << "\tCOUNTER" << endl;
    cout << "==============================\n";
    for(it = table.begin(); it != table.end(); it++) {
         cout << setw(15) << it->first
              << setw(15) << it->second << endl;
    }


    /***********************************************************
* PHASE 4: request two words to the user w1 and w2 *
* then display all words in the interval [w1,w2] *
************************************************************/
    //We assume that the words entered by the user exists in the table
    cout << "Please enter two words from the list " << endl;
    string first, last;
    cin >> first >> last;
    cout << "First: " << first << " and last: " << last << endl;
    BiIterator itr = table.find(first);
    BiIterator stop = table.find(last);
    itr--; //a dummy to include the last node
    for(stop; stop!=itr; stop--){
        cout << setw(15) << stop->first
        << setw(15) << stop->second << endl;
    }
    return 0;
}
Exemple #17
0
main(int argc,const char **argv)
{
  typedef  map<A*,A*,lessPtr<A> > MAP;
  typedef  MAP::iterator IT;

  MAP m;

  A aa(1);
  A bb(2);
  A cc(3);

  m[&aa] = &bb;
  m[&bb] = &cc;
  m[&cc] = &aa; 

  IT it;
  for(it=m.begin(); it!=m.end(); it++)
  {
     pair<A*,A*> dat = *it;
     printf("%d --> %d\n",dat.first->X,dat.second->X);
  }

//  return 0;

   const char *fname = (argc>1) ? argv[1] : "rismmol1d.prm"; 
   const char *str = readFile(fname); //distances = {(O,H1) : 1 [Angstr], (O,H2) : 1 [Angstr], (H1,H2) : 1.63[Angstr] };";
   StringParser sp(str);

   Parameters prm;
   ParseParameters pp("Bohr","Hartree",&prm);

   pp.parse(&sp);

   printf("%s\n",prm.toString());
   

   ParametersAdaptor1DRISM pa(&prm);
   pa.init();

   Matrix<Real> *dd =pa.getDistances();
   int ii,jj;
   for(ii=0;ii<dd->getNumRows();ii++)
   {
      for(jj=0;jj<dd->getNumCols();jj++)
      {
          printf("%lf ",dd->getAt(ii,jj));
      }
      printf("\n");
   }

   free((void *)str);
   return 0;

   int N = 4096;
   double dR = 0.05;
   SphericalFFT *fft = SphericalFFT::getInstance(); 
   Grid1DRISM grd(N,dR);

   Real *a = new Real[N]; 
   Real *fa = new Real[N];
   Real *b = new Real[N];
   Real *fb = new Real[N];
   Real *c = new Real[N];
   Real *fc = new Real[N];

   int i;
   for(i=0;i<N;i++) 
   { 
     a[i] = i % 20; 
     b[i] = exp(-(i*dR)*(i*dR));
   }
   
   fft->d3fft(a,fa,&grd); 
   fft->d3fft(b,fb,&grd);

   copyArray(fc,fa,N); // fc=fa
   mulArray(fc,fb,N);  // fc=fa*fb
   
   fft->d3ifft(fc,c,&grd);
   
   writeDoubleArrayToFile("a.dat",a,N);
   writeDoubleArrayToFile("fa.dat",fa,N);

   writeDoubleArrayToFile("b.dat",b,N);
   writeDoubleArrayToFile("fb.dat",fb,N);

   writeDoubleArrayToFile("c.dat",c,N);
   writeDoubleArrayToFile("fc.dat",fc,N);

   delete [] a;
   delete [] b;
   delete [] c;
   delete [] fa;
   delete [] fb;
   delete [] fc;
   

}
Exemple #18
0
 const_iterator begin() const { return terms.begin(); }
Exemple #19
0
 iterator begin() { return terms.begin(); }
Exemple #20
0
int main()
{
	// declare a map to handle the mesh
	MAP myMap;

	// add position attribute on vertices and get handler on it
	VertexAttribute<VEC3, MAP> position = myMap.addAttribute<VEC3, VERTEX, MAP>("position");

	// create a topo grid of 2x2 squares
	Algo::Surface::Tilings::Square::Grid<PFP> grid(myMap, 4, 4, true);

	// and embed it using position attribute
    grid.embedIntoGrid(position, 1.,1.,0.);

	// ALGO:
	// foreach vertex of the map
	//    print position of the vertex

	// 4 versions 	

	// low level traversal using pure topo
	DartMarker<MAP> dm(myMap);
	for (Dart d = myMap.begin(); d != myMap.end(); myMap.next(d)) // traverse all darts of map
	{
		if (!dm.isMarked(d))			// is dart not marked ?
		{
			dm.markOrbit<VERTEX>(d);	// mark all dart of vertex orbit to be sure to not traverse it again
			std::cout << d << " : " << position[d]<< " / ";
		}
	}
	std::cout << std::endl;

	// low level traversal using cell marking (use marker on embedding is available)
	CellMarker<MAP,VERTEX> cm(myMap);
	for (Dart d = myMap.begin(); d != myMap.end(); myMap.next(d))
	{
		if (!cm.isMarked(d))	// is dart of the vertex cell not marked ?
		{
			cm.mark(d);			// 
			std::cout << d << " : " << position[d]<< " / ";
		}
	}
	std::cout << std::endl;

	// using traversal
	TraversorV<MAP> tv(myMap);	// alias for Traversor<MAP,VERTEX> 
	for (Dart d = tv.begin(); d != tv.end(); d = tv.next())// traverse all vertices (d one dart of each vertex)
		std::cout << d << " : " << position[d]<< " / ";
	std::cout <<  std::endl;

	//using foreach function (C++11 lambda expression)
	foreach_cell<VERTEX>(myMap, [&] (Vertex v) // for each Vertex v of the MAP myMap
	{
		std::cout << v << " : " << position[v]<< " / ";
	});
	// warning here v is a Vertex and not a Dart (but can cast automatically into)

	std::cout <<  std::endl;

	// example of parallel traversal of cells
	Parallel::foreach_cell<VERTEX>(myMap,[&](Vertex v, unsigned int thread) // for each Vertex v of the MAP myMap
	{
		position[v] += VEC3(0.0, 0.0, PFP::REAL(thread) * 0.1f);
		// WARNING thread vary here from 1 to 4 (and not from 0 to 3) !!!!
	}); // 4:4 thread, false for no need for markers in threaded code.

	std::cout << "After // processing"<< std::endl;

	// last and simple traversal method (new for c++11 syntax)
	for(Vertex v : allVerticesOf(myMap))
	{
		std::cout << position[v] << " / ";
	}
	std::cout <<  std::endl;


	// Example with // accumulation
	// computing the sum of area faces

	// force number of threads to 4 (0 for traverse, 1,2,3 for computation)
	CGoGN::Parallel::NumberOfThreads = 4;

	// init nbthread values with 0
	float surf[3] = { 0.0f, 0.0f, 0.0f };
	// traverse face in //
	Parallel::foreach_cell<FACE>(myMap, [&] (Face f, unsigned int thr)
	{
		// for each face add surface to accumulator (-1 because counter between 1-3 not 0-3)
		surf[thr-1] += Algo::Surface::Geometry::convexFaceArea<PFP>(myMap, f, position);
	});

	std::cout << surf[0]<< "/"<< surf[1]<< "/"<< surf[2]<< "/"<< std::endl;
	std::cout << "Total="<<surf[0]+surf[1]+surf[2]<< std::endl;

	// example of traversal in two pass (optimizing marking/unmarking)

	TraversorV<MAP> tv0(myMap);
	TraversorCellEven<MAP, VERTEX> tv1(tv0);
	TraversorCellOdd<MAP, VERTEX> tv2(tv0);

	std::cout << "PAIR:";
	for (Dart d=tv1.begin(); d!=tv1.end(); d=tv1.next())// traverse all vertices (d one dart of each vertex)
		std::cout << d << " / ";
	std::cout << std::endl;

	std::cout << "IMPPAIR:";
	for (Dart d=tv2.begin(); d!=tv2.end(); d=tv2.next())// traverse all vertices (d one dart of each vertex)
		std::cout << d << " / ";
	std::cout <<  std::endl;

	std::cout << "PAIR:";
	for (Dart d=tv1.begin(); d!=tv1.end(); d=tv1.next())// traverse all vertices (d one dart of each vertex)
		std::cout << d << " / ";
	std::cout << std::endl;

	std::cout << "IMPPAIR:";
	for (Dart d=tv2.begin(); d!=tv2.end(); d=tv2.next())// traverse all vertices (d one dart of each vertex)
		std::cout << d << " / ";
	std::cout <<  std::endl;
	return 0;
}
Exemple #21
0
static void
functionality_test (MAP &map,
                    size_t iterations)
{
  size_t counter;
  VALUE i;
  KEY *original_keys = new KEY[iterations];
  KEY *modified_keys = new KEY[iterations];

  // Setup the keys to have some initial data.
  for (i = 0;
       i < iterations;
       ++i)
    {
      original_keys[i].size (sizeof i / sizeof (KEY::TYPE));
      ACE_OS::memcpy (&original_keys[i][0],
                      &i,
                      sizeof i);
    }

  // Make a copy of the keys so that we can compare with the original
  // keys later.
  for (i = 0; i < iterations; ++i)
    {
      modified_keys[i] = original_keys[i];
    }

  // Add to the map, allowing keys to be modified.
  counter = 0;
  for (i = 0; i < iterations; ++i)
    {
      ACE_ASSERT (map.bind_modify_key (i, modified_keys[i]) == 0);
      ++counter;
      ACE_ASSERT (map.current_size () == counter);
    }

  // Forward iteration...
  {
    counter = 0;
    MAP::iterator end = map.end ();

    for (MAP::iterator iter = map.begin ();
         iter != end;
         ++iter, ++counter)
      {
        MAP::value_type entry = *iter;

        // Recover original key.
        KEY original_key;
        ACE_ASSERT (map.recover_key (entry.first (),
                                     original_key) == 0);

        // Make sure recovering keys work.
        ACE_ASSERT (original_keys[entry.second ()] == original_key);

        // Obtain value from key.
        VALUE original_value;
        ACE_OS::memcpy (&original_value,
                        &original_key[0],
                        sizeof original_value);

        // Debugging info.
        ACE_DEBUG ((LM_DEBUG,
                    ACE_TEXT ("(%d|%d|%d)"),
                    counter,
                    original_value,
                    entry.second ()));
      }

    ACE_DEBUG ((LM_DEBUG,
                ACE_TEXT ("\n")));
    ACE_ASSERT (counter == iterations);
  }

  // Reverse iteration...
  {
    counter = iterations;
    MAP::reverse_iterator end = map.rend ();

    for (MAP::reverse_iterator iter = map.rbegin ();
         iter != end;
         ++iter)
      {
        --counter;
        MAP::value_type entry = *iter;

        // Recover original key.
        KEY original_key;
        ACE_ASSERT (map.recover_key (entry.first (),
                                     original_key) == 0);

        // Make sure recovering keys work.
        ACE_ASSERT (original_keys[entry.second ()] == original_key);

        // Obtain value from key.
        VALUE original_value;
        ACE_OS::memcpy (&original_value,
                        &original_key[0],
                        sizeof original_value);

        // Debugging info.
        ACE_DEBUG ((LM_DEBUG,
                    ACE_TEXT ("(%d|%d|%d)"),
                    counter,
                    original_value,
                    entry.second ()));
      }

    ACE_DEBUG ((LM_DEBUG,
                ACE_TEXT ("\n")));
    ACE_ASSERT (counter == 0);
  }

  // Search using the modified keys.
  for (i = 0; i < iterations; ++i)
    {
      VALUE j;
      ACE_ASSERT (map.find (modified_keys[i], j) != -1);
      ACE_ASSERT (i == j);
    }

  // Rmoved keys from map.
  counter = iterations;
  for (i = 0; i < iterations; ++i)
    {
      ACE_ASSERT (map.unbind (modified_keys[i]) != -1);
      --counter;
      ACE_ASSERT (map.current_size () == counter);
    }

  // Cleanup.
  delete[] modified_keys;
  delete[] original_keys;
}
bool napraia(pii x, const MAP & p  ){
	MAP::const_iterator it = p.lower_bound( x.F);
	if( it == p.begin()) return true;
	return (--it)->S >= x.S;
}
Exemple #23
0
int main()
{
	// declare a map to handle the mesh
	MAP myMap;

	// add position attribute on vertices and get handler on it
	VertexAttribute<VEC3, MAP> positionAtt = myMap.addAttribute<VEC3, VERTEX, MAP>("position");
	if (!positionAtt.isValid())
		std::cerr << "impossible to create an attribute with name position (already used ?)"<< std::endl;


	// create a topo grid of 2x2 squares
	Algo::Surface::Tilings::Square::Grid<PFP> grid(myMap, 2, 2, true);
	// and embed it using position attribute
	grid.embedIntoGrid(positionAtt, 1.,1.,0.);


	VertexGeneric(myMap,positionAtt);

	// ATTRIBUTE DECLARATION

	// add an attribute of type float on orbit EDGE
	EdgeAttribute<float, MAP> lengthAtt = myMap.addAttribute<float, EDGE, MAP>("length");
	if (!lengthAtt.isValid())
		std::cerr << "impossible to create the attribute"<< std::endl;

	computeLengthEdges(myMap,positionAtt,lengthAtt);

	// add an attribute of type std::string on orbit FACE
	FaceAttribute<std::string, MAP> nameAtt = myMap.addAttribute<std::string, FACE, MAP>("name");
	if (!nameAtt.isValid())
		std::cerr << "impossible to create the attribute"<< std::endl;

	// for complex type use following template (function nameOfType not applicable)
	EdgeAttribute< NoTypeNameAttribute< std::vector<int> >, MAP> vectAtt = myMap.addAttribute< NoTypeNameAttribute< std::vector<int> >, EDGE, MAP>("vector_of_int");
	if (!vectAtt.isValid())
		std::cerr << "impossible to create the attribute"<< std::endl;

	Dart d = myMap.begin();
	// define a vertex from a dart
	Vertex v(d);
	// define a face from a dart
	Face f(d);


	// ATTRIBUTE ACCESS

	// [] operator can take a dart, a cell (only same off attribute), or an unsigned inf
	// access to any attributes with darts
	std::cout << positionAtt[d]<< std::endl;
	nameAtt[d] = "Hello";
	lengthAtt[myMap.phi1(d)] = 54.0f;

	std::vector<int> vi = {3,5,7,9,11};
	vectAtt[d]= vi;
	vectAtt[d].push_back(11);

	// access to VertexAttribute with a Vertex
	std::cout << positionAtt[v]<< std::endl;

	// access to FaceAttribute with a Face
	std::cout << nameAtt[f]<< std::endl;

	// following line does not compile because of wrong cell type
	//	std::cout << positionAtt[f]<< std::endl;
	//  possible to bypass using dart access
	std::cout << positionAtt[f.dart]<< std::endl;

	// access with unsigned int is dangerous, index must be obtain with begin/end/next (see dumpAttribute)

	// COPY, REMOVE, SWAP

	// possible to have any number of attribute a same ORBIT
	VertexAttribute<VEC3, MAP> position2Att = myMap.addAttribute<VEC3, VERTEX, MAP>("other_position");

	// copy of attribute of same type (linear complexity)
	myMap.copyAttribute(position2Att,positionAtt);

	positionAtt[v] += VEC3(0,0,1);

	computeNewPositions(myMap,positionAtt);
	dumpAttribute(positionAtt);

	//check if there is a Vertex Attribute of VEC3 named position => yes
	testVAbyNames(myMap,"position");

	// remove the attribute
	myMap.removeAttribute(positionAtt);

	//check if there is a Vertex Attribute of VEC3 named position => no
	testVAbyNames(myMap,"position");

	return 0;
}
Exemple #24
0
		static CSession*		Begin( void ){
			m_It	= m_Sessions.begin();
			return(m_It->second);
		}
Exemple #25
0
void Topo3PrimalRender<PFP>::updateData(MAP& mapx, const VertexAttribute<VEC3, MAP>& positions, float ke, float kf)
{
	if (m_attIndex.map() != &mapx)
		m_attIndex  = mapx.template getAttribute<unsigned int, DART, MAP>("dart_index");
	if (!m_attIndex.isValid())
		m_attIndex  = mapx.template addAttribute<unsigned int, DART, MAP>("dart_index");

//	m_nbDarts = 0;
//	for (Dart d = mapx.begin(); d != mapx.end(); mapx.next(d))
//	{
//		m_nbDarts++;
//	}

	m_nbDarts = mapx.getNbDarts();

	// beta2/3
	DartAutoAttribute<VEC3, MAP> fv2(mapx);

	m_vbo2->bind();
	glBufferData(GL_ARRAY_BUFFER, 2*m_nbDarts*sizeof(Geom::Vec3f), 0, GL_STREAM_DRAW);
	GLvoid* ColorDartsBuffer = glMapBuffer(GL_ARRAY_BUFFER, GL_READ_WRITE);
	Geom::Vec3f* colorDartBuf = reinterpret_cast<Geom::Vec3f*>(ColorDartsBuffer);

	if (m_bufferDartPosition!=NULL)
		delete m_bufferDartPosition;
	m_bufferDartPosition = new Geom::Vec3f[2*m_nbDarts];
	Geom::Vec3f* positionDartBuf = reinterpret_cast<Geom::Vec3f*>(m_bufferDartPosition);

	unsigned int posDBI = 0;

	int nbf = 0;
	//traverse each face of each volume
	TraversorF<MAP> traFace(mapx);
	for (Dart d = traFace.begin(); d != traFace.end(); d = traFace.next())
	{
		std::vector<VEC3> vecPos;
		vecPos.reserve(16);

		VEC3 centerFace = Algo::Surface::Geometry::faceCentroidELW<PFP>(mapx, d, positions);

		//shrink the face
		float okf = 1.0f - kf;
		Dart dd = d;
		do
		{
			VEC3 P = centerFace*okf + positions[dd]*kf;
			vecPos.push_back(P);
			dd = mapx.phi1(dd);
		} while (dd != d);
		
		unsigned int nb = vecPos.size();
		
		vecPos.push_back(vecPos.front()); // copy the first for easy computation on next loop

		// compute position of points to use for drawing topo
		float oke = 1.0f - ke;
		for (unsigned int i = 0; i < nb; ++i)
		{
			VEC3 P = vecPos[i]*ke + vecPos[i+1]*oke;
			VEC3 Q = vecPos[i+1]*ke + vecPos[i]*oke;

//			VEC3 PP = 0.52f*P + 0.48f*Q;
//			VEC3 QQ = 0.52f*Q + 0.48f*P;

            VEC3 PP = 0.56f*P + 0.44f*Q;
            VEC3 QQ = 0.56f*Q + 0.44f*P;

			*positionDartBuf++ = PFP::toVec3f(P);
			*positionDartBuf++ = PFP::toVec3f(PP);
			if (mapx.template isBoundaryMarked<3>(d))
			{
				*colorDartBuf++ = m_boundaryDartsColor;
				*colorDartBuf++ = m_boundaryDartsColor;
			}
			else
			{
				*colorDartBuf++ = m_dartsColor;
				*colorDartBuf++ = m_dartsColor;
			}

			m_attIndex[d] = posDBI;
			posDBI+=2;
			fv2[d] = (P+PP)*0.5f;

			*positionDartBuf++ = PFP::toVec3f(Q);
			*positionDartBuf++ = PFP::toVec3f(QQ);

			Dart dx = mapx.phi3(d);
			if (mapx.template isBoundaryMarked<3>(dx))
			{
				*colorDartBuf++ = m_boundaryDartsColor;
				*colorDartBuf++ = m_boundaryDartsColor;
			}
			else
			{
				*colorDartBuf++ = m_dartsColor;
				*colorDartBuf++ = m_dartsColor;
			}

			m_attIndex[dx] = posDBI;
			posDBI+=2;
			fv2[dx] = (Q+QQ)*0.5f;

			d = mapx.phi1(d);
		}
		nbf++;
	}
	m_vbo2->bind();
	glUnmapBuffer(GL_ARRAY_BUFFER);

	m_vbo0->bind();
	glBufferData(GL_ARRAY_BUFFER, 2*m_nbDarts*sizeof(Geom::Vec3f), m_bufferDartPosition, GL_STREAM_DRAW);

	// alpha2
	m_vbo1->bind();
	glBufferData(GL_ARRAY_BUFFER, 2*m_nbDarts*sizeof(Geom::Vec3f), 0, GL_STREAM_DRAW);
	GLvoid* PositionBuffer2 = glMapBufferARB(GL_ARRAY_BUFFER, GL_READ_WRITE);

	Geom::Vec3f* positionF2 = reinterpret_cast<Geom::Vec3f*>(PositionBuffer2);

	m_nbRel2 = 0;

	for (Dart d = mapx.begin(); d != mapx.end(); mapx.next(d))
	{
		Dart e = mapx.phi2(mapx.phi3(d));
		//if (d < e)
		{
			*positionF2++ = PFP::toVec3f(fv2[d]);
			*positionF2++ = PFP::toVec3f(fv2[e]);
			m_nbRel2++;
		}
	}

	m_vbo1->bind();
	glUnmapBuffer(GL_ARRAY_BUFFER);

	glBindBuffer(GL_ARRAY_BUFFER, 0);
}