void AnalogLowPass::design (int numPoles, WorkspaceBase* w) { if (m_numPoles != numPoles) { m_numPoles = numPoles; reset (); PolynomialFinderBase& poly (w->poly); RootFinderBase& poles (w->roots); poly.solve (numPoles); int degree = numPoles * 2; poles.coef()[0] = 1 + poly.coef()[0]; poles.coef()[1] = 0; for (int i = 1; i <= degree; ++i) { poles.coef()[2*i] = poly.coef()[i] * ((i & 1) ? -1 : 1); poles.coef()[2*i+1] = 0; } poles.solve (degree); int j = 0; for (int i = 0; i < degree; ++i) if (poles.root()[i].real() <= 0) poles.root()[j++] = poles.root()[i]; // sort descending imag() and cut degree in half poles.sort (degree/2); const int pairs = numPoles / 2; for (int i = 0; i < pairs; ++i) { complex_t c = poles.root()[i]; addPoleZeroConjugatePairs (c, infinity()); } if (numPoles & 1) add (poles.root()[pairs].real(), infinity()); } }
void AnalogLowShelf::design (int numPoles, double gainDb, WorkspaceBase* w) { if (m_numPoles != numPoles || m_gainDb != gainDb) { m_numPoles = numPoles; m_gainDb = gainDb; reset (); const double G = pow (10., gainDb / 20) - 1; RootFinderBase& poles (w->roots); for (int i = 0; i < numPoles + 1; ++i) poles.coef()[i] = reversebessel (i, numPoles); poles.solve (numPoles); RootFinder<50> zeros; for (int i = 0; i < numPoles + 1; ++i) zeros.coef()[i] = reversebessel (i, numPoles); double a0 = reversebessel (0, numPoles); zeros.coef()[0] += G * a0; zeros.solve (numPoles); const int pairs = numPoles / 2; for (int i = 0; i < pairs; ++i) { complex_t p = poles.root()[i]; complex_t z = zeros.root()[i]; addPoleZeroConjugatePairs (p, z); } if (numPoles & 1) add (poles.root()[pairs].real(), zeros.root()[pairs].real()); } }
int convert_to_ifc(const Handle_Geom_Curve& c, IfcSchema::IfcCurve*& curve, bool advanced) { if (c->DynamicType() == STANDARD_TYPE(Geom_Line)) { IfcSchema::IfcDirection* d; IfcSchema::IfcCartesianPoint* p; Handle_Geom_Line line = Handle_Geom_Line::DownCast(c); if (!convert_to_ifc(line->Position().Location(), p, advanced)) { return 0; } if (!convert_to_ifc(line->Position().Direction(), d, advanced)) { return 0; } IfcSchema::IfcVector* v = new IfcSchema::IfcVector(d, 1.); curve = new IfcSchema::IfcLine(p, v); return 1; } else if (c->DynamicType() == STANDARD_TYPE(Geom_Circle)) { IfcSchema::IfcAxis2Placement3D* ax; Handle_Geom_Circle circle = Handle_Geom_Circle::DownCast(c); convert_to_ifc(circle->Position(), ax, advanced); curve = new IfcSchema::IfcCircle(ax, circle->Radius()); return 1; } else if (c->DynamicType() == STANDARD_TYPE(Geom_Ellipse)) { IfcSchema::IfcAxis2Placement3D* ax; Handle_Geom_Ellipse ellipse = Handle_Geom_Ellipse::DownCast(c); convert_to_ifc(ellipse->Position(), ax, advanced); curve = new IfcSchema::IfcEllipse(ax, ellipse->MajorRadius(), ellipse->MinorRadius()); return 1; } #ifdef USE_IFC4 else if (c->DynamicType() == STANDARD_TYPE(Geom_BSplineCurve)) { Handle_Geom_BSplineCurve bspline = Handle_Geom_BSplineCurve::DownCast(c); IfcSchema::IfcCartesianPoint::list::ptr points(new IfcSchema::IfcCartesianPoint::list); TColgp_Array1OfPnt poles(1, bspline->NbPoles()); bspline->Poles(poles); for (int i = 1; i <= bspline->NbPoles(); ++i) { IfcSchema::IfcCartesianPoint* p; if (!convert_to_ifc(poles.Value(i), p, advanced)) { return 0; } points->push(p); } IfcSchema::IfcKnotType::IfcKnotType knot_spec = opencascade_knotspec_to_ifc(bspline->KnotDistribution()); std::vector<int> mults; std::vector<double> knots; std::vector<double> weights; TColStd_Array1OfInteger bspline_mults(1, bspline->NbKnots()); TColStd_Array1OfReal bspline_knots(1, bspline->NbKnots()); TColStd_Array1OfReal bspline_weights(1, bspline->NbPoles()); bspline->Multiplicities(bspline_mults); bspline->Knots(bspline_knots); bspline->Weights(bspline_weights); opencascade_array_to_vector(bspline_mults, mults); opencascade_array_to_vector(bspline_knots, knots); opencascade_array_to_vector(bspline_weights, weights); bool rational = false; for (std::vector<double>::const_iterator it = weights.begin(); it != weights.end(); ++it) { if ((*it) != 1.) { rational = true; break; } } if (rational) { curve = new IfcSchema::IfcRationalBSplineCurveWithKnots( bspline->Degree(), points, IfcSchema::IfcBSplineCurveForm::IfcBSplineCurveForm_UNSPECIFIED, bspline->IsClosed(), false, mults, knots, knot_spec, weights ); } else { curve = new IfcSchema::IfcBSplineCurveWithKnots( bspline->Degree(), points, IfcSchema::IfcBSplineCurveForm::IfcBSplineCurveForm_UNSPECIFIED, bspline->IsClosed(), false, mults, knots, knot_spec ); } return 1; } #endif return 0; }
int convert_to_ifc(const Handle_Geom_Surface& s, IfcSchema::IfcSurface*& surface, bool advanced) { if (s->DynamicType() == STANDARD_TYPE(Geom_Plane)) { Handle_Geom_Plane plane = Handle_Geom_Plane::DownCast(s); IfcSchema::IfcAxis2Placement3D* place; /// @todo: Note that the Ax3 is converted to an Ax2 here if (!convert_to_ifc(plane->Position().Ax2(), place, advanced)) { return 0; } surface = new IfcSchema::IfcPlane(place); return 1; } #ifdef USE_IFC4 else if (s->DynamicType() == STANDARD_TYPE(Geom_CylindricalSurface)) { Handle_Geom_CylindricalSurface cyl = Handle_Geom_CylindricalSurface::DownCast(s); IfcSchema::IfcAxis2Placement3D* place; /// @todo: Note that the Ax3 is converted to an Ax2 here if (!convert_to_ifc(cyl->Position().Ax2(), place, advanced)) { return 0; } surface = new IfcSchema::IfcCylindricalSurface(place, cyl->Radius()); return 1; } else if (s->DynamicType() == STANDARD_TYPE(Geom_BSplineSurface)) { typedef IfcTemplatedEntityListList<IfcSchema::IfcCartesianPoint> points_t; Handle_Geom_BSplineSurface bspline = Handle_Geom_BSplineSurface::DownCast(s); points_t::ptr points(new points_t); TColgp_Array2OfPnt poles(1, bspline->NbUPoles(), 1, bspline->NbVPoles()); bspline->Poles(poles); for (int i = 1; i <= bspline->NbUPoles(); ++i) { std::vector<IfcSchema::IfcCartesianPoint*> ps; ps.reserve(bspline->NbVPoles()); for (int j = 1; j <= bspline->NbVPoles(); ++j) { IfcSchema::IfcCartesianPoint* p; if (!convert_to_ifc(poles.Value(i, j), p, advanced)) { return 0; } ps.push_back(p); } points->push(ps); } IfcSchema::IfcKnotType::IfcKnotType knot_spec_u = opencascade_knotspec_to_ifc(bspline->UKnotDistribution()); IfcSchema::IfcKnotType::IfcKnotType knot_spec_v = opencascade_knotspec_to_ifc(bspline->VKnotDistribution()); if (knot_spec_u != knot_spec_v) { knot_spec_u = IfcSchema::IfcKnotType::IfcKnotType_UNSPECIFIED; } std::vector<int> umults; std::vector<int> vmults; std::vector<double> uknots; std::vector<double> vknots; std::vector< std::vector<double> > weights; TColStd_Array1OfInteger bspline_umults(1, bspline->NbUKnots()); TColStd_Array1OfInteger bspline_vmults(1, bspline->NbVKnots()); TColStd_Array1OfReal bspline_uknots(1, bspline->NbUKnots()); TColStd_Array1OfReal bspline_vknots(1, bspline->NbVKnots()); TColStd_Array2OfReal bspline_weights(1, bspline->NbUPoles(), 1, bspline->NbVPoles()); bspline->UMultiplicities(bspline_umults); bspline->VMultiplicities(bspline_vmults); bspline->UKnots(bspline_uknots); bspline->VKnots(bspline_vknots); bspline->Weights(bspline_weights); opencascade_array_to_vector(bspline_umults, umults); opencascade_array_to_vector(bspline_vmults, vmults); opencascade_array_to_vector(bspline_uknots, uknots); opencascade_array_to_vector(bspline_vknots, vknots); opencascade_array_to_vector2(bspline_weights, weights); bool rational = false; for (std::vector< std::vector<double> >::const_iterator it = weights.begin(); it != weights.end(); ++it) { for (std::vector<double>::const_iterator jt = it->begin(); jt != it->end(); ++jt) { if ((*jt) != 1.) { rational = true; break; } } } if (rational) { surface = new IfcSchema::IfcRationalBSplineSurfaceWithKnots( bspline->UDegree(), bspline->VDegree(), points, IfcSchema::IfcBSplineSurfaceForm::IfcBSplineSurfaceForm_UNSPECIFIED, bspline->IsUClosed(), bspline->IsVClosed(), false, umults, vmults, uknots, vknots, knot_spec_u, weights ); } else { surface = new IfcSchema::IfcBSplineSurfaceWithKnots( bspline->UDegree(), bspline->VDegree(), points, IfcSchema::IfcBSplineSurfaceForm::IfcBSplineSurfaceForm_UNSPECIFIED, bspline->IsUClosed(), bspline->IsVClosed(), false, umults, vmults, uknots, vknots, knot_spec_u ); } return 1; } #endif return 0; }