plvInit.cc
上传用户:kellyonhid
上传日期:2013-10-12
资源大小:932k
文件大小:13k
源码类别:

3D图形编程

开发平台:

Visual C++

  1. #include <tk.h>
  2. #include <stdlib.h>
  3. #include <limits.h>
  4. #include "togl.h"
  5. #include "plvInit.h"
  6. #include "plvGlobals.h"
  7. #include "plvCmds.h"
  8. #include "plvPlyCmds.h"
  9. #include "plvViewerCmds.h"
  10. #include "plvDrawCmds.h"
  11. #include "plvCybCmds.h"
  12. #include "plvImageCmds.h"
  13. #include "plvClipBoxCmds.h"
  14. #include "plvMeshCmds.h"
  15. #include "plvScene.h"
  16. #include "plvDraw.h"
  17. #include "sczRegCmds.h"
  18. #include "plvAnalyze.h"
  19. #include "plvMMCmds.h"
  20. #include "CyberCmds.h"
  21. #include "Trackball.h"
  22. #include "BailDetector.h"
  23. #include "Progress.h"
  24. int PlvDeinitCmd(ClientData clientData, Tcl_Interp *interp, 
  25.  int argc, char *argv[]);
  26. int PlvGetRendererStringCmd(ClientData clientData, Tcl_Interp *interp, 
  27.     int argc, char *argv[]);
  28. int PlvGetWordSizeCmd(ClientData clientData, Tcl_Interp *interp, 
  29.       int argc, char *argv[]);
  30. float getGLVersion (void);
  31. #define PlvCreateCommand(name,func) 
  32.     Tcl_CreateCommand (interp, (name), (func), (ClientData)main, 
  33.        (Tcl_CmdDeleteProc *)NULL)
  34. int
  35. Plv_Init(Tcl_Interp *interp)
  36. {
  37.   Tk_Window main;
  38.   main = Tk_MainWindow(interp);
  39.   g_tclInterp = interp;
  40.   PlvCreateCommand("plv_saveCurrentGroup", PlvSaveCurrentGroup); 
  41.   PlvCreateCommand("plv_smoothMesh",PlvSmoothMesh );
  42.   PlvCreateCommand("plv_lastRenderTime",PlvLastRenderTime );
  43.   PlvCreateCommand("plv_sweepCoordToWorldCoord", PlvSweepCoordToWorldCoord);
  44.   PlvCreateCommand("plv_worldCoordToSweepCoord", PlvWorldCoordToSweepCoord);
  45.   PlvCreateCommand("plv_getVisiblyRenderedScans", PlvGetVisiblyRenderedScans);
  46.   PlvCreateCommand("plv_getrendererstring", PlvGetRendererStringCmd);
  47.   PlvCreateCommand("plv_getwordsize", PlvGetWordSizeCmd);
  48.   PlvCreateCommand("plv_draw", PlvDrawCmd);
  49.   PlvCreateCommand("plv_clearwin", PlvClearWinCmd);
  50.   PlvCreateCommand("plv_writeiris", PlvWriteIrisCmd);
  51.   PlvCreateCommand("plv_fillphoto", PlvFillPhotoCmd);
  52.   PlvCreateCommand("plv_invalidateToglCache", PlvInvalidateToglCacheCmd);
  53.   PlvCreateCommand("plv_countPixels", PlvCountPixelsCmd);
  54.   PlvCreateCommand("plv_light", PlvLightCmd);
  55.   PlvCreateCommand("plv_drawstyle", PlvDrawStyleCmd);
  56.   PlvCreateCommand("plv_material", PlvMaterialCmd);
  57.   PlvCreateCommand("plv_load_projective_texture", PlvLoadProjectiveTexture);
  58.   PlvCreateCommand("plv_resolution", PlvMeshResolutionCmd);
  59.   PlvCreateCommand("plv_setoverallres", PlvSetOverallResCmd);
  60.   PlvCreateCommand("plv_scan_colorcode", PlvScanColorCodeCmd);
  61.   PlvCreateCommand("plv_getvisible", PlvGetVisibleCmd);
  62.   PlvCreateCommand("plv_setvisible", PlvSetVisibleCmd);
  63.   PlvCreateCommand("plv_sort_scan_list", PlvSortScanListCmd);
  64.   PlvCreateCommand("plv_listscans", PlvListScansCmd);
  65.   PlvCreateCommand("plv_meshinfo", PlvMeshInfoCmd);
  66.   PlvCreateCommand("plv_meshsetdelete", PlvMeshSetDeleteCmd);
  67.   PlvCreateCommand("plv_camerainfo", PlvCameraInfoCmd);
  68.   PlvCreateCommand("plv_positioncamera", PlvPositionCameraCmd);
  69.   PlvCreateCommand("plv_zoom_to_rect", PlvZoomToRectCmd);
  70.   PlvCreateCommand("plv_print_voxels", PlvPrintVoxelsCmd);
  71.   /* added command to print voxel info for ply file 
  72.      - for display voxel feature */
  73.   PlvCreateCommand("plv_param", PlvParamCmd);
  74.   PlvCreateCommand("baildetect", PlvBailDetectCmd);
  75.   PlvCreateCommand("plv_progress", PlvProgressCmd);
  76.   PlvCreateCommand("plv_readcyb", PlvReadCybCmd);
  77.   PlvCreateCommand("plv_bumpcyb", PlvBumpCybCmd);
  78.   PlvCreateCommand("plv_shadecyb", PlvShadeCybCmd);
  79.   PlvCreateCommand("plv_israngegrid", PlvIsRangeGridCmd);
  80.   PlvCreateCommand("scz_session", SczSessionCmd);
  81.   PlvCreateCommand("scz_pseudogroup", SczPseudoGroupCmd);
  82.   PlvCreateCommand("plv_readfile", PlvReadFileCmd);
  83.   PlvCreateCommand("plv_readgroupmembers", PlvReadGroupMembersCmd); 
  84.   PlvCreateCommand("plv_synthesize", PlvSynthesizeObjectCmd);
  85.   PlvCreateCommand("plv_write_scan", PlvWriteScanCmd);
  86.   PlvCreateCommand("plv_write_metadata", PlvWriteMetaDataCmd);
  87.   PlvCreateCommand("plv_write_resolutionmesh", PlvWriteResolutionMeshCmd);
  88.   PlvCreateCommand("plv_get_scan_filename", PlvGetScanFilenameCmd);
  89.   PlvCreateCommand("plv_getNextAvailGroupName", PlvGetNextGroupNameCmd);
  90.   PlvCreateCommand("plv_is_scan_modified", PlvIsScanModifiedCmd);
  91.   PlvCreateCommand("plv_groupscans", PlvGroupScansCmd);
  92.     
  93.   PlvCreateCommand("plv_constrain_rotation", PlvConstrainRotationCmd);
  94.   PlvCreateCommand("plv_force_keep_onscreen", PlvForceKeepOnscreenCmd);
  95.   PlvCreateCommand("plv_ortho", PlvOrthographicCmd);
  96.   PlvCreateCommand("plv_persp", PlvPerspectiveCmd);
  97.   PlvCreateCommand("plv_zoomangle", PlvZoomAngleCmd);
  98.   PlvCreateCommand("plv_oblique_camera", PlvObliqueCameraCmd);
  99.   PlvCreateCommand("plv_viewall", PlvViewAllCmd);
  100.   PlvCreateCommand("plv_resetxform", PlvResetXformCmd);
  101.   PlvCreateCommand("plv_selectscan", PlvSelectScanCmd);
  102.   PlvCreateCommand("plv_rotlight", PlvRotateLightCmd);
  103.   PlvCreateCommand("plv_rotxyviewmouse", PlvRotateXYViewMouseCmd);
  104.   PlvCreateCommand("plv_transxyviewmouse", PlvTransXYViewMouseCmd);
  105.   PlvCreateCommand("plv_translateinplane", PlvTranslateInPlaneCmd);
  106.   PlvCreateCommand("plv_undo_xform", PlvUndoXformCmd);
  107.   PlvCreateCommand("plv_redo_xform", PlvRedoXformCmd);
  108.   PlvCreateCommand("plv_screentoworld", PlvGetScreenToWorldCoords);
  109.   PlvCreateCommand("plv_pickscan", PlvPickScanFromPointCmd);
  110.   PlvCreateCommand("plv_set_this_as_center_of_rotation",
  111.        PlvSetThisAsCenterOfRotation);
  112.   PlvCreateCommand("plv_reset_rotation_center",
  113.        PlvResetCenterOfRotation);
  114.   PlvCreateCommand("SetHome", PlvSetHomeCmd);
  115.   PlvCreateCommand("GoHome", PlvGoHomeCmd);
  116.   PlvCreateCommand("plv_transmesh", PlvTransMeshCmd);
  117.   PlvCreateCommand("plv_blendmesh", PlvBlendMeshCmd);
  118.   PlvCreateCommand("plv_camera_xform_to_mesh", PlvFlattenCameraXformCmd);
  119.   PlvCreateCommand("plv_setslowpolycount", PlvSetSlowPolyCountCmd);
  120.   PlvCreateCommand("plv_setManipRenderMode", PlvSetManipRenderModeCmd);
  121.   PlvCreateCommand("plv_manrotate", PlvManualRotateCmd);
  122.   PlvCreateCommand("plv_mantranslate", PlvManualTranslateCmd);
  123.   PlvCreateCommand("plv_clearselection", PlvClearSelectionCmd);
  124.   PlvCreateCommand("plv_drawboxselection", PlvDrawBoxSelectionCmd);
  125.   PlvCreateCommand("plv_drawlineselection", PlvDrawLineSelectionCmd);
  126.   PlvCreateCommand("plv_drawshapeselection", PlvDrawShapeSelectionCmd);
  127.   PlvCreateCommand("plv_getselectioncursor", PlvGetSelectionCursorCmd);
  128.   PlvCreateCommand("plv_getselectioninfo", PlvGetSelectionInfoCmd);
  129.   PlvCreateCommand("plv_clip_to_selection", PlvClipToSelectionCmd);
  130.   PlvCreateCommand("plv_get_selected_meshes", PlvGetSelectedMeshesCmd);
  131.   PlvCreateCommand("plv_clipBoxPlaneFit", PlvAlignToMeshBoxCmd);
  132.   PlvCreateCommand("plv_analyze_line_depth", PlvAnalyzeClipLineDepth);
  133.   PlvCreateCommand("plv_analyzeLineMode", PlvAnalyzeLineModeCmd);
  134.   PlvCreateCommand("plv_export_graph_as_text", PlvExportGraphAsText);
  135.   PlvCreateCommand("wsh_warp_mesh", wsh_WarpMesh);
  136.   PlvCreateCommand("wsh_align_points_to_plane", wsh_AlignPointsToPlane);
  137.   PlvCreateCommand("plv_draw_analyze_lines", PlvDrawAnalyzeLines);
  138.   PlvCreateCommand("plv_clear_analyze_lines", PlvClearAnalyzeLines);
  139.   PlvCreateCommand("plv_decimate", PlvMeshDecimateCmd);
  140.   PlvCreateCommand("plv_getreslist", PlvMeshResListCmd);
  141.   PlvCreateCommand("plv_getcurrentres", PlvCurrentResCmd);
  142.   PlvCreateCommand("plv_setmeshpreload", PlvSetMeshResPreloadCmd);
  143.   PlvCreateCommand("plv_mesh_res_delete", PlvMeshDeleteResCmd);
  144.   PlvCreateCommand("plv_mesh_res_unload", PlvMeshUnloadResCmd);
  145.   PlvCreateCommand("remove_step", PlvMeshRemoveStepCmd);  
  146.   PlvCreateCommand("FlipMeshNormals", PlvFlipMeshNormalsCmd);
  147.   PlvCreateCommand("plv_hilitescan", PlvHiliteScanCmd);
  148.   PlvCreateCommand("plv_render_thickness", PlvRenderThicknessCmd);
  149.   PlvCreateCommand("plv_shutdown", PlvDeinitCmd);
  150.       
  151.   PlvCreateCommand("plv_icpregister", PlvRegIcpCmd);
  152.   PlvCreateCommand("plv_icpreg_markquality", PlvRegIcpMarkQualityCmd);
  153.   PlvCreateCommand("plv_showicplines", PlvShowIcpLinesCmd);
  154.   PlvCreateCommand("bindToglToAlignmentView", PlvBindToglToAlignmentViewCmd);
  155.   PlvCreateCommand("bindToglToAlignmentOverview",
  156.    PlvBindToglToAlignmentOverviewCmd);
  157.   PlvCreateCommand("plv_correspRegParms", PlvCorrespRegParmsCmd);
  158.   PlvCreateCommand("RegUIMouse", PlvRegUIMouseCmd);
  159.   PlvCreateCommand("AddPartialRegCorrespondence",
  160.    PlvAddPartialRegCorrespondenceCmd);
  161.   PlvCreateCommand("DeleteRegCorrespondence", PlvDeleteRegCorrespondenceCmd);
  162.   PlvCreateCommand("ConfirmRegCorrespondence",
  163.    PlvConfirmRegCorrespondenceCmd);
  164.   PlvCreateCommand("GetCorrespondenceInfo", PlvGetCorrespondenceInfoCmd);
  165.   PlvCreateCommand("plv_registerCorresp", PlvCorrespondenceRegistrationCmd);
  166.   PlvCreateCommand("DragRegister", PlvDragRegisterCmd);
  167.   PlvCreateCommand("plv_globalreg", PlvGlobalRegistrationCmd);
  168.   PlvCreateCommand("scz_auto_register", SczAutoRegisterCmd);
  169.   PlvCreateCommand("scz_xform_scan", SczXformScanCmd);
  170.   PlvCreateCommand("scz_get_scan_xform", SczGetScanXformCmd);
  171.   PlvCreateCommand("mms_vriporient", MmsVripOrientCmd);
  172.   PlvCreateCommand("mms_absorbxform", MmsAbsorbXformCmd);
  173.   PlvCreateCommand("mms_getscanfalsecolor", MmsGetScanFalseColorCmd);
  174.   PlvCreateCommand("mms_numscans", MmsNumScansCmd);
  175.   PlvCreateCommand("mms_isscanvisible", MmsIsScanVisibleCmd);
  176.   PlvCreateCommand("mms_setscanvisible", MmsSetScanVisibleCmd);
  177.   PlvCreateCommand("mms_deletescan", MmsDeleteScanCmd);
  178.   PlvCreateCommand("mms_flipscannorms", MmsFlipScanNormsCmd);
  179.   PlvCreateCommand("mms_resetcache", MmsResetCacheCmd);
  180.   PlvCreateCommand("plv_write_mm_for_vrip", PlvWriteMMForVripCmd);
  181.   PlvCreateCommand("plv_spacecarve", PlvSpaceCarveCmd);
  182.   PlvCreateCommand("plv_write_sd_for_vrip", PlvWriteSDForVripCmd);
  183.   PlvCreateCommand("plv_dice_cyber_data", PlvDiceCyberDataCmd);
  184.   PlvCreateCommand("plv_cyberscan_selfalign", PlvCyberScanSelfAlignCmd);
  185.   PlvCreateCommand("scn_dumplaserpnts", ScnDumpLaserPntsCmd);
  186.   PlvCreateCommand("plv_working_volume", PlvWorkingVolumeCmd);
  187.   PlvCreateCommand("plv_saveworlddata", WriteWorldDataFromScreen);
  188.   PlvCreateCommand("plv_savedepth", WriteOrthoDepth);
  189.   PlvCreateCommand("plv_write_ply_for_vrip", PlvWritePlyForVripCmd);
  190.   PlvCreateCommand("updatewindow", PlvUpdateWindowCmd);
  191.   PlvCreateCommand("get_tick_count", SczGetSystemTickCountCmd);
  192.   
  193.   PlvCreateCommand("plv_extProg", PlvRunExternalProgram);
  194.   tbView  = new Trackball;
  195.   theScene = new Scene (interp);
  196.   if (!g_bNoUI) {
  197.     // initialize interactors
  198.     Togl_DisplayFunc (drawInTogl);
  199.     Togl_CreateFunc (catchToglCreate);
  200.     Togl_OverlayDisplayFunc (drawOverlay);
  201.     initDrawing();
  202.   }
  203.   char *plvDir = getenv("SCANALYZE_DIR");
  204.   if (plvDir == NULL) {
  205.     interp->result = "Need to set SCANALYZE_DIR environment variable.";
  206.     return TCL_ERROR;
  207.   }
  208.   char plvPath[PATH_MAX];
  209.   strcpy(plvPath, plvDir);
  210.   strcat(plvPath, "/scanalyze.tcl");
  211.   Tcl_SetVar (interp, "noui", g_bNoUI ? "1" : "0", TCL_GLOBAL_ONLY);
  212.   int code = Tcl_EvalFile(interp, plvPath);
  213.   if (code != TCL_OK) {
  214.     interp->result = Tcl_GetVar (interp, "errorInfo", TCL_GLOBAL_ONLY);
  215.     return TCL_ERROR;
  216.   }
  217.   // and, once togl widget exists (after scanalyze.tcl is sourced):
  218.   // since these things need a GL context
  219.   if (!g_bNoUI) {
  220.     initDrawingPostCreation();
  221.     g_glVersion = getGLVersion();
  222.     Tk_CreateTimerHandler (30, SpinTrackballs, (ClientData)main);
  223.   }
  224.   // finally, source the user customizations -- ~/.scanalyzerc
  225.   char* homeDir = getenv("HOME");
  226.   if (homeDir == NULL) {
  227.     fprintf(stderr, "Environment variable HOME not set - "
  228.     "will not execute $HOME/.scanalyzercn");
  229.   } else {
  230.     char rcPath[PATH_MAX];
  231.     strcpy(rcPath, homeDir);
  232.     strcat(rcPath, "/.scanalyzerc");
  233.     Tcl_VarEval(interp, "file exists ", rcPath, (char *)NULL);
  234.     if (atoi(interp->result)) {
  235.       code = Tcl_EvalFile(interp, rcPath);
  236.       if (code != TCL_OK) {
  237. char* errMsg = Tcl_GetVar (interp, "errorInfo", TCL_GLOBAL_ONLY);
  238. fprintf (stderr, "nWarning: errors detected in ~/.scanalyzercnn"
  239.  "%snn"
  240.  "Scanalyze should be ok but your customizations probably "
  241.  " won't be.nn", errMsg);
  242.       }
  243.     }
  244.   }
  245.   return TCL_OK;
  246. }
  247. int
  248. PlvDeinitCmd(ClientData clientData, Tcl_Interp *interp, 
  249.      int argc, char *argv[])
  250. {
  251. #if 0
  252.   delete theScene;
  253.   theScene = NULL;
  254.   //if this returns, Tk keeps processing events, and may call event
  255.   //handlers -- in particular, it will try to redraw, which will crash
  256.   //because there's no scene -- could also have drawMeshes() check for this.
  257.   exit (0);
  258. #else
  259.   theScene->freeMeshes();
  260. #endif
  261.   return TCL_OK;
  262. }
  263. float
  264. getGLVersion (void)
  265. {
  266.   const GLubyte* verStr = glGetString (GL_VERSION);
  267.   const GLubyte* verRenderer = glGetString (GL_RENDERER);
  268.   float ver = atof ((const char*)verStr);
  269.   printf ("OpenGL version is %g is rendered by %sn", ver, verRenderer);
  270.   return ver;
  271. }
  272. int PlvGetRendererStringCmd(ClientData clientData, Tcl_Interp *interp, 
  273.     int argc, char *argv[])
  274. {
  275.   const GLubyte* renderer = glGetString (GL_RENDERER);
  276.   Tcl_SetResult (interp, (char*)renderer, TCL_VOLATILE);
  277.   return TCL_OK;
  278. }
  279. int PlvGetWordSizeCmd(ClientData clientData, Tcl_Interp *interp, 
  280.       int argc, char *argv[])
  281. {
  282.   char buf[8];
  283.   sprintf (buf, "%ld", sizeof (long));
  284.   Tcl_SetResult (interp, buf, TCL_VOLATILE);
  285.   return TCL_OK;
  286. }