Skip to content

Commit

Permalink
Reverted execution logic, no more update IDs, it didn't work well. fi…
Browse files Browse the repository at this point in the history
…xed a slider bug
  • Loading branch information
Kaspar Schmid committed Jun 24, 2015
1 parent 79e413e commit 51a9503
Show file tree
Hide file tree
Showing 10 changed files with 62 additions and 79 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -47,3 +47,4 @@ Makefile.Release
intermediate/
_doc/
_bin/
.settings/
13 changes: 5 additions & 8 deletions IPL/include/IPLProcess.h
Original file line number Diff line number Diff line change
Expand Up @@ -142,12 +142,10 @@ class IPLSHARED_EXPORT IPLProcess
IPLProcessPropertyMap* properties();
IPLProcessProperty* property(std::string key);
void setProperty(std::string key, IPLProcessProperty* value);
bool isResultReady() { return (_completedUpdateID >= _requestedUpdateID); }
void setResultReady() { _completedUpdateID = _requestedUpdateID; }
bool isResultReady() { return _resultReady; }
void setResultReady(bool ready) { _resultReady = ready; }
void requestUpdate();
void requestUpdate(long updateID);
long updateID() { return _completedUpdateID; }
long requestedUpdateID() { return _requestedUpdateID; }

void resetMessages();
void addMessage(IPLProcessMessage msg);
Expand All @@ -160,8 +158,8 @@ class IPLSHARED_EXPORT IPLProcess
bool hasErrors();
bool hasMessages();

std::vector<IPLProcessIO>* inputs () { return &_inputs; }
std::vector<IPLProcessIO>* outputs () { return &_outputs; }
std::vector<IPLProcessIO>* inputs () { return &_inputs; }
std::vector<IPLProcessIO>* outputs () { return &_outputs; }

void setOutputName (int index, std::string name);
void setIsSource (bool isSource) { _isSource = isSource; }
Expand Down Expand Up @@ -215,6 +213,7 @@ class IPLSHARED_EXPORT IPLProcess

bool _isSource;
bool _isSequence;
bool _resultReady;
IPLProgressEventHandler* _progressHandler;
IPLPropertyChangedEventHandler* _propertyHandler;
//std::mutex _propertyMutex;
Expand All @@ -230,8 +229,6 @@ class IPLSHARED_EXPORT IPLProcess
IPLProcessPropertyMap _properties;
std::vector<IPLProcessMessage> _messages;
IPLOpenCVSupport _openCVSupport;
long _requestedUpdateID;
long _completedUpdateID;

};

Expand Down
3 changes: 1 addition & 2 deletions IPL/include/processes/IPLHoughCircles.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,7 @@ class IPLSHARED_EXPORT IPLHoughCircles : public IPLClonableProcess<IPLHoughCircl

protected:
IPLImage* _result;
IPLImage* _binaryImage;
IPLOrientedImage* _orientedImage;
IPLImage* _overlay;
};

