Skip to content

Commit

Permalink
MetaIO 2024-07-03 (d269b397)
Browse files Browse the repository at this point in the history
Code extracted from:

    https://github.com/Kitware/MetaIO.git

at commit d269b3972910919ad22f2b179a13c189b176deef (master).
  • Loading branch information
MetaIO Maintainers authored and hjmjohnson committed Jul 8, 2024
1 parent 6861944 commit 01e133c
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 39 deletions.
47 changes: 23 additions & 24 deletions Modules/ThirdParty/MetaIO/src/MetaIO/src/metaScene.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -166,18 +166,18 @@ MetaScene::Read(const char * _headerName)
}

const std::string objectType = MET_ReadType(*m_ReadStream);
if (!strncmp(objectType.c_str(), "Tube", 4) || ((objectType.empty()) && !strcmp(suf, "tre")))
if (objectType.find("Tube") != std::string::npos || ((objectType.empty()) && !strcmp(suf, "tre")))
{
char * subtype = MET_ReadSubType(*m_ReadStream);
if (!strncmp(subtype, "Vessel", 6))
const std::string subtype = MET_ReadSubType(*m_ReadStream);
if (subtype.find("Vessel") != std::string::npos)
{
auto * vesseltube = new MetaVesselTube();
vesseltube->APIVersion(m_APIVersion);
vesseltube->SetEvent(m_Event);
vesseltube->ReadStream(m_NDims, m_ReadStream);
m_ObjectList.push_back(vesseltube);
}
else if (!strncmp(subtype, "DTI", 3))
else if (subtype.find("DTI") != std::string::npos)
{
auto * dtitube = new MetaDTITube();
dtitube->APIVersion(m_APIVersion);
Expand All @@ -193,10 +193,9 @@ MetaScene::Read(const char * _headerName)
tube->ReadStream(m_NDims, m_ReadStream);
m_ObjectList.push_back(tube);
}
delete[] subtype;
}

else if (!strncmp(objectType.c_str(), "Transform", 9))
else if (objectType.find("Transform") != std::string::npos)
{
auto * transform = new MetaTransform();
transform->APIVersion(m_APIVersion);
Expand All @@ -205,7 +204,7 @@ MetaScene::Read(const char * _headerName)
m_ObjectList.push_back(transform);
}

else if (!strncmp(objectType.c_str(), "TubeGraph", 9))
else if (objectType.find("TubeGraph") != std::string::npos)
{
auto * tubeGraph = new MetaTubeGraph();
tubeGraph->APIVersion(m_APIVersion);
Expand All @@ -214,7 +213,7 @@ MetaScene::Read(const char * _headerName)
m_ObjectList.push_back(tubeGraph);
}

else if (!strncmp(objectType.c_str(), "Ellipse", 7) || ((objectType.empty()) && !strcmp(suf, "elp")))
else if (objectType.find("Ellipse") != std::string::npos || ((objectType.empty()) && !strcmp(suf, "elp")))
{
auto * ellipse = new MetaEllipse();
ellipse->APIVersion(m_APIVersion);
Expand All @@ -223,7 +222,7 @@ MetaScene::Read(const char * _headerName)
m_ObjectList.push_back(ellipse);
}

else if (!strncmp(objectType.c_str(), "Contour", 7) || ((objectType.empty()) && !strcmp(suf, "ctr")))
else if (objectType.find("Contour") != std::string::npos || ((objectType.empty()) && !strcmp(suf, "ctr")))
{
auto * contour = new MetaContour();
contour->APIVersion(m_APIVersion);
Expand All @@ -232,7 +231,7 @@ MetaScene::Read(const char * _headerName)
m_ObjectList.push_back(contour);
}

else if (!strncmp(objectType.c_str(), "Arrow", 5))
else if (objectType.find("Arrow") != std::string::npos)
{
auto * arrow = new MetaArrow();
arrow->APIVersion(m_APIVersion);
Expand All @@ -241,7 +240,7 @@ MetaScene::Read(const char * _headerName)
m_ObjectList.push_back(arrow);
}

else if (!strncmp(objectType.c_str(), "Gaussian", 8) || ((objectType.empty()) && !strcmp(suf, "gau")))
else if (objectType.find("Gaussian") != std::string::npos || ((objectType.empty()) && !strcmp(suf, "gau")))
{
auto * gaussian = new MetaGaussian();
gaussian->APIVersion(m_APIVersion);
Expand All @@ -250,7 +249,7 @@ MetaScene::Read(const char * _headerName)
m_ObjectList.push_back(gaussian);
}

else if (!strncmp(objectType.c_str(), "Image", 5) ||
else if (objectType.find("Image") != std::string::npos ||
((objectType.empty()) && (!strcmp(suf, "mhd") || !strcmp(suf, "mha"))))
{
auto * image = new MetaImage();
Expand All @@ -261,7 +260,7 @@ MetaScene::Read(const char * _headerName)
m_ObjectList.push_back(image);
}

else if (!strncmp(objectType.c_str(), "Blob", 4) || ((objectType.empty()) && !strcmp(suf, "blb")))
else if (objectType.find("Blob") != std::string::npos || ((objectType.empty()) && !strcmp(suf, "blb")))
{
auto * blob = new MetaBlob();
blob->APIVersion(m_APIVersion);
Expand All @@ -270,7 +269,7 @@ MetaScene::Read(const char * _headerName)
m_ObjectList.push_back(blob);
}

else if (!strncmp(objectType.c_str(), "Landmark", 8) || ((objectType.empty()) && !strcmp(suf, "ldm")))
else if (objectType.find("Landmark") != std::string::npos || ((objectType.empty()) && !strcmp(suf, "ldm")))
{
auto * landmark = new MetaLandmark();
landmark->APIVersion(m_APIVersion);
Expand All @@ -279,7 +278,7 @@ MetaScene::Read(const char * _headerName)
m_ObjectList.push_back(landmark);
}

else if (!strncmp(objectType.c_str(), "Surface", 5) || ((objectType.empty()) && !strcmp(suf, "suf")))
else if (objectType.find("Surface") != std::string::npos || ((objectType.empty()) && !strcmp(suf, "suf")))
{
auto * surface = new MetaSurface();
surface->APIVersion(m_APIVersion);
Expand All @@ -288,7 +287,7 @@ MetaScene::Read(const char * _headerName)
m_ObjectList.push_back(surface);
}

else if (!strncmp(objectType.c_str(), "Line", 4) || ((objectType.empty()) && !strcmp(suf, "lin")))
else if (objectType.find("Line") != std::string::npos || ((objectType.empty()) && !strcmp(suf, "lin")))
{
auto * line = new MetaLine();
line->APIVersion(m_APIVersion);
Expand All @@ -297,7 +296,7 @@ MetaScene::Read(const char * _headerName)
m_ObjectList.push_back(line);
}

else if (!strncmp(objectType.c_str(), "Group", 5) || ((objectType.empty()) && !strcmp(suf, "grp")))
else if (objectType.find("Group") != std::string::npos || ((objectType.empty()) && !strcmp(suf, "grp")))
{
auto * group = new MetaGroup();
group->APIVersion(m_APIVersion);
Expand All @@ -306,23 +305,23 @@ MetaScene::Read(const char * _headerName)
m_ObjectList.push_back(group);
}

else if (!strncmp(objectType.c_str(), "AffineTransform", 15) || ((objectType.empty()) && !strcmp(suf, "trn")))
else if (objectType.find("AffineTransform") != std::string::npos || ((objectType.empty()) && !strcmp(suf, "trn")))
{
auto * group = new MetaGroup();
group->APIVersion(m_APIVersion);
group->SetEvent(m_Event);
group->ReadStream(m_NDims, m_ReadStream);
m_ObjectList.push_back(group);
}
else if (!strncmp(objectType.c_str(), "Mesh", 4) || ((objectType.empty()) && !strcmp(suf, "msh")))
else if (objectType.find("Mesh") != std::string::npos || ((objectType.empty()) && !strcmp(suf, "msh")))
{
auto * mesh = new MetaMesh();
mesh->APIVersion(m_APIVersion);
mesh->SetEvent(m_Event);
mesh->ReadStream(m_NDims, m_ReadStream);
m_ObjectList.push_back(mesh);
}
else if (!strncmp(objectType.c_str(), "FEMObject", 9) || ((objectType.empty()) && !strcmp(suf, "fem")))
else if (objectType.find("FEMObject") != std::string::npos || ((objectType.empty()) && !strcmp(suf, "fem")))
{
auto * femobject = new MetaFEMObject();
femobject->APIVersion(m_APIVersion);
Expand Down Expand Up @@ -438,6 +437,10 @@ MetaScene::M_SetupWriteFields()

MET_FieldRecordType * mF;

mF = new MET_FieldRecordType;
MET_InitWriteField(mF, "ObjectType", MET_STRING, strlen(m_ObjectTypeName), m_ObjectTypeName);
m_Fields.push_back(mF);

if (m_FileFormatVersion > 0)
{
mF = new MET_FieldRecordType;
Expand All @@ -452,10 +455,6 @@ MetaScene::M_SetupWriteFields()
m_Fields.push_back(mF);
}

mF = new MET_FieldRecordType;
MET_InitWriteField(mF, "ObjectType", MET_STRING, strlen(m_ObjectTypeName), m_ObjectTypeName);
m_Fields.push_back(mF);

mF = new MET_FieldRecordType;
MET_InitWriteField(mF, "NDims", MET_INT, m_NDims);
m_Fields.push_back(mF);
Expand Down
27 changes: 13 additions & 14 deletions Modules/ThirdParty/MetaIO/src/MetaIO/src/metaUtils.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ MET_ReadType(std::istream & _fp)
//
// Read the subtype of the object
//
char *
std::string
MET_ReadSubType(std::istream & _fp)
{
std::streampos pos = _fp.tellg();
Expand All @@ -193,25 +193,23 @@ MET_ReadSubType(std::istream & _fp)
MET_InitReadField(mF, "ObjectType", MET_STRING, false);
mF->required = false;
fields.push_back(mF);
mF = new MET_FieldRecordType;
MET_InitReadField(mF, "ObjectSubType", MET_STRING, false);
mF->required = false;
fields.push_back(mF);

MET_Read(_fp, &fields, '=', true);
_fp.seekg(pos);

// Find the line right after the ObjectType
char s[1024];
_fp.getline(s, 500);
std::string value = s;
size_t position = value.find('=');
if (position != std::string::npos)
if (mF->defined)
{
value = value.substr(position + 2, value.size() - position);
std::string value = reinterpret_cast<char *>(mF->value);
delete mF;
return value;
}
_fp.seekg(pos);

char * ret = new char[value.size() + 1];
strncpy(ret, value.c_str(), value.size());
ret[value.size()] = '\0';
delete mF;
return ret;
return std::string();
}


Expand Down Expand Up @@ -1165,6 +1163,7 @@ MET_Read(std::istream & fp,

MET_SeperatorChar = _met_SeperatorChar;

unsigned int linecount = 0;
while (!fp.eof())
{
int i = 0;
Expand Down Expand Up @@ -1426,7 +1425,7 @@ MET_Read(std::istream & fp,
fp.getline(s, 500);
}
}
if (oneLine)
if (oneLine && ++linecount > 3)
{
return MET_IsComplete(fields);
}
Expand Down
2 changes: 1 addition & 1 deletion Modules/ThirdParty/MetaIO/src/MetaIO/src/metaUtils.h
Original file line number Diff line number Diff line change
Expand Up @@ -455,7 +455,7 @@ std::string
MET_ReadType(std::istream & _fp);

METAIO_EXPORT
char *
std::string
MET_ReadSubType(std::istream & _fp);

# if (METAIO_USE_NAMESPACE)
Expand Down

0 comments on commit 01e133c

Please sign in to comment.