void CylinderFit::ProjectToCylinder() { Base::Vector3f cBase(GetBase()); Base::Vector3f cAxis(GetAxis()); for (std::list< Base::Vector3f >::iterator it = _vPoints.begin(); it != _vPoints.end(); ++it) { Base::Vector3f& cPnt = *it; if (cPnt.DistanceToLine(cBase, cAxis) > 0) { Base::Vector3f proj; cBase.ProjectToPlane(cPnt, cAxis, proj); Base::Vector3f diff = cPnt - proj; diff.Normalize(); cPnt = proj + diff * _fRadius; } else { // Point is on the cylinder axis, so it can be moved in // any direction perpendicular to the cylinder axis Base::Vector3f cMov(cPnt); do { float x = ((float)rand() / (float)RAND_MAX); float y = ((float)rand() / (float)RAND_MAX); float z = ((float)rand() / (float)RAND_MAX); cMov.Move(x,y,z); } while (cMov.DistanceToLine(cBase, cAxis) == 0); Base::Vector3f proj; cMov.ProjectToPlane(cPnt, cAxis, proj); Base::Vector3f diff = cPnt - proj; diff.Normalize(); cPnt = proj + diff * _fRadius; } } }
void MeshObject::offsetSpecial(float fSize, float zmax, float zmin) { std::vector<Base::Vector3f> normals = _kernel.CalcVertexNormals(); unsigned int i = 0; // go through all the vertex normals for (std::vector<Base::Vector3f>::iterator It= normals.begin();It != normals.end();It++,i++) { Base::Vector3f Pnt = _kernel.GetPoint(i); if (Pnt.z < zmax && Pnt.z > zmin) { Pnt.z = 0; _kernel.MovePoint(i,Pnt.Normalize() * fSize); } else { // and move each mesh point in the normal direction _kernel.MovePoint(i,It->Normalize() * fSize); } } }
void MeshAlgos::offsetSpecial(MeshCore::MeshKernel* Mesh, float fSize, float zmax, float zmin) { std::vector<Base::Vector3f> normals = Mesh->CalcVertexNormals(); unsigned int i = 0; // go throug all the Vertex normales for(std::vector<Base::Vector3f>::iterator It= normals.begin();It != normals.end();++It,i++) { Base::Vector3f Pnt = Mesh->GetPoint(i); if(Pnt.z < zmax && Pnt.z > zmin) { Pnt.z = 0; Mesh->MovePoint(i,Pnt.Normalize() * fSize); }else // and move each mesh point in the normal direction Mesh->MovePoint(i,It->Normalize() * fSize); } }
void MeshAlgos::LoftOnCurve(MeshCore::MeshKernel &ResultMesh, const TopoDS_Shape &Shape, const std::vector<Base::Vector3f> &poly, const Base::Vector3f & up, float MaxSize) { TopExp_Explorer Ex; Standard_Real fBegin, fEnd; std::vector<MeshGeomFacet> cVAry; std::map<TopoDS_Vertex,std::vector<Base::Vector3f>,_VertexCompare> ConnectMap; for (Ex.Init(Shape, TopAbs_EDGE); Ex.More(); Ex.Next()) { // get the edge and the belonging Vertexes TopoDS_Edge Edge = (TopoDS_Edge&)Ex.Current(); TopoDS_Vertex V1, V2; TopExp::Vertices(Edge, V1, V2); bool bBegin = false,bEnd = false; // geting the geometric curve and the interval GeomLProp_CLProps prop(BRep_Tool::Curve(Edge,fBegin,fEnd),1,0.0000000001); int res = int((fEnd - fBegin)/MaxSize); // do at least 2 segments if(res < 2) res = 2; gp_Dir Tangent; std::vector<Base::Vector3f> prePoint(poly.size()); std::vector<Base::Vector3f> actPoint(poly.size()); // checking if there is already a end to conect if(ConnectMap.find(V1) != ConnectMap.end() ){ bBegin = true; prePoint = ConnectMap[V1]; } if(ConnectMap.find(V2) != ConnectMap.end() ) bEnd = true; for (long i = 0; i < res; i++) { // get point and tangent at the position, up is fix for the moment prop.SetParameter(fBegin + ((fEnd - fBegin) * float(i)) / float(res-1)); prop.Tangent(Tangent); Base::Vector3f Tng((float)Tangent.X(), (float)Tangent.Y(), (float)Tangent.Z()); Base::Vector3f Ptn((float)prop.Value().X(), (float)prop.Value().Y(), (float)prop.Value().Z()); Base::Vector3f Up (up); // normalize and calc the third vector of the plane coordinatesystem Tng.Normalize(); Up.Normalize(); Base::Vector3f Third(Tng%Up); // Base::Console().Log("Pos: %f %f %f \n",Ptn.x,Ptn.y,Ptn.z); unsigned int l=0; std::vector<Base::Vector3f>::const_iterator It; // got through the profile for(It=poly.begin();It!=poly.end();++It,l++) actPoint[l] = ((Third*It->x)+(Up*It->y)+(Tng*It->z)+Ptn); if(i == res-1 && !bEnd) // remeber the last row to conect to a otger edge with the same vertex ConnectMap[V2] = actPoint; if(i==1 && bBegin) // using the end of an other edge as start prePoint = ConnectMap[V1]; if(i==0 && !bBegin) // remember the first row for conection to a edge with the same vertex ConnectMap[V1] = actPoint; if(i ) // not the first row or somthing to conect to { for(l=0;l<actPoint.size();l++) { if(l) // not first point in row { if(i == res-1 && bEnd) // if last row and a end to conect actPoint = ConnectMap[V2]; Base::Vector3f p1 = prePoint[l-1], p2 = actPoint[l-1], p3 = prePoint[l], p4 = actPoint[l]; cVAry.push_back(MeshGeomFacet(p1,p2,p3)); cVAry.push_back(MeshGeomFacet(p3,p2,p4)); } } } prePoint = actPoint; } } ResultMesh.AddFacets(cVAry); }
void CurveProjectorWithToolMesh::makeToolMesh( const TopoDS_Edge& aEdge,std::vector<MeshGeomFacet> &cVAry ) { Standard_Real fBegin, fEnd; Handle(Geom_Curve) hCurve = BRep_Tool::Curve(aEdge,fBegin,fEnd); float fLen = float(fEnd - fBegin); Base::Vector3f cResultPoint; unsigned long ulNbOfPoints = 15,PointCount=0/*,uCurFacetIdx*/; std::vector<LineSeg> LineSegs; MeshFacetIterator It(_Mesh); Base::SequencerLauncher seq("Building up tool mesh...", ulNbOfPoints+1); std::map<unsigned long,std::vector<Base::Vector3f> > FaceProjctMap; for (unsigned long i = 0; i < ulNbOfPoints; i++) { seq.next(); gp_Pnt gpPt = hCurve->Value(fBegin + (fLen * float(i)) / float(ulNbOfPoints-1)); Base::Vector3f LinePoint((float)gpPt.X(), (float)gpPt.Y(), (float)gpPt.Z()); Base::Vector3f ResultNormal; // go through the whole Mesh for(It.Init();It.More();It.Next()) { // try to project (with angle) to the face if (It->IntersectWithLine (Base::Vector3f((float)gpPt.X(),(float)gpPt.Y(),(float)gpPt.Z()), It->GetNormal(), cResultPoint) ) { if(Base::Distance(LinePoint,cResultPoint) < 0.5) ResultNormal += It->GetNormal(); } } LineSeg s; s.p = Base::Vector3f((float)gpPt.X(), (float)gpPt.Y(), (float)gpPt.Z()); s.n = ResultNormal.Normalize(); LineSegs.push_back(s); } Base::Console().Log("Projection map [%d facets with %d points]\n",FaceProjctMap.size(),PointCount); // build up the new mesh Base::Vector3f lp(FLOAT_MAX,0,0), ln, p1, p2, p3, p4,p5,p6; float ToolSize = 0.2f; for (std::vector<LineSeg>::iterator It2=LineSegs.begin(); It2!=LineSegs.end();++It2) { if(lp.x != FLOAT_MAX) { p1 = lp + (ln * (-ToolSize)); p2 = lp + (ln * ToolSize); p3 = lp; p4 = (*It2).p; p5 = (*It2).p + ((*It2).n * (-ToolSize)); p6 = (*It2).p + ((*It2).n * ToolSize); cVAry.push_back(MeshGeomFacet(p3,p2,p6)); cVAry.push_back(MeshGeomFacet(p3,p6,p4)); cVAry.push_back(MeshGeomFacet(p1,p3,p4)); cVAry.push_back(MeshGeomFacet(p1,p4,p5)); } lp = (*It2).p; ln = (*It2).n; } }