1
2 //
3 // This source file is part of appleseed.
4 // Visit https://appleseedhq.net/ for additional information and resources.
5 //
6 // This software is released under the MIT license.
7 //
8 // Copyright (c) 2010-2013 Francois Beaune, Jupiter Jazz Limited
9 // Copyright (c) 2014-2018 Francois Beaune, The appleseedhq Organization
10 //
11 // Permission is hereby granted, free of charge, to any person obtaining a copy
12 // of this software and associated documentation files (the "Software"), to deal
13 // in the Software without restriction, including without limitation the rights
14 // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
15 // copies of the Software, and to permit persons to whom the Software is
16 // furnished to do so, subject to the following conditions:
17 //
18 // The above copyright notice and this permission notice shall be included in
19 // all copies or substantial portions of the Software.
20 //
21 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
22 // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
23 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
24 // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
25 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
26 // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
27 // THE SOFTWARE.
28 //
29
30 // appleseed.renderer headers.
31 #include "renderer/global/globaltypes.h"
32 #include "renderer/kernel/intersection/intersector.h"
33 #include "renderer/kernel/intersection/tracecontext.h"
34 #include "renderer/kernel/shading/shadingpoint.h"
35 #include "renderer/kernel/shading/shadingray.h"
36 #include "renderer/kernel/texturing/texturecache.h"
37 #include "renderer/kernel/texturing/texturestore.h"
38 #include "renderer/modeling/object/object.h"
39 #include "renderer/modeling/scene/assembly.h"
40 #include "renderer/modeling/scene/assemblyinstance.h"
41 #include "renderer/modeling/scene/containers.h"
42 #include "renderer/modeling/scene/objectinstance.h"
43 #include "renderer/modeling/scene/scene.h"
44 #include "renderer/modeling/scene/visibilityflags.h"
45 #include "renderer/utility/paramarray.h"
46 #include "renderer/utility/testutils.h"
47
48 // appleseed.foundation headers.
49 #include "foundation/math/matrix.h"
50 #include "foundation/math/transform.h"
51 #include "foundation/math/vector.h"
52 #include "foundation/utility/autoreleaseptr.h"
53 #include "foundation/utility/containers/dictionary.h"
54 #include "foundation/utility/test.h"
55
56 using namespace foundation;
57 using namespace renderer;
58
TEST_SUITE(Renderer_Kernel_Intersection_Intersector)59 TEST_SUITE(Renderer_Kernel_Intersection_Intersector)
60 {
61 struct TestScene
62 : public TestSceneBase
63 {
64 TestScene()
65 {
66 auto_release_ptr<Assembly> assembly(
67 AssemblyFactory().create("assembly", ParamArray()));
68
69 assembly->objects().insert(
70 auto_release_ptr<Object>(
71 new BoundingBoxObject(
72 "object",
73 GAABB3(GVector3(-1.0), GVector3(1.0)))));
74
75 assembly->object_instances().insert(
76 ObjectInstanceFactory::create(
77 "object_instance",
78 ParamArray(),
79 "object",
80 Transformd::identity(),
81 StringDictionary()));
82
83 m_scene.assembly_instances().insert(
84 auto_release_ptr<AssemblyInstance>(
85 AssemblyInstanceFactory::create(
86 "assembly_instance",
87 ParamArray(),
88 "assembly")));
89
90 m_scene.assemblies().insert(assembly);
91 }
92 };
93
94 template <bool UseEmbree>
95 struct Fixture
96 : public StaticTestSceneContext<TestScene>
97 {
98 TraceContext m_trace_context;
99 TextureStore m_texture_store;
100 TextureCache m_texture_cache;
101 Intersector m_intersector;
102
103 Fixture()
104 : m_trace_context(m_scene)
105 , m_texture_store(m_scene)
106 , m_texture_cache(m_texture_store)
107 , m_intersector(m_trace_context, m_texture_cache)
108 {
109 #ifdef APPLESEED_WITH_EMBREE
110 m_trace_context.set_use_embree(UseEmbree);
111 #endif
112 m_trace_context.update();
113 }
114 };
115
116 TEST_CASE_F(Trace_GivenAssemblyContainingEmptyBoundingBoxAndRayWithTMaxInsideAssembly_ReturnsFalse, Fixture<false>)
117 {
118 const ShadingRay ray(
119 Vector3d(0.0, 0.0, 2.0),
120 Vector3d(0.0, 0.0, -1.0),
121 0.0, // tmin
122 2.0, // tmax
123 ShadingRay::Time(),
124 VisibilityFlags::CameraRay,
125 0); // depth
126
127 ShadingPoint shading_point;
128 const bool hit = m_intersector.trace(ray, shading_point);
129
130 EXPECT_FALSE(hit);
131 }
132
133 TEST_CASE_F(TraceProbe_GivenAssemblyContainingEmptyBoundingBoxAndRayWithTMaxInsideAssembly_ReturnsFalse, Fixture<false>)
134 {
135 const ShadingRay ray(
136 Vector3d(0.0, 0.0, 2.0),
137 Vector3d(0.0, 0.0, -1.0),
138 0.0, // tmin
139 2.0, // tmax
140 ShadingRay::Time(),
141 VisibilityFlags::CameraRay,
142 0); // depth
143
144 const bool hit = m_intersector.trace_probe(ray);
145
146 EXPECT_FALSE(hit);
147 }
148
149 #ifdef APPLESEED_WITH_EMBREE
150
151 TEST_CASE_F(Trace_Embree_GivenAssemblyContainingEmptyBoundingBoxAndRayWithTMaxInsideAssembly_ReturnsFalse, Fixture<true>)
152 {
153 const ShadingRay ray(
154 Vector3d(0.0, 0.0, 2.0),
155 Vector3d(0.0, 0.0, -1.0),
156 0.0, // tmin
157 2.0, // tmax
158 ShadingRay::Time(),
159 VisibilityFlags::CameraRay,
160 0); // depth
161
162 ShadingPoint shading_point;
163 const bool hit = m_intersector.trace(ray, shading_point);
164
165 EXPECT_FALSE(hit);
166 }
167
168 TEST_CASE_F(TraceProbe_Embree_GivenAssemblyContainingEmptyBoundingBoxAndRayWithTMaxInsideAssembly_ReturnsFalse, Fixture<true>)
169 {
170 const ShadingRay ray(
171 Vector3d(0.0, 0.0, 2.0),
172 Vector3d(0.0, 0.0, -1.0),
173 0.0, // tmin
174 2.0, // tmax
175 ShadingRay::Time(),
176 VisibilityFlags::CameraRay,
177 0); // depth
178
179 const bool hit = m_intersector.trace_probe(ray);
180
181 EXPECT_FALSE(hit);
182 }
183
184 #endif // APPLESEED_WITH_EMBREE
185 }
186