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

Commit

Permalink
improve sub-mesh functions and test_againt_view
Browse files Browse the repository at this point in the history
  • Loading branch information
takashi310 committed Apr 7, 2023
1 parent 8b7afa5 commit ab20ca8
Showing 13 changed files with 888 additions and 254 deletions.
6 changes: 4 additions & 2 deletions fluorender/FluoRender/DataManager.cpp
Original file line number Diff line number Diff line change
@@ -4877,7 +4877,9 @@ bool MeshData::UpdateModelSWC()
(m_bounds.min().y()+m_bounds.max().y())*0.5,
(m_bounds.min().z()+m_bounds.max().z())*0.5);


if (m_mr)
m_mr->set_model(m_data);
/*
MeshRenderer *tmp = 0;
if (m_mr)
tmp = m_mr;
@@ -4893,7 +4895,7 @@ bool MeshData::UpdateModelSWC()
m_mr->set_limit(tmp->get_limit());
delete tmp;
}

*/
return true;
}

23 changes: 21 additions & 2 deletions fluorender/FluoRender/DataManager.h
Original file line number Diff line number Diff line change
@@ -376,6 +376,25 @@ class EXPORT_API MeshData : public TreeLayer

bool InsideClippingPlanes(Point pos);

wstring GetROIPath(int id)
{
if (m_mr)
{
if (auto ret = m_mr->get_roi_path(id))
return *ret;
}
return wstring();
}
bool GetROIVisibility(int id) { return m_mr ? m_mr->get_roi_visibility(id) : false; }
bool GetSubmeshLabelState(int id) { return m_mr ? m_mr->get_submesh_label_state(id) : false; }
void SetSelectedSubmeshID(int id) { if (m_mr) m_mr->set_selected_submesh_id(id); }
int GetSelectedSubmeshID() { return m_mr ? m_mr->get_selected_submesh_id() : -INT_MAX; }
void SetSubmeshLabel(int id, const MeshRenderer::SubMeshLabel &label_data) { if (m_mr) m_mr->set_submesh_label(id, label_data); }
void SetSubmeshLabelState(int id, bool state) { if (m_mr) m_mr->set_submesh_label_state(id, state); }
void SetSubmeshLabelStateSiblings(int id, bool state) { if (m_mr) m_mr->set_submesh_label_state_siblings(id, state); }
void SetSubmeshLabelStateByName(wstring name, bool state) { if (m_mr) m_mr->set_submesh_label_state_by_name(name, state); }
map<int, MeshRenderer::SubMeshLabel>* GetSubmeshLabels() { return m_mr ? m_mr->get_submesh_labels() : NULL; }
unordered_set<int>* GetActiveLabelSet() { return m_mr ? m_mr->get_active_label_set() : NULL; }
void UpdateIDPalette() { if (m_mr) m_mr->update_palette(L""); }
void SelectSegment(int id=-INT_MAX) { if (m_mr) m_mr->select_segment(id); }
bool isTree() { return m_mr ? m_mr->is_tree() : false; }
@@ -394,7 +413,7 @@ class EXPORT_API MeshData : public TreeLayer
void EraseROITreeNode(int id=-1){ if (m_mr) m_mr->erase_node(id); }
void EraseROITreeNode(wstring name){ if (m_mr) m_mr->erase_node(name); }
wstring GetROIName(int id=-1){ return m_mr ? m_mr->get_roi_name(id) : wstring(); }
int GetROIid(wstring name){ return m_mr ? m_mr->get_roi_id(name) : -1; }
int GetROIid(const wstring &path){ return m_mr ? m_mr->get_roi_id(path) : -INT_MAX; }
void SetROISel(wstring name, bool select, bool traverse=false){ if (m_mr) m_mr->set_roi_select(name, select, traverse); }
void SetROISelChildren(wstring name, bool select, bool traverse=false){ if (m_mr) m_mr->set_roi_select_children(name, select, traverse); }
void SelectAllNamedROI(){ if (m_mr) m_mr->select_all_roi_tree(); }
@@ -429,7 +448,7 @@ class EXPORT_API MeshData : public TreeLayer
void ClearSelIDs(){ if (m_mr) m_mr->clear_sel_ids(); }
void SetIDColDispMode(int mode){ if (m_mr) m_mr->update_palette(mode); }
int GetIDColDispMode(){ return m_mr ? m_mr->get_roi_disp_mode() : 0; }
boost::property_tree::wptree *getROITree(){ return m_mr ? m_mr->get_roi_tree() : NULL; };
boost::property_tree::wptree *getROITree(int id=-INT_MAX){ return m_mr ? m_mr->get_roi_tree(id) : NULL; };
wstring ExportROITree(){ return m_mr ? m_mr->export_roi_tree() : wstring(); }
string ExportSelIDs(){ return m_mr ? m_mr->exprot_selected_roi_ids() : string(); }
void ImportROITree(const wstring &tree){ if (m_mr) m_mr->import_roi_tree(tree); }
235 changes: 186 additions & 49 deletions fluorender/FluoRender/FLIVR/MeshRenderer.cpp
Original file line number Diff line number Diff line change
@@ -169,6 +169,120 @@ namespace FLIVR
}
}

