Compare commits

...

15 Commits

Author SHA1 Message Date
Andrey Tkachenko
9f13434d12 SvPoint Update 2014-08-01 17:35:29 +04:00
Andrey Tkachenko
23f5479b35 Fixed passing data through qml 2014-07-29 17:47:14 +04:00
Andrey Tkachenko
b6b4bf3eb6 Fixed seg fault 2014-07-29 15:22:01 +04:00
Andrey Tkachenko
9316eff244 Fixed OpenGL 2014-07-28 00:04:18 +04:00
Andrey Tkachenko
826af318d3 point cloud 2014-07-25 18:44:53 +04:00
Andrey Tkachenko
a7c102324c OpenGL PointCloudViewer added 2014-07-25 12:32:46 +04:00
Andrey Tkachenko
8bfc0687d8 Point Cloud 2014-07-23 20:51:07 +04:00
Andrey Tkachenko
eefc851af5 Additional Pixels 2014-07-23 15:44:35 +04:00
Andrey Tkachenko
5ab294bfa8 QtV2 2014-07-22 20:37:29 +04:00
Andrey Tkachenko
16cd697457 Add some images 2014-07-18 20:49:26 +04:00
Andrey Tkachenko
60ff52a6e4 V2 begin 2014-07-18 20:48:42 +04:00
Andrey Tkachenko
cae9dc0641 Update image 2014-07-14 18:05:08 +04:00
Andrey Tkachenko
ef41b0c59a Qt fix 2014-07-14 10:55:56 +04:00
Andrey Tkachenko
772bf4e9ae Migrate to Qt 2014-07-11 20:35:48 +04:00
Andrey Tkachenko
c7be57824a Latest 2014-07-11 20:32:56 +04:00
50 changed files with 1464 additions and 601 deletions

1
.gitignore vendored Normal file
View File

@ -0,0 +1 @@
CSV.pro.user

50
CSV.pro Normal file
View File

@ -0,0 +1,50 @@
#-------------------------------------------------
#
# Project created by QtCreator 2014-07-10T12:35:18
#
#-------------------------------------------------
QT += core gui qml quick widgets
TEMPLATE = app
TARGET = CSV
CONFIG += c++11
CONFIG += j4
CONFIG -= console
SOURCES += main.cpp \
svimage.cpp \
svworker.cpp \
svprocessor.cpp \
svimageprovider.cpp \
svpoint.cpp \
svcurve.cpp \
svsimplepoint.cpp \
svfigure.cpp \
svobject.cpp \
svpointcloud.cpp \
svkernel.cpp \
svpointcloudviewer.cpp \
svapplicationcontext.cpp
HEADERS += \
svimage.h \
svworker.h \
svprocessor.h \
svimageprovider.h \
svpoint.h \
svcurve.h \
svsimplepoint.h \
svfigure.h \
svobject.h \
svpointcloud.h \
svdefs.h \
svkernel.h \
svpointcloudviewer.h \
svapplicationcontext.h
RESOURCES += \
resource.qrc
OTHER_FILES += \
Main.qml

210
Main.qml Normal file
View File

@ -0,0 +1,210 @@
import QtQuick 2.2
import QtQuick.Window 2.1
import QtQuick.Controls 1.1
import SvPCV 1.0
ApplicationWindow {
id: mainWindow
visible: true
width: 800
height: 600
statusBar: StatusBar {
Row {
Label {
id: statusBarState
text: "In Progress"
}
}
}
Connections {
target: processor
onFinished: {
statusBarState.text = "Ready " + elapsedTime;
}
}
Item {
anchors.fill: parent
Item {
id: leftColumn
width: 200
anchors.bottom: parent.bottom
anchors.top: parent.top
anchors.right: rightColumn.left
anchors.left: parent.left
Component {
id: slider
Item {
property alias title: sliderTitle.text
property alias from: sliderSlider.minimumValue
property alias to: sliderSlider.maximumValue
property alias step: sliderSlider.stepSize
property string name: ''
height: 50
Text {
id: sliderTitle
anchors.left: parent.left
anchors.right: parent.right
anchors.top: parent.top
anchors.leftMargin: 15
anchors.rightMargin: 10
anchors.topMargin: 10
text: ""
}
Text {
id: sliderValue
anchors.horizontalCenter: parent.horizontalCenter
anchors.bottom: sliderSlider.top
text: sliderSlider.value
}
Slider {
id: sliderSlider
anchors.left: parent.left
anchors.bottom: parent.bottom
anchors.right: parent.right
anchors.leftMargin: 10
anchors.rightMargin: 10
stepSize: 1
}
}
}
Column {
anchors.bottom: renderButton.top
anchors.top: parent.top
anchors.right: parent.right
anchors.left: parent.left
Loader {
id: windowSize
sourceComponent: slider
anchors.left: parent.left
anchors.right: parent.right
onLoaded: {
windowSize.item.title = "Window Size"
windowSize.item.from = 0;
windowSize.item.to = 10;
windowSize.item.step = 1;
}
}
Loader {
id: matchSize
sourceComponent: slider
anchors.left: parent.left
anchors.right: parent.right
onLoaded: {
matchSize.item.title = "Match Size"
matchSize.item.from = 0;
matchSize.item.to = 10;
matchSize.item.step = 1;
}
}
Loader {
id: errorLevel
sourceComponent: slider
anchors.left: parent.left
anchors.right: parent.right
onLoaded: {
errorLevel.item.title = "Error Level"
errorLevel.item.from = 0;
errorLevel.item.to = 10;
errorLevel.item.step = 1;
}
}
}
Button {
id: renderButton
//anchors.bottom: parent.bottom
anchors.horizontalCenter: parent.horizontalCenter
anchors.bottom: parent.bottom
anchors.bottomMargin: 10
Text {
anchors.centerIn: parent
text: "Render"
}
}
}
Item {
id: rightColumn
anchors.bottom: parent.bottom
anchors.top: parent.top
anchors.right: parent.right
anchors.left: leftColumn.right
TabView {
anchors.fill: parent
Tab {
id: imageView
title: "PointCloud View"
Item {
anchors.fill: parent
SvPointCloudViewer {
id: pointCloudViewer1
pointCloud: app.pointCloud()
anchors.fill: parent
}
}
}
Tab {
id: leftImageView
title: "Left Image"
Item {
Flickable {
anchors.fill: parent
contentWidth: image.width
contentHeight: image.height
interactive: true
anchors.margins: 2
clip: true
Item {
Image {
id: leftImage
source: "image://images/left"
smooth: false
}
}
}
}
}
Tab {
id: rightImageView
title: "Right Image"
Item {
Flickable {
anchors.fill: parent
contentWidth: image.width
contentHeight: image.height
interactive: true
anchors.margins: 2
clip: true
Item {
Image {
id: rightImage
source: "image://images/right"
smooth: false
}
}
}
}
}
}
}
}
}

