AppReverseEngineeringPy.cpp

Go to the documentation of this file.
00001 /***************************************************************************
00002  *   Copyright (c) 2008 Jürgen Riegel (juergen.riegel@web.de)              *
00003  *                                                                         *
00004  *   This file is part of the FreeCAD CAx development system.              *
00005  *                                                                         *
00006  *   This library is free software; you can redistribute it and/or         *
00007  *   modify it under the terms of the GNU Library General Public           *
00008  *   License as published by the Free Software Foundation; either          *
00009  *   version 2 of the License, or (at your option) any later version.      *
00010  *                                                                         *
00011  *   This library  is distributed in the hope that it will be useful,      *
00012  *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
00013  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
00014  *   GNU Library General Public License for more details.                  *
00015  *                                                                         *
00016  *   You should have received a copy of the GNU Library General Public     *
00017  *   License along with this library; see the file COPYING.LIB. If not,    *
00018  *   write to the Free Software Foundation, Inc., 59 Temple Place,         *
00019  *   Suite 330, Boston, MA  02111-1307, USA                                *
00020  *                                                                         *
00021  ***************************************************************************/
00022 
00023 
00024 #include "PreCompiled.h"
00025 #ifndef _PreComp_
00026 # include <TColgp_Array1OfPnt.hxx>
00027 # include <Handle_Geom_BSplineSurface.hxx>
00028 #endif
00029 
00030 #include <CXX/Objects.hxx>
00031 #include <Base/PyObjectBase.h>
00032 #include <Base/Console.h>
00033 
00034 #include <Mod/Part/App/BSplineSurfacePy.h>
00035 
00036 #include "ApproxSurface.h"
00037 
00038 using namespace Reen;
00039 
00040 
00041 /* module functions */
00042 static PyObject * approxSurface(PyObject *self, PyObject *args)
00043 {
00044     PyObject *o;
00045     int orderU=4,orderV=4;
00046     int pointsU=6,pointsV=6;
00047     if (!PyArg_ParseTuple(args, "O|iiii",&o,&orderU,&orderV,&pointsU,&pointsV))
00048         return NULL;
00049 
00050     PY_TRY {
00051         Py::List l(o);
00052         TColgp_Array1OfPnt clPoints(0, l.size()-1);
00053 
00054         int index=0;
00055         for (Py::List::iterator it = l.begin(); it != l.end(); ++it) {
00056             Py::Tuple t(*it);
00057             clPoints(index++) = gp_Pnt(
00058                 (double)Py::Float(t.getItem(0)),
00059                 (double)Py::Float(t.getItem(1)),
00060                 (double)Py::Float(t.getItem(2)));
00061         }
00062 
00063         Reen::BSplineParameterCorrection pc(orderU,orderV,pointsU,pointsV);
00064         Handle_Geom_BSplineSurface hSurf;
00065 
00066         //pc.EnableSmoothing(true, 0.1f, 0.5f, 0.2f, 0.3f);
00067         pc.EnableSmoothing(true, 0.1f, 1.0f, 0.0f, 0.0f);
00068         hSurf = pc.CreateSurface(clPoints, 5, true, 1.0);
00069         if (!hSurf.IsNull()) {
00070             return new Part::BSplineSurfacePy(new Part::GeomBSplineSurface(hSurf));
00071         }
00072 
00073         PyErr_SetString(PyExc_Exception, "Computation of B-Spline surface failed");
00074         return 0;
00075     } PY_CATCH;
00076 }
00077 
00078 /* registration table  */
00079 struct PyMethodDef ReverseEngineering_methods[] = {
00080     {"approxSurface"   , approxSurface,  1},
00081     {NULL, NULL}        /* end of table marker */
00082 };

Generated on Wed Nov 23 18:59:56 2011 for FreeCAD by  doxygen 1.6.1