1 //
2 // Copyright 2016 Pixar
3 //
4 // Licensed under the Apache License, Version 2.0 (the "Apache License")
5 // with the following modification; you may not use this file except in
6 // compliance with the Apache License and the following modification to it:
7 // Section 6. Trademarks. is deleted and replaced with:
8 //
9 // 6. Trademarks. This License does not grant permission to use the trade
10 // names, trademarks, service marks, or product names of the Licensor
11 // and its affiliates, except as required to comply with Section 4(c) of
12 // the License and to reproduce the content of the NOTICE file.
13 //
14 // You may obtain a copy of the Apache License at
15 //
16 // http://www.apache.org/licenses/LICENSE-2.0
17 //
18 // Unless required by applicable law or agreed to in writing, software
19 // distributed under the Apache License with the above modification is
20 // distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
21 // KIND, either express or implied. See the Apache License for the specific
22 // language governing permissions and limitations under the Apache License.
23 //
24
25 #include "pxr/pxr.h"
26 #include "pxr/base/gf/plane.h"
27 #include "pxr/base/gf/matrix4d.h"
28 #include "pxr/base/gf/range3d.h"
29
30 #include "pxr/base/tf/pyUtils.h"
31 #include "pxr/base/tf/wrapTypeHelpers.h"
32 #include "pxr/base/tf/pyContainerConversions.h"
33
34 #include <boost/python/class.hpp>
35 #include <boost/python/copy_const_reference.hpp>
36 #include <boost/python/def.hpp>
37 #include <boost/python/operators.hpp>
38 #include <boost/python/return_arg.hpp>
39
40 #include <string>
41
42 using namespace boost::python;
43
44 using std::string;
45
46 PXR_NAMESPACE_USING_DIRECTIVE
47
48 namespace {
49
_Repr(GfPlane const & self)50 static string _Repr(GfPlane const &self) {
51 return TF_PY_REPR_PREFIX + "Plane(" + TfPyRepr(self.GetNormal()) + ", " +
52 TfPyRepr(self.GetDistanceFromOrigin()) + ")";
53 }
54
_FitPlaneToPoints(const std::vector<GfVec3d> & points)55 static object _FitPlaneToPoints(const std::vector<GfVec3d>& points) {
56 GfPlane plane;
57 return GfFitPlaneToPoints(points, &plane) ? object(plane) : object();
58 }
59
60 } // anonymous namespace
61
wrapPlane()62 void wrapPlane()
63 {
64 typedef GfPlane This;
65
66 object getNormal = make_function(&This::GetNormal,
67 return_value_policy<return_by_value>());
68
69 def( "FitPlaneToPoints", _FitPlaneToPoints );
70
71 class_<This>( "Plane", init<>() )
72 .def(init< const GfVec3d &, double >())
73 .def(init< const GfVec3d &, const GfVec3d & >())
74 .def(init< const GfVec3d &, const GfVec3d &, const GfVec3d & >())
75 .def(init< const GfVec4d & >())
76
77 .def( TfTypePythonClass() )
78
79 .def("Set", (void (This::*)(const GfVec3d &, double))
80 &This::Set, return_self<>())
81 .def("Set", (void (This::*)(const GfVec3d &, const GfVec3d &))
82 &This::Set, return_self<>())
83 .def("Set", (void (This::*)( const GfVec3d &, const GfVec3d &,
84 const GfVec3d & ))
85 &This::Set, return_self<>())
86 .def("Set", (void (This::*)(const GfVec4d &))
87 &This::Set, return_self<>())
88
89 .add_property( "normal", getNormal)
90 .add_property( "distanceFromOrigin", &This::GetDistanceFromOrigin )
91
92 .def( "GetDistance", &This::GetDistance )
93 .def( "GetDistanceFromOrigin", &This::GetDistanceFromOrigin )
94 .def( "GetNormal", getNormal)
95 .def( "GetEquation", &This::GetEquation )
96 .def( "Project", &This::Project )
97
98 .def( "Transform", &This::Transform, return_self<>() )
99
100 .def( "Reorient", &This::Reorient, return_self<>() )
101
102 .def( "IntersectsPositiveHalfSpace",
103 (bool (This::*)( const GfRange3d & ) const)
104 &This::IntersectsPositiveHalfSpace )
105
106 .def( "IntersectsPositiveHalfSpace",
107 (bool (This::*)( const GfVec3d & ) const)
108 &This::IntersectsPositiveHalfSpace )
109
110 .def( str(self) )
111 .def( self == self )
112 .def( self != self )
113
114 .def("__repr__", _Repr)
115
116 ;
117 to_python_converter<std::vector<This>,
118 TfPySequenceToPython<std::vector<This> > >();
119
120 }
121