bool MeshRenderer::get_submesh_label_state(int id)
{
auto ite = roi_active_labels_.find(id);
if (ite != roi_active_labels_.end())
return true;
return false;
}

void MeshRenderer::set_submesh_label(int id, const SubMeshLabel &label_data)
{
if (id < 0)
return;
if (roi_inv_dict_.count(id) == 0)
return;

roi_labels_[id] = label_data;

wstring name = roi_inv_dict_[id];
auto pos = name.find_last_of(L'.');
if (pos != wstring::npos && pos+1 < name.length())
name = name.substr(pos+1);

if (roi_labels_name_dict_.count(name) == 0)
{
vector<int> ids;
ids.push_back(id);
roi_labels_name_dict_[name] = ids;
}
else
roi_labels_name_dict_[name].push_back(id);
}

void MeshRenderer::set_submesh_label_state(int id, bool state)
{
if (id < 0)
return;

if (state)
roi_active_labels_.insert(id);
else
{
if (roi_active_labels_.empty()) return;

auto ite = roi_active_labels_.find(id);
if (ite != roi_active_labels_.end())
roi_active_labels_.erase(ite);
}
}

void MeshRenderer::set_submesh_label_state_siblings(int id, bool state)
{
if (roi_inv_dict_.count(id) == 0)
return;
wstring path = roi_inv_dict_[id];
size_t found = path.find_last_of(L".");
wstring parent = L"";
if (found != wstring::npos)
parent = path.substr(0, found);

boost::property_tree::wptree &tree = roi_tree_.get_child(parent);
for (wptree::const_iterator child = tree.begin(); child != tree.end(); ++child)
{
try
{
if ( const auto val = tree.get_optional<wstring>(child->first) )
{
int cid = boost::lexical_cast<int>(*val);
set_submesh_label_state(cid, state);
}
}
catch (boost::bad_lexical_cast e)
{
cerr << "MeshRenderer::set_submesh_label_state_siblings(int id, bool state): bad_lexical_cast" << endl;
}
}
}
void MeshRenderer::set_submesh_label_state_by_name(wstring name, bool state)
{
if (roi_labels_name_dict_.count(name) == 0)
return;

vector<int> ids = roi_labels_name_dict_[name];

for (auto id : ids)
set_submesh_label_state(id, state);
}
map<int, MeshRenderer::SubMeshLabel>* MeshRenderer::get_submesh_labels()
{
return &roi_labels_;
}
unordered_set<int>* MeshRenderer::get_active_label_set()
{
return &roi_active_labels_;
}

void MeshRenderer::set_model(GLMmodel* data)
{
data_ = data;
update_ = true;
}

boost::property_tree::wptree *MeshRenderer::get_roi_tree(int id)
{
if (id == -INT_MAX)
return &roi_tree_;
else if(roi_inv_dict_.count(id) > 0)
{
wstring path = roi_inv_dict_[id];
return &roi_tree_.get_child(path);
}

return NULL;
}

void MeshRenderer::init_palette()
{
memcpy(palette_, (const void *)palettes::palette_random_256_256_4, sizeof(unsigned char)*MR_PALETTE_SIZE*MR_PALETTE_ELEM_COMP);
@@ -267,11 +381,36 @@ void MeshRenderer::update_palette(const boost::property_tree::wptree& tree, bool
}
}


