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) 2014-2018 Francois Beaune, The appleseedhq Organization
9 //
10 // Permission is hereby granted, free of charge, to any person obtaining a copy
11 // of this software and associated documentation files (the "Software"), to deal
12 // in the Software without restriction, including without limitation the rights
13 // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
14 // copies of the Software, and to permit persons to whom the Software is
15 // furnished to do so, subject to the following conditions:
16 //
17 // The above copyright notice and this permission notice shall be included in
18 // all copies or substantial portions of the Software.
19 //
20 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
21 // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
22 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
23 // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
24 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
25 // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
26 // THE SOFTWARE.
27 //
28 
29 // Interface header.
30 #include "visibilityflags.h"
31 
32 // appleseed.renderer headers.
33 #include "renderer/utility/messagecontext.h"
34 #include "renderer/utility/paramarray.h"
35 
36 // appleseed.foundation headers.
37 #include "foundation/utility/countof.h"
38 
39 namespace renderer
40 {
41 
42 // The Names array must be kept in sync with the VisibilityFlags::Values enum and
43 // the order of the strings has to match the order of the enum.
44 const char* VisibilityFlags::Names[] =
45 {
46     "camera",
47     "light",
48     "shadow",
49     "transparency",
50     "probe",
51     "diffuse",
52     "glossy",
53     "specular",
54     "subsurface",
55     "npr"
56 };
57 
58 const size_t VisibilityFlags::Count = countof(VisibilityFlags::Names);
59 
parse(const ParamArray & params,const MessageContext & message_context)60 VisibilityFlags::Type VisibilityFlags::parse(
61     const ParamArray&       params,
62     const MessageContext&   message_context)
63 {
64     Type flags = 0;
65 
66     for (size_t i = 0; i < Count; ++i)
67     {
68         if (params.get_optional<bool>(Names[i], true, message_context))
69             flags |= 1UL << i;
70     }
71 
72     return flags;
73 }
74 
to_dictionary(const Type flags)75 ParamArray VisibilityFlags::to_dictionary(const Type flags)
76 {
77     ParamArray params;
78 
79     for (size_t i = 0; i < Count; ++i)
80         params.insert(Names[i], (flags & (1UL << i)) != 0);
81 
82     return params;
83 }
84 
85 }   // namespace renderer
86