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(); } }
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; } }