cell_system::CellSystem< Complex, MyModel > Class Template Reference

Full cell-system model. More...

#include <algorithms/cellsystem.h>

Inheritance diagram for cell_system::CellSystem< Complex, MyModel >:
Inheritance graph
[legend]

List of all members.

Public Types

typedef std::map< label_t,
DivisionParams
division_rules_t
 Type of rules of type A --> B |(a,r) C.
typedef std::map< label_t,
label_t
label_change_rules_t
 Type of rules of type A --> B.

Public Member Functions

double area (const cell &c) const
 CellSystem (QObject *parent)
 Constructor .
 IMPORT_COMPLEX_EDGES (Complex)
 IMPORT_COMPLEX_GRAPHS (Complex)
 IMPORT_COMPLEX_VERTICES (Complex)
label_t label (QString name)
 Returns the label number of a symbol.
void modifiedFiles (const std::set< QString > &filenames)
Point3d normal (const cell &) const
Point3d normal (const junction &) const
Point3d position (const junction &v) const
Point3d position (const cell &v) const
void readMechanicParam (util::Parms &parms, const QString &section)
 Read the mechanical parameters.
virtual void readParam ()
 Read the parameters.
void readRules (util::Parms &parms, const QString &section)
 Read a prepare the cell-system rules.
void readSymbols (util::Parms &parms, const QString &section)
 Read the list of symbols.
label_t registerSymbol (QString name)
 Register a new symbol to be used in the cell system.
bool serialize (storage::VVEStorage &store)
 Reimplement this method to load/save the current state of the model.
void setPosition (const junction &v, const Point3d &pos)
void setPosition (const cell &v, const Point3d &pos)
void setPositionHint (const junction &, const junction &, const junction &, double)
void step ()
 Default step method, just applies the rules and do the mechanics.
bool step_cellsystem ()
 Cell system step.
void step_cellsystem_division ()
 Divide the cells according to their current geometry and the rules in the parameter file.
bool step_cellsystem_meca ()
 Compute the mecanic stability of the system for a time showInterval.
void updateCellsArea ()
 Update the area and the center of all the cells.
void updateFromOld (const cell &cl, const cell &cr, const cell &c, const typename Complex::division_data &, Complex &T)
QString version () const
int versionNumber (const QString &version)

Public Attributes

DivisionParams current_div
 Current division rule.
double damping
 Damping parameter.
division_rules_t division_rules
 Rules of type A --> B |(a,r) C.
double dt
 Time step for mechanical simulation.
double ke
 Stiffness of an external spring.
double ki
 Stiffness of an internal spring.
label_change_rules_t label_change_rules
 Rules of type A --> B.
std::vector< QStringlabel_names
 Mapping from the label numbers to the label strings.
std::map< QString, label_tlabel_numbers
 Mapping from the label names to the label numbers.
double mass
 Mass of the junctions.
double pressure
 Pressure coefficient in a cell.
double restLength
 Restlength of the springs.
double showInterval
 Time step between two images.
double showTime
 Time since the last image.
double stability
 Stability criteria.
Complex T
 Cell complex.
double time
 Current time.
bool viewRulesApplication
 Set to true to display the rules when applied.
bool viewRulesDefinitions
 Set to true to display the rules when analyzed.

Detailed Description

template<class Complex, class MyModel>
class cell_system::CellSystem< Complex, MyModel >

Full cell-system model.

Inherit this model to use cell-system with rules defined in the parameter file.

Parameters:
Complex Cell complex class to be used (allows for sub-type of vvcomplex::VVComplex as tissue::Tissue)
Model Subclass used. Useful to initialise the cell complex class

Definition at line 418 of file cellsystem.h.


Member Typedef Documentation

template<class Complex, class MyModel>
typedef std::map<label_t, DivisionParams> cell_system::CellSystem< Complex, MyModel >::division_rules_t

Type of rules of type A --> B |(a,r) C.

Definition at line 480 of file cellsystem.h.

template<class Complex, class MyModel>
typedef std::map<label_t, label_t> cell_system::CellSystem< Complex, MyModel >::label_change_rules_t

