diff --git a/examples/polyscope-examples/dgtalFEM-poisson.cpp b/examples/polyscope-examples/dgtalFEM-poisson.cpp index 2b7ca749af..25de9e00ee 100644 --- a/examples/polyscope-examples/dgtalFEM-poisson.cpp +++ b/examples/polyscope-examples/dgtalFEM-poisson.cpp @@ -105,7 +105,7 @@ int main() auto params = SH3::defaultParameters() | SHG3::defaultParameters() | SHG3::parametersGeometryEstimation(); auto h=.7 ; //gridstep - params( "polynomial", "0.1*y*y -0.1*x*x - 2.0*z" )( "gridstep", h ); + params( "polynomial", "0.1*y*y -0.1*x*x - 2.1*z" )( "gridstep", h ); auto implicit_shape = SH3::makeImplicitShape3D ( params ); auto digitized_shape = SH3::makeDigitizedImplicitShape3D( implicit_shape, params ); auto K = SH3::getKSpace( params ); diff --git a/src/DGtal/dec/PolygonalCalculus.h b/src/DGtal/dec/PolygonalCalculus.h index e6cac56c2b..da1fb8da86 100644 --- a/src/DGtal/dec/PolygonalCalculus.h +++ b/src/DGtal/dec/PolygonalCalculus.h @@ -1488,10 +1488,14 @@ namespace DGtal auto v = sharp( j, i ); auto edge_i = mySurfaceMesh->makeEdge( vertices[ i ], vertices[ ( i + 1 ) % nf ] ); - if ( v != 0.0 ) - triplets.emplace_back( Triplet( - (SparseMatrix::StorageIndex)f + j * mySurfaceMesh->nbFaces(), - (SparseMatrix::StorageIndex)edge_i, v ) ); + if(vertices[i] < vertices[(i + 1) % nf]) + triplets.emplace_back( Triplet( + (SparseMatrix::StorageIndex)3 * f + j, + (SparseMatrix::StorageIndex)edge_i, v ) ); + else + triplets.emplace_back( Triplet( + (SparseMatrix::StorageIndex)3 * f + j, + (SparseMatrix::StorageIndex)edge_i, -v ) ); } } mySharp.setFromTriplets( triplets.begin(), triplets.end() ); @@ -1510,17 +1514,22 @@ namespace DGtal DenseMatrix flat = this->flat( f ); const auto vertices = mySurfaceMesh->incidentVertices( f ); for ( auto i = 0u; i < nf; ++i ) - for ( auto j = 0; j < 3; ++j ) - { - auto v = flat( i, j ); + for ( auto j = 0; j < 3; ++j ) + { auto edge_i = mySurfaceMesh->makeEdge( vertices[ i ], - vertices[ ( i + 1 ) % nf ] ); - if ( v != 0.0 ) - triplets.emplace_back( Triplet( - (SparseMatrix::StorageIndex)edge_i, - (SparseMatrix::StorageIndex)f + j * mySurfaceMesh->nbFaces(), - v ) ); - } + vertices[ ( i + 1 ) % nf ] ); + auto v = flat( i, j ) / (double) mySurfaceMesh->edgeFaces(edge_i).size(); + if(vertices[i] < vertices[(i + 1) % nf]) + triplets.emplace_back( Triplet( + (SparseMatrix::StorageIndex)edge_i, + (SparseMatrix::StorageIndex)3 * f + j, + v ) ); + else + triplets.emplace_back( Triplet( + (SparseMatrix::StorageIndex)edge_i, + (SparseMatrix::StorageIndex)3 * f + j, + -v ) ); + } } myFlat.setFromTriplets( triplets.begin(), triplets.end() ); return myFlat;