SIVIC API  0.9.26
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
svkUtils.h
Go to the documentation of this file.
1 /*
2  * Copyright © 2009-2014 The Regents of the University of California.
3  * All Rights Reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions are met:
7  * • Redistributions of source code must retain the above copyright notice,
8  * this list of conditions and the following disclaimer.
9  * • Redistributions in binary form must reproduce the above copyright notice,
10  * this list of conditions and the following disclaimer in the documentation
11  * and/or other materials provided with the distribution.
12  * • None of the names of any campus of the University of California, the name
13  * "The Regents of the University of California," or the names of any of its
14  * contributors may be used to endorse or promote products derived from this
15  * software without specific prior written permission.
16  *
17  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
18  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
19  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
20  * IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
21  * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
22  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
23  * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
24  * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
25  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
26  * OF SUCH DAMAGE.
27  */
28 
29 
30 
31 /*
32  * $URL$
33  * $Rev$
34  * $Author$
35  * $Date$
36  *
37  * Authors:
38  * Jason C. Crane, Ph.D.
39  * Beck Olson
40  */
41 
42 
43 #ifndef SVK_UTILS_H
44 #define SVK_UTILS_H
45 
46 
47 #include <string>
48 #include <map>
49 #include <vector>
50 #include <stdio.h>
51 #include <sstream>
52 #include <vtkObjectFactory.h>
53 #include <vtkObject.h>
54 #include <vtkGlobFileNames.h>
55 #include <vtkStringArray.h>
56 #include <vtkDirectory.h>
57 #include <svkMriImageData.h>
58 #include <svkMrsImageData.h>
59 
60 #ifdef WIN32
61 #include <windows.h>
62 #define MAXPATHLEN 260
63 #else
64 #include <sys/param.h>
65 #include <pwd.h>
66 #endif
67 namespace svk {
68 
69 
70 using namespace std;
74 class svkUtils : public vtkObject
75 {
76 
77  public:
78 
79 
80  // vtk type revision macro
81  vtkTypeMacro( svkUtils, vtkObject );
82 
83  // vtk initialization
84  static svkUtils* New();
85 
87  static bool FilePathExists( const char* path );
88  static string GetCurrentWorkingDirectory();
89  static string GetHomeDirectory();
90  static string GetUserName();
91  static bool CanWriteToPath( const char* path );
92  static int CopyFile( const char* input, const char* output );
93  static int MoveFile( const char* input, const char* output );
94  static bool PrintFile( const char* fileName, const char* printerName );
95  static vector<string> GetFileNamesFromPattern(
96  string imageBaseName,
97  int startSlice,
98  int endSlice
99  );
100  static string GetDefaultSecondaryCaptureDirectory(
101  svkMriImageData* image,
102  svk4DImageData* spectra
103  );
104  static string GetDefaultSecondaryCaptureFilePattern(
105  svkMriImageData* image,
106  svk4DImageData* spectra
107  );
108  static int GetNextPower2( int x );
109  static void StringToColorArray( double color[3], string colorString );
110  static string Double3x3ToString( double doubleMatrix[][3] );
111  static string ColorArrayToString( double color[3] );
112  static vector<string> SplitString( string str, string token );
113  static string GetFilenameFromFullPath( string fullPath );
114  static int NearestInt(double x);
115  static bool UncompressFiles( vtkStringArray *filenames );
116  static bool UncompressFile( vtkstd::string filename );
117  static bool IsFileCompressed( vtkstd::string filename );
118  static string SpacesTo_( string inputString );
119  static bool AreValuesClose(double x, double y, double maxRatio = 0.01 );
120  static bool AreValuesClose(double x[3], double y[3], double maxRatio = 0.01 );
121  static int GetNumberOfDigits( int value, bool isMinusDigit = false );
122  static void GetRealpath( const char * path, int size, char* realpath );
123  static void ReadLine(ifstream* fs, istringstream* iss);
124 
125 
126  protected:
127 
128  svkUtils();
129  ~svkUtils();
130 
131 };
132 
133 
134 } //svk
135 
136 
137 
138 #endif //SVK_UTILS
Definition: svkUtils.h:74
Definition: svk4DImageData.h:69
Definition: svkMriImageData.h:72