Type of rules of type A --> B.

Definition at line 476 of file cellsystem.h.


Constructor & Destructor Documentation

template<class Complex, class MyModel>
cell_system::CellSystem< Complex, MyModel >::CellSystem ( QObject parent  )  [inline]

Constructor .

..

Definition at line 778 of file cellsystem.h.

00779       : Model( parent )
00780       , T((MyModel*)this)
00781       , showTime(0)
00782       , time(0)
00783       , viewRulesDefinitions(false)
00784       , viewRulesApplication(false)
00785     {
00786     }


Member Function Documentation

template<class Complex, class MyModel>
label_t cell_system::CellSystem< Complex, MyModel >::label ( QString  name  )  [inline]

Returns the label number of a symbol.

Parameters:
name Name of the symbol

If the symbol do not exist, it is created

Definition at line 582 of file cellsystem.h.

Referenced by cell_system::CellSystem< TissueClass, RealModel >::readRules(), and cell_system::CellSystem< TissueClass, RealModel >::step_cellsystem_division().

00583     {
00584       std::map<QString,label_t>::const_iterator found = label_numbers.find(name);
00585       if(found != label_numbers.end())
00586       {
00587         return found->second;
00588       }
00589       cout << "Error, symbol '" << name.toStdString() << "' used but not defined" << endl;
00590       return -1;
00591     }

template<class Complex, class MyModel>
void cell_system::CellSystem< Complex, MyModel >::readMechanicParam ( util::Parms parms,
const QString section 
) [inline]

Read the mechanical parameters.

The mechanical parameters include: * dt: Time step for mechanical simulation * ki: Stiffness of internal springs * ke: Stability of external springs * ShowInterval: Time step between two images * Pressure: Pressure coefficient * Damping: Damping coefficient * RestLength: Rest length of the springs * Stability: Max force allowed on a junction to consider the system at equilibrium * Mass: Mass of a junction

Parameters:
parms Parameter object to read from
section Section containing the mechanical parameters

Definition at line 560 of file cellsystem.h.

Referenced by cell_system::CellSystem< TissueClass, RealModel >::readParam().

00561     {
00562       parms(section, "dt", dt);
00563       parms(section, "ki", ki);
00564       parms(section, "ke", ke);
00565       parms(section, "ShowInterval", showInterval);
00566       if(showInterval < dt)
00567         showInterval = dt;
00568       parms(section, "Pressure", pressure);
00569       parms(section, "Damping", damping);
00570       parms(section, "RestLength", restLength);
00571       parms(section, "Stability", stability);
00572       parms(section, "Mass", mass);
00573     }

template<class Complex, class MyModel>
virtual void cell_system::CellSystem< Complex, MyModel >::readParam (  )  [inline, virtual]

Read the parameters.

Usefull if no other parameters are needed (i.e. very unlikely)

Definition at line 761 of file cellsystem.h.

00762     {
00763       util::Parms parms("view.v");
00764       readMechanicParam(parms, "Mechanic");
00765       readSymbols(parms, "Symbols");
00766       readRules(parms, "Rules");
00767     }

template<class Complex, class MyModel>
void cell_system::CellSystem< Complex, MyModel >::readRules ( util::Parms parms,
const QString section 
) [inline]

Read a prepare the cell-system rules.

Parameters:
parms Parameter object to read from
section Section containing the rules (and only them)
Warning:
readSymbols() has to be called before readRules

The rules can take three form: # A: B, correspond to a relabelling A --> B # A: B |(a,r) C, correspond to a cell division. a is the angle between the reference vector and the normal to the new wall, r is the volume ration VB/VA. B and C and the labels of the new cells. If r is 0 then the wall goes through the center of the cell. # A: B |(a) C, is the same as the above rule but with r = 0.5.

There can be only one rule per symbol (i.e. no two rule can share the same left hand side symbol).

Definition at line 656 of file cellsystem.h.

Referenced by cell_system::CellSystem< TissueClass, RealModel >::readParam().

