<commit_before>#include "brainview.h"
#include <QtGui>
#include "c2eBrain.h"

BrainView::BrainView(BrainInAVat *p) {
	parent = p;

	neuron_var = 0;
	dendrite_var = 0;
	threshold = -1000.0f;

	setAutoFillBackground(true);
	QPalette pal(palette());
	pal.setColor(QPalette::Background, QColor(0, 0, 0));
	setPalette(pal);
}

QSize BrainView::minimumSize() {
	c2eCreature *c = parent->getCreature();
	if (!c) return QSize(0, 0);
	c2eBrain *b = c->getBrain();
	assert(b);

	int neededwidth = 2, neededheight = 2;
	for (std::map<std::string, c2eLobe *>::iterator i = b->lobes.begin(); i != b->lobes.end(); i++) {
		c2eBrainLobeGene *lobe = i->second->getGene();
		int this_x = lobe->x + lobe->width;
		int this_y = lobe->y + lobe->height;
		if (this_x > neededwidth)
			neededwidth = this_x;
		if (this_y > neededheight)
			neededheight = this_y;
	}

	return QSize((neededwidth + 6) * 20, (neededheight + 5) * 20);
}

void BrainView::paintEvent(QPaintEvent *) {
	c2eCreature *c = parent->getCreature();
	if (!c) return;
	c2eBrain *b = c->getBrain();
	assert(b);

	QPainter painter(this);
	//painter.setRenderHint(QPainter::Antialiasing, true); <- atrociously slow

	QBrush oldbrush = painter.brush();

	std::map<c2eNeuron *, std::pair<unsigned int, unsigned int> > neuroncoords;

	// draw lobes/neurons
	for (std::map<std::string, c2eLobe *>::iterator i = b->lobes.begin(); i != b->lobes.end(); i++) {
		c2eBrainLobeGene *lobe = i->second->getGene();
		QColor color(lobe->red, lobe->green, lobe->blue);
		painter.setPen(color);
		painter.setBrush(oldbrush);
		int lobex = (lobe->x + 4) * 20;
		int lobey = (lobe->y + 4) * 20;
		painter.drawRect(lobex, lobey, lobe->width * 20, lobe->height * 20);
		painter.drawText(lobex, lobey - 20, 200, 200, Qt::AlignLeft, QString(i->first.c_str()));

		for (unsigned int y = 0; y < lobe->height; y++)
			for (unsigned int x = 0; x < lobe->width; x++) {
				unsigned int neuronid = x + (y * lobe->width);
				c2eNeuron *neuron = i->second->getNeuron(neuronid);

				// store the centre coordinate for drawing dendrites
				assert(neuroncoords.find(neuron) == neuroncoords.end());
				neuroncoords[neuron] = std::pair<unsigned int, unsigned int>(lobex + (x * 20) + 10, lobey + (y * 20) + 10);

				// always highlight spare neuron
				if (i->second->getSpareNeuron() == neuronid) {
					// TODO: don't hardcode these names?
					if (i->second->getId() == "attn" || i->second->getId() == "decn") {
						painter.setPen(color);
						painter.setBrush(oldbrush);
						painter.drawRect(lobex + (x * 20) + 5, lobey + (y * 20) + 5, 10, 10);
					}
				}

				// if below threshold, don't draw
				float var = neuron->variables[neuron_var];<commit_msg>braininavat: highlight spare neuron in combination lobe, too<commit_after>#include "brainview.h"
#include <QtGui>
#include "c2eBrain.h"

BrainView::BrainView(BrainInAVat *p) {
	parent = p;

	neuron_var = 0;
	dendrite_var = 0;
	threshold = -1000.0f;

	setAutoFillBackground(true);
	QPalette pal(palette());
	pal.setColor(QPalette::Background, QColor(0, 0, 0));
	setPalette(pal);
}

QSize BrainView::minimumSize() {
	c2eCreature *c = parent->getCreature();
	if (!c) return QSize(0, 0);
	c2eBrain *b = c->getBrain();
	assert(b);

	int neededwidth = 2, neededheight = 2;
	for (std::map<std::string, c2eLobe *>::iterator i = b->lobes.begin(); i != b->lobes.end(); i++) {
		c2eBrainLobeGene *lobe = i->second->getGene();
		int this_x = lobe->x + lobe->width;
		int this_y = lobe->y + lobe->height;
		if (this_x > neededwidth)
			neededwidth = this_x;
		if (this_y > neededheight)
			neededheight = this_y;
	}

	return QSize((neededwidth + 6) * 20, (neededheight + 5) * 20);
}

void BrainView::paintEvent(QPaintEvent *) {
	c2eCreature *c = parent->getCreature();
	if (!c) return;
	c2eBrain *b = c->getBrain();
	assert(b);

	QPainter painter(this);
	//painter.setRenderHint(QPainter::Antialiasing, true); <- atrociously slow

	QBrush oldbrush = painter.brush();

	std::map<c2eNeuron *, std::pair<unsigned int, unsigned int> > neuroncoords;

	// draw lobes/neurons
	for (std::map<std::string, c2eLobe *>::iterator i = b->lobes.begin(); i != b->lobes.end(); i++) {
		c2eBrainLobeGene *lobe = i->second->getGene();
		QColor color(lobe->red, lobe->green, lobe->blue);
		painter.setPen(color);
		painter.setBrush(oldbrush);
		int lobex = (lobe->x + 4) * 20;
		int lobey = (lobe->y + 4) * 20;
		painter.drawRect(lobex, lobey, lobe->width * 20, lobe->height * 20);
		painter.drawText(lobex, lobey - 20, 200, 200, Qt::AlignLeft, QString(i->first.c_str()));

		for (unsigned int y = 0; y < lobe->height; y++)
			for (unsigned int x = 0; x < lobe->width; x++) {
				unsigned int neuronid = x + (y * lobe->width);
				c2eNeuron *neuron = i->second->getNeuron(neuronid);

				// store the centre coordinate for drawing dendrites
				assert(neuroncoords.find(neuron) == neuroncoords.end());
				neuroncoords[neuron] = std::pair<unsigned int, unsigned int>(lobex + (x * 20) + 10, lobey + (y * 20) + 10);

				// always highlight spare neuron
				if (i->second->getSpareNeuron() == neuronid) {
					// TODO: don't hardcode these names?
					if (i->second->getId() == "attn" || i->second->getId() == "decn" || i->second->getId() == "comb") {
						painter.setPen(color);
						painter.setBrush(oldbrush);
						painter.drawRect(lobex + (x * 20) + 5, lobey + (y * 20) + 5, 10, 10);
					}
				}

				// if below threshold, don't draw
				float var = neuron->variables[neuron_var];
{'fraction_non_alphanumeric': 0.180445590130731, 'fraction_numerical': 0.02540968514085804, 'mean_word_length': 3.947176684881603, 'pattern_counts': {'":': 0, '<': 21, '<?xml version=': 0, '>': 93, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '340849', 'n_tokens_mistral': 2475, 'n_tokens_neox': 2075, 'n_words': 474}