00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024 #include "PreCompiled.h"
00025
00026 #include "Base/BoundBox.h"
00027
00028
00029 #include "VectorPy.h"
00030 #include "GeometryPyCXX.h"
00031 #include "BoundBoxPy.h"
00032 #include "BoundBoxPy.cpp"
00033
00034 using namespace Base;
00035
00036
00037 std::string BoundBoxPy::representation(void) const
00038 {
00039 std::stringstream str;
00040 str << "BoundBox (";
00041 str << getBoundBoxPtr()->MinX << ", "
00042 << getBoundBoxPtr()->MinY << ", "
00043 << getBoundBoxPtr()->MinZ << ", "
00044 << getBoundBoxPtr()->MaxX << ", "
00045 << getBoundBoxPtr()->MaxY << ", "
00046 << getBoundBoxPtr()->MaxZ ;
00047 str << ")";
00048
00049 return str.str();
00050 }
00051
00052 PyObject *BoundBoxPy::PyMake(struct _typeobject *, PyObject *, PyObject *)
00053 {
00054
00055 return new BoundBoxPy(new BoundBox3d);
00056 }
00057
00058
00059 int BoundBoxPy::PyInit(PyObject* args, PyObject* )
00060 {
00061 double xMin=0.0,yMin=0.0,zMin=0.0,xMax=0.0,yMax=0.0,zMax=0.0;
00062 PyObject *object1, *object2;
00063 BoundBoxPy::PointerType ptr = getBoundBoxPtr();
00064 if (PyArg_ParseTuple(args, "|dddddd", &xMin, &yMin, &zMin, &xMax, &yMax, &zMax)) {
00065 ptr->MaxX = xMax;
00066 ptr->MaxY = yMax;
00067 ptr->MaxZ = zMax;
00068 ptr->MinX = xMin;
00069 ptr->MinY = yMin;
00070 ptr->MinZ = zMin;
00071 return 0;
00072 }
00073 PyErr_Clear();
00074 if (PyArg_ParseTuple(args,"O!O!",&PyTuple_Type, &object1,
00075 &PyTuple_Type, &object2)) {
00076 try {
00077 Vector3d v1 = getVectorFromTuple<double>(object1);
00078 Vector3d v2 = getVectorFromTuple<double>(object2);
00079 ptr->Add(v1);
00080 ptr->Add(v2);
00081 return 0;
00082 }
00083 catch (const Py::Exception&) {
00084 return -1;
00085 }
00086 }
00087 PyErr_Clear();
00088 if (PyArg_ParseTuple(args,"O!O!",&(Base::VectorPy::Type), &object1,
00089 &(Base::VectorPy::Type), &object2)) {
00090
00091 ptr->Add(*(static_cast<Base::VectorPy*>(object1)->getVectorPtr()));
00092 ptr->Add(*(static_cast<Base::VectorPy*>(object2)->getVectorPtr()));
00093 return 0;
00094 }
00095 PyErr_Clear();
00096 if (PyArg_ParseTuple(args,"O!",&(Base::BoundBoxPy::Type), &object1)) {
00097
00098 *ptr = *(static_cast<Base::BoundBoxPy*>(object1)->getBoundBoxPtr());
00099 return 0;
00100 }
00101
00102 PyErr_SetString(PyExc_TypeError, "Either six floats, two instances of "
00103 "Vector/Tuple or instance of BoundBox expected");
00104 return -1;
00105 }
00106
00107 PyObject* BoundBoxPy::add(PyObject *args)
00108 {
00109 double x,y,z;
00110 PyObject *object;
00111 if (PyArg_ParseTuple(args, "ddd", &x,&y,&z)) {
00112 getBoundBoxPtr()->Add(Vector3d(x,y,z));
00113 Py_Return;
00114 }
00115
00116 PyErr_Clear();
00117 if (PyArg_ParseTuple(args,"O!",&PyTuple_Type, &object)) {
00118 getBoundBoxPtr()->Add(getVectorFromTuple<double>(object));
00119 Py_Return;
00120 }
00121
00122 PyErr_Clear();
00123 if (PyArg_ParseTuple(args,"O!",&(Base::VectorPy::Type), &object)) {
00124 getBoundBoxPtr()->Add(*(static_cast<Base::VectorPy*>(object)->getVectorPtr()));
00125 Py_Return;
00126 }
00127
00128 PyErr_Clear();
00129 if (PyArg_ParseTuple(args,"O!;Need a Vector, BoundBox or three floats as argument",&(Base::BoundBoxPy::Type), &object)) {
00130 getBoundBoxPtr()->Add(*(static_cast<Base::BoundBoxPy*>(object)->getBoundBoxPtr()));
00131 Py_Return;
00132 }
00133
00134 PyErr_SetString(PyExc_TypeError, "Either three floats, instance of Vector or instance of BoundBox expected");
00135 return 0;
00136 }
00137
00138 PyObject* BoundBoxPy::isIntersection(PyObject *args)
00139 {
00140 double x,y,z;
00141 PyObject *object,*object2;
00142 Py::Boolean retVal;
00143 if (PyArg_ParseTuple(args, "ddd", &x,&y,&z)) {
00144 retVal = getBoundBoxPtr()->IsInBox(Vector3d(x,y,z));
00145 }
00146 else if (PyArg_ParseTuple(args,"O!",&PyTuple_Type, &object)) {
00147 PyErr_Clear();
00148 retVal = getBoundBoxPtr()->IsInBox(getVectorFromTuple<double>(object));
00149 }
00150 else if (PyArg_ParseTuple(args,"O!",&(Base::VectorPy::Type), &object)) {
00151 PyErr_Clear();
00152 retVal = getBoundBoxPtr()->IsInBox(*(static_cast<Base::VectorPy*>(object)->getVectorPtr()));
00153 }
00154 else if (PyArg_ParseTuple(args,"O!O!",&(Base::VectorPy::Type), &object,
00155 &(Base::VectorPy::Type), &object2)) {
00156 PyErr_Clear();
00157 retVal = getBoundBoxPtr()->IsCutLine(
00158 *(static_cast<Base::VectorPy*>(object )->getVectorPtr()),
00159 *(static_cast<Base::VectorPy*>(object2)->getVectorPtr()));
00160 }
00161 else if (PyArg_ParseTuple(args,"O!;Need vector, bounding box or three floats as argument",
00162 &(Base::BoundBoxPy::Type), &object)) {
00163 PyErr_Clear();
00164 retVal = getBoundBoxPtr()->IsInBox(*(static_cast<Base::BoundBoxPy*>(object)->getBoundBoxPtr()));
00165 }
00166 else {
00167 PyErr_SetString(PyExc_TypeError, "Either three floats, Vector(s) or BoundBox expected");
00168 return 0;
00169 }
00170
00171 return Py::new_reference_to(retVal);
00172 }
00173
00174 PyObject* BoundBoxPy::enlarge(PyObject *args)
00175 {
00176 double s;
00177 if (!PyArg_ParseTuple(args, "d;Need float parameter to enlarge", &s))
00178 return 0;
00179 getBoundBoxPtr()->Enlarge(s);
00180 Py_Return;
00181 }
00182
00183 PyObject* BoundBoxPy::getIntersectionPoint(PyObject *args)
00184 {
00185 PyObject *object,*object2;
00186 double epsilon=0.0001;
00187 if (PyArg_ParseTuple(args,"O!O!|d:Need base and direction vector",
00188 &(Base::VectorPy::Type), &object,&(Base::VectorPy::Type), &object2, &epsilon)) {
00189 Base::Vector3d point;
00190 bool ok = getBoundBoxPtr()->IntersectionPoint(
00191 *(static_cast<Base::VectorPy*>(object)->getVectorPtr()),
00192 *(static_cast<Base::VectorPy*>(object2)->getVectorPtr()),
00193 point, epsilon);
00194
00195 BoundBoxPy::PointerType bb = getBoundBoxPtr();
00196 if (ok) {
00197 return new VectorPy(point);
00198 }
00199 else {
00200 PyErr_SetString(PyExc_Exception, "No intersection");
00201 return 0;
00202 }
00203 }
00204 else
00205 return 0;
00206 }
00207
00208 PyObject* BoundBoxPy::move(PyObject *args)
00209 {
00210 double x,y,z;
00211 PyObject *object;
00212 Base::Vector3d vec;
00213
00214 if (PyArg_ParseTuple(args, "ddd", &x,&y,&z)) {
00215 vec = Vector3d(x,y,z);
00216 }
00217 else if (PyArg_ParseTuple(args,"O!:Need vector to move",&PyTuple_Type, &object)) {
00218 PyErr_Clear();
00219 vec = getVectorFromTuple<double>(object);
00220 }
00221 else if (PyArg_ParseTuple(args,"O!:Need vector to move",&(Base::VectorPy::Type), &object)) {
00222 PyErr_Clear();
00223 vec = *(static_cast<Base::VectorPy*>(object)->getVectorPtr());
00224 }
00225 else {
00226 PyErr_SetString(PyExc_TypeError, "Either three floats or vector expected");
00227 return 0;
00228 }
00229
00230 getBoundBoxPtr()->MoveX(vec.x);
00231 getBoundBoxPtr()->MoveY(vec.y);
00232 getBoundBoxPtr()->MoveZ(vec.z);
00233
00234 Py_Return;
00235 }
00236
00237 PyObject* BoundBoxPy::isCutPlane(PyObject *args)
00238 {
00239 PyObject *object,*object2;
00240 Py::Boolean retVal;
00241
00242 if (PyArg_ParseTuple(args,"O!O!:Need base and normal vector of a plane",
00243 &(Base::VectorPy::Type), &object,&(Base::VectorPy::Type), &object2))
00244 retVal = getBoundBoxPtr()->IsCutPlane(
00245 *(static_cast<Base::VectorPy*>(object)->getVectorPtr()),
00246 *(static_cast<Base::VectorPy*>(object2)->getVectorPtr()));
00247 else
00248 return 0;
00249
00250 return Py::new_reference_to(retVal);
00251 }
00252
00253 PyObject* BoundBoxPy::isInside(PyObject *args)
00254 {
00255 PyObject *object;
00256 Py::Boolean retVal;
00257
00258 if (!PyArg_ParseTuple(args,"O", &object))
00259 return 0;
00260 if (PyObject_TypeCheck(object, &(Base::VectorPy::Type))) {
00261 Base::VectorPy *vec = static_cast<Base::VectorPy*>(object);
00262 retVal = getBoundBoxPtr()->IsInBox(*vec->getVectorPtr());
00263 }
00264 else if (PyObject_TypeCheck(object, &(Base::BoundBoxPy::Type))) {
00265 Base::BoundBoxPy *box = static_cast<Base::BoundBoxPy*>(object);
00266 retVal = getBoundBoxPtr()->IsInBox(*box->getBoundBoxPtr());
00267 }
00268 else {
00269 PyErr_SetString(PyExc_TypeError, "Either a Vector or BoundBox object expected");
00270 return 0;
00271 }
00272
00273 return Py::new_reference_to(retVal);
00274 }
00275
00276 Py::Object BoundBoxPy::getCenter(void) const
00277 {
00278 return Py::Vector(getBoundBoxPtr()->CalcCenter());
00279 }
00280
00281 Py::Float BoundBoxPy::getXMax(void) const
00282 {
00283 return Py::Float(getBoundBoxPtr()->MaxX);
00284 }
00285
00286 void BoundBoxPy::setXMax(Py::Float arg)
00287 {
00288 getBoundBoxPtr()->MaxX = arg;
00289 }
00290
00291 Py::Float BoundBoxPy::getYMax(void) const
00292 {
00293 return Py::Float(getBoundBoxPtr()->MaxY);
00294 }
00295
00296 void BoundBoxPy::setYMax(Py::Float arg)
00297 {
00298 getBoundBoxPtr()->MaxY = arg;
00299 }
00300
00301 Py::Float BoundBoxPy::getZMax(void) const
00302 {
00303 return Py::Float(getBoundBoxPtr()->MaxZ);
00304 }
00305
00306 void BoundBoxPy::setZMax(Py::Float arg)
00307 {
00308 getBoundBoxPtr()->MaxZ = arg;
00309 }
00310
00311 Py::Float BoundBoxPy::getXMin(void) const
00312 {
00313 return Py::Float(getBoundBoxPtr()->MinX);
00314 }
00315
00316 void BoundBoxPy::setXMin(Py::Float arg)
00317 {
00318 getBoundBoxPtr()->MinX = arg;
00319 }
00320
00321 Py::Float BoundBoxPy::getYMin(void) const
00322 {
00323 return Py::Float(getBoundBoxPtr()->MinY);
00324 }
00325
00326 void BoundBoxPy::setYMin(Py::Float arg)
00327 {
00328 getBoundBoxPtr()->MinY = arg;
00329 }
00330
00331 Py::Float BoundBoxPy::getZMin(void) const
00332 {
00333 return Py::Float(getBoundBoxPtr()->MinZ);
00334 }
00335
00336 void BoundBoxPy::setZMin(Py::Float arg)
00337 {
00338 getBoundBoxPtr()->MinZ = arg;
00339 }
00340
00341 Py::Float BoundBoxPy::getXLength(void) const
00342 {
00343 return Py::Float(getBoundBoxPtr()->LengthX());
00344 }
00345
00346 Py::Float BoundBoxPy::getYLength(void) const
00347 {
00348 return Py::Float(getBoundBoxPtr()->LengthY());
00349 }
00350
00351 Py::Float BoundBoxPy::getZLength(void) const
00352 {
00353 return Py::Float(getBoundBoxPtr()->LengthZ());
00354 }
00355
00356 Py::Float BoundBoxPy::getDiagonalLength(void) const
00357 {
00358 return Py::Float(getBoundBoxPtr()->CalcDiagonalLength());
00359 }
00360
00361 PyObject *BoundBoxPy::getCustomAttributes(const char* ) const
00362 {
00363 return 0;
00364 }
00365
00366 int BoundBoxPy::setCustomAttributes(const char* , PyObject* )
00367 {
00368 return 0;
00369 }
00370
00371