Merge pull request #535 from google/draco_error

Rename Status::ERROR to Status::DRACO_ERROR.
This commit is contained in:
Tom Finegan 2019-07-08 09:59:43 -07:00 committed by GitHub
commit 7e3a61d46d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
14 changed files with 58 additions and 54 deletions

View File

@ -37,7 +37,7 @@ StatusOr<std::unique_ptr<PointCloudDecoder>> CreatePointCloudDecoder(
} else if (method == POINT_CLOUD_KD_TREE_ENCODING) {
return std::unique_ptr<PointCloudDecoder>(new PointCloudKdTreeDecoder());
}
return Status(Status::ERROR, "Unsupported encoding method.");
return Status(Status::DRACO_ERROR, "Unsupported encoding method.");
}
#endif
@ -48,7 +48,7 @@ StatusOr<std::unique_ptr<MeshDecoder>> CreateMeshDecoder(uint8_t method) {
} else if (method == MESH_EDGEBREAKER_ENCODING) {
return std::unique_ptr<MeshDecoder>(new MeshEdgebreakerDecoder());
}
return Status(Status::ERROR, "Unsupported encoding method.");
return Status(Status::DRACO_ERROR, "Unsupported encoding method.");
}
#endif
@ -77,7 +77,7 @@ StatusOr<std::unique_ptr<PointCloud>> Decoder::DecodePointCloudFromBuffer(
return static_cast<std::unique_ptr<PointCloud>>(std::move(mesh));
#endif
}
return Status(Status::ERROR, "Unsupported geometry type.");
return Status(Status::DRACO_ERROR, "Unsupported geometry type.");
}
StatusOr<std::unique_ptr<Mesh>> Decoder::DecodeMeshFromBuffer(
@ -94,7 +94,7 @@ Status Decoder::DecodeBufferToGeometry(DecoderBuffer *in_buffer,
DracoHeader header;
DRACO_RETURN_IF_ERROR(PointCloudDecoder::DecodeHeader(&temp_buffer, &header))
if (header.encoder_type != POINT_CLOUD) {
return Status(Status::ERROR, "Input is not a point cloud.");
return Status(Status::DRACO_ERROR, "Input is not a point cloud.");
}
DRACO_ASSIGN_OR_RETURN(std::unique_ptr<PointCloudDecoder> decoder,
CreatePointCloudDecoder(header.encoder_method))
@ -102,7 +102,7 @@ Status Decoder::DecodeBufferToGeometry(DecoderBuffer *in_buffer,
DRACO_RETURN_IF_ERROR(decoder->Decode(options_, in_buffer, out_geometry))
return OkStatus();
#else
return Status(Status::ERROR, "Unsupported geometry type.");
return Status(Status::DRACO_ERROR, "Unsupported geometry type.");
#endif
}
@ -113,7 +113,7 @@ Status Decoder::DecodeBufferToGeometry(DecoderBuffer *in_buffer,
DracoHeader header;
DRACO_RETURN_IF_ERROR(PointCloudDecoder::DecodeHeader(&temp_buffer, &header))
if (header.encoder_type != TRIANGULAR_MESH) {
return Status(Status::ERROR, "Input is not a mesh.");
return Status(Status::DRACO_ERROR, "Input is not a mesh.");
}
DRACO_ASSIGN_OR_RETURN(std::unique_ptr<MeshDecoder> decoder,
CreateMeshDecoder(header.encoder_method))
@ -121,7 +121,7 @@ Status Decoder::DecodeBufferToGeometry(DecoderBuffer *in_buffer,
DRACO_RETURN_IF_ERROR(decoder->Decode(options_, in_buffer, out_geometry))
return OkStatus();
#else
return Status(Status::ERROR, "Unsupported geometry type.");
return Status(Status::DRACO_ERROR, "Unsupported geometry type.");
#endif
}

View File

@ -69,25 +69,27 @@ class EncoderBase {
int prediction_scheme) const {
// Out of bound checks:
if (prediction_scheme < PREDICTION_NONE)
return Status(Status::ERROR, "Invalid prediction scheme requested.");
return Status(Status::DRACO_ERROR,
"Invalid prediction scheme requested.");
if (prediction_scheme >= NUM_PREDICTION_SCHEMES)
return Status(Status::ERROR, "Invalid prediction scheme requested.");
return Status(Status::DRACO_ERROR,
"Invalid prediction scheme requested.");
// Deprecated prediction schemes:
if (prediction_scheme == MESH_PREDICTION_TEX_COORDS_DEPRECATED)
return Status(Status::ERROR,
return Status(Status::DRACO_ERROR,
"MESH_PREDICTION_TEX_COORDS_DEPRECATED is deprecated.");
if (prediction_scheme == MESH_PREDICTION_MULTI_PARALLELOGRAM)
return Status(Status::ERROR,
return Status(Status::DRACO_ERROR,
"MESH_PREDICTION_MULTI_PARALLELOGRAM is deprecated.");
// Attribute specific checks:
if (prediction_scheme == MESH_PREDICTION_TEX_COORDS_PORTABLE) {
if (att_type != GeometryAttribute::TEX_COORD)
return Status(Status::ERROR,
return Status(Status::DRACO_ERROR,
"Invalid prediction scheme for attribute type.");
}
if (prediction_scheme == MESH_PREDICTION_GEOMETRIC_NORMAL) {
if (att_type != GeometryAttribute::NORMAL) {
return Status(Status::ERROR,
return Status(Status::DRACO_ERROR,
"Invalid prediction scheme for attribute type.");
}
}
@ -95,7 +97,7 @@ class EncoderBase {
if (att_type == GeometryAttribute::NORMAL) {
if (!(prediction_scheme == PREDICTION_DIFFERENCE ||
prediction_scheme == MESH_PREDICTION_GEOMETRIC_NORMAL)) {
return Status(Status::ERROR,
return Status(Status::DRACO_ERROR,
"Invalid prediction scheme for attribute type.");
}
}

View File

@ -31,7 +31,7 @@ ExpertEncoder::ExpertEncoder(const Mesh &mesh)
Status ExpertEncoder::EncodeToBuffer(EncoderBuffer *out_buffer) {
if (point_cloud_ == nullptr)
return Status(Status::ERROR, "Invalid input geometry.");
return Status(Status::DRACO_ERROR, "Invalid input geometry.");
if (mesh_ == nullptr) {
return EncodePointCloudToBuffer(*point_cloud_, out_buffer);
}
@ -77,7 +77,7 @@ Status ExpertEncoder::EncodePointCloudToBuffer(const PointCloud &pc,
} else if (encoding_method == POINT_CLOUD_KD_TREE_ENCODING) {
// Encoding method was explicitly specified but we cannot use it for
// the given input (some of the checks above failed).
return Status(Status::ERROR, "Invalid encoding method.");
return Status(Status::DRACO_ERROR, "Invalid encoding method.");
}
}
if (!encoder) {
@ -91,7 +91,7 @@ Status ExpertEncoder::EncodePointCloudToBuffer(const PointCloud &pc,
set_num_encoded_faces(0);
return OkStatus();
#else
return Status(Status::ERROR, "Point cloud encoding is not enabled.");
return Status(Status::DRACO_ERROR, "Point cloud encoding is not enabled.");
#endif
}

View File

@ -279,7 +279,7 @@ Status MeshEdgebreakerEncoderImpl<TraversalEncoder>::EncodeConnectivity() {
corner_table_->num_faces() == corner_table_->NumDegeneratedFaces()) {
// Failed to construct the corner table.
// TODO(ostava): Add better error reporting.
return Status(Status::ERROR, "All triangles are degenerate.");
return Status(Status::DRACO_ERROR, "All triangles are degenerate.");
}
traversal_encoder_.Init(this);
@ -317,10 +317,10 @@ Status MeshEdgebreakerEncoderImpl<TraversalEncoder>::EncodeConnectivity() {
pos_encoding_data_.num_values = 0;
if (!FindHoles())
return Status(Status::ERROR, "Failed to process mesh holes.");
return Status(Status::DRACO_ERROR, "Failed to process mesh holes.");
if (!InitAttributeData())
return Status(Status::ERROR, "Failed to initialize attribute data.");
return Status(Status::DRACO_ERROR, "Failed to initialize attribute data.");
const uint8_t num_attribute_data =
static_cast<uint8_t>(attribute_data_.size());
@ -376,7 +376,7 @@ Status MeshEdgebreakerEncoderImpl<TraversalEncoder>::EncodeConnectivity() {
if (opp_face_id != kInvalidFaceIndex &&
!visited_faces_[opp_face_id.value()]) {
if (!EncodeConnectivityFromCorner(opp_id))
return Status(Status::ERROR, "Failed to encode mesh component.");
return Status(Status::DRACO_ERROR, "Failed to encode mesh component.");
}
} else {
// Boundary configuration. We start on a boundary rather than on a face.
@ -385,7 +385,7 @@ Status MeshEdgebreakerEncoderImpl<TraversalEncoder>::EncodeConnectivity() {
// Start processing the face opposite to the boundary edge (the face
// containing the start_corner).
if (!EncodeConnectivityFromCorner(start_corner))
return Status(Status::ERROR, "Failed to encode mesh component.");
return Status(Status::DRACO_ERROR, "Failed to encode mesh component.");
}
}
// Reverse the order of connectivity corners to match the order in which
@ -417,7 +417,7 @@ Status MeshEdgebreakerEncoderImpl<TraversalEncoder>::EncodeConnectivity() {
// Append the traversal buffer.
if (!EncodeSplitData())
return Status(Status::ERROR, "Failed to encode split data.");
return Status(Status::DRACO_ERROR, "Failed to encode split data.");
encoder_->buffer()->Encode(traversal_encoder_.buffer().data(),
traversal_encoder_.buffer().size());

View File

@ -38,7 +38,7 @@ Status MeshSequentialEncoder::EncodeConnectivity() {
// 0 = Encode compressed indices.
buffer()->Encode(static_cast<uint8_t>(0));
if (!CompressAndEncodeIndices())
return Status(Status::ERROR, "Failed to compress connectivity.");
return Status(Status::DRACO_ERROR, "Failed to compress connectivity.");
} else {
// 1 = Encode indices directly.
buffer()->Encode(static_cast<uint8_t>(1));

View File

@ -31,7 +31,7 @@ Status PointCloudDecoder::DecodeHeader(DecoderBuffer *buffer,
if (!buffer->Decode(out_header->draco_string, 5))
return Status(Status::IO_ERROR, kIoErrorMsg);
if (memcmp(out_header->draco_string, "DRACO", 5) != 0)
return Status(Status::ERROR, "Not a Draco file.");
return Status(Status::DRACO_ERROR, "Not a Draco file.");
if (!buffer->Decode(&(out_header->version_major)))
return Status(Status::IO_ERROR, kIoErrorMsg);
if (!buffer->Decode(&(out_header->version_minor)))
@ -50,7 +50,7 @@ Status PointCloudDecoder::DecodeMetadata() {
std::unique_ptr<GeometryMetadata>(new GeometryMetadata());
MetadataDecoder metadata_decoder;
if (!metadata_decoder.DecodeGeometryMetadata(buffer_, metadata.get()))
return Status(Status::ERROR, "Failed to decode metadata.");
return Status(Status::DRACO_ERROR, "Failed to decode metadata.");
point_cloud_->AddMetadata(std::move(metadata));
return OkStatus();
}
@ -66,7 +66,7 @@ Status PointCloudDecoder::Decode(const DecoderOptions &options,
// Sanity check that we are really using the right decoder (mostly for cases
// where the Decode method was called manually outside of our main API.
if (header.encoder_type != GetGeometryType())
return Status(Status::ERROR,
return Status(Status::DRACO_ERROR,
"Using incompatible decoder for the input geometry.");
// TODO(ostava): We should check the method as well, but currently decoders
// don't expose the decoding method id.
@ -93,11 +93,11 @@ Status PointCloudDecoder::Decode(const DecoderOptions &options,
DRACO_RETURN_IF_ERROR(DecodeMetadata())
}
if (!InitializeDecoder())
return Status(Status::ERROR, "Failed to initialize the decoder.");
return Status(Status::DRACO_ERROR, "Failed to initialize the decoder.");
if (!DecodeGeometryData())
return Status(Status::ERROR, "Failed to decode geometry data.");
return Status(Status::DRACO_ERROR, "Failed to decode geometry data.");
if (!DecodePointAttributes())
return Status(Status::ERROR, "Failed to decode point attributes.");
return Status(Status::DRACO_ERROR, "Failed to decode point attributes.");
return OkStatus();
}

View File

@ -36,16 +36,16 @@ Status PointCloudEncoder::Encode(const EncoderOptions &options,
attributes_encoder_ids_order_.clear();
if (!point_cloud_)
return Status(Status::ERROR, "Invalid input geometry.");
return Status(Status::DRACO_ERROR, "Invalid input geometry.");
DRACO_RETURN_IF_ERROR(EncodeHeader())
DRACO_RETURN_IF_ERROR(EncodeMetadata())
if (!InitializeEncoder())
return Status(Status::ERROR, "Failed to initialize encoder.");
return Status(Status::DRACO_ERROR, "Failed to initialize encoder.");
if (!EncodeEncoderData())
return Status(Status::ERROR, "Failed to encode internal data.");
return Status(Status::DRACO_ERROR, "Failed to encode internal data.");
DRACO_RETURN_IF_ERROR(EncodeGeometryData());
if (!EncodePointAttributes())
return Status(Status::ERROR, "Failed to encode point attributes.");
return Status(Status::DRACO_ERROR, "Failed to encode point attributes.");
if (options.GetGlobalBool("store_number_of_encoded_points", false))
ComputeNumberOfEncodedPoints();
return OkStatus();
@ -86,7 +86,7 @@ Status PointCloudEncoder::EncodeMetadata() {
MetadataEncoder metadata_encoder;
if (!metadata_encoder.EncodeGeometryMetadata(buffer_,
point_cloud_->GetMetadata())) {
return Status(Status::ERROR, "Failed to encode metadata.");
return Status(Status::DRACO_ERROR, "Failed to encode metadata.");
}
return OkStatus();
}

View File

@ -25,7 +25,7 @@ class Status {
public:
enum Code {
OK = 0,
ERROR = -1, // Used for general errors.
DRACO_ERROR = -1, // Used for general errors.
IO_ERROR = -2, // Error when handling input or output stream.
INVALID_PARAMETER = -3, // Invalid parameter passed to a function.
UNSUPPORTED_VERSION = -4, // Input not compatible with the current version.

View File

@ -27,8 +27,8 @@ class StatusTest : public ::testing::Test {
TEST_F(StatusTest, TestStatusOutput) {
// Tests that the Status can be stored in a provided std::ostream.
const draco::Status status(draco::Status::ERROR, "Error msg.");
ASSERT_EQ(status.code(), draco::Status::ERROR);
const draco::Status status(draco::Status::DRACO_ERROR, "Error msg.");
ASSERT_EQ(status.code(), draco::Status::DRACO_ERROR);
std::stringstream str;
str << status;

View File

@ -59,9 +59,9 @@ StatusOr<std::unique_ptr<Mesh>> ReadMeshFromFile(const std::string &file_name,
// draco encoding methods.
std::ifstream is(file_name.c_str(), std::ios::binary);
if (!is)
return Status(Status::ERROR, "Invalid input stream.");
return Status(Status::DRACO_ERROR, "Invalid input stream.");
if (!ReadMeshFromStream(&mesh, is).good())
return Status(Status::ERROR,
return Status(Status::DRACO_ERROR,
"Unknown error."); // Error reading the stream.
return std::move(mesh);
}

View File

@ -104,12 +104,12 @@ Status ObjDecoder::DecodeInternal() {
// Ensure the number of all entries is same for all attributes.
if (num_positions_ == 0)
return Status(Status::ERROR, "No position attribute");
return Status(Status::DRACO_ERROR, "No position attribute");
if (num_tex_coords_ > 0 && num_tex_coords_ != num_positions_)
return Status(Status::ERROR,
return Status(Status::DRACO_ERROR,
"Invalid number of texture coordinates for a point cloud");
if (num_normals_ > 0 && num_normals_ != num_positions_)
return Status(Status::ERROR,
return Status(Status::DRACO_ERROR,
"Invalid number of normals for a point cloud");
out_mesh_ = nullptr; // Treat the output geometry as a point cloud.
@ -303,7 +303,7 @@ bool ObjDecoder::ParseVertexPosition(Status *status) {
for (int i = 0; i < 3; ++i) {
parser::SkipWhitespace(buffer());
if (!parser::ParseFloat(buffer(), val + i)) {
*status = Status(Status::ERROR, "Failed to parse a float number");
*status = Status(Status::DRACO_ERROR, "Failed to parse a float number");
// The definition is processed so return true.
return true;
}
@ -331,7 +331,7 @@ bool ObjDecoder::ParseNormal(Status *status) {
for (int i = 0; i < 3; ++i) {
parser::SkipWhitespace(buffer());
if (!parser::ParseFloat(buffer(), val + i)) {
*status = Status(Status::ERROR, "Failed to parse a float number");
*status = Status(Status::DRACO_ERROR, "Failed to parse a float number");
// The definition is processed so return true.
return true;
}
@ -359,7 +359,7 @@ bool ObjDecoder::ParseTexCoord(Status *status) {
for (int i = 0; i < 2; ++i) {
parser::SkipWhitespace(buffer());
if (!parser::ParseFloat(buffer(), val + i)) {
*status = Status(Status::ERROR, "Failed to parse a float number");
*status = Status(Status::DRACO_ERROR, "Failed to parse a float number");
// The definition is processed so return true.
return true;
}
@ -390,7 +390,7 @@ bool ObjDecoder::ParseFace(Status *status) {
if (i == 3) {
break; // It's OK if there is no fourth vertex index.
}
*status = Status(Status::ERROR, "Failed to parse vertex indices");
*status = Status(Status::DRACO_ERROR, "Failed to parse vertex indices");
return true;
}
++num_valid_indices;
@ -435,7 +435,8 @@ bool ObjDecoder::ParseFace(Status *status) {
}
}
if (num_indices < 3 || num_indices > 4) {
*status = Status(Status::ERROR, "Invalid number of indices on a face");
*status =
Status(Status::DRACO_ERROR, "Invalid number of indices on a face");
return false;
}
// Either one or two new triangles.
@ -460,7 +461,7 @@ bool ObjDecoder::ParseMaterialLib(Status *status) {
parser::SkipWhitespace(&line_buffer);
material_file_name_.clear();
if (!parser::ParseString(&line_buffer, &material_file_name_)) {
*status = Status(Status::ERROR, "Failed to parse material file name");
*status = Status(Status::DRACO_ERROR, "Failed to parse material file name");
return true;
}
parser::SkipLine(&line_buffer);

View File

@ -75,7 +75,8 @@ Status PlyDecoder::DecodeInternal() {
if (out_mesh_ && out_mesh_->num_faces() != 0) {
#ifdef DRACO_ATTRIBUTE_VALUES_DEDUPLICATION_SUPPORTED
if (!out_point_cloud_->DeduplicateAttributeValues())
return Status(Status::ERROR, "Could not deduplicate attribute values");
return Status(Status::DRACO_ERROR,
"Could not deduplicate attribute values");
#endif
#ifdef DRACO_ATTRIBUTE_INDICES_DEDUPLICATION_SUPPORTED
out_point_cloud_->DeduplicatePointIds();
@ -98,7 +99,7 @@ Status PlyDecoder::DecodeFaceData(const PlyElement *face_element) {
vertex_indices = face_element->GetPropertyByName("vertex_index");
}
if (vertex_indices == nullptr || !vertex_indices->is_list()) {
return Status(Status::ERROR, "No faces defined");
return Status(Status::DRACO_ERROR, "No faces defined");
}
PlyPropertyReader<PointIndex::ValueType> vertex_index_reader(vertex_indices);

View File

@ -28,7 +28,7 @@ class PlyDecoderTest : public ::testing::Test {
std::unique_ptr<Geometry> geometry(new Geometry());
Status status = decoder.DecodeFromFile(path, geometry.get());
if (!status.ok()) {
LOG(ERROR) << "Failed to decode " << file_name << ": " << status;
LOG(DRACO_ERROR) << "Failed to decode " << file_name << ": " << status;
return nullptr;
}
return geometry;

View File

@ -48,9 +48,9 @@ StatusOr<std::unique_ptr<PointCloud>> ReadPointCloudFromFile(
// draco encoding methods.
std::ifstream is(file_name.c_str(), std::ios::binary);
if (!is)
return Status(Status::ERROR, "Invalid input stream.");
return Status(Status::DRACO_ERROR, "Invalid input stream.");
if (!ReadPointCloudFromStream(&pc, is).good())
return Status(Status::ERROR,
return Status(Status::DRACO_ERROR,
"Unknown error."); // Error reading the stream.
return std::move(pc);
}