Skip to content
Snippets Groups Projects
Commit 29b8776f authored by andreas's avatar andreas
Browse files

ported some missing methods in pointlist_overlay from qtiplt to ost

git-svn-id: https://dng.biozentrum.unibas.ch/svn/openstructure/trunk@2457 5a81b35b-ba03-0410-adc8-b2c5c5119f08
parent 43495a9a
Branches
Tags
No related merge requests found
......@@ -47,7 +47,7 @@ void plo_add2(PointlistOverlay& plo, const PointList& p)
plo.Add(p);
}
/*void plo_add3(PointlistOverlay& plo, const Point& p, double scale)
void plo_add3(PointlistOverlay& plo, const Point& p, double scale)
{
plo.Add(p,scale);
}
......@@ -56,7 +56,7 @@ void plo_add4(PointlistOverlay& plo, const PointList& p, double scale)
{
plo.Add(p,scale);
}
*/
QColor qcolor_from_pyobj(boost::python::object& obj)
{
return QColor(boost::python::extract<int>(obj.attr("red")()),
......@@ -64,7 +64,7 @@ return QColor(boost::python::extract<int>(obj.attr("red")()),
boost::python::extract<int>(obj.attr("blue")()));
}
/*void set_active_color(PointlistOverlayBase& plo,boost::python::object& obj)
void set_active_color(PointlistOverlayBase& plo,boost::python::object& obj)
{
QColor color=qcolor_from_pyobj(obj);
plo.SetActiveColor(color);
......@@ -73,7 +73,7 @@ void set_passive_color(PointlistOverlayBase& plo,boost::python::object& obj)
{
QColor color=qcolor_from_pyobj(obj);
plo.SetPassiveColor(color);
}*/
}
}//ns
......@@ -94,16 +94,16 @@ void export_overlay()
.def("GetSymbolShape",&PointlistOverlayBase::GetSymbolShape)
.def("SetCrosshair",&PointlistOverlayBase::SetCrosshair)
.def("GetCrosshair",&PointlistOverlayBase::GetCrosshair)
// .def("SetActiveColor",set_active_color)
// .def("SetPassiveColor",set_passive_color)
.def("SetActiveColor",set_active_color)
.def("SetPassiveColor",set_passive_color)
;
class_<PointlistOverlay,bases<PointlistOverlayBase>,boost::noncopyable>("PointlistOverlay",init<optional<const String&> >())
.def(init<const PointList&,optional<const String&> >())
.def("Add",plo_add1)
.def("Add",plo_add2)
// .def("Add",plo_add3)
// .def("Add",plo_add4)
.def("Add",plo_add3)
.def("Add",plo_add4)
.def("Remove",&PointlistOverlay::Remove)
.def("Clear",&PointlistOverlay::Clear)
;
......
......@@ -31,15 +31,17 @@
namespace ost { namespace img { namespace gui {
PointlistOverlay::PointlistOverlay(const String& name):
PointlistOverlayBase(name)
PointlistOverlayBase(name),
pointlist_()
{
build();
build_();
}
PointlistOverlay::PointlistOverlay(const PointList& pl, const String& name):
PointlistOverlayBase(name)
PointlistOverlayBase(name),
pointlist_()
{
build();
build_();
Add(pl);
}
......@@ -52,22 +54,22 @@ void PointlistOverlay::OnMenuEvent(QAction* e)
}
}
void PointlistOverlay::Add(const Point& pnt)
void PointlistOverlay::Add(const Point& pnt, double scale)
{
pointlist_.push_back(pnt);
pointlist_.push_back(std::pair<Point,double>(pnt,scale));
}
void PointlistOverlay::Add(const PointList& pl)
void PointlistOverlay::Add(const PointList& pl, double scale)
{
for(PointList::const_iterator it=pl.begin();it!=pl.end();++it) {
Add(*it);
Add(*it,scale);
}
}
void PointlistOverlay::Remove(const Point& pnt)
{
for(PointList::iterator it=pointlist_.begin();it!=pointlist_.end();++it){
if (*it==pnt) {
for(std::vector<std::pair<Point,double> >::iterator it=pointlist_.begin();it!=pointlist_.end();++it){
if (it->first==pnt) {
pointlist_.erase(it);
}
}
......@@ -80,13 +82,14 @@ void PointlistOverlay::Clear()
void PointlistOverlay::OnDraw(QPainter& pnt, DataViewerPanel* dvp, bool is_active)
{
std::vector<QPoint> qpointlist;
for(PointList::iterator it=pointlist_.begin();it!=pointlist_.end();++it){
qpointlist.push_back(dvp->FracPointToWinCenter((*it).ToVec2()));
std::vector<std::pair<QPoint,double> > qpointlist;
for(std::vector<std::pair<Point,double> >::iterator it=pointlist_.begin();it!=pointlist_.end();++it){
qpointlist.push_back(std::pair<QPoint,double> (dvp->FracPointToWinCenter((it->first).ToVec2()),it->second));
}
DrawPointList(pnt,dvp, is_active? active_color_ : passive_color_,
qpointlist);
DrawVariableSizePointList(pnt,dvp,
is_active? active_color_ : passive_color_,
qpointlist);
}
bool PointlistOverlay::OnMouseEvent(QMouseEvent* e,
......@@ -96,19 +99,20 @@ bool PointlistOverlay::OnMouseEvent(QMouseEvent* e,
if(e->buttons()==Qt::LeftButton && e->modifiers()&Qt::ShiftModifier) {
// toggle point at mouse position
Point mpoint = dvp->WinToPoint(e->x(),e->y());
PointList::iterator pos=find(pointlist_.begin(),
pointlist_.end(),mpoint);
if(pos!=pointlist_.end()) {
pointlist_.erase(pos);
} else {
pointlist_.push_back(mpoint);
for(std::vector<std::pair<Point,double> >::iterator it=pointlist_.begin();it!=pointlist_.end();++it){
if (it->first==mpoint) {
pointlist_.erase(it);
return true;
}
}
pointlist_.push_back(std::pair<Point,double>(mpoint,1.0));
return true;
}
return false;
}
void PointlistOverlay::build()
void PointlistOverlay::build_()
{
menu_->addSeparator();
a_clr_ = menu_->addAction("Clear");
......
......@@ -45,8 +45,8 @@ public:
virtual bool OnMouseEvent(QMouseEvent* e, DataViewerPanel* dvp,
const QPoint& lastmouse);
void Add(const Point& pnt);
void Add(const PointList& pl);
void Add(const Point& pnt, double scale=1.0);
void Add(const PointList& pl, double scale=1.0);
//! remove all points on the given point
void Remove(const Point& pnt);
......@@ -55,11 +55,11 @@ public:
void Clear();
private:
PointList pointlist_;
std::vector<std::pair<Point,double> > pointlist_;
QAction* a_clr_;
void build();
void build_();
};
}}} //ns
......
......@@ -197,6 +197,18 @@ void PointlistOverlayBase::DrawPointList(QPainter& pnt, DataViewerPanel* dvp,
}
strategy_->SetSymbolSize(static_cast<int>((GetSymbolSize()-0.5) * dvp->GetZoomScale()));
}
void PointlistOverlayBase::DrawVariableSizePointList(QPainter& pnt, DataViewerPanel* dvp,
const QColor& color,
const std::vector<std::pair<QPoint,double> >& pointlist)
{
strategy_->SetPenColor(color);
strategy_->SetSymbolStrength(symbolstrength_);
for(unsigned int i = 0; i < pointlist.size(); i++) {
strategy_->SetSymbolSize(static_cast<int>((GetSymbolSize()-0.5) * dvp->GetZoomScale()*pointlist[i].second));
strategy_->Draw(pnt,pointlist[i].first);
}
strategy_->SetSymbolSize(static_cast<int>((GetSymbolSize()-0.5) * dvp->GetZoomScale()));
}
bool PointlistOverlayBase::GetCrosshair() const
{
......@@ -276,4 +288,14 @@ void PointlistOverlayBase::SetProps(PointlistOverlayBaseSettings* props)
symbolstrength_=props->symbol_strength;
}
void PointlistOverlayBase::SetActiveColor(const QColor& col)
{
active_color_=col;
}
void PointlistOverlayBase::SetPassiveColor(const QColor& col)
{
passive_color_=col;
}
}}} //ns
......@@ -85,6 +85,7 @@ public:
// own virtual interface
virtual void DrawPointList(QPainter& pnt, DataViewerPanel* dvp, const QColor& col ,const std::vector<QPoint>& pointlist);
virtual void DrawVariableSizePointList(QPainter& pnt, DataViewerPanel* dvp, const QColor& col ,const std::vector<std::pair<QPoint,double> >& pointlist);
//
unsigned int GetSymbolSize() const;
......@@ -93,6 +94,8 @@ public:
void SetSymbolShape(unsigned int symbolshape);
bool GetCrosshair() const;
void SetCrosshair(bool flag);
void SetActiveColor(const QColor& col);
void SetPassiveColor(const QColor& col);
private:
template <class StrategyClass>
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment