Skip to content

Commit 53d66ed

Browse files
committed
WIP: BUG: VTKPolyDataMeshIO FIELD data support
1 parent 1e121bb commit 53d66ed

3 files changed

Lines changed: 101 additions & 0 deletions

File tree

Modules/IO/MeshVTK/src/itkVTKPolyDataMeshIO.cxx

Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -655,6 +655,52 @@ VTKPolyDataMeshIO::ReadMeshInformation()
655655
this->m_NumberOfPointPixelComponents = this->m_PointDimension * (this->m_PointDimension + 1) / 2;
656656
this->m_UpdatePointData = true;
657657
}
658+
if (line.find("FIELD") != std::string::npos)
659+
{
660+
// define string stream and put line into it
661+
StringStreamType sss;
662+
sss << line;
663+
664+
// Get each item
665+
sss >> item; // should be "FIELD"
666+
if (item == "FIELD")
667+
{
668+
sss >> item; // e.g. "FieldData" -- the field data name
669+
sss >> item; // the number of field data arrays
670+
if (std::stoi(item) >= 1)
671+
{
672+
// Note: we only use the first field data array
673+
std::getline(inputFile, line, '\n');
674+
675+
StringStreamType asss;
676+
asss << line;
677+
asss >> item; // array name
678+
679+
asss >> item; // numComponents
680+
const unsigned int numComponents = std::stoi(item);
681+
682+
asss >> item; // numTuples
683+
const unsigned int numTuples = std::stoi(item);
684+
685+
asss >> item; // data type
686+
const IOComponentEnum componentType = this->GetComponentTypeFromString(item);
687+
688+
if (this->m_NumberOfPoints == numTuples)
689+
{
690+
this->m_NumberOfPointPixelComponents = numComponents;
691+
this->m_PointPixelType = IOPixelEnum::VARIABLELENGTHVECTOR;
692+
693+
this->m_PointPixelComponentType = componentType;
694+
if (this->m_PointPixelComponentType == IOComponentEnum::UNKNOWNCOMPONENTTYPE)
695+
{
696+
itkExceptionMacro("Unknown cell component type");
697+
}
698+
699+
this->m_UpdatePointData = true;
700+
}
701+
}
702+
}
703+
}
658704
}
659705
else if (line.find("CELL_DATA") != std::string::npos)
660706
{
@@ -788,6 +834,52 @@ VTKPolyDataMeshIO::ReadMeshInformation()
788834
this->m_NumberOfCellPixelComponents = this->m_PointDimension * (this->m_PointDimension + 1) / 2;
789835
this->m_UpdateCellData = true;
790836
}
837+
if (line.find("FIELD") != std::string::npos)
838+
{
839+
// define string stream and put line into it
840+
StringStreamType sss;
841+
sss << line;
842+
843+
// Get each item
844+
sss >> item; // should be "FIELD"
845+
if (item == "FIELD")
846+
{
847+
sss >> item; // e.g. "FieldData" -- the field data name
848+
sss >> item; // the number of field data arrays
849+
if (std::stoi(item) >= 1)
850+
{
851+
// Note: we only use the first field data array
852+
std::getline(inputFile, line, '\n');
853+
854+
StringStreamType asss;
855+
asss << line;
856+
asss >> item; // array name
857+
858+
asss >> item; // numComponents
859+
const unsigned int numComponents = std::stoi(item);
860+
861+
asss >> item; // numTuples
862+
const unsigned int numTuples = std::stoi(item);
863+
864+
asss >> item; // data type
865+
const IOComponentEnum componentType = this->GetComponentTypeFromString(item);
866+
867+
if (this->m_NumberOfCells == numTuples)
868+
{
869+
this->m_NumberOfCellPixelComponents = numComponents;
870+
this->m_CellPixelType = IOPixelEnum::VARIABLELENGTHVECTOR;
871+
872+
this->m_CellPixelComponentType = componentType;
873+
if (this->m_CellPixelComponentType == IOComponentEnum::UNKNOWNCOMPONENTTYPE)
874+
{
875+
itkExceptionMacro("Unknown cell component type");
876+
}
877+
878+
this->m_UpdateCellData = true;
879+
}
880+
}
881+
}
882+
}
791883
}
792884
else if (line.find("OFFSETS") != std::string::npos)
793885
{

Modules/IO/MeshVTK/test/CMakeLists.txt

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,14 @@ itk_add_test(
176176
2
177177
1
178178
1)
179+
itk_add_test(
180+
NAME
181+
itkMeshFileReadWriteTestField
182+
COMMAND
183+
ITKIOMeshVTKTestDriver
184+
itkMeshFileReadWriteTest
185+
DATA{Input/gourd.vtk}
186+
${ITK_TEST_OUTPUT_DIR}/gourd.vtk)
179187

180188
set(ITKIOMeshVTKGTests itkVTKPolyDataMeshIOGTest.cxx)
181189

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
bafkreidv66i2s5mleluikmvcpq32yziqt7qo3tvc5imncrx4auoimwtdua

0 commit comments

Comments
 (0)