00001
00008 #ifdef HAVE_CONFIG_H
00009 #include <tumble-conf.h>
00010 #endif
00011
00012 #include "boundarymesh.h"
00013
00014 #include "datastore.h"
00015 #include "spline.h"
00016
00017 using namespace std;
00018
00019 BoundaryMesh::BoundaryMesh(PersistantStore& pstore, DataStore *dstore)
00020 : BoundaryComplex(pstore), beziermesh(NULL), datastore(dstore)
00021 {
00022 }
00023
00024 void BoundaryMesh::set_bezier_mesh(BezierMesh* bez) {
00025 assert(!beziermesh);
00026 beziermesh = bez;
00027 }
00028
00034 BoundaryVertex* BoundaryMesh::add_boundary_vertex(const Point2D& p)
00035 {
00036 ControlPoint cp = datastore->add_cp(p);
00037 BoundaryVertex *bv = new BoundaryVertex(get_store(), cp);
00038 add_vertex(bv);
00039 return bv;
00040 }
00041
00042 BoundaryEdge* BoundaryMesh::add_boundary_edge(BoundaryVertex *v0,BoundaryVertex *v1, const vector<Point2D> &newd, const vector<double> &newk, Movement _fixed, int _color, double _restlength)
00043 {
00044 BoundaryEdge *be = add_boundary_edge(v0, v1, newd, newk);
00045 be->set_fixed(_fixed);
00046 be->set_color(_color);
00047 be->set_restlength( _restlength );
00048
00049 return be;
00050 }
00051
00052
00053
00054 BoundaryEdge* BoundaryMesh::add_boundary_edge(BoundaryVertex *v0,
00055 BoundaryVertex *v1,
00056 const vector<Point2D>& newd,
00057 const vector<double>& newk)
00058 {
00059
00060 assert(v0); assert(v1);
00061 assert(newd.size() >= 3);
00062 assert(newk.size() >= 2);
00063
00064
00065 vector<ControlPoint> deboor;
00066 deboor.push_back(v0->get_control_point());
00067 for(unsigned i=1; i < newd.size()-1; i++){
00068 deboor.push_back( datastore->add_cp( newd[ i ] ) );
00069 }
00070 deboor.push_back(v1->get_control_point());
00071
00072
00073 BoundaryEdge *be = new BoundaryEdge(get_store(), v0, v1,
00074 deboor, newk, datastore);
00075 add_edge(be);
00076 return be;
00077 }
00078
00079
00080 BoundaryFace* BoundaryMesh::add_boundary_face(const vector<BoundaryEdge*> &edges,double minangle, int color)
00081 {
00082 BoundaryFace *bf=new BoundaryFace(get_store(), minangle,color);
00083 BoundaryEdge **es = new BoundaryEdge*[edges.size()];
00084 for(unsigned i=0; i < edges.size(); i++) es[i]=edges[i];
00085 add_face(bf,es,edges.size());
00086 return bf;
00087 }
00088
00089 void BoundaryMesh::delete_vertex(BoundaryVertex *v)
00090 {
00091 while(v->num_edges() > 0) {
00092 delete_edge(v->get_any_edge());
00093 }
00094 datastore->rem_cp(v->get_control_point());
00095 BoundaryComplex::delete_vertex(v);
00096 }
00097
00098
00099 void BoundaryMesh::delete_edge(BoundaryEdge *e)
00100 {
00101 QBSpline *spline=e->get_spline();
00102 for(unsigned i = 1; i < spline->b.size() - 1; i++) {
00103 datastore->rem_cp( spline->b[i] );
00104 }
00105 BoundaryComplex::delete_edge( e );
00106 }
00107
00112 void BoundaryMesh::bbox(Point2D &top, Point2D &bot)
00113 {
00114 Boundary_Edge_Hash_T::iterator i;
00115 for(i = get_edges_begin(); i != get_edges_end(); ++i){
00116 double x_max,x_min,y_max,y_min;
00117 (*i)->get_spline()->bbox(&y_max,&x_min,&y_min,&x_max);
00118 if(x_max > top.coords[0]) top.coords[0]=x_max;
00119 if(y_max > top.coords[1]) top.coords[1]=y_max;
00120 if(x_min < bot.coords[0]) bot.coords[0]=x_min;
00121 if(y_min < bot.coords[1]) bot.coords[1]=y_min;
00122 }
00123 Boundary_Vertex_Hash_T::iterator j;
00124 for(j = get_vertices_begin(); j!= get_vertices_end(); ++j){
00125 double x,y;
00126 x = (*j)->get_control_point()->x();
00127 y = (*j)->get_control_point()->y();
00128 if(x > top.coords[0]) top.coords[0]=x;
00129 if(y > top.coords[1]) top.coords[1]=y;
00130 if(x < bot.coords[0]) bot.coords[0]=x;
00131 if(y < bot.coords[1]) bot.coords[1]=y;
00132 }
00133 }
00134
00136 ostream& operator<<(ostream &stream, const BoundaryMesh &bm)
00137 {
00138 stream<<"BoundaryMesh:"<<endl;
00139 stream<<" beziermesh: "<<bm.beziermesh<<endl;
00140 stream<<" datastore: "<<bm.datastore<<endl;
00141 stream<<" CellComplex: "<<endl;
00142 stream<<*((BoundaryComplex*)(&bm))<<endl;
00143 return stream;
00144 }
00145
00146