View File

@ -1,59 +0,0 @@
################################################################################
# Automatically-generated file. Do not edit!
################################################################################
-include ../makefile.init
RM := rm -rf
# All of the sources participating in the build are defined here
-include sources.mk
-include src/subdir.mk
-include subdir.mk
-include objects.mk
ifneq ($(MAKECMDGOALS),clean)
ifneq ($(strip $(C++_DEPS)),)
-include $(C++_DEPS)
endif
ifneq ($(strip $(C_DEPS)),)
-include $(C_DEPS)
endif
ifneq ($(strip $(CC_DEPS)),)
-include $(CC_DEPS)
endif
ifneq ($(strip $(CPP_DEPS)),)
-include $(CPP_DEPS)
endif
ifneq ($(strip $(CXX_DEPS)),)
-include $(CXX_DEPS)
endif
ifneq ($(strip $(C_UPPER_DEPS)),)
-include $(C_UPPER_DEPS)
endif
endif
-include ../makefile.defs
# Add inputs and outputs from these tool invocations to the build variables
# All Target
all: CSV
# Tool invocations
CSV: $(OBJS) $(USER_OBJS)
@echo 'Building target: $@'
@echo 'Invoking: GCC C++ Linker'
g++ -o "CSV" $(OBJS) $(USER_OBJS) $(LIBS)
@echo 'Finished building target: $@'
@echo ' '
# Other Targets
clean:
-$(RM) $(OBJS)$(C++_DEPS)$(C_DEPS)$(CC_DEPS)$(CPP_DEPS)$(EXECUTABLES)$(CXX_DEPS)$(C_UPPER_DEPS) CSV
-@echo ' '
.PHONY: all clean dependents
.SECONDARY:
-include ../makefile.targets

View File

@ -1,8 +0,0 @@
################################################################################
# Automatically-generated file. Do not edit!
################################################################################
USER_OBJS :=
LIBS := -lopencv_core -lpthread -lboost_system -lpcl -lpcl_visualization -lopencv_imgproc -lopencv_highgui -lopencv_legacy

View File

@ -1,27 +0,0 @@
################################################################################
# Automatically-generated file. Do not edit!
################################################################################
O_SRCS :=
CPP_SRCS :=
C_UPPER_SRCS :=
C_SRCS :=
S_UPPER_SRCS :=
OBJ_SRCS :=
ASM_SRCS :=
CXX_SRCS :=
C++_SRCS :=
CC_SRCS :=
OBJS :=
C++_DEPS :=
C_DEPS :=
CC_DEPS :=
CPP_DEPS :=
EXECUTABLES :=
CXX_DEPS :=
C_UPPER_DEPS :=
# Every subdirectory with source files must be described here
SUBDIRS := \
src \

View File

@ -1,36 +0,0 @@
################################################################################
# Automatically-generated file. Do not edit!
################################################################################
# Add inputs and outputs from these tool invocations to the build variables
CPP_SRCS += \
../src/SvImage.cpp \
../src/SvMain.cpp \
../src/SvMultithreadProcessor.cpp \
../src/SvProcessorV1.cpp \
../src/SvProcessorV2.cpp
OBJS += \
./src/SvImage.o \
./src/SvMain.o \
./src/SvMultithreadProcessor.o \
./src/SvProcessorV1.o \
./src/SvProcessorV2.o
CPP_DEPS += \
./src/SvImage.d \
./src/SvMain.d \
./src/SvMultithreadProcessor.d \
./src/SvProcessorV1.d \
./src/SvProcessorV2.d
# Each subdirectory must supply rules for building sources it contributes
src/%.o: ../src/%.cpp
@echo 'Building file: $<'
@echo 'Invoking: GCC C++ Compiler'
g++ -std=c++11 -I/usr/include/pcl-1.7 -I/usr/include/vtk-5.8/ -I/usr/include/eigen3 -O3 -Wall -c -fmessage-length=0 -pthread -MMD -MP -MF"$(@:%.o=%.d)" -MT"$(@:%.o=%.d)" -o "$@" "$<"
@echo 'Finished building: $<'
@echo ' '

14
cl/kernel.cl Normal file
View File

@ -0,0 +1,14 @@
__kernel void ProcessLine(__global const float* a, __global const float* b, __global float* c, int iNumElements)
{
// get index into global data array
int iGID = get_global_id(0);
// bound check (equivalent to the limit on a 'for' loop for standard/serial C code
if (iGID >= iNumElements)
{
return;
}
// add the vector elements
c[iGID] = a[iGID] + b[iGID];
}

BIN
img/left1.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 222 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 2.3 MiB

After

Width:  |  Height:  |  Size: 2.1 MiB

BIN
img/right1.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 215 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 2.3 MiB

After

Width:  |  Height:  |  Size: 2.1 MiB

49
main.cpp Normal file
View File

@ -0,0 +1,49 @@
#include <QApplication>
#include <QQmlApplicationEngine>
#include <QQmlComponent>
#include <QQmlContext>
#include "svimage.h"
#include "svprocessor.h"
#include "svimageprovider.h"
#include "svpointcloudviewer.h"
#include "svapplicationcontext.h"
int main(int argc, char *argv[])
{
QGuiApplication a(argc, argv);
qmlRegisterType<SvPointCloudViewer>("SvPCV", 1, 0, "SvPointCloudViewer");
qmlRegisterUncreatableType<SvPointCloud>("SvPCV", 1, 0, "SvApplicationContext", "c++ only");
QQmlApplicationEngine engine;
SvImageProvider imageProvider;
QImage imgLeft("../CSV/img/left3.png");
//QImage imgLeft("../CSV/img/right1.png");
QImage imgRight("../CSV/img/right1.png");
SvImage left(imgLeft);
SvImage right(imgRight);
SvPointCloud pointCloud(imgLeft.width(), imgLeft.height());
SvApplicationContext applicationContext;
applicationContext.setPointCloud(&pointCloud);
SvProcessor proc(4);
proc.enqueueImage(&pointCloud, &left);
imageProvider.addImage("left", &left);
imageProvider.addImage("right", &right);
engine.addImageProvider("images", &imageProvider);
engine.rootContext()->setContextProperty("processor", &proc);
engine.rootContext()->setContextProperty("app", &applicationContext);
engine.load(QUrl(QStringLiteral("qrc:///Main.qml")));
proc.start();
return a.exec();
}

7
resource.qrc Normal file
View File

@ -0,0 +1,7 @@
<RCC>
<qresource prefix="/">
<file>Main.qml</file>
<file>img/left4.png</file>
<file>img/right4.png</file>
</qresource>
</RCC>

View File

@ -1,74 +0,0 @@
/*
* SvImage.cpp
*
* Created on: 27 июня 2014 г.
* Author: andrey
*/
#include "SvImage.h"
int SvImage::getPixel(int x, int y, int channel = -1) {
if (y >= this->image->rows || y < 0 || x >= this->image->cols || x < 0) {
return 0;
}
uchar* pixel = this->image->ptr(y, x);
uchar value;
if (channel == -1 || channel > 2) {
value = 0.299 * pixel[0] + 0.587 * pixel[1] + 0.114 * pixel[2];
} else {
value = pixel[channel];
}
return value;
}
int SvImage::getPixelHue(int x, int y) {
uchar* pixel = this->image->ptr(y, x);
if (x >= 0 && x < this->image->cols && y >= 0 && y < this->image->rows) {
return abs(pixel[1] - pixel[0]) + abs(pixel[2] - pixel[1]);
}
return 0;
}
int SvImage::getPixelValue(int x, int y) {
uchar* pixel = this->image->ptr(y, x);
if (x >= 0 && x < this->image->cols && y >= 0 && y < this->image->rows) {
return (pixel[0] + pixel[1] + pixel[2])/3;
}
return 0;
}
void SvImage::putPixel(int x, int y, int value)
{
uchar* data;
if (x >= 0 && x < this->image->cols && y >= 0 && y < this->image->rows) {
data = this->image->ptr(y, x);
data[0] = value;
}
}
int SvImage::getHeight() {
return this->image->rows;
}
int SvImage::getWidth() {
return this->image->cols;
}
Mat& SvImage::getCvMatrix() {
return *this->image;
}
SvImage::SvImage(Mat& image) {
this->image = &image;
}
SvImage::~SvImage() {
}

View File

@ -1,34 +0,0 @@
/*
* SvImage.h
*
* Created on: 27 июня 2014 г.
* Author: andrey
*/
#ifndef SVIMAGE_H_
#define SVIMAGE_H_
#include <opencv2/opencv.hpp>
using namespace cv;
class SvImage {
protected:
Mat* image;
public:
int getPixel(int x, int y, int channel);
int getPixelHue(int x, int y);
int getPixelValue(int x, int y);
void putPixel(int x, int y, int val);
int getHeight();
int getWidth();
Mat& getCvMatrix();
SvImage(Mat& image);
virtual ~SvImage();
};
#endif /* SVIMAGE_H_ */

View File

@ -1,102 +0,0 @@
//============================================================================
// Name : CSV.cpp
// Author : Andrey
// Version :
// Copyright : Your copyright notice
// Description : Computer Stereo Vision in C++, Ansi-style
//============================================================================
#include <opencv2/opencv.hpp>
#include "SvImage.h"
#include "SvProcessorV1.h"
#include "SvProcessorV2.h"
#include <thread>
//#include <pcl/point_cloud.h>
//#include <pcl/point_types.h>
//#include <pcl/visualization/pcl_visualizer.h>
//#include <vtkRenderWindow.h>
//#include <pcl/visualization/cloud_viewer.h>
//#include <pcl/filters/statistical_outlier_removal.h>
using namespace cv;
void CallBackFunc(int event, int x, int y, int flags, void* userdata)
{
if (event == EVENT_LBUTTONDOWN ) {
} else if ( event == EVENT_RBUTTONDOWN ) {
} else if ( event == EVENT_MBUTTONDOWN ) {
} else if ( event == EVENT_MOUSEMOVE ) {
}
}
int main(int argc, char** argv) {
Mat matLeft = imread("img/left8.png", 1);
Mat matRight = imread("img/right8.png", 1);
Mat matStereo(Mat::zeros(matLeft.rows, matLeft.cols, CV_8U));
SvImage left(matLeft);
SvImage right(matRight);
SvImage stereo(matStereo);
int line = 0;
SvProcessorV2 proc[4];
for (int i = 0; i < 4; i++) {
proc[i].setLeftImage(left);
proc[i].setRightImage(right);
}
while (line < stereo.getHeight()) {
for (int i = 0; i < 4; i++) {
if (line < stereo.getHeight() && !proc[i].isActive()) {
proc[i].run(stereo, line++);
}
}
}
//pcl::PointXYZRGB point;
//pcl::PointCloud<pcl::PointXYZRGB>::Ptr cloud(new pcl::PointCloud<pcl::PointXYZRGB>);
//pcl::PointCloud<pcl::PointXYZRGB>::Ptr cloud_filtered (new pcl::PointCloud<pcl::PointXYZRGB>);
/*cloud->resize(stereo.getHeight() * stereo.getWidth());
for (int y = 0; y < stereo.getHeight(); y++) {
for (int x = 0; x < stereo.getWidth(); x++) {
int i = stereo.getWidth() * y + x;
int value = stereo.getPixel(x, y, 0);
if (value) {
cloud->points[i].x = (x - (stereo.getWidth() / 2.0))/100.0;
cloud->points[i].y = (-y + (stereo.getHeight() / 2.0))/100.0;
cloud->points[i].z = (-stereo.getPixel(x, y, 0) * 6.0)/100.0;
cloud->points[i].r = left.getPixel(x, y, 2);
cloud->points[i].g = left.getPixel(x, y, 1);
cloud->points[i].b = left.getPixel(x, y, 0);
}
}
}*/
/*
pcl::StatisticalOutlierRemoval<pcl::PointXYZRGB> sor;
sor.setInputCloud(cloud);
sor.setMeanK(50);
sor.setStddevMulThresh(1.0);
sor.filter(*cloud_filtered);
*/
/*pcl::visualization::CloudViewer viewer("Simple Cloud Viewer");
viewer.showCloud(cloud);
while (!viewer.wasStopped ())
{
}*/
imshow("Display Image", stereo.getCvMatrix());
//setMouseCallback("Display Image", CallBackFunc, NULL);
waitKey();
return 0;
}

View File

@ -1,41 +0,0 @@
/*
* SvMultithreadProcessor.cpp
*
* Created on: 09 июля 2014 г.
* Author: andrey
*/
#include "SvMultithreadProcessor.h"
SvMultithreadProcessor::SvMultithreadProcessor(SvImage& left, SvImage& right) {
m_left = &left;
m_right = &right;
m_stereo = NULL;
m_line = 0;
}
SvMultithreadProcessor::SvMultithreadProcessor() {
}
int SvMultithreadProcessor::run(SvImage& stereo, int line) {
m_stereo = &stereo;
m_line = line;
m_thread = std::thread(&SvMultithreadProcessor::process, this);
return 0;
}
void SvMultithreadProcessor::process() {
exec();
m_thread.detach();
}
void SvMultithreadProcessor::exec() {
}
SvMultithreadProcessor::~SvMultithreadProcessor() {
}

View File

@ -1,42 +0,0 @@
/*
* SvMultithreadProcessor.h
*
* Created on: 09 июля 2014 г.
* Author: andrey
*/
#ifndef SVMULTITHREADPROCESSOR_H_
#define SVMULTITHREADPROCESSOR_H_
#include <thread>
#include "SvImage.h"
class SvMultithreadProcessor {
protected:
SvImage* m_left;
SvImage* m_right;
SvImage* m_stereo;
std::thread m_thread;
int m_line;
public:
void setLeftImage(SvImage& image) { m_left = &image;}
void setRightImage(SvImage& image) { m_right = &image;}
bool isActive() { return m_thread.joinable(); }
void join() { m_thread.join(); }
void detach() { m_thread.detach(); }
int run(SvImage& stereo, int line);
void process();
virtual void exec();
SvMultithreadProcessor(SvImage& left, SvImage& right);
SvMultithreadProcessor();
virtual ~SvMultithreadProcessor();
};
#endif /* SVMULTITHREADPROCESSOR_H_ */

View File

@ -1,112 +0,0 @@
/*
* SvProcessor.cpp
*
* Created on: 27 июня 2014 г.
* Author: andrey
*/
#include "SvProcessorV1.h"
int SvProcessorV1::getPixelColor(int cursor) {
if (cursor == 0) {
return 0;
}
return ((10 * m_left->getWidth()) / (2.0 * 0.9 * cursor ));
}
/*
int SvProcessorV1::match(int x, int y, int j) {
int error = 0;
for (int i = 0; i <= 1; i++) {
for (int g = 0; g <= 2; g++) {
error += diff(x + i, y + g, x + i + j, y + g);
}
}
return error;
}*/
int SvProcessorV1::diff(int lx, int ly, int rx, int ry) {
int Rvalue, Gvalue, Bvalue, color;
Rvalue = abs(m_left->getPixel(lx, ly, 0) - m_right->getPixel(rx, ry, 0));
Gvalue = abs(m_left->getPixel(lx, ly, 1) - m_right->getPixel(rx, ry, 1));
Bvalue = abs(m_left->getPixel(lx, ly, 2) - m_right->getPixel(rx, ry, 2));
color = abs(Gvalue - Rvalue) + abs(Bvalue - Gvalue);
return (Gvalue + Rvalue + Bvalue) +
color * 4;
}
int SvProcessorV1::match(int x, int y, int j) {
int error = 0;
int ms = 4;
int c = diff(x, y, x + j, y),
l = 0, r = 0, t = 0, b = 0;
error = c;
for (int i = 1; i <= ms; i++) {
l += diff(x - i, y, x + j - i, y);
r += diff(x + i, y, x + j + i, y);
t += diff(x, y - i, x + j, y - i);
b += diff(x, y + i, x + j, y + i);
}
error += l > r ? r : l;
error += t > b ? b : t;
//error += l + r + b + t;
return error;
}
void SvProcessorV1::exec() {
int x, y, cursor, closest, tmp;
int minErrorValue, tmpSmoothed, matched;
int precursor, preprecursor;
int dist, diff, val, prev, preprev;
cursor = 0;
precursor = 0;
preprecursor = 0;
for (x = 0; x < m_stereo->getWidth(); x++) {
closest = -1; minErrorValue = -1;matched=0;
minErrorValue=-1;
val = m_left->getPixelHue(x, m_line);
for (int i = 1; i < windowSize; i++) {
dist = (abs(cursor - i));
tmp = match(x, m_line, i);
tmpSmoothed = tmp;// + (dist) * (1.0/diff);
if (tmpSmoothed < minErrorValue || minErrorValue == -1) {
minErrorValue = tmpSmoothed;
closest = i;
matched = 1;
} else if (tmpSmoothed == minErrorValue) {
if (abs(cursor - i) < abs(cursor - closest)) {
closest = i;
matched++;
}
}
}
if (matched == 1) {
cursor = closest;
}
m_stereo->putPixel(x, m_line, getPixelColor(cursor));
preprecursor = precursor;
precursor = cursor;
preprev = prev;
prev = val;
}
}

View File

@ -1,31 +0,0 @@
/*
* SvProcessor.h
*
* Created on: 27 июня 2014 г.
* Author: andrey
*/
#ifndef SVPROCESSORV1_H_
#define SVPROCESSORV1_H_
#include <iostream>
#include <thread>
#include "SvImage.h"
#include "SvMultithreadProcessor.h"
using namespace std;
class SvProcessorV1 : public SvMultithreadProcessor {
protected:
const int windowSize = 90;
public:
int diff(int lx, int ly, int rx, int ry);
int match(int x, int y, int i);
void exec();
int getPixelColor(int cursor);
};
#endif /* SVPROCESSORV1_H_ */

View File

@ -1,12 +0,0 @@
/*
* SvProcessor.cpp
*
* Created on: 27 июня 2014 г.
* Author: andrey
*/
#include "SvProcessorV2.h"
void SvProcessorV2::exec() {
}

View File

@ -1,23 +0,0 @@
/*
* SvProcessor.h
*
* Created on: 27 июня 2014 г.
* Author: andrey
*/
#ifndef SVPROCESSOR_H_
#define SVPROCESSOR_H_
#include <iostream>
#include "SvImage.h"
#include "SvMultithreadProcessor.h"
class SvProcessorV2 : public SvMultithreadProcessor {
protected:
public:
void exec();
};
#endif /* SVPROCESSOR_H_ */

6
svapplicationcontext.cpp Normal file
View File

@ -0,0 +1,6 @@
#include "svapplicationcontext.h"
SvApplicationContext::SvApplicationContext(QObject *parent) :
QObject(parent)
{
}

22
svapplicationcontext.h Normal file
View File

@ -0,0 +1,22 @@
#ifndef SVPOINTCLOUDVIEWMODEL_H
#define SVPOINTCLOUDVIEWMODEL_H
#include <QObject>
#include "svpointcloud.h"
class SvApplicationContext : public QObject
{
Q_OBJECT
public:
explicit SvApplicationContext(QObject *parent = 0);
void setPointCloud(SvPointCloud *pointCloud) { m_pointCloud = pointCloud; }
Q_INVOKABLE SvPointCloud* pointCloud() { return m_pointCloud; }
private:
SvPointCloud *m_pointCloud;
};
#endif // SVPOINTCLOUDVIEWMODEL_H

26
svcurve.cpp Normal file
View File

@ -0,0 +1,26 @@
#include "svcurve.h"
SvCurve::SvCurve()
{
}
void SvCurve::addPoint(SvPoint *point)
{
m_points.push_back(point);
}
bool SvCurve::hasPoint(SvPoint *point)
{
foreach (SvPoint *item, m_points) {
if (point == item) {
return true;
}
}
return false;
}
SvCurve *SvCurve::cut(SvPoint *point)
{
}

34
svcurve.h Normal file
View File

