void findFacesInMesh()
		{
		    multimap<indexPair, int>  mapface;
		    multimap<indexPair, int> ::iterator it, it2,it3;
          pair<multimap<indexPair, int> ::iterator,multimap<indexPair, int> ::iterator> rangeit;
 

			int ip1, ip2;

		for(int k=0; k!=cells.size(); k++)
			 {  
		 for(int i=0; i< ( cells[k].getNbPoints() ); i++)  {
	 if(i== (cells[k].getNbPoints()-1)   ){ ip1=cells[k].getListPointsIndex(i) ;	ip2=cells[k].getListPointsIndex(0);}  
   else {ip1=cells[k].getListPointsIndex(i);	ip2=cells[k].getListPointsIndex(i+1);  }						          		
     mapface.insert( multimap<indexPair, int> ::value_type( indexPair(ip1,ip2), k) );                                                      	 
				                                                                            }
			}

for ( it=mapface.begin() ; it != mapface.end(); it++ ){
				                   
		indexPair c=it->first;                                         rangeit=mapface.equal_range(c);
	for (it2=rangeit.first; it2!=rangeit.second;  ++it2)
			  {
				 int ip1=it2->first.originIndex1;
				  int ip2=it2->first.originIndex2;
				  int ip3=it2->second;
			    faces.push_back( Face( points[ip1]  , points[ip2] )  );
		             faces[faces.size()-1].pushBackAdjCells(ip3);
			   }
	
			  mapface.erase( rangeit.first,rangeit.second);

Dear friends:
I set up a multimap mapface from a finite element mesh file which recorde the connectivity of each cell. The mapface.first is IndexPair (int ,int) which records the indexes of the two ending points of a face, and the mapface.second records the index of master cell which contains the face. A face has at most two neighbor cells in the mesh.
My mission is to collect all the faces and their neighbor cells from the multimap. the faces are stoed in the faces list, and the neighbour cell are stored by faces.pushBackAdjCells().
I want to iterate from the first of mapface, then find all the repeated items by
mapface.equal_range(), then delete its from the mapface to make the face unique. but the code doesn't work and gives me the following error" map/set iterator not derefercable".
Could you please give me some ideas about this.
Regards

It would greatly improve readability if you used consistent indentation in your code. That said, one very likely problem is the usage of mapface.erase() within the loop of the iterator over items in mapface. Since you pick your range of elements from mapface as the first N with the same index-pair as the first element, use the data and delete those N, the loop increment step of it++ increments from a now-non-existent element to it's possibly-also-non-existent next element.

Since you're always looking at the first element, your outer loop doesn't need to loop over the elements in mapface, and since you always delete something, can be simplified to while (mapface.size() > 0) {...}.

At lines 27 and 28, it might be more readable to define the face object first, add the AdjacentCells to it, then push it onto the array:

...
Face face(points[ip1], points[ip2]);
face.pushBackAdjCells(ip3);
faces.push_back(face);
...

though I don't think there's anything technically wrong with what you have now.

Try that much, and get back to us?

It would greatly improve readability if you used consistent indentation in your code. That said, one very likely problem is the usage of mapface.erase() within the loop of the iterator over items in mapface. Since you pick your range of elements from mapface as the first N with the same index-pair as the first element, use the data and delete those N, the loop increment step of it++ increments from a now-non-existent element to it's possibly-also-non-existent next element.

Since you're always looking at the first element, your outer loop doesn't need to loop over the elements in mapface, and since you always delete something, can be simplified to while (mapface.size() > 0) {...}.

At lines 27 and 28, it might be more readable to define the face object first, add the AdjacentCells to it, then push it onto the array:

...
Face face(points[ip1], points[ip2]);
face.pushBackAdjCells(ip3);
faces.push_back(face);
...

though I don't think there's anything technically wrong with what you have now.

Try that much, and get back to us?

Thank you very much for your suggestions.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.