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

Added initial importing of f-tree VTK files.

parent ea664931
No related branches found
No related tags found
No related merge requests found
......@@ -397,6 +397,173 @@ int ActiveMesh::ImportVTK_Volumetric(const char *filename)
}
int ActiveMesh::ImportVTK_Ftree(const char *filename,bool resetMesh)
{
if (resetMesh)
{
Pos.clear();
ID.clear();
norm.clear();
}
//local/temporary list of vertices of segments that make up the f-tree
//later, we convert these to triangles and save these guys instead
fPoints.clear();
segFromPoint.clear();
segToPoint.clear();
segFromRadius.clear();
segToRadius.clear();
//try to open the file
std::ifstream file(filename);
if (!file.is_open()) return 1;
//read the "header" line
char tmp[1024];
file >> tmp >> tmp; //dangerous...
//check tmp for "vtk" or complain
if (tmp[0] != 'v'
|| tmp[1] != 't'
|| tmp[2] != 'k') { file.close(); return(2); }
//read (and skip) the rest of the header line
file.ignore(10240,'\n');
//ignore "vtk output"
file.ignore(10240,'\n');
//read "ASCII"
file >> tmp;
if (tmp[0] != 'A'
|| tmp[1] != 'S'
|| tmp[2] != 'C'
|| tmp[3] != 'I'
|| tmp[4] != 'I') { file.close(); return(3); }
file.ignore(10240,'\n');
//ignore "DATASET UNSTRUCTURED GRID"
file.ignore(10240,'\n');
//read points header
int itemCount;
file >> tmp >> itemCount;;
if (tmp[0] != 'P'
|| tmp[1] != 'O'
|| tmp[2] != 'I'
|| tmp[3] != 'N'
|| tmp[4] != 'T'
|| tmp[5] != 'S') { file.close(); return(4); }
file.ignore(10240,'\n');
std::cout << "reading " << itemCount << " point coordinates\n";
fPoints.reserve(itemCount);
//read all points...
float x,y,z;
while (itemCount > 0 && file >> x)
{
file >> y >> z;
//... and save them
Vector3FC v1(x,y,z);
v1*=100.f;
fPoints.push_back(v1);
--itemCount;
}
std::cout << "last coordinate was: " << x << "," << y << "," << z << "\n";
//read segments header
file >> tmp >> itemCount;
if (tmp[0] != 'C'
|| tmp[1] != 'E'
|| tmp[2] != 'L'
|| tmp[3] != 'L'
|| tmp[4] != 'S') { file.close(); return(5); }
file.ignore(10240,'\n');
std::cout << "reading " << itemCount << " segments\n";
segFromPoint.reserve(itemCount);
segToPoint.reserve(itemCount);
segFromRadius.reserve(itemCount);
segToRadius.reserve(itemCount);
//read all segments vertices
int ignore,v1,v2;
while (itemCount > 0 && file >> ignore && ignore == 2)
{
file >> v1 >> v2;
segFromPoint.push_back(v1);
segToPoint.push_back(v2);
--itemCount;
}
std::cout << "last segment was: " << v1 << "," << v2 << "\n";
//"ignore" cell types header, body
file >> tmp >> itemCount;
if (tmp[0] != 'C'
|| tmp[1] != 'E'
|| tmp[2] != 'L'
|| tmp[3] != 'L'
|| tmp[4] != '_'
|| tmp[5] != 'T'
|| tmp[6] != 'Y') { file.close(); return(6); }
file.ignore(10240,'\n');
while (itemCount > 0)
{
file.ignore(10240,'\n');
--itemCount;
}
//read radii, i.e. CELL_DATA header
file >> tmp >> itemCount;
if (tmp[0] != 'C'
|| tmp[1] != 'E'
|| tmp[2] != 'L'
|| tmp[3] != 'L'
|| tmp[4] != '_'
|| tmp[5] != 'D'
|| tmp[6] != 'A') { file.close(); return(7); }
file.ignore(10240,'\n');
file.ignore(10240,'\n'); //ignore SCALARS..
file.ignore(10240,'\n'); //ignore LOOKUP_TABLE
//read the radii
v1=0;
while (itemCount > 0 && file >> x)
{
segFromRadius.push_back(x);
if (v1 > 0) segToRadius.push_back(x);
--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
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);
norm.push_back(fictiveNormal);
}
return(0);
}
void ActiveMesh::RenderMask(i3d::Image3d<i3d::GRAY16>& mask)
{
//time savers: resolution
......
......@@ -99,6 +99,13 @@ class ActiveMesh
int ImportVTK(const char* filename);
int ImportVTK_Volumetric(const char* filename);
int ImportVTK_Ftree(const char* filename,bool resetMesh=false);
std::vector<Vector3FC> fPoints;
std::vector<int> segFromPoint; //segment description, quite ugly solution for now
std::vector<int> segToPoint;
std::vector<float> segFromRadius;
std::vector<float> segToRadius;
void RenderMask(i3d::Image3d<i3d::GRAY16>& mask);
void RenderMaskB(i3d::Image3d<i3d::GRAY16>& mask);
......
......@@ -32,6 +32,14 @@ int main(void)
return(1);
}
retval=mesh.ImportVTK_Ftree("../sample_input/ID1_t001_fTree01.vtk");
retval=mesh.ImportVTK_Ftree("../sample_input/ID1_t001_fTree02.vtk");
if (retval)
{
std::cout << "some error reading f-tree: " << retval << "\n";
return(2);
}
std::cout << "mesh: " << filename << "\n";
std::cout << "vertices #: " << mesh.Pos.size() << "\n";
std::cout << "triangles #: " << mesh.ID.size()/3 << "\n";
......
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