Changeset - 782330072e62
[Not reviewed]
default
! ! !
Michael Guravage - 15 years ago 2010-06-17 18:13:46
michael.guravage@cwi.nl
Reformatted the source files and generally straighten up the code.

--
user: Michael Guravage <michael.guravage@cwi.nl>
branch 'default'

changed src/Neighbor.cpp
changed src/Neighbor.h
changed src/OptionFileDialog.cpp
changed src/OptionFileDialog.h
changed src/UniqueMessage.cpp
changed src/UniqueMessage.h
changed src/VirtualLeaf.cpp
changed src/apoplastitem.cpp
changed src/apoplastitem.h
changed src/build_models/auxingrowthplugin.cpp
changed src/build_models/auxingrowthplugin.h
changed src/build_models/meinhardtplugin.cpp
changed src/build_models/meinhardtplugin.h
changed src/build_models/testplugin.cpp
changed src/build_models/testplugin.h
changed src/build_models/translate_plugin.pl
changed src/canvas.cpp
changed src/canvas.h
changed src/cell.cpp
changed src/cell.h
changed src/cellbase.cpp
changed src/cellbase.h
changed src/cellitem.cpp
changed src/cellitem.h
changed src/curvecolors.h
changed src/data_plot.cpp
changed src/data_plot.h
changed src/far_mem_5.h
changed src/flux_function.h
changed src/forwardeuler.cpp
changed src/forwardeuler.h
changed src/infobar.h
changed src/mainbase.cpp
changed src/mainbase.h
changed src/matrix.cpp
changed src/matrix.h
changed src/maxmin.h
changed src/mesh.cpp
changed src/mesh.h
changed src/miscq.cpp
changed src/miscq.h
changed src/modelcatalogue.cpp
changed src/modelcatalogue.h
changed src/modelelement.h
changed src/node.cpp
changed src/node.h
changed src/nodeitem.cpp
changed src/nodeitem.h
changed src/nodeset.cpp
changed src/nodeset.h
changed src/output.cpp
changed src/output.h
changed src/parameter.cpp
changed src/parameter.h
changed src/pardialog.cpp
changed src/pardialog.h
changed src/parse.cpp
changed src/parse.h
changed src/perl/deployapp.pl
changed src/perl/histogram.pl
changed src/perl/make_parameter_source.pl
changed src/perl/make_pardialog_source.pl
changed src/perl/make_xmlwritecode.pl
changed src/pi.h
changed src/qcanvasarrow.h
changed src/random.cpp
changed src/random.h
changed src/rseed.cpp
changed src/rungekutta.cpp
changed src/rungekutta.h
changed src/simitembase.cpp
changed src/simitembase.h
changed src/simplugin.cpp
changed src/simplugin.h
changed src/sqr.h
changed src/tiny.h
changed src/transporterdialog.cpp
changed src/transporterdialog.h
changed src/vector.cpp
changed src/vector.h
changed src/vleafmodel.h
changed src/wall.cpp
changed src/wall.h
changed src/wallbase.cpp
changed src/wallbase.h
changed src/wallitem.cpp
changed src/wallitem.h
changed src/warning.cpp
changed src/warning.h
changed src/xmlwrite.cpp
changed src/xmlwrite.h
87 files changed with 601 insertions and 792 deletions:
src/cell.cpp
62
118
src/node.h
19
32
0 comments (0 inline, 0 general)
src/Neighbor.cpp
Show inline comments
 
@@ -40,7 +40,8 @@ bool Neighbor::Eq(Neighbor &c) const { r
 
Cell* Neighbor::getCell(void) const { return cell; } 
 

	
 
bool neighbor_cell_eq(const Neighbor &n1, const Neighbor &n2) {
 
  return (n1.getCell())->Index() == (n2.getCell())->Index(); // Compare cell indices not pointers.
 
}
 
  
 
// finis
 
/* finis */
 

	
src/Neighbor.h
Show inline comments
 
@@ -65,7 +65,8 @@ ostream &operator<<(ostream &os, const N
 

	
 
// Realize that we're equating like pointers with object equivalence!
 
bool neighbor_cell_eq(const Neighbor &n1, const Neighbor &n2);
 

	
 
#endif
 

	
 
// finis
 
/* finis */
 

	
src/OptionFileDialog.cpp
Show inline comments
 
@@ -24,26 +24,27 @@
 
#include <QCheckBox>
 
#include <iostream>
 
using namespace  std; 
 

	
 
static const std::string _module_id("$Id$");
 

	
 
OptionFileDialog::OptionFileDialog(QWidget *parent, const char *name, bool modal) : Q3FileDialog(parent, name, modal) {
 

	
 
OptionFileDialog::OptionFileDialog(QWidget *parent, const char *name, bool modal) : Q3FileDialog(parent, name, modal)
 
{
 
	//cerr << "This is an OptionFileDialog\n";
 
	geometrycheck = new QCheckBox("geometry",this);
 
	geometrycheck -> setCheckState(Qt::Checked);
 
	
 
	parcheck = new QCheckBox("parameters", this);
 
	parcheck -> setCheckState(Qt::Checked);
 
	
 
	addToolButton(geometrycheck);
 
	addToolButton(parcheck);
 

	
 
};
 

	
 
OptionFileDialog::OptionFileDialog ( const QString & dirName, const QString & filter , QWidget * parent, const char * name , bool modal  ) :
 
OptionFileDialog::OptionFileDialog ( const QString & dirName, const QString & filter , 
 
				     QWidget * parent, const char * name , bool modal  ) :
 
		Q3FileDialog(dirName, filter, parent, name, modal) {
 
		
 
			cerr << "This is an OptionFileDialog\n";
 
};
 
					
 
	};
 
/* finis */
src/OptionFileDialog.h
Show inline comments
 
@@ -27,17 +27,20 @@
 
#include <QCheckBox>
 

	
 
class OptionFileDialog : public Q3FileDialog {
 
	Q_OBJECT
 
public:
 
	OptionFileDialog(QWidget *parent = 0, const char *name = 0, bool modal = false);
 
	OptionFileDialog ( const QString & dirName, const QString & filter = QString(), QWidget * parent = 0, const char * name = 0, bool modal = false );
 
  OptionFileDialog ( const QString & dirName, const QString & filter = QString(), 
 
		     QWidget * parent = 0, const char * name = 0, bool modal = false );
 
	
 
	bool readGeometryP(void) const { return geometrycheck->checkState()==Qt::Checked; }
 
	bool readParametersP(void) const { return parcheck->checkState()==Qt::Checked; }
 

	
 
private:
 
	QCheckBox *geometrycheck;	
 
	QCheckBox *parcheck;
 
};
 

	
 
#endif
 

	
 
/* finis */
src/UniqueMessage.cpp
Show inline comments
 
@@ -65,21 +65,20 @@ QDialog(parent, f) {
 
		
 
UniqueMessageBox::~UniqueMessageBox(void)  {
 
	
 
	if (show_again->checkState() == Qt::Checked ) {
 
		cerr << "Message won't be shown again\n";
 
		issued_messages << boxtext;
 

	
 
	}
 
}
 
int UniqueMessageBox::exec(void)  {
 
	
 
	if (display)
 
		return QDialog::exec();
 
	else {
 
		return 1;
 
	}
 

	
 
}
 
					   
 
QStringList UniqueMessageBox::issued_messages;
 
					   
 
/* finis */
src/UniqueMessage.h
Show inline comments
 
@@ -49,6 +49,8 @@ private:
 
	QPushButton *okButton;
 
	QLabel *label;
 
	QString boxtext;
 
};
 

	
 
#endif
 

	
 
/* finis */
src/VirtualLeaf.cpp
Show inline comments
 
@@ -135,13 +135,14 @@ public:
 
  }
 
};
 

	
 
Mesh mesh;
 
bool batch=false;
 

	
 
void MainBase::Plot(int resize_stride) {
 
void MainBase::Plot(int resize_stride)
 
{
 
	
 
  clear();
 
	
 
  static int count=0;
 
  if (resize_stride) {
 
    if ( !((++count)%resize_stride) ) {
 
@@ -258,36 +259,28 @@ TIMESTEP {
 
      mesh.IncreaseCellCapacityIfNecessary();
 
      mesh.DoCellHouseKeeping();
 
      //mesh.LoopCurrentCells(mem_fun(&plugin->CellHouseKeeping)); // this includes cell division
 
				
 
      // Reaction diffusion	
 
      mesh.ReactDiffuse(par.rd_dt);
 
				
 
      t++;
 
				
 
      Plot(par.resize_stride);
 
		
 
    }
 
		
 
  } else {
 
			
 
    mesh.ReactDiffuse(par.rd_dt);
 
		
 
    Plot(par.resize_stride);
 
			
 
  }
 
		
 
  i++;
 
  return mesh.getTime();
 
		
 
}
 
		
 
		
 
				
 
/* Called if a cell is clicked */
 
void Cell::OnClick(QMouseEvent *e) {
 
void Cell::OnClick(QMouseEvent *e)
 
{
 
  e = NULL; // use assignment merely to obviate compilation warning
 
}
 
				
 

	
 
/* Custom message handler - Default appends a newline character to the end of each line. */ 
 
void vlMessageOutput(QtMsgType type, const char *msg)
 
@@ -315,17 +308,13 @@ void vlMessageOutput(QtMsgType type, con
 

	
 
Parameter par;
 
				
 
int main(int argc,char **argv) {
 
					
 
  try {
 
						
 

	
 
    int c;
 

	
 
						
 
    char *leaffile=0;
 
    char *modelfile=0;
 
						
 
    while (1) {
 
							
 
      //int this_option_optind = optind ? optind : 1;
 
@@ -414,29 +403,25 @@ int main(int argc,char **argv) {
 
	((Main *)main_window)->resize( ((Main *)main_window)->sizeHint());
 
      } else {
 
        ((Main *)main_window)->showMaximized();
 
      }
 
    } else {
 
      main_window=new MainBase(canvas, mesh);
 

	
 
    }
 

	
 
    
 
	  
 
    canvas.setSceneRect(QRectF());
 
    if (!batch) {
 
      QObject::connect( qApp, SIGNAL(lastWindowClosed()), qApp, SLOT(quit()) );
 
    }
 

	
 
    // Install model or read catalogue of models
 
    ModelCatalogue model_catalogue(&mesh, useGUI?(Main *)main_window:0,modelfile);
 
    if (useGUI)
 
      model_catalogue.PopulateModelMenu();
 
    model_catalogue.InstallFirstModel();
 
    
 

	
 
    if (leaffile) 
 
      main_window->Init(leaffile);
 
	  
 
    Cell::SetMagnification(1);
 
    Cell::setOffset(0,0);
 
						
 
@@ -446,17 +431,15 @@ int main(int argc,char **argv) {
 

	
 
    if (batch) {
 
      double t=0.;
 
      do {
 
	t = main_window->TimeStep();
 
      } while (t < par.maxt);
 
							
 
    } else
 
      return app.exec();
 
	  
 
						
 
  } catch (const char *message) {
 
    if (batch) { 
 
      cerr << "Exception caught:" << endl;
 
      cerr << message << endl;
 
      abort();
 
    } else {
 
@@ -474,6 +457,8 @@ int main(int argc,char **argv) {
 
      QString qmess(error_message.str().c_str());
 
      QMessageBox::critical(0, "I/O Error", qmess );
 
      abort();
 
    }
 
  }
 
}
 

	
 
/* finis */
src/apoplastitem.cpp
Show inline comments
 
@@ -63,13 +63,13 @@ void ApoplastItem::setColor(void) {
 
	
 
	Wall *w=&getWall();
 
	double val = w->getApoplast(2);
 

	
 
	diffcolor.setRgb( 0,0,(int)( ( val / (1 + val) )*255.));
 
	setPen (QPen(diffcolor, 20) );
 

	
 
}
 

	
 
void ApoplastItem::OnClick(QMouseEvent *e) {
 
  e = NULL; // merely to obviate compilation warnings
 
}
 

	
 
/* finis*/
src/apoplastitem.h
Show inline comments
 
@@ -20,12 +20,13 @@
 
 *  Copyright 2010 Roeland Merks.
 
 *
 
 */
 

	
 
#ifndef _APOPLASTITEM_H_
 
#define _APOPLASTITEM_H_
 

	
 
#include <QGraphicsScene>
 
#include <QGraphicsLineItem>
 
#include <QPainter>
 
#include <qpainter.h>
 
#include <QMouseEvent>
 
#include "simitembase.h"
 
@@ -43,6 +44,8 @@ public:
 
	void setColor(void);
 
private:
 
	int wn;
 
};
 

	
 
#endif
 

	
 
/* finis*/
src/build_models/auxingrowthplugin.cpp
Show inline comments
 
@@ -34,13 +34,14 @@
 
static const std::string _module_id("$Id$");
 

	
 
bool batch = false;
 

	
 

	
 
// To be executed after cell division
 
void AuxinGrowthPlugin::OnDivide(ParentInfo *parent_info, CellBase *daughter1, CellBase *daughter2) {
 
void AuxinGrowthPlugin::OnDivide(ParentInfo *parent_info, CellBase *daughter1, CellBase *daughter2)
 
{
 
  parent_info = NULL; // merely to obviate compile time error
 

	
 
	// Auxin distributes between parent and daughter according to area
 
	double area1 = daughter1->Area(), area2 = daughter2->Area();
 
	double tot_area = area1 + area2;
 
	
 
@@ -54,44 +55,44 @@ void AuxinGrowthPlugin::OnDivide(ParentI
 
	
 
	// Reset transporter values of parent and daughter
 
	QList<WallBase *> walls;
 
	foreach(WallBase *w, walls) { 
 
		w->setTransporter(daughter1, 1, 0.);
 
	}
 
	
 
}
 

	
 
void AuxinGrowthPlugin::SetCellColor(CellBase *c, QColor *color) { 
 
void AuxinGrowthPlugin::SetCellColor(CellBase *c, QColor *color)
 
{ 
 

	
 
	// Red: PIN1
 
	// Green: Auxin
 
	if (c->CellType()==1) color->setNamedColor("Blue"); 
 
	else color->setRgb(c->Chemical(1)/(1+c->Chemical(1)) * 255.,(c->Chemical(0)/(1+c->Chemical(0)) * 255.),/* (chem[2]/(1+chem[2]) *255.) */ 0);
 
	
 
  if (c->CellType()==1)
 
    color->setNamedColor("Blue"); 
 
  else 
 
    color->setRgb(c->Chemical(1)/(1+c->Chemical(1)) * 255.,(c->Chemical(0)/(1+c->Chemical(0)) * 255.), 0);
 
}
 

	
 

	
 

	
 
void AuxinGrowthPlugin::CellHouseKeeping(CellBase *c) {
 

	
 
void AuxinGrowthPlugin::CellHouseKeeping(CellBase *c)
 
{
 
	if (c->Boundary()==CellBase::None) {
 
		if (c->Area() > par->rel_cell_div_threshold * c->BaseArea() ) {
 
			c->SetChemical(0,0);
 
			c->Divide();
 
        }		
 
		if (c->Chemical(0)>0.6) {
 
			c->SetCellType(1);
 
		} 
 
		// expand according to auxin concentration
 
   		c->EnlargeTargetArea(par->auxin_dependent_growth?(c->Chemical(0)/(1.+c->Chemical(0)))*par->cell_expansion_rate:par->cell_expansion_rate);
 
	}  
 
	
 

	
 
}
 

	
 
void AuxinGrowthPlugin::CelltoCellTransport(Wall *w, double *dchem_c1, double *dchem_c2) {
 
void AuxinGrowthPlugin::CelltoCellTransport(Wall *w, double *dchem_c1, double *dchem_c2)
 
{
 

	
 
	// leaf edge is const source of auxin
 
    // (Neumann boundary condition: we specify the influx)
 
    if (w->C2()->BoundaryPolP()) {
 
		if (w->AuxinSource()) {
 
			double aux_flux = par->leaf_tip_source * w->Length();
 
@@ -99,13 +100,12 @@ void AuxinGrowthPlugin::CelltoCellTransp
 
			return;
 
		} else {
 
			return;
 
		}
 
	}
 
	
 
	
 
	if (w->C1()->BoundaryPolP()) {
 
		
 
		if (w->AuxinSource()) {
 
			double aux_flux = par->leaf_tip_source * w->Length();
 
			dchem_c2[0] += aux_flux;
 
			return;
 
@@ -143,16 +143,14 @@ void AuxinGrowthPlugin::CelltoCellTransp
 
    
 
    dchem_c1[0] += trans21 - trans12;
 
    dchem_c2[0] += trans12 - trans21;
 
	
 
}
 

	
 
void AuxinGrowthPlugin::WallDynamics(Wall *w, double *dw1, double *dw2) {
 

	
 
	
 
	
 
void AuxinGrowthPlugin::WallDynamics(Wall *w, double *dw1, double *dw2)
 
{
 
    // Cells polarize available PIN1 to Shoot Apical Meristem
 
    if (w->C2()->BoundaryPolP()) {
 
		if (w->AuxinSink()) {
 
			
 
			dw1[0] = 0.; dw2[0] = 0.;
 
            
 
@@ -224,25 +222,28 @@ void AuxinGrowthPlugin::WallDynamics(Wal
 
    
 
    dw1[0] = 0.; dw2[0] = 0.;
 
    dw1[1] = dPijdt1;
 
    dw2[1] = dPijdt2;
 
}
 

	
 
double AuxinGrowthPlugin::complex_PijAj(CellBase *here, CellBase *nb, Wall *w) { 
 
	
 
double AuxinGrowthPlugin::complex_PijAj(CellBase *here, CellBase *nb, Wall *w)
 
{ 
 
	// gives the amount of complex "auxinreceptor-Pin1"  at the wall (at QSS) 
 
	//return here.Chemical(1) * nb.Chemical(0) / ( par->km + here.Chemical(1));
 
	
 
	double nb_aux = (nb->BoundaryPolP() && w->AuxinSink()) ? par->sam_auxin : nb->Chemical(0);
 
	double receptor_level = nb_aux * par->r / (par->kr + nb_aux);
 
	
 
	return here->Chemical(1) * receptor_level / ( par->km + here->Chemical(1));
 
	
 
}
 

	
 
void AuxinGrowthPlugin::CellDynamics(CellBase *c, double *dchem) {
 

	
 
void AuxinGrowthPlugin::CellDynamics(CellBase *c, double *dchem)
 
{
 
	// Note: Pi and Pij measured in numbers of molecules, not concentrations		
 
		double dPidt = 0.;
 
		
 
		double sum_Pij = c->SumTransporters( 1 );
 
		
 
		// exocytosis regulated:
 
@@ -257,18 +258,14 @@ void AuxinGrowthPlugin::CellDynamics(Cel
 
			dchem[1]=0.;
 
		dchem[0]= - par->sam_auxin_breakdown * c->Chemical(0);
 
	} else {
 
		
 
		dchem[1] = dPidt;
 
		
 
		
 
		// source of auxin
 
		dchem[0] = par->aux_cons - par->aux_breakdown * c->Chemical(0);
 
		>
 
  }
 
	}
 
	
 
	
 
Q_EXPORT_PLUGIN2(auxingrowthplugin, AuxinGrowthPlugin)
 
	
 
}
 

	
 

	
 
Q_EXPORT_PLUGIN2(auxingrowthplugin, AuxinGrowthPlugin)
 
/* finis */
src/build_models/auxingrowthplugin.h
Show inline comments
 
@@ -58,6 +58,8 @@ public:
 
	
 
private:
 
	double complex_PijAj(CellBase *here, CellBase *nb, Wall *w);
 
};
 

	
 
#endif
 

	
 
/* finis */
src/build_models/meinhardtplugin.cpp
Show inline comments
 
@@ -51,13 +51,12 @@ void MeinhardtPlugin::SetCellColor(CellB
 
		if (c->Chemical(0)<range_min) {
 
			MyWarning::warning("Whoops! Numerical instability!!");
 
			color->setNamedColor("blue");
 
		} else {
 
			color->setRgb(c->Chemical(1)/(1+c->Chemical(1)) * 255.,(c->Chemical(0)/(1+c->Chemical(0)) * 255.),(c->Chemical(3)/(1+c->Chemical(3)) *255.) );
 
		}
 
		
 
	}
 
}
 

	
 

	
 

	
 
void MeinhardtPlugin::CellHouseKeeping(CellBase *c) {
 
@@ -74,13 +73,12 @@ void MeinhardtPlugin::CellHouseKeeping(C
 
			double tmp;
 
			c->EnlargeTargetArea((tmp=(1.-par->vessel_inh_level*c->Chemical(3))*par->cell_expansion_rate /* + c->Chemical(4)*/)<0?0:tmp); 
 
		} else {
 
			c->EnlargeTargetArea(par->vessel_expansion_rate);
 
		}
 
	} 
 
    
 
}
 

	
 
void MeinhardtPlugin::CelltoCellTransport(Wall *w, double *dchem_c1, double *dchem_c2) {
 
	
 
	// No flux boundaries for all chemicals, except activator: boundary is sink
 
  if (w->C1()->BoundaryPolP() || w->C2()->BoundaryPolP()) {
 
@@ -97,14 +95,12 @@ void MeinhardtPlugin::CelltoCellTranspor
 
    // Passive fluxes (Fick's law)
 
    for (int c=0;c<NChem();c++) {
 
		double phi = w->Length() * ( par->D[c] ) * ( w->C2()->Chemical(c) - w->C1()->Chemical(c) );
 
		dchem_c1[c] += phi; 
 
		dchem_c2[c] -= phi;
 
	}
 
   
 

	
 
}
 

	
 
void MeinhardtPlugin::WallDynamics(Wall *w, double *dw1, double *dw2) {
 
  w = NULL;
 
	for (int c = 0;c<NChem();c++) {
 
		dw1[c] = 0.; dw2[c] = 0.;
 
@@ -115,16 +111,16 @@ void MeinhardtPlugin::CellDynamics(CellB
 

	
 
	double Y = c->Chemical(0);
 
	double A = c->Chemical(1);
 
	double H = c->Chemical(2);
 
	double S = c->Chemical(3);
 

	
 
	
 
	
 
    dchem[0] = ( par->d * A - par->e * Y + Y*Y/(1 + par->f * Y*Y ) );
 
	dchem[1] = ( par->c * A*A*S/H - par->mu * A + par->rho0*Y );
 
	dchem[2] = ( par->c * A*A*S - par->nu*H + par->rho1*Y );
 
	dchem[3] = ( par->c0 - par->gamma*S - par->eps * Y * S );
 
}
 

	
 

	
 
Q_EXPORT_PLUGIN2(meinhardtplugin, MeinhardtPlugin)
 

	
 
/* finis */
src/build_models/meinhardtplugin.h
Show inline comments
 
@@ -55,6 +55,8 @@ public:
 
	virtual void SetCellColor(CellBase *c, QColor *color);	
 
	// return number of chemicals
 
	virtual int NChem(void) { return 4; }
 
};
 

	
 
#endif
 

	
 
/* finis */
src/build_models/testplugin.cpp
Show inline comments
 
@@ -72,6 +72,8 @@ void TestPlugin::WallDynamics(Wall *w, d
 
void TestPlugin::CellDynamics(CellBase *c, double *dchem) {
 
  c = NULL;
 
  dchem=NULL;
 
}
 

	
 
Q_EXPORT_PLUGIN2(testplugin, TestPlugin)
 

	
 
/* finis */
src/build_models/testplugin.h
Show inline comments
 
@@ -55,6 +55,8 @@ public:
 
	virtual void SetCellColor(CellBase *c, QColor *color);	
 
	// return number of chemicals
 
	virtual int NChem(void) { return 0; }
 
};
 

	
 
#endif
 

	
 
/* finis */
src/build_models/translate_plugin.pl
Show inline comments
 
@@ -72,7 +72,9 @@ while (<pfile>) {
 
	
 
	s/\bplugin\b\.h/plugin_tl\.h/g;
 
	s/\bplugin\b\.cpp/plugin_tl\.cpp/g;
 
	
 
	print opfile;
 
	
 
}
 
\ No newline at end of file
 
}
 

	
 
#finis
src/canvas.cpp
Show inline comments
 
@@ -16,14 +16,12 @@
 
 *  along with the Virtual Leaf.  If not, see <http://www.gnu.org/licenses/>.
 
 *
 
 *  Copyright 2010 Roeland Merks.
 
 *
 
 */
 

	
 
#include <QDebug>
 

	
 
#include <string>
 
#include <QGraphicsScene>
 
#include <QGraphicsView>
 
#include <qdatetime.h>
 
#include <q3mainwindow.h>
 
#include <qstatusbar.h>
 
@@ -131,26 +129,26 @@ void FigureEditor::scaleView (qreal scal
 
{
 
  qreal factor = matrix().scale(scaleFactor, scaleFactor).mapRect(QRectF(0, 0, 1, 1)). width();
 
  if (factor < 0.07 || factor > 100) return;
 
  scale (scaleFactor, scaleFactor);
 
}
 

	
 
void FigureEditor::Save(const char *fname, const char *format, int sizex, int sizey) {
 
void FigureEditor::Save(const char *fname, const char *format, int sizex, int sizey)
 
{
 
  
 
    QImage *image = new QImage(sizex, sizey, QImage::Format_RGB32);
 
    image->fill(QColor(Qt::white).rgb());
 
    QPainter *painter=new QPainter(image);
 
    
 
    render(painter);
 
    
 
    image->save(QString(fname),format);
 
    delete painter;
 
    delete image;
 
}
 

	
 
//void FigureEditor::contentsMousePressEvent(QMouseEvent* e)
 
void FigureEditor::mousePressEvent(QMouseEvent* e)
 
{
 
  static QList<Node*> selected;
 
  emit MousePressed();
 

	
 
  //QPointF p = matrix().inverted().map(e->pos());
 
@@ -207,13 +205,12 @@ void FigureEditor::mousePressEvent(QMous
 
    }
 

	
 
  FullRedraw();
 
  moving = 0;
 
}
 
  
 
//void FigureEditor::contentsMouseMoveEvent(QMouseEvent* e)
 
void FigureEditor::mouseMoveEvent(QMouseEvent* e)
 
{
 

	
 
  // User choose "rotation mode" and we can rotate the object around its center of mass
 
  if (dynamic_cast<Main *>(parent())->RotationModeP()) {
 

	
 
@@ -389,14 +386,14 @@ void FigureEditor::mouseReleaseEvent(QMo
 
      } 
 
    }
 
}
 

	
 

	
 
// returns a vector of pointer to cells colliding with intersection line
 
vector <CellItem *> FigureEditor::getIntersectedCells(void) { 
 
  
 
vector <CellItem *> FigureEditor::getIntersectedCells(void)
 
{ 
 
  vector <CellItem *> colliding_cells;
 
  
 
  QList<QGraphicsItem *> l = intersection_line->collidingItems( );
 
  
 
  #ifdef QDEBUG
 
  qDebug() <<  "l.size() = " << l.size() << endl;
 
@@ -413,16 +410,16 @@ vector <CellItem *> FigureEditor::getInt
 
    }
 
  }
 
  
 
  delete intersection_line;
 
  intersection_line = 0;
 
  return colliding_cells;
 
    
 
}
 

	
 
void FigureEditor::FullRedraw(void) {
 
void FigureEditor::FullRedraw(void)
 
{
 
	QList<QRectF> rl;
 
	rl << sceneRect();
 
	updateScene(rl);   
 
}
 

	
 

	
 
@@ -582,37 +579,34 @@ Main::Main(QGraphicsScene& c, Mesh &m, Q
 
  statusBar()->addWidget(new QLabel("Ready."));
 
  setCaption(caption);
 
  gifanim = 0;
 
	
 
	infobar = new InfoBar();
 
	addDockWindow(infobar);
 

	
 
}
 

	
 
void Main::RefreshInfoBar(void) {
 
void Main::RefreshInfoBar(void)
 
{
 
	infobar->SetText(mesh.ModelID());
 
}
 

	
 

	
 
void Main::UserMessage(QString message, int timeout) {
 

	
 
void Main::UserMessage(QString message, int timeout)
 
{
 
  statusBar()->showMessage(message, timeout);
 

	
 
}
 

	
 

	
 
void Main::init()
 
{
 
  clear();
 
  
 
  static int r=24;
 
  srand(++r);
 
  
 
  mainCount++;
 
  
 
  
 
}
 

	
 
Main::~Main()
 
{
 
  delete printer;
 
  if ( !--mainCount ) {
 
@@ -627,24 +621,25 @@ void Main::newView()
 
  qApp->setMainWidget(m);
 
  m->show();
 
  qApp->setMainWidget(0);
 
}
 

	
 

	
 
void Main::EditParameters() {
 
void Main::EditParameters()
 
{
 
  
 
  ParameterDialog *pardial = new ParameterDialog(this, "stridediag");
 

	
 
  // Make sure the values in the parameter dialog are updated after a file is read 
 
  // each method changing the parameters (reading XML or PAR files) should
 
  // emit this signal
 
  QObject::connect(   this, SIGNAL( ParsChanged() ), pardial, SLOT( Reset() ) );
 

	
 
}
 

	
 
void Main::savePars() {
 
void Main::savePars()
 
{
 
  
 
  stopSimulation();
 
  
 
  Q3FileDialog *fd = new Q3FileDialog( this, "file dialog", TRUE );
 
  fd->setMode( Q3FileDialog::AnyFile );
 
  fd->setFilter( "Parameter files (*.par)");
 
@@ -654,16 +649,16 @@ void Main::savePars() {
 
    fileName = fd->selectedFile();
 
    ofstream parfile((const char *)fileName);
 
    par.Write(parfile);
 
  }
 

	
 
  startSimulation();
 

	
 
}
 

	
 
void Main::readPars() {
 
void Main::readPars()
 
{
 
  
 
  stopSimulation();
 
  
 
  Q3FileDialog *fd = new Q3FileDialog( this, "file dialog", TRUE );
 
  fd->setMode( Q3FileDialog::ExistingFile );
 
  fd->setFilter( "Parameter files (*.par)");
 
@@ -674,17 +669,17 @@ void Main::readPars() {
 
    par.Read((const char *)fileName);
 
  }
 
  
 
  emit ParsChanged();
 
  /* if (timer_active)
 
     timer->start( 0 );*/
 
  
 
}
 

	
 

	
 
void Main::saveStateXML() {
 
void Main::saveStateXML()
 
{
 
  
 
  stopSimulation();
 
  Q3FileDialog *fd = new Q3FileDialog( this, "file dialog", TRUE );
 
  fd->setMode( Q3FileDialog::AnyFile );
 
  fd->setFilter( "XML (*.xml)");
 
  QString fileName;
 
@@ -705,18 +700,18 @@ void Main::saveStateXML() {
 
    } else {
 
      
 
      mesh.XMLSave((const char *)fileName, XMLSettingsTree());
 
    
 
    }
 
  }
 

	
 
}
 

	
 

	
 

	
 
void Main::snapshot() {
 
void Main::snapshot()
 
{
 
  
 
   
 
  stopSimulation();
 
  Q3FileDialog *fd = new Q3FileDialog( this, "Save snapshot", TRUE );
 
  fd->setMode( Q3FileDialog::AnyFile );
 
  
 
@@ -741,18 +736,18 @@ void Main::snapshot() {
 
		QString extension = getExtension(fileName);
 
		
 
		// Save bitmaps at 1024x768
 
		Save((const char *)fileName, extension, 1024, 768);
 
    }
 
  }
 

	
 
}
 

	
 
 
 

	
 
void Main::readPrevStateXML() {
 
void Main::readPrevStateXML()
 
{
 
  
 
  // if we have already read a file, read the next file
 
  if (!currentFile.isEmpty() && working_dir) {
 
    QString next_file;
 
    
 
    QStringList xml_files = working_dir->entryList("*.xml");
 
@@ -780,13 +775,14 @@ void Main::readPrevStateXML() {
 
    
 
    readStateXML((const char *)next_file);
 
    
 
  }
 
}
 

	
 
int Main::readStateXML(const char *filename, bool geometry, bool pars, bool simtime) {
 
int Main::readStateXML(const char *filename, bool geometry, bool pars, bool simtime)
 
{
 
 
 
  try {
 
    xmlNode *settings;
 
    mesh.XMLRead((const char *)filename, &settings, geometry, pars, simtime);
 
    #ifdef QDEBUG
 
    qDebug() << "Reading done."<< endl;
 
@@ -817,17 +813,17 @@ int Main::readStateXML(const char *filen
 
		    QMessageBox::Ok | QMessageBox::Default,
 
		    Qt::NoButton,
 
		    Qt::NoButton);
 
    mb.exec();
 
    return 1;
 
  }
 
  
 
}
 

	
 

	
 
void Main::readNextStateXML() {
 
void Main::readNextStateXML()
 
{
 
  
 
  // if we have already read a file, read the next file
 
  if (!currentFile.isEmpty() && working_dir) {
 
    QString next_file;
 
    
 
    QStringList xml_files = working_dir->entryList("*.xml");
 
@@ -854,17 +850,16 @@ void Main::readNextStateXML() {
 
    }
 
    next_file = *f;
 
    next_file = currentFile_path+"/"+next_file;
 

	
 
    readStateXML((const char*)next_file);
 
  }
 
  
 
  
 
}
 

	
 
void Main::readLastStateXML() {
 
void Main::readLastStateXML()
 
{
 
  
 
  // if we have already read a file, read the next file
 
  if (!currentFile.isEmpty() && working_dir) {
 
    QString next_file;
 
    
 
    QStringList xml_files = working_dir->entryList("*.xml");
 
@@ -875,18 +870,17 @@ void Main::readLastStateXML() {
 
    next_file = xml_files.back();
 
    
 
    next_file = currentFile_path+"/"+next_file;
 

	
 
    readStateXML((const char*)next_file);
 
  }
 
  
 
  
 
}
 

	
 

	
 
void Main::readFirstStateXML() {
 
void Main::readFirstStateXML()
 
{
 
  
 
  // if we have already read a file, read the next file
 
  if (!currentFile.isEmpty() && working_dir) {
 
    QString next_file;
 
    
 
    QStringList xml_files = working_dir->entryList("*.xml");
 
@@ -897,17 +891,16 @@ void Main::readFirstStateXML() {
 
    next_file = xml_files.front();
 
    
 
    next_file = currentFile_path+"/"+next_file;
 

	
 
    readStateXML((const char*)next_file);
 
  }
 
  
 
  
 
}
 

	
 
void Main::readStateXML() {
 
void Main::readStateXML()
 
{
 

	
 
  //  extern Mesh mesh;
 

	
 
  stopSimulation();
 
  #ifdef QDEBUG
 
  qDebug() << "Trying to open an OptionFileDialog" << endl;
 
@@ -953,76 +946,87 @@ void Main::help()
 
      "Pilot release for WUR/Biometris, 21-10-2009 <br>", 
 
      QMessageBox::Information, 1, 0, 0, this, 0, FALSE );
 
  about->setButtonText( 1, "Dismiss" );
 
  about->show();
 
}
 

	
 
  void Main::aboutQt()
 
  {
 
void Main::aboutQt(){
 
    QMessageBox::aboutQt( this, "Virtual Leaf" );
 
  }
 

	
 
  void Main::toggleShowCellCenters()
 
  {
 
    Plot();
 
  }
 

	
 
  void Main::toggleShowWalls()
 
  {
 
    Plot();
 
  }
 

	
 
void Main::toggleShowApoplasts()
 
{
 
    Plot();
 
}
 

	
 
  void Main::toggleShowNodes()
 
  {
 
    Plot();
 
  }
 

	
 
  void Main::toggleNodeNumbers(void) {
 
void Main::toggleNodeNumbers(void)
 
{
 
    Plot();
 
  }
 

	
 
  void Main::toggleCellNumbers(void) {
 
void Main::toggleCellNumbers(void)
 
{
 
    Plot();
 
  }
 

	
 
  void Main::toggleCellAxes(void) {
 
void Main::toggleCellAxes(void)
 
{
 
    Plot();
 
  }
 

	
 
  void Main::toggleCellStrain(void) {
 
void Main::toggleCellStrain(void)
 
{
 
    Plot();
 
  }
 

	
 
  void Main::toggleShowFluxes(void) {
 
void Main::toggleShowFluxes(void)
 
{
 
    Plot();
 
  }
 

	
 
  void Main::toggleShowBorderCells(){
 
void Main::toggleShowBorderCells()
 
{
 
    Plot();
 
  }
 

	
 
void Main::toggleHideCells(void) {
 
void Main::toggleHideCells(void)
 
{
 
	Plot();
 
	editor->FullRedraw();
 
}
 

	
 
  void Main::toggleMovieFrames(){}
 

	
 
  void Main::toggleLeafBoundary(){}
 

	
 
  void Main::toggleDynCells() {}
 
  
 
  void Main::startSimulation(void) {
 
void Main::startSimulation(void)
 
{
 
    timer->start( 0 );
 
    statusBar()->message("Simulation started");
 
    running = true;
 
  }
 

	
 
  void Main::stopSimulation(void) {
 
void Main::stopSimulation(void)
 
{
 
    timer->stop();
 
    cerr << "Stopping simulation" << endl;
 
    statusBar()->message("Simulation paused");
 
    running = false;
 
  }
 

	
 
@@ -1035,14 +1039,14 @@ void Main::toggleHideCells(void) {
 
    } else {
 
      cerr << "Calling stop simulation" << endl;
 
      stopSimulation();
 
    }
 
  }
 

	
 
  void Main::setFluxArrowSize(int size) {
 
  
 
void Main::setFluxArrowSize(int size)
 
{
 
    flux_arrow_size = size/100.;
 
  }
 

	
 

	
 
  void Main::enlarge()
 
  {
 
@@ -1052,13 +1056,14 @@ void Main::toggleHideCells(void) {
 
  void Main::shrink()
 
  {
 
    canvas.setSceneRect( QRectF( 0,0, canvas.width()*3/4, canvas.height()*3/4) );
 
  }
 

	
 

	
 
  void Main::scale(double factor) {
 
void Main::scale(double factor)
 
{
 
    QMatrix m = editor->matrix();
 
    m.scale(factor, factor);
 
    editor->setMatrix( m );
 
  }
 

	
 
  void Main::zoomIn()
 
@@ -1107,25 +1112,26 @@ void Main::toggleHideCells(void) {
 
      }
 
      canvas.render(&pp, QRectF(), QRectF(0.,0.,canvas.width(),canvas.height()));
 
    }
 
  }
 

	
 

	
 
  void Main::TimeStepWrap(void) {
 
  
 
void Main::TimeStepWrap(void)
 
{
 
    static int t=0;
 
    TimeStep();
 
    t++;
 
    // check number of timesteps
 
    if (t==par.nit) {
 
      emit SimulationDone();
 
    }
 
  }
 

	
 

	
 
  void Main::RestartSim(void) {
 
void Main::RestartSim(void)
 
{
 

	
 
    stopSimulation();
 
    if ( QMessageBox::question(
 
			       this,
 
			       tr("Restart simulation?"),
 
			       tr("Restart simulation.\n"
 
@@ -1140,13 +1146,14 @@ void Main::toggleHideCells(void) {
 
		editor->FullRedraw();
 
    } 
 
    //startSimulation();
 
  }
 

	
 

	
 
void Main::FitCanvasToWindow(void) {
 
void Main::FitCanvasToWindow(void)
 
{
 
  
 
  double scale_factor_x = (double)editor->width()/(double)canvas.width();
 
  double scale_factor_y = (double)editor->height()/(double)canvas.height();
 
  double scale_factor = scale_factor_x > scale_factor_y ? scale_factor_x : scale_factor_y;
 
  QMatrix m = editor->matrix();
 

	
 
@@ -1160,25 +1167,28 @@ void Main::FitCanvasToWindow(void) {
 
  #endif
 
  m.scale( scale_factor, scale_factor );
 
  editor->setMatrix( m );
 
  editor->show();
 
}
 

	
 
  void Main::PauseIfRunning(void) {
 
void Main::PauseIfRunning(void)
 
{
 
    if (running) {
 
      timer->stop();
 
    }
 
  }
 

	
 
  void Main::ContIfRunning(void) {
 
void Main::ContIfRunning(void)
 
{
 
    if (running) {
 
      timer->start( 0 );
 
    }
 
  }
 

	
 
void Main::FitLeafToCanvas(void) {
 
void Main::FitLeafToCanvas(void) 
 
{
 

	
 
  Vector ll,ur;
 
  mesh.BoundingBox(ll, ur);
 
  
 
  ll*=Cell::Magnification(); ur*=Cell::Magnification();
 
  
 
@@ -1189,13 +1199,14 @@ void Main::FitLeafToCanvas(void) {
 
  
 
  
 
  // cerr << ur << ", " << ll << endl;
 
  editor->fitInView(bb, Qt::KeepAspectRatio);
 
}
 

	
 
void Main::CleanMesh(void) {
 
void Main::CleanMesh(void) 
 
{
 
	vector<double> clean_chem(Cell::NChem());
 
	vector<double> clean_transporters(Cell::NChem());
 

	
 
	for (int i=0;i<Cell::NChem();i++) {
 
		clean_chem[i]=par.initval[i];
 
		clean_transporters[i]=0.;		
 
@@ -1207,13 +1218,14 @@ void Main::CleanMesh(void) {
 
	mesh.setTime(0);
 
	Plot();
 
	
 
	editor->FullRedraw();
 
}
 

	
 
void Main::CleanMeshChemicals(void) {
 
void Main::CleanMeshChemicals(void) 
 
{
 
	
 
	vector<double> clean_chem(Cell::NChem());
 

	
 
	for (int i=0;i<Cell::NChem();i++) {
 
		clean_chem[i]=par.initval[i];
 
	}
 
@@ -1222,13 +1234,14 @@ void Main::CleanMeshChemicals(void) {
 
	mesh.setTime(0);
 
	Plot();
 
	
 
	editor->FullRedraw();
 
}
 

	
 
void Main::CleanMeshTransporters(void) {
 
void Main::CleanMeshTransporters(void) 
 
{
 
	vector<double> clean_transporters(Cell::NChem());
 
	for (int i=0;i<Cell::NChem();i++) {
 
		clean_transporters[i]=0.;
 
	}
 
	
 
	mesh.CleanTransporters(clean_transporters);
 
@@ -1236,13 +1249,14 @@ void Main::CleanMeshTransporters(void) {
 
	mesh.setTime(0);
 
	Plot();
 
	
 
	editor->FullRedraw();
 
}
 

	
 
void Main::RandomizeMesh(void) {
 
void Main::RandomizeMesh(void) 
 
{
 
  
 
  vector<double> max_chem(Cell::NChem());
 
  vector<double> max_transporters(Cell::NChem());
 
  
 
  for (int i=0;i<Cell::NChem();i++) {
 
    max_transporters[i]=0.;
 
@@ -1254,13 +1268,14 @@ void Main::RandomizeMesh(void) {
 
  
 
  mesh.RandomizeChemicals(max_chem, max_transporters);
 
  
 
  Plot();
 
}
 

	
 
void Main::XMLReadSettings(xmlNode *settings) {
 
void Main::XMLReadSettings(xmlNode *settings) 
 
{
 
  
 
  MainBase::XMLReadSettings(settings);
 

	
 
  view->setItemChecked(com_id, showcentersp);
 
  view->setItemChecked(mesh_id, showmeshp);
 
  view->setItemChecked(border_id, showbordercellp);
 
@@ -1274,13 +1289,14 @@ void Main::XMLReadSettings(xmlNode *sett
 
  view->setItemChecked(hide_cells_id, hidecellsp);
 
  options->setItemChecked(dyn_cells_id, dynamicscellsp);
 
  view->setItemChecked( cell_walls_id, showwallsp);
 
	view->setItemChecked( apoplasts_id, showapoplastsp);
 
}
 

	
 
xmlNode *Main::XMLSettingsTree(void) {
 
xmlNode *Main::XMLSettingsTree(void) 
 
{
 

	
 
  showcentersp = view->isItemChecked(com_id);
 
  showmeshp = view->isItemChecked(mesh_id);
 
  showbordercellp =  view->isItemChecked(border_id);
 
  shownodenumbersp =  view->isItemChecked(node_number_id);
 
  showcellnumbersp =  view->isItemChecked(cell_number_id);
 
@@ -1295,7 +1311,6 @@ xmlNode *Main::XMLSettingsTree(void) {
 
  hidecellsp = view->isItemChecked( hide_cells_id);
 

	
 
  return MainBase::XMLSettingsTree();
 
}
 

	
 
/* finis */
 

	
src/canvas.h
Show inline comments
 
@@ -125,13 +125,14 @@ class Main : public Q3MainWindow, public
 
  virtual bool DynamicCellsP(void) { return options->isItemChecked(dyn_cells_id); }
 
  virtual bool RotationModeP(void) { return options->isItemChecked(rotation_mode_id); }
 
  virtual bool InsertModeP(void) { return options->isItemChecked(insert_mode_id); }
 
  virtual bool ShowToolTipsP(void) { return helpmenu->isItemChecked(tooltips_id); }
 
  virtual bool HideCellsP(void) { return view->isItemChecked(hide_cells_id); }
 
  void scale(double factor); 
 
  virtual double getFluxArrowsize(void) {
 
  virtual double getFluxArrowsize(void)
 
  {
 
    return flux_arrow_size;
 
  }
 
    
 
  void FitCanvasToWindow();
 
  void FitLeafToCanvas(void);
 

	
 
@@ -159,24 +160,26 @@ class Main : public Q3MainWindow, public
 
  void toggleHideCells(void);
 
  void print();
 
  void startSimulation(void);
 
  void stopSimulation(void);
 
  void RefreshInfoBar(void);
 

	
 
  void EnterRotationMode(void) {
 
  void EnterRotationMode(void)
 
  {
 

	
 
    UserMessage("Rotation mode. Click mouse to exit.");
 
    if (editor) {
 
      editor->rot_angle = 0. ; 
 

	
 
      // Exit rotation mode if mouse is clicked
 
      connect(editor, SIGNAL(MousePressed()), this, SLOT(ExitRotationMode()));
 
    }
 
  
 
  }
 
  void ExitRotationMode(void) { 
 
  void ExitRotationMode(void)
 
  { 
 
    UserMessage("Exited rotation mode.",2000);
 

	
 
    options->setItemChecked(rotation_mode_id, false); 
 
    if (editor)
 
      disconnect(editor, SIGNAL(MousePressed()), this, SLOT(ExitRotationMode()));
 
  }
 
@@ -260,12 +263,11 @@ class Main : public Q3MainWindow, public
 
  QFile *gifanim;
 
  bool running;
 
  virtual xmlNode *XMLSettingsTree(void);
 
  static const QString caption;
 
  static const QString caption_with_file;
 
	InfoBar *infobar;
 

	
 
};
 

	
 

	
 
#endif
 

	
 
#endif
 
/* finis*/
src/cell.cpp
Show inline comments
 
@@ -37,41 +37,40 @@ static const std::string _module_id("$Id
 

	
 
extern Parameter par;
 

	
 
double Cell::factor=1.;
 
double Cell::offset[3]={0,0,0};
 

	
 
Cell::Cell(void) : CellBase() {
 

	
 
Cell::Cell(void) : CellBase()
 
{
 
	m=0;
 

	
 
}
 

	
 
Cell::Cell(double x, double y, double z) : CellBase(x,y,z) {
 

	
 
Cell::Cell(double x, double y, double z) : CellBase(x,y,z)
 
{
 
	m=0;
 
	
 
}
 

	
 
Cell::Cell(const Cell &src) :  CellBase(src) {
 
	
 
Cell::Cell(const Cell &src) :  CellBase(src)
 
{
 
	m=src.m;
 
}
 

	
 
bool Cell::Cmp(Cell *c) const { return this->Index() < c->Index(); }
 
bool Cell::Eq(Cell *c) const { return this->Index() == c->Index(); }
 

	
 
Cell Cell::operator=(const Cell &src) {
 
Cell Cell::operator=(const Cell &src) 
 
{
 
	CellBase::operator=(src);
 
	m=src.m;
 
	return *this;
 
}
 
//Cell(void) : CellBase() {}
 

	
 
void Cell::DivideOverAxis(Vector axis) {
 
	
 
void Cell::DivideOverAxis(Vector axis) 
 
{
 
	// Build a wall
 
	// ->  find the position of the wall
 
	
 
	// better look for intersection with a simple line intersection algorithm as below?
 
	// this leads to some exceptions: e.g. dividing a horizontal rectangle.
 
	// leaving it like this for the time being
 
@@ -96,21 +95,22 @@ void Cell::DivideOverAxis(Vector axis) {
 
			
 
		}		
 
		prev_cross_z=cross.z;
 
	}
 
	
 
	DivideWalls(new_node_locations, centroid, centroid+axis);
 
}
 
	
 
}
 
double Cell::MeanArea(void) {
 
double Cell::MeanArea(void)
 
{
 
	return m->MeanArea();
 
}
 

	
 

	
 
void Cell::Apoptose(void) {
 
	
 
void Cell::Apoptose(void)
 
{
 
	// First kill walls
 
        #ifdef QDEBUG
 
        qDebug() << "This is cell " << Index() << endl;
 
	qDebug() << "Number of walls: " << walls.size() << endl;
 
	#endif
 
	for (list<Wall *>::iterator w=walls.begin(); w!=walls.end(); w++) {
 
@@ -165,13 +165,12 @@ void Cell::Apoptose(void) {
 
		        #ifdef QDEBUG
 
		        qDebug() << "Not killing wall." << endl;
 
			qDebug() << "Wall " << (*w)->Index() << " says: c1 = " 
 
				 << (*w)->c1->Index() << ", c2 = " << (*w)->c2->Index() << endl;
 
                        #endif
 
		}
 
		
 
	}
 
	walls.remove(0);
 
	
 
	// Unregister me from my nodes, and delete the node if it no longer belongs to any cells
 
	list<Node *> superfluous_nodes;
 
	for (list<Node *>::iterator n=nodes.begin();
 
@@ -212,20 +211,18 @@ void Cell::Apoptose(void) {
 
				tmp.cell = m->boundary_polygon;
 
				no.owners.push_back(tmp);
 
			}
 
		}
 
	}
 
	
 
	
 
	
 
	// mark cell as dead
 
	MarkDead();
 
}
 

	
 
void Cell::ConstructConnections(void) {
 
	
 
void Cell::ConstructConnections(void)
 
{
 
    // Tie up the nodes of this cell, assuming they are correctly ordered
 
	
 
    //cerr << "Constructing connections of cell " << index << endl;
 
	
 
    for (list<Node *>::iterator i=nodes.begin();
 
		 i!=nodes.end();
 
@@ -258,40 +255,20 @@ void Cell::ConstructConnections(void) {
 
		next_iterator++;
 
		if (next_iterator==nodes.end()) {
 
			next=nodes.front();
 
		} else {
 
			next=*next_iterator;
 
		}
 
		
 
		//cerr << "[" << *i << "]";
 
		//if (*i==10 || *i==11) {
 
		//cerr << "previous = " << previous << ", next = " << next << endl;
 
		//}
 
		//if (*i!=10 && *i!=11)
 
		//cerr << "Node " << *i << endl << " = " << *(*i) << endl;
 
		(*i)->owners.push_back( Neighbor( this, previous, next ) );
 
		// if (*i==50 || *i==51) {
 
		//cerr << "Node " << *i << ".size() = " << (*i)->owners.size() << endl;
 
		// }
 
    }
 
}
 

	
 

	
 
/*! \brief Divide the cell over the line v1-v2.
 
 
 
 \param v1: First vertex of line.
 
 \param v2: Second vertex of line.
 
 \param fixed_wall: If true: wall will be set to "fixed" (i.e. not motile)
 
 \return: true if the cell divided, false if not (i.e. no intersection between v1 and v2, and the cell)
 
 */
 
bool Cell::DivideOverGivenLine(const Vector v1, const Vector v2, bool fix_cellwall, NodeSet *node_set ) {
 
	
 
bool Cell::DivideOverGivenLine(const Vector v1, const Vector v2, bool fix_cellwall, NodeSet *node_set )
 
{
 
	if (dead) return false;
 
	
 
	
 
	
 
	// check each edge for intersection with the line
 
	ItList new_node_locations;
 
	
 
	#ifdef QDEBUG
 
	qDebug() << "Cell " << Index() << " is doing DivideOverGivenLine" << endl;
 
	#endif
 
@@ -350,17 +327,17 @@ bool Cell::DivideOverGivenLine(const Vec
 
	}
 
	#endif
 

	
 
	DivideWalls(new_node_locations, v1, v2, fix_cellwall, node_set);
 
	
 
	return true;
 
	
 
}
 

	
 
// Core division procedure
 
void Cell::DivideWalls(ItList new_node_locations, const Vector from, const Vector to, bool fix_cellwall, NodeSet *node_set) {
 
void Cell::DivideWalls(ItList new_node_locations, const Vector from, const Vector to, bool fix_cellwall, NodeSet *node_set)
 
{
 
	
 
	if (dead) return;
 
	
 
	bool boundary_touched_flag=false;
 
	
 
	// Step 0: keep some data about the parent before dividing
 
@@ -384,22 +361,20 @@ void Cell::DivideWalls(ItList new_node_l
 
	daughter->cell_type = cell_type;
 
	
 
	for (int i=0;i<NChem();i++) {
 
		daughter->new_chem[i]=new_chem[i];
 
	}
 
	
 
	
 
	daughter->boundary=boundary;
 
	daughter->m=m;
 
	
 
	daughter->target_area=target_area/2.;
 
	
 
	target_area/=2;
 
	daughter->cellvec=cellvec;
 
	
 
	
 
	// Division currently only works for convex cells: i.e. if the division line
 
	// intersects the cells at two points only.
 
	if (new_node_locations.size()!=2) {
 
		
 
		// Note: if you would add the possibility of dividing non-convex
 
		// cells, remember to update the code below. There are some
 
@@ -423,13 +398,12 @@ void Cell::DivideWalls(ItList new_node_l
 
		m->cells.pop_back();
 
		Cell::NCells()--;
 
		m->shuffled_cells.pop_back();
 
		return;
 
	}
 
	
 
	
 
	// We can be sure we only need two positions here because divisions
 
	// of non-convex cells are rejected above.
 
	Vector new_node[2];
 
	Node *new_node_ind[2];
 
	
 
	int new_node_flag[2];
 
@@ -626,13 +600,15 @@ void Cell::DivideWalls(ItList new_node_l
 

	
 

	
 
                        #ifdef QDEBUG  
 
			list<Neighbor> unique_owners;
 
			copy(owners.begin(), owners.end(), back_inserter(unique_owners));
 
			unique_owners.unique( mem_fun_ref( &Neighbor::Eq ) );
 
			qDebug() << "The dividing edge nodes: " << div_edges[i].first->Index() << " and " << div_edges[i].second->Index() << " are owned by cells: ";
 
      qDebug() << "The dividing edge nodes: " << div_edges[i].first->Index() 
 
	       << " and " << div_edges[i].second->Index() << " are owned by cells: ";
 

	
 
			// spit out each owners' cell index
 
			foreach(Neighbor neighbor, unique_owners){
 
			  qDebug() << neighbor.cell->Index() << "  ";
 
			}
 
			qDebug() << endl;
 
                        #endif
 
@@ -654,13 +630,14 @@ void Cell::DivideWalls(ItList new_node_l
 
			  }
 
			} 
 

	
 
			if (edge_owners.size() > 1){
 
			  // Remove the boundary polygon - if its there
 
			  list<Neighbor>::iterator it;
 
			  if ((it = find_if (edge_owners.begin(), edge_owners.end(), bind2nd(mem_fun_ref(&Neighbor::CellEquals), -1))) != edge_owners.end()) {
 
	if ((it = find_if (edge_owners.begin(), edge_owners.end(), bind2nd(mem_fun_ref(&Neighbor::CellEquals), -1)))
 
	    != edge_owners.end()) {
 
                            #ifdef QDEBUG
 
			    qDebug() << "deleating: " << it->cell->Index() << " from the list of edge owners." << endl;
 
                            #endif
 
			    edge_owners.erase(it);
 
			  }
 
			}
 
@@ -842,12 +819,13 @@ void Cell::DivideWalls(ItList new_node_l
 
			// and remove them)
 
			list<Neighbor>::iterator neighb_with_this_cell=
 
			find_if((*i)->owners.begin(),
 
					(*i)->owners.end(),
 
				bind2nd(mem_fun_ref( &Neighbor::CellEquals ),this->Index() )  );
 
			if (neighb_with_this_cell==(*i)->owners.end()) {
 

	
 
			        #ifdef QDEBUG
 
			  qDebug() << "not found" << endl;
 
                                #endif
 
				abort();
 
			}
 
			
 
@@ -978,23 +956,19 @@ void Cell::DivideWalls(ItList new_node_l
 
	// this cell
 
	broken_neighbors.push_back(this);
 
	
 
	// its daughter
 
	broken_neighbors.push_back(daughter);
 
	
 
	
 
	
 
	// Recalculate area of parent and daughter
 
	area = CalcArea();
 
	daughter->area = daughter->CalcArea();
 
	
 
	SetIntegrals();
 
	daughter->SetIntegrals();
 
	
 
    
 
	
 
	// Add a "Cell Wall" for diffusion algorithms
 
	Wall *wall = new Wall( new_node_ind[0], new_node_ind[1], this, daughter );
 
	
 
	AddWall( wall );
 
	
 
	daughter->AddWall( wall );
 
@@ -1013,14 +987,12 @@ void Cell::DivideWalls(ItList new_node_l
 
		(*w)->CorrectWall ( );
 
		
 
		//cerr << "and after: " << **w << endl;
 
		
 
	}
 
	
 
	
 
	
 
	// Correct tranporterconcentrations of divided walls
 
	for (int i=0;i<4;i++) {
 
		if (div_wall[i]) {
 
			div_wall[i]->SetLength();
 
			div_wall[i]->CorrectTransporters(orig_length[i/2]);
 
		}
 
@@ -1032,34 +1004,32 @@ void Cell::DivideWalls(ItList new_node_l
 
	
 
	for (list<CellBase *>::iterator i=broken_neighbors.begin();
 
		 i!=broken_neighbors.end();i++) {
 
		((Cell *)(*i))->ConstructNeighborList();
 
	}
 
	
 
	
 
	ConstructNeighborList();
 
	daughter->ConstructNeighborList();
 
	
 
	m->plugin->OnDivide(&parent_info, daughter, this);
 
	
 
	daughter->div_counter=(++div_counter);
 
	
 
	
 
}
 

	
 
// Move the whole cell
 
void Cell::Move(const Vector T) {
 
	
 
    for (list<Node *>::const_iterator i=nodes.begin();
 
		 i!=nodes.end();
 
		 i++) {
 
		*(*i)+=T;
 
    }
 
}
 

	
 
double Cell::Displace(double dx, double dy, double dh) {
 
double Cell::Displace(double dx, double dy, double dh)
 
{
 
	
 
	// Displace whole cell, add resulting energy to dh,
 
	// and accept displacement if energetically favorable
 
	// 
 
	// Method is called if a "fixed" node is displaced
 
	
 
@@ -1155,19 +1125,20 @@ double Cell::Displace(double dx, double 
 
	}
 
	
 
	return dh;
 
}
 

	
 

	
 
void Cell::Displace (void) {
 
void Cell::Displace (void)
 
{
 
	Displace(par.mc_cell_stepsize*(RANDOM()-0.5),par.mc_cell_stepsize*(RANDOM()-0.5),0);
 
}
 

	
 
// Get energy level of whole cell (excluding length constraint?)
 
double Cell::Energy(void) const {
 
	
 
double Cell::Energy(void) const
 
{
 
	double energy = 0.;
 
	double length_contribution = 0.;
 
	
 
	for (list<Node *>::const_iterator i=nodes.begin();
 
		 i!=nodes.end();
 
		 i++) {
 
@@ -1190,26 +1161,23 @@ double Cell::Energy(void) const {
 
	energy += par.lambda_length * length_contribution;
 
	
 
	// area constraint
 
	energy += DSQR(CalcArea() - target_area);
 
	
 
	// cell length constraint
 
	
 
	
 
	energy += lambda_celllength * DSQR(Length() - target_length);
 
	
 
	
 
	return energy;
 
}
 

	
 

	
 

	
 

	
 

	
 
bool Cell::SelfIntersect(void) {
 
	
 
bool Cell::SelfIntersect(void)
 
{
 
    // The (obvious) O(N*N) algorithm
 
	
 
    // Compare each edge against each other edge
 
	
 
    // An O(N log(N)) algorithm by Shamos & Hoey (1976) supposedly exists;
 
    // it was mentioned on comp.graphics.algorithms
 
@@ -1262,13 +1230,14 @@ bool Cell::SelfIntersect(void) {
 
    }
 
	
 
    return false;
 
}
 

	
 

	
 
bool Cell::MoveSelfIntersectsP(Node *moving_node_ind, Vector new_pos) {
 
bool Cell::MoveSelfIntersectsP(Node *moving_node_ind, Vector new_pos)
 
{
 
	
 
	// Check whether the polygon will self-intersect if moving_node_ind 
 
	// were displaced to new_pos
 
	
 
	// Compare the two new edges against each other edge
 
	
 
@@ -1329,33 +1298,25 @@ bool Cell::MoveSelfIntersectsP(Node *mov
 
			if ( ( TINY < ua && ua < 1.-TINY ) && ( TINY < ub && ub < 1.-TINY ) ) {
 
				//cerr << "ua = " << ua << ", ub = " << ub << endl;
 
				return true;
 
			}
 
		}
 
	}
 
	
 
	return false;
 
}
 

	
 
/*! \brief Test if this cell intersects with the given line.
 
 
 
 */
 
bool Cell::IntersectsWithLineP(const Vector v1, const Vector v2) {
 
	
 
	
 
bool Cell::IntersectsWithLineP(const Vector v1, const Vector v2)
 
{
 
	// Compare the line against each edge
 
	
 
	// method used: http://astronomy.swin.edu.au/~pbourke/geometry/lineline2d/
 
	
 
	
 
	
 
	for (list<Node *>::const_iterator i=nodes.begin();
 
		 i!=nodes.end();
 
		 i++) 
 
  for (list<Node *>::const_iterator i=nodes.begin(); i!=nodes.end(); i++) 
 
    {
 
		
 
		Vector v3 = *(*i);
 
		list<Node *>::const_iterator nb=i;
 
		nb++;
 
		if (nb == nodes.end()) {
 
			nb = nodes.begin();
 
		}
 
@@ -1370,27 +1331,24 @@ bool Cell::IntersectsWithLineP(const Vec
 
		((v2.x - v1.x)*(v1.y-v3.y) - (v2.y- v1.y)*(v1.x - v3.x))/denominator;
 
		
 
		if ( ( TINY < ua && ua < 1.-TINY ) && ( TINY < ub && ub < 1.-TINY ) ) {
 
			return true;
 
		}
 
    }
 
	
 
	return false;
 
	
 
	
 
}
 
/*! \brief Constructs Walls, but only one per cell boundary.
 
 
 
 Standard method constructs a Wall for each cell wall element,
 
 making transport algorithms computationally more intensive than needed.
 
 
 
 We can remove this? Well, let's leave it in the code in case we need it for something else. E.g. for importing leaf architectures in different formats than our own... :-)
 
 
 
 */
 
void Cell::ConstructWalls(void) {
 
	
 
void Cell::ConstructWalls(void)
 
{
 
	return;
 
	if (dead) return;
 
	
 
	walls.clear();
 
	neighbors.clear();
 
	
 
@@ -1403,13 +1361,12 @@ void Cell::ConstructWalls(void) {
 
		// look for nodes belonging to >2 cells
 
		if ((*i)->owners.size()>2) {
 
			
 
			// push onto list
 
			corner_points.push_back(*i);
 
		}
 
		
 
	}
 
	
 
	// Construct Walls between corner points
 
	
 
	// previous one in list
 
	list<Node *>::const_iterator nb = (--corner_points.end());
 
@@ -1456,13 +1413,12 @@ void Cell::ConstructWalls(void) {
 
			vector<Cell *>::iterator dup_it = find_if(duplicates.begin(),duplicates.end(),mem_fun(&Cell::BoundaryPolP) );
 
			if (dup_it!=duplicates.end()) 
 
				duplicates.erase(dup_it);
 
			else {
 
				return;
 
			}
 
			
 
		}
 
		
 
		
 
		// One Wall for each neighbor, so we should be able to correctly construct neighbor lists here.
 
		if (duplicates[0]==this) {
 
			AddWall(  new Wall(*nb,*i,duplicates[0],duplicates[1]) );
 
@@ -1475,21 +1431,20 @@ void Cell::ConstructWalls(void) {
 
			if (!duplicates[0]->BoundaryPolP()) {
 
				neighbors.push_back(duplicates[0]);
 
				
 
			}
 
		}
 
	}
 
	
 
}
 

	
 

	
 
void BoundaryPolygon::Draw(QGraphicsScene *c, QString tooltip) {
 
void BoundaryPolygon::Draw(QGraphicsScene *c, QString tooltip)
 
{
 
	
 
	// Draw the BoundaryPolygon on a QCanvas object
 
	
 
	
 
	CellItem* p = new CellItem(this, c);
 
	
 
	QPolygonF pa(nodes.size());
 
	int cc=0;
 
	
 
	for (list<Node *>::const_iterator n=nodes.begin();
 
@@ -1498,28 +1453,25 @@ void BoundaryPolygon::Draw(QGraphicsScen
 
		Node *i=*n;
 
		
 
		pa[cc++] = QPoint((int)((Offset().x+i->x)*Factor()),
 
						  (int)((Offset().y+i->y)*Factor()) );
 
	}
 
	
 
	
 
	p->setPolygon(pa);
 
	p->setPen(par.outlinewidth>=0?QPen( QColor(par.cell_outline_color),par.outlinewidth):QPen(Qt::NoPen));
 
	p->setBrush( Qt::NoBrush );
 
	p->setZValue(1);
 
	
 
	if (!tooltip.isEmpty())
 
		p->setToolTip(tooltip);
 
	
 
	p->show();
 
	
 
}
 

	
 
void Cell::Flux(double *flux, double *D)  {
 
	
 
	
 
void Cell::Flux(double *flux, double *D)
 
{
 
	// loop over cell edges
 
	
 
	for (int c=0;c<NChem();c++) flux[c]=0.;
 
	
 
	for (list<Wall *>::iterator i=walls.begin();
 
		 i!=walls.end();
 
@@ -1540,22 +1492,22 @@ void Cell::Flux(double *flux, double *D)
 
			}
 
			#endif
 
			
 
			flux[c] += phi;
 
		}    
 
	}
 
	
 
}
 

	
 

	
 
// graphics stuff, not compiled for batch versions
 
#ifdef QTGRAPHICS
 

	
 
#include "canvas.h"
 

	
 
void Cell::Draw(QGraphicsScene *c, QString tooltip) {
 
void Cell::Draw(QGraphicsScene *c, QString tooltip)
 
{
 
	
 
	// Draw the cell on a QCanvas object
 
	
 
	if (DeadP()) { 
 
	        #ifdef QDEBUG
 
	  qDebug() << "Cell " << index << " not drawn, because dead." << endl;
 
@@ -1588,13 +1540,12 @@ void Cell::Draw(QGraphicsScene *c, QStri
 
	p->setZValue(1);
 
	
 
	if (!tooltip.isEmpty())
 
		p->setToolTip(tooltip);
 
	
 
	p->show();
 
	
 
}
 

	
 

	
 
void Cell::DrawCenter(QGraphicsScene *c) const {
 
  // Maginfication derived similarly to that in nodeitem.cpp
 
  // Why not use Cell::Magnification()?
 
@@ -1621,13 +1572,12 @@ void Cell::DrawNodes(QGraphicsScene *c) 
 
		item->setColor();
 
		item->setZValue(5);
 
		item->show();
 
		item ->setPos(((offset[0]+i->x)*factor),
 
					  ((offset[1]+i->y)*factor) );
 
	}
 
	
 
}
 

	
 
void Cell::DrawIndex(QGraphicsScene *c) const {
 
	
 
	DrawText( c, QString("%1").arg(index));
 
}
 
@@ -1640,13 +1590,12 @@ void Cell::DrawText(QGraphicsScene *c, c
 
	ctext->setPen( QPen(QColor(par.textcolor)) );
 
	ctext->setZValue(20);
 
	ctext->setFont( QFont( "Helvetica", par.cellnumsize, QFont::Bold) );
 
	ctext->show();
 
	ctext ->setPos(((offset[0]+centroid.x)*factor),
 
				   ((offset[1]+centroid.y)*factor) );
 
	
 
}
 

	
 

	
 
void Cell::DrawAxis(QGraphicsScene *c) const {
 
	
 
	Vector long_axis;
 
@@ -1670,22 +1619,22 @@ void Cell::DrawAxis(QGraphicsScene *c) c
 
	line->setLine( ( (offset[0]+from.x)*factor ),
 
				  ( (offset[1]+from.y)*factor ), 
 
				  ( (offset[0]+to.x)*factor ),
 
				  ( (offset[1]+to.y)*factor ) );
 
	line->setZValue(10);
 
	line->show();
 
	
 
}
 

	
 
void Cell::DrawStrain(QGraphicsScene *c) const {
 
  c = NULL; // assignment merely to obviate compilation warning
 
	MyWarning::warning("Sorry, Cell::DrawStrain temporarily not implemented.");
 
}
 

	
 

	
 
void Cell::DrawFluxes(QGraphicsScene *c, double arrowsize)  {
 
void Cell::DrawFluxes(QGraphicsScene *c, double arrowsize)
 
{
 
	
 
	// get the mean flux through this cell
 
	Vector vec_flux = ReduceCellAndWalls<Vector>( PINdir );
 
	
 
	vec_flux.Normalise();
 
	
 
@@ -1704,13 +1653,12 @@ void Cell::DrawFluxes(QGraphicsScene *c,
 
	arrow->setLine( ( (offset[0]+from.x)*factor ),
 
				   ( (offset[1]+from.y)*factor ), 
 
				   ( (offset[0]+to.x)*factor ),
 
				   ( (offset[1]+to.y)*factor ) );
 
	arrow->setZValue(10);
 
	arrow->show();
 
	
 
}
 

	
 

	
 
void Cell::DrawWalls(QGraphicsScene *c) const {
 
	
 
	for_each(walls.begin(), walls.end(), bind2nd ( mem_fun ( &Wall::Draw ) , c ) );
 
@@ -1720,23 +1668,23 @@ void Cell::DrawWalls(QGraphicsScene *c) 
 
}
 

	
 

	
 
void Cell::DrawValence(QGraphicsScene *c) const {
 
	
 
	DrawText(c, QString("%1").arg(walls.size()) );
 
	
 
}
 

	
 
#endif
 
#endif // QTGRAPHICS !
 

	
 
/*! \brief Recalculate the lengths of the cell's Walls.
 
 
 
 Call this function after the Monte Carlo updates, and before doing the reaction-diffusion iterations.
 
 
 
 */
 
void Cell::SetWallLengths(void) {
 
void Cell::SetWallLengths(void)
 
{
 
	
 
	for (list<Wall *>::iterator de=walls.begin();
 
		 de!=walls.end();
 
		 de++) {
 
		
 
		// Step 1: find the path of nodes leading along the Wall.
 
@@ -1776,13 +1724,14 @@ void Cell::SetWallLengths(void) {
 
		// goto next de
 
	}
 
}
 

	
 

	
 
//! Add Wall w to the list of Walls
 
void Cell::AddWall( Wall *w ) {
 
void Cell::AddWall( Wall *w )
 
{
 
	
 
	// if necessary, we could try later inserting it at the correct position
 
        #ifdef QDEBUG
 
	if (w->c1 == w->c2 ){
 
	  qDebug() << "Wall between identical cells: " << w->c1->Index()<< endl;
 
	}
 
@@ -1796,37 +1745,32 @@ void Cell::AddWall( Wall *w ) {
 
	if (find (
 
			  m->walls.begin(), m->walls.end(),
 
			  w )
 
		== m->walls.end() ) {
 
		m->walls.push_back(w);
 
	}
 
	
 
}
 

	
 
//! Remove Wall w from the list of Walls
 
list<Wall *>::iterator Cell::RemoveWall( Wall *w ) {
 
list<Wall *>::iterator Cell::RemoveWall( Wall *w )
 
{
 
	
 
	// remove wall from Mesh's list
 
	m->walls.erase(
 
				   find(
 
						m->walls.begin(), m->walls.end(),
 
						w )
 
				   );
 
	
 
	// remove wall from Cell's list
 
	return 
 
	walls.erase (
 
				 find( 
 
					  walls.begin(), walls.end(),
 
					  w )
 
				 );
 
	
 
  return walls.erase (find( walls.begin(), walls.end(), w ));
 
}
 

	
 

	
 

	
 
void Cell::EmitValues(double t) {
 
void Cell::EmitValues(double t)
 
{
 
	
 
	//  cerr << "Attempting to emit " << t << ", " << chem[0] << ", " << chem[1] << endl;
 
	emit ChemMonValue(t, chem);
 
}
 
	
 
}
 
/* finis */
src/cell.h
Show inline comments
 
@@ -89,20 +89,21 @@ public:
 
    static double Scale(const double scale) {
 
		factor*=scale;
 
		return factor;
 
    }
 
    
 
    void DivideOverAxis(Vector axis); // divide cell over axis
 
    bool DivideOverGivenLine(const Vector v1, const Vector v2, bool wall_fixed = false, NodeSet *node_set = 0); // divide over the line (if line and cell intersect)
 

	
 
  // divide over the line (if line and cell intersect)
 
  bool DivideOverGivenLine(const Vector v1, const Vector v2, bool wall_fixed = false, NodeSet *node_set = 0);
 
	
 
    void Divide(void) { // Divide cell over short axis
 
		
 
		Vector long_axis; 
 
		Length(&long_axis); 
 
		DivideOverAxis(long_axis.Perp2D()); 
 
		
 
    }
 
	
 
	//void CheckForGFDrivenDivision(void);
 
    inline int NNodes(void) const { return nodes.size(); }
 
  	
 
    void Move(Vector T);
 
@@ -119,17 +120,12 @@ public:
 

	
 
	void XMLAdd(xmlNodePtr cells_node) const;
 
	
 
	void ConstructWalls(void);
 
	void Flux(double *flux, double *D);
 
	
 
	/*! \brief Method called if a cell is clicked. 
 
	 
 
	 Define this in the end-user code (e.g. meinhardt.cpp).
 
	 
 
	 */
 
    void OnClick(QMouseEvent *e);
 
    inline Mesh& getMesh(void) const { return *m; }
 
	double MeanArea(void);
 
	
 
	void Apoptose(void); // Cell kills itself
 
	list<Wall *>::iterator RemoveWall( Wall *w );
 
@@ -150,13 +146,12 @@ public:
 
    void DrawValence(QGraphicsScene *c) const;
 
    void EmitValues(double t);
 
	
 
signals:
 
    void ChemMonValue(double t, double *x);
 
	
 
	
 
protected:
 
	void XMLAddCore(xmlNodePtr xmlcell) const;
 
    int XMLRead(xmlNode *cur);
 
	void DivideWalls(ItList new_node_locations, const Vector from, const Vector to, bool wall_fixed = false, NodeSet *node_set = 0);
 

	
 
private:
 
@@ -164,13 +159,12 @@ private:
 
    static QPen *cell_outline_pen;
 
	static double offset[3];
 
    static double factor;
 
	Mesh *m;
 
	void ConstructConnections(void);
 
	void SetWallLengths(void);
 

	
 
};
 

	
 

	
 
// Boundarypolygon is a special cell; will not increase ncells
 
//  and will not be part of Mesh::cells
 
class BoundaryPolygon : public Cell {
 
@@ -193,13 +187,11 @@ public:
 
	}
 
	virtual void Draw(QGraphicsScene *c, QString tooltip = QString::Null());
 
	
 
	virtual void XMLAdd(xmlNodePtr parent_node) const;
 
	
 
	virtual bool BoundaryPolP(void) const { return true; } 
 

	
 

	
 
};
 

	
 

	
 
#endif
 

	
 
#endif
 
/* finis */
src/cellbase.cpp
Show inline comments
 
@@ -131,13 +131,12 @@ CellBase::CellBase(double x,double y,dou
 
	marked=false;
 
	dead  = false;
 
	div_counter = 0;
 
	cell_type = 0;
 
	flag_for_divide = false;
 
	division_axis = 0;
 

	
 
}
 

	
 
CellBase::CellBase(const CellBase &src) :  Vector(src), QObject()
 
{
 
	
 
	chem=new double[NChem()];
 
@@ -175,13 +174,14 @@ CellBase::CellBase(const CellBase &src) 
 
	div_counter = src.div_counter;
 
	flag_for_divide = src.flag_for_divide;
 
	division_axis = src.division_axis;
 
}
 

	
 

	
 
CellBase CellBase::operator=(const CellBase &src) {
 
CellBase CellBase::operator=(const CellBase &src)
 
{
 
	Vector::operator=(src);
 

	
 
	for (int i=0;i<NChem();i++) {
 
		chem[i]=src.chem[i];
 
	}
 
	for (int i=0;i<NChem();i++) {
 
@@ -214,35 +214,38 @@ CellBase CellBase::operator=(const CellB
 
	div_counter = src.div_counter;
 
	flag_for_divide = src.flag_for_divide;
 
	division_axis = src.division_axis;
 
	return *this;
 
}
 

	
 
void CellBase::SetChemical(int c, double conc) {
 
void CellBase::SetChemical(int c, double conc)
 
{
 
	if (c>=NChem()) {
 
		stringstream error;
 
		error << "SetChemical: value c = " << c << " is out of range\n";
 
		throw error.str().c_str();
 
	}
 
	chem[c]=conc;
 
}
 

	
 
void CellBase::SetTransporters(int ch, double conc) {
 
void CellBase::SetTransporters(int ch, double conc)
 
{
 
	if (ch>=NChem()) {
 
		stringstream error;
 
		error << "SetChemical: value ch = " << ch << " is out of range\n";
 
		throw error.str().c_str();
 
	}
 
	for (list<Wall *>::iterator w=walls.begin();
 
		 w!=walls.end();
 
		 w++) {
 
		(*w)->setTransporter(this, ch, conc);
 
	}
 
}
 

	
 
ostream &CellBase::print(ostream &os) const {
 
ostream &CellBase::print(ostream &os) const
 
{
 
	
 
	
 
	os << "[ index = " << index << " {" << x << ", " << y << ", " << z << "}: {";
 
	
 
	for (int i=0;i<NChem()-1;i++) {
 
		os << chem[i] << ", ";
 
@@ -273,22 +276,23 @@ ostream &CellBase::print(ostream &os) co
 
	}
 
	os << " ] ";
 
	os << "div_counter = " << div_counter << endl;
 
	os << "cell_type = " << cell_type << endl;
 
	os << endl;
 
	return os;
 
	
 
}
 

	
 
ostream &operator<<(ostream &os, const CellBase &c) {
 
ostream &operator<<(ostream &os, const CellBase &c)
 
{
 
	c.print(os);
 
	return os;
 
}
 

	
 

	
 
double CellBase::CalcArea(void) const {
 
double CellBase::CalcArea(void) const
 
{
 
	
 
	double loc_area=0.;
 
	
 
	for (list<Node *>::const_iterator i=nodes.begin();
 
		 i!=(nodes.end());
 
		 i++) {
 
@@ -299,17 +303,17 @@ double CellBase::CalcArea(void) const {
 
		
 
		loc_area+= (*i)->x * (*i_plus_1)->y;
 
		loc_area-= (*i_plus_1)->x * (*i)->y;
 
	}
 

	
 
	// http://technology.niagarac.on.ca/courses/ctec1335/docs/arrays2.pdf	
 
	//return loc_area/2.0; 
 
	return fabs(loc_area)/2.0; 
 
} 
 

	
 
Vector CellBase::Centroid(void) const {
 
Vector CellBase::Centroid(void) const
 
{
 
	
 
	double area=0.;
 
	double integral_x_dxdy=0.,integral_y_dxdy=0.;
 
	
 
	for (list<Node *>::const_iterator i=nodes.begin();
 
		 i!=(nodes.end());
 
@@ -329,26 +333,26 @@ Vector CellBase::Centroid(void) const {
 
		integral_y_dxdy+=
 
			((*i_plus_1)->y+(*i)->y)*
 
			((*i)->x*(*i_plus_1)->y-
 
			 (*i_plus_1)->x*(*i)->y);
 
	}
 
    
 
	//area/=2.0;
 
	area = fabs(area)/2.0;
 
	
 
	integral_x_dxdy/=6.;
 
	integral_y_dxdy/=6.;
 
	
 
	Vector centroid(integral_x_dxdy,integral_y_dxdy,0);
 
	centroid/=area;
 
	return centroid;
 
}
 

	
 

	
 

	
 
void CellBase::SetIntegrals(void) const {
 
void CellBase::SetIntegrals(void) const
 
{
 
	
 
	// Set the initial values for the integrals over x^2,
 
	// xy, yy, x, and y
 
	
 
	// these values will be updated after each move of the CellBase wall
 
	
 
@@ -389,19 +393,17 @@ void CellBase::SetIntegrals(void) const 
 
			 (*nb)->x*(*i)->y);
 
		intgrl_y+=
 
			((*nb)->y+(*i)->y)*
 
			((*i)->x*(*nb)->y-
 
			 (*nb)->x*(*i)->y);
 
	}
 
	
 

	
 
	area = fabs(area)/2.0;
 
	
 
}
 

	
 
double CellBase::Length(Vector *long_axis, double *width)  const {
 
double CellBase::Length(Vector *long_axis, double *width)  const
 
{
 
	
 
	// Calculate length and axes of CellBase
 
    
 
	// Calculate inertia tensor
 
	// see file inertiatensor.nb for explanation of this method
 
	if (!lambda_celllength) {
 
@@ -431,18 +433,16 @@ double CellBase::Length(Vector *long_axi
 
	
 
	if (width) {
 
		*width = 4*sqrt((rhs1-rhs2)/area);
 
	}
 
	
 
	return 4*sqrt(lambda_b/area);
 
    
 
	
 
	
 
}
 

	
 
double CellBase::CalcLength(Vector *long_axis, double *width)  const {
 
double CellBase::CalcLength(Vector *long_axis, double *width)  const
 
{
 
	
 
	// Calculate length and axes of CellBase, without touching cells raw moments
 
    
 
	// Calculate inertia tensor
 
	// see file inertiatensor.nb for explanation of this method
 
	
 
@@ -512,20 +512,17 @@ double CellBase::CalcLength(Vector *long
 
	
 
	if (width) {
 
		*width = 4*sqrt((rhs1-rhs2)/my_area);
 
	}
 
	
 
	return 4*sqrt(lambda_b/my_area);
 
    
 
	
 
	
 
}
 

	
 

	
 

	
 
void CellBase::ConstructNeighborList(void) {
 
void CellBase::ConstructNeighborList(void)
 
{
 
	
 
	neighbors.clear();
 
	for (//list<Wall *>::const_reverse_iterator wit=walls.rbegin();
 
		 list<Wall *>::const_iterator wit=walls.begin();
 
		 // somehow the reverse_iterator returns by walls needs to be casted to const to let this work.
 
		 // it seems to me it is a bug in the STL implementation...
 
@@ -558,17 +555,17 @@ void CellBase::ConstructNeighborList(voi
 
			e=neighbors.erase(e);
 
			at_boundary=true;
 
		} else {
 
			break;
 
		}
 
  } while(1);
 
	
 
}
 
	
 
	// Save the cell to a stream so we can reconstruct its state later
 
	void CellBase::Dump(ostream &os) const {
 
void CellBase::Dump(ostream &os) const
 
{
 
		
 
		
 
		os << index << " " << nodes.size() << endl;
 
		
 
		Vector::Dump(os);
 
		os << endl;
 
@@ -580,79 +577,74 @@ void CellBase::ConstructNeighborList(voi
 
		
 
		
 
		os << index << " " << neighbors.size() << endl;
 
		for (list<CellBase *>::const_iterator i=neighbors.begin();i!=neighbors.end();i++) {
 
			os << *i << " ";
 
		}
 
		os << endl;
 
		
 
		os << walls.size() << endl;
 
		/*for (list<Wall *>::const_iterator i=walls.begin();i!=walls.end(); i++) {
 
			(*i)->Dump(os);
 
		}*/
 
  os << endl << walls.size() << endl << endl;
 
  os << NChem() << " ";
 
		
 
		os << endl;
 
		
 
		os << NChem() << " ";
 
		for (int i=0;i<NChem();i++) {
 
			os << chem[i] << " ";
 
		}
 
		os << endl;
 
		
 
		os << NChem() << " ";
 
		for (int i=0;i<NChem();i++) {
 
			os << new_chem[i] << " ";
 
		}
 
		os << endl;
 
		
 
		os << boundary << " " << area << " " << target_area << " " << target_length << " " << fixed << " " << intgrl_xx << " " << intgrl_xy << " " << intgrl_yy << " " << intgrl_x << " " << intgrl_y << " " << source << " ";
 
  os << boundary << " " << area << " " << target_area << " " << target_length 
 
     << " " << fixed << " " << intgrl_xx << " " << intgrl_xy << " " << intgrl_yy 
 
     << " " << intgrl_x << " " << intgrl_y << " " << source << " ";
 
		
 
		cellvec.Dump(os);
 
		
 
		os << " " << source_conc << " " << source_chem;
 
		os << endl;
 
		
 
	}
 
	
 
	
 
	
 
	void CellBase::UnfixNodes(void) {
 
void CellBase::UnfixNodes(void)
 
{
 
		
 
		for (list<Node *>::const_iterator i=nodes.begin();
 
			 i!=nodes.end();
 
			 i++) {
 
			(*i)->Unfix();
 
		}
 
		
 
	}
 
	
 
	void CellBase::FixNodes(void) {
 

	
 
void CellBase::FixNodes(void)
 
{
 
		
 
		for (list<Node *>::const_iterator i=nodes.begin();
 
			 i!=nodes.end();
 
			 i++) {
 
			(*i)->Fix();
 
		}
 
		
 
	}
 
	
 
	// returns true if cell is at border
 
	bool CellBase::AtBoundaryP(void) const {
 
		
 
bool CellBase::AtBoundaryP(void) const
 
{
 
		return at_boundary;
 
	}
 
	
 

	
 

	
 

	
 

	
 

	
 

	
 
QString CellBase::printednodelist(void) {
 
QString CellBase::printednodelist(void)
 
{
 
	QString info_string = "Nodelist = { ";
 
	for (list<Node *>::const_iterator i =  nodes.begin(); i!=nodes.end(); i++) {
 
		info_string += QString("%1 ").arg((*i)->Index());
 
	}
 
	info_string += " } ";
 
	return info_string;
 
}
 

	
 
/* finis*/
src/cellbase.h
Show inline comments
 
@@ -48,13 +48,12 @@ class NodeSet;
 

	
 
struct ParentInfo {
 
	
 
	Vector polarization;
 
	double PINmembrane;
 
	double PINendosome;
 
	
 
};
 

	
 
// We need a little trick here, to make sure the plugin and the main application will see the same static datamembers
 
// otherwise each have their own instantation.
 
// My solution is as follow. I collect all original statics in a class. The main application instantiates it and
 
// has a static pointer to it. After loading the plugin I set a static pointer to the same class 
 
@@ -74,22 +73,19 @@ public:
 
	        qDebug() << "Oops! Desctructor of CellsStaticDatamembers called" << endl;
 
                #endif
 
	}
 
	int ncells;
 
	int nchem;
 
	double base_area;
 

	
 

	
 
};
 

	
 
class CellBase :  public QObject, public Vector 
 
{
 

	
 
	Q_OBJECT
 

	
 

	
 
	friend class Mesh;
 
	friend class CellInfo;
 
	friend class Node;
 
	friend class WallBase;
 
	friend class SimPluginInterface;
 
	
 
@@ -109,20 +105,24 @@ class CellBase :  public QObject, public
 
	
 
	
 
    CellBase operator=(const CellBase &src); // assignment operator
 
    CellBase operator=(const Vector &src);
 
  
 
    void SetChemical(int chem, double conc);
 
    inline void SetNewChem(int chem, double conc) { 
 
  inline void SetNewChem(int chem, double conc)
 
  { 
 
      new_chem[chem] = conc;
 
    }
 
    void SetSource(int chem, double conc) {
 

	
 
  void SetSource(int chem, double conc)
 
  {
 
      source=true;
 
      source_chem = chem;
 
      source_conc = conc;
 
	}
 

	
 
	// set chem 1 to conc in all membranes of this cell
 
    void SetTransporters(int chem, double conc);
 
    void UnfixNodes(void);
 
    void FixNodes(void);
 
    void UnsetSource(void) {
 
      source = false;
 
@@ -151,84 +151,64 @@ class CellBase :  public QObject, public
 
      return ((c<0) || (c>=nchem)) ? 0 : chem[c];
 
    }
 

	
 
    
 
    //void print_nblist(void) const;
 

	
 
    boundary_type SetBoundary(boundary_type bound) {
 
  boundary_type SetBoundary(boundary_type bound)
 
  {
 
      if (bound!=None) {
 
      }
 
      return boundary=bound;
 
    }
 
  
 
    boundary_type ResetBoundary(void) {
 
      return boundary=None;
 
    }
 
    boundary_type Boundary(void) const {
 
      return boundary;
 
    }
 
    static int &NChem(void) {
 
      return static_data_members->nchem;
 
    }
 
  boundary_type ResetBoundary(void) { return boundary=None; }
 

	
 
  boundary_type Boundary(void) const { return boundary; }
 

	
 
  static int &NChem(void) { return static_data_members->nchem; }
 
  
 
    double CalcArea(void) const;
 
    double RecalcArea(void) {
 
      return area = CalcArea();
 
    }
 

	
 
  double RecalcArea(void) { return area = CalcArea(); }
 
    
 
    Vector Centroid(void) const;
 
  
 
    void SetIntegrals(void) const;
 
    
 
    double Length(Vector *long_axis = 0, double *width = 0) const;
 
    double CalcLength(Vector *long_axis = 0, double *width = 0) const;
 
    
 

	
 
    inline int Index(void) const {
 
      return index;
 
    }
 
  inline int Index(void) const { return index; }
 
  
 

	
 
    void SetTargetArea(double tar_ar) {
 
      target_area=tar_ar;
 
    }
 
    inline void SetTargetLength(double tar_l) {
 
      target_length=tar_l;
 
    }
 
    inline void SetLambdaLength(double lambda_length) {
 
      lambda_celllength = lambda_length;
 
    }
 
    inline double TargetArea(void) {
 
      return target_area;
 
    }
 
  void SetTargetArea(double tar_ar) { target_area=tar_ar; }
 

	
 
  inline void SetTargetLength(double tar_l) { target_length=tar_l; }
 
  
 
    inline void SetStiffness(double stiff) {
 
      stiffness = stiff;
 
    }
 
  inline void SetLambdaLength(double lambda_length) { lambda_celllength = lambda_length; }
 

	
 
  inline double TargetArea(void) { return target_area; }
 

	
 
  inline void SetStiffness(double stiff) { stiffness = stiff; }
 

	
 
    inline double Stiffness(void) {
 
      return stiffness;
 
    }
 
    inline double EnlargeTargetArea(double da) {
 
      return target_area+=da;
 
    }
 
  inline double Stiffness(void) { return stiffness; }
 

	
 
  inline double EnlargeTargetArea(double da) { return target_area+=da; }
 
  
 
    inline double Area(void) const {
 
      return area;
 
    }
 
  inline double Area(void) const { return area; }
 
    
 
	inline void Divide(void) {
 
		flag_for_divide = true;
 
	}
 
  inline void Divide(void) { flag_for_divide = true; }
 
	
 
	inline void DivideOverAxis(const Vector &v) {
 
  inline void DivideOverAxis(const Vector &v)
 
  {
 
		division_axis = new Vector(v);
 
		flag_for_divide = true;
 
	}
 
	
 

	
 
    inline double Circumference(void) const {
 
      double sum=0.;
 
      for (list<Wall *>::const_iterator w=walls.begin();
 
	   w!=walls.end();
 
	   w++) {
 
	sum +=  (*w)->Length();
 
@@ -248,51 +228,53 @@ class CellBase :  public QObject, public
 
	}
 
    
 
    void Dump(ostream &os) const;
 
   	
 
	QString printednodelist(void);
 
 
 

	
 
    
 
    inline bool DeadP(void) { return dead; }
 
    inline void MarkDead(void) { dead  = true; }
 
    
 
	static double &BaseArea(void) { 
 
  static double &BaseArea(void)
 
  { 
 
		return static_data_members->base_area;
 
	}
 
  
 
    void CheckForDivision(void);
 

	
 
	
 
    // write flux from neighboring cells into "flux"
 
    void Flux(double *flux, double *D); 
 
    inline bool FixedP(void) { return fixed; }
 
    inline bool Fix(void) {  FixNodes(); return (fixed=true); }
 
    inline bool Unfix(void) { UnfixNodes(); return (fixed=false);}
 
    inline void setCellVec(Vector cv) { cellvec = cv; }
 
    
 
	bool AtBoundaryP(void) const;
 
    
 
    static inline int &NCells(void) {
 
  static inline int &NCells(void)
 
  {
 
      return static_data_members->ncells;
 
    }
 

	
 
 
 
   
 
    inline void Mark(void) {
 
  inline void Mark(void)
 
  {
 
      marked=true;
 
    }
 
    inline void Unmark(void) {
 

	
 
  inline void Unmark(void)
 
  {
 
      marked=false;
 
    }
 

	
 
    inline bool Marked(void) const {
 
      return marked;
 
    }
 

	
 
	//! Returns the sum of chemical "chem" of this CellBase's neighbors
 
    double SumChemicalsOfNeighbors(int chem) {
 
  double SumChemicalsOfNeighbors(int chem)
 
  {
 
      double sum=0.;
 
      for (list<Wall *>::const_iterator w=walls.begin();
 
	   w!=walls.end();
 
	   w++) {
 
	sum +=  (*w)->Length() * ( (*w)->c1!=this ? (*w)->c1->Chemical(chem) : (*w)->c2->Chemical(chem) );
 
      }
 
@@ -317,17 +299,15 @@ class CellBase :  public QObject, public
 
	   w++) {
 
	sum += f( **w ); 
 
      }
 
      return sum;
 
    }
 
	
 
	
 
    
 
    
 
    //! The same, but now for the walls AND neighbors
 
    template<class P, class Op> P ReduceCellAndWalls(Op f) {
 
  template<class P, class Op> P ReduceCellAndWalls(Op f)
 
  {
 
      P sum = 0;
 
      for (list<Wall *>::const_iterator w=walls.begin();
 
	   w!=walls.end();
 
	   w++) {
 
	sum += ((*w)->c1 == this) ? 
 
	  f( ((*w)->c1), ((*w)->c2), *w ) :  
 
@@ -335,57 +315,58 @@ class CellBase :  public QObject, public
 
      }
 
      return sum;
 
    }
 
    
 
	
 
    //! Sum transporters at this CellBase's side of the walls
 
    double SumTransporters(int ch) {
 
  double SumTransporters(int ch)
 
  {
 
      double sum=0.;
 
      for (list<Wall *>::const_iterator w=walls.begin();
 
	   w!=walls.end();
 
	   w++) {
 
	sum += (*w)->getTransporter(this, ch);
 
      
 
      }
 
      
 
      return sum;
 
    }
 

	
 
    inline int NumberOfDivisions(void) { return div_counter; }
 
    
 
    //! Sum transporters at this CellBase's side of the walls
 
    double SumLengthTransporters(int ch) {
 
  double SumLengthTransporters(int ch)
 
  {
 
      double sum=0.;
 
      for (list<Wall *>::const_iterator w=walls.begin();
 
	   w!=walls.end();
 
	   w++) {
 
	sum += (*w)->getTransporter(this, ch) * (*w)->Length();
 
      
 
      }
 
      
 
      return sum;
 
    }
 
    
 
	
 
    
 
    double SumLengthTransportersChemical(int trch, int ch) {
 
  double SumLengthTransportersChemical(int trch, int ch)
 
  {
 
      double sum=0.;
 
      for (list<Wall *>::const_iterator w=walls.begin();
 
	   w!=walls.end();
 
	   w++) {
 
	sum += (*w)->getTransporter(this, trch) * ( (*w)->c1!=this ? (*w)->c1->Chemical(ch) : (*w)->c2->Chemical(ch) );
 
	
 
      }
 
      
 
      return sum;
 
    }
 
	inline int CellType(void) const { return cell_type; } 
 
	inline void SetCellType(int ct) { cell_type = ct; }
 

	
 
    
 
	static void SetNChem(int new_nchem) {
 
  static void SetNChem(int new_nchem)
 
  {
 
		if (NCells()) {
 
			MyWarning::error("CellBase::SetNChem says: not permitted, call SetNChem after deleting all cells.");
 
		} else {
 
			NChem() = new_nchem;
 
		}
 
	}
 
@@ -397,18 +378,20 @@ class CellBase :  public QObject, public
 
protected:
 
	// (define a list of Node* iterators)
 
	typedef list < list<Node *>::iterator > ItList;
 

	
 
    int index;
 

	
 
	inline void SetChemToNewchem(void) {
 
  inline void SetChemToNewchem(void)
 
  {
 
		for (int c=0;c<CellBase::NChem();c++) {
 
			chem[c]=new_chem[c];
 
		}
 
    }
 
    inline void SetNewChemToChem(void) {
 
  inline void SetNewChemToChem(void)
 
  {
 
		for (int c=0;c<CellBase::NChem();c++) {
 
			new_chem[c]=chem[c];
 
		}
 
    }
 
	inline double NewChem(int c) const { return new_chem[c]; }
 
	
 
@@ -443,44 +426,40 @@ protected:
 
    bool pin_fixed;
 
    bool at_boundary; 
 
    bool dead; 
 
	bool flag_for_divide;
 
	
 
	Vector *division_axis;
 
	
 
	int cell_type;
 
	
 
    
 
    // for length constraint
 
    mutable double intgrl_xx, intgrl_xy, intgrl_yy, intgrl_x, intgrl_y;
 
    
 
    bool source;
 
    Vector cellvec;
 
	
 
	// STATIC DATAMEMBERS MOVED TO CLASS
 
	static CellsStaticDatamembers *static_data_members;
 
	double source_conc;
 
    int source_chem;
 
	
 
    // PRIVATE MEMBER FUNCTIONS
 
    inline static void ClearNCells(void) {
 
  inline static void ClearNCells(void)
 
  {
 
      NCells()=0;
 
    }
 
    
 
    bool marked;
 
    int div_counter;
 
};
 

	
 
ostream &operator<<(ostream &os, const CellBase &v);
 

	
 
inline Vector PINdir(CellBase *here, CellBase *nb, Wall *w) {
 
inline Vector PINdir(CellBase *here, CellBase *nb, Wall *w)
 
{
 
	  nb = NULL; // assignment merely to obviate compilation warning
 
	  return w->getTransporter( here, 1)  *  w->getInfluxVector(here);
 
}
 

	
 

	
 
#endif
 

	
 

	
 

	
 

	
 

	
 
/* finis*/
src/cellitem.cpp
Show inline comments
 
@@ -26,20 +26,22 @@
 
static const std::string _module_id("$Id$");
 

	
 
CellItem::CellItem( Cell *c, QGraphicsScene *canvas )
 
  : QGraphicsPolygonItem( 0, canvas ), SimItemBase( c, canvas){
 
}
 

	
 
void CellItem::userMove(double dx, double dy) {
 
void CellItem::userMove(double dx, double dy)
 
{
 
  QGraphicsPolygonItem::moveBy( dx, dy );
 

	
 
  // also move the cell itself
 
  class_cast<Cell *>(obj)->x += (dx/Cell::Magnification());
 
  class_cast<Cell *>(obj)->y += (dy/Cell::Magnification());
 
  
 
  class_cast<Cell*>(obj)->Move( (dx/Cell::Magnification()), (dy/Cell::Magnification()) );
 
}
 

	
 

	
 
QPainterPath CellItem::shape() const { return QGraphicsPolygonItem::shape(); }
 
QRectF CellItem::boundingRect() const { return QGraphicsPolygonItem::boundingRect(); }
 

	
 

	
 
/* finis */
src/cellitem.h
Show inline comments
 
@@ -40,10 +40,11 @@ public:
 
  Cell &getCell(void) const { return *class_cast<Cell*>(obj); }
 
  virtual void userMove(double dx, double dy);  
 
  QPainterPath shape() const;
 
  QRectF boundingRect() const;
 

	
 
 private:
 

	
 
};
 

	
 
#endif
 

	
 
/* finis */
src/curvecolors.h
Show inline comments
 
@@ -172,6 +172,8 @@ class CurveColors {
 
      return colors[i];
 
  }
 
 private:
 
  QStringList colors;
 
};
 
#endif
 

	
 
/* finis */
src/data_plot.cpp
Show inline comments
 
@@ -63,14 +63,12 @@ DataPlot::DataPlot(QWidget *parent, cons
 
  // Disable polygon clipping
 
  QwtPainter::setDeviceClipping(false);
 

	
 
  alignScales();
 
    
 
  //  Initialize data
 
  
 
  
 
  for (int i = 0; i< PLOT_SIZE; i++) {
 
    d_t[i] = 0.;     // time axis
 
  }
 

	
 
  for (int i=0;i<ncurves * PLOT_SIZE;i++) {
 
    d_x[0][i]=0.;
 
@@ -95,26 +93,25 @@ DataPlot::DataPlot(QWidget *parent, cons
 

	
 
    curves[i].setRawData(d_t, d_x[i], PLOT_SIZE);
 
  }
 
    
 
  // Axis 
 
  setAxisTitle(QwtPlot::xBottom, "Time");
 

	
 
  setAxisTitle(QwtPlot::yLeft, "Level");
 
  setAxisScale(QwtPlot::yLeft, 0, 10);
 

	
 
  data_pos = 0;
 

	
 
}
 

	
 
DataPlot::~DataPlot(void) {
 
DataPlot::~DataPlot(void)
 
{
 
  delete[] d_t ;
 
  delete[] d_x[0];
 
  delete[] d_x;
 
  delete[] curves;
 
}
 

	
 
//
 
//  Set a plain canvas frame and align the scales to it
 
//
 
void DataPlot::alignScales()
 
{
 
    // The code below shows how to align the scales to
 
@@ -133,13 +130,12 @@ void DataPlot::alignScales()
 
        QwtScaleDraw *scaleDraw = (QwtScaleDraw *)axisScaleDraw(i);
 
        if ( scaleDraw )
 
            scaleDraw->enableComponent(QwtAbstractScaleDraw::Backbone, false);
 
    }
 
}
 

	
 

	
 
//  Generate new values 
 
void DataPlot::AddValue(double t,double *x)
 
{
 

	
 
  //  std::cerr << "AddValue receives: " << t << ", " << y << ", " << z << std::endl;
 
  
 
@@ -151,43 +147,37 @@ void DataPlot::AddValue(double t,double 
 

	
 
    for ( int i=0;i<ncurves;i++) {
 
      for ( int j = 0; j < PLOT_SIZE - 1; j++ )
 
	d_x[i][j] = d_x[i][j+1];
 
    }
 
    data_pos = PLOT_SIZE - 1;
 
    
 
  } 
 

	
 
  d_t[data_pos] = t;
 

	
 
  for ( int i=0;i<ncurves;i++) {
 
    curves[i].setRawData(d_t, d_x[i], data_pos);
 
    d_x[i][data_pos] = x[i];
 
  }
 
					       
 
  setAxisScale(QwtPlot::xBottom, d_t[0], t);
 
  data_pos++;
 
  
 
  data_pos++;
 
  // update the display
 
  replot();
 
  
 

	
 
}
 

	
 

	
 
PlotDialog::PlotDialog(QWidget *parent, const QString title, const QStringList curvenames):
 
  QDialog(parent) 
 
{
 
  
 
  plot = new DataPlot(this,title,curvenames);
 
  
 
  plot->resize(400,300);
 
  
 
  show();
 

	
 
}
 

	
 
PlotDialog::~PlotDialog(void) {
 
  
 
PlotDialog::~PlotDialog(void)
 
{
 
  delete plot;
 
}
 

	
 
/* finis */
src/data_plot.h
Show inline comments
 
@@ -60,13 +60,12 @@ private:
 
    CurveColors curvecolors;
 

	
 
 protected:
 
    // to write contents of DataPlot to a file
 
    QFile *datfile;
 
    QTextStream datstream;
 

	
 
};
 

	
 
class PlotDialog : public QDialog {
 

	
 
Q_OBJECT
 
 public:
 
@@ -79,6 +78,8 @@ Q_OBJECT
 
  }
 
 private:
 
  DataPlot *plot;
 
};
 

	
 
#endif
 

	
 
/* finis */
src/far_mem_5.h
Show inline comments
 
@@ -18,13 +18,12 @@
 
 *  along with the Virtual Leaf.  If not, see <http://www.gnu.org/licenses/>.
 
 *
 
 *  Copyright 2010 Roeland Merks.
 
 *
 
 */
 

	
 

	
 
#ifndef _FAR_MEM_5_h_
 
#define _FAR_MEM_5_h_
 

	
 
template <class _Arg1,  class _Result>
 
	struct my_1_function
 
	{
 
@@ -42,22 +41,26 @@ Result operator()(Param1 i_prm1) { retur
 

	
 
protected:
 
Type *m_ptyp;
 
Result (Type::*m_pmf)(Param1);
 
};
 

	
 
template <class Result, class Type, class Param1>far_1_arg_mem_fun_t<Result,Type,Param1> far_1_arg_mem_fun(Type &ir_typ, Result (Type::*i_pmf)(Param1) ) {
 
template <class Result, class Type, 
 
  class Param1>far_1_arg_mem_fun_t<Result,Type,Param1> far_1_arg_mem_fun(Type &ir_typ, Result (Type::*i_pmf)(Param1) )
 
{
 
	return far_1_arg_mem_fun_t<Result,Type,Param1>(ir_typ,i_pmf);
 
 }
 

	
 
template <class _Arg1, class _Arg2,  class _Result>
 
	struct my_2_function
 
	{
 
typedef _Arg1 argument_type1;
 
typedef _Arg2 argument_type2;
 
typedef _Result result_type;  ///<  result_type is the return type
 
};
 

	
 
template <class Result, class Type,  class Param1, class Param2>
 
class far_2_arg_mem_fun_t : public my_2_function<Param1, Param2, Result> {
 
public:
 
explicit far_2_arg_mem_fun_t(Type &ir_typ, Result (Type::*i_pmf)(Param1, Param2)) {
 
			m_ptyp = &ir_typ;
 
			m_pmf = i_pmf;
 
@@ -66,23 +69,26 @@ Result operator()(Param1 i_prm1, Param2 
 

	
 
protected:
 
Type *m_ptyp;
 
Result (Type::*m_pmf)(Param1, Param2);
 
};
 

	
 
template <class Result, class Type, class Param1, class Param2>far_2_arg_mem_fun_t<Result,Type,Param1, Param2> far_2_arg_mem_fun(Type &ir_typ, Result (Type::*i_pmf)(Param1, Param2) ) {
 
template <class Result, class Type, class Param1, 
 
  class Param2>far_2_arg_mem_fun_t<Result,Type,Param1, Param2> far_2_arg_mem_fun(Type &ir_typ, Result (Type::*i_pmf)(Param1, Param2) ) {
 
	return far_2_arg_mem_fun_t<Result,Type,Param1, Param2>(ir_typ,i_pmf);
 
 }
 

	
 
template <class _Arg1, class _Arg2, class _Arg3,  class _Result>
 
	struct my_3_function
 
	{
 
typedef _Arg1 argument_type1;
 
typedef _Arg2 argument_type2;
 
typedef _Arg3 argument_type3;
 
typedef _Result result_type;  ///<  result_type is the return type
 
};
 

	
 
template <class Result, class Type,  class Param1, class Param2, class Param3>
 
class far_3_arg_mem_fun_t : public my_3_function<Param1, Param2, Param3, Result> {
 
public:
 
explicit far_3_arg_mem_fun_t(Type &ir_typ, Result (Type::*i_pmf)(Param1, Param2, Param3)) {
 
			m_ptyp = &ir_typ;
 
			m_pmf = i_pmf;
 
@@ -91,24 +97,27 @@ Result operator()(Param1 i_prm1, Param2 
 

	
 
protected:
 
Type *m_ptyp;
 
Result (Type::*m_pmf)(Param1, Param2, Param3);
 
};
 

	
 
template <class Result, class Type, class Param1, class Param2, class Param3>far_3_arg_mem_fun_t<Result,Type,Param1, Param2, Param3> far_3_arg_mem_fun(Type &ir_typ, Result (Type::*i_pmf)(Param1, Param2, Param3) ) {
 
template <class Result, class Type, class Param1, class Param2, 
 
class Param3>far_3_arg_mem_fun_t<Result,Type,Param1, Param2, Param3> far_3_arg_mem_fun(Type &ir_typ, Result (Type::*i_pmf)(Param1, Param2, Param3) ) {
 
	return far_3_arg_mem_fun_t<Result,Type,Param1, Param2, Param3>(ir_typ,i_pmf);
 
 }
 

	
 
template <class _Arg1, class _Arg2, class _Arg3, class _Arg4,  class _Result>
 
	struct my_4_function
 
	{
 
typedef _Arg1 argument_type1;
 
typedef _Arg2 argument_type2;
 
typedef _Arg3 argument_type3;
 
typedef _Arg4 argument_type4;
 
typedef _Result result_type;  ///<  result_type is the return type
 
};
 

	
 
template <class Result, class Type,  class Param1, class Param2, class Param3, class Param4>
 
class far_4_arg_mem_fun_t : public my_4_function<Param1, Param2, Param3, Param4, Result> {
 
public:
 
explicit far_4_arg_mem_fun_t(Type &ir_typ, Result (Type::*i_pmf)(Param1, Param2, Param3, Param4)) {
 
			m_ptyp = &ir_typ;
 
			m_pmf = i_pmf;
 
@@ -120,22 +129,24 @@ Type *m_ptyp;
 
Result (Type::*m_pmf)(Param1, Param2, Param3, Param4);
 
};
 

	
 
template <class Result, class Type, class Param1, class Param2, class Param3, class Param4>far_4_arg_mem_fun_t<Result,Type,Param1, Param2, Param3, Param4> far_4_arg_mem_fun(Type &ir_typ, Result (Type::*i_pmf)(Param1, Param2, Param3, Param4) ) {
 
	return far_4_arg_mem_fun_t<Result,Type,Param1, Param2, Param3, Param4>(ir_typ,i_pmf);
 
 }
 

	
 
template <class _Arg1, class _Arg2, class _Arg3, class _Arg4, class _Arg5,  class _Result>
 
	struct my_5_function
 
	{
 
typedef _Arg1 argument_type1;
 
typedef _Arg2 argument_type2;
 
typedef _Arg3 argument_type3;
 
typedef _Arg4 argument_type4;
 
typedef _Arg5 argument_type5;
 
typedef _Result result_type;  ///<  result_type is the return type
 
};
 

	
 
template <class Result, class Type,  class Param1, class Param2, class Param3, class Param4, class Param5>
 
class far_5_arg_mem_fun_t : public my_5_function<Param1, Param2, Param3, Param4, Param5, Result> {
 
public:
 
explicit far_5_arg_mem_fun_t(Type &ir_typ, Result (Type::*i_pmf)(Param1, Param2, Param3, Param4, Param5)) {
 
			m_ptyp = &ir_typ;
 
			m_pmf = i_pmf;
 
@@ -149,6 +160,8 @@ Result (Type::*m_pmf)(Param1, Param2, Pa
 

	
 
template <class Result, class Type, class Param1, class Param2, class Param3, class Param4, class Param5>far_5_arg_mem_fun_t<Result,Type,Param1, Param2, Param3, Param4, Param5> far_5_arg_mem_fun(Type &ir_typ, Result (Type::*i_pmf)(Param1, Param2, Param3, Param4, Param5) ) {
 
	return far_5_arg_mem_fun_t<Result,Type,Param1, Param2, Param3, Param4, Param5>(ir_typ,i_pmf);
 
 }
 

	
 
#endif
 

	
 
/* finis */
src/flux_function.h
Show inline comments
 
@@ -36,6 +36,8 @@
 
#include "far_mem_5.h"
 

	
 
#define SumFluxFromWalls( _vleafcellp_, _flux_function_ ) \
 
(( _vleafcellp_->ReduceCellAndWalls<double>( far_3_arg_mem_fun( *this, &_flux_function_ ) ) ))
 

	
 
#endif
 

	
 
/* finis */
src/forwardeuler.cpp
Show inline comments
 
@@ -88,24 +88,21 @@ void ForwardEuler::odeint(double *ystart
 
      xp[kount]=x; //Store intermediate results.
 
      for (int i=0;i<nvar;i++) yp[i][kount]=y[i];
 
      kount++;
 
      //xsav=x;
 
    }
 

	
 

	
 
    for (int i=0;i<nvar;i++) {
 
      y[i]=y[i] + h1 * dydx[i];
 
    }
 
      
 
    x = x + h1;
 

	
 
    if ((x-x2)*(x2-x1) >= 0.0) { //Are we done?
 
      goto done;
 
    }
 

	
 

	
 
  }
 

	
 
 done:
 
  for (int i=0;i<nvar;i++) ystart[i]=y[i];
 
  if (kmax) {
 
    xp[kount]=x; //Save final step.
 
@@ -113,8 +110,9 @@ void ForwardEuler::odeint(double *ystart
 
    
 
  }
 
  
 
  delete[] dydx;
 
  delete[] y;
 
  return; //Normal exit.
 
}
 

	
 
}
 
/* finis */
src/forwardeuler.h
Show inline comments
 
@@ -19,13 +19,12 @@
 
 *  along with the Virtual Leaf.  If not, see <http://www.gnu.org/licenses/>.
 
 *
 
 *  Copyright 2010 Roeland Merks.
 
 *
 
 */
 

	
 

	
 
#ifndef _FORWARDEULER_H_
 
#define _FORWARDEULER_H_
 

	
 
class ForwardEuler  {
 

	
 
 public:
 
@@ -52,10 +51,10 @@ class ForwardEuler  {
 
  static const double Safety;
 
  static const double PGrow;
 
  static const double Pshrnk;
 
  static const double Errcon;
 
  static const double Maxstp;
 
  static const double Tiny;
 
  
 

	
 
};
 
#endif
 

	
 
/* finis */
src/infobar.h
Show inline comments
 
@@ -51,7 +51,9 @@ public:
 
	}
 
	
 
private:
 
	QLabel *virtleaf;
 
};
 

	
 
#endif
 
\ No newline at end of file
 
#endif
 

	
 
/* finis */
src/mainbase.cpp
Show inline comments
 
@@ -128,17 +128,17 @@ xmlNode *MainBase::XMLSettingsTree(void)
 
		xmlNode *xmloption = xmlNewChild(xmlsettings, NULL, BAD_CAST "setting", NULL);
 
		xmlNewProp(xmloption, BAD_CAST "name", BAD_CAST "hide_cells");
 
		ostringstream text;
 
		text << bool_name(hidecellsp);
 
		xmlNewProp(xmloption, BAD_CAST "val", BAD_CAST text.str().c_str());
 
	}
 
	
 
	return xmlsettings;
 
}
 

	
 
void MainBase::XMLReadSettings(xmlNode *settings) {
 
void MainBase::XMLReadSettings(xmlNode *settings)
 
{
 
	
 
	// Many files have no settings section, so don't complain about it.
 
	// Defaults will be used instead.
 
	if (settings == 0) {
 
		return;
 
	}
 
@@ -193,31 +193,28 @@ void MainBase::XMLReadSettings(xmlNode *
 
			if (!xmlStrcmp(name,(const xmlChar *)"hide_cells")) {
 
				hidecellsp = strtobool( (const char *)val ); 
 
			}
 
			
 
			xmlFree(name);
 
			xmlFree(val);
 
			
 
			
 
		}
 
		cur=cur->next;
 
	}
 
	
 
}
 

	
 
void MainBase::Save(const char *fname, const char *format, int sizex, int sizey) {
 
void MainBase::Save(const char *fname, const char *format, int sizex, int sizey)
 
{
 
	
 
	Vector ll,ur;
 
	mesh.BoundingBox(ll, ur);
 
	
 
	if (QString(fname).isEmpty()) {
 
		MyWarning::warning("No output filename given. Saving nothing.\n");
 
		return;
 
	}
 
	
 
	
 
	ll*=Cell::Magnification(); ur*=Cell::Magnification();
 
	
 
	// give the leaf some space
 
	Vector border = ((ur-ll)/5.);
 
	
 
	if (!QString(format).contains("pdf", Qt::CaseInsensitive)) {
 
@@ -239,11 +236,12 @@ void MainBase::Save(const char *fname, c
 
		canvas.render(&painter, QRectF(), QRectF(-5000,-5000, 10000, 10000));
 
		
 
		cerr << "Rendering to printer\n";
 
	}
 
}
 

	
 
void MainBase::CutSAM() {
 
	
 
void MainBase::CutSAM()
 
{
 
	mesh.CutAwaySAM();
 
}
 
	
 
}
 
/* finis */
src/mainbase.h
Show inline comments
 
@@ -129,6 +129,8 @@ class MainBase  {
 

	
 
//#include <qapplication.h>
 
#define TIMESTEP double MainBase::TimeStep(void)
 
#define INIT void MainBase::Init(char *leaffile)
 

	
 
#endif
 

	
 
/* finis */
src/matrix.cpp
Show inline comments
 
@@ -32,121 +32,113 @@ Matrix::Matrix(const Vector &c1, const V
 
  
 
  Alloc();
 

	
 
  mat[0][0]=c1.x; mat[0][1]=c2.x; mat[0][2]=c3.x;
 
  mat[1][0]=c1.y; mat[1][1]=c2.y; mat[1][2]=c3.y;
 
  mat[2][0]=c1.z; mat[2][1]=c2.z; mat[2][2]=c3.z;
 

	
 
    
 
}
 

	
 
void Matrix::Alloc(void) {
 

	
 
void Matrix::Alloc(void)
 
{
 
  // constructor
 
  mat = new double*[3];
 
  mat[0] = new double[9];
 
  for (int i=1;i<3;i++)
 
    mat[i]=mat[i-1]+3;
 
  
 
}
 

	
 
Matrix::~Matrix() {
 
 
 
Matrix::~Matrix()
 
{
 
  // destructor
 
  delete[] mat[0];
 
  delete[] mat;
 
}
 

	
 
Matrix::Matrix(void) {
 
  
 
Matrix::Matrix(void)
 
{
 
  // constructor
 
  Alloc();
 

	
 
  // clear matrix
 
  for (int i=0;i<9;i++) {
 
    mat[0][i]=0.;
 
  }
 
 
 
}
 

	
 
Matrix::Matrix(const Matrix &source) {
 
 
 
Matrix::Matrix(const Matrix &source)
 
{
 
  // copy constructor
 
  Alloc();
 
  
 
  for (int i=0;i<9;i++) {
 
    mat[0][i]=source.mat[0][i];
 
  }
 
  
 
}
 

	
 

	
 
void Matrix::operator=(const Matrix &source) {
 
  
 
void Matrix::operator=(const Matrix &source)
 
{
 
  // assignment
 
  
 
  // don't assign to self
 
  if (this==&source) return;
 
  
 
  // copy 
 
  for (int i=0;i<9;i++)
 
    mat[0][i]=source.mat[0][i];
 
  
 
}
 

	
 

	
 
void Matrix::print(ostream *os) {
 
  
 
  *os << "{ { " << mat[0][0] << "," << mat[0][1] << "," << mat[0][2] << "},{" << mat[1][0] << "," << mat[1][1] << "," << mat[1][2] << "},{" << mat[2][0] << "," << mat[2][1] << "," << mat[2][2] << "} }";
 

	
 
void Matrix::print(ostream *os)
 
{
 
  *os << "{ { " << mat[0][0] << "," << mat[0][1] << "," << mat[0][2] 
 
      << "},{" << mat[1][0] << "," << mat[1][1] << "," << mat[1][2] 
 
      << "},{" << mat[2][0] << "," << mat[2][1] << "," << mat[2][2] << "} }";
 
}
 

	
 
ostream &operator<<(ostream &os, Matrix &v) {
 
  v.print(&os);
 
  return os;
 
}
 

	
 

	
 
Vector Matrix::operator*(const Vector &v) const {
 
  
 
Vector Matrix::operator*(const Vector &v) const
 
{
 
  // matrix * vector
 
  Vector result;
 
  
 
  result.x = mat[0][0]*v.x+mat[0][1]*v.y+mat[0][2]*v.z;
 
  result.y = mat[1][0]*v.x+mat[1][1]*v.y+mat[1][2]*v.z;
 
  result.z = mat[2][0]*v.x+mat[2][1]*v.y+mat[2][2]*v.z;
 
  
 
  return result;
 
  
 
  
 
}
 

	
 

	
 
bool Matrix::operator==(Matrix &m) const {
 
   
 
bool Matrix::operator==(Matrix &m) const
 
{
 
  for (int i=0;i<9;i++) {
 
    if ((mat[0][i]-m.mat[0][i])>TINY)
 
      return false;
 
  }
 
  return true;
 
  
 
}
 

	
 
double Matrix::Det(void) const {
 
  
 
double Matrix::Det(void) const
 
{
 
  return 
 
    - mat[0][2]*mat[0][4]*mat[0][6]
 
    + mat[0][1]*mat[0][5]*mat[0][6] 
 
    + mat[0][2]*mat[0][3]*mat[0][7]
 
    - mat[0][0]*mat[0][5]*mat[0][7]
 
    - mat[0][1]*mat[0][3]*mat[0][8]
 
    + mat[0][0]*mat[0][4]*mat[0][8];
 

	
 
}
 

	
 
Matrix Matrix::Inverse(void) const {
 
Matrix Matrix::Inverse(void) const
 
{
 
  
 
  // return the Inverse of this matrix
 
  double rd=1./Det(); // Reciproce Det;
 
  Matrix inverse;
 
  inverse.mat[0][0]=rd*(-mat[0][5]*mat[0][7]+mat[0][4]*mat[0][8]);
 
  inverse.mat[0][1]=rd*( mat[0][2]*mat[0][7]-mat[0][1]*mat[0][8]);
 
@@ -155,20 +147,20 @@ Matrix Matrix::Inverse(void) const {
 
  inverse.mat[0][4]=rd*(-mat[0][2]*mat[0][6]+mat[0][0]*mat[0][8]);
 
  inverse.mat[0][5]=rd*( mat[0][2]*mat[0][3]-mat[0][0]*mat[0][5]);
 
  inverse.mat[0][6]=rd*(-mat[0][4]*mat[0][6]+mat[0][3]*mat[0][7]);
 
  inverse.mat[0][7]=rd*( mat[0][1]*mat[0][6]-mat[0][0]*mat[0][7]);
 
  inverse.mat[0][8]=rd*(-mat[0][1]*mat[0][3]+mat[0][0]*mat[0][4]);
 
  
 

	
 
  return inverse;
 
}
 

	
 
void Matrix::Rot2D(double theta) { 
 
  
 
void Matrix::Rot2D(double theta)
 
{ 
 
  // make this matrix a rotation matrix over theta
 
  // see http://mathworld.wolfram.com/RotationMatrix.html
 
 
 
  mat[0][0] = cos(theta); mat[0][1]=sin(theta);
 
  mat[1][0] = -sin(theta); mat[1][1]=cos(theta);
 
  mat[0][2] = mat[1][2] = mat[2][0] = mat[2][1] = mat[2][2] = 0.;
 
}
 

	
 
}
 
/* finis */
src/matrix.h
Show inline comments
 
@@ -52,6 +52,8 @@ private:
 
  void Alloc(void);
 
};
 

	
 
ostream &operator<<(ostream &os, Matrix &v);
 

	
 
#endif
 

	
 
/* finis */
src/maxmin.h
Show inline comments
 
@@ -30,6 +30,7 @@
 
inline double FMAX(double a, double b) { return a>b ? a : b; }
 
inline double FMIN(double a, double b) { return a<b ? a : b; }
 
inline double SIGN(double a, double b) { return b>=0.0 ? fabs(a) : -fabs(a); }
 

	
 
#endif
 

	
 
/* finis */
src/mesh.cpp
Show inline comments
 
@@ -58,24 +58,22 @@ void Mesh::AddNodeToCellAtIndex(Cell *c,
 

	
 

	
 
void Mesh::AddNodeToCell(Cell *c, Node *n, Node *nb1, Node *nb2) {
 
  
 
  c->nodes.push_back( n );
 
  n->owners.push_back( Neighbor(c, nb1, nb2 ) );
 
  
 
}
 

	
 
void Mesh::PerturbChem(int chemnum, double range) {
 
  
 
  for (vector<Cell *>::iterator i=cells.begin();
 
       i!=cells.end();
 
       i++) {
 
    (*i)->chem[chemnum] += range*(RANDOM()-0.5);
 
    if ((*i)->chem[chemnum]<0.) (*i)->chem[chemnum]=0.;
 
  }
 
  
 
}
 

	
 
void Mesh::CellFiles(const Vector ll, const Vector ur) {
 
  
 
  Cell *cell = RectangularCell(ll,ur,0.001); 
 
  
 
@@ -129,13 +127,12 @@ void Mesh::CellFiles(const Vector ll, co
 
  
 
  Node::target_length = sum_l/(double)n_l;
 
  // a bit more tension
 
  Node::target_length/=4.;
 
  
 
  SetBaseArea();
 

	
 
}
 

	
 
Cell *Mesh::RectangularCell(const Vector ll, const Vector ur, double rotation) {
 

	
 
  Cell *cell=AddCell(new Cell());
 
  cell->m=this;
 
@@ -278,14 +275,12 @@ Cell &Mesh::EllipticCell(double xc, doub
 
  // initial cell has one wall with the outside world
 
  //c->walls.push_back( new Wall ( nodes.front(), nodes.front(), c, boundary_polygon )); 
 
  
 
  c->at_boundary=true;
 
  
 
  return *c;
 

	
 
  
 
}
 

	
 
Cell &Mesh::LeafPrimordium(int nnodes, double pet_length) {
 
  
 
  // first leaf cell
 

	
 
@@ -448,15 +443,12 @@ Cell &Mesh::LeafPrimordium(int nnodes, d
 
  circle->setCellVec(Vector(0,1,0));
 
  
 
  return *circle;
 
}
 

	
 
/*Cell &Mesh::Box() {
 
  
 
  
 
  
 
}*/
 

	
 

	
 
// return bounding box of mesh
 
void Mesh::BoundingBox(Vector &LowerLeft, Vector &UpperRight) {
 
   
 
@@ -475,13 +467,12 @@ void Mesh::BoundingBox(Vector &LowerLeft
 
      UpperRight.x = (*c)->x;
 
    if ((*c)->y > UpperRight.y) 
 
      UpperRight.y = (*c)->y;
 
    if ((*c)->z > UpperRight.z)
 
      UpperRight.z = (*c)->z;
 
  }
 
  
 
}
 

	
 

	
 
double Mesh::Area(void) {
 
  
 
  double area=0;
 
@@ -1026,13 +1017,12 @@ double Mesh::DisplaceNodes(void) {
 
    next_node:
 
      delta_intgrl_list.clear();//dA_list.clear();
 
      
 
    }
 
    
 
    return sum_dh;
 
    
 
}
 
				   
 

	
 
void Mesh::InsertNode(Edge &e) {
 

	
 

	
 
@@ -1185,13 +1175,12 @@ void Mesh::InsertNode(Edge &e) {
 
      c->cell->ConstructNeighborList();
 
      //      debug_stream << "Repairing NeighborList of " << c->cell << endl;
 
    }
 
    c++;
 
  }
 
  //  debug_stream.flush();
 

	
 
}
 

	
 

	
 
/*
 
   Calculate circumcircle of triangle (x1,y1), (x2,y2), (x3,y3)
 
   The circumcircle centre is returned in (xc,yc) and the radius in r
 
@@ -1235,13 +1224,12 @@ void Mesh::CircumCircle(double x1,double
 
  rsqr = dx*dx + dy*dy;
 
  *r = sqrt(rsqr);
 

	
 
  return;
 
  // Suggested
 
  // return((drsqr <= rsqr + EPSILON) ? TRUE : FALSE);
 

	
 
}
 
  
 
//
 

	
 
// return the total amount of chemical "ch" in the leaf
 
double Mesh::SumChemical(int ch) {
 
@@ -1251,13 +1239,12 @@ double Mesh::SumChemical(int ch) {
 
       i!=cells.end();
 
       i++) {
 
  
 
    sum+=(*i)->chem[ch];
 
  }
 
  return sum;
 

	
 
}
 

	
 

	
 

	
 
void Mesh::CleanUpCellNodeLists(void) {
 
  
 
@@ -1436,13 +1423,12 @@ void Mesh::CleanUpCellNodeLists(void) {
 
  // remake shuffled_nodes and shuffled cells
 
  shuffled_nodes.clear();
 
  shuffled_nodes = nodes;
 
  
 
  shuffled_cells.clear();
 
  shuffled_cells = cells;
 
 
 
}
 

	
 
void Mesh::CutAwayBelowLine( Vector startpoint, Vector endpoint) {
 
  
 
  // Kills all cells below the line startpoint -> endpoint
 
  
 
@@ -1469,13 +1455,12 @@ void Mesh::CutAwayBelowLine( Vector star
 
  #ifdef QDEBUG
 
  qDebug() << "Before CleanUpCellNodeLists" << endl;
 
  #endif
 
  TestIllegalWalls();
 
  
 
  CleanUpCellNodeLists();
 

	
 
}
 

	
 
void Mesh::CutAwaySAM(void) {
 

	
 
  for (vector<Cell *>::iterator i=cells.begin();
 
       i!=cells.end();
 
@@ -1487,27 +1472,24 @@ void Mesh::CutAwaySAM(void) {
 
    }
 
  }
 

	
 
  TestIllegalWalls();
 
  
 
  CleanUpCellNodeLists();
 

	
 

	
 
}
 
void Mesh::TestIllegalWalls(void) {
 

	
 
  for (list<Wall *>::iterator w = walls.begin();
 
       w!=walls.end();
 
       w++) {
 
    if ((*w)->IllegalP() ) {
 
      #ifdef QDEBUG
 
      qDebug() << "Wall " << **w << " is illegal." << endl;
 
      #endif
 
    }
 
  }
 

	
 
}
 

	
 

	
 

	
 
class node_owners_eq : public unary_function<Node, bool> {
 
  int no;
 
@@ -1518,13 +1500,12 @@ public:
 
  bool operator() (const Node &n) const {
 
    if (n.CellsSize()==1) 
 
      return true;
 
    else 
 
      return false;
 
  }
 
  
 
};
 

	
 

	
 
void Mesh::RepairBoundaryPolygon(void) {
 
  
 
  // After serious manipulations (e.g. after cutting part off the
 
@@ -1649,13 +1630,12 @@ void Mesh::RepairBoundaryPolygon(void) {
 
  foreach(Cell* cell, cells) {
 
    qDebug() << *cell;
 
  }
 
  qDebug() << endl;
 
  #endif
 
#endif
 

	
 
}
 

	
 

	
 
Node* Mesh::findNextBoundaryNode(Node* boundary_node) {
 
  bool found_next_boundary_node = false;
 
  Node *next_boundary_node = NULL;
 
@@ -1752,13 +1732,12 @@ void Mesh::Rotate(double angle, Vector c
 
}
 

	
 

	
 
void Mesh::PrintWallList( void ) {
 
  
 
   transform ( walls.begin(), walls.end(), ostream_iterator<Wall>(cerr, "\n"), deref_ptr<Wall> );
 

	
 
}
 

	
 
#include <QString>
 
//#include "forwardeuler.h"
 
#include "rungekutta.h"
 

	
 
@@ -1825,13 +1804,12 @@ void Mesh::ReactDiffuse(double delta_t) 
 
  
 
  solver->odeint(ystart, nvar, getTime(), getTime() + delta_t, 
 
		 par.ode_accuracy, par.dt, 1e-10, &nok, &nbad);
 
  
 
  setTime(getTime()+delta_t);
 
  setValues(getTime(),ystart);
 
  
 
}
 

	
 

	
 
Vector Mesh::FirstConcMoment(int chem) {
 
  
 
  Vector moment;
 
@@ -1871,13 +1849,12 @@ void Mesh::DeleteLooseWalls(void) {
 
      }
 
    } else {
 
      w++;
 
    }
 
    
 
  }
 
  
 
}
 

	
 
/*void Mesh::FitLeafToCanvas(double width, double height) {
 

	
 
  Vector bbll,bbur;
 
  BoundingBox(bbll,bbur);
 
@@ -1910,14 +1887,12 @@ void Mesh::CleanChemicals(const vector<d
 
		for (int i=0;i<Cell::NChem();i++) {
 
			(*c)->SetChemical(i,clean_chem[i]);
 
		}
 
		(*c)->SetNewChemToChem();
 
		
 
	}
 
	
 

	
 
}
 

	
 

	
 
void Mesh::CleanTransporters(const vector<double> &clean_transporters) {
 
	
 
	if (clean_transporters.size()!=(unsigned)Cell::NChem()) {
 
@@ -1932,13 +1907,12 @@ void Mesh::CleanTransporters(const vecto
 
		
 
		for (int i=0;i<Cell::NChem();i++) {
 
			(*w)->setTransporters1(i,clean_transporters[i]); (*w)->setNewTransporters1(i,clean_transporters[i]);
 
			(*w)->setTransporters2(i,clean_transporters[i]); (*w)->setNewTransporters2(i,clean_transporters[i]);
 
		}
 
	}
 
	
 
}
 

	
 

	
 
void Mesh::RandomizeChemicals(const vector<double> &max_chem, const vector<double> &max_transporters) {
 
  
 
  if (max_chem.size()!=(unsigned)Cell::NChem() || max_transporters.size()!=(unsigned)Cell::NChem()) {
 
@@ -1963,13 +1937,12 @@ void Mesh::RandomizeChemicals(const vect
 
    
 
    for (int i=0;i<Cell::NChem();i++) {
 
      (*w)->setTransporters1(i,max_transporters[i] * RANDOM()); (*w)->setNewTransporters1(i, (*w)->Transporters1(i) );
 
      (*w)->setTransporters2(i,max_transporters[i] * RANDOM()); (*w)->setNewTransporters2(i, (*w)->Transporters1(i) );
 
    }
 
  }
 
  
 
}
 

	
 
//!\brief Calculates a vector with derivatives of all variables, which
 
// we can pass to an ODESolver. 
 
void Mesh::Derivatives(double *derivs) {
 
  
 
@@ -2021,14 +1994,12 @@ void Mesh::Derivatives(double *derivs) {
 
	  plugin->CelltoCellTransport(*w, dchem_c1, dchem_c2); 
 
								  
 
	  //(*tf)(*w, &(derivs[(*w)->c1->Index() * nchems]),
 
      //&(derivs[(*w)->c2->Index() * nchems] ) );
 
    i+=2*nchems;
 
  }
 
  
 
  
 
}
 

	
 
void Mesh::setValues(double x, double *y) {
 

	
 
  //int nwalls = walls.size();
 
  //int ncells = cells.size();
 
@@ -2135,13 +2106,12 @@ void Mesh::DrawNodes(QGraphicsScene *c) 
 
    
 
    item->setZValue(5);
 
    item->show();
 
    item ->setPos(((Cell::offset[0]+i->x)*Cell::factor),
 
		  ((Cell::offset[1]+i->y)*Cell::factor) );
 
  }
 

	
 
}
 

	
 
/*! Returns the sum of protein "ch" of a cycling protein in cells and walls */
 
double Mesh::CalcProtCellsWalls(int ch) const {
 

	
 

	
 
@@ -2161,13 +2131,12 @@ double Mesh::CalcProtCellsWalls(int ch) 
 
       c++) {
 
    
 
    sum_prot += (*c)->Chemical(ch);
 
  }
 
  
 
  return sum_prot;
 

	
 
}
 

	
 
void Mesh::SettoInitVals(void) {
 
  
 
  vector<double> clean_chem(Cell::NChem());
 
  vector<double> clean_transporters(Cell::NChem());
 
@@ -2179,13 +2148,12 @@ void Mesh::SettoInitVals(void) {
 

	
 
  // Amount of PIN1
 
  //clean_chem[1] = 0.;
 
  
 
	CleanChemicals(clean_chem);
 
	CleanTransporters(clean_transporters);
 

	
 
}
 

	
 
string Mesh::getTimeHours(void) const {
 
	int hours = (int)(time / 3600);
 
	int mins = (int)((time - hours * 3600)/60);
 
	int secs = (int)((time - hours * 3600 - mins * 60));
src/mesh.h
Show inline comments
 
@@ -162,27 +162,24 @@ public:
 
		
 
		for (vector<Node *>::const_iterator i=shuffled_nodes.begin();
 
			 i!=shuffled_nodes.end();
 
			 i++) {
 
			f(*shuffled_nodes[*i]);
 
		}
 
		
 
	}
 
	
 
	template<class Op> void RandomlyLoopCells(Op f) {
 
		
 
		MyUrand r(shuffled_cells.size());
 
		random_shuffle(shuffled_cells.begin(),shuffled_cells.end(),r);
 
		
 
		for (vector<Cell *>::const_iterator i=shuffled_cells.begin();
 
			 i!=shuffled_cells.end();
 
			 i++) {
 
			f(*shuffled_cells[*i]);
 
		}
 
		
 
		
 
	}
 
	
 
	template<class Op1, class Op2> void LoopCells(Op1 f, Op2 &g) {
 
		for (vector<Cell *>::iterator i=cells.begin();
 
			 i!=cells.end();
 
			 i++) {
 
@@ -424,6 +421,8 @@ private:
 
	}
 
	
 
	void CircumCircle(double x1,double y1,double x2,double y2,double x3,double y3,
 
					  double *xc,double *yc,double *r);
 
};
 
#endif
 

	
 
/* finis */
src/miscq.cpp
Show inline comments
 
@@ -23,15 +23,16 @@
 
#include <QString>
 
#include <QStringList>
 

	
 
static const std::string _module_id("$Id$");
 

	
 
// Returns the extension of a filename
 
QString getExtension(const QString fn) {
 
  
 
QString getExtension(const QString fn)
 
{
 
  // split on dots
 
  QStringList parts = fn.split(".");
 
  
 
  // return last part, this should be the extension
 
  return QString(parts.last());
 
}
 
  
 
}
 
/* finis */
src/miscq.h
Show inline comments
 
@@ -30,6 +30,7 @@
 
// Miscellaneous helper functions, using Qt
 

	
 
QString getExtension(const QString fn);
 

	
 
#endif
 

	
 
/* finis */
src/modelcatalogue.h
Show inline comments
 
@@ -52,9 +52,8 @@ public slots:
 
	void InstallModel(SimPluginInterface *model);	
 
	void InstallModel(QAction *modelaction);
 
private:
 
	QVector<SimPluginInterface *> models;
 
	Mesh *mesh;
 
	Main *mainwin;
 

	
 
};
 
#endif
src/node.cpp
Show inline comments
 
@@ -46,74 +46,75 @@ ostream &Edge::print(ostream &os) const 
 
}
 

	
 
ostream &Neighbor::print(ostream &os) const {
 
  
 
  os << " {" << cell->Index() << " " << nb1->Index() << " " << nb2->Index() << "}";
 
  return os;
 

	
 
}
 

	
 
ostream &operator<<(ostream &os, const Neighbor &n) {
 
  n.print(os);
 
  return os;
 
}
 
 
 

	
 
Node::Node(void) : Vector() {
 

	
 
Node::Node(void) : Vector()
 
{
 
  index=(nnodes++);
 
  node_set =0;
 
  fixed=false;
 
  boundary=false;
 
  sam=false;
 
  dead=false;
 
}
 

	
 
Node::Node(int ind) : Vector() {
 
Node::Node(int ind) : Vector()
 
{
 
  node_set =0;
 
  index=ind;
 
  fixed=false;
 
  boundary=false;
 
  sam=false;
 
  dead=false;
 
}
 

	
 
Node::Node(const Vector &src) : Vector(src) {
 

	
 
Node::Node(const Vector &src) : Vector(src)
 
{
 
  node_set = 0;
 
  index=(nnodes++);
 
  fixed=false;
 
  boundary=false;
 
  sam=false;
 
  dead = false;
 
}
 

	
 
Node::Node(double x,double y, double z) : Vector (x,y,z) {
 
  
 
Node::Node(double x,double y, double z) : Vector (x,y,z)
 
{
 
  node_set = 0;
 
  index=(nnodes++);
 
  fixed=false;
 
  boundary=false;
 
  sam=false;
 
  dead = false;
 
}
 

	
 
Node::Node(const Node &src) : Vector(src) {
 
  
 
Node::Node(const Node &src) : Vector(src)
 
{
 
  node_set=0;
 
  owners=src.owners;
 
  m=src.m;
 
  index=src.index;
 
  fixed = src.fixed;
 
  boundary = src.boundary;
 
  sam=src.sam;
 
  dead = src.dead;
 
}
 

	
 

	
 
Cell &Node::getCell(const Neighbor &i) {
 
Cell &Node::getCell(const Neighbor &i)
 
{
 
  return *i.getCell(); // use accessor!
 
}
 

	
 

	
 
ostream &Node::print(ostream &os) const {
 
  
 
@@ -129,13 +130,12 @@ ostream &Node::print(ostream &os) const 
 
  for (list<Neighbor>::const_iterator i =  owners.begin(); i!=owners.end(); i++) {
 
    os << " {" << i->cell->Index() << " " << i->nb1->Index() << " " << i->nb2->Index() << "} ";
 
  }
 
  os << " } " << endl;
 

	
 
  return os;
 

	
 
}
 

	
 

	
 
#ifdef QTGRAPHICS
 
void Node::DrawIndex(QGraphicsScene *c) const {
 

	
 
@@ -153,33 +153,28 @@ void Node::DrawIndex(QGraphicsScene *c) 
 
		   ((offs.y+y)*Cell::Factor()) );
 
}
 

	
 
void Node::DrawOwners(QGraphicsScene *c) const {
 
  
 
  stringstream text;
 
  
 
  
 

	
 
  text << owners.size();
 
  
 
  
 
  QGraphicsSimpleTextItem *number = new QGraphicsSimpleTextItem ( QString (text.str().c_str()), 0, c );
 
  number->setFont( QFont( "Helvetica", par.nodenumsize, QFont::Bold) );
 
  number->setPen( QPen(par.textcolor) );
 
  number->setZValue(20);
 
  number->show();
 
  Vector offs=Cell::Offset();
 
  
 
  number ->setPos(((offs.x+x)*Cell::Factor()),
 
		  ((offs.y+y)*Cell::Factor()) );
 
}
 

	
 

	
 

	
 
QVector<qreal> Node::NeighbourAngles(void) {
 
	
 
QVector<qreal> Node::NeighbourAngles(void)
 
{
 
	QVector<qreal> angles;
 
	for (list<Neighbor>::iterator i=owners.begin();
 
		 i!=owners.end();
 
		 i++) {
 
		
 
		Vector v1 = (*this - *i->nb1).Normalised();
 
@@ -189,13 +184,14 @@ QVector<qreal> Node::NeighbourAngles(voi
 
		if (angle<0) {
 
			//cerr << "Changing sign of angle " << angle << endl;
 
			angle = angle + 2*Pi;
 
		}
 
		angles.push_back(angle);
 
		
 
		//cerr << "Cell " << i->cell->Index() << ": " <<  v1 << " and " << v2 << ": angle = " << angles.back() << ", " << v1.Angle(v2) << endl;
 
    //cerr << "Cell " << i->cell->Index() << ": " <<  v1 << " and " << v2 
 
    //     << ": angle = " << angles.back() << ", " << v1.Angle(v2) << endl;
 
		
 
	}
 
	
 
	double sum=0.;
 
	for (QVector<qreal>::iterator i=angles.begin();
 
		 i!=angles.end();
 
@@ -209,15 +205,14 @@ QVector<qreal> Node::NeighbourAngles(voi
 
		MyWarning::warning("sum = %f",sum);
 
	}
 
		return angles;
 
}
 

	
 

	
 

	
 
#endif
 

	
 

	
 
ostream &operator<<(ostream &os, const Node &n) {
 
  n.print(os);
 
  return os;
 
}
 

	
 
/* finis */
src/node.h
Show inline comments
 
@@ -75,13 +75,12 @@ public:
 
  }
 
  
 

	
 
  // Output the Edge
 
  ostream &print(ostream &os) const;
 
    
 
  
 
  Node *first, *second;
 
};
 

	
 

	
 
class NodeSet;
 

	
 
@@ -135,51 +134,38 @@ public:
 
  void Draw(QGraphicsScene &c, QColor color=QColor("black"), int size = 10) const;
 
  void DrawIndex(QGraphicsScene *c) const;
 
  void DrawOwners(QGraphicsScene *c) const;
 
#endif
 
  
 
  // temporary function for easier debugging
 
  inline int CellsSize(void) const {
 
    return owners.size();
 
  }
 
  inline int CellsSize(void) const { return owners.size(); }
 

	
 
  inline int Value(void) const { return owners.size(); }
 

	
 
  inline int Value(void) const {
 
    return owners.size();
 
  }
 
  void Fix(void) { fixed=true; }
 

	
 
  inline bool Fixed(void) const { return fixed; }
 

	
 
  inline void Unfix(void) { fixed=false; }
 

	
 
  void Fix(void) {
 
    fixed=true;
 
  }
 
  inline bool Fixed(void) const {
 
    return fixed;
 
  }
 
  inline void Unfix(void) {
 
    fixed=false;
 
  }
 
  inline void MarkDead(void) {
 
    dead=true;
 
  }
 
  inline bool DeadP(void) {
 
    return dead;
 
  }
 
  inline void MarkDead(void) { dead=true; }
 

	
 
  inline bool DeadP(void) { return dead; }
 

	
 
  inline void Mark(void) {
 
    marked=true;
 
  }
 
  inline void Unmark(void) {
 
    marked=false;
 
  }
 
  inline bool Marked(void) const {
 
    return marked;
 
  }
 
  inline void Mark(void) { marked=true; }
 

	
 
  inline void Unmark(void) { marked=false; }
 

	
 
  inline bool Marked(void) const { return marked; }
 
  
 
  inline void setPos( Vector p ) { 
 
    x = p.x;
 
    y = p.y;
 
    z = p.z;
 
  }
 

	
 
  inline bool SamP(void) const { return sam; }
 

	
 
  //!\brief Calculate angles with neighboring vertices
 
  //! Sum of angles should be 2*Pi
 
  QVector<qreal> NeighbourAngles(void);
 
private:
 
@@ -207,8 +193,9 @@ ostream &operator<<(ostream &os, const N
 

	
 
inline ostream &operator<<(ostream &os, const Edge &e) {
 
  e.print(os);
 
  return os;
 
}
 

	
 
#endif
 

	
 
#endif
 
/* finis */
src/nodeitem.cpp
Show inline comments
 
@@ -36,27 +36,26 @@ NodeItem::NodeItem( Node *n, QGraphicsSc
 
  : QGraphicsItem( 0, canvas ), SimItemBase( n, canvas) {
 
  
 
  brush = Qt::darkGray;
 
  
 
  const double mag = par.node_mag;
 
  ellipsesize=QRectF(-1*mag, -1*mag, 2*mag, 2*mag);
 

	
 
}
 

	
 
void NodeItem::userMove(double dx, double dy) {
 
void NodeItem::userMove(double dx, double dy)
 
{
 
  QGraphicsItem::moveBy( dx, dy );
 
  
 
  class_cast<Node *>(obj)->x += (dx/Cell::Magnification());
 
  class_cast<Node *>(obj)->y += (dy/Cell::Magnification());
 
}
 

	
 

	
 

	
 
void NodeItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *)
 
{
 

	
 
  option = NULL; // use assignment merely to obviate compilation warning
 
  
 
  painter->setBrush(brush);
 
  painter->setPen(Qt::NoPen);
 
  painter->drawEllipse(ellipsesize);
 
}
 
@@ -74,31 +73,32 @@ QRectF NodeItem::boundingRect() const
 
  qreal penwidth = 0;// painter->pen()->widthF();
 
  return QRectF(ellipsesize.x()-penwidth/2.,ellipsesize.y()-penwidth/2.,
 
		ellipsesize.width()+penwidth, ellipsesize.height()+penwidth);
 
}
 

	
 
// polymorphic OnClick functions
 
void NodeItem::OnClick(void) {
 
void NodeItem::OnClick(void)
 
{
 
  Node *n = &getNode();
 
  n->toggleBoundary();
 
  setColor();
 
  update();
 
}
 

	
 
void NodeItem::OnClick(const Qt::MouseButton &mb) {
 
void NodeItem::OnClick(const Qt::MouseButton &mb)
 
{
 
  if (mb == Qt::LeftButton) {
 
    Node *n = &getNode();
 
    n->toggleBoundary();
 
    setColor();
 
    update();
 

	
 
  }
 
}
 

	
 
void NodeItem::setColor(void) {
 

	
 
void NodeItem::setColor(void)
 
{
 
  static QColor indian_red("IndianRed");
 
  static QColor deep_sky_blue("DeepSkyBlue");
 
  static QColor purple("Purple");
 
  
 
  Node &n=getNode();
 

	
 
@@ -110,6 +110,8 @@ void NodeItem::setColor(void) {
 
    } 
 
    else {
 
      setBrush( indian_red );
 
    }
 
  }
 
}
 

	
 
/* finis */
src/nodeitem.h
Show inline comments
 
@@ -53,6 +53,8 @@ protected:
 
  QRectF ellipsesize;
 

	
 
private:
 
};
 

	
 
#endif
 

	
 
/* finis */
src/nodeset.cpp
Show inline comments
 
@@ -26,6 +26,8 @@
 
static const std::string _module_id("$Id$");
 

	
 
ostream &operator<<(ostream &os, const NodeSet &ns)  {
 
  ns.print(os);
 
  return os;
 
}
 

	
 
/* finis */
src/nodeset.h
Show inline comments
 
@@ -58,14 +58,13 @@ class NodeSet : public list<Node *> {
 
    
 
    cellset.sort();
 
    
 
    // remove all non-unique elements
 
    // (unique moves all unique elements to the front and returns an iterator to the end of the unique elements;
 
    // so we simply erase all remaining elements.
 
    cellset.erase(::unique(cellset.begin(), cellset.end() ), 
 
		  cellset.end() );
 
    cellset.erase(::unique(cellset.begin(), cellset.end() ), cellset.end() );
 
    
 
    // remove boundary_polygon
 
    cellset.erase( find_if ( cellset.begin(), cellset.end(), mem_fun( &Cell::BoundaryPolP  ) ) );
 
    return cellset;
 
  }
 

	
 
@@ -108,13 +107,12 @@ class NodeSet : public list<Node *> {
 
	  n!=end();
 
	  ++n ) {
 
       
 
      (*n)->x+=rx;
 
      (*n)->y+=ry;
 
      // (*n)->z += rz;
 
       
 
    }
 
    
 
    // 4. Recalculate the energy
 
    double new_energy = 0.;
 
    for ( list<Cell *>::const_iterator i = celllist.begin(); 
 
	  i!=celllist.end();
 
@@ -148,19 +146,19 @@ class NodeSet : public list<Node *> {
 
	    n!= end();
 
	    ++n ) {
 
	
 
	(*n)->x-=rx;
 
	(*n)->y-=ry;
 
	  }
 
      
 
      
 
    }
 
  }
 
  
 
  void XMLAdd(xmlNode *root) const;
 
  void XMLRead(xmlNode *root, Mesh *m);
 
 private:
 
  bool done;
 
};
 

	
 
ostream &operator<<(ostream &os, const NodeSet &ns);
 
#endif
 

	
 
/* finis */
src/output.cpp
Show inline comments
 
@@ -58,13 +58,12 @@ int FileExistsP(const char *fname) {
 
  fp=fopen(fname,"r");
 
  if (fp==NULL)
 
    return FALSE;
 
  
 
  fclose(fp);
 
  return TRUE;
 
 
}
 
		       
 
int YesNoP(const char *message) {
 
  
 
  char answer[100];
 
 
@@ -78,19 +77,17 @@ int YesNoP(const char *message) {
 
    scanf("%s",answer);
 
  }
 
  
 
  if (!strcmp(answer,"y")) return TRUE;
 
  
 
  return FALSE;
 
    
 
}
 
 
 
FILE *OpenWriteFile(const char *filename) 
 
{
 
 
  char fname[FNAMESIZE];
 
 
  FILE *fp;
 
 
  fprintf(stderr,"Opening %s for writing\n",filename);
 
	
 
@@ -105,26 +102,24 @@ FILE *OpenWriteFile(const char *filename
 
	throw(message);
 
      }
 
    } else {
 
      /* Rename old file */
 
      sprintf(fname, "%s~",filename);
 
      rename(filename, fname);
 
      
 
    }
 
  }
 
  
 
  strncpy(fname, filename, FNAMESIZE-1);
 
  
 
  if ((fp=fopen(fname,"w"))==NULL) {
 
    char *message=(char *)malloc(2000*sizeof(char));
 
    sprintf(message," Could not open file %s for writing: "
 
	    ,fname);
 
    perror("");
 
    throw(message);
 
  }
 
	
 
  return fp;
 
}
 
 
 
FILE *OpenReadFile(const char *filename) 
 
{
 
@@ -167,50 +162,42 @@ char *ReadLine(FILE *fp)
 
 
  pos=0;
 
  
 
  while ((character=getc(fp))!=EOF && /* read a character and check */
 
		 character!='\n') {
 
 
	
 
	tmpstring[pos]=(char)character;
 
	(pos)++;
 
 
	if (pos >= bufsize) {
 
	  /* line is longer than initial_bufsize, reallocate space */
 
	  bufsize+=INITIAL_BUFSIZE;
 
	  MEMORYCHECK(tmpstring=(char *)realloc(tmpstring,bufsize*sizeof(char)));
 
	  
 
	}
 
		   
 
  }
 
 
 
  if (character==EOF) {
 
	
 
	if (pos==0) {
 
	  /* EOF was reached, while no characters were read */
 
	  free(tmpstring);
 
	  return NULL;
 
 
	}
 
	if (ferror(fp)) {
 
	  error("I/O error in ReadLine(%ld): %s\n",fp, strerror(errno));
 
	}
 
	
 
 
  }
 
  
 
  /* Allocate enough memory for the line */
 
  MEMORYCHECK(line=(char *)malloc((++(pos))*sizeof(char)));
 
 
  strncpy(line,tmpstring,(pos)-1);
 
  free(tmpstring);
 
  
 
  line[pos-1]='\0';
 
  return line;
 
    
 
}
 
 
 
void CheckFile(FILE *fp) 
 
{
 
  if (ftell(fp)<0) {
 
@@ -234,13 +221,12 @@ char *Chext(char *filename) {
 
  int i;
 
  char *result;
 
 
  for (i=strlen(filename)-1;i>=0;i--) {
 
    if (filename[i]=='.') 
 
      break;
 
    
 
  }
 
  
 
  /* No . found */
 
  if (i==0) {
 
    
 
    result=strdup(filename);
 
@@ -248,14 +234,12 @@ char *Chext(char *filename) {
 
   
 
    /* . found */
 
    result=(char *)malloc((i+1)*sizeof(char));
 
    strncpy(result, filename, i);
 
  }
 
  return result;
 
  
 
  
 
}
 
 
void MakeDir(const char *dirname) {
 
 
#ifdef QTGRAPHICS
 
  QFileInfo file_info(dirname);
 
@@ -270,13 +254,12 @@ void MakeDir(const char *dirname) {
 
    } else {
 
      char *message = new char[MESS_BUF_SIZE+1];
 
      snprintf(message, MESS_BUF_SIZE, "%s is not a directory", dirname);
 
      cerr << message << endl;
 
      throw(message);
 
    }
 
    
 
  }
 
 
  // make directory
 
  QDir dir;
 
  if (!dir.mkdir(QString(dirname))) {
 
    char *message = new char[MESS_BUF_SIZE+1];
 
@@ -326,16 +309,14 @@ void MakeDir(const char *dirname) {
 
    } else {
 
      // a different error occurred. Print error and quit 
 
      
 
      snprintf(message,MESS_BUF_SIZE,"Error in making directory %s",dirname);
 
      perror(message);
 
      exit(1);
 
      
 
    }
 
  
 
 
 
  }
 
 
#endif
 
}
 
 
 
/* finis */
src/output.h
Show inline comments
 
@@ -50,6 +50,8 @@ bool CanWeWriteP(char *filename);
 
#ifndef FALSE
 
#define FALSE 0
 
#define TRUE 1
 
#endif
 

	
 
#endif
 

	
 
/* finis */
src/parameter.cpp
Show inline comments
 
@@ -186,13 +186,12 @@ Parameter::~Parameter() {
 
  
 
  // destruct parameter object
 

	
 
  // free string parameter
 

	
 
  CleanUp();
 

	
 
}
 

	
 
void Parameter::CleanUp(void) {
 
  if (arrowcolor) 
 
     free(arrowcolor);
 
  if (textcolor) 
 
@@ -214,13 +213,12 @@ void Parameter::CleanUp(void) {
 
  if (s3) 
 
     free(s3);
 
  if (dir1) 
 
     free(dir1);
 
  if (dir2) 
 
     free(dir2);
 

	
 
}
 

	
 
void Parameter::Read(const char *filename) {
 
  
 
  static bool ReadP=false;
 

	
 
@@ -336,13 +334,12 @@ void Parameter::Read(const char *filenam
 
  dir1 = sgetpar(fp, "dir1", ".", true);
 
  if (strcmp(dir1, "."))
 
    MakeDir(dir1);
 
  dir2 = sgetpar(fp, "dir2", ".", true);
 
  if (strcmp(dir2, "."))
 
    MakeDir(dir2);
 

	
 
}
 

	
 
const char *sbool(const bool &p) {
 

	
 
  const char *true_str="true";
 
  const char *false_str="false";
 
@@ -1873,13 +1870,12 @@ if (!strcmp(namec, "k")) {
 
	par_node = par_node->next;
 
      }
 

	
 
    }
 
    cur=cur->next;
 
  }
 
    
 
}*/
 

	
 
ostream &operator<<(ostream &os, Parameter &p) {
 
  p.Write(os);
 
  return os;
 
}
src/pardialog.cpp
Show inline comments
 
@@ -691,13 +691,12 @@ void ParameterDialog::write(void) {
 
    if (QMessageBox::question(this, "Syntax error", tr("Value %1 of parameter %2 is not recognized as Boolean.\nDo you mean TRUE or FALSE?").arg(tmpval).arg("b4"),"True","False", QString::null, 0, 1)==0) par.b4=true;
 
      else par.b4=false;
 
  }
 
  par.dir1 = strdup((const char *)dir1_edit->text());
 
  par.dir2 = strdup((const char *)dir2_edit->text());
 
  Reset();
 

	
 
}
 
void ParameterDialog::Reset(void) {
 
  extern Parameter par;
 
  arrowcolor_edit->setText( QString("%1").arg(par.arrowcolor) );
 
  arrowsize_edit->setText( QString("%1").arg(par.arrowsize) );
 
  textcolor_edit->setText( QString("%1").arg(par.textcolor) );
src/parse.cpp
Show inline comments
 
@@ -61,13 +61,12 @@ char *ParsePar(FILE *fp, char *parameter
 
		  line);
 
 
  value=strdup(token);
 
  free(line);
 
  
 
  return value;
 
      
 
}
 
 
 
int igetpar(FILE *fp,char *parameter, bool wrapflag) {
 
  
 
  // overloaded compatibility function. Doesn't need default parameter
 
@@ -92,13 +91,12 @@ int igetpar(FILE *fp,char *parameter, in
 
  sscanf(token,"%d",&value);
 
  fprintf(stderr, "%d]\n",value);
 
  
 
  free(token);
 
 
  return value;
 
  
 
}
 
 
float fgetpar(FILE *fp,char *parameter, bool wrapflag) {
 
   
 
  // overloaded compatibility function. Doesn't need default parameter
 
  return fgetpar(fp, parameter, 0., wrapflag);
 
@@ -117,19 +115,15 @@ float fgetpar(FILE *fp, char *parameter,
 
    warning("No token %s found. Using default value %f.\n", parameter, default_val);
 
    return default_val;
 
  }
 
 
  /* read it */
 
  sscanf(token,"%e",&value);
 
 
  fprintf(stderr,"%e]\n",value);
 
  
 
  free(token);
 
 
  return value;
 
  
 
}
 
 
 
double *dgetparlist(FILE *fp,char *parameter, int n, bool wrapflag) 
 
{
 
  /* Get a list of n comma separated doubles */
 
@@ -177,13 +171,12 @@ double *dgetparlist(FILE *fp,char *param
 
      fprintf(stderr," %lf ",value[i]);
 
    }
 
    fprintf(stderr, "\n");
 
  }
 
  
 
  return value;
 
  
 
}
 
 
char *sgetpar(FILE *fp,char *parameter, bool wrapflag) 
 
{
 
  return sgetpar(fp, parameter, " ", wrapflag);
 
}
 
@@ -210,13 +203,12 @@ char *sgetpar(FILE *fp, char *parameter,
 
  sprintf(value,"%s",&token[pos]);
 
  free(token);
 
 
  fprintf(stderr,"%s]\n",value);
 
 
  return value;
 
  
 
}
 
 
char *bool_str(bool bool_var) {
 
  
 
  /* Return string "true" if bool_var=true */
 
  /* Return string "false" if bool_var=false */
 
@@ -226,22 +218,20 @@ char *bool_str(bool bool_var) {
 
 
  if (bool_var) {
 
    return t;
 
  } else {
 
    return f;
 
  }
 
  
 
}
 
 
bool bgetpar(FILE *fp, char *parameter,  bool wrapflag) {
 
  
 
  // overloaded compatibility function. Doesn't need default parameter
 
  // default = false
 
 
  return bgetpar(fp, parameter, 0, wrapflag);
 
 
}
 
 
bool bgetpar(FILE *fp, char *parameter, int default_val, bool wrapflag) {
 
 
  /* Get boolean parameter. */
 
  /* if "true" or "yes", return 1 */
 
@@ -273,13 +263,12 @@ bool bgetpar(FILE *fp, char *parameter, 
 
  else
 
    error("Keyword '%s' not recognized. Try yes/no or true/false.\n",&token[pos]);
 
 
  fprintf(stderr, "%s]\n",bool_str(value));
 
 
  return value;
 
 
}
 
 
 
char *SearchToken(FILE *fp, char *token,bool wrapflag) 
 
{
 
  /* This function returns the next line of FILE *fp that contains
 
@@ -341,15 +330,13 @@ char *SearchToken(FILE *fp, char *token,
 
	{
 
	  free(tokenplusspace);
 
	  return line;
 
	}
 
    }
 
    
 
 
    free(line);
 
    
 
  }
 
  free(tokenplusspace);
 
  return NULL; /* Token Not Found in the file */
 
}
 
 
int TokenInLineP(char *line,char *token) 
 
@@ -364,13 +351,12 @@ int TokenInLineP(char *line,char *token)
 
void SkipLine(FILE *fp) {
 
  
 
  /* Just skips a line in FILE *fp */
 
  char *tmpstring;
 
  tmpstring=ReadLine(fp);
 
  free(tmpstring);
 
  
 
}
 
 
void SkipToken(FILE *fp,char *token, bool wrapflag)
 
{
 
  /* A very simple function:
 
	 call SearchToken() and get rid of the memory returned by
 
@@ -383,9 +369,9 @@ void SkipToken(FILE *fp,char *token, boo
 
 
  if (tmppointer==NULL) {
 
	error("Token `%s' not found by function SkipToken.\n",token);
 
  }
 
 
  free(tmppointer);
 
      
 
}
 
 
/* finis */
src/parse.h
Show inline comments
 
@@ -41,6 +41,8 @@ char *SearchToken(FILE *fp, char *token,
 
int TokenInLineP(char *line,char *token);
 
void SkipToken(FILE *fp,char *token, bool wrapflag);
 
void SkipLine(FILE *fp);
 
char *bool_str(bool bool_var);
 

	
 
#endif
 

	
 
/* finis */
src/perl/deployapp.pl
Show inline comments
 
@@ -109,6 +109,8 @@ for $lib (@additionallibs) {
 
  for $fwfw (@frameworks_of_lib) {
 
    #    print "$fwfw\n";
 
    $liblib = $fwfw; $liblib =~ s/\.framework//g;    
 
    system "install_name_tool -change $fwfw/Versions/4/$liblib \@executable_path/../Frameworks/$fwfw/Versions/4.0/$liblib  $appdir/Contents/Frameworks/$lib";
 
  }
 
}
 

	
 
# finis
src/perl/histogram.pl
Show inline comments
 
@@ -42,6 +42,9 @@ while (<>) {
 

	
 

	
 
for ($bin=0;$bin<=$#bins;$bin++) {
 
   $halfwaybin = $bin * $binsize + $binsize/2.;
 
   print $halfwaybin." ".$bins[$bin]."\n";
 
}
 

	
 
# finis
 

	
src/perl/make_parameter_source.pl
Show inline comments
 
@@ -437,6 +437,8 @@ open parfile,">default.par";
 
for ($i=0;$i<$lines;$i++) {
 
  if ($type[$i] ne "title" && $type[$i] ne "label") {
 
    $value[$i] =~ s/\"//g;
 
    print parfile "  $param[$i] = $value[$i]\n";
 
  }
 
}
 

	
 
# finis
src/perl/make_pardialog_source.pl
Show inline comments
 
@@ -298,6 +298,7 @@ for ($i=0;$i<$lines;$i++) {
 

	
 
print hfile <<END_TRAILER2;
 
};
 
#endif
 
END_TRAILER2
 

	
 
# finis
src/perl/make_xmlwritecode.pl
Show inline comments
 
@@ -218,6 +218,7 @@ print xmlsrc "xmlChar *sourcecode = (xml
 
     }
 
  
 
}
 

	
 
END_MARKER3
 

	
 
# finis
src/pi.h
Show inline comments
 
@@ -25,6 +25,8 @@
 
#ifndef _PI_H_
 
#define _PI_H_
 

	
 
const double Pi=3.1415926535897932384626433832795028841971693993751058209749445923078164062862089986280348253421170676;
 

	
 
#endif
 

	
 
/* finis */
src/qcanvasarrow.h
Show inline comments
 
@@ -27,14 +27,13 @@
 

	
 
#include <QGraphicsScene>
 

	
 
class QGraphicsArrowItem : public QGraphicsLineItem {
 

	
 
 public:
 
  QGraphicsArrowItem(QGraphicsItem *parent, QGraphicsScene *c) : QGraphicsLineItem(parent, c) {
 
  };
 
 QGraphicsArrowItem(QGraphicsItem *parent, QGraphicsScene *c) : QGraphicsLineItem(parent, c) {};
 
    
 
    void paint ( QPainter *p, const QStyleOptionGraphicsItem *option,
 
		 QWidget *widget ) {
 

	
 
      widget = NULL; //use assignment merely to obviate compilation warning
 
      option = NULL;
 
@@ -71,6 +70,8 @@ class QGraphicsArrowItem : public QGraph
 
      // Draw arrow line
 
      p->drawLine( start, end);
 
    }
 
};
 

	
 
#endif
 

	
 
/* finis */
src/random.cpp
Show inline comments
 
@@ -144,6 +144,7 @@ int Randomize(void) {
 
#ifdef QDEBUG
 
  qdebug() << "Random seed is " << seed << endl;
 
#endif
 
  return seed;
 
}
 
 
/* finis */
src/random.h
Show inline comments
 
@@ -55,12 +55,9 @@ class MyUrand {
 
  }
 
  
 
  long operator()(long nn) { return RandomNumber(nn)-1; }
 
  long operator()(void) { return RandomNumber(n); }
 
};
 

	
 

	
 

	
 
#endif
 

	
 

	
 

	
 
#endif
 
/* finis */
src/rseed.cpp
Show inline comments
 
@@ -25,9 +25,10 @@
 

	
 
static const std::string _module_id("$Id$");
 

	
 
int main() {
 

	
 
   long rseed=Randomize();
 
   std::cout << rseed << "\n";
 
  std::cerr << rseed << std::endl;
 
}
 

	
 
}
 
/* finis */
src/rungekutta.cpp
Show inline comments
 
@@ -82,13 +82,12 @@ void RungeKutta::rkqs(double *y, double 
 
  }
 
  else *hnext=5.0*h; //No more than a factor of 5 increase.
 
  *x += (*hdid=h);
 
  for (i=0;i<n;i++) y[i]=ytemp[i];
 
  delete[] ytemp;
 
  delete[] yerr;
 

	
 
}
 

	
 

	
 
void RungeKutta::rkck(double *y, double *dydx, int n, double x, double h, double *yout, double *yerr)
 
/*Given values for n variables y[1..n] and their derivatives dydx[1..n] known at x, use
 
  the fifth-order Cash-Karp Runge-Kutta method to advance the solution over an interval h
 
@@ -200,6 +199,8 @@ void RungeKutta::odeint(double *ystart, 
 
    }
 
    if (fabs(hnext) <= hmin) MyWarning::error("Step size too small in odeint");
 
    h=hnext;
 
  }
 
  MyWarning::error("Too many steps in routine odeint");
 
}
 

	
 
/* finis */
src/rungekutta.h
Show inline comments
 
@@ -56,10 +56,10 @@ class RungeKutta  {
 
  static const double Safety;
 
  static const double PGrow;
 
  static const double Pshrnk;
 
  static const double Errcon;
 
  static const double Maxstp;
 
  static const double Tiny;
 
  
 

	
 
};
 
#endif
 

	
 
/* finis */
src/simitembase.cpp
Show inline comments
 
@@ -22,17 +22,21 @@
 
#include <string>
 
#include <QBrush>
 
#include "simitembase.h"
 

	
 
static const std::string _module_id("$Id$");
 

	
 
SimItemBase::SimItemBase( void *v, QGraphicsScene *canvas ) {
 
SimItemBase::SimItemBase( void *v, QGraphicsScene *canvas )
 
{
 
  canvas = NULL; // use assignment merely to obviate compilation warning
 
    obj=v;
 
};
 

	
 
SimItemBase::~SimItemBase(void) {};
 

	
 

	
 
void SimItemBase::userMove(double dx, double dy) {
 
void SimItemBase::userMove(double dx, double dy)
 
{
 
  dx = dy = 0.0; // use assignment merely to obviate compilation warning
 
};
 

	
 
/* finis */
src/simitembase.h
Show inline comments
 
@@ -62,6 +62,8 @@ public:
 
  // Not proper design... sorry.
 
 
 
  void *obj; 
 
  };
 

	
 
#endif
 

	
 
/* finis */
src/simplugin.cpp
Show inline comments
 
@@ -21,15 +21,17 @@
 

	
 
#include <string>
 
#include "simplugin.h"
 

	
 
static const std::string _module_id("$Id$");
 

	
 
void SimPluginInterface::SetParameters(Parameter *pass_pars) {
 
void SimPluginInterface::SetParameters(Parameter *pass_pars)
 
{
 
	par = pass_pars; 
 
}
 

	
 
void SimPluginInterface::SetCellsStaticDatamembers( CellsStaticDatamembers *cells_static_data_members_of_main)
 
{
 
	CellBase::static_data_members = cells_static_data_members_of_main;
 
}
 

	
 
/* finis */
src/simplugin.h
Show inline comments
 
@@ -68,15 +68,14 @@ public:
 
	// For internal use; not to be redefined by end users
 
	virtual void SetParameters(Parameter *pass_pars);// { par = pass_pars; }
 
	virtual void SetCellsStaticDatamembers (CellsStaticDatamembers *cells_static_data_members_of_main);
 

	
 
protected:
 
	class Parameter *par;
 
	
 
};
 

	
 
Q_DECLARE_INTERFACE(SimPluginInterface, 
 
                    "nl.cwi.VirtualLeaf.SimPluginInterface/1.2") 
 
Q_DECLARE_INTERFACE(SimPluginInterface, "nl.cwi.VirtualLeaf.SimPluginInterface/1.2") 
 
Q_DECLARE_METATYPE(SimPluginInterface *)
 

	
 
#endif
 

	
 
#endif
 
\ No newline at end of file
 
/* finis */
src/sqr.h
Show inline comments
 
@@ -37,17 +37,19 @@ inline double DSQR( double a ) {
 
  
 
  if (a == 0.0) {
 
    return 0.0;
 
  } else {
 
    return a*a;
 
  }
 

	
 
}
 

	
 
inline float SQR( float a ) {
 
   if (a == 0.0) {
 
    return 0.0;
 
  } else {
 
    return a*a;
 
  }
 
}
 

	
 
#endif
 

	
 
/* finis */
src/tiny.h
Show inline comments
 
@@ -25,6 +25,8 @@
 
#ifndef _TINY_H_
 
#define _TINY_H_
 

	
 
#define TINY 1e-5
 

	
 
#endif
 

	
 
/* finis */
src/transporterdialog.cpp
Show inline comments
 
@@ -38,13 +38,14 @@ TransporterDialog::TransporterDialog(Wal
 
  // connect the slots
 
  connect(ok, SIGNAL(clicked()), this, SLOT(setTransporterValues()));
 
  connect(cancel, SIGNAL(clicked()), this, SLOT(close()));
 

	
 
  // compose a label for the dialog box
 
  std::stringstream label_text; 
 
  label_text << "C("<< wall->C1()->Index() << "," << wall->C2()->Index() << "), N(" << wall->N1()->Index() << "," << wall->N2()->Index() << ")";
 
  label_text << "C("<< wall->C1()->Index() << "," << wall->C2()->Index() << "), N(" 
 
	     << wall->N1()->Index() << "," << wall->N2()->Index() << ")";
 
	
 
  // retrieve the current transporters
 
  QVector <double> transporters;  // transporter vector
 
  ntransporters = cell->NChem(); // size of transporter vector
 
  for (int i=0; i<ntransporters; ++i){
 
    transporters << ((wall_num == 1) ? wall->Transporters1(i) : wall->Transporters2(i)); // dependent on the wall number of course.
 
@@ -83,14 +84,14 @@ TransporterDialog::TransporterDialog(Wal
 
  layout->addLayout(b_grid);
 
  setLayout(layout);
 

	
 
  setWindowTitle(tr(label_text.str().c_str()));
 
}
 

	
 
void TransporterDialog::setTransporterValues(){
 

	
 
void TransporterDialog::setTransporterValues()
 
{
 
  // iterate over the editor widgets soliciting their values and setting the wall's transporters accordingly.
 
  for (int i=0; i<ntransporters; ++i){
 
    #ifdef QDEBUG  
 
    qDebug() << "Transporter(" << i << "): " << editors[i]->text().toDouble() << endl;
 
    #endif
 
    if (wall_num == 1)
 
@@ -99,8 +100,9 @@ void TransporterDialog::setTransporterVa
 
      wall->setTransporters2(i, editors[i]->text().toDouble());
 
  }
 
  editors.resize(0);
 
  close();
 
}
 

	
 
// finis
 
/* finis */
 

	
 

	
src/transporterdialog.h
Show inline comments
 
@@ -52,6 +52,8 @@ class TransporterDialog : public QDialog
 
  QLabel *label;
 
  int ntransporters;
 
  QVector <QLineEdit*> editors;
 
};
 

	
 
#endif
 

	
 
/* finis */
src/vector.cpp
Show inline comments
 
@@ -40,24 +40,21 @@ void Vector::operator=(const Vector &sou
 
  // don't assign to self
 
  if (this==&source) return;
 
  
 
  x=source.x;
 
  y=source.y;
 
  z=source.z;
 
  
 
}
 

	
 

	
 

	
 

	
 

	
 
ostream &Vector::print(ostream &os) const {
 
  os << "(" << x << ", " << y << ", " << z << ")";
 
  return os;
 
}
 

	
 

	
 
ostream &operator<<(ostream &os, const Vector &v) {
 
  v.print(os);
 
  return os;
 
}
 

	
 

	
 
@@ -66,108 +63,96 @@ Vector Vector::operator+(const Vector &v
 
  Vector result;
 
  result.x=x+v.x;
 
  result.y=y+v.y;
 
  result.z=z+v.z;
 
  
 
  return result;
 

	
 
}
 

	
 

	
 
Vector& Vector::operator-=(const Vector &v) {
 
  
 
  x-=v.x;
 
  y-=v.y;
 
  z-=v.z;
 
  
 
  return *this;
 

	
 
}
 

	
 
Vector Vector::operator/(const double divisor) const {
 
  
 
  
 
  Vector result;
 
  
 
  result.x=x/divisor;
 
  result.y=y/divisor;
 
  result.z=z/divisor;
 

	
 
  return result;
 
  
 
  
 
}
 

	
 

	
 
Vector Vector::operator*(const double multiplier) const {
 

	
 
  Vector result;
 
  
 
  result.x=x*multiplier;
 
  result.y=y*multiplier;
 
  result.z=z*multiplier;
 

	
 
  return result;
 

	
 
  
 
}
 

	
 

	
 
Vector operator*(const double multiplier, const Vector &v) {
 

	
 
  Vector result;
 
  
 
  result.x=v.x*multiplier;
 
  result.y=v.y*multiplier;
 
  result.z=v.z*multiplier;
 

	
 
  return result;
 
  
 
}
 

	
 
Vector &Vector::operator/=(const double divisor) {
 
  x/=divisor;
 
  y/=divisor;
 
  z/=divisor;
 
  
 
  return *this;
 

	
 
}
 

	
 
Vector &Vector::operator*=(const double multiplier) {
 

	
 
  x*=multiplier;
 
  y*=multiplier;
 
  z*=multiplier;
 

	
 
  return *this;
 

	
 
}
 

	
 
Vector Vector::operator*(const Vector &v) const {
 
  
 
  // cross product ("uitproduct")
 
  Vector result;
 
  
 
  result.x=y*v.z-z*v.y;
 
  result.y=z*v.x-x*v.z;
 
  result.z=x*v.y-y*v.x;
 
  
 
  return result;
 
  
 
  
 
}
 

	
 

	
 
double InnerProduct(const Vector &v1, const Vector &v2) {
 

	
 
  // Inner product ("inproduct")
 
  double result;
 
  result=v1.x*v2.x+v1.y*v2.y+v1.z*v2.z;
 
  return result;
 

	
 
}
 

	
 
double Vector::Angle(const Vector &v) const {
 
  
 
  // angle between this vector and another vector
 
  
 
@@ -184,13 +169,12 @@ double Vector::Angle(const Vector &v) co
 
  if (cos_angle>=1)
 
    return 0.;
 
  
 
  double angle=acos(cos_angle);
 
  
 
  return angle;
 

	
 
}
 

	
 
double Vector::SignedAngle(const Vector &v) const {
 
  
 
  // angle between this vector and another vector
 
  
 
@@ -208,57 +192,52 @@ double Vector::SignedAngle(const Vector 
 
    return 0.;
 
  
 
  double angle=acos(cos_angle);
 
  
 
  double sign = (InnerProduct ( Perp2D(), v ) )>0.?1.:-1.;
 
  return angle * sign;
 

	
 
}
 

	
 

	
 
bool Vector::operator==(const Vector &v) const {
 
   
 
  // "sloppy equal"
 
  if ((fabs(x-v.x)<TINY) && (fabs(y-v.y)<TINY) && (fabs(z-v.z)<TINY))
 
    return true;
 
  else
 
    return false;
 
  
 
}
 

	
 
bool Vector::operator< (const Vector &v) const {
 
  
 
  // Compare x coordinate
 
  if (x<v.x) 
 
    return true;
 
  else 
 
    return false;
 
  
 
}
 

	
 

	
 
double Vector::SqrNorm(void) const {
 
  
 
  // return the square of the norm
 
  // added this function to avoid taking the square root and 
 
  // the square again if this value is needed
 
  return DSQR(x)+DSQR(y)+DSQR(z);
 

	
 
}
 

	
 
void Vector::Normalise(void) {
 
  
 
  double norm;
 
  norm=Norm(); // Absolute value;
 
  
 
  if (norm>0.) { // if the norm is 0, don't normalise 
 
    // (otherwise division by zero occurs)
 
    
 
    (*this)/=norm;
 
  }
 
  
 
}
 

	
 
Vector Vector::Normalised(void) const {
 
  
 
  double norm;
 
  norm=Norm(); // Absolute value;
 
@@ -266,26 +245,24 @@ Vector Vector::Normalised(void) const {
 
  if (norm>0.) { // if the norm is 0, don't normalise 
 
    // (otherwise division by zero occurs)
 
    return (*this)/norm;
 
  } else {
 
    return *this;
 
  }
 
    
 
}
 

	
 
bool Vector::SameDirP(const Vector &v) {
 
  
 
  // return true if the two (parallel) vectors point in the same direction
 
  //  if (x*v.x>=0 && y*v.y>=0 && z*v.z>=0)
 
  double angle=Angle(v);
 
  
 
  if (angle<(Pi/2))
 
    return true;
 
  else
 
    return false;
 
 
 
}
 

	
 
double Vector::Max(void) {
 
  
 
  // Find maximum value of vector
 
  double max;
 
@@ -331,11 +308,11 @@ void main() {
 

	
 
//  cerr << d.Norm() << "\n";
 
  
 
  d.Normalise();
 
  
 
//  cerr << d << "  " << d.Norm() << "\n";
 
  
 
  
 
}
 

	
 
#endif 
 

	
 
/* finis */
src/vector.h
Show inline comments
 
@@ -94,37 +94,34 @@ public:
 
    
 
    result.x=x-v.x;
 
    result.y=y-v.y;
 
    result.z=z-v.z;
 
    
 
    return result;
 
    
 
  }
 
  Vector &operator-=(const Vector &v);
 
  
 
  inline Vector &operator+=(const Vector &v) {
 
  
 
    x+=v.x;
 
    y+=v.y;
 
    z+=v.z;
 
    
 
    return *this;
 
    
 
  }
 
  
 
  Vector operator/(const double divisor) const; // division by a double
 
  Vector operator*(const double multiplier) const; // multiply by a scalar (double)
 
  Vector &operator/=(const double divisor);
 
  Vector &operator*=(const double multiplier);
 
  Vector operator*(const Vector &v) const; // cross product
 
  bool operator==(const Vector &v) const; // comparison
 
  bool operator< (const Vector &v) const; // order x,y,z
 
  inline double Norm(void) const {
 
  
 
    return sqrt(DSQR(x)+DSQR(y)+DSQR(z));
 
    
 
  }
 

	
 
  // Quick and dirty Norm (i.e. Manhattan distance)
 
  // (e.g. useful if we want to see if the vec is (0,0,0);
 
  inline double ManhattanNorm(void) const {
 
    return x+y+z;
 
@@ -138,24 +135,26 @@ public:
 
  bool SameDirP(const Vector &v);
 
  double Max(void); // Find max, resp. min value of vector
 
  double Min(void);
 
  Vector Perp2D(void) const {
 
    return Vector(y,-x,0);
 
  }
 

	
 
  // data members
 
  double x,y,z;
 

	
 
  void Dump(ostream &os) const { 
 
    os << x << " " << y << " " << z << " ";
 
  }
 
  void ReadDump(istream &is) {
 
    is >> x >> y >> z;
 
  }
 
private:
 

	
 
};
 

	
 
ostream &operator<<(ostream &os, const Vector &v);
 
Vector operator*(const double multiplier, const Vector &v);
 
double InnerProduct(const Vector &v1, const Vector &v2);
 

	
 
#endif
 

	
 
/* finis */
src/vleafmodel.h
Show inline comments
 
@@ -34,6 +34,8 @@
 
#include "wallbase.h"
 
#include "cellbase.h"
 
#include "mymodel.h"
 
#include "flux_function.h"
 

	
 
#endif
 

	
 
/* finis */
src/wall.cpp
Show inline comments
 
@@ -61,13 +61,12 @@ bool Wall::CorrectWall( void ) {
 
		
 
		// find boundary polygon in the wall owners list
 
		list<CellBase *>::iterator bpit = find_if (
 
												   wall_owners.begin(), wall_owners.end(), 
 
												   mem_fun( &CellBase::BoundaryPolP )
 
												   );
 
		
 
		if (bpit!=wall_owners.end()) {
 
			
 
			// add a Wall with the boundary_polygon to each cell
 
			Wall *bp_wall1 = new Wall( n2, n1, c1, (*bpit) );
 
			bp_wall1->CopyWallContents(*this);
 
			((Cell *)c1)->AddWall( bp_wall1);
 
@@ -86,26 +85,27 @@ bool Wall::CorrectWall( void ) {
 
		  qDebug() << "Wall::CorrectWall says: Wall has three owners, but none of them is the BoundaryPolygon. I have no clue what to do with this case... Sorry!" << endl;
 
		  qDebug() << "Wall: " << *this << endl;
 
		  qDebug() << "Owners are: ";
 
		  transform(wall_owners.begin(), wall_owners.end(), ostream_iterator<int>(qDebug(), "  "), mem_fun (&CellBase::Index) );
 
		  qDebug() << endl;
 
		  qDebug() << "Owners node " << n1->Index() << ": ";
 

	
 
		  for (list<Neighbor>::iterator i = n1->owners.begin(); i!=n1->owners.end(); i++) {
 
		    qDebug() << i->getCell()->Index() << " ";
 
		  }
 

	
 
		  qDebug() << endl;
 
		  qDebug() << "Owners node " << n2->Index() << ": ";
 
			
 
		  for (list<Neighbor>::iterator i = n2->owners.begin(); i!=n2->owners.end(); i++) {
 
		    qDebug() << i->getCell()->Index() << " ";
 
		  }
 
		  qDebug() << endl;
 
                  #endif
 
		  std::exit(1);
 
		}
 
		
 
	}
 
	
 
	#ifdef QDEBUG
 
	if (wall_owners.size() == 1) {
 
	  qDebug() << "Corner point. Special case." << endl;
 
	}
 
@@ -148,33 +148,26 @@ bool Wall::CorrectWall( void ) {
 
					#endif
 
					return false;
 
				}
 
			}
 
		}
 
	}
 
	
 
	return true;
 
	
 
	
 
	
 
	
 
}
 

	
 
void Wall::Draw(QGraphicsScene *c) {
 
	
 
	WallItem *wi1 = new WallItem(this, 1, c);
 
	WallItem *wi2 = new WallItem(this, 2, c);
 
	wi1->show();
 
	wi2->show();
 
	
 
}
 

	
 
void Wall::DrawApoplast(QGraphicsScene *c) {
 
	ApoplastItem *apo = new ApoplastItem(this, c);
 
	apo->show();
 
	
 
}
 

	
 
void Wall::ShowStructure(QGraphicsScene *c) {
 
	
 
	Vector offset = Cell::Offset();
 
	double factor = Cell::Factor();
 
@@ -205,13 +198,12 @@ void Wall::ShowStructure(QGraphicsScene 
 
	text1->setFont( QFont( "Helvetica", par.nodenumsize, QFont::Bold) );
 
	text2->setFont( QFont( "Helvetica", par.nodenumsize, QFont::Bold) );
 
    
 
	text1->setPen ( QColor(par.textcolor) );
 
	text2->setPen ( text1->pen() );
 
	text1->show(); text2->show();
 
	
 
}
 
string Wall::WallTypetoStr(const WallType &wt) const {
 
	
 
	if (wt == Normal) {
 
		return string("normal");
 
	}
 
@@ -224,8 +216,7 @@ string Wall::WallTypetoStr(const WallTyp
 
		return string("aux_sink");
 
	}
 
	
 
	return string("");
 
}
 

	
 

	
 

	
 
/* finis */
src/wall.h
Show inline comments
 
@@ -51,13 +51,11 @@ public:
 
	 Used for debugging purposes.
 
	 */
 
	void ShowStructure(QGraphicsScene *c);
 

	
 
private:
 
	string WallTypetoStr(const WallType &wt) const;
 
	    
 
	
 
	
 
	
 
};
 

	
 
#endif
 

	
 
/* finis */
src/wallbase.cpp
Show inline comments
 
@@ -50,13 +50,14 @@ ostream &WallBase::print(ostream &os) co
 
ostream &operator<<(ostream &os, const WallBase &w) { 
 
	w.print(os); 
 
	return os;
 
}
 

	
 

	
 
WallBase::WallBase(Node *sn1, Node *sn2, CellBase *sc1, CellBase *sc2) {
 
WallBase::WallBase(Node *sn1, Node *sn2, CellBase *sc1, CellBase *sc2)
 
{
 
	
 
        #ifdef QDEBUG
 
	if (sc1==sc2) { 
 
	  qDebug() << "Attempting to build a wall between identical cells: " << sc1->Index() << endl; 
 
	}
 
	#endif
 
@@ -82,16 +83,16 @@ WallBase::WallBase(Node *sn1, Node *sn2,
 
	
 
	// to visualize flux through WallBase
 
	viz_flux=0;
 
	dead = false;
 
	wall_type = Normal;
 
	wall_index = nwalls++;
 
	
 
}
 

	
 
void WallBase::CopyWallContents(const WallBase &src) {
 
void WallBase::CopyWallContents(const WallBase &src)
 
{
 
	
 
	for (int i=0; i<CellBase::NChem(); i++) {
 
		if (transporters1) {
 
			transporters1[i]=src.transporters1[i];
 
		}
 
		if (transporters2) {
 
@@ -109,13 +110,14 @@ void WallBase::CopyWallContents(const Wa
 
		}
 
	}
 
	dead = src.dead;
 
	wall_type = src.wall_type;
 
}
 

	
 
void WallBase::SwapWallContents(WallBase *src) {
 
void WallBase::SwapWallContents(WallBase *src)
 
{
 
	
 
	for (int i=0; i<CellBase::NChem(); i++) {
 
		if (transporters1) {
 
			double tmp;
 
			
 
			tmp=src->transporters1[i];
 
@@ -155,28 +157,24 @@ void WallBase::SwapWallContents(WallBase
 
	dead = tmp_bool;
 
	
 
	WallType tmp_wall_type;
 
	tmp_wall_type = src->wall_type;
 
	src->wall_type = wall_type;
 
	wall_type = tmp_wall_type;
 
	
 
}
 

	
 
bool WallBase::SAM_P(void) { 
 
	
 
bool WallBase::SAM_P(void)
 
{ 
 
	return N1()->sam || N2()->sam; 
 
	
 
}  
 

	
 
#include <fstream>
 

	
 
void WallBase::SetLength(void) {
 
void WallBase::SetLength(void)
 
{
 
	
 
	//static bool show_nodes = true;
 
	
 
	//double old_length = length;
 
	// Step 1: find the path of nodes leading along the WallBase.
 
	// A WallBase often represents a curved cell wall: we want the total
 
	// length _along_ the wall here...
 
	
 
	// Locate first and second nodes of the edge in Cell's list of nodes
 
	list<Node *>::const_iterator first_node_edge = find(c1->nodes.begin(), c1->nodes.end(), n1);
 
@@ -203,74 +201,74 @@ void WallBase::SetLength(void) {
 
		--prev_n;
 
		
 
		//cerr << "Node: " << (Vector)(**n) << endl;
 
		
 
		// Note that Node derives from a Vector, so we can do vector calculus as defined in vector.h 
 
		
 
		
 
		deb_str << "[ " << (*prev_n)->index << " to " << (*n)->index << "]";
 
		
 
		length += (*(*prev_n) - *(*n)).Norm(); 
 
		
 
	}
 
}
 

	
 
void WallBase::CorrectTransporters(double orig_length) {
 
void WallBase::CorrectTransporters(double orig_length)
 
{
 
	
 
	double length_factor = length / orig_length;
 

	
 
	for (int ch=0;ch<CellBase::NChem();ch++) {
 
		transporters1[ch] *= length_factor;
 
		transporters2[ch] *= length_factor;
 
		new_transporters1[ch] *= length_factor;
 
		new_transporters2[ch] *= length_factor;
 
	}
 
	
 
}
 

	
 

	
 
Vector WallBase::VizFlux(void) {
 
Vector WallBase::VizFlux(void)
 
{
 
	return viz_flux * ( (*n2) - (*n1) ).Normalised().Perp2D();    
 
}
 

	
 

	
 
void WallBase::SetTransToNewTrans( void ){ 
 
	for (int i=0;i<CellBase::NChem();i++) { 
 
		transporters1[i] = new_transporters1[i]; 
 
		transporters2[i] = new_transporters2[i]; 
 
	} 
 
}
 

	
 

	
 
Vector WallBase::getWallVector(CellBase *c) {
 
Vector WallBase::getWallVector(CellBase *c)
 
{
 
	if ( c == c1 ) {
 
		return ( Vector(*n2) - Vector(*n1) );
 
	} else {
 
		return ( Vector(*n1) - Vector(*n2) );
 
	}
 
	
 
}
 
Vector WallBase::getInfluxVector(CellBase *c) {
 
Vector WallBase::getInfluxVector(CellBase *c)
 
{
 
	if ( c == c1 ) {
 
		return ( Vector(*n2) - Vector(*n1) ).Normalised().Perp2D();
 
	} else {
 
		return ( Vector(*n1) - Vector(*n2) ).Normalised().Perp2D();
 
	}
 
}
 

	
 
//! \brief Test if this wall intersects with division plane p1 -> p2 
 
bool WallBase::IntersectsWithDivisionPlaneP(const Vector &p1, const Vector &p2) {
 
bool WallBase::IntersectsWithDivisionPlaneP(const Vector &p1, const Vector &p2)
 
{
 
	
 
	// Algorithm of http://local.wasp.uwa.edu.au/~pbourke/geometry/lineline2d/
 
	double x1 = n1->x, y1 = n1->y;
 
	double x2 = n2->x, y2 = n2->y;
 
	double x3 = p1.x, y3 = p1.y;
 
	double x4 = p2.x, y4 = p2.y;
 
	
 
	double ua = ( (x4 - x3) * (y1-y3) - (y4 - y3)*(x1-x3) ) / ( (y4 -y3) * (x2 -x1) - (x4-x3)*(y2-y1));
 
	
 
	// If ua is between 0 and 1, line p1 intersects the line segment
 
	if ( ua >=0. && ua <=1.) return true;
 
	else return false;
 
	
 
}
 

	
 
/* finis */
src/wallbase.h
Show inline comments
 
@@ -25,18 +25,14 @@
 

	
 
#ifndef _WALLBASE_H_
 
#define _WALLBASE_H_
 

	
 
#include <list>
 
#include <iostream>
 

	
 

	
 

	
 
#include "vector.h"
 

	
 

	
 
class Node;
 
class CellBase;
 

	
 
using namespace std;
 

	
 
// warning, touches original sequence
 
@@ -153,13 +149,16 @@ public:
 
			else
 
				if (wall_type == AuxSink) {
 
					wall_type = Normal;
 
				}
 
	}
 
	// checked version. Use during debugging stage.
 
	inline double getTransporter(CellBase *c, int ch) const { return c1 == c ? transporters1[ch] : ( c2 == c ? transporters2[ch] : throw "WallBase::getTransporter called with wrong cell") ; } 
 
  inline double getTransporter(CellBase *c, int ch) const
 
  { 
 
    return c1 == c ? transporters1[ch] : ( c2 == c ? transporters2[ch] : throw "WallBase::getTransporter called with wrong cell") ; } 
 

	
 
	inline void setTransporter(CellBase *c, int ch, double val) { 
 
		if ( c1 == c ) {
 
			transporters1[ch]=val;
 
		} else 
 
			
 
			if (c2 == c ) {
 
@@ -191,11 +190,12 @@ public:
 
	 */
 
	Vector VizFlux(void);
 
	bool IntersectsWithDivisionPlaneP(const Vector &p1, const Vector &p2);
 
	void SetTransToNewTrans( void );
 
	
 
private:
 
	
 
};
 

	
 
ostream &operator<<(ostream &os, const WallBase &w);
 
#endif
 

	
 
/* finis */
src/wallitem.cpp
Show inline comments
 
@@ -125,6 +125,8 @@ void WallItem::OnClick(QMouseEvent *e) {
 
			}
 
			setColor();
 
			update(boundingRect());
 
		} 
 
	}
 
}
 

	
 
/* finis */
src/wallitem.h
Show inline comments
 
@@ -45,6 +45,8 @@ public:
 
  void setColor(void);
 
 private:
 
  int wn;
 
};
 

	
 
#endif
 

	
 
/* finis */
src/warning.cpp
Show inline comments
 
@@ -78,13 +78,12 @@ void MyWarning::error(const char *fmt, .
 
	QMessageBox::critical( 0 , "Fatal error", qmess, QMessageBox::Abort, QMessageBox::NoButton, QMessageBox::NoButton );
 
    fprintf(stderr, "Error: %s\n",qmess.toStdString().c_str());
 
    QCoreApplication::exit(1);
 
    std::exit(1);
 
  }
 
  delete[] message;
 
  
 
}
 
#endif
 

	
 

	
 
/*
 
 * EPRINTF: scream, but don't die yet.
 
@@ -128,13 +127,12 @@ void MyWarning::warning(const char *fmt,
 
    fprintf(stderr, "Warning: %s\n",qmess.toStdString().c_str());
 
  } else { // issue a dialog box
 
	  UniqueMessageBox msgBox( QString("Warning"), qmess );
 
	  msgBox.exec();
 
  }
 
  delete[] message;
 

	
 
}
 
#endif
 

	
 
/*! Issues a warning only once,
 
  by comparing it to a list of warnings issued previously. */
 
void MyWarning::unique_warning(const char *fmt, ...) {
 
@@ -174,6 +172,8 @@ main(int argc, char * argv[])
 
{
 
    eprintf("warning: foo=%f\tbar=%d\tfum=\"%s\"\n", 3.1415, 32768, "waldo");
 
    error("error: foo=%f\tbar=%d\tfum=\"%s\"\n", 3.1415, 32768, "waldo");
 
}
 

	
 
#endif
 

	
 
/* finis */
src/warning.h
Show inline comments
 
@@ -42,6 +42,8 @@ extern "C" {
 
  
 
#ifdef __cplusplus
 
}
 
#endif
 

	
 
#endif
 

	
 
/* finis */
src/xmlwrite.cpp
Show inline comments
 
@@ -53,20 +53,18 @@ void ThrowStringStream(stringstream &s) 
 
// Add this cell to the XML tree
 
void Cell::XMLAdd(xmlNodePtr cells_node) const {
 

	
 
  // Save the cell to a stream so we can reconstruct its state later
 
  xmlNodePtr xmlcell = xmlNewChild(cells_node, NULL, BAD_CAST "cell",NULL);
 
  XMLAddCore(xmlcell);
 

	
 
}
 

	
 
void BoundaryPolygon::XMLAdd(xmlNodePtr parent_node) const {
 
  
 
  xmlNodePtr xmlcell = xmlNewChild(parent_node, NULL, BAD_CAST "boundary_polygon",NULL);
 
  XMLAddCore(xmlcell);
 

	
 
}
 

	
 
void NodeSet::XMLAdd(xmlNode *root) const {
 
  
 
  xmlNode *xmlnodeset = xmlNewChild(root, NULL, BAD_CAST "nodeset", NULL);
 
  
 
@@ -75,13 +73,12 @@ void NodeSet::XMLAdd(xmlNode *root) cons
 
      ostringstream text;
 
      xmlNodePtr node_xml = xmlNewChild(xmlnodeset, NULL, BAD_CAST "node", NULL);
 
      text << (*i)->Index();
 
      xmlNewProp(node_xml, BAD_CAST "n", BAD_CAST text.str().c_str());
 
    }
 
  }
 
  
 
}
 

	
 

	
 

	
 

	
 
void Cell::XMLAddCore(xmlNodePtr xmlcell) const {
 
@@ -205,29 +202,23 @@ void Cell::XMLAddCore(xmlNodePtr xmlcell
 
  for (int i=0;i<NChem();i++) {
 
    xmlNodePtr chem_val_xml = xmlNewChild(chem_xml, NULL, BAD_CAST "val", NULL);
 
    { 
 
      ostringstream text;
 
      text << chem[i];
 
      xmlNewProp(chem_val_xml, BAD_CAST "v", BAD_CAST text.str().c_str());
 

	
 
    }
 
  }
 
  
 
  
 

	
 
}
 

	
 

	
 

	
 
void Node::XMLAdd(xmlNodePtr nodes_node) const { 
 
  
 
  // Save the node to a stream so we can reconstruct its state later
 
  xmlNodePtr xmlnode = xmlNewChild(nodes_node, NULL, BAD_CAST "node",NULL);
 

	
 
  
 
  
 
  {
 
    ostringstream text;
 
    text << x;
 
    xmlNewProp(xmlnode, BAD_CAST "x", BAD_CAST text.str().c_str());
 
  }
 
  
 
@@ -257,14 +248,12 @@ void Node::XMLAdd(xmlNodePtr nodes_node)
 

	
 
  if (node_set) {
 
    ostringstream text;
 
    text << XMLIO::list_index(m->node_sets.begin(),m->node_sets.end(),node_set);
 
    xmlNewProp(xmlnode, BAD_CAST "nodeset", BAD_CAST text.str().c_str());    
 
  }
 
  
 

	
 
}
 

	
 
void Neighbor::XMLAdd(xmlNodePtr neighbors_node) const {
 
  
 
  xmlNodePtr xmlnode = xmlNewChild(neighbors_node, NULL, BAD_CAST "neighbor",NULL);
 
  {
 
@@ -281,13 +270,12 @@ void Neighbor::XMLAdd(xmlNodePtr neighbo
 

	
 
  {
 
    ostringstream text;
 
    text << nb2->Index();
 
    xmlNewProp(xmlnode, BAD_CAST "nb2", BAD_CAST text.str().c_str());
 
  }
 

	
 
}
 

	
 

	
 
// from example code on www.libxml.org:
 
xmlXPathObjectPtr
 
getnodeset (xmlDocPtr doc, xmlChar *xpath){
 
@@ -313,13 +301,14 @@ getnodeset (xmlDocPtr doc, xmlChar *xpat
 
  }
 
  return result;
 
}
 

	
 

	
 

	
 
int Cell::XMLRead(xmlNode *cur)  {
 
int Cell::XMLRead(xmlNode *cur)
 
{
 
  
 
  xmlNode *n = cur->xmlChildrenNode;
 
  QLocale standardlocale(QLocale::C);
 
  bool ok;
 

	
 
  vector<int> tmp_nodes;
 
@@ -551,16 +540,16 @@ int Cell::XMLRead(xmlNode *cur)  {
 
		}
 
	}
 
  
 
  // Recalculate moments and area
 
  SetIntegrals();
 
  return 0;
 

	
 
}
 
  
 
void NodeSet::XMLRead(xmlNode *root, Mesh *m) {
 
void NodeSet::XMLRead(xmlNode *root, Mesh *m)
 
{
 
  
 
  xmlNode *n = root->xmlChildrenNode;
 
  
 
  vector<int> tmp_nodes;
 
  while(n!=NULL) {
 
    if ((!xmlStrcmp(n->name, (const xmlChar *)"node"))) {
 
@@ -576,13 +565,12 @@ void NodeSet::XMLRead(xmlNode *root, Mes
 
  }
 
  
 
  int nnodes = tmp_nodes.size();
 
  for (int i=0;i<nnodes;i++) {
 
    AddNode( &(m->getNode(tmp_nodes[i])) );
 
  }
 
  
 
}
 

	
 

	
 

	
 

	
 
void Wall::XMLAdd(xmlNode *parent) const { 
 
@@ -660,13 +648,12 @@ void Wall::XMLAdd(xmlNode *parent) const
 
    for (int i=0;i<Cell::NChem();i++) {
 
      xmlNodePtr tr2_val_xml = xmlNewChild(tr2_xml, NULL, BAD_CAST "val", NULL);
 
      { 
 
	ostringstream text;
 
	text << transporters2[i];
 
	xmlNewProp(tr2_val_xml, BAD_CAST "v", BAD_CAST text.str().c_str());
 
      
 
      }
 
    }
 
  }
 
   
 
  if (apoplast) {
 
    xmlNodePtr apo_xml = xmlNewChild(xmlwall, NULL, BAD_CAST "apoplast", NULL); 
 
@@ -674,20 +661,20 @@ void Wall::XMLAdd(xmlNode *parent) const
 
    for (int i=0;i<Cell::NChem();i++) {
 
      xmlNodePtr apo_val_xml = xmlNewChild(apo_xml, NULL, BAD_CAST "val", NULL);
 
      { 
 
	ostringstream text;
 
	text << transporters2[i];
 
	xmlNewProp(apo_val_xml, BAD_CAST "v", BAD_CAST text.str().c_str());
 
	
 
      }
 
    }
 
  } 
 
}
 

	
 

	
 
vector<double> XMLIO::XMLReadValArray(xmlNode *cur) {
 
vector<double> XMLIO::XMLReadValArray(xmlNode *cur)
 
{
 
  
 
  vector<double> result;
 
  QLocale standardlocale(QLocale::C);
 
  bool ok;
 

	
 
  xmlNode *valarray_node = cur->xmlChildrenNode;
 
@@ -760,14 +747,12 @@ void Mesh::XMLSave(const char *docname, 
 
	
 
	{ ostringstream text;
 
		text << Node::target_length;
 
		xmlNewProp(xmlnodes, BAD_CAST "target_length", BAD_CAST text.str().c_str());
 
	}
 
	
 
	
 
	
 
	for (vector<Node *>::const_iterator i=nodes.begin();
 
		 i!=nodes.end();
 
		 i++) {
 
		(*i)->XMLAdd(xmlnodes) ;
 
	}
 
	
 
@@ -839,28 +824,20 @@ void Mesh::XMLSave(const char *docname, 
 
	{ 
 
		ostringstream text;
 
		text << node_sets.size();
 
		xmlNewProp(xmlnodesets, BAD_CAST "n", BAD_CAST text.str().c_str());
 
	}
 
	
 
	
 
	for_each( node_sets.begin(), node_sets.end(), 
 
			 bind2nd ( 
 
					  mem_fun( &NodeSet::XMLAdd ),
 
					  xmlnodesets
 
					  ) );
 
	
 
  for_each( node_sets.begin(), node_sets.end(), bind2nd ( mem_fun( &NodeSet::XMLAdd ), xmlnodesets ) );
 
	
 
	// Add option tree for interactive application
 
	if (options) {
 
		xmlAddChild(root_node, options);
 
	}
 
	
 
	
 
	
 
	
 
	/* 
 
	 * Dumping document to stdio or file
 
	 */
 
	xmlSetDocCompressMode(doc,9);
 
	xmlSaveFormatFileEnc(docname, doc, "UTF-8", 1);
 
	
 
@@ -877,13 +854,14 @@ void Mesh::XMLSave(const char *docname, 
 
	 * this is to debug memory for regression tests
 
	 */
 
}
 

	
 

	
 

	
 
void Mesh::XMLReadSimtime(const xmlNode *a_node) {
 
void Mesh::XMLReadSimtime(const xmlNode *a_node)
 
{
 
	
 
  xmlNode *root_node;
 
  root_node = (xmlNode *)a_node;
 
  xmlChar *strsimtime = xmlGetProp(root_node, BAD_CAST "simtime");
 
  
 
  
 
@@ -903,13 +881,14 @@ void Mesh::XMLReadSimtime(const xmlNode 
 
    qDebug() << "No simtime found in file." << endl;
 
#endif
 
		time =0;
 
	}	
 
}
 

	
 
void Mesh::XMLReadPars(const xmlNode * a_node) {
 
void Mesh::XMLReadPars(const xmlNode * a_node)
 
{
 
	xmlNode *root_node;
 
	root_node = (xmlNode *)a_node;
 
	par.XMLRead(root_node);
 
	Seed(par.rseed);
 
	MakeDir(par.datadir);
 
}
 
@@ -976,13 +955,12 @@ void Mesh::XMLReadGeometry(const xmlNode
 
			xmlChar *baseareac = xmlGetProp(cur, BAD_CAST "base_area");
 

	
 
			Cell::BaseArea() = standardlocale.toDouble((const char *)baseareac, &ok);
 
			if (!ok) MyWarning::error("Could not convert \"%s\" to double in XMLRead.",(const char *)baseareac);
 
			xmlFree(baseareac);
 
			
 
			
 
			XMLReadCells(cur);
 
		}
 
		cur=cur->next;
 
	}
 
    
 
	// allocate Walls (we need to have read the cells before constructing walls)
 
@@ -1018,25 +996,24 @@ void Mesh::XMLReadGeometry(const xmlNode
 
	
 
	shuffled_cells.clear();
 
	shuffled_cells = cells;
 
	
 
	MyUrand r(shuffled_cells.size());
 
	random_shuffle(shuffled_cells.begin(),shuffled_cells.end(),r);
 
    
 
}
 

	
 
void Mesh::XMLParseTree(const xmlNode *root_node) {
 
	
 
void Mesh::XMLParseTree(const xmlNode *root_node)
 
{
 
	XMLReadSimtime(root_node);
 
	XMLReadPars(root_node);
 
	XMLReadGeometry(root_node);
 
	
 
}
 

	
 

	
 
void Mesh::XMLReadNodes(xmlNode *root) {
 
void Mesh::XMLReadNodes(xmlNode *root)
 
{
 
	
 
  QLocale standardlocale(QLocale::C);
 
  bool ok;
 

	
 
  xmlNode *cur = root;
 
  cur = cur->xmlChildrenNode;
 
@@ -1051,13 +1028,12 @@ void Mesh::XMLReadNodes(xmlNode *root) {
 
  Node::nnodes=0;
 
	
 
  xmlChar *tlc = xmlGetProp(root, BAD_CAST "target_length");
 
	
 
  if (tlc != 0) {
 

	
 
	  
 
    Node::target_length = standardlocale.toDouble((const char *)tlc, &ok);
 
    if (!ok) MyWarning::error("Could not convert \"%s\" to double in XMLRead.",(const char *)tlc);
 
		
 
    xmlFree(tlc);
 
  } else {
 
    // note that libxml2 also defines a token "warning"
 
@@ -1112,27 +1088,25 @@ void Mesh::XMLReadNodes(xmlNode *root) {
 
			
 
      xmlFree(xc);
 
      xmlFree(yc);
 
      xmlFree(boundaryc);
 
      xmlFree(fixedc);
 
      xmlFree(samc);
 
			
 
			
 
    }
 
    cur=cur->next;
 
  }
 
	
 
  shuffled_nodes.clear();
 
  shuffled_nodes = nodes;
 
	
 
  MyUrand r(shuffled_nodes.size());
 
  random_shuffle(shuffled_nodes.begin(),shuffled_nodes.end(),r);
 
	
 
}
 

	
 
void Mesh::XMLReadWalls(xmlNode *root, vector<Wall *> *tmp_walls) {
 
void Mesh::XMLReadWalls(xmlNode *root, vector<Wall *> *tmp_walls)
 
{
 
	
 
  xmlNode *cur = root;
 
  cur = cur->xmlChildrenNode;
 
	
 
  for (list<Wall *>::iterator i=walls.begin();
 
       i!=walls.end();
 
@@ -1237,13 +1211,12 @@ void Mesh::XMLReadWalls(xmlNode *root, v
 
	  xmlChar *v_str = xmlGetProp(cur, BAD_CAST "delete");
 
					
 
	  if (v_str != 0) {
 
	    dead = strtobool( (char *)v_str);
 
	    xmlFree(v_str);
 
	  }
 
					
 
	}
 
				
 
	Cell *cc1 = c1 != -1 ? cells[c1] : boundary_polygon;
 
	Cell *cc2 = c2 != -1 ? cells[c2] : boundary_polygon;
 
				
 
	Wall *w = new Wall( nodes[n1], nodes[n2], cc1, cc2);
 
@@ -1284,29 +1257,26 @@ void Mesh::XMLReadWalls(xmlNode *root, v
 
		w->transporters1[nv++]=v;
 
		xmlFree(nc);
 
								
 
	      }
 
	      v_node = v_node->next; 
 
	    }
 
						
 
	  }
 
					
 
					
 
	  if ((!xmlStrcmp(w_node->name, (const xmlChar *)"transporters2"))) {
 
						
 
	    xmlNode *v_node = w_node->xmlChildrenNode;
 
	    int nv=0;
 
	    while (v_node!=NULL) {
 
	      if ((!xmlStrcmp(v_node->name, (const xmlChar *)"val"))) {
 
		if (nv>=Cell::NChem()) {
 
		  {
 
		    stringstream text;
 
		    text << "Exception in Mesh::XMLRead: Too many transporter values given for wall(s). Ignoring remaining values.";
 
		    unique_warning(text.str().c_str());
 
		    break;
 

	
 
		  }
 
		}
 
								
 
		xmlChar *nc = xmlGetProp(v_node, (const xmlChar *) "v");
 
								
 
		if (nc==0) {
 
@@ -1318,13 +1288,12 @@ void Mesh::XMLReadWalls(xmlNode *root, v
 

	
 
		w->transporters2[nv++]=v;
 
		xmlFree(nc);
 
	      }
 
	      v_node = v_node->next; 
 
	    }
 
						
 
	  } 
 
					
 
	  if ((!xmlStrcmp(w_node->name, (const xmlChar *)"apoplast"))) {
 
						
 
	    xmlNode *v_node = w_node->xmlChildrenNode;
 
	    int nv=0;
 
@@ -1361,13 +1330,14 @@ void Mesh::XMLReadWalls(xmlNode *root, v
 
      cur = cur->next;
 
    }
 
  }
 
}
 

	
 

	
 
void Mesh::XMLReadWallsToCells(xmlNode *root, vector<Wall *> *tmp_walls) {
 
void Mesh::XMLReadWallsToCells(xmlNode *root, vector<Wall *> *tmp_walls)
 
{
 
	
 
	// Add the walls to the cells (do this after reading the walls; read walls after reading cells...)
 
	// 1. Read Nodes
 
	// 2. Read Cells
 
	// 3. Read Walls
 
	// 4. Read Walls into Cells
 
@@ -1406,25 +1376,22 @@ void Mesh::XMLReadWallsToCells(xmlNode *
 
			} else {
 
				
 
				int nwalls = tmp_walls_ind.size();
 
				for (int i=0;i<nwalls;i++) {
 
					cells[ci]->walls.push_back((*tmp_walls)[tmp_walls_ind[i]]);	
 
				}
 
				
 
				ci++;
 
			}
 
			
 
		} 
 
		cur=cur->next;
 
	}
 
	
 
	
 
}
 

	
 

	
 
void Mesh::XMLReadNodeSetsToNodes(xmlNode *root) {
 
void Mesh::XMLReadNodeSetsToNodes(xmlNode *root)
 
{
 
	
 
	xmlNode *cur = root->xmlChildrenNode;
 
	int ci=0; // cell index
 
	
 
	while (cur!=NULL) {
 
		
 
@@ -1445,24 +1412,21 @@ void Mesh::XMLReadNodeSetsToNodes(xmlNod
 
				} else {
 
					nodes[ci]->node_set = 0;
 
				}
 
				
 
				n = n->next;
 
			}
 
			
 
			ci++;
 
			
 
		} 
 
		cur=cur->next;
 
	}
 
	
 
	
 
}
 

	
 

	
 
void Mesh::XMLReadNodeSets(xmlNode *root) {
 
void Mesh::XMLReadNodeSets(xmlNode *root)
 
{
 
	
 
	for (vector<NodeSet *>::iterator i=node_sets.begin();
 
		 i!=node_sets.end();
 
		 i++) {
 
		delete *i;
 
	}
 
@@ -1484,16 +1448,16 @@ void Mesh::XMLReadNodeSets(xmlNode *root
 
			cur = cur->next;
 
			continue;
 
		}
 
		new_nodeset->XMLRead(cur, this);
 
		cur=cur->next;
 
	}
 
	
 
}
 

	
 
void Mesh::XMLReadCells(xmlNode *root) {
 
void Mesh::XMLReadCells(xmlNode *root)
 
{
 
	
 
	for (vector<Cell *>::iterator i=cells.begin();
 
		 i!=cells.end();
 
		 i++) {
 
		delete *i;
 
	}
 
@@ -1527,16 +1491,16 @@ void Mesh::XMLReadCells(xmlNode *root) {
 
			continue;
 
		}
 
		
 
		new_cell->XMLRead(cur);
 
		cur=cur->next;
 
	}
 
	
 
}
 

	
 
void Mesh::XMLRead(const char *docname, xmlNode **settings, bool geometry, bool pars, bool simtime) {
 
void Mesh::XMLRead(const char *docname, xmlNode **settings, bool geometry, bool pars, bool simtime)
 
{
 
	
 
	xmlDocPtr doc = xmlParseFile(docname);
 
	if (doc == NULL ) {
 
		throw("Document not parsed successfully.");
 
		return;
 
	}
 
@@ -1581,17 +1545,17 @@ void Mesh::XMLRead(const char *docname, 
 
	 *have been allocated by the parser.
 
	 */
 
	xmlCleanupParser();
 
	
 
	// We're doing this so we can manually delete walls with by adding the 'delete="true"' property
 
	CleanUpCellNodeLists();
 
	
 
}
 

	
 

	
 
void Parameter::XMLRead(xmlNode *root) {
 
void Parameter::XMLRead(xmlNode *root)
 
{
 
	
 
	xmlNode *cur = root->xmlChildrenNode;
 
	while (cur!=NULL) {
 
		if ((!xmlStrcmp(cur->name, (const xmlChar *)"parameter"))){
 
			xmlNode *par_node = cur->xmlChildrenNode;
 
			while (par_node!=NULL) {
 
@@ -1614,13 +1578,12 @@ void Parameter::XMLRead(xmlNode *root) {
 
							AssignValArrayToPar((const char*)namec, valarray);
 
						}
 
					}
 
				}	  
 
				par_node = par_node->next;
 
			}
 
			
 
		}
 
		cur=cur->next;
 
	}
 
    
 
}
 

	
 
/* finis */
src/xmlwrite.h
Show inline comments
 
@@ -42,13 +42,12 @@ namespace XMLIO {
 
	return n;
 
      }
 
      n++;
 
    }
 
    return -1;
 
  }
 
 	
 
}
 

	
 

	
 
static const char * bool_names[2] = {"true","false"};
 

	
 
inline const char *bool_name(bool q) { return q ? bool_names[0] : bool_names[1]; }
 
@@ -63,6 +62,8 @@ inline bool strtobool(const char *str) {
 
      throw("Error in xmlwrite.cpp : strtobool(const char *str). Parameter passed other than \"true\" or \"false\".");
 
    }
 
  }
 
}
 

	
 
#endif
 

	
 
/* finis */
0 comments (0 inline, 0 general)