Пример #1
0
Py::Object BezierCurve2dPy::getEndPoint(void) const
{
    Handle_Geom_BezierCurve c = Handle_Geom_BezierCurve::DownCast
        (getGeometryPtr()->handle());
    gp_Pnt pnt = c->EndPoint();
    return Py::Vector(Base::Vector3d(pnt.X(), pnt.Y(), pnt.Z()));
}
Пример #2
0
PyObject* BezierCurve2dPy::isClosed(PyObject *args)
{
    if (!PyArg_ParseTuple(args, ""))
        return 0;
    Handle_Geom_BezierCurve curve = Handle_Geom_BezierCurve::DownCast
        (getGeometryPtr()->handle());
    Standard_Boolean val = curve->IsClosed();
    return PyBool_FromLong(val ? 1 : 0);
}
Пример #3
0
PyObject* BezierCurve2dPy::increase(PyObject * args)
{
    int degree;
    if (!PyArg_ParseTuple(args, "i", &degree))
        return 0;
    Handle_Geom_BezierCurve curve = Handle_Geom_BezierCurve::DownCast
        (getGeometryPtr()->handle());
    curve->Increase(degree);
    Py_Return;
}
BezierSegment::BezierSegment(const TopoDS_Edge &e)
{
    geomType = BEZIER;
    occEdge = e;
    BRepAdaptor_Curve c(e);
    Handle_Geom_BezierCurve bez = c.Bezier();
    poles = bez->NbPoles();
    degree = bez->Degree();
    if (poles > 4)  {
        Base::Console().Log("Warning - BezierSegment has degree > 3: %d\n",degree);
    }
    for (int i = 1; i <= poles; ++i) {
        gp_Pnt controlPoint = bez->Pole(i);
        pnts.push_back(Base::Vector2d(controlPoint.X(), controlPoint.Y()));
    }
}
Пример #5
0
PyObject* BezierCurve2dPy::segment(PyObject * args)
{
    double u1,u2;
    if (!PyArg_ParseTuple(args, "dd", &u1,&u2))
        return 0;
    try {
        Handle_Geom_BezierCurve curve = Handle_Geom_BezierCurve::DownCast
            (getGeometryPtr()->handle());
        curve->Segment(u1,u2);
        Py_Return;
    }
    catch (Standard_Failure) {
        Handle_Standard_Failure e = Standard_Failure::Caught();
        PyErr_SetString(PartExceptionOCCError, e->GetMessageString());
        return 0;
    }
}
Пример #6
0
PyObject* BezierCurve2dPy::removePole(PyObject * args)
{
    int index;
    if (!PyArg_ParseTuple(args, "i", &index))
        return 0;
    try {
        Handle_Geom_BezierCurve curve = Handle_Geom_BezierCurve::DownCast
            (getGeometryPtr()->handle());
        curve->RemovePole(index);
        Py_Return;
    }
    catch (Standard_Failure) {
        Handle_Standard_Failure e = Standard_Failure::Caught();
        PyErr_SetString(PartExceptionOCCError, e->GetMessageString());
        return 0;
    }
}
Пример #7
0
PyObject* BezierCurve2dPy::getResolution(PyObject* args)
{
    double tol;
    if (!PyArg_ParseTuple(args, "d", &tol))
        return 0;
    try {
        Handle_Geom_BezierCurve curve = Handle_Geom_BezierCurve::DownCast
            (getGeometryPtr()->handle());
        double utol;
        curve->Resolution(tol,utol);
        return Py_BuildValue("d",utol);
    }
    catch (Standard_Failure) {
        Handle_Standard_Failure e = Standard_Failure::Caught();
        PyErr_SetString(PartExceptionOCCError, e->GetMessageString());
        return 0;
    }
}
Пример #8
0
PyObject* BezierCurve2dPy::getWeight(PyObject * args)
{
    int index;
    if (!PyArg_ParseTuple(args, "i", &index))
        return 0;
    try {
        Handle_Geom_BezierCurve curve = Handle_Geom_BezierCurve::DownCast
            (getGeometryPtr()->handle());
        Standard_OutOfRange_Raise_if
            (index < 1 || index > curve->NbPoles() , "Weight index out of range");
        double weight = curve->Weight(index);
        return Py_BuildValue("d", weight);
    }
    catch (Standard_Failure) {
        Handle_Standard_Failure e = Standard_Failure::Caught();
        PyErr_SetString(PartExceptionOCCError, e->GetMessageString());
        return 0;
    }
}
Пример #9
0
PyObject* BezierCurve2dPy::insertPoleBefore(PyObject * args)
{
    int index;
    double weight=1.0;
    PyObject* p;
    if (!PyArg_ParseTuple(args, "iO!|d", &index, &(Base::VectorPy::Type), &p, &weight))
        return 0;
    Base::Vector3d vec = static_cast<Base::VectorPy*>(p)->value();
    gp_Pnt pnt(vec.x, vec.y, vec.z);
    try {
        Handle_Geom_BezierCurve curve = Handle_Geom_BezierCurve::DownCast
            (getGeometryPtr()->handle());
        curve->InsertPoleBefore(index,pnt,weight);
        Py_Return;
    }
    catch (Standard_Failure) {
        Handle_Standard_Failure e = Standard_Failure::Caught();
        PyErr_SetString(PartExceptionOCCError, e->GetMessageString());
        return 0;
    }
}
Пример #10
0
PyObject* BezierCurve2dPy::getPole(PyObject * args)
{
    int index;
    if (!PyArg_ParseTuple(args, "i", &index))
        return 0;
    try {
        Handle_Geom_BezierCurve curve = Handle_Geom_BezierCurve::DownCast
            (getGeometryPtr()->handle());
        Standard_OutOfRange_Raise_if
            (index < 1 || index > curve->NbPoles(), "Pole index out of range");
        gp_Pnt pnt = curve->Pole(index);
        Base::VectorPy* vec = new Base::VectorPy(Base::Vector3d(
            pnt.X(), pnt.Y(), pnt.Z()));
        return vec;
    }
    catch (Standard_Failure) {
        Handle_Standard_Failure e = Standard_Failure::Caught();
        PyErr_SetString(PartExceptionOCCError, e->GetMessageString());
        return 0;
    }
}
Пример #11
0
PyObject* BezierCurve2dPy::getWeights(PyObject * args)
{
    if (!PyArg_ParseTuple(args, ""))
        return 0;
    try {
        Handle_Geom_BezierCurve curve = Handle_Geom_BezierCurve::DownCast
            (getGeometryPtr()->handle());
        TColStd_Array1OfReal w(1,curve->NbPoles());
        curve->Weights(w);
        Py::List weights;
        for (Standard_Integer i=w.Lower(); i<=w.Upper(); i++) {
            weights.append(Py::Float(w(i)));
        }
        return Py::new_reference_to(weights);
    }
    catch (Standard_Failure) {
        Handle_Standard_Failure e = Standard_Failure::Caught();
        PyErr_SetString(PartExceptionOCCError, e->GetMessageString());
        return 0;
    }
}
Пример #12
0
PyObject* BezierCurve2dPy::getPoles(PyObject * args)
{
    if (!PyArg_ParseTuple(args, ""))
        return 0;
    try {
        Handle_Geom_BezierCurve curve = Handle_Geom_BezierCurve::DownCast
            (getGeometryPtr()->handle());
        TColgp_Array1OfPnt p(1,curve->NbPoles());
        curve->Poles(p);
        Py::List poles;
        for (Standard_Integer i=p.Lower(); i<=p.Upper(); i++) {
            gp_Pnt pnt = p(i);
            Base::VectorPy* vec = new Base::VectorPy(Base::Vector3d(
                pnt.X(), pnt.Y(), pnt.Z()));
            poles.append(Py::Object(vec));
        }
        return Py::new_reference_to(poles);
    }
    catch (Standard_Failure) {
        Handle_Standard_Failure e = Standard_Failure::Caught();
        PyErr_SetString(PartExceptionOCCError, e->GetMessageString());
        return 0;
    }
}
Пример #13
0
void SVGOutput::printBSpline(const BRepAdaptor_Curve& c, int id, std::ostream& out)
{
    try {
        std::stringstream str;
        Handle_Geom_BSplineCurve spline = c.BSpline();
        if (spline->Degree() > 3) {
            Standard_Real tol3D = 0.001;
            Standard_Integer maxDegree = 3, maxSegment = 10;
            Handle_BRepAdaptor_HCurve hCurve = new BRepAdaptor_HCurve(c);
            // approximate the curve using a tolerance
            Approx_Curve3d approx(hCurve,tol3D,GeomAbs_C2,maxSegment,maxDegree);
            if (approx.IsDone() && approx.HasResult()) {
                // have the result
                spline = approx.Curve();
            }
        }

        GeomConvert_BSplineCurveToBezierCurve crt(spline);
        Standard_Integer arcs = crt.NbArcs();
        str << "<path d=\"M";
        for (Standard_Integer i=1; i<=arcs; i++) {
            Handle_Geom_BezierCurve bezier = crt.Arc(i);
            Standard_Integer poles = bezier->NbPoles();
            if (bezier->Degree() == 3) {
                if (poles != 4)
                    Standard_Failure::Raise("do it the generic way");
                gp_Pnt p1 = bezier->Pole(1);
                gp_Pnt p2 = bezier->Pole(2);
                gp_Pnt p3 = bezier->Pole(3);
                gp_Pnt p4 = bezier->Pole(4);
                if (i == 1) {
                    str << p1.X() << "," << p1.Y() << " C"
                        << p2.X() << "," << p2.Y() << " "
                        << p3.X() << "," << p3.Y() << " "
                        << p4.X() << "," << p4.Y() << " ";
                }
                else {
                    str << "S"
                        << p3.X() << "," << p3.Y() << " "
                        << p4.X() << "," << p4.Y() << " ";
                }
            }
            else if (bezier->Degree() == 2) {
                if (poles != 3)
                    Standard_Failure::Raise("do it the generic way");
                gp_Pnt p1 = bezier->Pole(1);
                gp_Pnt p2 = bezier->Pole(2);
                gp_Pnt p3 = bezier->Pole(3);
                if (i == 1) {
                    str << p1.X() << "," << p1.Y() << " Q"
                        << p2.X() << "," << p2.Y() << " "
                        << p3.X() << "," << p3.Y() << " ";
                }
                else {
                    str << "T"
                        << p3.X() << "," << p3.Y() << " ";
                }
            }
            else {
                Standard_Failure::Raise("do it the generic way");
            }
        }

        str << "\" />";
        out << str.str();
    }
    catch (Standard_Failure) {
        printGeneric(c, id, out);
    }
}
Пример #14
0
BSpline::BSpline(const TopoDS_Edge &e)
{
    geomType = BSPLINE;
    BRepAdaptor_Curve c(e);
    occEdge = e;
    Handle_Geom_BSplineCurve spline = c.BSpline();
    bool fail = false;
    double f,l;
    gp_Pnt s,m,ePt;
    //if startpoint == endpoint conversion to BSpline will fail

    if (spline->Degree() > 3) {                                        //if spline is too complex, approximate it
        Standard_Real tol3D = 0.001;                                   //1/1000 of a mm? screen can't resolve this
        Standard_Integer maxDegree = 3, maxSegment = 10;
        Handle_BRepAdaptor_HCurve hCurve = new BRepAdaptor_HCurve(c);
        // approximate the curve using a tolerance
        //Approx_Curve3d approx(hCurve, tol3D, GeomAbs_C2, maxSegment, maxDegree);   //gives degree == 5  ==> too many poles ==> buffer overrun
        Approx_Curve3d approx(hCurve, tol3D, GeomAbs_C0, maxSegment, maxDegree);
        if (approx.IsDone() && approx.HasResult()) {
            spline = approx.Curve();
        } else {
            if (approx.HasResult()) {                   //result, but not within tolerance
                spline = approx.Curve();
                Base::Console().Log("Geometry::BSpline - result not within tolerance\n");
            } else {
                fail = true;
                f = c.FirstParameter();
                l = c.LastParameter();
                s = c.Value(f);
                m = c.Value((l+f)/2.0);
                ePt = c.Value(l);
                Base::Console().Log("Error - Geometry::BSpline - from:(%.3f,%.3f) to:(%.3f,%.3f) poles: %d\n",
                                     s.X(),s.Y(),ePt.X(),ePt.Y(),spline->NbPoles());
                //throw Base::Exception("Geometry::BSpline - could not approximate curve");
            }
        }
    }

    GeomConvert_BSplineCurveToBezierCurve crt(spline);

    BezierSegment tempSegment;
    gp_Pnt controlPoint;
    if (fail) {
        tempSegment.poles = 3;
        tempSegment.pnts[0] = Base::Vector2D(s.X(),s.Y());
        tempSegment.pnts[1] = Base::Vector2D(m.X(),m.Y());
        tempSegment.pnts[2] = Base::Vector2D(ePt.X(),ePt.Y());
        segments.push_back(tempSegment);
    } else {
        for (Standard_Integer i = 1; i <= crt.NbArcs(); ++i) {
            Handle_Geom_BezierCurve bezier = crt.Arc(i);
            if (bezier->Degree() > 3) {
                throw Base::Exception("Geometry::BSpline - converted curve degree > 3");
            }
            tempSegment.poles = bezier->NbPoles();
            // Note: We really only need to keep the pnts[0] for the first Bezier segment,
            // assuming this only gets used as in QGIViewPart::drawPainterPath
            // ...it also gets used in GeometryObject::calcBoundingBox(), similar note applies
            for (int pole = 1; pole <= tempSegment.poles; ++pole) {
                controlPoint = bezier->Pole(pole);
                tempSegment.pnts[pole - 1] = Base::Vector2D(controlPoint.X(), controlPoint.Y());
            }
            segments.push_back(tempSegment);
        }
    }
}
BSpline::BSpline(const TopoDS_Edge &e)
{
    geomType = BSPLINE;
    BRepAdaptor_Curve c(e);
    occEdge = e;
    Handle_Geom_BSplineCurve spline = c.BSpline();
    bool fail = false;
    double f,l;
    gp_Pnt s,m,ePt;
    //if startpoint == endpoint conversion to BSpline will fail
    //Base::Console().Message("TRACE - Geometry::BSpline - start(%.3f,%.3f,%.3f) end(%.3f,%.3f,%.3f)\n",
    //                        s.X(),s.Y(),s.Z(),ePt.X(),ePt.Y(),ePt.Z());

    if (spline->Degree() > 3) {                                        //if spline is too complex, approximate it
        Standard_Real tol3D = 0.001;                                   //1/1000 of a mm? screen can't resolve this
        Standard_Integer maxDegree = 3, maxSegment = 10;
        Handle_BRepAdaptor_HCurve hCurve = new BRepAdaptor_HCurve(c);
        // approximate the curve using a tolerance
        //Approx_Curve3d approx(hCurve, tol3D, GeomAbs_C2, maxSegment, maxDegree);   //gives degree == 5  ==> too many poles ==> buffer overrun
        Approx_Curve3d approx(hCurve, tol3D, GeomAbs_C0, maxSegment, maxDegree);
        if (approx.IsDone() && approx.HasResult()) {
            spline = approx.Curve();
        } else {
            if (approx.HasResult()) {                   //result, but not within tolerance
                spline = approx.Curve();
                Base::Console().Log("Geometry::BSpline - result not within tolerance\n");
            } else {
                fail = true;
                f = c.FirstParameter();
                l = c.LastParameter();
                s = c.Value(f);
                m = c.Value((l+f)/2.0);
                ePt = c.Value(l);
                Base::Console().Log("Error - Geometry::BSpline - no result- from:(%.3f,%.3f) to:(%.3f,%.3f) poles: %d\n",
                                     s.X(),s.Y(),ePt.X(),ePt.Y(),spline->NbPoles());
                throw Base::Exception("Geometry::BSpline - could not approximate curve");
            }
        }
    }

    GeomConvert_BSplineCurveToBezierCurve crt(spline);

    gp_Pnt controlPoint;
    if (fail) {
        BezierSegment tempSegment;
        tempSegment.poles = 3;
        tempSegment.degree = 2;
        tempSegment.pnts.push_back(Base::Vector2d(s.X(),s.Y()));
        tempSegment.pnts.push_back(Base::Vector2d(m.X(),m.Y()));
        tempSegment.pnts.push_back(Base::Vector2d(ePt.X(),ePt.Y()));
        segments.push_back(tempSegment);
    } else {
        for (Standard_Integer i = 1; i <= crt.NbArcs(); ++i) {
            BezierSegment tempSegment;
            Handle_Geom_BezierCurve bezier = crt.Arc(i);
            if (bezier->Degree() > 3) {
                Base::Console().Log("Geometry::BSpline - converted curve degree > 3\n");
            }
            tempSegment.poles = bezier->NbPoles();
            tempSegment.degree = bezier->Degree();
            for (int pole = 1; pole <= tempSegment.poles; ++pole) {
                controlPoint = bezier->Pole(pole);
                tempSegment.pnts.push_back(Base::Vector2d(controlPoint.X(), controlPoint.Y()));
            }
            segments.push_back(tempSegment);
        }
    }
}
Пример #16
0
Py::Int BezierCurve2dPy::getNbPoles(void) const
{
    Handle_Geom_BezierCurve curve = Handle_Geom_BezierCurve::DownCast
        (getGeometryPtr()->handle());
    return Py::Int(curve->NbPoles()); 
}
Пример #17
0
void DXFOutput::printBSpline(const BRepAdaptor_Curve& c, int id, std::ostream& out) //Not even close yet- DF 
{
    try {
        std::stringstream str;
        Handle_Geom_BSplineCurve spline = c.BSpline();
        if (spline->Degree() > 3) {
            Standard_Real tol3D = 0.001;
            Standard_Integer maxDegree = 3, maxSegment = 10;
            Handle_BRepAdaptor_HCurve hCurve = new BRepAdaptor_HCurve(c);
            // approximate the curve using a tolerance
            Approx_Curve3d approx(hCurve,tol3D,GeomAbs_C2,maxSegment,maxDegree);
            if (approx.IsDone() && approx.HasResult()) {
                // have the result
                spline = approx.Curve();
            }
        }
		
        GeomConvert_BSplineCurveToBezierCurve crt(spline);
		//GeomConvert_BSplineCurveKnotSplitting crt(spline,0);
        Standard_Integer arcs = crt.NbArcs();
		//Standard_Integer arcs = crt.NbSplits()-1;
        	str << 0 << endl
				<< "SECTION" << endl
				<< 2 << endl
				<< "ENTITIES" << endl
				<< 0 << endl
				<< "SPLINE" << endl;
				//<< 8 << endl
				//<< 0 << endl
				//<< 66 << endl
				//<< 1 << endl
				//<< 0 << endl;

        for (Standard_Integer i=1; i<=arcs; i++) {
            Handle_Geom_BezierCurve bezier = crt.Arc(i);
            Standard_Integer poles = bezier->NbPoles();
			//Standard_Integer poles = bspline->NbPoles();
			//gp_Pnt p1 = bspline->Pole(1);

            if (bezier->Degree() == 3) {
                if (poles != 4)
                    Standard_Failure::Raise("do it the generic way");
                gp_Pnt p1 = bezier->Pole(1);
                gp_Pnt p2 = bezier->Pole(2);
                gp_Pnt p3 = bezier->Pole(3);
                gp_Pnt p4 = bezier->Pole(4);
                if (i == 1) {
                    str 
						<< 10 << endl
						<< p1.X() << endl
						<< 20 << endl
						<< p1.Y() << endl
						<< 30 << endl
						<< 0 << endl
						
						<< 10 << endl
                        << p2.X() << endl
						<< 20 << endl
						<< p2.Y() << endl
						<< 30 << endl
						<< 0 << endl
						
						<< 10 << endl
                        << p3.X() << endl
						<< 20 << endl
						<< p3.Y() << endl
						<< 30 << endl
						<< 0 << endl
						
						<< 10 << endl
                        << p4.X() << endl
						<< 20 << endl
						<< p4.Y() << endl
						<< 30 << endl
						<< 0 << endl

						<< 12 << endl
						<< p1.X() << endl
						<< 22 << endl
						<< p1.Y() << endl
						<< 32 << endl
						<< 0 << endl

						<< 13 << endl
						<< p4.X() << endl
						<< 23 << endl
						<< p4.Y() << endl
						<< 33 << endl
						<< 0 << endl;
                }
                else {
                    str 
						<< 10 << endl
                        << p3.X() << endl
						<< 20 << endl
						<< p3.Y() << endl
						<< 30 << endl
						<< 0 << endl
						
						<< 10 << endl
                        << p4.X() << endl
						<< 20 << endl
						<< p4.Y() << endl
						<< 30 << endl
						<< 0 << endl

						<< 12 << endl
						<< p3.X() << endl
						<< 22 << endl
						<< p3.Y() << endl
						<< 32 << endl
						<< 0 << endl

						<< 13 << endl
						<< p4.X() << endl
						<< 23 << endl
						<< p4.Y() << endl
						<< 33 << endl
						<< 0 << endl;

                }
            }
            else if (bezier->Degree() == 2) {
                if (poles != 3)
                    Standard_Failure::Raise("do it the generic way");
                gp_Pnt p1 = bezier->Pole(1);
                gp_Pnt p2 = bezier->Pole(2);
                gp_Pnt p3 = bezier->Pole(3);
                if (i == 1) {
                    str 
						<< 10 << endl
						<< p1.X() << endl
						<< 20 << endl
						<< p1.Y() << endl
						<< 30 << endl
						<< 0 << endl
						
						<< 10 << endl
                        << p2.X() << endl
						<< 20 << endl
						<< p2.Y() << endl
						<< 30 << endl
						<< 0 << endl
						
						<< 10 << endl
                        << p3.X() << endl
						<< 20 << endl
						<< p3.Y() << endl
						<< 30 << endl
						<< 0 << endl

						<< 12 << endl
						<< p1.X() << endl
						<< 22 << endl
						<< p1.Y() << endl
						<< 32 << endl
						<< 0 << endl

						<< 13 << endl
						<< p3.X() << endl
						<< 23 << endl
						<< p3.Y() << endl
						<< 33 << endl
						<< 0 << endl;
                }
                else {
                    str 
						<< 10 << endl
                        << p3.X() << endl
						<< 20 << endl
						<< p3.Y() << endl
						<< 30 << endl
						<< 0 << endl;
                }
            }
            else {
                Standard_Failure::Raise("do it the generic way");
            }
        }

        //str << "\" />";
        out << str.str();
    }
    catch (Standard_Failure) {
        printGeneric(c, id, out);
    }
}