Commit e5f5cb0a authored by promayon's avatar promayon
Browse files

FIXED off component on gcc (+ safer file reading)


git-svn-id: svn+ssh://scm.forge.imag.fr/var/lib/gforge/chroot/scmrepos/svn/camitk/trunk/camitk@514 ec899d31-69d1-42ba-9299-647d76f65fb3
parent 4f26aa4c
......@@ -57,66 +57,66 @@ OffComponent::OffComponent(const QString & file) throw(AbortException) : MeshCom
// use the file name without extension as component name
setName(QFileInfo(file).baseName());
vtkPolyData* offMesh = vtkPolyData::New();
vtkPoints *points = vtkPoints::New();
vtkCellArray *polys = vtkCellArray::New();
vtkPolyData* offMesh = vtkPolyData::New();
vtkPoints *points = vtkPoints::New();
vtkCellArray *polys = vtkCellArray::New();
std::ifstream inputFile(file.toStdString().c_str(), std::ios::in);
std::string line;
std::ifstream inputFile(file.toStdString().c_str(), std::ios::in);
std::string line;
// pass the comments and the first line
while (std::getline(inputFile, line)) {
if (!line.compare("#")||!line.compare("OFF"))
break;
// pass the comments and the first line
while (!std::getline(inputFile, line).eof() && line.at(0)=='#' && line.compare("OFF")!=0) {
}
//read the numbers of vertices and of cells
int nbVertex = 0;
int nbPolygon = 0;
vtkIdType countVertex = 0;
double pt[3];
//read the numbers of vertices and of cells
int nbVertex = 0;
int nbPolygon = 0;
vtkIdType countVertex = 0;
double pt[3];
std::getline(inputFile, line);
std::istringstream stream(line, std::istringstream::in);
stream >> nbVertex;
stream >> nbPolygon;
nbElements = nbPolygon;
nbPoints = nbVertex;
while(countVertex<nbPoints){
getline(inputFile, line);
std::istringstream stream(line, std::istringstream::in);
if (line.compare("#")!=0){
for (int i = 0; i < 3; i++)
stream >> pt[i];
points->InsertPoint(countVertex,pt[0],pt[1],pt[2]); // insert point
++countVertex;
}
}
offMesh->SetPoints(points);
//read connectivity
vtkIdType eltType = 0;
vtkIdType pts[3];
int elemCount = 0;
while (elemCount<nbElements) {
std::getline(inputFile, line);
std::istringstream stream(line, std::istringstream::in);
if (line.compare("#")!=0){
stream >> eltType; // the first character is the number of points of the element
for (int i = 0; i < eltType; i++)
stream >> pts[i]; // points coordinates
polys->InsertNextCell(eltType,pts); // add the element to the vtkCellArray
++elemCount;
}
}
offMesh->SetPolys(polys);
std::istringstream stream(line, std::istringstream::in);
stream >> nbVertex;
stream >> nbPolygon;
nbElements = nbPolygon;
nbPoints = nbVertex;
while(!std::getline(inputFile, line).eof() && countVertex<nbPoints) {
std::istringstream stream(line, std::istringstream::in);
if (line.compare("#")!=0) {
for (int i = 0; i < 3; i++)
stream >> pt[i];
points->InsertPoint(countVertex,pt[0],pt[1],pt[2]); // insert point
++countVertex;
}
}
offMesh->SetPoints(points);
//read connectivity
vtkIdType eltType = 0;
vtkIdType pts[3];
int elemCount = 0;
while (!std::getline(inputFile, line).eof() && elemCount<nbElements) {
std::istringstream stream(line, std::istringstream::in);
if (line.compare("#")!=0) {
stream >> eltType; // the first character is the number of points of the element
for (int i = 0; i < eltType; i++)
stream >> pts[i]; // points coordinates
polys->InsertNextCell(eltType,pts); // add the element to the vtkCellArray
++elemCount;
}
}
offMesh->SetPolys(polys);
offMesh->Update();
// instanciate the Geometry
......@@ -124,7 +124,7 @@ OffComponent::OffComponent(const QString & file) throw(AbortException) : MeshCom
// add the represention in the 3D viewer
setVisibility(InteractiveViewer::get3DViewer(), true);
// initialize the dynamic properties
//initDynamicProperties();
}
......@@ -137,31 +137,32 @@ void OffComponent::initDynamicProperties() {
vtkSmartPointer<vtkUnsignedCharArray> types = mesh->GetCellTypesArray();
std::map<unsigned char, int> elementsMap;
std::map<unsigned char, int>::iterator elementsMapIt;
for (int i=0; i<types->GetNumberOfTuples(); i++) {
if (!elementsMap.count(types->GetValue(i)))
elementsMap[types->GetValue(i)] = 0;
elementsMap[types->GetValue(i)]++;
if (!elementsMap.count(types->GetValue(i)))
elementsMap[types->GetValue(i)] = 0;
elementsMap[types->GetValue(i)]++;
}
for (elementsMapIt = elementsMap.begin(); elementsMapIt != elementsMap.end(); elementsMapIt++) {
switch(elementsMapIt->first) {
case VTK_TETRA :
setProperty("Tetra", elementsMapIt->second);
break;
case VTK_HEXAHEDRON :
setProperty("Hexa", elementsMapIt->second);
break;
case VTK_WEDGE :
setProperty("Prism", elementsMapIt->second);
break;
case VTK_PYRAMID :
setProperty("Pyramid", elementsMapIt->second);
break;
default :
setProperty("Prob", elementsMapIt->second);
break;
}
switch(elementsMapIt->first) {
case VTK_TETRA :
setProperty("Tetra", elementsMapIt->second);
break;
case VTK_HEXAHEDRON :
setProperty("Hexa", elementsMapIt->second);
break;
case VTK_WEDGE :
setProperty("Prism", elementsMapIt->second);
break;
case VTK_PYRAMID :
setProperty("Pyramid", elementsMapIt->second);
break;
default :
setProperty("Prob", elementsMapIt->second);
break;
}
}
}
......
# A simple mesh to test off component
OFF
3368 6732 0
42.4023 -14.3938 -48.4343
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment