Blender V4.3
libmv/libmv/image/image.h
Go to the documentation of this file.
1// Copyright (c) 2007, 2008 libmv authors.
2//
3// Permission is hereby granted, free of charge, to any person obtaining a copy
4// of this software and associated documentation files (the "Software"), to
5// deal in the Software without restriction, including without limitation the
6// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
7// sell copies of the Software, and to permit persons to whom the Software is
8// furnished to do so, subject to the following conditions:
9//
10// The above copyright notice and this permission notice shall be included in
11// all copies or substantial portions of the Software.
12//
13// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
18// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
19// IN THE SOFTWARE.
20
21#ifndef LIBMV_IMAGE_IMAGE_H
22#define LIBMV_IMAGE_IMAGE_H
23
24#include <cmath>
25
27
28namespace libmv {
29
30typedef Array3Du ByteImage; // For backwards compatibility.
32
33// Type added only to manage special 2D array for feature detection
36
37// An image class that is a thin wrapper around Array3D's of various types.
38// TODO(keir): Decide if we should add reference counting semantics... Maybe it
39// is the best solution after all.
40class Image {
41 public:
42 // Create an image from an array. The image takes ownership of the array.
43 Image(Array3Du* array) : array_type_(BYTE), array_(array) {}
44 Image(Array3Df* array) : array_type_(FLOAT), array_(array) {}
45
46 Image(const Image& img) : array_type_(NONE), array_(NULL) { *this = img; }
47
48 // Underlying data type.
56
57 // Size in bytes that the image takes in memory.
59 int size;
60 switch (array_type_) {
61 case BYTE:
62 size = reinterpret_cast<Array3Du*>(array_)->MemorySizeInBytes();
63 break;
64 case FLOAT:
65 size = reinterpret_cast<Array3Df*>(array_)->MemorySizeInBytes();
66 break;
67 case INT:
68 size = reinterpret_cast<Array3Di*>(array_)->MemorySizeInBytes();
69 break;
70 case SHORT:
71 size = reinterpret_cast<Array3Ds*>(array_)->MemorySizeInBytes();
72 break;
73 default: size = 0; assert(0);
74 }
75 size += sizeof(*this);
76 return size;
77 }
78
80 switch (array_type_) {
81 case BYTE: delete reinterpret_cast<Array3Du*>(array_); break;
82 case FLOAT: delete reinterpret_cast<Array3Df*>(array_); break;
83 case INT: delete reinterpret_cast<Array3Di*>(array_); break;
84 case SHORT: delete reinterpret_cast<Array3Ds*>(array_); break;
85 default: assert(0);
86 }
87 }
88
89 Image& operator=(const Image& f) {
90 if (this != &f) {
91 array_type_ = f.array_type_;
92 switch (array_type_) {
93 case BYTE:
94 delete reinterpret_cast<Array3Du*>(array_);
95 array_ = new Array3Du(*(Array3Du*)f.array_);
96 break;
97 case FLOAT:
98 delete reinterpret_cast<Array3Df*>(array_);
99 array_ = new Array3Df(*(Array3Df*)f.array_);
100 break;
101 case INT:
102 delete reinterpret_cast<Array3Di*>(array_);
103 array_ = new Array3Di(*(Array3Di*)f.array_);
104 break;
105 case SHORT:
106 delete reinterpret_cast<Array3Ds*>(array_);
107 array_ = new Array3Ds(*(Array3Ds*)f.array_);
108 break;
109 default: assert(0);
110 }
111 }
112 return *this;
113 }
114
116 if (array_type_ == BYTE) {
117 return reinterpret_cast<Array3Du*>(array_);
118 }
119 return NULL;
120 }
121
123 if (array_type_ == FLOAT) {
124 return reinterpret_cast<Array3Df*>(array_);
125 }
126 return NULL;
127 }
128
129 private:
130 DataType array_type_;
131 BaseArray* array_;
132};
133
134} // namespace libmv
135
136#endif // LIBMV_IMAGE_IMAGE_IMAGE_H
static DBVT_INLINE btScalar size(const btDbvtVolume &a)
Definition btDbvt.cpp:52
3D array (row, column, channel).
Definition array_nd.h:332
Image(Array3Du *array)
Image(const Image &img)
Array3Df * AsArray3Df() const
Array3Du * AsArray3Du() const
Image(Array3Df *array)
Image & operator=(const Image &f)
#define NULL
Array3D< unsigned char > Array3Du
Definition array_nd.h:370
Array3D< int > Array3Di
Definition array_nd.h:372
Array3Df FloatImage
Array3D< float > Array3Df
Definition array_nd.h:373
Array3D< short > Array3Ds
Definition array_nd.h:374
Array3Ds ShortImage