RAWDATA.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 This program is free software; you can redistribute it and/or
00006 modify it under the terms of the GNU General Public License
00007 as published by the Free Software Foundation; either version 2
00008 of the License, or (at your option) any later version.
00009 
00010 This program is distributed in the hope that it will be useful,
00011 but WITHOUT ANY WARRANTY; without even the implied warranty of
00012 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00013 GNU General Public License for more details.
00014 
00015 You should have received a copy of the GNU General Public License
00016 along with this program; if not, write to the Free Software
00017 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
00018 
00019 You may contact the OpenFX development team via elecronic mail
00020 at core@openfx.org, or visit our website at http://openfx.org for
00021 further information and support details.
00022 -- */
00023 
00024 /*  RAWDATA.CPP  read/write raw data in VTK text format */
00025 
00026 #include "vtk.hh"
00027 #include "vtkpolywriter.hh"
00028 #include <stdlib.h>
00029 #include <stdio.h>
00030 #include <math.h>
00031 #include <windows.h>
00032 
00033 #define UNIT         32768L
00034 #define DESELECTED       0
00035 #define SELECTED         1
00036 #define INEDITOR         6
00037 
00038 #ifdef __cplusplus
00039 extern "C" {
00040 #endif
00041 
00042 #include "struct.h"
00043 #include "dstruct.h"
00044 
00045 #ifdef __cplusplus
00046 }
00047 #endif
00048 
00049 #include "rawdata.h"
00050 
00051 #include "sfx2vtk.h"
00052 #include "sfx2vtk.cpp"
00053 
00054 static HWND      hParent;
00055 static HINSTANCE hThisInstance;
00056 static BOOL  i_read=TRUE;
00057 
00058 static BOOL LocalSelectFileName(char *szfile, char *szfilter,
00059                            HWND parent, HINSTANCE hInst);
00060 
00061 #if __WATCOMC__
00062 int APIENTRY LibMain(HANDLE hDLL, DWORD dwReason, LPVOID lpReserved){
00063 #else
00064 BOOL WINAPI DllMain(HANDLE hDLL, DWORD dwReason, LPVOID lpReserved){
00065 #endif
00066   switch (dwReason) {
00067     case DLL_PROCESS_ATTACH: {
00068       hThisInstance=(HINSTANCE)hDLL;
00069       if(hDLL == NULL)MessageBeep(MB_OK);
00070       break;
00071     }
00072     case DLL_PROCESS_DETACH:
00073       break;
00074   }
00075   return TRUE;
00076 }
00077 
00078 extern "C" BOOL _Xmodeler
00079  (HWND parent_window,HWND info_window,X__STRUCTURE *lpevi){
00080  HCURSOR hSave;
00081  char localfile[256];
00082  lpEVI=lpevi;
00083  localfile[0]='\0';
00084  hParent=parent_window;
00085  if(!LocalSelectFileName(localfile,
00086                         "VTK Structured Points Datasets (*.VTK)|*.vtk",
00087                          parent_window,hThisInstance))return FALSE;
00088  hSave=SetCursor(LoadCursor(NULL,IDC_WAIT));
00089  {
00090   if(i_read){
00091     SfxWriter sfxoutput;
00092     vtkPolyReader *volR = new vtkPolyReader;
00093     volR->SetFilename(localfile);
00094     vtkCleanPolyData *cp = new vtkCleanPolyData;
00095     cp->SetTolerance(0.0001);
00096     cp->SetInput(volR->GetOutput());
00097     vtkTriangleFilter *tf = new vtkTriangleFilter;
00098     tf->SetInput(cp->GetOutput());
00099     sfxoutput.SetInput(volR->GetOutput());
00100     sfxoutput.Write();
00101     delete cp;
00102     delete tf;
00103     delete volR;
00104   }
00105   else{
00106     SfxReader sfxinput;
00107     vtkPolyWriter *volR = new vtkPolyWriter;
00108     volR->SetFilename(localfile);
00109     volR->SetInput(sfxinput.GetOutput());
00110     volR->Update();
00111     delete volR;
00112   }
00113  }
00114  SetCursor(hSave);
00115  return TRUE;
00116 }
00117 
00118 static unsigned CALLBACK NameHookProc(HWND hwnd,UINT msg,
00119                               WPARAM wparam,LPARAM lparam){
00120  char str[32];
00121  BOOL err;
00122  LPOFNOTIFY lp;
00123  switch( msg ) {
00124    case WM_INITDIALOG:
00125      if(i_read)SendDlgItemMessage(hwnd,DLG_IO,BM_SETCHECK,1,0);
00126      return FALSE;
00127    case WM_COMMAND:
00128      switch(LOWORD(wparam)){
00129        case IDOK:{
00130            lp=NULL;
00131            goto JUMPHERE;
00132          }
00133          break;
00134        default: break;
00135      }
00136      break;
00137    case WM_NOTIFY:{
00138        lp=(LPOFNOTIFY)lparam;
00139        if(lp->hdr.code == CDN_FILEOK){
00140          JUMPHERE:
00141          if(SendDlgItemMessage(hwnd,DLG_IO,BM_GETCHECK,0,0))
00142          i_read=TRUE; else i_read=FALSE;
00143        }
00144      }
00145      break;
00146    default: break;
00147  }
00148  return FALSE;
00149 }
00150 
00151 static BOOL LocalSelectFileName(char *szfile, char *szfilter,
00152                            HWND parent, HINSTANCE hInst){
00153  int i;
00154  OPENFILENAME ofn;
00155  char szFilter[80],title[256];
00156  DWORD version;
00157  strcpy(szFilter,szfilter);
00158  i=0; while(szFilter[i] != '\0'){
00159    if(szFilter[i] == '|')szFilter[i]='\0'; i++;
00160  }
00161  memset(&ofn,0,sizeof(OPENFILENAME));
00162  ofn.lStructSize=sizeof(OPENFILENAME);
00163  ofn.hwndOwner=parent;
00164  ofn.lpstrFilter=szFilter;
00165  ofn.nFilterIndex=0;
00166  ofn.lpstrFile=szfile;
00167  ofn.nMaxFile=255;
00168  ofn.lpstrFileTitle=NULL;
00169  ofn.nMaxFileTitle=0;
00170  ofn.lpstrInitialDir=NULL;
00171  LoadString(hThisInstance,IDX_VTK_STRING1,title,255);
00172  ofn.lpstrTitle=title;
00173  ofn.hInstance=hInst;
00174  ofn.lpfnHook=NameHookProc;
00175  version=GetVersion();
00176  ofn.Flags=OFN_HIDEREADONLY|OFN_PATHMUSTEXIST|
00177            OFN_ENABLEHOOK|OFN_ENABLETEMPLATE|OFN_NONETWORKBUTTON;
00178  if(LOBYTE(LOWORD(version)) >= 4){
00179    ofn.lpTemplateName=MAKEINTRESOURCE(DLG_VTK);
00180    ofn.Flags |= OFN_EXPLORER;
00181  }
00182  else{
00183    ofn.lpTemplateName=MAKEINTRESOURCE(DLG_VTKOLD);
00184  }
00185  return GetOpenFileName(&ofn);
00186 }
00187 
00188 #if 0
00189   vol->GetPointData()->SetScalars(scalars);
00190   scalars->Delete();
00191   vtkDataSetWriter dw;
00192   dw.SetFilename("F:\\temp1.vtk");
00193   dw.SetInput(vol);
00194   dw.Update();
00195 #endif
00196 

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