basic/geometry/IGS/IGS_Polygon.cpp

Go to the documentation of this file.
00001 #include "IGS_Controller.h"
00002 #include "IGS_Polygon.h"
00003 #include "math/Matrix4x4.h"
00004 #include "opengl/glos.h"
00005 #include <gl/gl.h>
00006 
00007 //=============================================================================
00008 // AddEdge
00009 //
00010 // Description: adds an edge to the list of edges
00011 //=============================================================================
00012 /*int IGS_Polygon::AddEdge( const int v0, const int v1 )
00013 {
00014         int vertex0 = min( v0, v1 );
00015         int vertex1 = max( v0, v1 );
00016         MeshEdge m;
00017         m.v0 = vertex0;
00018         m.v1 = vertex1;
00019 
00020         //check if the edge already exists - linear search = slow!
00021         int i;
00022         int esize = this->edges.size();
00023         for( i = 0; i < esize; i++ )
00024         {
00025                 MeshEdge& inarray = edges[ i ];
00026                 if( inarray == m )
00027                 {
00028                         return i;
00029                 }
00030         }
00031 
00032         //we couldn't find the edge
00033         this->edges.push_back( m );
00034         return this->edges.size() - 1;
00035 }
00036 */
00037 //=============================================================================
00038 // AddFacet
00039 //
00040 // Description: adds a vertex to the list of points
00041 //=============================================================================
00042 /*int IGS_Polygon::AddFacet( const MeshFacet& facet )
00043 {
00044         this->facets.push_back( facet );
00045         return facets.size();
00046 }
00047 */
00048 //=============================================================================
00049 // AddNormal
00050 //
00051 // Description: adds a vertex to the list of points
00052 //=============================================================================
00053 /*int IGS_Polygon::AddNormal( const Vector4& normal )
00054 {
00055         this->normals.push_back( normal );
00056         return normals.size() - 1;
00057 }
00058 */
00059 //=============================================================================
00060 // AddVertex
00061 //
00062 // Description: adds a vector with the vertex coordinates to the mesh
00063 //=============================================================================
00064 int IGS_Polygon::AddVertex( const Vector4& vector )
00065 {
00066         this->vertexes.push_back( vector );
00067         return vertexes.size();
00068 }
00069 
00070 //=============================================================================
00071 // ClearSilhouetteEdges
00072 //
00073 // Description: clears all the computed silhouette edges from the last frame
00074 //=============================================================================
00075 /*void IGS_Polygon::ClearSilhouetteEdges() const
00076 {
00077         int i;
00078         int esize = this->edges.size();
00079         for( i = 0; i < esize; i++ )
00080         {
00081                 const MeshEdge& e = this->edges[ i ];
00082                 e.ClearSilhouetteInfo();
00083         }
00084 }
00085 */
00086 //=============================================================================
00087 // ComputeNormalsForFacet
00088 //
00089 // Description: computes the facet normal( flat shading ) for a facet
00090 //=============================================================================
00091 /*Vector4 IGS_Polygon::ComputeNormalForFacet( const int facetNum ) const
00092 {
00093         const MeshFacet& f = this->facets[ facetNum ];
00094         int size = this->vertexes.size();
00095 
00096         int i0 = f.GetVertexNum( 0 );
00097         int i1 = f.GetVertexNum( 1 );
00098         int i2 = f.GetVertexNum( 2 );
00099 
00100         const Vector4& v0 = this->GetVertex( i0 );
00101         const Vector4& v1 = this->GetVertex( i1 );
00102         const Vector4& v2 = this->GetVertex( i2 );
00103 
00104         Vector4 normal = ( v1 - v0 ).Cross( v2 - v0 );
00105         double mag = normal.Magnitude();
00106         assert( mag != 0 );
00107         normal.Normalize();
00108         return ( normal );
00109 }
00110 */
00111 //=============================================================================
00112 // GetBoundingBox
00113 //
00114 // Description: returns the bounding XYZ coordinates of the mesh
00115 //=============================================================================
00116 /*void IGS_Polygon::GetBoundingBox( double& xmin, double& xmax, double& ymin, double& ymax, double& zmin, double& zmax ) const
00117 {
00118         //setup the initial min/max
00119         const Vector4& v0 = this->GetVertex( 0 );
00120         xmin = xmax = v0[ 0 ];
00121         ymin = ymax = v0[ 1 ];
00122         zmin = zmax = v0[ 2 ];
00123 
00124         int i;
00125         int vsize = this->vertexes.size();
00126         for( i = 0; i < vsize; i++ )
00127         {
00128                 const Vector4& v = this->GetVertex( i );
00129                 xmin = min( xmin, v[ 0 ] );
00130                 ymin = min( ymin, v[ 1 ] );
00131                 zmin = min( zmin, v[ 2 ] );
00132 
00133                 xmax = max( xmax, v[ 0 ] );
00134                 ymax = max( ymax, v[ 1 ] );
00135                 zmax = max( zmax, v[ 2 ] );
00136         }
00137 }
00138 */
00139 //=============================================================================
00140 // GetNormal
00141 //
00142 // Description: returns the normal at index i
00143 //=============================================================================
00144 /*const Vector4& IGS_Polygon::GetNormal( const int i ) const
00145 {
00146 #ifdef _DEBUG
00147         int size = this->normals.size();
00148         assert( i < size );
00149 #endif
00150         return this->normals[ i ];
00151 }
00152 */
00153 //=============================================================================
00154 // GetVertex
00155 //
00156 // Description: gets a constant reference to a particular vertex
00157 //=============================================================================
00158 /*const Vector4& IGS_Polygon::GetVertex( const int i ) const
00159 {
00160 #ifdef _DEBUG
00161         int size = this->vertexes.size();
00162         assert( i < size );
00163 #endif
00164         return this->vertexes[ i ];
00165 }
00166 */
00167 //=============================================================================
00168 // Prepare
00169 //
00170 // Description: adds flat shaded normals to the object if it needs them
00171 //=============================================================================
00172 void IGS_Polygon::Prepare( const IGS_Controller& controller )
00173 {
00174         //do nothing
00175 }
00176 
00177 //=============================================================================
00178 // Render
00179 //
00180 // Description: renders the mesh to an openGl context
00181 //=============================================================================
00182 void IGS_Polygon::Render( const IGS_Controller& controller ) const
00183 {
00184         ::glBegin( GL_LINE_STRIP );
00185         {
00186                 int i;
00187                 for( i = 0; i < this->vertexes.size(); i++ )
00188                 {
00189                         const Vector4& vector = vertexes[ i ];
00190                         ::glVertex3d( vector[ 0 ], vector[ 1 ], vector[ 2 ] );
00191                 }
00192                 const Vector4& vector = vertexes[ 0 ];
00193                 ::glVertex3d( vector[ 0 ], vector[ 1 ], vector[ 2 ] );
00194 
00195         }
00196         ::glEnd();
00197 }
00198 
00199 //=============================================================================
00200 // constructor
00201 //
00202 // Description: constructor
00203 //=============================================================================
00204 /*MeshEdge::MeshEdge():
00205         mRenderedForward( false ),
00206         mRenderedReverse( false ),
00207         mTimesRendered( 0 )
00208 {
00209 }
00210 */
00211 //=============================================================================
00212 // operator==
00213 //
00214 // Description: comparison on two mesh edges
00215 //=============================================================================
00216 /*bool MeshEdge::operator==( const MeshEdge& right ) const
00217 {
00218         if( v0 != right.v0 )
00219         {
00220                 return false;
00221         }
00222         if( v1 != right.v1 )
00223         {
00224                 return false;
00225         }
00226         return true;
00227 }
00228 */
00229 //=============================================================================
00230 // ClearSilhouetteInfo
00231 //
00232 // Description: removes all cached silhouete info
00233 //=============================================================================
00234 /*void MeshEdge::ClearSilhouetteInfo() const
00235 {
00236         this->mTimesRendered = 0;
00237         this->mRenderedForward = false;
00238         this->mRenderedReverse = false;
00239 }
00240 */
00241 //=============================================================================
00242 // IsSilhouette
00243 //
00244 // Description: determines if an edge has been flagged as a silhouette or not
00245 //=============================================================================
00246 /*bool MeshEdge::IsSilhouette() const
00247 {
00248         if( ( this->mRenderedForward == true ) && ( this->mRenderedReverse == true ) )
00249         {
00250                 return true;
00251         }
00252         if( this->mTimesRendered != 2 )
00253         {
00254 //              assert( this->mTimesRendered == 2 );
00255                 return true;
00256         }
00257         return false;
00258 }
00259 */
00260 //=============================================================================
00261 // MarkFrontFacing
00262 //
00263 // Description: marks an edge as front facing
00264 //=============================================================================
00265 /*void MeshEdge::MarkFrontFacing() const
00266 {
00267         this->mTimesRendered++;
00268         this->mRenderedForward = true;
00269 }
00270 */
00271 //=============================================================================
00272 // MarkBackFacing
00273 //
00274 // Description: marks an edge as back facing
00275 //=============================================================================
00276 /*void MeshEdge::MarkBackFacing() const
00277 {
00278         this->mTimesRendered++;
00279         this->mRenderedReverse = true ;
00280 }
00281 */
00282 
00283 //=============================================================================
00284 // AddEdgeIndex
00285 //
00286 // Description: adds an edge index to this facet of a mesh
00287 //=============================================================================
00288 /*void MeshFacet::AddEdgeIndex( const int index )
00289 {
00290         //check to see if this edge already exists
00291         int i;
00292         int esize = this->edgeNums.size();
00293         for( i = 0; i < esize; i++ )
00294         {
00295                 int inarray = this->edgeNums[ i ];
00296                 if( index == inarray )
00297                 {
00298                         return;
00299                 }
00300         }
00301 
00302         this->edgeNums.push_back( index );       
00303 }
00304 */
00305 //=============================================================================
00306 // AddNormalIndex
00307 //
00308 // Description: adds a normal index to a facet
00309 //=============================================================================
00310 /*void MeshFacet::AddNormalIndex( const int index )
00311 {
00312         this->normalNums.push_back( index );
00313 }
00314 */
00315 //=============================================================================
00316 // AddVertexIndex
00317 //
00318 // Description: adds a vertex index to a facet
00319 //=============================================================================
00320 /*void MeshFacet::AddVertexIndex( const int index )
00321 {
00322         this->vertexNums.push_back( index );
00323 }
00324 */
00325 //=============================================================================
00326 // Clear
00327 //
00328 // Description: clears all the data out of the facet
00329 //=============================================================================
00330 /*void MeshFacet::Clear()
00331 {
00332         this->vertexNums.clear();
00333 }
00334 */
00335 //=============================================================================
00336 // ClearNormals
00337 //
00338 // Description: clears all the data about the normals
00339 //=============================================================================
00340 /*void MeshFacet::ClearNormals()
00341 {
00342         this->normalNums.clear();
00343         this->normalNums.reserve( this->Size() );
00344 }
00345 */
00346 //=============================================================================
00347 // GetNormalNum
00348 //
00349 // Description: gets the index of thr normal for vertex i
00350 //=============================================================================
00351 /*int MeshFacet::GetNormalNum( const int i ) const
00352 {
00353 #ifdef _DEBUG
00354         int size = this->normalNums.size();
00355         assert( i < size );
00356 #endif
00357         return this->normalNums[ i ];
00358 }
00359 */
00360 //=============================================================================
00361 // GetVertexNum
00362 //
00363 // Description: gets the index of the vertex for vertex i
00364 //=============================================================================
00365 /*int MeshFacet::GetVertexNum( const int i ) const
00366 {
00367 #ifdef _DEBUG
00368         int size = this->vertexNums.size();
00369         assert( i < size );
00370 #endif
00371         return this->vertexNums[ i ];
00372 }
00373 */
00374 //=============================================================================
00375 // MarkFrontFacing
00376 //
00377 // Description: marks all the edges associated with this mesh as being front 
00378 //                              facing
00379 //=============================================================================
00380 /*void MeshFacet::MarkFrontFacing( const IGS_Polygon* parent ) const 
00381 {
00382         int i;
00383         int esize = this->edgeNums.size();
00384         int vsize = this->vertexNums.size();
00385         for( i = 0; i < esize; i++ )
00386         {
00387                 int index = this->edgeNums[ i ];
00388                 parent->edges[ index ].MarkFrontFacing();
00389         }
00390 }
00391 */
00392 //=============================================================================
00393 // MarkBackFacing
00394 //
00395 // Description: marks all the edges associated with this mesh as being front 
00396 //                              facing
00397 //=============================================================================
00398 /*void MeshFacet::MarkBackFacing( const IGS_Polygon* parent ) const
00399 {
00400         int i;
00401         int esize = this->edgeNums.size();
00402         int vsize = this->vertexNums.size();
00403         for( i = 0; i < esize; i++ )
00404         {
00405                 int index = this->edgeNums[ i ];
00406                 parent->edges[ index ].MarkBackFacing();
00407         }
00408 }
00409 */
00410 
00411 //=============================================================================
00412 // Size
00413 //
00414 // Description: determines how many verteces are int this facet
00415 //=============================================================================
00416 /*int MeshFacet::Size() const
00417 {
00418         return this->vertexNums.size();
00419 }
00420 */

Generated on Sat Apr 1 21:30:32 2006 for Motion Planning Kernel by  doxygen 1.4.6-NO