FileReader Class Reference

a class for reading information from S3D and passing data into structs More...

#include <filereader.h>

List of all members.

Public Member Functions

 FileReader ()
 The Constructor.
 ~FileReader ()
 The Destructor.
int getColorFormat ()
 return ColorFormat
int getNRow ()
 return number of rows
int getNCol ()
 return number of columns
int getNp ()
 return number of pixels
int getEncoding ()
 return encoding
int getInfo2d ()
 return color information of 3d point
char getColor ()
 return black and white color
char getR ()
 return red portion
char getG ()
 return green portion
char getB ()
 return blue portion
float getX ()
 return x coordinate
float getY ()
 return y coordinate
float getZ ()
 return z coordinate
QString getColorText ()
 return color format description
QString getInfo ()
 return s3d header information
void readFile (QString &fileName)
 reading s3d file function

Public Attributes

GLubyte imagePixels [MAXPIXELHEIGHT][MAXPIXELWIDTH][3]
 pixel array of reference image
float pointArray [1048576][6]
 array for 3d points


Detailed Description

a class for reading information from S3D and passing data into structs

Definition at line 98 of file filereader.h.


Constructor & Destructor Documentation

FileReader::FileReader  ) 
 

The Constructor.

Definition at line 39 of file filereader.cpp.

00040 {
00041 }

FileReader::~FileReader  ) 
 

The Destructor.

Definition at line 44 of file filereader.cpp.

00045 {
00046 }


Member Function Documentation

char FileReader::getB  ) 
 

return blue portion

Returns:
image_color->b

Definition at line 281 of file filereader.cpp.

References TPixelColor::b.

00282 {
00283     return image_color->b;
00284 }

char FileReader::getColor  ) 
 

return black and white color

Returns:
image_bw->color

Definition at line 254 of file filereader.cpp.

References TPixelBW::color.

00255 {
00256     return image_bw->color;
00257 }

int FileReader::getColorFormat  ) 
 

return ColorFormat

Returns:
head->colorFormat

Definition at line 200 of file filereader.cpp.

References S3DHead::colorFormat.

00201 {
00202     return head->colorFormat;
00203 }

QString FileReader::getColorText  ) 
 

return color format description

Returns:
colorFormatText

Definition at line 209 of file filereader.cpp.

Referenced by MainWidget::openFile().

00210 {
00211     return colorFormatText;
00212 }

int FileReader::getEncoding  ) 
 

return encoding

Returns:
head->encoding

Definition at line 245 of file filereader.cpp.

References S3DHead::encoding.

Referenced by MainWidget::openFile(), and Point3dWidget::paintGL().

00246 {
00247     return head->encoding;
00248 }

char FileReader::getG  ) 
 

return green portion

Returns:
image_color->g

Definition at line 272 of file filereader.cpp.

References TPixelColor::g.

00273 {
00274     return image_color->g;
00275 }

QString FileReader::getInfo  ) 
 

return s3d header information

Returns:
head->info

Definition at line 191 of file filereader.cpp.

References S3DHead::info.

Referenced by MainWidget::openFile().

00192 {
00193     return QString( head->info );
00194 }

int FileReader::getInfo2d  ) 
 

return color information of 3d point

Returns:
points->info2d

Definition at line 317 of file filereader.cpp.

References TPoint3D::info2d.

00318 {
00319     return points->info2d;
00320 }

int FileReader::getNCol  ) 
 

return number of columns

Returns:
head->ncol

Definition at line 227 of file filereader.cpp.

References S3DHead::ncol.

Referenced by MainWidget::openFile(), and RefImgWidget::paintGL().

00228 {
00229     return head->ncol;
00230 }

int FileReader::getNp  ) 
 

return number of pixels

Returns:
head->np

Definition at line 236 of file filereader.cpp.

References S3DHead::np.

Referenced by MainWidget::openFile(), and Point3dWidget::paintGL().

00237 {
00238     return head->np;
00239 }

int FileReader::getNRow  ) 
 

return number of rows

Returns:
head->nrow

Definition at line 218 of file filereader.cpp.

References S3DHead::nrow.

Referenced by MainWidget::openFile(), and RefImgWidget::paintGL().

00219 {
00220     return head->nrow;
00221 }

char FileReader::getR  ) 
 

return red portion

Returns:
image_color->r

Definition at line 263 of file filereader.cpp.

References TPixelColor::r.

00264 {
00265     return image_color->r;
00266 }

float FileReader::getX  ) 
 

return x coordinate

Returns:
points->x

Definition at line 290 of file filereader.cpp.

References TPoint3D::x.

00291 {
00292     return points->x;
00293 }

float FileReader::getY  ) 
 

return y coordinate

Returns:
points->y

Definition at line 299 of file filereader.cpp.

References TPoint3D::y.

00300 {
00301     return points->y;
00302 }

float FileReader::getZ  ) 
 

return z coordinate

Returns:
points->z

Definition at line 308 of file filereader.cpp.

References TPoint3D::z.

00309 {
00310     return points->z;
00311 }

void FileReader::readFile QString &  fileName  ) 
 

reading s3d file function

Parameters:
fileName string
Returns:
void

Definition at line 53 of file filereader.cpp.

References TPixelColor::b, TPixelBW::color, S3DHead::colorFormat, S3DHead::encoding, TPixelColor::g, imagePixels, TPoint3D::info2d, S3DHead::ncol, S3DHead::np, S3DHead::nrow, pointArray, TPixelColor::r, TPoint3D::x, TPoint3D::y, and TPoint3D::z.

Referenced by MainWidget::openFile().

