Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make fixed point numbers work #175

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 17 additions & 15 deletions src/ply_io.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,7 @@ struct PlyPointField
TypeSpec::Semantics semantics;
std::string plyName;
e_ply_type plyType;
bool fixedPoint;
};


Expand All @@ -151,18 +152,18 @@ static std::vector<PlyPointField> parsePlyPointFields(p_ply_element vertexElemen
// List of some fields which might be found in a .ply file and mappings to
// displaz field groups. Note that there's no standard!
PlyPointField standardFields[] = {
{"position", 0, TypeSpec::Vector, "x", PLY_FLOAT},
{"position", 1, TypeSpec::Vector, "y", PLY_FLOAT},
{"position", 2, TypeSpec::Vector, "z", PLY_FLOAT},
{"color", 0, TypeSpec::Color , "red", PLY_UINT8},
{"color", 1, TypeSpec::Color , "green", PLY_UINT8},
{"color", 2, TypeSpec::Color , "blue", PLY_UINT8},
{"color", 0, TypeSpec::Color , "r", PLY_UINT8},
{"color", 1, TypeSpec::Color , "g", PLY_UINT8},
{"color", 2, TypeSpec::Color , "b", PLY_UINT8},
{"normal", 0, TypeSpec::Vector, "nx", PLY_FLOAT},
{"normal", 1, TypeSpec::Vector, "ny", PLY_FLOAT},
{"normal", 2, TypeSpec::Vector, "nz", PLY_FLOAT},
{"position", 0, TypeSpec::Vector, "x", PLY_FLOAT, false},
{"position", 1, TypeSpec::Vector, "y", PLY_FLOAT, false},
{"position", 2, TypeSpec::Vector, "z", PLY_FLOAT, false},
{"color", 0, TypeSpec::Color , "red", PLY_UINT8, true},
{"color", 1, TypeSpec::Color , "green", PLY_UINT8, true},
{"color", 2, TypeSpec::Color , "blue", PLY_UINT8, true},
{"color", 0, TypeSpec::Color , "r", PLY_UINT8, true},
{"color", 1, TypeSpec::Color , "g", PLY_UINT8, true},
{"color", 2, TypeSpec::Color , "b", PLY_UINT8, true},
{"normal", 0, TypeSpec::Vector, "nx", PLY_FLOAT, false},
{"normal", 1, TypeSpec::Vector, "ny", PLY_FLOAT, false},
{"normal", 2, TypeSpec::Vector, "nz", PLY_FLOAT, false},
};
QRegExp vec3ComponentPattern("(.*)_?([xyz])");
QRegExp arrayComponentPattern("(.*)\\[([0-9]+)\\]");
Expand Down Expand Up @@ -210,7 +211,7 @@ static std::vector<PlyPointField> parsePlyPointFields(p_ply_element vertexElemen
displazName = arrayComponentPattern.cap(1).toStdString();
index = arrayComponentPattern.cap(2).toInt();
}
PlyPointField field = {displazName, index, semantics, propName, propType};
PlyPointField field = {displazName, index, semantics, propName, propType, false};
fieldInfo.push_back(field);
}
}
Expand Down Expand Up @@ -250,6 +251,7 @@ bool loadPlyVertexProperties(QString fileName, p_ply ply, p_ply_element vertexEl
const std::string& fieldName = fieldInfo[i].displazName;
TypeSpec::Semantics semantics = fieldInfo[i].semantics;
TypeSpec::Type baseType = TypeSpec::Unknown;
bool fixedPoint = fieldInfo[i].fixedPoint;
int elsize = 0;
plyTypeToPointFieldType(fieldInfo[i].plyType, baseType, elsize);
size_t eltBegin = i;
Expand All @@ -270,7 +272,7 @@ bool loadPlyVertexProperties(QString fileName, p_ply ply, p_ply_element vertexEl
}
else
{
TypeSpec type(baseType, elsize, maxComponentIndex+1, semantics);
TypeSpec type(baseType, elsize, maxComponentIndex+1, semantics, fixedPoint);
//tfm::printf("%s: type %s\n", fieldName, type);
fields.push_back(GeomField(type, fieldName, npoints));
fieldLoaders.push_back(PlyFieldLoader(fields.back()));
Expand Down Expand Up @@ -402,7 +404,7 @@ bool loadDisplazNativePly(QString fileName, p_ply ply,
}

// Create loader callback object
TypeSpec type(baseType, elsize, numProps, semantics);
TypeSpec type(baseType, elsize, numProps, semantics, false);
fields.push_back(GeomField(type, fieldName, npoints));
fieldLoaders.push_back(PlyFieldLoader(fields.back()));
// Connect callbacks for each property
Expand Down
3 changes: 2 additions & 1 deletion src/render/PointArray.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -774,7 +774,8 @@ DrawCount PointArray::drawPoints(QGLShaderProgram& prog, const TransformState& t

GLintptr arrayElementOffset = bufferOffset + j*field.spec.elsize;

if (attr->baseType == TypeSpec::Int || attr->baseType == TypeSpec::Uint)
if ((attr->baseType == TypeSpec::Int || attr->baseType == TypeSpec::Uint) &&
!field.spec.fixedPoint)
{
glVertexAttribIPointer(attr->location, vecSize, glBaseType(field.spec),
0, (const GLvoid *)arrayElementOffset);
Expand Down
12 changes: 6 additions & 6 deletions src/typespec.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,15 +51,15 @@ struct TypeSpec
bool fixedPoint; /// For Int,Uint: indicates fixed point scaling by
/// max value of the underlying integer type

TypeSpec() : type(Unknown), elsize(0), count(0), semantics(Array), fixedPoint(true) {}
TypeSpec() : type(Unknown), elsize(0), count(0), semantics(Array), fixedPoint(false) {}

TypeSpec(Type type, int elsize, int count = 1,
Semantics semantics = Array, bool fixedPoint = true)
Semantics semantics = Array, bool fixedPoint = false)
: type(type),
elsize(elsize),
count(count),
semantics(semantics),
fixedPoint(fixedPoint)
fixedPoint(type == Float ? false : fixedPoint)
{}

/// Named constructors for common types
Expand All @@ -70,9 +70,9 @@ struct TypeSpec
static TypeSpec uint16_i() { return TypeSpec(Uint, 2, 1, Array, false); }
static TypeSpec uint8_i() { return TypeSpec(Uint, 1, 1, Array, false); }
// Scaled fixed point integers
static TypeSpec uint32() { return TypeSpec(Uint, 4, 1); }
static TypeSpec uint16() { return TypeSpec(Uint, 2, 1); }
static TypeSpec uint8() { return TypeSpec(Uint, 1, 1); }
static TypeSpec uint32() { return TypeSpec(Uint, 4, 1, Array, true); }
static TypeSpec uint16() { return TypeSpec(Uint, 2, 1, Array, true); }
static TypeSpec uint8() { return TypeSpec(Uint, 1, 1, Array, true); }

/// Return number of vector elements in the aggregate
int vectorSize() const { return (semantics == Array) ? 1 : count; }
Expand Down
46 changes: 23 additions & 23 deletions test/displaz_ply_points.ply
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@ property float x
property float y
property float z
element vertex_color 20
property uint8 r
property uint8 g
property uint8 b
property float r
property float g
property float b
element vertex_a 20
property float 0
property float 1
Expand Down Expand Up @@ -59,26 +59,26 @@ end_header
7.89140509e-01 6.14212713e-01 1
9.45817242e-01 3.24699469e-01 1
1.00000000e+00 2.44929360e-16 1
0 255 0
26 229 0
96 159 0
179 76 0
240 15 0
254 1 0
214 41 0
138 117 0
57 198 0
6 249 0
6 249 0
57 198 0
138 117 0
214 41 0
254 1 0
240 15 0
179 76 0
96 159 0
26 229 0
0 255 0
0.0 1.0 0.0
0.101961 0.898039 0.0
0.376471 0.623529 0.0
0.701961 0.298039 0.0
0.941176 0.0588235 0.0
0.996078 0.00392157 0.0
0.839216 0.160784 0.0
0.541176 0.458824 0.0
0.223529 0.776471 0.0
0.0235294 0.976471 0.0
0.0235294 0.976471 0.0
0.223529 0.776471 0.0
0.541176 0.458824 0.0
0.839216 0.160784 0.0
0.996078 0.00392157 0.0
0.941176 0.0588235 0.0
0.701961 0.298039 0.0
0.376471 0.623529 0.0
0.101961 0.898039 0.0
0.0 1.0 0.0
0.00000000e+00 1.00000000e+00
1.05429745e-01 8.94570255e-01
3.77257256e-01 6.22742744e-01
Expand Down