00001 #include "vuSimpleFVR.h"
00002 #include "vuSimpleTypes.h"
00003
00004 vu1112119::vu1112119()
00005 {
00006 }
00007
00008 vu1112119::~vu1112119()
00009 {
00010 vu1::m_Camera = NULL;
00011 }
00012
00013 byte *vu1112119::getData()
00014 {
00015 return m_Data;
00016 }
00017
00018 bool vu1112119::read()
00019 {
00020 if (!vu111211::read()) {
00021 cerr << "could not read spatial domain volume" << endl;
00022 return false;
00023 }
00024 bool result=preprocessSpatialInput(m_Data,m_Dim1Size,m_Dim2Size,m_Dim3Size);
00025
00026 CHECKNDELETE(m_Data);
00027 return result;
00028 }
00029
00030 void vu1112119::glResize(dword width, dword height)
00031 {
00032 if (m_ImageXSize && m_ImageYSize && width && height) {
00033 glPixelZoom((float)width/m_ImageXSize, (float)height/m_ImageYSize);
00034 }
00035 else {
00036 cerr << "vu1112119.glResize(): no m_ImageXSize/m_ImageYSize set." << endl;
00037 glPixelZoom(1.0f, 1.0f);
00038 }
00039 }
00040
00041 void vu1112119::render()
00042 {
00043 if (m_Volume) {
00044 vuFourierVolume1::setCamera(vu111211::getCameraPtr());
00045 computeSlice();
00046
00047 cerr << "vuSimpleFBR::render is not implemented" << endl;
00048 #if 0
00049 glDrawPixels(getImageWidth(),
00050 getImageHeight(),
00051 GL_LUMINANCE,
00052 GL_FLOAT,
00053 getImageData());
00054 #endif
00055 }
00056 }
00057
00058 void vu1112119::updateCamera()
00059 {
00060 vuFourierVolume1::setCamera(vu111211::getCameraPtr());
00061 }
00062
00063 void vu1112119::setCamera(vuCamera *camera)
00064 {
00065 vuFourierVolume1::setCamera(camera);
00066 vu111211::setCamera(camera);
00067 }
00068
00069 void vu1112119::setViewVectors(const vuVector& view,
00070 const vuVector& up,
00071 const vuVector& right)
00072 {
00073 vuFourierVolume1::setViewVectors(view, up, right);
00074 }
00075
00076 vuVector vu1112119::getCenter()
00077 {
00078 return vuVector(0,0,0);
00079 }
00080
00081
00082 bool vu1112119::convertVUD2VUF(vuString inputFile, vuString outputFile,
00083 float mult_pad, float add_pad, float scale,
00084 vuTFIntensity *tf)
00085 {
00086 vu1112119 *volume = new vu1112119();
00087
00088 volume->setFileName(inputFile);
00089 if (!volume->vu111211::read()) {
00090 cerr << "could not read vud file" << endl;
00091 CHECKNDELETE(volume);
00092 return false;
00093 }
00094
00095 dword SIZE = (tf == NULL) ? 1 : 3;
00096 dword dim1 = volume->getDim1Size();
00097 dword dim2 = volume->getDim2Size();
00098 dword dim3 = volume->getDim3Size();
00099 dword len = dim1 * dim2 * dim3;
00100 byte *spatData = new byte[len * SIZE];
00101 byte *d_ptr = spatData;
00102
00103 if (tf != NULL) {
00104 byte *s_ptr = volume->getData();
00105
00106 vuColourRGBa colour;
00107 tf->normalizeAlphaToOne();
00108
00109 for (dword j=0; j<len; j++) {
00110 tf->getRGBa(*(s_ptr++), colour);
00111 for (dword i=0; i<SIZE; i++) {
00112 *(d_ptr++) = (byte)(255 * colour[i]);
00113 }
00114 }
00115 }
00116 else {
00117 byte *s_ptr = volume->getData();
00118 for (dword i=0; i<len; i++) *(d_ptr++) = *(s_ptr++);
00119 }
00120
00121 CHECKNDELETE(volume);
00122
00123 {
00124 bool result;
00125
00126 switch (SIZE) {
00127 case 1: {
00128 vuFourierVolume_IO<1> fourierVolume;
00129 fourierVolume.preprocessSpatialInput(spatData, dim1, dim2, dim3,
00130 1.0, M_SQRT2, 0, false);
00131 CHECKNDELETE(spatData);
00132 result = fourierVolume.scaleAndWriteToFourierFile(outputFile, scale);
00133 break;
00134 }
00135 case 3: {
00136 vuFourierVolume_IO<3> fourierVolume;
00137 fourierVolume.preprocessSpatialInput(spatData, dim1, dim2, dim3,
00138 1.0, M_SQRT2, 0, false);
00139 CHECKNDELETE(spatData);
00140 result = fourierVolume.scaleAndWriteToFourierFile(outputFile, scale);
00141 break;
00142 }
00143 default: cerr << "vuSimpleFVR::convertVUD2VUF() case not implemented!";
00144 cerr << endl;
00145 return false;
00146 };
00147 return result;
00148 }
00149 }
00150
00151 bool vu1112119::convertVUF2VUD(vuString inputFile, vuString outputFile,
00152 float scale)
00153 {
00154 byte *volume = NULL;
00155 dword XSize, YSize, ZSize;
00156 bool status;
00157
00158 status = vuFourierVolume_IO<1>::getSpatialDataFromVUF(volume,
00159 XSize, YSize, ZSize,
00160 scale, inputFile);
00161 if (status) {
00162 vu11121 spatialVolume(volume, XSize, YSize, ZSize);
00163
00164 spatialVolume.setFileName(outputFile);
00165 spatialVolume.write();
00166 }
00167 else {
00168 CHECKNDELETE(volume);
00169 }
00170 return status;
00171 }
00172
00173 #if 0
00174 bool vu1112119::writeFrequencyData2VUD(float *freqData, vuString outputFile)
00175 {
00176 byte *volume = NULL;
00177 dword XSize, YSize, ZSize;
00178 bool status;
00179
00180 status = vuFourierVolume_IO<1>::getSpatialDataFromVUF(volume,
00181 XSize, YSize, ZSize,
00182 scale, inputFile);
00183 if (status) {
00184 vu11121 spatialVolume(volume, XSize, YSize, ZSize);
00185
00186 spatialVolume.setFileName(outputFile);
00187 spatialVolume.write();
00188 }
00189 else {
00190 CHECKNDELETE(volume);
00191 }
00192 return status;
00193 }
00194 #endif