Skip to Content.
Sympa Menu

cgal-discuss - Re: [cgal-discuss] write out and read in (Delauney) triangulation

Subject: CGAL users discussion list

List archive

Re: [cgal-discuss] write out and read in (Delauney) triangulation


Chronological Thread 
  • From: Tom Van Doorsselaere <>
  • To:
  • Subject: Re: [cgal-discuss] write out and read in (Delauney) triangulation
  • Date: Tue, 12 May 2015 15:39:21 +0200

As promised, I have tested the code on two computers, with different
versions of gcc (4.4.7 and 4.9.2) and with different combinations of
flags. However, I always get stuck at the assertion violation.

I have also tried CGAL version 4.3 and 4.0.2.

I have further simplified the example (so it doesn't need gnu++0x
anylonger, and fixing the space Monique pointed out). Now it compiles with
g++ -frounding-math -lCGAL -lgmp -o testreadin testreadinwriteout.cpp
but the problem persists.

After running
-----------------
>> ./testreadin --write
writing out triangulationGelukt
-----------------
the reading in of the triangulation fails:

-----------------
>> ./testreadin --read
terminate called after throwing an instance of 'CGAL::Assertion_exception'
what(): CGAL ERROR: assertion violation!
Expr: false
File: /usr/include/CGAL/Triangulation_3.h
Line: 5330
reading in triangulationAborted
-----------------

I will look into compiling CGAL with clang or icc. However, in the end,
I suppose I would like to use gcc, because it is readily available on
most systems.

Can anybody reproduce the assertion using gcc on their computer?

Thanks,

Tom


On 05/12/15 09:33, Tom Van Doorsselaere wrote:
> Dear Monique,
>
> Thanks for your e-mail.
>
> This is very interesting indeed. It thus means that
> - either it is a compiler issue,
> - or I am forgetting a compiler flag or have a flag too much.
>
> I will try this afternoon with different versions of gcc and with a
> combination of flags.
>
> Thanks for your input! I had not thought in this direction.
>
> Tom
>
>
> On 05/11/15 19:14, Monique Teillaud wrote:
>> Le 08/05/15 17:27, Tom Van Doorsselaere a écrit :
>>> Dear CGAL enthousiasts,
>>
>> :)
>> Dear Tom,
>>
>>> I'm building a program for the rendering of emission of solar coronal
>>> models.
>>
>> This sounds very interesting.
>>
>> I tested your code on my laptop, with CGAL 4.6, both release and debug
>> modes, clang 5.0.
>>
>> I had to add a space line 61 to avoid the consecutive >>
>> vector<vector<double> > allvar;
>> Then it compiled.
>>
>> teillaud@tzitziki:~/CGAL/test >./testreadinwriteout --write
>> writing out triangulationGelukt
>> teillaud@tzitziki:~/CGAL/test >./testreadinwriteout --read
>> reading in triangulationGelukt
>>
>> If I understand correctly, this is the result that you expect. It seems
>> to work like a charm...
>>
>> Best regards,
>
#include <fstream>
#include <sstream>
#include <cstdlib>
#include <cmath>

#include <CGAL/Exact_predicates_inexact_constructions_kernel.h>
#include <CGAL/Delaunay_triangulation_3.h>
#include <CGAL/interpolation_functions.h>

using namespace std;

typedef CGAL::Exact_predicates_inexact_constructions_kernel K;
typedef CGAL::Delaunay_triangulation_3<K, CGAL::Fast_location> Delaunay_triangulation_3;
typedef K::Point_3                                    Point;

Delaunay_triangulation_3 DT_global;

void writetriangulation(const string snapsave, const Delaunay_triangulation_3 *DTpointer)
{
		ofstream out(snapsave.c_str(),ios::ate|ios::trunc);
		if (out.is_open())
		{
			if (DTpointer!=NULL) out << *DTpointer;
			out.close();
		}
		else cout << "Unable to write to " << snapsave << endl;
}

void readtriangulation(const string snapsave, Delaunay_triangulation_3 *DTpointer)
{
		ifstream in(snapsave.c_str());
		if (in.is_open())
		{
			if (!in.eof() && (DTpointer!=NULL)) 
			{
				in >> *DTpointer;
				// Check is this is a valid Delaunay triangulation
				//assert(DTpointer->is_valid());
			}
			in.close();
		}
}

int main(int argc, char* argv[])
{
	stringstream ss;
	ss << "vae2_delta1_t=0.test2";
	string filename=ss.str();
	ss.str("");
	ss << "emissionsave";
	string snapsave=ss.str();
	ss.str("");

	if (strcmp(argv[1],"--write")==0)
	{
		cout << "writing out triangulation";
		int dim=3;
		int ng = 500/2;
		int nvars = 5; // \rho, T, vx, vy, vz
		vector<double> * grid=new vector<double>[dim];
		vector<vector<double> > allvar;
		allvar.resize(nvars);
		double r, theta;
		
		ifstream in(filename.c_str(),ios::binary);
		if (in.is_open())
		{
			for (int i=0; i<dim; i++)
			{
				grid[i].resize(ng);
			}
			for (int i=0; i<nvars; i++)
			{
				allvar[i].resize(ng);
			}
			for (int j=0; j<ng; j++)
			{
				for (int i=0; i<dim; i++) in >> grid[i][j];
				for (int i=0; i<nvars; i++) in >> allvar[i][j];
				r=grid[0][j];
				theta=grid[1][j];
				grid[0][j]=r*cos(theta);
				grid[1][j]=r*sin(theta);
			}
			in.close();
		}

		vector<Point> delaunaygrid;
		delaunaygrid.resize(ng);

		for (int i=0; i<ng; i++)
		{	
			delaunaygrid[i]=Point(grid[0][i],grid[1][i],grid[2][i]);
		}

		DT_global.insert(delaunaygrid.begin(),delaunaygrid.end());
	        assert(DT_global.is_valid());
	        assert(DT_global.dimension()==3);
		
		writetriangulation(snapsave,&DT_global);
	}
	else
	{
		Delaunay_triangulation_3  DT;
		cout << "reading in triangulation";
		readtriangulation(snapsave,&DT);
		assert(DT_global.is_valid());
	}
	cout << "Gelukt\n" ;
	return EXIT_SUCCESS;
}



Archive powered by MHonArc 2.6.18.

Top of Page