00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025 #ifndef SOFA_COMPONENT_MAPPING_BARYCENTRICMAPPING_H
00026 #define SOFA_COMPONENT_MAPPING_BARYCENTRICMAPPING_H
00027
00028 #include <sofa/helper/vector.h>
00029 #include <sofa/component/topology/PointData.h>
00030 #include <sofa/component/topology/HexahedronData.h>
00031 #include <sofa/core/componentmodel/topology/BaseMeshTopology.h>
00032 #include <sofa/component/topology/RegularGridTopology.h>
00033
00034
00035 namespace sofa {
00036 namespace core {
00037 namespace componentmodel {
00038 namespace topology {
00039 class BaseTopology;
00040 class BaseMeshTopology;
00041 }
00042 }
00043 }
00044
00045 namespace component {
00046 namespace topology {
00047 class MeshTopology;
00048 class RegularGridTopology;
00049 class SparseGridTopology;
00050 }
00051 }
00052 }
00053
00054 namespace sofa
00055 {
00056
00057 namespace component
00058 {
00059
00060 namespace mapping
00061 {
00062
00063 using core::componentmodel::topology::BaseMeshTopology;
00064
00066 template<class In, class Out>
00067 class BarycentricMapper
00068 {
00069 public:
00070 typedef typename In::Real Real;
00071 typedef typename Out::Real OutReal;
00072
00073 protected:
00074 template< int NC, int NP>
00075 class MappingData
00076 {
00077 public:
00078 int in_index;
00079
00080 Real baryCoords[NC];
00081
00082 inline friend std::istream& operator >> ( std::istream& in, MappingData< NC, NP> &m )
00083 {
00084 in>>m.in_index;
00085 for (int i=0;i<NC;i++) in >> m.baryCoords[i];
00086 return in;
00087 }
00088
00089 inline friend std::ostream& operator << ( std::ostream& out, const MappingData< NC , NP > & m ){
00090 out << m.in_index;
00091 for (int i=0;i<NC;i++)
00092 out << " " << m.baryCoords[i];
00093 return out;
00094 }
00095
00096 };
00097
00098 public:
00099 typedef MappingData<1,2> LineData;
00100 typedef MappingData<2,3> TriangleData;
00101 typedef MappingData<2,4> QuadData;
00102 typedef MappingData<3,4> TetraData;
00103 typedef MappingData<3,8> CubeData;
00104 typedef MappingData<1,0> MappingData1D;
00105 typedef MappingData<2,0> MappingData2D;
00106 typedef MappingData<3,0> MappingData3D;
00107
00108 virtual ~BarycentricMapper(){}
00109 virtual void init(const typename Out::VecCoord& out, const typename In::VecCoord& in) = 0;
00110 virtual void apply( typename Out::VecCoord& out, const typename In::VecCoord& in ) = 0;
00111 virtual void applyJ( typename Out::VecDeriv& out, const typename In::VecDeriv& in ) = 0;
00112 virtual void applyJT( typename In::VecDeriv& out, const typename Out::VecDeriv& in ) = 0;
00113 virtual void applyJT( typename In::VecConst& out, const typename Out::VecConst& in ) = 0;
00114 virtual void draw( const typename Out::VecCoord& out, const typename In::VecCoord& in) = 0;
00115
00116 virtual void clear( int reserve=0 ) =0;
00117
00118
00119 inline friend std::istream& operator >> ( std::istream& in, BarycentricMapper< In, Out > & ) {return in;}
00120 inline friend std::ostream& operator << ( std::ostream& out, const BarycentricMapper< In, Out > & ){ return out; }
00121 };
00122
00124 template<class In, class Out>
00125 class TopologyBarycentricMapper : public BarycentricMapper<In,Out>
00126 {
00127 public:
00128 typedef BarycentricMapper<In,Out> Inherit;
00129 typedef typename Inherit::Real Real;
00130
00131 virtual ~TopologyBarycentricMapper() {}
00132
00133 virtual int addPointInLine(int , const SReal* ) {return 0;}
00134 virtual int createPointInLine(const typename Out::Coord& , int , const typename In::VecCoord* ) {return 0;}
00135
00136 virtual int addPointInTriangle(int , const SReal* ) {return 0;}
00137 virtual int createPointInTriangle(const typename Out::Coord& , int , const typename In::VecCoord* ) {return 0;}
00138
00139 virtual int addPointInQuad(int , const SReal* ) {return 0;}
00140 virtual int createPointInQuad(const typename Out::Coord& , int , const typename In::VecCoord* ) {return 0;}
00141
00142 virtual int addPointInTetra(int , const SReal* ) {return 0;}
00143 virtual int createPointInTetra(const typename Out::Coord& , int , const typename In::VecCoord* ) {return 0;}
00144
00145 virtual int addPointInCube(int , const SReal* ) {return 0;}
00146 virtual int createPointInCube(const typename Out::Coord& , int , const typename In::VecCoord* ) {return 0;}
00147
00148 protected:
00149 TopologyBarycentricMapper(core::componentmodel::topology::BaseMeshTopology* ) {}
00150 };
00151
00153 template<class In, class Out>
00154 class BarycentricMapperRegularGridTopology : public TopologyBarycentricMapper<In,Out>
00155 {
00156 public:
00157 typedef TopologyBarycentricMapper<In,Out> Inherit;
00158 typedef typename Inherit::Real Real;
00159 typedef typename Inherit::OutReal OutReal;
00160 typedef typename Inherit::CubeData CubeData;
00161 protected:
00162 sofa::helper::vector<CubeData> map;
00163 topology::RegularGridTopology* topology;
00164 public:
00165 BarycentricMapperRegularGridTopology(topology::RegularGridTopology* topology)
00166 : TopologyBarycentricMapper<In,Out>(topology),
00167 topology(topology)
00168 {}
00169
00170 virtual ~BarycentricMapperRegularGridTopology(){}
00171
00172 void clear(int reserve=0);
00173 bool isEmpty(){return map.size() == 0;}
00174 void setTopology(topology::RegularGridTopology* topology){topology = topology;}
00175 int addPointInCube(int cubeIndex, const SReal* baryCoords);
00176
00177 void init(const typename Out::VecCoord& out, const typename In::VecCoord& in);
00178
00179 void apply( typename Out::VecCoord& out, const typename In::VecCoord& in );
00180 void applyJ( typename Out::VecDeriv& out, const typename In::VecDeriv& in );
00181 void applyJT( typename In::VecDeriv& out, const typename Out::VecDeriv& in );
00182 void applyJT( typename In::VecConst& out, const typename Out::VecConst& in );
00183 void draw( const typename Out::VecCoord& out, const typename In::VecCoord& in);
00184
00185 inline friend std::istream& operator >> ( std::istream& in, BarycentricMapperRegularGridTopology<In, Out> &b )
00186 {
00187 in >> b.map;
00188 return in;
00189 }
00190
00191 inline friend std::ostream& operator << ( std::ostream& out, const BarycentricMapperRegularGridTopology<In, Out> & b ){
00192 out << b.map;
00193 return out;
00194 }
00195
00196 };
00197
00199 template<class In, class Out>
00200 class BarycentricMapperSparseGridTopology : public TopologyBarycentricMapper<In,Out>
00201 {
00202 public:
00203 typedef TopologyBarycentricMapper<In,Out> Inherit;
00204 typedef typename Inherit::Real Real;
00205 typedef typename Inherit::OutReal OutReal;
00206 typedef typename Inherit::CubeData CubeData;
00207 protected:
00208 sofa::helper::vector<CubeData> map;
00209 topology::SparseGridTopology* topology;
00210 public:
00211 BarycentricMapperSparseGridTopology(topology::SparseGridTopology* topology)
00212 : TopologyBarycentricMapper<In,Out>(topology),
00213 topology(topology)
00214 {}
00215
00216 virtual ~BarycentricMapperSparseGridTopology(){}
00217
00218 void clear(int reserve=0);
00219
00220 int addPointInCube(int cubeIndex, const SReal* baryCoords);
00221
00222 void init(const typename Out::VecCoord& out, const typename In::VecCoord& in);
00223
00224 void apply( typename Out::VecCoord& out, const typename In::VecCoord& in );
00225 void applyJ( typename Out::VecDeriv& out, const typename In::VecDeriv& in );
00226 void applyJT( typename In::VecDeriv& out, const typename Out::VecDeriv& in );
00227 void applyJT( typename In::VecConst& out, const typename Out::VecConst& in );
00228 void draw( const typename Out::VecCoord& out, const typename In::VecCoord& in);
00229
00230 inline friend std::istream& operator >> ( std::istream& in, BarycentricMapperSparseGridTopology<In, Out> &b )
00231 {
00232 in >> b.map;
00233 return in;
00234 }
00235
00236 inline friend std::ostream& operator << ( std::ostream& out, const BarycentricMapperSparseGridTopology<In, Out> & b ){
00237 out << b.map;
00238 return out;
00239 }
00240
00241 };
00242
00243
00245 template<class In, class Out>
00246 class BarycentricMapperMeshTopology : public TopologyBarycentricMapper<In,Out>
00247 {
00248 public:
00249 typedef TopologyBarycentricMapper<In,Out> Inherit;
00250 typedef typename Inherit::Real Real;
00251 typedef typename Inherit::OutReal OutReal;
00252 typedef typename Inherit::MappingData1D MappingData1D;
00253 typedef typename Inherit::MappingData2D MappingData2D;
00254 typedef typename Inherit::MappingData3D MappingData3D;
00255 protected:
00256 sofa::helper::vector< MappingData1D > map1d;
00257 sofa::helper::vector< MappingData2D > map2d;
00258 sofa::helper::vector< MappingData3D > map3d;
00259 BaseMeshTopology* topology;
00260
00261 public:
00262 BarycentricMapperMeshTopology(BaseMeshTopology* topology)
00263 : TopologyBarycentricMapper<In,Out>(topology),
00264 topology(topology)
00265 {}
00266
00267 virtual ~BarycentricMapperMeshTopology(){}
00268
00269 void clear(int reserve=0);
00270
00271 int addPointInLine(int lineIndex, const SReal* baryCoords);
00272 int createPointInLine(const typename Out::Coord& p, int lineIndex, const typename In::VecCoord* points);
00273
00274 int addPointInTriangle(int triangleIndex, const SReal* baryCoords);
00275 int createPointInTriangle(const typename Out::Coord& p, int triangleIndex, const typename In::VecCoord* points);
00276
00277 int addPointInQuad(int quadIndex, const SReal* baryCoords);
00278 int createPointInQuad(const typename Out::Coord& p, int quadIndex, const typename In::VecCoord* points);
00279
00280 int addPointInTetra(int tetraIndex, const SReal* baryCoords);
00281
00282 int addPointInCube(int cubeIndex, const SReal* baryCoords);
00283
00284 void init(const typename Out::VecCoord& out, const typename In::VecCoord& in);
00285
00286 void apply( typename Out::VecCoord& out, const typename In::VecCoord& in );
00287 void applyJ( typename Out::VecDeriv& out, const typename In::VecDeriv& in );
00288 void applyJT( typename In::VecDeriv& out, const typename Out::VecDeriv& in );
00289 void applyJT( typename In::VecConst& out, const typename Out::VecConst& in );
00290 void draw( const typename Out::VecCoord& out, const typename In::VecCoord& in);
00291
00292 inline friend std::istream& operator >> ( std::istream& in, BarycentricMapperMeshTopology<In, Out> &b )
00293 {
00294 unsigned int size_vec;
00295 in >> size_vec;
00296 b.map1d.clear();
00297 MappingData1D value1d;
00298 for (unsigned int i=0;i<size_vec;i++)
00299 {
00300 in >> value1d;
00301 b.map1d.push_back(value1d);
00302 }
00303
00304 in >> size_vec;
00305 b.map2d.clear();
00306 MappingData2D value2d;
00307 for (unsigned int i=0;i<size_vec;i++)
00308 {
00309 in >> value2d;
00310 b.map2d.push_back(value2d);
00311 }
00312
00313 in >> size_vec;
00314 b.map3d.clear();
00315 MappingData3D value3d;
00316 for (unsigned int i=0;i<size_vec;i++)
00317 {
00318 in >> value3d;
00319 b.map3d.push_back(value3d);
00320 }
00321 return in;
00322 }
00323
00324 inline friend std::ostream& operator << ( std::ostream& out, const BarycentricMapperMeshTopology<In, Out> & b ){
00325
00326 out << b.map1d.size();
00327 out << " " ;
00328 out << b.map1d;
00329 out << " " ;
00330 out << b.map2d.size();
00331 out << " " ;
00332 out << b.map2d;
00333 out << " " ;
00334 out << b.map3d.size();
00335 out << " " ;
00336 out << b.map3d;
00337
00338 return out;
00339 }
00340
00341 private:
00342 void clear1d(int reserve=0);
00343 void clear2d(int reserve=0);
00344 void clear3d(int reserve=0);
00345
00346 };
00347
00349 class BarycentricMapperBaseTopology
00350 {
00351 public:
00352 virtual ~BarycentricMapperBaseTopology() {}
00353
00354
00355 virtual void handleTopologyChange()=0;
00356
00357 virtual void handlePointEvents(std::list< const core::componentmodel::topology::TopologyChange *>::const_iterator,
00358 std::list< const core::componentmodel::topology::TopologyChange *>::const_iterator )=0;
00359 protected:
00360 BarycentricMapperBaseTopology(core::componentmodel::topology::BaseMeshTopology* )
00361 {}
00362 };
00363
00364
00366 template<class In, class Out>
00367 class BarycentricMapperEdgeSetTopology : public BarycentricMapperBaseTopology, public TopologyBarycentricMapper<In,Out>
00368 {
00369 public:
00370 typedef TopologyBarycentricMapper<In,Out> Inherit;
00371 typedef typename Inherit::Real Real;
00372 typedef typename Inherit::OutReal OutReal;
00373 typedef typename Inherit::MappingData1D MappingData;
00374 protected:
00375 topology::PointData< MappingData > map;
00376 BaseMeshTopology* topology;
00377
00378 public:
00379 BarycentricMapperEdgeSetTopology(BaseMeshTopology* topology)
00380 : BarycentricMapperBaseTopology(topology), TopologyBarycentricMapper<In,Out>(topology),
00381 topology(topology)
00382 {}
00383
00384 virtual ~BarycentricMapperEdgeSetTopology(){}
00385
00386 void clear(int reserve=0);
00387
00388 int addPointInLine(int edgeIndex, const SReal* baryCoords);
00389 int createPointInLine(const typename Out::Coord& p, int edgeIndex, const typename In::VecCoord* points);
00390
00391 void init(const typename Out::VecCoord& out, const typename In::VecCoord& in);
00392
00393 void apply( typename Out::VecCoord& out, const typename In::VecCoord& in );
00394 void applyJ( typename Out::VecDeriv& out, const typename In::VecDeriv& in );
00395 void applyJT( typename In::VecDeriv& out, const typename Out::VecDeriv& in );
00396 void applyJT( typename In::VecConst& out, const typename Out::VecConst& in );
00397 void draw( const typename Out::VecCoord& out, const typename In::VecCoord& in);
00398
00399
00400 virtual void handleTopologyChange();
00401
00402 virtual void handlePointEvents(std::list< const core::componentmodel::topology::TopologyChange *>::const_iterator,
00403 std::list< const core::componentmodel::topology::TopologyChange *>::const_iterator);
00404
00405 inline friend std::istream& operator >> ( std::istream& in, BarycentricMapperEdgeSetTopology<In, Out> &b )
00406 {
00407 unsigned int size_vec;
00408
00409 in >> size_vec;
00410 b.map.clear();
00411 MappingData value;
00412 for (unsigned int i=0;i<size_vec;i++)
00413 {
00414 in >> value;
00415 b.map.push_back(value);
00416 }
00417 return in;
00418 }
00419
00420 inline friend std::ostream& operator << ( std::ostream& out, const BarycentricMapperEdgeSetTopology<In, Out> & b ){
00421
00422 out << b.map.size();
00423 out << " " ;
00424 out << b.map;
00425
00426 return out;
00427 }
00428
00429
00430 };
00431
00432
00434 template<class In, class Out>
00435 class BarycentricMapperTriangleSetTopology : public BarycentricMapperBaseTopology, public TopologyBarycentricMapper<In,Out>
00436 {
00437 public:
00438 typedef TopologyBarycentricMapper<In,Out> Inherit;
00439 typedef typename Inherit::Real Real;
00440 typedef typename Inherit::OutReal OutReal;
00441 typedef typename Inherit::MappingData2D MappingData;
00442 protected:
00443 topology::PointData< MappingData > map;
00444 BaseMeshTopology* topology;
00445
00446 public:
00447 BarycentricMapperTriangleSetTopology(BaseMeshTopology* topology)
00448 : BarycentricMapperBaseTopology(topology), TopologyBarycentricMapper<In,Out>(topology),
00449 topology(topology)
00450 {}
00451
00452 virtual ~BarycentricMapperTriangleSetTopology(){}
00453
00454 void clear(int reserve=0);
00455
00456 int addPointInTriangle(int triangleIndex, const SReal* baryCoords);
00457 int createPointInTriangle(const typename Out::Coord& p, int triangleIndex, const typename In::VecCoord* points);
00458
00459 void init(const typename Out::VecCoord& out, const typename In::VecCoord& in);
00460
00461 void apply( typename Out::VecCoord& out, const typename In::VecCoord& in );
00462 void applyJ( typename Out::VecDeriv& out, const typename In::VecDeriv& in );
00463 void applyJT( typename In::VecDeriv& out, const typename Out::VecDeriv& in );
00464 void applyJT( typename In::VecConst& out, const typename Out::VecConst& in );
00465 void draw( const typename Out::VecCoord& out, const typename In::VecCoord& in);
00466
00467
00468 virtual void handleTopologyChange();
00469
00470 virtual void handlePointEvents(std::list< const core::componentmodel::topology::TopologyChange *>::const_iterator,
00471 std::list< const core::componentmodel::topology::TopologyChange *>::const_iterator);
00472
00473 inline friend std::istream& operator >> ( std::istream& in, BarycentricMapperTriangleSetTopology<In, Out> &b )
00474 {
00475 unsigned int size_vec;
00476
00477 in >> size_vec;
00478 b.map.clear();
00479 MappingData value;
00480 for (unsigned int i=0;i<size_vec;i++)
00481 {
00482 in >> value;
00483 b.map.push_back(value);
00484 }
00485 return in;
00486 }
00487
00488 inline friend std::ostream& operator << ( std::ostream& out, const BarycentricMapperTriangleSetTopology<In, Out> & b ){
00489
00490 out << b.map.size();
00491 out << " " ;
00492 out << b.map;
00493
00494 return out;
00495 }
00496
00497
00498 };
00499
00500
00502 template<class In, class Out>
00503 class BarycentricMapperQuadSetTopology : public BarycentricMapperBaseTopology, public TopologyBarycentricMapper<In,Out>
00504 {
00505 public:
00506 typedef TopologyBarycentricMapper<In,Out> Inherit;
00507 typedef typename Inherit::Real Real;
00508 typedef typename Inherit::OutReal OutReal;
00509 typedef typename Inherit::MappingData2D MappingData;
00510 protected:
00511 topology::PointData< MappingData > map;
00512 BaseMeshTopology* topology;
00513
00514 public:
00515 BarycentricMapperQuadSetTopology(BaseMeshTopology* topology)
00516 : BarycentricMapperBaseTopology(topology), TopologyBarycentricMapper<In,Out>(topology),
00517 topology(topology)
00518 {}
00519
00520 virtual ~BarycentricMapperQuadSetTopology(){}
00521
00522 void clear(int reserve=0);
00523
00524 int addPointInQuad(int index, const SReal* baryCoords);
00525 int createPointInQuad(const typename Out::Coord& p, int index, const typename In::VecCoord* points);
00526
00527 void init(const typename Out::VecCoord& out, const typename In::VecCoord& in);
00528
00529 void apply( typename Out::VecCoord& out, const typename In::VecCoord& in );
00530 void applyJ( typename Out::VecDeriv& out, const typename In::VecDeriv& in );
00531 void applyJT( typename In::VecDeriv& out, const typename Out::VecDeriv& in );
00532 void applyJT( typename In::VecConst& out, const typename Out::VecConst& in );
00533 void draw( const typename Out::VecCoord& out, const typename In::VecCoord& in);
00534
00535
00536 virtual void handleTopologyChange();
00537
00538 virtual void handlePointEvents(std::list< const core::componentmodel::topology::TopologyChange *>::const_iterator,
00539 std::list< const core::componentmodel::topology::TopologyChange *>::const_iterator);
00540
00541 inline friend std::istream& operator >> ( std::istream& in, BarycentricMapperQuadSetTopology<In, Out> &b )
00542 {
00543 unsigned int size_vec;
00544
00545 in >> size_vec;
00546 b.map.clear();
00547 MappingData value;
00548 for (unsigned int i=0;i<size_vec;i++)
00549 {
00550 in >> value;
00551 b.map.push_back(value);
00552 }
00553 return in;
00554 }
00555
00556 inline friend std::ostream& operator << ( std::ostream& out, const BarycentricMapperQuadSetTopology<In, Out> & b ){
00557
00558 out << b.map.size();
00559 out << " " ;
00560 out << b.map;
00561
00562 return out;
00563 }
00564
00565 };
00566
00568 template<class In, class Out>
00569 class BarycentricMapperTetrahedronSetTopology : public BarycentricMapperBaseTopology, public TopologyBarycentricMapper<In,Out>
00570 {
00571 public:
00572 typedef TopologyBarycentricMapper<In,Out> Inherit;
00573 typedef typename Inherit::Real Real;
00574 typedef typename Inherit::OutReal OutReal;
00575 typedef typename Inherit::MappingData3D MappingData;
00576 protected:
00577 topology::PointData< MappingData > map;
00578 BaseMeshTopology* topology;
00579
00580 public:
00581 BarycentricMapperTetrahedronSetTopology(BaseMeshTopology* topology)
00582 : BarycentricMapperBaseTopology(topology), TopologyBarycentricMapper<In,Out>(topology),
00583 topology(topology)
00584 {}
00585
00586 virtual ~BarycentricMapperTetrahedronSetTopology(){}
00587
00588 void clear(int reserve=0);
00589
00590 int addPointInTetra(int index, const SReal* baryCoords);
00591
00592
00593 void init(const typename Out::VecCoord& out, const typename In::VecCoord& in);
00594
00595 void apply( typename Out::VecCoord& out, const typename In::VecCoord& in );
00596 void applyJ( typename Out::VecDeriv& out, const typename In::VecDeriv& in );
00597 void applyJT( typename In::VecDeriv& out, const typename Out::VecDeriv& in );
00598 void applyJT( typename In::VecConst& out, const typename Out::VecConst& in );
00599 void draw( const typename Out::VecCoord& out, const typename In::VecCoord& in);
00600
00601
00602 virtual void handleTopologyChange();
00603
00604 virtual void handlePointEvents(std::list< const core::componentmodel::topology::TopologyChange *>::const_iterator,
00605 std::list< const core::componentmodel::topology::TopologyChange *>::const_iterator);
00606
00607 inline friend std::istream& operator >> ( std::istream& in, BarycentricMapperTetrahedronSetTopology<In, Out> &b )
00608 {
00609 unsigned int size_vec;
00610
00611 in >> size_vec;
00612 b.map.clear();
00613 MappingData value;
00614 for (unsigned int i=0;i<size_vec;i++)
00615 {
00616 in >> value;
00617 b.map.push_back(value);
00618 }
00619 return in;
00620 }
00621
00622 inline friend std::ostream& operator << ( std::ostream& out, const BarycentricMapperTetrahedronSetTopology<In, Out> & b ){
00623
00624 out << b.map.size();
00625 out << " " ;
00626 out << b.map;
00627
00628 return out;
00629 }
00630 };
00631
00632
00634 template<class In, class Out>
00635 class BarycentricMapperHexahedronSetTopology : public BarycentricMapperBaseTopology, public TopologyBarycentricMapper<In,Out>
00636 {
00637 public:
00638 typedef TopologyBarycentricMapper<In,Out> Inherit;
00639 typedef typename Inherit::Real Real;
00640 typedef typename Inherit::OutReal OutReal;
00641 typedef typename Inherit::MappingData3D MappingData;
00642 protected:
00643 topology::PointData< MappingData > map;
00644 BaseMeshTopology* topology;
00645
00646 public:
00647 BarycentricMapperHexahedronSetTopology(BaseMeshTopology* topology)
00648 : BarycentricMapperBaseTopology(topology), TopologyBarycentricMapper<In,Out>(topology),
00649 topology(topology)
00650 {}
00651
00652 virtual ~BarycentricMapperHexahedronSetTopology(){}
00653
00654 void clear(int reserve=0);
00655
00656 int addPointInCube(int index, const SReal* baryCoords);
00657
00658
00659 void init(const typename Out::VecCoord& out, const typename In::VecCoord& in);
00660
00661 void apply( typename Out::VecCoord& out, const typename In::VecCoord& in );
00662 void applyJ( typename Out::VecDeriv& out, const typename In::VecDeriv& in );
00663 void applyJT( typename In::VecDeriv& out, const typename Out::VecDeriv& in );
00664 void applyJT( typename In::VecConst& out, const typename Out::VecConst& in );
00665 void draw( const typename Out::VecCoord& out, const typename In::VecCoord& in);
00666
00667
00668 virtual void handleTopologyChange();
00669
00670 virtual void handlePointEvents(std::list< const core::componentmodel::topology::TopologyChange *>::const_iterator,
00671 std::list< const core::componentmodel::topology::TopologyChange *>::const_iterator);
00672
00673 inline friend std::istream& operator >> ( std::istream& in, BarycentricMapperHexahedronSetTopology<In, Out> &b )
00674 {
00675 unsigned int size_vec;
00676
00677 in >> size_vec;
00678 b.map.clear();
00679 MappingData value;
00680 for (unsigned int i=0;i<size_vec;i++)
00681 {
00682 in >> value;
00683 b.map.push_back(value);
00684 }
00685 return in;
00686 }
00687
00688 inline friend std::ostream& operator << ( std::ostream& out, const BarycentricMapperHexahedronSetTopology<In, Out> & b ){
00689
00690 out << b.map.size();
00691 out << " " ;
00692 out << b.map;
00693
00694 return out;
00695 }
00696
00697
00698 private:
00699 struct _BaseAndCenter{
00700 defaulttype::Vector3 origin;
00701 defaulttype::Matrix3 base;
00702 defaulttype::Vector3 center;
00703 } ;
00704
00705 topology::HexahedronData< _BaseAndCenter > hexahedronData;
00706 };
00707
00708 template <class BasicMapping>
00709 class BarycentricMapping : public BasicMapping
00710 {
00711 public:
00712 typedef BasicMapping Inherit;
00713 typedef typename Inherit::In In;
00714 typedef typename Inherit::Out Out;
00715 typedef typename In::DataTypes InDataTypes;
00716 typedef typename InDataTypes::VecCoord InVecCoord;
00717 typedef typename InDataTypes::VecDeriv InVecDeriv;
00718 typedef typename InDataTypes::Coord InCoord;
00719 typedef typename InDataTypes::Deriv InDeriv;
00720 typedef typename InDataTypes::SparseVecDeriv InSparseVecDeriv;
00721 typedef typename InDataTypes::SparseDeriv InSparseDeriv;
00722 typedef typename InDataTypes::Real Real;
00723 typedef typename Out::DataTypes OutDataTypes;
00724 typedef typename OutDataTypes::VecCoord OutVecCoord;
00725 typedef typename OutDataTypes::VecDeriv OutVecDeriv;
00726 typedef typename OutDataTypes::Coord OutCoord;
00727 typedef typename OutDataTypes::Deriv OutDeriv;
00728 typedef typename OutDataTypes::SparseVecDeriv OutSparseVecDeriv;
00729 typedef typename OutDataTypes::SparseDeriv OutSparseDeriv;
00730 typedef typename OutDataTypes::Real OutReal;
00731
00732 typedef core::componentmodel::topology::BaseMeshTopology BaseMeshTopology;
00733
00734 protected:
00735
00736 typedef TopologyBarycentricMapper<InDataTypes,OutDataTypes> Mapper;
00737 typedef BarycentricMapperRegularGridTopology<InDataTypes, OutDataTypes> RegularGridMapper;
00738
00739 Mapper* mapper;
00740 DataPtr< RegularGridMapper >* f_grid;
00741 public:
00742 BarycentricMapping(In* from, Out* to)
00743 : Inherit(from, to), mapper(NULL)
00744 , f_grid (new DataPtr< RegularGridMapper >( new RegularGridMapper( NULL ),"Regular Grid Mapping"))
00745 {
00746 this->addField( f_grid, "gridmap"); f_grid->beginEdit();
00747 }
00748
00749 BarycentricMapping(In* from, Out* to, Mapper* mapper)
00750 : Inherit(from, to), mapper(mapper)
00751 {
00752 if (RegularGridMapper* m = dynamic_cast< RegularGridMapper* >(mapper))
00753 {
00754 f_grid = new DataPtr< RegularGridMapper >( m,"Regular Grid Mapping");
00755 this->addField( f_grid, "gridmap"); f_grid->beginEdit();
00756 }
00757 }
00758
00759 BarycentricMapping(In* from, Out* to, BaseMeshTopology * topology );
00760
00761 virtual ~BarycentricMapping()
00762 {
00763 if (mapper!=NULL)
00764 delete mapper;
00765 }
00766
00767 void init();
00768
00769 void apply( typename Out::VecCoord& out, const typename In::VecCoord& in );
00770
00771 void applyJ( typename Out::VecDeriv& out, const typename In::VecDeriv& in );
00772
00773 void applyJT( typename In::VecDeriv& out, const typename Out::VecDeriv& in );
00774
00775 void applyJT( typename In::VecConst& out, const typename Out::VecConst& in );
00776
00777 void draw();
00778
00779
00780 virtual void handleTopologyChange();
00781
00782 TopologyBarycentricMapper<InDataTypes,OutDataTypes>* getMapper() {return mapper;}
00783
00784 protected:
00785 sofa::core::componentmodel::topology::BaseMeshTopology* topology_from;
00786 sofa::core::componentmodel::topology::BaseMeshTopology* topology_to;
00787
00788 private:
00789 void createMapperFromTopology(BaseMeshTopology * topology);
00790 };
00791
00792 }
00793
00794 }
00795
00796 }
00797
00798 #endif