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
44 changed files with 1464 additions and 529 deletions

View File

@ -1,14 +0,0 @@
kind: pipeline
name: default
steps:
- name: build
image: rust
commands:
- cargo build --verbose --all
- name: fmt-check
image: rust
commands:
- rustup component add rustfmt
- cargo fmt --all -- --check

4
.gitignore vendored
View File

@ -1,3 +1 @@
/target
.undodir
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

339
Cargo.lock generated
View File

@ -1,339 +0,0 @@
# This file is automatically @generated by Cargo.
# It is not intended for manual editing.
version = 3
[[package]]
name = "adler"
version = "1.0.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f26201604c87b1e01bd3d98f8d5d9a8fcbb815e8cedb41ffccbeb4bf593a35fe"
[[package]]
name = "adler32"
version = "1.2.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "aae1277d39aeec15cb388266ecc24b11c80469deae6067e17a1a7aa9e5c1f234"
[[package]]
name = "anyhow"
version = "1.0.51"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8b26702f315f53b6071259e15dd9d64528213b44d61de1ec926eca7715d62203"
[[package]]
name = "autocfg"
version = "1.0.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "cdb031dd78e28731d87d56cc8ffef4a8f36ca26c38fe2de700543e627f8a464a"
[[package]]
name = "bitflags"
version = "1.3.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a"
[[package]]
name = "bytemuck"
version = "1.7.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "72957246c41db82b8ef88a5486143830adeb8227ef9837740bdec67724cf2c5b"
[[package]]
name = "byteorder"
version = "1.4.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "14c189c53d098945499cdfa7ecc63567cf3886b3332b312a5b4585d8d3a6a610"
[[package]]
name = "cfg-if"
version = "1.0.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd"
[[package]]
name = "color_quant"
version = "1.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3d7b894f5411737b7867f4827955924d7c254fc9f4d91a6aad6b097804b1018b"
[[package]]
name = "crc32fast"
version = "1.2.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3825b1e8580894917dc4468cb634a1b4e9745fddc854edad72d9c04644c0319f"
dependencies = [
"cfg-if",
]
[[package]]
name = "crossbeam-channel"
version = "0.5.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "06ed27e177f16d65f0f0c22a213e17c696ace5dd64b14258b52f9417ccb52db4"
dependencies = [
"cfg-if",
"crossbeam-utils",
]
[[package]]
name = "crossbeam-deque"
version = "0.8.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6455c0ca19f0d2fbf751b908d5c55c1f5cbc65e03c4225427254b46890bdde1e"
dependencies = [
"cfg-if",
"crossbeam-epoch",
"crossbeam-utils",
]
[[package]]
name = "crossbeam-epoch"
version = "0.9.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4ec02e091aa634e2c3ada4a392989e7c3116673ef0ac5b72232439094d73b7fd"
dependencies = [
"cfg-if",
"crossbeam-utils",
"lazy_static",
"memoffset",
"scopeguard",
]
[[package]]
name = "crossbeam-utils"
version = "0.8.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d82cfc11ce7f2c3faef78d8a684447b40d503d9681acebed6cb728d45940c4db"
dependencies = [
"cfg-if",
"lazy_static",
]
[[package]]
name = "deflate"
version = "0.8.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "73770f8e1fe7d64df17ca66ad28994a0a623ea497fa69486e14984e715c5d174"
dependencies = [
"adler32",
"byteorder",
]
[[package]]
name = "dispmap"
version = "0.1.0"
dependencies = [
"anyhow",
"image",
"rayon",
]
[[package]]
name = "either"
version = "1.6.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e78d4f1cc4ae33bbfc157ed5d5a5ef3bc29227303d595861deb238fcec4e9457"
[[package]]
name = "gif"
version = "0.11.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c3a7187e78088aead22ceedeee99779455b23fc231fe13ec443f99bb71694e5b"
dependencies = [
"color_quant",
"weezl",
]
[[package]]
name = "hermit-abi"
version = "0.1.19"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "62b467343b94ba476dcb2500d242dadbb39557df889310ac77c5d99100aaac33"
dependencies = [
"libc",
]
[[package]]
name = "image"
version = "0.23.14"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "24ffcb7e7244a9bf19d35bf2883b9c080c4ced3c07a9895572178cdb8f13f6a1"
dependencies = [
"bytemuck",
"byteorder",
"color_quant",
"gif",
"jpeg-decoder",
"num-iter",
"num-rational",
"num-traits",
"png",
"scoped_threadpool",
"tiff",
]
[[package]]
name = "jpeg-decoder"
version = "0.1.22"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "229d53d58899083193af11e15917b5640cd40b29ff475a1fe4ef725deb02d0f2"
dependencies = [
"rayon",
]
[[package]]
name = "lazy_static"
version = "1.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646"
[[package]]
name = "libc"
version = "0.2.108"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8521a1b57e76b1ec69af7599e75e38e7b7fad6610f037db8c79b127201b5d119"
[[package]]
name = "memoffset"
version = "0.6.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "59accc507f1338036a0477ef61afdae33cde60840f4dfe481319ce3ad116ddf9"
dependencies = [
"autocfg",
]
[[package]]
name = "miniz_oxide"
version = "0.3.7"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "791daaae1ed6889560f8c4359194f56648355540573244a5448a83ba1ecc7435"
dependencies = [
"adler32",
]
[[package]]
name = "miniz_oxide"
version = "0.4.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a92518e98c078586bc6c934028adcca4c92a53d6a958196de835170a01d84e4b"
dependencies = [
"adler",
"autocfg",
]
[[package]]
name = "num-integer"
version = "0.1.44"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d2cc698a63b549a70bc047073d2949cce27cd1c7b0a4a862d08a8031bc2801db"
dependencies = [
"autocfg",
"num-traits",
]
[[package]]
name = "num-iter"
version = "0.1.42"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b2021c8337a54d21aca0d59a92577a029af9431cb59b909b03252b9c164fad59"
dependencies = [
"autocfg",
"num-integer",
"num-traits",
]
[[package]]
name = "num-rational"
version = "0.3.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "12ac428b1cb17fce6f731001d307d351ec70a6d202fc2e60f7d4c5e42d8f4f07"
dependencies = [
"autocfg",
"num-integer",
"num-traits",
]
[[package]]
name = "num-traits"
version = "0.2.14"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9a64b1ec5cda2586e284722486d802acf1f7dbdc623e2bfc57e65ca1cd099290"
dependencies = [
"autocfg",
]
[[package]]
name = "num_cpus"
version = "1.13.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "05499f3756671c15885fee9034446956fff3f243d6077b91e5767df161f766b3"
dependencies = [
"hermit-abi",
"libc",
]
[[package]]
name = "png"
version = "0.16.8"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3c3287920cb847dee3de33d301c463fba14dda99db24214ddf93f83d3021f4c6"
dependencies = [
"bitflags",
"crc32fast",
"deflate",
"miniz_oxide 0.3.7",
]
[[package]]
name = "rayon"
version = "1.5.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c06aca804d41dbc8ba42dfd964f0d01334eceb64314b9ecf7c5fad5188a06d90"
dependencies = [
"autocfg",
"crossbeam-deque",
"either",
"rayon-core",
]
[[package]]
name = "rayon-core"
version = "1.9.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d78120e2c850279833f1dd3582f730c4ab53ed95aeaaaa862a2a5c71b1656d8e"
dependencies = [
"crossbeam-channel",
"crossbeam-deque",
"crossbeam-utils",
"lazy_static",
"num_cpus",
]
[[package]]
name = "scoped_threadpool"
version = "0.1.9"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1d51f5df5af43ab3f1360b429fa5e0152ac5ce8c0bd6485cae490332e96846a8"
[[package]]
name = "scopeguard"
version = "1.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d29ab0c6d3fc0ee92fe66e2d99f700eab17a8d57d1c1d3b748380fb20baa78cd"
[[package]]
name = "tiff"
version = "0.6.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9a53f4706d65497df0c4349241deddf35f84cee19c87ed86ea8ca590f4464437"
dependencies = [
"jpeg-decoder",
"miniz_oxide 0.4.4",
"weezl",
]
[[package]]
name = "weezl"
version = "0.1.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d8b77fdfd5a253be4ab714e4ffa3c49caf146b4de743e97510c0656cf90f1e8e"

View File

@ -1,16 +0,0 @@
[package]
name = "dispmap"
version = "0.1.0"
edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[[bin]]
name = "run"
path = "./bin/run.rs"
[dependencies]
anyhow = "1.0.51"
image = "0.23.14"
rayon = "1.5.1"

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,3 +0,0 @@
# Simple Disparity Map Algorithm
![example](disp.png "Example")

View File

@ -1,20 +0,0 @@
use dispmap::compute;
fn main() -> anyhow::Result<()> {
let mut args = std::env::args();
let _ = args.next();
let left_path = args.next().unwrap();
let right_path = args.next().unwrap();
println!("disparity for {} {}", left_path, right_path);
let left = image::open(left_path)?.to_rgb8();
let right = image::open(right_path)?.to_rgb8();
let disp = compute(&left, &right);
disp.save("disp.png")?;
Ok(())
}

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
disp.png

Binary file not shown.

Before

Width:  |  Height:  |  Size: 56 KiB

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,134 +0,0 @@
use image::{buffer::PixelsMut, GenericImageView, GrayImage, Luma, Rgb, RgbImage};
fn diff(left: Rgb<u8>, right: Rgb<u8>) -> i32 {
let r = (left[0] as i32 - right[0] as i32).abs();
let g = (left[1] as i32 - right[1] as i32).abs();
let b = (left[2] as i32 - right[2] as i32).abs();
let color = (g - r).abs() + (b - g).abs();
(r + g + b) + color * 4
}
fn match_box(left: [Rgb<u8>; 16], right: [Rgb<u8>; 16]) -> i32 {
let mut sqr_sum = 0;
for (l, r) in left.into_iter().zip(right.into_iter()) {
sqr_sum += diff(l, r);
}
sqr_sum
}
fn px(img: &RgbImage, x: u32, y: u32) -> Rgb<u8> {
if x >= img.width() || y >= img.height() {
return Rgb([0, 0, 0]);
}
img.get_pixel(x, y).clone()
}
fn match_pixels(left: &RgbImage, right: &RgbImage, x: u32, y: u32, j: u32) -> i32 {
let lx = x;
let rx = x + j;
match_box(
[
px(left, lx, y),
px(left, lx + 1, y),
px(left, lx + 2, y),
px(left, lx + 3, y),
px(left, lx, y + 1),
px(left, lx + 1, y + 1),
px(left, lx + 2, y + 1),
px(left, lx + 3, y + 1),
px(left, lx, y + 2),
px(left, lx + 1, y + 2),
px(left, lx + 2, y + 2),
px(left, lx + 3, y + 2),
px(left, lx, y + 3),
px(left, lx + 1, y + 3),
px(left, lx + 2, y + 3),
px(left, lx + 3, y + 3),
],
[
px(right, rx, y),
px(right, rx + 1, y),
px(right, rx + 2, y),
px(right, rx + 3, y),
px(right, rx, y + 1),
px(right, rx + 1, y + 1),
px(right, rx + 2, y + 1),
px(right, rx + 3, y + 1),
px(right, rx, y + 2),
px(right, rx + 1, y + 2),
px(right, rx + 2, y + 2),
px(right, rx + 3, y + 2),
px(right, rx, y + 3),
px(right, rx + 1, y + 3),
px(right, rx + 2, y + 3),
px(right, rx + 3, y + 3),
],
)
}
fn get_pixel_color(image: &RgbImage, cursor: i32) -> f32 {
if cursor == 0 {
return 0.0;
}
(10 * image.width()) as f32 / (2.0 * 0.9 * cursor as f32)
}
fn get_pixel_hue(image: &RgbImage, x: u32, y: u32) -> i32 {
let pixel = image.get_pixel(x, y);
(pixel[1] as i32 - pixel[0] as i32).abs() + (pixel[2] as i32 - pixel[1] as i32).abs()
}
fn exec<'a>(res: PixelsMut<'a, Luma<u8>>, left: &RgbImage, right: &RgbImage, line: u32) {
let mut cursor = 0i32;
let window_size = 128u32;
for (x, res) in res.enumerate() {
let mut closest = -1i32;
let mut min_error = -1i32;
let mut matched = 0;
let _val = get_pixel_hue(left, x as _, line);
for i in 1..window_size {
let _dist = (cursor - i as i32).abs();
let tmp = match_pixels(left, right, x as _, line as _, i as _);
let tmp_smoothed = tmp; // + (dist) * (1.0 / diff);
if tmp_smoothed < min_error || min_error == -1 {
min_error = tmp_smoothed;
closest = i as i32;
matched = 1;
} else if tmp_smoothed == min_error
&& ((cursor - i as i32).abs() < (cursor - closest).abs())
{
closest = i as i32;
matched += 1;
}
}
if matched == 1 {
cursor = closest;
}
*res = Luma([get_pixel_color(left, cursor) as u8]);
}
}
pub fn compute(left: &RgbImage, right: &RgbImage) -> GrayImage {
let mut out = GrayImage::new(left.width(), right.height());
out.rows_mut()
.enumerate()
.for_each(|(y, row)| exec(row, left, right, y as _));
out
}

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