Replaced other tabs by spaces... should be clear now
This commit is contained in:
parent
83f1b71240
commit
3ee36c9282
|
@ -218,51 +218,51 @@ genPaths(
|
|||
void AnimatedMesh::associateBranches(std::vector<geo::Segment<float,3>> const& segments, geo::Mesh& mesh)
|
||||
{
|
||||
// stock each point at the index corresponding to the nearest segment
|
||||
for(unsigned int i=0;i<mesh.vertices.size();i++)
|
||||
{
|
||||
geo::Point<float> p = geo::Point<float>{i,mesh.vertices[i]};
|
||||
associatedSegment.push_back(findNearestSegment(segments, p));
|
||||
}
|
||||
for(unsigned int i=0;i<mesh.vertices.size();i++)
|
||||
{
|
||||
geo::Point<float> p = geo::Point<float>{i,mesh.vertices[i]};
|
||||
associatedSegment.push_back(findNearestSegment(segments, p));
|
||||
}
|
||||
}
|
||||
|
||||
//finds the nearest segment to a point
|
||||
unsigned int AnimatedMesh::findNearestSegment(std::vector<geo::Segment<float,3>> const& segments, geo::Point<float> const& p)
|
||||
{
|
||||
unsigned int nearestSegment = 0;
|
||||
float shortest_distance = std::numeric_limits<float>::max();
|
||||
for(unsigned int i=0;i<segments.size();i++)
|
||||
{
|
||||
// find distance between point and segment
|
||||
float distance = geo::distanceToSegment(p.second, segments[i].first, segments[i].second);
|
||||
if (shortest_distance > distance)
|
||||
{
|
||||
shortest_distance = distance;
|
||||
nearestSegment = i;
|
||||
}
|
||||
}
|
||||
return nearestSegment;
|
||||
unsigned int nearestSegment = 0;
|
||||
float shortest_distance = std::numeric_limits<float>::max();
|
||||
for(unsigned int i=0;i<segments.size();i++)
|
||||
{
|
||||
// find distance between point and segment
|
||||
float distance = geo::distanceToSegment(p.second, segments[i].first, segments[i].second);
|
||||
if (shortest_distance > distance)
|
||||
{
|
||||
shortest_distance = distance;
|
||||
nearestSegment = i;
|
||||
}
|
||||
}
|
||||
return nearestSegment;
|
||||
}
|
||||
|
||||
void AnimatedMesh::findFaces(std::vector<unsigned int> const& associatedSegments, geo::Mesh& mesh, unsigned int nbSegments)
|
||||
{
|
||||
for (unsigned int i=0;i<nbSegments+1;i++)
|
||||
{
|
||||
facesPerSegment.push_back(std::vector<geo::Vector3<unsigned int>>{});
|
||||
}
|
||||
for (unsigned int i=0;i<nbSegments+1;i++)
|
||||
{
|
||||
facesPerSegment.push_back(std::vector<geo::Vector3<unsigned int>>{});
|
||||
}
|
||||
|
||||
unsigned int segment;
|
||||
for(unsigned int i=0;i<mesh.faces.size();i++)
|
||||
{
|
||||
segment = associatedSegments[mesh.faces[i].x()];
|
||||
if ((segment == associatedSegments[mesh.faces[i].y()]) && (segment == associatedSegments[mesh.faces[i].z()]))
|
||||
{
|
||||
facesPerSegment[segment].push_back(mesh.faces[i]);
|
||||
}
|
||||
else
|
||||
{
|
||||
facesPerSegment[nbSegments].push_back(mesh.faces[i]);
|
||||
}
|
||||
}
|
||||
unsigned int segment;
|
||||
for(unsigned int i=0;i<mesh.faces.size();i++)
|
||||
{
|
||||
segment = associatedSegments[mesh.faces[i].x()];
|
||||
if ((segment == associatedSegments[mesh.faces[i].y()]) && (segment == associatedSegments[mesh.faces[i].z()]))
|
||||
{
|
||||
facesPerSegment[segment].push_back(mesh.faces[i]);
|
||||
}
|
||||
else
|
||||
{
|
||||
facesPerSegment[nbSegments].push_back(mesh.faces[i]);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
|
|
@ -621,21 +621,21 @@ void Skeleton3D::meshExtremity(geo::Mesh& mesh, std::vector<std::vector<geo::Cir
|
|||
|
||||
if (profondeur==0)
|
||||
{
|
||||
mesh.vertices.push_back(intersection);
|
||||
for (unsigned int i=0;i<extremCircle.points.size();i++)
|
||||
{
|
||||
mesh.vertices.push_back(intersection);
|
||||
for (unsigned int i=0;i<extremCircle.points.size();i++)
|
||||
{
|
||||
auto ip1 = extremCircle.points[i].first;
|
||||
if (i==extremCircle.points.size()-1)
|
||||
{
|
||||
if (i==extremCircle.points.size()-1)
|
||||
{
|
||||
auto ip2 = extremCircle.points[0].first;
|
||||
mesh.faces.push_back(sortedIndexes(ip1,intersectionIndex,ip2,extremity.second));
|
||||
}
|
||||
else
|
||||
{
|
||||
auto ip2 = extremCircle.points[i+1].first;
|
||||
}
|
||||
else
|
||||
{
|
||||
auto ip2 = extremCircle.points[i+1].first;
|
||||
mesh.faces.push_back(sortedIndexes(ip1,intersectionIndex,ip2,extremity.second));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -648,13 +648,13 @@ void Skeleton3D::subdivision(geo::Mesh& mesh, unsigned int profondeur, geo::Circ
|
|||
std::vector<std::vector<geo::Vector3f>> arcs;
|
||||
for (unsigned int i=0;i<extremCircle.points.size();i++)
|
||||
{
|
||||
// compute the points build by subdivision on one arc (between a point on the extrem
|
||||
// circle and the extremity)
|
||||
// compute the points build by subdivision on one arc (between a point on the extrem
|
||||
// circle and the extremity)
|
||||
std::vector<geo::Vector3f> arc;
|
||||
arc.push_back(intersection);
|
||||
arcSubdivise(intersection, extremCircle.points[i].second, profondeur, arc, center, radius);
|
||||
arc.push_back(extremCircle.points[i].second);
|
||||
arcs.push_back(arc);
|
||||
arc.push_back(intersection);
|
||||
arcSubdivise(intersection, extremCircle.points[i].second, profondeur, arc, center, radius);
|
||||
arc.push_back(extremCircle.points[i].second);
|
||||
arcs.push_back(arc);
|
||||
}
|
||||
|
||||
// Compute the mesh
|
||||
|
@ -670,39 +670,39 @@ void Skeleton3D::subdivision(geo::Mesh& mesh, unsigned int profondeur, geo::Circ
|
|||
// push all the new vertices
|
||||
for (unsigned int i=0;i<arcs.size();i++)
|
||||
{
|
||||
for (unsigned int j=1;j<arcs[i].size()-1;j++)
|
||||
{
|
||||
mesh.vertices.push_back(arcs[i][j]);
|
||||
}
|
||||
for (unsigned int j=1;j<arcs[i].size()-1;j++)
|
||||
{
|
||||
mesh.vertices.push_back(arcs[i][j]);
|
||||
}
|
||||
}
|
||||
|
||||
//push the faces
|
||||
for (unsigned int i=0;i<arcs.size()-1;i++)
|
||||
{
|
||||
auto courant = arcs[i];
|
||||
auto courant = arcs[i];
|
||||
|
||||
for (unsigned int j=0;j<courant.size()-2;j++)
|
||||
{
|
||||
if (j==0)
|
||||
{
|
||||
for (unsigned int j=0;j<courant.size()-2;j++)
|
||||
{
|
||||
if (j==0)
|
||||
{
|
||||
mesh.faces.push_back(sortedIndexes(intersectionIndex, indexVertices + 1 + nbPoints, indexVertices + 1,t));
|
||||
}
|
||||
else
|
||||
{
|
||||
}
|
||||
else
|
||||
{
|
||||
mesh.faces.push_back(sortedIndexes(indexVertices + j, indexVertices + j + 1 + nbPoints, indexVertices + j + 1, t));
|
||||
mesh.faces.push_back(sortedIndexes(indexVertices + j, indexVertices + j + nbPoints, indexVertices + j + 1 + nbPoints, t));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// before last point
|
||||
unsigned int i1 = extremCircle.points[i].first;
|
||||
unsigned int i2 = extremCircle.points[i+1].first;
|
||||
// before last point
|
||||
unsigned int i1 = extremCircle.points[i].first;
|
||||
unsigned int i2 = extremCircle.points[i+1].first;
|
||||
|
||||
mesh.faces.push_back(sortedIndexes(indexVertices + nbPoints, i2, i1, t));
|
||||
mesh.faces.push_back(sortedIndexes(indexVertices + nbPoints , indexVertices + 2*nbPoints , i2, t));
|
||||
mesh.faces.push_back(sortedIndexes(indexVertices + nbPoints , indexVertices + 2*nbPoints , i2, t));
|
||||
|
||||
// increment the indexVertices
|
||||
indexVertices += nbPoints;
|
||||
indexVertices += nbPoints;
|
||||
|
||||
}
|
||||
|
||||
|
@ -750,15 +750,15 @@ void Skeleton3D::arcSubdivise(geo::Vector3f pt1, geo::Vector3f pt2, unsigned int
|
|||
// compute middle of arc
|
||||
geo::Vector3f middleSegment;
|
||||
middleSegment = (pt1+pt2)/2;
|
||||
// projection on the sphere
|
||||
// projection on the sphere
|
||||
geo::Vector3f direction = (middleSegment - center);
|
||||
direction /= direction.norm();
|
||||
direction *= radius;
|
||||
geo::Vector3f middle = center + direction;
|
||||
|
||||
arcSubdivise(pt1, middle, profondeur-1, arc, center, radius);
|
||||
arc.push_back(middle);
|
||||
arcSubdivise(middle, pt2, profondeur-1, arc, center, radius);
|
||||
arc.push_back(middle);
|
||||
arcSubdivise(middle, pt2, profondeur-1, arc, center, radius);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue