00001 #ifndef SHAPE_INTERSECTOR_PARAMETRIC_HPP
00002 #define SHAPE_INTERSECTOR_PARAMETRIC_HPP
00003
00004 # include <shape/ssi/ssi_dsearch.hpp>
00005 # include <shape/ssi/ssiqtsl.hpp>
00006
00007 #define TMPL template<class C, class V>
00008
00009 namespace mmx { namespace shape {
00010
00022 template<class C,class V= default_env>
00023 struct intersector_parametric {
00024 typedef typename use<ssi_def,C,V>::ParametricSurface Input;
00025 typedef typename use<ssi_def,C,V>::Mesh Output;
00026 typedef typename use<ssi_def,C,V>::Mesh::Point Point;
00027
00028 intersector_parametric(): u_spl(200), v_spl(200) {
00029 input1 = NULL;
00030 input2 = NULL;
00031 output = NULL;
00032 }
00033
00034 intersector_parametric(Input *s): u_spl(200), v_spl(200), input1(s), input2(s) {
00035 output = NULL;
00036 }
00037
00038 intersector_parametric(Input *s1, Input* s2): u_spl(200), v_spl(200), input1(s1), input2(s2) {
00039 output = NULL;
00040 }
00042 void set_sample(int n) { u_spl=n; v_spl=n;}
00044 void set_sample(int n, int m) { u_spl=n; v_spl=m;}
00045
00046 void set_input (Input* s) { input1 = s; input2 = s; }
00047
00048 void set_input (Input* s1, Input* s2) { input1 = s1; input2 = s2; }
00049 void set_input1(Input* s) { input1 = s; }
00050 void set_input2(Input* s) { input2 = s; }
00051
00052 Output* get_output() {return output;}
00053
00054 void run ();
00055
00056 private:
00057 void run_inter (void);
00058 void run_self (void);
00059 int u_spl, v_spl;
00060 Input * input1, * input2;
00061 Output * output;
00062 };
00063
00064 TMPL void intersector_parametric<C,V>::run(void) {
00065 if( input1 == input2 )
00066 this->run_self();
00067 else
00068 this->run_inter();
00069 }
00070 TMPL void intersector_parametric<C,V>::run_self(void) {
00071 mmx::ssi::dsearch<C,V> r(input1,u_spl,v_spl);
00072
00073 output = new Output;
00074
00075 C x,y,z;
00076 for ( unsigned i = 0; i < r.nbcurves; i++ )
00077 for ( unsigned k = 0; k < r.sizes[i]; k++ )
00078 {
00079
00080 input1->eval(x,y,z, r.lefts[i][k][0],r.lefts[i][k][1]);
00081 output->push_back_vertex(new Point(x,y,z));
00082 Point* p= new Point;input1->eval(p->x(),p->y(),p->z(), r.lefts[i][k][0],r.lefts[i][k][1]);
00083
00084
00085
00086 };
00087
00088 int np=0;
00089 for ( unsigned i = 0; i < r.nbcurves; i++ )
00090 for (unsigned k = 0; k < r.sizes[i]; k+=2 )
00091 {
00092 output->push_back_edge(np,np+1);
00093 np+=2;
00094 };
00095
00096 }
00097
00098 TMPL void intersector_parametric<C,V>::run_inter(void) {
00099 std::cerr<<"Intersect:"<< u_spl <<std::endl;
00100
00101 ssiqtsl<C,V> r(input1, input2, u_spl);
00102
00103 output = new Output;
00104 int nbv =r.spcs.size();
00105
00106 for ( int i = 0; i < nbv; i ++) {
00107 Point* p = new Point(r.spcs[i][0], r.spcs[i][1], r.spcs[i][2]);
00108 output->push_back_vertex(p);
00109 }
00110
00111 for ( int i = 0; i < nbv; i+=2) {
00112 output->push_back_edge(i, i+1);
00113 }
00114
00115 }
00116
00117
00118 }
00119 }
00120
00121 #undef TMPL
00122
00123 #endif // SHAPE_INTERSECTOR_PARAMETRIC_HPP