QUADRIC.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 /*  QUADRIC.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 "quadric.h"
00031 
00032 #include "sfx2vtk.h"
00033 #include "sfx2vtk.cpp"
00034 
00035 static HWND      hParent;
00036 static HINSTANCE hThisInstance;
00037 
00038 static BOOL CALLBACK SfxDlgProc(HWND hwnd, UINT msg,
00039                                 WPARAM wparam, LPARAM lparam);
00040 
00041 #if __WATCOMC__
00042 int APIENTRY LibMain(HANDLE hDLL, DWORD dwReason, LPVOID lpReserved){
00043 #else
00044 BOOL WINAPI DllMain(HANDLE hDLL, DWORD dwReason, LPVOID lpReserved){
00045 #endif
00046   switch (dwReason) {
00047     case DLL_PROCESS_ATTACH: {
00048       hThisInstance=(HINSTANCE)hDLL;
00049       if(hDLL == NULL)MessageBeep(MB_OK);
00050       break;
00051     }
00052     case DLL_PROCESS_DETACH:
00053       break;
00054   }
00055   return TRUE;
00056 }
00057 
00058 
00059 extern "C" BOOL _Xmodeler
00060  (HWND parent_window,HWND info_window,X__STRUCTURE *lpevi){
00061  HCURSOR hSave;
00062  static struct bp {
00063   BOOL cap;
00064   float xmin,xmax,ymin,ymax,zmin,zmax;
00065   int i,j,k;
00066   float cv;
00067   float a0,a1,a2,a3,a4,a5,a6,a7,a8,a9;
00068  } d;
00069  lpEVI=lpevi;
00070  hParent=parent_window;
00071  d.cap = TRUE;
00072  d.xmin = d.ymin = d.zmin = -1.0f;
00073  d.xmax = d.ymax = d.zmax =  1.0f;
00074  d.cv = 0.2;
00075  d.i = d.j = d.k = 20;
00076  d.a0=0.5;
00077  d.a1=1.0;
00078  d.a2=2,0;
00079  d.a3=0.0;
00080  d.a4=0.1;
00081  d.a5=0.0;
00082  d.a6=0.0;
00083  d.a7=0.2;
00084  d.a8=0.0;
00085  d.a9=0.0;
00086  if(DialogBoxParam(hThisInstance,MAKEINTRESOURCE(DLG_VTK),hParent,
00087              (DLGPROC)SfxDlgProc,(LPARAM)&d) == FALSE)return FALSE;
00088  hSave=SetCursor(LoadCursor(NULL,IDC_WAIT));
00089  {
00090   SfxWriter sfxoutput;
00091   vtkQuadric *quadric = new vtkQuadric;
00092   quadric->SetCoefficients(d.a0,d.a1,d.a2,d.a3,d.a4,d.a5,d.a6,d.a7,d.a8,d.a9);
00093 
00094   vtkSampleFunction *sample = new vtkSampleFunction;
00095   sample->SetSampleDimensions(d.i,d.j,d.k);
00096   sample->SetModelBounds(d.xmin,d.xmax,d.ymin,d.ymax,d.zmin,d.zmax);
00097   sample->SetCapping((int)d.cap);
00098   sample->SetImplicitFunction(quadric);
00099 
00100   vtkContourFilter *cf = new vtkContourFilter;
00101   cf->SetInput(sample->GetOutput());
00102   cf->SetValue(0,d.cv);
00103 
00104   vtkCleanPolyData *cp = new vtkCleanPolyData;
00105   cp->SetTolerance(0.001);
00106   cp->SetInput(cf->GetOutput());
00107 
00108   vtkTriangleFilter *tf = new vtkTriangleFilter;
00109   tf->SetInput(cp->GetOutput());
00110 
00111   sfxoutput.SetInput(tf->GetOutput());
00112   sfxoutput.Write();
00113 
00114   delete tf;
00115   delete cp;
00116   delete cf;
00117   delete sample;
00118   delete quadric;
00119 
00120  }
00121  SetCursor(hSave);
00122  return TRUE;
00123 }
00124 
00125 static BOOL CALLBACK SfxDlgProc(HWND hwnd, UINT msg,
00126                           WPARAM wparam, LPARAM lparam){
00127  BOOL err;
00128  double f;
00129  int i;
00130  static struct bp {
00131   BOOL cap;
00132   float xmin,xmax,ymin,ymax,zmin,zmax;
00133   int i,j,k;
00134   float cv;
00135   float a0,a1,a2,a3,a4,a5,a6,a7,a8,a9;
00136  } *dp;
00137  char str[32];
00138  switch( msg ) {
00139    case WM_INITDIALOG:
00140      dp=(struct bp *)lparam;
00141      SetDlgItemInt(hwnd,DLG_VTK_XRES,dp->i,FALSE);
00142      SetDlgItemInt(hwnd,DLG_VTK_YRES,dp->j,FALSE);
00143      SetDlgItemInt(hwnd,DLG_VTK_ZRES,dp->k,FALSE);
00144      sprintf(str,"%.2lf",dp->a0);
00145      SetDlgItemText(hwnd,DLG_VTK_a0,(LPCTSTR)str);
00146      sprintf(str,"%.2lf",dp->a1);
00147      SetDlgItemText(hwnd,DLG_VTK_a1,(LPCTSTR)str);
00148      sprintf(str,"%.2lf",dp->a2);
00149      SetDlgItemText(hwnd,DLG_VTK_a2,(LPCTSTR)str);
00150      sprintf(str,"%.2lf",dp->a3);
00151      SetDlgItemText(hwnd,DLG_VTK_a3,(LPCTSTR)str);
00152      sprintf(str,"%.2lf",dp->a4);
00153      SetDlgItemText(hwnd,DLG_VTK_a4,(LPCTSTR)str);
00154      sprintf(str,"%.2lf",dp->a5);
00155      SetDlgItemText(hwnd,DLG_VTK_a5,(LPCTSTR)str);
00156      sprintf(str,"%.2lf",dp->a6);
00157      SetDlgItemText(hwnd,DLG_VTK_a6,(LPCTSTR)str);
00158      sprintf(str,"%.2lf",dp->a7);
00159      SetDlgItemText(hwnd,DLG_VTK_a7,(LPCTSTR)str);
00160      sprintf(str,"%.2lf",dp->a8);
00161      SetDlgItemText(hwnd,DLG_VTK_a8,(LPCTSTR)str);
00162      sprintf(str,"%.2lf",dp->a9);
00163      SetDlgItemText(hwnd,DLG_VTK_a9,(LPCTSTR)str);
00164      sprintf(str,"%.2lf",dp->cv);
00165      SetDlgItemText(hwnd,DLG_VTK_CONTOUR,(LPCTSTR)str);
00166      sprintf(str,"%.2lf",dp->xmin);
00167      SetDlgItemText(hwnd,DLG_VTK_XMIN,(LPCTSTR)str);
00168      sprintf(str,"%.2lf",dp->xmax);
00169      SetDlgItemText(hwnd,DLG_VTK_XMAX,(LPCTSTR)str);
00170      sprintf(str,"%.2lf",dp->ymin);
00171      SetDlgItemText(hwnd,DLG_VTK_YMIN,(LPCTSTR)str);
00172      sprintf(str,"%.2lf",dp->ymax);
00173      SetDlgItemText(hwnd,DLG_VTK_YMAX,(LPCTSTR)str);
00174      sprintf(str,"%.2lf",dp->zmin);
00175      SetDlgItemText(hwnd,DLG_VTK_ZMIN,(LPCTSTR)str);
00176      sprintf(str,"%.2lf",dp->zmax);
00177      SetDlgItemText(hwnd,DLG_VTK_ZMAX,(LPCTSTR)str);
00178      if(dp->cap)SendDlgItemMessage(hwnd,DLG_VTK_CAP,BM_SETCHECK,TRUE,0);
00179      CentreDlgOnS(hwnd);
00180      return (TRUE);
00181    case WM_COMMAND:
00182       switch(LOWORD(wparam)){
00183         case IDCANCEL:
00184           EndDialog(hwnd,FALSE);
00185           return(TRUE);
00186         case IDOK:
00187           i=GetDlgItemInt(hwnd,DLG_VTK_XRES,&err,FALSE);
00188           if(err)dp->i=i;
00189           i=GetDlgItemInt(hwnd,DLG_VTK_YRES,&err,FALSE);
00190           if(err)dp->j=i;
00191           i=GetDlgItemInt(hwnd,DLG_VTK_ZRES,&err,FALSE);
00192           if(err)dp->k=i;
00193           if(GetDlgItemText(hwnd,DLG_VTK_a0,str,10) == 0){
00194             EndDialog(hwnd,FALSE); return TRUE;
00195           }
00196           dp->a0=atof(str);
00197           if(GetDlgItemText(hwnd,DLG_VTK_a1,str,10) == 0){
00198             EndDialog(hwnd,FALSE); return TRUE;
00199           }
00200           dp->a1=atof(str);
00201           if(GetDlgItemText(hwnd,DLG_VTK_a2,str,10) == 0){
00202             EndDialog(hwnd,FALSE); return TRUE;
00203           }
00204           dp->a2=atof(str);
00205           if(GetDlgItemText(hwnd,DLG_VTK_a3,str,10) == 0){
00206             EndDialog(hwnd,FALSE); return TRUE;
00207           }
00208           dp->a3=atof(str);
00209           if(GetDlgItemText(hwnd,DLG_VTK_a4,str,10) == 0){
00210             EndDialog(hwnd,FALSE); return TRUE;
00211           }
00212           dp->a4=atof(str);
00213           if(GetDlgItemText(hwnd,DLG_VTK_a5,str,10) == 0){
00214             EndDialog(hwnd,FALSE); return TRUE;
00215           }
00216           dp->a5=atof(str);
00217           if(GetDlgItemText(hwnd,DLG_VTK_a6,str,10) == 0){
00218             EndDialog(hwnd,FALSE); return TRUE;
00219           }
00220           dp->a6=atof(str);
00221           if(GetDlgItemText(hwnd,DLG_VTK_a7,str,10) == 0){
00222             EndDialog(hwnd,FALSE); return TRUE;
00223           }
00224           dp->a7=atof(str);
00225           if(GetDlgItemText(hwnd,DLG_VTK_a8,str,10) == 0){
00226             EndDialog(hwnd,FALSE); return TRUE;
00227           }
00228           dp->a8=atof(str);
00229           if(GetDlgItemText(hwnd,DLG_VTK_a9,str,10) == 0){
00230             EndDialog(hwnd,FALSE); return TRUE;
00231           }
00232           dp->a9=atof(str);
00233           if(GetDlgItemText(hwnd,DLG_VTK_CONTOUR,str,10) == 0){
00234             EndDialog(hwnd,FALSE); return TRUE;
00235           }
00236           dp->cv=atof(str);
00237           if(GetDlgItemText(hwnd,DLG_VTK_XMIN,str,10) == 0){
00238             EndDialog(hwnd,FALSE); return TRUE;
00239           }
00240           dp->xmin=atof(str);
00241           if(GetDlgItemText(hwnd,DLG_VTK_XMAX,str,10) == 0){
00242             EndDialog(hwnd,FALSE); return TRUE;
00243           }
00244           dp->xmax=atof(str);
00245           if(GetDlgItemText(hwnd,DLG_VTK_YMIN,str,10) == 0){
00246             EndDialog(hwnd,FALSE); return TRUE;
00247           }
00248           dp->ymin=atof(str);
00249           if(GetDlgItemText(hwnd,DLG_VTK_YMAX,str,10) == 0){
00250             EndDialog(hwnd,FALSE); return TRUE;
00251           }
00252           dp->ymax=atof(str);
00253           if(GetDlgItemText(hwnd,DLG_VTK_ZMIN,str,10) == 0){
00254             EndDialog(hwnd,FALSE); return TRUE;
00255           }
00256           dp->zmin=atof(str);
00257           if(GetDlgItemText(hwnd,DLG_VTK_YMAX,str,10) == 0){
00258             EndDialog(hwnd,FALSE); return TRUE;
00259           }
00260           dp->ymax=atof(str);
00261           if(SendDlgItemMessage(hwnd,DLG_VTK_CAP,BM_GETCHECK,0,0))
00262                dp->cap=TRUE;
00263           else dp->cap=FALSE;
00264           EndDialog(hwnd,TRUE);
00265           return(TRUE);
00266         default:
00267           break;
00268       }
00269       break;
00270     default: break;
00271  }
00272  return(FALSE);
00273 }
00274 

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