Skip to content
Snippets Groups Projects
Commit 4b07def4 authored by stefan's avatar stefan
Browse files

ColorOps, new algorithm for color by chain

git-svn-id: https://dng.biozentrum.unibas.ch/svn/openstructure/trunk@2560 5a81b35b-ba03-0410-adc8-b2c5c5119f08
parent 527ba207
No related branches found
No related tags found
No related merge requests found
......@@ -75,6 +75,8 @@ void export_ColorOps()
.def(init<const mol::QueryViewWrapper&>())
.def(init<const String&, int>())
.def(init<const mol::QueryViewWrapper&, int>())
.def("GetChainCount",&ByChainColorOp::GetChainCount)
.def("SetChainCount",&ByChainColorOp::SetChainCount)
.def("FromInfo",&ByChainColorOp::FromInfo)
.staticmethod("FromInfo")
;
......
......@@ -26,20 +26,11 @@
namespace ost { namespace gfx {
ByChainColorOp::ByChainColorOp() : ColorOp(){this->init();}
ByChainColorOp::ByChainColorOp() : ColorOp(),chain_count_(0),color_grad_("RAINBOW"){}
ByChainColorOp::ByChainColorOp(const String& selection, int mask) : ColorOp(selection,mask){this->init();}
ByChainColorOp::ByChainColorOp(const String& selection, int mask) : ColorOp(selection,mask),chain_count_(0),color_grad_("RAINBOW"){}
ByChainColorOp::ByChainColorOp(const mol::QueryViewWrapper& query_view, int mask) : ColorOp(query_view,mask){this->init();}
void ByChainColorOp::init(){
color_grad_.SetColorAt(0,Color(1,1,0));
color_grad_.SetColorAt(0.16666,Color(1,0,0));
color_grad_.SetColorAt(0.33333,Color(0,1,1));
color_grad_.SetColorAt(0.5,Color(0,1,0));
color_grad_.SetColorAt(0.66666,Color(1,0,1));
color_grad_.SetColorAt(0.83333,Color(0,0,1));
}
ByChainColorOp::ByChainColorOp(const mol::QueryViewWrapper& query_view, int mask) : ColorOp(query_view,mask),chain_count_(0),color_grad_("RAINBOW"){}
bool ByChainColorOp::CanApplyTo(const GfxObjP& obj) const{
if(dynamic_cast<Entity*>(obj.get()))
......@@ -62,6 +53,16 @@ gfx::Color ByChainColorOp::GetColor(String ident) const{
return colors_[ident];
}
int ByChainColorOp::GetChainCount() const
{
return chain_count_;
}
void ByChainColorOp::SetChainCount(int chain_count)
{
chain_count_ = chain_count;
}
gfx::ByChainColorOp ByChainColorOp::FromInfo(info::InfoGroup& group){
gfx::ColorOp op = ColorOp::FromInfo(group);
String selection = op.GetSelection();
......@@ -71,18 +72,13 @@ gfx::ByChainColorOp ByChainColorOp::FromInfo(info::InfoGroup& group){
gfx::Color ByChainColorOp::GenerateColor(String& ident) const{
unsigned int size=colors_.size()-1;
int cnt = size % 6;
int factor = abs(size/6.0)+1;
float start = 1.0/(6.0*factor);
if(factor > 1 && !((factor+1) & 1)){
float old_start = 1.0 / (6.0 *abs(size/6.0));
start += old_start;
if(size<=0){
colors_[ident] = color_grad_.GetColorAt(0.0);
}
float value = start + (cnt / 6.0);
if(value >= 1){
value -=1;
else{
colors_[ident] = color_grad_.GetColorAt(float(size) / chain_count_);
}
return color_grad_.GetColorAt(value);
return colors_[ident];
}
}}
......
......@@ -43,13 +43,16 @@ public:
virtual gfx::Color GetColor(String ident) const;
virtual int GetChainCount() const;
virtual void SetChainCount(int chain_count);
//virtual void ToInfo(info::InfoGroup& group) const;
static gfx::ByChainColorOp FromInfo(info::InfoGroup& group);
private:
void init();
gfx::Color GenerateColor(String& ident) const;
mutable int chain_count_;
mutable std::map<String,gfx::Color> colors_;
gfx::Gradient color_grad_;
......
......@@ -66,7 +66,6 @@ public:
static gfx::ColorOp FromInfo(info::InfoGroup& group);
private:
mol::QueryViewWrapper query_view_;
mol::EntityView view_;
ColorMask mask_;
};
......
......@@ -908,11 +908,13 @@ void Entity::Apply(const gfx::ByElementColorOp& op, bool store)
void Entity::Apply(const gfx::ByChainColorOp& op, bool store)
{
const_cast<gfx::ByChainColorOp&>(op).SetChainCount(this->GetView().GetChainCount());
if(store){
ByChainColorOp* op_ptr = new ByChainColorOp(op);
this->AppendColorOp(op_ptr);
}
apply_color_op_to_renderer_list(renderer_.begin(), renderer_.end(), op);
const_cast<gfx::ByChainColorOp&>(op).SetChainCount(0);
FlagRebuild();
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment