#include <vtkio.h>
Inheritance diagram for EMAN::VtkIO:
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::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 };
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::VtkType [private] |
Definition at line 88 of file vtkio.h.
00089 { 00090 VTK_UNKNOWN, 00091 VTK_ASCII, 00092 VTK_BINARY 00093 };
VtkIO::VtkIO | ( | const string & | filename, | |
IOMode | rw_mode = READ_ONLY | |||
) | [explicit] |
Definition at line 47 of file vtkio.cpp.
References datatype, DATATYPE_UNKNOWN, file_offset, filetype, is_big_endian, EMAN::ByteOrder::is_host_big_endian(), is_new_file, nx, ny, nz, originx, originy, originz, spacingx, spacingy, spacingz, and VTK_UNKNOWN.
00048 : filename(vtk_filename), rw_mode(rw), vtk_file(0), initialized(false) 00049 { 00050 is_big_endian = ByteOrder::is_host_big_endian(); 00051 is_new_file = false; 00052 00053 datatype = DATATYPE_UNKNOWN; 00054 filetype = VTK_UNKNOWN; 00055 nx = 0; 00056 ny = 0; 00057 nz = 0; 00058 originx = 0; 00059 originy = 0; 00060 originz = 0; 00061 spacingx = 0; 00062 spacingy = 0; 00063 spacingz = 0; 00064 file_offset = 0; 00065 }
VtkIO::~VtkIO | ( | ) |
VtkIO::DatasetType VtkIO::get_datasettype_from_name | ( | const string & | dataset_name | ) | [private] |
Definition at line 431 of file vtkio.cpp.
References DATASET_UNKNOWN, initialized, POLYDATA, RECTILINEAR_GRID, STRUCTURED_GRID, STRUCTURED_POINTS, and UNSTRUCTURED_GRID.
00432 { 00433 00434 static bool initialized = false; 00435 static map < string, DatasetType > types; 00436 00437 if (!initialized) { 00438 types["STRUCTURED_POINTS"] = STRUCTURED_POINTS; 00439 types["STRUCTURED_GRID"] = STRUCTURED_GRID; 00440 types["RECTILINEAR_GRID"] = RECTILINEAR_GRID; 00441 types["UNSTRUCTURED_GRID"] = UNSTRUCTURED_GRID; 00442 types["POLYDATA"] = POLYDATA; 00443 } 00444 00445 DatasetType result = DATASET_UNKNOWN; 00446 if (types.find(dataset_name) != types.end()) { 00447 result = types[dataset_name]; 00448 } 00449 return result; 00450 }
VtkIO::DataType VtkIO::get_datatype_from_name | ( | const string & | datatype_name | ) | [private] |
Definition at line 398 of file vtkio.cpp.
References BIT, CHAR, DATATYPE_UNKNOWN, DOUBLE, FLOAT, initialized, INT, LONG, SHORT, UNSIGNED_CHAR, UNSIGNED_INT, UNSIGNED_LONG, and UNSIGNED_SHORT.
00399 { 00400 static bool initialized = false; 00401 static map < string, VtkIO::DataType > datatypes; 00402 00403 if (!initialized) { 00404 datatypes["bit"] = BIT; 00405 00406 datatypes["unsigned_char"] = UNSIGNED_CHAR; 00407 datatypes["char"] = CHAR; 00408 00409 datatypes["unsigned_short"] = UNSIGNED_SHORT; 00410 datatypes["short"] = SHORT; 00411 00412 datatypes["unsigned_int"] = UNSIGNED_INT; 00413 datatypes["int"] = INT; 00414 00415 datatypes["unsigned_long"] = UNSIGNED_LONG; 00416 datatypes["long"] = LONG; 00417 00418 datatypes["float"] = FLOAT; 00419 datatypes["double"] = DOUBLE; 00420 initialized = true; 00421 } 00422 00423 DataType result = DATATYPE_UNKNOWN; 00424 00425 if (datatypes.find(datatype_name) != datatypes.end()) { 00426 result = datatypes[datatype_name]; 00427 } 00428 return result; 00429 }
int EMAN::VtkIO::get_mode_size | ( | DataType | d | ) | [private] |
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 }
void VtkIO::read_dataset | ( | DatasetType | dstype | ) | [private] |
Definition at line 452 of file vtkio.cpp.
References filename, ImageReadException, nx, originx, originy, originz, samestr(), spacingx, spacingy, spacingz, STRUCTURED_POINTS, and vtk_file.
00453 { 00454 char buf[1024]; 00455 int bufsz = sizeof(buf); 00456 00457 if (dstype == STRUCTURED_POINTS) { 00458 int nlines = 3; 00459 int i = 0; 00460 while (i < nlines && fgets(buf, bufsz, vtk_file)) { 00461 if (samestr(buf, "DIMENSIONS")) { 00462 sscanf(buf, "DIMENSIONS %d %d %d", &nx, &ny, &nz); 00463 } 00464 else if (samestr(buf, "ORIGIN")) { 00465 sscanf(buf, "ORIGIN %f %f %f", &originx, &originy, &originz); 00466 } 00467 else if (samestr(buf, "SPACING") || samestr(buf, "ASPECT_RATIO")) { 00468 if (samestr(buf, "SPACING")) { 00469 sscanf(buf, "SPACING %f %f %f", &spacingx, &spacingy, &spacingz); 00470 } 00471 else { 00472 sscanf(buf, "ASPECT_RATIO %f %f %f", &spacingx, &spacingy, &spacingz); 00473 } 00474 00475 if (spacingx != spacingy || spacingx != spacingz || spacingy != spacingz) { 00476 throw ImageReadException(filename, 00477 "not support non-uniform spacing VTK so far\n"); 00478 } 00479 } 00480 i++; 00481 } 00482 00483 if (i != nlines) { 00484 throw ImageReadException(filename, "read VTK file failed"); 00485 } 00486 } 00487 else { 00488 throw ImageReadException(filename, "only STRUCTURED_POINTS is supported so far"); 00489 } 00490 }
int VtkIO::to_em_datatype | ( | int | vtk_datatype | ) | [private] |
Definition at line 357 of file vtkio.cpp.
References EMAN::EMUtil::EM_FLOAT, EMAN::EMUtil::EM_UNKNOWN, EMAN::EMUtil::EM_USHORT, FLOAT, and UNSIGNED_SHORT.
00358 { 00359 DataType d = static_cast < DataType > (vtk_datatype); 00360 switch (d) { 00361 case UNSIGNED_SHORT: 00362 return EMUtil::EM_USHORT; 00363 case FLOAT: 00364 return EMUtil::EM_FLOAT; 00365 default: 00366 break; 00367 } 00368 return EMUtil::EM_UNKNOWN; 00369 }
DataType EMAN::VtkIO::datatype [private] |
off_t EMAN::VtkIO::file_offset [private] |
string EMAN::VtkIO::filename [private] |
VtkType EMAN::VtkIO::filetype [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().
bool EMAN::VtkIO::is_big_endian [private] |
bool EMAN::VtkIO::is_new_file [private] |
const char * VtkIO::MAGIC = "# vtk DataFile Version" [static, 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] |
IOMode EMAN::VtkIO::rw_mode [private] |
float EMAN::VtkIO::spacingx [private] |
float EMAN::VtkIO::spacingy [private] |
float EMAN::VtkIO::spacingz [private] |
FILE* EMAN::VtkIO::vtk_file [private] |