예제 #1
0
void OIFReader::Preprocess()
{
   m_type = 0;
   m_oif_info.clear();

   //separate path and name
   int64_t pos = m_path_name.find_last_of(GETSLASH());
   if (pos == -1)
      return;
   wstring path = m_path_name.substr(0, pos+1);
   wstring name = m_path_name.substr(pos+1);
   //extract time sequence string
   int64_t begin = name.find(m_time_id);
   size_t end = -1;
   size_t id_len = m_time_id.size();
   if (begin != -1)
   {
      wstring t_num;
      size_t j;
      for (j=begin+id_len; j<name.size(); j++)
      {
         wchar_t c = name[j];
         if (iswdigit(c))
            t_num.push_back(c);
         else break;
      }
      if (t_num.size() > 0)
         end = j;
      else
         begin = -1;
   }

   if (begin == -1)
   {
      ReadSingleOif();
   }
   else
   {
      //search time sequence files
      std::vector<std::wstring> list;
      int tmp = 0;
      FIND_FILES(path,L".oif",list,tmp,name.substr(0,begin+id_len+1));
      for(size_t i = 0; i < list.size(); i++) {
         size_t start_idx = list.at(i).find(m_time_id) + id_len;
         size_t end_idx   = list.at(i).find(L".oif");
         size_t size = end_idx - start_idx;
         std::wstring fileno = list.at(i).substr(start_idx, size);
         TimeDataInfo info;
         info.filenumber = WSTOI(fileno);
         info.filename = list.at(i);
         m_oif_info.push_back(info);
      }

      if (m_oif_info.size() > 0)
      {
         m_type = 1;
         std::sort(m_oif_info.begin(), m_oif_info.end(), OIFReader::oif_sort);
         ReadSequenceOif();
      }
      else
      {
         m_oif_info.clear();
         ReadSingleOif();
      }
   }

   ReadOif();

   m_time_num = int(m_oif_info.size());
   if (m_type == 0)
      m_cur_time = 0;
   m_chan_num = m_time_num>0?int(m_oif_info[0].dataset.size()):0;
   m_slice_num = m_chan_num>0?int(m_oif_info[0].dataset[0].size()):0;
}
예제 #2
0
void OIFReader::ReadOifLine(wstring oneline)
{
   //process
   if (oneline.substr(0, 6) == L"[Axis ")
   {
      axis_num++;
   }
   else
   {
      if (axis_num > -1)
      {
         size_t pos = oneline.find(L'=');
         wstring str1 = oneline.substr(0, oneline.find_last_not_of(L' ', pos));
         wstring str2 = oneline.substr(oneline.find_first_not_of(L' ', pos+1));

         if (str1 == L"AxisCode")
         {
            if (cur_axis != axis_num)
            {
               cur_axis = axis_num;
               axis_code.clear();
               pix_unit.clear();
               max_size.clear();
               start_pos.clear();
               end_pos.clear();
            }
            axis_code = str2;
         }
         else if (str1 == L"PixUnit")
         {
            if (cur_axis != axis_num)
            {
               cur_axis = axis_num;
               axis_code.clear();
               pix_unit.clear();
               max_size.clear();
               start_pos.clear();
               end_pos.clear();
            }
            pix_unit = str2;
         }
         else if (str1 == L"MaxSize")
         {
            if (cur_axis != axis_num)
            {
               cur_axis = axis_num;
               axis_code.clear();
               pix_unit.clear();
               max_size.clear();
               start_pos.clear();
               end_pos.clear();
            }
            max_size = str2;
         }
         else if (str1 == L"StartPosition")
         {
            if (cur_axis != axis_num)
            {
               cur_axis = axis_num;
               axis_code.clear();
               pix_unit.clear();
               max_size.clear();
               start_pos.clear();
               end_pos.clear();
            }
            start_pos = str2;
         }
         else if (str1 == L"EndPosition")
         {
            if (cur_axis != axis_num)
            {
               cur_axis = axis_num;
               axis_code.clear();
               pix_unit.clear();
               max_size.clear();
               start_pos.clear();
               end_pos.clear();
            }
            end_pos = str2;
         }
      }
   }
   if (oneline.substr(0, 9) == L"[Channel ")
   {
	  light_type.clear();
      chan_num++;
   }
   else
   {
      if (chan_num > -1)
      {
         size_t pos = oneline.find(L'=');
         wstring str1 = oneline.substr(0, oneline.find_last_not_of(L' ', pos));
         wstring str2 = oneline.substr(oneline.find_first_not_of(L' ', pos+1));
		 wstring str3 = L"Transmitted Light";
		 if (str1 == L"LightType") {
			 light_type = str2;
			 if (light_type.find(str3) != wstring::npos) {
				 for (int i = m_excitation_wavelength_list.size() -1; i >=0; i--) {
					 if (m_excitation_wavelength_list.at(i).chan_num == cur_chan) {
						 m_excitation_wavelength_list.at(i).wavelength = -1;
						 break;
					 }
				 }
			 }
		  }
         else if (str1 == L"ExcitationWavelength")
         {
            if (cur_chan != chan_num)
            {
               cur_chan = chan_num;
               WavelengthInfo info;
               info.chan_num = cur_chan;
               info.wavelength = WSTOD(str2);
				if (light_type == L"Transmitted Light") 
					info.wavelength = -1;
               m_excitation_wavelength_list.push_back(info);
            }
         }
      }
   }

   //axis
   if (!axis_code.empty() &&
         !pix_unit.empty() &&
         !max_size.empty() &&
         !start_pos.empty() &&
         !end_pos.empty())
   {
      //calculate
      double spc = 0.0;
      double dmax = WSTOD(max_size);
      if (dmax > 0.0)
         spc= fabs((WSTOD(end_pos)-
                  WSTOD(start_pos)))/
            dmax;
      if ((int64_t)pix_unit.find(L"nm")!=-1)
         spc /= 1000.0;
      if ((int64_t)axis_code.find(L"X")!=-1)
      {
         m_x_size = WSTOI(max_size);
         m_xspc = spc;
      }
      else if ((int64_t)axis_code.find(L"Y")!=-1)
      {
         m_y_size = WSTOI(max_size);
         m_yspc = spc;
      }
      else if ((int64_t)axis_code.find(L"Z")!=-1)
         m_zspc = spc;

      axis_code.clear();
      pix_unit.clear();
      max_size.clear();
      start_pos.clear();
      end_pos.clear();
   }
}
예제 #3
0
void OIFReader::ReadTifSequence(wstring file_name, int t)
{
   size_t line_size = file_name.size();
   if (file_name.substr(line_size-3, 3) == L"tif")
   {
      //interpret file_name
      int64_t pos;
      int64_t pos_ = file_name.find_last_of(L'_');
      if (pos_!=-1)
      {
         size_t j;
         wstring wstr;
         int num_c = -1;
         int num_z = -1;
         int num_t = -1;
         int num_l = -1;

         //read channel number 'C'
         pos = file_name.find(L'C', pos_+1);
         if (pos!=-1)
         {
            for (j=pos+1; j<file_name.size(); j++)
            {
               if (iswdigit(file_name[j]))
                  wstr.push_back(file_name[j]);
               else
                  break;
            }
            num_c = WSTOI(wstr);
            wstr.clear();
         }
         //read z number 'Z'
         pos = file_name.find(L'Z', pos_+1);
         if (pos!=-1)
         {
            for (j=pos+1; j<file_name.size(); j++)
            {
               if (iswdigit(file_name[j]))
                  wstr.push_back(file_name[j]);
               else
                  break;
            }
            num_z = WSTOI(wstr);
            wstr.clear();
         }
         //read time number 'T'
         pos = file_name.find(L'T', pos_+1);
         if (pos!=-1)
         {
            for (j=pos+1; j<file_name.size(); j++)
            {
               if (iswdigit(file_name[j]))
                  wstr.push_back(file_name[j]);
               else
                  break;
            }
            num_t = WSTOI(wstr);
            wstr.clear();
         }
         //read lambda number 'L'
         pos = file_name.find(L'L', pos_+1);
         if (pos!=-1)
         {
            for (j=pos+1; j<file_name.size(); j++)
            {
               if (iswdigit(file_name[j]))
                  wstr.push_back(file_name[j]);
               else
                  break;
            }
            num_l = WSTOI(wstr);
            wstr.clear();
         }

         //add info to the list
         num_c = num_c==-1?0:num_c-1;
         num_t = num_t==-1?t:num_t-1;
         num_z = num_z==-1?1:num_z;
         if (num_z > 0)
         {
            num_z--;
            //allocate
            if (m_type == 0)
            {
               if (int(m_oif_info.size()) < num_t+1)
                  m_oif_info.resize(num_t+1);
               if (int(m_oif_info[num_t].dataset.size()) < num_c+1)
                  m_oif_info[num_t].dataset.resize(num_c+1);
               if (int(m_oif_info[num_t].dataset[num_c].size()) < num_z+1)
                  m_oif_info[num_t].dataset[num_c].resize(num_z+1);
               //add
               m_oif_info[num_t].dataset[num_c][num_z] = file_name;
            }
            else
            {
               //if (num_t == 0)
               {
                  if (int(m_oif_info[num_t].dataset.size()) < num_c+1)
                     m_oif_info[num_t].dataset.resize(num_c+1);
                  if (int(m_oif_info[num_t].dataset[num_c].size()) < num_z+1)
                     m_oif_info[num_t].dataset[num_c].resize(num_z+1);
                  //add
                  m_oif_info[num_t].dataset[num_c][num_z] = file_name;
               }
            }
         }
      }
   }
}
예제 #4
0
void NRRDReader::Preprocess()
{
   m_4d_seq.clear();

   //separate path and name
   int64_t pos = m_path_name.find_last_of(GETSLASH());
   if (pos == -1)
      return;
   wstring path = m_path_name.substr(0, pos+1);
   wstring name = m_path_name.substr(pos+1);
   //generate search name for time sequence
   int64_t begin = name.find(m_time_id);
   size_t end = -1;
   size_t id_len = m_time_id.size();
   wstring t_num;
   if (begin != -1)
   {
      size_t j;
      for (j=begin+id_len; j<name.size(); j++)
      {
         wchar_t c = name[j];
         if (iswdigit(c))
            t_num.push_back(c);
         else
            break;
      }
      if (t_num.size() > 0)
         end = j;
      else
         begin = -1;
   }
   //build 4d sequence
   if (begin == -1)
   {
      TimeDataInfo info;
      info.filenumber = 0;
      info.filename = m_path_name;
      m_4d_seq.push_back(info);
      m_cur_time = 0;
   }
   else
   {
      //search time sequence files
      std::vector<std::wstring> list;
      int tmp = 0;
      FIND_FILES(path,L".nrrd",list,tmp,name.substr(0,begin+id_len+1));
      for(size_t i = 0; i < list.size(); i++) {
         size_t start_idx = list.at(i).find(m_time_id) + id_len;
         size_t end_idx   = list.at(i).find(L".nrrd");
         size_t size = end_idx - start_idx;
         std::wstring fileno = list.at(i).substr(start_idx, size);
         TimeDataInfo info;
         info.filenumber = WSTOI(fileno);
         info.filename = list.at(i);
         m_4d_seq.push_back(info);
      }
   }
   if (m_4d_seq.size() > 0)
   {
      std::sort(m_4d_seq.begin(), m_4d_seq.end(), NRRDReader::nrrd_sort);
      for (int t=0; t<(int)m_4d_seq.size(); t++)
      {
         if (m_4d_seq[t].filename == m_path_name)
         {
            m_cur_time = t;
            break;
         }
      }
   }
   else
      m_cur_time = 0;

   //3D nrrd file
   m_chan_num = 1;
   //get time number
   m_time_num = (int)m_4d_seq.size();
}
예제 #5
0
void OIBReader::ReadOif(unsigned char *pbyData, size_t size)
{
	if (!pbyData || !size)
		return;
	
	//reset
	m_excitation_wavelength_list.clear();
	m_x_size = 0;
	m_y_size = 0;
	m_xspc = 0.0;
	m_yspc = 0.0;
	m_zspc = 0.0;

	uint16_t* data = (uint16_t*)pbyData;

	size_t i = 1;
	wstring oneline;

	//axis info
	wstring axis_code;
	wstring pix_unit;
	wstring max_size;
	wstring start_pos;
	wstring end_pos;

	//axis count
	int axis_num = -1;
	int cur_axis = -1;
	//channel count
	int chan_num = -1;
	int cur_chan = -1;

	while (i<size/2)
	{
		if (data[i] != L'\n')
		{
			oneline.push_back(data[i]);
		}
		else
		{
			//process
			if (oneline.substr(0, 6) == L"[Axis ")
			{
				axis_num++;
			}
			else
			{
				if (axis_num > -1)
				{
					size_t pos = oneline.find(L'=');
					wstring str1 = oneline.substr(0, oneline.find_last_not_of(L' ', pos));
					wstring str2 = oneline.substr(oneline.find_first_not_of(L' ', pos+1));

					if (str1 == L"AxisCode")
					{
						if (cur_axis != axis_num)
						{
							cur_axis = axis_num;
							axis_code.clear();
							pix_unit.clear();
							max_size.clear();
							start_pos.clear();
							end_pos.clear();
						}
						axis_code = str2;
					}
					else if (str1 == L"PixUnit")
					{
						if (cur_axis != axis_num)
						{
							cur_axis = axis_num;
							axis_code.clear();
							pix_unit.clear();
							max_size.clear();
							start_pos.clear();
							end_pos.clear();
						}
						pix_unit = str2;
					}
					else if (str1 == L"MaxSize")
					{
						if (cur_axis != axis_num)
						{
							cur_axis = axis_num;
							axis_code.clear();
							pix_unit.clear();
							max_size.clear();
							start_pos.clear();
							end_pos.clear();
						}
						max_size = str2;
					}
					else if (str1 == L"StartPosition")
					{
						if (cur_axis != axis_num)
						{
							cur_axis = axis_num;
							axis_code.clear();
							pix_unit.clear();
							max_size.clear();
							start_pos.clear();
							end_pos.clear();
						}
						start_pos = str2;
					}
					else if (str1 == L"EndPosition")
					{
						if (cur_axis != axis_num)
						{
							cur_axis = axis_num;
							axis_code.clear();
							pix_unit.clear();
							max_size.clear();
							start_pos.clear();
							end_pos.clear();
						}
						end_pos = str2;
					}
				}
			}
			if (oneline.substr(0, 9) == L"[Channel ")
			{
				light_type.clear();
				chan_num++;
			}
			else
			{
				if (chan_num > -1)
				{
					size_t pos = oneline.find(L'=');
					wstring str1 = oneline.substr(0, oneline.find_last_not_of(L' ', pos));
					wstring str2 = oneline.substr(oneline.find_first_not_of(L' ', pos+1));
					wstring str3 = L"Transmitted Light";
					if (str1 == L"LightType") {
						light_type = str2;
						if (light_type.find(str3) != wstring::npos) {
							for (int i = m_excitation_wavelength_list.size() - 1; i >= 0; i--) {
								if (m_excitation_wavelength_list.at(i).chan_num == cur_chan) {
									m_excitation_wavelength_list.at(i).wavelength = -1;
									break;
								}
							}
						}
					}
					else if (str1 == L"ExcitationWavelength")
					{
						if (cur_chan != chan_num)
						{
							cur_chan = chan_num;
							WavelengthInfo info;
							info.chan_num = cur_chan;
							info.wavelength = WSTOD(str2.c_str());
							if (light_type == L"Transmitted Light")
								info.wavelength = -1;
							m_excitation_wavelength_list.push_back(info);
						}
					}
				}
			}
			//clear
			oneline.clear();
		}

		//axis
		if (!axis_code.empty() &&
			!pix_unit.empty() &&
			!max_size.empty() &&
			!start_pos.empty() &&
			!end_pos.empty())
		{ 
			//calculate
			double spc = 0.0;
			double dmax = WSTOD(max_size.c_str());
			if (dmax > 0.0)
				spc= fabs((WSTOD(end_pos.c_str())-
					WSTOD(start_pos.c_str())))/
					dmax;
			if ((int64_t)pix_unit.find(L"nm")!=-1)
				spc /= 1000.0;
			if ((int64_t)axis_code.find(L"X")!=-1)
			{
				m_x_size = WSTOI(max_size.c_str());
				m_xspc = spc;
			}
			else if ((int64_t)axis_code.find(L"Y")!=-1)
			{
				m_y_size = WSTOI(max_size.c_str());
				m_yspc = spc;
			}
			else if ((int64_t)axis_code.find(L"Z")!=-1)
				m_zspc = spc;

			axis_code.clear();
			pix_unit.clear();
			max_size.clear();
			start_pos.clear();
			end_pos.clear();
		}

		i++;
	}

	if (m_xspc>0.0 && m_xspc<100.0 &&
		m_yspc>0.0 && m_yspc<100.0)
	{
		m_valid_spc = true;
		if (m_zspc<=0.0 || m_zspc>100.0)
			m_zspc = max(m_xspc, m_yspc);
	}
	else
	{
		m_valid_spc = false;
		m_xspc = 1.0;
		m_yspc = 1.0;
		m_zspc = 1.0;
	}
}
예제 #6
0
void OIBReader::ReadOibInfo(unsigned char* pbyData, size_t size)
{
	if (!pbyData || !size)
		return;
	uint16_t * data = (uint16_t *)pbyData;

	size_t i = 1;
	wstring oneline;

	while (i<size/2)
	{
		if (data[i] != L'\n')
		{
			oneline.push_back(data[i]);
		}
		else
		{
			//process
			size_t line_size = oneline.size();
			if (oneline.substr(line_size-3, 3) == L"oif")
			{
				if (m_type==0 || (m_type==1&&m_oib_t==m_cur_time))
				{
					size_t pos = oneline.find(L'=');
					m_oif_name = oneline.substr(0, oneline.find_last_not_of(L' ', pos));
					m_data_name = oneline.substr(oneline.find_first_not_of(L' ', pos+1));
					m_data_name = m_data_name.substr(0, m_data_name.find_last_of(L'.')) + L".oib";
				}
			}
			else if (oneline.substr(0, 7) == L"Storage")
			{
				size_t pos = oneline.find(L'=');
				wstring name = oneline.substr(0, oneline.find_last_not_of(L' ', pos));
				if (m_type == 0)
					m_substg_name = name;
				else
					m_oib_info[m_oib_t].substgname = name;
			}
			else if (oneline.substr(line_size-3, 3) == L"tif")
			{
				int64_t pos1 = oneline.find(L'=');
				int64_t pos2 = oneline.find_last_of(L'/');
				pos2 = pos2==-1?oneline.find_last_of(L'\\'):pos2;
				if (pos1!=-1 && pos2!=-1)
				{
					wstring stream_name;
					wstring file_name;
					stream_name = oneline.substr(0, oneline.find_last_not_of(L' ', pos1));
					file_name = oneline.substr(oneline.find_first_not_of(L' ', pos2+1));

					//interpret file_name
					int64_t pos;
					int64_t pos_ = file_name.find_last_of(L'_');
					if (pos_!=-1)
					{
						size_t j;
						wstring wstr;
						int num_c = -1;
						int num_z = -1;
						int num_t = -1;
						int num_l = -1;

						//read channel number 'C'
						pos = file_name.find(L'C', pos_+1);
						if (pos!=-1)
						{
							for (j=pos+1; j<file_name.size(); j++)
							{
								if (iswdigit(file_name[j]))
									wstr.push_back(file_name[j]);
								else
									break;
							}
							num_c = WSTOI(wstr.c_str());
							wstr.clear();
						}
						//read z number 'Z'
						pos = file_name.find(L'Z', pos_+1);
						if (pos!=-1)
						{
							for (j=pos+1; j<file_name.size(); j++)
							{
								if (iswdigit(file_name[j]))
									wstr.push_back(file_name[j]);
								else
									break;
							}
							num_z = WSTOI(wstr.c_str());
							wstr.clear();
						}
						//read time number 'T'
						pos = file_name.find(L'T', pos_+1);
						if (pos!=-1)
						{
							for (j=pos+1; j<file_name.size(); j++)
							{
								if (iswdigit(file_name[j]))
									wstr.push_back(file_name[j]);
								else
									break;
							}
							num_t = WSTOI(wstr.c_str());
							wstr.clear();
						}
						//read lambda number 'L'
						pos = file_name.find(L'L', pos_+1);
						if (pos!=-1)
						{
							for (j=pos+1; j<file_name.size(); j++)
							{
								if (iswdigit(file_name[j]))
									wstr.push_back(file_name[j]);
								else
									break;
							}
							num_l = WSTOI(wstr.c_str());
							wstr.clear();
						}

						//add info to the list
						num_c = num_c==-1?0:num_c-1;
						num_t = num_t==-1?0:num_t-1;
						num_z = num_z==-1?1:num_z;
						if (num_z > 0)
						{
							num_z--;
							//allocate
							if (m_type == 0)
							{
								if (int(m_oib_info.size()) < num_t+1)
									m_oib_info.resize(num_t+1);
								if (int(m_oib_info[num_t].dataset.size()) < num_c+1)
									m_oib_info[num_t].dataset.resize(num_c+1);
								if (int(m_oib_info[num_t].dataset[num_c].size()) < num_z+1)
									m_oib_info[num_t].dataset[num_c].resize(num_z+1);
								//add
								m_oib_info[num_t].dataset[num_c][num_z].file_name = file_name;
								m_oib_info[num_t].dataset[num_c][num_z].stream_name = stream_name;
							}
							else
							{
								if (num_t == 0)
								{
									if (int(m_oib_info[m_oib_t].dataset.size()) < num_c+1)
										m_oib_info[m_oib_t].dataset.resize(num_c+1);
									if (int(m_oib_info[m_oib_t].dataset[num_c].size()) < num_z+1)
										m_oib_info[m_oib_t].dataset[num_c].resize(num_z+1);
									//add
									m_oib_info[m_oib_t].dataset[num_c][num_z].file_name = file_name;
									m_oib_info[m_oib_t].dataset[num_c][num_z].stream_name = stream_name;
								}
							}
						}
					}
				}
			}
			//clear
			oneline.clear();
		}

		i++;
	}
}