void MicrotubuleProcess::addDirect(Voxel& offVoxel, unsigned a,
                                   Voxel& adjoin, unsigned b)
{
  Point aPoint(*offVoxel.point);
  adjoin.id = tempID;
  Point adPoint(theSpatiocyteStepper->coord2point(b));
  if(!inMTCylinder(adPoint))
    { 
      if(initAdjoins(adjoin)) 
        {
          occCoords.push_back(b);
        }
      double dist(getDistance(&aPoint, &adPoint)); 
      if(dist <= latticeRadius+offLatticeRadius)
        {
          offVoxel.adjoiningCoords[offVoxel.adjoiningSize++] = b;
          updateAdjoinSize(adjoin);
          adjoin.initAdjoins[adjoin.adjoiningSize++] = a;
        }
      else
        { 
          addIndirect(offVoxel, a, adjoin, b);
        }
    }
}
void MicroscopyTrackingProcess::logFluorescentSpecies()
{
  std::vector<Point> aPoints;
  std::vector<unsigned> aMols;
  for(unsigned i(0); i != theFreqLatticeSize; ++i)
    { 
      for(unsigned j(0); j != theLatticeSpecies.size(); ++j)
        {
          if(theFreqLattice[j][i])
            {
              aMols.push_back(i);
              aPoints.push_back((*theInfo)[i].point);
              break;
            }
        }
    }
  double aCurrentTime(theSpatiocyteStepper->getCurrentTime());
  theLogFile.write((char*)(&aCurrentTime), sizeof(aCurrentTime));
  unsigned pointSize(aPoints.size());
  theLogFile.write((char*)(&pointSize), sizeof(pointSize));
  for(unsigned i(0); i != pointSize; ++i)
    {
      Point aPoint(aPoints[i]);
      theLogFile.write((char*)(&aPoint), sizeof(aPoint));
    }
  for(unsigned i(0); i != theLatticeSpecies.size(); ++i)
    {
      for(unsigned j(0); j != pointSize; ++j)
        {
          unsigned frequency(theFreqLattice[i][aMols[j]]);
          theLogFile.write((char*)(&frequency), sizeof(frequency));
        }
    }
}
Beispiel #3
0
void Activity::Draw(BRect rect)
{
bigtime_t present = system_time() - 600000;
	for (int i = 0; i < 4; i++)
		for (int j = 0; j < 4; j++)
		{
		BPoint aPoint(i * 60 + 70, j * 60 + 70);
			SetHighColor(0, 0, 0);
			StrokeEllipse(aPoint, 5, 5);
			SetHighColor(0, 255, 0);
			if (present < fActivity[j * 4 + i])
				FillEllipse(aPoint, 4, 4);
		}
}
void VisualizationLogProcess::logPolymers(int anIndex)
{
  Species* aSpecies(thePolymerSpecies[anIndex]);
  theLogFile.write((char*)(&anIndex), sizeof(anIndex));
  //The species molecule size:
  int aSize(aSpecies->size());
  theLogFile.write((char*)(&aSize), sizeof(aSize)); 
  for(unsigned i(0); i != theIDs->size(); ++i)
    {
      for(unsigned j(0); j != aSpecies->size(i); ++j)
        {
          Point aPoint(aSpecies->getPoint(i, j));
          theLogFile.write((char*)(&aPoint), sizeof(aPoint));
        }
    }
}  
void VisualizationLogProcess::logCompVacant()
{
  /*
  double aCurrentTime(theSpatiocyteStepper->getCurrentTime());
  theLogFile.write((char*)(&aCurrentTime), sizeof(aCurrentTime));
  for(unsigned int i(0); i != theLatticeSpecies.size(); ++i)
    {
      if(theLatticeSpecies[i]->getIsCompVacant())
        {
          Species* aVacantSpecies(theLatticeSpecies[i]);
          //The species index in the process:
          theLogFile.write((char*)(&i), sizeof(i));
          //The species molecule size:
          unsigned int aSize(aVacantSpecies->size());
          theLogFile.write((char*)(&aSize), sizeof(aSize)); 
          for(unsigned int j(0); j != aSize; ++j)
            {
              unsigned int aMol(aVacantSpecies->getMol(j));
              theLogFile.write((char*)(&aMol), sizeof(aMol));
            }  
        }
    }
    */
  //theLogMarker is a constant throughout the simulation:
  theLogFile.write((char*)(&theLogMarker), sizeof(theLogMarker));
  for(unsigned int k(0); k != theOffLatticeSpecies.size(); ++k)
    {
      if(theOffLatticeSpecies[k]->getIsCompVacant())
        {
          Species* aSpecies(theOffLatticeSpecies[k]);
          theLogFile.write((char*)(&k), sizeof(k));
          //The species molecule size:
          int aSize(aSpecies->size());
          theLogFile.write((char*)(&aSize), sizeof(aSize)); 
          for(unsigned i(0); i != theIDs->size(); ++i)
            {
              for(unsigned j(0); j != aSpecies->size(i); ++j)
                {
                  Point aPoint(aSpecies->getPoint(i, j));
                  theLogFile.write((char*)(&aPoint), sizeof(aPoint));
                }
            }
        }
    }
  theLogFile.write((char*)(&theLogMarker), sizeof(theLogMarker));
}
bool MicrotubuleProcess::initAdjoins(Voxel& aVoxel)
{
  if(aVoxel.initAdjoins == NULL)
    {
      aVoxel.adjoiningSize = 0;
      aVoxel.initAdjoins = new unsigned int[theAdjoiningCoordSize];
      for(unsigned int i(0); i != theAdjoiningCoordSize; ++i)
        {
          unsigned int aCoord(aVoxel.adjoiningCoords[i]);
          Point aPoint(theSpatiocyteStepper->coord2point(aCoord));
          if(!inMTCylinder(aPoint))
            {
              aVoxel.initAdjoins[aVoxel.adjoiningSize++] = aCoord;
            }
        }
      return true;
    }
  return false;
}
void VisualizationLogProcess::logOffLattice(int anIndex)
{
  Species* aSpecies(theOffLatticeSpecies[anIndex]);
  if(aSpecies->getIsVacant() && !aSpecies->getIsDiffusiveVacant() &&
     !aSpecies->getIsReactiveVacant())
    {
      return;
    }
  aSpecies->updateMols();
  theLogFile.write((char*)(&anIndex), sizeof(anIndex));
  //The species molecule size:
  int aSize(aSpecies->size());
  theLogFile.write((char*)(&aSize), sizeof(aSize)); 
  for(unsigned i(0); i != theIDs->size(); ++i)
    {
      for(unsigned j(0); j != aSpecies->size(i); ++j)
        {
          Point aPoint(aSpecies->getPoint(i, j));
          theLogFile.write((char*)(&aPoint), sizeof(aPoint));
        }
    }
}  
void MicrotubuleProcess::addIndirect(Voxel& offVoxel, unsigned a,
                                     Voxel& latVoxel, unsigned b)
{
  Point aPoint(*offVoxel.point);
  for(unsigned int i(0); i != theAdjoiningCoordSize; ++i)
    {
      unsigned int aCoord(latVoxel.adjoiningCoords[i]);
      Voxel& adjoin((*theLattice)[aCoord]);
      if(adjoin.id == theComp->vacantSpecies->getID() || adjoin.id == tempID)
        {
          Point adPoint(theSpatiocyteStepper->coord2point(aCoord));
          double dist(getDistance(&aPoint, &adPoint)); 
          if(dist <= offLatticeRadius && inMTCylinder(adPoint))
            { 
              offVoxel.adjoiningCoords[offVoxel.adjoiningSize++] = b; 
              initAdjoins(latVoxel);
              updateAdjoinSize(latVoxel);
              latVoxel.initAdjoins[latVoxel.adjoiningSize++] = a;
            }
        }
    }
}
void MicrotubuleProcess::enlistLatticeVoxels()
{
  for(unsigned int n(startCoord); n != endCoord; ++n)
    {
      Voxel& offVoxel((*theLattice)[n]);
      offVoxel.diffuseSize = offVoxel.adjoiningSize;
      double rA(theSpatiocyteStepper->getMinLatticeSpace());
      if(rA < offLatticeRadius)
        {
         rA = offLatticeRadius;
        } 
      Point center(*offVoxel.point);
      unsigned int aCoord(theSpatiocyteStepper->point2coord(center));
      Point cl(theSpatiocyteStepper->coord2point(aCoord));
      //theSpecies[3]->addMolecule(aVoxel.coord);
      Point bottomLeft(*offVoxel.point);
      Point topRight(*offVoxel.point);
      bottomLeft.x -= rA+center.x-cl.x+theSpatiocyteStepper->getColLength();
      bottomLeft.y -= rA+center.y-cl.y+theSpatiocyteStepper->getLayerLength();
      bottomLeft.z -= rA+center.z-cl.z+theSpatiocyteStepper->getRowLength();
      topRight.x += rA+cl.x-center.x+theSpatiocyteStepper->getColLength()*1.5;
      topRight.y += rA+cl.y-center.y+theSpatiocyteStepper->getLayerLength()*1.5;
      topRight.z += rA+cl.z-center.z+theSpatiocyteStepper->getRowLength()*1.5;
      unsigned int blRow(0);
      unsigned int blLayer(0);
      unsigned int blCol(0);
      theSpatiocyteStepper->point2global(bottomLeft, blRow, blLayer, blCol);
      unsigned int trRow(0);
      unsigned int trLayer(0);
      unsigned int trCol(0);
      theSpatiocyteStepper->point2global(topRight, trRow, trLayer, trCol);
      std::vector<unsigned int> checkedAdjoins;
      for(unsigned int i(blRow); i < trRow; ++i)
        {
          for(unsigned int j(blLayer); j < trLayer; ++j)
            {
              for(unsigned int k(blCol); k < trCol; ++k)
                {
                  unsigned int lat(theSpatiocyteStepper->global2coord(i, j, k));
                  Voxel& latVoxel((*theLattice)[lat]);
                  if(latVoxel.id != theSpatiocyteStepper->getNullID())
                    {
                      //theSpecies[3]->addMolecule(latVoxel);
                      Point aPoint(theSpatiocyteStepper->coord2point(lat));
                      if(inMTCylinder(aPoint))
                        {
                          for(unsigned int l(0); l != theAdjoiningCoordSize;
                              ++l)
                            {
                              unsigned adj(latVoxel.adjoiningCoords[l]);
                              Voxel& adjoin((*theLattice)[adj]);
                              if(adjoin.id == theComp->vacantSpecies->getID())
                                {
                                  checkedAdjoins.push_back(adj);
                                  addDirect(offVoxel, n, adjoin, adj);
                                }
                            }
                        }
                    }
                }
            }
        }
      for(unsigned int i(0); i != checkedAdjoins.size(); ++i)
        {
          (*theLattice)[checkedAdjoins[i]].id = theComp->vacantSpecies->getID();
        }
    }
  for(unsigned int i(0); i != occCoords.size(); ++i)
    {
      Voxel& aVoxel((*theLattice)[occCoords[i]]);
      unsigned int* temp = aVoxel.initAdjoins;
      aVoxel.initAdjoins = aVoxel.adjoiningCoords;
      aVoxel.adjoiningCoords = temp;
      aVoxel.diffuseSize = aVoxel.adjoiningSize;
    }
  for(unsigned int i(0); i != occCoords.size(); ++i)
    {
      Voxel& aVoxel((*theLattice)[occCoords[i]]);
      for(unsigned int i(0); i != aVoxel.adjoiningSize; ++i)
        {
          unsigned int aCoord(aVoxel.adjoiningCoords[i]);
          Voxel& adjoin((*theLattice)[aCoord]);
          if(adjoin.id == theComp->vacantSpecies->getID())
            {
              Point adPoint(theSpatiocyteStepper->coord2point(aCoord));
              if(inMTCylinder(adPoint))
                {
                  std::cout << "error in MT Process" << std::endl;
                }
            }
          else if(adjoin.id != theVacantSpecies->getID() &&
                  adjoin.id != theMinusSpecies->getID() &&
                  adjoin.id != thePlusSpecies->getID() &&
                  adjoin.id != theSpatiocyteStepper->getNullID())
            {
              std::cout << "species error in MT Process" << std::endl;
            }
        }
    }
}
Beispiel #10
0
void CardView::keyPressEvent( QKeyEvent *e )
{
  if ( !(childCount() && d->mCurrentItem) ) {
    e->ignore();
    return;
  }

  uint pos = d->mItemList.findRef( d->mCurrentItem );
  CardViewItem *aItem = 0;
  CardViewItem *old = d->mCurrentItem;

  switch ( e->key() ) {
    case Qt::Key_Up:
      if ( pos > 0 ) {
        aItem = d->mItemList.at( pos - 1 );
        setCurrentItem( aItem );
      }
      break;
    case Qt::Key_Down:
      if ( pos < d->mItemList.count() - 1 ) {
        aItem = d->mItemList.at( pos + 1 );
        setCurrentItem( aItem );
      }
      break;
    case Qt::Key_Left:
    {
      // look for an item in the previous/next column, starting from
      // the vertical middle of the current item.
      // FIXME use nice calculatd measures!!!
      QPoint aPoint( d->mCurrentItem->d->x, d->mCurrentItem->d->y );
      aPoint -= QPoint( 30, -(d->mCurrentItem->height() / 2) );
      aItem = itemAt( aPoint );
      // maybe we hit some space below an item
      while ( !aItem && aPoint.y() > 27 ) {
        aPoint -= QPoint( 0, 16 );
        aItem = itemAt( aPoint );
      }
      if ( aItem )
        setCurrentItem( aItem );

      break;
    }
    case Qt::Key_Right:
    {
      // FIXME use nice calculated measures!!!
      QPoint aPoint( d->mCurrentItem->d->x + d->mItemWidth, d->mCurrentItem->d->y );
      aPoint += QPoint( 30, (d->mCurrentItem->height() / 2) );
      aItem = itemAt( aPoint );
      while ( !aItem && aPoint.y() > 27 ) {
        aPoint -= QPoint( 0, 16 );
        aItem = itemAt( aPoint );
      }
      if ( aItem )
        setCurrentItem( aItem );

      break;
    }
    case Qt::Key_Home:
      aItem = d->mItemList.first();
      setCurrentItem( aItem );
      break;
    case Qt::Key_End:
      aItem = d->mItemList.last();
      setCurrentItem( aItem );
      break;
    case Qt::Key_PageUp: // PageUp
    {
      // QListView: "Make the item above the top visible and current"
      // TODO if contentsY(), pick the top item of the leftmost visible column
      if ( contentsX() <= 0 )
        return;
      int cw = columnWidth();
      int theCol = ( qMax( 0, ( contentsX() / cw) * cw ) ) + d->mItemSpacing;
      aItem = itemAt( QPoint( theCol + 1, d->mItemSpacing + 1 ) );
      if ( aItem )
        setCurrentItem( aItem );

      break;
    }
    case Qt::Key_PageDown:  // PageDown
    {
      // QListView: "Make the item below the bottom visible and current"
      // find the first not fully visible column.
      // TODO: consider if a partly visible (or even hidden) item at the
      //       bottom of the rightmost column exists
      int cw = columnWidth();
      int theCol = ( (( contentsX() + visibleWidth() ) / cw) * cw ) + d->mItemSpacing + 1;
      // if separators are on, we may need to we may be one column further right if only the spacing/sep is hidden
      if ( d->mDrawSeparators && cw - (( contentsX() + visibleWidth() ) % cw) <= int( d->mItemSpacing + d->mSepWidth ) )
        theCol += cw;

      // make sure this is not too far right
      while ( theCol > contentsWidth() )
        theCol -= columnWidth();

      aItem = itemAt( QPoint( theCol, d->mItemSpacing + 1 ) );

      if ( aItem )
        setCurrentItem( aItem );

      break;
    }
    case Qt::Key_Space:
      setSelected( d->mCurrentItem, !d->mCurrentItem->isSelected() );
      emit selectionChanged();
      break;
    case Qt::Key_Return:
    case Qt::Key_Enter:
      emit returnPressed( d->mCurrentItem );
      emit executed( d->mCurrentItem );
      break;
    case Qt::Key_Menu:
      emit contextMenuRequested( d->mCurrentItem, viewport()->mapToGlobal(
                                 itemRect(d->mCurrentItem).center() ) );
      break;
    default:
      if ( (e->modifiers() & Qt::ControlModifier) && e->key() == Qt::Key_A ) {
        // select all
        selectAll( true );
        break;
      } else if ( !e->text().isEmpty() && e->text()[ 0 ].isPrint() ) {
        // if we have a string, do autosearch
      }
      break;
  }

  // handle selection
  if ( aItem ) {
    if ( d->mSelectionMode == CardView::Extended ) {
      if ( e->modifiers() & Qt::ShiftModifier ) {
        // shift button: toggle range
        // if control button is pressed, leave all items
        // and toggle selection current->old current
        // otherwise, ??????
        bool s = ! aItem->isSelected();
        int from, to, a, b;
        a = d->mItemList.findRef( aItem );
        b = d->mItemList.findRef( old );
        from = a < b ? a : b;
        to = a > b ? a : b;

        if ( to - from > 1 ) {
          bool b = signalsBlocked();
          blockSignals( true );
          selectAll( false );
          blockSignals( b );
        }

        CardViewItem *item;
        for ( ; from <= to; ++from ) {
          item = d->mItemList.at( from );
          item->setSelected( s );
          repaintItem( item );
        }

        emit selectionChanged();
      } else if ( e->modifiers() & Qt::ControlModifier ) {
        // control button: do nothing
      } else {
        // no button: move selection to this item
        bool b = signalsBlocked();
        blockSignals( true );
        selectAll( false );
        blockSignals( b );

        setSelected( aItem, true );
        emit selectionChanged();
      }
    }
  }
}
void MoleculePopulateProcess::populateUniformRanged(Species* aSpecies)
{
  Comp* aComp(aSpecies->getComp());
  double delta(0);
  // Increase the compartment dimensions by delta if it is a surface 
  // compartment:
  if(aComp->dimension == 2)
    {
      delta = 0.1;
    }
  double maxX(std::min(1.0, OriginX+UniformRadiusX));
  double minX(std::max(-1.0, OriginX-UniformRadiusX));
  double maxY(std::min(1.0, OriginY+UniformRadiusY));
  double minY(std::max(-1.0, OriginY-UniformRadiusY));
  double maxZ(std::min(1.0, OriginZ+UniformRadiusZ));
  double minZ(std::max(-1.0, OriginZ-UniformRadiusZ)); 
  maxX = aComp->centerPoint.x + maxX*aComp->lengthX/2*(1+delta);
  minX = aComp->centerPoint.x + minX*aComp->lengthX/2*(1+delta);
  maxY = aComp->centerPoint.y + maxY*aComp->lengthY/2*(1+delta);
  minY = aComp->centerPoint.y + minY*aComp->lengthY/2*(1+delta);
  maxZ = aComp->centerPoint.z + maxZ*aComp->lengthZ/2*(1+delta);
  minZ = aComp->centerPoint.z + minZ*aComp->lengthZ/2*(1+delta);
  std::vector<unsigned int> aCoords;
  for(std::vector<unsigned int>::iterator i(aComp->coords.begin());
      i != aComp->coords.end(); ++i)
    {
      Voxel* aVoxel(theSpatiocyteStepper->coord2voxel(*i));
      Point aPoint(theSpatiocyteStepper->coord2point(aVoxel->coord));
      if(aVoxel->id == aSpecies->getVacantID() &&
         aPoint.x < maxX && aPoint.x > minX &&
         aPoint.y < maxY && aPoint.y > minY &&
         aPoint.z < maxZ && aPoint.z > minZ)
        {
          aCoords.push_back(*i);
        }
    }
  unsigned int aSize(aSpecies->getPopulateMoleculeSize());
  if(aCoords.size() < aSize)
    {
      THROW_EXCEPTION(ValueError, String(
                      getPropertyInterface().getClassName()) +
                      "[" + getFullID().asString() + "]: There are " +
                      int2str(aSize) + " " + getIDString(aSpecies) +
                      " molecules that must be uniformly populated in a " +
                      "given range,\n but there are only " +
                      int2str(aCoords.size()) + " vacant voxels of " +
                      getIDString(aSpecies->getVacantSpecies()) +
                      " that can be populated.");
    }
  unsigned int aCoordsArray[aCoords.size()]; 
  for(unsigned int i(0); i != aCoords.size(); ++i)
    {
      aCoordsArray[i] = aCoords[i];
    }
  gsl_ran_shuffle(getStepper()->getRng(), aCoordsArray, aCoords.size(),
                  sizeof(unsigned int));
  for(unsigned int i(0); i != aSize; ++i)
    {
      aSpecies->addMolecule(theSpatiocyteStepper->coord2voxel(aCoordsArray[i]));
    }
}