Main Page | Namespace List | Class Hierarchy | Class List | Directories | File List | Class Members | File Members

LayerManager.cpp

Go to the documentation of this file.
00001 /***************************************************************************
00002  *   SpikeStream Application                                               *
00003  *   Copyright (C) 2007 by David Gamez                                     *
00004  *   david@davidgamez.eu                                                   *
00005  *   Version 0.1                                                           *
00006  *                                                                         *
00007  *   This program is free software; you can redistribute it and/or modify  *
00008  *   it under the terms of the GNU General Public License as published by  *
00009  *   the Free Software Foundation; either version 2 of the License, or     *
00010  *   (at your option) any later version.                                   *
00011  *                                                                         *
00012  *   This program is distributed in the hope that it will be useful,       *
00013  *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
00014  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
00015  *   GNU General Public License for more details.                          *
00016  *                                                                         *
00017  *   You should have received a copy of the GNU General Public License     *
00018  *   along with this program; if not, write to the                         *
00019  *   Free Software Foundation, Inc.,                                       *
00020  *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
00021  ***************************************************************************/
00022 
00023 //SpikeStream includes
00024 #include "LayerManager.h"
00025 #include "Debug.h"
00026 #include "Utilities.h"
00027 #include "NeuronGroupType.h"
00028 #include "GlobalVariables.h"
00029 #include "DeviceTypes.h"
00030 
00031 //Other includes
00032 #include <cmath>
00033 #include <iostream>
00034 using namespace std;
00035 using namespace mysqlpp;
00036 
00037 
00038 /*! Exception thrown when there is an error creating connections. */
00039 class EditNeuronGroupException : public exception{
00040   virtual const char* what() const throw(){
00041     return "Error during editing of neuron group.";
00042   }
00043 } editNeuronGroupException;
00044 
00045 
00046 /*! Constructor. */
00047 LayerManager::LayerManager(DBInterface *netDBInter, DBInterface* devDBInter){
00048         //Store reference to the database
00049         networkDBInterface = netDBInter;
00050         deviceDBInterface = devDBInter;
00051 
00052         //Initialize the random number generator with the seed
00053         srand(randomSeed);
00054         
00055         //Create a progress dialog
00056         progressDialog = new QProgressDialog(0, "Creating layers", true);
00057 } 
00058 
00059 
00060 /*! Destructor. */
00061 LayerManager::~LayerManager(){
00062         #ifdef MEMORY_DEBUG
00063                 cout<<"DELETING LAYER MANAGER!"<<endl;
00064         #endif//MEMORY_DEBUG
00065         
00066         delete progressDialog;
00067 }
00068 
00069 
00070 //----------------------------------------------------------------------------------
00071 //--------------------------------- PUBLIC METHODS ---------------------------------
00072 //----------------------------------------------------------------------------------
00073 
00074 /*! This method creates layers in the database
00075         Initially only handle rectangular layers. Other shapes could be added later if necessary.
00076         Progress dialog is used to keep track of progress with large layers, which can take some time. */
00077 int LayerManager::createLayer(const NeuronGroup &neuronGrp){
00078         //Create appropriate connections        
00079         //Work on assumption that LayerPropertiesDialog has done checking on compatibility etc.
00080         switch(neuronGrp.neuronGrpType){
00081                 case (NeuronGroupType::RectangularLayer2D):
00082                         return create2DRectangularLayer(neuronGrp);
00083                 case (NeuronGroupType::RectangularLayer3D):
00084                         return create3DRectangularLayer(neuronGrp);
00085                 case (NeuronGroupType::SIMNOSComponentLayer):
00086                         return createSIMNOSComponentLayer(neuronGrp);
00087                 default:
00088                         cerr<<"CONNECTION TYPE NOT RECOGNIZED"<<endl;
00089                         return -1;
00090         }
00091 }
00092 
00093 
00094 /*! Deletes layer from the database. */
00095 void LayerManager::deleteLayers(vector<unsigned int> layerIDs){
00096         Query query = networkDBInterface->getQuery();
00097         
00098         vector<unsigned int>::iterator iter;
00099         for(iter = layerIDs.begin(); iter < layerIDs.end(); ++iter){
00100                 //First delete information about the layer from the layer table
00101                 query.reset();
00102                 query<<"DELETE FROM NeuronGroups WHERE NeuronGrpID=\'"<<*iter<<"\'";
00103                 query.execute();
00104                 
00105                 //Next delete neurons from neuron table
00106                 query.reset();
00107                 query<<"DELETE FROM Neurons WHERE NeuronGrpID=\'"<<*iter<<"\'";
00108                 query.execute();
00109 
00110                 //Delete neuron parameters for this neuron group
00111                 /* Simpler just to delete neuron group from all parameter tables than to query the
00112                          id and then delete it from the appropriate table */
00113                 query.reset();
00114                 query<<"SELECT ParameterTableName FROM NeuronTypes";
00115                 Result tableNameRes = query.store();
00116                 for(Result::iterator paramTableIter = tableNameRes.begin(); paramTableIter != tableNameRes.end(); ++paramTableIter){
00117                         Row tableNameRow (*paramTableIter);
00118                         query.reset();
00119                         query<<"DELETE FROM "<<(std::string)tableNameRow["ParameterTableName"]<<" WHERE NeuronGrpID= "<<*iter;
00120                         query.execute();
00121                 }
00122 
00123                 //Delete noise parameters for this neuron group
00124                 query.reset();
00125                 query<<"DELETE FROM NoiseParameters WHERE NeuronGrpID=\'"<<*iter<<"\'";
00126                 query.execute();
00127         }
00128 }
00129 
00130 
00131 /*! Passes a reference to connection widget that is used when creating 
00132         SIMNOS component layers. */
00133 void LayerManager::setConnectionWidget(ConnectionWidget* connWidg){
00134         connectionWidget = connWidg;
00135 }
00136 
00137 
00138 /*! Sets the name of a layer. Called during layer editing mode
00139         Name does not conflict with anything else so no checks need to be run. */
00140 void LayerManager::setNeuronGrpName(unsigned int neuronGrpID, QString name){
00141         Query query = networkDBInterface->getQuery();
00142         query.reset();
00143         query<<"UPDATE NeuronGroups SET Name = \""<<name<<"\" WHERE NeuronGrpID = "<<neuronGrpID;
00144         query.execute();
00145 }
00146 
00147 
00148 /*! Alters the spacing between neurons and the position of a neuron group
00149         This could potentially expand the layer to conflict with other layers, so need to check first
00150         False is returned if there is a conflict. */
00151 bool LayerManager::setNeuronGrpSpacingPosition(const unsigned int neuronGrpID, const NeuronGroup &oldNeurGrp, const NeuronGroup &newNeurGrp){
00152         //Check for conflicts with existing layers. Do not want two neurons at same location
00153         //At present layers are organised along the z axis. 
00154         //If there is already a layer at this z position, need to see if proposed layer will overlap
00155         int actualWidth = newNeurGrp.spacing * (newNeurGrp.width - 1);
00156         int actualLength = newNeurGrp.spacing * (newNeurGrp.length - 1);
00157                 
00158         //Get all layers with this z coordinate
00159         Query query = networkDBInterface->getQuery();
00160         query.reset();
00161         query<<"SELECT NeuronID FROM Neurons WHERE X >="<<newNeurGrp.xPos<<" AND X <= "<<(newNeurGrp.xPos+actualWidth)<<" AND Y >= "<<newNeurGrp.yPos<<" AND Y <= "<<(newNeurGrp.yPos + actualLength)<<" AND Z = "<<newNeurGrp.zPos<<" AND NeuronGrpID != "<<neuronGrpID;
00162         Result layerResult = query.store();
00163         if(layerResult.size() > 0)
00164                 return false;
00165         
00166         //If have reached this point in the program, the new neuron spacing and position should be ok
00167 
00168         /*Need to relocate all of the neurons
00169                 This uses the same method as was used to create the neurons
00170                 The old location and neuron spacing is used to find the original neurons, 
00171                 and their locations are updated.
00172                 Use neuronNumber as a check that only the relevant neuron is being updated since there is a 
00173                 chance that two neurons could be at the same location during the update process.*/
00174 
00175         //First get the first neuron Id in the group
00176         query.reset();
00177         query<<"SELECT MIN(NeuronID) FROM Neurons WHERE NeuronGrpID = "<<neuronGrpID;
00178         Result minNeuronIDRes = query.store();
00179         Row minNeuronIDRow(*minNeuronIDRes.begin());//Should only be one result
00180 
00181         //Initialise neuronIDCount
00182         unsigned int startNeuronID = Utilities::getUInt((std::string)minNeuronIDRow["MIN(NeuronID)"]);
00183         unsigned int neuronIDCount = startNeuronID;
00184         
00185         //Start up the progress dialog with the appropriate number of steps
00186         progressDialog->setTotalSteps(newNeurGrp.width*newNeurGrp.length);
00187         progressDialog->setLabelText("Updating Layer");
00188         int progressCounter = 0;
00189         
00190         //Work through the layers in the same way that was done when it was created
00191         for(unsigned int i=0; i<newNeurGrp.length; ++i){
00192                 for(unsigned int j=0; j<newNeurGrp.width; ++j){
00193                         query.reset();
00194                         query<<"UPDATE Neurons SET X = "<<(newNeurGrp.xPos + (j*newNeurGrp.spacing))<<", Y = "<<(newNeurGrp.yPos + (i*newNeurGrp.spacing))<<", Z = "<<newNeurGrp.zPos<<" WHERE X = "<<(oldNeurGrp.xPos + (j*oldNeurGrp.spacing))<<" AND Y = "<<(oldNeurGrp.yPos + (i*oldNeurGrp.spacing))<<" AND Z = "<<oldNeurGrp.zPos<<" AND NeuronID = "<<neuronIDCount;
00195                         
00196                         ResNSel updateResult = query.execute();
00197                         /*Check that neuron has been updated. For spacing changes, the first neuron 
00198                                 will not be changed so ignore it for this check */
00199                         if(updateResult.rows == 1 || neuronIDCount == startNeuronID){
00200                                 ++neuronIDCount;
00201                                 ++progressCounter;
00202                                 if(progressCounter % 100 == 0)
00203                                         progressDialog->setProgress(progressCounter);
00204                         }
00205                         else{
00206                                 cerr<<"LayerManager: NEURON HAS BEEN PASSED OVER DURING SPACING/POSITION CHANGE. NEURONGROUP: "<<neuronGrpID<<"; i="<<i<<"; j="<<j<<"; neuronIDCount="<<neuronIDCount<<endl;
00207                                 cerr<<"Old Neuron group holder: x="<<oldNeurGrp.xPos<<"; y="<<oldNeurGrp.yPos<<"; z="<<oldNeurGrp.zPos<<"; spacing="<<oldNeurGrp.spacing<<"; width="<<oldNeurGrp.width<<"; length="<<oldNeurGrp.length<<endl;
00208                                 cerr<<"New Neuron group holder: x="<<newNeurGrp.xPos<<"; y="<<newNeurGrp.yPos<<"; z="<<newNeurGrp.zPos<<"; spacing="<<newNeurGrp.spacing<<"; width="<<newNeurGrp.width<<"; length="<<newNeurGrp.length<<endl;
00209                                 throw editNeuronGroupException;
00210                         }
00211                 }
00212         }
00213         progressDialog->reset();
00214         
00215         //Update neuron spacing in the neuron group table
00216         query.reset();
00217         query<<"UPDATE NeuronGroups SET Spacing = "<<newNeurGrp.spacing<<" WHERE NeuronGrpID = "<<neuronGrpID;
00218         query.execute();
00219         
00220         //Update neuron group position in the neuron group table
00221         query<<"UPDATE NeuronGroups SET X = "<<newNeurGrp.xPos<<", Y = "<<newNeurGrp.yPos<<", Z = "<<newNeurGrp.zPos<<" WHERE NeuronGrpID = "<<neuronGrpID;
00222         query.execute();
00223         return true;
00224 }
00225 
00226 
00227 /*! Sets the type of neuron in a layer.
00228         Neuron type does not conflict with anything else, so no checks need to be run. */
00229 void LayerManager::setNeuronGrpType(unsigned int neuronGrpID, unsigned short neuronType){
00230         try{
00231                 Query query = networkDBInterface->getQuery();
00232                 query.reset();
00233         
00234                 //First set the type in the neuron group
00235                 query<<"UPDATE NeuronGroups SET NeuronType = "<<neuronType<<" WHERE NeuronGrpID = "<<neuronGrpID;
00236                 query.execute();
00237         
00238                 //Now need to sort out the parameters
00239                 //Delete entries for this neuron group from parameter tables and add an entry in the appropriate place
00240                 query.reset();
00241                 query<<"SELECT TypeID, ParameterTableName FROM NeuronTypes";
00242                 Result neurTypesRes = query.store();
00243                 for(Result::iterator iter = neurTypesRes.begin(); iter != neurTypesRes.end(); ++iter){
00244                         Row neurTypeRow (*iter);
00245                         unsigned short neuronTypeID = Utilities::getUShort((std::string) neurTypeRow["TypeID"]);
00246                         
00247                         //Delete entry if it exists
00248                         query.reset();
00249                         query<<"DELETE FROM "<<(std::string)neurTypeRow["ParameterTableName"]<<" WHERE NeuronGrpID = "<<neuronGrpID;
00250                         query.execute();
00251                         
00252                         //Add this neuron group to the parameter table
00253                         if(neuronTypeID == neuronType){
00254                                 query.reset();
00255                                 query<<"INSERT INTO "<<(std::string)neurTypeRow["ParameterTableName"]<<"(NeuronGrpID) VALUES("<<neuronGrpID<<")";
00256                                 query.execute();
00257                         }
00258                 }
00259         }
00260         catch(Exception ex){
00261                 cerr<<"Exception thrown whilst setting the neuron group type: "<<ex.what()<<endl;
00262         }
00263 }
00264 
00265 
00266 //-------------------------------------------------------------------------------
00267 //------------------------------ PRIVATE METHODS --------------------------------
00268 //-------------------------------------------------------------------------------
00269 
00270 /*! Creates a 2D rectangular layer. */
00271 int LayerManager::create2DRectangularLayer(const NeuronGroup &neuronGrp){
00272         //First set up the progress dialog with the appropriate number of steps
00273         progressDialog->reset();
00274         progressDialog->setTotalSteps(neuronGrp.width*neuronGrp.length);
00275         
00276         //Method starts by checking for conflicts with existing layers. Do not want two neurons at same location
00277         bool layerConflict = false;
00278 
00279         //At present layers are organised along the z axis. 
00280         //If there is already a layer at this z position, need to see if proposed layer will overlap
00281         int actualWidth = neuronGrp.spacing * (neuronGrp.width - 1);
00282         int actualLength = neuronGrp.spacing * (neuronGrp.length - 1);
00283                 
00284         //Get all layers with this z coordinate
00285         Query query = networkDBInterface->getQuery();
00286         query.reset();
00287         query<<"SELECT NeuronID FROM Neurons WHERE X >="<<neuronGrp.xPos<<" AND X <= "<<(neuronGrp.xPos+actualWidth)<<" AND Y >= "<<neuronGrp.yPos<<" AND Y <= "<<(neuronGrp.yPos + actualLength)<<" AND Z = "<<neuronGrp.zPos;
00288         Result zLayerResult = query.store();
00289         if(zLayerResult.size() >0){
00290                 layerConflict = true;
00291                 cout<<"CONFLICT WITH EXISTING LAYERS"<<endl;
00292                 progressDialog->reset();
00293                 return -1;
00294         }
00295 
00296         //Only reach this point if there are no conflicts with existing layers
00297         //Add layer entry to layer database
00298         query.reset();
00299     query<<"INSERT INTO NeuronGroups (Name, NeuronGrpType, NeuronType, X, Y, Z, Width, Length, Spacing, TaskID) VALUES (\""<<neuronGrp.name<<"\", "<<neuronGrp.neuronGrpType<<", "<<neuronGrp.neuronType<<", "<<neuronGrp.xPos<<", "<<neuronGrp.yPos<<", "<<neuronGrp.zPos<<", "<<neuronGrp.width<<", "<<neuronGrp.length<<", "<<neuronGrp.spacing<<", -1)";
00300         query.execute();
00301         
00302         //Now need to get the automatically generated NeuronGrpID so that it can be added to the neurons in the new layers
00303         query.reset();
00304         query<<"SELECT MAX(NeuronGrpID) from NeuronGroups";
00305         Result grpIDResult = query.store();
00306         Row row(*(grpIDResult.begin()));
00307         unsigned int neuronGrpID = row.at(0);
00308                         
00309         /* Add neurons to neuron database. 
00310                 This adds them in a scanning pattern moving horizontally along the x axis 
00311                 before moving to the next line */
00312         int neuronCount = 0;
00313         for(unsigned int i=0; i<neuronGrp.length; ++i){
00314                 for(unsigned int j=0; j<neuronGrp.width; ++j){
00315                         query.reset();
00316                         query<<"INSERT INTO Neurons (X, Y, Z, NeuronGrpID) VALUES ("<<(neuronGrp.xPos + (j*neuronGrp.spacing))<<", "<<(neuronGrp.yPos + (i*neuronGrp.spacing))<<", "<<neuronGrp.zPos<<", "<<neuronGrpID<<")";
00317                         query.execute();
00318                         ++neuronCount;
00319                         if(neuronCount % 100 == 0)
00320                                 progressDialog->setProgress(neuronCount);
00321                         if(progressDialog->wasCancelled())
00322                                 break;
00323                 }
00324         }
00325 
00326         /* Add entry for this layer to the neuron parameters database */
00327         //Find the appropriate table
00328         query.reset();
00329         query<<"SELECT ParameterTableName FROM NeuronTypes WHERE TypeID = "<<neuronGrp.neuronType;
00330         Result tableNameRes = query.store();
00331         Row tableNameRow (*tableNameRes.begin());//Should only be 1 row
00332         
00333         //Now add an entry for this neuron group to the appropriate table
00334         query.reset();
00335         query<<"INSERT INTO "<<(std::string)tableNameRow["ParameterTableName"]<<" (NeuronGrpID) VALUES ("<<neuronGrpID<<")";
00336         query.execute();
00337 
00338         //Add entry for this layer to the noise parameters table
00339         query.reset();
00340         query<<"INSERT INTO NoiseParameters (NeuronGrpID) VALUES ("<<neuronGrpID<<")";
00341         query.execute();
00342 
00343         //Hide progress dialog
00344         progressDialog->cancel();
00345 
00346         return neuronGrpID;
00347 }
00348 
00349 
00350 /*! Create a 3D rectangular layer. */
00351 int LayerManager::create3DRectangularLayer(const NeuronGroup &neuronGrp){
00352         //Parameters for the connection - will have to be set dynamically at some point
00353         unsigned int depth = 5;//3D box with this depth
00354         double density = 0.5;//Number of neurons per point within the box
00355 
00356         //Set up the progress dialog with the appropriate number of steps. This is a guess because of the random element in creating the layer
00357         unsigned int totalSteps = (unsigned int) ((double)neuronGrp.width * (double)neuronGrp.length * (double)depth * density);
00358         progressDialog->setTotalSteps(totalSteps);
00359 
00360         //Add layer entry to layer database
00361         Query query = networkDBInterface->getQuery();
00362         query.reset();
00363     query<<"INSERT INTO NeuronGroups (Name, NeuronGrpType, NeuronType, X, Y, Z, Width, Length, Spacing, TaskID) VALUES (\""<<neuronGrp.name<<"\", "<<neuronGrp.neuronGrpType<<", "<<neuronGrp.neuronType<<", "<<neuronGrp.xPos<<", "<<neuronGrp.yPos<<", "<<neuronGrp.zPos<<", "<<neuronGrp.width<<", "<<neuronGrp.length<<", "<<neuronGrp.spacing<<", -1)";
00364         query.execute();
00365 
00366         //Get the automatically generated NeuronGrpID so that it can be added to the neurons in the new layers
00367         query.reset();
00368         query<<"SELECT MAX(NeuronGrpID) from NeuronGroups";
00369         Result grpIDResult = query.store();
00370         Row row(*(grpIDResult.begin()));
00371         unsigned int neuronGrpID = Utilities::getUInt((std::string)row["MAX(NeuronGrpID)"]);
00372         unsigned int neuronCount = 0;
00373 
00374         //Work through each point in the box and add the neuron if necessary.
00375         for(int zPos = neuronGrp.zPos; zPos < (int)(neuronGrp.zPos + depth); ++zPos){
00376                 for(int yPos = neuronGrp.yPos; yPos < (int)(neuronGrp.yPos + neuronGrp.length); ++yPos){
00377                         for(int xPos = neuronGrp.xPos; xPos < (int)(neuronGrp.xPos + neuronGrp.width); ++xPos){
00378                                 //Decide if a neuron should be placed or not
00379                                 if(evaluatePlaceNeuronProbability(density)){
00380                                         //Check neuron does not exist at this location
00381                                         query.reset();
00382                                         query<<"SELECT NeuronID From Neurons WHERE X = "<<xPos<<" AND Y = "<<yPos<<" AND Z = "<<zPos;
00383                                         Result alreadyExistsResult = query.store();
00384                                         if(alreadyExistsResult.size() == 0){
00385                                                 //Add entry for neuron to database
00386                                                 query.reset();
00387                                                 query<<"INSERT INTO Neurons (X, Y, Z, NeuronGrpID) VALUES ("<<xPos<<", "<<yPos<<", "<<zPos<<", "<<neuronGrpID<<")";
00388                                                 query.execute();
00389                                                 ++neuronCount;
00390                                                 if(neuronCount % 100 == 0)
00391                                                         progressDialog->setProgress(neuronCount);
00392                                                 if(progressDialog->wasCancelled())
00393                                                         break;
00394                                         }
00395                                 }
00396                         }
00397                 }
00398         }
00399 
00400         //Hide progress dialog
00401         progressDialog->setProgress(totalSteps);
00402 
00403         //Check that at least one neurons has been added
00404         if(neuronCount <= 0){
00405                 cout<<"LayerManager: No neurons have been created, probably due to conflicts with existing neurons"<<endl;
00406                 query.reset();
00407                 query<<"DELETE FROM NeuronGroups WHERE NeuronGrpID = "<<neuronGrpID;
00408                 query.execute();
00409                 return -1;
00410         }
00411 
00412 
00413         /* Add entry for this layer to the neuron parameters database */
00414         //Find the appropriate table
00415         query.reset();
00416         query<<"SELECT ParameterTableName FROM NeuronTypes WHERE TypeID = "<<neuronGrp.neuronType;
00417         Result tableNameRes = query.store();
00418         Row tableNameRow (*tableNameRes.begin());//Should only be 1 row
00419         
00420         //Now add an entry for this neuron group to the appropriate table
00421         query.reset();
00422         query<<"INSERT INTO "<<(std::string)tableNameRow["ParameterTableName"]<<" (NeuronGrpID) VALUES ("<<neuronGrpID<<")";
00423         query.execute();
00424 
00425         //Add entry for this layer to the noise parameters table
00426         query.reset();
00427         query<<"INSERT INTO NoiseParameters (NeuronGrpID) VALUES ("<<neuronGrpID<<")";
00428         query.execute();
00429 
00430         //Hide progress dialog
00431         progressDialog->cancel();
00432 
00433         return neuronGrpID;
00434 }
00435 
00436 
00437 /*! Creates a layer for a component of SIMNOS with appropriate connections
00438         to the device input layer. */
00439 int LayerManager::createSIMNOSComponentLayer(const NeuronGroup &neuronGrp){
00440         //Create a 2D rectangular layer using method in this class
00441         int neuronGrpID = this->create2DRectangularLayer(neuronGrp);
00442 
00443         //Check layer has been created
00444         if(neuronGrpID < 0){
00445                 cerr<<"LayerManager: FAILED TO CREATE LAYER WHILST CREATING SIMNOS COMPONENT LAYER"<<endl;
00446                 return neuronGrpID;
00447         }
00448 
00449         //Find out if it is an input or output device
00450         Query deviceQuery = deviceDBInterface->getQuery();
00451         deviceQuery.reset();
00452         deviceQuery<<"SELECT ReceptorIDs FROM SIMNOSComponents WHERE ComponentID = "<<neuronGrp.componentID;
00453         Result simnosRes = deviceQuery.store();
00454         Row simnosRow (*simnosRes.begin());//Component ID should be unique
00455                 
00456         //Extract the first receptor id in the list
00457         //NOTE THIS ASSUMES THAT ALL OF THE RECEPTORS ARE FROM THE SAME DEVICE
00458         QString receptorIDString = (std::string)simnosRow["ReceptorIDs"];
00459         if(receptorIDString.isEmpty()){
00460                 cerr<<"LayerManager: NO RECEPTOR IDS FOR THIS COMPONENT"<<endl;
00461                 return neuronGrpID;
00462         }
00463 
00464         //Get the receptor ID - converting to int is a good check
00465         unsigned int firstReceptorID = Utilities::getUInt(receptorIDString.section(',', 0, 0).ascii());
00466         
00467         deviceQuery.reset();
00468         deviceQuery<<"SELECT DeviceDescription FROM SIMNOSSpikeReceptors WHERE ReceptorID = "<<firstReceptorID;
00469         Result receptorDevDesRes = deviceQuery.store();
00470         Row receptorDevDesRow(*receptorDevDesRes.begin());//ReceptorID should be unique
00471 
00472         //Now get device type from database
00473         deviceQuery.reset();
00474         deviceQuery<<"SELECT Type FROM Devices WHERE Description = \""<<((std::string) receptorDevDesRow["DeviceDescription"])<<"\"";
00475         Result devTypeRes = deviceQuery.store();
00476         Row devTypeRow(*devTypeRes.begin());//Description should be unique
00477         unsigned int deviceType = Utilities::getUInt((std::string)devTypeRow["Type"]);
00478 
00479         /* Instruct connectionWidget to launch the dialog so user can 
00480                 select the connection options */
00481         if(DeviceTypes::isInputDevice(deviceType))//Create connections from device
00482                 connectionWidget->createConnections(neuronGrp.deviceNeuronGrpID, neuronGrpID, neuronGrp.componentID, true);
00483         else
00484                 connectionWidget->createConnections(neuronGrpID, neuronGrp.deviceNeuronGrpID, neuronGrp.componentID, false);
00485 
00486         //Return the new neuronGrpID
00487         return neuronGrpID;
00488 }
00489 
00490 
00491 /*! Used to create layers that are not completely dense - especially
00492         the 3D layer. Decides whether neuron should be added at a particular
00493         point or not. */
00494 bool LayerManager::evaluatePlaceNeuronProbability(double density){
00495         int threshold = (int)(density * (double)RAND_MAX);
00496         if(rand() < threshold)
00497                 return true;
00498         return false;
00499 }
00500 
00501 

Generated on Mon Sep 3 22:29:04 2007 for SpikeStream Application by  doxygen 1.4.4