Blender  V2.93
bvh_unaligned.cpp
Go to the documentation of this file.
1 /*
2  * Copyright 2011-2016 Blender Foundation
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 #include "bvh/bvh_unaligned.h"
18 
19 #include "render/hair.h"
20 #include "render/object.h"
21 
22 #include "bvh/bvh_binning.h"
23 #include "bvh_params.h"
24 
25 #include "util/util_boundbox.h"
26 #include "util/util_transform.h"
27 
29 
30 BVHUnaligned::BVHUnaligned(const vector<Object *> &objects) : objects_(objects)
31 {
32 }
33 
35  const BVHReference *references) const
36 {
37  for (int i = range.start(); i < range.end(); ++i) {
38  const BVHReference &ref = references[i];
39  Transform aligned_space;
40  /* Use first primitive which defines correct direction to define
41  * the orientation space.
42  */
43  if (compute_aligned_space(ref, &aligned_space)) {
44  return aligned_space;
45  }
46  }
47  return transform_identity();
48 }
49 
51  const BVHReference *references) const
52 {
53  for (int i = range.start(); i < range.end(); ++i) {
54  const BVHReference &ref = references[i];
55  Transform aligned_space;
56  /* Use first primitive which defines correct direction to define
57  * the orientation space.
58  */
59  if (compute_aligned_space(ref, &aligned_space)) {
60  return aligned_space;
61  }
62  }
63  return transform_identity();
64 }
65 
66 bool BVHUnaligned::compute_aligned_space(const BVHReference &ref, Transform *aligned_space) const
67 {
68  const Object *object = objects_[ref.prim_object()];
69  const int packed_type = ref.prim_type();
70  const int type = (packed_type & PRIMITIVE_ALL);
71  /* No motion blur curves here, we can't fit them to aligned boxes well. */
73  const int curve_index = ref.prim_index();
74  const int segment = PRIMITIVE_UNPACK_SEGMENT(packed_type);
75  const Hair *hair = static_cast<const Hair *>(object->get_geometry());
76  const Hair::Curve &curve = hair->get_curve(curve_index);
77  const int key = curve.first_key + segment;
78  const float3 v1 = hair->get_curve_keys()[key], v2 = hair->get_curve_keys()[key + 1];
79  float length;
80  const float3 axis = normalize_len(v2 - v1, &length);
81  if (length > 1e-6f) {
82  *aligned_space = make_transform_frame(axis);
83  return true;
84  }
85  }
86  *aligned_space = transform_identity();
87  return false;
88 }
89 
91  const Transform &aligned_space) const
92 {
94  const Object *object = objects_[prim.prim_object()];
95  const int packed_type = prim.prim_type();
96  const int type = (packed_type & PRIMITIVE_ALL);
97  /* No motion blur curves here, we can't fit them to aligned boxes well. */
99  const int curve_index = prim.prim_index();
100  const int segment = PRIMITIVE_UNPACK_SEGMENT(packed_type);
101  const Hair *hair = static_cast<const Hair *>(object->get_geometry());
102  const Hair::Curve &curve = hair->get_curve(curve_index);
103  curve.bounds_grow(
104  segment, &hair->get_curve_keys()[0], &hair->get_curve_radius()[0], aligned_space, bounds);
105  }
106  else {
107  bounds = prim.bounds().transformed(&aligned_space);
108  }
109  return bounds;
110 }
111 
113  const BVHReference *references,
114  const Transform &aligned_space,
115  BoundBox *cent_bounds) const
116 {
118  if (cent_bounds != NULL) {
119  *cent_bounds = BoundBox::empty;
120  }
121  for (int i = range.start(); i < range.end(); ++i) {
122  const BVHReference &ref = references[i];
123  BoundBox ref_bounds = compute_aligned_prim_boundbox(ref, aligned_space);
124  bounds.grow(ref_bounds);
125  if (cent_bounds != NULL) {
126  cent_bounds->grow(ref_bounds.center2());
127  }
128  }
129  return bounds;
130 }
131 
133  const BVHReference *references,
134  const Transform &aligned_space,
135  BoundBox *cent_bounds) const
136 {
138  if (cent_bounds != NULL) {
139  *cent_bounds = BoundBox::empty;
140  }
141  for (int i = range.start(); i < range.end(); ++i) {
142  const BVHReference &ref = references[i];
143  BoundBox ref_bounds = compute_aligned_prim_boundbox(ref, aligned_space);
144  bounds.grow(ref_bounds);
145  if (cent_bounds != NULL) {
146  cent_bounds->grow(ref_bounds.center2());
147  }
148  }
149  return bounds;
150 }
151 
153  const Transform &aligned_space)
154 {
155  Transform space = aligned_space;
156  space.x.w -= bounds.min.x;
157  space.y.w -= bounds.min.y;
158  space.z.w -= bounds.min.z;
159  float3 dim = bounds.max - bounds.min;
160  return transform_scale(
161  1.0f / max(1e-18f, dim.x), 1.0f / max(1e-18f, dim.y), 1.0f / max(1e-18f, dim.z)) *
162  space;
163 }
164 
_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 type
_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 v1
ATTR_WARN_UNUSED_RESULT const BMVert * v2
static btDbvtVolume bounds(btDbvtNode **leaves, int count)
Definition: btDbvt.cpp:299
SIMD_FORCE_INLINE btScalar length(const btQuaternion &q)
Return the length of a quaternion.
Definition: btQuaternion.h:895
__forceinline int start() const
Definition: bvh_params.h:262
__forceinline int end() const
Definition: bvh_params.h:270
__forceinline int prim_type() const
Definition: bvh_params.h:192
__forceinline int prim_object() const
Definition: bvh_params.h:188
__forceinline const BoundBox & bounds() const
Definition: bvh_params.h:180
__forceinline int prim_index() const
Definition: bvh_params.h:184
BVHUnaligned(const vector< Object * > &objects)
Transform compute_aligned_space(const BVHObjectBinning &range, const BVHReference *references) const
BoundBox compute_aligned_boundbox(const BVHObjectBinning &range, const BVHReference *references, const Transform &aligned_space, BoundBox *cent_bounds=NULL) const
const vector< Object * > & objects_
Definition: bvh_unaligned.h:68
BoundBox compute_aligned_prim_boundbox(const BVHReference &prim, const Transform &aligned_space) const
static Transform compute_node_transform(const BoundBox &bounds, const Transform &aligned_space)
Curve curve
#define CCL_NAMESPACE_END
@ PRIMITIVE_ALL
Definition: kernel_types.h:702
@ PRIMITIVE_CURVE_RIBBON
Definition: kernel_types.h:690
@ PRIMITIVE_CURVE_THICK
Definition: kernel_types.h:688
#define PRIMITIVE_UNPACK_SEGMENT(type)
Definition: kernel_types.h:711
Segment< FEdge *, Vec3r > segment
BoundBox transformed(const Transform *tfm) const
__forceinline void grow(const float3 &pt)
Definition: util_boundbox.h:55
__forceinline float3 center2() const
Curve get_curve(size_t i) const
Definition: hair.h:119
float z
Definition: sky_float3.h:35
float y
Definition: sky_float3.h:35
float x
Definition: sky_float3.h:35
float max
ccl_device_inline float2 normalize_len(const float2 &a, float *t)
ccl_device_inline Transform make_transform_frame(float3 N)
ccl_device_inline Transform transform_identity()
ccl_device_inline Transform transform_scale(float3 s)