Three-dimensional CAD modeling--half Euler operation model based on the basic data structure

Source: Internet
Author: User

Three-dimensional CAD modeling--half Euler operation model based on the basic data structure (Elar, B_rep)

(Euler operations three-dimensional CAD modeling course three-dimensional CAD mold Gao Jingming teacher rendering frame brep with hole with handle b_rep brep elar sweep into operation)

This year, I chose teacher Gao's three-dimensional CAD modeling class. Zju chose this lesson and should know that the last thing to do is to do a program job--modeling based on the basic Euler operation of the half-data structure. A model with holes must be built.

(three-dimensional CAD modeling course of Euler operation three-dimensional CAD Gao Jingming teacher render frame brep with hole handle B_rep brep elar sweep into operation)

3.3 Selection of Euler operations (5-dimensional hyper-plane in 6-D space)

V E F H R S Operator

1 1 0 0 0 0 MeV

0 1 1 0 0 0 MEF

1 0 1 0 0 1 Mvfs

0-1 0 0 1 0 kemr

0 0-1 1 1 0 kfmrh

MVSF: Generates a polygon with one point, contains an empty ring, and forms a new body

MeV: Generates a new point E2, connecting that point to a bit v1. To construct a new edge

MEF: Joins two point v1,v2 on the surface F1, generates a new edge E, and produces a new polygon

KEMR: Deletes an edge e. Creates a new inner ring on a neighboring side of the edge

KFMRH: Removes a face F2 that is in contact with the face F1, creating an inner ring on the face F1 and forming a through hole on the body

The main thing is to achieve these five euro-pull operations can be.

The following is mainly a record of my work in the half of the data structure and the implementation of basic Euler operations.

#ifndef __half_edge_structure__#define __half_edge_structure__#include <stdlib.h>struct Solid;struct face; struct loop;struct halfedge;struct vertex;struct edge;struct solid{int ID; Face *faces; List of all faces to construct this solidedge *edges; List of all edges to construct this solid->to build the Framesolid *next; Solid *pre;int vnum;//the Count of all Vertexsint fnum;//the count of all Facesint lnum;//the count of All Loopssolid (): ID (0), Faces (null), Edges (null), Next (null), Pre (NULL), Fnum (0), Vnum (0), Lnum (0) {}};struct face{int ID; Solid *solid; The solid which the face belong Toloop *OUT_LP; Out loop of the face--construct the Faceloop *inner_lp;//inner_lp of the Face--inner loopface *next; Face *pre;int innum;//the Count of Inner loopsface (): ID (0), solid (null), OUT_LP (null), Next (null), Pre (NULL), INNER_LP (N ULL), Innum (0) {}};struct loop{int ID; Halfedge *halfedges; List of all halfeges to construct this loop face *face; The face, the constructed byThis looploop *next; Loop *pre; Loop (): ID (0), halfedges (null), Face (null), Next (null), pre (NULL) {}};struct Edge{halfedge *half_l;//the Edge's left half Edgehalfedge *half_r; The edge ' s right Halfedgeedge *next; Edge *pre; Edge (): half_l (null), Half_r (null), Next (null), pre (NULL) {}};struct Halfedge{edge *edge;//this Halfedge belong to which Edgevertex *SV; The start vertex of this halfedgevertex *ev; The end vertex of this halfedgeloop *lp; Pointer to the loop, this halfedge belong Tohalfedge *next; Halfedge *pre; Halfedge *brother; Halfedge (): Edge (NULL), SV (NULL), LP (NULL), Next (null), Pre (null), brother (null) {}};struct Vertex{int id;double Coordinate[3];//coordinate of the vertex (x, y, z) vertex *next; Vertex *pre; Vertex (double x, double y, double z): ID (0), Next (null), pre (NULL) {coordinate[0] = x;coordinate[1] = y;coordinate[2] = Z; }}; #endif


The following are the implementation codes for the five Euler operations

Elar_operator.h

#ifndef __elar_operator__#define __elar_operator__#include "half_edge_structure.h" #include <vector>using Namespace Std;class Elaroperator{public:elaroperator () {v_list.clear (); Sweep_list.clear (); L_list.clear ();} Std::vector<vertex *> getv_list () {return v_list;} Std::vector<face *> getsweep_list () {return sweep_list;} Std::vector<loop *> getloop_list () {return l_list;} void Addedgeintosolid (Edge *edge, solid *&solid), void Addfaceintosolid (face *face, solid *&solid); void Addloopintoface (Loop *loop, face *face); Solid *mvfs (double point[3], Vertex *&vertex); Halfedge *mev (Vertex *sv, double point[3], Loop *LP); Loop *MEF (Vertex *sv, Vertex *ev, loop *LP, bool mark); Loop *kemr (Vertex *sv, Vertex *ev, loop *lp), void Kfmrh (face *fa, face *FB), void Sweep (double dir[3], double dist);p rivate : Std::vector<vertex *> v_list;std::vector<loop *> l_list;std::vector<face *> sweep_list;}; #endif



