Main Page | Namespace List | Class Hierarchy | Class List | Directories | File List | Class Members | File Members | Related Pages

vpcutplane.cpp

Go to the documentation of this file.
00001 //deprecated
00003 //
00004 //  PROJECT.....: vpat - Creating Virtual Patients
00005 //  RESPONSIBLE.: Carla Freitas e Luciana Nedel
00006 //
00007 //  FILE........: vpcutplane.cpp
00008 //  DESCRIPTION.: Contain the VPCutPlane class implementation.
00009 //
00010 //  AUTHOR......: Fernando Sola Pereira
00011 //  DATE........: January/23/2001
00012 //  DESCRIPTION.: Implementation of class methods.
00013 //
00014 //  AUTHOR......: Isabel Harb Manssour
00015 //  DATE........: March/01/2001
00016 //  DESCRIPTION.: File and variables rename.
00017 //
00019 
00020 
00021 #include <vpcutplane.h>
00022 
00023 
00025 // Description: Class "VPCutPlane" constructor without parameter.
00026 // Parameters.: -
00027 // Return.....: -
00028 
00029 VPCutPlane::VPCutPlane() {
00030 
00031 }
00032 
00033 
00035 // Description: Class "VPCutPlane" constructor with parameter.
00036 // Parameters.: VPBoundingBox b (bounding box of the volume that
00037 //                               will be cut)
00038 // Return.....: -
00039 
00040 VPCutPlane::VPCutPlane(VPBoundingBox b) {
00041     boundingBox = b;
00042     vpPlaneComputation();
00043 }
00044 
00045 
00047 // Description: 
00048 // Parameters.: 
00049 // Return.....: -                   
00050 
00051 void VPCutPlane::vpSetBoundingBox(VPBoundingBox b) {
00052     boundingBox = b;
00053     vpPlaneComputation();
00054 }
00055 
00056 
00058 // Description: Method "vpGetNormal" returns the value of "normal"
00059 //              attribute.
00060 // Parameters.: -
00061 // Return.....: VPVector3D normal
00062 
00063 VPVector3D VPCutPlane::vpGetNormal(void) {
00064     return normal;
00065 }
00066 
00067 
00069 // Description: 
00070 // Parameters.: 
00071 // Return.....: 
00072 
00073 void VPCutPlane::vpPlaneComputation(void) {
00074     float maiorX,maiorY,maiorZ,menorX,menorY,menorZ,aux;
00075     float cx,cy,cz;
00076 
00077     cx = boundingBox.vpGetCenter()->vpGetX();
00078     cy = boundingBox.vpGetCenter()->vpGetY();
00079     cz = boundingBox.vpGetCenter()->vpGetZ();
00080 
00081     maiorX = boundingBox.vpGetGreaterX();
00082     maiorY = boundingBox.vpGetGreaterY();
00083     maiorZ = boundingBox.vpGetGreaterZ();
00084     menorX = boundingBox.vpGetSmallerX();
00085     menorY = boundingBox.vpGetSmallerY();
00086     menorZ = boundingBox.vpGetSmallerZ();
00087 
00088     if((maiorX)>(maiorY))
00089     {
00090         if((maiorX)>(maiorZ))
00091             aux = maiorX - cx;
00092         else
00093             aux = maiorZ - cz;
00094     }
00095     else
00096     {
00097         if((maiorY)>(maiorZ))
00098             aux = maiorY - cy;
00099         else
00100             aux = maiorZ - cz;
00101     }
00102 
00103     plane[0] = VPPoint3D(cx-aux,cy,cz-aux);
00104     plane[1] = VPPoint3D(cx+aux,cy,cz-aux);
00105     plane[2] = VPPoint3D(cx+aux,cy+(aux/2),cz+aux);
00106     plane[3] = VPPoint3D(cx-aux,cy+(aux/2),cz+aux);
00107 
00108     vpNormalComputation
00109             (plane[0].vpGetX(),plane[0].vpGetY(),plane[0].vpGetZ(),
00110              plane[1].vpGetX(),plane[1].vpGetY(),plane[1].vpGetZ(),
00111              plane[2].vpGetX(),plane[2].vpGetY(),plane[2].vpGetZ());
00112 }
00113 
00114 
00116 // Description: Method "vpNormalComputation" process the normal 
00117 //              attribute value.
00118 // Parameters.: 
00119 // Return.....: -
00120 
00121 void VPCutPlane::vpNormalComputation(float x1,float y1,float z1,
00122                                 float x2,float y2,float z2,
00123                                 float x3,float y3,float z3){
00124 
00125     float vax, vay, vaz, vbx, vby, vbz, nx, ny, nz;
00126     float modulo;
00127 
00128     // normal vector computation: N=(v2-v1)x(v3-v1)
00129 
00130     vax = x2-x1; //vector A va = (v2-v1)
00131     vay = y2-y1;
00132     vaz = z2-z1;
00133 
00134     vbx = x3-x1; //vector B vb = (v3-v1)
00135     vby = y3-y1;
00136     vbz = z3-z1;
00137 
00138     nx = (vay*vbz) - (vaz*vby);
00139     ny = (vaz*vbx) - (vax*vbz);
00140     nz = (vax*vby) - (vay*vbx);
00141 
00142     modulo = (float) sqrt(nx*nx + ny*ny + nz*nz);
00143     
00144     nx = nx / modulo;
00145     ny = ny / modulo;
00146     nz = nz / modulo;
00147 
00148     normal.vpSetVector3D(nx,ny,nz);
00149 }
00150 
00151 
00153 // Description: 
00154 // Parameters.: 
00155 // Return.....: 
00156 
00157 VPRotation* VPCutPlane::vpGetRotation(void){
00158     return &rotation;
00159 }
00160 
00161 
00163 // Description: 
00164 // Parameters.: 
00165 // Return.....: 
00166 
00167 VPTranslation* VPCutPlane::vpGetTranslation(void){
00168     return &translation;
00169 }
00170 
00171 
00173 // Description: 
00174 // Parameters.: 
00175 // Return.....: 
00176 void VPCutPlane::vpRender(void){
00177 
00178     glPushMatrix();
00179         glTranslatef(translation.vpGetPositionX(),0.0,0.0);
00180         glTranslatef(0.0,-translation.vpGetPositionY(),0.0);
00181         
00182         glPushMatrix();
00183             glRotatef(rotation.vpGetAngleX(),0.0,1.0,0.0);
00184             glRotatef(rotation.vpGetAngleY(),1.0,0.0,0.0);
00185 
00186             glPushMatrix();
00187                 glBegin(GL_QUADS);
00188                     glColor3ub(150,200,200);
00189                     glNormal3f(normal.vpGetVector3DX(),normal.vpGetVector3DY(),normal.vpGetVector3DZ());
00190                     glVertex3f(plane[0].vpGetX(),plane[0].vpGetY(),plane[0].vpGetZ());
00191                     glVertex3f(plane[1].vpGetX(),plane[1].vpGetY(),plane[1].vpGetZ());
00192                     glVertex3f(plane[2].vpGetX(),plane[2].vpGetY(),plane[2].vpGetZ());
00193                     glVertex3f(plane[3].vpGetX(),plane[3].vpGetY(),plane[3].vpGetZ());
00194                 glEnd();
00195             glPopMatrix();
00196         glPopMatrix();
00197     glPopMatrix();
00198 
00199 }
00200 
00201 
00203 // Description: 
00204 // Parameters.: 
00205 // Return.....: 
00206 
00207 void VPCutPlane::vpDComputation(void){
00208     float nx,ny,nz;
00209 
00210     nx = normal.vpGetVector3DX();
00211     ny = normal.vpGetVector3DY();
00212     nz = normal.vpGetVector3DZ();
00213 
00214     nD = -(nx*plane[0].vpGetX() + ny*plane[0].vpGetY() + nz*plane[0].vpGetZ());
00215 }
00216 
00217 
00219 // Description: 
00220 // Parameters.: 
00221 // Return.....: 
00222 
00223 float VPCutPlane::vpGetD(){
00224     return nD;
00225 }
00226 

Generated on Tue Sep 6 10:00:03 2005 for VPAT by  doxygen 1.4.4