From: <cr...@us...> - 2008-01-31 11:45:14
|
Revision: 6525 http://ravl.svn.sourceforge.net/ravl/?rev=6525&view=rev Author: craftit Date: 2008-01-31 03:45:10 -0800 (Thu, 31 Jan 2008) Log Message: ----------- Add some more displayable primitives. Modified Paths: -------------- main/Ravl/GUI/DPDisplay/DPDisplayView.cc main/Ravl/GUI/DPDisplay/DPDisplayView.hh main/Ravl/GUI/DPDisplay/RavlGUIDisplay.cc main/Ravl/GUI/DPDisplay/defs.mk main/Ravl/GUI/DPDisplay/exDPWindow.cc Added Paths: ----------- main/Ravl/GUI/DPDisplay/DPDisplayPoints.cc main/Ravl/GUI/DPDisplay/DPDisplayPoints.hh main/Ravl/GUI/DPDisplay/DPDisplayPolygon.cc main/Ravl/GUI/DPDisplay/DPDisplayPolygon.hh Added: main/Ravl/GUI/DPDisplay/DPDisplayPoints.cc =================================================================== --- main/Ravl/GUI/DPDisplay/DPDisplayPoints.cc (rev 0) +++ main/Ravl/GUI/DPDisplay/DPDisplayPoints.cc 2008-01-31 11:45:10 UTC (rev 6525) @@ -0,0 +1,95 @@ +// This file is part of RAVL, Recognition And Vision Library +// Copyright (C) 2008, OmniPerception Ltd. +// This code may be redistributed under the terms of the GNU Lesser +// General Public License (LGPL). See the lgpl.licence file for details or +// see http://www.gnu.org/copyleft/lesser.html +// file-header-ends-here + +#include "Ravl/GUI/DPDisplayPoints.hh" +#include "Ravl/GUI/MarkupPoint2d.hh" +#include "Ravl/StrStream.hh" +#include "Ravl/DP/Converter.hh" + +namespace RavlGUIN { + + + //: Constructor + + DPDisplayPointsBodyC::DPDisplayPointsBodyC(const DListC<Point2dC> &points) + : m_points(points) + {} + + //: Constructor + + DPDisplayPointsBodyC::DPDisplayPointsBodyC(const Point2dC &point) + { m_points.InsLast(point); } + + //: Draw object to canvas. + + bool DPDisplayPointsBodyC::Draw(FrameMarkupC &markup) { + for(DLIterC<Point2dC> it(m_points);it;it++) { + markup.Markup().InsLast(MarkupPoint2dC(m_id,1,*it,MP2DS_CrossHair,true)); + } + return true; + } + + //: Find bounding box for object. + + IndexRange2dC DPDisplayPointsBodyC::Frame() const { + DLIterC<Point2dC> it(m_points); + if(!it) + return IndexRange2dC(); + RealRange2dC rng(*it,0); + for(it++;it;it++) + rng.Involve(*it); + return rng.IndexRange(); + } + + //: Query a point in the display. + // Return true if point is within object. + + bool DPDisplayPointsBodyC::Query(const Vector2dC &pnt,StringC &text) { + RealT minDist = Sqr(8); + bool foundPoint = false; + Point2dC minPos; + for(DLIterC<Point2dC> it(m_points);it;it++) { + RealT dist = pnt.SqrEuclidDistance(*it); + if(dist < minDist) { + minDist = dist; + minPos = *it; + foundPoint = true; + } + } + if(foundPoint) { + text = StringC("Point:") + StringOf(minPos); + return true; + } + return false; + } + + //: Save to a file. + + bool DPDisplayPointsBodyC::Save(const StringC &str) const { + + return false; + } + + //------------------------------------------------------------------ + // Register some conversions as well. + + DPDisplayObjC Point2d2DPDisplayObj(const Point2dC &point) + { return DPDisplayPointsC(point); } + + DP_REGISTER_CONVERSION_NAMED(Point2d2DPDisplayObj,1,"DPDisplayObjC Point2d2DPDisplayObj(const Point2dC &) "); + + + + DPDisplayObjC DList_Point2d2DPDisplayObj(const DListC<Point2dC> &points) + { return DPDisplayPointsC(points); } + + DP_REGISTER_CONVERSION_NAMED(DList_Point2d2DPDisplayObj,1,"DPDisplayObjC DList_Point2d2DPDisplayObj(const DListC<Point2dC> &) "); + + void InitDPDisplayPoints() + {} + +} Added: main/Ravl/GUI/DPDisplay/DPDisplayPoints.hh =================================================================== --- main/Ravl/GUI/DPDisplay/DPDisplayPoints.hh (rev 0) +++ main/Ravl/GUI/DPDisplay/DPDisplayPoints.hh 2008-01-31 11:45:10 UTC (rev 6525) @@ -0,0 +1,72 @@ +// This file is part of RAVL, Recognition And Vision Library +// Copyright (C) 2008, OmniPerception Ltd. +// This code may be redistributed under the terms of the GNU Lesser +// General Public License (LGPL). See the lgpl.licence file for details or +// see http://www.gnu.org/copyleft/lesser.html +// file-header-ends-here +#ifndef RAVLGUI_DPDISPLAYPOINTS_HEADER +#define RAVLGUI_DPDISPLAYPOINTS_HEADER 1 +//! rcsid="$Id: DPDisplayImage.hh 5741 2006-07-13 10:27:51Z craftit $" +//! lib=RavlDPDisplay +//! file="Ravl/GUI/DPDisplay/DPDisplayImage.hh" +//! author="Charles Galambos" +//! docentry="Ravl.API.GUI.Data Display" + +#include "Ravl/GUI/DPDisplayObj.hh" +#include "Ravl/Point2d.hh" + +namespace RavlGUIN { + + //! userlevel=Develop + //: DPDisplayObj to handle images. + + class DPDisplayPointsBodyC + : public DPDisplayObjBodyC + { + public: + DPDisplayPointsBodyC(const DListC<Point2dC> &points); + //: Constructor + + DPDisplayPointsBodyC(const Point2dC &point); + //: Constructor + + virtual bool Draw(FrameMarkupC &markup); + //: Draw object to canvas. + + virtual IndexRange2dC Frame() const; + //: Find bounding box for object. + + virtual bool Query(const Vector2dC &pnt,StringC &text); + //: Query a point in the display. + // Return true if point is within object. + + virtual bool Save(const StringC &str) const; + //: Save to a file. + + protected: + DListC<Point2dC> m_points; + }; + + + class DPDisplayPointsC + : public DPDisplayObjC + { + public: + DPDisplayPointsC() + {} + //: Default constructor + + DPDisplayPointsC(const DListC<Point2dC> &points) + : DPDisplayObjC(new DPDisplayPointsBodyC(points)) + {} + //: Constructor + + DPDisplayPointsC(const Point2dC &point) + : DPDisplayObjC(new DPDisplayPointsBodyC(point)) + {} + //: Constructor + + }; +} + +#endif Added: main/Ravl/GUI/DPDisplay/DPDisplayPolygon.cc =================================================================== --- main/Ravl/GUI/DPDisplay/DPDisplayPolygon.cc (rev 0) +++ main/Ravl/GUI/DPDisplay/DPDisplayPolygon.cc 2008-01-31 11:45:10 UTC (rev 6525) @@ -0,0 +1,65 @@ +// This file is part of RAVL, Recognition And Vision Library +// Copyright (C) 2008, OmniPerception Ltd. +// This code may be redistributed under the terms of the GNU Lesser +// General Public License (LGPL). See the lgpl.licence file for details or +// see http://www.gnu.org/copyleft/lesser.html +// file-header-ends-here + +#include "Ravl/GUI/DPDisplayPolygon.hh" +#include "Ravl/GUI/MarkupPolygon2d.hh" +#include "Ravl/StrStream.hh" +#include "Ravl/DP/Converter.hh" + +namespace RavlGUIN { + + + //: Constructor + + DPDisplayPolygon2dBodyC::DPDisplayPolygon2dBodyC(const Polygon2dC &polygon) + : m_polygon(polygon) + {} + + //: Draw object to canvas. + + bool DPDisplayPolygon2dBodyC::Draw(FrameMarkupC &markup) { + markup.Markup().InsLast(MarkupPolygon2dC(m_id,1,m_polygon,true)); + return true; + } + + //: Find bounding box for object. + + IndexRange2dC DPDisplayPolygon2dBodyC::Frame() const + { return m_polygon.BoundingRectangle().IndexRange(); } + + //: Query a point in the display. + // Return true if point is within object. + + bool DPDisplayPolygon2dBodyC::Query(const Vector2dC &pnt,StringC &text) { + if(m_polygon.Contains(pnt)) { + StringC tmp = StringOf(m_polygon); + tmp.gsub("\n",","); + text = StringC("Polygon:") + tmp; + return true; + } + return false; + } + + //: Save to a file. + + bool DPDisplayPolygon2dBodyC::Save(const StringC &str) const { + + return false; + } + + //------------------------------------------------------------------ + // Register some conversions as well. + + DPDisplayObjC Polygon2dPDisplayObj(const Polygon2dC &poly) + { return DPDisplayPolygon2dC(poly.Copy()); } + + DP_REGISTER_CONVERSION_NAMED(Polygon2dPDisplayObj,1,"DPDisplayObjC Polygon2d2DPDisplayObj(const Polygon2dC &) "); + + void InitDPDisplayPolygon2d() + {} + +} Added: main/Ravl/GUI/DPDisplay/DPDisplayPolygon.hh =================================================================== --- main/Ravl/GUI/DPDisplay/DPDisplayPolygon.hh (rev 0) +++ main/Ravl/GUI/DPDisplay/DPDisplayPolygon.hh 2008-01-31 11:45:10 UTC (rev 6525) @@ -0,0 +1,64 @@ +// This file is part of RAVL, Recognition And Vision Library +// Copyright (C) 2008, OmniPerception Ltd. +// This code may be redistributed under the terms of the GNU Lesser +// General Public License (LGPL). See the lgpl.licence file for details or +// see http://www.gnu.org/copyleft/lesser.html +// file-header-ends-here +#ifndef RAVLGUI_DPDISPLAYPOLYGON_HEADER +#define RAVLGUI_DPDISPLAYPOLYGON_HEADER 1 +//! rcsid="$Id: DPDisplayImage.hh 5741 2006-07-13 10:27:51Z craftit $" +//! lib=RavlDPDisplay +//! file="Ravl/GUI/DPDisplay/DPDisplayImage.hh" +//! author="Charles Galambos" +//! docentry="Ravl.API.GUI.Data Display" + +#include "Ravl/GUI/DPDisplayObj.hh" +#include "Ravl/Polygon2d.hh" + +namespace RavlGUIN { + + //! userlevel=Develop + //: DPDisplayObj to handle images. + + class DPDisplayPolygon2dBodyC + : public DPDisplayObjBodyC + { + public: + DPDisplayPolygon2dBodyC(const Polygon2dC &polygon); + //: Constructor + + virtual bool Draw(FrameMarkupC &markup); + //: Draw object to canvas. + + virtual IndexRange2dC Frame() const; + //: Find bounding box for object. + + virtual bool Query(const Vector2dC &pnt,StringC &text); + //: Query a point in the display. + // Return true if point is within object. + + virtual bool Save(const StringC &str) const; + //: Save to a file. + + protected: + Polygon2dC m_polygon; + }; + + + class DPDisplayPolygon2dC + : public DPDisplayObjC + { + public: + DPDisplayPolygon2dC() + {} + //: Default constructor + + DPDisplayPolygon2dC(const Polygon2dC &polygon) + : DPDisplayObjC(new DPDisplayPolygon2dBodyC(polygon)) + {} + //: Constructor + + }; +} + +#endif Modified: main/Ravl/GUI/DPDisplay/DPDisplayView.cc =================================================================== --- main/Ravl/GUI/DPDisplay/DPDisplayView.cc 2008-01-31 11:44:32 UTC (rev 6524) +++ main/Ravl/GUI/DPDisplay/DPDisplayView.cc 2008-01-31 11:45:10 UTC (rev 6525) @@ -50,6 +50,7 @@ backMenu.GUIAdd(MenuItemR("Save",*this, &DPDisplayViewBodyC::CallbackStartSave)); menuBar.GUIAdd(MenuItemR("Save",*this, &DPDisplayViewBodyC::CallbackStartSave)); + //menuBar.GUIAdd(MenuItemR("Fit To Window",*this, &DPDisplayViewBodyC::CallbackFitToWindow)); fileSelector = FileSelectorC("@X Save"); connections += ConnectRef(fileSelector.Selected(),*this,&DPDisplayViewBodyC::CallbackSave); @@ -127,11 +128,11 @@ bool DPDisplayViewBodyC::AddObject(const DPDisplayObjC &obj) { ONDEBUG(cerr << "DPDisplayViewBodyC::AddObject(), Called \n"); RWLockHoldC hold(lockDisplayList,RWLOCK_WRITE); - if(displayList.IsEmpty()) + if(displayList.IsEmpty()) { displaySize = obj.Frame(); - else + } else displaySize.Involve(obj.Frame()); - displayList.InsLast(obj); + displayList.InsFirst(obj); hold.Unlock(); Refresh(); return true; @@ -251,7 +252,15 @@ backMenu.Popup(); return true; } + + //: Fit image to window. + bool DPDisplayViewBodyC::CallbackFitToWindow() { + if(canvas.IsValid()) + canvas.FitImageToScreen(); + return true; + } + //: Update info for mouse position. bool DPDisplayViewBodyC::UpdateInfo(const Vector2dC &at) { Modified: main/Ravl/GUI/DPDisplay/DPDisplayView.hh =================================================================== --- main/Ravl/GUI/DPDisplay/DPDisplayView.hh 2008-01-31 11:44:32 UTC (rev 6524) +++ main/Ravl/GUI/DPDisplay/DPDisplayView.hh 2008-01-31 11:45:10 UTC (rev 6525) @@ -89,6 +89,9 @@ bool CallbackMousePress(MouseEventC &mouseEvent); //: Call back for mouse press events. + bool CallbackFitToWindow(); + //: Fit image to window. + bool UpdateInfo(const Vector2dC &at); //: Update info for mouse position. Modified: main/Ravl/GUI/DPDisplay/RavlGUIDisplay.cc =================================================================== --- main/Ravl/GUI/DPDisplay/RavlGUIDisplay.cc 2008-01-31 11:44:32 UTC (rev 6524) +++ main/Ravl/GUI/DPDisplay/RavlGUIDisplay.cc 2008-01-31 11:45:10 UTC (rev 6525) @@ -11,8 +11,13 @@ namespace RavlGUIN { extern void InitDPWindowFormat(); extern void InitDPDisplayImage(); + extern void InitDPDisplayPoints(); + extern void InitDPDisplayPolygon2d(); + void InitRavlGUIDisplay() { InitDPWindowFormat(); InitDPDisplayImage(); + InitDPDisplayPoints(); + InitDPDisplayPolygon2d(); } } Modified: main/Ravl/GUI/DPDisplay/defs.mk =================================================================== --- main/Ravl/GUI/DPDisplay/defs.mk 2008-01-31 11:44:32 UTC (rev 6524) +++ main/Ravl/GUI/DPDisplay/defs.mk 2008-01-31 11:45:10 UTC (rev 6525) @@ -10,10 +10,10 @@ PACKAGE=Ravl/GUI HEADERS=DPWindow.hh DPDisplayObj.hh DPDisplayImage.hh DPWindowOPort.hh \ - DPWindowFormat.hh DPDisplayView.hh + DPWindowFormat.hh DPDisplayView.hh DPDisplayPoints.hh DPDisplayPolygon.hh SOURCES=DPWindow.cc DPDisplayObj.cc DPDisplayImage.cc DPWindowOPort.cc \ - DPWindowFormat.cc DPDisplayView.cc + DPWindowFormat.cc DPDisplayView.cc DPDisplayPoints.cc DPDisplayPolygon.cc PLIB=RavlDPDisplay Modified: main/Ravl/GUI/DPDisplay/exDPWindow.cc =================================================================== --- main/Ravl/GUI/DPDisplay/exDPWindow.cc 2008-01-31 11:44:32 UTC (rev 6524) +++ main/Ravl/GUI/DPDisplay/exDPWindow.cc 2008-01-31 11:45:10 UTC (rev 6525) @@ -31,6 +31,19 @@ return 1; } + // Add a point to the image. + Point2dC aPnt(128,64); + if(!Save("@XA:hello",aPnt)) { + cerr << "Failed to save point. \n"; + return 1; + } + + Polygon2dC aPoly(RealRange2dC(Point2dC(30,25),10)); + if(!Save("@XA:hello",aPoly)) { + cerr << "Failed to save point. \n"; + return 1; + } + IndexRangeC rr(-100,100); IndexRangeC cr(-100,200); ImageC<ByteT> img2(rr,cr); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |