Apollo
11.0
自动驾驶开放平台
image.h
浏览该文件的文档.
1
/******************************************************************************
2
* Copyright 2019 The Apollo Authors. All Rights Reserved.
3
*
4
* Licensed under the Apache License, Version 2.0 (the "License");
5
* you may not use this file except in compliance with the License.
6
* You may obtain a copy of the License at
7
*
8
* http://www.apache.org/licenses/LICENSE-2.0
9
*
10
* Unless required by applicable law or agreed to in writing, software
11
* distributed under the License is distributed on an "AS IS" BASIS,
12
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
* See the License for the specific language governing permissions and
14
* limitations under the License.
15
*****************************************************************************/
16
17
/*
18
Copyright (C) 2006 Pedro Felzenszwalb
19
This program is free software; you can redistribute it and/or modify
20
it under the terms of the GNU General Public License as published by
21
the Free Software Foundation; either version 2 of the License, or
22
(at your option) any later version.
23
This program is distributed in the hope that it will be useful,
24
but WITHOUT ANY WARRANTY; without even the implied warranty of
25
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
26
GNU General Public License for more details.
27
You should have received a copy of the GNU General Public License
28
along with this program; if not, write to the Free Software
29
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
30
*/
31
/* a simple image class */
32
#pragma once
33
#include <cstring>
34
35
namespace
apollo
{
36
namespace
perception {
37
namespace
lidar {
38
39
template
<
class
T>
40
class
Image
{
41
public
:
42
/* create an image */
43
Image
(
const
int
width
,
const
int
height
,
const
bool
init
=
true
);
44
/* delete an image */
45
~Image
();
46
51
void
init
(
const
T &val);
57
Image<T>
*
copy
()
const
;
58
64
int
width
()
const
{
65
return
_w;
66
}
67
73
int
height
()
const
{
74
return
_h;
75
}
76
77
/* image data. */
78
T *
_data
;
79
80
/* row pointers. */
81
T **
_access
;
82
83
private
:
84
int
_w;
85
int
_h;
86
};
87
/* use imRef to access image data. */
88
#define imRef(im, x, y) (im->_access[y][x])
89
/* use imPtr to get pointer to image data. */
90
#define imPtr(im, x, y) &(im->_access[y][x])
91
template
<
class
T>
92
Image<T>::Image
(
const
int
width,
const
int
height,
const
bool
init) {
93
_w = width;
94
_h = height;
95
_data =
new
T[_w * _h];
// allocate space for image data
96
_access =
new
T *[_h];
// allocate space for row pointers
97
98
// initialize row pointers
99
for
(
int
i = 0; i < _h; i++) {
100
_access[i] = _data + (i * _w);
101
}
102
103
if
(init) {
104
memset(_data, 0, _w * _h *
sizeof
(T));
105
}
106
}
107
template
<
class
T>
108
Image<T>::~Image
() {
109
delete
[] _data;
110
delete
[] _access;
111
}
112
template
<
class
T>
113
void
Image<T>::init
(
const
T &val) {
114
T *ptr =
imPtr
(
this
, 0, 0);
115
T *end =
imPtr
(
this
, _w - 1, _h - 1);
116
while
(ptr <= end) {
117
*ptr++ = val;
118
}
119
}
120
template
<
class
T>
121
Image<T>
*
Image<T>::copy
()
const
{
122
Image<T>
*im =
new
Image<T>
(_w, _h,
false
);
123
memcpy(im->
_data
, _data, _w * _h *
sizeof
(T));
124
return
im;
125
}
126
}
// namespace lidar
127
}
// namespace perception
128
}
// namespace apollo
apollo::perception::lidar::Image
Definition
image.h:40
apollo::perception::lidar::Image::Image
Image(const int width, const int height, const bool init=true)
Definition
image.h:92
apollo::perception::lidar::Image::_data
T * _data
Definition
image.h:78
apollo::perception::lidar::Image::height
int height() const
Get the height of an image
Definition
image.h:73
apollo::perception::lidar::Image::_access
T ** _access
Definition
image.h:81
apollo::perception::lidar::Image::init
void init(const T &val)
Init an image
Definition
image.h:113
apollo::perception::lidar::Image::width
int width() const
Get the width of an image
Definition
image.h:64
apollo::perception::lidar::Image::~Image
~Image()
Definition
image.h:108
apollo::perception::lidar::Image::copy
Image< T > * copy() const
Copy an image
Definition
image.h:121
imPtr
#define imPtr(im, x, y)
Definition
image.h:90
apollo
class register implement
Definition
arena_queue.h:37
modules
perception
lidar_segmentation
segmentor
ncut_segmentation
common
graph_felzenszwalb
image.h