@ -0,0 +1,34 @@
#ifndef SVCURVE_H
#define SVCURVE_H
#include "svdefs.h"
#include "svpoint.h"
#include "svsimplepoint.h"
class SvPoint;
class SvFigure;
class SvCurve
{
protected:
SvFigure *m_inner;
SvFigure *m_outer;
QList<SvPoint*> m_points;
QList<SvSimplePoint*> m_keyPoints;
private:
SvCurve();
public:
QList<SvPoint*> &points() {return m_points; }
SvPoint* head() {return m_points.first(); }
SvPoint* tail() {return m_points.last(); }
void setInner(SvFigure *figure) {m_inner = figure; }
void setOuter(SvFigure *figure) {m_outer = figure; }
void addPoint(SvPoint *point);
bool hasPoint(SvPoint *point);
SvCurve *cut(SvPoint *point);
};
#endif // SVCURVE_H

25
svdefs.h Normal file
View File

@ -0,0 +1,25 @@
#ifndef SVDEFS_H
#define SVDEFS_H
#include <QDebug>
#include <QRgb>
typedef unsigned int SvPointId;
typedef unsigned int uint;
#include "svpointcloud.h"
#include "svimage.h"
class SvPointCloud;
typedef struct {
SvPointCloud *pointCloud;
SvImage *image;
int line;
} SvProcessorTask;
#define sign(a) (a == 0 ? 0 : (a > 0 ? 1 : -1))
#define max(a,b,c) (a > b ? (a > c ? a : c) : (b > c ? b : c))
#define min(a,b,c) (a < b ? (a < c ? a : c) : (b < c ? b : c))
#endif // SVDEFS_H

41
svfigure.cpp Normal file
View File

@ -0,0 +1,41 @@
#include "svfigure.h"
SvFigure::SvFigure(SvCurve *curve)
{
addCurve(curve);
}
SvFigure::SvFigure()
{
}
SvCurve *SvFigure::findCurveByPoint(SvPoint *point)
{
foreach(SvCurve* curve, m_curves) {
if (curve->hasPoint(point)) {
return curve;
}
}
return 0;
}
SvFigure SvFigure::split(SvPoint *point)
{
SvCurve *curve = findCurveByPoint(point);
SvFigure figure;
if (curve) {
figure.addCurve(curve->cut(point));
SvCurve *item = m_curves.last();
while(item != curve) {
figure.addCurve(item);
m_curves.removeLast();
item = m_curves.last();
}
}
return figure;
}

26
svfigure.h Normal file
View File

@ -0,0 +1,26 @@
#ifndef SVFIGURE_H
#define SVFIGURE_H
#include <QColor>
#include "svpoint.h"
#include "svcurve.h"
class SvFigure
{
protected:
QRgb m_color;
QList<SvCurve*> m_curves;
public:
SvFigure();
SvFigure(SvCurve *curve);
QRgb color() {return m_color;}
void addCurve(SvCurve *curve){m_curves.push_back(curve); }
QList<SvCurve*> &curves() { return m_curves; }
SvCurve *findCurveByPoint(SvPoint *point);
SvFigure split(SvPoint *point);
};
#endif // SVFIGURE_H

148
svimage.cpp Normal file
View File

@ -0,0 +1,148 @@
#include "svimage.h"
int SvImage::getPixel(int x, int y, int channel) {
if (y >= m_image->height() ||
y < 0 ||
x >= m_image->width()
|| x < 0) {
return 0;
}
QRgb rgb = m_image->pixel(x, y);
switch (channel) {
case 0:
return qRed(rgb);
case 1:
return qGreen(rgb);
case 2:
return qBlue(rgb);
default:
return qGray(rgb);
}
}
int SvImage::getPixelNormalizedHue(int x, int y) {
if (y >= m_image->height() ||
y < 0 ||
x >= m_image->width()
|| x < 0) {
return 0;
}
QRgb rgb = m_image->pixel(x, y);
QColor color(rgb);
return (color.hsvHue() * getPixelSaturation(x, y)) / 255;
}
int SvImage::getPixelHue(int x, int y) {
if (y >= m_image->height() ||
y < 0 ||
x >= m_image->width()
|| x < 0) {
return 0;
}
QRgb rgb = m_image->pixel(x, y);
QColor color(rgb);
return color.hsvHue();
}
int SvImage::getPixelValue(int x, int y) {
if (y >= m_image->height() ||
y < 0 ||
x >= m_image->width()
|| x < 0) {
return 0;
}
QRgb rgb = m_image->pixel(x, y);
QColor color(rgb);
return color.value();
}
int SvImage::getPixelSaturation(int x, int y)
{
if (y >= m_image->height() ||
y < 0 ||
x >= m_image->width()
|| x < 0) {
return 0;
}
QRgb rgb = m_image->pixel(x, y);
QColor color(rgb);
return color.saturation();
}
QRgb SvImage::getPixelRGB(int x, int y)
{
if (y >= m_image->height() ||
y < 0 ||
x >= m_image->width()
|| x < 0) {
return 0;
}
return m_image->pixel(x, y);
}
void SvImage::putGrayPixel(int x, int y, int value)
{
if (y >= m_image->height() ||
y < 0 ||
x >= m_image->width()
|| x < 0) {
return;
}
if (value > 255) {
value = 255;
}
m_image->setPixel(x, y, qRgb(value, value, value));
}
void SvImage::putPixel(int x, int y, int red, int green, int blue)
{
if (y >= m_image->height() ||
y < 0 ||
x >= m_image->width()
|| x < 0) {
return;
}
m_image->setPixel(x, y, qRgb(red, green, blue));
}
unsigned int SvImage::getHeight() {
return m_image->height();
}
unsigned int SvImage::getWidth() {
return m_image->width();
}
QImage& SvImage::getImage() {
return *m_image;
}
SvImage::SvImage(QImage& image) {
m_image = &image;
}
SvImage::~SvImage() {
}

32
svimage.h Normal file
View File

@ -0,0 +1,32 @@
#ifndef SVIMAGE_H
#define SVIMAGE_H
#include <QImage>
#include <QColor>
#include <QRgb>
class SvImage
{
protected:
QImage* m_image;
public:
int getPixel(int x, int y, int channel = -1);
int getPixelHue(int x, int y);
int getPixelNormalizedHue(int x, int y);
int getPixelValue(int x, int y);
int getPixelSaturation(int x, int y);
QRgb getPixelRGB(int x, int y);
void putGrayPixel(int x, int y, int val);
void putPixel(int x, int y, int red, int green, int blue);
unsigned int getHeight();
unsigned int getWidth();
QImage& getImage();
SvImage(QImage& image);
virtual ~SvImage();
};
#endif // SVIMAGE_H

27
svimageprovider.cpp Normal file
View File

@ -0,0 +1,27 @@
#include "svimageprovider.h"
SvImageProvider::SvImageProvider():
QQuickImageProvider(QQuickImageProvider::Image)
{
}
QImage SvImageProvider::requestImage(const QString &id, QSize *size, const QSize &requestedSize)
{
Q_UNUSED(requestedSize)
SvImage* image = m_images[id];
if (image) {
*size = QSize(image->getWidth(), image->getHeight());
return image->getImage();
}
return QImage(0, 0, QImage::Format_RGB32);
}
void SvImageProvider::addImage(const QString &name, SvImage *image)
{
m_images[name] = image;
}

22
svimageprovider.h Normal file
View File

@ -0,0 +1,22 @@
#ifndef SVIMAGEPROVIDER_H
#define SVIMAGEPROVIDER_H
#include <QtQuick/QQuickImageProvider>
#include <QHash>
#include "svimage.h"
#include <QDebug>
class SvImageProvider : public QQuickImageProvider
{
protected:
QHash<QString, SvImage*> m_images;
public:
SvImageProvider();
virtual QImage requestImage(const QString &id, QSize *size, const QSize& requestedSize);
void addImage(const QString &name, SvImage* image);
};
#endif // SVIMAGEPROVIDER_H

112
svkernel.cpp Normal file
View File

@ -0,0 +1,112 @@
#include "svkernel.h"
SvKernel::SvKernel()
{
}
SvKernel::~SvKernel()
{
}
int SvKernel::rgbDiff(QRgb left, QRgb right)
{
QColor cLeft(left);
QColor cRight(right);
int leftDiff = max(qBlue(left), qRed(left), qGreen(left)) -
min(qBlue(left), qRed(left), qGreen(left));
int rightDiff = max(qBlue(right), qRed(right), qGreen(right)) -
min(qBlue(right), qRed(right), qGreen(right));
int minDiff= leftDiff < rightDiff ? rightDiff : leftDiff;
int diff = qGray(left) - qGray(right);
int hsvDiff = minDiff > 70 ? abs(cLeft.hsvHue() - cRight.hsvHue()) : 0;
if (hsvDiff > 180) {
hsvDiff = 360 - hsvDiff;
}
int dsign = sign(diff);
dsign = dsign == 0 ? 1 : dsign;
return /*dsign * (abs(rightDiff - leftDiff)>>2) + */diff /*+ (hsvDiff > 5 ? dsign * 10 : 0)*/;
}
void SvKernel::exec(SvPointCloud *pc, SvImage *image, int line)
{
SvPoint p;
QRgb vtop, top, right, bottom, vbottom, center;
QRgb rTop, lTop;
int __dX, _dX, dX, dX_,
__dY, _dY, dY, dY_;
int hDiff, vDiff;
for (int x = 0; x < image->getWidth(); x++) {
hDiff = 0; vDiff = 0;
top = image->getPixelRGB(x - 1, line - 2);
right = image->getPixelRGB(x, line - 1);
bottom = image->getPixelRGB(x - 1, line);
vtop = image->getPixelRGB(x - 1, line - 3);
dX_ = rgbDiff(center, right);
dY_ = rgbDiff(vtop, top);
dY = rgbDiff(top, center);
_dY = rgbDiff(center, bottom);
if ( dX >= _dX && dX > dX_ ||
dX <= _dX && dX < dX_) {
if (dX == _dX) {
if (dX > dX_ && _dX > __dX ||
dX < dX_ && _dX < __dX) {
hDiff = abs(dX);
}
} else {
hDiff = abs(dX);
}
}
if ( dY >= _dY && dY > dY_ ||
dY <= _dY && dY < dY_) {
if (dY == _dY) {
vbottom = image->getPixelRGB(x - 1, line + 1);
__dY = rgbDiff(bottom, vbottom);
if (dY > dY_ && _dY > __dY ||
dY < dY_ && _dY < __dY) {
vDiff = abs(dY);
}
} else {
vDiff = abs(dY);
}
}
if (hDiff > 0 || vDiff > 0) {
if (x > 1 && line > 1){
lTop = image->getPixelRGB(x - 2, line - 2);
rTop = image->getPixelRGB(x, line - 2);
p.setX(x - 1);
p.setY(line - 1);
p.setDiff(hDiff, rgbDiff(center, lTop), vDiff, rgbDiff(center, rTop));
pc->addPoint(p);
}
}
__dX = _dX;
_dX = dX;
dX = dX_;
center = right;
}
}

17
svkernel.h Normal file
View File

@ -0,0 +1,17 @@
#ifndef SVKERNELV2_H
#define SVKERNELV2_H
#include "svdefs.h"
#include "svimage.h"
#include "svpointcloud.h"
class SvKernel
{
public:
SvKernel();
virtual ~SvKernel();
void exec(SvPointCloud *pc, SvImage *image, int line);
int rgbDiff(QRgb left, QRgb right);
};
#endif // SVKERNELV2_H

5
svobject.cpp Normal file
View File

@ -0,0 +1,5 @@
#include "svobject.h"
SvObject::SvObject()
{
}

18
svobject.h Normal file
View File

@ -0,0 +1,18 @@
#ifndef SVOBJECT_H
#define SVOBJECT_H
#include "svfigure.h"
class SvFigure;
class SvObject
{
protected:
SvFigure *m_figures;
public:
SvObject();
};
#endif // SVOBJECT_H

30
svpoint.cpp Normal file
View File

@ -0,0 +1,30 @@
#include "svpoint.h"
SvPoint::SvPoint()
{
}
SvPoint::SvPoint(SvPoint &point)
{
(*this) = point;
}
void SvPoint::addCurve(SvCurve *curve)
{
m_curves[m_curveCount++] = curve;
}
int SvPoint::parallelism(SvPoint *p, DiffType type)
{
}
void SvPoint::setDiff(int lDiff, int ltDiff, int tDiff, int rtDiff)
{
m_diff[LEFT] = lDiff;
m_diff[LEFT_TOP] = ltDiff;
m_diff[TOP] = tDiff;
m_diff[RIGHT_TOP] = rtDiff;
}

41
svpoint.h Normal file
View File

@ -0,0 +1,41 @@
#ifndef SVPOINT_H
#define SVPOINT_H
#include "svsimplepoint.h"
#include "svdefs.h"
class SvCurve;
class SvPoint: public SvSimplePoint
{
public:
enum DiffType {
LEFT = 0,
LEFT_TOP = 1,
TOP = 2,
RIGHT_TOP = 3
};
protected:
uint m_id;
uint m_curveCount;
SvCurve *m_curves[8];
int m_diff[4];
QRgb m_colors[4];
public:
SvPoint();
SvPoint(SvPoint &point);
void addCurve(SvCurve *curve);
uint curveCount() {return m_curveCount; }
SvCurve *curve(uint index) { return m_curves[index]; }
int parallelism(SvPoint *p, DiffType type);
int diff(DiffType index) { return m_diff[index]; }
void setDiff(int lDiff, int ltDiff, int tDiff, int rtDiff);
void setColors(QRgb left, QRgb top, QRgb right, QRgb bottom);
};
#endif // SVPOINT_H

62
svpointcloud.cpp Normal file
View File

@ -0,0 +1,62 @@
#include "svpointcloud.h"
#include <string.h>
SvPointCloud::SvPointCloud(uint width, uint height)
{
m_pointFieldHeight = height;
m_pointFieldWidth = width;
m_pointField = new SvPoint**[height];
for (uint y = 0; y < height; y++) {
m_pointField[y] = new SvPoint*[width];
memset(m_pointField[y], 0, sizeof(SvPoint*) * width);
}
}
SvPointCloud::~SvPointCloud()
{
for (uint y = 0; y < m_pointFieldHeight; y++) {
for (uint x = 0; x < m_pointFieldWidth; x++) {
if (m_pointField[y][x]) {
delete m_pointField[y][x];
}
}
delete[] m_pointField[y];
}
delete[] m_pointField;
}
void SvPointCloud::addPoint(SvPoint &point)
{
int x = point.x(),
y = point.y();
SvPoint *topLeft, *top, *topRight;
SvPoint *left, *center, *right;
SvPoint *bottomLeft, *bottom, *bottomRight;
center = m_pointField[y][x - 1];
if (y > 1 && y < m_pointFieldHeight - 1 &&
x > 1 && x < m_pointFieldWidth && center) {
topRight = m_pointField[y - 1][x ];
top = m_pointField[y - 1][x - 1];
topLeft = m_pointField[y - 1][x - 2];
right = new SvPoint(point);
left = m_pointField[y ][x - 2];
bottomRight = m_pointField[y + 1][x ];
bottom = m_pointField[y + 1][x - 1];
bottomLeft = m_pointField[y + 1][x - 2];
}
m_pointField[y][x] = right;
}

49
svpointcloud.h Normal file
View File

@ -0,0 +1,49 @@
#ifndef SVPOINTCLOUD_H
#define SVPOINTCLOUD_H
#include <QObject>
#include "svdefs.h"
#include "svpoint.h"
#include "svcurve.h"
#include "svfigure.h"
#include "svobject.h"
class SvCurve;
class SvFigure;
class SvObject;
class SvPointCloud: public QObject
{
Q_OBJECT
friend class SvCurve;
friend class SvPoint;
friend class SvFigure;
friend class SvObject;
protected:
uint m_pointFieldHeight;
uint m_pointFieldWidth;
SvPoint*** m_pointField;
QList<SvCurve*> m_curves;
QList<SvFigure*> m_figures;
QList<SvObject*> m_objects;
public:
SvPointCloud(uint width, uint height);
~SvPointCloud();
SvCurve *createCurve();
SvFigure *createFigure();
SvObject *createObject();
void addPoint(SvPoint &point);
uint getWidth() { return m_pointFieldWidth; }
uint getHeight() { return m_pointFieldHeight; }
SvPoint *point(uint x, uint y) { return m_pointField[y][x]; }
QList<SvCurve*> &curves() { return m_curves; }
QList<SvFigure*> &figures() { return m_figures; }
};
#endif // SVPOINTCLOUD_H

94
svpointcloudviewer.cpp Normal file
View File

@ -0,0 +1,94 @@
#include "svpointcloudviewer.h"
#include <QtGui/QOpenGLShaderProgram>
#include <QtGui/QOpenGLContext>
SvPointCloudViewer::SvPointCloudViewer(QQuickItem *parent) :
QQuickPaintedItem(parent)
{
setRenderTarget(QQuickPaintedItem::FramebufferObject);
}
void SvPointCloudViewer::paint(QPainter *painter)
{
if (!m_pointCloud) {
qDebug() << "point cloud not set!";
return;
}
painter->beginNativePainting();
glViewport(0, 0, width(), height());
glClearColor(0, 0, 0, 1);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
glTranslatef(0.0f, height(), -40.0f);
glPointSize(1.0f);
glScalef(1.0f, 1.0f, 1.0f);
foreach (SvFigure *figure, m_pointCloud->figures()) {
glBegin(GL_POLYGON);
glColor3ub(qRed(figure->color()), qGreen(figure->color()), qBlue(figure->color()));
foreach (SvCurve *curve, figure->curves()) {
foreach (SvPoint *point, curve->points()) {
glVertex3i(point->x(), point->y(), 0);
}
}
glEnd();
}
painter->endNativePainting();
}
/*
void SvPointCloudViewer::paint(QPainter *painter)
{
if (!m_pointCloud) {
qDebug() << "point cloud not set!";
return;
}
painter->beginNativePainting();
glViewport(0, 0, width(), height());
glClearColor(0, 0, 0, 1);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
glTranslatef(0.0f, height(), -40.0f);
glPointSize(1.0f);
glScalef(1.0f, 1.0f, 1.0f);
glBegin(GL_POINTS);
for (int y = 1; y < m_pointCloud->getHeight(); y++) {
for (int x = 1; x < m_pointCloud->getWidth() - 1; x++) {
SvPoint *lp = m_pointCloud->point(x - 1, y);
SvPoint *tlp = m_pointCloud->point(x - 1, y - 1);
SvPoint *tp = m_pointCloud->point(x, y - 1);
SvPoint *trp = m_pointCloud->point(x + 1, y - 1);
SvPoint *p = m_pointCloud->point(x, y);
if (p) {
//glColor3ub(0, 0, 0);
int topRight = abs(p->diff(SvPoint::RIGHT_TOP));
int topLeft = abs(p->diff(SvPoint::LEFT_TOP));
int left = abs(p->diff(SvPoint::LEFT));
int top = abs(p->diff(SvPoint::TOP));
glColor3ub(top * 4 > 255 ? 255 : top * 4, left * 4 > 255 ? 255 : left * 4, 0);
}
}
}
glEnd();
painter->endNativePainting();
}
*/

48
svpointcloudviewer.h Normal file
View File

@ -0,0 +1,48 @@
#ifndef SVPOINTCLOUDVIEWER_H
#define SVPOINTCLOUDVIEWER_H
#include <QQuickPaintedItem>
#include <QQuickWindow>
#include <QPainter>
#include <QtGui/QOpenGLShaderProgram>
#include <QtGui/QOpenGLContext>
#include "svpointcloud.h"
#include "svapplicationcontext.h"
class SvPointCloudViewer : public QQuickPaintedItem
{
Q_OBJECT
Q_PROPERTY(SvPointCloud *pointCloud READ pointCloud WRITE setPointCloud NOTIFY pointCloudChanged)
// Q_PROPERTY(QString test123 READ pointCloud WRITE setPointCloud NOTIFY pointCloudChanged)
// Q_PROPERTY(qreal cameraX READ cameraX WRITE setCameraX NOTIFY cameraXChanged)
// Q_PROPERTY(qreal cameraY READ cameraY WRITE setCameraY NOTIFY cameraYChanged)
// Q_PROPERTY(qreal cameraZ READ cameraZ WRITE setCameraZ NOTIFY cameraZChanged)
protected:
SvPointCloud *m_pointCloud;
qreal m_cameraX;
qreal m_cameraY;
qreal m_cameraZ;
public:
explicit SvPointCloudViewer(QQuickItem *parent = 0);
void paint(QPainter *painter);
void setPointCloud(SvPointCloud *pointCloud) { m_pointCloud = pointCloud; }
SvPointCloud *pointCloud() { return m_pointCloud; }
signals:
void pointCloudChanged();
void cameraXChanged();
void cameraYChanged();
void cameraZChanged();
public slots:
//void resetCamera();
//void moveCamera(qreal X, qreal Y, qreal Z);
// void rotateCamera(qreal X, qreal Y, qreal Z);
};
#endif // SVPOINTCLOUDVIEWER_H

95
svprocessor.cpp Normal file
View File

@ -0,0 +1,95 @@
#include "svprocessor.h"
SvProcessor::SvProcessor(QObject *parent):
QObject(parent)
{
}
SvProcessor::SvProcessor(int numberOfWorkers)
{
uint i;
m_kernel = new SvKernel();
m_numberOfWorkers = numberOfWorkers;
m_workers = new SvWorker[m_numberOfWorkers];
m_threads = new QThread[m_numberOfWorkers];
for (i = 0; i < m_numberOfWorkers; i++) {
m_workers[i].setId(i);
m_workers[i].setKernel(m_kernel);
m_workers[i].setProcessor(this);
m_workers[i].moveToThread(&m_threads[i]);
connect(&m_threads[i], &QThread::started, &m_workers[i], &SvWorker::start);
connect(&m_workers[i], &SvWorker::finished, this, &SvProcessor::workerFinished);
}
}
SvProcessor::~SvProcessor()
{
delete m_kernel;
delete[] m_workers;
}
void SvProcessor::enqueueImage(SvPointCloud *pointCloud, SvImage *image)
{
SvProcessorTask *task;
for (uint i = 0; i < image->getHeight(); i++) {
task = new SvProcessorTask;
task->image = image;
task->line = i;
task->pointCloud = pointCloud;
m_taskQueue.enqueue(task);
}
}
SvProcessorTask SvProcessor::nextTask()
{
SvProcessorTask task, *taskPtr;
m_nextTaskMutex.lock();
if (!m_taskQueue.size()) {
m_nextTaskMutex.unlock();
throw SvNoMoreTasks();
}
taskPtr = m_taskQueue.dequeue();
m_nextTaskMutex.unlock();
task = *taskPtr;
delete taskPtr;
return task;
}
void SvProcessor::workerFinished(int workerId)
{
qDebug() << "worker " << workerId << " finished";
m_workersFinished++;
if (m_workersFinished == m_numberOfWorkers) {
qDebug() << "finished";
emit finished(time(NULL) - m_startTime);
}
}
void SvProcessor::start()
{
uint i;
m_startTime = time(NULL);
m_workersFinished = 0;
for (i = 0; i < m_numberOfWorkers; i++) {
m_threads[i].start(QThread::HighPriority);
}
}
void SvProcessor::stop()
{
emit stopped(time(NULL) - m_startTime);
}

61
svprocessor.h Normal file
View File

@ -0,0 +1,61 @@
#ifndef SVPROCESSOR_H
#define SVPROCESSOR_H
#include <time.h>
#include <QObject>
#include <QThread>
#include <QDebug>
#include <QQueue>
#include <QMutex>
#include <QException>
#include "svimage.h"
#include "svworker.h"
#include "svkernel.h"
#include "svpointcloud.h"
class SvWorker;
class SvNoMoreTasks: public QException
{
};
class SvProcessor: public QObject
{
Q_OBJECT
protected:
QThread* m_threads;
SvWorker* m_workers;
SvKernel* m_kernel;
uint m_numberOfWorkers;
uint m_workersFinished;
uint m_startTime;
QQueue<SvProcessorTask*> m_taskQueue;
QMutex m_nextTaskMutex;
public:
explicit SvProcessor(QObject *parent = 0);
SvProcessor(int numberOfWorkers = 1);
~SvProcessor();
void execute();
void enqueueImage(SvPointCloud *pointCloud, SvImage *image);
SvProcessorTask nextTask();
protected slots:
void workerFinished(int workerId);
public slots:
void start();
void stop();
signals:
void started();
void finished(int elapsedTime);
void stopped(int elapsedTime);
};
#endif // SVPROCESSOR_H

5
svsimplepoint.cpp Normal file
View File

@ -0,0 +1,5 @@
#include "svsimplepoint.h"
SvSimplePoint::SvSimplePoint()
{
}

22
svsimplepoint.h Normal file
View File

@ -0,0 +1,22 @@
#ifndef SVSIMPLEPOINT_H
#define SVSIMPLEPOINT_H
class SvSimplePoint
{
protected:
int m_px, m_py, m_pz;
public:
int x() {return m_px;}
int y() {return m_py;}
int z() {return m_pz;}
void setX(int px) {m_px = px;}
void setY(int py) {m_py = py;}
void setZ(int pz) {m_pz = pz;}
SvSimplePoint();
};
#endif // SVSIMPLEPOINT_H

29
svworker.cpp Normal file
View File

@ -0,0 +1,29 @@
#include "svworker.h"
SvWorker::SvWorker(QObject *parent) :
QObject(parent)
{
}
void SvWorker::stop()
{
}
void SvWorker::start()
{
SvProcessorTask task;
while(true) {
try {
task = m_processor->nextTask();
} catch (SvNoMoreTasks ex) {
break;
}
m_kernel->exec(task.pointCloud, task.image, task.line);
}
emit finished(m_id);
}

36
svworker.h Normal file
View File

@ -0,0 +1,36 @@
#ifndef SVWORKER_H
#define SVWORKER_H
#include <QObject>
#include <QList>
#include "svkernel.h"
#include "svprocessor.h"
#include "svimage.h"
class SvProcessor;
class SvWorker : public QObject
{
Q_OBJECT
protected:
int m_id;
SvKernel *m_kernel;
SvProcessor *m_processor;
public:
explicit SvWorker(QObject *parent = 0);
void setId(int id) {m_id = id;}
void setKernel(SvKernel* kernel) {m_kernel = kernel;}
void setProcessor(SvProcessor* processor) {m_processor = processor;}
signals:
void finished(int id);
public slots:
void stop();
void start();
};
#endif // SVWORKER_H