MorphoGraphX  2.0-1-227
CellTissue.hpp
Go to the documentation of this file.
1 //
2 // This file is part of MorphoGraphX - http://www.MorphoGraphX.org
3 // Copyright (C) 2012-2016 Richard S. Smith and collaborators.
4 //
5 // If you use MorphoGraphX in your work, please cite:
6 // http://dx.doi.org/10.7554/eLife.05864
7 //
8 // MorphoGraphX is free software, and is licensed under under the terms of the
9 // GNU General (GPL) Public License version 2.0, http://www.gnu.org/licenses.
10 //
11 #ifndef CELL_TISSUE_HPP
12 #define CELL_TISSUE_HPP
13 
20 #include <Config.hpp>
21 #include <Types.hpp>
22 #include <Information.hpp>
23 #include <Attributes.hpp>
24 #include <Subdivide.hpp>
25 #include <Geometry.hpp>
26 #include <DistObject.hpp>
27 
28 namespace mgx
29 {
30  class Mesh;
31 
32  // Parameter names for the various mesh types
33  struct mgx_EXPORT CellTissueMgx2d
34  {
36  pCellWallWidth, pCellWallCorner, pCellColorBegin, pCellColorEnd, pCellColorCenter, pCellBorderColor,
37  pCellPolWidth, pCellPolCorner, pCellPolColorBegin, pCellPolColorEnd, pCellNormalColor, pCellGraphColor,
38  pCellLineColor, pCellLineWidth, pNumParms };
39  };
40 
41  struct mgx_EXPORT CellDivideMgx2d
42  {
43  enum ParmNames { pCellMaxArea, pCellDivAlg, pCellWallSample, pCellPinch, pCellMaxPinch, pCellWallMin, pNumParms };
44  };
45 
46  class mgx_EXPORT CellTissue
47  {
48  public:
57  enum DivAlg {SHORTEST_WALL = 0, CLOSEST_MID = 1, CLOSEST_WALL = 2, SHORTEST_DIR = 3, PREDEFINED_DIR = 4};
58 
62  enum UpdGeom {UPD_AREA = 1, UPD_LENGTH = 2, UPD_CENTER = 4, UPD_NORMAL = 8, UPD_VOLUME = 16, UPD_WALLSZ = 32};
63 
64  vvGraph S; // All the vertices
65  vvGraph J; // The junction (plus centers) graph
66  cellGraph C; // Cell centers
67 
68  // Distributed neighborhood objects
73 
74  // Constructor
75  CellTissue() : nhbdS(S), nhbdC(C), CellMaxArea(25), CellDivAlg(SHORTEST_WALL),
76  CellWallSample(.05), CellPinch(.2), CellMaxPinch(1.0), CellWallMin(.1), CellUpdGeomMode(63),
77  CellWallWidth(0.025), CellWallCorner(0.15), CellColorBegin(1), CellColorEnd(2),
78  CellColorCenter(0.3), CellBorderColor(0), CellPolWidth(0.0), CellPolCorner(0.3), CellPolColorBegin(3),
79  CellPolColorEnd(4), CellNormalColor(5), CellGraphColor( 5), CellLineColor(5), CellLineWidth(1.0),
80  _meshType("MGXM"), _currLabel(0) {}
81 
91  const QString &meshType() { return _meshType; }
92 
93  const QString &setMeshType(const QString &meshType);
94 
98  int viewLabel() const { return _currLabel; }
99 
103  void setLabel(int l) { _currLabel = l; }
104 
108  int nextLabel() { return ++_currLabel; }
109 
113  bool chkGraph(const vvGraph &S) const;
114 
118  void updGeometry() { updGeometry(CellUpdGeomMode); }
119  void updGeometry(int mode);
120 
124  void updGeometry(const cell &c) { updGeometry(c, CellUpdGeomMode); }
125  void updGeometry(const cell &c, int mode);
126  bool hasCellGraph();
127 
131  static DivAlg stringToDivAlg(const QString &s)
132  {
133  if(s.toUpper() == "CLOSEST MIDPOINT")
134  return CLOSEST_MID;
135  else if(s.toUpper() == "CLOSEST WALL")
136  return CLOSEST_WALL;
137  else if(s.toUpper() == "SHORTEST DIRECTION")
138  return SHORTEST_DIR;
139  else if(s.toUpper() == "PREDEFINED DIRECTION")
140  return PREDEFINED_DIR;
141  // Shortest wall is the default
142  return SHORTEST_WALL;
143  }
144 
148  bool divideCell(const cell &c, Subdivide *sDiv, DivAlg divAlg = SHORTEST_WALL);
149 
153  bool divideCell(const cell &c, Subdivide *sDiv, DivAlg divAlg, std::vector<Point3d> &nrmls);
154 
158  void deleteCell(const cell &c);
159 
163  void processParms(const QStringList &parms);
164  void processParmsDivide(const QStringList &parms);
165 
169  bool addCell(std::vector<vertex> poly);
170 
174  bool toMgxm();
175 
180  bool toMgxc(double wallMax = 0);
181 
185  bool toMgx2d(double wallMax = 0);
186  bool createTissueGraphs(vvGraph &cS,vvGraph &cJ,cellGraph & cC,double wallMax = 0);
190  typedef std::pair<int, int> IntInt;
191  typedef std::pair<IntInt, double> IntIntDouble;
192  void getNeighborhoodMap3D(std::map<IntInt, double>& neighborMap);
193  bool toMgx3d(double tolerance = 0, double neighborMinArea = 0);
194 
198  void updateAllGraph();
199 
203  //bool correctCellMesh(const vvGraph &S);
204 
208  bool loadCellTissueFromText(const QString &fileName);
209 
213  bool saveCellTissueToText(const QString &fileName);
214 
218  inline cell getCell(vertex v)
219  {
220  cell c(0);
221  if(v and v->cId)
222  c = cell(v->cId);
223  return c;
224  }
225 
229  inline vertex getVtx(cell c)
230  {
231  vertex v(0);
232  if(c and c->vId)
233  v = vertex(c->vId);
234  return v;
235  }
236  inline bool assocCellVertex(vertex &v, cell &m)
237  {
238  //if(v->saveId == 0 or m->saveId == 0) //TODO: ErrorCheck
239  // return false;
240  m->vId = v.id();
241  v->cId = m.id();
242  return true;
243  }
244 
245  // Parameters for cell division, that have to be accessed from outside
246  // RSS: Make these methods if required
247  float CellMaxArea; // Area threshold for cell division
248  DivAlg CellDivAlg; // Cell division algorithm
249 
250  private:
251  // Apply Min distance from corner and return difference
252  double findWallMin(Point3d &v, Point3d v1, Point3d v2, double mw);
253 
254  // Find Cell divide point
255  bool findCellDiv(DivAlg divAlg, cell c, Point3d &pu, Point3d &pv, vertex &p_u1, vertex &p_u2,
256  vertex &p_v1, vertex &p_v2, double &su, double &sv, std::vector<Point3d> &nrmls);
257 
258  // Find Cell divide point 3D
259  bool findCellDiv3D(QString divAlg, cell c, Point3d &pu, Point3d &pv, vertex &p_u1,
260  vertex &p_u2, vertex &p_v1, vertex &p_v2, double &su, double &sv, std::vector<Point3d> &nrmls);
261 
262  // Parameters from parms file
263  double CellWallSample; // Sample size for cell division
264  double CellPinch; // Amount to pinch at division
265  double CellMaxPinch; // Max amount to pinch at division
266  double CellWallMin; // Min distance to avoid 4-way junction
267  int CellUpdGeomMode; // What to update when calling updGeometry()
268 
269  double CellWallWidth; // Width of lines for cell walls
270  double CellWallCorner; // Size of corner triangles
271  int CellColorBegin; // Beginning of cell face color ramp
272  int CellColorEnd; // End of cell face color ramp
273  double CellColorCenter; // Amount that color increases towards the center
274  int CellBorderColor; // Color to draw borders
275 
276  double CellPolWidth; // Width to draw cell polarity
277  double CellPolCorner; // Size of cell polarity corner triangles
278  int CellPolColorBegin; // Start of polarity color ramp
279  int CellPolColorEnd; // End of polarity color ramp
280 
281  int CellNormalColor; // Color to draw normals
282  int CellGraphColor; // Color to draw cell graph
283  int CellLineColor; // Color to draw lines
284  double CellLineWidth; // Width for all lines
285 
286  // Mesh Type
287  QString _meshType;
288  int _currLabel;
289  };
290 }
291 
292 #endif
mgx::CellTissue::CellTissue
CellTissue()
Definition: CellTissue.hpp:75
Attributes.hpp
mgx::vertex
vvGraph::vertex_t vertex
Type of a vertex.
Definition: Misc.hpp:50
mgx::CellTissue::J
vvGraph J
Definition: CellTissue.hpp:65
mgx::CellTissue::DivAlg
DivAlg
Type of cell division SHORTEST WALL : CLOSEST MID : take midpoints of all wall segments and check whi...
Definition: CellTissue.hpp:57
mgx::CellTissue::CellDivAlg
DivAlg CellDivAlg
Definition: CellTissue.hpp:248
mgx::CellTissueMgx2d::pCellWallWidth
@ pCellWallWidth
Definition: CellTissue.hpp:36
Information.hpp
mgx::CellTissue::DistNhbdS
DistNhbd< vvGraph > DistNhbdS
Definition: CellTissue.hpp:69
mgx::CellTissue
Definition: CellTissue.hpp:46
mgx::CellTissue::stringToDivAlg
static DivAlg stringToDivAlg(const QString &s)
Map a string to the enum.
Definition: CellTissue.hpp:131
mgx::CellTissue::viewLabel
int viewLabel() const
Returns the current label, without modifying it.
Definition: CellTissue.hpp:98
mgx::CellTissue::updGeometry
void updGeometry()
Set area, length of cell walls, center and normal.
Definition: CellTissue.hpp:118
mgx::CellTissueMgx2d::ParmNames
ParmNames
Definition: CellTissue.hpp:35
Geometry.hpp
mgx::CellTissue::setLabel
void setLabel(int l)
Sets the current label.
Definition: CellTissue.hpp:103
mgx
Distributed matrix library.
Definition: Assert.hpp:26
mgx::CellTissue::C
cellGraph C
Definition: CellTissue.hpp:66
mgx::CellTissue::IntInt
std::pair< int, int > IntInt
Create a 3D cellular tissue.
Definition: CellTissue.hpp:190
Subdivide.hpp
DistObject.hpp
mgx::CellTissue::nhbdC
DistNhbdC nhbdC
Definition: CellTissue.hpp:72
mgx::CellDivideMgx2d
Definition: CellTissue.hpp:41
mgx::CellTissueMgx2d::pCellUpdGeomMode
@ pCellUpdGeomMode
Definition: CellTissue.hpp:35
mgx::CellTissue::assocCellVertex
bool assocCellVertex(vertex &v, cell &m)
Definition: CellTissue.hpp:236
mgx::CellTissue::getVtx
vertex getVtx(cell c)
Return a vertex from the cell.
Definition: CellTissue.hpp:229
mgx::CellTissue::S
vvGraph S
Definition: CellTissue.hpp:64
mgx::CellTissue::CellMaxArea
float CellMaxArea
Definition: CellTissue.hpp:247
mgx::CellTissueMgx2d
Definition: CellTissue.hpp:33
mgx::CellTissue::DistNhbdC
DistNhbd< cellGraph > DistNhbdC
Definition: CellTissue.hpp:71
mgx::CellTissue::nextLabel
int nextLabel()
Increment the current label and return.
Definition: CellTissue.hpp:108
mgx::CellTissue::nhbdS
DistNhbdS nhbdS
Definition: CellTissue.hpp:70
mgx::Vertex::id
identity_t id() const
Return the identifier of a vertex.
Definition: Vertex.hpp:242
mgx::CellTissueMgx2d::pCellPolWidth
@ pCellPolWidth
Definition: CellTissue.hpp:37
mgx::cell
cellGraph::vertex_t cell
Type of a vertex.
Definition: Types.hpp:122
mgx::DistNhbd< vvGraph >
mgx::CellTissue::meshType
const QString & meshType()
Returns a reference to the mesh type.
Definition: CellTissue.hpp:91
mgx::Vector< 3, double >
Types.hpp
mgx::CellTissue::getCell
cell getCell(vertex v)
Return a vertex from the cell.
Definition: CellTissue.hpp:218
mgx::VVGraph< VertexData, EdgeData >
mgx::Subdivide
Definition: Subdivide.hpp:25
mgx::CellTissue::UpdGeom
UpdGeom
Type of update to geoemtry.
Definition: CellTissue.hpp:62
mgx::CellDivideMgx2d::ParmNames
ParmNames
Definition: CellTissue.hpp:43
mgx::CellTissue::IntIntDouble
std::pair< IntInt, double > IntIntDouble
Definition: CellTissue.hpp:191
mgx::Vertex
Definition: Vertex.hpp:58
mgx::CellTissue::updGeometry
void updGeometry(const cell &c)
Set area, length of cell walls, center and normal.
Definition: CellTissue.hpp:124