Skip to content
Permalink
Browse files

Merge pull request #407 from UniStuttgart-VISUS/MMSPD_fix

MMSPD actually loads the data in the order defined in the file!
  • Loading branch information...
tobiasrau committed Sep 10, 2019
2 parents c74a3e2 + ddf4e55 commit 109d6a4305db06dd8e3beb66a085b04bae5f27fe
Showing with 53 additions and 23 deletions.
  1. +53 −23 plugins/mmstd_moldyn/src/io/MMSPDDataSource.cpp
@@ -96,8 +96,9 @@ bool MMSPDDataSource::Frame::LoadFrame(
bool isCylinder = (type.GetBaseType().Equals("c", false) || type.GetBaseType().Equals("cylinder", false));

if (isDot || isSphere || isEllipsoid || isCylinder) {
int idx[17];
for (int i = 0; i < 17; i++) idx[i] = -1;
std::vector<int> idx;
idx.resize(18);
for (int i = 0; i < idx.size(); i++) idx[i] = -1;

for (SIZE_T fi = 0; fi < fieldCnt; fi++) {
if (type.GetFields()[fi].GetName().Equals("x")) idx[0] = static_cast<int>(fi);
@@ -117,6 +118,7 @@ bool MMSPDDataSource::Frame::LoadFrame(
if (type.GetFields()[fi].GetName().Equals("qi")) idx[14] = static_cast<int>(fi);
if (type.GetFields()[fi].GetName().Equals("qj")) idx[15] = static_cast<int>(fi);
if (type.GetFields()[fi].GetName().Equals("qk")) idx[16] = static_cast<int>(fi);
if (type.GetFields()[fi].GetName().Equals("ca")) idx[17] = static_cast<int>(fi);
}

if ((idx[0] >= 0) && (idx[1] >= 0) && (idx[2] >= 0)) {
@@ -164,6 +166,10 @@ bool MMSPDDataSource::Frame::LoadFrame(
parts.FieldMap()[remFields + 1] = idx[4];
parts.FieldMap()[remFields + 2] = idx[5];
remFields += 3;
if (idx[17] >= 0) {
parts.FieldMap()[remFields + 0] = idx[17];
remFields++;
}
}

}
@@ -235,17 +241,18 @@ void MMSPDDataSource::Frame::SetData(core::moldyn::MultiParticleDataCall& call,
const MMSPDHeader::TypeDefinition &typeDef = header.GetTypes()[pi];
MMSPDFrameData::Particles &parts = this->Data()[pi];

bool hasX = false, hasY = false, hasZ = false, hasR = false, hasCR = false, hasCG = false, hasCB = false;
unsigned int rIdx = -1, cIdx = -1;
bool hasX = false, hasY = false, hasZ = false, hasR = false, hasCR = false, hasCG = false, hasCB = false, hasCA = false;
unsigned int rIdx = -1, cIdx = -1, pIdx = -1;
for (SIZE_T fi = 0; fi < typeDef.GetFields().Count(); fi++) {
const vislib::StringA& fn = typeDef.GetFields()[fi].GetName();
if (fn.Equals("x")) hasX = true;
if (fn.Equals("x")) { hasX = true; pIdx = static_cast<unsigned int>(fi); }
if (fn.Equals("y")) hasY = true;
if (fn.Equals("z")) hasZ = true;
if (fn.Equals("r")) { hasR = true; rIdx = static_cast<unsigned int>(fi); }
if (fn.Equals("cr")) { hasCR = true; cIdx = static_cast<unsigned int>(fi); }
if (fn.Equals("cg")) hasCG = true;
if (fn.Equals("cb")) hasCB = true;
if (fn.Equals("ca")) hasCA = true;
}

if (hasR && (parts.FieldMap()[rIdx] != 3)) {
@@ -255,13 +262,14 @@ void MMSPDDataSource::Frame::SetData(core::moldyn::MultiParticleDataCall& call,

pts.SetGlobalColour(191, 191, 191);
pts.SetGlobalRadius(0.5f);
unsigned int cr = 191, cg = 191, cb = 191;
unsigned int cr = 191, cg = 191, cb = 191, ca = 255;
for (SIZE_T fi = 0; fi < typeDef.GetConstFields().Count(); fi++) {
const MMSPDHeader::ConstField &f = typeDef.GetConstFields()[fi];
if (f.GetName().Equals("r")) pts.SetGlobalRadius(f.GetAsFloat());
if (f.GetName().Equals("cr")) pts.SetGlobalColour(cr = static_cast<unsigned int>(f.GetAsFloat() * 255.0f), cg, cb);
if (f.GetName().Equals("cg")) pts.SetGlobalColour(cr, cg = static_cast<unsigned int>(f.GetAsFloat() * 255.0f), cb);
if (f.GetName().Equals("cb")) pts.SetGlobalColour(cr, cg, cb = static_cast<unsigned int>(f.GetAsFloat() * 255.0f));
if (f.GetName().Equals("ca")) pts.SetGlobalColour(cr, cg, cb, ca = static_cast<unsigned int>(f.GetAsFloat() * 255.0f));
}

// now use some because-I-know-magic:
@@ -284,15 +292,21 @@ void MMSPDDataSource::Frame::SetData(core::moldyn::MultiParticleDataCall& call,

pts.SetVertexData(hasR ? core::moldyn::MultiParticleDataCall::Particles::VERTDATA_FLOAT_XYZR
: core::moldyn::MultiParticleDataCall::Particles::VERTDATA_FLOAT_XYZ,
parts.Data().At(off),
parts.Data().At(off + pIdx * sizeof(float)),
static_cast<unsigned int>(off + typeDef.GetFields().Count() * sizeof(float)));
//printf("%lu\n", parts.Count());
//printf("%f %f %f\n", parts.Data().AsAt<float>(off)[0], parts.Data().AsAt<float>(off)[1], parts.Data().AsAt<float>(off)[2]);

if (hasCR && hasCG && hasCB) {
pts.SetColourData(core::moldyn::MultiParticleDataCall::Particles::COLDATA_FLOAT_RGB,
parts.Data().At(off + parts.FieldMap()[cIdx] * sizeof(float)),
static_cast<unsigned int>(off + typeDef.GetFields().Count() * sizeof(float)));
if (hasCA) {
pts.SetColourData(core::moldyn::MultiParticleDataCall::Particles::COLDATA_FLOAT_RGBA,
parts.Data().At(off + cIdx * sizeof(float)),
static_cast<unsigned int>(off + typeDef.GetFields().Count() * sizeof(float)));
} else {
pts.SetColourData(core::moldyn::MultiParticleDataCall::Particles::COLDATA_FLOAT_RGB,
parts.Data().At(off + cIdx * sizeof(float)),
static_cast<unsigned int>(off + typeDef.GetFields().Count() * sizeof(float)));
}
} else {
pts.SetColourData(core::moldyn::MultiParticleDataCall::Particles::COLDATA_NONE, NULL);
}
@@ -315,17 +329,18 @@ void MMSPDDataSource::Frame::SetDirData(core::moldyn::MultiParticleDataCall& cal
const MMSPDHeader::TypeDefinition &typeDef = header.GetTypes()[pi];
MMSPDFrameData::Particles &parts = this->Data()[pi];

bool hasX = false, hasY = false, hasZ = false, hasR = false, hasCR = false, hasCG = false, hasCB = false, hasDX = false, hasDY = false, hasDZ = false;
unsigned int rIdx = -1, cIdx = -1, dIdx = -1;
bool hasX = false, hasY = false, hasZ = false, hasR = false, hasCR = false, hasCG = false, hasCB = false, hasCA = false, hasDX = false, hasDY = false, hasDZ = false;
unsigned int rIdx = -1, cIdx = -1, dIdx = -1, pIdx = -1;
for (SIZE_T fi = 0; fi < typeDef.GetFields().Count(); fi++) {
const vislib::StringA& fn = typeDef.GetFields()[fi].GetName();
if (fn.Equals("x")) hasX = true;
if (fn.Equals("x")) { hasX = true; pIdx = static_cast<unsigned int>(fi); }
if (fn.Equals("y")) hasY = true;
if (fn.Equals("z")) hasZ = true;
if (fn.Equals("r")) { hasR = true; rIdx = static_cast<unsigned int>(fi); }
if (fn.Equals("cr")) { hasCR = true; cIdx = static_cast<unsigned int>(fi); }
if (fn.Equals("cg")) hasCG = true;
if (fn.Equals("cb")) hasCB = true;
if (fn.Equals("ca")) hasCA = true;
if (fn.Equals("dx")) { hasDX = true; dIdx = static_cast<unsigned int>(fi); }
if (fn.Equals("dy")) hasDY = true;
if (fn.Equals("dz")) hasDZ = true;
@@ -338,13 +353,14 @@ void MMSPDDataSource::Frame::SetDirData(core::moldyn::MultiParticleDataCall& cal

pts.SetGlobalColour(191, 191, 191);
pts.SetGlobalRadius(0.5f);
unsigned int cr = 191, cg = 191, cb = 191;
unsigned int cr = 191, cg = 191, cb = 191, ca = 255;
for (SIZE_T fi = 0; fi < typeDef.GetConstFields().Count(); fi++) {
const MMSPDHeader::ConstField &f = typeDef.GetConstFields()[fi];
if (f.GetName().Equals("r")) pts.SetGlobalRadius(f.GetAsFloat());
if (f.GetName().Equals("cr")) pts.SetGlobalColour(cr = static_cast<unsigned int>(f.GetAsFloat() * 255.0f), cg, cb);
if (f.GetName().Equals("cg")) pts.SetGlobalColour(cr, cg = static_cast<unsigned int>(f.GetAsFloat() * 255.0f), cb);
if (f.GetName().Equals("cb")) pts.SetGlobalColour(cr, cg, cb = static_cast<unsigned int>(f.GetAsFloat() * 255.0f));
if (f.GetName().Equals("ca")) pts.SetGlobalColour(cr, cg, cb, ca = static_cast<unsigned int>(f.GetAsFloat() * 255.0f));
}

// now use some because-I-know-magic:
@@ -368,12 +384,12 @@ void MMSPDDataSource::Frame::SetDirData(core::moldyn::MultiParticleDataCall& cal

pts.SetVertexData(hasR ? core::moldyn::SimpleSphericalParticles::VERTDATA_FLOAT_XYZR
: core::moldyn::SimpleSphericalParticles::VERTDATA_FLOAT_XYZ,
parts.Data().At(off),
parts.Data().At(off + pIdx * sizeof(float)),
static_cast<unsigned int>(off + typeDef.GetFields().Count() * sizeof(float)));

if (hasDX && hasDY && hasDZ) {
pts.SetDirData(core::moldyn::SimpleSphericalParticles::DIRDATA_FLOAT_XYZ,
parts.Data().At(off + parts.FieldMap()[dIdx] * sizeof(float)),
parts.Data().At(off + dIdx * sizeof(float)),
static_cast<unsigned int>(off + typeDef.GetFields().Count() * sizeof(float)));
} else {
pts.SetDirData(core::moldyn::SimpleSphericalParticles::DIRDATA_NONE,
@@ -384,9 +400,15 @@ void MMSPDDataSource::Frame::SetDirData(core::moldyn::MultiParticleDataCall& cal
//printf("%f %f %f\n", parts.Data().AsAt<float>(off)[0], parts.Data().AsAt<float>(off)[1], parts.Data().AsAt<float>(off)[2]);

if (hasCR && hasCG && hasCB) {
pts.SetColourData(core::moldyn::SimpleSphericalParticles::COLDATA_FLOAT_RGB,
parts.Data().At(off + parts.FieldMap()[cIdx] * sizeof(float)),
static_cast<unsigned int>(off + typeDef.GetFields().Count() * sizeof(float)));
if (hasCA) {
pts.SetColourData(core::moldyn::SimpleSphericalParticles::COLDATA_FLOAT_RGBA,
parts.Data().At(off + cIdx * sizeof(float)),
static_cast<unsigned int>(off + typeDef.GetFields().Count() * sizeof(float)));
} else {
pts.SetColourData(core::moldyn::SimpleSphericalParticles::COLDATA_FLOAT_RGB,
parts.Data().At(off + cIdx * sizeof(float)),
static_cast<unsigned int>(off + typeDef.GetFields().Count() * sizeof(float)));
}
} else {
pts.SetColourData(core::moldyn::SimpleSphericalParticles::COLDATA_NONE, NULL);
}
@@ -460,10 +482,16 @@ void MMSPDDataSource::Frame::loadFrameText(char *buffer, UINT64 size, const MMSP
if (line.Count() < fieldCnt + off) throw vislib::Exception("line truncated", __FILE__, __LINE__);

for (SIZE_T fi = 0; fi < fieldCnt; fi++) {
float val = static_cast<float>(vislib::CharTraitsA::ParseDouble(line.Word(off + this->GetData()[type].FieldMap()[fi])));
if (header.GetTypes()[type].GetFields()[this->GetData()[type].FieldMap()[fi]].GetType() == MMSPDHeader::Field::TYPE_BYTE) {
//float val = static_cast<float>(vislib::CharTraitsA::ParseDouble(line.Word(off + this->GetData()[type].FieldMap()[fi])));
//if (header.GetTypes()[type].GetFields()[this->GetData()[type].FieldMap()[fi]].GetType() ==
// MMSPDHeader::Field::TYPE_BYTE) {
// val /= 255.0f;
//}
float val = vislib::CharTraitsA::ParseDouble(line.Word(off + fi));
if (header.GetTypes()[type].GetFields()[fi].GetType() == MMSPDHeader::Field::TYPE_BYTE) {
val /= 255.0f;
}

//vislib::sys::Log::DefaultLog.WriteInfo("read: %f", val);
typeData[type]->Write(val);
}
@@ -546,7 +574,8 @@ void MMSPDDataSource::Frame::loadFrameBinary(char *buffer, UINT64 size, const MM
}

for (SIZE_T fi = 0; fi < fieldCnt; fi++) {
typeData[type]->Write(values.operator->()[this->GetData()[type].FieldMap()[fi]]);
//typeData[type]->Write(values.operator->()[this->GetData()[type].FieldMap()[fi]]);
typeData[type]->Write(values.operator->()[fi]);
}

}
@@ -645,7 +674,8 @@ void MMSPDDataSource::Frame::loadFrameBinaryBE(char *buffer, UINT64 size, const
}

for (SIZE_T fi = 0; fi < fieldCnt; fi++) {
typeData[type]->Write(values.operator->()[this->GetData()[type].FieldMap()[fi]]);
//typeData[type]->Write(values.operator->()[this->GetData()[type].FieldMap()[fi]]);
typeData[type]->Write(values.operator->()[fi]);
}

}

0 comments on commit 109d6a4

Please sign in to comment.
You can’t perform that action at this time.