#endif // IPLHOUGHCIRCLES_H
16 changes: 4 additions & 12 deletions IPL/src/IPLProcess.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,7 @@ IPLProcess::IPLProcess(void)
{
_isSource = false;
_isSequence = false;
_requestedUpdateID = 1;
_completedUpdateID = 0;
_resultReady = false;
_openCVSupport = IPLProcess::OPENCV_NONE;
_progressHandler = NULL;
_propertyHandler = NULL;
Expand All @@ -41,8 +40,7 @@ IPLProcess::IPLProcess(const IPLProcess &other)
_propertyHandler = other._propertyHandler;
_isSource = other._isSource;
_isSequence = other._isSequence;
_requestedUpdateID = other._requestedUpdateID;
_completedUpdateID = other._completedUpdateID;
_resultReady = other._resultReady;
_title = other._title;
_category = other._category;
_keywords = other._keywords;
Expand All @@ -63,8 +61,7 @@ IPLProcess::IPLProcess(IPLProcess &&other):
_propertyHandler(std::move(other._propertyHandler)),
_isSource(std::move(other._isSource)),
_isSequence(std::move(other._isSequence)),
_requestedUpdateID(std::move(other._requestedUpdateID)),
_completedUpdateID(std::move(other._completedUpdateID)),
_resultReady(std::move(other._resultReady)),
_title(std::move(other._title)),
_category(std::move(other._category)),
_keywords(std::move(other._keywords)),
Expand Down Expand Up @@ -298,12 +295,7 @@ void IPLProcess::setProperty(std::string key, IPLProcessProperty *value)

void IPLProcess::requestUpdate()
{
_requestedUpdateID++;
}

void IPLProcess::requestUpdate(long updateID)
{
_requestedUpdateID = updateID;
_resultReady = false;
}

void IPLProcess::resetMessages()
Expand Down
53 changes: 34 additions & 19 deletions IPL/src/processes/IPLHoughCircles.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,8 @@
void IPLHoughCircles::init()
{
// init
_overlay = NULL;
_result = NULL;
_binaryImage = NULL;
_orientedImage = NULL;

// basic settings
setClassName("IPLHoughCircles");
Expand All @@ -35,8 +34,9 @@ void IPLHoughCircles::init()

// inputs and outputs
addInput("Image", IPLData::IMAGE_COLOR);
addOutput("Circle Positions", IPLImage::POINT);
addOutput("Hough Result", IPLImage::IMAGE_GRAYSCALE);
addOutput("Circle Overlay", IPLImage::IMAGE_COLOR);
addOutput("Circle Positions", IPLImage::POINT);

// properties
addProcessPropertyInt("thresholdCanny", "Threshold 1", "Upper threshold for the internal Canny edge detector", 200, IPL_WIDGET_SLIDER, 1, 200);
Expand All @@ -55,6 +55,8 @@ bool IPLHoughCircles::processInputData(IPLImage* image , int, bool useOpenCV)
// delete previous result
delete _result;
_result = NULL;
delete _overlay;
_overlay = NULL;

// get properties
int thresholdCanny = getProcessPropertyInt("thresholdCanny");
Expand All @@ -63,41 +65,54 @@ bool IPLHoughCircles::processInputData(IPLImage* image , int, bool useOpenCV)
int maxRadius = getProcessPropertyInt("maxRadius");
int minDist = getProcessPropertyInt("minDist");

notifyProgressEventHandler(-1);
cv::Mat input;
cv::Mat output = image->toCvMat();
notifyProgressEventHandler(-1);
cv::Mat input;
cv::Mat overlay = image->toCvMat();
cv::Mat result = cv::Mat(image->height(), image->width(), CV_8UC1);
result = cv::Scalar(0);
cvtColor(image->toCvMat(), input, CV_BGR2GRAY);

std::vector<cv::Vec3f> circles;
cv::HoughCircles(input, circles, CV_HOUGH_GRADIENT, 2, input.rows/4);//, thresholdCanny, thresholdCenter, minRadius, maxRadius);
cv::HoughCircles(input, circles, CV_HOUGH_GRADIENT, 2, input.rows/4, thresholdCanny, thresholdCenter, minRadius, maxRadius);

int size = circles.size();

if(size < 0)
return false;
// WARNING: cv::HoughCircles does not work in debug mode!!!
// destroys the std::vector<cv::Vec3f> circles;

std::stringstream s;
s << "Circles found: ";
s << circles.size();
addInformation(s.str());

/*for(int i = 0; i < circles.size(); i++ )
for(int i = 0; i < circles.size(); i++ )
{
cv::Point center(round(circles[i][0]), round(circles[i][1]));
int radius = cvRound(circles[i][2]);
// circle center
cv::circle(output, center, 3, cv::Scalar(0,255,0), -1, 8, 0);
cv::circle(overlay, center, 3, cv::Scalar(0,255,0), -1, 8, 0);
// circle outline
cv::circle(output, center, radius, cv::Scalar(0,0,255), 3, 1, 0);
}*/
cv::circle(overlay, center, radius, cv::Scalar(0,0,255), 3, 1, 0);

// raw result
cv::circle(result, center, radius, cv::Scalar(255), -1);
}

delete _result;
_result = new IPLImage(output);
_overlay = new IPLImage(overlay);
_result = new IPLImage(result);

return true;
}

