TESSEL.C

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 /*  TESSEL.C  */
00007 #include <stdlib.h>
00008 #include <stdio.h>
00009 #include <math.h>
00010 #include <windows.h>
00011 
00012 #include "struct.h"
00013 #include "dstruct.h"
00014 
00015 #include "tessel.h"
00016 
00017 #define DESELECTED 0
00018 #define SELECTED   1
00019 
00020 static HWND      hParent;
00021 static HINSTANCE hThisInstance;
00022 
00023 
00024 #if __WATCOMC__
00025 int APIENTRY LibMain(HANDLE hDLL, DWORD dwReason, LPVOID lpReserved){
00026 #else
00027 BOOL WINAPI DllMain(HANDLE hDLL, DWORD dwReason, LPVOID lpReserved){
00028 #endif
00029   switch (dwReason) {
00030     case DLL_PROCESS_ATTACH: {
00031       hThisInstance=hDLL;
00032       if(hDLL == NULL)MessageBox ( GetFocus()," NULL instance",NULL, MB_OK);
00033       break;
00034     }
00035     case DLL_PROCESS_DETACH:
00036       break;
00037   }
00038   return TRUE;
00039 }
00040 
00041 BOOL _Xmodeler
00042  (HWND parent_window,HWND info_window,X__STRUCTURE *lpevi){
00043  char text_string[255],name_string[255];
00044  lpEVI=lpevi;
00045  hParent=parent_window;
00046  LoadString(hThisInstance,IDX_STRING2,text_string,256);
00047  LoadString(hThisInstance,IDX_STRING1,name_string,256);
00048  if(MessageBox(hParent,text_string,name_string,MB_OKCANCEL)
00049                == IDCANCEL)return FALSE;
00050  else{
00051 #if 0
00052  {// this is the copy code //
00053  HCURSOR hSave;
00054  vertex *vp,*V0,*V1,*V2,*Vp;
00055  edge   *ep;
00056  face   *fp;
00057  long   i,Nvert1,Nedge1,Nface1;
00058  long x,y,z;
00059  if(NvertSelect == 0 || NvertSelect > 32000)return FALSE;
00060  hSave=SetCursor(LoadCursor(NULL,IDC_WAIT));
00061  if(!UpdateVertexHeap(Nvert+NvertSelect))return FALSE;
00062  for(Nedge1=0,ep=MainEp,i=0;i<Nedge;i++){
00063    V0=(MainVp+ep->V[0]); V1=(MainVp+ep->V[1]);
00064    if(V0->status == SELECTED && V1->status == SELECTED)Nedge1++;
00065    ep++;
00066  }
00067  if(!UpdateEdgeHeap(Nedge+Nedge1))return FALSE;
00068  for(Nface1=0,fp=MainFp,i=0;i<Nface;i++){
00069    V0=(MainVp+fp->V[0]); V1=(MainVp+fp->V[1]); V2=(MainVp+fp->V[2]);
00070    if(V0->status == SELECTED &&
00071       V1->status == SELECTED &&
00072       V2->status == SELECTED)Nface1++;
00073    fp++;
00074  }
00075  if(!UpdateFaceHeap(Nface+Nface1))return FALSE;
00076  Nvert1=Nvert; Nedge1=Nedge; Nface1=Nface;
00077  vp=MainVp; for(i=0;i<Nvert1;i++){
00078    if(vp->status == SELECTED){
00079      CreateVertex();
00080      Vp=(MainVp+Nvert-1);
00081      Vp->xyz[0]=vp->xyz[0];
00082      Vp->xyz[1]=vp->xyz[1];
00083      Vp->xyz[2]=vp->xyz[2];
00084      Vp->gp=vp->gp;
00085      if(Vp->gp == 1){
00086        Vp->x=vp->x;
00087        Vp->y=vp->y;
00088        NvertGlue++;
00089      }
00090      Vp->status=DESELECTED;
00091      vp->id=Nvert-1;
00092      NvertSelect--; NvertDeselect++;
00093    }
00094    else{
00095      vp->id = -1;  /* needed by copy+flip+weld */
00096    }
00097    vp++;
00098  }
00099  if(Nedge > 0)for(ep=MainEp,i=0;i<Nedge1;i++){
00100    V0=(MainVp+ep->V[0]); V1=(MainVp+ep->V[1]);
00101    if(V0->status == SELECTED &&
00102       V1->status == SELECTED){
00103       CreateEdge(V0->id,V1->id);
00104    }
00105    ep++;
00106  }
00107  if(Nface > 0)for(fp=MainFp,i=0;i<Nface1;i++){
00108    V0=(MainVp+fp->V[0]); V1=(MainVp+fp->V[1]); V2=(MainVp+fp->V[2]);
00109    if(V0->status == SELECTED &&
00110       V1->status == SELECTED &&
00111       V2->status == SELECTED) {
00112      CreateFace(V0->id,V1->id,V2->id);
00113      CopyFaceProp(fp,(MainFp+Nface-1));
00114    }
00115    fp++;
00116  }
00117  vp=MainVp; for(i=0;i<Nvert1;i++){
00118    if(vp->status == SELECTED){
00119     vp->status=DESELECTED;
00120     (MainVp+vp->id)->status=SELECTED;
00121    }
00122    vp++;
00123  }
00124  SetCursor(hSave);
00125  }
00126 #endif
00127    HCURSOR hSave;
00128    vertex *vp,*V0,*V1,*V2,*Vp;
00129    face   *fp;
00130    long   i,nf;
00131    long x,y,z;
00132    if(NvertSelect == 0 || NvertSelect > 32000 || Nface == 0)return FALSE;
00133    hSave=SetCursor(LoadCursor(NULL,IDC_WAIT));
00134    for(nf=0,fp=MainFp,i=0;i<Nface;i++){
00135      V0=(MainVp+fp->V[0]); V1=(MainVp+fp->V[1]); V2=(MainVp+fp->V[2]);
00136      if(V0->status == SELECTED &&
00137         V1->status == SELECTED &&
00138         V2->status == SELECTED)nf++;
00139      fp++;
00140    }
00141    if(nf == 0)goto XXIT;
00142    if(!UpdateVertexHeap(Nvert+nf))goto XXIT;
00143    if(!UpdateEdgeHeap(Nedge+3*nf))goto XXIT;
00144    if(!UpdateFaceHeap(Nface+2*nf))goto XXIT;
00145    for(nf=0,fp=MainFp,i=0;i<Nface;i++){
00146      V0=(MainVp+fp->V[0]); V1=(MainVp+fp->V[1]); V2=(MainVp+fp->V[2]);
00147      if(V0->status == SELECTED &&
00148         V1->status == SELECTED &&
00149         V2->status == SELECTED){ /* this face */
00150        x=(long)(((double)V0->xyz[0]+(double)V1->xyz[0]+(double)V2->xyz[0])/3.0);
00151        y=(long)(((double)V0->xyz[1]+(double)V1->xyz[1]+(double)V2->xyz[1])/3.0);
00152        z=(long)(((double)V0->xyz[2]+(double)V1->xyz[2]+(double)V2->xyz[2])/3.0);
00153        CreateVertex();
00154        Vp=(MainVp+Nvert-1);
00155        Vp->xyz[0]=x; Vp->xyz[1]=y; Vp->xyz[2]=z;
00156        Vp->status=DESELECTED;
00157        NvertSelect--; NvertDeselect++;
00158        CreateEdge(Nvert-1,fp->V[0]);
00159        CreateEdge(Nvert-1,fp->V[1]);
00160        CreateEdge(Nvert-1,fp->V[2]);
00161        CreateFace(fp->V[0],Nvert-1,fp->V[2]);
00162        CreateFace(fp->V[0],fp->V[1],Nvert-1);
00163        fp->V[0]=Nvert-1;
00164      }
00165      fp++;
00166    }
00167    XXIT:
00168    SetCursor(hSave);
00169  }
00170  return TRUE;
00171 }

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