コード例 #1
0
ファイル: AppMeshPartPy.cpp プロジェクト: neuroidss/FreeCAD
    Py::Object wireFromSegment(const Py::Tuple& args)
    {
        PyObject *o, *m;
        if (!PyArg_ParseTuple(args.ptr(), "O!O!", &(Mesh::MeshPy::Type), &m,&PyList_Type,&o))
            throw Py::Exception();

        Py::List list(o);
        Mesh::MeshObject* mesh = static_cast<Mesh::MeshPy*>(m)->getMeshObjectPtr();
        std::vector<unsigned long> segm;
        segm.reserve(list.size());
        for (unsigned int i=0; i<list.size(); i++) {
            segm.push_back((int)Py::Int(list[i]));
        }

        std::list<std::vector<Base::Vector3f> > bounds;
        MeshCore::MeshAlgorithm algo(mesh->getKernel());
        algo.GetFacetBorders(segm, bounds);

        Py::List wires;
        std::list<std::vector<Base::Vector3f> >::iterator bt;

        for (bt = bounds.begin(); bt != bounds.end(); ++bt) {
            BRepBuilderAPI_MakePolygon mkPoly;
            for (std::vector<Base::Vector3f>::reverse_iterator it = bt->rbegin(); it != bt->rend(); ++it) {
                mkPoly.Add(gp_Pnt(it->x,it->y,it->z));
            }
            if (mkPoly.IsDone()) {
                PyObject* wire = new Part::TopoShapeWirePy(new Part::TopoShape(mkPoly.Wire()));
                wires.append(Py::Object(wire, true));
            }
        }

        return wires;
    }