IPLData* IPLHoughCircles::getResultData( int )
/*!
* \brief IPLHoughCircles::getResultData
* index == 0: "Hough Result", IPLImage::IMAGE_GRAYSCALE
* index == 1: "Circle Overlay", IPLImage::IMAGE_COLOR
* index == 2: "Circle Positions", IPLImage::IMAGE_POINT
* \return
*/
IPLData* IPLHoughCircles::getResultData(int index)
{
return _result;
if(index == 0)
return _result;
else if(index == 1)
return _overlay;
}
14 changes: 8 additions & 6 deletions IPL/src/processes/IPLMarkImage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ void IPLMarkImage::init()

// basic settings
setClassName("IPLMarkImage");
setTitle("Mark Image");
setTitle("Mark Range");
setCategory(IPLProcess::CATEGORY_POINTOPERATIONS);
setDescription("Mark a level range in the image histogram with a selected color. The background"
"may be cleared or it may retain the original image. The resulting"
Expand All @@ -39,8 +39,9 @@ void IPLMarkImage::init()
// properties
addProcessPropertyDouble("min", "Min", "", 0.4, IPL_WIDGET_SLIDER, 0.0, 1.0);
addProcessPropertyDouble("max", "Max", "", 0.6, IPL_WIDGET_SLIDER, 0.0, 1.0);
addProcessPropertyInt("mode", "Mode:Show Background|Mask Only", "", 0, IPL_WIDGET_COMBOBOX);
addProcessPropertyInt("mode", "Mode:Binary|Show Background|Mask Only", "", 0, IPL_WIDGET_GROUP);
addProcessPropertyColor("color", "Color", "", IPLColor(1.0,0.0,0.0), IPL_WIDGET_COLOR_RGB);
addProcessPropertyBool("invert", "Invert Mask", "", false, IPL_WIDGET_CHECKBOXES);
}

void IPLMarkImage::destroy()
Expand All @@ -59,10 +60,11 @@ bool IPLMarkImage::processInputData(IPLImage* image , int, bool)
_result = new IPLImage(IPLImage::IMAGE_COLOR, width, height );

// get properties
float min = getProcessPropertyDouble("min");
float max = getProcessPropertyDouble("max");
IPLColor color = getProcessPropertyColor("color");
int mode = getProcessPropertyInt("mode");
float min = getProcessPropertyDouble("min");
float max = getProcessPropertyDouble("max");
IPLColor color = getProcessPropertyColor("color");
int mode = getProcessPropertyInt("mode");
bool invert = getProcessPropertyBool("invert");

int progress = 0;
int maxProgress = image->height() * image->getNumberOfPlanes();
Expand Down
2 changes: 0 additions & 2 deletions ImagePlay/include/IPProcessGrid.h
Original file line number Diff line number Diff line change
Expand Up @@ -87,8 +87,6 @@ public slots:
int _lastSequenceIndex; //!< Last image sequence index
bool _isSequenceRunning; //!< Is sequence running
bool _lastProcessSuccess; //!< Last process was successful
long _currentUpdateID; //!< Used to check if an update is needed
long _updateID; //!<
bool _stopExecution; //!< Used to stop the execution early
bool _longProcess; //!< Unmeasurable processes must update GUI regularly

Expand Down
6 changes: 3 additions & 3 deletions ImagePlay/include/PropertyWidgets/IPPropertySliderDouble.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,6 @@ class IPPropertySliderDouble : public IPPropertyWidget
layout()->addWidget(_slider);
layout()->addWidget(_spinner);

connect(_slider, &QSlider::valueChanged, this, &IPPropertySliderDouble::updateSpinner );
connect(_spinner, static_cast<void (QDoubleSpinBox::*)(double)>(&QDoubleSpinBox::valueChanged), this, &IPPropertySliderDouble::updateSlider );

_slider->setMinimum(min*100);
_slider->setMaximum(max*100);
_slider->setValue(value*100);
Expand All @@ -62,6 +59,9 @@ class IPPropertySliderDouble : public IPPropertyWidget
_spinner->setMaximum(max);
_spinner->setValue(value);
_spinner->setSingleStep(0.01);

