00001 #ifndef MSMSINTERFACE_H
00002 #define MSMSINTERFACE_H
00003 
00004 
00005 
00006 
00007 
00008 
00009 
00010 
00011 
00012 
00013 
00014 
00015 
00016 
00017 
00018 
00019 
00020 
00021 
00022 
00023 
00024 
00025 
00026 
00027 
00028 
00029 
00030 
00031 
00032 
00033 
00034 
00035 
00036 
00037 
00038 
00039 
00040 #include "ResizeArray.h"
00041 
00043 struct MSMSCoord {
00044   float x[3];       
00045   int operator==(const MSMSCoord& c) {
00046     return !memcmp(x, c.x, 3L*sizeof(float));
00047   }
00048 };
00049 
00051 struct MSMSFace {
00052   int vertex[3];    
00053 
00054   int surface_type; 
00055 
00056 
00057 
00058   int anaface;      
00059 
00060 
00061   int component;    
00062 
00063   int operator==(const MSMSFace &f) {
00064     return (!memcmp(vertex, f.vertex, 3L*sizeof(float)) &&
00065                     surface_type==f.surface_type && anaface==f.anaface &&
00066                     component==f.component);
00067   }
00068 };
00069 
00072 class MSMSInterface {
00073 private:
00074   void *msms_server;               
00075   static int find_free_port(void); 
00076 
00078   static const char *server_name(void);
00079 
00080   static int start_msms(int port); 
00081 
00083   static void *conn_to_service_port(int portnum);
00084 
00087   int check_for_input(int timeout_in_seconds, int num_reps, int stage);
00088 
00090   int call_msms(float probe_radius, float density,
00091                 int n, float *xyzr, int *flgs);
00092 
00094   int msms_ended(void);
00095 
00097   void close_server(int erno = 0);
00098 
00100   void get_triangulated_ses(int component);
00101 
00105   int get_blocking(char *str, int nbytes);
00106 
00109   char *get_message(char *buffer);
00110 
00111 public:
00112   int err;                         
00113   MSMSInterface(void) { err = 0; }
00114   ResizeArray<int>       atomids;  
00115   ResizeArray<MSMSFace>  faces;    
00116   ResizeArray<MSMSCoord> coords;   
00117   ResizeArray<MSMSCoord> norms;    
00118 
00120   enum {BAD_RANGE = -2, NO_PORTS = -3, NO_CONNECTION = -4,
00121         NO_INITIALIZATION = -5, MSMS_DIED = -6, COMPUTED = 1};
00122   int compute_from_socket(float probe_radius, float density,
00123               int n, int *ids, float *xyzr, int *flgs, int component = 0);
00124 
00126   void clear();
00127 
00128   
00129   int compute_from_file(float probe_radius, float density,
00130               int n, int *ids, float *xyzr, int *flgs, int component = 0);
00131 };
00132   
00133 #endif
00134