00001 /************************************************************************* 00002 * CompuCell - A software framework for multimodel simulations of * 00003 * biocomplexity problems Copyright (C) 2003 University of Notre Dame, * 00004 * Indiana * 00005 * * 00006 * This program is free software; IF YOU AGREE TO CITE USE OF CompuCell * 00007 * IN ALL RELATED RESEARCH PUBLICATIONS according to the terms of the * 00008 * CompuCell GNU General Public License RIDER you can redistribute it * 00009 * and/or modify it under the terms of the GNU General Public License as * 00010 * published by the Free Software Foundation; either version 2 of the * 00011 * License, or (at your option) any later version. * 00012 * * 00013 * This program is distributed in the hope that it will be useful, but * 00014 * WITHOUT ANY WARRANTY; without even the implied warranty of * 00015 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * 00016 * General Public License for more details. * 00017 * * 00018 * You should have received a copy of the GNU General Public License * 00019 * along with this program; if not, write to the Free Software * 00020 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. * 00021 *************************************************************************/ 00022 00023 00024 00025 #include <CompuCell3D/Simulator.h> 00026 00027 #include <CompuCell3D/Potts3D/Potts3D.h> 00028 #include <CompuCell3D/Field3D/Field3D.h> 00029 #include <CompuCell3D/Field3D/WatchableField3D.h> 00030 #include <CompuCell3D/Boundary/BoundaryStrategy.h> 00031 using namespace CompuCell3D; 00032 00033 00034 #include <iostream> 00035 using namespace std; 00036 00037 #define EXP_STL 00038 #include "SurfaceTrackerPlugin.h" 00039 00040 SurfaceTrackerPlugin::SurfaceTrackerPlugin() : cellFieldG(0),boundaryStrategy(0),maxNeighborIndex(0) {} 00041 00042 SurfaceTrackerPlugin::~SurfaceTrackerPlugin() { 00043 } 00044 00045 00046 00047 void SurfaceTrackerPlugin::init(Simulator *simulator, CC3DXMLElement *_xmlData) { 00048 00049 potts = simulator->getPotts(); 00050 cellFieldG = (WatchableField3D<CellG *> *)potts->getCellFieldG(); 00051 00052 potts->registerCellGChangeWatcher(this); 00053 00054 boundaryStrategy=BoundaryStrategy::getInstance(); 00055 00056 update(_xmlData); 00057 00058 simulator->registerSteerableObject(this); 00059 00060 } 00061 00062 00064 00065 void SurfaceTrackerPlugin::field3DChange(const Point3D &pt, CellG *newCell, CellG *oldCell) 00066 { 00067 if (newCell==oldCell) //this may happen if you are trying to assign same cell to one pixel twice 00068 return; 00069 00070 unsigned int token = 0; 00071 double distance; 00072 double oldDiff = 0.; 00073 double newDiff = 0.; 00074 CellG *nCell = 0; 00075 Neighbor neighbor; 00076 00077 for(unsigned int nIdx=0 ; nIdx <= maxNeighborIndex ; ++nIdx ) 00078 { 00079 neighbor = boundaryStrategy->getNeighborDirect(const_cast<Point3D&>(pt),nIdx); 00080 if(!neighbor.distance) 00081 continue; 00082 00083 nCell = cellFieldG->get(neighbor.pt); 00084 if (newCell == nCell) newDiff-=lmf.surfaceMF; 00085 else newDiff+=lmf.surfaceMF; 00086 00087 if (oldCell == nCell) oldDiff+=lmf.surfaceMF; 00088 else oldDiff-=lmf.surfaceMF; 00089 } 00090 00091 if (newCell) newCell->surface += newDiff; 00092 if (oldCell) oldCell->surface += oldDiff; 00093 } 00094 00095 00096 00097 00098 void SurfaceTrackerPlugin::update(CC3DXMLElement *_xmlData, bool _fullInitFlag){ 00099 if(!_xmlData){ 00100 maxNeighborIndex=boundaryStrategy->getMaxNeighborIndexFromNeighborOrder(1); //use first nearest neighbors for surface calculations as default 00101 }else if(_xmlData->getFirstElement("MaxNeighborOrder")){ 00102 maxNeighborIndex=boundaryStrategy->getMaxNeighborIndexFromNeighborOrder(_xmlData->getFirstElement("MaxNeighborOrder")->getUInt()); 00103 }else if (_xmlData->getFirstElement("MaxNeighborDistance")){ 00104 maxNeighborIndex=boundaryStrategy->getMaxNeighborIndexFromDepth(_xmlData->getFirstElement("MaxNeighborDistance")->getDouble());//depth=1.1 - means 1st nearest neighbor 00105 }else{ 00106 maxNeighborIndex=boundaryStrategy->getMaxNeighborIndexFromNeighborOrder(1); //use first nearest neighbors for surface calculations as default 00107 } 00108 lmf=boundaryStrategy->getLatticeMultiplicativeFactors(); 00109 } 00110 00111 std::string SurfaceTrackerPlugin::steerableName(){return toString();} 00112 00113 std::string SurfaceTrackerPlugin::toString(){return "SurfaceTracker";}
1.5.6