forked from cnr-isti-vclab/vcglib
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add generalized winding number computation for meshToVolume conversion
- Loading branch information
Showing
4 changed files
with
190 additions
and
43 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
#ifndef WINDING_NUMBER_CPP | ||
#define WINDING_NUMBER_CPP | ||
|
||
#include <UT_SolidAngle.h> | ||
#include <vcg/complex/complex.h> | ||
|
||
template<class TRI_MESH_TYPE> | ||
class WindingNumber { | ||
typedef TRI_MESH_TYPE MeshType; | ||
typedef typename MeshType::FaceType FaceType; | ||
typedef typename FaceType::VertexType VertexType; | ||
typedef typename VertexType::ScalarType ScalarType; | ||
|
||
private: | ||
HDK_Sample::UT_SolidAngle<float,float> solid_angle; // Only works with float | ||
|
||
public: | ||
void init(MeshType &m, int order = 2) | ||
{ | ||
// Initialize vector of vertex positions | ||
std::vector<HDK_Sample::UT_Vector3T<float>> U(m.vert.size()); | ||
for(int i = 0; i < m.vert.size(); i++) | ||
{ | ||
for(int j = 0;j<3;j++) | ||
{ | ||
U[i][j] = m.vert[i].P()[j]; | ||
} | ||
} | ||
|
||
// Initialize vector of triangle indices | ||
std::vector<int> mTriIndex(m.face.size() * 3); | ||
for(int i = 0; i < m.face.size(); i++) | ||
{ | ||
for(int j = 0;j<3;j++) | ||
{ | ||
mTriIndex[i*3+j] = vcg::tri::Index(m, m.face[i].V(j)); | ||
} | ||
} | ||
|
||
solid_angle.init(m.face.size(), mTriIndex.data(), m.vert.size(), &U[0], order); | ||
} | ||
|
||
ScalarType computeWindingNumber(std::vector<ScalarType> coordV, double accuracy_scale = 2.0){ | ||
auto pt = HDK_Sample::UT_Vector3T<float>(coordV.data()); | ||
return solid_angle.computeSolidAngle(pt, accuracy_scale) / (4.0 * M_PI); | ||
} | ||
}; | ||
|
||
#endif |