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

Generated on Thu Jan 23 12:32:16 2003 by doxygen1.3-rc2