1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
use crate::{
error::{ErrorChecker, Result as RsResult},
kind::Extension,
};
use std::{marker::PhantomData, ptr::NonNull};
pub mod marker {
use super::*;
pub trait ProcessingBlockKind {}
pub trait NonAnyProcessingBlockKind
where
Self: ProcessingBlockKind,
{
const TYPE: Extension;
}
#[derive(Debug)]
pub struct Any;
impl ProcessingBlockKind for Any {}
#[derive(Debug)]
pub struct Decimation;
impl ProcessingBlockKind for Decimation {}
impl NonAnyProcessingBlockKind for Decimation {
const TYPE: Extension = Extension::DecimationFilter;
}
#[derive(Debug)]
pub struct Threshold;
impl ProcessingBlockKind for Threshold {}
impl NonAnyProcessingBlockKind for Threshold {
const TYPE: Extension = Extension::ThresholdFilter;
}
#[derive(Debug)]
pub struct Disparity;
impl ProcessingBlockKind for Disparity {}
impl NonAnyProcessingBlockKind for Disparity {
const TYPE: Extension = Extension::DisparityFilter;
}
#[derive(Debug)]
pub struct Spatial;
impl ProcessingBlockKind for Spatial {}
impl NonAnyProcessingBlockKind for Spatial {
const TYPE: Extension = Extension::SpatialFilter;
}
#[derive(Debug)]
pub struct Temporal;
impl ProcessingBlockKind for Temporal {}
impl NonAnyProcessingBlockKind for Temporal {
const TYPE: Extension = Extension::TemporalFilter;
}
#[derive(Debug)]
pub struct HoleFilling;
impl ProcessingBlockKind for HoleFilling {}
impl NonAnyProcessingBlockKind for HoleFilling {
const TYPE: Extension = Extension::HoleFillingFilter;
}
#[derive(Debug)]
pub struct ZeroOrder;
impl ProcessingBlockKind for ZeroOrder {}
impl NonAnyProcessingBlockKind for ZeroOrder {
const TYPE: Extension = Extension::ZeroOrderFilter;
}
}
#[derive(Debug)]
pub struct ProcessingBlock<Kind>
where
Kind: marker::ProcessingBlockKind,
{
ptr: NonNull<realsense_sys::rs2_processing_block>,
_phantom: PhantomData<Kind>,
}
impl<Kind> ProcessingBlock<Kind>
where
Kind: marker::ProcessingBlockKind,
{
pub(crate) unsafe fn from_ptr(ptr: NonNull<realsense_sys::rs2_processing_block>) -> Self {
Self {
ptr,
_phantom: PhantomData,
}
}
}
impl ProcessingBlock<marker::Spatial> {
pub fn create() -> RsResult<Self> {
let processing_block = unsafe {
let mut checker = ErrorChecker::new();
let ptr = realsense_sys::rs2_create_spatial_filter_block(checker.inner_mut_ptr());
checker.check()?;
Self::from_ptr(NonNull::new(ptr).unwrap())
};
Ok(processing_block)
}
}
impl ProcessingBlock<marker::Temporal> {
pub fn create() -> RsResult<Self> {
let processing_block = unsafe {
let mut checker = ErrorChecker::new();
let ptr = realsense_sys::rs2_create_temporal_filter_block(checker.inner_mut_ptr());
checker.check()?;
Self::from_ptr(NonNull::new(ptr).unwrap())
};
Ok(processing_block)
}
}
impl ProcessingBlock<marker::Decimation> {
pub fn create() -> RsResult<Self> {
let processing_block = unsafe {
let mut checker = ErrorChecker::new();
let ptr = realsense_sys::rs2_create_decimation_filter_block(checker.inner_mut_ptr());
checker.check()?;
Self::from_ptr(NonNull::new(ptr).unwrap())
};
Ok(processing_block)
}
}
impl ProcessingBlock<marker::HoleFilling> {
pub fn create() -> RsResult<Self> {
let processing_block = unsafe {
let mut checker = ErrorChecker::new();
let ptr = realsense_sys::rs2_create_hole_filling_filter_block(checker.inner_mut_ptr());
checker.check()?;
Self::from_ptr(NonNull::new(ptr).unwrap())
};
Ok(processing_block)
}
}
impl<Kind> Drop for ProcessingBlock<Kind>
where
Kind: marker::ProcessingBlockKind,
{
fn drop(&mut self) {
unsafe {
realsense_sys::rs2_delete_processing_block(self.ptr.as_ptr());
}
}
}