void GaborFilterModel::trainCarFilter()
{
		
	int32_t rank = MPI::COMM_WORLD.Get_rank();
	string s2file_un = "";
	string c2file_un = "";
	keyfile      = keydir    + OSPATHSEP + "train.key" ;
	patchposfile = pposdir   + OSPATHSEP + "train.ploc";
	s2file       = s2dir     + OSPATHSEP + "train.s2";
	s2file_un    = s2dir     + OSPATHSEP + "train.s2.unsorted";
	c2file       = c2dir     + OSPATHSEP + "train.c2";
	c2file_un    = c2dir     + OSPATHSEP + "train.c2.unsorted";
	svmtrfile    = svmtrdir  + OSPATHSEP + "train.svmtr"; 	
	svmmofile    = svmmodir  + OSPATHSEP + "train.svmmo"; 

	if ( rank == 0 ) // Single Host 
	{
		createKeyFile(trdir,keyfile);
		readKeyFile(keyfile);
		createRandomPatches(patchposfile); 
		calcS2(s2file_un);
		s2file = s2dir + OSPATHSEP + "train.s2"; // reset s2 file name as it is overwritten
		sortS2(s2file_un,s2file);
		readKeyFile(keyfile);
		calcFVStage1(s2file,patchposfile);
		calcFVStage2(c2file_un);
		c2file = c2dir + OSPATHSEP + "train.c2";
		sortS2(c2file_un,c2file);
		convC2ToSVM(c2file,svmtrfile,this->FVDim);
		svmtrain(svmtrfile,svmmofile);
	}

}
void GaborFilterModel::testCarFilter()
{
	int32_t rank = MPI::COMM_WORLD.Get_rank();
	string trkeyfile = keydir    + OSPATHSEP + "train.key" ;
	string tekeyfile = keydir    + OSPATHSEP + "test.key" ;
	patchposfile     = pposdir   + OSPATHSEP + "train.ploc";
	string trs2file  = s2dir     + OSPATHSEP + "train.s2";
	string tes2file  = s2dir     + OSPATHSEP + "test.s2";
	string tes2file_un  = s2dir     + OSPATHSEP + "test.s2.unsorted";
	c2file           = c2dir     + OSPATHSEP + "test.c2";
	string c2file_un = c2dir     + OSPATHSEP + "test.c2.unsorted";
	svmmofile        = svmmodir  + OSPATHSEP + "train.svmmo"; 
	svmtefile        = svmtedir  + OSPATHSEP + "train.svmte"; 
	svmoufile        = svmoudir  + OSPATHSEP + "train.svmou"; 
	
	if ( rank == 0 ) // Single host
	{
		keyfile = trkeyfile;
		readKeyFile(trkeyfile);
		s2file = trs2file;
		calcFVStage1(s2file,patchposfile);

		// At this moment vpatch has S2 patches of training images .. OK
		// .. but vmmat also has S2 patches of training images ..
		// .. so we need to flush them and bring in S2 features of test images
		s2file = tes2file_un;  // Change S2 file name
		keyfile = tekeyfile; // Change the key file name
		createKeyFile(tedir,tekeyfile); // Create key file of test images
		readKeyFile(tekeyfile); // Change Key file name and read key file for test images
		calcS2(s2file); // Calculate S2 features for test images ( note S2 features do not require patches)
		s2file = tes2file;
		sortS2(tes2file_un,s2file);
		readS2File(s2file); // S2 file written is read in memory for calling calcFVStage2

		// Now, perform C2 computations 
		calcFVStage2(c2file_un); // Calculate C2 features
		c2file = c2dir + OSPATHSEP + "test.c2";
		sortS2(c2file_un,c2file);
		convC2ToSVM(c2file,svmtefile,this->FVDim);
		// Run SVM predict
		stringstream svmtecmdstr;
		svmtecmdstr << svmpredexe <<  " " <<  svmtefile << " " << svmmofile << " " << svmoufile;
		string svmtecmd = svmtecmdstr.str();
		CERR << svmtecmd.c_str() << endl;
		system(svmtecmd.c_str()); // Execute SVM predict 
		perror(0); // Report error if any in the system call

	}


}
ChangeMasterKeyWidget::ChangeMasterKeyWidget(QWidget* parent)
    : DialogyWidget(parent)
    , m_ui(new Ui::ChangeMasterKeyWidget())
{
    m_ui->setupUi(this);

    connect(m_ui->buttonBox, SIGNAL(accepted()), SLOT(generateKey()));
    connect(m_ui->buttonBox, SIGNAL(rejected()), SLOT(reject()));
    m_ui->togglePasswordButton->setIcon(filePath()->onOffIcon("actions", "password-show"));
    connect(m_ui->togglePasswordButton, SIGNAL(toggled(bool)), m_ui->enterPasswordEdit, SLOT(setShowPassword(bool)));
    m_ui->repeatPasswordEdit->enableVerifyMode(m_ui->enterPasswordEdit);
    connect(m_ui->createKeyFileButton, SIGNAL(clicked()), SLOT(createKeyFile()));
    connect(m_ui->browseKeyFileButton, SIGNAL(clicked()), SLOT(browseKeyFile()));
}