diff --git a/SofaKernel/framework/sofa/helper/system/PluginManager.cpp b/SofaKernel/framework/sofa/helper/system/PluginManager.cpp index f5343d1fd4f..835657650ab 100644 --- a/SofaKernel/framework/sofa/helper/system/PluginManager.cpp +++ b/SofaKernel/framework/sofa/helper/system/PluginManager.cpp @@ -255,6 +255,9 @@ std::string PluginManager::findPlugin(const std::string& pluginName, bool ignore std::string name(pluginName); #ifdef SOFA_LIBSUFFIX name += sofa_tostring(SOFA_LIBSUFFIX); +#endif +#if defined(_DEBUG) && defined(_MSC_VER) + name += "_d"; #endif const std::string libName = DynamicLibrary::prefix + name + "." + DynamicLibrary::extension; diff --git a/SofaKernel/modules/SofaBaseTopology/SofaBaseTopology_test/BezierTetrahedronTopology_test.cpp b/SofaKernel/modules/SofaBaseTopology/SofaBaseTopology_test/BezierTetrahedronTopology_test.cpp deleted file mode 100644 index aba4187e09d..00000000000 --- a/SofaKernel/modules/SofaBaseTopology/SofaBaseTopology_test/BezierTetrahedronTopology_test.cpp +++ /dev/null @@ -1,320 +0,0 @@ -/****************************************************************************** -* SOFA, Simulation Open-Framework Architecture, development version * -* (c) 2006-2016 INRIA, USTL, UJF, CNRS, MGH * -* * -* This program is free software; you can redistribute it and/or modify it * -* under the terms of the GNU General Public License as published by the Free * -* Software Foundation; either version 2 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 General Public License for * -* more details. * -* * -* You should have received a copy of the GNU General Public License along * -* with this program; if not, write to the Free Software Foundation, Inc., 51 * -* Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * -******************************************************************************* -* SOFA :: Applications * -* * -* Authors: The SOFA Team and external contributors (see Authors.txt) * -* * -* Contact information: contact@sofa-framework.org * -******************************************************************************/ -#include -#include -#include -#include - -//Including Simulation -#include -#include -#include - -// Including constraint, force and mass -#include -#include -#include -#include -#include -#include -#include -#include -#include - -namespace sofa { - -using std::cout; -using std::cerr; -using std::endl; -using namespace component; -using namespace defaulttype; - -/** Test the topology and geometry of Bezier Tetrahedral meshes. -No deformation is applied but only the init() function is called to create a Bezier Tetrahedral mesh from a a regular tetraheral mesh */ - -template -struct BezierTetrahedronTopology_test : public Sofa_test -{ - typedef _DataTypes DataTypes; - typedef typename DataTypes::VecCoord VecCoord; - typedef typename DataTypes::VecDeriv VecDeriv; - typedef typename DataTypes::Deriv Deriv; - typedef typename DataTypes::Coord Coord; - typedef typename DataTypes::Real Real; - typedef typename sofa::component::topology::BezierTetrahedronSetTopologyContainer BezierTetrahedronSetTopologyContainer; - typedef typename sofa::component::topology::BezierTetrahedronSetGeometryAlgorithms BezierTetrahedronSetGeometryAlgorithms; - typedef typename sofa::component::topology::BezierDegreeType BezierDegreeType; - typedef typename sofa::component::topology::TetrahedronBezierIndex TetrahedronBezierIndex; - typedef typename BezierTetrahedronSetTopologyContainer::BezierTetrahedronPointLocation BezierTetrahedronPointLocation; - typedef typename container::MechanicalObject MechanicalObject; - typedef typename sofa::component::mass::MeshMatrixMass MeshMatrixMass; - - - /// Root of the scene graph - simulation::Node::SPtr root; - /// Simulation - simulation::Simulation* simulation; - - // Create the context for the scene - void SetUp() - { - // Init simulation - sofa::simulation::setSimulation(simulation = new sofa::simulation::graph::DAGSimulation()); - - root = simulation::getSimulation()->createNewGraph("root"); - } - // Load the scene BezierTetrahedronTopology.scn from the scenes directory - void loadScene(std::string sceneName) - { - // Load the scene from the xml file - std::string fileName = std::string(SOFABASETOPOLOGY_TEST_SCENES_DIR) + "/" + sceneName; - root = sofa::simulation::getSimulation()->load(fileName.c_str()); - } - // Load the scene BezierTetrahedronTopology.sc from the Scenes directory - void createScene() - { - // GenerateCylinder object - typename sofa::component::engine::GenerateCylinder::SPtr eng= sofa::modeling::addNew >(root,"cylinder"); - eng->f_radius=0.2; - eng->f_height=1.0; - // TetrahedronSetTopologyContainer object - sofa::component::topology::TetrahedronSetTopologyContainer::SPtr container1= sofa::modeling::addNew(root,"Container1"); - sofa::modeling::setDataLink(&eng->f_tetrahedra,&container1->d_tetrahedron); - sofa::modeling::setDataLink(&eng->f_outputTetrahedraPositions,&container1->d_initPoints); - // TetrahedronSetGeometryAlgorithms object - typename sofa::component::topology::TetrahedronSetGeometryAlgorithms::SPtr geo1= sofa::modeling::addNew >(root); - // mechanicalObject object - typename MechanicalObject::SPtr meca1= sofa::modeling::addNew(root); - sofa::modeling::setDataLink(&eng->f_outputTetrahedraPositions,&meca1->x); - // subnode - simulation::Node::SPtr bezierNode = root->createChild("BezierTetrahedronTopology"); - // BezierTetrahedronSetTopologyContainer - sofa::component::topology::BezierTetrahedronSetTopologyContainer::SPtr container2= sofa::modeling::addNew(bezierNode,"Container2"); - // Mesh2BezierTopologicalMapping - sofa::component::topology::Mesh2BezierTopologicalMapping::SPtr mapping= sofa::modeling::addNew(bezierNode,"Mapping"); - mapping->setTopologies(container1.get(),container2.get()); - mapping->bezierTetrahedronDegree=3; - // mechanicalObject object - typename MechanicalObject::SPtr meca2= sofa::modeling::addNew(bezierNode,"BezierMechanicalObject"); - // BezierTetrahedronSetGeometryAlgorithms - typename sofa::component::topology::BezierTetrahedronSetGeometryAlgorithms::SPtr geo2= sofa::modeling::addNew >(bezierNode); - // MeshMatrixMass - typename MeshMatrixMass::SPtr mass= sofa::modeling::addNew(bezierNode,"BezierMass"); - mass->m_massDensity=1.0; - mass->d_integrationMethod.setValue(std::string("analytical")); - } - bool testBezierTetrahedronTopology() - { - // Init simulation - sofa::simulation::getSimulation()->init(root.get()); - BezierTetrahedronSetTopologyContainer *container=root->get(root->SearchDown); - size_t nTetras,elem; - BezierDegreeType degree=container->getDegree(); - // check the total number of vertices. - size_t nbPoints=container->getNumberOfTetrahedralPoints()+container->getNumberOfEdges()*(degree-1)+container->getNumberOfTriangles()*(degree-1)*(degree-2)/2+container->getNumberOfTetrahedra()*((degree-1)*(degree-2)*(degree-3)/6); - if((size_t)container->getNbPoints()!=nbPoints) { - ADD_FAILURE() << "wrong number of points " <getNbPoints() << " is wrong. It should be " < tbiArray=container->getTetrahedronBezierIndexArray(); - - BezierTetrahedronPointLocation location; - size_t elementIndex, elementOffset/*,localIndex*/; - for (nTetras=0;nTetrasgetNumberOfTetrahedra();++nTetras) { - - const BezierTetrahedronSetTopologyContainer::VecPointID &indexArray=container->getGlobalIndexArrayOfBezierPoints(nTetras); - // check the number of control points per tetrahedron is correct - nbPoints=(4+6*(degree-1)+2*(degree-1)*(degree-2)+(degree-1)*(degree-2)*(degree-3)/6); - if(indexArray.size()!=nbPoints) { - ADD_FAILURE() << "wrong number of control points in tetrahedron " <getGlobalIndexOfBezierPoint(nTetras,tbiArray[elem]); - // check that getGlobalIndexOfBezierPoint and getGlobalIndexArrayOfBezierPointsInTetrahedron give the same answer - if(globalIndex!=indexArray[elem]) { - ADD_FAILURE() << "wrong global index given by getGlobalIndexOfBezierPoint(). It is : "<getTetrahedronBezierIndex(elem); - if(elem!=container->getLocalIndexFromTetrahedronBezierIndex(tbi)) { - ADD_FAILURE() << "wrong local index given by getLocalIndexFromTetrahedronBezierIndex(). It is : "<getLocalIndexFromTetrahedronBezierIndex(tbi) <<" and should be "<getLocationFromGlobalIndex(globalIndex,location,elementIndex,elementOffset); - if (elem<4) { - if ((location!=BezierTetrahedronSetTopologyContainer::POINT) || (elementIndex!=container->getTetrahedron(nTetras)[elem]) || (elementOffset!=0)) { - ADD_FAILURE() << "non consistent indices given by getLocationFromGlobalIndex() for global index : "<getEdgesInTetrahedron(nTetras)[(elem-4)/(degree-1)])) { - ADD_FAILURE() << "non consistent indices given by getLocationFromGlobalIndex() for global index : "<getTrianglesInTetrahedron(nTetras)[val])) { - ADD_FAILURE() << "non consistent indices given by getLocationFromGlobalIndex() for global index : "<get(root->SearchDown); - typename MechanicalObject::SPtr dofs = root->get(std::string("BezierTetrahedronTopology/")); - typename MechanicalObject::WriteVecCoord coords = dofs->writePositions(); - size_t i,j; - BezierDegreeType degree=container->getDegree(); - - sofa::helper::vector tbiArray=container->getTetrahedronBezierIndexArray(); - for ( i = 0; igetNumberOfTetrahedra(); i++) - { - - const BezierTetrahedronSetTopologyContainer::VecPointID &indexArray=container->getGlobalIndexArrayOfBezierPoints(i); - - - for (j=0;j=4) { - // test if the position is correct - Coord pos=coords[indexArray[0]]*(Real)tbiArray[j][0]/degree+coords[indexArray[1]]*(Real)tbiArray[j][1]/degree+coords[indexArray[2]]*(Real)tbiArray[j][2]/degree+coords[indexArray[3]]*(Real)tbiArray[j][3]/degree; - if ((pos-coords[indexArray[j]]).norm()>1e-5) { - ADD_FAILURE() << "Wrong control point position in tetrahedron no : "<get(root->SearchDown); - BezierTetrahedronSetGeometryAlgorithms *geo=root->get(root->SearchDown); - - typename MechanicalObject::SPtr dofs = root->get(std::string("BezierTetrahedronTopology/")); - typename MechanicalObject::WriteVecCoord coords = dofs->writePositions(); - MeshMatrixMass *mass=root->get(root->SearchDown); - const sofa::helper::vector & mv=mass->tetrahedronMassInfo.getValue(); - const sofa::helper::vector &ma =mass->vertexMassInfo.getValue(); - - size_t i,j,k,rank; - BezierDegreeType degree=container->getDegree(); - Real tetraVol1,tetraVol2,totalVol1,totalVol2; - - sofa::helper::vector tbiArray=container->getTetrahedronBezierIndexArray(); - size_t nbControlPoints=(degree+1)*(degree+2)*(degree+3)/6; - totalVol1=0; - for ( i = 0; igetNumberOfTetrahedra(); i++) - { - -// const BezierTetrahedronSetTopologyContainer::VecPointID &indexArray=container->getGlobalIndexArrayOfBezierPoints(i); - - - /// get the volume of the tetrahedron - tetraVol1=geo->computeTetrahedronVolume(i); - tetraVol2=0; - // compute the total volume - totalVol1+=tetraVol1; - /// check that the sum of the volume matrix elements is equal to the volume of the tetrahedron - for (rank=0,j=0;j1e-5) { - ADD_FAILURE() << "Wrong mass matrix in tetrahedron no : "<1e-5) { - ADD_FAILURE() << "Wrong total vertex mass value." - << " Got total vertex mass="<unload(root); -// cerr<<"tearing down"< DataTypes; // the types to instanciate. - -// Test suite for all the instanciations -TYPED_TEST_CASE(BezierTetrahedronTopology_test, DataTypes); - -// first test topology -TYPED_TEST( BezierTetrahedronTopology_test , testTopology ) -{ -// this->loadScene( "tests/SofaTest/BezierTetrahedronTopology.scn"); - this->createScene(); - ASSERT_TRUE( this->testBezierTetrahedronTopology()); - ASSERT_TRUE( this->testBezierTetrahedronGeometry()); - ASSERT_TRUE( this->testBezierTetrahedronMass()); -} - - - -} // namespace sofa diff --git a/SofaKernel/modules/SofaBaseTopology/SofaBaseTopology_test/CMakeLists.txt b/SofaKernel/modules/SofaBaseTopology/SofaBaseTopology_test/CMakeLists.txt index 020d6956bf8..b62f816158f 100644 --- a/SofaKernel/modules/SofaBaseTopology/SofaBaseTopology_test/CMakeLists.txt +++ b/SofaKernel/modules/SofaBaseTopology/SofaBaseTopology_test/CMakeLists.txt @@ -3,7 +3,6 @@ cmake_minimum_required(VERSION 2.8.12) project(SofaBaseTopology_test) set(SOURCE_FILES - BezierTetrahedronTopology_test.cpp TetrahedronNumericalIntegration_test.cpp) add_definitions("-DSOFABASETOPOLOGY_TEST_SCENES_DIR=\"${CMAKE_CURRENT_SOURCE_DIR}/scenes\"") diff --git a/SofaKernel/modules/SofaBaseTopology/SofaBaseTopology_test/scenes/BezierTetrahedronTopology.scn b/SofaKernel/modules/SofaBaseTopology/SofaBaseTopology_test/scenes/BezierTetrahedronTopology.scn deleted file mode 100644 index 47452084855..00000000000 --- a/SofaKernel/modules/SofaBaseTopology/SofaBaseTopology_test/scenes/BezierTetrahedronTopology.scn +++ /dev/null @@ -1,14 +0,0 @@ - - - - - - - - - - - - - - diff --git a/modules/SofaGeneralEngine/GenerateCylinder.h b/modules/SofaGeneralEngine/GenerateCylinder.h index 2f367c3b099..9102d334860 100644 --- a/modules/SofaGeneralEngine/GenerateCylinder.h +++ b/modules/SofaGeneralEngine/GenerateCylinder.h @@ -90,13 +90,7 @@ class GenerateCylinder : public core::DataEngine Data f_outputTrianglesPositions; ///< ouput triangle positions Data f_tetrahedra; ///< output tetrahedra Data f_triangles; ///< output triangles - Data > f_bezierTriangleWeight; /// output weight for rational Bezier triangles - Data > f_isBezierTriangleRational; /// for each Bezier triangle indicates if it is rational or integral - Data f_bezierTriangleDegree; /// degree of Bezier triangles - Data > f_bezierTetrahedronWeight; /// output weight for rational Bezier triangles - Data > f_isBezierTetrahedronRational; /// for each Bezier tetrahedron indicates if it is rational - Data f_bezierTetrahedronDegree; /// degree of Bezier tetrahedron - Data f_radius; /// radius of cylinder + Data f_radius; /// radius of cylinder Data f_height; /// height of cylinder Data f_origin; /// origin Data f_openSurface; /// if the triangulated surface is open or not diff --git a/modules/SofaGeneralEngine/GenerateCylinder.inl b/modules/SofaGeneralEngine/GenerateCylinder.inl index 3f409a797dd..b98eddc1d12 100644 --- a/modules/SofaGeneralEngine/GenerateCylinder.inl +++ b/modules/SofaGeneralEngine/GenerateCylinder.inl @@ -46,12 +46,6 @@ GenerateCylinder::GenerateCylinder() , f_outputTrianglesPositions ( initData (&f_outputTrianglesPositions, "output_TrianglesPosition", "output array of 3d points of triangle mesh") ) , f_tetrahedra( initData (&f_tetrahedra, "tetrahedra", "output mesh tetrahedra") ) , f_triangles( initData (&f_triangles, "triangles", "output triangular mesh") ) - , f_bezierTriangleWeight( initData (&f_bezierTriangleWeight, "BezierTriangleWeights", "weights of rational Bezier triangles") ) - , f_isBezierTriangleRational( initData (&f_isBezierTriangleRational, "isBezierTriangleRational", "booleans indicating if each Bezier triangle is rational or integral") ) - , f_bezierTriangleDegree( initData (&f_bezierTriangleDegree, "BezierTriangleDegree", "order of Bezier triangles") ) - , f_bezierTetrahedronWeight( initData (&f_bezierTetrahedronWeight, "BezierTetrahedronWeights", "weights of rational Bezier tetrahedra") ) - , f_isBezierTetrahedronRational( initData (&f_isBezierTetrahedronRational, "isBezierTetrahedronRational", "booleans indicating if each Bezier tetrahedron is rational or integral") ) - , f_bezierTetrahedronDegree( initData (&f_bezierTetrahedronDegree, "BezierTetrahedronDegree", "order of Bezier tetrahedra") ) , f_radius( initData (&f_radius,(Real)0.2, "radius", "input cylinder radius") ) , f_height( initData (&f_height,(Real)1.0, "height", "input cylinder height") ) , f_origin( initData (&f_origin,Coord(), "origin", "cylinder origin point") ) @@ -78,14 +72,10 @@ void GenerateCylinder::init() addOutput(&f_triangles); addOutput(&f_outputTrianglesPositions); - addOutput(&f_bezierTriangleWeight); - addOutput(&f_isBezierTriangleRational); - addOutput(&f_tetrahedra); addOutput(&f_outputTetrahedraPositions); - addOutput(&f_bezierTetrahedronWeight); - addOutput(&f_isBezierTetrahedronRational); + setDirtyValue(); } @@ -199,228 +189,7 @@ void GenerateCylinder::update() } } - if (f_bezierTetrahedronDegree.getValue()>1) { - - size_t degreeTetrahedron=f_bezierTetrahedronDegree.getValue(); - // fill the bezier tetrahedra weight to 1 for integral tetrahedron vertices - sofa::helper::vector & bezierTetrahedronWeight=*(f_bezierTetrahedronWeight.beginEdit()); - // initialize the weight to 1 - bezierTetrahedronWeight.resize(out.size()); - std::fill(bezierTetrahedronWeight.begin(),bezierTetrahedronWeight.end(),(Real)1.0); - // initialize the rational flag for each tetrahedron to false - helper::WriteOnlyAccessor > > isRationalSpline=f_isBezierTetrahedronRational; - isRationalSpline.resize(nbTetrahedra); - std::fill(isRationalSpline.begin(),isRationalSpline.end(),false); - // set the tetrahedra next to the circular surface to true - size_t nbSurfaceNodes,tetraRank; - - // parse edges - std::map edgeMap; - std::map::iterator item; - SeqTetrahedra::iterator itt; - //size_t pointOffset=freqTheta*freqZ; - Real ctheta=(Real)cos(M_PI/freqTheta); - Coord posTmp,posTmp2; - std::vector edgeArray; - for (tetraRank=0,itt=tetras.begin();itt!=tetras.end();++itt,++tetraRank) { - nbSurfaceNodes=0; - for (i=0;i<4;++i){ - if (onSurface[(*itt)[i]]) - ++nbSurfaceNodes; - } - // if the tetrahedron has at least 2 vertices on the circular surface then the bezier tetrahedron is rational - if (nbSurfaceNodes>=2) - isRationalSpline[tetraRank]=true; - // parse the tetrahedron edge - for (i=0;i<6;++i){ - - Edge e,se; - e[0]=(*itt)[edgesInTetrahedronArray[i][0]]; - e[1]=(*itt)[edgesInTetrahedronArray[i][1]]; - if (e[0]>e[1]){ - se[0]=e[1];se[1]=e[0]; - } else { - se=e; - } - if ((item=edgeMap.find(se))==edgeMap.end()){ - edgeMap.insert(std::pair(se,edgeArray.size())); - edgeArray.push_back(se); - e=se; - - // add Bezier points along the edge - - if ( (out[e[0]][2]==out[e[1]][2]) &&(onSurface[e[0]])&&(onSurface[e[1]])) { - // the edge is along a circle - if (degreeTetrahedron==2) { - pos=(out[e[0]]+out[e[1]])/2.0; - pos[2]=0; - pos*=radius/(pos.norm()*ctheta); - pos[2]=out[e[1]][2]; - out.push_back(pos); - bezierTetrahedronWeight.push_back((Real)ctheta); - } else if (degreeTetrahedron==3) { - posTmp=(out[e[0]]+out[e[1]])/2.0; - posTmp[2]=0; - posTmp*=radius/(posTmp.norm()*ctheta); - posTmp[2]=out[e[1]][2]; - pos=(2*ctheta*posTmp+out[e[0]])/(1+2*ctheta); - out.push_back(pos); - pos=(2*ctheta*posTmp+out[e[1]])/(1+2*ctheta); - out.push_back(pos); - bezierTetrahedronWeight.push_back((Real)(1+2*ctheta)/3.0f); - bezierTetrahedronWeight.push_back((Real)(1+2*ctheta)/3.0f); - } else { - for (j=1;j2) { - std::map triangleMap; - std::map::iterator ittm; - size_t v[3],triangleRank; - - for (triangleRank=0,itt=tetras.begin();itt!=tetras.end();++itt) { - - // parse the tetrahedron edge - for (i=0;i<4;++i){ - - - if (i%2) - { - v[0]=(*itt)[(i+1)%4]; - v[1]=(*itt)[(i+2)%4]; - v[2]=(*itt)[(i+3)%4]; - } - else - { - v[0]=(*itt)[(i+1)%4]; - v[2]=(*itt)[(i+2)%4]; - v[1]=(*itt)[(i+3)%4]; - } - // permute v such that v[0] has the smallest index - while ((v[0]>v[1]) || (v[0]>v[2])) - { - size_t val=v[0]; - v[0]=v[1]; - v[1]=v[2]; - v[2]=val; - } - - // check if a triangle with an opposite orientation already exists - Triangle tr = Triangle(v[0], v[2], v[1]); - - if (triangleMap.find(tr) == triangleMap.end()) - { - // triangle not in triangleMap so create a new one - tr = Triangle(v[0], v[1], v[2]); - if (triangleMap.find(tr) == triangleMap.end()) - { - triangleMap[tr] = triangleRank++; - } - else - { - serr << "ERROR: duplicate triangle " << tr << " in tetra " << i <<" : " << (*itt) << sendl; - } - // tests if all vertices are on the circular surface - nbSurfaceNodes=0; - - for (j=1;j<4;++j){ - if (onSurface[(*itt)[(i+j)%4]]) - ++nbSurfaceNodes; - } - if (nbSurfaceNodes==3) { - // this is the more complex case as the bezier triangle is rational and non affine - // ONLY the case for degree=3 is considered here. - for(j=0;(out[tr[(j+1)%3]][2]==out[tr[(j+2)%3]][2])||(out[tr[(j+1)%3]][1]==out[tr[(j+2)%3]][1]);++j); - for(k=1;out[tr[(j+k)%3]][2]!=out[tr[j]][2];++k); - posTmp=(out[tr[j]]+out[tr[(j+k)%3]])/2.0; - posTmp[2]=0; - posTmp*=radius/(posTmp.norm()*ctheta); - posTmp[2]=out[tr[(j+1)%3]][2]; - posTmp2=posTmp; - posTmp2[2]=out[tr[(j+2)%3]][2]; - pos=(out[tr[j]]+ctheta*posTmp+ctheta*posTmp2)/(1+2*ctheta); - out.push_back(pos); - bezierTetrahedronWeight.push_back((Real)(1+2*ctheta)/3.0f); - } else { - // this is the affine case. The triangular control points are simply built from a tesselation of the triangles - for (j=1;j<(degreeTetrahedron-1);++j) { - for (k=1;k<(degreeTetrahedron-j);++k) { - pos= out[tr[0]]*k/degreeTetrahedron+(Real)(degreeTetrahedron-j-k)*out[tr[1]]/degreeTetrahedron+ - (Real)(j)*out[tr[2]]/degreeTetrahedron; - out.push_back(pos); - // weight is 1 - bezierTetrahedronWeight.push_back((Real)1.0f); - } - - } - } - - } - } - } - } - } - bool open=f_openSurface.getValue(); helper::WriteOnlyAccessor > outTrian = f_outputTrianglesPositions; @@ -538,164 +307,6 @@ void GenerateCylinder::update() } } - if (f_bezierTriangleDegree.getValue()>1) { - - size_t degreeTriangle=f_bezierTriangleDegree.getValue(); - // fill the bezier triangle weight to 1 for regular triangle vertices - sofa::helper::vector & bezierTriangleWeight=*(f_bezierTriangleWeight.beginEdit()); - // initialize the weight to 1 - bezierTriangleWeight.resize(outTrian.size()); - std::fill(bezierTriangleWeight.begin(),bezierTriangleWeight.end(),(Real)1.0); - // initialize the rational flag for each triangle to false - helper::WriteOnlyAccessor > > isRationalSpline=f_isBezierTriangleRational; - isRationalSpline.resize(nbTriangles); - // sets the first set of triangles to be rational - std::fill(isRationalSpline.begin(),isRationalSpline.end(),false); - - - // parse edges - std::map edgeMap; - std::map::iterator item; - SeqTriangles::iterator itt; - size_t pointOffset=freqTheta*freqZ; - Real ctheta=(Real)cos(M_PI/freqTheta); - Coord posTmp,posTmp2; - size_t nbCircularSurfaceNodes; - std::vector edgeArray; - for (itt=triangles.begin();itt!=triangles.end();++itt) { - nbCircularSurfaceNodes=0; - for (i=0;i<3;++i){ - if ((*itt)[i]<(freqTheta*freqZ)) - ++nbCircularSurfaceNodes; - } - // if the triangle has at least 2 vertices on the circular surface then the bezier triangle is rational - if (nbCircularSurfaceNodes>=2) - isRationalSpline[itt-triangles.begin()]=true; - for (i=0;i<3;++i){ - Edge e,se; - e[0]=(*itt)[(i+1)%3]; - e[1]=(*itt)[(i+2)%3]; - if (e[0]>e[1]){ - se[0]=e[1];se[1]=e[0]; - } else { - se=e; - } - if ((item=edgeMap.find(se))==edgeMap.end()){ - edgeMap.insert(std::pair(se,edgeArray.size())); - edgeArray.push_back(e); - // add Bezier points along the edge - if ( (outTrian[e[0]][2]==outTrian[e[1]][2]) &&(e[0]2) { - for (j=0,itt=triangles.begin();itt!=triangles.end();++itt,++j) { - if (j<(2*freqTheta*(freqZ-1))){ - - // add points inside triangles - // find the edge along the axis z of the cylinder - for(i=0;(outTrian[(*itt)[(i+1)%3]][2]==outTrian[(*itt)[(i+2)%3]][2])||(outTrian[(*itt)[(i+1)%3]][1]==outTrian[(*itt)[(i+2)%3]][1]);++i); - // posTmp=outTrian[(*itt)[(i+1)%3]]; - // posTmp2=outTrian[(*itt)[(i+2)%3]]; - // std::cerr << "pos0= "<::init() addOutput(&f_triangles); addOutput(&f_outputTrianglesPositions); - addOutput(&f_bezierTriangleWeight); - addOutput(&f_isBezierTriangleRational); - + addOutput(&f_tetrahedra); addOutput(&f_outputTetrahedraPositions); - addOutput(&f_bezierTetrahedronWeight); - addOutput(&f_isBezierTetrahedronRational); setDirtyValue(); @@ -443,370 +433,8 @@ void GenerateSphere::update() tetras[i]=tet; } } - // now handle bezier triangulation - if (f_bezierTriangleDegree.getValue()>1) { - - size_t degreeTriangle=f_bezierTriangleDegree.getValue(); - // fill the bezier triangle weight to 1 for regular triangle vertices - helper::WriteOnlyAccessor > > bezierTriangleWeight=f_bezierTriangleWeight; - // initialize the weight to 1 - bezierTriangleWeight.resize(posTrian.size()); - std::fill(bezierTriangleWeight.begin(),bezierTriangleWeight.end(),(Real)1.0); - // initialize the rational flag for each triangle to true - helper::WriteOnlyAccessor > > isRationalSpline=f_isBezierTriangleRational; - isRationalSpline.resize(nbTriangles); - // sets the first set of triangles to be rational - std::fill(isRationalSpline.begin(),isRationalSpline.end(),true); - - // parse edges - edgeMap.clear(); - std::map::iterator item; - SeqTriangles::iterator itt; - Real phi,ctheta; - Coord posTmp,posTmp2,normal; - edgeArray.clear(); - - for (itt=trians.begin();itt!=trians.end();++itt) { - - for (i=0;i<3;++i){ - Edge e,se; - e[0]=(*itt)[(i+1)%3]; - e[1]=(*itt)[(i+2)%3]; - if (e[0]>e[1]){ - se[0]=e[1];se[1]=e[0]; - } else { - se=e; - } - if ((item=edgeMap.find(se))==edgeMap.end()){ - edgeMap.insert(std::pair(se,edgeArray.size())); - edgeArray.push_back(e); - // add Bezier points along the edge - phi=acos(dot(posTrian[se[0]],posTrian[se[1]])); - normal=defaulttype::cross(posTrian[(*itt)[2]]-posTrian[(*itt)[1]], - posTrian[(*itt)[2]]-posTrian[(*itt)[0]]); - normal/=normal.norm(); - ctheta=dot(normal,posTrian[(*itt)[1]]); - // ctheta must be negative otherwise get negative weights - if (ctheta>0) { - normal*= -1.0f; - ctheta*= -1.0f; - } - if (degreeTriangle==2) { - pos=(posTrian[e[0]]+posTrian[e[1]])/2.0; - pos/=pos.norm(); - pos/=cos(phi/2); - posTrian.push_back(pos); - bezierTriangleWeight.push_back((Real)cos(phi/2)); - } else if (degreeTriangle==3) { - posTmp=(posTrian[e[0]]+posTrian[e[1]])/(1+dot(posTrian[e[0]],posTrian[e[1]])); - pos=(2*ctheta*posTmp+posTrian[e[0]])/(1+2*ctheta); - posTrian.push_back(pos); - pos=(2*ctheta*posTmp+posTrian[e[1]])/(1+2*ctheta); - posTrian.push_back(pos); - bezierTriangleWeight.push_back((Real)(1+2*ctheta)/3.0f); - bezierTriangleWeight.push_back((Real)(1+2*ctheta)/3.0f); - } else if (degreeTriangle==4) { - Coord P110=(posTrian[e[0]]+posTrian[e[1]])/(1+dot(posTrian[e[0]],posTrian[e[1]])); - Real w110=((posTrian[e[0]]+posTrian[e[1]])/2).norm(); - Real w310=(2-ctheta-dot(normal,P110)); - posTmp=(P110*(1-ctheta)+posTrian[e[0]]*(1-dot(normal,P110)))/w310; - Coord P130=((1-ctheta)*P110+(1-dot(normal,P110))*posTrian[e[1]])/w310; - w310*=w110/(2*(1-ctheta)); - posTrian.push_back(posTmp); - bezierTriangleWeight.push_back((Real)w310); - Real w220=4*(1-dot(normal,P110))*w110*w110+2*(1-ctheta); - Coord P220=P110*4*(1-dot(normal,P110))*w110*w110+ - (posTrian[e[0]]+posTrian[e[1]])*(1-ctheta); - P220/=w220; - w220/=6*(1-ctheta); - posTrian.push_back(P220); - bezierTriangleWeight.push_back((Real)w220); - posTrian.push_back(P130); - bezierTriangleWeight.push_back((Real)w310); - } else { - for (j=1;j2) { - - for (itt=trians.begin();itt!=trians.end();++itt) { - // add inside points - if (degreeTriangle==4) { - normal=defaulttype::cross(posTrian[(*itt)[2]]-posTrian[(*itt)[1]], - posTrian[(*itt)[2]]-posTrian[(*itt)[0]]); - normal/=normal.norm(); - ctheta=dot(normal,posTrian[(*itt)[1]]); - // ctheta must be negative otherwise get negative weights - if (ctheta>0) { - normal*= -1.0f; - ctheta*= -1.0f; - } - Coord mid[3]; - Real wmid[3]; - for (i=0;i<3;++i) { - mid[i]=(posTrian[(*itt)[(i+1)%3]]+posTrian[(*itt)[(i+2)%3]])/(1+dot(posTrian[(*itt)[(i+1)%3]],posTrian[(*itt)[(i+2)%3]])); - wmid[i]=((posTrian[(*itt)[(i+1)%3]]+posTrian[(*itt)[(i+2)%3]])/2).norm(); - } - Coord posTmp; - Real ww; - for (j=3;j>0;--j) { - i=(j+2)%3; - ww= 2*wmid[(i+1)%3]*wmid[(i+2)%3]*(1+dot(mid[(i+1)%3],mid[(i+2)%3])-dot(normal,mid[(i+1)%3])-dot(normal,mid[(i+2)%3]))+ - wmid[i]*(1+dot(posTrian[(*itt)[i]],mid[i])-ctheta-dot(mid[i],normal)); - posTmp=2*wmid[(i+1)%3]*wmid[(i+2)%3]*((1-dot(normal,mid[(i+1)%3]))*mid[(i+2)%3]+(1-dot(normal,mid[(i+2)%3]))*mid[(i+1)%3]+ - (dot(mid[(i+1)%3],mid[(i+2)%3])-1)*normal)+wmid[i]*((1-ctheta)*mid[i]+(1-dot(normal,mid[i]))*posTrian[(*itt)[i]]+(dot(posTrian[(*itt)[i]],mid[i])-1)*normal); - posTmp/=ww; - ww/=6*(1-ctheta); - posTrian.push_back(posTmp); - bezierTriangleWeight.push_back((Real)ww); - } - } else { - for (i=1;i<(degreeTriangle-1);++i) { - for (j=1;j<(degreeTriangle-i);++j) { - pos= ((Real) i*posTrian[(*itt)[0]]+ - (Real)j*posTrian[(*itt)[1]]+(Real) (degreeTriangle-i-j)*posTrian[(*itt)[2]])/degreeTriangle; - posTrian.push_back(pos); - bezierTriangleWeight.push_back((Real)1.0f); - } - } - } - } - } - } - - // now handle bezier tetrahedra - if (f_bezierTetrahedronDegree.getValue()>1) { - size_t degreeTetrahedron=f_bezierTetrahedronDegree.getValue(); - // fill the bezier triangle weight to 1 for regular tetrahedron vertices - helper::WriteOnlyAccessor > > bezierTetrahedronWeight=f_bezierTetrahedronWeight; - // initialize the weight to 1 - bezierTetrahedronWeight.resize(posTetra.size()); - std::fill(bezierTetrahedronWeight.begin(),bezierTetrahedronWeight.end(),(Real)1.0); - // initialize the rational flag for each tetrahedron to true - helper::WriteOnlyAccessor > > isRationalSpline=f_isBezierTetrahedronRational; - isRationalSpline.resize(tetras.size()); - // sets the first set of tetrahedra to be rational - std::fill(isRationalSpline.begin(),isRationalSpline.end(),true); - - // parse edges - edgeMap.clear(); - std::map::iterator item; - SeqTetrahedra::iterator itt; - Real phi,ctheta; - Coord posTmp,posTmp2,normal; - edgeArray.clear(); - for (itt=tetras.begin();itt!=tetras.end();++itt) { - } - for (itt=tetras.begin();itt!=tetras.end();++itt) { - for (i=0;i<6;++i){ - Edge e,se; - e[0]=(*itt)[edgesInTetrahedronArray[i][0]]; - e[1]=(*itt)[edgesInTetrahedronArray[i][1]]; - if (e[0]>e[1]){ - se[0]=e[1];se[1]=e[0]; - } else { - se=e; - } - if ((item=edgeMap.find(se))==edgeMap.end()){ - edgeMap.insert(std::pair(se,edgeArray.size())); - edgeArray.push_back(e); - // check if the edge is on the sphere - bool onSphere=false; - if ((fabs(posTetra[e[0]].norm2()-1)<1e-4)&& (fabs(posTetra[e[1]].norm2()-1)<1e-4)){ - onSphere=true; - - } - if (onSphere) { - // add Bezier points along the edge - phi=acos(dot(posTetra[e[0]],posTetra[e[1]])); - // one of the 2 other vertices must be on the sphere - size_t nextVertexOnSphere=(*itt)[adjacentVerticesToEdges[i][0]]; - if (fabs(posTetra[nextVertexOnSphere].norm2()-1)>1e-4){ - nextVertexOnSphere=(*itt)[adjacentVerticesToEdges[i][1]]; - assert(fabs(posTetra[nextVertexOnSphere].norm2()-1)<1e-4); - } - // we have 3 points on the sphere therefore can compute a normal - normal=defaulttype::cross(posTetra[nextVertexOnSphere]-posTetra[e[1]], - posTetra[nextVertexOnSphere]-posTetra[e[0]]); - normal/=normal.norm(); - ctheta=dot(normal,posTetra[e[1]]); - // ctheta must be negative otherwise get negative weights - if (ctheta>0) { - normal*= -1.0f; - ctheta*= -1.0f; - } - if (degreeTetrahedron==2) { - pos=(posTetra[e[0]]+posTetra[e[1]])/2.0; - pos/=pos.norm(); - pos/=cos(phi/2); - posTetra.push_back(pos); - bezierTetrahedronWeight.push_back((Real)cos(phi/2)); - } else if (degreeTetrahedron==3) { - posTmp=(posTetra[e[0]]+posTetra[e[1]])/(1+dot(posTetra[e[0]],posTetra[e[1]])); - pos=(2*ctheta*posTmp+posTetra[se[0]])/(1+2*ctheta); - posTetra.push_back(pos); - pos=(2*ctheta*posTmp+posTetra[se[1]])/(1+2*ctheta); - posTetra.push_back(pos); - bezierTetrahedronWeight.push_back((Real)(1+2*ctheta)/3.0f); - bezierTetrahedronWeight.push_back((Real)(1+2*ctheta)/3.0f); - } else if (degreeTetrahedron==4) { - Coord P110=(posTetra[e[0]]+posTetra[e[1]])/(1+dot(posTetra[e[0]],posTetra[e[1]])); - Real w110=((posTetra[e[0]]+posTetra[e[1]])/2).norm(); - Real w310=(2-ctheta-dot(normal,P110)); - posTmp=(P110*(1-ctheta)+posTetra[se[0]]*(1-dot(normal,P110)))/w310; - Coord P130=((1-ctheta)*P110+(1-dot(normal,P110))*posTetra[se[1]])/w310; - w310*=w110/(2*(1-ctheta)); - posTetra.push_back(posTmp); - bezierTetrahedronWeight.push_back((Real)w310); - Real w220=4*(1-dot(normal,P110))*w110*w110+2*(1-ctheta); - Coord P220=P110*4*(1-dot(normal,P110))*w110*w110+ - (posTetra[e[0]]+posTetra[e[1]])*(1-ctheta); - P220/=w220; - w220/=6*(1-ctheta); - posTetra.push_back(P220); - bezierTetrahedronWeight.push_back((Real)w220); - posTetra.push_back(P130); - bezierTetrahedronWeight.push_back((Real)w310); - } else { - for (j=1;j2) { - std::set triangleSet; - std::set::iterator itemtr; - for (itt=tetras.begin();itt!=tetras.end();++itt) { - for (k=0;k<4;++k){ - // add inside points - - Triangle tr,sortedtr; - if (k%2) - tr=Triangle((*itt)[(k+1)%4],(*itt)[(k+2)%4],(*itt)[(k+3)%4]); - else - tr=Triangle((*itt)[(k+1)%4],(*itt)[(k+3)%4],(*itt)[(k+2)%4]); - // permute until small index at tr[0] - while ((tr[0]>tr[1]) || (tr[0]>tr[2])) - { - unsigned int val=tr[0]; - tr[0]=tr[1]; - tr[1]=tr[2]; - tr[2]=val; - } - // check if a triangle with an opposite orientation already exists - sortedtr = Triangle(tr[0], tr[2], tr[1]); - - // finds unique triangle - if ((itemtr=triangleSet.find(sortedtr))==triangleSet.end()){ - triangleSet.insert(tr); - - if (degreeTetrahedron==4) { - - bool onSphere=true; - for (i=0;i<3;++i) { - if (fabs(posTetra[tr[i]].norm2()-1)>1e-4) - onSphere=false; - } - if (onSphere) { - normal=defaulttype::cross(posTetra[tr[2]]-posTetra[tr[1]], - posTetra[tr[2]]-posTetra[tr[0]]); - normal/=normal.norm(); - ctheta=dot(normal,posTetra[tr[1]]); - // ctheta must be negative otherwise get negative weights - if (ctheta>0) { - normal*= -1.0f; - ctheta*= -1.0f; - } - Coord mid[3]; - Real wmid[3]; - for (i=0;i<3;++i) { - mid[i]=(posTetra[tr[(i+1)%3]]+posTetra[tr[(i+2)%3]])/(1+dot(posTetra[tr[(i+1)%3]],posTetra[tr[(i+2)%3]])); - wmid[i]=((posTetra[tr[(i+1)%3]]+posTetra[tr[(i+2)%3]])/2).norm(); - } - Coord posTmp; - Real ww; - for (j=3;j>0;--j) { - i=(j+2)%3; - ww= 2*wmid[(i+1)%3]*wmid[(i+2)%3]*(1+dot(mid[(i+1)%3],mid[(i+2)%3])-dot(normal,mid[(i+1)%3])-dot(normal,mid[(i+2)%3]))+ - wmid[i]*(1+dot(posTetra[tr[i]],mid[i])-ctheta-dot(mid[i],normal)); - posTmp=2*wmid[(i+1)%3]*wmid[(i+2)%3]*((1-dot(normal,mid[(i+1)%3]))*mid[(i+2)%3]+(1-dot(normal,mid[(i+2)%3]))*mid[(i+1)%3]+ - (dot(mid[(i+1)%3],mid[(i+2)%3])-1)*normal)+wmid[i]*((1-ctheta)*mid[i]+(1-dot(normal,mid[i]))*posTetra[tr[i]]+(dot(posTetra[tr[i]],mid[i])-1)*normal); - posTmp/=ww; - ww/=6*(1-ctheta); - posTetra.push_back(posTmp); - bezierTetrahedronWeight.push_back((Real)ww); - } - } else { - for (i=1;i<(degreeTetrahedron-1);++i) { - for (j=1;j<(degreeTetrahedron-i);++j) { - pos= ((Real) i*posTetra[tr[0]]+ - (Real)j*posTetra[tr[1]]+(Real) (degreeTetrahedron-i-j)*posTetra[tr[2]])/degreeTetrahedron; - posTetra.push_back(pos); - bezierTetrahedronWeight.push_back((Real)1.0f); - } - } - } - } else { - for (i=1;i<(degreeTetrahedron-1);++i) { - for (j=1;j<(degreeTetrahedron-i);++j) { - pos= ((Real) i*posTetra[tr[0]]+ - (Real)j*posTetra[tr[1]]+(Real) (degreeTetrahedron-i-j)*posTetra[tr[2]])/degreeTetrahedron; - posTetra.push_back(pos); - bezierTetrahedronWeight.push_back((Real)1.0f); - } - } - } - } - } - } - } - if (degreeTetrahedron>3) { - for (itt=tetras.begin();itt!=tetras.end();++itt) { - // use default position - for (i=1;i<(degreeTetrahedron-2);++i) { - for (j=1;j<(degreeTetrahedron-i-1);++j) { - for (k=1;k<(degreeTetrahedron-j-i);++k) { - pos= ((Real) i*posTetra[(*itt)[0]]+ - (Real)j*posTetra[(*itt)[1]]+(Real)k*posTetra[(*itt)[2]]+ - (Real) (degreeTetrahedron-i-j-k)*posTetra[(*itt)[3]])/degreeTetrahedron; - posTetra.push_back(pos); - bezierTetrahedronWeight.push_back((Real)1.0f); - } - } - } - - } - } - } // now translate and scale the mesh for (i=0;i -#include -#include -namespace sofa -{ - -namespace component -{ - -namespace topology -{ -using namespace sofa::defaulttype; -SOFA_DECL_CLASS(BezierTetrahedronSetGeometryAlgorithms) -int BezierTetrahedronSetGeometryAlgorithmsClass = core::RegisterObject("Bezier Tetrahedron set geometry algorithms") -#ifdef SOFA_FLOAT - .add< BezierTetrahedronSetGeometryAlgorithms >(true) // default template -#else - .add< BezierTetrahedronSetGeometryAlgorithms >(true) // default template -#ifndef SOFA_DOUBLE - .add< BezierTetrahedronSetGeometryAlgorithms >() // default template -#endif -#endif -#ifndef SOFA_FLOAT - .add< BezierTetrahedronSetGeometryAlgorithms >() - .add< BezierTetrahedronSetGeometryAlgorithms >() -#endif -#ifndef SOFA_DOUBLE - .add< BezierTetrahedronSetGeometryAlgorithms >() - .add< BezierTetrahedronSetGeometryAlgorithms >() -#endif - ; - -#ifndef SOFA_FLOAT -template class SOFA_GENERAL_TOPOLOGY_API BezierTetrahedronSetGeometryAlgorithms; -template class SOFA_GENERAL_TOPOLOGY_API BezierTetrahedronSetGeometryAlgorithms; -template class SOFA_GENERAL_TOPOLOGY_API BezierTetrahedronSetGeometryAlgorithms; -#endif - -#ifndef SOFA_DOUBLE -template class SOFA_GENERAL_TOPOLOGY_API BezierTetrahedronSetGeometryAlgorithms; -template class SOFA_GENERAL_TOPOLOGY_API BezierTetrahedronSetGeometryAlgorithms; -template class SOFA_GENERAL_TOPOLOGY_API BezierTetrahedronSetGeometryAlgorithms; -#endif - -} // namespace topology - -} // namespace component - -} // namespace sofa - diff --git a/modules/SofaGeneralTopology/BezierTetrahedronSetGeometryAlgorithms.h b/modules/SofaGeneralTopology/BezierTetrahedronSetGeometryAlgorithms.h deleted file mode 100644 index 54febf35d63..00000000000 --- a/modules/SofaGeneralTopology/BezierTetrahedronSetGeometryAlgorithms.h +++ /dev/null @@ -1,142 +0,0 @@ -/****************************************************************************** -* SOFA, Simulation Open-Framework Architecture, development version * -* (c) 2006-2016 INRIA, USTL, UJF, CNRS, MGH * -* * -* This library 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 library 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 library; if not, write to the Free Software Foundation, * -* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * -******************************************************************************* -* SOFA :: Modules * -* * -* Authors: The SOFA Team and external contributors (see Authors.txt) * -* * -* Contact information: contact@sofa-framework.org * -******************************************************************************/ -#ifndef SOFA_COMPONENT_TOPOLOGY_BEZIERTETRAHEDRONSETGEOMETRYALGORITHMS_H -#define SOFA_COMPONENT_TOPOLOGY_BEZIERTETRAHEDRONSETGEOMETRYALGORITHMS_H -#include "config.h" - -#include -#include - - -namespace sofa -{ - -namespace component -{ - -namespace topology -{ - -/** -* A class that provides geometry information on an TetrahedronSet. -*/ -template < class DataTypes > -class BezierTetrahedronSetGeometryAlgorithms : public TetrahedronSetGeometryAlgorithms -{ -public: - SOFA_CLASS(SOFA_TEMPLATE(BezierTetrahedronSetGeometryAlgorithms,DataTypes),SOFA_TEMPLATE(TetrahedronSetGeometryAlgorithms,DataTypes)); - typedef typename DataTypes::VecCoord VecCoord; - typedef typename DataTypes::Real Real; - typedef typename DataTypes::Coord Coord; - typedef sofa::defaulttype::Vec<4,Real> Vec4; - typedef sofa::defaulttype::Mat<4,4,Real> Mat44; - - typedef core::topology::BaseMeshTopology::PointID PointID; - typedef core::topology::BaseMeshTopology::Edge Edge; - typedef core::topology::BaseMeshTopology::TetraID TetraID; - typedef core::topology::BaseMeshTopology::Tetra Tetra; - typedef core::topology::BaseMeshTopology::SeqTetrahedra SeqTetrahedra; - typedef core::topology::BaseMeshTopology::SeqEdges SeqEdges; - typedef core::topology::BaseMeshTopology::TetrahedraAroundVertex TetrahedraAroundVertex; - typedef core::topology::BaseMeshTopology::TetrahedraAroundEdge TetrahedraAroundEdge; - typedef core::topology::BaseMeshTopology::TetrahedraAroundTriangle TetrahedraAroundTriangle; - typedef core::topology::BaseMeshTopology::EdgesInTetrahedron EdgesInTetrahedron; - typedef core::topology::BaseMeshTopology::TrianglesInTetrahedron TrianglesInTetrahedron; - typedef BezierTetrahedronSetTopologyContainer::VecPointID VecPointID; - - typedef Tetra Tetrahedron; -protected: - - /// container - BezierTetrahedronSetTopologyContainer *container; - /// degree of the polynomial - BezierDegreeType degree; - // array of Tetrahedral Bezier indices - sofa::helper::vector tbiArray; - // array of Bernstein coefficient following the same order as tbiArray - sofa::helper::vector bernsteinCoefficientArray; - // map used to store the Bernstein coefficient given a Tetrahedron Bezier Index - std::map bernsteinCoeffMap; - /// the list of edges of the Bezier Tetrahedron used in the draw function - sofa::helper::set > bezierTetrahedronEdgeSet; - - - - /// constructor - BezierTetrahedronSetGeometryAlgorithms(); - virtual ~BezierTetrahedronSetGeometryAlgorithms() {} -public: - virtual void init(); - virtual void reinit(); - virtual void draw(const core::visual::VisualParams* vparams); - /// returns a pointer to the BezierTetrahedronSetTopologyContainer object - BezierTetrahedronSetTopologyContainer *getTopologyContainer() const { - return container; - } - /// computes the nodal value given the tetrahedron index, the barycentric coordinates and the vector of nodal values - Coord computeNodalValue(const size_t tetrahedronIndex,const Vec4 barycentricCoordinate,const VecCoord& p); - /// computes the nodal value assuming that the position is the regular position in the mechanical state object - Coord computeNodalValue(const size_t tetrahedronIndex,const Vec4 barycentricCoordinate); - /// computes the shape function - Real computeBernsteinPolynomial(const TetrahedronBezierIndex tbi, const Vec4 barycentricCoordinate); - /// computes the shape function gradient - Vec4 computeBernsteinPolynomialGradient(const TetrahedronBezierIndex tbi, const Vec4 barycentricCoordinate); - /// computes the shape function hessian - Mat44 computeBernsteinPolynomialHessian(const TetrahedronBezierIndex tbi, const Vec4 barycentricCoordinate); - /// computes Jacobian i.e. determinant of dpos/dmu - Real computeJacobian(const size_t tetrahedronIndex, const Vec4 barycentricCoordinate,const VecCoord& p); - /// computes Jacobian - Real computeJacobian(const size_t tetrahedronIndex, const Vec4 barycentricCoordinate); - /// compute the 4 De Casteljeau of degree d-1 - void computeDeCasteljeauPoints(const size_t tetrahedronIndex, const Vec4 barycentricCoordinate, const VecCoord& p,Coord point[4]); - /// test if the Bezier tetrahedron is a simple affine tesselation of a regular tetrahedron - bool isBezierTetrahedronAffine(const size_t tetrahedronIndex,const VecCoord& p, const Real tolerance=(Real)1e-5) const; -protected: - Data drawControlPointsEdges; - Data drawSmoothEdges; - Data drawControlPoints; - Data d_referenceRadius; // radius to draw control points -}; - -#if defined(SOFA_EXTERN_TEMPLATE) && !defined(SOFA_COMPONENT_TOPOLOGY_BEZIERTETRAHEDRONSETGEOMETRYALGORITHMS_CPP) -#ifndef SOFA_FLOAT -extern template class SOFA_GENERAL_TOPOLOGY_API BezierTetrahedronSetGeometryAlgorithms; -extern template class SOFA_GENERAL_TOPOLOGY_API BezierTetrahedronSetGeometryAlgorithms; -extern template class SOFA_GENERAL_TOPOLOGY_API BezierTetrahedronSetGeometryAlgorithms; -#endif -#ifndef SOFA_DOUBLE -extern template class SOFA_GENERAL_TOPOLOGY_API BezierTetrahedronSetGeometryAlgorithms; -extern template class SOFA_GENERAL_TOPOLOGY_API BezierTetrahedronSetGeometryAlgorithms; -extern template class SOFA_GENERAL_TOPOLOGY_API BezierTetrahedronSetGeometryAlgorithms; -#endif -#endif - -} // namespace topology - -} // namespace component - -} // namespace sofa - -#endif diff --git a/modules/SofaGeneralTopology/BezierTetrahedronSetGeometryAlgorithms.inl b/modules/SofaGeneralTopology/BezierTetrahedronSetGeometryAlgorithms.inl deleted file mode 100644 index 251758cc809..00000000000 --- a/modules/SofaGeneralTopology/BezierTetrahedronSetGeometryAlgorithms.inl +++ /dev/null @@ -1,609 +0,0 @@ -/****************************************************************************** -* SOFA, Simulation Open-Framework Architecture, development version * -* (c) 2006-2016 INRIA, USTL, UJF, CNRS, MGH * -* * -* This library 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 library 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 library; if not, write to the Free Software Foundation, * -* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * -******************************************************************************* -* SOFA :: Modules * -* * -* Authors: The SOFA Team and external contributors (see Authors.txt) * -* * -* Contact information: contact@sofa-framework.org * -******************************************************************************/ -#ifndef SOFA_COMPONENT_TOPOLOGY_BEZIERTETRAHEDRONSETGEOMETRYALGORITHMS_INL -#define SOFA_COMPONENT_TOPOLOGY_BEZIERTETRAHEDRONSETGEOMETRYALGORITHMS_INL - -#include -#include -#include -#include -namespace sofa -{ - -namespace component -{ - -namespace topology -{ - -double multinomial(const size_t n,const TetrahedronBezierIndex tbiIn) - { - size_t i,ival; - TetrahedronBezierIndex tbi=tbiIn; - // divide n! with the largest of the multinomial coefficient - std::sort(tbi.begin(),tbi.end()); - ival=1; - for (i=n;i>tbi[3];--i){ - ival*=i; - } - return(((double)ival)/(sofa::helper::factorial(tbi[0])*sofa::helper::factorial(tbi[1])*sofa::helper::factorial(tbi[2]))); - } -template< class DataTypes> - BezierTetrahedronSetGeometryAlgorithms< DataTypes >::BezierTetrahedronSetGeometryAlgorithms() : -TetrahedronSetGeometryAlgorithms() - ,degree(0) - ,drawControlPointsEdges (core::objectmodel::Base::initData(&drawControlPointsEdges, (bool) false, "drawControlPointsEdges", "Debug : draw Control point edges ")) - ,drawSmoothEdges (core::objectmodel::Base::initData(&drawSmoothEdges, (bool) false, "drawSmoothEdges", "Debug : draw Bezier curves as edges of the Bezier triangle")) - ,drawControlPoints (core::objectmodel::Base::initData(&drawControlPoints, (bool) false, "drawControlPoints", "Debug : draw Control points with a color depending on its status ")) - ,d_referenceRadius (core::objectmodel::Base::initData(&d_referenceRadius, (Real) -1.0f, "referenceRadius", "Debug : radius of control points when drawing ")) - { - } -template< class DataTypes> - void BezierTetrahedronSetGeometryAlgorithms< DataTypes >::init() -{ - TetrahedronSetGeometryAlgorithms::init(); - // recovers the pointer to a BezierTetrahedronSetTopologyContainer - BezierTetrahedronSetTopologyContainer *btstc = NULL; - this->getContext()->get(btstc, sofa::core::objectmodel::BaseContext::Local); - if (!btstc) { - serr << " Could not find a BezierTetrahedronSetTopologyContainer object"<< sendl; - } else { - container=btstc; - /// get the degree of the Bezier tetrahedron - degree=container->getDegree(); - /// store the tetrahedron bezier index for each tetrahedron - tbiArray=container->getTetrahedronBezierIndexArray(); - /// compute the Bernstein coefficient for each control point in a tetrahedron - bernsteinCoefficientArray.clear(); - bernsteinCoeffMap.clear(); - bernsteinCoefficientArray.resize(tbiArray.size()); - - TetrahedronBezierIndex tbi; - /// precompute the factorial of the degree. - for (size_t i=0;i(tbi,(Real)bernsteinCoefficientArray[i])); - } - /// insert coefficient for the inferior degree - BezierDegreeType i,j,k,l,m,n,index1,index2; - for (i=0;i<=(degree-1);++i) { - for (j=0;j<=(degree-i-1);++j) { - for (k=0;k<=(degree-j-i-1);++k) { - l=degree-1-i-j-k; - tbi=TetrahedronBezierIndex(i,j,k,l); - bernsteinCoeffMap.insert(std::pair(tbi,(Real)multinomial(degree-1,tbi))); - } - } - } - /// fills the array of edges - bezierTetrahedronEdgeSet.clear(); - TetrahedronBezierIndex tbiNext; - - for (i=0;i<=degree;++i) { - for (j=0;j<=(degree-i);++j) { - for (k=0;k<=(degree-j-i);++k) { - l=degree-i-j-k; - tbi=TetrahedronBezierIndex(i,j,k,l); - index1=container->getLocalIndexFromTetrahedronBezierIndex(tbi); - for(m=0;m<4;++m) { - if (tbi[m]getLocalIndexFromTetrahedronBezierIndex(tbiNext); - Edge e((PointID)std::min(index1,index2),(PointID)std::max(index1,index2)); - // test if both control points are on an edge or an - if (tbi[(m+1+(n%3))%4]==0) { - if (tbi[(m+1+((n+1)%3))%4]==0) { - // edge connects points along an edge - bezierTetrahedronEdgeSet.insert(std::pair(e,(size_t)2)); - } else - // edge connects points along a triangle - bezierTetrahedronEdgeSet.insert(std::pair(e,(size_t)1)); - } else if (tbi[(m+1+((n+1)%3))%4]==0) { - bezierTetrahedronEdgeSet.insert(std::pair(e,(size_t)1)); - } else - bezierTetrahedronEdgeSet.insert(std::pair(e,(size_t)0)); - } - } - } - } - } - } - } - } - - -} - -template< class DataTypes> - void BezierTetrahedronSetGeometryAlgorithms< DataTypes >::reinit() -{ -} -template< class DataTypes> -typename DataTypes::Coord BezierTetrahedronSetGeometryAlgorithms< DataTypes >::computeNodalValue(const size_t tetrahedronIndex,const Vec4 barycentricCoordinate, const typename DataTypes::VecCoord& p) -{ - Coord nodalValue; - nodalValue.clear(); - - TetrahedronBezierIndex tbi; - const VecPointID &indexArray=container->getGlobalIndexArrayOfBezierPoints(tetrahedronIndex); - bool isRational=container->isRationalSpline(tetrahedronIndex); - if (isRational) { - const BezierTetrahedronSetTopologyContainer::SeqWeights &wa=container->getWeightArray(); - Real weight=(Real)0.0f; - Real bernsteinPolynonial; - for(size_t i=0; i -typename DataTypes::Coord BezierTetrahedronSetGeometryAlgorithms< DataTypes >::computeNodalValue(const size_t tetrahedronIndex,const Vec4 barycentricCoordinate) -{ - const typename DataTypes::VecCoord& p =(this->object->read(core::ConstVecCoordId::position())->getValue()); - return(computeNodalValue(tetrahedronIndex,barycentricCoordinate,p)); -} -template -typename DataTypes::Real BezierTetrahedronSetGeometryAlgorithms::computeBernsteinPolynomial(const TetrahedronBezierIndex tbi, const Vec4 barycentricCoordinate) -{ - Real val=pow(barycentricCoordinate[0],tbi[0])*pow(barycentricCoordinate[1],tbi[1])*pow(barycentricCoordinate[2],tbi[2])*pow(barycentricCoordinate[3],tbi[3]); - typename std::map::iterator it=bernsteinCoeffMap.find(tbi); - if (it!=bernsteinCoeffMap.end()) { - val*=(*it).second; - return(val); - } else { - val*=multinomial(tbi[0]+tbi[1]+tbi[2]+tbi[3],tbi); - return(val); - } -} - template - typename BezierTetrahedronSetGeometryAlgorithms::Real - BezierTetrahedronSetGeometryAlgorithms::computeJacobian(const size_t tetrahedronIndex, const Vec4 barycentricCoordinate, const typename DataTypes::VecCoord& p) - { - /// the 3 derivatives - Coord dpos[3]; - - TetrahedronBezierIndex tbi; - size_t j; - Real val; - const VecPointID &indexArray=container->getGlobalIndexArrayOfBezierPoints(tetrahedronIndex); - bool isRational=container->isRationalSpline(tetrahedronIndex); - if (isRational) { - const BezierTetrahedronSetTopologyContainer::SeqWeights &wa=container->getWeightArray(); - Real weight=(Real)0.0f; - Real dweight[3]= {0,0,0}; - dweight[0]=dweight[1]=dweight[2]=(Real)0.0f; - Coord pos; - for(size_t i=0; i - typename BezierTetrahedronSetGeometryAlgorithms::Real - BezierTetrahedronSetGeometryAlgorithms::computeJacobian(const size_t tetrahedronIndex, const Vec4 barycentricCoordinate) - { - const typename DataTypes::VecCoord& p =(this->object->read(core::ConstVecCoordId::position())->getValue()); - return(computeJacobian(tetrahedronIndex,barycentricCoordinate,p)); - - } -template -void BezierTetrahedronSetGeometryAlgorithms::computeDeCasteljeauPoints(const size_t tetrahedronIndex, const Vec4 barycentricCoordinate, const VecCoord& p, Coord dpos[4]) -{ - /// the 4 derivatives - - TetrahedronBezierIndex tbi; - size_t j; - Real val; - const VecPointID &indexArray=container->getGlobalIndexArrayOfBezierPoints(tetrahedronIndex); - // initialize dpos - for (j=0;j<4;++j) - dpos[j]=Coord(); - bool isRational=container->isRationalSpline(tetrahedronIndex); - if (isRational) { - const BezierTetrahedronSetTopologyContainer::SeqWeights &wa=container->getWeightArray(); - Real weight=(Real)0.0f; - Real dweight[4]; - dweight[0]=0.0f;dweight[1]=0.0f;dweight[2]=0.0f;dweight[3]=0.0f; - - Coord pos; - for(size_t i=0; i -bool BezierTetrahedronSetGeometryAlgorithms::isBezierTetrahedronAffine(const size_t tetrahedronIndex,const VecCoord& p, Real tolerance) const{ - // get the global indices of all points - - const VecPointID &indexArray=container->getGlobalIndexArrayOfBezierPoints(tetrahedronIndex); - bool affine=true; - - /// skip the first 4 control points corresponding to the 4 corners - size_t index=0; - Coord corner[4],pos,actualPos; - // store the position of the 4 corners - for (index=0;index<4;++index) - corner[index]=p[indexArray[index]]; - do { - // compute the position of the control point as if the tetrahedron was affine - pos=corner[0]*tbiArray[index][0]+corner[1]*tbiArray[index][1]+corner[2]*tbiArray[index][2]+ - corner[3]*tbiArray[index][3]; - pos/=degree; - // measure the distance between the real position and the affine position - actualPos=p[indexArray[index]]; - if ((actualPos-pos).norm2()>tolerance) { - affine=false; - } - index++; - } while ((affine) && (index - typename BezierTetrahedronSetGeometryAlgorithms::Vec4 BezierTetrahedronSetGeometryAlgorithms::computeBernsteinPolynomialGradient(const TetrahedronBezierIndex tbi, const Vec4 barycentricCoordinate) - { - Real val=computeBernsteinPolynomial(tbi,barycentricCoordinate); - Vec4 dval(0,0,0,0); - for(unsigned i=0;i<4;++i) - if(tbi[i] && barycentricCoordinate[i]) - dval[i]=(Real)tbi[i]*val/barycentricCoordinate[i]; - return dval; - } - - template - typename BezierTetrahedronSetGeometryAlgorithms::Mat44 BezierTetrahedronSetGeometryAlgorithms::computeBernsteinPolynomialHessian(const TetrahedronBezierIndex tbi, const Vec4 barycentricCoordinate) - { - Vec4 dval = computeBernsteinPolynomialGradient(tbi,barycentricCoordinate); - Mat44 ddval; - for(unsigned i=0;i<4;++i) - if(barycentricCoordinate[i]) - for(unsigned j=0;j<4;++j) - { - if(i==j) { if(tbi[i]>1) ddval[j][i]=((Real)tbi[i]-1.)*dval[j]/barycentricCoordinate[i]; } - else { if(tbi[i]) ddval[j][i]=(Real)tbi[i]*dval[j]/barycentricCoordinate[i]; } - } - return ddval; - } - -template -void BezierTetrahedronSetGeometryAlgorithms::draw(const core::visual::VisualParams* vparams) -{ - - if ((degree>0) && (container) ) - { - TetrahedronSetGeometryAlgorithms::draw(vparams); - // Draw Tetra - // reference radius - if (d_referenceRadius.getValue()<0.0) { - // estimate the mean radius of the spheres from the first Bezier triangle - -// size_t nbPoints=container->getNbPoints(); -// size_t i,elementIndex,elementOffset; - const typename DataTypes::VecCoord& coords =(this->object->read(core::ConstVecCoordId::position())->getValue()); -// BezierTetrahedronSetTopologyContainer::BezierTetrahedronPointLocation location; - const VecPointID &indexArray=container->getGlobalIndexArrayOfBezierPoints(0); - std::vector edgeLengthArray; - // compute median of the edge distance between control points - sofa::helper::set >::iterator ite=bezierTetrahedronEdgeSet.begin(); - //Real val=0; - Coord pp; - for (; ite!=bezierTetrahedronEdgeSet.end(); ite++) - { - pp = coords[indexArray[(*ite).first[0]]] -coords[indexArray[(*ite).first[1]]] ; - edgeLengthArray.push_back(pp.norm()); - } - std::nth_element(edgeLengthArray.begin(), edgeLengthArray.begin() + edgeLengthArray.size()/2, edgeLengthArray.end()); - Real radius=edgeLengthArray[edgeLengthArray.size()/2]/5; - d_referenceRadius.setValue(radius); - } - - if (drawControlPoints.getValue()) - { - size_t nbPoints=container->getNbPoints(); - size_t i,elementIndex,elementOffset; - const typename DataTypes::VecCoord& pos =(this->object->read(core::ConstVecCoordId::position())->getValue()); - BezierTetrahedronSetTopologyContainer::BezierTetrahedronPointLocation location; - - if (container->getNbTriangles()>0) { - // estimate the mean radius of the spheres from the first Bezier triangle -// VecPointID indexArray; - float radius = (float)d_referenceRadius.getValue(); - std::vector pointsVertices,pointsEdges,pointsTriangles,pointsTetrahedra; - std::vector radiusVertices,radiusEdges,radiusTriangles,radiusTetrahedra; - sofa::defaulttype::Vector3 p; - - - for (i=0;igetLocationFromGlobalIndex(i,location,elementIndex,elementOffset); - if (location==BezierTetrahedronSetTopologyContainer::POINT) { - p=pos[i]; - pointsVertices.push_back(p); - - radiusVertices.push_back(radius*(float)container->getWeight(i)); - - } else if (location==BezierTetrahedronSetTopologyContainer::EDGE) { - p=pos[i]; - pointsEdges.push_back(p); - - radiusEdges.push_back(radius*(float)container->getWeight(i)); - - } else if (location==BezierTetrahedronSetTopologyContainer::TRIANGLE) { - p=pos[i]; - pointsTriangles.push_back(p); - - radiusTriangles.push_back(radius*(float)container->getWeight(i)); - - } else { - p=pos[i]; - pointsTetrahedra.push_back(p); - - radiusTetrahedra.push_back(radius*(float)container->getWeight(i)); - } - } - vparams->drawTool()->setLightingEnabled(true); //Enable lightning - vparams->drawTool()->drawSpheres(pointsVertices, radiusVertices, defaulttype::Vec<4,float>(1.0f,0,0,1.0f)); - vparams->drawTool()->drawSpheres(pointsEdges, radiusEdges, defaulttype::Vec<4,float>(0,1.0f,0,1.0f)); - vparams->drawTool()->drawSpheres(pointsTriangles, radiusTriangles, defaulttype::Vec<4,float>(0,0,1.0f,1.0f)); - vparams->drawTool()->drawSpheres(pointsTetrahedra, radiusTetrahedra, defaulttype::Vec<4,float>(1,0,1.0f,1.0f)); - vparams->drawTool()->setLightingEnabled(false); //Disable lightning - } - } - // Draw edges linking Bezier tetrahedra control points with a color code - if (drawSmoothEdges.getValue()) - { - - const sofa::helper::vector &tetraArray = this->m_topology->getTetrahedra(); - - if (!tetraArray.empty()) - { - float radius = (float)d_referenceRadius.getValue(); - const typename DataTypes::VecCoord& coords =(this->object->read(core::ConstVecCoordId::position())->getValue()); - std::vector pointsVertices; - std::vector radiusVertices; - sofa::defaulttype::Vector3 p1; - size_t elementIndex,i,elementOffset; - BezierTetrahedronSetTopologyContainer::BezierTetrahedronPointLocation location; - size_t nbPoints=container->getNbPoints(); - - for (i=0;igetLocationFromGlobalIndex(i,location,elementIndex,elementOffset); - if (location==BezierTetrahedronSetTopologyContainer::POINT) { - p1=coords[i]; - pointsVertices.push_back(p1); - - radiusVertices.push_back(radius*(float)container->getWeight(i)); - - } - } - vparams->drawTool()->setLightingEnabled(true); //Enable lightning - vparams->drawTool()->drawSpheres(pointsVertices, radiusVertices, defaulttype::Vec<4,float>(1.0f,0,0,1.0f)); - vparams->drawTool()->setLightingEnabled(false); //Disable lightning - -#ifndef SOFA_NO_OPENGL - glDisable(GL_LIGHTING); - - glColor3f(0.0f, 1.0f, 0.0f); - glLineWidth(3.0); - glEnable(GL_DEPTH_TEST); - glEnable(GL_POLYGON_OFFSET_LINE); - glPolygonOffset(-1.0,100.0); - - const unsigned int edgesInTetrahedronArray[6][2] = {{0,1}, {0,2}, {0,3}, {1,2}, {1,3}, {2,3}}; - const unsigned int oppositeEdgesInTetrahedronArray[6][2] = {{2,3}, {1,3}, {1,2}, {0,3}, {0,2}, {0,1}}; - // how many points is used to discretize the edge - const size_t edgeTesselation=9; - sofa::defaulttype::Vec3f p; //,p2; - for ( i = 0; igetGlobalIndexArrayOfBezierPoints(i); -// sofa::helper::vector trianCoord; - // process each edge of the tetrahedron - for (size_t j = 0; j<6; j++) { - Vec4 baryCoord; - baryCoord[oppositeEdgesInTetrahedronArray[j][0]]=0; - baryCoord[oppositeEdgesInTetrahedronArray[j][1]]=0; - glBegin(GL_LINE_STRIP); - for (size_t k=0;k<=edgeTesselation;++k) { - baryCoord[edgesInTetrahedronArray[j][0]]=(Real)k/(Real)edgeTesselation; - baryCoord[edgesInTetrahedronArray[j][1]]=(Real)(edgeTesselation-k)/(Real)edgeTesselation; - p=DataTypes::getCPos(computeNodalValue(i,baryCoord)); - glVertex3f(p[0],p[1],p[2]); - } - glEnd(); - } - } - glDisable(GL_POLYGON_OFFSET_LINE); -#endif // SOFA_NO_OPENGL - } - - } - - if (drawControlPointsEdges.getValue()) - { -#ifndef SOFA_NO_OPENGL - const sofa::helper::vector &tetraArray = this->m_topology->getTetrahedra(); - if (!tetraArray.empty()) - { - glDisable(GL_LIGHTING); - const sofa::defaulttype::Vec4f& color = this->_drawColor.getValue(); - glColor3f(color[0], color[1], color[2]); - glBegin(GL_LINES); - const VecCoord& coords =(this->object->read(core::ConstVecCoordId::position())->getValue()); - - Vec4 baryCoord; - sofa::defaulttype::Vec3f p; //,p2; - for (unsigned int i = 0; igetGlobalIndexArrayOfBezierPoints(i); - sofa::helper::vector tetraCoord; - - for (unsigned int j = 0; j >::iterator ite=bezierTetrahedronEdgeSet.begin(); - for (; ite!=bezierTetrahedronEdgeSet.end(); ite++) - { - if ((*ite).second==2) { - glColor3f(0.0f, 1.0f, 0.0f); - } else if ((*ite).second==1) { - glColor3f(0.0f, 0.0f, 1.0f ); - } else { - glColor3f(1.0f, 0.0f, 1.0f ); - } - glVertex3f(tetraCoord[(*ite).first[0]][0], tetraCoord[(*ite).first[0]][1], tetraCoord[(*ite).first[0]][2]); - glVertex3f(tetraCoord[(*ite).first[1]][0], tetraCoord[(*ite).first[1]][1], tetraCoord[(*ite).first[1]][2]); - - - } - } - glEnd(); - } -#endif // SOFA_NO_OPENGL - } - } - -} - - - -} // namespace topology - -} // namespace component - -} // namespace sofa - -#endif // SOFA_COMPONENTS_TETEAHEDRONSETGEOMETRYALGORITHMS_INL diff --git a/modules/SofaGeneralTopology/BezierTetrahedronSetTopologyContainer.cpp b/modules/SofaGeneralTopology/BezierTetrahedronSetTopologyContainer.cpp deleted file mode 100644 index 8ab4e939096..00000000000 --- a/modules/SofaGeneralTopology/BezierTetrahedronSetTopologyContainer.cpp +++ /dev/null @@ -1,650 +0,0 @@ -/****************************************************************************** -* SOFA, Simulation Open-Framework Architecture, development version * -* (c) 2006-2016 INRIA, USTL, UJF, CNRS, MGH * -* * -* This library 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 library 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 library; if not, write to the Free Software Foundation, * -* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * -******************************************************************************* -* SOFA :: Modules * -* * -* Authors: The SOFA Team and external contributors (see Authors.txt) * -* * -* Contact information: contact@sofa-framework.org * -******************************************************************************/ - -#include -#include -#include - - -namespace sofa -{ - -namespace component -{ - -namespace topology -{ - -using namespace std; -using namespace sofa::defaulttype; - -SOFA_DECL_CLASS(BezierTetrahedronSetTopologyContainer) -int BezierTetrahedronSetTopologyContainerClass = core::RegisterObject("Bezier Tetrahedron set topology container") - .add< BezierTetrahedronSetTopologyContainer >() - ; - -const unsigned int edgesInTetrahedronArray[6][2] = {{0,1}, {0,2}, {0,3}, {1,2}, {1,3}, {2,3}}; -///convention triangles in tetra (orientation interior) -const unsigned int trianglesInTetrahedronArray[4][3]= {{1,2,3}, {0,3,2}, {1,3,0},{0,2,1}}; - - - -typedef std::pair ElementMapType; -typedef std::map::iterator ElementMapIterator; - -typedef std::pair OffsetMapType; -typedef std::map::iterator OffsetMapIterator; -typedef std::map::const_iterator OffsetMapConstIterator; - -BezierTetrahedronSetTopologyContainer::BezierTetrahedronSetTopologyContainer() - : TetrahedronSetTopologyContainer() - , d_degree(initData(&d_degree, (BezierDegreeType)0,"degree", "Degree of Bezier Tetrahedra")) - , d_numberOfTetrahedralPoints(initData(&d_numberOfTetrahedralPoints, (size_t) 0,"NbTetrahedralVertices", "Number of Tetrahedral Vertices")) - , d_isRationalSpline(initData(&d_isRationalSpline, SeqBools(),"isRational", "If a bezier tetrahedron is rational or integral")) - , d_weightArray(initData(&d_weightArray, SeqWeights(),"weights", "Array of weights for rational bezier tetrahedra")) -{ - addAlias(&d_degree, "order"); -} - - - -void BezierTetrahedronSetTopologyContainer::init() -{ - d_degree.updateIfDirty(); // make sure m_tetrahedron is up to date - d_numberOfTetrahedralPoints.updateIfDirty(); - TetrahedronSetTopologyContainer::init(); // initialize the tetrahedron array - reinit(); -} -void BezierTetrahedronSetTopologyContainer::reinit() -{ - if (d_degree.getValue()>0) { - // fill the elementMap and the 3 offsetMap in order to get the global index of an element from its Bezier index - BezierDegreeType degree=d_degree.getValue(); - BezierDegreeType i,j,k; - size_t localIndex=0; - // vertex index - for (i=0;i<4;++i) { - TetrahedronBezierIndex bti(0,0,0,0); - bti[i]=degree; - elementMap.insert(ElementMapType(bti,ElementTetrahedronIndex(i,-1,-1,-1))); - localIndexMap.insert(OffsetMapType(bti,localIndex)); - bezierIndexArray.push_back(bti); - localIndex++; - } - // edge index - if (degree>1) { - for (i=0;i<6;++i) { - - for (j=1;j2) { - size_t ind; - offsetToTriangleBezierIndexArray.clear(); - for (i=0;i<4;++i) { - for (ind=0,j=1;j<(degree-1);++j) { - for (k=1;k<(degree-j);++k,++ind) { - TetrahedronBezierIndex bti(0,0,0,0); - bti[trianglesInTetrahedronArray[i][0]]=j; - bti[trianglesInTetrahedronArray[i][1]]=k; - bti[trianglesInTetrahedronArray[i][2]]=degree-j-k; - if (i==0) - offsetToTriangleBezierIndexArray.push_back(TriangleBezierIndex(j,k,degree-k-j)); - elementMap.insert(ElementMapType(bti,ElementTetrahedronIndex(-1,-1,i,-1))); - triangleOffsetMap.insert(OffsetMapType(bti,ind)); - // std::cerr << "offsetMap["<<(size_t)bti[0]<<' '<<(size_t)bti[1]<<' '<<(size_t)bti[2]<<' '<<(size_t)bti[3]<<" ]= "<3) { - size_t ind=0; - offsetToTetrahedronBezierIndexArray.clear(); - for (i=1;i<(degree-2);++i) { - for (j=1;j<(degree-i-1);++j) { - for (k=1;k<(degree-j-i);++k,++ind) { - TetrahedronBezierIndex bti(0,0,0,0); - bti[0]=i;bti[1]=j;bti[2]=k; - bti[3]=degree-i-j-k; - offsetToTetrahedronBezierIndexArray.push_back(bti); - elementMap.insert(ElementMapType(bti,ElementTetrahedronIndex(-1,-1,-1,0))); - tetrahedronOffsetMap.insert(OffsetMapType(bti,ind)); - localIndexMap.insert(OffsetMapType(bti,localIndex)); - bezierIndexArray.push_back(bti); - localIndex++; - } - } - } - } - // initialize the array of weights if necessary - - if (d_weightArray.getValue().empty()){ - - SeqWeights &wa=*(d_weightArray.beginEdit()); - wa.resize(this->getNbPoints()); - std::fill(wa.begin(),wa.end(),(SReal)1); - d_weightArray.endEdit(); - } - if (d_isRationalSpline.getValue().empty()){ - helper::WriteOnlyAccessor > isRationalSpline=d_isRationalSpline; - isRationalSpline.resize(this->getNbPoints()); - std::fill(isRationalSpline.begin(),isRationalSpline.end(),false); - } - // manually creates the edge and triangle structures. - createTriangleSetArray(); - createEdgeSetArray(); - createEdgesInTetrahedronArray(); - createTrianglesInTetrahedronArray(); - } - if ((d_numberOfTetrahedralPoints.getValue()==0) && (getNumberOfTetrahedra()>0)){ - // compute the number of tetrahedral point if it is not provided - std::set vertexSet; - size_t i; - // count the number of vertices involved in the list of tetrahedra - const sofa::helper::vector &tra=getTetrahedronArray(); - for (i=0;i BezierTetrahedronSetTopologyContainer::getTetrahedronBezierIndexArray() const -{ - return (bezierIndexArray); -} -sofa::helper::vector BezierTetrahedronSetTopologyContainer::getTetrahedronBezierIndexArrayOfGivenDegree(const BezierDegreeType deg) const -{ - // vertex index - size_t i,j,k; - sofa::helper::vector tbiArray; - for (i=0;i<4;++i) { - TetrahedronBezierIndex bti(0,0,0,0); - bti[i]=deg; - tbiArray.push_back(bti); - } - // edge index - if (deg>1) { - for (i=0;i<6;++i) { - for (j=1;j2) {; - for (i=0;i<4;++i) { - for (j=1;j<(size_t)(deg-1);++j) { - for (k=1;k<(deg-j);++k) { - TetrahedronBezierIndex bti(0,0,0,0); - bti[trianglesInTetrahedronArray[i][0]]=j; - bti[trianglesInTetrahedronArray[i][1]]=k; - bti[trianglesInTetrahedronArray[i][2]]=deg-j-k; - tbiArray.push_back(bti); - } - } - } - } - // tetrahedron index - if (deg>3) { - for (i=1;i<(size_t)(deg-2);++i) { - for (j=1;j<(size_t)(deg-i-1);++j) { - for (k=1;k<(deg-j-i);++k) { - TetrahedronBezierIndex bti(0,0,0,0); - bti[0]=i;bti[1]=j;bti[2]=k; - bti[3]=deg-i-j-k; - tbiArray.push_back(bti); - } - } - } - } - return(tbiArray); -} -sofa::helper::vector BezierTetrahedronSetTopologyContainer::getMapOfTetrahedronBezierIndexArrayFromInferiorDegree() const -{ - BezierDegreeType degree=d_degree.getValue(); - sofa::helper::vector tbiDerivArray=getTetrahedronBezierIndexArrayOfGivenDegree(degree-1); - sofa::helper::vector tbiLinearArray=getTetrahedronBezierIndexArrayOfGivenDegree(1); - TetrahedronBezierIndex tbi; - sofa::helper::vector correspondanceArray; -// correspondanceArray.resize(tbiDerivArray.size()); - size_t i,j; - for (i=0;i1) { - EdgesInTetrahedron eit=getEdgesInTetrahedron(tetrahedronIndex); - for (i=0;i<6;++i) { - Edge e=getEdge(eit[i]); - if (locationToGlobalIndexMap.empty()) { - offset=getNumberOfTetrahedralPoints()+eit[i]*(degree-1); - // check the order of the edge to be consistent with the tetrahedron - if (e[0]==tet[edgesInTetrahedronArray[i][0]]) { - for (j=0;j<(size_t)(degree-1);++j) { - indexArray.push_back(offset+j); - } - } else { - int jj; - for (jj=degree-2;jj>=0;--jj) { - indexArray.push_back(offset+jj); - } - } - } else { - ControlPointLocation cpl; - - if (e[0]!=tet[edgesInTetrahedronArray[i][0]]) { - for (j=0;j<(size_t)(degree-1);++j) { - cpl=ControlPointLocation(eit[i],std::make_pair(EDGE,j)); - assert(locationToGlobalIndexMap.find(cpl)!=locationToGlobalIndexMap.end()); - indexArray.push_back(locationToGlobalIndexMap[cpl]); - } - } - else { - int jj; - for (jj=degree-2;jj>=0;--jj) { - cpl=ControlPointLocation(eit[i],std::make_pair(EDGE,(size_t)jj)); - assert(locationToGlobalIndexMap.find(cpl)!=locationToGlobalIndexMap.end()); - indexArray.push_back(locationToGlobalIndexMap[cpl]); - } - } - - } - } - } - // triangle index - if (degree>2) { - TrianglesInTetrahedron tit=getTrianglesInTetrahedron(tetrahedronIndex); - size_t pointsPerTriangle=(degree-1)*(degree-2)/2; - for (i=0;i<4;++i) { - offset=getNumberOfTetrahedralPoints()+getNumberOfEdges()*(degree-1)+tit[i]*pointsPerTriangle; - Triangle tr=getTriangle(tit[i]); - Triangle indexTriangle; - for (k=0;(tr[0]!=tet[trianglesInTetrahedronArray[i][k]]);++k); - indexTriangle[k]=0; - if (tr[1]==tet[trianglesInTetrahedronArray[i][(k+1)%3]]) { - indexTriangle[(k+1)%3]=1; - indexTriangle[(k+2)%3]=2; - } else { - indexTriangle[(k+2)%3]=1; - indexTriangle[(k+1)%3]=2; - } - for (j=1;j<(size_t)(degree-1);++j) { - for (k=1;k<(degree-j);++k) { - TetrahedronBezierIndex bti(0,0,0,0); - bti[trianglesInTetrahedronArray[i][indexTriangle[0]]]=j; - bti[trianglesInTetrahedronArray[i][indexTriangle[1]]]=k; - bti[trianglesInTetrahedronArray[i][indexTriangle[2]]]=degree-j-k; - OffsetMapIterator omi=triangleOffsetMap.find(bti); - if (locationToGlobalIndexMap.empty()) { - indexArray.push_back(offset+(*omi).second); - } else { - ControlPointLocation cpl(tit[i],std::make_pair(TRIANGLE,(*omi).second)); - assert(locationToGlobalIndexMap.find(cpl)!=locationToGlobalIndexMap.end()); - indexArray.push_back(locationToGlobalIndexMap[cpl]); - } - } - } - } - } - - - // tetrahedron index - if (degree>3) { - size_t pointsPerTetrahedron=(degree-1)*(degree-2)*(degree-3)/6; - offset=getNumberOfTetrahedralPoints()+getNumberOfEdges()*(degree-1)+getNumberOfTriangles()*(degree-1)*(degree-2)/2+tetrahedronIndex*pointsPerTetrahedron; - size_t rank=0; - for (i=0;i<(size_t)(degree-3);++i) { - for (j=0;j<(degree-i-3);++j) { - for (k=0;k<(degree-j-i-3);++k) { - if (locationToGlobalIndexMap.empty()) { - indexArray.push_back(offset+rank); - } else { - ControlPointLocation cpl(tetrahedronIndex,std::make_pair(TETRAHEDRON,rank)); - assert(locationToGlobalIndexMap.find(cpl)!=locationToGlobalIndexMap.end()); - indexArray.push_back(locationToGlobalIndexMap[cpl]); - } - rank++; - } - } - } - } - - } -void BezierTetrahedronSetTopologyContainer::getLocationFromGlobalIndex(const size_t globalIndex, BezierTetrahedronPointLocation &location, - size_t &elementIndex, size_t &elementOffset) -{ - size_t gi=globalIndex; - if (globalIndexToLocationMap.empty()) { - if (gi::iterator itcpl=globalIndexToLocationMap.find(globalIndex); -#ifndef NDEBUG - if (itcpl==globalIndexToLocationMap.end()) - sout << "Error. [BezierTetrahedronSetTopologyContainer::getLocationFromGlobalIndex] Global Index "<< globalIndex <<" is not in the map globalIndexToLocationMap " << sendl; - assert(itcpl!=globalIndexToLocationMap.end()); -#endif - location=((*itcpl).second).second.first; - elementIndex=((*itcpl).second).first; - elementOffset=((*itcpl).second).second.second; - } -} -void BezierTetrahedronSetTopologyContainer::getEdgeBezierIndexFromEdgeOffset(size_t offset, EdgeBezierIndex &ebi){ - assert(offset tbiArray=getTetrahedronBezierIndexArray(); - VecPointID indexArray; - BezierTetrahedronPointLocation location; - size_t elementIndex, elementOffset/*,localIndex*/; - for (nTetras=0;nTetras0) { - // check consistency between both maps - assert(locationToGlobalIndexMap.size()==globalIndexToLocationMap.size()); - std::map::iterator itcpl; - std::map::iterator itgi; - for (itcpl=locationToGlobalIndexMap.begin();itcpl!=locationToGlobalIndexMap.end();++itcpl) { - itgi=globalIndexToLocationMap.find(itcpl->second); - assert(itgi!=globalIndexToLocationMap.end()); - assert((*itgi).second==(*itcpl).first); - } - } - return( true); -} - -} // namespace topology - -} // namespace component - -} // namespace sofa diff --git a/modules/SofaGeneralTopology/BezierTetrahedronSetTopologyContainer.h b/modules/SofaGeneralTopology/BezierTetrahedronSetTopologyContainer.h deleted file mode 100644 index f26cd3630d0..00000000000 --- a/modules/SofaGeneralTopology/BezierTetrahedronSetTopologyContainer.h +++ /dev/null @@ -1,260 +0,0 @@ -/****************************************************************************** -* SOFA, Simulation Open-Framework Architecture, development version * -* (c) 2006-2016 INRIA, USTL, UJF, CNRS, MGH * -* * -* This library 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 library 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 library; if not, write to the Free Software Foundation, * -* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * -******************************************************************************* -* SOFA :: Modules * -* * -* Authors: The SOFA Team and external contributors (see Authors.txt) * -* * -* Contact information: contact@sofa-framework.org * -******************************************************************************/ -#ifndef SOFA_COMPONENT_TOPOLOGY_BEZIERTETRAHEDRONSETTOPOLOGYCONTAINER_H -#define SOFA_COMPONENT_TOPOLOGY_BEZIERTETRAHEDRONSETTOPOLOGYCONTAINER_H -#include "config.h" - -#include - - -namespace sofa -{ - -namespace component -{ - -namespace topology -{ -class BezierTetrahedronSetTopologyModifier; - -//using core::topology::BaseMeshTopology; - -typedef unsigned char BezierDegreeType; -typedef sofa::defaulttype::Vec<4,BezierDegreeType> TetrahedronBezierIndex; - -/** a class that stores a set of Bezier tetrahedra and provides access with adjacent triangles, edges and vertices -A Bezier Tetrahedron has exactly the same topology as a Tetrahedron but with additional (control) points on its edges, triangles and inside -We use a Vec4D to number the control points inside a Bezier tetrahedron */ -class SOFA_GENERAL_TOPOLOGY_API BezierTetrahedronSetTopologyContainer : public TetrahedronSetTopologyContainer -{ - -public: - SOFA_CLASS(BezierTetrahedronSetTopologyContainer,TetrahedronSetTopologyContainer); - - typedef BaseMeshTopology::PointID PointID; - typedef BaseMeshTopology::EdgeID EdgeID; - typedef BaseMeshTopology::TriangleID TriangleID; - typedef BaseMeshTopology::TetraID TetraID; - typedef BaseMeshTopology::Edge Edge; - typedef BaseMeshTopology::Triangle Triangle; - typedef BaseMeshTopology::Tetra Tetra; - typedef BaseMeshTopology::SeqTetrahedra SeqTetrahedra; - typedef sofa::defaulttype::Vec<2,BezierDegreeType> EdgeBezierIndex; - typedef sofa::defaulttype::Vec<3,BezierDegreeType> TriangleBezierIndex; - - - - typedef Tetra Tetrahedron; - typedef EdgesInTetrahedron EdgesInTetrahedron; - typedef TrianglesInTetrahedron TrianglesInTetrahedron; - typedef sofa::helper::vector VecPointID; - typedef sofa::helper::vector VecTetraID; - typedef sofa::helper::vector SeqWeights; - typedef sofa::helper::vector SeqBools; - typedef VecPointID BezierDOFInTetrahedron; - typedef sofa::helper::vector< VecPointID > SeqBezierDOFInTetrahedron; - - - - typedef sofa::defaulttype::Vec<4,int> ElementTetrahedronIndex; - typedef sofa::defaulttype::Vec<4,size_t> LocalTetrahedronIndex; - - friend class BezierTetrahedronSetTopologyModifier; - friend class Mesh2BezierTopologicalMapping; - -public : - // specifies where a Bezier Point can lies with respect to the underlying tetrahedral mesh - enum BezierTetrahedronPointLocation - { - POINT = 0, - EDGE =1 , - TRIANGLE = 2, - TETRAHEDRON = 3 - }; - - - typedef std::pair > ControlPointLocation; -protected: - BezierTetrahedronSetTopologyContainer(); - - virtual ~BezierTetrahedronSetTopologyContainer() {} -public: - virtual void init(); - // build some maps specific of the degree of the tetrahedral elements. - virtual void reinit(); - - /// Bezier Specific Information Topology API - /// @{ -protected : - /// the degree of the Bezier Tetrahedron 1=linear, 2=quadratic... - Data d_degree; - /// the number of control points corresponding to the vertices of the tetrahedra (different from the total number of points) - Data d_numberOfTetrahedralPoints; - /// whether the Bezier tetrahedron are integral (false = classical Bezier splines) or rational splines (true) - Data d_isRationalSpline; - /// the array of weights for rational splines - Data d_weightArray; -public : - - /// get the Degree of the Bezier Tetrahedron - BezierDegreeType getDegree() const; - /// get the number of control points corresponding to the vertices of the tetrahedra - size_t getNumberOfTetrahedralPoints() const; - /// get the global index of the Bezier point associated with a given tetrahedron index and given its 4D Index - size_t getGlobalIndexOfBezierPoint(const TetraID tetrahedronIndex,const TetrahedronBezierIndex id) ; - /// get the indices of all control points associated with a given tetrahedron - const VecPointID &getGlobalIndexArrayOfBezierPoints(const TetraID tetrahedronIndex) const; - /// return the Bezier index given the local index in a tetrahedron - TetrahedronBezierIndex getTetrahedronBezierIndex(const size_t localIndex) const; - /// get the Tetrahedron Bezier Index Array of degree d - sofa::helper::vector getTetrahedronBezierIndexArray() const; - /// get the Tetrahedron Bezier Index Array of a given degree - sofa::helper::vector getTetrahedronBezierIndexArrayOfGivenDegree(const BezierDegreeType deg) const; - /** create an array which maps the local index of a Tetrahedron Bezier Index of degree d-1 - into a local index of a TBI of degree d by adding respectively (1,0,0,0), (0,1,0,0), (0,0,1,0), (0,0,0,1) **/ - sofa::helper::vector getMapOfTetrahedronBezierIndexArrayFromInferiorDegree() const; - /// return the local index in a tetrahedron from a tetrahedron Bezier index (inverse of getTetrahedronBezierIndex()) - size_t getLocalIndexFromTetrahedronBezierIndex(const TetrahedronBezierIndex id) const; - /// return the location, the element index and offset from the global index of a point - void getLocationFromGlobalIndex(const size_t globalIndex, BezierTetrahedronPointLocation &location, - size_t &elementIndex, size_t &elementOffset) ; - /// convert the edge offset into a EdgeBezierIndex - void getEdgeBezierIndexFromEdgeOffset(size_t offset, EdgeBezierIndex &ebi); - /// convert the triangle offset into a TriangleBezierIndex - void getTriangleBezierIndexFromTriangleOffset(size_t offset, TriangleBezierIndex &tbi); - /// convert the tetrahedron offset into a TriangleBezierIndex - void getTetrahedronBezierIndexFromTetrahedronOffset(size_t offset, TetrahedronBezierIndex &tbi); - /// check the Bezier Point Topology - virtual bool checkBezierPointTopology(); - /** \brief Returns the weight coordinate of the ith DOF. */ - virtual SReal getWeight(int i) const; - /// returns the array of weights - const SeqWeights & getWeightArray() const; - // if the Bezier tetrahedron is rational or integral - bool isRationalSpline(int i) const; - /// @} - - inline friend std::ostream& operator<< (std::ostream& out, const BezierTetrahedronSetTopologyContainer& t) - { - helper::ReadAccessor< Data< sofa::helper::vector > > m_tetrahedron = t.d_tetrahedron; - out << m_tetrahedron<< " " - << t.m_edgesInTetrahedron<< " " - << t.m_trianglesInTetrahedron; - - out << " "<< t.m_tetrahedraAroundVertex.size(); - for (unsigned int i=0; i>(std::istream& in, BezierTetrahedronSetTopologyContainer& t) - { - unsigned int s=0; - sofa::helper::vector< unsigned int > value; - helper::WriteAccessor< Data< sofa::helper::vector > > m_tetrahedron = t.d_tetrahedron; - - in >> m_tetrahedron >> t.m_edgesInTetrahedron >> t.m_trianglesInTetrahedron; - - - in >> s; - for (unsigned int i=0; i> value; - t.m_tetrahedraAroundVertex.push_back(value); - } - in >> s; - for (unsigned int i=0; i> value; - t.m_tetrahedraAroundEdge.push_back(value); - } - in >> s; - for (unsigned int i=0; i> value; - t.m_tetrahedraAroundTriangle.push_back(value); - } - BezierDegreeType bdt=0; - in >> bdt; - t.d_degree.setValue(bdt); - int nbp; - in >> nbp; - t.setNbPoints(nbp); - return in; - } -protected: - /// array describing the global index of the DOFs used in weightedDOFArray - SeqBezierDOFInTetrahedron tetrahedronDOFArray; - /// Map which provides the location (point, edge, triangle, tetrahedron) of a control point given its tetrahedron Bezier index - std::map elementMap; - /// Map which provides the offset in the DOF vector for a control point lying on an edge - std::map edgeOffsetMap; - /// Map which provides the offset in the DOF vector for a control point lying on a triangle - std::map triangleOffsetMap; - /// Map which provides the offset in the DOF vector for a control point lying on a tetrahedron - std::map tetrahedronOffsetMap; - /// Map which provides the rank in a control point from the array outputed by getGlobalIndexArrayOfBezierPointsInTetrahedron (consistent with bezierIndexArray) - std::map localIndexMap; - /// array of the tetrahedron Bezier index outputed by the function getGlobalIndexArrayOfBezierPointsInTetrahedron() - sofa::helper::vector bezierIndexArray; - /// array of the tetrahedron Bezier index outputed by the function getGlobalIndexArrayOfBezierPointsInTetrahedron() - sofa::helper::vector reducedDegreeBezierIndexArray; - /// convert triangle offset into triangle bezier index - sofa::helper::vector offsetToTriangleBezierIndexArray; - /// convert triangle offset into triangle bezier index - sofa::helper::vector offsetToTetrahedronBezierIndexArray; - /** Map which provides the global index of a control point knowing its location (i.e. triangle index and its TriangleBezierIndex). - This is empty by default since there is a default layout of control points based on edge and triangles indices */ - std::map locationToGlobalIndexMap; - /** Map which provides the location (i.e. triangle index and its TriangleBezierIndex) of a control point knowing its global index. - Note that the location may not be unique. - This is empty by default since there is a default layout of control points based on edge and triangles indices */ - std::map globalIndexToLocationMap; - - void getGlobalIndexArrayOfBezierPointsInTetrahedron(const TetraID tetrahedronIndex, VecPointID & indexArray) ; - -}; - -} // namespace topology - -} // namespace component - -} // namespace sofa - -#endif diff --git a/modules/SofaGeneralTopology/BezierTriangleSetGeometryAlgorithms.cpp b/modules/SofaGeneralTopology/BezierTriangleSetGeometryAlgorithms.cpp deleted file mode 100644 index 79084283230..00000000000 --- a/modules/SofaGeneralTopology/BezierTriangleSetGeometryAlgorithms.cpp +++ /dev/null @@ -1,75 +0,0 @@ -/****************************************************************************** -* SOFA, Simulation Open-Framework Architecture, development version * -* (c) 2006-2016 INRIA, USTL, UJF, CNRS, MGH * -* * -* This library 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 library 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 library; if not, write to the Free Software Foundation, * -* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * -******************************************************************************* -* SOFA :: Modules * -* * -* Authors: The SOFA Team and external contributors (see Authors.txt) * -* * -* Contact information: contact@sofa-framework.org * -******************************************************************************/ -#define SOFA_COMPONENT_TOPOLOGY_BEZIERTRIANGLESETGEOMETRYALGORITHMS_CPP -#include -#include -#include -namespace sofa -{ - -namespace component -{ - -namespace topology -{ -using namespace sofa::defaulttype; -SOFA_DECL_CLASS(BezierTriangleSetGeometryAlgorithms) -int BezierTriangleSetGeometryAlgorithmsClass = core::RegisterObject("Bezier Triangle set geometry algorithms") -#ifdef SOFA_FLOAT - .add< BezierTriangleSetGeometryAlgorithms >(true) // default template -#else - .add< BezierTriangleSetGeometryAlgorithms >(true) // default template -#ifndef SOFA_DOUBLE - .add< BezierTriangleSetGeometryAlgorithms >() // default template -#endif -#endif -#ifndef SOFA_FLOAT - .add< BezierTriangleSetGeometryAlgorithms >() - .add< BezierTriangleSetGeometryAlgorithms >() -#endif -#ifndef SOFA_DOUBLE - .add< BezierTriangleSetGeometryAlgorithms >() - .add< BezierTriangleSetGeometryAlgorithms >() -#endif - ; - -#ifndef SOFA_FLOAT -template class SOFA_GENERAL_TOPOLOGY_API BezierTriangleSetGeometryAlgorithms; -template class SOFA_GENERAL_TOPOLOGY_API BezierTriangleSetGeometryAlgorithms; -template class SOFA_GENERAL_TOPOLOGY_API BezierTriangleSetGeometryAlgorithms; -#endif - -#ifndef SOFA_DOUBLE -template class SOFA_GENERAL_TOPOLOGY_API BezierTriangleSetGeometryAlgorithms; -template class SOFA_GENERAL_TOPOLOGY_API BezierTriangleSetGeometryAlgorithms; -template class SOFA_GENERAL_TOPOLOGY_API BezierTriangleSetGeometryAlgorithms; -#endif - -} // namespace topology - -} // namespace component - -} // namespace sofa - diff --git a/modules/SofaGeneralTopology/BezierTriangleSetGeometryAlgorithms.h b/modules/SofaGeneralTopology/BezierTriangleSetGeometryAlgorithms.h deleted file mode 100644 index 509cc6e3e1b..00000000000 --- a/modules/SofaGeneralTopology/BezierTriangleSetGeometryAlgorithms.h +++ /dev/null @@ -1,138 +0,0 @@ -/****************************************************************************** -* SOFA, Simulation Open-Framework Architecture, development version * -* (c) 2006-2016 INRIA, USTL, UJF, CNRS, MGH * -* * -* This library 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 library 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 library; if not, write to the Free Software Foundation, * -* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * -******************************************************************************* -* SOFA :: Modules * -* * -* Authors: The SOFA Team and external contributors (see Authors.txt) * -* * -* Contact information: contact@sofa-framework.org * -******************************************************************************/ -#ifndef SOFA_COMPONENT_TOPOLOGY_BEZIERTRIANGLESETGEOMETRYALGORITHMS_H -#define SOFA_COMPONENT_TOPOLOGY_BEZIERTRIANGLESETGEOMETRYALGORITHMS_H - -#include -#include - - -namespace sofa -{ - -namespace component -{ - -namespace topology -{ - - -/** -* A class that provides geometry information on an Bezier TriangleSet of any degree. -*/ -template < class DataTypes > -class BezierTriangleSetGeometryAlgorithms : public TriangleSetGeometryAlgorithms -{ -public: - SOFA_CLASS(SOFA_TEMPLATE(BezierTriangleSetGeometryAlgorithms,DataTypes),SOFA_TEMPLATE(TriangleSetGeometryAlgorithms,DataTypes)); - - - typedef core::topology::BaseMeshTopology::PointID PointID; - typedef core::topology::BaseMeshTopology::Edge Edge; - typedef core::topology::BaseMeshTopology::TriangleID TriangleID; - typedef core::topology::BaseMeshTopology::Triangle Triangle; - typedef core::topology::BaseMeshTopology::SeqTriangles SeqTriangles; - typedef core::topology::BaseMeshTopology::TrianglesAroundVertex TrianglesAroundVertex; - typedef core::topology::BaseMeshTopology::TrianglesAroundEdge TrianglesAroundEdge; - typedef core::topology::BaseMeshTopology::EdgesInTriangle EdgesInTriangle; - typedef BezierTriangleSetTopologyContainer::VecPointID VecPointID; - typedef typename DataTypes::VecCoord VecCoord; - typedef typename DataTypes::Real Real; - typedef typename DataTypes::Coord Coord; - typedef typename DataTypes::Deriv Deriv; - typedef sofa::defaulttype::Vec<3,Real> Vec3; - typedef sofa::defaulttype::Mat<3,3,Real> Mat33; - - Data drawControlPointsEdges; - Data drawSmoothEdges; - Data drawControlPoints; -protected: - - /// container - BezierTriangleSetTopologyContainer *container; - /// degree of the polynomial - BezierDegreeType degree; - // array of Triangle Bezier indices - sofa::helper::vector tbiArray; - // array of Bernstein coefficient following the same order as tbiArray - sofa::helper::vector bernsteinCoefficientArray; - // map used to store the Bernstein coefficient given a Triangle Bezier Index - std::map bernsteinCoeffMap; - /// the list of edges of the Bezier Triangle used in the draw function - sofa::helper::set > bezierTriangleEdgeSet; - - - /// constructor - BezierTriangleSetGeometryAlgorithms(); - virtual ~BezierTriangleSetGeometryAlgorithms() {} -public: - virtual void init(); - virtual void reinit(); - virtual void draw(const core::visual::VisualParams* vparams); - /// returns a pointer to the BezierTriangleSetTopologyContainer object - BezierTriangleSetTopologyContainer *getTopologyContainer() const { - return container; - } - /// computes the nodal value given the Triangle index, the barycentric coordinates and the vector of nodal values - Coord computeNodalValue(const size_t triangleIndex,const Vec3 barycentricCoordinate,const VecCoord& p); - /// computes the nodal value assuming that the position is the regular position in the mechanical state object - Coord computeNodalValue(const size_t triangleIndex,const Vec3 barycentricCoordinate); - /// computes the shape function - Real computeBernsteinPolynomial(const TriangleBezierIndex tbi, const Vec3 barycentricCoordinate); - /// computes the shape function gradient - Vec3 computeBernsteinPolynomialGradient(const TriangleBezierIndex tbi, const Vec3 barycentricCoordinate); - /// computes the shape function hessian - Mat33 computeBernsteinPolynomialHessian(const TriangleBezierIndex tbi, const Vec3 barycentricCoordinate); - /// computes Jacobian i.e. cross product of dpos/du and dpos/dv - Deriv computeJacobian(const size_t triangleIndex, const Vec3 barycentricCoordinate,const VecCoord& p); - /// computes Jacobian - Deriv computeJacobian(const size_t triangleIndex, const Vec3 barycentricCoordinate); - /// compute the 4 De Casteljeau of degree d-1 - void computeDeCasteljeauPoints(const size_t triangleIndex, const Vec3 barycentricCoordinate, const VecCoord& p,Coord point[3]); - /// test if the Bezier Triangle is a simple affine tesselation of a regular Triangle - bool isBezierTriangleAffine(const size_t triangleIndex,const VecCoord& p, const Real tolerance=(Real)1e-5) const; - -}; - -#if defined(SOFA_EXTERN_TEMPLATE) && !defined(SOFA_COMPONENT_TOPOLOGY_BEZIERTRIANGLESETGEOMETRYALGORITHMS_CPP) -#ifndef SOFA_FLOAT -extern template class SOFA_GENERAL_TOPOLOGY_API BezierTriangleSetGeometryAlgorithms; -extern template class SOFA_GENERAL_TOPOLOGY_API BezierTriangleSetGeometryAlgorithms; -extern template class SOFA_GENERAL_TOPOLOGY_API BezierTriangleSetGeometryAlgorithms; -#endif -#ifndef SOFA_DOUBLE -extern template class SOFA_GENERAL_TOPOLOGY_API BezierTriangleSetGeometryAlgorithms; -extern template class SOFA_GENERAL_TOPOLOGY_API BezierTriangleSetGeometryAlgorithms; -extern template class SOFA_GENERAL_TOPOLOGY_API BezierTriangleSetGeometryAlgorithms; -#endif -#endif - -} // namespace topology - -} // namespace component - -} // namespace sofa - -#endif diff --git a/modules/SofaGeneralTopology/BezierTriangleSetGeometryAlgorithms.inl b/modules/SofaGeneralTopology/BezierTriangleSetGeometryAlgorithms.inl deleted file mode 100644 index 9cd8949664d..00000000000 --- a/modules/SofaGeneralTopology/BezierTriangleSetGeometryAlgorithms.inl +++ /dev/null @@ -1,589 +0,0 @@ -/****************************************************************************** -* SOFA, Simulation Open-Framework Architecture, development version * -* (c) 2006-2016 INRIA, USTL, UJF, CNRS, MGH * -* * -* This library 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 library 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 library; if not, write to the Free Software Foundation, * -* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * -******************************************************************************* -* SOFA :: Modules * -* * -* Authors: The SOFA Team and external contributors (see Authors.txt) * -* * -* Contact information: contact@sofa-framework.org * -******************************************************************************/ -#ifndef SOFA_COMPONENT_TOPOLOGY_BEZIERTRIANGLESETGEOMETRYALGORITHMS_INL -#define SOFA_COMPONENT_TOPOLOGY_BEZIERTRIANGLESETGEOMETRYALGORITHMS_INL - -#include -#include -#include -#include -namespace sofa -{ - -namespace component -{ - -namespace topology -{ - -double multinomial(const size_t n,const TriangleBezierIndex tbiIn) - { - size_t i,ival; - TriangleBezierIndex tbi=tbiIn; - // divide n! with the largest of the multinomial coefficient - std::sort(tbi.begin(),tbi.end()); - ival=1; - for (i=n;i>tbi[2];--i){ - ival*=i; - } - return(((double)ival)/(sofa::helper::factorial(tbi[0])*sofa::helper::factorial(tbi[1]))); - } -template< class DataTypes> - BezierTriangleSetGeometryAlgorithms< DataTypes >::BezierTriangleSetGeometryAlgorithms() : -TriangleSetGeometryAlgorithms() - ,drawControlPointsEdges (core::objectmodel::Base::initData(&drawControlPointsEdges, (bool) false, "drawControlPointsEdges", "Debug : draw Control point edges ")) - ,drawSmoothEdges (core::objectmodel::Base::initData(&drawSmoothEdges, (bool) false, "drawSmoothEdges", "Debug : draw Bezier curves as edges of the Bezier triangle")) - ,drawControlPoints (core::objectmodel::Base::initData(&drawControlPoints, (bool) false, "drawControlPoints", "Debug : draw Control points with a color depending on its status ")) - ,degree(0) - - { - } -template< class DataTypes> - void BezierTriangleSetGeometryAlgorithms< DataTypes >::init() -{ - TriangleSetGeometryAlgorithms::init(); - // recovers the pointer to a BezierTriangleSetTopologyContainer - BezierTriangleSetTopologyContainer *btstc = NULL; - this->getContext()->get(btstc, sofa::core::objectmodel::BaseContext::Local); - if (!btstc) { - serr << " Could not find a BezierTriangleSetTopologyContainer object"<< sendl; - } else { - container=btstc; - /// get the degree of the Bezier Triangle - degree=container->getDegree(); - /// store the Triangle bezier index for each Triangle - tbiArray=container->getTriangleBezierIndexArray(); - /// compute the Bernstein coefficient for each control point in a Triangle - bernsteinCoefficientArray.clear(); - bernsteinCoeffMap.clear(); - bernsteinCoefficientArray.resize(tbiArray.size()); - - TriangleBezierIndex tbi; - /// precompute the factorial of the degree. - for (size_t i=0;i(tbi,(Real) bernsteinCoefficientArray[i])); - } - /// insert coefficient for the inferior degree - BezierDegreeType i,j,k,/*l,*/m,n,index1,index2; - for (i=0;i<=(degree-1);++i) { - for (j=0;j<=(degree-i-1);++j) { - k=degree-1-i-j; - tbi=TriangleBezierIndex(i,j,k); - bernsteinCoeffMap.insert(std::pair(tbi,(Real) multinomial(degree-1,tbi))); - } - } - - /// fills the array of edges - bezierTriangleEdgeSet.clear(); - TriangleBezierIndex tbiNext; - - for (i=0;i<=degree;++i) { - for (j=0;j<=(degree-i);++j) { - k=degree-i-j; - tbi=TriangleBezierIndex(i,j,k); - index1=container->getLocalIndexFromTriangleBezierIndex(tbi); - for(m=0;m<3;++m) { - if (tbi[m]getLocalIndexFromTriangleBezierIndex(tbiNext); - Edge e((PointID)std::min(index1,index2),(PointID)std::max(index1,index2)); - // test if both control points are on an edge - if (tbi[(m+3-n)%3]==0) - bezierTriangleEdgeSet.insert(std::pair(e,true)); - else - bezierTriangleEdgeSet.insert(std::pair(e,false)); - } - } - } - } - } - } - } - - - - } - -template< class DataTypes> - void BezierTriangleSetGeometryAlgorithms< DataTypes >::reinit() -{ -} -template< class DataTypes> -typename DataTypes::Coord BezierTriangleSetGeometryAlgorithms< DataTypes >::computeNodalValue(const size_t triangleIndex,const Vec3 barycentricCoordinate, const typename DataTypes::VecCoord& p) -{ - Coord nodalValue; - nodalValue.clear(); - VecPointID indexArray; - TriangleBezierIndex tbi; - bool isRational=container->isRationalSpline(triangleIndex); - - container->getGlobalIndexArrayOfBezierPointsInTriangle(triangleIndex, indexArray); - if (isRational) { - const BezierTriangleSetTopologyContainer::SeqWeights &wa=container->getWeightArray(); - Real weight=(Real)0.0f; - Real bernsteinPolynonial; - for(size_t i=0; i -typename DataTypes::Coord BezierTriangleSetGeometryAlgorithms< DataTypes >::computeNodalValue(const size_t triangleIndex,const Vec3 barycentricCoordinate) -{ - const typename DataTypes::VecCoord& p =(this->object->read(core::ConstVecCoordId::position())->getValue()); - return(computeNodalValue(triangleIndex,barycentricCoordinate,p)); -} -template -typename DataTypes::Real BezierTriangleSetGeometryAlgorithms::computeBernsteinPolynomial(const TriangleBezierIndex tbi, const Vec3 barycentricCoordinate) -{ - Real val=pow(barycentricCoordinate[0],tbi[0])*pow(barycentricCoordinate[1],tbi[1])*pow(barycentricCoordinate[2],tbi[2]); - typename std::map::iterator it=bernsteinCoeffMap.find(tbi); - if (it!=bernsteinCoeffMap.end()) { - val*=(*it).second; - return(val); - } else { - val*=multinomial(tbi[0]+tbi[1]+tbi[2],tbi); - return(val); - } -} - template - typename BezierTriangleSetGeometryAlgorithms::Deriv - BezierTriangleSetGeometryAlgorithms::computeJacobian(const size_t triangleIndex, const Vec3 barycentricCoordinate, const typename DataTypes::VecCoord& p) - { - /// the 2 derivatives - Deriv dpos[2]; - VecPointID indexArray; - bool isRational=container->isRationalSpline(triangleIndex); - TriangleBezierIndex tbi; - size_t j; - Real val; - container->getGlobalIndexArrayOfBezierPointsInTriangle(triangleIndex, indexArray); - if (isRational) { - const BezierTriangleSetTopologyContainer::SeqWeights &wa=container->getWeightArray(); - Real weight=(Real)0.0f; - Real dweight[2]={0,0}; - Coord pos; - for(size_t i=0; i - typename BezierTriangleSetGeometryAlgorithms::Deriv - BezierTriangleSetGeometryAlgorithms::computeJacobian(const size_t triangleIndex, const Vec3 barycentricCoordinate) - { - const typename DataTypes::VecCoord& p =(this->object->read(core::ConstVecCoordId::position())->getValue()); - return(computeJacobian(triangleIndex,barycentricCoordinate,p)); - - } -template -void BezierTriangleSetGeometryAlgorithms::computeDeCasteljeauPoints(const size_t triangleIndex, const Vec3 barycentricCoordinate, const VecCoord& p, Coord dpos[3]) -{ - /// the 4 derivatives - VecPointID indexArray; - TriangleBezierIndex tbi; - bool isRational=container->isRationalSpline(triangleIndex); - size_t j; - Real val; - container->getGlobalIndexArrayOfBezierPointsInTriangle(triangleIndex, indexArray); - // initialize dpos - for (j=0;j<3;++j) - dpos[j]=Coord(); - if (isRational) { - Real weight=(Real)0.0f; - Real dweight[3]; - const BezierTriangleSetTopologyContainer::SeqWeights &wa=container->getWeightArray(); - Coord pos; - dweight[0]=dweight[1]=0.0; - for(size_t i=0; i -bool BezierTriangleSetGeometryAlgorithms::isBezierTriangleAffine(const size_t triangleIndex,const VecCoord& p, Real tolerance) const{ - // get the global indices of all points - VecPointID indexArray; - container->getGlobalIndexArrayOfBezierPointsInTriangle(triangleIndex, indexArray); - bool affine=true; - - /// skip the first 4 control points corresponding to the 4 corners - size_t index=0; - Coord corner[3],pos,actualPos; - // store the position of the 4 corners - for (index=0;index<3;++index) - corner[index]=p[indexArray[index]]; - do { - // compute the position of the control point as if the Triangle was affine - pos=corner[0]*tbiArray[index][0]+corner[1]*tbiArray[index][1]+corner[2]*tbiArray[index][2]; - - pos/=degree; - // measure the distance between the real position and the affine position - actualPos=p[indexArray[index]]; - if ((actualPos-pos).norm2()>tolerance) { - affine=false; - } - index++; - } while ((affine) && (index - typename BezierTriangleSetGeometryAlgorithms::Vec3 BezierTriangleSetGeometryAlgorithms::computeBernsteinPolynomialGradient(const TriangleBezierIndex tbi, const Vec3 barycentricCoordinate) - { - Real val=computeBernsteinPolynomial(tbi,barycentricCoordinate); - Vec3 dval(0,0,0); - for(unsigned i=0;i<3;++i) - if(tbi[i] && barycentricCoordinate[i]) - dval[i]=(Real)tbi[i]*val/barycentricCoordinate[i]; - return dval; - } - - template - typename BezierTriangleSetGeometryAlgorithms::Mat33 BezierTriangleSetGeometryAlgorithms::computeBernsteinPolynomialHessian(const TriangleBezierIndex tbi, const Vec3 barycentricCoordinate) - { - Vec3 dval = computeBernsteinPolynomialGradient(tbi,barycentricCoordinate); - Mat33 ddval; - for(unsigned i=0;i<3;++i) - if(barycentricCoordinate[i]) - for(unsigned j=0;j<3;++j) - { - if(i==j) { if(tbi[i]>1) ddval[j][i]=((Real)tbi[i]-1.)*dval[j]/barycentricCoordinate[i]; } - else { if(tbi[i]) ddval[j][i]=(Real)tbi[i]*dval[j]/barycentricCoordinate[i]; } - } - return ddval; - } - -template -void BezierTriangleSetGeometryAlgorithms::draw(const core::visual::VisualParams* vparams) -{ - - - if ((degree>0) && (container) ){ - TriangleSetGeometryAlgorithms::draw(vparams); - if (drawControlPoints.getValue()) - { - size_t nbPoints=container->getNbPoints(); - size_t i,elementIndex,elementOffset; - const typename DataTypes::VecCoord& pos =(this->object->read(core::ConstVecCoordId::position())->getValue()); - BezierTriangleSetTopologyContainer::BezierTrianglePointLocation location; - - if (container->getNbTriangles()>0) { - // estimate the mean radius of the spheres from the first Bezier triangle - VecPointID indexArray; - container->getGlobalIndexArrayOfBezierPointsInTriangle(0, indexArray); - std::vector edgeLengthArray; - // compute median of the edge distance between control points - sofa::helper::set >::iterator ite=bezierTriangleEdgeSet.begin(); -// Real val=0; - Coord pp; - for (; ite!=bezierTriangleEdgeSet.end(); ite++) - { - pp = pos[indexArray[(*ite).first[0]]] -pos[indexArray[(*ite).first[1]]] ; - edgeLengthArray.push_back(pp.norm()); - } - std::nth_element(edgeLengthArray.begin(), edgeLengthArray.begin() + edgeLengthArray.size()/2, edgeLengthArray.end()); - Real radius=edgeLengthArray[edgeLengthArray.size()/2]/5; - std::vector pointsVertices,pointsEdges,pointsTriangles; - std::vector radiusVertices,radiusEdges,radiusTriangles; - sofa::defaulttype::Vector3 p; - - - for (i=0;igetLocationFromGlobalIndex(i,location,elementIndex,elementOffset); - if (location==BezierTriangleSetTopologyContainer::NONE) { - } else if (location==BezierTriangleSetTopologyContainer::POINT) { - p=pos[i]; - pointsVertices.push_back(p); - - radiusVertices.push_back(radius*container->getWeight(i)); - - } else if (location==BezierTriangleSetTopologyContainer::EDGE) { - p=pos[i]; - pointsEdges.push_back(p); - - radiusEdges.push_back(radius*container->getWeight(i)); - - } else { - p=pos[i]; - pointsTriangles.push_back(p); - - radiusTriangles.push_back(radius*container->getWeight(i)); - - } - } - vparams->drawTool()->setLightingEnabled(true); //Enable lightning - vparams->drawTool()->drawSpheres(pointsVertices, radiusVertices, defaulttype::Vec<4,float>(1.0f,0,0,1.0f)); - vparams->drawTool()->drawSpheres(pointsEdges, radiusEdges, defaulttype::Vec<4,float>(0,1.0f,0,1.0f)); - vparams->drawTool()->drawSpheres(pointsTriangles, radiusTriangles, defaulttype::Vec<4,float>(0,0,1.0f,1.0f)); - vparams->drawTool()->setLightingEnabled(false); //Disable lightning - } - } - // Draw edges linking Bezier Triangle control points with a color code - if (drawSmoothEdges.getValue()) - { - - const sofa::helper::vector &trianArray = this->m_topology->getTriangles(); - - if (!trianArray.empty()) - { - // estimate the mean radius of the spheres from the first Bezier triangle - VecPointID indexArray; - size_t nbPoints=container->getNbPoints(); - size_t i,elementIndex,elementOffset; - const typename DataTypes::VecCoord& coords =(this->object->read(core::ConstVecCoordId::position())->getValue()); - BezierTriangleSetTopologyContainer::BezierTrianglePointLocation location; - container->getGlobalIndexArrayOfBezierPointsInTriangle(0, indexArray); - std::vector edgeLengthArray; - // compute median of the edge distance between control points - sofa::helper::set >::iterator ite=bezierTriangleEdgeSet.begin(); -// Real val=0; - Coord pp; - for (; ite!=bezierTriangleEdgeSet.end(); ite++) - { - pp = coords[indexArray[(*ite).first[0]]] -coords[indexArray[(*ite).first[1]]] ; - edgeLengthArray.push_back(pp.norm()); - } - std::nth_element(edgeLengthArray.begin(), edgeLengthArray.begin() + edgeLengthArray.size()/2, edgeLengthArray.end()); - Real radius=edgeLengthArray[edgeLengthArray.size()/2]/5; - std::vector pointsVertices; - std::vector radiusVertices; - sofa::defaulttype::Vector3 p1; - - - for (i=0;igetLocationFromGlobalIndex(i,location,elementIndex,elementOffset); - if (location==BezierTriangleSetTopologyContainer::POINT) { - p1=coords[i]; - pointsVertices.push_back(p1); - - radiusVertices.push_back(radius*container->getWeight(i)); - - } - } - vparams->drawTool()->setLightingEnabled(true); //Enable lightning - vparams->drawTool()->drawSpheres(pointsVertices, radiusVertices, defaulttype::Vec<4,float>(1.0f,0,0,1.0f)); - vparams->drawTool()->setLightingEnabled(false); //Disable lightning - -#ifndef SOFA_NO_OPENGL - glDisable(GL_LIGHTING); - - glColor3f(0.0f, 1.0f, 0.0f); - glLineWidth(3.0); - glEnable(GL_DEPTH_TEST); - glEnable(GL_POLYGON_OFFSET_LINE); - glPolygonOffset(-1.0,100.0); - - - // how many points is used to discretize the edge - const size_t edgeTesselation=9; - sofa::defaulttype::Vec3f p; //,p2; - for ( i = 0; igetGlobalIndexArrayOfBezierPointsInTriangle(i, indexArray); - sofa::helper::vector trianCoord; - // process each edge of the triangle - for (size_t j = 0; j<3; j++) { - Vec3 baryCoord; - baryCoord[j]=0; - glBegin(GL_LINE_STRIP); - for (size_t k=0;k<=edgeTesselation;++k) { - baryCoord[(j+1)%3]=(Real)k/(Real)edgeTesselation; - baryCoord[(j+2)%3]=(Real)(edgeTesselation-k)/(Real)edgeTesselation; - p=DataTypes::getCPos(computeNodalValue(i,baryCoord)); - glVertex3f(p[0],p[1],p[2]); - } - glEnd(); - } - } - glDisable(GL_POLYGON_OFFSET_LINE); - - } -#endif // SOFA_NO_OPENGL - } - - // Draw edges linking Bezier Triangle control points with a color code - if (drawControlPointsEdges.getValue()) - { -#ifndef SOFA_NO_OPENGL - const sofa::helper::vector &trianArray = this->m_topology->getTriangles(); - - if (!trianArray.empty()) - { - glDisable(GL_LIGHTING); - const sofa::defaulttype::Vec4f& color = this->_drawColor.getValue(); - glColor3f(color[0], color[1], color[2]); - glBegin(GL_LINES); - const VecCoord& coords =(this->object->read(core::ConstVecCoordId::position())->getValue()); - VecPointID indexArray; - Vec3 baryCoord; - sofa::defaulttype::Vec3f p; //,p2; - for (unsigned int i = 0; igetGlobalIndexArrayOfBezierPointsInTriangle(i, indexArray); - sofa::helper::vector trianCoord; - - for (unsigned int j = 0; j >::iterator ite=bezierTriangleEdgeSet.begin(); - for (; ite!=bezierTriangleEdgeSet.end(); ite++) - { - if ((*ite).second) { - glColor3f(0.0f, 1.0f, 0.0f); - } else { - glColor3f(0.0f, 0.0f, 1.0f ); - } - glVertex3f(trianCoord[(*ite).first[0]][0], trianCoord[(*ite).first[0]][1], trianCoord[(*ite).first[0]][2]); - glVertex3f(trianCoord[(*ite).first[1]][0], trianCoord[(*ite).first[1]][1], trianCoord[(*ite).first[1]][2]); - } - } - glEnd(); -#endif // SOFA_NO_OPENGL - } - - } - } - - -} - - - -} // namespace topology - -} // namespace component - -} // namespace sofa - -#endif // SOFA_COMPONENTS_TRIANGLESETGEOMETRYALGORITHMS_INL diff --git a/modules/SofaGeneralTopology/BezierTriangleSetTopologyContainer.cpp b/modules/SofaGeneralTopology/BezierTriangleSetTopologyContainer.cpp deleted file mode 100644 index 65b233fb765..00000000000 --- a/modules/SofaGeneralTopology/BezierTriangleSetTopologyContainer.cpp +++ /dev/null @@ -1,616 +0,0 @@ -/****************************************************************************** -* SOFA, Simulation Open-Framework Architecture, development version * -* (c) 2006-2016 INRIA, USTL, UJF, CNRS, MGH * -* * -* This library 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 library 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 library; if not, write to the Free Software Foundation, * -* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * -******************************************************************************* -* SOFA :: Modules * -* * -* Authors: The SOFA Team and external contributors (see Authors.txt) * -* * -* Contact information: contact@sofa-framework.org * -******************************************************************************/ - -#include -#include -#include - - -namespace sofa -{ - -namespace component -{ - -namespace topology -{ - -using namespace std; -using namespace sofa::defaulttype; - -SOFA_DECL_CLASS(BezierTriangleSetTopologyContainer) -int BezierTriangleSetTopologyContainerClass = core::RegisterObject("Bezier Triangle set topology container") - .add< BezierTriangleSetTopologyContainer >() - ; - - -typedef std::pair ElementMapType; -typedef std::map::iterator ElementMapIterator; - -typedef std::pair OffsetMapType; -typedef std::map::iterator OffsetMapIterator; -typedef std::map::const_iterator OffsetMapConstIterator; - -BezierTriangleSetTopologyContainer::BezierTriangleSetTopologyContainer() - : TriangleSetTopologyContainer() - , d_degree(initData(&d_degree, (size_t)0,"degree", "Degree of Bezier Tetrahedra")) - , d_numberOfTriangularPoints(initData(&d_numberOfTriangularPoints, (size_t) 0,"NbTriangularVertices", "Number of Triangular Vertices")) - , d_isRationalSpline(initData(&d_isRationalSpline, SeqBools(),"isRational", "If a bezier triangle is rational or integral")) - , d_weightArray(initData(&d_weightArray, SeqWeights(),"weights", "Array of weights for rational bezier triangles")) -{ - addAlias(&d_degree, "order"); -} - - - -void BezierTriangleSetTopologyContainer::init() -{ - d_degree.updateIfDirty(); // make sure m_Triangle is up to date - d_numberOfTriangularPoints.updateIfDirty(); - TriangleSetTopologyContainer::init(); // initialize the Triangle array - reinit(); -} -void BezierTriangleSetTopologyContainer::reinit() -{ - if (d_degree.getValue()>0) { - // clear previous entries if it exists - elementMap.clear(); - localIndexMap.clear(); - bezierIndexArray.clear(); - edgeOffsetMap.clear(); - triangleOffsetMap.clear(); - - // fill the elementMap and the 3 offsetMap in order to get the global index of an element from its Bezier index - BezierDegreeType degree=d_degree.getValue(); - BezierDegreeType i,j; - size_t localIndex=0; - // vertex index - for (i=0;i<3;++i) { - TriangleBezierIndex bti(0,0,0); - bti[i]=degree; - elementMap.insert(ElementMapType(bti,ElementTriangleIndex(i,-1,-1))); - localIndexMap.insert(OffsetMapType(bti,localIndex)); - bezierIndexArray.push_back(bti); - localIndex++; - } - // edge index - if (degree>1) { - for (i=0;i<3;++i) { - - for (j=1;j2) { - offsetToTriangleBezierIndexArray.clear(); - size_t ind=0; - for (i=1;i<(degree-1);++i) { - for (j=1;j<(degree-i);++j,++ind) { - TriangleBezierIndex bti(0,0,0); - bti[0]=i;bti[1]=j; - bti[2]=degree-i-j; - offsetToTriangleBezierIndexArray.push_back(bti); - elementMap.insert(ElementMapType(bti,ElementTriangleIndex(-1,-1,0))); - triangleOffsetMap.insert(OffsetMapType(bti,ind)); - // std::cerr << "offsetMap["<<(size_t)bti[0]<<' '<<(size_t)bti[1]<<' '<<(size_t)bti[2]<<' '<<(size_t)bti[3]<<" ]= "< > wa=d_weightArray; - wa.resize(this->getNbPoints()); - std::fill(wa.begin(),wa.end(),(SReal)1); - } - // initialize the array of boolean indicating if the nature of the Bezier triangle if necessary - if ((d_isRationalSpline.getValue().empty()) && (getNumberOfTriangles()>0)){ - helper::WriteOnlyAccessor > isRationalSpline=d_isRationalSpline; - isRationalSpline.resize(this->getNumberOfTriangles()); - std::fill(isRationalSpline.begin(),isRationalSpline.end(),false); - } - // manually creates the edge and triangle structures. - createEdgeSetArray(); - createEdgesInTriangleArray(); - } - if ((d_numberOfTriangularPoints.getValue()==0) && (getNumberOfTriangles()>0)){ - // compute the number of triangular point if it is not provided - std::set vertexSet; - size_t i; - // count the number of vertices involved in the list of triangles - const sofa::helper::vector &tra=getTriangleArray(); - for (i=0;i )(id) <<" has not been recognized to be valid" << sendl; -#endif - return 0; - } - } else { - std::map::const_iterator itgi; - - itgi=locationToGlobalIndexMap.find(ControlPointLocation(triangleIndex,id)); - if (itgi!=locationToGlobalIndexMap.end()) { - return(itgi->second); - } else { -#ifndef NDEBUG - sout << "Error. [BezierTriangleSetTopologyContainer::getGlobalIndexOfBezierPoint] Cannot find global index of control point with TRBI "<< (sofa::defaulttype::Vec<3,int> )(id) <<" and triangle index " << triangleIndex < BezierTriangleSetTopologyContainer::getTriangleBezierIndexArray() const -{ - return (bezierIndexArray); -} -sofa::helper::vector BezierTriangleSetTopologyContainer::getTriangleBezierIndexArrayOfGivenDegree(const BezierDegreeType deg) const -{ - // vertex index - size_t i,j; - sofa::helper::vector tbiArray; - for (i=0;i<3;++i) { - TriangleBezierIndex bti(0,0,0); - bti[i]=deg; - tbiArray.push_back(bti); - } - // edge index - if (deg>1) { - for (i=0;i<3;++i) { - for (j=1;j2) { - size_t ind=0; - for (i=1;i<(BezierDegreeType)(deg-1);++i) { - for (j=1;j<(deg-i);++j,++ind) { - TriangleBezierIndex bti(0,0,0); - bti[0]=i;bti[1]=j; - bti[2]=deg-i-j; - tbiArray.push_back(bti); - } - } - } - - return(tbiArray); -} -sofa::helper::vector BezierTriangleSetTopologyContainer::getMapOfTriangleBezierIndexArrayFromInferiorDegree() const -{ - BezierDegreeType degree=d_degree.getValue(); - sofa::helper::vector tbiDerivArray=getTriangleBezierIndexArrayOfGivenDegree(degree-1); - sofa::helper::vector tbiLinearArray=getTriangleBezierIndexArrayOfGivenDegree(1); - TriangleBezierIndex tbi; - sofa::helper::vector correspondanceArray; -// correspondanceArray.resize(tbiDerivArray.size()); - size_t i,j; - for (i=0;i1) { - EdgesInTriangle eit=getEdgesInTriangle(triangleIndex); - for (i=0;i<3;++i) { - Edge e=getEdge(eit[i]); - offset=getNumberOfTriangularPoints()+eit[i]*(degree-1); - // check the order of the edge to be consistent with the Triangle - if (e[0]==tr[(i+1)%3] ) { - for (j=0;j<(size_t)(degree-1);++j) { - indexArray.push_back(offset+j); - } - } else { - int jj; - for (jj=degree-2;jj>=0;--jj) { - indexArray.push_back(offset+jj); - } - } - } - } - - - - // Triangle index - if (degree>2) { - size_t pointsPerTriangle=(degree-1)*(degree-2)/2; - offset=getNumberOfTriangularPoints()+getNumberOfEdges()*(degree-1)+triangleIndex*pointsPerTriangle; - size_t rank=0; - for (i=0;i<(size_t)(degree-2);++i) { - for (j=0;j<(degree-i-2);++j) { - indexArray.push_back(offset+rank); - rank++; - } - } - } - } else { - size_t i; - std::map::const_iterator itgi; - for (i=0;isecond); - } else { -#ifndef NDEBUG - sout << "Error. [BezierTriangleSetTopologyContainer::getGlobalIndexArrayOfBezierPointsInTriangle] Cannot find global index of control point with TRBI "<< (sofa::defaulttype::Vec<3,int> )(bezierIndexArray[i]) <<" and triangle index " << triangleIndex <::const_iterator itcpl; - itcpl=globalIndexToLocationMap.find(gi); - if (itcpl!=globalIndexToLocationMap.end()) { - // get the local index and triangle index of that control point - size_t offset=getLocalIndexFromTriangleBezierIndex(itcpl->second.second); - // if its local index is less than 3 then it is a triangle vertex - if (offset<3) { - location=POINT; - elementIndex=getTriangle(itcpl->second.first)[offset]; - elementOffset=0; - } else { - offset -= 3; - BezierDegreeType degree=d_degree.getValue(); - if ((BezierDegreeType)offset<3*(degree-1)){ - location=EDGE; - // get the id of the edge on which it lies - elementIndex=getEdgesInTriangle(itcpl->second.first)[offset/(degree-1)]; - elementOffset=offset%(degree-1); - } else { - offset -= 3*(degree-1); - location=TRIANGLE; - elementIndex=itcpl->second.first; - elementOffset=offset; - } - } - } else { - location=NONE; - elementIndex=0; - elementOffset=0; - } - } -} -sofa::helper::vector BezierTriangleSetTopologyContainer::getLocalIndexSubtriangleArray() const { - sofa::helper::vector subtriangleArray; - BezierDegreeType degree=d_degree.getValue(); - TriangleBezierIndex tbi1,tbi2,tbi3; - LocalTriangleIndex lti; - for (size_t i=1;i<=degree;++i) { - for (size_t j=0;j<(degree-i+1);++j) { - tbi1=TriangleBezierIndex(i,j,degree-i-j); - tbi2=TriangleBezierIndex(i-1,j+1,degree-i-j); - tbi3=TriangleBezierIndex(i-1,j,degree-i-j+1); - - lti[0]=getLocalIndexFromTriangleBezierIndex(tbi1); - lti[1]=getLocalIndexFromTriangleBezierIndex(tbi2); - lti[2]=getLocalIndexFromTriangleBezierIndex(tbi3); - subtriangleArray.push_back(lti); - if ((i+j) BezierTriangleSetTopologyContainer::getLocalIndexSubtriangleArrayOfGivenDegree(const BezierDegreeType deg) const { - - sofa::helper::vector tbia=getTriangleBezierIndexArrayOfGivenDegree(deg); - // create a local map for indexing - std::map tmpLocalIndexMap; - size_t i; - for (i=0;i subtriangleArray; - - TriangleBezierIndex tbi[3]; - size_t k; - LocalTriangleIndex lti; - std::map::iterator omi; - for ( i=1;i<=deg;++i) { - for (size_t j=0;j<(deg-i+1);++j) { - tbi[0]=TriangleBezierIndex(i,j,deg-i-j); - tbi[1]=TriangleBezierIndex(i-1,j+1,deg-i-j); - tbi[2]=TriangleBezierIndex(i-1,j,deg-i-j+1); - for (k=0;k<3;++k) { - omi=tmpLocalIndexMap.find(tbi[k]); - if (omi==tmpLocalIndexMap.end()) - { -#ifndef NDEBUG - sout << "Error. [BezierTriangleSetTopologyContainer::getLocalIndexSubtriangleArrayOfGivenDegree(const BezierDegreeType deg) ] Triangle Bezier Index "<< tbi[k] <<" is out of range." << sendl; -#endif - } else { - lti[k]= (*omi).second; - } - } - - subtriangleArray.push_back(lti); - if ((i+j) tbiArray=getTriangleBezierIndexArray(); - VecPointID indexArray; - BezierTrianglePointLocation location; - size_t elementIndex, elementOffset/*,localIndex*/; - for (nTrians=0;nTrians0) { - // check consistency between both maps - assert(locationToGlobalIndexMap.size()==globalIndexToLocationMap.size()); - std::map::iterator itcpl; - std::map::iterator itgi; - std::pair::iterator,std::map::iterator> itgir; - for (itcpl=locationToGlobalIndexMap.begin();itcpl!=locationToGlobalIndexMap.end();++itcpl) { - itgir=globalIndexToLocationMap.equal_range(itcpl->second); - assert(itgir.first!=itgir.second); - for (itgi=itgir.first;itgi->second!=itcpl->first && itgi!=itgir.second;++itgi); - assert(itgi->second==itcpl->first); - } - } - #endif - return( true); -} - -} // namespace topology - -} // namespace component - -} // namespace sofa diff --git a/modules/SofaGeneralTopology/BezierTriangleSetTopologyContainer.h b/modules/SofaGeneralTopology/BezierTriangleSetTopologyContainer.h deleted file mode 100644 index d5680f1af87..00000000000 --- a/modules/SofaGeneralTopology/BezierTriangleSetTopologyContainer.h +++ /dev/null @@ -1,188 +0,0 @@ -/****************************************************************************** -* SOFA, Simulation Open-Framework Architecture, development version * -* (c) 2006-2016 INRIA, USTL, UJF, CNRS, MGH * -* * -* This library 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 library 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 library; if not, write to the Free Software Foundation, * -* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * -******************************************************************************* -* SOFA :: Modules * -* * -* Authors: The SOFA Team and external contributors (see Authors.txt) * -* * -* Contact information: contact@sofa-framework.org * -******************************************************************************/ -#ifndef SOFA_COMPONENT_TOPOLOGY_BEZIERTRIANGLESETTOPOLOGYCONTAINER_H -#define SOFA_COMPONENT_TOPOLOGY_BEZIERTRIANGLESETTOPOLOGYCONTAINER_H - -#include "config.h" - -#include - -namespace sofa -{ - -namespace component -{ - -namespace topology -{ -class BezierTriangleSetTopologyModifier; - -//using core::topology::BaseMeshTopology; - - - -typedef unsigned char BezierDegreeType; -typedef sofa::defaulttype::Vec<3,BezierDegreeType> TriangleBezierIndex; - - -/** a class that stores a set of Bezier tetrahedra and provides access with adjacent triangles, edges and vertices -A Bezier Tetrahedron has exactly the same topology as a Tetrahedron but with additional (control) points on its edges, triangles and inside -We use a Vec4D to number the control points inside a Bezier tetrahedron */ -class SOFA_GENERAL_TOPOLOGY_API BezierTriangleSetTopologyContainer : public TriangleSetTopologyContainer -{ -public: - SOFA_CLASS(BezierTriangleSetTopologyContainer,TriangleSetTopologyContainer); - - typedef BaseMeshTopology::PointID PointID; - typedef BaseMeshTopology::EdgeID EdgeID; - typedef BaseMeshTopology::TriangleID TriangleID; - typedef BaseMeshTopology::Edge Edge; - typedef BaseMeshTopology::Triangle Triangle; - typedef BaseMeshTopology::SeqTriangles SeqTriangles; - typedef BaseMeshTopology::EdgesInTriangle EdgesInTriangle; - typedef BaseMeshTopology::TrianglesAroundVertex TrianglesAroundVertex; - typedef BaseMeshTopology::TrianglesAroundEdge TrianglesAroundEdge; - typedef sofa::helper::vector VecTriangleID; - typedef sofa::helper::vector VecPointID; - typedef sofa::defaulttype::Vec<2,BezierDegreeType> EdgeBezierIndex; - - typedef sofa::defaulttype::Vec<3,int> ElementTriangleIndex; - typedef sofa::defaulttype::Vec<3,size_t> LocalTriangleIndex; - typedef std::pair ControlPointLocation; - typedef sofa::helper::vector SeqWeights; - typedef sofa::helper::vector SeqBools; - - friend class BezierTriangleSetTopologyModifier; - friend class Mesh2BezierTopologicalMapping; - friend class BezierTetra2BezierTriangleTopologicalMapping; - - - -protected: - BezierTriangleSetTopologyContainer(); - - virtual ~BezierTriangleSetTopologyContainer() {} -public: - virtual void init(); - // build some maps specific of the degree of the tetrahedral elements. - virtual void reinit(); - - /// Bezier Specific Information Topology API - /// @{ -public : - /// the degree of the Bezier Tetrahedron 1=linear, 2=quadratic... - Data d_degree; - /// the number of control points corresponding to the vertices of the triangle mesh (different from the total number of points) - Data d_numberOfTriangularPoints; - /// whether the Bezier triangles are integral (false = classical Bezier splines) or rational splines (true) - Data d_isRationalSpline; - /// the array of weights for rational splines - Data d_weightArray; -public : - // specifies where a Bezier Point can lies with respect to the underlying tetrahedral mesh - enum BezierTrianglePointLocation - { - POINT = 0, - EDGE =1 , - TRIANGLE = 2, - NONE = 3 - }; - /// get the Degree of the Bezier Tetrahedron - BezierDegreeType getDegree() const; - /// get the number of control points corresponding to the vertices of the triangle mesh - size_t getNumberOfTriangularPoints() const; - /// get the global index of the Bezier point associated with a given tetrahedron index and given its 4D Index - size_t getGlobalIndexOfBezierPoint(const TriangleID tetrahedronIndex,const TriangleBezierIndex id) ; - /// get the indices of all control points associated with a given triangle - void getGlobalIndexArrayOfBezierPointsInTriangle(const TriangleID triangleIndex, VecPointID & indexArray) ; - /// return the Bezier index given the local index in a triangle - TriangleBezierIndex getTriangleBezierIndex(const size_t localIndex) const; - /// get the Triangle Bezier Index Array of degree d - sofa::helper::vector getTriangleBezierIndexArray() const; - /// get the Triangle Bezier Index Array of a given degree - sofa::helper::vector getTriangleBezierIndexArrayOfGivenDegree(const BezierDegreeType deg) const; - /** create an array which maps the local index of a Triangle Bezier Index of degree d-1 - into a local index of a TBI of degree d by adding respectively (1,0,0,0), (0,1,0,0), (0,0,1,0), (0,0,0,1) **/ - sofa::helper::vector getMapOfTriangleBezierIndexArrayFromInferiorDegree() const; - /** return the array describing each of the (degree+1)*(degree+1) subtriangles with local indices ( i.e. indices between 0 and (degree+1)*(degree+2)/2 ) */ - sofa::helper::vector getLocalIndexSubtriangleArray() const; - /** return the array describing each of the (deg+1)*(deg+1) subtriangles with local indices ( i.e. indices between 0 and (deg+1)*(deg+2)/2 ) */ - sofa::helper::vector getLocalIndexSubtriangleArrayOfGivenDegree(const BezierDegreeType deg) const; - /// return the local index in a tetrahedron from a tetrahedron Bezier index (inverse of getTetrahedronBezierIndex()) - size_t getLocalIndexFromTriangleBezierIndex(const TriangleBezierIndex id) const; - /// return the location, the element index and offset from the global index of a point - void getLocationFromGlobalIndex(const size_t globalIndex, BezierTrianglePointLocation &location, - size_t &elementIndex, size_t &elementOffset) ; - /// convert the edge offset into a EdgeBezierIndex - void getEdgeBezierIndexFromEdgeOffset(size_t offset, EdgeBezierIndex &ebi); - /// convert the triangle offset into a TriangleBezierIndex - void getTriangleBezierIndexFromTriangleOffset(size_t offset, TriangleBezierIndex &tbi); - /// check the Bezier Point Topology - bool checkBezierPointTopology(); - /// @} - /** \brief Returns the weight coordinate of the ith DOF. */ - virtual SReal getWeight(int i) const; - /// returns the array of weights - const SeqWeights & getWeightArray() const; - // if the Bezier triangle is rational or integral - bool isRationalSpline(int i) const; - -protected: - /** Map which provides the global index of a control point knowing its location (i.e. triangle index and its TriangleBezierIndex). - This is empty by default since there is a default layout of control points based on edge and triangles indices */ - std::map locationToGlobalIndexMap; - /** Map which provides the location (i.e. triangle index and its TriangleBezierIndex) of a control point knowing its global index. - Note that the location may not be unique. - This is empty by default since there is a default layout of control points based on edge and triangles indices */ - std::multimap globalIndexToLocationMap; - - - /// Map which provides the location (point, edge, Triangle) of a control point given its Triangle Bezier index - std::map elementMap; - /// Map which provides the offset in the DOF vector for a control point lying on an edge - std::map edgeOffsetMap; - /// Map which provides the offset in the DOF vector for a control point lying on a triangle - std::map triangleOffsetMap; - - /// Map which provides the rank in a control point from the array outputted by getGlobalIndexArrayOfBezierPointsInTriangle (consistent with bezierIndexArray) - std::map localIndexMap; - /// array of the Triangle Bezier index outputed by the function getGlobalIndexArrayOfBezierPointsInTriangle() - sofa::helper::vector bezierIndexArray; - /// array of the Triangle Bezier index outputed by the function getGlobalIndexArrayOfBezierPointsInTriangle() - sofa::helper::vector reducedDegreeBezierIndexArray; - /// convert triangle offset into triangle bezier index - sofa::helper::vector offsetToTriangleBezierIndexArray; - - - -}; - -} // namespace topology - -} // namespace component - -} // namespace sofa - -#endif diff --git a/modules/SofaGeneralTopology/CMakeLists.txt b/modules/SofaGeneralTopology/CMakeLists.txt index f92aed53bbe..c216a828f0c 100644 --- a/modules/SofaGeneralTopology/CMakeLists.txt +++ b/modules/SofaGeneralTopology/CMakeLists.txt @@ -3,12 +3,6 @@ project(SofaGeneralTopology) set(HEADER_FILES - BezierTetrahedronSetGeometryAlgorithms.h - BezierTetrahedronSetGeometryAlgorithms.inl - BezierTetrahedronSetTopologyContainer.h - BezierTriangleSetGeometryAlgorithms.h - BezierTriangleSetGeometryAlgorithms.inl - BezierTriangleSetTopologyContainer.h CubeTopology.h CylinderGridTopology.h SphereQuadTopology.h @@ -17,10 +11,6 @@ set(HEADER_FILES ) set(SOURCE_FILES - BezierTetrahedronSetGeometryAlgorithms.cpp - BezierTetrahedronSetTopologyContainer.cpp - BezierTriangleSetGeometryAlgorithms.cpp - BezierTriangleSetTopologyContainer.cpp CubeTopology.cpp CylinderGridTopology.cpp SphereQuadTopology.cpp diff --git a/modules/SofaGeneralTopology/initGeneralTopology.cpp b/modules/SofaGeneralTopology/initGeneralTopology.cpp index 92e18dde408..5df4636c4e4 100644 --- a/modules/SofaGeneralTopology/initGeneralTopology.cpp +++ b/modules/SofaGeneralTopology/initGeneralTopology.cpp @@ -45,7 +45,6 @@ void initGeneralTopology() SOFA_LINK_CLASS(CubeTopology) SOFA_LINK_CLASS(SphereQuadTopology) SOFA_LINK_CLASS(CylinderGridTopology) -SOFA_LINK_CLASS(BezierTetrahedronSetGeometryAlgorithms) } // namespace component diff --git a/modules/SofaMiscForceField/MeshMatrixMass.h b/modules/SofaMiscForceField/MeshMatrixMass.h index d9994098108..f1690fdcb74 100644 --- a/modules/SofaMiscForceField/MeshMatrixMass.h +++ b/modules/SofaMiscForceField/MeshMatrixMass.h @@ -98,8 +98,7 @@ class MeshMatrixMass : public core::behavior::Mass TOPOLOGY_TRIANGLESET=2, TOPOLOGY_TETRAHEDRONSET=3, TOPOLOGY_QUADSET=4, - TOPOLOGY_HEXAHEDRONSET=5, - TOPOLOGY_BEZIERTETRAHEDRONSET=6, + TOPOLOGY_HEXAHEDRONSET=5 } TopologyType; /// the way the mass should be computed on non-linear elements typedef enum @@ -114,14 +113,7 @@ class MeshMatrixMass : public core::behavior::Mass topology::PointData > vertexMassInfo; topology::EdgeData > edgeMassInfo; - /* ---------- Specific data for Bezier Elements ------*/ - /// use this data structure to store mass for Bezier tetrahedra. - //// The size of the vector is nbControlPoints*(nbControlPoints+1)/2 where nbControlPoints=(degree+1)*(degree+2)*(degree+3)/2 - topology::TetrahedronData > tetrahedronMassInfo; - // array of Tetrahedral Bezier indices - //sofa::helper::vector tbiArray; - /* ---------- end ------*/ - + /// the mass density used to compute the mass from a mesh topology and geometry Data< Real > m_massDensity; @@ -133,14 +125,7 @@ class MeshMatrixMass : public core::behavior::Mass /// if specific mass information should be outputed Data< bool > printMass; Data > > f_graph; - /// the order of integration for numerical integration - Data numericalIntegrationOrder; - /// the type of numerical integration method chosen - Data numericalIntegrationMethod; - /// the type of integration method chosen for non linear element. - Data d_integrationMethod; - IntegrationMethod integrationMethod; - + protected: @@ -166,7 +151,6 @@ class MeshMatrixMass : public core::behavior::Mass sofa::component::topology::QuadSetGeometryAlgorithms* quadGeo; sofa::component::topology::TetrahedronSetGeometryAlgorithms* tetraGeo; sofa::component::topology::HexahedronSetGeometryAlgorithms* hexaGeo; - sofa::component::topology::BezierTetrahedronSetGeometryAlgorithms* bezierTetraGeo; virtual void clear(); @@ -227,8 +211,7 @@ class MeshMatrixMass : public core::behavior::Mass /// Answer wether mass matrix is lumped or not bool isLumped() { return lumping.getValue(); } - // returns the mass vector for a given index of a Bezier tetrahedron - virtual const MassVector &getBezierTetrahedronMassVector(const size_t i) const; + protected: @@ -407,27 +390,6 @@ class MeshMatrixMass : public core::behavior::Mass EdgeMassHandler* edgeMassHandler; - class TetrahedronMassHandler : public topology::TopologyDataHandler - { - public: - typedef typename DataTypes::Real Real; - TetrahedronMassHandler(MeshMatrixMass* _m, topology::TetrahedronData >* _data) : topology::TopologyDataHandler >(_data), m(_m) {} - - /// Edge mass coefficient matrix creation function - void applyCreateFunction(unsigned int tetrahedronIndex, MassVector & tetrahedronMass, - const core::topology::BaseMeshTopology::Tetrahedron&, - const sofa::helper::vector< unsigned int > &, - const sofa::helper::vector< double >&); - - /// Edge coefficient of mass matrix destruction function to handle creation of new tetrahedra -// void applyDestructionFunction(const sofa::helper::vector & /*indices*/); - - protected: - MeshMatrixMass* m; - }; - - TetrahedronMassHandler* tetrahedronMassHandler; - }; #if defined(SOFA_EXTERN_TEMPLATE) && !defined(SOFA_COMPONENT_MASS_MESHMATRIXMASS_CPP) diff --git a/modules/SofaMiscForceField/MeshMatrixMass.inl b/modules/SofaMiscForceField/MeshMatrixMass.inl index c266d9ed802..d658af8cd18 100644 --- a/modules/SofaMiscForceField/MeshMatrixMass.inl +++ b/modules/SofaMiscForceField/MeshMatrixMass.inl @@ -36,7 +36,6 @@ #include #include #include -#include #include #include #include @@ -60,20 +59,15 @@ template MeshMatrixMass::MeshMatrixMass() : vertexMassInfo( initData(&vertexMassInfo, "vertexMass", "values of the particles masses on vertices") ) , edgeMassInfo( initData(&edgeMassInfo, "edgeMass", "values of the particles masses on edges") ) - , tetrahedronMassInfo( initData(&tetrahedronMassInfo, "tetrahedronMass", "values of the particles masses for all control points inside a Bezier tetrahedron") ) - , m_massDensity( initData(&m_massDensity, (Real)1.0,"massDensity", "mass density that allows to compute the particles masses from a mesh topology and geometry.\nOnly used if > 0") ) + , m_massDensity( initData(&m_massDensity, (Real)1.0,"massDensity", "mass density that allows to compute the particles masses from a mesh topology and geometry.\nOnly used if > 0") ) , showCenterOfGravity( initData(&showCenterOfGravity, false, "showGravityCenter", "display the center of gravity of the system" ) ) , showAxisSize( initData(&showAxisSize, (Real)1.0, "showAxisSizeFactor", "factor length of the axis displayed (only used for rigids)" ) ) , lumping( initData(&lumping, true, "lumping","boolean if you need to use a lumped mass matrix") ) , printMass( initData(&printMass, false, "printMass","boolean if you want to get the totalMass") ) , f_graph( initData(&f_graph,"graph","Graph of the controlled potential") ) - , numericalIntegrationOrder( initData(&numericalIntegrationOrder,(size_t)2,"integrationOrder","The order of integration for numerical integration")) - , numericalIntegrationMethod( initData(&numericalIntegrationMethod,(size_t)0,"numericalIntegrationMethod","The type of numerical integration method chosen")) - , d_integrationMethod( initData(&d_integrationMethod,std::string("analytical"),"integrationMethod","\"exact\" if closed form expression for high order elements, \"analytical\" if closed form expression for affine element, \"numerical\" if numerical integration is chosen")) , topologyType(TOPOLOGY_UNKNOWN) , vertexMassHandler(NULL) , edgeMassHandler(NULL) - , tetrahedronMassHandler(NULL) { f_graph.setWidget("graph"); } @@ -83,7 +77,6 @@ MeshMatrixMass::~MeshMatrixMass() { if (vertexMassHandler) delete vertexMassHandler; if (edgeMassHandler) delete edgeMassHandler; - if (tetrahedronMassHandler) delete tetrahedronMassHandler; } template< class DataTypes, class MassType> @@ -102,178 +95,7 @@ void MeshMatrixMass::EdgeMassHandler::applyCreateFunction(u { EdgeMass = 0; } -template< class DataTypes, class MassType> -void MeshMatrixMass::TetrahedronMassHandler::applyCreateFunction(unsigned int tetra, MassVector & TetrahedronMass, - const core::topology::BaseMeshTopology::Tetrahedron&, - const sofa::helper::vector< unsigned int > &, - const sofa::helper::vector< double >&) -{ - MeshMatrixMass *MMM = this->m; - if (MMM && (MMM->bezierTetraGeo) && (MMM->getMassTopologyType()==MeshMatrixMass::TOPOLOGY_BEZIERTETRAHEDRONSET)) - { - Real densityM = MMM->getMassDensity(); - topology::BezierDegreeType degree=MMM->bezierTetraGeo->getTopologyContainer()->getDegree(); - size_t nbControlPoints=(degree+1)*(degree+2)*(degree+3)/6; - size_t nbMassEntries=nbControlPoints*(nbControlPoints+1)/2; - - if (TetrahedronMass.size()!=nbMassEntries) { - TetrahedronMass.resize(nbMassEntries); - } - // set array to zero - std::fill(TetrahedronMass.begin(),TetrahedronMass.end(),(MassType)0); - sofa::helper::vector lumpedVertexMass; - lumpedVertexMass.resize(nbControlPoints); - size_t i,j,k,rank; - typedef typename topology::BezierTetrahedronSetGeometryAlgorithms::VecPointID VecPointID; - /// get the global index of each control point in the tetrahedron - const VecPointID &indexArray=MMM->bezierTetraGeo->getTopologyContainer()->getGlobalIndexArrayOfBezierPoints(tetra); - std::fill(lumpedVertexMass.begin(),lumpedVertexMass.end(),(MassType)0); - if (MMM->integrationMethod==MeshMatrixMass::NUMERICAL_INTEGRATION) { - sofa::helper::vector shapeFunctionValue; - shapeFunctionValue.resize(nbControlPoints); - // set array to zero - - /// get value of integration points - topology::NumericalIntegrationDescriptor &nid=MMM->bezierTetraGeo->getTetrahedronNumericalIntegrationDescriptor(); - typename topology::NumericalIntegrationDescriptor::QuadraturePointArray qpa=nid.getQuadratureMethod((typename topology::NumericalIntegrationDescriptor::QuadratureMethod)MMM->numericalIntegrationMethod.getValue(), - MMM->numericalIntegrationOrder.getValue()); - - sofa::defaulttype::Vec<4,Real> bc; - sofa::helper::vector tbi=MMM->bezierTetraGeo->getTopologyContainer()->getTetrahedronBezierIndexArray(); - typename DataTypes::Real jac,weight; - MassType tmpMass; - - // loop through the integration points - for (i=0;i::QuadraturePoint qp=qpa[i]; - // the barycentric coordinate - bc=qp.first; - // the weight of the integration point - weight=qp.second; - // the Jacobian Derterminant of the integration point - jac=MMM->bezierTetraGeo->computeJacobian(tetra,bc)*densityM; - /// prestore the shape function value for that integration point. - for (j=0;jbezierTetraGeo->computeBernsteinPolynomial(tbi[j],bc); - } - // now loop through each pair of control point to compute the mass - rank=0; - for (j=0;jgetContext()->getMeshTopology(); savedMass = m_massDensity.getValue(); @@ -1035,7 +846,6 @@ void MeshMatrixMass::init() this->getContext()->get(quadGeo); this->getContext()->get(tetraGeo); this->getContext()->get(hexaGeo); - this->getContext()->get(bezierTetraGeo); // add the functions to handle topology changes for Vertex informations vertexMassHandler = new VertexMassHandler(this, &vertexMassInfo); @@ -1056,13 +866,6 @@ void MeshMatrixMass::init() edgeMassInfo.linkToHexahedronDataArray(); edgeMassInfo.registerTopologicalData(); - if (bezierTetraGeo) { - // for Bezier Tetrahedra add the functions to handle topology changes for Tetrahedron informations - tetrahedronMassHandler = new TetrahedronMassHandler(this, &tetrahedronMassInfo); - tetrahedronMassInfo.createTopologicalEngine(_topology, tetrahedronMassHandler); - tetrahedronMassInfo.linkToTetrahedronDataArray(); - - } if ((vertexMassInfo.getValue().size()==0 || edgeMassInfo.getValue().size()==0) && (_topology!=0)) reinit(); @@ -1122,48 +925,7 @@ void MeshMatrixMass::reinit() } - else if (_topology->getNbTetrahedra()>0 && bezierTetraGeo) // Bezier Tetrahedron topology - { - helper::vector& my_tetrahedronMassInfo = *tetrahedronMassInfo.beginEdit(); - - - size_t nbTetrahedra=_topology->getNbTetrahedra(); - const helper::vector& tetrahedra = _topology->getTetrahedra(); - - my_tetrahedronMassInfo.resize(nbTetrahedra); - setMassTopologyType(TOPOLOGY_BEZIERTETRAHEDRONSET); - // set vertex tensor to 0 - for (unsigned int i = 0; iapplyCreateFunction(i, my_tetrahedronMassInfo[i], tetrahedra[i],emptyAncestor, emptyCoefficient); - - // create vector tensor by calling the tetrahedron creation function on the entire mesh - sofa::helper::vector tetrahedraAdded; - - - size_t n = _topology->getNbTetrahedra(); - for (size_t i = 0; iapplyTetrahedronCreation(tetrahedraAdded, _topology->getTetrahedra(), _topology->getTetrahedron(i),emptyAncestors, emptyCoefficients); - massLumpingCoeff = 1.0; - - tetrahedronMassInfo.registerTopologicalData(); - tetrahedronMassInfo.endEdit(); - } - else if (_topology->getNbTetrahedra()>0 && tetraGeo) // Tetrahedron topology - { - // create vector tensor by calling the tetrahedron creation function on the entire mesh - sofa::helper::vector tetrahedraAdded; - setMassTopologyType(TOPOLOGY_TETRAHEDRONSET); - - int n = _topology->getNbTetrahedra(); - for (int i = 0; iapplyTetrahedronCreation(tetrahedraAdded, _topology->getTetrahedra(), emptyAncestors, emptyCoefficients); - edgeMassHandler->applyTetrahedronCreation(tetrahedraAdded, _topology->getTetrahedra(), emptyAncestors, emptyCoefficients); - massLumpingCoeff = 2.5; - } + else if (_topology->getNbQuads()>0 && quadGeo) // Quad topology { // create vector tensor by calling the quad creation function on the entire mesh @@ -1211,13 +973,11 @@ void MeshMatrixMass::clear() { MassVector& vertexMass = *vertexMassInfo.beginEdit(); MassVector& edgeMass = *edgeMassInfo.beginEdit(); - MassVectorVector& tetrahedronMass = *tetrahedronMassInfo.beginEdit(); vertexMass.clear(); edgeMass.clear(); - tetrahedronMass.clear(); vertexMassInfo.endEdit(); edgeMassInfo.endEdit(); - tetrahedronMassInfo.endEdit(); + } @@ -1244,75 +1004,6 @@ void MeshMatrixMass::addMDx(const core::MechanicalParams*, } - - //using a sparse matrix--------------- - else if (getMassTopologyType()!=TOPOLOGY_BEZIERTETRAHEDRONSET) - { - size_t nbEdges=_topology->getNbEdges(); - size_t v0,v1; - - for (unsigned int i=0; igetEdge(j)[0]; - v1=_topology->getEdge(j)[1]; - - res[v0] += dx[v1] * tempMass; - res[v1] += dx[v0] * tempMass; - - massTotal += 2*edgeMass[j] * (Real)factor; - } - } else if (bezierTetraGeo ){ - typedef typename topology::BezierTetrahedronSetGeometryAlgorithms::VecPointID VecPointID; - topology::BezierDegreeType degree=bezierTetraGeo->getTopologyContainer()->getDegree(); - size_t nbControlPoints=(degree+1)*(degree+2)*(degree+3)/6; - size_t nbTetras=_topology->getNbTetrahedra(); -#ifdef NDEBUG - assert(tetrahedronMassInfo.size()==(nbControlPoints*(nbControlPoints+1)/2)); -#endif - // go through the mass stored in each tetrahedron element - size_t rank=0; - MassType tempMass; - size_t v0,v1; - // loop over each tetrahedron of size nbControlPoints*nbControlPoints - for (size_t i=0; igetTopologyContainer()->getGlobalIndexArrayOfBezierPoints(i) ; - // get the mass matrix in the tetrahedron -// const MassVector &mv=tetrahedronMassInfo.getValue()[i]; - const MassVector &mv=getBezierTetrahedronMassVector(i); - nbControlPoints=indexArray.size(); - assert(mv.size()==nbControlPoints*(nbControlPoints+1)/2); - // loop over each entry in the mass matrix of size nbControlPoints*(nbControlPoints+1)/2 - rank=0; - for (size_t j=0; jj) { - res[v0] += dx[v1] * tempMass; - res[v1] += dx[v0] * tempMass; - massTotal += 2*tempMass; - } else { - res[v0] += dx[v0] * tempMass; - massTotal += tempMass; - } - } - } - } - } if(printMass.getValue() && (this->getContext()->getTime()==0.0)) sout<<"Total Mass = "<::getKineticEnergy( const core::Mechani { e += dot(v[i],v[i]) * vertexMass[i]; // v[i]*v[i]*masses[i] would be more efficient but less generic } - if (getMassTopologyType()!=TOPOLOGY_BEZIERTETRAHEDRONSET) { - for (unsigned int i=0; igetEdge(i)[0]; - v1=_topology->getEdge(i)[1]; - - e += 2*dot(v[v0],v[v1])*edgeMass[i]; - - } - } else if (bezierTetraGeo ){ -// topology::BezierDegreeType degree=bezierTetraGeo->getTopologyContainer()->getDegree(); -// size_t nbControlPoints=(degree+1)*(degree+2)*(degree+3)/6; - size_t nbControlPoints; - typedef typename topology::BezierTetrahedronSetGeometryAlgorithms::VecPointID VecPointID; - size_t nbTetras=_topology->getNbTetrahedra(); -#ifdef NDEBUG - assert(tetrahedronMassInfo.size()==(nbControlPoints*(nbControlPoints+1)/2)); -#endif - // go through the mass stored in each tetrahedron element - size_t rank=0; - // loop over each tetrahedron of size nbControlPoints*nbControlPoints - for (size_t i=0; igetTopologyContainer()->getGlobalIndexArrayOfBezierPoints(i) ; - nbControlPoints=indexArray.size(); - // get the mass matrix in the tetrahedron -// const MassVector &mv=tetrahedronMassInfo.getValue()[i]; - const MassVector &mv=getBezierTetrahedronMassVector(i); - // MassVector mv; - // loop over each entry in the mass matrix of size nbControlPoints*(nbControlPoints+1)/2 - for (size_t j=0; jj) { - e += 2*dot(v[v0],v[v1])*mv[rank]; - } else - e += dot(v[v0],v[v1])*mv[rank]; - } - } - } - } return e/2; } -template - const typename MeshMatrixMass::MassVector & - MeshMatrixMass::getBezierTetrahedronMassVector(const size_t i) const { - return tetrahedronMassInfo.getValue()[i]; - } template SReal MeshMatrixMass::getPotentialEnergy( const core::MechanicalParams*, const DataVecCoord& vx) const @@ -1584,59 +1226,25 @@ void MeshMatrixMass::addMToMatrix(const core::MechanicalPar else { - if (getMassTopologyType()!=TOPOLOGY_BEZIERTETRAHEDRONSET) { - for (size_t i=0; igetEdge(j)[0]; - v1=_topology->getEdge(j)[1]; - - calc(r.matrix, edgeMass[j], r.offset + N*v0, r.offset + N*v1, mFactor); - calc(r.matrix, edgeMass[j], r.offset + N*v1, r.offset + N*v0, mFactor); - - massTotal += 2*edgeMass[j]; - } - } else if (bezierTetraGeo ){ -// topology::BezierDegreeType degree=bezierTetraGeo->getTopologyContainer()->getDegree(); -// size_t nbControlPoints=(degree+1)*(degree+2)*(degree+3)/6; - size_t nbControlPoints; - typedef typename topology::BezierTetrahedronSetGeometryAlgorithms::VecPointID VecPointID; - size_t nbTetras=_topology->getNbTetrahedra(); -#ifdef NDEBUG - assert(tetrahedronMassInfo.size()==(nbControlPoints*(nbControlPoints+1)/2)); -#endif - // go through the mass stored in each tetrahedron element - size_t rank=0; - // loop over each tetrahedron of size nbControlPoints*nbControlPoints - for (size_t i=0; igetTopologyContainer()->getGlobalIndexArrayOfBezierPoints(i) ; - nbControlPoints=indexArray.size(); - // get the mass matrix in the tetrahedron -// MassVector &mv=tetrahedronMassInfo[i]; - const MassVector &mv=getBezierTetrahedronMassVector(i); - // loop over each entry in the mass matrix of size nbControlPoints*(nbControlPoints+1)/2 - for (size_t j=0; jj) { - calc(r.matrix, mv[rank], r.offset + N*v1, r.offset + N*v0, mFactor); - massTotal += 2*mv[rank]; - } else - massTotal += mv[rank]; - } - } - } + + for (size_t i=0; igetEdge(j)[0]; + v1=_topology->getEdge(j)[1]; + + calc(r.matrix, edgeMass[j], r.offset + N*v0, r.offset + N*v1, mFactor); + calc(r.matrix, edgeMass[j], r.offset + N*v1, r.offset + N*v0, mFactor); + + massTotal += 2*edgeMass[j]; + } + if(printMass.getValue() && (this->getContext()->getTime()==0.0)) std::cout<<"Total Mass = "< - -namespace sofa -{ - -namespace component -{ - -namespace mapping -{ - -using namespace sofa::defaulttype; - - -SOFA_DECL_CLASS(Bezier2MeshMechanicalMapping) - -int Bezier2MeshMechanicalMappingClass = core::RegisterObject("Mechanical mapping between a Bezier triangle or Bezier tetrahedra with a tesselated triangle mesh or tesselated tetrahedron mesh") -#ifndef SOFA_FLOAT - .add< Bezier2MeshMechanicalMapping< Vec3dTypes, Vec3dTypes > >() - .add< Bezier2MeshMechanicalMapping< Vec3dTypes, ExtVec3dTypes > >() -#endif -#ifndef SOFA_DOUBLE - .add< Bezier2MeshMechanicalMapping< Vec3fTypes, Vec3fTypes > >() - .add< Bezier2MeshMechanicalMapping< Vec3fTypes, ExtVec3fTypes > >() -#endif - -#ifndef SOFA_FLOAT -#ifndef SOFA_DOUBLE - .add< Bezier2MeshMechanicalMapping< Vec3fTypes, Vec3dTypes > >() - .add< Bezier2MeshMechanicalMapping< Vec3dTypes, Vec3fTypes > >() - .add< Bezier2MeshMechanicalMapping< Vec3dTypes, ExtVec3fTypes > >() - .add< Bezier2MeshMechanicalMapping< Vec3fTypes, ExtVec3dTypes > >() -#endif -#endif -//.addAlias("SimpleTesselatedTetraMechanicalMapping") - ; - - -#ifndef SOFA_FLOAT -template class SOFA_TOPOLOGY_MAPPING_API Bezier2MeshMechanicalMapping< Vec3dTypes, Vec3dTypes >; -template class SOFA_TOPOLOGY_MAPPING_API Bezier2MeshMechanicalMapping< Vec3dTypes, ExtVec3dTypes >; -#endif -#ifndef SOFA_DOUBLE -template class SOFA_TOPOLOGY_MAPPING_API Bezier2MeshMechanicalMapping< Vec3fTypes, Vec3fTypes >; -template class SOFA_TOPOLOGY_MAPPING_API Bezier2MeshMechanicalMapping< Vec3fTypes, ExtVec3fTypes >; -#endif - -#ifndef SOFA_FLOAT -#ifndef SOFA_DOUBLE -template class SOFA_TOPOLOGY_MAPPING_API Bezier2MeshMechanicalMapping< Vec3dTypes, Vec3fTypes >; -template class SOFA_TOPOLOGY_MAPPING_API Bezier2MeshMechanicalMapping< Vec3fTypes, Vec3dTypes >; -template class SOFA_TOPOLOGY_MAPPING_API Bezier2MeshMechanicalMapping< Vec3fTypes, ExtVec3dTypes >; -template class SOFA_TOPOLOGY_MAPPING_API Bezier2MeshMechanicalMapping< Vec3dTypes, ExtVec3fTypes >; -#endif -#endif - -} // namespace mapping - -} // namespace component - -} // namespace sofa diff --git a/modules/SofaTopologyMapping/Bezier2MeshMechanicalMapping.h b/modules/SofaTopologyMapping/Bezier2MeshMechanicalMapping.h deleted file mode 100644 index 1256fef42e5..00000000000 --- a/modules/SofaTopologyMapping/Bezier2MeshMechanicalMapping.h +++ /dev/null @@ -1,137 +0,0 @@ -/****************************************************************************** -* SOFA, Simulation Open-Framework Architecture, development version * -* (c) 2006-2016 INRIA, USTL, UJF, CNRS, MGH * -* * -* This library 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 library 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 library; if not, write to the Free Software Foundation, * -* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * -******************************************************************************* -* SOFA :: Modules * -* * -* Authors: The SOFA Team and external contributors (see Authors.txt) * -* * -* Contact information: contact@sofa-framework.org * -******************************************************************************/ -#ifndef SOFA_COMPONENT_MAPPING_BEZIER2MESHMECHANICALMAPPING_H -#define SOFA_COMPONENT_MAPPING_BEZIER2MESHMECHANICALMAPPING_H - -#include - -#include - -namespace sofa { namespace core { namespace topology { class BaseMeshTopology; } } } -namespace sofa { namespace component { namespace topology { class Bezier2MeshTopologicalMapping; } } } -namespace sofa { namespace component { namespace topology { template class BezierTriangleSetGeometryAlgorithms; } } } -namespace sofa { namespace component { namespace topology { class BezierTriangleSetTopologyContainer; } } } -namespace sofa -{ - -namespace component -{ - -namespace mapping -{ - -template -class Bezier2MeshMechanicalMapping : public core::Mapping -{ -public: - SOFA_CLASS(SOFA_TEMPLATE2(Bezier2MeshMechanicalMapping,TIn,TOut), SOFA_TEMPLATE2(core::Mapping,TIn,TOut)); - - typedef core::Mapping Inherit; - typedef TIn In; - typedef TOut Out; - - typedef typename Out::VecCoord OutVecCoord; - typedef typename Out::VecDeriv OutVecDeriv; - typedef typename Out::Coord OutCoord; - typedef typename Out::Deriv OutDeriv; - typedef typename Out::MatrixDeriv OutMatrixDeriv; - - typedef typename In::VecCoord InVecCoord; - typedef typename In::VecDeriv InVecDeriv; - typedef typename In::Coord InCoord; - typedef typename In::Deriv InDeriv; - typedef typename In::MatrixDeriv InMatrixDeriv; - typedef typename InCoord::value_type Real; -protected: - Bezier2MeshMechanicalMapping(core::State* from = NULL, core::State* to = NULL); - - virtual ~Bezier2MeshMechanicalMapping(); - -public: - - void init(); - - void apply(const core::MechanicalParams *mparams, Data& out, const Data& in); - - void applyJ(const core::MechanicalParams *mparams, Data& out, const Data& in); - - void applyJT(const core::MechanicalParams *mparams, Data& out, const Data& in); - - void applyJT(const core::ConstraintParams *cparams, Data& out, const Data& in); - -protected: - // the associated topological map - topology::Bezier2MeshTopologicalMapping* topoMap; - // the input bezier triangle geometry algorithm object - topology::BezierTriangleSetGeometryAlgorithms *btsga; - // the input bezier triangle geometry algorithm object - topology::BezierTriangleSetTopologyContainer *btstc; - // currently used bezier degree for the input Bezier triangulation or tetrahedral mesh - size_t bezierDegree; - // currently used tesselation degree for the output riangulation or tetrahedral mesh - size_t tesselationDegree; - - /// precomputed coefficients to interpolate the positions of points. - sofa::helper::vector< sofa::helper::vector > precomputedLinearBernsteinCoefficientArray; - sofa::helper::vector< sofa::helper::vector > precomputedTriangularBernsteinCoefficientArray; - sofa::helper::vector< sofa::helper::vector > precomputedDerivUTriangularBernsteinCoefficientArray; - sofa::helper::vector< sofa::helper::vector > precomputedDerivVTriangularBernsteinCoefficientArray; - /// precompute weight array for tesselated mesh - sofa::helper::vector< Real > bezierTesselationWeightArray; - // local indexing of points inside tessellated triangles - sofa::helper::vector > tesselatedTriangleIndices; - - -}; - - - -#if defined(SOFA_EXTERN_TEMPLATE) && !defined(SOFA_COMPONENT_MAPPING_BEZIER2MESHMECHANICALMAPPING_CPP) //// ATTENTION PB COMPIL WIN3Z -#ifndef SOFA_FLOAT -extern template class SOFA_TOPOLOGY_MAPPING_API Bezier2MeshMechanicalMapping< defaulttype::Vec3dTypes, defaulttype::Vec3dTypes >; -extern template class SOFA_TOPOLOGY_MAPPING_API Bezier2MeshMechanicalMapping< defaulttype::Vec3dTypes, defaulttype::ExtVec3dTypes >; -#endif -#ifndef SOFA_DOUBLE -extern template class SOFA_TOPOLOGY_MAPPING_API Bezier2MeshMechanicalMapping< defaulttype::Vec3fTypes, defaulttype::Vec3fTypes >; -extern template class SOFA_TOPOLOGY_MAPPING_API Bezier2MeshMechanicalMapping< defaulttype::Vec3fTypes, defaulttype::ExtVec3fTypes >; -#endif - -#ifndef SOFA_FLOAT -#ifndef SOFA_DOUBLE -extern template class SOFA_TOPOLOGY_MAPPING_API Bezier2MeshMechanicalMapping< defaulttype::Vec3dTypes, defaulttype::Vec3fTypes >; -extern template class SOFA_TOPOLOGY_MAPPING_API Bezier2MeshMechanicalMapping< defaulttype::Vec3fTypes, defaulttype::Vec3dTypes >; -extern template class SOFA_TOPOLOGY_MAPPING_API Bezier2MeshMechanicalMapping< defaulttype::Vec3fTypes, defaulttype::ExtVec3dTypes >; -extern template class SOFA_TOPOLOGY_MAPPING_API Bezier2MeshMechanicalMapping< defaulttype::Vec3dTypes, defaulttype::ExtVec3fTypes >; -#endif -#endif -#endif - -} // namespace mapping - -} // namespace component - -} // namespace sofa - -#endif diff --git a/modules/SofaTopologyMapping/Bezier2MeshMechanicalMapping.inl b/modules/SofaTopologyMapping/Bezier2MeshMechanicalMapping.inl deleted file mode 100644 index 81f3a596686..00000000000 --- a/modules/SofaTopologyMapping/Bezier2MeshMechanicalMapping.inl +++ /dev/null @@ -1,726 +0,0 @@ -/****************************************************************************** -* SOFA, Simulation Open-Framework Architecture, development version * -* (c) 2006-2016 INRIA, USTL, UJF, CNRS, MGH * -* * -* This library 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 library 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 library; if not, write to the Free Software Foundation, * -* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * -******************************************************************************* -* SOFA :: Modules * -* * -* Authors: The SOFA Team and external contributors (see Authors.txt) * -* * -* Contact information: contact@sofa-framework.org * -******************************************************************************/ -#ifndef SOFA_COMPONENT_MAPPING_BEZIER2MESHMECHANICALMAPPING_INL -#define SOFA_COMPONENT_MAPPING_BEZIER2MESHMECHANICALMAPPING_INL - -#include "Bezier2MeshMechanicalMapping.h" - -#include -#include -#include -#include - -namespace sofa -{ - -namespace component -{ - -namespace mapping -{ - - -template -Bezier2MeshMechanicalMapping::Bezier2MeshMechanicalMapping(core::State* from, core::State* to) - : Inherit(from, to) - , topoMap(NULL) - , bezierDegree(0) - , tesselationDegree(0) -{ -} - -template -Bezier2MeshMechanicalMapping::~Bezier2MeshMechanicalMapping() -{ -} - -double multinomial(const size_t n,const sofa::component::topology::TriangleBezierIndex tbiIn) -{ - size_t i,ival; - sofa::component::topology::TriangleBezierIndex tbi=tbiIn; - // divide n! with the largest of the multinomial coefficient - std::sort(tbi.begin(),tbi.end()); - ival=1; - for (i=n;i>tbi[2];--i){ - ival*=i; - } - return(((double)ival)/(sofa::helper::factorial(tbi[0])*sofa::helper::factorial(tbi[1]))); -} -template -void Bezier2MeshMechanicalMapping::init() -{ - - this->getContext()->get(topoMap); - if (!topoMap) { - serr << "Could not find any Bezier2MeshTopologicalMapping object"<fromModel->getContext()->get(btstc); - if (!btstc){ - topoMap->fromModel->getContext()->get(btstc); - if (!btstc){ - serr << "Could not find any BezierTriangleSetTopologyContainer object"<fromModel->getContext()->get(btsga); - if (!btsga){ - topoMap->fromModel->getContext()->get(btsga); - if (!btsga){ - serr << "Could not find any BezierTriangleSetGeometryAlgorithms object"<getDegree(); - tesselationDegree=topoMap->d_tesselationTriangleDegree.getValue(); - size_t bezierTesselation=tesselationDegree; - size_t i; - // resize bezierTesselationWeightArray - bezierTesselationWeightArray.resize(topoMap->nbPoints); - this->toModel->resize(topoMap->nbPoints); - - if (precomputedLinearBernsteinCoefficientArray.size()!=(bezierTesselation-1)) { - // (re)compute the interpolation factor associated with a given tesselation level and bezier order - precomputedLinearBernsteinCoefficientArray.resize(bezierTesselation-1); - Real u,v; - size_t j; - for (i=1;i weightArray(bezierDegree+1); - // linear barycentric coordinates of the point - u=(Real)i/(Real)bezierTesselation; - v=(Real)(1.0f-u); - for(j=0;j<=bezierDegree;++j){ - weightArray[j]=(Real)(pow(u,(int)j)*pow(v,(int)(bezierDegree-j))*sofa::component::topology::binomial(bezierDegree-j,j)); - } - precomputedLinearBernsteinCoefficientArray[i-1]=weightArray; - } - - } - - if (precomputedTriangularBernsteinCoefficientArray.size()!= ((bezierTesselation-1)*(bezierTesselation-2)/2)) { - // for each point inside the tesselated triangle, store the weights of each control points (bivariate Bernstein polynomials) - // there are (bezierTesselation-1)*(bezierTesselation-2)/2 points inside each triangle and (bezierDegree+1)*(bezierDegree+2)/2 control points - // (re)compute the interpolation factor associated with a given tesselation level and bezier order - precomputedTriangularBernsteinCoefficientArray.resize( ((bezierTesselation-1)*(bezierTesselation-2)/2)); - Real u,v,w; - size_t j,k,ind; - sofa::helper::vector tbia=btstc->getTriangleBezierIndexArray(); - for (ind=0,i=1;i<(bezierTesselation-1);++i) { - for (j=1;j<(bezierTesselation-i);++j,++ind) { - - sofa::helper::vector weightArray(tbia.size()); - // linear barycentric coordinates of the point - u=(Real)i/(Real)bezierTesselation; - v=(Real)j/(Real)bezierTesselation; - w=(Real)(1.0f-u-v); - for(k=0;kgetTriangleBezierIndexArrayOfGivenDegree(bezierTesselation); - } - if (precomputedDerivUTriangularBernsteinCoefficientArray.size()!=((bezierTesselation+1)*(bezierTesselation+2)/2)) { - precomputedDerivUTriangularBernsteinCoefficientArray.resize( ((bezierTesselation+1)*(bezierTesselation+2)/2)); - precomputedDerivVTriangularBernsteinCoefficientArray.resize( ((bezierTesselation+1)*(bezierTesselation+2)/2)); - - size_t j,k,l; - Real val; - InCoord barycentricCoordinate; - sofa::helper::vector tbia=btstc->getTriangleBezierIndexArray(); - - - for (j=0;j weightArrayDU(tbia.size()); - sofa::helper::vector weightArrayDV(tbia.size()); - for(k=0;kInherit::init(); -} - - -template -void Bezier2MeshMechanicalMapping::apply(const core::MechanicalParams * /*mparams*/, Data& dOut, const Data& dIn) -{ - helper::WriteAccessor< Data > out = dOut; - helper::ReadAccessor< Data > in = dIn; - - - size_t i; - // copy the points of underlying triangulation - for (i=0;igetNumberOfTriangularPoints();++i) { - out[i]=in[topoMap->local2GlobalBezierVertexArray[i]]; - bezierTesselationWeightArray[i]=btstc->getWeight(topoMap->local2GlobalBezierVertexArray[i]); - } - const size_t bezierTesselation=tesselationDegree; - - // copy the points on the edges pf the Bezier patches - if (bezierTesselation>1) { - size_t l,k; - size_t edgeRank=0; - sofa::helper::vector edgeControlPoints; - sofa::helper::vector edgeControlPointWeights; - InCoord p; - Real weight; - sofa::helper::vector::iterator ite=topoMap->edgeTriangleArray.begin(); - for (;ite!=topoMap->edgeTriangleArray.end();++ite,++edgeRank) { - // get control points along edges and their weights - edgeControlPoints.clear(); - edgeControlPointWeights.clear(); - // must decide if the edge is a rational Bezier or integral Bezier curve - const core::topology::BaseMeshTopology::TrianglesAroundEdge &tae=btstc->getTrianglesAroundEdge(edgeRank); - bool isRational=false; - for (l=0;lisRationalSpline(tae[l])) - isRational=true; - } - - edgeControlPoints.push_back(in[(*ite)[0]]); - if (isRational) - edgeControlPointWeights.push_back(btstc->getWeight((*ite)[0])); - sofa::helper::vector bezierEdge=topoMap->bezierEdgeArray[edgeRank]; - for(l=1;l<=(bezierDegree-1);++l) { - - edgeControlPoints.push_back(in[bezierEdge[l-1]]); - if (isRational) - edgeControlPointWeights.push_back(btstc->getWeight(bezierEdge[l-1])); - } - edgeControlPoints.push_back(in[(*ite)[1]]); - if (isRational) - edgeControlPointWeights.push_back(btstc->getWeight((*ite)[1])); - - // then interpolate position based on the 2 previous arrays - size_t tesselatedEdgeRank=btstc->getNumberOfTriangularPoints()+edgeRank*(bezierTesselation-1); - for (l=1;l weightArray=precomputedLinearBernsteinCoefficientArray[l-1]; - if (isRational) { - weight=0; - for (k=0;k<=bezierDegree;++k) { - /// univariate Bernstein polynomial - p+=edgeControlPoints[k]*weightArray[k]*edgeControlPointWeights[k]; - weight+=edgeControlPointWeights[k]*weightArray[k]; - } - } else{ - for (k=0;k<=bezierDegree;++k) { - /// univariate Bernstein polynomial - p+=edgeControlPoints[k]*weightArray[k]; - } - } - if (isRational) { - p/=weight; - bezierTesselationWeightArray[tesselatedEdgeRank]=weight; - } - - out[tesselatedEdgeRank++]=p; - } - } - // copy the points on the ed the Bezier patches - if (bezierTesselation>2) { - sofa::component::topology::BezierTriangleSetTopologyContainer::VecPointID indexArray; - size_t j,ind; - size_t tesselatedTriangleRank=btstc->getNumberOfTriangularPoints()+btstc->getNbEdges()*(bezierTesselation-1); - for (i=0;igetNumberOfTriangles();++i) { - - bool isRational=btstc->isRationalSpline(i); - // first get the Bezier control points in the triangle - btstc->getGlobalIndexArrayOfBezierPointsInTriangle(i, indexArray); - for (ind=0,j=1;j<(bezierTesselation-1);++j) { - for (k=1;k<(bezierTesselation-j);++k,++ind) { - p=InCoord(); - sofa::helper::vector &weigthArray=precomputedTriangularBernsteinCoefficientArray[ind]; - if (isRational) { - weight=0; - for (l=0;lgetWeight( indexArray[l])*weigthArray[l]; - weight+=btstc->getWeight( indexArray[l])*weigthArray[l]; - } - } else { - for (l=0;lgetNumberOfTriangles();++i) { - // first get the Bezier control points in the triangle - btstc->getGlobalIndexArrayOfBezierPointsInTriangle(i, indexArray); - - for (j=0;j &weigthArrayDU=precomputedDerivUTriangularBernsteinCoefficientArray[j]; - sofa::helper::vector &weigthArrayDV=precomputedDerivVTriangularBernsteinCoefficientArray[j]; - if (isRational){ - for (k=0;k -void Bezier2MeshMechanicalMapping::applyJ(const core::MechanicalParams * /*mparams*/, Data& dOut, const Data& dIn) -{ - if (!topoMap) return; - - helper::WriteAccessor< Data > out = dOut; - helper::ReadAccessor< Data > in = dIn; - - - size_t i; - // copy the points of underlying triangulation - for (i=0;igetNumberOfTriangularPoints();++i) { - out[i]=in[topoMap->local2GlobalBezierVertexArray[i]]; - - } - const size_t bezierTesselation=tesselationDegree; - - // copy the points on the edges pf the Bezier patches - if (bezierTesselation>1) { - size_t l,k; - size_t edgeRank=0; - sofa::helper::vector edgeControlPoints; - sofa::helper::vector edgeControlPointWeights; - InCoord p; - Real weight; - sofa::helper::vector::iterator ite=topoMap->edgeTriangleArray.begin(); - for (;ite!=topoMap->edgeTriangleArray.end();++ite,++edgeRank) { - // get control points along edges and their weights - edgeControlPoints.clear(); - edgeControlPointWeights.clear(); - // must decide if the edge is a rational Bezier or integral Bezier curve - const core::topology::BaseMeshTopology::TrianglesAroundEdge &tae=btstc->getTrianglesAroundEdge(edgeRank); - bool isRational=false; - for (l=0;lisRationalSpline(tae[l])) - isRational=true; - } - edgeControlPoints.push_back(in[(*ite)[0]]); - if (isRational) - edgeControlPointWeights.push_back(btstc->getWeight((*ite)[0])); - sofa::helper::vector bezierEdge=topoMap->bezierEdgeArray[edgeRank]; - for(l=1;l<=(bezierDegree-1);++l) { - - edgeControlPoints.push_back(in[bezierEdge[l-1]]); - if (isRational) - edgeControlPointWeights.push_back(btstc->getWeight(bezierEdge[l-1])); - } - edgeControlPoints.push_back(in[(*ite)[1]]); - if (isRational) - edgeControlPointWeights.push_back(btstc->getWeight((*ite)[1])); - - // then interpolate position based on the 2 previous arrays - size_t tesselatedEdgeRank=btstc->getNumberOfTriangularPoints()+edgeRank*(bezierTesselation-1); - for (l=1;l weightArray=precomputedLinearBernsteinCoefficientArray[l-1]; - if (isRational) { - weight=0; - for (k=0;k<=bezierDegree;++k) { - /// univariate Bernstein polynomial - p+=edgeControlPoints[k]*weightArray[k]*edgeControlPointWeights[k]; - weight+=edgeControlPointWeights[k]*weightArray[k]; - } - } else{ - for (k=0;k<=bezierDegree;++k) { - /// univariate Bernstein polynomial - p+=edgeControlPoints[k]*weightArray[k]; - } - } - if (isRational) { - p/=weight; - bezierTesselationWeightArray[tesselatedEdgeRank]=weight; - } - - out[tesselatedEdgeRank++]=p; - } - } - // copy the points on the ed the Bezier patches - if (bezierTesselation>2) { - sofa::component::topology::BezierTriangleSetTopologyContainer::VecPointID indexArray; - size_t j,ind; - size_t tesselatedTriangleRank=btstc->getNumberOfTriangularPoints()+btstc->getNbEdges()*(bezierTesselation-1); - for (i=0;igetNumberOfTriangles();++i) { - bool isRational=btstc->isRationalSpline(i); - // first get the Bezier control points in the triangle - btstc->getGlobalIndexArrayOfBezierPointsInTriangle(i, indexArray); - for (ind=0,j=1;j<(bezierTesselation-1);++j) { - for (k=1;k<(bezierTesselation-j);++k,++ind) { - p=InCoord(); - sofa::helper::vector &weigthArray=precomputedTriangularBernsteinCoefficientArray[ind]; - if (isRational) { - weight=0; - for (l=0;lgetWeight( indexArray[l])*weigthArray[l]; - weight+=btstc->getWeight( indexArray[l])*weigthArray[l]; - } - } else { - for (l=0;l -void Bezier2MeshMechanicalMapping::applyJT(const core::MechanicalParams * /*mparams*/, Data& dOut, const Data& dIn) -{ - if (!topoMap) return; - - helper::WriteAccessor< Data > out = dOut; - helper::ReadAccessor< Data > in = dIn; - - - size_t i; - // copy the points of underlying triangulation - for (i=0;igetNumberOfTriangularPoints();++i) { - out[i]=in[topoMap->local2GlobalBezierVertexArray[i]]; - - } - const size_t bezierTesselation=tesselationDegree; - - // copy the points on the edges pf the Bezier patches - if (bezierTesselation>1) { - size_t l,k; - size_t edgeRank=0; - - Real weight; - sofa::helper::vector::iterator ite=topoMap->edgeTriangleArray.begin(); - for (;ite!=topoMap->edgeTriangleArray.end();++ite,++edgeRank) { - // must decide if the edge is a rational Bezier or integral Bezier curve - const core::topology::BaseMeshTopology::TrianglesAroundEdge &tae=btstc->getTrianglesAroundEdge(edgeRank); - bool isRational=false; - for (l=0;lisRationalSpline(tae[l])) - isRational=true; - } - // get control points along edges and their weights - sofa::helper::vector bezierEdge=topoMap->bezierEdgeArray[edgeRank]; - size_t tesselatedEdgeRank=btstc->getNumberOfTriangularPoints()+edgeRank*(bezierTesselation-1); - if (isRational) { - for (l=1;l weightArray=precomputedLinearBernsteinCoefficientArray[l-1]; - // first compute the weight at the denominator - weight=btstc->getWeight((*ite)[0])*weightArray[0]; - for(k=1;k<=(bezierDegree-1);++k) { - weight+=weightArray[k]*btstc->getWeight(bezierEdge[k-1]); - } - weight+=btstc->getWeight((*ite)[1])*weightArray[bezierDegree]; - // now compute the normalized weight - out[(*ite)[0]]+=in[tesselatedEdgeRank]*weightArray[0]*btstc->getWeight((*ite)[0])/weight; - for(k=1;k<=(bezierDegree-1);++k) { - out[bezierEdge[k-1]]+=in[tesselatedEdgeRank]*weightArray[k]*btstc->getWeight(bezierEdge[k-1])/weight; - } - out[(*ite)[1]]+=in[tesselatedEdgeRank]*weightArray[bezierDegree]*btstc->getWeight((*ite)[1])/weight; - tesselatedEdgeRank++; - } - } else { - - for (l=1;l weightArray=precomputedLinearBernsteinCoefficientArray[l-1]; - out[(*ite)[0]]+=in[tesselatedEdgeRank]*weightArray[0]; - for(k=1;k<=(bezierDegree-1);++k) { - out[bezierEdge[k-1]]+=in[tesselatedEdgeRank]*weightArray[k]; - } - out[(*ite)[1]]+=in[tesselatedEdgeRank]*weightArray[bezierDegree]; - tesselatedEdgeRank++; - } - - } - } - // update according to the control points located inside triangles - if (bezierTesselation>2) { - sofa::component::topology::BezierTriangleSetTopologyContainer::VecPointID indexArray; - size_t j,ind; - size_t tesselatedTriangleRank=btstc->getNumberOfTriangularPoints()+btstc->getNbEdges()*(bezierTesselation-1); - for (i=0;igetNumberOfTriangles();++i) { - bool isRational=btstc->isRationalSpline(i); - // first get the Bezier control points in the triangle - btstc->getGlobalIndexArrayOfBezierPointsInTriangle(i, indexArray); - for (ind=0,j=1;j<(bezierTesselation-1);++j) { - for (k=1;k<(bezierTesselation-j);++k,++ind) { - - sofa::helper::vector &weigthArray=precomputedTriangularBernsteinCoefficientArray[ind]; - if (isRational) { - // first compute the whole weight at the denominator - weight=0; - for (l=0;lgetWeight( indexArray[l])*weigthArray[l]; - } - // then compute the output - for (l=0;lgetWeight( indexArray[l])/weight; - } - } else { - - for (l=0;l -void Bezier2MeshMechanicalMapping::applyJT(const core::ConstraintParams * /*cparams*/, Data& /*dOut*/, const Data& /*dIn*/) -{ - - if (!topoMap) - return; - -// const sofa::helper::vector< std::pair< Mesh2PointTopologicalMapping::Element, int> >& pointSource = topoMap->getPointSource(); - - // if (pointSource.empty()) - // return; - /* - InMatrixDeriv& out = *dOut.beginEdit(); - const OutMatrixDeriv& in = dIn.getValue(); - - const core::topology::BaseMeshTopology::SeqEdges& edges = inputTopo->getEdges(); - const core::topology::BaseMeshTopology::SeqTriangles& triangles = inputTopo->getTriangles(); - const core::topology::BaseMeshTopology::SeqQuads& quads = inputTopo->getQuads(); - const core::topology::BaseMeshTopology::SeqTetrahedra& tetrahedra = inputTopo->getTetrahedra(); - const core::topology::BaseMeshTopology::SeqHexahedra& hexahedra = inputTopo->getHexahedra(); - - typename Out::MatrixDeriv::RowConstIterator rowItEnd = in.end(); - - for (typename Out::MatrixDeriv::RowConstIterator rowIt = in.begin(); rowIt != rowItEnd; ++rowIt) - { - typename Out::MatrixDeriv::ColConstIterator colIt = rowIt.begin(); - typename Out::MatrixDeriv::ColConstIterator colItEnd = rowIt.end(); - - // Creates a constraints if the input constraint is not empty. - if (colIt != colItEnd) - { - typename In::MatrixDeriv::RowIterator o = out.writeLine(rowIt.index()); - - while (colIt != colItEnd) - { - const unsigned int indexIn = colIt.index(); - const OutDeriv data = colIt.val(); - std::pair< Mesh2PointTopologicalMapping::Element, int> source = pointSource[indexIn]; - - switch (source.first) - { - case topology::Mesh2PointTopologicalMapping::POINT: - { - o.addCol(source.second, data); - - break; - } - case topology::Mesh2PointTopologicalMapping::EDGE: - { - core::topology::BaseMeshTopology::Edge e = edges[source.second]; - typename In::Deriv f = data; - double fx = topoMap->getEdgeBaryCoords()[indexIn][0]; - - o.addCol(e[0], f * (1 - fx)); - o.addCol(e[1], f * fx); - - break; - } - case topology::Mesh2PointTopologicalMapping::TRIANGLE: - { - core::topology::BaseMeshTopology::Triangle t = triangles[source.second]; - typename In::Deriv f = data; - double fx = topoMap->getTriangleBaryCoords()[indexIn][0]; - double fy = topoMap->getTriangleBaryCoords()[indexIn][1]; - - o.addCol(t[0], f * (1 - fx - fy)); - o.addCol(t[1], f * fx); - o.addCol(t[2], f * fy); - - break; - } - case topology::Mesh2PointTopologicalMapping::QUAD: - { - core::topology::BaseMeshTopology::Quad q = quads[source.second]; - typename In::Deriv f = data; - double fx = topoMap->getQuadBaryCoords()[indexIn][0]; - double fy = topoMap->getQuadBaryCoords()[indexIn][1]; - - o.addCol(q[0], f * ((1-fx) * (1-fy))); - o.addCol(q[1], f * (fx * (1-fy))); - o.addCol(q[2], f * ((1-fx) * fy)); - o.addCol(q[3], f * (fx * fy)); - - break; - } - case topology::Mesh2PointTopologicalMapping::TETRA: - { - core::topology::BaseMeshTopology::Tetra t = tetrahedra[source.second]; - typename In::Deriv f = data; - double fx = topoMap->getTetraBaryCoords()[indexIn][0]; - double fy = topoMap->getTetraBaryCoords()[indexIn][1]; - double fz = topoMap->getTetraBaryCoords()[indexIn][2]; - - o.addCol(t[0], f * (1-fx-fy-fz)); - o.addCol(t[1], f * fx); - o.addCol(t[2], f * fy); - o.addCol(t[3], f * fz); - - break; - } - case topology::Mesh2PointTopologicalMapping::HEXA: - { - core::topology::BaseMeshTopology::Hexa h = hexahedra[source.second]; - typename In::Deriv f = data; - const double fx = topoMap->getHexaBaryCoords()[indexIn][0]; - const double fy = topoMap->getHexaBaryCoords()[indexIn][1]; - const double fz = topoMap->getHexaBaryCoords()[indexIn][2]; - const double oneMinFx = 1 - fx; - const double oneMinFy = 1 - fy; - const double oneMinFz = 1 - fz; - - o.addCol(h[0] , f * oneMinFx * oneMinFy * oneMinFz); - o.addCol(h[1] , f * fx * oneMinFy * oneMinFz); - o.addCol(h[3] , f * oneMinFx * fy * oneMinFz); - o.addCol(h[2] , f * fx * fy * oneMinFz); - o.addCol(h[4] , f * oneMinFx * oneMinFy * fz); - o.addCol(h[5] , f * fx * oneMinFy * fz); - o.addCol(h[6] , f * fx * fy * fz); - o.addCol(h[7] , f * oneMinFx * fy * fz); - - break; - } - default: - - break; - } - - ++colIt; - } - } - } - - dOut.endEdit(); */ -} - -} // namespace mapping - -} // namespace component - -} // namespace sofa - -#endif diff --git a/modules/SofaTopologyMapping/Bezier2MeshTopologicalMapping.cpp b/modules/SofaTopologyMapping/Bezier2MeshTopologicalMapping.cpp deleted file mode 100644 index d70807cc0c7..00000000000 --- a/modules/SofaTopologyMapping/Bezier2MeshTopologicalMapping.cpp +++ /dev/null @@ -1,285 +0,0 @@ -/****************************************************************************** -* SOFA, Simulation Open-Framework Architecture, development version * -* (c) 2006-2016 INRIA, USTL, UJF, CNRS, MGH * -* * -* This library 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 library 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 library; if not, write to the Free Software Foundation, * -* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * -******************************************************************************* -* SOFA :: Modules * -* * -* Authors: The SOFA Team and external contributors (see Authors.txt) * -* * -* Contact information: contact@sofa-framework.org * -******************************************************************************/ -#include -#include -#include -#include -#include - -#include - - -#include -#include -#include - -namespace sofa -{ -namespace component -{ -namespace topology -{ -using namespace sofa::defaulttype; -using namespace sofa::component::topology; -using namespace sofa::core::topology; - -SOFA_DECL_CLASS ( Bezier2MeshTopologicalMapping ) - -// Register in the Factory -int Bezier2MeshTopologicalMappingClass = core::RegisterObject ( "This class maps a Bezier tetrahedral or triangular mesh into an interpolated refined tetrahedral or triangular mesh" ) - .add< Bezier2MeshTopologicalMapping >() - ; - -// Implementation -Bezier2MeshTopologicalMapping::Bezier2MeshTopologicalMapping () - : d_tesselationTetrahedronDegree ( initData ( &d_tesselationTetrahedronDegree, (unsigned int)0, "tesselatedTetrahedronDegree", "Tesselate a tetrahedral mesh as to create a Bezier Tetrahedral mesh of a given order" ) ) - , d_tesselationTriangleDegree ( initData ( &d_tesselationTriangleDegree, (unsigned int)0, "tesselatedTriangleDegree", "Tesselate a triangular mesh as to create a Bezier Triangular mesh of a given order" ) ) - -{ - -} -Bezier2MeshTopologicalMapping::~Bezier2MeshTopologicalMapping(){ -} - -void Bezier2MeshTopologicalMapping::init() -{ -// initDone = true; - if(!fromModel) - { - serr << "Could not find an input Bezier topology " << sendl; - return; - } - if(!toModel) - { - serr << "Could not find an output mesh topology " << sendl; - return; - } - toModel->clear(); - - BezierTriangleSetTopologyContainer *btstc; - fromModel->getContext()->get(btstc); - - if (!btstc) { - serr << "Could not find an input BezierTriangleSetTopologyContainer " <getContext()->get(tstc); - - if (!tstc) { - serr << "Could not find an output TriangleSetTopologyContainer " <getDegree(); - - PointSetTopologyModifier *toPointMod = NULL; - toModel->getContext()->get(toPointMod, sofa::core::objectmodel::BaseContext::Local); - EdgeSetTopologyModifier *toEdgeMod = NULL; - toModel->getContext()->get(toEdgeMod, sofa::core::objectmodel::BaseContext::Local); - TriangleSetTopologyModifier *toTriangleMod = NULL; - toModel->getContext()->get(toTriangleMod, sofa::core::objectmodel::BaseContext::Local); -// TetrahedronSetTopologyModifier *toTetrahedronMod = NULL; -// toModel->getContext()->get(toTetrahedronMod, sofa::core::objectmodel::BaseContext::Local); - - - if (bezierTesselation>0) { - nbPoints=btstc->getNumberOfTriangularPoints()+btstc->getNumberOfEdges()*(bezierTesselation-1)+ - btstc->getNumberOfTriangles()*(bezierTesselation-1)*(bezierTesselation-2)/2; - - // fill topology container with empty points instead of specifying its size - // the real position will be filled by the mechanical mapping - size_t i; - tstc->setNbPoints((int)nbPoints); - // for (i=0;iaddPoint((SReal)0.0f,(SReal)0.0f,(SReal)0.0f); - - // store the vertices of the macro triangles since the set of positions may be a large overset of the positions of the triangular bezier triangles (if a Tetra2Trian mapping is used) - std::set triangleVertexSet; - - - const core::topology::BaseMeshTopology::SeqTriangles &ta=btstc->getTriangleArray(); - - for (i=0;igetNumberOfTriangularPoints()==triangleVertexSet.size()); - - global2LocalBezierVertexArray.resize(btstc->getNbPoints()); - std::fill(global2LocalBezierVertexArray.begin(),global2LocalBezierVertexArray.end(),-1); - - std::set::iterator itvs; - for (i=0,itvs=triangleVertexSet.begin();itvs!=triangleVertexSet.end();++itvs,++i) { - local2GlobalBezierVertexArray.push_back(*itvs); - global2LocalBezierVertexArray[*itvs]=i; - } - /* - if (toPointMod) - { - toPointMod->addPointsProcess(pBaryCoords.size()); - } - else - { - for (unsigned int j = 0; j < pBaryCoords.size(); j++) - { - toModel->addPoint(fromModel->getPX(i) + pBaryCoords[j][0], fromModel->getPY(i) + pBaryCoords[j][1], fromModel->getPZ(i) + pBaryCoords[j][2]); - } - } - - for (unsigned int j = 0; j < pBaryCoords.size(); j++) - { - pointsMappedFrom[POINT][i].push_back(pointSource.size()); - pointSource.push_back(std::make_pair(POINT, i)); - } - - if (toPointMod) - { - helper::vector< helper::vector< unsigned int > > ancestors; - helper::vector< helper::vector< double > > coefs; - toPointMod->addPointsWarning(pBaryCoords.size(), ancestors, coefs); - } - */ - - // this is used to store the global indices of tessellated Bezier triangles - globalIndexTesselatedBezierTriangleArray.resize(btstc->getNumberOfTriangles()); - // get the division of the triangle into subtriangles - sofa::helper::vector< sofa::component::topology::BezierTriangleSetTopologyContainer::LocalTriangleIndex> - sta=btstc->getLocalIndexSubtriangleArrayOfGivenDegree(bezierTesselation); - - // handle triangles - size_t nbTriangles=btstc->getNumberOfTriangles()*(bezierTesselation*bezierTesselation); - - helper::WriteOnlyAccessor > > loc2glob=Loc2GlobDataVec; - loc2glob.resize(nbTriangles); - - size_t j,k,l,offset,rank; - size_t baseEdgeOffset=btstc->getNumberOfTriangularPoints(); - size_t baseTriangleOffset=baseEdgeOffset+btstc->getNumberOfEdges()*(bezierTesselation-1); - size_t pointsPerTriangle=(bezierTesselation-1)*(bezierTesselation-2)/2; - core::topology::BaseMeshTopology::Triangle subtriangle; - sofa::component::topology::BezierTriangleSetTopologyContainer::VecPointID indexArray; - sofa::helper::vector bezierEdge; - sofa::component::topology::TriangleBezierIndex trbi; - size_t bezierDegree=btstc->getDegree(); - - for (rank=0,i=0;igetNumberOfTriangles();++i) { - // there are (bezierTesselation)*(bezierTesselation) subtriangles - // first store the indices of all the macro triangles into an array - core::topology::BaseMeshTopology::Triangle tr=btstc->getTriangle(i); - sofa::helper::vector macroTriangleIndexArray; - // store the 3 vertices - - for (j=0;j<3;++j) { - macroTriangleIndexArray.push_back(global2LocalBezierVertexArray[tr[j]]); - } -// std::cerr << std::endl; - // for(j=0;j)(tesselatedTriangleIndices[j])<1) { - core::topology::BaseMeshTopology::EdgesInTriangle eit=btstc->getEdgesInTriangle(i); - btstc->getGlobalIndexArrayOfBezierPointsInTriangle(i, indexArray); - for (j=0;j<3;++j) { - - // store the edge in an array only once - const core::topology::BaseMeshTopology::TrianglesAroundEdge &tae= btstc->getTrianglesAroundEdge(eit[j]); - if (tae[0]==i) { - const core::topology::BaseMeshTopology::Edge &e= btstc->getEdge(eit[j]); - edgeTriangleArray.push_back(e); - // find the edge index - for(k=0;tr[k]==e[0]||tr[k]==e[1];++k); - assert(tr[(k+1)%3]==e[0]); - bezierEdge.clear(); - for(l=1;l<=(bezierDegree-1);++l) { - - trbi[k]=0; - trbi[(k+1)%3]=bezierDegree-l; - trbi[(k+2)%3]=l; - - bezierEdge.push_back(indexArray[ btstc->getLocalIndexFromTriangleBezierIndex(trbi)]); - } - bezierEdgeArray.push_back(bezierEdge); - } - - - - - core::topology::BaseMeshTopology::Edge e=btstc->getEdge(eit[j]); - offset=baseEdgeOffset+eit[j]*(bezierTesselation-1); - if (e[0]==tr[(j+1)%3] ) { - for (k=0;k<(size_t)(bezierTesselation-1);++k) { - macroTriangleIndexArray.push_back(offset+k); - } - } else { - for (k=bezierTesselation-1;k>0;--k) { - macroTriangleIndexArray.push_back(offset+k-1); - } - } - - } - } - // store the triangle point - if (bezierTesselation>2) { - offset=baseTriangleOffset+i*pointsPerTriangle; - for (j=0;jaddTriangleProcess(subtriangle); - else - tstc->addTriangle(subtriangle[0],subtriangle[1],subtriangle[2]); - // update the topological maps - loc2glob[rank]=i; - Glob2LocMap.insert(std::pair(i,rank)); - } - } - } - -} - -void Bezier2MeshTopologicalMapping::updateTopologicalMappingTopDown() { - // TO DO : Handle topological changes -} - - -} // namespace topology -} // namespace component -} // namespace sofa - diff --git a/modules/SofaTopologyMapping/Bezier2MeshTopologicalMapping.h b/modules/SofaTopologyMapping/Bezier2MeshTopologicalMapping.h deleted file mode 100644 index 89821985db6..00000000000 --- a/modules/SofaTopologyMapping/Bezier2MeshTopologicalMapping.h +++ /dev/null @@ -1,109 +0,0 @@ -/****************************************************************************** -* SOFA, Simulation Open-Framework Architecture, development version * -* (c) 2006-2016 INRIA, USTL, UJF, CNRS, MGH * -* * -* This library 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 library 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 library; if not, write to the Free Software Foundation, * -* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * -******************************************************************************* -* SOFA :: Modules * -* * -* Authors: The SOFA Team and external contributors (see Authors.txt) * -* * -* Contact information: contact@sofa-framework.org * -******************************************************************************/ -#ifndef SOFA_COMPONENT_TOPOLOGY_BEZIER2MESHTOPOLOGICALMAPPING_H -#define SOFA_COMPONENT_TOPOLOGY_BEZIER2MESHTOPOLOGICALMAPPING_H -#include "config.h" - - -#include -#include - -#include -#include -#include - - - -namespace sofa { namespace component { namespace mapping { template class Bezier2MeshMechanicalMapping; } } } - - -namespace sofa -{ -namespace component -{ -namespace topology -{ -/** - * This class, called Bezier2MeshTopologicalMapping, is a specific implementation of the interface TopologicalMapping where : - * - * INPUT TOPOLOGY = A BezierTetrahedronSetTopology or BezierTriangleSetTopology as a tesselated version of the input mesh - * OUTPUT TOPOLOGY = a Tetrahedral or triangular mesh interpolated with a given degree of tesselation from its Bezier mesh - * - * This Topological mapping handles the specic input topology of Bezier elements and is made more efficient by using precomputations of maps - * - * Bezier2MeshTopologicalMapping class is templated by the pair (INPUT TOPOLOGY, OUTPUT TOPOLOGY) - * -*/ - - class SOFA_TOPOLOGY_MAPPING_API Bezier2MeshTopologicalMapping : public sofa::core::topology::TopologicalMapping -{ -public: - SOFA_CLASS(Bezier2MeshTopologicalMapping,sofa::core::topology::TopologicalMapping); - template friend class sofa::component::mapping::Bezier2MeshMechanicalMapping; - -protected: - /** \brief Constructor. - * - */ - Bezier2MeshTopologicalMapping (); - - /** \brief Destructor. - * - * Does nothing. - */ - virtual ~Bezier2MeshTopologicalMapping(); -public: - /** \brief Initializes the target BaseTopology from the source BaseTopology. - */ - virtual void init(); - - /// create a number of subtetrahedra depending on the level of tesselation. Degree is the number of times an edge will be split. - Data < unsigned int > d_tesselationTetrahedronDegree; - /// create a number of subtriangles depending on the level of tesselation. Degree is the number of times an edge will be split. - Data < unsigned int > d_tesselationTriangleDegree; -protected: - // local indexing of points inside tessellated triangles - sofa::helper::vector > tesselatedTriangleIndices; - sofa::helper::vector edgeTriangleArray; - sofa::helper::vector > bezierEdgeArray; - /// for each macro triangle set the index of tesselated points inside that triangle (used for nmal computation) - sofa::helper::vector< sofa::helper::vector > globalIndexTesselatedBezierTriangleArray; - sofa::helper::vector local2GlobalBezierVertexArray; - sofa::helper::vector global2LocalBezierVertexArray; - // the number of points in the output triangulation - size_t nbPoints; -public : - /// Method called at each topological changes propagation which comes from the INPUT topology to adapt the OUTPUT topology : - virtual void updateTopologicalMappingTopDown(); - -}; - - - -} // namespace topology -} // namespace component -} // namespace sofa - -#endif // SOFA_COMPONENT_TOPOLOGY_MESH2BEZIERTOPOLOGICALMAPPING_H diff --git a/modules/SofaTopologyMapping/BezierTetra2BezierTriangleTopologicalMapping.cpp b/modules/SofaTopologyMapping/BezierTetra2BezierTriangleTopologicalMapping.cpp deleted file mode 100644 index 49cc1cf362a..00000000000 --- a/modules/SofaTopologyMapping/BezierTetra2BezierTriangleTopologicalMapping.cpp +++ /dev/null @@ -1,320 +0,0 @@ -/****************************************************************************** -* SOFA, Simulation Open-Framework Architecture, development version * -* (c) 2006-2016 INRIA, USTL, UJF, CNRS, MGH * -* * -* This library 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 library 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 library; if not, write to the Free Software Foundation, * -* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * -******************************************************************************* -* SOFA :: Modules * -* * -* Authors: The SOFA Team and external contributors (see Authors.txt) * -* * -* Contact information: contact@sofa-framework.org * -******************************************************************************/ -#include "config.h" -#include -#include -#include -#include -#include -#include -#include - -#include -#include -#include - -namespace sofa -{ - -namespace component -{ - -namespace topology -{ - -using namespace sofa::defaulttype; - -using namespace sofa::component::topology; -using namespace sofa::core::topology; - -SOFA_DECL_CLASS(BezierTetra2BezierTriangleTopologicalMapping) - -// Register in the Factory -int BezierTetra2BezierTriangleTopologicalMappingClass = core::RegisterObject("Special case of mapping where BezierTetrahedronSetTopology is converted to BezierTriangleSetTopology") - .add< BezierTetra2BezierTriangleTopologicalMapping >() - - ; - -// Implementation - -BezierTetra2BezierTriangleTopologicalMapping::BezierTetra2BezierTriangleTopologicalMapping() - : flipNormals(initData(&flipNormals, bool(false), "flipNormals", "Flip Normal ? (Inverse point order when creating triangle)")) - { -} - -BezierTetra2BezierTriangleTopologicalMapping::~BezierTetra2BezierTriangleTopologicalMapping() -{ -} - -void BezierTetra2BezierTriangleTopologicalMapping::init() -{ - //sout << "INFO_print : init BezierTetra2BezierTriangleTopologicalMapping" << sendl; - - // INITIALISATION of Bezier TRIANGULAR mesh from Bezier TETRAHEDRAL mesh : - - - if (fromModel) - { - BezierTetrahedronSetTopologyContainer *from_btstc; - fromModel->getContext()->get(from_btstc); - if (!from_btstc) { - serr << "Could not find an input BezierTetrahedronSetTopologyContainer"<getContext()->get(to_btstc); - - if (!to_btstc) { - serr << "Could not find an output BezierTriangleSetTopologyContainer " <clear(); - - // set the number of points of Bezier triangle = number of points of Bezier tetra - toModel->setNbPoints(from_btstc->getNbPoints()); - - TriangleSetTopologyModifier *to_tstm; - toModel->getContext()->get(to_tstm); - - const sofa::helper::vector &triangleArray=fromModel->getTriangles(); - const bool flipN = flipNormals.getValue(); - - // set the degree of Bezier triangle equal to that of Bezier tetra - to_btstc->d_degree.setValue(from_btstc->getDegree()); - to_btstc->init(); - - // initialize table of equivalence - sofa::helper::vector & Loc2GlobVec = *(Loc2GlobDataVec.beginEdit()); - - Loc2GlobVec.clear(); - Glob2LocMap.clear(); - size_t rankTriangle=0; - // set to count the number of vertices - std::set vertexSet; - // set the boolean indicating if the triangulation is rational - helper::WriteOnlyAccessor > isRationalSpline=to_btstc->d_isRationalSpline; - - for (unsigned int i=0; igetTetrahedraAroundTriangle(i); - if (tat.size()==1) - { - // add macro triangle - core::topology::BaseMeshTopology::Triangle t = triangleArray[i]; - if(flipN) - { - unsigned int tmp = t[2]; - t[2] = t[1]; - t[1] = tmp; - } - to_tstm->addTriangleProcess(t); - // add vertices in set - vertexSet.insert(t[0]);vertexSet.insert(t[1]);vertexSet.insert(t[2]); - // if the adjacent tetrahedron is rational then the triangle is also rational - const bool irs=from_btstc->isRationalSpline(tat[0]); - isRationalSpline.push_back(irs); - - Loc2GlobVec.push_back(i); - Glob2LocMap[i]=Loc2GlobVec.size()-1; - // update the local maps of control points - // get the control points of the tetrahedron adjacent to that triangle - const BezierTriangleSetTopologyContainer::VecPointID &indexArray= - from_btstc->getGlobalIndexArrayOfBezierPoints(tat[0]); - core::topology::BaseMeshTopology::Tetrahedron tet=from_btstc->getTetrahedron(tat[0]); - size_t k,j,l,equiv[3]; - // get the index of that triangle in the tetrahedron - core::topology::BaseMeshTopology::TrianglesInTetrahedron tit=from_btstc->getTrianglesInTetrahedron(tat[0]); - for (l=0;tit[l]!=i;++l); - // find the equivalence between the triangle index and tetrahedron index - for(j=0;j<3;++j) { - for(k=0;tet[k]!=t[j];++k); - equiv[j]=k; - } - // now gets the indices of all control points in the Bezier triangle - sofa::helper::vector trbia=to_btstc->getTriangleBezierIndexArray(); - for (j=0;jgetLocalIndexFromTetrahedronBezierIndex(tbi)]; - // now fill the Bezier triangle maps - to_btstc->locationToGlobalIndexMap.insert(std::pair(BezierTriangleSetTopologyContainer::ControlPointLocation(rankTriangle,trbia[j]),globalIndex)); - to_btstc->globalIndexToLocationMap.insert(std::pair(globalIndex,BezierTriangleSetTopologyContainer::ControlPointLocation(rankTriangle,trbia[j]))); - } - rankTriangle++; - } - } - // copy the weights - const BezierTetrahedronSetTopologyContainer::SeqWeights &swFrom=from_btstc->getWeightArray(); - - BezierTriangleSetTopologyContainer::SeqWeights &wa=*(to_btstc->d_weightArray.beginEdit()); - wa.resize(swFrom.size()); - std::copy(swFrom.begin(),swFrom.end(),wa.begin()); - to_btstc->d_weightArray.endEdit(); - - to_btstc->d_numberOfTriangularPoints.setValue(vertexSet.size()); - to_btstc->checkTopology(); - //to_tstm->propagateTopologicalChanges(); - to_tstm->notifyEndingEvent(); - //to_tstm->propagateTopologicalChanges(); - Loc2GlobDataVec.endEdit(); - } - } -} - - -unsigned int BezierTetra2BezierTriangleTopologicalMapping::getFromIndex(unsigned int ind) -{ - - if(fromModel->getTetrahedraAroundTriangle(ind).size()==1) - { - return fromModel->getTetrahedraAroundTriangle(ind)[0]; - } - else - { - return 0; - } -} - -void BezierTetra2BezierTriangleTopologicalMapping::updateTopologicalMappingTopDown() -{ - - // INITIALISATION of TRIANGULAR mesh from TETRAHEDRAL mesh : -// cerr << "updateTopologicalMappingTopDown called" << endl; - - if (fromModel) - { - - TriangleSetTopologyModifier *to_tstm; - toModel->getContext()->get(to_tstm); - - if (toModel) - { - - std::list::const_iterator itBegin=fromModel->beginChange(); - std::list::const_iterator itEnd=fromModel->endChange(); - - //sofa::helper::vector & Loc2GlobVec = *(Loc2GlobDataVec.beginEdit()); - - while( itBegin != itEnd ) - { - TopologyChangeType changeType = (*itBegin)->getChangeType(); - - switch( changeType ) - { - - case core::topology::ENDING_EVENT: - { - //sout << "INFO_print : Tetra2TriangleTopologicalMapping - ENDING_EVENT" << sendl; - to_tstm->propagateTopologicalChanges(); - to_tstm->notifyEndingEvent(); - to_tstm->propagateTopologicalChanges(); - break; - } - - case core::topology::TRIANGLESREMOVED: - { - - break; - } - - case core::topology::TRIANGLESADDED: - { - - break; - } - - case core::topology::TETRAHEDRAADDED: - { - - break; - } - - case core::topology::TETRAHEDRAREMOVED: - { - - - break; - - } - - case core::topology::EDGESADDED: - { - - break; - } - - case core::topology::POINTSADDED: - { - - - break; - } - - case core::topology::POINTSREMOVED: - { - - - break; - } - - case core::topology::POINTSRENUMBERING: - { - - - break; - } - default: - // Ignore events that are not Triangle related. - break; - }; - - ++itBegin; - } - to_tstm->propagateTopologicalChanges(); - //Loc2GlobDataVec.endEdit(); - } - } - - return; -} - - -} // namespace topology - -} // namespace component - -} // namespace sofa diff --git a/modules/SofaTopologyMapping/BezierTetra2BezierTriangleTopologicalMapping.h b/modules/SofaTopologyMapping/BezierTetra2BezierTriangleTopologicalMapping.h deleted file mode 100644 index 9a1a9832b95..00000000000 --- a/modules/SofaTopologyMapping/BezierTetra2BezierTriangleTopologicalMapping.h +++ /dev/null @@ -1,98 +0,0 @@ -/****************************************************************************** -* SOFA, Simulation Open-Framework Architecture, development version * -* (c) 2006-2016 INRIA, USTL, UJF, CNRS, MGH * -* * -* This library 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 library 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 library; if not, write to the Free Software Foundation, * -* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * -******************************************************************************* -* SOFA :: Modules * -* * -* Authors: The SOFA Team and external contributors (see Authors.txt) * -* * -* Contact information: contact@sofa-framework.org * -******************************************************************************/ -#ifndef SOFA_COMPONENT_TOPOLOGY_BEZIERTETRA2BEZIERTRIANGLETOPOLOGICALMAPPING_H -#define SOFA_COMPONENT_TOPOLOGY_BEZIERTETRA2BEZIERTRIANGLETOPOLOGICALMAPPING_H - -#include - -#include -#include - -#include - -namespace sofa -{ - -namespace component -{ - -namespace topology -{ - - -/** - * This class, called Tetra2TriangleTopologicalMapping, is a specific implementation of the interface TopologicalMapping where : - * - * INPUT TOPOLOGY = TetrahedronSetTopology - * OUTPUT TOPOLOGY = TriangleSetTopology, as the boundary of the INPUT TOPOLOGY - * - * Tetra2TriangleTopologicalMapping class is templated by the pair (INPUT TOPOLOGY, OUTPUT TOPOLOGY) - * -*/ - -class SOFA_TOPOLOGY_MAPPING_API BezierTetra2BezierTriangleTopologicalMapping : public sofa::core::topology::TopologicalMapping -{ -public: - SOFA_CLASS(BezierTetra2BezierTriangleTopologicalMapping,sofa::core::topology::TopologicalMapping); -protected: - /** \brief Constructor. - * - */ - BezierTetra2BezierTriangleTopologicalMapping(); - - /** \brief Destructor. - * - * Does nothing. - */ - virtual ~BezierTetra2BezierTriangleTopologicalMapping(); -public: - /** \brief Initializes the target BaseTopology from the source BaseTopology. - */ - virtual void init(); - - - /** \brief Translates the TopologyChange objects from the source to the target. - * - * Translates each of the TopologyChange objects waiting in the source list so that they have a meaning and - * reflect the effects of the first topology changes on the second topology. - * - */ - virtual void updateTopologicalMappingTopDown(); - - virtual unsigned int getFromIndex(unsigned int ind); -protected: - Data flipNormals; - - - std::vector addedTriangleIndex; -}; - -} // namespace topology - -} // namespace component - -} // namespace sofa - -#endif // SOFA_COMPONENT_TOPOLOGY_BEZIERTETRA2BEZIERTRIANGLETOPOLOGICALMAPPING_H diff --git a/modules/SofaTopologyMapping/CMakeLists.txt b/modules/SofaTopologyMapping/CMakeLists.txt index e24356d77fc..bff4380d286 100644 --- a/modules/SofaTopologyMapping/CMakeLists.txt +++ b/modules/SofaTopologyMapping/CMakeLists.txt @@ -2,16 +2,11 @@ cmake_minimum_required(VERSION 2.8.12) project(SofaTopologyMapping) set(HEADER_FILES - Bezier2MeshMechanicalMapping.h - Bezier2MeshMechanicalMapping.inl - Bezier2MeshTopologicalMapping.h - BezierTetra2BezierTriangleTopologicalMapping.h CenterPointTopologicalMapping.h Edge2QuadTopologicalMapping.h Hexa2QuadTopologicalMapping.h Hexa2TetraTopologicalMapping.h IdentityTopologicalMapping.h - Mesh2BezierTopologicalMapping.h Mesh2PointMechanicalMapping.h Mesh2PointMechanicalMapping.inl Mesh2PointTopologicalMapping.h @@ -28,15 +23,11 @@ set(HEADER_FILES ) set(SOURCE_FILES - Bezier2MeshMechanicalMapping.cpp - Bezier2MeshTopologicalMapping.cpp - BezierTetra2BezierTriangleTopologicalMapping.cpp CenterPointTopologicalMapping.cpp Edge2QuadTopologicalMapping.cpp Hexa2QuadTopologicalMapping.cpp Hexa2TetraTopologicalMapping.cpp IdentityTopologicalMapping.cpp - Mesh2BezierTopologicalMapping.cpp Mesh2PointMechanicalMapping.cpp Mesh2PointTopologicalMapping.cpp Quad2TriangleTopologicalMapping.cpp diff --git a/modules/SofaTopologyMapping/Mesh2BezierTopologicalMapping.cpp b/modules/SofaTopologyMapping/Mesh2BezierTopologicalMapping.cpp deleted file mode 100644 index 24375bfaba7..00000000000 --- a/modules/SofaTopologyMapping/Mesh2BezierTopologicalMapping.cpp +++ /dev/null @@ -1,186 +0,0 @@ -/****************************************************************************** -* SOFA, Simulation Open-Framework Architecture, development version * -* (c) 2006-2016 INRIA, USTL, UJF, CNRS, MGH * -* * -* This library 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 library 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 library; if not, write to the Free Software Foundation, * -* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * -******************************************************************************* -* SOFA :: Modules * -* * -* Authors: The SOFA Team and external contributors (see Authors.txt) * -* * -* Contact information: contact@sofa-framework.org * -******************************************************************************/ -#include -#include -#include -#include - -#include - - -#include -#include -#include - -namespace sofa -{ -namespace component -{ -namespace topology -{ -using namespace sofa::defaulttype; -using namespace sofa::component::topology; -using namespace sofa::core::topology; -using helper::vector; - -SOFA_DECL_CLASS ( Mesh2BezierTopologicalMapping ) - -// Register in the Factory -int Mesh2BezierTopologicalMappingClass = core::RegisterObject ( "This class maps a tetrahedral mesh mesh into a high order tetrahedral mesh" ) - .add< Mesh2BezierTopologicalMapping >() - ; - -// Implementation -Mesh2BezierTopologicalMapping::Mesh2BezierTopologicalMapping () - : bezierTetrahedronDegree ( initData ( &bezierTetrahedronDegree, (unsigned int)0, "bezierTetrahedronDegree", "Tesselate a tetrahedral mesh as to create a Bezier Tetrahedral mesh of a given order" ) ) - , bezierTriangleDegree ( initData ( &bezierTriangleDegree, (unsigned int)0, "bezierTriangleDegree", "Tesselate a triangular mesh as to create a Bezier Triangular mesh of a given order" ) ) - -{ - -} - -void Mesh2BezierTopologicalMapping::init() -{ - - if (bezierTetrahedronDegree.getValue()>0) { - size_t degree=bezierTetrahedronDegree.getValue(); - // make copyTetrahedra as true - copyTetrahedra.setValue(true); - - // process each coord array - helper::WriteAccessor< Data > > pBary = pointBaryCoords; - pBary.clear(); - pBary.push_back(Vec3d(0,0,0)); - if (degree >1) { - // process each edge array - helper::WriteAccessor< Data > > eBary = edgeBaryCoords; - eBary.clear(); - size_t i; - for (i=1;i2) { - // process each triangle array - helper::WriteAccessor< Data > > trBary = triangleBaryCoords; - trBary.clear(); - size_t i,j; - for (i=1;i<(degree-1);++i) { - for (j=1;j<(degree-i);++j) { - trBary.push_back(Vec3d((double)j/degree,(double)(degree-i-j)/degree,(double)i/degree)); -// trBary.push_back(Vec3d((double)(i)/degree,(double)j/degree,(double)(degree-i-j)/degree)); - } - } - - } - if (degree >3) { - // process each tetrahedron array - helper::WriteAccessor< Data > > tetBary = tetraBaryCoords; - tetBary.clear(); - size_t i,j,k; - for (i=1;i<(degree-2);++i) { - for (j=1;j<(degree-i-1);++j) { - for (k=1;k<(degree-j-i);++k) { - tetBary.push_back(Vec3d((double)j/degree,(double)k/degree,(double)(degree-i-j-k)/degree)); -// tetBary.push_back(Vec3d((double)i/degree,(double)j/degree,(double)k/degree)); - } - } - } - - } - - } - - if (bezierTriangleDegree.getValue()>0) { - size_t degree=bezierTriangleDegree.getValue(); - // make copytriangles as true - copyTriangles.setValue(true); - - // process each coord array - helper::WriteAccessor< Data > > pBary = pointBaryCoords; - pBary.clear(); - pBary.push_back(Vec3d(0,0,0)); - if (degree >1) { - // process each edge array - helper::WriteAccessor< Data > > eBary = edgeBaryCoords; - eBary.clear(); - size_t i; - for (i=1;i2) { - // process each triangle array - helper::WriteAccessor< Data > > trBary = triangleBaryCoords; - trBary.clear(); - size_t i,j; - for (i=1;i<(degree-1);++i) { - for (j=1;j<(degree-i);++j) { - trBary.push_back(Vec3d((double)j/degree,(double)(degree-i-j)/degree,(double)i/degree)); - // trBary.push_back(Vec3d((double)(i)/degree,(double)j/degree,(double)(degree-i-j)/degree)); - } - } - - } - } - Mesh2PointTopologicalMapping::init(); - if (bezierTetrahedronDegree.getValue()>0) { - /// copy the number of tetrahedron vertices to the Bezier topology container - BezierTetrahedronSetTopologyContainer *toBTTC = NULL; - toModel->getContext()->get(toBTTC, sofa::core::objectmodel::BaseContext::Local); - if (toBTTC) { - // set the number of tetrahedral vertices among the number of control points. - toBTTC->d_numberOfTetrahedralPoints.setValue(pointsMappedFrom[POINT].size()); - toBTTC->d_degree.setValue(bezierTetrahedronDegree.getValue()); - toBTTC->reinit(); - toBTTC->checkBezierPointTopology(); - } else { - serr << "Could not find a BezierTetrahedronSetTopologyContainer as target topology " << sendl; - } - } - if (bezierTriangleDegree.getValue()>0) { - /// copy the number of triangle vertices to the Bezier triangle topology container - BezierTriangleSetTopologyContainer *toBTTC = NULL; - toModel->getContext()->get(toBTTC, sofa::core::objectmodel::BaseContext::Local); - if (toBTTC) { - // set the number of tetrahedral vertices among the number of control points. - toBTTC->d_numberOfTriangularPoints.setValue(pointsMappedFrom[POINT].size()); - toBTTC->d_degree.setValue(bezierTriangleDegree.getValue()); - toBTTC->reinit(); - toBTTC->checkBezierPointTopology(); - } else { - serr << "Could not find a BezierTriangleSetTopologyContainer as target topology " << sendl; - } - } - -} - - -} // namespace topology -} // namespace component -} // namespace sofa - diff --git a/modules/SofaTopologyMapping/Mesh2BezierTopologicalMapping.h b/modules/SofaTopologyMapping/Mesh2BezierTopologicalMapping.h deleted file mode 100644 index cf7dc25fb0e..00000000000 --- a/modules/SofaTopologyMapping/Mesh2BezierTopologicalMapping.h +++ /dev/null @@ -1,82 +0,0 @@ -/****************************************************************************** -* SOFA, Simulation Open-Framework Architecture, development version * -* (c) 2006-2016 INRIA, USTL, UJF, CNRS, MGH * -* * -* This library 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 library 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 library; if not, write to the Free Software Foundation, * -* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * -******************************************************************************* -* SOFA :: Modules * -* * -* Authors: The SOFA Team and external contributors (see Authors.txt) * -* * -* Contact information: contact@sofa-framework.org * -******************************************************************************/ -#ifndef SOFA_COMPONENT_TOPOLOGY_MESH2BEZIERTOPOLOGICALMAPPING_H -#define SOFA_COMPONENT_TOPOLOGY_MESH2BEZIERTOPOLOGICALMAPPING_H -#include "config.h" - -#include - - - -namespace sofa -{ -namespace component -{ -namespace topology -{ - -/** - * This class, called Mesh2BezierTopologicalMapping, is a specific implementation of the interface TopologicalMapping where : - * - * INPUT TOPOLOGY = any Tetrahedral or triangular MeshTopology - * OUTPUT TOPOLOGY = A BezierTetrahedronSetTopology or BezierTriangleSetTopology as a tesselated version of the input mesh - * - * This Topological mapping is a specific implementation of the Mesh2PointTopologicalMapping with a small overhead - * - * Mesh2BezierTopologicalMapping class is templated by the pair (INPUT TOPOLOGY, OUTPUT TOPOLOGY) - * -*/ - - class SOFA_TOPOLOGY_MAPPING_API Mesh2BezierTopologicalMapping : public sofa::component::topology::Mesh2PointTopologicalMapping -{ -public: - SOFA_CLASS(Mesh2BezierTopologicalMapping,sofa::component::topology::Mesh2PointTopologicalMapping); -protected: - /** \brief Constructor. - * - */ - Mesh2BezierTopologicalMapping (); - - /** \brief Destructor. - * - * Does nothing. - */ - virtual ~Mesh2BezierTopologicalMapping() {}; -public: - /** \brief Initializes the target BaseTopology from the source BaseTopology. - */ - virtual void init(); - - /// Fills pointBaryCoords, edgeBaryCoords, triangleBaryCoords and tetraBaryCoords so as to create a Bezier Tetrahedron mesh of a given order - Data < unsigned int > bezierTetrahedronDegree; - /// Fills pointBaryCoords, edgeBaryCoords, triangleBaryCoords so as to create a Bezier Triangle mesh of a given order - Data < unsigned int > bezierTriangleDegree; -}; - -} // namespace topology -} // namespace component -} // namespace sofa - -#endif // SOFA_COMPONENT_TOPOLOGY_MESH2BEZIERTOPOLOGICALMAPPING_H diff --git a/modules/SofaTopologyMapping/initTopologyMapping.cpp b/modules/SofaTopologyMapping/initTopologyMapping.cpp index 491e554feba..78cf86c6c3c 100644 --- a/modules/SofaTopologyMapping/initTopologyMapping.cpp +++ b/modules/SofaTopologyMapping/initTopologyMapping.cpp @@ -42,9 +42,7 @@ void initTopologyMapping() } } -SOFA_LINK_CLASS(BezierTetra2BezierTriangleTopologicalMapping) -SOFA_LINK_CLASS(Bezier2MeshTopologicalMapping) -SOFA_LINK_CLASS(Bezier2MeshMechanicalMapping) + SOFA_LINK_CLASS(Mesh2PointMechanicalMapping) SOFA_LINK_CLASS(SimpleTesselatedTetraMechanicalMapping) SOFA_LINK_CLASS(CenterPointTopologicalMapping)