Exemple #1
0
PidMain::PidMain(QWidget *parent) : QMainWindow(parent)
{
    setupUi(this);

    // Connect signals
    // File
    connect(menuOpenImage, SIGNAL( triggered() ), this, SLOT( openImage() ));
    connect(menuSaveCurrent, SIGNAL( triggered() ), this, SLOT( saveCurrentAs() ));

    // Image
    connect(menuGenerateGrayScale, SIGNAL( triggered() ), this, SLOT( generateGrayScale() ));
    connect(menuGenerateHistogram, SIGNAL( triggered() ), this, SLOT( generateHistogram() ));

    // Help
    connect(menuOpenAbout, SIGNAL( triggered() ), this, SLOT( openAboutDialog() ));
    connect(menuOpenHelp, SIGNAL( triggered() ), this, SLOT( openHelpDialog() ));

    // Filters
    connect(menuFiltersAltaIdeal, SIGNAL( triggered() ), this, SLOT( openPassaAltaIdeal() ));
    connect(menuFiltersBaixaIdeal, SIGNAL( triggered() ), this, SLOT( openPassaBaixaIdeal() ));
    connect(menuFiltersIdeal, SIGNAL( triggered() ), this, SLOT( openIdeal() ));
    connect(menuButterworthBaixa, SIGNAL( triggered() ), this, SLOT( openButterworthBaixa() ));
    connect(menuButterworthAlta, SIGNAL( triggered() ), this, SLOT( openButterworthAlta() ));

    // initializing some widgets
    mdiArea->setHorizontalScrollBarPolicy(Qt::ScrollBarAsNeeded);
    mdiArea->setVerticalScrollBarPolicy(Qt::ScrollBarAsNeeded);
}
void
RawSlabsPlugin::setMinMax(float rmin, float rmax)
{
  m_rawMin = rmin;
  m_rawMax = rmax;
  
  generateHistogram();
}
void
RemapHDF4::setMinMax(float rmin, float rmax)
{
  m_rawMin = rmin;
  m_rawMax = rmax;
  
  generateHistogram();
}
void HistogramFilter::processFrame()
{
	//qDebug() << "HistogramFilter::processFrame(): source:"<<m_source;
	
	// dont call generateHistogram here if manual fps is set because the 
	// m_generateHistoTimer will call it when it times out
	if(m_manualFps > 0)
		return;
	
	generateHistogram();
}
Exemple #5
0
void
RawPlugin::setMinMax(float rmin, float rmax)
{
  m_rawMin = rmin;
  m_rawMax = rmax;

  if (m_voxelType == _UChar ||
      m_voxelType == _Char ||
      m_voxelType == _UShort ||
      m_voxelType == _Short)
    return;
  generateHistogram();
}
HistogramFilter::HistogramFilter(QObject* parent)
	: VideoFilter(parent)
	, m_histoType(HSV)
	, m_includeOriginalImage(true)
	, m_chartHsv(true)
	, m_calcHsvStats(true)
	, m_frameAccumEnabled(false)
	, m_frameAccumNum(10) // just a guess
	, m_drawBorder(true)
	, m_hsvStatsValid(false)
	, m_manualFps(-1)
{
	//setIsThreaded(true);
	connect(&m_generateHistoTimer, SIGNAL(timeout()), this, SLOT(generateHistogram()));
}
TEST_F(VideoThumbnailerTest, CreateHistogramWhiteFrame)
{
    fill(frame.frameData.begin(), frame.frameData.end(), 255);
    generateHistogram();

    EXPECT_EQ(100, histogram.r[255]);
    EXPECT_EQ(100, histogram.g[255]);
    EXPECT_EQ(100, histogram.b[255]);

    for (int i = 0; i < 254; ++i)
    {
        EXPECT_EQ(0, histogram.r[i]) << "index " << i;
        EXPECT_EQ(0, histogram.g[i]) << "index " << i;
        EXPECT_EQ(0, histogram.b[i]) << "index " << i;
    }
}
TEST_F(VideoThumbnailerTest, CreateHistogramBlackFrame)
{
    fill(frame.frameData.begin(), frame.frameData.end(), 0);
    generateHistogram();

    EXPECT_EQ(100, histogram.r[0]);
    EXPECT_EQ(100, histogram.g[0]);
    EXPECT_EQ(100, histogram.b[0]);

    for (int i = 1; i < 255; ++i)
    {
        EXPECT_EQ(0, histogram.r[i]);
        EXPECT_EQ(0, histogram.g[i]);
        EXPECT_EQ(0, histogram.b[i]);
    }
}
void VideoThumbnailer::generateSmartThumbnail(MovieDecoder& movieDecoder, VideoFrame& videoFrame)
{
    vector<VideoFrame> videoFrames(SMART_FRAME_ATTEMPTS);
    vector<Histogram<int> > histograms(SMART_FRAME_ATTEMPTS);

    for (int i = 0; i < SMART_FRAME_ATTEMPTS; ++i) {
        movieDecoder.decodeVideoFrame();
        movieDecoder.getScaledVideoFrame(m_ThumbnailSize, m_MaintainAspectRatio, videoFrames[i]);
        generateHistogram(videoFrames[i], histograms[i]);
    }

    int bestFrame = getBestThumbnailIndex(videoFrames, histograms);

    Q_ASSERT(bestFrame != -1);
    videoFrame = videoFrames[bestFrame];
}
Exemple #10
0
Datum htg_in(PG_FUNCTION_ARGS){
	char *str = PG_GETARG_CSTRING(0);
	char buffer[30];
	VALH temp;
	Histogram *result;
	
	generateHistogram(str);
	//memcpy(result->path,str,256);

	str = strcat(str,".htg");
	FILE * hgrFile = fopen(str,"r");
	

	if(hgrFile == NULL){
		ereport(ERROR,
				(errcode(ERRCODE_INVALID_TEXT_REPRESENTATION),
				 errmsg("invalid input syntax for histogram: \"%s\" The file doesn't exist",
						str)));
	}
	
	result = (Histogram *) palloc(sizeof(Histogram));

	for(int i = 0; i < HTG_SIZE; i++){	
		fgets(buffer,31,hgrFile);	
		sscanf(buffer, "%d", &temp);
		result->htg[i] = temp;
		
	}

	fclose(hgrFile);

	char * comp2 = (char*) palloc(strlen(str) + 3 + 5);
	comp2 = strcpy(comp2,"rm ");
	comp2 = strcat(comp2,str);
	Counter e = system(comp2);
	
	if(e == -1){
		ereport(ERROR,
				(errcode(ERRCODE_INVALID_TEXT_REPRESENTATION),
				 errmsg("The histogram doesn't generate")));	
	}

	result->radius = 0;

	PG_RETURN_POINTER(result);
}
Exemple #11
0
bool
RawPlugin::setFile(QStringList files)
{
  m_fileName = files;

  int nX, nY, nZ;
  {
    // --- load various parameters from the raw file ---
    LoadRawDialog loadRawDialog(0,
				(char *)m_fileName[0].toAscii().data());

    if (!m_4dvol)
      {
	loadRawDialog.exec();    
	if (loadRawDialog.result() == QDialog::Rejected)
	  return false;
      }

    m_voxelType = loadRawDialog.voxelType();
    m_skipBytes = loadRawDialog.skipHeaderBytes();
    loadRawDialog.gridSize(nX, nY, nZ);
    m_depth = nX;
    m_width = nY;
    m_height = nZ;
  }

  //-----------------------------------
  QFile fin(m_fileName[0]);
  fin.open(QFile::ReadOnly);

  //-- recheck the information (for backward compatibility) ----
  if (m_skipBytes == 0)
    {
      int bpv = 1;
      if (m_voxelType == _UChar) bpv = 1;
      else if (m_voxelType == _Char) bpv = 1;
      else if (m_voxelType == _UShort) bpv = 2;
      else if (m_voxelType == _Short) bpv = 2;
      else if (m_voxelType == _Int) bpv = 4;
      else if (m_voxelType == _Float) bpv = 4;

      if (fin.size() == 13+nX*nY*nZ*bpv)
	m_skipBytes = 13;
      else if (fin.size() == 12+nX*nY*nZ*bpv)
	m_skipBytes = 12;
      else
	m_skipBytes = 0;
    }
  m_headerBytes = m_skipBytes;
  fin.close();
  //------------------------------

  m_bytesPerVoxel = 1;
  if (m_voxelType == _UChar) m_bytesPerVoxel = 1;
  else if (m_voxelType == _Char) m_bytesPerVoxel = 1;
  else if (m_voxelType == _UShort) m_bytesPerVoxel = 2;
  else if (m_voxelType == _Short) m_bytesPerVoxel = 2;
  else if (m_voxelType == _Int) m_bytesPerVoxel = 4;
  else if (m_voxelType == _Float) m_bytesPerVoxel = 4;

  if (m_4dvol) // do not perform further calculations.
    return true;

  if (m_voxelType == _UChar ||
      m_voxelType == _Char ||
      m_voxelType == _UShort ||
      m_voxelType == _Short)
    {
      findMinMaxandGenerateHistogram();
    }
  else
    {
      findMinMax();
      generateHistogram();
    }

  return true;
}
bool
RemapHDF4::setFile(QList<QString> fl)
{
  m_fileName = fl;
  
  // list all image files in the directory
  QStringList imageNameFilter;
  imageNameFilter << "*.hdf";
  QStringList files= QDir(m_fileName[0]).entryList(imageNameFilter,
						   QDir::NoSymLinks|
						   QDir::NoDotAndDotDot|
						   QDir::Readable|
						   QDir::Files);
  m_imageList.clear();
  for(uint i=0; i<files.size(); i++)
    {
      QFileInfo fileInfo(m_fileName[0], files[i]);
      QString imgfl = fileInfo.absoluteFilePath();
      m_imageList.append(imgfl);
    }

  m_depth = m_imageList.size();


  /* Open the file and initiate the SD interface. */
  int32 sd_id = SDstart(strdup(m_imageList[0].toAscii().data()),
		  DFACC_READ);
  if (sd_id < 0) {
    QMessageBox::information(0, 
			     "Error",
			     QString("Failed to open %1").arg(m_imageList[0]));
    return false;
  }
    
  /* Determine the contents of the file. */
  int32 dim_sizes[MAX_VAR_DIMS];
  int32 rank, num_type, attributes, istat;
  char name[64];
  int32 n_datasets, n_file_attrs;

  istat = SDfileinfo(sd_id, &n_datasets, &n_file_attrs);

  /* Access the name of every data set in the file. */
  QStringList varNames;
  for (int32 index = 0; index < n_datasets; index++)
    {
      int32 sds_id = SDselect(sd_id, index);
      
      istat = SDgetinfo(sds_id, name, &rank, dim_sizes,	\
			&num_type, &attributes);
            
      istat = SDendaccess(sds_id);

      if (rank == 2)
	varNames.append(name);
    }
  
  QString var;
  if (varNames.size() == 0) {
    QMessageBox::information(0, 
			     "Error",
			     QString("No variables in file with rank of 2"));
    return false;
  } else if (varNames.size() == 1)
    {
      var = varNames[0];
    }
  else
    {
      var = QInputDialog::getItem(0,
				  "Select Variable to Extract",
				  "Variable Names",
				  varNames,
				  0,
				  false);
    }
  
  m_Index = 0;
  for (int32 index = 0; index < n_datasets; index++)
    {
      int32 sds_id = SDselect(sd_id, index);
      
      istat = SDgetinfo(sds_id, name, &rank, dim_sizes,	\
			&num_type, &attributes);
      
      istat = SDendaccess(sds_id);
      
      if (var == QString(name))
	{
	  m_Index = index;
	  break;
	}
    }

  {    
    int32 sds_id = SDselect(sd_id, m_Index);
    
    istat = SDgetinfo(sds_id,
		      name,
		      &rank,
		      dim_sizes,
		      &num_type,
		      &attributes);
    
    istat = SDendaccess(sds_id);
  }

  /* Terminate access to the SD interface and close the file. */
  istat = SDend(sd_id);


  if (num_type == DFNT_CHAR8)
    m_voxelType = _Char;
  else if (num_type == DFNT_UCHAR8)
    m_voxelType = _UChar;
  else if (num_type == DFNT_INT8)
    m_voxelType = _Char;
  else if (num_type == DFNT_UINT8)
    m_voxelType = _UChar;
  else if (num_type == DFNT_INT16)
    m_voxelType = _Short;
  else if (num_type == DFNT_UINT16)
    m_voxelType = _UShort;
  else if (num_type == DFNT_INT32)
    m_voxelType = _Int;
  else if (num_type == DFNT_FLOAT32)
    m_voxelType = _Float;
  else
    {
      QMessageBox::information(0, "Error",
			       QString("Cannot handle datatype %1").arg(num_type));
      return false;
    }

  m_width = dim_sizes[0];
  m_height = dim_sizes[1];

  m_bytesPerVoxel = 1;
  if (m_voxelType == _UChar) m_bytesPerVoxel = 1;
  else if (m_voxelType == _Char) m_bytesPerVoxel = 1;
  else if (m_voxelType == _UShort) m_bytesPerVoxel = 2;
  else if (m_voxelType == _Short) m_bytesPerVoxel = 2;
  else if (m_voxelType == _Int) m_bytesPerVoxel = 4;
  else if (m_voxelType == _Float) m_bytesPerVoxel = 4;

  m_headerBytes = 0;

  if (m_voxelType == _UChar ||
      m_voxelType == _Char ||
      m_voxelType == _UShort ||
      m_voxelType == _Short)
    {
      findMinMaxandGenerateHistogram();
    }
  else
    {
      findMinMax();
      generateHistogram();
    }

  m_rawMap.append(m_rawMin);
  m_rawMap.append(m_rawMax);
  m_pvlMap.append(0);
  m_pvlMap.append(255);

  return true;
}
Exemple #13
0
bool
NrrdPlugin::setFile(QStringList files)
{
  m_fileName = files;
 
  typedef itk::Image<unsigned char, 3> ImageType;
  typedef itk::ImageFileReader<ImageType> ReaderType;
  ReaderType::Pointer reader = ReaderType::New();
  reader->SetFileName(m_fileName[0].toAscii().data());

  typedef itk::NrrdImageIO NrrdIOType;
  NrrdIOType::Pointer nrrdIO = NrrdIOType::New();
  reader->SetImageIO(nrrdIO);
  reader->Update();

  itk::ImageIOBase::Pointer imageIO = reader->GetImageIO();

  m_height = imageIO->GetDimensions(0);
  m_width = imageIO->GetDimensions(1);
  m_depth = imageIO->GetDimensions(2);

  m_voxelSizeX = imageIO->GetSpacing(0);
  m_voxelSizeY = imageIO->GetSpacing(1);
  m_voxelSizeZ = imageIO->GetSpacing(2);

  int et = imageIO->GetComponentType();
  if (et == itk::ImageIOBase::UCHAR) m_voxelType = _UChar;
  if (et == itk::ImageIOBase::CHAR) m_voxelType = _Char;
  if (et == itk::ImageIOBase::USHORT) m_voxelType = _UShort;
  if (et == itk::ImageIOBase::SHORT) m_voxelType = _Short;
  if (et == itk::ImageIOBase::INT) m_voxelType = _Int;
  if (et == itk::ImageIOBase::FLOAT) m_voxelType = _Float;

  m_skipBytes = m_headerBytes = 0;

  m_bytesPerVoxel = 1;
  if (m_voxelType == _UChar) m_bytesPerVoxel = 1;
  else if (m_voxelType == _Char) m_bytesPerVoxel = 1;
  else if (m_voxelType == _UShort) m_bytesPerVoxel = 2;
  else if (m_voxelType == _Short) m_bytesPerVoxel = 2;
  else if (m_voxelType == _Int) m_bytesPerVoxel = 4;
  else if (m_voxelType == _Float) m_bytesPerVoxel = 4;

  if (m_4dvol) // do not perform further calculations.
    return true;

  if (m_voxelType == _UChar ||
      m_voxelType == _Char ||
      m_voxelType == _UShort ||
      m_voxelType == _Short)
    {
      findMinMaxandGenerateHistogram();
    }
  else
    {
      findMinMax();
      generateHistogram();
    }

  return true;
}
Exemple #14
0
bool
GrdPlugin::setFile(QStringList files)
{
  m_fileName = files;

  m_imageList.clear();

  QFileInfo f(m_fileName[0]);
  if (f.isDir())
    {
      // list all image files in the directory
      QStringList imageNameFilter;
      imageNameFilter << "*";
      QStringList imgfiles= QDir(m_fileName[0]).entryList(imageNameFilter,
							  QDir::NoSymLinks|
							  QDir::NoDotAndDotDot|
							  QDir::Readable|
							  QDir::Files);


      m_imageList.clear();
      for(uint i=0; i<imgfiles.size(); i++)
	{
	  QFileInfo fileInfo(m_fileName[0], imgfiles[i]);
	  QString imgfl = fileInfo.absoluteFilePath();
	  m_imageList.append(imgfl);
	}
    }
  else
    m_imageList = files;

  // --- load various parameters from the raw file ---
  LoadRawDialog loadRawDialog(0,
			      (char *)m_imageList[0].toAscii().data());
  //(char *)m_fileName[0].toAscii().data());

  loadRawDialog.exec();
  if (loadRawDialog.result() == QDialog::Rejected)
    return false;
  
  m_voxelType = loadRawDialog.voxelType();
  m_headerBytes = loadRawDialog.skipHeaderBytes();

  int nX, nY, nZ;
  loadRawDialog.gridSize(nX, nY, nZ);

  m_depth = m_imageList.size();
  m_width = nX;
  m_height = nY;


  m_bytesPerVoxel = 1;
  if (m_voxelType == _UChar) m_bytesPerVoxel = 1;
  else if (m_voxelType == _Char) m_bytesPerVoxel = 1;
  else if (m_voxelType == _UShort) m_bytesPerVoxel = 2;
  else if (m_voxelType == _Short) m_bytesPerVoxel = 2;
  else if (m_voxelType == _Int) m_bytesPerVoxel = 4;
  else if (m_voxelType == _Float) m_bytesPerVoxel = 4;

  if (m_voxelType == _UChar ||
      m_voxelType == _Char ||
      m_voxelType == _UShort ||
      m_voxelType == _Short)
    {
      findMinMaxandGenerateHistogram();
    }
  else
    {
      findMinMax();
      generateHistogram();
    }

  return true;
}
Exemple #15
0
int main(int argc, char **argv) {
	srand(time(0));

	int popNum;
	int indCount;

	fstream simdata;
	simdata.open("simdata.txt");
	simdata >> popNum >> indCount;
	simdata.close();

	cout << "População: " << popNum << endl;
	cout << "Numero de individuos: " << indCount << endl;

	stringstream popOutName;

	popOutName << "popstat." << setw(5) << setfill('0') << popNum << ".txt";

	simdata.open("simdata.txt");
	simdata << (popNum + 1) << ' ' << indCount;
	simdata.close();

	vector<guy> pop;
	map<string, guy> popmap;

	ifstream read;
	read.open("stats.txt");

	Robot r(nullptr, nullptr, nullptr);

	map<string, RobotDescriptor*> descs;

	do {
		string id;
		double score;
		int stall;
		double duration;

		read >> id >> score >> stall >> duration;

		if (!id.length()) {
			break;
		}

		guy g;
		g.id = id;
		g.score = score;

		pop.push_back(g);

		popmap.insert(pair<string, guy>(g.id, g));

		RobotDescriptor *descriptor = new RobotDescriptor();

		stringstream fileName;
		fileName << "robots/desc" << id;

		cout << "READING FILE " << fileName.str() << endl;
		ifstream inputFile;
		inputFile.open(fileName.str());
		descriptor->loadFromFile(inputFile, &r);
		inputFile.close();

		descs.insert(pair<string, RobotDescriptor*>(id, descriptor));
	} while (!read.eof());

	sort(pop.begin(), pop.end());

	ofstream popOut;
	popOut.open(popOutName.str());

	map<string, RobotDescriptor*> newPop;

	vector<guy> newpop;
	map<string, guy> mapunique;
	while (newpop.size() != indCount) {
		vector<string> killed;
		vector<string> chosen;
		tournament(pop, 0, pop.size() - 1, SIZE, chosen, killed);

		newpop.push_back(popmap[chosen[0]]);
		mapunique.insert(pair<string, guy>(chosen[0], popmap[chosen[0]]));
	}

	vector<guy> popunique;

	for (map<string, guy>::iterator it = mapunique.begin();
			it != mapunique.end(); ++it) {
		popunique.push_back(it->second);
	}

	sort(newpop.begin(), newpop.end());
	sort(popunique.begin(), popunique.end());

	vector<double> divs;
	vector<double> oldPopScores;
	vector<double> newPopScores;
	vector<double> newPopScoresUnique;

	for (int i = 0; i < 400; i += 10) {
		divs.push_back(i);
	}

	for (int i = 0; i < pop.size(); i++) {
		oldPopScores.push_back(pop[i].score);
	}

	for (int i = 0; i < newpop.size(); i++) {
		newPopScores.push_back(newpop[i].score);
	}

	for (int i = 0; i < popunique.size(); i++) {
		newPopScoresUnique.push_back(popunique[i].score);
	}

	vector<int> oldPopStats = generateHistogram(divs, oldPopScores);
	vector<int> newPopStats = generateHistogram(divs, newPopScores);
	vector<int> newPopStatsUnique = generateHistogram(divs, newPopScoresUnique);

	popOut << newpop.size() << " chosen, " << popunique.size() << " unique\n";
	popOut << "range\told\tnew\tunique\n";

	for (int i = 0; i < divs.size(); i++) {
		popOut << divs[i] << '\t' << oldPopStats[i] << '\t' << newPopStats[i]
				<< '\t' << newPopStatsUnique[i] << '\n';
	}

	for (int i = 0; i < pop.size(); i++) {
		popOut << pop[i].score << "\t" << pop[i].id << '\n';
	}

	for (int j = 0; j < SURVIVAL_RATE * popunique.size(); j++) {
		string id = popunique[j].id;
		popOut << id << " survived\n";
		cout << "choosing " << id << ", score: " << popunique[j].score << endl;
		newPop.insert(pair<string, RobotDescriptor*>(id, descs[id]));
	}

	popOut.close();

	cout << endl;

	if (argc > 1) {
		return 0;
	}

	ofstream output;
	output.open("generated.txt");
	
	int ammountCross = TAXA_CROSS * (indCount - newPop.size());

	for (int i = 0; i < ammountCross; i++) {
		string parent1 = popunique[rand() % (popunique.size())].id;
		string parent2 = popunique[rand() % (popunique.size())].id;
		RobotDescriptor *p1 = descs[parent1];
		RobotDescriptor *p2 = descs[parent2];

		double point = (rand() % 10) / 10.0;

		if (p1->behaviours.size() < 3 || p2->behaviours.size() < 3) {
			continue;
		}

		RobotDescriptor *ind = new RobotDescriptor();

		int cut1 = std::min(std::max(1, (int) (point * p1->behaviours.size())),
				(int) p1->behaviours.size() - 2);
		int cut2 = std::min(std::max(1, (int) (point * p2->behaviours.size())),
				(int) p2->behaviours.size() - 2);

		//@bug Referência ao descritor pai é mantida!
		for (int i = 0; i < cut1; i++) {
			ind->addBehavior(p1->behaviours[i]);
		}
		for (int i = cut2; i < p2->behaviours.size(); i++) {
			ind->addBehavior(p2->behaviours[i]);
		}
	}

	//Mutação!
	int k = 0;
	while (newPop.size() < indCount) {
		string parentID = popunique[rand() % (popunique.size())].id;
		RobotDescriptor *parent = descs[parentID];
		RobotDescriptor *ind = new RobotDescriptor();

		stringstream fileName;
		fileName << "robots/desc" << parentID;
		ifstream inParent;
		inParent.open(fileName.str());
		ind->loadFromFile(inParent, nullptr);
		inParent.close();

		for (int i = 0; i < ind->behaviours.size(); i++) {
			BehaviourOnObstacleDistance *b =
					static_cast<BehaviourOnObstacleDistance*>(ind->behaviours[i]);
			if (rand() % 100 <= 5) {
				b->angle += rand()%5 - 2;
				b->angle = std::min(std::max(b->angle, 360.0), 0.0);
			}
			if (rand() % 100 <= 5) {
				b->distanceMax += (rand() % 20) / 100.0 - 0.1;
			}
			if (rand() % 100 <= 5) {
				b->distanceMin += (rand() % 20) / 100.0 - 0.1;
			}

			for (int j = 0; j < b->actions.size(); j++) {
				Action *a = b->actions[j];

				if (rand() % 100 <= 5) {
					a->duration += (rand() % 20) / 100.0 - 0.1;
				}
				if (rand() % 100 <= 5) {
					a->duration = std::max(0.0, a->duration);
				}

				if (rand() % 100 <= 5) {
					a->value += (rand() % 20) / 100.0 - 0.1;
				}
			}

			if (!(rand() % 100)) {
				Action *a;
				if (rand() % 2) {
					a = new Action(ACTION_LINEAR_VEL, (rand() % 100) / 100.0,
							(rand() % 100) / 100.0);
				} else {
					a = new Action(ACTION_ANGULAR_VEL,
							(rand() % 200) / 100.0 - 1, (rand() % 100) / 100.0);
				}

				b->addAction(a);
			}
		}

		if (!(rand() % 100)) {
			double minDist = (rand() % 100) / 100.0;
			Behaviour *b = new BehaviourOnObstacleDistance(nullptr,
					rand() % 360, minDist, minDist + (rand() % 400) / 100.0);

			Action *act;
			if (rand() % 2) {
				act = new Action(ACTION_LINEAR_VEL, (rand() % 100) / 100.0,
						(rand() % 100) / 100.0);
			} else {
				act = new Action(ACTION_ANGULAR_VEL, (rand() % 200) / 100.0 - 1,
						(rand() % 100) / 100.0);
			}

			b->addAction(act);
		}

		stringstream generatedID;
		generatedID << setw(5) << setfill('0') << popNum << '.' << setw(5)
				<< setfill('0') << k;

		cout << "New ID: " << generatedID.str() << endl;

		stringstream generatedFile;
		generatedFile << "robots/desc" << generatedID.str();

		cout << "New File: " << generatedFile.str() << endl;

		ofstream saveFile;
		saveFile.open(generatedFile.str());
		ind->saveToFile(saveFile);
		saveFile.close();

		newPop.insert(pair<string, RobotDescriptor*>(generatedID.str(), ind));

		k++;

	}

	for (map<string, RobotDescriptor*>::iterator it = newPop.begin();
			it != newPop.end(); ++it) {
		output << it->first << '\n';
	}

	output.close();

	return 0;
}
bool
RawSlabsPlugin::setFile(QStringList files)
{
  m_fileName = files;

  {
    m_slices.clear();

    QFileInfo fi(files[0]);

    QString hdrflnm;
    hdrflnm = QFileDialog::getOpenFileName(0,
					"Load text header file",
					fi.absolutePath(),
					"Files (*.*)");

    int nfX0, nfY0, nfZ0;
    
    if (hdrflnm.isEmpty())
      {
	uchar nvt0;
	QFile fd(m_fileName[0]);
	fd.open(QFile::ReadOnly);
	fd.read((char*)&nvt0, sizeof(unsigned char));
	fd.read((char*)&nfX0, sizeof(int));
	fd.read((char*)&nfY0, sizeof(int));
	fd.read((char*)&nfZ0, sizeof(int));
	fd.close();
    
	m_voxelType = _UChar;
	if (nvt0 == 0) m_voxelType = _UChar;
	if (nvt0 == 1) m_voxelType = _Char;
	if (nvt0 == 2) m_voxelType = _UShort;
	if (nvt0 == 3) m_voxelType = _Short;
	if (nvt0 == 4) m_voxelType = _Int;
	if (nvt0 == 8) m_voxelType = _Float;

	m_headerBytes = m_skipBytes = 13;
	int nslices = nfX0;
	m_slices.append(nslices);
	
	for (int nf=1; nf<m_fileName.count(); nf++)
	  {
	    uchar nvt;
	    int nfX, nfY, nfZ;
	    QFile fd(m_fileName[nf]);
	    fd.open(QFile::ReadOnly);
	    fd.read((char*)&nvt, sizeof(unsigned char));
	    fd.read((char*)&nfX, sizeof(int));
	    fd.read((char*)&nfY, sizeof(int));
	    fd.read((char*)&nfZ, sizeof(int));
	    fd.close();
	    if (nvt != nvt0 || nfY != nfY0 || nfZ != nfZ0)
	      {
		QMessageBox::information(0, "", "Raw File format does not match");
		return false;
	      }
	    
	    nslices += nfX;
	    m_slices.append(nslices);
	  }
      }
    else
      {
	// load header information from a text file
	
	int nvt0, nvt;
	int nfX, nfY, nfZ;
	
	QFile fd(hdrflnm);
	fd.open(QFile::ReadOnly | QFile::Text);
	QTextStream in(&fd);

	QString line = (in.readLine()).simplified();
	QStringList words = line.split(" ", QString::SkipEmptyParts);
	if (words.count() >= 2)
	  {
	    int nvt0 = words[0].toInt();
	    m_voxelType = _UChar;
	    if (nvt0 == 0) m_voxelType = _UChar;
	    if (nvt0 == 1) m_voxelType = _Char;
	    if (nvt0 == 2) m_voxelType = _UShort;
	    if (nvt0 == 3) m_voxelType = _Short;
	    if (nvt0 == 4) m_voxelType = _Int;
	    if (nvt0 == 8) m_voxelType = _Float;
	    m_headerBytes = m_skipBytes = words[1].toInt();
	  }
	else
	  {
	    QMessageBox::information(0, "",
	     QString("Expecting voxeltype and headerbytes\nGot this %1").arg(line));
	    return false;
	  }

	int nslices = 0;
	while (!in.atEnd())
	  {
	    line = (in.readLine()).simplified();
	    words = line.split(" ", QString::SkipEmptyParts);
	    if (words.count() >= 3)
	      {
		nfX = words[0].toInt();
		nfY = words[1].toInt();
		nfZ = words[2].toInt();
		
		if (nslices == 0)
		  {
		    nfY0 = nfY;
		    nfZ0 = nfZ;
		  }
		else
		  {
		    if (nfY0 != nfY || nfZ0 != nfZ)
		      {
			QMessageBox::information(0, "",
			   QString("Slice size not same :: %1 %2 : %3 %4").\
			     arg(nfY0).arg(nfZ0).arg(nfY).arg(nfZ));
			return false;
		      }
		  }

		nslices += nfX;
		m_slices.append(nslices);
	      }
	    else
	      {
		QMessageBox::information(0, "",
	          QString("Expecting dimensions\nGot this %1").arg(line));
		return false;
	      }
	  }	
      }
    m_depth = m_slices[m_slices.count()-1];
    m_width = nfY0;
    m_height = nfZ0;
  }
  //------------------------------
  m_bytesPerVoxel = 1;
  if (m_voxelType == _UChar) m_bytesPerVoxel = 1;
  else if (m_voxelType == _Char) m_bytesPerVoxel = 1;
  else if (m_voxelType == _UShort) m_bytesPerVoxel = 2;
  else if (m_voxelType == _Short) m_bytesPerVoxel = 2;
  else if (m_voxelType == _Int) m_bytesPerVoxel = 4;
  else if (m_voxelType == _Float) m_bytesPerVoxel = 4;

  if (m_voxelType == _UChar ||
      m_voxelType == _Char ||
      m_voxelType == _UShort ||
      m_voxelType == _Short)
    {
      findMinMaxandGenerateHistogram();
    }
  else
    {
      findMinMax();
      generateHistogram();
    }

  return true;
}
void SMIHED_widget::sltStartConversion(){
  _log->writeDebug("function: void SMIHED_widget::sltStartConversion()");
	//set Strings
	QString subjectindexPath = _ui.subjectCsv_pathEdit->text();
	QString imagePath        = _ui.imageFolder_pathEdit->text();
	QString outputPath       = _ui.outputFolder_pathEdit->text();
	QString qualityPrefix    = _ui.quality_lineEdit->text();
	//set bools
	bool use_offset     = _ui.use_offset->checkState() && _ui.checkQuality_checkBox->isEnabled();
	bool quality        = _ui.checkQuality_checkBox->isChecked() && _ui.checkQuality_checkBox->isEnabled();
  bool show_histogram = _ui.showhistogram_checkBox->checkState() && _ui.showhistogram_checkBox->isEnabled();
  bool save_histogram = _ui.savehistogram_checkBox->checkState() && _ui.savehistogram_checkBox->isEnabled();

  SMIHED plugin(_log);

  //Check Filelist
	if( _fileList.length() <= 0 ) {
		QMessageBox::warning(0, "Error", "Please choose files for conversion!");
		_log->writeError("No files were selected, Error message: 'Please choose files for conversion!'");
    return;
	}
  //Check output path
	if( outputPath == "" ) {
		QMessageBox::warning(0, "Error", "Please set output folder!");
		_log->writeWarn("No output folder selected, Error message: 'Please set output folder!'");
    return;
	}

  //read Subjects information
  if( subjectindexPath == "" ) {
    int ret = QMessageBox::question(this, 
                                    "No subjectindex specified", 
                                    "Do you want to continue without subjectindex?",
                                    QMessageBox::Yes|QMessageBox::No);
    if( ret == QMessageBox::No ) return;
  }else{
    if( ! plugin.loadSubject(subjectindexPath.toStdString()) ){
      QMessageBox::warning(this,"Error", "Error loading Subject file");
      _log->writeWarn("No subject set, Error message: 'Error loading Subject file': " + subjectindexPath.toStdString());
      return;
    }
  }

  //Set Bilder info
  plugin.setPrintPics(true); //print only if the picture is available
  plugin.setUseOffset(use_offset);
  plugin.setBilderPath(imagePath.toStdString());

  //create quality output
  if( quality ){
    if( !plugin.writeQualityHeader(outputPath.toStdString(), qualityPrefix.toStdString() ) ){
      QMessageBox::critical(this,"Error", "Error creating quality output");
      _log->writeError("Error creating quality output");
    }
  }

  //for writting error file
  vector<string> fileError;

  //read Data
  QProgressDialog progressDialog("Loading data, please wait.", "Hide", 0, _fileList.length(), this);
  progressDialog.setAutoClose(true);
  progressDialog.show();
  QWidget     *neues = new QWidget();
  QVBoxLayout *lay   = new QVBoxLayout();
  if( !show_histogram ){ neues->setAttribute(Qt::WA_DontShowOnScreen,true); }
  neues->setLayout(lay);
  //_widgets_open.append(neues); 
  for(int i=0; i<_fileList.length(); i++ ){
    list<Data*> list_data;
    list<string> list_quality;
    progressDialog.setValue(i);
    progressDialog.repaint();
    _log->writeDebug("Processing file: "  + _fileList.at(i).toStdString());

    //parse file
    if( !plugin.parseDataFile(_fileList.at(i).toStdString(), list_data) ){
      //QMessageBox::critical(this,"Error", "Parsing file: " + _fileList.at(i));
      _log->writeError("Parsing file");
      fileError.push_back(_fileList.at(i).toStdString() + ": Parsing file");
      list_data.remove_if ( Data::deleteAll );
      continue;
    }

    //write data output
    vector<string> file_list_error;
    if( !plugin.writeDataOutput(outputPath.toStdString(), list_data, *plugin.getDataExtra(), file_list_error) ){
      //QMessageBox::critical(this,"Error", "Writing output");
      _log->writeError("Writing output");
      fileError.insert( fileError.end(), file_list_error.begin(), file_list_error.end() );
      list_data.remove_if ( Data::deleteAll );
      continue;
    }  

    if( !file_list_error.empty() ){
      fileError.insert( fileError.end(), file_list_error.begin(), file_list_error.end() );
    }

    if(quality){
      //calculate quality
      if( !plugin.calculateQuality(list_data, list_quality) ){
        //QMessageBox::critical(this,"Error", "Calculating Quality");
        _log->writeError("Calculating Quality");
        fileError.push_back(_fileList.at(i).toStdString() + ": Calculating Quality" );
      }else{
        //write quality output
        if( !plugin.writeQualityOutput(list_quality) ){
          //QMessageBox::critical(this,"Error", "Writing quality output");
          _log->writeError("Writing quality output");
          fileError.push_back(_fileList.at(i).toStdString() + ": Writing quality output" );
        }
      }
    }
   
    if( save_histogram || show_histogram ){
      //generate histogram
      generateHistogram(neues, lay, etbutler::extractFileNameFromPath(_fileList.at(i).toStdString()), list_data);
    }

    //deallocate memory of the list
    list_data.remove_if ( Data::deleteAll );
  }

  //save and close the histograms
  finishHistogram(neues, outputPath, qualityPrefix, save_histogram, show_histogram);

  progressDialog.close();

  //write fileError to the output
  writeFileError(fileError, outputPath);

  QMessageBox::information(0, "Information", "The file conversion is done!");
  _log->writeDebug("The file conversion is done!");

  string outputlogfile_path = outputPath.toStdString() + FILE_SLASH + "log.txt";
  _log->copylogfile(outputlogfile_path);
  
}