コード例 #2
0
ファイル: OCCFace.cpp プロジェクト: Felipeasg/occmodel
int OCCFace::createPolygonal(std::vector<OCCStruct3d> points)
{
    try {
        BRepBuilderAPI_MakePolygon MP;
        for (unsigned i=0; i<points.size(); i++) {
            MP.Add(gp_Pnt(points[i].x, points[i].y, points[i].z));
        }
        MP.Close();
        if (!MP.IsDone()) {
            StdFail_NotDone::Raise("failed to create face");;
        }
        BRepBuilderAPI_MakeFace MF(MP.Wire(), false);
        this->setShape(MF.Face());
        
        // possible fix shape
        if (!this->fixShape())
            StdFail_NotDone::Raise("Shapes not valid");
        
    } 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 face");
        }
        return 0;
    }
    return 1;
}
コード例 #3
0
ファイル: FeaturePartPolygon.cpp プロジェクト: KimK/FreeCAD
App::DocumentObjectExecReturn *Part::Polygon::execute(void)
{
    BRepBuilderAPI_MakePolygon poly;
    const std::vector<Base::Vector3d> nodes = Nodes.getValues();

    for (std::vector<Base::Vector3d>::const_iterator it = nodes.begin(); it != nodes.end(); ++it) {
        gp_Pnt pnt(it->x, it->y, it->z);
        poly.Add(pnt);
    }

    if (Close.getValue())
        poly.Close();

    if (!poly.IsDone())
        throw Base::CADKernelError("Cannot create polygon because less than two vertices are given");
    TopoDS_Wire wire = poly.Wire();
    this->Shape.setValue(wire);

    return App::DocumentObject::StdReturn;
}
コード例 #4
0
ファイル: AppMeshPartPy.cpp プロジェクト: 5263/FreeCAD
static PyObject *
wireFromSegment(PyObject *self, PyObject *args)
{
    PyObject *o, *m;
    if (!PyArg_ParseTuple(args, "O!O!", &(Mesh::MeshPy::Type), &m,&PyList_Type,&o))
        return 0;
    Py::List list(o);
    Mesh::MeshObject* mesh = static_cast<Mesh::MeshPy*>(m)->getMeshObjectPtr();
    std::vector<unsigned long> segm;
    segm.reserve(list.size());
    for (unsigned int i=0; i<list.size(); i++) {
        segm.push_back((int)Py::Int(list[i]));
    }

    std::list<std::vector<Base::Vector3f> > bounds;
    MeshCore::MeshAlgorithm algo(mesh->getKernel());
    algo.GetFacetBorders(segm, bounds);

    Py::List wires;
    std::list<std::vector<Base::Vector3f> >::iterator bt;

    try {
        for (bt = bounds.begin(); bt != bounds.end(); ++bt) {
            BRepBuilderAPI_MakePolygon mkPoly;
            for (std::vector<Base::Vector3f>::reverse_iterator it = bt->rbegin(); it != bt->rend(); ++it) {
                mkPoly.Add(gp_Pnt(it->x,it->y,it->z));
            }
            if (mkPoly.IsDone()) {
                PyObject* wire = new Part::TopoShapeWirePy(new Part::TopoShape(mkPoly.Wire()));
                wires.append(Py::Object(wire, true));
            }
        }
    }
    catch (Standard_Failure) {
        Handle_Standard_Failure e = Standard_Failure::Caught();
        PyErr_SetString(Base::BaseExceptionFreeCADError, e->GetMessageString());
        return 0;
    }

    return Py::new_reference_to(wires);
}
コード例 #5
0
bool DrawingLineWallCtrller::UpdateMesh()
{
	if ( !NeedUpdateMesh_ )
	{
		return true;
	}

	if ( Pnts_.size() > 1 )
	{
		{//Triangle Mesh
			BRepBuilderAPI_MakePolygon mp;
			for ( const auto& curPnt : Pnts_ )
			{
				mp.Add(gp_Pnt(curPnt.X, curPnt.Y, curPnt.Z));
			}
			assert(mp.IsDone());

			auto wallPath = mp.Wire();
			assert(!wallPath.IsNull());

			auto& wallPnt1 = Pnts_[0];
			auto& wallPnt2 = Pnts_[1];

			auto beginThickPnt = (wallPnt2 - wallPnt1).normalize().crossProduct(s_PntNormal) * WallThickness_;
			beginThickPnt = wallPnt1 + beginThickPnt;

			auto thickEdge = BRepBuilderAPI_MakeEdge(gp_Pnt(wallPnt1.X,wallPnt1.Y, wallPnt1.Z), gp_Pnt(beginThickPnt.X,beginThickPnt.Y, beginThickPnt.Z) ).Edge();
			BRepBuilderAPI_MakeWire dirWireMaker(thickEdge);
			TopoDS_Wire dirWire = dirWireMaker.Wire();

			BRepOffsetAPI_MakePipeShell pipeMaker(wallPath);
			pipeMaker.SetTransitionMode(BRepBuilderAPI_RightCorner);//延切线方向缝合
			pipeMaker.Add(dirWire);
			pipeMaker.Build();

			FaceShape_ = pipeMaker.Shape();
			if ( wallPath.Closed() )
			{
				State_ = EDWLS_FINISH;
				return false;
			}

			if ( MeshBuf_ )
			{
				MeshBuf_->drop();
			}

			auto mesh = ODLTools::CreateMesh(FaceShape_);
			assert(mesh);
			MeshBuf_ = mesh->getMeshBuffer(0);
			MeshBuf_->grab();

			auto tex = GetRenderContextSPtr()->Smgr_->getVideoDriver()->getTexture("../Data/Resource/3D/wallLine.png");
			MeshBuf_->getMaterial().setTexture(0, tex);
			float uLen = 200;
			float vLen = 200;
			irr::core::matrix4 scaleMat,rotateMat;
			scaleMat.setScale(irr::core::vector3df(1/uLen, 1/vLen, 1));
			rotateMat.setTextureRotationCenter(static_cast<float>(M_PI/4));
			MeshBuf_->getMaterial().setTextureMatrix(0, rotateMat*scaleMat);
			MeshBuf_->getMaterial().Lighting = false;
			MeshBuf_->getMaterial().ZWriteEnable = false;
			MeshBuf_->getMaterial().BackfaceCulling = false;
			mesh->drop();
		}

		{//Line Mesh
			if ( LineMeshBuf_ )
			{
				LineMeshBuf_->drop();
			}

			auto newSmesh = new SMeshBuffer;
			for ( TopExp_Explorer exp(FaceShape_, TopAbs_EDGE); exp.More(); exp.Next() )
			{
				auto& curEdge = TopoDS::Edge(exp.Current());
				auto& v1 = TopExp::FirstVertex(curEdge);
				auto& v2 = TopExp::LastVertex(curEdge);

				auto p1 = BRep_Tool::Pnt(v1);
				auto p2 = BRep_Tool::Pnt(v2);

				S3DVertex sv1(irr::core::vector3df(static_cast<float>(p1.X()), static_cast<float>(p1.Y()), static_cast<float>(p1.Z())), s_PntNormal, s_LineColor, s_PntCoord);
				S3DVertex sv2(irr::core::vector3df(static_cast<float>(p2.X()), static_cast<float>(p2.Y()), static_cast<float>(p2.Z())), s_PntNormal, s_LineColor, s_PntCoord);

				newSmesh->Vertices.push_back(sv1);
				newSmesh->Vertices.push_back(sv2);
				newSmesh->Indices.push_back(newSmesh->getIndexCount());
				newSmesh->Indices.push_back(newSmesh->getIndexCount());
			}

			LineMeshBuf_ = newSmesh;

			LineMeshBuf_->getMaterial().Lighting = false;
			LineMeshBuf_->getMaterial().ZWriteEnable = false;
			LineMeshBuf_->getMaterial().BackfaceCulling = false;
			LineMeshBuf_->getMaterial().Thickness = 3;
			LineMeshBuf_->getMaterial().MaterialType = IrrEngine::GetInstance()->GetShaderType(EST_LINE);
			LineMeshBuf_->getMaterial().DiffuseColor = s_LineColor;
		}
	}


	{//Path Mesh
		auto smeshBuf = static_cast<irr::scene::SMeshBuffer*>(PathMeshBuf_);
		smeshBuf->Vertices.clear();
		smeshBuf->Indices.clear();

		auto curCount = PathMeshBuf_->getIndexCount();
		for ( const auto& curPnt : Pnts_ )
		{
			smeshBuf->Vertices.push_back(irr::video::S3DVertex(curPnt, s_PntNormal, s_PathColor, s_PntCoord));
			smeshBuf->Indices.push_back(curCount++);
		}
	}

	NeedUpdateMesh_ = false;

	return true;
}
コード例 #6
0
App::DocumentObjectExecReturn *Fractal::execute(void)
{
	faces.clear();
	//Appel de la fonction de generation avec des valeurs prereglees(taille) et la valeur de l'utilisateur
	//sierpin([-7, -4, 0], [0, 8, 0], [7, -4, 0], [0, 0, 11], 6)
	//sierpin(Base::Vector3d(-5, -5, -5), Base::Vector3d(5, 5, -5), Base::Vector3d(-5, 5, 5), Base::Vector3d(5, -5, 5), 1, Nodes.getValues());
	
	sierpin(Base::Vector3d(-Length.getValue(), -Width.getValue(), -Height.getValue()), Base::Vector3d(Length.getValue(), Width.getValue(), -Height.getValue()), Base::Vector3d(-Length.getValue(), Width.getValue(), Height.getValue()), Base::Vector3d(Length.getValue(), -Width.getValue(), Height.getValue()), Depth.getValue(), Nodes.getValues());
	//Sponge();

		/*//Creation du shell avec la liste des faces
		myShell = Part.makeShell(partFaces);
		// Creation du polygon avec le shell
		mySolid = Part.makeSolid(myShell);
		// Mise a jour de l'orientation des faces
		mySolidRev = mySolid.copy();
		mySolidRev.reverse();

		//Affichage du solide
		Part.show(mySolidRev);*/

	BRepBuilderAPI_MakePolygon poly;
	//const std::vector<Base::Vector3d> nodes = Nodes;
	/*_nodes.push_back(Base::Vector3d(0, 0, 0));
	_nodes.push_back(Base::Vector3d(0, 0, 1));
	_nodes.push_back(Base::Vector3d(0, 0, 3));
	_nodes.push_back(Base::Vector3d(0, 0, 5));
	_nodes.push_back(Base::Vector3d(0, 5, 0));
	_nodes.push_back(Base::Vector3d(0, 0, 8));*/

	/*std::string s = std::to_string(_nodes.size());
	char const *pchar = s.c_str();
	Base::Console().Message(pchar);
	Base::Console().Log(pchar);*/

	for (std::vector<Base::Vector3d>::const_iterator it = _nodes.begin(); it != _nodes.end(); ++it) {
		gp_Pnt pnt(it->x, it->y, it->z);
		poly.Add(pnt);
	}

	if (!poly.IsDone())
		throw Base::Exception("Cannot create polygon because less than two vetices are given");
	//TopoDS_Wire wire = poly.Wire();
	//BRepBuilderAPI_MakeFace makeFace(poly.Wire());

	/*gp_Pnt point1 = gp_Pnt(1,0,0);
	gp_Pnt point2 = gp_Pnt(1,1,0);
	gp_Pnt point3 = gp_Pnt(1,0,1);*/
	//TopoDS_Wire wire = BRepBuilderAPI_MakePolygon(, Standard_True);
	//TopoDS_Face face = BRepBuilderAPI_MakeFace(wire, Standard_True);
	//TopoDS_Shape s;

	/*if (makeFace.Error() == BRepBuilderAPI_FaceDone)
	{
		TopoDS_Face faceCurrent = makeFace.Face();
	}
	BRepBuilderAPI_MakeFace makeFace(faceCurrent);
	makeFace.Add(MP.Wire());
	if (makeFace.Error() == BRepBuilderAPI_FaceDone)
	{
		faceCurrent = makeFace.Face();
	}*/

	//this->Shape.setValue();



	//TopoDS_Face tf;

	//BRepBuilderAPI_MakeFace mkFace(TopoDS::Wire(sh));

	//Handle_Geom_Surface gs;
	//Handle<Geom_Surface> dd;
	//gs.Access = 0;

	/*RepOffsetAPI_MakeOffsetShape mkOffset(this->_Shape, offset, tol, BRepOffset_Mode(offsetMode),
        intersection ? Standard_True : Standard_False,
        selfInter ? Standard_True : Standard_False,
        GeomAbs_JoinType(join));
   
    if (!fill)
        return res;
#if 1
    //s=Part.makePlane(10,10)
    //s.makeOffsetShape(1.0,0.01,False,False,0,0,True)*/

	//BRepOffsetAPI_MakeOffsetShape myOffsetShape;
	//TopoShape ts;
	//myOffsetShape = ts.makeOffsetShape(1.0, 0.01, False, False, 0, 0, True);
	//const TopoDS_Shape& res = myOffsetShape.Shape();

	BRep_Builder builder;
	TopoDS_Shell shell;
	builder.MakeShell(shell);
	/*s = std::to_string(faces.size());
	pchar = s.c_str();
	Base::Console().Message(pchar);
	Base::Console().Log(pchar);*/
	for (int i = 0; i < faces.size(); i++) {
		builder.Add(shell, faces[i]);
		//this->Shape.setValue(shell);
	}
	//this->Shape.setValue(builder.sh);

	//BRepBuilderAPI_MakeShell myShell(gs);
	//const TopoDS_Shell& td = gs.sh;

	/*TopoDS_Solid mysolid;
	builder.MakeSolid(mysolid);
	builder.Add(mysolid, shell);*/

	BRepBuilderAPI_MakeSolid mySolid(shell);
	this->Shape.setValue(mySolid.Shape());


	return App::DocumentObject::StdReturn;
	}