00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018 #ifndef CONSTRAINEDVERTEX_H
00019 #define CONSTRAINEDVERTEX_H
00020
00021 #include <animal/array.h>
00022 #include <vector>
00023 using std::vector;
00024 #include <deque>
00025 using std::deque;
00026 #include <set>
00027
00028 namespace animal
00029 {
00030 namespace octree
00031 {
00032
00033 class ConstrainedVertex;
00034 typedef ConstrainedVertex CVertex;
00035
00036 }
00037 }
00038
00039
00040
00041
00042 #include "fastoctreedeformableconstrained.h"
00043
00044 #include "octree_instanciation.h"
00045 #include "GeoLink.h"
00046 #include "Frame.h"
00047
00048
00049 namespace animal
00050 {
00051 namespace octree
00052 {
00053
00054
00055
00056
00057
00058
00059 class ConstrainedVertex
00060 {
00061 public:
00062
00063
00064
00065
00069 ConstrainedVertex( Vec3d v, CVertex *cv1, CVertex *cv2, CVertex *cv3, CVertex *cv4,
00070 CVertex *cv5, CVertex *cv6, CVertex *cv7, CVertex *cv8,
00071 Cell *connectedCell );
00072
00077 ConstrainedVertex( Vec3d position, Cell *connectedCell );
00078 ConstrainedVertex( FloatingPointType x, FloatingPointType y, FloatingPointType z, Cell *connectedCell );
00079
00080
00081
00082 ConstrainedVertex( const ConstrainedVertex & cmsv );
00083
00084 ConstrainedVertex & operator=( const ConstrainedVertex & cmsv );
00085
00089 ~ConstrainedVertex();
00090
00091
00094 bool isFree() const;
00095
00096
00097
00099 Vec3d get_Vec3d() const;
00100 operator const Vec3d() const;
00101 Vec3d getPosition() const;
00102 void addPosition( Vec3d addPos );
00103
00104
00105
00106
00107
00108
00109 operator const FloatingPointType*();
00110 FloatingPointType operator []( int ) const;
00111
00116 FloatingPointType* get_FloatingPointTypePointerCopy() const;
00117
00118
00119
00120
00121
00122
00123
00124
00125
00126
00127
00132 void updatePosition( ConstrainedVertex* parent, Vec3d v );
00133 void updateChildrensPosition( Vec3d v, unsigned int depth );
00134 void updateChildrensPositionOptimized( Vec3d v, unsigned int depth );
00135 void updateChildrensPositionOptimizedNotFree( Vec3d v );
00136
00137
00138 void updateConstrainedChildrensPosition( Vec3d v, unsigned int depth );
00139
00140 GeoLink* getGeoLink() const;
00141
00142
00146 void freeIt();
00147
00148
00149 Vec3d getParameters( Cell *cStart, unsigned short vId );
00150 Vec3d getParameters( Cell *cStart, unsigned int depth, unsigned short vId );
00151 ConstrainedVertex* getFathersFreeVertex( Cell *cStart, unsigned short vId );
00152 Cell* getFathersFreeVertexCell( Cell *cStart, unsigned short vId );
00153
00154
00155
00156
00157
00158
00159 void softLinkIt( ConstrainedVertex* cv1, ConstrainedVertex* cv2 );
00160 void softLinkIt( ConstrainedVertex* cv1, ConstrainedVertex* cv2, ConstrainedVertex* cv3, ConstrainedVertex* cv4 );
00161 void softLinkIt( ConstrainedVertex* cv1, ConstrainedVertex* cv2, ConstrainedVertex* cv3, ConstrainedVertex* cv4, ConstrainedVertex* cv5, ConstrainedVertex* cv6, ConstrainedVertex* cv7, ConstrainedVertex* cv8 );
00162
00163
00164 void hardLinkIt( ConstrainedVertex* cv1, ConstrainedVertex* cv2, ConstrainedVertex* cv3, ConstrainedVertex* cv4 );
00168 void hardLinkIt( ConstrainedVertex* cv1, ConstrainedVertex* cv2 );
00169
00170
00171
00178 bool isChild( const ConstrainedVertex *cv ) const;
00179
00184 void addChild( ConstrainedVertex *cv );
00189 void removeChild( ConstrainedVertex *cv );
00190
00194 unsigned int getChildPos( ConstrainedVertex *cv ) const;
00195
00199 ConstrainedVertex * child( const unsigned int pos ) const;
00200
00201 unsigned int nChildren() const;
00202 bool isParent( const ConstrainedVertex *cv ) const;
00203
00204
00205
00206
00207
00208
00209
00210
00214 void unregisterCell( const Cell* unconnectedCell );
00218 void registerCell( Cell *connectedCell );
00221 unsigned short nConnectedCells() const;
00223 bool isConnected( const Cell* cell ) const;
00227 Cell* connectedCell( unsigned short id ) const;
00228
00229
00230
00231
00232 Cell* fatherCell() const;
00233
00234
00235
00236
00237 unsigned int getDepth() const;
00238
00239
00240 void setData( const ConstrainedVertexData& d );
00241 ConstrainedVertexData getData( ) const;
00242
00243
00244 void updateFrame();
00245 Frame computeFrame();
00246 Frame & getFrame();
00247
00248
00249 bool hasMainCell( ) const;
00250 void setMainCell( Cell* mainCell, unsigned int vId );
00251 Cell* getMainCell() const;
00252 unsigned short getMainCellVertexId() const
00253 {
00254 return _vertexId;
00255 }
00256
00257
00258 static FloatingPointType getAlpha( Cell *cell, unsigned int faceId, unsigned int vId, unsigned int diffDepth );
00259 static FloatingPointType getBeta( Cell *cell, unsigned int faceId, unsigned int vId, unsigned int diffDepth );
00260 static FloatingPointType getGamma( Cell *cell, unsigned int faceId, unsigned int vId, unsigned int diffDepth );
00261
00262
00263 ConstrainedVertex* getSmallestCellsFreeVertexSharingFaceForVertex( Cell *neighbour, unsigned int face, unsigned int vertex );
00264 Cell* getCellWithFreeVertexConnectedToVertex( Cell *cell, unsigned int direction, unsigned int vertexId ) const;
00265
00266
00270 static std::set
00271 <ConstrainedVertex*> getFreeParentVertices( Cell *cell );
00272
00273
00274 FloatingPointType _mass;
00275
00276 protected:
00277
00278 void copyAllData( const ConstrainedVertex & cmsv );
00279
00280
00281
00286 Vec3d _position;
00287
00288 Vec3d _velocity;
00289
00290
00291
00294 FloatingPointType _positionROPointer[3];
00295
00299 std::vector<ConstrainedVertex*> _childs;
00300
00313 deque<Cell*> _connectedCells;
00314
00315 Cell* _fatherCell;
00316
00317
00318 unsigned short _vertexId;
00319
00320 Cell* _mainCell;
00321
00322
00323 ConstrainedVertexData _data;
00324
00325 GeoLink *_geoLink;
00326
00327 Frame _frame;
00328
00329
00330 static std::deque<unsigned int> getAlphaFactors( Cell *cell, unsigned int faceId, unsigned int depthLeft );
00331 static std::deque<unsigned int> getBetaFactors( Cell *cell, unsigned int faceId, unsigned int depthLeft );
00332 static std::deque<unsigned int> getGammaFactors( Cell *cell, unsigned int faceId, unsigned int depthLeft );
00333
00334
00335
00336 public:
00337
00341 void setPosition( Vec3d newPos );
00342
00346 void setPositionAndPropagate( Vec3d newPos );
00347
00353 void setPositionAndPropagateAll( Vec3d newPos, unsigned int depth );
00354
00358 Vec3d computePosition() const;
00359
00360
00361
00364 Vec3d getDelta() const;
00365 void setDelta( Vec3d d );
00366 Vec3d computeDelta() const;
00367
00368 enum { POS=0, VEL, ACC, VELHALF, NB_AUXILIARY_VECTORS };
00369
00372 Vec3d& value( int value_id );
00373
00376 const Vec3d& value( int value_id ) const;
00377
00381 void setValue( int value_id, Vec3d newPos );
00382
00386 void setValueAndPropagate( int value_id, Vec3d newPos );
00387
00388
00389
00390
00391
00392
00393
00394
00398 Vec3d computeValue( int value_id ) const;
00399
00403 void computeValueFromParents( int value_id );
00404
00408 void computeValueFromRelatives( int value_id );
00409
00410
00411
00412
00413
00414
00415
00419
00420
00421
00422
00423
00424
00428
00429
00430
00431 protected:
00432 animal::Array<NB_AUXILIARY_VECTORS,Vec3d> _aux;
00433 Vec3d _delta;
00434
00435 public:
00436 ConstrainedVertex *_connectedVertices[3][2];
00437 FloatingPointType _connectedVerticesFactors[3][2];
00438
00439
00440 unsigned int getConstrainedDepth() const;
00441 unsigned int _lastConstrainedDepth;
00442 };
00443
00444
00445
00446
00452 class Cell::vertex_connected_iterator
00453 {
00454 public:
00455
00456 vertex_connected_iterator( ConstrainedVertex* vertex, Cell *cell, unsigned int vPos );
00457 ~vertex_connected_iterator();
00458
00459 TempOctree::Vertex* operator++();
00460 bool empty();
00461
00462 private:
00463 std::list<TempOctree::Vertex*> _vList;
00464 };
00465
00466 static std::ostream& operator<<(std::ostream& s, const ConstrainedVertex& v)
00467 {
00468 s << *(v.getMainCell()) << " : " << v.getMainCellVertexId();
00469 return s;
00470 }
00471
00472
00473 }
00474 }
00475
00476 #endif