Blame view

ManageProject.cpp 6.23 KB
ee96a02c   David Mayerich   first commit from...
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
  #include "trueeyes.h"
  #include "GlobalValues.h"
  #include "VolumeDataStruct.h"
  #include "VolumeShaderStruct.h"
  #include <fstream>
  #include <qstring.h>
  #include <qdir.h>
  using namespace std;
  
  #define OBJECT_TYPE_VOLUME	0
  #define OBJECT_TYPE_SHADER	1
  #define OBJECT_TYPE_SOURCE	2
  #define OBJECT_TYPE_TEXTURE	3
  
  void SaveProject(string filename)
  {
  	//determine the project directory
  	QDir projectDir(QString(filename.c_str()));
  	cout<<"Project directory: "<<string(projectDir.absolutePath().toAscii())<<endl;
  	//create a project file for output
  	ofstream out;
  	out.open(filename.c_str());
  
  	//save the global variables
  	out<<StepSize<<endl;
  	out<<gpVolSize[0]<<" "<<gpVolSize[1]<<" "<<gpVolSize[2]<<endl;
  	out<<gpCropMin[0]<<" "<<gpCropMin[1]<<" "<<gpCropMin[2]<<endl;
  	out<<gpCropMax[0]<<" "<<gpCropMax[1]<<" "<<gpCropMax[2]<<endl;
  
  	//write volume data
  	for(int v=0; v<VolumeList.size(); v++)
  	{
  		if(v > 0) out<<endl;
  		VolumeData outVol = VolumeList[v];
  		//specify the object as a volume
  		out<<OBJECT_TYPE_VOLUME<<endl;
  		out<<outVol.Name<<endl;
  		out<<outVol.FileType<<endl;
  		out<<outVol.Filenames.size()<<endl;
  		for(int f=0; f<outVol.Filenames.size(); f++)
  		{
  			//out<<outVol.Filenames[f].getString()<<endl;
  			QString fullPath = QString(outVol.Filenames[f].getString().c_str());
  			QString relativePath = projectDir.relativeFilePath(fullPath);
  			out<<string(relativePath.toAscii())<<endl;
  		}
  		out<<outVol.Dim.x<<endl;
  		out<<outVol.Dim.y<<endl;
  		out<<outVol.Dim.z<<endl;
  		out<<outVol.HeaderSize<<endl;
  		out<<outVol.BitType<<endl;
  		out<<outVol.ExternalComponents<<endl;
  		out<<outVol.ExternalDatatype<<endl;
  		out<<outVol.InternalComponents<<endl;
  		out<<outVol.InternalDatatype<<endl;
  		out<<outVol.Normalized;
  	}
  
  	//write shader data
  	for(int s=0; s<ShaderList.size(); s++)
  	{
  		VolumeShader outShader = ShaderList[s];
  		out<<endl;
  		out<<OBJECT_TYPE_SHADER<<endl;
  		out<<outShader.Name<<endl;
  
  		QString fullPath = QString(outShader.Filename.c_str());
  		QString relativePath = projectDir.relativeFilePath(fullPath);
  		out<<string(relativePath.toAscii());
  	}
  
  	//write source data
  	for(int s=0; s<SourceList.size(); s++)
  	{
  		VolumeSource outSource = SourceList[s];
  		out<<endl;
  		out<<OBJECT_TYPE_SOURCE<<endl;
  		out<<outSource.Name<<endl;
  		point3D<float> position = outSource.S.getPosition();
  		point3D<float> lookat = outSource.S.getLookAt();
  		vector3D<float> up = outSource.S.getUp();
  		out<<position.x<<" "<<position.y<<" "<<position.z<<endl;
  		out<<lookat.x<<" "<<lookat.y<<" "<<lookat.z<<endl;
  		out<<up.x<<" "<<up.y<<" "<<up.z;
  	}
  
  	//write texture data
  	for(int t=0; t<TextureList.size(); t++)
  	{
  		TextureData outTexture = TextureList[t];
  		out<<endl;
  		out<<OBJECT_TYPE_TEXTURE<<endl;
  		out<<outTexture.Name<<endl;
  
  		//save the file information (convert to a relative path)
  		QString fullPath = QString(outTexture.Filename.getString().c_str());
  		QString relativePath = projectDir.relativeFilePath(fullPath);
  		out<<string(relativePath.toAscii())<<endl;
  
  		out<<outTexture.sX<<endl;
  		out<<outTexture.sY<<endl;
  		out<<outTexture.ExternalComponents<<endl;
  		out<<outTexture.ExternalDatatype<<endl;
  		out<<outTexture.InternalComponents<<endl;
  		out<<outTexture.InternalDatatype<<endl;
  		out<<outTexture.Normalized;
  
  	}
  
  	//close the file
  	out.close();
  }
  
  void LoadProject(string filename)
  {
  	//determine the project directory
  	QFileInfo projectFile(QString(filename.c_str()));
  	QDir projectDir = projectFile.dir();
  	QString test = projectDir.path();
  
  	//first clear all previous list data
  	int v, s;
  	for(v=0; v<VolumeList.size(); v++)
  		VolumeList[v].Texture.Clean();
  	VolumeList.clear();
  	for(s=0; s<ShaderList.size(); s++)
  		ShaderList[s].glProgram.Clean();
  	ShaderList.clear();
  
  	SourceList.clear();
  
  	//open the file for reading
  	ifstream in;
  	in.open(filename.c_str());
  	if(!in.is_open())
      {
          cout<<"Error opening file."<<endl;
          return;
      }
  
  	//grab the global variables
  	in>>StepSize;
  	in>>gpVolSize[0];
  	in>>gpVolSize[1];
  	in>>gpVolSize[2];
  	in>>gpCropMin[0];
  	in>>gpCropMin[1];
  	in>>gpCropMin[2];
  	in>>gpCropMax[0];
  	in>>gpCropMax[1];
  	in>>gpCropMax[2];
  
  	while(!in.eof())
  	{
  		//get the object type
  		int t;
  		char c[1024];
  		in>>t;
  		if(t == OBJECT_TYPE_VOLUME)
  		{
  			VolumeData inVol;
  			in>>inVol.Name;
  			in>>inVol.FileType;
  			int num_files;
  			in>>num_files;
  			for(int f=0; f<num_files; f++)
  			{
                  //get the file name
  				in>>c;
  				QString relativePath = QString(c);
  				QString fullPath = projectDir.absoluteFilePath(relativePath);
  				inVol.Filenames.push_back(string(fullPath.toAscii()));
  			}
  			in>>inVol.Dim.x;
  			in>>inVol.Dim.y;
  			in>>inVol.Dim.z;
  			in>>inVol.HeaderSize;
  			in>>inVol.BitType;
  			in>>inVol.ExternalComponents;
  			in>>inVol.ExternalDatatype;
  			in>>inVol.InternalComponents;
  			in>>inVol.InternalDatatype;
  			in>>inVol.Normalized;
  
  			//add the volume data structure to the list
  			if(inVol.FileType == VOLUME_FILE_RAW)
  				LoadRawVolume(inVol);
  			if(inVol.FileType == VOLUME_FILE_IMAGES)
  				LoadImages(inVol);
  		}
  		else if(t == OBJECT_TYPE_TEXTURE)
  		{
  			TextureData inTex;
  			in>>inTex.Name;
  
  			//read the file name
  			in>>c;
  			QString relativePath = QString(c);
  			QString fullPath = projectDir.absoluteFilePath(relativePath);
  			inTex.Filename = string(fullPath.toAscii());
  
  			in>>inTex.sX;
  			in>>inTex.sY;
  
  			in>>inTex.ExternalComponents;
  			in>>inTex.ExternalDatatype;
  			in>>inTex.InternalComponents;
  			in>>inTex.InternalDatatype;
  			in>>inTex.Normalized;
  
  			//add the texture data structure to the list
  			LoadTexture(inTex);
  			TextureList.push_back(inTex);
  		}
  		else if(t == OBJECT_TYPE_SHADER)
  		{
  			VolumeShader inShader;
  			in>>inShader.Name;
  			in>>c;
  			QString relativePath = QString(c);
  			QString fullPath = projectDir.absoluteFilePath(relativePath);
  			inShader.Filename = string(fullPath.toAscii());
  
  			ShaderList.push_back(inShader);
  		}
  		else if(t == OBJECT_TYPE_SOURCE)
  		{
  			VolumeSource inSource;
  			in>>inSource.Name;
  
  			point3D<float> position;
  			point3D<float> lookat;
  			vector3D<float> up;
  
  			in>>position.x;
  			in>>position.y;
  			in>>position.z;
  			in>>lookat.x;
  			in>>lookat.y;
  			in>>lookat.z;
  			in>>up.x;
  			in>>up.y;
  			in>>up.z;
  
  			inSource.S.setPosition(position);
  			inSource.S.LookAt(lookat, up);
  			SourceList.push_back(inSource);
  		}
  	}
  	//close the file
  	in.close();
  
  	//reload everything
  	ReloadShaders();
  
  }