BLOBBY.CPP

Go to the documentation of this file.
00001 /* --
00002 OpenFX version 2.0 - Modelling, Animation and Rendering Package
00003 Copyright (C) 2000 - 2007 OpenFX Development Team
00004 -- */
00005 
00006 /*  BLOBBY.CPP  */
00007 
00008 #include <iostream>
00009 //#include <iomanip>
00010 //#include <cmath>
00011 
00012 using namespace std;
00013 
00014 #include "vtk.hh"
00015 #include <stdlib.h>
00016 #include <stdio.h>
00017 #include <math.h>
00018 #include <windows.h>
00019 
00020 #define UNIT         32768L
00021 #define DESELECTED       0
00022 #define SELECTED         1
00023 #define INEDITOR         6
00024 
00025 #ifdef __cplusplus
00026 extern "C" {
00027 #endif
00028 
00029 #include "struct.h"
00030 #include "dstruct.h"
00031 
00032 #ifdef __cplusplus
00033 }
00034 #endif
00035 
00036 #include "blobby.h"
00037 
00038 #include "sfx2vtk.h"
00039 #include "sfx2vtk.cpp"
00040 
00041 static HWND      hParent;
00042 static HINSTANCE hThisInstance;
00043 
00044 static BOOL CALLBACK SfxDlgProc(HWND hwnd, UINT msg,
00045                                 WPARAM wparam, LPARAM lparam);
00046 
00047 #if __WATCOMC__
00048 int APIENTRY LibMain(HANDLE hDLL, DWORD dwReason, LPVOID lpReserved){
00049 #else
00050 BOOL WINAPI DllMain(HANDLE hDLL, DWORD dwReason, LPVOID lpReserved){
00051 #endif
00052   switch (dwReason) {
00053     case DLL_PROCESS_ATTACH: {
00054       hThisInstance=(HINSTANCE)hDLL;
00055       if(hDLL == NULL)MessageBeep(MB_OK);
00056       break;
00057     }
00058     case DLL_PROCESS_DETACH:
00059       break;
00060   }
00061   return TRUE;
00062 }
00063 
00064 
00065 extern "C" BOOL _Xmodeler
00066  (HWND parent_window,HWND info_window,X__STRUCTURE *lpevi){
00067  HCURSOR hSave;
00068  static struct bp {
00069   float f1,f2;
00070   int   type;
00071   int   i,j,k;
00072  } d;
00073  lpEVI=lpevi;
00074  hParent=parent_window;
00075  d.type=1;
00076  d.f1=1.0;
00077  d.f2=0.1;
00078  d.i=25;
00079  d.j=25;
00080  d.k=25;
00081  if(DialogBoxParam(hThisInstance,MAKEINTRESOURCE(DLG_VTK),hParent,
00082              (DLGPROC)SfxDlgProc,(LPARAM)&d) == FALSE)return FALSE;
00083  hSave=SetCursor(LoadCursor(NULL,IDC_WAIT));
00084  {
00085   SfxBound  sfxbound;
00086   SfxReader sfxinput;
00087   SfxWriter sfxoutput;
00088   SfxPointReader sfxpointinput;
00089   SfxEdgeReader sfxedgeinput;
00090   if(NvertSelect < 2){
00091     MessageBox(hParent,"At least two vertices must be selected",NULL,MB_OK);
00092     return FALSE;
00093   }
00094   double scale=sfxbound.GetMaximumSize();
00095   d.f1 *= RulerScale/(float)UNIT;
00096   d.f2 *= RulerScale/(float)UNIT;
00097   //{ char mmm[256]; sprintf(mmm,"Scale %lf   (%lf %lf)",scale,d.f1,d.f2); MessageBox(NULL,mmm,NULL,MB_OK);}
00098   sfxpointinput.SetScale(1.0);
00099   sfxedgeinput.SetScale(1.0);
00100   sfxinput.SetScale(1.0);
00101 
00102   vtkImplicitModeller *imp = new vtkImplicitModeller;
00103   if(d.type == 0)imp->SetInput(sfxpointinput.GetOutput());
00104   if(d.type == 1)imp->SetInput(sfxedgeinput.GetOutput());
00105   if(d.type == 2)imp->SetInput(sfxinput.GetOutput());
00106   imp->SetSampleDimensions(d.i,d.j,d.k);
00107   imp->SetMaximumDistance(d.f1*2.0);
00108 
00109   vtkContourFilter *cf = new vtkContourFilter;
00110   cf->SetInput(imp->GetOutput());
00111   cf->SetValue(0,d.f2);
00112 
00113   vtkCleanPolyData *cp = new vtkCleanPolyData;
00114   cp->SetTolerance(0.0001);
00115   cp->SetInput(cf->GetOutput());
00116 
00117   vtkTriangleFilter *tf = new vtkTriangleFilter;
00118   tf->SetInput(cp->GetOutput());
00119 
00120   sfxoutput.SetScale(1.0);
00121   sfxoutput.SetInput(tf->GetOutput());
00122   sfxoutput.Write();
00123 
00124   delete tf;
00125   delete cp;
00126   delete cf;
00127   delete imp;
00128 
00129  }
00130  SetCursor(hSave);
00131  return TRUE;
00132 }
00133 
00134 static BOOL CALLBACK SfxDlgProc(HWND hwnd, UINT msg,
00135                           WPARAM wparam, LPARAM lparam){
00136  BOOL err;
00137  double f;
00138  int i;
00139  static struct bp {
00140   float f1,f2;
00141   int   type;
00142   int   i,j,k;
00143  } *dp;
00144  char str[32];
00145  switch( msg ) {
00146    case WM_INITDIALOG:
00147      dp=(struct bp *)lparam;
00148      SetDlgItemInt(hwnd,DLG_VTK_XRES,dp->i,FALSE);
00149      SetDlgItemInt(hwnd,DLG_VTK_YRES,dp->j,FALSE);
00150      SetDlgItemInt(hwnd,DLG_VTK_ZRES,dp->k,FALSE);
00151      sprintf(str,"%.2lf",dp->f1);
00152      SetDlgItemText(hwnd,DLG_VTK_MAX_SAMPLING_DISTANCE,(LPCTSTR)str);
00153      sprintf(str,"%.2lf",dp->f2);
00154      SetDlgItemText(hwnd,DLG_VTK_CONTOUR_DISTANCE,(LPCTSTR)str);
00155      if(dp->type == 0)
00156        SendDlgItemMessage(hwnd,DLG_VTK_TYPE0,BM_SETCHECK,TRUE,0);
00157      if(dp->type == 1)
00158        SendDlgItemMessage(hwnd,DLG_VTK_TYPE1,BM_SETCHECK,TRUE,0);
00159      if(dp->type == 2)
00160        SendDlgItemMessage(hwnd,DLG_VTK_TYPE2,BM_SETCHECK,TRUE,0);
00161      CentreDlgOnS(hwnd);
00162      return (TRUE);
00163    case WM_COMMAND:
00164       switch(LOWORD(wparam)){
00165         case IDCANCEL:
00166           EndDialog(hwnd,FALSE);
00167           return(TRUE);
00168         case IDOK:
00169           i=GetDlgItemInt(hwnd,DLG_VTK_XRES,&err,FALSE);
00170           if(err)dp->i=i;
00171           i=GetDlgItemInt(hwnd,DLG_VTK_YRES,&err,FALSE);
00172           if(err)dp->j=i;
00173           i=GetDlgItemInt(hwnd,DLG_VTK_ZRES,&err,FALSE);
00174           if(err)dp->k=i;
00175           if(GetDlgItemText(hwnd,DLG_VTK_MAX_SAMPLING_DISTANCE,str,10) == 0){
00176             EndDialog(hwnd,FALSE); return TRUE;
00177           }
00178           dp->f1=atof(str);
00179           if(GetDlgItemText(hwnd,DLG_VTK_CONTOUR_DISTANCE,str,10) == 0){
00180             EndDialog(hwnd,FALSE); return TRUE;
00181           }
00182           dp->f2=atof(str);
00183           if(SendDlgItemMessage(hwnd,DLG_VTK_TYPE0,BM_GETCHECK,0,0))
00184              dp->type=0;
00185           else if(SendDlgItemMessage(hwnd,DLG_VTK_TYPE1,BM_GETCHECK,0,0))
00186              dp->type=1;
00187           else if(SendDlgItemMessage(hwnd,DLG_VTK_TYPE2,BM_GETCHECK,0,0))
00188              dp->type=2;
00189           EndDialog(hwnd,TRUE);
00190           return(TRUE);
00191         default:
00192           break;
00193       }
00194       break;
00195     default: break;
00196  }
00197  return(FALSE);
00198 }
00199 

Generated on Sun Apr 27 14:20:10 2014 for OpenFX by  doxygen 1.5.6