00001
00002
00003
00004
00043
00053
00065
00094 mhe[0] = pt_array[focus][p0]->lookup_hedge(pt_array[focus][p1]);
00095 mhe[1] = pt_array[focus][p1]->lookup_hedge(pt_array[focus][p2]);
00096 mhe[2] = pt_array[focus][p2]->lookup_hedge(pt_array[focus][p0]);
00097
00098
00099 is_manifold = true;
00100 for(j =0;j<3; j++)
00101 if (mhe[j]!=NULL && !mhe[j]->edge()->is_bdry())
00102 is_manifold = false;
00103
00104 if(is_manifold){
00105
00106
00107 f = surf[focus]->create(pt_array[focus][p0],
00108 pt_array[focus][p1],
00109 pt_array[focus][p2]);
00110 he[0]=f->hedge(0);
00111 he[1]=f->hedge(1);
00112 he[2]=f->hedge(2);
00113
00114
00115 if(mhe[0]!=NULL)
00116 surf[focus]->glue(mhe[0], he[0]);
00117
00118 if(mhe[1]!=NULL)
00119 surf[focus]->glue(mhe[1], he[1]);
00120
00121 if(mhe[2]!=NULL)
00122 surf[focus]->glue(mhe[2], he[2]);
00123 }
00124 break;
00125 default:
00126 break;
00127 }
00128
00129 return 1;
00130 }
00131
00133
00134 \endcode
00135
00136 In this function we use explicitly stellars API's.
00137
00138 \code
00139 void sqrt_3_subdivide(Surf* s){
00140
00141 Vertex *v, *v0, *v1, *v2;
00142 Hedge *he;
00143 Face *f;
00144 vec3 temp(0, 0, 0);
00145 float alpha; int n;
00146
00147 FaceIter face_iter;
00148 VertexIter verts_iter;
00149 EdgeIter edge_iter;
00150 vector<Face*>::iterator face_iter1;
00151 vector<Vertex*>::iterator verts_iter1;
00152 vector<Edge*>::iterator edge_iter1;
00153
00154 vector<Face*> old_faces;
00155 vector<Vertex*> old_verts;
00156 vector<Edge*> old_edges;
00157 vector<vec3> old_points_displct;
00158
00159
00160 for(face_iter = s->faces_begin();face_iter!=s->faces_end(); face_iter++)
00161 old_faces.push_back(*face_iter);
00162
00163
00164 for(verts_iter = s->verts_begin();verts_iter!=s->verts_end(); verts_iter++)
00165 old_verts.push_back(*verts_iter);
00166
00167
00168 for(edge_iter = s->edges_begin();edge_iter!=s->edges_end(); edge_iter++)
00169 old_edges.push_back(*edge_iter);
00170
00171
00172 for(face_iter1 = old_faces.begin();face_iter1!=old_faces.end(); face_iter1++)
00173 {
00174 f = (*face_iter1);
00175 v0 = f->vertex(0);
00176 v1 = f->vertex(1);
00177 v2 = f->vertex(2);
00178 v = s->split(f);
00179
00180 v->p()->add((v0->p()->p() + v1->p()->p() + v2->p()->p())/3.0);
00181 }
00182
00183
00184 for(verts_iter1 = old_verts.begin();verts_iter1!=old_verts.end(); verts_iter1++)
00185 {
00186 v = *verts_iter1;
00187 temp = vec3(0, 0, 0);
00188 for(n =0, he = v->star_first(); he!=NULL; he = v->star_next(he), n++)
00189 {
00190 if(!(n%2)){
00191 temp += he->org()->p()->p();}
00192 }
00193 alpha = (4 - 2*cos(4*M_PI/n))/9;
00194 temp = v->p()->p()*(1-alpha) + 2*alpha*temp/n;
00195 old_points_displct.push_back(temp);
00196 }
00197
00198
00199 for(n =0; n< old_verts.size(); n++)
00200 {
00201 v = old_verts[n];
00202 v->p()->add(old_points_displct[n] - v->p()->p());
00203 }
00204
00205
00206 for(edge_iter1 = old_edges.begin(); edge_iter1!=old_edges.end(); edge_iter1++)
00207 s->flip((*edge_iter1)->hedge(0));
00208 }
00209
00210 \endcode
00211
00212 The Display is done with OpenGl.
00213
00214 \code
00215 void draw_tri(double x0, double y0, double z0,
00216 double x1, double y1, double z1,
00217 double x2, double y2, double z2)
00218 {
00219 glColor3f (0.0, 0.0, 0.0);
00220 glBegin(GL_LINE_LOOP);
00221 glVertex3d(x0, y0, z0);
00222 glVertex3d(x1, y1, z1);
00223 glVertex3d(x2, y2, z2);
00224 glEnd();
00225 }
00226
00227 void display_mesh()
00228 {
00229 vec3 p0, p1, p2;
00230 FaceIter f;
00231
00232 glPushMatrix();
00233 glTranslatef(-1.5, 0.0, 0);
00234 for (f = surf[0]->faces_begin(); f != surf[0]->faces_end(); f++) {
00235 p0=(*f)->vertex(0)->p()->p();
00236 p1=(*f)->vertex(1)->p()->p();
00237 p2=(*f)->vertex(2)->p()->p();
00238 draw_tri(p0[0], p0[1], p0[2],
00239 p1[0], p1[1], p1[2],
00240 p2[0], p2[1], p2[2]);
00241 }
00242 glPopMatrix();
00243
00244 glPushMatrix();
00245 glTranslatef(1.5, 0,0);
00246 for (f = surf[1]->faces_begin(); f != surf[1]->faces_end(); f++) {
00247 p0=(*f)->vertex(0)->p()->p();
00248 p1=(*f)->vertex(1)->p()->p();
00249 p2=(*f)->vertex(2)->p()->p();
00250 draw_tri(p0[0], p0[1], p0[2],
00251 p1[0], p1[1], p1[2],
00252 p2[0], p2[1], p2[2]);
00253 }
00254 glPopMatrix();
00255 }
00256
00257 void initgl(void)
00258 {
00259 glClearColor (1.0, 1.0, 1.0, 1.0);
00260 glMatrixMode(GL_PROJECTION);
00261 glLoadIdentity();
00262 glOrtho(-3.0, 3.0, -1.5, 1.5, -1.0, 1.0);
00263 }
00264
00265 void display(void)
00266 {
00267 glClear (GL_COLOR_BUFFER_BIT);
00268 display_mesh();
00269 glutSwapBuffers();
00270 }
00271 \endcode
00272
00273 The application is based on GLUT and uses the "s" key to subdivide the sphere on the right.
00274
00275 \code
00276 void keyboard(unsigned char key, int x, int y)
00277 {
00278 switch(key) {
00279 case 27: exit(0);
00280 case 's':
00281 sqrt_3_subdivide(surf[1]);
00282 glutPostRedisplay();
00283 break;
00284
00285 default: break;
00286 }
00287 }
00288
00289 int main(int argc, char** argv)
00290 {
00291 int wsize = 512;
00292
00293 surf[0] = new Surf();
00294 surf[1] = new Surf();
00295
00296 focus = 0;
00297 read_ply("./sphere.ply");
00298 focus = 1;
00299 read_ply("./sphere.ply");
00300
00301 glutInit(&argc, argv);
00302 glutInitDisplayMode (GLUT_DOUBLE | GLUT_RGB);
00303 glutInitWindowSize (2*wsize, wsize);
00304 glutCreateWindow ("viewply");
00305 initgl();
00306 glutDisplayFunc(display);
00307 glutKeyboardFunc(keyboard);
00308 glutMainLoop();
00309 return 0;
00310 }
00311
00312 \endcode
00313
00314 */