VTK.CPP

Go to the documentation of this file.
00001 /* --
00002 OpenFX version 2.0 - Modelling, Animation and Rendering Package
00003 Copyright (C) 2000 - 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 /*  VTK.CPP  */
00025 
00026 // test code for the VTK library
00027 
00028 #include "vtk.hh"
00029 #include <stdlib.h>
00030 #include <stdio.h>
00031 #include <math.h>
00032 #include <windows.h>
00033 
00034 #define UNIT         32768L
00035 #define DESELECTED       0
00036 #define SELECTED         1
00037 #define INEDITOR         6
00038 
00039 #ifdef __cplusplus
00040 extern "C" {
00041 #endif
00042 
00043 #include "struct.h"
00044 #include "dstruct.h"
00045 
00046 #ifdef __cplusplus
00047 }
00048 #endif
00049 
00050 #include "vtk.h"
00051 
00052 #include "sfx2vtk.h"
00053 #include "sfx2vtk.cpp"
00054 
00055 static HWND      hParent;
00056 static HINSTANCE hThisInstance;
00057 
00058 static BOOL CALLBACK SfxDlgProc(HWND hwnd, UINT msg,
00059                                 WPARAM wparam, LPARAM lparam);
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 
00079 extern "C" BOOL _Xmodeler
00080  (HWND parent_window,HWND info_window,X__STRUCTURE *lpevi){
00081  HCURSOR hSave;
00082  static struct bp {
00083   float f;
00084  } d;
00085  lpEVI=lpevi;
00086  hParent=parent_window;
00087  d.f=0.8;
00088  if(DialogBoxParam(hThisInstance,MAKEINTRESOURCE(DLG_VTK),hParent,
00089              (DLGPROC)SfxDlgProc,(LPARAM)&d) == FALSE)return FALSE;
00090  hSave=SetCursor(LoadCursor(NULL,IDC_WAIT));
00091  {
00092 #if 0
00093   SfxReader sfxinput;
00094   SfxWriter sfxoutput;
00095 
00096   SfxPointReader sfxpointinput;
00097   SfxEdgeReader sfxedgeinput;
00098   vtkRenderMaster rm;
00099   vtkRenderWindow *renWin;
00100   vtkRenderer *aren;
00101   vtkActor    *actor1, *actor2;
00102   vtkCubeSource *cube1,*cube2;
00103   vtkAppendPolyData *cube;
00104   vtkConeSource *cone;
00105   vtkLineSource *line;
00106   vtkPointSource *pts;
00107   vtkImplicitModeller *imp;
00108   vtkContourFilter *cf;
00109   vtkPolyMapper *mapper, *omapper;
00110   vtkOutlineFilter *outline;
00111   vtkRenderWindowInteractor *iren;
00112 
00113 //  renWin  = rm.MakeRenderWindow();
00114 //  iren = renWin->MakeRenderWindowInteractor();
00115 //  aren    = renWin->MakeRenderer();
00116 //  pts = new vtkPointSource;
00117 //  pts->SetNumberOfPoints(10);
00118 
00119 //line = new vtkLineSource;
00120 //line->SetResolution(1);
00121 
00122 //  cone = new vtkConeSource;
00123 //    cone->SetResolution(8);
00124 
00125   cube1 = new vtkCubeSource(1,2,3);
00126   cube2 = new vtkCubeSource(2,3,4);
00127   cube2->SetCenter(3,3,3);
00128 
00129   cube = new vtkAppendPolyData;
00130   cube->AddInput(cube1->GetOutput());
00131   cube->AddInput(cube2->GetOutput());
00132 
00133   imp = new vtkImplicitModeller;
00134 //    imp->SetInput(sfxinput.GetOutput());
00135 //    imp->SetInput(sfxpointinput.GetOutput());
00136     imp->SetInput(sfxedgeinput.GetOutput());
00137 //    imp->SetInput(cube1->GetOutput());
00138     imp->SetSampleDimensions(25,25,25);
00139     imp->SetMaximumDistance(0.1);
00140 //    imp->SetMaximumDistance(0.2);
00141 
00142   cf = new vtkContourFilter;
00143 //    cf->SetInput(imp->GetOutput());
00144 //    cf->SetValue(0, 0.1);
00146 
00147     vtkSphere *sph1 = new vtkSphere;
00148     sph1->SetRadius(1.0);
00149     vtkSphere *sph2 = new vtkSphere;
00150     sph2->SetRadius(0.5);
00151     sph2->SetCenter(0.0,0.0,0.5);
00152     vtkImplicitBoolean *ibool = new vtkImplicitBoolean;
00153     ibool->AddFunction(sph1);
00154     ibool->AddFunction(sph2);
00155     ibool->SetOperationType(VTK_DIFFERENCE);
00156     vtkSampleFunction *sam = new vtkSampleFunction;
00157     sam->SetSampleDimensions(25,25,25);
00158     sam->SetImplicitFunction(ibool);
00159 //    sam->SetImplicitFunction(sph1);
00160     cf->SetInput(sam->GetOutput());
00161     cf->SetValue(0, 0.0);
00162 
00163 //  mapper = new vtkPolyMapper;
00164 //    mapper->SetInput(cf->GetOutput());
00165 
00166 //  actor1 = new vtkActor;
00167 //    actor1->SetMapper(mapper);
00168 //    actor1->GetProperty()->SetColor(0.8,1.0,0.9);
00169 
00170   // draw an outline
00171 //  outline = new vtkOutlineFilter;
00172 //    outline->SetInput(imp->GetOutput());
00173 
00174 //  omapper = new vtkPolyMapper;
00175 //    omapper->SetInput(outline->GetOutput());
00176 
00177 //  actor2 = new vtkActor;
00178 //    actor2->SetMapper(omapper);
00179 //    actor2->GetProperty()->SetColor(1,1,1);
00180 
00181 //  aren->AddActors(actor2);
00182 //  aren->AddActors(actor1);
00183 //  aren->SetBackground(0.2,0.2,0.2);
00184 
00185 //  renWin->Render();
00186 
00187   // interact with data
00188 //  iren->Start();
00189 
00190 //  vtkShrinkPolyData shrink;
00191 //  shrink.SetInput(sfxinput.GetOutput());
00192 //  shrink.SetShrinkFactor(d.f);
00193 
00194   vtkCleanPolyData *cp = new vtkCleanPolyData;
00195   cp->SetTolerance(0.0001);
00196   cp->SetInput(cf->GetOutput());
00197 
00198   vtkTriangleFilter *tf = new vtkTriangleFilter;
00199   tf->SetInput(cp->GetOutput());
00200 
00201   sfxoutput.SetInput(tf->GetOutput());
00202   sfxoutput.Write();
00203 
00204   delete tf;
00205   delete cp;
00206   delete cf;
00207   delete imp;
00208 #endif
00209 
00210  }
00211  SetCursor(hSave);
00212  return TRUE;
00213 }
00214 
00215 static BOOL CALLBACK SfxDlgProc(HWND hwnd, UINT msg,
00216                           WPARAM wparam, LPARAM lparam){
00217  BOOL err;
00218  double f;
00219  int i;
00220  static struct bp {
00221    float f;
00222  } *dp;
00223  char str[32];
00224  switch( msg ) {
00225    case WM_INITDIALOG:
00226      dp=(struct bp *)lparam;
00227      CentreDlgOnS(hwnd);
00228      return (TRUE);
00229    case WM_COMMAND:
00230       switch(LOWORD(wparam)){
00231         case IDCANCEL:
00232           EndDialog(hwnd,FALSE);
00233           return(TRUE);
00234         case IDOK:
00235           EndDialog(hwnd,TRUE);
00236           return(TRUE);
00237         default:
00238           break;
00239       }
00240       break;
00241     default: break;
00242  }
00243  return(FALSE);
00244 }
00245 

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