00657     {
00658       typedef std::map<QString, std::vector<QString> > rmap;
00659       rmap rules;
00660       parms.all(section, rules);
00661 
00662       for(rmap::iterator it = rules.begin() ; it != rules.end() ; ++it)
00663       {
00664         QString name = it->first;
00665         label(name);
00666       }
00667 
00668       label_change_rules.clear();
00669       division_rules.clear();
00670 
00671       for(rmap::iterator it = rules.begin() ; it != rules.end() ; ++it)
00672       {
00673         label_t lhs = label_numbers[it->first];
00674         if(it->second.size() > 1)
00675         {
00676           cout << "Error, more than one rule for '" << lhs << "' ... ignoring" << endl;
00677           continue;
00678         }
00679         QString rhs = it->second[0];
00680         int pos = rhs.indexOf('|');
00681         if(pos == -1)
00682         {
00683           label_t new_label = label(rhs);
00684           label_change_rules[lhs] = new_label;
00685           if(viewRulesDefinitions)
00686             cout << "Rule: " << label_names[lhs].toStdString() << " --> " << label_names[new_label].toStdString() << endl;
00687         }
00688         else
00689         {
00690           if(pos == -1)
00691           {
00692            cout << "Error, division rule without '|': " << lhs << " --> " << rhs.toStdString() << endl;
00693            continue;
00694           }
00695           QString left_name = rhs.mid(0, pos).trimmed();
00696           label_t left_label = label(left_name);
00697           int pos_left_paren, pos_right_paren, pos_comma;
00698           pos_left_paren = rhs.indexOf('(', pos);
00699           pos_comma = rhs.indexOf(',', pos_left_paren);
00700           pos_right_paren = rhs.indexOf(')', pos_left_paren);
00701           if(pos_left_paren == -1)
00702           {
00703            cout << "Error, division rule without '(': " << lhs << " --> " << rhs.toStdString() << endl;
00704            continue;
00705           }
00706           if(pos_right_paren == -1)
00707           {
00708            cout << "Error, division rule without ')': " << lhs << " --> " << rhs.toStdString() << endl;
00709            continue;
00710           }
00711           QString right_name = rhs.mid(pos_right_paren+1).trimmed();
00712           label_t right_label = label(right_name);
00713           if(pos_comma != -1)
00714           {
00715             QString angle_str = rhs.mid(pos_left_paren+1, pos_comma-pos_left_paren-1);
00716             QString ratio_str = rhs.mid(pos_comma+1, pos_right_paren-pos_comma-1);
00717             bool ok;
00718             double angle = angle_str.toDouble(&ok);
00719             if(!ok)
00720             {
00721               cout << "Error, cannot read angle (" << angle_str.toStdString() << ") in " << lhs << " --> " << rhs.toStdString() << endl;
00722               continue;
00723             }
00724             angle *= M_PI/180;
00725             double ratio = ratio_str.toDouble(&ok);
00726             if(!ok)
00727             {
00728               cout << "Error, cannot read ratio (" << ratio_str.toStdString() << ") in " << lhs << " --> " << rhs.toStdString() << endl;
00729               continue;
00730             }
00731             division_rules[lhs] = DivisionParams(left_label, right_label, angle, ratio);
00732           }
00733           else
00734           {
00735             QString angle_str = rhs.mid(pos_left_paren+1, pos_right_paren-pos_left_paren-1);
00736             bool ok;
00737             double angle = angle_str.toDouble(&ok);
00738             if(!ok)
00739             {
00740               cout << "Error, cannot read angle (" << angle_str.toStdString() << ") in " << lhs << " --> " << rhs.toStdString() << endl;
00741               continue;
00742             }
00743             angle *= M_PI/180;
00744             division_rules[lhs] = DivisionParams(left_label, right_label, angle);
00745           }
00746           const DivisionParams& dp = division_rules[lhs];
00747           if(viewRulesDefinitions)
00748             cout << "Rule: " << label_names[lhs].toStdString() << " --> " << label_names[dp.left_label].toStdString() << " |("
00749               << (dp.angle*180/M_PI) << ","
00750               << dp.ratio << ") " << label_names[dp.right_label].toStdString() << endl;
00751         }
00752       }
00753       cout << endl;
00754     }

