Esempio n. 1
0
Dt *construct3DDelaunayTriangulation(){
	int i;

	Dt *dt = new Dt();

	for (i = 0; i < vertexCount; i++){
		Point point = Point(v[i].vec[0], v[i].vec[1], v[i].vec[2]);
		DVertex vh = dt->insert(point); //hier absturz
		vh->info().setIndex(i);
	}

	//	cout << "DT3: finite: vertices=" << dt->number_of_vertices() << ", edges=" << dt->number_of_finite_edges() << ", faces=" << dt->number_of_finite_facets() << ", cells=" << dt->number_of_finite_cells() << endl;
	cout << "DT3: all: vertices=" << (dt->number_of_vertices() + 1) << ", edges=" << dt->number_of_edges() << ", faces=" << dt->number_of_facets() << ", cells=" << dt->number_of_cells() << endl;

	if ((int)dt->number_of_vertices() != vertexCount){
		cout << "Warning: point set contains identical points: will fail later because of indices larger than that count!" << endl;

		// adjust indices to account for removed duplicate points (required for consistency, and no indices >= vertexcount!)
		map<int, int> vertexMap;
		i = 0;

		for (Dt::Vertex_iterator vhIter = dt->vertices_begin(); vhIter != dt->vertices_end(); vhIter++){
			DVertex vh = vhIter;

			if (vh->info().index() != -1)
			{
				vertexMap[i] = vh->info().index();
				vh->info().setIndex(i);
				i++;
			}
		}

		cout << "vertices reduced from " << vertexCount << " to " << (int)dt->number_of_vertices() << endl;

		vertexCount = (int)dt->number_of_vertices();
		_Vertex *newV = new _Vertex[vertexCount];

		for (i = 0; i < vertexCount; i++){
			//			cout << i << ": " << vertexMap[i] << endl;
			newV[i].vec = v[vertexMap[i]].vec;
		}

		//		delete v;	// TODO: dirty
		v = newV;
	}
	return dt;
}