ISOSURF.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 /*  ISOSURF.CPP  */
00007 
00008 #include "vtk.hh"
00009 #include <stdlib.h>
00010 #include <stdio.h>
00011 #include <math.h>
00012 #include <windows.h>
00013 
00014 #define UNIT         32768L
00015 #define DESELECTED       0
00016 #define SELECTED         1
00017 #define INEDITOR         6
00018 
00019 #ifdef __cplusplus
00020 extern "C" {
00021 #endif
00022 
00023 #include "struct.h"
00024 #include "dstruct.h"
00025 
00026 #ifdef __cplusplus
00027 }
00028 #endif
00029 
00030 #include "isosurf.h"
00031 
00032 #include "sfx2vtk.h"
00033 #include "sfx2vtk.cpp"
00034 
00035 static HWND      hParent;
00036 static HINSTANCE hThisInstance;
00037 static BOOL  inc_c1=TRUE, inc_c2=FALSE, inc_c3=FALSE, inc_c4=FALSE;
00038 static float c1_val=0.0, c2_val=0.0, c3_val=0.0, c4_val=0.0;
00039 
00040 static BOOL LocalSelectFileName(char *szfile, char *szfilter,
00041                            HWND parent, HINSTANCE hInst);
00042 
00043 #if __WATCOMC__
00044 int APIENTRY LibMain(HANDLE hDLL, DWORD dwReason, LPVOID lpReserved){
00045 #else
00046 BOOL WINAPI DllMain(HANDLE hDLL, DWORD dwReason, LPVOID lpReserved){
00047 #endif
00048   switch (dwReason) {
00049     case DLL_PROCESS_ATTACH: {
00050       hThisInstance=(HINSTANCE)hDLL;
00051       if(hDLL == NULL)MessageBeep(MB_OK);
00052       break;
00053     }
00054     case DLL_PROCESS_DETACH:
00055       break;
00056   }
00057   return TRUE;
00058 }
00059 
00060 extern "C" BOOL _Xmodeler
00061  (HWND parent_window,HWND info_window,X__STRUCTURE *lpevi){
00062  HCURSOR hSave;
00063  char localfile[256];
00064  lpEVI=lpevi;
00065  localfile[0]='\0';
00066  hParent=parent_window;
00067  if(!LocalSelectFileName(localfile,
00068                         "VTK Structured Points Datasets (*.VTK)|*.vtk",
00069                          parent_window,hThisInstance))return FALSE;
00070  hSave=SetCursor(LoadCursor(NULL,IDC_WAIT));
00071  {
00072   int i,j,k,Offset,jOffset,kOffset;
00073   float x,y,z,s;
00074   SfxWriter sfxoutput;
00075 
00076 #if 0
00077 #define SAMPLE_SIZE 26
00078   vtkStructuredPoints *vol = new vtkStructuredPoints;
00079   vol->SetDimensions(SAMPLE_SIZE,SAMPLE_SIZE,SAMPLE_SIZE);
00080   vol->SetOrigin(-0.5,-0.5,-0.5);
00081   float ar=1.0/((float)SAMPLE_SIZE-1.0);
00082   vol->SetAspectRatio(ar,ar,ar);
00083   vtkFloatScalars *scalars = new vtkFloatScalars(SAMPLE_SIZE*SAMPLE_SIZE*SAMPLE_SIZE);
00084   for(k=0;k<SAMPLE_SIZE;k++){
00085     z= -0.5 + k*ar;
00086     kOffset = k*SAMPLE_SIZE*SAMPLE_SIZE;
00087     for(j=0;j<SAMPLE_SIZE;j++){
00088       y = -0.5 + j*ar;
00089       jOffset = j*SAMPLE_SIZE;
00090       for(i=0;i<SAMPLE_SIZE;i++){
00091         x = - 0.5 + i*ar;
00092         s = x*x + y*y + z*z - (0.4*0.4);
00093         Offset = i + jOffset + kOffset;
00094         scalars->InsertScalar(Offset,s);
00095       }
00096     }
00097   }
00098   vol->GetPointData()->SetScalars(scalars);
00099   scalars->Delete();
00100   vtkDataSetWriter dw;
00101   dw.SetFilename("F:\\temp1.vtk");
00102   dw.SetInput(vol);
00103   dw.Update();
00104 #endif
00105 
00106   vtkStructuredPointsReader *volR = new vtkStructuredPointsReader;
00107   volR->SetFilename(localfile);
00108 
00109   vtkContourFilter *cf = new vtkContourFilter;
00110   cf->SetInput(volR->GetOutput());
00111 //  cf->SetInput(vol);  for structured points
00112   if(inc_c1)cf->SetValue(0,c1_val);
00113   if(inc_c2)cf->SetValue(0,c2_val);
00114   if(inc_c3)cf->SetValue(0,c3_val);
00115   if(inc_c4)cf->SetValue(0,c4_val);
00116 
00117   vtkCleanPolyData *cp = new vtkCleanPolyData;
00118   cp->SetTolerance(0.0001);
00119   cp->SetInput(cf->GetOutput());
00120 
00121   vtkTriangleFilter *tf = new vtkTriangleFilter;
00122   tf->SetInput(cp->GetOutput());
00123 
00124   sfxoutput.SetInput(tf->GetOutput());
00125   sfxoutput.Write();
00126 
00127   delete tf;
00128   delete cp;
00129   delete cf;
00130   delete volR;
00131  }
00132  SetCursor(hSave);
00133  return TRUE;
00134 }
00135 
00136 static unsigned CALLBACK NameHookProc(HWND hwnd,UINT msg,
00137                               WPARAM wparam,LPARAM lparam){
00138  char str[32];
00139  BOOL err;
00140  LPOFNOTIFY lp;
00141  switch( msg ) {
00142    case WM_INITDIALOG:
00143      if(inc_c1)SendDlgItemMessage(hwnd,DLG_C1,BM_SETCHECK,1,0);
00144      if(inc_c2)SendDlgItemMessage(hwnd,DLG_C2,BM_SETCHECK,1,0);
00145      if(inc_c3)SendDlgItemMessage(hwnd,DLG_C3,BM_SETCHECK,1,0);
00146      if(inc_c4)SendDlgItemMessage(hwnd,DLG_C4,BM_SETCHECK,1,0);
00147      sprintf(str,"%.2lf",c1_val);
00148      SetDlgItemText(hwnd,DLG_C1_V,str);
00149      sprintf(str,"%.2lf",c2_val);
00150      SetDlgItemText(hwnd,DLG_C2_V,str);
00151      sprintf(str,"%.2lf",c3_val);
00152      SetDlgItemText(hwnd,DLG_C3_V,str);
00153      sprintf(str,"%.2lf",c4_val);
00154      SetDlgItemText(hwnd,DLG_C4_V,str);
00155      return FALSE;
00156    case WM_COMMAND:
00157      switch(LOWORD(wparam)){
00158        case IDOK:{
00159            lp=NULL;
00160            goto JUMPHERE;
00161          }
00162          break;
00163        default: break;
00164      }
00165      break;
00166    case WM_NOTIFY:{
00167        lp=(LPOFNOTIFY)lparam;
00168        if(lp->hdr.code == CDN_FILEOK){
00169          JUMPHERE:
00170          if(SendDlgItemMessage(hwnd,DLG_C1,BM_GETCHECK,0,0))
00171            inc_c1=TRUE; else inc_c1=FALSE;
00172          if(SendDlgItemMessage(hwnd,DLG_C2,BM_GETCHECK,0,0))
00173            inc_c2=TRUE; else inc_c2=FALSE;
00174          if(SendDlgItemMessage(hwnd,DLG_C3,BM_GETCHECK,0,0))
00175            inc_c3=TRUE; else inc_c3=FALSE;
00176          if(SendDlgItemMessage(hwnd,DLG_C4,BM_GETCHECK,0,0))
00177            inc_c4=TRUE; else inc_c4=FALSE;
00178          GetDlgItemText(hwnd,DLG_C1_V,str,255);
00179          if(inc_c1)c1_val=atof(str);
00180          GetDlgItemText(hwnd,DLG_C2_V,str,255);
00181          if(inc_c2)c2_val=atof(str);
00182          GetDlgItemText(hwnd,DLG_C3_V,str,255);
00183          if(inc_c3)c3_val=atof(str);
00184          GetDlgItemText(hwnd,DLG_C4_V,str,255);
00185          if(inc_c4)c4_val=atof(str);
00186        }
00187      }
00188      break;
00189    default: break;
00190  }
00191  return FALSE;
00192 }
00193 
00194 static BOOL LocalSelectFileName(char *szfile, char *szfilter,
00195                            HWND parent, HINSTANCE hInst){
00196  int i;
00197  OPENFILENAME ofn;
00198  char szFilter[80],title[256];
00199  DWORD version;
00200  strcpy(szFilter,szfilter);
00201  i=0; while(szFilter[i] != '\0'){
00202    if(szFilter[i] == '|')szFilter[i]='\0'; i++;
00203  }
00204  memset(&ofn,0,sizeof(OPENFILENAME));
00205  ofn.lStructSize=sizeof(OPENFILENAME);
00206  ofn.hwndOwner=parent;
00207  ofn.lpstrFilter=szFilter;
00208  ofn.nFilterIndex=0;
00209  ofn.lpstrFile=szfile;
00210  ofn.nMaxFile=255;
00211  ofn.lpstrFileTitle=NULL;
00212  ofn.nMaxFileTitle=0;
00213  ofn.lpstrInitialDir=NULL;
00214  LoadString(hThisInstance,IDX_VTK_STRING1,title,255);
00215  ofn.lpstrTitle=title;
00216  ofn.hInstance=hInst;
00217  ofn.lpfnHook=NameHookProc;
00218  version=GetVersion();
00219  ofn.Flags=OFN_HIDEREADONLY|OFN_PATHMUSTEXIST|
00220            OFN_ENABLEHOOK|OFN_ENABLETEMPLATE|OFN_NONETWORKBUTTON;
00221  if(LOBYTE(LOWORD(version)) >= 4){
00222    ofn.lpTemplateName=MAKEINTRESOURCE(DLG_VTK);
00223    ofn.Flags |= OFN_EXPLORER;
00224  }
00225  else{
00226    ofn.lpTemplateName=MAKEINTRESOURCE(DLG_VTKOLD);
00227  }
00228  return GetOpenFileName(&ofn);
00229 }

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