Blender  V3.3
array_nd.cc
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 #include <cmath>
22 #include <iostream>
23 #include "libmv/image/image.h"
24 
25 namespace libmv {
26 
27 void FloatArrayToScaledByteArray(const Array3Df& float_array,
28  Array3Du* byte_array,
29  bool automatic_range_detection) {
30  byte_array->ResizeLike(float_array);
31  float minval = HUGE_VAL;
32  float maxval = -HUGE_VAL;
33  if (automatic_range_detection) {
34  for (int i = 0; i < float_array.Height(); ++i) {
35  for (int j = 0; j < float_array.Width(); ++j) {
36  for (int k = 0; k < float_array.Depth(); ++k) {
37  minval = std::min(minval, float_array(i, j, k));
38  maxval = std::max(maxval, float_array(i, j, k));
39  }
40  }
41  }
42  } else {
43  minval = 0;
44  maxval = 1;
45  }
46  for (int i = 0; i < float_array.Height(); ++i) {
47  for (int j = 0; j < float_array.Width(); ++j) {
48  for (int k = 0; k < float_array.Depth(); ++k) {
49  float unscaled = (float_array(i, j, k) - minval) / (maxval - minval);
50  (*byte_array)(i, j, k) = (unsigned char)(255 * unscaled);
51  }
52  }
53  }
54 }
55 
56 void ByteArrayToScaledFloatArray(const Array3Du& byte_array,
57  Array3Df* float_array) {
58  float_array->ResizeLike(byte_array);
59  for (int i = 0; i < byte_array.Height(); ++i) {
60  for (int j = 0; j < byte_array.Width(); ++j) {
61  for (int k = 0; k < byte_array.Depth(); ++k) {
62  (*float_array)(i, j, k) = float(byte_array(i, j, k)) / 255.0f;
63  }
64  }
65  }
66 }
67 
69  Array3Df* channel0,
70  Array3Df* channel1,
71  Array3Df* channel2) {
72  assert(input.Depth() >= 3);
73  channel0->Resize(input.Height(), input.Width());
74  channel1->Resize(input.Height(), input.Width());
75  channel2->Resize(input.Height(), input.Width());
76  for (int row = 0; row < input.Height(); ++row) {
77  for (int column = 0; column < input.Width(); ++column) {
78  (*channel0)(row, column) = input(row, column, 0);
79  (*channel1)(row, column) = input(row, column, 1);
80  (*channel2)(row, column) = input(row, column, 2);
81  }
82  }
83 }
84 
85 void PrintArray(const Array3Df& array) {
86  using namespace std;
87 
88  printf("[\n");
89  for (int r = 0; r < array.Height(); ++r) {
90  printf("[");
91  for (int c = 0; c < array.Width(); ++c) {
92  if (array.Depth() == 1) {
93  printf("%11f, ", array(r, c));
94  } else {
95  printf("[");
96  for (int k = 0; k < array.Depth(); ++k) {
97  printf("%11f, ", array(r, c, k));
98  }
99  printf("],");
100  }
101  }
102  printf("],\n");
103  }
104  printf("]\n");
105 }
106 
107 } // namespace libmv
_GL_VOID GLfloat value _GL_VOID_RET _GL_VOID const GLuint GLboolean *residences _GL_BOOL_RET _GL_VOID GLsizei GLfloat GLfloat GLfloat GLfloat const GLubyte *bitmap _GL_VOID_RET _GL_VOID GLenum const void *lists _GL_VOID_RET _GL_VOID const GLdouble *equation _GL_VOID_RET _GL_VOID GLdouble GLdouble blue _GL_VOID_RET _GL_VOID GLfloat GLfloat blue _GL_VOID_RET _GL_VOID GLint GLint blue _GL_VOID_RET _GL_VOID GLshort GLshort blue _GL_VOID_RET _GL_VOID GLubyte GLubyte blue _GL_VOID_RET _GL_VOID GLuint GLuint blue _GL_VOID_RET _GL_VOID GLushort GLushort blue _GL_VOID_RET _GL_VOID GLbyte GLbyte GLbyte alpha _GL_VOID_RET _GL_VOID GLdouble GLdouble GLdouble alpha _GL_VOID_RET _GL_VOID GLfloat GLfloat GLfloat alpha _GL_VOID_RET _GL_VOID GLint GLint GLint alpha _GL_VOID_RET _GL_VOID GLshort GLshort GLshort alpha _GL_VOID_RET _GL_VOID GLubyte GLubyte GLubyte alpha _GL_VOID_RET _GL_VOID GLuint GLuint GLuint alpha _GL_VOID_RET _GL_VOID GLushort GLushort GLushort alpha _GL_VOID_RET _GL_VOID GLenum mode _GL_VOID_RET _GL_VOID GLint GLsizei GLsizei GLenum type _GL_VOID_RET _GL_VOID GLsizei GLenum GLenum const void *pixels _GL_VOID_RET _GL_VOID const void *pointer _GL_VOID_RET _GL_VOID GLdouble v _GL_VOID_RET _GL_VOID GLfloat v _GL_VOID_RET _GL_VOID GLint GLint i2 _GL_VOID_RET _GL_VOID GLint j _GL_VOID_RET _GL_VOID GLfloat param _GL_VOID_RET _GL_VOID GLint param _GL_VOID_RET _GL_VOID GLdouble GLdouble GLdouble GLdouble GLdouble zFar _GL_VOID_RET _GL_UINT GLdouble *equation _GL_VOID_RET _GL_VOID GLenum GLint *params _GL_VOID_RET _GL_VOID GLenum GLfloat *v _GL_VOID_RET _GL_VOID GLenum GLfloat *params _GL_VOID_RET _GL_VOID GLfloat *values _GL_VOID_RET _GL_VOID GLushort *values _GL_VOID_RET _GL_VOID GLenum GLfloat *params _GL_VOID_RET _GL_VOID GLenum GLdouble *params _GL_VOID_RET _GL_VOID GLenum GLint *params _GL_VOID_RET _GL_VOID GLsizei const void *pointer _GL_VOID_RET _GL_VOID GLsizei const void *pointer _GL_VOID_RET _GL_BOOL GLfloat param _GL_VOID_RET _GL_VOID GLint param _GL_VOID_RET _GL_VOID GLenum GLfloat param _GL_VOID_RET _GL_VOID GLenum GLint param _GL_VOID_RET _GL_VOID GLushort pattern _GL_VOID_RET _GL_VOID GLdouble GLdouble GLint GLint const GLdouble *points _GL_VOID_RET _GL_VOID GLdouble GLdouble GLint GLint GLdouble GLdouble GLint GLint const GLdouble *points _GL_VOID_RET _GL_VOID GLdouble GLdouble u2 _GL_VOID_RET _GL_VOID GLdouble GLdouble GLint GLdouble GLdouble v2 _GL_VOID_RET _GL_VOID GLenum GLfloat param _GL_VOID_RET _GL_VOID GLenum GLint param _GL_VOID_RET _GL_VOID GLenum mode _GL_VOID_RET _GL_VOID GLdouble GLdouble nz _GL_VOID_RET _GL_VOID GLfloat GLfloat nz _GL_VOID_RET _GL_VOID GLint GLint nz _GL_VOID_RET _GL_VOID GLshort GLshort nz _GL_VOID_RET _GL_VOID GLsizei const void *pointer _GL_VOID_RET _GL_VOID GLsizei const GLfloat *values _GL_VOID_RET _GL_VOID GLsizei const GLushort *values _GL_VOID_RET _GL_VOID GLint param _GL_VOID_RET _GL_VOID const GLuint const GLclampf *priorities _GL_VOID_RET _GL_VOID GLdouble y _GL_VOID_RET _GL_VOID GLfloat y _GL_VOID_RET _GL_VOID GLint y _GL_VOID_RET _GL_VOID GLshort y _GL_VOID_RET _GL_VOID GLdouble GLdouble z _GL_VOID_RET _GL_VOID GLfloat GLfloat z _GL_VOID_RET _GL_VOID GLint GLint z _GL_VOID_RET _GL_VOID GLshort GLshort z _GL_VOID_RET _GL_VOID GLdouble GLdouble GLdouble w _GL_VOID_RET _GL_VOID GLfloat GLfloat GLfloat w _GL_VOID_RET _GL_VOID GLint GLint GLint w _GL_VOID_RET _GL_VOID GLshort GLshort GLshort w _GL_VOID_RET _GL_VOID GLdouble GLdouble GLdouble y2 _GL_VOID_RET _GL_VOID GLfloat GLfloat GLfloat y2 _GL_VOID_RET _GL_VOID GLint GLint GLint y2 _GL_VOID_RET _GL_VOID GLshort GLshort GLshort y2 _GL_VOID_RET _GL_VOID GLdouble GLdouble GLdouble z _GL_VOID_RET _GL_VOID GLdouble GLdouble z _GL_VOID_RET _GL_VOID GLuint *buffer _GL_VOID_RET _GL_VOID GLdouble t _GL_VOID_RET _GL_VOID GLfloat t _GL_VOID_RET _GL_VOID GLint t _GL_VOID_RET _GL_VOID GLshort t _GL_VOID_RET _GL_VOID GLdouble GLdouble r _GL_VOID_RET _GL_VOID GLfloat GLfloat r _GL_VOID_RET _GL_VOID GLint GLint r _GL_VOID_RET _GL_VOID GLshort GLshort r _GL_VOID_RET _GL_VOID GLdouble GLdouble r
3D array (row, column, channel).
Definition: array_nd.h:325
void Resize(int height, int width, int depth=1)
Definition: array_nd.h:334
int Depth() const
Definition: array_nd.h:340
int Height() const
Definition: array_nd.h:338
int Width() const
Definition: array_nd.h:339
void ResizeLike(const ArrayND< D, N > &other)
Definition: array_nd.h:109
ccl_global KernelShaderEvalInput * input
static unsigned c
Definition: RandGen.cpp:83
void SplitChannels(const Array3Df &input, Array3Df *channel0, Array3Df *channel1, Array3Df *channel2)
Definition: array_nd.cc:68
void ByteArrayToScaledFloatArray(const Array3Du &byte_array, Array3Df *float_array)
Convert a byte array into a float array by dividing values by 255.
Definition: array_nd.cc:56
void PrintArray(const Array3Df &array)
Definition: array_nd.cc:85
void FloatArrayToScaledByteArray(const Array3Df &float_array, Array3Du *byte_array, bool automatic_range_detection)
Definition: array_nd.cc:27
#define min(a, b)
Definition: sort.c:35
float max