Home || Architecture || Video Search || Visual Search || Scripts || Applications || Important Messages || OGL || Src

mainConceptSupport.cpp

Go to the documentation of this file.
00001 /*
00002 12345678901234567890123456789012345678901234567890123456789012345678901234567890
00003 */
00004 
00005 #define ALL_AT_ONCE
00006 #define ANIMATE_POINTS
00007 
00008 #include "OglGui/View.h"
00009 #include "OglGui/ViewerPoint.h"
00010 #include "OglGui/ViewerPointCloud.h"
00011 #include "OglGui/ViewerPointCloudNavigator.h"
00012 #include "OglGui/WindowView2D.h"
00013 #include "OglGui/ConceptSupportControl.h"
00014 #include "OglGui/FramesPerSecond.h"
00015 #include "Core/Array/ReadJpg.h"
00016 #include "Visualization/RgbOglImage.h"
00017 #include "OglGui/OglLib.cpp"
00018 #include "Link/ImpalaLib.cpp"
00019 
00020 using namespace OglGui;
00021 
00022 using Impala::Core::Array::Array2dVec3UInt8;
00023 
00024 OGLIMAGE* OglImageReadJpg(strconst str)
00025 {
00026     Array2dVec3UInt8*   im = 0;
00027     ReadJpg(im, str);
00028     return Impala::Visualization::RgbOglImage::OglImage(im);
00029 }
00030 
00031 OGLVIEW* ViewReadImage(OGLWND* oglWnd, int n)
00032 {
00033     char    buf[256];
00034     sprintf(buf, "/map176x120/image%d.jpg", n);
00035     OGLIMAGE* im = OglImageReadJpg(buf);
00036     OGLVIEW* view = viewSys.View2D(oglWnd, im, 0,0,6,6);
00037     viewSys.SetTags(view, FlexViewTags);
00038     //viewSys.ClearTags(view, deletableTag);
00039     view->borderCol = oglRED;
00040     //viewSys.SetTexturing(view, 1);
00041     viewSys.ClearTags(view, visibleTag);
00042     oglSys.ReleaseOglImage(im);
00043     return view;
00044 }
00045 
00046 void FormatError(char *str)
00047 {
00048     fprintf(stderr, "%s", str);
00049     exit(1);
00050 }
00051 
00052 OGLVIEW* ViewReadImageFile(OGLWND* oglWnd, char *fileName)
00053 {
00054     OGLIMAGE* im = OglImageReadJpg(fileName);
00055     OGLVIEW* view = viewSys.View2D(oglWnd, im, 0,0,6,6);
00056     viewSys.SetTags(view, FlexViewTags);
00057     //viewSys.ClearTags(view, deletableTag);
00058     view->borderCol = oglRED;
00059     //viewSys.SetTexturing(view, 1);
00060     viewSys.ClearTags(view, visibleTag);
00061     oglSys.ReleaseOglImage(im);
00062     return view;
00063 }
00064 
00065 void ReadTheImages(FILE* fp, OGLWND *oglWnd, ULONG *colors, int maxNr,
00066                    float minX, float maxX, float minY, float maxY)
00067 {
00068     int res;
00069     float   ptX, ptY;
00070     char    buf[512];
00071     int     id;
00072     int     count = 0;
00073     while(count<maxNr && fscanf(fp, "%511s %f %f %d\n", buf, &ptX, &ptY, &id) != EOF)
00074     {
00075 
00076         OGLVIEW*    view = ViewReadImageFile(oglWnd, buf);
00077         view->borderCol = colors[id];
00078         float x = minX + ptX * (maxX-minX);
00079         float y = minY + ptY * (maxY-minY);
00080         new ViewerPoint(view, x, y);
00081 
00082 //        if (!(count %100))
00083 //            printf("%f %f\n", x, y);
00084         if (!(count++ % 1000))
00085             printf("%d\n", count);
00086     }
00087     printf("Finished reading %d images\n", count);
00088 }
00089 
00090 void WriteImageFile(char *fileName, int maxNr, float minX, float maxX,
00091                     float minY, float maxY, char *imageName)
00092 {
00093     FILE* fp = fopen(fileName, "w");
00094     if (!fp)
00095         FormatError("Could not open file for writing\n");
00096     fprintf(fp, "%d\n%f %f %f %f\n", maxNr, minX, maxX, minY, maxY);
00097     for (int i=0; i<maxNr; i++)
00098     {
00099         float   x1 = (130 * sin(i/30.) + 20 - rand()%40) + 150;
00100         float   y1 = (130 * cos(i/30.) + 20 - rand()%40) + 150;
00101         float   ptX = x1 / (maxX-minX);
00102         float   ptY = y1 / (maxY-minY);
00103 
00104         char    buf[512];
00105         sprintf(buf, "%s%d.jpg ", imageName, i+1);
00106         fprintf(fp, " %s %f %f %d\n", buf, ptX, ptY, i%8);
00107     }
00108 }
00109 
00110 int main(int argc, char* argv[])
00111 {
00112     FILE*   fp;
00113 
00114     OglInit(&argc, &argv[0]);
00115 
00116     //WriteImageFile("\\Images.txt", 50001, -150, 150, -150, 150, "\\map88x60\\image");
00117     //exit(1);
00118     if (argc < 2)
00119     {
00120         fprintf(stderr, "Usage %s <images_file>\n", argv[0]);
00121         exit(1);
00122     }
00123     if (!(fp=fopen(argv[1], "r")))
00124     {
00125         fprintf(stderr, "%s could not open: %s\n", argv[0], argv[1]);
00126         exit(1);
00127     }
00128     int     maxNr;
00129     float   minX, maxX, minY, maxY;
00130 
00131     if (5 != fscanf(fp, "%d\n%f %f %f %f\n", &maxNr, &minX, &maxX, &minY, &maxY))
00132     {
00133         FormatError("Format error\nFormat:\nMaxNr\nMinX MaxX MinY MaxY\nfilename x y setId\n");
00134         fprintf(stderr,
00135 "Example:\n10000\n0 400 0 400\nC:\\images\\image1.jpg 0.102 0.63146 0\nC:\\otherims\\otherim.jpg 0.20253 0.53121 4\n");
00136     }
00137     
00138     Window* wnd = new Window(0, 0, 1024, 768);
00139     wnd->SetBackground(oglGUI_BG);
00140     oglSys.SetSleepTime(wnd->GetOGLWND(), 0);
00141 
00142     ViewerPointCloud* vpc = new ViewerPointCloud(wnd, 0, 0, 768, 768);
00143     vpc->SetBorderType(BEV_LINE);
00144 
00145     new FramesPerSecond(vpc, 0, 0, 60, 20);
00146 
00147     WindowView2D* detailWnd = new WindowView2D(wnd, 768, 0, 256, 256, NULL);
00148     detailWnd->GetOglView()->texturing = false;
00149     detailWnd->SetScaleToWindow(false);
00150     vpc->DetailImageInterface(detailWnd);
00151 
00152     ViewerPointCloudNavigator* vpcNavigator =
00153         new ViewerPointCloudNavigator(wnd, 768, 512, 256, 256);
00154     vpcNavigator->SetTarget(vpc);
00155 
00156     ConceptSupportControl* csControl =
00157         new ConceptSupportControl(wnd, 768, 256, 256, 256);
00158     csControl->SetBorderType(BEV_ETCHED);
00159     csControl->SetViewerPointCloud(vpc);
00160 
00161     ReadTheImages(fp, vpc->GetOGLWND(), csControl->Colors(), maxNr, minX, maxX, minY, maxY);
00162     fclose(fp);
00163     vpc->SetPtDocXY(vpc->W()/2 -minX -(maxX-minX)/2, vpc->H()/2 -minY -(maxY-minY)/2);
00164 
00165     wnd->ScaleChildren(0,1);
00166     if (!wnd->Valid())
00167     {
00168         fprintf( stderr, "ConceptSupport failed\n" );
00169         return 0;
00170     }
00171 
00172     wnd->Start(); // start OGL
00173     OglEventLoop();
00174     return 1;
00175 }

Generated on Fri Mar 19 09:30:28 2010 for ImpalaSrc by  doxygen 1.5.1