#include <vtkio.h>


VTK is a file format used by the Visual Toolkit. (http://public.kitware.com/VTK/)
There are 2 VTK formats: ASCII or Binary.
ASCII format It has 5 parts:
Binary format It has the same 5 parts like ASCII format,followed by data in binary format. The data are stored in big endian by default..
A VTK file contains 1 2D or 3D image.
Definition at line 76 of file vtkio.h.
enum EMAN::VtkIO::VtkType [private] |
Definition at line 88 of file vtkio.h.
00089 { 00090 VTK_UNKNOWN, 00091 VTK_ASCII, 00092 VTK_BINARY 00093 };
enum EMAN::VtkIO::DataType [private] |
| DATATYPE_UNKNOWN | |
| BIT | |
| UNSIGNED_CHAR | |
| CHAR | |
| UNSIGNED_SHORT | |
| SHORT | |
| UNSIGNED_INT | |
| INT | |
| UNSIGNED_LONG | |
| LONG | |
| FLOAT | |
| DOUBLE |
Definition at line 95 of file vtkio.h.
00096 { 00097 DATATYPE_UNKNOWN, 00098 BIT, 00099 UNSIGNED_CHAR, 00100 CHAR, 00101 UNSIGNED_SHORT, 00102 SHORT, 00103 UNSIGNED_INT, 00104 INT, 00105 UNSIGNED_LONG, 00106 LONG, 00107 FLOAT, 00108 DOUBLE 00109 };
enum EMAN::VtkIO::DatasetType [private] |
| DATASET_UNKNOWN | |
| STRUCTURED_POINTS | |
| STRUCTURED_GRID | |
| RECTILINEAR_GRID | |
| UNSTRUCTURED_GRID | |
| POLYDATA |
Definition at line 111 of file vtkio.h.
00112 { 00113 DATASET_UNKNOWN, 00114 STRUCTURED_POINTS, 00115 STRUCTURED_GRID, 00116 RECTILINEAR_GRID, 00117 UNSTRUCTURED_GRID, 00118 POLYDATA 00119 };
| EMAN::VtkIO::VtkIO | ( | const string & | filename, | |
| IOMode | rw_mode = READ_ONLY | |||
| ) | [explicit] |
| VtkIO::~VtkIO | ( | ) |
| bool VtkIO::is_valid | ( | const void * | first_block | ) | [static] |
Definition at line 164 of file vtkio.cpp.
References EMAN::Util::check_file_by_magic(), ENTERFUNC, EXITFUNC, and MAGIC.
Referenced by EMAN::EMUtil::fast_get_image_type(), and EMAN::EMUtil::get_image_type().
00165 { 00166 ENTERFUNC; 00167 bool result = false; 00168 if (first_block) { 00169 result = Util::check_file_by_magic(first_block, MAGIC); 00170 } 00171 EXITFUNC; 00172 return result; 00173 }
| int VtkIO::to_em_datatype | ( | int | vtk_datatype | ) | [private] |
Definition at line 345 of file vtkio.cpp.
References EMAN::EMUtil::EM_FLOAT, EMAN::EMUtil::EM_UNKNOWN, EMAN::EMUtil::EM_USHORT, FLOAT, and UNSIGNED_SHORT.
00346 { 00347 DataType d = static_cast < DataType > (vtk_datatype); 00348 switch (d) { 00349 case UNSIGNED_SHORT: 00350 return EMUtil::EM_USHORT; 00351 case FLOAT: 00352 return EMUtil::EM_FLOAT; 00353 default: 00354 break; 00355 } 00356 return EMUtil::EM_UNKNOWN; 00357 }
| int VtkIO::get_mode_size | ( | DataType | d | ) | [private] |
Definition at line 360 of file vtkio.cpp.
References CHAR, DOUBLE, FLOAT, INT, LOGERR, LONG, SHORT, UNSIGNED_CHAR, UNSIGNED_INT, UNSIGNED_LONG, and UNSIGNED_SHORT.
00361 { 00362 switch (d) { 00363 case UNSIGNED_CHAR: 00364 case CHAR: 00365 return sizeof(char); 00366 case UNSIGNED_SHORT: 00367 case SHORT: 00368 return sizeof(short); 00369 case UNSIGNED_INT: 00370 case INT: 00371 return sizeof(int); 00372 case UNSIGNED_LONG: 00373 case LONG: 00374 return sizeof(long); 00375 case FLOAT: 00376 return sizeof(float); 00377 case DOUBLE: 00378 return sizeof(double); 00379 default: 00380 LOGERR("don't support this data type '%d'", d); 00381 break; 00382 } 00383 return 0; 00384 }
| void VtkIO::read_dataset | ( | DatasetType | dstype | ) | [private] |
Definition at line 440 of file vtkio.cpp.
References filename, ImageReadException, nx, originx, originy, originz, samestr(), spacingx, spacingy, spacingz, STRUCTURED_POINTS, and vtk_file.
00441 { 00442 char buf[1024]; 00443 int bufsz = sizeof(buf); 00444 00445 if (dstype == STRUCTURED_POINTS) { 00446 int nlines = 3; 00447 int i = 0; 00448 while (i < nlines && fgets(buf, bufsz, vtk_file)) { 00449 if (samestr(buf, "DIMENSIONS")) { 00450 sscanf(buf, "DIMENSIONS %d %d %d", &nx, &ny, &nz); 00451 } 00452 else if (samestr(buf, "ORIGIN")) { 00453 sscanf(buf, "ORIGIN %f %f %f", &originx, &originy, &originz); 00454 } 00455 else if (samestr(buf, "SPACING") || samestr(buf, "ASPECT_RATIO")) { 00456 if (samestr(buf, "SPACING")) { 00457 sscanf(buf, "SPACING %f %f %f", &spacingx, &spacingy, &spacingz); 00458 } 00459 else { 00460 sscanf(buf, "ASPECT_RATIO %f %f %f", &spacingx, &spacingy, &spacingz); 00461 } 00462 00463 if (spacingx != spacingy || spacingx != spacingz || spacingy != spacingz) { 00464 throw ImageReadException(filename, 00465 "not support non-uniform spacing VTK so far\n"); 00466 } 00467 } 00468 i++; 00469 } 00470 00471 if (i != nlines) { 00472 throw ImageReadException(filename, "read VTK file failed"); 00473 } 00474 } 00475 else { 00476 throw ImageReadException(filename, "only STRUCTURED_POINTS is supported so far"); 00477 } 00478 }
| VtkIO::DataType VtkIO::get_datatype_from_name | ( | const string & | datatype_name | ) | [private] |
Definition at line 386 of file vtkio.cpp.
References BIT, CHAR, DATATYPE_UNKNOWN, DOUBLE, FLOAT, initialized, INT, LONG, SHORT, UNSIGNED_CHAR, UNSIGNED_INT, UNSIGNED_LONG, and UNSIGNED_SHORT.
00387 { 00388 static bool initialized = false; 00389 static map < string, VtkIO::DataType > datatypes; 00390 00391 if (!initialized) { 00392 datatypes["bit"] = BIT; 00393 00394 datatypes["unsigned_char"] = UNSIGNED_CHAR; 00395 datatypes["char"] = CHAR; 00396 00397 datatypes["unsigned_short"] = UNSIGNED_SHORT; 00398 datatypes["short"] = SHORT; 00399 00400 datatypes["unsigned_int"] = UNSIGNED_INT; 00401 datatypes["int"] = INT; 00402 00403 datatypes["unsigned_long"] = UNSIGNED_LONG; 00404 datatypes["long"] = LONG; 00405 00406 datatypes["float"] = FLOAT; 00407 datatypes["double"] = DOUBLE; 00408 initialized = true; 00409 } 00410 00411 DataType result = DATATYPE_UNKNOWN; 00412 00413 if (datatypes.find(datatype_name) != datatypes.end()) { 00414 result = datatypes[datatype_name]; 00415 } 00416 return result; 00417 }
| VtkIO::DatasetType VtkIO::get_datasettype_from_name | ( | const string & | dataset_name | ) | [private] |
Definition at line 419 of file vtkio.cpp.
References DATASET_UNKNOWN, initialized, POLYDATA, RECTILINEAR_GRID, STRUCTURED_GRID, STRUCTURED_POINTS, and UNSTRUCTURED_GRID.
00420 { 00421 00422 static bool initialized = false; 00423 static map < string, DatasetType > types; 00424 00425 if (!initialized) { 00426 types["STRUCTURED_POINTS"] = STRUCTURED_POINTS; 00427 types["STRUCTURED_GRID"] = STRUCTURED_GRID; 00428 types["RECTILINEAR_GRID"] = RECTILINEAR_GRID; 00429 types["UNSTRUCTURED_GRID"] = UNSTRUCTURED_GRID; 00430 types["POLYDATA"] = POLYDATA; 00431 } 00432 00433 DatasetType result = DATASET_UNKNOWN; 00434 if (types.find(dataset_name) != types.end()) { 00435 result = types[dataset_name]; 00436 } 00437 return result; 00438 }
const char * VtkIO::MAGIC = "# vtk DataFile Version" [static, private] |
string EMAN::VtkIO::filename [private] |
IOMode EMAN::VtkIO::rw_mode [private] |
FILE* EMAN::VtkIO::vtk_file [private] |
bool EMAN::VtkIO::is_big_endian [private] |
bool EMAN::VtkIO::is_new_file [private] |
bool EMAN::VtkIO::initialized [private] |
Definition at line 133 of file vtkio.h.
Referenced by get_datasettype_from_name(), and get_datatype_from_name().
DataType EMAN::VtkIO::datatype [private] |
VtkType EMAN::VtkIO::filetype [private] |
int EMAN::VtkIO::nx [private] |
int EMAN::VtkIO::ny [private] |
int EMAN::VtkIO::nz [private] |
float EMAN::VtkIO::originx [private] |
float EMAN::VtkIO::originy [private] |
float EMAN::VtkIO::originz [private] |
float EMAN::VtkIO::spacingx [private] |
float EMAN::VtkIO::spacingy [private] |
float EMAN::VtkIO::spacingz [private] |
off_t EMAN::VtkIO::file_offset [private] |
1.5.6