template<class Complex, class MyModel>
void cell_system::CellSystem< Complex, MyModel >::readSymbols ( util::Parms parms,
const QString section 
) [inline]

Read the list of symbols.

The symbols are the keys and may have values (but it is not necessary)

Definition at line 599 of file cellsystem.h.

Referenced by cell_system::CellSystem< TissueClass, RealModel >::readParam().

00600     {
00601       typedef std::map<QString, std::vector<QString> > rmap;
00602       rmap symbols;
00603       parms.all(section, symbols);
00604       if(viewRulesDefinitions)
00605         util::out << "Reading " << symbols.size() << " symbols from section [" << section << "]" << endl;
00606       for(rmap::iterator it = symbols.begin() ; it != symbols.end() ; ++it)
00607       {
00608         QString name = it->first;
00609         registerSymbol(name);
00610       }
00611     }

template<class Complex, class MyModel>
label_t cell_system::CellSystem< Complex, MyModel >::registerSymbol ( QString  name  )  [inline]

Register a new symbol to be used in the cell system.

If the symbol already exists, return the id of the existing one.

name Name of the new symbol

Returns:
The id of the symbol

Definition at line 622 of file cellsystem.h.

Referenced by cell_system::CellSystem< TissueClass, RealModel >::readSymbols().

00623     {
00624       std::map<QString, label_t>::iterator found = label_numbers.find(name);
00625       if(found == label_numbers.end())
00626       {
00627         label_t new_label = label_names.size();
00628         label_names.push_back(name);
00629         label_numbers[name] = new_label;
00630         if(viewRulesDefinitions)
00631           cout << "Defining symbol '" << name.toStdString() << "' as value " << new_label << endl;
00632         return new_label;
00633       }
00634       return found->second;
00635     }

template<class Complex, class MyModel>
bool cell_system::CellSystem< Complex, MyModel >::serialize ( storage::VVEStorage  )  [inline, virtual]

Reimplement this method to load/save the current state of the model.

Returns:
true if serialization was successful, false otherwise.
Parameters:
store Object to store the state in the model in.

Reimplemented from Model.

Definition at line 997 of file cellsystem.h.

00998     {
00999       if(!store.field("T", T))
01000       {
01001         return false;
01002       }
01003       if(!store.field("Time", time))
01004       {
01005         std::cerr << "Warning, cell system saved without time. Setting time to 0" << endl;
01006         time = 0;
01007       }
01008       return true;
01009     }

template<class Complex, class MyModel>
void cell_system::CellSystem< Complex, MyModel >::step (  )  [inline, virtual]

Default step method, just applies the rules and do the mechanics.

Implements Model.

Definition at line 791 of file cellsystem.h.

00792     {
00793       step_cellsystem();
00794     }

template<class Complex, class MyModel>
bool cell_system::CellSystem< Complex, MyModel >::step_cellsystem (  )  [inline]

Cell system step.

Returns true if the rules were applied, false if just the mechanic was done (i.e. the system is not stabilised)

Definition at line 903 of file cellsystem.h.

Referenced by cell_system::CellSystem< TissueClass, RealModel >::step().

00904     {
00905       if(!this->step_cellsystem_meca())
00906         return false;
00907 
00908       step_cellsystem_division();
00909       return true;
00910    }

template<class Complex, class MyModel>
void cell_system::CellSystem< Complex, MyModel >::step_cellsystem_division (  )  [inline]

Divide the cells according to their current geometry and the rules in the parameter file.

Definition at line 864 of file cellsystem.h.

Referenced by cell_system::CellSystem< TissueClass, RealModel >::step_cellsystem().