Elar_operator.cpp

#include "elar_operator.h" #include <cstdio>solid *elaroperator::mvfs (double point[3], Vertex *&vertex) { Solid *solid = new Solid (); Face *face = new Face ();  Loop *OUT_LP = new loop (), vertex = new vertex (point[0], point[1], point[2]); vertex->id = Solid->vnum;out_lp->id = Solid->lnum;face->id = Solid->fnum;l_list.push_back (OUT_LP);//printf ("%lf%lf%lf\n", vertex-> Coordinate[0], vertex->coordinate[1], vertex->coordinate[2]); V_list.push_back (vertex);//store the vertex by Ordersolid->vnum + = 1;//increase the num of Vertexssolid->fnum + = 1;//increase the num of Facessolid->lnum + = 1;/ /increase the num of loopssolid->faces = Face;face->solid = SOLID;FACE-&GT;OUT_LP = Out_lp;out_lp->face = Face;re Turn solid;} Halfedge *elaroperator::mev (Vertex *sv, double point[3], Loop *loop) {Solid *solid = loop->face->solid; Edge *edge = new Edge ();//create a new Edgehalfedge *half_l = new Halfedge (); Halfedge *half_r = new Halfedge (); Vertex *ev = new VErtex (Point[0], point[1], point[2]); ev->id = Solid->vnum;v_list.push_back (EV);//store the vertex by ordersolid- >vnum + = 1;//remember to increase the vertex num of the SOLIDHALF_L-&GT;SV = Sv;half_l->ev = EV;HALF_R-&GT;SV = Ev;h Alf_r->ev = sv;edge->half_l = Half_l;edge->half_r = Half_r;half_l->edge = Edge;half_r->edge = edge;half_ R->brother = Half_l;half_l->brother = HALF_R;HALF_L-&GT;LP = LOOP;HALF_R-&GT;LP = Loop;//add The new II Halfedges I Nto the loopif (loop->halfedges = = NULL) {half_l->next = Half_r;half_r->next = Half_l;half_l->pre = Half_r;hal F_r->pre = Half_l;loop->halfedges = half_l;} Else{halfedge *thalf = Loop->halfedges;while (Thalf->ev! = SV) Thalf = Thalf->next;half_r->next = thalf-> Next;thalf->next->pre = Half_r;thalf->next = Half_l;half_l->pre = Thalf;half_l->next = half_r;half_r- >pre = half_l;} Add the edge into the edge list of solidaddedgeintosolid (edge, solid); return half_l;} Loop *elaROPERATOR::MEF (Vertex *sv, Vertex *ev, Loop *loop, bool mark) {Solid *solid = loop->face->solid; Edge *edge = new Edge (); Halfedge *half_l = new Halfedge (); Halfedge *half_r = new Halfedge (); Loop *newloop = new loop (); half_l->sv = Sv;half_l->ev = EV;HALF_R-&GT;SV = Ev;half_r->ev = Sv;half_r->brother = Half_l;half_l->brother = Half_r;half_l->edge = Edge;half_r->edge = edge;edge->half_l = half_l;edge-> Half_r = Half_r;//add The new and Halfedge into the Loophalfedge *thalf = loop->halfedges;  Halfedge *tmpa, *TMPB, *tmpc;while (Thalf->ev! = SV) Thalf = Thalf->next;tmpa = Thalf;while (Thalf->ev! = EV) thalf = THALF-&GT;NEXT;TMPB = Thalf;thalf = Thalf->next;while (Thalf->ev! = ev) Thalf = THALF-&GT;NEXT;TMPC = Thalf;//divi De The big loop into the small loophalf_r->next = Tmpa->next;tmpa->next->pre = Half_r;tmpa->next = Half_l;h Alf_l->pre = Tmpa;half_l->next = Tmpb->next;tmpb->next->pre = Half_l;tmpb->next = Half_r;haLf_r->pre = Tmpb;loop->halfedges = Half_l;newloop->halfedges = HALF_R;HALF_L-&GT;LP = LOOP;HALF_R-&GT;LP = Newloop;  Face *face = new Face (); newloop->id = Solid->lnum;solid->lnum + = 1;l_list.push_back (newloop);//add face into the  Face list of solidaddfaceintosolid (face, solid), Addloopintoface (Newloop, face), if (TMPC = = TMPB) {if (Mark)//only the face In the bottom {sweep_list.push_back (half_l->lp->face);}} Else{sweep_list.push_back (half_r->lp->face);} Add edge into the edge list of solidaddedgeintosolid (edge, solid); return loop;} Loop *elaroperator::kemr (Vertex *sv, Vertex *ev, loop *loop)//sv must belong to the outer Loop{halfedge *tmpa, *TMPB, *hal ; Face *face = loop->face; Loop *INLP = new loop (); Solid *solid = Loop->face->solid;hal = Loop->halfedges;while (hal->sv! = SV | | Hal->ev! = EV) HAL = hal-> Next;tmpa = Hal;while (hal->sv! = EV | | Hal->ev! = SV) Hal = HAL-&GT;NEXT;TMPB = Hal;tmpb->pre->next = Tmpa-&gt ; next;tmpa->pre-&Gt;next = Tmpb->next;loop->face->solid->faces->out_lp->halfedges = tmpa->pre;inlp-> Halfedges = TMPB-&GT;PRE;TMPB-&GT;PRE-&GT;LP = INLP; Inlp->id = Solid->lnum;solid->lnum + = 1;l_list.push_back (INLP); Addloopintoface (INLP, tmpa->pre-> Brother->lp->face);d elete tmpa;delete tmpb;return NULL;} void Elaroperator::kfmrh (Face *fa, face *FB)//fa indicate the outface, FB indicate the innerface{loop *loop = fb->out_l P;addloopintoface (Loop, FA); fa->solid->lnum-= 1;fa->solid->fnum-= 1; Solid *solid = fa->solid; Face *face = solid->faces;if (face = = FB) {solid->faces = Face->next;} Else{face *TF = Face;while (face! = FB && face = NULL) {tf = Face;face = Face->next;} Tf->next = Face->next;} Delete fb;} void Elaroperator::sweep (double dir[3], double d) {Vertex *startv, *NEXTV, *UPV, *upprev; Halfedge *he, *suphe, *uphe;double point[3];vector<face *>::iterator ite;for (ite = Sweep_list.begin (); ITE! = Sweep _list.end (); ++ite) {//solve The first vertex when process the sweeping operatorloop *loop = (*ite)->out_lp;he = Loop->halfedges;s TARTV = he->sv;point[0] = startv->coordinate[0] + d*dir[0];p oint[1] = startv->coordinate[1] + d*dir[1];p oint[2] = Startv->coordinate[2] + d*dir[2];suphe = MeV (StarTV, point, Loop);//acquire the first down_to_up Halfedgeupprev = sup He->ev;//record the fist up vertex as the pre vertexhe = HE-&GT;NEXT;NEXTV = he->sv;  Loop *LP = Loop;while (nextv! = StarTV) {point[0] = Nextv->coordinate[0] + d*dir[0];p oint[1] = nextv->coordinate[1] + D*DIR[1];p oint[2] = nextv->coordinate[2] + d*dir[2];uphe = MeV (NEXTV, point, LP); UPV = UPHE-&GT;EV;LP = MEF (Upprev, up V, loop, false); Upprev = Upv;he = He->next;nextv = HE-&GT;SV;} MEF (Upprev, Suphe->ev, loop, false);}} Inlinevoid Elaroperator::addedgeintosolid (Edge *edge, Solid *&solid) {Edge *te = solid->edges;if (Te = = NULL) Solid->edges = Edge;else{while (te->next! = NULL) Te = Te->next;te-> next = Edge;edge->pre = Te;}} Inlinevoid Elaroperator::addfaceintosolid (Face *face, Solid *&solid) {Face *tface = solid->faces;if (Tface = = NULL {solid->faces = face;} Else{while (Tface->next! = NULL) Tface = Tface->next;tface->next = Face;face->pre = Tface;} Face->solid = Solid;face->id = solid->fnum;solid->fnum + 1;//increase the num of faces}inlinevoid ElarOperat Or::addloopintoface (Loop *loop, face *face) {loop->face = Face;//there are only one off Loop but there could have lots of I Nner loopif (FACE-&GT;OUT_LP = = NULL) {FACE-&GT;OUT_LP = loop;} Else{loop *TLP = face->inner_lp;if (TLP = = null) FACE-&GT;INNER_LP = Loop;else{while (tlp->next! = NULL) TLP = Tlp-&gt ; next;tlp->next = Loop;loop->pre = TLP;} Face->innum + = 1;}}

The above is the basic implementation, and then add their own input and output to achieve the construction of the hole model.


watermark/2/text/ahr0cdovl2jsb2cuy3nkbi5uzxqvsufjy2vwdgvk/font/5a6l5l2t/fontsize/400/fill/i0jbqkfcma==/ Dissolve/70/gravity/center ">


watermark/2/text/ahr0cdovl2jsb2cuy3nkbi5uzxqvsufjy2vwdgvk/font/5a6l5l2t/fontsize/400/fill/i0jbqkfcma==/ Dissolve/70/gravity/center ">

The above is simply built with a hole model, of course, can build a lot of other holes in the body, the construction of different shapes of holes, so that the completion of the job requirements.


Each operation is very simple, the key is the MEF should pay attention to the choice of face ring when the normal problem can be. Using the right hand rule to make a few gestures can be very easy to determine. After each hole is swept, remember to KFMRH to get the hole.

OK, that's all.

The above code link: http://download.csdn.net/detail/iaccepted/8167679

Copyright notice: This article Bo Master original article. Blog, not reproduced without consent.

Three-dimensional CAD molding--half Euler operation model based on the basic data structure

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.