Main Page   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members   File Members  

transfuncfile.cpp

Go to the documentation of this file.
00001 
00002 
00003 
00004 
00005 
00006 #include "stdafx.h"
00007 #include "transfuncfile.h"
00008 #include <stdio.h>
00009 
00012 INDEXLIST CTransfuncFile::LoadTransferFunc(const char *filename, bool &success) {
00013         success = false;
00014         FILE *file;
00015         if ((file = fopen(filename, "rb")) == NULL) {
00016                 success = false;
00017                 return NULL;
00018         }
00019 
00020 
00021         fread(&m_sTransHeader, sizeof(m_sTransHeader), 1, file);
00022         
00023         INDEXLIST temp;
00024         INDICES tempInd;
00025 
00026         for (int i = 0; i < m_sTransHeader.m_bNumber; i++) {
00027                 fread(&m_sTransData, sizeof(m_sTransData), 1, file);
00028                 tempInd.m_sdBegin = m_sTransData.m_dBegin;
00029                 tempInd.m_sdEnd = m_sTransData.m_dEnd;
00030                 tempInd.m_ucAlpha = m_sTransData.m_pcAlpha;
00031                 tempInd.m_scColor = m_sTransData.m_pColor;
00032                 temp.push_back(tempInd);
00033         }
00034 
00035         fclose(file);
00036 
00037         success = true;
00038         return temp;
00039 }
00040 
00045 INDEXLIST *CTransfuncFile::LoadPresets(int &numPresets) {
00046         string filename = "transferfunctions/preset_.tff";
00047 
00048         INDEXLIST *templist = new INDEXLIST[10];
00049         INDEXLIST temp;
00050 
00051         bool success;
00052 
00053         numPresets = 0;
00054         for (int i = 0; i < 10; i++) {
00055                 filename[24] = i + '0';
00056                 temp = LoadTransferFunc(filename.c_str(), success);
00057                 if (success)
00058                         templist[numPresets++] = temp;
00059         }
00060         return templist;
00061 }
00062 
00063 
00066 void CTransfuncFile::SaveTransferFunc(INDEXLIST &indexList, string filename) {
00067         m_sTransHeader.m_pcName;
00068         m_sTransHeader.m_bNumber = indexList.size();
00069         FILE *file;
00070 
00071         if ((file = fopen(filename.c_str(), "wb")) == NULL) 
00072                 return;
00073 
00074         INDICES tempInd;
00075 
00076         fwrite(&m_sTransHeader, sizeof(m_sTransHeader), 1, file);
00077         for (int i = 0; i < indexList.size(); i++) {
00078                 tempInd = indexList[i];
00079                 m_sTransData.m_dBegin = tempInd.m_sdBegin;
00080                 m_sTransData.m_dEnd = tempInd.m_sdEnd;
00081                 m_sTransData.m_pcAlpha = tempInd.m_ucAlpha;
00082                 m_sTransData.m_pColor = tempInd.m_scColor;
00083                 fwrite(&m_sTransData, sizeof(m_sTransData), 1, file);
00084         }
00085 
00086         fclose(file);
00087 }

Generated on Thu Jan 30 21:35:43 2003 for 3DVis by doxygen1.3-rc2