SpikeStream Application Library
0.2
|
00001 //SpikeStream includes 00002 #include "ConnectionsModel.h" 00003 #include "ConnectionsTableView.h" 00004 #include "Globals.h" 00005 #include "GlobalVariables.h" 00006 #include "NetworkDisplay.h" 00007 #include "EventRouter.h" 00008 #include "NetworkViewerProperties.h" 00009 #include "SpikeStreamException.h" 00010 using namespace spikestream; 00011 00012 //Qt includes 00013 #include <QButtonGroup> 00014 #include <QLayout> 00015 00016 00018 NetworkViewerProperties::NetworkViewerProperties(QWidget* parent) : QWidget(parent){ 00019 //Main vertical layout 00020 QVBoxLayout* mainVerticalBox = new QVBoxLayout(this); 00021 00022 //Set up check box to toggle full rendering of scene 00023 QHBoxLayout *renderBox = new QHBoxLayout(); 00024 renderCheckBox = new QCheckBox("Render high quality view", this); 00025 connect(renderCheckBox, SIGNAL(clicked()), this, SLOT(setRenderMode())); 00026 renderBox->addWidget(renderCheckBox); 00027 renderBox->addStretch(5); 00028 mainVerticalBox->addLayout(renderBox); 00029 00030 //Widget for full render controls 00031 fullRenderControlsWidget = new QWidget(); 00032 fullRenderControlsWidget->setEnabled(false); 00033 QVBoxLayout* fullRenConVBox = new QVBoxLayout(fullRenderControlsWidget); 00034 00035 //Slider for neuron transparency 00036 QHBoxLayout* transparencyBox = new QHBoxLayout(); 00037 QSlider* transparencySlider = new QSlider(Qt::Horizontal); 00038 transparencySlider->setRange(0, 1000); 00039 transparencySlider->setSliderPosition(1000); 00040 connect(transparencySlider, SIGNAL(sliderMoved(int)), this, SLOT(neuronTransparencyChanged(int))); 00041 transparencyBox->addWidget(new QLabel("Neuron opacity ")); 00042 transparencyBox->addWidget(transparencySlider); 00043 transparencyBox->addWidget(new QLabel("max")); 00044 transparencyBox->addStretch(5); 00045 fullRenConVBox->addLayout(transparencyBox); 00046 00047 //Weight rendering mode 00048 QHBoxLayout* weightRenderLayout = new QHBoxLayout(); 00049 QButtonGroup* weightButtonGroup = new QButtonGroup(); 00050 connect(weightButtonGroup, SIGNAL(buttonClicked(int)), this, SLOT(weightDisplayChanged(int))); 00051 QRadioButton* noWeightsButton = new QRadioButton("Positive/negative weights"); 00052 noWeightsButton->setChecked(true); 00053 weightButtonGroup->addButton(noWeightsButton, 0); 00054 weightRenderLayout->addWidget(noWeightsButton); 00055 QRadioButton* currentWeightsButton = new QRadioButton("Current weights"); 00056 weightButtonGroup->addButton(currentWeightsButton, 1); 00057 weightRenderLayout->addWidget(currentWeightsButton); 00058 QRadioButton* tempWeightsButton = new QRadioButton("Temp weights"); 00059 weightButtonGroup->addButton(tempWeightsButton, 2); 00060 weightRenderLayout->addWidget(tempWeightsButton); 00061 weightRenderLayout->addStretch(5); 00062 fullRenConVBox->addLayout(weightRenderLayout); 00063 00064 //Add full render controls widget to main layout 00065 QHBoxLayout* fullRenderHolderBox = new QHBoxLayout(); 00066 fullRenderHolderBox->addSpacing(30); 00067 fullRenderHolderBox->addWidget(fullRenderControlsWidget); 00068 fullRenderHolderBox->addStretch(5); 00069 mainVerticalBox->addLayout(fullRenderHolderBox); 00070 00071 //Button group to set connection mode 00072 QButtonGroup* conButGroup = new QButtonGroup(); 00073 00074 //All connection widgets 00075 allConsButt = new QRadioButton("All selected connections"); 00076 conButGroup->addButton(allConsButt); 00077 mainVerticalBox->addWidget(allConsButt); 00078 00079 //Single neuron widgets 00080 conSingleNeurButt = new QRadioButton("Neuron"); 00081 conButGroup->addButton(conSingleNeurButt); 00082 singleNeuronIDLabel = new QLabel(""); 00083 QHBoxLayout* singleNeuronBox = new QHBoxLayout(); 00084 singleNeuronBox->addWidget(conSingleNeurButt); 00085 singleNeuronBox->addWidget(singleNeuronIDLabel); 00086 singleNeuronBox->addWidget(new QLabel ("connections")); 00087 singleNeuronBox->addStretch(5); 00088 mainVerticalBox->addLayout(singleNeuronBox); 00089 00090 fromToCombo = new QComboBox(); 00091 fromToCombo->addItem("From and To"); 00092 fromToCombo->addItem("From"); 00093 fromToCombo->addItem("To"); 00094 connect(fromToCombo, SIGNAL(currentIndexChanged(int)), this, SLOT(fromToSelectionChanged(int))); 00095 QHBoxLayout* fromToSingleBox = new QHBoxLayout(); 00096 fromToSingleBox->addSpacing(20); 00097 fromToSingleBox->addWidget(fromToCombo); 00098 truthTableButton = new QPushButton("Truth Table"); 00099 truthTableButton->setVisible(false); 00100 connect(truthTableButton, SIGNAL(clicked()), this, SLOT(showTruthTable())); 00101 fromToSingleBox->addWidget(truthTableButton); 00102 fromToSingleBox->addStretch(5); 00103 mainVerticalBox->addLayout(fromToSingleBox); 00104 00105 //Between neuron widgets 00106 conBetweenNeurButt = new QRadioButton("Connection "); 00107 conButGroup->addButton(conBetweenNeurButt); 00108 QHBoxLayout* betweenBox = new QHBoxLayout(); 00109 betweenBox->addWidget(conBetweenNeurButt); 00110 fromLabel = new QLabel("From: "); 00111 betweenBox->addWidget(fromLabel); 00112 fromNeuronIDLabel = new QLabel(""); 00113 betweenBox->addWidget(fromNeuronIDLabel); 00114 toLabel = new QLabel("to: "); 00115 betweenBox->addWidget(toLabel); 00116 toNeuronIDLabel = new QLabel(""); 00117 betweenBox->addWidget(toNeuronIDLabel); 00118 betweenBox->addStretch(5); 00119 mainVerticalBox->addLayout(betweenBox); 00120 00121 //Positive and negative filtering 00122 QHBoxLayout* posNegBox = new QHBoxLayout(); 00123 posNegBox->addWidget(new QLabel("Filter by connection weight: ")); 00124 posNegCombo = new QComboBox(); 00125 posNegCombo->addItem("All connections"); 00126 posNegCombo->addItem("Positive connections"); 00127 posNegCombo->addItem("Negative connections"); 00128 connect(posNegCombo, SIGNAL(currentIndexChanged(int)), this, SLOT(posNegSelectionChanged(int))); 00129 posNegBox->addWidget(posNegCombo); 00130 posNegBox->addStretch(5); 00131 mainVerticalBox->addLayout(posNegBox); 00132 00133 //Add table view and model 00134 QAbstractTableModel* connectionsModel = new ConnectionsModel(); 00135 QTableView* connectionsView = new ConnectionsTableView(this, connectionsModel); 00136 connectionsView->setMinimumWidth(500); 00137 connectionsView->setMinimumHeight(500); 00138 mainVerticalBox->addWidget(connectionsView); 00139 00140 //Label listing number of connections in the table 00141 QHBoxLayout* numConLabBox = new QHBoxLayout(); 00142 numConLabBox->addSpacing(5); 00143 numberOfConnectionsLabel = new QLabel("Number of connections: 0"); 00144 numConLabBox->addWidget(numberOfConnectionsLabel); 00145 numConLabBox->addStretch(5); 00146 mainVerticalBox->addLayout(numConLabBox); 00147 mainVerticalBox->addStretch(5); 00148 00149 //Listen for changes in the network display 00150 connect(Globals::getEventRouter(), SIGNAL(networkDisplayChangedSignal()), this, SLOT(networkDisplayChanged())); 00151 connect(Globals::getEventRouter(), SIGNAL(visibleConnectionsChangedSignal()), this, SLOT(updateConnectionCount())); 00152 00153 /* Initialize truth table dialog to NULL 00154 Otherwise it appears as an annoying flash up during boot up of SpikeStream */ 00155 truthTableDialog = NULL; 00156 00157 //Initial state is to show all connections 00158 showAllConnections(); 00159 } 00160 00161 00163 NetworkViewerProperties::~NetworkViewerProperties(){ 00164 } 00165 00166 00167 /*----------------------------------------------------------*/ 00168 /*----- PRIVATE SLOTS -----*/ 00169 /*----------------------------------------------------------*/ 00170 00172 void NetworkViewerProperties::fromToSelectionChanged(int index){ 00173 if(index == 0){ 00174 Globals::getNetworkDisplay()->clearDirectionFiltering(); 00175 } 00176 else if (index == 1){ 00177 Globals::getNetworkDisplay()->showFromConnections(); 00178 } 00179 else if (index == 2){ 00180 Globals::getNetworkDisplay()->showToConnections(); 00181 } 00182 } 00183 00184 00186 void NetworkViewerProperties::networkDisplayChanged(){ 00187 unsigned int connectionMode = Globals::getNetworkDisplay()->getConnectionMode(); 00188 if(connectionMode & CONNECTION_MODE_ENABLED){ 00189 if(connectionMode & SHOW_BETWEEN_CONNECTIONS) 00190 showBetweenConnections(); 00191 else 00192 showSingleConnections(); 00193 } 00194 else{ 00195 showAllConnections(); 00196 } 00197 } 00198 00200 void NetworkViewerProperties::neuronTransparencyChanged(int sliderValue){ 00201 Globals::getNetworkDisplay()->setNeuronTransparency((float)sliderValue/1000.0f); 00202 } 00203 00204 00206 void NetworkViewerProperties::posNegSelectionChanged(int index){ 00207 if(index == 0){ 00208 Globals::getNetworkDisplay()->clearWeightFiltering(); 00209 } 00210 else if (index == 1){ 00211 Globals::getNetworkDisplay()->showPositiveConnections(); 00212 } 00213 else if (index == 2){ 00214 Globals::getNetworkDisplay()->showNegativeConnections(); 00215 } 00216 } 00217 00218 00220 void NetworkViewerProperties::setRenderMode(){ 00221 if(renderCheckBox->isChecked()){//Full render mode 00222 Globals::getNetworkDisplay()->setFullRenderMode(true); 00223 fullRenderControlsWidget->setEnabled(true); 00224 } 00225 else{ 00226 Globals::getNetworkDisplay()->setFullRenderMode(false); 00227 fullRenderControlsWidget->setEnabled(false); 00228 } 00229 } 00230 00231 00233 void NetworkViewerProperties::showTruthTable(){ 00234 //Get neuron id. 00235 unsigned int tmpNeurID = Globals::getNetworkDisplay()->getSingleNeuronID(); 00236 if(tmpNeurID == 0) 00237 throw SpikeStreamException("Truth table cannot be displayed for an invalid neuron ID"); 00238 00239 //Show non modal dialog 00240 showTruthTableDialog(tmpNeurID); 00241 } 00242 00243 00245 void NetworkViewerProperties::updateConnectionCount(){ 00246 numberOfConnectionsLabel->setText("Number of connections: " + QString::number( Globals::getNetworkDisplay()->getVisibleConnectionsList().size() ) ); 00247 } 00248 00249 00251 void NetworkViewerProperties::weightDisplayChanged(int buttonID){ 00252 if(buttonID == 0) 00253 Globals::getNetworkDisplay()->disableWeightRender(); 00254 else if(buttonID == 1) 00255 Globals::getNetworkDisplay()->renderCurrentWeights(); 00256 else if(buttonID == 2) 00257 Globals::getNetworkDisplay()->renderTempWeights(); 00258 else 00259 qCritical()<<"Button ID not recognized: "<<buttonID; 00260 } 00261 00262 00263 /*----------------------------------------------------------*/ 00264 /*----- PRIVATE METHODS -----*/ 00265 /*----------------------------------------------------------*/ 00266 00268 void NetworkViewerProperties::showAllConnections(){ 00269 allConsButt->setChecked(true); 00270 allConsButt->setEnabled(true); 00271 conBetweenNeurButt->setEnabled(false); 00272 conSingleNeurButt->setEnabled(false); 00273 singleNeuronIDLabel->setEnabled(false); 00274 singleNeuronIDLabel->setText(""); 00275 fromToCombo->setEnabled(false); 00276 fromNeuronIDLabel->setEnabled(false); 00277 fromNeuronIDLabel->setText(""); 00278 toNeuronIDLabel->setEnabled(false); 00279 toNeuronIDLabel->setText(""); 00280 fromLabel->setEnabled(false); 00281 toLabel->setEnabled(false); 00282 truthTableButton->setVisible(false); 00283 hideTruthTableDialog(); 00284 } 00285 00286 00288 void NetworkViewerProperties::showBetweenConnections(){ 00289 conBetweenNeurButt->setChecked(true); 00290 conBetweenNeurButt->setEnabled(true); 00291 fromNeuronIDLabel->setEnabled(true); 00292 fromNeuronIDLabel->setText(QString::number(Globals::getNetworkDisplay()->getSingleNeuronID())); 00293 toNeuronIDLabel->setEnabled(true); 00294 toNeuronIDLabel->setText(QString::number(Globals::getNetworkDisplay()->getToNeuronID())); 00295 fromToCombo->setEnabled(false); 00296 allConsButt->setEnabled(false); 00297 conSingleNeurButt->setEnabled(false); 00298 singleNeuronIDLabel->setEnabled(false); 00299 singleNeuronIDLabel->setText(""); 00300 fromLabel->setEnabled(true); 00301 toLabel->setEnabled(true); 00302 truthTableButton->setVisible(false); 00303 hideTruthTableDialog(); 00304 } 00305 00306 00308 void NetworkViewerProperties::showSingleConnections(){ 00309 //Id of the single neuron 00310 unsigned int singleNeuronID = Globals::getNetworkDisplay()->getSingleNeuronID(); 00311 00312 //Set up graphical components appropriately 00313 conSingleNeurButt->setChecked(true); 00314 conSingleNeurButt->setEnabled(true); 00315 singleNeuronIDLabel->setEnabled(true); 00316 singleNeuronIDLabel->setText(QString::number(singleNeuronID)); 00317 fromToCombo->setEnabled(true); 00318 fromNeuronIDLabel->setEnabled(false); 00319 fromNeuronIDLabel->setText(""); 00320 toNeuronIDLabel->setEnabled(false); 00321 toNeuronIDLabel->setText(""); 00322 allConsButt->setEnabled(false); 00323 conBetweenNeurButt->setEnabled(false); 00324 fromLabel->setEnabled(false); 00325 toLabel->setEnabled(false); 00326 00327 //Show button to launch truth table dialog if to neuron connections are shown and it is a weightless neuron 00328 if(Globals::getNetwork()->getNeuronGroupFromNeuronID(singleNeuronID)->isWeightless()){ 00329 //Update neuron in truth table dialog if it is visible 00330 if(truthTableDialog != NULL && truthTableDialog->isVisible()) 00331 showTruthTableDialog(singleNeuronID); 00332 00333 //Show button to display dialog if it is not already visible 00334 if(fromToCombo->currentText() == "To"){ 00335 truthTableButton->setVisible(true); 00336 } 00337 else{ 00338 truthTableButton->setVisible(false); 00339 hideTruthTableDialog(); 00340 } 00341 } 00342 else{ 00343 truthTableButton->setVisible(false); 00344 hideTruthTableDialog(); 00345 } 00346 } 00347 00348 00350 void NetworkViewerProperties::showTruthTableDialog(unsigned int neuronID){ 00351 if(truthTableDialog == NULL) 00352 truthTableDialog = new TruthTableDialog(); 00353 truthTableDialog->show(neuronID); 00354 } 00355 00356 00358 void NetworkViewerProperties::hideTruthTableDialog(){ 00359 if(truthTableDialog != NULL) 00360 truthTableDialog->hide(); 00361 } 00362