1

Anyone have any idea how I can implement this? I'd like to have a function basically exactly like impoly in matlab or the "polygon sections" tool in imageJ, where you click to form a polygonal section and then each node can be adjusted, etc. I'd also like to have access to this function from Qt since I'm trying to make a gui for a small program I wrote.

Also, I'd like to avoid making calls to the matlab function because it's part of the image processing toolbox which isnt free. Thanks.

JustinBlaber
  • 4,629
  • 2
  • 36
  • 57

2 Answers2

3

I think the best way to implement this is using the Qt Graphics View framework. Create a scene with an Item displaying your image in the back and add draggable Items on top representing the corners of your polygon.

Your selection tool should probably be a subclass of QGraphicsObject hosting the polygon corners as child items and a QGraphicsPolygonItem below the corners being updated whenever the user readjusts the selection. As QGraphicsObject inherits QObject, you can emit signals with a QPolygonF or QPolygon argument whenever the selection changes, informing other parts of your application

This demo should be a good example of the corner-adjust functionality you need.

Qt Pathstroke Demo

(uh well, the example implements the drawing and dragging of the control points from scratch.. I'm sure you can do it by using QGraphicsEllipseItem instead and react on their position changes)

Scheff's Cat
  • 19,528
  • 6
  • 28
  • 56
pwuertz
  • 1,325
  • 8
  • 15
2

I think you would need to code this yourself. There is an excellent example in the C++ GUI Programming with Qt 4 book (there's a PDF copy floating around online; I think it's legal) where they show you how to create a diagram with nodes and links. The chapter is called "Item-based rendering with Graphics View".

The basic idea is that you have some draggable nodes, which are QGraphicsItems with the ItemIsMovable flag set to true, and then some links that connect them, which are QGraphicsLineItems. All of these would go into a composite QGraphicsItem representing the ROI, and all of those would go into a QGraphicsScene, which would be displayed by a QGraphicsView.

Bottom line: there isn't a built-in copy of the MATLAB function, but all the tools are there for you.

Anthony
  • 8,570
  • 3
  • 38
  • 46
  • Thanks for the response. I've found the book you mentioned. I'll try to read it more in depth later. For now I'll mark your response as the answer. – JustinBlaber May 20 '12 at 00:01