From 75d5a5f680e208e75ded421cf92b79d18007adaf Mon Sep 17 00:00:00 2001 From: COEVOET Eulalie Date: Thu, 11 Oct 2018 15:41:12 +0200 Subject: [PATCH 01/15] [SofaBaseMechanics] cleaning and refactoring of BarycentricMapping (TopologyContainer part) 1-variable renaming with sofa prefix 2-added parent class (BarycentricMapperTopologyContainer) to gather duplicated codes 3-added templates --- .../SofaBaseMechanics/BarycentricMapping.cpp | 44 +- .../SofaBaseMechanics/BarycentricMapping.h | 748 +++--- .../SofaBaseMechanics/BarycentricMapping.inl | 2258 ++++++++--------- .../BarycentricContactMapper.h | 2 +- .../BarycentricMappingRigid.cpp | 210 +- .../SofaMiscMapping/BarycentricMappingRigid.h | 34 +- .../BarycentricMappingRigid.inl | 18 +- 7 files changed, 1536 insertions(+), 1778 deletions(-) diff --git a/SofaKernel/modules/SofaBaseMechanics/BarycentricMapping.cpp b/SofaKernel/modules/SofaBaseMechanics/BarycentricMapping.cpp index 4144c2b9d6f..f013d3a2f89 100644 --- a/SofaKernel/modules/SofaBaseMechanics/BarycentricMapping.cpp +++ b/SofaKernel/modules/SofaBaseMechanics/BarycentricMapping.cpp @@ -42,7 +42,7 @@ SOFA_DECL_CLASS(BarycentricMapping) // Register in the Factory int BarycentricMappingClass = core::RegisterObject("Mapping using barycentric coordinates of the child with respect to cells of its parent") #ifndef SOFA_FLOAT - .add< BarycentricMapping< Vec3dTypes, Vec3dTypes > >() + .add< BarycentricMapping< Vec3dTypes, Vec3dTypes > >(true) .add< BarycentricMapping< Vec3dTypes, ExtVec3fTypes > >() #endif #ifndef SOFA_DOUBLE @@ -70,14 +70,20 @@ template class SOFA_BASE_MECHANICS_API BarycentricMapperSparseGridTopology< Vec3 template class SOFA_BASE_MECHANICS_API BarycentricMapperSparseGridTopology< Vec3dTypes, ExtVec3fTypes >; template class SOFA_BASE_MECHANICS_API BarycentricMapperMeshTopology< Vec3dTypes, Vec3dTypes >; template class SOFA_BASE_MECHANICS_API BarycentricMapperMeshTopology< Vec3dTypes, ExtVec3fTypes >; -template class SOFA_BASE_MECHANICS_API BarycentricMapperEdgeSetTopology< Vec3dTypes, Vec3dTypes >; -template class SOFA_BASE_MECHANICS_API BarycentricMapperEdgeSetTopology< Vec3dTypes, ExtVec3fTypes >; +template class SOFA_BASE_MECHANICS_API BarycentricMapperTopologyContainer< Vec3dTypes, Vec3dTypes , typename BarycentricMapper::MappingData1D>; +template class SOFA_BASE_MECHANICS_API BarycentricMapperTopologyContainer< Vec3dTypes, ExtVec3fTypes , typename BarycentricMapper::MappingData1D>; +template class SOFA_BASE_MECHANICS_API BarycentricMapperTopologyContainer< Vec3dTypes, Vec3dTypes , typename BarycentricMapper::MappingData2D>; +template class SOFA_BASE_MECHANICS_API BarycentricMapperTopologyContainer< Vec3dTypes, ExtVec3fTypes , typename BarycentricMapper::MappingData2D>; +template class SOFA_BASE_MECHANICS_API BarycentricMapperTopologyContainer< Vec3dTypes, Vec3dTypes , typename BarycentricMapper::MappingData3D>; +template class SOFA_BASE_MECHANICS_API BarycentricMapperTopologyContainer< Vec3dTypes, ExtVec3fTypes , typename BarycentricMapper::MappingData3D>; +template class SOFA_BASE_MECHANICS_API BarycentricMapperEdgeSetTopology< Vec3dTypes, Vec3dTypes>; +template class SOFA_BASE_MECHANICS_API BarycentricMapperEdgeSetTopology< Vec3dTypes, ExtVec3fTypes>; template class SOFA_BASE_MECHANICS_API BarycentricMapperTriangleSetTopology< Vec3dTypes, Vec3dTypes >; template class SOFA_BASE_MECHANICS_API BarycentricMapperTriangleSetTopology< Vec3dTypes, ExtVec3fTypes >; template class SOFA_BASE_MECHANICS_API BarycentricMapperQuadSetTopology< Vec3dTypes, Vec3dTypes >; template class SOFA_BASE_MECHANICS_API BarycentricMapperQuadSetTopology< Vec3dTypes, ExtVec3fTypes >; -template class SOFA_BASE_MECHANICS_API BarycentricMapperTetrahedronSetTopology< Vec3dTypes, Vec3dTypes >; -template class SOFA_BASE_MECHANICS_API BarycentricMapperTetrahedronSetTopology< Vec3dTypes, ExtVec3fTypes >; +//template class SOFA_BASE_MECHANICS_API BarycentricMapperTetrahedronSetTopology< Vec3dTypes, Vec3dTypes >; +//template class SOFA_BASE_MECHANICS_API BarycentricMapperTetrahedronSetTopology< Vec3dTypes, ExtVec3fTypes >; template class SOFA_BASE_MECHANICS_API BarycentricMapperHexahedronSetTopology< Vec3dTypes, Vec3dTypes >; template class SOFA_BASE_MECHANICS_API BarycentricMapperHexahedronSetTopology< Vec3dTypes, ExtVec3fTypes >; #endif @@ -94,14 +100,20 @@ template class SOFA_BASE_MECHANICS_API BarycentricMapperSparseGridTopology< Vec3 template class SOFA_BASE_MECHANICS_API BarycentricMapperSparseGridTopology< Vec3fTypes, ExtVec3fTypes >; template class SOFA_BASE_MECHANICS_API BarycentricMapperMeshTopology< Vec3fTypes, Vec3fTypes >; template class SOFA_BASE_MECHANICS_API BarycentricMapperMeshTopology< Vec3fTypes, ExtVec3fTypes >; -template class SOFA_BASE_MECHANICS_API BarycentricMapperEdgeSetTopology< Vec3fTypes, Vec3fTypes >; -template class SOFA_BASE_MECHANICS_API BarycentricMapperEdgeSetTopology< Vec3fTypes, ExtVec3fTypes >; +template class SOFA_BASE_MECHANICS_API BarycentricMapperTopologyContainer< Vec3fTypes, Vec3fTypes , typename BarycentricMapper::MappingData1D>; +template class SOFA_BASE_MECHANICS_API BarycentricMapperTopologyContainer< Vec3fTypes, ExtVec3fTypes , typename BarycentricMapper::MappingData1D>; +template class SOFA_BASE_MECHANICS_API BarycentricMapperTopologyContainer< Vec3fTypes, Vec3fTypes , typename BarycentricMapper::MappingData2D>; +template class SOFA_BASE_MECHANICS_API BarycentricMapperTopologyContainer< Vec3fTypes, ExtVec3fTypes , typename BarycentricMapper::MappingData2D>; +template class SOFA_BASE_MECHANICS_API BarycentricMapperTopologyContainer< Vec3fTypes, Vec3fTypes , typename BarycentricMapper::MappingData3D>; +template class SOFA_BASE_MECHANICS_API BarycentricMapperTopologyContainer< Vec3fTypes, ExtVec3fTypes , typename BarycentricMapper::MappingData3D>; +template class SOFA_BASE_MECHANICS_API BarycentricMapperEdgeSetTopology< Vec3fTypes, Vec3fTypes>; +template class SOFA_BASE_MECHANICS_API BarycentricMapperEdgeSetTopology< Vec3fTypes, ExtVec3fTypes>; template class SOFA_BASE_MECHANICS_API BarycentricMapperTriangleSetTopology< Vec3fTypes, Vec3fTypes >; template class SOFA_BASE_MECHANICS_API BarycentricMapperTriangleSetTopology< Vec3fTypes, ExtVec3fTypes >; template class SOFA_BASE_MECHANICS_API BarycentricMapperQuadSetTopology< Vec3fTypes, Vec3fTypes >; template class SOFA_BASE_MECHANICS_API BarycentricMapperQuadSetTopology< Vec3fTypes, ExtVec3fTypes >; -template class SOFA_BASE_MECHANICS_API BarycentricMapperTetrahedronSetTopology< Vec3fTypes, Vec3fTypes >; -template class SOFA_BASE_MECHANICS_API BarycentricMapperTetrahedronSetTopology< Vec3fTypes, ExtVec3fTypes >; +//template class SOFA_BASE_MECHANICS_API BarycentricMapperTetrahedronSetTopology< Vec3fTypes, Vec3fTypes >; +//template class SOFA_BASE_MECHANICS_API BarycentricMapperTetrahedronSetTopology< Vec3fTypes, ExtVec3fTypes >; template class SOFA_BASE_MECHANICS_API BarycentricMapperHexahedronSetTopology< Vec3fTypes, Vec3fTypes >; template class SOFA_BASE_MECHANICS_API BarycentricMapperHexahedronSetTopology< Vec3fTypes, ExtVec3fTypes >; #endif @@ -119,14 +131,20 @@ template class SOFA_BASE_MECHANICS_API BarycentricMapperSparseGridTopology< Vec3 template class SOFA_BASE_MECHANICS_API BarycentricMapperSparseGridTopology< Vec3fTypes, Vec3dTypes >; template class SOFA_BASE_MECHANICS_API BarycentricMapperMeshTopology< Vec3dTypes, Vec3fTypes >; template class SOFA_BASE_MECHANICS_API BarycentricMapperMeshTopology< Vec3fTypes, Vec3dTypes >; -template class SOFA_BASE_MECHANICS_API BarycentricMapperEdgeSetTopology< Vec3dTypes, Vec3fTypes >; -template class SOFA_BASE_MECHANICS_API BarycentricMapperEdgeSetTopology< Vec3fTypes, Vec3dTypes >; +template class SOFA_BASE_MECHANICS_API BarycentricMapperTopologyContainer< Vec3dTypes, Vec3fTypes , typename BarycentricMapper::MappingData1D>; +template class SOFA_BASE_MECHANICS_API BarycentricMapperTopologyContainer< Vec3fTypes, Vec3dTypes , typename BarycentricMapper::MappingData1D>; +template class SOFA_BASE_MECHANICS_API BarycentricMapperTopologyContainer< Vec3dTypes, Vec3fTypes , typename BarycentricMapper::MappingData2D>; +template class SOFA_BASE_MECHANICS_API BarycentricMapperTopologyContainer< Vec3fTypes, Vec3dTypes , typename BarycentricMapper::MappingData2D>; +template class SOFA_BASE_MECHANICS_API BarycentricMapperTopologyContainer< Vec3dTypes, Vec3fTypes , typename BarycentricMapper::MappingData3D>; +template class SOFA_BASE_MECHANICS_API BarycentricMapperTopologyContainer< Vec3fTypes, Vec3dTypes , typename BarycentricMapper::MappingData3D>; +template class SOFA_BASE_MECHANICS_API BarycentricMapperEdgeSetTopology< Vec3dTypes, Vec3fTypes>; +template class SOFA_BASE_MECHANICS_API BarycentricMapperEdgeSetTopology< Vec3fTypes, Vec3dTypes>; template class SOFA_BASE_MECHANICS_API BarycentricMapperTriangleSetTopology< Vec3dTypes, Vec3fTypes >; template class SOFA_BASE_MECHANICS_API BarycentricMapperTriangleSetTopology< Vec3fTypes, Vec3dTypes >; template class SOFA_BASE_MECHANICS_API BarycentricMapperQuadSetTopology< Vec3dTypes, Vec3fTypes >; template class SOFA_BASE_MECHANICS_API BarycentricMapperQuadSetTopology< Vec3fTypes, Vec3dTypes >; -template class SOFA_BASE_MECHANICS_API BarycentricMapperTetrahedronSetTopology< Vec3dTypes, Vec3fTypes >; -template class SOFA_BASE_MECHANICS_API BarycentricMapperTetrahedronSetTopology< Vec3fTypes, Vec3dTypes >; +//template class SOFA_BASE_MECHANICS_API BarycentricMapperTetrahedronSetTopology< Vec3dTypes, Vec3fTypes >; +//template class SOFA_BASE_MECHANICS_API BarycentricMapperTetrahedronSetTopology< Vec3fTypes, Vec3dTypes >; template class SOFA_BASE_MECHANICS_API BarycentricMapperHexahedronSetTopology< Vec3dTypes, Vec3fTypes >; template class SOFA_BASE_MECHANICS_API BarycentricMapperHexahedronSetTopology< Vec3fTypes, Vec3dTypes >; #endif diff --git a/SofaKernel/modules/SofaBaseMechanics/BarycentricMapping.h b/SofaKernel/modules/SofaBaseMechanics/BarycentricMapping.h index ff701af51f0..68122dc6e8c 100644 --- a/SofaKernel/modules/SofaBaseMechanics/BarycentricMapping.h +++ b/SofaKernel/modules/SofaBaseMechanics/BarycentricMapping.h @@ -95,7 +95,6 @@ namespace mapping { /// Base class for barycentric mapping topology-specific mappers - template class BarycentricMapper : public virtual core::objectmodel::BaseObject { @@ -131,7 +130,6 @@ class BarycentricMapper : public virtual core::objectmodel::BaseObject { public: int in_index; - //unsigned int points[NP]; Real baryCoords[NC]; inline friend std::istream& operator >> ( std::istream& in, MappingData< NC, NP> &m ) @@ -192,7 +190,7 @@ class BarycentricMapper : public virtual core::objectmodel::BaseObject //-- - virtual void clear( int reserve=0 ) =0; + virtual void clearMapAndReserve( int reserve=0 ) =0; //Nothing to do inline friend std::istream& operator >> ( std::istream& in, BarycentricMapper< In, Out > & ) {return in;} @@ -214,7 +212,6 @@ class TopologyBarycentricMapper : public BarycentricMapper ForceMask *maskFrom; ForceMask *maskTo; -// core::State* toModel; protected: virtual ~TopologyBarycentricMapper() {} @@ -243,22 +240,19 @@ class TopologyBarycentricMapper : public BarycentricMapper virtual void setToTopology( topology::PointSetTopologyContainer* toTopology) {this->toTopology = toTopology;} const topology::PointSetTopologyContainer *getToTopology() const {return toTopology;} - - virtual void updateForceMask() - { - // mask is already filled in the mapper's applyJT; - } + virtual void updateForceMask(){/*mask is already filled in the mapper's applyJT*/} virtual void resize( core::State* toModel ) = 0; protected: + core::topology::BaseMeshTopology* m_fromTopology; + topology::PointSetTopologyContainer* toTopology; + TopologyBarycentricMapper(core::topology::BaseMeshTopology* fromTopology, topology::PointSetTopologyContainer* toTopology = NULL) - : fromTopology(fromTopology), toTopology(toTopology) + : m_fromTopology(fromTopology) + , toTopology(toTopology) {} -protected: - core::topology::BaseMeshTopology* fromTopology; - topology::PointSetTopologyContainer* toTopology; }; @@ -294,27 +288,27 @@ class BarycentricMapperMeshTopology : public TopologyBarycentricMapper Inherit::addMatrixContrib(m, row, col, value); } - sofa::helper::vector< MappingData1D > map1d; - sofa::helper::vector< MappingData2D > map2d; - sofa::helper::vector< MappingData3D > map3d; + sofa::helper::vector< MappingData1D > m_map1d; + sofa::helper::vector< MappingData2D > m_map2d; + sofa::helper::vector< MappingData3D > m_map3d; - MatrixType* matrixJ; - bool updateJ; + MatrixType* m_matrixJ; + bool m_updateJ; BarycentricMapperMeshTopology(core::topology::BaseMeshTopology* fromTopology, topology::PointSetTopologyContainer* toTopology) : TopologyBarycentricMapper(fromTopology, toTopology), - matrixJ(NULL), updateJ(true) + m_matrixJ(NULL), m_updateJ(true) { } virtual ~BarycentricMapperMeshTopology() { - if (matrixJ) delete matrixJ; + if (m_matrixJ) delete m_matrixJ; } public: - void clear(int reserve=0) override; + void clearMapAndReserve(int reserve=0) override; int addPointInLine(const int lineIndex, const SReal* baryCoords) override; int createPointInLine(const typename Out::Coord& p, int lineIndex, const typename In::VecCoord* points) override; @@ -339,36 +333,36 @@ class BarycentricMapperMeshTopology : public TopologyBarycentricMapper void draw(const core::visual::VisualParams*,const typename Out::VecCoord& out, const typename In::VecCoord& in) override; virtual void resize( core::State* toModel ) override; - sofa::helper::vector< MappingData3D > const* getMap3d() const { return &map3d; } + sofa::helper::vector< MappingData3D > const* getMap3d() const { return &m_map3d; } inline friend std::istream& operator >> ( std::istream& in, BarycentricMapperMeshTopology &b ) { unsigned int size_vec; in >> size_vec; - b.map1d.clear(); + b.m_map1d.clear(); MappingData1D value1d; for (unsigned int i=0; i> value1d; - b.map1d.push_back(value1d); + b.m_map1d.push_back(value1d); } in >> size_vec; - b.map2d.clear(); + b.m_map2d.clear(); MappingData2D value2d; for (unsigned int i=0; i> value2d; - b.map2d.push_back(value2d); + b.m_map2d.push_back(value2d); } in >> size_vec; - b.map3d.clear(); + b.m_map3d.clear(); MappingData3D value3d; for (unsigned int i=0; i> value3d; - b.map3d.push_back(value3d); + b.m_map3d.push_back(value3d); } return in; } @@ -376,25 +370,25 @@ class BarycentricMapperMeshTopology : public TopologyBarycentricMapper inline friend std::ostream& operator << ( std::ostream& out, const BarycentricMapperMeshTopology & b ) { - out << b.map1d.size(); + out << b.m_map1d.size(); out << " " ; - out << b.map1d; + out << b.m_map1d; out << " " ; - out << b.map2d.size(); + out << b.m_map2d.size(); out << " " ; - out << b.map2d; + out << b.m_map2d; out << " " ; - out << b.map3d.size(); + out << b.m_map3d.size(); out << " " ; - out << b.map3d; + out << b.m_map3d; return out; } private: - void clear1d(int reserve=0); - void clear2d(int reserve=0); - void clear3d(int reserve=0); + void clearMap1dAndReserve(int size=0); + void clearMap2dAndReserve(int size=0); + void clearMap3dAndReserve(int size=0); }; @@ -427,15 +421,15 @@ class BarycentricMapperRegularGridTopology : public TopologyBarycentricMapper map; - topology::RegularGridTopology* fromTopology; + sofa::helper::vector m_map; + topology::RegularGridTopology* m_fromTopology; MatrixType* matrixJ; bool updateJ; BarycentricMapperRegularGridTopology(topology::RegularGridTopology* fromTopology, topology::PointSetTopologyContainer* toTopology) - : Inherit(fromTopology, toTopology),fromTopology(fromTopology), + : Inherit(fromTopology, toTopology),m_fromTopology(fromTopology), matrixJ(NULL), updateJ(true) { } @@ -446,11 +440,11 @@ class BarycentricMapperRegularGridTopology : public TopologyBarycentricMappermap.size() == 0;} - void setTopology(topology::RegularGridTopology* _topology) {this->fromTopology = _topology;} - topology::RegularGridTopology *getTopology() {return dynamic_cast(this->fromTopology);} + bool isEmpty() {return this->m_map.size() == 0;} + void setTopology(topology::RegularGridTopology* _topology) {this->m_fromTopology = _topology;} + topology::RegularGridTopology *getTopology() {return dynamic_cast(this->m_fromTopology);} int addPointInCube(const int cubeIndex, const SReal* baryCoords) override; @@ -465,13 +459,13 @@ class BarycentricMapperRegularGridTopology : public TopologyBarycentricMapper> ( std::istream& in, BarycentricMapperRegularGridTopology &b ) { - in >> b.map; + in >> b.m_map; return in; } inline friend std::ostream& operator << ( std::ostream& out, const BarycentricMapperRegularGridTopology & b ) { - out << b.map; + out << b.m_map; return out; } @@ -507,8 +501,8 @@ class BarycentricMapperSparseGridTopology : public TopologyBarycentricMapper map; - topology::SparseGridTopology* fromTopology; + sofa::helper::vector m_map; + topology::SparseGridTopology* m_fromTopology; MatrixType* matrixJ; bool updateJ; @@ -516,7 +510,7 @@ class BarycentricMapperSparseGridTopology : public TopologyBarycentricMapper(fromTopology, _toTopology), - fromTopology(fromTopology), + m_fromTopology(fromTopology), matrixJ(NULL), updateJ(true) { } @@ -527,7 +521,7 @@ class BarycentricMapperSparseGridTopology : public TopologyBarycentricMapper> ( std::istream& in, BarycentricMapperSparseGridTopology &b ) { - in >> b.map; + in >> b.m_map; return in; } inline friend std::ostream& operator << ( std::ostream& out, const BarycentricMapperSparseGridTopology & b ) { - out << b.map; + out << b.m_map; return out; } }; -/// Class allowing barycentric mapping computation on a EdgeSetTopology -template -class BarycentricMapperEdgeSetTopology : public TopologyBarycentricMapper +/// Template class for set topology mapper +template +class BarycentricMapperTopologyContainer : public TopologyBarycentricMapper { public: - SOFA_CLASS(SOFA_TEMPLATE2(BarycentricMapperEdgeSetTopology,In,Out),SOFA_TEMPLATE2(TopologyBarycentricMapper,In,Out)); + SOFA_CLASS(SOFA_TEMPLATE3(BarycentricMapperTopologyContainer,In,Out,MappingDataType),SOFA_TEMPLATE2(TopologyBarycentricMapper,In,Out)); typedef TopologyBarycentricMapper Inherit; + typedef typename Inherit::MatrixType MatrixType; + typedef typename MatrixType::Index MatrixTypeIndex; typedef typename Inherit::Real Real; - typedef typename Inherit::OutReal OutReal; - typedef typename Inherit::OutDeriv OutDeriv; - typedef typename Inherit::InDeriv InDeriv; - typedef typename Inherit::MappingData1D MappingData; - enum { NIn = Inherit::NIn }; enum { NOut = Inherit::NOut }; - typedef typename Inherit::MBloc MBloc; - typedef typename Inherit::MatrixType MatrixType; - typedef typename MatrixType::Index MatrixTypeIndex; - - typedef typename Inherit::ForceMask ForceMask; protected: - topology::PointData< sofa::helper::vector > map; ///< mapper data - topology::EdgeSetTopologyContainer* _fromContainer; - topology::EdgeSetGeometryAlgorithms* _fromGeomAlgo; - MatrixType* matrixJ; - bool updateJ; + topology::PointData< helper::vector > d_map; + MatrixType* m_matrixJ; + bool m_updateJ; - BarycentricMapperEdgeSetTopology(topology::EdgeSetTopologyContainer* fromTopology, - topology::PointSetTopologyContainer* _toTopology) - : TopologyBarycentricMapper(fromTopology, _toTopology), - map(initData(&map,"map", "mapper data")), - _fromContainer(fromTopology), - _fromGeomAlgo(NULL), - matrixJ(NULL), - updateJ(true) - {} + BarycentricMapperTopologyContainer(core::topology::BaseMeshTopology* fromTopology, topology::PointSetTopologyContainer* toTopology) + : Inherit(fromTopology, toTopology), + d_map(initData(&d_map,"map", "mapper data")), + m_matrixJ(NULL), + m_updateJ(true) + {} - virtual ~BarycentricMapperEdgeSetTopology() {} -public: + virtual ~BarycentricMapperTopologyContainer() {} - void clear(int reserve=0) override; +public: - int addPointInLine(const int edgeIndex, const SReal* baryCoords) override; - int createPointInLine(const typename Out::Coord& p, int edgeIndex, const typename In::VecCoord* points) override; + virtual void clearMapAndReserve(int size=0) override + { + helper::vector& vectorData = *(d_map.beginEdit()); + vectorData.clear(); + if ( size>0 ) vectorData.reserve ( size ); + d_map.endEdit(); + } - void init(const typename Out::VecCoord& out, const typename In::VecCoord& in) override; + virtual void resize( core::State* toModel ) override + { + toModel->resize(d_map.getValue().size()); + } - void apply( typename Out::VecCoord& out, const typename In::VecCoord& in ) override; - void applyJ( typename Out::VecDeriv& out, const typename In::VecDeriv& in ) override; - void applyJT( typename In::VecDeriv& out, const typename Out::VecDeriv& in ) override; - void applyJT( typename In::MatrixDeriv& out, const typename Out::MatrixDeriv& in ) override; + virtual const sofa::defaulttype::BaseMatrix* getJ(int outSize, int inSize) override + { + if (m_matrixJ && !m_updateJ) + return m_matrixJ; - virtual const sofa::defaulttype::BaseMatrix* getJ(int outSize, int inSize) override; + if (!m_matrixJ) m_matrixJ = new MatrixType; + if (m_matrixJ->rowBSize() != (MatrixTypeIndex)outSize || m_matrixJ->colBSize() != (MatrixTypeIndex)inSize) + m_matrixJ->resize(outSize*NOut, inSize*NIn); + else + m_matrixJ->clear(); - void draw(const core::visual::VisualParams*,const typename Out::VecCoord& out, const typename In::VecCoord& in) override; - virtual void resize( core::State* toModel ) override; + return m_matrixJ; + } - inline friend std::istream& operator >> ( std::istream& in, BarycentricMapperEdgeSetTopology &b ) + inline friend std::istream& operator >> ( std::istream& in, BarycentricMapperTopologyContainer &b ) { unsigned int size_vec; in >> size_vec; - sofa::helper::vector& m = *(b.map.beginEdit()); + sofa::helper::vector& m = *(b.d_map.beginEdit()); m.clear(); - MappingData value; + MappingDataType value; for (unsigned int i=0; i> value; m.push_back(value); } - b.map.endEdit(); + b.d_map.endEdit(); return in; } - inline friend std::ostream& operator << ( std::ostream& out, const BarycentricMapperEdgeSetTopology & b ) + inline friend std::ostream& operator << ( std::ostream& out, const BarycentricMapperTopologyContainer & b ) { - out << b.map.getValue().size(); + out << b.d_map.getValue().size(); out << " " ; - out << b.map; + out << b.d_map; return out; } -}; + bool isEmpty() + { + return d_map.getValue().empty(); + } + +}; -/// Class allowing barycentric mapping computation on a TriangleSetTopology -template -class BarycentricMapperTriangleSetTopology : public TopologyBarycentricMapper +/////// Class allowing barycentric mapping computation on a EdgeSetTopology +template::MappingData1D> +class BarycentricMapperEdgeSetTopology : public BarycentricMapperTopologyContainer { public: - SOFA_CLASS(SOFA_TEMPLATE2(BarycentricMapperTriangleSetTopology,In,Out),SOFA_TEMPLATE2(TopologyBarycentricMapper,In,Out)); - typedef TopologyBarycentricMapper Inherit; + SOFA_CLASS(SOFA_TEMPLATE3(BarycentricMapperEdgeSetTopology,In,Out,MappingDataType),SOFA_TEMPLATE3(BarycentricMapperTopologyContainer,In,Out,MappingDataType)); + typedef MappingDataType MappingData; + typedef BarycentricMapperTopologyContainer Inherit; typedef typename Inherit::Real Real; typedef typename Inherit::OutReal OutReal; typedef typename Inherit::OutDeriv OutDeriv; typedef typename Inherit::InDeriv InDeriv; - typedef typename Inherit::MappingData2D MappingData; - enum { NIn = Inherit::NIn }; - enum { NOut = Inherit::NOut }; typedef typename Inherit::MBloc MBloc; typedef typename Inherit::MatrixType MatrixType; - typedef typename MatrixType::Index MatrixTypeIndex; typedef typename Inherit::ForceMask ForceMask; + protected: - topology::PointData< sofa::helper::vector > map; ///< mapper data - topology::TriangleSetTopologyContainer* _fromContainer; - topology::TriangleSetGeometryAlgorithms* _fromGeomAlgo; - MatrixType* matrixJ; - bool updateJ; + topology::EdgeSetTopologyContainer* m_fromContainer; + topology::EdgeSetGeometryAlgorithms* m_fromGeomAlgo; + + using Inherit::d_map; + using Inherit::m_fromTopology; + using Inherit::m_matrixJ; + using Inherit::m_updateJ; + + BarycentricMapperEdgeSetTopology(topology::EdgeSetTopologyContainer* fromTopology, topology::PointSetTopologyContainer* toTopology) + : Inherit(fromTopology, toTopology), + m_fromContainer(fromTopology), + m_fromGeomAlgo(NULL) + {} - BarycentricMapperTriangleSetTopology(topology::TriangleSetTopologyContainer* fromTopology, - topology::PointSetTopologyContainer* _toTopology) - : TopologyBarycentricMapper(fromTopology, _toTopology), - map(initData(&map,"map", "mapper data")), - _fromContainer(fromTopology), - _fromGeomAlgo(NULL), - matrixJ(NULL), - updateJ(true) + virtual ~BarycentricMapperEdgeSetTopology() {} + + helper::vector getBaryCoef(const Real* f) { + return getBaryCoef(f[0]); } - virtual ~BarycentricMapperTriangleSetTopology(){} + helper::vector getBaryCoef(const Real fx) + { + helper::vector edgeCoef{1-fx,fx}; + return edgeCoef; + } public: - void clear(int reserve=0) override; - virtual int addPointInTriangle(const int triangleIndex, const SReal* baryCoords) override; - int createPointInTriangle(const typename Out::Coord& p, int triangleIndex, const typename In::VecCoord* points) override; + int addPointInLine(const int edgeIndex, const SReal* baryCoords) override; + int createPointInLine(const typename Out::Coord& p, int edgeIndex, const typename In::VecCoord* points) override; void init(const typename Out::VecCoord& out, const typename In::VecCoord& in) override; @@ -702,86 +704,130 @@ class BarycentricMapperTriangleSetTopology : public TopologyBarycentricMapper* toModel ) override; +}; -#ifdef BARYCENTRIC_MAPPER_TOPOCHANGE_REINIT - // handle topology changes in the From topology - virtual void handleTopologyChange(core::topology::Topology* t); -#endif // BARYCENTRIC_MAPPER_TOPOCHANGE_REINIT - inline friend std::istream& operator >> ( std::istream& in, BarycentricMapperTriangleSetTopology &b ) - { - unsigned int size_vec; - in >> size_vec; +/// Class allowing barycentric mapping computation on a TriangleSetTopology +template::MappingData2D> +class BarycentricMapperTriangleSetTopology : public BarycentricMapperTopologyContainer +{ +public: + SOFA_CLASS(SOFA_TEMPLATE3(BarycentricMapperTriangleSetTopology,In,Out,MappingDataType),SOFA_TEMPLATE3(BarycentricMapperTopologyContainer,In,Out,MappingDataType)); + typedef MappingDataType MappingData; + typedef BarycentricMapperTopologyContainer Inherit; + typedef typename Inherit::Real Real; + typedef typename Inherit::OutReal OutReal; + typedef typename Inherit::OutDeriv OutDeriv; + typedef typename Inherit::InDeriv InDeriv; - sofa::helper::vector& m = *(b.map.beginEdit()); - m.clear(); - MappingData value; - for (unsigned int i=0; i> value; - m.push_back(value); - } - b.map.endEdit(); - return in; + typedef typename Inherit::MBloc MBloc; + typedef typename Inherit::MatrixType MatrixType; + + typedef typename Inherit::ForceMask ForceMask; + +protected: + topology::TriangleSetTopologyContainer* m_fromContainer; + topology::TriangleSetGeometryAlgorithms* m_fromGeomAlgo; + + using Inherit::d_map; + using Inherit::m_fromTopology; + using Inherit::m_matrixJ; + using Inherit::m_updateJ; + + BarycentricMapperTriangleSetTopology(topology::TriangleSetTopologyContainer* fromTopology, topology::PointSetTopologyContainer* toTopology) + : Inherit(fromTopology, toTopology), + m_fromContainer(fromTopology), + m_fromGeomAlgo(NULL) + {} + + virtual ~BarycentricMapperTriangleSetTopology(){} + + helper::vector getBaryCoef(const Real* f) + { + return getBaryCoef(f[0],f[1]); } - inline friend std::ostream& operator << ( std::ostream& out, const BarycentricMapperTriangleSetTopology & b ) + helper::vector getBaryCoef(const Real fx, const Real fy) { + helper::vector triangleCoef{1-fx-fy, fx, fy}; + return triangleCoef; + } - out << b.map.getValue().size(); - out << " " ; - out << b.map; +public: - return out; - } + virtual int addPointInTriangle(const int triangleIndex, const SReal* baryCoords) override; + int createPointInTriangle(const typename Out::Coord& p, int triangleIndex, const typename In::VecCoord* points) override; + + void init(const typename Out::VecCoord& out, const typename In::VecCoord& in) override; + + void apply( typename Out::VecCoord& out, const typename In::VecCoord& in ) override; + void applyJ( typename Out::VecDeriv& out, const typename In::VecDeriv& in ) override; + void applyJT( typename In::VecDeriv& out, const typename Out::VecDeriv& in ) override; + void applyJT( typename In::MatrixDeriv& out, const typename Out::MatrixDeriv& in ) override; + + virtual const sofa::defaulttype::BaseMatrix* getJ(int outSize, int inSize) override; + + void draw(const core::visual::VisualParams*,const typename Out::VecCoord& out, const typename In::VecCoord& in) override; + +#ifdef BARYCENTRIC_MAPPER_TOPOCHANGE_REINIT + // handle topology changes in the From topology + virtual void handleTopologyChange(core::topology::Topology* t); +#endif // BARYCENTRIC_MAPPER_TOPOCHANGE_REINIT }; /// Class allowing barycentric mapping computation on a QuadSetTopology -template -class BarycentricMapperQuadSetTopology : public TopologyBarycentricMapper +template::MappingData2D> +class BarycentricMapperQuadSetTopology : public BarycentricMapperTopologyContainer { public: - SOFA_CLASS(SOFA_TEMPLATE2(BarycentricMapperQuadSetTopology,In,Out),SOFA_TEMPLATE2(TopologyBarycentricMapper,In,Out)); - typedef TopologyBarycentricMapper Inherit; + SOFA_CLASS(SOFA_TEMPLATE3(BarycentricMapperQuadSetTopology,In,Out,MappingDataType),SOFA_TEMPLATE3(BarycentricMapperTopologyContainer,In,Out,MappingDataType)); + typedef MappingDataType MappingData; + typedef BarycentricMapperTopologyContainer Inherit; typedef typename Inherit::Real Real; typedef typename Inherit::OutReal OutReal; typedef typename Inherit::OutDeriv OutDeriv; typedef typename Inherit::InDeriv InDeriv; - typedef typename Inherit::MappingData2D MappingData; - enum { NIn = Inherit::NIn }; - enum { NOut = Inherit::NOut }; typedef typename Inherit::MBloc MBloc; typedef typename Inherit::MatrixType MatrixType; - typedef typename MatrixType::Index MatrixTypeIndex; typedef typename Inherit::ForceMask ForceMask; protected: - topology::PointData< sofa::helper::vector > map; ///< mapper data - topology::QuadSetTopologyContainer* _fromContainer; - topology::QuadSetGeometryAlgorithms* _fromGeomAlgo; - MatrixType* matrixJ; - bool updateJ; - - BarycentricMapperQuadSetTopology(topology::QuadSetTopologyContainer* fromTopology, - topology::PointSetTopologyContainer* _toTopology) - : TopologyBarycentricMapper(fromTopology, _toTopology), - map(initData(&map,"map", "mapper data")), - _fromContainer(fromTopology), - _fromGeomAlgo(NULL), - matrixJ(NULL), - updateJ(true) + topology::QuadSetTopologyContainer* m_fromContainer; + topology::QuadSetGeometryAlgorithms* m_fromGeomAlgo; + + using Inherit::d_map; + using Inherit::m_fromTopology; + using Inherit::m_matrixJ; + using Inherit::m_updateJ; + + BarycentricMapperQuadSetTopology(topology::QuadSetTopologyContainer* fromTopology, topology::PointSetTopologyContainer* toTopology) + : Inherit(fromTopology, toTopology), + m_fromContainer(fromTopology), + m_fromGeomAlgo(NULL) {} virtual ~BarycentricMapperQuadSetTopology() {} + helper::vector getBaryCoef(const Real* f) + { + return getBaryCoef(f[0],f[1]); + } + + helper::vector getBaryCoef(const Real fx, const Real fy) + { + helper::vector quadCoef{(1-fx)*(1-fy), + (fx)*(1-fy), + (1-fx)*(fy), + (fx)*(fy)}; + return quadCoef; + } + public: - void clear(int reserve=0) override; int addPointInQuad(const int index, const SReal* baryCoords) override; int createPointInQuad(const typename Out::Coord& p, int index, const typename In::VecCoord* points) override; @@ -796,86 +842,62 @@ class BarycentricMapperQuadSetTopology : public TopologyBarycentricMapper* toModel ) override; - - inline friend std::istream& operator >> ( std::istream& in, BarycentricMapperQuadSetTopology &b ) - { - unsigned int size_vec; - - in >> size_vec; - sofa::helper::vector& m = *(b.map.beginEdit()); - m.clear(); - MappingData value; - for (unsigned int i=0; i> value; - m.push_back(value); - } - b.map.endEdit(); - return in; - } - - inline friend std::ostream& operator << ( std::ostream& out, const BarycentricMapperQuadSetTopology & b ) - { +}; - out << b.map.getValue().size(); - out << " " ; - out << b.map; - return out; - } - -}; /// Class allowing barycentric mapping computation on a TetrahedronSetTopology -template -class BarycentricMapperTetrahedronSetTopology : public TopologyBarycentricMapper +template::MappingData3D> +class BarycentricMapperTetrahedronSetTopology : BarycentricMapperTopologyContainer { public: - SOFA_CLASS(SOFA_TEMPLATE2(BarycentricMapperTetrahedronSetTopology,In,Out),SOFA_TEMPLATE2(TopologyBarycentricMapper,In,Out)); - typedef TopologyBarycentricMapper Inherit; + SOFA_CLASS(SOFA_TEMPLATE3(BarycentricMapperTetrahedronSetTopology,In,Out,MappingDataType),SOFA_TEMPLATE3(BarycentricMapperTopologyContainer,In,Out,MappingDataType)); + typedef MappingDataType MappingData; + typedef BarycentricMapperTopologyContainer Inherit; typedef typename Inherit::Real Real; typedef typename Inherit::OutReal OutReal; typedef typename Inherit::OutDeriv OutDeriv; typedef typename Inherit::InDeriv InDeriv; - typedef typename Inherit::MappingData3D MappingData; typedef typename In::VecCoord VecCoord; - enum { NIn = Inherit::NIn }; - enum { NOut = Inherit::NOut }; typedef typename Inherit::MBloc MBloc; typedef typename Inherit::MatrixType MatrixType; - typedef typename MatrixType::Index MatrixTypeIndex; typedef typename Inherit::ForceMask ForceMask; protected: - topology::PointData< sofa::helper::vector > map; ///< mapper data - VecCoord actualTetraPosition; + VecCoord m_actualTetraPosition; + topology::TetrahedronSetTopologyContainer* m_fromContainer; + topology::TetrahedronSetGeometryAlgorithms* m_fromGeomAlgo; - topology::TetrahedronSetTopologyContainer* _fromContainer; - topology::TetrahedronSetGeometryAlgorithms* _fromGeomAlgo; + using Inherit::d_map; + using Inherit::m_fromTopology; + using Inherit::m_matrixJ; + using Inherit::m_updateJ; - MatrixType* matrixJ; - bool updateJ; - - BarycentricMapperTetrahedronSetTopology(topology::TetrahedronSetTopologyContainer* fromTopology, topology::PointSetTopologyContainer* _toTopology) - : TopologyBarycentricMapper(fromTopology, _toTopology), - map(initData(&map,"map", "mapper data")), - _fromContainer(fromTopology), - _fromGeomAlgo(NULL), - matrixJ(NULL), - updateJ(true) + BarycentricMapperTetrahedronSetTopology(topology::TetrahedronSetTopologyContainer* fromTopology, topology::PointSetTopologyContainer* toTopology) + : Inherit(fromTopology, toTopology), + m_fromContainer(fromTopology), + m_fromGeomAlgo(NULL) {} virtual ~BarycentricMapperTetrahedronSetTopology() {} -public: - void clear(int reserve=0) override; + helper::vector getBaryCoef(const Real* f) + { + return getBaryCoef(f[0],f[1],f[2]); + } - int addPointInTetra(const int index, const SReal* baryCoords) override; + helper::vector getBaryCoef(const Real fx, const Real fy, const Real fz) + { + helper::vector tetrahedronCoef{(1-fx-fy-fz),fx,fy,fz}; + return tetrahedronCoef; + } + +public: + int addPointInTetra(const int index, const SReal* baryCoords) override ; void init(const typename Out::VecCoord& out, const typename In::VecCoord& in) override; @@ -887,63 +909,72 @@ class BarycentricMapperTetrahedronSetTopology : public TopologyBarycentricMapper virtual const sofa::defaulttype::BaseMatrix* getJ(int outSize, int inSize) override; void draw(const core::visual::VisualParams*,const typename Out::VecCoord& out, const typename In::VecCoord& in) override; - virtual void resize( core::State* toModel ) override; - - }; /// Class allowing barycentric mapping computation on a HexahedronSetTopology -template -class BarycentricMapperHexahedronSetTopology : public TopologyBarycentricMapper +template::MappingData3D> +class BarycentricMapperHexahedronSetTopology : public BarycentricMapperTopologyContainer { public: - SOFA_CLASS(SOFA_TEMPLATE2(BarycentricMapperHexahedronSetTopology,In,Out),SOFA_TEMPLATE2(TopologyBarycentricMapper,In,Out)); - typedef TopologyBarycentricMapper Inherit; + SOFA_CLASS(SOFA_TEMPLATE3(BarycentricMapperHexahedronSetTopology,In,Out,MappingDataType),SOFA_TEMPLATE3(BarycentricMapperTopologyContainer,In,Out,MappingDataType)); + typedef MappingDataType MappingData; + typedef BarycentricMapperTopologyContainer Inherit; typedef typename Inherit::Real Real; typedef typename Inherit::OutReal OutReal; typedef typename Inherit::OutDeriv OutDeriv; typedef typename Inherit::InDeriv InDeriv; - typedef typename Inherit::MappingData3D MappingData; - enum { NIn = Inherit::NIn }; - enum { NOut = Inherit::NOut }; typedef typename Inherit::MBloc MBloc; typedef typename Inherit::MatrixType MatrixType; - typedef typename MatrixType::Index MatrixTypeIndex; typedef typename Inherit::ForceMask ForceMask; protected: - topology::PointData< sofa::helper::vector > map; ///< mapper data - topology::HexahedronSetTopologyContainer* _fromContainer; - topology::HexahedronSetGeometryAlgorithms* _fromGeomAlgo; + topology::HexahedronSetTopologyContainer* m_fromContainer; + topology::HexahedronSetGeometryAlgorithms* m_fromGeomAlgo; + std::set m_invalidIndex; - std::set _invalidIndex; - MatrixType* matrixJ; - bool updateJ; + using Inherit::d_map; + using Inherit::m_matrixJ; + using Inherit::m_updateJ; + using Inherit::m_fromTopology; BarycentricMapperHexahedronSetTopology() - : TopologyBarycentricMapper(NULL, NULL), - map(initData(&map,"map", "mapper data")), - _fromContainer(NULL),_fromGeomAlgo(NULL) + : Inherit(NULL, NULL), + m_fromContainer(NULL), + m_fromGeomAlgo(NULL) {} - BarycentricMapperHexahedronSetTopology(topology::HexahedronSetTopologyContainer* fromTopology, - topology::PointSetTopologyContainer* _toTopology) - : TopologyBarycentricMapper(fromTopology, _toTopology), - map(initData(&map,"map", "mapper data")), - _fromContainer(fromTopology), - _fromGeomAlgo(NULL), - matrixJ(NULL), - updateJ(true) + BarycentricMapperHexahedronSetTopology(topology::HexahedronSetTopologyContainer* fromTopology, topology::PointSetTopologyContainer* toTopology) + : Inherit(fromTopology, toTopology), + m_fromContainer(fromTopology), + m_fromGeomAlgo(NULL) {} virtual ~BarycentricMapperHexahedronSetTopology() {} + + helper::vector getBaryCoef(const Real* f) + { + return getBaryCoef(f[0],f[1],f[2]); + } + + helper::vector getBaryCoef(const Real fx, const Real fy, const Real fz) + { + helper::vector hexahedronCoef{(1-fx)*(1-fy)*(1-fz), + (fx)*(1-fy)*(1-fz), + (1-fx)*(fy)*(1-fz), + (fx)*(fy)*(1-fz), + (1-fx)*(1-fy)*(fz), + (fx)*(1-fy)*(fz), + (1-fx)*(fy)*(fz), + (fx)*(fy)*(fz)}; + return hexahedronCoef; + } + public: - void clear(int reserve=0) override; int addPointInCube(const int index, const SReal* baryCoords) override; @@ -959,7 +990,6 @@ class BarycentricMapperHexahedronSetTopology : public TopologyBarycentricMapper< virtual const sofa::defaulttype::BaseMatrix* getJ(int outSize, int inSize) override; void draw(const core::visual::VisualParams*,const typename Out::VecCoord& out, const typename In::VecCoord& in) override; - virtual void resize( core::State* toModel ) override; //-- test mapping partiel void applyOnePoint( const unsigned int& hexaId, typename Out::VecCoord& out, const typename In::VecCoord& in) override; @@ -968,36 +998,11 @@ class BarycentricMapperHexahedronSetTopology : public TopologyBarycentricMapper< // handle topology changes in the From topology virtual void handleTopologyChange(core::topology::Topology* t) override; - bool isEmpty() {return this->map.getValue().empty();} - void setTopology(topology::HexahedronSetTopologyContainer* _topology) {this->fromTopology = _topology; _fromContainer=_topology;} - inline friend std::istream& operator >> ( std::istream& in, BarycentricMapperHexahedronSetTopology &b ) + void setTopology(topology::HexahedronSetTopologyContainer* topology) { - unsigned int size_vec; - - in >> size_vec; - sofa::helper::vector& m = *(b.map.beginEdit()); - m.clear(); - MappingData value; - for (unsigned int i=0; i> value; - m.push_back(value); - } - b.map.endEdit(); - return in; + m_fromTopology = topology; + m_fromContainer = topology; } - - inline friend std::ostream& operator << ( std::ostream& out, const BarycentricMapperHexahedronSetTopology & b ) - { - - out << b.map.getValue().size(); - out << " " ; - out << b.map; - - return out; - } - - }; @@ -1012,12 +1017,12 @@ class BarycentricMapping : public core::Mapping typedef TIn In; typedef TOut Out; typedef In InDataTypes; + typedef Out OutDataTypes; typedef typename InDataTypes::VecCoord InVecCoord; typedef typename InDataTypes::VecDeriv InVecDeriv; typedef typename InDataTypes::Coord InCoord; typedef typename InDataTypes::Deriv InDeriv; typedef typename InDataTypes::Real Real; - typedef Out OutDataTypes; typedef typename OutDataTypes::VecCoord OutVecCoord; typedef typename OutDataTypes::VecDeriv OutVecDeriv; typedef typename OutDataTypes::Coord OutCoord; @@ -1025,16 +1030,12 @@ class BarycentricMapping : public core::Mapping typedef typename OutDataTypes::Real OutReal; typedef core::topology::BaseMeshTopology BaseMeshTopology; - typedef TopologyBarycentricMapper Mapper; - //typedef BarycentricMapperRegularGridTopology RegularGridMapper; - //typedef BarycentricMapperHexahedronSetTopology HexaMapper; - typedef typename Inherit::ForceMask ForceMask; protected: - SingleLink,Mapper,BaseLink::FLAG_STRONGLINK> mapper; + SingleLink,Mapper,BaseLink::FLAG_STRONGLINK> m_mapper; public: @@ -1047,7 +1048,7 @@ class BarycentricMapping : public core::Mapping protected: BarycentricMapping(); - BarycentricMapping(core::State* from, core::State* to, typename Mapper::SPtr mapper); + BarycentricMapping(core::State* from, core::State* to, typename Mapper::SPtr m_mapper); BarycentricMapping(core::State* from, core::State* to, BaseMeshTopology * topology=NULL ); @@ -1089,12 +1090,9 @@ class BarycentricMapping : public core::Mapping virtual void handleTopologyChange(core::topology::Topology* t) override; // interface for continuous friction contact - - - TopologyBarycentricMapper *getMapper() { - return mapper.get(); + return m_mapper.get(); } protected: @@ -1105,79 +1103,103 @@ class BarycentricMapping : public core::Mapping void createMapperFromTopology(BaseMeshTopology * topology); }; + +using sofa::defaulttype::Vec3dTypes; +using sofa::defaulttype::Vec3fTypes; +using sofa::defaulttype::ExtVec3fTypes; + + #if defined(SOFA_EXTERN_TEMPLATE) && !defined(SOFA_COMPONENT_MAPPING_BARYCENTRICMAPPING_CPP) #ifndef SOFA_FLOAT -extern template class SOFA_BASE_MECHANICS_API BarycentricMapping< sofa::defaulttype::Vec3dTypes, sofa::defaulttype::Vec3dTypes >; -extern template class SOFA_BASE_MECHANICS_API BarycentricMapping< sofa::defaulttype::Vec3dTypes, sofa::defaulttype::ExtVec3fTypes >; -extern template class SOFA_BASE_MECHANICS_API BarycentricMapper< sofa::defaulttype::Vec3dTypes, sofa::defaulttype::Vec3dTypes >; -extern template class SOFA_BASE_MECHANICS_API BarycentricMapper< sofa::defaulttype::Vec3dTypes, sofa::defaulttype::ExtVec3fTypes >; -extern template class SOFA_BASE_MECHANICS_API TopologyBarycentricMapper< sofa::defaulttype::Vec3dTypes, sofa::defaulttype::Vec3dTypes >; -extern template class SOFA_BASE_MECHANICS_API TopologyBarycentricMapper< sofa::defaulttype::Vec3dTypes, sofa::defaulttype::ExtVec3fTypes >; -extern template class SOFA_BASE_MECHANICS_API BarycentricMapperRegularGridTopology< sofa::defaulttype::Vec3dTypes, sofa::defaulttype::Vec3dTypes >; -extern template class SOFA_BASE_MECHANICS_API BarycentricMapperRegularGridTopology< sofa::defaulttype::Vec3dTypes, sofa::defaulttype::ExtVec3fTypes >; -extern template class SOFA_BASE_MECHANICS_API BarycentricMapperSparseGridTopology< sofa::defaulttype::Vec3dTypes, sofa::defaulttype::Vec3dTypes >; -extern template class SOFA_BASE_MECHANICS_API BarycentricMapperSparseGridTopology< sofa::defaulttype::Vec3dTypes, sofa::defaulttype::ExtVec3fTypes >; -extern template class SOFA_BASE_MECHANICS_API BarycentricMapperMeshTopology< sofa::defaulttype::Vec3dTypes, sofa::defaulttype::Vec3dTypes >; -extern template class SOFA_BASE_MECHANICS_API BarycentricMapperMeshTopology< sofa::defaulttype::Vec3dTypes, sofa::defaulttype::ExtVec3fTypes >; -extern template class SOFA_BASE_MECHANICS_API BarycentricMapperEdgeSetTopology< sofa::defaulttype::Vec3dTypes, sofa::defaulttype::Vec3dTypes >; -extern template class SOFA_BASE_MECHANICS_API BarycentricMapperEdgeSetTopology< sofa::defaulttype::Vec3dTypes, sofa::defaulttype::ExtVec3fTypes >; -extern template class SOFA_BASE_MECHANICS_API BarycentricMapperTriangleSetTopology< sofa::defaulttype::Vec3dTypes, sofa::defaulttype::Vec3dTypes >; -extern template class SOFA_BASE_MECHANICS_API BarycentricMapperTriangleSetTopology< sofa::defaulttype::Vec3dTypes, sofa::defaulttype::ExtVec3fTypes >; -extern template class SOFA_BASE_MECHANICS_API BarycentricMapperQuadSetTopology< sofa::defaulttype::Vec3dTypes, sofa::defaulttype::Vec3dTypes >; -extern template class SOFA_BASE_MECHANICS_API BarycentricMapperQuadSetTopology< sofa::defaulttype::Vec3dTypes, sofa::defaulttype::ExtVec3fTypes >; -extern template class SOFA_BASE_MECHANICS_API BarycentricMapperTetrahedronSetTopology< sofa::defaulttype::Vec3dTypes, sofa::defaulttype::Vec3dTypes >; -extern template class SOFA_BASE_MECHANICS_API BarycentricMapperTetrahedronSetTopology< sofa::defaulttype::Vec3dTypes, sofa::defaulttype::ExtVec3fTypes >; -extern template class SOFA_BASE_MECHANICS_API BarycentricMapperHexahedronSetTopology< sofa::defaulttype::Vec3dTypes, sofa::defaulttype::Vec3dTypes >; -extern template class SOFA_BASE_MECHANICS_API BarycentricMapperHexahedronSetTopology< sofa::defaulttype::Vec3dTypes, sofa::defaulttype::ExtVec3fTypes >; +extern template class SOFA_BASE_MECHANICS_API BarycentricMapping< Vec3dTypes, Vec3dTypes >; +extern template class SOFA_BASE_MECHANICS_API BarycentricMapping< Vec3dTypes, ExtVec3fTypes >; +extern template class SOFA_BASE_MECHANICS_API BarycentricMapper< Vec3dTypes, Vec3dTypes >; +extern template class SOFA_BASE_MECHANICS_API BarycentricMapper< Vec3dTypes, ExtVec3fTypes >; +extern template class SOFA_BASE_MECHANICS_API TopologyBarycentricMapper< Vec3dTypes, Vec3dTypes >; +extern template class SOFA_BASE_MECHANICS_API TopologyBarycentricMapper< Vec3dTypes, ExtVec3fTypes >; +extern template class SOFA_BASE_MECHANICS_API BarycentricMapperRegularGridTopology< Vec3dTypes, Vec3dTypes >; +extern template class SOFA_BASE_MECHANICS_API BarycentricMapperRegularGridTopology< Vec3dTypes, ExtVec3fTypes >; +extern template class SOFA_BASE_MECHANICS_API BarycentricMapperSparseGridTopology< Vec3dTypes, Vec3dTypes >; +extern template class SOFA_BASE_MECHANICS_API BarycentricMapperSparseGridTopology< Vec3dTypes, ExtVec3fTypes >; +extern template class SOFA_BASE_MECHANICS_API BarycentricMapperMeshTopology< Vec3dTypes, Vec3dTypes >; +extern template class SOFA_BASE_MECHANICS_API BarycentricMapperMeshTopology< Vec3dTypes, ExtVec3fTypes >; +extern template class SOFA_BASE_MECHANICS_API BarycentricMapperTopologyContainer< Vec3dTypes, Vec3dTypes , typename BarycentricMapper::MappingData1D>; +extern template class SOFA_BASE_MECHANICS_API BarycentricMapperTopologyContainer< Vec3dTypes, ExtVec3fTypes , typename BarycentricMapper::MappingData1D>; +extern template class SOFA_BASE_MECHANICS_API BarycentricMapperTopologyContainer< Vec3dTypes, Vec3dTypes , typename BarycentricMapper::MappingData2D>; +extern template class SOFA_BASE_MECHANICS_API BarycentricMapperTopologyContainer< Vec3dTypes, ExtVec3fTypes , typename BarycentricMapper::MappingData2D>; +extern template class SOFA_BASE_MECHANICS_API BarycentricMapperTopologyContainer< Vec3dTypes, Vec3dTypes , typename BarycentricMapper::MappingData3D>; +extern template class SOFA_BASE_MECHANICS_API BarycentricMapperTopologyContainer< Vec3dTypes, ExtVec3fTypes , typename BarycentricMapper::MappingData3D>; +extern template class SOFA_BASE_MECHANICS_API BarycentricMapperEdgeSetTopology< Vec3dTypes, Vec3dTypes>; +extern template class SOFA_BASE_MECHANICS_API BarycentricMapperEdgeSetTopology< Vec3dTypes, ExtVec3fTypes>; +extern template class SOFA_BASE_MECHANICS_API BarycentricMapperTriangleSetTopology< Vec3dTypes, Vec3dTypes >; +extern template class SOFA_BASE_MECHANICS_API BarycentricMapperTriangleSetTopology< Vec3dTypes, ExtVec3fTypes >; +extern template class SOFA_BASE_MECHANICS_API BarycentricMapperQuadSetTopology< Vec3dTypes, Vec3dTypes >; +extern template class SOFA_BASE_MECHANICS_API BarycentricMapperQuadSetTopology< Vec3dTypes, ExtVec3fTypes >; +extern template class SOFA_BASE_MECHANICS_API BarycentricMapperTetrahedronSetTopology< Vec3dTypes, Vec3dTypes >; +extern template class SOFA_BASE_MECHANICS_API BarycentricMapperTetrahedronSetTopology< Vec3dTypes, ExtVec3fTypes >; +extern template class SOFA_BASE_MECHANICS_API BarycentricMapperHexahedronSetTopology< Vec3dTypes, Vec3dTypes >; +extern template class SOFA_BASE_MECHANICS_API BarycentricMapperHexahedronSetTopology< Vec3dTypes, ExtVec3fTypes >; #endif #ifndef SOFA_DOUBLE -extern template class SOFA_BASE_MECHANICS_API BarycentricMapping< sofa::defaulttype::Vec3fTypes, sofa::defaulttype::Vec3fTypes >; -extern template class SOFA_BASE_MECHANICS_API BarycentricMapping< sofa::defaulttype::Vec3fTypes, sofa::defaulttype::ExtVec3fTypes >; -extern template class SOFA_BASE_MECHANICS_API BarycentricMapper< sofa::defaulttype::Vec3fTypes, sofa::defaulttype::Vec3fTypes >; -extern template class SOFA_BASE_MECHANICS_API BarycentricMapper< sofa::defaulttype::Vec3fTypes, sofa::defaulttype::ExtVec3fTypes >; -extern template class SOFA_BASE_MECHANICS_API TopologyBarycentricMapper< sofa::defaulttype::Vec3fTypes, sofa::defaulttype::Vec3fTypes >; -extern template class SOFA_BASE_MECHANICS_API TopologyBarycentricMapper< sofa::defaulttype::Vec3fTypes, sofa::defaulttype::ExtVec3fTypes >; -extern template class SOFA_BASE_MECHANICS_API BarycentricMapperRegularGridTopology< sofa::defaulttype::Vec3fTypes, sofa::defaulttype::Vec3fTypes >; -extern template class SOFA_BASE_MECHANICS_API BarycentricMapperRegularGridTopology< sofa::defaulttype::Vec3fTypes, sofa::defaulttype::ExtVec3fTypes >; -extern template class SOFA_BASE_MECHANICS_API BarycentricMapperSparseGridTopology< sofa::defaulttype::Vec3fTypes, sofa::defaulttype::Vec3fTypes >; -extern template class SOFA_BASE_MECHANICS_API BarycentricMapperSparseGridTopology< sofa::defaulttype::Vec3fTypes, sofa::defaulttype::ExtVec3fTypes >; -extern template class SOFA_BASE_MECHANICS_API BarycentricMapperMeshTopology< sofa::defaulttype::Vec3fTypes, sofa::defaulttype::Vec3fTypes >; -extern template class SOFA_BASE_MECHANICS_API BarycentricMapperMeshTopology< sofa::defaulttype::Vec3fTypes, sofa::defaulttype::ExtVec3fTypes >; -extern template class SOFA_BASE_MECHANICS_API BarycentricMapperEdgeSetTopology< sofa::defaulttype::Vec3fTypes, sofa::defaulttype::Vec3fTypes >; -extern template class SOFA_BASE_MECHANICS_API BarycentricMapperEdgeSetTopology< sofa::defaulttype::Vec3fTypes, sofa::defaulttype::ExtVec3fTypes >; -extern template class SOFA_BASE_MECHANICS_API BarycentricMapperTriangleSetTopology< sofa::defaulttype::Vec3fTypes, sofa::defaulttype::Vec3fTypes >; -extern template class SOFA_BASE_MECHANICS_API BarycentricMapperTriangleSetTopology< sofa::defaulttype::Vec3fTypes, sofa::defaulttype::ExtVec3fTypes >; -extern template class SOFA_BASE_MECHANICS_API BarycentricMapperQuadSetTopology< sofa::defaulttype::Vec3fTypes, sofa::defaulttype::Vec3fTypes >; -extern template class SOFA_BASE_MECHANICS_API BarycentricMapperQuadSetTopology< sofa::defaulttype::Vec3fTypes, sofa::defaulttype::ExtVec3fTypes >; -extern template class SOFA_BASE_MECHANICS_API BarycentricMapperTetrahedronSetTopology< sofa::defaulttype::Vec3fTypes, sofa::defaulttype::Vec3fTypes >; -extern template class SOFA_BASE_MECHANICS_API BarycentricMapperTetrahedronSetTopology< sofa::defaulttype::Vec3fTypes, sofa::defaulttype::ExtVec3fTypes >; -extern template class SOFA_BASE_MECHANICS_API BarycentricMapperHexahedronSetTopology< sofa::defaulttype::Vec3fTypes, sofa::defaulttype::Vec3fTypes >; -extern template class SOFA_BASE_MECHANICS_API BarycentricMapperHexahedronSetTopology< sofa::defaulttype::Vec3fTypes, sofa::defaulttype::ExtVec3fTypes >; +extern template class SOFA_BASE_MECHANICS_API BarycentricMapping< Vec3fTypes, Vec3fTypes >; +extern template class SOFA_BASE_MECHANICS_API BarycentricMapping< Vec3fTypes, ExtVec3fTypes >; +extern template class SOFA_BASE_MECHANICS_API BarycentricMapper< Vec3fTypes, Vec3fTypes >; +extern template class SOFA_BASE_MECHANICS_API BarycentricMapper< Vec3fTypes, ExtVec3fTypes >; +extern template class SOFA_BASE_MECHANICS_API TopologyBarycentricMapper< Vec3fTypes, Vec3fTypes >; +extern template class SOFA_BASE_MECHANICS_API TopologyBarycentricMapper< Vec3fTypes, ExtVec3fTypes >; +extern template class SOFA_BASE_MECHANICS_API BarycentricMapperRegularGridTopology< Vec3fTypes, Vec3fTypes >; +extern template class SOFA_BASE_MECHANICS_API BarycentricMapperRegularGridTopology< Vec3fTypes, ExtVec3fTypes >; +extern template class SOFA_BASE_MECHANICS_API BarycentricMapperSparseGridTopology< Vec3fTypes, Vec3fTypes >; +extern template class SOFA_BASE_MECHANICS_API BarycentricMapperSparseGridTopology< Vec3fTypes, ExtVec3fTypes >; +extern template class SOFA_BASE_MECHANICS_API BarycentricMapperMeshTopology< Vec3fTypes, Vec3fTypes >; +extern template class SOFA_BASE_MECHANICS_API BarycentricMapperMeshTopology< Vec3fTypes, ExtVec3fTypes >; +extern template class SOFA_BASE_MECHANICS_API BarycentricMapperTopologyContainer< Vec3fTypes, Vec3fTypes , typename BarycentricMapper::MappingData1D>; +extern template class SOFA_BASE_MECHANICS_API BarycentricMapperTopologyContainer< Vec3fTypes, ExtVec3fTypes , typename BarycentricMapper::MappingData1D>; +extern template class SOFA_BASE_MECHANICS_API BarycentricMapperTopologyContainer< Vec3fTypes, Vec3fTypes , typename BarycentricMapper::MappingData2D>; +extern template class SOFA_BASE_MECHANICS_API BarycentricMapperTopologyContainer< Vec3fTypes, ExtVec3fTypes , typename BarycentricMapper::MappingData2D>; +extern template class SOFA_BASE_MECHANICS_API BarycentricMapperTopologyContainer< Vec3fTypes, Vec3fTypes , typename BarycentricMapper::MappingData3D>; +extern template class SOFA_BASE_MECHANICS_API BarycentricMapperTopologyContainer< Vec3fTypes, ExtVec3fTypes , typename BarycentricMapper::MappingData3D>; +extern template class SOFA_BASE_MECHANICS_API BarycentricMapperEdgeSetTopology< Vec3fTypes, Vec3fTypes>; +extern template class SOFA_BASE_MECHANICS_API BarycentricMapperEdgeSetTopology< Vec3fTypes, ExtVec3fTypes>; +extern template class SOFA_BASE_MECHANICS_API BarycentricMapperTriangleSetTopology< Vec3fTypes, Vec3fTypes >; +extern template class SOFA_BASE_MECHANICS_API BarycentricMapperTriangleSetTopology< Vec3fTypes, ExtVec3fTypes >; +extern template class SOFA_BASE_MECHANICS_API BarycentricMapperQuadSetTopology< Vec3fTypes, Vec3fTypes >; +extern template class SOFA_BASE_MECHANICS_API BarycentricMapperQuadSetTopology< Vec3fTypes, ExtVec3fTypes >; +extern template class SOFA_BASE_MECHANICS_API BarycentricMapperTetrahedronSetTopology< Vec3fTypes, Vec3fTypes >; +extern template class SOFA_BASE_MECHANICS_API BarycentricMapperTetrahedronSetTopology< Vec3fTypes, ExtVec3fTypes >; +extern template class SOFA_BASE_MECHANICS_API BarycentricMapperHexahedronSetTopology< Vec3fTypes, Vec3fTypes >; +extern template class SOFA_BASE_MECHANICS_API BarycentricMapperHexahedronSetTopology< Vec3fTypes, ExtVec3fTypes >; #endif #ifndef SOFA_FLOAT #ifndef SOFA_DOUBLE -extern template class SOFA_BASE_MECHANICS_API BarycentricMapping< sofa::defaulttype::Vec3dTypes, sofa::defaulttype::Vec3fTypes >; -extern template class SOFA_BASE_MECHANICS_API BarycentricMapping< sofa::defaulttype::Vec3fTypes, sofa::defaulttype::Vec3dTypes >; -extern template class SOFA_BASE_MECHANICS_API BarycentricMapper< sofa::defaulttype::Vec3dTypes, sofa::defaulttype::Vec3fTypes >; -extern template class SOFA_BASE_MECHANICS_API BarycentricMapper< sofa::defaulttype::Vec3fTypes, sofa::defaulttype::Vec3dTypes >; -extern template class SOFA_BASE_MECHANICS_API TopologyBarycentricMapper< sofa::defaulttype::Vec3dTypes, sofa::defaulttype::Vec3fTypes >; -extern template class SOFA_BASE_MECHANICS_API TopologyBarycentricMapper< sofa::defaulttype::Vec3fTypes, sofa::defaulttype::Vec3dTypes >; -extern template class SOFA_BASE_MECHANICS_API BarycentricMapperRegularGridTopology< sofa::defaulttype::Vec3dTypes, sofa::defaulttype::Vec3fTypes >; -extern template class SOFA_BASE_MECHANICS_API BarycentricMapperRegularGridTopology< sofa::defaulttype::Vec3fTypes, sofa::defaulttype::Vec3dTypes >; -extern template class SOFA_BASE_MECHANICS_API BarycentricMapperSparseGridTopology< sofa::defaulttype::Vec3dTypes, sofa::defaulttype::Vec3fTypes >; -extern template class SOFA_BASE_MECHANICS_API BarycentricMapperSparseGridTopology< sofa::defaulttype::Vec3fTypes, sofa::defaulttype::Vec3dTypes >; -extern template class SOFA_BASE_MECHANICS_API BarycentricMapperMeshTopology< sofa::defaulttype::Vec3dTypes, sofa::defaulttype::Vec3fTypes >; -extern template class SOFA_BASE_MECHANICS_API BarycentricMapperMeshTopology< sofa::defaulttype::Vec3fTypes, sofa::defaulttype::Vec3dTypes >; -extern template class SOFA_BASE_MECHANICS_API BarycentricMapperEdgeSetTopology< sofa::defaulttype::Vec3dTypes, sofa::defaulttype::Vec3fTypes >; -extern template class SOFA_BASE_MECHANICS_API BarycentricMapperEdgeSetTopology< sofa::defaulttype::Vec3fTypes, sofa::defaulttype::Vec3dTypes >; -extern template class SOFA_BASE_MECHANICS_API BarycentricMapperTriangleSetTopology< sofa::defaulttype::Vec3dTypes, sofa::defaulttype::Vec3fTypes >; -extern template class SOFA_BASE_MECHANICS_API BarycentricMapperTriangleSetTopology< sofa::defaulttype::Vec3fTypes, sofa::defaulttype::Vec3dTypes >; -extern template class SOFA_BASE_MECHANICS_API BarycentricMapperQuadSetTopology< sofa::defaulttype::Vec3dTypes, sofa::defaulttype::Vec3fTypes >; -extern template class SOFA_BASE_MECHANICS_API BarycentricMapperQuadSetTopology< sofa::defaulttype::Vec3fTypes, sofa::defaulttype::Vec3dTypes >; -extern template class SOFA_BASE_MECHANICS_API BarycentricMapperTetrahedronSetTopology< sofa::defaulttype::Vec3dTypes, sofa::defaulttype::Vec3fTypes >; -extern template class SOFA_BASE_MECHANICS_API BarycentricMapperTetrahedronSetTopology< sofa::defaulttype::Vec3fTypes, sofa::defaulttype::Vec3dTypes >; -extern template class SOFA_BASE_MECHANICS_API BarycentricMapperHexahedronSetTopology< sofa::defaulttype::Vec3dTypes, sofa::defaulttype::Vec3fTypes >; -extern template class SOFA_BASE_MECHANICS_API BarycentricMapperHexahedronSetTopology< sofa::defaulttype::Vec3fTypes, sofa::defaulttype::Vec3dTypes >; +extern template class SOFA_BASE_MECHANICS_API BarycentricMapping< Vec3dTypes, Vec3fTypes >; +extern template class SOFA_BASE_MECHANICS_API BarycentricMapping< Vec3fTypes, Vec3dTypes >; +extern template class SOFA_BASE_MECHANICS_API BarycentricMapper< Vec3dTypes, Vec3fTypes >; +extern template class SOFA_BASE_MECHANICS_API BarycentricMapper< Vec3fTypes, Vec3dTypes >; +extern template class SOFA_BASE_MECHANICS_API TopologyBarycentricMapper< Vec3dTypes, Vec3fTypes >; +extern template class SOFA_BASE_MECHANICS_API TopologyBarycentricMapper< Vec3fTypes, Vec3dTypes >; +extern template class SOFA_BASE_MECHANICS_API BarycentricMapperRegularGridTopology< Vec3dTypes, Vec3fTypes >; +extern template class SOFA_BASE_MECHANICS_API BarycentricMapperRegularGridTopology< Vec3fTypes, Vec3dTypes >; +extern template class SOFA_BASE_MECHANICS_API BarycentricMapperSparseGridTopology< Vec3dTypes, Vec3fTypes >; +extern template class SOFA_BASE_MECHANICS_API BarycentricMapperSparseGridTopology< Vec3fTypes, Vec3dTypes >; +extern template class SOFA_BASE_MECHANICS_API BarycentricMapperMeshTopology< Vec3dTypes, Vec3fTypes >; +extern template class SOFA_BASE_MECHANICS_API BarycentricMapperMeshTopology< Vec3fTypes, Vec3dTypes >; +extern template class SOFA_BASE_MECHANICS_API BarycentricMapperTopologyContainer< Vec3dTypes, Vec3fTypes , typename BarycentricMapper::MappingData1D>; +extern template class SOFA_BASE_MECHANICS_API BarycentricMapperTopologyContainer< Vec3fTypes, Vec3dTypes , typename BarycentricMapper::MappingData1D>; +extern template class SOFA_BASE_MECHANICS_API BarycentricMapperTopologyContainer< Vec3dTypes, Vec3fTypes , typename BarycentricMapper::MappingData2D>; +extern template class SOFA_BASE_MECHANICS_API BarycentricMapperTopologyContainer< Vec3fTypes, Vec3dTypes , typename BarycentricMapper::MappingData2D>; +extern template class SOFA_BASE_MECHANICS_API BarycentricMapperTopologyContainer< Vec3dTypes, Vec3fTypes , typename BarycentricMapper::MappingData3D>; +extern template class SOFA_BASE_MECHANICS_API BarycentricMapperTopologyContainer< Vec3fTypes, Vec3dTypes , typename BarycentricMapper::MappingData3D>; +extern template class SOFA_BASE_MECHANICS_API BarycentricMapperEdgeSetTopology< Vec3dTypes, Vec3fTypes>; +extern template class SOFA_BASE_MECHANICS_API BarycentricMapperEdgeSetTopology< Vec3fTypes, Vec3dTypes>; +extern template class SOFA_BASE_MECHANICS_API BarycentricMapperTriangleSetTopology< Vec3dTypes, Vec3fTypes >; +extern template class SOFA_BASE_MECHANICS_API BarycentricMapperTriangleSetTopology< Vec3fTypes, Vec3dTypes >; +extern template class SOFA_BASE_MECHANICS_API BarycentricMapperQuadSetTopology< Vec3dTypes, Vec3fTypes >; +extern template class SOFA_BASE_MECHANICS_API BarycentricMapperQuadSetTopology< Vec3fTypes, Vec3dTypes >; +extern template class SOFA_BASE_MECHANICS_API BarycentricMapperTetrahedronSetTopology< Vec3dTypes, Vec3fTypes >; +extern template class SOFA_BASE_MECHANICS_API BarycentricMapperTetrahedronSetTopology< Vec3fTypes, Vec3dTypes >; +extern template class SOFA_BASE_MECHANICS_API BarycentricMapperHexahedronSetTopology< Vec3dTypes, Vec3fTypes >; +extern template class SOFA_BASE_MECHANICS_API BarycentricMapperHexahedronSetTopology< Vec3fTypes, Vec3dTypes >; #endif #endif #endif diff --git a/SofaKernel/modules/SofaBaseMechanics/BarycentricMapping.inl b/SofaKernel/modules/SofaBaseMechanics/BarycentricMapping.inl index 3414eb4c0fd..3b4d9c11fce 100644 --- a/SofaKernel/modules/SofaBaseMechanics/BarycentricMapping.inl +++ b/SofaKernel/modules/SofaBaseMechanics/BarycentricMapping.inl @@ -59,10 +59,30 @@ namespace component namespace mapping { +using sofa::defaulttype::Vector3; +using sofa::defaulttype::Matrix3; +using sofa::defaulttype::Mat3x3d; +using sofa::defaulttype::Vec3d; +// 10/18 E.Coevoet: what's the difference between edge/line, tetra/tetrahedron, hexa/hexahedron? +typedef typename sofa::core::topology::BaseMeshTopology::Line Line; +typedef typename sofa::core::topology::BaseMeshTopology::Line Edge; +typedef typename sofa::core::topology::BaseMeshTopology::Triangle Triangle; +typedef typename sofa::core::topology::BaseMeshTopology::Quad Quad; +typedef typename sofa::core::topology::BaseMeshTopology::Tetra Tetra; +typedef typename sofa::core::topology::BaseMeshTopology::Tetrahedron Tetrahedron; +typedef typename sofa::core::topology::BaseMeshTopology::Hexa Hexa; +typedef typename sofa::core::topology::BaseMeshTopology::Hexahedron Hexahedron; +typedef typename sofa::core::topology::BaseMeshTopology::SeqLines SeqLines; +typedef typename sofa::core::topology::BaseMeshTopology::SeqEdges SeqEdges; +typedef typename sofa::core::topology::BaseMeshTopology::SeqTriangles SeqTriangles; +typedef typename sofa::core::topology::BaseMeshTopology::SeqQuads SeqQuads; +typedef typename sofa::core::topology::BaseMeshTopology::SeqTetrahedra SeqTetrahedra; +typedef typename sofa::core::topology::BaseMeshTopology::SeqHexahedra SeqHexahedra; + template BarycentricMapping::BarycentricMapping() : Inherit() - , mapper(initLink("mapper","Internal mapper created depending on the type of topology")) + , m_mapper(initLink("mapper","Internal mapper created depending on the type of topology")) , useRestPosition(core::objectmodel::Base::initData(&useRestPosition, false, "useRestPosition", "Use the rest position of the input and output models to initialize the mapping")) #ifdef SOFA_DEV , sleeping(core::objectmodel::Base::initData(&sleeping, false, "sleeping", "is the mapping sleeping (not computed)")) @@ -73,7 +93,7 @@ BarycentricMapping::BarycentricMapping() template BarycentricMapping::BarycentricMapping(core::State* from, core::State* to, typename Mapper::SPtr mapper) : Inherit ( from, to ) - , mapper(initLink("mapper","Internal mapper created depending on the type of topology"), mapper) + , m_mapper(initLink("mapper","Internal mapper created depending on the type of topology"), mapper) #ifdef SOFA_DEV , sleeping(core::objectmodel::Base::initData(&sleeping, false, "sleeping", "is the mapping sleeping (not computed)")) #endif @@ -85,7 +105,7 @@ BarycentricMapping::BarycentricMapping(core::State* from, core::S template BarycentricMapping::BarycentricMapping (core::State* from, core::State* to, BaseMeshTopology * topology ) : Inherit ( from, to ) - , mapper (initLink("mapper","Internal mapper created depending on the type of topology")) + , m_mapper (initLink("mapper","Internal mapper created depending on the type of topology")) #ifdef SOFA_DEV , sleeping(core::objectmodel::Base::initData(&sleeping, false, "sleeping", "is the mapping sleeping (not computed)")) #endif @@ -102,44 +122,41 @@ BarycentricMapping::~BarycentricMapping() } template -void BarycentricMapperRegularGridTopology::clear ( int reserve ) +void BarycentricMapperRegularGridTopology::clearMapAndReserve ( int size ) { updateJ = true; - map.clear(); - if ( reserve>0 ) map.reserve ( reserve ); + m_map.clear(); + if ( size>0 ) m_map.reserve ( size ); } template int BarycentricMapperRegularGridTopology::addPointInCube ( const int cubeIndex, const SReal* baryCoords ) { - map.resize ( map.size() +1 ); - CubeData& data = *map.rbegin(); + m_map.resize ( m_map.size() +1 ); + CubeData& data = *m_map.rbegin(); data.in_index = cubeIndex; data.baryCoords[0] = ( Real ) baryCoords[0]; data.baryCoords[1] = ( Real ) baryCoords[1]; data.baryCoords[2] = ( Real ) baryCoords[2]; - return (int)map.size()-1; + return (int)m_map.size()-1; } template -void BarycentricMapperRegularGridTopology::init ( const typename Out::VecCoord& out, const typename In::VecCoord& /*in*/ ) +void BarycentricMapperRegularGridTopology::init ( const typename Out::VecCoord& out, const typename In::VecCoord& in ) { - //if ( map.size() != 0 ) return; + SOFA_UNUSED(in); + updateJ = true; - int outside = 0; - clear ( (int)out.size() ); - if ( fromTopology->isVolume() ) + clearMapAndReserve ( (int)out.size() ); + if ( m_fromTopology->isVolume() ) { for ( unsigned int i=0; ifindCube ( sofa::defaulttype::Vector3 ( Out::getCPos(out[i]) ), coefs[0], coefs[1], coefs[2] ); + Vector3 coefs; + int cube = m_fromTopology->findCube ( Vector3 ( Out::getCPos(out[i]) ), coefs[0], coefs[1], coefs[2] ); if ( cube==-1 ) - { - ++outside; - cube = fromTopology->findNearestCube ( sofa::defaulttype::Vector3 ( Out::getCPos(out[i]) ), coefs[0], coefs[1], coefs[2] ); - } + cube = m_fromTopology->findNearestCube ( Vector3 ( Out::getCPos(out[i]) ), coefs[0], coefs[1], coefs[2] ); this->addPointInCube ( cube, coefs.ptr() ); } @@ -147,141 +164,147 @@ void BarycentricMapperRegularGridTopology::init ( const typename Out::Ve } template -void BarycentricMapperSparseGridTopology::clear ( int reserve ) +void BarycentricMapperSparseGridTopology::clearMapAndReserve ( int size ) { updateJ = true; - map.clear(); - if ( reserve>0 ) map.reserve ( reserve ); + m_map.clear(); + if ( size>0 ) m_map.reserve ( size ); } template int BarycentricMapperSparseGridTopology::addPointInCube ( const int cubeIndex, const SReal* baryCoords ) { - map.resize ( map.size() +1 ); - CubeData& data = *map.rbegin(); + m_map.resize ( m_map.size() +1 ); + CubeData& data = *m_map.rbegin(); data.in_index = cubeIndex; data.baryCoords[0] = ( Real ) baryCoords[0]; data.baryCoords[1] = ( Real ) baryCoords[1]; data.baryCoords[2] = ( Real ) baryCoords[2]; - return (int)map.size()-1; + return (int)m_map.size()-1; } template void BarycentricMapperSparseGridTopology::init ( const typename Out::VecCoord& out, const typename In::VecCoord& /*in*/ ) { - if ( this->map.size() != 0 ) return; + if ( this->m_map.size() != 0 ) return; updateJ = true; - int outside = 0; - clear ( (int)out.size() ); + clearMapAndReserve ( (int)out.size() ); - if ( fromTopology->isVolume() ) + if ( m_fromTopology->isVolume() ) { for ( unsigned int i=0; ifindCube ( sofa::defaulttype::Vector3 ( Out::getCPos(out[i]) ), coefs[0], coefs[1], coefs[2] ); + Vector3 coefs; + int cube = m_fromTopology->findCube ( Vector3 ( Out::getCPos(out[i]) ), coefs[0], coefs[1], coefs[2] ); if ( cube==-1 ) { - ++outside; - cube = fromTopology->findNearestCube ( sofa::defaulttype::Vector3 ( Out::getCPos(out[i]) ), coefs[0], coefs[1], coefs[2] ); + cube = m_fromTopology->findNearestCube ( Vector3 ( Out::getCPos(out[i]) ), coefs[0], coefs[1], coefs[2] ); } - sofa::defaulttype::Vector3 baryCoords = coefs; + Vector3 baryCoords = coefs; this->addPointInCube ( cube, baryCoords.ptr() ); } } } template -void BarycentricMapperMeshTopology::clear1d ( int reserve ) +void BarycentricMapperMeshTopology::clearMap1dAndReserve ( int size ) { - updateJ = true; - map1d.clear(); if ( reserve>0 ) map1d.reserve ( reserve ); + m_updateJ = true; + m_map1d.clear(); + if ( size>0 ) m_map1d.reserve ( size ); } template -void BarycentricMapperMeshTopology::clear2d ( int reserve ) +void BarycentricMapperMeshTopology::clearMap2dAndReserve ( int size ) { - updateJ = true; - map2d.clear(); if ( reserve>0 ) map2d.reserve ( reserve ); + m_updateJ = true; + m_map2d.clear(); + if ( size>0 ) m_map2d.reserve ( size ); } template -void BarycentricMapperMeshTopology::clear3d ( int reserve ) +void BarycentricMapperMeshTopology::clearMap3dAndReserve ( int size ) { - updateJ = true; - map3d.clear(); if ( reserve>0 ) map3d.reserve ( reserve ); + m_updateJ = true; + m_map3d.clear(); + if ( size>0 ) m_map3d.reserve ( size ); } template -void BarycentricMapperMeshTopology::clear ( int reserve ) +void BarycentricMapperMeshTopology::clearMapAndReserve ( int size ) { - updateJ = true; - map1d.clear(); if ( reserve>0 ) map1d.reserve ( reserve ); - map2d.clear(); if ( reserve>0 ) map2d.reserve ( reserve ); - map3d.clear(); if ( reserve>0 ) map3d.reserve ( reserve ); + m_updateJ = true; + m_map1d.clear(); + if ( size>0 ) m_map1d.reserve ( size ); + + m_map2d.clear(); + if ( size>0 ) m_map2d.reserve ( size ); + + m_map3d.clear(); + if ( size>0 ) m_map3d.reserve ( size ); } template int BarycentricMapperMeshTopology::addPointInLine ( const int lineIndex, const SReal* baryCoords ) { - map1d.resize ( map1d.size() +1 ); - MappingData1D& data = *map1d.rbegin(); + m_map1d.resize ( m_map1d.size() +1 ); + MappingData1D& data = *m_map1d.rbegin(); data.in_index = lineIndex; data.baryCoords[0] = ( Real ) baryCoords[0]; - return (int)map1d.size()-1; + return (int)m_map1d.size()-1; } template int BarycentricMapperMeshTopology::addPointInTriangle ( const int triangleIndex, const SReal* baryCoords ) { - map2d.resize ( map2d.size() +1 ); - MappingData2D& data = *map2d.rbegin(); + m_map2d.resize ( m_map2d.size() +1 ); + MappingData2D& data = *m_map2d.rbegin(); data.in_index = triangleIndex; data.baryCoords[0] = ( Real ) baryCoords[0]; data.baryCoords[1] = ( Real ) baryCoords[1]; - return (int)map2d.size()-1; + return (int)m_map2d.size()-1; } template int BarycentricMapperMeshTopology::addPointInQuad ( const int quadIndex, const SReal* baryCoords ) { - map2d.resize ( map2d.size() +1 ); - MappingData2D& data = *map2d.rbegin(); - data.in_index = quadIndex + this->fromTopology->getNbTriangles(); + m_map2d.resize ( m_map2d.size() +1 ); + MappingData2D& data = *m_map2d.rbegin(); + data.in_index = quadIndex + this->m_fromTopology->getNbTriangles(); data.baryCoords[0] = ( Real ) baryCoords[0]; data.baryCoords[1] = ( Real ) baryCoords[1]; - return (int)map2d.size()-1; + return (int)m_map2d.size()-1; } template int BarycentricMapperMeshTopology::addPointInTetra ( const int tetraIndex, const SReal* baryCoords ) { - map3d.resize ( map3d.size() +1 ); - MappingData3D& data = *map3d.rbegin(); + m_map3d.resize ( m_map3d.size() +1 ); + MappingData3D& data = *m_map3d.rbegin(); data.in_index = tetraIndex; data.baryCoords[0] = ( Real ) baryCoords[0]; data.baryCoords[1] = ( Real ) baryCoords[1]; data.baryCoords[2] = ( Real ) baryCoords[2]; - return (int)map3d.size()-1; + return (int)m_map3d.size()-1; } template int BarycentricMapperMeshTopology::addPointInCube ( const int cubeIndex, const SReal* baryCoords ) { - map3d.resize ( map3d.size() +1 ); - MappingData3D& data = *map3d.rbegin(); - data.in_index = cubeIndex + this->fromTopology->getNbTetrahedra(); + m_map3d.resize ( m_map3d.size() +1 ); + MappingData3D& data = *m_map3d.rbegin(); + data.in_index = cubeIndex + this->m_fromTopology->getNbTetrahedra(); data.baryCoords[0] = ( Real ) baryCoords[0]; data.baryCoords[1] = ( Real ) baryCoords[1]; data.baryCoords[2] = ( Real ) baryCoords[2]; - return (int)map3d.size()-1; + return (int)m_map3d.size()-1; } template int BarycentricMapperMeshTopology::createPointInLine ( const typename Out::Coord& p, int lineIndex, const typename In::VecCoord* points ) { SReal baryCoords[1]; - const sofa::core::topology::BaseMeshTopology::Line& elem = this->fromTopology->getLine ( lineIndex ); + const Line& elem = this->m_fromTopology->getLine ( lineIndex ); const typename In::Coord p0 = ( *points ) [elem[0]]; const typename In::Coord pA = ( *points ) [elem[1]] - p0; typename In::Coord pos = Out::getCPos(p) - p0; @@ -293,7 +316,7 @@ template int BarycentricMapperMeshTopology::createPointInTriangle ( const typename Out::Coord& p, int triangleIndex, const typename In::VecCoord* points ) { SReal baryCoords[2]; - const sofa::core::topology::BaseMeshTopology::Triangle& elem = this->fromTopology->getTriangle ( triangleIndex ); + const Triangle& elem = this->m_fromTopology->getTriangle ( triangleIndex ); const typename In::Coord & p1 = ( *points ) [elem[0]]; const typename In::Coord & p2 = ( *points ) [elem[1]]; @@ -373,7 +396,7 @@ template int BarycentricMapperMeshTopology::createPointInQuad ( const typename Out::Coord& p, int quadIndex, const typename In::VecCoord* points ) { SReal baryCoords[2]; - const sofa::core::topology::BaseMeshTopology::Quad& elem = this->fromTopology->getQuad ( quadIndex ); + const Quad& elem = this->m_fromTopology->getQuad ( quadIndex ); const typename In::Coord p0 = ( *points ) [elem[0]]; const typename In::Coord pA = ( *points ) [elem[1]] - p0; const typename In::Coord pB = ( *points ) [elem[3]] - p0; @@ -394,36 +417,33 @@ int BarycentricMapperMeshTopology::createPointInQuad ( const typename Ou template void BarycentricMapperMeshTopology::init ( const typename Out::VecCoord& out, const typename In::VecCoord& in ) { - int outside = 0; - updateJ = true; + m_updateJ = true; - const sofa::core::topology::BaseMeshTopology::SeqTetrahedra& tetrahedra = this->fromTopology->getTetrahedra(); - const sofa::core::topology::BaseMeshTopology::SeqHexahedra& cubes = this->fromTopology->getHexahedra(); + const SeqTetrahedra& tetras = this->m_fromTopology->getTetrahedra(); + const SeqHexahedra& hexas = this->m_fromTopology->getHexahedra(); - const sofa::core::topology::BaseMeshTopology::SeqTriangles& triangles = this->fromTopology->getTriangles(); - const sofa::core::topology::BaseMeshTopology::SeqQuads& quads = this->fromTopology->getQuads(); - sofa::helper::vector bases; - sofa::helper::vector centers; - if ( tetrahedra.empty() && cubes.empty() ) + const SeqTriangles& triangles = this->m_fromTopology->getTriangles(); + const SeqQuads& quads = this->m_fromTopology->getQuads(); + helper::vector bases; + helper::vector centers; + if ( tetras.empty() && hexas.empty() ) { if ( triangles.empty() && quads.empty() ) { - //no 3D elements, nor 2D elements -> map on 1D elements - - const sofa::core::topology::BaseMeshTopology::SeqEdges& edges = this->fromTopology->getEdges(); + const SeqEdges& edges = this->m_fromTopology->getEdges(); if ( edges.empty() ) return; - clear1d ( (int)out.size() ); + clearMap1dAndReserve ( (int)out.size() ); - sofa::helper::vector< SReal > lengthEdges; - sofa::helper::vector< sofa::defaulttype::Vector3 > unitaryVectors; + helper::vector< SReal > lengthEdges; + helper::vector< Vector3 > unitaryVectors; unsigned int e; for ( e=0; e::init ( const typename Out::VecCoord& for ( e=0; e= 0 && coef <= 1 ) {addPointInLine ( e,&coef ); break; } } //If no good coefficient has been found, we add to the last element if ( e == edges.size() ) addPointInLine ( (int)edges.size()-1,&coef ); - } } else { - // no 3D elements -> map on 2D elements - clear2d ( (int)out.size() ); // reserve space for 2D mapping - size_t c0 = triangles.size(); + clearMap2dAndReserve ( (int)out.size() ); + size_t nbTriangles = triangles.size(); bases.resize ( triangles.size() +quads.size() ); centers.resize ( triangles.size() +quads.size() ); for ( unsigned int t = 0; t < triangles.size(); t++ ) { - sofa::defaulttype::Mat3x3d m,mt; + Mat3x3d m,mt; m[0] = in[triangles[t][1]]-in[triangles[t][0]]; m[1] = in[triangles[t][2]]-in[triangles[t][0]]; m[2] = cross ( m[0],m[1] ); @@ -461,135 +479,116 @@ void BarycentricMapperMeshTopology::init ( const typename Out::VecCoord& bases[t].invert ( mt ); centers[t] = ( in[triangles[t][0]]+in[triangles[t][1]]+in[triangles[t][2]] ) /3; } - for ( unsigned int c = 0; c < quads.size(); c++ ) + for ( unsigned int q = 0; q < quads.size(); q++ ) { - sofa::defaulttype::Mat3x3d m,mt; - m[0] = in[quads[c][1]]-in[quads[c][0]]; - m[1] = in[quads[c][3]]-in[quads[c][0]]; + Mat3x3d m,mt; + m[0] = in[quads[q][1]]-in[quads[q][0]]; + m[1] = in[quads[q][3]]-in[quads[q][0]]; m[2] = cross ( m[0],m[1] ); mt.transpose ( m ); - bases[c0+c].invert ( mt ); - centers[c0+c] = ( in[quads[c][0]]+in[quads[c][1]]+in[quads[c][2]]+in[quads[c][3]] ) *0.25; + bases[nbTriangles+q].invert ( mt ); + centers[nbTriangles+q] = ( in[quads[q][0]]+in[quads[q][1]]+in[quads[q][2]]+in[quads[q][3]] ) *0.25; } for ( unsigned int i=0; i0 ) d = ( pos-centers[t] ).norm2(); if ( d0 ) d = ( pos-centers[c0+c] ).norm2(); - if ( d0 ) - { - ++outside; + if ( d>0 ) d = ( pos-centers[nbTriangles+q] ).norm2(); + if ( d0 ) d = ( pos-centers[t] ).norm2(); if ( d0 ) d = ( pos-centers[c0+c] ).norm2(); - if ( d0 ) - { - ++outside; + if ( d>0 ) d = ( pos-centers[nbTetras+h] ).norm2(); + if ( d -void BarycentricMapperEdgeSetTopology::clear ( int reserve ) +template +int BarycentricMapperEdgeSetTopology::addPointInLine ( const int edgeIndex, const SReal* baryCoords ) { - helper::vector& vectorData = *(map.beginEdit()); - vectorData.clear(); if ( reserve>0 ) vectorData.reserve ( reserve ); - map.endEdit(); -} - - -template -int BarycentricMapperEdgeSetTopology::addPointInLine ( const int edgeIndex, const SReal* baryCoords ) -{ - helper::vector& vectorData = *(map.beginEdit()); - vectorData.resize ( map.getValue().size() +1 ); - map.endEdit(); + helper::vector& vectorData = *(d_map.beginEdit()); + vectorData.resize ( d_map.getValue().size() +1 ); + d_map.endEdit(); MappingData& data = *vectorData.rbegin(); data.in_index = edgeIndex; data.baryCoords[0] = ( Real ) baryCoords[0]; - return (int)map.getValue().size()-1; + return (int)d_map.getValue().size()-1; } -template -int BarycentricMapperEdgeSetTopology::createPointInLine ( const typename Out::Coord& p, int edgeIndex, const typename In::VecCoord* points ) +template +int BarycentricMapperEdgeSetTopology::createPointInLine ( const typename Out::Coord& p, int edgeIndex, const typename In::VecCoord* points ) { SReal baryCoords[1]; - const core::topology::BaseMeshTopology::Edge& elem = this->fromTopology->getEdge ( edgeIndex ); + const Edge& elem = this->m_fromTopology->getEdge ( edgeIndex ); const typename In::Coord p0 = ( *points ) [elem[0]]; const typename In::Coord pA = ( *points ) [elem[1]] - p0; typename In::Coord pos = Out::getCPos(p) - p0; @@ -597,48 +596,30 @@ int BarycentricMapperEdgeSetTopology::createPointInLine ( const typename return this->addPointInLine ( edgeIndex, baryCoords ); } -template -void BarycentricMapperEdgeSetTopology::init ( const typename Out::VecCoord& /*out*/, const typename In::VecCoord& /*in*/ ) +template +void BarycentricMapperEdgeSetTopology::init ( const typename Out::VecCoord& /*out*/, const typename In::VecCoord& /*in*/ ) { - _fromContainer->getContext()->get ( _fromGeomAlgo ); - // Why do we need that ? is reset the map in case of topology change -// if (this->toTopology) -// { -// map.createTopologicalEngine(this->toTopology); -// map.registerTopologicalData(); -// } - - // int outside = 0; - // const sofa::helper::vector& edges = this->fromTopology->getEdges(); - //TODO: implementation of BarycentricMapperEdgeSetTopology::init + m_fromContainer->getContext()->get ( m_fromGeomAlgo ); } -template -void BarycentricMapperTriangleSetTopology::clear ( int reserve ) -{ - helper::vector& vectorData = *(map.beginEdit()); - vectorData.clear(); if ( reserve>0 ) vectorData.reserve ( reserve ); - map.endEdit(); -} - -template -int BarycentricMapperTriangleSetTopology::addPointInTriangle ( const int triangleIndex, const SReal* baryCoords ) +template +int BarycentricMapperTriangleSetTopology::addPointInTriangle ( const int triangleIndex, const SReal* baryCoords ) { - helper::vector& vectorData = *(map.beginEdit()); - vectorData.resize ( map.getValue().size() +1 ); + helper::vector& vectorData = *(d_map.beginEdit()); + vectorData.resize ( d_map.getValue().size() +1 ); MappingData& data = *vectorData.rbegin(); - map.endEdit(); + d_map.endEdit(); data.in_index = triangleIndex; data.baryCoords[0] = ( Real ) baryCoords[0]; data.baryCoords[1] = ( Real ) baryCoords[1]; - return (int)map.getValue().size()-1; + return (int)d_map.getValue().size()-1; } -template -int BarycentricMapperTriangleSetTopology::createPointInTriangle ( const typename Out::Coord& p, int triangleIndex, const typename In::VecCoord* points ) +template +int BarycentricMapperTriangleSetTopology::createPointInTriangle ( const typename Out::Coord& p, int triangleIndex, const typename In::VecCoord* points ) { SReal baryCoords[2]; - const core::topology::BaseMeshTopology::Triangle& elem = this->fromTopology->getTriangle ( triangleIndex ); + const Triangle& elem = this->m_fromTopology->getTriangle ( triangleIndex ); const typename In::Coord p0 = ( *points ) [elem[0]]; const typename In::Coord pA = ( *points ) [elem[1]] - p0; const typename In::Coord pB = ( *points ) [elem[2]] - p0; @@ -652,32 +633,22 @@ int BarycentricMapperTriangleSetTopology::createPointInTriangle ( const return this->addPointInTriangle ( triangleIndex, baryCoords ); } -template -void BarycentricMapperTriangleSetTopology::init ( const typename Out::VecCoord& out, const typename In::VecCoord& in ) +template +void BarycentricMapperTriangleSetTopology::init ( const typename Out::VecCoord& out, const typename In::VecCoord& in ) { - _fromContainer->getContext()->get ( _fromGeomAlgo ); - - // Why do we need that ? it reset the map in case of topology change -// if (this->toTopology) -// { -// map.createTopologicalEngine(this->toTopology); -// map.registerTopologicalData(); -// } + m_fromContainer->getContext()->get ( m_fromGeomAlgo ); - int outside = 0; + const helper::vector& triangles = this->m_fromTopology->getTriangles(); + helper::vector bases; + helper::vector centers; - const sofa::helper::vector& triangles = this->fromTopology->getTriangles(); - sofa::helper::vector bases; - sofa::helper::vector centers; - - // no 3D elements -> map on 2D elements - clear ( (int)out.size() ); // reserve space for 2D mapping + this->clearMapAndReserve ( (int)out.size() ); bases.resize ( triangles.size() ); centers.resize ( triangles.size() ); for ( unsigned int t = 0; t < triangles.size(); t++ ) { - sofa::defaulttype::Mat3x3d m,mt; + Mat3x3d m,mt; m[0] = in[triangles[t][1]]-in[triangles[t][0]]; m[1] = in[triangles[t][2]]-in[triangles[t][0]]; m[2] = cross ( m[0],m[1] ); @@ -688,51 +659,39 @@ void BarycentricMapperTriangleSetTopology::init ( const typename Out::Ve for ( unsigned int i=0; i0 ) d = ( pos-centers[t] ).norm2(); - if ( d0 ) - { - ++outside; - } - addPointInTriangle ( index, coefs.ptr() ); + addPointInTriangle ( triangleIndex, baryCoords.ptr() ); } } -template -void BarycentricMapperQuadSetTopology::clear ( int reserve ) -{ - helper::vector& vectorData = *(map.beginEdit()); - vectorData.clear(); if ( reserve>0 ) vectorData.reserve ( reserve ); - map.beginEdit(); -} - -template -int BarycentricMapperQuadSetTopology::addPointInQuad ( const int quadIndex, const SReal* baryCoords ) +template +int BarycentricMapperQuadSetTopology::addPointInQuad ( const int quadIndex, const SReal* baryCoords ) { - helper::vector& vectorData = *(map.beginEdit()); - vectorData.resize ( map.getValue().size() +1 ); + helper::vector& vectorData = *(d_map.beginEdit()); + vectorData.resize ( d_map.getValue().size() +1 ); MappingData& data = *vectorData.rbegin(); - map.endEdit(); + d_map.endEdit(); data.in_index = quadIndex; data.baryCoords[0] = ( Real ) baryCoords[0]; data.baryCoords[1] = ( Real ) baryCoords[1]; - return (int)map.getValue().size()-1; + return (int)d_map.getValue().size()-1; } -template -int BarycentricMapperQuadSetTopology::createPointInQuad ( const typename Out::Coord& p, int quadIndex, const typename In::VecCoord* points ) +template +int BarycentricMapperQuadSetTopology::createPointInQuad ( const typename Out::Coord& p, int quadIndex, const typename In::VecCoord* points ) { SReal baryCoords[2]; - const core::topology::BaseMeshTopology::Quad& elem = this->fromTopology->getQuad ( quadIndex ); + const Quad& elem = this->m_fromTopology->getQuad ( quadIndex ); const typename In::Coord p0 = ( *points ) [elem[0]]; const typename In::Coord pA = ( *points ) [elem[1]] - p0; const typename In::Coord pB = ( *points ) [elem[3]] - p0; @@ -750,30 +709,23 @@ int BarycentricMapperQuadSetTopology::createPointInQuad ( const typename return this->addPointInQuad ( quadIndex, baryCoords ); } -template -void BarycentricMapperQuadSetTopology::init ( const typename Out::VecCoord& out, const typename In::VecCoord& in ) +template +void BarycentricMapperQuadSetTopology::init ( const typename Out::VecCoord& out, const typename In::VecCoord& in ) { - _fromContainer->getContext()->get ( _fromGeomAlgo ); - // Why do we need that ? is reset the map in case of topology change -// if (this->toTopology) -// { -// map.createTopologicalEngine(this->toTopology); -// map.registerTopologicalData(); -// } + m_fromContainer->getContext()->get ( m_fromGeomAlgo ); - int outside = 0; - const sofa::helper::vector& quads = this->fromTopology->getQuads(); + const helper::vector& quads = this->m_fromTopology->getQuads(); - sofa::helper::vector< sofa::defaulttype::Matrix3> bases; - sofa::helper::vector< sofa::defaulttype::Vector3> centers; + helper::vector< Matrix3> bases; + helper::vector< Vector3> centers; - clear ( (int)out.size() ); + this->clearMapAndReserve ( (int)out.size() ); bases.resize ( quads.size() ); centers.resize ( quads.size() ); for ( unsigned int c = 0; c < quads.size(); c++ ) { - sofa::defaulttype::Mat3x3d m,mt; + Mat3x3d m,mt; m[0] = in[quads[c][1]]-in[quads[c][0]]; m[1] = in[quads[c][3]]-in[quads[c][0]]; m[2] = cross ( m[0],m[1] ); @@ -784,182 +736,140 @@ void BarycentricMapperQuadSetTopology::init ( const typename Out::VecCoo for ( unsigned int i=0; i0 ) d = ( pos-centers[c] ).norm2(); - if ( d0 ) - { - ++outside; - } - addPointInQuad ( index, coefs.ptr() ); + addPointInQuad ( quadIndex, coefs.ptr() ); } } -template -void BarycentricMapperTetrahedronSetTopology::clear ( int reserve ) +template +int BarycentricMapperTetrahedronSetTopology::addPointInTetra ( const int tetraIndex, const SReal* baryCoords ) { - helper::vector& vectorData = *(map.beginEdit()); - vectorData.clear(); if ( reserve>0 ) vectorData.reserve ( reserve ); - map.endEdit(); -} - -template -int BarycentricMapperTetrahedronSetTopology::addPointInTetra ( const int tetraIndex, const SReal* baryCoords ) -{ - helper::vector& vectorData = *(map.beginEdit()); - vectorData.resize ( map.getValue().size() +1 ); + helper::vector& vectorData = *(d_map.beginEdit()); + vectorData.resize ( d_map.getValue().size() +1 ); MappingData& data = *vectorData.rbegin(); - map.endEdit(); + d_map.endEdit(); data.in_index = tetraIndex; data.baryCoords[0] = ( Real ) baryCoords[0]; data.baryCoords[1] = ( Real ) baryCoords[1]; data.baryCoords[2] = ( Real ) baryCoords[2]; - return (int)map.getValue().size()-1; + return (int)d_map.getValue().size()-1; } -//template -//int BarycentricMapperTetrahedronSetTopology::createPointInTetra(const typename Out::Coord& p, int index, const typename In::VecCoord* points) -//{ -// //TODO: add implementation -//} +template +void BarycentricMapperTetrahedronSetTopology::init ( const typename Out::VecCoord& out, const typename In::VecCoord& in ) +{ + m_fromContainer->getContext()->get ( m_fromGeomAlgo ); + + const helper::vector& tetras = this->m_fromTopology->getTetrahedra(); -template -void BarycentricMapperTetrahedronSetTopology::init ( const typename Out::VecCoord& out, const typename In::VecCoord& in ) -{ - _fromContainer->getContext()->get ( _fromGeomAlgo ); - // Why do we need that ? is reset the map in case of topology change -// if (this->toTopology) -// { -// map.createTopologicalEngine(this->toTopology); -// map.registerTopologicalData(); -// } - - int outside = 0; - const sofa::helper::vector& tetrahedra = this->fromTopology->getTetrahedra(); - - sofa::helper::vector< sofa::defaulttype::Matrix3> bases; - sofa::helper::vector< sofa::defaulttype::Vector3> centers; - - clear ( (int)out.size() ); - bases.resize ( tetrahedra.size() ); - centers.resize ( tetrahedra.size() ); - for ( unsigned int t = 0; t < tetrahedra.size(); t++ ) - { - sofa::defaulttype::Mat3x3d m,mt; - m[0] = in[tetrahedra[t][1]]-in[tetrahedra[t][0]]; - m[1] = in[tetrahedra[t][2]]-in[tetrahedra[t][0]]; - m[2] = in[tetrahedra[t][3]]-in[tetrahedra[t][0]]; + helper::vector< Matrix3> bases; + helper::vector< Vector3> centers; + + this->clearMapAndReserve ( (int)out.size() ); + bases.resize ( tetras.size() ); + centers.resize ( tetras.size() ); + + // Compute tetras base and center + for ( unsigned int t = 0; t < tetras.size(); t++ ) + { + Mat3x3d m,mt; + m[0] = in[tetras[t][1]]-in[tetras[t][0]]; + m[1] = in[tetras[t][2]]-in[tetras[t][0]]; + m[2] = in[tetras[t][3]]-in[tetras[t][0]]; mt.transpose ( m ); bases[t].invert ( mt ); - centers[t] = ( in[tetrahedra[t][0]]+in[tetrahedra[t][1]]+in[tetrahedra[t][2]]+in[tetrahedra[t][3]] ) *0.25; + centers[t] = ( in[tetras[t][0]]+in[tetras[t][1]]+in[tetras[t][2]]+in[tetras[t][3]] ) *0.25; } - for ( unsigned int i=0; i0 ) d = ( pos-centers[t] ).norm2(); - if ( d0 ) - { - ++outside; + if ( d -void BarycentricMapperHexahedronSetTopology::clear ( int reserve ) -{ - helper::vector& vectorData = *(map.beginEdit()); - vectorData.clear(); - if ( reserve>0 ) vectorData.reserve ( reserve ); - map.endEdit(); -} - -template -int BarycentricMapperHexahedronSetTopology::addPointInCube ( const int cubeIndex, const SReal* baryCoords ) +template +int BarycentricMapperHexahedronSetTopology::addPointInCube ( const int cubeIndex, const SReal* baryCoords ) { - helper::vector& vectorData = *(map.beginEdit()); - vectorData.resize ( map.getValue().size() +1 ); + helper::vector& vectorData = *(d_map.beginEdit()); + vectorData.resize ( d_map.getValue().size() +1 ); MappingData& data = *vectorData.rbegin(); - map.endEdit(); + d_map.endEdit(); data.in_index = cubeIndex; data.baryCoords[0] = ( Real ) baryCoords[0]; data.baryCoords[1] = ( Real ) baryCoords[1]; data.baryCoords[2] = ( Real ) baryCoords[2]; - return (int)map.getValue().size()-1; + return (int)d_map.getValue().size()-1; } -template -int BarycentricMapperHexahedronSetTopology::setPointInCube ( const int pointIndex, - const int cubeIndex, - const SReal* baryCoords ) +template +int BarycentricMapperHexahedronSetTopology::setPointInCube ( const int pointIndex, const int cubeIndex, const SReal* baryCoords ) { - if ( pointIndex >= ( int ) map.getValue().size() ) + if ( pointIndex >= ( int ) d_map.getValue().size() ) return -1; - helper::vector& vectorData = *(map.beginEdit()); + helper::vector& vectorData = *(d_map.beginEdit()); MappingData& data = vectorData[pointIndex]; data.in_index = cubeIndex; data.baryCoords[0] = ( Real ) baryCoords[0]; data.baryCoords[1] = ( Real ) baryCoords[1]; data.baryCoords[2] = ( Real ) baryCoords[2]; - map.endEdit(); + d_map.endEdit(); if(cubeIndex == -1) - _invalidIndex.insert(pointIndex); + m_invalidIndex.insert(pointIndex); else - _invalidIndex.erase(pointIndex); + m_invalidIndex.erase(pointIndex); return pointIndex; } -template -void BarycentricMapperHexahedronSetTopology::init ( const typename Out::VecCoord& out, - const typename In::VecCoord& /*in*/ ) +template +void BarycentricMapperHexahedronSetTopology::init ( const typename Out::VecCoord& out, const typename In::VecCoord& in ) { - _fromContainer->getContext()->get ( _fromGeomAlgo ); + SOFA_UNUSED(in); + m_fromContainer->getContext()->get ( m_fromGeomAlgo ); - if ( _fromGeomAlgo == NULL ) + if ( m_fromGeomAlgo == NULL ) { msg_error() << "Cannot find GeometryAlgorithms component at init." ; } - if ( !map.getValue().empty() ) + if ( !d_map.getValue().empty() ) return; - - clear ( (int)out.size() ); + this->clearMapAndReserve ( (int)out.size() ); typename In::VecCoord coord; helper::vector elements ( out.size() ); - helper::vector coefs ( out.size() ); + helper::vector coefs ( out.size() ); helper::vector distances ( out.size() ); coord.resize ( out.size() ); for ( unsigned int i=0; ifindNearestElementsInRestPos ( coord, elements, coefs, distances ); + m_fromGeomAlgo->findNearestElementsInRestPos ( coord, elements, coefs, distances ); for ( unsigned int i=0; i::init ( const typename Out:: } } + + template void BarycentricMapping::createMapperFromTopology ( BaseMeshTopology * topology ) { using sofa::core::behavior::BaseMechanicalState; - mapper = NULL; + m_mapper = NULL; topology::PointSetTopologyContainer* toTopoCont; this->toModel->getContext()->get(toTopoCont); @@ -991,14 +903,13 @@ void BarycentricMapping::createMapperFromTopology ( BaseMeshTopology this->fromModel->getContext()->get(fromTopoCont); } - if (fromTopoCont != NULL) { topology::HexahedronSetTopologyContainer* t1 = dynamic_cast< topology::HexahedronSetTopologyContainer* >(fromTopoCont); if (t1 != NULL) { typedef BarycentricMapperHexahedronSetTopology HexahedronSetMapper; - mapper = sofa::core::objectmodel::New(t1, toTopoCont); + m_mapper = sofa::core::objectmodel::New(t1, toTopoCont); } else { @@ -1006,7 +917,7 @@ void BarycentricMapping::createMapperFromTopology ( BaseMeshTopology if (t2 != NULL) { typedef BarycentricMapperTetrahedronSetTopology TetrahedronSetMapper; - mapper = sofa::core::objectmodel::New(t2, toTopoCont); + //m_mapper = sofa::core::objectmodel::New(t2, toTopoCont); } else { @@ -1014,7 +925,7 @@ void BarycentricMapping::createMapperFromTopology ( BaseMeshTopology if (t3 != NULL) { typedef BarycentricMapperQuadSetTopology QuadSetMapper; - mapper = sofa::core::objectmodel::New(t3, toTopoCont); + m_mapper = sofa::core::objectmodel::New(t3, toTopoCont); } else { @@ -1022,7 +933,7 @@ void BarycentricMapping::createMapperFromTopology ( BaseMeshTopology if (t4 != NULL) { typedef BarycentricMapperTriangleSetTopology TriangleSetMapper; - mapper = sofa::core::objectmodel::New(t4, toTopoCont); + m_mapper = sofa::core::objectmodel::New(t4, toTopoCont); } else { @@ -1030,7 +941,7 @@ void BarycentricMapping::createMapperFromTopology ( BaseMeshTopology if ( t5 != NULL ) { typedef BarycentricMapperEdgeSetTopology EdgeSetMapper; - mapper = sofa::core::objectmodel::New(t5, toTopoCont); + m_mapper = sofa::core::objectmodel::New(t5, toTopoCont); } } } @@ -1047,7 +958,7 @@ void BarycentricMapping::createMapperFromTopology ( BaseMeshTopology { typedef BarycentricMapperRegularGridTopology< InDataTypes, OutDataTypes > RegularGridMapper; - mapper = sofa::core::objectmodel::New(rgt, toTopoCont); + m_mapper = sofa::core::objectmodel::New(rgt, toTopoCont); } else { @@ -1057,7 +968,7 @@ void BarycentricMapping::createMapperFromTopology ( BaseMeshTopology if (sgt != NULL && sgt->isVolume()) { typedef BarycentricMapperSparseGridTopology< InDataTypes, OutDataTypes > SparseGridMapper; - mapper = sofa::core::objectmodel::New(sgt, toTopoCont); + m_mapper = sofa::core::objectmodel::New(sgt, toTopoCont); } else // generic MeshTopology { @@ -1065,16 +976,16 @@ void BarycentricMapping::createMapperFromTopology ( BaseMeshTopology typedef BarycentricMapperMeshTopology< InDataTypes, OutDataTypes > MeshMapper; BaseMeshTopology* bmt = dynamic_cast< BaseMeshTopology* >(topology); - mapper = sofa::core::objectmodel::New(bmt, toTopoCont); + m_mapper = sofa::core::objectmodel::New(bmt, toTopoCont); } } } - if (mapper) + if (m_mapper) { - mapper->setName("mapper"); - this->addSlave(mapper.get()); - mapper->maskFrom = this->maskFrom; - mapper->maskTo = this->maskTo; + m_mapper->setName("mapper"); + this->addSlave(m_mapper.get()); + m_mapper->maskFrom = this->maskFrom; + m_mapper->maskTo = this->maskTo; } } @@ -1084,15 +995,9 @@ void BarycentricMapping::init() topology_from = this->fromModel->getContext()->getMeshTopology(); topology_to = this->toModel->getContext()->getMeshTopology(); - //IPB - //core::objectmodel::BaseContext* context = this->fromModel->getContext(); - //->get(tetForceField); - //serr << "!!!!!!!!!!!! getDT = " << this->fromModel->getContext()->getDt() << sendl; - //IPE - Inherit::init(); - if ( mapper == NULL ) // try to create a mapper according to the topology of the In model + if ( m_mapper == NULL ) // try to create a mapper according to the topology of the In model { if ( topology_from!=NULL ) { @@ -1100,16 +1005,16 @@ void BarycentricMapping::init() } } - if ( mapper != NULL ) + if ( m_mapper != NULL ) { if (useRestPosition.getValue()) - mapper->init ( ((const core::State *)this->toModel)->read(core::ConstVecCoordId::restPosition())->getValue(), ((const core::State *)this->fromModel)->read(core::ConstVecCoordId::restPosition())->getValue() ); + m_mapper->init ( ((const core::State *)this->toModel)->read(core::ConstVecCoordId::restPosition())->getValue(), ((const core::State *)this->fromModel)->read(core::ConstVecCoordId::restPosition())->getValue() ); else - mapper->init (((const core::State *)this->toModel)->read(core::ConstVecCoordId::position())->getValue(), ((const core::State *)this->fromModel)->read(core::ConstVecCoordId::position())->getValue() ); + m_mapper->init (((const core::State *)this->toModel)->read(core::ConstVecCoordId::position())->getValue(), ((const core::State *)this->fromModel)->read(core::ConstVecCoordId::position())->getValue() ); } else { - serr << "ERROR: Barycentric mapping does not understand topology."<::init() template void BarycentricMapping::reinit() { - if ( mapper != NULL ) + if ( m_mapper != NULL ) { - mapper->clear(); - mapper->init (((const core::State *)this->toModel)->read(core::ConstVecCoordId::position())->getValue(), ((const core::State *)this->fromModel)->read(core::ConstVecCoordId::position())->getValue() ); + m_mapper->clearMapAndReserve(); + m_mapper->init (((const core::State *)this->toModel)->read(core::ConstVecCoordId::position())->getValue(), ((const core::State *)this->fromModel)->read(core::ConstVecCoordId::position())->getValue() ); } } + + +/************************************* Apply and Resize ***********************************/ + + + template -void BarycentricMapping::apply(const core::MechanicalParams * /*mparams*/, Data< typename Out::VecCoord >& out, const Data< typename In::VecCoord >& in) +void BarycentricMapping::apply(const core::MechanicalParams * mparams, Data< typename Out::VecCoord >& out, const Data< typename In::VecCoord >& in) { + SOFA_UNUSED(mparams); + if ( #ifdef SOFA_DEV sleeping.getValue()==false && #endif - mapper != NULL) + m_mapper != NULL) { - mapper->resize( this->toModel ); - mapper->apply(*out.beginWriteOnly(), in.getValue()); + m_mapper->resize( this->toModel ); + m_mapper->apply(*out.beginWriteOnly(), in.getValue()); out.endEdit(); } } - template void BarycentricMapperMeshTopology::resize( core::State* toModel ) { - toModel->resize(map1d.size() +map2d.size() +map3d.size()); + toModel->resize(m_map1d.size() +m_map2d.size() +m_map3d.size()); } template void BarycentricMapperMeshTopology::apply ( typename Out::VecCoord& out, const typename In::VecCoord& in ) { - out.resize( map1d.size() +map2d.size() +map3d.size() ); + out.resize( m_map1d.size() +m_map2d.size() +m_map3d.size() ); - const sofa::core::topology::BaseMeshTopology::SeqLines& lines = this->fromTopology->getLines(); - const sofa::core::topology::BaseMeshTopology::SeqTriangles& triangles = this->fromTopology->getTriangles(); - const sofa::core::topology::BaseMeshTopology::SeqQuads& quads = this->fromTopology->getQuads(); - const sofa::core::topology::BaseMeshTopology::SeqTetrahedra& tetrahedra = this->fromTopology->getTetrahedra(); - const sofa::core::topology::BaseMeshTopology::SeqHexahedra& cubes = this->fromTopology->getHexahedra(); + const SeqLines& lines = this->m_fromTopology->getLines(); + const SeqTriangles& triangles = this->m_fromTopology->getTriangles(); + const SeqQuads& quads = this->m_fromTopology->getQuads(); + const SeqTetrahedra& tetrahedra = this->m_fromTopology->getTetrahedra(); + const SeqHexahedra& cubes = this->m_fromTopology->getHexahedra(); // 1D elements { - for ( unsigned int i=0; i::apply ( typename Out::VecCoord& out, } // 2D elements { - const int i0 = map1d.size(); + const int i0 = m_map1d.size(); const int c0 = triangles.size(); - for ( unsigned int i=0; i::apply ( typename Out::VecCoord& out, { if (quads.size()) { - const sofa::core::topology::BaseMeshTopology::Quad& quad = quads[index-c0]; + const Quad& quad = quads[index-c0]; Out::setCPos(out[i+i0] , in[quad[0]] * ( ( 1-fx ) * ( 1-fy ) ) + in[quad[1]] * ( ( fx ) * ( 1-fy ) ) + in[quad[3]] * ( ( 1-fx ) * ( fy ) ) @@ -1201,17 +1113,17 @@ void BarycentricMapperMeshTopology::apply ( typename Out::VecCoord& out, } // 3D elements { - const int i0 = map1d.size() + map2d.size(); + const int i0 = m_map1d.size() + m_map2d.size(); const int c0 = tetrahedra.size(); - for ( unsigned int i=0; i::apply ( typename Out::VecCoord& out, } else { - const sofa::core::topology::BaseMeshTopology::Hexa& cube = cubes[index-c0]; + const Hexa& cube = cubes[index-c0]; Out::setCPos(out[i+i0] , in[cube[0]] * ( ( 1-fx ) * ( 1-fy ) * ( 1-fz ) ) + in[cube[1]] * ( ( fx ) * ( 1-fy ) * ( 1-fz ) ) @@ -1234,26 +1146,24 @@ void BarycentricMapperMeshTopology::apply ( typename Out::VecCoord& out, } } - template void BarycentricMapperRegularGridTopology::resize( core::State* toModel ) { - toModel->resize(map.size()); + toModel->resize(m_map.size()); } - template void BarycentricMapperRegularGridTopology::apply ( typename Out::VecCoord& out, const typename In::VecCoord& in ) { - out.resize( map.size() ); + out.resize( m_map.size() ); - for ( unsigned int i=0; ifromTopology->getHexaCopy ( this->map[i].in_index ); + const topology::RegularGridTopology::Hexa cube = this->m_fromTopology->getHexaCopy ( this->m_map[i].in_index ); - const Real fx = map[i].baryCoords[0]; - const Real fy = map[i].baryCoords[1]; - const Real fz = map[i].baryCoords[2]; + const Real fx = m_map[i].baryCoords[0]; + const Real fy = m_map[i].baryCoords[1]; + const Real fz = m_map[i].baryCoords[2]; Out::setCPos(out[i] , in[cube[0]] * ( ( 1-fx ) * ( 1-fy ) * ( 1-fz ) ) + in[cube[1]] * ( ( fx ) * ( 1-fy ) * ( 1-fz ) ) + in[cube[3]] * ( ( 1-fx ) * ( fy ) * ( 1-fz ) ) @@ -1268,25 +1178,25 @@ void BarycentricMapperRegularGridTopology::apply ( typename Out::VecCoor template void BarycentricMapperSparseGridTopology::resize( core::State* toModel ) { - toModel->resize(map.size()); + toModel->resize(m_map.size()); } template void BarycentricMapperSparseGridTopology::apply ( typename Out::VecCoord& out, const typename In::VecCoord& in ) { - out.resize( map.size() ); + out.resize( m_map.size() ); - typedef sofa::helper::vector< CubeData > CubeDataVector; + typedef helper::vector< CubeData > CubeDataVector; typedef typename CubeDataVector::const_iterator CubeDataVectorIt; - CubeDataVectorIt it = map.begin(); - CubeDataVectorIt itEnd = map.end(); + CubeDataVectorIt it = m_map.begin(); + CubeDataVectorIt itEnd = m_map.end(); unsigned int i = 0; while (it != itEnd) { - const topology::SparseGridTopology::Hexa cube = this->fromTopology->getHexahedron( it->in_index ); + const topology::SparseGridTopology::Hexa cube = this->m_fromTopology->getHexahedron( it->in_index ); const Real fx = it->baryCoords[0]; const Real fy = it->baryCoords[1]; @@ -1306,149 +1216,116 @@ void BarycentricMapperSparseGridTopology::apply ( typename Out::VecCoord } } -template -void BarycentricMapperEdgeSetTopology::resize( core::State* toModel ) +template +void BarycentricMapperEdgeSetTopology::apply ( typename Out::VecCoord& out, const typename In::VecCoord& in ) { - toModel->resize(map.getValue().size()); -} + out.resize( d_map.getValue().size() ); -template -void BarycentricMapperEdgeSetTopology::apply ( typename Out::VecCoord& out, const typename In::VecCoord& in ) -{ - out.resize( map.getValue().size() ); + const helper::vector& edges = this->m_fromTopology->getEdges(); + for ( unsigned int i=0; i& edges = this->fromTopology->getEdges(); - // 2D elements - helper::vector& vectorData = *(map.beginEdit()); + helper::vector baryCoef = getBaryCoef(d_map.getValue()[i].baryCoords); + InDeriv inPos{0.,0.,0.}; + for (unsigned int j=0; j -void BarycentricMapperTriangleSetTopology::resize( core::State* toModel ) +template +void BarycentricMapperTriangleSetTopology::apply ( typename Out::VecCoord& out, const typename In::VecCoord& in ) { - toModel->resize(map.getValue().size()); -} + out.resize( d_map.getValue().size() ); -template -void BarycentricMapperTriangleSetTopology::apply ( typename Out::VecCoord& out, const typename In::VecCoord& in ) -{ - out.resize( map.getValue().size() ); - - const sofa::helper::vector& triangles = this->fromTopology->getTriangles(); - for ( unsigned int i=0; i& triangles = this->m_fromTopology->getTriangles(); + for ( unsigned int i=0; i -void BarycentricMapperQuadSetTopology::resize( core::State* toModel ) -{ - toModel->resize(map.getValue().size()); + helper::vector baryCoef = getBaryCoef(d_map.getValue()[i].baryCoords); + InDeriv inPos{0.,0.,0.}; + for (unsigned int j=0; j -void BarycentricMapperQuadSetTopology::apply ( typename Out::VecCoord& out, const typename In::VecCoord& in ) +template +void BarycentricMapperQuadSetTopology::apply ( typename Out::VecCoord& out, const typename In::VecCoord& in ) { - out.resize( map.getValue().size() ); + out.resize( d_map.getValue().size() ); - const sofa::helper::vector& quads = this->fromTopology->getQuads(); - for ( unsigned int i=0; i& quads = this->m_fromTopology->getQuads(); + for ( unsigned int i=0; i -void BarycentricMapperTetrahedronSetTopology::resize( core::State* toModel ) -{ - toModel->resize(map.getValue().size()); + helper::vector baryCoef = getBaryCoef(d_map.getValue()[i].baryCoords); + InDeriv inPos{0.,0.,0.}; + for (unsigned int j=0; j -void BarycentricMapperTetrahedronSetTopology::apply ( typename Out::VecCoord& out, const typename In::VecCoord& in ) +template +void BarycentricMapperTetrahedronSetTopology::apply ( typename Out::VecCoord& out, const typename In::VecCoord& in ) { - out.resize( map.getValue().size() ); + out.resize( d_map.getValue().size() ); - const sofa::helper::vector& tetrahedra = this->fromTopology->getTetrahedra(); - for ( unsigned int i=0; i& tetrahedra = this->m_fromTopology->getTetrahedra(); + for ( unsigned int i=0; i::apply, in = "<::apply, out = "< -void BarycentricMapperHexahedronSetTopology::resize( core::State* toModel ) -{ - toModel->resize(map.getValue().size()); + helper::vector baryCoef = getBaryCoef(d_map.getValue()[i].baryCoords); + InDeriv inPos{0.,0.,0.}; + for (unsigned int j=0; j -void BarycentricMapperHexahedronSetTopology::apply ( typename Out::VecCoord& out, const typename In::VecCoord& in ) +template +void BarycentricMapperHexahedronSetTopology::apply ( typename Out::VecCoord& out, const typename In::VecCoord& in ) { - out.resize( map.getValue().size() ); + out.resize( d_map.getValue().size() ); - const sofa::helper::vector& cubes = this->fromTopology->getHexahedra(); - for ( unsigned int i=0; i& cubes = this->m_fromTopology->getHexahedra(); + for ( unsigned int i=0; i baryCoef = getBaryCoef(d_map.getValue()[i].baryCoords); + InDeriv inPos{0.,0.,0.}; + for (unsigned int j=0; j -void BarycentricMapperHexahedronSetTopology::applyOnePoint( const unsigned int& hexaPointId,typename Out::VecCoord& out, const typename In::VecCoord& in ) -{ - const sofa::helper::vector& cubes = this->fromTopology->getHexahedra(); - const Real fx = map.getValue()[hexaPointId].baryCoords[0]; - const Real fy = map.getValue()[hexaPointId].baryCoords[1]; - const Real fz = map.getValue()[hexaPointId].baryCoords[2]; - int index = map.getValue()[hexaPointId].in_index; - const core::topology::BaseMeshTopology::Hexahedron& cube = cubes[index]; +template +void BarycentricMapperHexahedronSetTopology::applyOnePoint( const unsigned int& hexaPointId,typename Out::VecCoord& out, const typename In::VecCoord& in ) +{ + const helper::vector& cubes = this->m_fromTopology->getHexahedra(); + const Real fx = d_map.getValue()[hexaPointId].baryCoords[0]; + const Real fy = d_map.getValue()[hexaPointId].baryCoords[1]; + const Real fz = d_map.getValue()[hexaPointId].baryCoords[2]; + int index = d_map.getValue()[hexaPointId].in_index; + const Hexahedron& cube = cubes[index]; Out::setCPos(out[hexaPointId] , in[cube[0]] * ( ( 1-fx ) * ( 1-fy ) * ( 1-fz ) ) + in[cube[1]] * ( ( fx ) * ( 1-fy ) * ( 1-fz ) ) + in[cube[3]] * ( ( 1-fx ) * ( fy ) * ( 1-fz ) ) @@ -1460,17 +1337,22 @@ void BarycentricMapperHexahedronSetTopology::applyOnePoint( const unsign } //-- + +/************************************* ApplyJ ***********************************/ + template -void BarycentricMapping::applyJ (const core::MechanicalParams * /*mparams*/, Data< typename Out::VecDeriv >& _out, const Data< typename In::VecDeriv >& in) +void BarycentricMapping::applyJ (const core::MechanicalParams * mparams, Data< typename Out::VecDeriv >& _out, const Data< typename In::VecDeriv >& in) { + SOFA_UNUSED(mparams); + #ifdef SOFA_DEV if ( sleeping.getValue()==false) { #endif typename Out::VecDeriv* out = _out.beginEdit(); - if (mapper != NULL) + if (m_mapper != NULL) { - mapper->applyJ(*out, in.getValue()); + m_mapper->applyJ(*out, in.getValue()); } _out.endEdit(); #ifdef SOFA_DEV @@ -1481,21 +1363,17 @@ void BarycentricMapping::applyJ (const core::MechanicalParams * /*mpa template void BarycentricMapperMeshTopology::applyJ ( typename Out::VecDeriv& out, const typename In::VecDeriv& in ) { - out.resize( map1d.size() +map2d.size() +map3d.size() ); + out.resize( m_map1d.size() +m_map2d.size() +m_map3d.size() ); - const sofa::core::topology::BaseMeshTopology::SeqLines& lines = this->fromTopology->getLines(); - const sofa::core::topology::BaseMeshTopology::SeqTriangles& triangles = this->fromTopology->getTriangles(); - const sofa::core::topology::BaseMeshTopology::SeqQuads& quads = this->fromTopology->getQuads(); - const sofa::core::topology::BaseMeshTopology::SeqTetrahedra& tetrahedra = this->fromTopology->getTetrahedra(); - const sofa::core::topology::BaseMeshTopology::SeqHexahedra& cubes = this->fromTopology->getHexahedra(); + const SeqLines& lines = this->m_fromTopology->getLines(); + const SeqTriangles& triangles = this->m_fromTopology->getTriangles(); + const SeqQuads& quads = this->m_fromTopology->getQuads(); + const SeqTetrahedra& tetrahedra = this->m_fromTopology->getTetrahedra(); + const SeqHexahedra& cubes = this->m_fromTopology->getHexahedra(); - - - //std::cout << "BarycentricMapper: applyJ with masks" << std::endl; - - const size_t sizeMap1d=map1d.size(); - const size_t sizeMap2d=map2d.size(); - const size_t sizeMap3d=map3d.size(); + const size_t sizeMap1d=m_map1d.size(); + const size_t sizeMap2d=m_map2d.size(); + const size_t sizeMap3d=m_map3d.size(); const size_t idxStart1=sizeMap1d; const size_t idxStart2=sizeMap1d+sizeMap2d; @@ -1508,10 +1386,10 @@ void BarycentricMapperMeshTopology::applyJ ( typename Out::VecDeriv& out // 1D elements if (i < idxStart1) { - const Real fx = map1d[i].baryCoords[0]; - int index = map1d[i].in_index; + const Real fx = m_map1d[i].baryCoords[0]; + int index = m_map1d[i].in_index; { - const sofa::core::topology::BaseMeshTopology::Line& line = lines[index]; + const Line& line = lines[index]; Out::setDPos(out[i] , in[line[0]] * ( 1-fx ) + in[line[1]] * fx ); } @@ -1522,20 +1400,20 @@ void BarycentricMapperMeshTopology::applyJ ( typename Out::VecDeriv& out const size_t i0 = idxStart1; const size_t c0 = triangles.size(); - const Real fx = map2d[i-i0].baryCoords[0]; - const Real fy = map2d[i-i0].baryCoords[1]; - size_t index = map2d[i-i0].in_index; + const Real fx = m_map2d[i-i0].baryCoords[0]; + const Real fy = m_map2d[i-i0].baryCoords[1]; + size_t index = m_map2d[i-i0].in_index; if ( index::applyJ ( typename Out::VecDeriv& out { const size_t i0 = idxStart2; const size_t c0 = tetrahedra.size(); - const Real fx = map3d[i-i0].baryCoords[0]; - const Real fy = map3d[i-i0].baryCoords[1]; - const Real fz = map3d[i-i0].baryCoords[2]; - size_t index = map3d[i-i0].in_index; + const Real fx = m_map3d[i-i0].baryCoords[0]; + const Real fy = m_map3d[i-i0].baryCoords[1]; + const Real fz = m_map3d[i-i0].baryCoords[2]; + size_t index = m_map3d[i-i0].in_index; if ( index::applyJ ( typename Out::VecDeriv& out } else { - const sofa::core::topology::BaseMeshTopology::Hexa& cube = cubes[index-c0]; + const Hexa& cube = cubes[index-c0]; Out::setDPos(out[i] , in[cube[0]] * ( ( 1-fx ) * ( 1-fy ) * ( 1-fz ) ) + in[cube[1]] * ( ( fx ) * ( 1-fy ) * ( 1-fz ) ) @@ -1580,17 +1458,17 @@ void BarycentricMapperMeshTopology::applyJ ( typename Out::VecDeriv& out template void BarycentricMapperRegularGridTopology::applyJ ( typename Out::VecDeriv& out, const typename In::VecDeriv& in ) { - out.resize( map.size() ); + out.resize( m_map.size() ); for( size_t index=0 ; indexmaskTo->size() ; ++index) { if( this->maskTo->isActivated() && !this->maskTo->getEntry(index) ) continue; - const topology::RegularGridTopology::Hexa cube = this->fromTopology->getHexaCopy ( this->map[index].in_index ); + const topology::RegularGridTopology::Hexa cube = this->m_fromTopology->getHexaCopy ( this->m_map[index].in_index ); - const Real fx = map[index].baryCoords[0]; - const Real fy = map[index].baryCoords[1]; - const Real fz = map[index].baryCoords[2]; + const Real fx = m_map[index].baryCoords[0]; + const Real fy = m_map[index].baryCoords[1]; + const Real fz = m_map[index].baryCoords[2]; Out::setDPos(out[index] , in[cube[0]] * ( ( 1-fx ) * ( 1-fy ) * ( 1-fz ) ) + in[cube[1]] * ( ( fx ) * ( 1-fy ) * ( 1-fz ) ) + in[cube[3]] * ( ( 1-fx ) * ( fy ) * ( 1-fz ) ) @@ -1605,17 +1483,17 @@ void BarycentricMapperRegularGridTopology::applyJ ( typename Out::VecDer template void BarycentricMapperSparseGridTopology::applyJ ( typename Out::VecDeriv& out, const typename In::VecDeriv& in ) { - out.resize( map.size() ); + out.resize( m_map.size() ); for( size_t index=0 ; indexmaskTo->size() ; ++index) { if( this->maskTo->isActivated() && !this->maskTo->getEntry(index) ) continue; - const topology::SparseGridTopology::Hexa cube = this->fromTopology->getHexahedron ( this->map[index].in_index ); + const topology::SparseGridTopology::Hexa cube = this->m_fromTopology->getHexahedron ( this->m_map[index].in_index ); - const Real fx = map[index].baryCoords[0]; - const Real fy = map[index].baryCoords[1]; - const Real fz = map[index].baryCoords[2]; + const Real fx = m_map[index].baryCoords[0]; + const Real fy = m_map[index].baryCoords[1]; + const Real fz = m_map[index].baryCoords[2]; Out::setDPos(out[index] , in[cube[0]] * ( ( 1-fx ) * ( 1-fy ) * ( 1-fz ) ) + in[cube[1]] * ( ( fx ) * ( 1-fy ) * ( 1-fz ) ) + in[cube[3]] * ( ( 1-fx ) * ( fy ) * ( 1-fz ) ) @@ -1628,130 +1506,136 @@ void BarycentricMapperSparseGridTopology::applyJ ( typename Out::VecDeri } -template -void BarycentricMapperEdgeSetTopology::applyJ ( typename Out::VecDeriv& out, const typename In::VecDeriv& in ) +template +void BarycentricMapperEdgeSetTopology::applyJ ( typename Out::VecDeriv& out, const typename In::VecDeriv& in ) { - out.resize( map.getValue().size() ); - - const sofa::helper::vector& edges = this->fromTopology->getEdges(); + out.resize( d_map.getValue().size() ); + const helper::vector& edges = this->m_fromTopology->getEdges(); for( size_t i=0 ; imaskTo->size() ; ++i) { if( this->maskTo->isActivated() && !this->maskTo->getEntry(i) ) continue; - const Real fx = map.getValue()[i].baryCoords[0]; - int index = map.getValue()[i].in_index; - const core::topology::BaseMeshTopology::Edge& edge = edges[index]; - Out::setDPos(out[i] , in[edge[0]] * ( 1-fx ) - + in[edge[1]] * fx); + int index = d_map.getValue()[i].in_index; + const Edge& edge = edges[index]; + + helper::vector baryCoef = getBaryCoef(d_map.getValue()[i].baryCoords); + InDeriv inPos{0.,0.,0.}; + for (unsigned int j=0; j -void BarycentricMapperTriangleSetTopology::applyJ ( typename Out::VecDeriv& out, const typename In::VecDeriv& in ) +template +void BarycentricMapperTriangleSetTopology::applyJ ( typename Out::VecDeriv& out, const typename In::VecDeriv& in ) { - out.resize( map.getValue().size() ); - - const sofa::helper::vector& triangles = this->fromTopology->getTriangles(); + out.resize( d_map.getValue().size() ); + const helper::vector& triangles = this->m_fromTopology->getTriangles(); for( size_t i=0 ; imaskTo->size() ; ++i) { if( this->maskTo->isActivated() && !this->maskTo->getEntry(i) ) continue; - const Real fx = map.getValue()[i].baryCoords[0]; - const Real fy = map.getValue()[i].baryCoords[1]; - int index = map.getValue()[i].in_index; - const core::topology::BaseMeshTopology::Triangle& triangle = triangles[index]; - Out::setDPos(out[i] , in[triangle[0]] * ( 1-fx-fy ) - + in[triangle[1]] * fx - + in[triangle[2]] * fy); + int index = d_map.getValue()[i].in_index; + const Triangle& triangle = triangles[index]; + + helper::vector baryCoef = getBaryCoef(d_map.getValue()[i].baryCoords); + InDeriv inPos{0.,0.,0.}; + for (unsigned int j=0; j -void BarycentricMapperQuadSetTopology::applyJ ( typename Out::VecDeriv& out, const typename In::VecDeriv& in ) +template +void BarycentricMapperQuadSetTopology::applyJ ( typename Out::VecDeriv& out, const typename In::VecDeriv& in ) { - out.resize( map.getValue().size() ); + out.resize( d_map.getValue().size() ); - const sofa::helper::vector& quads = this->fromTopology->getQuads(); + const helper::vector& quads = this->m_fromTopology->getQuads(); for( size_t i=0 ; imaskTo->size() ; ++i) { if( this->maskTo->isActivated() && !this->maskTo->getEntry(i) ) continue; - const Real fx = map.getValue()[i].baryCoords[0]; - const Real fy = map.getValue()[i].baryCoords[1]; - int index = map.getValue()[i].in_index; - const core::topology::BaseMeshTopology::Quad& quad = quads[index]; - Out::setDPos(out[i] , in[quad[0]] * ( ( 1-fx ) * ( 1-fy ) ) - + in[quad[1]] * ( ( fx ) * ( 1-fy ) ) - + in[quad[3]] * ( ( 1-fx ) * ( fy ) ) - + in[quad[2]] * ( ( fx ) * ( fy ) ) ); + int index = d_map.getValue()[i].in_index; + const Quad& quad = quads[index]; + + helper::vector baryCoef = getBaryCoef(d_map.getValue()[i].baryCoords); + InDeriv inPos{0.,0.,0.}; + for (unsigned int j=0; j -void BarycentricMapperTetrahedronSetTopology::applyJ ( typename Out::VecDeriv& out, const typename In::VecDeriv& in ) +template +void BarycentricMapperTetrahedronSetTopology::applyJ ( typename Out::VecDeriv& out, const typename In::VecDeriv& in ) { - out.resize( map.getValue().size() ); + out.resize( d_map.getValue().size() ); - const sofa::helper::vector& tetrahedra = this->fromTopology->getTetrahedra(); + const helper::vector& tetrahedra = this->m_fromTopology->getTetrahedra(); for( size_t i=0 ; imaskTo->size() ; ++i) { if( this->maskTo->isActivated() && !this->maskTo->getEntry(i) ) continue; - const Real fx = map.getValue()[i].baryCoords[0]; - const Real fy = map.getValue()[i].baryCoords[1]; - const Real fz = map.getValue()[i].baryCoords[2]; - int index = map.getValue()[i].in_index; - const core::topology::BaseMeshTopology::Tetrahedron& tetra = tetrahedra[index]; - Out::setDPos(out[i] , in[tetra[0]] * ( 1-fx-fy-fz ) - + in[tetra[1]] * fx - + in[tetra[2]] * fy - + in[tetra[3]] * fz ); + int index = d_map.getValue()[i].in_index; + const Tetrahedron& tetra = tetrahedra[index]; + + helper::vector baryCoef = getBaryCoef(d_map.getValue()[i].baryCoords); + InDeriv inPos{0.,0.,0.}; + for (unsigned int j=0; j -void BarycentricMapperHexahedronSetTopology::applyJ ( typename Out::VecDeriv& out, const typename In::VecDeriv& in ) +template +void BarycentricMapperHexahedronSetTopology::applyJ ( typename Out::VecDeriv& out, const typename In::VecDeriv& in ) { - out.resize( map.getValue().size() ); + out.resize( d_map.getValue().size() ); - const sofa::helper::vector& cubes = this->fromTopology->getHexahedra(); + const helper::vector& cubes = this->m_fromTopology->getHexahedra(); for( size_t i=0 ; imaskTo->size() ; ++i) { if( this->maskTo->isActivated() && !this->maskTo->getEntry(i) ) continue; - const Real fx = map.getValue()[i].baryCoords[0]; - const Real fy = map.getValue()[i].baryCoords[1]; - const Real fz = map.getValue()[i].baryCoords[2]; - int index = map.getValue()[i].in_index; - const core::topology::BaseMeshTopology::Hexahedron& cube = cubes[index]; - Out::setDPos(out[i] , - in[cube[0]] * ( ( 1-fx ) * ( 1-fy ) * ( 1-fz ) ) - + in[cube[1]] * ( ( fx ) * ( 1-fy ) * ( 1-fz ) ) - + in[cube[3]] * ( ( 1-fx ) * ( fy ) * ( 1-fz ) ) - + in[cube[2]] * ( ( fx ) * ( fy ) * ( 1-fz ) ) - + in[cube[4]] * ( ( 1-fx ) * ( 1-fy ) * ( fz ) ) - + in[cube[5]] * ( ( fx ) * ( 1-fy ) * ( fz ) ) - + in[cube[7]] * ( ( 1-fx ) * ( fy ) * ( fz ) ) - + in[cube[6]] * ( ( fx ) * ( fy ) * ( fz ) ) ); + int index = d_map.getValue()[i].in_index; + const Hexahedron& cube = cubes[index]; + + helper::vector baryCoef = getBaryCoef(d_map.getValue()[i].baryCoords); + InDeriv inPos{0.,0.,0.}; + for (unsigned int j=0; j -void BarycentricMapping::applyJT (const core::MechanicalParams * /*mparams*/, Data< typename In::VecDeriv >& out, const Data< typename Out::VecDeriv >& in) +void BarycentricMapping::applyJT (const core::MechanicalParams * mparams, Data< typename In::VecDeriv >& out, const Data< typename Out::VecDeriv >& in) { + SOFA_UNUSED(mparams); + if ( #ifdef SOFA_DEV sleeping.getValue()==false && #endif - mapper != NULL) + m_mapper != NULL) { - mapper->applyJT(*out.beginEdit(), in.getValue()); + m_mapper->applyJT(*out.beginEdit(), in.getValue()); out.endEdit(); } } @@ -1759,15 +1643,15 @@ void BarycentricMapping::applyJT (const core::MechanicalParams * /*mp template void BarycentricMapperMeshTopology::applyJT ( typename In::VecDeriv& out, const typename Out::VecDeriv& in ) { - const sofa::core::topology::BaseMeshTopology::SeqLines& lines = this->fromTopology->getLines(); - const sofa::core::topology::BaseMeshTopology::SeqTriangles& triangles = this->fromTopology->getTriangles(); - const sofa::core::topology::BaseMeshTopology::SeqQuads& quads = this->fromTopology->getQuads(); - const sofa::core::topology::BaseMeshTopology::SeqTetrahedra& tetrahedra = this->fromTopology->getTetrahedra(); - const sofa::core::topology::BaseMeshTopology::SeqHexahedra& cubes = this->fromTopology->getHexahedra(); + const SeqLines& lines = this->m_fromTopology->getLines(); + const SeqTriangles& triangles = this->m_fromTopology->getTriangles(); + const SeqQuads& quads = this->m_fromTopology->getQuads(); + const SeqTetrahedra& tetrahedra = this->m_fromTopology->getTetrahedra(); + const SeqHexahedra& cubes = this->m_fromTopology->getHexahedra(); - const size_t i1d = map1d.size(); - const size_t i2d = map2d.size(); - const size_t i3d = map3d.size(); + const size_t i1d = m_map1d.size(); + const size_t i2d = m_map2d.size(); + const size_t i3d = m_map3d.size(); ForceMask& mask = *this->maskFrom; @@ -1779,10 +1663,10 @@ void BarycentricMapperMeshTopology::applyJT ( typename In::VecDeriv& out if (i < i1d) { const typename Out::DPos v = Out::getDPos(in[i]); - const OutReal fx = ( OutReal ) map1d[i].baryCoords[0]; - size_t index = map1d[i].in_index; + const OutReal fx = ( OutReal ) m_map1d[i].baryCoords[0]; + size_t index = m_map1d[i].in_index; { - const sofa::core::topology::BaseMeshTopology::Line& line = lines[index]; + const Line& line = lines[index]; out[line[0]] += v * ( 1-fx ); out[line[1]] += v * fx; mask.insertEntry(line[0]); @@ -1792,15 +1676,15 @@ void BarycentricMapperMeshTopology::applyJT ( typename In::VecDeriv& out // 2D elements else if (i < i1d+i2d) { - const size_t i0 = map1d.size(); + const size_t i0 = m_map1d.size(); const size_t c0 = triangles.size(); const typename Out::DPos v = Out::getDPos(in[i]); - const OutReal fx = ( OutReal ) map2d[i-i0].baryCoords[0]; - const OutReal fy = ( OutReal ) map2d[i-i0].baryCoords[1]; - size_t index = map2d[i-i0].in_index; + const OutReal fx = ( OutReal ) m_map2d[i-i0].baryCoords[0]; + const OutReal fy = ( OutReal ) m_map2d[i-i0].baryCoords[1]; + size_t index = m_map2d[i-i0].in_index; if ( index::applyJT ( typename In::VecDeriv& out } else { - const sofa::core::topology::BaseMeshTopology::Quad& quad = quads[index-c0]; + const Quad& quad = quads[index-c0]; out[quad[0]] += v * ( ( 1-fx ) * ( 1-fy ) ); out[quad[1]] += v * ( ( fx ) * ( 1-fy ) ); out[quad[3]] += v * ( ( 1-fx ) * ( fy ) ); @@ -1824,16 +1708,16 @@ void BarycentricMapperMeshTopology::applyJT ( typename In::VecDeriv& out // 3D elements else if (i < i1d+i2d+i3d) { - const size_t i0 = map1d.size() + map2d.size(); + const size_t i0 = m_map1d.size() + m_map2d.size(); const size_t c0 = tetrahedra.size(); const typename Out::DPos v = Out::getDPos(in[i]); - const OutReal fx = ( OutReal ) map3d[i-i0].baryCoords[0]; - const OutReal fy = ( OutReal ) map3d[i-i0].baryCoords[1]; - const OutReal fz = ( OutReal ) map3d[i-i0].baryCoords[2]; - size_t index = map3d[i-i0].in_index; + const OutReal fx = ( OutReal ) m_map3d[i-i0].baryCoords[0]; + const OutReal fy = ( OutReal ) m_map3d[i-i0].baryCoords[1]; + const OutReal fz = ( OutReal ) m_map3d[i-i0].baryCoords[2]; + size_t index = m_map3d[i-i0].in_index; if ( index::applyJT ( typename In::VecDeriv& out else { - const sofa::core::topology::BaseMeshTopology::Hexa& cube = cubes[index-c0]; + const Hexa& cube = cubes[index-c0]; out[cube[0]] += v * ( ( 1-fx ) * ( 1-fy ) * ( 1-fz ) ); out[cube[1]] += v * ( ( fx ) * ( 1-fy ) * ( 1-fz ) ); @@ -1874,9 +1758,6 @@ void BarycentricMapperMeshTopology::applyJT ( typename In::VecDeriv& out } } - - - template void BarycentricMapperRegularGridTopology::applyJT ( typename In::VecDeriv& out, const typename Out::VecDeriv& in ) { @@ -1887,11 +1768,11 @@ void BarycentricMapperRegularGridTopology::applyJT ( typename In::VecDer if( !this->maskTo->getEntry(index) ) continue; const typename Out::DPos v = Out::getDPos(in[index]); - const topology::RegularGridTopology::Hexa cube = this->fromTopology->getHexaCopy ( this->map[index].in_index ); + const topology::RegularGridTopology::Hexa cube = this->m_fromTopology->getHexaCopy ( this->m_map[index].in_index ); - const OutReal fx = ( OutReal ) map[index].baryCoords[0]; - const OutReal fy = ( OutReal ) map[index].baryCoords[1]; - const OutReal fz = ( OutReal ) map[index].baryCoords[2]; + const OutReal fx = ( OutReal ) m_map[index].baryCoords[0]; + const OutReal fy = ( OutReal ) m_map[index].baryCoords[1]; + const OutReal fz = ( OutReal ) m_map[index].baryCoords[2]; out[cube[0]] += v * ( ( 1-fx ) * ( 1-fy ) * ( 1-fz ) ); out[cube[1]] += v * ( ( fx ) * ( 1-fy ) * ( 1-fz ) ); @@ -1927,11 +1808,11 @@ void BarycentricMapperSparseGridTopology::applyJT ( typename In::VecDeri const typename Out::DPos v = Out::getDPos(in[index]); - const topology::SparseGridTopology::Hexa cube = this->fromTopology->getHexahedron ( this->map[index].in_index ); + const topology::SparseGridTopology::Hexa cube = this->m_fromTopology->getHexahedron ( this->m_map[index].in_index ); - const OutReal fx = ( OutReal ) map[index].baryCoords[0]; - const OutReal fy = ( OutReal ) map[index].baryCoords[1]; - const OutReal fz = ( OutReal ) map[index].baryCoords[2]; + const OutReal fx = ( OutReal ) m_map[index].baryCoords[0]; + const OutReal fy = ( OutReal ) m_map[index].baryCoords[1]; + const OutReal fz = ( OutReal ) m_map[index].baryCoords[2]; out[cube[0]] += v * ( ( 1-fx ) * ( 1-fy ) * ( 1-fz ) ); out[cube[1]] += v * ( ( fx ) * ( 1-fy ) * ( 1-fz ) ); @@ -1955,158 +1836,124 @@ void BarycentricMapperSparseGridTopology::applyJT ( typename In::VecDeri } } -template -void BarycentricMapperEdgeSetTopology::applyJT ( typename In::VecDeriv& out, const typename Out::VecDeriv& in ) +template +void BarycentricMapperEdgeSetTopology::applyJT ( typename In::VecDeriv& out, const typename Out::VecDeriv& in ) { - const sofa::helper::vector& edges = this->fromTopology->getEdges(); + const helper::vector& edges = this->m_fromTopology->getEdges(); ForceMask& mask = *this->maskFrom; - for( size_t i=0 ; imaskTo->size() ; ++i) { if( !this->maskTo->getEntry(i) ) continue; - const typename Out::DPos v = Out::getDPos(in[i]); - const OutReal fx = ( OutReal ) map.getValue()[i].baryCoords[0]; - int index = map.getValue()[i].in_index; - const core::topology::BaseMeshTopology::Edge& edge = edges[index]; - out[edge[0]] += v * ( 1-fx ); - out[edge[1]] += v * fx; + int index = d_map.getValue()[i].in_index; + const Edge& edge = edges[index]; - mask.insertEntry(edge[0]); - mask.insertEntry(edge[1]); + const typename Out::DPos inPos = Out::getDPos(in[i]); + helper::vector baryCoef = getBaryCoef(d_map.getValue()[i].baryCoords); + for (unsigned int j=0; j -void BarycentricMapperTriangleSetTopology::applyJT ( typename In::VecDeriv& out, const typename Out::VecDeriv& in ) +template +void BarycentricMapperTriangleSetTopology::applyJT ( typename In::VecDeriv& out, const typename Out::VecDeriv& in ) { - const sofa::helper::vector& triangles = this->fromTopology->getTriangles(); + const helper::vector& triangles = this->m_fromTopology->getTriangles(); ForceMask& mask = *this->maskFrom; - for( size_t i=0 ; imaskTo->size() ; ++i) { if( !this->maskTo->getEntry(i) ) continue; - const typename Out::DPos v = Out::getDPos(in[i]); - const OutReal fx = ( OutReal ) map.getValue()[i].baryCoords[0]; - const OutReal fy = ( OutReal ) map.getValue()[i].baryCoords[1]; - int index = map.getValue()[i].in_index; - const core::topology::BaseMeshTopology::Triangle& triangle = triangles[index]; - out[triangle[0]] += v * ( 1-fx-fy ); - out[triangle[1]] += v * fx; - out[triangle[2]] += v * fy; - mask.insertEntry(triangle[0]); - mask.insertEntry(triangle[1]); - mask.insertEntry(triangle[2]); - } + int index = d_map.getValue()[i].in_index; + const Triangle& triangle = triangles[index]; + const typename Out::DPos inPos = Out::getDPos(in[i]); + helper::vector baryCoef = getBaryCoef(d_map.getValue()[i].baryCoords); + for (unsigned int j=0; j -void BarycentricMapperQuadSetTopology::applyJT ( typename In::VecDeriv& out, const typename Out::VecDeriv& in ) +template +void BarycentricMapperQuadSetTopology::applyJT ( typename In::VecDeriv& out, const typename Out::VecDeriv& in ) { - const sofa::helper::vector& quads = this->fromTopology->getQuads(); + const helper::vector& quads = this->m_fromTopology->getQuads(); ForceMask& mask = *this->maskFrom; - for( size_t i=0 ; imaskTo->size() ; ++i) { if( !this->maskTo->getEntry(i) ) continue; - const typename Out::DPos v = Out::getDPos(in[i]); - const OutReal fx = ( OutReal ) map.getValue()[i].baryCoords[0]; - const OutReal fy = ( OutReal ) map.getValue()[i].baryCoords[1]; - int index = map.getValue()[i].in_index; - const core::topology::BaseMeshTopology::Quad& quad = quads[index]; - out[quad[0]] += v * ( ( 1-fx ) * ( 1-fy ) ); - out[quad[1]] += v * ( ( fx ) * ( 1-fy ) ); - out[quad[3]] += v * ( ( 1-fx ) * ( fy ) ); - out[quad[2]] += v * ( ( fx ) * ( fy ) ); - mask.insertEntry(quad[0]); - mask.insertEntry(quad[1]); - mask.insertEntry(quad[2]); - mask.insertEntry(quad[3]); + int index = d_map.getValue()[i].in_index; + const Quad& quad = quads[index]; + + const typename Out::DPos inPos = Out::getDPos(in[i]); + helper::vector baryCoef = getBaryCoef(d_map.getValue()[i].baryCoords); + for (unsigned int j=0; j -void BarycentricMapperTetrahedronSetTopology::applyJT ( typename In::VecDeriv& out, const typename Out::VecDeriv& in ) +template +void BarycentricMapperTetrahedronSetTopology::applyJT ( typename In::VecDeriv& out, const typename Out::VecDeriv& in ) { - const sofa::helper::vector& tetrahedra = this->fromTopology->getTetrahedra(); + const helper::vector& tetrahedra = this->m_fromTopology->getTetrahedra(); ForceMask& mask = *this->maskFrom; - for( size_t i=0 ; imaskTo->size() ; ++i) { if( !this->maskTo->getEntry(i) ) continue; - const typename Out::DPos v = Out::getDPos(in[i]); - const OutReal fx = ( OutReal ) map.getValue()[i].baryCoords[0]; - const OutReal fy = ( OutReal ) map.getValue()[i].baryCoords[1]; - const OutReal fz = ( OutReal ) map.getValue()[i].baryCoords[2]; - int index = map.getValue()[i].in_index; - const core::topology::BaseMeshTopology::Tetrahedron& tetra = tetrahedra[index]; - out[tetra[0]] += v * ( 1-fx-fy-fz ); - out[tetra[1]] += v * fx; - out[tetra[2]] += v * fy; - out[tetra[3]] += v * fz; - mask.insertEntry(tetra[0]); - mask.insertEntry(tetra[1]); - mask.insertEntry(tetra[2]); - mask.insertEntry(tetra[3]); + int index = d_map.getValue()[i].in_index; + const Tetrahedron& tetra = tetrahedra[index]; + + const typename Out::DPos inPos = Out::getDPos(in[i]); + helper::vector baryCoef = getBaryCoef(d_map.getValue()[i].baryCoords); + for (unsigned int j=0; j -void BarycentricMapperHexahedronSetTopology::applyJT ( typename In::VecDeriv& out, const typename Out::VecDeriv& in ) +template +void BarycentricMapperHexahedronSetTopology::applyJT ( typename In::VecDeriv& out, const typename Out::VecDeriv& in ) { - const sofa::helper::vector& cubes = this->fromTopology->getHexahedra(); + const helper::vector& cubes = this->m_fromTopology->getHexahedra(); ForceMask& mask = *this->maskFrom; - - ////////////// DEBUG ///////////// - // unsigned int mapSize = map.size(); - // std::cout << "Map size: " << mapSize << std::endl; - // for(unsigned int i=0;imaskTo->size() ; ++i) { if( !this->maskTo->getEntry(i) ) continue; - const typename Out::DPos v = Out::getDPos(in[i]); - const OutReal fx = ( OutReal ) map.getValue()[i].baryCoords[0]; - const OutReal fy = ( OutReal ) map.getValue()[i].baryCoords[1]; - const OutReal fz = ( OutReal ) map.getValue()[i].baryCoords[2]; - int index = map.getValue()[i].in_index; - const core::topology::BaseMeshTopology::Hexahedron& cube = cubes[index]; - out[cube[0]] += v * ( ( 1-fx ) * ( 1-fy ) * ( 1-fz ) ); - out[cube[1]] += v * ( ( fx ) * ( 1-fy ) * ( 1-fz ) ); - out[cube[3]] += v * ( ( 1-fx ) * ( fy ) * ( 1-fz ) ); - out[cube[2]] += v * ( ( fx ) * ( fy ) * ( 1-fz ) ); - out[cube[4]] += v * ( ( 1-fx ) * ( 1-fy ) * ( fz ) ); - out[cube[5]] += v * ( ( fx ) * ( 1-fy ) * ( fz ) ); - out[cube[7]] += v * ( ( 1-fx ) * ( fy ) * ( fz ) ); - out[cube[6]] += v * ( ( fx ) * ( fy ) * ( fz ) ); + int index = d_map.getValue()[i].in_index; + const Hexahedron& cube = cubes[index]; - mask.insertEntry(cube[0]); - mask.insertEntry(cube[1]); - mask.insertEntry(cube[2]); - mask.insertEntry(cube[3]); - mask.insertEntry(cube[4]); - mask.insertEntry(cube[5]); - mask.insertEntry(cube[6]); - mask.insertEntry(cube[7]); + const typename Out::DPos inPos = Out::getDPos(in[i]); + helper::vector baryCoef = getBaryCoef(d_map.getValue()[i].baryCoords); + for (unsigned int j=0; j const sofa::defaulttype::BaseMatrix* BarycentricMapping::getJ() { @@ -2114,11 +1961,11 @@ const sofa::defaulttype::BaseMatrix* BarycentricMapping::getJ() #ifdef SOFA_DEV sleeping.getValue()==false && #endif - mapper!=NULL ) + m_mapper!=NULL ) { const size_t outStateSize = this->toModel->getSize(); const size_t inStateSize = this->fromModel->getSize(); - const sofa::defaulttype::BaseMatrix* matJ = mapper->getJ((int)outStateSize, (int)inStateSize); + const sofa::defaulttype::BaseMatrix* matJ = m_mapper->getJ((int)outStateSize, (int)inStateSize); return matJ; } @@ -2130,109 +1977,106 @@ template const sofa::defaulttype::BaseMatrix* BarycentricMapperMeshTopology::getJ(int outSize, int inSize) { - if (matrixJ && !updateJ && matrixJ->rowBSize() == (MatrixTypeIndex)outSize && matrixJ->colBSize() == (MatrixTypeIndex)inSize) - return matrixJ; - if (outSize > 0 && map1d.size()+map2d.size()+map3d.size() == 0) + if (m_matrixJ && !m_updateJ && m_matrixJ->rowBSize() == (MatrixTypeIndex)outSize && m_matrixJ->colBSize() == (MatrixTypeIndex)inSize) + return m_matrixJ; + if (outSize > 0 && m_map1d.size()+m_map2d.size()+m_map3d.size() == 0) return NULL; // error: maps not yet created ? -// std::cout << "BarycentricMapperMeshTopology: creating " << outSize << "x" << inSize << " " << NOut << "x" << NIn << " J matrix" << std::endl; - if (!matrixJ) matrixJ = new MatrixType; - if (matrixJ->rowBSize() != (MatrixTypeIndex)outSize || matrixJ->colBSize() != (MatrixTypeIndex)inSize) - matrixJ->resize(outSize*NOut, inSize*NIn); + if (!m_matrixJ) m_matrixJ = new MatrixType; + if (m_matrixJ->rowBSize() != (MatrixTypeIndex)outSize || m_matrixJ->colBSize() != (MatrixTypeIndex)inSize) + m_matrixJ->resize(outSize*NOut, inSize*NIn); else - matrixJ->clear(); + m_matrixJ->clear(); - const sofa::core::topology::BaseMeshTopology::SeqLines& lines = this->fromTopology->getLines(); - const sofa::core::topology::BaseMeshTopology::SeqTriangles& triangles = this->fromTopology->getTriangles(); - const sofa::core::topology::BaseMeshTopology::SeqQuads& quads = this->fromTopology->getQuads(); - const sofa::core::topology::BaseMeshTopology::SeqTetrahedra& tetrahedra = this->fromTopology->getTetrahedra(); - const sofa::core::topology::BaseMeshTopology::SeqHexahedra& cubes = this->fromTopology->getHexahedra(); + const SeqLines& lines = this->m_fromTopology->getLines(); + const SeqTriangles& triangles = this->m_fromTopology->getTriangles(); + const SeqQuads& quads = this->m_fromTopology->getQuads(); + const SeqTetrahedra& tetrahedra = this->m_fromTopology->getTetrahedra(); + const SeqHexahedra& cubes = this->m_fromTopology->getHexahedra(); // 1D elements { - for ( size_t i=0; iaddMatrixContrib(matrixJ, out, line[0], ( 1-fx )); - this->addMatrixContrib(matrixJ, out, line[1], fx); + const Line& line = lines[index]; + this->addMatrixContrib(m_matrixJ, out, line[0], ( 1-fx )); + this->addMatrixContrib(m_matrixJ, out, line[1], fx); } } } // 2D elements { - const size_t i0 = map1d.size(); + const size_t i0 = m_map1d.size(); const size_t c0 = triangles.size(); - for ( size_t i=0; iaddMatrixContrib(matrixJ, out, triangle[0], ( 1-fx-fy )); - this->addMatrixContrib(matrixJ, out, triangle[1], fx); - this->addMatrixContrib(matrixJ, out, triangle[2], fy); + const Triangle& triangle = triangles[index]; + this->addMatrixContrib(m_matrixJ, out, triangle[0], ( 1-fx-fy )); + this->addMatrixContrib(m_matrixJ, out, triangle[1], fx); + this->addMatrixContrib(m_matrixJ, out, triangle[2], fy); } else { - const sofa::core::topology::BaseMeshTopology::Quad& quad = quads[index-c0]; - this->addMatrixContrib(matrixJ, out, quad[0], ( ( 1-fx ) * ( 1-fy ) )); - this->addMatrixContrib(matrixJ, out, quad[1], ( ( fx ) * ( 1-fy ) )); - this->addMatrixContrib(matrixJ, out, quad[3], ( ( 1-fx ) * ( fy ) )); - this->addMatrixContrib(matrixJ, out, quad[2], ( ( fx ) * ( fy ) )); + const Quad& quad = quads[index-c0]; + this->addMatrixContrib(m_matrixJ, out, quad[0], ( ( 1-fx ) * ( 1-fy ) )); + this->addMatrixContrib(m_matrixJ, out, quad[1], ( ( fx ) * ( 1-fy ) )); + this->addMatrixContrib(m_matrixJ, out, quad[3], ( ( 1-fx ) * ( fy ) )); + this->addMatrixContrib(m_matrixJ, out, quad[2], ( ( fx ) * ( fy ) )); } } } // 3D elements { - const size_t i0 = map1d.size() + map2d.size(); + const size_t i0 = m_map1d.size() + m_map2d.size(); const size_t c0 = tetrahedra.size(); - for ( size_t i=0; iaddMatrixContrib(matrixJ, out, tetra[0], ( 1-fx-fy-fz )); - this->addMatrixContrib(matrixJ, out, tetra[1], fx); - this->addMatrixContrib(matrixJ, out, tetra[2], fy); - this->addMatrixContrib(matrixJ, out, tetra[3], fz); + const Tetra& tetra = tetrahedra[index]; + this->addMatrixContrib(m_matrixJ, out, tetra[0], ( 1-fx-fy-fz )); + this->addMatrixContrib(m_matrixJ, out, tetra[1], fx); + this->addMatrixContrib(m_matrixJ, out, tetra[2], fy); + this->addMatrixContrib(m_matrixJ, out, tetra[3], fz); } else { - const sofa::core::topology::BaseMeshTopology::Hexa& cube = cubes[index-c0]; + const Hexa& cube = cubes[index-c0]; - this->addMatrixContrib(matrixJ, out, cube[0], ( ( 1-fx ) * ( 1-fy ) * ( 1-fz ) )); - this->addMatrixContrib(matrixJ, out, cube[1], ( ( fx ) * ( 1-fy ) * ( 1-fz ) )); + this->addMatrixContrib(m_matrixJ, out, cube[0], ( ( 1-fx ) * ( 1-fy ) * ( 1-fz ) )); + this->addMatrixContrib(m_matrixJ, out, cube[1], ( ( fx ) * ( 1-fy ) * ( 1-fz ) )); - this->addMatrixContrib(matrixJ, out, cube[3], ( ( 1-fx ) * ( fy ) * ( 1-fz ) )); - this->addMatrixContrib(matrixJ, out, cube[2], ( ( fx ) * ( fy ) * ( 1-fz ) )); + this->addMatrixContrib(m_matrixJ, out, cube[3], ( ( 1-fx ) * ( fy ) * ( 1-fz ) )); + this->addMatrixContrib(m_matrixJ, out, cube[2], ( ( fx ) * ( fy ) * ( 1-fz ) )); - this->addMatrixContrib(matrixJ, out, cube[4], ( ( 1-fx ) * ( 1-fy ) * ( fz ) )); - this->addMatrixContrib(matrixJ, out, cube[5], ( ( fx ) * ( 1-fy ) * ( fz ) )); + this->addMatrixContrib(m_matrixJ, out, cube[4], ( ( 1-fx ) * ( 1-fy ) * ( fz ) )); + this->addMatrixContrib(m_matrixJ, out, cube[5], ( ( fx ) * ( 1-fy ) * ( fz ) )); - this->addMatrixContrib(matrixJ, out, cube[7], ( ( 1-fx ) * ( fy ) * ( fz ) )); - this->addMatrixContrib(matrixJ, out, cube[6], ( ( fx ) * ( fy ) * ( fz ) )); + this->addMatrixContrib(m_matrixJ, out, cube[7], ( ( 1-fx ) * ( fy ) * ( fz ) )); + this->addMatrixContrib(m_matrixJ, out, cube[6], ( ( fx ) * ( fy ) * ( fz ) )); } } } - matrixJ->compress(); -// std::cout << "J = " << *matrixJ << std::endl; - updateJ = false; - return matrixJ; + m_matrixJ->compress(); + m_updateJ = false; + return m_matrixJ; } - template const sofa::defaulttype::BaseMatrix* BarycentricMapperRegularGridTopology::getJ(int outSize, int inSize) { @@ -2246,15 +2090,15 @@ const sofa::defaulttype::BaseMatrix* BarycentricMapperRegularGridTopologyclear(); - for ( size_t i=0; ifromTopology->getHexaCopy ( this->map[i].in_index ); + const topology::RegularGridTopology::Hexa cube = this->m_fromTopology->getHexaCopy ( this->m_map[i].in_index ); - const Real fx = ( Real ) map[i].baryCoords[0]; - const Real fy = ( Real ) map[i].baryCoords[1]; - const Real fz = ( Real ) map[i].baryCoords[2]; + const Real fx = ( Real ) m_map[i].baryCoords[0]; + const Real fy = ( Real ) m_map[i].baryCoords[1]; + const Real fz = ( Real ) m_map[i].baryCoords[2]; this->addMatrixContrib(matrixJ, out, cube[0], ( ( 1-fx ) * ( 1-fy ) * ( 1-fz ) )); this->addMatrixContrib(matrixJ, out, cube[1], ( ( fx ) * ( 1-fy ) * ( 1-fz ) )); @@ -2284,15 +2128,15 @@ const sofa::defaulttype::BaseMatrix* BarycentricMapperSparseGridTopology else matrixJ->clear(); - for ( size_t i=0; ifromTopology->getHexahedron ( this->map[i].in_index ); + const topology::SparseGridTopology::Hexa cube = this->m_fromTopology->getHexahedron ( this->m_map[i].in_index ); - const Real fx = ( Real ) map[i].baryCoords[0]; - const Real fy = ( Real ) map[i].baryCoords[1]; - const Real fz = ( Real ) map[i].baryCoords[2]; + const Real fx = ( Real ) m_map[i].baryCoords[0]; + const Real fy = ( Real ) m_map[i].baryCoords[1]; + const Real fz = ( Real ) m_map[i].baryCoords[2]; this->addMatrixContrib(matrixJ, out, cube[0], ( ( 1-fx ) * ( 1-fy ) * ( 1-fz ) )); this->addMatrixContrib(matrixJ, out, cube[1], ( ( fx ) * ( 1-fy ) * ( 1-fz ) )); @@ -2306,194 +2150,127 @@ const sofa::defaulttype::BaseMatrix* BarycentricMapperSparseGridTopology this->addMatrixContrib(matrixJ, out, cube[6], ( ( fx ) * ( fy ) * ( fz ) )); } matrixJ->compress(); -// std::cout << "J = " << *matrixJ << std::endl; updateJ = false; return matrixJ; } -/////////////////////////////////////////////////////////////////////////////////////////////// -/////////////////////////////////////////////////////////////////////////////////////////////// - -template -const sofa::defaulttype::BaseMatrix* BarycentricMapperEdgeSetTopology::getJ(int outSize, int inSize) +template +const sofa::defaulttype::BaseMatrix* BarycentricMapperEdgeSetTopology::getJ(int outSize, int inSize) { - if (matrixJ && !updateJ) - return matrixJ; - - if (!matrixJ) matrixJ = new MatrixType; - if (matrixJ->rowBSize() != (MatrixTypeIndex)outSize || matrixJ->colBSize() != (MatrixTypeIndex)inSize) - matrixJ->resize(outSize*NOut, inSize*NIn); - else - matrixJ->clear(); + Inherit::getJ(outSize,inSize); - const sofa::helper::vector& edges = this->fromTopology->getEdges(); + const helper::vector& edges = this->m_fromTopology->getEdges(); for( size_t outId=0 ; outIdmaskTo->size() ; ++outId) { if( !this->maskTo->getEntry(outId) ) continue; - const Real fx = map.getValue()[outId].baryCoords[0]; - int index = map.getValue()[outId].in_index; - const core::topology::BaseMeshTopology::Edge& edge = edges[index]; + const Edge& edge = edges[d_map.getValue()[outId].in_index]; - this->addMatrixContrib(matrixJ, outId, edge[0], ( 1-fx)); - this->addMatrixContrib(matrixJ, outId, edge[1], ( fx)); + helper::vector baryCoef = getBaryCoef(d_map.getValue()[outId].baryCoords); + for (unsigned int j=0; jaddMatrixContrib(m_matrixJ, outId, edge[j], baryCoef[j]); } - matrixJ->compress(); - updateJ = false; - return matrixJ; + m_matrixJ->compress(); + m_updateJ = false; + return m_matrixJ; } -template -const sofa::defaulttype::BaseMatrix* BarycentricMapperTriangleSetTopology::getJ(int outSize, int inSize) +template +const sofa::defaulttype::BaseMatrix* BarycentricMapperTriangleSetTopology::getJ(int outSize, int inSize) { - if (matrixJ && !updateJ) - return matrixJ; - - if (!matrixJ) matrixJ = new MatrixType; - if (matrixJ->rowBSize() != (MatrixTypeIndex)outSize || matrixJ->colBSize() != (MatrixTypeIndex)inSize) - matrixJ->resize(outSize*NOut, inSize*NIn); - else - matrixJ->clear(); + Inherit::getJ(outSize,inSize); - const sofa::helper::vector& triangles = this->fromTopology->getTriangles(); + const helper::vector& triangles = this->m_fromTopology->getTriangles(); for( size_t outId=0 ; outIdmaskTo->size() ; ++outId) { if( !this->maskTo->getEntry(outId) ) continue; - const Real fx = map.getValue()[outId].baryCoords[0]; - const Real fy = map.getValue()[outId].baryCoords[1]; - int index = map.getValue()[outId].in_index; - const core::topology::BaseMeshTopology::Triangle& triangle = triangles[index]; - this->addMatrixContrib(matrixJ, outId, triangle[0], ( 1-fx-fy )); - this->addMatrixContrib(matrixJ, outId, triangle[1], ( fx )); - this->addMatrixContrib(matrixJ, outId, triangle[2], ( fy )); + const Triangle& triangle = triangles[d_map.getValue()[outId].in_index]; + + helper::vector baryCoef = getBaryCoef(d_map.getValue()[outId].baryCoords); + for (unsigned int j=0; jaddMatrixContrib(m_matrixJ, outId, triangle[j], baryCoef[j]); } - matrixJ->compress(); - updateJ = false; - return matrixJ; + m_matrixJ->compress(); + m_updateJ = false; + return m_matrixJ; } -template -const sofa::defaulttype::BaseMatrix* BarycentricMapperQuadSetTopology::getJ(int outSize, int inSize) +template +const sofa::defaulttype::BaseMatrix* BarycentricMapperQuadSetTopology::getJ(int outSize, int inSize) { - if (matrixJ && !updateJ) - return matrixJ; - - if (!matrixJ) matrixJ = new MatrixType; - if (matrixJ->rowBSize() != (MatrixTypeIndex)outSize || matrixJ->colBSize() != (MatrixTypeIndex)inSize) - matrixJ->resize(outSize*NOut, inSize*NIn); - else - matrixJ->clear(); - - const sofa::helper::vector& quads = this->fromTopology->getQuads(); + Inherit::getJ(outSize,inSize); + const helper::vector& quads = this->m_fromTopology->getQuads(); for( size_t outId=0 ; outIdmaskTo->size() ; ++outId) { if( !this->maskTo->getEntry(outId) ) continue; - const Real fx = map.getValue()[outId].baryCoords[0]; - const Real fy = map.getValue()[outId].baryCoords[1]; - int index = map.getValue()[outId].in_index; - const core::topology::BaseMeshTopology::Quad& quad = quads[index]; + const Quad& quad = quads[d_map.getValue()[outId].in_index]; - this->addMatrixContrib(matrixJ, outId, quad[0], ( ( 1-fx ) * ( 1-fy ) )); - this->addMatrixContrib(matrixJ, outId, quad[1], ( ( fx ) * ( 1-fy ) )); - this->addMatrixContrib(matrixJ, outId, quad[2], ( ( fx ) * ( fy ) )); - this->addMatrixContrib(matrixJ, outId, quad[3], ( ( 1-fx ) * ( fy ) )); + helper::vector baryCoef = getBaryCoef(d_map.getValue()[outId].baryCoords); + for (unsigned int j=0; jaddMatrixContrib(m_matrixJ, outId, quad[j], baryCoef[j]); } - matrixJ->compress(); - updateJ = false; - return matrixJ; + m_matrixJ->compress(); + m_updateJ = false; + return m_matrixJ; } -template -const sofa::defaulttype::BaseMatrix* BarycentricMapperTetrahedronSetTopology::getJ(int outSize, int inSize) +template +const sofa::defaulttype::BaseMatrix* BarycentricMapperTetrahedronSetTopology::getJ(int outSize, int inSize) { + Inherit::getJ(outSize,inSize); - if (matrixJ && !updateJ) - return matrixJ; - - if (!matrixJ) matrixJ = new MatrixType; - if (matrixJ->rowBSize() != (MatrixTypeIndex)outSize || matrixJ->colBSize() != (MatrixTypeIndex)inSize) - matrixJ->resize(outSize*NOut, inSize*NIn); - else - matrixJ->clear(); - - const sofa::helper::vector& tetrahedra = this->fromTopology->getTetrahedra(); + const helper::vector& tetrahedra = this->m_fromTopology->getTetrahedra(); for( size_t outId=0 ; outIdmaskTo->size() ; ++outId) { if( !this->maskTo->getEntry(outId) ) continue; - const Real fx = map.getValue()[outId].baryCoords[0]; - const Real fy = map.getValue()[outId].baryCoords[1]; - const Real fz = map.getValue()[outId].baryCoords[2]; - int index = map.getValue()[outId].in_index; - const core::topology::BaseMeshTopology::Tetrahedron& tetra = tetrahedra[index]; + const Tetrahedron& tetra = tetrahedra[d_map.getValue()[outId].in_index]; - this->addMatrixContrib(matrixJ, outId, tetra[0], ( 1-fx-fy-fz )); - this->addMatrixContrib(matrixJ, outId, tetra[1], ( fx )); - this->addMatrixContrib(matrixJ, outId, tetra[2], ( fy )); - this->addMatrixContrib(matrixJ, outId, tetra[3], ( fz )); + helper::vector baryCoef = getBaryCoef(d_map.getValue()[outId].baryCoords); + for (unsigned int j=0; jaddMatrixContrib(m_matrixJ, outId, tetra[j], baryCoef[j]); } - matrixJ->compress(); - updateJ = false; - return matrixJ; + m_matrixJ->compress(); + m_updateJ = false; + return m_matrixJ; } -template -const sofa::defaulttype::BaseMatrix* BarycentricMapperHexahedronSetTopology::getJ(int outSize, int inSize) +template +const sofa::defaulttype::BaseMatrix* BarycentricMapperHexahedronSetTopology::getJ(int outSize, int inSize) { - if (matrixJ && !updateJ) - return matrixJ; - - if (!matrixJ) matrixJ = new MatrixType; - if (matrixJ->rowBSize() != (MatrixTypeIndex)outSize || matrixJ->colBSize() != (MatrixTypeIndex)inSize) - matrixJ->resize(outSize*NOut, inSize*NIn); - else - matrixJ->clear(); + Inherit::getJ(outSize,inSize); - const sofa::helper::vector& cubes = this->fromTopology->getHexahedra(); + const helper::vector& hexas = this->m_fromTopology->getHexahedra(); for( size_t outId=0 ; outIdmaskTo->size() ; ++outId) { if( !this->maskTo->getEntry(outId) ) continue; - const Real fx = map.getValue()[outId].baryCoords[0]; - const Real fy = map.getValue()[outId].baryCoords[1]; - const Real fz = map.getValue()[outId].baryCoords[2]; - int index = map.getValue()[outId].in_index; - const core::topology::BaseMeshTopology::Hexahedron& cube = cubes[index]; + const Hexahedron& hexa = hexas[d_map.getValue()[outId].in_index]; - this->addMatrixContrib(matrixJ, outId, cube[0], ( ( 1-fx ) * ( 1-fy ) * ( 1-fz ) )); - this->addMatrixContrib(matrixJ, outId, cube[1], ( ( fx ) * ( 1-fy ) * ( 1-fz ) )); - this->addMatrixContrib(matrixJ, outId, cube[2], ( ( fx ) * ( fy ) * ( 1-fz ) )); - this->addMatrixContrib(matrixJ, outId, cube[3], ( ( 1-fx ) * ( fy ) * ( 1-fz ) )); - this->addMatrixContrib(matrixJ, outId, cube[4], ( ( 1-fx ) * ( 1-fy ) * ( fz ) )); - this->addMatrixContrib(matrixJ, outId, cube[5], ( ( fx ) * ( 1-fy ) * ( fz ) )); - this->addMatrixContrib(matrixJ, outId, cube[6], ( ( fx ) * ( fy ) * ( fz ) )); - this->addMatrixContrib(matrixJ, outId, cube[7], ( ( 1-fx ) * ( fy ) * ( fz ) )); + helper::vector baryCoef = getBaryCoef(d_map.getValue()[outId].baryCoords); + for (unsigned int j=0; jaddMatrixContrib(m_matrixJ, outId, hexa[j], baryCoef[j]); } - matrixJ->compress(); - updateJ = false; - return matrixJ; + m_matrixJ->compress(); + m_updateJ = false; + return m_matrixJ; } -/////////////////////////////////////////////////////////////////////////////////////////////// -/////////////////////////////////////////////////////////////////////////////////////////////// - - - - +/************************************* Draw ***********************************/ template @@ -2501,38 +2278,43 @@ void BarycentricMapping::draw(const core::visual::VisualParams* vpara { if ( !vparams->displayFlags().getShowMappings() ) return; + // Draw model (out) points const OutVecCoord& out = this->toModel->read(core::ConstVecCoordId::position())->getValue(); - std::vector< sofa::defaulttype::Vector3 > points; + std::vector< Vector3 > points; for ( unsigned int i=0; idrawTool()->drawPoints ( points, 7, sofa::defaulttype::Vec<4,float> ( 1,1,0,1 ) ); + + // Draw mapping line between models const InVecCoord& in = this->fromModel->read(core::ConstVecCoordId::position())->getValue(); - if ( mapper!=NULL ) mapper->draw(vparams,out, in ); + if ( m_mapper!=NULL ) + m_mapper->draw(vparams,out,in); - vparams->drawTool()->drawPoints ( points, 7, sofa::defaulttype::Vec<4,float> ( 1,1,0,1 ) ); } template -void BarycentricMapperMeshTopology::draw (const core::visual::VisualParams* vparams,const typename Out::VecCoord& out, const typename In::VecCoord& in ) +void BarycentricMapperMeshTopology::draw (const core::visual::VisualParams* vparams, + const typename Out::VecCoord& out, + const typename In::VecCoord& in ) { - const sofa::core::topology::BaseMeshTopology::SeqLines& lines = this->fromTopology->getLines(); - const sofa::core::topology::BaseMeshTopology::SeqTriangles& triangles = this->fromTopology->getTriangles(); - const sofa::core::topology::BaseMeshTopology::SeqQuads& quads = this->fromTopology->getQuads(); - const sofa::core::topology::BaseMeshTopology::SeqTetrahedra& tetrahedra = this->fromTopology->getTetrahedra(); - const sofa::core::topology::BaseMeshTopology::SeqHexahedra& cubes = this->fromTopology->getHexahedra(); + const SeqLines& lines = this->m_fromTopology->getLines(); + const SeqTriangles& triangles = this->m_fromTopology->getTriangles(); + const SeqQuads& quads = this->m_fromTopology->getQuads(); + const SeqTetrahedra& tetrahedra = this->m_fromTopology->getTetrahedra(); + const SeqHexahedra& cubes = this->m_fromTopology->getHexahedra(); - std::vector< sofa::defaulttype::Vector3 > points; + std::vector< Vector3 > points; // 1D elements { const int i0 = 0; - for ( unsigned int i=0; i::draw (const core::visual::VisualPar { if ( f[j]<=-0.0001 || f[j]>=0.0001 ) { - // glColor3f((float)f[j],1,(float)f[j]); points.push_back ( Out::getCPos(out[i+i0]) ); points.push_back ( in[line[j]] ); } @@ -2550,16 +2331,16 @@ void BarycentricMapperMeshTopology::draw (const core::visual::VisualPar } // 2D elements { - const int i0 = map1d.size(); + const int i0 = m_map1d.size(); const int c0 = triangles.size(); - for ( unsigned int i=0; i::draw (const core::visual::VisualPar { if ( f[j]<=-0.0001 || f[j]>=0.0001 ) { - // glColor3f((float)f[j],1,(float)f[j]); points.push_back ( Out::getCPos(out[i+i0]) ); points.push_back ( in[triangle[j]] ); } @@ -2576,7 +2356,7 @@ void BarycentricMapperMeshTopology::draw (const core::visual::VisualPar } else { - const sofa::core::topology::BaseMeshTopology::Quad& quad = quads[index-c0]; + const Quad& quad = quads[index-c0]; Real f[4]; f[0] = ( ( 1-fx ) * ( 1-fy ) ); f[1] = ( ( fx ) * ( 1-fy ) ); @@ -2586,7 +2366,6 @@ void BarycentricMapperMeshTopology::draw (const core::visual::VisualPar { if ( f[j]<=-0.0001 || f[j]>=0.0001 ) { - // glColor3f((float)f[j],1,(float)f[j]); points.push_back ( Out::getCPos(out[i+i0]) ); points.push_back ( in[quad[j]] ); } @@ -2596,17 +2375,17 @@ void BarycentricMapperMeshTopology::draw (const core::visual::VisualPar } // 3D elements { - const int i0 = map1d.size() +map2d.size(); + const int i0 = m_map1d.size() +m_map2d.size(); const int c0 = tetrahedra.size(); - for ( unsigned int i=0; i::draw (const core::visual::VisualPar { if ( f[j]<=-0.0001 || f[j]>=0.0001 ) { - // glColor3f((float)f[j],1,(float)f[j]); points.push_back ( Out::getCPos(out[i+i0]) ); points.push_back ( in[tetra[j]] ); } @@ -2624,7 +2402,7 @@ void BarycentricMapperMeshTopology::draw (const core::visual::VisualPar } else { - const sofa::core::topology::BaseMeshTopology::Hexa& cube = cubes[index-c0]; + const Hexa& cube = cubes[index-c0]; Real f[8]; f[0] = ( 1-fx ) * ( 1-fy ) * ( 1-fz ); @@ -2643,7 +2421,6 @@ void BarycentricMapperMeshTopology::draw (const core::visual::VisualPar { if ( f[j]<=-0.0001 || f[j]>=0.0001 ) { - // glColor3f((float)f[j],1,1); points.push_back ( Out::getCPos(out[i+i0]) ); points.push_back ( in[cube[j]] ); } @@ -2655,18 +2432,20 @@ void BarycentricMapperMeshTopology::draw (const core::visual::VisualPar } template -void BarycentricMapperRegularGridTopology::draw (const core::visual::VisualParams* vparams,const typename Out::VecCoord& out, const typename In::VecCoord& in ) +void BarycentricMapperRegularGridTopology::draw (const core::visual::VisualParams* vparams, + const typename Out::VecCoord& out, + const typename In::VecCoord& in ) { - std::vector< sofa::defaulttype::Vector3 > points; + std::vector< Vector3 > points; - for ( unsigned int i=0; ifromTopology->getHexaCopy ( this->map[i].in_index ); + const topology::RegularGridTopology::Hexa cube = this->m_fromTopology->getHexaCopy ( this->m_map[i].in_index ); - const Real fx = map[i].baryCoords[0]; - const Real fy = map[i].baryCoords[1]; - const Real fz = map[i].baryCoords[2]; + const Real fx = m_map[i].baryCoords[0]; + const Real fy = m_map[i].baryCoords[1]; + const Real fz = m_map[i].baryCoords[2]; Real f[8]; f[0] = ( 1-fx ) * ( 1-fy ) * ( 1-fz ); f[1] = ( fx ) * ( 1-fy ) * ( 1-fz ); @@ -2684,7 +2463,6 @@ void BarycentricMapperRegularGridTopology::draw (const core::visual::Vi { if ( f[j]<=-0.0001 || f[j]>=0.0001 ) { - //glColor3f((float)f[j],(float)f[j],1); points.push_back ( Out::getCPos(out[i]) ); points.push_back ( in[cube[j]] ); } @@ -2695,17 +2473,19 @@ void BarycentricMapperRegularGridTopology::draw (const core::visual::Vi } template -void BarycentricMapperSparseGridTopology::draw (const core::visual::VisualParams* vparams,const typename Out::VecCoord& out, const typename In::VecCoord& in ) +void BarycentricMapperSparseGridTopology::draw (const core::visual::VisualParams* vparams, + const typename Out::VecCoord& out, + const typename In::VecCoord& in ) { - std::vector< sofa::defaulttype::Vector3 > points; - for ( unsigned int i=0; i points; + for ( unsigned int i=0; ifromTopology->getHexahedron ( this->map[i].in_index ); + const topology::SparseGridTopology::Hexa cube = this->m_fromTopology->getHexahedron ( this->m_map[i].in_index ); - const Real fx = map[i].baryCoords[0]; - const Real fy = map[i].baryCoords[1]; - const Real fz = map[i].baryCoords[2]; + const Real fx = m_map[i].baryCoords[0]; + const Real fy = m_map[i].baryCoords[1]; + const Real fz = m_map[i].baryCoords[2]; Real f[8]; f[0] = ( 1-fx ) * ( 1-fy ) * ( 1-fz ); f[1] = ( fx ) * ( 1-fy ) * ( 1-fz ); @@ -2723,44 +2503,34 @@ void BarycentricMapperSparseGridTopology::draw (const core::visual::Vis { if ( f[j]<=-0.0001 || f[j]>=0.0001 ) { - //glColor3f((float)f[j],(float)f[j],1); points.push_back ( Out::getCPos(out[i]) ); points.push_back ( in[cube[j]] ); } } } vparams->drawTool()->drawLines ( points, 1, sofa::defaulttype::Vec<4,float> ( 0,0,1,1 ) ); - } -template -void BarycentricMapperEdgeSetTopology::draw (const core::visual::VisualParams* vparams,const typename Out::VecCoord& out, const typename In::VecCoord& in ) +template +void BarycentricMapperEdgeSetTopology::draw (const core::visual::VisualParams* vparams, + const typename Out::VecCoord& out, + const typename In::VecCoord& in ) { - const sofa::helper::vector& edges = this->fromTopology->getEdges(); + // Draw line between mapped node (out) and nodes of nearest element (in) + const helper::vector& edges = this->m_fromTopology->getEdges(); - std::vector< sofa::defaulttype::Vector3 > points; + std::vector< Vector3 > points; { - for ( unsigned int i=0; i=0.0001 ) - { - // glColor3f((float)f,1,(float)f); - points.push_back ( Out::getCPos(out[i]) ); - points.push_back ( in[edge[0]] ); - } - } + const Edge& edge = edges[d_map.getValue()[i].in_index]; + helper::vector baryCoef = getBaryCoef(d_map.getValue()[i].baryCoords); + for ( int j=0; j<2; j++ ) { - const Real f = fx; - if ( f<=-0.0001 || f>=0.0001 ) + if ( baryCoef[j]<=-0.0001 || baryCoef[j]>=0.0001 ) { - // glColor3f((float)f,1,(float)f); points.push_back ( Out::getCPos(out[i]) ); - points.push_back ( in[edge[1]] ); + points.push_back ( in[edge[j]] ); } } } @@ -2768,28 +2538,24 @@ void BarycentricMapperEdgeSetTopology::draw (const core::visual::Visual vparams->drawTool()->drawLines ( points, 1, sofa::defaulttype::Vec<4,float> ( 0,1,0,1 ) ); } -template -void BarycentricMapperTriangleSetTopology::draw (const core::visual::VisualParams* vparams,const typename Out::VecCoord& out, const typename In::VecCoord& in ) +template +void BarycentricMapperTriangleSetTopology::draw (const core::visual::VisualParams* vparams, + const typename Out::VecCoord& out, + const typename In::VecCoord& in ) { - const sofa::helper::vector& triangles = this->fromTopology->getTriangles(); + // Draw line between mapped node (out) and nodes of nearest element (in) + const helper::vector& triangles = m_fromTopology->getTriangles(); - std::vector< sofa::defaulttype::Vector3 > points; + std::vector< Vector3 > points; { - for ( unsigned int i=0; i baryCoef = getBaryCoef(d_map.getValue()[i].baryCoords); for ( int j=0; j<3; j++ ) { - if ( f[j]<=-0.0001 || f[j]>=0.0001 ) + if ( baryCoef[j]<=-0.0001 || baryCoef[j]>=0.0001 ) { - // glColor3f((float)f[j],1,(float)f[j]); points.push_back ( Out::getCPos(out[i]) ); points.push_back ( in[triangle[j]] ); } @@ -2799,28 +2565,24 @@ void BarycentricMapperTriangleSetTopology::draw (const core::visual::Vi vparams->drawTool()->drawLines ( points, 1, sofa::defaulttype::Vec<4,float> ( 0,1,0,1 ) ); } -template -void BarycentricMapperQuadSetTopology::draw (const core::visual::VisualParams* vparams,const typename Out::VecCoord& out, const typename In::VecCoord& in ) +template +void BarycentricMapperQuadSetTopology::draw (const core::visual::VisualParams* vparams, + const typename Out::VecCoord& out, + const typename In::VecCoord& in ) { - const sofa::helper::vector& quads = this->fromTopology->getQuads(); - std::vector< sofa::defaulttype::Vector3 > points; + // Draw line between mapped node (out) and nodes of nearest element (in) + const helper::vector& quads = this->m_fromTopology->getQuads(); + + std::vector< Vector3 > points; { - for ( unsigned int i=0; i baryCoef = getBaryCoef(d_map.getValue()[i].baryCoords); for ( int j=0; j<4; j++ ) { - if ( f[j]<=-0.0001 || f[j]>=0.0001 ) + if ( baryCoef[j]<=-0.0001 || baryCoef[j]>=0.0001 ) { - // glColor3f((float)f[j],1,(float)f[j]); points.push_back ( Out::getCPos(out[i]) ); points.push_back ( in[quad[j]] ); } @@ -2830,30 +2592,23 @@ void BarycentricMapperQuadSetTopology::draw (const core::visual::Visual vparams->drawTool()->drawLines ( points, 1, sofa::defaulttype::Vec<4,float> ( 0,1,0,1 ) ); } -template -void BarycentricMapperTetrahedronSetTopology::draw (const core::visual::VisualParams* vparams,const typename Out::VecCoord& out, const typename In::VecCoord& in ) +template +void BarycentricMapperTetrahedronSetTopology::draw (const core::visual::VisualParams* vparams, + const typename Out::VecCoord& out, + const typename In::VecCoord& in ) { - const sofa::helper::vector& tetrahedra = this->fromTopology->getTetrahedra(); + const helper::vector& tetrahedra = this->m_fromTopology->getTetrahedra(); - std::vector< sofa::defaulttype::Vector3 > points; + std::vector< Vector3 > points; { - for ( unsigned int i=0; i baryCoef = getBaryCoef(d_map.getValue()[i].baryCoords); for ( int j=0; j<4; j++ ) { - if ( f[j]<=-0.0001 || f[j]>=0.0001 ) + if ( baryCoef[j]<=-0.0001 || baryCoef[j]>=0.0001 ) { - // glColor3f((float)f[j],1,(float)f[j]); points.push_back ( Out::getCPos(out[i]) ); points.push_back ( in[tetra[j]] ); } @@ -2863,36 +2618,27 @@ void BarycentricMapperTetrahedronSetTopology::draw (const core::visual: vparams->drawTool()->drawLines ( points, 1, sofa::defaulttype::Vec<4,float> ( 0,1,0,1 ) ); } -template -void BarycentricMapperHexahedronSetTopology::draw (const core::visual::VisualParams* vparams,const typename Out::VecCoord& out, const typename In::VecCoord& in ) +template +void BarycentricMapperHexahedronSetTopology::draw (const core::visual::VisualParams* vparams, + const typename Out::VecCoord& out, + const typename In::VecCoord& in ) { - const sofa::helper::vector& cubes = this->fromTopology->getHexahedra(); + // Draw line between mapped node (out) and nodes of nearest element (in) + const helper::vector& hexas = this->m_fromTopology->getHexahedra(); - std::vector< sofa::defaulttype::Vector3 > points; + std::vector< Vector3 > points; { - for ( unsigned int i=0; i baryCoef = getBaryCoef(d_map.getValue()[i].baryCoords); for ( int j=0; j<8; j++ ) { - if ( f[j]<=-0.0001 || f[j]>=0.0001 ) + if ( baryCoef[j]<=-0.0001 || baryCoef[j]>=0.0001 ) { - // glColor3f((float)f[j],1,1); points.push_back ( Out::getCPos(out[i]) ); - points.push_back ( in[cube[j]] ); + points.push_back ( in[hexa[j]] ); } } } @@ -2900,43 +2646,41 @@ void BarycentricMapperHexahedronSetTopology::draw (const core::visual:: vparams->drawTool()->drawLines ( points, 1, sofa::defaulttype::Vec<4,float> ( 0,1,0,1 ) ); } + /************************************* PropagateConstraint ***********************************/ template -void BarycentricMapping::applyJT(const core::ConstraintParams * /*cparams*/, Data< typename In::MatrixDeriv >& out, const Data< typename Out::MatrixDeriv >& in) +void BarycentricMapping::applyJT(const core::ConstraintParams * cparams, Data< typename In::MatrixDeriv >& out, const Data< typename Out::MatrixDeriv >& in) { + SOFA_UNUSED(cparams); + if ( #ifdef SOFA_DEV sleeping.getValue()==false && #endif - mapper!=NULL ) + m_mapper!=NULL ) { - mapper->applyJT(*out.beginEdit(), in.getValue()); + m_mapper->applyJT(*out.beginEdit(), in.getValue()); out.endEdit(); } } - -/// @todo Optimization template void BarycentricMapperMeshTopology::applyJT ( typename In::MatrixDeriv& out, const typename Out::MatrixDeriv& in ) { - const sofa::core::topology::BaseMeshTopology::SeqLines& lines = this->fromTopology->getLines(); - const sofa::core::topology::BaseMeshTopology::SeqTriangles& triangles = this->fromTopology->getTriangles(); - const sofa::core::topology::BaseMeshTopology::SeqQuads& quads = this->fromTopology->getQuads(); - const sofa::core::topology::BaseMeshTopology::SeqTetrahedra& tetrahedra = this->fromTopology->getTetrahedra(); - const sofa::core::topology::BaseMeshTopology::SeqHexahedra& cubes = this->fromTopology->getHexahedra(); + const SeqLines& lines = this->m_fromTopology->getLines(); + const SeqTriangles& triangles = this->m_fromTopology->getTriangles(); + const SeqQuads& quads = this->m_fromTopology->getQuads(); + const SeqTetrahedra& tetrahedra = this->m_fromTopology->getTetrahedra(); + const SeqHexahedra& hexas = this->m_fromTopology->getHexahedra(); - //const size_t iLine = lines.size(); const size_t iTri = triangles.size(); - //const size_t iQuad = quads.size(); const size_t iTetra= tetrahedra.size(); - //const size_t iCube = cubes.size(); - const size_t i1d = map1d.size(); - const size_t i2d = map2d.size(); - const size_t i3d = map3d.size(); + const size_t i1d = m_map1d.size(); + const size_t i2d = m_map2d.size(); + const size_t i3d = m_map3d.size(); size_t indexIn; @@ -2959,10 +2703,10 @@ void BarycentricMapperMeshTopology::applyJT ( typename In::MatrixDeriv& // 1D elements if ( indexIn < i1d ) { - const OutReal fx = ( OutReal ) map1d[indexIn].baryCoords[0]; - size_t index = map1d[indexIn].in_index; + const OutReal fx = ( OutReal ) m_map1d[indexIn].baryCoords[0]; + size_t index = m_map1d[indexIn].in_index; { - const sofa::core::topology::BaseMeshTopology::Line& line = lines[index]; + const Line& line = lines[index]; o.addCol( line[0], data * ( 1-fx ) ); o.addCol( line[1], data * fx ); } @@ -2970,55 +2714,55 @@ void BarycentricMapperMeshTopology::applyJT ( typename In::MatrixDeriv& // 2D elements : triangle or quad else if ( indexIn < i2d ) { - const OutReal fx = ( OutReal ) map2d[indexIn].baryCoords[0]; - const OutReal fy = ( OutReal ) map2d[indexIn].baryCoords[1]; - size_t index = map2d[indexIn].in_index; + const OutReal fx = ( OutReal ) m_map2d[indexIn].baryCoords[0]; + const OutReal fy = ( OutReal ) m_map2d[indexIn].baryCoords[1]; + size_t index = m_map2d[indexIn].in_index; if ( index < iTri ) // triangle { - const sofa::core::topology::BaseMeshTopology::Triangle& triangle = triangles[index]; + const Triangle& triangle = triangles[index]; o.addCol( triangle[0], data * ( 1-fx-fy ) ); o.addCol( triangle[1], data * fx ); o.addCol( triangle[2], data * fy ); } - else // 2D element : Quad + else // quad { - const sofa::core::topology::BaseMeshTopology::Quad& quad = quads[index - iTri]; + const Quad& quad = quads[index - iTri]; o.addCol( quad[0], data * ( ( 1-fx ) * ( 1-fy ) ) ); o.addCol( quad[1], data * ( ( fx ) * ( 1-fy ) ) ); o.addCol( quad[3], data * ( ( 1-fx ) * ( fy ) ) ); o.addCol( quad[2], data * ( ( fx ) * ( fy ) ) ); } } - // 3D elements + // 3D elements : tetra or hexa else if ( indexIn < i3d ) { - const OutReal fx = ( OutReal ) map3d[indexIn].baryCoords[0]; - const OutReal fy = ( OutReal ) map3d[indexIn].baryCoords[1]; - const OutReal fz = ( OutReal ) map3d[indexIn].baryCoords[2]; - size_t index = map3d[indexIn].in_index; + const OutReal fx = ( OutReal ) m_map3d[indexIn].baryCoords[0]; + const OutReal fy = ( OutReal ) m_map3d[indexIn].baryCoords[1]; + const OutReal fz = ( OutReal ) m_map3d[indexIn].baryCoords[2]; + size_t index = m_map3d[indexIn].in_index; if ( index < iTetra ) // tetra { - const sofa::core::topology::BaseMeshTopology::Tetra& tetra = tetrahedra[index]; + const Tetra& tetra = tetrahedra[index]; o.addCol ( tetra[0], data * ( 1-fx-fy-fz ) ); o.addCol ( tetra[1], data * fx ); o.addCol ( tetra[2], data * fy ); o.addCol ( tetra[3], data * fz ); } - else // cube + else // hexa { - const sofa::core::topology::BaseMeshTopology::Hexa& cube = cubes[index-iTetra]; + const Hexa& hexa = hexas[index-iTetra]; - o.addCol ( cube[0],data * ( ( 1-fx ) * ( 1-fy ) * ( 1-fz ) ) ) ; - o.addCol ( cube[1],data * ( ( fx ) * ( 1-fy ) * ( 1-fz ) ) ) ; + o.addCol ( hexa[0],data * ( ( 1-fx ) * ( 1-fy ) * ( 1-fz ) ) ) ; + o.addCol ( hexa[1],data * ( ( fx ) * ( 1-fy ) * ( 1-fz ) ) ) ; - o.addCol ( cube[3],data * ( ( 1-fx ) * ( fy ) * ( 1-fz ) ) ) ; - o.addCol ( cube[2],data * ( ( fx ) * ( fy ) * ( 1-fz ) ) ) ; + o.addCol ( hexa[3],data * ( ( 1-fx ) * ( fy ) * ( 1-fz ) ) ) ; + o.addCol ( hexa[2],data * ( ( fx ) * ( fy ) * ( 1-fz ) ) ) ; - o.addCol ( cube[4],data * ( ( 1-fx ) * ( 1-fy ) * ( fz ) ) ) ; - o.addCol ( cube[5],data * ( ( fx ) * ( 1-fy ) * ( fz ) ) ) ; + o.addCol ( hexa[4],data * ( ( 1-fx ) * ( 1-fy ) * ( fz ) ) ) ; + o.addCol ( hexa[5],data * ( ( fx ) * ( 1-fy ) * ( fz ) ) ) ; - o.addCol ( cube[7],data * ( ( 1-fx ) * ( fy ) * ( fz ) ) ) ; - o.addCol ( cube[6],data * ( ( fx ) * ( fy ) * ( fz ) ) ) ; + o.addCol ( hexa[7],data * ( ( 1-fx ) * ( fy ) * ( fz ) ) ) ; + o.addCol ( hexa[6],data * ( ( fx ) * ( fy ) * ( fz ) ) ) ; } } } @@ -3046,11 +2790,11 @@ void BarycentricMapperRegularGridTopology::applyJT ( typename In::Matrix InDeriv data = (InDeriv) Out::getDPos(colIt.val()); - const topology::RegularGridTopology::Hexa cube = this->fromTopology->getHexaCopy ( this->map[indexIn].in_index ); + const topology::RegularGridTopology::Hexa cube = this->m_fromTopology->getHexaCopy ( this->m_map[indexIn].in_index ); - const OutReal fx = (OutReal) map[indexIn].baryCoords[0]; - const OutReal fy = (OutReal) map[indexIn].baryCoords[1]; - const OutReal fz = (OutReal) map[indexIn].baryCoords[2]; + const OutReal fx = (OutReal) m_map[indexIn].baryCoords[0]; + const OutReal fy = (OutReal) m_map[indexIn].baryCoords[1]; + const OutReal fz = (OutReal) m_map[indexIn].baryCoords[2]; const OutReal oneMinusFx = 1-fx; const OutReal oneMinusFy = 1-fy; const OutReal oneMinusFz = 1-fz; @@ -3091,11 +2835,11 @@ void BarycentricMapperSparseGridTopology::applyJT ( typename In::MatrixD InDeriv data = (InDeriv) Out::getDPos(colIt.val()); - const topology::SparseGridTopology::Hexa cube = this->fromTopology->getHexahedron ( this->map[indexIn].in_index ); + const topology::SparseGridTopology::Hexa cube = this->m_fromTopology->getHexahedron ( this->m_map[indexIn].in_index ); - const OutReal fx = ( OutReal ) map[indexIn].baryCoords[0]; - const OutReal fy = ( OutReal ) map[indexIn].baryCoords[1]; - const OutReal fz = ( OutReal ) map[indexIn].baryCoords[2]; + const OutReal fx = ( OutReal ) m_map[indexIn].baryCoords[0]; + const OutReal fy = ( OutReal ) m_map[indexIn].baryCoords[1]; + const OutReal fz = ( OutReal ) m_map[indexIn].baryCoords[2]; const OutReal oneMinusFx = 1-fx; const OutReal oneMinusFy = 1-fy; const OutReal oneMinusFz = 1-fz; @@ -3131,11 +2875,11 @@ void BarycentricMapperSparseGridTopology::applyJT ( typename In::MatrixD } } -template -void BarycentricMapperEdgeSetTopology::applyJT ( typename In::MatrixDeriv& out, const typename Out::MatrixDeriv& in ) +template +void BarycentricMapperEdgeSetTopology::applyJT ( typename In::MatrixDeriv& out, const typename Out::MatrixDeriv& in ) { typename Out::MatrixDeriv::RowConstIterator rowItEnd = in.end(); - const sofa::helper::vector& edges = this->fromTopology->getEdges(); + const helper::vector& edges = this->m_fromTopology->getEdges(); for (typename Out::MatrixDeriv::RowConstIterator rowIt = in.begin(); rowIt != rowItEnd; ++rowIt) { @@ -3150,21 +2894,21 @@ void BarycentricMapperEdgeSetTopology::applyJT ( typename In::MatrixDeri unsigned indexIn = colIt.index(); InDeriv data = (InDeriv) Out::getDPos(colIt.val()); - const core::topology::BaseMeshTopology::Edge edge = edges[this->map.getValue()[indexIn].in_index]; - const OutReal fx = ( OutReal ) map.getValue()[indexIn].baryCoords[0]; + const Edge edge = edges[this->d_map.getValue()[indexIn].in_index]; - o.addCol ( edge[0], data * ( 1-fx ) ); - o.addCol ( edge[1], data * ( fx ) ); + helper::vector baryCoef = getBaryCoef(d_map.getValue()[indexIn].baryCoords); + for (unsigned int j=0; j -void BarycentricMapperTriangleSetTopology::applyJT ( typename In::MatrixDeriv& out, const typename Out::MatrixDeriv& in ) +template +void BarycentricMapperTriangleSetTopology::applyJT ( typename In::MatrixDeriv& out, const typename Out::MatrixDeriv& in ) { typename Out::MatrixDeriv::RowConstIterator rowItEnd = in.end(); - const sofa::helper::vector& triangles = this->fromTopology->getTriangles(); + const helper::vector& triangles = this->m_fromTopology->getTriangles(); for (typename Out::MatrixDeriv::RowConstIterator rowIt = in.begin(); rowIt != rowItEnd; ++rowIt) { @@ -3180,23 +2924,21 @@ void BarycentricMapperTriangleSetTopology::applyJT ( typename In::Matrix unsigned indexIn = colIt.index(); InDeriv data = (InDeriv) Out::getDPos(colIt.val()); - const core::topology::BaseMeshTopology::Triangle triangle = triangles[this->map.getValue()[indexIn].in_index]; - const OutReal fx = ( OutReal ) map.getValue()[indexIn].baryCoords[0]; - const OutReal fy = ( OutReal ) map.getValue()[indexIn].baryCoords[1]; + const Triangle triangle = triangles[this->d_map.getValue()[indexIn].in_index]; - o.addCol (triangle[0],data * ( 1-fx-fy ) ); - o.addCol (triangle[1],data * ( fx ) ); - o.addCol (triangle[2],data * ( fy ) ); + helper::vector baryCoef = getBaryCoef(d_map.getValue()[indexIn].baryCoords); + for (unsigned int j=0; j -void BarycentricMapperQuadSetTopology::applyJT ( typename In::MatrixDeriv& out, const typename Out::MatrixDeriv& in ) +template +void BarycentricMapperQuadSetTopology::applyJT ( typename In::MatrixDeriv& out, const typename Out::MatrixDeriv& in ) { typename Out::MatrixDeriv::RowConstIterator rowItEnd = in.end(); - const sofa::helper::vector& quads = this->fromTopology->getQuads(); + const helper::vector& quads = this->m_fromTopology->getQuads(); for (typename Out::MatrixDeriv::RowConstIterator rowIt = in.begin(); rowIt != rowItEnd; ++rowIt) { @@ -3212,24 +2954,21 @@ void BarycentricMapperQuadSetTopology::applyJT ( typename In::MatrixDeri unsigned indexIn = colIt.index(); InDeriv data = (InDeriv) Out::getDPos(colIt.val()); - const OutReal fx = ( OutReal ) map.getValue()[indexIn].baryCoords[0]; - const OutReal fy = ( OutReal ) map.getValue()[indexIn].baryCoords[1]; - const sofa::core::topology::BaseMeshTopology::Quad& quad = quads[map.getValue()[indexIn].in_index]; + const Quad& quad = quads[d_map.getValue()[indexIn].in_index]; - o.addCol (quad[0], data * ( ( 1-fx ) * ( 1-fy ) ) ); - o.addCol (quad[1], data * ( ( fx ) * ( 1-fy ) ) ); - o.addCol (quad[3], data * ( ( 1-fx ) * ( fy ) ) ); - o.addCol (quad[2], data * ( ( fx ) * ( fy ) ) ); + helper::vector baryCoef = getBaryCoef(d_map.getValue()[indexIn].baryCoords); + for (unsigned int j=0; j -void BarycentricMapperTetrahedronSetTopology::applyJT ( typename In::MatrixDeriv& out, const typename Out::MatrixDeriv& in ) +template +void BarycentricMapperTetrahedronSetTopology::applyJT ( typename In::MatrixDeriv& out, const typename Out::MatrixDeriv& in ) { typename Out::MatrixDeriv::RowConstIterator rowItEnd = in.end(); - const sofa::helper::vector& tetrahedra = this->fromTopology->getTetrahedra(); + const helper::vector& tetrahedra = this->m_fromTopology->getTetrahedra(); for (typename Out::MatrixDeriv::RowConstIterator rowIt = in.begin(); rowIt != rowItEnd; ++rowIt) { @@ -3245,26 +2984,21 @@ void BarycentricMapperTetrahedronSetTopology::applyJT ( typename In::Mat unsigned indexIn = colIt.index(); InDeriv data = (InDeriv) Out::getDPos(colIt.val()); - const OutReal fx = ( OutReal ) map.getValue()[indexIn].baryCoords[0]; - const OutReal fy = ( OutReal ) map.getValue()[indexIn].baryCoords[1]; - const OutReal fz = ( OutReal ) map.getValue()[indexIn].baryCoords[2]; - int index = map.getValue()[indexIn].in_index; - const core::topology::BaseMeshTopology::Tetrahedron& tetra = tetrahedra[index]; + const Tetrahedron& tetra = tetrahedra[d_map.getValue()[indexIn].in_index]; - o.addCol (tetra[0], data * ( 1-fx-fy-fz ) ); - o.addCol (tetra[1], data * fx ); - o.addCol (tetra[2], data * fy ); - o.addCol (tetra[3], data * fz ); + helper::vector baryCoef = getBaryCoef(d_map.getValue()[indexIn].baryCoords); + for (unsigned int j=0; j -void BarycentricMapperHexahedronSetTopology::applyJT ( typename In::MatrixDeriv& out, const typename Out::MatrixDeriv& in ) +template +void BarycentricMapperHexahedronSetTopology::applyJT ( typename In::MatrixDeriv& out, const typename Out::MatrixDeriv& in ) { typename Out::MatrixDeriv::RowConstIterator rowItEnd = in.end(); - const sofa::helper::vector< core::topology::BaseMeshTopology::Hexahedron >& cubes = this->fromTopology->getHexahedra(); + const helper::vector< Hexahedron >& hexas = this->m_fromTopology->getHexahedra(); for (typename Out::MatrixDeriv::RowConstIterator rowIt = in.begin(); rowIt != rowItEnd; ++rowIt) { @@ -3280,43 +3014,32 @@ void BarycentricMapperHexahedronSetTopology::applyJT ( typename In::Matr unsigned indexIn = colIt.index(); InDeriv data = (InDeriv) Out::getDPos(colIt.val()); - const OutReal fx = ( OutReal ) map.getValue()[indexIn].baryCoords[0]; - const OutReal fy = ( OutReal ) map.getValue()[indexIn].baryCoords[1]; - const OutReal fz = ( OutReal ) map.getValue()[indexIn].baryCoords[2]; - const OutReal oneMinusFx = 1-fx; - const OutReal oneMinusFy = 1-fy; - const OutReal oneMinusFz = 1-fz; + const Hexahedron& hexa = hexas[d_map.getValue()[indexIn].in_index]; - int index = map.getValue()[indexIn].in_index; - const core::topology::BaseMeshTopology::Hexahedron& cube = cubes[index]; - - o.addCol (cube[0], data * ( oneMinusFx * oneMinusFy * oneMinusFz ) ); - o.addCol (cube[1], data * ( ( fx ) * oneMinusFy * oneMinusFz ) ); - o.addCol (cube[3], data * ( oneMinusFx * ( fy ) * oneMinusFz ) ); - o.addCol (cube[2], data * ( ( fx ) * ( fy ) * oneMinusFz ) ); - o.addCol (cube[4], data * ( oneMinusFx * oneMinusFy * ( fz ) ) ); - o.addCol (cube[5], data * ( ( fx ) * oneMinusFy * ( fz ) ) ); - o.addCol (cube[7], data * ( oneMinusFx * ( fy ) * ( fz ) ) ); - o.addCol (cube[6], data * ( ( fx ) * ( fy ) * ( fz ) ) ); + helper::vector baryCoef = getBaryCoef(d_map.getValue()[indexIn].baryCoords); + for (unsigned int j=0; j -void BarycentricMapperHexahedronSetTopology::handleTopologyChange(core::topology::Topology* t) + +template +void BarycentricMapperHexahedronSetTopology::handleTopologyChange(core::topology::Topology* t) { using sofa::core::behavior::MechanicalState; - if (t != this->fromTopology) return; + if (t != this->m_fromTopology) return; - if ( this->fromTopology->beginChange() == this->fromTopology->endChange() ) + if ( this->m_fromTopology->beginChange() == this->m_fromTopology->endChange() ) return; - std::list::const_iterator itBegin = this->fromTopology->beginChange(); - std::list::const_iterator itEnd = this->fromTopology->endChange(); + std::list::const_iterator itBegin = this->m_fromTopology->beginChange(); + std::list::const_iterator itEnd = this->m_fromTopology->endChange(); for ( std::list::const_iterator changeIt = itBegin; changeIt != itEnd; ++changeIt ) @@ -3327,17 +3050,17 @@ void BarycentricMapperHexahedronSetTopology::handleTopologyChange(core:: //TODO: implementation of BarycentricMapperHexahedronSetTopology::handleTopologyChange() case core::topology::ENDING_EVENT: ///< To notify the end for the current sequence of topological change events { - if(!_invalidIndex.empty()) + if(!m_invalidIndex.empty()) { - helper::vector& mapData = *(map.beginEdit()); + helper::vector& mapData = *(d_map.beginEdit()); - for ( std::set::const_iterator iter = _invalidIndex.begin(); - iter != _invalidIndex.end(); ++iter ) + for ( std::set::const_iterator iter = m_invalidIndex.begin(); + iter != m_invalidIndex.end(); ++iter ) { const int j = *iter; if ( mapData[j].in_index == -1 ) // compute new mapping { - sofa::defaulttype::Vector3 coefs; + Vector3 coefs; typename In::Coord pos; pos[0] = mapData[j].baryCoords[0]; pos[1] = mapData[j].baryCoords[1]; @@ -3360,13 +3083,13 @@ void BarycentricMapperHexahedronSetTopology::handleTopologyChange(core:: else { const typename MechanicalStateT::VecCoord& xto0 = (mState->read(core::ConstVecCoordId::restPosition())->getValue()); - index = _fromGeomAlgo->findNearestElementInRestPos ( Out::getCPos(xto0[j]), coefs, distance ); - coefs = _fromGeomAlgo->computeHexahedronRestBarycentricCoeficients(index, pos); + index = m_fromGeomAlgo->findNearestElementInRestPos ( Out::getCPos(xto0[j]), coefs, distance ); + coefs = m_fromGeomAlgo->computeHexahedronRestBarycentricCoeficients(index, pos); } } else { - index = _fromGeomAlgo->findNearestElementInRestPos ( pos, coefs, distance ); + index = m_fromGeomAlgo->findNearestElementInRestPos ( pos, coefs, distance ); } if ( index != -1 ) @@ -3379,8 +3102,8 @@ void BarycentricMapperHexahedronSetTopology::handleTopologyChange(core:: } } - map.endEdit(); - _invalidIndex.clear(); + d_map.endEdit(); + m_invalidIndex.clear(); } } break; @@ -3402,35 +3125,35 @@ void BarycentricMapperHexahedronSetTopology::handleTopologyChange(core:: break; case core::topology::HEXAHEDRAREMOVED: ///< For HexahedraRemoved. { - const unsigned int nbHexahedra = this->fromTopology->getNbHexahedra(); + const unsigned int nbHexahedra = this->m_fromTopology->getNbHexahedra(); - const sofa::helper::vector &hexahedra = + const helper::vector &hexahedra = ( static_cast< const core::topology::HexahedraRemoved *> ( *changeIt ) )->getArray(); - // sofa::helper::vector hexahedra(tab); + // helper::vector hexahedra(tab); for ( unsigned int i=0; igetRestPointPositionInHexahedron ( cubeId, coefs ); + typename In::Coord restPos = m_fromGeomAlgo->getRestPointPositionInHexahedron ( cubeId, coefs ); - helper::vector& vectorData = *(map.beginEdit()); + helper::vector& vectorData = *(d_map.beginEdit()); vectorData[j].in_index = -1; vectorData[j].baryCoords[0] = restPos[0]; vectorData[j].baryCoords[1] = restPos[1]; vectorData[j].baryCoords[2] = restPos[2]; - map.endEdit(); + d_map.endEdit(); - _invalidIndex.insert(j); + m_invalidIndex.insert(j); } } } @@ -3440,13 +3163,13 @@ void BarycentricMapperHexahedronSetTopology::handleTopologyChange(core:: for ( unsigned int i=0; i& vectorData = *(map.beginEdit()); + helper::vector& vectorData = *(d_map.beginEdit()); vectorData[j].in_index = cubeId; - map.endEdit(); + d_map.endEdit(); } } } @@ -3460,12 +3183,10 @@ void BarycentricMapperHexahedronSetTopology::handleTopologyChange(core:: } } -// handle topology changes depending on the topology template -void BarycentricMapping::handleTopologyChange ( core::topology::Topology* /*t*/ ) +void BarycentricMapping::handleTopologyChange ( core::topology::Topology* t ) { -// if (mapper) -// mapper->handleTopologyChange(t); + SOFA_UNUSED(t); reinit(); // we now recompute the entire mapping when there is a topologychange } @@ -3546,7 +3267,6 @@ void BarycentricMapperTriangleSetTopology::handleTopologyChange(core::to #endif // BARYCENTRIC_MAPPER_TOPOCHANGE_REINIT - template const helper::vector< defaulttype::BaseMatrix*>* BarycentricMapping::getJs() { @@ -3566,8 +3286,8 @@ const helper::vector< defaulttype::BaseMatrix*>* BarycentricMapping:: template void BarycentricMapping::updateForceMask() { - if( mapper ) - mapper->updateForceMask(); + if( m_mapper ) + m_mapper->updateForceMask(); } } // namespace mapping diff --git a/SofaKernel/modules/SofaMeshCollision/BarycentricContactMapper.h b/SofaKernel/modules/SofaMeshCollision/BarycentricContactMapper.h index 342d900ffa0..d912649e342 100644 --- a/SofaKernel/modules/SofaMeshCollision/BarycentricContactMapper.h +++ b/SofaKernel/modules/SofaMeshCollision/BarycentricContactMapper.h @@ -88,7 +88,7 @@ class BarycentricContactMapper : public BaseContactMapper { if (mapping!=NULL) { - mapper->clear(); + mapper->clearMapAndReserve(); mapping->getMechTo()[0]->resize(size); } } diff --git a/modules/SofaMiscMapping/BarycentricMappingRigid.cpp b/modules/SofaMiscMapping/BarycentricMappingRigid.cpp index 3c8f34d55b0..2e55c6c2e7e 100644 --- a/modules/SofaMiscMapping/BarycentricMappingRigid.cpp +++ b/modules/SofaMiscMapping/BarycentricMappingRigid.cpp @@ -62,12 +62,12 @@ int BarycentricMappingRigidClass = core::RegisterObject("") template <> void BarycentricMapperHexahedronSetTopology::handleTopologyChange(core::topology::Topology* t) { - if (t != this->fromTopology) return; - if ( this->fromTopology->beginChange() == this->fromTopology->endChange() ) + if (t != this->m_fromTopology) return; + if ( this->m_fromTopology->beginChange() == this->m_fromTopology->endChange() ) return; - std::list::const_iterator itBegin = this->fromTopology->beginChange(); - std::list::const_iterator itEnd = this->fromTopology->endChange(); + std::list::const_iterator itBegin = this->m_fromTopology->beginChange(); + std::list::const_iterator itEnd = this->m_fromTopology->endChange(); for ( std::list::const_iterator changeIt = itBegin; changeIt != itEnd; ++changeIt ) @@ -78,12 +78,12 @@ void BarycentricMapperHexahedronSetTopology::handleTopologyChange() case core::topology::ENDING_EVENT: ///< To notify the end for the current sequence of topological change events { - if(!_invalidIndex.empty()) + if(!m_invalidIndex.empty()) { - helper::vector& mapData = *(map.beginEdit()); + helper::vector& mapData = *(d_map.beginEdit()); - for ( std::set::const_iterator iter = _invalidIndex.begin(); - iter != _invalidIndex.end(); ++iter ) + for ( std::set::const_iterator iter = m_invalidIndex.begin(); + iter != m_invalidIndex.end(); ++iter ) { const int j = *iter; if ( mapData[j].in_index == -1 ) // compute new mapping @@ -97,7 +97,7 @@ void BarycentricMapperHexahedronSetTopologyfindNearestElementInRestPos ( pos, coefs, distance ); + int index = m_fromGeomAlgo->findNearestElementInRestPos ( pos, coefs, distance ); if ( index != -1 ) { @@ -109,8 +109,8 @@ void BarycentricMapperHexahedronSetTopologyfromTopology->getNbHexahedra(); + const unsigned int nbHexahedra = this->m_fromTopology->getNbHexahedra(); const sofa::helper::vector &hexahedra = ( static_cast< const sofa::core::topology::HexahedraRemoved *> ( *changeIt ) )->getArray(); @@ -141,25 +141,25 @@ void BarycentricMapperHexahedronSetTopologygetRestPointPositionInHexahedron ( cubeId, coefs ); + defaulttype::Vec3dTypes::Coord restPos = m_fromGeomAlgo->getRestPointPositionInHexahedron ( cubeId, coefs ); - helper::vector& vectorData = *(map.beginEdit()); + helper::vector& vectorData = *(d_map.beginEdit()); vectorData[j].in_index = -1; vectorData[j].baryCoords[0] = restPos[0]; vectorData[j].baryCoords[1] = restPos[1]; vectorData[j].baryCoords[2] = restPos[2]; - map.endEdit(); + d_map.endEdit(); - _invalidIndex.insert(j); + m_invalidIndex.insert(j); } } } @@ -169,13 +169,13 @@ void BarycentricMapperHexahedronSetTopology& vectorData = *(map.beginEdit()); + helper::vector& vectorData = *(d_map.beginEdit()); vectorData[j].in_index = cubeId; - map.endEdit(); + d_map.endEdit(); } } } @@ -194,13 +194,13 @@ void BarycentricMapperHexahedronSetTopology void BarycentricMapperHexahedronSetTopology::handleTopologyChange(core::topology::Topology* t) { - if (t != this->fromTopology) return; + if (t != this->m_fromTopology) return; - if ( this->fromTopology->beginChange() == this->fromTopology->endChange() ) + if ( this->m_fromTopology->beginChange() == this->m_fromTopology->endChange() ) return; - std::list::const_iterator itBegin = this->fromTopology->beginChange(); - std::list::const_iterator itEnd = this->fromTopology->endChange(); + std::list::const_iterator itBegin = this->m_fromTopology->beginChange(); + std::list::const_iterator itEnd = this->m_fromTopology->endChange(); for ( std::list::const_iterator changeIt = itBegin; changeIt != itEnd; ++changeIt ) @@ -211,12 +211,12 @@ void BarycentricMapperHexahedronSetTopology::handleTopologyChange() case core::topology::ENDING_EVENT: ///< To notify the end for the current sequence of topological change events { - if(!_invalidIndex.empty()) + if(!m_invalidIndex.empty()) { - helper::vector& mapData = *(map.beginEdit()); + helper::vector& mapData = *(d_map.beginEdit()); - for ( std::set::const_iterator iter = _invalidIndex.begin(); - iter != _invalidIndex.end(); ++iter ) + for ( std::set::const_iterator iter = m_invalidIndex.begin(); + iter != m_invalidIndex.end(); ++iter ) { const int j = *iter; if ( mapData[j].in_index == -1 ) // compute new mapping @@ -230,7 +230,7 @@ void BarycentricMapperHexahedronSetTopologyfindNearestElementInRestPos ( pos, coefs, distance ); + int index = m_fromGeomAlgo->findNearestElementInRestPos ( pos, coefs, distance ); if ( index != -1 ) { @@ -242,8 +242,8 @@ void BarycentricMapperHexahedronSetTopologyfromTopology->getNbHexahedra(); + const unsigned int nbHexahedra = this->m_fromTopology->getNbHexahedra(); const sofa::helper::vector &hexahedra = ( static_cast< const sofa::core::topology::HexahedraRemoved *> ( *changeIt ) )->getArray(); @@ -274,25 +274,25 @@ void BarycentricMapperHexahedronSetTopologygetRestPointPositionInHexahedron ( cubeId, coefs ); + defaulttype::Vec3fTypes::Coord restPos = m_fromGeomAlgo->getRestPointPositionInHexahedron ( cubeId, coefs ); - helper::vector& vectorData = *(map.beginEdit()); + helper::vector& vectorData = *(d_map.beginEdit()); vectorData[j].in_index = -1; vectorData[j].baryCoords[0] = restPos[0]; vectorData[j].baryCoords[1] = restPos[1]; vectorData[j].baryCoords[2] = restPos[2]; - map.endEdit(); + d_map.endEdit(); - _invalidIndex.insert(j); + m_invalidIndex.insert(j); } } } @@ -302,13 +302,13 @@ void BarycentricMapperHexahedronSetTopology& vectorData = *(map.beginEdit()); + helper::vector& vectorData = *(d_map.beginEdit()); vectorData[j].in_index = cubeId; - map.endEdit(); + d_map.endEdit(); } } } @@ -329,13 +329,13 @@ void BarycentricMapperHexahedronSetTopology void BarycentricMapperHexahedronSetTopology::handleTopologyChange(core::topology::Topology* t) { - if (t != this->fromTopology) return; + if (t != this->m_fromTopology) return; - if ( this->fromTopology->beginChange() == this->fromTopology->endChange() ) + if ( this->m_fromTopology->beginChange() == this->m_fromTopology->endChange() ) return; - std::list::const_iterator itBegin = this->fromTopology->beginChange(); - std::list::const_iterator itEnd = this->fromTopology->endChange(); + std::list::const_iterator itBegin = this->m_fromTopology->beginChange(); + std::list::const_iterator itEnd = this->m_fromTopology->endChange(); for ( std::list::const_iterator changeIt = itBegin; changeIt != itEnd; ++changeIt ) @@ -347,12 +347,12 @@ void BarycentricMapperHexahedronSetTopology::handleTopologyChange() case core::topology::ENDING_EVENT: ///< To notify the end for the current sequence of topological change events { - if(!_invalidIndex.empty()) + if(!m_invalidIndex.empty()) { - helper::vector& mapData = *(map.beginEdit()); + helper::vector& mapData = *(d_map.beginEdit()); - for ( std::set::const_iterator iter = _invalidIndex.begin(); - iter != _invalidIndex.end(); ++iter ) + for ( std::set::const_iterator iter = m_invalidIndex.begin(); + iter != m_invalidIndex.end(); ++iter ) { const int j = *iter; if ( mapData[j].in_index == -1 ) // compute new mapping @@ -366,7 +366,7 @@ void BarycentricMapperHexahedronSetTopologyfindNearestElementInRestPos ( pos, coefs, distance ); + int index = m_fromGeomAlgo->findNearestElementInRestPos ( pos, coefs, distance ); if ( index != -1 ) { @@ -378,8 +378,8 @@ void BarycentricMapperHexahedronSetTopologyfromTopology->getNbHexahedra(); + const unsigned int nbHexahedra = this->m_fromTopology->getNbHexahedra(); const sofa::helper::vector &hexahedra = ( static_cast< const sofa::core::topology::HexahedraRemoved *> ( *changeIt ) )->getArray(); @@ -410,25 +410,25 @@ void BarycentricMapperHexahedronSetTopologygetRestPointPositionInHexahedron ( cubeId, coefs ); + defaulttype::Vec3dTypes::Coord restPos = m_fromGeomAlgo->getRestPointPositionInHexahedron ( cubeId, coefs ); - helper::vector& vectorData = *(map.beginEdit()); + helper::vector& vectorData = *(d_map.beginEdit()); vectorData[j].in_index = -1; vectorData[j].baryCoords[0] = restPos[0]; vectorData[j].baryCoords[1] = restPos[1]; vectorData[j].baryCoords[2] = restPos[2]; - map.endEdit(); + d_map.endEdit(); - _invalidIndex.insert(j); + m_invalidIndex.insert(j); } } } @@ -438,13 +438,13 @@ void BarycentricMapperHexahedronSetTopology& vectorData = *(map.beginEdit()); + helper::vector& vectorData = *(d_map.beginEdit()); vectorData[j].in_index = cubeId; - map.endEdit(); + d_map.endEdit(); } } } @@ -463,13 +463,13 @@ void BarycentricMapperHexahedronSetTopology void BarycentricMapperHexahedronSetTopology::handleTopologyChange(core::topology::Topology* t) { - if (t != this->fromTopology) return; + if (t != this->m_fromTopology) return; - if ( this->fromTopology->beginChange() == this->fromTopology->endChange() ) + if ( this->m_fromTopology->beginChange() == this->m_fromTopology->endChange() ) return; - std::list::const_iterator itBegin = this->fromTopology->beginChange(); - std::list::const_iterator itEnd = this->fromTopology->endChange(); + std::list::const_iterator itBegin = this->m_fromTopology->beginChange(); + std::list::const_iterator itEnd = this->m_fromTopology->endChange(); for ( std::list::const_iterator changeIt = itBegin; changeIt != itEnd; ++changeIt ) @@ -481,12 +481,12 @@ void BarycentricMapperHexahedronSetTopology::handleTopologyChange() case core::topology::ENDING_EVENT: ///< To notify the end for the current sequence of topological change events { - if(!_invalidIndex.empty()) + if(!m_invalidIndex.empty()) { - helper::vector& mapData = *(map.beginEdit()); + helper::vector& mapData = *(d_map.beginEdit()); - for ( std::set::const_iterator iter = _invalidIndex.begin(); - iter != _invalidIndex.end(); ++iter ) + for ( std::set::const_iterator iter = m_invalidIndex.begin(); + iter != m_invalidIndex.end(); ++iter ) { const int j = *iter; if ( mapData[j].in_index == -1 ) // compute new mapping @@ -500,7 +500,7 @@ void BarycentricMapperHexahedronSetTopologyfindNearestElementInRestPos ( pos, coefs, distance ); + int index = m_fromGeomAlgo->findNearestElementInRestPos ( pos, coefs, distance ); if ( index != -1 ) { @@ -512,8 +512,8 @@ void BarycentricMapperHexahedronSetTopologyfromTopology->getNbHexahedra(); + const unsigned int nbHexahedra = this->m_fromTopology->getNbHexahedra(); const sofa::helper::vector &hexahedra = ( static_cast< const sofa::core::topology::HexahedraRemoved *> ( *changeIt ) )->getArray(); @@ -544,25 +544,25 @@ void BarycentricMapperHexahedronSetTopologygetRestPointPositionInHexahedron ( cubeId, coefs ); + defaulttype::Vec3fTypes::Coord restPos = m_fromGeomAlgo->getRestPointPositionInHexahedron ( cubeId, coefs ); - helper::vector& vectorData = *(map.beginEdit()); + helper::vector& vectorData = *(d_map.beginEdit()); vectorData[j].in_index = -1; vectorData[j].baryCoords[0] = restPos[0]; vectorData[j].baryCoords[1] = restPos[1]; vectorData[j].baryCoords[2] = restPos[2]; - map.endEdit(); + d_map.endEdit(); - _invalidIndex.insert(j); + m_invalidIndex.insert(j); } } } @@ -572,13 +572,13 @@ void BarycentricMapperHexahedronSetTopology& vectorData = *(map.beginEdit()); + helper::vector& vectorData = *(d_map.beginEdit()); vectorData[j].in_index = cubeId; - map.endEdit(); + d_map.endEdit(); } } } @@ -606,7 +606,7 @@ template class SOFA_MISC_MAPPING_API BarycentricMapperEdgeSetTopology< Vec3dType template class SOFA_MISC_MAPPING_API BarycentricMapperTriangleSetTopology< Vec3dTypes, Rigid3dTypes >; template class SOFA_MISC_MAPPING_API BarycentricMapperQuadSetTopology< Vec3dTypes, Rigid3dTypes >; template class SOFA_MISC_MAPPING_API BarycentricMapperTetrahedronSetTopologyRigid< Vec3dTypes, Rigid3dTypes >; -template class SOFA_MISC_MAPPING_API BarycentricMapperTetrahedronSetTopology< Vec3dTypes, Rigid3dTypes >; +//template class SOFA_MISC_MAPPING_API BarycentricMapperTetrahedronSetTopology< Vec3dTypes, Rigid3dTypes >; template class SOFA_MISC_MAPPING_API BarycentricMapperHexahedronSetTopology< Vec3dTypes, Rigid3dTypes >; #endif #ifndef SOFA_DOUBLE @@ -620,7 +620,7 @@ template class SOFA_MISC_MAPPING_API BarycentricMapperEdgeSetTopology< Vec3fType template class SOFA_MISC_MAPPING_API BarycentricMapperTriangleSetTopology< Vec3fTypes, Rigid3fTypes >; template class SOFA_MISC_MAPPING_API BarycentricMapperQuadSetTopology< Vec3fTypes, Rigid3fTypes >; template class SOFA_MISC_MAPPING_API BarycentricMapperTetrahedronSetTopologyRigid< Vec3fTypes, Rigid3fTypes >; -template class SOFA_MISC_MAPPING_API BarycentricMapperTetrahedronSetTopology< Vec3fTypes, Rigid3fTypes >; +//template class SOFA_MISC_MAPPING_API BarycentricMapperTetrahedronSetTopology< Vec3fTypes, Rigid3fTypes >; template class SOFA_MISC_MAPPING_API BarycentricMapperHexahedronSetTopology< Vec3fTypes, Rigid3fTypes >; #endif #ifndef SOFA_FLOAT @@ -637,16 +637,14 @@ template class SOFA_MISC_MAPPING_API BarycentricMapperSparseGridTopology< Vec3dT template class SOFA_MISC_MAPPING_API BarycentricMapperSparseGridTopology< Vec3fTypes, Rigid3dTypes >; template class SOFA_MISC_MAPPING_API BarycentricMapperMeshTopology< Vec3dTypes, Rigid3fTypes >; template class SOFA_MISC_MAPPING_API BarycentricMapperMeshTopology< Vec3fTypes, Rigid3dTypes >; -template class SOFA_MISC_MAPPING_API BarycentricMapperEdgeSetTopology< Vec3dTypes, Rigid3fTypes >; -template class SOFA_MISC_MAPPING_API BarycentricMapperEdgeSetTopology< Vec3fTypes, Rigid3dTypes >; template class SOFA_MISC_MAPPING_API BarycentricMapperTriangleSetTopology< Vec3dTypes, Rigid3fTypes >; template class SOFA_MISC_MAPPING_API BarycentricMapperTriangleSetTopology< Vec3fTypes, Rigid3dTypes >; template class SOFA_MISC_MAPPING_API BarycentricMapperQuadSetTopology< Vec3dTypes, Rigid3fTypes >; template class SOFA_MISC_MAPPING_API BarycentricMapperQuadSetTopology< Vec3fTypes, Rigid3dTypes >; template class SOFA_MISC_MAPPING_API BarycentricMapperTetrahedronSetTopologyRigid< Vec3dTypes, Rigid3fTypes >; -template class SOFA_MISC_MAPPING_API BarycentricMapperTetrahedronSetTopology< Vec3dTypes, Rigid3fTypes >; +//template class SOFA_MISC_MAPPING_API BarycentricMapperTetrahedronSetTopology< Vec3dTypes, Rigid3fTypes >; template class SOFA_MISC_MAPPING_API BarycentricMapperTetrahedronSetTopologyRigid< Vec3fTypes, Rigid3dTypes >; -template class SOFA_MISC_MAPPING_API BarycentricMapperTetrahedronSetTopology< Vec3fTypes, Rigid3dTypes >; +//template class SOFA_MISC_MAPPING_API BarycentricMapperTetrahedronSetTopology< Vec3fTypes, Rigid3dTypes >; template class SOFA_MISC_MAPPING_API BarycentricMapperHexahedronSetTopology< Vec3dTypes, Rigid3fTypes >; template class SOFA_MISC_MAPPING_API BarycentricMapperHexahedronSetTopology< Vec3fTypes, Rigid3dTypes >; #endif diff --git a/modules/SofaMiscMapping/BarycentricMappingRigid.h b/modules/SofaMiscMapping/BarycentricMappingRigid.h index 47c85572e95..d510e774b4f 100644 --- a/modules/SofaMiscMapping/BarycentricMappingRigid.h +++ b/modules/SofaMiscMapping/BarycentricMappingRigid.h @@ -94,7 +94,7 @@ class BarycentricMapperTetrahedronSetTopologyRigid : public TopologyBarycentricM virtual ~BarycentricMapperTetrahedronSetTopologyRigid() {} public: - void clear(int reserve=0) override; + void clearMapAndReserve(int reserve=0) override; int addPointInTetra(const int index, const SReal* baryCoords) override; int addPointOrientationInTetra( const int tetraIndex, const sofa::defaulttype::Matrix3 baryCoorsOrient ); @@ -114,20 +114,20 @@ class BarycentricMapperTetrahedronSetTopologyRigid : public TopologyBarycentricM //virtual int addContactPointFromInputMapping(const typename In::VecDeriv& in, const sofa::defaulttype::Vector3& /*pos*/, std::vector< std::pair > & /*baryCoords*/); }; -template -class BarycentricMapperTetrahedronSetTopology< sofa::defaulttype::StdVectorTypes,sofa::defaulttype::Vec<3,TInReal>,TInReal>, sofa::defaulttype::StdRigidTypes<3,TOutReal> > : public BarycentricMapperTetrahedronSetTopologyRigid< sofa::defaulttype::StdVectorTypes,sofa::defaulttype::Vec<3,TInReal>,TInReal>, sofa::defaulttype::StdRigidTypes<3,TOutReal> > -{ -public: - typedef sofa::defaulttype::StdVectorTypes,sofa::defaulttype::Vec<3,TInReal>,TInReal> In; - typedef sofa::defaulttype::StdRigidTypes<3,TOutReal> Out; - SOFA_CLASS(SOFA_TEMPLATE2(BarycentricMapperTetrahedronSetTopology,In,Out),SOFA_TEMPLATE2(BarycentricMapperTetrahedronSetTopologyRigid,In,Out)); - typedef BarycentricMapperTetrahedronSetTopologyRigid Inherit; +//template +//class BarycentricMapperTetrahedronSetTopology< sofa::defaulttype::StdVectorTypes,sofa::defaulttype::Vec<3,TInReal>,TInReal>, sofa::defaulttype::StdRigidTypes<3,TOutReal> > : public BarycentricMapperTetrahedronSetTopologyRigid< sofa::defaulttype::StdVectorTypes,sofa::defaulttype::Vec<3,TInReal>,TInReal>, sofa::defaulttype::StdRigidTypes<3,TOutReal> > +//{ +//public: +// typedef sofa::defaulttype::StdVectorTypes,sofa::defaulttype::Vec<3,TInReal>,TInReal> In; +// typedef sofa::defaulttype::StdRigidTypes<3,TOutReal> Out; +// SOFA_CLASS(SOFA_TEMPLATE2(BarycentricMapperTetrahedronSetTopology,In,Out),SOFA_TEMPLATE2(BarycentricMapperTetrahedronSetTopologyRigid,In,Out)); +// typedef BarycentricMapperTetrahedronSetTopologyRigid Inherit; - BarycentricMapperTetrahedronSetTopology(topology::TetrahedronSetTopologyContainer* fromTopology, topology::PointSetTopologyContainer* _toTopology) - : Inherit(fromTopology, _toTopology) - {} +// BarycentricMapperTetrahedronSetTopology(topology::TetrahedronSetTopologyContainer* fromTopology, topology::PointSetTopologyContainer* _toTopology) +// : Inherit(fromTopology, _toTopology) +// {} -}; +//}; @@ -143,7 +143,7 @@ extern template class SOFA_MISC_MAPPING_API BarycentricMapperEdgeSetTopology< de extern template class SOFA_MISC_MAPPING_API BarycentricMapperTriangleSetTopology< defaulttype::Vec3dTypes, defaulttype::Rigid3dTypes >; extern template class SOFA_MISC_MAPPING_API BarycentricMapperQuadSetTopology< defaulttype::Vec3dTypes, defaulttype::Rigid3dTypes >; extern template class SOFA_MISC_MAPPING_API BarycentricMapperTetrahedronSetTopologyRigid< defaulttype::Vec3dTypes, defaulttype::Rigid3dTypes >; -extern template class SOFA_MISC_MAPPING_API BarycentricMapperTetrahedronSetTopology< defaulttype::Vec3dTypes, defaulttype::Rigid3dTypes >; +//extern template class SOFA_MISC_MAPPING_API BarycentricMapperTetrahedronSetTopology< defaulttype::Vec3dTypes, defaulttype::Rigid3dTypes >; extern template class SOFA_MISC_MAPPING_API BarycentricMapperHexahedronSetTopology< defaulttype::Vec3dTypes, defaulttype::Rigid3dTypes >; #endif #ifndef SOFA_DOUBLE @@ -157,7 +157,7 @@ extern template class SOFA_MISC_MAPPING_API BarycentricMapperEdgeSetTopology< de extern template class SOFA_MISC_MAPPING_API BarycentricMapperTriangleSetTopology< defaulttype::Vec3fTypes, defaulttype::Rigid3fTypes >; extern template class SOFA_MISC_MAPPING_API BarycentricMapperQuadSetTopology< defaulttype::Vec3fTypes, defaulttype::Rigid3fTypes >; extern template class SOFA_MISC_MAPPING_API BarycentricMapperTetrahedronSetTopologyRigid< defaulttype::Vec3fTypes, defaulttype::Rigid3fTypes >; -extern template class SOFA_MISC_MAPPING_API BarycentricMapperTetrahedronSetTopology< defaulttype::Vec3fTypes, defaulttype::Rigid3fTypes >; +//extern template class SOFA_MISC_MAPPING_API BarycentricMapperTetrahedronSetTopology< defaulttype::Vec3fTypes, defaulttype::Rigid3fTypes >; extern template class SOFA_MISC_MAPPING_API BarycentricMapperHexahedronSetTopology< defaulttype::Vec3fTypes, defaulttype::Rigid3fTypes >; #endif #ifndef SOFA_FLOAT @@ -181,9 +181,9 @@ extern template class SOFA_MISC_MAPPING_API BarycentricMapperTriangleSetTopology extern template class SOFA_MISC_MAPPING_API BarycentricMapperQuadSetTopology< defaulttype::Vec3dTypes, defaulttype::Rigid3fTypes >; extern template class SOFA_MISC_MAPPING_API BarycentricMapperQuadSetTopology< defaulttype::Vec3fTypes, defaulttype::Rigid3dTypes >; extern template class SOFA_MISC_MAPPING_API BarycentricMapperTetrahedronSetTopologyRigid< defaulttype::Vec3dTypes, defaulttype::Rigid3fTypes >; -extern template class SOFA_MISC_MAPPING_API BarycentricMapperTetrahedronSetTopology< defaulttype::Vec3dTypes, defaulttype::Rigid3fTypes >; +//extern template class SOFA_MISC_MAPPING_API BarycentricMapperTetrahedronSetTopology< defaulttype::Vec3dTypes, defaulttype::Rigid3fTypes >; extern template class SOFA_MISC_MAPPING_API BarycentricMapperTetrahedronSetTopologyRigid< defaulttype::Vec3fTypes, defaulttype::Rigid3dTypes >; -extern template class SOFA_MISC_MAPPING_API BarycentricMapperTetrahedronSetTopology< defaulttype::Vec3fTypes, defaulttype::Rigid3dTypes >; +//extern template class SOFA_MISC_MAPPING_API BarycentricMapperTetrahedronSetTopology< defaulttype::Vec3fTypes, defaulttype::Rigid3dTypes >; extern template class SOFA_MISC_MAPPING_API BarycentricMapperHexahedronSetTopology< defaulttype::Vec3dTypes, defaulttype::Rigid3fTypes >; extern template class SOFA_MISC_MAPPING_API BarycentricMapperHexahedronSetTopology< defaulttype::Vec3fTypes, defaulttype::Rigid3dTypes >; #endif diff --git a/modules/SofaMiscMapping/BarycentricMappingRigid.inl b/modules/SofaMiscMapping/BarycentricMappingRigid.inl index a9aad68d899..8778e9509cd 100644 --- a/modules/SofaMiscMapping/BarycentricMappingRigid.inl +++ b/modules/SofaMiscMapping/BarycentricMappingRigid.inl @@ -38,7 +38,7 @@ namespace mapping template -void BarycentricMapperTetrahedronSetTopologyRigid::clear ( int reserve ) +void BarycentricMapperTetrahedronSetTopologyRigid::clearMapAndReserve ( int reserve ) { helper::vector& vectorData = *(map.beginEdit()); @@ -102,12 +102,12 @@ void BarycentricMapperTetrahedronSetTopologyRigid::init(const typename O _fromContainer->getContext()->get ( _fromGeomAlgo ); int outside = 0; - const sofa::helper::vector& tetrahedra = this->fromTopology->getTetrahedra(); + const sofa::helper::vector& tetrahedra = this->m_fromTopology->getTetrahedra(); sofa::helper::vector bases; sofa::helper::vector centers; - clear ( out.size() ); + clearMapAndReserve ( out.size() ); bases.resize ( tetrahedra.size() ); centers.resize ( tetrahedra.size() ); for ( unsigned int t = 0; t < tetrahedra.size(); t++ ) @@ -174,7 +174,7 @@ void BarycentricMapperTetrahedronSetTopologyRigid::apply( typename Out:: { actualTetraPosition=in; //get number of point being mapped - const sofa::helper::vector& tetrahedra = this->fromTopology->getTetrahedra(); + const sofa::helper::vector& tetrahedra = this->m_fromTopology->getTetrahedra(); const sofa::helper::vector& map = this->map.getValue(); const sofa::helper::vector& mapOrient = this->mapOrient.getValue(); @@ -237,7 +237,7 @@ void BarycentricMapperTetrahedronSetTopologyRigid::applyJ( typename Out: { out.resize( map.getValue().size() ); - const sofa::helper::vector& tetrahedra = this->fromTopology->getTetrahedra(); + const sofa::helper::vector& tetrahedra = this->m_fromTopology->getTetrahedra(); const sofa::helper::vector& map = this->map.getValue(); // TODO: use mapOrient //const sofa::helper::vector& mapOrient = this->mapOrient.getValue(); @@ -271,7 +271,7 @@ void BarycentricMapperTetrahedronSetTopologyRigid::applyJ( typename Out: template void BarycentricMapperTetrahedronSetTopologyRigid::applyJT( typename In::VecDeriv& out, const typename Out::VecDeriv& in ) { - const sofa::helper::vector& tetrahedra = this->fromTopology->getTetrahedra(); + const sofa::helper::vector& tetrahedra = this->m_fromTopology->getTetrahedra(); const sofa::helper::vector& map = this->map.getValue(); typename core::behavior::MechanicalState* mechanicalObject; this->getContext()->get(mechanicalObject); @@ -342,7 +342,7 @@ const sofa::defaulttype::BaseMatrix* BarycentricMapperTetrahedronSetTopologyRigi else matrixJ->clear(); - const sofa::helper::vector& tetrahedra = this->fromTopology->getTetrahedra(); + const sofa::helper::vector& tetrahedra = this->m_fromTopology->getTetrahedra(); const sofa::helper::vector& map = this->map.getValue(); // TODO(dmarchal 2017-05-03) who do it & when it will be done. Otherwise I will delete that one day. @@ -393,7 +393,7 @@ template void BarycentricMapperTetrahedronSetTopologyRigid::applyJT ( typename In::MatrixDeriv& out, const typename Out::MatrixDeriv& in ) { typename Out::MatrixDeriv::RowConstIterator rowItEnd = in.end(); - const sofa::helper::vector& tetrahedra = this->fromTopology->getTetrahedra(); + const sofa::helper::vector& tetrahedra = this->m_fromTopology->getTetrahedra(); const sofa::helper::vector& map = this->map.getValue(); // TODO(dmarchal 2017-05-03) who do it & when it will be done. Otherwise I will delete that one day. // TODO: use mapOrient @@ -431,7 +431,7 @@ void BarycentricMapperTetrahedronSetTopologyRigid::applyJT ( typename In template void BarycentricMapperTetrahedronSetTopologyRigid::draw (const core::visual::VisualParams* vparams,const typename Out::VecCoord& out, const typename In::VecCoord& in ) { - const sofa::helper::vector& tetrahedra = this->fromTopology->getTetrahedra(); + const sofa::helper::vector& tetrahedra = this->m_fromTopology->getTetrahedra(); const sofa::helper::vector& map = this->map.getValue(); // TODO(dmarchal 2017-05-03) who do it & when it will be done. Otherwise I will delete that one day. // TODO: use mapOrient From 6130d616440d2c1e0fe69af197150ab5cc723301 Mon Sep 17 00:00:00 2001 From: COEVOET Eulalie Date: Thu, 11 Oct 2018 17:45:18 +0200 Subject: [PATCH 02/15] [SofaBaseMechanics] cleaning and refactoring of BarycentricMapping (TopologyContainer part) Major refactoring: 1-added template on element type 2-removed apply, applyJ, applyJT, getJ, draw and init functions from child to BarycentricMapperTopologyContainer --- .../SofaBaseMechanics/BarycentricMapping.cpp | 60 +- .../SofaBaseMechanics/BarycentricMapping.h | 430 +++++--- .../SofaBaseMechanics/BarycentricMapping.inl | 983 +++--------------- .../BarycentricMappingRigid.cpp | 8 +- .../SofaMiscMapping/BarycentricMappingRigid.h | 32 +- 5 files changed, 468 insertions(+), 1045 deletions(-) diff --git a/SofaKernel/modules/SofaBaseMechanics/BarycentricMapping.cpp b/SofaKernel/modules/SofaBaseMechanics/BarycentricMapping.cpp index f013d3a2f89..7d1527fcdf6 100644 --- a/SofaKernel/modules/SofaBaseMechanics/BarycentricMapping.cpp +++ b/SofaKernel/modules/SofaBaseMechanics/BarycentricMapping.cpp @@ -70,20 +70,24 @@ template class SOFA_BASE_MECHANICS_API BarycentricMapperSparseGridTopology< Vec3 template class SOFA_BASE_MECHANICS_API BarycentricMapperSparseGridTopology< Vec3dTypes, ExtVec3fTypes >; template class SOFA_BASE_MECHANICS_API BarycentricMapperMeshTopology< Vec3dTypes, Vec3dTypes >; template class SOFA_BASE_MECHANICS_API BarycentricMapperMeshTopology< Vec3dTypes, ExtVec3fTypes >; -template class SOFA_BASE_MECHANICS_API BarycentricMapperTopologyContainer< Vec3dTypes, Vec3dTypes , typename BarycentricMapper::MappingData1D>; -template class SOFA_BASE_MECHANICS_API BarycentricMapperTopologyContainer< Vec3dTypes, ExtVec3fTypes , typename BarycentricMapper::MappingData1D>; -template class SOFA_BASE_MECHANICS_API BarycentricMapperTopologyContainer< Vec3dTypes, Vec3dTypes , typename BarycentricMapper::MappingData2D>; -template class SOFA_BASE_MECHANICS_API BarycentricMapperTopologyContainer< Vec3dTypes, ExtVec3fTypes , typename BarycentricMapper::MappingData2D>; -template class SOFA_BASE_MECHANICS_API BarycentricMapperTopologyContainer< Vec3dTypes, Vec3dTypes , typename BarycentricMapper::MappingData3D>; -template class SOFA_BASE_MECHANICS_API BarycentricMapperTopologyContainer< Vec3dTypes, ExtVec3fTypes , typename BarycentricMapper::MappingData3D>; +template class SOFA_BASE_MECHANICS_API BarycentricMapperTopologyContainer< Vec3dTypes, Vec3dTypes , typename BarycentricMapper::MappingData1D, Edge>; +template class SOFA_BASE_MECHANICS_API BarycentricMapperTopologyContainer< Vec3dTypes, ExtVec3fTypes , typename BarycentricMapper::MappingData1D, Edge>; +template class SOFA_BASE_MECHANICS_API BarycentricMapperTopologyContainer< Vec3dTypes, Vec3dTypes , typename BarycentricMapper::MappingData2D, Triangle>; +template class SOFA_BASE_MECHANICS_API BarycentricMapperTopologyContainer< Vec3dTypes, ExtVec3fTypes , typename BarycentricMapper::MappingData2D, Triangle>; +template class SOFA_BASE_MECHANICS_API BarycentricMapperTopologyContainer< Vec3dTypes, Vec3dTypes , typename BarycentricMapper::MappingData2D, Quad>; +template class SOFA_BASE_MECHANICS_API BarycentricMapperTopologyContainer< Vec3dTypes, ExtVec3fTypes , typename BarycentricMapper::MappingData2D, Quad>; +template class SOFA_BASE_MECHANICS_API BarycentricMapperTopologyContainer< Vec3dTypes, Vec3dTypes , typename BarycentricMapper::MappingData3D, Tetrahedron>; +template class SOFA_BASE_MECHANICS_API BarycentricMapperTopologyContainer< Vec3dTypes, ExtVec3fTypes , typename BarycentricMapper::MappingData3D, Tetrahedron>; +template class SOFA_BASE_MECHANICS_API BarycentricMapperTopologyContainer< Vec3dTypes, Vec3dTypes , typename BarycentricMapper::MappingData3D, Hexahedron>; +template class SOFA_BASE_MECHANICS_API BarycentricMapperTopologyContainer< Vec3dTypes, ExtVec3fTypes , typename BarycentricMapper::MappingData3D, Hexahedron>; template class SOFA_BASE_MECHANICS_API BarycentricMapperEdgeSetTopology< Vec3dTypes, Vec3dTypes>; template class SOFA_BASE_MECHANICS_API BarycentricMapperEdgeSetTopology< Vec3dTypes, ExtVec3fTypes>; template class SOFA_BASE_MECHANICS_API BarycentricMapperTriangleSetTopology< Vec3dTypes, Vec3dTypes >; template class SOFA_BASE_MECHANICS_API BarycentricMapperTriangleSetTopology< Vec3dTypes, ExtVec3fTypes >; template class SOFA_BASE_MECHANICS_API BarycentricMapperQuadSetTopology< Vec3dTypes, Vec3dTypes >; template class SOFA_BASE_MECHANICS_API BarycentricMapperQuadSetTopology< Vec3dTypes, ExtVec3fTypes >; -//template class SOFA_BASE_MECHANICS_API BarycentricMapperTetrahedronSetTopology< Vec3dTypes, Vec3dTypes >; -//template class SOFA_BASE_MECHANICS_API BarycentricMapperTetrahedronSetTopology< Vec3dTypes, ExtVec3fTypes >; +template class SOFA_BASE_MECHANICS_API BarycentricMapperTetrahedronSetTopology< Vec3dTypes, Vec3dTypes >; +template class SOFA_BASE_MECHANICS_API BarycentricMapperTetrahedronSetTopology< Vec3dTypes, ExtVec3fTypes >; template class SOFA_BASE_MECHANICS_API BarycentricMapperHexahedronSetTopology< Vec3dTypes, Vec3dTypes >; template class SOFA_BASE_MECHANICS_API BarycentricMapperHexahedronSetTopology< Vec3dTypes, ExtVec3fTypes >; #endif @@ -100,20 +104,24 @@ template class SOFA_BASE_MECHANICS_API BarycentricMapperSparseGridTopology< Vec3 template class SOFA_BASE_MECHANICS_API BarycentricMapperSparseGridTopology< Vec3fTypes, ExtVec3fTypes >; template class SOFA_BASE_MECHANICS_API BarycentricMapperMeshTopology< Vec3fTypes, Vec3fTypes >; template class SOFA_BASE_MECHANICS_API BarycentricMapperMeshTopology< Vec3fTypes, ExtVec3fTypes >; -template class SOFA_BASE_MECHANICS_API BarycentricMapperTopologyContainer< Vec3fTypes, Vec3fTypes , typename BarycentricMapper::MappingData1D>; -template class SOFA_BASE_MECHANICS_API BarycentricMapperTopologyContainer< Vec3fTypes, ExtVec3fTypes , typename BarycentricMapper::MappingData1D>; -template class SOFA_BASE_MECHANICS_API BarycentricMapperTopologyContainer< Vec3fTypes, Vec3fTypes , typename BarycentricMapper::MappingData2D>; -template class SOFA_BASE_MECHANICS_API BarycentricMapperTopologyContainer< Vec3fTypes, ExtVec3fTypes , typename BarycentricMapper::MappingData2D>; -template class SOFA_BASE_MECHANICS_API BarycentricMapperTopologyContainer< Vec3fTypes, Vec3fTypes , typename BarycentricMapper::MappingData3D>; -template class SOFA_BASE_MECHANICS_API BarycentricMapperTopologyContainer< Vec3fTypes, ExtVec3fTypes , typename BarycentricMapper::MappingData3D>; +template class SOFA_BASE_MECHANICS_API BarycentricMapperTopologyContainer< Vec3fTypes, Vec3fTypes , typename BarycentricMapper::MappingData1D, Edge>; +template class SOFA_BASE_MECHANICS_API BarycentricMapperTopologyContainer< Vec3fTypes, ExtVec3fTypes , typename BarycentricMapper::MappingData1D, Edge>; +template class SOFA_BASE_MECHANICS_API BarycentricMapperTopologyContainer< Vec3fTypes, Vec3fTypes , typename BarycentricMapper::MappingData2D, Triangle>; +template class SOFA_BASE_MECHANICS_API BarycentricMapperTopologyContainer< Vec3fTypes, ExtVec3fTypes , typename BarycentricMapper::MappingData2D, Triangle>; +template class SOFA_BASE_MECHANICS_API BarycentricMapperTopologyContainer< Vec3fTypes, Vec3fTypes , typename BarycentricMapper::MappingData2D, Quad>; +template class SOFA_BASE_MECHANICS_API BarycentricMapperTopologyContainer< Vec3fTypes, ExtVec3fTypes , typename BarycentricMapper::MappingData2D, Quad>; +template class SOFA_BASE_MECHANICS_API BarycentricMapperTopologyContainer< Vec3fTypes, Vec3fTypes , typename BarycentricMapper::MappingData3D, Tetrahedron>; +template class SOFA_BASE_MECHANICS_API BarycentricMapperTopologyContainer< Vec3fTypes, ExtVec3fTypes , typename BarycentricMapper::MappingData3D, Tetrahedron>; +template class SOFA_BASE_MECHANICS_API BarycentricMapperTopologyContainer< Vec3fTypes, Vec3fTypes , typename BarycentricMapper::MappingData3D, Hexahedron>; +template class SOFA_BASE_MECHANICS_API BarycentricMapperTopologyContainer< Vec3fTypes, ExtVec3fTypes , typename BarycentricMapper::MappingData3D, Hexahedron>; template class SOFA_BASE_MECHANICS_API BarycentricMapperEdgeSetTopology< Vec3fTypes, Vec3fTypes>; template class SOFA_BASE_MECHANICS_API BarycentricMapperEdgeSetTopology< Vec3fTypes, ExtVec3fTypes>; template class SOFA_BASE_MECHANICS_API BarycentricMapperTriangleSetTopology< Vec3fTypes, Vec3fTypes >; template class SOFA_BASE_MECHANICS_API BarycentricMapperTriangleSetTopology< Vec3fTypes, ExtVec3fTypes >; template class SOFA_BASE_MECHANICS_API BarycentricMapperQuadSetTopology< Vec3fTypes, Vec3fTypes >; template class SOFA_BASE_MECHANICS_API BarycentricMapperQuadSetTopology< Vec3fTypes, ExtVec3fTypes >; -//template class SOFA_BASE_MECHANICS_API BarycentricMapperTetrahedronSetTopology< Vec3fTypes, Vec3fTypes >; -//template class SOFA_BASE_MECHANICS_API BarycentricMapperTetrahedronSetTopology< Vec3fTypes, ExtVec3fTypes >; +template class SOFA_BASE_MECHANICS_API BarycentricMapperTetrahedronSetTopology< Vec3fTypes, Vec3fTypes >; +template class SOFA_BASE_MECHANICS_API BarycentricMapperTetrahedronSetTopology< Vec3fTypes, ExtVec3fTypes >; template class SOFA_BASE_MECHANICS_API BarycentricMapperHexahedronSetTopology< Vec3fTypes, Vec3fTypes >; template class SOFA_BASE_MECHANICS_API BarycentricMapperHexahedronSetTopology< Vec3fTypes, ExtVec3fTypes >; #endif @@ -131,20 +139,24 @@ template class SOFA_BASE_MECHANICS_API BarycentricMapperSparseGridTopology< Vec3 template class SOFA_BASE_MECHANICS_API BarycentricMapperSparseGridTopology< Vec3fTypes, Vec3dTypes >; template class SOFA_BASE_MECHANICS_API BarycentricMapperMeshTopology< Vec3dTypes, Vec3fTypes >; template class SOFA_BASE_MECHANICS_API BarycentricMapperMeshTopology< Vec3fTypes, Vec3dTypes >; -template class SOFA_BASE_MECHANICS_API BarycentricMapperTopologyContainer< Vec3dTypes, Vec3fTypes , typename BarycentricMapper::MappingData1D>; -template class SOFA_BASE_MECHANICS_API BarycentricMapperTopologyContainer< Vec3fTypes, Vec3dTypes , typename BarycentricMapper::MappingData1D>; -template class SOFA_BASE_MECHANICS_API BarycentricMapperTopologyContainer< Vec3dTypes, Vec3fTypes , typename BarycentricMapper::MappingData2D>; -template class SOFA_BASE_MECHANICS_API BarycentricMapperTopologyContainer< Vec3fTypes, Vec3dTypes , typename BarycentricMapper::MappingData2D>; -template class SOFA_BASE_MECHANICS_API BarycentricMapperTopologyContainer< Vec3dTypes, Vec3fTypes , typename BarycentricMapper::MappingData3D>; -template class SOFA_BASE_MECHANICS_API BarycentricMapperTopologyContainer< Vec3fTypes, Vec3dTypes , typename BarycentricMapper::MappingData3D>; +template class SOFA_BASE_MECHANICS_API BarycentricMapperTopologyContainer< Vec3dTypes, Vec3fTypes , typename BarycentricMapper::MappingData1D,Edge>; +template class SOFA_BASE_MECHANICS_API BarycentricMapperTopologyContainer< Vec3fTypes, Vec3dTypes , typename BarycentricMapper::MappingData1D,Edge>; +template class SOFA_BASE_MECHANICS_API BarycentricMapperTopologyContainer< Vec3dTypes, Vec3fTypes , typename BarycentricMapper::MappingData2D,Triangle>; +template class SOFA_BASE_MECHANICS_API BarycentricMapperTopologyContainer< Vec3fTypes, Vec3dTypes , typename BarycentricMapper::MappingData2D,Triangle>; +template class SOFA_BASE_MECHANICS_API BarycentricMapperTopologyContainer< Vec3dTypes, Vec3fTypes , typename BarycentricMapper::MappingData2D,Quad>; +template class SOFA_BASE_MECHANICS_API BarycentricMapperTopologyContainer< Vec3fTypes, Vec3dTypes , typename BarycentricMapper::MappingData2D,Quad>; +template class SOFA_BASE_MECHANICS_API BarycentricMapperTopologyContainer< Vec3dTypes, Vec3fTypes , typename BarycentricMapper::MappingData3D,Tetrahedron>; +template class SOFA_BASE_MECHANICS_API BarycentricMapperTopologyContainer< Vec3fTypes, Vec3dTypes , typename BarycentricMapper::MappingData3D,Tetrahedron>; +template class SOFA_BASE_MECHANICS_API BarycentricMapperTopologyContainer< Vec3dTypes, Vec3fTypes , typename BarycentricMapper::MappingData3D,Hexahedron>; +template class SOFA_BASE_MECHANICS_API BarycentricMapperTopologyContainer< Vec3fTypes, Vec3dTypes , typename BarycentricMapper::MappingData3D,Hexahedron>; template class SOFA_BASE_MECHANICS_API BarycentricMapperEdgeSetTopology< Vec3dTypes, Vec3fTypes>; template class SOFA_BASE_MECHANICS_API BarycentricMapperEdgeSetTopology< Vec3fTypes, Vec3dTypes>; template class SOFA_BASE_MECHANICS_API BarycentricMapperTriangleSetTopology< Vec3dTypes, Vec3fTypes >; template class SOFA_BASE_MECHANICS_API BarycentricMapperTriangleSetTopology< Vec3fTypes, Vec3dTypes >; template class SOFA_BASE_MECHANICS_API BarycentricMapperQuadSetTopology< Vec3dTypes, Vec3fTypes >; template class SOFA_BASE_MECHANICS_API BarycentricMapperQuadSetTopology< Vec3fTypes, Vec3dTypes >; -//template class SOFA_BASE_MECHANICS_API BarycentricMapperTetrahedronSetTopology< Vec3dTypes, Vec3fTypes >; -//template class SOFA_BASE_MECHANICS_API BarycentricMapperTetrahedronSetTopology< Vec3fTypes, Vec3dTypes >; +template class SOFA_BASE_MECHANICS_API BarycentricMapperTetrahedronSetTopology< Vec3dTypes, Vec3fTypes >; +template class SOFA_BASE_MECHANICS_API BarycentricMapperTetrahedronSetTopology< Vec3fTypes, Vec3dTypes >; template class SOFA_BASE_MECHANICS_API BarycentricMapperHexahedronSetTopology< Vec3dTypes, Vec3fTypes >; template class SOFA_BASE_MECHANICS_API BarycentricMapperHexahedronSetTopology< Vec3fTypes, Vec3dTypes >; #endif diff --git a/SofaKernel/modules/SofaBaseMechanics/BarycentricMapping.h b/SofaKernel/modules/SofaBaseMechanics/BarycentricMapping.h index 68122dc6e8c..e2aa9ce178c 100644 --- a/SofaKernel/modules/SofaBaseMechanics/BarycentricMapping.h +++ b/SofaKernel/modules/SofaBaseMechanics/BarycentricMapping.h @@ -32,6 +32,8 @@ #include #include +#include + #include #include #include @@ -550,16 +552,36 @@ class BarycentricMapperSparseGridTopology : public TopologyBarycentricMapper + + + + +typedef typename sofa::core::topology::BaseMeshTopology::Edge Edge; +typedef typename sofa::core::topology::BaseMeshTopology::Triangle Triangle; +typedef typename sofa::core::topology::BaseMeshTopology::Quad Quad; +typedef typename sofa::core::topology::BaseMeshTopology::Tetrahedron Tetrahedron; +typedef typename sofa::core::topology::BaseMeshTopology::Hexahedron Hexahedron; +using sofa::defaulttype::Mat3x3d; +using sofa::defaulttype::Vector3; + + +/// Template class for topology container mappers +template class BarycentricMapperTopologyContainer : public TopologyBarycentricMapper { public: - SOFA_CLASS(SOFA_TEMPLATE3(BarycentricMapperTopologyContainer,In,Out,MappingDataType),SOFA_TEMPLATE2(TopologyBarycentricMapper,In,Out)); + SOFA_CLASS(SOFA_TEMPLATE4(BarycentricMapperTopologyContainer,In,Out,MappingDataType,Element),SOFA_TEMPLATE2(TopologyBarycentricMapper,In,Out)); typedef TopologyBarycentricMapper Inherit; + typedef typename Inherit::Real Real; + typedef typename Inherit::OutReal OutReal; + typedef typename Inherit::OutDeriv OutDeriv; + typedef typename Inherit::InDeriv InDeriv; + + typedef typename Inherit::MBloc MBloc; typedef typename Inherit::MatrixType MatrixType; + + typedef typename Inherit::ForceMask ForceMask; typedef typename MatrixType::Index MatrixTypeIndex; - typedef typename Inherit::Real Real; enum { NIn = Inherit::NIn }; enum { NOut = Inherit::NOut }; @@ -577,36 +599,29 @@ class BarycentricMapperTopologyContainer : public TopologyBarycentricMapper& vectorData = *(d_map.beginEdit()); - vectorData.clear(); - if ( size>0 ) vectorData.reserve ( size ); - d_map.endEdit(); - } +protected: - virtual void resize( core::State* toModel ) override - { - toModel->resize(d_map.getValue().size()); - } + virtual helper::vector getElements()=0; + virtual helper::vector getBaryCoef(const Real* f)=0; + virtual void computeBase(Mat3x3d& base, const typename In::VecCoord& in, const Element& element)=0; + virtual void computeCenter(Vector3& center, const typename In::VecCoord& in, const Element& element)=0; + virtual void addPointInElement(const int elementIndex, const SReal* baryCoords)=0; + virtual void computeDistance(double& d, const Vector3& v)=0; - virtual const sofa::defaulttype::BaseMatrix* getJ(int outSize, int inSize) override - { - if (m_matrixJ && !m_updateJ) - return m_matrixJ; +public: - if (!m_matrixJ) m_matrixJ = new MatrixType; - if (m_matrixJ->rowBSize() != (MatrixTypeIndex)outSize || m_matrixJ->colBSize() != (MatrixTypeIndex)inSize) - m_matrixJ->resize(outSize*NOut, inSize*NIn); - else - m_matrixJ->clear(); + virtual void clearMapAndReserve(int size=0) override; + virtual void resize( core::State* toModel ) override; - return m_matrixJ; - } + void apply( typename Out::VecCoord& out, const typename In::VecCoord& in ) override; + void applyJ( typename Out::VecDeriv& out, const typename In::VecDeriv& in ) override; + void applyJT( typename In::VecDeriv& out, const typename Out::VecDeriv& in ) override; + void applyJT( typename In::MatrixDeriv& out, const typename Out::MatrixDeriv& in ) override; + virtual const sofa::defaulttype::BaseMatrix* getJ(int outSize, int inSize) override; + virtual void init(const typename Out::VecCoord& out, const typename In::VecCoord& in) override; + void draw(const core::visual::VisualParams*,const typename Out::VecCoord& out, const typename In::VecCoord& in) override; - inline friend std::istream& operator >> ( std::istream& in, BarycentricMapperTopologyContainer &b ) + inline friend std::istream& operator >> ( std::istream& in, BarycentricMapperTopologyContainer &b ) { unsigned int size_vec; @@ -624,7 +639,7 @@ class BarycentricMapperTopologyContainer : public TopologyBarycentricMapper & b ) + inline friend std::ostream& operator << ( std::ostream& out, const BarycentricMapperTopologyContainer & b ) { out << b.d_map.getValue().size(); @@ -642,28 +657,20 @@ class BarycentricMapperTopologyContainer : public TopologyBarycentricMapper::MappingData1D> -class BarycentricMapperEdgeSetTopology : public BarycentricMapperTopologyContainer +template::MappingData1D, class Element = Edge> +class BarycentricMapperEdgeSetTopology : public BarycentricMapperTopologyContainer { public: - SOFA_CLASS(SOFA_TEMPLATE3(BarycentricMapperEdgeSetTopology,In,Out,MappingDataType),SOFA_TEMPLATE3(BarycentricMapperTopologyContainer,In,Out,MappingDataType)); + SOFA_CLASS(SOFA_TEMPLATE4(BarycentricMapperEdgeSetTopology,In,Out,MappingDataType,Element),SOFA_TEMPLATE4(BarycentricMapperTopologyContainer,In,Out,MappingDataType,Element)); typedef MappingDataType MappingData; - typedef BarycentricMapperTopologyContainer Inherit; + typedef BarycentricMapperTopologyContainer Inherit; typedef typename Inherit::Real Real; - typedef typename Inherit::OutReal OutReal; - typedef typename Inherit::OutDeriv OutDeriv; - typedef typename Inherit::InDeriv InDeriv; - - typedef typename Inherit::MBloc MBloc; - typedef typename Inherit::MatrixType MatrixType; - - typedef typename Inherit::ForceMask ForceMask; - protected: topology::EdgeSetTopologyContainer* m_fromContainer; - topology::EdgeSetGeometryAlgorithms* m_fromGeomAlgo; + topology::EdgeSetGeometryAlgorithms* m_fromGeomAlgo; using Inherit::d_map; using Inherit::m_fromTopology; @@ -678,7 +685,12 @@ class BarycentricMapperEdgeSetTopology : public BarycentricMapperTopologyContain virtual ~BarycentricMapperEdgeSetTopology() {} - helper::vector getBaryCoef(const Real* f) + virtual helper::vector getElements() override + { + return this->m_fromTopology->getEdges(); + } + + virtual helper::vector getBaryCoef(const Real* f) override { return getBaryCoef(f[0]); } @@ -689,42 +701,54 @@ class BarycentricMapperEdgeSetTopology : public BarycentricMapperTopologyContain return edgeCoef; } -public: + virtual void computeBase(Mat3x3d& base, const typename In::VecCoord& in, const Element& element) override + { + //Not implemented for Edge + SOFA_UNUSED(base); + SOFA_UNUSED(in); + SOFA_UNUSED(element); + } - int addPointInLine(const int edgeIndex, const SReal* baryCoords) override; - int createPointInLine(const typename Out::Coord& p, int edgeIndex, const typename In::VecCoord* points) override; + virtual void computeCenter(Vector3& center, const typename In::VecCoord& in, const Element& element) override + { + center = (in[element[0]]+in[element[1]])*0.5; + } - void init(const typename Out::VecCoord& out, const typename In::VecCoord& in) override; + virtual void computeDistance(double& d, const Vector3& v) override + { + //Not implemented for Edge + SOFA_UNUSED(d); + SOFA_UNUSED(v); + } - void apply( typename Out::VecCoord& out, const typename In::VecCoord& in ) override; - void applyJ( typename Out::VecDeriv& out, const typename In::VecDeriv& in ) override; - void applyJT( typename In::VecDeriv& out, const typename Out::VecDeriv& in ) override; - void applyJT( typename In::MatrixDeriv& out, const typename Out::MatrixDeriv& in ) override; + virtual void addPointInElement(const int elementIndex, const SReal* baryCoords) override + { + addPointInLine(elementIndex,baryCoords); + } - virtual const sofa::defaulttype::BaseMatrix* getJ(int outSize, int inSize) override; +public: - void draw(const core::visual::VisualParams*,const typename Out::VecCoord& out, const typename In::VecCoord& in) override; + virtual void init(const typename Out::VecCoord& out, const typename In::VecCoord& in) override + { + SOFA_UNUSED(out); + SOFA_UNUSED(in); + msg_warning() << "Mapping not implemented for edge elements."; + } + virtual int addPointInLine(const int edgeIndex, const SReal* baryCoords) override; + virtual int createPointInLine(const typename Out::Coord& p, int edgeIndex, const typename In::VecCoord* points) override; }; /// Class allowing barycentric mapping computation on a TriangleSetTopology -template::MappingData2D> -class BarycentricMapperTriangleSetTopology : public BarycentricMapperTopologyContainer +template::MappingData2D, class Element = Triangle> +class BarycentricMapperTriangleSetTopology : public BarycentricMapperTopologyContainer { public: - SOFA_CLASS(SOFA_TEMPLATE3(BarycentricMapperTriangleSetTopology,In,Out,MappingDataType),SOFA_TEMPLATE3(BarycentricMapperTopologyContainer,In,Out,MappingDataType)); + SOFA_CLASS(SOFA_TEMPLATE4(BarycentricMapperTriangleSetTopology,In,Out,MappingDataType,Element),SOFA_TEMPLATE4(BarycentricMapperTopologyContainer,In,Out,MappingDataType,Element)); typedef MappingDataType MappingData; - typedef BarycentricMapperTopologyContainer Inherit; + typedef BarycentricMapperTopologyContainer Inherit; typedef typename Inherit::Real Real; - typedef typename Inherit::OutReal OutReal; - typedef typename Inherit::OutDeriv OutDeriv; - typedef typename Inherit::InDeriv InDeriv; - - typedef typename Inherit::MBloc MBloc; - typedef typename Inherit::MatrixType MatrixType; - - typedef typename Inherit::ForceMask ForceMask; protected: topology::TriangleSetTopologyContainer* m_fromContainer; @@ -741,9 +765,15 @@ class BarycentricMapperTriangleSetTopology : public BarycentricMapperTopologyCon m_fromGeomAlgo(NULL) {} - virtual ~BarycentricMapperTriangleSetTopology(){} + virtual ~BarycentricMapperTriangleSetTopology() {} + + + virtual helper::vector getElements() override + { + return this->m_fromTopology->getTriangles(); + } - helper::vector getBaryCoef(const Real* f) + virtual helper::vector getBaryCoef(const Real* f) override { return getBaryCoef(f[0],f[1]); } @@ -754,21 +784,35 @@ class BarycentricMapperTriangleSetTopology : public BarycentricMapperTopologyCon return triangleCoef; } -public: + virtual void computeBase(Mat3x3d& base, const typename In::VecCoord& in, const Element& element) override + { + Mat3x3d mt; + base[0] = in[element[1]]-in[element[0]]; + base[1] = in[element[2]]-in[element[0]]; + base[2] = cross(base[0],base[1]); + mt.transpose(base); + base.invert(mt); + } - virtual int addPointInTriangle(const int triangleIndex, const SReal* baryCoords) override; - int createPointInTriangle(const typename Out::Coord& p, int triangleIndex, const typename In::VecCoord* points) override; + virtual void computeCenter(Vector3& center, const typename In::VecCoord& in, const Element& element) override + { + center = (in[element[0]]+in[element[1]]+in[element[2]])/3; + } - void init(const typename Out::VecCoord& out, const typename In::VecCoord& in) override; + virtual void computeDistance(double& d, const Vector3& v) override + { + d = std::max ( std::max ( -v[0],-v[1] ),std::max ( ( v[2]<0?-v[2]:v[2] )-0.01,v[0]+v[1]-1 ) ); + } - void apply( typename Out::VecCoord& out, const typename In::VecCoord& in ) override; - void applyJ( typename Out::VecDeriv& out, const typename In::VecDeriv& in ) override; - void applyJT( typename In::VecDeriv& out, const typename Out::VecDeriv& in ) override; - void applyJT( typename In::MatrixDeriv& out, const typename Out::MatrixDeriv& in ) override; + virtual void addPointInElement(const int elementIndex, const SReal* baryCoords) override + { + addPointInTriangle(elementIndex,baryCoords); + } - virtual const sofa::defaulttype::BaseMatrix* getJ(int outSize, int inSize) override; +public: - void draw(const core::visual::VisualParams*,const typename Out::VecCoord& out, const typename In::VecCoord& in) override; + virtual int addPointInTriangle(const int triangleIndex, const SReal* baryCoords) override; + int createPointInTriangle(const typename Out::Coord& p, int triangleIndex, const typename In::VecCoord* points) override; #ifdef BARYCENTRIC_MAPPER_TOPOCHANGE_REINIT // handle topology changes in the From topology @@ -779,22 +823,14 @@ class BarycentricMapperTriangleSetTopology : public BarycentricMapperTopologyCon /// Class allowing barycentric mapping computation on a QuadSetTopology -template::MappingData2D> -class BarycentricMapperQuadSetTopology : public BarycentricMapperTopologyContainer +template::MappingData2D, class Element = Quad> +class BarycentricMapperQuadSetTopology : public BarycentricMapperTopologyContainer { public: - SOFA_CLASS(SOFA_TEMPLATE3(BarycentricMapperQuadSetTopology,In,Out,MappingDataType),SOFA_TEMPLATE3(BarycentricMapperTopologyContainer,In,Out,MappingDataType)); + SOFA_CLASS(SOFA_TEMPLATE4(BarycentricMapperQuadSetTopology,In,Out,MappingDataType,Element),SOFA_TEMPLATE4(BarycentricMapperTopologyContainer,In,Out,MappingDataType,Element)); typedef MappingDataType MappingData; - typedef BarycentricMapperTopologyContainer Inherit; + typedef BarycentricMapperTopologyContainer Inherit; typedef typename Inherit::Real Real; - typedef typename Inherit::OutReal OutReal; - typedef typename Inherit::OutDeriv OutDeriv; - typedef typename Inherit::InDeriv InDeriv; - - typedef typename Inherit::MBloc MBloc; - typedef typename Inherit::MatrixType MatrixType; - - typedef typename Inherit::ForceMask ForceMask; protected: topology::QuadSetTopologyContainer* m_fromContainer; @@ -813,7 +849,13 @@ class BarycentricMapperQuadSetTopology : public BarycentricMapperTopologyContain virtual ~BarycentricMapperQuadSetTopology() {} - helper::vector getBaryCoef(const Real* f) + + virtual helper::vector getElements() override + { + return this->m_fromTopology->getQuads(); + } + + virtual helper::vector getBaryCoef(const Real* f) override { return getBaryCoef(f[0],f[1]); } @@ -827,48 +869,53 @@ class BarycentricMapperQuadSetTopology : public BarycentricMapperTopologyContain return quadCoef; } -public: + virtual void computeBase(Mat3x3d& base, const typename In::VecCoord& in, const Element& element) override + { + Mat3x3d matrixTranspose; + base[0] = in[element[1]]-in[element[0]]; + base[1] = in[element[3]]-in[element[0]]; + base[2] = cross(base[0],base[1]); + matrixTranspose.transpose(base); + base.invert(matrixTranspose); + } - int addPointInQuad(const int index, const SReal* baryCoords) override; - int createPointInQuad(const typename Out::Coord& p, int index, const typename In::VecCoord* points) override; + virtual void computeCenter(Vector3& center, const typename In::VecCoord& in, const Element& element) override + { + center = ( in[element[0]]+in[element[1]]+in[element[2]]+in[element[3]] ) *0.25; + } - void init(const typename Out::VecCoord& out, const typename In::VecCoord& in) override; + virtual void computeDistance(double& d, const Vector3& v) override + { + d = std::max ( std::max ( -v[0],-v[1] ),std::max ( std::max ( v[1]-1,v[0]-1 ),std::max ( v[2]-0.01,-v[2]-0.01 ) ) ); + } - void apply( typename Out::VecCoord& out, const typename In::VecCoord& in ) override; - void applyJ( typename Out::VecDeriv& out, const typename In::VecDeriv& in ) override; - void applyJT( typename In::VecDeriv& out, const typename Out::VecDeriv& in ) override; - void applyJT( typename In::MatrixDeriv& out, const typename Out::MatrixDeriv& in ) override; + virtual void addPointInElement(const int elementIndex, const SReal* baryCoords) override + { + addPointInQuad(elementIndex,baryCoords); + } - virtual const sofa::defaulttype::BaseMatrix* getJ(int outSize, int inSize) override; +public: - void draw(const core::visual::VisualParams*,const typename Out::VecCoord& out, const typename In::VecCoord& in) override; + virtual int addPointInQuad(const int index, const SReal* baryCoords) override; + virtual int createPointInQuad(const typename Out::Coord& p, int index, const typename In::VecCoord* points) override; }; /// Class allowing barycentric mapping computation on a TetrahedronSetTopology -template::MappingData3D> -class BarycentricMapperTetrahedronSetTopology : BarycentricMapperTopologyContainer +template::MappingData3D, class Element = Tetrahedron> +class BarycentricMapperTetrahedronSetTopology : public BarycentricMapperTopologyContainer { public: - SOFA_CLASS(SOFA_TEMPLATE3(BarycentricMapperTetrahedronSetTopology,In,Out,MappingDataType),SOFA_TEMPLATE3(BarycentricMapperTopologyContainer,In,Out,MappingDataType)); + SOFA_CLASS(SOFA_TEMPLATE4(BarycentricMapperTetrahedronSetTopology,In,Out,MappingDataType,Element),SOFA_TEMPLATE4(BarycentricMapperTopologyContainer,In,Out,MappingDataType,Element)); typedef MappingDataType MappingData; - typedef BarycentricMapperTopologyContainer Inherit; + typedef BarycentricMapperTopologyContainer Inherit; typedef typename Inherit::Real Real; - typedef typename Inherit::OutReal OutReal; - typedef typename Inherit::OutDeriv OutDeriv; - typedef typename Inherit::InDeriv InDeriv; - typedef typename In::VecCoord VecCoord; - typedef typename Inherit::MBloc MBloc; - typedef typename Inherit::MatrixType MatrixType; - - typedef typename Inherit::ForceMask ForceMask; protected: - VecCoord m_actualTetraPosition; topology::TetrahedronSetTopologyContainer* m_fromContainer; topology::TetrahedronSetGeometryAlgorithms* m_fromGeomAlgo; @@ -883,9 +930,15 @@ class BarycentricMapperTetrahedronSetTopology : BarycentricMapperTopologyContain m_fromGeomAlgo(NULL) {} - virtual ~BarycentricMapperTetrahedronSetTopology() {} + virtual ~BarycentricMapperTetrahedronSetTopology() override {} + - helper::vector getBaryCoef(const Real* f) + virtual helper::vector getElements() override + { + return this->m_fromTopology->getTetrahedra(); + } + + virtual helper::vector getBaryCoef(const Real* f) override { return getBaryCoef(f[0],f[1],f[2]); } @@ -896,40 +949,47 @@ class BarycentricMapperTetrahedronSetTopology : BarycentricMapperTopologyContain return tetrahedronCoef; } -public: - int addPointInTetra(const int index, const SReal* baryCoords) override ; + virtual void computeBase(Mat3x3d& base, const typename In::VecCoord& in, const Element& element) override + { + Mat3x3d matrixTranspose; + base[0] = in[element[1]]-in[element[0]]; + base[1] = in[element[2]]-in[element[0]]; + base[2] = in[element[3]]-in[element[0]]; + matrixTranspose.transpose(base); + base.invert(matrixTranspose); + } - void init(const typename Out::VecCoord& out, const typename In::VecCoord& in) override; + virtual void computeCenter(Vector3& center, const typename In::VecCoord& in, const Element& element) override + { + center = ( in[element[0]]+in[element[1]]+in[element[2]]+in[element[3]] ) *0.25; + } - void apply( typename Out::VecCoord& out, const typename In::VecCoord& in ) override; - void applyJ( typename Out::VecDeriv& out, const typename In::VecDeriv& in ) override; - void applyJT( typename In::VecDeriv& out, const typename Out::VecDeriv& in ) override; - void applyJT( typename In::MatrixDeriv& out, const typename Out::MatrixDeriv& in ) override; + virtual void computeDistance(double& d, const Vector3& v) override + { + d = std::max ( std::max ( -v[0],-v[1] ), std::max ( -v[2],v[0]+v[1]+v[2]-1 ) ); + } - virtual const sofa::defaulttype::BaseMatrix* getJ(int outSize, int inSize) override; + virtual void addPointInElement(const int elementIndex, const SReal* baryCoords) override + { + addPointInTetra(elementIndex,baryCoords); + } - void draw(const core::visual::VisualParams*,const typename Out::VecCoord& out, const typename In::VecCoord& in) override; +public: + + virtual int addPointInTetra(const int index, const SReal* baryCoords) override ; }; /// Class allowing barycentric mapping computation on a HexahedronSetTopology -template::MappingData3D> -class BarycentricMapperHexahedronSetTopology : public BarycentricMapperTopologyContainer +template::MappingData3D, class Element = Hexahedron> +class BarycentricMapperHexahedronSetTopology : public BarycentricMapperTopologyContainer { public: - SOFA_CLASS(SOFA_TEMPLATE3(BarycentricMapperHexahedronSetTopology,In,Out,MappingDataType),SOFA_TEMPLATE3(BarycentricMapperTopologyContainer,In,Out,MappingDataType)); + SOFA_CLASS(SOFA_TEMPLATE4(BarycentricMapperHexahedronSetTopology,In,Out,MappingDataType,Element),SOFA_TEMPLATE4(BarycentricMapperTopologyContainer,In,Out,MappingDataType,Element)); typedef MappingDataType MappingData; - typedef BarycentricMapperTopologyContainer Inherit; + typedef BarycentricMapperTopologyContainer Inherit; typedef typename Inherit::Real Real; - typedef typename Inherit::OutReal OutReal; - typedef typename Inherit::OutDeriv OutDeriv; - typedef typename Inherit::InDeriv InDeriv; - - typedef typename Inherit::MBloc MBloc; - typedef typename Inherit::MatrixType MatrixType; - - typedef typename Inherit::ForceMask ForceMask; protected: topology::HexahedronSetTopologyContainer* m_fromContainer; @@ -956,7 +1016,12 @@ class BarycentricMapperHexahedronSetTopology : public BarycentricMapperTopologyC virtual ~BarycentricMapperHexahedronSetTopology() {} - helper::vector getBaryCoef(const Real* f) + virtual helper::vector getElements() override + { + return this->m_fromTopology->getHexahedra(); + } + + virtual helper::vector getBaryCoef(const Real* f) override { return getBaryCoef(f[0],f[1],f[2]); } @@ -974,27 +1039,38 @@ class BarycentricMapperHexahedronSetTopology : public BarycentricMapperTopologyC return hexahedronCoef; } -public: - - int addPointInCube(const int index, const SReal* baryCoords) override; - - int setPointInCube(const int pointIndex, const int cubeIndex, const SReal* baryCoords) override; + virtual void computeBase(Mat3x3d& base, const typename In::VecCoord& in, const Element& element) override + { + Mat3x3d matrixTranspose; + base[0] = in[element[1]]-in[element[0]]; + base[1] = in[element[3]]-in[element[0]]; + base[2] = in[element[4]]-in[element[0]]; + matrixTranspose.transpose(base); + base.invert(matrixTranspose); + } - void init(const typename Out::VecCoord& out, const typename In::VecCoord& in) override; + virtual void computeCenter(Vector3& center, const typename In::VecCoord& in, const Element& element) override + { + center = ( in[element[0]]+in[element[1]]+in[element[2]]+in[element[3]]+in[element[4]]+in[element[5]]+in[element[6]]+in[element[7]] ) *0.125; + } - void apply( typename Out::VecCoord& out, const typename In::VecCoord& in ) override; - void applyJ( typename Out::VecDeriv& out, const typename In::VecDeriv& in ) override; - void applyJT( typename In::VecDeriv& out, const typename Out::VecDeriv& in ) override; - void applyJT( typename In::MatrixDeriv& out, const typename Out::MatrixDeriv& in ) override; + virtual void computeDistance(double& d, const Vector3& v) override + { + d = std::max ( std::max ( -v[0],-v[1] ),std::max ( std::max ( -v[2],v[0]-1 ),std::max ( v[1]-1,v[2]-1 ) ) ); + } - virtual const sofa::defaulttype::BaseMatrix* getJ(int outSize, int inSize) override; + virtual void addPointInElement(const int elementIndex, const SReal* baryCoords) override + { + addPointInCube(elementIndex,baryCoords); + } - void draw(const core::visual::VisualParams*,const typename Out::VecCoord& out, const typename In::VecCoord& in) override; +public: + virtual int addPointInCube(const int index, const SReal* baryCoords) override; + virtual int setPointInCube(const int pointIndex, const int cubeIndex, const SReal* baryCoords) override; //-- test mapping partiel - void applyOnePoint( const unsigned int& hexaId, typename Out::VecCoord& out, const typename In::VecCoord& in) override; + virtual void applyOnePoint( const unsigned int& hexaId, typename Out::VecCoord& out, const typename In::VecCoord& in) override; //-- - // handle topology changes in the From topology virtual void handleTopologyChange(core::topology::Topology* t) override; @@ -1123,12 +1199,16 @@ extern template class SOFA_BASE_MECHANICS_API BarycentricMapperSparseGridTopolog extern template class SOFA_BASE_MECHANICS_API BarycentricMapperSparseGridTopology< Vec3dTypes, ExtVec3fTypes >; extern template class SOFA_BASE_MECHANICS_API BarycentricMapperMeshTopology< Vec3dTypes, Vec3dTypes >; extern template class SOFA_BASE_MECHANICS_API BarycentricMapperMeshTopology< Vec3dTypes, ExtVec3fTypes >; -extern template class SOFA_BASE_MECHANICS_API BarycentricMapperTopologyContainer< Vec3dTypes, Vec3dTypes , typename BarycentricMapper::MappingData1D>; -extern template class SOFA_BASE_MECHANICS_API BarycentricMapperTopologyContainer< Vec3dTypes, ExtVec3fTypes , typename BarycentricMapper::MappingData1D>; -extern template class SOFA_BASE_MECHANICS_API BarycentricMapperTopologyContainer< Vec3dTypes, Vec3dTypes , typename BarycentricMapper::MappingData2D>; -extern template class SOFA_BASE_MECHANICS_API BarycentricMapperTopologyContainer< Vec3dTypes, ExtVec3fTypes , typename BarycentricMapper::MappingData2D>; -extern template class SOFA_BASE_MECHANICS_API BarycentricMapperTopologyContainer< Vec3dTypes, Vec3dTypes , typename BarycentricMapper::MappingData3D>; -extern template class SOFA_BASE_MECHANICS_API BarycentricMapperTopologyContainer< Vec3dTypes, ExtVec3fTypes , typename BarycentricMapper::MappingData3D>; +extern template class SOFA_BASE_MECHANICS_API BarycentricMapperTopologyContainer< Vec3dTypes, Vec3dTypes , typename BarycentricMapper::MappingData1D, Edge>; +extern template class SOFA_BASE_MECHANICS_API BarycentricMapperTopologyContainer< Vec3dTypes, ExtVec3fTypes , typename BarycentricMapper::MappingData1D, Edge>; +extern template class SOFA_BASE_MECHANICS_API BarycentricMapperTopologyContainer< Vec3dTypes, Vec3dTypes , typename BarycentricMapper::MappingData2D, Triangle>; +extern template class SOFA_BASE_MECHANICS_API BarycentricMapperTopologyContainer< Vec3dTypes, ExtVec3fTypes , typename BarycentricMapper::MappingData2D, Triangle>; +extern template class SOFA_BASE_MECHANICS_API BarycentricMapperTopologyContainer< Vec3dTypes, Vec3dTypes , typename BarycentricMapper::MappingData2D, Quad>; +extern template class SOFA_BASE_MECHANICS_API BarycentricMapperTopologyContainer< Vec3dTypes, ExtVec3fTypes , typename BarycentricMapper::MappingData2D, Quad>; +extern template class SOFA_BASE_MECHANICS_API BarycentricMapperTopologyContainer< Vec3dTypes, Vec3dTypes , typename BarycentricMapper::MappingData3D, Tetrahedron>; +extern template class SOFA_BASE_MECHANICS_API BarycentricMapperTopologyContainer< Vec3dTypes, ExtVec3fTypes , typename BarycentricMapper::MappingData3D, Tetrahedron>; +extern template class SOFA_BASE_MECHANICS_API BarycentricMapperTopologyContainer< Vec3dTypes, Vec3dTypes , typename BarycentricMapper::MappingData3D, Hexahedron>; +extern template class SOFA_BASE_MECHANICS_API BarycentricMapperTopologyContainer< Vec3dTypes, ExtVec3fTypes , typename BarycentricMapper::MappingData3D, Hexahedron>; extern template class SOFA_BASE_MECHANICS_API BarycentricMapperEdgeSetTopology< Vec3dTypes, Vec3dTypes>; extern template class SOFA_BASE_MECHANICS_API BarycentricMapperEdgeSetTopology< Vec3dTypes, ExtVec3fTypes>; extern template class SOFA_BASE_MECHANICS_API BarycentricMapperTriangleSetTopology< Vec3dTypes, Vec3dTypes >; @@ -1153,12 +1233,16 @@ extern template class SOFA_BASE_MECHANICS_API BarycentricMapperSparseGridTopolog extern template class SOFA_BASE_MECHANICS_API BarycentricMapperSparseGridTopology< Vec3fTypes, ExtVec3fTypes >; extern template class SOFA_BASE_MECHANICS_API BarycentricMapperMeshTopology< Vec3fTypes, Vec3fTypes >; extern template class SOFA_BASE_MECHANICS_API BarycentricMapperMeshTopology< Vec3fTypes, ExtVec3fTypes >; -extern template class SOFA_BASE_MECHANICS_API BarycentricMapperTopologyContainer< Vec3fTypes, Vec3fTypes , typename BarycentricMapper::MappingData1D>; -extern template class SOFA_BASE_MECHANICS_API BarycentricMapperTopologyContainer< Vec3fTypes, ExtVec3fTypes , typename BarycentricMapper::MappingData1D>; -extern template class SOFA_BASE_MECHANICS_API BarycentricMapperTopologyContainer< Vec3fTypes, Vec3fTypes , typename BarycentricMapper::MappingData2D>; -extern template class SOFA_BASE_MECHANICS_API BarycentricMapperTopologyContainer< Vec3fTypes, ExtVec3fTypes , typename BarycentricMapper::MappingData2D>; -extern template class SOFA_BASE_MECHANICS_API BarycentricMapperTopologyContainer< Vec3fTypes, Vec3fTypes , typename BarycentricMapper::MappingData3D>; -extern template class SOFA_BASE_MECHANICS_API BarycentricMapperTopologyContainer< Vec3fTypes, ExtVec3fTypes , typename BarycentricMapper::MappingData3D>; +extern template class SOFA_BASE_MECHANICS_API BarycentricMapperTopologyContainer< Vec3fTypes, Vec3fTypes , typename BarycentricMapper::MappingData1D, Edge>; +extern template class SOFA_BASE_MECHANICS_API BarycentricMapperTopologyContainer< Vec3fTypes, ExtVec3fTypes , typename BarycentricMapper::MappingData1D, Edge>; +extern template class SOFA_BASE_MECHANICS_API BarycentricMapperTopologyContainer< Vec3fTypes, Vec3fTypes , typename BarycentricMapper::MappingData2D, Triangle>; +extern template class SOFA_BASE_MECHANICS_API BarycentricMapperTopologyContainer< Vec3fTypes, ExtVec3fTypes , typename BarycentricMapper::MappingData2D, Triangle>; +extern template class SOFA_BASE_MECHANICS_API BarycentricMapperTopologyContainer< Vec3fTypes, Vec3fTypes , typename BarycentricMapper::MappingData2D, Quad>; +extern template class SOFA_BASE_MECHANICS_API BarycentricMapperTopologyContainer< Vec3fTypes, ExtVec3fTypes , typename BarycentricMapper::MappingData2D, Quad>; +extern template class SOFA_BASE_MECHANICS_API BarycentricMapperTopologyContainer< Vec3fTypes, Vec3fTypes , typename BarycentricMapper::MappingData3D, Tetrahedron>; +extern template class SOFA_BASE_MECHANICS_API BarycentricMapperTopologyContainer< Vec3fTypes, ExtVec3fTypes , typename BarycentricMapper::MappingData3D, Tetrahedron>; +extern template class SOFA_BASE_MECHANICS_API BarycentricMapperTopologyContainer< Vec3fTypes, Vec3fTypes , typename BarycentricMapper::MappingData3D, Hexahedron>; +extern template class SOFA_BASE_MECHANICS_API BarycentricMapperTopologyContainer< Vec3fTypes, ExtVec3fTypes , typename BarycentricMapper::MappingData3D, Hexahedron>; extern template class SOFA_BASE_MECHANICS_API BarycentricMapperEdgeSetTopology< Vec3fTypes, Vec3fTypes>; extern template class SOFA_BASE_MECHANICS_API BarycentricMapperEdgeSetTopology< Vec3fTypes, ExtVec3fTypes>; extern template class SOFA_BASE_MECHANICS_API BarycentricMapperTriangleSetTopology< Vec3fTypes, Vec3fTypes >; @@ -1184,12 +1268,16 @@ extern template class SOFA_BASE_MECHANICS_API BarycentricMapperSparseGridTopolog extern template class SOFA_BASE_MECHANICS_API BarycentricMapperSparseGridTopology< Vec3fTypes, Vec3dTypes >; extern template class SOFA_BASE_MECHANICS_API BarycentricMapperMeshTopology< Vec3dTypes, Vec3fTypes >; extern template class SOFA_BASE_MECHANICS_API BarycentricMapperMeshTopology< Vec3fTypes, Vec3dTypes >; -extern template class SOFA_BASE_MECHANICS_API BarycentricMapperTopologyContainer< Vec3dTypes, Vec3fTypes , typename BarycentricMapper::MappingData1D>; -extern template class SOFA_BASE_MECHANICS_API BarycentricMapperTopologyContainer< Vec3fTypes, Vec3dTypes , typename BarycentricMapper::MappingData1D>; -extern template class SOFA_BASE_MECHANICS_API BarycentricMapperTopologyContainer< Vec3dTypes, Vec3fTypes , typename BarycentricMapper::MappingData2D>; -extern template class SOFA_BASE_MECHANICS_API BarycentricMapperTopologyContainer< Vec3fTypes, Vec3dTypes , typename BarycentricMapper::MappingData2D>; -extern template class SOFA_BASE_MECHANICS_API BarycentricMapperTopologyContainer< Vec3dTypes, Vec3fTypes , typename BarycentricMapper::MappingData3D>; -extern template class SOFA_BASE_MECHANICS_API BarycentricMapperTopologyContainer< Vec3fTypes, Vec3dTypes , typename BarycentricMapper::MappingData3D>; +extern template class SOFA_BASE_MECHANICS_API BarycentricMapperTopologyContainer< Vec3dTypes, Vec3fTypes , typename BarycentricMapper::MappingData1D,Edge>; +extern template class SOFA_BASE_MECHANICS_API BarycentricMapperTopologyContainer< Vec3fTypes, Vec3dTypes , typename BarycentricMapper::MappingData1D,Edge>; +extern template class SOFA_BASE_MECHANICS_API BarycentricMapperTopologyContainer< Vec3dTypes, Vec3fTypes , typename BarycentricMapper::MappingData2D,Triangle>; +extern template class SOFA_BASE_MECHANICS_API BarycentricMapperTopologyContainer< Vec3fTypes, Vec3dTypes , typename BarycentricMapper::MappingData2D,Triangle>; +extern template class SOFA_BASE_MECHANICS_API BarycentricMapperTopologyContainer< Vec3dTypes, Vec3fTypes , typename BarycentricMapper::MappingData2D,Quad>; +extern template class SOFA_BASE_MECHANICS_API BarycentricMapperTopologyContainer< Vec3fTypes, Vec3dTypes , typename BarycentricMapper::MappingData2D,Quad>; +extern template class SOFA_BASE_MECHANICS_API BarycentricMapperTopologyContainer< Vec3dTypes, Vec3fTypes , typename BarycentricMapper::MappingData3D,Tetrahedron>; +extern template class SOFA_BASE_MECHANICS_API BarycentricMapperTopologyContainer< Vec3fTypes, Vec3dTypes , typename BarycentricMapper::MappingData3D,Tetrahedron>; +extern template class SOFA_BASE_MECHANICS_API BarycentricMapperTopologyContainer< Vec3dTypes, Vec3fTypes , typename BarycentricMapper::MappingData3D,Hexahedron>; +extern template class SOFA_BASE_MECHANICS_API BarycentricMapperTopologyContainer< Vec3fTypes, Vec3dTypes , typename BarycentricMapper::MappingData3D,Hexahedron>; extern template class SOFA_BASE_MECHANICS_API BarycentricMapperEdgeSetTopology< Vec3dTypes, Vec3fTypes>; extern template class SOFA_BASE_MECHANICS_API BarycentricMapperEdgeSetTopology< Vec3fTypes, Vec3dTypes>; extern template class SOFA_BASE_MECHANICS_API BarycentricMapperTriangleSetTopology< Vec3dTypes, Vec3fTypes >; diff --git a/SofaKernel/modules/SofaBaseMechanics/BarycentricMapping.inl b/SofaKernel/modules/SofaBaseMechanics/BarycentricMapping.inl index 3b4d9c11fce..2f03ac49667 100644 --- a/SofaKernel/modules/SofaBaseMechanics/BarycentricMapping.inl +++ b/SofaKernel/modules/SofaBaseMechanics/BarycentricMapping.inl @@ -25,7 +25,6 @@ #include #include -#include #include #include @@ -65,7 +64,7 @@ using sofa::defaulttype::Mat3x3d; using sofa::defaulttype::Vec3d; // 10/18 E.Coevoet: what's the difference between edge/line, tetra/tetrahedron, hexa/hexahedron? typedef typename sofa::core::topology::BaseMeshTopology::Line Line; -typedef typename sofa::core::topology::BaseMeshTopology::Line Edge; +typedef typename sofa::core::topology::BaseMeshTopology::Edge Edge; typedef typename sofa::core::topology::BaseMeshTopology::Triangle Triangle; typedef typename sofa::core::topology::BaseMeshTopology::Quad Quad; typedef typename sofa::core::topology::BaseMeshTopology::Tetra Tetra; @@ -121,6 +120,7 @@ BarycentricMapping::~BarycentricMapping() { } + template void BarycentricMapperRegularGridTopology::clearMapAndReserve ( int size ) { @@ -163,6 +163,8 @@ void BarycentricMapperRegularGridTopology::init ( const typename Out::Ve } } + + template void BarycentricMapperSparseGridTopology::clearMapAndReserve ( int size ) { @@ -206,6 +208,8 @@ void BarycentricMapperSparseGridTopology::init ( const typename Out::Vec } } + + template void BarycentricMapperMeshTopology::clearMap1dAndReserve ( int size ) { @@ -234,14 +238,9 @@ template void BarycentricMapperMeshTopology::clearMapAndReserve ( int size ) { m_updateJ = true; - m_map1d.clear(); - if ( size>0 ) m_map1d.reserve ( size ); - - m_map2d.clear(); - if ( size>0 ) m_map2d.reserve ( size ); - - m_map3d.clear(); - if ( size>0 ) m_map3d.reserve ( size ); + clearMap1dAndReserve(size); + clearMap2dAndReserve(size); + clearMap3dAndReserve(size); } template @@ -457,7 +456,6 @@ void BarycentricMapperMeshTopology::init ( const typename Out::VecCoord& coef = ( V12 ) * Vector3 ( Out::getCPos(out[i])-in[edges[e][0]] ) /lengthEdge; if ( coef >= 0 && coef <= 1 ) {addPointInLine ( e,&coef ); break; } - } //If no good coefficient has been found, we add to the last element if ( e == edges.size() ) addPointInLine ( (int)edges.size()-1,&coef ); @@ -491,22 +489,22 @@ void BarycentricMapperMeshTopology::init ( const typename Out::VecCoord& } for ( unsigned int i=0; i0 ) d = ( pos-centers[t] ).norm2(); + if ( d>0 ) d = ( outPos-centers[t] ).norm2(); if ( d0 ) d = ( pos-centers[nbTriangles+q] ).norm2(); + if ( d>0 ) d = ( outPos-centers[nbTriangles+q] ).norm2(); if ( d::init ( const typename Out::VecCoord& -template -int BarycentricMapperEdgeSetTopology::addPointInLine ( const int edgeIndex, const SReal* baryCoords ) +template +void BarycentricMapperTopologyContainer::clearMapAndReserve(int size) +{ + helper::vector& vectorData = *(d_map.beginEdit()); + vectorData.clear(); + if ( size>0 ) vectorData.reserve ( size ); + d_map.endEdit(); +} + +template +int BarycentricMapperEdgeSetTopology::addPointInLine ( const int edgeIndex, const SReal* baryCoords ) { helper::vector& vectorData = *(d_map.beginEdit()); vectorData.resize ( d_map.getValue().size() +1 ); @@ -584,8 +591,8 @@ int BarycentricMapperEdgeSetTopology::addPointInLine ( c return (int)d_map.getValue().size()-1; } -template -int BarycentricMapperEdgeSetTopology::createPointInLine ( const typename Out::Coord& p, int edgeIndex, const typename In::VecCoord* points ) +template +int BarycentricMapperEdgeSetTopology::createPointInLine ( const typename Out::Coord& p, int edgeIndex, const typename In::VecCoord* points ) { SReal baryCoords[1]; const Edge& elem = this->m_fromTopology->getEdge ( edgeIndex ); @@ -596,14 +603,8 @@ int BarycentricMapperEdgeSetTopology::createPointInLine return this->addPointInLine ( edgeIndex, baryCoords ); } -template -void BarycentricMapperEdgeSetTopology::init ( const typename Out::VecCoord& /*out*/, const typename In::VecCoord& /*in*/ ) -{ - m_fromContainer->getContext()->get ( m_fromGeomAlgo ); -} - -template -int BarycentricMapperTriangleSetTopology::addPointInTriangle ( const int triangleIndex, const SReal* baryCoords ) +template +int BarycentricMapperTriangleSetTopology::addPointInTriangle ( const int triangleIndex, const SReal* baryCoords ) { helper::vector& vectorData = *(d_map.beginEdit()); vectorData.resize ( d_map.getValue().size() +1 ); @@ -615,8 +616,8 @@ int BarycentricMapperTriangleSetTopology::addPointInTria return (int)d_map.getValue().size()-1; } -template -int BarycentricMapperTriangleSetTopology::createPointInTriangle ( const typename Out::Coord& p, int triangleIndex, const typename In::VecCoord* points ) +template +int BarycentricMapperTriangleSetTopology::createPointInTriangle ( const typename Out::Coord& p, int triangleIndex, const typename In::VecCoord* points ) { SReal baryCoords[2]; const Triangle& elem = this->m_fromTopology->getTriangle ( triangleIndex ); @@ -633,49 +634,8 @@ int BarycentricMapperTriangleSetTopology::createPointInT return this->addPointInTriangle ( triangleIndex, baryCoords ); } -template -void BarycentricMapperTriangleSetTopology::init ( const typename Out::VecCoord& out, const typename In::VecCoord& in ) -{ - m_fromContainer->getContext()->get ( m_fromGeomAlgo ); - - const helper::vector& triangles = this->m_fromTopology->getTriangles(); - helper::vector bases; - helper::vector centers; - - this->clearMapAndReserve ( (int)out.size() ); - bases.resize ( triangles.size() ); - centers.resize ( triangles.size() ); - - for ( unsigned int t = 0; t < triangles.size(); t++ ) - { - Mat3x3d m,mt; - m[0] = in[triangles[t][1]]-in[triangles[t][0]]; - m[1] = in[triangles[t][2]]-in[triangles[t][0]]; - m[2] = cross ( m[0],m[1] ); - mt.transpose ( m ); - bases[t].invert ( mt ); - centers[t] = ( in[triangles[t][0]]+in[triangles[t][1]]+in[triangles[t][2]] ) /3; - } - - for ( unsigned int i=0; i0 ) d = ( pos-centers[t] ).norm2(); - if ( d -int BarycentricMapperQuadSetTopology::addPointInQuad ( const int quadIndex, const SReal* baryCoords ) +template +int BarycentricMapperQuadSetTopology::addPointInQuad ( const int quadIndex, const SReal* baryCoords ) { helper::vector& vectorData = *(d_map.beginEdit()); vectorData.resize ( d_map.getValue().size() +1 ); @@ -687,8 +647,8 @@ int BarycentricMapperQuadSetTopology::addPointInQuad ( c return (int)d_map.getValue().size()-1; } -template -int BarycentricMapperQuadSetTopology::createPointInQuad ( const typename Out::Coord& p, int quadIndex, const typename In::VecCoord* points ) +template +int BarycentricMapperQuadSetTopology::createPointInQuad ( const typename Out::Coord& p, int quadIndex, const typename In::VecCoord* points ) { SReal baryCoords[2]; const Quad& elem = this->m_fromTopology->getQuad ( quadIndex ); @@ -709,50 +669,8 @@ int BarycentricMapperQuadSetTopology::createPointInQuad return this->addPointInQuad ( quadIndex, baryCoords ); } -template -void BarycentricMapperQuadSetTopology::init ( const typename Out::VecCoord& out, const typename In::VecCoord& in ) -{ - m_fromContainer->getContext()->get ( m_fromGeomAlgo ); - - const helper::vector& quads = this->m_fromTopology->getQuads(); - - helper::vector< Matrix3> bases; - helper::vector< Vector3> centers; - - this->clearMapAndReserve ( (int)out.size() ); - bases.resize ( quads.size() ); - centers.resize ( quads.size() ); - - for ( unsigned int c = 0; c < quads.size(); c++ ) - { - Mat3x3d m,mt; - m[0] = in[quads[c][1]]-in[quads[c][0]]; - m[1] = in[quads[c][3]]-in[quads[c][0]]; - m[2] = cross ( m[0],m[1] ); - mt.transpose ( m ); - bases[c].invert ( mt ); - centers[c] = ( in[quads[c][0]]+in[quads[c][1]]+in[quads[c][2]]+in[quads[c][3]] ) *0.25; - } - - for ( unsigned int i=0; i0 ) d = ( pos-centers[c] ).norm2(); - if ( d -int BarycentricMapperTetrahedronSetTopology::addPointInTetra ( const int tetraIndex, const SReal* baryCoords ) +template +int BarycentricMapperTetrahedronSetTopology::addPointInTetra ( const int tetraIndex, const SReal* baryCoords ) { helper::vector& vectorData = *(d_map.beginEdit()); vectorData.resize ( d_map.getValue().size() +1 ); @@ -765,52 +683,8 @@ int BarycentricMapperTetrahedronSetTopology::addPointInT return (int)d_map.getValue().size()-1; } -template -void BarycentricMapperTetrahedronSetTopology::init ( const typename Out::VecCoord& out, const typename In::VecCoord& in ) -{ - m_fromContainer->getContext()->get ( m_fromGeomAlgo ); - - const helper::vector& tetras = this->m_fromTopology->getTetrahedra(); - - helper::vector< Matrix3> bases; - helper::vector< Vector3> centers; - - this->clearMapAndReserve ( (int)out.size() ); - bases.resize ( tetras.size() ); - centers.resize ( tetras.size() ); - - // Compute tetras base and center - for ( unsigned int t = 0; t < tetras.size(); t++ ) - { - Mat3x3d m,mt; - m[0] = in[tetras[t][1]]-in[tetras[t][0]]; - m[1] = in[tetras[t][2]]-in[tetras[t][0]]; - m[2] = in[tetras[t][3]]-in[tetras[t][0]]; - mt.transpose ( m ); - bases[t].invert ( mt ); - centers[t] = ( in[tetras[t][0]]+in[tetras[t][1]]+in[tetras[t][2]]+in[tetras[t][3]] ) *0.25; - } - - // Find nearest tetra for each point, and compute corresponding barycentric coordinate - for ( unsigned int i = 0; i < out.size(); i++ ) - { - Vec3d pos = Out::getCPos(out[i]); - Vector3 baryCoords; - int tetraIndex = -1; - double distance = 1e10; - for ( unsigned int t = 0; t < tetras.size(); t++ ) - { - Vec3d v = bases[t] * ( pos - in[tetras[t][0]] ); - double d = std::max ( std::max ( -v[0],-v[1] ), std::max ( -v[2],v[0]+v[1]+v[2]-1 ) ); - if ( d>0 ) d = ( pos-centers[t] ).norm2(); - if ( d -int BarycentricMapperHexahedronSetTopology::addPointInCube ( const int cubeIndex, const SReal* baryCoords ) +template +int BarycentricMapperHexahedronSetTopology::addPointInCube ( const int cubeIndex, const SReal* baryCoords ) { helper::vector& vectorData = *(d_map.beginEdit()); vectorData.resize ( d_map.getValue().size() +1 ); @@ -823,8 +697,8 @@ int BarycentricMapperHexahedronSetTopology::addPointInCu return (int)d_map.getValue().size()-1; } -template -int BarycentricMapperHexahedronSetTopology::setPointInCube ( const int pointIndex, const int cubeIndex, const SReal* baryCoords ) +template +int BarycentricMapperHexahedronSetTopology::setPointInCube ( const int pointIndex, const int cubeIndex, const SReal* baryCoords ) { if ( pointIndex >= ( int ) d_map.getValue().size() ) return -1; @@ -845,43 +719,56 @@ int BarycentricMapperHexahedronSetTopology::setPointInCu return pointIndex; } -template -void BarycentricMapperHexahedronSetTopology::init ( const typename Out::VecCoord& out, const typename In::VecCoord& in ) +template +void BarycentricMapperTopologyContainer::init ( const typename Out::VecCoord& out, const typename In::VecCoord& in ) { - SOFA_UNUSED(in); - m_fromContainer->getContext()->get ( m_fromGeomAlgo ); - - if ( m_fromGeomAlgo == NULL ) - { - msg_error() << "Cannot find GeometryAlgorithms component at init." ; - } - - if ( !d_map.getValue().empty() ) - return; + const helper::vector& elements = getElements(); + helper::vector bases; + helper::vector centers; this->clearMapAndReserve ( (int)out.size() ); + bases.resize ( elements.size() ); + centers.resize ( elements.size() ); - typename In::VecCoord coord; - helper::vector elements ( out.size() ); - helper::vector coefs ( out.size() ); - helper::vector distances ( out.size() ); + // Compute bases and centers of each element + for ( unsigned int e = 0; e < elements.size(); e++ ) + { + Element element = elements[e]; - coord.resize ( out.size() ); - for ( unsigned int i=0; ifindNearestElementsInRestPos ( coord, elements, coefs, distances ); + Vector3 center; + computeCenter(center,in,element); + centers[e] = center; + } - for ( unsigned int i=0; i0 ) + dist = ( outPos-centers[e] ).norm2(); + if ( dist void BarycentricMapping::createMapperFromTopology ( BaseMeshTopology * topology ) { @@ -917,7 +804,7 @@ void BarycentricMapping::createMapperFromTopology ( BaseMeshTopology if (t2 != NULL) { typedef BarycentricMapperTetrahedronSetTopology TetrahedronSetMapper; - //m_mapper = sofa::core::objectmodel::New(t2, toTopoCont); + m_mapper = sofa::core::objectmodel::New(t2, toTopoCont); } else { @@ -1216,109 +1103,35 @@ void BarycentricMapperSparseGridTopology::apply ( typename Out::VecCoord } } -template -void BarycentricMapperEdgeSetTopology::apply ( typename Out::VecCoord& out, const typename In::VecCoord& in ) -{ - out.resize( d_map.getValue().size() ); - - const helper::vector& edges = this->m_fromTopology->getEdges(); - for ( unsigned int i=0; i baryCoef = getBaryCoef(d_map.getValue()[i].baryCoords); - InDeriv inPos{0.,0.,0.}; - for (unsigned int j=0; j -void BarycentricMapperTriangleSetTopology::apply ( typename Out::VecCoord& out, const typename In::VecCoord& in ) -{ - out.resize( d_map.getValue().size() ); - - const helper::vector& triangles = this->m_fromTopology->getTriangles(); - for ( unsigned int i=0; i baryCoef = getBaryCoef(d_map.getValue()[i].baryCoords); - InDeriv inPos{0.,0.,0.}; - for (unsigned int j=0; j -void BarycentricMapperQuadSetTopology::apply ( typename Out::VecCoord& out, const typename In::VecCoord& in ) -{ - out.resize( d_map.getValue().size() ); - - const helper::vector& quads = this->m_fromTopology->getQuads(); - for ( unsigned int i=0; i baryCoef = getBaryCoef(d_map.getValue()[i].baryCoords); - InDeriv inPos{0.,0.,0.}; - for (unsigned int j=0; j -void BarycentricMapperTetrahedronSetTopology::apply ( typename Out::VecCoord& out, const typename In::VecCoord& in ) +template +void BarycentricMapperTopologyContainer::apply ( typename Out::VecCoord& out, const typename In::VecCoord& in ) { out.resize( d_map.getValue().size() ); - const helper::vector& tetrahedra = this->m_fromTopology->getTetrahedra(); + const helper::vector& elements = getElements(); for ( unsigned int i=0; i baryCoef = getBaryCoef(d_map.getValue()[i].baryCoords); InDeriv inPos{0.,0.,0.}; - for (unsigned int j=0; j -void BarycentricMapperHexahedronSetTopology::apply ( typename Out::VecCoord& out, const typename In::VecCoord& in ) +template +void BarycentricMapperTopologyContainer::resize( core::State* toModel ) { - out.resize( d_map.getValue().size() ); - - const helper::vector& cubes = this->m_fromTopology->getHexahedra(); - for ( unsigned int i=0; i baryCoef = getBaryCoef(d_map.getValue()[i].baryCoords); - InDeriv inPos{0.,0.,0.}; - for (unsigned int j=0; jresize(d_map.getValue().size()); } - //-- test mapping partiel -template -void BarycentricMapperHexahedronSetTopology::applyOnePoint( const unsigned int& hexaPointId,typename Out::VecCoord& out, const typename In::VecCoord& in ) +template +void BarycentricMapperHexahedronSetTopology::applyOnePoint( const unsigned int& hexaPointId,typename Out::VecCoord& out, const typename In::VecCoord& in ) { const helper::vector& cubes = this->m_fromTopology->getHexahedra(); const Real fx = d_map.getValue()[hexaPointId].baryCoords[0]; @@ -1340,6 +1153,7 @@ void BarycentricMapperHexahedronSetTopology::applyOnePoi /************************************* ApplyJ ***********************************/ + template void BarycentricMapping::applyJ (const core::MechanicalParams * mparams, Data< typename Out::VecDeriv >& _out, const Data< typename In::VecDeriv >& in) { @@ -1506,115 +1320,24 @@ void BarycentricMapperSparseGridTopology::applyJ ( typename Out::VecDeri } -template -void BarycentricMapperEdgeSetTopology::applyJ ( typename Out::VecDeriv& out, const typename In::VecDeriv& in ) -{ - out.resize( d_map.getValue().size() ); - - const helper::vector& edges = this->m_fromTopology->getEdges(); - for( size_t i=0 ; imaskTo->size() ; ++i) - { - if( this->maskTo->isActivated() && !this->maskTo->getEntry(i) ) continue; - - int index = d_map.getValue()[i].in_index; - const Edge& edge = edges[index]; - - helper::vector baryCoef = getBaryCoef(d_map.getValue()[i].baryCoords); - InDeriv inPos{0.,0.,0.}; - for (unsigned int j=0; j -void BarycentricMapperTriangleSetTopology::applyJ ( typename Out::VecDeriv& out, const typename In::VecDeriv& in ) -{ - out.resize( d_map.getValue().size() ); - - const helper::vector& triangles = this->m_fromTopology->getTriangles(); - for( size_t i=0 ; imaskTo->size() ; ++i) - { - if( this->maskTo->isActivated() && !this->maskTo->getEntry(i) ) continue; - - int index = d_map.getValue()[i].in_index; - const Triangle& triangle = triangles[index]; - - helper::vector baryCoef = getBaryCoef(d_map.getValue()[i].baryCoords); - InDeriv inPos{0.,0.,0.}; - for (unsigned int j=0; j -void BarycentricMapperQuadSetTopology::applyJ ( typename Out::VecDeriv& out, const typename In::VecDeriv& in ) -{ - out.resize( d_map.getValue().size() ); - - const helper::vector& quads = this->m_fromTopology->getQuads(); - - for( size_t i=0 ; imaskTo->size() ; ++i) - { - if( this->maskTo->isActivated() && !this->maskTo->getEntry(i) ) continue; - - int index = d_map.getValue()[i].in_index; - const Quad& quad = quads[index]; - - helper::vector baryCoef = getBaryCoef(d_map.getValue()[i].baryCoords); - InDeriv inPos{0.,0.,0.}; - for (unsigned int j=0; j -void BarycentricMapperTetrahedronSetTopology::applyJ ( typename Out::VecDeriv& out, const typename In::VecDeriv& in ) -{ - out.resize( d_map.getValue().size() ); - - const helper::vector& tetrahedra = this->m_fromTopology->getTetrahedra(); - - - for( size_t i=0 ; imaskTo->size() ; ++i) - { - if( this->maskTo->isActivated() && !this->maskTo->getEntry(i) ) continue; - - int index = d_map.getValue()[i].in_index; - const Tetrahedron& tetra = tetrahedra[index]; - - helper::vector baryCoef = getBaryCoef(d_map.getValue()[i].baryCoords); - InDeriv inPos{0.,0.,0.}; - for (unsigned int j=0; j -void BarycentricMapperHexahedronSetTopology::applyJ ( typename Out::VecDeriv& out, const typename In::VecDeriv& in ) +template +void BarycentricMapperTopologyContainer::applyJ ( typename Out::VecDeriv& out, const typename In::VecDeriv& in ) { out.resize( d_map.getValue().size() ); - const helper::vector& cubes = this->m_fromTopology->getHexahedra(); + const helper::vector& elements = getElements(); for( size_t i=0 ; imaskTo->size() ; ++i) { if( this->maskTo->isActivated() && !this->maskTo->getEntry(i) ) continue; int index = d_map.getValue()[i].in_index; - const Hexahedron& cube = cubes[index]; + const Element& element = elements[index]; helper::vector baryCoef = getBaryCoef(d_map.getValue()[i].baryCoords); InDeriv inPos{0.,0.,0.}; - for (unsigned int j=0; j::applyJT ( typename In::VecDeri } } -template -void BarycentricMapperEdgeSetTopology::applyJT ( typename In::VecDeriv& out, const typename Out::VecDeriv& in ) +template +void BarycentricMapperTopologyContainer::applyJT ( typename In::VecDeriv& out, const typename Out::VecDeriv& in ) { - const helper::vector& edges = this->m_fromTopology->getEdges(); + const helper::vector& elements = getElements(); ForceMask& mask = *this->maskFrom; for( size_t i=0 ; imaskTo->size() ; ++i) @@ -1847,134 +1570,42 @@ void BarycentricMapperEdgeSetTopology::applyJT ( typenam if( !this->maskTo->getEntry(i) ) continue; int index = d_map.getValue()[i].in_index; - const Edge& edge = edges[index]; + const Element& element = elements[index]; const typename Out::DPos inPos = Out::getDPos(in[i]); helper::vector baryCoef = getBaryCoef(d_map.getValue()[i].baryCoords); - for (unsigned int j=0; j -void BarycentricMapperTriangleSetTopology::applyJT ( typename In::VecDeriv& out, const typename Out::VecDeriv& in ) -{ - const helper::vector& triangles = this->m_fromTopology->getTriangles(); - ForceMask& mask = *this->maskFrom; - for( size_t i=0 ; imaskTo->size() ; ++i) - { - if( !this->maskTo->getEntry(i) ) continue; +/************************************* GetJ ***********************************/ - int index = d_map.getValue()[i].in_index; - const Triangle& triangle = triangles[index]; +template +const sofa::defaulttype::BaseMatrix* BarycentricMapping::getJ() +{ + if ( +#ifdef SOFA_DEV + sleeping.getValue()==false && +#endif + m_mapper!=NULL ) + { + const size_t outStateSize = this->toModel->getSize(); + const size_t inStateSize = this->fromModel->getSize(); + const sofa::defaulttype::BaseMatrix* matJ = m_mapper->getJ((int)outStateSize, (int)inStateSize); - const typename Out::DPos inPos = Out::getDPos(in[i]); - helper::vector baryCoef = getBaryCoef(d_map.getValue()[i].baryCoords); - for (unsigned int j=0; j -void BarycentricMapperQuadSetTopology::applyJT ( typename In::VecDeriv& out, const typename Out::VecDeriv& in ) -{ - const helper::vector& quads = this->m_fromTopology->getQuads(); - - ForceMask& mask = *this->maskFrom; - for( size_t i=0 ; imaskTo->size() ; ++i) - { - if( !this->maskTo->getEntry(i) ) continue; - - int index = d_map.getValue()[i].in_index; - const Quad& quad = quads[index]; - - const typename Out::DPos inPos = Out::getDPos(in[i]); - helper::vector baryCoef = getBaryCoef(d_map.getValue()[i].baryCoords); - for (unsigned int j=0; j -void BarycentricMapperTetrahedronSetTopology::applyJT ( typename In::VecDeriv& out, const typename Out::VecDeriv& in ) -{ - const helper::vector& tetrahedra = this->m_fromTopology->getTetrahedra(); - - ForceMask& mask = *this->maskFrom; - for( size_t i=0 ; imaskTo->size() ; ++i) - { - if( !this->maskTo->getEntry(i) ) continue; - - int index = d_map.getValue()[i].in_index; - const Tetrahedron& tetra = tetrahedra[index]; - - const typename Out::DPos inPos = Out::getDPos(in[i]); - helper::vector baryCoef = getBaryCoef(d_map.getValue()[i].baryCoords); - for (unsigned int j=0; j -void BarycentricMapperHexahedronSetTopology::applyJT ( typename In::VecDeriv& out, const typename Out::VecDeriv& in ) -{ - const helper::vector& cubes = this->m_fromTopology->getHexahedra(); - - ForceMask& mask = *this->maskFrom; - for( size_t i=0 ; imaskTo->size() ; ++i) - { - if( !this->maskTo->getEntry(i) ) continue; - - int index = d_map.getValue()[i].in_index; - const Hexahedron& cube = cubes[index]; - - const typename Out::DPos inPos = Out::getDPos(in[i]); - helper::vector baryCoef = getBaryCoef(d_map.getValue()[i].baryCoords); - for (unsigned int j=0; j -const sofa::defaulttype::BaseMatrix* BarycentricMapping::getJ() -{ - if ( -#ifdef SOFA_DEV - sleeping.getValue()==false && -#endif - m_mapper!=NULL ) - { - const size_t outStateSize = this->toModel->getSize(); - const size_t inStateSize = this->fromModel->getSize(); - const sofa::defaulttype::BaseMatrix* matJ = m_mapper->getJ((int)outStateSize, (int)inStateSize); - - return matJ; - } - else - return NULL; -} - -template -const sofa::defaulttype::BaseMatrix* BarycentricMapperMeshTopology::getJ(int outSize, int inSize) +template +const sofa::defaulttype::BaseMatrix* BarycentricMapperMeshTopology::getJ(int outSize, int inSize) { if (m_matrixJ && !m_updateJ && m_matrixJ->rowBSize() == (MatrixTypeIndex)outSize && m_matrixJ->colBSize() == (MatrixTypeIndex)inSize) @@ -2154,114 +1785,31 @@ const sofa::defaulttype::BaseMatrix* BarycentricMapperSparseGridTopology return matrixJ; } -template -const sofa::defaulttype::BaseMatrix* BarycentricMapperEdgeSetTopology::getJ(int outSize, int inSize) +template +const sofa::defaulttype::BaseMatrix* BarycentricMapperTopologyContainer::getJ(int outSize, int inSize) { - Inherit::getJ(outSize,inSize); - - const helper::vector& edges = this->m_fromTopology->getEdges(); - - for( size_t outId=0 ; outIdmaskTo->size() ; ++outId) - { - if( !this->maskTo->getEntry(outId) ) continue; - - const Edge& edge = edges[d_map.getValue()[outId].in_index]; - - helper::vector baryCoef = getBaryCoef(d_map.getValue()[outId].baryCoords); - for (unsigned int j=0; jaddMatrixContrib(m_matrixJ, outId, edge[j], baryCoef[j]); - } - m_matrixJ->compress(); - m_updateJ = false; - return m_matrixJ; -} - -template -const sofa::defaulttype::BaseMatrix* BarycentricMapperTriangleSetTopology::getJ(int outSize, int inSize) -{ - Inherit::getJ(outSize,inSize); - - const helper::vector& triangles = this->m_fromTopology->getTriangles(); - - for( size_t outId=0 ; outIdmaskTo->size() ; ++outId) - { - if( !this->maskTo->getEntry(outId) ) continue; - - const Triangle& triangle = triangles[d_map.getValue()[outId].in_index]; - - helper::vector baryCoef = getBaryCoef(d_map.getValue()[outId].baryCoords); - for (unsigned int j=0; jaddMatrixContrib(m_matrixJ, outId, triangle[j], baryCoef[j]); - } - - - m_matrixJ->compress(); - m_updateJ = false; - return m_matrixJ; -} - -template -const sofa::defaulttype::BaseMatrix* BarycentricMapperQuadSetTopology::getJ(int outSize, int inSize) -{ - Inherit::getJ(outSize,inSize); - - const helper::vector& quads = this->m_fromTopology->getQuads(); - - for( size_t outId=0 ; outIdmaskTo->size() ; ++outId) - { - if( !this->maskTo->getEntry(outId) ) continue; - - const Quad& quad = quads[d_map.getValue()[outId].in_index]; - - helper::vector baryCoef = getBaryCoef(d_map.getValue()[outId].baryCoords); - for (unsigned int j=0; jaddMatrixContrib(m_matrixJ, outId, quad[j], baryCoef[j]); - } - - m_matrixJ->compress(); - m_updateJ = false; - return m_matrixJ; -} - -template -const sofa::defaulttype::BaseMatrix* BarycentricMapperTetrahedronSetTopology::getJ(int outSize, int inSize) -{ - Inherit::getJ(outSize,inSize); - - const helper::vector& tetrahedra = this->m_fromTopology->getTetrahedra(); - - for( size_t outId=0 ; outIdmaskTo->size() ; ++outId) - { - if( !this->maskTo->getEntry(outId) ) continue; - - const Tetrahedron& tetra = tetrahedra[d_map.getValue()[outId].in_index]; + if (m_matrixJ && !m_updateJ) + return m_matrixJ; - helper::vector baryCoef = getBaryCoef(d_map.getValue()[outId].baryCoords); - for (unsigned int j=0; jaddMatrixContrib(m_matrixJ, outId, tetra[j], baryCoef[j]); - } + if (!m_matrixJ) m_matrixJ = new MatrixType; + if (m_matrixJ->rowBSize() != (MatrixTypeIndex)outSize || m_matrixJ->colBSize() != (MatrixTypeIndex)inSize) + m_matrixJ->resize(outSize*NOut, inSize*NIn); + else + m_matrixJ->clear(); - m_matrixJ->compress(); - m_updateJ = false; return m_matrixJ; -} - -template -const sofa::defaulttype::BaseMatrix* BarycentricMapperHexahedronSetTopology::getJ(int outSize, int inSize) -{ - Inherit::getJ(outSize,inSize); - const helper::vector& hexas = this->m_fromTopology->getHexahedra(); + const helper::vector& elements = getElements(); for( size_t outId=0 ; outIdmaskTo->size() ; ++outId) { if( !this->maskTo->getEntry(outId) ) continue; - const Hexahedron& hexa = hexas[d_map.getValue()[outId].in_index]; + const Element& element = elements[d_map.getValue()[outId].in_index]; helper::vector baryCoef = getBaryCoef(d_map.getValue()[outId].baryCoords); - for (unsigned int j=0; jaddMatrixContrib(m_matrixJ, outId, hexa[j], baryCoef[j]); + for (unsigned int j=0; jaddMatrixContrib(m_matrixJ, outId, element[j], baryCoef[j]); } m_matrixJ->compress(); @@ -2511,134 +2059,28 @@ void BarycentricMapperSparseGridTopology::draw (const core::visual::Vis vparams->drawTool()->drawLines ( points, 1, sofa::defaulttype::Vec<4,float> ( 0,0,1,1 ) ); } -template -void BarycentricMapperEdgeSetTopology::draw (const core::visual::VisualParams* vparams, - const typename Out::VecCoord& out, - const typename In::VecCoord& in ) -{ - // Draw line between mapped node (out) and nodes of nearest element (in) - const helper::vector& edges = this->m_fromTopology->getEdges(); - - std::vector< Vector3 > points; - { - for ( unsigned int i=0; i baryCoef = getBaryCoef(d_map.getValue()[i].baryCoords); - for ( int j=0; j<2; j++ ) - { - if ( baryCoef[j]<=-0.0001 || baryCoef[j]>=0.0001 ) - { - points.push_back ( Out::getCPos(out[i]) ); - points.push_back ( in[edge[j]] ); - } - } - } - } - vparams->drawTool()->drawLines ( points, 1, sofa::defaulttype::Vec<4,float> ( 0,1,0,1 ) ); -} -template -void BarycentricMapperTriangleSetTopology::draw (const core::visual::VisualParams* vparams, - const typename Out::VecCoord& out, - const typename In::VecCoord& in ) +template +void BarycentricMapperTopologyContainer::draw (const core::visual::VisualParams* vparams, + const typename Out::VecCoord& out, + const typename In::VecCoord& in ) { // Draw line between mapped node (out) and nodes of nearest element (in) - const helper::vector& triangles = m_fromTopology->getTriangles(); - - std::vector< Vector3 > points; - { - for ( unsigned int i=0; i baryCoef = getBaryCoef(d_map.getValue()[i].baryCoords); - for ( int j=0; j<3; j++ ) - { - if ( baryCoef[j]<=-0.0001 || baryCoef[j]>=0.0001 ) - { - points.push_back ( Out::getCPos(out[i]) ); - points.push_back ( in[triangle[j]] ); - } - } - } - } - vparams->drawTool()->drawLines ( points, 1, sofa::defaulttype::Vec<4,float> ( 0,1,0,1 ) ); -} - -template -void BarycentricMapperQuadSetTopology::draw (const core::visual::VisualParams* vparams, - const typename Out::VecCoord& out, - const typename In::VecCoord& in ) -{ - // Draw line between mapped node (out) and nodes of nearest element (in) - const helper::vector& quads = this->m_fromTopology->getQuads(); - - std::vector< Vector3 > points; - { - for ( unsigned int i=0; i baryCoef = getBaryCoef(d_map.getValue()[i].baryCoords); - for ( int j=0; j<4; j++ ) - { - if ( baryCoef[j]<=-0.0001 || baryCoef[j]>=0.0001 ) - { - points.push_back ( Out::getCPos(out[i]) ); - points.push_back ( in[quad[j]] ); - } - } - } - } - vparams->drawTool()->drawLines ( points, 1, sofa::defaulttype::Vec<4,float> ( 0,1,0,1 ) ); -} - -template -void BarycentricMapperTetrahedronSetTopology::draw (const core::visual::VisualParams* vparams, - const typename Out::VecCoord& out, - const typename In::VecCoord& in ) -{ - const helper::vector& tetrahedra = this->m_fromTopology->getTetrahedra(); - - std::vector< Vector3 > points; - { - for ( unsigned int i=0; i baryCoef = getBaryCoef(d_map.getValue()[i].baryCoords); - for ( int j=0; j<4; j++ ) - { - if ( baryCoef[j]<=-0.0001 || baryCoef[j]>=0.0001 ) - { - points.push_back ( Out::getCPos(out[i]) ); - points.push_back ( in[tetra[j]] ); - } - } - } - } - vparams->drawTool()->drawLines ( points, 1, sofa::defaulttype::Vec<4,float> ( 0,1,0,1 ) ); -} - -template -void BarycentricMapperHexahedronSetTopology::draw (const core::visual::VisualParams* vparams, - const typename Out::VecCoord& out, - const typename In::VecCoord& in ) -{ - // Draw line between mapped node (out) and nodes of nearest element (in) - const helper::vector& hexas = this->m_fromTopology->getHexahedra(); + const helper::vector& elements = getElements(); std::vector< Vector3 > points; { for ( unsigned int i=0; i baryCoef = getBaryCoef(d_map.getValue()[i].baryCoords); - for ( int j=0; j<8; j++ ) + for ( unsigned int j=0; j=0.0001 ) { points.push_back ( Out::getCPos(out[i]) ); - points.push_back ( in[hexa[j]] ); + points.push_back ( in[element[j]] ); } } } @@ -2875,130 +2317,11 @@ void BarycentricMapperSparseGridTopology::applyJT ( typename In::MatrixD } } -template -void BarycentricMapperEdgeSetTopology::applyJT ( typename In::MatrixDeriv& out, const typename Out::MatrixDeriv& in ) -{ - typename Out::MatrixDeriv::RowConstIterator rowItEnd = in.end(); - const helper::vector& edges = this->m_fromTopology->getEdges(); - - for (typename Out::MatrixDeriv::RowConstIterator rowIt = in.begin(); rowIt != rowItEnd; ++rowIt) - { - typename Out::MatrixDeriv::ColConstIterator colItEnd = rowIt.end(); - typename Out::MatrixDeriv::ColConstIterator colIt = rowIt.begin(); - - if (colIt != colItEnd) - { - typename In::MatrixDeriv::RowIterator o = out.writeLine(rowIt.index()); - for ( ; colIt != colItEnd; ++colIt) - { - unsigned indexIn = colIt.index(); - InDeriv data = (InDeriv) Out::getDPos(colIt.val()); - - const Edge edge = edges[this->d_map.getValue()[indexIn].in_index]; - - helper::vector baryCoef = getBaryCoef(d_map.getValue()[indexIn].baryCoords); - for (unsigned int j=0; j -void BarycentricMapperTriangleSetTopology::applyJT ( typename In::MatrixDeriv& out, const typename Out::MatrixDeriv& in ) -{ - typename Out::MatrixDeriv::RowConstIterator rowItEnd = in.end(); - const helper::vector& triangles = this->m_fromTopology->getTriangles(); - - for (typename Out::MatrixDeriv::RowConstIterator rowIt = in.begin(); rowIt != rowItEnd; ++rowIt) - { - typename Out::MatrixDeriv::ColConstIterator colItEnd = rowIt.end(); - typename Out::MatrixDeriv::ColConstIterator colIt = rowIt.begin(); - - if (colIt != colItEnd) - { - typename In::MatrixDeriv::RowIterator o = out.writeLine(rowIt.index()); - - for ( ; colIt != colItEnd; ++colIt) - { - unsigned indexIn = colIt.index(); - InDeriv data = (InDeriv) Out::getDPos(colIt.val()); - - const Triangle triangle = triangles[this->d_map.getValue()[indexIn].in_index]; - - helper::vector baryCoef = getBaryCoef(d_map.getValue()[indexIn].baryCoords); - for (unsigned int j=0; j -void BarycentricMapperQuadSetTopology::applyJT ( typename In::MatrixDeriv& out, const typename Out::MatrixDeriv& in ) -{ - typename Out::MatrixDeriv::RowConstIterator rowItEnd = in.end(); - const helper::vector& quads = this->m_fromTopology->getQuads(); - - for (typename Out::MatrixDeriv::RowConstIterator rowIt = in.begin(); rowIt != rowItEnd; ++rowIt) - { - typename Out::MatrixDeriv::ColConstIterator colItEnd = rowIt.end(); - typename Out::MatrixDeriv::ColConstIterator colIt = rowIt.begin(); - - if (colIt != colItEnd) - { - typename In::MatrixDeriv::RowIterator o = out.writeLine(rowIt.index()); - - for ( ; colIt != colItEnd; ++colIt) - { - unsigned indexIn = colIt.index(); - InDeriv data = (InDeriv) Out::getDPos(colIt.val()); - - const Quad& quad = quads[d_map.getValue()[indexIn].in_index]; - - helper::vector baryCoef = getBaryCoef(d_map.getValue()[indexIn].baryCoords); - for (unsigned int j=0; j -void BarycentricMapperTetrahedronSetTopology::applyJT ( typename In::MatrixDeriv& out, const typename Out::MatrixDeriv& in ) -{ - typename Out::MatrixDeriv::RowConstIterator rowItEnd = in.end(); - const helper::vector& tetrahedra = this->m_fromTopology->getTetrahedra(); - - for (typename Out::MatrixDeriv::RowConstIterator rowIt = in.begin(); rowIt != rowItEnd; ++rowIt) - { - typename Out::MatrixDeriv::ColConstIterator colItEnd = rowIt.end(); - typename Out::MatrixDeriv::ColConstIterator colIt = rowIt.begin(); - - if (colIt != colItEnd) - { - typename In::MatrixDeriv::RowIterator o = out.writeLine(rowIt.index()); - - for ( ; colIt != colItEnd; ++colIt) - { - unsigned indexIn = colIt.index(); - InDeriv data = (InDeriv) Out::getDPos(colIt.val()); - - const Tetrahedron& tetra = tetrahedra[d_map.getValue()[indexIn].in_index]; - - helper::vector baryCoef = getBaryCoef(d_map.getValue()[indexIn].baryCoords); - for (unsigned int j=0; j -void BarycentricMapperHexahedronSetTopology::applyJT ( typename In::MatrixDeriv& out, const typename Out::MatrixDeriv& in ) +template +void BarycentricMapperTopologyContainer::applyJT ( typename In::MatrixDeriv& out, const typename Out::MatrixDeriv& in ) { typename Out::MatrixDeriv::RowConstIterator rowItEnd = in.end(); - const helper::vector< Hexahedron >& hexas = this->m_fromTopology->getHexahedra(); + const helper::vector< Element >& elements = getElements(); for (typename Out::MatrixDeriv::RowConstIterator rowIt = in.begin(); rowIt != rowItEnd; ++rowIt) { @@ -3014,11 +2337,11 @@ void BarycentricMapperHexahedronSetTopology::applyJT ( t unsigned indexIn = colIt.index(); InDeriv data = (InDeriv) Out::getDPos(colIt.val()); - const Hexahedron& hexa = hexas[d_map.getValue()[indexIn].in_index]; + const Element& element = elements[d_map.getValue()[indexIn].in_index]; helper::vector baryCoef = getBaryCoef(d_map.getValue()[indexIn].baryCoords); - for (unsigned int j=0; j::applyJT ( t /************************************* Topological Changes ***********************************/ -template -void BarycentricMapperHexahedronSetTopology::handleTopologyChange(core::topology::Topology* t) +template +void BarycentricMapperHexahedronSetTopology::handleTopologyChange(core::topology::Topology* t) { using sofa::core::behavior::MechanicalState; diff --git a/modules/SofaMiscMapping/BarycentricMappingRigid.cpp b/modules/SofaMiscMapping/BarycentricMappingRigid.cpp index 2e55c6c2e7e..f9af3c0371e 100644 --- a/modules/SofaMiscMapping/BarycentricMappingRigid.cpp +++ b/modules/SofaMiscMapping/BarycentricMappingRigid.cpp @@ -606,7 +606,7 @@ template class SOFA_MISC_MAPPING_API BarycentricMapperEdgeSetTopology< Vec3dType template class SOFA_MISC_MAPPING_API BarycentricMapperTriangleSetTopology< Vec3dTypes, Rigid3dTypes >; template class SOFA_MISC_MAPPING_API BarycentricMapperQuadSetTopology< Vec3dTypes, Rigid3dTypes >; template class SOFA_MISC_MAPPING_API BarycentricMapperTetrahedronSetTopologyRigid< Vec3dTypes, Rigid3dTypes >; -//template class SOFA_MISC_MAPPING_API BarycentricMapperTetrahedronSetTopology< Vec3dTypes, Rigid3dTypes >; +template class SOFA_MISC_MAPPING_API BarycentricMapperTetrahedronSetTopology< Vec3dTypes, Rigid3dTypes >; template class SOFA_MISC_MAPPING_API BarycentricMapperHexahedronSetTopology< Vec3dTypes, Rigid3dTypes >; #endif #ifndef SOFA_DOUBLE @@ -620,7 +620,7 @@ template class SOFA_MISC_MAPPING_API BarycentricMapperEdgeSetTopology< Vec3fType template class SOFA_MISC_MAPPING_API BarycentricMapperTriangleSetTopology< Vec3fTypes, Rigid3fTypes >; template class SOFA_MISC_MAPPING_API BarycentricMapperQuadSetTopology< Vec3fTypes, Rigid3fTypes >; template class SOFA_MISC_MAPPING_API BarycentricMapperTetrahedronSetTopologyRigid< Vec3fTypes, Rigid3fTypes >; -//template class SOFA_MISC_MAPPING_API BarycentricMapperTetrahedronSetTopology< Vec3fTypes, Rigid3fTypes >; +template class SOFA_MISC_MAPPING_API BarycentricMapperTetrahedronSetTopology< Vec3fTypes, Rigid3fTypes >; template class SOFA_MISC_MAPPING_API BarycentricMapperHexahedronSetTopology< Vec3fTypes, Rigid3fTypes >; #endif #ifndef SOFA_FLOAT @@ -642,9 +642,9 @@ template class SOFA_MISC_MAPPING_API BarycentricMapperTriangleSetTopology< Vec3f template class SOFA_MISC_MAPPING_API BarycentricMapperQuadSetTopology< Vec3dTypes, Rigid3fTypes >; template class SOFA_MISC_MAPPING_API BarycentricMapperQuadSetTopology< Vec3fTypes, Rigid3dTypes >; template class SOFA_MISC_MAPPING_API BarycentricMapperTetrahedronSetTopologyRigid< Vec3dTypes, Rigid3fTypes >; -//template class SOFA_MISC_MAPPING_API BarycentricMapperTetrahedronSetTopology< Vec3dTypes, Rigid3fTypes >; +template class SOFA_MISC_MAPPING_API BarycentricMapperTetrahedronSetTopology< Vec3dTypes, Rigid3fTypes >; template class SOFA_MISC_MAPPING_API BarycentricMapperTetrahedronSetTopologyRigid< Vec3fTypes, Rigid3dTypes >; -//template class SOFA_MISC_MAPPING_API BarycentricMapperTetrahedronSetTopology< Vec3fTypes, Rigid3dTypes >; +template class SOFA_MISC_MAPPING_API BarycentricMapperTetrahedronSetTopology< Vec3fTypes, Rigid3dTypes >; template class SOFA_MISC_MAPPING_API BarycentricMapperHexahedronSetTopology< Vec3dTypes, Rigid3fTypes >; template class SOFA_MISC_MAPPING_API BarycentricMapperHexahedronSetTopology< Vec3fTypes, Rigid3dTypes >; #endif diff --git a/modules/SofaMiscMapping/BarycentricMappingRigid.h b/modules/SofaMiscMapping/BarycentricMappingRigid.h index d510e774b4f..3f316780e3c 100644 --- a/modules/SofaMiscMapping/BarycentricMappingRigid.h +++ b/modules/SofaMiscMapping/BarycentricMappingRigid.h @@ -114,20 +114,20 @@ class BarycentricMapperTetrahedronSetTopologyRigid : public TopologyBarycentricM //virtual int addContactPointFromInputMapping(const typename In::VecDeriv& in, const sofa::defaulttype::Vector3& /*pos*/, std::vector< std::pair > & /*baryCoords*/); }; -//template -//class BarycentricMapperTetrahedronSetTopology< sofa::defaulttype::StdVectorTypes,sofa::defaulttype::Vec<3,TInReal>,TInReal>, sofa::defaulttype::StdRigidTypes<3,TOutReal> > : public BarycentricMapperTetrahedronSetTopologyRigid< sofa::defaulttype::StdVectorTypes,sofa::defaulttype::Vec<3,TInReal>,TInReal>, sofa::defaulttype::StdRigidTypes<3,TOutReal> > -//{ -//public: -// typedef sofa::defaulttype::StdVectorTypes,sofa::defaulttype::Vec<3,TInReal>,TInReal> In; -// typedef sofa::defaulttype::StdRigidTypes<3,TOutReal> Out; -// SOFA_CLASS(SOFA_TEMPLATE2(BarycentricMapperTetrahedronSetTopology,In,Out),SOFA_TEMPLATE2(BarycentricMapperTetrahedronSetTopologyRigid,In,Out)); -// typedef BarycentricMapperTetrahedronSetTopologyRigid Inherit; +template +class BarycentricMapperTetrahedronSetTopology< sofa::defaulttype::StdVectorTypes,sofa::defaulttype::Vec<3,TInReal>,TInReal>, sofa::defaulttype::StdRigidTypes<3,TOutReal> > : public BarycentricMapperTetrahedronSetTopologyRigid< sofa::defaulttype::StdVectorTypes,sofa::defaulttype::Vec<3,TInReal>,TInReal>, sofa::defaulttype::StdRigidTypes<3,TOutReal> > +{ +public: + typedef sofa::defaulttype::StdVectorTypes,sofa::defaulttype::Vec<3,TInReal>,TInReal> In; + typedef sofa::defaulttype::StdRigidTypes<3,TOutReal> Out; + SOFA_CLASS(SOFA_TEMPLATE2(BarycentricMapperTetrahedronSetTopology,In,Out),SOFA_TEMPLATE2(BarycentricMapperTetrahedronSetTopologyRigid,In,Out)); + typedef BarycentricMapperTetrahedronSetTopologyRigid Inherit; -// BarycentricMapperTetrahedronSetTopology(topology::TetrahedronSetTopologyContainer* fromTopology, topology::PointSetTopologyContainer* _toTopology) -// : Inherit(fromTopology, _toTopology) -// {} + BarycentricMapperTetrahedronSetTopology(topology::TetrahedronSetTopologyContainer* fromTopology, topology::PointSetTopologyContainer* _toTopology) + : Inherit(fromTopology, _toTopology) + {} -//}; +}; @@ -143,7 +143,7 @@ extern template class SOFA_MISC_MAPPING_API BarycentricMapperEdgeSetTopology< de extern template class SOFA_MISC_MAPPING_API BarycentricMapperTriangleSetTopology< defaulttype::Vec3dTypes, defaulttype::Rigid3dTypes >; extern template class SOFA_MISC_MAPPING_API BarycentricMapperQuadSetTopology< defaulttype::Vec3dTypes, defaulttype::Rigid3dTypes >; extern template class SOFA_MISC_MAPPING_API BarycentricMapperTetrahedronSetTopologyRigid< defaulttype::Vec3dTypes, defaulttype::Rigid3dTypes >; -//extern template class SOFA_MISC_MAPPING_API BarycentricMapperTetrahedronSetTopology< defaulttype::Vec3dTypes, defaulttype::Rigid3dTypes >; +extern template class SOFA_MISC_MAPPING_API BarycentricMapperTetrahedronSetTopology< defaulttype::Vec3dTypes, defaulttype::Rigid3dTypes >; extern template class SOFA_MISC_MAPPING_API BarycentricMapperHexahedronSetTopology< defaulttype::Vec3dTypes, defaulttype::Rigid3dTypes >; #endif #ifndef SOFA_DOUBLE @@ -157,7 +157,7 @@ extern template class SOFA_MISC_MAPPING_API BarycentricMapperEdgeSetTopology< de extern template class SOFA_MISC_MAPPING_API BarycentricMapperTriangleSetTopology< defaulttype::Vec3fTypes, defaulttype::Rigid3fTypes >; extern template class SOFA_MISC_MAPPING_API BarycentricMapperQuadSetTopology< defaulttype::Vec3fTypes, defaulttype::Rigid3fTypes >; extern template class SOFA_MISC_MAPPING_API BarycentricMapperTetrahedronSetTopologyRigid< defaulttype::Vec3fTypes, defaulttype::Rigid3fTypes >; -//extern template class SOFA_MISC_MAPPING_API BarycentricMapperTetrahedronSetTopology< defaulttype::Vec3fTypes, defaulttype::Rigid3fTypes >; +extern template class SOFA_MISC_MAPPING_API BarycentricMapperTetrahedronSetTopology< defaulttype::Vec3fTypes, defaulttype::Rigid3fTypes >; extern template class SOFA_MISC_MAPPING_API BarycentricMapperHexahedronSetTopology< defaulttype::Vec3fTypes, defaulttype::Rigid3fTypes >; #endif #ifndef SOFA_FLOAT @@ -181,9 +181,9 @@ extern template class SOFA_MISC_MAPPING_API BarycentricMapperTriangleSetTopology extern template class SOFA_MISC_MAPPING_API BarycentricMapperQuadSetTopology< defaulttype::Vec3dTypes, defaulttype::Rigid3fTypes >; extern template class SOFA_MISC_MAPPING_API BarycentricMapperQuadSetTopology< defaulttype::Vec3fTypes, defaulttype::Rigid3dTypes >; extern template class SOFA_MISC_MAPPING_API BarycentricMapperTetrahedronSetTopologyRigid< defaulttype::Vec3dTypes, defaulttype::Rigid3fTypes >; -//extern template class SOFA_MISC_MAPPING_API BarycentricMapperTetrahedronSetTopology< defaulttype::Vec3dTypes, defaulttype::Rigid3fTypes >; +extern template class SOFA_MISC_MAPPING_API BarycentricMapperTetrahedronSetTopology< defaulttype::Vec3dTypes, defaulttype::Rigid3fTypes >; extern template class SOFA_MISC_MAPPING_API BarycentricMapperTetrahedronSetTopologyRigid< defaulttype::Vec3fTypes, defaulttype::Rigid3dTypes >; -//extern template class SOFA_MISC_MAPPING_API BarycentricMapperTetrahedronSetTopology< defaulttype::Vec3fTypes, defaulttype::Rigid3dTypes >; +extern template class SOFA_MISC_MAPPING_API BarycentricMapperTetrahedronSetTopology< defaulttype::Vec3fTypes, defaulttype::Rigid3dTypes >; extern template class SOFA_MISC_MAPPING_API BarycentricMapperHexahedronSetTopology< defaulttype::Vec3dTypes, defaulttype::Rigid3fTypes >; extern template class SOFA_MISC_MAPPING_API BarycentricMapperHexahedronSetTopology< defaulttype::Vec3fTypes, defaulttype::Rigid3dTypes >; #endif From 7b183a22159bcc23286872789a6c59253ac6a23a Mon Sep 17 00:00:00 2001 From: eulaliecoevoet Date: Thu, 25 Oct 2018 13:33:17 +0200 Subject: [PATCH 03/15] [SofaBaseMechanics] revert highly breaking renaming (clear()) --- .../SofaBaseMechanics/BarycentricMapping.h | 10 +++++----- .../SofaBaseMechanics/BarycentricMapping.inl | 16 ++++++++-------- .../SofaMeshCollision/BarycentricContactMapper.h | 2 +- .../SofaMiscMapping/BarycentricMappingRigid.h | 2 +- .../SofaMiscMapping/BarycentricMappingRigid.inl | 4 ++-- 5 files changed, 17 insertions(+), 17 deletions(-) diff --git a/SofaKernel/modules/SofaBaseMechanics/BarycentricMapping.h b/SofaKernel/modules/SofaBaseMechanics/BarycentricMapping.h index e2aa9ce178c..6caf53b5b9c 100644 --- a/SofaKernel/modules/SofaBaseMechanics/BarycentricMapping.h +++ b/SofaKernel/modules/SofaBaseMechanics/BarycentricMapping.h @@ -192,7 +192,7 @@ class BarycentricMapper : public virtual core::objectmodel::BaseObject //-- - virtual void clearMapAndReserve( int reserve=0 ) =0; + virtual void clear( int reserve=0 ) =0; //Nothing to do inline friend std::istream& operator >> ( std::istream& in, BarycentricMapper< In, Out > & ) {return in;} @@ -310,7 +310,7 @@ class BarycentricMapperMeshTopology : public TopologyBarycentricMapper } public: - void clearMapAndReserve(int reserve=0) override; + void clear(int reserve=0) override; int addPointInLine(const int lineIndex, const SReal* baryCoords) override; int createPointInLine(const typename Out::Coord& p, int lineIndex, const typename In::VecCoord* points) override; @@ -442,7 +442,7 @@ class BarycentricMapperRegularGridTopology : public TopologyBarycentricMapperm_map.size() == 0;} void setTopology(topology::RegularGridTopology* _topology) {this->m_fromTopology = _topology;} @@ -523,7 +523,7 @@ class BarycentricMapperSparseGridTopology : public TopologyBarycentricMapper* toModel ) override; void apply( typename Out::VecCoord& out, const typename In::VecCoord& in ) override; diff --git a/SofaKernel/modules/SofaBaseMechanics/BarycentricMapping.inl b/SofaKernel/modules/SofaBaseMechanics/BarycentricMapping.inl index 2f03ac49667..4610bf2cc52 100644 --- a/SofaKernel/modules/SofaBaseMechanics/BarycentricMapping.inl +++ b/SofaKernel/modules/SofaBaseMechanics/BarycentricMapping.inl @@ -122,7 +122,7 @@ BarycentricMapping::~BarycentricMapping() template -void BarycentricMapperRegularGridTopology::clearMapAndReserve ( int size ) +void BarycentricMapperRegularGridTopology::clear ( int size ) { updateJ = true; m_map.clear(); @@ -148,7 +148,7 @@ void BarycentricMapperRegularGridTopology::init ( const typename Out::Ve updateJ = true; - clearMapAndReserve ( (int)out.size() ); + clear ( (int)out.size() ); if ( m_fromTopology->isVolume() ) { for ( unsigned int i=0; i::init ( const typename Out::Ve template -void BarycentricMapperSparseGridTopology::clearMapAndReserve ( int size ) +void BarycentricMapperSparseGridTopology::clear ( int size ) { updateJ = true; m_map.clear(); @@ -190,7 +190,7 @@ void BarycentricMapperSparseGridTopology::init ( const typename Out::Vec { if ( this->m_map.size() != 0 ) return; updateJ = true; - clearMapAndReserve ( (int)out.size() ); + clear ( (int)out.size() ); if ( m_fromTopology->isVolume() ) { @@ -235,7 +235,7 @@ void BarycentricMapperMeshTopology::clearMap3dAndReserve ( int size ) } template -void BarycentricMapperMeshTopology::clearMapAndReserve ( int size ) +void BarycentricMapperMeshTopology::clear ( int size ) { m_updateJ = true; clearMap1dAndReserve(size); @@ -571,7 +571,7 @@ void BarycentricMapperMeshTopology::init ( const typename Out::VecCoord& template -void BarycentricMapperTopologyContainer::clearMapAndReserve(int size) +void BarycentricMapperTopologyContainer::clear(int size) { helper::vector& vectorData = *(d_map.beginEdit()); vectorData.clear(); @@ -726,7 +726,7 @@ void BarycentricMapperTopologyContainer::init ( helper::vector bases; helper::vector centers; - this->clearMapAndReserve ( (int)out.size() ); + this->clear ( (int)out.size() ); bases.resize ( elements.size() ); centers.resize ( elements.size() ); @@ -911,7 +911,7 @@ void BarycentricMapping::reinit() { if ( m_mapper != NULL ) { - m_mapper->clearMapAndReserve(); + m_mapper->clear(); m_mapper->init (((const core::State *)this->toModel)->read(core::ConstVecCoordId::position())->getValue(), ((const core::State *)this->fromModel)->read(core::ConstVecCoordId::position())->getValue() ); } } diff --git a/SofaKernel/modules/SofaMeshCollision/BarycentricContactMapper.h b/SofaKernel/modules/SofaMeshCollision/BarycentricContactMapper.h index d912649e342..342d900ffa0 100644 --- a/SofaKernel/modules/SofaMeshCollision/BarycentricContactMapper.h +++ b/SofaKernel/modules/SofaMeshCollision/BarycentricContactMapper.h @@ -88,7 +88,7 @@ class BarycentricContactMapper : public BaseContactMapper { if (mapping!=NULL) { - mapper->clearMapAndReserve(); + mapper->clear(); mapping->getMechTo()[0]->resize(size); } } diff --git a/modules/SofaMiscMapping/BarycentricMappingRigid.h b/modules/SofaMiscMapping/BarycentricMappingRigid.h index 3f316780e3c..47c85572e95 100644 --- a/modules/SofaMiscMapping/BarycentricMappingRigid.h +++ b/modules/SofaMiscMapping/BarycentricMappingRigid.h @@ -94,7 +94,7 @@ class BarycentricMapperTetrahedronSetTopologyRigid : public TopologyBarycentricM virtual ~BarycentricMapperTetrahedronSetTopologyRigid() {} public: - void clearMapAndReserve(int reserve=0) override; + void clear(int reserve=0) override; int addPointInTetra(const int index, const SReal* baryCoords) override; int addPointOrientationInTetra( const int tetraIndex, const sofa::defaulttype::Matrix3 baryCoorsOrient ); diff --git a/modules/SofaMiscMapping/BarycentricMappingRigid.inl b/modules/SofaMiscMapping/BarycentricMappingRigid.inl index 8778e9509cd..88aa46281b8 100644 --- a/modules/SofaMiscMapping/BarycentricMappingRigid.inl +++ b/modules/SofaMiscMapping/BarycentricMappingRigid.inl @@ -38,7 +38,7 @@ namespace mapping template -void BarycentricMapperTetrahedronSetTopologyRigid::clearMapAndReserve ( int reserve ) +void BarycentricMapperTetrahedronSetTopologyRigid::clear ( int reserve ) { helper::vector& vectorData = *(map.beginEdit()); @@ -107,7 +107,7 @@ void BarycentricMapperTetrahedronSetTopologyRigid::init(const typename O sofa::helper::vector bases; sofa::helper::vector centers; - clearMapAndReserve ( out.size() ); + clear ( out.size() ); bases.resize ( tetrahedra.size() ); centers.resize ( tetrahedra.size() ); for ( unsigned int t = 0; t < tetrahedra.size(); t++ ) From bdf14cdeb042d887677889faed145bc37ba69b58 Mon Sep 17 00:00:00 2001 From: eulaliecoevoet Date: Wed, 14 Nov 2018 13:21:17 +0100 Subject: [PATCH 04/15] [SofaCUDA] fixed compile, following cleaning of BarycentricMapping --- .../gpu/cuda/CudaBarycentricMapping-3f.cpp | 2 +- .../cuda/CudaBarycentricMapping-3f1-3f.cpp | 4 +- .../gpu/cuda/CudaBarycentricMapping-3f1.cpp | 2 +- .../gpu/cuda/CudaBarycentricMappingRigid.cpp | 50 +++++++++---------- 4 files changed, 29 insertions(+), 29 deletions(-) diff --git a/applications/plugins/SofaCUDA/sofa/gpu/cuda/CudaBarycentricMapping-3f.cpp b/applications/plugins/SofaCUDA/sofa/gpu/cuda/CudaBarycentricMapping-3f.cpp index ae5a959f7ee..4b1594e6dfa 100644 --- a/applications/plugins/SofaCUDA/sofa/gpu/cuda/CudaBarycentricMapping-3f.cpp +++ b/applications/plugins/SofaCUDA/sofa/gpu/cuda/CudaBarycentricMapping-3f.cpp @@ -157,7 +157,7 @@ void BarycentricMapperSparseGridTopology::applyJT unsigned indexIn = colIt.index(); InDeriv data = (InDeriv) Out::getDPos(colIt.val()); - const topology::SparseGridTopology::Hexa cube = this->fromTopology->getHexahedron ( map[indexIn].in_index ); + const topology::SparseGridTopology::Hexa cube = this->m_fromTopology->getHexahedron ( map[indexIn].in_index ); const OutReal fx = ( OutReal ) map[indexIn].baryCoords[0]; const OutReal fy = ( OutReal ) map[indexIn].baryCoords[1]; diff --git a/applications/plugins/SofaCUDA/sofa/gpu/cuda/CudaBarycentricMapping-3f1-3f.cpp b/applications/plugins/SofaCUDA/sofa/gpu/cuda/CudaBarycentricMapping-3f1-3f.cpp index a36af3184f5..f8eed11960a 100644 --- a/applications/plugins/SofaCUDA/sofa/gpu/cuda/CudaBarycentricMapping-3f1-3f.cpp +++ b/applications/plugins/SofaCUDA/sofa/gpu/cuda/CudaBarycentricMapping-3f1-3f.cpp @@ -187,7 +187,7 @@ void BarycentricMapperSparseGridTopology::applyJ unsigned indexIn = colIt.index(); InDeriv data = (InDeriv) Out::getDPos(colIt.val()); - const topology::SparseGridTopology::Hexa cube = this->fromTopology->getHexahedron ( map[indexIn].in_index ); + const topology::SparseGridTopology::Hexa cube = this->m_fromTopology->getHexahedron ( map[indexIn].in_index ); const OutReal fx = ( OutReal ) map[indexIn].baryCoords[0]; const OutReal fy = ( OutReal ) map[indexIn].baryCoords[1]; @@ -280,7 +280,7 @@ void BarycentricMapperSparseGridTopology::applyJ unsigned indexIn = colIt.index(); InDeriv data = (InDeriv) Out::getDPos(colIt.val()); - const topology::SparseGridTopology::Hexa cube = this->fromTopology->getHexahedron ( map[indexIn].in_index ); + const topology::SparseGridTopology::Hexa cube = this->m_fromTopology->getHexahedron ( map[indexIn].in_index ); const OutReal fx = ( OutReal ) map[indexIn].baryCoords[0]; const OutReal fy = ( OutReal ) map[indexIn].baryCoords[1]; diff --git a/applications/plugins/SofaCUDA/sofa/gpu/cuda/CudaBarycentricMapping-3f1.cpp b/applications/plugins/SofaCUDA/sofa/gpu/cuda/CudaBarycentricMapping-3f1.cpp index 809a15cbe50..17ecc4de544 100644 --- a/applications/plugins/SofaCUDA/sofa/gpu/cuda/CudaBarycentricMapping-3f1.cpp +++ b/applications/plugins/SofaCUDA/sofa/gpu/cuda/CudaBarycentricMapping-3f1.cpp @@ -386,7 +386,7 @@ void BarycentricMapperSparseGridTopology::apply unsigned indexIn = colIt.index(); InDeriv data = (InDeriv) Out::getDPos(colIt.val()); - const topology::SparseGridTopology::Hexa cube = this->fromTopology->getHexahedron ( map[indexIn].in_index ); + const topology::SparseGridTopology::Hexa cube = this->m_fromTopology->getHexahedron ( map[indexIn].in_index ); const OutReal fx = ( OutReal ) map[indexIn].baryCoords[0]; const OutReal fy = ( OutReal ) map[indexIn].baryCoords[1]; diff --git a/applications/plugins/SofaCUDA/sofa/gpu/cuda/CudaBarycentricMappingRigid.cpp b/applications/plugins/SofaCUDA/sofa/gpu/cuda/CudaBarycentricMappingRigid.cpp index 6d186baf15b..64b41e082b1 100644 --- a/applications/plugins/SofaCUDA/sofa/gpu/cuda/CudaBarycentricMappingRigid.cpp +++ b/applications/plugins/SofaCUDA/sofa/gpu/cuda/CudaBarycentricMappingRigid.cpp @@ -67,12 +67,12 @@ int BarycentricMappingRigidClass = core::RegisterObject("") template <> void BarycentricMapperHexahedronSetTopology::handleTopologyChange(core::topology::Topology* t) { - if (t != this->fromTopology) return; - if ( this->fromTopology->beginChange() == this->fromTopology->endChange() ) + if (t != this->m_fromTopology) return; + if ( this->m_fromTopology->beginChange() == this->m_fromTopology->endChange() ) return; - std::list::const_iterator itBegin = this->fromTopology->beginChange(); - std::list::const_iterator itEnd = this->fromTopology->endChange(); + std::list::const_iterator itBegin = this->m_fromTopology->beginChange(); + std::list::const_iterator itEnd = this->m_fromTopology->endChange(); for ( std::list::const_iterator changeIt = itBegin; changeIt != itEnd; ++changeIt ) @@ -83,12 +83,12 @@ void BarycentricMapperHexahedronSetTopology::handleTopologyChange() case core::topology::ENDING_EVENT: ///< To notify the end for the current sequence of topological change events { - if(!_invalidIndex.empty()) + if(!m_invalidIndex.empty()) { - helper::vector& mapData = *(map.beginEdit()); + helper::vector& mapData = *(d_map.beginEdit()); - for ( std::set::const_iterator iter = _invalidIndex.begin(); - iter != _invalidIndex.end(); ++iter ) + for ( std::set::const_iterator iter = m_invalidIndex.begin(); + iter != m_invalidIndex.end(); ++iter ) { const int j = *iter; if ( mapData[j].in_index == -1 ) // compute new mapping @@ -103,7 +103,7 @@ void BarycentricMapperHexahedronSetTopologyfindNearestElementInRestPos ( pos, coefs, distance ); + int index = m_fromGeomAlgo->findNearestElementInRestPos ( pos, coefs, distance ); if ( index != -1 ) { @@ -115,8 +115,8 @@ void BarycentricMapperHexahedronSetTopologyfromTopology->getNbHexahedra(); + const unsigned int nbHexahedra = this->m_fromTopology->getNbHexahedra(); const sofa::helper::vector &hexahedra = ( static_cast< const core::topology::HexahedraRemoved *> ( *changeIt ) )->getArray(); // sofa::helper::vector hexahedra(tab); @@ -148,25 +148,25 @@ void BarycentricMapperHexahedronSetTopologygetRestPointPositionInHexahedron ( cubeId, coefs ); + defaulttype::Vec3dTypes::Coord restPos = m_fromGeomAlgo->getRestPointPositionInHexahedron ( cubeId, coefs ); - helper::vector& vectorData = *(map.beginEdit()); + helper::vector& vectorData = *(d_map.beginEdit()); vectorData[j].in_index = -1; vectorData[j].baryCoords[0] = restPos[0]; vectorData[j].baryCoords[1] = restPos[1]; vectorData[j].baryCoords[2] = restPos[2]; - map.endEdit(); + d_map.endEdit(); - _invalidIndex.insert(j); + m_invalidIndex.insert(j); } } } @@ -176,13 +176,13 @@ void BarycentricMapperHexahedronSetTopology& vectorData = *(map.beginEdit()); + helper::vector& vectorData = *(d_map.beginEdit()); vectorData[j].in_index = cubeId; - map.endEdit(); + d_map.endEdit(); } } } From 033428d350722865022368b5696d5eeb8c3b2d8e Mon Sep 17 00:00:00 2001 From: COEVOET Eulalie Date: Wed, 14 Nov 2018 22:08:48 +0100 Subject: [PATCH 05/15] [SofaBaseMechanics] fixed compile with clang and minor cleaning --- .../SofaBaseMechanics/BarycentricMapping.h | 328 +++++++++--------- .../SofaBaseMechanics/BarycentricMapping.inl | 52 +-- 2 files changed, 185 insertions(+), 195 deletions(-) diff --git a/SofaKernel/modules/SofaBaseMechanics/BarycentricMapping.h b/SofaKernel/modules/SofaBaseMechanics/BarycentricMapping.h index 6caf53b5b9c..09ac6b87187 100644 --- a/SofaKernel/modules/SofaBaseMechanics/BarycentricMapping.h +++ b/SofaKernel/modules/SofaBaseMechanics/BarycentricMapping.h @@ -164,7 +164,7 @@ class BarycentricMapper : public virtual core::objectmodel::BaseObject protected: BarycentricMapper() {} - virtual ~BarycentricMapper() {} + virtual ~BarycentricMapper() override {} private: BarycentricMapper(const BarycentricMapper& n) ; @@ -208,15 +208,14 @@ class TopologyBarycentricMapper : public BarycentricMapper public: SOFA_CLASS(SOFA_TEMPLATE2(TopologyBarycentricMapper,In,Out),SOFA_TEMPLATE2(BarycentricMapper,In,Out)); - typedef BarycentricMapper Inherit; - typedef typename Inherit::Real Real; + typedef typename Inherit1::Real Real; typedef typename core::behavior::BaseMechanicalState::ForceMask ForceMask; ForceMask *maskFrom; ForceMask *maskTo; protected: - virtual ~TopologyBarycentricMapper() {} + virtual ~TopologyBarycentricMapper() override {} public: virtual int addPointInLine(const int /*lineIndex*/, const SReal* /*baryCoords*/) {return 0;} @@ -266,28 +265,27 @@ class BarycentricMapperMeshTopology : public TopologyBarycentricMapper public: SOFA_CLASS(SOFA_TEMPLATE2(BarycentricMapperMeshTopology,In,Out),SOFA_TEMPLATE2(TopologyBarycentricMapper,In,Out)); - typedef TopologyBarycentricMapper Inherit; - typedef typename Inherit::Real Real; - typedef typename Inherit::OutReal OutReal; - typedef typename Inherit::OutDeriv OutDeriv; + typedef typename Inherit1::Real Real; + typedef typename Inherit1::OutReal OutReal; + typedef typename Inherit1::OutDeriv OutDeriv; - typedef typename Inherit::InDeriv InDeriv; - typedef typename Inherit::MappingData1D MappingData1D; - typedef typename Inherit::MappingData2D MappingData2D; - typedef typename Inherit::MappingData3D MappingData3D; + typedef typename Inherit1::InDeriv InDeriv; + typedef typename Inherit1::MappingData1D MappingData1D; + typedef typename Inherit1::MappingData2D MappingData2D; + typedef typename Inherit1::MappingData3D MappingData3D; - enum { NIn = Inherit::NIn }; - enum { NOut = Inherit::NOut }; - typedef typename Inherit::MBloc MBloc; - typedef typename Inherit::MatrixType MatrixType; + enum { NIn = Inherit1::NIn }; + enum { NOut = Inherit1::NOut }; + typedef typename Inherit1::MBloc MBloc; + typedef typename Inherit1::MatrixType MatrixType; typedef typename MatrixType::Index MatrixTypeIndex; - typedef typename Inherit::ForceMask ForceMask; + typedef typename Inherit1::ForceMask ForceMask; protected: void addMatrixContrib(MatrixType* m, int row, int col, Real value) { - Inherit::addMatrixContrib(m, row, col, value); + Inherit1::addMatrixContrib(m, row, col, value); } sofa::helper::vector< MappingData1D > m_map1d; @@ -304,35 +302,35 @@ class BarycentricMapperMeshTopology : public TopologyBarycentricMapper { } - virtual ~BarycentricMapperMeshTopology() + virtual ~BarycentricMapperMeshTopology() override { if (m_matrixJ) delete m_matrixJ; } public: - void clear(int reserve=0) override; + virtual void clear(int reserve=0) override; - int addPointInLine(const int lineIndex, const SReal* baryCoords) override; - int createPointInLine(const typename Out::Coord& p, int lineIndex, const typename In::VecCoord* points) override; + virtual int addPointInLine(const int lineIndex, const SReal* baryCoords) override; + virtual int createPointInLine(const typename Out::Coord& p, int lineIndex, const typename In::VecCoord* points) override; - int addPointInTriangle(const int triangleIndex, const SReal* baryCoords) override; - int createPointInTriangle(const typename Out::Coord& p, int triangleIndex, const typename In::VecCoord* points) override; + virtual int addPointInTriangle(const int triangleIndex, const SReal* baryCoords) override; + virtual int createPointInTriangle(const typename Out::Coord& p, int triangleIndex, const typename In::VecCoord* points) override; - int addPointInQuad(const int quadIndex, const SReal* baryCoords) override; - int createPointInQuad(const typename Out::Coord& p, int quadIndex, const typename In::VecCoord* points) override; + virtual int addPointInQuad(const int quadIndex, const SReal* baryCoords) override; + virtual int createPointInQuad(const typename Out::Coord& p, int quadIndex, const typename In::VecCoord* points) override; - int addPointInTetra(const int tetraIndex, const SReal* baryCoords) override; + virtual int addPointInTetra(const int tetraIndex, const SReal* baryCoords) override; - int addPointInCube(const int cubeIndex, const SReal* baryCoords) override; + virtual int addPointInCube(const int cubeIndex, const SReal* baryCoords) override; - void init(const typename Out::VecCoord& out, const typename In::VecCoord& in) override; + virtual void init(const typename Out::VecCoord& out, const typename In::VecCoord& in) override; - void apply( typename Out::VecCoord& out, const typename In::VecCoord& in ) override; - void applyJ( typename Out::VecDeriv& out, const typename In::VecDeriv& in ) override; - void applyJT( typename In::VecDeriv& out, const typename Out::VecDeriv& in ) override; - void applyJT( typename In::MatrixDeriv& out, const typename Out::MatrixDeriv& in ) override; - const sofa::defaulttype::BaseMatrix* getJ(int outSize, int inSize) override; - void draw(const core::visual::VisualParams*,const typename Out::VecCoord& out, const typename In::VecCoord& in) override; + virtual void apply( typename Out::VecCoord& out, const typename In::VecCoord& in ) override; + virtual void applyJ( typename Out::VecDeriv& out, const typename In::VecDeriv& in ) override; + virtual void applyJT( typename In::VecDeriv& out, const typename Out::VecDeriv& in ) override; + virtual void applyJT( typename In::MatrixDeriv& out, const typename Out::MatrixDeriv& in ) override; + virtual const sofa::defaulttype::BaseMatrix* getJ(int outSize, int inSize) override; + virtual void draw(const core::visual::VisualParams*,const typename Out::VecCoord& out, const typename In::VecCoord& in) override; virtual void resize( core::State* toModel ) override; sofa::helper::vector< MappingData3D > const* getMap3d() const { return &m_map3d; } @@ -402,25 +400,24 @@ class BarycentricMapperRegularGridTopology : public TopologyBarycentricMapper Inherit; - typedef typename Inherit::Real Real; - typedef typename Inherit::OutReal OutReal; - typedef typename Inherit::OutDeriv OutDeriv; - typedef typename Inherit::InDeriv InDeriv; - typedef typename Inherit::CubeData CubeData; - - enum { NIn = Inherit::NIn }; - enum { NOut = Inherit::NOut }; - typedef typename Inherit::MBloc MBloc; - typedef typename Inherit::MatrixType MatrixType; + typedef typename Inherit1::Real Real; + typedef typename Inherit1::OutReal OutReal; + typedef typename Inherit1::OutDeriv OutDeriv; + typedef typename Inherit1::InDeriv InDeriv; + typedef typename Inherit1::CubeData CubeData; + + enum { NIn = Inherit1::NIn }; + enum { NOut = Inherit1::NOut }; + typedef typename Inherit1::MBloc MBloc; + typedef typename Inherit1::MatrixType MatrixType; typedef typename MatrixType::Index MatrixTypeIndex; - typedef typename Inherit::ForceMask ForceMask; + typedef typename Inherit1::ForceMask ForceMask; protected: void addMatrixContrib(MatrixType* m, int row, int col, Real value) { - Inherit::addMatrixContrib(m, row, col, value); + Inherit1::addMatrixContrib(m, row, col, value); } sofa::helper::vector m_map; @@ -431,32 +428,32 @@ class BarycentricMapperRegularGridTopology : public TopologyBarycentricMapperm_map.size() == 0;} void setTopology(topology::RegularGridTopology* _topology) {this->m_fromTopology = _topology;} topology::RegularGridTopology *getTopology() {return dynamic_cast(this->m_fromTopology);} - int addPointInCube(const int cubeIndex, const SReal* baryCoords) override; + virtual int addPointInCube(const int cubeIndex, const SReal* baryCoords) override; - void init(const typename Out::VecCoord& out, const typename In::VecCoord& in) override; - void apply( typename Out::VecCoord& out, const typename In::VecCoord& in ) override; - void applyJ( typename Out::VecDeriv& out, const typename In::VecDeriv& in ) override; - void applyJT( typename In::VecDeriv& out, const typename Out::VecDeriv& in ) override; - void applyJT( typename In::MatrixDeriv& out, const typename Out::MatrixDeriv& in ) override; - const sofa::defaulttype::BaseMatrix* getJ(int outSize, int inSize) override; - void draw(const core::visual::VisualParams*,const typename Out::VecCoord& out, const typename In::VecCoord& in) override; + virtual void init(const typename Out::VecCoord& out, const typename In::VecCoord& in) override; + virtual void apply( typename Out::VecCoord& out, const typename In::VecCoord& in ) override; + virtual void applyJ( typename Out::VecDeriv& out, const typename In::VecDeriv& in ) override; + virtual void applyJT( typename In::VecDeriv& out, const typename Out::VecDeriv& in ) override; + virtual void applyJT( typename In::MatrixDeriv& out, const typename Out::MatrixDeriv& in ) override; + virtual const sofa::defaulttype::BaseMatrix* getJ(int outSize, int inSize) override; + virtual void draw(const core::visual::VisualParams*,const typename Out::VecCoord& out, const typename In::VecCoord& in) override; virtual void resize( core::State* toModel ) override; inline friend std::istream& operator >> ( std::istream& in, BarycentricMapperRegularGridTopology &b ) @@ -481,26 +478,25 @@ class BarycentricMapperSparseGridTopology : public TopologyBarycentricMapper Inherit; - typedef typename Inherit::Real Real; - typedef typename Inherit::OutReal OutReal; - typedef typename Inherit::OutDeriv OutDeriv; - typedef typename Inherit::InDeriv InDeriv; - - typedef typename Inherit::CubeData CubeData; - - enum { NIn = Inherit::NIn }; - enum { NOut = Inherit::NOut }; - typedef typename Inherit::MBloc MBloc; - typedef typename Inherit::MatrixType MatrixType; + typedef typename Inherit1::Real Real; + typedef typename Inherit1::OutReal OutReal; + typedef typename Inherit1::OutDeriv OutDeriv; + typedef typename Inherit1::InDeriv InDeriv; + + typedef typename Inherit1::CubeData CubeData; + + enum { NIn = Inherit1::NIn }; + enum { NOut = Inherit1::NOut }; + typedef typename Inherit1::MBloc MBloc; + typedef typename Inherit1::MatrixType MatrixType; typedef typename MatrixType::Index MatrixTypeIndex; - typedef typename Inherit::ForceMask ForceMask; + typedef typename Inherit1::ForceMask ForceMask; protected: void addMatrixContrib(MatrixType* m, int row, int col, Real value) { - Inherit::addMatrixContrib(m, row, col, value); + Inherit1::addMatrixContrib(m, row, col, value); } sofa::helper::vector m_map; @@ -517,7 +513,7 @@ class BarycentricMapperSparseGridTopology : public TopologyBarycentricMapper Inherit; - typedef typename Inherit::Real Real; - typedef typename Inherit::OutReal OutReal; - typedef typename Inherit::OutDeriv OutDeriv; - typedef typename Inherit::InDeriv InDeriv; + typedef typename Inherit1::Real Real; + typedef typename Inherit1::OutReal OutReal; + typedef typename Inherit1::OutDeriv OutDeriv; + typedef typename Inherit1::InDeriv InDeriv; - typedef typename Inherit::MBloc MBloc; - typedef typename Inherit::MatrixType MatrixType; + typedef typename Inherit1::MBloc MBloc; + typedef typename Inherit1::MatrixType MatrixType; - typedef typename Inherit::ForceMask ForceMask; + typedef typename Inherit1::ForceMask ForceMask; typedef typename MatrixType::Index MatrixTypeIndex; - enum { NIn = Inherit::NIn }; - enum { NOut = Inherit::NOut }; + enum { NIn = Inherit1::NIn }; + enum { NOut = Inherit1::NOut }; protected: topology::PointData< helper::vector > d_map; @@ -591,13 +586,13 @@ class BarycentricMapperTopologyContainer : public TopologyBarycentricMapper* toModel ) override; - void apply( typename Out::VecCoord& out, const typename In::VecCoord& in ) override; - void applyJ( typename Out::VecDeriv& out, const typename In::VecDeriv& in ) override; - void applyJT( typename In::VecDeriv& out, const typename Out::VecDeriv& in ) override; - void applyJT( typename In::MatrixDeriv& out, const typename Out::MatrixDeriv& in ) override; + virtual void apply( typename Out::VecCoord& out, const typename In::VecCoord& in ) override; + virtual void applyJ( typename Out::VecDeriv& out, const typename In::VecDeriv& in ) override; + virtual void applyJT( typename In::VecDeriv& out, const typename Out::VecDeriv& in ) override; + virtual void applyJT( typename In::MatrixDeriv& out, const typename Out::MatrixDeriv& in ) override; virtual const sofa::defaulttype::BaseMatrix* getJ(int outSize, int inSize) override; virtual void init(const typename Out::VecCoord& out, const typename In::VecCoord& in) override; - void draw(const core::visual::VisualParams*,const typename Out::VecCoord& out, const typename In::VecCoord& in) override; + virtual void draw(const core::visual::VisualParams*,const typename Out::VecCoord& out, const typename In::VecCoord& in) override; inline friend std::istream& operator >> ( std::istream& in, BarycentricMapperTopologyContainer &b ) { @@ -659,33 +654,32 @@ class BarycentricMapperTopologyContainer : public TopologyBarycentricMapper::MappingData1D, class Element = Edge> -class BarycentricMapperEdgeSetTopology : public BarycentricMapperTopologyContainer +template +class BarycentricMapperEdgeSetTopology : public BarycentricMapperTopologyContainer::MappingData1D,Edge> { + typedef typename BarycentricMapper::MappingData1D MappingData; public: - SOFA_CLASS(SOFA_TEMPLATE4(BarycentricMapperEdgeSetTopology,In,Out,MappingDataType,Element),SOFA_TEMPLATE4(BarycentricMapperTopologyContainer,In,Out,MappingDataType,Element)); - typedef MappingDataType MappingData; - typedef BarycentricMapperTopologyContainer Inherit; - typedef typename Inherit::Real Real; + SOFA_CLASS(SOFA_TEMPLATE2(BarycentricMapperEdgeSetTopology,In,Out),SOFA_TEMPLATE4(BarycentricMapperTopologyContainer,In,Out,MappingData,Edge)); + typedef typename Inherit1::Real Real; protected: topology::EdgeSetTopologyContainer* m_fromContainer; topology::EdgeSetGeometryAlgorithms* m_fromGeomAlgo; - using Inherit::d_map; - using Inherit::m_fromTopology; - using Inherit::m_matrixJ; - using Inherit::m_updateJ; + using Inherit1::d_map; + using Inherit1::m_fromTopology; + using Inherit1::m_matrixJ; + using Inherit1::m_updateJ; BarycentricMapperEdgeSetTopology(topology::EdgeSetTopologyContainer* fromTopology, topology::PointSetTopologyContainer* toTopology) - : Inherit(fromTopology, toTopology), + : Inherit1(fromTopology, toTopology), m_fromContainer(fromTopology), m_fromGeomAlgo(NULL) {} - virtual ~BarycentricMapperEdgeSetTopology() {} + virtual ~BarycentricMapperEdgeSetTopology() override {} - virtual helper::vector getElements() override + virtual helper::vector getElements() override { return this->m_fromTopology->getEdges(); } @@ -701,7 +695,7 @@ class BarycentricMapperEdgeSetTopology : public BarycentricMapperTopologyContain return edgeCoef; } - virtual void computeBase(Mat3x3d& base, const typename In::VecCoord& in, const Element& element) override + virtual void computeBase(Mat3x3d& base, const typename In::VecCoord& in, const Edge& element) override { //Not implemented for Edge SOFA_UNUSED(base); @@ -709,7 +703,7 @@ class BarycentricMapperEdgeSetTopology : public BarycentricMapperTopologyContain SOFA_UNUSED(element); } - virtual void computeCenter(Vector3& center, const typename In::VecCoord& in, const Element& element) override + virtual void computeCenter(Vector3& center, const typename In::VecCoord& in, const Edge& element) override { center = (in[element[0]]+in[element[1]])*0.5; } @@ -741,34 +735,33 @@ class BarycentricMapperEdgeSetTopology : public BarycentricMapperTopologyContain /// Class allowing barycentric mapping computation on a TriangleSetTopology -template::MappingData2D, class Element = Triangle> -class BarycentricMapperTriangleSetTopology : public BarycentricMapperTopologyContainer +template +class BarycentricMapperTriangleSetTopology : public BarycentricMapperTopologyContainer::MappingData2D,Triangle> { + typedef typename BarycentricMapper::MappingData2D MappingData; public: - SOFA_CLASS(SOFA_TEMPLATE4(BarycentricMapperTriangleSetTopology,In,Out,MappingDataType,Element),SOFA_TEMPLATE4(BarycentricMapperTopologyContainer,In,Out,MappingDataType,Element)); - typedef MappingDataType MappingData; - typedef BarycentricMapperTopologyContainer Inherit; - typedef typename Inherit::Real Real; + SOFA_CLASS(SOFA_TEMPLATE2(BarycentricMapperTriangleSetTopology,In,Out),SOFA_TEMPLATE4(BarycentricMapperTopologyContainer,In,Out,MappingData,Triangle)); + typedef typename Inherit1::Real Real; protected: topology::TriangleSetTopologyContainer* m_fromContainer; topology::TriangleSetGeometryAlgorithms* m_fromGeomAlgo; - using Inherit::d_map; - using Inherit::m_fromTopology; - using Inherit::m_matrixJ; - using Inherit::m_updateJ; + using Inherit1::d_map; + using Inherit1::m_fromTopology; + using Inherit1::m_matrixJ; + using Inherit1::m_updateJ; BarycentricMapperTriangleSetTopology(topology::TriangleSetTopologyContainer* fromTopology, topology::PointSetTopologyContainer* toTopology) - : Inherit(fromTopology, toTopology), + : Inherit1(fromTopology, toTopology), m_fromContainer(fromTopology), m_fromGeomAlgo(NULL) {} - virtual ~BarycentricMapperTriangleSetTopology() {} + virtual ~BarycentricMapperTriangleSetTopology() override {} - virtual helper::vector getElements() override + virtual helper::vector getElements() override { return this->m_fromTopology->getTriangles(); } @@ -784,7 +777,7 @@ class BarycentricMapperTriangleSetTopology : public BarycentricMapperTopologyCon return triangleCoef; } - virtual void computeBase(Mat3x3d& base, const typename In::VecCoord& in, const Element& element) override + virtual void computeBase(Mat3x3d& base, const typename In::VecCoord& in, const Triangle& element) override { Mat3x3d mt; base[0] = in[element[1]]-in[element[0]]; @@ -794,7 +787,7 @@ class BarycentricMapperTriangleSetTopology : public BarycentricMapperTopologyCon base.invert(mt); } - virtual void computeCenter(Vector3& center, const typename In::VecCoord& in, const Element& element) override + virtual void computeCenter(Vector3& center, const typename In::VecCoord& in, const Triangle& element) override { center = (in[element[0]]+in[element[1]]+in[element[2]])/3; } @@ -823,34 +816,33 @@ class BarycentricMapperTriangleSetTopology : public BarycentricMapperTopologyCon /// Class allowing barycentric mapping computation on a QuadSetTopology -template::MappingData2D, class Element = Quad> -class BarycentricMapperQuadSetTopology : public BarycentricMapperTopologyContainer +template +class BarycentricMapperQuadSetTopology : public BarycentricMapperTopologyContainer::MappingData2D, Quad> { + typedef typename BarycentricMapper::MappingData2D MappingData; public: - SOFA_CLASS(SOFA_TEMPLATE4(BarycentricMapperQuadSetTopology,In,Out,MappingDataType,Element),SOFA_TEMPLATE4(BarycentricMapperTopologyContainer,In,Out,MappingDataType,Element)); - typedef MappingDataType MappingData; - typedef BarycentricMapperTopologyContainer Inherit; - typedef typename Inherit::Real Real; + SOFA_CLASS(SOFA_TEMPLATE2(BarycentricMapperQuadSetTopology,In,Out),SOFA_TEMPLATE4(BarycentricMapperTopologyContainer,In,Out,MappingData,Quad)); + typedef typename Inherit1::Real Real; protected: topology::QuadSetTopologyContainer* m_fromContainer; topology::QuadSetGeometryAlgorithms* m_fromGeomAlgo; - using Inherit::d_map; - using Inherit::m_fromTopology; - using Inherit::m_matrixJ; - using Inherit::m_updateJ; + using Inherit1::d_map; + using Inherit1::m_fromTopology; + using Inherit1::m_matrixJ; + using Inherit1::m_updateJ; BarycentricMapperQuadSetTopology(topology::QuadSetTopologyContainer* fromTopology, topology::PointSetTopologyContainer* toTopology) - : Inherit(fromTopology, toTopology), + : Inherit1(fromTopology, toTopology), m_fromContainer(fromTopology), m_fromGeomAlgo(NULL) {} - virtual ~BarycentricMapperQuadSetTopology() {} + virtual ~BarycentricMapperQuadSetTopology() override {} - virtual helper::vector getElements() override + virtual helper::vector getElements() override { return this->m_fromTopology->getQuads(); } @@ -869,7 +861,7 @@ class BarycentricMapperQuadSetTopology : public BarycentricMapperTopologyContain return quadCoef; } - virtual void computeBase(Mat3x3d& base, const typename In::VecCoord& in, const Element& element) override + virtual void computeBase(Mat3x3d& base, const typename In::VecCoord& in, const Quad& element) override { Mat3x3d matrixTranspose; base[0] = in[element[1]]-in[element[0]]; @@ -879,7 +871,7 @@ class BarycentricMapperQuadSetTopology : public BarycentricMapperTopologyContain base.invert(matrixTranspose); } - virtual void computeCenter(Vector3& center, const typename In::VecCoord& in, const Element& element) override + virtual void computeCenter(Vector3& center, const typename In::VecCoord& in, const Quad& element) override { center = ( in[element[0]]+in[element[1]]+in[element[2]]+in[element[3]] ) *0.25; } @@ -903,14 +895,13 @@ class BarycentricMapperQuadSetTopology : public BarycentricMapperTopologyContain /// Class allowing barycentric mapping computation on a TetrahedronSetTopology -template::MappingData3D, class Element = Tetrahedron> -class BarycentricMapperTetrahedronSetTopology : public BarycentricMapperTopologyContainer +template +class BarycentricMapperTetrahedronSetTopology : public BarycentricMapperTopologyContainer::MappingData3D,Tetrahedron> { + typedef typename BarycentricMapper::MappingData3D MappingData; public: - SOFA_CLASS(SOFA_TEMPLATE4(BarycentricMapperTetrahedronSetTopology,In,Out,MappingDataType,Element),SOFA_TEMPLATE4(BarycentricMapperTopologyContainer,In,Out,MappingDataType,Element)); - typedef MappingDataType MappingData; - typedef BarycentricMapperTopologyContainer Inherit; - typedef typename Inherit::Real Real; + SOFA_CLASS(SOFA_TEMPLATE2(BarycentricMapperTetrahedronSetTopology,In,Out),SOFA_TEMPLATE4(BarycentricMapperTopologyContainer,In,Out,MappingData,Tetrahedron)); + typedef typename Inherit1::Real Real; typedef typename In::VecCoord VecCoord; @@ -919,13 +910,13 @@ class BarycentricMapperTetrahedronSetTopology : public BarycentricMapperTopology topology::TetrahedronSetTopologyContainer* m_fromContainer; topology::TetrahedronSetGeometryAlgorithms* m_fromGeomAlgo; - using Inherit::d_map; - using Inherit::m_fromTopology; - using Inherit::m_matrixJ; - using Inherit::m_updateJ; + using Inherit1::d_map; + using Inherit1::m_fromTopology; + using Inherit1::m_matrixJ; + using Inherit1::m_updateJ; BarycentricMapperTetrahedronSetTopology(topology::TetrahedronSetTopologyContainer* fromTopology, topology::PointSetTopologyContainer* toTopology) - : Inherit(fromTopology, toTopology), + : Inherit1(fromTopology, toTopology), m_fromContainer(fromTopology), m_fromGeomAlgo(NULL) {} @@ -933,7 +924,7 @@ class BarycentricMapperTetrahedronSetTopology : public BarycentricMapperTopology virtual ~BarycentricMapperTetrahedronSetTopology() override {} - virtual helper::vector getElements() override + virtual helper::vector getElements() override { return this->m_fromTopology->getTetrahedra(); } @@ -949,7 +940,7 @@ class BarycentricMapperTetrahedronSetTopology : public BarycentricMapperTopology return tetrahedronCoef; } - virtual void computeBase(Mat3x3d& base, const typename In::VecCoord& in, const Element& element) override + virtual void computeBase(Mat3x3d& base, const typename In::VecCoord& in, const Tetrahedron& element) override { Mat3x3d matrixTranspose; base[0] = in[element[1]]-in[element[0]]; @@ -959,7 +950,7 @@ class BarycentricMapperTetrahedronSetTopology : public BarycentricMapperTopology base.invert(matrixTranspose); } - virtual void computeCenter(Vector3& center, const typename In::VecCoord& in, const Element& element) override + virtual void computeCenter(Vector3& center, const typename In::VecCoord& in, const Tetrahedron& element) override { center = ( in[element[0]]+in[element[1]]+in[element[2]]+in[element[3]] ) *0.25; } @@ -982,41 +973,41 @@ class BarycentricMapperTetrahedronSetTopology : public BarycentricMapperTopology /// Class allowing barycentric mapping computation on a HexahedronSetTopology -template::MappingData3D, class Element = Hexahedron> -class BarycentricMapperHexahedronSetTopology : public BarycentricMapperTopologyContainer +template +class BarycentricMapperHexahedronSetTopology : public BarycentricMapperTopologyContainer::MappingData3D,Hexahedron> { + typedef typename BarycentricMapper::MappingData3D MappingData; + public: - SOFA_CLASS(SOFA_TEMPLATE4(BarycentricMapperHexahedronSetTopology,In,Out,MappingDataType,Element),SOFA_TEMPLATE4(BarycentricMapperTopologyContainer,In,Out,MappingDataType,Element)); - typedef MappingDataType MappingData; - typedef BarycentricMapperTopologyContainer Inherit; - typedef typename Inherit::Real Real; + SOFA_CLASS(SOFA_TEMPLATE2(BarycentricMapperHexahedronSetTopology,In,Out),SOFA_TEMPLATE4(BarycentricMapperTopologyContainer,In,Out,MappingData,Hexahedron)); + typedef typename Inherit1::Real Real; protected: topology::HexahedronSetTopologyContainer* m_fromContainer; topology::HexahedronSetGeometryAlgorithms* m_fromGeomAlgo; std::set m_invalidIndex; - using Inherit::d_map; - using Inherit::m_matrixJ; - using Inherit::m_updateJ; - using Inherit::m_fromTopology; + using Inherit1::d_map; + using Inherit1::m_matrixJ; + using Inherit1::m_updateJ; + using Inherit1::m_fromTopology; BarycentricMapperHexahedronSetTopology() - : Inherit(NULL, NULL), + : Inherit1(NULL, NULL), m_fromContainer(NULL), m_fromGeomAlgo(NULL) {} BarycentricMapperHexahedronSetTopology(topology::HexahedronSetTopologyContainer* fromTopology, topology::PointSetTopologyContainer* toTopology) - : Inherit(fromTopology, toTopology), + : Inherit1(fromTopology, toTopology), m_fromContainer(fromTopology), m_fromGeomAlgo(NULL) {} - virtual ~BarycentricMapperHexahedronSetTopology() {} + virtual ~BarycentricMapperHexahedronSetTopology() override {} - virtual helper::vector getElements() override + virtual helper::vector getElements() override { return this->m_fromTopology->getHexahedra(); } @@ -1039,7 +1030,7 @@ class BarycentricMapperHexahedronSetTopology : public BarycentricMapperTopologyC return hexahedronCoef; } - virtual void computeBase(Mat3x3d& base, const typename In::VecCoord& in, const Element& element) override + virtual void computeBase(Mat3x3d& base, const typename In::VecCoord& in, const Hexahedron& element) override { Mat3x3d matrixTranspose; base[0] = in[element[1]]-in[element[0]]; @@ -1049,7 +1040,7 @@ class BarycentricMapperHexahedronSetTopology : public BarycentricMapperTopologyC base.invert(matrixTranspose); } - virtual void computeCenter(Vector3& center, const typename In::VecCoord& in, const Element& element) override + virtual void computeCenter(Vector3& center, const typename In::VecCoord& in, const Hexahedron& element) override { center = ( in[element[0]]+in[element[1]]+in[element[2]]+in[element[3]]+in[element[4]]+in[element[5]]+in[element[6]]+in[element[7]] ) *0.125; } @@ -1089,7 +1080,6 @@ class BarycentricMapping : public core::Mapping public: SOFA_CLASS(SOFA_TEMPLATE2(BarycentricMapping,TIn,TOut), SOFA_TEMPLATE2(core::Mapping,TIn,TOut)); - typedef core::Mapping Inherit; typedef TIn In; typedef TOut Out; typedef In InDataTypes; @@ -1107,7 +1097,7 @@ class BarycentricMapping : public core::Mapping typedef core::topology::BaseMeshTopology BaseMeshTopology; typedef TopologyBarycentricMapper Mapper; - typedef typename Inherit::ForceMask ForceMask; + typedef typename Inherit1::ForceMask ForceMask; protected: @@ -1128,7 +1118,7 @@ class BarycentricMapping : public core::Mapping BarycentricMapping(core::State* from, core::State* to, BaseMeshTopology * topology=NULL ); - virtual ~BarycentricMapping(); + virtual ~BarycentricMapping() override ; public: void init() override; diff --git a/SofaKernel/modules/SofaBaseMechanics/BarycentricMapping.inl b/SofaKernel/modules/SofaBaseMechanics/BarycentricMapping.inl index 4610bf2cc52..8b0f568f1f3 100644 --- a/SofaKernel/modules/SofaBaseMechanics/BarycentricMapping.inl +++ b/SofaKernel/modules/SofaBaseMechanics/BarycentricMapping.inl @@ -80,7 +80,7 @@ typedef typename sofa::core::topology::BaseMeshTopology::SeqHexahedra SeqHexahed template BarycentricMapping::BarycentricMapping() - : Inherit() + : Inherit1() , m_mapper(initLink("mapper","Internal mapper created depending on the type of topology")) , useRestPosition(core::objectmodel::Base::initData(&useRestPosition, false, "useRestPosition", "Use the rest position of the input and output models to initialize the mapping")) #ifdef SOFA_DEV @@ -91,7 +91,7 @@ BarycentricMapping::BarycentricMapping() template BarycentricMapping::BarycentricMapping(core::State* from, core::State* to, typename Mapper::SPtr mapper) - : Inherit ( from, to ) + : Inherit1 ( from, to ) , m_mapper(initLink("mapper","Internal mapper created depending on the type of topology"), mapper) #ifdef SOFA_DEV , sleeping(core::objectmodel::Base::initData(&sleeping, false, "sleeping", "is the mapping sleeping (not computed)")) @@ -103,7 +103,7 @@ BarycentricMapping::BarycentricMapping(core::State* from, core::S template BarycentricMapping::BarycentricMapping (core::State* from, core::State* to, BaseMeshTopology * topology ) - : Inherit ( from, to ) + : Inherit1 ( from, to ) , m_mapper (initLink("mapper","Internal mapper created depending on the type of topology")) #ifdef SOFA_DEV , sleeping(core::objectmodel::Base::initData(&sleeping, false, "sleeping", "is the mapping sleeping (not computed)")) @@ -579,8 +579,8 @@ void BarycentricMapperTopologyContainer::clear(i d_map.endEdit(); } -template -int BarycentricMapperEdgeSetTopology::addPointInLine ( const int edgeIndex, const SReal* baryCoords ) +template +int BarycentricMapperEdgeSetTopology::addPointInLine ( const int edgeIndex, const SReal* baryCoords ) { helper::vector& vectorData = *(d_map.beginEdit()); vectorData.resize ( d_map.getValue().size() +1 ); @@ -591,8 +591,8 @@ int BarycentricMapperEdgeSetTopology::addPointIn return (int)d_map.getValue().size()-1; } -template -int BarycentricMapperEdgeSetTopology::createPointInLine ( const typename Out::Coord& p, int edgeIndex, const typename In::VecCoord* points ) +template +int BarycentricMapperEdgeSetTopology::createPointInLine ( const typename Out::Coord& p, int edgeIndex, const typename In::VecCoord* points ) { SReal baryCoords[1]; const Edge& elem = this->m_fromTopology->getEdge ( edgeIndex ); @@ -603,8 +603,8 @@ int BarycentricMapperEdgeSetTopology::createPoin return this->addPointInLine ( edgeIndex, baryCoords ); } -template -int BarycentricMapperTriangleSetTopology::addPointInTriangle ( const int triangleIndex, const SReal* baryCoords ) +template +int BarycentricMapperTriangleSetTopology::addPointInTriangle ( const int triangleIndex, const SReal* baryCoords ) { helper::vector& vectorData = *(d_map.beginEdit()); vectorData.resize ( d_map.getValue().size() +1 ); @@ -616,8 +616,8 @@ int BarycentricMapperTriangleSetTopology::addPoi return (int)d_map.getValue().size()-1; } -template -int BarycentricMapperTriangleSetTopology::createPointInTriangle ( const typename Out::Coord& p, int triangleIndex, const typename In::VecCoord* points ) +template +int BarycentricMapperTriangleSetTopology::createPointInTriangle ( const typename Out::Coord& p, int triangleIndex, const typename In::VecCoord* points ) { SReal baryCoords[2]; const Triangle& elem = this->m_fromTopology->getTriangle ( triangleIndex ); @@ -634,8 +634,8 @@ int BarycentricMapperTriangleSetTopology::create return this->addPointInTriangle ( triangleIndex, baryCoords ); } -template -int BarycentricMapperQuadSetTopology::addPointInQuad ( const int quadIndex, const SReal* baryCoords ) +template +int BarycentricMapperQuadSetTopology::addPointInQuad ( const int quadIndex, const SReal* baryCoords ) { helper::vector& vectorData = *(d_map.beginEdit()); vectorData.resize ( d_map.getValue().size() +1 ); @@ -647,8 +647,8 @@ int BarycentricMapperQuadSetTopology::addPointIn return (int)d_map.getValue().size()-1; } -template -int BarycentricMapperQuadSetTopology::createPointInQuad ( const typename Out::Coord& p, int quadIndex, const typename In::VecCoord* points ) +template +int BarycentricMapperQuadSetTopology::createPointInQuad ( const typename Out::Coord& p, int quadIndex, const typename In::VecCoord* points ) { SReal baryCoords[2]; const Quad& elem = this->m_fromTopology->getQuad ( quadIndex ); @@ -669,8 +669,8 @@ int BarycentricMapperQuadSetTopology::createPoin return this->addPointInQuad ( quadIndex, baryCoords ); } -template -int BarycentricMapperTetrahedronSetTopology::addPointInTetra ( const int tetraIndex, const SReal* baryCoords ) +template +int BarycentricMapperTetrahedronSetTopology::addPointInTetra ( const int tetraIndex, const SReal* baryCoords ) { helper::vector& vectorData = *(d_map.beginEdit()); vectorData.resize ( d_map.getValue().size() +1 ); @@ -683,8 +683,8 @@ int BarycentricMapperTetrahedronSetTopology::add return (int)d_map.getValue().size()-1; } -template -int BarycentricMapperHexahedronSetTopology::addPointInCube ( const int cubeIndex, const SReal* baryCoords ) +template +int BarycentricMapperHexahedronSetTopology::addPointInCube ( const int cubeIndex, const SReal* baryCoords ) { helper::vector& vectorData = *(d_map.beginEdit()); vectorData.resize ( d_map.getValue().size() +1 ); @@ -697,8 +697,8 @@ int BarycentricMapperHexahedronSetTopology::addP return (int)d_map.getValue().size()-1; } -template -int BarycentricMapperHexahedronSetTopology::setPointInCube ( const int pointIndex, const int cubeIndex, const SReal* baryCoords ) +template +int BarycentricMapperHexahedronSetTopology::setPointInCube ( const int pointIndex, const int cubeIndex, const SReal* baryCoords ) { if ( pointIndex >= ( int ) d_map.getValue().size() ) return -1; @@ -882,7 +882,7 @@ void BarycentricMapping::init() topology_from = this->fromModel->getContext()->getMeshTopology(); topology_to = this->toModel->getContext()->getMeshTopology(); - Inherit::init(); + Inherit1::init(); if ( m_mapper == NULL ) // try to create a mapper according to the topology of the In model { @@ -1130,8 +1130,8 @@ void BarycentricMapperTopologyContainer::resize( } //-- test mapping partiel -template -void BarycentricMapperHexahedronSetTopology::applyOnePoint( const unsigned int& hexaPointId,typename Out::VecCoord& out, const typename In::VecCoord& in ) +template +void BarycentricMapperHexahedronSetTopology::applyOnePoint( const unsigned int& hexaPointId,typename Out::VecCoord& out, const typename In::VecCoord& in ) { const helper::vector& cubes = this->m_fromTopology->getHexahedra(); const Real fx = d_map.getValue()[hexaPointId].baryCoords[0]; @@ -2351,8 +2351,8 @@ void BarycentricMapperTopologyContainer::applyJT /************************************* Topological Changes ***********************************/ -template -void BarycentricMapperHexahedronSetTopology::handleTopologyChange(core::topology::Topology* t) +template +void BarycentricMapperHexahedronSetTopology::handleTopologyChange(core::topology::Topology* t) { using sofa::core::behavior::MechanicalState; From 528e512f9d249b185522162d2aa99103eca8fe10 Mon Sep 17 00:00:00 2001 From: defrost Date: Wed, 14 Nov 2018 20:41:03 +0100 Subject: [PATCH 06/15] [SofaBaseMechanics] went further with cleaning, split the 10 mapper classes into files --- .../BarycentricMappers/BarycentricMapper.cpp | 60 + .../BarycentricMappers/BarycentricMapper.h | 168 ++ .../BarycentricMappers/BarycentricMapper.inl | 69 + .../BarycentricMapperEdgeSetTopology.cpp | 55 + .../BarycentricMapperEdgeSetTopology.h | 112 + .../BarycentricMapperEdgeSetTopology.inl | 111 + ...BarycentricMapperHexahedronSetTopology.cpp | 55 + .../BarycentricMapperHexahedronSetTopology.h | 123 + ...BarycentricMapperHexahedronSetTopology.inl | 315 +++ .../BarycentricMapperMeshTopology.cpp | 56 + .../BarycentricMapperMeshTopology.h | 199 ++ .../BarycentricMapperMeshTopology.inl | 1093 ++++++++ .../BarycentricMapperQuadSetTopology.cpp | 55 + .../BarycentricMapperQuadSetTopology.h | 111 + .../BarycentricMapperQuadSetTopology.inl | 125 + .../BarycentricMapperRegularGridTopology.cpp | 56 + .../BarycentricMapperRegularGridTopology.h | 142 ++ .../BarycentricMapperRegularGridTopology.inl | 304 +++ .../BarycentricMapperSparseGridTopology.cpp | 60 + .../BarycentricMapperSparseGridTopology.h | 142 ++ .../BarycentricMapperSparseGridTopology.inl | 338 +++ ...arycentricMapperTetrahedronSetTopology.cpp | 56 + .../BarycentricMapperTetrahedronSetTopology.h | 113 + ...arycentricMapperTetrahedronSetTopology.inl | 101 + .../BarycentricMapperTopologyContainer.cpp | 83 + .../BarycentricMapperTopologyContainer.h | 192 ++ .../BarycentricMapperTopologyContainer.inl | 278 +++ .../BarycentricMapperTriangleSetTopology.cpp | 53 + .../BarycentricMapperTriangleSetTopology.h | 115 + .../BarycentricMapperTriangleSetTopology.inl | 120 + .../TopologyBarycentricMapper.cpp | 62 + .../TopologyBarycentricMapper.h | 126 + .../TopologyBarycentricMapper.inl | 164 ++ .../SofaBaseMechanics/BarycentricMapping.cpp | 91 - .../SofaBaseMechanics/BarycentricMapping.h | 1149 +-------- .../SofaBaseMechanics/BarycentricMapping.inl | 2211 +---------------- .../modules/SofaBaseMechanics/CMakeLists.txt | 37 + .../BarycentricContactMapper.inl | 1 + .../BaryMapper_test.cpp | 3 +- .../BarycentricMappingRigid.cpp | 59 +- .../SofaMiscMapping/BarycentricMappingRigid.h | 51 +- 41 files changed, 5412 insertions(+), 3402 deletions(-) create mode 100644 SofaKernel/modules/SofaBaseMechanics/BarycentricMappers/BarycentricMapper.cpp create mode 100644 SofaKernel/modules/SofaBaseMechanics/BarycentricMappers/BarycentricMapper.h create mode 100644 SofaKernel/modules/SofaBaseMechanics/BarycentricMappers/BarycentricMapper.inl create mode 100644 SofaKernel/modules/SofaBaseMechanics/BarycentricMappers/BarycentricMapperEdgeSetTopology.cpp create mode 100644 SofaKernel/modules/SofaBaseMechanics/BarycentricMappers/BarycentricMapperEdgeSetTopology.h create mode 100644 SofaKernel/modules/SofaBaseMechanics/BarycentricMappers/BarycentricMapperEdgeSetTopology.inl create mode 100644 SofaKernel/modules/SofaBaseMechanics/BarycentricMappers/BarycentricMapperHexahedronSetTopology.cpp create mode 100644 SofaKernel/modules/SofaBaseMechanics/BarycentricMappers/BarycentricMapperHexahedronSetTopology.h create mode 100644 SofaKernel/modules/SofaBaseMechanics/BarycentricMappers/BarycentricMapperHexahedronSetTopology.inl create mode 100644 SofaKernel/modules/SofaBaseMechanics/BarycentricMappers/BarycentricMapperMeshTopology.cpp create mode 100644 SofaKernel/modules/SofaBaseMechanics/BarycentricMappers/BarycentricMapperMeshTopology.h create mode 100644 SofaKernel/modules/SofaBaseMechanics/BarycentricMappers/BarycentricMapperMeshTopology.inl create mode 100644 SofaKernel/modules/SofaBaseMechanics/BarycentricMappers/BarycentricMapperQuadSetTopology.cpp create mode 100644 SofaKernel/modules/SofaBaseMechanics/BarycentricMappers/BarycentricMapperQuadSetTopology.h create mode 100644 SofaKernel/modules/SofaBaseMechanics/BarycentricMappers/BarycentricMapperQuadSetTopology.inl create mode 100644 SofaKernel/modules/SofaBaseMechanics/BarycentricMappers/BarycentricMapperRegularGridTopology.cpp create mode 100644 SofaKernel/modules/SofaBaseMechanics/BarycentricMappers/BarycentricMapperRegularGridTopology.h create mode 100644 SofaKernel/modules/SofaBaseMechanics/BarycentricMappers/BarycentricMapperRegularGridTopology.inl create mode 100644 SofaKernel/modules/SofaBaseMechanics/BarycentricMappers/BarycentricMapperSparseGridTopology.cpp create mode 100644 SofaKernel/modules/SofaBaseMechanics/BarycentricMappers/BarycentricMapperSparseGridTopology.h create mode 100644 SofaKernel/modules/SofaBaseMechanics/BarycentricMappers/BarycentricMapperSparseGridTopology.inl create mode 100644 SofaKernel/modules/SofaBaseMechanics/BarycentricMappers/BarycentricMapperTetrahedronSetTopology.cpp create mode 100644 SofaKernel/modules/SofaBaseMechanics/BarycentricMappers/BarycentricMapperTetrahedronSetTopology.h create mode 100644 SofaKernel/modules/SofaBaseMechanics/BarycentricMappers/BarycentricMapperTetrahedronSetTopology.inl create mode 100644 SofaKernel/modules/SofaBaseMechanics/BarycentricMappers/BarycentricMapperTopologyContainer.cpp create mode 100644 SofaKernel/modules/SofaBaseMechanics/BarycentricMappers/BarycentricMapperTopologyContainer.h create mode 100644 SofaKernel/modules/SofaBaseMechanics/BarycentricMappers/BarycentricMapperTopologyContainer.inl create mode 100644 SofaKernel/modules/SofaBaseMechanics/BarycentricMappers/BarycentricMapperTriangleSetTopology.cpp create mode 100644 SofaKernel/modules/SofaBaseMechanics/BarycentricMappers/BarycentricMapperTriangleSetTopology.h create mode 100644 SofaKernel/modules/SofaBaseMechanics/BarycentricMappers/BarycentricMapperTriangleSetTopology.inl create mode 100644 SofaKernel/modules/SofaBaseMechanics/BarycentricMappers/TopologyBarycentricMapper.cpp create mode 100644 SofaKernel/modules/SofaBaseMechanics/BarycentricMappers/TopologyBarycentricMapper.h create mode 100644 SofaKernel/modules/SofaBaseMechanics/BarycentricMappers/TopologyBarycentricMapper.inl diff --git a/SofaKernel/modules/SofaBaseMechanics/BarycentricMappers/BarycentricMapper.cpp b/SofaKernel/modules/SofaBaseMechanics/BarycentricMappers/BarycentricMapper.cpp new file mode 100644 index 00000000000..8f4fa5d49e5 --- /dev/null +++ b/SofaKernel/modules/SofaBaseMechanics/BarycentricMappers/BarycentricMapper.cpp @@ -0,0 +1,60 @@ +/****************************************************************************** +* SOFA, Simulation Open-Framework Architecture, development version * +* (c) 2006-2018 INRIA, USTL, UJF, CNRS, MGH * +* * +* This program is free software; you can redistribute it and/or modify it * +* under the terms of the GNU Lesser General Public License as published by * +* the Free Software Foundation; either version 2.1 of the License, or (at * +* your option) any later version. * +* * +* This program is distributed in the hope that it will be useful, but WITHOUT * +* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * +* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License * +* for more details. * +* * +* You should have received a copy of the GNU Lesser General Public License * +* along with this program. If not, see . * +******************************************************************************* +* Authors: The SOFA Team and external contributors (see Authors.txt) * +* * +* Contact information: contact@sofa-framework.org * +******************************************************************************/ +#ifndef SOFA_COMPONENT_MAPPING_BARYCENTRICMAPPER_CPP +#define SOFA_COMPONENT_MAPPING_BARYCENTRICMAPPER_CPP + +#include "BarycentricMapper.inl" + +namespace sofa +{ + +namespace component +{ + +namespace mapping +{ + +namespace _barycentricmapper_ +{ + +using namespace sofa::defaulttype; + +#ifndef SOFA_FLOAT +template class SOFA_BASE_MECHANICS_API BarycentricMapper< Vec3dTypes, Vec3dTypes >; +template class SOFA_BASE_MECHANICS_API BarycentricMapper< Vec3dTypes, ExtVec3fTypes >; +#endif +#ifndef SOFA_DOUBLE +template class SOFA_BASE_MECHANICS_API BarycentricMapper< Vec3fTypes, Vec3fTypes >; +template class SOFA_BASE_MECHANICS_API BarycentricMapper< Vec3fTypes, ExtVec3fTypes >; +#endif +#ifndef SOFA_FLOAT +#ifndef SOFA_DOUBLE +template class SOFA_BASE_MECHANICS_API BarycentricMapper< Vec3dTypes, Vec3fTypes >; +template class SOFA_BASE_MECHANICS_API BarycentricMapper< Vec3fTypes, Vec3dTypes >; +#endif +#endif + +} + +}}} + +#endif diff --git a/SofaKernel/modules/SofaBaseMechanics/BarycentricMappers/BarycentricMapper.h b/SofaKernel/modules/SofaBaseMechanics/BarycentricMappers/BarycentricMapper.h new file mode 100644 index 00000000000..97c7eb36bc9 --- /dev/null +++ b/SofaKernel/modules/SofaBaseMechanics/BarycentricMappers/BarycentricMapper.h @@ -0,0 +1,168 @@ +/****************************************************************************** +* SOFA, Simulation Open-Framework Architecture, development version * +* (c) 2006-2018 INRIA, USTL, UJF, CNRS, MGH * +* * +* This program is free software; you can redistribute it and/or modify it * +* under the terms of the GNU Lesser General Public License as published by * +* the Free Software Foundation; either version 2.1 of the License, or (at * +* your option) any later version. * +* * +* This program is distributed in the hope that it will be useful, but WITHOUT * +* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * +* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License * +* for more details. * +* * +* You should have received a copy of the GNU Lesser General Public License * +* along with this program. If not, see . * +******************************************************************************* +* Authors: The SOFA Team and external contributors (see Authors.txt) * +* * +* Contact information: contact@sofa-framework.org * +******************************************************************************/ +#ifndef SOFA_COMPONENT_MAPPING_BARYCENTRICMAPPER_H +#define SOFA_COMPONENT_MAPPING_BARYCENTRICMAPPER_H + +#include +#include +#include + +namespace sofa +{ + +namespace component +{ + +namespace mapping +{ + +namespace _barycentricmapper_ +{ + +using core::visual::VisualParams; +using sofa::defaulttype::BaseMatrix; + +/// Base class for barycentric mapping topology-specific mappers +template +class SOFA_BASE_MECHANICS_API BarycentricMapper : public virtual core::objectmodel::BaseObject +{ + +public: + + SOFA_CLASS(SOFA_TEMPLATE2(BarycentricMapper,In,Out),core::objectmodel::BaseObject); + + typedef typename In::Real Real; + typedef typename In::Real InReal; + typedef typename Out::Real OutReal; + + typedef typename In::VecDeriv InVecDeriv; + typedef typename In::Deriv InDeriv; + + typedef typename Out::VecDeriv OutVecDeriv; + typedef typename Out::Deriv OutDeriv; + + enum { NIn = sofa::defaulttype::DataTypeInfo::Size }; + enum { NOut = sofa::defaulttype::DataTypeInfo::Size }; + typedef defaulttype::Mat MBloc; + typedef sofa::component::linearsolver::CompressedRowSparseMatrix MatrixType; + + +public: + + using BaseObject::init; + virtual void init(const typename Out::VecCoord& out, const typename In::VecCoord& in) = 0; + + using BaseObject::draw; + virtual void draw(const VisualParams*, const typename Out::VecCoord& out, const typename In::VecCoord& in) = 0; + + virtual void apply( typename Out::VecCoord& out, const typename In::VecCoord& in ) = 0; + virtual const BaseMatrix* getJ(int outSize, int inSize); + virtual void applyJ( typename Out::VecDeriv& out, const typename In::VecDeriv& in ) = 0; + virtual void applyJT( typename In::VecDeriv& out, const typename Out::VecDeriv& in ) = 0; + virtual void applyJT( typename In::MatrixDeriv& out, const typename Out::MatrixDeriv& in ) = 0; + virtual void applyOnePoint( const unsigned int& hexaId, typename Out::VecCoord& out, const typename In::VecCoord& in); + virtual void clear( int reserve=0 ) =0; + + inline friend std::istream& operator >> ( std::istream& in, BarycentricMapper< In, Out > & ) {return in;} + inline friend std::ostream& operator << ( std::ostream& out, const BarycentricMapper< In, Out > & ) { return out; } + + +protected: + + void addMatrixContrib(MatrixType* m, int row, int col, Real value); + + template< int NC, int NP> + class MappingData + { + public: + int in_index; + Real baryCoords[NC]; + + inline friend std::istream& operator >> ( std::istream& in, MappingData< NC, NP> &m ) + { + in>>m.in_index; + for (int i=0; i> m.baryCoords[i]; + return in; + } + + inline friend std::ostream& operator << ( std::ostream& out, const MappingData< NC , NP > & m ) + { + out << m.in_index; + for (int i=0; i LineData; + typedef MappingData<2,3> TriangleData; + typedef MappingData<2,4> QuadData; + typedef MappingData<3,4> TetraData; + typedef MappingData<3,8> CubeData; + typedef MappingData<1,0> MappingData1D; + typedef MappingData<2,0> MappingData2D; + typedef MappingData<3,0> MappingData3D; + + +protected: + BarycentricMapper() {} + virtual ~BarycentricMapper() override {} + +private: + BarycentricMapper(const BarycentricMapper& n) ; + BarycentricMapper& operator=(const BarycentricMapper& n) ; +}; + + +using sofa::defaulttype::Vec3dTypes; +using sofa::defaulttype::Vec3fTypes; +using sofa::defaulttype::ExtVec3fTypes; + + +#if defined(SOFA_EXTERN_TEMPLATE) && !defined(SOFA_COMPONENT_MAPPING_BARYCENTRICMAPPER_CPP) +#ifndef SOFA_FLOAT +extern template class SOFA_BASE_MECHANICS_API BarycentricMapper< Vec3dTypes, Vec3dTypes >; +extern template class SOFA_BASE_MECHANICS_API BarycentricMapper< Vec3dTypes, ExtVec3fTypes >; +#endif +#ifndef SOFA_DOUBLE +extern template class SOFA_BASE_MECHANICS_API BarycentricMapper< Vec3fTypes, Vec3fTypes >; +extern template class SOFA_BASE_MECHANICS_API BarycentricMapper< Vec3fTypes, ExtVec3fTypes >; +#endif +#ifndef SOFA_FLOAT +#ifndef SOFA_DOUBLE +extern template class SOFA_BASE_MECHANICS_API BarycentricMapper< Vec3dTypes, Vec3fTypes >; +extern template class SOFA_BASE_MECHANICS_API BarycentricMapper< Vec3fTypes, Vec3dTypes >; +#endif +#endif +#endif + +} + +using _barycentricmapper_::BarycentricMapper; + +}}} + +#endif diff --git a/SofaKernel/modules/SofaBaseMechanics/BarycentricMappers/BarycentricMapper.inl b/SofaKernel/modules/SofaBaseMechanics/BarycentricMappers/BarycentricMapper.inl new file mode 100644 index 00000000000..b6f8463fb43 --- /dev/null +++ b/SofaKernel/modules/SofaBaseMechanics/BarycentricMappers/BarycentricMapper.inl @@ -0,0 +1,69 @@ +/****************************************************************************** +* SOFA, Simulation Open-Framework Architecture, development version * +* (c) 2006-2018 INRIA, USTL, UJF, CNRS, MGH * +* * +* This program is free software; you can redistribute it and/or modify it * +* under the terms of the GNU Lesser General Public License as published by * +* the Free Software Foundation; either version 2.1 of the License, or (at * +* your option) any later version. * +* * +* This program is distributed in the hope that it will be useful, but WITHOUT * +* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * +* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License * +* for more details. * +* * +* You should have received a copy of the GNU Lesser General Public License * +* along with this program. If not, see . * +******************************************************************************* +* Authors: The SOFA Team and external contributors (see Authors.txt) * +* * +* Contact information: contact@sofa-framework.org * +******************************************************************************/ +#ifndef SOFA_COMPONENT_MAPPING_BARYCENTRICMAPPER_INL +#define SOFA_COMPONENT_MAPPING_BARYCENTRICMAPPER_INL + +#include "BarycentricMapper.h" + +namespace sofa +{ + +namespace component +{ + +namespace mapping +{ + +namespace _barycentricmapper_ +{ + +using sofa::component::linearsolver::CompressedRowSparseMatrix; + +template +void BarycentricMapper::addMatrixContrib(CompressedRowSparseMatrix* m, int row, int col, Real value) +{ + MBloc* b = m->wbloc(row, col, true); // get write access to a matrix bloc, creating it if not found + for (int i=0; i < ((int)NIn < (int)NOut ? (int)NIn : (int)NOut); ++i) + (*b)[i][i] += value; +} + + +template +const sofa::defaulttype::BaseMatrix* BarycentricMapper::getJ(int outSize, int inSize) +{ + SOFA_UNUSED(outSize); + SOFA_UNUSED(inSize); + dmsg_error() << " getJ() NOT IMPLEMENTED BY " << sofa::core::objectmodel::BaseClass::decodeClassName(typeid(*this)) ; + return nullptr; +} + +template +void BarycentricMapper::applyOnePoint( const unsigned int& hexaId, typename Out::VecCoord& out, const typename In::VecCoord& in) +{ + SOFA_UNUSED(hexaId); + SOFA_UNUSED(out); + SOFA_UNUSED(in); +} + +}}}} + +#endif diff --git a/SofaKernel/modules/SofaBaseMechanics/BarycentricMappers/BarycentricMapperEdgeSetTopology.cpp b/SofaKernel/modules/SofaBaseMechanics/BarycentricMappers/BarycentricMapperEdgeSetTopology.cpp new file mode 100644 index 00000000000..eaf6894ec7e --- /dev/null +++ b/SofaKernel/modules/SofaBaseMechanics/BarycentricMappers/BarycentricMapperEdgeSetTopology.cpp @@ -0,0 +1,55 @@ +/****************************************************************************** +* SOFA, Simulation Open-Framework Architecture, development version * +* (c) 2006-2018 INRIA, USTL, UJF, CNRS, MGH * +* * +* This program is free software; you can redistribute it and/or modify it * +* under the terms of the GNU Lesser General Public License as published by * +* the Free Software Foundation; either version 2.1 of the License, or (at * +* your option) any later version. * +* * +* This program is distributed in the hope that it will be useful, but WITHOUT * +* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * +* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License * +* for more details. * +* * +* You should have received a copy of the GNU Lesser General Public License * +* along with this program. If not, see . * +******************************************************************************* +* Authors: The SOFA Team and external contributors (see Authors.txt) * +* * +* Contact information: contact@sofa-framework.org * +******************************************************************************/ +#ifndef SOFA_COMPONENT_MAPPING_BARYCENTRICMAPPEREDGESETTOPOLOGY_CPP +#define SOFA_COMPONENT_MAPPING_BARYCENTRICMAPPEREDGESETTOPOLOGY_CPP + +#include "BarycentricMapperEdgeSetTopology.inl" + +namespace sofa +{ + +namespace component +{ + +namespace mapping +{ + +using namespace sofa::defaulttype; + +#ifndef SOFA_FLOAT +template class SOFA_BASE_MECHANICS_API BarycentricMapperEdgeSetTopology< Vec3dTypes, Vec3dTypes>; +template class SOFA_BASE_MECHANICS_API BarycentricMapperEdgeSetTopology< Vec3dTypes, ExtVec3fTypes>; +#endif +#ifndef SOFA_DOUBLE +template class SOFA_BASE_MECHANICS_API BarycentricMapperEdgeSetTopology< Vec3fTypes, Vec3fTypes>; +template class SOFA_BASE_MECHANICS_API BarycentricMapperEdgeSetTopology< Vec3fTypes, ExtVec3fTypes>; +#endif +#ifndef SOFA_FLOAT +#ifndef SOFA_DOUBLE +template class SOFA_BASE_MECHANICS_API BarycentricMapperEdgeSetTopology< Vec3dTypes, Vec3fTypes>; +template class SOFA_BASE_MECHANICS_API BarycentricMapperEdgeSetTopology< Vec3fTypes, Vec3dTypes>; +#endif +#endif + +}}} + +#endif diff --git a/SofaKernel/modules/SofaBaseMechanics/BarycentricMappers/BarycentricMapperEdgeSetTopology.h b/SofaKernel/modules/SofaBaseMechanics/BarycentricMappers/BarycentricMapperEdgeSetTopology.h new file mode 100644 index 00000000000..f3d2dc112db --- /dev/null +++ b/SofaKernel/modules/SofaBaseMechanics/BarycentricMappers/BarycentricMapperEdgeSetTopology.h @@ -0,0 +1,112 @@ +/****************************************************************************** +* SOFA, Simulation Open-Framework Architecture, development version * +* (c) 2006-2018 INRIA, USTL, UJF, CNRS, MGH * +* * +* This program is free software; you can redistribute it and/or modify it * +* under the terms of the GNU Lesser General Public License as published by * +* the Free Software Foundation; either version 2.1 of the License, or (at * +* your option) any later version. * +* * +* This program is distributed in the hope that it will be useful, but WITHOUT * +* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * +* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License * +* for more details. * +* * +* You should have received a copy of the GNU Lesser General Public License * +* along with this program. If not, see . * +******************************************************************************* +* Authors: The SOFA Team and external contributors (see Authors.txt) * +* * +* Contact information: contact@sofa-framework.org * +******************************************************************************/ +#ifndef SOFA_COMPONENT_MAPPING_BARYCENTRICMAPPEREDGESETTOPOLOGY_H +#define SOFA_COMPONENT_MAPPING_BARYCENTRICMAPPEREDGESETTOPOLOGY_H + + +#include +#include +#include + + +namespace sofa +{ + +namespace component +{ + +namespace mapping +{ + +using sofa::defaulttype::Mat3x3d; +using sofa::defaulttype::Vector3; +typedef typename sofa::core::topology::BaseMeshTopology::Edge Edge; + +/////// Class allowing barycentric mapping computation on a EdgeSetTopology +template +class SOFA_BASE_MECHANICS_API BarycentricMapperEdgeSetTopology : public BarycentricMapperTopologyContainer::MappingData1D,Edge> +{ + typedef typename BarycentricMapper::MappingData1D MappingData; + +public: + SOFA_CLASS(SOFA_TEMPLATE2(BarycentricMapperEdgeSetTopology,In,Out),SOFA_TEMPLATE4(BarycentricMapperTopologyContainer,In,Out,MappingData,Edge)); + typedef typename Inherit1::Real Real; + +public: + + virtual void init(const typename Out::VecCoord& out, const typename In::VecCoord& in) override + { + SOFA_UNUSED(out); + SOFA_UNUSED(in); + msg_warning() << "BarycentricMapping not implemented for EdgeSetTopologyContainer."; + } + virtual int addPointInLine(const int edgeIndex, const SReal* baryCoords) override; + virtual int createPointInLine(const typename Out::Coord& p, int edgeIndex, const typename In::VecCoord* points) override; + + +protected: + topology::EdgeSetTopologyContainer* m_fromContainer; + topology::EdgeSetGeometryAlgorithms* m_fromGeomAlgo; + + using Inherit1::d_map; + using Inherit1::m_fromTopology; + using Inherit1::m_matrixJ; + using Inherit1::m_updateJ; + + BarycentricMapperEdgeSetTopology(topology::EdgeSetTopologyContainer* fromTopology, topology::PointSetTopologyContainer* toTopology) + : Inherit1(fromTopology, toTopology), + m_fromContainer(fromTopology), + m_fromGeomAlgo(NULL) + {} + + virtual ~BarycentricMapperEdgeSetTopology() override {} + + virtual helper::vector getElements() override; + virtual helper::vector getBaryCoef(const Real* f) override; + helper::vector getBaryCoef(const Real fx); + virtual void computeBase(Mat3x3d& base, const typename In::VecCoord& in, const Edge& element) override; + virtual void computeCenter(Vector3& center, const typename In::VecCoord& in, const Edge& element) override; + virtual void computeDistance(double& d, const Vector3& v) override; + virtual void addPointInElement(const int elementIndex, const SReal* baryCoords) override; +}; + + +#if defined(SOFA_EXTERN_TEMPLATE) && !defined(SOFA_COMPONENT_MAPPING_BARYCENTRICMAPPEREDGESETTOPOLOGY_CPP) +#ifndef SOFA_FLOAT +extern template class SOFA_BASE_MECHANICS_API BarycentricMapperEdgeSetTopology< Vec3dTypes, Vec3dTypes>; +extern template class SOFA_BASE_MECHANICS_API BarycentricMapperEdgeSetTopology< Vec3dTypes, ExtVec3fTypes>; +#endif +#ifndef SOFA_DOUBLE +extern template class SOFA_BASE_MECHANICS_API BarycentricMapperEdgeSetTopology< Vec3fTypes, Vec3fTypes>; +extern template class SOFA_BASE_MECHANICS_API BarycentricMapperEdgeSetTopology< Vec3fTypes, ExtVec3fTypes>; +#endif +#ifndef SOFA_FLOAT +#ifndef SOFA_DOUBLE +extern template class SOFA_BASE_MECHANICS_API BarycentricMapperEdgeSetTopology< Vec3dTypes, Vec3fTypes>; +extern template class SOFA_BASE_MECHANICS_API BarycentricMapperEdgeSetTopology< Vec3fTypes, Vec3dTypes>; +#endif +#endif +#endif + +}}} + +#endif diff --git a/SofaKernel/modules/SofaBaseMechanics/BarycentricMappers/BarycentricMapperEdgeSetTopology.inl b/SofaKernel/modules/SofaBaseMechanics/BarycentricMappers/BarycentricMapperEdgeSetTopology.inl new file mode 100644 index 00000000000..03c55e4cee1 --- /dev/null +++ b/SofaKernel/modules/SofaBaseMechanics/BarycentricMappers/BarycentricMapperEdgeSetTopology.inl @@ -0,0 +1,111 @@ +/****************************************************************************** +* SOFA, Simulation Open-Framework Architecture, development version * +* (c) 2006-2018 INRIA, USTL, UJF, CNRS, MGH * +* * +* This program is free software; you can redistribute it and/or modify it * +* under the terms of the GNU Lesser General Public License as published by * +* the Free Software Foundation; either version 2.1 of the License, or (at * +* your option) any later version. * +* * +* This program is distributed in the hope that it will be useful, but WITHOUT * +* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * +* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License * +* for more details. * +* * +* You should have received a copy of the GNU Lesser General Public License * +* along with this program. If not, see . * +******************************************************************************* +* Authors: The SOFA Team and external contributors (see Authors.txt) * +* * +* Contact information: contact@sofa-framework.org * +******************************************************************************/ +#ifndef SOFA_COMPONENT_MAPPING_BARYCENTRICMAPPEREDGESETTOPOLOGY_INL +#define SOFA_COMPONENT_MAPPING_BARYCENTRICMAPPEREDGESETTOPOLOGY_INL + +#include "BarycentricMapperEdgeSetTopology.h" + +namespace sofa +{ + +namespace component +{ + +namespace mapping +{ + +template +int BarycentricMapperEdgeSetTopology::addPointInLine ( const int edgeIndex, const SReal* baryCoords ) +{ + helper::vector& vectorData = *(d_map.beginEdit()); + vectorData.resize ( d_map.getValue().size() +1 ); + d_map.endEdit(); + MappingData& data = *vectorData.rbegin(); + data.in_index = edgeIndex; + data.baryCoords[0] = ( Real ) baryCoords[0]; + return (int)d_map.getValue().size()-1; +} + +template +int BarycentricMapperEdgeSetTopology::createPointInLine ( const typename Out::Coord& p, int edgeIndex, const typename In::VecCoord* points ) +{ + SReal baryCoords[1]; + const Edge& elem = this->m_fromTopology->getEdge ( edgeIndex ); + const typename In::Coord p0 = ( *points ) [elem[0]]; + const typename In::Coord pA = ( *points ) [elem[1]] - p0; + typename In::Coord pos = Out::getCPos(p) - p0; + baryCoords[0] = dot ( pA,pos ) /dot ( pA,pA ); + return this->addPointInLine ( edgeIndex, baryCoords ); +} + + +template +helper::vector BarycentricMapperEdgeSetTopology::getElements() +{ + return this->m_fromTopology->getEdges(); +} + +template +helper::vector BarycentricMapperEdgeSetTopology::getBaryCoef(const Real* f) +{ + return getBaryCoef(f[0]); +} + +template +helper::vector BarycentricMapperEdgeSetTopology::getBaryCoef(const Real fx) +{ + helper::vector edgeCoef{1-fx,fx}; + return edgeCoef; +} + +template +void BarycentricMapperEdgeSetTopology::computeBase(Mat3x3d& base, const typename In::VecCoord& in, const Edge& element) +{ + //Not implemented for Edge + SOFA_UNUSED(base); + SOFA_UNUSED(in); + SOFA_UNUSED(element); +} + +template +void BarycentricMapperEdgeSetTopology::computeCenter(Vector3& center, const typename In::VecCoord& in, const Edge& element) +{ + center = (in[element[0]]+in[element[1]])*0.5; +} + +template +void BarycentricMapperEdgeSetTopology::computeDistance(double& d, const Vector3& v) +{ + //Not implemented for Edge + SOFA_UNUSED(d); + SOFA_UNUSED(v); +} + +template +void BarycentricMapperEdgeSetTopology::addPointInElement(const int elementIndex, const SReal* baryCoords) +{ + addPointInLine(elementIndex,baryCoords); +} + +}}} + +#endif diff --git a/SofaKernel/modules/SofaBaseMechanics/BarycentricMappers/BarycentricMapperHexahedronSetTopology.cpp b/SofaKernel/modules/SofaBaseMechanics/BarycentricMappers/BarycentricMapperHexahedronSetTopology.cpp new file mode 100644 index 00000000000..c75b7bffe26 --- /dev/null +++ b/SofaKernel/modules/SofaBaseMechanics/BarycentricMappers/BarycentricMapperHexahedronSetTopology.cpp @@ -0,0 +1,55 @@ +/****************************************************************************** +* SOFA, Simulation Open-Framework Architecture, development version * +* (c) 2006-2018 INRIA, USTL, UJF, CNRS, MGH * +* * +* This program is free software; you can redistribute it and/or modify it * +* under the terms of the GNU Lesser General Public License as published by * +* the Free Software Foundation; either version 2.1 of the License, or (at * +* your option) any later version. * +* * +* This program is distributed in the hope that it will be useful, but WITHOUT * +* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * +* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License * +* for more details. * +* * +* You should have received a copy of the GNU Lesser General Public License * +* along with this program. If not, see . * +******************************************************************************* +* Authors: The SOFA Team and external contributors (see Authors.txt) * +* * +* Contact information: contact@sofa-framework.org * +******************************************************************************/ +#ifndef SOFA_COMPONENT_MAPPING_BARYCENTRICMAPPERHEXAHEDRONSETTOPOLOGY_CPP +#define SOFA_COMPONENT_MAPPING_BARYCENTRICMAPPERHEXAHEDRONSETTOPOLOGY_CPP + +#include "BarycentricMapperHexahedronSetTopology.inl" + +namespace sofa +{ + +namespace component +{ + +namespace mapping +{ + +using namespace sofa::defaulttype; + +#ifndef SOFA_FLOAT +template class SOFA_BASE_MECHANICS_API BarycentricMapperHexahedronSetTopology< Vec3dTypes, Vec3dTypes >; +template class SOFA_BASE_MECHANICS_API BarycentricMapperHexahedronSetTopology< Vec3dTypes, ExtVec3fTypes >; +#endif +#ifndef SOFA_DOUBLE +template class SOFA_BASE_MECHANICS_API BarycentricMapperHexahedronSetTopology< Vec3fTypes, Vec3fTypes >; +template class SOFA_BASE_MECHANICS_API BarycentricMapperHexahedronSetTopology< Vec3fTypes, ExtVec3fTypes >; +#endif +#ifndef SOFA_FLOAT +#ifndef SOFA_DOUBLE +template class SOFA_BASE_MECHANICS_API BarycentricMapperHexahedronSetTopology< Vec3dTypes, Vec3fTypes >; +template class SOFA_BASE_MECHANICS_API BarycentricMapperHexahedronSetTopology< Vec3fTypes, Vec3dTypes >; +#endif +#endif + +}}} + +#endif diff --git a/SofaKernel/modules/SofaBaseMechanics/BarycentricMappers/BarycentricMapperHexahedronSetTopology.h b/SofaKernel/modules/SofaBaseMechanics/BarycentricMappers/BarycentricMapperHexahedronSetTopology.h new file mode 100644 index 00000000000..71036c23c81 --- /dev/null +++ b/SofaKernel/modules/SofaBaseMechanics/BarycentricMappers/BarycentricMapperHexahedronSetTopology.h @@ -0,0 +1,123 @@ +/****************************************************************************** +* SOFA, Simulation Open-Framework Architecture, development version * +* (c) 2006-2018 INRIA, USTL, UJF, CNRS, MGH * +* * +* This program is free software; you can redistribute it and/or modify it * +* under the terms of the GNU Lesser General Public License as published by * +* the Free Software Foundation; either version 2.1 of the License, or (at * +* your option) any later version. * +* * +* This program is distributed in the hope that it will be useful, but WITHOUT * +* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * +* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License * +* for more details. * +* * +* You should have received a copy of the GNU Lesser General Public License * +* along with this program. If not, see . * +******************************************************************************* +* Authors: The SOFA Team and external contributors (see Authors.txt) * +* * +* Contact information: contact@sofa-framework.org * +******************************************************************************/ +#ifndef SOFA_COMPONENT_MAPPING_BARYCENTRICMAPPERHEXAHEDRONSETTOPOLOGY_H +#define SOFA_COMPONENT_MAPPING_BARYCENTRICMAPPERHEXAHEDRONSETTOPOLOGY_H + +#include +#include +#include + +namespace sofa +{ + +namespace component +{ + +namespace mapping +{ + +using sofa::defaulttype::Mat3x3d; +using sofa::defaulttype::Vector3; +typedef typename sofa::core::topology::BaseMeshTopology::Hexahedron Hexahedron; + +/// Class allowing barycentric mapping computation on a HexahedronSetTopology +template +class SOFA_BASE_MECHANICS_API BarycentricMapperHexahedronSetTopology : public BarycentricMapperTopologyContainer::MappingData3D,Hexahedron> +{ + +public: + + typedef typename BarycentricMapper::MappingData3D MappingData; + SOFA_CLASS(SOFA_TEMPLATE2(BarycentricMapperHexahedronSetTopology,In,Out),SOFA_TEMPLATE4(BarycentricMapperTopologyContainer,In,Out,MappingData,Hexahedron)); + typedef typename Inherit1::Real Real; + +protected: + + topology::HexahedronSetTopologyContainer* m_fromContainer; + topology::HexahedronSetGeometryAlgorithms* m_fromGeomAlgo; + std::set m_invalidIndex; + + using Inherit1::d_map; + using Inherit1::m_matrixJ; + using Inherit1::m_updateJ; + using Inherit1::m_fromTopology; + + BarycentricMapperHexahedronSetTopology() + : Inherit1(nullptr, nullptr), + m_fromContainer(nullptr), + m_fromGeomAlgo(nullptr) + {} + + BarycentricMapperHexahedronSetTopology(topology::HexahedronSetTopologyContainer* fromTopology, topology::PointSetTopologyContainer* toTopology) + : Inherit1(fromTopology, toTopology), + m_fromContainer(fromTopology), + m_fromGeomAlgo(nullptr) + {} + + virtual ~BarycentricMapperHexahedronSetTopology() override {} + + virtual helper::vector getElements() override; + virtual helper::vector getBaryCoef(const Real* f) override; + helper::vector getBaryCoef(const Real fx, const Real fy, const Real fz); + virtual void computeBase(Mat3x3d& base, const typename In::VecCoord& in, const Hexahedron& element) override; + virtual void computeCenter(Vector3& center, const typename In::VecCoord& in, const Hexahedron& element) override; + virtual void computeDistance(double& d, const Vector3& v) override; + virtual void addPointInElement(const int elementIndex, const SReal* baryCoords) override; + +public: + + virtual int addPointInCube(const int index, const SReal* baryCoords) override; + virtual int setPointInCube(const int pointIndex, const int cubeIndex, const SReal* baryCoords) override; + virtual void applyOnePoint( const unsigned int& hexaId, typename Out::VecCoord& out, const typename In::VecCoord& in) override; + virtual void handleTopologyChange(core::topology::Topology* t) override; + + void setTopology(topology::HexahedronSetTopologyContainer* topology) + { + m_fromTopology = topology; + m_fromContainer = topology; + } +}; + +using sofa::defaulttype::Vec3dTypes; +using sofa::defaulttype::Vec3fTypes; +using sofa::defaulttype::ExtVec3fTypes; + +#if defined(SOFA_EXTERN_TEMPLATE) && !defined(SOFA_COMPONENT_MAPPING_BARYCENTRICMAPPERHEXAHEDRONSETTOPOLOGY_CPP) +#ifndef SOFA_FLOAT +extern template class SOFA_BASE_MECHANICS_API BarycentricMapperHexahedronSetTopology< Vec3dTypes, Vec3dTypes >; +extern template class SOFA_BASE_MECHANICS_API BarycentricMapperHexahedronSetTopology< Vec3dTypes, ExtVec3fTypes >; +#endif +#ifndef SOFA_DOUBLE +extern template class SOFA_BASE_MECHANICS_API BarycentricMapperHexahedronSetTopology< Vec3fTypes, Vec3fTypes >; +extern template class SOFA_BASE_MECHANICS_API BarycentricMapperHexahedronSetTopology< Vec3fTypes, ExtVec3fTypes >; +#endif +#ifndef SOFA_FLOAT +#ifndef SOFA_DOUBLE +extern template class SOFA_BASE_MECHANICS_API BarycentricMapperHexahedronSetTopology< Vec3dTypes, Vec3fTypes >; +extern template class SOFA_BASE_MECHANICS_API BarycentricMapperHexahedronSetTopology< Vec3fTypes, Vec3dTypes >; +#endif +#endif +#endif + +}}} + +#endif diff --git a/SofaKernel/modules/SofaBaseMechanics/BarycentricMappers/BarycentricMapperHexahedronSetTopology.inl b/SofaKernel/modules/SofaBaseMechanics/BarycentricMappers/BarycentricMapperHexahedronSetTopology.inl new file mode 100644 index 00000000000..49f382c66b1 --- /dev/null +++ b/SofaKernel/modules/SofaBaseMechanics/BarycentricMappers/BarycentricMapperHexahedronSetTopology.inl @@ -0,0 +1,315 @@ +/****************************************************************************** +* SOFA, Simulation Open-Framework Architecture, development version * +* (c) 2006-2018 INRIA, USTL, UJF, CNRS, MGH * +* * +* This program is free software; you can redistribute it and/or modify it * +* under the terms of the GNU Lesser General Public License as published by * +* the Free Software Foundation; either version 2.1 of the License, or (at * +* your option) any later version. * +* * +* This program is distributed in the hope that it will be useful, but WITHOUT * +* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * +* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License * +* for more details. * +* * +* You should have received a copy of the GNU Lesser General Public License * +* along with this program. If not, see . * +******************************************************************************* +* Authors: The SOFA Team and external contributors (see Authors.txt) * +* * +* Contact information: contact@sofa-framework.org * +******************************************************************************/ +#ifndef SOFA_COMPONENT_MAPPING_BARYCENTRICMAPPERHEXAHEDRONSETTOPOLOGY_INL +#define SOFA_COMPONENT_MAPPING_BARYCENTRICMAPPERHEXAHEDRONSETTOPOLOGY_INL + +#include "BarycentricMapperHexahedronSetTopology.h" + +namespace sofa +{ + +namespace component +{ + +namespace mapping +{ + + +template +int BarycentricMapperHexahedronSetTopology::addPointInCube ( const int cubeIndex, const SReal* baryCoords ) +{ + helper::vector& vectorData = *(d_map.beginEdit()); + vectorData.resize ( d_map.getValue().size() +1 ); + MappingData& data = *vectorData.rbegin(); + d_map.endEdit(); + data.in_index = cubeIndex; + data.baryCoords[0] = ( Real ) baryCoords[0]; + data.baryCoords[1] = ( Real ) baryCoords[1]; + data.baryCoords[2] = ( Real ) baryCoords[2]; + return (int)d_map.getValue().size()-1; +} + + +template +int BarycentricMapperHexahedronSetTopology::setPointInCube ( const int pointIndex, const int cubeIndex, const SReal* baryCoords ) +{ + if ( pointIndex >= ( int ) d_map.getValue().size() ) + return -1; + + helper::vector& vectorData = *(d_map.beginEdit()); + MappingData& data = vectorData[pointIndex]; + data.in_index = cubeIndex; + data.baryCoords[0] = ( Real ) baryCoords[0]; + data.baryCoords[1] = ( Real ) baryCoords[1]; + data.baryCoords[2] = ( Real ) baryCoords[2]; + d_map.endEdit(); + + if(cubeIndex == -1) + m_invalidIndex.insert(pointIndex); + else + m_invalidIndex.erase(pointIndex); + + return pointIndex; +} + + +template +helper::vector BarycentricMapperHexahedronSetTopology::getElements() +{ + return this->m_fromTopology->getHexahedra(); +} + + +template +helper::vector BarycentricMapperHexahedronSetTopology::getBaryCoef(const Real* f) +{ + return getBaryCoef(f[0],f[1],f[2]); +} + + +template +helper::vector BarycentricMapperHexahedronSetTopology::getBaryCoef(const Real fx, const Real fy, const Real fz) +{ + helper::vector hexahedronCoef{(1-fx)*(1-fy)*(1-fz), + (fx)*(1-fy)*(1-fz), + (1-fx)*(fy)*(1-fz), + (fx)*(fy)*(1-fz), + (1-fx)*(1-fy)*(fz), + (fx)*(1-fy)*(fz), + (1-fx)*(fy)*(fz), + (fx)*(fy)*(fz)}; + return hexahedronCoef; +} + + +template +void BarycentricMapperHexahedronSetTopology::computeBase(Mat3x3d& base, const typename In::VecCoord& in, const Hexahedron& element) +{ + Mat3x3d matrixTranspose; + base[0] = in[element[1]]-in[element[0]]; + base[1] = in[element[3]]-in[element[0]]; + base[2] = in[element[4]]-in[element[0]]; + matrixTranspose.transpose(base); + base.invert(matrixTranspose); +} + + +template +void BarycentricMapperHexahedronSetTopology::computeCenter(Vector3& center, const typename In::VecCoord& in, const Hexahedron &element) +{ + center = ( in[element[0]]+in[element[1]]+in[element[2]]+in[element[3]]+in[element[4]]+in[element[5]]+in[element[6]]+in[element[7]] ) *0.125; +} + + +template +void BarycentricMapperHexahedronSetTopology::computeDistance(double& d, const Vector3& v) +{ + d = std::max ( std::max ( -v[0],-v[1] ),std::max ( std::max ( -v[2],v[0]-1 ),std::max ( v[1]-1,v[2]-1 ) ) ); +} + + +template +void BarycentricMapperHexahedronSetTopology::addPointInElement(const int elementIndex, const SReal* baryCoords) +{ + addPointInCube(elementIndex,baryCoords); +} + + + +template +void BarycentricMapperHexahedronSetTopology::handleTopologyChange(core::topology::Topology* t) +{ + using sofa::core::behavior::MechanicalState; + + if (t != this->m_fromTopology) return; + + if ( this->m_fromTopology->beginChange() == this->m_fromTopology->endChange() ) + return; + + std::list::const_iterator itBegin = this->m_fromTopology->beginChange(); + std::list::const_iterator itEnd = this->m_fromTopology->endChange(); + + for ( std::list::const_iterator changeIt = itBegin; + changeIt != itEnd; ++changeIt ) + { + const core::topology::TopologyChangeType changeType = ( *changeIt )->getChangeType(); + switch ( changeType ) + { + //TODO: implementation of BarycentricMapperHexahedronSetTopology::handleTopologyChange() + case core::topology::ENDING_EVENT: ///< To notify the end for the current sequence of topological change events + { + if(!m_invalidIndex.empty()) + { + helper::vector& mapData = *(d_map.beginEdit()); + + for ( std::set::const_iterator iter = m_invalidIndex.begin(); + iter != m_invalidIndex.end(); ++iter ) + { + const int j = *iter; + if ( mapData[j].in_index == -1 ) // compute new mapping + { + Vector3 coefs; + typename In::Coord pos; + pos[0] = mapData[j].baryCoords[0]; + pos[1] = mapData[j].baryCoords[1]; + pos[2] = mapData[j].baryCoords[2]; + + // find nearest cell and barycentric coords + Real distance = 1e10; + + int index = -1; + // When smoothing a mesh, the element has to be found using the rest position of the point. Then, its position is set using this element. + if( this->toTopology) + { + typedef MechanicalState MechanicalStateT; + MechanicalStateT* mState; + this->toTopology->getContext()->get( mState); + if( !mState) + { + msg_error() << "Can not find mechanical state." ; + } + else + { + const typename MechanicalStateT::VecCoord& xto0 = (mState->read(core::ConstVecCoordId::restPosition())->getValue()); + index = m_fromGeomAlgo->findNearestElementInRestPos ( Out::getCPos(xto0[j]), coefs, distance ); + coefs = m_fromGeomAlgo->computeHexahedronRestBarycentricCoeficients(index, pos); + } + } + else + { + index = m_fromGeomAlgo->findNearestElementInRestPos ( pos, coefs, distance ); + } + + if ( index != -1 ) + { + mapData[j].baryCoords[0] = ( Real ) coefs[0]; + mapData[j].baryCoords[1] = ( Real ) coefs[1]; + mapData[j].baryCoords[2] = ( Real ) coefs[2]; + mapData[j].in_index = index; + } + } + } + + d_map.endEdit(); + m_invalidIndex.clear(); + } + } + break; + case core::topology::POINTSINDICESSWAP: ///< For PointsIndicesSwap. + break; + case core::topology::POINTSADDED: ///< For PointsAdded. + break; + case core::topology::POINTSREMOVED: ///< For PointsRemoved. + break; + case core::topology::POINTSRENUMBERING: ///< For PointsRenumbering. + break; + case core::topology::TRIANGLESADDED: ///< For Triangles Added. + break; + case core::topology::TRIANGLESREMOVED: ///< For Triangles Removed. + break; + case core::topology::HEXAHEDRAADDED: ///< For HexahedraAdded. + { + } + break; + case core::topology::HEXAHEDRAREMOVED: ///< For HexahedraRemoved. + { + const unsigned int nbHexahedra = this->m_fromTopology->getNbHexahedra(); + + const helper::vector &hexahedra = + ( static_cast< const core::topology::HexahedraRemoved *> ( *changeIt ) )->getArray(); + // helper::vector hexahedra(tab); + + for ( unsigned int i=0; igetRestPointPositionInHexahedron ( cubeId, coefs ); + + helper::vector& vectorData = *(d_map.beginEdit()); + vectorData[j].in_index = -1; + vectorData[j].baryCoords[0] = restPos[0]; + vectorData[j].baryCoords[1] = restPos[1]; + vectorData[j].baryCoords[2] = restPos[2]; + d_map.endEdit(); + + m_invalidIndex.insert(j); + } + } + } + + // renumber + unsigned int lastCubeId = nbHexahedra-1; + for ( unsigned int i=0; i& vectorData = *(d_map.beginEdit()); + vectorData[j].in_index = cubeId; + d_map.endEdit(); + } + } + } + } + break; + case core::topology::HEXAHEDRARENUMBERING: ///< For HexahedraRenumbering. + break; + default: + break; + } + } +} + +template +void BarycentricMapperHexahedronSetTopology::applyOnePoint( const unsigned int& hexaPointId,typename Out::VecCoord& out, const typename In::VecCoord& in ) +{ + const helper::vector& cubes = this->m_fromTopology->getHexahedra(); + const Real fx = d_map.getValue()[hexaPointId].baryCoords[0]; + const Real fy = d_map.getValue()[hexaPointId].baryCoords[1]; + const Real fz = d_map.getValue()[hexaPointId].baryCoords[2]; + int index = d_map.getValue()[hexaPointId].in_index; + const Hexahedron& cube = cubes[index]; + Out::setCPos(out[hexaPointId] , in[cube[0]] * ( ( 1-fx ) * ( 1-fy ) * ( 1-fz ) ) + + in[cube[1]] * ( ( fx ) * ( 1-fy ) * ( 1-fz ) ) + + in[cube[3]] * ( ( 1-fx ) * ( fy ) * ( 1-fz ) ) + + in[cube[2]] * ( ( fx ) * ( fy ) * ( 1-fz ) ) + + in[cube[4]] * ( ( 1-fx ) * ( 1-fy ) * ( fz ) ) + + in[cube[5]] * ( ( fx ) * ( 1-fy ) * ( fz ) ) + + in[cube[7]] * ( ( 1-fx ) * ( fy ) * ( fz ) ) + + in[cube[6]] * ( ( fx ) * ( fy ) * ( fz ) ) ); +} + + +}}} + +#endif diff --git a/SofaKernel/modules/SofaBaseMechanics/BarycentricMappers/BarycentricMapperMeshTopology.cpp b/SofaKernel/modules/SofaBaseMechanics/BarycentricMappers/BarycentricMapperMeshTopology.cpp new file mode 100644 index 00000000000..3756723d61e --- /dev/null +++ b/SofaKernel/modules/SofaBaseMechanics/BarycentricMappers/BarycentricMapperMeshTopology.cpp @@ -0,0 +1,56 @@ +/****************************************************************************** +* SOFA, Simulation Open-Framework Architecture, development version * +* (c) 2006-2018 INRIA, USTL, UJF, CNRS, MGH * +* * +* This program is free software; you can redistribute it and/or modify it * +* under the terms of the GNU Lesser General Public License as published by * +* the Free Software Foundation; either version 2.1 of the License, or (at * +* your option) any later version. * +* * +* This program is distributed in the hope that it will be useful, but WITHOUT * +* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * +* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License * +* for more details. * +* * +* You should have received a copy of the GNU Lesser General Public License * +* along with this program. If not, see . * +******************************************************************************* +* Authors: The SOFA Team and external contributors (see Authors.txt) * +* * +* Contact information: contact@sofa-framework.org * +******************************************************************************/ +#ifndef SOFA_COMPONENT_MAPPING_BARYCENTRICMAPPERMESHTOPOLOGY_CPP +#define SOFA_COMPONENT_MAPPING_BARYCENTRICMAPPERMESHTOPOLOGY_CPP + +#include "BarycentricMapperMeshTopology.inl" + +namespace sofa +{ + +namespace component +{ + +namespace mapping +{ + +using namespace sofa::defaulttype; + +#ifndef SOFA_FLOAT +template class SOFA_BASE_MECHANICS_API BarycentricMapperMeshTopology< Vec3dTypes, Vec3dTypes >; +template class SOFA_BASE_MECHANICS_API BarycentricMapperMeshTopology< Vec3dTypes, ExtVec3fTypes >; +#endif +#ifndef SOFA_DOUBLE +template class SOFA_BASE_MECHANICS_API BarycentricMapperMeshTopology< Vec3fTypes, Vec3fTypes >; +template class SOFA_BASE_MECHANICS_API BarycentricMapperMeshTopology< Vec3fTypes, ExtVec3fTypes >; +#endif +#ifndef SOFA_FLOAT +#ifndef SOFA_DOUBLE +template class SOFA_BASE_MECHANICS_API BarycentricMapperMeshTopology< Vec3dTypes, Vec3fTypes >; +template class SOFA_BASE_MECHANICS_API BarycentricMapperMeshTopology< Vec3fTypes, Vec3dTypes >; +#endif +#endif + +}}} + + +#endif diff --git a/SofaKernel/modules/SofaBaseMechanics/BarycentricMappers/BarycentricMapperMeshTopology.h b/SofaKernel/modules/SofaBaseMechanics/BarycentricMappers/BarycentricMapperMeshTopology.h new file mode 100644 index 00000000000..196b43de4a9 --- /dev/null +++ b/SofaKernel/modules/SofaBaseMechanics/BarycentricMappers/BarycentricMapperMeshTopology.h @@ -0,0 +1,199 @@ +/****************************************************************************** +* SOFA, Simulation Open-Framework Architecture, development version * +* (c) 2006-2018 INRIA, USTL, UJF, CNRS, MGH * +* * +* This program is free software; you can redistribute it and/or modify it * +* under the terms of the GNU Lesser General Public License as published by * +* the Free Software Foundation; either version 2.1 of the License, or (at * +* your option) any later version. * +* * +* This program is distributed in the hope that it will be useful, but WITHOUT * +* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * +* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License * +* for more details. * +* * +* You should have received a copy of the GNU Lesser General Public License * +* along with this program. If not, see . * +******************************************************************************* +* Authors: The SOFA Team and external contributors (see Authors.txt) * +* * +* Contact information: contact@sofa-framework.org * +******************************************************************************/ +#ifndef SOFA_COMPONENT_MAPPING_BARYCENTRICMAPPERMESHTOPOLOGY_H +#define SOFA_COMPONENT_MAPPING_BARYCENTRICMAPPERMESHTOPOLOGY_H + +#include + +namespace sofa +{ + +namespace component +{ + +namespace mapping +{ + +using core::visual::VisualParams; +using sofa::defaulttype::BaseMatrix; + +/// Class allowing barycentric mapping computation on a MeshTopology +template +class SOFA_BASE_MECHANICS_API BarycentricMapperMeshTopology : public TopologyBarycentricMapper +{ +public: + SOFA_CLASS(SOFA_TEMPLATE2(BarycentricMapperMeshTopology,In,Out),SOFA_TEMPLATE2(TopologyBarycentricMapper,In,Out)); + + typedef typename Inherit1::Real Real; + typedef typename Inherit1::OutReal OutReal; + typedef typename Inherit1::OutDeriv OutDeriv; + + typedef typename Inherit1::InDeriv InDeriv; + typedef typename Inherit1::MappingData1D MappingData1D; + typedef typename Inherit1::MappingData2D MappingData2D; + typedef typename Inherit1::MappingData3D MappingData3D; + + enum { NIn = Inherit1::NIn }; + enum { NOut = Inherit1::NOut }; + typedef typename Inherit1::MBloc MBloc; + typedef typename Inherit1::MatrixType MatrixType; + typedef typename MatrixType::Index MatrixTypeIndex; + + typedef typename Inherit1::ForceMask ForceMask; + + +public: + + virtual void clear(int reserve=0) override; + virtual void resize( core::State* toModel ) override; + virtual int addPointInLine(const int lineIndex, const SReal* baryCoords) override; + virtual int createPointInLine(const typename Out::Coord& p, int lineIndex, const typename In::VecCoord* points) override; + virtual int addPointInTriangle(const int triangleIndex, const SReal* baryCoords) override; + virtual int createPointInTriangle(const typename Out::Coord& p, int triangleIndex, const typename In::VecCoord* points) override; + virtual int addPointInQuad(const int quadIndex, const SReal* baryCoords) override; + virtual int createPointInQuad(const typename Out::Coord& p, int quadIndex, const typename In::VecCoord* points) override; + virtual int addPointInTetra(const int tetraIndex, const SReal* baryCoords) override; + virtual int addPointInCube(const int cubeIndex, const SReal* baryCoords) override; + + virtual void init(const typename Out::VecCoord& out, const typename In::VecCoord& in) override; + virtual void draw(const core::visual::VisualParams*,const typename Out::VecCoord& out, const typename In::VecCoord& in) override; + + virtual void apply( typename Out::VecCoord& out, const typename In::VecCoord& in ) override; + virtual void applyJ( typename Out::VecDeriv& out, const typename In::VecDeriv& in ) override; + virtual void applyJT( typename In::VecDeriv& out, const typename Out::VecDeriv& in ) override; + virtual void applyJT( typename In::MatrixDeriv& out, const typename Out::MatrixDeriv& in ) override; + virtual const BaseMatrix* getJ(int outSize, int inSize) override; + + sofa::helper::vector< MappingData3D > const* getMap3d() const { return &m_map3d; } + + inline friend std::istream& operator >> ( std::istream& in, BarycentricMapperMeshTopology &b ) + { + unsigned int size_vec; + in >> size_vec; + b.m_map1d.clear(); + MappingData1D value1d; + for (unsigned int i=0; i> value1d; + b.m_map1d.push_back(value1d); + } + + in >> size_vec; + b.m_map2d.clear(); + MappingData2D value2d; + for (unsigned int i=0; i> value2d; + b.m_map2d.push_back(value2d); + } + + in >> size_vec; + b.m_map3d.clear(); + MappingData3D value3d; + for (unsigned int i=0; i> value3d; + b.m_map3d.push_back(value3d); + } + return in; + } + + inline friend std::ostream& operator << ( std::ostream& out, const BarycentricMapperMeshTopology & b ) + { + + out << b.m_map1d.size(); + out << " " ; + out << b.m_map1d; + out << " " ; + out << b.m_map2d.size(); + out << " " ; + out << b.m_map2d; + out << " " ; + out << b.m_map3d.size(); + out << " " ; + out << b.m_map3d; + + return out; + } + +protected: + + void addMatrixContrib(MatrixType* m, int row, int col, Real value) + { + Inherit1::addMatrixContrib(m, row, col, value); + } + + sofa::helper::vector< MappingData1D > m_map1d; + sofa::helper::vector< MappingData2D > m_map2d; + sofa::helper::vector< MappingData3D > m_map3d; + + MatrixType* m_matrixJ; + bool m_updateJ; + + BarycentricMapperMeshTopology(core::topology::BaseMeshTopology* fromTopology, + topology::PointSetTopologyContainer* toTopology) + : TopologyBarycentricMapper(fromTopology, toTopology), + m_matrixJ(NULL), m_updateJ(true) + { + } + + virtual ~BarycentricMapperMeshTopology() override + { + if (m_matrixJ) delete m_matrixJ; + } + + +private: + + void clearMap1dAndReserve(int size=0); + void clearMap2dAndReserve(int size=0); + void clearMap3dAndReserve(int size=0); + +}; + + +using sofa::defaulttype::Vec3dTypes; +using sofa::defaulttype::Vec3fTypes; +using sofa::defaulttype::ExtVec3fTypes; + + +#if defined(SOFA_EXTERN_TEMPLATE) && !defined(SOFA_COMPONENT_MAPPING_BARYCENTRICMAPPERMESHTOPOLOGY_CPP) +#ifndef SOFA_FLOAT +extern template class SOFA_BASE_MECHANICS_API BarycentricMapperMeshTopology< Vec3dTypes, Vec3dTypes >; +extern template class SOFA_BASE_MECHANICS_API BarycentricMapperMeshTopology< Vec3dTypes, ExtVec3fTypes >; +#endif +#ifndef SOFA_DOUBLE +extern template class SOFA_BASE_MECHANICS_API BarycentricMapperMeshTopology< Vec3fTypes, Vec3fTypes >; +extern template class SOFA_BASE_MECHANICS_API BarycentricMapperMeshTopology< Vec3fTypes, ExtVec3fTypes >; +#endif +#ifndef SOFA_FLOAT +#ifndef SOFA_DOUBLE +extern template class SOFA_BASE_MECHANICS_API BarycentricMapperMeshTopology< Vec3dTypes, Vec3fTypes >; +extern template class SOFA_BASE_MECHANICS_API BarycentricMapperMeshTopology< Vec3fTypes, Vec3dTypes >; +#endif +#endif +#endif + +}}} + + +#endif diff --git a/SofaKernel/modules/SofaBaseMechanics/BarycentricMappers/BarycentricMapperMeshTopology.inl b/SofaKernel/modules/SofaBaseMechanics/BarycentricMappers/BarycentricMapperMeshTopology.inl new file mode 100644 index 00000000000..d983c6e88e7 --- /dev/null +++ b/SofaKernel/modules/SofaBaseMechanics/BarycentricMappers/BarycentricMapperMeshTopology.inl @@ -0,0 +1,1093 @@ +/****************************************************************************** +* SOFA, Simulation Open-Framework Architecture, development version * +* (c) 2006-2018 INRIA, USTL, UJF, CNRS, MGH * +* * +* This program is free software; you can redistribute it and/or modify it * +* under the terms of the GNU Lesser General Public License as published by * +* the Free Software Foundation; either version 2.1 of the License, or (at * +* your option) any later version. * +* * +* This program is distributed in the hope that it will be useful, but WITHOUT * +* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * +* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License * +* for more details. * +* * +* You should have received a copy of the GNU Lesser General Public License * +* along with this program. If not, see . * +******************************************************************************* +* Authors: The SOFA Team and external contributors (see Authors.txt) * +* * +* Contact information: contact@sofa-framework.org * +******************************************************************************/ +#ifndef SOFA_COMPONENT_MAPPING_BARYCENTRICMAPPERMESHTOPOLOGY_INL +#define SOFA_COMPONENT_MAPPING_BARYCENTRICMAPPERMESHTOPOLOGY_INL + +#include "BarycentricMapperMeshTopology.h" + +namespace sofa +{ + +namespace component +{ + +namespace mapping +{ + +using sofa::defaulttype::Vector3; +using sofa::core::visual::VisualParams; +using sofa::defaulttype::Vec; +using sofa::defaulttype::Vector3; +using sofa::defaulttype::Matrix3; +using sofa::defaulttype::Mat3x3d; +using sofa::defaulttype::Vec3d; +typedef typename sofa::core::topology::BaseMeshTopology::Edge Edge; +typedef typename sofa::core::topology::BaseMeshTopology::Line Line; +typedef typename sofa::core::topology::BaseMeshTopology::Triangle Triangle; +typedef typename sofa::core::topology::BaseMeshTopology::Quad Quad; +typedef typename sofa::core::topology::BaseMeshTopology::Tetrahedron Tetrahedron; +typedef typename sofa::core::topology::BaseMeshTopology::Tetra Tetra; +typedef typename sofa::core::topology::BaseMeshTopology::Hexahedron Hexahedron; +typedef typename sofa::core::topology::BaseMeshTopology::Hexa Hexa; +typedef typename sofa::core::topology::BaseMeshTopology::SeqLines SeqLines; +typedef typename sofa::core::topology::BaseMeshTopology::SeqEdges SeqEdges; +typedef typename sofa::core::topology::BaseMeshTopology::SeqTriangles SeqTriangles; +typedef typename sofa::core::topology::BaseMeshTopology::SeqQuads SeqQuads; +typedef typename sofa::core::topology::BaseMeshTopology::SeqTetrahedra SeqTetrahedra; +typedef typename sofa::core::topology::BaseMeshTopology::SeqHexahedra SeqHexahedra; + + +template +void BarycentricMapperMeshTopology::init ( const typename Out::VecCoord& out, const typename In::VecCoord& in ) +{ + m_updateJ = true; + + const SeqTetrahedra& tetras = this->m_fromTopology->getTetrahedra(); + const SeqHexahedra& hexas = this->m_fromTopology->getHexahedra(); + + const SeqTriangles& triangles = this->m_fromTopology->getTriangles(); + const SeqQuads& quads = this->m_fromTopology->getQuads(); + helper::vector bases; + helper::vector centers; + if ( tetras.empty() && hexas.empty() ) + { + if ( triangles.empty() && quads.empty() ) + { + const SeqEdges& edges = this->m_fromTopology->getEdges(); + if ( edges.empty() ) return; + + clearMap1dAndReserve ( (int)out.size() ); + + helper::vector< SReal > lengthEdges; + helper::vector< Vector3 > unitaryVectors; + + unsigned int e; + for ( e=0; e= 0 && coef <= 1 ) {addPointInLine ( e,&coef ); break; } + } + //If no good coefficient has been found, we add to the last element + if ( e == edges.size() ) addPointInLine ( (int)edges.size()-1,&coef ); + } + } + else + { + clearMap2dAndReserve ( int(out.size()) ); + size_t nbTriangles = triangles.size(); + bases.resize ( triangles.size() +quads.size() ); + centers.resize ( triangles.size() +quads.size() ); + for ( unsigned int t = 0; t < triangles.size(); t++ ) + { + Mat3x3d m,mt; + m[0] = in[triangles[t][1]]-in[triangles[t][0]]; + m[1] = in[triangles[t][2]]-in[triangles[t][0]]; + m[2] = cross ( m[0],m[1] ); + mt.transpose ( m ); + bases[t].invert ( mt ); + centers[t] = ( in[triangles[t][0]]+in[triangles[t][1]]+in[triangles[t][2]] ) /3; + } + for ( unsigned int q = 0; q < quads.size(); q++ ) + { + Mat3x3d m,mt; + m[0] = in[quads[q][1]]-in[quads[q][0]]; + m[1] = in[quads[q][3]]-in[quads[q][0]]; + m[2] = cross ( m[0],m[1] ); + mt.transpose ( m ); + bases[nbTriangles+q].invert ( mt ); + centers[nbTriangles+q] = ( in[quads[q][0]]+in[quads[q][1]]+in[quads[q][2]]+in[quads[q][3]] ) *0.25; + } + for ( unsigned int i=0; i0 ) d = ( outPos-centers[t] ).norm2(); + if ( d0 ) d = ( outPos-centers[nbTriangles+q] ).norm2(); + if ( d0 ) d = ( pos-centers[t] ).norm2(); + if ( d0 ) d = ( pos-centers[nbTetras+h] ).norm2(); + if ( d +void BarycentricMapperMeshTopology::clearMap1dAndReserve ( int size ) +{ + m_updateJ = true; + m_map1d.clear(); + if ( size>0 ) m_map1d.reserve ( size ); +} + + +template +void BarycentricMapperMeshTopology::clearMap2dAndReserve ( int size ) +{ + m_updateJ = true; + m_map2d.clear(); + if ( size>0 ) m_map2d.reserve ( size ); +} + + +template +void BarycentricMapperMeshTopology::clearMap3dAndReserve ( int size ) +{ + m_updateJ = true; + m_map3d.clear(); + if ( size>0 ) m_map3d.reserve ( size ); +} + + +template +void BarycentricMapperMeshTopology::clear ( int size ) +{ + m_updateJ = true; + clearMap1dAndReserve(size); + clearMap2dAndReserve(size); + clearMap3dAndReserve(size); +} + + +template +int BarycentricMapperMeshTopology::addPointInLine ( const int lineIndex, const SReal* baryCoords ) +{ + m_map1d.resize ( m_map1d.size() +1 ); + MappingData1D& data = *m_map1d.rbegin(); + data.in_index = lineIndex; + data.baryCoords[0] = ( Real ) baryCoords[0]; + return (int)m_map1d.size()-1; +} + + +template +int BarycentricMapperMeshTopology::addPointInTriangle ( const int triangleIndex, const SReal* baryCoords ) +{ + m_map2d.resize ( m_map2d.size() +1 ); + MappingData2D& data = *m_map2d.rbegin(); + data.in_index = triangleIndex; + data.baryCoords[0] = ( Real ) baryCoords[0]; + data.baryCoords[1] = ( Real ) baryCoords[1]; + return (int)m_map2d.size()-1; +} + + +template +int BarycentricMapperMeshTopology::addPointInQuad ( const int quadIndex, const SReal* baryCoords ) +{ + m_map2d.resize ( m_map2d.size() +1 ); + MappingData2D& data = *m_map2d.rbegin(); + data.in_index = quadIndex + this->m_fromTopology->getNbTriangles(); + data.baryCoords[0] = ( Real ) baryCoords[0]; + data.baryCoords[1] = ( Real ) baryCoords[1]; + return (int)m_map2d.size()-1; +} + + +template +int BarycentricMapperMeshTopology::addPointInTetra ( const int tetraIndex, const SReal* baryCoords ) +{ + m_map3d.resize ( m_map3d.size() +1 ); + MappingData3D& data = *m_map3d.rbegin(); + data.in_index = tetraIndex; + data.baryCoords[0] = ( Real ) baryCoords[0]; + data.baryCoords[1] = ( Real ) baryCoords[1]; + data.baryCoords[2] = ( Real ) baryCoords[2]; + return (int)m_map3d.size()-1; +} + + +template +int BarycentricMapperMeshTopology::addPointInCube ( const int cubeIndex, const SReal* baryCoords ) +{ + m_map3d.resize ( m_map3d.size() +1 ); + MappingData3D& data = *m_map3d.rbegin(); + data.in_index = cubeIndex + this->m_fromTopology->getNbTetrahedra(); + data.baryCoords[0] = ( Real ) baryCoords[0]; + data.baryCoords[1] = ( Real ) baryCoords[1]; + data.baryCoords[2] = ( Real ) baryCoords[2]; + return (int)m_map3d.size()-1; +} + + +template +int BarycentricMapperMeshTopology::createPointInLine ( const typename Out::Coord& p, int lineIndex, const typename In::VecCoord* points ) +{ + SReal baryCoords[1]; + const Line& elem = this->m_fromTopology->getLine ( lineIndex ); + const typename In::Coord p0 = ( *points ) [elem[0]]; + const typename In::Coord pA = ( *points ) [elem[1]] - p0; + typename In::Coord pos = Out::getCPos(p) - p0; + baryCoords[0] = ( ( pos*pA ) /pA.norm2() ); + return this->addPointInLine ( lineIndex, baryCoords ); +} + + +template +int BarycentricMapperMeshTopology::createPointInTriangle ( const typename Out::Coord& p, int triangleIndex, const typename In::VecCoord* points ) +{ + SReal baryCoords[2]; + const Triangle& elem = this->m_fromTopology->getTriangle ( triangleIndex ); + + const typename In::Coord & p1 = ( *points ) [elem[0]]; + const typename In::Coord & p2 = ( *points ) [elem[1]]; + const typename In::Coord & p3 = ( *points ) [elem[2]]; + const typename In::Coord & to_be_projected = Out::getCPos(p); + + const typename In::Coord AB = p2-p1; + const typename In::Coord AC = p3-p1; + const typename In::Coord AQ = to_be_projected -p1; + sofa::defaulttype::Mat<2,2,typename In::Real> A; + sofa::defaulttype::Vec<2,typename In::Real> b; + A[0][0] = AB*AB; + A[1][1] = AC*AC; + A[0][1] = A[1][0] = AB*AC; + b[0] = AQ*AB; + b[1] = AQ*AC; + const typename In::Real det = sofa::defaulttype::determinant(A); + + baryCoords[0] = (b[0]*A[1][1] - b[1]*A[0][1])/det; + baryCoords[1] = (b[1]*A[0][0] - b[0]*A[1][0])/det; + + if (baryCoords[0] < 0 || baryCoords[1] < 0 || baryCoords[0] + baryCoords[1] > 1) + { + // nearest point is on an edge or corner + // barycentric coordinate on AB + SReal pAB = b[0] / A[0][0]; // AQ*AB / AB*AB + // barycentric coordinate on AC + SReal pAC = b[1] / A[1][1]; // AQ*AC / AB*AB + if (pAB < 0 && pAC < 0) + { + // closest point is A + baryCoords[0] = 0.0; + baryCoords[1] = 0.0; + } + else if (pAB < 1 && baryCoords[1] < 0) + { + // closest point is on AB + baryCoords[0] = pAB; + baryCoords[1] = 0.0; + } + else if (pAC < 1 && baryCoords[0] < 0) + { + // closest point is on AC + baryCoords[0] = 0.0; + baryCoords[1] = pAC; + } + else + { + // barycentric coordinate on BC + // BQ*BC / BC*BC = (AQ-AB)*(AC-AB) / (AC-AB)*(AC-AB) = (AQ*AC-AQ*AB + AB*AB-AB*AC) / (AB*AB+AC*AC-2AB*AC) + SReal pBC = (b[1] - b[0] + A[0][0] - A[0][1]) / (A[0][0] + A[1][1] - 2*A[0][1]); // BQ*BC / BC*BC + if (pBC < 0) + { + // closest point is B + baryCoords[0] = 1.0; + baryCoords[1] = 0.0; + } + else if (pBC > 1) + { + // closest point is C + baryCoords[0] = 0.0; + baryCoords[1] = 1.0; + } + else + { + // closest point is on BC + baryCoords[0] = 1.0-pBC; + baryCoords[1] = pBC; + } + } + } + + return this->addPointInTriangle ( triangleIndex, baryCoords ); +} + + +template +int BarycentricMapperMeshTopology::createPointInQuad ( const typename Out::Coord& p, int quadIndex, const typename In::VecCoord* points ) +{ + SReal baryCoords[2]; + const Quad& elem = this->m_fromTopology->getQuad ( quadIndex ); + const typename In::Coord p0 = ( *points ) [elem[0]]; + const typename In::Coord pA = ( *points ) [elem[1]] - p0; + const typename In::Coord pB = ( *points ) [elem[3]] - p0; + typename In::Coord pos = Out::getCPos(p) - p0; + sofa::defaulttype::Mat<3,3,typename In::Real> m,mt,base; + m[0] = pA; + m[1] = pB; + m[2] = cross ( pA, pB ); + mt.transpose ( m ); + base.invert ( mt ); + const typename In::Coord base0 = base[0]; + const typename In::Coord base1 = base[1]; + baryCoords[0] = base0 * pos; + baryCoords[1] = base1 * pos; + return this->addPointInQuad ( quadIndex, baryCoords ); +} + + +template +void BarycentricMapperMeshTopology::applyJT ( typename In::MatrixDeriv& out, const typename Out::MatrixDeriv& in ) +{ + const SeqLines& lines = this->m_fromTopology->getLines(); + const SeqTriangles& triangles = this->m_fromTopology->getTriangles(); + const SeqQuads& quads = this->m_fromTopology->getQuads(); + const SeqTetrahedra& tetrahedra = this->m_fromTopology->getTetrahedra(); + const SeqHexahedra& hexas = this->m_fromTopology->getHexahedra(); + + const size_t iTri = triangles.size(); + const size_t iTetra= tetrahedra.size(); + + const size_t i1d = m_map1d.size(); + const size_t i2d = m_map2d.size(); + const size_t i3d = m_map3d.size(); + + size_t indexIn; + + typename Out::MatrixDeriv::RowConstIterator rowItEnd = in.end(); + + for (typename Out::MatrixDeriv::RowConstIterator rowIt = in.begin(); rowIt != rowItEnd; ++rowIt) + { + typename Out::MatrixDeriv::ColConstIterator colItEnd = rowIt.end(); + typename Out::MatrixDeriv::ColConstIterator colIt = rowIt.begin(); + + if (colIt != colItEnd) + { + typename In::MatrixDeriv::RowIterator o = out.writeLine(rowIt.index()); + + for ( ; colIt != colItEnd; ++colIt) + { + indexIn = colIt.index(); + InDeriv data = (InDeriv) Out::getDPos(colIt.val()); + + // 1D elements + if ( indexIn < i1d ) + { + const OutReal fx = ( OutReal ) m_map1d[indexIn].baryCoords[0]; + size_t index = m_map1d[indexIn].in_index; + { + const Line& line = lines[index]; + o.addCol( line[0], data * ( 1-fx ) ); + o.addCol( line[1], data * fx ); + } + } + // 2D elements : triangle or quad + else if ( indexIn < i2d ) + { + const OutReal fx = ( OutReal ) m_map2d[indexIn].baryCoords[0]; + const OutReal fy = ( OutReal ) m_map2d[indexIn].baryCoords[1]; + size_t index = m_map2d[indexIn].in_index; + if ( index < iTri ) // triangle + { + const Triangle& triangle = triangles[index]; + o.addCol( triangle[0], data * ( 1-fx-fy ) ); + o.addCol( triangle[1], data * fx ); + o.addCol( triangle[2], data * fy ); + } + else // quad + { + const Quad& quad = quads[index - iTri]; + o.addCol( quad[0], data * ( ( 1-fx ) * ( 1-fy ) ) ); + o.addCol( quad[1], data * ( ( fx ) * ( 1-fy ) ) ); + o.addCol( quad[3], data * ( ( 1-fx ) * ( fy ) ) ); + o.addCol( quad[2], data * ( ( fx ) * ( fy ) ) ); + } + } + // 3D elements : tetra or hexa + else if ( indexIn < i3d ) + { + const OutReal fx = ( OutReal ) m_map3d[indexIn].baryCoords[0]; + const OutReal fy = ( OutReal ) m_map3d[indexIn].baryCoords[1]; + const OutReal fz = ( OutReal ) m_map3d[indexIn].baryCoords[2]; + size_t index = m_map3d[indexIn].in_index; + if ( index < iTetra ) // tetra + { + const Tetra& tetra = tetrahedra[index]; + o.addCol ( tetra[0], data * ( 1-fx-fy-fz ) ); + o.addCol ( tetra[1], data * fx ); + o.addCol ( tetra[2], data * fy ); + o.addCol ( tetra[3], data * fz ); + } + else // hexa + { + const Hexa& hexa = hexas[index-iTetra]; + + o.addCol ( hexa[0],data * ( ( 1-fx ) * ( 1-fy ) * ( 1-fz ) ) ) ; + o.addCol ( hexa[1],data * ( ( fx ) * ( 1-fy ) * ( 1-fz ) ) ) ; + + o.addCol ( hexa[3],data * ( ( 1-fx ) * ( fy ) * ( 1-fz ) ) ) ; + o.addCol ( hexa[2],data * ( ( fx ) * ( fy ) * ( 1-fz ) ) ) ; + + o.addCol ( hexa[4],data * ( ( 1-fx ) * ( 1-fy ) * ( fz ) ) ) ; + o.addCol ( hexa[5],data * ( ( fx ) * ( 1-fy ) * ( fz ) ) ) ; + + o.addCol ( hexa[7],data * ( ( 1-fx ) * ( fy ) * ( fz ) ) ) ; + o.addCol ( hexa[6],data * ( ( fx ) * ( fy ) * ( fz ) ) ) ; + } + } + } + } + } +} + + +template +void BarycentricMapperMeshTopology::draw (const core::visual::VisualParams* vparams, + const typename Out::VecCoord& out, + const typename In::VecCoord& in ) +{ + const SeqLines& lines = this->m_fromTopology->getLines(); + const SeqTriangles& triangles = this->m_fromTopology->getTriangles(); + const SeqQuads& quads = this->m_fromTopology->getQuads(); + const SeqTetrahedra& tetrahedra = this->m_fromTopology->getTetrahedra(); + const SeqHexahedra& cubes = this->m_fromTopology->getHexahedra(); + + std::vector< Vector3 > points; + // 1D elements + { + const int i0 = 0; + for ( unsigned int i=0; i=0.0001 ) + { + points.push_back ( Out::getCPos(out[i+i0]) ); + points.push_back ( in[line[j]] ); + } + } + } + } + } + // 2D elements + { + const int i0 = m_map1d.size(); + const int c0 = triangles.size(); + for ( unsigned int i=0; i=0.0001 ) + { + points.push_back ( Out::getCPos(out[i+i0]) ); + points.push_back ( in[triangle[j]] ); + } + } + } + else + { + const Quad& quad = quads[index-c0]; + Real f[4]; + f[0] = ( ( 1-fx ) * ( 1-fy ) ); + f[1] = ( ( fx ) * ( 1-fy ) ); + f[3] = ( ( 1-fx ) * ( fy ) ); + f[2] = ( ( fx ) * ( fy ) ); + for ( int j=0; j<4; j++ ) + { + if ( f[j]<=-0.0001 || f[j]>=0.0001 ) + { + points.push_back ( Out::getCPos(out[i+i0]) ); + points.push_back ( in[quad[j]] ); + } + } + } + } + } + // 3D elements + { + const int i0 = m_map1d.size() +m_map2d.size(); + const int c0 = tetrahedra.size(); + for ( unsigned int i=0; i=0.0001 ) + { + points.push_back ( Out::getCPos(out[i+i0]) ); + points.push_back ( in[tetra[j]] ); + } + } + } + else + { + const Hexa& cube = cubes[index-c0]; + + Real f[8]; + f[0] = ( 1-fx ) * ( 1-fy ) * ( 1-fz ); + f[1] = ( fx ) * ( 1-fy ) * ( 1-fz ); + + f[3] = ( 1-fx ) * ( fy ) * ( 1-fz ); + f[2] = ( fx ) * ( fy ) * ( 1-fz ); + + f[4] = ( 1-fx ) * ( 1-fy ) * ( fz ); + f[5] = ( fx ) * ( 1-fy ) * ( fz ); + + f[7] = ( 1-fx ) * ( fy ) * ( fz ); + f[6] = ( fx ) * ( fy ) * ( fz ); + + for ( int j=0; j<8; j++ ) + { + if ( f[j]<=-0.0001 || f[j]>=0.0001 ) + { + points.push_back ( Out::getCPos(out[i+i0]) ); + points.push_back ( in[cube[j]] ); + } + } + } + } + } +// vparams->drawTool()->drawLines ( points, 1, sofa::defaulttype::Vec<4,float> ( 0,1,0,1 ) ); +} + +template +const sofa::defaulttype::BaseMatrix* BarycentricMapperMeshTopology::getJ(int outSize, int inSize) +{ + + if (m_matrixJ && !m_updateJ && m_matrixJ->rowBSize() == (MatrixTypeIndex)outSize && m_matrixJ->colBSize() == (MatrixTypeIndex)inSize) + return m_matrixJ; + if (outSize > 0 && m_map1d.size()+m_map2d.size()+m_map3d.size() == 0) + return nullptr; // error: maps not yet created ? + if (!m_matrixJ) m_matrixJ = new MatrixType; + if (m_matrixJ->rowBSize() != (MatrixTypeIndex)outSize || m_matrixJ->colBSize() != (MatrixTypeIndex)inSize) + m_matrixJ->resize(outSize*NOut, inSize*NIn); + else + m_matrixJ->clear(); + + const SeqLines& lines = this->m_fromTopology->getLines(); + const SeqTriangles& triangles = this->m_fromTopology->getTriangles(); + const SeqQuads& quads = this->m_fromTopology->getQuads(); + const SeqTetrahedra& tetrahedra = this->m_fromTopology->getTetrahedra(); + const SeqHexahedra& cubes = this->m_fromTopology->getHexahedra(); + + + // 1D elements + { + for ( size_t i=0; iaddMatrixContrib(m_matrixJ, out, line[0], ( 1-fx )); + this->addMatrixContrib(m_matrixJ, out, line[1], fx); + } + } + } + // 2D elements + { + const size_t i0 = m_map1d.size(); + const size_t c0 = triangles.size(); + for ( size_t i=0; iaddMatrixContrib(m_matrixJ, out, triangle[0], ( 1-fx-fy )); + this->addMatrixContrib(m_matrixJ, out, triangle[1], fx); + this->addMatrixContrib(m_matrixJ, out, triangle[2], fy); + } + else + { + const Quad& quad = quads[index-c0]; + this->addMatrixContrib(m_matrixJ, out, quad[0], ( ( 1-fx ) * ( 1-fy ) )); + this->addMatrixContrib(m_matrixJ, out, quad[1], ( ( fx ) * ( 1-fy ) )); + this->addMatrixContrib(m_matrixJ, out, quad[3], ( ( 1-fx ) * ( fy ) )); + this->addMatrixContrib(m_matrixJ, out, quad[2], ( ( fx ) * ( fy ) )); + } + } + } + // 3D elements + { + const size_t i0 = m_map1d.size() + m_map2d.size(); + const size_t c0 = tetrahedra.size(); + for ( size_t i=0; iaddMatrixContrib(m_matrixJ, out, tetra[0], ( 1-fx-fy-fz )); + this->addMatrixContrib(m_matrixJ, out, tetra[1], fx); + this->addMatrixContrib(m_matrixJ, out, tetra[2], fy); + this->addMatrixContrib(m_matrixJ, out, tetra[3], fz); + } + else + { + const Hexa& cube = cubes[index-c0]; + + this->addMatrixContrib(m_matrixJ, out, cube[0], ( ( 1-fx ) * ( 1-fy ) * ( 1-fz ) )); + this->addMatrixContrib(m_matrixJ, out, cube[1], ( ( fx ) * ( 1-fy ) * ( 1-fz ) )); + + this->addMatrixContrib(m_matrixJ, out, cube[3], ( ( 1-fx ) * ( fy ) * ( 1-fz ) )); + this->addMatrixContrib(m_matrixJ, out, cube[2], ( ( fx ) * ( fy ) * ( 1-fz ) )); + + this->addMatrixContrib(m_matrixJ, out, cube[4], ( ( 1-fx ) * ( 1-fy ) * ( fz ) )); + this->addMatrixContrib(m_matrixJ, out, cube[5], ( ( fx ) * ( 1-fy ) * ( fz ) )); + + this->addMatrixContrib(m_matrixJ, out, cube[7], ( ( 1-fx ) * ( fy ) * ( fz ) )); + this->addMatrixContrib(m_matrixJ, out, cube[6], ( ( fx ) * ( fy ) * ( fz ) )); + } + } + } + m_matrixJ->compress(); + m_updateJ = false; + return m_matrixJ; +} + + +template +void BarycentricMapperMeshTopology::applyJT ( typename In::VecDeriv& out, const typename Out::VecDeriv& in ) +{ + const SeqLines& lines = this->m_fromTopology->getLines(); + const SeqTriangles& triangles = this->m_fromTopology->getTriangles(); + const SeqQuads& quads = this->m_fromTopology->getQuads(); + const SeqTetrahedra& tetrahedra = this->m_fromTopology->getTetrahedra(); + const SeqHexahedra& cubes = this->m_fromTopology->getHexahedra(); + + const size_t i1d = m_map1d.size(); + const size_t i2d = m_map2d.size(); + const size_t i3d = m_map3d.size(); + + ForceMask& mask = *this->maskFrom; + + for( size_t i=0 ; imaskTo->size() ; ++i) + { + if( !this->maskTo->getEntry(i) ) continue; + + // 1D elements + if (i < i1d) + { + const typename Out::DPos v = Out::getDPos(in[i]); + const OutReal fx = ( OutReal ) m_map1d[i].baryCoords[0]; + size_t index = m_map1d[i].in_index; + { + const Line& line = lines[index]; + out[line[0]] += v * ( 1-fx ); + out[line[1]] += v * fx; + mask.insertEntry(line[0]); + mask.insertEntry(line[1]); + } + } + // 2D elements + else if (i < i1d+i2d) + { + const size_t i0 = m_map1d.size(); + const size_t c0 = triangles.size(); + const typename Out::DPos v = Out::getDPos(in[i]); + const OutReal fx = ( OutReal ) m_map2d[i-i0].baryCoords[0]; + const OutReal fy = ( OutReal ) m_map2d[i-i0].baryCoords[1]; + size_t index = m_map2d[i-i0].in_index; + if ( index +void BarycentricMapperMeshTopology::applyJ ( typename Out::VecDeriv& out, const typename In::VecDeriv& in ) +{ + out.resize( m_map1d.size() +m_map2d.size() +m_map3d.size() ); + + const SeqLines& lines = this->m_fromTopology->getLines(); + const SeqTriangles& triangles = this->m_fromTopology->getTriangles(); + const SeqQuads& quads = this->m_fromTopology->getQuads(); + const SeqTetrahedra& tetrahedra = this->m_fromTopology->getTetrahedra(); + const SeqHexahedra& cubes = this->m_fromTopology->getHexahedra(); + + const size_t sizeMap1d=m_map1d.size(); + const size_t sizeMap2d=m_map2d.size(); + const size_t sizeMap3d=m_map3d.size(); + + const size_t idxStart1=sizeMap1d; + const size_t idxStart2=sizeMap1d+sizeMap2d; + const size_t idxStart3=sizeMap1d+sizeMap2d+sizeMap3d; + + for( size_t i=0 ; imaskTo->size() ; ++i) + { + if( this->maskTo->isActivated() && !this->maskTo->getEntry(i) ) continue; + + // 1D elements + if (i < idxStart1) + { + const Real fx = m_map1d[i].baryCoords[0]; + int index = m_map1d[i].in_index; + { + const Line& line = lines[index]; + Out::setDPos(out[i] , in[line[0]] * ( 1-fx ) + + in[line[1]] * fx ); + } + } + // 2D elements + else if (i < idxStart2) + { + const size_t i0 = idxStart1; + const size_t c0 = triangles.size(); + + const Real fx = m_map2d[i-i0].baryCoords[0]; + const Real fy = m_map2d[i-i0].baryCoords[1]; + size_t index = m_map2d[i-i0].in_index; + + if ( index +void BarycentricMapperMeshTopology::resize( core::State* toModel ) +{ + toModel->resize(m_map1d.size() +m_map2d.size() +m_map3d.size()); +} + + +template +void BarycentricMapperMeshTopology::apply ( typename Out::VecCoord& out, const typename In::VecCoord& in ) +{ + out.resize( m_map1d.size() +m_map2d.size() +m_map3d.size() ); + + const SeqLines& lines = this->m_fromTopology->getLines(); + const SeqTriangles& triangles = this->m_fromTopology->getTriangles(); + const SeqQuads& quads = this->m_fromTopology->getQuads(); + const SeqTetrahedra& tetrahedra = this->m_fromTopology->getTetrahedra(); + const SeqHexahedra& cubes = this->m_fromTopology->getHexahedra(); + + // 1D elements + { + for ( unsigned int i=0; i. * +******************************************************************************* +* Authors: The SOFA Team and external contributors (see Authors.txt) * +* * +* Contact information: contact@sofa-framework.org * +******************************************************************************/ +#ifndef SOFA_COMPONENT_MAPPING_BARYCENTRICMAPPERQUADSETTOPOLOGY_CPP +#define SOFA_COMPONENT_MAPPING_BARYCENTRICMAPPERQUADSETTOPOLOGY_CPP + +#include "BarycentricMapperQuadSetTopology.inl" + +namespace sofa +{ + +namespace component +{ + +namespace mapping +{ + +using namespace sofa::defaulttype; + +#ifndef SOFA_FLOAT +template class SOFA_BASE_MECHANICS_API BarycentricMapperQuadSetTopology< Vec3dTypes, Vec3dTypes >; +template class SOFA_BASE_MECHANICS_API BarycentricMapperQuadSetTopology< Vec3dTypes, ExtVec3fTypes >; +#endif +#ifndef SOFA_DOUBLE +template class SOFA_BASE_MECHANICS_API BarycentricMapperQuadSetTopology< Vec3fTypes, Vec3fTypes >; +template class SOFA_BASE_MECHANICS_API BarycentricMapperQuadSetTopology< Vec3fTypes, ExtVec3fTypes >; +#endif +#ifndef SOFA_FLOAT +#ifndef SOFA_DOUBLE +template class SOFA_BASE_MECHANICS_API BarycentricMapperQuadSetTopology< Vec3dTypes, Vec3fTypes >; +template class SOFA_BASE_MECHANICS_API BarycentricMapperQuadSetTopology< Vec3fTypes, Vec3dTypes >; +#endif +#endif + +}}} + +#endif diff --git a/SofaKernel/modules/SofaBaseMechanics/BarycentricMappers/BarycentricMapperQuadSetTopology.h b/SofaKernel/modules/SofaBaseMechanics/BarycentricMappers/BarycentricMapperQuadSetTopology.h new file mode 100644 index 00000000000..148aa7b0698 --- /dev/null +++ b/SofaKernel/modules/SofaBaseMechanics/BarycentricMappers/BarycentricMapperQuadSetTopology.h @@ -0,0 +1,111 @@ +/****************************************************************************** +* SOFA, Simulation Open-Framework Architecture, development version * +* (c) 2006-2018 INRIA, USTL, UJF, CNRS, MGH * +* * +* This program is free software; you can redistribute it and/or modify it * +* under the terms of the GNU Lesser General Public License as published by * +* the Free Software Foundation; either version 2.1 of the License, or (at * +* your option) any later version. * +* * +* This program is distributed in the hope that it will be useful, but WITHOUT * +* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * +* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License * +* for more details. * +* * +* You should have received a copy of the GNU Lesser General Public License * +* along with this program. If not, see . * +******************************************************************************* +* Authors: The SOFA Team and external contributors (see Authors.txt) * +* * +* Contact information: contact@sofa-framework.org * +******************************************************************************/ +#ifndef SOFA_COMPONENT_MAPPING_BARYCENTRICMAPPERQUADSETTOPOLOGY_H +#define SOFA_COMPONENT_MAPPING_BARYCENTRICMAPPERQUADSETTOPOLOGY_H + +#include +#include +#include + +namespace sofa +{ + +namespace component +{ + +namespace mapping +{ + +using sofa::defaulttype::Mat3x3d; +using sofa::defaulttype::Vector3; + +typedef typename sofa::core::topology::BaseMeshTopology::Quad Quad; + +/// Class allowing barycentric mapping computation on a QuadSetTopology +template +class SOFA_BASE_MECHANICS_API BarycentricMapperQuadSetTopology : public BarycentricMapperTopologyContainer::MappingData2D, Quad> +{ + typedef typename BarycentricMapper::MappingData2D MappingData; + +public: + + SOFA_CLASS(SOFA_TEMPLATE2(BarycentricMapperQuadSetTopology,In,Out),SOFA_TEMPLATE4(BarycentricMapperTopologyContainer,In,Out,MappingData,Quad)); + typedef typename Inherit1::Real Real; + +protected: + + topology::QuadSetTopologyContainer* m_fromContainer; + topology::QuadSetGeometryAlgorithms* m_fromGeomAlgo; + + using Inherit1::d_map; + using Inherit1::m_fromTopology; + using Inherit1::m_matrixJ; + using Inherit1::m_updateJ; + + BarycentricMapperQuadSetTopology(topology::QuadSetTopologyContainer* fromTopology, topology::PointSetTopologyContainer* toTopology) + : Inherit1(fromTopology, toTopology), + m_fromContainer(fromTopology), + m_fromGeomAlgo(NULL) + {} + + virtual ~BarycentricMapperQuadSetTopology() {} + + virtual helper::vector getElements() override; + virtual helper::vector getBaryCoef(const Real* f) override; + helper::vector getBaryCoef(const Real fx, const Real fy); + virtual void computeBase(Mat3x3d& base, const typename In::VecCoord& in, const Quad& element) override; + virtual void computeCenter(Vector3& center, const typename In::VecCoord& in, const Quad& element) override; + virtual void computeDistance(double& d, const Vector3& v) override; + virtual void addPointInElement(const int elementIndex, const SReal* baryCoords) override; + +public: + + virtual int addPointInQuad(const int index, const SReal* baryCoords) override; + virtual int createPointInQuad(const typename Out::Coord& p, int index, const typename In::VecCoord* points) override; +}; + + +using sofa::defaulttype::Vec3dTypes; +using sofa::defaulttype::Vec3fTypes; +using sofa::defaulttype::ExtVec3fTypes; + + +#if defined(SOFA_EXTERN_TEMPLATE) && !defined(SOFA_COMPONENT_MAPPING_BARYCENTRICMAPPERQUADSETTOPOLOGY_CPP) +#ifndef SOFA_FLOAT +extern template class SOFA_BASE_MECHANICS_API BarycentricMapperQuadSetTopology< Vec3dTypes, Vec3dTypes >; +extern template class SOFA_BASE_MECHANICS_API BarycentricMapperQuadSetTopology< Vec3dTypes, ExtVec3fTypes >; +#endif +#ifndef SOFA_DOUBLE +extern template class SOFA_BASE_MECHANICS_API BarycentricMapperQuadSetTopology< Vec3fTypes, Vec3fTypes >; +extern template class SOFA_BASE_MECHANICS_API BarycentricMapperQuadSetTopology< Vec3fTypes, ExtVec3fTypes >; +#endif +#ifndef SOFA_FLOAT +#ifndef SOFA_DOUBLE +extern template class SOFA_BASE_MECHANICS_API BarycentricMapperQuadSetTopology< Vec3dTypes, Vec3fTypes >; +extern template class SOFA_BASE_MECHANICS_API BarycentricMapperQuadSetTopology< Vec3fTypes, Vec3dTypes >; +#endif +#endif +#endif + +}}} + +#endif diff --git a/SofaKernel/modules/SofaBaseMechanics/BarycentricMappers/BarycentricMapperQuadSetTopology.inl b/SofaKernel/modules/SofaBaseMechanics/BarycentricMappers/BarycentricMapperQuadSetTopology.inl new file mode 100644 index 00000000000..c4bb0df330d --- /dev/null +++ b/SofaKernel/modules/SofaBaseMechanics/BarycentricMappers/BarycentricMapperQuadSetTopology.inl @@ -0,0 +1,125 @@ +/****************************************************************************** +* SOFA, Simulation Open-Framework Architecture, development version * +* (c) 2006-2018 INRIA, USTL, UJF, CNRS, MGH * +* * +* This program is free software; you can redistribute it and/or modify it * +* under the terms of the GNU Lesser General Public License as published by * +* the Free Software Foundation; either version 2.1 of the License, or (at * +* your option) any later version. * +* * +* This program is distributed in the hope that it will be useful, but WITHOUT * +* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * +* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License * +* for more details. * +* * +* You should have received a copy of the GNU Lesser General Public License * +* along with this program. If not, see . * +******************************************************************************* +* Authors: The SOFA Team and external contributors (see Authors.txt) * +* * +* Contact information: contact@sofa-framework.org * +******************************************************************************/ +#ifndef SOFA_COMPONENT_MAPPING_BARYCENTRICMAPPERQUADSETTOPOLOGY_INL +#define SOFA_COMPONENT_MAPPING_BARYCENTRICMAPPERQUADSETTOPOLOGY_INL + + +#include "BarycentricMapperQuadSetTopology.h" + +namespace sofa +{ + +namespace component +{ + +namespace mapping +{ + +template +int BarycentricMapperQuadSetTopology::addPointInQuad ( const int quadIndex, const SReal* baryCoords ) +{ + helper::vector& vectorData = *(d_map.beginEdit()); + vectorData.resize ( d_map.getValue().size() +1 ); + MappingData& data = *vectorData.rbegin(); + d_map.endEdit(); + data.in_index = quadIndex; + data.baryCoords[0] = ( Real ) baryCoords[0]; + data.baryCoords[1] = ( Real ) baryCoords[1]; + return (int)d_map.getValue().size()-1; +} + +template +int BarycentricMapperQuadSetTopology::createPointInQuad ( const typename Out::Coord& p, int quadIndex, const typename In::VecCoord* points ) +{ + SReal baryCoords[2]; + const Quad& elem = this->m_fromTopology->getQuad ( quadIndex ); + const typename In::Coord p0 = ( *points ) [elem[0]]; + const typename In::Coord pA = ( *points ) [elem[1]] - p0; + const typename In::Coord pB = ( *points ) [elem[3]] - p0; + typename In::Coord pos = Out::getCPos(p) - p0; + sofa::defaulttype::Mat<3,3,typename In::Real> m,mt,base; + m[0] = pA; + m[1] = pB; + m[2] = cross ( pA, pB ); + mt.transpose ( m ); + base.invert ( mt ); + const typename In::Coord base0 = base[0]; + const typename In::Coord base1 = base[1]; + baryCoords[0] = base0 * pos; + baryCoords[1] = base1 * pos; + return this->addPointInQuad ( quadIndex, baryCoords ); +} + +template +helper::vector BarycentricMapperQuadSetTopology::getElements() +{ + return this->m_fromTopology->getQuads(); +} + +template +helper::vector BarycentricMapperQuadSetTopology::getBaryCoef(const Real* f) +{ + return getBaryCoef(f[0],f[1]); +} + +template +helper::vector BarycentricMapperQuadSetTopology::getBaryCoef(const Real fx, const Real fy) +{ + helper::vector quadCoef{(1-fx)*(1-fy), + (fx)*(1-fy), + (1-fx)*(fy), + (fx)*(fy)}; + return quadCoef; +} + +template +void BarycentricMapperQuadSetTopology::computeBase(Mat3x3d& base, const typename In::VecCoord& in, const Quad& element) +{ + Mat3x3d matrixTranspose; + base[0] = in[element[1]]-in[element[0]]; + base[1] = in[element[3]]-in[element[0]]; + base[2] = cross(base[0],base[1]); + matrixTranspose.transpose(base); + base.invert(matrixTranspose); +} + +template +void BarycentricMapperQuadSetTopology::computeCenter(Vector3& center, const typename In::VecCoord& in, const Quad& element) +{ + center = ( in[element[0]]+in[element[1]]+in[element[2]]+in[element[3]] ) *0.25; +} + +template +void BarycentricMapperQuadSetTopology::computeDistance(double& d, const Vector3& v) +{ + d = std::max ( std::max ( -v[0],-v[1] ),std::max ( std::max ( v[1]-1,v[0]-1 ),std::max ( v[2]-0.01,-v[2]-0.01 ) ) ); +} + +template +void BarycentricMapperQuadSetTopology::addPointInElement(const int elementIndex, const SReal* baryCoords) +{ + addPointInQuad(elementIndex,baryCoords); +} + +}}} + +#endif diff --git a/SofaKernel/modules/SofaBaseMechanics/BarycentricMappers/BarycentricMapperRegularGridTopology.cpp b/SofaKernel/modules/SofaBaseMechanics/BarycentricMappers/BarycentricMapperRegularGridTopology.cpp new file mode 100644 index 00000000000..9d899d2382c --- /dev/null +++ b/SofaKernel/modules/SofaBaseMechanics/BarycentricMappers/BarycentricMapperRegularGridTopology.cpp @@ -0,0 +1,56 @@ +/****************************************************************************** +* SOFA, Simulation Open-Framework Architecture, development version * +* (c) 2006-2018 INRIA, USTL, UJF, CNRS, MGH * +* * +* This program is free software; you can redistribute it and/or modify it * +* under the terms of the GNU Lesser General Public License as published by * +* the Free Software Foundation; either version 2.1 of the License, or (at * +* your option) any later version. * +* * +* This program is distributed in the hope that it will be useful, but WITHOUT * +* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * +* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License * +* for more details. * +* * +* You should have received a copy of the GNU Lesser General Public License * +* along with this program. If not, see . * +******************************************************************************* +* Authors: The SOFA Team and external contributors (see Authors.txt) * +* * +* Contact information: contact@sofa-framework.org * +******************************************************************************/ +#ifndef SOFA_COMPONENT_MAPPING_BARYCENTRICMAPPERREGULARGRIDTOPOLOGY_CPP +#define SOFA_COMPONENT_MAPPING_BARYCENTRICMAPPERREGULARGRIDTOPOLOGY_CPP + +#include "BarycentricMapperRegularGridTopology.inl" + +namespace sofa +{ + +namespace component +{ + +namespace mapping +{ + +using namespace sofa::defaulttype; + +#ifndef SOFA_FLOAT +template class SOFA_BASE_MECHANICS_API BarycentricMapperRegularGridTopology< Vec3dTypes, Vec3dTypes >; +template class SOFA_BASE_MECHANICS_API BarycentricMapperRegularGridTopology< Vec3dTypes, ExtVec3fTypes >; +#endif +#ifndef SOFA_DOUBLE +template class SOFA_BASE_MECHANICS_API BarycentricMapperRegularGridTopology< Vec3fTypes, Vec3fTypes >; +template class SOFA_BASE_MECHANICS_API BarycentricMapperRegularGridTopology< Vec3fTypes, ExtVec3fTypes >; +#endif +#ifndef SOFA_FLOAT +#ifndef SOFA_DOUBLE +template class SOFA_BASE_MECHANICS_API BarycentricMapperRegularGridTopology< Vec3dTypes, Vec3fTypes >; +template class SOFA_BASE_MECHANICS_API BarycentricMapperRegularGridTopology< Vec3fTypes, Vec3dTypes >; +#endif +#endif + +}}} + + +#endif diff --git a/SofaKernel/modules/SofaBaseMechanics/BarycentricMappers/BarycentricMapperRegularGridTopology.h b/SofaKernel/modules/SofaBaseMechanics/BarycentricMappers/BarycentricMapperRegularGridTopology.h new file mode 100644 index 00000000000..1b9eda8f880 --- /dev/null +++ b/SofaKernel/modules/SofaBaseMechanics/BarycentricMappers/BarycentricMapperRegularGridTopology.h @@ -0,0 +1,142 @@ +/****************************************************************************** +* SOFA, Simulation Open-Framework Architecture, development version * +* (c) 2006-2018 INRIA, USTL, UJF, CNRS, MGH * +* * +* This program is free software; you can redistribute it and/or modify it * +* under the terms of the GNU Lesser General Public License as published by * +* the Free Software Foundation; either version 2.1 of the License, or (at * +* your option) any later version. * +* * +* This program is distributed in the hope that it will be useful, but WITHOUT * +* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * +* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License * +* for more details. * +* * +* You should have received a copy of the GNU Lesser General Public License * +* along with this program. If not, see . * +******************************************************************************* +* Authors: The SOFA Team and external contributors (see Authors.txt) * +* * +* Contact information: contact@sofa-framework.org * +******************************************************************************/ +#ifndef SOFA_COMPONENT_MAPPING_BARYCENTRICMAPPERREGULARGRIDTOPOLOGY_H +#define SOFA_COMPONENT_MAPPING_BARYCENTRICMAPPERREGULARGRIDTOPOLOGY_H + +#include +#include + +namespace sofa +{ + +namespace component +{ + +namespace mapping +{ + +using core::visual::VisualParams; +using sofa::defaulttype::BaseMatrix; +using topology::RegularGridTopology; +using topology::PointSetTopologyContainer; + +/// Class allowing barycentric mapping computation on a RegularGridTopology +template +class SOFA_BASE_MECHANICS_API BarycentricMapperRegularGridTopology : public TopologyBarycentricMapper +{ + +public: + + SOFA_CLASS(SOFA_TEMPLATE2(BarycentricMapperRegularGridTopology,In,Out),SOFA_TEMPLATE2(TopologyBarycentricMapper,In,Out)); + typedef typename Inherit1::Real Real; + typedef typename Inherit1::OutReal OutReal; + typedef typename Inherit1::OutDeriv OutDeriv; + typedef typename Inherit1::InDeriv InDeriv; + typedef typename Inherit1::CubeData CubeData; + typedef typename Inherit1::MBloc MBloc; + typedef typename Inherit1::MatrixType MatrixType; + typedef typename MatrixType::Index MatrixTypeIndex; + typedef typename Inherit1::ForceMask ForceMask; + + enum { NIn = Inherit1::NIn }; + enum { NOut = Inherit1::NOut }; + + +public: + + virtual void clear(int reserve=0) override; + virtual void resize( core::State* toModel ) override; + virtual bool isEmpty() {return this->m_map.size() == 0;} + virtual void setTopology(topology::RegularGridTopology* _topology) {this->m_fromTopology = _topology;} + RegularGridTopology *getTopology() {return dynamic_cast(this->m_fromTopology);} + virtual int addPointInCube(const int cubeIndex, const SReal* baryCoords) override; + + virtual void init(const typename Out::VecCoord& out, const typename In::VecCoord& in) override; + virtual void draw(const core::visual::VisualParams*,const typename Out::VecCoord& out, const typename In::VecCoord& in) override; + virtual void apply( typename Out::VecCoord& out, const typename In::VecCoord& in ) override; + virtual void applyJ( typename Out::VecDeriv& out, const typename In::VecDeriv& in ) override; + virtual void applyJT( typename In::VecDeriv& out, const typename Out::VecDeriv& in ) override; + virtual void applyJT( typename In::MatrixDeriv& out, const typename Out::MatrixDeriv& in ) override; + virtual const BaseMatrix* getJ(int outSize, int inSize) override; + + inline friend std::istream& operator >> ( std::istream& in, BarycentricMapperRegularGridTopology &b ) + { + in >> b.m_map; + return in; + } + + inline friend std::ostream& operator << ( std::ostream& out, const BarycentricMapperRegularGridTopology & b ) + { + out << b.m_map; + return out; + } + +protected: + + void addMatrixContrib(MatrixType* m, int row, int col, Real value) + { + Inherit1::addMatrixContrib(m, row, col, value); + } + + helper::vector m_map; + RegularGridTopology* m_fromTopology; + MatrixType* matrixJ; + bool updateJ; + + BarycentricMapperRegularGridTopology(RegularGridTopology* fromTopology, PointSetTopologyContainer* toTopology) + : Inherit1(fromTopology, toTopology) + , m_fromTopology(fromTopology) + , matrixJ(NULL), updateJ(true) + { + } + + virtual ~BarycentricMapperRegularGridTopology() override + { + if (matrixJ) delete matrixJ; + } +}; + +using sofa::defaulttype::Vec3dTypes; +using sofa::defaulttype::Vec3fTypes; +using sofa::defaulttype::ExtVec3fTypes; + +#if defined(SOFA_EXTERN_TEMPLATE) && !defined(SOFA_COMPONENT_MAPPING_BARYCENTRICMAPPERREGULARGRIDTOPOLOGY_CPP) +#ifndef SOFA_FLOAT +extern template class SOFA_BASE_MECHANICS_API BarycentricMapperRegularGridTopology< Vec3dTypes, Vec3dTypes >; +extern template class SOFA_BASE_MECHANICS_API BarycentricMapperRegularGridTopology< Vec3dTypes, ExtVec3fTypes >; +#endif +#ifndef SOFA_DOUBLE +extern template class SOFA_BASE_MECHANICS_API BarycentricMapperRegularGridTopology< Vec3fTypes, Vec3fTypes >; +extern template class SOFA_BASE_MECHANICS_API BarycentricMapperRegularGridTopology< Vec3fTypes, ExtVec3fTypes >; +#endif +#ifndef SOFA_FLOAT +#ifndef SOFA_DOUBLE +extern template class SOFA_BASE_MECHANICS_API BarycentricMapperRegularGridTopology< Vec3dTypes, Vec3fTypes >; +extern template class SOFA_BASE_MECHANICS_API BarycentricMapperRegularGridTopology< Vec3fTypes, Vec3dTypes >; +#endif +#endif +#endif + +}}} + + +#endif diff --git a/SofaKernel/modules/SofaBaseMechanics/BarycentricMappers/BarycentricMapperRegularGridTopology.inl b/SofaKernel/modules/SofaBaseMechanics/BarycentricMappers/BarycentricMapperRegularGridTopology.inl new file mode 100644 index 00000000000..56745ab9100 --- /dev/null +++ b/SofaKernel/modules/SofaBaseMechanics/BarycentricMappers/BarycentricMapperRegularGridTopology.inl @@ -0,0 +1,304 @@ +/****************************************************************************** +* SOFA, Simulation Open-Framework Architecture, development version * +* (c) 2006-2018 INRIA, USTL, UJF, CNRS, MGH * +* * +* This program is free software; you can redistribute it and/or modify it * +* under the terms of the GNU Lesser General Public License as published by * +* the Free Software Foundation; either version 2.1 of the License, or (at * +* your option) any later version. * +* * +* This program is distributed in the hope that it will be useful, but WITHOUT * +* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * +* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License * +* for more details. * +* * +* You should have received a copy of the GNU Lesser General Public License * +* along with this program. If not, see . * +******************************************************************************* +* Authors: The SOFA Team and external contributors (see Authors.txt) * +* * +* Contact information: contact@sofa-framework.org * +******************************************************************************/ +#ifndef SOFA_COMPONENT_MAPPING_BARYCENTRICMAPPERREGULARGRIDTOPOLOGY_INL +#define SOFA_COMPONENT_MAPPING_BARYCENTRICMAPPERREGULARGRIDTOPOLOGY_INL + +#include "BarycentricMapperRegularGridTopology.h" + +namespace sofa +{ + +namespace component +{ + +namespace mapping +{ + +using sofa::defaulttype::Vector3; + +template +void BarycentricMapperRegularGridTopology::clear ( int size ) +{ + updateJ = true; + m_map.clear(); + if ( size>0 ) m_map.reserve ( size ); +} + +template +int BarycentricMapperRegularGridTopology::addPointInCube ( const int cubeIndex, const SReal* baryCoords ) +{ + m_map.resize ( m_map.size() +1 ); + CubeData& data = *m_map.rbegin(); + data.in_index = cubeIndex; + data.baryCoords[0] = ( Real ) baryCoords[0]; + data.baryCoords[1] = ( Real ) baryCoords[1]; + data.baryCoords[2] = ( Real ) baryCoords[2]; + return (int)m_map.size()-1; +} + +template +void BarycentricMapperRegularGridTopology::init ( const typename Out::VecCoord& out, const typename In::VecCoord& in ) +{ + SOFA_UNUSED(in); + + updateJ = true; + + clear ( (int)out.size() ); + if ( m_fromTopology->isVolume() ) + { + for ( unsigned int i=0; ifindCube ( Vector3 ( Out::getCPos(out[i]) ), coefs[0], coefs[1], coefs[2] ); + if ( cube==-1 ) + cube = m_fromTopology->findNearestCube ( Vector3 ( Out::getCPos(out[i]) ), coefs[0], coefs[1], coefs[2] ); + + this->addPointInCube ( cube, coefs.ptr() ); + } + } +} + + + +template +void BarycentricMapperRegularGridTopology::resize( core::State* toModel ) +{ + toModel->resize(m_map.size()); +} + +template +void BarycentricMapperRegularGridTopology::apply ( typename Out::VecCoord& out, const typename In::VecCoord& in ) +{ + out.resize( m_map.size() ); + + for ( unsigned int i=0; im_fromTopology->getHexaCopy ( this->m_map[i].in_index ); + + const Real fx = m_map[i].baryCoords[0]; + const Real fy = m_map[i].baryCoords[1]; + const Real fz = m_map[i].baryCoords[2]; + Out::setCPos(out[i] , in[cube[0]] * ( ( 1-fx ) * ( 1-fy ) * ( 1-fz ) ) + + in[cube[1]] * ( ( fx ) * ( 1-fy ) * ( 1-fz ) ) + + in[cube[3]] * ( ( 1-fx ) * ( fy ) * ( 1-fz ) ) + + in[cube[2]] * ( ( fx ) * ( fy ) * ( 1-fz ) ) + + in[cube[4]] * ( ( 1-fx ) * ( 1-fy ) * ( fz ) ) + + in[cube[5]] * ( ( fx ) * ( 1-fy ) * ( fz ) ) + + in[cube[7]] * ( ( 1-fx ) * ( fy ) * ( fz ) ) + + in[cube[6]] * ( ( fx ) * ( fy ) * ( fz ) ) ); + } +} + + +template +void BarycentricMapperRegularGridTopology::applyJ ( typename Out::VecDeriv& out, const typename In::VecDeriv& in ) +{ + out.resize( m_map.size() ); + + for( size_t index=0 ; indexmaskTo->size() ; ++index) + { + if( this->maskTo->isActivated() && !this->maskTo->getEntry(index) ) continue; + + const topology::RegularGridTopology::Hexa cube = this->m_fromTopology->getHexaCopy ( this->m_map[index].in_index ); + + const Real fx = m_map[index].baryCoords[0]; + const Real fy = m_map[index].baryCoords[1]; + const Real fz = m_map[index].baryCoords[2]; + Out::setDPos(out[index] , in[cube[0]] * ( ( 1-fx ) * ( 1-fy ) * ( 1-fz ) ) + + in[cube[1]] * ( ( fx ) * ( 1-fy ) * ( 1-fz ) ) + + in[cube[3]] * ( ( 1-fx ) * ( fy ) * ( 1-fz ) ) + + in[cube[2]] * ( ( fx ) * ( fy ) * ( 1-fz ) ) + + in[cube[4]] * ( ( 1-fx ) * ( 1-fy ) * ( fz ) ) + + in[cube[5]] * ( ( fx ) * ( 1-fy ) * ( fz ) ) + + in[cube[7]] * ( ( 1-fx ) * ( fy ) * ( fz ) ) + + in[cube[6]] * ( ( fx ) * ( fy ) * ( fz ) ) ); + } +} + +template +void BarycentricMapperRegularGridTopology::applyJT ( typename In::VecDeriv& out, const typename Out::VecDeriv& in ) +{ + ForceMask& mask = *this->maskFrom; + + for( size_t index=0 ; indexmaskTo->size() ; ++index) + { + if( !this->maskTo->getEntry(index) ) continue; + + const typename Out::DPos v = Out::getDPos(in[index]); + const topology::RegularGridTopology::Hexa cube = this->m_fromTopology->getHexaCopy ( this->m_map[index].in_index ); + + const OutReal fx = ( OutReal ) m_map[index].baryCoords[0]; + const OutReal fy = ( OutReal ) m_map[index].baryCoords[1]; + const OutReal fz = ( OutReal ) m_map[index].baryCoords[2]; + out[cube[0]] += v * ( ( 1-fx ) * ( 1-fy ) * ( 1-fz ) ); + out[cube[1]] += v * ( ( fx ) * ( 1-fy ) * ( 1-fz ) ); + + out[cube[3]] += v * ( ( 1-fx ) * ( fy ) * ( 1-fz ) ); + out[cube[2]] += v * ( ( fx ) * ( fy ) * ( 1-fz ) ); + + out[cube[4]] += v * ( ( 1-fx ) * ( 1-fy ) * ( fz ) ); + out[cube[5]] += v * ( ( fx ) * ( 1-fy ) * ( fz ) ); + + out[cube[7]] += v * ( ( 1-fx ) * ( fy ) * ( fz ) ); + out[cube[6]] += v * ( ( fx ) * ( fy ) * ( fz ) ); + + mask.insertEntry(cube[0]); + mask.insertEntry(cube[1]); + mask.insertEntry(cube[2]); + mask.insertEntry(cube[3]); + mask.insertEntry(cube[4]); + mask.insertEntry(cube[5]); + mask.insertEntry(cube[6]); + mask.insertEntry(cube[7]); + } + +} + + +template +const sofa::defaulttype::BaseMatrix* BarycentricMapperRegularGridTopology::getJ(int outSize, int inSize) +{ + + if (matrixJ && !updateJ) + return matrixJ; + + if (!matrixJ) matrixJ = new MatrixType; + if (matrixJ->rowBSize() != (MatrixTypeIndex)outSize || matrixJ->colBSize() != (MatrixTypeIndex)inSize) + matrixJ->resize(outSize*NOut, inSize*NIn); + else + matrixJ->clear(); + + for ( size_t i=0; im_fromTopology->getHexaCopy ( this->m_map[i].in_index ); + + const Real fx = ( Real ) m_map[i].baryCoords[0]; + const Real fy = ( Real ) m_map[i].baryCoords[1]; + const Real fz = ( Real ) m_map[i].baryCoords[2]; + this->addMatrixContrib(matrixJ, out, cube[0], ( ( 1-fx ) * ( 1-fy ) * ( 1-fz ) )); + this->addMatrixContrib(matrixJ, out, cube[1], ( ( fx ) * ( 1-fy ) * ( 1-fz ) )); + + this->addMatrixContrib(matrixJ, out, cube[3], ( ( 1-fx ) * ( fy ) * ( 1-fz ) )); + this->addMatrixContrib(matrixJ, out, cube[2], ( ( fx ) * ( fy ) * ( 1-fz ) )); + + this->addMatrixContrib(matrixJ, out, cube[4], ( ( 1-fx ) * ( 1-fy ) * ( fz ) )); + this->addMatrixContrib(matrixJ, out, cube[5], ( ( fx ) * ( 1-fy ) * ( fz ) )); + + this->addMatrixContrib(matrixJ, out, cube[7], ( ( 1-fx ) * ( fy ) * ( fz ) )); + this->addMatrixContrib(matrixJ, out, cube[6], ( ( fx ) * ( fy ) * ( fz ) )); + } + updateJ = false; + return matrixJ; +} + + + +template +void BarycentricMapperRegularGridTopology::draw (const core::visual::VisualParams* vparams, + const typename Out::VecCoord& out, + const typename In::VecCoord& in ) +{ + std::vector< Vector3 > points; + + for ( unsigned int i=0; im_fromTopology->getHexaCopy ( this->m_map[i].in_index ); + + const Real fx = m_map[i].baryCoords[0]; + const Real fy = m_map[i].baryCoords[1]; + const Real fz = m_map[i].baryCoords[2]; + Real f[8]; + f[0] = ( 1-fx ) * ( 1-fy ) * ( 1-fz ); + f[1] = ( fx ) * ( 1-fy ) * ( 1-fz ); + + f[3] = ( 1-fx ) * ( fy ) * ( 1-fz ); + f[2] = ( fx ) * ( fy ) * ( 1-fz ); + + f[4] = ( 1-fx ) * ( 1-fy ) * ( fz ); + f[5] = ( fx ) * ( 1-fy ) * ( fz ); + + f[7] = ( 1-fx ) * ( fy ) * ( fz ); + f[6] = ( fx ) * ( fy ) * ( fz ); + + for ( int j=0; j<8; j++ ) + { + if ( f[j]<=-0.0001 || f[j]>=0.0001 ) + { + points.push_back ( Out::getCPos(out[i]) ); + points.push_back ( in[cube[j]] ); + } + } + } +// vparams->drawTool()->drawLines ( points, 1, sofa::defaulttype::Vec<4,float> ( 0,0,1,1 ) ); +} + + +template +void BarycentricMapperRegularGridTopology::applyJT ( typename In::MatrixDeriv& out, const typename Out::MatrixDeriv& in ) +{ + typename Out::MatrixDeriv::RowConstIterator rowItEnd = in.end(); + + for (typename Out::MatrixDeriv::RowConstIterator rowIt = in.begin(); rowIt != rowItEnd; ++rowIt) + { + typename Out::MatrixDeriv::ColConstIterator colItEnd = rowIt.end(); + typename Out::MatrixDeriv::ColConstIterator colIt = rowIt.begin(); + + if (colIt != colItEnd) + { + typename In::MatrixDeriv::RowIterator o = out.writeLine(rowIt.index()); + + for ( ; colIt != colItEnd; ++colIt) + { + unsigned int indexIn = colIt.index(); + InDeriv data = (InDeriv) Out::getDPos(colIt.val()); + + const topology::RegularGridTopology::Hexa cube = this->m_fromTopology->getHexaCopy ( this->m_map[indexIn].in_index ); + + const OutReal fx = (OutReal) m_map[indexIn].baryCoords[0]; + const OutReal fy = (OutReal) m_map[indexIn].baryCoords[1]; + const OutReal fz = (OutReal) m_map[indexIn].baryCoords[2]; + const OutReal oneMinusFx = 1-fx; + const OutReal oneMinusFy = 1-fy; + const OutReal oneMinusFz = 1-fz; + + o.addCol(cube[0], data * ((oneMinusFx) * (oneMinusFy) * (oneMinusFz))); + o.addCol(cube[1], data * ((fx) * (oneMinusFy) * (oneMinusFz))); + + o.addCol(cube[3], data * ((oneMinusFx) * (fy) * (oneMinusFz))); + o.addCol(cube[2], data * ((fx) * (fy) * (oneMinusFz))); + + o.addCol(cube[4], data * ((oneMinusFx) * (oneMinusFy) * (fz))); + o.addCol(cube[5], data * ((fx) * (oneMinusFy) * (fz))); + + o.addCol(cube[7], data * ((oneMinusFx) * (fy) * (fz))); + o.addCol(cube[6], data * ((fx) * (fy) * (fz))); + } + } + } +} + +}}} + +#endif diff --git a/SofaKernel/modules/SofaBaseMechanics/BarycentricMappers/BarycentricMapperSparseGridTopology.cpp b/SofaKernel/modules/SofaBaseMechanics/BarycentricMappers/BarycentricMapperSparseGridTopology.cpp new file mode 100644 index 00000000000..fa3a20d703e --- /dev/null +++ b/SofaKernel/modules/SofaBaseMechanics/BarycentricMappers/BarycentricMapperSparseGridTopology.cpp @@ -0,0 +1,60 @@ +/****************************************************************************** +* SOFA, Simulation Open-Framework Architecture, development version * +* (c) 2006-2018 INRIA, USTL, UJF, CNRS, MGH * +* * +* This program is free software; you can redistribute it and/or modify it * +* under the terms of the GNU Lesser General Public License as published by * +* the Free Software Foundation; either version 2.1 of the License, or (at * +* your option) any later version. * +* * +* This program is distributed in the hope that it will be useful, but WITHOUT * +* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * +* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License * +* for more details. * +* * +* You should have received a copy of the GNU Lesser General Public License * +* along with this program. If not, see . * +******************************************************************************* +* Authors: The SOFA Team and external contributors (see Authors.txt) * +* * +* Contact information: contact@sofa-framework.org * +******************************************************************************/ +#ifndef SOFA_COMPONENT_MAPPING_BARYCENTRICMAPPERSPARSEGRIDTOPOLOGY_CPP +#define SOFA_COMPONENT_MAPPING_BARYCENTRICMAPPERSPARSEGRIDTOPOLOGY_CPP + +#include "BarycentricMapperSparseGridTopology.inl" + +namespace sofa +{ + +namespace component +{ + +namespace mapping +{ + +using namespace sofa::defaulttype; + +#ifndef SOFA_FLOAT +template class SOFA_BASE_MECHANICS_API BarycentricMapperSparseGridTopology< Vec3dTypes, Vec3dTypes >; +template class SOFA_BASE_MECHANICS_API BarycentricMapperSparseGridTopology< Vec3dTypes, ExtVec3fTypes >; +#endif +#ifndef SOFA_DOUBLE +template class SOFA_BASE_MECHANICS_API BarycentricMapperSparseGridTopology< Vec3fTypes, Vec3fTypes >; +template class SOFA_BASE_MECHANICS_API BarycentricMapperSparseGridTopology< Vec3fTypes, ExtVec3fTypes >; +#endif +#ifndef SOFA_FLOAT +#ifndef SOFA_DOUBLE +template class SOFA_BASE_MECHANICS_API BarycentricMapperSparseGridTopology< Vec3dTypes, Vec3fTypes >; +template class SOFA_BASE_MECHANICS_API BarycentricMapperSparseGridTopology< Vec3fTypes, Vec3dTypes >; +#endif +#endif + +} // namespace mapping + +} // namespace component + +} // namespace sofa + + +#endif diff --git a/SofaKernel/modules/SofaBaseMechanics/BarycentricMappers/BarycentricMapperSparseGridTopology.h b/SofaKernel/modules/SofaBaseMechanics/BarycentricMappers/BarycentricMapperSparseGridTopology.h new file mode 100644 index 00000000000..91aaa409d29 --- /dev/null +++ b/SofaKernel/modules/SofaBaseMechanics/BarycentricMappers/BarycentricMapperSparseGridTopology.h @@ -0,0 +1,142 @@ +/****************************************************************************** +* SOFA, Simulation Open-Framework Architecture, development version * +* (c) 2006-2018 INRIA, USTL, UJF, CNRS, MGH * +* * +* This program is free software; you can redistribute it and/or modify it * +* under the terms of the GNU Lesser General Public License as published by * +* the Free Software Foundation; either version 2.1 of the License, or (at * +* your option) any later version. * +* * +* This program is distributed in the hope that it will be useful, but WITHOUT * +* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * +* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License * +* for more details. * +* * +* You should have received a copy of the GNU Lesser General Public License * +* along with this program. If not, see . * +******************************************************************************* +* Authors: The SOFA Team and external contributors (see Authors.txt) * +* * +* Contact information: contact@sofa-framework.org * +******************************************************************************/ +#ifndef SOFA_COMPONENT_MAPPING_BARYCENTRICMAPPERSPARSEGRIDTOPOLOGY_H +#define SOFA_COMPONENT_MAPPING_BARYCENTRICMAPPERSPARSEGRIDTOPOLOGY_H + +#include +#include + +namespace sofa +{ + +namespace component +{ + +namespace mapping +{ + +using sofa::defaulttype::BaseMatrix; +using core::visual::VisualParams; + +/// Class allowing barycentric mapping computation on a SparseGridTopology +template +class SOFA_BASE_MECHANICS_API BarycentricMapperSparseGridTopology : public TopologyBarycentricMapper +{ +public: + + SOFA_CLASS(SOFA_TEMPLATE2(BarycentricMapperSparseGridTopology,In,Out),SOFA_TEMPLATE2(TopologyBarycentricMapper,In,Out)); + typedef typename Inherit1::Real Real; + typedef typename Inherit1::OutReal OutReal; + typedef typename Inherit1::OutDeriv OutDeriv; + typedef typename Inherit1::InDeriv InDeriv; + typedef typename Inherit1::CubeData CubeData; + typedef typename Inherit1::MBloc MBloc; + typedef typename Inherit1::MatrixType MatrixType; + typedef typename MatrixType::Index MatrixTypeIndex; + typedef typename Inherit1::ForceMask ForceMask; + enum { NIn = Inherit1::NIn }; + enum { NOut = Inherit1::NOut }; + +public: + + virtual void clear(int reserve=0) override; + + virtual int addPointInCube(const int cubeIndex, const SReal* baryCoords) override; + + virtual void init(const typename Out::VecCoord& out, const typename In::VecCoord& in) override; + + virtual void apply( typename Out::VecCoord& out, const typename In::VecCoord& in ) override; + virtual void applyJ( typename Out::VecDeriv& out, const typename In::VecDeriv& in ) override; + virtual void applyJT( typename In::VecDeriv& out, const typename Out::VecDeriv& in ) override; + virtual void applyJT( typename In::MatrixDeriv& out, const typename Out::MatrixDeriv& in ) override; + virtual const BaseMatrix* getJ(int outSize, int inSize) override; + + virtual void draw(const VisualParams*,const typename Out::VecCoord& out, const typename In::VecCoord& in) override; + virtual void resize( core::State* toModel ) override; + + inline friend std::istream& operator >> ( std::istream& in, BarycentricMapperSparseGridTopology &b ) + { + in >> b.m_map; + return in; + } + + inline friend std::ostream& operator << ( std::ostream& out, const BarycentricMapperSparseGridTopology & b ) + { + out << b.m_map; + return out; + } + +protected: + + sofa::helper::vector m_map; + topology::SparseGridTopology* m_fromTopology; + + MatrixType* matrixJ; + bool updateJ; + + BarycentricMapperSparseGridTopology(topology::SparseGridTopology* fromTopology, + topology::PointSetTopologyContainer* _toTopology) + : TopologyBarycentricMapper(fromTopology, _toTopology), + m_fromTopology(fromTopology), + matrixJ(NULL), updateJ(true) + { + } + + virtual ~BarycentricMapperSparseGridTopology() override + { + if (matrixJ) delete matrixJ; + } + + void addMatrixContrib(MatrixType* m, int row, int col, Real value) + { + Inherit1::addMatrixContrib(m, row, col, value); + } + +}; + + +using sofa::defaulttype::Vec3dTypes; +using sofa::defaulttype::Vec3fTypes; +using sofa::defaulttype::ExtVec3fTypes; + + +#if defined(SOFA_EXTERN_TEMPLATE) && !defined(SOFA_COMPONENT_MAPPING_BARYCENTRICMAPPERSPARSEGRIDTOPOLOGY_CPP) +#ifndef SOFA_FLOAT +extern template class SOFA_BASE_MECHANICS_API BarycentricMapperSparseGridTopology< Vec3dTypes, Vec3dTypes >; +extern template class SOFA_BASE_MECHANICS_API BarycentricMapperSparseGridTopology< Vec3dTypes, ExtVec3fTypes >; +#endif +#ifndef SOFA_DOUBLE +extern template class SOFA_BASE_MECHANICS_API BarycentricMapperSparseGridTopology< Vec3fTypes, Vec3fTypes >; +extern template class SOFA_BASE_MECHANICS_API BarycentricMapperSparseGridTopology< Vec3fTypes, ExtVec3fTypes >; +#endif +#ifndef SOFA_FLOAT +#ifndef SOFA_DOUBLE +extern template class SOFA_BASE_MECHANICS_API BarycentricMapperSparseGridTopology< Vec3dTypes, Vec3fTypes >; +extern template class SOFA_BASE_MECHANICS_API BarycentricMapperSparseGridTopology< Vec3fTypes, Vec3dTypes >; +#endif +#endif +#endif + +}}} + + +#endif diff --git a/SofaKernel/modules/SofaBaseMechanics/BarycentricMappers/BarycentricMapperSparseGridTopology.inl b/SofaKernel/modules/SofaBaseMechanics/BarycentricMappers/BarycentricMapperSparseGridTopology.inl new file mode 100644 index 00000000000..44354214100 --- /dev/null +++ b/SofaKernel/modules/SofaBaseMechanics/BarycentricMappers/BarycentricMapperSparseGridTopology.inl @@ -0,0 +1,338 @@ +/****************************************************************************** +* SOFA, Simulation Open-Framework Architecture, development version * +* (c) 2006-2018 INRIA, USTL, UJF, CNRS, MGH * +* * +* This program is free software; you can redistribute it and/or modify it * +* under the terms of the GNU Lesser General Public License as published by * +* the Free Software Foundation; either version 2.1 of the License, or (at * +* your option) any later version. * +* * +* This program is distributed in the hope that it will be useful, but WITHOUT * +* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * +* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License * +* for more details. * +* * +* You should have received a copy of the GNU Lesser General Public License * +* along with this program. If not, see . * +******************************************************************************* +* Authors: The SOFA Team and external contributors (see Authors.txt) * +* * +* Contact information: contact@sofa-framework.org * +******************************************************************************/ +#ifndef SOFA_COMPONENT_MAPPING_BARYCENTRICMAPPERSPARSEGRIDTOPOLOGY_INL +#define SOFA_COMPONENT_MAPPING_BARYCENTRICMAPPERSPARSEGRIDTOPOLOGY_INL +#include "BarycentricMapperSparseGridTopology.h" + +namespace sofa +{ + +namespace component +{ + +namespace mapping +{ + +using sofa::defaulttype::Vector3; +using sofa::core::visual::VisualParams; +using sofa::defaulttype::Vec; + + +template +void BarycentricMapperSparseGridTopology::clear ( int size ) +{ + updateJ = true; + m_map.clear(); + if ( size>0 ) m_map.reserve ( size ); +} + + +template +void BarycentricMapperSparseGridTopology::resize( core::State* toModel ) +{ + toModel->resize(m_map.size()); +} + + +template +int BarycentricMapperSparseGridTopology::addPointInCube ( const int cubeIndex, const SReal* baryCoords ) +{ + m_map.resize ( m_map.size() +1 ); + CubeData& data = *m_map.rbegin(); + data.in_index = cubeIndex; + data.baryCoords[0] = ( Real ) baryCoords[0]; + data.baryCoords[1] = ( Real ) baryCoords[1]; + data.baryCoords[2] = ( Real ) baryCoords[2]; + return (int)m_map.size()-1; +} + + +template +void BarycentricMapperSparseGridTopology::init ( const typename Out::VecCoord& out, const typename In::VecCoord& /*in*/ ) +{ + if ( this->m_map.size() != 0 ) return; + updateJ = true; + clear ( (int)out.size() ); + + if ( m_fromTopology->isVolume() ) + { + for ( unsigned int i=0; ifindCube ( Vector3 ( Out::getCPos(out[i]) ), coefs[0], coefs[1], coefs[2] ); + if ( cube==-1 ) + { + cube = m_fromTopology->findNearestCube ( Vector3 ( Out::getCPos(out[i]) ), coefs[0], coefs[1], coefs[2] ); + } + Vector3 baryCoords = coefs; + this->addPointInCube ( cube, baryCoords.ptr() ); + } + } +} + + +template +void BarycentricMapperSparseGridTopology::draw (const VisualParams* vparams, + const typename Out::VecCoord& out, + const typename In::VecCoord& in ) +{ + std::vector< Vector3 > points; + for ( unsigned int i=0; im_fromTopology->getHexahedron ( this->m_map[i].in_index ); + + const Real fx = m_map[i].baryCoords[0]; + const Real fy = m_map[i].baryCoords[1]; + const Real fz = m_map[i].baryCoords[2]; + Real f[8]; + f[0] = ( 1-fx ) * ( 1-fy ) * ( 1-fz ); + f[1] = ( fx ) * ( 1-fy ) * ( 1-fz ); + + f[3] = ( 1-fx ) * ( fy ) * ( 1-fz ); + f[2] = ( fx ) * ( fy ) * ( 1-fz ); + + f[4] = ( 1-fx ) * ( 1-fy ) * ( fz ); + f[5] = ( fx ) * ( 1-fy ) * ( fz ); + + f[7] = ( 1-fx ) * ( fy ) * ( fz ); + f[6] = ( fx ) * ( fy ) * ( fz ); + + for ( int j=0; j<8; j++ ) + { + if ( f[j]<=-0.0001 || f[j]>=0.0001 ) + { + points.push_back ( Out::getCPos(out[i]) ); + points.push_back ( in[cube[j]] ); + } + } + } +// vparams->drawTool()->drawLines ( points, 1, Vec<4,float> ( 0,0,1,1 ) ); +} + + +template +const sofa::defaulttype::BaseMatrix* BarycentricMapperSparseGridTopology::getJ(int outSize, int inSize) +{ + if (matrixJ && !updateJ) + return matrixJ; + + if (!matrixJ) matrixJ = new MatrixType; + if (matrixJ->rowBSize() != (MatrixTypeIndex)outSize || matrixJ->colBSize() != (MatrixTypeIndex)inSize) + matrixJ->resize(outSize*NOut, inSize*NIn); + else + matrixJ->clear(); + + for ( size_t i=0; im_fromTopology->getHexahedron ( this->m_map[i].in_index ); + + const Real fx = ( Real ) m_map[i].baryCoords[0]; + const Real fy = ( Real ) m_map[i].baryCoords[1]; + const Real fz = ( Real ) m_map[i].baryCoords[2]; + this->addMatrixContrib(matrixJ, out, cube[0], ( ( 1-fx ) * ( 1-fy ) * ( 1-fz ) )); + this->addMatrixContrib(matrixJ, out, cube[1], ( ( fx ) * ( 1-fy ) * ( 1-fz ) )); + + this->addMatrixContrib(matrixJ, out, cube[3], ( ( 1-fx ) * ( fy ) * ( 1-fz ) )); + this->addMatrixContrib(matrixJ, out, cube[2], ( ( fx ) * ( fy ) * ( 1-fz ) )); + + this->addMatrixContrib(matrixJ, out, cube[4], ( ( 1-fx ) * ( 1-fy ) * ( fz ) )); + this->addMatrixContrib(matrixJ, out, cube[5], ( ( fx ) * ( 1-fy ) * ( fz ) )); + + this->addMatrixContrib(matrixJ, out, cube[7], ( ( 1-fx ) * ( fy ) * ( fz ) )); + this->addMatrixContrib(matrixJ, out, cube[6], ( ( fx ) * ( fy ) * ( fz ) )); + } + matrixJ->compress(); + updateJ = false; + return matrixJ; +} + + +template +void BarycentricMapperSparseGridTopology::applyJT ( typename In::VecDeriv& out, const typename Out::VecDeriv& in ) +{ + ForceMask& mask = *this->maskFrom; + + for( size_t index=0 ; indexmaskTo->size() ; ++index) + { + if( !this->maskTo->getEntry(index) ) continue; + + const typename Out::DPos v = Out::getDPos(in[index]); + + const topology::SparseGridTopology::Hexa cube = this->m_fromTopology->getHexahedron ( this->m_map[index].in_index ); + + const OutReal fx = ( OutReal ) m_map[index].baryCoords[0]; + const OutReal fy = ( OutReal ) m_map[index].baryCoords[1]; + const OutReal fz = ( OutReal ) m_map[index].baryCoords[2]; + out[cube[0]] += v * ( ( 1-fx ) * ( 1-fy ) * ( 1-fz ) ); + out[cube[1]] += v * ( ( fx ) * ( 1-fy ) * ( 1-fz ) ); + + out[cube[3]] += v * ( ( 1-fx ) * ( fy ) * ( 1-fz ) ); + out[cube[2]] += v * ( ( fx ) * ( fy ) * ( 1-fz ) ); + + out[cube[4]] += v * ( ( 1-fx ) * ( 1-fy ) * ( fz ) ); + out[cube[5]] += v * ( ( fx ) * ( 1-fy ) * ( fz ) ); + + out[cube[7]] += v * ( ( 1-fx ) * ( fy ) * ( fz ) ); + out[cube[6]] += v * ( ( fx ) * ( fy ) * ( fz ) ); + + mask.insertEntry(cube[0]); + mask.insertEntry(cube[1]); + mask.insertEntry(cube[2]); + mask.insertEntry(cube[3]); + mask.insertEntry(cube[4]); + mask.insertEntry(cube[5]); + mask.insertEntry(cube[6]); + mask.insertEntry(cube[7]); + } +} + + +template +void BarycentricMapperSparseGridTopology::applyJT ( typename In::MatrixDeriv& out, const typename Out::MatrixDeriv& in ) +{ + typename Out::MatrixDeriv::RowConstIterator rowItEnd = in.end(); + + for (typename Out::MatrixDeriv::RowConstIterator rowIt = in.begin(); rowIt != rowItEnd; ++rowIt) + { + typename Out::MatrixDeriv::ColConstIterator colItEnd = rowIt.end(); + typename Out::MatrixDeriv::ColConstIterator colIt = rowIt.begin(); + + if (colIt != colItEnd) + { + typename In::MatrixDeriv::RowIterator o = out.writeLine(rowIt.index()); + + for ( ; colIt != colItEnd; ++colIt) + { + unsigned indexIn = colIt.index(); + InDeriv data = (InDeriv) Out::getDPos(colIt.val()); + + + const topology::SparseGridTopology::Hexa cube = this->m_fromTopology->getHexahedron ( this->m_map[indexIn].in_index ); + + const OutReal fx = ( OutReal ) m_map[indexIn].baryCoords[0]; + const OutReal fy = ( OutReal ) m_map[indexIn].baryCoords[1]; + const OutReal fz = ( OutReal ) m_map[indexIn].baryCoords[2]; + const OutReal oneMinusFx = 1-fx; + const OutReal oneMinusFy = 1-fy; + const OutReal oneMinusFz = 1-fz; + + OutReal f = ( oneMinusFx * oneMinusFy * oneMinusFz ); + o.addCol ( cube[0], ( data * f ) ); + + f = ( ( fx ) * oneMinusFy * oneMinusFz ); + o.addCol ( cube[1], ( data * f ) ); + + + f = ( oneMinusFx * ( fy ) * oneMinusFz ); + o.addCol ( cube[3], ( data * f ) ); + + f = ( ( fx ) * ( fy ) * oneMinusFz ); + o.addCol ( cube[2], ( data * f ) ); + + + f = ( oneMinusFx * oneMinusFy * ( fz ) ); + o.addCol ( cube[4], ( data * f ) ); + + f = ( ( fx ) * oneMinusFy * ( fz ) ); + o.addCol ( cube[5], ( data * f ) ); + + + f = ( oneMinusFx * ( fy ) * ( fz ) ); + o.addCol ( cube[7], ( data * f ) ); + + f = ( ( fx ) * ( fy ) * ( fz ) ); + o.addCol ( cube[6], ( data * f ) ); + } + } + } +} + + +template +void BarycentricMapperSparseGridTopology::applyJ ( typename Out::VecDeriv& out, const typename In::VecDeriv& in ) +{ + out.resize( m_map.size() ); + + for( size_t index=0 ; indexmaskTo->size() ; ++index) + { + if( this->maskTo->isActivated() && !this->maskTo->getEntry(index) ) continue; + + const topology::SparseGridTopology::Hexa cube = this->m_fromTopology->getHexahedron ( this->m_map[index].in_index ); + + const Real fx = m_map[index].baryCoords[0]; + const Real fy = m_map[index].baryCoords[1]; + const Real fz = m_map[index].baryCoords[2]; + Out::setDPos(out[index] , in[cube[0]] * ( ( 1-fx ) * ( 1-fy ) * ( 1-fz ) ) + + in[cube[1]] * ( ( fx ) * ( 1-fy ) * ( 1-fz ) ) + + in[cube[3]] * ( ( 1-fx ) * ( fy ) * ( 1-fz ) ) + + in[cube[2]] * ( ( fx ) * ( fy ) * ( 1-fz ) ) + + in[cube[4]] * ( ( 1-fx ) * ( 1-fy ) * ( fz ) ) + + in[cube[5]] * ( ( fx ) * ( 1-fy ) * ( fz ) ) + + in[cube[7]] * ( ( 1-fx ) * ( fy ) * ( fz ) ) + + in[cube[6]] * ( ( fx ) * ( fy ) * ( fz ) ) ); + } + +} + + +template +void BarycentricMapperSparseGridTopology::apply ( typename Out::VecCoord& out, const typename In::VecCoord& in ) +{ + out.resize( m_map.size() ); + + typedef helper::vector< CubeData > CubeDataVector; + typedef typename CubeDataVector::const_iterator CubeDataVectorIt; + + CubeDataVectorIt it = m_map.begin(); + CubeDataVectorIt itEnd = m_map.end(); + + unsigned int i = 0; + + while (it != itEnd) + { + const topology::SparseGridTopology::Hexa cube = this->m_fromTopology->getHexahedron( it->in_index ); + + const Real fx = it->baryCoords[0]; + const Real fy = it->baryCoords[1]; + const Real fz = it->baryCoords[2]; + + Out::setCPos(out[i] , in[cube[0]] * ( ( 1-fx ) * ( 1-fy ) * ( 1-fz ) ) + + in[cube[1]] * ( ( fx ) * ( 1-fy ) * ( 1-fz ) ) + + in[cube[3]] * ( ( 1-fx ) * ( fy ) * ( 1-fz ) ) + + in[cube[2]] * ( ( fx ) * ( fy ) * ( 1-fz ) ) + + in[cube[4]] * ( ( 1-fx ) * ( 1-fy ) * ( fz ) ) + + in[cube[5]] * ( ( fx ) * ( 1-fy ) * ( fz ) ) + + in[cube[7]] * ( ( 1-fx ) * ( fy ) * ( fz ) ) + + in[cube[6]] * ( ( fx ) * ( fy ) * ( fz ) ) ); + + ++it; + ++i; + } +} + + +}}} + +#endif diff --git a/SofaKernel/modules/SofaBaseMechanics/BarycentricMappers/BarycentricMapperTetrahedronSetTopology.cpp b/SofaKernel/modules/SofaBaseMechanics/BarycentricMappers/BarycentricMapperTetrahedronSetTopology.cpp new file mode 100644 index 00000000000..466496fb8d1 --- /dev/null +++ b/SofaKernel/modules/SofaBaseMechanics/BarycentricMappers/BarycentricMapperTetrahedronSetTopology.cpp @@ -0,0 +1,56 @@ +/****************************************************************************** +* SOFA, Simulation Open-Framework Architecture, development version * +* (c) 2006-2018 INRIA, USTL, UJF, CNRS, MGH * +* * +* This program is free software; you can redistribute it and/or modify it * +* under the terms of the GNU Lesser General Public License as published by * +* the Free Software Foundation; either version 2.1 of the License, or (at * +* your option) any later version. * +* * +* This program is distributed in the hope that it will be useful, but WITHOUT * +* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * +* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License * +* for more details. * +* * +* You should have received a copy of the GNU Lesser General Public License * +* along with this program. If not, see . * +******************************************************************************* +* Authors: The SOFA Team and external contributors (see Authors.txt) * +* * +* Contact information: contact@sofa-framework.org * +******************************************************************************/ +#ifndef SOFA_COMPONENT_MAPPING_BARYCENTRICMAPPERTETRAHEDRONSETTOPOLOGY_CPP +#define SOFA_COMPONENT_MAPPING_BARYCENTRICMAPPERTETRAHEDRONSETTOPOLOGY_CPP + +#include "BarycentricMapperTetrahedronSetTopology.inl" + +namespace sofa +{ + +namespace component +{ + +namespace mapping +{ + +using namespace sofa::defaulttype; + +#ifndef SOFA_FLOAT +template class SOFA_BASE_MECHANICS_API BarycentricMapperTetrahedronSetTopology< Vec3dTypes, Vec3dTypes >; +template class SOFA_BASE_MECHANICS_API BarycentricMapperTetrahedronSetTopology< Vec3dTypes, ExtVec3fTypes >; +#endif +#ifndef SOFA_DOUBLE +template class SOFA_BASE_MECHANICS_API BarycentricMapperTetrahedronSetTopology< Vec3fTypes, Vec3fTypes >; +template class SOFA_BASE_MECHANICS_API BarycentricMapperTetrahedronSetTopology< Vec3fTypes, ExtVec3fTypes >; +#endif +#ifndef SOFA_FLOAT +#ifndef SOFA_DOUBLE +template class SOFA_BASE_MECHANICS_API BarycentricMapperTetrahedronSetTopology< Vec3dTypes, Vec3fTypes >; +template class SOFA_BASE_MECHANICS_API BarycentricMapperTetrahedronSetTopology< Vec3fTypes, Vec3dTypes >; +#endif +#endif + +}}} + + +#endif diff --git a/SofaKernel/modules/SofaBaseMechanics/BarycentricMappers/BarycentricMapperTetrahedronSetTopology.h b/SofaKernel/modules/SofaBaseMechanics/BarycentricMappers/BarycentricMapperTetrahedronSetTopology.h new file mode 100644 index 00000000000..a14377d78a1 --- /dev/null +++ b/SofaKernel/modules/SofaBaseMechanics/BarycentricMappers/BarycentricMapperTetrahedronSetTopology.h @@ -0,0 +1,113 @@ +/****************************************************************************** +* SOFA, Simulation Open-Framework Architecture, development version * +* (c) 2006-2018 INRIA, USTL, UJF, CNRS, MGH * +* * +* This program is free software; you can redistribute it and/or modify it * +* under the terms of the GNU Lesser General Public License as published by * +* the Free Software Foundation; either version 2.1 of the License, or (at * +* your option) any later version. * +* * +* This program is distributed in the hope that it will be useful, but WITHOUT * +* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * +* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License * +* for more details. * +* * +* You should have received a copy of the GNU Lesser General Public License * +* along with this program. If not, see . * +******************************************************************************* +* Authors: The SOFA Team and external contributors (see Authors.txt) * +* * +* Contact information: contact@sofa-framework.org * +******************************************************************************/ +#ifndef SOFA_COMPONENT_MAPPING_BARYCENTRICMAPPERTETRAHEDRONSETTOPOLOGY_H +#define SOFA_COMPONENT_MAPPING_BARYCENTRICMAPPERTETRAHEDRONSETTOPOLOGY_H + +#include +#include +#include + +namespace sofa +{ + +namespace component +{ + +namespace mapping +{ + + +using sofa::defaulttype::Mat3x3d; +using sofa::defaulttype::Vector3; +typedef typename sofa::core::topology::BaseMeshTopology::Tetrahedron Tetrahedron; + + +/// Class allowing barycentric mapping computation on a TetrahedronSetTopology +template +class SOFA_BASE_MECHANICS_API BarycentricMapperTetrahedronSetTopology : public BarycentricMapperTopologyContainer::MappingData3D,Tetrahedron> +{ + typedef typename BarycentricMapper::MappingData3D MappingData; + +public: + + SOFA_CLASS(SOFA_TEMPLATE2(BarycentricMapperTetrahedronSetTopology,In,Out),SOFA_TEMPLATE4(BarycentricMapperTopologyContainer,In,Out,MappingData,Tetrahedron)); + typedef typename Inherit1::Real Real; + typedef typename In::VecCoord VecCoord; + + +protected: + + topology::TetrahedronSetTopologyContainer* m_fromContainer; + topology::TetrahedronSetGeometryAlgorithms* m_fromGeomAlgo; + + using Inherit1::d_map; + using Inherit1::m_fromTopology; + using Inherit1::m_matrixJ; + using Inherit1::m_updateJ; + + BarycentricMapperTetrahedronSetTopology(topology::TetrahedronSetTopologyContainer* fromTopology, topology::PointSetTopologyContainer* toTopology) + : Inherit1(fromTopology, toTopology), + m_fromContainer(fromTopology), + m_fromGeomAlgo(NULL) + {} + + virtual ~BarycentricMapperTetrahedronSetTopology() override {} + + virtual helper::vector getElements() override; + virtual helper::vector getBaryCoef(const Real* f) override; + helper::vector getBaryCoef(const Real fx, const Real fy, const Real fz); + virtual void computeBase(Mat3x3d& base, const typename In::VecCoord& in, const Tetrahedron& element) override; + virtual void computeCenter(Vector3& center, const typename In::VecCoord& in, const Tetrahedron& element) override; + virtual void computeDistance(double& d, const Vector3& v) override; + virtual void addPointInElement(const int elementIndex, const SReal* baryCoords) override; + +public: + + virtual int addPointInTetra(const int index, const SReal* baryCoords) override ; +}; + + +using sofa::defaulttype::Vec3dTypes; +using sofa::defaulttype::Vec3fTypes; +using sofa::defaulttype::ExtVec3fTypes; + + +#if defined(SOFA_EXTERN_TEMPLATE) && !defined(SOFA_COMPONENT_MAPPING_BARYCENTRICMAPPERTETRAHEDRONSETTOPOLOGY_CPP) +#ifndef SOFA_FLOAT +extern template class SOFA_BASE_MECHANICS_API BarycentricMapperTetrahedronSetTopology< Vec3dTypes, Vec3dTypes >; +extern template class SOFA_BASE_MECHANICS_API BarycentricMapperTetrahedronSetTopology< Vec3dTypes, ExtVec3fTypes >; +#endif +#ifndef SOFA_DOUBLE +extern template class SOFA_BASE_MECHANICS_API BarycentricMapperTetrahedronSetTopology< Vec3fTypes, Vec3fTypes >; +extern template class SOFA_BASE_MECHANICS_API BarycentricMapperTetrahedronSetTopology< Vec3fTypes, ExtVec3fTypes >; +#endif +#ifndef SOFA_FLOAT +#ifndef SOFA_DOUBLE +extern template class SOFA_BASE_MECHANICS_API BarycentricMapperTetrahedronSetTopology< Vec3dTypes, Vec3fTypes >; +extern template class SOFA_BASE_MECHANICS_API BarycentricMapperTetrahedronSetTopology< Vec3fTypes, Vec3dTypes >; +#endif +#endif +#endif + +}}} + +#endif diff --git a/SofaKernel/modules/SofaBaseMechanics/BarycentricMappers/BarycentricMapperTetrahedronSetTopology.inl b/SofaKernel/modules/SofaBaseMechanics/BarycentricMappers/BarycentricMapperTetrahedronSetTopology.inl new file mode 100644 index 00000000000..8755a71db81 --- /dev/null +++ b/SofaKernel/modules/SofaBaseMechanics/BarycentricMappers/BarycentricMapperTetrahedronSetTopology.inl @@ -0,0 +1,101 @@ +/****************************************************************************** +* SOFA, Simulation Open-Framework Architecture, development version * +* (c) 2006-2018 INRIA, USTL, UJF, CNRS, MGH * +* * +* This program is free software; you can redistribute it and/or modify it * +* under the terms of the GNU Lesser General Public License as published by * +* the Free Software Foundation; either version 2.1 of the License, or (at * +* your option) any later version. * +* * +* This program is distributed in the hope that it will be useful, but WITHOUT * +* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * +* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License * +* for more details. * +* * +* You should have received a copy of the GNU Lesser General Public License * +* along with this program. If not, see . * +******************************************************************************* +* Authors: The SOFA Team and external contributors (see Authors.txt) * +* * +* Contact information: contact@sofa-framework.org * +******************************************************************************/ +#ifndef SOFA_COMPONENT_MAPPING_BARYCENTRICMAPPERTETRAHEDRONSETTOPOLOGY_INL +#define SOFA_COMPONENT_MAPPING_BARYCENTRICMAPPERTETRAHEDRONSETTOPOLOGY_INL + +#include "BarycentricMapperTetrahedronSetTopology.h" + +namespace sofa +{ + +namespace component +{ + +namespace mapping +{ + + +template +int BarycentricMapperTetrahedronSetTopology::addPointInTetra ( const int tetraIndex, const SReal* baryCoords ) +{ + helper::vector& vectorData = *(d_map.beginEdit()); + vectorData.resize ( d_map.getValue().size() +1 ); + MappingData& data = *vectorData.rbegin(); + d_map.endEdit(); + data.in_index = tetraIndex; + data.baryCoords[0] = ( Real ) baryCoords[0]; + data.baryCoords[1] = ( Real ) baryCoords[1]; + data.baryCoords[2] = ( Real ) baryCoords[2]; + return (int)d_map.getValue().size()-1; +} + +template +helper::vector BarycentricMapperTetrahedronSetTopology::getElements() +{ + return this->m_fromTopology->getTetrahedra(); +} + +template +helper::vector BarycentricMapperTetrahedronSetTopology::getBaryCoef(const Real* f) +{ + return getBaryCoef(f[0],f[1],f[2]); +} + +template +helper::vector BarycentricMapperTetrahedronSetTopology::getBaryCoef(const Real fx, const Real fy, const Real fz) +{ + helper::vector tetrahedronCoef{(1-fx-fy-fz),fx,fy,fz}; + return tetrahedronCoef; +} + +template +void BarycentricMapperTetrahedronSetTopology::computeBase(Mat3x3d& base, const typename In::VecCoord& in, const Tetrahedron& element) +{ + Mat3x3d matrixTranspose; + base[0] = in[element[1]]-in[element[0]]; + base[1] = in[element[2]]-in[element[0]]; + base[2] = in[element[3]]-in[element[0]]; + matrixTranspose.transpose(base); + base.invert(matrixTranspose); +} + +template +void BarycentricMapperTetrahedronSetTopology::computeCenter(Vector3& center, const typename In::VecCoord& in, const Tetrahedron& element) +{ + center = ( in[element[0]]+in[element[1]]+in[element[2]]+in[element[3]] ) *0.25; +} + +template +void BarycentricMapperTetrahedronSetTopology::computeDistance(double& d, const Vector3& v) +{ + d = std::max ( std::max ( -v[0],-v[1] ), std::max ( -v[2],v[0]+v[1]+v[2]-1 ) ); +} + +template +void BarycentricMapperTetrahedronSetTopology::addPointInElement(const int elementIndex, const SReal* baryCoords) +{ + addPointInTetra(elementIndex,baryCoords); +} + +}}} + +#endif diff --git a/SofaKernel/modules/SofaBaseMechanics/BarycentricMappers/BarycentricMapperTopologyContainer.cpp b/SofaKernel/modules/SofaBaseMechanics/BarycentricMappers/BarycentricMapperTopologyContainer.cpp new file mode 100644 index 00000000000..bf407bd2622 --- /dev/null +++ b/SofaKernel/modules/SofaBaseMechanics/BarycentricMappers/BarycentricMapperTopologyContainer.cpp @@ -0,0 +1,83 @@ +/****************************************************************************** +* SOFA, Simulation Open-Framework Architecture, development version * +* (c) 2006-2018 INRIA, USTL, UJF, CNRS, MGH * +* * +* This program is free software; you can redistribute it and/or modify it * +* under the terms of the GNU Lesser General Public License as published by * +* the Free Software Foundation; either version 2.1 of the License, or (at * +* your option) any later version. * +* * +* This program is distributed in the hope that it will be useful, but WITHOUT * +* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * +* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License * +* for more details. * +* * +* You should have received a copy of the GNU Lesser General Public License * +* along with this program. If not, see . * +******************************************************************************* +* Authors: The SOFA Team and external contributors (see Authors.txt) * +* * +* Contact information: contact@sofa-framework.org * +******************************************************************************/ +#ifndef SOFA_COMPONENT_MAPPING_BARYCENTRICMAPPERTOPOLOGYCONTAINER_CPP +#define SOFA_COMPONENT_MAPPING_BARYCENTRICMAPPERTOPOLOGYCONTAINER_CPP + +#include "BarycentricMapperTopologyContainer.inl" + +namespace sofa +{ + +namespace component +{ + +namespace mapping +{ + +namespace _barycentricmappertopologycontainer_ +{ + +using namespace sofa::defaulttype; + +#ifndef SOFA_FLOAT +template class SOFA_BASE_MECHANICS_API BarycentricMapperTopologyContainer< Vec3dTypes, Vec3dTypes , typename BarycentricMapper::MappingData1D, Edge>; +template class SOFA_BASE_MECHANICS_API BarycentricMapperTopologyContainer< Vec3dTypes, ExtVec3fTypes , typename BarycentricMapper::MappingData1D, Edge>; +template class SOFA_BASE_MECHANICS_API BarycentricMapperTopologyContainer< Vec3dTypes, Vec3dTypes , typename BarycentricMapper::MappingData2D, Triangle>; +template class SOFA_BASE_MECHANICS_API BarycentricMapperTopologyContainer< Vec3dTypes, ExtVec3fTypes , typename BarycentricMapper::MappingData2D, Triangle>; +template class SOFA_BASE_MECHANICS_API BarycentricMapperTopologyContainer< Vec3dTypes, Vec3dTypes , typename BarycentricMapper::MappingData2D, Quad>; +template class SOFA_BASE_MECHANICS_API BarycentricMapperTopologyContainer< Vec3dTypes, ExtVec3fTypes , typename BarycentricMapper::MappingData2D, Quad>; +template class SOFA_BASE_MECHANICS_API BarycentricMapperTopologyContainer< Vec3dTypes, Vec3dTypes , typename BarycentricMapper::MappingData3D, Tetrahedron>; +template class SOFA_BASE_MECHANICS_API BarycentricMapperTopologyContainer< Vec3dTypes, ExtVec3fTypes , typename BarycentricMapper::MappingData3D, Tetrahedron>; +template class SOFA_BASE_MECHANICS_API BarycentricMapperTopologyContainer< Vec3dTypes, Vec3dTypes , typename BarycentricMapper::MappingData3D, Hexahedron>; +template class SOFA_BASE_MECHANICS_API BarycentricMapperTopologyContainer< Vec3dTypes, ExtVec3fTypes , typename BarycentricMapper::MappingData3D, Hexahedron>; +#endif +#ifndef SOFA_DOUBLE +template class SOFA_BASE_MECHANICS_API BarycentricMapperTopologyContainer< Vec3fTypes, Vec3fTypes , typename BarycentricMapper::MappingData1D, Edge>; +template class SOFA_BASE_MECHANICS_API BarycentricMapperTopologyContainer< Vec3fTypes, ExtVec3fTypes , typename BarycentricMapper::MappingData1D, Edge>; +template class SOFA_BASE_MECHANICS_API BarycentricMapperTopologyContainer< Vec3fTypes, Vec3fTypes , typename BarycentricMapper::MappingData2D, Triangle>; +template class SOFA_BASE_MECHANICS_API BarycentricMapperTopologyContainer< Vec3fTypes, ExtVec3fTypes , typename BarycentricMapper::MappingData2D, Triangle>; +template class SOFA_BASE_MECHANICS_API BarycentricMapperTopologyContainer< Vec3fTypes, Vec3fTypes , typename BarycentricMapper::MappingData2D, Quad>; +template class SOFA_BASE_MECHANICS_API BarycentricMapperTopologyContainer< Vec3fTypes, ExtVec3fTypes , typename BarycentricMapper::MappingData2D, Quad>; +template class SOFA_BASE_MECHANICS_API BarycentricMapperTopologyContainer< Vec3fTypes, Vec3fTypes , typename BarycentricMapper::MappingData3D, Tetrahedron>; +template class SOFA_BASE_MECHANICS_API BarycentricMapperTopologyContainer< Vec3fTypes, ExtVec3fTypes , typename BarycentricMapper::MappingData3D, Tetrahedron>; +template class SOFA_BASE_MECHANICS_API BarycentricMapperTopologyContainer< Vec3fTypes, Vec3fTypes , typename BarycentricMapper::MappingData3D, Hexahedron>; +template class SOFA_BASE_MECHANICS_API BarycentricMapperTopologyContainer< Vec3fTypes, ExtVec3fTypes , typename BarycentricMapper::MappingData3D, Hexahedron>; +#endif +#ifndef SOFA_FLOAT +#ifndef SOFA_DOUBLE +template class SOFA_BASE_MECHANICS_API BarycentricMapperTopologyContainer< Vec3dTypes, Vec3fTypes , typename BarycentricMapper::MappingData1D,Edge>; +template class SOFA_BASE_MECHANICS_API BarycentricMapperTopologyContainer< Vec3fTypes, Vec3dTypes , typename BarycentricMapper::MappingData1D,Edge>; +template class SOFA_BASE_MECHANICS_API BarycentricMapperTopologyContainer< Vec3dTypes, Vec3fTypes , typename BarycentricMapper::MappingData2D,Triangle>; +template class SOFA_BASE_MECHANICS_API BarycentricMapperTopologyContainer< Vec3fTypes, Vec3dTypes , typename BarycentricMapper::MappingData2D,Triangle>; +template class SOFA_BASE_MECHANICS_API BarycentricMapperTopologyContainer< Vec3dTypes, Vec3fTypes , typename BarycentricMapper::MappingData2D,Quad>; +template class SOFA_BASE_MECHANICS_API BarycentricMapperTopologyContainer< Vec3fTypes, Vec3dTypes , typename BarycentricMapper::MappingData2D,Quad>; +template class SOFA_BASE_MECHANICS_API BarycentricMapperTopologyContainer< Vec3dTypes, Vec3fTypes , typename BarycentricMapper::MappingData3D,Tetrahedron>; +template class SOFA_BASE_MECHANICS_API BarycentricMapperTopologyContainer< Vec3fTypes, Vec3dTypes , typename BarycentricMapper::MappingData3D,Tetrahedron>; +template class SOFA_BASE_MECHANICS_API BarycentricMapperTopologyContainer< Vec3dTypes, Vec3fTypes , typename BarycentricMapper::MappingData3D,Hexahedron>; +template class SOFA_BASE_MECHANICS_API BarycentricMapperTopologyContainer< Vec3fTypes, Vec3dTypes , typename BarycentricMapper::MappingData3D,Hexahedron>; +#endif +#endif + +}}}} + + +#endif diff --git a/SofaKernel/modules/SofaBaseMechanics/BarycentricMappers/BarycentricMapperTopologyContainer.h b/SofaKernel/modules/SofaBaseMechanics/BarycentricMappers/BarycentricMapperTopologyContainer.h new file mode 100644 index 00000000000..c0f2dfd17c4 --- /dev/null +++ b/SofaKernel/modules/SofaBaseMechanics/BarycentricMappers/BarycentricMapperTopologyContainer.h @@ -0,0 +1,192 @@ +/****************************************************************************** +* SOFA, Simulation Open-Framework Architecture, development version * +* (c) 2006-2018 INRIA, USTL, UJF, CNRS, MGH * +* * +* This program is free software; you can redistribute it and/or modify it * +* under the terms of the GNU Lesser General Public License as published by * +* the Free Software Foundation; either version 2.1 of the License, or (at * +* your option) any later version. * +* * +* This program is distributed in the hope that it will be useful, but WITHOUT * +* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * +* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License * +* for more details. * +* * +* You should have received a copy of the GNU Lesser General Public License * +* along with this program. If not, see . * +******************************************************************************* +* Authors: The SOFA Team and external contributors (see Authors.txt) * +* * +* Contact information: contact@sofa-framework.org * +******************************************************************************/ +#ifndef SOFA_COMPONENT_MAPPING_BARYCENTRICMAPPERTOPOLOGYCONTAINER_H +#define SOFA_COMPONENT_MAPPING_BARYCENTRICMAPPERTOPOLOGYCONTAINER_H + +#include +#include + +namespace sofa +{ + +namespace component +{ + +namespace mapping +{ + +namespace _barycentricmappertopologycontainer_ +{ + +using sofa::defaulttype::Mat3x3d; +using sofa::defaulttype::Vector3; + + +/// Template class for topology container mappers +template +class SOFA_BASE_MECHANICS_API BarycentricMapperTopologyContainer : public TopologyBarycentricMapper +{ + +public: + + SOFA_CLASS(SOFA_TEMPLATE4(BarycentricMapperTopologyContainer,In,Out,MappingDataType,Element),SOFA_TEMPLATE2(TopologyBarycentricMapper,In,Out)); + typedef typename Inherit1::Real Real; + typedef typename Inherit1::OutReal OutReal; + typedef typename Inherit1::OutDeriv OutDeriv; + typedef typename Inherit1::InDeriv InDeriv; + + typedef typename Inherit1::MBloc MBloc; + typedef typename Inherit1::MatrixType MatrixType; + + typedef typename Inherit1::ForceMask ForceMask; + typedef typename MatrixType::Index MatrixTypeIndex; + enum { NIn = Inherit1::NIn }; + enum { NOut = Inherit1::NOut }; + +public: + + virtual void init(const typename Out::VecCoord& out, const typename In::VecCoord& in) override; + virtual void draw(const core::visual::VisualParams*,const typename Out::VecCoord& out, const typename In::VecCoord& in) override; + + virtual void clear(int size=0) override; + virtual void resize( core::State* toModel ) override; + + virtual void apply( typename Out::VecCoord& out, const typename In::VecCoord& in ) override; + virtual void applyJ( typename Out::VecDeriv& out, const typename In::VecDeriv& in ) override; + virtual void applyJT( typename In::VecDeriv& out, const typename Out::VecDeriv& in ) override; + virtual void applyJT( typename In::MatrixDeriv& out, const typename Out::MatrixDeriv& in ) override; + virtual const sofa::defaulttype::BaseMatrix* getJ(int outSize, int inSize) override; + + inline friend std::istream& operator >> ( std::istream& in, BarycentricMapperTopologyContainer &b ) + { + unsigned int size_vec; + + in >> size_vec; + sofa::helper::vector& m = *(b.d_map.beginEdit()); + m.clear(); + + MappingDataType value; + for (unsigned int i=0; i> value; + m.push_back(value); + } + b.d_map.endEdit(); + return in; + } + + inline friend std::ostream& operator << ( std::ostream& out, const BarycentricMapperTopologyContainer & b ) + { + + out << b.d_map.getValue().size(); + out << " " ; + out << b.d_map; + + return out; + } + + bool isEmpty(); + +protected: + topology::PointData< helper::vector > d_map; + MatrixType* m_matrixJ; + bool m_updateJ; + + BarycentricMapperTopologyContainer(core::topology::BaseMeshTopology* fromTopology, topology::PointSetTopologyContainer* toTopology) + : Inherit1(fromTopology, toTopology), + d_map(initData(&d_map,"map", "mapper data")), + m_matrixJ(NULL), + m_updateJ(true) + {} + + virtual ~BarycentricMapperTopologyContainer() override {} + +protected: + + virtual helper::vector getElements()=0; + virtual helper::vector getBaryCoef(const Real* f)=0; + virtual void computeBase(Mat3x3d& base, const typename In::VecCoord& in, const Element& element)=0; + virtual void computeCenter(Vector3& center, const typename In::VecCoord& in, const Element& element)=0; + virtual void addPointInElement(const int elementIndex, const SReal* baryCoords)=0; + virtual void computeDistance(double& d, const Vector3& v)=0; + +}; + + +using sofa::defaulttype::Vec3dTypes; +using sofa::defaulttype::Vec3fTypes; +using sofa::defaulttype::ExtVec3fTypes; +typedef typename sofa::core::topology::BaseMeshTopology::Edge Edge; +typedef typename sofa::core::topology::BaseMeshTopology::Triangle Triangle; +typedef typename sofa::core::topology::BaseMeshTopology::Quad Quad; +typedef typename sofa::core::topology::BaseMeshTopology::Tetrahedron Tetrahedron; +typedef typename sofa::core::topology::BaseMeshTopology::Hexahedron Hexahedron; + + +#if defined(SOFA_EXTERN_TEMPLATE) && !defined(SOFA_COMPONENT_MAPPING_BARYCENTRICMAPPERTOPOLOGYCONTAINER_CPP) +#ifndef SOFA_FLOAT +extern template class SOFA_BASE_MECHANICS_API BarycentricMapperTopologyContainer< Vec3dTypes, Vec3dTypes , typename BarycentricMapper::MappingData1D, Edge>; +extern template class SOFA_BASE_MECHANICS_API BarycentricMapperTopologyContainer< Vec3dTypes, ExtVec3fTypes , typename BarycentricMapper::MappingData1D, Edge>; +extern template class SOFA_BASE_MECHANICS_API BarycentricMapperTopologyContainer< Vec3dTypes, Vec3dTypes , typename BarycentricMapper::MappingData2D, Triangle>; +extern template class SOFA_BASE_MECHANICS_API BarycentricMapperTopologyContainer< Vec3dTypes, ExtVec3fTypes , typename BarycentricMapper::MappingData2D, Triangle>; +extern template class SOFA_BASE_MECHANICS_API BarycentricMapperTopologyContainer< Vec3dTypes, Vec3dTypes , typename BarycentricMapper::MappingData2D, Quad>; +extern template class SOFA_BASE_MECHANICS_API BarycentricMapperTopologyContainer< Vec3dTypes, ExtVec3fTypes , typename BarycentricMapper::MappingData2D, Quad>; +extern template class SOFA_BASE_MECHANICS_API BarycentricMapperTopologyContainer< Vec3dTypes, Vec3dTypes , typename BarycentricMapper::MappingData3D, Tetrahedron>; +extern template class SOFA_BASE_MECHANICS_API BarycentricMapperTopologyContainer< Vec3dTypes, ExtVec3fTypes , typename BarycentricMapper::MappingData3D, Tetrahedron>; +extern template class SOFA_BASE_MECHANICS_API BarycentricMapperTopologyContainer< Vec3dTypes, Vec3dTypes , typename BarycentricMapper::MappingData3D, Hexahedron>; +extern template class SOFA_BASE_MECHANICS_API BarycentricMapperTopologyContainer< Vec3dTypes, ExtVec3fTypes , typename BarycentricMapper::MappingData3D, Hexahedron>; +#endif +#ifndef SOFA_DOUBLE +extern template class SOFA_BASE_MECHANICS_API BarycentricMapperTopologyContainer< Vec3fTypes, Vec3fTypes , typename BarycentricMapper::MappingData1D, Edge>; +extern template class SOFA_BASE_MECHANICS_API BarycentricMapperTopologyContainer< Vec3fTypes, ExtVec3fTypes , typename BarycentricMapper::MappingData1D, Edge>; +extern template class SOFA_BASE_MECHANICS_API BarycentricMapperTopologyContainer< Vec3fTypes, Vec3fTypes , typename BarycentricMapper::MappingData2D, Triangle>; +extern template class SOFA_BASE_MECHANICS_API BarycentricMapperTopologyContainer< Vec3fTypes, ExtVec3fTypes , typename BarycentricMapper::MappingData2D, Triangle>; +extern template class SOFA_BASE_MECHANICS_API BarycentricMapperTopologyContainer< Vec3fTypes, Vec3fTypes , typename BarycentricMapper::MappingData2D, Quad>; +extern template class SOFA_BASE_MECHANICS_API BarycentricMapperTopologyContainer< Vec3fTypes, ExtVec3fTypes , typename BarycentricMapper::MappingData2D, Quad>; +extern template class SOFA_BASE_MECHANICS_API BarycentricMapperTopologyContainer< Vec3fTypes, Vec3fTypes , typename BarycentricMapper::MappingData3D, Tetrahedron>; +extern template class SOFA_BASE_MECHANICS_API BarycentricMapperTopologyContainer< Vec3fTypes, ExtVec3fTypes , typename BarycentricMapper::MappingData3D, Tetrahedron>; +extern template class SOFA_BASE_MECHANICS_API BarycentricMapperTopologyContainer< Vec3fTypes, Vec3fTypes , typename BarycentricMapper::MappingData3D, Hexahedron>; +extern template class SOFA_BASE_MECHANICS_API BarycentricMapperTopologyContainer< Vec3fTypes, ExtVec3fTypes , typename BarycentricMapper::MappingData3D, Hexahedron>; +#endif +#ifndef SOFA_FLOAT +#ifndef SOFA_DOUBLE +extern template class SOFA_BASE_MECHANICS_API BarycentricMapperTopologyContainer< Vec3dTypes, Vec3fTypes , typename BarycentricMapper::MappingData1D,Edge>; +extern template class SOFA_BASE_MECHANICS_API BarycentricMapperTopologyContainer< Vec3fTypes, Vec3dTypes , typename BarycentricMapper::MappingData1D,Edge>; +extern template class SOFA_BASE_MECHANICS_API BarycentricMapperTopologyContainer< Vec3dTypes, Vec3fTypes , typename BarycentricMapper::MappingData2D,Triangle>; +extern template class SOFA_BASE_MECHANICS_API BarycentricMapperTopologyContainer< Vec3fTypes, Vec3dTypes , typename BarycentricMapper::MappingData2D,Triangle>; +extern template class SOFA_BASE_MECHANICS_API BarycentricMapperTopologyContainer< Vec3dTypes, Vec3fTypes , typename BarycentricMapper::MappingData2D,Quad>; +extern template class SOFA_BASE_MECHANICS_API BarycentricMapperTopologyContainer< Vec3fTypes, Vec3dTypes , typename BarycentricMapper::MappingData2D,Quad>; +extern template class SOFA_BASE_MECHANICS_API BarycentricMapperTopologyContainer< Vec3dTypes, Vec3fTypes , typename BarycentricMapper::MappingData3D,Tetrahedron>; +extern template class SOFA_BASE_MECHANICS_API BarycentricMapperTopologyContainer< Vec3fTypes, Vec3dTypes , typename BarycentricMapper::MappingData3D,Tetrahedron>; +extern template class SOFA_BASE_MECHANICS_API BarycentricMapperTopologyContainer< Vec3dTypes, Vec3fTypes , typename BarycentricMapper::MappingData3D,Hexahedron>; +extern template class SOFA_BASE_MECHANICS_API BarycentricMapperTopologyContainer< Vec3fTypes, Vec3dTypes , typename BarycentricMapper::MappingData3D,Hexahedron>; +#endif +#endif +#endif + +} + +using _barycentricmappertopologycontainer_::BarycentricMapperTopologyContainer; + +}}} + +#endif diff --git a/SofaKernel/modules/SofaBaseMechanics/BarycentricMappers/BarycentricMapperTopologyContainer.inl b/SofaKernel/modules/SofaBaseMechanics/BarycentricMappers/BarycentricMapperTopologyContainer.inl new file mode 100644 index 00000000000..5b4cac8dc0a --- /dev/null +++ b/SofaKernel/modules/SofaBaseMechanics/BarycentricMappers/BarycentricMapperTopologyContainer.inl @@ -0,0 +1,278 @@ +/****************************************************************************** +* SOFA, Simulation Open-Framework Architecture, development version * +* (c) 2006-2018 INRIA, USTL, UJF, CNRS, MGH * +* * +* This program is free software; you can redistribute it and/or modify it * +* under the terms of the GNU Lesser General Public License as published by * +* the Free Software Foundation; either version 2.1 of the License, or (at * +* your option) any later version. * +* * +* This program is distributed in the hope that it will be useful, but WITHOUT * +* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * +* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License * +* for more details. * +* * +* You should have received a copy of the GNU Lesser General Public License * +* along with this program. If not, see . * +******************************************************************************* +* Authors: The SOFA Team and external contributors (see Authors.txt) * +* * +* Contact information: contact@sofa-framework.org * +******************************************************************************/ +#ifndef SOFA_COMPONENT_MAPPING_BARYCENTRICMAPPERTOPOLOGYCONTAINER_INL +#define SOFA_COMPONENT_MAPPING_BARYCENTRICMAPPERTOPOLOGYCONTAINER_INL +#include "BarycentricMapperTopologyContainer.h" + +namespace sofa +{ + +namespace component +{ + +namespace mapping +{ + +namespace _barycentricmappertopologycontainer_ +{ + +using defaulttype::Vec3d; + +template +void BarycentricMapperTopologyContainer::clear(int size) +{ + helper::vector& vectorData = *(d_map.beginEdit()); + vectorData.clear(); + if ( size>0 ) vectorData.reserve ( size ); + d_map.endEdit(); +} + + +template +void BarycentricMapperTopologyContainer::init ( const typename Out::VecCoord& out, const typename In::VecCoord& in ) +{ + const helper::vector& elements = getElements(); + helper::vector bases; + helper::vector centers; + + this->clear ( (int)out.size() ); + bases.resize ( elements.size() ); + centers.resize ( elements.size() ); + + // Compute bases and centers of each element + for ( unsigned int e = 0; e < elements.size(); e++ ) + { + Element element = elements[e]; + + Mat3x3d base; + computeBase(base,in,element); + bases[e] = base; + + Vector3 center; + computeCenter(center,in,element); + centers[e] = center; + } + + // Compute distances to get nearest element and corresponding bary coef + for ( unsigned int i=0; i0 ) + dist = ( outPos-centers[e] ).norm2(); + if ( dist +void BarycentricMapperTopologyContainer::applyJT ( typename In::MatrixDeriv& out, const typename Out::MatrixDeriv& in ) +{ + typename Out::MatrixDeriv::RowConstIterator rowItEnd = in.end(); + const helper::vector< Element >& elements = getElements(); + + for (typename Out::MatrixDeriv::RowConstIterator rowIt = in.begin(); rowIt != rowItEnd; ++rowIt) + { + typename Out::MatrixDeriv::ColConstIterator colItEnd = rowIt.end(); + typename Out::MatrixDeriv::ColConstIterator colIt = rowIt.begin(); + + if (colIt != colItEnd) + { + typename In::MatrixDeriv::RowIterator o = out.writeLine(rowIt.index()); + + for ( ; colIt != colItEnd; ++colIt) + { + unsigned indexIn = colIt.index(); + InDeriv data = (InDeriv) Out::getDPos(colIt.val()); + + const Element& element = elements[d_map.getValue()[indexIn].in_index]; + + helper::vector baryCoef = getBaryCoef(d_map.getValue()[indexIn].baryCoords); + for (unsigned int j=0; j +const sofa::defaulttype::BaseMatrix* BarycentricMapperTopologyContainer::getJ(int outSize, int inSize) +{ + if (m_matrixJ && !m_updateJ) + return m_matrixJ; + + if (!m_matrixJ) m_matrixJ = new MatrixType; + if (m_matrixJ->rowBSize() != (MatrixTypeIndex)outSize || m_matrixJ->colBSize() != (MatrixTypeIndex)inSize) + m_matrixJ->resize(outSize*NOut, inSize*NIn); + else + m_matrixJ->clear(); + + return m_matrixJ; + + const helper::vector& elements = getElements(); + + for( size_t outId=0 ; outIdmaskTo->size() ; ++outId) + { + if( !this->maskTo->getEntry(outId) ) continue; + + const Element& element = elements[d_map.getValue()[outId].in_index]; + + helper::vector baryCoef = getBaryCoef(d_map.getValue()[outId].baryCoords); + for (unsigned int j=0; jaddMatrixContrib(m_matrixJ, outId, element[j], baryCoef[j]); + } + + m_matrixJ->compress(); + m_updateJ = false; + return m_matrixJ; +} + + +template +void BarycentricMapperTopologyContainer::applyJT ( typename In::VecDeriv& out, const typename Out::VecDeriv& in ) +{ + const helper::vector& elements = getElements(); + + ForceMask& mask = *this->maskFrom; + for( size_t i=0 ; imaskTo->size() ; ++i) + { + if( !this->maskTo->getEntry(i) ) continue; + + int index = d_map.getValue()[i].in_index; + const Element& element = elements[index]; + + const typename Out::DPos inPos = Out::getDPos(in[i]); + helper::vector baryCoef = getBaryCoef(d_map.getValue()[i].baryCoords); + for (unsigned int j=0; j +void BarycentricMapperTopologyContainer::applyJ ( typename Out::VecDeriv& out, const typename In::VecDeriv& in ) +{ + out.resize( d_map.getValue().size() ); + + const helper::vector& elements = getElements(); + + for( size_t i=0 ; imaskTo->size() ; ++i) + { + if( this->maskTo->isActivated() && !this->maskTo->getEntry(i) ) continue; + + int index = d_map.getValue()[i].in_index; + const Element& element = elements[index]; + + helper::vector baryCoef = getBaryCoef(d_map.getValue()[i].baryCoords); + InDeriv inPos{0.,0.,0.}; + for (unsigned int j=0; j +void BarycentricMapperTopologyContainer::resize( core::State* toModel ) +{ + toModel->resize(d_map.getValue().size()); +} + +template +bool BarycentricMapperTopologyContainer::isEmpty() +{ + return d_map.getValue().empty(); +} + + + +template +void BarycentricMapperTopologyContainer::apply ( typename Out::VecCoord& out, const typename In::VecCoord& in ) +{ + out.resize( d_map.getValue().size() ); + + const helper::vector& elements = getElements(); + for ( unsigned int i=0; i baryCoef = getBaryCoef(d_map.getValue()[i].baryCoords); + InDeriv inPos{0.,0.,0.}; + for (unsigned int j=0; j +void BarycentricMapperTopologyContainer::draw (const core::visual::VisualParams* vparams, + const typename Out::VecCoord& out, + const typename In::VecCoord& in ) +{ + // Draw line between mapped node (out) and nodes of nearest element (in) + const helper::vector& elements = getElements(); + + std::vector< Vector3 > points; + { + for ( unsigned int i=0; i baryCoef = getBaryCoef(d_map.getValue()[i].baryCoords); + for ( unsigned int j=0; j=0.0001 ) + { + points.push_back ( Out::getCPos(out[i]) ); + points.push_back ( in[element[j]] ); + } + } + } + } + //vparams->drawTool()->drawLines ( points, 1, sofa::defaulttype::Vec<4,float> ( 0,1,0,1 ) ); +} + +}}}} + +#endif diff --git a/SofaKernel/modules/SofaBaseMechanics/BarycentricMappers/BarycentricMapperTriangleSetTopology.cpp b/SofaKernel/modules/SofaBaseMechanics/BarycentricMappers/BarycentricMapperTriangleSetTopology.cpp new file mode 100644 index 00000000000..0031548a727 --- /dev/null +++ b/SofaKernel/modules/SofaBaseMechanics/BarycentricMappers/BarycentricMapperTriangleSetTopology.cpp @@ -0,0 +1,53 @@ +/****************************************************************************** +* SOFA, Simulation Open-Framework Architecture, development version * +* (c) 2006-2018 INRIA, USTL, UJF, CNRS, MGH * +* * +* This program is free software; you can redistribute it and/or modify it * +* under the terms of the GNU Lesser General Public License as published by * +* the Free Software Foundation; either version 2.1 of the License, or (at * +* your option) any later version. * +* * +* This program is distributed in the hope that it will be useful, but WITHOUT * +* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * +* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License * +* for more details. * +* * +* You should have received a copy of the GNU Lesser General Public License * +* along with this program. If not, see . * +******************************************************************************* +* Authors: The SOFA Team and external contributors (see Authors.txt) * +* * +* Contact information: contact@sofa-framework.org * +******************************************************************************/ +#ifndef SOFA_COMPONENT_MAPPING_BARYCENTRICMAPPERTRIANGLESETTOPOLOGY_CPP +#define SOFA_COMPONENT_MAPPING_BARYCENTRICMAPPERTRIANGLESETTOPOLOGY_CPP +#include "BarycentricMapperTriangleSetTopology.inl" + +namespace sofa +{ + +namespace component +{ + +namespace mapping +{ + +using namespace sofa::defaulttype; + +#ifndef SOFA_FLOAT +template class SOFA_BASE_MECHANICS_API BarycentricMapperTriangleSetTopology< Vec3dTypes, Vec3dTypes >; +template class SOFA_BASE_MECHANICS_API BarycentricMapperTriangleSetTopology< Vec3dTypes, ExtVec3fTypes >; +#endif +#ifndef SOFA_DOUBLE +template class SOFA_BASE_MECHANICS_API BarycentricMapperTriangleSetTopology< Vec3fTypes, Vec3fTypes >; +template class SOFA_BASE_MECHANICS_API BarycentricMapperTriangleSetTopology< Vec3fTypes, ExtVec3fTypes >; +#endif +#ifndef SOFA_FLOAT +#ifndef SOFA_DOUBLE +template class SOFA_BASE_MECHANICS_API BarycentricMapperTriangleSetTopology< Vec3dTypes, Vec3fTypes >; +template class SOFA_BASE_MECHANICS_API BarycentricMapperTriangleSetTopology< Vec3fTypes, Vec3dTypes >; +#endif +#endif + +}}} +#endif diff --git a/SofaKernel/modules/SofaBaseMechanics/BarycentricMappers/BarycentricMapperTriangleSetTopology.h b/SofaKernel/modules/SofaBaseMechanics/BarycentricMappers/BarycentricMapperTriangleSetTopology.h new file mode 100644 index 00000000000..d5d34a82e11 --- /dev/null +++ b/SofaKernel/modules/SofaBaseMechanics/BarycentricMappers/BarycentricMapperTriangleSetTopology.h @@ -0,0 +1,115 @@ +/****************************************************************************** +* SOFA, Simulation Open-Framework Architecture, development version * +* (c) 2006-2018 INRIA, USTL, UJF, CNRS, MGH * +* * +* This program is free software; you can redistribute it and/or modify it * +* under the terms of the GNU Lesser General Public License as published by * +* the Free Software Foundation; either version 2.1 of the License, or (at * +* your option) any later version. * +* * +* This program is distributed in the hope that it will be useful, but WITHOUT * +* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * +* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License * +* for more details. * +* * +* You should have received a copy of the GNU Lesser General Public License * +* along with this program. If not, see . * +******************************************************************************* +* Authors: The SOFA Team and external contributors (see Authors.txt) * +* * +* Contact information: contact@sofa-framework.org * +******************************************************************************/ +#ifndef SOFA_COMPONENT_MAPPING_BARYCENTRICMAPPERTRIANGLESETTOPOLOGY_H +#define SOFA_COMPONENT_MAPPING_BARYCENTRICMAPPERTRIANGLESETTOPOLOGY_H +#include +#include +#include + +namespace sofa +{ + +namespace component +{ + +namespace mapping +{ + + +using sofa::defaulttype::Mat3x3d; +using sofa::defaulttype::Vector3; +typedef typename sofa::core::topology::BaseMeshTopology::Triangle Triangle; + + +/// Class allowing barycentric mapping computation on a TriangleSetTopology +template +class SOFA_BASE_MECHANICS_API BarycentricMapperTriangleSetTopology : public BarycentricMapperTopologyContainer::MappingData2D,Triangle> +{ + typedef typename BarycentricMapper::MappingData2D MappingData; +public: + SOFA_CLASS(SOFA_TEMPLATE2(BarycentricMapperTriangleSetTopology,In,Out),SOFA_TEMPLATE4(BarycentricMapperTopologyContainer,In,Out,MappingData,Triangle)); + typedef typename Inherit1::Real Real; + +protected: + topology::TriangleSetTopologyContainer* m_fromContainer; + topology::TriangleSetGeometryAlgorithms* m_fromGeomAlgo; + + using Inherit1::d_map; + using Inherit1::m_fromTopology; + using Inherit1::m_matrixJ; + using Inherit1::m_updateJ; + + BarycentricMapperTriangleSetTopology(topology::TriangleSetTopologyContainer* fromTopology, topology::PointSetTopologyContainer* toTopology) + : Inherit1(fromTopology, toTopology), + m_fromContainer(fromTopology), + m_fromGeomAlgo(NULL) + {} + + virtual ~BarycentricMapperTriangleSetTopology() {} + + + virtual helper::vector getElements() override; + virtual helper::vector getBaryCoef(const Real* f) override; + helper::vector getBaryCoef(const Real fx, const Real fy); + virtual void computeBase(Mat3x3d& base, const typename In::VecCoord& in, const Triangle& element) override; + virtual void computeCenter(Vector3& center, const typename In::VecCoord& in, const Triangle& element) override; + virtual void computeDistance(double& d, const Vector3& v) override; + virtual void addPointInElement(const int elementIndex, const SReal* baryCoords) override; + +public: + + virtual int addPointInTriangle(const int triangleIndex, const SReal* baryCoords) override; + int createPointInTriangle(const typename Out::Coord& p, int triangleIndex, const typename In::VecCoord* points) override; + +#ifdef BARYCENTRIC_MAPPER_TOPOCHANGE_REINIT + // handle topology changes in the From topology + virtual void handleTopologyChange(core::topology::Topology* t); +#endif // BARYCENTRIC_MAPPER_TOPOCHANGE_REINIT +}; + + +using sofa::defaulttype::Vec3dTypes; +using sofa::defaulttype::Vec3fTypes; +using sofa::defaulttype::ExtVec3fTypes; + + +#if defined(SOFA_EXTERN_TEMPLATE) && !defined(SOFA_COMPONENT_MAPPING_BARYCENTRICMAPPERTRIANGLESETTOPOLOGY_CPP) +#ifndef SOFA_FLOAT +extern template class SOFA_BASE_MECHANICS_API BarycentricMapperTriangleSetTopology< Vec3dTypes, Vec3dTypes >; +extern template class SOFA_BASE_MECHANICS_API BarycentricMapperTriangleSetTopology< Vec3dTypes, ExtVec3fTypes >; +#endif +#ifndef SOFA_DOUBLE +extern template class SOFA_BASE_MECHANICS_API BarycentricMapperTriangleSetTopology< Vec3fTypes, Vec3fTypes >; +extern template class SOFA_BASE_MECHANICS_API BarycentricMapperTriangleSetTopology< Vec3fTypes, ExtVec3fTypes >; +#endif +#ifndef SOFA_FLOAT +#ifndef SOFA_DOUBLE +extern template class SOFA_BASE_MECHANICS_API BarycentricMapperTriangleSetTopology< Vec3dTypes, Vec3fTypes >; +extern template class SOFA_BASE_MECHANICS_API BarycentricMapperTriangleSetTopology< Vec3fTypes, Vec3dTypes >; +#endif +#endif +#endif + +}}} + + +#endif diff --git a/SofaKernel/modules/SofaBaseMechanics/BarycentricMappers/BarycentricMapperTriangleSetTopology.inl b/SofaKernel/modules/SofaBaseMechanics/BarycentricMappers/BarycentricMapperTriangleSetTopology.inl new file mode 100644 index 00000000000..24aaf78b08c --- /dev/null +++ b/SofaKernel/modules/SofaBaseMechanics/BarycentricMappers/BarycentricMapperTriangleSetTopology.inl @@ -0,0 +1,120 @@ +/****************************************************************************** +* SOFA, Simulation Open-Framework Architecture, development version * +* (c) 2006-2018 INRIA, USTL, UJF, CNRS, MGH * +* * +* This program is free software; you can redistribute it and/or modify it * +* under the terms of the GNU Lesser General Public License as published by * +* the Free Software Foundation; either version 2.1 of the License, or (at * +* your option) any later version. * +* * +* This program is distributed in the hope that it will be useful, but WITHOUT * +* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * +* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License * +* for more details. * +* * +* You should have received a copy of the GNU Lesser General Public License * +* along with this program. If not, see . * +******************************************************************************* +* Authors: The SOFA Team and external contributors (see Authors.txt) * +* * +* Contact information: contact@sofa-framework.org * +******************************************************************************/ +#ifndef SOFA_COMPONENT_MAPPING_BARYCENTRICMAPPERTRIANGLESETTOPOLOGY_INL +#define SOFA_COMPONENT_MAPPING_BARYCENTRICMAPPERTRIANGLESETTOPOLOGY_INL + +#include "BarycentricMapperTriangleSetTopology.h" + +namespace sofa +{ + +namespace component +{ + +namespace mapping +{ + + +template +int BarycentricMapperTriangleSetTopology::addPointInTriangle ( const int triangleIndex, const SReal* baryCoords ) +{ + helper::vector& vectorData = *(d_map.beginEdit()); + vectorData.resize ( d_map.getValue().size() +1 ); + MappingData& data = *vectorData.rbegin(); + d_map.endEdit(); + data.in_index = triangleIndex; + data.baryCoords[0] = ( Real ) baryCoords[0]; + data.baryCoords[1] = ( Real ) baryCoords[1]; + return (int)d_map.getValue().size()-1; +} + +template +int BarycentricMapperTriangleSetTopology::createPointInTriangle ( const typename Out::Coord& p, int triangleIndex, const typename In::VecCoord* points ) +{ + SReal baryCoords[2]; + const Triangle& elem = this->m_fromTopology->getTriangle ( triangleIndex ); + const typename In::Coord p0 = ( *points ) [elem[0]]; + const typename In::Coord pA = ( *points ) [elem[1]] - p0; + const typename In::Coord pB = ( *points ) [elem[2]] - p0; + typename In::Coord pos = Out::getCPos(p) - p0; + // First project to plane + typename In::Coord normal = cross ( pA, pB ); + Real norm2 = normal.norm2(); + pos -= normal* ( ( pos*normal ) /norm2 ); + baryCoords[0] = ( Real ) sqrt ( cross ( pB, pos ).norm2() / norm2 ); + baryCoords[1] = ( Real ) sqrt ( cross ( pA, pos ).norm2() / norm2 ); + return this->addPointInTriangle ( triangleIndex, baryCoords ); +} + + +template +helper::vector BarycentricMapperTriangleSetTopology::getElements() +{ + return this->m_fromTopology->getTriangles(); +} + +template +helper::vector BarycentricMapperTriangleSetTopology::getBaryCoef(const Real* f) +{ + return getBaryCoef(f[0],f[1]); +} + +template +helper::vector BarycentricMapperTriangleSetTopology::getBaryCoef(const Real fx, const Real fy) +{ + helper::vector triangleCoef{1-fx-fy, fx, fy}; + return triangleCoef; +} + +template +void BarycentricMapperTriangleSetTopology::computeBase(Mat3x3d& base, const typename In::VecCoord& in, const Triangle& element) +{ + Mat3x3d mt; + base[0] = in[element[1]]-in[element[0]]; + base[1] = in[element[2]]-in[element[0]]; + base[2] = cross(base[0],base[1]); + mt.transpose(base); + base.invert(mt); +} + +template +void BarycentricMapperTriangleSetTopology::computeCenter(Vector3& center, const typename In::VecCoord& in, const Triangle& element) +{ + center = (in[element[0]]+in[element[1]]+in[element[2]])/3; +} + +template +void BarycentricMapperTriangleSetTopology::computeDistance(double& d, const Vector3& v) +{ + d = std::max ( std::max ( -v[0],-v[1] ),std::max ( ( v[2]<0?-v[2]:v[2] )-0.01,v[0]+v[1]-1 ) ); +} + +template +void BarycentricMapperTriangleSetTopology::addPointInElement(const int elementIndex, const SReal* baryCoords) +{ + addPointInTriangle(elementIndex,baryCoords); +} + +}}} + + +#endif diff --git a/SofaKernel/modules/SofaBaseMechanics/BarycentricMappers/TopologyBarycentricMapper.cpp b/SofaKernel/modules/SofaBaseMechanics/BarycentricMappers/TopologyBarycentricMapper.cpp new file mode 100644 index 00000000000..95b5b0643df --- /dev/null +++ b/SofaKernel/modules/SofaBaseMechanics/BarycentricMappers/TopologyBarycentricMapper.cpp @@ -0,0 +1,62 @@ +/****************************************************************************** +* SOFA, Simulation Open-Framework Architecture, development version * +* (c) 2006-2018 INRIA, USTL, UJF, CNRS, MGH * +* * +* This program is free software; you can redistribute it and/or modify it * +* under the terms of the GNU Lesser General Public License as published by * +* the Free Software Foundation; either version 2.1 of the License, or (at * +* your option) any later version. * +* * +* This program is distributed in the hope that it will be useful, but WITHOUT * +* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * +* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License * +* for more details. * +* * +* You should have received a copy of the GNU Lesser General Public License * +* along with this program. If not, see . * +******************************************************************************* +* Authors: The SOFA Team and external contributors (see Authors.txt) * +* * +* Contact information: contact@sofa-framework.org * +******************************************************************************/ +#define SOFA_COMPONENT_MAPPING_TOPOLOGYBARYCENTRICMAPPER_CPP +#include "TopologyBarycentricMapper.inl" + +namespace sofa +{ + +namespace component +{ + +namespace mapping +{ + +namespace _topologybarycentricmapper_ +{ + +using namespace sofa::defaulttype; + + +#ifndef SOFA_FLOAT +template class SOFA_BASE_MECHANICS_API TopologyBarycentricMapper< Vec3dTypes, Vec3dTypes >; +template class SOFA_BASE_MECHANICS_API TopologyBarycentricMapper< Vec3dTypes, ExtVec3fTypes >; +#endif +#ifndef SOFA_DOUBLE +template class SOFA_BASE_MECHANICS_API TopologyBarycentricMapper< Vec3fTypes, Vec3fTypes >; +template class SOFA_BASE_MECHANICS_API TopologyBarycentricMapper< Vec3fTypes, ExtVec3fTypes >; +#endif +#ifndef SOFA_FLOAT +#ifndef SOFA_DOUBLE +template class SOFA_BASE_MECHANICS_API TopologyBarycentricMapper< Vec3dTypes, Vec3fTypes >; +template class SOFA_BASE_MECHANICS_API TopologyBarycentricMapper< Vec3fTypes, Vec3dTypes >; +#endif +#endif + +} + +} // namespace mapping + +} // namespace component + +} // namespace sofa + diff --git a/SofaKernel/modules/SofaBaseMechanics/BarycentricMappers/TopologyBarycentricMapper.h b/SofaKernel/modules/SofaBaseMechanics/BarycentricMappers/TopologyBarycentricMapper.h new file mode 100644 index 00000000000..4e5ebaf2759 --- /dev/null +++ b/SofaKernel/modules/SofaBaseMechanics/BarycentricMappers/TopologyBarycentricMapper.h @@ -0,0 +1,126 @@ +/****************************************************************************** +* SOFA, Simulation Open-Framework Architecture, development version * +* (c) 2006-2018 INRIA, USTL, UJF, CNRS, MGH * +* * +* This program is free software; you can redistribute it and/or modify it * +* under the terms of the GNU Lesser General Public License as published by * +* the Free Software Foundation; either version 2.1 of the License, or (at * +* your option) any later version. * +* * +* This program is distributed in the hope that it will be useful, but WITHOUT * +* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * +* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License * +* for more details. * +* * +* You should have received a copy of the GNU Lesser General Public License * +* along with this program. If not, see . * +******************************************************************************* +* Authors: The SOFA Team and external contributors (see Authors.txt) * +* * +* Contact information: contact@sofa-framework.org * +******************************************************************************/ +#ifndef SOFA_COMPONENT_MAPPING_TOPOLOGYBARYCENTRICMAPPER_H +#define SOFA_COMPONENT_MAPPING_TOPOLOGYBARYCENTRICMAPPER_H +#include +#include + +namespace sofa +{ + +namespace component +{ + +namespace mapping +{ + +namespace _topologybarycentricmapper_ +{ + +/// Template class for barycentric mapping topology-specific mappers. +template +class SOFA_BASE_MECHANICS_API TopologyBarycentricMapper : public BarycentricMapper +{ + +public: + + SOFA_CLASS(SOFA_TEMPLATE2(TopologyBarycentricMapper,In,Out),SOFA_TEMPLATE2(BarycentricMapper,In,Out)); + + typedef typename Inherit1::Real Real; + typedef typename core::behavior::BaseMechanicalState::ForceMask ForceMask; + + ForceMask *maskFrom; + ForceMask *maskTo; + +public: + + virtual int addPointInLine(const int lineIndex, const SReal* baryCoords); + virtual int setPointInLine(const int pointIndex, const int lineIndex, const SReal* baryCoords); + virtual int createPointInLine(const typename Out::Coord& p, int lineIndex, const typename In::VecCoord* points); + + virtual int addPointInTriangle(const int triangleIndex, const SReal* baryCoords); + virtual int setPointInTriangle(const int pointIndex, const int triangleIndex, const SReal* baryCoords); + virtual int createPointInTriangle(const typename Out::Coord& p, int triangleIndex, const typename In::VecCoord* points); + + virtual int addPointInQuad(const int quadIndex, const SReal* baryCoords); + virtual int setPointInQuad(const int pointIndex, const int quadIndex, const SReal* baryCoords); + virtual int createPointInQuad(const typename Out::Coord& p, int quadIndex, const typename In::VecCoord* points); + + virtual int addPointInTetra(const int tetraIndex, const SReal* baryCoords); + virtual int setPointInTetra(const int pointIndex, const int tetraIndex, const SReal* baryCoords); + virtual int createPointInTetra(const typename Out::Coord& p, int tetraIndex, const typename In::VecCoord* points); + + virtual int addPointInCube(const int cubeIndex, const SReal* baryCoords); + virtual int setPointInCube(const int pointIndex, const int cubeIndex, const SReal* baryCoords); + virtual int createPointInCube(const typename Out::Coord& p, int cubeIndex, const typename In::VecCoord* points); + + virtual void setToTopology( topology::PointSetTopologyContainer* toTopology) {this->toTopology = toTopology;} + const topology::PointSetTopologyContainer *getToTopology() const {return toTopology;} + + virtual void updateForceMask(){/*mask is already filled in the mapper's applyJT*/} + + virtual void resize( core::State* toModel ) = 0; + +protected: + TopologyBarycentricMapper(core::topology::BaseMeshTopology* fromTopology, topology::PointSetTopologyContainer* toTopology = nullptr) + : m_fromTopology(fromTopology) + , toTopology(toTopology) + {} + + virtual ~TopologyBarycentricMapper() override {} + +protected: + core::topology::BaseMeshTopology* m_fromTopology; + topology::PointSetTopologyContainer* toTopology; + +}; + +using sofa::defaulttype::Vec3dTypes; +using sofa::defaulttype::Vec3fTypes; +using sofa::defaulttype::ExtVec3fTypes; + + +#if defined(SOFA_EXTERN_TEMPLATE) && !defined(SOFA_COMPONENT_MAPPING_TOPOLOGYBARYCENTRICMAPPER_CPP) +#ifndef SOFA_FLOAT +extern template class SOFA_BASE_MECHANICS_API TopologyBarycentricMapper< Vec3dTypes, Vec3dTypes >; +extern template class SOFA_BASE_MECHANICS_API TopologyBarycentricMapper< Vec3dTypes, ExtVec3fTypes >; +#endif +#ifndef SOFA_DOUBLE +extern template class SOFA_BASE_MECHANICS_API TopologyBarycentricMapper< Vec3fTypes, Vec3fTypes >; +extern template class SOFA_BASE_MECHANICS_API TopologyBarycentricMapper< Vec3fTypes, ExtVec3fTypes >; +#endif +#ifndef SOFA_FLOAT +#ifndef SOFA_DOUBLE +extern template class SOFA_BASE_MECHANICS_API TopologyBarycentricMapper< Vec3dTypes, Vec3fTypes >; +extern template class SOFA_BASE_MECHANICS_API TopologyBarycentricMapper< Vec3fTypes, Vec3dTypes >; +#endif +#endif +#endif + +} + +using _topologybarycentricmapper_::TopologyBarycentricMapper; + +}}} + + +#endif diff --git a/SofaKernel/modules/SofaBaseMechanics/BarycentricMappers/TopologyBarycentricMapper.inl b/SofaKernel/modules/SofaBaseMechanics/BarycentricMappers/TopologyBarycentricMapper.inl new file mode 100644 index 00000000000..fdd2878cbb1 --- /dev/null +++ b/SofaKernel/modules/SofaBaseMechanics/BarycentricMappers/TopologyBarycentricMapper.inl @@ -0,0 +1,164 @@ +/****************************************************************************** +* SOFA, Simulation Open-Framework Architecture, development version * +* (c) 2006-2018 INRIA, USTL, UJF, CNRS, MGH * +* * +* This program is free software; you can redistribute it and/or modify it * +* under the terms of the GNU Lesser General Public License as published by * +* the Free Software Foundation; either version 2.1 of the License, or (at * +* your option) any later version. * +* * +* This program is distributed in the hope that it will be useful, but WITHOUT * +* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * +* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License * +* for more details. * +* * +* You should have received a copy of the GNU Lesser General Public License * +* along with this program. If not, see . * +******************************************************************************* +* Authors: The SOFA Team and external contributors (see Authors.txt) * +* * +* Contact information: contact@sofa-framework.org * +******************************************************************************/ +#ifndef SOFA_COMPONENT_MAPPING_TOPOLOGYBARYCENTRICMAPPER_INL +#define SOFA_COMPONENT_MAPPING_TOPOLOGYBARYCENTRICMAPPER_INL + +#include "TopologyBarycentricMapper.h" + +namespace sofa +{ + +namespace component +{ + +namespace mapping +{ + +namespace _topologybarycentricmapper_ +{ + +template +int TopologyBarycentricMapper::addPointInLine(const int lineIndex, const SReal* baryCoords) +{ + SOFA_UNUSED(lineIndex); + SOFA_UNUSED(baryCoords); + return 0; +} + +template +int TopologyBarycentricMapper::setPointInLine(const int pointIndex, const int lineIndex, const SReal* baryCoords) +{ + SOFA_UNUSED(pointIndex); + SOFA_UNUSED(lineIndex); + SOFA_UNUSED(baryCoords); + return 0; +} + +template +int TopologyBarycentricMapper::createPointInLine(const typename Out::Coord& p, int lineIndex, const typename In::VecCoord* points) +{ + SOFA_UNUSED(p); + SOFA_UNUSED(lineIndex); + SOFA_UNUSED(points); + return 0; +} + +template +int TopologyBarycentricMapper::addPointInTriangle(const int triangleIndex, const SReal* baryCoords) +{ + SOFA_UNUSED(triangleIndex); + SOFA_UNUSED(baryCoords); + return 0; +} +template +int TopologyBarycentricMapper::setPointInTriangle(const int pointIndex, const int triangleIndex, const SReal* baryCoords) +{ + SOFA_UNUSED(pointIndex); + SOFA_UNUSED(triangleIndex); + SOFA_UNUSED(baryCoords); + return 0; +} +template +int TopologyBarycentricMapper::createPointInTriangle(const typename Out::Coord& p, int triangleIndex, const typename In::VecCoord* points) +{ + SOFA_UNUSED(p); + SOFA_UNUSED(triangleIndex); + SOFA_UNUSED(points); + return 0; +} + +template +int TopologyBarycentricMapper::addPointInQuad(const int quadIndex, const SReal* baryCoords) +{ + SOFA_UNUSED(quadIndex); + SOFA_UNUSED(baryCoords); + return 0; +} +template +int TopologyBarycentricMapper::setPointInQuad(const int pointIndex, const int quadIndex, const SReal* baryCoords) +{ + SOFA_UNUSED(pointIndex); + SOFA_UNUSED(quadIndex); + SOFA_UNUSED(baryCoords); + return 0; +} +template +int TopologyBarycentricMapper::createPointInQuad(const typename Out::Coord& p, int quadIndex, const typename In::VecCoord* points) +{ + SOFA_UNUSED(p); + SOFA_UNUSED(quadIndex); + SOFA_UNUSED(points); + return 0; +} + +template +int TopologyBarycentricMapper::addPointInTetra(const int tetraIndex, const SReal* baryCoords) +{ + SOFA_UNUSED(tetraIndex); + SOFA_UNUSED(baryCoords); + return 0; +} +template +int TopologyBarycentricMapper::setPointInTetra(const int pointIndex, const int tetraIndex, const SReal* baryCoords) +{ + SOFA_UNUSED(pointIndex); + SOFA_UNUSED(tetraIndex); + SOFA_UNUSED(baryCoords); + return 0; +} +template +int TopologyBarycentricMapper::createPointInTetra(const typename Out::Coord& p, int tetraIndex, const typename In::VecCoord* points) +{ + SOFA_UNUSED(p); + SOFA_UNUSED(tetraIndex); + SOFA_UNUSED(points); + return 0; +} + +template +int TopologyBarycentricMapper::addPointInCube(const int cubeIndex, const SReal* baryCoords) +{ + SOFA_UNUSED(cubeIndex); + SOFA_UNUSED(baryCoords); + return 0; +} +template +int TopologyBarycentricMapper::setPointInCube(const int pointIndex, const int cubeIndex, const SReal* baryCoords) +{ + SOFA_UNUSED(pointIndex); + SOFA_UNUSED(cubeIndex); + SOFA_UNUSED(baryCoords); + return 0; +} +template +int TopologyBarycentricMapper::createPointInCube(const typename Out::Coord& p, int cubeIndex, const typename In::VecCoord* points) +{ + SOFA_UNUSED(p); + SOFA_UNUSED(cubeIndex); + SOFA_UNUSED(points); + return 0; +} + +}}}} + + +#endif diff --git a/SofaKernel/modules/SofaBaseMechanics/BarycentricMapping.cpp b/SofaKernel/modules/SofaBaseMechanics/BarycentricMapping.cpp index 7d1527fcdf6..242e614e4b2 100644 --- a/SofaKernel/modules/SofaBaseMechanics/BarycentricMapping.cpp +++ b/SofaKernel/modules/SofaBaseMechanics/BarycentricMapping.cpp @@ -23,7 +23,6 @@ #include #include - #include namespace sofa @@ -60,105 +59,15 @@ int BarycentricMappingClass = core::RegisterObject("Mapping using barycentric co #ifndef SOFA_FLOAT template class SOFA_BASE_MECHANICS_API BarycentricMapping< Vec3dTypes, Vec3dTypes >; template class SOFA_BASE_MECHANICS_API BarycentricMapping< Vec3dTypes, ExtVec3fTypes >; -template class SOFA_BASE_MECHANICS_API BarycentricMapper< Vec3dTypes, Vec3dTypes >; -template class SOFA_BASE_MECHANICS_API BarycentricMapper< Vec3dTypes, ExtVec3fTypes >; -template class SOFA_BASE_MECHANICS_API TopologyBarycentricMapper< Vec3dTypes, Vec3dTypes >; -template class SOFA_BASE_MECHANICS_API TopologyBarycentricMapper< Vec3dTypes, ExtVec3fTypes >; -template class SOFA_BASE_MECHANICS_API BarycentricMapperRegularGridTopology< Vec3dTypes, Vec3dTypes >; -template class SOFA_BASE_MECHANICS_API BarycentricMapperRegularGridTopology< Vec3dTypes, ExtVec3fTypes >; -template class SOFA_BASE_MECHANICS_API BarycentricMapperSparseGridTopology< Vec3dTypes, Vec3dTypes >; -template class SOFA_BASE_MECHANICS_API BarycentricMapperSparseGridTopology< Vec3dTypes, ExtVec3fTypes >; -template class SOFA_BASE_MECHANICS_API BarycentricMapperMeshTopology< Vec3dTypes, Vec3dTypes >; -template class SOFA_BASE_MECHANICS_API BarycentricMapperMeshTopology< Vec3dTypes, ExtVec3fTypes >; -template class SOFA_BASE_MECHANICS_API BarycentricMapperTopologyContainer< Vec3dTypes, Vec3dTypes , typename BarycentricMapper::MappingData1D, Edge>; -template class SOFA_BASE_MECHANICS_API BarycentricMapperTopologyContainer< Vec3dTypes, ExtVec3fTypes , typename BarycentricMapper::MappingData1D, Edge>; -template class SOFA_BASE_MECHANICS_API BarycentricMapperTopologyContainer< Vec3dTypes, Vec3dTypes , typename BarycentricMapper::MappingData2D, Triangle>; -template class SOFA_BASE_MECHANICS_API BarycentricMapperTopologyContainer< Vec3dTypes, ExtVec3fTypes , typename BarycentricMapper::MappingData2D, Triangle>; -template class SOFA_BASE_MECHANICS_API BarycentricMapperTopologyContainer< Vec3dTypes, Vec3dTypes , typename BarycentricMapper::MappingData2D, Quad>; -template class SOFA_BASE_MECHANICS_API BarycentricMapperTopologyContainer< Vec3dTypes, ExtVec3fTypes , typename BarycentricMapper::MappingData2D, Quad>; -template class SOFA_BASE_MECHANICS_API BarycentricMapperTopologyContainer< Vec3dTypes, Vec3dTypes , typename BarycentricMapper::MappingData3D, Tetrahedron>; -template class SOFA_BASE_MECHANICS_API BarycentricMapperTopologyContainer< Vec3dTypes, ExtVec3fTypes , typename BarycentricMapper::MappingData3D, Tetrahedron>; -template class SOFA_BASE_MECHANICS_API BarycentricMapperTopologyContainer< Vec3dTypes, Vec3dTypes , typename BarycentricMapper::MappingData3D, Hexahedron>; -template class SOFA_BASE_MECHANICS_API BarycentricMapperTopologyContainer< Vec3dTypes, ExtVec3fTypes , typename BarycentricMapper::MappingData3D, Hexahedron>; -template class SOFA_BASE_MECHANICS_API BarycentricMapperEdgeSetTopology< Vec3dTypes, Vec3dTypes>; -template class SOFA_BASE_MECHANICS_API BarycentricMapperEdgeSetTopology< Vec3dTypes, ExtVec3fTypes>; -template class SOFA_BASE_MECHANICS_API BarycentricMapperTriangleSetTopology< Vec3dTypes, Vec3dTypes >; -template class SOFA_BASE_MECHANICS_API BarycentricMapperTriangleSetTopology< Vec3dTypes, ExtVec3fTypes >; -template class SOFA_BASE_MECHANICS_API BarycentricMapperQuadSetTopology< Vec3dTypes, Vec3dTypes >; -template class SOFA_BASE_MECHANICS_API BarycentricMapperQuadSetTopology< Vec3dTypes, ExtVec3fTypes >; -template class SOFA_BASE_MECHANICS_API BarycentricMapperTetrahedronSetTopology< Vec3dTypes, Vec3dTypes >; -template class SOFA_BASE_MECHANICS_API BarycentricMapperTetrahedronSetTopology< Vec3dTypes, ExtVec3fTypes >; -template class SOFA_BASE_MECHANICS_API BarycentricMapperHexahedronSetTopology< Vec3dTypes, Vec3dTypes >; -template class SOFA_BASE_MECHANICS_API BarycentricMapperHexahedronSetTopology< Vec3dTypes, ExtVec3fTypes >; #endif #ifndef SOFA_DOUBLE template class SOFA_BASE_MECHANICS_API BarycentricMapping< Vec3fTypes, Vec3fTypes >; template class SOFA_BASE_MECHANICS_API BarycentricMapping< Vec3fTypes, ExtVec3fTypes >; -template class SOFA_BASE_MECHANICS_API BarycentricMapper< Vec3fTypes, Vec3fTypes >; -template class SOFA_BASE_MECHANICS_API BarycentricMapper< Vec3fTypes, ExtVec3fTypes >; -template class SOFA_BASE_MECHANICS_API TopologyBarycentricMapper< Vec3fTypes, Vec3fTypes >; -template class SOFA_BASE_MECHANICS_API TopologyBarycentricMapper< Vec3fTypes, ExtVec3fTypes >; -template class SOFA_BASE_MECHANICS_API BarycentricMapperRegularGridTopology< Vec3fTypes, Vec3fTypes >; -template class SOFA_BASE_MECHANICS_API BarycentricMapperRegularGridTopology< Vec3fTypes, ExtVec3fTypes >; -template class SOFA_BASE_MECHANICS_API BarycentricMapperSparseGridTopology< Vec3fTypes, Vec3fTypes >; -template class SOFA_BASE_MECHANICS_API BarycentricMapperSparseGridTopology< Vec3fTypes, ExtVec3fTypes >; -template class SOFA_BASE_MECHANICS_API BarycentricMapperMeshTopology< Vec3fTypes, Vec3fTypes >; -template class SOFA_BASE_MECHANICS_API BarycentricMapperMeshTopology< Vec3fTypes, ExtVec3fTypes >; -template class SOFA_BASE_MECHANICS_API BarycentricMapperTopologyContainer< Vec3fTypes, Vec3fTypes , typename BarycentricMapper::MappingData1D, Edge>; -template class SOFA_BASE_MECHANICS_API BarycentricMapperTopologyContainer< Vec3fTypes, ExtVec3fTypes , typename BarycentricMapper::MappingData1D, Edge>; -template class SOFA_BASE_MECHANICS_API BarycentricMapperTopologyContainer< Vec3fTypes, Vec3fTypes , typename BarycentricMapper::MappingData2D, Triangle>; -template class SOFA_BASE_MECHANICS_API BarycentricMapperTopologyContainer< Vec3fTypes, ExtVec3fTypes , typename BarycentricMapper::MappingData2D, Triangle>; -template class SOFA_BASE_MECHANICS_API BarycentricMapperTopologyContainer< Vec3fTypes, Vec3fTypes , typename BarycentricMapper::MappingData2D, Quad>; -template class SOFA_BASE_MECHANICS_API BarycentricMapperTopologyContainer< Vec3fTypes, ExtVec3fTypes , typename BarycentricMapper::MappingData2D, Quad>; -template class SOFA_BASE_MECHANICS_API BarycentricMapperTopologyContainer< Vec3fTypes, Vec3fTypes , typename BarycentricMapper::MappingData3D, Tetrahedron>; -template class SOFA_BASE_MECHANICS_API BarycentricMapperTopologyContainer< Vec3fTypes, ExtVec3fTypes , typename BarycentricMapper::MappingData3D, Tetrahedron>; -template class SOFA_BASE_MECHANICS_API BarycentricMapperTopologyContainer< Vec3fTypes, Vec3fTypes , typename BarycentricMapper::MappingData3D, Hexahedron>; -template class SOFA_BASE_MECHANICS_API BarycentricMapperTopologyContainer< Vec3fTypes, ExtVec3fTypes , typename BarycentricMapper::MappingData3D, Hexahedron>; -template class SOFA_BASE_MECHANICS_API BarycentricMapperEdgeSetTopology< Vec3fTypes, Vec3fTypes>; -template class SOFA_BASE_MECHANICS_API BarycentricMapperEdgeSetTopology< Vec3fTypes, ExtVec3fTypes>; -template class SOFA_BASE_MECHANICS_API BarycentricMapperTriangleSetTopology< Vec3fTypes, Vec3fTypes >; -template class SOFA_BASE_MECHANICS_API BarycentricMapperTriangleSetTopology< Vec3fTypes, ExtVec3fTypes >; -template class SOFA_BASE_MECHANICS_API BarycentricMapperQuadSetTopology< Vec3fTypes, Vec3fTypes >; -template class SOFA_BASE_MECHANICS_API BarycentricMapperQuadSetTopology< Vec3fTypes, ExtVec3fTypes >; -template class SOFA_BASE_MECHANICS_API BarycentricMapperTetrahedronSetTopology< Vec3fTypes, Vec3fTypes >; -template class SOFA_BASE_MECHANICS_API BarycentricMapperTetrahedronSetTopology< Vec3fTypes, ExtVec3fTypes >; -template class SOFA_BASE_MECHANICS_API BarycentricMapperHexahedronSetTopology< Vec3fTypes, Vec3fTypes >; -template class SOFA_BASE_MECHANICS_API BarycentricMapperHexahedronSetTopology< Vec3fTypes, ExtVec3fTypes >; #endif #ifndef SOFA_FLOAT #ifndef SOFA_DOUBLE template class SOFA_BASE_MECHANICS_API BarycentricMapping< Vec3dTypes, Vec3fTypes >; template class SOFA_BASE_MECHANICS_API BarycentricMapping< Vec3fTypes, Vec3dTypes >; -template class SOFA_BASE_MECHANICS_API BarycentricMapper< Vec3dTypes, Vec3fTypes >; -template class SOFA_BASE_MECHANICS_API BarycentricMapper< Vec3fTypes, Vec3dTypes >; -template class SOFA_BASE_MECHANICS_API TopologyBarycentricMapper< Vec3dTypes, Vec3fTypes >; -template class SOFA_BASE_MECHANICS_API TopologyBarycentricMapper< Vec3fTypes, Vec3dTypes >; -template class SOFA_BASE_MECHANICS_API BarycentricMapperRegularGridTopology< Vec3dTypes, Vec3fTypes >; -template class SOFA_BASE_MECHANICS_API BarycentricMapperRegularGridTopology< Vec3fTypes, Vec3dTypes >; -template class SOFA_BASE_MECHANICS_API BarycentricMapperSparseGridTopology< Vec3dTypes, Vec3fTypes >; -template class SOFA_BASE_MECHANICS_API BarycentricMapperSparseGridTopology< Vec3fTypes, Vec3dTypes >; -template class SOFA_BASE_MECHANICS_API BarycentricMapperMeshTopology< Vec3dTypes, Vec3fTypes >; -template class SOFA_BASE_MECHANICS_API BarycentricMapperMeshTopology< Vec3fTypes, Vec3dTypes >; -template class SOFA_BASE_MECHANICS_API BarycentricMapperTopologyContainer< Vec3dTypes, Vec3fTypes , typename BarycentricMapper::MappingData1D,Edge>; -template class SOFA_BASE_MECHANICS_API BarycentricMapperTopologyContainer< Vec3fTypes, Vec3dTypes , typename BarycentricMapper::MappingData1D,Edge>; -template class SOFA_BASE_MECHANICS_API BarycentricMapperTopologyContainer< Vec3dTypes, Vec3fTypes , typename BarycentricMapper::MappingData2D,Triangle>; -template class SOFA_BASE_MECHANICS_API BarycentricMapperTopologyContainer< Vec3fTypes, Vec3dTypes , typename BarycentricMapper::MappingData2D,Triangle>; -template class SOFA_BASE_MECHANICS_API BarycentricMapperTopologyContainer< Vec3dTypes, Vec3fTypes , typename BarycentricMapper::MappingData2D,Quad>; -template class SOFA_BASE_MECHANICS_API BarycentricMapperTopologyContainer< Vec3fTypes, Vec3dTypes , typename BarycentricMapper::MappingData2D,Quad>; -template class SOFA_BASE_MECHANICS_API BarycentricMapperTopologyContainer< Vec3dTypes, Vec3fTypes , typename BarycentricMapper::MappingData3D,Tetrahedron>; -template class SOFA_BASE_MECHANICS_API BarycentricMapperTopologyContainer< Vec3fTypes, Vec3dTypes , typename BarycentricMapper::MappingData3D,Tetrahedron>; -template class SOFA_BASE_MECHANICS_API BarycentricMapperTopologyContainer< Vec3dTypes, Vec3fTypes , typename BarycentricMapper::MappingData3D,Hexahedron>; -template class SOFA_BASE_MECHANICS_API BarycentricMapperTopologyContainer< Vec3fTypes, Vec3dTypes , typename BarycentricMapper::MappingData3D,Hexahedron>; -template class SOFA_BASE_MECHANICS_API BarycentricMapperEdgeSetTopology< Vec3dTypes, Vec3fTypes>; -template class SOFA_BASE_MECHANICS_API BarycentricMapperEdgeSetTopology< Vec3fTypes, Vec3dTypes>; -template class SOFA_BASE_MECHANICS_API BarycentricMapperTriangleSetTopology< Vec3dTypes, Vec3fTypes >; -template class SOFA_BASE_MECHANICS_API BarycentricMapperTriangleSetTopology< Vec3fTypes, Vec3dTypes >; -template class SOFA_BASE_MECHANICS_API BarycentricMapperQuadSetTopology< Vec3dTypes, Vec3fTypes >; -template class SOFA_BASE_MECHANICS_API BarycentricMapperQuadSetTopology< Vec3fTypes, Vec3dTypes >; -template class SOFA_BASE_MECHANICS_API BarycentricMapperTetrahedronSetTopology< Vec3dTypes, Vec3fTypes >; -template class SOFA_BASE_MECHANICS_API BarycentricMapperTetrahedronSetTopology< Vec3fTypes, Vec3dTypes >; -template class SOFA_BASE_MECHANICS_API BarycentricMapperHexahedronSetTopology< Vec3dTypes, Vec3fTypes >; -template class SOFA_BASE_MECHANICS_API BarycentricMapperHexahedronSetTopology< Vec3fTypes, Vec3dTypes >; #endif #endif diff --git a/SofaKernel/modules/SofaBaseMechanics/BarycentricMapping.h b/SofaKernel/modules/SofaBaseMechanics/BarycentricMapping.h index 09ac6b87187..dce44bc480f 100644 --- a/SofaKernel/modules/SofaBaseMechanics/BarycentricMapping.h +++ b/SofaKernel/modules/SofaBaseMechanics/BarycentricMapping.h @@ -23,10 +23,6 @@ #define SOFA_COMPONENT_MAPPING_BARYCENTRICMAPPING_H #include "config.h" -#include -#include -#include - #include #include @@ -35,57 +31,13 @@ #include #include -#include #include #include #include -// forward declarations -namespace sofa -{ -namespace core -{ -namespace topology -{ -class BaseMeshTopology; -} -} - -namespace component -{ -namespace topology -{ -class MeshTopology; -class RegularGridTopology; -class SparseGridTopology; - -class PointSetTopologyContainer; -template -class PointSetGeometryAlgorithms; - -class EdgeSetTopologyContainer; -template -class EdgeSetGeometryAlgorithms; - -class TriangleSetTopologyContainer; -template -class TriangleSetGeometryAlgorithms; - -class QuadSetTopologyContainer; -template -class QuadSetGeometryAlgorithms; - -class TetrahedronSetTopologyContainer; -template -class TetrahedronSetGeometryAlgorithms; +#include -class HexahedronSetTopologyContainer; -template -class HexahedronSetGeometryAlgorithms; -} -} -} namespace sofa { @@ -96,990 +48,13 @@ namespace component namespace mapping { -/// Base class for barycentric mapping topology-specific mappers -template -class BarycentricMapper : public virtual core::objectmodel::BaseObject -{ -public: - SOFA_CLASS(SOFA_TEMPLATE2(BarycentricMapper,In,Out),core::objectmodel::BaseObject); - - typedef typename In::Real Real; - typedef typename In::Real InReal; - typedef typename Out::Real OutReal; - - typedef typename In::VecDeriv InVecDeriv; - typedef typename In::Deriv InDeriv; - - typedef typename Out::VecDeriv OutVecDeriv; - typedef typename Out::Deriv OutDeriv; - - enum { NIn = sofa::defaulttype::DataTypeInfo::Size }; - enum { NOut = sofa::defaulttype::DataTypeInfo::Size }; - typedef defaulttype::Mat MBloc; - typedef sofa::component::linearsolver::CompressedRowSparseMatrix MatrixType; - -protected: - - void addMatrixContrib(MatrixType* m, int row, int col, Real value) - { - MBloc* b = m->wbloc(row, col, true); // get write access to a matrix bloc, creating it if not found - for (int i=0; i < ((int)NIn < (int)NOut ? (int)NIn : (int)NOut); ++i) - (*b)[i][i] += value; - } - - template< int NC, int NP> - class MappingData - { - public: - int in_index; - Real baryCoords[NC]; - - inline friend std::istream& operator >> ( std::istream& in, MappingData< NC, NP> &m ) - { - in>>m.in_index; - for (int i=0; i> m.baryCoords[i]; - return in; - } - - inline friend std::ostream& operator << ( std::ostream& out, const MappingData< NC , NP > & m ) - { - out << m.in_index; - for (int i=0; i LineData; - typedef MappingData<2,3> TriangleData; - typedef MappingData<2,4> QuadData; - typedef MappingData<3,4> TetraData; - typedef MappingData<3,8> CubeData; - typedef MappingData<1,0> MappingData1D; - typedef MappingData<2,0> MappingData2D; - typedef MappingData<3,0> MappingData3D; - -protected: - BarycentricMapper() {} - virtual ~BarycentricMapper() override {} - -private: - BarycentricMapper(const BarycentricMapper& n) ; - BarycentricMapper& operator=(const BarycentricMapper& n) ; - -public: - using core::objectmodel::BaseObject::init; - virtual void init(const typename Out::VecCoord& out, const typename In::VecCoord& in) = 0; - virtual void apply( typename Out::VecCoord& out, const typename In::VecCoord& in ) = 0; - virtual const sofa::defaulttype::BaseMatrix* getJ(int /*outSize*/, int /*inSize*/) - { - dmsg_error() << " getJ() NOT IMPLEMENTED BY " << sofa::core::objectmodel::BaseClass::decodeClassName(typeid(*this)) ; - return NULL; - } - virtual void applyJ( typename Out::VecDeriv& out, const typename In::VecDeriv& in ) = 0; - virtual void applyJT( typename In::VecDeriv& out, const typename Out::VecDeriv& in ) = 0; - virtual void applyJT( typename In::MatrixDeriv& out, const typename Out::MatrixDeriv& in ) = 0; - - using core::objectmodel::BaseObject::draw; - virtual void draw(const core::visual::VisualParams*, const typename Out::VecCoord& out, const typename In::VecCoord& in) = 0; - - //-- test mapping partiel - virtual void applyOnePoint( const unsigned int& /*hexaId*/, typename Out::VecCoord& /*out*/, const typename In::VecCoord& /*in*/) - {} - //-- - - - virtual void clear( int reserve=0 ) =0; - - //Nothing to do - inline friend std::istream& operator >> ( std::istream& in, BarycentricMapper< In, Out > & ) {return in;} - inline friend std::ostream& operator << ( std::ostream& out, const BarycentricMapper< In, Out > & ) { return out; } -}; - - - -/// Template class for barycentric mapping topology-specific mappers. -template -class TopologyBarycentricMapper : public BarycentricMapper -{ -public: - SOFA_CLASS(SOFA_TEMPLATE2(TopologyBarycentricMapper,In,Out),SOFA_TEMPLATE2(BarycentricMapper,In,Out)); - - typedef typename Inherit1::Real Real; - typedef typename core::behavior::BaseMechanicalState::ForceMask ForceMask; - - ForceMask *maskFrom; - ForceMask *maskTo; - -protected: - virtual ~TopologyBarycentricMapper() override {} -public: - - virtual int addPointInLine(const int /*lineIndex*/, const SReal* /*baryCoords*/) {return 0;} - virtual int setPointInLine(const int /*pointIndex*/, const int /*lineIndex*/, const SReal* /*baryCoords*/) {return 0;} - virtual int createPointInLine(const typename Out::Coord& /*p*/, int /*lineIndex*/, const typename In::VecCoord* /*points*/) {return 0;} - - virtual int addPointInTriangle(const int /*triangleIndex*/, const SReal* /*baryCoords*/) {return 0;} - virtual int setPointInTriangle(const int /*pointIndex*/, const int /*triangleIndex*/, const SReal* /*baryCoords*/) {return 0;} - virtual int createPointInTriangle(const typename Out::Coord& /*p*/, int /*triangleIndex*/, const typename In::VecCoord* /*points*/) {return 0;} - - virtual int addPointInQuad(const int /*quadIndex*/, const SReal* /*baryCoords*/) {return 0;} - virtual int setPointInQuad(const int /*pointIndex*/, const int /*quadIndex*/, const SReal* /*baryCoords*/) {return 0;} - virtual int createPointInQuad(const typename Out::Coord& /*p*/, int /*quadIndex*/, const typename In::VecCoord* /*points*/) {return 0;} - - virtual int addPointInTetra(const int /*tetraIndex*/, const SReal* /*baryCoords*/) {return 0;} - virtual int setPointInTetra(const int /*pointIndex*/, const int /*tetraIndex*/, const SReal* /*baryCoords*/) {return 0;} - virtual int createPointInTetra(const typename Out::Coord& /*p*/, int /*tetraIndex*/, const typename In::VecCoord* /*points*/) {return 0;} - - virtual int addPointInCube(const int /*cubeIndex*/, const SReal* /*baryCoords*/) {return 0;} - virtual int setPointInCube(const int /*pointIndex*/, const int /*cubeIndex*/, const SReal* /*baryCoords*/) {return 0;} - virtual int createPointInCube(const typename Out::Coord& /*p*/, int /*cubeIndex*/, const typename In::VecCoord* /*points*/) {return 0;} - - virtual void setToTopology( topology::PointSetTopologyContainer* toTopology) {this->toTopology = toTopology;} - const topology::PointSetTopologyContainer *getToTopology() const {return toTopology;} - - virtual void updateForceMask(){/*mask is already filled in the mapper's applyJT*/} - - virtual void resize( core::State* toModel ) = 0; - -protected: - core::topology::BaseMeshTopology* m_fromTopology; - topology::PointSetTopologyContainer* toTopology; - - TopologyBarycentricMapper(core::topology::BaseMeshTopology* fromTopology, topology::PointSetTopologyContainer* toTopology = NULL) - : m_fromTopology(fromTopology) - , toTopology(toTopology) - {} - -}; - - - -/// Class allowing barycentric mapping computation on a MeshTopology -template -class BarycentricMapperMeshTopology : public TopologyBarycentricMapper -{ -public: - SOFA_CLASS(SOFA_TEMPLATE2(BarycentricMapperMeshTopology,In,Out),SOFA_TEMPLATE2(TopologyBarycentricMapper,In,Out)); - - typedef typename Inherit1::Real Real; - typedef typename Inherit1::OutReal OutReal; - typedef typename Inherit1::OutDeriv OutDeriv; - - typedef typename Inherit1::InDeriv InDeriv; - typedef typename Inherit1::MappingData1D MappingData1D; - typedef typename Inherit1::MappingData2D MappingData2D; - typedef typename Inherit1::MappingData3D MappingData3D; - - enum { NIn = Inherit1::NIn }; - enum { NOut = Inherit1::NOut }; - typedef typename Inherit1::MBloc MBloc; - typedef typename Inherit1::MatrixType MatrixType; - typedef typename MatrixType::Index MatrixTypeIndex; - - typedef typename Inherit1::ForceMask ForceMask; - -protected: - void addMatrixContrib(MatrixType* m, int row, int col, Real value) - { - Inherit1::addMatrixContrib(m, row, col, value); - } - - sofa::helper::vector< MappingData1D > m_map1d; - sofa::helper::vector< MappingData2D > m_map2d; - sofa::helper::vector< MappingData3D > m_map3d; - - MatrixType* m_matrixJ; - bool m_updateJ; - - BarycentricMapperMeshTopology(core::topology::BaseMeshTopology* fromTopology, - topology::PointSetTopologyContainer* toTopology) - : TopologyBarycentricMapper(fromTopology, toTopology), - m_matrixJ(NULL), m_updateJ(true) - { - } - - virtual ~BarycentricMapperMeshTopology() override - { - if (m_matrixJ) delete m_matrixJ; - } -public: - - virtual void clear(int reserve=0) override; - - virtual int addPointInLine(const int lineIndex, const SReal* baryCoords) override; - virtual int createPointInLine(const typename Out::Coord& p, int lineIndex, const typename In::VecCoord* points) override; - - virtual int addPointInTriangle(const int triangleIndex, const SReal* baryCoords) override; - virtual int createPointInTriangle(const typename Out::Coord& p, int triangleIndex, const typename In::VecCoord* points) override; - - virtual int addPointInQuad(const int quadIndex, const SReal* baryCoords) override; - virtual int createPointInQuad(const typename Out::Coord& p, int quadIndex, const typename In::VecCoord* points) override; - - virtual int addPointInTetra(const int tetraIndex, const SReal* baryCoords) override; - - virtual int addPointInCube(const int cubeIndex, const SReal* baryCoords) override; - - virtual void init(const typename Out::VecCoord& out, const typename In::VecCoord& in) override; - - virtual void apply( typename Out::VecCoord& out, const typename In::VecCoord& in ) override; - virtual void applyJ( typename Out::VecDeriv& out, const typename In::VecDeriv& in ) override; - virtual void applyJT( typename In::VecDeriv& out, const typename Out::VecDeriv& in ) override; - virtual void applyJT( typename In::MatrixDeriv& out, const typename Out::MatrixDeriv& in ) override; - virtual const sofa::defaulttype::BaseMatrix* getJ(int outSize, int inSize) override; - virtual void draw(const core::visual::VisualParams*,const typename Out::VecCoord& out, const typename In::VecCoord& in) override; - virtual void resize( core::State* toModel ) override; - - sofa::helper::vector< MappingData3D > const* getMap3d() const { return &m_map3d; } - - inline friend std::istream& operator >> ( std::istream& in, BarycentricMapperMeshTopology &b ) - { - unsigned int size_vec; - in >> size_vec; - b.m_map1d.clear(); - MappingData1D value1d; - for (unsigned int i=0; i> value1d; - b.m_map1d.push_back(value1d); - } - - in >> size_vec; - b.m_map2d.clear(); - MappingData2D value2d; - for (unsigned int i=0; i> value2d; - b.m_map2d.push_back(value2d); - } - - in >> size_vec; - b.m_map3d.clear(); - MappingData3D value3d; - for (unsigned int i=0; i> value3d; - b.m_map3d.push_back(value3d); - } - return in; - } - - inline friend std::ostream& operator << ( std::ostream& out, const BarycentricMapperMeshTopology & b ) - { - - out << b.m_map1d.size(); - out << " " ; - out << b.m_map1d; - out << " " ; - out << b.m_map2d.size(); - out << " " ; - out << b.m_map2d; - out << " " ; - out << b.m_map3d.size(); - out << " " ; - out << b.m_map3d; - - return out; - } - -private: - void clearMap1dAndReserve(int size=0); - void clearMap2dAndReserve(int size=0); - void clearMap3dAndReserve(int size=0); - -}; - - - -/// Class allowing barycentric mapping computation on a RegularGridTopology -template -class BarycentricMapperRegularGridTopology : public TopologyBarycentricMapper -{ -public: - SOFA_CLASS(SOFA_TEMPLATE2(BarycentricMapperRegularGridTopology,In,Out),SOFA_TEMPLATE2(TopologyBarycentricMapper,In,Out)); - typedef typename Inherit1::Real Real; - typedef typename Inherit1::OutReal OutReal; - typedef typename Inherit1::OutDeriv OutDeriv; - typedef typename Inherit1::InDeriv InDeriv; - typedef typename Inherit1::CubeData CubeData; - - enum { NIn = Inherit1::NIn }; - enum { NOut = Inherit1::NOut }; - typedef typename Inherit1::MBloc MBloc; - typedef typename Inherit1::MatrixType MatrixType; - typedef typename MatrixType::Index MatrixTypeIndex; - - typedef typename Inherit1::ForceMask ForceMask; - -protected: - void addMatrixContrib(MatrixType* m, int row, int col, Real value) - { - Inherit1::addMatrixContrib(m, row, col, value); - } - - sofa::helper::vector m_map; - topology::RegularGridTopology* m_fromTopology; - - MatrixType* matrixJ; - bool updateJ; - - BarycentricMapperRegularGridTopology(topology::RegularGridTopology* fromTopology, - topology::PointSetTopologyContainer* toTopology) - : Inherit1(fromTopology, toTopology),m_fromTopology(fromTopology), - matrixJ(NULL), updateJ(true) - { - } - - virtual ~BarycentricMapperRegularGridTopology() override - { - if (matrixJ) delete matrixJ; - } -public: - - virtual void clear(int reserve=0) override; - - bool isEmpty() {return this->m_map.size() == 0;} - void setTopology(topology::RegularGridTopology* _topology) {this->m_fromTopology = _topology;} - topology::RegularGridTopology *getTopology() {return dynamic_cast(this->m_fromTopology);} - - virtual int addPointInCube(const int cubeIndex, const SReal* baryCoords) override; - - virtual void init(const typename Out::VecCoord& out, const typename In::VecCoord& in) override; - virtual void apply( typename Out::VecCoord& out, const typename In::VecCoord& in ) override; - virtual void applyJ( typename Out::VecDeriv& out, const typename In::VecDeriv& in ) override; - virtual void applyJT( typename In::VecDeriv& out, const typename Out::VecDeriv& in ) override; - virtual void applyJT( typename In::MatrixDeriv& out, const typename Out::MatrixDeriv& in ) override; - virtual const sofa::defaulttype::BaseMatrix* getJ(int outSize, int inSize) override; - virtual void draw(const core::visual::VisualParams*,const typename Out::VecCoord& out, const typename In::VecCoord& in) override; - virtual void resize( core::State* toModel ) override; - - inline friend std::istream& operator >> ( std::istream& in, BarycentricMapperRegularGridTopology &b ) - { - in >> b.m_map; - return in; - } - - inline friend std::ostream& operator << ( std::ostream& out, const BarycentricMapperRegularGridTopology & b ) - { - out << b.m_map; - return out; - } - -}; - - - -/// Class allowing barycentric mapping computation on a SparseGridTopology -template -class BarycentricMapperSparseGridTopology : public TopologyBarycentricMapper -{ -public: - SOFA_CLASS(SOFA_TEMPLATE2(BarycentricMapperSparseGridTopology,In,Out),SOFA_TEMPLATE2(TopologyBarycentricMapper,In,Out)); - typedef typename Inherit1::Real Real; - typedef typename Inherit1::OutReal OutReal; - typedef typename Inherit1::OutDeriv OutDeriv; - typedef typename Inherit1::InDeriv InDeriv; - - typedef typename Inherit1::CubeData CubeData; - - enum { NIn = Inherit1::NIn }; - enum { NOut = Inherit1::NOut }; - typedef typename Inherit1::MBloc MBloc; - typedef typename Inherit1::MatrixType MatrixType; - typedef typename MatrixType::Index MatrixTypeIndex; - - typedef typename Inherit1::ForceMask ForceMask; - -protected: - void addMatrixContrib(MatrixType* m, int row, int col, Real value) - { - Inherit1::addMatrixContrib(m, row, col, value); - } - - sofa::helper::vector m_map; - topology::SparseGridTopology* m_fromTopology; - - MatrixType* matrixJ; - bool updateJ; - - BarycentricMapperSparseGridTopology(topology::SparseGridTopology* fromTopology, - topology::PointSetTopologyContainer* _toTopology) - : TopologyBarycentricMapper(fromTopology, _toTopology), - m_fromTopology(fromTopology), - matrixJ(NULL), updateJ(true) - { - } - - virtual ~BarycentricMapperSparseGridTopology() override - { - if (matrixJ) delete matrixJ; - } -public: - - void clear(int reserve=0) override; - - int addPointInCube(const int cubeIndex, const SReal* baryCoords) override; - - void init(const typename Out::VecCoord& out, const typename In::VecCoord& in) override; - - void apply( typename Out::VecCoord& out, const typename In::VecCoord& in ) override; - void applyJ( typename Out::VecDeriv& out, const typename In::VecDeriv& in ) override; - void applyJT( typename In::VecDeriv& out, const typename Out::VecDeriv& in ) override; - void applyJT( typename In::MatrixDeriv& out, const typename Out::MatrixDeriv& in ) override; - const sofa::defaulttype::BaseMatrix* getJ(int outSize, int inSize) override; - void draw(const core::visual::VisualParams*,const typename Out::VecCoord& out, const typename In::VecCoord& in) override; - virtual void resize( core::State* toModel ) override; - - inline friend std::istream& operator >> ( std::istream& in, BarycentricMapperSparseGridTopology &b ) - { - in >> b.m_map; - return in; - } - - inline friend std::ostream& operator << ( std::ostream& out, const BarycentricMapperSparseGridTopology & b ) - { - out << b.m_map; - return out; - } - -}; - - - - - - -typedef typename sofa::core::topology::BaseMeshTopology::Edge Edge; -typedef typename sofa::core::topology::BaseMeshTopology::Triangle Triangle; -typedef typename sofa::core::topology::BaseMeshTopology::Quad Quad; -typedef typename sofa::core::topology::BaseMeshTopology::Tetrahedron Tetrahedron; -typedef typename sofa::core::topology::BaseMeshTopology::Hexahedron Hexahedron; -using sofa::defaulttype::Mat3x3d; -using sofa::defaulttype::Vector3; - - -/// Template class for topology container mappers -template -class BarycentricMapperTopologyContainer : public TopologyBarycentricMapper -{ -public: - SOFA_CLASS(SOFA_TEMPLATE4(BarycentricMapperTopologyContainer,In,Out,MappingDataType,Element),SOFA_TEMPLATE2(TopologyBarycentricMapper,In,Out)); - typedef typename Inherit1::Real Real; - typedef typename Inherit1::OutReal OutReal; - typedef typename Inherit1::OutDeriv OutDeriv; - typedef typename Inherit1::InDeriv InDeriv; - - typedef typename Inherit1::MBloc MBloc; - typedef typename Inherit1::MatrixType MatrixType; - - typedef typename Inherit1::ForceMask ForceMask; - typedef typename MatrixType::Index MatrixTypeIndex; - enum { NIn = Inherit1::NIn }; - enum { NOut = Inherit1::NOut }; - -protected: - topology::PointData< helper::vector > d_map; - MatrixType* m_matrixJ; - bool m_updateJ; - - BarycentricMapperTopologyContainer(core::topology::BaseMeshTopology* fromTopology, topology::PointSetTopologyContainer* toTopology) - : Inherit1(fromTopology, toTopology), - d_map(initData(&d_map,"map", "mapper data")), - m_matrixJ(NULL), - m_updateJ(true) - {} - - virtual ~BarycentricMapperTopologyContainer() override {} - -protected: - - virtual helper::vector getElements()=0; - virtual helper::vector getBaryCoef(const Real* f)=0; - virtual void computeBase(Mat3x3d& base, const typename In::VecCoord& in, const Element& element)=0; - virtual void computeCenter(Vector3& center, const typename In::VecCoord& in, const Element& element)=0; - virtual void addPointInElement(const int elementIndex, const SReal* baryCoords)=0; - virtual void computeDistance(double& d, const Vector3& v)=0; - -public: - - virtual void clear(int size=0) override; - virtual void resize( core::State* toModel ) override; - - virtual void apply( typename Out::VecCoord& out, const typename In::VecCoord& in ) override; - virtual void applyJ( typename Out::VecDeriv& out, const typename In::VecDeriv& in ) override; - virtual void applyJT( typename In::VecDeriv& out, const typename Out::VecDeriv& in ) override; - virtual void applyJT( typename In::MatrixDeriv& out, const typename Out::MatrixDeriv& in ) override; - virtual const sofa::defaulttype::BaseMatrix* getJ(int outSize, int inSize) override; - virtual void init(const typename Out::VecCoord& out, const typename In::VecCoord& in) override; - virtual void draw(const core::visual::VisualParams*,const typename Out::VecCoord& out, const typename In::VecCoord& in) override; - - inline friend std::istream& operator >> ( std::istream& in, BarycentricMapperTopologyContainer &b ) - { - unsigned int size_vec; - - in >> size_vec; - sofa::helper::vector& m = *(b.d_map.beginEdit()); - m.clear(); - - MappingDataType value; - for (unsigned int i=0; i> value; - m.push_back(value); - } - b.d_map.endEdit(); - return in; - } - - inline friend std::ostream& operator << ( std::ostream& out, const BarycentricMapperTopologyContainer & b ) - { - - out << b.d_map.getValue().size(); - out << " " ; - out << b.d_map; - - return out; - } - - bool isEmpty() - { - return d_map.getValue().empty(); - } - -}; - - - -/////// Class allowing barycentric mapping computation on a EdgeSetTopology -template -class BarycentricMapperEdgeSetTopology : public BarycentricMapperTopologyContainer::MappingData1D,Edge> -{ - typedef typename BarycentricMapper::MappingData1D MappingData; -public: - SOFA_CLASS(SOFA_TEMPLATE2(BarycentricMapperEdgeSetTopology,In,Out),SOFA_TEMPLATE4(BarycentricMapperTopologyContainer,In,Out,MappingData,Edge)); - typedef typename Inherit1::Real Real; - -protected: - topology::EdgeSetTopologyContainer* m_fromContainer; - topology::EdgeSetGeometryAlgorithms* m_fromGeomAlgo; - - using Inherit1::d_map; - using Inherit1::m_fromTopology; - using Inherit1::m_matrixJ; - using Inherit1::m_updateJ; - - BarycentricMapperEdgeSetTopology(topology::EdgeSetTopologyContainer* fromTopology, topology::PointSetTopologyContainer* toTopology) - : Inherit1(fromTopology, toTopology), - m_fromContainer(fromTopology), - m_fromGeomAlgo(NULL) - {} - - virtual ~BarycentricMapperEdgeSetTopology() override {} - - virtual helper::vector getElements() override - { - return this->m_fromTopology->getEdges(); - } - - virtual helper::vector getBaryCoef(const Real* f) override - { - return getBaryCoef(f[0]); - } - - helper::vector getBaryCoef(const Real fx) - { - helper::vector edgeCoef{1-fx,fx}; - return edgeCoef; - } - - virtual void computeBase(Mat3x3d& base, const typename In::VecCoord& in, const Edge& element) override - { - //Not implemented for Edge - SOFA_UNUSED(base); - SOFA_UNUSED(in); - SOFA_UNUSED(element); - } - - virtual void computeCenter(Vector3& center, const typename In::VecCoord& in, const Edge& element) override - { - center = (in[element[0]]+in[element[1]])*0.5; - } - - virtual void computeDistance(double& d, const Vector3& v) override - { - //Not implemented for Edge - SOFA_UNUSED(d); - SOFA_UNUSED(v); - } - - virtual void addPointInElement(const int elementIndex, const SReal* baryCoords) override - { - addPointInLine(elementIndex,baryCoords); - } - -public: - - virtual void init(const typename Out::VecCoord& out, const typename In::VecCoord& in) override - { - SOFA_UNUSED(out); - SOFA_UNUSED(in); - msg_warning() << "Mapping not implemented for edge elements."; - } - virtual int addPointInLine(const int edgeIndex, const SReal* baryCoords) override; - virtual int createPointInLine(const typename Out::Coord& p, int edgeIndex, const typename In::VecCoord* points) override; -}; - - - -/// Class allowing barycentric mapping computation on a TriangleSetTopology -template -class BarycentricMapperTriangleSetTopology : public BarycentricMapperTopologyContainer::MappingData2D,Triangle> -{ - typedef typename BarycentricMapper::MappingData2D MappingData; -public: - SOFA_CLASS(SOFA_TEMPLATE2(BarycentricMapperTriangleSetTopology,In,Out),SOFA_TEMPLATE4(BarycentricMapperTopologyContainer,In,Out,MappingData,Triangle)); - typedef typename Inherit1::Real Real; - -protected: - topology::TriangleSetTopologyContainer* m_fromContainer; - topology::TriangleSetGeometryAlgorithms* m_fromGeomAlgo; - - using Inherit1::d_map; - using Inherit1::m_fromTopology; - using Inherit1::m_matrixJ; - using Inherit1::m_updateJ; - - BarycentricMapperTriangleSetTopology(topology::TriangleSetTopologyContainer* fromTopology, topology::PointSetTopologyContainer* toTopology) - : Inherit1(fromTopology, toTopology), - m_fromContainer(fromTopology), - m_fromGeomAlgo(NULL) - {} - - virtual ~BarycentricMapperTriangleSetTopology() override {} - - - virtual helper::vector getElements() override - { - return this->m_fromTopology->getTriangles(); - } - - virtual helper::vector getBaryCoef(const Real* f) override - { - return getBaryCoef(f[0],f[1]); - } - - helper::vector getBaryCoef(const Real fx, const Real fy) - { - helper::vector triangleCoef{1-fx-fy, fx, fy}; - return triangleCoef; - } - - virtual void computeBase(Mat3x3d& base, const typename In::VecCoord& in, const Triangle& element) override - { - Mat3x3d mt; - base[0] = in[element[1]]-in[element[0]]; - base[1] = in[element[2]]-in[element[0]]; - base[2] = cross(base[0],base[1]); - mt.transpose(base); - base.invert(mt); - } - - virtual void computeCenter(Vector3& center, const typename In::VecCoord& in, const Triangle& element) override - { - center = (in[element[0]]+in[element[1]]+in[element[2]])/3; - } - - virtual void computeDistance(double& d, const Vector3& v) override - { - d = std::max ( std::max ( -v[0],-v[1] ),std::max ( ( v[2]<0?-v[2]:v[2] )-0.01,v[0]+v[1]-1 ) ); - } - - virtual void addPointInElement(const int elementIndex, const SReal* baryCoords) override - { - addPointInTriangle(elementIndex,baryCoords); - } - -public: - - virtual int addPointInTriangle(const int triangleIndex, const SReal* baryCoords) override; - int createPointInTriangle(const typename Out::Coord& p, int triangleIndex, const typename In::VecCoord* points) override; - -#ifdef BARYCENTRIC_MAPPER_TOPOCHANGE_REINIT - // handle topology changes in the From topology - virtual void handleTopologyChange(core::topology::Topology* t); -#endif // BARYCENTRIC_MAPPER_TOPOCHANGE_REINIT -}; - - - -/// Class allowing barycentric mapping computation on a QuadSetTopology -template -class BarycentricMapperQuadSetTopology : public BarycentricMapperTopologyContainer::MappingData2D, Quad> -{ - typedef typename BarycentricMapper::MappingData2D MappingData; -public: - SOFA_CLASS(SOFA_TEMPLATE2(BarycentricMapperQuadSetTopology,In,Out),SOFA_TEMPLATE4(BarycentricMapperTopologyContainer,In,Out,MappingData,Quad)); - typedef typename Inherit1::Real Real; - -protected: - topology::QuadSetTopologyContainer* m_fromContainer; - topology::QuadSetGeometryAlgorithms* m_fromGeomAlgo; - - using Inherit1::d_map; - using Inherit1::m_fromTopology; - using Inherit1::m_matrixJ; - using Inherit1::m_updateJ; - - BarycentricMapperQuadSetTopology(topology::QuadSetTopologyContainer* fromTopology, topology::PointSetTopologyContainer* toTopology) - : Inherit1(fromTopology, toTopology), - m_fromContainer(fromTopology), - m_fromGeomAlgo(NULL) - {} - - virtual ~BarycentricMapperQuadSetTopology() override {} - - - virtual helper::vector getElements() override - { - return this->m_fromTopology->getQuads(); - } - - virtual helper::vector getBaryCoef(const Real* f) override - { - return getBaryCoef(f[0],f[1]); - } - - helper::vector getBaryCoef(const Real fx, const Real fy) - { - helper::vector quadCoef{(1-fx)*(1-fy), - (fx)*(1-fy), - (1-fx)*(fy), - (fx)*(fy)}; - return quadCoef; - } - - virtual void computeBase(Mat3x3d& base, const typename In::VecCoord& in, const Quad& element) override - { - Mat3x3d matrixTranspose; - base[0] = in[element[1]]-in[element[0]]; - base[1] = in[element[3]]-in[element[0]]; - base[2] = cross(base[0],base[1]); - matrixTranspose.transpose(base); - base.invert(matrixTranspose); - } - - virtual void computeCenter(Vector3& center, const typename In::VecCoord& in, const Quad& element) override - { - center = ( in[element[0]]+in[element[1]]+in[element[2]]+in[element[3]] ) *0.25; - } - - virtual void computeDistance(double& d, const Vector3& v) override - { - d = std::max ( std::max ( -v[0],-v[1] ),std::max ( std::max ( v[1]-1,v[0]-1 ),std::max ( v[2]-0.01,-v[2]-0.01 ) ) ); - } - - virtual void addPointInElement(const int elementIndex, const SReal* baryCoords) override - { - addPointInQuad(elementIndex,baryCoords); - } - -public: - - virtual int addPointInQuad(const int index, const SReal* baryCoords) override; - virtual int createPointInQuad(const typename Out::Coord& p, int index, const typename In::VecCoord* points) override; -}; - - - -/// Class allowing barycentric mapping computation on a TetrahedronSetTopology -template -class BarycentricMapperTetrahedronSetTopology : public BarycentricMapperTopologyContainer::MappingData3D,Tetrahedron> -{ - typedef typename BarycentricMapper::MappingData3D MappingData; -public: - SOFA_CLASS(SOFA_TEMPLATE2(BarycentricMapperTetrahedronSetTopology,In,Out),SOFA_TEMPLATE4(BarycentricMapperTopologyContainer,In,Out,MappingData,Tetrahedron)); - typedef typename Inherit1::Real Real; - typedef typename In::VecCoord VecCoord; - - -protected: - - topology::TetrahedronSetTopologyContainer* m_fromContainer; - topology::TetrahedronSetGeometryAlgorithms* m_fromGeomAlgo; - - using Inherit1::d_map; - using Inherit1::m_fromTopology; - using Inherit1::m_matrixJ; - using Inherit1::m_updateJ; - - BarycentricMapperTetrahedronSetTopology(topology::TetrahedronSetTopologyContainer* fromTopology, topology::PointSetTopologyContainer* toTopology) - : Inherit1(fromTopology, toTopology), - m_fromContainer(fromTopology), - m_fromGeomAlgo(NULL) - {} - - virtual ~BarycentricMapperTetrahedronSetTopology() override {} - - - virtual helper::vector getElements() override - { - return this->m_fromTopology->getTetrahedra(); - } - - virtual helper::vector getBaryCoef(const Real* f) override - { - return getBaryCoef(f[0],f[1],f[2]); - } - - helper::vector getBaryCoef(const Real fx, const Real fy, const Real fz) - { - helper::vector tetrahedronCoef{(1-fx-fy-fz),fx,fy,fz}; - return tetrahedronCoef; - } - - virtual void computeBase(Mat3x3d& base, const typename In::VecCoord& in, const Tetrahedron& element) override - { - Mat3x3d matrixTranspose; - base[0] = in[element[1]]-in[element[0]]; - base[1] = in[element[2]]-in[element[0]]; - base[2] = in[element[3]]-in[element[0]]; - matrixTranspose.transpose(base); - base.invert(matrixTranspose); - } - - virtual void computeCenter(Vector3& center, const typename In::VecCoord& in, const Tetrahedron& element) override - { - center = ( in[element[0]]+in[element[1]]+in[element[2]]+in[element[3]] ) *0.25; - } - - virtual void computeDistance(double& d, const Vector3& v) override - { - d = std::max ( std::max ( -v[0],-v[1] ), std::max ( -v[2],v[0]+v[1]+v[2]-1 ) ); - } - - virtual void addPointInElement(const int elementIndex, const SReal* baryCoords) override - { - addPointInTetra(elementIndex,baryCoords); - } - -public: - - virtual int addPointInTetra(const int index, const SReal* baryCoords) override ; -}; - - - -/// Class allowing barycentric mapping computation on a HexahedronSetTopology -template -class BarycentricMapperHexahedronSetTopology : public BarycentricMapperTopologyContainer::MappingData3D,Hexahedron> -{ - typedef typename BarycentricMapper::MappingData3D MappingData; - -public: - SOFA_CLASS(SOFA_TEMPLATE2(BarycentricMapperHexahedronSetTopology,In,Out),SOFA_TEMPLATE4(BarycentricMapperTopologyContainer,In,Out,MappingData,Hexahedron)); - typedef typename Inherit1::Real Real; - -protected: - topology::HexahedronSetTopologyContainer* m_fromContainer; - topology::HexahedronSetGeometryAlgorithms* m_fromGeomAlgo; - std::set m_invalidIndex; - - using Inherit1::d_map; - using Inherit1::m_matrixJ; - using Inherit1::m_updateJ; - using Inherit1::m_fromTopology; - - BarycentricMapperHexahedronSetTopology() - : Inherit1(NULL, NULL), - m_fromContainer(NULL), - m_fromGeomAlgo(NULL) - {} - - BarycentricMapperHexahedronSetTopology(topology::HexahedronSetTopologyContainer* fromTopology, topology::PointSetTopologyContainer* toTopology) - : Inherit1(fromTopology, toTopology), - m_fromContainer(fromTopology), - m_fromGeomAlgo(NULL) - {} - - virtual ~BarycentricMapperHexahedronSetTopology() override {} - - - virtual helper::vector getElements() override - { - return this->m_fromTopology->getHexahedra(); - } - - virtual helper::vector getBaryCoef(const Real* f) override - { - return getBaryCoef(f[0],f[1],f[2]); - } - - helper::vector getBaryCoef(const Real fx, const Real fy, const Real fz) - { - helper::vector hexahedronCoef{(1-fx)*(1-fy)*(1-fz), - (fx)*(1-fy)*(1-fz), - (1-fx)*(fy)*(1-fz), - (fx)*(fy)*(1-fz), - (1-fx)*(1-fy)*(fz), - (fx)*(1-fy)*(fz), - (1-fx)*(fy)*(fz), - (fx)*(fy)*(fz)}; - return hexahedronCoef; - } - - virtual void computeBase(Mat3x3d& base, const typename In::VecCoord& in, const Hexahedron& element) override - { - Mat3x3d matrixTranspose; - base[0] = in[element[1]]-in[element[0]]; - base[1] = in[element[3]]-in[element[0]]; - base[2] = in[element[4]]-in[element[0]]; - matrixTranspose.transpose(base); - base.invert(matrixTranspose); - } - - virtual void computeCenter(Vector3& center, const typename In::VecCoord& in, const Hexahedron& element) override - { - center = ( in[element[0]]+in[element[1]]+in[element[2]]+in[element[3]]+in[element[4]]+in[element[5]]+in[element[6]]+in[element[7]] ) *0.125; - } - - virtual void computeDistance(double& d, const Vector3& v) override - { - d = std::max ( std::max ( -v[0],-v[1] ),std::max ( std::max ( -v[2],v[0]-1 ),std::max ( v[1]-1,v[2]-1 ) ) ); - } - - virtual void addPointInElement(const int elementIndex, const SReal* baryCoords) override - { - addPointInCube(elementIndex,baryCoords); - } - -public: - - virtual int addPointInCube(const int index, const SReal* baryCoords) override; - virtual int setPointInCube(const int pointIndex, const int cubeIndex, const SReal* baryCoords) override; - //-- test mapping partiel - virtual void applyOnePoint( const unsigned int& hexaId, typename Out::VecCoord& out, const typename In::VecCoord& in) override; - //-- - // handle topology changes in the From topology - virtual void handleTopologyChange(core::topology::Topology* t) override; - - void setTopology(topology::HexahedronSetTopologyContainer* topology) - { - m_fromTopology = topology; - m_fromContainer = topology; - } -}; - - - template class BarycentricMapping : public core::Mapping { public: SOFA_CLASS(SOFA_TEMPLATE2(BarycentricMapping,TIn,TOut), SOFA_TEMPLATE2(core::Mapping,TIn,TOut)); + typedef core::Mapping Inherit; typedef TIn In; typedef TOut Out; typedef In InDataTypes; @@ -1097,7 +72,7 @@ class BarycentricMapping : public core::Mapping typedef core::topology::BaseMeshTopology BaseMeshTopology; typedef TopologyBarycentricMapper Mapper; - typedef typename Inherit1::ForceMask ForceMask; + typedef typename Inherit::ForceMask ForceMask; protected: @@ -1111,35 +86,34 @@ class BarycentricMapping : public core::Mapping //--- partial mapping test Data< bool > sleeping; ///< is the mapping sleeping (not computed) #endif + protected: + BarycentricMapping(); BarycentricMapping(core::State* from, core::State* to, typename Mapper::SPtr m_mapper); - BarycentricMapping(core::State* from, core::State* to, BaseMeshTopology * topology=NULL ); + BarycentricMapping(core::State* from, core::State* to, BaseMeshTopology * topology=nullptr ); - virtual ~BarycentricMapping() override ; + virtual ~BarycentricMapping() override; public: - void init() override; - - void reinit() override; - - void apply(const core::MechanicalParams *mparams, Data< typename Out::VecCoord >& out, const Data< typename In::VecCoord >& in) override; - - void applyJ(const core::MechanicalParams *mparams, Data< typename Out::VecDeriv >& out, const Data< typename In::VecDeriv >& in) override; - - void applyJT(const core::MechanicalParams *mparams, Data< typename In::VecDeriv >& out, const Data< typename Out::VecDeriv >& in) override; - - void applyJT(const core::ConstraintParams *cparams, Data< typename In::MatrixDeriv >& out, const Data< typename Out::MatrixDeriv >& in) override; + virtual void init() override; + virtual void reinit() override; + virtual void apply(const core::MechanicalParams *mparams, Data< typename Out::VecCoord >& out, const Data< typename In::VecCoord >& in) override; + virtual void applyJ(const core::MechanicalParams *mparams, Data< typename Out::VecDeriv >& out, const Data< typename In::VecDeriv >& in) override; + virtual void applyJT(const core::MechanicalParams *mparams, Data< typename In::VecDeriv >& out, const Data< typename Out::VecDeriv >& in) override; + virtual void applyJT(const core::ConstraintParams *cparams, Data< typename In::MatrixDeriv >& out, const Data< typename Out::MatrixDeriv >& in) override; virtual const sofa::defaulttype::BaseMatrix* getJ() override; public: + virtual const helper::vector* getJs() override; protected: + typedef linearsolver::EigenSparseMatrix eigen_type; // eigen matrix for use with Compliant plugin @@ -1152,7 +126,6 @@ class BarycentricMapping : public core::Mapping void draw(const core::visual::VisualParams* vparams) override; - // handle topology changes depending on the topology virtual void handleTopologyChange(core::topology::Topology* t) override; // interface for continuous friction contact @@ -1162,10 +135,12 @@ class BarycentricMapping : public core::Mapping } protected: + sofa::core::topology::BaseMeshTopology* topology_from; sofa::core::topology::BaseMeshTopology* topology_to; private: + void createMapperFromTopology(BaseMeshTopology * topology); }; @@ -1179,105 +154,15 @@ using sofa::defaulttype::ExtVec3fTypes; #ifndef SOFA_FLOAT extern template class SOFA_BASE_MECHANICS_API BarycentricMapping< Vec3dTypes, Vec3dTypes >; extern template class SOFA_BASE_MECHANICS_API BarycentricMapping< Vec3dTypes, ExtVec3fTypes >; -extern template class SOFA_BASE_MECHANICS_API BarycentricMapper< Vec3dTypes, Vec3dTypes >; -extern template class SOFA_BASE_MECHANICS_API BarycentricMapper< Vec3dTypes, ExtVec3fTypes >; -extern template class SOFA_BASE_MECHANICS_API TopologyBarycentricMapper< Vec3dTypes, Vec3dTypes >; -extern template class SOFA_BASE_MECHANICS_API TopologyBarycentricMapper< Vec3dTypes, ExtVec3fTypes >; -extern template class SOFA_BASE_MECHANICS_API BarycentricMapperRegularGridTopology< Vec3dTypes, Vec3dTypes >; -extern template class SOFA_BASE_MECHANICS_API BarycentricMapperRegularGridTopology< Vec3dTypes, ExtVec3fTypes >; -extern template class SOFA_BASE_MECHANICS_API BarycentricMapperSparseGridTopology< Vec3dTypes, Vec3dTypes >; -extern template class SOFA_BASE_MECHANICS_API BarycentricMapperSparseGridTopology< Vec3dTypes, ExtVec3fTypes >; -extern template class SOFA_BASE_MECHANICS_API BarycentricMapperMeshTopology< Vec3dTypes, Vec3dTypes >; -extern template class SOFA_BASE_MECHANICS_API BarycentricMapperMeshTopology< Vec3dTypes, ExtVec3fTypes >; -extern template class SOFA_BASE_MECHANICS_API BarycentricMapperTopologyContainer< Vec3dTypes, Vec3dTypes , typename BarycentricMapper::MappingData1D, Edge>; -extern template class SOFA_BASE_MECHANICS_API BarycentricMapperTopologyContainer< Vec3dTypes, ExtVec3fTypes , typename BarycentricMapper::MappingData1D, Edge>; -extern template class SOFA_BASE_MECHANICS_API BarycentricMapperTopologyContainer< Vec3dTypes, Vec3dTypes , typename BarycentricMapper::MappingData2D, Triangle>; -extern template class SOFA_BASE_MECHANICS_API BarycentricMapperTopologyContainer< Vec3dTypes, ExtVec3fTypes , typename BarycentricMapper::MappingData2D, Triangle>; -extern template class SOFA_BASE_MECHANICS_API BarycentricMapperTopologyContainer< Vec3dTypes, Vec3dTypes , typename BarycentricMapper::MappingData2D, Quad>; -extern template class SOFA_BASE_MECHANICS_API BarycentricMapperTopologyContainer< Vec3dTypes, ExtVec3fTypes , typename BarycentricMapper::MappingData2D, Quad>; -extern template class SOFA_BASE_MECHANICS_API BarycentricMapperTopologyContainer< Vec3dTypes, Vec3dTypes , typename BarycentricMapper::MappingData3D, Tetrahedron>; -extern template class SOFA_BASE_MECHANICS_API BarycentricMapperTopologyContainer< Vec3dTypes, ExtVec3fTypes , typename BarycentricMapper::MappingData3D, Tetrahedron>; -extern template class SOFA_BASE_MECHANICS_API BarycentricMapperTopologyContainer< Vec3dTypes, Vec3dTypes , typename BarycentricMapper::MappingData3D, Hexahedron>; -extern template class SOFA_BASE_MECHANICS_API BarycentricMapperTopologyContainer< Vec3dTypes, ExtVec3fTypes , typename BarycentricMapper::MappingData3D, Hexahedron>; -extern template class SOFA_BASE_MECHANICS_API BarycentricMapperEdgeSetTopology< Vec3dTypes, Vec3dTypes>; -extern template class SOFA_BASE_MECHANICS_API BarycentricMapperEdgeSetTopology< Vec3dTypes, ExtVec3fTypes>; -extern template class SOFA_BASE_MECHANICS_API BarycentricMapperTriangleSetTopology< Vec3dTypes, Vec3dTypes >; -extern template class SOFA_BASE_MECHANICS_API BarycentricMapperTriangleSetTopology< Vec3dTypes, ExtVec3fTypes >; -extern template class SOFA_BASE_MECHANICS_API BarycentricMapperQuadSetTopology< Vec3dTypes, Vec3dTypes >; -extern template class SOFA_BASE_MECHANICS_API BarycentricMapperQuadSetTopology< Vec3dTypes, ExtVec3fTypes >; -extern template class SOFA_BASE_MECHANICS_API BarycentricMapperTetrahedronSetTopology< Vec3dTypes, Vec3dTypes >; -extern template class SOFA_BASE_MECHANICS_API BarycentricMapperTetrahedronSetTopology< Vec3dTypes, ExtVec3fTypes >; -extern template class SOFA_BASE_MECHANICS_API BarycentricMapperHexahedronSetTopology< Vec3dTypes, Vec3dTypes >; -extern template class SOFA_BASE_MECHANICS_API BarycentricMapperHexahedronSetTopology< Vec3dTypes, ExtVec3fTypes >; #endif #ifndef SOFA_DOUBLE extern template class SOFA_BASE_MECHANICS_API BarycentricMapping< Vec3fTypes, Vec3fTypes >; extern template class SOFA_BASE_MECHANICS_API BarycentricMapping< Vec3fTypes, ExtVec3fTypes >; -extern template class SOFA_BASE_MECHANICS_API BarycentricMapper< Vec3fTypes, Vec3fTypes >; -extern template class SOFA_BASE_MECHANICS_API BarycentricMapper< Vec3fTypes, ExtVec3fTypes >; -extern template class SOFA_BASE_MECHANICS_API TopologyBarycentricMapper< Vec3fTypes, Vec3fTypes >; -extern template class SOFA_BASE_MECHANICS_API TopologyBarycentricMapper< Vec3fTypes, ExtVec3fTypes >; -extern template class SOFA_BASE_MECHANICS_API BarycentricMapperRegularGridTopology< Vec3fTypes, Vec3fTypes >; -extern template class SOFA_BASE_MECHANICS_API BarycentricMapperRegularGridTopology< Vec3fTypes, ExtVec3fTypes >; -extern template class SOFA_BASE_MECHANICS_API BarycentricMapperSparseGridTopology< Vec3fTypes, Vec3fTypes >; -extern template class SOFA_BASE_MECHANICS_API BarycentricMapperSparseGridTopology< Vec3fTypes, ExtVec3fTypes >; -extern template class SOFA_BASE_MECHANICS_API BarycentricMapperMeshTopology< Vec3fTypes, Vec3fTypes >; -extern template class SOFA_BASE_MECHANICS_API BarycentricMapperMeshTopology< Vec3fTypes, ExtVec3fTypes >; -extern template class SOFA_BASE_MECHANICS_API BarycentricMapperTopologyContainer< Vec3fTypes, Vec3fTypes , typename BarycentricMapper::MappingData1D, Edge>; -extern template class SOFA_BASE_MECHANICS_API BarycentricMapperTopologyContainer< Vec3fTypes, ExtVec3fTypes , typename BarycentricMapper::MappingData1D, Edge>; -extern template class SOFA_BASE_MECHANICS_API BarycentricMapperTopologyContainer< Vec3fTypes, Vec3fTypes , typename BarycentricMapper::MappingData2D, Triangle>; -extern template class SOFA_BASE_MECHANICS_API BarycentricMapperTopologyContainer< Vec3fTypes, ExtVec3fTypes , typename BarycentricMapper::MappingData2D, Triangle>; -extern template class SOFA_BASE_MECHANICS_API BarycentricMapperTopologyContainer< Vec3fTypes, Vec3fTypes , typename BarycentricMapper::MappingData2D, Quad>; -extern template class SOFA_BASE_MECHANICS_API BarycentricMapperTopologyContainer< Vec3fTypes, ExtVec3fTypes , typename BarycentricMapper::MappingData2D, Quad>; -extern template class SOFA_BASE_MECHANICS_API BarycentricMapperTopologyContainer< Vec3fTypes, Vec3fTypes , typename BarycentricMapper::MappingData3D, Tetrahedron>; -extern template class SOFA_BASE_MECHANICS_API BarycentricMapperTopologyContainer< Vec3fTypes, ExtVec3fTypes , typename BarycentricMapper::MappingData3D, Tetrahedron>; -extern template class SOFA_BASE_MECHANICS_API BarycentricMapperTopologyContainer< Vec3fTypes, Vec3fTypes , typename BarycentricMapper::MappingData3D, Hexahedron>; -extern template class SOFA_BASE_MECHANICS_API BarycentricMapperTopologyContainer< Vec3fTypes, ExtVec3fTypes , typename BarycentricMapper::MappingData3D, Hexahedron>; -extern template class SOFA_BASE_MECHANICS_API BarycentricMapperEdgeSetTopology< Vec3fTypes, Vec3fTypes>; -extern template class SOFA_BASE_MECHANICS_API BarycentricMapperEdgeSetTopology< Vec3fTypes, ExtVec3fTypes>; -extern template class SOFA_BASE_MECHANICS_API BarycentricMapperTriangleSetTopology< Vec3fTypes, Vec3fTypes >; -extern template class SOFA_BASE_MECHANICS_API BarycentricMapperTriangleSetTopology< Vec3fTypes, ExtVec3fTypes >; -extern template class SOFA_BASE_MECHANICS_API BarycentricMapperQuadSetTopology< Vec3fTypes, Vec3fTypes >; -extern template class SOFA_BASE_MECHANICS_API BarycentricMapperQuadSetTopology< Vec3fTypes, ExtVec3fTypes >; -extern template class SOFA_BASE_MECHANICS_API BarycentricMapperTetrahedronSetTopology< Vec3fTypes, Vec3fTypes >; -extern template class SOFA_BASE_MECHANICS_API BarycentricMapperTetrahedronSetTopology< Vec3fTypes, ExtVec3fTypes >; -extern template class SOFA_BASE_MECHANICS_API BarycentricMapperHexahedronSetTopology< Vec3fTypes, Vec3fTypes >; -extern template class SOFA_BASE_MECHANICS_API BarycentricMapperHexahedronSetTopology< Vec3fTypes, ExtVec3fTypes >; #endif #ifndef SOFA_FLOAT #ifndef SOFA_DOUBLE extern template class SOFA_BASE_MECHANICS_API BarycentricMapping< Vec3dTypes, Vec3fTypes >; extern template class SOFA_BASE_MECHANICS_API BarycentricMapping< Vec3fTypes, Vec3dTypes >; -extern template class SOFA_BASE_MECHANICS_API BarycentricMapper< Vec3dTypes, Vec3fTypes >; -extern template class SOFA_BASE_MECHANICS_API BarycentricMapper< Vec3fTypes, Vec3dTypes >; -extern template class SOFA_BASE_MECHANICS_API TopologyBarycentricMapper< Vec3dTypes, Vec3fTypes >; -extern template class SOFA_BASE_MECHANICS_API TopologyBarycentricMapper< Vec3fTypes, Vec3dTypes >; -extern template class SOFA_BASE_MECHANICS_API BarycentricMapperRegularGridTopology< Vec3dTypes, Vec3fTypes >; -extern template class SOFA_BASE_MECHANICS_API BarycentricMapperRegularGridTopology< Vec3fTypes, Vec3dTypes >; -extern template class SOFA_BASE_MECHANICS_API BarycentricMapperSparseGridTopology< Vec3dTypes, Vec3fTypes >; -extern template class SOFA_BASE_MECHANICS_API BarycentricMapperSparseGridTopology< Vec3fTypes, Vec3dTypes >; -extern template class SOFA_BASE_MECHANICS_API BarycentricMapperMeshTopology< Vec3dTypes, Vec3fTypes >; -extern template class SOFA_BASE_MECHANICS_API BarycentricMapperMeshTopology< Vec3fTypes, Vec3dTypes >; -extern template class SOFA_BASE_MECHANICS_API BarycentricMapperTopologyContainer< Vec3dTypes, Vec3fTypes , typename BarycentricMapper::MappingData1D,Edge>; -extern template class SOFA_BASE_MECHANICS_API BarycentricMapperTopologyContainer< Vec3fTypes, Vec3dTypes , typename BarycentricMapper::MappingData1D,Edge>; -extern template class SOFA_BASE_MECHANICS_API BarycentricMapperTopologyContainer< Vec3dTypes, Vec3fTypes , typename BarycentricMapper::MappingData2D,Triangle>; -extern template class SOFA_BASE_MECHANICS_API BarycentricMapperTopologyContainer< Vec3fTypes, Vec3dTypes , typename BarycentricMapper::MappingData2D,Triangle>; -extern template class SOFA_BASE_MECHANICS_API BarycentricMapperTopologyContainer< Vec3dTypes, Vec3fTypes , typename BarycentricMapper::MappingData2D,Quad>; -extern template class SOFA_BASE_MECHANICS_API BarycentricMapperTopologyContainer< Vec3fTypes, Vec3dTypes , typename BarycentricMapper::MappingData2D,Quad>; -extern template class SOFA_BASE_MECHANICS_API BarycentricMapperTopologyContainer< Vec3dTypes, Vec3fTypes , typename BarycentricMapper::MappingData3D,Tetrahedron>; -extern template class SOFA_BASE_MECHANICS_API BarycentricMapperTopologyContainer< Vec3fTypes, Vec3dTypes , typename BarycentricMapper::MappingData3D,Tetrahedron>; -extern template class SOFA_BASE_MECHANICS_API BarycentricMapperTopologyContainer< Vec3dTypes, Vec3fTypes , typename BarycentricMapper::MappingData3D,Hexahedron>; -extern template class SOFA_BASE_MECHANICS_API BarycentricMapperTopologyContainer< Vec3fTypes, Vec3dTypes , typename BarycentricMapper::MappingData3D,Hexahedron>; -extern template class SOFA_BASE_MECHANICS_API BarycentricMapperEdgeSetTopology< Vec3dTypes, Vec3fTypes>; -extern template class SOFA_BASE_MECHANICS_API BarycentricMapperEdgeSetTopology< Vec3fTypes, Vec3dTypes>; -extern template class SOFA_BASE_MECHANICS_API BarycentricMapperTriangleSetTopology< Vec3dTypes, Vec3fTypes >; -extern template class SOFA_BASE_MECHANICS_API BarycentricMapperTriangleSetTopology< Vec3fTypes, Vec3dTypes >; -extern template class SOFA_BASE_MECHANICS_API BarycentricMapperQuadSetTopology< Vec3dTypes, Vec3fTypes >; -extern template class SOFA_BASE_MECHANICS_API BarycentricMapperQuadSetTopology< Vec3fTypes, Vec3dTypes >; -extern template class SOFA_BASE_MECHANICS_API BarycentricMapperTetrahedronSetTopology< Vec3dTypes, Vec3fTypes >; -extern template class SOFA_BASE_MECHANICS_API BarycentricMapperTetrahedronSetTopology< Vec3fTypes, Vec3dTypes >; -extern template class SOFA_BASE_MECHANICS_API BarycentricMapperHexahedronSetTopology< Vec3dTypes, Vec3fTypes >; -extern template class SOFA_BASE_MECHANICS_API BarycentricMapperHexahedronSetTopology< Vec3fTypes, Vec3dTypes >; #endif #endif #endif diff --git a/SofaKernel/modules/SofaBaseMechanics/BarycentricMapping.inl b/SofaKernel/modules/SofaBaseMechanics/BarycentricMapping.inl index 8b0f568f1f3..6f0b07d6355 100644 --- a/SofaKernel/modules/SofaBaseMechanics/BarycentricMapping.inl +++ b/SofaKernel/modules/SofaBaseMechanics/BarycentricMapping.inl @@ -39,7 +39,15 @@ #include #include #include -#include + +#include +#include +#include +#include +#include +#include +#include +#include #include #include @@ -80,7 +88,7 @@ typedef typename sofa::core::topology::BaseMeshTopology::SeqHexahedra SeqHexahed template BarycentricMapping::BarycentricMapping() - : Inherit1() + : Inherit() , m_mapper(initLink("mapper","Internal mapper created depending on the type of topology")) , useRestPosition(core::objectmodel::Base::initData(&useRestPosition, false, "useRestPosition", "Use the rest position of the input and output models to initialize the mapping")) #ifdef SOFA_DEV @@ -91,7 +99,7 @@ BarycentricMapping::BarycentricMapping() template BarycentricMapping::BarycentricMapping(core::State* from, core::State* to, typename Mapper::SPtr mapper) - : Inherit1 ( from, to ) + : Inherit ( from, to ) , m_mapper(initLink("mapper","Internal mapper created depending on the type of topology"), mapper) #ifdef SOFA_DEV , sleeping(core::objectmodel::Base::initData(&sleeping, false, "sleeping", "is the mapping sleeping (not computed)")) @@ -103,7 +111,7 @@ BarycentricMapping::BarycentricMapping(core::State* from, core::S template BarycentricMapping::BarycentricMapping (core::State* from, core::State* to, BaseMeshTopology * topology ) - : Inherit1 ( from, to ) + : Inherit ( from, to ) , m_mapper (initLink("mapper","Internal mapper created depending on the type of topology")) #ifdef SOFA_DEV , sleeping(core::objectmodel::Base::initData(&sleeping, false, "sleeping", "is the mapping sleeping (not computed)")) @@ -121,654 +129,6 @@ BarycentricMapping::~BarycentricMapping() } -template -void BarycentricMapperRegularGridTopology::clear ( int size ) -{ - updateJ = true; - m_map.clear(); - if ( size>0 ) m_map.reserve ( size ); -} - -template -int BarycentricMapperRegularGridTopology::addPointInCube ( const int cubeIndex, const SReal* baryCoords ) -{ - m_map.resize ( m_map.size() +1 ); - CubeData& data = *m_map.rbegin(); - data.in_index = cubeIndex; - data.baryCoords[0] = ( Real ) baryCoords[0]; - data.baryCoords[1] = ( Real ) baryCoords[1]; - data.baryCoords[2] = ( Real ) baryCoords[2]; - return (int)m_map.size()-1; -} - -template -void BarycentricMapperRegularGridTopology::init ( const typename Out::VecCoord& out, const typename In::VecCoord& in ) -{ - SOFA_UNUSED(in); - - updateJ = true; - - clear ( (int)out.size() ); - if ( m_fromTopology->isVolume() ) - { - for ( unsigned int i=0; ifindCube ( Vector3 ( Out::getCPos(out[i]) ), coefs[0], coefs[1], coefs[2] ); - if ( cube==-1 ) - cube = m_fromTopology->findNearestCube ( Vector3 ( Out::getCPos(out[i]) ), coefs[0], coefs[1], coefs[2] ); - - this->addPointInCube ( cube, coefs.ptr() ); - } - } -} - - - -template -void BarycentricMapperSparseGridTopology::clear ( int size ) -{ - updateJ = true; - m_map.clear(); - if ( size>0 ) m_map.reserve ( size ); -} - -template -int BarycentricMapperSparseGridTopology::addPointInCube ( const int cubeIndex, const SReal* baryCoords ) -{ - m_map.resize ( m_map.size() +1 ); - CubeData& data = *m_map.rbegin(); - data.in_index = cubeIndex; - data.baryCoords[0] = ( Real ) baryCoords[0]; - data.baryCoords[1] = ( Real ) baryCoords[1]; - data.baryCoords[2] = ( Real ) baryCoords[2]; - return (int)m_map.size()-1; -} - -template -void BarycentricMapperSparseGridTopology::init ( const typename Out::VecCoord& out, const typename In::VecCoord& /*in*/ ) -{ - if ( this->m_map.size() != 0 ) return; - updateJ = true; - clear ( (int)out.size() ); - - if ( m_fromTopology->isVolume() ) - { - for ( unsigned int i=0; ifindCube ( Vector3 ( Out::getCPos(out[i]) ), coefs[0], coefs[1], coefs[2] ); - if ( cube==-1 ) - { - cube = m_fromTopology->findNearestCube ( Vector3 ( Out::getCPos(out[i]) ), coefs[0], coefs[1], coefs[2] ); - } - Vector3 baryCoords = coefs; - this->addPointInCube ( cube, baryCoords.ptr() ); - } - } -} - - - -template -void BarycentricMapperMeshTopology::clearMap1dAndReserve ( int size ) -{ - m_updateJ = true; - m_map1d.clear(); - if ( size>0 ) m_map1d.reserve ( size ); -} - -template -void BarycentricMapperMeshTopology::clearMap2dAndReserve ( int size ) -{ - m_updateJ = true; - m_map2d.clear(); - if ( size>0 ) m_map2d.reserve ( size ); -} - -template -void BarycentricMapperMeshTopology::clearMap3dAndReserve ( int size ) -{ - m_updateJ = true; - m_map3d.clear(); - if ( size>0 ) m_map3d.reserve ( size ); -} - -template -void BarycentricMapperMeshTopology::clear ( int size ) -{ - m_updateJ = true; - clearMap1dAndReserve(size); - clearMap2dAndReserve(size); - clearMap3dAndReserve(size); -} - -template -int BarycentricMapperMeshTopology::addPointInLine ( const int lineIndex, const SReal* baryCoords ) -{ - m_map1d.resize ( m_map1d.size() +1 ); - MappingData1D& data = *m_map1d.rbegin(); - data.in_index = lineIndex; - data.baryCoords[0] = ( Real ) baryCoords[0]; - return (int)m_map1d.size()-1; -} - -template -int BarycentricMapperMeshTopology::addPointInTriangle ( const int triangleIndex, const SReal* baryCoords ) -{ - m_map2d.resize ( m_map2d.size() +1 ); - MappingData2D& data = *m_map2d.rbegin(); - data.in_index = triangleIndex; - data.baryCoords[0] = ( Real ) baryCoords[0]; - data.baryCoords[1] = ( Real ) baryCoords[1]; - return (int)m_map2d.size()-1; -} - -template -int BarycentricMapperMeshTopology::addPointInQuad ( const int quadIndex, const SReal* baryCoords ) -{ - m_map2d.resize ( m_map2d.size() +1 ); - MappingData2D& data = *m_map2d.rbegin(); - data.in_index = quadIndex + this->m_fromTopology->getNbTriangles(); - data.baryCoords[0] = ( Real ) baryCoords[0]; - data.baryCoords[1] = ( Real ) baryCoords[1]; - return (int)m_map2d.size()-1; -} - -template -int BarycentricMapperMeshTopology::addPointInTetra ( const int tetraIndex, const SReal* baryCoords ) -{ - m_map3d.resize ( m_map3d.size() +1 ); - MappingData3D& data = *m_map3d.rbegin(); - data.in_index = tetraIndex; - data.baryCoords[0] = ( Real ) baryCoords[0]; - data.baryCoords[1] = ( Real ) baryCoords[1]; - data.baryCoords[2] = ( Real ) baryCoords[2]; - return (int)m_map3d.size()-1; -} - -template -int BarycentricMapperMeshTopology::addPointInCube ( const int cubeIndex, const SReal* baryCoords ) -{ - m_map3d.resize ( m_map3d.size() +1 ); - MappingData3D& data = *m_map3d.rbegin(); - data.in_index = cubeIndex + this->m_fromTopology->getNbTetrahedra(); - data.baryCoords[0] = ( Real ) baryCoords[0]; - data.baryCoords[1] = ( Real ) baryCoords[1]; - data.baryCoords[2] = ( Real ) baryCoords[2]; - return (int)m_map3d.size()-1; -} - -template -int BarycentricMapperMeshTopology::createPointInLine ( const typename Out::Coord& p, int lineIndex, const typename In::VecCoord* points ) -{ - SReal baryCoords[1]; - const Line& elem = this->m_fromTopology->getLine ( lineIndex ); - const typename In::Coord p0 = ( *points ) [elem[0]]; - const typename In::Coord pA = ( *points ) [elem[1]] - p0; - typename In::Coord pos = Out::getCPos(p) - p0; - baryCoords[0] = ( ( pos*pA ) /pA.norm2() ); - return this->addPointInLine ( lineIndex, baryCoords ); -} - -template -int BarycentricMapperMeshTopology::createPointInTriangle ( const typename Out::Coord& p, int triangleIndex, const typename In::VecCoord* points ) -{ - SReal baryCoords[2]; - const Triangle& elem = this->m_fromTopology->getTriangle ( triangleIndex ); - - const typename In::Coord & p1 = ( *points ) [elem[0]]; - const typename In::Coord & p2 = ( *points ) [elem[1]]; - const typename In::Coord & p3 = ( *points ) [elem[2]]; - const typename In::Coord & to_be_projected = Out::getCPos(p); - - const typename In::Coord AB = p2-p1; - const typename In::Coord AC = p3-p1; - const typename In::Coord AQ = to_be_projected -p1; - sofa::defaulttype::Mat<2,2,typename In::Real> A; - sofa::defaulttype::Vec<2,typename In::Real> b; - A[0][0] = AB*AB; - A[1][1] = AC*AC; - A[0][1] = A[1][0] = AB*AC; - b[0] = AQ*AB; - b[1] = AQ*AC; - const typename In::Real det = sofa::defaulttype::determinant(A); - - baryCoords[0] = (b[0]*A[1][1] - b[1]*A[0][1])/det; - baryCoords[1] = (b[1]*A[0][0] - b[0]*A[1][0])/det; - - if (baryCoords[0] < 0 || baryCoords[1] < 0 || baryCoords[0] + baryCoords[1] > 1) - { - // nearest point is on an edge or corner - // barycentric coordinate on AB - SReal pAB = b[0] / A[0][0]; // AQ*AB / AB*AB - // barycentric coordinate on AC - SReal pAC = b[1] / A[1][1]; // AQ*AC / AB*AB - if (pAB < 0 && pAC < 0) - { - // closest point is A - baryCoords[0] = 0.0; - baryCoords[1] = 0.0; - } - else if (pAB < 1 && baryCoords[1] < 0) - { - // closest point is on AB - baryCoords[0] = pAB; - baryCoords[1] = 0.0; - } - else if (pAC < 1 && baryCoords[0] < 0) - { - // closest point is on AC - baryCoords[0] = 0.0; - baryCoords[1] = pAC; - } - else - { - // barycentric coordinate on BC - // BQ*BC / BC*BC = (AQ-AB)*(AC-AB) / (AC-AB)*(AC-AB) = (AQ*AC-AQ*AB + AB*AB-AB*AC) / (AB*AB+AC*AC-2AB*AC) - SReal pBC = (b[1] - b[0] + A[0][0] - A[0][1]) / (A[0][0] + A[1][1] - 2*A[0][1]); // BQ*BC / BC*BC - if (pBC < 0) - { - // closest point is B - baryCoords[0] = 1.0; - baryCoords[1] = 0.0; - } - else if (pBC > 1) - { - // closest point is C - baryCoords[0] = 0.0; - baryCoords[1] = 1.0; - } - else - { - // closest point is on BC - baryCoords[0] = 1.0-pBC; - baryCoords[1] = pBC; - } - } - } - - return this->addPointInTriangle ( triangleIndex, baryCoords ); -} - -template -int BarycentricMapperMeshTopology::createPointInQuad ( const typename Out::Coord& p, int quadIndex, const typename In::VecCoord* points ) -{ - SReal baryCoords[2]; - const Quad& elem = this->m_fromTopology->getQuad ( quadIndex ); - const typename In::Coord p0 = ( *points ) [elem[0]]; - const typename In::Coord pA = ( *points ) [elem[1]] - p0; - const typename In::Coord pB = ( *points ) [elem[3]] - p0; - typename In::Coord pos = Out::getCPos(p) - p0; - sofa::defaulttype::Mat<3,3,typename In::Real> m,mt,base; - m[0] = pA; - m[1] = pB; - m[2] = cross ( pA, pB ); - mt.transpose ( m ); - base.invert ( mt ); - const typename In::Coord base0 = base[0]; - const typename In::Coord base1 = base[1]; - baryCoords[0] = base0 * pos; - baryCoords[1] = base1 * pos; - return this->addPointInQuad ( quadIndex, baryCoords ); -} - -template -void BarycentricMapperMeshTopology::init ( const typename Out::VecCoord& out, const typename In::VecCoord& in ) -{ - m_updateJ = true; - - const SeqTetrahedra& tetras = this->m_fromTopology->getTetrahedra(); - const SeqHexahedra& hexas = this->m_fromTopology->getHexahedra(); - - const SeqTriangles& triangles = this->m_fromTopology->getTriangles(); - const SeqQuads& quads = this->m_fromTopology->getQuads(); - helper::vector bases; - helper::vector centers; - if ( tetras.empty() && hexas.empty() ) - { - if ( triangles.empty() && quads.empty() ) - { - const SeqEdges& edges = this->m_fromTopology->getEdges(); - if ( edges.empty() ) return; - - clearMap1dAndReserve ( (int)out.size() ); - - helper::vector< SReal > lengthEdges; - helper::vector< Vector3 > unitaryVectors; - - unsigned int e; - for ( e=0; e= 0 && coef <= 1 ) {addPointInLine ( e,&coef ); break; } - } - //If no good coefficient has been found, we add to the last element - if ( e == edges.size() ) addPointInLine ( (int)edges.size()-1,&coef ); - } - } - else - { - clearMap2dAndReserve ( (int)out.size() ); - size_t nbTriangles = triangles.size(); - bases.resize ( triangles.size() +quads.size() ); - centers.resize ( triangles.size() +quads.size() ); - for ( unsigned int t = 0; t < triangles.size(); t++ ) - { - Mat3x3d m,mt; - m[0] = in[triangles[t][1]]-in[triangles[t][0]]; - m[1] = in[triangles[t][2]]-in[triangles[t][0]]; - m[2] = cross ( m[0],m[1] ); - mt.transpose ( m ); - bases[t].invert ( mt ); - centers[t] = ( in[triangles[t][0]]+in[triangles[t][1]]+in[triangles[t][2]] ) /3; - } - for ( unsigned int q = 0; q < quads.size(); q++ ) - { - Mat3x3d m,mt; - m[0] = in[quads[q][1]]-in[quads[q][0]]; - m[1] = in[quads[q][3]]-in[quads[q][0]]; - m[2] = cross ( m[0],m[1] ); - mt.transpose ( m ); - bases[nbTriangles+q].invert ( mt ); - centers[nbTriangles+q] = ( in[quads[q][0]]+in[quads[q][1]]+in[quads[q][2]]+in[quads[q][3]] ) *0.25; - } - for ( unsigned int i=0; i0 ) d = ( outPos-centers[t] ).norm2(); - if ( d0 ) d = ( outPos-centers[nbTriangles+q] ).norm2(); - if ( d0 ) d = ( pos-centers[t] ).norm2(); - if ( d0 ) d = ( pos-centers[nbTetras+h] ).norm2(); - if ( d -void BarycentricMapperTopologyContainer::clear(int size) -{ - helper::vector& vectorData = *(d_map.beginEdit()); - vectorData.clear(); - if ( size>0 ) vectorData.reserve ( size ); - d_map.endEdit(); -} - -template -int BarycentricMapperEdgeSetTopology::addPointInLine ( const int edgeIndex, const SReal* baryCoords ) -{ - helper::vector& vectorData = *(d_map.beginEdit()); - vectorData.resize ( d_map.getValue().size() +1 ); - d_map.endEdit(); - MappingData& data = *vectorData.rbegin(); - data.in_index = edgeIndex; - data.baryCoords[0] = ( Real ) baryCoords[0]; - return (int)d_map.getValue().size()-1; -} - -template -int BarycentricMapperEdgeSetTopology::createPointInLine ( const typename Out::Coord& p, int edgeIndex, const typename In::VecCoord* points ) -{ - SReal baryCoords[1]; - const Edge& elem = this->m_fromTopology->getEdge ( edgeIndex ); - const typename In::Coord p0 = ( *points ) [elem[0]]; - const typename In::Coord pA = ( *points ) [elem[1]] - p0; - typename In::Coord pos = Out::getCPos(p) - p0; - baryCoords[0] = dot ( pA,pos ) /dot ( pA,pA ); - return this->addPointInLine ( edgeIndex, baryCoords ); -} - -template -int BarycentricMapperTriangleSetTopology::addPointInTriangle ( const int triangleIndex, const SReal* baryCoords ) -{ - helper::vector& vectorData = *(d_map.beginEdit()); - vectorData.resize ( d_map.getValue().size() +1 ); - MappingData& data = *vectorData.rbegin(); - d_map.endEdit(); - data.in_index = triangleIndex; - data.baryCoords[0] = ( Real ) baryCoords[0]; - data.baryCoords[1] = ( Real ) baryCoords[1]; - return (int)d_map.getValue().size()-1; -} - -template -int BarycentricMapperTriangleSetTopology::createPointInTriangle ( const typename Out::Coord& p, int triangleIndex, const typename In::VecCoord* points ) -{ - SReal baryCoords[2]; - const Triangle& elem = this->m_fromTopology->getTriangle ( triangleIndex ); - const typename In::Coord p0 = ( *points ) [elem[0]]; - const typename In::Coord pA = ( *points ) [elem[1]] - p0; - const typename In::Coord pB = ( *points ) [elem[2]] - p0; - typename In::Coord pos = Out::getCPos(p) - p0; - // First project to plane - typename In::Coord normal = cross ( pA, pB ); - Real norm2 = normal.norm2(); - pos -= normal* ( ( pos*normal ) /norm2 ); - baryCoords[0] = ( Real ) sqrt ( cross ( pB, pos ).norm2() / norm2 ); - baryCoords[1] = ( Real ) sqrt ( cross ( pA, pos ).norm2() / norm2 ); - return this->addPointInTriangle ( triangleIndex, baryCoords ); -} - -template -int BarycentricMapperQuadSetTopology::addPointInQuad ( const int quadIndex, const SReal* baryCoords ) -{ - helper::vector& vectorData = *(d_map.beginEdit()); - vectorData.resize ( d_map.getValue().size() +1 ); - MappingData& data = *vectorData.rbegin(); - d_map.endEdit(); - data.in_index = quadIndex; - data.baryCoords[0] = ( Real ) baryCoords[0]; - data.baryCoords[1] = ( Real ) baryCoords[1]; - return (int)d_map.getValue().size()-1; -} - -template -int BarycentricMapperQuadSetTopology::createPointInQuad ( const typename Out::Coord& p, int quadIndex, const typename In::VecCoord* points ) -{ - SReal baryCoords[2]; - const Quad& elem = this->m_fromTopology->getQuad ( quadIndex ); - const typename In::Coord p0 = ( *points ) [elem[0]]; - const typename In::Coord pA = ( *points ) [elem[1]] - p0; - const typename In::Coord pB = ( *points ) [elem[3]] - p0; - typename In::Coord pos = Out::getCPos(p) - p0; - sofa::defaulttype::Mat<3,3,typename In::Real> m,mt,base; - m[0] = pA; - m[1] = pB; - m[2] = cross ( pA, pB ); - mt.transpose ( m ); - base.invert ( mt ); - const typename In::Coord base0 = base[0]; - const typename In::Coord base1 = base[1]; - baryCoords[0] = base0 * pos; - baryCoords[1] = base1 * pos; - return this->addPointInQuad ( quadIndex, baryCoords ); -} - -template -int BarycentricMapperTetrahedronSetTopology::addPointInTetra ( const int tetraIndex, const SReal* baryCoords ) -{ - helper::vector& vectorData = *(d_map.beginEdit()); - vectorData.resize ( d_map.getValue().size() +1 ); - MappingData& data = *vectorData.rbegin(); - d_map.endEdit(); - data.in_index = tetraIndex; - data.baryCoords[0] = ( Real ) baryCoords[0]; - data.baryCoords[1] = ( Real ) baryCoords[1]; - data.baryCoords[2] = ( Real ) baryCoords[2]; - return (int)d_map.getValue().size()-1; -} - -template -int BarycentricMapperHexahedronSetTopology::addPointInCube ( const int cubeIndex, const SReal* baryCoords ) -{ - helper::vector& vectorData = *(d_map.beginEdit()); - vectorData.resize ( d_map.getValue().size() +1 ); - MappingData& data = *vectorData.rbegin(); - d_map.endEdit(); - data.in_index = cubeIndex; - data.baryCoords[0] = ( Real ) baryCoords[0]; - data.baryCoords[1] = ( Real ) baryCoords[1]; - data.baryCoords[2] = ( Real ) baryCoords[2]; - return (int)d_map.getValue().size()-1; -} - -template -int BarycentricMapperHexahedronSetTopology::setPointInCube ( const int pointIndex, const int cubeIndex, const SReal* baryCoords ) -{ - if ( pointIndex >= ( int ) d_map.getValue().size() ) - return -1; - - helper::vector& vectorData = *(d_map.beginEdit()); - MappingData& data = vectorData[pointIndex]; - data.in_index = cubeIndex; - data.baryCoords[0] = ( Real ) baryCoords[0]; - data.baryCoords[1] = ( Real ) baryCoords[1]; - data.baryCoords[2] = ( Real ) baryCoords[2]; - d_map.endEdit(); - - if(cubeIndex == -1) - m_invalidIndex.insert(pointIndex); - else - m_invalidIndex.erase(pointIndex); - - return pointIndex; -} - -template -void BarycentricMapperTopologyContainer::init ( const typename Out::VecCoord& out, const typename In::VecCoord& in ) -{ - const helper::vector& elements = getElements(); - helper::vector bases; - helper::vector centers; - - this->clear ( (int)out.size() ); - bases.resize ( elements.size() ); - centers.resize ( elements.size() ); - - // Compute bases and centers of each element - for ( unsigned int e = 0; e < elements.size(); e++ ) - { - Element element = elements[e]; - - Mat3x3d base; - computeBase(base,in,element); - bases[e] = base; - - Vector3 center; - computeCenter(center,in,element); - centers[e] = center; - } - - // Compute distances to get nearest element and corresponding bary coef - for ( unsigned int i=0; i0 ) - dist = ( outPos-centers[e] ).norm2(); - if ( dist void BarycentricMapping::createMapperFromTopology ( BaseMeshTopology * topology ) { @@ -779,21 +139,21 @@ void BarycentricMapping::createMapperFromTopology ( BaseMeshTopology topology::PointSetTopologyContainer* toTopoCont; this->toModel->getContext()->get(toTopoCont); - core::topology::TopologyContainer* fromTopoCont = 0; + core::topology::TopologyContainer* fromTopoCont = nullptr; - if (dynamic_cast< core::topology::TopologyContainer* >(topology) != 0) + if (dynamic_cast< core::topology::TopologyContainer* >(topology) != nullptr) { fromTopoCont = dynamic_cast< core::topology::TopologyContainer* >(topology); } - else if (topology == 0) + else if (topology == nullptr) { this->fromModel->getContext()->get(fromTopoCont); } - if (fromTopoCont != NULL) + if (fromTopoCont != nullptr) { topology::HexahedronSetTopologyContainer* t1 = dynamic_cast< topology::HexahedronSetTopologyContainer* >(fromTopoCont); - if (t1 != NULL) + if (t1 != nullptr) { typedef BarycentricMapperHexahedronSetTopology HexahedronSetMapper; m_mapper = sofa::core::objectmodel::New(t1, toTopoCont); @@ -801,7 +161,7 @@ void BarycentricMapping::createMapperFromTopology ( BaseMeshTopology else { topology::TetrahedronSetTopologyContainer* t2 = dynamic_cast(fromTopoCont); - if (t2 != NULL) + if (t2 != nullptr) { typedef BarycentricMapperTetrahedronSetTopology TetrahedronSetMapper; m_mapper = sofa::core::objectmodel::New(t2, toTopoCont); @@ -809,7 +169,7 @@ void BarycentricMapping::createMapperFromTopology ( BaseMeshTopology else { topology::QuadSetTopologyContainer* t3 = dynamic_cast(fromTopoCont); - if (t3 != NULL) + if (t3 != nullptr) { typedef BarycentricMapperQuadSetTopology QuadSetMapper; m_mapper = sofa::core::objectmodel::New(t3, toTopoCont); @@ -817,7 +177,7 @@ void BarycentricMapping::createMapperFromTopology ( BaseMeshTopology else { topology::TriangleSetTopologyContainer* t4 = dynamic_cast(fromTopoCont); - if (t4 != NULL) + if (t4 != nullptr) { typedef BarycentricMapperTriangleSetTopology TriangleSetMapper; m_mapper = sofa::core::objectmodel::New(t4, toTopoCont); @@ -825,7 +185,7 @@ void BarycentricMapping::createMapperFromTopology ( BaseMeshTopology else { topology::EdgeSetTopologyContainer* t5 = dynamic_cast(fromTopoCont); - if ( t5 != NULL ) + if ( t5 != nullptr ) { typedef BarycentricMapperEdgeSetTopology EdgeSetMapper; m_mapper = sofa::core::objectmodel::New(t5, toTopoCont); @@ -841,7 +201,7 @@ void BarycentricMapping::createMapperFromTopology ( BaseMeshTopology RegularGridTopology* rgt = dynamic_cast< RegularGridTopology* >(topology); - if (rgt != NULL && rgt->isVolume()) + if (rgt != nullptr && rgt->isVolume()) { typedef BarycentricMapperRegularGridTopology< InDataTypes, OutDataTypes > RegularGridMapper; @@ -852,7 +212,7 @@ void BarycentricMapping::createMapperFromTopology ( BaseMeshTopology using sofa::component::topology::SparseGridTopology; SparseGridTopology* sgt = dynamic_cast< SparseGridTopology* >(topology); - if (sgt != NULL && sgt->isVolume()) + if (sgt != nullptr && sgt->isVolume()) { typedef BarycentricMapperSparseGridTopology< InDataTypes, OutDataTypes > SparseGridMapper; m_mapper = sofa::core::objectmodel::New(sgt, toTopoCont); @@ -882,7 +242,7 @@ void BarycentricMapping::init() topology_from = this->fromModel->getContext()->getMeshTopology(); topology_to = this->toModel->getContext()->getMeshTopology(); - Inherit1::init(); + Inherit::init(); if ( m_mapper == NULL ) // try to create a mapper according to the topology of the In model { @@ -917,11 +277,6 @@ void BarycentricMapping::reinit() } - -/************************************* Apply and Resize ***********************************/ - - - template void BarycentricMapping::apply(const core::MechanicalParams * mparams, Data< typename Out::VecCoord >& out, const Data< typename In::VecCoord >& in) { @@ -939,228 +294,16 @@ void BarycentricMapping::apply(const core::MechanicalParams * mparams } } -template -void BarycentricMapperMeshTopology::resize( core::State* toModel ) -{ - toModel->resize(m_map1d.size() +m_map2d.size() +m_map3d.size()); -} -template -void BarycentricMapperMeshTopology::apply ( typename Out::VecCoord& out, const typename In::VecCoord& in ) -{ - out.resize( m_map1d.size() +m_map2d.size() +m_map3d.size() ); - const SeqLines& lines = this->m_fromTopology->getLines(); - const SeqTriangles& triangles = this->m_fromTopology->getTriangles(); - const SeqQuads& quads = this->m_fromTopology->getQuads(); - const SeqTetrahedra& tetrahedra = this->m_fromTopology->getTetrahedra(); - const SeqHexahedra& cubes = this->m_fromTopology->getHexahedra(); - // 1D elements - { - for ( unsigned int i=0; i -void BarycentricMapperRegularGridTopology::resize( core::State* toModel ) -{ - toModel->resize(m_map.size()); -} - -template -void BarycentricMapperRegularGridTopology::apply ( typename Out::VecCoord& out, const typename In::VecCoord& in ) -{ - out.resize( m_map.size() ); - - for ( unsigned int i=0; im_fromTopology->getHexaCopy ( this->m_map[i].in_index ); - - const Real fx = m_map[i].baryCoords[0]; - const Real fy = m_map[i].baryCoords[1]; - const Real fz = m_map[i].baryCoords[2]; - Out::setCPos(out[i] , in[cube[0]] * ( ( 1-fx ) * ( 1-fy ) * ( 1-fz ) ) - + in[cube[1]] * ( ( fx ) * ( 1-fy ) * ( 1-fz ) ) - + in[cube[3]] * ( ( 1-fx ) * ( fy ) * ( 1-fz ) ) - + in[cube[2]] * ( ( fx ) * ( fy ) * ( 1-fz ) ) - + in[cube[4]] * ( ( 1-fx ) * ( 1-fy ) * ( fz ) ) - + in[cube[5]] * ( ( fx ) * ( 1-fy ) * ( fz ) ) - + in[cube[7]] * ( ( 1-fx ) * ( fy ) * ( fz ) ) - + in[cube[6]] * ( ( fx ) * ( fy ) * ( fz ) ) ); - } -} - -template -void BarycentricMapperSparseGridTopology::resize( core::State* toModel ) -{ - toModel->resize(m_map.size()); -} - -template -void BarycentricMapperSparseGridTopology::apply ( typename Out::VecCoord& out, const typename In::VecCoord& in ) -{ - out.resize( m_map.size() ); - - typedef helper::vector< CubeData > CubeDataVector; - typedef typename CubeDataVector::const_iterator CubeDataVectorIt; - - CubeDataVectorIt it = m_map.begin(); - CubeDataVectorIt itEnd = m_map.end(); - - unsigned int i = 0; - - while (it != itEnd) - { - const topology::SparseGridTopology::Hexa cube = this->m_fromTopology->getHexahedron( it->in_index ); - - const Real fx = it->baryCoords[0]; - const Real fy = it->baryCoords[1]; - const Real fz = it->baryCoords[2]; - - Out::setCPos(out[i] , in[cube[0]] * ( ( 1-fx ) * ( 1-fy ) * ( 1-fz ) ) - + in[cube[1]] * ( ( fx ) * ( 1-fy ) * ( 1-fz ) ) - + in[cube[3]] * ( ( 1-fx ) * ( fy ) * ( 1-fz ) ) - + in[cube[2]] * ( ( fx ) * ( fy ) * ( 1-fz ) ) - + in[cube[4]] * ( ( 1-fx ) * ( 1-fy ) * ( fz ) ) - + in[cube[5]] * ( ( fx ) * ( 1-fy ) * ( fz ) ) - + in[cube[7]] * ( ( 1-fx ) * ( fy ) * ( fz ) ) - + in[cube[6]] * ( ( fx ) * ( fy ) * ( fz ) ) ); - - ++it; - ++i; - } -} - -template -void BarycentricMapperTopologyContainer::apply ( typename Out::VecCoord& out, const typename In::VecCoord& in ) -{ - out.resize( d_map.getValue().size() ); - - const helper::vector& elements = getElements(); - for ( unsigned int i=0; i baryCoef = getBaryCoef(d_map.getValue()[i].baryCoords); - InDeriv inPos{0.,0.,0.}; - for (unsigned int j=0; j -void BarycentricMapperTopologyContainer::resize( core::State* toModel ) -{ - toModel->resize(d_map.getValue().size()); -} - -//-- test mapping partiel -template -void BarycentricMapperHexahedronSetTopology::applyOnePoint( const unsigned int& hexaPointId,typename Out::VecCoord& out, const typename In::VecCoord& in ) -{ - const helper::vector& cubes = this->m_fromTopology->getHexahedra(); - const Real fx = d_map.getValue()[hexaPointId].baryCoords[0]; - const Real fy = d_map.getValue()[hexaPointId].baryCoords[1]; - const Real fz = d_map.getValue()[hexaPointId].baryCoords[2]; - int index = d_map.getValue()[hexaPointId].in_index; - const Hexahedron& cube = cubes[index]; - Out::setCPos(out[hexaPointId] , in[cube[0]] * ( ( 1-fx ) * ( 1-fy ) * ( 1-fz ) ) - + in[cube[1]] * ( ( fx ) * ( 1-fy ) * ( 1-fz ) ) - + in[cube[3]] * ( ( 1-fx ) * ( fy ) * ( 1-fz ) ) - + in[cube[2]] * ( ( fx ) * ( fy ) * ( 1-fz ) ) - + in[cube[4]] * ( ( 1-fx ) * ( 1-fy ) * ( fz ) ) - + in[cube[5]] * ( ( fx ) * ( 1-fy ) * ( fz ) ) - + in[cube[7]] * ( ( 1-fx ) * ( fy ) * ( fz ) ) - + in[cube[6]] * ( ( fx ) * ( fy ) * ( fz ) ) ); -} -//-- - - -/************************************* ApplyJ ***********************************/ - - -template -void BarycentricMapping::applyJ (const core::MechanicalParams * mparams, Data< typename Out::VecDeriv >& _out, const Data< typename In::VecDeriv >& in) -{ - SOFA_UNUSED(mparams); - -#ifdef SOFA_DEV - if ( sleeping.getValue()==false) +template +void BarycentricMapping::applyJ (const core::MechanicalParams * mparams, Data< typename Out::VecDeriv >& _out, const Data< typename In::VecDeriv >& in) +{ + SOFA_UNUSED(mparams); + +#ifdef SOFA_DEV + if ( sleeping.getValue()==false) { #endif typename Out::VecDeriv* out = _out.beginEdit(); @@ -1174,178 +317,6 @@ void BarycentricMapping::applyJ (const core::MechanicalParams * mpara #endif } -template -void BarycentricMapperMeshTopology::applyJ ( typename Out::VecDeriv& out, const typename In::VecDeriv& in ) -{ - out.resize( m_map1d.size() +m_map2d.size() +m_map3d.size() ); - - const SeqLines& lines = this->m_fromTopology->getLines(); - const SeqTriangles& triangles = this->m_fromTopology->getTriangles(); - const SeqQuads& quads = this->m_fromTopology->getQuads(); - const SeqTetrahedra& tetrahedra = this->m_fromTopology->getTetrahedra(); - const SeqHexahedra& cubes = this->m_fromTopology->getHexahedra(); - - const size_t sizeMap1d=m_map1d.size(); - const size_t sizeMap2d=m_map2d.size(); - const size_t sizeMap3d=m_map3d.size(); - - const size_t idxStart1=sizeMap1d; - const size_t idxStart2=sizeMap1d+sizeMap2d; - const size_t idxStart3=sizeMap1d+sizeMap2d+sizeMap3d; - - for( size_t i=0 ; imaskTo->size() ; ++i) - { - if( this->maskTo->isActivated() && !this->maskTo->getEntry(i) ) continue; - - // 1D elements - if (i < idxStart1) - { - const Real fx = m_map1d[i].baryCoords[0]; - int index = m_map1d[i].in_index; - { - const Line& line = lines[index]; - Out::setDPos(out[i] , in[line[0]] * ( 1-fx ) - + in[line[1]] * fx ); - } - } - // 2D elements - else if (i < idxStart2) - { - const size_t i0 = idxStart1; - const size_t c0 = triangles.size(); - - const Real fx = m_map2d[i-i0].baryCoords[0]; - const Real fy = m_map2d[i-i0].baryCoords[1]; - size_t index = m_map2d[i-i0].in_index; - - if ( index -void BarycentricMapperRegularGridTopology::applyJ ( typename Out::VecDeriv& out, const typename In::VecDeriv& in ) -{ - out.resize( m_map.size() ); - - for( size_t index=0 ; indexmaskTo->size() ; ++index) - { - if( this->maskTo->isActivated() && !this->maskTo->getEntry(index) ) continue; - - const topology::RegularGridTopology::Hexa cube = this->m_fromTopology->getHexaCopy ( this->m_map[index].in_index ); - - const Real fx = m_map[index].baryCoords[0]; - const Real fy = m_map[index].baryCoords[1]; - const Real fz = m_map[index].baryCoords[2]; - Out::setDPos(out[index] , in[cube[0]] * ( ( 1-fx ) * ( 1-fy ) * ( 1-fz ) ) - + in[cube[1]] * ( ( fx ) * ( 1-fy ) * ( 1-fz ) ) - + in[cube[3]] * ( ( 1-fx ) * ( fy ) * ( 1-fz ) ) - + in[cube[2]] * ( ( fx ) * ( fy ) * ( 1-fz ) ) - + in[cube[4]] * ( ( 1-fx ) * ( 1-fy ) * ( fz ) ) - + in[cube[5]] * ( ( fx ) * ( 1-fy ) * ( fz ) ) - + in[cube[7]] * ( ( 1-fx ) * ( fy ) * ( fz ) ) - + in[cube[6]] * ( ( fx ) * ( fy ) * ( fz ) ) ); - } -} - -template -void BarycentricMapperSparseGridTopology::applyJ ( typename Out::VecDeriv& out, const typename In::VecDeriv& in ) -{ - out.resize( m_map.size() ); - - for( size_t index=0 ; indexmaskTo->size() ; ++index) - { - if( this->maskTo->isActivated() && !this->maskTo->getEntry(index) ) continue; - - const topology::SparseGridTopology::Hexa cube = this->m_fromTopology->getHexahedron ( this->m_map[index].in_index ); - - const Real fx = m_map[index].baryCoords[0]; - const Real fy = m_map[index].baryCoords[1]; - const Real fz = m_map[index].baryCoords[2]; - Out::setDPos(out[index] , in[cube[0]] * ( ( 1-fx ) * ( 1-fy ) * ( 1-fz ) ) - + in[cube[1]] * ( ( fx ) * ( 1-fy ) * ( 1-fz ) ) - + in[cube[3]] * ( ( 1-fx ) * ( fy ) * ( 1-fz ) ) - + in[cube[2]] * ( ( fx ) * ( fy ) * ( 1-fz ) ) - + in[cube[4]] * ( ( 1-fx ) * ( 1-fy ) * ( fz ) ) - + in[cube[5]] * ( ( fx ) * ( 1-fy ) * ( fz ) ) - + in[cube[7]] * ( ( 1-fx ) * ( fy ) * ( fz ) ) - + in[cube[6]] * ( ( fx ) * ( fy ) * ( fz ) ) ); - } - -} - -template -void BarycentricMapperTopologyContainer::applyJ ( typename Out::VecDeriv& out, const typename In::VecDeriv& in ) -{ - out.resize( d_map.getValue().size() ); - - const helper::vector& elements = getElements(); - - for( size_t i=0 ; imaskTo->size() ; ++i) - { - if( this->maskTo->isActivated() && !this->maskTo->getEntry(i) ) continue; - - int index = d_map.getValue()[i].in_index; - const Element& element = elements[index]; - - helper::vector baryCoef = getBaryCoef(d_map.getValue()[i].baryCoords); - InDeriv inPos{0.,0.,0.}; - for (unsigned int j=0; j void BarycentricMapping::applyJT (const core::MechanicalParams * mparams, Data< typename In::VecDeriv >& out, const Data< typename Out::VecDeriv >& in) @@ -1363,227 +334,6 @@ void BarycentricMapping::applyJT (const core::MechanicalParams * mpar } } -template -void BarycentricMapperMeshTopology::applyJT ( typename In::VecDeriv& out, const typename Out::VecDeriv& in ) -{ - const SeqLines& lines = this->m_fromTopology->getLines(); - const SeqTriangles& triangles = this->m_fromTopology->getTriangles(); - const SeqQuads& quads = this->m_fromTopology->getQuads(); - const SeqTetrahedra& tetrahedra = this->m_fromTopology->getTetrahedra(); - const SeqHexahedra& cubes = this->m_fromTopology->getHexahedra(); - - const size_t i1d = m_map1d.size(); - const size_t i2d = m_map2d.size(); - const size_t i3d = m_map3d.size(); - - ForceMask& mask = *this->maskFrom; - - for( size_t i=0 ; imaskTo->size() ; ++i) - { - if( !this->maskTo->getEntry(i) ) continue; - - // 1D elements - if (i < i1d) - { - const typename Out::DPos v = Out::getDPos(in[i]); - const OutReal fx = ( OutReal ) m_map1d[i].baryCoords[0]; - size_t index = m_map1d[i].in_index; - { - const Line& line = lines[index]; - out[line[0]] += v * ( 1-fx ); - out[line[1]] += v * fx; - mask.insertEntry(line[0]); - mask.insertEntry(line[1]); - } - } - // 2D elements - else if (i < i1d+i2d) - { - const size_t i0 = m_map1d.size(); - const size_t c0 = triangles.size(); - const typename Out::DPos v = Out::getDPos(in[i]); - const OutReal fx = ( OutReal ) m_map2d[i-i0].baryCoords[0]; - const OutReal fy = ( OutReal ) m_map2d[i-i0].baryCoords[1]; - size_t index = m_map2d[i-i0].in_index; - if ( index -void BarycentricMapperRegularGridTopology::applyJT ( typename In::VecDeriv& out, const typename Out::VecDeriv& in ) -{ - ForceMask& mask = *this->maskFrom; - - for( size_t index=0 ; indexmaskTo->size() ; ++index) - { - if( !this->maskTo->getEntry(index) ) continue; - - const typename Out::DPos v = Out::getDPos(in[index]); - const topology::RegularGridTopology::Hexa cube = this->m_fromTopology->getHexaCopy ( this->m_map[index].in_index ); - - const OutReal fx = ( OutReal ) m_map[index].baryCoords[0]; - const OutReal fy = ( OutReal ) m_map[index].baryCoords[1]; - const OutReal fz = ( OutReal ) m_map[index].baryCoords[2]; - out[cube[0]] += v * ( ( 1-fx ) * ( 1-fy ) * ( 1-fz ) ); - out[cube[1]] += v * ( ( fx ) * ( 1-fy ) * ( 1-fz ) ); - - out[cube[3]] += v * ( ( 1-fx ) * ( fy ) * ( 1-fz ) ); - out[cube[2]] += v * ( ( fx ) * ( fy ) * ( 1-fz ) ); - - out[cube[4]] += v * ( ( 1-fx ) * ( 1-fy ) * ( fz ) ); - out[cube[5]] += v * ( ( fx ) * ( 1-fy ) * ( fz ) ); - - out[cube[7]] += v * ( ( 1-fx ) * ( fy ) * ( fz ) ); - out[cube[6]] += v * ( ( fx ) * ( fy ) * ( fz ) ); - - mask.insertEntry(cube[0]); - mask.insertEntry(cube[1]); - mask.insertEntry(cube[2]); - mask.insertEntry(cube[3]); - mask.insertEntry(cube[4]); - mask.insertEntry(cube[5]); - mask.insertEntry(cube[6]); - mask.insertEntry(cube[7]); - } - -} - -template -void BarycentricMapperSparseGridTopology::applyJT ( typename In::VecDeriv& out, const typename Out::VecDeriv& in ) -{ - ForceMask& mask = *this->maskFrom; - - for( size_t index=0 ; indexmaskTo->size() ; ++index) - { - if( !this->maskTo->getEntry(index) ) continue; - - const typename Out::DPos v = Out::getDPos(in[index]); - - const topology::SparseGridTopology::Hexa cube = this->m_fromTopology->getHexahedron ( this->m_map[index].in_index ); - - const OutReal fx = ( OutReal ) m_map[index].baryCoords[0]; - const OutReal fy = ( OutReal ) m_map[index].baryCoords[1]; - const OutReal fz = ( OutReal ) m_map[index].baryCoords[2]; - out[cube[0]] += v * ( ( 1-fx ) * ( 1-fy ) * ( 1-fz ) ); - out[cube[1]] += v * ( ( fx ) * ( 1-fy ) * ( 1-fz ) ); - - out[cube[3]] += v * ( ( 1-fx ) * ( fy ) * ( 1-fz ) ); - out[cube[2]] += v * ( ( fx ) * ( fy ) * ( 1-fz ) ); - - out[cube[4]] += v * ( ( 1-fx ) * ( 1-fy ) * ( fz ) ); - out[cube[5]] += v * ( ( fx ) * ( 1-fy ) * ( fz ) ); - - out[cube[7]] += v * ( ( 1-fx ) * ( fy ) * ( fz ) ); - out[cube[6]] += v * ( ( fx ) * ( fy ) * ( fz ) ); - - mask.insertEntry(cube[0]); - mask.insertEntry(cube[1]); - mask.insertEntry(cube[2]); - mask.insertEntry(cube[3]); - mask.insertEntry(cube[4]); - mask.insertEntry(cube[5]); - mask.insertEntry(cube[6]); - mask.insertEntry(cube[7]); - } -} - -template -void BarycentricMapperTopologyContainer::applyJT ( typename In::VecDeriv& out, const typename Out::VecDeriv& in ) -{ - const helper::vector& elements = getElements(); - - ForceMask& mask = *this->maskFrom; - for( size_t i=0 ; imaskTo->size() ; ++i) - { - if( !this->maskTo->getEntry(i) ) continue; - - int index = d_map.getValue()[i].in_index; - const Element& element = elements[index]; - - const typename Out::DPos inPos = Out::getDPos(in[i]); - helper::vector baryCoef = getBaryCoef(d_map.getValue()[i].baryCoords); - for (unsigned int j=0; j const sofa::defaulttype::BaseMatrix* BarycentricMapping::getJ() @@ -1601,501 +351,37 @@ const sofa::defaulttype::BaseMatrix* BarycentricMapping::getJ() return matJ; } else - return NULL; + return nullptr; } -template -const sofa::defaulttype::BaseMatrix* BarycentricMapperMeshTopology::getJ(int outSize, int inSize) -{ - - if (m_matrixJ && !m_updateJ && m_matrixJ->rowBSize() == (MatrixTypeIndex)outSize && m_matrixJ->colBSize() == (MatrixTypeIndex)inSize) - return m_matrixJ; - if (outSize > 0 && m_map1d.size()+m_map2d.size()+m_map3d.size() == 0) - return NULL; // error: maps not yet created ? - if (!m_matrixJ) m_matrixJ = new MatrixType; - if (m_matrixJ->rowBSize() != (MatrixTypeIndex)outSize || m_matrixJ->colBSize() != (MatrixTypeIndex)inSize) - m_matrixJ->resize(outSize*NOut, inSize*NIn); - else - m_matrixJ->clear(); - const SeqLines& lines = this->m_fromTopology->getLines(); - const SeqTriangles& triangles = this->m_fromTopology->getTriangles(); - const SeqQuads& quads = this->m_fromTopology->getQuads(); - const SeqTetrahedra& tetrahedra = this->m_fromTopology->getTetrahedra(); - const SeqHexahedra& cubes = this->m_fromTopology->getHexahedra(); +template +void BarycentricMapping::draw(const core::visual::VisualParams* vparams) +{ + if ( !vparams->displayFlags().getShowMappings() ) return; - // 1D elements - { - for ( size_t i=0; iaddMatrixContrib(m_matrixJ, out, line[0], ( 1-fx )); - this->addMatrixContrib(m_matrixJ, out, line[1], fx); - } - } - } - // 2D elements + // Draw model (out) points + const OutVecCoord& out = this->toModel->read(core::ConstVecCoordId::position())->getValue(); + std::vector< Vector3 > points; + for ( unsigned int i=0; iaddMatrixContrib(m_matrixJ, out, triangle[0], ( 1-fx-fy )); - this->addMatrixContrib(m_matrixJ, out, triangle[1], fx); - this->addMatrixContrib(m_matrixJ, out, triangle[2], fy); - } - else - { - const Quad& quad = quads[index-c0]; - this->addMatrixContrib(m_matrixJ, out, quad[0], ( ( 1-fx ) * ( 1-fy ) )); - this->addMatrixContrib(m_matrixJ, out, quad[1], ( ( fx ) * ( 1-fy ) )); - this->addMatrixContrib(m_matrixJ, out, quad[3], ( ( 1-fx ) * ( fy ) )); - this->addMatrixContrib(m_matrixJ, out, quad[2], ( ( fx ) * ( fy ) )); - } - } + points.push_back ( OutDataTypes::getCPos(out[i]) ); } - // 3D elements - { - const size_t i0 = m_map1d.size() + m_map2d.size(); - const size_t c0 = tetrahedra.size(); - for ( size_t i=0; iaddMatrixContrib(m_matrixJ, out, tetra[0], ( 1-fx-fy-fz )); - this->addMatrixContrib(m_matrixJ, out, tetra[1], fx); - this->addMatrixContrib(m_matrixJ, out, tetra[2], fy); - this->addMatrixContrib(m_matrixJ, out, tetra[3], fz); - } - else - { - const Hexa& cube = cubes[index-c0]; - - this->addMatrixContrib(m_matrixJ, out, cube[0], ( ( 1-fx ) * ( 1-fy ) * ( 1-fz ) )); - this->addMatrixContrib(m_matrixJ, out, cube[1], ( ( fx ) * ( 1-fy ) * ( 1-fz ) )); - - this->addMatrixContrib(m_matrixJ, out, cube[3], ( ( 1-fx ) * ( fy ) * ( 1-fz ) )); - this->addMatrixContrib(m_matrixJ, out, cube[2], ( ( fx ) * ( fy ) * ( 1-fz ) )); + vparams->drawTool()->drawPoints ( points, 7, sofa::defaulttype::Vec<4,float> ( 1,1,0,1 ) ); - this->addMatrixContrib(m_matrixJ, out, cube[4], ( ( 1-fx ) * ( 1-fy ) * ( fz ) )); - this->addMatrixContrib(m_matrixJ, out, cube[5], ( ( fx ) * ( 1-fy ) * ( fz ) )); + // Draw mapping line between models + const InVecCoord& in = this->fromModel->read(core::ConstVecCoordId::position())->getValue(); + if ( m_mapper!=NULL ) + m_mapper->draw(vparams,out,in); - this->addMatrixContrib(m_matrixJ, out, cube[7], ( ( 1-fx ) * ( fy ) * ( fz ) )); - this->addMatrixContrib(m_matrixJ, out, cube[6], ( ( fx ) * ( fy ) * ( fz ) )); - } - } - } - m_matrixJ->compress(); - m_updateJ = false; - return m_matrixJ; } -template -const sofa::defaulttype::BaseMatrix* BarycentricMapperRegularGridTopology::getJ(int outSize, int inSize) -{ - - if (matrixJ && !updateJ) - return matrixJ; - - if (!matrixJ) matrixJ = new MatrixType; - if (matrixJ->rowBSize() != (MatrixTypeIndex)outSize || matrixJ->colBSize() != (MatrixTypeIndex)inSize) - matrixJ->resize(outSize*NOut, inSize*NIn); - else - matrixJ->clear(); - for ( size_t i=0; im_fromTopology->getHexaCopy ( this->m_map[i].in_index ); - - const Real fx = ( Real ) m_map[i].baryCoords[0]; - const Real fy = ( Real ) m_map[i].baryCoords[1]; - const Real fz = ( Real ) m_map[i].baryCoords[2]; - this->addMatrixContrib(matrixJ, out, cube[0], ( ( 1-fx ) * ( 1-fy ) * ( 1-fz ) )); - this->addMatrixContrib(matrixJ, out, cube[1], ( ( fx ) * ( 1-fy ) * ( 1-fz ) )); - - this->addMatrixContrib(matrixJ, out, cube[3], ( ( 1-fx ) * ( fy ) * ( 1-fz ) )); - this->addMatrixContrib(matrixJ, out, cube[2], ( ( fx ) * ( fy ) * ( 1-fz ) )); - - this->addMatrixContrib(matrixJ, out, cube[4], ( ( 1-fx ) * ( 1-fy ) * ( fz ) )); - this->addMatrixContrib(matrixJ, out, cube[5], ( ( fx ) * ( 1-fy ) * ( fz ) )); - - this->addMatrixContrib(matrixJ, out, cube[7], ( ( 1-fx ) * ( fy ) * ( fz ) )); - this->addMatrixContrib(matrixJ, out, cube[6], ( ( fx ) * ( fy ) * ( fz ) )); - } - updateJ = false; - return matrixJ; -} - -template -const sofa::defaulttype::BaseMatrix* BarycentricMapperSparseGridTopology::getJ(int outSize, int inSize) -{ - - if (matrixJ && !updateJ) - return matrixJ; - - if (!matrixJ) matrixJ = new MatrixType; - if (matrixJ->rowBSize() != (MatrixTypeIndex)outSize || matrixJ->colBSize() != (MatrixTypeIndex)inSize) - matrixJ->resize(outSize*NOut, inSize*NIn); - else - matrixJ->clear(); - - for ( size_t i=0; im_fromTopology->getHexahedron ( this->m_map[i].in_index ); - - const Real fx = ( Real ) m_map[i].baryCoords[0]; - const Real fy = ( Real ) m_map[i].baryCoords[1]; - const Real fz = ( Real ) m_map[i].baryCoords[2]; - this->addMatrixContrib(matrixJ, out, cube[0], ( ( 1-fx ) * ( 1-fy ) * ( 1-fz ) )); - this->addMatrixContrib(matrixJ, out, cube[1], ( ( fx ) * ( 1-fy ) * ( 1-fz ) )); - - this->addMatrixContrib(matrixJ, out, cube[3], ( ( 1-fx ) * ( fy ) * ( 1-fz ) )); - this->addMatrixContrib(matrixJ, out, cube[2], ( ( fx ) * ( fy ) * ( 1-fz ) )); - - this->addMatrixContrib(matrixJ, out, cube[4], ( ( 1-fx ) * ( 1-fy ) * ( fz ) )); - this->addMatrixContrib(matrixJ, out, cube[5], ( ( fx ) * ( 1-fy ) * ( fz ) )); - - this->addMatrixContrib(matrixJ, out, cube[7], ( ( 1-fx ) * ( fy ) * ( fz ) )); - this->addMatrixContrib(matrixJ, out, cube[6], ( ( fx ) * ( fy ) * ( fz ) )); - } - matrixJ->compress(); - updateJ = false; - return matrixJ; -} - -template -const sofa::defaulttype::BaseMatrix* BarycentricMapperTopologyContainer::getJ(int outSize, int inSize) -{ - if (m_matrixJ && !m_updateJ) - return m_matrixJ; - - if (!m_matrixJ) m_matrixJ = new MatrixType; - if (m_matrixJ->rowBSize() != (MatrixTypeIndex)outSize || m_matrixJ->colBSize() != (MatrixTypeIndex)inSize) - m_matrixJ->resize(outSize*NOut, inSize*NIn); - else - m_matrixJ->clear(); - - return m_matrixJ; - - const helper::vector& elements = getElements(); - - for( size_t outId=0 ; outIdmaskTo->size() ; ++outId) - { - if( !this->maskTo->getEntry(outId) ) continue; - - const Element& element = elements[d_map.getValue()[outId].in_index]; - - helper::vector baryCoef = getBaryCoef(d_map.getValue()[outId].baryCoords); - for (unsigned int j=0; jaddMatrixContrib(m_matrixJ, outId, element[j], baryCoef[j]); - } - - m_matrixJ->compress(); - m_updateJ = false; - return m_matrixJ; -} - - -/************************************* Draw ***********************************/ - - -template -void BarycentricMapping::draw(const core::visual::VisualParams* vparams) -{ - if ( !vparams->displayFlags().getShowMappings() ) return; - - // Draw model (out) points - const OutVecCoord& out = this->toModel->read(core::ConstVecCoordId::position())->getValue(); - std::vector< Vector3 > points; - for ( unsigned int i=0; idrawTool()->drawPoints ( points, 7, sofa::defaulttype::Vec<4,float> ( 1,1,0,1 ) ); - - // Draw mapping line between models - const InVecCoord& in = this->fromModel->read(core::ConstVecCoordId::position())->getValue(); - if ( m_mapper!=NULL ) - m_mapper->draw(vparams,out,in); - -} - -template -void BarycentricMapperMeshTopology::draw (const core::visual::VisualParams* vparams, - const typename Out::VecCoord& out, - const typename In::VecCoord& in ) -{ - const SeqLines& lines = this->m_fromTopology->getLines(); - const SeqTriangles& triangles = this->m_fromTopology->getTriangles(); - const SeqQuads& quads = this->m_fromTopology->getQuads(); - const SeqTetrahedra& tetrahedra = this->m_fromTopology->getTetrahedra(); - const SeqHexahedra& cubes = this->m_fromTopology->getHexahedra(); - - std::vector< Vector3 > points; - // 1D elements - { - const int i0 = 0; - for ( unsigned int i=0; i=0.0001 ) - { - points.push_back ( Out::getCPos(out[i+i0]) ); - points.push_back ( in[line[j]] ); - } - } - } - } - } - // 2D elements - { - const int i0 = m_map1d.size(); - const int c0 = triangles.size(); - for ( unsigned int i=0; i=0.0001 ) - { - points.push_back ( Out::getCPos(out[i+i0]) ); - points.push_back ( in[triangle[j]] ); - } - } - } - else - { - const Quad& quad = quads[index-c0]; - Real f[4]; - f[0] = ( ( 1-fx ) * ( 1-fy ) ); - f[1] = ( ( fx ) * ( 1-fy ) ); - f[3] = ( ( 1-fx ) * ( fy ) ); - f[2] = ( ( fx ) * ( fy ) ); - for ( int j=0; j<4; j++ ) - { - if ( f[j]<=-0.0001 || f[j]>=0.0001 ) - { - points.push_back ( Out::getCPos(out[i+i0]) ); - points.push_back ( in[quad[j]] ); - } - } - } - } - } - // 3D elements - { - const int i0 = m_map1d.size() +m_map2d.size(); - const int c0 = tetrahedra.size(); - for ( unsigned int i=0; i=0.0001 ) - { - points.push_back ( Out::getCPos(out[i+i0]) ); - points.push_back ( in[tetra[j]] ); - } - } - } - else - { - const Hexa& cube = cubes[index-c0]; - - Real f[8]; - f[0] = ( 1-fx ) * ( 1-fy ) * ( 1-fz ); - f[1] = ( fx ) * ( 1-fy ) * ( 1-fz ); - - f[3] = ( 1-fx ) * ( fy ) * ( 1-fz ); - f[2] = ( fx ) * ( fy ) * ( 1-fz ); - - f[4] = ( 1-fx ) * ( 1-fy ) * ( fz ); - f[5] = ( fx ) * ( 1-fy ) * ( fz ); - - f[7] = ( 1-fx ) * ( fy ) * ( fz ); - f[6] = ( fx ) * ( fy ) * ( fz ); - - for ( int j=0; j<8; j++ ) - { - if ( f[j]<=-0.0001 || f[j]>=0.0001 ) - { - points.push_back ( Out::getCPos(out[i+i0]) ); - points.push_back ( in[cube[j]] ); - } - } - } - } - } - vparams->drawTool()->drawLines ( points, 1, sofa::defaulttype::Vec<4,float> ( 0,1,0,1 ) ); -} - -template -void BarycentricMapperRegularGridTopology::draw (const core::visual::VisualParams* vparams, - const typename Out::VecCoord& out, - const typename In::VecCoord& in ) -{ - std::vector< Vector3 > points; - - for ( unsigned int i=0; im_fromTopology->getHexaCopy ( this->m_map[i].in_index ); - - const Real fx = m_map[i].baryCoords[0]; - const Real fy = m_map[i].baryCoords[1]; - const Real fz = m_map[i].baryCoords[2]; - Real f[8]; - f[0] = ( 1-fx ) * ( 1-fy ) * ( 1-fz ); - f[1] = ( fx ) * ( 1-fy ) * ( 1-fz ); - - f[3] = ( 1-fx ) * ( fy ) * ( 1-fz ); - f[2] = ( fx ) * ( fy ) * ( 1-fz ); - - f[4] = ( 1-fx ) * ( 1-fy ) * ( fz ); - f[5] = ( fx ) * ( 1-fy ) * ( fz ); - - f[7] = ( 1-fx ) * ( fy ) * ( fz ); - f[6] = ( fx ) * ( fy ) * ( fz ); - - for ( int j=0; j<8; j++ ) - { - if ( f[j]<=-0.0001 || f[j]>=0.0001 ) - { - points.push_back ( Out::getCPos(out[i]) ); - points.push_back ( in[cube[j]] ); - } - } - } - vparams->drawTool()->drawLines ( points, 1, sofa::defaulttype::Vec<4,float> ( 0,0,1,1 ) ); - -} - -template -void BarycentricMapperSparseGridTopology::draw (const core::visual::VisualParams* vparams, - const typename Out::VecCoord& out, - const typename In::VecCoord& in ) -{ - std::vector< Vector3 > points; - for ( unsigned int i=0; im_fromTopology->getHexahedron ( this->m_map[i].in_index ); - - const Real fx = m_map[i].baryCoords[0]; - const Real fy = m_map[i].baryCoords[1]; - const Real fz = m_map[i].baryCoords[2]; - Real f[8]; - f[0] = ( 1-fx ) * ( 1-fy ) * ( 1-fz ); - f[1] = ( fx ) * ( 1-fy ) * ( 1-fz ); - - f[3] = ( 1-fx ) * ( fy ) * ( 1-fz ); - f[2] = ( fx ) * ( fy ) * ( 1-fz ); - - f[4] = ( 1-fx ) * ( 1-fy ) * ( fz ); - f[5] = ( fx ) * ( 1-fy ) * ( fz ); - - f[7] = ( 1-fx ) * ( fy ) * ( fz ); - f[6] = ( fx ) * ( fy ) * ( fz ); - - for ( int j=0; j<8; j++ ) - { - if ( f[j]<=-0.0001 || f[j]>=0.0001 ) - { - points.push_back ( Out::getCPos(out[i]) ); - points.push_back ( in[cube[j]] ); - } - } - } - vparams->drawTool()->drawLines ( points, 1, sofa::defaulttype::Vec<4,float> ( 0,0,1,1 ) ); -} - - -template -void BarycentricMapperTopologyContainer::draw (const core::visual::VisualParams* vparams, - const typename Out::VecCoord& out, - const typename In::VecCoord& in ) -{ - // Draw line between mapped node (out) and nodes of nearest element (in) - const helper::vector& elements = getElements(); - - std::vector< Vector3 > points; - { - for ( unsigned int i=0; i baryCoef = getBaryCoef(d_map.getValue()[i].baryCoords); - for ( unsigned int j=0; j=0.0001 ) - { - points.push_back ( Out::getCPos(out[i]) ); - points.push_back ( in[element[j]] ); - } - } - } - } - vparams->drawTool()->drawLines ( points, 1, sofa::defaulttype::Vec<4,float> ( 0,1,0,1 ) ); -} - - -/************************************* PropagateConstraint ***********************************/ - - -template -void BarycentricMapping::applyJT(const core::ConstraintParams * cparams, Data< typename In::MatrixDeriv >& out, const Data< typename Out::MatrixDeriv >& in) -{ - SOFA_UNUSED(cparams); +template +void BarycentricMapping::applyJT(const core::ConstraintParams * cparams, Data< typename In::MatrixDeriv >& out, const Data< typename Out::MatrixDeriv >& in) +{ + SOFA_UNUSED(cparams); if ( #ifdef SOFA_DEV @@ -2108,403 +394,6 @@ void BarycentricMapping::applyJT(const core::ConstraintParams * cpara } } -template -void BarycentricMapperMeshTopology::applyJT ( typename In::MatrixDeriv& out, const typename Out::MatrixDeriv& in ) -{ - const SeqLines& lines = this->m_fromTopology->getLines(); - const SeqTriangles& triangles = this->m_fromTopology->getTriangles(); - const SeqQuads& quads = this->m_fromTopology->getQuads(); - const SeqTetrahedra& tetrahedra = this->m_fromTopology->getTetrahedra(); - const SeqHexahedra& hexas = this->m_fromTopology->getHexahedra(); - - const size_t iTri = triangles.size(); - const size_t iTetra= tetrahedra.size(); - - const size_t i1d = m_map1d.size(); - const size_t i2d = m_map2d.size(); - const size_t i3d = m_map3d.size(); - - size_t indexIn; - - typename Out::MatrixDeriv::RowConstIterator rowItEnd = in.end(); - - for (typename Out::MatrixDeriv::RowConstIterator rowIt = in.begin(); rowIt != rowItEnd; ++rowIt) - { - typename Out::MatrixDeriv::ColConstIterator colItEnd = rowIt.end(); - typename Out::MatrixDeriv::ColConstIterator colIt = rowIt.begin(); - - if (colIt != colItEnd) - { - typename In::MatrixDeriv::RowIterator o = out.writeLine(rowIt.index()); - - for ( ; colIt != colItEnd; ++colIt) - { - indexIn = colIt.index(); - InDeriv data = (InDeriv) Out::getDPos(colIt.val()); - - // 1D elements - if ( indexIn < i1d ) - { - const OutReal fx = ( OutReal ) m_map1d[indexIn].baryCoords[0]; - size_t index = m_map1d[indexIn].in_index; - { - const Line& line = lines[index]; - o.addCol( line[0], data * ( 1-fx ) ); - o.addCol( line[1], data * fx ); - } - } - // 2D elements : triangle or quad - else if ( indexIn < i2d ) - { - const OutReal fx = ( OutReal ) m_map2d[indexIn].baryCoords[0]; - const OutReal fy = ( OutReal ) m_map2d[indexIn].baryCoords[1]; - size_t index = m_map2d[indexIn].in_index; - if ( index < iTri ) // triangle - { - const Triangle& triangle = triangles[index]; - o.addCol( triangle[0], data * ( 1-fx-fy ) ); - o.addCol( triangle[1], data * fx ); - o.addCol( triangle[2], data * fy ); - } - else // quad - { - const Quad& quad = quads[index - iTri]; - o.addCol( quad[0], data * ( ( 1-fx ) * ( 1-fy ) ) ); - o.addCol( quad[1], data * ( ( fx ) * ( 1-fy ) ) ); - o.addCol( quad[3], data * ( ( 1-fx ) * ( fy ) ) ); - o.addCol( quad[2], data * ( ( fx ) * ( fy ) ) ); - } - } - // 3D elements : tetra or hexa - else if ( indexIn < i3d ) - { - const OutReal fx = ( OutReal ) m_map3d[indexIn].baryCoords[0]; - const OutReal fy = ( OutReal ) m_map3d[indexIn].baryCoords[1]; - const OutReal fz = ( OutReal ) m_map3d[indexIn].baryCoords[2]; - size_t index = m_map3d[indexIn].in_index; - if ( index < iTetra ) // tetra - { - const Tetra& tetra = tetrahedra[index]; - o.addCol ( tetra[0], data * ( 1-fx-fy-fz ) ); - o.addCol ( tetra[1], data * fx ); - o.addCol ( tetra[2], data * fy ); - o.addCol ( tetra[3], data * fz ); - } - else // hexa - { - const Hexa& hexa = hexas[index-iTetra]; - - o.addCol ( hexa[0],data * ( ( 1-fx ) * ( 1-fy ) * ( 1-fz ) ) ) ; - o.addCol ( hexa[1],data * ( ( fx ) * ( 1-fy ) * ( 1-fz ) ) ) ; - - o.addCol ( hexa[3],data * ( ( 1-fx ) * ( fy ) * ( 1-fz ) ) ) ; - o.addCol ( hexa[2],data * ( ( fx ) * ( fy ) * ( 1-fz ) ) ) ; - - o.addCol ( hexa[4],data * ( ( 1-fx ) * ( 1-fy ) * ( fz ) ) ) ; - o.addCol ( hexa[5],data * ( ( fx ) * ( 1-fy ) * ( fz ) ) ) ; - - o.addCol ( hexa[7],data * ( ( 1-fx ) * ( fy ) * ( fz ) ) ) ; - o.addCol ( hexa[6],data * ( ( fx ) * ( fy ) * ( fz ) ) ) ; - } - } - } - } - } -} - -template -void BarycentricMapperRegularGridTopology::applyJT ( typename In::MatrixDeriv& out, const typename Out::MatrixDeriv& in ) -{ - typename Out::MatrixDeriv::RowConstIterator rowItEnd = in.end(); - - for (typename Out::MatrixDeriv::RowConstIterator rowIt = in.begin(); rowIt != rowItEnd; ++rowIt) - { - typename Out::MatrixDeriv::ColConstIterator colItEnd = rowIt.end(); - typename Out::MatrixDeriv::ColConstIterator colIt = rowIt.begin(); - - if (colIt != colItEnd) - { - typename In::MatrixDeriv::RowIterator o = out.writeLine(rowIt.index()); - - for ( ; colIt != colItEnd; ++colIt) - { - unsigned int indexIn = colIt.index(); - InDeriv data = (InDeriv) Out::getDPos(colIt.val()); - - - const topology::RegularGridTopology::Hexa cube = this->m_fromTopology->getHexaCopy ( this->m_map[indexIn].in_index ); - - const OutReal fx = (OutReal) m_map[indexIn].baryCoords[0]; - const OutReal fy = (OutReal) m_map[indexIn].baryCoords[1]; - const OutReal fz = (OutReal) m_map[indexIn].baryCoords[2]; - const OutReal oneMinusFx = 1-fx; - const OutReal oneMinusFy = 1-fy; - const OutReal oneMinusFz = 1-fz; - - o.addCol(cube[0], data * ((oneMinusFx) * (oneMinusFy) * (oneMinusFz))); - o.addCol(cube[1], data * ((fx) * (oneMinusFy) * (oneMinusFz))); - - o.addCol(cube[3], data * ((oneMinusFx) * (fy) * (oneMinusFz))); - o.addCol(cube[2], data * ((fx) * (fy) * (oneMinusFz))); - - o.addCol(cube[4], data * ((oneMinusFx) * (oneMinusFy) * (fz))); - o.addCol(cube[5], data * ((fx) * (oneMinusFy) * (fz))); - - o.addCol(cube[7], data * ((oneMinusFx) * (fy) * (fz))); - o.addCol(cube[6], data * ((fx) * (fy) * (fz))); - } - } - } -} - -template -void BarycentricMapperSparseGridTopology::applyJT ( typename In::MatrixDeriv& out, const typename Out::MatrixDeriv& in ) -{ - typename Out::MatrixDeriv::RowConstIterator rowItEnd = in.end(); - - for (typename Out::MatrixDeriv::RowConstIterator rowIt = in.begin(); rowIt != rowItEnd; ++rowIt) - { - typename Out::MatrixDeriv::ColConstIterator colItEnd = rowIt.end(); - typename Out::MatrixDeriv::ColConstIterator colIt = rowIt.begin(); - - if (colIt != colItEnd) - { - typename In::MatrixDeriv::RowIterator o = out.writeLine(rowIt.index()); - - for ( ; colIt != colItEnd; ++colIt) - { - unsigned indexIn = colIt.index(); - InDeriv data = (InDeriv) Out::getDPos(colIt.val()); - - - const topology::SparseGridTopology::Hexa cube = this->m_fromTopology->getHexahedron ( this->m_map[indexIn].in_index ); - - const OutReal fx = ( OutReal ) m_map[indexIn].baryCoords[0]; - const OutReal fy = ( OutReal ) m_map[indexIn].baryCoords[1]; - const OutReal fz = ( OutReal ) m_map[indexIn].baryCoords[2]; - const OutReal oneMinusFx = 1-fx; - const OutReal oneMinusFy = 1-fy; - const OutReal oneMinusFz = 1-fz; - - OutReal f = ( oneMinusFx * oneMinusFy * oneMinusFz ); - o.addCol ( cube[0], ( data * f ) ); - - f = ( ( fx ) * oneMinusFy * oneMinusFz ); - o.addCol ( cube[1], ( data * f ) ); - - - f = ( oneMinusFx * ( fy ) * oneMinusFz ); - o.addCol ( cube[3], ( data * f ) ); - - f = ( ( fx ) * ( fy ) * oneMinusFz ); - o.addCol ( cube[2], ( data * f ) ); - - - f = ( oneMinusFx * oneMinusFy * ( fz ) ); - o.addCol ( cube[4], ( data * f ) ); - - f = ( ( fx ) * oneMinusFy * ( fz ) ); - o.addCol ( cube[5], ( data * f ) ); - - - f = ( oneMinusFx * ( fy ) * ( fz ) ); - o.addCol ( cube[7], ( data * f ) ); - - f = ( ( fx ) * ( fy ) * ( fz ) ); - o.addCol ( cube[6], ( data * f ) ); - } - } - } -} - -template -void BarycentricMapperTopologyContainer::applyJT ( typename In::MatrixDeriv& out, const typename Out::MatrixDeriv& in ) -{ - typename Out::MatrixDeriv::RowConstIterator rowItEnd = in.end(); - const helper::vector< Element >& elements = getElements(); - - for (typename Out::MatrixDeriv::RowConstIterator rowIt = in.begin(); rowIt != rowItEnd; ++rowIt) - { - typename Out::MatrixDeriv::ColConstIterator colItEnd = rowIt.end(); - typename Out::MatrixDeriv::ColConstIterator colIt = rowIt.begin(); - - if (colIt != colItEnd) - { - typename In::MatrixDeriv::RowIterator o = out.writeLine(rowIt.index()); - - for ( ; colIt != colItEnd; ++colIt) - { - unsigned indexIn = colIt.index(); - InDeriv data = (InDeriv) Out::getDPos(colIt.val()); - - const Element& element = elements[d_map.getValue()[indexIn].in_index]; - - helper::vector baryCoef = getBaryCoef(d_map.getValue()[indexIn].baryCoords); - for (unsigned int j=0; j -void BarycentricMapperHexahedronSetTopology::handleTopologyChange(core::topology::Topology* t) -{ - using sofa::core::behavior::MechanicalState; - - if (t != this->m_fromTopology) return; - - if ( this->m_fromTopology->beginChange() == this->m_fromTopology->endChange() ) - return; - - std::list::const_iterator itBegin = this->m_fromTopology->beginChange(); - std::list::const_iterator itEnd = this->m_fromTopology->endChange(); - - for ( std::list::const_iterator changeIt = itBegin; - changeIt != itEnd; ++changeIt ) - { - const core::topology::TopologyChangeType changeType = ( *changeIt )->getChangeType(); - switch ( changeType ) - { - //TODO: implementation of BarycentricMapperHexahedronSetTopology::handleTopologyChange() - case core::topology::ENDING_EVENT: ///< To notify the end for the current sequence of topological change events - { - if(!m_invalidIndex.empty()) - { - helper::vector& mapData = *(d_map.beginEdit()); - - for ( std::set::const_iterator iter = m_invalidIndex.begin(); - iter != m_invalidIndex.end(); ++iter ) - { - const int j = *iter; - if ( mapData[j].in_index == -1 ) // compute new mapping - { - Vector3 coefs; - typename In::Coord pos; - pos[0] = mapData[j].baryCoords[0]; - pos[1] = mapData[j].baryCoords[1]; - pos[2] = mapData[j].baryCoords[2]; - - // find nearest cell and barycentric coords - Real distance = 1e10; - - int index = -1; - // When smoothing a mesh, the element has to be found using the rest position of the point. Then, its position is set using this element. - if( this->toTopology) - { - typedef MechanicalState MechanicalStateT; - MechanicalStateT* mState; - this->toTopology->getContext()->get( mState); - if( !mState) - { - msg_error() << "Can not find mechanical state." ; - } - else - { - const typename MechanicalStateT::VecCoord& xto0 = (mState->read(core::ConstVecCoordId::restPosition())->getValue()); - index = m_fromGeomAlgo->findNearestElementInRestPos ( Out::getCPos(xto0[j]), coefs, distance ); - coefs = m_fromGeomAlgo->computeHexahedronRestBarycentricCoeficients(index, pos); - } - } - else - { - index = m_fromGeomAlgo->findNearestElementInRestPos ( pos, coefs, distance ); - } - - if ( index != -1 ) - { - mapData[j].baryCoords[0] = ( Real ) coefs[0]; - mapData[j].baryCoords[1] = ( Real ) coefs[1]; - mapData[j].baryCoords[2] = ( Real ) coefs[2]; - mapData[j].in_index = index; - } - } - } - - d_map.endEdit(); - m_invalidIndex.clear(); - } - } - break; - case core::topology::POINTSINDICESSWAP: ///< For PointsIndicesSwap. - break; - case core::topology::POINTSADDED: ///< For PointsAdded. - break; - case core::topology::POINTSREMOVED: ///< For PointsRemoved. - break; - case core::topology::POINTSRENUMBERING: ///< For PointsRenumbering. - break; - case core::topology::TRIANGLESADDED: ///< For Triangles Added. - break; - case core::topology::TRIANGLESREMOVED: ///< For Triangles Removed. - break; - case core::topology::HEXAHEDRAADDED: ///< For HexahedraAdded. - { - } - break; - case core::topology::HEXAHEDRAREMOVED: ///< For HexahedraRemoved. - { - const unsigned int nbHexahedra = this->m_fromTopology->getNbHexahedra(); - - const helper::vector &hexahedra = - ( static_cast< const core::topology::HexahedraRemoved *> ( *changeIt ) )->getArray(); - // helper::vector hexahedra(tab); - - for ( unsigned int i=0; igetRestPointPositionInHexahedron ( cubeId, coefs ); - - helper::vector& vectorData = *(d_map.beginEdit()); - vectorData[j].in_index = -1; - vectorData[j].baryCoords[0] = restPos[0]; - vectorData[j].baryCoords[1] = restPos[1]; - vectorData[j].baryCoords[2] = restPos[2]; - d_map.endEdit(); - - m_invalidIndex.insert(j); - } - } - } - - // renumber - unsigned int lastCubeId = nbHexahedra-1; - for ( unsigned int i=0; i& vectorData = *(d_map.beginEdit()); - vectorData[j].in_index = cubeId; - d_map.endEdit(); - } - } - } - } - break; - case core::topology::HEXAHEDRARENUMBERING: ///< For HexahedraRenumbering. - break; - default: - break; - } - } -} template void BarycentricMapping::handleTopologyChange ( core::topology::Topology* t ) diff --git a/SofaKernel/modules/SofaBaseMechanics/CMakeLists.txt b/SofaKernel/modules/SofaBaseMechanics/CMakeLists.txt index 299da67513f..75160436eeb 100644 --- a/SofaKernel/modules/SofaBaseMechanics/CMakeLists.txt +++ b/SofaKernel/modules/SofaBaseMechanics/CMakeLists.txt @@ -2,6 +2,30 @@ cmake_minimum_required(VERSION 3.1) project(SofaBaseMechanics) set(HEADER_FILES + + BarycentricMappers/BarycentricMapper.h + BarycentricMappers/BarycentricMapper.inl + BarycentricMappers/TopologyBarycentricMapper.h + BarycentricMappers/TopologyBarycentricMapper.inl + BarycentricMappers/BarycentricMapperMeshTopology.h + BarycentricMappers/BarycentricMapperMeshTopology.inl + BarycentricMappers/BarycentricMapperRegularGridTopology.h + BarycentricMappers/BarycentricMapperRegularGridTopology.inl + BarycentricMappers/BarycentricMapperSparseGridTopology.h + BarycentricMappers/BarycentricMapperSparseGridTopology.inl + BarycentricMappers/BarycentricMapperTopologyContainer.h + BarycentricMappers/BarycentricMapperTopologyContainer.inl + BarycentricMappers/BarycentricMapperEdgeSetTopology.h + BarycentricMappers/BarycentricMapperEdgeSetTopology.inl + BarycentricMappers/BarycentricMapperTriangleSetTopology.h + BarycentricMappers/BarycentricMapperTriangleSetTopology.inl + BarycentricMappers/BarycentricMapperQuadSetTopology.h + BarycentricMappers/BarycentricMapperQuadSetTopology.inl + BarycentricMappers/BarycentricMapperTetrahedronSetTopology.h + BarycentricMappers/BarycentricMapperTetrahedronSetTopology.inl + BarycentricMappers/BarycentricMapperHexahedronSetTopology.h + BarycentricMappers/BarycentricMapperHexahedronSetTopology.inl + AddMToMatrixFunctor.h BarycentricMapping.h BarycentricMapping.inl @@ -22,6 +46,19 @@ set(HEADER_FILES ) set(SOURCE_FILES + + BarycentricMappers/BarycentricMapper.cpp + BarycentricMappers/TopologyBarycentricMapper.cpp + BarycentricMappers/BarycentricMapperMeshTopology.cpp + BarycentricMappers/BarycentricMapperRegularGridTopology.cpp + BarycentricMappers/BarycentricMapperSparseGridTopology.cpp + BarycentricMappers/BarycentricMapperTopologyContainer.cpp + BarycentricMappers/BarycentricMapperEdgeSetTopology.cpp + BarycentricMappers/BarycentricMapperTriangleSetTopology.cpp + BarycentricMappers/BarycentricMapperQuadSetTopology.cpp + BarycentricMappers/BarycentricMapperTetrahedronSetTopology.cpp + BarycentricMappers/BarycentricMapperHexahedronSetTopology.cpp + BarycentricMapping.cpp DiagonalMass.cpp IdentityMapping.cpp diff --git a/SofaKernel/modules/SofaMeshCollision/BarycentricContactMapper.inl b/SofaKernel/modules/SofaMeshCollision/BarycentricContactMapper.inl index 1911613d5b5..cd937522d70 100644 --- a/SofaKernel/modules/SofaMeshCollision/BarycentricContactMapper.inl +++ b/SofaKernel/modules/SofaMeshCollision/BarycentricContactMapper.inl @@ -23,6 +23,7 @@ #define SOFA_COMPONENT_COLLISION_BARYCENTRICCONTACTMAPPER_INL #include +#include #include #include #include diff --git a/SofaKernel/modules/SofaMeshCollision/SofaMeshCollision_test/BaryMapper_test.cpp b/SofaKernel/modules/SofaMeshCollision/SofaMeshCollision_test/BaryMapper_test.cpp index 2468b975836..952ae8e9ba8 100644 --- a/SofaKernel/modules/SofaMeshCollision/SofaMeshCollision_test/BaryMapper_test.cpp +++ b/SofaKernel/modules/SofaMeshCollision/SofaMeshCollision_test/BaryMapper_test.cpp @@ -22,7 +22,7 @@ #include #include #include -#include +#include namespace sofa { @@ -34,6 +34,7 @@ typedef sofa::simulation::Node::SPtr NodePtr; typedef sofa::component::collision::TriangleModel TriangleModel; typedef sofa::defaulttype::Vec3Types DataTypes; typedef DataTypes::VecCoord VecCoord; + struct BaryMapperTest : public ::testing::Test{ diff --git a/modules/SofaMiscMapping/BarycentricMappingRigid.cpp b/modules/SofaMiscMapping/BarycentricMappingRigid.cpp index f9af3c0371e..e26017bf1da 100644 --- a/modules/SofaMiscMapping/BarycentricMappingRigid.cpp +++ b/modules/SofaMiscMapping/BarycentricMappingRigid.cpp @@ -21,6 +21,18 @@ ******************************************************************************/ #define SOFA_COMPONENT_MAPPING_BARYCENTRICMAPPINGRIGID_CPP #include +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include #include @@ -42,7 +54,7 @@ using namespace sofa::defaulttype; SOFA_DECL_CLASS(BarycentricMappingRigid) // Register in the Factory -int BarycentricMappingRigidClass = core::RegisterObject("") +static int BarycentricMappingRigidClass = core::RegisterObject("") #ifndef SOFA_FLOAT .add< BarycentricMapping< Vec3dTypes, Rigid3dTypes > >() #endif @@ -597,8 +609,6 @@ void BarycentricMapperHexahedronSetTopology; -template class SOFA_MISC_MAPPING_API BarycentricMapper< Vec3dTypes, Rigid3dTypes >; -template class SOFA_MISC_MAPPING_API TopologyBarycentricMapper< Vec3dTypes, Rigid3dTypes >; template class SOFA_MISC_MAPPING_API BarycentricMapperRegularGridTopology< Vec3dTypes, Rigid3dTypes >; template class SOFA_MISC_MAPPING_API BarycentricMapperSparseGridTopology< Vec3dTypes, Rigid3dTypes >; template class SOFA_MISC_MAPPING_API BarycentricMapperMeshTopology< Vec3dTypes, Rigid3dTypes >; @@ -611,8 +621,6 @@ template class SOFA_MISC_MAPPING_API BarycentricMapperHexahedronSetTopology< Vec #endif #ifndef SOFA_DOUBLE template class SOFA_MISC_MAPPING_API BarycentricMapping< Vec3fTypes, Rigid3fTypes >; -template class SOFA_MISC_MAPPING_API BarycentricMapper< Vec3fTypes, Rigid3fTypes >; -template class SOFA_MISC_MAPPING_API TopologyBarycentricMapper< Vec3fTypes, Rigid3fTypes >; template class SOFA_MISC_MAPPING_API BarycentricMapperRegularGridTopology< Vec3fTypes, Rigid3fTypes >; template class SOFA_MISC_MAPPING_API BarycentricMapperSparseGridTopology< Vec3fTypes, Rigid3fTypes >; template class SOFA_MISC_MAPPING_API BarycentricMapperMeshTopology< Vec3fTypes, Rigid3fTypes >; @@ -627,10 +635,6 @@ template class SOFA_MISC_MAPPING_API BarycentricMapperHexahedronSetTopology< Vec #ifndef SOFA_DOUBLE template class SOFA_MISC_MAPPING_API BarycentricMapping< Vec3dTypes, Rigid3fTypes >; template class SOFA_MISC_MAPPING_API BarycentricMapping< Vec3fTypes, Rigid3dTypes >; -template class SOFA_MISC_MAPPING_API BarycentricMapper< Vec3dTypes, Rigid3fTypes >; -template class SOFA_MISC_MAPPING_API BarycentricMapper< Vec3fTypes, Rigid3dTypes >; -template class SOFA_MISC_MAPPING_API TopologyBarycentricMapper< Vec3dTypes, Rigid3fTypes >; -template class SOFA_MISC_MAPPING_API TopologyBarycentricMapper< Vec3fTypes, Rigid3dTypes >; template class SOFA_MISC_MAPPING_API BarycentricMapperRegularGridTopology< Vec3dTypes, Rigid3fTypes >; template class SOFA_MISC_MAPPING_API BarycentricMapperRegularGridTopology< Vec3fTypes, Rigid3dTypes >; template class SOFA_MISC_MAPPING_API BarycentricMapperSparseGridTopology< Vec3dTypes, Rigid3fTypes >; @@ -650,6 +654,43 @@ template class SOFA_MISC_MAPPING_API BarycentricMapperHexahedronSetTopology< Vec #endif #endif + +namespace _topologybarycentricmapper_ { +#ifndef SOFA_FLOAT +template class SOFA_MISC_MAPPING_API TopologyBarycentricMapper< Vec3dTypes, Rigid3dTypes >; +#endif +#ifndef SOFA_DOUBLE +template class SOFA_MISC_MAPPING_API TopologyBarycentricMapper< Vec3fTypes, Rigid3fTypes >; +#endif +#ifndef SOFA_FLOAT +#ifndef SOFA_DOUBLE +template class SOFA_MISC_MAPPING_API TopologyBarycentricMapper< Vec3dTypes, Rigid3fTypes >; +template class SOFA_MISC_MAPPING_API TopologyBarycentricMapper< Vec3fTypes, Rigid3dTypes >; +#endif +#endif +} + +namespace _barycentricmapper_ { +#ifndef SOFA_FLOAT +template class SOFA_MISC_MAPPING_API BarycentricMapper< Vec3dTypes, Rigid3dTypes >; +#endif +#ifndef SOFA_DOUBLE +template class SOFA_MISC_MAPPING_API BarycentricMapper< Vec3fTypes, Rigid3fTypes >; +#endif +#ifndef SOFA_FLOAT +#ifndef SOFA_DOUBLE +template class SOFA_MISC_MAPPING_API BarycentricMapper< Vec3dTypes, Rigid3fTypes >; +template class SOFA_MISC_MAPPING_API BarycentricMapper< Vec3fTypes, Rigid3dTypes >; +#endif +#endif + + + + + +} + + } // namespace mapping } // namespace component diff --git a/modules/SofaMiscMapping/BarycentricMappingRigid.h b/modules/SofaMiscMapping/BarycentricMappingRigid.h index 47c85572e95..936a6e62b32 100644 --- a/modules/SofaMiscMapping/BarycentricMappingRigid.h +++ b/modules/SofaMiscMapping/BarycentricMappingRigid.h @@ -24,6 +24,19 @@ #include "config.h" #include +#include +#include +#include + +#include +#include +#include +#include +#include + +#include +#include +#include #include @@ -134,8 +147,6 @@ class BarycentricMapperTetrahedronSetTopology< sofa::defaulttype::StdVectorTypes #if defined(SOFA_EXTERN_TEMPLATE) && !defined(SOFA_COMPONENT_MAPPING_BARYCENTRICMAPPINGRIGID_CPP) #ifndef SOFA_FLOAT extern template class SOFA_MISC_MAPPING_API BarycentricMapping< defaulttype::Vec3dTypes, defaulttype::Rigid3dTypes >; -extern template class SOFA_MISC_MAPPING_API BarycentricMapper< defaulttype::Vec3dTypes, defaulttype::Rigid3dTypes >; -extern template class SOFA_MISC_MAPPING_API TopologyBarycentricMapper< defaulttype::Vec3dTypes, defaulttype::Rigid3dTypes >; extern template class SOFA_MISC_MAPPING_API BarycentricMapperRegularGridTopology< defaulttype::Vec3dTypes, defaulttype::Rigid3dTypes >; extern template class SOFA_MISC_MAPPING_API BarycentricMapperSparseGridTopology< defaulttype::Vec3dTypes, defaulttype::Rigid3dTypes >; extern template class SOFA_MISC_MAPPING_API BarycentricMapperMeshTopology< defaulttype::Vec3dTypes, defaulttype::Rigid3dTypes >; @@ -148,8 +159,6 @@ extern template class SOFA_MISC_MAPPING_API BarycentricMapperHexahedronSetTopolo #endif #ifndef SOFA_DOUBLE extern template class SOFA_MISC_MAPPING_API BarycentricMapping< defaulttype::Vec3fTypes, defaulttype::Rigid3fTypes >; -extern template class SOFA_MISC_MAPPING_API BarycentricMapper< defaulttype::Vec3fTypes, defaulttype::Rigid3fTypes >; -extern template class SOFA_MISC_MAPPING_API TopologyBarycentricMapper< defaulttype::Vec3fTypes, defaulttype::Rigid3fTypes >; extern template class SOFA_MISC_MAPPING_API BarycentricMapperRegularGridTopology< defaulttype::Vec3fTypes, defaulttype::Rigid3fTypes >; extern template class SOFA_MISC_MAPPING_API BarycentricMapperSparseGridTopology< defaulttype::Vec3fTypes, defaulttype::Rigid3fTypes >; extern template class SOFA_MISC_MAPPING_API BarycentricMapperMeshTopology< defaulttype::Vec3fTypes, defaulttype::Rigid3fTypes >; @@ -164,10 +173,6 @@ extern template class SOFA_MISC_MAPPING_API BarycentricMapperHexahedronSetTopolo #ifndef SOFA_DOUBLE extern template class SOFA_MISC_MAPPING_API BarycentricMapping< defaulttype::Vec3dTypes, defaulttype::Rigid3fTypes >; extern template class SOFA_MISC_MAPPING_API BarycentricMapping< defaulttype::Vec3fTypes, defaulttype::Rigid3dTypes >; -extern template class SOFA_MISC_MAPPING_API BarycentricMapper< defaulttype::Vec3dTypes, defaulttype::Rigid3fTypes >; -extern template class SOFA_MISC_MAPPING_API BarycentricMapper< defaulttype::Vec3fTypes, defaulttype::Rigid3dTypes >; -extern template class SOFA_MISC_MAPPING_API TopologyBarycentricMapper< defaulttype::Vec3dTypes, defaulttype::Rigid3fTypes >; -extern template class SOFA_MISC_MAPPING_API TopologyBarycentricMapper< defaulttype::Vec3fTypes, defaulttype::Rigid3dTypes >; extern template class SOFA_MISC_MAPPING_API BarycentricMapperRegularGridTopology< defaulttype::Vec3dTypes, defaulttype::Rigid3fTypes >; extern template class SOFA_MISC_MAPPING_API BarycentricMapperRegularGridTopology< defaulttype::Vec3fTypes, defaulttype::Rigid3dTypes >; extern template class SOFA_MISC_MAPPING_API BarycentricMapperSparseGridTopology< defaulttype::Vec3dTypes, defaulttype::Rigid3fTypes >; @@ -190,6 +195,36 @@ extern template class SOFA_MISC_MAPPING_API BarycentricMapperHexahedronSetTopolo #endif #endif +namespace _topologybarycentricmapper_ { +#ifndef SOFA_FLOAT +extern template class SOFA_MISC_MAPPING_API TopologyBarycentricMapper< Vec3dTypes, defaulttype::Rigid3dTypes >; +#endif +#ifndef SOFA_DOUBLE +extern template class SOFA_MISC_MAPPING_API TopologyBarycentricMapper< Vec3fTypes, defaulttype::Rigid3fTypes >; +#endif +#ifndef SOFA_FLOAT +#ifndef SOFA_DOUBLE +extern template class SOFA_MISC_MAPPING_API TopologyBarycentricMapper< Vec3dTypes, defaulttype::Rigid3fTypes >; +extern template class SOFA_MISC_MAPPING_API TopologyBarycentricMapper< Vec3fTypes, defaulttype::Rigid3dTypes >; +#endif +#endif +} // namesapce _topologybarycentricmapper_ + +namespace _barycentricmapper_ { +#ifndef SOFA_FLOAT +extern template class SOFA_MISC_MAPPING_API BarycentricMapper< Vec3dTypes, defaulttype::Rigid3dTypes >; +#endif +#ifndef SOFA_DOUBLE +extern template class SOFA_MISC_MAPPING_API BarycentricMapper< Vec3fTypes, defaulttype::Rigid3fTypes >; +#endif +#ifndef SOFA_FLOAT +#ifndef SOFA_DOUBLE +extern template class SOFA_MISC_MAPPING_API BarycentricMapper< Vec3dTypes, defaulttype::Rigid3fTypes >; +extern template class SOFA_MISC_MAPPING_API BarycentricMapper< Vec3fTypes, defaulttype::Rigid3dTypes >; +#endif +#endif +} // namesapce _barycentricmapper_ + } // namespace mapping } // namespace component From 6d91f2ffc066d8b4c85ae92a3256977836736037 Mon Sep 17 00:00:00 2001 From: Damien Marchal Date: Fri, 16 Nov 2018 17:22:54 +0100 Subject: [PATCH 07/15] [SofaBaseMechanics] CLEAN - moves the code in .h into .inl - add #include --- .../BarycentricMappers/BarycentricMapper.h | 1 - .../BarycentricMapperEdgeSetTopology.h | 25 +++-- .../BarycentricMapperEdgeSetTopology.inl | 9 +- .../BarycentricMapperHexahedronSetTopology.h | 55 ++++------- ...BarycentricMapperHexahedronSetTopology.inl | 30 +++++- .../BarycentricMapperMeshTopology.h | 86 +++-------------- .../BarycentricMapperMeshTopology.inl | 92 +++++++++++++++++-- .../BarycentricMapperQuadSetTopology.h | 37 +++----- .../BarycentricMapperQuadSetTopology.inl | 13 +++ .../BarycentricMapperRegularGridTopology.h | 46 ++-------- .../BarycentricMapperRegularGridTopology.inl | 82 +++++++++++++---- .../BarycentricMapperSparseGridTopology.h | 52 +++-------- .../BarycentricMapperSparseGridTopology.inl | 85 ++++++++++++----- .../BarycentricMapperTetrahedronSetTopology.h | 29 ++---- ...arycentricMapperTetrahedronSetTopology.inl | 7 ++ .../BarycentricMapperTopologyContainer.h | 48 ++-------- .../BarycentricMapperTopologyContainer.inl | 51 +++++++++- .../BarycentricMapperTriangleSetTopology.h | 41 +++------ .../BarycentricMapperTriangleSetTopology.inl | 8 ++ .../TopologyBarycentricMapper.h | 23 ++--- .../SofaBaseMechanics/BarycentricMapping.h | 58 ++++-------- .../SofaBaseMechanics/BarycentricMapping.inl | 2 +- 22 files changed, 459 insertions(+), 421 deletions(-) diff --git a/SofaKernel/modules/SofaBaseMechanics/BarycentricMappers/BarycentricMapper.h b/SofaKernel/modules/SofaBaseMechanics/BarycentricMappers/BarycentricMapper.h index 97c7eb36bc9..5f3834d1146 100644 --- a/SofaKernel/modules/SofaBaseMechanics/BarycentricMappers/BarycentricMapper.h +++ b/SofaKernel/modules/SofaBaseMechanics/BarycentricMappers/BarycentricMapper.h @@ -87,7 +87,6 @@ class SOFA_BASE_MECHANICS_API BarycentricMapper : public virtual core::objectmod protected: - void addMatrixContrib(MatrixType* m, int row, int col, Real value); template< int NC, int NP> diff --git a/SofaKernel/modules/SofaBaseMechanics/BarycentricMappers/BarycentricMapperEdgeSetTopology.h b/SofaKernel/modules/SofaBaseMechanics/BarycentricMappers/BarycentricMapperEdgeSetTopology.h index f3d2dc112db..faf62b26693 100644 --- a/SofaKernel/modules/SofaBaseMechanics/BarycentricMappers/BarycentricMapperEdgeSetTopology.h +++ b/SofaKernel/modules/SofaBaseMechanics/BarycentricMappers/BarycentricMapperEdgeSetTopology.h @@ -64,19 +64,8 @@ class SOFA_BASE_MECHANICS_API BarycentricMapperEdgeSetTopology : public Barycent protected: - topology::EdgeSetTopologyContainer* m_fromContainer; - topology::EdgeSetGeometryAlgorithms* m_fromGeomAlgo; - - using Inherit1::d_map; - using Inherit1::m_fromTopology; - using Inherit1::m_matrixJ; - using Inherit1::m_updateJ; - - BarycentricMapperEdgeSetTopology(topology::EdgeSetTopologyContainer* fromTopology, topology::PointSetTopologyContainer* toTopology) - : Inherit1(fromTopology, toTopology), - m_fromContainer(fromTopology), - m_fromGeomAlgo(NULL) - {} + BarycentricMapperEdgeSetTopology(topology::EdgeSetTopologyContainer* fromTopology, + topology::PointSetTopologyContainer* toTopology); virtual ~BarycentricMapperEdgeSetTopology() override {} @@ -87,10 +76,18 @@ class SOFA_BASE_MECHANICS_API BarycentricMapperEdgeSetTopology : public Barycent virtual void computeCenter(Vector3& center, const typename In::VecCoord& in, const Edge& element) override; virtual void computeDistance(double& d, const Vector3& v) override; virtual void addPointInElement(const int elementIndex, const SReal* baryCoords) override; + + topology::EdgeSetTopologyContainer* m_fromContainer; + topology::EdgeSetGeometryAlgorithms* m_fromGeomAlgo; + + using Inherit1::d_map; + using Inherit1::m_fromTopology; + using Inherit1::m_matrixJ; + using Inherit1::m_updateJ; }; -#if defined(SOFA_EXTERN_TEMPLATE) && !defined(SOFA_COMPONENT_MAPPING_BARYCENTRICMAPPEREDGESETTOPOLOGY_CPP) +#if !defined(SOFA_COMPONENT_MAPPING_BARYCENTRICMAPPEREDGESETTOPOLOGY_CPP) #ifndef SOFA_FLOAT extern template class SOFA_BASE_MECHANICS_API BarycentricMapperEdgeSetTopology< Vec3dTypes, Vec3dTypes>; extern template class SOFA_BASE_MECHANICS_API BarycentricMapperEdgeSetTopology< Vec3dTypes, ExtVec3fTypes>; diff --git a/SofaKernel/modules/SofaBaseMechanics/BarycentricMappers/BarycentricMapperEdgeSetTopology.inl b/SofaKernel/modules/SofaBaseMechanics/BarycentricMappers/BarycentricMapperEdgeSetTopology.inl index 03c55e4cee1..eea0071fd1c 100644 --- a/SofaKernel/modules/SofaBaseMechanics/BarycentricMappers/BarycentricMapperEdgeSetTopology.inl +++ b/SofaKernel/modules/SofaBaseMechanics/BarycentricMappers/BarycentricMapperEdgeSetTopology.inl @@ -33,6 +33,14 @@ namespace component namespace mapping { +template +BarycentricMapperEdgeSetTopology::BarycentricMapperEdgeSetTopology(topology::EdgeSetTopologyContainer* fromTopology, + topology::PointSetTopologyContainer* toTopology) + : Inherit1(fromTopology, toTopology), + m_fromContainer(fromTopology), + m_fromGeomAlgo(NULL) +{} + template int BarycentricMapperEdgeSetTopology::addPointInLine ( const int edgeIndex, const SReal* baryCoords ) { @@ -57,7 +65,6 @@ int BarycentricMapperEdgeSetTopology::createPointInLine ( const typename return this->addPointInLine ( edgeIndex, baryCoords ); } - template helper::vector BarycentricMapperEdgeSetTopology::getElements() { diff --git a/SofaKernel/modules/SofaBaseMechanics/BarycentricMappers/BarycentricMapperHexahedronSetTopology.h b/SofaKernel/modules/SofaBaseMechanics/BarycentricMappers/BarycentricMapperHexahedronSetTopology.h index 71036c23c81..2bed0cfbbb3 100644 --- a/SofaKernel/modules/SofaBaseMechanics/BarycentricMappers/BarycentricMapperHexahedronSetTopology.h +++ b/SofaKernel/modules/SofaBaseMechanics/BarycentricMappers/BarycentricMapperHexahedronSetTopology.h @@ -43,38 +43,15 @@ typedef typename sofa::core::topology::BaseMeshTopology::Hexahedron Hexahedron; template class SOFA_BASE_MECHANICS_API BarycentricMapperHexahedronSetTopology : public BarycentricMapperTopologyContainer::MappingData3D,Hexahedron> { + typedef typename BarycentricMapper::MappingData3D MappingData; public: + SOFA_CLASS(SOFA_TEMPLATE2(BarycentricMapperHexahedronSetTopology,In,Out), + SOFA_TEMPLATE4(BarycentricMapperTopologyContainer,In,Out,MappingData,Hexahedron)); - typedef typename BarycentricMapper::MappingData3D MappingData; - SOFA_CLASS(SOFA_TEMPLATE2(BarycentricMapperHexahedronSetTopology,In,Out),SOFA_TEMPLATE4(BarycentricMapperTopologyContainer,In,Out,MappingData,Hexahedron)); typedef typename Inherit1::Real Real; -protected: - - topology::HexahedronSetTopologyContainer* m_fromContainer; - topology::HexahedronSetGeometryAlgorithms* m_fromGeomAlgo; - std::set m_invalidIndex; - - using Inherit1::d_map; - using Inherit1::m_matrixJ; - using Inherit1::m_updateJ; - using Inherit1::m_fromTopology; - - BarycentricMapperHexahedronSetTopology() - : Inherit1(nullptr, nullptr), - m_fromContainer(nullptr), - m_fromGeomAlgo(nullptr) - {} - - BarycentricMapperHexahedronSetTopology(topology::HexahedronSetTopologyContainer* fromTopology, topology::PointSetTopologyContainer* toTopology) - : Inherit1(fromTopology, toTopology), - m_fromContainer(fromTopology), - m_fromGeomAlgo(nullptr) - {} - - virtual ~BarycentricMapperHexahedronSetTopology() override {} - + virtual ~BarycentricMapperHexahedronSetTopology() override ; virtual helper::vector getElements() override; virtual helper::vector getBaryCoef(const Real* f) override; helper::vector getBaryCoef(const Real fx, const Real fy, const Real fz); @@ -83,25 +60,33 @@ class SOFA_BASE_MECHANICS_API BarycentricMapperHexahedronSetTopology : public Ba virtual void computeDistance(double& d, const Vector3& v) override; virtual void addPointInElement(const int elementIndex, const SReal* baryCoords) override; -public: - virtual int addPointInCube(const int index, const SReal* baryCoords) override; virtual int setPointInCube(const int pointIndex, const int cubeIndex, const SReal* baryCoords) override; virtual void applyOnePoint( const unsigned int& hexaId, typename Out::VecCoord& out, const typename In::VecCoord& in) override; virtual void handleTopologyChange(core::topology::Topology* t) override; - void setTopology(topology::HexahedronSetTopologyContainer* topology) - { - m_fromTopology = topology; - m_fromContainer = topology; - } +protected: + BarycentricMapperHexahedronSetTopology(); + BarycentricMapperHexahedronSetTopology(topology::HexahedronSetTopologyContainer* fromTopology, + topology::PointSetTopologyContainer* toTopology); + + void setTopology(topology::HexahedronSetTopologyContainer* topology); + + topology::HexahedronSetTopologyContainer* m_fromContainer {nullptr}; + topology::HexahedronSetGeometryAlgorithms* m_fromGeomAlgo {nullptr}; + std::set m_invalidIndex; + + using Inherit1::d_map; + using Inherit1::m_matrixJ; + using Inherit1::m_updateJ; + using Inherit1::m_fromTopology; }; using sofa::defaulttype::Vec3dTypes; using sofa::defaulttype::Vec3fTypes; using sofa::defaulttype::ExtVec3fTypes; -#if defined(SOFA_EXTERN_TEMPLATE) && !defined(SOFA_COMPONENT_MAPPING_BARYCENTRICMAPPERHEXAHEDRONSETTOPOLOGY_CPP) +#if !defined(SOFA_COMPONENT_MAPPING_BARYCENTRICMAPPERHEXAHEDRONSETTOPOLOGY_CPP) #ifndef SOFA_FLOAT extern template class SOFA_BASE_MECHANICS_API BarycentricMapperHexahedronSetTopology< Vec3dTypes, Vec3dTypes >; extern template class SOFA_BASE_MECHANICS_API BarycentricMapperHexahedronSetTopology< Vec3dTypes, ExtVec3fTypes >; diff --git a/SofaKernel/modules/SofaBaseMechanics/BarycentricMappers/BarycentricMapperHexahedronSetTopology.inl b/SofaKernel/modules/SofaBaseMechanics/BarycentricMappers/BarycentricMapperHexahedronSetTopology.inl index 49f382c66b1..c0db70734eb 100644 --- a/SofaKernel/modules/SofaBaseMechanics/BarycentricMappers/BarycentricMapperHexahedronSetTopology.inl +++ b/SofaKernel/modules/SofaBaseMechanics/BarycentricMappers/BarycentricMapperHexahedronSetTopology.inl @@ -33,6 +33,32 @@ namespace component namespace mapping { +template +BarycentricMapperHexahedronSetTopology::BarycentricMapperHexahedronSetTopology() + : Inherit1(nullptr, nullptr), + m_fromContainer(nullptr), + m_fromGeomAlgo(nullptr) +{} + +template +BarycentricMapperHexahedronSetTopology::BarycentricMapperHexahedronSetTopology(topology::HexahedronSetTopologyContainer* fromTopology, + topology::PointSetTopologyContainer* toTopology) + : Inherit1(fromTopology, toTopology), + m_fromContainer(fromTopology), + m_fromGeomAlgo(nullptr) +{} + +template +BarycentricMapperHexahedronSetTopology::~BarycentricMapperHexahedronSetTopology() +{} + +template +void BarycentricMapperHexahedronSetTopology::setTopology(topology::HexahedronSetTopologyContainer* topology) +{ + m_fromTopology = topology; + m_fromContainer = topology; +} + template int BarycentricMapperHexahedronSetTopology::addPointInCube ( const int cubeIndex, const SReal* baryCoords ) @@ -178,11 +204,11 @@ void BarycentricMapperHexahedronSetTopology::handleTopologyChange(core:: int index = -1; // When smoothing a mesh, the element has to be found using the rest position of the point. Then, its position is set using this element. - if( this->toTopology) + if( this->m_toTopology) { typedef MechanicalState MechanicalStateT; MechanicalStateT* mState; - this->toTopology->getContext()->get( mState); + this->m_toTopology->getContext()->get( mState); if( !mState) { msg_error() << "Can not find mechanical state." ; diff --git a/SofaKernel/modules/SofaBaseMechanics/BarycentricMappers/BarycentricMapperMeshTopology.h b/SofaKernel/modules/SofaBaseMechanics/BarycentricMappers/BarycentricMapperMeshTopology.h index 196b43de4a9..141470580a9 100644 --- a/SofaKernel/modules/SofaBaseMechanics/BarycentricMappers/BarycentricMapperMeshTopology.h +++ b/SofaKernel/modules/SofaBaseMechanics/BarycentricMappers/BarycentricMapperMeshTopology.h @@ -41,7 +41,8 @@ template class SOFA_BASE_MECHANICS_API BarycentricMapperMeshTopology : public TopologyBarycentricMapper { public: - SOFA_CLASS(SOFA_TEMPLATE2(BarycentricMapperMeshTopology,In,Out),SOFA_TEMPLATE2(TopologyBarycentricMapper,In,Out)); + SOFA_CLASS(SOFA_TEMPLATE2(BarycentricMapperMeshTopology,In,Out), + SOFA_TEMPLATE2(TopologyBarycentricMapper,In,Out)); typedef typename Inherit1::Real Real; typedef typename Inherit1::OutReal OutReal; @@ -60,9 +61,7 @@ class SOFA_BASE_MECHANICS_API BarycentricMapperMeshTopology : public TopologyBar typedef typename Inherit1::ForceMask ForceMask; - public: - virtual void clear(int reserve=0) override; virtual void resize( core::State* toModel ) override; virtual int addPointInLine(const int lineIndex, const SReal* baryCoords) override; @@ -85,92 +84,29 @@ class SOFA_BASE_MECHANICS_API BarycentricMapperMeshTopology : public TopologyBar sofa::helper::vector< MappingData3D > const* getMap3d() const { return &m_map3d; } - inline friend std::istream& operator >> ( std::istream& in, BarycentricMapperMeshTopology &b ) - { - unsigned int size_vec; - in >> size_vec; - b.m_map1d.clear(); - MappingData1D value1d; - for (unsigned int i=0; i> value1d; - b.m_map1d.push_back(value1d); - } - - in >> size_vec; - b.m_map2d.clear(); - MappingData2D value2d; - for (unsigned int i=0; i> value2d; - b.m_map2d.push_back(value2d); - } - - in >> size_vec; - b.m_map3d.clear(); - MappingData3D value3d; - for (unsigned int i=0; i> value3d; - b.m_map3d.push_back(value3d); - } - return in; - } - - inline friend std::ostream& operator << ( std::ostream& out, const BarycentricMapperMeshTopology & b ) - { - - out << b.m_map1d.size(); - out << " " ; - out << b.m_map1d; - out << " " ; - out << b.m_map2d.size(); - out << " " ; - out << b.m_map2d; - out << " " ; - out << b.m_map3d.size(); - out << " " ; - out << b.m_map3d; - - return out; - } + friend std::istream& operator >> ( std::istream& in, BarycentricMapperMeshTopology &b ); + friend std::ostream& operator << ( std::ostream& out, const BarycentricMapperMeshTopology & b ); + + virtual ~BarycentricMapperMeshTopology() override ; protected: + BarycentricMapperMeshTopology(core::topology::BaseMeshTopology* fromTopology, + topology::PointSetTopologyContainer* toTopology) ; - void addMatrixContrib(MatrixType* m, int row, int col, Real value) - { - Inherit1::addMatrixContrib(m, row, col, value); - } + void addMatrixContrib(MatrixType* m, int row, int col, Real value); sofa::helper::vector< MappingData1D > m_map1d; sofa::helper::vector< MappingData2D > m_map2d; sofa::helper::vector< MappingData3D > m_map3d; - MatrixType* m_matrixJ; - bool m_updateJ; - - BarycentricMapperMeshTopology(core::topology::BaseMeshTopology* fromTopology, - topology::PointSetTopologyContainer* toTopology) - : TopologyBarycentricMapper(fromTopology, toTopology), - m_matrixJ(NULL), m_updateJ(true) - { - } - - virtual ~BarycentricMapperMeshTopology() override - { - if (m_matrixJ) delete m_matrixJ; - } - - + MatrixType* m_matrixJ {nullptr}; + bool m_updateJ {false}; private: - void clearMap1dAndReserve(int size=0); void clearMap2dAndReserve(int size=0); void clearMap3dAndReserve(int size=0); - }; - using sofa::defaulttype::Vec3dTypes; using sofa::defaulttype::Vec3fTypes; using sofa::defaulttype::ExtVec3fTypes; diff --git a/SofaKernel/modules/SofaBaseMechanics/BarycentricMappers/BarycentricMapperMeshTopology.inl b/SofaKernel/modules/SofaBaseMechanics/BarycentricMappers/BarycentricMapperMeshTopology.inl index d983c6e88e7..828242a6e69 100644 --- a/SofaKernel/modules/SofaBaseMechanics/BarycentricMappers/BarycentricMapperMeshTopology.inl +++ b/SofaKernel/modules/SofaBaseMechanics/BarycentricMappers/BarycentricMapperMeshTopology.inl @@ -23,6 +23,7 @@ #define SOFA_COMPONENT_MAPPING_BARYCENTRICMAPPERMESHTOPOLOGY_INL #include "BarycentricMapperMeshTopology.h" +#include namespace sofa { @@ -41,7 +42,6 @@ using sofa::defaulttype::Matrix3; using sofa::defaulttype::Mat3x3d; using sofa::defaulttype::Vec3d; typedef typename sofa::core::topology::BaseMeshTopology::Edge Edge; -typedef typename sofa::core::topology::BaseMeshTopology::Line Line; typedef typename sofa::core::topology::BaseMeshTopology::Triangle Triangle; typedef typename sofa::core::topology::BaseMeshTopology::Quad Quad; typedef typename sofa::core::topology::BaseMeshTopology::Tetrahedron Tetrahedron; @@ -55,6 +55,27 @@ typedef typename sofa::core::topology::BaseMeshTopology::SeqQuads SeqQuads; typedef typename sofa::core::topology::BaseMeshTopology::SeqTetrahedra SeqTetrahedra; typedef typename sofa::core::topology::BaseMeshTopology::SeqHexahedra SeqHexahedra; +template +BarycentricMapperMeshTopology::BarycentricMapperMeshTopology(core::topology::BaseMeshTopology* fromTopology, + topology::PointSetTopologyContainer* toTopology) + : TopologyBarycentricMapper(fromTopology, toTopology), + m_matrixJ(NULL), m_updateJ(true) +{ +} + +template +BarycentricMapperMeshTopology::~BarycentricMapperMeshTopology() +{ + if (m_matrixJ) + delete m_matrixJ; +} + +template +void BarycentricMapperMeshTopology::addMatrixContrib(MatrixType* m, + int row, int col, Real value) +{ + Inherit1::addMatrixContrib(m, row, col, value); +} template void BarycentricMapperMeshTopology::init ( const typename Out::VecCoord& out, const typename In::VecCoord& in ) @@ -314,7 +335,7 @@ template int BarycentricMapperMeshTopology::createPointInLine ( const typename Out::Coord& p, int lineIndex, const typename In::VecCoord* points ) { SReal baryCoords[1]; - const Line& elem = this->m_fromTopology->getLine ( lineIndex ); + const Edge& elem = this->m_fromTopology->getLine ( lineIndex ); const typename In::Coord p0 = ( *points ) [elem[0]]; const typename In::Coord pA = ( *points ) [elem[1]] - p0; typename In::Coord pos = Out::getCPos(p) - p0; @@ -467,7 +488,7 @@ void BarycentricMapperMeshTopology::applyJT ( typename In::MatrixDeriv& const OutReal fx = ( OutReal ) m_map1d[indexIn].baryCoords[0]; size_t index = m_map1d[indexIn].in_index; { - const Line& line = lines[index]; + const Edge& line = lines[index]; o.addCol( line[0], data * ( 1-fx ) ); o.addCol( line[1], data * fx ); } @@ -552,7 +573,7 @@ void BarycentricMapperMeshTopology::draw (const core::visual::VisualPar const Real fx = m_map1d[i].baryCoords[0]; int index = m_map1d[i].in_index; { - const Line& line = lines[index]; + const Edge& line = lines[index]; Real f[2]; f[0] = ( 1-fx ); f[1] = fx; @@ -666,7 +687,7 @@ void BarycentricMapperMeshTopology::draw (const core::visual::VisualPar } } } -// vparams->drawTool()->drawLines ( points, 1, sofa::defaulttype::Vec<4,float> ( 0,1,0,1 ) ); + vparams->drawTool()->drawLines ( points, 1, sofa::defaulttype::Vec<4,float> ( 0,1,0,1 ) ); } template @@ -698,7 +719,7 @@ const sofa::defaulttype::BaseMatrix* BarycentricMapperMeshTopology::getJ const Real fx = ( Real ) m_map1d[i].baryCoords[0]; size_t index = m_map1d[i].in_index; { - const Line& line = lines[index]; + const Edge& line = lines[index]; this->addMatrixContrib(m_matrixJ, out, line[0], ( 1-fx )); this->addMatrixContrib(m_matrixJ, out, line[1], fx); } @@ -800,7 +821,7 @@ void BarycentricMapperMeshTopology::applyJT ( typename In::VecDeriv& out const OutReal fx = ( OutReal ) m_map1d[i].baryCoords[0]; size_t index = m_map1d[i].in_index; { - const Line& line = lines[index]; + const Edge& line = lines[index]; out[line[0]] += v * ( 1-fx ); out[line[1]] += v * fx; mask.insertEntry(line[0]); @@ -923,7 +944,7 @@ void BarycentricMapperMeshTopology::applyJ ( typename Out::VecDeriv& out const Real fx = m_map1d[i].baryCoords[0]; int index = m_map1d[i].in_index; { - const Line& line = lines[index]; + const Edge& line = lines[index]; Out::setDPos(out[i] , in[line[0]] * ( 1-fx ) + in[line[1]] * fx ); } @@ -1015,7 +1036,7 @@ void BarycentricMapperMeshTopology::apply ( typename Out::VecCoord& out, const Real fx = m_map1d[i].baryCoords[0]; int index = m_map1d[i].in_index; { - const Line& line = lines[index]; + const Edge& line = lines[index]; Out::setCPos(out[i] , in[line[0]] * ( 1-fx ) + in[line[1]] * fx ); } @@ -1085,6 +1106,59 @@ void BarycentricMapperMeshTopology::apply ( typename Out::VecCoord& out, } } +template +std::istream& operator >> ( std::istream& in, BarycentricMapperMeshTopology &b ) +{ + unsigned int size_vec; + in >> size_vec; + b.m_map1d.clear(); + typename BarycentricMapperMeshTopology::MappingData1D value1d; + for (unsigned int i=0; i> value1d; + b.m_map1d.push_back(value1d); + } + + in >> size_vec; + b.m_map2d.clear(); + typename BarycentricMapperMeshTopology::MappingData2D value2d; + for (unsigned int i=0; i> value2d; + b.m_map2d.push_back(value2d); + } + + in >> size_vec; + b.m_map3d.clear(); + typename BarycentricMapperMeshTopology::MappingData3D value3d; + for (unsigned int i=0; i> value3d; + b.m_map3d.push_back(value3d); + } + return in; +} + +template +std::ostream& operator << ( std::ostream& out, const BarycentricMapperMeshTopology & b ) +{ + + out << b.m_map1d.size(); + out << " " ; + out << b.m_map1d; + out << " " ; + out << b.m_map2d.size(); + out << " " ; + out << b.m_map2d; + out << " " ; + out << b.m_map3d.size(); + out << " " ; + out << b.m_map3d; + + return out; +} + + } } } diff --git a/SofaKernel/modules/SofaBaseMechanics/BarycentricMappers/BarycentricMapperQuadSetTopology.h b/SofaKernel/modules/SofaBaseMechanics/BarycentricMappers/BarycentricMapperQuadSetTopology.h index 148aa7b0698..9456cf621f4 100644 --- a/SofaKernel/modules/SofaBaseMechanics/BarycentricMappers/BarycentricMapperQuadSetTopology.h +++ b/SofaKernel/modules/SofaBaseMechanics/BarycentricMappers/BarycentricMapperQuadSetTopology.h @@ -47,27 +47,17 @@ class SOFA_BASE_MECHANICS_API BarycentricMapperQuadSetTopology : public Barycent typedef typename BarycentricMapper::MappingData2D MappingData; public: - - SOFA_CLASS(SOFA_TEMPLATE2(BarycentricMapperQuadSetTopology,In,Out),SOFA_TEMPLATE4(BarycentricMapperTopologyContainer,In,Out,MappingData,Quad)); + SOFA_CLASS(SOFA_TEMPLATE2(BarycentricMapperQuadSetTopology,In,Out), + SOFA_TEMPLATE4(BarycentricMapperTopologyContainer,In,Out,MappingData,Quad)); typedef typename Inherit1::Real Real; -protected: - - topology::QuadSetTopologyContainer* m_fromContainer; - topology::QuadSetGeometryAlgorithms* m_fromGeomAlgo; - - using Inherit1::d_map; - using Inherit1::m_fromTopology; - using Inherit1::m_matrixJ; - using Inherit1::m_updateJ; - - BarycentricMapperQuadSetTopology(topology::QuadSetTopologyContainer* fromTopology, topology::PointSetTopologyContainer* toTopology) - : Inherit1(fromTopology, toTopology), - m_fromContainer(fromTopology), - m_fromGeomAlgo(NULL) - {} + virtual int addPointInQuad(const int index, const SReal* baryCoords) override; + virtual int createPointInQuad(const typename Out::Coord& p, int index, const typename In::VecCoord* points) override; - virtual ~BarycentricMapperQuadSetTopology() {} + virtual ~BarycentricMapperQuadSetTopology(); +protected: + BarycentricMapperQuadSetTopology(topology::QuadSetTopologyContainer* fromTopology, + topology::PointSetTopologyContainer* toTopology); virtual helper::vector getElements() override; virtual helper::vector getBaryCoef(const Real* f) override; @@ -77,10 +67,13 @@ class SOFA_BASE_MECHANICS_API BarycentricMapperQuadSetTopology : public Barycent virtual void computeDistance(double& d, const Vector3& v) override; virtual void addPointInElement(const int elementIndex, const SReal* baryCoords) override; -public: + topology::QuadSetTopologyContainer* m_fromContainer; + topology::QuadSetGeometryAlgorithms* m_fromGeomAlgo; - virtual int addPointInQuad(const int index, const SReal* baryCoords) override; - virtual int createPointInQuad(const typename Out::Coord& p, int index, const typename In::VecCoord* points) override; + using Inherit1::d_map; + using Inherit1::m_fromTopology; + using Inherit1::m_matrixJ; + using Inherit1::m_updateJ; }; @@ -89,7 +82,7 @@ using sofa::defaulttype::Vec3fTypes; using sofa::defaulttype::ExtVec3fTypes; -#if defined(SOFA_EXTERN_TEMPLATE) && !defined(SOFA_COMPONENT_MAPPING_BARYCENTRICMAPPERQUADSETTOPOLOGY_CPP) +#if !defined(SOFA_COMPONENT_MAPPING_BARYCENTRICMAPPERQUADSETTOPOLOGY_CPP) #ifndef SOFA_FLOAT extern template class SOFA_BASE_MECHANICS_API BarycentricMapperQuadSetTopology< Vec3dTypes, Vec3dTypes >; extern template class SOFA_BASE_MECHANICS_API BarycentricMapperQuadSetTopology< Vec3dTypes, ExtVec3fTypes >; diff --git a/SofaKernel/modules/SofaBaseMechanics/BarycentricMappers/BarycentricMapperQuadSetTopology.inl b/SofaKernel/modules/SofaBaseMechanics/BarycentricMappers/BarycentricMapperQuadSetTopology.inl index c4bb0df330d..9cc3c120044 100644 --- a/SofaKernel/modules/SofaBaseMechanics/BarycentricMappers/BarycentricMapperQuadSetTopology.inl +++ b/SofaKernel/modules/SofaBaseMechanics/BarycentricMappers/BarycentricMapperQuadSetTopology.inl @@ -34,6 +34,19 @@ namespace component namespace mapping { +template +BarycentricMapperQuadSetTopology::BarycentricMapperQuadSetTopology(topology::QuadSetTopologyContainer* fromTopology, + topology::PointSetTopologyContainer* toTopology) + : Inherit1(fromTopology, toTopology), + m_fromContainer(fromTopology), + m_fromGeomAlgo(NULL) +{} + +template +BarycentricMapperQuadSetTopology::~BarycentricMapperQuadSetTopology() +{} + + template int BarycentricMapperQuadSetTopology::addPointInQuad ( const int quadIndex, const SReal* baryCoords ) { diff --git a/SofaKernel/modules/SofaBaseMechanics/BarycentricMappers/BarycentricMapperRegularGridTopology.h b/SofaKernel/modules/SofaBaseMechanics/BarycentricMappers/BarycentricMapperRegularGridTopology.h index 1b9eda8f880..4473074d84f 100644 --- a/SofaKernel/modules/SofaBaseMechanics/BarycentricMappers/BarycentricMapperRegularGridTopology.h +++ b/SofaKernel/modules/SofaBaseMechanics/BarycentricMappers/BarycentricMapperRegularGridTopology.h @@ -43,9 +43,7 @@ using topology::PointSetTopologyContainer; template class SOFA_BASE_MECHANICS_API BarycentricMapperRegularGridTopology : public TopologyBarycentricMapper { - public: - SOFA_CLASS(SOFA_TEMPLATE2(BarycentricMapperRegularGridTopology,In,Out),SOFA_TEMPLATE2(TopologyBarycentricMapper,In,Out)); typedef typename Inherit1::Real Real; typedef typename Inherit1::OutReal OutReal; @@ -60,9 +58,8 @@ class SOFA_BASE_MECHANICS_API BarycentricMapperRegularGridTopology : public Topo enum { NIn = Inherit1::NIn }; enum { NOut = Inherit1::NOut }; - public: - + virtual ~BarycentricMapperRegularGridTopology() override; virtual void clear(int reserve=0) override; virtual void resize( core::State* toModel ) override; virtual bool isEmpty() {return this->m_map.size() == 0;} @@ -78,48 +75,25 @@ class SOFA_BASE_MECHANICS_API BarycentricMapperRegularGridTopology : public Topo virtual void applyJT( typename In::MatrixDeriv& out, const typename Out::MatrixDeriv& in ) override; virtual const BaseMatrix* getJ(int outSize, int inSize) override; - inline friend std::istream& operator >> ( std::istream& in, BarycentricMapperRegularGridTopology &b ) - { - in >> b.m_map; - return in; - } - - inline friend std::ostream& operator << ( std::ostream& out, const BarycentricMapperRegularGridTopology & b ) - { - out << b.m_map; - return out; - } + inline friend std::istream& operator >> ( std::istream& in, BarycentricMapperRegularGridTopology &b ); + inline friend std::ostream& operator << ( std::ostream& out, const BarycentricMapperRegularGridTopology & b ); protected: - - void addMatrixContrib(MatrixType* m, int row, int col, Real value) - { - Inherit1::addMatrixContrib(m, row, col, value); - } + BarycentricMapperRegularGridTopology(RegularGridTopology* fromTopology, + PointSetTopologyContainer* toTopology); + void addMatrixContrib(MatrixType* m, int row, int col, Real value); helper::vector m_map; - RegularGridTopology* m_fromTopology; - MatrixType* matrixJ; - bool updateJ; - - BarycentricMapperRegularGridTopology(RegularGridTopology* fromTopology, PointSetTopologyContainer* toTopology) - : Inherit1(fromTopology, toTopology) - , m_fromTopology(fromTopology) - , matrixJ(NULL), updateJ(true) - { - } - - virtual ~BarycentricMapperRegularGridTopology() override - { - if (matrixJ) delete matrixJ; - } + RegularGridTopology* m_fromTopology {nullptr}; + MatrixType* m_matrixJ {nullptr}; + bool m_updateJ {false}; }; using sofa::defaulttype::Vec3dTypes; using sofa::defaulttype::Vec3fTypes; using sofa::defaulttype::ExtVec3fTypes; -#if defined(SOFA_EXTERN_TEMPLATE) && !defined(SOFA_COMPONENT_MAPPING_BARYCENTRICMAPPERREGULARGRIDTOPOLOGY_CPP) +#if !defined(SOFA_COMPONENT_MAPPING_BARYCENTRICMAPPERREGULARGRIDTOPOLOGY_CPP) #ifndef SOFA_FLOAT extern template class SOFA_BASE_MECHANICS_API BarycentricMapperRegularGridTopology< Vec3dTypes, Vec3dTypes >; extern template class SOFA_BASE_MECHANICS_API BarycentricMapperRegularGridTopology< Vec3dTypes, ExtVec3fTypes >; diff --git a/SofaKernel/modules/SofaBaseMechanics/BarycentricMappers/BarycentricMapperRegularGridTopology.inl b/SofaKernel/modules/SofaBaseMechanics/BarycentricMappers/BarycentricMapperRegularGridTopology.inl index 56745ab9100..04740a35021 100644 --- a/SofaKernel/modules/SofaBaseMechanics/BarycentricMappers/BarycentricMapperRegularGridTopology.inl +++ b/SofaKernel/modules/SofaBaseMechanics/BarycentricMappers/BarycentricMapperRegularGridTopology.inl @@ -22,6 +22,8 @@ #ifndef SOFA_COMPONENT_MAPPING_BARYCENTRICMAPPERREGULARGRIDTOPOLOGY_INL #define SOFA_COMPONENT_MAPPING_BARYCENTRICMAPPERREGULARGRIDTOPOLOGY_INL +#include + #include "BarycentricMapperRegularGridTopology.h" namespace sofa @@ -35,10 +37,26 @@ namespace mapping using sofa::defaulttype::Vector3; +template +BarycentricMapperRegularGridTopology::BarycentricMapperRegularGridTopology(RegularGridTopology* fromTopology, + PointSetTopologyContainer* toTopology) + : Inherit1(fromTopology, toTopology) + , m_fromTopology(fromTopology) + , m_matrixJ(NULL), m_updateJ(true) +{ +} + +template +BarycentricMapperRegularGridTopology::~BarycentricMapperRegularGridTopology() +{ + if (m_matrixJ) + delete m_matrixJ; +} + template void BarycentricMapperRegularGridTopology::clear ( int size ) { - updateJ = true; + m_updateJ = true; m_map.clear(); if ( size>0 ) m_map.reserve ( size ); } @@ -60,7 +78,7 @@ void BarycentricMapperRegularGridTopology::init ( const typename Out::Ve { SOFA_UNUSED(in); - updateJ = true; + m_updateJ = true; clear ( (int)out.size() ); if ( m_fromTopology->isVolume() ) @@ -178,14 +196,14 @@ template const sofa::defaulttype::BaseMatrix* BarycentricMapperRegularGridTopology::getJ(int outSize, int inSize) { - if (matrixJ && !updateJ) - return matrixJ; + if (m_matrixJ && !m_updateJ) + return m_matrixJ; - if (!matrixJ) matrixJ = new MatrixType; - if (matrixJ->rowBSize() != (MatrixTypeIndex)outSize || matrixJ->colBSize() != (MatrixTypeIndex)inSize) - matrixJ->resize(outSize*NOut, inSize*NIn); + if (!m_matrixJ) m_matrixJ = new MatrixType; + if (m_matrixJ->rowBSize() != (MatrixTypeIndex)outSize || m_matrixJ->colBSize() != (MatrixTypeIndex)inSize) + m_matrixJ->resize(outSize*NOut, inSize*NIn); else - matrixJ->clear(); + m_matrixJ->clear(); for ( size_t i=0; iaddMatrixContrib(matrixJ, out, cube[0], ( ( 1-fx ) * ( 1-fy ) * ( 1-fz ) )); - this->addMatrixContrib(matrixJ, out, cube[1], ( ( fx ) * ( 1-fy ) * ( 1-fz ) )); + this->addMatrixContrib(m_matrixJ, out, cube[0], ( ( 1-fx ) * ( 1-fy ) * ( 1-fz ) )); + this->addMatrixContrib(m_matrixJ, out, cube[1], ( ( fx ) * ( 1-fy ) * ( 1-fz ) )); - this->addMatrixContrib(matrixJ, out, cube[3], ( ( 1-fx ) * ( fy ) * ( 1-fz ) )); - this->addMatrixContrib(matrixJ, out, cube[2], ( ( fx ) * ( fy ) * ( 1-fz ) )); + this->addMatrixContrib(m_matrixJ, out, cube[3], ( ( 1-fx ) * ( fy ) * ( 1-fz ) )); + this->addMatrixContrib(m_matrixJ, out, cube[2], ( ( fx ) * ( fy ) * ( 1-fz ) )); - this->addMatrixContrib(matrixJ, out, cube[4], ( ( 1-fx ) * ( 1-fy ) * ( fz ) )); - this->addMatrixContrib(matrixJ, out, cube[5], ( ( fx ) * ( 1-fy ) * ( fz ) )); + this->addMatrixContrib(m_matrixJ, out, cube[4], ( ( 1-fx ) * ( 1-fy ) * ( fz ) )); + this->addMatrixContrib(m_matrixJ, out, cube[5], ( ( fx ) * ( 1-fy ) * ( fz ) )); - this->addMatrixContrib(matrixJ, out, cube[7], ( ( 1-fx ) * ( fy ) * ( fz ) )); - this->addMatrixContrib(matrixJ, out, cube[6], ( ( fx ) * ( fy ) * ( fz ) )); + this->addMatrixContrib(m_matrixJ, out, cube[7], ( ( 1-fx ) * ( fy ) * ( fz ) )); + this->addMatrixContrib(m_matrixJ, out, cube[6], ( ( fx ) * ( fy ) * ( fz ) )); } - updateJ = false; - return matrixJ; + m_updateJ = false; + return m_matrixJ; } @@ -251,9 +269,15 @@ void BarycentricMapperRegularGridTopology::draw (const core::visual::Vi } } } -// vparams->drawTool()->drawLines ( points, 1, sofa::defaulttype::Vec<4,float> ( 0,0,1,1 ) ); + vparams->drawTool()->drawLines ( points, 1, sofa::defaulttype::Vec<4,float> ( 0,0,1,1 ) ); } +template +void BarycentricMapperRegularGridTopology::addMatrixContrib(MatrixType* m, + int row, int col, Real value) +{ + Inherit1::addMatrixContrib(m, row, col, value); +} template void BarycentricMapperRegularGridTopology::applyJT ( typename In::MatrixDeriv& out, const typename Out::MatrixDeriv& in ) @@ -299,6 +323,24 @@ void BarycentricMapperRegularGridTopology::applyJT ( typename In::Matrix } } -}}} +template +std::istream& operator >> ( std::istream& in, BarycentricMapperRegularGridTopology &b ) +{ + in >> b.m_map; + return in; +} + +template +std::ostream& operator << ( std::ostream& out, const BarycentricMapperRegularGridTopology & b ) +{ + out << b.m_map; + return out; +} + + + +} +} +} #endif diff --git a/SofaKernel/modules/SofaBaseMechanics/BarycentricMappers/BarycentricMapperSparseGridTopology.h b/SofaKernel/modules/SofaBaseMechanics/BarycentricMappers/BarycentricMapperSparseGridTopology.h index 91aaa409d29..e25b6b352f2 100644 --- a/SofaKernel/modules/SofaBaseMechanics/BarycentricMappers/BarycentricMapperSparseGridTopology.h +++ b/SofaKernel/modules/SofaBaseMechanics/BarycentricMappers/BarycentricMapperSparseGridTopology.h @@ -57,13 +57,13 @@ class SOFA_BASE_MECHANICS_API BarycentricMapperSparseGridTopology : public Topol enum { NOut = Inherit1::NOut }; public: + virtual ~BarycentricMapperSparseGridTopology() override ; - virtual void clear(int reserve=0) override; + virtual void init(const typename Out::VecCoord& out, const typename In::VecCoord& in) override; + virtual void clear(int reserve=0) override; virtual int addPointInCube(const int cubeIndex, const SReal* baryCoords) override; - virtual void init(const typename Out::VecCoord& out, const typename In::VecCoord& in) override; - virtual void apply( typename Out::VecCoord& out, const typename In::VecCoord& in ) override; virtual void applyJ( typename Out::VecDeriv& out, const typename In::VecDeriv& in ) override; virtual void applyJT( typename In::VecDeriv& out, const typename Out::VecDeriv& in ) override; @@ -73,44 +73,19 @@ class SOFA_BASE_MECHANICS_API BarycentricMapperSparseGridTopology : public Topol virtual void draw(const VisualParams*,const typename Out::VecCoord& out, const typename In::VecCoord& in) override; virtual void resize( core::State* toModel ) override; - inline friend std::istream& operator >> ( std::istream& in, BarycentricMapperSparseGridTopology &b ) - { - in >> b.m_map; - return in; - } - - inline friend std::ostream& operator << ( std::ostream& out, const BarycentricMapperSparseGridTopology & b ) - { - out << b.m_map; - return out; - } + inline friend std::istream& operator >> ( std::istream& in, BarycentricMapperSparseGridTopology &b ); + inline friend std::ostream& operator << ( std::ostream& out, const BarycentricMapperSparseGridTopology & b ); protected: - - sofa::helper::vector m_map; - topology::SparseGridTopology* m_fromTopology; - - MatrixType* matrixJ; - bool updateJ; - BarycentricMapperSparseGridTopology(topology::SparseGridTopology* fromTopology, - topology::PointSetTopologyContainer* _toTopology) - : TopologyBarycentricMapper(fromTopology, _toTopology), - m_fromTopology(fromTopology), - matrixJ(NULL), updateJ(true) - { - } - - virtual ~BarycentricMapperSparseGridTopology() override - { - if (matrixJ) delete matrixJ; - } - - void addMatrixContrib(MatrixType* m, int row, int col, Real value) - { - Inherit1::addMatrixContrib(m, row, col, value); - } + topology::PointSetTopologyContainer* _toTopology); + void addMatrixContrib(MatrixType* m, int row, int col, Real value); + + sofa::helper::vector m_map; + topology::SparseGridTopology* m_fromTopology {nullptr}; + MatrixType* m_matrixJ {nullptr}; + bool m_updateJ {false}; }; @@ -118,8 +93,7 @@ using sofa::defaulttype::Vec3dTypes; using sofa::defaulttype::Vec3fTypes; using sofa::defaulttype::ExtVec3fTypes; - -#if defined(SOFA_EXTERN_TEMPLATE) && !defined(SOFA_COMPONENT_MAPPING_BARYCENTRICMAPPERSPARSEGRIDTOPOLOGY_CPP) +#if !defined(SOFA_COMPONENT_MAPPING_BARYCENTRICMAPPERSPARSEGRIDTOPOLOGY_CPP) #ifndef SOFA_FLOAT extern template class SOFA_BASE_MECHANICS_API BarycentricMapperSparseGridTopology< Vec3dTypes, Vec3dTypes >; extern template class SOFA_BASE_MECHANICS_API BarycentricMapperSparseGridTopology< Vec3dTypes, ExtVec3fTypes >; diff --git a/SofaKernel/modules/SofaBaseMechanics/BarycentricMappers/BarycentricMapperSparseGridTopology.inl b/SofaKernel/modules/SofaBaseMechanics/BarycentricMappers/BarycentricMapperSparseGridTopology.inl index 44354214100..50e4edf5499 100644 --- a/SofaKernel/modules/SofaBaseMechanics/BarycentricMappers/BarycentricMapperSparseGridTopology.inl +++ b/SofaKernel/modules/SofaBaseMechanics/BarycentricMappers/BarycentricMapperSparseGridTopology.inl @@ -22,7 +22,7 @@ #ifndef SOFA_COMPONENT_MAPPING_BARYCENTRICMAPPERSPARSEGRIDTOPOLOGY_INL #define SOFA_COMPONENT_MAPPING_BARYCENTRICMAPPERSPARSEGRIDTOPOLOGY_INL #include "BarycentricMapperSparseGridTopology.h" - +#include namespace sofa { @@ -36,11 +36,35 @@ using sofa::defaulttype::Vector3; using sofa::core::visual::VisualParams; using sofa::defaulttype::Vec; +template +BarycentricMapperSparseGridTopology::BarycentricMapperSparseGridTopology(topology::SparseGridTopology* fromTopology, + topology::PointSetTopologyContainer* _toTopology) + : TopologyBarycentricMapper(fromTopology, _toTopology), + m_fromTopology(fromTopology), + m_matrixJ(NULL), m_updateJ(true) +{ +} + +template +BarycentricMapperSparseGridTopology::~BarycentricMapperSparseGridTopology() +{ + if (m_matrixJ) + delete m_matrixJ; +} + +template +void BarycentricMapperSparseGridTopology::addMatrixContrib(MatrixType* m, + int row, int col, Real value) +{ + Inherit1::addMatrixContrib(m, row, col, value); +} + + template void BarycentricMapperSparseGridTopology::clear ( int size ) { - updateJ = true; + m_updateJ = true; m_map.clear(); if ( size>0 ) m_map.reserve ( size ); } @@ -70,7 +94,7 @@ template void BarycentricMapperSparseGridTopology::init ( const typename Out::VecCoord& out, const typename In::VecCoord& /*in*/ ) { if ( this->m_map.size() != 0 ) return; - updateJ = true; + m_updateJ = true; clear ( (int)out.size() ); if ( m_fromTopology->isVolume() ) @@ -126,21 +150,21 @@ void BarycentricMapperSparseGridTopology::draw (const VisualParams* vpa } } } -// vparams->drawTool()->drawLines ( points, 1, Vec<4,float> ( 0,0,1,1 ) ); + vparams->drawTool()->drawLines ( points, 1, Vec<4,float> ( 0,0,1,1 ) ); } template const sofa::defaulttype::BaseMatrix* BarycentricMapperSparseGridTopology::getJ(int outSize, int inSize) { - if (matrixJ && !updateJ) - return matrixJ; + if (m_matrixJ && !m_updateJ) + return m_matrixJ; - if (!matrixJ) matrixJ = new MatrixType; - if (matrixJ->rowBSize() != (MatrixTypeIndex)outSize || matrixJ->colBSize() != (MatrixTypeIndex)inSize) - matrixJ->resize(outSize*NOut, inSize*NIn); + if (!m_matrixJ) m_matrixJ = new MatrixType; + if (m_matrixJ->rowBSize() != (MatrixTypeIndex)outSize || m_matrixJ->colBSize() != (MatrixTypeIndex)inSize) + m_matrixJ->resize(outSize*NOut, inSize*NIn); else - matrixJ->clear(); + m_matrixJ->clear(); for ( size_t i=0; i const Real fx = ( Real ) m_map[i].baryCoords[0]; const Real fy = ( Real ) m_map[i].baryCoords[1]; const Real fz = ( Real ) m_map[i].baryCoords[2]; - this->addMatrixContrib(matrixJ, out, cube[0], ( ( 1-fx ) * ( 1-fy ) * ( 1-fz ) )); - this->addMatrixContrib(matrixJ, out, cube[1], ( ( fx ) * ( 1-fy ) * ( 1-fz ) )); + this->addMatrixContrib(m_matrixJ, out, cube[0], ( ( 1-fx ) * ( 1-fy ) * ( 1-fz ) )); + this->addMatrixContrib(m_matrixJ, out, cube[1], ( ( fx ) * ( 1-fy ) * ( 1-fz ) )); - this->addMatrixContrib(matrixJ, out, cube[3], ( ( 1-fx ) * ( fy ) * ( 1-fz ) )); - this->addMatrixContrib(matrixJ, out, cube[2], ( ( fx ) * ( fy ) * ( 1-fz ) )); + this->addMatrixContrib(m_matrixJ, out, cube[3], ( ( 1-fx ) * ( fy ) * ( 1-fz ) )); + this->addMatrixContrib(m_matrixJ, out, cube[2], ( ( fx ) * ( fy ) * ( 1-fz ) )); - this->addMatrixContrib(matrixJ, out, cube[4], ( ( 1-fx ) * ( 1-fy ) * ( fz ) )); - this->addMatrixContrib(matrixJ, out, cube[5], ( ( fx ) * ( 1-fy ) * ( fz ) )); + this->addMatrixContrib(m_matrixJ, out, cube[4], ( ( 1-fx ) * ( 1-fy ) * ( fz ) )); + this->addMatrixContrib(m_matrixJ, out, cube[5], ( ( fx ) * ( 1-fy ) * ( fz ) )); - this->addMatrixContrib(matrixJ, out, cube[7], ( ( 1-fx ) * ( fy ) * ( fz ) )); - this->addMatrixContrib(matrixJ, out, cube[6], ( ( fx ) * ( fy ) * ( fz ) )); + this->addMatrixContrib(m_matrixJ, out, cube[7], ( ( 1-fx ) * ( fy ) * ( fz ) )); + this->addMatrixContrib(m_matrixJ, out, cube[6], ( ( fx ) * ( fy ) * ( fz ) )); } - matrixJ->compress(); - updateJ = false; - return matrixJ; + m_matrixJ->compress(); + m_updateJ = false; + return m_matrixJ; } @@ -333,6 +357,23 @@ void BarycentricMapperSparseGridTopology::apply ( typename Out::VecCoord } -}}} + +template +std::istream& operator >> ( std::istream& in, BarycentricMapperSparseGridTopology &b ) +{ + in >> b.m_map; + return in; +} + +template +std::ostream& operator << ( std::ostream& out, const BarycentricMapperSparseGridTopology & b ) +{ + out << b.m_map; + return out; +} + +} // namespace mapping +} // namespace component +} // namespace sofa #endif diff --git a/SofaKernel/modules/SofaBaseMechanics/BarycentricMappers/BarycentricMapperTetrahedronSetTopology.h b/SofaKernel/modules/SofaBaseMechanics/BarycentricMappers/BarycentricMapperTetrahedronSetTopology.h index a14377d78a1..53bffae15e8 100644 --- a/SofaKernel/modules/SofaBaseMechanics/BarycentricMappers/BarycentricMapperTetrahedronSetTopology.h +++ b/SofaKernel/modules/SofaBaseMechanics/BarycentricMappers/BarycentricMapperTetrahedronSetTopology.h @@ -48,28 +48,15 @@ class SOFA_BASE_MECHANICS_API BarycentricMapperTetrahedronSetTopology : public B typedef typename BarycentricMapper::MappingData3D MappingData; public: - SOFA_CLASS(SOFA_TEMPLATE2(BarycentricMapperTetrahedronSetTopology,In,Out),SOFA_TEMPLATE4(BarycentricMapperTopologyContainer,In,Out,MappingData,Tetrahedron)); typedef typename Inherit1::Real Real; typedef typename In::VecCoord VecCoord; + virtual int addPointInTetra(const int index, const SReal* baryCoords) override ; protected: - - topology::TetrahedronSetTopologyContainer* m_fromContainer; - topology::TetrahedronSetGeometryAlgorithms* m_fromGeomAlgo; - - using Inherit1::d_map; - using Inherit1::m_fromTopology; - using Inherit1::m_matrixJ; - using Inherit1::m_updateJ; - - BarycentricMapperTetrahedronSetTopology(topology::TetrahedronSetTopologyContainer* fromTopology, topology::PointSetTopologyContainer* toTopology) - : Inherit1(fromTopology, toTopology), - m_fromContainer(fromTopology), - m_fromGeomAlgo(NULL) - {} - + BarycentricMapperTetrahedronSetTopology(topology::TetrahedronSetTopologyContainer* fromTopology, + topology::PointSetTopologyContainer* toTopology); virtual ~BarycentricMapperTetrahedronSetTopology() override {} virtual helper::vector getElements() override; @@ -80,9 +67,13 @@ class SOFA_BASE_MECHANICS_API BarycentricMapperTetrahedronSetTopology : public B virtual void computeDistance(double& d, const Vector3& v) override; virtual void addPointInElement(const int elementIndex, const SReal* baryCoords) override; -public: + topology::TetrahedronSetTopologyContainer* m_fromContainer {nullptr}; + topology::TetrahedronSetGeometryAlgorithms* m_fromGeomAlgo {nullptr}; - virtual int addPointInTetra(const int index, const SReal* baryCoords) override ; + using Inherit1::d_map; + using Inherit1::m_fromTopology; + using Inherit1::m_matrixJ; + using Inherit1::m_updateJ; }; @@ -91,7 +82,7 @@ using sofa::defaulttype::Vec3fTypes; using sofa::defaulttype::ExtVec3fTypes; -#if defined(SOFA_EXTERN_TEMPLATE) && !defined(SOFA_COMPONENT_MAPPING_BARYCENTRICMAPPERTETRAHEDRONSETTOPOLOGY_CPP) +#if !defined(SOFA_COMPONENT_MAPPING_BARYCENTRICMAPPERTETRAHEDRONSETTOPOLOGY_CPP) #ifndef SOFA_FLOAT extern template class SOFA_BASE_MECHANICS_API BarycentricMapperTetrahedronSetTopology< Vec3dTypes, Vec3dTypes >; extern template class SOFA_BASE_MECHANICS_API BarycentricMapperTetrahedronSetTopology< Vec3dTypes, ExtVec3fTypes >; diff --git a/SofaKernel/modules/SofaBaseMechanics/BarycentricMappers/BarycentricMapperTetrahedronSetTopology.inl b/SofaKernel/modules/SofaBaseMechanics/BarycentricMappers/BarycentricMapperTetrahedronSetTopology.inl index 8755a71db81..27cd65ffd43 100644 --- a/SofaKernel/modules/SofaBaseMechanics/BarycentricMappers/BarycentricMapperTetrahedronSetTopology.inl +++ b/SofaKernel/modules/SofaBaseMechanics/BarycentricMappers/BarycentricMapperTetrahedronSetTopology.inl @@ -33,6 +33,13 @@ namespace component namespace mapping { +template +BarycentricMapperTetrahedronSetTopology::BarycentricMapperTetrahedronSetTopology(topology::TetrahedronSetTopologyContainer* fromTopology, topology::PointSetTopologyContainer* toTopology) + : Inherit1(fromTopology, toTopology), + m_fromContainer(fromTopology), + m_fromGeomAlgo(NULL) +{} + template int BarycentricMapperTetrahedronSetTopology::addPointInTetra ( const int tetraIndex, const SReal* baryCoords ) diff --git a/SofaKernel/modules/SofaBaseMechanics/BarycentricMappers/BarycentricMapperTopologyContainer.h b/SofaKernel/modules/SofaBaseMechanics/BarycentricMappers/BarycentricMapperTopologyContainer.h index c0f2dfd17c4..d9120f7ac0d 100644 --- a/SofaKernel/modules/SofaBaseMechanics/BarycentricMappers/BarycentricMapperTopologyContainer.h +++ b/SofaKernel/modules/SofaBaseMechanics/BarycentricMappers/BarycentricMapperTopologyContainer.h @@ -76,52 +76,15 @@ class SOFA_BASE_MECHANICS_API BarycentricMapperTopologyContainer : public Topolo virtual void applyJT( typename In::MatrixDeriv& out, const typename Out::MatrixDeriv& in ) override; virtual const sofa::defaulttype::BaseMatrix* getJ(int outSize, int inSize) override; - inline friend std::istream& operator >> ( std::istream& in, BarycentricMapperTopologyContainer &b ) - { - unsigned int size_vec; - - in >> size_vec; - sofa::helper::vector& m = *(b.d_map.beginEdit()); - m.clear(); - - MappingDataType value; - for (unsigned int i=0; i> value; - m.push_back(value); - } - b.d_map.endEdit(); - return in; - } - - inline friend std::ostream& operator << ( std::ostream& out, const BarycentricMapperTopologyContainer & b ) - { - - out << b.d_map.getValue().size(); - out << " " ; - out << b.d_map; - - return out; - } + inline friend std::istream& operator >> ( std::istream& in, BarycentricMapperTopologyContainer &b ); + inline friend std::ostream& operator << ( std::ostream& out, const BarycentricMapperTopologyContainer & b ); bool isEmpty(); protected: - topology::PointData< helper::vector > d_map; - MatrixType* m_matrixJ; - bool m_updateJ; - - BarycentricMapperTopologyContainer(core::topology::BaseMeshTopology* fromTopology, topology::PointSetTopologyContainer* toTopology) - : Inherit1(fromTopology, toTopology), - d_map(initData(&d_map,"map", "mapper data")), - m_matrixJ(NULL), - m_updateJ(true) - {} - + BarycentricMapperTopologyContainer(core::topology::BaseMeshTopology* fromTopology, topology::PointSetTopologyContainer* toTopology); virtual ~BarycentricMapperTopologyContainer() override {} -protected: - virtual helper::vector getElements()=0; virtual helper::vector getBaryCoef(const Real* f)=0; virtual void computeBase(Mat3x3d& base, const typename In::VecCoord& in, const Element& element)=0; @@ -129,6 +92,9 @@ class SOFA_BASE_MECHANICS_API BarycentricMapperTopologyContainer : public Topolo virtual void addPointInElement(const int elementIndex, const SReal* baryCoords)=0; virtual void computeDistance(double& d, const Vector3& v)=0; + topology::PointData< helper::vector > d_map; + MatrixType* m_matrixJ {nullptr}; + bool m_updateJ {nullptr}; }; @@ -142,7 +108,7 @@ typedef typename sofa::core::topology::BaseMeshTopology::Tetrahedron Tetrahedron typedef typename sofa::core::topology::BaseMeshTopology::Hexahedron Hexahedron; -#if defined(SOFA_EXTERN_TEMPLATE) && !defined(SOFA_COMPONENT_MAPPING_BARYCENTRICMAPPERTOPOLOGYCONTAINER_CPP) +#if !defined(SOFA_COMPONENT_MAPPING_BARYCENTRICMAPPERTOPOLOGYCONTAINER_CPP) #ifndef SOFA_FLOAT extern template class SOFA_BASE_MECHANICS_API BarycentricMapperTopologyContainer< Vec3dTypes, Vec3dTypes , typename BarycentricMapper::MappingData1D, Edge>; extern template class SOFA_BASE_MECHANICS_API BarycentricMapperTopologyContainer< Vec3dTypes, ExtVec3fTypes , typename BarycentricMapper::MappingData1D, Edge>; diff --git a/SofaKernel/modules/SofaBaseMechanics/BarycentricMappers/BarycentricMapperTopologyContainer.inl b/SofaKernel/modules/SofaBaseMechanics/BarycentricMappers/BarycentricMapperTopologyContainer.inl index 5b4cac8dc0a..42950fbe93b 100644 --- a/SofaKernel/modules/SofaBaseMechanics/BarycentricMappers/BarycentricMapperTopologyContainer.inl +++ b/SofaKernel/modules/SofaBaseMechanics/BarycentricMappers/BarycentricMapperTopologyContainer.inl @@ -21,6 +21,8 @@ ******************************************************************************/ #ifndef SOFA_COMPONENT_MAPPING_BARYCENTRICMAPPERTOPOLOGYCONTAINER_INL #define SOFA_COMPONENT_MAPPING_BARYCENTRICMAPPERTOPOLOGYCONTAINER_INL +#include + #include "BarycentricMapperTopologyContainer.h" namespace sofa @@ -37,6 +39,17 @@ namespace _barycentricmappertopologycontainer_ using defaulttype::Vec3d; +template +BarycentricMapperTopologyContainer::BarycentricMapperTopologyContainer(core::topology::BaseMeshTopology* fromTopology, + topology::PointSetTopologyContainer* toTopology) + : Inherit1(fromTopology, toTopology), + d_map(initData(&d_map,"map", "mapper data")), + m_matrixJ(NULL), + m_updateJ(true) + {} + + + template void BarycentricMapperTopologyContainer::clear(int size) { @@ -270,9 +283,43 @@ void BarycentricMapperTopologyContainer::draw ( } } } - //vparams->drawTool()->drawLines ( points, 1, sofa::defaulttype::Vec<4,float> ( 0,1,0,1 ) ); + vparams->drawTool()->drawLines ( points, 1, sofa::defaulttype::Vec<4,float> ( 0,1,0,1 ) ); } -}}}} +template +std::istream& operator >> ( std::istream& in, BarycentricMapperTopologyContainer &b ) +{ + unsigned int size_vec; + + in >> size_vec; + sofa::helper::vector& m = *(b.d_map.beginEdit()); + m.clear(); + + MappingData value; + for (unsigned int i=0; i> value; + m.push_back(value); + } + b.d_map.endEdit(); + return in; +} + +template +std::ostream& operator << ( std::ostream& out, const BarycentricMapperTopologyContainer & b ) +{ + out << b.d_map.getValue().size(); + out << " " ; + out << b.d_map; + + return out; +} + + + +} +} // +} // +} // #endif diff --git a/SofaKernel/modules/SofaBaseMechanics/BarycentricMappers/BarycentricMapperTriangleSetTopology.h b/SofaKernel/modules/SofaBaseMechanics/BarycentricMappers/BarycentricMapperTriangleSetTopology.h index d5d34a82e11..d05acad41a6 100644 --- a/SofaKernel/modules/SofaBaseMechanics/BarycentricMappers/BarycentricMapperTriangleSetTopology.h +++ b/SofaKernel/modules/SofaBaseMechanics/BarycentricMappers/BarycentricMapperTriangleSetTopology.h @@ -46,26 +46,21 @@ class SOFA_BASE_MECHANICS_API BarycentricMapperTriangleSetTopology : public Bary { typedef typename BarycentricMapper::MappingData2D MappingData; public: - SOFA_CLASS(SOFA_TEMPLATE2(BarycentricMapperTriangleSetTopology,In,Out),SOFA_TEMPLATE4(BarycentricMapperTopologyContainer,In,Out,MappingData,Triangle)); + SOFA_CLASS(SOFA_TEMPLATE2(BarycentricMapperTriangleSetTopology,In,Out), + SOFA_TEMPLATE4(BarycentricMapperTopologyContainer,In,Out,MappingData,Triangle)); typedef typename Inherit1::Real Real; -protected: - topology::TriangleSetTopologyContainer* m_fromContainer; - topology::TriangleSetGeometryAlgorithms* m_fromGeomAlgo; - - using Inherit1::d_map; - using Inherit1::m_fromTopology; - using Inherit1::m_matrixJ; - using Inherit1::m_updateJ; + virtual ~BarycentricMapperTriangleSetTopology() {} - BarycentricMapperTriangleSetTopology(topology::TriangleSetTopologyContainer* fromTopology, topology::PointSetTopologyContainer* toTopology) - : Inherit1(fromTopology, toTopology), - m_fromContainer(fromTopology), - m_fromGeomAlgo(NULL) - {} + virtual int addPointInTriangle(const int triangleIndex, const SReal* baryCoords) override; + int createPointInTriangle(const typename Out::Coord& p, int triangleIndex, const typename In::VecCoord* points) override; - virtual ~BarycentricMapperTriangleSetTopology() {} +protected: + BarycentricMapperTriangleSetTopology(topology::TriangleSetTopologyContainer* fromTopology, + topology::PointSetTopologyContainer* toTopology); + topology::TriangleSetTopologyContainer* m_fromContainer; + topology::TriangleSetGeometryAlgorithms* m_fromGeomAlgo; virtual helper::vector getElements() override; virtual helper::vector getBaryCoef(const Real* f) override; @@ -75,15 +70,10 @@ class SOFA_BASE_MECHANICS_API BarycentricMapperTriangleSetTopology : public Bary virtual void computeDistance(double& d, const Vector3& v) override; virtual void addPointInElement(const int elementIndex, const SReal* baryCoords) override; -public: - - virtual int addPointInTriangle(const int triangleIndex, const SReal* baryCoords) override; - int createPointInTriangle(const typename Out::Coord& p, int triangleIndex, const typename In::VecCoord* points) override; - -#ifdef BARYCENTRIC_MAPPER_TOPOCHANGE_REINIT - // handle topology changes in the From topology - virtual void handleTopologyChange(core::topology::Topology* t); -#endif // BARYCENTRIC_MAPPER_TOPOCHANGE_REINIT + using Inherit1::d_map; + using Inherit1::m_fromTopology; + using Inherit1::m_matrixJ; + using Inherit1::m_updateJ; }; @@ -91,8 +81,7 @@ using sofa::defaulttype::Vec3dTypes; using sofa::defaulttype::Vec3fTypes; using sofa::defaulttype::ExtVec3fTypes; - -#if defined(SOFA_EXTERN_TEMPLATE) && !defined(SOFA_COMPONENT_MAPPING_BARYCENTRICMAPPERTRIANGLESETTOPOLOGY_CPP) +#if !defined(SOFA_COMPONENT_MAPPING_BARYCENTRICMAPPERTRIANGLESETTOPOLOGY_CPP) #ifndef SOFA_FLOAT extern template class SOFA_BASE_MECHANICS_API BarycentricMapperTriangleSetTopology< Vec3dTypes, Vec3dTypes >; extern template class SOFA_BASE_MECHANICS_API BarycentricMapperTriangleSetTopology< Vec3dTypes, ExtVec3fTypes >; diff --git a/SofaKernel/modules/SofaBaseMechanics/BarycentricMappers/BarycentricMapperTriangleSetTopology.inl b/SofaKernel/modules/SofaBaseMechanics/BarycentricMappers/BarycentricMapperTriangleSetTopology.inl index 24aaf78b08c..b892efea1ef 100644 --- a/SofaKernel/modules/SofaBaseMechanics/BarycentricMappers/BarycentricMapperTriangleSetTopology.inl +++ b/SofaKernel/modules/SofaBaseMechanics/BarycentricMappers/BarycentricMapperTriangleSetTopology.inl @@ -33,6 +33,14 @@ namespace component namespace mapping { +template +BarycentricMapperTriangleSetTopology::BarycentricMapperTriangleSetTopology(topology::TriangleSetTopologyContainer* fromTopology, + topology::PointSetTopologyContainer* toTopology) + : Inherit1(fromTopology, toTopology), + m_fromContainer(fromTopology), + m_fromGeomAlgo(NULL) +{} + template int BarycentricMapperTriangleSetTopology::addPointInTriangle ( const int triangleIndex, const SReal* baryCoords ) diff --git a/SofaKernel/modules/SofaBaseMechanics/BarycentricMappers/TopologyBarycentricMapper.h b/SofaKernel/modules/SofaBaseMechanics/BarycentricMappers/TopologyBarycentricMapper.h index 4e5ebaf2759..3d2b7570d9f 100644 --- a/SofaKernel/modules/SofaBaseMechanics/BarycentricMappers/TopologyBarycentricMapper.h +++ b/SofaKernel/modules/SofaBaseMechanics/BarycentricMappers/TopologyBarycentricMapper.h @@ -40,10 +40,9 @@ namespace _topologybarycentricmapper_ template class SOFA_BASE_MECHANICS_API TopologyBarycentricMapper : public BarycentricMapper { - public: - - SOFA_CLASS(SOFA_TEMPLATE2(TopologyBarycentricMapper,In,Out),SOFA_TEMPLATE2(BarycentricMapper,In,Out)); + SOFA_CLASS(SOFA_TEMPLATE2(TopologyBarycentricMapper,In,Out), + SOFA_TEMPLATE2(BarycentricMapper,In,Out)); typedef typename Inherit1::Real Real; typedef typename core::behavior::BaseMechanicalState::ForceMask ForceMask; @@ -51,8 +50,6 @@ class SOFA_BASE_MECHANICS_API TopologyBarycentricMapper : public BarycentricMapp ForceMask *maskFrom; ForceMask *maskTo; -public: - virtual int addPointInLine(const int lineIndex, const SReal* baryCoords); virtual int setPointInLine(const int pointIndex, const int lineIndex, const SReal* baryCoords); virtual int createPointInLine(const typename Out::Coord& p, int lineIndex, const typename In::VecCoord* points); @@ -73,25 +70,23 @@ class SOFA_BASE_MECHANICS_API TopologyBarycentricMapper : public BarycentricMapp virtual int setPointInCube(const int pointIndex, const int cubeIndex, const SReal* baryCoords); virtual int createPointInCube(const typename Out::Coord& p, int cubeIndex, const typename In::VecCoord* points); - virtual void setToTopology( topology::PointSetTopologyContainer* toTopology) {this->toTopology = toTopology;} - const topology::PointSetTopologyContainer *getToTopology() const {return toTopology;} + virtual void setToTopology( topology::PointSetTopologyContainer* toTopology) {this->m_toTopology = toTopology;} + const topology::PointSetTopologyContainer *getToTopology() const {return m_toTopology;} virtual void updateForceMask(){/*mask is already filled in the mapper's applyJT*/} - virtual void resize( core::State* toModel ) = 0; protected: - TopologyBarycentricMapper(core::topology::BaseMeshTopology* fromTopology, topology::PointSetTopologyContainer* toTopology = nullptr) + TopologyBarycentricMapper(core::topology::BaseMeshTopology* fromTopology, + topology::PointSetTopologyContainer* toTopology = nullptr) : m_fromTopology(fromTopology) - , toTopology(toTopology) + , m_toTopology(toTopology) {} virtual ~TopologyBarycentricMapper() override {} -protected: - core::topology::BaseMeshTopology* m_fromTopology; - topology::PointSetTopologyContainer* toTopology; - + core::topology::BaseMeshTopology* m_fromTopology; + topology::PointSetTopologyContainer* m_toTopology; }; using sofa::defaulttype::Vec3dTypes; diff --git a/SofaKernel/modules/SofaBaseMechanics/BarycentricMapping.h b/SofaKernel/modules/SofaBaseMechanics/BarycentricMapping.h index dce44bc480f..02ed2cafea5 100644 --- a/SofaKernel/modules/SofaBaseMechanics/BarycentricMapping.h +++ b/SofaKernel/modules/SofaBaseMechanics/BarycentricMapping.h @@ -38,7 +38,6 @@ #include - namespace sofa { @@ -74,31 +73,9 @@ class BarycentricMapping : public core::Mapping typedef TopologyBarycentricMapper Mapper; typedef typename Inherit::ForceMask ForceMask; -protected: - - SingleLink,Mapper,BaseLink::FLAG_STRONGLINK> m_mapper; - public: - Data< bool > useRestPosition; ///< Use the rest position of the input and output models to initialize the mapping -#ifdef SOFA_DEV - //--- partial mapping test - Data< bool > sleeping; ///< is the mapping sleeping (not computed) -#endif - -protected: - - BarycentricMapping(); - - BarycentricMapping(core::State* from, core::State* to, typename Mapper::SPtr m_mapper); - - BarycentricMapping(core::State* from, core::State* to, BaseMeshTopology * topology=nullptr ); - - virtual ~BarycentricMapping() override; - -public: - virtual void init() override; virtual void reinit() override; virtual void apply(const core::MechanicalParams *mparams, Data< typename Out::VecCoord >& out, const Data< typename In::VecCoord >& in) override; @@ -106,41 +83,38 @@ class BarycentricMapping : public core::Mapping virtual void applyJT(const core::MechanicalParams *mparams, Data< typename In::VecDeriv >& out, const Data< typename Out::VecDeriv >& in) override; virtual void applyJT(const core::ConstraintParams *cparams, Data< typename In::MatrixDeriv >& out, const Data< typename Out::MatrixDeriv >& in) override; virtual const sofa::defaulttype::BaseMatrix* getJ() override; - - -public: - virtual const helper::vector* getJs() override; + virtual void draw(const core::visual::VisualParams* vparams) override; + virtual void handleTopologyChange(core::topology::Topology* t) override; -protected: + // interface for continuous friction contact + TopologyBarycentricMapper *getMapper() + { + return m_mapper.get(); + } +protected: typedef linearsolver::EigenSparseMatrix eigen_type; // eigen matrix for use with Compliant plugin eigen_type eigen; helper::vector< defaulttype::BaseMatrix* > js; - virtual void updateForceMask() override; - -public: - - void draw(const core::visual::VisualParams* vparams) override; - - virtual void handleTopologyChange(core::topology::Topology* t) override; + BarycentricMapping(); + BarycentricMapping(core::State* from, core::State* to, + typename Mapper::SPtr m_mapper); + BarycentricMapping(core::State* from, core::State* to, + BaseMeshTopology * topology=nullptr ); - // interface for continuous friction contact - TopologyBarycentricMapper *getMapper() - { - return m_mapper.get(); - } + SingleLink,Mapper,BaseLink::FLAG_STRONGLINK> m_mapper; -protected: + virtual ~BarycentricMapping() override; + virtual void updateForceMask() override; sofa::core::topology::BaseMeshTopology* topology_from; sofa::core::topology::BaseMeshTopology* topology_to; private: - void createMapperFromTopology(BaseMeshTopology * topology); }; diff --git a/SofaKernel/modules/SofaBaseMechanics/BarycentricMapping.inl b/SofaKernel/modules/SofaBaseMechanics/BarycentricMapping.inl index 6f0b07d6355..4d79285b897 100644 --- a/SofaKernel/modules/SofaBaseMechanics/BarycentricMapping.inl +++ b/SofaKernel/modules/SofaBaseMechanics/BarycentricMapping.inl @@ -71,7 +71,7 @@ using sofa::defaulttype::Matrix3; using sofa::defaulttype::Mat3x3d; using sofa::defaulttype::Vec3d; // 10/18 E.Coevoet: what's the difference between edge/line, tetra/tetrahedron, hexa/hexahedron? -typedef typename sofa::core::topology::BaseMeshTopology::Line Line; +typedef typename sofa::core::topology::BaseMeshTopology::Line Edge; typedef typename sofa::core::topology::BaseMeshTopology::Edge Edge; typedef typename sofa::core::topology::BaseMeshTopology::Triangle Triangle; typedef typename sofa::core::topology::BaseMeshTopology::Quad Quad; From 82beff31fb64a6bbd0ca33e0ac72022d76cbd283 Mon Sep 17 00:00:00 2001 From: Damien Marchal Date: Mon, 19 Nov 2018 15:45:34 +0100 Subject: [PATCH 08/15] =?UTF-8?q?[SofaSimulationGraph]=C2=A0Adds=20the=20m?= =?UTF-8?q?issing=20importPlugin()=20function=20in=20SimpleAPI?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- SofaKernel/modules/SofaSimulationGraph/SimpleApi.cpp | 8 ++++++++ SofaKernel/modules/SofaSimulationGraph/SimpleApi.h | 2 +- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/SofaKernel/modules/SofaSimulationGraph/SimpleApi.cpp b/SofaKernel/modules/SofaSimulationGraph/SimpleApi.cpp index d8a88df888c..3d38abbde17 100644 --- a/SofaKernel/modules/SofaSimulationGraph/SimpleApi.cpp +++ b/SofaKernel/modules/SofaSimulationGraph/SimpleApi.cpp @@ -35,11 +35,19 @@ using sofa::core::objectmodel::BaseObjectDescription ; #include using sofa::simulation::XMLPrintVisitor ; +#include +using sofa::helper::system::PluginManager ; + namespace sofa { namespace simpleapi { +bool importPlugin(const std::string& name) +{ + return PluginManager::getInstance().loadPlugin(name) ; +} + void dumpScene(Node::SPtr root) { XMLPrintVisitor p(sofa::core::ExecParams::defaultInstance(), std::cout) ; diff --git a/SofaKernel/modules/SofaSimulationGraph/SimpleApi.h b/SofaKernel/modules/SofaSimulationGraph/SimpleApi.h index 23d1c49d3d9..ebebe5e7c13 100644 --- a/SofaKernel/modules/SofaSimulationGraph/SimpleApi.h +++ b/SofaKernel/modules/SofaSimulationGraph/SimpleApi.h @@ -44,7 +44,7 @@ using sofa::core::objectmodel::BaseObject ; using sofa::simulation::Simulation ; using sofa::simulation::Node ; -void SOFA_SIMULATION_GRAPH_API importPlugin(const std::string& name) ; +bool SOFA_SIMULATION_GRAPH_API importPlugin(const std::string& name) ; Simulation::SPtr SOFA_SIMULATION_GRAPH_API createSimulation(const std::string& type="DAG") ; From 102e862f1af4211e00dba2cfa8d57eaeb1324522 Mon Sep 17 00:00:00 2001 From: Damien Marchal Date: Mon, 19 Nov 2018 15:46:19 +0100 Subject: [PATCH 09/15] [SofaBaseMechanics] Refactor the tests to cut the dependencies to SofaTest and SceneCreator. --- .../SofaBaseMechanics_test/CMakeLists.txt | 2 +- .../SofaBaseMechanics_test/DiagonalMass_test.cpp | 9 +++++++-- .../SofaBaseMechanics_test/MechanicalObject_test.cpp | 6 +++--- .../SofaBaseMechanics_test/UniformMass_test.cpp | 10 +++++++++- 4 files changed, 20 insertions(+), 7 deletions(-) diff --git a/SofaKernel/modules/SofaBaseMechanics/SofaBaseMechanics_test/CMakeLists.txt b/SofaKernel/modules/SofaBaseMechanics/SofaBaseMechanics_test/CMakeLists.txt index c1f3a39cadd..6e3331bf411 100644 --- a/SofaKernel/modules/SofaBaseMechanics/SofaBaseMechanics_test/CMakeLists.txt +++ b/SofaKernel/modules/SofaBaseMechanics/SofaBaseMechanics_test/CMakeLists.txt @@ -19,7 +19,7 @@ endif() add_executable(${PROJECT_NAME} ${SOURCE_FILES}) -target_link_libraries(${PROJECT_NAME} SofaGTestMain SofaTest) +target_link_libraries(${PROJECT_NAME} SofaBaseMechanics SofaGTestMain SofaSimulationGraph) if(SofaPython_FOUND) target_link_libraries(${PROJECT_NAME} SofaPython) endif() diff --git a/SofaKernel/modules/SofaBaseMechanics/SofaBaseMechanics_test/DiagonalMass_test.cpp b/SofaKernel/modules/SofaBaseMechanics/SofaBaseMechanics_test/DiagonalMass_test.cpp index f25f9cee4a1..a0e0dfb98f1 100644 --- a/SofaKernel/modules/SofaBaseMechanics/SofaBaseMechanics_test/DiagonalMass_test.cpp +++ b/SofaKernel/modules/SofaBaseMechanics/SofaBaseMechanics_test/DiagonalMass_test.cpp @@ -42,13 +42,16 @@ using sofa::simulation::Node ; #include #include +#include + #include using sofa::simulation::SceneLoaderXML ; #include using std::string ; -#include +#include +using sofa::helper::testing::BaseTest; using namespace sofa::defaulttype; using namespace sofa::component::topology; @@ -70,7 +73,7 @@ namespace sofa { // Given the positions and the topology, it then checks the expected values for // the mass. template -class DiagonalMass_test : public ::testing::Test +class DiagonalMass_test : public BaseTest { public: typedef TDataTypes DataTypes; @@ -88,6 +91,8 @@ class DiagonalMass_test : public ::testing::Test virtual void SetUp() { + sofa::simpleapi::importPlugin("SofaAllCommonComponents") ; + component::initBaseMechanics(); simulation::setSimulation(simulation = new simulation::graph::DAGSimulation()); root = simulation::getSimulation()->createNewGraph("root"); diff --git a/SofaKernel/modules/SofaBaseMechanics/SofaBaseMechanics_test/MechanicalObject_test.cpp b/SofaKernel/modules/SofaBaseMechanics/SofaBaseMechanics_test/MechanicalObject_test.cpp index 985f91669a8..60e9d7d6607 100644 --- a/SofaKernel/modules/SofaBaseMechanics/SofaBaseMechanics_test/MechanicalObject_test.cpp +++ b/SofaKernel/modules/SofaBaseMechanics/SofaBaseMechanics_test/MechanicalObject_test.cpp @@ -21,8 +21,8 @@ ******************************************************************************/ #include -#include - +#include +using sofa::helper::testing::BaseTest; namespace sofa { @@ -37,7 +37,7 @@ struct StubMechanicalObject : public component::container::MechanicalObject {}; template -struct MechanicalObject_test : public ::testing::Test +struct MechanicalObject_test : public BaseTest { typedef typename StubMechanicalObject::DataTypes::Coord Coord; typedef typename StubMechanicalObject::DataTypes::Real Real; diff --git a/SofaKernel/modules/SofaBaseMechanics/SofaBaseMechanics_test/UniformMass_test.cpp b/SofaKernel/modules/SofaBaseMechanics/SofaBaseMechanics_test/UniformMass_test.cpp index 13eae86a3ec..474c808278f 100644 --- a/SofaKernel/modules/SofaBaseMechanics/SofaBaseMechanics_test/UniformMass_test.cpp +++ b/SofaKernel/modules/SofaBaseMechanics/SofaBaseMechanics_test/UniformMass_test.cpp @@ -37,6 +37,8 @@ using sofa::component::mass::UniformMass ; #include using sofa::component::initBaseMechanics ; +#include + #include using sofa::simulation::Simulation ; using sofa::simulation::graph::DAGSimulation ; @@ -50,6 +52,10 @@ using sofa::component::container::MechanicalObject ; #include using sofa::simulation::SceneLoaderXML ; +#include +using sofa::helper::testing::BaseTest; + + template struct TemplateTypes { @@ -58,7 +64,7 @@ struct TemplateTypes }; template -struct UniformMassTest : public ::testing::Test +struct UniformMassTest : public BaseTest { typedef UniformMass TheUniformMass ; @@ -78,6 +84,8 @@ struct UniformMassTest : public ::testing::Test virtual void SetUp() { + sofa::simpleapi::importPlugin("SofaAllCommonComponents") ; + todo = true ; initBaseMechanics(); setSimulation( m_simu = new DAGSimulation() ); From a51a1e1365cf739cd056d7b3de1309d3745acd7d Mon Sep 17 00:00:00 2001 From: Damien Marchal Date: Mon, 19 Nov 2018 23:16:10 +0100 Subject: [PATCH 10/15] [SofaBaseMechanics_test] Restore the use of SofaTest. using SofaTest is bad but we should have working test to have the Barycentricmapping refactoring to work. --- .../SofaBaseMechanics/SofaBaseMechanics_test/CMakeLists.txt | 3 ++- .../SofaBaseMechanics_test/DiagonalMass_test.cpp | 4 ++-- .../SofaBaseMechanics_test/MechanicalObject_test.cpp | 4 ++-- .../SofaBaseMechanics_test/UniformMass_test.cpp | 4 ++-- 4 files changed, 8 insertions(+), 7 deletions(-) diff --git a/SofaKernel/modules/SofaBaseMechanics/SofaBaseMechanics_test/CMakeLists.txt b/SofaKernel/modules/SofaBaseMechanics/SofaBaseMechanics_test/CMakeLists.txt index 6e3331bf411..df9213efb4c 100644 --- a/SofaKernel/modules/SofaBaseMechanics/SofaBaseMechanics_test/CMakeLists.txt +++ b/SofaKernel/modules/SofaBaseMechanics/SofaBaseMechanics_test/CMakeLists.txt @@ -19,7 +19,8 @@ endif() add_executable(${PROJECT_NAME} ${SOURCE_FILES}) -target_link_libraries(${PROJECT_NAME} SofaBaseMechanics SofaGTestMain SofaSimulationGraph) +target_link_libraries(${PROJECT_NAME} SofaTest SofaGTestMain) + if(SofaPython_FOUND) target_link_libraries(${PROJECT_NAME} SofaPython) endif() diff --git a/SofaKernel/modules/SofaBaseMechanics/SofaBaseMechanics_test/DiagonalMass_test.cpp b/SofaKernel/modules/SofaBaseMechanics/SofaBaseMechanics_test/DiagonalMass_test.cpp index a0e0dfb98f1..2cf6cfff349 100644 --- a/SofaKernel/modules/SofaBaseMechanics/SofaBaseMechanics_test/DiagonalMass_test.cpp +++ b/SofaKernel/modules/SofaBaseMechanics/SofaBaseMechanics_test/DiagonalMass_test.cpp @@ -50,8 +50,8 @@ using sofa::simulation::SceneLoaderXML ; #include using std::string ; -#include -using sofa::helper::testing::BaseTest; +#include +using BaseTest = sofa::Sofa_test; using namespace sofa::defaulttype; using namespace sofa::component::topology; diff --git a/SofaKernel/modules/SofaBaseMechanics/SofaBaseMechanics_test/MechanicalObject_test.cpp b/SofaKernel/modules/SofaBaseMechanics/SofaBaseMechanics_test/MechanicalObject_test.cpp index 60e9d7d6607..02c2306fd79 100644 --- a/SofaKernel/modules/SofaBaseMechanics/SofaBaseMechanics_test/MechanicalObject_test.cpp +++ b/SofaKernel/modules/SofaBaseMechanics/SofaBaseMechanics_test/MechanicalObject_test.cpp @@ -21,8 +21,8 @@ ******************************************************************************/ #include -#include -using sofa::helper::testing::BaseTest; +#include +using BaseTest = sofa::Sofa_test<>; namespace sofa { diff --git a/SofaKernel/modules/SofaBaseMechanics/SofaBaseMechanics_test/UniformMass_test.cpp b/SofaKernel/modules/SofaBaseMechanics/SofaBaseMechanics_test/UniformMass_test.cpp index 474c808278f..23b5d7f4846 100644 --- a/SofaKernel/modules/SofaBaseMechanics/SofaBaseMechanics_test/UniformMass_test.cpp +++ b/SofaKernel/modules/SofaBaseMechanics/SofaBaseMechanics_test/UniformMass_test.cpp @@ -52,8 +52,8 @@ using sofa::component::container::MechanicalObject ; #include using sofa::simulation::SceneLoaderXML ; -#include -using sofa::helper::testing::BaseTest; +#include +using BaseTest = sofa::Sofa_test; template From 451e2b5a457683ee13fdece1458bc6bafedc7b7a Mon Sep 17 00:00:00 2001 From: COEVOET Eulalie Date: Tue, 27 Nov 2018 11:19:57 +0100 Subject: [PATCH 11/15] [SofaCUDA] fix compile and minor cleaning: 1- added missing includes related to the refactoring of BarycentricMapping into different files 2- removed commented code --- .../gpu/cuda/CudaBarycentricMapping-3f.cpp | 33 +- .../gpu/cuda/CudaBarycentricMapping-3f1.cpp | 335 +----------- .../gpu/cuda/CudaBarycentricMapping-f.cpp | 12 - .../sofa/gpu/cuda/CudaBarycentricMapping.cpp | 12 - .../sofa/gpu/cuda/CudaBarycentricMapping.h | 4 + .../sofa/gpu/cuda/CudaBarycentricMapping.inl | 11 + .../gpu/cuda/CudaBarycentricMappingRigid.cpp | 484 +----------------- .../BarycentricMappingRigid.cpp | 1 - 8 files changed, 36 insertions(+), 856 deletions(-) diff --git a/applications/plugins/SofaCUDA/sofa/gpu/cuda/CudaBarycentricMapping-3f.cpp b/applications/plugins/SofaCUDA/sofa/gpu/cuda/CudaBarycentricMapping-3f.cpp index 4b1594e6dfa..6d8c9d227e8 100644 --- a/applications/plugins/SofaCUDA/sofa/gpu/cuda/CudaBarycentricMapping-3f.cpp +++ b/applications/plugins/SofaCUDA/sofa/gpu/cuda/CudaBarycentricMapping-3f.cpp @@ -111,31 +111,6 @@ void BarycentricMapperSparseGridTopology::applyJT { buildTranslate(out.size()); SparseGridMapperCuda3f_applyJT(out.size(), CudaTnb.deviceRead(),CudaTst.deviceRead(),CudaTid.deviceRead(),CudaTVal.deviceRead(), out.deviceWrite(), in.deviceRead()); - /* - for ( unsigned int i=0;itopology->getHexahedron ( map[i].in_index ); - const OutReal fx = ( OutReal ) map[i].baryCoords[0]; - const OutReal fy = ( OutReal ) map[i].baryCoords[1]; - const OutReal fz = ( OutReal ) map[i].baryCoords[2]; - out[cube[0]] += v * ( ( 1-fx ) * ( 1-fy ) * ( 1-fz ) ); - out[cube[1]] += v * ( ( fx ) * ( 1-fy ) * ( 1-fz ) ); - out[cube[3]] += v * ( ( 1-fx ) * ( fy ) * ( 1-fz ) ); - out[cube[2]] += v * ( ( fx ) * ( fy ) * ( 1-fz ) ); - out[cube[4]] += v * ( ( 1-fx ) * ( 1-fy ) * ( fz ) ); - out[cube[5]] += v * ( ( fx ) * ( 1-fy ) * ( fz ) ); - out[cube[7]] += v * ( ( 1-fx ) * ( fy ) * ( fz ) ); - out[cube[6]] += v * ( ( fx ) * ( fy ) * ( fz ) ); - } - */ -// for ( unsigned int o=0;o @@ -200,9 +175,9 @@ void BarycentricMapperSparseGridTopology::draw (c } template<> -void BarycentricMapperSparseGridTopology::resize( core::State* /*toModel*/ ) +void BarycentricMapperSparseGridTopology::resize( core::State* toModel ) { -// toModel->resize(map.size()); + SOFA_UNUSED(toModel); } //////////////////////////////////////////////////////////// @@ -271,9 +246,9 @@ void BarycentricMapperMeshTopology::draw (const c } template<> -void BarycentricMapperMeshTopology::resize( core::State* /*toModel*/ ) +void BarycentricMapperMeshTopology::resize( core::State* toModel ) { -// toModel->resize(size); + SOFA_UNUSED(toModel); } diff --git a/applications/plugins/SofaCUDA/sofa/gpu/cuda/CudaBarycentricMapping-3f1.cpp b/applications/plugins/SofaCUDA/sofa/gpu/cuda/CudaBarycentricMapping-3f1.cpp index 17ecc4de544..07aacb150b5 100644 --- a/applications/plugins/SofaCUDA/sofa/gpu/cuda/CudaBarycentricMapping-3f1.cpp +++ b/applications/plugins/SofaCUDA/sofa/gpu/cuda/CudaBarycentricMapping-3f1.cpp @@ -83,87 +83,11 @@ void BarycentricMapperRegularGridTopology::draw template<> -void BarycentricMapperRegularGridTopology::resize( core::State* /*toModel*/ ) +void BarycentricMapperRegularGridTopology::resize( core::State* toModel ) { -// toModel->resize(map.size()); + SOFA_UNUSED(toModel); } -//template<> -//void BarycentricMapperRegularGridTopology::apply( Out::VecCoord& out, const In::VecCoord& in ) -//{ -// unsigned int gridsize[3] = { (unsigned int)topology->getNx(), (unsigned int)topology->getNy(), (unsigned int)topology->getNz() }; -// out.fastResize(map.size()); -// RegularGridMapperCuda3f1_3f_apply(map.size(), gridsize, map.deviceRead(), out.deviceWrite(), in.deviceRead()); -//} - -//template<> -//void BarycentricMapperRegularGridTopology::applyJ( Out::VecDeriv& out, const In::VecDeriv& in ) -//{ -// unsigned int gridsize[3] = { (unsigned int)topology->getNx(), (unsigned int)topology->getNy(), (unsigned int)topology->getNz() }; -// out.fastResize(map.size()); -// RegularGridMapperCuda3f1_3f_applyJ(map.size(), gridsize, map.deviceRead(), out.deviceWrite(), in.deviceRead()); -//} - -//template<> -//void BarycentricMapperRegularGridTopology::applyJT( In::VecDeriv& out, const Out::VecDeriv& in ) -//{ -// calcMapT(); -// if (map.size() == 0) return; -// unsigned int gridsize[3] = { (unsigned int)topology->getNx(), (unsigned int)topology->getNy(), (unsigned int)topology->getNz() }; -// unsigned int insize = out.size(); - -// RegularGridMapperCuda3f1_3f_applyJT(insize, maxNOut, gridsize, mapT.deviceRead(), out.deviceWrite(), in.deviceRead()); -//} - -//template<> -//void BarycentricMapperRegularGridTopology::applyJT( In::MatrixDeriv& /*out*/, const Out::MatrixDeriv& /*in*/ ) -//{ -//} - -//template<> -//void BarycentricMapperRegularGridTopology::draw (const core::visual::VisualParams* ,const Out::VecCoord& /*out*/, const In::VecCoord& /*in*/) -//{ -//} - - - -//template<> -//void BarycentricMapperRegularGridTopology::apply( Out::VecCoord& out, const In::VecCoord& in ) -//{ -// unsigned int gridsize[3] = { (unsigned int)topology->getNx(), (unsigned int)topology->getNy(), (unsigned int)topology->getNz() }; -// out.fastResize(map.size()); -// RegularGridMapperCuda3f_3f1_apply(map.size(), gridsize, map.deviceRead(), out.deviceWrite(), in.deviceRead()); -//} - -//template<> -//void BarycentricMapperRegularGridTopology::applyJ( Out::VecDeriv& out, const In::VecDeriv& in ) -//{ -// unsigned int gridsize[3] = { (unsigned int)topology->getNx(), (unsigned int)topology->getNy(), (unsigned int)topology->getNz() }; -// out.fastResize(map.size()); -// RegularGridMapperCuda3f_3f1_applyJ(map.size(), gridsize, map.deviceRead(), out.deviceWrite(), in.deviceRead()); -//} - -//template<> -//void BarycentricMapperRegularGridTopology::applyJT( In::VecDeriv& out, const Out::VecDeriv& in ) -//{ -// calcMapT(); -// if (map.size() == 0) return; -// unsigned int gridsize[3] = { (unsigned int)topology->getNx(), (unsigned int)topology->getNy(), (unsigned int)topology->getNz() }; -// unsigned int insize = out.size(); - -// RegularGridMapperCuda3f_3f1_applyJT(insize, maxNOut, gridsize, mapT.deviceRead(), out.deviceWrite(), in.deviceRead()); -//} - -//template<> -//void BarycentricMapperRegularGridTopology::applyJT( In::MatrixDeriv& /*out*/, const Out::MatrixDeriv& /*in*/ ) -//{ -//} - -//template<> -//void BarycentricMapperRegularGridTopology::draw (const core::visual::VisualParams* ,const Out::VecCoord& /*out*/, const In::VecCoord& /*in*/) -//{ -//} - //////////////////////////////////////////////////////////////////////////// ////////// BarycentricMapperSparseGridTopology ////////// @@ -175,175 +99,6 @@ void BarycentricMapperSparseGridTopology::draw { } -//template<> -//void BarycentricMapperSparseGridTopology::apply( Out::VecCoord& out, const In::VecCoord& in ) -//{ -// out.fastResize(map.size()); -// buildHexa(); -// SparseGridMapperCuda3f1_3f_apply(map.size(), CudaHexa.deviceRead(), map.deviceRead(), out.deviceWrite(), in.deviceRead()); -//} - -//template<> -//void BarycentricMapperSparseGridTopology::applyJ( Out::VecDeriv& out, const In::VecDeriv& in ) -//{ -// out.fastResize(map.size()); -// buildHexa(); -// SparseGridMapperCuda3f1_3f_applyJ(map.size(), CudaHexa.deviceRead(), map.deviceRead(), out.deviceWrite(), in.deviceRead()); -//} - -//template<> -//void BarycentricMapperSparseGridTopology::applyJT( In::VecDeriv& out, const Out::VecDeriv& in ) -//{ -// buildTranslate(out.size()); -// SparseGridMapperCuda3f1_3f_applyJT(out.size(), CudaTnb.deviceRead(),CudaTst.deviceRead(),CudaTid.deviceRead(),CudaTVal.deviceRead(), out.deviceWrite(), in.deviceRead()); -//} - -//template<> -//void BarycentricMapperSparseGridTopology::applyJT( In::MatrixDeriv& out, const Out::MatrixDeriv& in ) -//{ -// helper::ReadAccessor > map = this->map; - -// for (Out::MatrixDeriv::RowConstIterator rowIt = in.begin(), rowItEnd = in.end(); rowIt != rowItEnd; ++rowIt) -// { -// Out::MatrixDeriv::ColConstIterator colItEnd = rowIt.end(); -// Out::MatrixDeriv::ColConstIterator colIt = rowIt.begin(); - -// if (colIt != colItEnd) -// { -// In::MatrixDeriv::RowIterator o = out.writeLine(rowIt.index()); - -// for ( ; colIt != colItEnd; ++colIt) -// { -// unsigned indexIn = colIt.index(); -// InDeriv data = (InDeriv) Out::getDPos(colIt.val()); - -// const topology::SparseGridTopology::Hexa cube = this->fromTopology->getHexahedron ( map[indexIn].in_index ); - -// const OutReal fx = ( OutReal ) map[indexIn].baryCoords[0]; -// const OutReal fy = ( OutReal ) map[indexIn].baryCoords[1]; -// const OutReal fz = ( OutReal ) map[indexIn].baryCoords[2]; -// const OutReal oneMinusFx = 1-fx; -// const OutReal oneMinusFy = 1-fy; -// const OutReal oneMinusFz = 1-fz; - -// OutReal f = ( oneMinusFx * oneMinusFy * oneMinusFz ); -// o.addCol ( cube[0], ( data * f ) ); - -// f = ( ( fx ) * oneMinusFy * oneMinusFz ); -// o.addCol ( cube[1], ( data * f ) ); - -// f = ( oneMinusFx * ( fy ) * oneMinusFz ); -// o.addCol ( cube[3], ( data * f ) ); - -// f = ( ( fx ) * ( fy ) * oneMinusFz ); -// o.addCol ( cube[2], ( data * f ) ); - -// f = ( oneMinusFx * oneMinusFy * ( fz ) ); -// o.addCol ( cube[4], ( data * f ) ); - -// f = ( ( fx ) * oneMinusFy * ( fz ) ); -// o.addCol ( cube[5], ( data * f ) ); - -// f = ( oneMinusFx * ( fy ) * ( fz ) ); -// o.addCol ( cube[7], ( data * f ) ); - -// f = ( ( fx ) * ( fy ) * ( fz ) ); -// o.addCol ( cube[6], ( data * f ) ); - -// } -// } -// } -//} - -//template<> -//void BarycentricMapperSparseGridTopology::draw (const core::visual::VisualParams* ,const Out::VecCoord& /*out*/, const In::VecCoord& /*in*/) -//{ -//} - -//template<> -//void BarycentricMapperSparseGridTopology::apply( Out::VecCoord& out, const In::VecCoord& in ) -//{ -// out.fastResize(map.size()); -// buildHexa(); -// SparseGridMapperCuda3f_3f1_apply(map.size(), CudaHexa.deviceRead(), map.deviceRead(), out.deviceWrite(), in.deviceRead()); -//} - -//template<> -//void BarycentricMapperSparseGridTopology::applyJ( Out::VecDeriv& out, const In::VecDeriv& in ) -//{ -// out.fastResize(map.size()); -// buildHexa(); -// SparseGridMapperCuda3f_3f1_applyJ(map.size(), CudaHexa.deviceRead(), map.deviceRead(), out.deviceWrite(), in.deviceRead()); -//} - -//template<> -//void BarycentricMapperSparseGridTopology::applyJT( In::VecDeriv& out, const Out::VecDeriv& in ) -//{ -// buildTranslate(out.size()); -// SparseGridMapperCuda3f_3f1_applyJT(out.size(), CudaTnb.deviceRead(),CudaTst.deviceRead(),CudaTid.deviceRead(),CudaTVal.deviceRead(), out.deviceWrite(), in.deviceRead()); -//} - -//template<> -//void BarycentricMapperSparseGridTopology::applyJT( In::MatrixDeriv& out, const Out::MatrixDeriv& in ) -//{ -// helper::ReadAccessor > map = this->map; - -// for (Out::MatrixDeriv::RowConstIterator rowIt = in.begin(), rowItEnd = in.end(); rowIt != rowItEnd; ++rowIt) -// { -// Out::MatrixDeriv::ColConstIterator colItEnd = rowIt.end(); -// Out::MatrixDeriv::ColConstIterator colIt = rowIt.begin(); - -// if (colIt != colItEnd) -// { -// In::MatrixDeriv::RowIterator o = out.writeLine(rowIt.index()); - -// for ( ; colIt != colItEnd; ++colIt) -// { -// unsigned indexIn = colIt.index(); -// InDeriv data = (InDeriv) Out::getDPos(colIt.val()); - -// const topology::SparseGridTopology::Hexa cube = this->fromTopology->getHexahedron ( map[indexIn].in_index ); - -// const OutReal fx = ( OutReal ) map[indexIn].baryCoords[0]; -// const OutReal fy = ( OutReal ) map[indexIn].baryCoords[1]; -// const OutReal fz = ( OutReal ) map[indexIn].baryCoords[2]; -// const OutReal oneMinusFx = 1-fx; -// const OutReal oneMinusFy = 1-fy; -// const OutReal oneMinusFz = 1-fz; - -// OutReal f = ( oneMinusFx * oneMinusFy * oneMinusFz ); -// o.addCol ( cube[0], ( data * f ) ); - -// f = ( ( fx ) * oneMinusFy * oneMinusFz ); -// o.addCol ( cube[1], ( data * f ) ); - -// f = ( oneMinusFx * ( fy ) * oneMinusFz ); -// o.addCol ( cube[3], ( data * f ) ); - -// f = ( ( fx ) * ( fy ) * oneMinusFz ); -// o.addCol ( cube[2], ( data * f ) ); - -// f = ( oneMinusFx * oneMinusFy * ( fz ) ); -// o.addCol ( cube[4], ( data * f ) ); - -// f = ( ( fx ) * oneMinusFy * ( fz ) ); -// o.addCol ( cube[5], ( data * f ) ); - -// f = ( oneMinusFx * ( fy ) * ( fz ) ); -// o.addCol ( cube[7], ( data * f ) ); - -// f = ( ( fx ) * ( fy ) * ( fz ) ); -// o.addCol ( cube[6], ( data * f ) ); -// } -// } -// } -//} - -//template<> -//void BarycentricMapperSparseGridTopology::draw (const core::visual::VisualParams* ,const Out::VecCoord& /*out*/, const In::VecCoord& /*in*/) -//{ -//} - template<> void BarycentricMapperSparseGridTopology::apply( Out::VecCoord& out, const In::VecCoord& in ) { @@ -424,9 +179,9 @@ void BarycentricMapperSparseGridTopology::apply } template<> -void BarycentricMapperSparseGridTopology::resize( core::State* /*toModel*/ ) +void BarycentricMapperSparseGridTopology::resize( core::State* toModel ) { -// toModel->resize(map.size()); + SOFA_UNUSED(toModel); } @@ -468,89 +223,11 @@ void BarycentricMapperMeshTopology::draw (const } template<> -void BarycentricMapperMeshTopology::resize( core::State* /*toModel*/ ) +void BarycentricMapperMeshTopology::resize( core::State* toModel ) { -// toModel->resize(size); + SOFA_UNUSED(toModel); } -//template<> -//void BarycentricMapperMeshTopology::apply( Out::VecCoord& out, const In::VecCoord& in ) -//{ -// out.fastResize(size); -// MeshMapperCuda3f1_3f_apply(size, maxNIn, map.deviceRead(), out.deviceWrite(), in.deviceRead()); -//} - -//template<> -//void BarycentricMapperMeshTopology::applyJ( Out::VecDeriv& out, const In::VecDeriv& in ) -//{ -// out.fastResize(size); -// MeshMapperCuda3f1_3f_apply(size, maxNIn, map.deviceRead(), out.deviceWrite(), in.deviceRead()); -//} - -//template<> -//void BarycentricMapperMeshTopology::applyJT( In::VecDeriv& out, const Out::VecDeriv& in ) -//{ -// if (size == 0) return; -// calcMapT(); -// MeshMapperCuda3f_3f1_applyPEq(insize, maxNOut, mapT.deviceRead(), out.deviceWrite(), in.deviceRead()); -//} - -//template<> -//void BarycentricMapperMeshTopology::applyJT( In::MatrixDeriv& /*out*/, const Out::MatrixDeriv& /*in*/ ) -//{ -//} - -//template<> -//void BarycentricMapperMeshTopology::draw (const core::visual::VisualParams* ,const Out::VecCoord& /*out*/, const In::VecCoord& /*in*/) -//{ -//} - -//template<> -//void BarycentricMapperMeshTopology::resize( core::State* toModel ) -//{ -//// toModel->resize(size); -//} - - -//template<> -//void BarycentricMapperMeshTopology::apply( Out::VecCoord& out, const In::VecCoord& in ) -//{ -// out.fastResize(size); -// MeshMapperCuda3f_3f1_apply(size, maxNIn, map.deviceRead(), out.deviceWrite(), in.deviceRead()); -//} - -//template<> -//void BarycentricMapperMeshTopology::applyJ( Out::VecDeriv& out, const In::VecDeriv& in ) -//{ -// out.fastResize(size); -// MeshMapperCuda3f_3f1_apply(size, maxNIn, map.deviceRead(), out.deviceWrite(), in.deviceRead()); -//} - -//template<> -//void BarycentricMapperMeshTopology::applyJT( In::VecDeriv& out, const Out::VecDeriv& in ) -//{ -// if (size == 0) return; -// calcMapT(); -// MeshMapperCuda3f1_3f_applyPEq(insize, maxNOut, mapT.deviceRead(), out.deviceWrite(), in.deviceRead()); -//} - -//template<> -//void BarycentricMapperMeshTopology::applyJT( In::MatrixDeriv& /*out*/, const Out::MatrixDeriv& /*in*/ ) -//{ -//} - -//template<> -//void BarycentricMapperMeshTopology::draw (const core::visual::VisualParams* ,const Out::VecCoord& /*out*/, const In::VecCoord& /*in*/) -//{ -//} - -//template<> -//void BarycentricMapperMeshTopology::resize( core::State* toModel ) -//{ -//// toModel->resize(size); -//} - - //////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////// diff --git a/applications/plugins/SofaCUDA/sofa/gpu/cuda/CudaBarycentricMapping-f.cpp b/applications/plugins/SofaCUDA/sofa/gpu/cuda/CudaBarycentricMapping-f.cpp index 18f04ce46d5..381ef1f2b31 100644 --- a/applications/plugins/SofaCUDA/sofa/gpu/cuda/CudaBarycentricMapping-f.cpp +++ b/applications/plugins/SofaCUDA/sofa/gpu/cuda/CudaBarycentricMapping-f.cpp @@ -69,18 +69,6 @@ int BarycentricMappingCudaClass_f = core::RegisterObject("Supports GPU-side comp .add< BarycentricMapping< Vec3fTypes, CudaVec3fTypes> >() .add< BarycentricMapping< CudaVec3fTypes, Vec3fTypes> >() #endif - -// what about the following guys ? They were not instanciated. - -//#ifdef SOFA_GPU_CUDA_DOUBLE -//.add< BarycentricMapping< CudaVec3fTypes, CudaVec3dTypes> >() -//.add< BarycentricMapping< CudaVec3dTypes, CudaVec3fTypes> >() -//.add< BarycentricMapping< CudaVec3dTypes, CudaVec3dTypes> >() -//.add< BarycentricMapping< CudaVec3dTypes, Vec3fTypes> >() -//.add< BarycentricMapping< CudaVec3dTypes, Vec3dTypes> >() -//.add< BarycentricMapping< Vec3fTypes, CudaVec3dTypes> >() -//.add< BarycentricMapping< Vec3dTypes, CudaVec3dTypes> >() -//#endif ; } // namespace cuda diff --git a/applications/plugins/SofaCUDA/sofa/gpu/cuda/CudaBarycentricMapping.cpp b/applications/plugins/SofaCUDA/sofa/gpu/cuda/CudaBarycentricMapping.cpp index dd0206f0838..383b6f9b813 100644 --- a/applications/plugins/SofaCUDA/sofa/gpu/cuda/CudaBarycentricMapping.cpp +++ b/applications/plugins/SofaCUDA/sofa/gpu/cuda/CudaBarycentricMapping.cpp @@ -68,18 +68,6 @@ int BarycentricMappingCudaClass = core::RegisterObject("Supports GPU-side comput .add< BarycentricMapping< Vec3dTypes, CudaVec3fTypes> >() .add< BarycentricMapping< CudaVec3fTypes, Vec3dTypes> >() #endif - -// what about the following guys ? They were not instanciated. - -//#ifdef SOFA_GPU_CUDA_DOUBLE -//.add< BarycentricMapping< CudaVec3fTypes, CudaVec3dTypes> >() -//.add< BarycentricMapping< CudaVec3dTypes, CudaVec3fTypes> >() -//.add< BarycentricMapping< CudaVec3dTypes, CudaVec3dTypes> >() -//.add< BarycentricMapping< CudaVec3dTypes, Vec3fTypes> >() -//.add< BarycentricMapping< CudaVec3dTypes, Vec3dTypes> >() -//.add< BarycentricMapping< Vec3fTypes, CudaVec3dTypes> >() -//.add< BarycentricMapping< Vec3dTypes, CudaVec3dTypes> >() -//#endif ; } // namespace cuda diff --git a/applications/plugins/SofaCUDA/sofa/gpu/cuda/CudaBarycentricMapping.h b/applications/plugins/SofaCUDA/sofa/gpu/cuda/CudaBarycentricMapping.h index 4969cb6e6fb..d84766ef0fb 100644 --- a/applications/plugins/SofaCUDA/sofa/gpu/cuda/CudaBarycentricMapping.h +++ b/applications/plugins/SofaCUDA/sofa/gpu/cuda/CudaBarycentricMapping.h @@ -24,6 +24,10 @@ #include "CudaTypes.h" #include +#include +#include +#include +#include #include namespace sofa diff --git a/applications/plugins/SofaCUDA/sofa/gpu/cuda/CudaBarycentricMapping.inl b/applications/plugins/SofaCUDA/sofa/gpu/cuda/CudaBarycentricMapping.inl index 518ac8276ed..cdac39b9b50 100644 --- a/applications/plugins/SofaCUDA/sofa/gpu/cuda/CudaBarycentricMapping.inl +++ b/applications/plugins/SofaCUDA/sofa/gpu/cuda/CudaBarycentricMapping.inl @@ -25,6 +25,17 @@ #include "CudaBarycentricMapping.h" #include #include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include namespace sofa { diff --git a/applications/plugins/SofaCUDA/sofa/gpu/cuda/CudaBarycentricMappingRigid.cpp b/applications/plugins/SofaCUDA/sofa/gpu/cuda/CudaBarycentricMappingRigid.cpp index 64b41e082b1..4ad8422e29c 100644 --- a/applications/plugins/SofaCUDA/sofa/gpu/cuda/CudaBarycentricMappingRigid.cpp +++ b/applications/plugins/SofaCUDA/sofa/gpu/cuda/CudaBarycentricMappingRigid.cpp @@ -22,9 +22,19 @@ #define SOFA_COMPONENT_MAPPING_CUDABARYCENTRICMAPPINGRIGID_CPP #include "CudaTypes.h" #include -#include #include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include #include @@ -51,15 +61,6 @@ int BarycentricMappingRigidClass = core::RegisterObject("") #ifndef SOFA_FLOAT .add< BarycentricMapping< CudaVec3fTypes, Rigid3dTypes > >() #endif - /*#ifndef SOFA_DOUBLE - .add< BarycentricMapping< CudaVec3fTypes, Rigid3fTypes > >() - #endif - #ifndef SOFA_FLOAT - #ifndef SOFA_DOUBLE - .add< BarycentricMapping< CudaVec3fTypes, Rigid3dTypes > >() - .add< BarycentricMapping< CudaVec3fTypes, Rigid3fTypes > >() - #endif - #endif*/ ; #ifndef SOFA_FLOAT @@ -80,7 +81,6 @@ void BarycentricMapperHexahedronSetTopologygetChangeType(); switch ( changeType ) { - //TODO: implementation of BarycentricMapperHexahedronSetTopology::handleTopologyChange() case core::topology::ENDING_EVENT: ///< To notify the end for the current sequence of topological change events { if(!m_invalidIndex.empty()) @@ -93,7 +93,6 @@ void BarycentricMapperHexahedronSetTopologym_fromTopology->getNbHexahedra(); const sofa::helper::vector &hexahedra = ( static_cast< const core::topology::HexahedraRemoved *> ( *changeIt ) )->getArray(); - // sofa::helper::vector hexahedra(tab); for ( unsigned int i=0; i -void BarycentricMapperHexahedronSetTopology::handleTopologyChange(core::topology::Topology* t) -{ - - if (t != this->fromTopology) return; - if ( this->fromTopology->beginChange() == this->fromTopology->endChange() ) - return; - - std::list::const_iterator itBegin = this->fromTopology->beginChange(); - std::list::const_iterator itEnd = this->fromTopology->endChange(); - - for ( std::list::const_iterator changeIt = itBegin; - changeIt != itEnd; ++changeIt ) - { - const core::topology::TopologyChangeType changeType = ( *changeIt )->getChangeType(); - switch ( changeType ) - { - //TODO: implementation of BarycentricMapperHexahedronSetTopology::handleTopologyChange() - case core::topology::ENDING_EVENT: ///< To notify the end for the current sequence of topological change events - { - if(!_invalidIndex.empty()) - { - helper::vector& mapData = *(map.beginEdit()); - - for ( std::set::const_iterator iter = _invalidIndex.begin(); - iter != _invalidIndex.end(); ++iter ) - { - const int j = *iter; - if ( mapData[j].in_index == -1 ) // compute new mapping - { - // std::cout << "BarycentricMapperHexahedronSetTopology : new mapping" << std::endl; - Vector3 coefs; - defaulttype::Vec3fTypes::Coord pos; - pos[0] = mapData[j].baryCoords[0]; - pos[1] = mapData[j].baryCoords[1]; - pos[2] = mapData[j].baryCoords[2]; - - // find nearest cell and barycentric coords - Real distance = 1e10; - - int index = _fromGeomAlgo->findNearestElementInRestPos ( pos, coefs, distance ); - - if ( index != -1 ) - { - mapData[j].baryCoords[0] = ( Real ) coefs[0]; - mapData[j].baryCoords[1] = ( Real ) coefs[1]; - mapData[j].baryCoords[2] = ( Real ) coefs[2]; - mapData[j].in_index = index; - } - } - } - - map.endEdit(); - _invalidIndex.clear(); - } - } - break; - case core::topology::POINTSINDICESSWAP: ///< For PointsIndicesSwap. - break; - case core::topology::POINTSADDED: ///< For PointsAdded. - break; - case core::topology::POINTSREMOVED: ///< For PointsRemoved. - break; - case core::topology::POINTSRENUMBERING: ///< For PointsRenumbering. - break; - case core::topology::TRIANGLESADDED: ///< For Triangles Added. - break; - case core::topology::TRIANGLESREMOVED: ///< For Triangles Removed. - break; - case core::topology::HEXAHEDRAADDED: ///< For HexahedraAdded. - { - } - break; - case core::topology::HEXAHEDRAREMOVED: ///< For HexahedraRemoved. - { - // std::cout << "BarycentricMapperHexahedronSetTopology() HEXAHEDRAREMOVED" << std::endl; - const unsigned int nbHexahedra = this->fromTopology->getNbHexahedra(); - - const sofa::helper::vector &hexahedra = ( static_cast< const core::topology::HexahedraRemoved *> ( *changeIt ) )->getArray(); - // sofa::helper::vector hexahedra(tab); - - for ( unsigned int i=0; igetRestPointPositionInHexahedron ( cubeId, coefs ); - - helper::vector& vectorData = *(map.beginEdit()); - vectorData[j].in_index = -1; - vectorData[j].baryCoords[0] = restPos[0]; - vectorData[j].baryCoords[1] = restPos[1]; - vectorData[j].baryCoords[2] = restPos[2]; - map.endEdit(); - - _invalidIndex.insert(j); - } - } - } - - // renumber - unsigned int lastCubeId = nbHexahedra-1; - for ( unsigned int i=0; i& vectorData = *(map.beginEdit()); - vectorData[j].in_index = cubeId; - map.endEdit(); - } - } - } - } - break; - case core::topology::HEXAHEDRARENUMBERING: ///< For HexahedraRenumbering. - break; - default: - break; - } - } -} -#endif - -#ifndef SOFA_FLOAT -#ifndef SOFA_DOUBLE - -template <> -void BarycentricMapperHexahedronSetTopology::handleTopologyChange(core::topology::Topology* t) -{ - - if (t != this->fromTopology) return; - if ( this->fromTopology->beginChange() == this->fromTopology->endChange() ) - return; - - std::list::const_iterator itBegin = this->fromTopology->beginChange(); - std::list::const_iterator itEnd = this->fromTopology->endChange(); - - for ( std::list::const_iterator changeIt = itBegin; - changeIt != itEnd; ++changeIt ) - { - const core::topology::TopologyChangeType changeType = ( *changeIt )->getChangeType(); - switch ( changeType ) - { - //TODO: implementation of BarycentricMapperHexahedronSetTopology::handleTopologyChange() - case core::topology::ENDING_EVENT: ///< To notify the end for the current sequence of topological change events - { - if(!_invalidIndex.empty()) - { - helper::vector& mapData = *(map.beginEdit()); - - for ( std::set::const_iterator iter = _invalidIndex.begin(); - iter != _invalidIndex.end(); ++iter ) - { - const int j = *iter; - if ( mapData[j].in_index == -1 ) // compute new mapping - { - // std::cout << "BarycentricMapperHexahedronSetTopology : new mapping" << std::endl; - Vector3 coefs; - defaulttype::Vec3dTypes::Coord pos; - pos[0] = mapData[j].baryCoords[0]; - pos[1] = mapData[j].baryCoords[1]; - pos[2] = mapData[j].baryCoords[2]; - - // find nearest cell and barycentric coords - Real distance = 1e10; - - int index = _fromGeomAlgo->findNearestElementInRestPos ( pos, coefs, distance ); - - if ( index != -1 ) - { - mapData[j].baryCoords[0] = ( Real ) coefs[0]; - mapData[j].baryCoords[1] = ( Real ) coefs[1]; - mapData[j].baryCoords[2] = ( Real ) coefs[2]; - mapData[j].in_index = index; - } - } - } - - map.endEdit(); - _invalidIndex.clear(); - } - } - break; - case core::topology::POINTSINDICESSWAP: ///< For PointsIndicesSwap. - break; - case core::topology::POINTSADDED: ///< For PointsAdded. - break; - case core::topology::POINTSREMOVED: ///< For PointsRemoved. - break; - case core::topology::POINTSRENUMBERING: ///< For PointsRenumbering. - break; - case core::topology::TRIANGLESADDED: ///< For Triangles Added. - break; - case core::topology::TRIANGLESREMOVED: ///< For Triangles Removed. - break; - case core::topology::HEXAHEDRAADDED: ///< For HexahedraAdded. - { - } - break; - case core::topology::HEXAHEDRAREMOVED: ///< For HexahedraRemoved. - { - // std::cout << "BarycentricMapperHexahedronSetTopology() HEXAHEDRAREMOVED" << std::endl; - const unsigned int nbHexahedra = this->fromTopology->getNbHexahedra(); - - const sofa::helper::vector &hexahedra = ( static_cast< const core::topology::HexahedraRemoved *> ( *changeIt ) )->getArray(); - // sofa::helper::vector hexahedra(tab); - - for ( unsigned int i=0; igetRestPointPositionInHexahedron ( cubeId, coefs ); - - helper::vector& vectorData = *(map.beginEdit()); - vectorData[j].in_index = -1; - vectorData[j].baryCoords[0] = restPos[0]; - vectorData[j].baryCoords[1] = restPos[1]; - vectorData[j].baryCoords[2] = restPos[2]; - map.endEdit(); - - _invalidIndex.insert(j); - } - } - } - - // renumber - unsigned int lastCubeId = nbHexahedra-1; - for ( unsigned int i=0; i& vectorData = *(map.beginEdit()); - vectorData[j].in_index = cubeId; - map.endEdit(); - } - } - } - } - break; - case core::topology::HEXAHEDRARENUMBERING: ///< For HexahedraRenumbering. - break; - default: - break; - } - } -} - - -template <> -void BarycentricMapperHexahedronSetTopology::handleTopologyChange(core::topology::Topology* t) -{ - - if (t != this->fromTopology) return; - if ( this->fromTopology->beginChange() == this->fromTopology->endChange() ) - return; - - std::list::const_iterator itBegin = this->fromTopology->beginChange(); - std::list::const_iterator itEnd = this->fromTopology->endChange(); - - for ( std::list::const_iterator changeIt = itBegin; - changeIt != itEnd; ++changeIt ) - { - const core::topology::TopologyChangeType changeType = ( *changeIt )->getChangeType(); - switch ( changeType ) - { - //TODO: implementation of BarycentricMapperHexahedronSetTopology::handleTopologyChange() - case core::topology::ENDING_EVENT: ///< To notify the end for the current sequence of topological change events - { - if(!_invalidIndex.empty()) - { - helper::vector& mapData = *(map.beginEdit()); - - for ( std::set::const_iterator iter = _invalidIndex.begin(); - iter != _invalidIndex.end(); ++iter ) - { - const int j = *iter; - if ( mapData[j].in_index == -1 ) // compute new mapping - { - // std::cout << "BarycentricMapperHexahedronSetTopology : new mapping" << std::endl; - Vector3 coefs; - defaulttype::Vec3fTypes::Coord pos; - pos[0] = mapData[j].baryCoords[0]; - pos[1] = mapData[j].baryCoords[1]; - pos[2] = mapData[j].baryCoords[2]; - - // find nearest cell and barycentric coords - Real distance = 1e10; - - int index = _fromGeomAlgo->findNearestElementInRestPos ( pos, coefs, distance ); - - if ( index != -1 ) - { - mapData[j].baryCoords[0] = ( Real ) coefs[0]; - mapData[j].baryCoords[1] = ( Real ) coefs[1]; - mapData[j].baryCoords[2] = ( Real ) coefs[2]; - mapData[j].in_index = index; - } - } - } - - map.endEdit(); - _invalidIndex.clear(); - } - } - break; - case core::topology::POINTSINDICESSWAP: ///< For PointsIndicesSwap. - break; - case core::topology::POINTSADDED: ///< For PointsAdded. - break; - case core::topology::POINTSREMOVED: ///< For PointsRemoved. - break; - case core::topology::POINTSRENUMBERING: ///< For PointsRenumbering. - break; - case core::topology::TRIANGLESADDED: ///< For Triangles Added. - break; - case core::topology::TRIANGLESREMOVED: ///< For Triangles Removed. - break; - case core::topology::HEXAHEDRAADDED: ///< For HexahedraAdded. - { - } - break; - case core::topology::HEXAHEDRAREMOVED: ///< For HexahedraRemoved. - { - // std::cout << "BarycentricMapperHexahedronSetTopology() HEXAHEDRAREMOVED" << std::endl; - const unsigned int nbHexahedra = this->fromTopology->getNbHexahedra(); - - const sofa::helper::vector &hexahedra = ( static_cast< const core::topology::HexahedraRemoved *> ( *changeIt ) )->getArray(); - // sofa::helper::vector hexahedra(tab); - - for ( unsigned int i=0; igetRestPointPositionInHexahedron ( cubeId, coefs ); - - helper::vector& vectorData = *(map.beginEdit()); - vectorData[j].in_index = -1; - vectorData[j].baryCoords[0] = restPos[0]; - vectorData[j].baryCoords[1] = restPos[1]; - vectorData[j].baryCoords[2] = restPos[2]; - map.endEdit(); - - _invalidIndex.insert(j); - } - } - } - - // renumber - unsigned int lastCubeId = nbHexahedra-1; - for ( unsigned int i=0; i& vectorData = *(map.beginEdit()); - vectorData[j].in_index = cubeId; - map.endEdit(); - } - } - } - } - break; - case core::topology::HEXAHEDRARENUMBERING: ///< For HexahedraRenumbering. - break; - default: - break; - } - } -} - -#endif -#endif -*/ #ifndef SOFA_FLOAT template class SOFA_GPU_CUDA_API BarycentricMapping< CudaVec3fTypes, Rigid3dTypes >; -//template class SOFA_COMPONENT_MAPPING_API BarycentricMapper< CudaVec3fTypes, Rigid3dTypes >; -/*template class SOFA_COMPONENT_MAPPING_API TopologyBarycentricMapper< Vec3dTypes, Rigid3dTypes >; -template class SOFA_COMPONENT_MAPPING_API BarycentricMapperRegularGridTopology< Vec3dTypes, Rigid3dTypes >; -template class SOFA_COMPONENT_MAPPING_API BarycentricMapperSparseGridTopology< Vec3dTypes, Rigid3dTypes >; -template class SOFA_COMPONENT_MAPPING_API BarycentricMapperMeshTopology< Vec3dTypes, Rigid3dTypes >; -template class SOFA_COMPONENT_MAPPING_API BarycentricMapperEdgeSetTopology< Vec3dTypes, Rigid3dTypes >; -template class SOFA_COMPONENT_MAPPING_API BarycentricMapperTriangleSetTopology< Vec3dTypes, Rigid3dTypes >; -template class SOFA_COMPONENT_MAPPING_API BarycentricMapperQuadSetTopology< Vec3dTypes, Rigid3dTypes >; -template class SOFA_COMPONENT_MAPPING_API BarycentricMapperTetrahedronSetTopology< Vec3dTypes, Rigid3dTypes >; -template class SOFA_COMPONENT_MAPPING_API BarycentricMapperHexahedronSetTopology< Vec3dTypes, Rigid3dTypes >;*/ #endif -//#ifndef SOFA_DOUBLE -//template class SOFA_COMPONENT_MAPPING_API BarycentricMapping< CudaVec3fTypes, Rigid3fTypes >; -//template class SOFA_COMPONENT_MAPPING_API BarycentricMapper< CudaVec3fTypes, Rigid3fTypes >; -/*template class SOFA_COMPONENT_MAPPING_API TopologyBarycentricMapper< Vec3fTypes, Rigid3fTypes >; -template class SOFA_COMPONENT_MAPPING_API BarycentricMapperRegularGridTopology< Vec3fTypes, Rigid3fTypes >; -template class SOFA_COMPONENT_MAPPING_API BarycentricMapperSparseGridTopology< Vec3fTypes, Rigid3fTypes >; -template class SOFA_COMPONENT_MAPPING_API BarycentricMapperMeshTopology< Vec3fTypes, Rigid3fTypes >; -template class SOFA_COMPONENT_MAPPING_API BarycentricMapperEdgeSetTopology< Vec3fTypes, Rigid3fTypes >; -template class SOFA_COMPONENT_MAPPING_API BarycentricMapperTriangleSetTopology< Vec3fTypes, Rigid3fTypes >; -template class SOFA_COMPONENT_MAPPING_API BarycentricMapperQuadSetTopology< Vec3fTypes, Rigid3fTypes >; -template class SOFA_COMPONENT_MAPPING_API BarycentricMapperTetrahedronSetTopology< Vec3fTypes, Rigid3fTypes >; -template class SOFA_COMPONENT_MAPPING_API BarycentricMapperHexahedronSetTopology< Vec3fTypes, Rigid3fTypes >;*/ -//#endif -/*#ifndef SOFA_FLOAT -#ifndef SOFA_DOUBLE -template class SOFA_COMPONENT_MAPPING_API BarycentricMapping< CudaVec3fTypes, Rigid3fTypes >; -template class SOFA_COMPONENT_MAPPING_API BarycentricMapping< CudaVec3fTypes, Rigid3dTypes >; -template class SOFA_COMPONENT_MAPPING_API BarycentricMapper< CudaVec3fTypes, Rigid3fTypes >; -template class SOFA_COMPONENT_MAPPING_API BarycentricMapper< CudaVec3fTypes, Rigid3dTypes >; -template class SOFA_COMPONENT_MAPPING_API TopologyBarycentricMapper< Vec3dTypes, Rigid3fTypes >; -template class SOFA_COMPONENT_MAPPING_API TopologyBarycentricMapper< Vec3fTypes, Rigid3dTypes >; -template class SOFA_COMPONENT_MAPPING_API BarycentricMapperRegularGridTopology< Vec3dTypes, Rigid3fTypes >; -template class SOFA_COMPONENT_MAPPING_API BarycentricMapperRegularGridTopology< Vec3fTypes, Rigid3dTypes >; -template class SOFA_COMPONENT_MAPPING_API BarycentricMapperSparseGridTopology< Vec3dTypes, Rigid3fTypes >; -template class SOFA_COMPONENT_MAPPING_API BarycentricMapperSparseGridTopology< Vec3fTypes, Rigid3dTypes >; -template class SOFA_COMPONENT_MAPPING_API BarycentricMapperMeshTopology< Vec3dTypes, Rigid3fTypes >; -template class SOFA_COMPONENT_MAPPING_API BarycentricMapperMeshTopology< Vec3fTypes, Rigid3dTypes >; -template class SOFA_COMPONENT_MAPPING_API BarycentricMapperEdgeSetTopology< Vec3dTypes, Rigid3fTypes >; -template class SOFA_COMPONENT_MAPPING_API BarycentricMapperEdgeSetTopology< Vec3fTypes, Rigid3dTypes >; -template class SOFA_COMPONENT_MAPPING_API BarycentricMapperTriangleSetTopology< Vec3dTypes, Rigid3fTypes >; -template class SOFA_COMPONENT_MAPPING_API BarycentricMapperTriangleSetTopology< Vec3fTypes, Rigid3dTypes >; -template class SOFA_COMPONENT_MAPPING_API BarycentricMapperQuadSetTopology< Vec3dTypes, Rigid3fTypes >; -template class SOFA_COMPONENT_MAPPING_API BarycentricMapperQuadSetTopology< Vec3fTypes, Rigid3dTypes >; -template class SOFA_COMPONENT_MAPPING_API BarycentricMapperTetrahedronSetTopology< Vec3dTypes, Rigid3fTypes >; -template class SOFA_COMPONENT_MAPPING_API BarycentricMapperTetrahedronSetTopology< Vec3fTypes, Rigid3dTypes >; -template class SOFA_COMPONENT_MAPPING_API BarycentricMapperHexahedronSetTopology< Vec3dTypes, Rigid3fTypes >; -template class SOFA_COMPONENT_MAPPING_API BarycentricMapperHexahedronSetTopology< Vec3fTypes, Rigid3dTypes >; -#endif -#endif*/ - } // namespace mapping } // namespace component diff --git a/modules/SofaMiscMapping/BarycentricMappingRigid.cpp b/modules/SofaMiscMapping/BarycentricMappingRigid.cpp index e26017bf1da..cc159432e31 100644 --- a/modules/SofaMiscMapping/BarycentricMappingRigid.cpp +++ b/modules/SofaMiscMapping/BarycentricMappingRigid.cpp @@ -22,7 +22,6 @@ #define SOFA_COMPONENT_MAPPING_BARYCENTRICMAPPINGRIGID_CPP #include #include - #include #include #include From 425c9f8d6108e887beee6ed999604d4d0c1521b1 Mon Sep 17 00:00:00 2001 From: Damien Marchal Date: Fri, 30 Nov 2018 23:02:25 +0100 Subject: [PATCH 12/15] [BarycentricMappers] remove the SOFA_EXTERN_TEMPLATE macro in the .h --- .../BarycentricMappers/BarycentricMapper.h | 2 +- .../BarycentricMapperMeshTopology.h | 12 ++++++------ .../BarycentricMappers/TopologyBarycentricMapper.h | 2 +- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/SofaKernel/modules/SofaBaseMechanics/BarycentricMappers/BarycentricMapper.h b/SofaKernel/modules/SofaBaseMechanics/BarycentricMappers/BarycentricMapper.h index 5f3834d1146..48e06accb27 100644 --- a/SofaKernel/modules/SofaBaseMechanics/BarycentricMappers/BarycentricMapper.h +++ b/SofaKernel/modules/SofaBaseMechanics/BarycentricMappers/BarycentricMapper.h @@ -141,7 +141,7 @@ using sofa::defaulttype::Vec3fTypes; using sofa::defaulttype::ExtVec3fTypes; -#if defined(SOFA_EXTERN_TEMPLATE) && !defined(SOFA_COMPONENT_MAPPING_BARYCENTRICMAPPER_CPP) +#if !defined(SOFA_COMPONENT_MAPPING_BARYCENTRICMAPPER_CPP) #ifndef SOFA_FLOAT extern template class SOFA_BASE_MECHANICS_API BarycentricMapper< Vec3dTypes, Vec3dTypes >; extern template class SOFA_BASE_MECHANICS_API BarycentricMapper< Vec3dTypes, ExtVec3fTypes >; diff --git a/SofaKernel/modules/SofaBaseMechanics/BarycentricMappers/BarycentricMapperMeshTopology.h b/SofaKernel/modules/SofaBaseMechanics/BarycentricMappers/BarycentricMapperMeshTopology.h index 141470580a9..ca476797be0 100644 --- a/SofaKernel/modules/SofaBaseMechanics/BarycentricMappers/BarycentricMapperMeshTopology.h +++ b/SofaKernel/modules/SofaBaseMechanics/BarycentricMappers/BarycentricMapperMeshTopology.h @@ -33,8 +33,13 @@ namespace component namespace mapping { +/// Groupe the using as early as possible to make very obvious what are the +/// external dependencies of the following code. using core::visual::VisualParams; using sofa::defaulttype::BaseMatrix; +using sofa::defaulttype::Vec3dTypes; +using sofa::defaulttype::Vec3fTypes; +using sofa::defaulttype::ExtVec3fTypes; /// Class allowing barycentric mapping computation on a MeshTopology template @@ -107,12 +112,7 @@ class SOFA_BASE_MECHANICS_API BarycentricMapperMeshTopology : public TopologyBar void clearMap3dAndReserve(int size=0); }; -using sofa::defaulttype::Vec3dTypes; -using sofa::defaulttype::Vec3fTypes; -using sofa::defaulttype::ExtVec3fTypes; - - -#if defined(SOFA_EXTERN_TEMPLATE) && !defined(SOFA_COMPONENT_MAPPING_BARYCENTRICMAPPERMESHTOPOLOGY_CPP) +#if !defined(SOFA_COMPONENT_MAPPING_BARYCENTRICMAPPERMESHTOPOLOGY_CPP) #ifndef SOFA_FLOAT extern template class SOFA_BASE_MECHANICS_API BarycentricMapperMeshTopology< Vec3dTypes, Vec3dTypes >; extern template class SOFA_BASE_MECHANICS_API BarycentricMapperMeshTopology< Vec3dTypes, ExtVec3fTypes >; diff --git a/SofaKernel/modules/SofaBaseMechanics/BarycentricMappers/TopologyBarycentricMapper.h b/SofaKernel/modules/SofaBaseMechanics/BarycentricMappers/TopologyBarycentricMapper.h index 3d2b7570d9f..bf2fb62d71f 100644 --- a/SofaKernel/modules/SofaBaseMechanics/BarycentricMappers/TopologyBarycentricMapper.h +++ b/SofaKernel/modules/SofaBaseMechanics/BarycentricMappers/TopologyBarycentricMapper.h @@ -94,7 +94,7 @@ using sofa::defaulttype::Vec3fTypes; using sofa::defaulttype::ExtVec3fTypes; -#if defined(SOFA_EXTERN_TEMPLATE) && !defined(SOFA_COMPONENT_MAPPING_TOPOLOGYBARYCENTRICMAPPER_CPP) +#if !defined(SOFA_COMPONENT_MAPPING_TOPOLOGYBARYCENTRICMAPPER_CPP) #ifndef SOFA_FLOAT extern template class SOFA_BASE_MECHANICS_API TopologyBarycentricMapper< Vec3dTypes, Vec3dTypes >; extern template class SOFA_BASE_MECHANICS_API TopologyBarycentricMapper< Vec3dTypes, ExtVec3fTypes >; From e1be4c9e3225bf99024258ad271ff5e4424b75a6 Mon Sep 17 00:00:00 2001 From: Damien Marchal Date: Fri, 30 Nov 2018 23:19:04 +0100 Subject: [PATCH 13/15] [SofaMiscMapping] Remove a typo in MiscMapping.cpp --- modules/SofaMiscMapping/MiscMapping.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/SofaMiscMapping/MiscMapping.cpp b/modules/SofaMiscMapping/MiscMapping.cpp index 09f6af64dda..bb8aed9be88 100644 --- a/modules/SofaMiscMapping/MiscMapping.cpp +++ b/modules/SofaMiscMapping/MiscMapping.cpp @@ -32,4 +32,4 @@ class MiscMappingPlugin: public sofa::core::Plugin { } }; -SOFA_PLUGIN(MiscMappingPlugin); +SOFA_PLUGIN(MiscMappingPlugin) From 045dc029fa8e9dfb4040805e22f666d6cfdf18ad Mon Sep 17 00:00:00 2001 From: Damien Marchal Date: Fri, 30 Nov 2018 23:19:48 +0100 Subject: [PATCH 14/15] [SofaMiscMapping] Remove commented file in CMakeLists.txt --- modules/SofaMiscMapping/CMakeLists.txt | 18 ------------------ 1 file changed, 18 deletions(-) diff --git a/modules/SofaMiscMapping/CMakeLists.txt b/modules/SofaMiscMapping/CMakeLists.txt index 8718c19fa1b..cc1080ca26b 100644 --- a/modules/SofaMiscMapping/CMakeLists.txt +++ b/modules/SofaMiscMapping/CMakeLists.txt @@ -15,32 +15,20 @@ list(APPEND HEADER_FILES BarycentricMappingRigid.inl BeamLinearMapping.h BeamLinearMapping.inl - #CatmullRomSplineMapping.h - #CatmullRomSplineMapping.inl CenterOfMassMapping.h CenterOfMassMapping.inl CenterOfMassMulti2Mapping.h CenterOfMassMulti2Mapping.inl CenterOfMassMultiMapping.h CenterOfMassMultiMapping.inl - #CenterPointMechanicalMapping.h - #CenterPointMechanicalMapping.inl - #CurveMapping.h - #CurveMapping.inl DeformableOnRigidFrameMapping.h DeformableOnRigidFrameMapping.inl DistanceFromTargetMapping.h DistanceFromTargetMapping.inl DistanceMapping.h DistanceMapping.inl - #ExternalInterpolationMapping.h - #ExternalInterpolationMapping.inl IdentityMultiMapping.h IdentityMultiMapping.inl - #ProjectionToLineMapping.h - #ProjectionToLineMapping.inl - #ProjectionToPlaneMapping.h - #ProjectionToPlaneMapping.inl SquareDistanceMapping.h SquareDistanceMapping.inl SquareMapping.h @@ -54,19 +42,13 @@ list(APPEND HEADER_FILES list(APPEND SOURCE_FILES BarycentricMappingRigid.cpp BeamLinearMapping.cpp - #CatmullRomSplineMapping.cpp CenterOfMassMapping.cpp CenterOfMassMulti2Mapping.cpp CenterOfMassMultiMapping.cpp - #CenterPointMechanicalMapping.cpp - #CurveMapping.cpp DeformableOnRigidFrameMapping.cpp DistanceFromTargetMapping.cpp DistanceMapping.cpp - #ExternalInterpolationMapping.cpp IdentityMultiMapping.cpp - #ProjectionToLineMapping.cpp - #ProjectionToPlaneMapping.cpp SquareDistanceMapping.cpp SquareMapping.cpp SubsetMultiMapping.cpp From 9404ed1ba70a0efb58a87d4a7edf503cea8f78c9 Mon Sep 17 00:00:00 2001 From: Damien Marchal Date: Fri, 30 Nov 2018 23:39:59 +0100 Subject: [PATCH 15/15] [SofaBaseMechanics] Remove the SOFA_BASE_MECHANICS_API in the class declaration. --- .../BarycentricMappers/BarycentricMapper.h | 11 ++---- .../BarycentricMapperEdgeSetTopology.h | 3 +- .../BarycentricMapperHexahedronSetTopology.h | 10 ++--- .../BarycentricMapperMeshTopology.h | 2 +- .../BarycentricMapperQuadSetTopology.h | 12 ++---- .../BarycentricMapperRegularGridTopology.h | 9 ++--- .../BarycentricMapperSparseGridTopology.h | 10 ++--- .../BarycentricMapperTetrahedronSetTopology.h | 12 ++---- .../BarycentricMapperTopologyContainer.h | 22 +++++------ .../BarycentricMapperTriangleSetTopology.h | 12 +++--- .../TopologyBarycentricMapper.h | 11 +++--- .../SofaBaseMechanics/BarycentricMapping.h | 39 +++++++++---------- .../SofaBaseMechanics/BarycentricMapping.inl | 25 ++---------- 13 files changed, 68 insertions(+), 110 deletions(-) diff --git a/SofaKernel/modules/SofaBaseMechanics/BarycentricMappers/BarycentricMapper.h b/SofaKernel/modules/SofaBaseMechanics/BarycentricMappers/BarycentricMapper.h index 48e06accb27..767b925eb15 100644 --- a/SofaKernel/modules/SofaBaseMechanics/BarycentricMappers/BarycentricMapper.h +++ b/SofaKernel/modules/SofaBaseMechanics/BarycentricMappers/BarycentricMapper.h @@ -40,10 +40,13 @@ namespace _barycentricmapper_ using core::visual::VisualParams; using sofa::defaulttype::BaseMatrix; +using sofa::defaulttype::Vec3dTypes; +using sofa::defaulttype::Vec3fTypes; +using sofa::defaulttype::ExtVec3fTypes; /// Base class for barycentric mapping topology-specific mappers template -class SOFA_BASE_MECHANICS_API BarycentricMapper : public virtual core::objectmodel::BaseObject +class BarycentricMapper : public virtual core::objectmodel::BaseObject { public: @@ -135,12 +138,6 @@ class SOFA_BASE_MECHANICS_API BarycentricMapper : public virtual core::objectmod BarycentricMapper& operator=(const BarycentricMapper& n) ; }; - -using sofa::defaulttype::Vec3dTypes; -using sofa::defaulttype::Vec3fTypes; -using sofa::defaulttype::ExtVec3fTypes; - - #if !defined(SOFA_COMPONENT_MAPPING_BARYCENTRICMAPPER_CPP) #ifndef SOFA_FLOAT extern template class SOFA_BASE_MECHANICS_API BarycentricMapper< Vec3dTypes, Vec3dTypes >; diff --git a/SofaKernel/modules/SofaBaseMechanics/BarycentricMappers/BarycentricMapperEdgeSetTopology.h b/SofaKernel/modules/SofaBaseMechanics/BarycentricMappers/BarycentricMapperEdgeSetTopology.h index faf62b26693..cae71ce6e92 100644 --- a/SofaKernel/modules/SofaBaseMechanics/BarycentricMappers/BarycentricMapperEdgeSetTopology.h +++ b/SofaKernel/modules/SofaBaseMechanics/BarycentricMappers/BarycentricMapperEdgeSetTopology.h @@ -43,7 +43,7 @@ typedef typename sofa::core::topology::BaseMeshTopology::Edge Edge; /////// Class allowing barycentric mapping computation on a EdgeSetTopology template -class SOFA_BASE_MECHANICS_API BarycentricMapperEdgeSetTopology : public BarycentricMapperTopologyContainer::MappingData1D,Edge> +class BarycentricMapperEdgeSetTopology : public BarycentricMapperTopologyContainer::MappingData1D,Edge> { typedef typename BarycentricMapper::MappingData1D MappingData; @@ -86,7 +86,6 @@ class SOFA_BASE_MECHANICS_API BarycentricMapperEdgeSetTopology : public Barycent using Inherit1::m_updateJ; }; - #if !defined(SOFA_COMPONENT_MAPPING_BARYCENTRICMAPPEREDGESETTOPOLOGY_CPP) #ifndef SOFA_FLOAT extern template class SOFA_BASE_MECHANICS_API BarycentricMapperEdgeSetTopology< Vec3dTypes, Vec3dTypes>; diff --git a/SofaKernel/modules/SofaBaseMechanics/BarycentricMappers/BarycentricMapperHexahedronSetTopology.h b/SofaKernel/modules/SofaBaseMechanics/BarycentricMappers/BarycentricMapperHexahedronSetTopology.h index 2bed0cfbbb3..1b62ba7192c 100644 --- a/SofaKernel/modules/SofaBaseMechanics/BarycentricMappers/BarycentricMapperHexahedronSetTopology.h +++ b/SofaKernel/modules/SofaBaseMechanics/BarycentricMappers/BarycentricMapperHexahedronSetTopology.h @@ -35,13 +35,17 @@ namespace component namespace mapping { + using sofa::defaulttype::Mat3x3d; using sofa::defaulttype::Vector3; +using sofa::defaulttype::Vec3dTypes; +using sofa::defaulttype::Vec3fTypes; +using sofa::defaulttype::ExtVec3fTypes; typedef typename sofa::core::topology::BaseMeshTopology::Hexahedron Hexahedron; /// Class allowing barycentric mapping computation on a HexahedronSetTopology template -class SOFA_BASE_MECHANICS_API BarycentricMapperHexahedronSetTopology : public BarycentricMapperTopologyContainer::MappingData3D,Hexahedron> +class BarycentricMapperHexahedronSetTopology : public BarycentricMapperTopologyContainer::MappingData3D,Hexahedron> { typedef typename BarycentricMapper::MappingData3D MappingData; @@ -82,10 +86,6 @@ class SOFA_BASE_MECHANICS_API BarycentricMapperHexahedronSetTopology : public Ba using Inherit1::m_fromTopology; }; -using sofa::defaulttype::Vec3dTypes; -using sofa::defaulttype::Vec3fTypes; -using sofa::defaulttype::ExtVec3fTypes; - #if !defined(SOFA_COMPONENT_MAPPING_BARYCENTRICMAPPERHEXAHEDRONSETTOPOLOGY_CPP) #ifndef SOFA_FLOAT extern template class SOFA_BASE_MECHANICS_API BarycentricMapperHexahedronSetTopology< Vec3dTypes, Vec3dTypes >; diff --git a/SofaKernel/modules/SofaBaseMechanics/BarycentricMappers/BarycentricMapperMeshTopology.h b/SofaKernel/modules/SofaBaseMechanics/BarycentricMappers/BarycentricMapperMeshTopology.h index ca476797be0..1e69a74e79a 100644 --- a/SofaKernel/modules/SofaBaseMechanics/BarycentricMappers/BarycentricMapperMeshTopology.h +++ b/SofaKernel/modules/SofaBaseMechanics/BarycentricMappers/BarycentricMapperMeshTopology.h @@ -43,7 +43,7 @@ using sofa::defaulttype::ExtVec3fTypes; /// Class allowing barycentric mapping computation on a MeshTopology template -class SOFA_BASE_MECHANICS_API BarycentricMapperMeshTopology : public TopologyBarycentricMapper +class BarycentricMapperMeshTopology : public TopologyBarycentricMapper { public: SOFA_CLASS(SOFA_TEMPLATE2(BarycentricMapperMeshTopology,In,Out), diff --git a/SofaKernel/modules/SofaBaseMechanics/BarycentricMappers/BarycentricMapperQuadSetTopology.h b/SofaKernel/modules/SofaBaseMechanics/BarycentricMappers/BarycentricMapperQuadSetTopology.h index 9456cf621f4..7df600f546b 100644 --- a/SofaKernel/modules/SofaBaseMechanics/BarycentricMappers/BarycentricMapperQuadSetTopology.h +++ b/SofaKernel/modules/SofaBaseMechanics/BarycentricMappers/BarycentricMapperQuadSetTopology.h @@ -37,12 +37,14 @@ namespace mapping using sofa::defaulttype::Mat3x3d; using sofa::defaulttype::Vector3; - +using sofa::defaulttype::Vec3dTypes; +using sofa::defaulttype::Vec3fTypes; +using sofa::defaulttype::ExtVec3fTypes; typedef typename sofa::core::topology::BaseMeshTopology::Quad Quad; /// Class allowing barycentric mapping computation on a QuadSetTopology template -class SOFA_BASE_MECHANICS_API BarycentricMapperQuadSetTopology : public BarycentricMapperTopologyContainer::MappingData2D, Quad> +class BarycentricMapperQuadSetTopology : public BarycentricMapperTopologyContainer::MappingData2D, Quad> { typedef typename BarycentricMapper::MappingData2D MappingData; @@ -76,12 +78,6 @@ class SOFA_BASE_MECHANICS_API BarycentricMapperQuadSetTopology : public Barycent using Inherit1::m_updateJ; }; - -using sofa::defaulttype::Vec3dTypes; -using sofa::defaulttype::Vec3fTypes; -using sofa::defaulttype::ExtVec3fTypes; - - #if !defined(SOFA_COMPONENT_MAPPING_BARYCENTRICMAPPERQUADSETTOPOLOGY_CPP) #ifndef SOFA_FLOAT extern template class SOFA_BASE_MECHANICS_API BarycentricMapperQuadSetTopology< Vec3dTypes, Vec3dTypes >; diff --git a/SofaKernel/modules/SofaBaseMechanics/BarycentricMappers/BarycentricMapperRegularGridTopology.h b/SofaKernel/modules/SofaBaseMechanics/BarycentricMappers/BarycentricMapperRegularGridTopology.h index 4473074d84f..0fac4fe5182 100644 --- a/SofaKernel/modules/SofaBaseMechanics/BarycentricMappers/BarycentricMapperRegularGridTopology.h +++ b/SofaKernel/modules/SofaBaseMechanics/BarycentricMappers/BarycentricMapperRegularGridTopology.h @@ -36,12 +36,15 @@ namespace mapping using core::visual::VisualParams; using sofa::defaulttype::BaseMatrix; +using sofa::defaulttype::Vec3dTypes; +using sofa::defaulttype::Vec3fTypes; +using sofa::defaulttype::ExtVec3fTypes; using topology::RegularGridTopology; using topology::PointSetTopologyContainer; /// Class allowing barycentric mapping computation on a RegularGridTopology template -class SOFA_BASE_MECHANICS_API BarycentricMapperRegularGridTopology : public TopologyBarycentricMapper +class BarycentricMapperRegularGridTopology : public TopologyBarycentricMapper { public: SOFA_CLASS(SOFA_TEMPLATE2(BarycentricMapperRegularGridTopology,In,Out),SOFA_TEMPLATE2(TopologyBarycentricMapper,In,Out)); @@ -89,10 +92,6 @@ class SOFA_BASE_MECHANICS_API BarycentricMapperRegularGridTopology : public Topo bool m_updateJ {false}; }; -using sofa::defaulttype::Vec3dTypes; -using sofa::defaulttype::Vec3fTypes; -using sofa::defaulttype::ExtVec3fTypes; - #if !defined(SOFA_COMPONENT_MAPPING_BARYCENTRICMAPPERREGULARGRIDTOPOLOGY_CPP) #ifndef SOFA_FLOAT extern template class SOFA_BASE_MECHANICS_API BarycentricMapperRegularGridTopology< Vec3dTypes, Vec3dTypes >; diff --git a/SofaKernel/modules/SofaBaseMechanics/BarycentricMappers/BarycentricMapperSparseGridTopology.h b/SofaKernel/modules/SofaBaseMechanics/BarycentricMappers/BarycentricMapperSparseGridTopology.h index e25b6b352f2..5d0505e8cae 100644 --- a/SofaKernel/modules/SofaBaseMechanics/BarycentricMappers/BarycentricMapperSparseGridTopology.h +++ b/SofaKernel/modules/SofaBaseMechanics/BarycentricMappers/BarycentricMapperSparseGridTopology.h @@ -36,10 +36,13 @@ namespace mapping using sofa::defaulttype::BaseMatrix; using core::visual::VisualParams; +using sofa::defaulttype::Vec3dTypes; +using sofa::defaulttype::Vec3fTypes; +using sofa::defaulttype::ExtVec3fTypes; /// Class allowing barycentric mapping computation on a SparseGridTopology template -class SOFA_BASE_MECHANICS_API BarycentricMapperSparseGridTopology : public TopologyBarycentricMapper +class BarycentricMapperSparseGridTopology : public TopologyBarycentricMapper { public: @@ -88,11 +91,6 @@ class SOFA_BASE_MECHANICS_API BarycentricMapperSparseGridTopology : public Topol bool m_updateJ {false}; }; - -using sofa::defaulttype::Vec3dTypes; -using sofa::defaulttype::Vec3fTypes; -using sofa::defaulttype::ExtVec3fTypes; - #if !defined(SOFA_COMPONENT_MAPPING_BARYCENTRICMAPPERSPARSEGRIDTOPOLOGY_CPP) #ifndef SOFA_FLOAT extern template class SOFA_BASE_MECHANICS_API BarycentricMapperSparseGridTopology< Vec3dTypes, Vec3dTypes >; diff --git a/SofaKernel/modules/SofaBaseMechanics/BarycentricMappers/BarycentricMapperTetrahedronSetTopology.h b/SofaKernel/modules/SofaBaseMechanics/BarycentricMappers/BarycentricMapperTetrahedronSetTopology.h index 53bffae15e8..5bce5f5d182 100644 --- a/SofaKernel/modules/SofaBaseMechanics/BarycentricMappers/BarycentricMapperTetrahedronSetTopology.h +++ b/SofaKernel/modules/SofaBaseMechanics/BarycentricMappers/BarycentricMapperTetrahedronSetTopology.h @@ -36,14 +36,16 @@ namespace mapping { +using sofa::defaulttype::Vec3dTypes; +using sofa::defaulttype::Vec3fTypes; +using sofa::defaulttype::ExtVec3fTypes; using sofa::defaulttype::Mat3x3d; using sofa::defaulttype::Vector3; typedef typename sofa::core::topology::BaseMeshTopology::Tetrahedron Tetrahedron; - /// Class allowing barycentric mapping computation on a TetrahedronSetTopology template -class SOFA_BASE_MECHANICS_API BarycentricMapperTetrahedronSetTopology : public BarycentricMapperTopologyContainer::MappingData3D,Tetrahedron> +class BarycentricMapperTetrahedronSetTopology : public BarycentricMapperTopologyContainer::MappingData3D,Tetrahedron> { typedef typename BarycentricMapper::MappingData3D MappingData; @@ -76,12 +78,6 @@ class SOFA_BASE_MECHANICS_API BarycentricMapperTetrahedronSetTopology : public B using Inherit1::m_updateJ; }; - -using sofa::defaulttype::Vec3dTypes; -using sofa::defaulttype::Vec3fTypes; -using sofa::defaulttype::ExtVec3fTypes; - - #if !defined(SOFA_COMPONENT_MAPPING_BARYCENTRICMAPPERTETRAHEDRONSETTOPOLOGY_CPP) #ifndef SOFA_FLOAT extern template class SOFA_BASE_MECHANICS_API BarycentricMapperTetrahedronSetTopology< Vec3dTypes, Vec3dTypes >; diff --git a/SofaKernel/modules/SofaBaseMechanics/BarycentricMappers/BarycentricMapperTopologyContainer.h b/SofaKernel/modules/SofaBaseMechanics/BarycentricMappers/BarycentricMapperTopologyContainer.h index d9120f7ac0d..c0e20cbf7db 100644 --- a/SofaKernel/modules/SofaBaseMechanics/BarycentricMappers/BarycentricMapperTopologyContainer.h +++ b/SofaKernel/modules/SofaBaseMechanics/BarycentricMappers/BarycentricMapperTopologyContainer.h @@ -39,11 +39,18 @@ namespace _barycentricmappertopologycontainer_ using sofa::defaulttype::Mat3x3d; using sofa::defaulttype::Vector3; - +using sofa::defaulttype::Vec3dTypes; +using sofa::defaulttype::Vec3fTypes; +using sofa::defaulttype::ExtVec3fTypes; +typedef typename sofa::core::topology::BaseMeshTopology::Edge Edge; +typedef typename sofa::core::topology::BaseMeshTopology::Triangle Triangle; +typedef typename sofa::core::topology::BaseMeshTopology::Quad Quad; +typedef typename sofa::core::topology::BaseMeshTopology::Tetrahedron Tetrahedron; +typedef typename sofa::core::topology::BaseMeshTopology::Hexahedron Hexahedron; /// Template class for topology container mappers template -class SOFA_BASE_MECHANICS_API BarycentricMapperTopologyContainer : public TopologyBarycentricMapper +class BarycentricMapperTopologyContainer : public TopologyBarycentricMapper { public: @@ -97,17 +104,6 @@ class SOFA_BASE_MECHANICS_API BarycentricMapperTopologyContainer : public Topolo bool m_updateJ {nullptr}; }; - -using sofa::defaulttype::Vec3dTypes; -using sofa::defaulttype::Vec3fTypes; -using sofa::defaulttype::ExtVec3fTypes; -typedef typename sofa::core::topology::BaseMeshTopology::Edge Edge; -typedef typename sofa::core::topology::BaseMeshTopology::Triangle Triangle; -typedef typename sofa::core::topology::BaseMeshTopology::Quad Quad; -typedef typename sofa::core::topology::BaseMeshTopology::Tetrahedron Tetrahedron; -typedef typename sofa::core::topology::BaseMeshTopology::Hexahedron Hexahedron; - - #if !defined(SOFA_COMPONENT_MAPPING_BARYCENTRICMAPPERTOPOLOGYCONTAINER_CPP) #ifndef SOFA_FLOAT extern template class SOFA_BASE_MECHANICS_API BarycentricMapperTopologyContainer< Vec3dTypes, Vec3dTypes , typename BarycentricMapper::MappingData1D, Edge>; diff --git a/SofaKernel/modules/SofaBaseMechanics/BarycentricMappers/BarycentricMapperTriangleSetTopology.h b/SofaKernel/modules/SofaBaseMechanics/BarycentricMappers/BarycentricMapperTriangleSetTopology.h index d05acad41a6..731bc69d276 100644 --- a/SofaKernel/modules/SofaBaseMechanics/BarycentricMappers/BarycentricMapperTriangleSetTopology.h +++ b/SofaKernel/modules/SofaBaseMechanics/BarycentricMappers/BarycentricMapperTriangleSetTopology.h @@ -37,12 +37,15 @@ namespace mapping using sofa::defaulttype::Mat3x3d; using sofa::defaulttype::Vector3; -typedef typename sofa::core::topology::BaseMeshTopology::Triangle Triangle; +using sofa::defaulttype::Vec3dTypes; +using sofa::defaulttype::Vec3fTypes; +using sofa::defaulttype::ExtVec3fTypes; +typedef typename sofa::core::topology::BaseMeshTopology::Triangle Triangle; /// Class allowing barycentric mapping computation on a TriangleSetTopology template -class SOFA_BASE_MECHANICS_API BarycentricMapperTriangleSetTopology : public BarycentricMapperTopologyContainer::MappingData2D,Triangle> +class BarycentricMapperTriangleSetTopology : public BarycentricMapperTopologyContainer::MappingData2D,Triangle> { typedef typename BarycentricMapper::MappingData2D MappingData; public: @@ -76,11 +79,6 @@ class SOFA_BASE_MECHANICS_API BarycentricMapperTriangleSetTopology : public Bary using Inherit1::m_updateJ; }; - -using sofa::defaulttype::Vec3dTypes; -using sofa::defaulttype::Vec3fTypes; -using sofa::defaulttype::ExtVec3fTypes; - #if !defined(SOFA_COMPONENT_MAPPING_BARYCENTRICMAPPERTRIANGLESETTOPOLOGY_CPP) #ifndef SOFA_FLOAT extern template class SOFA_BASE_MECHANICS_API BarycentricMapperTriangleSetTopology< Vec3dTypes, Vec3dTypes >; diff --git a/SofaKernel/modules/SofaBaseMechanics/BarycentricMappers/TopologyBarycentricMapper.h b/SofaKernel/modules/SofaBaseMechanics/BarycentricMappers/TopologyBarycentricMapper.h index bf2fb62d71f..5985f722e76 100644 --- a/SofaKernel/modules/SofaBaseMechanics/BarycentricMappers/TopologyBarycentricMapper.h +++ b/SofaKernel/modules/SofaBaseMechanics/BarycentricMappers/TopologyBarycentricMapper.h @@ -36,9 +36,13 @@ namespace mapping namespace _topologybarycentricmapper_ { +using sofa::defaulttype::Vec3dTypes; +using sofa::defaulttype::Vec3fTypes; +using sofa::defaulttype::ExtVec3fTypes; + /// Template class for barycentric mapping topology-specific mappers. template -class SOFA_BASE_MECHANICS_API TopologyBarycentricMapper : public BarycentricMapper +class TopologyBarycentricMapper : public BarycentricMapper { public: SOFA_CLASS(SOFA_TEMPLATE2(TopologyBarycentricMapper,In,Out), @@ -89,11 +93,6 @@ class SOFA_BASE_MECHANICS_API TopologyBarycentricMapper : public BarycentricMapp topology::PointSetTopologyContainer* m_toTopology; }; -using sofa::defaulttype::Vec3dTypes; -using sofa::defaulttype::Vec3fTypes; -using sofa::defaulttype::ExtVec3fTypes; - - #if !defined(SOFA_COMPONENT_MAPPING_TOPOLOGYBARYCENTRICMAPPER_CPP) #ifndef SOFA_FLOAT extern template class SOFA_BASE_MECHANICS_API TopologyBarycentricMapper< Vec3dTypes, Vec3dTypes >; diff --git a/SofaKernel/modules/SofaBaseMechanics/BarycentricMapping.h b/SofaKernel/modules/SofaBaseMechanics/BarycentricMapping.h index dfa5c6c0c25..5910eef2e7a 100644 --- a/SofaKernel/modules/SofaBaseMechanics/BarycentricMapping.h +++ b/SofaKernel/modules/SofaBaseMechanics/BarycentricMapping.h @@ -47,13 +47,17 @@ namespace component namespace mapping { +using sofa::defaulttype::Vec3dTypes; +using sofa::defaulttype::Vec3fTypes; +using sofa::defaulttype::ExtVec3fTypes; + template class BarycentricMapping : public core::Mapping { public: - SOFA_CLASS(SOFA_TEMPLATE2(BarycentricMapping,TIn,TOut), SOFA_TEMPLATE2(core::Mapping,TIn,TOut)); + SOFA_CLASS(SOFA_TEMPLATE2(BarycentricMapping,TIn,TOut), + SOFA_TEMPLATE2(core::Mapping,TIn,TOut)); - typedef core::Mapping Inherit; typedef TIn In; typedef TOut Out; typedef In InDataTypes; @@ -71,10 +75,12 @@ class BarycentricMapping : public core::Mapping typedef core::topology::BaseMeshTopology BaseMeshTopology; typedef TopologyBarycentricMapper Mapper; - typedef typename Inherit::ForceMask ForceMask; + typedef typename Inherit1::ForceMask ForceMask; public: - Data< bool > useRestPosition; ///< Use the rest position of the input and output models to initialize the mapping + Data< bool > useRestPosition; ///< Use the rest position of the input and output models to initialize the mapping + + SingleLink,Mapper,BaseLink::FLAG_STRONGLINK> m_mapper; virtual void init() override; virtual void reinit() override; @@ -88,7 +94,7 @@ class BarycentricMapping : public core::Mapping virtual void draw(const core::visual::VisualParams* vparams) override; virtual void handleTopologyChange(core::topology::Topology* t) override; - // interface for continuous friction contact + /// interface for continuous friction contact TopologyBarycentricMapper *getMapper() { return m_mapper.get(); @@ -97,21 +103,18 @@ class BarycentricMapping : public core::Mapping protected: typedef linearsolver::EigenSparseMatrix eigen_type; - // eigen matrix for use with Compliant plugin - eigen_type eigen; - helper::vector< defaulttype::BaseMatrix* > js; - - BarycentricMapping(); BarycentricMapping(core::State* from, core::State* to, typename Mapper::SPtr m_mapper); - BarycentricMapping(core::State* from, core::State* to, + BarycentricMapping(core::State* from=nullptr, core::State* to=nullptr, BaseMeshTopology * topology=nullptr ); - SingleLink,Mapper,BaseLink::FLAG_STRONGLINK> m_mapper; - - virtual ~BarycentricMapping() override; + virtual ~BarycentricMapping() override {} virtual void updateForceMask() override; + /// eigen matrix for use with Compliant plugin + eigen_type eigen; + helper::vector< defaulttype::BaseMatrix* > js; + sofa::core::topology::BaseMeshTopology* topology_from; sofa::core::topology::BaseMeshTopology* topology_to; @@ -119,13 +122,7 @@ class BarycentricMapping : public core::Mapping void createMapperFromTopology(BaseMeshTopology * topology); }; - -using sofa::defaulttype::Vec3dTypes; -using sofa::defaulttype::Vec3fTypes; -using sofa::defaulttype::ExtVec3fTypes; - - -#if !defined(SOFA_COMPONENT_MAPPING_BARYCENTRICMAPPING_CPP) +#if !defined(SOFA_COMPONENT_MAPPING_BARYCENTRICMAPPING_CPP) #ifndef SOFA_FLOAT extern template class SOFA_BASE_MECHANICS_API BarycentricMapping< Vec3dTypes, Vec3dTypes >; extern template class SOFA_BASE_MECHANICS_API BarycentricMapping< Vec3dTypes, ExtVec3fTypes >; diff --git a/SofaKernel/modules/SofaBaseMechanics/BarycentricMapping.inl b/SofaKernel/modules/SofaBaseMechanics/BarycentricMapping.inl index 137104cc1d3..51e1d1111c7 100644 --- a/SofaKernel/modules/SofaBaseMechanics/BarycentricMapping.inl +++ b/SofaKernel/modules/SofaBaseMechanics/BarycentricMapping.inl @@ -86,17 +86,9 @@ typedef typename sofa::core::topology::BaseMeshTopology::SeqQuads SeqQuads; typedef typename sofa::core::topology::BaseMeshTopology::SeqTetrahedra SeqTetrahedra; typedef typename sofa::core::topology::BaseMeshTopology::SeqHexahedra SeqHexahedra; -template -BarycentricMapping::BarycentricMapping() - : Inherit() - , m_mapper(initLink("mapper","Internal mapper created depending on the type of topology")) - , useRestPosition(core::objectmodel::Base::initData(&useRestPosition, false, "useRestPosition", "Use the rest position of the input and output models to initialize the mapping")) -{ -} - template BarycentricMapping::BarycentricMapping(core::State* from, core::State* to, typename Mapper::SPtr mapper) - : Inherit ( from, to ) + : Inherit1 ( from, to ) , m_mapper(initLink("mapper","Internal mapper created depending on the type of topology"), mapper) { @@ -106,7 +98,7 @@ BarycentricMapping::BarycentricMapping(core::State* from, core::S template BarycentricMapping::BarycentricMapping (core::State* from, core::State* to, BaseMeshTopology * topology ) - : Inherit ( from, to ) + : Inherit1 ( from, to ) , m_mapper (initLink("mapper","Internal mapper created depending on the type of topology")) { if (topology) @@ -115,18 +107,12 @@ BarycentricMapping::BarycentricMapping (core::State* from, core:: } } -template -BarycentricMapping::~BarycentricMapping() -{ -} - - template void BarycentricMapping::createMapperFromTopology ( BaseMeshTopology * topology ) { using sofa::core::behavior::BaseMechanicalState; - m_mapper = NULL; + m_mapper = nullptr; topology::PointSetTopologyContainer* toTopoCont; this->toModel->getContext()->get(toTopoCont); @@ -234,7 +220,7 @@ void BarycentricMapping::init() topology_from = this->fromModel->getContext()->getMeshTopology(); topology_to = this->toModel->getContext()->getMeshTopology(); - Inherit::init(); + Inherit1::init(); if ( m_mapper == NULL ) // try to create a mapper according to the topology of the In model { @@ -282,9 +268,6 @@ void BarycentricMapping::apply(const core::MechanicalParams * mparams } } - - - template void BarycentricMapping::applyJ (const core::MechanicalParams * mparams, Data< typename Out::VecDeriv >& _out, const Data< typename In::VecDeriv >& in) {