57 vtkDataObject* doOutput)
60 vtkDebugMacro(<<
"Reading FDNEUT file...");
62 vtkUnstructuredGrid* output = vtkUnstructuredGrid::SafeDownCast(doOutput);
66 vtkErrorMacro(<<
"Input filename not set");
71 FDNEUTFile = fopen(fname.c_str(),
"r");
75 vtkErrorMacro(<<
"Unable to open " << fname <<
" for reading");
83 ret = fscanf(FDNEUTFile,
"%s", buffer);
84 while (fgetc(FDNEUTFile) !=
'\n');
86 while (strncmp(buffer,
"NODAL",5)!=0);
90 float point[3], doublePoint[3];
92 vtkPoints* points = vtkPoints::New();
94 while(fscanf(FDNEUTFile,
"%d", &pointId))
96 ret = fscanf(FDNEUTFile,
"%f", &point[0]);
97 ret = fscanf(FDNEUTFile,
"%f", &point[1]);
98 ret = fscanf(FDNEUTFile,
"%f", &point[2]);
99 while (fgetc(FDNEUTFile) !=
'\n');
101 doublePoint[0] = point[0];
102 doublePoint[1] = point[1];
103 doublePoint[2] = point[2];
105 points->InsertPoint(pointId-1,doublePoint);
109 int nodesPerElement, geometry, fdneutType;
111 vtkCellArray* gridCellArray = vtkCellArray::New();
113 int entityCounter = 0;
114 vtkUnsignedCharArray* singleEntityArray;
115 singleEntityArray = vtkUnsignedCharArray::New();
117 output->GetCellData()->AddArray(singleEntityArray);
119 vtkIntArray* typesArray = vtkIntArray::New();
120 while (fscanf(FDNEUTFile,
"%s", buffer)!=EOF)
122 while (strncmp(buffer,
"NODES:",6)!=0)
123 ret = fscanf(FDNEUTFile,
"%s", buffer);
124 ret = fscanf(FDNEUTFile,
"%d", &nodesPerElement);
125 while (strncmp(buffer,
"GEOMETRY:",9)!=0)
126 ret = fscanf(FDNEUTFile,
"%s", buffer);
127 ret = fscanf(FDNEUTFile,
"%d", &geometry);
128 while (strncmp(buffer,
"TYPE:",5)!=0)
129 ret = fscanf(FDNEUTFile,
"%s", buffer);
130 ret = fscanf(FDNEUTFile,
"%d", &fdneutType);
132 while (fgetc(FDNEUTFile) !=
'\n');
133 ret = fscanf(FDNEUTFile,
"%s", buffer);
134 ret = fscanf(FDNEUTFile,
"%s", buffer);
136 char currentEntityName[256];
137 ret = fscanf(FDNEUTFile,
"%s", currentEntityName);
138 while (fgetc(FDNEUTFile) !=
'\n');
142 vtkIdType numberOfCellPoints = 0;
144 vtkUnsignedCharArray* entityArray = NULL;
145 entityArray = vtkUnsignedCharArray::New();
146 entityArray->SetName(currentEntityName);
147 output->GetCellData()->AddArray(entityArray);
149 while(fscanf(FDNEUTFile,
"%d", &cellId)>0)
151 int* cellPoints = NULL;
152 bool invalid =
false;
160 if (nodesPerElement==4)
163 numberOfCellPoints = this->
GhostNodes ? nodesPerElement : 4;
164 cellPoints =
new int[numberOfCellPoints];
165 for (i=0; i<nodesPerElement; i++)
167 ret = fscanf(FDNEUTFile,
"%d", &cellPoints[i]);
170 else if ((nodesPerElement==8) || (nodesPerElement==9))
172 type = VTK_QUADRATIC_QUAD;
173 numberOfCellPoints = this->
GhostNodes ? nodesPerElement : 8;
174 cellPoints =
new int[numberOfCellPoints];
175 ret = fscanf(FDNEUTFile,
"%d", &cellPoints[0]);
176 ret = fscanf(FDNEUTFile,
"%d", &cellPoints[4]);
177 ret = fscanf(FDNEUTFile,
"%d", &cellPoints[1]);
178 ret = fscanf(FDNEUTFile,
"%d", &cellPoints[5]);
179 ret = fscanf(FDNEUTFile,
"%d", &cellPoints[2]);
180 ret = fscanf(FDNEUTFile,
"%d", &cellPoints[6]);
181 ret = fscanf(FDNEUTFile,
"%d", &cellPoints[3]);
182 ret = fscanf(FDNEUTFile,
"%d", &cellPoints[7]);
183 if (nodesPerElement==9)
187 ret = fscanf(FDNEUTFile,
"%d",&cellPoints[8]);
191 ret = fscanf(FDNEUTFile,
"%d",&pointBuffer);
201 if (nodesPerElement==3)
204 numberOfCellPoints = this->
GhostNodes ? nodesPerElement : 3;
205 cellPoints =
new int[numberOfCellPoints];
206 for (i=0; i<nodesPerElement; i++)
208 ret = fscanf(FDNEUTFile,
"%d", &cellPoints[i]);
211 else if ((nodesPerElement==6) || (nodesPerElement==7))
213 type = VTK_QUADRATIC_TRIANGLE;
214 numberOfCellPoints = this->
GhostNodes ? nodesPerElement : 6;
215 cellPoints =
new int[numberOfCellPoints];
216 ret = fscanf(FDNEUTFile,
"%d", &cellPoints[0]);
217 ret = fscanf(FDNEUTFile,
"%d", &cellPoints[3]);
218 ret = fscanf(FDNEUTFile,
"%d", &cellPoints[1]);
219 ret = fscanf(FDNEUTFile,
"%d", &cellPoints[4]);
220 ret = fscanf(FDNEUTFile,
"%d", &cellPoints[2]);
221 ret = fscanf(FDNEUTFile,
"%d", &cellPoints[5]);
223 if (nodesPerElement==7)
227 ret = fscanf(FDNEUTFile,
"%d",&cellPoints[6]);
231 ret = fscanf(FDNEUTFile,
"%d",&pointBuffer);
237 if (nodesPerElement==8)
239 type = VTK_HEXAHEDRON;
240 numberOfCellPoints = this->
GhostNodes ? nodesPerElement : 8;
241 cellPoints =
new int[numberOfCellPoints];
242 ret = fscanf(FDNEUTFile,
"%d", &cellPoints[0]);
243 ret = fscanf(FDNEUTFile,
"%d", &cellPoints[1]);
244 ret = fscanf(FDNEUTFile,
"%d", &cellPoints[3]);
245 ret = fscanf(FDNEUTFile,
"%d", &cellPoints[2]);
246 ret = fscanf(FDNEUTFile,
"%d", &cellPoints[4]);
247 ret = fscanf(FDNEUTFile,
"%d", &cellPoints[5]);
248 ret = fscanf(FDNEUTFile,
"%d", &cellPoints[7]);
249 ret = fscanf(FDNEUTFile,
"%d", &cellPoints[6]);
251 else if (nodesPerElement==27)
253 type = VTK_QUADRATIC_HEXAHEDRON;
254 numberOfCellPoints = this->
GhostNodes ? nodesPerElement : 20;
255 cellPoints =
new int[numberOfCellPoints];
256 ret = fscanf(FDNEUTFile,
"%d", &cellPoints[0]);
257 ret = fscanf(FDNEUTFile,
"%d", &cellPoints[8]);
258 ret = fscanf(FDNEUTFile,
"%d", &cellPoints[1]);
260 ret = fscanf(FDNEUTFile,
"%d", &cellPoints[11]);
263 ret = fscanf(FDNEUTFile,
"%d", &cellPoints[24]);
267 ret = fscanf(FDNEUTFile,
"%d", &pointBuffer);
269 ret = fscanf(FDNEUTFile,
"%d", &cellPoints[9]);
271 ret = fscanf(FDNEUTFile,
"%d", &cellPoints[3]);
272 ret = fscanf(FDNEUTFile,
"%d", &cellPoints[10]);
273 ret = fscanf(FDNEUTFile,
"%d", &cellPoints[2]);
275 ret = fscanf(FDNEUTFile,
"%d", &cellPoints[16]);
278 ret = fscanf(FDNEUTFile,
"%d", &cellPoints[20]);
282 ret = fscanf(FDNEUTFile,
"%d", &pointBuffer);
284 ret = fscanf(FDNEUTFile,
"%d", &cellPoints[17]);
288 ret = fscanf(FDNEUTFile,
"%d", &cellPoints[23]);
289 ret = fscanf(FDNEUTFile,
"%d", &cellPoints[26]);
290 ret = fscanf(FDNEUTFile,
"%d", &cellPoints[21]);
294 ret = fscanf(FDNEUTFile,
"%d", &pointBuffer);
295 ret = fscanf(FDNEUTFile,
"%d", &pointBuffer);
296 ret = fscanf(FDNEUTFile,
"%d", &pointBuffer);
299 ret = fscanf(FDNEUTFile,
"%d",&cellPoints[19]);
302 ret = fscanf(FDNEUTFile,
"%d", &cellPoints[22]);
306 ret = fscanf(FDNEUTFile,
"%d", &pointBuffer);
308 ret = fscanf(FDNEUTFile,
"%d",&cellPoints[18]);
310 ret = fscanf(FDNEUTFile,
"%d",&cellPoints[4]);
311 ret = fscanf(FDNEUTFile,
"%d",&cellPoints[12]);
312 ret = fscanf(FDNEUTFile,
"%d",&cellPoints[5]);
314 ret = fscanf(FDNEUTFile,
"%d",&cellPoints[15]);
317 ret = fscanf(FDNEUTFile,
"%d", &cellPoints[25]);
321 ret = fscanf(FDNEUTFile,
"%d", &pointBuffer);
323 ret = fscanf(FDNEUTFile,
"%d",&cellPoints[13]);
325 ret = fscanf(FDNEUTFile,
"%d",&cellPoints[7]);
326 ret = fscanf(FDNEUTFile,
"%d",&cellPoints[14]);
327 ret = fscanf(FDNEUTFile,
"%d",&cellPoints[6]);
331 if (nodesPerElement==4)
334 numberOfCellPoints = this->
GhostNodes ? nodesPerElement : 4;
335 cellPoints =
new int[numberOfCellPoints];
336 for (i=0; i<nodesPerElement; i++)
338 ret = fscanf(FDNEUTFile,
"%d", &cellPoints[i]);
341 else if (nodesPerElement==10)
343 type = VTK_QUADRATIC_TETRA;
344 numberOfCellPoints = this->
GhostNodes ? nodesPerElement : 10;
345 cellPoints =
new int[numberOfCellPoints];
346 ret = fscanf(FDNEUTFile,
"%d", &cellPoints[0]);
347 ret = fscanf(FDNEUTFile,
"%d", &cellPoints[4]);
348 ret = fscanf(FDNEUTFile,
"%d", &cellPoints[1]);
349 ret = fscanf(FDNEUTFile,
"%d", &cellPoints[6]);
350 ret = fscanf(FDNEUTFile,
"%d", &cellPoints[5]);
351 ret = fscanf(FDNEUTFile,
"%d", &cellPoints[2]);
352 ret = fscanf(FDNEUTFile,
"%d", &cellPoints[7]);
353 ret = fscanf(FDNEUTFile,
"%d", &cellPoints[8]);
354 ret = fscanf(FDNEUTFile,
"%d", &cellPoints[9]);
355 ret = fscanf(FDNEUTFile,
"%d", &cellPoints[3]);
359 if (nodesPerElement==6)
362 numberOfCellPoints = this->
GhostNodes ? nodesPerElement : 6;
363 cellPoints =
new int[numberOfCellPoints];
364 for (i=0; i<nodesPerElement; i++)
366 ret = fscanf(FDNEUTFile,
"%d", &cellPoints[i]);
369 else if (nodesPerElement==18)
371 type = VTK_QUADRATIC_WEDGE;
372 numberOfCellPoints = this->
GhostNodes ? nodesPerElement : 15;
373 cellPoints =
new int[numberOfCellPoints];
374 ret = fscanf(FDNEUTFile,
"%d", &cellPoints[0]);
375 ret = fscanf(FDNEUTFile,
"%d", &cellPoints[6]);
376 ret = fscanf(FDNEUTFile,
"%d", &cellPoints[1]);
378 ret = fscanf(FDNEUTFile,
"%d", &cellPoints[8]);
379 ret = fscanf(FDNEUTFile,
"%d", &cellPoints[7]);
380 ret = fscanf(FDNEUTFile,
"%d", &cellPoints[2]);
382 ret = fscanf(FDNEUTFile,
"%d", &cellPoints[12]);
385 ret = fscanf(FDNEUTFile,
"%d", &cellPoints[15]);
389 ret = fscanf(FDNEUTFile,
"%d", &pointBuffer);
391 ret = fscanf(FDNEUTFile,
"%d", &cellPoints[13]);
395 ret = fscanf(FDNEUTFile,
"%d", &cellPoints[16]);
396 ret = fscanf(FDNEUTFile,
"%d", &cellPoints[17]);
400 ret = fscanf(FDNEUTFile,
"%d", &pointBuffer);
401 ret = fscanf(FDNEUTFile,
"%d", &pointBuffer);
403 ret = fscanf(FDNEUTFile,
"%d", &cellPoints[14]);
405 ret = fscanf(FDNEUTFile,
"%d", &cellPoints[3]);
406 ret = fscanf(FDNEUTFile,
"%d", &cellPoints[9]);
407 ret = fscanf(FDNEUTFile,
"%d", &cellPoints[4]);
409 ret = fscanf(FDNEUTFile,
"%d",&cellPoints[11]);
410 ret = fscanf(FDNEUTFile,
"%d",&cellPoints[10]);
411 ret = fscanf(FDNEUTFile,
"%d",&cellPoints[5]);
413 else if (nodesPerElement==15)
415 type = VTK_QUADRATIC_WEDGE;
416 numberOfCellPoints = this->
GhostNodes ? nodesPerElement : 15;
417 cellPoints =
new int[numberOfCellPoints];
418 ret = fscanf(FDNEUTFile,
"%d", &cellPoints[0]);
419 ret = fscanf(FDNEUTFile,
"%d", &cellPoints[6]);
420 ret = fscanf(FDNEUTFile,
"%d", &cellPoints[1]);
422 ret = fscanf(FDNEUTFile,
"%d", &cellPoints[8]);
423 ret = fscanf(FDNEUTFile,
"%d", &cellPoints[7]);
424 ret = fscanf(FDNEUTFile,
"%d", &cellPoints[2]);
426 ret = fscanf(FDNEUTFile,
"%d", &cellPoints[12]);
427 ret = fscanf(FDNEUTFile,
"%d", &cellPoints[13]);
428 ret = fscanf(FDNEUTFile,
"%d", &cellPoints[14]);
430 ret = fscanf(FDNEUTFile,
"%d", &cellPoints[3]);
431 ret = fscanf(FDNEUTFile,
"%d", &cellPoints[9]);
432 ret = fscanf(FDNEUTFile,
"%d", &cellPoints[4]);
434 ret = fscanf(FDNEUTFile,
"%d",&cellPoints[11]);
435 ret = fscanf(FDNEUTFile,
"%d",&cellPoints[10]);
436 ret = fscanf(FDNEUTFile,
"%d",&cellPoints[5]);
443 entityArray->InsertValue(gridCellArray->GetNumberOfCells()-1,1);
447 typesArray->InsertNextValue(type);
449 vtkIdType* cellPointsIdType =
new vtkIdType[numberOfCellPoints];
450 for (
int i=0; i<numberOfCellPoints; i++)
452 cellPointsIdType[i] = cellPoints[i];
454 gridCellArray->InsertNextCell(numberOfCellPoints,cellPointsIdType);
455 delete[] cellPointsIdType;
456 singleEntityArray->InsertNextValue(entityCounter);
461 entityArray->Delete();
466 singleEntityArray->Delete();
470 output->SetPoints(points);
471 output->SetCells(typesArray->GetPointer(0),gridCellArray);
474 typesArray->Delete();
475 gridCellArray->Delete();