int MeshRenderer::get_roi_id(const wstring &path)
{
int rval = -INT_MAX;

wstring wsval;
try
{
rval = boost::lexical_cast<int>(roi_tree_.get(path, wsval));
}
catch (boost::bad_lexical_cast e)
{
cerr << "MeshRenderer::get_roi_id(const wstring &path): bad_lexical_cast" << endl;
return -INT_MAX;
}

return rval;
}

void MeshRenderer::select_segment(int id)
{
wstring path = L"";
if(roi_inv_dict_.count(id) > 0)
{
path = roi_inv_dict_[id];
selected_submesh_id_ = id;
}
else
selected_submesh_id_ = -INT_MAX;

select_segment(path);
}

@@ -375,31 +514,32 @@ void MeshRenderer::set_roi_state_traverse(int id, bool state, int exclude)
}
}

if (id != -INT_MAX) roi_inv_state_[id] = state;
//if (id != -INT_MAX) roi_inv_state_[id] = state;
set_roi_state_traverse(tree, state, exclude);

update_palette(path);
}
void MeshRenderer::set_roi_state_traverse(const boost::property_tree::wptree& tree, bool state, int exclude)
{
for (wptree::const_iterator child = tree.begin(); child != tree.end(); ++child)
try
{
try
{
wstring val = tree.get<wstring>(child->first);
if (!val.empty())
{
int id = boost::lexical_cast<int>(val);
if (id == exclude)
continue;
roi_inv_state_[id] = state;
}
}
catch (boost::bad_lexical_cast e)
wstring val = tree.get_value<wstring>();
if (!val.empty())
{
cerr << "MeshRenderer::set_roi_state_traverse(const wptree& tree, bool state): bad_lexical_cast" << endl;
int id = boost::lexical_cast<int>(val);
if (id == exclude)
return;
roi_inv_state_[id] = state;
}
set_roi_state_traverse(child->second, state);
}
catch (boost::bad_lexical_cast e)
{
cerr << "MeshRenderer::set_roi_state_traverse(const wptree& tree, bool state): bad_lexical_cast" << endl;
}

for (wptree::const_iterator child = tree.begin(); child != tree.end(); ++child)
{
set_roi_state_traverse(child->second, state, exclude);
}
}
void MeshRenderer::toggle_roi_state(int id)
@@ -417,6 +557,32 @@ bool MeshRenderer::get_roi_state(int id)
else
return false;
}
bool MeshRenderer::get_roi_visibility(int id)
{
wstring path = id != -INT_MAX ? roi_inv_dict_[id] : L"";
boost::property_tree::wptree &tree = id != -INT_MAX ? roi_tree_.get_child(path) : roi_tree_;
bool state = roi_inv_state_[id];

if (state)
{
wstring parent = path;
size_t found = path.find_last_of(L".");
while (found != wstring::npos)
{
parent = parent.substr(0, found);
int pid = boost::lexical_cast<int>(roi_tree_.get<wstring>(parent));
if (roi_inv_state_.count(pid) > 0)
{
state = state && roi_inv_state_[pid];
if (!state)
break;
}
found = parent.find_last_of(L".");
}
}

return state;
}
map<int, bool> MeshRenderer::get_all_roi_state()
{
return roi_inv_state_;
@@ -783,40 +949,11 @@ void MeshRenderer::erase_node(wstring name)

wstring MeshRenderer::get_roi_name(int id)
{
wstring rval;

int edid = (id == -1) ? edit_sel_id_ : id;
wstring rval = roi_inv_dict_[id];

if (edid != -1)
{
if(auto path = get_roi_path(edid))
rval = roi_tree_.get<wstring>(*path);
}

return rval;
}

int MeshRenderer::get_roi_id(wstring name)
{
int rval = -1;

if (auto path = get_roi_path(name))
{
auto pos = path->find_last_of(L'.');
wstring strid;
if (pos != wstring::npos && pos+1 < path->length())
strid = path->substr(pos+1);
else
strid = *path;
try
{
rval = boost::lexical_cast<int>(strid);
}
catch (boost::bad_lexical_cast e)
{
cerr << "MeshRenderer::get_roi_id(wstring name): bad_lexical_cast" << endl;
}
}
auto pos = rval.find_last_of(L'.');
if (pos != wstring::npos && pos+1 < rval.length())
rval = rval.substr(pos+1);

return rval;
}
Loading

0 comments on commit ab20ca8

Please sign in to comment.