Exemplo n.º 1
0
int main(int argc, char *argv[])
{
	FILE *regfile;
	FILE *posfile;
	FILE *logfile;
	FILE *dualfcoffsetfile;

	fpos_t offsetval;

	char regfilename[200];
	char logfilename[200];
	char log_string[255];

	int i, j, k, l;
	int curr_fc, curr_array, curr_img, curr_numobjs;
	int num_fcs;

	short unsigned int *curr_img_x;
	short unsigned int *curr_img_y;
	short unsigned int *regindices;
	short unsigned int temp;

	srand((unsigned)time(NULL) );
	srandom((unsigned)time(NULL));

	start_logger((char*)"initialize_processor-log", 1);
 
	if(argc !=3 )
	{
		sprintf(log_string, "Usage: %s <Position file> <Number of flowcells>", argv[0]);
		p_log(log_string);
		exit(0);
	}

	num_fcs = atoi(argv[2]);
	if( (dualfcoffsetfile = fopen("DUAL_FC_REGOFFSET.dat", "wb"))==NULL)
	{
		sprintf(log_string, "ERROR opening offset file DUAL_FC_REGOFFSET.dat for output");
		p_log_errorno(log_string);
		exit(0);
	}

	if((curr_img_x = (short unsigned int*) malloc(MAX_BEADS_PERFRAME * sizeof(short unsigned int))) == NULL)
	{
		p_log_errorno((char*)"ERROR allocating memory for curr_img_x");
		exit(0);
	}
	if((curr_img_y = (short unsigned int*) malloc(MAX_BEADS_PERFRAME * sizeof(short unsigned int))) == NULL)
	{
		p_log_errorno((char*)"ERROR allocating memory for curr_img_y");
		exit(0);
	}
	if((regindices = (short unsigned int*) malloc(REG_PIXELS * sizeof(short unsigned int))) == NULL)
	{
		p_log_errorno((char*)"ERROR allocating memory for regindices");
		exit(0);
	}

	strcpy(regfilename, argv[1]);
	strcat(regfilename, ".reg");
	sprintf(log_string, "Generating .reg file %s from position file %s with %d beads per image (random)",
	regfilename,
	argv[1],
	REG_PIXELS);
	p_log(log_string);

	strcpy(logfilename, argv[1]);
	strcat(logfilename, ".reglog");
	sprintf(log_string, "Logging positions used to file %s", logfilename);
	p_log(log_string);
  
	if( (posfile=fopen(argv[1], "rb")) == NULL)
	{
		sprintf(log_string, "ERROR opening position file %s for input", argv[1]);
		p_log_errorno(log_string);
		exit(0);
	}
	if( (regfile=fopen(regfilename, "wb")) == NULL)
	{
		sprintf(log_string, "ERROR opening reg file %s for output", argv[2]);
		p_log_errorno(log_string);
		exit(0);
	}
	if( (logfile=fopen(logfilename, "wb")) == NULL)
	{
		sprintf(log_string, "ERROR opening reglog file %s for output", argv[2]);
		p_log_errorno(log_string);
		exit(0);
	}


	// loop through FC, ARRAY, IMAGE:
	for(i=0; i < num_fcs; i++)
	{
		for(j=0; j < ARRAYS_PER_FC; j++)
		{
			for(k=0; k < IMGS_PER_ARRAY; k++)
			{
				// load positions for current image
				// ------
				// each 'record' in the pos file is as follows:
				// 4 bytes:  -1
				// 4 bytes:  flowcell # ([0..num_fcs])
				// 4 bytes:  array #    ([0..ARRAYS_PER_FC])
				// 4 bytes:  image #    ([0..IMGS_PER_ARRAY])
				// 4 bytes:  # of beads
				// 2 bytes:  beadpos_xcol
				// 2 bytes:  beadpos_yrow
				// ...
				// 2 bytes:  0
				//
				// ------

				if( (fread(&curr_fc, sizeof(int), 1, posfile)) < 1){
					p_log_errorno((char*)"ERROR reading curr_fc(1) from posfile");
				}
				if( (fread(&curr_fc, sizeof(int), 1, posfile)) < 1){
					p_log_errorno((char*)"ERROR reading curr_fc(2) from posfile");
				}
				if( (fread(&curr_array, sizeof(int), 1, posfile)) < 1){
					p_log_errorno((char*)"ERROR reading curr_array from posfile");
				}
				if( (fread(&curr_img, sizeof(int), 1, posfile)) < 1){
					p_log_errorno((char*)"ERROR reading curr_img from posfile");
				}
				if( (fread(&curr_numobjs, sizeof(int), 1, posfile)) < 1){
					p_log_errorno((char*)"ERROR reading curr_numobjs from posfile");
				}

				// make sure we are where we think we are in the position file
				if( (curr_fc != i) || (curr_array != j)|| (curr_img != k))
				{
					sprintf(log_string, "ERROR: expecting %d %d %d from position file, and read %d %d %d",
									i, j, k,
									curr_fc, curr_array, curr_img);
					p_log(log_string);
					exit(0);
				}

				sprintf(log_string, "Position %d %d %d... %d objects", i, j, k, curr_numobjs);
				p_log(log_string);

				for(l=0; l < curr_numobjs; l++)
				{
					if((fread(curr_img_x+l, sizeof(short unsigned int), 1, posfile)) < 1)
					{
						sprintf(log_string, "ERROR reading x from posfile at %d %d %d %d",
									i, j, k, l);
						p_log_errorno(log_string);
					}
					if((fread(curr_img_y+l, sizeof(short unsigned int), 1, posfile)) < 1)
					{
						sprintf(log_string, "ERROR reading y from posfile at %d %d %d %d",
								i, j, k, l);
						p_log_errorno(log_string);
					}
				}

				// make sure we are where we think we are in the position file
				if( (fread(&temp, sizeof(short unsigned int), 1, posfile)) < 1)
				{
					p_log_errorno((char*)"ERROR reading curr_img from posfile");
				}
				if(temp != 0)
				{
					sprintf(log_string, "ERROR: expecting delimiter value of 0, read %d", temp);
					p_log(log_string);
					exit(0);
				}


				// generate list of random coords and log to reglog, 2 bytes per position
				// as we generate them, output corresponding position values to regfile
				for(l = 0; l < REG_PIXELS; l++)
				{
					if(curr_numobjs < 100)
					{
						*(regindices + l) = randdist(0, NUM_XCOLS-1);
					}
					else
					{
						*(regindices + l) = randdist(0, curr_numobjs-1);
					}
					if((fwrite(regindices+l, sizeof(short unsigned int), 1, logfile)) < 1)
					{
						sprintf(log_string, "ERROR writing to reglog at %d %d %d %d", i, j, k, l);
						p_log_errorno(log_string);
						exit(0);
					}
	  
					if((fwrite(curr_img_x+(*(regindices+l)), sizeof(short unsigned int), 1, regfile)) < 1)
					{
						sprintf(log_string, "ERROR writing x to regfile at %d %d %d %d: %d",
							i,j,k,l,*(regindices+l));
						p_log_errorno(log_string);
						exit(0);
					}
					if((fwrite(curr_img_y+(*(regindices+l)), sizeof(short unsigned int), 1, regfile)) < 1)
					{
						sprintf(log_string, "ERROR writing y to regfile at %d %d %d %d: %d",
							i,j,k,l,*(regindices+l));	
						p_log_errorno(log_string);
						exit(0);
					}
				}
			} // end for k
		} // end for j
		if( i == 0 )
		{
			fgetpos(regfile, &offsetval);
			fwrite(&offsetval, sizeof(fpos_t), 1, dualfcoffsetfile);
			fclose(dualfcoffsetfile);
		}
	} // end for i
	fclose(posfile);
	fclose(regfile);
}
Exemplo n.º 2
0
TestMRPPWindow::TestMRPPWindow(HWND parent, std::string title) : MRPWindow(parent, title)
{
	for (int i = 0; i < 8; ++i)
	{
		auto but = std::make_shared<WinButton>(this, std::to_string(i));
		but->GenericNotifyCallback = [i](GenericNotifications)
		{
			readbg() << "you pressed " << i << "\n";
		};
		add_control(but);
	}
	// Button 0 toggless enabled state of button 1
	m_controls[0]->GenericNotifyCallback = [this](GenericNotifications)
	{
		m_controls[1]->setEnabled(!m_controls[1]->isEnabled());
	};
	m_envcontrol1 = std::make_shared<EnvelopeControl>(this);

	// Button 3 toggless enabled state of envelope control
	m_controls[3]->GenericNotifyCallback = [this](GenericNotifications)
	{
		m_envcontrol1->setEnabled(!m_envcontrol1->isEnabled());
	};

	// Button 7 toggless visible state of button 0
	m_controls[7]->GenericNotifyCallback = [this](GenericNotifications)
	{
		m_controls[0]->setVisible(!m_controls[0]->isVisible());
	};
	auto env = std::make_shared<breakpoint_envelope>("foo", LICE_RGBA(255, 255, 255, 255));
	env->add_point({ 0.0, 0.5 , envbreakpoint::Power, 0.5 }, true);
	env->add_point({ 0.5, 0.0 , envbreakpoint::Power, 0.5 }, true);
	env->add_point({ 1.0, 0.5 }, true);
	m_envcontrol1->add_envelope(env);

	m_envcontrol1->GenericNotifyCallback = [this, env](GenericNotifications reason)
	{
		//if (reason == GenericNotifications::AfterManipulation)
		//	generate_items_sequence(env, m_edit1->getText().c_str());
	};

	add_control(m_envcontrol1);

	// Button 5 does some Xenakios silliness
	m_controls[5]->GenericNotifyCallback = [this, env](GenericNotifications)
	{
		generate_items_sequence(env, m_edit1->getText().c_str());
	};

	m_label1 = std::make_shared<WinLabel>(this, "This is a label");
	add_control(m_label1);

	m_edit1 = std::make_shared<WinLineEdit>(this, "C:/MusicAudio/pihla_ei/ei_mono_005.wav");
	add_control(m_edit1);
	m_edit1->TextCallback = [this](std::string txt)
	{
		m_label1->setText(txt);
	};
	// Button 6 launches bogus work in another thread to demo progress bar
	m_controls[6]->GenericNotifyCallback = [this](GenericNotifications)
	{
		m_progressbar1->setVisible(true);
		// we don't deal with multiple background tasks now, so disable the button to start the task
		m_controls[6]->setEnabled(false);
		static int rseed = 0;
		auto task = [this](int randseed)
		{
			std::mt19937 randgen(randseed);
			std::uniform_real_distribution<double> randdist(0.0, 1.0);
			double accum = 0.0;
			const int iterations = 50000000;
			double t0 = time_precise();
			for (int i = 0; i < iterations; ++i)
			{
				accum += randdist(randgen);
				//accum += randdist(randgen);
				// Production code should not do this at this granularity, because setProgressValue deals with
				// an atomic value. but this is just a demo...
				m_progressbar1->setProgressValue(1.0 / iterations*i);
			}
			double t1 = time_precise();
			auto finishtask = [=]()
			{
				m_edit1->setText(std::to_string(accum) + " elapsed time " + std::to_string(t1-t0));
				m_progressbar1->setProgressValue(0.0);
				m_progressbar1->setVisible(false);
				m_controls[6]->setEnabled(true);
			};
			execute_in_main_thread(finishtask);
		};
		m_future1 = std::async(std::launch::async, task, rseed);
		++rseed;
	};
	// Button 1 shows popup menu
	m_controls[1]->GenericNotifyCallback = [this, env](GenericNotifications)
	{
		PopupMenu popmenu(getWindowHandle());
		popmenu.add_menu_item("Menu entry 1", [](PopupMenu::CheckState) {});
		popmenu.add_menu_item("Menu entry 2", m_menuitem2state, [this](PopupMenu::CheckState cs)
		{
			m_menuitem2state = cs;
		});
		popmenu.add_menu_item("Menu entry 3", m_menuitem3state, [this](PopupMenu::CheckState cs) 
		{
			m_menuitem3state = cs;
		});
		PopupMenu submenu(getWindowHandle());
		submenu.add_menu_item("Submenu entry 1", [](PopupMenu::CheckState) { readbg() << "submenu entry 1\n"; });
		submenu.add_menu_item("Submenu entry 2", [](PopupMenu::CheckState) { readbg() << "submenu entry 2\n"; });
		PopupMenu subsubmenu(getWindowHandle());
		for (int i = 0; i < 8; ++i)
		{
			subsubmenu.add_menu_item(std::string("Subsubmenu entry ") + std::to_string(i + 1), [i](PopupMenu::CheckState) 
			{
				readbg() << "subsubmenu entry " << i + 1 << "\n";
			});
		}
		submenu.add_submenu("Going still deeper", subsubmenu);
		popmenu.add_submenu("More stuff", submenu);
		popmenu.execute(m_controls[1]->getXPosition(), m_controls[1]->getYPosition());
	};
	// Button 4 removes envelope points with value over 0.5
	m_controls[4]->GenericNotifyCallback = [this, env](GenericNotifications)
	{
		env->remove_points_conditionally([](const envbreakpoint& pt)
		{ return pt.get_y() > 0.5; });
		m_envcontrol1->repaint();
	};
	m_combo1 = std::make_shared<WinComboBox>(this);
	m_combo1->addItem("Apple", -9001);
	m_combo1->addItem("Pear", 666);
	m_combo1->addItem("Kiwi", 42);
	m_combo1->addItem("Banana", 100);
	m_combo1->SelectedChangedCallback = [this](int index)
	{
		int user_id = m_combo1->userIDfromIndex(index);
		readbg() << "combo index " << index << " userid " << user_id << "\n";
	};
	add_control(m_combo1);
	m_combo1->setSelectedUserID(42);

	m_combo2 = std::make_shared<WinComboBox>(this);
	m_combo2->addItem("Item 1", 100);
	m_combo2->addItem("Item 2", 101);
	m_combo2->addItem("Item 3", 102);
	m_combo2->addItem("Item 4", 103);
	m_combo2->SelectedChangedCallback = [this](int index)
	{
		int user_id = m_combo2->userIDfromIndex(index);
		readbg() << "combo index " << index << " userid " << user_id << "\n";
	};
	add_control(m_combo2);
	m_combo2->setSelectedIndex(0);

	m_slider1 = std::make_shared<ReaSlider>(this, 0.5);
	//m_slider1->setValueConverter(std::make_shared<FFTSizesValueConverter>());
	m_slider1->SliderValueCallback = [this](GenericNotifications, double x)
	{
		m_label1->setText(std::to_string(x));
		m_progressbar1->setProgressValue(x);
	};
	add_control(m_slider1);
	m_zoomscroll1 = std::make_shared<ZoomScrollBar>(this);
	add_control(m_zoomscroll1);
	m_zoomscroll1->RangeChangedCallback = [this](double t0, double t1)
	{
		m_envcontrol1->setViewTimeRange(t0, t1);
	};

	m_progressbar1 = std::make_shared<ProgressControl>(this);
	m_progressbar1->setVisible(false);
}