Skip to content

Commit 1fa5634

Browse files
authored
Fusion experimental weights (#5696)
- add more parameters to fusion algorithm
1 parent 2849669 commit 1fa5634

File tree

7 files changed

+40
-4
lines changed

7 files changed

+40
-4
lines changed

source/MRCuda/MRCudaPointsToDistanceVolume.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,8 @@ MRCUDA_API Expected<void> pointsToDistanceVolumeByParts( const PointCloud& cloud
101101
.dimensions = fromVec( params.dimensions ),
102102
.sigma = params.sigma,
103103
.minWeight = params.minWeight,
104+
.invSigmaModifier = params.invSigmaModifier,
105+
.sqrtAngleWeight = params.sqrtAngleWeight
104106
};
105107

106108
const auto layerSize = (size_t)params.dimensions.x * params.dimensions.y;

source/MRCuda/MRCudaPointsToDistanceVolume.cu

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ namespace Cuda
5454
};
5555

5656
addSubTask( 0 );
57-
const auto inv2SgSq = -0.5f / ( params.sigma * params.sigma );
57+
const auto inv2SgSq = -params.invSigmaModifier / ( params.sigma * params.sigma );
5858
while ( !subtasks.empty() )
5959
{
6060
const auto n = subtasks.top();
@@ -73,7 +73,11 @@ namespace Cuda
7373
const auto distSq = lengthSq(voxelCenter - coord );
7474
const auto w = exp( distSq * inv2SgSq );
7575
sumWeight += w;
76-
sumDist += dot( normals[orderedPoints[i].id], voxelCenter - coord ) * w;
76+
const auto dt = dot( normals[orderedPoints[i].id], voxelCenter - coord );
77+
if ( !params.sqrtAngleWeight )
78+
sumDist += dt * w;
79+
else
80+
sumDist += copysign( sqrt( abs( dt ) ), dt ) * w;
7781
}
7882
}
7983
continue;

source/MRCuda/MRCudaPointsToDistanceVolume.cuh

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,14 @@ namespace Cuda
2020

2121
/// minimum sum of influence weights from surrounding points for a triangle to appear, meaning that there shall be at least this number of points in close proximity
2222
float minWeight = 1;
23+
24+
/// coefficient used for weight calculation: e^(dist^2 * -invSigmaModifier * sigma^-2)
25+
/// values: (0;inf)
26+
float invSigmaModifier = 0.5f;
27+
28+
/// changes the way point angle affects weight, by default it is linearly increasing with dot product
29+
/// if enabled - increasing as dot product^(0.5) (with respect to its sign)
30+
bool sqrtAngleWeight{ false };
2331
};
2432

2533
// struct similar to MR::Point

source/MRVoxels/MRPointsToDistanceVolume.cpp

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ FunctionVolume pointsToDistanceFunctionVolume( const PointCloud & cloud, const P
2121

2222
return FunctionVolume
2323
{
24-
.data = [&cloud, params, inv2SgSq = -0.5f / sqr( params.sigma ), ballRadiusSq = sqr( 3 * params.sigma ),
24+
.data = [&cloud, params, inv2SgSq = -params.invSigmaModifier / sqr( params.sigma ), ballRadiusSq = sqr( 3 * params.sigma ),
2525
&normals = params.ptNormals ? *params.ptNormals : cloud.normals] ( const Vector3i& pos ) -> float
2626
{
2727
auto coord = Vector3f( pos ) + Vector3f::diagonal( 0.5f );
@@ -33,7 +33,11 @@ FunctionVolume pointsToDistanceFunctionVolume( const PointCloud & cloud, const P
3333
{
3434
const auto w = std::exp( found.distSq * inv2SgSq );
3535
sumWeight += w;
36-
sumDist += dot( normals[found.vId], voxelCenter - p ) * w;
36+
auto dt = dot( normals[found.vId], voxelCenter - p );
37+
if ( !params.sqrtAngleWeight )
38+
sumDist += dt * w;
39+
else
40+
sumDist += std::copysign( std::sqrt( std::abs( dt ) ), dt ) * w;
3741
return Processing::Continue;
3842
} );
3943

source/MRVoxels/MRPointsToDistanceVolume.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,14 @@ struct PointsToDistanceVolumeParams : DistanceVolumeParams
1818
/// minimum sum of influence weights from surrounding points for a voxel to get a value, meaning that there shall be at least this number of points in close proximity
1919
float minWeight = 1;
2020

21+
/// coefficient used for weight calculation: e^(dist^2 * -invSigmaModifier * sigma^-2)
22+
/// values: (0;inf)
23+
float invSigmaModifier = 0.5f;
24+
25+
/// changes the way point angle affects weight, by default it is linearly increasing with dot product
26+
/// if enabled - increasing as dot product^(0.5) (with respect to its sign)
27+
bool sqrtAngleWeight{ false };
28+
2129
/// optional input: if this pointer is set then function will use these normals instead of ones present in cloud
2230
const VertNormals* ptNormals = nullptr;
2331
};

source/MRVoxels/MRPointsToMeshFusion.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,8 @@ Expected<Mesh> pointsToMeshFusion( const PointCloud & cloud, const PointsToMeshP
5252
p2vParams.dimensions = dimensions;
5353
p2vParams.sigma = params.sigma;
5454
p2vParams.minWeight = params.minWeight;
55+
p2vParams.invSigmaModifier = params.invSigmaModifier;
56+
p2vParams.sqrtAngleWeight = params.sqrtAngleWeight;
5557

5658
MarchingCubesParams vmParams;
5759
vmParams.origin = p2vParams.origin;

source/MRVoxels/MRPointsToMeshFusion.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,14 @@ struct PointsToMeshParameters
1919
/// minimum sum of influence weights from surrounding points for a triangle to appear, meaning that there shall be at least this number of points in close proximity
2020
float minWeight = 1;
2121

22+
/// coefficient used for weight calculation: e^(dist^2 * -invSigmaModifier * sigma^-2)
23+
/// values: (0;inf)
24+
float invSigmaModifier = 0.5f;
25+
26+
/// changes the way point angle affects weight, by default it is linearly increasing with dot product
27+
/// if enabled - increasing as dot product^(0.5) (with respect to its sign)
28+
bool sqrtAngleWeight{ false };
29+
2230
/// Size of voxel in grid conversions;
2331
/// The user is responsible for setting some positive value here
2432
float voxelSize = 0;

0 commit comments

Comments
 (0)