Ejemplo n.º 1
0
HMDT MGL_EXPORT mgl_triangulation_2d(HCDT x, HCDT y)
{
	mglData *nums=0;
	long n = x->GetNN();
	if(y->GetNN()!=n)	return nums;
	// use s-hull here
	std::vector<Shx> pts;
	std::vector<long> out;
	Shx pt;

	double mx = 0, my = 0;
	for(long i=0;i<n;i++)
	{
		register double t;
		t = fabs(x->vthr(i));	if(t>mx)	mx=t;
		t = fabs(y->vthr(i));	if(t>my)	my=t;
	}
	mx *= 1e-15;	my *= 1e-15;
	for(long i=0;i<n;i++)
	{
		pt.r = x->vthr(i);	pt.c = y->vthr(i);
		if(mgl_isbad(pt.r) || mgl_isbad(pt.c))	continue;
		if(fabs(pt.r)<mx)	pt.r=0;
		if(fabs(pt.c)<my)	pt.c=0;
		pt.id = i;    pts.push_back(pt);
	}

	std::vector<Triad> triads;
	if(de_duplicate(pts, out))
		mgl_set_global_warn("There are duplicated points for triangulation.");
	s_hull_pro(pts, triads);
	long m = triads.size();
	nums=new mglData(3,m);
	for(long i=0;i<m;i++)
	{
		nums->a[3*i]   = triads[i].a;
		nums->a[3*i+1] = triads[i].b;
		nums->a[3*i+2] = triads[i].c;
	}
	return nums;
}
Ejemplo n.º 2
0
//-----------------------------------------------------------------------------
void DatPanel::putValue(int r, int c)
{
	if(!var || r<0 || c<0 || r>=ny || c>=nx || !ready)	return;
	QString s = tab->item(r,c)->text().toLower();
	mreal f;
	dual g;
	if(s=="nan")	f=NAN;
	else if(s=="inf")	f=INFINITY;
	else if(s=="-inf")	f=-INFINITY;
	else	g = mgl_str2dual(s.toLocal8Bit().constData());	//f = s.toDouble();
	f = real(g);
	mglDataC *cc = dynamic_cast<mglDataC*>(var);
	if(cc)
	{
		if(g!=cc->a[c+nx*(r+ny*kz)])
		{
			if(mgl_isnan(g))	s="nan";
			else if(mgl_isbad(g))	s="inf";
			else if(imag(g)>0)	s.sprintf("%g+%gi",real(g),imag(g));
			else if(imag(g)<0)	s.sprintf("%g-%gi",real(g),-imag(g));
			else	s.sprintf("%g",real(g));
			tab->item(r,c)->setText(s);
		}
		cc->a[c+nx*(r+ny*kz)] = g;
	}
	else
	{
		if(f!=var->v(c,r,kz))
		{
			if(mgl_isnan(f))	s="nan";
			else if(mgl_isbad(f))	s=f>0?"inf":"-inf";
			else	s.sprintf("%g", f);
			tab->item(r,c)->setText(s);
		}
		var->set_v(f,c,r,kz);
	}
	infoDlg->refresh();
}
Ejemplo n.º 3
0
//-----------------------------------------------------------------------------
void DatPanel::refresh()
{
	bool rc = false;
	if(!var)	return;
	infoDlg->allowRefresh=false;
	if(nx!=var->GetNx())	{	nx = var->GetNx();	tab->setColumnCount(nx);	rc=true;	}
	if(ny!=var->GetNy())	{	ny = var->GetNy();	tab->setRowCount(ny);	rc=true;	}
	if(kz>=var->GetNz())	{	kz = 0;	emit sliceChanged(0);	}
	if(nz!=var->GetNz())	{	nz = var->GetNz();	emit nzChanged(nz);		}
	const mglData *dd = dynamic_cast<const mglData *>(var);	if(dd)	id = QString(dd->id.c_str());
	const mglDataC *dc = dynamic_cast<const mglDataC *>(var);	if(dc)	id = QString(dc->id.c_str());
	if(nz==1 && ny>1 && !id.isEmpty())
	{
		QStringList head;
		QString s;
		for(int i=0;i<ny;i++)
		{
			s = QString("%1").arg(i);
			if(id[i]>='a' && id[i]<='z')	s=s+" ("+id[i]+")";
			head<<s;
		}
		tab->setHorizontalHeaderLabels(head);
	}
	long m=var->s.length();
	QString s,d;
	if(rc)
	{
		QStringList sh,sv;
		for(long i=0;i<nx;i++)	sh<<QString::number(i);
		tab->setHorizontalHeaderLabels(sh);
		for(long i=0;i<ny;i++)	sv<<QString::number(i);
		tab->setVerticalHeaderLabels(sv);
		for(long i=0;i<nx;i++)	for(long j=0;j<ny;j++)
			tab->setItem(j,i,new QTableWidgetItem);
	}
	mglDataC *cc = dynamic_cast<mglDataC*>(var);
	if(cc)	for(long i=0;i<nx;i++)	for(long j=0;j<ny;j++)
	{
		dual f = cc->a[i+nx*(j+ny*kz)];
		if(mgl_isnan(f))	s = "nan";
		else if(mgl_isbad(f))	s="inf";
		else if(imag(f)>0)	s.sprintf("%.15g+%.15gi",real(f),imag(f));
		else if(imag(f)<0)	s.sprintf("%.15g-%.15gi",real(f),-imag(f));
		else	s.sprintf("%15g",real(f));
		tab->item(j,i)->setText(s);
	}
	else	for(long i=0;i<nx;i++)	for(long j=0;j<ny;j++)
	{
		double f = var->v(i,j,kz);
		if(mgl_isnan(f))	s = "nan";
		else if(mgl_isbad(f))	s=f>0?"inf":"-inf";
		else	s.sprintf("%.15g",f);
		tab->item(j,i)->setText(s);
	}
	infoDlg->allowRefresh=true;	infoDlg->refresh();
	QChar *ss = new QChar[m+1];
	for(long i=0;i<m;i++)	ss[i] = var->s[i];
	s = QString(ss, m);	delete []ss;
	d.sprintf("%d * %d * %d", nx, ny, nz);
	ready = true;
}