Documentation


OctreeEngine.cpp

Go to the documentation of this file.
00001 //
00002 // C++ Implementation: OctreeEngine
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 "OctreeEngine.h"
00013 #include <iostream>
00014 using std::cerr;
00015 using std::endl;
00016 #include "ConstrainedVertex.h"
00017 
00018 
00019 
00020 namespace animal
00021 {
00022 
00023 namespace octree
00024 {
00025 
00026 
00027 /*void incrementNumberOfNodes( int& freeNodes, int& constrainedNodes )*/
00028 
00029 
00030 OctreeEngine::OctreeEngine(Vec3d bboxMin, Vec3d bboxMax, MFVec3f *points, MFVec3f normals, unsigned int nMaxPointsPerCell)
00031         : Octree(bboxMin, bboxMax, points, normals, nMaxPointsPerCell)
00032         , _time(0)
00033 {}
00034 
00035 
00036 OctreeEngine::~OctreeEngine()
00037 {}
00038 
00039 void OctreeEngine::init( )
00040 {
00041     //cerr<<"--------------------------------------------------OctreeEngine::init( )"<<endl;
00042     v_assign( ConstrainedVertex::VEL, Vec3d(0,1,0) );
00043     writePositionsTo( ConstrainedVertex::POS );
00044 }
00045 
00046 void OctreeEngine::move( double dt )
00047 {
00048     //cerr<<"==================  OctreeEngine::move, dt = "<< dt << endl;
00049     _time += dt;
00050     v_eq_a_plus_alpha_b( ConstrainedVertex::POS, ConstrainedVertex::POS, dt, ConstrainedVertex::VEL );
00051     readPositionsFrom( ConstrainedVertex::POS );
00052     movedRecLeaves( root_ );
00053 }
00054 
00055 void OctreeEngine::v_eq( int target_value_id, int a)
00056 {
00057     for( Cell::vertex_width_iterator it( root_ ) ; !it.empty() ; )
00058     {
00059         ConstrainedVertex* v = ++it;
00060         v->setValue(target_value_id,v->value(a));
00061     }
00062 }
00063 
00064 void OctreeEngine::v_assign( int target_value_id, const Vec3d& a)
00065 {
00066     for( Cell::vertex_width_iterator it( root_ ) ; !it.empty() ; )
00067     {
00068         ConstrainedVertex* v = ++it;
00069         v->setValue(target_value_id,a);
00070     }
00071 }
00072 
00073 void OctreeEngine::v_eq_a_plus_alpha_b( int target, int a, FloatingPointType alpha, int b )
00074 {
00075     for( Cell::vertex_width_iterator it( root_ ) ; !it.empty() ; )
00076     {
00077         ConstrainedVertex* v = ++it;
00078         //cerr<<"OctreeEngine::v_eq_a_plus_alpha_b, old value= "<< v->value(target) <<endl;
00079         if( v->isFree() )
00080         {
00081             //cerr<<"OctreeEngine::v_eq_a_plus_alpha_b, b = "<<v->value(b)<<endl;
00082             v->setValue(target, v->value(a) + v->value(b) * alpha );
00083         }
00084         else
00085         {
00086             v->computeValueFromParents(target);
00087         }
00088         //cerr<<"OctreeEngine::v_eq_a_plus_alpha_b, new value= "<< v->value(target) <<endl;
00089     }
00090 }
00091 
00092 void OctreeEngine::readPositionsFrom(int target)
00093 {
00094     for( Cell::vertex_width_iterator it( root_ ) ; !it.empty() ; )
00095     {
00096         ConstrainedVertex* v = ++it;
00097         if( v->isFree() )
00098         {
00099             v->setPosition(v->value(target));
00100         }
00101         else
00102         {
00103             v->setPosition(v->computePosition());
00104         }
00105         //cerr<<"OctreeEngine::move, vertex_width_iterator visits at depth = "<<v->getDepth()<<endl;
00106 
00107 
00108         //nVertices++;
00109     }
00110 
00111 }
00112 
00113 
00114 void OctreeEngine::writePositionsTo(int target)
00115 {
00116     //     for( read_position_iterator it( root_,target ); !it.empty(); ++it )
00117     //         ;
00118     for( Cell::vertex_width_iterator it( root_ ) ; !it.empty() ; )
00119     {
00120         ConstrainedVertex* v = ++it;
00121         if( v->isFree() )
00122         {
00123             v->setValue(target,v->getPosition());
00124         }
00125         else
00126         {
00127             v->computeValueFromParents(target);
00128         }
00129         //cerr<<"OctreeEngine::move, vertex_width_iterator visits at depth = "<<v->getDepth()<<endl;
00130 
00131 
00132         //nVertices++;
00133     }
00134 
00135 }
00136 
00137 }
00138 ;
00139 
00140 };
00141 

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