void MeshObject::transformGeometry(const Base::Matrix4D &rclMat) { MeshCore::MeshKernel kernel; swap(kernel); kernel.Transform(rclMat); swap(kernel); }
void PropertyMeshKernel::Restore(Base::XMLReader &reader) { reader.readElement("Mesh"); std::string file (reader.getAttribute("file") ); if (file.empty()) { // read XML MeshCore::MeshKernel kernel; MeshCore::MeshInput restorer(kernel); restorer.LoadXML(reader); // avoid to duplicate the mesh in memory MeshCore::MeshPointArray points; MeshCore::MeshFacetArray facets; kernel.Adopt(points, facets); aboutToSetValue(); _meshObject->getKernel().Adopt(points, facets); hasSetValue(); } else { // initate a file read reader.addFile(file.c_str(),this); } }
static PyObject * exporter(PyObject *self, PyObject *args) { PyObject* object; char* Name; if (!PyArg_ParseTuple(args, "Oet",&object,"utf-8",&Name)) return NULL; std::string EncodedName = std::string(Name); PyMem_Free(Name); float fTolerance = 0.1f; MeshObject global_mesh; PY_TRY { Py::Sequence list(object); Base::Type meshId = Base::Type::fromName("Mesh::Feature"); Base::Type partId = Base::Type::fromName("Part::Feature"); for (Py::Sequence::iterator it = list.begin(); it != list.end(); ++it) { PyObject* item = (*it).ptr(); if (PyObject_TypeCheck(item, &(App::DocumentObjectPy::Type))) { App::DocumentObject* obj = static_cast<App::DocumentObjectPy*>(item)->getDocumentObjectPtr(); if (obj->getTypeId().isDerivedFrom(meshId)) { const MeshObject& mesh = static_cast<Mesh::Feature*>(obj)->Mesh.getValue(); MeshCore::MeshKernel kernel = mesh.getKernel(); kernel.Transform(mesh.getTransform()); if (global_mesh.countFacets() == 0) global_mesh.setKernel(kernel); else global_mesh.addMesh(kernel); } else if (obj->getTypeId().isDerivedFrom(partId)) { App::Property* shape = obj->getPropertyByName("Shape"); Base::Reference<MeshObject> mesh(new MeshObject()); if (shape && shape->getTypeId().isDerivedFrom(App::PropertyComplexGeoData::getClassTypeId())) { std::vector<Base::Vector3d> aPoints; std::vector<Data::ComplexGeoData::Facet> aTopo; static_cast<App::PropertyComplexGeoData*>(shape)->getFaces(aPoints, aTopo,fTolerance); mesh->addFacets(aTopo, aPoints); if (global_mesh.countFacets() == 0) global_mesh = *mesh; else global_mesh.addMesh(*mesh); } } else { Base::Console().Message("'%s' is not a mesh or shape, export will be ignored.\n", obj->Label.getValue()); } } } // export mesh compound global_mesh.save(EncodedName.c_str()); } PY_CATCH; Py_Return; }
void MeshConversion::convert(const pcl::PolygonMesh& pclMesh, Mesh::MeshObject& meshObject) { // number of points size_t nr_points = pclMesh.cloud.width * pclMesh.cloud.height; size_t point_size = pclMesh.cloud.data.size () / nr_points; // number of faces for header size_t nr_faces = pclMesh.polygons.size (); MeshCore::MeshPointArray points; points.reserve(nr_points); MeshCore::MeshFacetArray facets; facets.reserve(nr_faces); // get vertices MeshCore::MeshPoint vertex; for (size_t i = 0; i < nr_points; ++i) { int xyz = 0; for (size_t d = 0; d < pclMesh.cloud.fields.size(); ++d) { int c = 0; // adding vertex if ((pclMesh.cloud.fields[d].datatype == #if PCL_VERSION_COMPARE(>,1,6,0) pcl::PCLPointField::FLOAT32) && #else sensor_msgs::PointField::FLOAT32) && #endif (pclMesh.cloud.fields[d].name == "x" || pclMesh.cloud.fields[d].name == "y" || pclMesh.cloud.fields[d].name == "z")) { float value; memcpy (&value, &pclMesh.cloud.data[i * point_size + pclMesh.cloud.fields[d].offset + c * sizeof (float)], sizeof (float)); vertex[xyz] = value; if (++xyz == 3) { points.push_back(vertex); break; } } } } // get faces MeshCore::MeshFacet face; for (size_t i = 0; i < nr_faces; i++) { face._aulPoints[0] = pclMesh.polygons[i].vertices[0]; face._aulPoints[1] = pclMesh.polygons[i].vertices[1]; face._aulPoints[2] = pclMesh.polygons[i].vertices[2]; facets.push_back(face); } MeshCore::MeshKernel kernel; kernel.Adopt(points, facets, true); meshObject.swap(kernel); meshObject.harmonizeNormals(); }
static PyObject * calculateEigenTransform(PyObject *self, PyObject *args) { PyObject *input; if (!PyArg_ParseTuple(args, "O",&input)) return NULL; if(! PySequence_Check(input) ){ PyErr_SetString(Base::BaseExceptionFreeCADError, "Input have to be a sequence of Base.Vector()"); return NULL; } PY_TRY { MeshCore::MeshKernel aMesh; MeshCore::MeshPointArray vertices; vertices.clear(); MeshCore::MeshFacetArray faces; faces.clear(); MeshCore::MeshPoint current_node; Py::Sequence list(input); for (Py::Sequence::iterator it = list.begin(); it != list.end(); ++it) { PyObject* value = (*it).ptr(); if (PyObject_TypeCheck(value, &(Base::VectorPy::Type))) { Base::VectorPy *pcObject = static_cast<Base::VectorPy*>(value); Base::Vector3d* val = pcObject->getVectorPtr(); current_node.Set(float(val->x),float(val->y),float(val->z)); vertices.push_back(current_node); } } MeshCore::MeshFacet aFacet; aFacet._aulPoints[0] = 0;aFacet._aulPoints[1] = 1;aFacet._aulPoints[2] = 2; faces.push_back(aFacet); //Fill the Kernel with the temp smesh structure and delete the current containers aMesh.Adopt(vertices,faces); MeshCore::MeshEigensystem pca(aMesh); pca.Evaluate(); Base::Matrix4D Trafo = pca.Transform(); return new Base::PlacementPy(new Base::Placement(Trafo) ); } PY_CATCH; Py_Return; }
MeshObject* MeshObject::meshFromSegment(const std::vector<unsigned long>& indices) const { MeshCore::MeshFacetArray facets; facets.reserve(indices.size()); const MeshCore::MeshPointArray& kernel_p = _kernel.GetPoints(); const MeshCore::MeshFacetArray& kernel_f = _kernel.GetFacets(); for (std::vector<unsigned long>::const_iterator it = indices.begin(); it != indices.end(); ++it) { facets.push_back(kernel_f[*it]); } MeshCore::MeshKernel kernel; kernel.Merge(kernel_p, facets); return new MeshObject(kernel, _Mtrx); }
virtual void Append(const MeshCore::MeshKernel& kernel, unsigned long index) { unsigned long ulP1, ulP2, ulP3; kernel.GetFacetPoints(index, ulP1, ulP2, ulP3); indices.insert(ulP1); indices.insert(ulP2); indices.insert(ulP3); }
double UniGridApprox::CompMeshError() { Base::Builder3D log3d; MeshCore::MeshKernel mesh; BRepBuilderAPI_MakeFace Face(aAdaptorSurface.BSpline()); GeomAPI_ProjectPointOnSurf proj; best_fit::Tesselate_Face(Face.Face(), mesh, float(0.1)); cout << mesh.CountPoints() << endl; std::vector<Base::Vector3f> normals = best_fit::Comp_Normals(mesh); double tmp = 0.0, sqrdis; double errSum = 0.0; int c=0; m_err.clear(); m_err.resize(mesh.CountPoints(), 0.0); MeshCore::MeshFacetGrid aFacetGrid(m_Mesh); MeshCore::MeshAlgorithm malg(m_Mesh); MeshCore::MeshAlgorithm malg2(m_Mesh); MeshCore::MeshPointIterator p_it(mesh); Base::Vector3f projPoint, distVec, pnt; unsigned long facetIndex; for (p_it.Begin(); p_it.More(); p_it.Next()) { if (!malg.NearestFacetOnRay(*p_it, normals[p_it.Position()], aFacetGrid, projPoint, facetIndex)) // gridoptimiert { if (malg2.NearestFacetOnRay(*p_it, normals[p_it.Position()], projPoint, facetIndex)) { pnt.x = p_it->x; pnt.y = p_it->y; pnt.z = p_it->z; log3d.addSingleLine(pnt,projPoint); distVec = projPoint - pnt; sqrdis = distVec*distVec; } else { cout << "oops, "; continue; } } else { pnt.x = p_it->x; pnt.y = p_it->y; pnt.z = p_it->z; log3d.addSingleLine(pnt,projPoint); distVec = projPoint - pnt; sqrdis = distVec*distVec; } errSum += sqrt(sqrdis); ++c; if (sqrt(sqrdis) > tmp) { m_err[p_it.Position()] = sqrt(sqrdis); tmp = m_err[p_it.Position()]; } } log3d.saveToFile("c:/Error.iv"); return errSum/c; }
Mesh::MeshObject* Mesher::createMesh() const { // OCC standard mesher if (method == Standard) { Handle_StlMesh_Mesh aMesh = new StlMesh_Mesh(); if (!shape.IsNull()) { BRepTools::Clean(shape); #if OCC_VERSION_HEX >= 0x060801 BRepMesh_IncrementalMesh bMesh(shape, deflection, Standard_False, angularDeflection); StlTransfer::RetrieveMesh(shape,aMesh); #else StlTransfer::BuildIncrementalMesh(shape, deflection, #if OCC_VERSION_HEX >= 0x060503 Standard_True, #endif aMesh); #endif } std::map<uint32_t, std::vector<std::size_t> > colorMap; for (std::size_t i=0; i<colors.size(); i++) { colorMap[colors[i]].push_back(i); } bool createSegm = (static_cast<int>(colors.size()) == aMesh->NbDomains()); MeshCore::MeshFacetArray faces; faces.reserve(aMesh->NbTriangles()); std::set<Vertex> vertices; Standard_Real x1, y1, z1; Standard_Real x2, y2, z2; Standard_Real x3, y3, z3; std::vector< std::vector<unsigned long> > meshSegments; std::size_t numMeshFaces = 0; StlMesh_MeshExplorer xp(aMesh); for (Standard_Integer nbd=1;nbd<=aMesh->NbDomains();nbd++) { std::size_t numDomainFaces = 0; for (xp.InitTriangle(nbd); xp.MoreTriangle(); xp.NextTriangle()) { xp.TriangleVertices(x1,y1,z1,x2,y2,z2,x3,y3,z3); std::set<Vertex>::iterator it; MeshCore::MeshFacet face; // 1st vertex Vertex v1(x1,y1,z1); it = vertices.find(v1); if (it == vertices.end()) { v1.i = vertices.size(); face._aulPoints[0] = v1.i; vertices.insert(v1); } else { face._aulPoints[0] = it->i; } // 2nd vertex Vertex v2(x2,y2,z2); it = vertices.find(v2); if (it == vertices.end()) { v2.i = vertices.size(); face._aulPoints[1] = v2.i; vertices.insert(v2); } else { face._aulPoints[1] = it->i; } // 3rd vertex Vertex v3(x3,y3,z3); it = vertices.find(v3); if (it == vertices.end()) { v3.i = vertices.size(); face._aulPoints[2] = v3.i; vertices.insert(v3); } else { face._aulPoints[2] = it->i; } // make sure that we don't insert invalid facets if (face._aulPoints[0] != face._aulPoints[1] && face._aulPoints[1] != face._aulPoints[2] && face._aulPoints[2] != face._aulPoints[0]) { faces.push_back(face); numDomainFaces++; } } // add a segment for the face if (createSegm || this->segments) { std::vector<unsigned long> segment(numDomainFaces); std::generate(segment.begin(), segment.end(), Base::iotaGen<unsigned long>(numMeshFaces)); numMeshFaces += numDomainFaces; meshSegments.push_back(segment); } } MeshCore::MeshPointArray verts; verts.resize(vertices.size()); for (auto it : vertices) verts[it.i] = it.toPoint(); MeshCore::MeshKernel kernel; kernel.Adopt(verts, faces, true); Mesh::MeshObject* meshdata = new Mesh::MeshObject(); meshdata->swap(kernel); if (createSegm) { int index = 0; for (auto it : colorMap) { Mesh::Segment segm(meshdata, false); for (auto jt : it.second) { segm.addIndices(meshSegments[jt]); } segm.save(true); std::stringstream str; str << "patch" << index++; segm.setName(str.str()); meshdata->addSegment(segm); } } else { for (auto it : meshSegments) { meshdata->addSegment(it); } } return meshdata; } #ifndef HAVE_SMESH throw Base::Exception("SMESH is not available on this platform"); #else std::list<SMESH_Hypothesis*> hypoth; SMESH_Gen* meshgen = SMESH_Gen::get(); SMESH_Mesh* mesh = meshgen->CreateMesh(0, true); int hyp=0; switch (method) { #if defined (HAVE_NETGEN) case Netgen: { NETGENPlugin_Hypothesis_2D* hyp2d = new NETGENPlugin_Hypothesis_2D(hyp++,0,meshgen); if (fineness >=0 && fineness < 5) { hyp2d->SetFineness(NETGENPlugin_Hypothesis_2D::Fineness(fineness)); } // user defined values else { if (growthRate > 0) hyp2d->SetGrowthRate(growthRate); if (nbSegPerEdge > 0) hyp2d->SetNbSegPerEdge(nbSegPerEdge); if (nbSegPerRadius > 0) hyp2d->SetNbSegPerRadius(nbSegPerRadius); } hyp2d->SetQuadAllowed(allowquad); hyp2d->SetOptimize(optimize); hyp2d->SetSecondOrder(secondOrder); // apply bisecting to create four triangles out of one hypoth.push_back(hyp2d); NETGENPlugin_NETGEN_2D* alg2d = new NETGENPlugin_NETGEN_2D(hyp++,0,meshgen); hypoth.push_back(alg2d); } break; #endif #if defined (HAVE_MEFISTO) case Mefisto: { if (maxLength > 0) { StdMeshers_MaxLength* hyp1d = new StdMeshers_MaxLength(hyp++, 0, meshgen); hyp1d->SetLength(maxLength); hypoth.push_back(hyp1d); } else if (localLength > 0) { StdMeshers_LocalLength* hyp1d = new StdMeshers_LocalLength(hyp++,0,meshgen); hyp1d->SetLength(localLength); hypoth.push_back(hyp1d); } else if (maxArea > 0) { StdMeshers_MaxElementArea* hyp2d = new StdMeshers_MaxElementArea(hyp++,0,meshgen); hyp2d->SetMaxArea(maxArea); hypoth.push_back(hyp2d); } else if (deflection > 0) { StdMeshers_Deflection1D* hyp1d = new StdMeshers_Deflection1D(hyp++,0,meshgen); hyp1d->SetDeflection(deflection); hypoth.push_back(hyp1d); } else if (minLen > 0 && maxLen > 0) { StdMeshers_Arithmetic1D* hyp1d = new StdMeshers_Arithmetic1D(hyp++,0,meshgen); hyp1d->SetLength(minLen, false); hyp1d->SetLength(maxLen, true); hypoth.push_back(hyp1d); } else { StdMeshers_AutomaticLength* hyp1d = new StdMeshers_AutomaticLength(hyp++,0,meshgen); hypoth.push_back(hyp1d); } { StdMeshers_NumberOfSegments* hyp1d = new StdMeshers_NumberOfSegments(hyp++,0,meshgen); hyp1d->SetNumberOfSegments(1); hypoth.push_back(hyp1d); } if (regular) { StdMeshers_Regular_1D* hyp1d = new StdMeshers_Regular_1D(hyp++,0,meshgen); hypoth.push_back(hyp1d); } StdMeshers_TrianglePreference* hyp2d_1 = new StdMeshers_TrianglePreference(hyp++,0,meshgen); hypoth.push_back(hyp2d_1); StdMeshers_MEFISTO_2D* alg2d = new StdMeshers_MEFISTO_2D(hyp++,0,meshgen); hypoth.push_back(alg2d); } break; #endif default: break; } // Set new cout MeshingOutput stdcout; std::streambuf* oldcout = std::cout.rdbuf(&stdcout); // Apply the hypothesis and create the mesh mesh->ShapeToMesh(shape); for (int i=0; i<hyp;i++) mesh->AddHypothesis(shape, i); meshgen->Compute(*mesh, mesh->GetShapeToMesh()); // Restore old cout std::cout.rdbuf(oldcout); // build up the mesh structure SMDS_FaceIteratorPtr aFaceIter = mesh->GetMeshDS()->facesIterator(); SMDS_NodeIteratorPtr aNodeIter = mesh->GetMeshDS()->nodesIterator(); MeshCore::MeshPointArray verts; MeshCore::MeshFacetArray faces; verts.reserve(mesh->NbNodes()); faces.reserve(mesh->NbFaces()); int index=0; std::map<const SMDS_MeshNode*, int> mapNodeIndex; for (;aNodeIter->more();) { const SMDS_MeshNode* aNode = aNodeIter->next(); MeshCore::MeshPoint p; p.Set((float)aNode->X(), (float)aNode->Y(), (float)aNode->Z()); verts.push_back(p); mapNodeIndex[aNode] = index++; } for (;aFaceIter->more();) { const SMDS_MeshFace* aFace = aFaceIter->next(); if (aFace->NbNodes() == 3) { MeshCore::MeshFacet f; for (int i=0; i<3;i++) { const SMDS_MeshNode* node = aFace->GetNode(i); f._aulPoints[i] = mapNodeIndex[node]; } faces.push_back(f); } else if (aFace->NbNodes() == 4) { MeshCore::MeshFacet f1, f2; const SMDS_MeshNode* node0 = aFace->GetNode(0); const SMDS_MeshNode* node1 = aFace->GetNode(1); const SMDS_MeshNode* node2 = aFace->GetNode(2); const SMDS_MeshNode* node3 = aFace->GetNode(3); f1._aulPoints[0] = mapNodeIndex[node0]; f1._aulPoints[1] = mapNodeIndex[node1]; f1._aulPoints[2] = mapNodeIndex[node2]; f2._aulPoints[0] = mapNodeIndex[node0]; f2._aulPoints[1] = mapNodeIndex[node2]; f2._aulPoints[2] = mapNodeIndex[node3]; faces.push_back(f1); faces.push_back(f2); } else if (aFace->NbNodes() == 6) { MeshCore::MeshFacet f1, f2, f3, f4; const SMDS_MeshNode* node0 = aFace->GetNode(0); const SMDS_MeshNode* node1 = aFace->GetNode(1); const SMDS_MeshNode* node2 = aFace->GetNode(2); const SMDS_MeshNode* node3 = aFace->GetNode(3); const SMDS_MeshNode* node4 = aFace->GetNode(4); const SMDS_MeshNode* node5 = aFace->GetNode(5); f1._aulPoints[0] = mapNodeIndex[node0]; f1._aulPoints[1] = mapNodeIndex[node3]; f1._aulPoints[2] = mapNodeIndex[node5]; f2._aulPoints[0] = mapNodeIndex[node1]; f2._aulPoints[1] = mapNodeIndex[node4]; f2._aulPoints[2] = mapNodeIndex[node3]; f3._aulPoints[0] = mapNodeIndex[node2]; f3._aulPoints[1] = mapNodeIndex[node5]; f3._aulPoints[2] = mapNodeIndex[node4]; f4._aulPoints[0] = mapNodeIndex[node3]; f4._aulPoints[1] = mapNodeIndex[node4]; f4._aulPoints[2] = mapNodeIndex[node5]; faces.push_back(f1); faces.push_back(f2); faces.push_back(f3); faces.push_back(f4); } else if (aFace->NbNodes() == 8) { MeshCore::MeshFacet f1, f2, f3, f4, f5, f6; const SMDS_MeshNode* node0 = aFace->GetNode(0); const SMDS_MeshNode* node1 = aFace->GetNode(1); const SMDS_MeshNode* node2 = aFace->GetNode(2); const SMDS_MeshNode* node3 = aFace->GetNode(3); const SMDS_MeshNode* node4 = aFace->GetNode(4); const SMDS_MeshNode* node5 = aFace->GetNode(5); const SMDS_MeshNode* node6 = aFace->GetNode(6); const SMDS_MeshNode* node7 = aFace->GetNode(7); f1._aulPoints[0] = mapNodeIndex[node0]; f1._aulPoints[1] = mapNodeIndex[node4]; f1._aulPoints[2] = mapNodeIndex[node7]; f2._aulPoints[0] = mapNodeIndex[node1]; f2._aulPoints[1] = mapNodeIndex[node5]; f2._aulPoints[2] = mapNodeIndex[node4]; f3._aulPoints[0] = mapNodeIndex[node2]; f3._aulPoints[1] = mapNodeIndex[node6]; f3._aulPoints[2] = mapNodeIndex[node5]; f4._aulPoints[0] = mapNodeIndex[node3]; f4._aulPoints[1] = mapNodeIndex[node7]; f4._aulPoints[2] = mapNodeIndex[node6]; // Two solutions are possible: // <4,6,7>, <4,5,6> or <4,5,7>, <5,6,7> Base::Vector3d v4(node4->X(),node4->Y(),node4->Z()); Base::Vector3d v5(node5->X(),node5->Y(),node5->Z()); Base::Vector3d v6(node6->X(),node6->Y(),node6->Z()); Base::Vector3d v7(node7->X(),node7->Y(),node7->Z()); double dist46 = Base::DistanceP2(v4,v6); double dist57 = Base::DistanceP2(v5,v7); if (dist46 > dist57) { f5._aulPoints[0] = mapNodeIndex[node4]; f5._aulPoints[1] = mapNodeIndex[node6]; f5._aulPoints[2] = mapNodeIndex[node7]; f6._aulPoints[0] = mapNodeIndex[node4]; f6._aulPoints[1] = mapNodeIndex[node5]; f6._aulPoints[2] = mapNodeIndex[node6]; } else { f5._aulPoints[0] = mapNodeIndex[node4]; f5._aulPoints[1] = mapNodeIndex[node5]; f5._aulPoints[2] = mapNodeIndex[node7]; f6._aulPoints[0] = mapNodeIndex[node5]; f6._aulPoints[1] = mapNodeIndex[node6]; f6._aulPoints[2] = mapNodeIndex[node7]; } faces.push_back(f1); faces.push_back(f2); faces.push_back(f3); faces.push_back(f4); faces.push_back(f5); faces.push_back(f6); } else { Base::Console().Warning("Face with %d nodes ignored\n", aFace->NbNodes()); } } // clean up TopoDS_Shape aNull; mesh->ShapeToMesh(aNull); mesh->Clear(); delete mesh; for (std::list<SMESH_Hypothesis*>::iterator it = hypoth.begin(); it != hypoth.end(); ++it) delete *it; MeshCore::MeshKernel kernel; kernel.Adopt(verts, faces, true); Mesh::MeshObject* meshdata = new Mesh::MeshObject(); meshdata->swap(kernel); return meshdata; #endif // HAVE_SMESH }
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); }
Mesh::MeshObject* Mesher::createMesh() const { #ifndef HAVE_SMESH throw Base::Exception("SMESH is not available on this platform"); #else std::list<SMESH_Hypothesis*> hypoth; SMESH_Gen* meshgen = SMESH_Gen::get(); SMESH_Mesh* mesh = meshgen->CreateMesh(0, true); int hyp=0; switch (method) { #if defined (HAVE_NETGEN) case Netgen: { NETGENPlugin_Hypothesis_2D* hyp2d = new NETGENPlugin_Hypothesis_2D(hyp++,0,meshgen); if (fineness >=0 && fineness < 5) { hyp2d->SetFineness(NETGENPlugin_Hypothesis_2D::Fineness(fineness)); } // user defined values else { if (growthRate > 0) hyp2d->SetGrowthRate(growthRate); if (nbSegPerEdge > 0) hyp2d->SetNbSegPerEdge(nbSegPerEdge); if (nbSegPerRadius > 0) hyp2d->SetNbSegPerRadius(nbSegPerRadius); } hyp2d->SetQuadAllowed(allowquad); hyp2d->SetOptimize(optimize); hyp2d->SetSecondOrder(secondOrder); // apply bisecting to create four triangles out of one hypoth.push_back(hyp2d); NETGENPlugin_NETGEN_2D* alg2d = new NETGENPlugin_NETGEN_2D(hyp++,0,meshgen); hypoth.push_back(alg2d); } break; #endif #if defined (HAVE_MEFISTO) case Mefisto: { if (maxLength > 0) { StdMeshers_MaxLength* hyp1d = new StdMeshers_MaxLength(hyp++, 0, meshgen); hyp1d->SetLength(maxLength); hypoth.push_back(hyp1d); } else if (localLength > 0) { StdMeshers_LocalLength* hyp1d = new StdMeshers_LocalLength(hyp++,0,meshgen); hyp1d->SetLength(localLength); hypoth.push_back(hyp1d); } else if (maxArea > 0) { StdMeshers_MaxElementArea* hyp2d = new StdMeshers_MaxElementArea(hyp++,0,meshgen); hyp2d->SetMaxArea(maxArea); hypoth.push_back(hyp2d); } else if (deflection > 0) { StdMeshers_Deflection1D* hyp1d = new StdMeshers_Deflection1D(hyp++,0,meshgen); hyp1d->SetDeflection(deflection); hypoth.push_back(hyp1d); } else if (minLen > 0 && maxLen > 0) { StdMeshers_Arithmetic1D* hyp1d = new StdMeshers_Arithmetic1D(hyp++,0,meshgen); hyp1d->SetLength(minLen, false); hyp1d->SetLength(maxLen, true); hypoth.push_back(hyp1d); } else { StdMeshers_AutomaticLength* hyp1d = new StdMeshers_AutomaticLength(hyp++,0,meshgen); hypoth.push_back(hyp1d); } { StdMeshers_NumberOfSegments* hyp1d = new StdMeshers_NumberOfSegments(hyp++,0,meshgen); hyp1d->SetNumberOfSegments(1); hypoth.push_back(hyp1d); } if (regular) { StdMeshers_Regular_1D* hyp1d = new StdMeshers_Regular_1D(hyp++,0,meshgen); hypoth.push_back(hyp1d); } StdMeshers_TrianglePreference* hyp2d_1 = new StdMeshers_TrianglePreference(hyp++,0,meshgen); hypoth.push_back(hyp2d_1); StdMeshers_MEFISTO_2D* alg2d = new StdMeshers_MEFISTO_2D(hyp++,0,meshgen); hypoth.push_back(alg2d); } break; #endif default: break; } // Set new cout MeshingOutput stdcout; std::streambuf* oldcout = std::cout.rdbuf(&stdcout); // Apply the hypothesis and create the mesh mesh->ShapeToMesh(shape); for (int i=0; i<hyp;i++) mesh->AddHypothesis(shape, i); meshgen->Compute(*mesh, mesh->GetShapeToMesh()); // Restore old cout std::cout.rdbuf(oldcout); // build up the mesh structure SMDS_FaceIteratorPtr aFaceIter = mesh->GetMeshDS()->facesIterator(); SMDS_NodeIteratorPtr aNodeIter = mesh->GetMeshDS()->nodesIterator(); MeshCore::MeshPointArray verts; MeshCore::MeshFacetArray faces; verts.reserve(mesh->NbNodes()); faces.reserve(mesh->NbFaces()); int index=0; std::map<const SMDS_MeshNode*, int> mapNodeIndex; for (;aNodeIter->more();) { const SMDS_MeshNode* aNode = aNodeIter->next(); MeshCore::MeshPoint p; p.Set((float)aNode->X(), (float)aNode->Y(), (float)aNode->Z()); verts.push_back(p); mapNodeIndex[aNode] = index++; } for (;aFaceIter->more();) { const SMDS_MeshFace* aFace = aFaceIter->next(); if (aFace->NbNodes() == 3) { MeshCore::MeshFacet f; for (int i=0; i<3;i++) { const SMDS_MeshNode* node = aFace->GetNode(i); f._aulPoints[i] = mapNodeIndex[node]; } faces.push_back(f); } else if (aFace->NbNodes() == 4) { MeshCore::MeshFacet f1, f2; const SMDS_MeshNode* node0 = aFace->GetNode(0); const SMDS_MeshNode* node1 = aFace->GetNode(1); const SMDS_MeshNode* node2 = aFace->GetNode(2); const SMDS_MeshNode* node3 = aFace->GetNode(3); f1._aulPoints[0] = mapNodeIndex[node0]; f1._aulPoints[1] = mapNodeIndex[node1]; f1._aulPoints[2] = mapNodeIndex[node2]; f2._aulPoints[0] = mapNodeIndex[node0]; f2._aulPoints[1] = mapNodeIndex[node2]; f2._aulPoints[2] = mapNodeIndex[node3]; faces.push_back(f1); faces.push_back(f2); } else if (aFace->NbNodes() == 6) { MeshCore::MeshFacet f1, f2, f3, f4; const SMDS_MeshNode* node0 = aFace->GetNode(0); const SMDS_MeshNode* node1 = aFace->GetNode(1); const SMDS_MeshNode* node2 = aFace->GetNode(2); const SMDS_MeshNode* node3 = aFace->GetNode(3); const SMDS_MeshNode* node4 = aFace->GetNode(4); const SMDS_MeshNode* node5 = aFace->GetNode(5); f1._aulPoints[0] = mapNodeIndex[node0]; f1._aulPoints[1] = mapNodeIndex[node3]; f1._aulPoints[2] = mapNodeIndex[node5]; f2._aulPoints[0] = mapNodeIndex[node1]; f2._aulPoints[1] = mapNodeIndex[node4]; f2._aulPoints[2] = mapNodeIndex[node3]; f3._aulPoints[0] = mapNodeIndex[node2]; f3._aulPoints[1] = mapNodeIndex[node5]; f3._aulPoints[2] = mapNodeIndex[node4]; f4._aulPoints[0] = mapNodeIndex[node3]; f4._aulPoints[1] = mapNodeIndex[node4]; f4._aulPoints[2] = mapNodeIndex[node5]; faces.push_back(f1); faces.push_back(f2); faces.push_back(f3); faces.push_back(f4); } else if (aFace->NbNodes() == 8) { MeshCore::MeshFacet f1, f2, f3, f4, f5, f6; const SMDS_MeshNode* node0 = aFace->GetNode(0); const SMDS_MeshNode* node1 = aFace->GetNode(1); const SMDS_MeshNode* node2 = aFace->GetNode(2); const SMDS_MeshNode* node3 = aFace->GetNode(3); const SMDS_MeshNode* node4 = aFace->GetNode(4); const SMDS_MeshNode* node5 = aFace->GetNode(5); const SMDS_MeshNode* node6 = aFace->GetNode(6); const SMDS_MeshNode* node7 = aFace->GetNode(7); f1._aulPoints[0] = mapNodeIndex[node0]; f1._aulPoints[1] = mapNodeIndex[node4]; f1._aulPoints[2] = mapNodeIndex[node7]; f2._aulPoints[0] = mapNodeIndex[node1]; f2._aulPoints[1] = mapNodeIndex[node5]; f2._aulPoints[2] = mapNodeIndex[node4]; f3._aulPoints[0] = mapNodeIndex[node2]; f3._aulPoints[1] = mapNodeIndex[node6]; f3._aulPoints[2] = mapNodeIndex[node5]; f4._aulPoints[0] = mapNodeIndex[node3]; f4._aulPoints[1] = mapNodeIndex[node7]; f4._aulPoints[2] = mapNodeIndex[node6]; // Two solutions are possible: // <4,6,7>, <4,5,6> or <4,5,7>, <5,6,7> Base::Vector3d v4(node4->X(),node4->Y(),node4->Z()); Base::Vector3d v5(node5->X(),node5->Y(),node5->Z()); Base::Vector3d v6(node6->X(),node6->Y(),node6->Z()); Base::Vector3d v7(node7->X(),node7->Y(),node7->Z()); double dist46 = Base::DistanceP2(v4,v6); double dist57 = Base::DistanceP2(v5,v7); if (dist46 > dist57) { f5._aulPoints[0] = mapNodeIndex[node4]; f5._aulPoints[1] = mapNodeIndex[node6]; f5._aulPoints[2] = mapNodeIndex[node7]; f6._aulPoints[0] = mapNodeIndex[node4]; f6._aulPoints[1] = mapNodeIndex[node5]; f6._aulPoints[2] = mapNodeIndex[node6]; } else { f5._aulPoints[0] = mapNodeIndex[node4]; f5._aulPoints[1] = mapNodeIndex[node5]; f5._aulPoints[2] = mapNodeIndex[node7]; f6._aulPoints[0] = mapNodeIndex[node5]; f6._aulPoints[1] = mapNodeIndex[node6]; f6._aulPoints[2] = mapNodeIndex[node7]; } faces.push_back(f1); faces.push_back(f2); faces.push_back(f3); faces.push_back(f4); faces.push_back(f5); faces.push_back(f6); } else { Base::Console().Warning("Face with %d nodes ignored\n", aFace->NbNodes()); } } // clean up TopoDS_Shape aNull; mesh->ShapeToMesh(aNull); mesh->Clear(); delete mesh; for (std::list<SMESH_Hypothesis*>::iterator it = hypoth.begin(); it != hypoth.end(); ++it) delete *it; MeshCore::MeshKernel kernel; kernel.Adopt(verts, faces, true); Mesh::MeshObject* meshdata = new Mesh::MeshObject(); meshdata->swap(kernel); return meshdata; #endif // HAVE_SMESH }