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/VectorPy.h>
00027 #include <Base/Handle.h>
00028 #include <Base/Builder3D.h>
00029 #include <Base/GeometryPyCXX.h>
00030
00031 #include "Mesh.h"
00032 #include "MeshPy.h"
00033 #include "MeshPointPy.h"
00034 #include "FacetPy.h"
00035 #include "MeshPy.cpp"
00036 #include "MeshProperties.h"
00037 #include "Core/Algorithm.h"
00038 #include "Core/Iterator.h"
00039 #include "Core/Elements.h"
00040 #include "Core/Grid.h"
00041 #include "Core/MeshKernel.h"
00042 #include "Core/Triangulation.h"
00043
00044 using namespace Mesh;
00045
00046
00047 struct MeshPropertyLock {
00048 MeshPropertyLock(PropertyMeshKernel* p) : prop(p)
00049 { if (prop) prop->startEditing(); }
00050 ~MeshPropertyLock()
00051 { if (prop) prop->finishEditing(); }
00052 private:
00053 PropertyMeshKernel* prop;
00054 };
00055
00056 int MeshPy::PyInit(PyObject* args, PyObject*)
00057 {
00058 PyObject *pcObj=0;
00059 if (!PyArg_ParseTuple(args, "|O", &pcObj))
00060 return -1;
00061
00062 try {
00063 this->parentProperty = 0;
00064
00065 if (!pcObj) return 0;
00066 if (PyObject_TypeCheck(pcObj, &(MeshPy::Type))) {
00067 getMeshObjectPtr()->operator = (*static_cast<MeshPy*>(pcObj)->getMeshObjectPtr());
00068 }
00069 else if (PyList_Check(pcObj)) {
00070 PyObject* ret = addFacets(args);
00071 bool ok = (ret!=0);
00072 Py_XDECREF(ret);
00073 if (!ok) return -1;
00074 }
00075 else if (PyTuple_Check(pcObj)) {
00076 PyObject* ret = addFacets(args);
00077 bool ok = (ret!=0);
00078 Py_XDECREF(ret);
00079 if (!ok) return -1;
00080 }
00081 else if (PyString_Check(pcObj)) {
00082 getMeshObjectPtr()->load(PyString_AsString(pcObj));
00083 }
00084 else {
00085 PyErr_Format(PyExc_TypeError, "Cannot create a mesh out of a '%s'",
00086 pcObj->ob_type->tp_name);
00087 return -1;
00088 }
00089 }
00090 catch (const Base::Exception &e) {
00091 PyErr_SetString(PyExc_Exception,e.what());
00092 return -1;
00093 }
00094 catch (const std::exception &e) {
00095 PyErr_SetString(PyExc_Exception,e.what());
00096 return -1;
00097 }
00098 catch (const Py::Exception&) {
00099 return -1;
00100 }
00101
00102 return 0;
00103 }
00104
00105
00106 std::string MeshPy::representation(void) const
00107 {
00108
00109
00110
00111
00112 MeshPy::PointerType ptr = reinterpret_cast<MeshPy::PointerType>(_pcTwinPointer);
00113
00114 return ptr->representation();
00115 }
00116
00117 PyObject *MeshPy::PyMake(struct _typeobject *, PyObject *, PyObject *)
00118 {
00119
00120 return new MeshPy(new MeshObject);
00121 }
00122
00123 PyObject* MeshPy::copy(PyObject *args)
00124 {
00125 if (!PyArg_ParseTuple(args, ""))
00126 return NULL;
00127
00128 const MeshCore::MeshKernel& kernel = getMeshObjectPtr()->getKernel();
00129 return new MeshPy(new MeshObject(kernel));
00130 }
00131
00132 PyObject* MeshPy::read(PyObject *args)
00133 {
00134 const char* Name;
00135 if (!PyArg_ParseTuple(args, "s",&Name))
00136 return NULL;
00137
00138 PY_TRY {
00139 getMeshObjectPtr()->load(Name);
00140 } PY_CATCH;
00141
00142 Py_Return;
00143 }
00144
00145 PyObject* MeshPy::write(PyObject *args)
00146 {
00147 const char* Name;
00148 char* Ext=0;
00149 if (!PyArg_ParseTuple(args, "s|s",&Name,&Ext))
00150 return NULL;
00151
00152 MeshCore::MeshIO::Format format = MeshCore::MeshIO::Undefined;
00153 if (Ext) {
00154 std::map<std::string, MeshCore::MeshIO::Format> ext;
00155 ext["BMS" ] = MeshCore::MeshIO::BMS;
00156 ext["STL" ] = MeshCore::MeshIO::BSTL;
00157 ext["AST" ] = MeshCore::MeshIO::ASTL;
00158 ext["OBJ" ] = MeshCore::MeshIO::OBJ;
00159 ext["OFF" ] = MeshCore::MeshIO::OFF;
00160 ext["IV" ] = MeshCore::MeshIO::IV;
00161 ext["VRML"] = MeshCore::MeshIO::VRML;
00162 ext["WRL" ] = MeshCore::MeshIO::VRML;
00163 ext["WRZ" ] = MeshCore::MeshIO::WRZ;
00164 ext["NAS" ] = MeshCore::MeshIO::NAS;
00165 ext["BDF" ] = MeshCore::MeshIO::NAS;
00166 ext["PLY" ] = MeshCore::MeshIO::PLY;
00167 ext["PY" ] = MeshCore::MeshIO::PY;
00168 if (ext.find(Ext) != ext.end())
00169 format = ext[Ext];
00170 };
00171
00172 PY_TRY {
00173 getMeshObjectPtr()->save(Name, format);
00174 } PY_CATCH;
00175
00176 Py_Return;
00177 }
00178
00179 PyObject* MeshPy::writeInventor(PyObject *args)
00180 {
00181 float creaseangle=0.0f;
00182 if (!PyArg_ParseTuple(args, "|f",&creaseangle))
00183 return NULL;
00184
00185 MeshObject* mesh = getMeshObjectPtr();
00186 const MeshCore::MeshFacetArray& faces = mesh->getKernel().GetFacets();
00187 std::vector<int> indices;
00188 std::vector<Base::Vector3f> coords;
00189 coords.reserve(mesh->countPoints());
00190 for (MeshObject::const_point_iterator it = mesh->points_begin(); it != mesh->points_end(); ++it)
00191 coords.push_back(Base::Vector3f((float)it->x,(float)it->y,(float)it->z));
00192 indices.reserve(4*faces.size());
00193 for (MeshCore::MeshFacetArray::_TConstIterator it = faces.begin(); it != faces.end(); ++it) {
00194 indices.push_back(it->_aulPoints[0]);
00195 indices.push_back(it->_aulPoints[1]);
00196 indices.push_back(it->_aulPoints[2]);
00197 indices.push_back(-1);
00198 }
00199
00200 std::stringstream result;
00201 Base::InventorBuilder builder(result);
00202 builder.addIndexedFaceSet(coords, indices, creaseangle);
00203 builder.close();
00204
00205 return Py::new_reference_to(Py::String(result.str()));
00206 }
00207
00208 PyObject* MeshPy::offset(PyObject *args)
00209 {
00210 float Float;
00211 if (!PyArg_ParseTuple(args, "f",&Float))
00212 return NULL;
00213
00214 PY_TRY {
00215 getMeshObjectPtr()->offsetSpecial2(Float);
00216 } PY_CATCH;
00217
00218 Py_Return;
00219 }
00220
00221 PyObject* MeshPy::offsetSpecial(PyObject *args)
00222 {
00223 float Float,zmin,zmax;
00224 if (!PyArg_ParseTuple(args, "fff",&Float,&zmin,&zmax))
00225 return NULL;
00226
00227 PY_TRY {
00228 getMeshObjectPtr()->offsetSpecial(Float,zmax,zmin);
00229 } PY_CATCH;
00230
00231 Py_Return;
00232 }
00233
00234 PyObject* MeshPy::crossSections(PyObject *args)
00235 {
00236 PyObject *obj;
00237 PyObject *poly=0;
00238 float min_eps = 1.0e-2f;
00239 if (!PyArg_ParseTuple(args, "O!|fO!", &PyList_Type, &obj, &min_eps, &PyBool_Type, &poly))
00240 return 0;
00241
00242 Py::List list(obj);
00243 union PyType_Object pyType = {&(Base::VectorPy::Type)};
00244 Py::Type vType(pyType.o);
00245
00246 std::vector<MeshObject::TPlane> csPlanes;
00247 for (Py::List::iterator it = list.begin(); it != list.end(); ++it) {
00248 Py::Tuple pair(*it);
00249 Py::Object p1 = pair.getItem(0);
00250 Py::Object p2 = pair.getItem(1);
00251 if (p1.isType(vType) && p2.isType(vType)) {
00252 MeshObject::TPlane plane;
00253 Base::Vector3d b = static_cast<Base::VectorPy*>(p1.ptr())->value();
00254 Base::Vector3d n = static_cast<Base::VectorPy*>(p2.ptr())->value();
00255 plane.first.Set((float)b.x,(float)b.y,(float)b.z);
00256 plane.second.Set((float)n.x,(float)n.y,(float)n.z);
00257 csPlanes.push_back(plane);
00258 }
00259 else if (p1.isTuple() && p2.isTuple()) {
00260 Py::Tuple b(p1);
00261 Py::Tuple n(p2);
00262 float bx = (float)Py::Float(b.getItem(0));
00263 float by = (float)Py::Float(b.getItem(1));
00264 float bz = (float)Py::Float(b.getItem(2));
00265 float nx = (float)Py::Float(n.getItem(0));
00266 float ny = (float)Py::Float(n.getItem(1));
00267 float nz = (float)Py::Float(n.getItem(2));
00268
00269 MeshObject::TPlane plane;
00270 plane.first .Set(bx,by,bz);
00271 plane.second.Set(nx,ny,nz);
00272 csPlanes.push_back(plane);
00273 }
00274 }
00275
00276 std::vector<MeshObject::TPolylines> sections;
00277 getMeshObjectPtr()->crossSections(csPlanes, sections, min_eps, (poly == Py_True));
00278
00279
00280 Py::List crossSections;
00281 for (std::vector<MeshObject::TPolylines>::iterator it = sections.begin(); it != sections.end(); ++it) {
00282 Py::List section;
00283 for (MeshObject::TPolylines::const_iterator jt = it->begin(); jt != it->end(); ++jt) {
00284 Py::List polyline;
00285 for (std::vector<Base::Vector3f>::const_iterator kt = jt->begin(); kt != jt->end(); ++kt) {
00286 polyline.append(Py::Object(new Base::VectorPy(*kt)));
00287 }
00288 section.append(polyline);
00289 }
00290 crossSections.append(section);
00291 }
00292
00293 return Py::new_reference_to(crossSections);
00294 }
00295
00296 PyObject* MeshPy::unite(PyObject *args)
00297 {
00298 MeshPy *pcObject;
00299 PyObject *pcObj;
00300 if (!PyArg_ParseTuple(args, "O!", &(MeshPy::Type), &pcObj))
00301 return NULL;
00302
00303 pcObject = static_cast<MeshPy*>(pcObj);
00304
00305 PY_TRY {
00306 MeshObject* mesh = getMeshObjectPtr()->unite(*pcObject->getMeshObjectPtr());
00307 return new MeshPy(mesh);
00308 } PY_CATCH;
00309
00310 Py_Return;
00311 }
00312
00313 PyObject* MeshPy::intersect(PyObject *args)
00314 {
00315 MeshPy *pcObject;
00316 PyObject *pcObj;
00317 if (!PyArg_ParseTuple(args, "O!", &(MeshPy::Type), &pcObj))
00318 return NULL;
00319
00320 pcObject = static_cast<MeshPy*>(pcObj);
00321
00322 PY_TRY {
00323 MeshObject* mesh = getMeshObjectPtr()->intersect(*pcObject->getMeshObjectPtr());
00324 return new MeshPy(mesh);
00325 } PY_CATCH;
00326
00327 Py_Return;
00328 }
00329
00330 PyObject* MeshPy::difference(PyObject *args)
00331 {
00332 MeshPy *pcObject;
00333 PyObject *pcObj;
00334 if (!PyArg_ParseTuple(args, "O!", &(MeshPy::Type), &pcObj))
00335 return NULL;
00336
00337 pcObject = static_cast<MeshPy*>(pcObj);
00338
00339 PY_TRY {
00340 MeshObject* mesh = getMeshObjectPtr()->subtract(*pcObject->getMeshObjectPtr());
00341 return new MeshPy(mesh);
00342 } PY_CATCH;
00343
00344 Py_Return;
00345 }
00346
00347 PyObject* MeshPy::inner(PyObject *args)
00348 {
00349 MeshPy *pcObject;
00350 PyObject *pcObj;
00351 if (!PyArg_ParseTuple(args, "O!", &(MeshPy::Type), &pcObj))
00352 return NULL;
00353
00354 pcObject = static_cast<MeshPy*>(pcObj);
00355
00356 PY_TRY {
00357 MeshObject* mesh = getMeshObjectPtr()->inner(*pcObject->getMeshObjectPtr());
00358 return new MeshPy(mesh);
00359 } PY_CATCH;
00360
00361 Py_Return;
00362 }
00363
00364 PyObject* MeshPy::outer(PyObject *args)
00365 {
00366 MeshPy *pcObject;
00367 PyObject *pcObj;
00368 if (!PyArg_ParseTuple(args, "O!", &(MeshPy::Type), &pcObj))
00369 return NULL;
00370
00371 pcObject = static_cast<MeshPy*>(pcObj);
00372
00373 PY_TRY {
00374 MeshObject* mesh = getMeshObjectPtr()->outer(*pcObject->getMeshObjectPtr());
00375 return new MeshPy(mesh);
00376 } PY_CATCH;
00377
00378 Py_Return;
00379 }
00380
00381 PyObject* MeshPy::coarsen(PyObject *args)
00382 {
00383 PyErr_SetString(PyExc_NotImplementedError, "Not yet implemented");
00384 return 0;
00385 }
00386
00387 PyObject* MeshPy::translate(PyObject *args)
00388 {
00389 float x,y,z;
00390 if (!PyArg_ParseTuple(args, "fff",&x,&y,&z))
00391 return NULL;
00392
00393 PY_TRY {
00394 Base::Matrix4D m;
00395 m.move(x,y,z);
00396 getMeshObjectPtr()->getKernel().Transform(m);
00397 } PY_CATCH;
00398
00399 Py_Return;
00400 }
00401
00402 PyObject* MeshPy::rotate(PyObject *args)
00403 {
00404 double x,y,z;
00405 if (!PyArg_ParseTuple(args, "ddd",&x,&y,&z))
00406 return NULL;
00407
00408 PY_TRY {
00409 Base::Matrix4D m;
00410 m.rotX(x);
00411 m.rotY(y);
00412 m.rotZ(z);
00413 getMeshObjectPtr()->getKernel().Transform(m);
00414 } PY_CATCH;
00415
00416 Py_Return;
00417 }
00418
00419 PyObject* MeshPy::transform(PyObject *args)
00420 {
00421 PyObject *mat;
00422 if (!PyArg_ParseTuple(args, "O!",&(Base::MatrixPy::Type), &mat))
00423 return NULL;
00424
00425 PY_TRY {
00426 getMeshObjectPtr()->getKernel().Transform(static_cast<Base::MatrixPy*>(mat)->value());
00427 } PY_CATCH;
00428
00429 Py_Return;
00430 }
00431
00432 PyObject* MeshPy::transformToEigen(PyObject *args)
00433 {
00434 if (!PyArg_ParseTuple(args, ""))
00435 return NULL;
00436 getMeshObjectPtr()->transformToEigenSystem();
00437 Py_Return;
00438 }
00439
00440 PyObject* MeshPy::addFacet(PyObject *args)
00441 {
00442 double x1,y1,z1,x2,y2,z2,x3,y3,z3;
00443 if (PyArg_ParseTuple(args, "ddddddddd",&x1,&y1,&z1,&x2,&y2,&z2,&x3,&y3,&z3)) {
00444 getMeshObjectPtr()->addFacet(MeshCore::MeshGeomFacet(
00445 Base::Vector3f((float)x1,(float)y1,(float)z1),
00446 Base::Vector3f((float)x2,(float)y2,(float)z2),
00447 Base::Vector3f((float)x3,(float)y3,(float)z3)));
00448 Py_Return;
00449 }
00450
00451 PyErr_Clear();
00452 PyObject *v1, *v2, *v3;
00453 if (PyArg_ParseTuple(args, "O!O!O!",&(Base::VectorPy::Type), &v1,
00454 &(Base::VectorPy::Type), &v2,
00455 &(Base::VectorPy::Type), &v3)) {
00456 Base::Vector3d *p1 = static_cast<Base::VectorPy*>(v1)->getVectorPtr();
00457 Base::Vector3d *p2 = static_cast<Base::VectorPy*>(v2)->getVectorPtr();
00458 Base::Vector3d *p3 = static_cast<Base::VectorPy*>(v3)->getVectorPtr();
00459 getMeshObjectPtr()->addFacet(MeshCore::MeshGeomFacet(
00460 Base::Vector3f((float)p1->x,(float)p1->y,(float)p1->z),
00461 Base::Vector3f((float)p2->x,(float)p2->y,(float)p2->z),
00462 Base::Vector3f((float)p3->x,(float)p3->y,(float)p3->z)));
00463 Py_Return;
00464 }
00465
00466 PyErr_SetString(PyExc_Exception, "set 9 floats or three vectors");
00467 return 0;
00468 }
00469
00470 PyObject* MeshPy::addFacets(PyObject *args)
00471 {
00472 PyObject *list;
00473 if (PyArg_ParseTuple(args, "O!", &PyList_Type, &list)) {
00474 Py::List list_f(list);
00475 union PyType_Object pyVType = {&(Base::VectorPy::Type)};
00476 Py::Type vVType(pyVType.o);
00477
00478 union PyType_Object pyFType = {&(Mesh::FacetPy::Type)};
00479 Py::Type vFType(pyFType.o);
00480
00481 std::vector<MeshCore::MeshGeomFacet> facets;
00482 MeshCore::MeshGeomFacet facet;
00483 for (Py::List::iterator it = list_f.begin(); it != list_f.end(); ++it) {
00484 if ((*it).isType(vFType)) {
00485 Mesh::FacetPy* face = static_cast<Mesh::FacetPy*>((*it).ptr());
00486 facets.push_back(*face->getFacetPtr());
00487 }
00488 else if ((*it).isSequence()) {
00489 Py::Sequence seq(*it);
00490 if (seq.size() == 3) {
00491 if (PyFloat_Check(seq[0].ptr())) {
00492
00493 facet._aclPoints[0] = Base::getVectorFromTuple<float>((*it).ptr());
00494 ++it;
00495 facet._aclPoints[1] = Base::getVectorFromTuple<float>((*it).ptr());
00496 ++it;
00497 facet._aclPoints[2] = Base::getVectorFromTuple<float>((*it).ptr());
00498 }
00499 else {
00500 for (int i=0; i<3; i++) {
00501 if (PyObject_TypeCheck(seq[i].ptr(), &(Base::VectorPy::Type))) {
00502 Base::Vector3d p = Py::Vector(seq[i]).toVector();
00503 facet._aclPoints[i].Set((float)p.x,(float)p.y,(float)p.z);
00504 }
00505 else if (seq[i].isSequence()){
00506 facet._aclPoints[i] = Base::getVectorFromTuple<float>(seq[i].ptr());
00507 }
00508 }
00509 }
00510
00511 facet.CalcNormal();
00512 facets.push_back(facet);
00513 }
00514 else {
00515 int index=0;
00516 for (int i=0; i<3; i++) {
00517 facet._aclPoints[i].x = (float)(double)Py::Float(seq[index++]);
00518 facet._aclPoints[i].y = (float)(double)Py::Float(seq[index++]);
00519 facet._aclPoints[i].z = (float)(double)Py::Float(seq[index++]);
00520 }
00521 facet.CalcNormal();
00522 facets.push_back(facet);
00523 }
00524 }
00525 }
00526
00527 getMeshObjectPtr()->addFacets(facets);
00528 Py_Return;
00529 }
00530
00531 PyErr_Clear();
00532 if (PyArg_ParseTuple(args, "O!", &PyTuple_Type, &list)) {
00533 Py::Tuple tuple(list);
00534 Py::List list_v(tuple.getItem(0));
00535 std::vector<Base::Vector3f> vertices;
00536 union PyType_Object pyVertType = {&(Base::VectorPy::Type)};
00537 Py::Type vType(pyVertType.o);
00538 for (Py::List::iterator it = list_v.begin(); it != list_v.end(); ++it) {
00539 if ((*it).isType(vType)) {
00540 Base::Vector3d v = static_cast<Base::VectorPy*>((*it).ptr())->value();
00541 vertices.push_back(Base::Vector3f((float)v.x,(float)v.y,(float)v.z));
00542 }
00543 }
00544
00545 Py::List list_f(tuple.getItem(1));
00546 MeshCore::MeshFacetArray faces;
00547 for (Py::List::iterator it = list_f.begin(); it != list_f.end(); ++it) {
00548 Py::Tuple f(*it);
00549 MeshCore::MeshFacet face;
00550 face._aulPoints[0] = (long)Py::Int(f.getItem(0));
00551 face._aulPoints[1] = (long)Py::Int(f.getItem(1));
00552 face._aulPoints[2] = (long)Py::Int(f.getItem(2));
00553 faces.push_back(face);
00554 }
00555
00556 getMeshObjectPtr()->addFacets(faces, vertices);
00557
00558 Py_Return;
00559 }
00560
00561 PyErr_SetString(PyExc_Exception, "either expect\n"
00562 "-- [Vector] (3 of them define a facet)\n"
00563 "-- ([Vector],[(int,int,int)])");
00564 return NULL;
00565 }
00566
00567 PyObject* MeshPy::removeFacets(PyObject *args)
00568 {
00569 PyObject* list;
00570 if (!PyArg_ParseTuple(args, "O!", &PyList_Type, &list))
00571 return 0;
00572
00573 std::vector<unsigned long> indices;
00574 Py::List ary(list);
00575 for (Py::List::iterator it = ary.begin(); it != ary.end(); ++it) {
00576 Py::Int f(*it);
00577 indices.push_back((long)f);
00578 }
00579
00580 getMeshObjectPtr()->deleteFacets(indices);
00581 Py_Return;
00582 }
00583
00584 PyObject* MeshPy::addMesh(PyObject *args)
00585 {
00586 PyObject* mesh;
00587 if (!PyArg_ParseTuple(args, "O!",&(MeshPy::Type), &mesh))
00588 return NULL;
00589
00590 PY_TRY {
00591 getMeshObjectPtr()->addMesh(*static_cast<MeshPy*>(mesh)->getMeshObjectPtr());
00592 } PY_CATCH;
00593
00594 Py_Return;
00595 }
00596
00597 PyObject* MeshPy::setPoint(PyObject *args)
00598 {
00599 unsigned long index;
00600 PyObject* pnt;
00601 if (!PyArg_ParseTuple(args, "kO!",&index, &(Base::VectorPy::Type), &pnt))
00602 return NULL;
00603
00604 PY_TRY {
00605 getMeshObjectPtr()->setPoint(index, static_cast<Base::VectorPy*>(pnt)->value());
00606 } PY_CATCH;
00607
00608 Py_Return;
00609 }
00610
00611 PyObject* MeshPy::countSegments(PyObject *args)
00612 {
00613 if (!PyArg_ParseTuple(args, ""))
00614 return 0;
00615
00616 unsigned long count = getMeshObjectPtr()->countSegments();
00617 return Py_BuildValue("k",count);
00618 }
00619
00620 PyObject* MeshPy::getSegment(PyObject *args)
00621 {
00622 unsigned long index;
00623 if (!PyArg_ParseTuple(args, "k", &index))
00624 return 0;
00625
00626 unsigned long count = getMeshObjectPtr()->countSegments();
00627 if (index >= count) {
00628 PyErr_SetString(PyExc_IndexError, "index out of range");
00629 return 0;
00630 }
00631
00632 Py::List ary;
00633 const std::vector<unsigned long>& segm = getMeshObjectPtr()->getSegment(index).getIndices();
00634 for (std::vector<unsigned long>::const_iterator it = segm.begin(); it != segm.end(); ++it) {
00635 ary.append(Py::Int((int)*it));
00636 }
00637
00638 return Py::new_reference_to(ary);
00639 }
00640
00641 PyObject* MeshPy::getSeparateComponents(PyObject *args)
00642 {
00643 if (!PyArg_ParseTuple(args, ""))
00644 return NULL;
00645
00646 Py::List meshesList;
00647 std::vector<std::vector<unsigned long> > segs;
00648 segs = getMeshObjectPtr()->getComponents();
00649 for (unsigned int i=0; i<segs.size(); i++) {
00650 MeshObject* mesh = getMeshObjectPtr()->meshFromSegment(segs[i]);
00651 meshesList.append(Py::Object(new MeshPy(mesh),true));
00652 }
00653 return Py::new_reference_to(meshesList);
00654 }
00655
00656 PyObject* MeshPy::getFacetSelection(PyObject *args)
00657 {
00658 if (!PyArg_ParseTuple(args, ""))
00659 return 0;
00660
00661 Py::List ary;
00662 std::vector<unsigned long> facets;
00663 getMeshObjectPtr()->getFacetsFromSelection(facets);
00664 for (std::vector<unsigned long>::const_iterator it = facets.begin(); it != facets.end(); ++it) {
00665 ary.append(Py::Int((int)*it));
00666 }
00667
00668 return Py::new_reference_to(ary);
00669 }
00670
00671 PyObject* MeshPy::getPointSelection(PyObject *args)
00672 {
00673 if (!PyArg_ParseTuple(args, ""))
00674 return 0;
00675
00676 Py::List ary;
00677 std::vector<unsigned long> points;
00678 getMeshObjectPtr()->getPointsFromSelection(points);
00679 for (std::vector<unsigned long>::const_iterator it = points.begin(); it != points.end(); ++it) {
00680 ary.append(Py::Int((int)*it));
00681 }
00682
00683 return Py::new_reference_to(ary);
00684 }
00685
00686 PyObject* MeshPy::meshFromSegment(PyObject *args)
00687 {
00688 PyObject* list;
00689 if (!PyArg_ParseTuple(args, "O!", &PyList_Type, &list))
00690 return 0;
00691
00692 std::vector<unsigned long> segment;
00693 Py::List ary(list);
00694 for (Py::List::iterator it = ary.begin(); it != ary.end(); ++it) {
00695 Py::Int f(*it);
00696 segment.push_back((long)f);
00697 }
00698
00699
00700 MeshObject* mesh = getMeshObjectPtr()->meshFromSegment(segment);
00701 return new MeshPy(mesh);
00702 }
00703
00704 PyObject* MeshPy::clear(PyObject *args)
00705 {
00706 if (!PyArg_ParseTuple(args, ""))
00707 return NULL;
00708 getMeshObjectPtr()->clear();
00709 Py_Return;
00710 }
00711
00712 PyObject* MeshPy::isSolid(PyObject *args)
00713 {
00714 if (!PyArg_ParseTuple(args, ""))
00715 return NULL;
00716 bool ok = getMeshObjectPtr()->isSolid();
00717 return Py_BuildValue("O", (ok ? Py_True : Py_False));
00718 }
00719
00720 PyObject* MeshPy::hasNonManifolds(PyObject *args)
00721 {
00722 if (!PyArg_ParseTuple(args, ""))
00723 return NULL;
00724 bool ok = getMeshObjectPtr()->hasNonManifolds();
00725 return Py_BuildValue("O", (ok ? Py_True : Py_False));
00726 }
00727
00728 PyObject* MeshPy::removeNonManifolds(PyObject *args)
00729 {
00730 if (!PyArg_ParseTuple(args, ""))
00731 return NULL;
00732 getMeshObjectPtr()->removeNonManifolds();
00733 Py_Return
00734 }
00735
00736 PyObject* MeshPy::hasSelfIntersections(PyObject *args)
00737 {
00738 if (!PyArg_ParseTuple(args, ""))
00739 return NULL;
00740 bool ok = getMeshObjectPtr()->hasSelfIntersections();
00741 return Py_BuildValue("O", (ok ? Py_True : Py_False));
00742 }
00743
00744 PyObject* MeshPy::fixSelfIntersections(PyObject *args)
00745 {
00746 if (!PyArg_ParseTuple(args, ""))
00747 return NULL;
00748 try {
00749 getMeshObjectPtr()->removeSelfIntersections();
00750 }
00751 catch (const Base::Exception& e) {
00752 PyErr_SetString(PyExc_Exception, e.what());
00753 return NULL;
00754 }
00755 Py_Return;
00756 }
00757
00758 PyObject* MeshPy::removeFoldsOnSurface(PyObject *args)
00759 {
00760 if (!PyArg_ParseTuple(args, ""))
00761 return NULL;
00762 try {
00763 getMeshObjectPtr()->removeFoldsOnSurface();
00764 }
00765 catch (const Base::Exception& e) {
00766 PyErr_SetString(PyExc_Exception, e.what());
00767 return NULL;
00768 }
00769 Py_Return;
00770 }
00771
00772 PyObject* MeshPy::flipNormals(PyObject *args)
00773 {
00774 if (!PyArg_ParseTuple(args, ""))
00775 return NULL;
00776
00777 PY_TRY {
00778 MeshPropertyLock lock(this->parentProperty);
00779 getMeshObjectPtr()->flipNormals();
00780 } PY_CATCH;
00781
00782 Py_Return;
00783 }
00784
00785 PyObject* MeshPy::hasNonUniformOrientedFacets(PyObject *args)
00786 {
00787 if (!PyArg_ParseTuple(args, ""))
00788 return NULL;
00789 bool ok = getMeshObjectPtr()->countNonUniformOrientedFacets() > 0;
00790 return Py_BuildValue("O", (ok ? Py_True : Py_False));
00791 }
00792
00793 PyObject* MeshPy::countNonUniformOrientedFacets(PyObject *args)
00794 {
00795 if (!PyArg_ParseTuple(args, ""))
00796 return NULL;
00797 unsigned long count = getMeshObjectPtr()->countNonUniformOrientedFacets();
00798 return Py_BuildValue("k", count);
00799 }
00800
00801 PyObject* MeshPy::harmonizeNormals(PyObject *args)
00802 {
00803 if (!PyArg_ParseTuple(args, ""))
00804 return NULL;
00805
00806 PY_TRY {
00807 MeshPropertyLock lock(this->parentProperty);
00808 getMeshObjectPtr()->harmonizeNormals();
00809 } PY_CATCH;
00810
00811 Py_Return;
00812 }
00813
00814 PyObject* MeshPy::countComponents(PyObject *args)
00815 {
00816 if (!PyArg_ParseTuple(args, ""))
00817 return NULL;
00818
00819 unsigned long count = getMeshObjectPtr()->countComponents();
00820 return Py_BuildValue("k",count);
00821 }
00822
00823 PyObject* MeshPy::removeComponents(PyObject *args)
00824 {
00825 unsigned long count;
00826 if (!PyArg_ParseTuple(args, "k", &count))
00827 return NULL;
00828
00829 PY_TRY {
00830 if (count > 0) {
00831 getMeshObjectPtr()->removeComponents(count);
00832 }
00833 } PY_CATCH;
00834
00835 Py_Return;
00836 }
00837
00838 PyObject* MeshPy::fillupHoles(PyObject *args)
00839 {
00840 unsigned long len;
00841 int level = 0;
00842 float max_area = 0.0f;
00843 if (!PyArg_ParseTuple(args, "k|if", &len,&level,&max_area))
00844 return NULL;
00845 try {
00846 std::auto_ptr<MeshCore::AbstractPolygonTriangulator> tria;
00847 if (max_area > 0.0f) {
00848 tria = std::auto_ptr<MeshCore::AbstractPolygonTriangulator>
00849 (new MeshCore::ConstraintDelaunayTriangulator(max_area));
00850 }
00851 else {
00852 tria = std::auto_ptr<MeshCore::AbstractPolygonTriangulator>
00853 (new MeshCore::FlatTriangulator());
00854 }
00855
00856 MeshPropertyLock lock(this->parentProperty);
00857 getMeshObjectPtr()->fillupHoles(len, level, *tria);
00858 }
00859 catch (const Base::Exception& e) {
00860 PyErr_SetString(PyExc_Exception, e.what());
00861 return NULL;
00862 }
00863
00864 Py_Return;
00865 }
00866
00867 PyObject* MeshPy::fixIndices(PyObject *args)
00868 {
00869 if (!PyArg_ParseTuple(args, ""))
00870 return NULL;
00871
00872 PY_TRY {
00873 getMeshObjectPtr()->validateIndices();
00874 } PY_CATCH;
00875
00876 Py_Return;
00877 }
00878
00879 PyObject* MeshPy::fixDeformations(PyObject *args)
00880 {
00881 float fMaxAngle;
00882 if (!PyArg_ParseTuple(args, "f", &fMaxAngle))
00883 return NULL;
00884
00885 PY_TRY {
00886 getMeshObjectPtr()->validateDeformations(fMaxAngle);
00887 } PY_CATCH;
00888
00889 Py_Return;
00890 }
00891
00892 PyObject* MeshPy::fixDegenerations(PyObject *args)
00893 {
00894 if (!PyArg_ParseTuple(args, ""))
00895 return NULL;
00896
00897 PY_TRY {
00898 getMeshObjectPtr()->validateDegenerations();
00899 } PY_CATCH;
00900
00901 Py_Return;
00902 }
00903
00904 PyObject* MeshPy::removeDuplicatedPoints(PyObject *args)
00905 {
00906 if (!PyArg_ParseTuple(args, ""))
00907 return NULL;
00908
00909 PY_TRY {
00910 getMeshObjectPtr()->removeDuplicatedPoints();
00911 } PY_CATCH;
00912
00913 Py_Return;
00914 }
00915
00916 PyObject* MeshPy::removeDuplicatedFacets(PyObject *args)
00917 {
00918 if (!PyArg_ParseTuple(args, ""))
00919 return NULL;
00920
00921 PY_TRY {
00922 getMeshObjectPtr()->removeDuplicatedFacets();
00923 } PY_CATCH;
00924
00925 Py_Return;
00926 }
00927
00928 PyObject* MeshPy::refine(PyObject *args)
00929 {
00930 if (!PyArg_ParseTuple(args, ""))
00931 return NULL;
00932
00933 PY_TRY {
00934 getMeshObjectPtr()->refine();
00935 } PY_CATCH;
00936
00937 Py_Return;
00938 }
00939
00940 PyObject* MeshPy::optimizeTopology(PyObject *args)
00941 {
00942 float fMaxAngle=-1.0f;
00943 if (!PyArg_ParseTuple(args, "|f; specify the maximum allowed angle between the normals of two adjacent facets", &fMaxAngle))
00944 return NULL;
00945
00946 PY_TRY {
00947 MeshPropertyLock lock(this->parentProperty);
00948 getMeshObjectPtr()->optimizeTopology(fMaxAngle);
00949 } PY_CATCH;
00950
00951 Py_Return;
00952 }
00953
00954 PyObject* MeshPy::optimizeEdges(PyObject *args)
00955 {
00956 if (!PyArg_ParseTuple(args, ""))
00957 return NULL;
00958
00959 PY_TRY {
00960 MeshPropertyLock lock(this->parentProperty);
00961 getMeshObjectPtr()->optimizeEdges();
00962 } PY_CATCH;
00963
00964 Py_Return;
00965 }
00966
00967 PyObject* MeshPy::splitEdges(PyObject *args)
00968 {
00969 if (!PyArg_ParseTuple(args, ""))
00970 return NULL;
00971
00972 PY_TRY {
00973 getMeshObjectPtr()->splitEdges();
00974 } PY_CATCH;
00975
00976 Py_Return;
00977 }
00978
00979 PyObject* MeshPy::splitEdge(PyObject *args)
00980 {
00981 unsigned long facet, neighbour;
00982 PyObject* vertex;
00983 if (!PyArg_ParseTuple(args, "kkO!", &facet, &neighbour, &Base::VectorPy::Type, &vertex))
00984 return NULL;
00985
00986 Base::VectorPy *pcObject = static_cast<Base::VectorPy*>(vertex);
00987 Base::Vector3d* val = pcObject->getVectorPtr();
00988 Base::Vector3f v((float)val->x,(float)val->y,(float)val->z);
00989
00990 const MeshCore::MeshKernel& kernel = getMeshObjectPtr()->getKernel();
00991 PY_TRY {
00992 if (facet < 0 || facet >= kernel.CountFacets()) {
00993 PyErr_SetString(PyExc_IndexError, "Facet index out of range");
00994 return NULL;
00995 }
00996 if (neighbour < 0 || neighbour >= kernel.CountFacets()) {
00997 PyErr_SetString(PyExc_IndexError, "Facet index out of range");
00998 return NULL;
00999 }
01000
01001 const MeshCore::MeshFacet& rclF = kernel.GetFacets()[facet];
01002 if (rclF._aulNeighbours[0] != neighbour && rclF._aulNeighbours[1] != neighbour &&
01003 rclF._aulNeighbours[2] != neighbour) {
01004 PyErr_SetString(PyExc_IndexError, "No adjacent facets");
01005 return NULL;
01006 }
01007
01008 getMeshObjectPtr()->splitEdge(facet, neighbour, v);
01009 } PY_CATCH;
01010
01011 Py_Return;
01012 }
01013
01014 PyObject* MeshPy::splitFacet(PyObject *args)
01015 {
01016 unsigned long facet;
01017 PyObject* vertex1;
01018 PyObject* vertex2;
01019 if (!PyArg_ParseTuple(args, "kO!O!", &facet, &Base::VectorPy::Type, &vertex1,
01020 &Base::VectorPy::Type, &vertex2))
01021 return NULL;
01022
01023 Base::VectorPy *pcObject = static_cast<Base::VectorPy*>(vertex1);
01024 Base::Vector3d* val = pcObject->getVectorPtr();
01025 Base::Vector3f v1((float)val->x,(float)val->y,(float)val->z);
01026
01027 pcObject = static_cast<Base::VectorPy*>(vertex2);
01028 val = pcObject->getVectorPtr();
01029 Base::Vector3f v2((float)val->x,(float)val->y,(float)val->z);
01030
01031 const MeshCore::MeshKernel& kernel = getMeshObjectPtr()->getKernel();
01032 PY_TRY {
01033 if (facet < 0 || facet >= kernel.CountFacets()) {
01034 PyErr_SetString(PyExc_IndexError, "Facet index out of range");
01035 return NULL;
01036 }
01037
01038 getMeshObjectPtr()->splitFacet(facet, v1, v2);
01039 } PY_CATCH;
01040
01041 Py_Return;
01042 }
01043
01044 PyObject* MeshPy::swapEdge(PyObject *args)
01045 {
01046 unsigned long facet, neighbour;
01047 if (!PyArg_ParseTuple(args, "kk", &facet, &neighbour))
01048 return NULL;
01049
01050 const MeshCore::MeshKernel& kernel = getMeshObjectPtr()->getKernel();
01051 PY_TRY {
01052 if (facet < 0 || facet >= kernel.CountFacets()) {
01053 PyErr_SetString(PyExc_IndexError, "Facet index out of range");
01054 return NULL;
01055 }
01056 if (neighbour < 0 || neighbour >= kernel.CountFacets()) {
01057 PyErr_SetString(PyExc_IndexError, "Facet index out of range");
01058 return NULL;
01059 }
01060
01061 const MeshCore::MeshFacet& rclF = kernel.GetFacets()[facet];
01062 if (rclF._aulNeighbours[0] != neighbour && rclF._aulNeighbours[1] != neighbour &&
01063 rclF._aulNeighbours[2] != neighbour) {
01064 PyErr_SetString(PyExc_IndexError, "No adjacent facets");
01065 return NULL;
01066 }
01067
01068 getMeshObjectPtr()->swapEdge(facet, neighbour);
01069 } PY_CATCH;
01070
01071 Py_Return;
01072 }
01073
01074 PyObject* MeshPy::collapseEdge(PyObject *args)
01075 {
01076 unsigned long facet, neighbour;
01077 if (!PyArg_ParseTuple(args, "kk", &facet, &neighbour))
01078 return NULL;
01079
01080 const MeshCore::MeshKernel& kernel = getMeshObjectPtr()->getKernel();
01081 PY_TRY {
01082 if (facet < 0 || facet >= kernel.CountFacets()) {
01083 PyErr_SetString(PyExc_IndexError, "Facet index out of range");
01084 return NULL;
01085 }
01086 if (neighbour < 0 || neighbour >= kernel.CountFacets()) {
01087 PyErr_SetString(PyExc_IndexError, "Facet index out of range");
01088 return NULL;
01089 }
01090
01091 const MeshCore::MeshFacet& rclF = kernel.GetFacets()[facet];
01092 if (rclF._aulNeighbours[0] != neighbour && rclF._aulNeighbours[1] != neighbour &&
01093 rclF._aulNeighbours[2] != neighbour) {
01094 PyErr_SetString(PyExc_IndexError, "No adjacent facets");
01095 return NULL;
01096 }
01097
01098 getMeshObjectPtr()->collapseEdge(facet, neighbour);
01099 } PY_CATCH;
01100
01101 Py_Return;
01102 }
01103
01104 PyObject* MeshPy::collapseFacet(PyObject *args)
01105 {
01106 unsigned long facet;
01107 if (!PyArg_ParseTuple(args, "k", &facet))
01108 return NULL;
01109
01110 PY_TRY {
01111 if (facet < 0 || facet >= getMeshObjectPtr()->countFacets()) {
01112 PyErr_SetString(PyExc_IndexError, "Facet index out of range");
01113 return NULL;
01114 }
01115
01116 getMeshObjectPtr()->collapseFacet(facet);
01117 } PY_CATCH;
01118
01119 Py_Return;
01120 }
01121
01122 PyObject* MeshPy::insertVertex(PyObject *args)
01123 {
01124 unsigned long facet;
01125 PyObject* vertex;
01126 if (!PyArg_ParseTuple(args, "kO!", &facet, &Base::VectorPy::Type, &vertex))
01127 return NULL;
01128
01129 Base::VectorPy *pcObject = static_cast<Base::VectorPy*>(vertex);
01130 Base::Vector3d* val = pcObject->getVectorPtr();
01131 Base::Vector3f v((float)val->x,(float)val->y,(float)val->z);
01132
01133 PY_TRY {
01134 if (facet < 0 || facet >= getMeshObjectPtr()->countFacets()) {
01135 PyErr_SetString(PyExc_IndexError, "Facet index out of range");
01136 return NULL;
01137 }
01138
01139 getMeshObjectPtr()->insertVertex(facet, v);
01140 } PY_CATCH;
01141
01142 Py_Return;
01143 }
01144
01145 PyObject* MeshPy::snapVertex(PyObject *args)
01146 {
01147 unsigned long facet;
01148 PyObject* vertex;
01149 if (!PyArg_ParseTuple(args, "kO!", &facet, &Base::VectorPy::Type, &vertex))
01150 return NULL;
01151
01152 Base::VectorPy *pcObject = static_cast<Base::VectorPy*>(vertex);
01153 Base::Vector3d* val = pcObject->getVectorPtr();
01154 Base::Vector3f v((float)val->x,(float)val->y,(float)val->z);
01155
01156 PY_TRY {
01157 if (facet < 0 || facet >= getMeshObjectPtr()->countFacets()) {
01158 PyErr_SetString(PyExc_IndexError, "Facet index out of range");
01159 return NULL;
01160 }
01161
01162 getMeshObjectPtr()->snapVertex(facet, v);
01163 } PY_CATCH;
01164
01165 Py_Return;
01166 }
01167
01168 PyObject* MeshPy::printInfo(PyObject *args)
01169 {
01170 if (!PyArg_ParseTuple(args, ""))
01171 return NULL;
01172 return Py_BuildValue("s", getMeshObjectPtr()->topologyInfo().c_str());
01173 }
01174
01175 PyObject* MeshPy::collapseFacets(PyObject *args)
01176 {
01177 PyObject *pcObj=0;
01178 if (!PyArg_ParseTuple(args, "O", &pcObj))
01179 return 0;
01180
01181
01182 if (PyList_Check(pcObj)) {
01183 std::vector<unsigned long> facets;
01184 for (int i = 0; i < PyList_Size(pcObj); i++) {
01185 PyObject *idx = PyList_GetItem(pcObj, i);
01186 if (PyInt_Check(idx)){
01187 unsigned long iIdx = PyInt_AsLong(idx);
01188 facets.push_back(iIdx);
01189 }
01190 else {
01191 Py_Error(PyExc_Exception, "list of integers needed");
01192 }
01193 }
01194
01195 getMeshObjectPtr()->collapseFacets(facets);
01196 }
01197 else {
01198 Py_Error(PyExc_Exception, "List of Integers needed");
01199 }
01200
01201 Py_Return;
01202 }
01203
01204 PyObject* MeshPy::foraminate(PyObject *args)
01205 {
01206 PyObject* pnt_p;
01207 PyObject* dir_p;
01208 if (!PyArg_ParseTuple(args, "OO", &pnt_p, &dir_p))
01209 return NULL;
01210
01211 try {
01212 Py::Tuple pnt_t(pnt_p);
01213 Py::Tuple dir_t(dir_p);
01214 Base::Vector3f pnt((float)Py::Float(pnt_t.getItem(0)),
01215 (float)Py::Float(pnt_t.getItem(1)),
01216 (float)Py::Float(pnt_t.getItem(2)));
01217 Base::Vector3f dir((float)Py::Float(dir_t.getItem(0)),
01218 (float)Py::Float(dir_t.getItem(1)),
01219 (float)Py::Float(dir_t.getItem(2)));
01220
01221 Base::Vector3f res;
01222 MeshCore::MeshFacetIterator f_it(getMeshObjectPtr()->getKernel());
01223 int index = 0;
01224
01225 Py::Dict dict;
01226 for (f_it.Begin(); f_it.More(); f_it.Next(), index++) {
01227 if (f_it->Foraminate(pnt, dir, res)) {
01228 Py::Tuple tuple(3);
01229 tuple.setItem(0, Py::Float(res.x));
01230 tuple.setItem(1, Py::Float(res.y));
01231 tuple.setItem(2, Py::Float(res.z));
01232 dict.setItem(Py::Int(index), tuple);
01233 }
01234 }
01235
01236 return Py::new_reference_to(dict);
01237 }
01238 catch (const Py::Exception&) {
01239 return 0;
01240 }
01241 }
01242
01243 PyObject* MeshPy::smooth(PyObject *args)
01244 {
01245 int iter=1;
01246 float d_max=FLOAT_MAX;
01247 if (!PyArg_ParseTuple(args, "|if", &iter,&d_max))
01248 return NULL;
01249
01250 PY_TRY {
01251 MeshPropertyLock lock(this->parentProperty);
01252 getMeshObjectPtr()->smooth(iter, d_max);
01253 } PY_CATCH;
01254
01255 Py_Return;
01256 }
01257
01258 PyObject* MeshPy::nearestFacetOnRay(PyObject *args)
01259 {
01260 PyObject* pnt_p;
01261 PyObject* dir_p;
01262 if (!PyArg_ParseTuple(args, "OO", &pnt_p, &dir_p))
01263 return NULL;
01264
01265 try {
01266 Py::Tuple pnt_t(pnt_p);
01267 Py::Tuple dir_t(dir_p);
01268 Py::Dict dict;
01269 Base::Vector3f pnt((float)Py::Float(pnt_t.getItem(0)),
01270 (float)Py::Float(pnt_t.getItem(1)),
01271 (float)Py::Float(pnt_t.getItem(2)));
01272 Base::Vector3f dir((float)Py::Float(dir_t.getItem(0)),
01273 (float)Py::Float(dir_t.getItem(1)),
01274 (float)Py::Float(dir_t.getItem(2)));
01275
01276 unsigned long index = 0;
01277 Base::Vector3f res;
01278 MeshCore::MeshAlgorithm alg(getMeshObjectPtr()->getKernel());
01279
01280 #if 0 // for testing only
01281 MeshCore::MeshFacetGrid grid(getMeshObjectPtr()->getKernel(),10);
01282
01283 if (alg.NearestFacetOnRay(pnt, dir, grid, res, index) ||
01284 alg.NearestFacetOnRay(pnt, -dir, grid, res, index)) {
01285 #else
01286 if (alg.NearestFacetOnRay(pnt, dir, res, index)) {
01287 #endif
01288 Py::Tuple tuple(3);
01289 tuple.setItem(0, Py::Float(res.x));
01290 tuple.setItem(1, Py::Float(res.y));
01291 tuple.setItem(2, Py::Float(res.z));
01292 dict.setItem(Py::Int((int)index), tuple);
01293 }
01294
01295 #if 0 // for testing only
01296 char szBuf[200];
01297 std::ofstream str("grid_test.iv");
01298 Base::InventorBuilder builder(str);
01299 MeshCore::MeshGridIterator g_it(grid);
01300 for (g_it.Init(); g_it.More(); g_it.Next()) {
01301 Base::BoundBox3f box = g_it.GetBoundBox();
01302 unsigned long uX,uY,uZ;
01303 g_it.GetGridPos(uX,uY,uZ);
01304 builder.addBoundingBox(Base::Vector3f(box.MinX,box.MinY, box.MinZ),
01305 Base::Vector3f(box.MaxX,box.MaxY, box.MaxZ));
01306 sprintf(szBuf, "(%lu,%lu,%lu)", uX, uY, uZ);
01307 builder.addText(box.CalcCenter(), szBuf);
01308 }
01309 builder.addSingleArrow(pnt-20.0f*dir, pnt+10.0f*dir);
01310 builder.close();
01311 str.close();
01312 #endif
01313
01314 return Py::new_reference_to(dict);
01315 }
01316 catch (const Py::Exception&) {
01317 return 0;
01318 }
01319 }
01320
01321 PyObject* MeshPy::getPlanes(PyObject *args)
01322 {
01323 float dev;
01324 if (!PyArg_ParseTuple(args, "f",&dev))
01325 return NULL;
01326
01327 Mesh::MeshObject* mesh = getMeshObjectPtr();
01328 std::vector<Mesh::Segment> segments = mesh->getSegmentsFromType
01329 (Mesh::MeshObject::PLANE, Mesh::Segment(mesh,false), dev);
01330
01331 Py::List s;
01332 for (std::vector<Mesh::Segment>::iterator it = segments.begin(); it != segments.end(); ++it) {
01333 const std::vector<unsigned long>& segm = it->getIndices();
01334 Py::List ary;
01335 for (std::vector<unsigned long>::const_iterator jt = segm.begin(); jt != segm.end(); ++jt) {
01336 ary.append(Py::Int((int)*jt));
01337 }
01338 s.append(ary);
01339 }
01340
01341 return Py::new_reference_to(s);
01342 }
01343
01344 Py::Int MeshPy::getCountPoints(void) const
01345 {
01346 return Py::Int((long)getMeshObjectPtr()->countPoints());
01347 }
01348
01349 Py::Int MeshPy::getCountFacets(void) const
01350 {
01351 return Py::Int((long)getMeshObjectPtr()->countFacets());
01352 }
01353
01354 Py::Float MeshPy::getArea(void) const
01355 {
01356 return Py::Float((long)getMeshObjectPtr()->getSurface());
01357 }
01358
01359 Py::Float MeshPy::getVolume(void) const
01360 {
01361 return Py::Float((long)getMeshObjectPtr()->getVolume());
01362 }
01363
01364 PyObject *MeshPy::getCustomAttributes(const char* attr) const
01365 {
01366 return 0;
01367 }
01368
01369 int MeshPy::setCustomAttributes(const char* attr, PyObject *obj)
01370 {
01371 return 0;
01372 }
01373
01374 Py::List MeshPy::getPoints(void) const
01375 {
01376 Py::List PointList;
01377 unsigned int Index=0;
01378 MeshObject* mesh = getMeshObjectPtr();
01379 for (MeshObject::const_point_iterator it = mesh->points_begin(); it != mesh->points_end(); ++it) {
01380 PointList.append(Py::Object(new MeshPointPy(new MeshPoint(*it,getMeshObjectPtr(),Index++)), true));
01381 }
01382 return PointList;
01383 }
01384
01385 Py::List MeshPy::getFacets(void) const
01386 {
01387 Py::List FacetList;
01388 MeshObject* mesh = getMeshObjectPtr();
01389 for (MeshObject::const_facet_iterator it = mesh->facets_begin(); it != mesh->facets_end(); ++it) {
01390 FacetList.append(Py::Object(new FacetPy(new Facet(*it)), true));
01391 }
01392 return FacetList;
01393 }
01394
01395 Py::Tuple MeshPy::getTopology(void) const
01396 {
01397 std::vector<Base::Vector3d> Points;
01398 std::vector<Data::ComplexGeoData::Facet> Facets;
01399 getMeshObjectPtr()->getFaces(Points, Facets, 0.0f);
01400 Py::Tuple tuple(2);
01401 Py::List vertex;
01402 for (std::vector<Base::Vector3d>::const_iterator it = Points.begin();
01403 it != Points.end(); ++it)
01404 vertex.append(Py::Object(new Base::VectorPy(*it)));
01405 tuple.setItem(0, vertex);
01406 Py::List facet;
01407 for (std::vector<Data::ComplexGeoData::Facet>::const_iterator
01408 it = Facets.begin(); it != Facets.end(); ++it) {
01409 Py::Tuple f(3);
01410 f.setItem(0,Py::Int((int)it->I1));
01411 f.setItem(1,Py::Int((int)it->I2));
01412 f.setItem(2,Py::Int((int)it->I3));
01413 facet.append(f);
01414 }
01415 tuple.setItem(1, facet);
01416 return tuple;
01417 }
01418
01419