00001 /* ImLib3D 00002 * Copyright (c) 2001, ULP-IPB Strasbourg. 00003 * 00004 * This program is free software; you can redistribute it and/or modify 00005 * it under the terms of the GNU General Public License as published by 00006 * the Free Software Foundation; either version 2 of the License, or (at 00007 * your option) any later version. 00008 * 00009 * This program is distributed in the hope that it will be useful, but 00010 * WITHOUT ANY WARRANTY; without even the implied warranty of 00011 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00012 * General Public License for more details. 00013 * 00014 * You should have received a copy of the GNU General Public License 00015 * along with this program; if not, write to the Free Software 00016 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 00017 */ 00020 #include<ImLib3D/ImLib3D.hpp> 00021 #include<ImLib3D/Display.hpp> 00022 #include<ImLib3D/TaskProgressManager.hpp> 00023 00024 #include <sys/types.h> 00025 #include <sys/stat.h> 00026 #include <fcntl.h> 00027 #include <stdio.h> 00028 #include <unistd.h> 00029 #include <signal.h> 00030 00031 00032 00034 ImLib3D imLib3D; 00035 00036 extern "C" 00037 { 00038 // On HP, constructors are not called correctly when ImLib3D is used as a shared library. To initialize global variables correctly you must link (the shared version of) the library with the switch: '+I HPSharedLibInit' 00039 void HPSharedLibInit() 00040 { 00041 imLib3D.Init(); 00042 } 00043 } 00044 00045 00046 ImLib3D::ImLib3D() 00047 { 00048 Init(); 00049 } 00050 00051 void ImLib3D::Init() 00052 { 00053 // this is necessary, otherwise numbers might have "," instead of "." 00054 setlocale(LC_NUMERIC, "C"); 00055 // fprintf(stderr,"******************** Initializing IMLIB3D pid:%d parent:%d (%x)*********************\n", 00056 // getpid(),getppid(),(uint)this); 00057 00058 // Check if ImLib3D's global constructors are being called twice 00059 // due to problems with shared libraries 00060 // This is done by checking if pidCheckMultipleCtr and thisCheckMultipleCtr 00061 // are already set 00062 if(pidCheckMultipleCtr!=getpid() || thisCheckMultipleCtr!=this) 00063 { 00064 // printf("ImLib3D:first init\n"); 00065 pidCheckMultipleCtr=getpid(); 00066 thisCheckMultipleCtr=this; 00067 00068 display=NULL; 00069 ImLib3DDisplay::Set(new ViewerDisplay()); 00070 taskProgressManager=new TaskProgressManager(1,3); 00071 defaultTaskProgressManager=taskProgressManager; 00072 defaultTaskProgressManager->Start(); 00073 } 00074 else 00075 { 00076 // fprintf(stderr,"ImLib3D::ImLib3D ignoring multiple calls to global constructor due to shared library\n"); 00077 } 00078 } 00079 00080 00081 ImLib3D::~ImLib3D() 00082 { 00083 // fprintf(stderr,"#################### Destroying IMLIB3D pid:%d parent:%d ##################### \n", 00084 // getpid(),getppid()); 00085 00086 if(pidCheckMultipleCtr==getpid() || thisCheckMultipleCtr==this) 00087 { 00088 // printf("ImLib3D:first destuct\n"); 00089 pidCheckMultipleCtr=0; 00090 thisCheckMultipleCtr=NULL; 00091 00092 if(taskProgressManager) 00093 { 00094 taskProgressManager->Stop(); 00095 delete taskProgressManager; 00096 } 00097 } 00098 else 00099 { 00100 //fprintf(stderr,"ImLib3D::ImLib3D ignoring multiple calls to global destructor due to shared library\n"); 00101 } 00102 }