connect(_slider, &QSlider::valueChanged, this, &IPPropertySliderDouble::updateSpinner );
connect(_spinner, static_cast<void (QDoubleSpinBox::*)(double)>(&QDoubleSpinBox::valueChanged), this, &IPPropertySliderDouble::updateSlider );
}
void setMinimum(double v) { _slider->setMinimum(v*100); }
void setMaximum(double v) { _slider->setMaximum(v*100); }
Expand Down
15 changes: 6 additions & 9 deletions ImagePlay/src/IPProcessGrid.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,6 @@ IPProcessGrid::IPProcessGrid(QWidget *parent) : QGraphicsView(parent)
setMouseTracking(true);

_scale = 1.0;
_currentUpdateID = 0;
_updateID = 0;

_isRunning = false;
_isSequenceRunning = true;
Expand Down Expand Up @@ -142,6 +140,8 @@ int IPProcessGrid::executeThread(IPLProcess* process, IPLImage *image = NULL, in
connect(&thread, &IPProcessThread::progressUpdated, this, &IPProcessGrid::updateProgress);

_mainWindow->setThreadRunning(true);
process->setResultReady(false);
process->resetMessages();

thread.start();
while(!thread.isFinished())
Expand All @@ -151,7 +151,7 @@ int IPProcessGrid::executeThread(IPLProcess* process, IPLImage *image = NULL, in

QApplication::processEvents();
}
process->setResultReady();
process->setResultReady(thread.success());
_mainWindow->setThreadRunning(false);

_lastProcessSuccess = thread.success();
Expand Down Expand Up @@ -193,7 +193,7 @@ void IPProcessGrid::propagateNeedsUpdate(IPLProcess* process)
IPProcessEdge* edge = (IPProcessEdge*) *it;
IPProcessStep* nextStep = edge->to();

nextStep->process()->requestUpdate(step->process()->requestedUpdateID());
nextStep->process()->requestUpdate();

// add to queue and list
tmpQueue.enqueue(nextStep);
Expand Down Expand Up @@ -223,7 +223,6 @@ void IPProcessGrid::execute(bool forcedUpdate /* = false*/)
_mainWindow->lockScene();
_isRunning = true;
_sequenceCount = 0;
_currentUpdateID = _updateID;

qDebug() << "buildQueue";

Expand Down Expand Up @@ -376,13 +375,11 @@ void IPProcessGrid::execute(bool forcedUpdate /* = false*/)
//if(_updateID > _currentUpdateID)
// _mainWindow->execute(false);

_updateID = _currentUpdateID;

// only for testing the camera
//if(graphNeedsUpdate)
// _mainWindow->execute(false);

//_updateNeeded = false;
_updateNeeded = false;
}

void IPProcessGrid::updateProgress(int progress)
Expand Down Expand Up @@ -530,5 +527,5 @@ void IPProcessGrid::setSequenceIndex(int index)

void IPProcessGrid::requestUpdate()
{
_updateID++;
_updateNeeded = true;
}
18 changes: 0 additions & 18 deletions ImagePlay/src/IPProcessStep.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -294,24 +294,6 @@ void IPProcessStep::paint(QPainter *painter, const QStyleOptionGraphicsItem*, QW
painter->setFont(fontSmallGray);
painter->drawText(bounds, Qt::AlignCenter, "CV");
}

// DEBUG
QFont fontSmallGray(painter->font());
fontSmallGray.setBold(true);

QRect idBounds(5,5,44,10);
QBrush brushYellow(QColor(252,248,227));
QPen penYellow(QColor(138,109,59));
painter->setBrush(brushYellow);
painter->setPen(penYellow);
painter->fillRect(idBounds, brushYellow);
painter->drawRect(idBounds);

fontSmallGray.setPointSize(6);
painter->setFont(fontSmallGray);
QString update("%1/%2");
painter->drawText(idBounds, Qt::AlignCenter, update.arg(process()->updateID()).arg(process()->requestedUpdateID()));

}

/*!
Expand Down

0 comments on commit 51a9503

Please sign in to comment.