void ProcessesList::produzirListaProcessos(){ this->listaProcessos.clear(); QDir *directory; QFile *arquivo; QString *S; QStringList files; std::string data; QDir aDir("/proc"); aDir.setFilter(QDir::Dirs); QStringList entries = aDir.entryList(); this->numThreads = 0; for( QStringList::ConstIterator entry=entries.begin(); entry!=entries.end(); ++entry) { S = new QString("/proc/" + QString(*entry)); if((S->compare("/proc/.") == 0) || (S->compare("/proc/..") == 0)){ continue; } directory = new QDir(*S); if(!directory->exists()){ continue; } else if(!((S->toStdString()[6] >= '0') && (S->toStdString()[6] <= '9'))){ continue; } directory->setFilter(QDir::Files); arquivo = new QFile(*S + "/status"); if((!arquivo)){ qDebug() << "ERRO 1! (" << *S << ")"; continue; } else if(!arquivo->open(QIODevice::ReadOnly | QIODevice::Text)){ qDebug() << arquivo->errorString(); qDebug() << "ERRO 2! (" << *S << ")"; continue; } process P; QTextStream buffer(arquivo); QStringList fileContent = buffer.readAll().split("\n"); QString buf; P.nome = processName(fileContent.at(0)); P.status = processStatus(fileContent.at(1)); P.pid = processPid(fileContent.at(3)); P.ppid = processPPid(fileContent.at(4)); P.user = processUser(fileContent.at(6)); for (int var = 7; var < fileContent.size(); ++var) { buf = fileContent.at(var); if(buf.startsWith("Threads")){ break; } } P.threads = processThreadsNumber(buf); this->numThreads += P.threads; P.trocas_contexto = processTrocasContexto(fileContent.at(fileContent.size()-3),fileContent.at(fileContent.size()-2)); this->listaProcessos.push_back(P); arquivo->close(); } delete arquivo; delete directory; delete S; }
//---------------------------------------------------------------- // Function: reflect // Description: reflect the body about an plane given the normal // vector. // // Author: Jane Hu //---------------------------------------------------------------- CubitStatus OCCBody::reflect( double reflect_axis_x, double reflect_axis_y, double reflect_axis_z ) { gp_Pnt aOrigin(0,0,0); gp_Dir aDir(reflect_axis_x, reflect_axis_y,reflect_axis_z); gp_Ax2 anAx2(aOrigin, aDir); gp_Trsf aTrsf; aTrsf.SetMirror(anAx2); BRepBuilderAPI_Transform aBRepTrsf(aTrsf); return transform(aBRepTrsf); }
//---------------------------------------------------------------- // Function: rotate // Description: rotate the body and its child entities // // Author: Jane Hu //---------------------------------------------------------------- CubitStatus OCCBody::rotate( double x, double y, double z, double angle )//in radians { gp_Pnt aOrigin(0,0,0); gp_Dir aDir(x, y, z); gp_Ax1 anAxis(aOrigin, aDir); //a is angular value of rotation in radians gp_Trsf aTrsf; aTrsf.SetRotation(anAxis, angle); BRepBuilderAPI_Transform aBRepTrsf(aTrsf); return transform(aBRepTrsf); }
//================================================================ // Function : Convert_Presentation::sampleCircle // Purpose : //================================================================ void Convert_Presentation::sampleCircle() { gp_Pnt aOrigin (0,0,0); gp_Dir aDir (1,0,0); gp_Ax2 aAxis (aOrigin, aDir); Standard_Real aRadius = 300; Handle_Geom_Circle aCurve = new Geom_Circle (aAxis, aRadius); TCollection_AsciiString aText ( " gp_Pnt aOrigin (0,0,0);" EOL " gp_Dir aDir (1,0,0);" EOL " gp_Ax2 aAxis (aOrigin, aDir);" EOL " Standard_Real aRadius = 300;" EOL " Handle(Geom_Circle) aCurve = new Geom_Circle (aAxis, aRadius);" EOL ); drawCurveAndItsBSpline (aCurve, "Circle", aText); }
//======================================================================= //function : FindBestPoint //purpose : Auxilare for Compute() // V - normal to (P1,P2,PC) //======================================================================= static gp_Pnt FindBestPoint(const gp_Pnt& P1, const gp_Pnt& P2, const gp_Pnt& PC, const gp_Vec& V) { double a = P1.Distance(P2); double b = P1.Distance(PC); double c = P2.Distance(PC); if( a < (b+c)/2 ) return PC; else { // find shift along V in order to a became equal to (b+c)/2 double shift = sqrt( a*a + (b*b-c*c)*(b*b-c*c)/16/a/a - (b*b+c*c)/2 ); gp_Dir aDir(V); gp_Pnt Pbest( PC.X() + aDir.X()*shift, PC.Y() + aDir.Y()*shift, PC.Z() + aDir.Z()*shift ); return Pbest; } }
int OCCEdge::createHelix(double pitch, double height, double radius, double angle, bool leftHanded) { try { gp_Ax2 cylAx2(gp_Pnt(0.0,0.0,0.0) , gp::DZ()); if (radius <= Precision::Confusion()) { StdFail_NotDone::Raise("radius to small"); } Handle_Geom_Surface surf; if (angle <= 0.0) { surf = new Geom_CylindricalSurface(cylAx2, radius); } else { surf = new Geom_ConicalSurface(gp_Ax3(cylAx2), angle, radius); } gp_Pnt2d aPnt(0, 0); gp_Dir2d aDir(2. * M_PI, pitch); if (leftHanded) { aPnt.SetCoord(2. * M_PI, 0.0); aDir.SetCoord(-2. * M_PI, pitch); } gp_Ax2d aAx2d(aPnt, aDir); Handle(Geom2d_Line) line = new Geom2d_Line(aAx2d); gp_Pnt2d pnt_beg = line->Value(0); gp_Pnt2d pnt_end = line->Value(sqrt(4.0*M_PI*M_PI+pitch*pitch)*(height/pitch)); const Handle(Geom2d_TrimmedCurve)& segm = GCE2d_MakeSegment(pnt_beg , pnt_end); this->setShape(BRepBuilderAPI_MakeEdge(segm , surf)); BRepLib::BuildCurves3d(edge); } catch(Standard_Failure &err) { Handle_Standard_Failure e = Standard_Failure::Caught(); const Standard_CString msg = e->GetMessageString(); if (msg != NULL && strlen(msg) > 1) { setErrorMessage(msg); } else { setErrorMessage("Failed to create helix"); } return 0; } return 1; }
//================================================================ // Function : Convert_Presentation::sampleEllipse // Purpose : //================================================================ void Convert_Presentation::sampleEllipse() { gp_Pnt aOrigin (0,0,0); gp_Dir aDir (1,0,0); gp_Ax2 aMajorAxis (aOrigin, aDir); Standard_Real aMajorRadius = 300; Standard_Real aMinorRadius = 150; Handle(Geom_Ellipse) aCurve = new Geom_Ellipse (aMajorAxis, aMajorRadius, aMinorRadius); TCollection_AsciiString aText ( " gp_Pnt aOrigin (0,0,0);" EOL " gp_Dir aDir (1,0,0);" EOL " gp_Ax2 aAxis (aOrigin, aDir);" EOL " Standard_Real aMajorRadius = 300;" EOL " Standard_Real aMinorRadius = 150;" EOL " Handle(Geom_Ellipse) aCurve = " EOL " new Geom_Ellipse (aAxis, aMajorRadius, aMinorRadius);" EOL ); drawCurveAndItsBSpline (aCurve, "Ellipse", aText); }
//======================================================================= //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; }
void cIncEnsembleCamera::OptimJacobi ( std::list<cIncSetLiaison *> * aListSL, const std::vector<cFonctrPond> & aFoncAux ) { mListSl = aListSL; mFoncsAux = aFoncAux; SetOpt(); ELISE_ASSERT(mL2Opt,"Need L2 Sys for OptimJacobi"); mSysL2->GetMatr(mMatrL2,mMatrtB); jacobi_diag(mMatrL2,mMatrValP,mMatrVecP); mtBVecP = mMatrtB * mMatrVecP; cElRanGen aR; Im1D_REAL8 P0 = CurVals(); Im1D_REAL8 mImBest = CurVals(); REAL aScInit = ScoreCur(false); REAL aScMin = aScInit; REAL aScAmMin = aScInit; for (INT aTest =0 ; aTest < 100 ; aTest ++) { SetPtCur(P0.data()); Im1D_REAL8 aDir( NbVal(),0.0); for (INT aK = 0 ; aK < NbVal() ; aK++) { ELISE_ASSERT(mMatrValP(aK,aK) != 0,"Jcobi "); REAL Val = (mtBVecP(aK,0) / ElAbs(mMatrValP(aK,aK))) ; REAL aRan = aR.cNRrandom3() ; if (aRan < 0.25) { Val = 0; } else if (aRan < 0.5) ; /* { Val = Val; } */ else Val *= 3 * aR.cNRrandom3() -1; for (INT aY =0 ; aY< NbVal() ; aY++) aDir.data()[aY] += mMatrVecP(aK,aY) * Val; } ELISE_COPY(aDir.all_pts(),P0.in() + aDir.in(),aDir.out()); SetPtCur(aDir.data()); REAL aSc = ScoreCur(false); if (aSc < aScMin) { ElSetMin(aScMin,aSc); for (INT aK= 0 ; aK< 10 ; aK++) OneItereDevL1( aK < 3); REAL aSc = ScoreCur(false); if (aSc < aScAmMin) { aScAmMin = aSc; ELISE_COPY(mImBest.all_pts(),CurVals().in(),mImBest.out()); } } cout << aScMin << " " << aScInit << " " << aSc << " " << aScAmMin << "\n"; } SetPtCur(mImBest.data()); }
//======================================================================= //function : Execute //purpose : //======================================================================= Standard_Integer GEOMImpl_ScaleDriver::Execute(TFunction_Logbook& log) const { if (Label().IsNull()) return 0; Handle(GEOM_Function) aFunction = GEOM_Function::GetFunction(Label()); GEOMImpl_IScale aCI (aFunction); Standard_Integer aType = aFunction->GetType(); TopoDS_Shape aShape; if (aType == SCALE_SHAPE || aType == SCALE_SHAPE_COPY) { Handle(GEOM_Function) aRefShape = aCI.GetShape(); TopoDS_Shape aShapeBase = aRefShape->GetValue(); if (aShapeBase.IsNull()) return 0; gp_Pnt aP (0,0,0); Handle(GEOM_Function) aRefPoint = aCI.GetPoint(); if (!aRefPoint.IsNull()) { TopoDS_Shape aShapePnt = aRefPoint->GetValue(); if (aShapePnt.IsNull()) return 0; if (aShapePnt.ShapeType() != TopAbs_VERTEX) return 0; aP = BRep_Tool::Pnt(TopoDS::Vertex(aShapePnt)); } // Bug 6839: Check for standalone (not included in faces) degenerated edges TopTools_IndexedDataMapOfShapeListOfShape aEFMap; TopExp::MapShapesAndAncestors(aShapeBase, TopAbs_EDGE, TopAbs_FACE, aEFMap); Standard_Integer i, nbE = aEFMap.Extent(); for (i = 1; i <= nbE; i++) { TopoDS_Shape anEdgeSh = aEFMap.FindKey(i); if (BRep_Tool::Degenerated(TopoDS::Edge(anEdgeSh))) { const TopTools_ListOfShape& aFaces = aEFMap.FindFromIndex(i); if (aFaces.IsEmpty()) Standard_ConstructionError::Raise ("Scaling aborted : cannot scale standalone degenerated edge"); } } // Perform Scaling gp_Trsf aTrsf; aTrsf.SetScale(aP, aCI.GetFactor()); BRepBuilderAPI_Transform aBRepTrsf (aShapeBase, aTrsf, Standard_False); aShape = aBRepTrsf.Shape(); } else if (aType == SCALE_SHAPE_AFFINE || aType == SCALE_SHAPE_AFFINE_COPY) { Handle(GEOM_Function) aRefShape = aCI.GetShape(); Handle(GEOM_Function) aRefVector = aCI.GetVector(); TopoDS_Shape aShapeBase = aRefShape->GetValue(); TopoDS_Shape aShapeVector = aRefVector->GetValue(); if (aShapeBase.IsNull() || aShapeVector.IsNull()) return 0; if (aShapeVector.ShapeType() != TopAbs_EDGE) return 0; TopoDS_Edge anEdgeVector = TopoDS::Edge(aShapeVector); // Bug 6839: Check for standalone (not included in faces) degenerated edges TopTools_IndexedDataMapOfShapeListOfShape aEFMap; TopExp::MapShapesAndAncestors(aShapeBase, TopAbs_EDGE, TopAbs_FACE, aEFMap); Standard_Integer i, nbE = aEFMap.Extent(); for (i = 1; i <= nbE; i++) { TopoDS_Shape anEdgeSh = aEFMap.FindKey(i); if (BRep_Tool::Degenerated(TopoDS::Edge(anEdgeSh))) { const TopTools_ListOfShape& aFaces = aEFMap.FindFromIndex(i); if (aFaces.IsEmpty()) Standard_ConstructionError::Raise ("Scaling aborted : cannot scale standalone degenerated edge"); } } //Get axis gp_Pnt aP1 = BRep_Tool::Pnt(TopExp::FirstVertex(anEdgeVector)); gp_Pnt aP2 = BRep_Tool::Pnt(TopExp::LastVertex(anEdgeVector)); gp_Dir aDir(gp_Vec(aP1, aP2)); gp_Ax2 anAx2(aP1, aDir); // Perform Scaling gp_GTrsf aGTrsf; aGTrsf.SetAffinity(anAx2, aCI.GetFactor()); BRepBuilderAPI_GTransform aBRepGTrsf(aShapeBase, aGTrsf, Standard_False); aShape = aBRepGTrsf.Shape(); } else if (aType == SCALE_SHAPE_AXES || aType == SCALE_SHAPE_AXES_COPY) { Handle(GEOM_Function) aRefShape = aCI.GetShape(); TopoDS_Shape aShapeBase = aRefShape->GetValue(); if (aShapeBase.IsNull()) return 0; bool isP = false; gp_Pnt aP (0,0,0); Handle(GEOM_Function) aRefPoint = aCI.GetPoint(); if (!aRefPoint.IsNull()) { TopoDS_Shape aShapePnt = aRefPoint->GetValue(); if (aShapePnt.IsNull()) return 0; if (aShapePnt.ShapeType() != TopAbs_VERTEX) return 0; aP = BRep_Tool::Pnt(TopoDS::Vertex(aShapePnt)); isP = true; } // Bug 6839: Check for standalone (not included in faces) degenerated edges TopTools_IndexedDataMapOfShapeListOfShape aEFMap; TopExp::MapShapesAndAncestors(aShapeBase, TopAbs_EDGE, TopAbs_FACE, aEFMap); Standard_Integer i, nbE = aEFMap.Extent(); for (i = 1; i <= nbE; i++) { TopoDS_Shape anEdgeSh = aEFMap.FindKey(i); if (BRep_Tool::Degenerated(TopoDS::Edge(anEdgeSh))) { const TopTools_ListOfShape& aFaces = aEFMap.FindFromIndex(i); if (aFaces.IsEmpty()) Standard_ConstructionError::Raise ("Scaling aborted : cannot scale standalone degenerated edge"); } } // Perform Scaling gp_GTrsf aGTrsf; gp_Mat rot (aCI.GetFactorX(), 0, 0, 0, aCI.GetFactorY(), 0, 0, 0, aCI.GetFactorZ()); aGTrsf.SetVectorialPart(rot); if (isP) { gp_Pnt anO (0,0,0); if (anO.Distance(aP) > Precision::Confusion()) { gp_GTrsf aGTrsfP0; aGTrsfP0.SetTranslationPart(anO.XYZ() - aP.XYZ()); gp_GTrsf aGTrsf0P; aGTrsf0P.SetTranslationPart(aP.XYZ()); //aGTrsf = aGTrsf0P * aGTrsf * aGTrsfP0; aGTrsf = aGTrsf0P.Multiplied(aGTrsf); aGTrsf = aGTrsf.Multiplied(aGTrsfP0); } } BRepBuilderAPI_GTransform aBRepGTrsf (aShapeBase, aGTrsf, Standard_False); if (!aBRepGTrsf.IsDone()) Standard_ConstructionError::Raise("Scaling not done"); aShape = aBRepGTrsf.Shape(); } else { } if (aShape.IsNull()) return 0; // Check shape validity BRepCheck_Analyzer ana (aShape, false); if (!ana.IsValid()) { ShapeFix_ShapeTolerance aSFT; aSFT.LimitTolerance(aShape,Precision::Confusion(),Precision::Confusion()); Handle(ShapeFix_Shape) aSfs = new ShapeFix_Shape(aShape); aSfs->SetPrecision(Precision::Confusion()); aSfs->Perform(); aShape = aSfs->Shape(); ana.Init(aShape, Standard_False); if (!ana.IsValid()) { Standard_CString anErrStr("Scaling aborted : non valid shape result"); #ifdef THROW_ON_INVALID_SH Standard_ConstructionError::Raise(anErrStr); #else MESSAGE(anErrStr); //further processing can be performed here //... //in case of failure of automatic treatment //mark the corresponding GEOM_Object as problematic TDF_Label aLabel = aFunction->GetOwnerEntry(); if (!aLabel.IsRoot()) { Handle(GEOM_Object) aMainObj = GEOM_Object::GetObject(aLabel); if (!aMainObj.IsNull()) aMainObj->SetDirty(Standard_True); } #endif } } aFunction->SetValue(aShape); log.SetTouched(Label()); return 1; }
//======================================================================= //function : Execute //purpose : //======================================================================= Standard_Integer GEOMImpl_CircleDriver::Execute(TFunction_Logbook& log) const { if (Label().IsNull()) return 0; Handle(GEOM_Function) aFunction = GEOM_Function::GetFunction(Label()); GEOMImpl_ICircle aCI (aFunction); Standard_Integer aType = aFunction->GetType(); TopoDS_Shape aShape; if (aType == CIRCLE_PNT_VEC_R) { // Center gp_Pnt aP = gp::Origin(); Handle(GEOM_Function) aRefPoint = aCI.GetCenter(); if (!aRefPoint.IsNull()) { TopoDS_Shape aShapePnt = aRefPoint->GetValue(); if (aShapePnt.ShapeType() != TopAbs_VERTEX) { Standard_ConstructionError::Raise ("Circle creation aborted: invalid center argument, must be a point"); } aP = BRep_Tool::Pnt(TopoDS::Vertex(aShapePnt)); } // Normal gp_Vec aV = gp::DZ(); Handle(GEOM_Function) aRefVector = aCI.GetVector(); if (!aRefVector.IsNull()) { TopoDS_Shape aShapeVec = aRefVector->GetValue(); if (aShapeVec.ShapeType() != TopAbs_EDGE) { Standard_ConstructionError::Raise ("Circle creation aborted: invalid vector argument, must be a vector or an edge"); } TopoDS_Edge anE = TopoDS::Edge(aShapeVec); TopoDS_Vertex V1, V2; TopExp::Vertices(anE, V1, V2, Standard_True); if (!V1.IsNull() && !V2.IsNull()) { aV = gp_Vec(BRep_Tool::Pnt(V1), BRep_Tool::Pnt(V2)); if (aV.Magnitude() < gp::Resolution()) { Standard_ConstructionError::Raise ("Circle creation aborted: vector of zero length is given"); } } } // Axes gp_Ax2 anAxes (aP, aV); // Radius double anR = aCI.GetRadius(); char aMsg[] = "Circle creation aborted: radius value less than 1e-07 is not acceptable"; if (anR < Precision::Confusion()) Standard_ConstructionError::Raise(aMsg); // Circle gp_Circ aCirc (anAxes, anR); aShape = BRepBuilderAPI_MakeEdge(aCirc).Edge(); } else if (aType == CIRCLE_CENTER_TWO_PNT) { Handle(GEOM_Function) aRefPoint1 = aCI.GetPoint1(); Handle(GEOM_Function) aRefPoint2 = aCI.GetPoint2(); Handle(GEOM_Function) aRefPoint3 = aCI.GetPoint3(); TopoDS_Shape aShapePnt1 = aRefPoint1->GetValue(); TopoDS_Shape aShapePnt2 = aRefPoint2->GetValue(); TopoDS_Shape aShapePnt3 = aRefPoint3->GetValue(); if (aShapePnt1.ShapeType() == TopAbs_VERTEX && aShapePnt2.ShapeType() == TopAbs_VERTEX && aShapePnt3.ShapeType() == TopAbs_VERTEX) { gp_Pnt aP1 = BRep_Tool::Pnt(TopoDS::Vertex(aShapePnt1)); gp_Pnt aP2 = BRep_Tool::Pnt(TopoDS::Vertex(aShapePnt2)); gp_Pnt aP3 = BRep_Tool::Pnt(TopoDS::Vertex(aShapePnt3)); if (aP1.Distance(aP2) < gp::Resolution() || aP1.Distance(aP3) < gp::Resolution() || aP2.Distance(aP3) < gp::Resolution()) Standard_ConstructionError::Raise("Circle creation aborted: coincident points given"); if (gp_Vec(aP1, aP2).IsParallel(gp_Vec(aP1, aP3), Precision::Angular())) Standard_ConstructionError::Raise("Circle creation aborted: points lay on one line"); double x, y, z, x1, y1, z1, x2, y2, z2, dx, dy, dz, dx2, dy2, dz2, dx3, dy3, dz3, aRadius; //Calculations for Radius x = aP1.X(); y = aP1.Y(); z = aP1.Z(); x1 = aP2.X(); y1 = aP2.Y(); z1 = aP2.Z(); dx = x1 - x; dy = y1 - y; dz = z1 - z; aRadius = sqrt(dx*dx + dy*dy + dz*dz); //Calculations for Plane Vector x2 = aP3.X(); y2 = aP3.Y(); z2 = aP3.Z(); dx2 = x2 - x; dy2 = y2 - y; dz2 = z2 - z; dx3 = ((dy*dz2) - (dy2*dz))/100; dy3 = ((dx2*dz) - (dx*dz2))/100; dz3 = ((dx*dy2) - (dx2*dy))/100; //Make Plane Vector gp_Dir aDir ( dx3, dy3, dz3 ); //Make Circle gp_Ax2 anAxes (aP1, aDir); gp_Circ aCirc (anAxes, aRadius); aShape = BRepBuilderAPI_MakeEdge(aCirc).Edge(); } } else if (aType == CIRCLE_THREE_PNT) { Handle(GEOM_Function) aRefPoint1 = aCI.GetPoint1(); Handle(GEOM_Function) aRefPoint2 = aCI.GetPoint2(); Handle(GEOM_Function) aRefPoint3 = aCI.GetPoint3(); TopoDS_Shape aShapePnt1 = aRefPoint1->GetValue(); TopoDS_Shape aShapePnt2 = aRefPoint2->GetValue(); TopoDS_Shape aShapePnt3 = aRefPoint3->GetValue(); if (aShapePnt1.ShapeType() == TopAbs_VERTEX && aShapePnt2.ShapeType() == TopAbs_VERTEX && aShapePnt3.ShapeType() == TopAbs_VERTEX) { gp_Pnt aP1 = BRep_Tool::Pnt(TopoDS::Vertex(aShapePnt1)); gp_Pnt aP2 = BRep_Tool::Pnt(TopoDS::Vertex(aShapePnt2)); gp_Pnt aP3 = BRep_Tool::Pnt(TopoDS::Vertex(aShapePnt3)); if (aP1.Distance(aP2) < gp::Resolution() || aP1.Distance(aP3) < gp::Resolution() || aP2.Distance(aP3) < gp::Resolution()) Standard_ConstructionError::Raise("Circle creation aborted: coincident points given"); if (gp_Vec(aP1, aP2).IsParallel(gp_Vec(aP1, aP3), Precision::Angular())) Standard_ConstructionError::Raise("Circle creation aborted: points lay on one line"); Handle(Geom_Circle) aCirc = GC_MakeCircle(aP1, aP2, aP3).Value(); aShape = BRepBuilderAPI_MakeEdge(aCirc).Edge(); } } else { } if (aShape.IsNull()) return 0; aFunction->SetValue(aShape); log.SetTouched(Label()); return 1; }
//======================================================================= //function : GetMinDistanceSingular //purpose : //======================================================================= double GEOMUtils::GetMinDistanceSingular(const TopoDS_Shape& aSh1, const TopoDS_Shape& aSh2, gp_Pnt& Ptmp1, gp_Pnt& Ptmp2) { TopoDS_Shape tmpSh1; TopoDS_Shape tmpSh2; Standard_Real AddDist1 = 0.; Standard_Real AddDist2 = 0.; Standard_Boolean IsChange1 = ModifyShape(aSh1, tmpSh1, AddDist1); Standard_Boolean IsChange2 = ModifyShape(aSh2, tmpSh2, AddDist2); if( !IsChange1 && !IsChange2 ) return -2.0; BRepExtrema_DistShapeShape dst(tmpSh1,tmpSh2); if (dst.IsDone()) { double MinDist = 1.e9; gp_Pnt PMin1, PMin2, P1, P2; for (int i = 1; i <= dst.NbSolution(); i++) { P1 = dst.PointOnShape1(i); P2 = dst.PointOnShape2(i); Standard_Real Dist = P1.Distance(P2); if (MinDist > Dist) { MinDist = Dist; PMin1 = P1; PMin2 = P2; } } if(MinDist<1.e-7) { Ptmp1 = PMin1; Ptmp2 = PMin2; } else { gp_Dir aDir(gp_Vec(PMin1,PMin2)); if( MinDist > (AddDist1+AddDist2) ) { Ptmp1 = gp_Pnt( PMin1.X() + aDir.X()*AddDist1, PMin1.Y() + aDir.Y()*AddDist1, PMin1.Z() + aDir.Z()*AddDist1 ); Ptmp2 = gp_Pnt( PMin2.X() - aDir.X()*AddDist2, PMin2.Y() - aDir.Y()*AddDist2, PMin2.Z() - aDir.Z()*AddDist2 ); return (MinDist - AddDist1 - AddDist2); } else { if( AddDist1 > 0 ) { Ptmp1 = gp_Pnt( PMin1.X() + aDir.X()*AddDist1, PMin1.Y() + aDir.Y()*AddDist1, PMin1.Z() + aDir.Z()*AddDist1 ); Ptmp2 = Ptmp1; } else { Ptmp2 = gp_Pnt( PMin2.X() - aDir.X()*AddDist2, PMin2.Y() - aDir.Y()*AddDist2, PMin2.Z() - aDir.Z()*AddDist2 ); Ptmp1 = Ptmp2; } } } double res = MinDist - AddDist1 - AddDist2; if(res<0.) res = 0.0; return res; } return -2.0; }
void ScanDiskThirdPartyPM::scan(const QString& path, Job* job, int level, QStringList& ignore) const { if (ignore.contains(path)) return; QDir aDir(path); QMap<QString, QString> path2sha1; DBRepository* r = DBRepository::getDefault(); QString err; QList<PackageVersion*> packageVersions = r->getPackageVersionsWithDetectFiles(&err); // qDebug() << "package versions with detect files: " << packageVersions.count(); if (!err.isEmpty()) job->setErrorMessage(err); for (int i = 0; i < packageVersions.count(); i++) { if (!job->shouldProceed()) break; PackageVersion* pv = packageVersions.at(i); if (!pv->installed() && pv->detectFiles.count() > 0) { boolean ok = true; for (int j = 0; j < pv->detectFiles.count(); j++) { bool fileOK = false; DetectFile* df = pv->detectFiles.at(j); if (aDir.exists(df->path)) { QString fullPath = path + "\\" + df->path; QFileInfo f(fullPath); if (f.isFile() && f.isReadable()) { QString sha1 = path2sha1.value(df->path); if (sha1.isEmpty()) { sha1 = WPMUtils::sha1(fullPath); path2sha1[df->path] = sha1; } if (df->sha1 == sha1) { fileOK = true; } } } if (!fileOK) { ok = false; break; } } if (ok) { pv->setPath(path); return; } } } if (job && !job->isCancelled()) { QFileInfoList entries = aDir.entryInfoList( QDir::NoDotAndDotDot | QDir::Dirs); int count = entries.size(); for (int idx = 0; idx < count; idx++) { if (job && job->isCancelled()) break; QFileInfo entryInfo = entries[idx]; QString name = entryInfo.fileName(); if (job) { job->setTitle(name); if (job->isCancelled()) break; } Job* djob; if (level < 2) djob = job->newSubJob(1.0 / count); else djob = 0; scan(path + "\\" + name.toLower(), djob, level + 1, ignore); if (job) { job->setProgress(((double) idx) / count); } } } qDeleteAll(packageVersions); if (job) job->complete(); }
TopoDS_Shape MakeBottle(const Standard_Real myWidth, const Standard_Real myHeight, const Standard_Real myThickness) { // Profile : Define Support Points gp_Pnt aPnt1(-myWidth / 2., 0, 0); gp_Pnt aPnt2(-myWidth / 2., -myThickness / 4., 0); gp_Pnt aPnt3(0, -myThickness / 2., 0); gp_Pnt aPnt4(myWidth / 2., -myThickness / 4., 0); gp_Pnt aPnt5(myWidth / 2., 0, 0); // Profile : Define the Geometry Handle(Geom_TrimmedCurve) anArcOfCircle = GC_MakeArcOfCircle(aPnt2,aPnt3,aPnt4); Handle(Geom_TrimmedCurve) aSegment1 = GC_MakeSegment(aPnt1, aPnt2); Handle(Geom_TrimmedCurve) aSegment2 = GC_MakeSegment(aPnt4, aPnt5); // Profile : Define the Topology TopoDS_Edge anEdge1 = BRepBuilderAPI_MakeEdge(aSegment1); TopoDS_Edge anEdge2 = BRepBuilderAPI_MakeEdge(anArcOfCircle); TopoDS_Edge anEdge3 = BRepBuilderAPI_MakeEdge(aSegment2); TopoDS_Wire aWire = BRepBuilderAPI_MakeWire(anEdge1, anEdge2, anEdge3); // Complete Profile gp_Ax1 xAxis = gp::OX(); gp_Trsf aTrsf; aTrsf.SetMirror(xAxis); BRepBuilderAPI_Transform aBRepTrsf(aWire, aTrsf); TopoDS_Shape aMirroredShape = aBRepTrsf.Shape(); TopoDS_Wire aMirroredWire = TopoDS::Wire(aMirroredShape); BRepBuilderAPI_MakeWire mkWire; mkWire.Add(aWire); mkWire.Add(aMirroredWire); TopoDS_Wire myWireProfile = mkWire.Wire(); // Body : Prism the Profile TopoDS_Face myFaceProfile = BRepBuilderAPI_MakeFace(myWireProfile); gp_Vec aPrismVec(0, 0, myHeight); TopoDS_Shape myBody = BRepPrimAPI_MakePrism(myFaceProfile, aPrismVec); // Body : Apply Fillets BRepFilletAPI_MakeFillet mkFillet(myBody); TopExp_Explorer anEdgeExplorer(myBody, TopAbs_EDGE); while(anEdgeExplorer.More()) { TopoDS_Edge anEdge = TopoDS::Edge(anEdgeExplorer.Current()); //Add edge to fillet algorithm mkFillet.Add(myThickness / 12., anEdge); anEdgeExplorer.Next(); } myBody = mkFillet.Shape(); // Body : Add the Neck gp_Pnt neckLocation(0, 0, myHeight); gp_Dir neckAxis = gp::DZ(); gp_Ax2 neckAx2(neckLocation, neckAxis); Standard_Real myNeckRadius = myThickness / 4.; Standard_Real myNeckHeight = myHeight / 10.; BRepPrimAPI_MakeCylinder MKCylinder(neckAx2, myNeckRadius, myNeckHeight); TopoDS_Shape myNeck = MKCylinder.Shape(); myBody = BRepAlgoAPI_Fuse(myBody, myNeck); // Body : Create a Hollowed Solid TopoDS_Face faceToRemove; Standard_Real zMax = -1; for(TopExp_Explorer aFaceExplorer(myBody, TopAbs_FACE); aFaceExplorer.More(); aFaceExplorer.Next()) { TopoDS_Face aFace = TopoDS::Face(aFaceExplorer.Current()); // Check if <aFace> is the top face of the bottle�s neck Handle(Geom_Surface) aSurface = BRep_Tool::Surface(aFace); if(aSurface->DynamicType() == STANDARD_TYPE(Geom_Plane)) { Handle(Geom_Plane) aPlane = Handle(Geom_Plane)::DownCast(aSurface); gp_Pnt aPnt = aPlane->Location(); Standard_Real aZ = aPnt.Z(); if(aZ > zMax) { zMax = aZ; faceToRemove = aFace; } } } TopTools_ListOfShape facesToRemove; facesToRemove.Append(faceToRemove); myBody = BRepOffsetAPI_MakeThickSolid(myBody, facesToRemove, -myThickness / 50, 1.e-3); // Threading : Create Surfaces Handle(Geom_CylindricalSurface) aCyl1 = new Geom_CylindricalSurface(neckAx2, myNeckRadius * 0.99); Handle(Geom_CylindricalSurface) aCyl2 = new Geom_CylindricalSurface(neckAx2, myNeckRadius * 1.05); // Threading : Define 2D Curves gp_Pnt2d aPnt(2. * M_PI, myNeckHeight / 2.); gp_Dir2d aDir(2. * M_PI, myNeckHeight / 4.); gp_Ax2d anAx2d(aPnt, aDir); Standard_Real aMajor = 2. * M_PI; Standard_Real aMinor = myNeckHeight / 10; Handle(Geom2d_Ellipse) anEllipse1 = new Geom2d_Ellipse(anAx2d, aMajor, aMinor); Handle(Geom2d_Ellipse) anEllipse2 = new Geom2d_Ellipse(anAx2d, aMajor, aMinor / 4); Handle(Geom2d_TrimmedCurve) anArc1 = new Geom2d_TrimmedCurve(anEllipse1, 0, M_PI); Handle(Geom2d_TrimmedCurve) anArc2 = new Geom2d_TrimmedCurve(anEllipse2, 0, M_PI); gp_Pnt2d anEllipsePnt1 = anEllipse1->Value(0); gp_Pnt2d anEllipsePnt2 = anEllipse1->Value(M_PI); Handle(Geom2d_TrimmedCurve) aSegment = GCE2d_MakeSegment(anEllipsePnt1, anEllipsePnt2); // Threading : Build Edges and Wires TopoDS_Edge anEdge1OnSurf1 = BRepBuilderAPI_MakeEdge(anArc1, aCyl1); TopoDS_Edge anEdge2OnSurf1 = BRepBuilderAPI_MakeEdge(aSegment, aCyl1); TopoDS_Edge anEdge1OnSurf2 = BRepBuilderAPI_MakeEdge(anArc2, aCyl2); TopoDS_Edge anEdge2OnSurf2 = BRepBuilderAPI_MakeEdge(aSegment, aCyl2); TopoDS_Wire threadingWire1 = BRepBuilderAPI_MakeWire(anEdge1OnSurf1, anEdge2OnSurf1); TopoDS_Wire threadingWire2 = BRepBuilderAPI_MakeWire(anEdge1OnSurf2, anEdge2OnSurf2); BRepLib::BuildCurves3d(threadingWire1); BRepLib::BuildCurves3d(threadingWire2); // Create Threading BRepOffsetAPI_ThruSections aTool(Standard_True); aTool.AddWire(threadingWire1); aTool.AddWire(threadingWire2); aTool.CheckCompatibility(Standard_False); TopoDS_Shape myThreading = aTool.Shape(); // Building the Resulting Compound TopoDS_Compound aRes; BRep_Builder aBuilder; aBuilder.MakeCompound (aRes); aBuilder.Add (aRes, myBody); aBuilder.Add (aRes, myThreading); return aRes; }