void HGear::GetBox(CBox &box){ double acting_radius = (double)(m_module * m_num_teeth)/2; double outside_radius = acting_radius + (m_addendum_multiplier*m_module + m_addendum_offset); gp_Trsf mat = make_matrix(m_pos.Location(), m_pos.XDirection(), m_pos.YDirection()); gp_Pnt p[4]; p[0] = gp_Pnt(m_pos.Location().XYZ() + gp_XYZ(outside_radius, outside_radius, 0.0)); p[1] = gp_Pnt(m_pos.Location().XYZ() + gp_XYZ(-outside_radius, outside_radius, 0.0)); p[2] = gp_Pnt(m_pos.Location().XYZ() + gp_XYZ(-outside_radius, -outside_radius, 0.0)); p[3] = gp_Pnt(m_pos.Location().XYZ() + gp_XYZ(outside_radius, -outside_radius, 0.0)); for(int i = 0; i<4; i++) { p[i].Transform(mat); box.Insert(p[i].X(), p[i].Y(), p[i].Z()); } }
void transform_for_cone_and_depth(gp_Pnt &p) { gp_Vec v(p.XYZ()); double radius_beyond_surface = v.Magnitude() - pitch_radius; v.Normalize(); double scale = 1.0 - cone_sin_for_point * height_for_point / pitch_radius; p = gp_Pnt(v.XYZ() * (scale * pitch_radius + scale * radius_beyond_surface * cone_cos_for_point) + gp_XYZ(0.0, 0.0, height_for_point * cone_cos_for_point + scale * radius_beyond_surface * cone_sin_for_point)); }
static Handle(Geom_Curve) mkBezierCurve(const Standard_Integer nPoles, const Standard_Real theCoords[][3], const Standard_Real aScale = 1, const gp_XYZ& aShift = gp_XYZ(0,0,0)) { TColgp_Array1OfPnt aPoles (1, nPoles); for (Standard_Integer i=0; i < nPoles; i++) { gp_XYZ aP (theCoords[i][0], theCoords[i][1], theCoords[i][2]); aPoles(i+1) = gp_Pnt (aP * aScale + aShift); } return new Geom_BezierCurve (aPoles); }
static TopoDS_Wire mkPolygonWire(const Standard_Integer nPoints, const Standard_Real theCoords[][3], const Standard_Real aScale = 1, const gp_XYZ& aShift = gp_XYZ(0,0,0)) { BRepBuilderAPI_MakePolygon aPol; for (Standard_Integer i=0; i < nPoints; i++) { gp_XYZ aP(theCoords[i][0], theCoords[i][1], theCoords[i][2]); aPol.Add (gp_Pnt (aP * aScale + aShift)); } return aPol.Wire(); }
gp_Trsf CCPACSControlSurfaceDevice::GetFlapTransform() const { // this block of code calculates all needed values to rotate and move the controlSurfaceDevice according // to the given relDeflection by using a linearInterpolation. std::vector<double> relDeflections, innerXTrans, outerXTrans, innerYTrans, innerZTrans, outerZTrans, rotations; CCPACSControlSurfaceDeviceSteps steps = getMovementPath().getSteps(); for (int istep = 1; istep <= steps.GetStepCount(); ++istep) { CCPACSControlSurfaceDeviceStep& step = steps.GetStep(istep); relDeflections.push_back(step.getRelDeflection()); innerXTrans.push_back(step.getInnerHingeTranslation().x); innerYTrans.push_back(step.getInnerHingeTranslation().y); innerZTrans.push_back(step.getInnerHingeTranslation().z); outerXTrans.push_back(step.getOuterHingeTranslation().x); outerZTrans.push_back(step.getOuterHingeTranslation().z); rotations.push_back(step.getHingeLineRotation()); } double rotation = Interpolate( relDeflections, rotations, currentDeflection ); double innerTranslationX = Interpolate( relDeflections, innerXTrans, currentDeflection ); double innerTranslationY = Interpolate( relDeflections, innerYTrans, currentDeflection ); double innerTranslationZ = Interpolate( relDeflections, innerZTrans, currentDeflection ); double outerTranslationX = Interpolate( relDeflections, outerXTrans, currentDeflection ); double outerTranslationZ = Interpolate( relDeflections, outerZTrans, currentDeflection ); gp_Pnt innerHingeOld = _hingeLine->getInnerHingePoint();; gp_Pnt outerHingeOld = _hingeLine->getOuterHingePoint();; // innerTranslationY on hingePoint1 on purpose, maybe consider setting it to zero as default. See CPACS definition on // Path/Step/HingeLineTransformation for more informations. gp_Pnt hingePoint1 = _hingeLine->getOuterHingePoint().XYZ() + gp_XYZ(outerTranslationX, innerTranslationY, outerTranslationZ); gp_Pnt hingePoint2 = _hingeLine->getInnerHingePoint().XYZ() + gp_XYZ(innerTranslationX, innerTranslationY, innerTranslationZ); // calculating the needed transformations CTiglControlSurfaceTransformation transformation(innerHingeOld, outerHingeOld, hingePoint2, hingePoint1, rotation); return transformation.getTotalTransformation(); }
//================================================================ // Function : Convert_Presentation::sampleBezierSurface // Purpose : //================================================================ void Convert_Presentation::sampleBezierSurface() { getAISContext()->EraseAll(); Standard_CString aName = "BezierSurface"; // Create a BezierSurface TColgp_Array2OfPnt aPoles(1,2,1,4); // 8 points TColStd_Array2OfReal aWeights(1,2,1,4); // initializing array of points aPoles.SetValue(1,1,gp_Pnt(0,10,0)); aPoles.SetValue(1,2,gp_Pnt(3.3,6.6,3)); aPoles.SetValue(1,3,gp_Pnt(6.6,6.6,-3)); aPoles.SetValue(1,4,gp_Pnt(10,10,0)); aPoles.SetValue(2,1,gp_Pnt(0,0,0)); aPoles.SetValue(2,2,gp_Pnt(3.3,3.3,-3)); aPoles.SetValue(2,3,gp_Pnt(6.6,3.3,3)); aPoles.SetValue(2,4,gp_Pnt(10,0,0)); // scaling poles for (Standard_Integer i=1; i <= aPoles.ColLength(); i++) for (Standard_Integer j=1; j <= aPoles.RowLength(); j++) aPoles(i,j).ChangeCoord() = aPoles(i,j).Coord() * 100 + gp_XYZ(-500,-500,0); //initializing array of weights aWeights.SetValue(1,1,1); aWeights.SetValue(1,2,3); aWeights.SetValue(1,3,9); aWeights.SetValue(1,4,1); aWeights.SetValue(2,1,1); aWeights.SetValue(2,2,2); aWeights.SetValue(2,3,5); aWeights.SetValue(2,4,1); Handle(Geom_BezierSurface) aSurface = new Geom_BezierSurface(aPoles, aWeights); TCollection_AsciiString aText ( " // Create a BezierSurface" EOL " TColgp_Array2OfPnt aPoles(1,2,1,4); // 8 points" EOL " TColStd_Array2OfReal aWeights(1,2,1,4);" EOL " // initializing array of points" EOL " aPoles.SetValue(1,1,gp_Pnt(0,10,0)); aPoles.SetValue(1,2,gp_Pnt(3.3,6.6,3));" EOL " aPoles.SetValue(1,3,gp_Pnt(6.6,6.6,-3)); aPoles.SetValue(1,4,gp_Pnt(10,10,0));" EOL " aPoles.SetValue(2,1,gp_Pnt(0,0,0)); aPoles.SetValue(2,2,gp_Pnt(3.3,3.3,-3));" EOL " aPoles.SetValue(2,3,gp_Pnt(6.6,3.3,3)); aPoles.SetValue(2,4,gp_Pnt(10,0,0)); " EOL " // scaling poles" EOL " for (Standard_Integer i=1; i <= aPoles.ColLength(); i++)" EOL " for (Standard_Integer j=1; j <= aPoles.RowLength(); j++)" EOL " aPoles(i,j).ChangeCoord() = aPoles(i,j).Coord() * 100 + gp_XYZ(-500,-500,0);" EOL " //initializing array of weights" EOL " aWeights.SetValue(1,1,1); aWeights.SetValue(1,2,3);" EOL " aWeights.SetValue(1,3,9); aWeights.SetValue(1,4,1);" EOL " aWeights.SetValue(2,1,1); aWeights.SetValue(2,2,2);" EOL " aWeights.SetValue(2,3,5); aWeights.SetValue(2,4,1);" EOL " Handle(Geom_BezierSurface) aSurface =" EOL " new Geom_BezierSurface(aPoles, aWeights);" EOL ); drawSurfaceAndItsBSpline (aSurface, aName, aText); }
static Handle(Geom_Curve) mkPBSplineCurve(const Standard_Integer nPoles, const Standard_Real theCoords[][3], const Standard_Real aScale = 1, const gp_XYZ& aShift = gp_XYZ(0,0,0)) { TColgp_Array1OfPnt aPoles (1, nPoles); TColStd_Array1OfReal aKnots (1, nPoles+1); TColStd_Array1OfInteger aMults(1, nPoles+1); for (Standard_Integer i=0; i < nPoles; i++) { gp_XYZ aP (theCoords[i][0], theCoords[i][1], theCoords[i][2]); aPoles(i+1) = gp_Pnt (aP * aScale + aShift); } for (i=1; i <= nPoles+1; i++) aKnots(i) = Standard_Real(i-1); aMults.Init(1); return new Geom_BSplineCurve (aPoles, aKnots, aMults, 3, Standard_True); }
//======================================================================= //function : Execute //purpose : //======================================================================= Standard_Integer GEOMImpl_RotateDriver::Execute(TFunction_Logbook& log) const { if (Label().IsNull()) return 0; Handle(GEOM_Function) aFunction = GEOM_Function::GetFunction(Label()); if (aFunction.IsNull()) return 0; GEOMImpl_IRotate RI(aFunction); gp_Trsf aTrsf; gp_Pnt aCP, aP1, aP2; Standard_Integer aType = aFunction->GetType(); Handle(GEOM_Function) anOriginalFunction = RI.GetOriginal(); if (anOriginalFunction.IsNull()) return 0; TopoDS_Shape aShape, anOriginal = anOriginalFunction->GetValue(); if (anOriginal.IsNull()) return 0; if (aType == ROTATE || aType == ROTATE_COPY) { Handle(GEOM_Function) anAxis = RI.GetAxis(); if (anAxis.IsNull()) return 0; TopoDS_Shape A = anAxis->GetValue(); if (A.IsNull() || A.ShapeType() != TopAbs_EDGE) return 0; TopoDS_Edge anEdge = TopoDS::Edge(A); gp_Pnt aP1 = BRep_Tool::Pnt(TopExp::FirstVertex(anEdge)); gp_Pnt aP2 = BRep_Tool::Pnt(TopExp::LastVertex(anEdge)); gp_Dir aDir(gp_Vec(aP1, aP2)); gp_Ax1 anAx1(aP1, aDir); Standard_Real anAngle = RI.GetAngle(); if (fabs(anAngle) < Precision::Angular()) anAngle += 2*PI; // NPAL19665,19769 aTrsf.SetRotation(anAx1, anAngle); //NPAL18620: performance problem: multiple locations are accumulated // in shape and need a great time to process //BRepBuilderAPI_Transform aTransformation(anOriginal, aTrsf, Standard_False); //aShape = aTransformation.Shape(); TopLoc_Location aLocOrig = anOriginal.Location(); gp_Trsf aTrsfOrig = aLocOrig.Transformation(); //TopLoc_Location aLocRes (aTrsf * aTrsfOrig); // gp_Trsf::Multiply() has a bug aTrsfOrig.PreMultiply(aTrsf); TopLoc_Location aLocRes (aTrsfOrig); aShape = anOriginal.Located(aLocRes); } else if (aType == ROTATE_THREE_POINTS || aType == ROTATE_THREE_POINTS_COPY) { Handle(GEOM_Function) aCentPoint = RI.GetCentPoint(); Handle(GEOM_Function) aPoint1 = RI.GetPoint1(); Handle(GEOM_Function) aPoint2 = RI.GetPoint2(); if(aCentPoint.IsNull() || aPoint1.IsNull() || aPoint2.IsNull()) return 0; TopoDS_Shape aCV = aCentPoint->GetValue(); TopoDS_Shape aV1 = aPoint1->GetValue(); TopoDS_Shape aV2 = aPoint2->GetValue(); if(aCV.IsNull() || aCV.ShapeType() != TopAbs_VERTEX) return 0; if(aV1.IsNull() || aV1.ShapeType() != TopAbs_VERTEX) return 0; if(aV2.IsNull() || aV2.ShapeType() != TopAbs_VERTEX) return 0; aCP = BRep_Tool::Pnt(TopoDS::Vertex(aCV)); aP1 = BRep_Tool::Pnt(TopoDS::Vertex(aV1)); aP2 = BRep_Tool::Pnt(TopoDS::Vertex(aV2)); gp_Vec aVec1 (aCP, aP1); gp_Vec aVec2 (aCP, aP2); gp_Dir aDir (aVec1 ^ aVec2); gp_Ax1 anAx1 (aCP, aDir); Standard_Real anAngle = aVec1.Angle(aVec2); if (fabs(anAngle) < Precision::Angular()) anAngle += 2*PI; // NPAL19665 aTrsf.SetRotation(anAx1, anAngle); //NPAL18620: performance problem: multiple locations are accumulated // in shape and need a great time to process //BRepBuilderAPI_Transform aTransformation(anOriginal, aTrsf, Standard_False); //aShape = aTransformation.Shape(); TopLoc_Location aLocOrig = anOriginal.Location(); gp_Trsf aTrsfOrig = aLocOrig.Transformation(); //TopLoc_Location aLocRes (aTrsf * aTrsfOrig); // gp_Trsf::Multiply() has a bug aTrsfOrig.PreMultiply(aTrsf); TopLoc_Location aLocRes (aTrsfOrig); aShape = anOriginal.Located(aLocRes); } else if (aType == ROTATE_1D) { //Get direction Handle(GEOM_Function) anAxis = RI.GetAxis(); if(anAxis.IsNull()) return 0; TopoDS_Shape A = anAxis->GetValue(); if(A.IsNull() || A.ShapeType() != TopAbs_EDGE) return 0; TopoDS_Edge anEdge = TopoDS::Edge(A); gp_Pnt aP1 = BRep_Tool::Pnt(TopExp::FirstVertex(anEdge)); gp_Pnt aP2 = BRep_Tool::Pnt(TopExp::LastVertex(anEdge)); gp_Dir D(gp_Vec(aP1, aP2)); gp_Ax1 AX1(aP1, D); Standard_Integer nbtimes = RI.GetNbIter1(); Standard_Real angle = 360.0/nbtimes; TopoDS_Compound aCompound; BRep_Builder B; B.MakeCompound( aCompound ); TopLoc_Location aLocOrig = anOriginal.Location(); gp_Trsf aTrsfOrig = aLocOrig.Transformation(); for (int i = 0; i < nbtimes; i++ ) { if (i == 0) { // NPAL19665 B.Add(aCompound, anOriginal); } else { aTrsf.SetRotation(AX1, i*angle/* * PI180 */); //TopLoc_Location aLocRes (aTrsf * aTrsfOrig); // gp_Trsf::Multiply() has a bug gp_Trsf aTrsfNew (aTrsfOrig); aTrsfNew.PreMultiply(aTrsf); TopLoc_Location aLocRes (aTrsfNew); B.Add(aCompound, anOriginal.Located(aLocRes)); } //NPAL18620: performance problem: multiple locations are accumulated // in shape and need a great time to process //BRepBuilderAPI_Transform aBRepTransformation(anOriginal, aTrsf, Standard_False); //B.Add(aCompound, aBRepTransformation.Shape()); } aShape = aCompound; } else if (aType == ROTATE_2D) { //Get direction Handle(GEOM_Function) anAxis = RI.GetAxis(); if(anAxis.IsNull()) return 0; TopoDS_Shape A = anAxis->GetValue(); if(A.IsNull() || A.ShapeType() != TopAbs_EDGE) return 0; TopoDS_Edge anEdge = TopoDS::Edge(A); gp_Pnt aP1 = BRep_Tool::Pnt(TopExp::FirstVertex(anEdge)); gp_Pnt aP2 = BRep_Tool::Pnt(TopExp::LastVertex(anEdge)); gp_Dir D(gp_Vec(aP1, aP2)); gp_Ax1 AX1(aP1, D); gp_Trsf aTrsf1; gp_Trsf aTrsf2; gp_Trsf aTrsf3; gp_XYZ aDir2 = RI.GetDir2(); // can be set by previous execution if (aDir2.Modulus() < gp::Resolution()) { // Calculate direction as vector from the axis to the shape's center gp_Pnt P1; GProp_GProps System; if (anOriginal.ShapeType() == TopAbs_VERTEX) { P1 = BRep_Tool::Pnt(TopoDS::Vertex( anOriginal )); } else if ( anOriginal.ShapeType() == TopAbs_EDGE || anOriginal.ShapeType() == TopAbs_WIRE ) { BRepGProp::LinearProperties(anOriginal, System); P1 = System.CentreOfMass(); } else if ( anOriginal.ShapeType() == TopAbs_FACE || anOriginal.ShapeType() == TopAbs_SHELL ) { BRepGProp::SurfaceProperties(anOriginal, System); P1 = System.CentreOfMass(); } else { BRepGProp::VolumeProperties(anOriginal, System); P1 = System.CentreOfMass(); } Handle(Geom_Line) Line = new Geom_Line(AX1); GeomAPI_ProjectPointOnCurve aPrjTool( P1, Line ); gp_Pnt P2 = aPrjTool.NearestPoint(); if ( P1.IsEqual(P2, Precision::Confusion() ) ) return 0; aDir2 = gp_XYZ(P1.X()-P2.X(), P1.Y()-P2.Y(), P1.Z()-P2.Z()); // Attention: this abnormal action is done for good working of // TransformLikeOther(), used by RestoreSubShapes functionality RI.SetDir2(aDir2); } gp_Vec Vec (aDir2); Vec.Normalize(); gp_Vec elevVec(D); elevVec.Normalize(); Standard_Integer nbtimes2 = RI.GetNbIter2(); Standard_Integer nbtimes1 = RI.GetNbIter1(); Standard_Real step = RI.GetStep(); Standard_Real elevationstep = RI.GetElevationStep(); Standard_Real ang = RI.GetAngle(); TopLoc_Location aLocOrig = anOriginal.Location(); gp_Trsf aTrsfOrig = aLocOrig.Transformation(); gp_Vec aVec; TopoDS_Compound aCompound; BRep_Builder B; B.MakeCompound( aCompound ); Standard_Real DX, DY, DZ; for (int i = 0; i < nbtimes2; i++ ) { if (i != 0) { DX = i * step * Vec.X(); DY = i * step * Vec.Y(); DZ = i * step * Vec.Z(); aVec.SetCoord( DX, DY, DZ ); aTrsf1.SetTranslation(aVec); } for (int j = 0; j < nbtimes1; j++ ) { if (j == 0) { // NPAL19665 TopLoc_Location aLocRes (aTrsf1 * aTrsfOrig); B.Add(aCompound, anOriginal.Located(aLocRes)); } else { DX = j * elevationstep * elevVec.X(); DY = j * elevationstep * elevVec.Y(); DZ = j * elevationstep * elevVec.Z(); aVec.SetCoord( DX, DY, DZ ); aTrsf3.SetTranslation(aVec); aTrsf2.SetRotation(AX1, j*ang /* * PI180 */ ); //TopLoc_Location aLocRes (aTrsf2 * aTrsf1 * aTrsfOrig); // gp_Trsf::Multiply() has a bug gp_Trsf aTrsfNew (aTrsfOrig); aTrsfNew.PreMultiply(aTrsf1); aTrsfNew.PreMultiply(aTrsf2); aTrsfNew.PreMultiply(aTrsf3); TopLoc_Location aLocRes (aTrsfNew); B.Add(aCompound, anOriginal.Located(aLocRes)); } //NPAL18620: performance problem: multiple locations are accumulated // in shape and need a great time to process //BRepBuilderAPI_Transform aBRepTrsf1 (anOriginal, aTrsf1, Standard_False); //BRepBuilderAPI_Transform aBRepTrsf2 (aBRepTrsf1.Shape(), aTrsf2, Standard_False); //B.Add(aCompound, aBRepTrsf2.Shape()); } } aShape = aCompound; } else return 0; if (aShape.IsNull()) return 0; aFunction->SetValue(aShape); log.SetTouched(Label()); return 1; }
CCuboid::CCuboid(const gp_Ax2& pos, double x, double y, double z, const wxChar* title, const HeeksColor& col, float opacity) :CSolid(BRepPrimAPI_MakeBox(gp_Ax2(pos.Location().XYZ() + gp_XYZ((x < 0) ? x:0.0, (y < 0) ? y:0.0, (z < 0) ? z:0.0), pos.Direction(), pos.XDirection()), fabs(x), fabs(y), fabs(z)), title, col, opacity) , m_pos(pos), m_x(x), m_y(y), m_z(z) { }