00865     {
00866       updateCellsArea();
00867 
00868       // Second, division
00869       std::vector<cell> cells(T.C.begin(), T.C.end());
00870       forall(const cell& c, cells)
00871       {
00872         label_t label = c->label;
00873         label_change_rules_t::const_iterator label_found = label_change_rules.find(label);
00874         division_rules_t::const_iterator division_found = division_rules.find(label);
00875         if(label_found != label_change_rules.end())
00876         {
00877           if(viewRulesApplication)
00878             cout << "Applying rule: " << c->label << " --> " << label_found->second << endl;
00879           c->label = label_found->second;
00880         }
00881         else if(division_found != division_rules.end())
00882         {
00883           const DivisionParams& div = division_found->second;
00884           if(viewRulesApplication)
00885             cout << "Applying rule: " << c->label << " --> "
00886               << div.left_label << " |(" << (div.angle*180/M_PI) << "," << div.ratio << ") "
00887               << div.right_label << endl;
00888           current_div = div;
00889           Point3d ref = ((MyModel*)this)->referenceVector(c);
00890           ref.normalize();
00891           CellSystemDivisionParams parms(ref, div.angle, div.ratio, EPSILON);
00892           T.divideCell(c, parms, c);
00893         }
00894       }
00895     }

template<class Complex, class MyModel>
bool cell_system::CellSystem< Complex, MyModel >::step_cellsystem_meca (  )  [inline]

Compute the mecanic stability of the system for a time showInterval.

Return true if the system is stable, false otherwise.

Definition at line 801 of file cellsystem.h.

Referenced by cell_system::CellSystem< TissueClass, RealModel >::step_cellsystem().

00802     {
00803       time += dt;
00804       bool stable;
00805       do
00806       {
00807         showTime += dt;
00808         // First, mechanical model
00809         updateCellsArea();
00810         forall(const junction& v, T.W)
00811         {
00812           v->force = 0;
00813         }
00814         forall_named(const cell& c, T.S, cells)
00815         {
00816           double area= c->area;
00817           // First, compute the forces due to the pressure
00818           forall(const junction& j, T.S.neighbors(c))
00819           {
00820             const junction& k = T.S.nextTo(c, j);
00821             Point3d u = k->pos - j->pos;
00822             double l = util::norm(u);
00823             u /= l;
00824             Point3d n(u.y(), -u.x(), 0);
00825             n *= pressure*l/area/2;
00826             j->force += n;
00827             k->force += n;
00828           }
00829         }
00830         // Second, compute the forces due to the springs
00831         forall(const junction& j, T.W)
00832         {
00833           const Point3d& jpos = j->pos;
00834           forall(const junction& k, T.W.neighbors(j))
00835           {
00836             double ks = ki;
00837             if(T.border(j, k))
00838               ks = ke;
00839             Point3d u = k->pos - jpos;
00840             double l = util::norm(u);
00841             u *= ks*(1 - restLength/l);
00842             j->force += u;
00843           }
00844         }
00845 
00846         // Now, integrate and check for stability
00847         stable = true;
00848         forall(const junction& j, T.W)
00849         {
00850           if(util::norm(j->force) > stability) stable = false;
00851           j->velocity += (j->force - damping*j->velocity)/mass*dt;
00852           j->pos += j->velocity*dt;
00853         }
00854       } while(showTime < showInterval);
00855       showTime -= showInterval;
00856 
00857       return stable;
00858     }

template<class Complex, class MyModel>
void cell_system::CellSystem< Complex, MyModel >::updateCellsArea (  )  [inline]

Update the area and the center of all the cells.

Definition at line 517 of file cellsystem.h.

Referenced by cell_system::CellSystem< TissueClass, RealModel >::step_cellsystem_division(), and cell_system::CellSystem< TissueClass, RealModel >::step_cellsystem_meca().

00518     {
00519       forall_named( const cell& c, T.S, cells)
00520       {
00521         Point3d center;
00522         double np = 0;
00523         c->area = 0.0;
00524         forall(const junction& n, T.S.neighbors(c))
00525         {
00526           // Find area
00527           const junction& m = T.S.nextTo(c, n);
00528           c->area += geometry::triangleArea(c->pos, m->pos, n->pos);
00529           center += n->pos;
00530           np++;
00531         }
00532         center /= np;
00533         c->pos = center;
00534         if(c->area <= EPSILON ) // Avoid inf
00535         {
00536           cout << "Bad area " << c->area << endl;
00537           c->area = 0.1;
00538         }
00539       }
00540     }

template<class Complex, class MyModel>
QString cell_system::CellSystem< Complex, MyModel >::version (  )  const [inline, virtual]
Returns:
the current version of the class.

The default implementation returns an empty string

Reimplemented from Model.

Definition at line 992 of file cellsystem.h.

00993     {
00994       return "CellSystemModel 1.0";
00995     }

template<class Complex, class MyModel>
int cell_system::CellSystem< Complex, MyModel >::versionNumber ( const QString  )  [inline, virtual]
Returns:
an integer representing the version string for the model.

The default implementation always return 0.

The number has no meaning outside the model.

Reimplemented from Model.

Definition at line 987 of file cellsystem.h.

Referenced by cell_system::CellSystem< TissueClass, RealModel >::versionNumber().

00988     {
00989       return storage::versionNumber(version);
00990     }


Member Data Documentation

template<class Complex, class MyModel>
DivisionParams cell_system::CellSystem< Complex, MyModel >::current_div

Current division rule.

Used to setup the cell labels in updateFromOld

Definition at line 503 of file cellsystem.h.

Referenced by cell_system::CellSystem< TissueClass, RealModel >::step_cellsystem_division().

template<class Complex, class MyModel>
double cell_system::CellSystem< Complex, MyModel >::damping
template<class Complex, class MyModel>
division_rules_t cell_system::CellSystem< Complex, MyModel >::division_rules
template<class Complex, class MyModel>
double cell_system::CellSystem< Complex, MyModel >::dt
template<class Complex, class MyModel>
double cell_system::CellSystem< Complex, MyModel >::ke
template<class Complex, class MyModel>
double cell_system::CellSystem< Complex, MyModel >::ki
template<class Complex, class MyModel>
label_change_rules_t cell_system::CellSystem< Complex, MyModel >::label_change_rules
template<class Complex, class MyModel>
std::vector<QString> cell_system::CellSystem< Complex, MyModel >::label_names

Mapping from the label numbers to the label strings.

Definition at line 496 of file cellsystem.h.

Referenced by cell_system::CellSystem< TissueClass, RealModel >::readRules(), and cell_system::CellSystem< TissueClass, RealModel >::registerSymbol().

template<class Complex, class MyModel>
std::map<QString, label_t> cell_system::CellSystem< Complex, MyModel >::label_numbers
template<class Complex, class MyModel>
double cell_system::CellSystem< Complex, MyModel >::mass
template<class Complex, class MyModel>
double cell_system::CellSystem< Complex, MyModel >::pressure
template<class Complex, class MyModel>
double cell_system::CellSystem< Complex, MyModel >::restLength
template<class Complex, class MyModel>
double cell_system::CellSystem< Complex, MyModel >::showInterval
template<class Complex, class MyModel>
double cell_system::CellSystem< Complex, MyModel >::showTime

Time since the last image.

Definition at line 439 of file cellsystem.h.

Referenced by cell_system::CellSystem< TissueClass, RealModel >::step_cellsystem_meca().

template<class Complex, class MyModel>
double cell_system::CellSystem< Complex, MyModel >::stability
template<class Complex, class MyModel>
Complex cell_system::CellSystem< Complex, MyModel >::T
template<class Complex, class MyModel>
double cell_system::CellSystem< Complex, MyModel >::time
template<class Complex, class MyModel>
bool cell_system::CellSystem< Complex, MyModel >::viewRulesApplication

Set to true to display the rules when applied.

Definition at line 512 of file cellsystem.h.

Referenced by cell_system::CellSystem< TissueClass, RealModel >::step_cellsystem_division().

template<class Complex, class MyModel>
bool cell_system::CellSystem< Complex, MyModel >::viewRulesDefinitions

The documentation for this class was generated from the following file:
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines
Generated on Fri May 31 15:38:06 2013 for VVE by  doxygen 1.6.3