00054 {
00055     // convert fileName to string
00056     const char *file = fileName.toLatin1 ();
00057 
00058     // open file under READ ONLY mode
00059     int fich=open(file,O_RDONLY);
00060     if(fich<0){
00061         qDebug("Error: file not found.");
00062         return;
00063     }
00064 
00065     // initiate head structure
00066     head=(S3DHead*)malloc(sizeof(S3DHead));
00067     // number of bytes read
00068     int br=read(fich,head,sizeof(S3DHead)); 
00069 
00070     // error reading control
00071     if(br!=sizeof(S3DHead)){
00072         qDebug("Error: file corrupt.");
00073         return;
00074     }
00075 
00076     // Gray image (if the file contains it)
00077     if(head->encoding==0 && head->colorFormat==0){
00078         int npix=head->nrow*head->ncol;
00079         image_bw=(TPixelBW*)malloc(sizeof(TPixelBW)*npix);
00080         br=read(fich,image_bw,sizeof(TPixelBW)*npix);
00081 
00082         //error reading control
00083         if(br!=(int)sizeof(TPixelBW)*npix){
00084             qDebug("Error: file corrupt.");
00085             return;
00086         }
00087     }
00088 
00089     // color format for info purpose
00090     if(head->colorFormat == 0)
00091         colorFormatText = "Black and White";
00092     else
00093         colorFormatText = "Color RGB";
00094 
00095     // Color image (if the file contains it)
00096     TPixelColor *image_color=NULL;
00097     if(head->encoding==0 && head->colorFormat==1){
00098         int npix=head->nrow*head->ncol;
00099         image_color=(TPixelColor*)malloc(sizeof(TPixelColor)*npix);
00100         br=read(fich,image_color,sizeof(TPixelColor)*npix);
00101 
00102         // error reading control
00103         if(br!=(int)sizeof(TPixelColor)*npix){
00104             qDebug("Error: file corrupt.");
00105             return;
00106         }
00107     }
00108 
00109     // 3D Points
00110     TPoint3D *points=NULL;
00111     if(head->np>0){
00112         points=(TPoint3D*)malloc(sizeof(TPoint3D)*head->np);
00113         br=read(fich,points,sizeof(TPoint3D)*head->np);
00114 
00115         //error reading control
00116         if(br!=(int)sizeof(TPoint3D)*head->np){
00117             if(image_bw) free(image_bw);
00118             if(image_color) free(image_color);
00119             qDebug("Error: file corrupt.");
00120             return;
00121         }
00122     }
00123 
00124     // At this point, we have read all of the file data
00125     close(fich);
00126 
00127     // Image (if exists)
00128     if(head->encoding==0){
00129         for(int i=0;i<head->nrow;i++){
00130             for(int j=0;j<head->ncol;j++){
00131                 if(head->colorFormat==0){ //Black and white case
00132                     TPixelBW p=image_bw[ i*head->ncol+j ];
00133                     imagePixels[i][j][0] = (GLubyte) ( p.color );
00134                     imagePixels[i][j][1] = (GLubyte) ( p.color );
00135                     imagePixels[i][j][2] = (GLubyte) ( p.color );
00136                 }else{                    //Color RGB case
00137                     TPixelColor p=image_color[ i*head->ncol+j ];
00138                     imagePixels[i][j][0] = (GLubyte) ( p.r );
00139                     imagePixels[i][j][1] = (GLubyte) ( p.g );
00140                     imagePixels[i][j][2] = (GLubyte) ( p.b );
00141                 }
00142             }
00143         }
00144     }
00145 
00146     // 3D points
00147     if(head->encoding==0){
00148         for(int i=0;i<head->np;i++){
00149             // we show the 3D coordinates (XYZ) and the image coordinates (IJ) of the points
00150             TPoint3D p=points[i];
00151             pointArray[i][0] = p.x; // x coord
00152             pointArray[i][1] = p.y; // y coord
00153             pointArray[i][2] = p.z; // z coord
00154             pointArray[i][3] = (int) p.info2d/head->ncol; // x reference image coord
00155             pointArray[i][4] = (int) ( p.info2d - pointArray[i][3] * head->ncol ); // y coord
00156         }
00157     }else{
00158         if(head->colorFormat==0){ // point cloud with gray levels
00159             for(int i=0;i<head->np;i++){
00160                 TPoint3D p=points[i];
00161                 pointArray[i][0] = p.x;
00162                 pointArray[i][1] = p.y;
00163                 pointArray[i][2] = p.z;
00164                 pointArray[i][3] = p.info2d;
00165                 pointArray[i][4] = p.info2d;
00166                 pointArray[i][5] = p.info2d;
00167             }
00168         }else{                    // point cloud with color rgb values
00169             for(int i=0;i<head->np;i++){
00170                 TPoint3D p=points[i];
00171                 int r,g,b;
00172                 r=(p.info2d & 0xff0000)>>16;
00173                 g=(p.info2d & 0xff00)>>8;
00174                 b=(p.info2d & 0xff);
00175 
00176                 pointArray[i][0] = p.x;
00177                 pointArray[i][1] = p.y;
00178                 pointArray[i][2] = p.z;
00179                 pointArray[i][3] = r;
00180                 pointArray[i][4] = g;
00181                 pointArray[i][5] = b;
00182             }
00183         }
00184     }
00185 }


Member Data Documentation

GLubyte FileReader::imagePixels[MAXPIXELHEIGHT][MAXPIXELWIDTH][3]
 

pixel array of reference image

Definition at line 121 of file filereader.h.

Referenced by RefImgWidget::paintGL(), and readFile().

float FileReader::pointArray[1048576][6]
 

array for 3d points

Definition at line 122 of file filereader.h.

Referenced by Point3dWidget::paintGL(), and readFile().


The documentation for this class was generated from the following files:
Generated on Mon Aug 14 10:44:20 2006 for S3DViewer by  doxygen 1.4.4