Skip to content
This repository has been archived by the owner on May 23, 2023. It is now read-only.

Commit

Permalink
change GUI and update csv reader
Browse files Browse the repository at this point in the history
  • Loading branch information
takashi310 committed Feb 23, 2023
1 parent bf43d0a commit 6e50b4e
Show file tree
Hide file tree
Showing 4 changed files with 132 additions and 66 deletions.
4 changes: 2 additions & 2 deletions fluorender/FluoRender/BrushToolDlg.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -399,7 +399,7 @@ wxWindow* BrushToolDlg::CreateCalculationPage(wxWindow *parent)
new wxStaticBox(page, wxID_ANY,
"Single-valued Operators (Require A)"), wxVERTICAL);
//sizer3
m_calc_fill_btn = new wxButton(page, ID_CalcFillBtn, "Consolidate Voxels",
m_calc_fill_btn = new wxButton(page, ID_CalcFillBtn, "3D Fill Holes",
wxDefaultPosition, wxDefaultSize);
sizer3->Add(m_calc_fill_btn, 0, wxEXPAND);
//two operators
Expand All @@ -408,7 +408,7 @@ wxWindow* BrushToolDlg::CreateCalculationPage(wxWindow *parent)
"Two-valued Operators (Require both A and B)"), wxHORIZONTAL);
m_calc_sub_btn = new wxButton(page, ID_CalcSubBtn, "Subtract",
wxDefaultPosition, wxSize(50, 25));
m_calc_add_btn = new wxButton(page, ID_CalcAddBtn, "Add",
m_calc_add_btn = new wxButton(page, ID_CalcAddBtn, "Max",
wxDefaultPosition, wxSize(50, 25));
m_calc_div_btn = new wxButton(page, ID_CalcDivBtn, "Divide",
wxDefaultPosition, wxSize(50, 25));
Expand Down
180 changes: 117 additions & 63 deletions fluorender/FluoRender/Formats/swc_reader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -485,78 +485,132 @@ void SWCReader::SetFile(wstring &file)

void SWCReader::Preprocess()
{
if (!m_vertices.empty()) m_vertices.clear();
if (!m_edges.empty()) m_edges.clear();
if (!m_vertices.empty()) m_vertices.clear();
if (!m_edges.empty()) m_edges.clear();
if (!m_extra_data.empty()) m_extra_data.clear();
// if (!m_group_names.empty()) m_group_names.clear();
// if (!m_v_group_id.empty()) m_v_group_id.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);

ifstream ifs(ws2s(m_path_name));
if (ifs.fail())
{
cerr << "file open error: " << ws2s(m_path_name) << endl;
return;
}

//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);

ifstream ifs(ws2s(m_path_name));
if (ifs.fail())
{
cerr << "file open error: " << ws2s(m_path_name) << endl;
return;
}

string line, token;
vector<vector<string>> str_data;
map<int, int> id_corresp;
int maxid = 0;
while (getline(ifs, line))
{
if (line.empty() || line[0] == '#')
continue;
stringstream ls(line);
vector<string> tokens = split(line, " ", "#");
if (tokens.size() >= 7)
{
glm::vec4 v4;
float fval;
int ival;
int id = STOI(tokens[0].c_str());
fval = STOD(tokens[2].c_str());
v4.x = fval;
fval = STOD(tokens[3].c_str());
v4.y = fval;
fval = STOD(tokens[4].c_str());
v4.z = -fval;
if (tokens[5] != "NA")
{
fval = STOD(tokens[5].c_str());
v4.w = fval;
}
else
v4.w = 0.0;

string line, token;
vector<vector<string>> str_data;
map<string, vector<size_t>, less<string>> group_verts;
map<int, int> id_corresp;
map<int, int> id_corresp2;
int maxid = 0;
while (getline(ifs, line))
{
if (line.empty() || line[0] == '#')
continue;
vector<string> tokens = split(line, " ", "#");
if (tokens.size() >= 7)
{
glm::vec4 v4;
float fval;
int ival;
int id = STOI(tokens[0].c_str());
fval = STOD(tokens[2].c_str());
v4.x = fval;
fval = STOD(tokens[3].c_str());
v4.y = fval;
fval = STOD(tokens[4].c_str());
v4.z = -fval;
if (tokens[5] != "NA")
{
fval = STOD(tokens[5].c_str());
v4.w = fval;
}
else
v4.w = 0.0;
/*
if (tokens.size() >= 8)
{
string gname = tokens[7].c_str();
if (group_verts.find(gname) == group_verts.end())
{
vector<size_t> e;
e.push_back(m_vertices.size());
group_verts[gname] = e;
}
else
group_verts[gname].push_back(m_vertices.size());
}
if (tokens.size() >= 9)
{
fval = STOD(tokens[8].c_str());
m_extra_data.push_back(fval);
}
*/
if (tokens.size() >= 8)
{
fval = STOD(tokens[7].c_str());
m_extra_data.push_back(fval);
}

int newid = m_vertices.size();
id_corresp[id] = newid;
m_vertices.push_back(v4);

ival = STOI(tokens[6].c_str());
if (ival != -1)
m_edges.push_back(glm::ivec2(id, ival));

}
}

for (auto &e : m_edges)
{
e[0] = id_corresp[e[0]];
e[1] = id_corresp[e[1]];
}
int newid = m_vertices.size();
id_corresp[id] = newid;
m_vertices.push_back(v4);

ival = STOI(tokens[6].c_str());
if (ival != -1)
m_edges.push_back(glm::ivec2(id, ival));

}
}

return;
for (auto &e : m_edges)
{
e[0] = id_corresp[e[0]];
e[1] = id_corresp[e[1]];
}
/*
if (!group_verts.empty())
{
size_t count = 0;
for (map<string, vector<size_t>>::iterator it = group_verts.begin(); it != group_verts.end(); it++)
{
for (int i = 0; i < it->second.size(); i++)
{
id_corresp2[it->second[i]] = count;
m_v_group_id.push_back(m_group_names.size());
count++;
}
m_group_names.push_back(it->first);
}
vector<glm::vec4> tmp_vertices;
tmp_vertices.resize(m_vertices.size());
for (int i = 0; i < m_vertices.size(); i++)
tmp_vertices[i] = m_vertices[id_corresp2[i]];
m_vertices = tmp_vertices;
vector<float> tmp_extra_data;
tmp_extra_data.resize(m_extra_data.size());
for (int i = 0; i < m_extra_data.size(); i++)
tmp_extra_data[i] = m_extra_data[id_corresp2[i]];
m_extra_data = tmp_extra_data;
for (auto &e : m_edges)
{
e[0] = id_corresp2[e[0]];
e[1] = id_corresp2[e[1]];
}
}
*/
return;
}

bool SWCReader::DeepCopy(SWCReader *in, SWCReader *out)
Expand Down
4 changes: 4 additions & 0 deletions fluorender/FluoRender/Formats/swc_reader.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,10 @@ class EXPORT_API SWCReader
vector<float> m_model_norms;
vector<float> m_model_extra_data;
vector<unsigned int> m_model_tris;

vector<vector<unsigned int>> m_model_group_tris;
vector<string> m_group_names;
vector<size_t> m_v_group_id;

vector<glm::vec3> m_sphere_verts_cache;
vector<glm::ivec3> m_sphere_tris_cache;
Expand Down
10 changes: 9 additions & 1 deletion fluorender/FluoRender/VRenderFrame.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1535,7 +1535,6 @@ void VRenderFrame::LoadMeshes(wxArrayString files, VRenderView* vrv, wxArrayStri
wxArrayString linkswcstr;
while(!csv.Eof())
{
str = csv.GetNextLine();
wxStringTokenizer tkz(str, wxT(","));
wxArrayString elems;
while(tkz.HasMoreTokens())
Expand Down Expand Up @@ -1568,6 +1567,15 @@ void VRenderFrame::LoadMeshes(wxArrayString files, VRenderView* vrv, wxArrayStri
linkswcstr.Add(swc_line);
}
}
else if (elems.Count() >= 3)
{
wxString key = "default";
if (swcdata.count(key) == 0)
swcdata[key] = wxArrayString();
wxString swc_line = wxString::Format("%d 6 %s %s %s %f -1", (int)swcdata[key].Count()+1, elems[0], elems[1], elems[2], 0.1f);
swcdata[key].Add(swc_line);
}
str = csv.GetNextLine();
}
csv.Close();

Expand Down

0 comments on commit 6e50b4e

Please sign in to comment.