Commit 1ae04a22 authored by Michael Krämer's avatar Michael Krämer
Browse files

adding support for additional elements

parent 57bc372a
Pipeline #4191 passed with stage
in 41 minutes and 40 seconds
......@@ -309,8 +309,12 @@ bool _PLYReader_::read_ascii(std::istream& _in, BaseImporter& _bi, const Options
if (err_enabled)
omerr().disable();
for (std::vector<ElementInfo>::iterator e_it = elements_.begin(); e_it != elements_.end(); ++e_it)
{
if (e_it->element_== VERTEX)
{
// read vertices:
for (i = 0; i < vertexCount_ && !_in.eof(); ++i) {
for (i = 0; i < e_it->count_ && !_in.eof(); ++i) {
vh = _bi.add_vertex();
v[0] = 0.0;
......@@ -329,8 +333,9 @@ bool _PLYReader_::read_ascii(std::istream& _in, BaseImporter& _bi, const Options
c[2] = 0;
c[3] = 255;
for (size_t propertyIndex = 0; propertyIndex < vertexProperties_.size(); ++propertyIndex) {
switch (vertexProperties_[propertyIndex].property) {
for (size_t propertyIndex = 0; propertyIndex < e_it->properties_.size(); ++propertyIndex) {
PropertyInfo prop = e_it->properties_[propertyIndex];
switch (prop.property) {
case XCOORD:
_in >> v[0];
break;
......@@ -356,40 +361,44 @@ bool _PLYReader_::read_ascii(std::istream& _in, BaseImporter& _bi, const Options
_in >> t[1];
break;
case COLORRED:
if (vertexProperties_[propertyIndex].value == ValueTypeFLOAT32 ||
vertexProperties_[propertyIndex].value == ValueTypeFLOAT) {
if (prop.value == ValueTypeFLOAT32 ||
prop.value == ValueTypeFLOAT) {
_in >> tmp;
c[0] = static_cast<OpenMesh::Vec4i::value_type> (tmp * 255.0f);
} else
}
else
_in >> c[0];
break;
case COLORGREEN:
if (vertexProperties_[propertyIndex].value == ValueTypeFLOAT32 ||
vertexProperties_[propertyIndex].value == ValueTypeFLOAT) {
if (prop.value == ValueTypeFLOAT32 ||
prop.value == ValueTypeFLOAT) {
_in >> tmp;
c[1] = static_cast<OpenMesh::Vec4i::value_type> (tmp * 255.0f);
} else
}
else
_in >> c[1];
break;
case COLORBLUE:
if (vertexProperties_[propertyIndex].value == ValueTypeFLOAT32 ||
vertexProperties_[propertyIndex].value == ValueTypeFLOAT) {
if (prop.value == ValueTypeFLOAT32 ||
prop.value == ValueTypeFLOAT) {
_in >> tmp;
c[2] = static_cast<OpenMesh::Vec4i::value_type> (tmp * 255.0f);
} else
}
else
_in >> c[2];
break;
case COLORALPHA:
if (vertexProperties_[propertyIndex].value == ValueTypeFLOAT32 ||
vertexProperties_[propertyIndex].value == ValueTypeFLOAT) {
if (prop.value == ValueTypeFLOAT32 ||
prop.value == ValueTypeFLOAT) {
_in >> tmp;
c[3] = static_cast<OpenMesh::Vec4i::value_type> (tmp * 255.0f);
} else
}
else
_in >> c[3];
break;
case CUSTOM_PROP:
if (_opt.check(Options::Custom))
readCustomProperty<false>(_in, _bi, vh, vertexProperties_[propertyIndex].name, vertexProperties_[propertyIndex].value, vertexProperties_[propertyIndex].listIndexType);
readCustomProperty<false>(_in, _bi, vh, prop.name, prop.value, prop.listIndexType);
else
_in >> trash;
break;
......@@ -407,12 +416,14 @@ bool _PLYReader_::read_ascii(std::istream& _in, BaseImporter& _bi, const Options
if (_opt.vertex_has_color())
_bi.set_color(vh, Vec4uc(c));
}
}
else if (e_it->element_ == FACE)
{
// faces
for (i = 0; i < faceCount_; ++i) {
for (i = 0; i < faceCount_ && !_in.eof(); ++i) {
FaceHandle fh;
for (size_t propertyIndex = 0; propertyIndex < faceProperties_.size(); ++propertyIndex) {
PropertyInfo prop = faceProperties_[propertyIndex];
for (size_t propertyIndex = 0; propertyIndex < e_it->properties_.size(); ++propertyIndex) {
PropertyInfo prop = e_it->properties_[propertyIndex];
switch (prop.property) {
case VERTEX_INDICES:
......@@ -428,7 +439,8 @@ bool _PLYReader_::read_ascii(std::istream& _in, BaseImporter& _bi, const Options
vhandles[0] = VertexHandle(j);
vhandles[1] = VertexHandle(k);
vhandles[2] = VertexHandle(l);
} else {
}
else {
vhandles.clear();
for (j = 0; j < nV; ++j) {
_in >> idx;
......@@ -455,6 +467,19 @@ bool _PLYReader_::read_ascii(std::istream& _in, BaseImporter& _bi, const Options
}
}
}
else
{
// other elements
for (i = 0; i < e_it->count_ && !_in.eof(); ++i) {
for (size_t propertyIndex = 0; propertyIndex < e_it->properties_.size(); ++propertyIndex)
{
// just skip the values
_in >> trash;
}
}
}
}
if (err_enabled)
omerr().enable();
......@@ -490,8 +515,12 @@ bool _PLYReader_::read_binary(std::istream& _in, BaseImporter& _bi, bool /*_swap
if (err_enabled)
omerr().disable();
for (std::vector<ElementInfo>::iterator e_it = elements_.begin(); e_it != elements_.end(); ++e_it)
{
if (e_it->element_ == VERTEX)
{
// read vertices:
for (unsigned int i = 0; i < vertexCount_ && !_in.eof(); ++i) {
for (unsigned int i = 0; i < e_it->count_ && !_in.eof(); ++i) {
vh = _bi.add_vertex();
v[0] = 0.0;
......@@ -510,84 +539,89 @@ bool _PLYReader_::read_binary(std::istream& _in, BaseImporter& _bi, bool /*_swap
c[2] = 0;
c[3] = 255;
for (size_t propertyIndex = 0; propertyIndex < vertexProperties_.size(); ++propertyIndex) {
switch (vertexProperties_[propertyIndex].property) {
for (size_t propertyIndex = 0; propertyIndex < e_it->properties_.size(); ++propertyIndex) {
PropertyInfo prop = e_it->properties_[propertyIndex];
switch (prop.property) {
case XCOORD:
readValue(vertexProperties_[propertyIndex].value, _in, v[0]);
readValue(prop.value, _in, v[0]);
break;
case YCOORD:
readValue(vertexProperties_[propertyIndex].value, _in, v[1]);
readValue(prop.value, _in, v[1]);
break;
case ZCOORD:
readValue(vertexProperties_[propertyIndex].value, _in, v[2]);
readValue(prop.value, _in, v[2]);
break;
case XNORM:
readValue(vertexProperties_[propertyIndex].value, _in, n[0]);
readValue(prop.value, _in, n[0]);
break;
case YNORM:
readValue(vertexProperties_[propertyIndex].value, _in, n[1]);
readValue(prop.value, _in, n[1]);
break;
case ZNORM:
readValue(vertexProperties_[propertyIndex].value, _in, n[2]);
readValue(prop.value, _in, n[2]);
break;
case TEXX:
readValue(vertexProperties_[propertyIndex].value, _in, t[0]);
readValue(prop.value, _in, t[0]);
break;
case TEXY:
readValue(vertexProperties_[propertyIndex].value, _in, t[1]);
readValue(prop.value, _in, t[1]);
break;
case COLORRED:
if (vertexProperties_[propertyIndex].value == ValueTypeFLOAT32 ||
vertexProperties_[propertyIndex].value == ValueTypeFLOAT) {
readValue(vertexProperties_[propertyIndex].value, _in, tmp);
if (prop.value == ValueTypeFLOAT32 ||
prop.value == ValueTypeFLOAT) {
readValue(prop.value, _in, tmp);
c[0] = static_cast<OpenMesh::Vec4i::value_type> (tmp * 255.0f);
} else
readInteger(vertexProperties_[propertyIndex].value, _in, c[0]);
}
else
readInteger(prop.value, _in, c[0]);
break;
case COLORGREEN:
if (vertexProperties_[propertyIndex].value == ValueTypeFLOAT32 ||
vertexProperties_[propertyIndex].value == ValueTypeFLOAT) {
readValue(vertexProperties_[propertyIndex].value, _in, tmp);
if (prop.value == ValueTypeFLOAT32 ||
prop.value == ValueTypeFLOAT) {
readValue(prop.value, _in, tmp);
c[1] = static_cast<OpenMesh::Vec4i::value_type> (tmp * 255.0f);
} else
readInteger(vertexProperties_[propertyIndex].value, _in, c[1]);
}
else
readInteger(prop.value, _in, c[1]);
break;
case COLORBLUE:
if (vertexProperties_[propertyIndex].value == ValueTypeFLOAT32 ||
vertexProperties_[propertyIndex].value == ValueTypeFLOAT) {
readValue(vertexProperties_[propertyIndex].value, _in, tmp);
if (prop.value == ValueTypeFLOAT32 ||
prop.value == ValueTypeFLOAT) {
readValue(prop.value, _in, tmp);
c[2] = static_cast<OpenMesh::Vec4i::value_type> (tmp * 255.0f);
} else
readInteger(vertexProperties_[propertyIndex].value, _in, c[2]);
}
else
readInteger(prop.value, _in, c[2]);
break;
case COLORALPHA:
if (vertexProperties_[propertyIndex].value == ValueTypeFLOAT32 ||
vertexProperties_[propertyIndex].value == ValueTypeFLOAT) {
readValue(vertexProperties_[propertyIndex].value, _in, tmp);
if (prop.value == ValueTypeFLOAT32 ||
prop.value == ValueTypeFLOAT) {
readValue(prop.value, _in, tmp);
c[3] = static_cast<OpenMesh::Vec4i::value_type> (tmp * 255.0f);
} else
readInteger(vertexProperties_[propertyIndex].value, _in, c[3]);
}
else
readInteger(prop.value, _in, c[3]);
break;
case CUSTOM_PROP:
if (_opt.check(Options::Custom))
readCustomProperty<true>(_in, _bi, vh, vertexProperties_[propertyIndex].name, vertexProperties_[propertyIndex].value, vertexProperties_[propertyIndex].listIndexType);
readCustomProperty<true>(_in, _bi, vh, prop.name, prop.value, prop.listIndexType);
else
consume_input(_in, scalar_size_[vertexProperties_[propertyIndex].value]);
consume_input(_in, scalar_size_[prop.value]);
break;
default:
// Read unsupported property
consume_input(_in, scalar_size_[vertexProperties_[propertyIndex].value]);
consume_input(_in, scalar_size_[prop.value]);
break;
}
}
_bi.set_point(vh,v);
_bi.set_point(vh, v);
if (_opt.vertex_has_normal())
_bi.set_normal(vh, n);
if (_opt.vertex_has_texcoord())
......@@ -595,12 +629,13 @@ bool _PLYReader_::read_binary(std::istream& _in, BaseImporter& _bi, bool /*_swap
if (_opt.vertex_has_color())
_bi.set_color(vh, Vec4uc(c));
}
for (unsigned i = 0; i < faceCount_; ++i) {
}
else if (e_it->element_ == FACE) {
for (unsigned i = 0; i < e_it->count_ && !_in.eof(); ++i) {
FaceHandle fh;
for (size_t propertyIndex = 0; propertyIndex < faceProperties_.size(); ++propertyIndex)
for (size_t propertyIndex = 0; propertyIndex < e_it->properties_.size(); ++propertyIndex)
{
PropertyInfo prop = faceProperties_[propertyIndex];
PropertyInfo prop = e_it->properties_[propertyIndex];
switch (prop.property) {
case VERTEX_INDICES:
......@@ -610,7 +645,7 @@ bool _PLYReader_::read_binary(std::istream& _in, BaseImporter& _bi, bool /*_swap
if (nV == 3) {
vhandles.resize(3);
unsigned int j,k,l;
unsigned int j, k, l;
readInteger(prop.value, _in, j);
readInteger(prop.value, _in, k);
readInteger(prop.value, _in, l);
......@@ -618,7 +653,8 @@ bool _PLYReader_::read_binary(std::istream& _in, BaseImporter& _bi, bool /*_swap
vhandles[0] = VertexHandle(j);
vhandles[1] = VertexHandle(k);
vhandles[2] = VertexHandle(l);
} else {
}
else {
vhandles.clear();
for (unsigned j = 0; j < nV; ++j) {
unsigned int idx;
......@@ -636,16 +672,29 @@ bool _PLYReader_::read_binary(std::istream& _in, BaseImporter& _bi, bool /*_swap
if (_opt.check(Options::Custom) && fh.is_valid())
readCustomProperty<true>(_in, _bi, fh, prop.name, prop.value, prop.listIndexType);
else
consume_input(_in, scalar_size_[faceProperties_[propertyIndex].value]);
consume_input(_in, scalar_size_[prop.value]);
break;
default:
consume_input(_in, scalar_size_[faceProperties_[propertyIndex].value]);
consume_input(_in, scalar_size_[prop.value]);
break;
}
}
}
}
else {
for (unsigned int i = 0; i < e_it->count_ && !_in.eof(); ++i)
{
for (size_t propertyIndex = 0; propertyIndex < e_it->properties_.size(); ++propertyIndex)
{
PropertyInfo prop = e_it->properties_[propertyIndex];
// skip element values
consume_input(_in, scalar_size_[prop.value]);
}
}
}
}
if (err_enabled)
omerr().enable();
......@@ -1067,9 +1116,8 @@ bool _PLYReader_::can_u_read(std::istream& _is) const {
// Clear per file options
options_.cleanup();
// clear property maps, will be recreated
vertexProperties_.clear();
faceProperties_.clear();
// clear element list
elements_.clear();
// read 1st line
std::string line;
......@@ -1088,6 +1136,8 @@ bool _PLYReader_::can_u_read(std::istream& _is) const {
faceCount_ = 0;
vertexDimension_ = 0;
unsigned int elementCount = 0;
std::string keyword;
std::string fileType;
std::string elementName = "";
......@@ -1132,13 +1182,24 @@ bool _PLYReader_::can_u_read(std::istream& _is) const {
std::getline(_is, line);
} else if (keyword == "element") {
_is >> elementName;
_is >> elementCount;
ElementInfo element;
element.name_ = elementName;
element.count_ = elementCount;
if (elementName == "vertex") {
_is >> vertexCount_;
vertexCount_ = elementCount;
element.element_ = VERTEX;
} else if (elementName == "face") {
_is >> faceCount_;
faceCount_ = elementCount;
element.element_ = FACE;
} else {
omerr() << "PLY header unsupported element type: " << elementName << std::endl;
element.element_ = UNKNOWN;
}
elements_.push_back(element);
} else if (keyword == "property") {
std::string tmp1;
std::string tmp2;
......@@ -1174,29 +1235,26 @@ bool _PLYReader_::can_u_read(std::istream& _is) const {
PropertyInfo property(CUSTOM_PROP, entryType, propertyName);
property.listIndexType = indexType;
// just 2 elements supported by now
if (elementName == "vertex")
{
vertexProperties_.push_back(property);
}
else if (elementName == "face")
if (elementName == "face")
{
// special case for vertex indices
if (propertyName == "vertex_index" || propertyName == "vertex_indices")
{
property.property = VERTEX_INDICES;
if (!faceProperties_.empty())
if (!elements_.back().properties_.empty())
{
omerr() << "Custom face Properties defined, before 'vertex_indices' property was defined. They will be skipped" << std::endl;
faceProperties_.clear();
elements_.back().properties_.clear();
}
}
faceProperties_.push_back(property);
}
else
omerr() << "property " << propertyName << " belongs to unsupported element " << elementName << std::endl;
elements_.back().properties_.push_back(property);
} else {
// as this is not a list property, read second value of property
_is >> tmp2;
......@@ -1283,14 +1341,8 @@ bool _PLYReader_::can_u_read(std::istream& _is) const {
if (entry.property != UNSUPPORTED)
{
if (elementName == "vertex")
vertexProperties_.push_back(entry);
else if (elementName == "face")
faceProperties_.push_back(entry);
else
omerr() << "Properties not supported in element " << elementName << std::endl;
elements_.back().properties_.push_back(entry);
}
}
} else {
......
......@@ -165,7 +165,6 @@ private:
mutable unsigned int vertexCount_;
mutable unsigned int faceCount_;
mutable ValueType vertexType_;
mutable uint vertexDimension_;
enum Property {
......@@ -190,8 +189,23 @@ private:
PropertyInfo(Property _p, ValueType _v):property(_p),value(_v),name(""),listIndexType(Unsupported){}
PropertyInfo(Property _p, ValueType _v, const std::string& _n):property(_p),value(_v),name(_n),listIndexType(Unsupported){}
};
mutable std::vector< PropertyInfo > vertexProperties_;
mutable std::vector< PropertyInfo > faceProperties_;
enum Element {
VERTEX,
FACE,
UNKNOWN
};
// Information on the elements
struct ElementInfo
{
Element element_;
std::string name_;
unsigned int count_;
std::vector< PropertyInfo > properties_;
};
mutable std::vector< ElementInfo > elements_;
template<typename T>
inline void read(_PLYReader_::ValueType _type, std::istream& _in, T& _value, OpenMesh::GenProg::TrueType /*_binary*/) const
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment