Skip to content
Snippets Groups Projects
Commit 5034705f authored by Vladimír Ulman's avatar Vladimír Ulman
Browse files

Added proper triangulation of fTrees.

parent 84be467d
No related branches found
No related tags found
No related merge requests found
......@@ -400,6 +400,9 @@ int ActiveMesh::ImportVTK_Volumetric(const char *filename)
int ActiveMesh::ImportVTK_Ftree(const char *filename,bool resetMesh)
{
const int PointsOnRadiusPeriphery=10;
const float radiusCorrection=0.2f;
if (resetMesh)
{
Pos.clear();
......@@ -413,7 +416,6 @@ int ActiveMesh::ImportVTK_Ftree(const char *filename,bool resetMesh)
segFromPoint.clear();
segToPoint.clear();
segFromRadius.clear();
segToRadius.clear();
//try to open the file
std::ifstream file(filename);
......@@ -486,7 +488,6 @@ int ActiveMesh::ImportVTK_Ftree(const char *filename,bool resetMesh)
segFromPoint.reserve(itemCount);
segToPoint.reserve(itemCount);
segFromRadius.reserve(itemCount);
segToRadius.reserve(itemCount);
//read all segments vertices
int ignore,v1,v2;
......@@ -534,33 +535,117 @@ int ActiveMesh::ImportVTK_Ftree(const char *filename,bool resetMesh)
v1=0;
while (itemCount > 0 && file >> x)
{
segFromRadius.push_back(x);
if (v1 > 0) segToRadius.push_back(x);
segFromRadius.push_back(x*radiusCorrection);
--itemCount;
++v1;
}
//the tip has width 0
segToRadius.push_back(0.f);
file.close();
//now widen segments and save triangles...
//prepare "information about faces normals"
Vector3F fictiveNormal(1.f,0.f,0.f);
//temporary view of segments themselves
size_t firstRadiusPoint=Pos.size();
PointsFirstOffset=firstRadiusPoint;
//for all bending points except the last one (tip)
for (unsigned int i=0; i < segFromPoint.size(); ++i)
{
Pos.push_back(fPoints[segFromPoint[i]]);
Pos.push_back(fPoints[segFromPoint[i]]+Vector3FC(0.01f,0.01f,0.01f));
Pos.push_back(fPoints[segToPoint[i]]);
ID.push_back(Pos.size()-3);
ID.push_back(Pos.size()-2);
ID.push_back(Pos.size()-1);
//we need to construct rotation matrix that would
//rotate points on a circle which lays in the XZ plane
//(Y axis is normal to it then) such that the points
//would lay in the plane to which this new Y axis
//would be normal
//
//new Y axis
Vector3F nYaxis=fPoints[segToPoint[i]];
if (i == 0) nYaxis-=fPoints[segFromPoint[i]];
else
{
nYaxis-=fPoints[segFromPoint[i-1]];
nYaxis/=2.f; //unnecessary scaling
}
Vector3F nZaxis(0.f,1.f,0.f); //in fact it is original Yaxis _for now_
Vector3F nXaxis;
//new X axis is perpendicular to the original and new Y axis
Mul(nYaxis,nZaxis,nXaxis);
//new Z axis is perpendicular to the new X and Y axes
Mul(nYaxis,nXaxis,nZaxis);
//normalize...
nXaxis/=nXaxis.Len();
nZaxis/=nZaxis.Len();
//now render the points on the circle and project them into the scene
for (int p=0; p < PointsOnRadiusPeriphery; ++p)
{
//the point in its original position
float x=segFromRadius[i]*cosf(6.28f*float(p)/float(PointsOnRadiusPeriphery));
float z=segFromRadius[i]*sinf(6.28f*float(p)/float(PointsOnRadiusPeriphery));
//rotate
Vector3FC V(x*nXaxis);
V+=z*nZaxis;
//shift to the centre and save
V+=fPoints[segFromPoint[i]];
Pos.push_back(V);
}
}
//finally, add the tip point
Pos.push_back(fPoints[segToPoint.back()]);
//now create triangles for all segment strips
//except the last one (that leads to the tip)
for (unsigned int i=1; i < segFromPoint.size(); ++i)
{
int p=0;
for (; p < PointsOnRadiusPeriphery-1; ++p)
{
ID.push_back(firstRadiusPoint+p);
ID.push_back(firstRadiusPoint+p+1);
ID.push_back(firstRadiusPoint+p+PointsOnRadiusPeriphery);
norm.push_back(fictiveNormal);
ID.push_back(firstRadiusPoint+p+PointsOnRadiusPeriphery+1);
ID.push_back(firstRadiusPoint+p+PointsOnRadiusPeriphery);
ID.push_back(firstRadiusPoint+p+1);
norm.push_back(fictiveNormal);
}
ID.push_back(firstRadiusPoint+p);
ID.push_back(firstRadiusPoint);
ID.push_back(firstRadiusPoint+p+PointsOnRadiusPeriphery);
norm.push_back(fictiveNormal);
ID.push_back(firstRadiusPoint +PointsOnRadiusPeriphery);
ID.push_back(firstRadiusPoint+p+PointsOnRadiusPeriphery);
ID.push_back(firstRadiusPoint);
norm.push_back(fictiveNormal);
firstRadiusPoint+=PointsOnRadiusPeriphery;
}
//the last segment...
int p=0;
for (; p < PointsOnRadiusPeriphery-1; ++p)
{
ID.push_back(firstRadiusPoint+p);
ID.push_back(firstRadiusPoint+p+1);
ID.push_back(firstRadiusPoint+PointsOnRadiusPeriphery);
norm.push_back(fictiveNormal);
}
ID.push_back(firstRadiusPoint+p);
ID.push_back(firstRadiusPoint);
ID.push_back(firstRadiusPoint+PointsOnRadiusPeriphery);
norm.push_back(fictiveNormal);
return(0);
}
......@@ -754,6 +839,12 @@ void ActiveMesh::CenterMesh(const Vector3F& newCentre)
Pos[i].y-=float(y);
Pos[i].z-=float(z);
}
for (unsigned int i=0; i < fPoints.size(); ++i)
{
fPoints[i].x-=float(x);
fPoints[i].y-=float(y);
fPoints[i].z-=float(z);
}
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment