Beispiel #1
0
//------------------------------------------------------------------------------
void
keyboard(unsigned char key, int x, int y) {

    switch (key) {
        case 'q': quit();
        case 'w': g_wire = (g_wire+1)%2; break;
        case 'e': g_drawNormals = (g_drawNormals+1)%2; break;
        case 'f': fitFrame(); break;
        case 'a': if (g_osdPTexOcclusion) g_occlusion = !g_occlusion; linkProgram(); break;
        case 'd': if (g_osdPTexDisplacement) g_displacement = !g_displacement; linkProgram();break;
        case 'c': g_color = !g_color; linkProgram(); break;
        case 's': schemeMenu(!g_scheme); break;
        case 'm': g_moveScale = 1.0f - g_moveScale; break;
        case 'p': g_ptexDebug++; break;
        case 'o': g_ptexDebug = std::max(0, g_ptexDebug-1); break;
        case 'g': g_gutterWidth = (g_gutterWidth+1)%8; createOsdMesh(g_level, g_kernel); break;
        case 'h': g_gutterDebug = !g_gutterDebug; createOsdMesh(g_level, g_kernel); break;
        case '1':
        case '2':
        case '3':
        case '4':
        case '5':
        case '6':
        case '7': levelMenu(key-'0'); break;
    }
}
Beispiel #2
0
void preFitFrame(char *command, FILE *gnuPipe, int npnts, double chisq)
{
   fprintf(gnuPipe, "set logscale y\n"
	            "set bar small\n"
                    "set xlabel \"%s\"\n"
                    "set ylabel \"%s\"\n"
                    "plot \"%s\" w errorbars, \"%s\" w line\n",
                    qlabel, rlabel, infile, fitfile);
   fitFrame(gnuPipe, npnts, chisq);

   queryString("Wait for first frame, then press enter to commence fitting. ",
      NULL, 0);
}
Beispiel #3
0
void preFitFrame(char *command, FILE *gnuPipe, int xspin[4], double chisq)
{
   /* Determine reflectivities to print */
   setPspin(pspin, xspin, command + 3);

#if LINEAR_DATA
   fputs("set logscale y\n", gnuPipe);
#endif
   fputs("set bar small\n", gnuPipe);
   fitFrame(gnuPipe, xspin, chisq);

   queryString("Wait for first frame, then press enter to commence fitting. ",
      NULL, 0);
}
Beispiel #4
0
//------------------------------------------------------------------------------
void
keyboard(unsigned char key, int x, int y) {

    switch (key) {
        case 'q': quit();
        case ' ': g_freeze = (g_freeze+1)%2; break;
        case 'w': g_wire = (g_wire+1)%3; break;
        case 'e': g_drawNormals = (g_drawNormals+1)%2; break;
        case 'f': fitFrame(); break;
        case 'm': g_moveScale = 1.0f - g_moveScale; break;
        case 'h': g_drawCoarseMesh = (g_drawCoarseMesh+1)%3; break;
        case '1':
        case '2':
        case '3':
        case '4':
        case '5':
        case '6':
        case '7': levelMenu(key-'0'); break;
        case 'n': modelMenu(++g_currentShape); break;
        case 'p': modelMenu(--g_currentShape); break;
        case 0x1b: g_drawHUD = (g_drawHUD+1)%2; break;
    }
}
//------------------------------------------------------------------------------
static void
keyboard(GLFWwindow *, int key, int /* scancode */, int event, int /* mods */) {

    if (event == GLFW_RELEASE) return;
    if (g_hud.KeyDown(tolower(key))) return;

    switch (key) {
        case 'Q': g_running = 0; break;
        case 'F': fitFrame(); break;

        case '[': if (g_currentPatch > 0) {
                      --g_currentPatch;
                      rebuildOsdMeshes();
                  } break;

        case ']': if (g_currentPatch < g_numPatches) {
                      ++g_currentPatch;
                      rebuildOsdMeshes();
                  } break;

        case GLFW_KEY_TAB: toggleFullScreen(); break;
        case GLFW_KEY_ESCAPE: g_hud.SetVisible(!g_hud.IsVisible()); break;
    }
}
Beispiel #6
0
//------------------------------------------------------------------------------
static void
#if GLFW_VERSION_MAJOR>=3
keyboard(GLFWwindow *, int key, int scancode, int event, int mods) {
#else
#define GLFW_KEY_ESCAPE GLFW_KEY_ESC
keyboard(int key, int event) {
#endif

    if (event == GLFW_RELEASE) return;
    if (g_hud.KeyDown(tolower(key))) return;

    switch (key) {
        case 'Q': g_running = 0; break;
        case 'F': fitFrame(); break;
        case '+':  
        case '=': g_tessLevel++; break;
        case '-': g_tessLevel = std::max(g_tessLevelMin, g_tessLevel-1); break;
        case '.': g_moveModels = std::max(g_moveModels*2, 1); break;
        case ',': g_moveModels = std::max(g_moveModels/2, 0); break;
        case 'I': g_modelCount = std::max(g_modelCount/2, 1); rebuild(); break;
        case 'O': g_modelCount = std::min(g_modelCount*2, MAX_MODELS); rebuild(); break;
        case GLFW_KEY_ESCAPE: g_hud.SetVisible(!g_hud.IsVisible()); break;
    }
}

//------------------------------------------------------------------------------
static void
callbackDisplayStyle(int b)
{
    if (g_displayStyle == kVaryingColor or b == kVaryingColor or
        g_displayStyle == kFaceVaryingColor or b == kFaceVaryingColor) {
        // need to rebuild for varying reconstruct
        g_displayStyle = b;
        rebuild();
        return;
    }
    g_displayStyle = b;
}

static void
callbackKernel(int k)
{
    g_kernel = k;

#ifdef OPENSUBDIV_HAS_OPENCL
    if (g_kernel == kCL and g_clContext == NULL) {
        if (initCL(&g_clContext, &g_clQueue) == false) {
            printf("Error in initializing OpenCL\n");
            exit(1);
        }
    }
#endif
#ifdef OPENSUBDIV_HAS_CUDA
    if (g_kernel == kCUDA and g_cudaInitialized == false) {
        g_cudaInitialized = true;
        cudaGLSetGLDevice( cutGetMaxGflopsDeviceId() );
    }
#endif

    rebuild();
}
Beispiel #7
0
//------------------------------------------------------------------------------
int main(int argc, char ** argv) {

    glutInit(&argc, argv);

    glutInitDisplayMode(GLUT_RGBA |GLUT_DOUBLE | GLUT_DEPTH);
    glutInitWindowSize(1024, 1024);
    glutCreateWindow("OpenSubdiv ptexViewer");

    int lmenu = glutCreateMenu(levelMenu);
    for(int i = 1; i < 8; ++i){
        char level[16];
        sprintf(level, "Level %d\n", i);
        glutAddMenuEntry(level, i);
    }
    int smenu = glutCreateMenu(schemeMenu);
    glutAddMenuEntry("Catmark", 0);
    glutAddMenuEntry("Bilinear", 1);

    // Register Osd compute kernels
    OpenSubdiv::OsdCpuKernelDispatcher::Register();

#if OPENSUBDIV_HAS_GLSL
    OpenSubdiv::OsdGlslKernelDispatcher::Register();
#endif

#if OPENSUBDIV_HAS_OPENCL
    OpenSubdiv::OsdClKernelDispatcher::Register();
#endif

#if OPENSUBDIV_HAS_CUDA
    OpenSubdiv::OsdCudaKernelDispatcher::Register();

    // Note: This function randomly crashes with linux 5.0-dev driver.
    // cudaGetDeviceProperties overrun stack..?
    cudaGLSetGLDevice( cutGetMaxGflopsDeviceId() );
#endif

    int kmenu = glutCreateMenu(kernelMenu);
    int nKernels = OpenSubdiv::OsdKernelDispatcher::kMAX;

    for(int i = 0; i < nKernels; ++i)
        if(OpenSubdiv::OsdKernelDispatcher::HasKernelType(
               OpenSubdiv::OsdKernelDispatcher::KernelType(i)))
            glutAddMenuEntry(getKernelName(i), i);

    glutCreateMenu(menu);
    glutAddSubMenu("Level", lmenu);
    glutAddSubMenu("Scheme", smenu);
    glutAddSubMenu("Kernel", kmenu);
    glutAttachMenu(GLUT_RIGHT_BUTTON);

    glutDisplayFunc(display);
    glutReshapeFunc(reshape);
    glutMouseFunc(mouse);
    glutKeyboardFunc(keyboard);
    glutMotionFunc(motion);
    glewInit();
    initGL();

    for (int i = 1; i < argc; ++i) {
        if (!strcmp(argv[i], "-d"))
            g_level = atoi(argv[++i]);
        else if (!strcmp(argv[i], "-c"))
            g_repeatCount = atoi(argv[++i]);
        else if (g_ptexColorFile == NULL)
            g_ptexColorFile = argv[i];
        else if (g_ptexDisplacementFile == NULL)
            g_ptexDisplacementFile = argv[i];
        else if (g_ptexOcclusionFile == NULL)
            g_ptexOcclusionFile = argv[i];

    }

    if (g_ptexColorFile == NULL) {
        printf("Usage: %s <color.ptx> [<displacement.ptx>] [<occlusion.ptx>] \n", argv[0]);
        return 1;
    }

    createOsdMesh(g_level, g_kernel);

    fitFrame();

    glutIdleFunc(idle);
    glutMainLoop();

    quit();
}
void FilmstripTile::render(QPainter& painter, const Widgets::TileInfo& tileInfo, const QVariant& data)
{
    int w = painter.window().width();
    int h = painter.window().height();

    //   painter.drawLine(0,0,w-1,h-1);
    //   painter.drawLine(0,h,w-1,0);

    // TODO: Load fonts in advance??
    painter.setFont(QFont("helvetica", 18));

    if (!data.isNull())
    {
        if ((tileInfo.tileState & Widgets::TileInfo::TileStateSelected) ==
            Widgets::TileInfo::TileStateSelected)
            painter.setBrush(QBrush(QColor(Qt::darkGray).lighter(180),
                Qt::SolidPattern));
        else
            painter.setBrush(QBrush(QColor(Qt::darkGray),
                Qt::SolidPattern));
        // draw the tile
        painter.setPen(QColor(Qt::darkGray));
        painter.drawRect(0, 0, w - 2, h - 2);
        painter.setBrush(Qt::NoBrush);

        // draw the bevel
        painter.setPen(QColor(Qt::gray));
        // draw clock wise
        painter.drawLine(0, h - 1, 0, 0);     //left side
        painter.drawLine(0, 0, w - 1, 0);     // top side
        painter.setPen(QColor(Qt::black));
        painter.drawLine(w - 1, 0, w - 1, h - 1);    // right side
        painter.drawLine(w - 1, h - 1, 0, h - 1);     // bottom side

        Photo info = data.value<Photo>();

        // draw the id text
        painter.save();
        painter.setPen(QColor(Qt::darkGray).lighter(110));
        painter.setFont(QFont(QString("Verdana"), 24, QFont::Bold));
        int fontHeight = painter.fontMetrics().height();
        painter.drawText(5, fontHeight - 5, QString::number(info.id()));

        painter.restore();

        // draw the image.
        QImage image = info.libraryPreviewsRGB();
        QRect  photoFinalDimension;

        if (!image.isNull())
        {
            float ratio = 0.90f;
            int   wf    = (int)(w * ratio);     // width frame
            int   hf    = (int)(h * ratio);     // height frame

            photoFinalDimension = fitFrame(image.size(), QSize(wf, hf));

            // move the frame to the center
            photoFinalDimension.translate((w - wf) / 2, (h - hf) / 2);
            painter.drawImage(photoFinalDimension, image);

            // draw border around image
            painter.setPen(QColor(Qt::black));
            painter.drawRect(photoFinalDimension);
        }
        else
        {
            // TODO: draw missing image indicator
            painter.setPen(QColor(Qt::red));
            painter.drawLine(w / 2 - 15, h / 2 - 15, w / 2 + 15,
                h / 2 + 15);
            painter.drawLine(w / 2 - 15, h / 2 + 15, w / 2 + 15,
                h / 2 - 15);
        }
    }
    else
    {
        // TODO: draw missing picture instead of blue cross
        painter.setPen(QColor(Qt::blue));
        painter.drawLine(0, 0, w - 1, h - 1);
        painter.drawLine(0, h - 1, w - 1, 0);
    }
}
Beispiel #9
0
int fitReflec(char *command)
{
   int failed = FALSE;
   int ndata;
   register int j;
   double sumsq, old_sumsq;
   void icp_fitupdate(void);

   /* Read in data */
   loadData(infile, xspin);
   ndata = npntsa + npntsb + npntsc + npntsd;
   /* Although mrqmin called with xdata, fgenm4 uses q4x for its source */
   /* of q's when calling genderiv4 */
   if (extend(q4x, n4x, lambda, lamdel, thedel) != NULL) {

      /* Fit data */
      if (ndata <= mfit) {
         puts("/** More parameters than data points **/");
         failed = TRUE;
      } else {
         /* genderiv temp data allocated by extend */
         /* Allocate data for mrqmin */
         cleanFree((void **) (&ymod));
         cleanFree((void **) (&dyda));
         ymod = MALLOC(sizeof(double) * ndata);
         dyda = MALLOC(sizeof(double) * ndata * mfit);
         if (ymod == NULL || dyda == NULL) {
            cleanFree((void **) (&ymod));
            cleanFree((void **) (&dyda));
            puts("/** Cannot allocate temporary data for fit **/");
            failed = TRUE;
         } else {
            FILE *unit99 = NULL, *gnuPipe = NULL;
            void (*oldhandler)();
            dynarray Covar, Alpha;
	    int sendgui  = 0;

            Covar.a = (double *) covar;
            Covar.row = NA;
            Covar.col = NA;
   
            Alpha.a = (double *) alpha;
            Alpha.row = NA;
            Alpha.col = NA;

            /* Setup signal handlers to interrupt fitting */
            oldhandler = signal(SIGINT, stopFit);
            abortFit = FALSE;

            /* Transfer generating parameters to fit parameters */
            genshift(a, TRUE);

            /* Check for movie request */
            if (command[2] == 'M') {
               gnuPipe = popen("gnuplot", "w");
               if (gnuPipe == NULL)
                  puts("/** Cannot initialize movie **/");
            } else {
	      sendgui = (command[2] == 'G' || command[3] == 'G');
	    }

            /* Initialize fit routine */
            alamda = -1.;
            sumsq = mrqmin(xdat, ydat, srvar, ndata, a, NA, listA, mfit,
                   Covar, Alpha, beta, NA, 0., fgenm4, &alamda, NULL);
	    if (sendgui) { ipc_fitupdate(); }
            else printf("\n Chi-squared: %#15.7G\n", sumsq / (double) (ndata - mfit));
            if (gnuPipe)
               preFitFrame(command, gnuPipe, xspin, sumsq / (double) (ndata - mfit));

            /* Apply MRQMIN until CHISQ changes by less than 5.e-4 */
            /* on successive iterations */
            old_sumsq = 2*sumsq; /* force the first step */
            while (!abortFit && fabs(sumsq - old_sumsq) > 5.e-4*sumsq) {
               old_sumsq = sumsq;
               sumsq = mrqmin(xdat, ydat, srvar, ndata, a, NA, listA, mfit,
                      Covar, Alpha, beta, NA, old_sumsq, fgenm4, &alamda, unit99);
	       if (sumsq<old_sumsq) { /* Improvement */
		 chisq = sumsq; /* update assumes global variable */
	         if (sendgui) ipc_fitupdate();
                 else printf("\n Chi-squared: %#15.7G\n", sumsq / (double) (ndata - mfit));
	       }
               if (gnuPipe)
                  fitFrame(gnuPipe, xspin, sumsq / (double) (ndata - mfit));
            }
            if (abortFit && !sendgui) puts("\nAborting the fit.");

            /* Finished--calculate covariance matrix */
            alamda = 0.;
            mrqmin(xdat, ydat, srvar, ndata, a, NA, listA, mfit,
                   Covar, Alpha, beta, NA, old_sumsq, fgenm4, &alamda, unit99);

            /* Restore signal handlers */
            signal(SIGINT, oldhandler);

            /* Close output file */
            if (unit99) {
               fputs("# End fit\n", unit99); 
	       fclose(unit99);
	    }

            /* Transfer fit parameters back to generating variables */
            /* constrain(a); */
            (*Constrain)(FALSE, a, nlayer);
            genshift(a, FALSE);
            for (j = 0; j < mfit; j++) DA[listA[j]] = sqrt(fabs(covar[j][j]));
	    if (!sendgui) {
	      for (j = 0; j < mfit; j++) {
		char varName[10];
		
		genva(listA + j, 1, varName);
		printf("%5s: %#15.7G +/- %#15.7G\n", varName, a[listA[j]],
		       DA[listA[j]]);
	      }
	    }

            /* Terminate movie */
            if (gnuPipe) {
               queryString("Press enter to terminate movie", NULL, 0);
               fputs("quit\n", gnuPipe);
               pclose(gnuPipe);
            }
         }
      }
   }
   return failed;
}