Documentation


ManipulatedMeshVertex.cpp

Go to the documentation of this file.
00001 //
00002 // C++ Implementation: ManipulatedMeshVertex
00003 //
00004 // Description: 
00005 //
00006 //
00007 // Author: François Faure <>, (C) 2004
00008 //
00009 // Copyright: See COPYING file that comes with this distribution
00010 //
00011 //
00012 #include "ManipulatedMeshVertex.h"
00013 #include "assertions.h"
00014 #include <GL/glut.h>
00015 
00016 namespace animal {
00017 
00018 namespace octree {
00019 
00020 /*
00021 ManipulatedMeshVertex::ManipulatedMeshVertex( Octree *octree, SFVec3fCellConstrained * vertex ) :
00022     _octree(octree)
00023     , _vertex(vertex)
00024 {
00025     Require( _octree );
00026     Require( _vertex );
00027 }
00028 */
00029 
00030 ManipulatedMeshVertex::ManipulatedMeshVertex( X3DTK::X3D::DeformableOctreeNode *dosn, const X3DTK::SFVec3f *meshVertex ) :
00031     _dosn(dosn)
00032 {
00033     Octree *octree = dosn->getOctree();
00034     
00035     Require( octree );
00036     
00037     _vertex = NULL;
00038     
00039     // First find in the root the SFConstrainedVertex
00040     Cell *cell = octree->root();
00041 
00042     if( cell->isLeaf() )
00043     {
00044         OctreeDataPoints::iterator it;
00045         for( it = cell->getData()._points.begin() ; 
00046             it != cell->getData()._points.end() ;
00047             ++it )
00048         {
00049             if( (*it)->getSFVec3f() == meshVertex)
00050             {
00051                 _vertex = *it;
00052                 break;
00053             }
00054         }
00055         Require( _vertex );
00056     }
00057     else
00058     {
00059         while( !cell->isLeaf() )
00060         {   
00061             std::cerr << "Searching from cell : " << *cell << "\n";
00062             
00063             // Find which of our children contains this vertex
00064             unsigned int i;
00065             _vertex = NULL;
00066             Cell *child = NULL;
00067             for( i=0 ; i<8 ; ++i )
00068             {
00069                 child = cell->child(i);
00070                 //std::cerr << "\tSearching for the vertex in the cell" << cell->child(i) << "\n";
00071                 OctreeDataPoints::iterator it;
00072                 for( it = child->getData()._points.begin() ; 
00073                     it != child->getData()._points.end() ;
00074                     ++it )
00075                 {
00076                     if( (*it)->getSFVec3f() == meshVertex)
00077                     {
00078                         _vertex = *it;
00079                         break;
00080                     }
00081                 }
00082                 if( it != child->getData()._points.end() )
00083                 {
00084                     // We found it
00085                     break;
00086                 }
00087                 
00088             }
00089             // Means that we've found it
00090             Require( i!=8 );
00091             cell = child;
00092             //std::cerr << "\t found child " << i << " cell : " << *cell << "\n";
00093         }
00094     }
00095     
00096     // Now _vertex contains the pointer to the vertex and cell the child
00097     
00098 
00099     /*
00100     // Then find the leaf cell containing this vertex
00101      * With the alpha, beta, gamma
00102      * But this depend on the subdivision scheme
00103      * Beter put this method in the "Octree" class so
00104      * people can understand where to look at the subdivision scheme
00105      */
00106      
00107      _initPos = Vec3d( (*meshVertex)[0], (*meshVertex)[1], (*meshVertex)[2] );
00108      
00109      //std::cerr << "Initposition is " << _initPos << "\n";
00110      
00111     Ensure( _vertex );
00112     
00113 }
00114 
00115 ManipulatedMeshVertex::~ManipulatedMeshVertex()
00116 {
00117     Require( _octree );
00118     _dosn->updateGL();
00119 }
00120 
00122 void ManipulatedMeshVertex::getPoint( float& x, float& y, float& z ) const
00123 {
00124     //std::cerr << "ManipulatedMeshVertex::getPoint( float& x, float& y, float& z )\n";
00125     x = _initPos[0];
00126     y = _initPos[1];
00127     z = _initPos[2];
00128 }
00129     
00130     
00131 void ManipulatedMeshVertex::moveTo( float x, float y, float z )
00132 {
00133     //std::cerr << "ManipulatedMeshVertex::moveTo( " << x << ", " << y << " , " << z << " )\n";
00134     Require( _octree );
00135     Require( _vertex );
00136     _dosn->getOctree()->directManipulation( _vertex, Vec3d(x,y,z) );
00137     _dosn->getOctree()->movedRecLeaves( _dosn->getOctree()->root() );
00138     _dosn->updateGL();
00139     //std::cerr << "\tPosition is now : " << *_vertex->getSFVec3f() << "\n";
00140     /*
00141     (*(_vertex->getSFVec3f()))[0] = _initPos[0]+x;
00142     (*(_vertex->getSFVec3f()))[1] = _initPos[1]+y;
00143     (*(_vertex->getSFVec3f()))[2] = _initPos[2]+z;
00144     */
00145 }
00146 
00147 
00148 bool ManipulatedMeshVertex::operator==( const ConstrainedItem* mmv ) const
00149 {
00150     const ManipulatedMeshVertex* p = dynamic_cast<const ManipulatedMeshVertex*>(mmv);
00151     return p && (_dosn == p->_dosn) && (_vertex == p->_vertex);
00152 }
00153 
00154 void ManipulatedMeshVertex::draw()
00155 {
00156         glPushAttrib( GL_ALL_ATTRIB_BITS );
00157 
00158         glDisable( GL_LIGHTING );
00159         glPolygonMode ( GL_FRONT_AND_BACK, GL_LINE );
00160         glEnable (GL_BLEND);
00161         glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); 
00162     
00163     glPushMatrix();
00164     glPolygonMode( GL_FRONT_AND_BACK, GL_FILL );
00165     glEnable( GL_CULL_FACE );
00166     
00167     X3DTK::SFVec3f pos = *_vertex->getSFVec3f();
00168     glTranslatef( pos[0], pos[1], pos[2] );
00169     glColor4f( 0.0, 0.0 , 1.0, 0.5 );
00170     glutSolidSphere( _dosn->getToolsSize(), 10, 10 );
00171     
00172     glPopMatrix();
00173     glPopAttrib();
00174     
00175 }
00176 
00177 };
00178 
00179 };

Generated on Thu Dec 23 13:52:25 2004 by doxygen 1.3.6