Apollo
6.0
Open source self driving car software
modules
perception
lidar
lib
detector
ncut_segmentation
common
graph_felzenszwalb
image.h
Go to the documentation of this file.
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
/* init an image */
47
void
init
(
const
T &val);
48
/* copy an image */
49
Image<T>
*
copy
()
const
;
50
51
/* get the width of an image. */
52
int
width
()
const
{
return
_w; }
53
54
/* get the height of an image. */
55
int
height
()
const
{
return
_h; }
56
57
/* image data. */
58
T *
_data
;
59
60
/* row pointers. */
61
T **
_access
;
62
63
private
:
64
int
_w;
65
int
_h;
66
};
67
/* use imRef to access image data. */
68
#define imRef(im, x, y) (im->_access[y][x])
69
/* use imPtr to get pointer to image data. */
70
#define imPtr(im, x, y) &(im->_access[y][x])
71
template
<
class
T>
72
Image<T>::Image
(
const
int
width
,
const
int
height
,
const
bool
init
) {
73
_w =
width
;
74
_h =
height
;
75
_data
=
new
T[_w * _h];
// allocate space for image data
76
_access
=
new
T *[_h];
// allocate space for row pointers
77
78
// initialize row pointers
79
for
(
int
i = 0; i < _h; i++) {
80
_access
[i] =
_data
+ (i * _w);
81
}
82
83
if
(init) {
84
memset(
_data
, 0, _w * _h *
sizeof
(T));
85
}
86
}
87
template
<
class
T>
88
Image<T>::~Image
() {
89
delete
[]
_data
;
90
delete
[]
_access
;
91
}
92
template
<
class
T>
93
void
Image<T>::init
(
const
T &val) {
94
T *ptr =
imPtr
(
this
, 0, 0);
95
T *end =
imPtr
(
this
, _w - 1, _h - 1);
96
while
(ptr <= end) {
97
*ptr++ = val;
98
}
99
}
100
template
<
class
T>
101
Image<T>
*
Image<T>::copy
()
const
{
102
Image<T>
*im =
new
Image<T>
(_w, _h,
false
);
103
memcpy(im->
_data
,
_data
, _w * _h *
sizeof
(T));
104
return
im;
105
}
106
}
// namespace lidar
107
}
// namespace perception
108
}
// namespace apollo
apollo::perception::lidar::Image::height
int height() const
Definition:
image.h:55
apollo
PlanningContext is the runtime context in planning. It is persistent across multiple frames...
Definition:
atomic_hash_map.h:25
apollo::perception::lidar::Image::width
int width() const
Definition:
image.h:52
apollo::perception::lidar::Image
Definition:
image.h:40
imPtr
#define imPtr(im, x, y)
Definition:
image.h:70
apollo::perception::lidar::Image::_data
T * _data
Definition:
image.h:58
apollo::perception::lidar::Image::_access
T ** _access
Definition:
image.h:61
apollo::perception::lidar::Image::Image
Image(const int width, const int height, const bool init=true)
Definition:
image.h:72
apollo::perception::lidar::Image::init
void init(const T &val)
Definition:
image.h:93
apollo::perception::lidar::Image::copy
Image< T > * copy() const
Definition:
image.h:101
apollo::perception::lidar::Image::~Image
~Image()
Definition:
image.h:88
Generated by
1.8.13