Cortex  10.0.0-a4
BoxTraits.h
1 //
3 // Copyright (c) 2007-2009, Image Engine Design Inc. All rights reserved.
4 //
5 // Redistribution and use in source and binary forms, with or without
6 // modification, are permitted provided that the following conditions are
7 // met:
8 //
9 // * Redistributions of source code must retain the above copyright
10 // notice, this list of conditions and the following disclaimer.
11 //
12 // * Redistributions in binary form must reproduce the above copyright
13 // notice, this list of conditions and the following disclaimer in the
14 // documentation and/or other materials provided with the distribution.
15 //
16 // * Neither the name of Image Engine Design nor the names of any
17 // other contributors to this software may be used to endorse or
18 // promote products derived from this software without specific prior
19 // written permission.
20 //
21 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
22 // IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
23 // THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
24 // PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
25 // CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
26 // EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
27 // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
28 // PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
29 // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
30 // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
31 // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32 //
34 
35 #ifndef IE_CORE_BOXTRAITS_H
36 #define IE_CORE_BOXTRAITS_H
37 
38 #include "boost/static_assert.hpp"
39 
40 #include "OpenEXR/ImathBox.h"
41 #include "OpenEXR/ImathBoxAlgo.h"
42 
43 #include "IECore/VectorTraits.h"
44 
45 namespace IECore
46 {
47 
50 template<typename T>
52 {
53  typedef typename T::BaseType BaseType;
54 };
55 
58 template<typename T>
59 struct BoxTraits
60 {
61  typedef typename BoxTypeTraits<T>::BaseType BaseType;
62 
64  static T create( const BaseType &min, const BaseType &max )
65  {
66  return T( min, max );
67  }
68 
70  static T create()
71  {
72  return T();
73  }
74 
76  static BaseType min( const T &box )
77  {
78  return box.min;
79  }
80 
82  static BaseType max( const T &box )
83  {
84  return box.max;
85  }
86 
87  static void setMin( T &box, const BaseType &p )
88  {
89  box.min = p;
90  }
91 
92  static void setMax( T &box, const BaseType &p )
93  {
94  box.max = p;
95  }
96 
98  static bool isEmpty( const T &box )
99  {
100  return box.isEmpty();
101  }
102 
104  static void makeEmpty( T &box )
105  {
106  box.makeEmpty();
107 
108  assert( isEmpty(box) );
109  }
110 };
111 
112 template<>
113 struct BoxTypeTraits<Imath::Box3s>
114 {
115  typedef Imath::V3s BaseType;
116 
117 };
118 
119 template<>
120 struct BoxTypeTraits<Imath::Box3i>
121 {
122  typedef Imath::V3i BaseType;
123 
124 };
125 
126 template<>
127 struct BoxTypeTraits<Imath::Box3f>
128 {
129  typedef Imath::V3f BaseType;
130 
131 };
132 
133 template<>
134 struct BoxTypeTraits<Imath::Box3d>
135 {
136  typedef Imath::V3d BaseType;
137 
138 };
139 
140 template<>
141 struct BoxTypeTraits<Imath::Box2s>
142 {
143  typedef Imath::V2s BaseType;
144 
145 };
146 
147 template<>
148 struct BoxTypeTraits<Imath::Box2i>
149 {
150  typedef Imath::V2i BaseType;
151 
152 };
153 
154 template<>
155 struct BoxTypeTraits<Imath::Box2f>
156 {
157  typedef Imath::V2f BaseType;
158 
159 };
160 
161 template<>
162 struct BoxTypeTraits<Imath::Box2d>
163 {
164  typedef Imath::V2d BaseType;
165 
166 };
167 
168 
169 } // namespace IECore
170 
171 #endif // IE_CORE_BOXTRAITS_H
static BaseType min(const T &box)
Return the box's minimum corner point.
Definition: BoxTraits.h:76
Definition: BoxTraits.h:59
Definition: BoxTraits.h:51
static BaseType max(const T &box)
Return the box's maximum corner point.
Definition: BoxTraits.h:82
static T create()
Create an empty box.
Definition: BoxTraits.h:70
static void makeEmpty(T &box)
Modify the box such that it is considered to be empty.
Definition: BoxTraits.h:104
static T create(const BaseType &min, const BaseType &max)
Create a box from the minimum and maximum corner points.
Definition: BoxTraits.h:64
This namespace contains all components of the core library.
Definition: AddSmoothSkinningInfluencesOp.h:43
Definition: VecAlgo.h:49
static bool isEmpty(const T &box)
Return true if the box is considered to be empty.
Definition: BoxTraits.h:98