70 else if ( key ==
'p' ) {
73 else if ( key ==
's' ) {
74 glShadeModel(GL_SMOOTH);
77 else if ( key ==
'f' ) {
78 glShadeModel(GL_FLAT);
81 else if ( key ==
'q' ) {
85 else if ( key ==
'r' ) {
89 else if (key ==
'i') {
97 glReadPixels(0, 0,
grab->width,
grab->height,
98 GL_RGB, GL_UNSIGNED_BYTE,
grab->imageData);
99 cvSaveImage(
"res.bmp",
grab);
108 double x = 0, y = 0, color = 0;
111 glClear (GL_COLOR_BUFFER_BIT);
116 for(fai =
dt.all_faces_begin(); fai !=
dt.all_faces_end(); fai++) {
117 if(
dt.is_infinite(fai))
121 for(
int k = 0; k < 3; k ++) {
122 Point pt = fai->vertex(k)->point();
123 color = ((uchar*)(
src->imageData +
124 int(pt.y()/
ratio) *
src->widthStep))[
int(pt.x()/
ratio)] / 255.0f;
125 if(
mode == GL_LINE_LOOP)
126 glColor3f(0.5, 0.5, 1);
128 glColor3f(color, color, color);
144 glClearColor (0.0, 0.0, 0.0, 0.0);
145 glShadeModel (GL_FLAT);
151 glViewport(0, 0, (GLsizei) w, (GLsizei) h);
152 glMatrixMode(GL_PROJECTION);
154 gluOrtho2D(0.0, (GLdouble) w, 0.0, (GLdouble) h);
166 assert(src->nChannels == 1);
170 for(
int j = 0; j < src->height; j ++) {
171 for(
int i = 0; i < src->width; i ++) {
172 tmp = int(((uchar*)(src->imageData + j * src->widthStep))[i]);
173 pt =
Point(ratio * i, ratio * j);
175 values->insert(std::make_pair(pt, tmp));
180 std::cout <<
"width, height of source img: " << src->width <<
", " << src->height << std::endl;
181 std::cout <<
"upsample ratio: " << ratio << std::endl;
182 std::cout <<
"# of vertices: " <<
dt.number_of_vertices() << std::endl;
194 char* argvg[] = {
"interpolation"};
195 glutInit(&argcg, argvg);
196 glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB);
197 glutInitWindowSize(w,h);
198 glutInitWindowPosition(100,100);
199 glutCreateWindow(
"Interpolation");
206 glShadeModel(GL_SMOOTH);
217 assert(src->nChannels == 1);
220 wraper(&values, src, ratio);
221 std::cout <<
"Done Delaunay " << std::endl;
224 for(
int itr=0;itr<4;itr++)
226 std::cout<<
"Iteration "<<itr<<std::endl;
237 if(
dt.is_infinite(f))
241 if(!
dt.is_edge(f->vertex(f->cw(i)),f->vertex(f->ccw(i))))
244 if(
dt.is_infinite(f->vertex(f->cw(i))))
246 if(
dt.is_infinite(f->vertex(f->ccw(i))))
248 edges.push_back(
GEdge(f->vertex(f->cw(i)),f->vertex(f->ccw(i))));
249 push_heap(edges.begin(), edges.end()) ;
251 }
while(++ei!=
dt.finite_edges_end());
257 for(evi=edges.begin();evi!=edges.end();evi++)
260 printf(
"edge %d\n",cnt);
266 pop_heap(edges.begin(), edges.end()) ;
271 if(!v1->is_valid() || !v2->is_valid() ||
dt.is_infinite(v1) ||
dt.is_infinite(v2))
276 if(!
dt.is_edge(v1,v2))
279 if(
dt.is_edge ( v1, v2,f1,i))
282 if(!
dt.is_infinite(f1))
286 if(
dt.is_edge(v2,v1,f2,j) && !
dt.is_infinite(f2) && f1->has_neighbor(f2))
289 GPoint pts[]={
GPoint(v1->point().x(),v1->point().y()),
GPoint(f1->vertex(i)->point().x(),f1->vertex(i)->point().y()),
GPoint(v2->point().x(),v2->point().y()),
GPoint(f2->vertex(j)->point().x(),f2->vertex(j)->point().y())};
312 std::cout <<
"Done DDT " << std::endl;
315 res = cvCreateImage(cvSize((src->width - 1) * ratio + 1,
316 (src->height - 1) * ratio + 1), IPL_DEPTH_8U, 1);
317 grab = cvCreateImage(cvGetSize(
res), IPL_DEPTH_8U, 3);
321 std::cout <<
"Done interpolation " << std::endl;
328 int main(
int argc,
char** argv)
330 char* filename = NULL;
335 ratio = atoi(argv[2]);
338 filename =
"test.bmp";
343 src = cvLoadImage(filename, 0);
346 IplImage*
res =
ddt(src, ratio);
347 cvSaveImage(
"ddt.bmp", res);
void onKeyPress(unsigned char key, int x, int y)
IplImage * ddt(IplImage *src, int ratio)
CDT::All_faces_iterator All_faces_iterator
CGAL::Polygon_2< K1 > Polygon_2
int wraper(Point_value_map *values, IplImage *src, int ratio)
std::pair< Vertex_handle, Vertex_handle > GEdge
Delaunay::Finite_edges_iterator Edge_iterator
EdgeVector::iterator EdgeVectorIterator
bool processForCost(Face_handle f1, int i, Point_value_map values, Delaunay *dt)
int main(int argc, char **argv)
Ss::Vertex_handle Vertex_handle
std::vector< GEdge > EdgeVector
std::map< Point, Coord_type, K::Less_xy_2 > Point_value_map
void reshape(int w, int h)
CGAL::Delaunay_triangulation_2< K > Delaunay
CDT::Face_handle Face_handle